@nesso-how/plugin 0.4.0 → 0.6.0
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/README.md +121 -51
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/node/data.d.ts +1 -0
- package/dist/node/data.js +28 -0
- package/dist/node/definitions.d.ts +69 -0
- package/dist/node/definitions.js +124 -0
- package/dist/node/errors.d.ts +10 -0
- package/dist/node/errors.js +45 -0
- package/dist/node/files.d.ts +20 -0
- package/dist/node/files.js +36 -0
- package/dist/node/i18n.d.ts +12 -0
- package/dist/node/i18n.js +11 -0
- package/dist/node/index.d.ts +6 -0
- package/dist/node/index.js +2 -0
- package/dist/node/package.d.ts +34 -0
- package/dist/node/package.js +224 -0
- package/dist/node/runtime.d.ts +555 -0
- package/dist/node/runtime.js +513 -0
- package/dist/node/storage.d.ts +46 -0
- package/dist/node/storage.js +67 -0
- package/dist/node/theme-fonts.d.ts +2 -0
- package/dist/node/theme-fonts.js +11 -0
- package/dist/package.d.ts +1 -1
- package/dist/package.js +1 -1
- package/dist/{runtime-C-k6OiHL.js → runtime-BM45o1qi.js} +307 -219
- package/dist/{runtime-BrWPGuBB.d.ts → runtime-BxtTAcko.d.ts} +159 -123
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +1 -1
- package/example/README.md +11 -8
- package/example/package.json +46 -20
- package/example/src/Quiz.css +50 -0
- package/example/src/Quiz.tsx +70 -0
- package/example/src/index.ts +18 -9
- package/example/tsconfig.json +6 -4
- package/example/vite.config.ts +14 -0
- package/package.json +9 -3
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
//#region ../errors/
|
|
2
|
+
//#region ../errors/dist/index.js
|
|
3
|
+
function validationIssues(issues, prefix = "") {
|
|
4
|
+
return issues.map(({ path, message }) => ({
|
|
5
|
+
path: path.reduce((result, key) => typeof key === "number" ? `${result}[${key}]` : result ? `${result}.${String(key)}` : String(key), prefix),
|
|
6
|
+
message
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
3
9
|
var NessoError = class extends Error {
|
|
4
10
|
name = "NessoError";
|
|
5
11
|
issues;
|
|
@@ -52,7 +58,7 @@ function parseOrThrow(schema, value, prefix = "") {
|
|
|
52
58
|
return parsed.data;
|
|
53
59
|
}
|
|
54
60
|
//#endregion
|
|
55
|
-
//#region ../schema/
|
|
61
|
+
//#region ../schema/dist/core.js
|
|
56
62
|
const newIri = () => `urn:uuid:${crypto.randomUUID()}`;
|
|
57
63
|
const isAbsoluteIri = (value) => typeof value === "string" && /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
58
64
|
const relationKey = ({ source, predicate, target }) => JSON.stringify([
|
|
@@ -61,211 +67,114 @@ const relationKey = ({ source, predicate, target }) => JSON.stringify([
|
|
|
61
67
|
target
|
|
62
68
|
]);
|
|
63
69
|
//#endregion
|
|
64
|
-
//#region
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
id,
|
|
94
|
-
value
|
|
95
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
96
|
-
setConceptColor: (id, value, historyGroup) => applyOperations([{
|
|
97
|
-
kind: "concept.color",
|
|
98
|
-
id,
|
|
99
|
-
value
|
|
100
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
101
|
-
setConceptBold: (id, value, historyGroup) => applyOperations([{
|
|
102
|
-
kind: "concept.bold",
|
|
103
|
-
id,
|
|
104
|
-
value
|
|
105
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
106
|
-
setConceptItalic: (id, value, historyGroup) => applyOperations([{
|
|
107
|
-
kind: "concept.italic",
|
|
108
|
-
id,
|
|
109
|
-
value
|
|
110
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
111
|
-
addConcept: (position, historyGroup) => {
|
|
112
|
-
const id = newIri();
|
|
113
|
-
return created(id, applyOperations([{
|
|
114
|
-
kind: "concept.add",
|
|
115
|
-
id,
|
|
116
|
-
position
|
|
117
|
-
}], historyGroup ? { historyGroup } : void 0));
|
|
118
|
-
},
|
|
119
|
-
connect: (source, target) => applyOperations([{
|
|
120
|
-
kind: "relation.connect",
|
|
121
|
-
source,
|
|
122
|
-
target
|
|
123
|
-
}]),
|
|
124
|
-
reconnectRelation: (id, source, target) => applyOperations([{
|
|
125
|
-
kind: "relation.reconnect",
|
|
126
|
-
id,
|
|
127
|
-
source,
|
|
128
|
-
target
|
|
129
|
-
}]),
|
|
130
|
-
setRelationType: (id, typeId) => applyOperations([{
|
|
131
|
-
kind: "relation.type",
|
|
132
|
-
id,
|
|
133
|
-
typeId
|
|
134
|
-
}]),
|
|
135
|
-
createRelationType: (id, label) => applyOperations([{
|
|
136
|
-
kind: "relation.type.create",
|
|
137
|
-
id,
|
|
138
|
-
typeId: newIri(),
|
|
139
|
-
label
|
|
140
|
-
}]),
|
|
141
|
-
removeConcept: (id) => applyOperations([{
|
|
142
|
-
kind: "concept.remove",
|
|
143
|
-
id
|
|
144
|
-
}]),
|
|
145
|
-
removeRelation: (id) => applyOperations([{
|
|
146
|
-
kind: "relation.remove",
|
|
147
|
-
id
|
|
148
|
-
}]),
|
|
149
|
-
setActiveVocab: (id) => applyOperations([{
|
|
150
|
-
kind: "preferences.vocab",
|
|
151
|
-
id
|
|
152
|
-
}]),
|
|
153
|
-
setActiveTheme: (id) => applyOperations([{
|
|
154
|
-
kind: "preferences.theme",
|
|
155
|
-
id
|
|
156
|
-
}]),
|
|
157
|
-
setLocale: (value) => applyOperations([{
|
|
158
|
-
kind: "preferences.locale",
|
|
159
|
-
value
|
|
160
|
-
}]),
|
|
161
|
-
setPanelSizes: (value) => applyOperations([{
|
|
162
|
-
kind: "preferences.panels",
|
|
163
|
-
value
|
|
164
|
-
}]),
|
|
165
|
-
setSectionOpen: (id, open) => applyOperations([{
|
|
166
|
-
kind: "preferences.section",
|
|
167
|
-
id,
|
|
168
|
-
open
|
|
169
|
-
}]),
|
|
170
|
-
createView: (name, conceptIds) => {
|
|
171
|
-
const id = newIri();
|
|
172
|
-
return created(id, applyOperations([{
|
|
173
|
-
kind: "view.create",
|
|
174
|
-
id,
|
|
175
|
-
name,
|
|
176
|
-
conceptIds
|
|
177
|
-
}]));
|
|
178
|
-
},
|
|
179
|
-
renameView: (id, name) => applyOperations([{
|
|
180
|
-
kind: "view.rename",
|
|
181
|
-
id,
|
|
182
|
-
name
|
|
183
|
-
}]),
|
|
184
|
-
setViewPinned: (id, pinned) => applyOperations([{
|
|
185
|
-
kind: "view.pin",
|
|
186
|
-
id,
|
|
187
|
-
pinned
|
|
188
|
-
}]),
|
|
189
|
-
setViewMembership: (viewId, conceptId, included) => applyOperations([{
|
|
190
|
-
kind: "view.membership",
|
|
191
|
-
viewId,
|
|
192
|
-
conceptId,
|
|
193
|
-
included
|
|
194
|
-
}]),
|
|
195
|
-
deleteView: (id) => applyOperations([{
|
|
196
|
-
kind: "view.remove",
|
|
197
|
-
id
|
|
198
|
-
}])
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region ../schema/src/validate.ts
|
|
203
|
-
function validateGraph(graph) {
|
|
204
|
-
const issues = [];
|
|
70
|
+
//#region ../schema/dist/types.js
|
|
71
|
+
const iriSchema = z.string({ error: "Expected an absolute IRI" }).refine(isAbsoluteIri, "Expected an absolute IRI");
|
|
72
|
+
const positionSchema = z.strictObject({
|
|
73
|
+
x: z.number(),
|
|
74
|
+
y: z.number()
|
|
75
|
+
});
|
|
76
|
+
const conceptSchema = z.strictObject({
|
|
77
|
+
id: iriSchema,
|
|
78
|
+
label: z.string(),
|
|
79
|
+
notes: z.string().optional(),
|
|
80
|
+
color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
|
|
81
|
+
bold: z.boolean().optional(),
|
|
82
|
+
italic: z.boolean().optional(),
|
|
83
|
+
position: positionSchema
|
|
84
|
+
});
|
|
85
|
+
const relationTypeSchema = z.strictObject({
|
|
86
|
+
id: iriSchema,
|
|
87
|
+
label: z.string()
|
|
88
|
+
});
|
|
89
|
+
const relationSchema = z.strictObject({
|
|
90
|
+
source: iriSchema,
|
|
91
|
+
predicate: iriSchema,
|
|
92
|
+
target: iriSchema
|
|
93
|
+
});
|
|
94
|
+
const graphSchema = z.strictObject({
|
|
95
|
+
concepts: z.array(conceptSchema),
|
|
96
|
+
relationTypes: z.array(relationTypeSchema),
|
|
97
|
+
relations: z.array(relationSchema)
|
|
98
|
+
}).superRefine((graph, context) => {
|
|
205
99
|
const concepts = /* @__PURE__ */ new Set();
|
|
206
100
|
const types = /* @__PURE__ */ new Set();
|
|
207
101
|
const relations = /* @__PURE__ */ new Set();
|
|
208
102
|
for (const [index, concept] of graph.concepts.entries()) {
|
|
209
|
-
if (
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
103
|
+
if (concepts.has(concept.id)) context.addIssue({
|
|
104
|
+
code: "custom",
|
|
105
|
+
path: [
|
|
106
|
+
"concepts",
|
|
107
|
+
index,
|
|
108
|
+
"id"
|
|
109
|
+
],
|
|
215
110
|
message: `Duplicate concept IRI: ${concept.id}`
|
|
216
111
|
});
|
|
217
112
|
concepts.add(concept.id);
|
|
218
|
-
if (concept.description !== void 0 && typeof concept.description !== "string") issues.push({
|
|
219
|
-
path: `concepts[${index}].description`,
|
|
220
|
-
message: "Expected a string"
|
|
221
|
-
});
|
|
222
|
-
if (!Number.isFinite(concept.position.x) || !Number.isFinite(concept.position.y)) issues.push({
|
|
223
|
-
path: `concepts[${index}].position`,
|
|
224
|
-
message: `Invalid position: ${concept.id}`
|
|
225
|
-
});
|
|
226
|
-
if (concept.color !== void 0 && !/^#[0-9a-fA-F]{6}$/.test(concept.color)) issues.push({
|
|
227
|
-
path: `concepts[${index}].color`,
|
|
228
|
-
message: `Invalid color: ${concept.id}`
|
|
229
|
-
});
|
|
230
|
-
if (concept.bold !== void 0 && typeof concept.bold !== "boolean") issues.push({
|
|
231
|
-
path: `concepts[${index}].bold`,
|
|
232
|
-
message: "Expected a boolean"
|
|
233
|
-
});
|
|
234
|
-
if (concept.italic !== void 0 && typeof concept.italic !== "boolean") issues.push({
|
|
235
|
-
path: `concepts[${index}].italic`,
|
|
236
|
-
message: "Expected a boolean"
|
|
237
|
-
});
|
|
238
113
|
}
|
|
239
114
|
for (const [index, type] of graph.relationTypes.entries()) {
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
115
|
+
if (types.has(type.id) || concepts.has(type.id)) context.addIssue({
|
|
116
|
+
code: "custom",
|
|
117
|
+
path: [
|
|
118
|
+
"relationTypes",
|
|
119
|
+
index,
|
|
120
|
+
"id"
|
|
121
|
+
],
|
|
246
122
|
message: `Duplicate relation IRI: ${type.id}`
|
|
247
123
|
});
|
|
248
124
|
types.add(type.id);
|
|
249
125
|
}
|
|
250
126
|
for (const [index, relation] of graph.relations.entries()) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
127
|
+
const key = relationKey(relation);
|
|
128
|
+
if (!concepts.has(relation.source) || !concepts.has(relation.target)) context.addIssue({
|
|
129
|
+
code: "custom",
|
|
130
|
+
path: ["relations", index],
|
|
131
|
+
message: `Unknown concept in relation: ${key}`
|
|
254
132
|
});
|
|
255
|
-
if (!types.has(relation.predicate))
|
|
256
|
-
|
|
133
|
+
if (!types.has(relation.predicate)) context.addIssue({
|
|
134
|
+
code: "custom",
|
|
135
|
+
path: [
|
|
136
|
+
"relations",
|
|
137
|
+
index,
|
|
138
|
+
"predicate"
|
|
139
|
+
],
|
|
257
140
|
message: `Unknown relation type: ${relation.predicate}`
|
|
258
141
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
path:
|
|
142
|
+
if (relations.has(key)) context.addIssue({
|
|
143
|
+
code: "custom",
|
|
144
|
+
path: ["relations", index],
|
|
262
145
|
message: `Duplicate relation: ${key}`
|
|
263
146
|
});
|
|
264
147
|
relations.add(key);
|
|
265
148
|
}
|
|
266
|
-
|
|
149
|
+
});
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region ../schema/dist/validate.js
|
|
152
|
+
function validateGraph(graph) {
|
|
153
|
+
const result = graphSchema.safeParse(graph);
|
|
154
|
+
return result.success ? [] : validationIssues(result.error.issues);
|
|
267
155
|
}
|
|
268
156
|
//#endregion
|
|
157
|
+
//#region ../schema/dist/jsonld.js
|
|
158
|
+
const jsonObject = z.record(z.string(), z.unknown());
|
|
159
|
+
z.strictObject({
|
|
160
|
+
"@context": jsonObject,
|
|
161
|
+
"@graph": z.array(jsonObject)
|
|
162
|
+
});
|
|
163
|
+
z.strictObject({
|
|
164
|
+
"@id": iriSchema,
|
|
165
|
+
"@type": z.literal("rdf:Property"),
|
|
166
|
+
"rdfs:label": z.string()
|
|
167
|
+
});
|
|
168
|
+
z.object({
|
|
169
|
+
"@id": iriSchema,
|
|
170
|
+
"rdfs:label": conceptSchema.shape.label,
|
|
171
|
+
"rdfs:comment": conceptSchema.shape.notes,
|
|
172
|
+
position: positionSchema.optional(),
|
|
173
|
+
color: conceptSchema.shape.color,
|
|
174
|
+
bold: conceptSchema.shape.bold,
|
|
175
|
+
italic: conceptSchema.shape.italic
|
|
176
|
+
}).catchall(z.unknown());
|
|
177
|
+
//#endregion
|
|
269
178
|
//#region src/definitions.ts
|
|
270
179
|
const themeColors = [
|
|
271
180
|
"background",
|
|
@@ -345,18 +254,27 @@ const themeDefinition = z.strictObject({
|
|
|
345
254
|
message: "Font face limit exceeded"
|
|
346
255
|
});
|
|
347
256
|
});
|
|
257
|
+
const vocabRelationType = z.strictObject({
|
|
258
|
+
id: z.string().min(1).max(2048),
|
|
259
|
+
label: z.string().max(30),
|
|
260
|
+
translations: z.strictObject({
|
|
261
|
+
en: z.string().trim().min(1).max(30).optional(),
|
|
262
|
+
it: z.string().trim().min(1).max(30).optional(),
|
|
263
|
+
"zh-CN": z.string().trim().min(1).max(30).optional()
|
|
264
|
+
}).optional()
|
|
265
|
+
});
|
|
348
266
|
const vocabDefinition = z.strictObject({
|
|
349
267
|
id: contributionId,
|
|
350
|
-
relationTypes: z.array(
|
|
351
|
-
id: z.string().min(1).max(2048),
|
|
352
|
-
label: z.string().max(30)
|
|
353
|
-
})).min(1),
|
|
268
|
+
relationTypes: z.array(vocabRelationType).min(1),
|
|
354
269
|
defaultTypeId: z.string().min(1).max(2048)
|
|
355
270
|
}).superRefine(({ relationTypes, defaultTypeId }, context) => {
|
|
356
271
|
for (const issue of validateGraph({
|
|
357
272
|
concepts: [],
|
|
358
273
|
relations: [],
|
|
359
|
-
relationTypes
|
|
274
|
+
relationTypes: relationTypes.map(({ id, label }) => ({
|
|
275
|
+
id,
|
|
276
|
+
label
|
|
277
|
+
}))
|
|
360
278
|
})) context.addIssue({
|
|
361
279
|
code: "custom",
|
|
362
280
|
path: ["relationTypes"],
|
|
@@ -393,6 +311,144 @@ function parseFileOptions(kind, value) {
|
|
|
393
311
|
return parseOrThrow(kind === "open" ? fileOpenOptions : fileSaveOptions, value);
|
|
394
312
|
}
|
|
395
313
|
//#endregion
|
|
314
|
+
//#region ../core/dist/commands.js
|
|
315
|
+
function createWriteCommands(applyOperations, created) {
|
|
316
|
+
return {
|
|
317
|
+
undo: () => applyOperations([{ kind: "history.undo" }]),
|
|
318
|
+
redo: () => applyOperations([{ kind: "history.redo" }]),
|
|
319
|
+
setSelection: (value) => applyOperations([{
|
|
320
|
+
kind: "selection.set",
|
|
321
|
+
value
|
|
322
|
+
}]),
|
|
323
|
+
setView: (id) => applyOperations([{
|
|
324
|
+
kind: "view.activate",
|
|
325
|
+
id
|
|
326
|
+
}]),
|
|
327
|
+
setConceptPosition: (id, value, historyGroup) => applyOperations([{
|
|
328
|
+
kind: "concept.position",
|
|
329
|
+
id,
|
|
330
|
+
value
|
|
331
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
332
|
+
setConceptPositions: (updates, historyGroup) => applyOperations([{
|
|
333
|
+
kind: "concept.positions",
|
|
334
|
+
updates
|
|
335
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
336
|
+
setConceptLabel: (id, value, historyGroup) => applyOperations([{
|
|
337
|
+
kind: "concept.label",
|
|
338
|
+
id,
|
|
339
|
+
value
|
|
340
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
341
|
+
setConceptNotes: (id, value, historyGroup) => applyOperations([{
|
|
342
|
+
kind: "concept.notes",
|
|
343
|
+
id,
|
|
344
|
+
value
|
|
345
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
346
|
+
setConceptColor: (id, value, historyGroup) => applyOperations([{
|
|
347
|
+
kind: "concept.color",
|
|
348
|
+
id,
|
|
349
|
+
value
|
|
350
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
351
|
+
setConceptBold: (id, value, historyGroup) => applyOperations([{
|
|
352
|
+
kind: "concept.bold",
|
|
353
|
+
id,
|
|
354
|
+
value
|
|
355
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
356
|
+
setConceptItalic: (id, value, historyGroup) => applyOperations([{
|
|
357
|
+
kind: "concept.italic",
|
|
358
|
+
id,
|
|
359
|
+
value
|
|
360
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
361
|
+
addConcept: (position, historyGroup) => {
|
|
362
|
+
const id = newIri();
|
|
363
|
+
return created(id, applyOperations([{
|
|
364
|
+
kind: "concept.add",
|
|
365
|
+
id,
|
|
366
|
+
position
|
|
367
|
+
}], historyGroup ? { historyGroup } : void 0));
|
|
368
|
+
},
|
|
369
|
+
connect: (source, target) => applyOperations([{
|
|
370
|
+
kind: "relation.connect",
|
|
371
|
+
source,
|
|
372
|
+
target
|
|
373
|
+
}]),
|
|
374
|
+
reconnectRelation: (id, source, target) => applyOperations([{
|
|
375
|
+
kind: "relation.reconnect",
|
|
376
|
+
id,
|
|
377
|
+
source,
|
|
378
|
+
target
|
|
379
|
+
}]),
|
|
380
|
+
setRelationType: (id, typeId) => applyOperations([{
|
|
381
|
+
kind: "relation.type",
|
|
382
|
+
id,
|
|
383
|
+
typeId
|
|
384
|
+
}]),
|
|
385
|
+
createRelationType: (id, label) => applyOperations([{
|
|
386
|
+
kind: "relation.type.create",
|
|
387
|
+
id,
|
|
388
|
+
typeId: newIri(),
|
|
389
|
+
label
|
|
390
|
+
}]),
|
|
391
|
+
removeConcept: (id) => applyOperations([{
|
|
392
|
+
kind: "concept.remove",
|
|
393
|
+
id
|
|
394
|
+
}]),
|
|
395
|
+
removeRelation: (id) => applyOperations([{
|
|
396
|
+
kind: "relation.remove",
|
|
397
|
+
id
|
|
398
|
+
}]),
|
|
399
|
+
setActiveVocab: (id) => applyOperations([{
|
|
400
|
+
kind: "preferences.vocab",
|
|
401
|
+
id
|
|
402
|
+
}]),
|
|
403
|
+
setActiveTheme: (id) => applyOperations([{
|
|
404
|
+
kind: "preferences.theme",
|
|
405
|
+
id
|
|
406
|
+
}]),
|
|
407
|
+
setLocale: (value) => applyOperations([{
|
|
408
|
+
kind: "preferences.locale",
|
|
409
|
+
value
|
|
410
|
+
}]),
|
|
411
|
+
setPanelSizes: (value) => applyOperations([{
|
|
412
|
+
kind: "preferences.panels",
|
|
413
|
+
value
|
|
414
|
+
}]),
|
|
415
|
+
setSectionOpen: (id, open) => applyOperations([{
|
|
416
|
+
kind: "preferences.section",
|
|
417
|
+
id,
|
|
418
|
+
open
|
|
419
|
+
}]),
|
|
420
|
+
createView: (name, conceptIds) => {
|
|
421
|
+
const id = newIri();
|
|
422
|
+
return created(id, applyOperations([{
|
|
423
|
+
kind: "view.create",
|
|
424
|
+
id,
|
|
425
|
+
name,
|
|
426
|
+
conceptIds
|
|
427
|
+
}]));
|
|
428
|
+
},
|
|
429
|
+
renameView: (id, name) => applyOperations([{
|
|
430
|
+
kind: "view.rename",
|
|
431
|
+
id,
|
|
432
|
+
name
|
|
433
|
+
}]),
|
|
434
|
+
setViewPinned: (id, pinned) => applyOperations([{
|
|
435
|
+
kind: "view.pin",
|
|
436
|
+
id,
|
|
437
|
+
pinned
|
|
438
|
+
}]),
|
|
439
|
+
setViewMembership: (viewId, conceptId, included) => applyOperations([{
|
|
440
|
+
kind: "view.membership",
|
|
441
|
+
viewId,
|
|
442
|
+
conceptId,
|
|
443
|
+
included
|
|
444
|
+
}]),
|
|
445
|
+
deleteView: (id) => applyOperations([{
|
|
446
|
+
kind: "view.remove",
|
|
447
|
+
id
|
|
448
|
+
}])
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
//#endregion
|
|
396
452
|
//#region src/i18n.ts
|
|
397
453
|
const text = (limit) => z.string().max(limit).refine((value) => new TextEncoder().encode(value).byteLength <= limit, "Text byte limit exceeded");
|
|
398
454
|
const localizedText = (limit) => z.strictObject({
|
|
@@ -486,6 +542,17 @@ function parsePluginStorageKey(value) {
|
|
|
486
542
|
return parseOrThrow(pluginStorageKey, value);
|
|
487
543
|
}
|
|
488
544
|
//#endregion
|
|
545
|
+
//#region src/theme-fonts.ts
|
|
546
|
+
const fontFaces = (ranges, stem, weight) => ({ faces: Object.entries(ranges).map(([subset, intervals]) => ({
|
|
547
|
+
path: `fonts/${stem.replace("{subset}", subset)}.woff2`,
|
|
548
|
+
weight,
|
|
549
|
+
style: "normal",
|
|
550
|
+
unicodeRange: intervals.split(",").map((interval) => {
|
|
551
|
+
const [from, to = from] = interval.slice(2).split("-");
|
|
552
|
+
return [parseInt(from, 16), parseInt(to, 16)];
|
|
553
|
+
})
|
|
554
|
+
})) });
|
|
555
|
+
//#endregion
|
|
489
556
|
//#region src/runtime.ts
|
|
490
557
|
const runtimeLimits = {
|
|
491
558
|
request: 33554432,
|
|
@@ -494,8 +561,20 @@ const runtimeLimits = {
|
|
|
494
561
|
deadline: 3e4,
|
|
495
562
|
interaction: 3e5,
|
|
496
563
|
initialization: 1e4,
|
|
497
|
-
action: 12e4
|
|
564
|
+
action: 12e4,
|
|
565
|
+
heartbeat: 15e3
|
|
498
566
|
};
|
|
567
|
+
const badgeLimits = {
|
|
568
|
+
value: 999999,
|
|
569
|
+
execution: 2e3,
|
|
570
|
+
refresh: 15e3,
|
|
571
|
+
rate: 1e3
|
|
572
|
+
};
|
|
573
|
+
const actionBadgeResult = z.strictObject({
|
|
574
|
+
value: z.number().int().min(0).max(badgeLimits.value).nullable(),
|
|
575
|
+
refreshAt: z.number().int().min(0).max(864e13).optional()
|
|
576
|
+
});
|
|
577
|
+
const parseActionBadgeResult = (value) => parseOrThrow(actionBadgeResult, value);
|
|
499
578
|
const themeTokens = [
|
|
500
579
|
...themeColors,
|
|
501
580
|
"font-sans",
|
|
@@ -505,10 +584,7 @@ const themeTokens = [
|
|
|
505
584
|
"duration-state"
|
|
506
585
|
];
|
|
507
586
|
const id = z.string().min(1).max(2048);
|
|
508
|
-
const position =
|
|
509
|
-
x: z.number(),
|
|
510
|
-
y: z.number()
|
|
511
|
-
});
|
|
587
|
+
const position = positionSchema;
|
|
512
588
|
const selection = z.array(z.strictObject({
|
|
513
589
|
kind: z.enum(["concept", "relation"]),
|
|
514
590
|
id
|
|
@@ -529,7 +605,7 @@ const operation = z.discriminatedUnion("kind", [
|
|
|
529
605
|
value: z.string()
|
|
530
606
|
}),
|
|
531
607
|
z.strictObject({
|
|
532
|
-
kind: z.literal("concept.
|
|
608
|
+
kind: z.literal("concept.notes"),
|
|
533
609
|
id,
|
|
534
610
|
value: z.string()
|
|
535
611
|
}),
|
|
@@ -681,7 +757,7 @@ const jsEntry = z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.js$/);
|
|
|
681
757
|
const jsonEntry = z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.json$/);
|
|
682
758
|
const operationDeclarations = z.array(z.enum([
|
|
683
759
|
"concept.label",
|
|
684
|
-
"concept.
|
|
760
|
+
"concept.notes",
|
|
685
761
|
"concept.color",
|
|
686
762
|
"concept.bold",
|
|
687
763
|
"concept.italic",
|
|
@@ -705,7 +781,8 @@ const manifest = z.discriminatedUnion("kind", [z.strictObject({
|
|
|
705
781
|
capabilities: z.array(z.enum([
|
|
706
782
|
"files",
|
|
707
783
|
"notifications",
|
|
708
|
-
"storage"
|
|
784
|
+
"storage",
|
|
785
|
+
"ui"
|
|
709
786
|
]))
|
|
710
787
|
}), ...["theme", "vocab"].map((kind) => z.strictObject({
|
|
711
788
|
...manifestFields,
|
|
@@ -793,10 +870,19 @@ const wireError = z.strictObject({
|
|
|
793
870
|
});
|
|
794
871
|
const message = z.union([
|
|
795
872
|
request,
|
|
873
|
+
z.strictObject({ type: z.literal("panel-ready") }),
|
|
874
|
+
z.strictObject({
|
|
875
|
+
type: z.literal("pong"),
|
|
876
|
+
id: z.number().int().positive()
|
|
877
|
+
}),
|
|
796
878
|
z.strictObject({
|
|
797
879
|
type: z.literal("contribution"),
|
|
798
880
|
value: z.unknown()
|
|
799
881
|
}),
|
|
882
|
+
z.strictObject({
|
|
883
|
+
type: z.literal("badge-result"),
|
|
884
|
+
value: actionBadgeResult
|
|
885
|
+
}),
|
|
800
886
|
z.strictObject({
|
|
801
887
|
type: z.literal("close"),
|
|
802
888
|
reason: z.string().max(2048)
|
|
@@ -814,7 +900,9 @@ const message = z.union([
|
|
|
814
900
|
const actionDescriptor = z.strictObject({
|
|
815
901
|
id: z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
816
902
|
label: localizedText(128),
|
|
817
|
-
icon: z.string().min(1).max(32).regex(/^[a-z]+(?:-[a-z]+)*$/).optional()
|
|
903
|
+
icon: z.string().min(1).max(32).regex(/^[a-z]+(?:-[a-z]+)*$/).optional(),
|
|
904
|
+
ui: z.literal(true).optional(),
|
|
905
|
+
badge: z.literal(true).optional()
|
|
818
906
|
});
|
|
819
907
|
const actionIconNames = [
|
|
820
908
|
"arrow-right",
|
|
@@ -825,12 +913,14 @@ const actionIconNames = [
|
|
|
825
913
|
"file-down",
|
|
826
914
|
"file-up",
|
|
827
915
|
"folder",
|
|
916
|
+
"glasses",
|
|
828
917
|
"globe",
|
|
829
918
|
"layers",
|
|
830
919
|
"pencil",
|
|
831
920
|
"play",
|
|
832
921
|
"plus",
|
|
833
922
|
"refresh",
|
|
923
|
+
"repeat",
|
|
834
924
|
"scissors",
|
|
835
925
|
"search",
|
|
836
926
|
"share",
|
|
@@ -844,35 +934,18 @@ function parseContribution(kind, value) {
|
|
|
844
934
|
if (kind === "theme" || kind === "vocab") return parseDefinition(kind, value);
|
|
845
935
|
return parseOrThrow(actionDescriptors, value);
|
|
846
936
|
}
|
|
847
|
-
const graph = z.strictObject({
|
|
848
|
-
concepts: z.array(z.strictObject({
|
|
849
|
-
id,
|
|
850
|
-
label: z.string(),
|
|
851
|
-
description: z.string().optional(),
|
|
852
|
-
color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
|
|
853
|
-
bold: z.boolean().optional(),
|
|
854
|
-
italic: z.boolean().optional(),
|
|
855
|
-
position
|
|
856
|
-
})),
|
|
857
|
-
relationTypes: z.array(relationType),
|
|
858
|
-
relations: z.array(z.strictObject({
|
|
859
|
-
source: id,
|
|
860
|
-
predicate: id,
|
|
861
|
-
target: id
|
|
862
|
-
}))
|
|
863
|
-
});
|
|
864
937
|
const actionStateSchema = z.strictObject({
|
|
865
938
|
revision: z.number().int().nonnegative(),
|
|
866
939
|
contextId: id,
|
|
867
940
|
locale,
|
|
868
941
|
theme: z.strictObject(Object.fromEntries(themeTokens.map((token) => [token, z.string().max(512).regex(/^[#\w\s.,()%/"'-]*$/)]))),
|
|
869
942
|
conceptPlacementOffset: position,
|
|
870
|
-
viewGraph:
|
|
943
|
+
viewGraph: graphSchema,
|
|
871
944
|
selected: selection,
|
|
872
945
|
targetViewId: id.nullable(),
|
|
873
946
|
activeVocab: z.strictObject({
|
|
874
947
|
id,
|
|
875
|
-
relationTypes: z.array(
|
|
948
|
+
relationTypes: z.array(vocabRelationType),
|
|
876
949
|
defaultTypeId: id
|
|
877
950
|
}).nullable(),
|
|
878
951
|
history: z.strictObject({
|
|
@@ -889,6 +962,10 @@ const actionStateSchema = z.strictObject({
|
|
|
889
962
|
})
|
|
890
963
|
});
|
|
891
964
|
const reply = z.union([
|
|
965
|
+
z.strictObject({
|
|
966
|
+
type: z.literal("ping"),
|
|
967
|
+
id: z.number().int().positive()
|
|
968
|
+
}),
|
|
892
969
|
z.strictObject({
|
|
893
970
|
type: z.literal("state"),
|
|
894
971
|
state: actionStateSchema
|
|
@@ -1008,6 +1085,13 @@ function createPluginClient(port, initial) {
|
|
|
1008
1085
|
return;
|
|
1009
1086
|
}
|
|
1010
1087
|
const data = parsed.data;
|
|
1088
|
+
if (data.type === "ping") {
|
|
1089
|
+
port.postMessage({
|
|
1090
|
+
type: "pong",
|
|
1091
|
+
id: data.id
|
|
1092
|
+
});
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1011
1095
|
if (data.type === "close") {
|
|
1012
1096
|
close();
|
|
1013
1097
|
return;
|
|
@@ -1108,8 +1192,12 @@ function createPluginClient(port, initial) {
|
|
|
1108
1192
|
},
|
|
1109
1193
|
signal: controller.signal
|
|
1110
1194
|
},
|
|
1111
|
-
close
|
|
1195
|
+
close,
|
|
1196
|
+
getPresentation: () => ({
|
|
1197
|
+
theme: state.theme,
|
|
1198
|
+
locale: state.locale
|
|
1199
|
+
})
|
|
1112
1200
|
};
|
|
1113
1201
|
}
|
|
1114
1202
|
//#endregion
|
|
1115
|
-
export {
|
|
1203
|
+
export { PluginError as C, themeColors as S, checkMessageSize as _, parseContribution as a, parseFileOptions as b, parsePluginMessage as c, themeTokens as d, fontFaces as f, pluginStorageLimits as g, parsePluginStorageSnapshot as h, parseActionBadgeResult as i, runtimeLimits as l, parsePluginStorageRecord as m, badgeLimits as n, parsePluginI18n as o, parsePluginStorageKey as p, createPluginClient as r, parsePluginManifest as s, actionIconNames as t, sha256Hex as u, resolvePluginText as v, parseOrThrow as w, parseDefinition as x, fileTextLimit as y };
|