@powerhousedao/powerhouse-vetra-packages 6.2.0-dev.4 → 6.2.0-dev.40

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 (72) hide show
  1. package/dist/browser/assets/{entry-Bzani6_n.js → entry-BHcFjTEd.js} +2 -2
  2. package/dist/browser/assets/{projection-entry-Bpu-8SnI.js → projection-entry-Cs-5j8OX.js} +4 -4
  3. package/dist/browser/{connect-DPNyOTBV.js → connect-CmgZSI0Z.js} +45 -45
  4. package/dist/browser/connect-CmgZSI0Z.js.map +1 -0
  5. package/dist/browser/{dist-Bha1Om6O.js → dist-D1NFJMzm.js} +100 -49
  6. package/dist/browser/dist-D1NFJMzm.js.map +1 -0
  7. package/dist/browser/{document-drive-CDaY4aIj.js → document-drive-sTKoi6L4.js} +310 -3
  8. package/dist/browser/document-drive-sTKoi6L4.js.map +1 -0
  9. package/dist/browser/document-models/index.js +1 -1
  10. package/dist/browser/{editor-CJFM1rC9.js → editor-Bs5C6sAt.js} +21 -21
  11. package/dist/browser/editor-Bs5C6sAt.js.map +1 -0
  12. package/dist/browser/{editor-BtOSWTjb.js → editor-BsVLT-lJ.js} +5 -5
  13. package/dist/browser/{editor-BtOSWTjb.js.map → editor-BsVLT-lJ.js.map} +1 -1
  14. package/dist/browser/editors/document-model-editor/module.js +1 -1
  15. package/dist/browser/editors/generic-drive-explorer/index.js +5 -5
  16. package/dist/browser/editors/generic-drive-explorer/index.js.map +1 -1
  17. package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
  18. package/dist/browser/{folder-view-DAhpWssS.js → folder-view-LYhTe15T.js} +7 -7
  19. package/dist/browser/folder-view-LYhTe15T.js.map +1 -0
  20. package/dist/browser/{graphql-editor-Dwgpm08w.js → graphql-editor-b61MnkEP.js} +3 -3
  21. package/dist/browser/{graphql-editor-Dwgpm08w.js.map → graphql-editor-b61MnkEP.js.map} +1 -1
  22. package/dist/browser/index.js +334 -2
  23. package/dist/browser/index.js.map +1 -1
  24. package/dist/browser/{json-editor-SKLjwlux.js → json-editor-DO_EwDmY.js} +3 -3
  25. package/dist/browser/{json-editor-SKLjwlux.js.map → json-editor-DO_EwDmY.js.map} +1 -1
  26. package/dist/browser/lib-DtwK2kyR.js +200 -0
  27. package/dist/browser/lib-DtwK2kyR.js.map +1 -0
  28. package/dist/browser/{state-schemas-S69fnpVk.js → state-schemas-Cx-QbW5a.js} +12 -12
  29. package/dist/browser/state-schemas-Cx-QbW5a.js.map +1 -0
  30. package/dist/node/{connect-5a3Nx0Jd.mjs → connect-CwDdrOag.mjs} +45 -45
  31. package/dist/node/connect-CwDdrOag.mjs.map +1 -0
  32. package/dist/node/{dist-QOGgRb-y.mjs → dist-RdOXBdt-.mjs} +100 -49
  33. package/dist/node/dist-RdOXBdt-.mjs.map +1 -0
  34. package/dist/node/{document-drive-BK2-EDni.mjs → document-drive-DjL9iikf.mjs} +310 -3
  35. package/dist/node/document-drive-DjL9iikf.mjs.map +1 -0
  36. package/dist/node/document-models/index.mjs +1 -1
  37. package/dist/node/{editor-BNOTRmUU.mjs → editor-CTJUSbjg.mjs} +21 -21
  38. package/dist/node/editor-CTJUSbjg.mjs.map +1 -0
  39. package/dist/node/{editor-C_Gchmop.mjs → editor-DLr8Eb3u.mjs} +5 -5
  40. package/dist/node/{editor-C_Gchmop.mjs.map → editor-DLr8Eb3u.mjs.map} +1 -1
  41. package/dist/node/editors/document-model-editor/module.mjs +1 -1
  42. package/dist/node/editors/generic-drive-explorer/index.mjs +5 -5
  43. package/dist/node/editors/generic-drive-explorer/index.mjs.map +1 -1
  44. package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
  45. package/dist/node/{folder-view-af4hVjjx.mjs → folder-view-CfvJLoKi.mjs} +7 -7
  46. package/dist/node/folder-view-CfvJLoKi.mjs.map +1 -0
  47. package/dist/node/{graphql-editor-BoTCyC9n.mjs → graphql-editor-C-0f2bX3.mjs} +3 -3
  48. package/dist/node/{graphql-editor-BoTCyC9n.mjs.map → graphql-editor-C-0f2bX3.mjs.map} +1 -1
  49. package/dist/node/index.mjs +335 -2
  50. package/dist/node/index.mjs.map +1 -1
  51. package/dist/node/{json-editor-Bk4_b03g.mjs → json-editor-DJtigEsH.mjs} +3 -3
  52. package/dist/node/{json-editor-Bk4_b03g.mjs.map → json-editor-DJtigEsH.mjs.map} +1 -1
  53. package/dist/node/{dist-C7ZmTHz4.mjs → main-DbTMJyA_.mjs} +45 -340
  54. package/dist/node/main-DbTMJyA_.mjs.map +1 -0
  55. package/dist/node/{state-schemas-DMw1UvT8.mjs → state-schemas-Bv5h5MqY.mjs} +12 -12
  56. package/dist/node/state-schemas-Bv5h5MqY.mjs.map +1 -0
  57. package/package.json +6 -6
  58. package/dist/browser/connect-DPNyOTBV.js.map +0 -1
  59. package/dist/browser/dist-Bha1Om6O.js.map +0 -1
  60. package/dist/browser/dist-DnQpckQ8.js +0 -494
  61. package/dist/browser/dist-DnQpckQ8.js.map +0 -1
  62. package/dist/browser/document-drive-CDaY4aIj.js.map +0 -1
  63. package/dist/browser/editor-CJFM1rC9.js.map +0 -1
  64. package/dist/browser/folder-view-DAhpWssS.js.map +0 -1
  65. package/dist/browser/state-schemas-S69fnpVk.js.map +0 -1
  66. package/dist/node/connect-5a3Nx0Jd.mjs.map +0 -1
  67. package/dist/node/dist-C7ZmTHz4.mjs.map +0 -1
  68. package/dist/node/dist-QOGgRb-y.mjs.map +0 -1
  69. package/dist/node/document-drive-BK2-EDni.mjs.map +0 -1
  70. package/dist/node/editor-BNOTRmUU.mjs.map +0 -1
  71. package/dist/node/folder-view-af4hVjjx.mjs.map +0 -1
  72. package/dist/node/state-schemas-DMw1UvT8.mjs.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { E as __commonJSMin, k as __toESM, t as capitalCase } from "./dist-CXoKspdx.js";
2
- import { A as replayDocument, J as validateStateSchemaName, K as validateInitialState, S as createZip, Y as generateId, _ as baseSaveToFileHandle, a as handleTargetNameCollisions, c as moveNode, d as logger, g as baseLoadFromInput, i as generateNodesCopy, l as updateNode, n as copyNode, o as isFileNode, q as validateModules, r as driveDocumentModelModule, s as isFolderNode, t as addFolder$1, u as documentModelDocumentModelModule, v as buildSignedAction, y as createPresignedHeader, z as setName } from "./document-drive-CDaY4aIj.js";
3
- import { c as driveCollectionId, n as gql, o as SyncStatus, s as ModuleNotFoundError, t as reactorDriveDocumentModelModule } from "./dist-DnQpckQ8.js";
4
- import { Children, cloneElement, forwardRef, isValidElement, use, useEffect, useMemo, useState, useSyncExternalStore } from "react";
2
+ import { B as setName, C as createZip, J as validateModules, X as generateId, Y as validateStateSchemaName, _ as baseLoadFromInputVersioned, a as handleTargetNameCollisions, b as createPresignedHeader, c as moveNode, d as logger, g as baseLoadFromInput, i as generateNodesCopy, j as replayDocumentVersioned, l as updateNode, n as copyNode, o as isFileNode, q as validateInitialState, s as isFolderNode, t as addFolder$1, v as baseSaveToFileHandle, y as buildSignedAction } from "./document-drive-sTKoi6L4.js";
3
+ import { a as SyncStatus, o as DriveCollectionId, s as ModuleNotFoundError, t as gql } from "./lib-DtwK2kyR.js";
4
+ import { Children, cloneElement, forwardRef, isValidElement, use, useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
5
5
  import "react/jsx-runtime";
6
- //#region ../reactor-browser/dist/make-ph-event-functions-DwiD1zH9.js
6
+ //#region ../reactor-browser/dist/make-ph-event-functions-BHoLPif5.js
7
7
  const isServer$1 = typeof window === "undefined";
8
8
  function makePHEventFunctions(key) {
9
9
  const setEventName = `ph:set${capitalCase(key)}`;
@@ -51,7 +51,7 @@ function makePHEventFunctions(key) {
51
51
  };
52
52
  }
53
53
  //#endregion
54
- //#region ../reactor-browser/dist/document-by-id-BrIy0iHX.js
54
+ //#region ../reactor-browser/dist/document-by-id-dLYFX-xz.js
55
55
  async function queueActions(document, actionOrActions) {
56
56
  if (!document) throw new Error("No document provided");
57
57
  if (!actionOrActions) throw new Error("No actions provided");
@@ -196,6 +196,18 @@ function useDocument(id) {
196
196
  const document = useSyncExternalStore((cb) => id && documentCache ? documentCache.subscribe(id, cb) : () => {}, () => id ? documentCache?.get(id) : void 0);
197
197
  return document ? use(document) : void 0;
198
198
  }
199
+ /**
200
+ * Returns a function to retrieve a document from the cache.
201
+ * The returned function fetches and returns a document by ID.
202
+ * @returns A function that takes a document ID and returns a Promise of the document
203
+ */
204
+ function useGetDocument() {
205
+ const documentCache = useDocumentCache();
206
+ return useCallback((id) => {
207
+ if (!documentCache) return Promise.reject(/* @__PURE__ */ new Error("Document cache not initialized"));
208
+ return documentCache.get(id);
209
+ }, [documentCache]);
210
+ }
199
211
  function useDispatch(document) {
200
212
  /**
201
213
  * Dispatches actions to the document.
@@ -214,7 +226,7 @@ function useDocumentById(id) {
214
226
  return [document, dispatch];
215
227
  }
216
228
  //#endregion
217
- //#region ../reactor-browser/dist/client-CvgFU1Dv.js
229
+ //#region ../reactor-browser/dist/client-_Gh2Uf0E.js
218
230
  const PhDocumentFieldsFragmentDoc = gql`
219
231
  fragment PHDocumentFields on PHDocument {
220
232
  id
@@ -725,7 +737,7 @@ function extractQueryParts(doc, fallbackBody) {
725
737
  extractSelectionSet(GetDocumentOperationsDocument, "documentOperations", "{ items { index } }");
726
738
  extractQueryParts(GetDocumentDocument, "document(identifier: $identifier) { document { id name documentType state revisionsList { scope revision } createdAtUtcIso lastModifiedAtUtcIso } childIds }");
727
739
  //#endregion
728
- //#region ../reactor-browser/dist/renown-Dzmo1gJD.js
740
+ //#region ../reactor-browser/dist/renown-D-1c_Bvx.js
729
741
  const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
730
742
  const renownEventFunctions = makePHEventFunctions("renown");
731
743
  renownEventFunctions.addEventHandler;
@@ -2488,14 +2500,30 @@ async function exportFile(document, suggestedName) {
2488
2500
  if (!(e instanceof DOMException && e.name === "AbortError")) throw e;
2489
2501
  }
2490
2502
  }
2503
+ /**
2504
+ * Loads a document file and replays it with version-aware reducers from the registry.
2505
+ * Falls back to single-version legacy replay when no upgrade manifest is registered for
2506
+ * the document type.
2507
+ */
2491
2508
  async function loadFile(path) {
2492
2509
  const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
2493
2510
  const reactorClient = window.ph?.reactorClient;
2494
2511
  if (!reactorClient) throw new Error("ReactorClient not initialized");
2512
+ const documentType = baseDocument.header.documentType;
2495
2513
  const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
2496
- const documentModelModule = documentModelModules.find((module) => module.documentModel.global.id === baseDocument.header.documentType);
2497
- if (!documentModelModule) throw new DocumentModelNotFoundError(baseDocument.header.documentType);
2498
- return documentModelModule.utils.loadFromInput(path);
2514
+ const modulesForType = documentModelModules.filter((module) => module.documentModel.global.id === documentType);
2515
+ if (modulesForType.length === 0) throw new DocumentModelNotFoundError(documentType);
2516
+ const reducers = {};
2517
+ for (const module of modulesForType) reducers[module.version ?? 1] = module.reducer;
2518
+ const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
2519
+ let upgradeManifest;
2520
+ if (registry) try {
2521
+ upgradeManifest = registry.getUpgradeManifest(documentType);
2522
+ } catch {}
2523
+ return baseLoadFromInputVersioned(path, {
2524
+ reducers,
2525
+ upgradeManifest
2526
+ });
2499
2527
  }
2500
2528
  async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor) {
2501
2529
  const { isAllowedToCreateDocuments } = getUserPermissions();
@@ -2617,9 +2645,28 @@ async function moveNode$1(driveId, src, target) {
2617
2645
  targetParentFolder: target?.id
2618
2646
  })]);
2619
2647
  }
2648
+ /**
2649
+ * Duplicates a document under a new id using version-aware replay.
2650
+ * Falls back gracefully when no upgrade manifest is registered for the document type.
2651
+ */
2620
2652
  async function _duplicateDocument(reactor, document, newId = generateId()) {
2621
- const documentModule = await reactor.getDocumentModelModule(document.header.documentType);
2622
- return replayDocument(document.initialState, document.operations, documentModule.reducer, createPresignedHeader(newId, document.header.documentType));
2653
+ const documentType = document.header.documentType;
2654
+ const { results: allModules } = await reactor.getDocumentModelModules();
2655
+ const modulesForType = allModules.filter((m) => m.documentModel.global.id === documentType);
2656
+ const reducers = {};
2657
+ for (const m of modulesForType) reducers[m.version ?? 1] = m.reducer;
2658
+ if (Object.keys(reducers).length === 0) throw new Error(`Document model module not found for type: ${documentType}`);
2659
+ const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
2660
+ let upgradeManifest;
2661
+ if (registry) try {
2662
+ upgradeManifest = registry.getUpgradeManifest(documentType);
2663
+ } catch {}
2664
+ const config = {
2665
+ reducers,
2666
+ upgradeManifest
2667
+ };
2668
+ const header = createPresignedHeader(newId, documentType);
2669
+ return replayDocumentVersioned(document.initialState, document.operations, config, header);
2623
2670
  }
2624
2671
  async function copyNode$1(driveId, src, target) {
2625
2672
  const reactor = window.ph?.reactorClient;
@@ -2659,12 +2706,31 @@ async function copyNode$1(driveId, src, target) {
2659
2706
  }
2660
2707
  return await queueActions(drive, copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput)));
2661
2708
  }
2662
- const baseDocumentModelsMap = {
2663
- DocumentModel: documentModelDocumentModelModule,
2664
- DocumentDrive: driveDocumentModelModule,
2665
- ReactorDrive: reactorDriveDocumentModelModule
2666
- };
2667
- Object.values(baseDocumentModelsMap);
2709
+ const modalEventFunctions = makePHEventFunctions("modal");
2710
+ modalEventFunctions.useValue;
2711
+ /** Sets the current modal */
2712
+ const setPHModal = modalEventFunctions.setValue;
2713
+ modalEventFunctions.addEventHandler;
2714
+ /** Shows a modal */
2715
+ function showPHModal(modal) {
2716
+ setPHModal(modal);
2717
+ }
2718
+ /** Shows the create document modal */
2719
+ function showCreateDocumentModal(documentType) {
2720
+ setPHModal({
2721
+ type: "createDocument",
2722
+ documentType
2723
+ });
2724
+ }
2725
+ /** Shows the delete node modal */
2726
+ function showDeleteNodeModal(nodeOrId) {
2727
+ setPHModal({
2728
+ type: "deleteItem",
2729
+ id: typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id
2730
+ });
2731
+ }
2732
+ /** Document types that represent a "drive": a container of nodes. */
2733
+ const DRIVE_DOCUMENT_TYPES = ["powerhouse/document-drive", "powerhouse/reactor-drive"];
2668
2734
  const isExternalControlsEnabledEventFunctions = makePHEventFunctions("isExternalControlsEnabled");
2669
2735
  /** Sets whether external controls are enabled for a given editor. */
2670
2736
  const setIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.setValue;
@@ -3183,36 +3249,13 @@ const graphQLReactorClientEventFunctions = makePHEventFunctions("reactorGraphQLC
3183
3249
  graphQLReactorClientEventFunctions.useValue;
3184
3250
  graphQLReactorClientEventFunctions.setValue;
3185
3251
  graphQLReactorClientEventFunctions.addEventHandler;
3186
- const modalEventFunctions = makePHEventFunctions("modal");
3187
- modalEventFunctions.useValue;
3188
- /** Sets the current modal */
3189
- const setPHModal = modalEventFunctions.setValue;
3190
- modalEventFunctions.addEventHandler;
3191
- /** Shows a modal */
3192
- function showPHModal(modal) {
3193
- setPHModal(modal);
3194
- }
3195
- /** Shows the create document modal */
3196
- function showCreateDocumentModal(documentType) {
3197
- setPHModal({
3198
- type: "createDocument",
3199
- documentType
3200
- });
3201
- }
3202
- /** Shows the delete node modal */
3203
- function showDeleteNodeModal(nodeOrId) {
3204
- setPHModal({
3205
- type: "deleteItem",
3206
- id: typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id
3207
- });
3208
- }
3209
3252
  const packageDiscoveryFunctions = makePHEventFunctions("packageDiscoveryService");
3210
3253
  packageDiscoveryFunctions.useValue;
3211
3254
  packageDiscoveryFunctions.setValue;
3212
3255
  packageDiscoveryFunctions.addEventHandler;
3213
3256
  const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
3214
3257
  const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
3215
- /** Returns the reactor client module */
3258
+ /** Returns the reactor client module (in-process or worker-backed) */
3216
3259
  const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
3217
3260
  reactorClientModuleEventFunctions.setValue;
3218
3261
  reactorClientModuleEventFunctions.addEventHandler;
@@ -3410,9 +3453,17 @@ function downloadDocument(document, handleError = defaultHandleError) {
3410
3453
  exportFile(document).catch((error) => handleError(normalizeException(error)));
3411
3454
  }
3412
3455
  function useDownloadDocument(id) {
3413
- const [document] = useDocumentById(id);
3456
+ const getDocument = useGetDocument();
3414
3457
  const toast = usePHToast();
3415
- return () => downloadDocument(document, (error) => toast?.(`Failed to export document: ${error.message}`));
3458
+ return async () => {
3459
+ if (!id) return;
3460
+ const handleError = (error) => toast?.(`Failed to export document: ${error.message}`);
3461
+ try {
3462
+ downloadDocument(await getDocument(id), handleError);
3463
+ } catch (error) {
3464
+ handleError(error);
3465
+ }
3466
+ };
3416
3467
  }
3417
3468
  function useFolderById(id) {
3418
3469
  return useFolderNodesInSelectedDrive()?.find((n) => n.id === id);
@@ -3603,7 +3654,7 @@ const syncStatusToUI = {
3603
3654
  [SyncStatus.Error]: "ERROR"
3604
3655
  };
3605
3656
  async function getDrives(reactor) {
3606
- return (await reactor.find({ type: "powerhouse/document-drive" })).results;
3657
+ return (await Promise.all(DRIVE_DOCUMENT_TYPES.map((type) => reactor.find({ type })))).flatMap((r) => r.results);
3607
3658
  }
3608
3659
  function getSyncStatusSync(documentId, sharingType) {
3609
3660
  if (sharingType === "LOCAL") return;
@@ -3648,12 +3699,12 @@ function useGetSwitchboardLink(document) {
3648
3699
  const remotes = useSyncList();
3649
3700
  const isRemoteDrive = useMemo(() => {
3650
3701
  if (!e$4(drive)) return false;
3651
- return remotes.some((remote) => remote.collectionId === driveCollectionId("main", drive.header.id));
3702
+ return remotes.some((remote) => remote.meta.collectionId.equals(DriveCollectionId.forDrive(drive.header.id)));
3652
3703
  }, [remotes, drive]);
3653
3704
  const remoteUrl = useMemo(() => {
3654
3705
  if (!e$4(drive)) return null;
3655
3706
  try {
3656
- const channelUrl = (remotes.find((remote) => remote.collectionId === driveCollectionId("main", drive.header.id))?.channel)?.config.url;
3707
+ const channelUrl = (remotes.find((remote) => remote.meta.collectionId.equals(DriveCollectionId.forDrive(drive.header.id)))?.channel)?.config.url;
3657
3708
  if (typeof channelUrl === "string") return channelUrl;
3658
3709
  return null;
3659
3710
  } catch (error) {
@@ -3699,7 +3750,7 @@ async function _refreshReactorData(reactor) {
3699
3750
  }
3700
3751
  async function _refreshReactorDataClient(reactor) {
3701
3752
  if (!reactor) return;
3702
- setDrives((await reactor.find({ type: "powerhouse/document-drive" })).results);
3753
+ setDrives(await getDrives(reactor));
3703
3754
  }
3704
3755
  function createDebouncedRefreshReactorData(debounceDelayMs = DEFAULT_DEBOUNCE_DELAY_MS, immediateThresholdMs = DEFAULT_IMMEDIATE_THRESHOLD_MS) {
3705
3756
  let timeout = null;
@@ -3744,4 +3795,4 @@ createDebouncedRefreshReactorDataClient();
3744
3795
  //#endregion
3745
3796
  export { e$4 as A, useSelectedDriveSafe as C, useTheme as D, useSetPHDocumentEditorConfig as E, t$5 as M, useDocumentById as N, useUserPermissions as O, useSelectedDriveId as S, useSetPHAppConfig as T, useNodeParentFolderById as _, setSelectedDrive as a, useSelectedDocumentOfType as b, showDeleteNodeModal as c, useDownloadDocument as d, useDragNode as f, useNodeById as g, useNodeActions as h, isFolderNodeKind as i, t$2 as j, e$1 as k, showRevisionHistory as l, useGetSwitchboardLink as m, getSyncStatusSync as n, setSelectedNode as o, useDropNode as p, isFileNodeKind as r, showCreateDocumentModal as s, addFolder as t, useDocumentModelModules as u, useNodesInSelectedDriveOrFolder as v, useSelectedNodePath as w, useSelectedDocumentSafe as x, usePHToast as y };
3746
3797
 
3747
- //# sourceMappingURL=dist-Bha1Om6O.js.map
3798
+ //# sourceMappingURL=dist-D1NFJMzm.js.map