@paged-media/plugin-sdk 0.2.4-canary.0 → 0.2.6-canary.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/dist/index.js +52 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -92,6 +92,8 @@ var HOST_FEATURES = [
|
|
|
92
92
|
"document.elementGeometry@1",
|
|
93
93
|
"document.tree@1",
|
|
94
94
|
"document.onDidChange@1",
|
|
95
|
+
"document.getMetadata@1",
|
|
96
|
+
"document.setMetadata@1",
|
|
95
97
|
"selection@1",
|
|
96
98
|
"viewport@1",
|
|
97
99
|
"overlay.toolPreview@1",
|
|
@@ -136,6 +138,7 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
136
138
|
const sink = options?.console ?? console;
|
|
137
139
|
const ns = `${manifest.id}.`;
|
|
138
140
|
const tag = `[${manifest.id}]`;
|
|
141
|
+
const metadataKey = (m) => `x-paged:${m.id}`;
|
|
139
142
|
const assertNamespaced = (id, kind) => {
|
|
140
143
|
if (!id.startsWith(ns)) {
|
|
141
144
|
throw new Error(
|
|
@@ -182,8 +185,26 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
182
185
|
);
|
|
183
186
|
}
|
|
184
187
|
};
|
|
188
|
+
const foreignMetadataKey = (m) => {
|
|
189
|
+
if (m.op === "setPluginMetadata") {
|
|
190
|
+
return m.args.key === metadataKey(manifest) ? null : m.args.key;
|
|
191
|
+
}
|
|
192
|
+
if (m.op === "batch") {
|
|
193
|
+
for (const child of m.args.ops) {
|
|
194
|
+
const bad = foreignMetadataKey(child);
|
|
195
|
+
if (bad !== null) return bad;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
};
|
|
185
200
|
const document = {
|
|
186
201
|
async mutate(mutation) {
|
|
202
|
+
const foreign = foreignMetadataKey(mutation);
|
|
203
|
+
if (foreign !== null) {
|
|
204
|
+
const error = `setPluginMetadata key "${foreign}" is outside this plugin's namespace ("${metadataKey(manifest)}")`;
|
|
205
|
+
log.warn(error);
|
|
206
|
+
return { applied: false, error };
|
|
207
|
+
}
|
|
187
208
|
try {
|
|
188
209
|
const reply = await getEditor().client.mutate(mutation);
|
|
189
210
|
if (reply.kind === "mutationApplied") {
|
|
@@ -236,6 +257,37 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
236
257
|
});
|
|
237
258
|
return reply.kind === "sceneTree" ? reply.payload.roots : [];
|
|
238
259
|
},
|
|
260
|
+
async getMetadata(id) {
|
|
261
|
+
const key = metadataKey(manifest);
|
|
262
|
+
const reply = await getEditor().client.send({
|
|
263
|
+
kind: "requestElementProperties",
|
|
264
|
+
payload: { id }
|
|
265
|
+
});
|
|
266
|
+
if (reply.kind !== "elementProperties" || !reply.payload.result) {
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
for (const entry of reply.payload.result.entries) {
|
|
270
|
+
const v = entry.value;
|
|
271
|
+
if (v && typeof v === "object" && v.type === "pluginMetadata" && v.value.key === key && typeof v.value.value === "string") {
|
|
272
|
+
try {
|
|
273
|
+
return JSON.parse(v.value.value);
|
|
274
|
+
} catch {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
},
|
|
281
|
+
async setMetadata(id, envelope) {
|
|
282
|
+
return this.mutate({
|
|
283
|
+
op: "setPluginMetadata",
|
|
284
|
+
args: {
|
|
285
|
+
elementId: id,
|
|
286
|
+
key: metadataKey(manifest),
|
|
287
|
+
value: envelope === null ? null : JSON.stringify(envelope)
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
},
|
|
239
291
|
onDidChange(listener) {
|
|
240
292
|
const off = getEditor().client.subscribe((msg) => {
|
|
241
293
|
if (msg.kind === "mutationApplied" || msg.kind === "undoApplied" || msg.kind === "redoApplied") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paged-media/plugin-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6-canary.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@paged-media/plugin-api": "0.2.
|
|
14
|
+
"@paged-media/plugin-api": "0.2.6-canary.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"typescript": "^5.6.3",
|
|
18
18
|
"vitest": "^2.1.8"
|
|
19
19
|
},
|
|
20
20
|
"description": "The Paged plugin runtime: loadBundle, the in-process BundleHost adapter, the gesture kit, and version negotiation.",
|
|
21
|
-
"license": "
|
|
21
|
+
"license": "MPL-2.0 OR LicenseRef-PMEL",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
24
24
|
],
|