@nesso-how/plugin 1.0.0-beta.14 → 1.0.0-beta.16
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 +10 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -1
- package/dist/node/index.d.ts +2 -1
- package/dist/node/index.js +1 -0
- package/dist/node/runtime.d.ts +5 -5
- package/dist/node/runtime.js +3 -3
- package/dist/package.d.ts +1 -1
- package/dist/package.js +1 -1
- package/dist/{runtime-Mst9R37I.d.ts → runtime-B6vu2uAB.d.ts} +41 -15
- package/dist/{runtime-CkCuGeU2.js → runtime-D7mWRns_.js} +280 -230
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +1 -1
- package/example/package.json +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ For a new project, start with the [standalone example](example/), which includes
|
|
|
14
14
|
|
|
15
15
|
The app, UI package, SDK, and official example share a release version on npm's default `latest` channel, including beta versions. Plugin compatibility is identified separately by `nesso.apiVersion`; matching the app's exact version is not required.
|
|
16
16
|
|
|
17
|
+
The [compatibility guide](../../docs/compatibility.md#plugin-api) explains API support and version changes.
|
|
18
|
+
|
|
17
19
|
The desktop plugin catalog offers the newest compatible version on `latest`. Other prerelease channels are not included.
|
|
18
20
|
|
|
19
21
|
## Create a plugin
|
|
@@ -78,7 +80,7 @@ Keep the example's build configuration and set these fields in `package.json`:
|
|
|
78
80
|
"version": "1.0.0",
|
|
79
81
|
"keywords": ["nesso-plugin"],
|
|
80
82
|
"nesso": {
|
|
81
|
-
"apiVersion":
|
|
83
|
+
"apiVersion": 4,
|
|
82
84
|
"kind": "actions",
|
|
83
85
|
"entry": "dist/index.js",
|
|
84
86
|
"writes": ["concept.label"],
|
|
@@ -220,11 +222,13 @@ Runs in an isolated Worker with no action APIs and a 2-second calculation limit.
|
|
|
220
222
|
|
|
221
223
|
The graph snapshot provides:
|
|
222
224
|
|
|
223
|
-
- `viewGraph`: `{ concepts, relations, relationTypes }` for the invoked view.
|
|
225
|
+
- `viewGraph`: `{ concepts, relations, relationTypes }` for the invoked view. In a saved view, concepts carry its `position`, `color`, `bold`, and `italic`.
|
|
224
226
|
- `selected`: the invoked view's selection.
|
|
225
227
|
- `targetViewId`: the invoked view's ID, or `null` for All; fixed for each invocation. Headless actions keep their target during navigation; panels restart with a new invocation when the active view changes.
|
|
226
228
|
- `activeVocab`: the current vocabulary, or `null`.
|
|
227
229
|
|
|
230
|
+
`viewGraph` contains stored relation-type labels. `resolveRelationTypeLabel(type, vocabs, locale)`, exported by `@nesso-how/plugin`, returns a translated display label from the supplied vocabularies, preserving custom labels.
|
|
231
|
+
|
|
228
232
|
Concept and relation-type IDs are absolute IRIs. Relations are `{ source, predicate, target }` triples; use `JSON.stringify([source, predicate, target])` as their selection/write ID.
|
|
229
233
|
|
|
230
234
|
### Write the graph
|
|
@@ -250,7 +254,7 @@ Call helpers on `document` and declare their operation kinds in `nesso.writes`:
|
|
|
250
254
|
| `setSelection([{ kind, id }])` | `selection.set` |
|
|
251
255
|
| `setViewMembership(viewId, conceptId, included)` | `view.membership` |
|
|
252
256
|
|
|
253
|
-
`addConcept` returns the new IRI. New concepts join the active saved view
|
|
257
|
+
Position, color, and style helpers edit the invoked saved view; they reject the batch in All, after navigation, or for concepts outside the view. `addConcept` returns the new IRI. New concepts join the active saved view, at the given position or near the single selected concept, and link to that concept, if any. These links and `connect` use the vocabulary's default relation type. `createRelationType` creates and assigns a type to the given relation. The selection keeps only concepts and relations visible in the active view.
|
|
254
258
|
|
|
255
259
|
For related edits, use `document.applyOperations(operations)` as in the quickstart. The entire batch succeeds or changes nothing. Editing, reconnecting, retyping, or removing an unknown concept or relation rejects the batch, as does reconnecting or retyping onto an existing relation; removing an item already removed earlier in the same batch, such as a relation of a removed concept, is allowed. Separate calls are separate transactions. Raw `concept.add` operations require an explicit new absolute IRI.
|
|
256
260
|
|
|
@@ -270,7 +274,7 @@ The invoked view is **not a write sandbox**: permitted writes can affect the who
|
|
|
270
274
|
|
|
271
275
|
File saves accept exactly one of UTF-8 `text` or canonical `base64` (without a data URL prefix), with a 16 MiB decoded byte limit. File opening remains UTF-8 text only. Host-managed dialogs or browser downloads grant no unrestricted filesystem access. Plugins have no Node, host DOM, direct filesystem, clipboard, or network access.
|
|
272
276
|
|
|
273
|
-
`images.renderView` captures the invoked view with the current theme and fonts, without selection or canvas controls. Scale defaults to `2`, or accepts `4`, and is a maximum: views too large for it render at the highest of `4`, `2`, or `1` within 8192 pixels per side and 16,777,216 pixels total. Empty views, views over that budget at scale `1`, and PNGs over 16 MiB fail. Save the result separately with `files.save({ name: 'view.png', ...image })`; this also requires `files`.
|
|
277
|
+
`images.renderView` captures the invoked view with the current theme and fonts, without selection or canvas controls. In the Overview (`viewId` `null`) it captures the overview map of the complete graph. Scale defaults to `2`, or accepts `4`, and is a maximum: views too large for it render at the highest of `4`, `2`, or `1` within 8192 pixels per side and 16,777,216 pixels total. Empty views, views over that budget at scale `1`, and PNGs over 16 MiB fail. Save the result separately with `files.save({ name: 'view.png', ...image })`; this also requires `files`.
|
|
274
278
|
|
|
275
279
|
Failures throw `PluginError` with `code` and `{ path, message }[]` issues. Let them propagate instead of reporting success. Files and notifications cannot be rolled back with graph edits.
|
|
276
280
|
|
|
@@ -300,6 +304,8 @@ await storage.delete('progress', { kind: 'concept', id: concept.id })
|
|
|
300
304
|
- Scopes identify records within the same plugin/document namespace; they do not create separate namespaces or revision baselines. The same key can be used at document scope and for different concepts and views, including a concept and view with the same ID.
|
|
301
305
|
- Your plugin owns the payload format and any migrations. Version it independently of the SDK and package version; Nesso does not interpret its fields.
|
|
302
306
|
|
|
307
|
+
The [downgrade and backup policy](../../docs/compatibility.md#downgrades-and-backups) also applies to private plugin data.
|
|
308
|
+
|
|
303
309
|
`storage.set(key, value, scope?)` saves one record and `storage.delete(key, scope?)` removes one. Each call is a single transaction returning `true` if data changed, or `false` if nothing changed, such as saving an identical value or deleting a missing record. Failed writes throw.
|
|
304
310
|
|
|
305
311
|
Setting a scoped record requires the concept or saved view to exist. Concept IDs must be absolute IRIs; view IDs are opaque identifiers. Deleting a record also accepts references to deleted entities.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as PluginStorageKey, F as ImageRenderOptions, G as
|
|
2
|
-
export { type ActionBadgeInput, type ActionBadgeResult, type ActionContext, type ActionContribution, type ActionDescriptor, type ActionIconName, type ActionState, type GraphSnapshot, type ImageRenderOptions, type LocalizedText, type NessoOperation, PluginError, type PluginI18n, type PluginManifest, type PluginStorage, type PluginStorageKey, type PluginStorageRecord, type PluginStorageScope, type RenderedImage, type SavedView, type Selection, type ThemeDefinition, type VocabDefinition, actionIconNames };
|
|
1
|
+
import { C as PluginStorageKey, F as ImageRenderOptions, G as resolveRelationTypeLabel, H as ThemeDefinition, I as RenderedImage, J as SavedView, K as GraphSnapshot, L as PluginError, S as PluginStorage, T as PluginStorageScope, X as ViewGraphSnapshot, Y as Selection, Z as VocabDefinition, a as ActionDescriptor, c as PluginI18n, i as ActionContribution, l as PluginManifest, n as ActionBadgeResult, o as ActionIconName, q as NessoOperation, r as ActionContext, s as ActionState, t as ActionBadgeInput, u as actionIconNames, w as PluginStorageRecord, z as LocalizedText } from "./runtime-B6vu2uAB.js";
|
|
2
|
+
export { type ActionBadgeInput, type ActionBadgeResult, type ActionContext, type ActionContribution, type ActionDescriptor, type ActionIconName, type ActionState, type GraphSnapshot, type ImageRenderOptions, type LocalizedText, type NessoOperation, PluginError, type PluginI18n, type PluginManifest, type PluginStorage, type PluginStorageKey, type PluginStorageRecord, type PluginStorageScope, type RenderedImage, type SavedView, type Selection, type ThemeDefinition, type ViewGraphSnapshot, type VocabDefinition, actionIconNames, resolveRelationTypeLabel };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { S as PluginError, t as actionIconNames } from "./runtime-D7mWRns_.js";
|
|
2
|
+
//#region ../core/dist/vocab.js
|
|
3
|
+
function resolveRelationTypeLabel(type, vocabs, locale) {
|
|
4
|
+
for (const vocab of vocabs) {
|
|
5
|
+
const definition = vocab.relationTypes.find((item) => item.id === type.id && item.label === type.label);
|
|
6
|
+
if (definition) return definition.translations?.[locale] ?? definition.translations?.en ?? type.label;
|
|
7
|
+
}
|
|
8
|
+
return type.label;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PluginError, actionIconNames, resolveRelationTypeLabel };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type { GraphSnapshot, NessoOperation, SavedView, Selection, VocabDefinition, } from '@nesso-how/core';
|
|
1
|
+
export type { GraphSnapshot, NessoOperation, SavedView, Selection, ViewGraphSnapshot, VocabDefinition, } from '@nesso-how/core';
|
|
2
|
+
export { resolveRelationTypeLabel } from '@nesso-how/core';
|
|
2
3
|
export type { ThemeDefinition } from './definitions.ts';
|
|
3
4
|
export { PluginError } from './errors.ts';
|
|
4
5
|
export type { ActionContext, ActionBadgeInput, ActionBadgeResult, ActionContribution, ActionDescriptor, ActionIconName, ActionState, LocalizedText, PluginI18n, PluginManifest, } from './runtime.ts';
|
package/dist/node/index.js
CHANGED
package/dist/node/runtime.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { type ImageRenderOptions, type RenderedImage } from './images.ts';
|
|
3
3
|
export type { ImageRenderOptions, RenderedImage } from './images.ts';
|
|
4
4
|
import type { ComponentType } from 'react';
|
|
5
|
-
import type { DeepReadonly,
|
|
5
|
+
import type { DeepReadonly, NessoOperation, Selection, SavedView, ViewGraphSnapshot, VocabDefinition } from '@nesso-how/core';
|
|
6
6
|
import type { Locale } from '@nesso-how/i18n';
|
|
7
7
|
import { type Definition } from './definitions.ts';
|
|
8
8
|
import { type FileOpenOptions, type FileOpenResult, type FileSaveOptions } from './files.ts';
|
|
@@ -37,7 +37,7 @@ declare const actionBadgeResult: z.ZodObject<{
|
|
|
37
37
|
}, z.core.$strict>;
|
|
38
38
|
export type ActionBadgeInput = {
|
|
39
39
|
readonly viewId: string | null;
|
|
40
|
-
readonly viewGraph:
|
|
40
|
+
readonly viewGraph: ViewGraphSnapshot;
|
|
41
41
|
readonly records: readonly PluginStorageRecord[];
|
|
42
42
|
readonly now: number;
|
|
43
43
|
};
|
|
@@ -67,7 +67,7 @@ export type PluginI18n = DeepReadonly<{
|
|
|
67
67
|
}>;
|
|
68
68
|
export declare function parsePluginI18n(value: unknown): PluginI18n;
|
|
69
69
|
declare const manifest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
70
|
-
apiVersion: z.ZodLiteral<
|
|
70
|
+
apiVersion: z.ZodLiteral<4>;
|
|
71
71
|
kind: z.ZodLiteral<"actions">;
|
|
72
72
|
entry: z.ZodString;
|
|
73
73
|
writes: z.ZodArray<z.ZodEnum<{
|
|
@@ -97,7 +97,7 @@ declare const manifest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
97
97
|
ui: "ui";
|
|
98
98
|
}>>;
|
|
99
99
|
}, z.core.$strict>, ...z.ZodObject<{
|
|
100
|
-
apiVersion: z.ZodLiteral<
|
|
100
|
+
apiVersion: z.ZodLiteral<4>;
|
|
101
101
|
kind: z.ZodLiteral<"theme" | "vocab">;
|
|
102
102
|
entry: z.ZodString;
|
|
103
103
|
writes: z.ZodTuple<[], null>;
|
|
@@ -530,7 +530,7 @@ export type ActionState = {
|
|
|
530
530
|
x: number;
|
|
531
531
|
y: number;
|
|
532
532
|
}>;
|
|
533
|
-
readonly viewGraph:
|
|
533
|
+
readonly viewGraph: ViewGraphSnapshot;
|
|
534
534
|
readonly selected: Selection;
|
|
535
535
|
readonly workspace: {
|
|
536
536
|
readonly activeViewId: string | null;
|
package/dist/node/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { imageRenderOptions, renderedImage, } from './images.js';
|
|
3
|
-
import {
|
|
3
|
+
import { positionSchema, viewGraphSchema } from '@nesso-how/schema';
|
|
4
4
|
import { parseOrThrow, PluginError, pluginErrorCodes } from './errors.js';
|
|
5
5
|
import { parseDefinition, themeColors, vocabRelationType } from './definitions.js';
|
|
6
6
|
import { fileOpenOptions, fileOpenResult, fileSaveOptions, } from './files.js';
|
|
@@ -118,7 +118,7 @@ export function parsePluginI18n(value) {
|
|
|
118
118
|
return parseOrThrow(pluginI18n, value, 'i18n.');
|
|
119
119
|
}
|
|
120
120
|
const manifestFields = {
|
|
121
|
-
apiVersion: z.literal(
|
|
121
|
+
apiVersion: z.literal(4),
|
|
122
122
|
};
|
|
123
123
|
const jsEntry = z
|
|
124
124
|
.string()
|
|
@@ -295,7 +295,7 @@ const actionStateSchema = z.strictObject({
|
|
|
295
295
|
.regex(/^[#\w\s.,()%/"'-]*$/),
|
|
296
296
|
]))),
|
|
297
297
|
conceptPlacementOffset: position,
|
|
298
|
-
viewGraph:
|
|
298
|
+
viewGraph: viewGraphSchema,
|
|
299
299
|
selected: selection,
|
|
300
300
|
targetViewId: id.nullable(),
|
|
301
301
|
activeVocab: z
|
package/dist/package.d.ts
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as parseOrThrow, S as PluginError, g as checkMessageSize, o as parsePluginI18n, s as parsePluginManifest, u as sha256Hex, v as parseDefinition } from "./runtime-
|
|
1
|
+
import { C as parseOrThrow, S as PluginError, g as checkMessageSize, o as parsePluginI18n, s as parsePluginManifest, u as sha256Hex, v as parseDefinition } from "./runtime-D7mWRns_.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import parseVersion from "semver/functions/parse.js";
|
|
4
4
|
import validateName from "validate-npm-package-name";
|
|
@@ -16,6 +16,30 @@ declare const positionSchema: z.ZodObject<{
|
|
|
16
16
|
x: z.ZodNumber;
|
|
17
17
|
y: z.ZodNumber;
|
|
18
18
|
}, z.core.$strict>;
|
|
19
|
+
declare const conceptSchema: z.ZodObject<{
|
|
20
|
+
id: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
21
|
+
label: z.ZodString;
|
|
22
|
+
notes: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
declare const presentationSchema: z.ZodObject<{
|
|
25
|
+
position: z.ZodObject<{
|
|
26
|
+
x: z.ZodNumber;
|
|
27
|
+
y: z.ZodNumber;
|
|
28
|
+
}, z.core.$strict>;
|
|
29
|
+
color: z.ZodOptional<z.ZodString>;
|
|
30
|
+
bold: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
italic: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
declare const viewMemberSchema: z.ZodObject<{
|
|
34
|
+
position: z.ZodObject<{
|
|
35
|
+
x: z.ZodNumber;
|
|
36
|
+
y: z.ZodNumber;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
color: z.ZodOptional<z.ZodString>;
|
|
39
|
+
bold: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
italic: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
id: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
42
|
+
}, z.core.$strict>;
|
|
19
43
|
declare const relationTypeSchema: z.ZodObject<{
|
|
20
44
|
id: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
21
45
|
label: z.ZodString;
|
|
@@ -25,13 +49,6 @@ declare const graphSchema: z.ZodObject<{
|
|
|
25
49
|
id: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
26
50
|
label: z.ZodString;
|
|
27
51
|
notes: z.ZodOptional<z.ZodString>;
|
|
28
|
-
color: z.ZodOptional<z.ZodString>;
|
|
29
|
-
bold: z.ZodOptional<z.ZodBoolean>;
|
|
30
|
-
italic: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
-
position: z.ZodObject<{
|
|
32
|
-
x: z.ZodNumber;
|
|
33
|
-
y: z.ZodNumber;
|
|
34
|
-
}, z.core.$strict>;
|
|
35
52
|
}, z.core.$strict>>;
|
|
36
53
|
relationTypes: z.ZodArray<z.ZodObject<{
|
|
37
54
|
id: z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
|
|
@@ -44,6 +61,9 @@ declare const graphSchema: z.ZodObject<{
|
|
|
44
61
|
}, z.core.$strict>>;
|
|
45
62
|
}, z.core.$strict>;
|
|
46
63
|
type Position = z.infer<typeof positionSchema>;
|
|
64
|
+
type Concept = z.infer<typeof conceptSchema>;
|
|
65
|
+
type Presentation = z.infer<typeof presentationSchema>;
|
|
66
|
+
type ViewMember = z.infer<typeof viewMemberSchema>;
|
|
47
67
|
type RelationType = z.infer<typeof relationTypeSchema>;
|
|
48
68
|
type Graph = z.infer<typeof graphSchema>;
|
|
49
69
|
//#endregion
|
|
@@ -58,6 +78,9 @@ type Selection = readonly {
|
|
|
58
78
|
readonly id: string;
|
|
59
79
|
}[];
|
|
60
80
|
type GraphSnapshot = DeepReadonly<Graph>;
|
|
81
|
+
type ViewGraphSnapshot = DeepReadonly<Omit<Graph, 'concepts'> & {
|
|
82
|
+
concepts: (Concept & Partial<Presentation>)[];
|
|
83
|
+
}>;
|
|
61
84
|
type NessoOperation = {
|
|
62
85
|
readonly kind: 'concept.label';
|
|
63
86
|
readonly id: string;
|
|
@@ -188,7 +211,7 @@ type VocabDefinition = {
|
|
|
188
211
|
type SavedView = {
|
|
189
212
|
readonly id: string;
|
|
190
213
|
readonly name: string;
|
|
191
|
-
readonly
|
|
214
|
+
readonly members: readonly DeepReadonly<ViewMember>[];
|
|
192
215
|
readonly pinned: boolean;
|
|
193
216
|
};
|
|
194
217
|
type Viewport = {
|
|
@@ -224,7 +247,7 @@ type NessoState = {
|
|
|
224
247
|
readonly graph: GraphSnapshot;
|
|
225
248
|
readonly workspace: WorkspaceState;
|
|
226
249
|
readonly preferences: Preferences;
|
|
227
|
-
readonly viewGraph:
|
|
250
|
+
readonly viewGraph: ViewGraphSnapshot;
|
|
228
251
|
readonly selected: Selection;
|
|
229
252
|
readonly vocabs: readonly VocabDefinition[];
|
|
230
253
|
readonly history: {
|
|
@@ -273,13 +296,16 @@ type NessoStore = {
|
|
|
273
296
|
readonly setViewPinned: (id: string, pinned: boolean) => void;
|
|
274
297
|
readonly setViewMembership: (viewId: string, conceptId: string, included: boolean) => void;
|
|
275
298
|
readonly deleteView: (id: string) => void;
|
|
276
|
-
readonly getViewGraph: (id: string) =>
|
|
299
|
+
readonly getViewGraph: (id: string) => ViewGraphSnapshot;
|
|
277
300
|
};
|
|
278
301
|
//#endregion
|
|
279
302
|
//#region ../core/dist/commands.d.ts
|
|
280
303
|
type WriteMethods = Omit<NessoStore, 'getState' | 'subscribe' | 'getViewGraph' | 'conceptPlacementOffset' | 'applyOperations' | 'setViewport' | 'setActiveRenderer' | 'resetGraph'>;
|
|
281
304
|
declare function createWriteCommands<Commit, Created>(applyOperations: (...args: Parameters<NessoStore['applyOperations']>) => Commit, created: (id: string, commit: Commit) => Created): { readonly [K in keyof WriteMethods]: (...args: Parameters<WriteMethods[K]>) => K extends 'addConcept' | 'createView' ? Created : Commit; };
|
|
282
305
|
//#endregion
|
|
306
|
+
//#region ../core/dist/vocab.d.ts
|
|
307
|
+
declare function resolveRelationTypeLabel(type: Readonly<RelationType>, vocabs: readonly VocabDefinition[], locale: Locale): string;
|
|
308
|
+
//#endregion
|
|
283
309
|
//#region src/definitions.d.ts
|
|
284
310
|
declare const themeColors: readonly ['background', 'foreground', 'canvas', 'sidebar', 'primary', 'primary-hover', 'primary-foreground', 'muted', 'muted-foreground', 'hover', 'pressed', 'border', 'ring', 'selection-halo', 'node-border', 'edge', 'handle'];
|
|
285
311
|
declare const themeDefinition: z.ZodObject<{
|
|
@@ -463,7 +489,7 @@ declare const actionBadgeResult: z.ZodObject<{
|
|
|
463
489
|
}, z.core.$strict>;
|
|
464
490
|
type ActionBadgeInput = {
|
|
465
491
|
readonly viewId: string | null;
|
|
466
|
-
readonly viewGraph:
|
|
492
|
+
readonly viewGraph: ViewGraphSnapshot;
|
|
467
493
|
readonly records: readonly PluginStorageRecord[];
|
|
468
494
|
readonly now: number;
|
|
469
495
|
};
|
|
@@ -493,7 +519,7 @@ type PluginI18n = DeepReadonly<{
|
|
|
493
519
|
}>;
|
|
494
520
|
declare function parsePluginI18n(value: unknown): PluginI18n;
|
|
495
521
|
declare const manifest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
496
|
-
apiVersion: z.ZodLiteral<
|
|
522
|
+
apiVersion: z.ZodLiteral<4>;
|
|
497
523
|
kind: z.ZodLiteral<"actions">;
|
|
498
524
|
entry: z.ZodString;
|
|
499
525
|
writes: z.ZodArray<z.ZodEnum<{
|
|
@@ -523,7 +549,7 @@ declare const manifest: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
523
549
|
ui: "ui";
|
|
524
550
|
}>>;
|
|
525
551
|
}, z.core.$strict>, ...z.ZodObject<{
|
|
526
|
-
apiVersion: z.ZodLiteral<
|
|
552
|
+
apiVersion: z.ZodLiteral<4>;
|
|
527
553
|
kind: z.ZodLiteral<"theme" | "vocab">;
|
|
528
554
|
entry: z.ZodString;
|
|
529
555
|
writes: z.ZodTuple<[], null>;
|
|
@@ -956,7 +982,7 @@ type ActionState = {
|
|
|
956
982
|
x: number;
|
|
957
983
|
y: number;
|
|
958
984
|
}>;
|
|
959
|
-
readonly viewGraph:
|
|
985
|
+
readonly viewGraph: ViewGraphSnapshot;
|
|
960
986
|
readonly selected: Selection;
|
|
961
987
|
readonly workspace: {
|
|
962
988
|
readonly activeViewId: string | null;
|
|
@@ -1011,4 +1037,4 @@ declare function createPluginClient(port: MessagePort, initial: unknown): {
|
|
|
1011
1037
|
getPresentation: () => Pick<ActionState, 'theme' | 'locale'>;
|
|
1012
1038
|
};
|
|
1013
1039
|
//#endregion
|
|
1014
|
-
export { FileOpenOptions as A, resolvePluginText as B, PluginStorageKey as C, parsePluginStorageRecord as D, parsePluginStorageKey as E, ImageRenderOptions as F,
|
|
1040
|
+
export { FileOpenOptions as A, resolvePluginText as B, PluginStorageKey as C, parsePluginStorageRecord as D, parsePluginStorageKey as E, ImageRenderOptions as F, resolveRelationTypeLabel as G, ThemeDefinition as H, RenderedImage as I, SavedView as J, GraphSnapshot as K, PluginError as L, FileSaveOptions as M, fileTextLimit as N, parsePluginStorageSnapshot as O, parseFileOptions as P, parseOrThrow as R, PluginStorage as S, PluginStorageScope as T, parseDefinition as U, Definition as V, themeColors as W, ViewGraphSnapshot as X, Selection as Y, VocabDefinition as Z, parsePluginMessage as _, ActionDescriptor as a, themeTokens as b, PluginI18n as c, badgeLimits as d, createPluginClient as f, parsePluginManifest as g, parsePluginI18n as h, ActionContribution as i, FileOpenResult as j, pluginStorageLimits as k, PluginManifest as l, parseContribution as m, ActionBadgeResult as n, ActionIconName as o, parseActionBadgeResult as p, NessoOperation as q, ActionContext as r, ActionState as s, ActionBadgeInput as t, actionIconNames as u, runtimeLimits as v, PluginStorageRecord as w, checkMessageSize as x, sha256Hex as y, LocalizedText as z };
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
//#region ../schema/dist/core.js
|
|
3
|
+
const conceptKeys = [
|
|
4
|
+
"@id",
|
|
5
|
+
"rdfs:label",
|
|
6
|
+
"rdfs:comment"
|
|
7
|
+
];
|
|
8
|
+
const newIri = () => `urn:uuid:${crypto.randomUUID()}`;
|
|
9
|
+
const isAbsoluteIri = (value) => typeof value === "string" && /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
10
|
+
const relationKey = ({ source, predicate, target }) => JSON.stringify([
|
|
11
|
+
source,
|
|
12
|
+
predicate,
|
|
13
|
+
target
|
|
14
|
+
]);
|
|
15
|
+
//#endregion
|
|
2
16
|
//#region ../errors/dist/index.js
|
|
3
17
|
function validationIssues(issues, prefix = "") {
|
|
4
18
|
return issues.map(({ path, message }) => ({
|
|
@@ -15,124 +29,6 @@ var NessoError = class extends Error {
|
|
|
15
29
|
}
|
|
16
30
|
};
|
|
17
31
|
//#endregion
|
|
18
|
-
//#region src/errors.ts
|
|
19
|
-
const boundText = (text, limit) => {
|
|
20
|
-
let result = "";
|
|
21
|
-
let bytes = 0;
|
|
22
|
-
const encoder = new TextEncoder();
|
|
23
|
-
for (const character of text) {
|
|
24
|
-
bytes += encoder.encode(character).byteLength;
|
|
25
|
-
if (bytes > limit) break;
|
|
26
|
-
result += character;
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
};
|
|
30
|
-
const pluginErrorCodes = [
|
|
31
|
-
"invalid-input",
|
|
32
|
-
"denied",
|
|
33
|
-
"stale-state",
|
|
34
|
-
"stale-context",
|
|
35
|
-
"unavailable",
|
|
36
|
-
"cancelled",
|
|
37
|
-
"timeout",
|
|
38
|
-
"closed",
|
|
39
|
-
"failed"
|
|
40
|
-
];
|
|
41
|
-
var PluginError = class extends NessoError {
|
|
42
|
-
name = "PluginError";
|
|
43
|
-
code;
|
|
44
|
-
displayMessage;
|
|
45
|
-
constructor(code, issues, displayMessage) {
|
|
46
|
-
const bounded = issues.slice(0, 32).map(({ path, message }) => ({
|
|
47
|
-
path: boundText(path, 256),
|
|
48
|
-
message: boundText(message, 2048)
|
|
49
|
-
}));
|
|
50
|
-
if (!bounded.length) bounded.push({
|
|
51
|
-
path: "plugin",
|
|
52
|
-
message: "Plugin request failed"
|
|
53
|
-
});
|
|
54
|
-
super(bounded);
|
|
55
|
-
this.code = code;
|
|
56
|
-
if (displayMessage) this.displayMessage = {
|
|
57
|
-
en: boundText(displayMessage.en, 2048),
|
|
58
|
-
...displayMessage.it !== void 0 ? { it: boundText(displayMessage.it, 2048) } : {},
|
|
59
|
-
...displayMessage["zh-CN"] !== void 0 ? { "zh-CN": boundText(displayMessage["zh-CN"], 2048) } : {}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
function parseOrThrow(schema, value, prefix = "") {
|
|
64
|
-
const parsed = schema.safeParse(value);
|
|
65
|
-
if (!parsed.success) throw new PluginError("invalid-input", parsed.error.issues.map((issue) => ({
|
|
66
|
-
path: `${prefix}${issue.path.join(".")}`,
|
|
67
|
-
message: issue.message
|
|
68
|
-
})));
|
|
69
|
-
return parsed.data;
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/files.ts
|
|
73
|
-
const fileTextLimit = 16777216;
|
|
74
|
-
const mediaType = z.string().max(128).regex(/^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/);
|
|
75
|
-
const fileOpenOptions = z.strictObject({
|
|
76
|
-
extensions: z.array(z.string().regex(/^[a-zA-Z0-9]{1,16}$/)).min(1).max(16),
|
|
77
|
-
mimeTypes: z.array(mediaType).max(16)
|
|
78
|
-
});
|
|
79
|
-
const fileFields = {
|
|
80
|
-
name: z.string().trim().min(1).max(240).regex(/^[^/\\]+$/).refine((value) => value !== "." && value !== ".." && [...value].every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127)),
|
|
81
|
-
mediaType
|
|
82
|
-
};
|
|
83
|
-
const fileText = z.string().max(fileTextLimit).refine((value) => new TextEncoder().encode(value).byteLength <= fileTextLimit, "File text byte limit exceeded");
|
|
84
|
-
const fileBase64 = z.string().max(4 * Math.ceil(fileTextLimit / 3)).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine((value) => {
|
|
85
|
-
const size = value.length / 4 * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
|
|
86
|
-
try {
|
|
87
|
-
return value.length % 4 === 0 && size <= 16777216 && btoa(atob(value)) === value;
|
|
88
|
-
} catch {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}, "Invalid base64 or file byte limit exceeded");
|
|
92
|
-
const fileSaveOptions = z.union([z.strictObject({
|
|
93
|
-
...fileFields,
|
|
94
|
-
text: fileText
|
|
95
|
-
}), z.strictObject({
|
|
96
|
-
...fileFields,
|
|
97
|
-
base64: fileBase64
|
|
98
|
-
})]);
|
|
99
|
-
const fileOpenResult = z.strictObject({
|
|
100
|
-
name: z.string().min(1).max(240),
|
|
101
|
-
mediaType,
|
|
102
|
-
text: fileText
|
|
103
|
-
}).nullable();
|
|
104
|
-
function parseFileOptions(kind, value) {
|
|
105
|
-
return parseOrThrow(kind === "open" ? fileOpenOptions : fileSaveOptions, value);
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/images.ts
|
|
109
|
-
const imageRenderOptions = z.strictObject({
|
|
110
|
-
format: z.literal("png"),
|
|
111
|
-
scale: z.union([z.literal(2), z.literal(4)]).optional()
|
|
112
|
-
});
|
|
113
|
-
const renderedImage = z.strictObject({
|
|
114
|
-
mediaType: z.literal("image/png"),
|
|
115
|
-
base64: fileBase64
|
|
116
|
-
});
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region ../schema/dist/core.js
|
|
119
|
-
const conceptKeys = [
|
|
120
|
-
"@id",
|
|
121
|
-
"rdfs:label",
|
|
122
|
-
"rdfs:comment",
|
|
123
|
-
"position",
|
|
124
|
-
"color",
|
|
125
|
-
"bold",
|
|
126
|
-
"italic"
|
|
127
|
-
];
|
|
128
|
-
const newIri = () => `urn:uuid:${crypto.randomUUID()}`;
|
|
129
|
-
const isAbsoluteIri = (value) => typeof value === "string" && /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
130
|
-
const relationKey = ({ source, predicate, target }) => JSON.stringify([
|
|
131
|
-
source,
|
|
132
|
-
predicate,
|
|
133
|
-
target
|
|
134
|
-
]);
|
|
135
|
-
//#endregion
|
|
136
32
|
//#region ../schema/dist/types.js
|
|
137
33
|
const iriSchema = z.string({ error: "Expected an absolute IRI" }).refine(isAbsoluteIri, "Expected an absolute IRI");
|
|
138
34
|
const positionSchema = z.strictObject({
|
|
@@ -142,12 +38,15 @@ const positionSchema = z.strictObject({
|
|
|
142
38
|
const conceptSchema = z.strictObject({
|
|
143
39
|
id: iriSchema,
|
|
144
40
|
label: z.string(),
|
|
145
|
-
notes: z.string().optional()
|
|
41
|
+
notes: z.string().optional()
|
|
42
|
+
});
|
|
43
|
+
const presentationSchema = z.strictObject({
|
|
44
|
+
position: positionSchema,
|
|
146
45
|
color: z.string().regex(/^#[0-9a-fA-F]{6}$/).optional(),
|
|
147
46
|
bold: z.boolean().optional(),
|
|
148
|
-
italic: z.boolean().optional()
|
|
149
|
-
position: positionSchema
|
|
47
|
+
italic: z.boolean().optional()
|
|
150
48
|
});
|
|
49
|
+
const viewMemberSchema = presentationSchema.extend({ id: iriSchema });
|
|
151
50
|
const relationTypeSchema = z.strictObject({
|
|
152
51
|
id: iriSchema.refine((id) => !conceptKeys.includes(id), "Reserved concept property IRI"),
|
|
153
52
|
label: z.string()
|
|
@@ -157,11 +56,17 @@ const relationSchema = z.strictObject({
|
|
|
157
56
|
predicate: iriSchema,
|
|
158
57
|
target: iriSchema
|
|
159
58
|
});
|
|
160
|
-
const
|
|
59
|
+
const viewSchema = z.strictObject({
|
|
60
|
+
id: iriSchema,
|
|
61
|
+
name: z.string(),
|
|
62
|
+
members: z.array(viewMemberSchema)
|
|
63
|
+
});
|
|
64
|
+
const graphShape = {
|
|
161
65
|
concepts: z.array(conceptSchema),
|
|
162
66
|
relationTypes: z.array(relationTypeSchema),
|
|
163
67
|
relations: z.array(relationSchema)
|
|
164
|
-
}
|
|
68
|
+
};
|
|
69
|
+
const checkReferences = (graph, context) => {
|
|
165
70
|
const concepts = /* @__PURE__ */ new Set();
|
|
166
71
|
const types = /* @__PURE__ */ new Set();
|
|
167
72
|
const relations = /* @__PURE__ */ new Set();
|
|
@@ -212,17 +117,60 @@ const graphSchema = z.strictObject({
|
|
|
212
117
|
});
|
|
213
118
|
relations.add(key);
|
|
214
119
|
}
|
|
120
|
+
};
|
|
121
|
+
const graphSchema = z.strictObject(graphShape).superRefine(checkReferences);
|
|
122
|
+
const viewGraphSchema = z.strictObject({
|
|
123
|
+
...graphShape,
|
|
124
|
+
concepts: z.array(conceptSchema.extend(presentationSchema.partial().shape))
|
|
125
|
+
}).superRefine(checkReferences);
|
|
126
|
+
const viewsSchema = (graph) => z.array(viewSchema).superRefine((views, context) => {
|
|
127
|
+
const concepts = new Set(graph.concepts.map(({ id }) => id));
|
|
128
|
+
const taken = /* @__PURE__ */ new Set([...concepts, ...graph.relationTypes.map(({ id }) => id)]);
|
|
129
|
+
for (const [index, view] of views.entries()) {
|
|
130
|
+
if (taken.has(view.id)) context.addIssue({
|
|
131
|
+
code: "custom",
|
|
132
|
+
path: [index, "id"],
|
|
133
|
+
message: `Duplicate view IRI: ${view.id}`
|
|
134
|
+
});
|
|
135
|
+
taken.add(view.id);
|
|
136
|
+
const members = /* @__PURE__ */ new Set();
|
|
137
|
+
for (const [position, member] of view.members.entries()) {
|
|
138
|
+
if (!concepts.has(member.id) || members.has(member.id)) context.addIssue({
|
|
139
|
+
code: "custom",
|
|
140
|
+
path: [
|
|
141
|
+
index,
|
|
142
|
+
"members",
|
|
143
|
+
position,
|
|
144
|
+
"id"
|
|
145
|
+
],
|
|
146
|
+
message: `${members.has(member.id) ? "Duplicate" : "Unknown"} view member: ${member.id}`
|
|
147
|
+
});
|
|
148
|
+
members.add(member.id);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
215
151
|
});
|
|
216
152
|
//#endregion
|
|
153
|
+
//#region ../schema/dist/migrations.js
|
|
154
|
+
const jsonObject$1 = z.record(z.string(), z.unknown());
|
|
155
|
+
z.strictObject({
|
|
156
|
+
"@context": jsonObject$1,
|
|
157
|
+
"@graph": z.array(jsonObject$1)
|
|
158
|
+
});
|
|
159
|
+
presentationSchema.partial();
|
|
160
|
+
z.object({ schemaVersion: z.number().int().positive().optional() });
|
|
161
|
+
//#endregion
|
|
217
162
|
//#region ../schema/dist/validate.js
|
|
218
|
-
function validateGraph(graph) {
|
|
163
|
+
function validateGraph(graph, views = []) {
|
|
219
164
|
const result = graphSchema.safeParse(graph);
|
|
220
|
-
|
|
165
|
+
if (!result.success) return validationIssues(result.error.issues);
|
|
166
|
+
const viewResult = viewsSchema(result.data).safeParse(views);
|
|
167
|
+
return viewResult.success ? [] : validationIssues(viewResult.error.issues, "views");
|
|
221
168
|
}
|
|
222
169
|
//#endregion
|
|
223
170
|
//#region ../schema/dist/jsonld.js
|
|
224
171
|
const jsonObject = z.record(z.string(), z.unknown());
|
|
225
172
|
z.strictObject({
|
|
173
|
+
schemaVersion: z.literal(1),
|
|
226
174
|
"@context": jsonObject,
|
|
227
175
|
"@graph": z.array(jsonObject)
|
|
228
176
|
});
|
|
@@ -234,111 +182,14 @@ z.strictObject({
|
|
|
234
182
|
z.object({
|
|
235
183
|
"@id": iriSchema,
|
|
236
184
|
"rdfs:label": conceptSchema.shape.label,
|
|
237
|
-
"rdfs:comment": conceptSchema.shape.notes
|
|
238
|
-
position: positionSchema.optional(),
|
|
239
|
-
color: conceptSchema.shape.color,
|
|
240
|
-
bold: conceptSchema.shape.bold,
|
|
241
|
-
italic: conceptSchema.shape.italic
|
|
185
|
+
"rdfs:comment": conceptSchema.shape.notes
|
|
242
186
|
}).catchall(z.unknown());
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
"
|
|
247
|
-
"
|
|
248
|
-
"canvas",
|
|
249
|
-
"sidebar",
|
|
250
|
-
"primary",
|
|
251
|
-
"primary-hover",
|
|
252
|
-
"primary-foreground",
|
|
253
|
-
"muted",
|
|
254
|
-
"muted-foreground",
|
|
255
|
-
"hover",
|
|
256
|
-
"pressed",
|
|
257
|
-
"border",
|
|
258
|
-
"ring",
|
|
259
|
-
"selection-halo",
|
|
260
|
-
"node-border",
|
|
261
|
-
"edge",
|
|
262
|
-
"handle"
|
|
263
|
-
];
|
|
264
|
-
const contributionId = z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
265
|
-
const color = z.string().regex(/^#[\da-fA-F]{6}([\da-fA-F]{2})?$/);
|
|
266
|
-
const luminance = (value) => {
|
|
267
|
-
const linear = [
|
|
268
|
-
1,
|
|
269
|
-
3,
|
|
270
|
-
5
|
|
271
|
-
].map((offset) => parseInt(value.slice(offset, offset + 2), 16) / 255).map((value) => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
|
|
272
|
-
return linear[0] * .2126 + linear[1] * .7152 + linear[2] * .0722;
|
|
273
|
-
};
|
|
274
|
-
const opaque = (value) => value.length === 7 || value.slice(7).toLowerCase() === "ff";
|
|
275
|
-
const contrast = (left, right) => (Math.max(luminance(left), luminance(right)) + .05) / (Math.min(luminance(left), luminance(right)) + .05);
|
|
276
|
-
const themeDefinition = z.strictObject({
|
|
277
|
-
id: contributionId,
|
|
278
|
-
colors: z.strictObject(Object.fromEntries(themeColors.map((key) => [key, color]))),
|
|
279
|
-
metrics: z.strictObject({
|
|
280
|
-
"radius-control": z.number().min(0).max(16),
|
|
281
|
-
"radius-object": z.number().min(0).max(16),
|
|
282
|
-
"duration-state": z.number().int().min(0).max(300)
|
|
283
|
-
})
|
|
284
|
-
}).superRefine(({ colors }, context) => {
|
|
285
|
-
for (const key of [
|
|
286
|
-
"background",
|
|
287
|
-
"canvas",
|
|
288
|
-
"sidebar"
|
|
289
|
-
]) {
|
|
290
|
-
if (!opaque(colors[key]) || luminance(colors[key]) < .8) context.addIssue({
|
|
291
|
-
code: "custom",
|
|
292
|
-
path: ["colors", key],
|
|
293
|
-
message: "Expected an opaque light surface"
|
|
294
|
-
});
|
|
295
|
-
if (!opaque(colors.foreground) || contrast(colors.foreground, colors[key]) < 4.5) context.addIssue({
|
|
296
|
-
code: "custom",
|
|
297
|
-
path: ["colors", "foreground"],
|
|
298
|
-
message: "Insufficient foreground contrast"
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
if (!opaque(colors.primary) || !opaque(colors["primary-foreground"]) || contrast(colors.primary, colors["primary-foreground"]) < 4.5) context.addIssue({
|
|
302
|
-
code: "custom",
|
|
303
|
-
path: ["colors", "primary-foreground"],
|
|
304
|
-
message: "Insufficient primary contrast"
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
const vocabRelationType = z.strictObject({
|
|
308
|
-
id: z.string().min(1).max(2048),
|
|
309
|
-
label: z.string().max(30),
|
|
310
|
-
translations: z.strictObject({
|
|
311
|
-
en: z.string().trim().min(1).max(30).optional(),
|
|
312
|
-
it: z.string().trim().min(1).max(30).optional(),
|
|
313
|
-
"zh-CN": z.string().trim().min(1).max(30).optional()
|
|
314
|
-
}).optional()
|
|
315
|
-
});
|
|
316
|
-
const vocabDefinition = z.strictObject({
|
|
317
|
-
id: contributionId,
|
|
318
|
-
relationTypes: z.array(vocabRelationType).min(1),
|
|
319
|
-
defaultTypeId: z.string().min(1).max(2048)
|
|
320
|
-
}).superRefine(({ relationTypes, defaultTypeId }, context) => {
|
|
321
|
-
for (const issue of validateGraph({
|
|
322
|
-
concepts: [],
|
|
323
|
-
relations: [],
|
|
324
|
-
relationTypes: relationTypes.map(({ id, label }) => ({
|
|
325
|
-
id,
|
|
326
|
-
label
|
|
327
|
-
}))
|
|
328
|
-
})) context.addIssue({
|
|
329
|
-
code: "custom",
|
|
330
|
-
path: ["relationTypes"],
|
|
331
|
-
message: issue.message
|
|
332
|
-
});
|
|
333
|
-
if (!relationTypes.some(({ id }) => id === defaultTypeId)) context.addIssue({
|
|
334
|
-
code: "custom",
|
|
335
|
-
path: ["defaultTypeId"],
|
|
336
|
-
message: "Default type must be offered by the vocabulary"
|
|
337
|
-
});
|
|
187
|
+
z.strictObject({
|
|
188
|
+
"@id": iriSchema,
|
|
189
|
+
"@type": z.literal("View"),
|
|
190
|
+
"rdfs:label": z.string(),
|
|
191
|
+
members: z.array(presentationSchema.extend({ concept: z.strictObject({ "@id": iriSchema }) }))
|
|
338
192
|
});
|
|
339
|
-
function parseDefinition(kind, value) {
|
|
340
|
-
return parseOrThrow(kind === "theme" ? themeDefinition : vocabDefinition, value);
|
|
341
|
-
}
|
|
342
193
|
//#endregion
|
|
343
194
|
//#region ../core/dist/commands.js
|
|
344
195
|
function createWriteCommands(applyOperations, created) {
|
|
@@ -478,6 +329,205 @@ function createWriteCommands(applyOperations, created) {
|
|
|
478
329
|
};
|
|
479
330
|
}
|
|
480
331
|
//#endregion
|
|
332
|
+
//#region src/errors.ts
|
|
333
|
+
const boundText = (text, limit) => {
|
|
334
|
+
let result = "";
|
|
335
|
+
let bytes = 0;
|
|
336
|
+
const encoder = new TextEncoder();
|
|
337
|
+
for (const character of text) {
|
|
338
|
+
bytes += encoder.encode(character).byteLength;
|
|
339
|
+
if (bytes > limit) break;
|
|
340
|
+
result += character;
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
};
|
|
344
|
+
const pluginErrorCodes = [
|
|
345
|
+
"invalid-input",
|
|
346
|
+
"denied",
|
|
347
|
+
"stale-state",
|
|
348
|
+
"stale-context",
|
|
349
|
+
"unavailable",
|
|
350
|
+
"cancelled",
|
|
351
|
+
"timeout",
|
|
352
|
+
"closed",
|
|
353
|
+
"failed"
|
|
354
|
+
];
|
|
355
|
+
var PluginError = class extends NessoError {
|
|
356
|
+
name = "PluginError";
|
|
357
|
+
code;
|
|
358
|
+
displayMessage;
|
|
359
|
+
constructor(code, issues, displayMessage) {
|
|
360
|
+
const bounded = issues.slice(0, 32).map(({ path, message }) => ({
|
|
361
|
+
path: boundText(path, 256),
|
|
362
|
+
message: boundText(message, 2048)
|
|
363
|
+
}));
|
|
364
|
+
if (!bounded.length) bounded.push({
|
|
365
|
+
path: "plugin",
|
|
366
|
+
message: "Plugin request failed"
|
|
367
|
+
});
|
|
368
|
+
super(bounded);
|
|
369
|
+
this.code = code;
|
|
370
|
+
if (displayMessage) this.displayMessage = {
|
|
371
|
+
en: boundText(displayMessage.en, 2048),
|
|
372
|
+
...displayMessage.it !== void 0 ? { it: boundText(displayMessage.it, 2048) } : {},
|
|
373
|
+
...displayMessage["zh-CN"] !== void 0 ? { "zh-CN": boundText(displayMessage["zh-CN"], 2048) } : {}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
function parseOrThrow(schema, value, prefix = "") {
|
|
378
|
+
const parsed = schema.safeParse(value);
|
|
379
|
+
if (!parsed.success) throw new PluginError("invalid-input", parsed.error.issues.map((issue) => ({
|
|
380
|
+
path: `${prefix}${issue.path.join(".")}`,
|
|
381
|
+
message: issue.message
|
|
382
|
+
})));
|
|
383
|
+
return parsed.data;
|
|
384
|
+
}
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/files.ts
|
|
387
|
+
const fileTextLimit = 16777216;
|
|
388
|
+
const mediaType = z.string().max(128).regex(/^[\w!#$&^.+-]+\/[\w!#$&^.+-]+$/);
|
|
389
|
+
const fileOpenOptions = z.strictObject({
|
|
390
|
+
extensions: z.array(z.string().regex(/^[a-zA-Z0-9]{1,16}$/)).min(1).max(16),
|
|
391
|
+
mimeTypes: z.array(mediaType).max(16)
|
|
392
|
+
});
|
|
393
|
+
const fileFields = {
|
|
394
|
+
name: z.string().trim().min(1).max(240).regex(/^[^/\\]+$/).refine((value) => value !== "." && value !== ".." && [...value].every((character) => character.charCodeAt(0) >= 32 && character.charCodeAt(0) !== 127)),
|
|
395
|
+
mediaType
|
|
396
|
+
};
|
|
397
|
+
const fileText = z.string().max(fileTextLimit).refine((value) => new TextEncoder().encode(value).byteLength <= fileTextLimit, "File text byte limit exceeded");
|
|
398
|
+
const fileBase64 = z.string().max(4 * Math.ceil(fileTextLimit / 3)).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine((value) => {
|
|
399
|
+
const size = value.length / 4 * 3 - (value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0);
|
|
400
|
+
try {
|
|
401
|
+
return value.length % 4 === 0 && size <= 16777216 && btoa(atob(value)) === value;
|
|
402
|
+
} catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}, "Invalid base64 or file byte limit exceeded");
|
|
406
|
+
const fileSaveOptions = z.union([z.strictObject({
|
|
407
|
+
...fileFields,
|
|
408
|
+
text: fileText
|
|
409
|
+
}), z.strictObject({
|
|
410
|
+
...fileFields,
|
|
411
|
+
base64: fileBase64
|
|
412
|
+
})]);
|
|
413
|
+
const fileOpenResult = z.strictObject({
|
|
414
|
+
name: z.string().min(1).max(240),
|
|
415
|
+
mediaType,
|
|
416
|
+
text: fileText
|
|
417
|
+
}).nullable();
|
|
418
|
+
function parseFileOptions(kind, value) {
|
|
419
|
+
return parseOrThrow(kind === "open" ? fileOpenOptions : fileSaveOptions, value);
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/images.ts
|
|
423
|
+
const imageRenderOptions = z.strictObject({
|
|
424
|
+
format: z.literal("png"),
|
|
425
|
+
scale: z.union([z.literal(2), z.literal(4)]).optional()
|
|
426
|
+
});
|
|
427
|
+
const renderedImage = z.strictObject({
|
|
428
|
+
mediaType: z.literal("image/png"),
|
|
429
|
+
base64: fileBase64
|
|
430
|
+
});
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/definitions.ts
|
|
433
|
+
const themeColors = [
|
|
434
|
+
"background",
|
|
435
|
+
"foreground",
|
|
436
|
+
"canvas",
|
|
437
|
+
"sidebar",
|
|
438
|
+
"primary",
|
|
439
|
+
"primary-hover",
|
|
440
|
+
"primary-foreground",
|
|
441
|
+
"muted",
|
|
442
|
+
"muted-foreground",
|
|
443
|
+
"hover",
|
|
444
|
+
"pressed",
|
|
445
|
+
"border",
|
|
446
|
+
"ring",
|
|
447
|
+
"selection-halo",
|
|
448
|
+
"node-border",
|
|
449
|
+
"edge",
|
|
450
|
+
"handle"
|
|
451
|
+
];
|
|
452
|
+
const contributionId = z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
453
|
+
const color = z.string().regex(/^#[\da-fA-F]{6}([\da-fA-F]{2})?$/);
|
|
454
|
+
const luminance = (value) => {
|
|
455
|
+
const linear = [
|
|
456
|
+
1,
|
|
457
|
+
3,
|
|
458
|
+
5
|
|
459
|
+
].map((offset) => parseInt(value.slice(offset, offset + 2), 16) / 255).map((value) => value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4);
|
|
460
|
+
return linear[0] * .2126 + linear[1] * .7152 + linear[2] * .0722;
|
|
461
|
+
};
|
|
462
|
+
const opaque = (value) => value.length === 7 || value.slice(7).toLowerCase() === "ff";
|
|
463
|
+
const contrast = (left, right) => (Math.max(luminance(left), luminance(right)) + .05) / (Math.min(luminance(left), luminance(right)) + .05);
|
|
464
|
+
const themeDefinition = z.strictObject({
|
|
465
|
+
id: contributionId,
|
|
466
|
+
colors: z.strictObject(Object.fromEntries(themeColors.map((key) => [key, color]))),
|
|
467
|
+
metrics: z.strictObject({
|
|
468
|
+
"radius-control": z.number().min(0).max(16),
|
|
469
|
+
"radius-object": z.number().min(0).max(16),
|
|
470
|
+
"duration-state": z.number().int().min(0).max(300)
|
|
471
|
+
})
|
|
472
|
+
}).superRefine(({ colors }, context) => {
|
|
473
|
+
for (const key of [
|
|
474
|
+
"background",
|
|
475
|
+
"canvas",
|
|
476
|
+
"sidebar"
|
|
477
|
+
]) {
|
|
478
|
+
if (!opaque(colors[key]) || luminance(colors[key]) < .8) context.addIssue({
|
|
479
|
+
code: "custom",
|
|
480
|
+
path: ["colors", key],
|
|
481
|
+
message: "Expected an opaque light surface"
|
|
482
|
+
});
|
|
483
|
+
if (!opaque(colors.foreground) || contrast(colors.foreground, colors[key]) < 4.5) context.addIssue({
|
|
484
|
+
code: "custom",
|
|
485
|
+
path: ["colors", "foreground"],
|
|
486
|
+
message: "Insufficient foreground contrast"
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (!opaque(colors.primary) || !opaque(colors["primary-foreground"]) || contrast(colors.primary, colors["primary-foreground"]) < 4.5) context.addIssue({
|
|
490
|
+
code: "custom",
|
|
491
|
+
path: ["colors", "primary-foreground"],
|
|
492
|
+
message: "Insufficient primary contrast"
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
const vocabRelationType = z.strictObject({
|
|
496
|
+
id: z.string().min(1).max(2048),
|
|
497
|
+
label: z.string().max(30),
|
|
498
|
+
translations: z.strictObject({
|
|
499
|
+
en: z.string().trim().min(1).max(30).optional(),
|
|
500
|
+
it: z.string().trim().min(1).max(30).optional(),
|
|
501
|
+
"zh-CN": z.string().trim().min(1).max(30).optional()
|
|
502
|
+
}).optional()
|
|
503
|
+
});
|
|
504
|
+
const vocabDefinition = z.strictObject({
|
|
505
|
+
id: contributionId,
|
|
506
|
+
relationTypes: z.array(vocabRelationType).min(1),
|
|
507
|
+
defaultTypeId: z.string().min(1).max(2048)
|
|
508
|
+
}).superRefine(({ relationTypes, defaultTypeId }, context) => {
|
|
509
|
+
for (const issue of validateGraph({
|
|
510
|
+
concepts: [],
|
|
511
|
+
relations: [],
|
|
512
|
+
relationTypes: relationTypes.map(({ id, label }) => ({
|
|
513
|
+
id,
|
|
514
|
+
label
|
|
515
|
+
}))
|
|
516
|
+
})) context.addIssue({
|
|
517
|
+
code: "custom",
|
|
518
|
+
path: ["relationTypes"],
|
|
519
|
+
message: issue.message
|
|
520
|
+
});
|
|
521
|
+
if (!relationTypes.some(({ id }) => id === defaultTypeId)) context.addIssue({
|
|
522
|
+
code: "custom",
|
|
523
|
+
path: ["defaultTypeId"],
|
|
524
|
+
message: "Default type must be offered by the vocabulary"
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
function parseDefinition(kind, value) {
|
|
528
|
+
return parseOrThrow(kind === "theme" ? themeDefinition : vocabDefinition, value);
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
481
531
|
//#region src/i18n.ts
|
|
482
532
|
const text = (limit) => z.string().max(limit).refine((value) => new TextEncoder().encode(value).byteLength <= limit, "Text byte limit exceeded");
|
|
483
533
|
const localizedText = (limit) => z.strictObject({
|
|
@@ -785,7 +835,7 @@ function parsePluginI18n(value) {
|
|
|
785
835
|
checkMessageSize(value, 65536);
|
|
786
836
|
return parseOrThrow(pluginI18n, value, "i18n.");
|
|
787
837
|
}
|
|
788
|
-
const manifestFields = { apiVersion: z.literal(
|
|
838
|
+
const manifestFields = { apiVersion: z.literal(4) };
|
|
789
839
|
const jsEntry = z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.js$/);
|
|
790
840
|
const jsonEntry = z.string().max(240).regex(/^(?:[\w-]+\/)*[\w-]+\.json$/);
|
|
791
841
|
const operationDeclarations = z.array(z.enum([
|
|
@@ -970,7 +1020,7 @@ const actionStateSchema = z.strictObject({
|
|
|
970
1020
|
locale,
|
|
971
1021
|
theme: z.strictObject(Object.fromEntries(themeTokens.map((token) => [token, z.string().max(512).regex(/^[#\w\s.,()%/"'-]*$/)]))),
|
|
972
1022
|
conceptPlacementOffset: position,
|
|
973
|
-
viewGraph:
|
|
1023
|
+
viewGraph: viewGraphSchema,
|
|
974
1024
|
selected: selection,
|
|
975
1025
|
targetViewId: id.nullable(),
|
|
976
1026
|
activeVocab: z.strictObject({
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as FileOpenOptions, B as resolvePluginText, D as parsePluginStorageRecord, E as parsePluginStorageKey, F as ImageRenderOptions, I as RenderedImage, L as PluginError, M as FileSaveOptions, N as fileTextLimit, O as parsePluginStorageSnapshot, P as parseFileOptions, R as parseOrThrow, U as parseDefinition, V as Definition, W as themeColors, _ as parsePluginMessage, a as ActionDescriptor, b as themeTokens, c as PluginI18n, d as badgeLimits, f as createPluginClient, g as parsePluginManifest, h as parsePluginI18n, i as ActionContribution, j as FileOpenResult, k as pluginStorageLimits, l as PluginManifest, m as parseContribution, n as ActionBadgeResult, o as ActionIconName, p as parseActionBadgeResult, r as ActionContext, s as ActionState, t as ActionBadgeInput, u as actionIconNames, v as runtimeLimits, x as checkMessageSize, y as sha256Hex, z as LocalizedText } from "./runtime-
|
|
1
|
+
import { A as FileOpenOptions, B as resolvePluginText, D as parsePluginStorageRecord, E as parsePluginStorageKey, F as ImageRenderOptions, I as RenderedImage, L as PluginError, M as FileSaveOptions, N as fileTextLimit, O as parsePluginStorageSnapshot, P as parseFileOptions, R as parseOrThrow, U as parseDefinition, V as Definition, W as themeColors, _ as parsePluginMessage, a as ActionDescriptor, b as themeTokens, c as PluginI18n, d as badgeLimits, f as createPluginClient, g as parsePluginManifest, h as parsePluginI18n, i as ActionContribution, j as FileOpenResult, k as pluginStorageLimits, l as PluginManifest, m as parseContribution, n as ActionBadgeResult, o as ActionIconName, p as parseActionBadgeResult, r as ActionContext, s as ActionState, t as ActionBadgeInput, u as actionIconNames, v as runtimeLimits, x as checkMessageSize, y as sha256Hex, z as LocalizedText } from "./runtime-B6vu2uAB.js";
|
|
2
2
|
export { ActionBadgeInput, ActionBadgeResult, ActionContext, ActionContribution, ActionDescriptor, ActionIconName, ActionState, type Definition, type FileOpenOptions, type FileOpenResult, type FileSaveOptions, type ImageRenderOptions, type LocalizedText, PluginError, PluginI18n, PluginManifest, type RenderedImage, actionIconNames, badgeLimits, checkMessageSize, createPluginClient, fileTextLimit, parseActionBadgeResult, parseContribution, parseDefinition, parseFileOptions, parseOrThrow, parsePluginI18n, parsePluginManifest, parsePluginMessage, parsePluginStorageKey, parsePluginStorageRecord, parsePluginStorageSnapshot, pluginStorageLimits, resolvePluginText, runtimeLimits, sha256Hex, themeColors, themeTokens };
|
package/dist/runtime.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { S as PluginError, t as actionIconNames, n as badgeLimits, g as checkMessageSize, r as createPluginClient, b as fileTextLimit, i as parseActionBadgeResult, a as parseContribution, v as parseDefinition, x as parseFileOptions, C as parseOrThrow, o as parsePluginI18n, s as parsePluginManifest, c as parsePluginMessage, f as parsePluginStorageKey, p as parsePluginStorageRecord, m as parsePluginStorageSnapshot, h as pluginStorageLimits, _ as resolvePluginText, l as runtimeLimits, u as sha256Hex, y as themeColors, d as themeTokens } from "./runtime-
|
|
1
|
+
export { S as PluginError, t as actionIconNames, n as badgeLimits, g as checkMessageSize, r as createPluginClient, b as fileTextLimit, i as parseActionBadgeResult, a as parseContribution, v as parseDefinition, x as parseFileOptions, C as parseOrThrow, o as parsePluginI18n, s as parsePluginManifest, c as parsePluginMessage, f as parsePluginStorageKey, p as parsePluginStorageRecord, m as parsePluginStorageSnapshot, h as pluginStorageLimits, _ as resolvePluginText, l as runtimeLimits, u as sha256Hex, y as themeColors, d as themeTokens } from "./runtime-D7mWRns_.js";
|
package/example/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nesso-how/plugin-example",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.16",
|
|
4
4
|
"description": "Official example showing how to build Nesso plugins with the SDK and plugin APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nesso-plugin"
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"prepack": "npm run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@nesso-how/ui": "1.0.0-beta.
|
|
31
|
+
"@nesso-how/ui": "1.0.0-beta.16",
|
|
32
32
|
"react": "^19.2.8",
|
|
33
33
|
"react-dom": "^19.2.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@nesso-how/plugin": "1.0.0-beta.
|
|
36
|
+
"@nesso-how/plugin": "1.0.0-beta.16",
|
|
37
37
|
"@types/react": "^19.2.18",
|
|
38
38
|
"@types/react-dom": "^19.2.7",
|
|
39
39
|
"typescript": "~7.0.2",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
}
|
|
55
55
|
},
|
|
56
56
|
"nesso": {
|
|
57
|
-
"apiVersion":
|
|
57
|
+
"apiVersion": 4,
|
|
58
58
|
"kind": "actions",
|
|
59
59
|
"entry": "dist/index.js",
|
|
60
60
|
"writes": [
|