Skip to content

Commit be413f4

Browse files
Generalized w3c text format adapter
1 parent 2b00afd commit be413f4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

packages/text-annotator/src/model/w3c/W3CTextFormatAdapter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ import type { TextAnnotation, TextAnnotationTarget, TextSelector } from '../core
1010
import type { W3CTextAnnotation, W3CTextAnnotationTarget, W3CTextSelector } from '../w3c';
1111
import { getQuoteContext } from '../../utils';
1212

13-
export type W3CTextFormatAdapter = FormatAdapter<TextAnnotation, W3CTextAnnotation>;
13+
export type W3CTextFormatAdapter<I extends TextAnnotation = TextAnnotation, E extends W3CTextAnnotation = W3CTextAnnotation> = FormatAdapter<I, E>;
1414

1515
/**
1616
* @param source - the IRI of the annotated content
1717
* @param container - the HTML container of the annotated content,
1818
* Required to locate the content's `range` within the DOM
1919
*/
20-
export const W3CTextFormat = (
20+
export const W3CTextFormat = <E extends W3CTextAnnotation = W3CTextAnnotation>(
2121
source: string,
2222
container: HTMLElement
23-
): W3CTextFormatAdapter => ({
23+
): W3CTextFormatAdapter<TextAnnotation, E> => ({
2424
parse: (serialized) => parseW3CTextAnnotation(serialized),
2525
serialize: (annotation) => serializeW3CTextAnnotation(annotation, source, container)
2626
});
@@ -119,11 +119,11 @@ export const parseW3CTextAnnotation = (
119119

120120
};
121121

122-
export const serializeW3CTextAnnotation = (
122+
export const serializeW3CTextAnnotation = <E extends W3CTextAnnotation = W3CTextAnnotation>(
123123
annotation: TextAnnotation,
124124
source: string,
125125
container: HTMLElement
126-
): W3CTextAnnotation => {
126+
): E => {
127127
const { bodies, target, ...rest } = annotation;
128128

129129
const {
@@ -171,6 +171,6 @@ export const serializeW3CTextAnnotation = (
171171
created: created?.toISOString(),
172172
modified: updated?.toISOString(),
173173
target: w3cTargets
174-
};
174+
} as E;
175175

176176
};

0 commit comments

Comments
 (0)