@ghentcdh/annotation-api 0.0.1-alpha.1 → 0.0.1-alpha.13
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/index.cjs +856 -1
- package/index.d.ts +5 -7
- package/index.js +752 -308
- package/lib/annotation/annotation.controller.d.ts +3854 -0
- package/lib/annotation/annotation.mapper.service.d.ts +11 -0
- package/lib/annotation/annotation.repository.d.ts +9 -0
- package/lib/annotation-api.module.d.ts +7 -6
- package/lib/annotation-namespace.controller.d.ts +13 -61
- package/lib/context/annotation-context.service.d.ts +12 -0
- package/lib/context/index.d.ts +1 -0
- package/lib/prefix.d.ts +1 -0
- package/lib/utils/schemaEnricher.utils.d.ts +1 -0
- package/package.json +6 -3
- package/README.md +0 -3
- package/lib/resource/annotation-resource-definition.service.d.ts +0 -10
- package/lib/resource/annotation-resource.loader.d.ts +0 -2
- package/lib/service/annotation-definition-from-files.service.d.ts +0 -26
- package/lib/service/annotation-definition.loader.d.ts +0 -2
- package/lib/service/annotation-definition.service.d.ts +0 -16
package/index.js
CHANGED
|
@@ -1,369 +1,813 @@
|
|
|
1
|
-
import { Controller
|
|
2
|
-
import { z
|
|
3
|
-
import { contextBuilder
|
|
4
|
-
import "@ghentcdh/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
//#region
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { Body, Controller, Delete, Get, Inject, Injectable, Module, Param, Patch, Post } from "@nestjs/common";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ContextBuilder, contextBuilder, w3cAnnotation } from "@ghentcdh/w3c-utils";
|
|
4
|
+
import { JsonOperationsSchema, ResourceJsonShape, ViewConfigSchema, labelFromId, registerResourceExtensions } from "@ghentcdh/crouton-core";
|
|
5
|
+
import { Debugger, PlainTextAdapter, W3CAnnotationAdapter, WordSnapper, createAnnotatedText, createHighlightStyle } from "@ghentcdh/annotated-text";
|
|
6
|
+
import { CroutonApiModule, ResourceConfigRegistry } from "@ghentcdh/crouton-api";
|
|
7
|
+
import { ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from "@nestjs/swagger";
|
|
8
|
+
//#region src/lib/annotation/annotation.repository.ts
|
|
9
|
+
var AnnotationCrudRepository = class {};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region ../annotation-core/src/lib/types/key-label.type.ts
|
|
12
|
+
var KeyLabelSchema = z.object();
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../annotation-core/src/lib/types/source.model.ts
|
|
15
|
+
var SourceTypesList = ["text"];
|
|
16
|
+
var SourceTextSchema = z.object({
|
|
17
|
+
text: z.string(),
|
|
18
|
+
textDirection: z.enum(["ltr", "rtl"]).default("ltr"),
|
|
19
|
+
processingLanguage: z.string().default("en"),
|
|
20
|
+
label: z.string().optional(),
|
|
21
|
+
offset: z.number().optional().default(0)
|
|
22
|
+
});
|
|
23
|
+
var SourceModelSchema = z.object({
|
|
24
|
+
id: z.string(),
|
|
25
|
+
uri: z.string(),
|
|
26
|
+
type: z.enum(SourceTypesList),
|
|
27
|
+
content: SourceTextSchema
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region ../annotation-core/src/lib/types/grid-layout.types.ts
|
|
31
|
+
/** Computed CSS styles for the grid container */
|
|
32
|
+
var buildGridStyle = (layout) => {
|
|
33
|
+
const templateAreas = layout.areas.map((row) => `"${row.join(" ")}"`).join(" ");
|
|
34
|
+
const colCount = layout.areas[0]?.length ?? 1;
|
|
35
|
+
const style = {
|
|
36
|
+
gridTemplateAreas: templateAreas,
|
|
37
|
+
gridTemplateColumns: layout.columns ?? Array(colCount).fill("minmax(0, 1fr)").join(" ")
|
|
38
|
+
};
|
|
39
|
+
if (layout.rows) style["gridTemplateRows"] = layout.rows;
|
|
40
|
+
return style;
|
|
41
|
+
};
|
|
42
|
+
/** Returns the grid-area CSS value for a given source id, or undefined if not configured */
|
|
43
|
+
var getPaneArea = (layout, sourceId) => {
|
|
44
|
+
return layout.panes.find((p) => p.sourceId === sourceId)?.area;
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region ../annotation-core/src/lib/utils/annotation.context-builder.ts
|
|
48
|
+
var defaultConfig = {
|
|
49
|
+
baseUrl: "http://localhost:3333/",
|
|
50
|
+
crudController: "annotation/annotation",
|
|
31
51
|
app: "ghentcdh",
|
|
32
52
|
prefix: "ghentcdh",
|
|
33
|
-
isDev:
|
|
53
|
+
isDev: false,
|
|
34
54
|
cacheTTLms: 1200 * 1e3
|
|
35
|
-
}
|
|
36
|
-
|
|
55
|
+
};
|
|
56
|
+
var resolveConfig = (config = {}) => {
|
|
57
|
+
const baseUrl = config.baseUrl ?? defaultConfig.baseUrl;
|
|
58
|
+
const normalizedBaseUrl = baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`;
|
|
59
|
+
const isDev = config.isDev ?? false;
|
|
60
|
+
const cacheTTLms = isDev ? 0 : 1200 * 1e3;
|
|
61
|
+
return {
|
|
62
|
+
baseUrl: normalizedBaseUrl,
|
|
63
|
+
contextUrl: `${normalizedBaseUrl}ns/`,
|
|
64
|
+
app: config.app ?? defaultConfig.app,
|
|
65
|
+
prefix: config.prefix ?? defaultConfig.prefix,
|
|
66
|
+
crudController: config.crudController ?? defaultConfig.crudController,
|
|
67
|
+
isDev,
|
|
68
|
+
cacheTTLms
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var baseContextBuilder = (id, config) => {
|
|
72
|
+
const { prefix, baseUrl, contextUrl } = resolveConfig(config);
|
|
73
|
+
const metaData = AnnotationMetadataType;
|
|
74
|
+
return contextBuilder(prefix, baseUrl).setType(prefix, metaData).addPrefix(id, `${prefix}:${id}`).setContextUri(`${contextUrl}${id}.jsonld`);
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../annotation-core/src/lib/types/annotation.contex.ts
|
|
78
|
+
var AnnotationMetadataType = "AnnotationMetadata";
|
|
79
|
+
var createAnnotationContext = (annotationDefConfig, resource) => {
|
|
80
|
+
const formView = resource.views?.["form"];
|
|
81
|
+
const builder = baseContextBuilder(resource.id, annotationDefConfig);
|
|
82
|
+
if (formView) builder.parseJsonSchema(formView.json_schema);
|
|
37
83
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
84
|
+
id: resource.id,
|
|
85
|
+
styling: {
|
|
86
|
+
name: resource.name,
|
|
87
|
+
id: resource.id,
|
|
88
|
+
target: resource.annotation.target,
|
|
89
|
+
color: resource.annotation.color
|
|
90
|
+
},
|
|
91
|
+
hasContext: !!formView,
|
|
92
|
+
prefix: buildPrefix(annotationDefConfig, resource),
|
|
93
|
+
uri: builder.uri,
|
|
94
|
+
jsonLd: builder.toJsonLdContext(),
|
|
95
|
+
safeParse: builder.safeParse.bind(builder),
|
|
96
|
+
toAnnotationBody: builder.toAnnotationBody.bind(builder)
|
|
44
97
|
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
98
|
+
};
|
|
99
|
+
var buildPrefix = (annotationDefConfig, resource) => {
|
|
100
|
+
return `${annotationDefConfig.prefix}:${resource.annotation.type}/`;
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region ../annotation-core/src/lib/types/version.ts
|
|
104
|
+
/**
|
|
105
|
+
* resource.json schema versioning.
|
|
106
|
+
*
|
|
107
|
+
* `schemaVersion` is a monotonic integer stamped on every `resource.json`. It is
|
|
108
|
+
* **decoupled from the crouton package semver** on purpose — bump it only when the
|
|
109
|
+
* resource.json *shape* changes in a way that needs a migration, and ship a matching
|
|
110
|
+
* step in `./migrations`. This keeps the migration chain one-step-per-bump with no
|
|
111
|
+
* version-range math.
|
|
112
|
+
*
|
|
113
|
+
* Files written before versioning existed carry no field and are treated as the
|
|
114
|
+
* baseline. Because `CURRENT_RESOURCE_VERSION` starts equal to the baseline, shipping
|
|
115
|
+
* the versioning machinery is a pure no-op for every existing file until the first
|
|
116
|
+
* real shape change lands (`CURRENT_RESOURCE_VERSION = 2` + a `1 → 2` migration).
|
|
117
|
+
*/
|
|
118
|
+
/** Version assumed for a `resource.json` that has no `schemaVersion` field. */
|
|
119
|
+
var BASELINE_RESOURCE_VERSION = 1;
|
|
120
|
+
/**
|
|
121
|
+
* The version the running crouton understands. Bump by 1 whenever resource.json's
|
|
122
|
+
* shape changes, and add a migration step (`from: N, to: N + 1`) in `./migrations`.
|
|
123
|
+
*/
|
|
124
|
+
var CURRENT_RESOURCE_VERSION = 1;
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region ../annotation-core/src/lib/types/annotation-json-config.types.ts
|
|
127
|
+
var AnnotationTargetEnum = z.enum([
|
|
128
|
+
"gutter",
|
|
129
|
+
"underline",
|
|
130
|
+
"highlight"
|
|
131
|
+
]);
|
|
132
|
+
var AnnotationConfigSchema = z.object({
|
|
133
|
+
color: z.string().optional(),
|
|
134
|
+
type: z.string().optional(),
|
|
135
|
+
icon: z.string().optional(),
|
|
136
|
+
isRoot: z.boolean().optional().default(true),
|
|
137
|
+
allowedChildren: z.array(z.string()).optional().default([]),
|
|
138
|
+
allowedLinks: z.array(z.string()).optional().default([]),
|
|
139
|
+
target: AnnotationTargetEnum.optional().default("highlight")
|
|
140
|
+
});
|
|
141
|
+
var AnnotationJsonResourceShape = ResourceJsonShape.extend({
|
|
142
|
+
route: z.string().optional(),
|
|
143
|
+
tag: z.string().optional(),
|
|
144
|
+
operations: JsonOperationsSchema.optional().default(JsonOperationsSchema.parse({})),
|
|
145
|
+
id: z.string(),
|
|
146
|
+
annotation: AnnotationConfigSchema.optional().default(AnnotationConfigSchema.parse({}))
|
|
147
|
+
}).passthrough();
|
|
148
|
+
var AnnotationJsonResourceSchema = AnnotationJsonResourceShape.transform((obj) => {
|
|
149
|
+
const title = labelFromId(obj.name);
|
|
150
|
+
return {
|
|
151
|
+
schemaVersion: obj.schemaVersion ?? 1,
|
|
152
|
+
title,
|
|
153
|
+
...obj
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region ../annotation-core/src/lib/types/annotation-definition.type.ts
|
|
158
|
+
var annotationColumnDefinition = z.custom();
|
|
159
|
+
var AnnotationResourceSchema = AnnotationJsonResourceShape.pick({
|
|
160
|
+
id: true,
|
|
161
|
+
name: true,
|
|
162
|
+
title: true,
|
|
163
|
+
operations: true,
|
|
164
|
+
annotation: true
|
|
165
|
+
}).extend({
|
|
166
|
+
annotation: AnnotationConfigSchema,
|
|
167
|
+
context: z.instanceof(ContextBuilder).optional().nullish(),
|
|
168
|
+
schemas: z.record(z.string(), ViewConfigSchema.partial()).optional().nullish()
|
|
169
|
+
});
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region ../annotation-core/src/lib/annotation.style.ts
|
|
172
|
+
var CONTEXT = "annotation.style";
|
|
173
|
+
var AnnotationStyleSchema = z.object({
|
|
174
|
+
id: z.string(),
|
|
175
|
+
name: z.string(),
|
|
176
|
+
target: z.enum([
|
|
52
177
|
"gutter",
|
|
53
178
|
"underline",
|
|
54
179
|
"highlight"
|
|
55
180
|
]).optional().default("underline"),
|
|
56
|
-
color:
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
181
|
+
color: z.string().optional()
|
|
182
|
+
});
|
|
183
|
+
var AnnotationStyleType = "AnnotationStyle";
|
|
184
|
+
var AnnotationStyleContextBuilder = (annotationConfig) => {
|
|
185
|
+
const { prefix, baseUrl, contextUrl } = resolveConfig(annotationConfig);
|
|
186
|
+
return contextBuilder(prefix, baseUrl).setType(prefix, AnnotationStyleType).setContextUri(`${contextUrl}${AnnotationStyleType}.jsonld`).parseZodSchema(AnnotationStyleSchema);
|
|
187
|
+
};
|
|
188
|
+
var createAnnotationStyleBodyUnsafe = (annotationConfig, style) => {
|
|
189
|
+
const resource = {
|
|
190
|
+
...style,
|
|
191
|
+
...style.annotation
|
|
192
|
+
};
|
|
193
|
+
const parsed = AnnotationStyleContextBuilder(annotationConfig).toAnnotationBodyUnsafe(resource);
|
|
194
|
+
if (!parsed.success) {
|
|
195
|
+
Debugger.debug(CONTEXT, "AnnotationStyleContextBuilder safe parse failed");
|
|
196
|
+
Debugger.warn(parsed.error);
|
|
65
197
|
}
|
|
198
|
+
return parsed;
|
|
199
|
+
};
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region ../annotation-core/src/lib/utils/annotation-utils.ts
|
|
202
|
+
var mapRelationsToLinks = (sourceUri, builders, annotations) => {
|
|
203
|
+
return annotations.map((link) => {
|
|
204
|
+
const builder = builders.get(link.id);
|
|
205
|
+
const specifyResource = builder.getSpecificResourceTargets(sourceUri);
|
|
206
|
+
if (!specifyResource || specifyResource.length === 0) return null;
|
|
207
|
+
const relations = builder.getSpecificResourceTargets().map((s) => s.source).filter((s) => s !== sourceUri).map((uri) => {
|
|
208
|
+
return annotations.find((a) => a.id === uri);
|
|
209
|
+
}).filter(Boolean);
|
|
210
|
+
return {
|
|
211
|
+
purpose: getAnnotationType(builder),
|
|
212
|
+
annotation: link,
|
|
213
|
+
relations
|
|
214
|
+
};
|
|
215
|
+
}).filter(Boolean);
|
|
216
|
+
};
|
|
217
|
+
var getAnnotationType = (builder) => {
|
|
218
|
+
return getAnnotationStyle(builder)?.id ?? "text";
|
|
219
|
+
};
|
|
220
|
+
var getAnnotationStyle = (builder) => {
|
|
221
|
+
return builder.getBodiesByPurpose("styling").find((b) => b.type === "AnnotationStyle");
|
|
222
|
+
};
|
|
223
|
+
var getAnnotationPosition = (id, builder, allowedChildrenPerType) => {
|
|
224
|
+
const sourceUri = builder.getSpecificResourceTargets()[0]?.source;
|
|
225
|
+
if (!sourceUri) return null;
|
|
226
|
+
const textPositionSelector = builder.getTextPositionSelector(sourceUri)[0];
|
|
227
|
+
if (!textPositionSelector) return null;
|
|
228
|
+
const type = getAnnotationStyle(builder)?.id ?? "text";
|
|
66
229
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
230
|
+
id,
|
|
231
|
+
start: textPositionSelector.start,
|
|
232
|
+
end: textPositionSelector.end,
|
|
233
|
+
allowedChildren: allowedChildrenPerType[type] ?? [],
|
|
234
|
+
sourceUri: sourceUri ?? "",
|
|
235
|
+
type,
|
|
236
|
+
minX: textPositionSelector.start,
|
|
237
|
+
minY: 0,
|
|
238
|
+
maxX: textPositionSelector.end,
|
|
239
|
+
maxY: 0
|
|
70
240
|
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
241
|
+
};
|
|
242
|
+
var rootId = "ROOT";
|
|
243
|
+
var createId = () => {
|
|
244
|
+
return `mela:new-annotation:${Date.now()}`;
|
|
245
|
+
};
|
|
246
|
+
var updateSelector = (builder, selector) => {
|
|
247
|
+
if (!builder.getSpecificResourceTargets(selector.source).length) builder.addTarget({
|
|
248
|
+
type: "SpecificResource",
|
|
249
|
+
source: selector.source
|
|
250
|
+
});
|
|
251
|
+
builder.updateTextPositionSelector({
|
|
252
|
+
start: selector.start,
|
|
253
|
+
end: selector.end
|
|
254
|
+
}, selector.source);
|
|
255
|
+
builder.updateTextQuoteSelector({
|
|
256
|
+
prefix: selector.prefix,
|
|
257
|
+
suffix: selector.suffix,
|
|
258
|
+
exact: selector.exact
|
|
259
|
+
}, selector.source);
|
|
260
|
+
return builder;
|
|
261
|
+
};
|
|
262
|
+
var AnnotationUtilsImpl = class {
|
|
263
|
+
annotationConfig;
|
|
264
|
+
builderMap = /* @__PURE__ */ new Map();
|
|
265
|
+
childParentMap = /* @__PURE__ */ new Map();
|
|
266
|
+
parentChildMap = /* @__PURE__ */ new Map();
|
|
267
|
+
linkedAnnotations = /* @__PURE__ */ new Map();
|
|
268
|
+
annotations = [];
|
|
269
|
+
allowedChildrenPerType = {};
|
|
270
|
+
constructor(annotationConfig) {
|
|
271
|
+
this.annotationConfig = annotationConfig;
|
|
272
|
+
}
|
|
273
|
+
getBuilder(annotation) {
|
|
274
|
+
const builder = this.builderMap.get(annotation.id);
|
|
275
|
+
if (!builder) throw new Error(`Annotation builder not found: ${annotation.id}`);
|
|
276
|
+
return builder;
|
|
277
|
+
}
|
|
278
|
+
setAnnotations(annotations, allowedChildrenPerType) {
|
|
279
|
+
this.allowedChildrenPerType = allowedChildrenPerType;
|
|
280
|
+
this.annotations = annotations;
|
|
281
|
+
this.parentChildMap.clear();
|
|
282
|
+
this.childParentMap.clear();
|
|
283
|
+
this.builderMap.clear();
|
|
284
|
+
const annotationsWithPositons = [];
|
|
285
|
+
const annotationIdMap = /* @__PURE__ */ new Map();
|
|
286
|
+
annotations.forEach((annotation) => {
|
|
287
|
+
const builder = w3cAnnotation(annotation);
|
|
288
|
+
this.builderMap.set(annotation.id, builder);
|
|
289
|
+
const position = getAnnotationPosition(annotation.id, builder, this.allowedChildrenPerType);
|
|
290
|
+
annotationIdMap.set(annotation.id, annotation);
|
|
291
|
+
if (position) annotationsWithPositons.push(position);
|
|
292
|
+
});
|
|
293
|
+
annotationsWithPositons.forEach((annotation) => {
|
|
294
|
+
const parentAnnotation = annotationsWithPositons.filter((a) => a.id !== annotation.id && a.sourceUri === annotation.sourceUri && a.start <= annotation.start && a.end >= annotation.end && a.allowedChildren.some((c) => c.key === annotation.type)).sort((a, b) => a.end - a.start - (b.end - b.start))[0];
|
|
295
|
+
const parentId = parentAnnotation?.id ?? rootId;
|
|
296
|
+
const children = this.parentChildMap.get(parentId) ?? [];
|
|
297
|
+
children.push(annotationIdMap.get(annotation.id));
|
|
298
|
+
this.parentChildMap.set(parentAnnotation?.id ?? rootId, children);
|
|
299
|
+
this.childParentMap.set(annotation.id, annotationIdMap.get(parentId) ?? null);
|
|
300
|
+
});
|
|
301
|
+
annotations.forEach((annotation) => {
|
|
302
|
+
this.linkedAnnotations.set(annotation.id, mapRelationsToLinks(annotation.id, this.builderMap, annotations));
|
|
303
|
+
});
|
|
304
|
+
return this;
|
|
77
305
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
elements: e.filter((e) => !e.hiddenInForm).map(C),
|
|
81
|
-
options: {}
|
|
82
|
-
}), E = (e) => ({
|
|
83
|
-
type: "GridLayout",
|
|
84
|
-
elements: e.filter((e) => !e.hiddenInMetadata).map(w),
|
|
85
|
-
options: {}
|
|
86
|
-
}), D = (e) => {
|
|
87
|
-
if (e.type === "object" && e.properties) {
|
|
88
|
-
let t = {};
|
|
89
|
-
for (let [n, r] of Object.entries(e.properties)) t[n] = D(r);
|
|
90
|
-
return s.object(t);
|
|
306
|
+
getLinks(annotation) {
|
|
307
|
+
return this.linkedAnnotations.get(annotation.id) ?? [];
|
|
91
308
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
309
|
+
getTextPositionSelector(annotation, sourceUri) {
|
|
310
|
+
return this.getBuilder(annotation).getTextPositionSelector(sourceUri)[0];
|
|
311
|
+
}
|
|
312
|
+
isAnnotationUri = (uri) => {
|
|
313
|
+
return uri.startsWith("mela:annotation/");
|
|
314
|
+
};
|
|
315
|
+
getParentSelector = (builder) => {
|
|
316
|
+
return builder.getSpecificResourceTargets().find((t) => this.isAnnotationUri(t.source)) ?? null;
|
|
317
|
+
};
|
|
318
|
+
getParent(annotation) {
|
|
319
|
+
const builder = this.getBuilder(annotation);
|
|
320
|
+
const parentUri = this.getParentSelector(builder);
|
|
321
|
+
if (!parentUri) return null;
|
|
322
|
+
return this.annotations.find((a) => a.id === parentUri.source) ?? null;
|
|
323
|
+
}
|
|
324
|
+
createAnnotation(fromAnnotation, type, data, selectors) {
|
|
325
|
+
const styleBody = AnnotationStyleContextBuilder(this.annotationConfig).toAnnotationBody(type);
|
|
326
|
+
const builder = w3cAnnotation(fromAnnotation ?? void 0).setMotivation("tagging").addBody(styleBody);
|
|
327
|
+
if (!fromAnnotation?.id) builder.setId(createId());
|
|
328
|
+
if (data && Object.keys(data).length > 0) {
|
|
329
|
+
data.type = data.type ?? "AnnotationMetadata";
|
|
330
|
+
data.purpose = data.purpose ?? getAnnotationType(builder);
|
|
331
|
+
builder.updateBodyByType(data.type, data);
|
|
332
|
+
}
|
|
333
|
+
for (const selector of selectors) updateSelector(builder, selector);
|
|
334
|
+
return builder.build();
|
|
335
|
+
}
|
|
336
|
+
createLinkAnnotation = (sourceAnnotation, targetAnnotation, type, data) => {
|
|
337
|
+
const styleBody = AnnotationStyleContextBuilder(this.annotationConfig).toAnnotationBody(type);
|
|
338
|
+
const builder = w3cAnnotation().setMotivation("tagging").setId(createId()).addBody(styleBody);
|
|
339
|
+
if (data && Object.keys(data).length > 0) {
|
|
340
|
+
data.type = data.type ?? "AnnotationMetadata";
|
|
341
|
+
data.purpose = data.purpose ?? getAnnotationType(builder);
|
|
342
|
+
builder.updateBodyByType(data.type, data);
|
|
343
|
+
}
|
|
344
|
+
builder.addTarget({ source: sourceAnnotation.id }).addTarget({ source: targetAnnotation.id });
|
|
345
|
+
return builder.build();
|
|
346
|
+
};
|
|
347
|
+
cancel() {
|
|
348
|
+
this.setAnnotations(this.annotations, this.allowedChildrenPerType);
|
|
349
|
+
}
|
|
350
|
+
getSourceUri = (annotation) => {
|
|
351
|
+
const builder = this.getBuilder(annotation);
|
|
352
|
+
const sourceUri = builder.getSourceUri();
|
|
353
|
+
if (!sourceUri) {
|
|
354
|
+
console.warn("no source uri");
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
textPositionSelector: builder.getTextPositionSelector(sourceUri)[0],
|
|
359
|
+
sourceUri
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
getMetadata = (annotation) => {
|
|
363
|
+
return this.getBuilder(annotation).getBodiesByType("AnnotationMetadata")?.[0] ?? null;
|
|
364
|
+
};
|
|
365
|
+
getAnnotationStyle = (annotation) => {
|
|
366
|
+
return getAnnotationStyle(this.getBuilder(annotation));
|
|
367
|
+
};
|
|
368
|
+
getAnnotationType = (annotation) => {
|
|
369
|
+
return getAnnotationType(this.getBuilder(annotation));
|
|
109
370
|
};
|
|
110
|
-
|
|
111
|
-
|
|
371
|
+
createAnnotationFromSelector(type, annotation, selector) {
|
|
372
|
+
const builder = w3cAnnotation(annotation ?? void 0).setMotivation("tagging").setId(createId());
|
|
373
|
+
const styleBody = AnnotationStyleContextBuilder(this.annotationConfig).toAnnotationBody(type);
|
|
374
|
+
builder.addBody(styleBody);
|
|
375
|
+
if (selector) updateSelector(builder, selector);
|
|
376
|
+
return builder.build();
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
var annotationUtils = (annotationConfig) => {
|
|
380
|
+
return new AnnotationUtilsImpl(annotationConfig);
|
|
381
|
+
};
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region ../annotation-core/src/lib/utils/annotation-render.style.ts
|
|
384
|
+
var defaultRender = (utils) => (annotation) => {
|
|
385
|
+
return (utils?.getAnnotationStyle(annotation))?.target ?? "default";
|
|
386
|
+
};
|
|
387
|
+
var styleFn = (listStyles, utils) => (annotation) => {
|
|
388
|
+
const style = utils?.getAnnotationStyle(annotation);
|
|
389
|
+
if (!style) return "default";
|
|
390
|
+
const styleId = style?.id ?? "default";
|
|
391
|
+
if (!listStyles.includes(styleId)) {
|
|
392
|
+
Debugger.debug("styleFn", `No style found for ${styleId}`);
|
|
393
|
+
if (style.color) return { default: createHighlightStyle(style.color) };
|
|
394
|
+
return "default";
|
|
395
|
+
}
|
|
396
|
+
return styleId;
|
|
397
|
+
};
|
|
112
398
|
//#endregion
|
|
113
|
-
//#region
|
|
114
|
-
|
|
115
|
-
if (
|
|
399
|
+
//#region ../annotation-core/src/lib/utils/annotation-configuration.factory.ts
|
|
400
|
+
var groupById = (defs, valueKey) => {
|
|
401
|
+
if (!defs) return {};
|
|
402
|
+
return defs.reduce((acc, def) => {
|
|
403
|
+
acc[def.id] = valueKey ? def[valueKey] : def;
|
|
404
|
+
return acc;
|
|
405
|
+
}, {});
|
|
406
|
+
};
|
|
407
|
+
var createAnnotationConfiguration = (annotationDefinitions, utils, textAdapter, annotationAdapter) => {
|
|
408
|
+
const definitions = annotationDefinitions ?? [];
|
|
409
|
+
const definitionsMap = groupById(definitions);
|
|
410
|
+
const rootTypes = definitions.filter((d) => d.annotation.isRoot).map((d) => ({
|
|
411
|
+
key: d.id,
|
|
412
|
+
label: d.label
|
|
413
|
+
}));
|
|
414
|
+
const styles = groupById(definitions, "style");
|
|
415
|
+
if (!styles["default"]) styles["default"] = {
|
|
416
|
+
label: "Annotation",
|
|
417
|
+
isRoot: true,
|
|
418
|
+
style: { default: createHighlightStyle("#dd7777") },
|
|
419
|
+
allowedChildren: [],
|
|
420
|
+
allowedLinks: [],
|
|
421
|
+
views: {}
|
|
422
|
+
};
|
|
423
|
+
const listStyles = Object.keys(styles);
|
|
424
|
+
const allowedChildrenPerType = groupById(definitions, "allowedChildren");
|
|
425
|
+
const defaultAnnotationAdapter = (source) => W3CAnnotationAdapter(source ? { sourceUri: source.uri } : {});
|
|
426
|
+
const renderParams = () => ({ renderFn: defaultRender(utils) });
|
|
427
|
+
const styleParams = () => ({ styleFn: styleFn(listStyles, utils) });
|
|
428
|
+
const _createAnnotatedText = (id, sourceModel) => {
|
|
429
|
+
const _textAdapter = textAdapter?.() ?? PlainTextAdapter();
|
|
430
|
+
const annotatedText = createAnnotatedText(id, {
|
|
431
|
+
annotationAdapter: annotationAdapter?.() ?? defaultAnnotationAdapter(sourceModel),
|
|
432
|
+
textAdapter: _textAdapter
|
|
433
|
+
});
|
|
434
|
+
annotatedText.setSnapper(new WordSnapper()).setRenderParams(renderParams()).setStyleParams(styleParams()).registerStyles(styles);
|
|
435
|
+
if (sourceModel) {
|
|
436
|
+
const { content } = sourceModel;
|
|
437
|
+
annotatedText.setText(content.text).setTextAdapterParams({ textDirection: content.textDirection });
|
|
438
|
+
}
|
|
439
|
+
return annotatedText;
|
|
440
|
+
};
|
|
441
|
+
return {
|
|
442
|
+
allowedChildrenPerType,
|
|
443
|
+
definitions,
|
|
444
|
+
getDefinition: (id) => {
|
|
445
|
+
return definitionsMap[id] ?? void 0;
|
|
446
|
+
},
|
|
447
|
+
rootTypes,
|
|
448
|
+
createAnnotatedText: _createAnnotatedText
|
|
449
|
+
};
|
|
450
|
+
};
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/lib/utils/annotation.context-builder.ts
|
|
453
|
+
var ANNOTATION_DEF_CONFIG_TOKEN = Symbol("ANNOTATION_DEF_CONFIG_TOKEN");
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorateMetadata.js
|
|
456
|
+
function __decorateMetadata(k, v) {
|
|
457
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
116
458
|
}
|
|
117
459
|
//#endregion
|
|
118
|
-
//#region \0@oxc-project+runtime@0.
|
|
119
|
-
function
|
|
120
|
-
return function(
|
|
121
|
-
|
|
460
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorateParam.js
|
|
461
|
+
function __decorateParam(paramIndex, decorator) {
|
|
462
|
+
return function(target, key) {
|
|
463
|
+
decorator(target, key, paramIndex);
|
|
122
464
|
};
|
|
123
465
|
}
|
|
124
466
|
//#endregion
|
|
125
|
-
//#region \0@oxc-project+runtime@0.
|
|
126
|
-
function
|
|
127
|
-
var
|
|
128
|
-
if (typeof Reflect
|
|
129
|
-
else for (var
|
|
130
|
-
return
|
|
467
|
+
//#region \0@oxc-project+runtime@0.139.0/helpers/esm/decorate.js
|
|
468
|
+
function __decorate(decorators, target, key, desc) {
|
|
469
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
470
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
471
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
472
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
131
473
|
}
|
|
132
474
|
//#endregion
|
|
133
|
-
//#region
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
constructor(
|
|
140
|
-
this.
|
|
141
|
-
|
|
142
|
-
async findAllGrouped() {
|
|
143
|
-
return await this.setDefinitions(), Promise.resolve(this.groupedDefinitions);
|
|
475
|
+
//#region src/lib/context/annotation-context.service.ts
|
|
476
|
+
var AnnotationContextService = class AnnotationContextService {
|
|
477
|
+
configRegistry;
|
|
478
|
+
annotationDefConfig;
|
|
479
|
+
contextConfigMap = /* @__PURE__ */ new Map();
|
|
480
|
+
prefixMap = /* @__PURE__ */ new Map();
|
|
481
|
+
constructor(configRegistry, annotationDefConfig) {
|
|
482
|
+
this.configRegistry = configRegistry;
|
|
483
|
+
this.annotationDefConfig = annotationDefConfig;
|
|
144
484
|
}
|
|
145
|
-
async
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
485
|
+
async reloadAll() {
|
|
486
|
+
this.contextConfigMap.clear();
|
|
487
|
+
this.configRegistry.findAll().forEach((resource) => {
|
|
488
|
+
const context = createAnnotationContext(this.annotationDefConfig, resource);
|
|
489
|
+
this.contextConfigMap.set(resource.id, context);
|
|
490
|
+
this.prefixMap.set(context.prefix, resource.id);
|
|
491
|
+
});
|
|
150
492
|
}
|
|
151
|
-
async
|
|
152
|
-
|
|
493
|
+
async findById(annotationId) {
|
|
494
|
+
const find = this.contextConfigMap.get(annotationId);
|
|
495
|
+
if (find) return find;
|
|
496
|
+
const resource = await this.configRegistry.findById(annotationId);
|
|
497
|
+
if (!resource) return null;
|
|
498
|
+
const context = createAnnotationContext(this.annotationDefConfig, resource);
|
|
499
|
+
this.contextConfigMap.set(annotationId, context);
|
|
500
|
+
return context;
|
|
153
501
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
502
|
+
getResourceIdFromUri = (uri) => {
|
|
503
|
+
for (const prefix of this.prefixMap.keys()) if (uri.startsWith(prefix)) return uri.substring(prefix.length);
|
|
504
|
+
return null;
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
AnnotationContextService = __decorate([
|
|
508
|
+
Injectable(),
|
|
509
|
+
__decorateParam(0, Inject(ResourceConfigRegistry)),
|
|
510
|
+
__decorateParam(1, Inject(ANNOTATION_DEF_CONFIG_TOKEN)),
|
|
511
|
+
__decorateMetadata("design:paramtypes", [typeof ResourceConfigRegistry === "undefined" ? Object : ResourceConfigRegistry, Object])
|
|
512
|
+
], AnnotationContextService);
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/lib/annotation/annotation.mapper.service.ts
|
|
515
|
+
var AnnotationW3cMapperService = class AnnotationW3cMapperService {
|
|
516
|
+
contextService;
|
|
517
|
+
constructor(contextService) {
|
|
518
|
+
this.contextService = contextService;
|
|
159
519
|
}
|
|
160
|
-
async
|
|
161
|
-
|
|
520
|
+
async getW3CAnnotation(type, annotation) {
|
|
521
|
+
const annotationDef = await this.contextService.findById(type);
|
|
522
|
+
return this.mapToW3CAnnotation(annotationDef, annotation);
|
|
162
523
|
}
|
|
163
|
-
async
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return t.context;
|
|
524
|
+
async fromW3CAnnotation(type, annotation) {
|
|
525
|
+
const annotationDef = await this.contextService.findById(type);
|
|
526
|
+
return this.mapFromW3CAnnotation(annotationDef, annotation);
|
|
167
527
|
}
|
|
168
528
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
], P);
|
|
529
|
+
AnnotationW3cMapperService = __decorate([__decorateParam(0, Inject(AnnotationContextService)), __decorateMetadata("design:paramtypes", [typeof AnnotationContextService === "undefined" ? Object : AnnotationContextService])], AnnotationW3cMapperService);
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/lib/prefix.ts
|
|
532
|
+
var SCHEMA_PREFIX = "annotation-editor";
|
|
174
533
|
//#endregion
|
|
175
|
-
//#region
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
constructor(
|
|
180
|
-
|
|
534
|
+
//#region src/lib/annotation-namespace.controller.ts
|
|
535
|
+
var AnnotationNamespaceController = class AnnotationNamespaceController {
|
|
536
|
+
service;
|
|
537
|
+
annotationContextService;
|
|
538
|
+
constructor(service, annotationContextService) {
|
|
539
|
+
this.service = service;
|
|
540
|
+
this.annotationContextService = annotationContextService;
|
|
541
|
+
}
|
|
542
|
+
async listNames() {
|
|
543
|
+
const basePath = process.env["API_URL"] ?? "";
|
|
544
|
+
const base = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
545
|
+
return { annotations: (await this.service.getAll()).map((a) => ({
|
|
546
|
+
id: a.id,
|
|
547
|
+
name: a.name,
|
|
548
|
+
schemas: `${base}/${SCHEMA_PREFIX}/${a.id}/schemas`,
|
|
549
|
+
jsonld: `${base}/ns/${a.id}.jsonld`
|
|
550
|
+
})) };
|
|
551
|
+
}
|
|
552
|
+
async getJsonLd_(id) {
|
|
553
|
+
return (await this.annotationContextService.findById(id))?.jsonLd;
|
|
181
554
|
}
|
|
182
|
-
reloadDefinitions = () => this.config.isDev && this._loaderFn ? Promise.resolve(this._loaderFn()) : Promise.resolve(this._initialDefinitions ?? []);
|
|
183
555
|
};
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
556
|
+
__decorate([
|
|
557
|
+
Get(),
|
|
558
|
+
__decorateMetadata("design:type", Function),
|
|
559
|
+
__decorateMetadata("design:paramtypes", []),
|
|
560
|
+
__decorateMetadata("design:returntype", Promise)
|
|
561
|
+
], AnnotationNamespaceController.prototype, "listNames", null);
|
|
562
|
+
__decorate([
|
|
563
|
+
Get(":id.jsonld"),
|
|
564
|
+
__decorateParam(0, Param("id")),
|
|
565
|
+
__decorateMetadata("design:type", Function),
|
|
566
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
567
|
+
__decorateMetadata("design:returntype", Promise)
|
|
568
|
+
], AnnotationNamespaceController.prototype, "getJsonLd_", null);
|
|
569
|
+
AnnotationNamespaceController = __decorate([
|
|
570
|
+
Controller("ns"),
|
|
571
|
+
ApiTags("Annotations NS"),
|
|
572
|
+
__decorateParam(0, Inject(ResourceConfigRegistry)),
|
|
573
|
+
__decorateParam(1, Inject(ANNOTATION_DEF_CONFIG_TOKEN)),
|
|
574
|
+
__decorateMetadata("design:paramtypes", [typeof ResourceConfigRegistry === "undefined" ? Object : ResourceConfigRegistry, Object])
|
|
575
|
+
], AnnotationNamespaceController);
|
|
193
576
|
//#endregion
|
|
194
|
-
//#region
|
|
195
|
-
var
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
577
|
+
//#region src/lib/annotation/annotation.controller.ts
|
|
578
|
+
var AnnotationController = class AnnotationController {
|
|
579
|
+
annotationRepository;
|
|
580
|
+
wrapper;
|
|
581
|
+
contextService;
|
|
582
|
+
constructor(annotationRepository, wrapper, contextService) {
|
|
583
|
+
this.annotationRepository = annotationRepository;
|
|
584
|
+
this.wrapper = wrapper;
|
|
585
|
+
this.contextService = contextService;
|
|
203
586
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
constructor(e, t) {
|
|
209
|
-
this.service = e, this.annotationDefConfig = t;
|
|
587
|
+
async create(type, annotationBody) {
|
|
588
|
+
const parsed = await this.wrapper.fromW3CAnnotation(type, annotationBody);
|
|
589
|
+
const annotation = await this.annotationRepository.create(parsed);
|
|
590
|
+
return this.get(annotation.id);
|
|
210
591
|
}
|
|
211
|
-
|
|
212
|
-
|
|
592
|
+
async getByType(id) {
|
|
593
|
+
const { annotation, type } = await this.annotationRepository.findOne(id);
|
|
594
|
+
return this.wrapper.getW3CAnnotation(type, annotation);
|
|
213
595
|
}
|
|
214
|
-
async
|
|
215
|
-
|
|
596
|
+
async get(id) {
|
|
597
|
+
const _id = this.contextService.getResourceIdFromUri(id) ?? id;
|
|
598
|
+
const { annotation, type } = await this.annotationRepository.findOne(_id);
|
|
599
|
+
return this.wrapper.getW3CAnnotation(type, annotation);
|
|
216
600
|
}
|
|
217
|
-
async
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
json_schema: t.json_schema,
|
|
223
|
-
ui_schema: t.ui_schema,
|
|
224
|
-
metadata_schema: t.metadata_schema,
|
|
225
|
-
columns: t.columns,
|
|
226
|
-
isRoot: t.isRoot,
|
|
227
|
-
allowedChildren: t.allowedChildren,
|
|
228
|
-
allowedLinks: t.allowedLinks,
|
|
229
|
-
type: t.type,
|
|
230
|
-
icon: t.icon,
|
|
231
|
-
target: t.target
|
|
232
|
-
};
|
|
601
|
+
async patch(type, id, annotationBody) {
|
|
602
|
+
const _id = this.contextService.getResourceIdFromUri(id) ?? id;
|
|
603
|
+
const _annotation = await this.wrapper.fromW3CAnnotation(type, annotationBody);
|
|
604
|
+
const annotation = await this.annotationRepository.update(_id, _annotation);
|
|
605
|
+
return this.get(annotation.id);
|
|
233
606
|
}
|
|
234
|
-
async
|
|
235
|
-
|
|
607
|
+
async delete(id) {
|
|
608
|
+
const _id = this.contextService.getResourceIdFromUri(id) ?? id;
|
|
609
|
+
return this.annotationRepository.delete(_id);
|
|
236
610
|
}
|
|
237
|
-
async
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
async getJsonLd(e) {
|
|
241
|
-
let t = await this.service.getContextBuilder(e);
|
|
242
|
-
return {
|
|
243
|
-
jsonLd: t.toJsonLdContext(),
|
|
244
|
-
forms: t.toJsonSchema()
|
|
245
|
-
};
|
|
611
|
+
async deleteType(id) {
|
|
612
|
+
const _id = this.contextService.getResourceIdFromUri(id) ?? id;
|
|
613
|
+
return this.annotationRepository.delete(_id);
|
|
246
614
|
}
|
|
247
615
|
};
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
616
|
+
__decorate([
|
|
617
|
+
Post(":type"),
|
|
618
|
+
ApiOperation({ summary: "Create a W3C annotation" }),
|
|
619
|
+
ApiBody({ description: "W3C annotation body" }),
|
|
620
|
+
ApiResponse({
|
|
621
|
+
status: 201,
|
|
622
|
+
description: "The created W3C annotation"
|
|
623
|
+
}),
|
|
624
|
+
__decorateParam(0, Param("type")),
|
|
625
|
+
__decorateParam(1, Body()),
|
|
626
|
+
__decorateMetadata("design:type", Function),
|
|
627
|
+
__decorateMetadata("design:paramtypes", [String, Object]),
|
|
628
|
+
__decorateMetadata("design:returntype", Promise)
|
|
629
|
+
], AnnotationController.prototype, "create", null);
|
|
630
|
+
__decorate([
|
|
631
|
+
Get(":type/:id"),
|
|
632
|
+
ApiOperation({ summary: "Get one annotation by id" }),
|
|
633
|
+
ApiParam({
|
|
634
|
+
name: "id",
|
|
635
|
+
type: "string"
|
|
636
|
+
}),
|
|
637
|
+
ApiParam({
|
|
638
|
+
name: "type",
|
|
639
|
+
type: "string"
|
|
640
|
+
}),
|
|
641
|
+
ApiResponse({
|
|
642
|
+
status: 200,
|
|
643
|
+
description: "The W3C annotation"
|
|
644
|
+
}),
|
|
645
|
+
__decorateParam(0, Param("id")),
|
|
646
|
+
__decorateMetadata("design:type", Function),
|
|
647
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
648
|
+
__decorateMetadata("design:returntype", Promise)
|
|
649
|
+
], AnnotationController.prototype, "getByType", null);
|
|
650
|
+
__decorate([
|
|
651
|
+
Get(":id"),
|
|
652
|
+
ApiOperation({ summary: "Get one annotation by id" }),
|
|
653
|
+
ApiParam({
|
|
654
|
+
name: "id",
|
|
655
|
+
type: "string"
|
|
656
|
+
}),
|
|
657
|
+
ApiResponse({
|
|
658
|
+
status: 200,
|
|
659
|
+
description: "The W3C annotation"
|
|
660
|
+
}),
|
|
661
|
+
__decorateParam(0, Param("id")),
|
|
662
|
+
__decorateMetadata("design:type", Function),
|
|
663
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
664
|
+
__decorateMetadata("design:returntype", Promise)
|
|
665
|
+
], AnnotationController.prototype, "get", null);
|
|
666
|
+
__decorate([
|
|
667
|
+
Patch(":type/:id"),
|
|
668
|
+
ApiOperation({ summary: "Update an annotation" }),
|
|
669
|
+
ApiParam({
|
|
670
|
+
name: "id",
|
|
671
|
+
type: "string"
|
|
672
|
+
}),
|
|
673
|
+
ApiBody({ description: "W3C annotation body" }),
|
|
674
|
+
ApiResponse({
|
|
675
|
+
status: 200,
|
|
676
|
+
description: "The updated W3C annotation"
|
|
677
|
+
}),
|
|
678
|
+
__decorateParam(0, Param("type")),
|
|
679
|
+
__decorateParam(1, Param("id")),
|
|
680
|
+
__decorateParam(2, Body()),
|
|
681
|
+
__decorateMetadata("design:type", Function),
|
|
682
|
+
__decorateMetadata("design:paramtypes", [
|
|
683
|
+
String,
|
|
684
|
+
String,
|
|
685
|
+
Object
|
|
686
|
+
]),
|
|
687
|
+
__decorateMetadata("design:returntype", Promise)
|
|
688
|
+
], AnnotationController.prototype, "patch", null);
|
|
689
|
+
__decorate([
|
|
690
|
+
Delete(":id"),
|
|
691
|
+
ApiOperation({ summary: "Delete an annotation" }),
|
|
692
|
+
ApiParam({
|
|
693
|
+
name: "id",
|
|
694
|
+
type: "string"
|
|
695
|
+
}),
|
|
696
|
+
ApiResponse({
|
|
697
|
+
status: 200,
|
|
698
|
+
description: "Annotation deleted"
|
|
699
|
+
}),
|
|
700
|
+
__decorateParam(0, Param("id")),
|
|
701
|
+
__decorateMetadata("design:type", Function),
|
|
702
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
703
|
+
__decorateMetadata("design:returntype", Promise)
|
|
704
|
+
], AnnotationController.prototype, "delete", null);
|
|
705
|
+
__decorate([
|
|
706
|
+
Delete(":type/:id"),
|
|
707
|
+
ApiOperation({ summary: "Delete an annotation" }),
|
|
708
|
+
ApiParam({
|
|
709
|
+
name: "id",
|
|
710
|
+
type: "string"
|
|
711
|
+
}),
|
|
712
|
+
ApiResponse({
|
|
713
|
+
status: 200,
|
|
714
|
+
description: "Annotation deleted"
|
|
715
|
+
}),
|
|
716
|
+
__decorateParam(0, Param("id")),
|
|
717
|
+
__decorateMetadata("design:type", Function),
|
|
718
|
+
__decorateMetadata("design:paramtypes", [String]),
|
|
719
|
+
__decorateMetadata("design:returntype", Promise)
|
|
720
|
+
], AnnotationController.prototype, "deleteType", null);
|
|
721
|
+
AnnotationController = __decorate([
|
|
722
|
+
Controller(`${SCHEMA_PREFIX}/annotation`),
|
|
723
|
+
ApiTags("Annotations"),
|
|
724
|
+
__decorateParam(0, Inject(AnnotationCrudRepository)),
|
|
725
|
+
__decorateParam(1, Inject(AnnotationW3cMapperService)),
|
|
726
|
+
__decorateParam(2, Inject(AnnotationContextService)),
|
|
727
|
+
__decorateMetadata("design:paramtypes", [
|
|
728
|
+
typeof AnnotationCrudRepository === "undefined" ? Object : AnnotationCrudRepository,
|
|
729
|
+
typeof AnnotationW3cMapperService === "undefined" ? Object : AnnotationW3cMapperService,
|
|
730
|
+
typeof AnnotationContextService === "undefined" ? Object : AnnotationContextService
|
|
731
|
+
])
|
|
732
|
+
], AnnotationController);
|
|
289
733
|
//#endregion
|
|
290
|
-
//#region
|
|
291
|
-
var
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
findAll = () => [...this.byType.values()];
|
|
314
|
-
getResourceForType = (e) => this.byType.get(e) ?? null;
|
|
315
|
-
getResourceFromUri = (e) => {
|
|
316
|
-
for (let t of this.byType.values()) if (e.startsWith(t.prefix)) return {
|
|
317
|
-
...t,
|
|
318
|
-
id: e.substring(t.prefix.length)
|
|
319
|
-
};
|
|
320
|
-
return null;
|
|
734
|
+
//#region src/lib/utils/schemaEnricher.utils.ts
|
|
735
|
+
var createSchemaEnricher = (baseUrl = "") => (schema) => {
|
|
736
|
+
const uri = `${baseUrl}${SCHEMA_PREFIX}/annotation/${schema.route}`;
|
|
737
|
+
const uriId = `${uri}/{id}`;
|
|
738
|
+
schema.operations = {
|
|
739
|
+
findOne: schema.operations.findOne ?? {
|
|
740
|
+
uri: uriId,
|
|
741
|
+
method: "get"
|
|
742
|
+
},
|
|
743
|
+
update: schema.operations.update ?? {
|
|
744
|
+
uri: uriId,
|
|
745
|
+
method: "patch"
|
|
746
|
+
},
|
|
747
|
+
delete: schema.operations.delete ?? {
|
|
748
|
+
uri: uriId,
|
|
749
|
+
method: "delete"
|
|
750
|
+
},
|
|
751
|
+
create: schema.operations.create ?? {
|
|
752
|
+
uri,
|
|
753
|
+
method: "post"
|
|
754
|
+
},
|
|
755
|
+
findAll: schema.operations.findAll
|
|
321
756
|
};
|
|
757
|
+
return { ...schema };
|
|
322
758
|
};
|
|
323
|
-
z = N([r(), j("design:paramtypes", [Array])], z);
|
|
324
759
|
//#endregion
|
|
325
|
-
//#region
|
|
326
|
-
var
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
module: B,
|
|
343
|
-
global: !0,
|
|
344
|
-
controllers: [L],
|
|
760
|
+
//#region src/lib/annotation-api.module.ts
|
|
761
|
+
var _AnnotationApiModule;
|
|
762
|
+
registerResourceExtensions({ annotation: AnnotationConfigSchema });
|
|
763
|
+
var AnnotationApiModule = _AnnotationApiModule = class AnnotationApiModule {
|
|
764
|
+
static async forResourceDir(resourcePath, datasourcePath, config, annotation) {
|
|
765
|
+
const _config = resolveConfig(config);
|
|
766
|
+
const crouton = await CroutonApiModule.forResourceDir(resourcePath, datasourcePath, {
|
|
767
|
+
baseUrl: "",
|
|
768
|
+
prefix: SCHEMA_PREFIX,
|
|
769
|
+
extensions: { annotation: AnnotationConfigSchema },
|
|
770
|
+
schemaEnricher: createSchemaEnricher(_config.baseUrl)
|
|
771
|
+
});
|
|
772
|
+
if (annotation) return {
|
|
773
|
+
module: _AnnotationApiModule,
|
|
774
|
+
global: true,
|
|
775
|
+
imports: [crouton],
|
|
776
|
+
controllers: [AnnotationNamespaceController, AnnotationController],
|
|
345
777
|
providers: [
|
|
778
|
+
AnnotationContextService,
|
|
346
779
|
{
|
|
347
|
-
provide:
|
|
348
|
-
useValue:
|
|
780
|
+
provide: ANNOTATION_DEF_CONFIG_TOKEN,
|
|
781
|
+
useValue: _config
|
|
349
782
|
},
|
|
350
783
|
{
|
|
351
|
-
provide:
|
|
352
|
-
|
|
784
|
+
provide: AnnotationCrudRepository,
|
|
785
|
+
useExisting: annotation.repository
|
|
353
786
|
},
|
|
354
787
|
{
|
|
355
|
-
provide:
|
|
356
|
-
|
|
788
|
+
provide: AnnotationW3cMapperService,
|
|
789
|
+
useExisting: annotation.mapper
|
|
357
790
|
}
|
|
358
791
|
],
|
|
359
|
-
exports: [
|
|
792
|
+
exports: [AnnotationContextService]
|
|
793
|
+
};
|
|
794
|
+
return {
|
|
795
|
+
module: _AnnotationApiModule,
|
|
796
|
+
global: true,
|
|
797
|
+
imports: [crouton],
|
|
798
|
+
controllers: [AnnotationNamespaceController],
|
|
799
|
+
providers: [AnnotationContextService, {
|
|
800
|
+
provide: ANNOTATION_DEF_CONFIG_TOKEN,
|
|
801
|
+
useValue: _config
|
|
802
|
+
}],
|
|
803
|
+
exports: [AnnotationContextService]
|
|
360
804
|
};
|
|
361
805
|
}
|
|
362
806
|
};
|
|
363
|
-
|
|
807
|
+
AnnotationApiModule = _AnnotationApiModule = __decorate([Module({
|
|
364
808
|
controllers: [],
|
|
365
809
|
providers: [],
|
|
366
810
|
exports: []
|
|
367
|
-
})],
|
|
811
|
+
})], AnnotationApiModule);
|
|
368
812
|
//#endregion
|
|
369
|
-
export {
|
|
813
|
+
export { AnnotationApiModule, AnnotationConfigSchema, AnnotationContextService, AnnotationCrudRepository, AnnotationJsonResourceSchema, AnnotationJsonResourceShape, AnnotationMetadataType, AnnotationResourceSchema, AnnotationStyleContextBuilder, AnnotationStyleType, AnnotationW3cMapperService, BASELINE_RESOURCE_VERSION, CURRENT_RESOURCE_VERSION, KeyLabelSchema, SourceModelSchema, SourceTextSchema, annotationColumnDefinition, annotationUtils, baseContextBuilder, buildGridStyle, buildPrefix, createAnnotationConfiguration, createAnnotationContext, createAnnotationStyleBodyUnsafe, defaultRender, getPaneArea, resolveConfig, styleFn };
|