Skip to content

Commit 3a8f51b

Browse files
authored
Merge pull request #170 from oleksandr-danylchenko/add-scope-serialization-parsing
Added W3C `scope` property support parsing/serialization
2 parents daf5466 + c21ae2c commit 3a8f51b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

packages/text-annotator/src/model/core/TextAnnotation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface TextSelector {
2424

2525
range: Range;
2626

27-
offsetReference?: HTMLElement
27+
offsetReference?: HTMLElement;
28+
29+
scope?: string;
2830

2931
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface W3CTextAnnotationTarget extends W3CAnnotationTarget {
1414

1515
styleClass?: string;
1616

17+
scope?: string;
18+
1719
}
1820

1921
/**

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ const parseW3CTextTargets = (annotation: W3CTextAnnotation) => {
6464
}, {});
6565

6666
if (isTextSelector(selector)) {
67-
parsed.selector.push({ id: w3cTarget.id, ...selector });
67+
parsed.selector.push({
68+
...selector,
69+
id: w3cTarget.id,
70+
scope: w3cTarget.scope
71+
});
6872
} else {
6973
const missingTypes = [
7074
!selector.start ? 'TextPositionSelector' : undefined,
@@ -123,7 +127,7 @@ export const serializeW3CTextAnnotation = (
123127
} = target;
124128

125129
const w3cTargets = selector.map((s) => {
126-
const { quote, start, end, range } = s;
130+
const { id, scope, quote, start, end, range } = s;
127131

128132
const { prefix, suffix } = getQuoteContext(range, container);
129133

@@ -140,7 +144,8 @@ export const serializeW3CTextAnnotation = (
140144

141145
return {
142146
...targetRest,
143-
id: s.id,
147+
id,
148+
scope,
144149
source,
145150
selector: w3cSelectors
146151
};

0 commit comments

Comments
 (0)