Skip to content

Commit

Permalink
Merge branch 'main' into recogito#172-fix-popup-flickering-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-danylchenko committed Dec 16, 2024
2 parents 3e92bd0 + 5b9abad commit 1555b84
Show file tree
Hide file tree
Showing 9 changed files with 1,814 additions and 727 deletions.
2,449 changes: 1,766 additions & 683 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/extension-tei/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
},
"devDependencies": {
"CETEIcean": "^1.9.3",
"typescript": "5.6.3",
"vite": "^5.4.11",
"typescript": "5.7.2",
"vite": "^6.0.3",
"vite-plugin-dts": "^4.3.0"
},
"peerDependencies": {
"@annotorious/core": "^3.0.12",
"@annotorious/core": "^3.0.14",
"@recogito/text-annotator": "3.0.0-rc.53"
}
}
6 changes: 3 additions & 3 deletions packages/extension-tei/src/crosswalk/forward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ export const reviveTarget = (t: TextAnnotationTarget, container: HTMLElement) =>

// Helper
const reanchorIfNeeded = (parent: Node, offset: number) => {
if (parent.firstChild.toString().length >= offset) {
if (parent.firstChild instanceof Text && parent.firstChild.length >= offset) {
return { node: parent.firstChild, offset };
} else {
return reanchor(parent.firstChild, parent, offset);
}
}

const reanchoredStart = reanchorIfNeeded(startNode, startOffset);
const reanchoredEnd = reanchorIfNeeded(endNode, endOffset);

range.setStart(reanchoredStart.node, reanchoredStart.offset);

const reanchoredEnd = reanchorIfNeeded(endNode, endOffset);
range.setEnd(reanchoredEnd.node, reanchoredEnd.offset);

const textSelector = rangeToSelector(range, container);
Expand Down
16 changes: 8 additions & 8 deletions packages/text-annotator-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"module": "./dist/react-text-annotator.es.js",
"types": "./dist/index.d.ts",
"devDependencies": {
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "5.6.3",
"vite": "^5.4.11",
"typescript": "5.7.2",
"vite": "^6.0.3",
"vite-plugin-dts": "^4.3.0",
"vite-tsconfig-paths": "^5.1.3"
"vite-tsconfig-paths": "^5.1.4"
},
"peerDependencies": {
"openseadragon": "^3.0.0 || ^4.0.0 || ^5.0.0",
Expand All @@ -44,9 +44,9 @@
}
},
"dependencies": {
"@annotorious/core": "^3.0.12",
"@annotorious/react": "^3.0.12",
"@floating-ui/react": "^0.26.28",
"@annotorious/core": "^3.0.14",
"@annotorious/react": "^3.0.14",
"@floating-ui/react": "^0.27.1",
"@recogito/text-annotator": "3.0.0-rc.53",
"@recogito/text-annotator-tei": "3.0.0-rc.53",
"CETEIcean": "^1.9.3",
Expand Down
10 changes: 6 additions & 4 deletions packages/text-annotator-react/src/TextAnnotator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ import { createTextAnnotator } from '@recogito/text-annotator';

import '@recogito/text-annotator/dist/text-annotator.css';

export interface TextAnnotatorProps<E extends unknown> extends Omit<TextAnnotatorOptions<TextAnnotation, E>, 'adapter'> {
export interface TextAnnotatorProps<I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation> extends Omit<TextAnnotatorOptions<I, E>, 'adapter'> {

children?: ReactNode | JSX.Element;

adapter?: FormatAdapter<TextAnnotation, E> | ((container: HTMLElement) => FormatAdapter<TextAnnotation, E>) | null;
adapter?: FormatAdapter<I, E> | ((container: HTMLElement) => FormatAdapter<I, E>) | null;

filter?: Filter;
filter?: Filter<I>;

style?: HighlightStyleExpression;

className?: string;

}

export const TextAnnotator = <E extends unknown>(props: TextAnnotatorProps<E>) => {
export const TextAnnotator = <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(
props: TextAnnotatorProps<I, E>
) => {

const el = useRef<HTMLDivElement>(null);

Expand Down
10 changes: 5 additions & 5 deletions packages/text-annotator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
"@types/jsdom": "^21.1.7",
"@types/rbush": "^4.0.0",
"jsdom": "^25.0.1",
"typescript": "5.6.3",
"vite": "^5.4.11",
"typescript": "5.7.2",
"vite": "^6.0.3",
"vite-plugin-dts": "^4.3.0",
"vitest": "^2.1.5"
"vitest": "^2.1.8"
},
"dependencies": {
"@annotorious/core": "^3.0.12",
"@annotorious/core": "^3.0.14",
"colord": "^2.9.3",
"dequal": "^2.0.3",
"hotkeys-js": "^3.13.7",
"hotkeys-js": "^3.13.9",
"rbush": "^4.0.1",
"uuid": "^11.0.3"
}
Expand Down
22 changes: 11 additions & 11 deletions packages/text-annotator/src/TextAnnotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ export interface TextAnnotator<I extends TextAnnotation = TextAnnotation, E exte

}

export const createTextAnnotator = <E extends unknown = TextAnnotation>(
export const createTextAnnotator = <I extends TextAnnotation = TextAnnotation, E extends unknown = TextAnnotation>(
container: HTMLElement,
options: TextAnnotatorOptions<TextAnnotation, E> = {}
): TextAnnotator<TextAnnotation, E> => {
options: TextAnnotatorOptions<I, E> = {}
): TextAnnotator<I, E> => {
// Prevent mobile browsers from triggering word selection on single click.
cancelSingleClickEvents(container);

// Make sure that the container is focusable and can receive both pointer and keyboard events
programmaticallyFocusable(container);

const opts = fillDefaults<TextAnnotation, E>(options, {
const opts = fillDefaults<I, E>(options, {
annotatingEnabled: true,
user: createAnonymousGuest()
});

const state: TextAnnotatorState<TextAnnotation, E> =
createTextAnnotatorState<TextAnnotation, E>(container, opts.userSelectAction);
const state: TextAnnotatorState<I, E> =
createTextAnnotatorState<I, E>(container, opts.userSelectAction);

const { selection, viewport } = state;

const store: TextAnnotationStore = state.store;
const store: TextAnnotationStore<I> = state.store;

const undoStack = createUndoStack(store);
const undoStack = createUndoStack<I>(store);

const lifecycle = createLifecycleObserver<TextAnnotation, E>(state, undoStack, opts.adapter);
const lifecycle = createLifecycleObserver<I, E>(state, undoStack, opts.adapter);

let currentUser: User = opts.user;

Expand Down Expand Up @@ -84,11 +84,11 @@ export const createTextAnnotator = <E extends unknown = TextAnnotation>(
/******++++++*************/

// Most of the external API functions are covered in the base annotator
const base = createBaseAnnotator<TextAnnotation, E>(state, undoStack, opts.adapter);
const base = createBaseAnnotator<I, E>(state, undoStack, opts.adapter);

const getUser = () => currentUser;

const setFilter = (filter?: Filter) => {
const setFilter = (filter?: Filter<I>) => {
highlightRenderer.setFilter(filter);
selectionHandler.setFilter(filter);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/text-annotator/src/highlight/HighlightStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface HighlightStyle extends Pick<DrawingStyle, 'fill' | 'fillOpacity
}

export type HighlightStyleExpression = HighlightStyle
| ((annotation: TextAnnotation, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);
| (<I extends TextAnnotation = TextAnnotation>(annotation: I, state: AnnotationState, zIndex?: number) => HighlightStyle | undefined);

export const DEFAULT_STYLE: HighlightStyle = {
fill: 'rgb(0, 128, 255)',
Expand Down
20 changes: 11 additions & 9 deletions packages/text-annotator/src/model/w3c/W3CTextFormatAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export type W3CTextFormatAdapter<I extends TextAnnotation = TextAnnotation, E ex
* @param container - the HTML container of the annotated content,
* Required to locate the content's `range` within the DOM
*/
export const W3CTextFormat = <E extends W3CTextAnnotation = W3CTextAnnotation>(
export const W3CTextFormat =<I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation>(
source: string,
container: HTMLElement
): W3CTextFormatAdapter<TextAnnotation, E> => ({
): W3CTextFormatAdapter<I, E> => ({
parse: (serialized) => parseW3CTextAnnotation(serialized),
serialize: (annotation) => serializeW3CTextAnnotation(annotation, source, container)
});
Expand Down Expand Up @@ -90,9 +90,9 @@ const parseW3CTextTargets = (annotation: W3CTextAnnotation) => {
return { parsed };
};

export const parseW3CTextAnnotation = (
annotation: W3CTextAnnotation
): ParseResult<TextAnnotation> => {
export const parseW3CTextAnnotation = <I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation>(
annotation: E
): ParseResult<I> => {
const annotationId = annotation.id || uuidv4();

const {
Expand All @@ -106,7 +106,7 @@ export const parseW3CTextAnnotation = (
const bodies = parseW3CBodies(body, annotationId);
const target = parseW3CTextTargets(annotation);

return 'error' in target
const parseResult = 'error' in target
? { error: target.error }
: {
parsed: {
Expand All @@ -117,10 +117,12 @@ export const parseW3CTextAnnotation = (
}
};

return parseResult as ParseResult<I>;

};

export const serializeW3CTextAnnotation = <E extends W3CTextAnnotation = W3CTextAnnotation>(
annotation: TextAnnotation,
export const serializeW3CTextAnnotation = <I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation>(
annotation: I,
source: string,
container: HTMLElement
): E => {
Expand Down Expand Up @@ -171,6 +173,6 @@ export const serializeW3CTextAnnotation = <E extends W3CTextAnnotation = W3CText
created: created?.toISOString(),
modified: updated?.toISOString(),
target: w3cTargets
} as E;
} as unknown as E;

};

0 comments on commit 1555b84

Please sign in to comment.