@paged-media/plugin-sdk 0.2.50-canary.0 → 0.2.51-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 CHANGED
@@ -1,4 +1,4 @@
1
- import { PagedBundle, ParsedAddress, ElementId, MutationInput, MutationOutcome, ObjectErrorCode, ObjectKindInfo, PropertySchema, ObjectValue, ObjectOp, PagedEditor, ObjectsSurface, ObjectModelContribution, PartsSurface, PluginLogger, ObjectModelHandle, BindingProvider, Disposable, ActiveBindingProvider, BindingPropertyRequest, BindingReadResult, BindingPropertyWrite, BindingWriteResult, BindingCollectionRequest, BindingCollectionResult, FontFaceAsset, BundleHost, ClipboardPayload, ConsentResult, DataProviderRegistration, DataProviderHandle, DataProviderInfo, DataProviderSnapshot, JournalRecord, ShellSurface, WidgetSurface, WillSaveEvent, ToolSettingValue, SchemaPanelRenderer, SchemaPanelContribution, EditContextContribution, ObjectTypeContribution, Diagnostic, TextCaret, OpenDocumentResult, PluginManifest, ToolContribution, PanelContribution, CommandContribution, KeybindingContribution, OverlayContribution, ImporterContribution, ExporterContribution, ToolPreviewShape, EnteredEditContext, ValueType, ObjectCommandInfo, PropertyPath, BindingsSurface, PanelProps, SchemaGate, WasmArtifact, CanvasPointerEvent, Mutation, PanelSchemaPropertyRow, PanelSchemaRow, PropertyFieldAddress, PanelSchema, ValueEdit, Address, ListEdit, StructEdit, ObjectWriteResult, BindingProviderHandle } from '@paged-media/plugin-api';
1
+ import { PagedBundle, ParsedAddress, ElementId, MutationInput, MutationOutcome, ObjectErrorCode, ObjectKindInfo, PropertySchema, ObjectValue, ObjectOp, PagedEditor, ObjectsSurface, ObjectModelContribution, PartsSurface, PluginLogger, ObjectModelHandle, BindingProvider, Disposable, ActiveBindingProvider, BindingPropertyRequest, BindingReadResult, BindingPropertyWrite, BindingWriteResult, BindingCollectionRequest, BindingCollectionResult, FontFaceAsset, BundleHost, ClipboardPayload, ConsentResult, DataProviderRegistration, DataProviderHandle, DataProviderInfo, DataProviderSnapshot, JournalRecord, ShellSurface, WidgetSurface, WillSaveEvent, ToolSettingValue, SchemaPanelRenderer, SchemaPanelContribution, EditContextContribution, ObjectTypeContribution, Diagnostic, TextCaret, OpenDocumentResult, WasmArtifact, PluginManifest, ToolContribution, PanelContribution, CommandContribution, KeybindingContribution, OverlayContribution, ImporterContribution, ExporterContribution, ToolPreviewShape, EnteredEditContext, ValueType, ObjectCommandInfo, PropertyPath, BindingsSurface, PanelProps, SchemaGate, ModulesSurface, CanvasPointerEvent, Mutation, PanelSchemaPropertyRow, PanelSchemaRow, PropertyFieldAddress, PanelSchema, ValueEdit, Address, ListEdit, StructEdit, ObjectWriteResult, BindingProviderHandle } from '@paged-media/plugin-api';
2
2
  import { ComponentType } from 'react';
3
3
 
4
4
  /**
@@ -339,6 +339,31 @@ interface SpawnedWorker {
339
339
  interface WorkerBackend {
340
340
  spawn(pluginId: string, module: string, name?: string): Promise<SpawnedWorker>;
341
341
  }
342
+ /**
343
+ * What a `ModulesBackend` answers for one declared artifact: the URL the
344
+ * host serves its bytes at and, when the host knows it, the bytes'
345
+ * Subresource Integrity (`sha384-…`).
346
+ */
347
+ interface ModuleLocation {
348
+ url: string;
349
+ integrity?: string | null;
350
+ }
351
+ /**
352
+ * The backend the editor injects to back `host.modules` (ADR 326). The SDK
353
+ * adapter owns the capability gate (only a name declared in
354
+ * `capabilities.wasm` reaches the backend, and the backend receives the
355
+ * DECLARED artifact, never a bundle-supplied path) and the integrity rule
356
+ * (the manifest's own `integrity` wins; a contradicting host answer is
357
+ * refused). The backend maps `(pluginId, artifact)` to where the host serves
358
+ * those bytes — the editor answers from its build-time module manifest
359
+ * (`https://modules.paged.media/<package>/<version>/<path>` in a deployed
360
+ * build). `null` = "not served here": the bundle loads its own copy. A
361
+ * headless host injects none → every answer is `null` and
362
+ * `supports("modules@1")` is false.
363
+ */
364
+ interface ModulesBackend {
365
+ url(pluginId: string, artifact: WasmArtifact): ModuleLocation | null | Promise<ModuleLocation | null>;
366
+ }
342
367
  /**
343
368
  * The backend the editor injects to back `host.secrets` (D-11;
344
369
  * rfc-credential-store): a REFERENCE-ONLY, host-owned credential store. The
@@ -729,6 +754,12 @@ interface CreateBundleHostOptions {
729
754
  * honestly, `concurrency()` is 0, and the feature flag is false (the
730
755
  * honest no-worker door). */
731
756
  workers?: WorkerBackend;
757
+ /** Host-provided MODULE backend (ADR 326). When present,
758
+ * `host.modules.resolve/url/fetch` answer a declared `capabilities.wasm`
759
+ * artifact with the URL the host serves it at (+ integrity) and
760
+ * `supports("modules@1")` answers true. When absent every answer is
761
+ * `null` and the bundle loads its bundle-relative copy. */
762
+ modules?: ModulesBackend;
732
763
  /** Host-provided CREDENTIAL-STORE backend (D-11; rfc-credential-store).
733
764
  * When present, `host.secrets.set/exists/forget` go through it
734
765
  * (capability-gated on `capabilities.secrets`; `set` prompts the user —
@@ -1434,6 +1465,37 @@ interface LoadBundleWasmOptions {
1434
1465
  */
1435
1466
  declare function loadBundleWasm(bundle: PagedBundle, name: string, options: LoadBundleWasmOptions): Promise<LoadedBundleWasm>;
1436
1467
 
1468
+ /** Where a wasm artifact will be loaded from. */
1469
+ interface ResolvedWasm {
1470
+ /** The URL to load. */
1471
+ url: string;
1472
+ /** Subresource Integrity to fetch it with, or `null` when unknown. */
1473
+ integrity: string | null;
1474
+ /** `"host"` when the host served the answer, `"bundle"` for the fallback. */
1475
+ source: "host" | "bundle";
1476
+ }
1477
+ type HostLike = Pick<BundleHost, "manifest" | "supports"> & {
1478
+ readonly modules?: Partial<ModulesSurface>;
1479
+ };
1480
+ /**
1481
+ * Resolve the declared wasm artifact `name`: the host's URL + integrity when
1482
+ * the host serves it (`supports("modules@1")`), else `fallbackUrl` (the
1483
+ * bundle-relative URL the bundle used before) with the manifest's own
1484
+ * integrity stamp, if it has one. Never rejects: a host path that fails —
1485
+ * no door, an undeclared name, a throwing backend — is the fallback.
1486
+ */
1487
+ declare function resolveWasm(host: HostLike, name: string, fallbackUrl: string | URL): Promise<ResolvedWasm>;
1488
+ /** `resolveWasm(...)`'s URL alone. */
1489
+ declare function resolveWasmUrl(host: HostLike, name: string, fallbackUrl: string | URL): Promise<string>;
1490
+ /**
1491
+ * Fetch the declared wasm artifact `name` from wherever `resolveWasm` says,
1492
+ * with `{ integrity }` when one is known — a byte that differs fails the
1493
+ * fetch instead of reaching `WebAssembly`. Hand the promise to
1494
+ * `WebAssembly.instantiateStreaming` or a wasm-bindgen
1495
+ * `init({ module_or_path })`.
1496
+ */
1497
+ declare function fetchWasm(host: HostLike, name: string, fallbackUrl: string | URL): Promise<Response>;
1498
+
1437
1499
  declare const CLICK_DRAG_THRESHOLD_PX = 4;
1438
1500
  /** A drag anchored to the page under the pointer at pointer-down. */
1439
1501
  interface PageDrag {
@@ -1597,4 +1659,4 @@ declare function contributeObjectType(host: BundleHost, contribution: ObjectType
1597
1659
  */
1598
1660
  declare function contributeBindingProvider(host: BundleHost, contextType: string, provider: BindingProvider): BindingProviderHandle;
1599
1661
 
1600
- export { API_VERSION, ASSET_BUDGETS, BLOB_BUDGETS, type BindingProviderBackend, type BlobStore, type BundleAssetProvider, type BundleAssetSource, type BundleHostHandle, type BundleTrust, CANVAS_WASM_PKG, CLICK_DRAG_THRESHOLD_PX, CORE_CATALOG_ROWS, CORE_COMMAND_CREATES, CORE_COMMAND_EXCLUSIONS, CORE_COMMAND_OPS, CORE_COMMAND_PREFIX, CORE_PATHS, CORE_PATH_ALIASES, CORE_WIRE_OPS, type ClipboardBackend, type ConsentBackend, type CoreCatalogRow, type CoreCreatePlan, type CoreObjects, type CorePathRow, type CorePathScope, type CorePlan, type CoreRow71, type CoreWireOpRow, type CreateBundleHostOptions, type CreateCoreObjectsOptions, type CreateObjectRegistryOptions, type DataProviderBackend, type DiagnosticsSink, DisposableStore, type DocumentsBackend, FALLBACK_WIDGETS, FRAME_KIND_WORDS, HOST_FEATURES, type HarnessOptions, type HeadlessCanvasWorker, type HeadlessHost, type HeadlessHostHandle, type HostObjectAnswer, type HostObjectCall, type JournalSink, type LoadBundleWasmOptions, type LoadHeadlessEngineOptions, type LoadedBundle, type LoadedBundleWasm, type LoadedEngine, type NativeDocumentBackend, OBJECT_MODEL_PROTOCOL, type ObjectListRow, type ObjectModelRegistration, type ObjectRegistry, type PageDrag, type PagesBackend, type PanelSchemaIssue, type ParsedSelector, PluginApiNotImplemented, PluginCapabilityError, type PropertyRowOptions, type PublishObjectListOptions, ROW_PATH, type RecordableAssetSource, type RecordedContribution, type RecordedFontFaceRequest, type RegisteredBindingProvider, type ScriptRunResult, type ScriptSend, type SecretStoreBackend, type SeededFace, type SelectorHead, type SelectorPredicate, type SelectorStep, type ShellBackend, type SpawnedWorker, type StorageBacking, type TextCaretBackend, type TextRevealBackend, type ToolSettingsBackend, VALUE_TYPE_KINDS, type ValidatePanelSchemaOptions, WASM_BUDGETS, WORKER_BUDGETS, type WillSaveBackend, type WorkerBackend, addressKindOf, answerHostObjects, answerHostObjectsRound, applyDefaults, applyValueEdit, assetFromBytes, beginPageDrag, checkSchemaRows, checkValueType, codeOfEngineError, coerceValue, commitAndSelect, contributeBindingProvider, contributeEditContext, contributeObjectType, contributePanel, contributeSchemaPanel, contributeTool, coreCommandInfos, coreSchema71, createBindingProviderRegistry, createBundleHost, createCoreObjects, createDataProviderRegistry, createHeadlessHost, createObjectRegistry, createRecordableAssetSource, defaultValueOf, defineBundle, editValue, endLocalFor, escapeLabelValue, findRow, formatAddress, fromElementId, inMemoryToolSettings, inMemoryWillSave, isCoreCommand, isPropertyRow, loadBundle, loadBundleWasm, loadHeadlessEngine, makeSchemaPanelComponent, normalizeAddress, normalizeCoreType, parseAddress, parseLength, parseSelector, planValueEdit, propertyRow, propertyRows, propertyRowsOf, protocolFromVersion, publishObjectList, pxToPt, readVendoredWireVersion, resolveCanvasWasm, resolveGate, rowPathOf, runScriptWithObjects, satisfiesApiVersion, selectorKind, toDisposable, toElementId, validatePanelSchema, validateValue };
1662
+ export { API_VERSION, ASSET_BUDGETS, BLOB_BUDGETS, type BindingProviderBackend, type BlobStore, type BundleAssetProvider, type BundleAssetSource, type BundleHostHandle, type BundleTrust, CANVAS_WASM_PKG, CLICK_DRAG_THRESHOLD_PX, CORE_CATALOG_ROWS, CORE_COMMAND_CREATES, CORE_COMMAND_EXCLUSIONS, CORE_COMMAND_OPS, CORE_COMMAND_PREFIX, CORE_PATHS, CORE_PATH_ALIASES, CORE_WIRE_OPS, type ClipboardBackend, type ConsentBackend, type CoreCatalogRow, type CoreCreatePlan, type CoreObjects, type CorePathRow, type CorePathScope, type CorePlan, type CoreRow71, type CoreWireOpRow, type CreateBundleHostOptions, type CreateCoreObjectsOptions, type CreateObjectRegistryOptions, type DataProviderBackend, type DiagnosticsSink, DisposableStore, type DocumentsBackend, FALLBACK_WIDGETS, FRAME_KIND_WORDS, HOST_FEATURES, type HarnessOptions, type HeadlessCanvasWorker, type HeadlessHost, type HeadlessHostHandle, type HostObjectAnswer, type HostObjectCall, type JournalSink, type LoadBundleWasmOptions, type LoadHeadlessEngineOptions, type LoadedBundle, type LoadedBundleWasm, type LoadedEngine, type ModuleLocation, type ModulesBackend, type NativeDocumentBackend, OBJECT_MODEL_PROTOCOL, type ObjectListRow, type ObjectModelRegistration, type ObjectRegistry, type PageDrag, type PagesBackend, type PanelSchemaIssue, type ParsedSelector, PluginApiNotImplemented, PluginCapabilityError, type PropertyRowOptions, type PublishObjectListOptions, ROW_PATH, type RecordableAssetSource, type RecordedContribution, type RecordedFontFaceRequest, type RegisteredBindingProvider, type ResolvedWasm, type ScriptRunResult, type ScriptSend, type SecretStoreBackend, type SeededFace, type SelectorHead, type SelectorPredicate, type SelectorStep, type ShellBackend, type SpawnedWorker, type StorageBacking, type TextCaretBackend, type TextRevealBackend, type ToolSettingsBackend, VALUE_TYPE_KINDS, type ValidatePanelSchemaOptions, WASM_BUDGETS, WORKER_BUDGETS, type WillSaveBackend, type WorkerBackend, addressKindOf, answerHostObjects, answerHostObjectsRound, applyDefaults, applyValueEdit, assetFromBytes, beginPageDrag, checkSchemaRows, checkValueType, codeOfEngineError, coerceValue, commitAndSelect, contributeBindingProvider, contributeEditContext, contributeObjectType, contributePanel, contributeSchemaPanel, contributeTool, coreCommandInfos, coreSchema71, createBindingProviderRegistry, createBundleHost, createCoreObjects, createDataProviderRegistry, createHeadlessHost, createObjectRegistry, createRecordableAssetSource, defaultValueOf, defineBundle, editValue, endLocalFor, escapeLabelValue, fetchWasm, findRow, formatAddress, fromElementId, inMemoryToolSettings, inMemoryWillSave, isCoreCommand, isPropertyRow, loadBundle, loadBundleWasm, loadHeadlessEngine, makeSchemaPanelComponent, normalizeAddress, normalizeCoreType, parseAddress, parseLength, parseSelector, planValueEdit, propertyRow, propertyRows, propertyRowsOf, protocolFromVersion, publishObjectList, pxToPt, readVendoredWireVersion, resolveCanvasWasm, resolveGate, resolveWasm, resolveWasmUrl, rowPathOf, runScriptWithObjects, satisfiesApiVersion, selectorKind, toDisposable, toElementId, validatePanelSchema, validateValue };
package/dist/index.js CHANGED
@@ -12683,6 +12683,52 @@ function createBundleHost(getEditor, manifest, options) {
12683
12683
  },
12684
12684
  concurrency: () => workerCap
12685
12685
  };
12686
+ const modulesBackend = options?.modules;
12687
+ const declaredWasm = (name) => caps?.wasm?.find((a) => a.name === name);
12688
+ const sriAlgorithm = (sri) => sri.split("-", 1)[0] ?? "";
12689
+ const modules = {
12690
+ async resolve(name) {
12691
+ const artifact = declaredWasm(name);
12692
+ requireDeclared(
12693
+ artifact !== void 0,
12694
+ `modules.resolve("${name}")`,
12695
+ `capabilities.wasm must declare an artifact named "${name}"`
12696
+ );
12697
+ if (!artifact || !modulesBackend) return null;
12698
+ let answer;
12699
+ try {
12700
+ answer = await modulesBackend.url(manifest.id, { ...artifact });
12701
+ } catch (err) {
12702
+ log.warn(`modules.resolve("${name}"): the host backend threw`, err);
12703
+ return null;
12704
+ }
12705
+ if (!answer || typeof answer.url !== "string") return null;
12706
+ let url;
12707
+ try {
12708
+ url = new URL(answer.url).href;
12709
+ } catch {
12710
+ log.warn(`modules.resolve("${name}"): the host answered a non-absolute URL "${answer.url}"`);
12711
+ return null;
12712
+ }
12713
+ const declaredSri = artifact.integrity ?? null;
12714
+ const hostSri = answer.integrity ?? null;
12715
+ if (declaredSri && hostSri && sriAlgorithm(declaredSri) === sriAlgorithm(hostSri) && declaredSri !== hostSri) {
12716
+ log.warn(
12717
+ `modules.resolve("${name}"): the host serves bytes whose integrity (${hostSri}) differs from the manifest's (${declaredSri}) \u2014 refused; load the bundle's own copy`
12718
+ );
12719
+ return null;
12720
+ }
12721
+ return { url, integrity: declaredSri ?? hostSri, artifact };
12722
+ },
12723
+ async url(name) {
12724
+ return (await modules.resolve(name))?.url ?? null;
12725
+ },
12726
+ async fetch(name) {
12727
+ const hosted = await modules.resolve(name);
12728
+ if (!hosted) return null;
12729
+ return hosted.integrity ? globalThis.fetch(hosted.url, { integrity: hosted.integrity }) : globalThis.fetch(hosted.url);
12730
+ }
12731
+ };
12686
12732
  const secretStore = options?.secrets;
12687
12733
  const secrets = {
12688
12734
  async set(ref, secret) {
@@ -12830,6 +12876,9 @@ function createBundleHost(getEditor, manifest, options) {
12830
12876
  if (options?.workers) {
12831
12877
  featureSet.add("workers@1");
12832
12878
  }
12879
+ if (options?.modules) {
12880
+ featureSet.add("modules@1");
12881
+ }
12833
12882
  if (options?.secrets) {
12834
12883
  featureSet.add("secrets@1");
12835
12884
  }
@@ -12899,6 +12948,7 @@ function createBundleHost(getEditor, manifest, options) {
12899
12948
  assets,
12900
12949
  images,
12901
12950
  workers,
12951
+ modules,
12902
12952
  secrets,
12903
12953
  clipboard,
12904
12954
  tools,
@@ -14009,6 +14059,35 @@ async function loadBundleWasm(bundle, name, options) {
14009
14059
  return { artifact, module, instance, memory, byteLength: view.byteLength };
14010
14060
  }
14011
14061
 
14062
+ // src/modules.ts
14063
+ function declaredIntegrity(host, name) {
14064
+ const a = host.manifest.capabilities?.wasm?.find((w) => w.name === name);
14065
+ return a?.integrity ?? null;
14066
+ }
14067
+ async function resolveWasm(host, name, fallbackUrl) {
14068
+ const fallback = {
14069
+ url: String(fallbackUrl),
14070
+ integrity: declaredIntegrity(host, name),
14071
+ source: "bundle"
14072
+ };
14073
+ if (!host.supports("modules@1") || typeof host.modules?.resolve !== "function") {
14074
+ return fallback;
14075
+ }
14076
+ try {
14077
+ const hosted = await host.modules.resolve(name);
14078
+ if (hosted) return { url: hosted.url, integrity: hosted.integrity, source: "host" };
14079
+ } catch {
14080
+ }
14081
+ return fallback;
14082
+ }
14083
+ async function resolveWasmUrl(host, name, fallbackUrl) {
14084
+ return (await resolveWasm(host, name, fallbackUrl)).url;
14085
+ }
14086
+ async function fetchWasm(host, name, fallbackUrl) {
14087
+ const r = await resolveWasm(host, name, fallbackUrl);
14088
+ return r.integrity ? fetch(r.url, { integrity: r.integrity }) : fetch(r.url);
14089
+ }
14090
+
14012
14091
  // src/gestures.ts
14013
14092
  var CLICK_DRAG_THRESHOLD_PX = 4;
14014
14093
  function beginPageDrag(e) {
@@ -14516,6 +14595,7 @@ export {
14516
14595
  editValue,
14517
14596
  endLocalFor,
14518
14597
  escapeLabelValue,
14598
+ fetchWasm,
14519
14599
  findRow,
14520
14600
  formatAddress,
14521
14601
  fromElementId,
@@ -14542,6 +14622,8 @@ export {
14542
14622
  readVendoredWireVersion,
14543
14623
  resolveCanvasWasm,
14544
14624
  resolveGate,
14625
+ resolveWasm,
14626
+ resolveWasmUrl,
14545
14627
  rowPathOf,
14546
14628
  runScriptWithObjects,
14547
14629
  satisfiesApiVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paged-media/plugin-sdk",
3
- "version": "0.2.50-canary.0",
3
+ "version": "0.2.51-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.49-canary.0"
14
+ "@paged-media/plugin-api": "0.2.50-canary.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "react": "^18.3.0"