@paged-media/plugin-sdk 0.2.4-canary.0 → 0.2.5-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.
Files changed (2) hide show
  1. package/dist/index.js +34 -0
  2. package/package.json +2 -2
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(
@@ -236,6 +239,37 @@ function createBundleHost(getEditor, manifest, options) {
236
239
  });
237
240
  return reply.kind === "sceneTree" ? reply.payload.roots : [];
238
241
  },
242
+ async getMetadata(id) {
243
+ const key = metadataKey(manifest);
244
+ const reply = await getEditor().client.send({
245
+ kind: "requestElementProperties",
246
+ payload: { id }
247
+ });
248
+ if (reply.kind !== "elementProperties" || !reply.payload.result) {
249
+ return null;
250
+ }
251
+ for (const entry of reply.payload.result.entries) {
252
+ const v = entry.value;
253
+ if (v && typeof v === "object" && v.type === "pluginMetadata" && v.value.key === key && typeof v.value.value === "string") {
254
+ try {
255
+ return JSON.parse(v.value.value);
256
+ } catch {
257
+ return null;
258
+ }
259
+ }
260
+ }
261
+ return null;
262
+ },
263
+ async setMetadata(id, envelope) {
264
+ return this.mutate({
265
+ op: "setPluginMetadata",
266
+ args: {
267
+ elementId: id,
268
+ key: metadataKey(manifest),
269
+ value: envelope === null ? null : JSON.stringify(envelope)
270
+ }
271
+ });
272
+ },
239
273
  onDidChange(listener) {
240
274
  const off = getEditor().client.subscribe((msg) => {
241
275
  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.4-canary.0",
3
+ "version": "0.2.5-canary.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@paged-media/plugin-api": "0.2.4-canary.0"
14
+ "@paged-media/plugin-api": "0.2.5-canary.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "typescript": "^5.6.3",