@annotorious/core 3.0.0-pre-alpha-50 → 3.0.0-pre-alpha-52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@annotorious/core",
3
- "version": "3.0.0-pre-alpha-50",
3
+ "version": "3.0.0-pre-alpha-52",
4
4
  "description": "Annotorious core types and functions",
5
5
  "author": "Rainer Simon",
6
6
  "license": "BSD-3-Clause",
@@ -44,7 +44,7 @@ export interface AnnotationBody {
44
44
 
45
45
  purpose?: string;
46
46
 
47
- value: string;
47
+ value?: string;
48
48
 
49
49
  creator?: User;
50
50
 
@@ -26,6 +26,8 @@ export interface W3CAnnotationBody {
26
26
 
27
27
  value?: string;
28
28
 
29
+ source?: string;
30
+
29
31
  created?: Date;
30
32
 
31
33
  creator?: {
@@ -78,23 +80,30 @@ const hashCode = (obj: Object): string => {
78
80
  export const parseW3CBodies = (
79
81
  body: W3CAnnotationBody | W3CAnnotationBody[],
80
82
  annotationId: string
81
- ): AnnotationBody[] => (Array.isArray(body) ? body : [body]).map(b => ({
83
+ ): AnnotationBody[] => (Array.isArray(body) ? body : [body]).map(body => {
84
+
85
+ // Exctract properties that conform to the internal model, but keep custom props
86
+ const { id, type, purpose, value, created, creator, ...rest} = body;
87
+
82
88
  // The internal model strictly requires IDs. (Because multi-user scenarios
83
89
  // will have problems without them.) In the W3C model, bodys *may* have IDs.
84
90
  // We'll create ad-hoc IDs for bodies without IDs, but want to make sure that
85
91
  // generating the ID is idempotent: the same body should always get the same ID.
86
92
  // This will avoid unexpected results when checking for equality.
87
- id: b.id || hashCode(b),
88
- annotation: annotationId,
89
- type: b.type,
90
- purpose: b.purpose,
91
- value: b.value,
92
- created: b.created,
93
- creator: b.creator ?
94
- typeof b.creator === 'object' ? { ...b.creator }: b.creator :
95
- undefined
96
- }));
93
+ return {
94
+ id: id || hashCode(body),
95
+ annotation: annotationId,
96
+ type,
97
+ purpose,
98
+ value,
99
+ created,
100
+ creator: creator ?
101
+ typeof creator === 'object' ? { ...creator }: creator :
102
+ undefined,
103
+ ...rest
104
+ }
97
105
 
106
+ });
98
107
 
99
108
  export const serializeW3CBodies = (bodies: AnnotationBody[]): W3CAnnotationBody[] =>
100
109
  bodies.map(b => {
@@ -108,9 +108,13 @@ export const createStore = <T extends Annotation>() => {
108
108
 
109
109
  const all = () => [...annotationIndex.values()];
110
110
 
111
- const clear = () => {
111
+ const clear = (origin = Origin.LOCAL) => {
112
+ const all = [...annotationIndex.values()];
113
+
112
114
  annotationIndex.clear();
113
115
  bodyIndex.clear();
116
+
117
+ emit(origin, { deleted: all });
114
118
  }
115
119
 
116
120
  const bulkAddAnnotation = (annotations: T[], replace = true, origin = Origin.LOCAL) => {
@@ -21,7 +21,7 @@ export const getContributors = (annotation: Annotation): User[] => {
21
21
 
22
22
  export const createBody = (
23
23
  annotation: Annotation,
24
- payload: { value: string, [key: string]: any },
24
+ payload: { [key: string]: any },
25
25
  created?: Date,
26
26
  creator?: User
27
27
  ): AnnotationBody => ({