@nesso-how/plugin 0.1.0 → 0.2.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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/package.d.ts +1 -1
- package/dist/package.js +1 -2
- package/dist/{runtime-CeTVu8np.d.ts → runtime-Ciol8MqD.d.ts} +4 -2
- package/dist/{runtime-Dfjx2_F9.js → runtime-DEm2BYYI.js} +214 -3
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +1 -3
- package/example/README.md +2 -2
- package/example/package.json +1 -1
- package/example/src/index.ts +0 -1
- package/package.json +30 -19
- package/dist/commands-xXIv9QeH.js +0 -191
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ Types, validation, and asynchronous clients for isolated Nesso actions plus data
|
|
|
6
6
|
|
|
7
7
|
Start with the [standalone action example](example/README.md). Actions export `create(context)` and build one self-contained browser JavaScript entry, bundling any dependencies. Nesso does not install dependencies, run package scripts, compile received source, or load module graphs. Themes and vocabularies ship a JSON definition file instead; the host validates it and never executes it.
|
|
8
8
|
|
|
9
|
-
- **Actions** return `{ id, label,
|
|
9
|
+
- **Actions** return `{ id, label, icon?, run }` records. `icon` is an optional `ActionIconName`: `arrow-right`, `book-open`, `clipboard-paste`, `copy`, `download`, `file-down`, `file-up`, `folder`, `globe`, `layers`, `pencil`, `play`, `plus`, `refresh`, `scissors`, `search`, `share`, `sparkles`, `upload`, `zap` (unknown keys render as `zap`). Discovery has no document access or effects; each invocation runs in a fresh worker. See [Import](../../plugins/import) and [Export](../../plugins/export).
|
|
10
10
|
- **Vocabularies** ship a `VocabDefinition` JSON file with stable absolute relation-type IRIs and a default among their own types. See [Base Vocab](../../plugins/base-vocab).
|
|
11
|
-
- **Themes** ship a light-only `ThemeDefinition` JSON file with colors, metrics, and local WOFF2 font descriptors. Include exactly the referenced fonts: at most 32 files, 4 MiB each. The host validates and applies them; arbitrary CSS and remote fonts are not supported. See [Kernel](../../plugins/kernel).
|
|
11
|
+
- **Themes** ship a light-only `ThemeDefinition` JSON file with colors, metrics, and local WOFF2 font descriptors. Include exactly the referenced fonts: at most 32 files, 4 MiB each. The host validates and applies them; arbitrary CSS and remote fonts are not supported. See [Kernel](../../plugins/kernel-theme) and [Paper](../../plugins/paper-theme).
|
|
12
12
|
|
|
13
13
|
Nesso injects the context. Import types such as `ActionContext` and `ActionContribution` from `@nesso-how/plugin`; there is no need to create a client yourself.
|
|
14
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActionContext, type ActionContribution, type ActionDescriptor, type ActionState, type BaseState, type GraphSnapshot, type LocalizedText, type NessoOperation, type NessoState, type NessoStore, type Notification, type NotificationAction, type Notifications, type PanelSizes, type PluginContext, PluginError, type PluginI18n, type PluginManifest, type Preferences, type SavedView, type SectionId, type Selection, type ThemeDefinition, type ViewState, type Viewport, type VocabDefinition, type WorkspaceState, createWriteCommands };
|
|
1
|
+
import { B as SavedView, D as PluginError, E as createWriteCommands, F as Notification, G as WorkspaceState, H as Selection, I as NotificationAction, L as Notifications, M as NessoOperation, N as NessoState, P as NessoStore, R as PanelSizes, U as Viewport, V as SectionId, W as VocabDefinition, a as ActionState, c as PluginI18n, d as actionIconNames, i as ActionIconName, j as GraphSnapshot, k as LocalizedText, l as PluginManifest, n as ActionContribution, o as BaseState, q as ThemeDefinition, r as ActionDescriptor, s as PluginContext, t as ActionContext, u as ViewState, z as Preferences } from "./runtime-Ciol8MqD.js";
|
|
2
|
+
export { type ActionContext, type ActionContribution, type ActionDescriptor, type ActionIconName, type ActionState, type BaseState, type GraphSnapshot, type LocalizedText, type NessoOperation, type NessoState, type NessoStore, type Notification, type NotificationAction, type Notifications, type PanelSizes, type PluginContext, PluginError, type PluginI18n, type PluginManifest, type Preferences, type SavedView, type SectionId, type Selection, type ThemeDefinition, type ViewState, type Viewport, type VocabDefinition, type WorkspaceState, actionIconNames, createWriteCommands };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { _ as PluginError, t as actionIconNames, g as createWriteCommands } from "./runtime-DEm2BYYI.js";
|
package/dist/package.d.ts
CHANGED
package/dist/package.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as parsePluginManifest, c as sha256Hex, i as parsePluginI18n, p as parseDefinition, t as checkMessageSize } from "./runtime-Dfjx2_F9.js";
|
|
1
|
+
import { _ as PluginError, a as parsePluginI18n, l as sha256Hex, m as parseDefinition, n as checkMessageSize, o as parsePluginManifest, v as parseOrThrow } from "./runtime-DEm2BYYI.js";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
import parseVersion from "semver/functions/parse.js";
|
|
5
4
|
import validateName from "validate-npm-package-name";
|
|
@@ -662,8 +662,10 @@ declare const actionDescriptor: z.ZodObject<{
|
|
|
662
662
|
it: z.ZodOptional<z.ZodString>;
|
|
663
663
|
'zh-CN': z.ZodOptional<z.ZodString>;
|
|
664
664
|
}, z.core.$strict>;
|
|
665
|
-
|
|
665
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
666
666
|
}, z.core.$strict>;
|
|
667
|
+
declare const actionIconNames: readonly ['arrow-right', 'book-open', 'clipboard-paste', 'copy', 'download', 'file-down', 'file-up', 'folder', 'globe', 'layers', 'pencil', 'play', 'plus', 'refresh', 'scissors', 'search', 'share', 'sparkles', 'upload', 'zap'];
|
|
668
|
+
type ActionIconName = typeof actionIconNames[number];
|
|
667
669
|
type ActionDescriptor = DeepReadonly<z.infer<typeof actionDescriptor>>;
|
|
668
670
|
type ActionContribution = ActionDescriptor & {
|
|
669
671
|
readonly run: (invocation: {
|
|
@@ -736,4 +738,4 @@ declare function createPluginClient<S extends BaseState>(port: MessagePort, init
|
|
|
736
738
|
close: () => void;
|
|
737
739
|
};
|
|
738
740
|
//#endregion
|
|
739
|
-
export {
|
|
741
|
+
export { resolvePluginText as A, SavedView as B, FileSaveOptions as C, PluginError as D, createWriteCommands as E, Notification as F, WorkspaceState as G, Selection as H, NotificationAction as I, parseDefinition as J, Definition as K, Notifications as L, NessoOperation as M, NessoState as N, parseOrThrow as O, NessoStore as P, PanelSizes as R, FileOpenResult as S, parseFileOptions as T, Viewport as U, SectionId as V, VocabDefinition as W, themeColors as Y, parsePluginMessage as _, ActionState as a, themeTokens as b, PluginI18n as c, actionIconNames as d, checkMessageSize as f, parsePluginManifest as g, parsePluginI18n as h, ActionIconName as i, GraphSnapshot as j, LocalizedText as k, PluginManifest as l, parseContribution as m, ActionContribution as n, BaseState as o, createPluginClient as p, ThemeDefinition as q, ActionDescriptor as r, PluginContext as s, ActionContext as t, ViewState as u, runtimeLimits as v, fileTextLimit as w, FileOpenOptions as x, sha256Hex as y, Preferences as z };
|
|
@@ -1,5 +1,194 @@
|
|
|
1
|
-
import { a as parseOrThrow, i as PluginError, n as isAbsoluteIri, r as relationKey, t as createWriteCommands } from "./commands-xXIv9QeH.js";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
//#region ../errors/src/index.ts
|
|
3
|
+
var NessoError = class extends Error {
|
|
4
|
+
name = "NessoError";
|
|
5
|
+
issues;
|
|
6
|
+
constructor(issues) {
|
|
7
|
+
super(issues.map(({ path, message }) => path ? `${path}: ${message}` : message).join("\n"));
|
|
8
|
+
this.issues = issues;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/errors.ts
|
|
13
|
+
const boundText = (text, limit) => {
|
|
14
|
+
let result = "";
|
|
15
|
+
let bytes = 0;
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
for (const character of text) {
|
|
18
|
+
bytes += encoder.encode(character).byteLength;
|
|
19
|
+
if (bytes > limit) break;
|
|
20
|
+
result += character;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
var PluginError = class extends NessoError {
|
|
25
|
+
name = "PluginError";
|
|
26
|
+
code;
|
|
27
|
+
displayMessage;
|
|
28
|
+
constructor(code, issues, displayMessage) {
|
|
29
|
+
const bounded = issues.slice(0, 32).map(({ path, message }) => ({
|
|
30
|
+
path: boundText(path, 256),
|
|
31
|
+
message: boundText(message, 2048)
|
|
32
|
+
}));
|
|
33
|
+
if (!bounded.length) bounded.push({
|
|
34
|
+
path: "plugin",
|
|
35
|
+
message: "Plugin request failed"
|
|
36
|
+
});
|
|
37
|
+
super(bounded);
|
|
38
|
+
this.code = code;
|
|
39
|
+
if (displayMessage) this.displayMessage = {
|
|
40
|
+
en: boundText(displayMessage.en, 2048),
|
|
41
|
+
...displayMessage.it !== void 0 ? { it: boundText(displayMessage.it, 2048) } : {},
|
|
42
|
+
...displayMessage["zh-CN"] !== void 0 ? { "zh-CN": boundText(displayMessage["zh-CN"], 2048) } : {}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function parseOrThrow(schema, value, prefix = "") {
|
|
47
|
+
const parsed = schema.safeParse(value);
|
|
48
|
+
if (!parsed.success) throw new PluginError("invalid-input", parsed.error.issues.map((issue) => ({
|
|
49
|
+
path: `${prefix}${issue.path.join(".")}`,
|
|
50
|
+
message: issue.message
|
|
51
|
+
})));
|
|
52
|
+
return parsed.data;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region ../schema/src/core.ts
|
|
56
|
+
const newIri = () => `urn:uuid:${crypto.randomUUID()}`;
|
|
57
|
+
const isAbsoluteIri = (value) => typeof value === "string" && /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
58
|
+
const relationKey = ({ source, predicate, target }) => JSON.stringify([
|
|
59
|
+
source,
|
|
60
|
+
predicate,
|
|
61
|
+
target
|
|
62
|
+
]);
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/commands.ts
|
|
65
|
+
function createWriteCommands(applyOperations, created) {
|
|
66
|
+
return {
|
|
67
|
+
undo: () => applyOperations([{ kind: "history.undo" }]),
|
|
68
|
+
redo: () => applyOperations([{ kind: "history.redo" }]),
|
|
69
|
+
setSelection: (value) => applyOperations([{
|
|
70
|
+
kind: "selection.set",
|
|
71
|
+
value
|
|
72
|
+
}]),
|
|
73
|
+
setView: (id) => applyOperations([{
|
|
74
|
+
kind: "view.activate",
|
|
75
|
+
id
|
|
76
|
+
}]),
|
|
77
|
+
setConceptPosition: (id, value, historyGroup) => applyOperations([{
|
|
78
|
+
kind: "concept.position",
|
|
79
|
+
id,
|
|
80
|
+
value
|
|
81
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
82
|
+
setConceptPositions: (updates, historyGroup) => applyOperations([{
|
|
83
|
+
kind: "concept.positions",
|
|
84
|
+
updates
|
|
85
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
86
|
+
setConceptLabel: (id, value, historyGroup) => applyOperations([{
|
|
87
|
+
kind: "concept.label",
|
|
88
|
+
id,
|
|
89
|
+
value
|
|
90
|
+
}], historyGroup ? { historyGroup } : void 0),
|
|
91
|
+
setConceptDescription: (id, value, historyGroup) => applyOperations([{
|
|
92
|
+
kind: "concept.description",
|
|
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
|
+
addConcept: (position, historyGroup) => {
|
|
102
|
+
const id = newIri();
|
|
103
|
+
return created(id, applyOperations([{
|
|
104
|
+
kind: "concept.add",
|
|
105
|
+
id,
|
|
106
|
+
position
|
|
107
|
+
}], historyGroup ? { historyGroup } : void 0));
|
|
108
|
+
},
|
|
109
|
+
connect: (source, target) => applyOperations([{
|
|
110
|
+
kind: "relation.connect",
|
|
111
|
+
source,
|
|
112
|
+
target
|
|
113
|
+
}]),
|
|
114
|
+
reconnectRelation: (id, source, target) => applyOperations([{
|
|
115
|
+
kind: "relation.reconnect",
|
|
116
|
+
id,
|
|
117
|
+
source,
|
|
118
|
+
target
|
|
119
|
+
}]),
|
|
120
|
+
setRelationType: (id, typeId) => applyOperations([{
|
|
121
|
+
kind: "relation.type",
|
|
122
|
+
id,
|
|
123
|
+
typeId
|
|
124
|
+
}]),
|
|
125
|
+
createRelationType: (id, label) => applyOperations([{
|
|
126
|
+
kind: "relation.type.create",
|
|
127
|
+
id,
|
|
128
|
+
typeId: newIri(),
|
|
129
|
+
label
|
|
130
|
+
}]),
|
|
131
|
+
removeConcept: (id) => applyOperations([{
|
|
132
|
+
kind: "concept.remove",
|
|
133
|
+
id
|
|
134
|
+
}]),
|
|
135
|
+
removeRelation: (id) => applyOperations([{
|
|
136
|
+
kind: "relation.remove",
|
|
137
|
+
id
|
|
138
|
+
}]),
|
|
139
|
+
setActiveVocab: (id) => applyOperations([{
|
|
140
|
+
kind: "preferences.vocab",
|
|
141
|
+
id
|
|
142
|
+
}]),
|
|
143
|
+
setActiveTheme: (id) => applyOperations([{
|
|
144
|
+
kind: "preferences.theme",
|
|
145
|
+
id
|
|
146
|
+
}]),
|
|
147
|
+
setLocale: (value) => applyOperations([{
|
|
148
|
+
kind: "preferences.locale",
|
|
149
|
+
value
|
|
150
|
+
}]),
|
|
151
|
+
setPanelSizes: (value) => applyOperations([{
|
|
152
|
+
kind: "preferences.panels",
|
|
153
|
+
value
|
|
154
|
+
}]),
|
|
155
|
+
setSectionOpen: (id, open) => applyOperations([{
|
|
156
|
+
kind: "preferences.section",
|
|
157
|
+
id,
|
|
158
|
+
open
|
|
159
|
+
}]),
|
|
160
|
+
createView: (name, conceptIds) => {
|
|
161
|
+
const id = newIri();
|
|
162
|
+
return created(id, applyOperations([{
|
|
163
|
+
kind: "view.create",
|
|
164
|
+
id,
|
|
165
|
+
name,
|
|
166
|
+
conceptIds
|
|
167
|
+
}]));
|
|
168
|
+
},
|
|
169
|
+
renameView: (id, name) => applyOperations([{
|
|
170
|
+
kind: "view.rename",
|
|
171
|
+
id,
|
|
172
|
+
name
|
|
173
|
+
}]),
|
|
174
|
+
setViewPinned: (id, pinned) => applyOperations([{
|
|
175
|
+
kind: "view.pin",
|
|
176
|
+
id,
|
|
177
|
+
pinned
|
|
178
|
+
}]),
|
|
179
|
+
setViewMembership: (viewId, conceptId, included) => applyOperations([{
|
|
180
|
+
kind: "view.membership",
|
|
181
|
+
viewId,
|
|
182
|
+
conceptId,
|
|
183
|
+
included
|
|
184
|
+
}]),
|
|
185
|
+
deleteView: (id) => applyOperations([{
|
|
186
|
+
kind: "view.remove",
|
|
187
|
+
id
|
|
188
|
+
}])
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
3
192
|
//#region ../schema/src/validate.ts
|
|
4
193
|
function validateGraph(graph) {
|
|
5
194
|
const issues = [];
|
|
@@ -498,8 +687,30 @@ const message = z.union([
|
|
|
498
687
|
const actionDescriptor = z.strictObject({
|
|
499
688
|
id: z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/),
|
|
500
689
|
label: localizedText(128),
|
|
501
|
-
|
|
690
|
+
icon: z.string().min(1).max(32).regex(/^[a-z]+(?:-[a-z]+)*$/).optional()
|
|
502
691
|
});
|
|
692
|
+
const actionIconNames = [
|
|
693
|
+
"arrow-right",
|
|
694
|
+
"book-open",
|
|
695
|
+
"clipboard-paste",
|
|
696
|
+
"copy",
|
|
697
|
+
"download",
|
|
698
|
+
"file-down",
|
|
699
|
+
"file-up",
|
|
700
|
+
"folder",
|
|
701
|
+
"globe",
|
|
702
|
+
"layers",
|
|
703
|
+
"pencil",
|
|
704
|
+
"play",
|
|
705
|
+
"plus",
|
|
706
|
+
"refresh",
|
|
707
|
+
"scissors",
|
|
708
|
+
"search",
|
|
709
|
+
"share",
|
|
710
|
+
"sparkles",
|
|
711
|
+
"upload",
|
|
712
|
+
"zap"
|
|
713
|
+
];
|
|
503
714
|
const actionDescriptors = z.array(actionDescriptor).min(1).max(64).refine((value) => new Set(value.map(({ id }) => id)).size === value.length, "Action IDs must be unique");
|
|
504
715
|
function parseContribution(kind, value) {
|
|
505
716
|
checkMessageSize(value, 1048576);
|
|
@@ -761,4 +972,4 @@ function createPluginClient(port, initial) {
|
|
|
761
972
|
};
|
|
762
973
|
}
|
|
763
974
|
//#endregion
|
|
764
|
-
export {
|
|
975
|
+
export { PluginError as _, parsePluginI18n as a, runtimeLimits as c, resolvePluginText as d, fileTextLimit as f, createWriteCommands as g, themeColors as h, parseContribution as i, sha256Hex as l, parseDefinition as m, checkMessageSize as n, parsePluginManifest as o, parseFileOptions as p, createPluginClient as r, parsePluginMessage as s, actionIconNames as t, themeTokens as u, parseOrThrow as v };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
export { ActionContext, ActionContribution, ActionDescriptor, ActionState, BaseState, type Definition, type FileOpenOptions, type FileOpenResult, type FileSaveOptions, type LocalizedText, PluginContext, PluginError, PluginI18n, PluginManifest, ViewState, checkMessageSize, createPluginClient, fileTextLimit, parseContribution, parseDefinition, parseFileOptions, parseOrThrow, parsePluginI18n, parsePluginManifest, parsePluginMessage, resolvePluginText, runtimeLimits, sha256Hex, themeColors, themeTokens };
|
|
1
|
+
import { A as resolvePluginText, C as FileSaveOptions, D as PluginError, J as parseDefinition, K as Definition, O as parseOrThrow, S as FileOpenResult, T as parseFileOptions, Y as themeColors, _ as parsePluginMessage, a as ActionState, b as themeTokens, c as PluginI18n, d as actionIconNames, f as checkMessageSize, g as parsePluginManifest, h as parsePluginI18n, i as ActionIconName, k as LocalizedText, l as PluginManifest, m as parseContribution, n as ActionContribution, o as BaseState, p as createPluginClient, r as ActionDescriptor, s as PluginContext, t as ActionContext, u as ViewState, v as runtimeLimits, w as fileTextLimit, x as FileOpenOptions, y as sha256Hex } from "./runtime-Ciol8MqD.js";
|
|
2
|
+
export { ActionContext, ActionContribution, ActionDescriptor, ActionIconName, ActionState, BaseState, type Definition, type FileOpenOptions, type FileOpenResult, type FileSaveOptions, type LocalizedText, PluginContext, PluginError, PluginI18n, PluginManifest, ViewState, actionIconNames, checkMessageSize, createPluginClient, fileTextLimit, parseContribution, parseDefinition, parseFileOptions, parseOrThrow, parsePluginI18n, parsePluginManifest, parsePluginMessage, resolvePluginText, runtimeLimits, sha256Hex, themeColors, themeTokens };
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { a as parsePluginManifest, c as sha256Hex, d as fileTextLimit, f as parseFileOptions, i as parsePluginI18n, l as themeTokens, m as themeColors, n as createPluginClient, o as parsePluginMessage, p as parseDefinition, r as parseContribution, s as runtimeLimits, t as checkMessageSize, u as resolvePluginText } from "./runtime-Dfjx2_F9.js";
|
|
3
|
-
export { PluginError, checkMessageSize, createPluginClient, fileTextLimit, parseContribution, parseDefinition, parseFileOptions, parseOrThrow, parsePluginI18n, parsePluginManifest, parsePluginMessage, resolvePluginText, runtimeLimits, sha256Hex, themeColors, themeTokens };
|
|
1
|
+
export { _ as PluginError, t as actionIconNames, n as checkMessageSize, r as createPluginClient, f as fileTextLimit, i as parseContribution, m as parseDefinition, p as parseFileOptions, v as parseOrThrow, a as parsePluginI18n, o as parsePluginManifest, s as parsePluginMessage, d as resolvePluginText, c as runtimeLimits, l as sha256Hex, h as themeColors, u as themeTokens } from "./runtime-DEm2BYYI.js";
|
package/example/README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Uppercases labels in the invoked view with one undoable batch. Shared concepts change in every view containing them.
|
|
4
4
|
|
|
5
|
-
Copy this directory outside the workspace,
|
|
5
|
+
Copy this directory outside the workspace, then install the published SDK and build:
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install --
|
|
8
|
+
npm install --save-dev @nesso-how/plugin@^0.1.0
|
|
9
9
|
npm run build
|
|
10
10
|
```
|
|
11
11
|
|
package/example/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"build": "npm run check && esbuild src/index.ts --bundle --format=esm --platform=browser --target=es2022 --outfile=dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@nesso-how/plugin": "0.
|
|
14
|
+
"@nesso-how/plugin": "^0.1.0",
|
|
15
15
|
"esbuild": "^0.28.2",
|
|
16
16
|
"typescript": "~7.0.2"
|
|
17
17
|
},
|
package/example/src/index.ts
CHANGED
|
@@ -4,7 +4,6 @@ import source from '../package.json' with { type: 'json' }
|
|
|
4
4
|
export const create = ({ store }: ActionContext): readonly ActionContribution[] => [{
|
|
5
5
|
id: 'uppercase-labels',
|
|
6
6
|
label: source.i18n.metadata.name,
|
|
7
|
-
supportsViews: true,
|
|
8
7
|
run: async () => {
|
|
9
8
|
const state = store.getState()
|
|
10
9
|
if (!('viewGraph' in state)) return
|
package/package.json
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nesso-how/plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Types, validation, and asynchronous clients for isolated Nesso plugins",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/nesso-how/nesso.git",
|
|
9
|
+
"directory": "packages/plugin"
|
|
10
|
+
},
|
|
6
11
|
"type": "module",
|
|
7
|
-
"files": [
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"example"
|
|
15
|
+
],
|
|
8
16
|
"types": "./dist/index.d.ts",
|
|
9
17
|
"exports": {
|
|
10
|
-
".":
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./runtime": {
|
|
23
|
+
"types": "./dist/runtime.d.ts",
|
|
24
|
+
"default": "./dist/runtime.js"
|
|
25
|
+
},
|
|
26
|
+
"./package": {
|
|
27
|
+
"types": "./dist/package.d.ts",
|
|
28
|
+
"default": "./dist/package.js"
|
|
20
29
|
}
|
|
21
30
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"prepack": "pnpm run build"
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
25
33
|
},
|
|
26
34
|
"dependencies": {
|
|
27
35
|
"semver": "^7.8.5",
|
|
@@ -29,11 +37,14 @@
|
|
|
29
37
|
"zod": "^4.6.5"
|
|
30
38
|
},
|
|
31
39
|
"devDependencies": {
|
|
32
|
-
"@nesso-how/errors": "
|
|
33
|
-
"@nesso-how/i18n": "
|
|
34
|
-
"@nesso-how/schema": "
|
|
40
|
+
"@nesso-how/errors": "0.0.0",
|
|
41
|
+
"@nesso-how/i18n": "0.0.0",
|
|
42
|
+
"@nesso-how/schema": "0.0.0",
|
|
35
43
|
"@types/semver": "^7.8.0",
|
|
36
44
|
"@types/validate-npm-package-name": "^4.0.2",
|
|
37
45
|
"tsdown": "^0.23.1"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p ../../tsconfig.plugin.json && tsdown"
|
|
38
49
|
}
|
|
39
|
-
}
|
|
50
|
+
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
//#region ../errors/src/index.ts
|
|
2
|
-
var NessoError = class extends Error {
|
|
3
|
-
name = "NessoError";
|
|
4
|
-
issues;
|
|
5
|
-
constructor(issues) {
|
|
6
|
-
super(issues.map(({ path, message }) => path ? `${path}: ${message}` : message).join("\n"));
|
|
7
|
-
this.issues = issues;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/errors.ts
|
|
12
|
-
const boundText = (text, limit) => {
|
|
13
|
-
let result = "";
|
|
14
|
-
let bytes = 0;
|
|
15
|
-
const encoder = new TextEncoder();
|
|
16
|
-
for (const character of text) {
|
|
17
|
-
bytes += encoder.encode(character).byteLength;
|
|
18
|
-
if (bytes > limit) break;
|
|
19
|
-
result += character;
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
var PluginError = class extends NessoError {
|
|
24
|
-
name = "PluginError";
|
|
25
|
-
code;
|
|
26
|
-
displayMessage;
|
|
27
|
-
constructor(code, issues, displayMessage) {
|
|
28
|
-
const bounded = issues.slice(0, 32).map(({ path, message }) => ({
|
|
29
|
-
path: boundText(path, 256),
|
|
30
|
-
message: boundText(message, 2048)
|
|
31
|
-
}));
|
|
32
|
-
if (!bounded.length) bounded.push({
|
|
33
|
-
path: "plugin",
|
|
34
|
-
message: "Plugin request failed"
|
|
35
|
-
});
|
|
36
|
-
super(bounded);
|
|
37
|
-
this.code = code;
|
|
38
|
-
if (displayMessage) this.displayMessage = {
|
|
39
|
-
en: boundText(displayMessage.en, 2048),
|
|
40
|
-
...displayMessage.it !== void 0 ? { it: boundText(displayMessage.it, 2048) } : {},
|
|
41
|
-
...displayMessage["zh-CN"] !== void 0 ? { "zh-CN": boundText(displayMessage["zh-CN"], 2048) } : {}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
function parseOrThrow(schema, value, prefix = "") {
|
|
46
|
-
const parsed = schema.safeParse(value);
|
|
47
|
-
if (!parsed.success) throw new PluginError("invalid-input", parsed.error.issues.map((issue) => ({
|
|
48
|
-
path: `${prefix}${issue.path.join(".")}`,
|
|
49
|
-
message: issue.message
|
|
50
|
-
})));
|
|
51
|
-
return parsed.data;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region ../schema/src/core.ts
|
|
55
|
-
const newIri = () => `urn:uuid:${crypto.randomUUID()}`;
|
|
56
|
-
const isAbsoluteIri = (value) => typeof value === "string" && /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
57
|
-
const relationKey = ({ source, predicate, target }) => JSON.stringify([
|
|
58
|
-
source,
|
|
59
|
-
predicate,
|
|
60
|
-
target
|
|
61
|
-
]);
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region src/commands.ts
|
|
64
|
-
function createWriteCommands(applyOperations, created) {
|
|
65
|
-
return {
|
|
66
|
-
undo: () => applyOperations([{ kind: "history.undo" }]),
|
|
67
|
-
redo: () => applyOperations([{ kind: "history.redo" }]),
|
|
68
|
-
setSelection: (value) => applyOperations([{
|
|
69
|
-
kind: "selection.set",
|
|
70
|
-
value
|
|
71
|
-
}]),
|
|
72
|
-
setView: (id) => applyOperations([{
|
|
73
|
-
kind: "view.activate",
|
|
74
|
-
id
|
|
75
|
-
}]),
|
|
76
|
-
setConceptPosition: (id, value, historyGroup) => applyOperations([{
|
|
77
|
-
kind: "concept.position",
|
|
78
|
-
id,
|
|
79
|
-
value
|
|
80
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
81
|
-
setConceptPositions: (updates, historyGroup) => applyOperations([{
|
|
82
|
-
kind: "concept.positions",
|
|
83
|
-
updates
|
|
84
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
85
|
-
setConceptLabel: (id, value, historyGroup) => applyOperations([{
|
|
86
|
-
kind: "concept.label",
|
|
87
|
-
id,
|
|
88
|
-
value
|
|
89
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
90
|
-
setConceptDescription: (id, value, historyGroup) => applyOperations([{
|
|
91
|
-
kind: "concept.description",
|
|
92
|
-
id,
|
|
93
|
-
value
|
|
94
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
95
|
-
setConceptColor: (id, value, historyGroup) => applyOperations([{
|
|
96
|
-
kind: "concept.color",
|
|
97
|
-
id,
|
|
98
|
-
value
|
|
99
|
-
}], historyGroup ? { historyGroup } : void 0),
|
|
100
|
-
addConcept: (position, historyGroup) => {
|
|
101
|
-
const id = newIri();
|
|
102
|
-
return created(id, applyOperations([{
|
|
103
|
-
kind: "concept.add",
|
|
104
|
-
id,
|
|
105
|
-
position
|
|
106
|
-
}], historyGroup ? { historyGroup } : void 0));
|
|
107
|
-
},
|
|
108
|
-
connect: (source, target) => applyOperations([{
|
|
109
|
-
kind: "relation.connect",
|
|
110
|
-
source,
|
|
111
|
-
target
|
|
112
|
-
}]),
|
|
113
|
-
reconnectRelation: (id, source, target) => applyOperations([{
|
|
114
|
-
kind: "relation.reconnect",
|
|
115
|
-
id,
|
|
116
|
-
source,
|
|
117
|
-
target
|
|
118
|
-
}]),
|
|
119
|
-
setRelationType: (id, typeId) => applyOperations([{
|
|
120
|
-
kind: "relation.type",
|
|
121
|
-
id,
|
|
122
|
-
typeId
|
|
123
|
-
}]),
|
|
124
|
-
createRelationType: (id, label) => applyOperations([{
|
|
125
|
-
kind: "relation.type.create",
|
|
126
|
-
id,
|
|
127
|
-
typeId: newIri(),
|
|
128
|
-
label
|
|
129
|
-
}]),
|
|
130
|
-
removeConcept: (id) => applyOperations([{
|
|
131
|
-
kind: "concept.remove",
|
|
132
|
-
id
|
|
133
|
-
}]),
|
|
134
|
-
removeRelation: (id) => applyOperations([{
|
|
135
|
-
kind: "relation.remove",
|
|
136
|
-
id
|
|
137
|
-
}]),
|
|
138
|
-
setActiveVocab: (id) => applyOperations([{
|
|
139
|
-
kind: "preferences.vocab",
|
|
140
|
-
id
|
|
141
|
-
}]),
|
|
142
|
-
setActiveTheme: (id) => applyOperations([{
|
|
143
|
-
kind: "preferences.theme",
|
|
144
|
-
id
|
|
145
|
-
}]),
|
|
146
|
-
setLocale: (value) => applyOperations([{
|
|
147
|
-
kind: "preferences.locale",
|
|
148
|
-
value
|
|
149
|
-
}]),
|
|
150
|
-
setPanelSizes: (value) => applyOperations([{
|
|
151
|
-
kind: "preferences.panels",
|
|
152
|
-
value
|
|
153
|
-
}]),
|
|
154
|
-
setSectionOpen: (id, open) => applyOperations([{
|
|
155
|
-
kind: "preferences.section",
|
|
156
|
-
id,
|
|
157
|
-
open
|
|
158
|
-
}]),
|
|
159
|
-
createView: (name, conceptIds) => {
|
|
160
|
-
const id = newIri();
|
|
161
|
-
return created(id, applyOperations([{
|
|
162
|
-
kind: "view.create",
|
|
163
|
-
id,
|
|
164
|
-
name,
|
|
165
|
-
conceptIds
|
|
166
|
-
}]));
|
|
167
|
-
},
|
|
168
|
-
renameView: (id, name) => applyOperations([{
|
|
169
|
-
kind: "view.rename",
|
|
170
|
-
id,
|
|
171
|
-
name
|
|
172
|
-
}]),
|
|
173
|
-
setViewPinned: (id, pinned) => applyOperations([{
|
|
174
|
-
kind: "view.pin",
|
|
175
|
-
id,
|
|
176
|
-
pinned
|
|
177
|
-
}]),
|
|
178
|
-
setViewMembership: (viewId, conceptId, included) => applyOperations([{
|
|
179
|
-
kind: "view.membership",
|
|
180
|
-
viewId,
|
|
181
|
-
conceptId,
|
|
182
|
-
included
|
|
183
|
-
}]),
|
|
184
|
-
deleteView: (id) => applyOperations([{
|
|
185
|
-
kind: "view.remove",
|
|
186
|
-
id
|
|
187
|
-
}])
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
//#endregion
|
|
191
|
-
export { parseOrThrow as a, PluginError as i, isAbsoluteIri as n, relationKey as r, createWriteCommands as t };
|