@ghentcdh/annotation-vue 0.0.1-alpha.6 → 0.0.1-alpha.9
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.js +103 -101
- package/index.umd.cjs +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { z as e } from "zod";
|
|
2
2
|
import { contextBuilder as t } from "@ghentcdh/w3c-utils";
|
|
3
3
|
import { createHighlightStyle as n } from "@ghentcdh/annotated-text";
|
|
4
|
-
import {
|
|
4
|
+
import { ControlBuilder as r, LayoutBuilder as i } from "@ghentcdh/crouton-forms-vue";
|
|
5
|
+
import { computed as a, defineComponent as o, h as s, inject as c, markRaw as l, provide as u, reactive as d, ref as f } from "vue";
|
|
5
6
|
//#region packages/annotation-vue/src/lib/service/annotation-definition.service.ts
|
|
6
|
-
var
|
|
7
|
+
var p = class {
|
|
7
8
|
definitions = [];
|
|
8
9
|
groupedDefinitions = {};
|
|
9
10
|
constructor(e = []) {
|
|
@@ -27,11 +28,11 @@ var d = class {
|
|
|
27
28
|
getContextBuilder(e) {
|
|
28
29
|
return this.findById(e)?.context;
|
|
29
30
|
}
|
|
30
|
-
},
|
|
31
|
+
}, m = "AnnotationMetadata", h = e.object({});
|
|
31
32
|
e.object({
|
|
32
33
|
id: e.string(),
|
|
33
34
|
name: e.string(),
|
|
34
|
-
columns: e.array(
|
|
35
|
+
columns: e.array(h),
|
|
35
36
|
json_schema: e.any().optional(),
|
|
36
37
|
json_ld: e.any().optional(),
|
|
37
38
|
ui_schema: e.any().optional(),
|
|
@@ -51,26 +52,26 @@ e.object({
|
|
|
51
52
|
});
|
|
52
53
|
//#endregion
|
|
53
54
|
//#region packages/annotation-core/src/lib/utils/annotation.context-builder.ts
|
|
54
|
-
var
|
|
55
|
+
var g = {
|
|
55
56
|
baseUrl: "http://localhost:3000/",
|
|
56
57
|
app: "ghentcdh",
|
|
57
58
|
prefix: "ghentcdh",
|
|
58
59
|
isDev: !1,
|
|
59
60
|
cacheTTLms: 1200 * 1e3
|
|
60
|
-
},
|
|
61
|
-
let t = e.baseUrl ??
|
|
61
|
+
}, _ = (e = {}) => {
|
|
62
|
+
let t = e.baseUrl ?? g.baseUrl, n = t.endsWith("/") ? t : `${t}/`, r = e.isDev ?? !1, i = r ? 0 : 1200 * 1e3;
|
|
62
63
|
return {
|
|
63
64
|
baseUrl: n,
|
|
64
65
|
contextUrl: `${n}ns/`,
|
|
65
|
-
app: e.app ??
|
|
66
|
-
prefix: e.prefix ??
|
|
66
|
+
app: e.app ?? g.app,
|
|
67
|
+
prefix: e.prefix ?? g.prefix,
|
|
67
68
|
isDev: r,
|
|
68
69
|
cacheTTLms: i
|
|
69
70
|
};
|
|
70
|
-
},
|
|
71
|
-
let { prefix: r, baseUrl: i, contextUrl: a } =
|
|
71
|
+
}, v = (e, n) => {
|
|
72
|
+
let { prefix: r, baseUrl: i, contextUrl: a } = _(n), o = m;
|
|
72
73
|
return t(r, i).setType(r, o).addPrefix(e, `${r}:${e}`).setContextUri(`${a}${e}.jsonld`);
|
|
73
|
-
},
|
|
74
|
+
}, y = e.object({
|
|
74
75
|
id: e.string(),
|
|
75
76
|
name: e.string(),
|
|
76
77
|
target: e.enum([
|
|
@@ -79,50 +80,51 @@ var m = {
|
|
|
79
80
|
"highlight"
|
|
80
81
|
]).optional().default("underline"),
|
|
81
82
|
color: e.string().optional()
|
|
82
|
-
}),
|
|
83
|
-
let { prefix: n, baseUrl: r, contextUrl: i } =
|
|
84
|
-
return t(n, r).setType(n,
|
|
85
|
-
},
|
|
86
|
-
let t =
|
|
87
|
-
if (e.fieldInput)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
options: {}
|
|
111
|
-
}), w = (t) => {
|
|
83
|
+
}), b = "AnnotationStyle", x = (e) => {
|
|
84
|
+
let { prefix: n, baseUrl: r, contextUrl: i } = _(e);
|
|
85
|
+
return t(n, r).setType(n, b).setContextUri(`${i}${b}.jsonld`).parseZodSchema(y);
|
|
86
|
+
}, S = (e) => {
|
|
87
|
+
let t = r.properties(e.id);
|
|
88
|
+
if (!e.fieldInput) return t;
|
|
89
|
+
let { type: n, options: i = {} } = e.fieldInput;
|
|
90
|
+
return n === "autocomplete" ? t.autocomplete({
|
|
91
|
+
...i.uri && { uri: i.uri },
|
|
92
|
+
...i.resource && { resource: i.resource },
|
|
93
|
+
...i.valueKey && { valueKey: i.valueKey },
|
|
94
|
+
...i.labelKey && { labelKey: i.labelKey },
|
|
95
|
+
...i.enableCreate !== void 0 && { enableCreate: i.enableCreate },
|
|
96
|
+
...i.colspan && { colspan: i.colspan }
|
|
97
|
+
}) : n === "select" ? t.select({
|
|
98
|
+
...i.values && { values: i.values },
|
|
99
|
+
...i.clearable !== void 0 && { clearable: i.clearable },
|
|
100
|
+
...i.storeValue !== void 0 && { storeValue: i.storeValue },
|
|
101
|
+
...i.emitObject !== void 0 && { emitObject: i.emitObject },
|
|
102
|
+
...i.colspan && { colspan: i.colspan }
|
|
103
|
+
}) : t.control(n, { ...i.colspan && { colspan: i.colspan } });
|
|
104
|
+
}, C = (e) => {
|
|
105
|
+
let t = i.grid();
|
|
106
|
+
return e.filter((e) => !e.hiddenInForm).forEach((e) => t.addControl(S(e))), t.build();
|
|
107
|
+
}, w = (e) => {
|
|
108
|
+
let t = i.grid();
|
|
109
|
+
return e.filter((e) => !e.hiddenInMetadata).forEach((e) => t.addControl(S(e).readonly())), t.build();
|
|
110
|
+
}, T = (t) => {
|
|
112
111
|
if (t.type === "object" && t.properties) {
|
|
113
112
|
let n = {};
|
|
114
|
-
for (let [e, r] of Object.entries(t.properties)) n[e] =
|
|
113
|
+
for (let [e, r] of Object.entries(t.properties)) n[e] = T(r);
|
|
115
114
|
return e.object(n);
|
|
116
115
|
}
|
|
117
116
|
return e.string();
|
|
118
|
-
},
|
|
119
|
-
let i =
|
|
117
|
+
}, E = (t, n, r) => {
|
|
118
|
+
let i = v(t, r), a = n.columns ?? [];
|
|
120
119
|
if (!a.length) return i;
|
|
121
120
|
let o = {};
|
|
122
|
-
for (let e of a)
|
|
121
|
+
for (let e of a) if (e.type) {
|
|
122
|
+
let t = T(e.type);
|
|
123
|
+
o[e.id] = e.required === !1 ? t.optional() : t;
|
|
124
|
+
}
|
|
123
125
|
return Object.keys(o).length ? i.parseZodSchema(e.object(o)) : i;
|
|
124
|
-
},
|
|
125
|
-
let r = n(e.id, e, t), i = e.columns ?? [], a = i.length > 0, o = e.ui_schema ?? (a ?
|
|
126
|
+
}, D = (e, t, n = E) => {
|
|
127
|
+
let r = n(e.id, e, t), i = e.columns ?? [], a = i.length > 0, o = e.ui_schema ?? (a ? C(i) : void 0), s = e.metadata_schema ?? (a ? w(i) : void 0), c = {
|
|
126
128
|
id: e.id,
|
|
127
129
|
name: e.name,
|
|
128
130
|
color: e.color,
|
|
@@ -133,11 +135,11 @@ var m = {
|
|
|
133
135
|
json_schema: o ? r.toJsonSchema() : null
|
|
134
136
|
};
|
|
135
137
|
return o && (c.ui_schema = o), s && (c.metadata_schema = s), e.type && (c.type = e.type), e.icon && (c.icon = e.icon), e.target && (c.target = e.target), e.allowedChildren && (c.allowedChildren = e.allowedChildren), e.allowedLinks && (c.allowedLinks = e.allowedLinks), c;
|
|
136
|
-
},
|
|
138
|
+
}, O = (e, t, n) => e.map((e) => D(e, t, n)), k = (e) => "default" in e ? e.default : e, A = (e, t, n) => j(Object.values(e).map(k), t, n), j = (e, t, n) => O(e, t, n), M = async (e) => {
|
|
137
139
|
let t = await fetch(e);
|
|
138
140
|
if (!t.ok) throw Error(`Failed to fetch annotation definitions: ${t.status} ${t.statusText}`);
|
|
139
141
|
return t.json();
|
|
140
|
-
},
|
|
142
|
+
}, N = async (e, t, n, r = M) => j(await r(e), t, n), P = Symbol("annotation-definitions"), F = (e, t) => e ? e.reduce((e, n) => {
|
|
141
143
|
let r = t[n];
|
|
142
144
|
if (r) {
|
|
143
145
|
let t = {
|
|
@@ -147,7 +149,7 @@ var m = {
|
|
|
147
149
|
r.icon && (t.icon = r.icon), e.push(t);
|
|
148
150
|
}
|
|
149
151
|
return e;
|
|
150
|
-
}, []) : [],
|
|
152
|
+
}, []) : [], I = (e, t, n, r) => {
|
|
151
153
|
let i = {
|
|
152
154
|
uiSchema: e.ui_schema ?? null,
|
|
153
155
|
jsonSchema: e.json_schema ?? null,
|
|
@@ -164,8 +166,8 @@ var m = {
|
|
|
164
166
|
active: r(e.color)
|
|
165
167
|
},
|
|
166
168
|
schema: i,
|
|
167
|
-
allowedChildren:
|
|
168
|
-
allowedLinks:
|
|
169
|
+
allowedChildren: F(e.allowedChildren, t),
|
|
170
|
+
allowedLinks: F(e.allowedLinks, t),
|
|
169
171
|
isRoot: e.isRoot ?? !0,
|
|
170
172
|
icon: e.icon,
|
|
171
173
|
type: e.type,
|
|
@@ -173,20 +175,20 @@ var m = {
|
|
|
173
175
|
context: e.context,
|
|
174
176
|
_core: e
|
|
175
177
|
};
|
|
176
|
-
},
|
|
177
|
-
let { config: t, factory:
|
|
178
|
-
let e =
|
|
179
|
-
return
|
|
180
|
-
}), m =
|
|
181
|
-
|
|
178
|
+
}, L = (e) => {
|
|
179
|
+
let { config: t, factory: r } = e, i = e.createHighlightStyle ?? n, o = e.activeHighlightStyle ?? i, s = l(new p()), c = f([]), u = a(() => {
|
|
180
|
+
let e = s.findAllGrouped();
|
|
181
|
+
return c.value.map((t) => I(t, e, i, o));
|
|
182
|
+
}), m = a(() => u.value.reduce((e, t) => (e[t.id] = t, e), {})), h = (e) => m.value[e], g = (e) => {
|
|
183
|
+
s.setDefinitions(e), c.value = e;
|
|
182
184
|
}, _ = (e) => {
|
|
183
|
-
g(
|
|
185
|
+
g(A(e, t, r));
|
|
184
186
|
}, v = (e) => {
|
|
185
|
-
g(
|
|
186
|
-
}, y =
|
|
187
|
-
return
|
|
187
|
+
g(j(e, t, r));
|
|
188
|
+
}, y = f(!1), b = f(null);
|
|
189
|
+
return d({
|
|
188
190
|
configuration: t,
|
|
189
|
-
definitions:
|
|
191
|
+
definitions: u,
|
|
190
192
|
definitionsMap: m,
|
|
191
193
|
getDefinitionById: h,
|
|
192
194
|
loadFromGlob: _,
|
|
@@ -195,7 +197,7 @@ var m = {
|
|
|
195
197
|
loadFromUrl: async (e, n) => {
|
|
196
198
|
y.value = !0, b.value = null;
|
|
197
199
|
try {
|
|
198
|
-
g(await
|
|
200
|
+
g(await N(e, t, r, n));
|
|
199
201
|
} catch (e) {
|
|
200
202
|
b.value = e instanceof Error ? e : Error(String(e));
|
|
201
203
|
} finally {
|
|
@@ -204,16 +206,16 @@ var m = {
|
|
|
204
206
|
},
|
|
205
207
|
loading: y,
|
|
206
208
|
error: b,
|
|
207
|
-
service:
|
|
209
|
+
service: s
|
|
208
210
|
});
|
|
209
|
-
},
|
|
210
|
-
let t =
|
|
211
|
-
return e.resourceFolder && t.loadFromGlob(e.resourceFolder), e.definitionsUrl && t.loadFromUrl(e.definitionsUrl, e.fetchFn),
|
|
212
|
-
},
|
|
213
|
-
let e =
|
|
211
|
+
}, R = (e) => {
|
|
212
|
+
let t = L(e);
|
|
213
|
+
return e.resourceFolder && t.loadFromGlob(e.resourceFolder), e.definitionsUrl && t.loadFromUrl(e.definitionsUrl, e.fetchFn), u(P, t), t;
|
|
214
|
+
}, z = () => {
|
|
215
|
+
let e = c(P);
|
|
214
216
|
if (!e) throw Error("useAnnotationDefinitions() must be called inside a component that called provideAnnotationDefinitions()");
|
|
215
217
|
return e;
|
|
216
|
-
},
|
|
218
|
+
}, B = (e = "/ns") => {
|
|
217
219
|
let t = e.endsWith("/") ? e.slice(0, -1) : e;
|
|
218
220
|
return {
|
|
219
221
|
all: t,
|
|
@@ -223,7 +225,7 @@ var m = {
|
|
|
223
225
|
schemasById: (e) => `${t}/${e}/schemas`,
|
|
224
226
|
typeJsonLd: (e) => `${t}/${e}/anno.jsonld`
|
|
225
227
|
};
|
|
226
|
-
},
|
|
228
|
+
}, V = o({
|
|
227
229
|
name: "JsonView",
|
|
228
230
|
props: {
|
|
229
231
|
data: {
|
|
@@ -242,32 +244,32 @@ var m = {
|
|
|
242
244
|
}
|
|
243
245
|
},
|
|
244
246
|
setup(e) {
|
|
245
|
-
let t =
|
|
247
|
+
let t = a(() => JSON.stringify(e.data, null, 2)), n = a(() => !1), r = () => {
|
|
246
248
|
navigator.clipboard.writeText(t.value);
|
|
247
|
-
},
|
|
249
|
+
}, i = () => {
|
|
248
250
|
let n = new Blob([t.value], { type: "application/json" }), r = URL.createObjectURL(n), i = document.createElement("a");
|
|
249
251
|
i.href = r, i.download = `${e.title || "data"}.json`, i.click(), URL.revokeObjectURL(r);
|
|
250
252
|
};
|
|
251
|
-
return () =>
|
|
253
|
+
return () => s("div", { style: {
|
|
252
254
|
fontFamily: "monospace",
|
|
253
255
|
fontSize: "13px",
|
|
254
256
|
padding: "16px",
|
|
255
257
|
maxWidth: "100%",
|
|
256
258
|
boxSizing: "border-box"
|
|
257
|
-
} }, [
|
|
259
|
+
} }, [s("div", { style: {
|
|
258
260
|
display: "flex",
|
|
259
261
|
alignItems: "center",
|
|
260
262
|
gap: "8px",
|
|
261
263
|
marginBottom: "12px",
|
|
262
264
|
flexWrap: "wrap"
|
|
263
265
|
} }, [
|
|
264
|
-
e.title ?
|
|
266
|
+
e.title ? s("span", { style: {
|
|
265
267
|
fontWeight: "bold",
|
|
266
268
|
fontSize: "14px",
|
|
267
269
|
marginRight: "auto"
|
|
268
270
|
} }, e.title) : null,
|
|
269
|
-
|
|
270
|
-
onClick:
|
|
271
|
+
s("button", {
|
|
272
|
+
onClick: r,
|
|
271
273
|
style: {
|
|
272
274
|
cursor: "pointer",
|
|
273
275
|
padding: "4px 10px",
|
|
@@ -277,8 +279,8 @@ var m = {
|
|
|
277
279
|
background: "#f5f5f5"
|
|
278
280
|
}
|
|
279
281
|
}, n.value ? "Copied" : "Copy"),
|
|
280
|
-
|
|
281
|
-
onClick:
|
|
282
|
+
s("button", {
|
|
283
|
+
onClick: i,
|
|
282
284
|
style: {
|
|
283
285
|
cursor: "pointer",
|
|
284
286
|
padding: "4px 10px",
|
|
@@ -288,7 +290,7 @@ var m = {
|
|
|
288
290
|
background: "#f5f5f5"
|
|
289
291
|
}
|
|
290
292
|
}, "Download")
|
|
291
|
-
]),
|
|
293
|
+
]), s("pre", { style: {
|
|
292
294
|
margin: 0,
|
|
293
295
|
whiteSpace: "pre-wrap",
|
|
294
296
|
wordBreak: "break-word",
|
|
@@ -299,16 +301,16 @@ var m = {
|
|
|
299
301
|
overflow: "auto"
|
|
300
302
|
} }, t.value)]);
|
|
301
303
|
}
|
|
302
|
-
}),
|
|
304
|
+
}), H = {
|
|
303
305
|
namespace: !0,
|
|
304
306
|
layout: "blank"
|
|
305
|
-
},
|
|
306
|
-
let r = e.endsWith("/") ? e.slice(0, -1) : e, i = { ...
|
|
307
|
+
}, U = (e, t, n) => {
|
|
308
|
+
let r = e.endsWith("/") ? e.slice(0, -1) : e, i = { ...H };
|
|
307
309
|
return [
|
|
308
310
|
{
|
|
309
311
|
path: `${r}/anno.jsonld`,
|
|
310
312
|
name: "annotation-ns-all-jsonld",
|
|
311
|
-
component:
|
|
313
|
+
component: V,
|
|
312
314
|
meta: i,
|
|
313
315
|
props: () => ({
|
|
314
316
|
title: "All JSON-LD contexts",
|
|
@@ -318,13 +320,13 @@ var m = {
|
|
|
318
320
|
{
|
|
319
321
|
path: `${r}/:id.jsonld`,
|
|
320
322
|
name: "annotation-ns-jsonld",
|
|
321
|
-
component:
|
|
323
|
+
component: V,
|
|
322
324
|
meta: i,
|
|
323
325
|
props: (e) => {
|
|
324
326
|
let r = e.params.id;
|
|
325
327
|
if (r === "AnnotationStyle" && n) return {
|
|
326
328
|
title: `${r}.jsonld`,
|
|
327
|
-
data:
|
|
329
|
+
data: x(n).toJsonLdContext()
|
|
328
330
|
};
|
|
329
331
|
let i = t.findById(r);
|
|
330
332
|
return {
|
|
@@ -336,7 +338,7 @@ var m = {
|
|
|
336
338
|
{
|
|
337
339
|
path: `${r}/:type/anno.jsonld`,
|
|
338
340
|
name: "annotation-ns-type-jsonld",
|
|
339
|
-
component:
|
|
341
|
+
component: V,
|
|
340
342
|
meta: i,
|
|
341
343
|
props: (e) => {
|
|
342
344
|
let n = e.params.type, r = t.getContextBuilder(n);
|
|
@@ -355,7 +357,7 @@ var m = {
|
|
|
355
357
|
{
|
|
356
358
|
path: `${r}/:id/schemas`,
|
|
357
359
|
name: "annotation-ns-schemas",
|
|
358
|
-
component:
|
|
360
|
+
component: V,
|
|
359
361
|
meta: i,
|
|
360
362
|
props: (e) => {
|
|
361
363
|
let n = e.params.id, r = t.findById(n);
|
|
@@ -384,7 +386,7 @@ var m = {
|
|
|
384
386
|
{
|
|
385
387
|
path: `${r}/:id`,
|
|
386
388
|
name: "annotation-ns-by-id",
|
|
387
|
-
component:
|
|
389
|
+
component: V,
|
|
388
390
|
meta: i,
|
|
389
391
|
props: (e) => {
|
|
390
392
|
let n = e.params.id;
|
|
@@ -397,7 +399,7 @@ var m = {
|
|
|
397
399
|
{
|
|
398
400
|
path: r,
|
|
399
401
|
name: "annotation-ns-all",
|
|
400
|
-
component:
|
|
402
|
+
component: V,
|
|
401
403
|
meta: i,
|
|
402
404
|
props: () => ({
|
|
403
405
|
title: "All definitions",
|
|
@@ -405,19 +407,19 @@ var m = {
|
|
|
405
407
|
})
|
|
406
408
|
}
|
|
407
409
|
];
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
},
|
|
411
|
-
|
|
410
|
+
}, W = (e, t, n) => {
|
|
411
|
+
U(n?.basePath ?? "/ns", t, n?.config).forEach((t) => e.addRoute(t));
|
|
412
|
+
}, G = { install(e, t) {
|
|
413
|
+
W(t.router, t.service, {
|
|
412
414
|
basePath: t.basePath,
|
|
413
415
|
config: t.config
|
|
414
416
|
});
|
|
415
|
-
} },
|
|
416
|
-
let n =
|
|
417
|
-
return t.resourceFolder && n.loadFromGlob(t.resourceFolder), t.definitionsUrl && n.loadFromUrl(t.definitionsUrl, t.fetchFn), e.provide(
|
|
417
|
+
} }, K = { install(e, t) {
|
|
418
|
+
let n = L(t);
|
|
419
|
+
return t.resourceFolder && n.loadFromGlob(t.resourceFolder), t.definitionsUrl && n.loadFromUrl(t.definitionsUrl, t.fetchFn), e.provide(P, n), W(t.router, n.service, {
|
|
418
420
|
basePath: t.basePath,
|
|
419
421
|
config: t.config
|
|
420
422
|
}), n;
|
|
421
423
|
} };
|
|
422
424
|
//#endregion
|
|
423
|
-
export {
|
|
425
|
+
export { p as AnnotationDefinitionService, G as AnnotationNamespacePlugin, K as AnnotationPlugin, H as NAMESPACE_ROUTE_META, L as createAnnotationDefinitionsState, B as createAnnotationNamespacePaths, U as createAnnotationNamespaceRoutes, W as installAnnotationNamespaceRoutes, j as loadAnnotationDefinitionsFromConfigs, A as loadAnnotationDefinitionsFromGlob, N as loadAnnotationDefinitionsFromUrl, R as provideAnnotationDefinitions, z as useAnnotationDefinitions };
|
package/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("zod"),require("@ghentcdh/w3c-utils"),require("@ghentcdh/annotated-text"),require("vue")):typeof define==`function`&&define.amd?define([`exports`,`zod`,`@ghentcdh/w3c-utils`,`@ghentcdh/annotated-text`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`annotation-vue`]={},e.zod,e._ghentcdh_w3c_utils,e._ghentcdh_annotated_text,e.vue))})(this,function(e,t,n,r,i){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("zod"),require("@ghentcdh/w3c-utils"),require("@ghentcdh/annotated-text"),require("@ghentcdh/crouton-forms-vue"),require("vue")):typeof define==`function`&&define.amd?define([`exports`,`zod`,`@ghentcdh/w3c-utils`,`@ghentcdh/annotated-text`,`@ghentcdh/crouton-forms-vue`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`annotation-vue`]={},e.zod,e._ghentcdh_w3c_utils,e._ghentcdh_annotated_text,e._ghentcdh_crouton_forms_vue,e.vue))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=class{definitions=[];groupedDefinitions={};constructor(e=[]){e.length&&this.setDefinitions(e)}setDefinitions(e){this.definitions=e,this.groupedDefinitions=e.reduce((e,t)=>(e[t.id]=t,e),{})}findAll(){return this.definitions}findById(e){return this.groupedDefinitions[e]}findAllGrouped(){return this.groupedDefinitions}getAllContextBuilders(){return this.definitions.map(e=>e.context)}getContextBuilder(e){return this.findById(e)?.context}},s=`AnnotationMetadata`,c=t.z.object({});t.z.object({id:t.z.string(),name:t.z.string(),columns:t.z.array(c),json_schema:t.z.any().optional(),json_ld:t.z.any().optional(),ui_schema:t.z.any().optional(),metadata_schema:t.z.any().optional(),color:t.z.string(),type:t.z.string().optional(),icon:t.z.string().optional(),isRoot:t.z.boolean().default(!0),allowedChildren:t.z.array(t.z.string()).optional(),allowedLinks:t.z.array(t.z.string()).optional(),context:t.z.custom(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional()});var l={baseUrl:`http://localhost:3000/`,app:`ghentcdh`,prefix:`ghentcdh`,isDev:!1,cacheTTLms:1200*1e3},u=(e={})=>{let t=e.baseUrl??l.baseUrl,n=t.endsWith(`/`)?t:`${t}/`,r=e.isDev??!1,i=r?0:1200*1e3;return{baseUrl:n,contextUrl:`${n}ns/`,app:e.app??l.app,prefix:e.prefix??l.prefix,isDev:r,cacheTTLms:i}},d=(e,t)=>{let{prefix:r,baseUrl:i,contextUrl:a}=u(t),o=s;return(0,n.contextBuilder)(r,i).setType(r,o).addPrefix(e,`${r}:${e}`).setContextUri(`${a}${e}.jsonld`)},f=t.z.object({id:t.z.string(),name:t.z.string(),target:t.z.enum([`gutter`,`underline`,`highlight`]).optional().default(`underline`),color:t.z.string().optional()}),p=`AnnotationStyle`,m=e=>{let{prefix:t,baseUrl:r,contextUrl:i}=u(e);return(0,n.contextBuilder)(t,r).setType(t,p).setContextUri(`${i}${p}.jsonld`).parseZodSchema(f)},h=e=>{let t=i.ControlBuilder.properties(e.id);if(!e.fieldInput)return t;let{type:n,options:r={}}=e.fieldInput;return n===`autocomplete`?t.autocomplete({...r.uri&&{uri:r.uri},...r.resource&&{resource:r.resource},...r.valueKey&&{valueKey:r.valueKey},...r.labelKey&&{labelKey:r.labelKey},...r.enableCreate!==void 0&&{enableCreate:r.enableCreate},...r.colspan&&{colspan:r.colspan}}):n===`select`?t.select({...r.values&&{values:r.values},...r.clearable!==void 0&&{clearable:r.clearable},...r.storeValue!==void 0&&{storeValue:r.storeValue},...r.emitObject!==void 0&&{emitObject:r.emitObject},...r.colspan&&{colspan:r.colspan}}):t.control(n,{...r.colspan&&{colspan:r.colspan}})},g=e=>{let t=i.LayoutBuilder.grid();return e.filter(e=>!e.hiddenInForm).forEach(e=>t.addControl(h(e))),t.build()},_=e=>{let t=i.LayoutBuilder.grid();return e.filter(e=>!e.hiddenInMetadata).forEach(e=>t.addControl(h(e).readonly())),t.build()},v=e=>{if(e.type===`object`&&e.properties){let n={};for(let[t,r]of Object.entries(e.properties))n[t]=v(r);return t.z.object(n)}return t.z.string()},y=(e,n,r)=>{let i=d(e,r),a=n.columns??[];if(!a.length)return i;let o={};for(let e of a)if(e.type){let t=v(e.type);o[e.id]=e.required===!1?t.optional():t}return Object.keys(o).length?i.parseZodSchema(t.z.object(o)):i},b=(e,t,n=y)=>{let r=n(e.id,e,t),i=e.columns??[],a=i.length>0,o=e.ui_schema??(a?g(i):void 0),s=e.metadata_schema??(a?_(i):void 0),c={id:e.id,name:e.name,color:e.color,isRoot:e.isRoot??!0,columns:i,context:r,json_ld:r.toJsonLdContext(),json_schema:o?r.toJsonSchema():null};return o&&(c.ui_schema=o),s&&(c.metadata_schema=s),e.type&&(c.type=e.type),e.icon&&(c.icon=e.icon),e.target&&(c.target=e.target),e.allowedChildren&&(c.allowedChildren=e.allowedChildren),e.allowedLinks&&(c.allowedLinks=e.allowedLinks),c},x=(e,t,n)=>e.map(e=>b(e,t,n)),S=e=>`default`in e?e.default:e,C=(e,t,n)=>w(Object.values(e).map(S),t,n),w=(e,t,n)=>x(e,t,n),T=async e=>{let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch annotation definitions: ${t.status} ${t.statusText}`);return t.json()},E=async(e,t,n,r=T)=>w(await r(e),t,n),D=Symbol(`annotation-definitions`),O=(e,t)=>e?e.reduce((e,n)=>{let r=t[n];if(r){let t={key:r.id,label:r.name};r.icon&&(t.icon=r.icon),e.push(t)}return e},[]):[],k=(e,t,n,r)=>{let i={uiSchema:e.ui_schema??null,jsonSchema:e.json_schema??null,metaDataSchema:e.metadata_schema??null,validation:e=>e};return{id:e.id,name:e.name,label:e.name,color:e.color,style:{default:n(e.color),active:r(e.color)},schema:i,allowedChildren:O(e.allowedChildren,t),allowedLinks:O(e.allowedLinks,t),isRoot:e.isRoot??!0,icon:e.icon,type:e.type,target:e.target,context:e.context,_core:e}},A=e=>{let{config:t,factory:n}=e,i=e.createHighlightStyle??r.createHighlightStyle,s=e.activeHighlightStyle??i,c=(0,a.markRaw)(new o),l=(0,a.ref)([]),u=(0,a.computed)(()=>{let e=c.findAllGrouped();return l.value.map(t=>k(t,e,i,s))}),d=(0,a.computed)(()=>u.value.reduce((e,t)=>(e[t.id]=t,e),{})),f=e=>d.value[e],p=e=>{c.setDefinitions(e),l.value=e},m=e=>{p(C(e,t,n))},h=e=>{p(w(e,t,n))},g=(0,a.ref)(!1),_=(0,a.ref)(null);return(0,a.reactive)({configuration:t,definitions:u,definitionsMap:d,getDefinitionById:f,loadFromGlob:m,loadFromConfigs:h,loadFromDefinitions:p,loadFromUrl:async(e,r)=>{g.value=!0,_.value=null;try{p(await E(e,t,n,r))}catch(e){_.value=e instanceof Error?e:Error(String(e))}finally{g.value=!1}},loading:g,error:_,service:c})},j=e=>{let t=A(e);return e.resourceFolder&&t.loadFromGlob(e.resourceFolder),e.definitionsUrl&&t.loadFromUrl(e.definitionsUrl,e.fetchFn),(0,a.provide)(D,t),t},M=()=>{let e=(0,a.inject)(D);if(!e)throw Error(`useAnnotationDefinitions() must be called inside a component that called provideAnnotationDefinitions()`);return e},N=(e=`/ns`)=>{let t=e.endsWith(`/`)?e.slice(0,-1):e;return{all:t,allJsonLd:`${t}/anno.jsonld`,byId:e=>`${t}/${e}`,jsonLdById:e=>`${t}/${e}.jsonld`,schemasById:e=>`${t}/${e}/schemas`,typeJsonLd:e=>`${t}/${e}/anno.jsonld`}},P=(0,a.defineComponent)({name:`JsonView`,props:{data:{type:[Object,Array,String,Number],default:null},title:{type:String,required:!1,default:``}},setup(e){let t=(0,a.computed)(()=>JSON.stringify(e.data,null,2)),n=(0,a.computed)(()=>!1),r=()=>{navigator.clipboard.writeText(t.value)},i=()=>{let n=new Blob([t.value],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title||`data`}.json`,i.click(),URL.revokeObjectURL(r)};return()=>(0,a.h)(`div`,{style:{fontFamily:`monospace`,fontSize:`13px`,padding:`16px`,maxWidth:`100%`,boxSizing:`border-box`}},[(0,a.h)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,marginBottom:`12px`,flexWrap:`wrap`}},[e.title?(0,a.h)(`span`,{style:{fontWeight:`bold`,fontSize:`14px`,marginRight:`auto`}},e.title):null,(0,a.h)(`button`,{onClick:r,style:{cursor:`pointer`,padding:`4px 10px`,fontSize:`12px`,border:`1px solid #ccc`,borderRadius:`4px`,background:`#f5f5f5`}},n.value?`Copied`:`Copy`),(0,a.h)(`button`,{onClick:i,style:{cursor:`pointer`,padding:`4px 10px`,fontSize:`12px`,border:`1px solid #ccc`,borderRadius:`4px`,background:`#f5f5f5`}},`Download`)]),(0,a.h)(`pre`,{style:{margin:0,whiteSpace:`pre-wrap`,wordBreak:`break-word`,background:`#fafafa`,border:`1px solid #e0e0e0`,borderRadius:`4px`,padding:`12px`,overflow:`auto`}},t.value)])}}),F={namespace:!0,layout:`blank`},I=(e,t,n)=>{let r=e.endsWith(`/`)?e.slice(0,-1):e,i={...F};return[{path:`${r}/anno.jsonld`,name:`annotation-ns-all-jsonld`,component:P,meta:i,props:()=>({title:`All JSON-LD contexts`,data:t.getAllContextBuilders().map(e=>e.toJsonLdContext())})},{path:`${r}/:id.jsonld`,name:`annotation-ns-jsonld`,component:P,meta:i,props:e=>{let r=e.params.id;if(r===`AnnotationStyle`&&n)return{title:`${r}.jsonld`,data:m(n).toJsonLdContext()};let i=t.findById(r);return{title:`${r}.jsonld`,data:i?.json_ld??null}}},{path:`${r}/:type/anno.jsonld`,name:`annotation-ns-type-jsonld`,component:P,meta:i,props:e=>{let n=e.params.type,r=t.getContextBuilder(n);return r?{title:`${n}/anno.jsonld`,data:{jsonLd:r.toJsonLdContext(),forms:r.toJsonSchema()}}:{title:n,data:null}}},{path:`${r}/:id/schemas`,name:`annotation-ns-schemas`,component:P,meta:i,props:e=>{let n=e.params.id,r=t.findById(n);return r?{title:`${n}/schemas`,data:{id:r.id,name:r.name,json_schema:r.json_schema,ui_schema:r.ui_schema,metadata_schema:r.metadata_schema,columns:r.columns,isRoot:r.isRoot,allowedChildren:r.allowedChildren,allowedLinks:r.allowedLinks,type:r.type,icon:r.icon,target:r.target}}:{title:n,data:null}}},{path:`${r}/:id`,name:`annotation-ns-by-id`,component:P,meta:i,props:e=>{let n=e.params.id;return{title:n,data:t.findById(n)??null}}},{path:r,name:`annotation-ns-all`,component:P,meta:i,props:()=>({title:`All definitions`,data:t.findAll()})}]},L=(e,t,n)=>{I(n?.basePath??`/ns`,t,n?.config).forEach(t=>e.addRoute(t))};e.AnnotationDefinitionService=o,e.AnnotationNamespacePlugin={install(e,t){L(t.router,t.service,{basePath:t.basePath,config:t.config})}},e.AnnotationPlugin={install(e,t){let n=A(t);return t.resourceFolder&&n.loadFromGlob(t.resourceFolder),t.definitionsUrl&&n.loadFromUrl(t.definitionsUrl,t.fetchFn),e.provide(D,n),L(t.router,n.service,{basePath:t.basePath,config:t.config}),n}},e.NAMESPACE_ROUTE_META=F,e.createAnnotationDefinitionsState=A,e.createAnnotationNamespacePaths=N,e.createAnnotationNamespaceRoutes=I,e.installAnnotationNamespaceRoutes=L,e.loadAnnotationDefinitionsFromConfigs=w,e.loadAnnotationDefinitionsFromGlob=C,e.loadAnnotationDefinitionsFromUrl=E,e.provideAnnotationDefinitions=j,e.useAnnotationDefinitions=M});
|