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

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, j as __toESM, t as capitalCase } from "./dist-fA4EItr0.mjs";
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-BK2-EDni.mjs";
3
- import { a as SyncStatus, n as require_main, o as ModuleNotFoundError, s as driveCollectionId, t as reactorDriveDocumentModelModule } from "./dist-C7ZmTHz4.mjs";
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-DjL9iikf.mjs";
3
+ import { a as DriveCollectionId, i as SyncStatus, o as ModuleNotFoundError, t as require_main } from "./main-DbTMJyA_.mjs";
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
  var import_main = require_main();
219
231
  const PhDocumentFieldsFragmentDoc = import_main.gql`
220
232
  fragment PHDocumentFields on PHDocument {
@@ -726,7 +738,7 @@ function extractQueryParts(doc, fallbackBody) {
726
738
  extractSelectionSet(GetDocumentOperationsDocument, "documentOperations", "{ items { index } }");
727
739
  extractQueryParts(GetDocumentDocument, "document(identifier: $identifier) { document { id name documentType state revisionsList { scope revision } createdAtUtcIso lastModifiedAtUtcIso } childIds }");
728
740
  //#endregion
729
- //#region ../reactor-browser/dist/renown-Dzmo1gJD.js
741
+ //#region ../reactor-browser/dist/renown-D-1c_Bvx.js
730
742
  const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
731
743
  const renownEventFunctions = makePHEventFunctions("renown");
732
744
  renownEventFunctions.addEventHandler;
@@ -2489,14 +2501,30 @@ async function exportFile(document, suggestedName) {
2489
2501
  if (!(e instanceof DOMException && e.name === "AbortError")) throw e;
2490
2502
  }
2491
2503
  }
2504
+ /**
2505
+ * Loads a document file and replays it with version-aware reducers from the registry.
2506
+ * Falls back to single-version legacy replay when no upgrade manifest is registered for
2507
+ * the document type.
2508
+ */
2492
2509
  async function loadFile(path) {
2493
2510
  const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
2494
2511
  const reactorClient = window.ph?.reactorClient;
2495
2512
  if (!reactorClient) throw new Error("ReactorClient not initialized");
2513
+ const documentType = baseDocument.header.documentType;
2496
2514
  const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
2497
- const documentModelModule = documentModelModules.find((module) => module.documentModel.global.id === baseDocument.header.documentType);
2498
- if (!documentModelModule) throw new DocumentModelNotFoundError(baseDocument.header.documentType);
2499
- return documentModelModule.utils.loadFromInput(path);
2515
+ const modulesForType = documentModelModules.filter((module) => module.documentModel.global.id === documentType);
2516
+ if (modulesForType.length === 0) throw new DocumentModelNotFoundError(documentType);
2517
+ const reducers = {};
2518
+ for (const module of modulesForType) reducers[module.version ?? 1] = module.reducer;
2519
+ const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
2520
+ let upgradeManifest;
2521
+ if (registry) try {
2522
+ upgradeManifest = registry.getUpgradeManifest(documentType);
2523
+ } catch {}
2524
+ return baseLoadFromInputVersioned(path, {
2525
+ reducers,
2526
+ upgradeManifest
2527
+ });
2500
2528
  }
2501
2529
  async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor) {
2502
2530
  const { isAllowedToCreateDocuments } = getUserPermissions();
@@ -2618,9 +2646,28 @@ async function moveNode$1(driveId, src, target) {
2618
2646
  targetParentFolder: target?.id
2619
2647
  })]);
2620
2648
  }
2649
+ /**
2650
+ * Duplicates a document under a new id using version-aware replay.
2651
+ * Falls back gracefully when no upgrade manifest is registered for the document type.
2652
+ */
2621
2653
  async function _duplicateDocument(reactor, document, newId = generateId()) {
2622
- const documentModule = await reactor.getDocumentModelModule(document.header.documentType);
2623
- return replayDocument(document.initialState, document.operations, documentModule.reducer, createPresignedHeader(newId, document.header.documentType));
2654
+ const documentType = document.header.documentType;
2655
+ const { results: allModules } = await reactor.getDocumentModelModules();
2656
+ const modulesForType = allModules.filter((m) => m.documentModel.global.id === documentType);
2657
+ const reducers = {};
2658
+ for (const m of modulesForType) reducers[m.version ?? 1] = m.reducer;
2659
+ if (Object.keys(reducers).length === 0) throw new Error(`Document model module not found for type: ${documentType}`);
2660
+ const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
2661
+ let upgradeManifest;
2662
+ if (registry) try {
2663
+ upgradeManifest = registry.getUpgradeManifest(documentType);
2664
+ } catch {}
2665
+ const config = {
2666
+ reducers,
2667
+ upgradeManifest
2668
+ };
2669
+ const header = createPresignedHeader(newId, documentType);
2670
+ return replayDocumentVersioned(document.initialState, document.operations, config, header);
2624
2671
  }
2625
2672
  async function copyNode$1(driveId, src, target) {
2626
2673
  const reactor = window.ph?.reactorClient;
@@ -2660,12 +2707,31 @@ async function copyNode$1(driveId, src, target) {
2660
2707
  }
2661
2708
  return await queueActions(drive, copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput)));
2662
2709
  }
2663
- const baseDocumentModelsMap = {
2664
- DocumentModel: documentModelDocumentModelModule,
2665
- DocumentDrive: driveDocumentModelModule,
2666
- ReactorDrive: reactorDriveDocumentModelModule
2667
- };
2668
- Object.values(baseDocumentModelsMap);
2710
+ const modalEventFunctions = makePHEventFunctions("modal");
2711
+ modalEventFunctions.useValue;
2712
+ /** Sets the current modal */
2713
+ const setPHModal = modalEventFunctions.setValue;
2714
+ modalEventFunctions.addEventHandler;
2715
+ /** Shows a modal */
2716
+ function showPHModal(modal) {
2717
+ setPHModal(modal);
2718
+ }
2719
+ /** Shows the create document modal */
2720
+ function showCreateDocumentModal(documentType) {
2721
+ setPHModal({
2722
+ type: "createDocument",
2723
+ documentType
2724
+ });
2725
+ }
2726
+ /** Shows the delete node modal */
2727
+ function showDeleteNodeModal(nodeOrId) {
2728
+ setPHModal({
2729
+ type: "deleteItem",
2730
+ id: typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id
2731
+ });
2732
+ }
2733
+ /** Document types that represent a "drive": a container of nodes. */
2734
+ const DRIVE_DOCUMENT_TYPES = ["powerhouse/document-drive", "powerhouse/reactor-drive"];
2669
2735
  const isExternalControlsEnabledEventFunctions = makePHEventFunctions("isExternalControlsEnabled");
2670
2736
  /** Sets whether external controls are enabled for a given editor. */
2671
2737
  const setIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.setValue;
@@ -3184,36 +3250,13 @@ const graphQLReactorClientEventFunctions = makePHEventFunctions("reactorGraphQLC
3184
3250
  graphQLReactorClientEventFunctions.useValue;
3185
3251
  graphQLReactorClientEventFunctions.setValue;
3186
3252
  graphQLReactorClientEventFunctions.addEventHandler;
3187
- const modalEventFunctions = makePHEventFunctions("modal");
3188
- modalEventFunctions.useValue;
3189
- /** Sets the current modal */
3190
- const setPHModal = modalEventFunctions.setValue;
3191
- modalEventFunctions.addEventHandler;
3192
- /** Shows a modal */
3193
- function showPHModal(modal) {
3194
- setPHModal(modal);
3195
- }
3196
- /** Shows the create document modal */
3197
- function showCreateDocumentModal(documentType) {
3198
- setPHModal({
3199
- type: "createDocument",
3200
- documentType
3201
- });
3202
- }
3203
- /** Shows the delete node modal */
3204
- function showDeleteNodeModal(nodeOrId) {
3205
- setPHModal({
3206
- type: "deleteItem",
3207
- id: typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id
3208
- });
3209
- }
3210
3253
  const packageDiscoveryFunctions = makePHEventFunctions("packageDiscoveryService");
3211
3254
  packageDiscoveryFunctions.useValue;
3212
3255
  packageDiscoveryFunctions.setValue;
3213
3256
  packageDiscoveryFunctions.addEventHandler;
3214
3257
  const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
3215
3258
  const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
3216
- /** Returns the reactor client module */
3259
+ /** Returns the reactor client module (in-process or worker-backed) */
3217
3260
  const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
3218
3261
  reactorClientModuleEventFunctions.setValue;
3219
3262
  reactorClientModuleEventFunctions.addEventHandler;
@@ -3411,9 +3454,17 @@ function downloadDocument(document, handleError = defaultHandleError) {
3411
3454
  exportFile(document).catch((error) => handleError(normalizeException(error)));
3412
3455
  }
3413
3456
  function useDownloadDocument(id) {
3414
- const [document] = useDocumentById(id);
3457
+ const getDocument = useGetDocument();
3415
3458
  const toast = usePHToast();
3416
- return () => downloadDocument(document, (error) => toast?.(`Failed to export document: ${error.message}`));
3459
+ return async () => {
3460
+ if (!id) return;
3461
+ const handleError = (error) => toast?.(`Failed to export document: ${error.message}`);
3462
+ try {
3463
+ downloadDocument(await getDocument(id), handleError);
3464
+ } catch (error) {
3465
+ handleError(error);
3466
+ }
3467
+ };
3417
3468
  }
3418
3469
  function useFolderById(id) {
3419
3470
  return useFolderNodesInSelectedDrive()?.find((n) => n.id === id);
@@ -3604,7 +3655,7 @@ const syncStatusToUI = {
3604
3655
  [SyncStatus.Error]: "ERROR"
3605
3656
  };
3606
3657
  async function getDrives(reactor) {
3607
- return (await reactor.find({ type: "powerhouse/document-drive" })).results;
3658
+ return (await Promise.all(DRIVE_DOCUMENT_TYPES.map((type) => reactor.find({ type })))).flatMap((r) => r.results);
3608
3659
  }
3609
3660
  function getSyncStatusSync(documentId, sharingType) {
3610
3661
  if (sharingType === "LOCAL") return;
@@ -3649,12 +3700,12 @@ function useGetSwitchboardLink(document) {
3649
3700
  const remotes = useSyncList();
3650
3701
  const isRemoteDrive = useMemo(() => {
3651
3702
  if (!e$4(drive)) return false;
3652
- return remotes.some((remote) => remote.collectionId === driveCollectionId("main", drive.header.id));
3703
+ return remotes.some((remote) => remote.meta.collectionId.equals(DriveCollectionId.forDrive(drive.header.id)));
3653
3704
  }, [remotes, drive]);
3654
3705
  const remoteUrl = useMemo(() => {
3655
3706
  if (!e$4(drive)) return null;
3656
3707
  try {
3657
- const channelUrl = (remotes.find((remote) => remote.collectionId === driveCollectionId("main", drive.header.id))?.channel)?.config.url;
3708
+ const channelUrl = (remotes.find((remote) => remote.meta.collectionId.equals(DriveCollectionId.forDrive(drive.header.id)))?.channel)?.config.url;
3658
3709
  if (typeof channelUrl === "string") return channelUrl;
3659
3710
  return null;
3660
3711
  } catch (error) {
@@ -3700,7 +3751,7 @@ async function _refreshReactorData(reactor) {
3700
3751
  }
3701
3752
  async function _refreshReactorDataClient(reactor) {
3702
3753
  if (!reactor) return;
3703
- setDrives((await reactor.find({ type: "powerhouse/document-drive" })).results);
3754
+ setDrives(await getDrives(reactor));
3704
3755
  }
3705
3756
  function createDebouncedRefreshReactorData(debounceDelayMs = DEFAULT_DEBOUNCE_DELAY_MS, immediateThresholdMs = DEFAULT_IMMEDIATE_THRESHOLD_MS) {
3706
3757
  let timeout = null;
@@ -3745,4 +3796,4 @@ createDebouncedRefreshReactorDataClient();
3745
3796
  //#endregion
3746
3797
  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 };
3747
3798
 
3748
- //# sourceMappingURL=dist-QOGgRb-y.mjs.map
3799
+ //# sourceMappingURL=dist-RdOXBdt-.mjs.map