Skip to content

Commit

Permalink
feat(annotation): add/update/delete/filter tags in publication annota…
Browse files Browse the repository at this point in the history
…tions (Fixes #2524 PR #2538)
  • Loading branch information
panaC authored Sep 17, 2024
1 parent a75a8d3 commit 081e746
Show file tree
Hide file tree
Showing 23 changed files with 1,014 additions and 309 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/common/redux/actions/reader/annotations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export const ID = "READER_ANNOTATIONS_UPDATE";

// eslint-disable-next-line @typescript-eslint/no-empty-interface
// interface IPayload extends Pick<IAnnotationState, "color"|"comment"|"uuid"> {
interface IPayload extends IAnnotationState {
}
export function build(param: IAnnotationState):
type IPayload = [IAnnotationState, IAnnotationState];

export function build(oldAnnotation: IAnnotationState, newAnnotation: IAnnotationState):
Action<typeof ID, IPayload> {

return {
type: ID,
payload: param,
payload: [oldAnnotation, newAnnotation],
};
}
build.toString = () => ID; // Redux StringableActionCreator
Expand Down
3 changes: 3 additions & 0 deletions src/common/redux/states/renderer/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IAnnotationState {
comment: string;
color: IColor;
drawType: TDrawType;
tags?: string[] | undefined;
}

export type TAnnotationState = TPQueueState<number, IAnnotationState>;
Expand All @@ -42,3 +43,5 @@ export interface IAnnotationReaderConfigState {
annotation_defaultDrawType: TDrawType;
annotation_defaultDrawView: TDrawView;
}

export type TAnnotationTagsIndex = Record<string, number>;
3 changes: 2 additions & 1 deletion src/common/redux/states/renderer/readerRootState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { LocatorExtended } from "@r2-navigator-js/electron/renderer";

import { TBookmarkState } from "../bookmark";
import { IRTLFlipState } from "./rtlFlip";
import { IAnnotationModeState, TAnnotationState } from "./annotation";
import { IAnnotationModeState, TAnnotationState, TAnnotationTagsIndex } from "./annotation";
import { ITTSState } from "readium-desktop/renderer/reader/redux/state/tts";
import { IMediaOverlayState } from "readium-desktop/renderer/reader/redux/state/mediaOverlay";
import { IAllowCustomConfigState } from "readium-desktop/renderer/reader/redux/state/allowCustom";
Expand All @@ -29,6 +29,7 @@ export interface IReaderRootState extends IRendererCommonRootState {
search: ISearchState;
mode: ReaderMode;
annotation: IAnnotationModeState;
annotationTagsIndex: TAnnotationTagsIndex;
}

export interface IReaderStateReader {
Expand Down
14 changes: 14 additions & 0 deletions src/common/rgb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

export function rgbToHex(color: { red: number; green: number; blue: number }): string {
const { red, green, blue } = color;
const redHex = Math.min(255, Math.max(0, red)).toString(16).padStart(2, "0");
const greenHex = Math.min(255, Math.max(0, green)).toString(16).padStart(2, "0");
const blueHex = Math.min(255, Math.max(0, blue)).toString(16).padStart(2, "0");
return `#${redHex}${greenHex}${blueHex}`;
}
9 changes: 1 addition & 8 deletions src/main/w3c/annotation/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ import { v4 as uuidv4 } from "uuid";
import { _APP_NAME, _APP_VERSION } from "readium-desktop/preprocessor-directives";
import { PublicationView } from "readium-desktop/common/views/publication";
import { IAnnotationState } from "readium-desktop/common/redux/states/renderer/annotation";

function rgbToHex(color: { red: number; green: number; blue: number }): string {
const { red, green, blue } = color;
const redHex = Math.min(255, Math.max(0, red)).toString(16).padStart(2, "0");
const greenHex = Math.min(255, Math.max(0, green)).toString(16).padStart(2, "0");
const blueHex = Math.min(255, Math.max(0, blue)).toString(16).padStart(2, "0");
return `#${redHex}${greenHex}${blueHex}`;
}
import { rgbToHex } from "readium-desktop/common/rgb";

export function convertAnnotationToW3CAnnotationModel(annotation: IAnnotationState): IW3CAnnotationModel {

Expand Down
3 changes: 3 additions & 0 deletions src/renderer/assets/icons/filter2-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 081e746

Please sign in to comment.