@paged-media/plugin-sdk 0.2.25-canary.0 → 0.2.26-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.d.ts +26 -0
- package/dist/index.js +41 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -192,6 +192,23 @@ interface ClipboardBackend {
|
|
|
192
192
|
read(): Promise<ClipboardPayload | null>;
|
|
193
193
|
write(payload: ClipboardPayload): Promise<void>;
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* The backend the editor injects to back `host.nativeDocument` (ADR-021 /
|
|
197
|
+
* document-model direction): the isolate-safe replacement for an importer/
|
|
198
|
+
* exporter reaching through `host.editor.client`. It exposes read access to
|
|
199
|
+
* the document's CORE-OWNED native parts (the `paged/core/` MODEL + COMPOSITION
|
|
200
|
+
* parts) plus a `open` that loads a plugin-produced native/importable package
|
|
201
|
+
* as the active document. The SDK adapter owns the capability gate; this
|
|
202
|
+
* backend only does the raw IO. A headless host injects no backend → the reads
|
|
203
|
+
* answer `null`/`[]`, `open` rejects, and `supports("document.readNative@1")` /
|
|
204
|
+
* `supports("document.openNative@1")` are false (the honest no-backend door).
|
|
205
|
+
*/
|
|
206
|
+
interface NativeDocumentBackend {
|
|
207
|
+
readModel(): Promise<Uint8Array | null>;
|
|
208
|
+
readComposition(): Promise<Uint8Array | null>;
|
|
209
|
+
listParts(prefix?: string): Promise<string[]>;
|
|
210
|
+
open(bytes: Uint8Array): Promise<void>;
|
|
211
|
+
}
|
|
195
212
|
/** The SHARED cross-plugin data-provider registry (paged.data §7.1 / D-09). The
|
|
196
213
|
* editor creates ONE (`createDataProviderRegistry`) and injects the SAME
|
|
197
214
|
* instance into every plugin host, so a provider plugin and a consumer plugin
|
|
@@ -305,6 +322,15 @@ interface CreateBundleHostOptions {
|
|
|
305
322
|
* When absent, `read` answers `null` and `write` is a no-op (the honest
|
|
306
323
|
* no-clipboard door). */
|
|
307
324
|
clipboard?: ClipboardBackend;
|
|
325
|
+
/** Host-provided NATIVE-DOCUMENT backend (ADR-021). When present,
|
|
326
|
+
* `host.nativeDocument.readModel/readComposition/listParts` read the
|
|
327
|
+
* document's core-owned `paged/core/` native parts through it (gated on
|
|
328
|
+
* `capabilities.document.readNative`) and `host.nativeDocument.open` loads a
|
|
329
|
+
* plugin-produced package as the active document (gated on
|
|
330
|
+
* `capabilities.document.openNative`); `supports("document.readNative@1")` /
|
|
331
|
+
* `supports("document.openNative@1")` answer true. When absent, the reads
|
|
332
|
+
* answer `null`/`[]` and `open` rejects (the honest no-backend door). */
|
|
333
|
+
nativeDocument?: NativeDocumentBackend;
|
|
308
334
|
/** Host-provided WORKER backend (K-3 / S-07 / I-02). When present,
|
|
309
335
|
* `host.workers.spawn` resolves a declared bundle-relative module +
|
|
310
336
|
* constructs a host-owned `Worker` through it (capability-gated,
|
package/dist/index.js
CHANGED
|
@@ -282,6 +282,8 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
282
282
|
const caps = manifest.capabilities;
|
|
283
283
|
const declared = manifest.contributes;
|
|
284
284
|
const hasDoc = (dir) => caps?.document?.[dir] !== void 0;
|
|
285
|
+
const hasNativeRead = () => caps?.document?.readNative === true;
|
|
286
|
+
const hasNativeOpen = () => caps?.document?.openNative === true;
|
|
285
287
|
const hasRendering = (s) => caps?.rendering?.includes(s) ?? false;
|
|
286
288
|
const hasAsset = (k) => caps?.assets?.includes(k) ?? false;
|
|
287
289
|
const hasBlobStore = () => caps?.storage?.blob === true;
|
|
@@ -538,6 +540,16 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
538
540
|
door,
|
|
539
541
|
"capabilities.document.read must be declared"
|
|
540
542
|
);
|
|
543
|
+
const requireNativeRead = (door) => requireDeclared(
|
|
544
|
+
hasNativeRead(),
|
|
545
|
+
door,
|
|
546
|
+
"capabilities.document.readNative must be declared"
|
|
547
|
+
);
|
|
548
|
+
const requireNativeOpen = (door) => requireDeclared(
|
|
549
|
+
hasNativeOpen(),
|
|
550
|
+
door,
|
|
551
|
+
"capabilities.document.openNative must be declared"
|
|
552
|
+
);
|
|
541
553
|
const document = {
|
|
542
554
|
async mutate(mutation) {
|
|
543
555
|
const denied = denyWrite(
|
|
@@ -1169,6 +1181,30 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
1169
1181
|
);
|
|
1170
1182
|
}
|
|
1171
1183
|
};
|
|
1184
|
+
const nativeDocBackend = options?.nativeDocument;
|
|
1185
|
+
const nativeDocument = {
|
|
1186
|
+
async readModel() {
|
|
1187
|
+
requireNativeRead("nativeDocument.readModel");
|
|
1188
|
+
return nativeDocBackend ? nativeDocBackend.readModel() : null;
|
|
1189
|
+
},
|
|
1190
|
+
async readComposition() {
|
|
1191
|
+
requireNativeRead("nativeDocument.readComposition");
|
|
1192
|
+
return nativeDocBackend ? nativeDocBackend.readComposition() : null;
|
|
1193
|
+
},
|
|
1194
|
+
async listParts(prefix2) {
|
|
1195
|
+
requireNativeRead("nativeDocument.listParts");
|
|
1196
|
+
return nativeDocBackend ? nativeDocBackend.listParts(prefix2) : [];
|
|
1197
|
+
},
|
|
1198
|
+
async open(bytes) {
|
|
1199
|
+
requireNativeOpen("nativeDocument.open");
|
|
1200
|
+
if (!nativeDocBackend) {
|
|
1201
|
+
throw new Error(
|
|
1202
|
+
'host.nativeDocument.open: the host wired no nativeDocument backend (supports("document.openNative@1") is false; the editor injects one)'
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
return nativeDocBackend.open(bytes);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1172
1208
|
const clipboardBackend = options?.clipboard;
|
|
1173
1209
|
const clipboardGate = (door) => {
|
|
1174
1210
|
const grant = clipboardGrant();
|
|
@@ -1405,6 +1441,10 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
1405
1441
|
if (options?.clipboard) {
|
|
1406
1442
|
featureSet.add("clipboard@1");
|
|
1407
1443
|
}
|
|
1444
|
+
if (options?.nativeDocument) {
|
|
1445
|
+
featureSet.add("document.readNative@1");
|
|
1446
|
+
featureSet.add("document.openNative@1");
|
|
1447
|
+
}
|
|
1408
1448
|
if (options?.workers) {
|
|
1409
1449
|
featureSet.add("workers@1");
|
|
1410
1450
|
}
|
|
@@ -1427,6 +1467,7 @@ function createBundleHost(getEditor, manifest, options) {
|
|
|
1427
1467
|
storage,
|
|
1428
1468
|
blob,
|
|
1429
1469
|
parts,
|
|
1470
|
+
nativeDocument,
|
|
1430
1471
|
network,
|
|
1431
1472
|
dataProviders,
|
|
1432
1473
|
diagnostics,
|
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.26-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.
|
|
14
|
+
"@paged-media/plugin-api": "0.2.26-canary.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"react": "^18.3.0"
|