@powerhousedao/powerhouse-vetra-packages 6.2.2-dev.7 → 6.2.2-dev.71
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/browser/assets/{entry-Cvoo4_c9.js → entry-D9kxNMhQ.js} +3 -2
- package/dist/browser/assets/{projection-entry-DVec8YRh.js → projection-entry-CuhmOECW.js} +4 -4
- package/dist/browser/{linting-Dn6pXRkK.js → button-CuO8Gh3v.js} +20 -6
- package/dist/browser/button-CuO8Gh3v.js.map +1 -0
- package/dist/browser/{connect-KEU-HR3o.js → connect-BQ3NfcJz.js} +916 -200
- package/dist/browser/connect-BQ3NfcJz.js.map +1 -0
- package/dist/browser/{dist-CXoKspdx.js → dist-B4FWbuEM.js} +10 -2
- package/dist/browser/{dist-CXoKspdx.js.map → dist-B4FWbuEM.js.map} +1 -1
- package/dist/{node/dist-BeZaEP6S.mjs → browser/dist-BAJ5nRDl.js} +21 -2
- package/dist/browser/{dist-D8H48e8N.js.map → dist-BAJ5nRDl.js.map} +1 -1
- package/dist/browser/{dist-D5ra2aRj.js → dist-Ha_NNo7z.js} +1987 -1451
- package/dist/browser/dist-Ha_NNo7z.js.map +1 -0
- package/dist/browser/{document-drive-IdFV1QXL.js → document-drive-BgXuuZ9v.js} +1184 -122
- package/dist/browser/document-drive-BgXuuZ9v.js.map +1 -0
- package/dist/browser/document-models/index.js +1 -1
- package/dist/browser/{documents-D4ek7Ubv.js → documents-J_l59mSV.js} +5 -604
- package/dist/browser/documents-J_l59mSV.js.map +1 -0
- package/dist/browser/editor-DHPXrcLc.js +25 -0
- package/dist/browser/editor-DHPXrcLc.js.map +1 -0
- package/dist/browser/{editor-DiZF3ao3.js → editor-XuCmPGuB.js} +671 -236
- package/dist/browser/editor-XuCmPGuB.js.map +1 -0
- package/dist/browser/editors/document-model-editor/module.js +1 -1
- package/dist/browser/editors/generic-drive-explorer/index.js +5 -5
- package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
- package/dist/{node/folder-view-Cy-QxsDg.mjs → browser/folder-view-CuDz6ylG.js} +73 -46
- package/dist/browser/folder-view-CuDz6ylG.js.map +1 -0
- package/dist/browser/{graphql-editor-ZLRO_8Ce.js → graphql-editor-DSVq4B4o.js} +8 -7
- package/dist/browser/{graphql-editor-ZLRO_8Ce.js.map → graphql-editor-DSVq4B4o.js.map} +1 -1
- package/dist/browser/{hooks-CORHBNHb.js → hooks-KKcNp2X0.js} +2 -2
- package/dist/browser/{hooks-CORHBNHb.js.map → hooks-KKcNp2X0.js.map} +1 -1
- package/dist/browser/index.js +378 -9
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/{json-editor-DBuZ6gN7.js → json-editor-CKhR3Fvh.js} +4 -4
- package/dist/browser/{json-editor-DBuZ6gN7.js.map → json-editor-CKhR3Fvh.js.map} +1 -1
- package/dist/browser/{lib-C-f3izXz.js → lib-DMgQj1v2.js} +13 -4
- package/dist/browser/lib-DMgQj1v2.js.map +1 -0
- package/dist/browser/printer-CEYr4JOg.js +604 -0
- package/dist/browser/printer-CEYr4JOg.js.map +1 -0
- package/dist/browser/{schema-context-DY-GEGnY.js → schema-context-ZyeclQwy.js} +2 -2
- package/dist/browser/{schema-context-DY-GEGnY.js.map → schema-context-ZyeclQwy.js.map} +1 -1
- package/dist/browser/{state-schemas-BjQKM498.js → state-schemas-D0_9u4nu.js} +8 -18
- package/dist/browser/state-schemas-D0_9u4nu.js.map +1 -0
- package/dist/node/{linting-Dx50GuLN.mjs → button-Da7CxMn7.mjs} +20 -7
- package/dist/node/button-Da7CxMn7.mjs.map +1 -0
- package/dist/node/{connect-KcYZcy_Z.mjs → connect-DOD5zQrl.mjs} +916 -200
- package/dist/node/connect-DOD5zQrl.mjs.map +1 -0
- package/dist/node/{dist-DJEK2WVi.mjs → dist-CNlIJlyu.mjs} +1992 -1451
- package/dist/node/dist-CNlIJlyu.mjs.map +1 -0
- package/dist/{browser/dist-D8H48e8N.js → node/dist-CzYOpeXN.mjs} +21 -2
- package/dist/node/{dist-BeZaEP6S.mjs.map → dist-CzYOpeXN.mjs.map} +1 -1
- package/dist/node/{dist-fA4EItr0.mjs → dist-DT7jI9ol.mjs} +10 -2
- package/dist/node/{dist-fA4EItr0.mjs.map → dist-DT7jI9ol.mjs.map} +1 -1
- package/dist/node/{document-drive-C8hbqQ3C.mjs → document-drive-BV8zVgUr.mjs} +1184 -122
- package/dist/node/document-drive-BV8zVgUr.mjs.map +1 -0
- package/dist/node/document-models/index.mjs +1 -1
- package/dist/node/{documents-BFBPmyw1.mjs → documents-DCf53bzO.mjs} +3 -3
- package/dist/node/{documents-BFBPmyw1.mjs.map → documents-DCf53bzO.mjs.map} +1 -1
- package/dist/node/editor-BIIW42CR.mjs +25 -0
- package/dist/node/editor-BIIW42CR.mjs.map +1 -0
- package/dist/node/{editor-B1KhoF1f.mjs → editor-BznTtugG.mjs} +672 -237
- package/dist/node/editor-BznTtugG.mjs.map +1 -0
- package/dist/node/editors/document-model-editor/module.mjs +1 -1
- package/dist/node/editors/generic-drive-explorer/index.mjs +5 -5
- package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
- package/dist/{browser/folder-view-DMFqcJhc.js → node/folder-view-WvkfzzHI.mjs} +73 -46
- package/dist/node/folder-view-WvkfzzHI.mjs.map +1 -0
- package/dist/node/{graphql-DskHmkMe.mjs → graphql-BfAoPeWM.mjs} +2 -2
- package/dist/node/{graphql-DskHmkMe.mjs.map → graphql-BfAoPeWM.mjs.map} +1 -1
- package/dist/node/{graphql-editor-C5VLRqEf.mjs → graphql-editor-aDsDHPSg.mjs} +7 -7
- package/dist/node/{graphql-editor-C5VLRqEf.mjs.map → graphql-editor-aDsDHPSg.mjs.map} +1 -1
- package/dist/node/{hooks-DJrjfVaS.mjs → hooks-D0DcS3MV.mjs} +2 -2
- package/dist/node/{hooks-DJrjfVaS.mjs.map → hooks-D0DcS3MV.mjs.map} +1 -1
- package/dist/node/index.mjs +378 -9
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/{json-editor-iI2s9a_4.mjs → json-editor-hK4xilEL.mjs} +4 -4
- package/dist/node/{json-editor-iI2s9a_4.mjs.map → json-editor-hK4xilEL.mjs.map} +1 -1
- package/dist/node/{main-D82dkD7g.mjs → main-DutzjcaZ.mjs} +15 -6
- package/dist/node/main-DutzjcaZ.mjs.map +1 -0
- package/dist/node/{schema-context-CX5ml_9t.mjs → schema-context-DL8jhi_d.mjs} +3 -3
- package/dist/node/{schema-context-CX5ml_9t.mjs.map → schema-context-DL8jhi_d.mjs.map} +1 -1
- package/dist/node/{state-schemas-Bl7nA8bB.mjs → state-schemas-CQ4bprzx.mjs} +10 -20
- package/dist/{browser/state-schemas-BjQKM498.js.map → node/state-schemas-CQ4bprzx.mjs.map} +1 -1
- package/package.json +8 -7
- package/dist/browser/connect-KEU-HR3o.js.map +0 -1
- package/dist/browser/dist-D5ra2aRj.js.map +0 -1
- package/dist/browser/document-drive-IdFV1QXL.js.map +0 -1
- package/dist/browser/documents-D4ek7Ubv.js.map +0 -1
- package/dist/browser/editor-DiZF3ao3.js.map +0 -1
- package/dist/browser/editor-SqNULDP-.js +0 -29
- package/dist/browser/editor-SqNULDP-.js.map +0 -1
- package/dist/browser/folder-view-DMFqcJhc.js.map +0 -1
- package/dist/browser/lib-C-f3izXz.js.map +0 -1
- package/dist/browser/linting-Dn6pXRkK.js.map +0 -1
- package/dist/node/connect-KcYZcy_Z.mjs.map +0 -1
- package/dist/node/dist-DJEK2WVi.mjs.map +0 -1
- package/dist/node/document-drive-C8hbqQ3C.mjs.map +0 -1
- package/dist/node/editor-B1KhoF1f.mjs.map +0 -1
- package/dist/node/editor-yBGEvMGD.mjs +0 -29
- package/dist/node/editor-yBGEvMGD.mjs.map +0 -1
- package/dist/node/folder-view-Cy-QxsDg.mjs.map +0 -1
- package/dist/node/linting-Dx50GuLN.mjs.map +0 -1
- package/dist/node/main-D82dkD7g.mjs.map +0 -1
- package/dist/node/state-schemas-Bl7nA8bB.mjs.map +0 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as DriveCollectionId, i as SyncStatus, o as ModuleNotFoundError, t as require_main } from "./main-
|
|
4
|
-
import {
|
|
1
|
+
import { D as __commonJSMin, M as __toESM, t as capitalCase } from "./dist-DT7jI9ol.mjs";
|
|
2
|
+
import { C as baseLoadFromInputVersioned, O as createPresignedHeader, Q as setName, S as baseLoadFromInput, T as buildSignedAction, U as replayDocumentVersioned, a as handleTargetNameCollisions, ct as validateStateSchemaName, f as logger, h as UnsupportedDocumentModelVersionError, i as generateNodesCopy, j as createZip, l as moveNode, lt as generateId, n as copyNode, o as isFileNode, ot as validateInitialState, s as isFolderNode, st as validateModules, t as addFolder, u as updateNode, w as baseSaveToFileHandle, y as assertAuthPreservedOnDuplicate } from "./document-drive-BV8zVgUr.mjs";
|
|
3
|
+
import { a as DriveCollectionId, i as SyncStatus, o as ModuleNotFoundError, t as require_main } from "./main-DutzjcaZ.mjs";
|
|
4
|
+
import { t as require_graphql } from "./graphql-BfAoPeWM.mjs";
|
|
5
|
+
import { createContext, use, useCallback, useContext, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
5
6
|
import "react/jsx-runtime";
|
|
6
|
-
//#region ../reactor-browser/dist/make-ph-event-functions-
|
|
7
|
+
//#region ../reactor-browser/dist/make-ph-event-functions-DBq3iWYn.js
|
|
7
8
|
const isServer$1 = typeof window === "undefined";
|
|
8
9
|
function makePHEventFunctions(key) {
|
|
9
10
|
const setEventName = `ph:set${capitalCase(key)}`;
|
|
@@ -51,7 +52,7 @@ function makePHEventFunctions(key) {
|
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
//#endregion
|
|
54
|
-
//#region ../reactor-browser/dist/document-by-id-
|
|
55
|
+
//#region ../reactor-browser/dist/document-by-id-BSZqTN66.js
|
|
55
56
|
async function queueActions(document, actionOrActions) {
|
|
56
57
|
if (!document) throw new Error("No document provided");
|
|
57
58
|
if (!actionOrActions) throw new Error("No actions provided");
|
|
@@ -97,12 +98,12 @@ async function uploadOperations(documentId, allOperations, pushOperations, optio
|
|
|
97
98
|
logger.verbose(`uploadDocumentOperations:for:waitForUpdate(${documentId}): END`);
|
|
98
99
|
}
|
|
99
100
|
async function signAction(action, document) {
|
|
100
|
-
const reactor = window.ph?.reactorClient;
|
|
101
|
-
if (!reactor) return action;
|
|
102
|
-
const reducer = (await reactor.getDocumentModelModule(document.header.documentType)).reducer;
|
|
103
101
|
const renown = window.ph?.renown;
|
|
104
102
|
if (!renown?.user) return action;
|
|
105
103
|
if (!action.context?.signer) return action;
|
|
104
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
105
|
+
if (!reactorClient) return action;
|
|
106
|
+
const reducer = (await reactorClient.getDocumentModelModuleForDocument(document)).reducer;
|
|
106
107
|
const actionSigner = action.context.signer;
|
|
107
108
|
return await buildSignedAction(action, reducer, document, actionSigner, renown.crypto.sign);
|
|
108
109
|
}
|
|
@@ -180,6 +181,21 @@ async function dispatchActions(actionOrActions, documentOrDocumentId, onErrors,
|
|
|
180
181
|
if (onSuccess && result) onSuccess(result);
|
|
181
182
|
return result;
|
|
182
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* The reactor's `DocumentChangeType` members, typed as the enum so they can be
|
|
186
|
+
* assigned to `DocumentChangeEvent.type`. The assertion is unavoidable - a
|
|
187
|
+
* TypeScript string enum is nominal, so no string literal is assignable to it
|
|
188
|
+
* without one - and the two checks above are what make it safe.
|
|
189
|
+
*/
|
|
190
|
+
const DOCUMENT_CHANGE_TYPE = {
|
|
191
|
+
Created: "created",
|
|
192
|
+
Deleted: "deleted",
|
|
193
|
+
Updated: "updated",
|
|
194
|
+
ParentAdded: "parent_added",
|
|
195
|
+
ParentRemoved: "parent_removed",
|
|
196
|
+
ChildAdded: "child_added",
|
|
197
|
+
ChildRemoved: "child_removed"
|
|
198
|
+
};
|
|
183
199
|
const documentEventFunctions = makePHEventFunctions("documentCache");
|
|
184
200
|
/** Returns all documents in the reactor. */
|
|
185
201
|
const useDocumentCache = documentEventFunctions.useValue;
|
|
@@ -225,9 +241,27 @@ function useDocumentById(id) {
|
|
|
225
241
|
const [, dispatch] = useDispatch(document);
|
|
226
242
|
return [document, dispatch];
|
|
227
243
|
}
|
|
244
|
+
Error;
|
|
245
|
+
require_graphql();
|
|
246
|
+
JSON;
|
|
228
247
|
//#endregion
|
|
229
|
-
//#region ../reactor-browser/dist/client-
|
|
248
|
+
//#region ../reactor-browser/dist/client-DB8gP4hz.js
|
|
230
249
|
var import_main = require_main();
|
|
250
|
+
let DocumentChangeType = /* @__PURE__ */ function(DocumentChangeType) {
|
|
251
|
+
DocumentChangeType["ChildAdded"] = "CHILD_ADDED";
|
|
252
|
+
DocumentChangeType["ChildRemoved"] = "CHILD_REMOVED";
|
|
253
|
+
DocumentChangeType["Created"] = "CREATED";
|
|
254
|
+
DocumentChangeType["Deleted"] = "DELETED";
|
|
255
|
+
DocumentChangeType["ParentAdded"] = "PARENT_ADDED";
|
|
256
|
+
DocumentChangeType["ParentRemoved"] = "PARENT_REMOVED";
|
|
257
|
+
DocumentChangeType["Updated"] = "UPDATED";
|
|
258
|
+
return DocumentChangeType;
|
|
259
|
+
}({});
|
|
260
|
+
let PropagationMode = /* @__PURE__ */ function(PropagationMode) {
|
|
261
|
+
PropagationMode["Cascade"] = "CASCADE";
|
|
262
|
+
PropagationMode["Orphan"] = "ORPHAN";
|
|
263
|
+
return PropagationMode;
|
|
264
|
+
}({});
|
|
231
265
|
const PhDocumentFieldsFragmentDoc = import_main.gql`
|
|
232
266
|
fragment PHDocumentFields on PHDocument {
|
|
233
267
|
id
|
|
@@ -288,6 +322,7 @@ const GetDocumentWithOperationsDocument = import_main.gql`
|
|
|
288
322
|
hash
|
|
289
323
|
skip
|
|
290
324
|
error
|
|
325
|
+
deniedReason
|
|
291
326
|
id
|
|
292
327
|
action {
|
|
293
328
|
id
|
|
@@ -400,6 +435,7 @@ const GetDocumentOperationsDocument = import_main.gql`
|
|
|
400
435
|
hash
|
|
401
436
|
skip
|
|
402
437
|
error
|
|
438
|
+
deniedReason
|
|
403
439
|
id
|
|
404
440
|
action {
|
|
405
441
|
id
|
|
@@ -442,6 +478,28 @@ import_main.gql`
|
|
|
442
478
|
}
|
|
443
479
|
}
|
|
444
480
|
`;
|
|
481
|
+
import_main.gql`
|
|
482
|
+
query EvaluateActions(
|
|
483
|
+
$documentIdentifier: String!
|
|
484
|
+
$branch: String
|
|
485
|
+
$candidates: [ActionCandidateInput!]!
|
|
486
|
+
) {
|
|
487
|
+
evaluateActions(
|
|
488
|
+
documentIdentifier: $documentIdentifier
|
|
489
|
+
branch: $branch
|
|
490
|
+
candidates: $candidates
|
|
491
|
+
) {
|
|
492
|
+
evaluations {
|
|
493
|
+
decision
|
|
494
|
+
reason
|
|
495
|
+
}
|
|
496
|
+
allAllowed
|
|
497
|
+
anyAllowed
|
|
498
|
+
allDenied
|
|
499
|
+
anyDenied
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
`;
|
|
445
503
|
import_main.gql`
|
|
446
504
|
mutation CreateDocument($document: JSONObject!, $parentIdentifier: String) {
|
|
447
505
|
createDocument(document: $document, parentIdentifier: $parentIdentifier) {
|
|
@@ -467,13 +525,13 @@ import_main.gql`
|
|
|
467
525
|
import_main.gql`
|
|
468
526
|
mutation MutateDocument(
|
|
469
527
|
$documentIdentifier: String!
|
|
470
|
-
$actions: [
|
|
471
|
-
$
|
|
528
|
+
$actions: [ActionInput!]!
|
|
529
|
+
$branch: String
|
|
472
530
|
) {
|
|
473
|
-
mutateDocument(
|
|
531
|
+
mutateDocument: execute(
|
|
474
532
|
documentIdentifier: $documentIdentifier
|
|
475
533
|
actions: $actions
|
|
476
|
-
|
|
534
|
+
branch: $branch
|
|
477
535
|
) {
|
|
478
536
|
...PHDocumentFields
|
|
479
537
|
}
|
|
@@ -483,14 +541,21 @@ import_main.gql`
|
|
|
483
541
|
import_main.gql`
|
|
484
542
|
mutation MutateDocumentAsync(
|
|
485
543
|
$documentIdentifier: String!
|
|
486
|
-
$actions: [
|
|
487
|
-
$
|
|
544
|
+
$actions: [ActionInput!]!
|
|
545
|
+
$branch: String
|
|
488
546
|
) {
|
|
489
|
-
mutateDocumentAsync(
|
|
547
|
+
mutateDocumentAsync: executeAsync(
|
|
490
548
|
documentIdentifier: $documentIdentifier
|
|
491
549
|
actions: $actions
|
|
492
|
-
|
|
493
|
-
)
|
|
550
|
+
branch: $branch
|
|
551
|
+
) {
|
|
552
|
+
id
|
|
553
|
+
status
|
|
554
|
+
result
|
|
555
|
+
error
|
|
556
|
+
createdAt
|
|
557
|
+
completedAt
|
|
558
|
+
}
|
|
494
559
|
}
|
|
495
560
|
`;
|
|
496
561
|
import_main.gql`
|
|
@@ -650,6 +715,7 @@ import_main.gql`
|
|
|
650
715
|
hash
|
|
651
716
|
skip
|
|
652
717
|
error
|
|
718
|
+
deniedReason
|
|
653
719
|
id
|
|
654
720
|
action {
|
|
655
721
|
id
|
|
@@ -692,6 +758,7 @@ import_main.gql`
|
|
|
692
758
|
deadLetters {
|
|
693
759
|
documentId
|
|
694
760
|
error
|
|
761
|
+
errorType
|
|
695
762
|
}
|
|
696
763
|
hasMore
|
|
697
764
|
}
|
|
@@ -738,51 +805,65 @@ function extractQueryParts(doc, fallbackBody) {
|
|
|
738
805
|
extractSelectionSet(GetDocumentOperationsDocument, "documentOperations", "{ items { index } }");
|
|
739
806
|
extractQueryParts(GetDocumentDocument, "document(identifier: $identifier) { document { id name documentType state revisionsList { scope revision } createdAtUtcIso lastModifiedAtUtcIso } childIds }");
|
|
740
807
|
//#endregion
|
|
741
|
-
//#region ../reactor-browser/dist/renown-
|
|
808
|
+
//#region ../reactor-browser/dist/renown-6w_ImTvm.js
|
|
742
809
|
const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
|
|
810
|
+
const RenownInitialUserContext = createContext({ state: "unknown" });
|
|
811
|
+
/** First-render auth as a three-state value; use this to skip a spinner when anonymous. */
|
|
812
|
+
function useRenownInitialAuth() {
|
|
813
|
+
return useContext(RenownInitialUserContext);
|
|
814
|
+
}
|
|
815
|
+
function useRenownInitialUser() {
|
|
816
|
+
const initial = useRenownInitialAuth();
|
|
817
|
+
return initial.state === "authenticated" ? initial.user : void 0;
|
|
818
|
+
}
|
|
743
819
|
const renownEventFunctions = makePHEventFunctions("renown");
|
|
744
820
|
renownEventFunctions.addEventHandler;
|
|
745
821
|
/** Returns the renown instance */
|
|
746
822
|
const useRenown = renownEventFunctions.useValue;
|
|
747
823
|
renownEventFunctions.setValue;
|
|
824
|
+
function jsonEqual(a, b) {
|
|
825
|
+
if (a === b) return true;
|
|
826
|
+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) return false;
|
|
827
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
828
|
+
const ra = a;
|
|
829
|
+
const rb = b;
|
|
830
|
+
const keys = Object.keys(ra).filter((k) => ra[k] !== void 0);
|
|
831
|
+
if (keys.length !== Object.keys(rb).filter((k) => rb[k] !== void 0).length) return false;
|
|
832
|
+
return keys.every((k) => jsonEqual(ra[k], rb[k]));
|
|
833
|
+
}
|
|
834
|
+
function sameUser(a, b) {
|
|
835
|
+
return jsonEqual(a, b);
|
|
836
|
+
}
|
|
837
|
+
function resolveInstanceUser(instance, seed) {
|
|
838
|
+
const restored = instance.user;
|
|
839
|
+
if (restored) return sameUser(seed, restored) ? seed : restored;
|
|
840
|
+
return instance.status === "initial" ? void 0 : seed;
|
|
841
|
+
}
|
|
748
842
|
/** Returns the current user from the renown instance, subscribing to user events */
|
|
749
843
|
function useUser() {
|
|
750
844
|
const renown = useRenown();
|
|
751
|
-
const
|
|
845
|
+
const initialUser = useRenownInitialUser();
|
|
846
|
+
const instance = renown ? renown : void 0;
|
|
847
|
+
const [tracked, setTracked] = useState(() => ({
|
|
848
|
+
instance,
|
|
849
|
+
user: instance ? resolveInstanceUser(instance, initialUser) : initialUser
|
|
850
|
+
}));
|
|
851
|
+
const current = tracked.instance === instance ? tracked : {
|
|
852
|
+
instance,
|
|
853
|
+
user: instance ? resolveInstanceUser(instance, tracked.user ?? initialUser) : tracked.user
|
|
854
|
+
};
|
|
752
855
|
useEffect(() => {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const childValue = childProps[key];
|
|
764
|
-
if (key === "style") merged[key] = {
|
|
765
|
-
...parentValue,
|
|
766
|
-
...childValue
|
|
767
|
-
};
|
|
768
|
-
else if (key === "className") merged[key] = [parentValue, childValue].filter(Boolean).join(" ");
|
|
769
|
-
else if (typeof parentValue === "function" && typeof childValue === "function") merged[key] = (...args) => {
|
|
770
|
-
childValue(...args);
|
|
771
|
-
parentValue(...args);
|
|
772
|
-
};
|
|
773
|
-
else if (childValue !== void 0) merged[key] = childValue;
|
|
774
|
-
}
|
|
775
|
-
return merged;
|
|
856
|
+
if (current !== tracked) setTracked(current);
|
|
857
|
+
}, [current, tracked]);
|
|
858
|
+
useEffect(() => {
|
|
859
|
+
if (!instance) return;
|
|
860
|
+
return instance.on("user", (user) => setTracked((prev) => ({
|
|
861
|
+
instance,
|
|
862
|
+
user: sameUser(prev.user, user) ? prev.user : user
|
|
863
|
+
})));
|
|
864
|
+
}, [instance]);
|
|
865
|
+
return instance ? current.user : initialUser ?? current.user;
|
|
776
866
|
}
|
|
777
|
-
const Slot = forwardRef(({ children, ...props }, ref) => {
|
|
778
|
-
const child = Children.only(children);
|
|
779
|
-
if (!isValidElement(child)) return null;
|
|
780
|
-
const childElement = child;
|
|
781
|
-
const mergedProps = mergeProps(props, childElement.props);
|
|
782
|
-
if (ref) mergedProps.ref = ref;
|
|
783
|
-
return cloneElement(childElement, mergedProps);
|
|
784
|
-
});
|
|
785
|
-
Slot.displayName = "Slot";
|
|
786
867
|
//#endregion
|
|
787
868
|
//#region ../../node_modules/.pnpm/remeda@2.33.7/node_modules/remeda/dist/lazyDataLastImpl-DtF3cihj.js
|
|
788
869
|
function e$8(e, t, n) {
|
|
@@ -907,6 +988,32 @@ function e(e) {
|
|
|
907
988
|
let t = !1, n;
|
|
908
989
|
return () => (t ||= (n = e(), !0), n);
|
|
909
990
|
}
|
|
991
|
+
var CloseCode = /* @__PURE__ */ ((CloseCode2) => {
|
|
992
|
+
CloseCode2[CloseCode2["InternalServerError"] = 4500] = "InternalServerError";
|
|
993
|
+
CloseCode2[CloseCode2["InternalClientError"] = 4005] = "InternalClientError";
|
|
994
|
+
CloseCode2[CloseCode2["BadRequest"] = 4400] = "BadRequest";
|
|
995
|
+
CloseCode2[CloseCode2["BadResponse"] = 4004] = "BadResponse";
|
|
996
|
+
CloseCode2[CloseCode2["Unauthorized"] = 4401] = "Unauthorized";
|
|
997
|
+
CloseCode2[CloseCode2["Forbidden"] = 4403] = "Forbidden";
|
|
998
|
+
CloseCode2[CloseCode2["SubprotocolNotAcceptable"] = 4406] = "SubprotocolNotAcceptable";
|
|
999
|
+
CloseCode2[CloseCode2["ConnectionInitialisationTimeout"] = 4408] = "ConnectionInitialisationTimeout";
|
|
1000
|
+
CloseCode2[CloseCode2["ConnectionAcknowledgementTimeout"] = 4504] = "ConnectionAcknowledgementTimeout";
|
|
1001
|
+
CloseCode2[CloseCode2["SubscriberAlreadyExists"] = 4409] = "SubscriberAlreadyExists";
|
|
1002
|
+
CloseCode2[CloseCode2["TooManyInitialisationRequests"] = 4429] = "TooManyInitialisationRequests";
|
|
1003
|
+
return CloseCode2;
|
|
1004
|
+
})(CloseCode || {});
|
|
1005
|
+
var MessageType = /* @__PURE__ */ ((MessageType2) => {
|
|
1006
|
+
MessageType2["ConnectionInit"] = "connection_init";
|
|
1007
|
+
MessageType2["ConnectionAck"] = "connection_ack";
|
|
1008
|
+
MessageType2["Ping"] = "ping";
|
|
1009
|
+
MessageType2["Pong"] = "pong";
|
|
1010
|
+
MessageType2["Subscribe"] = "subscribe";
|
|
1011
|
+
MessageType2["Next"] = "next";
|
|
1012
|
+
MessageType2["Error"] = "error";
|
|
1013
|
+
MessageType2["Complete"] = "complete";
|
|
1014
|
+
return MessageType2;
|
|
1015
|
+
})(MessageType || {});
|
|
1016
|
+
Error;
|
|
910
1017
|
//#endregion
|
|
911
1018
|
//#region ../../node_modules/.pnpm/slug@11.0.1/node_modules/slug/slug.js
|
|
912
1019
|
let base64;
|
|
@@ -1694,1075 +1801,740 @@ slug.setLocale = function(locale) {
|
|
|
1694
1801
|
defaultLocale = locales[locale] || {};
|
|
1695
1802
|
};
|
|
1696
1803
|
//#endregion
|
|
1697
|
-
//#region
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
};
|
|
1703
|
-
const CORE_ERROR_PROPS = [
|
|
1704
|
-
"name",
|
|
1705
|
-
"message",
|
|
1706
|
-
"stack",
|
|
1707
|
-
"cause",
|
|
1708
|
-
"errors"
|
|
1709
|
-
];
|
|
1710
|
-
const normalizeDescriptor = (error, propName) => {
|
|
1711
|
-
const descriptor = getDescriptor(error, propName);
|
|
1712
|
-
if (descriptor === void 0) return;
|
|
1713
|
-
if (isReadonlyGetter(descriptor)) {
|
|
1714
|
-
setErrorProperty(error, propName, error[propName]);
|
|
1715
|
-
return;
|
|
1804
|
+
//#region ../reactor-browser/dist/document-operations-B2lxu6qg.js
|
|
1805
|
+
var UnsupportedDocumentTypeError = class extends Error {
|
|
1806
|
+
constructor(documentType) {
|
|
1807
|
+
super(`Document type ${documentType} is not supported`);
|
|
1808
|
+
this.name = "UnsupportedDocumentTypeError";
|
|
1716
1809
|
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
const getDescriptor = (value, propName) => {
|
|
1720
|
-
const descriptor = Object.getOwnPropertyDescriptor(value, propName);
|
|
1721
|
-
if (descriptor !== void 0) return descriptor;
|
|
1722
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1723
|
-
return prototype === null ? void 0 : getDescriptor(prototype, propName);
|
|
1724
|
-
};
|
|
1725
|
-
const isReadonlyGetter = ({ get, set }) => get !== void 0 && set === void 0;
|
|
1726
|
-
const isInvalidDescriptor = ({ enumerable, writable }) => enumerable || !writable;
|
|
1727
|
-
const setErrorProperty = (error, propName, value) => {
|
|
1728
|
-
setErrorDescriptor(error, propName, { value });
|
|
1729
|
-
};
|
|
1730
|
-
const setErrorDescriptor = (error, propName, descriptor) => {
|
|
1731
|
-
Object.defineProperty(error, propName, {
|
|
1732
|
-
...descriptor,
|
|
1733
|
-
..."get" in descriptor || "set" in descriptor ? {} : { writable: true },
|
|
1734
|
-
enumerable: false,
|
|
1735
|
-
configurable: true
|
|
1736
|
-
});
|
|
1737
|
-
};
|
|
1738
|
-
//#endregion
|
|
1739
|
-
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/aggregate.js
|
|
1740
|
-
const normalizeAggregate = (error, recurse) => {
|
|
1741
|
-
if (Array.isArray(error.errors)) setErrorProperty(error, "errors", error.errors.filter(isDefined).map(recurse).filter(Boolean));
|
|
1742
|
-
else if (isAggregateError(error)) setErrorProperty(error, "errors", []);
|
|
1743
|
-
else if (error.errors !== void 0) deleteAggregateErrors(error);
|
|
1744
|
-
};
|
|
1745
|
-
const isDefined = (error) => error !== void 0;
|
|
1746
|
-
const isAggregateError = (error) => "AggregateError" in globalThis && (error.name === "AggregateError" || error instanceof AggregateError);
|
|
1747
|
-
const deleteAggregateErrors = (error) => {
|
|
1748
|
-
delete error.errors;
|
|
1749
|
-
if (error.errors !== void 0) setErrorProperty(error, "errors", []);
|
|
1750
|
-
};
|
|
1751
|
-
//#endregion
|
|
1752
|
-
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/cause.js
|
|
1753
|
-
const normalizeCause = (error, recurse) => {
|
|
1754
|
-
if (!("cause" in error)) return;
|
|
1755
|
-
const cause = error.cause === void 0 ? error.cause : recurse(error.cause);
|
|
1756
|
-
if (cause === void 0) delete error.cause;
|
|
1757
|
-
else setErrorProperty(error, "cause", cause);
|
|
1758
|
-
};
|
|
1759
|
-
//#endregion
|
|
1760
|
-
//#region ../../node_modules/.pnpm/is-error-instance@3.0.1/node_modules/is-error-instance/build/src/main.js
|
|
1761
|
-
const isErrorInstance = (value) => isInstanceOfError(value) || hasErrorTag(value);
|
|
1762
|
-
const isInstanceOfError = (value) => {
|
|
1763
|
-
try {
|
|
1764
|
-
return value instanceof Error;
|
|
1765
|
-
} catch {
|
|
1766
|
-
return false;
|
|
1810
|
+
static isError(error) {
|
|
1811
|
+
return Error.isError(error) && error.name === "UnsupportedDocumentTypeError";
|
|
1767
1812
|
}
|
|
1768
1813
|
};
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1814
|
+
var DocumentModelNotFoundError = class extends Error {
|
|
1815
|
+
documentType;
|
|
1816
|
+
name = "DocumentModelNotFoundError";
|
|
1817
|
+
constructor(documentType) {
|
|
1818
|
+
super(`Document model module for type ${documentType} not found`);
|
|
1819
|
+
this.documentType = documentType;
|
|
1774
1820
|
}
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
"[object Error]",
|
|
1778
|
-
"[object DOMException]",
|
|
1779
|
-
"[object DOMError]",
|
|
1780
|
-
"[object Exception]"
|
|
1781
|
-
]);
|
|
1782
|
-
//#endregion
|
|
1783
|
-
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
1784
|
-
function isPlainObject(value) {
|
|
1785
|
-
if (typeof value !== "object" || value === null) return false;
|
|
1786
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1787
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
1788
|
-
}
|
|
1789
|
-
//#endregion
|
|
1790
|
-
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/modifiable.js
|
|
1791
|
-
const isNonModifiableError = (error) => !Object.isExtensible(error) || CORE_ERROR_PROPS.some((propName) => isNonConfigurableProp(error, propName) || isThrowingProp(error, propName));
|
|
1792
|
-
const isNonConfigurableProp = (error, propName) => {
|
|
1793
|
-
const descriptor = Object.getOwnPropertyDescriptor(error, propName);
|
|
1794
|
-
return descriptor !== void 0 && !descriptor.configurable;
|
|
1795
|
-
};
|
|
1796
|
-
const isThrowingProp = (error, propName) => {
|
|
1797
|
-
try {
|
|
1798
|
-
error[propName];
|
|
1799
|
-
return false;
|
|
1800
|
-
} catch {
|
|
1801
|
-
return true;
|
|
1821
|
+
static isError(error) {
|
|
1822
|
+
return Error.isError(error) && error.name === "DocumentModelNotFoundError";
|
|
1802
1823
|
}
|
|
1803
1824
|
};
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1825
|
+
var DocumentTypeMismatchError = class extends Error {
|
|
1826
|
+
constructor(documentId, expectedType, actualType) {
|
|
1827
|
+
super(`Document ${documentId} is not of type ${expectedType}. Actual type: ${actualType}`);
|
|
1828
|
+
}
|
|
1808
1829
|
};
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1830
|
+
var NoSelectedDocumentError = class extends Error {
|
|
1831
|
+
constructor() {
|
|
1832
|
+
super("There is no selected document. Did you mean to call 'useSelectedDocumentSafe' instead?");
|
|
1833
|
+
}
|
|
1812
1834
|
};
|
|
1813
|
-
const
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1835
|
+
const modalEventFunctions = makePHEventFunctions("modal");
|
|
1836
|
+
modalEventFunctions.useValue;
|
|
1837
|
+
/** Sets the current modal */
|
|
1838
|
+
const setPHModal = modalEventFunctions.setValue;
|
|
1839
|
+
modalEventFunctions.addEventHandler;
|
|
1840
|
+
/** Shows a modal */
|
|
1841
|
+
function showPHModal(modal) {
|
|
1842
|
+
setPHModal(modal);
|
|
1843
|
+
}
|
|
1844
|
+
/** Shows the delete node modal */
|
|
1845
|
+
function showDeleteNodeModal(nodeOrId) {
|
|
1846
|
+
setPHModal({
|
|
1847
|
+
type: "deleteItem",
|
|
1848
|
+
id: typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id
|
|
1849
|
+
});
|
|
1850
|
+
}
|
|
1851
|
+
function isDocumentTypeSupported(documentType, supportedDocuments) {
|
|
1852
|
+
if (!supportedDocuments?.length) return true;
|
|
1853
|
+
return supportedDocuments.some((pattern) => {
|
|
1854
|
+
if (pattern.endsWith("/*")) {
|
|
1855
|
+
const prefix = pattern.slice(0, -2);
|
|
1856
|
+
return documentType.startsWith(prefix + "/");
|
|
1857
|
+
}
|
|
1858
|
+
if (pattern.endsWith("*") && !pattern.endsWith("/*")) {
|
|
1859
|
+
const prefix = pattern.slice(0, -1);
|
|
1860
|
+
return documentType.startsWith(prefix);
|
|
1861
|
+
}
|
|
1862
|
+
return pattern === documentType;
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
function getUserPermissions() {
|
|
1866
|
+
const user = window.ph?.renown?.user;
|
|
1867
|
+
const allowList = window.ph?.allowList;
|
|
1868
|
+
if (!allowList) return {
|
|
1869
|
+
isAllowedToCreateDocuments: true,
|
|
1870
|
+
isAllowedToEditDocuments: true
|
|
1819
1871
|
};
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
};
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
return
|
|
1848
|
-
|
|
1849
|
-
return
|
|
1872
|
+
return {
|
|
1873
|
+
isAllowedToCreateDocuments: allowList.includes(user?.address ?? ""),
|
|
1874
|
+
isAllowedToEditDocuments: allowList.includes(user?.address ?? "")
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
1878
|
+
/** An unreadable drive cannot be shown to hold no duplicate, so reads throw. */
|
|
1879
|
+
async function isDocumentInLocation(reactorClient, document, driveId, parentFolder) {
|
|
1880
|
+
const drive = await reactorClient.get(driveId);
|
|
1881
|
+
const nodeById = drive.state.global.nodes.find((node) => node.id === document.header.id);
|
|
1882
|
+
if (nodeById && nodeById.parentFolder === (parentFolder ?? null)) return {
|
|
1883
|
+
isDuplicate: true,
|
|
1884
|
+
duplicateType: "id",
|
|
1885
|
+
nodeId: nodeById.id
|
|
1886
|
+
};
|
|
1887
|
+
const nodeByNameAndType = drive.state.global.nodes.find((node) => isFileNode(node) && node.name === document.header.name && node.documentType === document.header.documentType && node.parentFolder === (parentFolder ?? null));
|
|
1888
|
+
if (nodeByNameAndType) return {
|
|
1889
|
+
isDuplicate: true,
|
|
1890
|
+
duplicateType: "name",
|
|
1891
|
+
nodeId: nodeByNameAndType.id
|
|
1892
|
+
};
|
|
1893
|
+
return { isDuplicate: false };
|
|
1894
|
+
}
|
|
1895
|
+
function getDocumentTypeIcon(document) {
|
|
1896
|
+
switch (document.header.documentType) {
|
|
1897
|
+
case "powerhouse/document-model": return "document-model";
|
|
1898
|
+
case "powerhouse/app": return "app";
|
|
1899
|
+
case "powerhouse/document-editor": return "editor";
|
|
1900
|
+
case "powerhouse/subgraph": return "subgraph";
|
|
1901
|
+
case "powerhouse/package": return "package";
|
|
1902
|
+
case "powerhouse/processor": {
|
|
1903
|
+
const processorType = document.state.global?.type;
|
|
1904
|
+
if (processorType === "analytics") return "analytics-processor";
|
|
1905
|
+
if (processorType === "relational") return "relational-processor";
|
|
1906
|
+
if (processorType === "codegen") return "codegen-processor";
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
default: return;
|
|
1850
1910
|
}
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1911
|
+
}
|
|
1912
|
+
async function downloadFile(document, fileName) {
|
|
1853
1913
|
try {
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1914
|
+
const data = await createZip(document);
|
|
1915
|
+
const blob = new Blob([new Uint8Array(data)], { type: "application/zip" });
|
|
1916
|
+
const link = window.document.createElement("a");
|
|
1917
|
+
link.style.display = "none";
|
|
1918
|
+
link.href = URL.createObjectURL(blob);
|
|
1919
|
+
link.download = fileName;
|
|
1920
|
+
window.document.body.appendChild(link);
|
|
1921
|
+
link.click();
|
|
1922
|
+
window.document.body.removeChild(link);
|
|
1923
|
+
} catch (e) {
|
|
1924
|
+
logger.error(e instanceof Error ? e.message : String(e));
|
|
1857
1925
|
}
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
cause,
|
|
1870
|
-
errors
|
|
1871
|
-
}).forEach(([propName, propValue]) => {
|
|
1872
|
-
setNewErrorProperty(error, propName, propValue);
|
|
1873
|
-
});
|
|
1874
|
-
if (stack === void 0) setStack(error);
|
|
1875
|
-
return error;
|
|
1876
|
-
};
|
|
1877
|
-
const getMessage = (message, object) => typeof message === "string" && message !== "" ? message : truncateMessage(safeJsonStringify(object));
|
|
1878
|
-
const safeJsonStringify = (object) => {
|
|
1879
|
-
try {
|
|
1880
|
-
return JSON.stringify(object);
|
|
1881
|
-
} catch {
|
|
1882
|
-
return safeStringify(object);
|
|
1926
|
+
}
|
|
1927
|
+
async function getDocumentExtension(document) {
|
|
1928
|
+
const documentType = document.header.documentType;
|
|
1929
|
+
let rawExtension;
|
|
1930
|
+
if (documentType === "powerhouse/document-model") rawExtension = document.state.global?.extension;
|
|
1931
|
+
else {
|
|
1932
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
1933
|
+
if (reactorClient) {
|
|
1934
|
+
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
1935
|
+
rawExtension = documentModelModules.find((m) => m.documentModel.global.id === documentType)?.utils.fileExtension;
|
|
1936
|
+
}
|
|
1883
1937
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
1938
|
+
return (rawExtension ?? "").replace(/^\.+|\.+$/g, "");
|
|
1939
|
+
}
|
|
1940
|
+
/**
|
|
1941
|
+
* Fetches all operations for a document using cursor-based pagination.
|
|
1942
|
+
* The reactor client handles multi-scope cursors transparently via
|
|
1943
|
+
* composite cursors, so all scopes are fetched in a single paginated stream.
|
|
1944
|
+
*/
|
|
1945
|
+
async function fetchDocumentOperations(reactorClient, document, pageSize = 100) {
|
|
1946
|
+
const scopes = Object.keys(document.state);
|
|
1947
|
+
const operations = {};
|
|
1948
|
+
for (const scope of scopes) operations[scope] = [];
|
|
1949
|
+
let cursor = "";
|
|
1950
|
+
do {
|
|
1951
|
+
const page = await reactorClient.getOperations(document.header.id, { scopes }, void 0, {
|
|
1952
|
+
cursor,
|
|
1953
|
+
limit: pageSize
|
|
1954
|
+
});
|
|
1955
|
+
for (const op of page.results) {
|
|
1956
|
+
const scope = op.action.scope ?? "global";
|
|
1957
|
+
if (operations[scope]) operations[scope].push(op);
|
|
1958
|
+
}
|
|
1959
|
+
cursor = page.nextCursor ?? "";
|
|
1960
|
+
} while (cursor);
|
|
1961
|
+
return operations;
|
|
1962
|
+
}
|
|
1963
|
+
function extractInitialState(documentScopeOps) {
|
|
1964
|
+
const upgradeOp = documentScopeOps.find((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
1965
|
+
if (!upgradeOp) throw new Error("No UPGRADE_DOCUMENT operation found — document is invalid");
|
|
1966
|
+
const input = upgradeOp.action.input;
|
|
1967
|
+
const initialState = input.initialState ?? input.state;
|
|
1968
|
+
if (!initialState) throw new Error("UPGRADE_DOCUMENT operation has no initialState — document is invalid");
|
|
1969
|
+
return initialState;
|
|
1970
|
+
}
|
|
1971
|
+
function filterDomainOperations(operations) {
|
|
1972
|
+
return Object.fromEntries(Object.entries(operations).filter(([scope]) => !NON_DOMAIN_SCOPES.has(scope)));
|
|
1973
|
+
}
|
|
1974
|
+
function countOperations(operations) {
|
|
1975
|
+
let total = 0;
|
|
1976
|
+
for (const ops of Object.values(operations)) total += ops?.length ?? 0;
|
|
1977
|
+
return total;
|
|
1978
|
+
}
|
|
1979
|
+
/**
|
|
1980
|
+
* Split an imported document's domain operations at its mid-history upgrade
|
|
1981
|
+
* boundaries, so the caller can re-dispatch each upgrade between segments.
|
|
1982
|
+
*
|
|
1983
|
+
* The seed's CREATE_DOCUMENT and 0 -> N upgrade are replayed by the creation
|
|
1984
|
+
* path and must not be repeated. A later upgrade must be: it is where the
|
|
1985
|
+
* reducer version changes, and dropping it replays everything after it through
|
|
1986
|
+
* the module the document was created with.
|
|
1987
|
+
*/
|
|
1988
|
+
function splitAtUpgradeBoundaries(operations) {
|
|
1989
|
+
const upgrades = (operations.document ?? []).filter((op) => op.action.type === "UPGRADE_DOCUMENT").filter((op) => op.action.input.fromVersion > 0).sort((a, b) => a.index - b.index);
|
|
1990
|
+
const domain = filterDomainOperations(operations);
|
|
1991
|
+
if (upgrades.length === 0) return [{ operations: domain }];
|
|
1992
|
+
const segments = [];
|
|
1993
|
+
const consumed = /* @__PURE__ */ new Map();
|
|
1994
|
+
const take = (until) => {
|
|
1995
|
+
const slice = {};
|
|
1996
|
+
for (const [scope, ops] of Object.entries(domain)) {
|
|
1997
|
+
if (!ops) continue;
|
|
1998
|
+
const from = consumed.get(scope) ?? 0;
|
|
1999
|
+
const stop = Math.max(from, until(scope, ops));
|
|
2000
|
+
const chunk = ops.slice(from, stop);
|
|
2001
|
+
if (chunk.length > 0) slice[scope] = chunk;
|
|
2002
|
+
consumed.set(scope, stop);
|
|
2003
|
+
}
|
|
2004
|
+
return slice;
|
|
2005
|
+
};
|
|
2006
|
+
for (const upgrade of upgrades) {
|
|
2007
|
+
const input = upgrade.action.input;
|
|
2008
|
+
const slice = take((scope, ops) => boundary(upgrade, scope, ops));
|
|
2009
|
+
segments.push({
|
|
2010
|
+
operations: slice,
|
|
2011
|
+
upgradeTo: input.toVersion
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
const tail = take((_scope, ops) => ops.length);
|
|
2015
|
+
if (countOperations(tail) > 0) segments.push({ operations: tail });
|
|
2016
|
+
return segments;
|
|
2017
|
+
}
|
|
2018
|
+
/**
|
|
2019
|
+
* How many of a scope's operations precede an upgrade. Must stay identical to
|
|
2020
|
+
* the boundary computation in `replayDocumentVersioned` — snapshots compare
|
|
2021
|
+
* against operation indices, not array positions, and the timestamp fallback
|
|
2022
|
+
* excludes the upgrade's own instant.
|
|
2023
|
+
*/
|
|
2024
|
+
function boundary(upgrade, scope, ops) {
|
|
2025
|
+
const snapshot = upgrade.action.input.revision;
|
|
2026
|
+
if (snapshot !== void 0) {
|
|
2027
|
+
const revision = snapshot[scope] ?? 0;
|
|
2028
|
+
let count = 0;
|
|
2029
|
+
for (let i = 0; i < ops.length; i++) if (ops[i].index < revision) count = i + 1;
|
|
2030
|
+
return count;
|
|
2031
|
+
}
|
|
2032
|
+
for (let i = 0; i < ops.length; i++) if (ops[i].timestampUtcMs >= upgrade.timestampUtcMs) return i;
|
|
2033
|
+
return ops.length;
|
|
2034
|
+
}
|
|
2035
|
+
async function exportFile(document, suggestedName) {
|
|
2036
|
+
const reactorClient = window.ph?.reactorClient;
|
|
2037
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2038
|
+
const operations = await fetchDocumentOperations(reactorClient, document);
|
|
2039
|
+
const initialState = extractInitialState(operations["document"] ?? []);
|
|
2040
|
+
const documentWithOps = {
|
|
2041
|
+
...document,
|
|
2042
|
+
operations,
|
|
2043
|
+
initialState
|
|
2044
|
+
};
|
|
2045
|
+
const extension = await getDocumentExtension(documentWithOps);
|
|
2046
|
+
const baseName = suggestedName || documentWithOps.header.name || "Untitled";
|
|
2047
|
+
const name = extension ? `${baseName}.${extension}.phd` : `${baseName}.phd`;
|
|
2048
|
+
if (!window.showSaveFilePicker) return await downloadFile(documentWithOps, name);
|
|
1886
2049
|
try {
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
return
|
|
2050
|
+
const fileHandle = await window.showSaveFilePicker({ suggestedName: name });
|
|
2051
|
+
await baseSaveToFileHandle(documentWithOps, fileHandle);
|
|
2052
|
+
return fileHandle;
|
|
2053
|
+
} catch (e) {
|
|
2054
|
+
if (!(e instanceof DOMException && e.name === "AbortError")) throw e;
|
|
1890
2055
|
}
|
|
1891
|
-
}
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
};
|
|
1899
|
-
const
|
|
1900
|
-
Error
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Loads a document file and replays it with version-aware reducers from the registry.
|
|
2059
|
+
* Falls back to single-version legacy replay when no upgrade manifest is registered for
|
|
2060
|
+
* the document type.
|
|
2061
|
+
*/
|
|
2062
|
+
async function loadFile(path) {
|
|
2063
|
+
const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
|
|
2064
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
2065
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2066
|
+
const documentType = baseDocument.header.documentType;
|
|
2067
|
+
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
2068
|
+
const modulesForType = documentModelModules.filter((module) => module.documentModel.global.id === documentType);
|
|
2069
|
+
if (modulesForType.length === 0) throw new DocumentModelNotFoundError(documentType);
|
|
2070
|
+
const reducers = {};
|
|
2071
|
+
for (const module of modulesForType) reducers[module.version ?? 1] = module.reducer;
|
|
2072
|
+
const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
2073
|
+
let upgradeManifest;
|
|
2074
|
+
if (registry) try {
|
|
2075
|
+
upgradeManifest = registry.getUpgradeManifest(documentType);
|
|
2076
|
+
} catch {}
|
|
2077
|
+
return baseLoadFromInputVersioned(path, {
|
|
2078
|
+
reducers,
|
|
2079
|
+
upgradeManifest
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2082
|
+
async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor, documentModelVersion) {
|
|
2083
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2084
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create documents");
|
|
2085
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
2086
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2087
|
+
let documentModelModule;
|
|
2088
|
+
if (documentModelVersion !== void 0) {
|
|
2089
|
+
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
2090
|
+
const module = documentModelModules.find((m) => m.documentModel.global.id === documentType && (m.version ?? 1) === documentModelVersion);
|
|
2091
|
+
if (!module) throw new Error(`Document model not found for type: ${documentType} with version: ${documentModelVersion}`);
|
|
2092
|
+
documentModelModule = module;
|
|
2093
|
+
} else documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
2094
|
+
const newDocument = document ?? documentModelModule.utils.createDocument();
|
|
2095
|
+
if (!document) newDocument.state.document.version = documentModelModule.version ?? 1;
|
|
2096
|
+
newDocument.header.name = name;
|
|
2097
|
+
if (preferredEditor) newDocument.header.meta = {
|
|
2098
|
+
...newDocument.header.meta,
|
|
2099
|
+
preferredEditor
|
|
2100
|
+
};
|
|
2101
|
+
let newDoc;
|
|
1917
2102
|
try {
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
return error_;
|
|
2103
|
+
newDoc = await reactorClient.drives.addFile(driveId, newDocument, parentFolder);
|
|
2104
|
+
} catch (e) {
|
|
2105
|
+
logger.error("Error adding document: @error", e);
|
|
2106
|
+
throw new Error("There was an error adding document", { cause: e });
|
|
1923
2107
|
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2108
|
+
return {
|
|
2109
|
+
id: newDoc.header.id,
|
|
2110
|
+
name: newDoc.header.name,
|
|
2111
|
+
documentType,
|
|
2112
|
+
parentFolder: parentFolder ?? null,
|
|
2113
|
+
kind: "file"
|
|
2114
|
+
};
|
|
2115
|
+
}
|
|
2116
|
+
/**
|
|
2117
|
+
* How many ids an import will try before giving up. The check before the create
|
|
2118
|
+
* catches an id that is already taken; this bound covers the window between the
|
|
2119
|
+
* two, where a create can still lose to a claim made in the meantime.
|
|
2120
|
+
*/
|
|
2121
|
+
const IMPORT_ID_ATTEMPTS = 3;
|
|
2122
|
+
/** True when this error, or anything it wraps, is a taken document id. */
|
|
2123
|
+
function isDocumentAlreadyExists(error) {
|
|
2124
|
+
let current = error;
|
|
2125
|
+
while (current instanceof Error) {
|
|
2126
|
+
if (current.name === "DocumentAlreadyExistsError") return true;
|
|
2127
|
+
current = current.cause;
|
|
2128
|
+
}
|
|
2129
|
+
return false;
|
|
2130
|
+
}
|
|
2131
|
+
/**
|
|
2132
|
+
* Creates the imported document under an id that is free, retrying on a
|
|
2133
|
+
* collision.
|
|
2134
|
+
*
|
|
2135
|
+
* The check cannot stand on its own: it answers for the moment it ran, and the
|
|
2136
|
+
* create that follows can still land on an id claimed in between. The store
|
|
2137
|
+
* rejects that create as DocumentAlreadyExistsError, which is not retryable
|
|
2138
|
+
* under the same id and is resolved by minting another one. A create that
|
|
2139
|
+
* fails leaves the drive untouched, so a retry has nothing to clean up.
|
|
2140
|
+
*/
|
|
2141
|
+
async function createImportedDocument(reactor, document, driveId, name, parentFolder) {
|
|
2142
|
+
let documentId = await reactor.isDocumentIdTaken(document.header.id) ? generateId() : document.header.id;
|
|
2143
|
+
for (let attempt = 1;; attempt++) {
|
|
2144
|
+
const header = createPresignedHeader(documentId, document.header.documentType);
|
|
2145
|
+
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
2146
|
+
header.meta = document.header.meta;
|
|
2147
|
+
header.name = name || document.header.name;
|
|
2148
|
+
const initialDocument = {
|
|
2149
|
+
...document,
|
|
2150
|
+
header,
|
|
2151
|
+
state: document.initialState,
|
|
2152
|
+
operations: Object.keys(document.operations).reduce((acc, key) => {
|
|
2153
|
+
acc[key] = [];
|
|
2154
|
+
return acc;
|
|
2155
|
+
}, {})
|
|
2156
|
+
};
|
|
2157
|
+
try {
|
|
2158
|
+
const fileNode = await addDocument(driveId, name || document.header.name, document.header.documentType, parentFolder, initialDocument, documentId, document.header.meta?.preferredEditor);
|
|
2159
|
+
if (!fileNode) throw new Error("There was an error adding file");
|
|
2160
|
+
return {
|
|
2161
|
+
documentId,
|
|
2162
|
+
fileNode
|
|
2163
|
+
};
|
|
2164
|
+
} catch (error) {
|
|
2165
|
+
if (!isDocumentAlreadyExists(error) || attempt === IMPORT_ID_ATTEMPTS) throw error;
|
|
2166
|
+
logger.warn(`Document id ${documentId} was taken between the check and the create; importing under a new id`);
|
|
2167
|
+
documentId = generateId();
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
async function addFileWithProgress(file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict) {
|
|
2172
|
+
logger.verbose(`addFileWithProgress(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
2173
|
+
const reactor = window.ph?.reactorClientModule?.client;
|
|
2174
|
+
if (!reactor) {
|
|
2175
|
+
onProgress?.({
|
|
2176
|
+
stage: "failed",
|
|
2177
|
+
progress: 100,
|
|
2178
|
+
error: "ReactorClient not initialized"
|
|
2179
|
+
});
|
|
2180
|
+
throw new Error("ReactorClient not initialized");
|
|
2181
|
+
}
|
|
2182
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2183
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create files");
|
|
1935
2184
|
try {
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2185
|
+
onProgress?.({
|
|
2186
|
+
stage: "loading",
|
|
2187
|
+
progress: 0
|
|
2188
|
+
});
|
|
2189
|
+
let document;
|
|
2190
|
+
try {
|
|
2191
|
+
document = await loadFile(file);
|
|
2192
|
+
} catch (loadError) {
|
|
2193
|
+
if (UnsupportedDocumentModelVersionError.isError(loadError)) {
|
|
2194
|
+
showPHModal({
|
|
2195
|
+
type: "documentVersionUnsupported",
|
|
2196
|
+
documentType: loadError.documentType,
|
|
2197
|
+
requiredVersion: loadError.requiredVersion,
|
|
2198
|
+
availableVersions: loadError.availableVersions
|
|
2199
|
+
});
|
|
2200
|
+
onProgress?.({
|
|
2201
|
+
stage: "failed",
|
|
2202
|
+
progress: 100,
|
|
2203
|
+
error: loadError.message
|
|
2204
|
+
});
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
const discoveryService = window.ph?.packageDiscoveryService;
|
|
2208
|
+
if (discoveryService && DocumentModelNotFoundError.isError(loadError)) {
|
|
2209
|
+
retryAfterDiscovery(discoveryService, loadError.documentType, file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict).catch((retryError) => {
|
|
2210
|
+
logger.error("Import retry after discovery failed: @error", retryError);
|
|
2211
|
+
onProgress?.({
|
|
2212
|
+
stage: "failed",
|
|
2213
|
+
progress: 100,
|
|
2214
|
+
error: retryError instanceof Error ? retryError.message : String(retryError)
|
|
2215
|
+
});
|
|
2216
|
+
});
|
|
2217
|
+
return;
|
|
2218
|
+
}
|
|
2219
|
+
throw loadError;
|
|
2220
|
+
}
|
|
2221
|
+
const duplicateCheck = await isDocumentInLocation(reactor, document, driveId, parentFolder);
|
|
2222
|
+
if (duplicateCheck.isDuplicate && !resolveConflict) {
|
|
2223
|
+
onProgress?.({
|
|
2224
|
+
stage: "conflict",
|
|
2225
|
+
progress: 0,
|
|
2226
|
+
duplicateType: duplicateCheck.duplicateType
|
|
2227
|
+
});
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
const documentType = getDocumentTypeIcon(document);
|
|
2231
|
+
if (documentType) onProgress?.({
|
|
2232
|
+
stage: "loading",
|
|
2233
|
+
progress: 10,
|
|
2234
|
+
documentType
|
|
2235
|
+
});
|
|
2236
|
+
else onProgress?.({
|
|
2237
|
+
stage: "loading",
|
|
2238
|
+
progress: 10
|
|
2239
|
+
});
|
|
2240
|
+
if (!isDocumentTypeSupported(document.header.documentType, documentTypes)) {
|
|
2241
|
+
onProgress?.({
|
|
2242
|
+
stage: "unsupported-document-type",
|
|
2243
|
+
progress: 100,
|
|
2244
|
+
error: `Document type ${document.header.documentType} is not supported`
|
|
2245
|
+
});
|
|
2246
|
+
throw new UnsupportedDocumentTypeError(document.header.documentType);
|
|
2247
|
+
}
|
|
2248
|
+
await reactor.getDocumentModelModule(document.header.documentType);
|
|
2249
|
+
onProgress?.({
|
|
2250
|
+
stage: "initializing",
|
|
2251
|
+
progress: 10
|
|
2252
|
+
});
|
|
2253
|
+
const created = await createImportedDocument(reactor, document, driveId, name, parentFolder);
|
|
2254
|
+
const documentId = created.documentId;
|
|
2255
|
+
const fileNode = created.fileNode;
|
|
2256
|
+
onProgress?.({
|
|
2257
|
+
stage: "initializing",
|
|
2258
|
+
progress: 20
|
|
2259
|
+
});
|
|
2260
|
+
await reactor.get(documentId);
|
|
2261
|
+
console.log("Document created, starting upload of operations");
|
|
2262
|
+
const segments = splitAtUpgradeBoundaries(document.operations);
|
|
2263
|
+
const totalOperations = segments.reduce((total, segment) => total + countOperations(segment.operations), 0);
|
|
2264
|
+
let uploadedBefore = 0;
|
|
2265
|
+
for (const segment of segments) {
|
|
2266
|
+
await uploadOperations(documentId, segment.operations, queueOperations, { onProgress: (uploadProgress) => {
|
|
2267
|
+
if (uploadProgress.uploadedOperations === void 0) return;
|
|
2268
|
+
const uploaded = uploadedBefore + uploadProgress.uploadedOperations;
|
|
2269
|
+
const uploadPercent = totalOperations > 0 ? uploaded / totalOperations : 0;
|
|
2270
|
+
onProgress?.({
|
|
2271
|
+
stage: "uploading",
|
|
2272
|
+
progress: 20 + Math.round(uploadPercent * 80),
|
|
2273
|
+
totalOperations,
|
|
2274
|
+
uploadedOperations: uploaded
|
|
2275
|
+
});
|
|
2276
|
+
} });
|
|
2277
|
+
uploadedBefore += countOperations(segment.operations);
|
|
2278
|
+
if (segment.upgradeTo !== void 0) await reactor.upgradeDocument(documentId, segment.upgradeTo);
|
|
2279
|
+
}
|
|
2280
|
+
onProgress?.({
|
|
2281
|
+
stage: "complete",
|
|
2282
|
+
progress: 100,
|
|
2283
|
+
fileNode
|
|
2284
|
+
});
|
|
2285
|
+
return fileNode;
|
|
2286
|
+
} catch (error) {
|
|
2287
|
+
if (!UnsupportedDocumentTypeError.isError(error)) {
|
|
2288
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
2289
|
+
onProgress?.({
|
|
2290
|
+
stage: "failed",
|
|
2291
|
+
progress: 100,
|
|
2292
|
+
error: errorMessage
|
|
2293
|
+
});
|
|
2294
|
+
}
|
|
2295
|
+
throw error;
|
|
1939
2296
|
}
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
|
|
2297
|
+
}
|
|
2298
|
+
async function retryAfterDiscovery(discoveryService, documentType, file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict) {
|
|
2299
|
+
if (!discoveryService) return;
|
|
1943
2300
|
try {
|
|
1944
|
-
|
|
2301
|
+
await discoveryService.load(documentType);
|
|
1945
2302
|
} catch {
|
|
1946
|
-
|
|
2303
|
+
onProgress?.({
|
|
2304
|
+
stage: "unsupported-document-type",
|
|
2305
|
+
progress: 100,
|
|
2306
|
+
error: `Document type ${documentType} is not supported`
|
|
2307
|
+
});
|
|
2308
|
+
return;
|
|
1947
2309
|
}
|
|
2310
|
+
await addFileWithProgress(file, driveId, name, parentFolder, onProgress, documentTypes, resolveConflict);
|
|
2311
|
+
}
|
|
2312
|
+
async function addFolder$1(driveId, name, parentFolder) {
|
|
2313
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2314
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create folders");
|
|
2315
|
+
const reactorClient = window.ph?.reactorClient;
|
|
2316
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2317
|
+
await reactorClient.get(driveId);
|
|
2318
|
+
const folderId = generateId();
|
|
2319
|
+
const node = (await reactorClient.execute(driveId, "main", [addFolder({
|
|
2320
|
+
id: folderId,
|
|
2321
|
+
name,
|
|
2322
|
+
parentFolder
|
|
2323
|
+
})])).state.global.nodes.find((node) => node.id === folderId);
|
|
2324
|
+
if (!node || !isFolderNode(node)) throw new Error("There was an error adding folder");
|
|
2325
|
+
return node;
|
|
2326
|
+
}
|
|
2327
|
+
async function renameNode(driveId, nodeId, name) {
|
|
2328
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2329
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
2330
|
+
const reactorClient = window.ph?.reactorClient;
|
|
2331
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2332
|
+
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
2333
|
+
const node = (await reactorClient.execute(driveId, "main", [updateNode({
|
|
2334
|
+
id: nodeId,
|
|
2335
|
+
name
|
|
2336
|
+
})])).state.global.nodes.find((n) => n.id === nodeId);
|
|
2337
|
+
if (!node) throw new Error("There was an error renaming node in the drive");
|
|
2338
|
+
return node;
|
|
2339
|
+
}
|
|
2340
|
+
async function renameDriveNode(driveId, nodeId, name) {
|
|
2341
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2342
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
2343
|
+
const reactorClient = window.ph?.reactorClient;
|
|
2344
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2345
|
+
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
2346
|
+
await reactorClient.execute(driveId, "main", [updateNode({
|
|
2347
|
+
id: nodeId,
|
|
2348
|
+
name
|
|
2349
|
+
})]);
|
|
2350
|
+
return (await reactorClient.get(driveId)).state.global.nodes.find((n) => n.id === nodeId);
|
|
2351
|
+
}
|
|
2352
|
+
async function moveNodeById(args) {
|
|
2353
|
+
const { driveId, srcId, targetId } = args;
|
|
2354
|
+
if (!driveId || !srcId) return;
|
|
2355
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2356
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
2357
|
+
const reactorClient = window.ph?.reactorClient;
|
|
2358
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2359
|
+
const targetParentFolder = t$3(targetId, [e$3(e$4), e$6(void 0)], [t(driveId), e$6(void 0)], e$6(targetId));
|
|
2360
|
+
if (t(targetParentFolder, srcId)) return;
|
|
2361
|
+
return await reactorClient.execute(driveId, "main", [moveNode({
|
|
2362
|
+
srcFolder: srcId,
|
|
2363
|
+
targetParentFolder
|
|
2364
|
+
})]);
|
|
2365
|
+
}
|
|
2366
|
+
async function moveNode$1(driveId, src, target) {
|
|
2367
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2368
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
2369
|
+
const reactorClient = window.ph?.reactorClient;
|
|
2370
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2371
|
+
return await reactorClient.execute(driveId, "main", [moveNode({
|
|
2372
|
+
srcFolder: src.id,
|
|
2373
|
+
targetParentFolder: target?.id
|
|
2374
|
+
})]);
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Duplicates a document under a new id using version-aware replay.
|
|
2378
|
+
* Falls back gracefully when no upgrade manifest is registered for the document type.
|
|
2379
|
+
*/
|
|
2380
|
+
async function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
2381
|
+
const documentType = document.header.documentType;
|
|
2382
|
+
const { results: allModules } = await reactor.getDocumentModelModules();
|
|
2383
|
+
const modulesForType = allModules.filter((m) => m.documentModel.global.id === documentType);
|
|
2384
|
+
const reducers = {};
|
|
2385
|
+
for (const m of modulesForType) reducers[m.version ?? 1] = m.reducer;
|
|
2386
|
+
if (Object.keys(reducers).length === 0) throw new Error(`Document model module not found for type: ${documentType}`);
|
|
2387
|
+
const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
2388
|
+
let upgradeManifest;
|
|
2389
|
+
if (registry) try {
|
|
2390
|
+
upgradeManifest = registry.getUpgradeManifest(documentType);
|
|
2391
|
+
} catch {}
|
|
2392
|
+
const config = {
|
|
2393
|
+
reducers,
|
|
2394
|
+
upgradeManifest
|
|
2395
|
+
};
|
|
2396
|
+
const header = createPresignedHeader(newId, documentType);
|
|
2397
|
+
const duplicated = replayDocumentVersioned(document.initialState, document.operations, config, header);
|
|
2398
|
+
assertAuthPreservedOnDuplicate(document.header.id, document.state.auth, duplicated.state.auth);
|
|
2399
|
+
return duplicated;
|
|
2400
|
+
}
|
|
2401
|
+
async function copyNode$1(driveId, src, target) {
|
|
2402
|
+
const reactor = window.ph?.reactorClientModule?.client;
|
|
2403
|
+
if (!reactor) return;
|
|
2404
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2405
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to copy documents");
|
|
2406
|
+
const drive = await reactor.get(driveId);
|
|
2407
|
+
const copyNodesInput = generateNodesCopy({
|
|
2408
|
+
srcId: src.id,
|
|
2409
|
+
targetParentFolder: target?.id,
|
|
2410
|
+
targetName: src.name
|
|
2411
|
+
}, () => generateId(), drive.state.global.nodes);
|
|
2412
|
+
const resolvedNamesMap = /* @__PURE__ */ new Map();
|
|
2413
|
+
for (const copyNodeInput of copyNodesInput) {
|
|
2414
|
+
const node = drive.state.global.nodes.find((n) => n.id === copyNodeInput.srcId);
|
|
2415
|
+
if (node) {
|
|
2416
|
+
const resolvedName = handleTargetNameCollisions({
|
|
2417
|
+
nodes: drive.state.global.nodes,
|
|
2418
|
+
srcName: copyNodeInput.targetName || node.name,
|
|
2419
|
+
srcKind: isFileNode(node) ? "file" : "folder",
|
|
2420
|
+
targetParentFolder: copyNodeInput.targetParentFolder || null
|
|
2421
|
+
});
|
|
2422
|
+
resolvedNamesMap.set(copyNodeInput.targetId, resolvedName);
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
const fileNodesToCopy = copyNodesInput.filter((copyNodeInput) => {
|
|
2426
|
+
const node = drive.state.global.nodes.find((node) => node.id === copyNodeInput.srcId);
|
|
2427
|
+
return node !== void 0 && isFileNode(node);
|
|
2428
|
+
});
|
|
2429
|
+
for (const fileNodeToCopy of fileNodesToCopy) try {
|
|
2430
|
+
const duplicatedDocument = await _duplicateDocument(reactor, await reactor.get(fileNodeToCopy.srcId), fileNodeToCopy.targetId);
|
|
2431
|
+
const resolvedName = resolvedNamesMap.get(fileNodeToCopy.targetId);
|
|
2432
|
+
if (resolvedName) duplicatedDocument.header.name = resolvedName;
|
|
2433
|
+
await reactor.drives.addFile(driveId, duplicatedDocument, target?.id);
|
|
2434
|
+
} catch (e) {
|
|
2435
|
+
logger.error(`Error copying document ${fileNodeToCopy.srcId}: ${String(e)}`);
|
|
2436
|
+
}
|
|
2437
|
+
return await queueActions(drive, copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput)));
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* The operation selection of `GetDocumentOperations`, lifted into a fragment so
|
|
2441
|
+
* the write path can reuse `remoteOperationToLocal` on the items it selects.
|
|
2442
|
+
*/
|
|
2443
|
+
const ReactorOperationFieldsFragmentDoc = import_main.gql`
|
|
2444
|
+
fragment ReactorOperationFields on ReactorOperation {
|
|
2445
|
+
index
|
|
2446
|
+
timestampUtcMs
|
|
2447
|
+
hash
|
|
2448
|
+
skip
|
|
2449
|
+
error
|
|
2450
|
+
deniedReason
|
|
2451
|
+
id
|
|
2452
|
+
action {
|
|
2453
|
+
id
|
|
2454
|
+
type
|
|
2455
|
+
timestampUtcMs
|
|
2456
|
+
input
|
|
2457
|
+
scope
|
|
2458
|
+
context {
|
|
2459
|
+
signer {
|
|
2460
|
+
user {
|
|
2461
|
+
address
|
|
2462
|
+
networkId
|
|
2463
|
+
chainId
|
|
2464
|
+
}
|
|
2465
|
+
app {
|
|
2466
|
+
name
|
|
2467
|
+
key
|
|
2468
|
+
}
|
|
2469
|
+
signatures
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
`;
|
|
2475
|
+
import_main.gql`
|
|
2476
|
+
mutation MutateDocumentWithOperations(
|
|
2477
|
+
$documentIdentifier: String!
|
|
2478
|
+
$actions: [ActionInput!]!
|
|
2479
|
+
$sinceRevision: Int
|
|
2480
|
+
$scopes: [String!]
|
|
2481
|
+
$branch: String
|
|
2482
|
+
) {
|
|
2483
|
+
mutateDocument: execute(
|
|
2484
|
+
documentIdentifier: $documentIdentifier
|
|
2485
|
+
actions: $actions
|
|
2486
|
+
branch: $branch
|
|
2487
|
+
) {
|
|
2488
|
+
...PHDocumentFields
|
|
2489
|
+
operations(
|
|
2490
|
+
filter: {
|
|
2491
|
+
sinceRevision: $sinceRevision
|
|
2492
|
+
scopes: $scopes
|
|
2493
|
+
branch: $branch
|
|
2494
|
+
}
|
|
2495
|
+
) {
|
|
2496
|
+
items {
|
|
2497
|
+
...ReactorOperationFields
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
${PhDocumentFieldsFragmentDoc}
|
|
2503
|
+
${ReactorOperationFieldsFragmentDoc}
|
|
2504
|
+
`;
|
|
2505
|
+
DocumentChangeType.Created, DOCUMENT_CHANGE_TYPE.Created, DocumentChangeType.Deleted, DOCUMENT_CHANGE_TYPE.Deleted, DocumentChangeType.Updated, DOCUMENT_CHANGE_TYPE.Updated, DocumentChangeType.ParentAdded, DOCUMENT_CHANGE_TYPE.ParentAdded, DocumentChangeType.ParentRemoved, DOCUMENT_CHANGE_TYPE.ParentRemoved, DocumentChangeType.ChildAdded, DOCUMENT_CHANGE_TYPE.ChildAdded, DocumentChangeType.ChildRemoved, DOCUMENT_CHANGE_TYPE.ChildRemoved;
|
|
2506
|
+
PropagationMode.Cascade, PropagationMode.Orphan;
|
|
2507
|
+
const isExternalControlsEnabledEventFunctions = makePHEventFunctions("isExternalControlsEnabled");
|
|
2508
|
+
/** Sets whether external controls are enabled for a given editor. */
|
|
2509
|
+
const setIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.setValue;
|
|
2510
|
+
/** Gets whether external controls are enabled for a given editor. */
|
|
2511
|
+
const useIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.useValue;
|
|
2512
|
+
isExternalControlsEnabledEventFunctions.addEventHandler;
|
|
2513
|
+
const isDragAndDropEnabledEventFunctions = makePHEventFunctions("isDragAndDropEnabled");
|
|
2514
|
+
/** Sets whether drag and drop is enabled for a given app. */
|
|
2515
|
+
const setIsDragAndDropEnabled = isDragAndDropEnabledEventFunctions.setValue;
|
|
2516
|
+
/** Gets whether drag and drop is enabled for a given app. */
|
|
2517
|
+
const useIsDragAndDropEnabled = isDragAndDropEnabledEventFunctions.useValue;
|
|
2518
|
+
isDragAndDropEnabledEventFunctions.addEventHandler;
|
|
2519
|
+
const allowedDocumentTypesEventFunctions = makePHEventFunctions("allowedDocumentTypes");
|
|
2520
|
+
/** Sets the allowed document types for a given app. */
|
|
2521
|
+
const setAllowedDocumentTypes = allowedDocumentTypesEventFunctions.setValue;
|
|
2522
|
+
/** Defines the document types a drive supports.
|
|
2523
|
+
*
|
|
2524
|
+
* Defaults to all of the document types registered in the reactor.
|
|
2525
|
+
*/
|
|
2526
|
+
function useAllowedDocumentTypes() {
|
|
2527
|
+
return allowedDocumentTypesEventFunctions.useValue();
|
|
2528
|
+
}
|
|
2529
|
+
allowedDocumentTypesEventFunctions.addEventHandler;
|
|
2530
|
+
const phAppConfigSetters = {
|
|
2531
|
+
allowedDocumentTypes: setAllowedDocumentTypes,
|
|
2532
|
+
isDragAndDropEnabled: setIsDragAndDropEnabled
|
|
1948
2533
|
};
|
|
1949
|
-
const
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
const recurseException = (error, parents, shallow) => {
|
|
1954
|
-
if (parents.includes(error)) return;
|
|
1955
|
-
const recurse = shallow ? identity : (innerError) => recurseException(innerError, [...parents, error], shallow);
|
|
1956
|
-
const errorA = createError(error);
|
|
1957
|
-
normalizeProps(errorA, recurse);
|
|
1958
|
-
return errorA;
|
|
1959
|
-
};
|
|
1960
|
-
const identity = (error) => error;
|
|
1961
|
-
const normalizeProps = (error, recurse) => {
|
|
1962
|
-
normalizeName(error);
|
|
1963
|
-
normalizeMessage(error);
|
|
1964
|
-
normalizeStack(error);
|
|
1965
|
-
normalizeCause(error, recurse);
|
|
1966
|
-
normalizeAggregate(error, recurse);
|
|
1967
|
-
normalizeDescriptors(error);
|
|
1968
|
-
};
|
|
1969
|
-
const normalizeName = (error) => {
|
|
1970
|
-
if (isDefinedString(error.name)) return;
|
|
1971
|
-
const prototypeName = Object.getPrototypeOf(error).name;
|
|
1972
|
-
setErrorProperty(error, "name", isDefinedString(prototypeName) ? prototypeName : error.constructor.name);
|
|
1973
|
-
};
|
|
1974
|
-
const normalizeMessage = (error) => {
|
|
1975
|
-
if (!isDefinedString(error.message)) setErrorProperty(error, "message", "");
|
|
1976
|
-
};
|
|
1977
|
-
const normalizeStack = (error) => {
|
|
1978
|
-
if (!isDefinedString(error.stack)) setStack(error);
|
|
1979
|
-
};
|
|
1980
|
-
const isDefinedString = (value) => typeof value === "string" && value !== "";
|
|
1981
|
-
//#endregion
|
|
1982
|
-
//#region ../reactor-browser/dist/index.js
|
|
1983
|
-
var import_lz_string = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1984
|
-
var LZString = (function() {
|
|
1985
|
-
var f = String.fromCharCode;
|
|
1986
|
-
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
1987
|
-
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
|
1988
|
-
var baseReverseDic = {};
|
|
1989
|
-
function getBaseValue(alphabet, character) {
|
|
1990
|
-
if (!baseReverseDic[alphabet]) {
|
|
1991
|
-
baseReverseDic[alphabet] = {};
|
|
1992
|
-
for (var i = 0; i < alphabet.length; i++) baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
1993
|
-
}
|
|
1994
|
-
return baseReverseDic[alphabet][character];
|
|
1995
|
-
}
|
|
1996
|
-
var LZString = {
|
|
1997
|
-
compressToBase64: function(input) {
|
|
1998
|
-
if (input == null) return "";
|
|
1999
|
-
var res = LZString._compress(input, 6, function(a) {
|
|
2000
|
-
return keyStrBase64.charAt(a);
|
|
2001
|
-
});
|
|
2002
|
-
switch (res.length % 4) {
|
|
2003
|
-
default:
|
|
2004
|
-
case 0: return res;
|
|
2005
|
-
case 1: return res + "===";
|
|
2006
|
-
case 2: return res + "==";
|
|
2007
|
-
case 3: return res + "=";
|
|
2008
|
-
}
|
|
2009
|
-
},
|
|
2010
|
-
decompressFromBase64: function(input) {
|
|
2011
|
-
if (input == null) return "";
|
|
2012
|
-
if (input == "") return null;
|
|
2013
|
-
return LZString._decompress(input.length, 32, function(index) {
|
|
2014
|
-
return getBaseValue(keyStrBase64, input.charAt(index));
|
|
2015
|
-
});
|
|
2016
|
-
},
|
|
2017
|
-
compressToUTF16: function(input) {
|
|
2018
|
-
if (input == null) return "";
|
|
2019
|
-
return LZString._compress(input, 15, function(a) {
|
|
2020
|
-
return f(a + 32);
|
|
2021
|
-
}) + " ";
|
|
2022
|
-
},
|
|
2023
|
-
decompressFromUTF16: function(compressed) {
|
|
2024
|
-
if (compressed == null) return "";
|
|
2025
|
-
if (compressed == "") return null;
|
|
2026
|
-
return LZString._decompress(compressed.length, 16384, function(index) {
|
|
2027
|
-
return compressed.charCodeAt(index) - 32;
|
|
2028
|
-
});
|
|
2029
|
-
},
|
|
2030
|
-
compressToUint8Array: function(uncompressed) {
|
|
2031
|
-
var compressed = LZString.compress(uncompressed);
|
|
2032
|
-
var buf = new Uint8Array(compressed.length * 2);
|
|
2033
|
-
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
|
|
2034
|
-
var current_value = compressed.charCodeAt(i);
|
|
2035
|
-
buf[i * 2] = current_value >>> 8;
|
|
2036
|
-
buf[i * 2 + 1] = current_value % 256;
|
|
2037
|
-
}
|
|
2038
|
-
return buf;
|
|
2039
|
-
},
|
|
2040
|
-
decompressFromUint8Array: function(compressed) {
|
|
2041
|
-
if (compressed === null || compressed === void 0) return LZString.decompress(compressed);
|
|
2042
|
-
else {
|
|
2043
|
-
var buf = new Array(compressed.length / 2);
|
|
2044
|
-
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
|
|
2045
|
-
var result = [];
|
|
2046
|
-
buf.forEach(function(c) {
|
|
2047
|
-
result.push(f(c));
|
|
2048
|
-
});
|
|
2049
|
-
return LZString.decompress(result.join(""));
|
|
2050
|
-
}
|
|
2051
|
-
},
|
|
2052
|
-
compressToEncodedURIComponent: function(input) {
|
|
2053
|
-
if (input == null) return "";
|
|
2054
|
-
return LZString._compress(input, 6, function(a) {
|
|
2055
|
-
return keyStrUriSafe.charAt(a);
|
|
2056
|
-
});
|
|
2057
|
-
},
|
|
2058
|
-
decompressFromEncodedURIComponent: function(input) {
|
|
2059
|
-
if (input == null) return "";
|
|
2060
|
-
if (input == "") return null;
|
|
2061
|
-
input = input.replace(/ /g, "+");
|
|
2062
|
-
return LZString._decompress(input.length, 32, function(index) {
|
|
2063
|
-
return getBaseValue(keyStrUriSafe, input.charAt(index));
|
|
2064
|
-
});
|
|
2065
|
-
},
|
|
2066
|
-
compress: function(uncompressed) {
|
|
2067
|
-
return LZString._compress(uncompressed, 16, function(a) {
|
|
2068
|
-
return f(a);
|
|
2069
|
-
});
|
|
2070
|
-
},
|
|
2071
|
-
_compress: function(uncompressed, bitsPerChar, getCharFromInt) {
|
|
2072
|
-
if (uncompressed == null) return "";
|
|
2073
|
-
var i, value, context_dictionary = {}, context_dictionaryToCreate = {}, context_c = "", context_wc = "", context_w = "", context_enlargeIn = 2, context_dictSize = 3, context_numBits = 2, context_data = [], context_data_val = 0, context_data_position = 0, ii;
|
|
2074
|
-
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
2075
|
-
context_c = uncompressed.charAt(ii);
|
|
2076
|
-
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
2077
|
-
context_dictionary[context_c] = context_dictSize++;
|
|
2078
|
-
context_dictionaryToCreate[context_c] = true;
|
|
2079
|
-
}
|
|
2080
|
-
context_wc = context_w + context_c;
|
|
2081
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) context_w = context_wc;
|
|
2082
|
-
else {
|
|
2083
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
2084
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
2085
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2086
|
-
context_data_val = context_data_val << 1;
|
|
2087
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2088
|
-
context_data_position = 0;
|
|
2089
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2090
|
-
context_data_val = 0;
|
|
2091
|
-
} else context_data_position++;
|
|
2092
|
-
}
|
|
2093
|
-
value = context_w.charCodeAt(0);
|
|
2094
|
-
for (i = 0; i < 8; i++) {
|
|
2095
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2096
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2097
|
-
context_data_position = 0;
|
|
2098
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2099
|
-
context_data_val = 0;
|
|
2100
|
-
} else context_data_position++;
|
|
2101
|
-
value = value >> 1;
|
|
2102
|
-
}
|
|
2103
|
-
} else {
|
|
2104
|
-
value = 1;
|
|
2105
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2106
|
-
context_data_val = context_data_val << 1 | value;
|
|
2107
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2108
|
-
context_data_position = 0;
|
|
2109
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2110
|
-
context_data_val = 0;
|
|
2111
|
-
} else context_data_position++;
|
|
2112
|
-
value = 0;
|
|
2113
|
-
}
|
|
2114
|
-
value = context_w.charCodeAt(0);
|
|
2115
|
-
for (i = 0; i < 16; i++) {
|
|
2116
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2117
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2118
|
-
context_data_position = 0;
|
|
2119
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2120
|
-
context_data_val = 0;
|
|
2121
|
-
} else context_data_position++;
|
|
2122
|
-
value = value >> 1;
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
context_enlargeIn--;
|
|
2126
|
-
if (context_enlargeIn == 0) {
|
|
2127
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2128
|
-
context_numBits++;
|
|
2129
|
-
}
|
|
2130
|
-
delete context_dictionaryToCreate[context_w];
|
|
2131
|
-
} else {
|
|
2132
|
-
value = context_dictionary[context_w];
|
|
2133
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2134
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2135
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2136
|
-
context_data_position = 0;
|
|
2137
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2138
|
-
context_data_val = 0;
|
|
2139
|
-
} else context_data_position++;
|
|
2140
|
-
value = value >> 1;
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
context_enlargeIn--;
|
|
2144
|
-
if (context_enlargeIn == 0) {
|
|
2145
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2146
|
-
context_numBits++;
|
|
2147
|
-
}
|
|
2148
|
-
context_dictionary[context_wc] = context_dictSize++;
|
|
2149
|
-
context_w = String(context_c);
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
if (context_w !== "") {
|
|
2153
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
2154
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
2155
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2156
|
-
context_data_val = context_data_val << 1;
|
|
2157
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2158
|
-
context_data_position = 0;
|
|
2159
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2160
|
-
context_data_val = 0;
|
|
2161
|
-
} else context_data_position++;
|
|
2162
|
-
}
|
|
2163
|
-
value = context_w.charCodeAt(0);
|
|
2164
|
-
for (i = 0; i < 8; i++) {
|
|
2165
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2166
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2167
|
-
context_data_position = 0;
|
|
2168
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2169
|
-
context_data_val = 0;
|
|
2170
|
-
} else context_data_position++;
|
|
2171
|
-
value = value >> 1;
|
|
2172
|
-
}
|
|
2173
|
-
} else {
|
|
2174
|
-
value = 1;
|
|
2175
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2176
|
-
context_data_val = context_data_val << 1 | value;
|
|
2177
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2178
|
-
context_data_position = 0;
|
|
2179
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2180
|
-
context_data_val = 0;
|
|
2181
|
-
} else context_data_position++;
|
|
2182
|
-
value = 0;
|
|
2183
|
-
}
|
|
2184
|
-
value = context_w.charCodeAt(0);
|
|
2185
|
-
for (i = 0; i < 16; i++) {
|
|
2186
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2187
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2188
|
-
context_data_position = 0;
|
|
2189
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2190
|
-
context_data_val = 0;
|
|
2191
|
-
} else context_data_position++;
|
|
2192
|
-
value = value >> 1;
|
|
2193
|
-
}
|
|
2194
|
-
}
|
|
2195
|
-
context_enlargeIn--;
|
|
2196
|
-
if (context_enlargeIn == 0) {
|
|
2197
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2198
|
-
context_numBits++;
|
|
2199
|
-
}
|
|
2200
|
-
delete context_dictionaryToCreate[context_w];
|
|
2201
|
-
} else {
|
|
2202
|
-
value = context_dictionary[context_w];
|
|
2203
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2204
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2205
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2206
|
-
context_data_position = 0;
|
|
2207
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2208
|
-
context_data_val = 0;
|
|
2209
|
-
} else context_data_position++;
|
|
2210
|
-
value = value >> 1;
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
context_enlargeIn--;
|
|
2214
|
-
if (context_enlargeIn == 0) {
|
|
2215
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
2216
|
-
context_numBits++;
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
value = 2;
|
|
2220
|
-
for (i = 0; i < context_numBits; i++) {
|
|
2221
|
-
context_data_val = context_data_val << 1 | value & 1;
|
|
2222
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2223
|
-
context_data_position = 0;
|
|
2224
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2225
|
-
context_data_val = 0;
|
|
2226
|
-
} else context_data_position++;
|
|
2227
|
-
value = value >> 1;
|
|
2228
|
-
}
|
|
2229
|
-
while (true) {
|
|
2230
|
-
context_data_val = context_data_val << 1;
|
|
2231
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
2232
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
2233
|
-
break;
|
|
2234
|
-
} else context_data_position++;
|
|
2235
|
-
}
|
|
2236
|
-
return context_data.join("");
|
|
2237
|
-
},
|
|
2238
|
-
decompress: function(compressed) {
|
|
2239
|
-
if (compressed == null) return "";
|
|
2240
|
-
if (compressed == "") return null;
|
|
2241
|
-
return LZString._decompress(compressed.length, 32768, function(index) {
|
|
2242
|
-
return compressed.charCodeAt(index);
|
|
2243
|
-
});
|
|
2244
|
-
},
|
|
2245
|
-
_decompress: function(length, resetValue, getNextValue) {
|
|
2246
|
-
var dictionary = [], enlargeIn = 4, dictSize = 4, numBits = 3, entry = "", result = [], i, w, bits, resb, maxpower, power, c, data = {
|
|
2247
|
-
val: getNextValue(0),
|
|
2248
|
-
position: resetValue,
|
|
2249
|
-
index: 1
|
|
2250
|
-
};
|
|
2251
|
-
for (i = 0; i < 3; i += 1) dictionary[i] = i;
|
|
2252
|
-
bits = 0;
|
|
2253
|
-
maxpower = Math.pow(2, 2);
|
|
2254
|
-
power = 1;
|
|
2255
|
-
while (power != maxpower) {
|
|
2256
|
-
resb = data.val & data.position;
|
|
2257
|
-
data.position >>= 1;
|
|
2258
|
-
if (data.position == 0) {
|
|
2259
|
-
data.position = resetValue;
|
|
2260
|
-
data.val = getNextValue(data.index++);
|
|
2261
|
-
}
|
|
2262
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2263
|
-
power <<= 1;
|
|
2264
|
-
}
|
|
2265
|
-
switch (bits) {
|
|
2266
|
-
case 0:
|
|
2267
|
-
bits = 0;
|
|
2268
|
-
maxpower = Math.pow(2, 8);
|
|
2269
|
-
power = 1;
|
|
2270
|
-
while (power != maxpower) {
|
|
2271
|
-
resb = data.val & data.position;
|
|
2272
|
-
data.position >>= 1;
|
|
2273
|
-
if (data.position == 0) {
|
|
2274
|
-
data.position = resetValue;
|
|
2275
|
-
data.val = getNextValue(data.index++);
|
|
2276
|
-
}
|
|
2277
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2278
|
-
power <<= 1;
|
|
2279
|
-
}
|
|
2280
|
-
c = f(bits);
|
|
2281
|
-
break;
|
|
2282
|
-
case 1:
|
|
2283
|
-
bits = 0;
|
|
2284
|
-
maxpower = Math.pow(2, 16);
|
|
2285
|
-
power = 1;
|
|
2286
|
-
while (power != maxpower) {
|
|
2287
|
-
resb = data.val & data.position;
|
|
2288
|
-
data.position >>= 1;
|
|
2289
|
-
if (data.position == 0) {
|
|
2290
|
-
data.position = resetValue;
|
|
2291
|
-
data.val = getNextValue(data.index++);
|
|
2292
|
-
}
|
|
2293
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2294
|
-
power <<= 1;
|
|
2295
|
-
}
|
|
2296
|
-
c = f(bits);
|
|
2297
|
-
break;
|
|
2298
|
-
case 2: return "";
|
|
2299
|
-
}
|
|
2300
|
-
dictionary[3] = c;
|
|
2301
|
-
w = c;
|
|
2302
|
-
result.push(c);
|
|
2303
|
-
while (true) {
|
|
2304
|
-
if (data.index > length) return "";
|
|
2305
|
-
bits = 0;
|
|
2306
|
-
maxpower = Math.pow(2, numBits);
|
|
2307
|
-
power = 1;
|
|
2308
|
-
while (power != maxpower) {
|
|
2309
|
-
resb = data.val & data.position;
|
|
2310
|
-
data.position >>= 1;
|
|
2311
|
-
if (data.position == 0) {
|
|
2312
|
-
data.position = resetValue;
|
|
2313
|
-
data.val = getNextValue(data.index++);
|
|
2314
|
-
}
|
|
2315
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2316
|
-
power <<= 1;
|
|
2317
|
-
}
|
|
2318
|
-
switch (c = bits) {
|
|
2319
|
-
case 0:
|
|
2320
|
-
bits = 0;
|
|
2321
|
-
maxpower = Math.pow(2, 8);
|
|
2322
|
-
power = 1;
|
|
2323
|
-
while (power != maxpower) {
|
|
2324
|
-
resb = data.val & data.position;
|
|
2325
|
-
data.position >>= 1;
|
|
2326
|
-
if (data.position == 0) {
|
|
2327
|
-
data.position = resetValue;
|
|
2328
|
-
data.val = getNextValue(data.index++);
|
|
2329
|
-
}
|
|
2330
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2331
|
-
power <<= 1;
|
|
2332
|
-
}
|
|
2333
|
-
dictionary[dictSize++] = f(bits);
|
|
2334
|
-
c = dictSize - 1;
|
|
2335
|
-
enlargeIn--;
|
|
2336
|
-
break;
|
|
2337
|
-
case 1:
|
|
2338
|
-
bits = 0;
|
|
2339
|
-
maxpower = Math.pow(2, 16);
|
|
2340
|
-
power = 1;
|
|
2341
|
-
while (power != maxpower) {
|
|
2342
|
-
resb = data.val & data.position;
|
|
2343
|
-
data.position >>= 1;
|
|
2344
|
-
if (data.position == 0) {
|
|
2345
|
-
data.position = resetValue;
|
|
2346
|
-
data.val = getNextValue(data.index++);
|
|
2347
|
-
}
|
|
2348
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2349
|
-
power <<= 1;
|
|
2350
|
-
}
|
|
2351
|
-
dictionary[dictSize++] = f(bits);
|
|
2352
|
-
c = dictSize - 1;
|
|
2353
|
-
enlargeIn--;
|
|
2354
|
-
break;
|
|
2355
|
-
case 2: return result.join("");
|
|
2356
|
-
}
|
|
2357
|
-
if (enlargeIn == 0) {
|
|
2358
|
-
enlargeIn = Math.pow(2, numBits);
|
|
2359
|
-
numBits++;
|
|
2360
|
-
}
|
|
2361
|
-
if (dictionary[c]) entry = dictionary[c];
|
|
2362
|
-
else if (c === dictSize) entry = w + w.charAt(0);
|
|
2363
|
-
else return null;
|
|
2364
|
-
result.push(entry);
|
|
2365
|
-
dictionary[dictSize++] = w + entry.charAt(0);
|
|
2366
|
-
enlargeIn--;
|
|
2367
|
-
w = entry;
|
|
2368
|
-
if (enlargeIn == 0) {
|
|
2369
|
-
enlargeIn = Math.pow(2, numBits);
|
|
2370
|
-
numBits++;
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
}
|
|
2374
|
-
};
|
|
2375
|
-
return LZString;
|
|
2376
|
-
})();
|
|
2377
|
-
if (typeof define === "function" && define.amd) define(function() {
|
|
2378
|
-
return LZString;
|
|
2379
|
-
});
|
|
2380
|
-
else if (typeof module !== "undefined" && module != null) module.exports = LZString;
|
|
2381
|
-
else if (typeof angular !== "undefined" && angular != null) angular.module("LZString", []).factory("LZString", function() {
|
|
2382
|
-
return LZString;
|
|
2383
|
-
});
|
|
2384
|
-
})))(), 1);
|
|
2385
|
-
var DocumentModelNotFoundError = class extends Error {
|
|
2386
|
-
documentType;
|
|
2387
|
-
name = "DocumentModelNotFoundError";
|
|
2388
|
-
constructor(documentType) {
|
|
2389
|
-
super(`Document model module for type ${documentType} not found`);
|
|
2390
|
-
this.documentType = documentType;
|
|
2391
|
-
}
|
|
2392
|
-
static isError(error) {
|
|
2393
|
-
return Error.isError(error) && error.name === "DocumentModelNotFoundError";
|
|
2394
|
-
}
|
|
2395
|
-
};
|
|
2396
|
-
var DocumentTypeMismatchError = class extends Error {
|
|
2397
|
-
constructor(documentId, expectedType, actualType) {
|
|
2398
|
-
super(`Document ${documentId} is not of type ${expectedType}. Actual type: ${actualType}`);
|
|
2399
|
-
}
|
|
2400
|
-
};
|
|
2401
|
-
var NoSelectedDocumentError = class extends Error {
|
|
2402
|
-
constructor() {
|
|
2403
|
-
super("There is no selected document. Did you mean to call 'useSelectedDocumentSafe' instead?");
|
|
2404
|
-
}
|
|
2405
|
-
};
|
|
2406
|
-
function getUserPermissions() {
|
|
2407
|
-
const user = window.ph?.renown?.user;
|
|
2408
|
-
const allowList = window.ph?.allowList;
|
|
2409
|
-
if (!allowList) return {
|
|
2410
|
-
isAllowedToCreateDocuments: true,
|
|
2411
|
-
isAllowedToEditDocuments: true
|
|
2412
|
-
};
|
|
2413
|
-
return {
|
|
2414
|
-
isAllowedToCreateDocuments: allowList.includes(user?.address ?? ""),
|
|
2415
|
-
isAllowedToEditDocuments: allowList.includes(user?.address ?? "")
|
|
2416
|
-
};
|
|
2417
|
-
}
|
|
2418
|
-
const BASE_STATE_KEYS = new Set(["auth"]);
|
|
2419
|
-
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
2420
|
-
async function downloadFile(document, fileName) {
|
|
2421
|
-
try {
|
|
2422
|
-
const data = await createZip(document);
|
|
2423
|
-
const blob = new Blob([new Uint8Array(data)], { type: "application/zip" });
|
|
2424
|
-
const link = window.document.createElement("a");
|
|
2425
|
-
link.style.display = "none";
|
|
2426
|
-
link.href = URL.createObjectURL(blob);
|
|
2427
|
-
link.download = fileName;
|
|
2428
|
-
window.document.body.appendChild(link);
|
|
2429
|
-
link.click();
|
|
2430
|
-
window.document.body.removeChild(link);
|
|
2431
|
-
} catch (e) {
|
|
2432
|
-
logger.error(e instanceof Error ? e.message : String(e));
|
|
2433
|
-
}
|
|
2434
|
-
}
|
|
2435
|
-
async function getDocumentExtension(document) {
|
|
2436
|
-
const documentType = document.header.documentType;
|
|
2437
|
-
let rawExtension;
|
|
2438
|
-
if (documentType === "powerhouse/document-model") rawExtension = document.state.global?.extension;
|
|
2439
|
-
else {
|
|
2440
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2441
|
-
if (reactorClient) {
|
|
2442
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
2443
|
-
rawExtension = documentModelModules.find((m) => m.documentModel.global.id === documentType)?.utils.fileExtension;
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
return (rawExtension ?? "").replace(/^\.+|\.+$/g, "");
|
|
2447
|
-
}
|
|
2448
|
-
/**
|
|
2449
|
-
* Fetches all operations for a document using cursor-based pagination.
|
|
2450
|
-
* The reactor client handles multi-scope cursors transparently via
|
|
2451
|
-
* composite cursors, so all scopes are fetched in a single paginated stream.
|
|
2452
|
-
*/
|
|
2453
|
-
async function fetchDocumentOperations(reactorClient, document, pageSize = 100) {
|
|
2454
|
-
const scopes = Object.keys(document.state).filter((k) => !BASE_STATE_KEYS.has(k));
|
|
2455
|
-
const operations = {};
|
|
2456
|
-
for (const scope of scopes) operations[scope] = [];
|
|
2457
|
-
let cursor = "";
|
|
2458
|
-
do {
|
|
2459
|
-
const page = await reactorClient.getOperations(document.header.id, { scopes }, void 0, {
|
|
2460
|
-
cursor,
|
|
2461
|
-
limit: pageSize
|
|
2462
|
-
});
|
|
2463
|
-
for (const op of page.results) {
|
|
2464
|
-
const scope = op.action.scope ?? "global";
|
|
2465
|
-
if (operations[scope]) operations[scope].push(op);
|
|
2466
|
-
}
|
|
2467
|
-
cursor = page.nextCursor ?? "";
|
|
2468
|
-
} while (cursor);
|
|
2469
|
-
return operations;
|
|
2470
|
-
}
|
|
2471
|
-
function extractInitialState(documentScopeOps) {
|
|
2472
|
-
const upgradeOp = documentScopeOps.find((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
2473
|
-
if (!upgradeOp) throw new Error("No UPGRADE_DOCUMENT operation found — document is invalid");
|
|
2474
|
-
const input = upgradeOp.action.input;
|
|
2475
|
-
const initialState = input.initialState ?? input.state;
|
|
2476
|
-
if (!initialState) throw new Error("UPGRADE_DOCUMENT operation has no initialState — document is invalid");
|
|
2477
|
-
return initialState;
|
|
2478
|
-
}
|
|
2479
|
-
function filterDomainOperations(operations) {
|
|
2480
|
-
return Object.fromEntries(Object.entries(operations).filter(([scope]) => !NON_DOMAIN_SCOPES.has(scope)));
|
|
2481
|
-
}
|
|
2482
|
-
async function exportFile(document, suggestedName) {
|
|
2483
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2484
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2485
|
-
const operations = await fetchDocumentOperations(reactorClient, document);
|
|
2486
|
-
const initialState = extractInitialState(operations["document"] ?? []);
|
|
2487
|
-
const documentWithOps = {
|
|
2488
|
-
...document,
|
|
2489
|
-
operations,
|
|
2490
|
-
initialState
|
|
2491
|
-
};
|
|
2492
|
-
const extension = await getDocumentExtension(documentWithOps);
|
|
2493
|
-
const baseName = suggestedName || documentWithOps.header.name || "Untitled";
|
|
2494
|
-
const name = extension ? `${baseName}.${extension}.phd` : `${baseName}.phd`;
|
|
2495
|
-
if (!window.showSaveFilePicker) return await downloadFile(documentWithOps, name);
|
|
2496
|
-
try {
|
|
2497
|
-
const fileHandle = await window.showSaveFilePicker({ suggestedName: name });
|
|
2498
|
-
await baseSaveToFileHandle(documentWithOps, fileHandle);
|
|
2499
|
-
return fileHandle;
|
|
2500
|
-
} catch (e) {
|
|
2501
|
-
if (!(e instanceof DOMException && e.name === "AbortError")) throw e;
|
|
2502
|
-
}
|
|
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
|
-
*/
|
|
2509
|
-
async function loadFile(path) {
|
|
2510
|
-
const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
|
|
2511
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2512
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2513
|
-
const documentType = baseDocument.header.documentType;
|
|
2514
|
-
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
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
|
-
});
|
|
2528
|
-
}
|
|
2529
|
-
async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor) {
|
|
2530
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2531
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create documents");
|
|
2532
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2533
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2534
|
-
const documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
2535
|
-
const newDocument = document ?? documentModelModule.utils.createDocument();
|
|
2536
|
-
newDocument.header.name = name;
|
|
2537
|
-
if (preferredEditor) newDocument.header.meta = {
|
|
2538
|
-
...newDocument.header.meta,
|
|
2539
|
-
preferredEditor
|
|
2540
|
-
};
|
|
2541
|
-
let newDoc;
|
|
2542
|
-
try {
|
|
2543
|
-
newDoc = await reactorClient.drives.addFile(driveId, newDocument, parentFolder);
|
|
2544
|
-
} catch (e) {
|
|
2545
|
-
logger.error("Error adding document: @error", e);
|
|
2546
|
-
throw new Error("There was an error adding document", { cause: e });
|
|
2547
|
-
}
|
|
2548
|
-
return {
|
|
2549
|
-
id: newDoc.header.id,
|
|
2550
|
-
name: newDoc.header.name,
|
|
2551
|
-
documentType,
|
|
2552
|
-
parentFolder: parentFolder ?? null,
|
|
2553
|
-
kind: "file"
|
|
2554
|
-
};
|
|
2555
|
-
}
|
|
2556
|
-
async function addFile(file, driveId, name, parentFolder) {
|
|
2557
|
-
logger.verbose(`addFile(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
2558
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2559
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create files");
|
|
2560
|
-
const document = await loadFile(file);
|
|
2561
|
-
let duplicateId = false;
|
|
2562
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2563
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2564
|
-
try {
|
|
2565
|
-
await reactorClient.get(document.header.id);
|
|
2566
|
-
duplicateId = true;
|
|
2567
|
-
} catch {}
|
|
2568
|
-
const documentId = duplicateId ? generateId() : document.header.id;
|
|
2569
|
-
const header = createPresignedHeader(documentId, document.header.documentType);
|
|
2570
|
-
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
2571
|
-
header.meta = document.header.meta;
|
|
2572
|
-
header.name = name || document.header.name;
|
|
2573
|
-
const initialDocument = {
|
|
2574
|
-
...document,
|
|
2575
|
-
header,
|
|
2576
|
-
state: document.initialState,
|
|
2577
|
-
operations: Object.keys(document.operations).reduce((acc, key) => {
|
|
2578
|
-
acc[key] = [];
|
|
2579
|
-
return acc;
|
|
2580
|
-
}, {})
|
|
2581
|
-
};
|
|
2582
|
-
await addDocument(driveId, name || document.header.name, document.header.documentType, parentFolder, initialDocument, documentId, document.header.meta?.preferredEditor);
|
|
2583
|
-
await uploadOperations(documentId, filterDomainOperations(document.operations), queueOperations);
|
|
2584
|
-
}
|
|
2585
|
-
async function addFolder(driveId, name, parentFolder) {
|
|
2586
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2587
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create folders");
|
|
2588
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2589
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2590
|
-
await reactorClient.get(driveId);
|
|
2591
|
-
const folderId = generateId();
|
|
2592
|
-
const node = (await reactorClient.execute(driveId, "main", [addFolder$1({
|
|
2593
|
-
id: folderId,
|
|
2594
|
-
name,
|
|
2595
|
-
parentFolder
|
|
2596
|
-
})])).state.global.nodes.find((node) => node.id === folderId);
|
|
2597
|
-
if (!node || !isFolderNode(node)) throw new Error("There was an error adding folder");
|
|
2598
|
-
return node;
|
|
2599
|
-
}
|
|
2600
|
-
async function renameNode(driveId, nodeId, name) {
|
|
2601
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2602
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
2603
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2604
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2605
|
-
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
2606
|
-
const node = (await reactorClient.execute(driveId, "main", [updateNode({
|
|
2607
|
-
id: nodeId,
|
|
2608
|
-
name
|
|
2609
|
-
})])).state.global.nodes.find((n) => n.id === nodeId);
|
|
2610
|
-
if (!node) throw new Error("There was an error renaming node in the drive");
|
|
2611
|
-
return node;
|
|
2612
|
-
}
|
|
2613
|
-
async function renameDriveNode(driveId, nodeId, name) {
|
|
2614
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2615
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
2616
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2617
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2618
|
-
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
2619
|
-
await reactorClient.execute(driveId, "main", [updateNode({
|
|
2620
|
-
id: nodeId,
|
|
2621
|
-
name
|
|
2622
|
-
})]);
|
|
2623
|
-
return (await reactorClient.get(driveId)).state.global.nodes.find((n) => n.id === nodeId);
|
|
2624
|
-
}
|
|
2625
|
-
async function moveNodeById(args) {
|
|
2626
|
-
const { driveId, srcId, targetId } = args;
|
|
2627
|
-
if (!driveId || !srcId) return;
|
|
2628
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2629
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
2630
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2631
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2632
|
-
const targetParentFolder = t$3(targetId, [e$3(e$4), e$6(void 0)], [t(driveId), e$6(void 0)], e$6(targetId));
|
|
2633
|
-
if (t(targetParentFolder, srcId)) return;
|
|
2634
|
-
return await reactorClient.execute(driveId, "main", [moveNode({
|
|
2635
|
-
srcFolder: srcId,
|
|
2636
|
-
targetParentFolder
|
|
2637
|
-
})]);
|
|
2638
|
-
}
|
|
2639
|
-
async function moveNode$1(driveId, src, target) {
|
|
2640
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2641
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
2642
|
-
const reactorClient = window.ph?.reactorClient;
|
|
2643
|
-
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2644
|
-
return await reactorClient.execute(driveId, "main", [moveNode({
|
|
2645
|
-
srcFolder: src.id,
|
|
2646
|
-
targetParentFolder: target?.id
|
|
2647
|
-
})]);
|
|
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
|
-
*/
|
|
2653
|
-
async function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
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);
|
|
2671
|
-
}
|
|
2672
|
-
async function copyNode$1(driveId, src, target) {
|
|
2673
|
-
const reactor = window.ph?.reactorClient;
|
|
2674
|
-
if (!reactor) return;
|
|
2675
|
-
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2676
|
-
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to copy documents");
|
|
2677
|
-
const drive = await reactor.get(driveId);
|
|
2678
|
-
const copyNodesInput = generateNodesCopy({
|
|
2679
|
-
srcId: src.id,
|
|
2680
|
-
targetParentFolder: target?.id,
|
|
2681
|
-
targetName: src.name
|
|
2682
|
-
}, () => generateId(), drive.state.global.nodes);
|
|
2683
|
-
const resolvedNamesMap = /* @__PURE__ */ new Map();
|
|
2684
|
-
for (const copyNodeInput of copyNodesInput) {
|
|
2685
|
-
const node = drive.state.global.nodes.find((n) => n.id === copyNodeInput.srcId);
|
|
2686
|
-
if (node) {
|
|
2687
|
-
const resolvedName = handleTargetNameCollisions({
|
|
2688
|
-
nodes: drive.state.global.nodes,
|
|
2689
|
-
srcName: copyNodeInput.targetName || node.name,
|
|
2690
|
-
srcKind: isFileNode(node) ? "file" : "folder",
|
|
2691
|
-
targetParentFolder: copyNodeInput.targetParentFolder || null
|
|
2692
|
-
});
|
|
2693
|
-
resolvedNamesMap.set(copyNodeInput.targetId, resolvedName);
|
|
2694
|
-
}
|
|
2695
|
-
}
|
|
2696
|
-
const fileNodesToCopy = copyNodesInput.filter((copyNodeInput) => {
|
|
2697
|
-
const node = drive.state.global.nodes.find((node) => node.id === copyNodeInput.srcId);
|
|
2698
|
-
return node !== void 0 && isFileNode(node);
|
|
2699
|
-
});
|
|
2700
|
-
for (const fileNodeToCopy of fileNodesToCopy) try {
|
|
2701
|
-
const duplicatedDocument = await _duplicateDocument(reactor, await reactor.get(fileNodeToCopy.srcId), fileNodeToCopy.targetId);
|
|
2702
|
-
const resolvedName = resolvedNamesMap.get(fileNodeToCopy.targetId);
|
|
2703
|
-
if (resolvedName) duplicatedDocument.header.name = resolvedName;
|
|
2704
|
-
await reactor.drives.addFile(driveId, duplicatedDocument, target?.id);
|
|
2705
|
-
} catch (e) {
|
|
2706
|
-
logger.error(`Error copying document ${fileNodeToCopy.srcId}: ${String(e)}`);
|
|
2707
|
-
}
|
|
2708
|
-
return await queueActions(drive, copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput)));
|
|
2709
|
-
}
|
|
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"];
|
|
2735
|
-
const isExternalControlsEnabledEventFunctions = makePHEventFunctions("isExternalControlsEnabled");
|
|
2736
|
-
/** Sets whether external controls are enabled for a given editor. */
|
|
2737
|
-
const setIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.setValue;
|
|
2738
|
-
/** Gets whether external controls are enabled for a given editor. */
|
|
2739
|
-
const useIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.useValue;
|
|
2740
|
-
isExternalControlsEnabledEventFunctions.addEventHandler;
|
|
2741
|
-
const isDragAndDropEnabledEventFunctions = makePHEventFunctions("isDragAndDropEnabled");
|
|
2742
|
-
/** Sets whether drag and drop is enabled for a given app. */
|
|
2743
|
-
const setIsDragAndDropEnabled = isDragAndDropEnabledEventFunctions.setValue;
|
|
2744
|
-
/** Gets whether drag and drop is enabled for a given app. */
|
|
2745
|
-
const useIsDragAndDropEnabled = isDragAndDropEnabledEventFunctions.useValue;
|
|
2746
|
-
isDragAndDropEnabledEventFunctions.addEventHandler;
|
|
2747
|
-
const allowedDocumentTypesEventFunctions = makePHEventFunctions("allowedDocumentTypes");
|
|
2748
|
-
/** Sets the allowed document types for a given app. */
|
|
2749
|
-
const setAllowedDocumentTypes = allowedDocumentTypesEventFunctions.setValue;
|
|
2750
|
-
/** Defines the document types a drive supports.
|
|
2751
|
-
*
|
|
2752
|
-
* Defaults to all of the document types registered in the reactor.
|
|
2753
|
-
*/
|
|
2754
|
-
function useAllowedDocumentTypes() {
|
|
2755
|
-
return allowedDocumentTypesEventFunctions.useValue();
|
|
2756
|
-
}
|
|
2757
|
-
allowedDocumentTypesEventFunctions.addEventHandler;
|
|
2758
|
-
const phAppConfigSetters = {
|
|
2759
|
-
allowedDocumentTypes: setAllowedDocumentTypes,
|
|
2760
|
-
isDragAndDropEnabled: setIsDragAndDropEnabled
|
|
2761
|
-
};
|
|
2762
|
-
const phDocumentEditorConfigSetters = { isExternalControlsEnabled: setIsExternalControlsEnabled };
|
|
2763
|
-
const phAppConfigHooks = {
|
|
2764
|
-
allowedDocumentTypes: useAllowedDocumentTypes,
|
|
2765
|
-
isDragAndDropEnabled: useIsDragAndDropEnabled
|
|
2534
|
+
const phDocumentEditorConfigSetters = { isExternalControlsEnabled: setIsExternalControlsEnabled };
|
|
2535
|
+
const phAppConfigHooks = {
|
|
2536
|
+
allowedDocumentTypes: useAllowedDocumentTypes,
|
|
2537
|
+
isDragAndDropEnabled: useIsDragAndDropEnabled
|
|
2766
2538
|
};
|
|
2767
2539
|
const phDocumentEditorConfigHooks = { isExternalControlsEnabled: useIsExternalControlsEnabled };
|
|
2768
2540
|
const { useValue: useRouterBasename, setValue: setRouterBasename, addEventHandler: addRouterBasenameEventHandler } = makePHEventFunctions("routerBasename");
|
|
@@ -2797,6 +2569,8 @@ const { useValue: useIsDriveAnalyticsEnabled, setValue: setIsDriveAnalyticsEnabl
|
|
|
2797
2569
|
const { useValue: useRenownUrl, setValue: setRenownUrl, addEventHandler: addRenownUrlEventHandler } = makePHEventFunctions("renownUrl");
|
|
2798
2570
|
const { useValue: useRenownNetworkId, setValue: setRenownNetworkId, addEventHandler: addRenownNetworkIdEventHandler } = makePHEventFunctions("renownNetworkId");
|
|
2799
2571
|
const { useValue: useRenownChainId, setValue: setRenownChainId, addEventHandler: addRenownChainIdEventHandler } = makePHEventFunctions("renownChainId");
|
|
2572
|
+
const { useValue: useSwitchboardUrl, setValue: setSwitchboardUrl, addEventHandler: addSwitchboardUrlEventHandler } = makePHEventFunctions("switchboardUrl");
|
|
2573
|
+
const { useValue: useRenownAdapters, setValue: setRenownAdapters, addEventHandler: addRenownAdaptersEventHandler } = makePHEventFunctions("renownAdapters");
|
|
2800
2574
|
const { useValue: useSentryRelease, setValue: setSentryRelease, addEventHandler: addSentryReleaseEventHandler } = makePHEventFunctions("sentryRelease");
|
|
2801
2575
|
const { useValue: useSentryDsn, setValue: setSentryDsn, addEventHandler: addSentryDsnEventHandler } = makePHEventFunctions("sentryDsn");
|
|
2802
2576
|
const { useValue: useSentryEnv, setValue: setSentryEnv, addEventHandler: addSentryEnvEventHandler } = makePHEventFunctions("sentryEnv");
|
|
@@ -2894,6 +2668,8 @@ const nonUserConfigSetters = {
|
|
|
2894
2668
|
renownUrl: setRenownUrl,
|
|
2895
2669
|
renownNetworkId: setRenownNetworkId,
|
|
2896
2670
|
renownChainId: setRenownChainId,
|
|
2671
|
+
switchboardUrl: setSwitchboardUrl,
|
|
2672
|
+
renownAdapters: setRenownAdapters,
|
|
2897
2673
|
sentryRelease: setSentryRelease,
|
|
2898
2674
|
sentryDsn: setSentryDsn,
|
|
2899
2675
|
sentryEnv: setSentryEnv,
|
|
@@ -2942,6 +2718,8 @@ const nonUserConfigHooks = {
|
|
|
2942
2718
|
renownUrl: useRenownUrl,
|
|
2943
2719
|
renownNetworkId: useRenownNetworkId,
|
|
2944
2720
|
renownChainId: useRenownChainId,
|
|
2721
|
+
switchboardUrl: useSwitchboardUrl,
|
|
2722
|
+
renownAdapters: useRenownAdapters,
|
|
2945
2723
|
sentryRelease: useSentryRelease,
|
|
2946
2724
|
sentryDsn: useSentryDsn,
|
|
2947
2725
|
sentryEnv: useSentryEnv,
|
|
@@ -2963,374 +2741,1090 @@ const nonUserConfigHooks = {
|
|
|
2963
2741
|
...phDocumentEditorConfigHooks,
|
|
2964
2742
|
...nonUserConfigHooks
|
|
2965
2743
|
});
|
|
2966
|
-
const attachmentServiceEventFunctions = makePHEventFunctions("attachmentService");
|
|
2967
|
-
attachmentServiceEventFunctions.useValue;
|
|
2968
|
-
attachmentServiceEventFunctions.setValue;
|
|
2969
|
-
attachmentServiceEventFunctions.addEventHandler;
|
|
2970
|
-
const featuresEventFunctions = makePHEventFunctions("features");
|
|
2971
|
-
featuresEventFunctions.useValue;
|
|
2972
|
-
featuresEventFunctions.setValue;
|
|
2973
|
-
featuresEventFunctions.addEventHandler;
|
|
2974
|
-
function resolveUrlPathname(path) {
|
|
2975
|
-
return new URL(path.replace(/^\/+/, ""), window.location.origin + (window.ph?.basePath ?? "/")).pathname;
|
|
2744
|
+
const attachmentServiceEventFunctions = makePHEventFunctions("attachmentService");
|
|
2745
|
+
attachmentServiceEventFunctions.useValue;
|
|
2746
|
+
attachmentServiceEventFunctions.setValue;
|
|
2747
|
+
attachmentServiceEventFunctions.addEventHandler;
|
|
2748
|
+
const featuresEventFunctions = makePHEventFunctions("features");
|
|
2749
|
+
featuresEventFunctions.useValue;
|
|
2750
|
+
featuresEventFunctions.setValue;
|
|
2751
|
+
featuresEventFunctions.addEventHandler;
|
|
2752
|
+
function resolveUrlPathname(path) {
|
|
2753
|
+
return new URL(path.replace(/^\/+/, ""), window.location.origin + (window.ph?.basePath ?? "/")).pathname;
|
|
2754
|
+
}
|
|
2755
|
+
/** Returns the current path without the base path */
|
|
2756
|
+
function getPathWithoutBase(path) {
|
|
2757
|
+
const basePath = window.ph?.basePath ?? "/";
|
|
2758
|
+
return path.replace(basePath, basePath.endsWith("/") ? "/" : "");
|
|
2759
|
+
}
|
|
2760
|
+
/** Makes a URL component for a node. */
|
|
2761
|
+
function makeNodeSlug(node) {
|
|
2762
|
+
if (!node) return "";
|
|
2763
|
+
const nodeName = node.name;
|
|
2764
|
+
if (!nodeName) return slug(node.id);
|
|
2765
|
+
return slug(`${nodeName}-${node.id}`);
|
|
2766
|
+
}
|
|
2767
|
+
/** Extracts the node slug from a path.
|
|
2768
|
+
*
|
|
2769
|
+
* The path is expected to be in the format `/d/<drive-slug>/<node-slug>`.
|
|
2770
|
+
*/
|
|
2771
|
+
function extractNodeSlugFromPath(path) {
|
|
2772
|
+
const currentPath = getPathWithoutBase(path);
|
|
2773
|
+
return /^\/d\/[^/]+\/([^/]+)$/.exec(currentPath)?.[1];
|
|
2774
|
+
}
|
|
2775
|
+
/** Finds a UUID in a string, used for extracting node ids from node slugs in the URL. */
|
|
2776
|
+
function findUuid(input) {
|
|
2777
|
+
if (!input) return void 0;
|
|
2778
|
+
return /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/.exec(input)?.[0];
|
|
2779
|
+
}
|
|
2780
|
+
function extractNodeIdFromSlug(nodeSlug) {
|
|
2781
|
+
return findUuid(nodeSlug);
|
|
2782
|
+
}
|
|
2783
|
+
/** Extracts the drive slug from a path.
|
|
2784
|
+
* Used for extracting drive ids from drive slugs in the URL.
|
|
2785
|
+
* Expects the path to be in the format `/d/<drive-slug>`.
|
|
2786
|
+
*/
|
|
2787
|
+
function extractDriveSlugFromPath(path) {
|
|
2788
|
+
const currentPath = getPathWithoutBase(path);
|
|
2789
|
+
return /^\/d\/([^/]+)/.exec(currentPath)?.[1] ?? "";
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* Creates a URL string with the given pathname while preserving existing query parameters.
|
|
2793
|
+
*/
|
|
2794
|
+
function createUrlWithPreservedParams(pathname) {
|
|
2795
|
+
const search = window.location.search;
|
|
2796
|
+
return search ? `${pathname}${search}` : pathname;
|
|
2797
|
+
}
|
|
2798
|
+
const drivesEventFunctions = makePHEventFunctions("drives");
|
|
2799
|
+
/** Returns all of the drives in the reactor */
|
|
2800
|
+
const useDrives = drivesEventFunctions.useValue;
|
|
2801
|
+
/** Sets the drives in the reactor */
|
|
2802
|
+
const setDrives = drivesEventFunctions.setValue;
|
|
2803
|
+
drivesEventFunctions.addEventHandler;
|
|
2804
|
+
const selectedNodeIdEventFunctions = makePHEventFunctions("selectedNodeId");
|
|
2805
|
+
const useSelectedNodeId = selectedNodeIdEventFunctions.useValue;
|
|
2806
|
+
const setSelectedNodeId = selectedNodeIdEventFunctions.setValue;
|
|
2807
|
+
selectedNodeIdEventFunctions.addEventHandler;
|
|
2808
|
+
/** Sets the selected node (file or folder). */
|
|
2809
|
+
function setSelectedNode(nodeOrNodeSlug) {
|
|
2810
|
+
const nodeSlug = typeof nodeOrNodeSlug === "string" ? nodeOrNodeSlug : makeNodeSlug(nodeOrNodeSlug);
|
|
2811
|
+
setSelectedNodeId(extractNodeIdFromSlug(nodeSlug));
|
|
2812
|
+
const driveSlugFromPath = extractDriveSlugFromPath(window.location.pathname);
|
|
2813
|
+
if (!driveSlugFromPath) return;
|
|
2814
|
+
if (!nodeSlug) {
|
|
2815
|
+
const pathname = resolveUrlPathname(`/d/${driveSlugFromPath}`);
|
|
2816
|
+
if (pathname === window.location.pathname) return;
|
|
2817
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
const pathname = resolveUrlPathname(`/d/${driveSlugFromPath}/${nodeSlug}`);
|
|
2821
|
+
if (pathname === window.location.pathname) return;
|
|
2822
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2823
|
+
}
|
|
2824
|
+
const selectedDriveIdEventFunctions = makePHEventFunctions("selectedDriveId");
|
|
2825
|
+
/** Returns the selected drive id */
|
|
2826
|
+
const useSelectedDriveId = selectedDriveIdEventFunctions.useValue;
|
|
2827
|
+
/** Sets the selected drive id */
|
|
2828
|
+
const setSelectedDriveId = selectedDriveIdEventFunctions.setValue;
|
|
2829
|
+
selectedDriveIdEventFunctions.addEventHandler;
|
|
2830
|
+
/** Returns the selected drive, or undefined if no drive is selected */
|
|
2831
|
+
function useSelectedDriveSafe() {
|
|
2832
|
+
const selectedDriveId = useSelectedDriveId();
|
|
2833
|
+
const selectedDrive = useDrives()?.find((drive) => drive.header.id === selectedDriveId);
|
|
2834
|
+
const [drive, dispatch] = useDispatch(selectedDrive);
|
|
2835
|
+
if (!selectedDrive) return [void 0, void 0];
|
|
2836
|
+
return [drive, dispatch];
|
|
2837
|
+
}
|
|
2838
|
+
function setSelectedDrive(driveOrDriveSlug) {
|
|
2839
|
+
const driveSlug = typeof driveOrDriveSlug === "string" ? driveOrDriveSlug : driveOrDriveSlug?.header.slug;
|
|
2840
|
+
const drives = window.ph?.drives;
|
|
2841
|
+
const driveId = (typeof driveOrDriveSlug === "object" && driveOrDriveSlug !== null ? driveOrDriveSlug : drives?.find((d) => d.header.slug === driveSlug))?.header.id;
|
|
2842
|
+
if (!driveId && driveSlug && extractDriveSlugFromPath(window.location.pathname) === driveSlug) {
|
|
2843
|
+
if (window.ph?.selectedDriveId) setSelectedDriveId(void 0);
|
|
2844
|
+
deferDriveSelection(driveSlug);
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
cancelPendingDriveSelection();
|
|
2848
|
+
setSelectedDriveId(driveId);
|
|
2849
|
+
if (!driveId) {
|
|
2850
|
+
const pathname = resolveUrlPathname("/");
|
|
2851
|
+
if (pathname === window.location.pathname) return;
|
|
2852
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
const pathname = resolveUrlPathname(`/d/${driveSlug}`);
|
|
2856
|
+
if (pathname === window.location.pathname) return;
|
|
2857
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2858
|
+
}
|
|
2859
|
+
const DEFERRED_DRIVE_TICK_MS = 2e3;
|
|
2860
|
+
const DEFERRED_DRIVE_MAX_WAIT_MS = 15e3;
|
|
2861
|
+
function isInitialSyncInFlight() {
|
|
2862
|
+
const remotes = window.ph?.reactorClientModule?.reactorModule?.syncModule?.syncManager?.list();
|
|
2863
|
+
if (!remotes?.length) return false;
|
|
2864
|
+
return remotes.some((remote) => {
|
|
2865
|
+
try {
|
|
2866
|
+
const snapshot = remote.channel.getConnectionState();
|
|
2867
|
+
return snapshot.receivingPages || !snapshot.lastSuccessUtcMs && snapshot.state !== "error";
|
|
2868
|
+
} catch {
|
|
2869
|
+
return false;
|
|
2870
|
+
}
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
let pendingHandler;
|
|
2874
|
+
let pendingTimeout;
|
|
2875
|
+
function cancelPendingDriveSelection() {
|
|
2876
|
+
if (pendingHandler) {
|
|
2877
|
+
window.removeEventListener("ph:drivesUpdated", pendingHandler);
|
|
2878
|
+
pendingHandler = void 0;
|
|
2879
|
+
}
|
|
2880
|
+
if (pendingTimeout) {
|
|
2881
|
+
clearTimeout(pendingTimeout);
|
|
2882
|
+
pendingTimeout = void 0;
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
function deferDriveSelection(driveSlug) {
|
|
2886
|
+
cancelPendingDriveSelection();
|
|
2887
|
+
const nodeSlug = extractNodeSlugFromPath(window.location.pathname);
|
|
2888
|
+
const handler = () => {
|
|
2889
|
+
if (!window.ph?.drives?.find((d) => d.header.slug === driveSlug)) return;
|
|
2890
|
+
cancelPendingDriveSelection();
|
|
2891
|
+
setSelectedDrive(driveSlug);
|
|
2892
|
+
setSelectedNode(nodeSlug);
|
|
2893
|
+
};
|
|
2894
|
+
pendingHandler = handler;
|
|
2895
|
+
window.addEventListener("ph:drivesUpdated", handler);
|
|
2896
|
+
const deadline = Date.now() + DEFERRED_DRIVE_MAX_WAIT_MS;
|
|
2897
|
+
const scheduleTick = () => {
|
|
2898
|
+
pendingTimeout = setTimeout(() => {
|
|
2899
|
+
if (Date.now() < deadline && isInitialSyncInFlight()) {
|
|
2900
|
+
scheduleTick();
|
|
2901
|
+
return;
|
|
2902
|
+
}
|
|
2903
|
+
cancelPendingDriveSelection();
|
|
2904
|
+
const pathname = resolveUrlPathname("/");
|
|
2905
|
+
if (pathname === window.location.pathname) return;
|
|
2906
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2907
|
+
}, DEFERRED_DRIVE_TICK_MS);
|
|
2908
|
+
};
|
|
2909
|
+
scheduleTick();
|
|
2910
|
+
}
|
|
2911
|
+
function useDropTarget() {
|
|
2912
|
+
const [isDropTarget, setIsDropTarget] = useState(false);
|
|
2913
|
+
const isDragAndDropEnabled = useIsDragAndDropEnabled();
|
|
2914
|
+
const targetSetter = n$1(() => setIsDropTarget(true), {
|
|
2915
|
+
triggerAt: "start",
|
|
2916
|
+
minQuietPeriodMs: 100
|
|
2917
|
+
});
|
|
2918
|
+
const targetUnsetter = n$1(() => setIsDropTarget(false), {
|
|
2919
|
+
triggerAt: "start",
|
|
2920
|
+
minQuietPeriodMs: 100
|
|
2921
|
+
});
|
|
2922
|
+
function setTarget() {
|
|
2923
|
+
if (!isDragAndDropEnabled) return;
|
|
2924
|
+
targetUnsetter.cancel();
|
|
2925
|
+
targetSetter.call();
|
|
2926
|
+
}
|
|
2927
|
+
function unsetTarget() {
|
|
2928
|
+
if (!isDragAndDropEnabled) return;
|
|
2929
|
+
targetSetter.cancel();
|
|
2930
|
+
targetUnsetter.call();
|
|
2931
|
+
}
|
|
2932
|
+
return {
|
|
2933
|
+
isDropTarget,
|
|
2934
|
+
setTarget,
|
|
2935
|
+
unsetTarget
|
|
2936
|
+
};
|
|
2937
|
+
}
|
|
2938
|
+
const draggingNodeEventFunctions = makePHEventFunctions("draggingNode");
|
|
2939
|
+
const useDraggingNode = draggingNodeEventFunctions.useValue;
|
|
2940
|
+
const setDraggingNode = draggingNodeEventFunctions.setValue;
|
|
2941
|
+
draggingNodeEventFunctions.addEventHandler;
|
|
2942
|
+
const draggingNodeSetter = n$1((node) => setDraggingNode(node), {
|
|
2943
|
+
reducer: (_, newNode) => newNode,
|
|
2944
|
+
triggerAt: "start",
|
|
2945
|
+
minQuietPeriodMs: 100
|
|
2946
|
+
});
|
|
2947
|
+
const draggingNodeUnsetter = n$1(() => setDraggingNode(void 0), {
|
|
2948
|
+
triggerAt: "start",
|
|
2949
|
+
minQuietPeriodMs: 100
|
|
2950
|
+
});
|
|
2951
|
+
function setDragging(node) {
|
|
2952
|
+
draggingNodeUnsetter.cancel();
|
|
2953
|
+
draggingNodeSetter.call(node);
|
|
2976
2954
|
}
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
return path.replace(basePath, basePath.endsWith("/") ? "/" : "");
|
|
2955
|
+
function unsetDragging() {
|
|
2956
|
+
draggingNodeSetter.cancel();
|
|
2957
|
+
draggingNodeUnsetter.call();
|
|
2981
2958
|
}
|
|
2982
|
-
|
|
2983
|
-
function
|
|
2984
|
-
|
|
2985
|
-
const
|
|
2986
|
-
|
|
2987
|
-
|
|
2959
|
+
const isNodeDrag = (params) => t$3(params, [({ srcId }) => e$3(e$1)(srcId), e$6(false)], [({ driveId }) => e$3(e$1)(driveId), e$6(false)], [({ driveId, srcId }) => t(driveId, srcId), e$6(false)], e$6(true));
|
|
2960
|
+
function useDragNode(args) {
|
|
2961
|
+
const { srcId, parentId } = args;
|
|
2962
|
+
const driveId = useSelectedDriveId();
|
|
2963
|
+
const draggingNodeId = useDraggingNode()?.srcId;
|
|
2964
|
+
const params = {
|
|
2965
|
+
driveId,
|
|
2966
|
+
srcId,
|
|
2967
|
+
parentId
|
|
2968
|
+
};
|
|
2969
|
+
const draggable = isNodeDrag(params);
|
|
2970
|
+
const isDragging = t$4({
|
|
2971
|
+
srcId,
|
|
2972
|
+
draggingNodeId
|
|
2973
|
+
}, [
|
|
2974
|
+
() => draggable,
|
|
2975
|
+
({ srcId }) => e$2(srcId),
|
|
2976
|
+
({ draggingNodeId }) => e$2(draggingNodeId),
|
|
2977
|
+
({ srcId, draggingNodeId }) => t(srcId, draggingNodeId)
|
|
2978
|
+
]);
|
|
2979
|
+
const onDragStart = () => {
|
|
2980
|
+
if (!draggable) return;
|
|
2981
|
+
setDragging(params);
|
|
2982
|
+
};
|
|
2983
|
+
const onDragEnd = () => {
|
|
2984
|
+
if (!draggable) return;
|
|
2985
|
+
unsetDragging();
|
|
2986
|
+
};
|
|
2987
|
+
return {
|
|
2988
|
+
isDragging,
|
|
2989
|
+
draggable,
|
|
2990
|
+
onDragStart,
|
|
2991
|
+
onDragEnd
|
|
2992
|
+
};
|
|
2988
2993
|
}
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
const
|
|
2995
|
-
|
|
2994
|
+
const isNodeDrop = (params) => t$3(params, [({ srcId }) => e$3(e$1)(srcId), e$6(false)], [({ driveId }) => e$3(e$4)(driveId), e$6(false)], [({ srcId, targetId }) => t(srcId, targetId), e$6(false)], [({ driveId, parentId, targetId }) => e$3(e$1)(parentId) && t(targetId, driveId), e$6(false)], [({ targetId, parentId }) => t(targetId, parentId), e$6(false)], e$6(true));
|
|
2995
|
+
function useDropNode(targetId) {
|
|
2996
|
+
const driveId = useSelectedDriveId();
|
|
2997
|
+
const { srcId, parentId } = useDraggingNode() ?? {};
|
|
2998
|
+
const { isDropTarget, setTarget, unsetTarget } = useDropTarget();
|
|
2999
|
+
const params = {
|
|
3000
|
+
driveId,
|
|
3001
|
+
parentId,
|
|
3002
|
+
targetId,
|
|
3003
|
+
srcId
|
|
3004
|
+
};
|
|
3005
|
+
function handleNodeDrop(event, cb) {
|
|
3006
|
+
if (!isNodeDrop(params)) return;
|
|
3007
|
+
event.preventDefault();
|
|
3008
|
+
event.stopPropagation();
|
|
3009
|
+
cb?.();
|
|
3010
|
+
}
|
|
3011
|
+
const onDragEnter = (event) => handleNodeDrop(event);
|
|
3012
|
+
const onDragOver = (event) => handleNodeDrop(event, e(setTarget));
|
|
3013
|
+
const onDragLeave = (event) => handleNodeDrop(event, e(unsetTarget));
|
|
3014
|
+
const onDrop = (event) => handleNodeDrop(event, e(() => {
|
|
3015
|
+
unsetDragging();
|
|
3016
|
+
unsetTarget();
|
|
3017
|
+
moveNodeById(params).catch(console.error);
|
|
3018
|
+
}));
|
|
3019
|
+
return {
|
|
3020
|
+
isDropTarget,
|
|
3021
|
+
onDragEnter,
|
|
3022
|
+
onDragOver,
|
|
3023
|
+
onDragLeave,
|
|
3024
|
+
onDrop
|
|
3025
|
+
};
|
|
2996
3026
|
}
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3027
|
+
const graphQLReactorClientEventFunctions = makePHEventFunctions("reactorGraphQLClient");
|
|
3028
|
+
graphQLReactorClientEventFunctions.useValue;
|
|
3029
|
+
graphQLReactorClientEventFunctions.setValue;
|
|
3030
|
+
graphQLReactorClientEventFunctions.addEventHandler;
|
|
3031
|
+
const packageDiscoveryFunctions = makePHEventFunctions("packageDiscoveryService");
|
|
3032
|
+
packageDiscoveryFunctions.useValue;
|
|
3033
|
+
packageDiscoveryFunctions.setValue;
|
|
3034
|
+
packageDiscoveryFunctions.addEventHandler;
|
|
3035
|
+
const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
|
|
3036
|
+
const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
|
|
3037
|
+
/** Returns the reactor client module (in-process or worker-backed) */
|
|
3038
|
+
const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
|
|
3039
|
+
reactorClientModuleEventFunctions.setValue;
|
|
3040
|
+
reactorClientModuleEventFunctions.addEventHandler;
|
|
3041
|
+
reactorClientEventFunctions.useValue;
|
|
3042
|
+
reactorClientEventFunctions.setValue;
|
|
3043
|
+
reactorClientEventFunctions.addEventHandler;
|
|
3044
|
+
const useSync = () => useReactorClientModule()?.reactorModule?.syncModule?.syncManager;
|
|
3045
|
+
const useSyncList = () => {
|
|
3046
|
+
return useSync()?.list() ?? [];
|
|
3047
|
+
};
|
|
3048
|
+
const useModelRegistry = () => useReactorClientModule()?.reactorModule?.documentModelRegistry;
|
|
3049
|
+
const revisionHistoryEventFunctions = makePHEventFunctions("revisionHistoryVisible");
|
|
3050
|
+
revisionHistoryEventFunctions.useValue;
|
|
3051
|
+
/** Sets revision history visibility */
|
|
3052
|
+
const setRevisionHistoryVisible = revisionHistoryEventFunctions.setValue;
|
|
3053
|
+
revisionHistoryEventFunctions.addEventHandler;
|
|
3054
|
+
/** Shows the revision history */
|
|
3055
|
+
function showRevisionHistory() {
|
|
3056
|
+
setRevisionHistoryVisible(true);
|
|
3001
3057
|
}
|
|
3002
|
-
|
|
3003
|
-
|
|
3058
|
+
/** Sorts nodes by name. */
|
|
3059
|
+
function sortNodesByName(nodes) {
|
|
3060
|
+
return nodes.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
3004
3061
|
}
|
|
3005
|
-
/**
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3062
|
+
/** Returns whether a node is a file. */
|
|
3063
|
+
function isFileNodeKind(node) {
|
|
3064
|
+
if (!node) return false;
|
|
3065
|
+
return node.kind.toUpperCase() === "FILE";
|
|
3066
|
+
}
|
|
3067
|
+
/** Returns whether a node is a folder. */
|
|
3068
|
+
function isFolderNodeKind(node) {
|
|
3069
|
+
if (!node) return false;
|
|
3070
|
+
return node.kind.toUpperCase() === "FOLDER";
|
|
3071
|
+
}
|
|
3072
|
+
/** Returns the nodes in the selected drive. */
|
|
3073
|
+
function useNodesInSelectedDrive() {
|
|
3074
|
+
const [selectedDrive] = useSelectedDriveSafe();
|
|
3075
|
+
return selectedDrive?.state.global.nodes;
|
|
3076
|
+
}
|
|
3077
|
+
/** Returns the folder nodes in the selected drive. */
|
|
3078
|
+
function useFolderNodesInSelectedDrive() {
|
|
3079
|
+
return useNodesInSelectedDrive()?.filter((n) => isFolderNodeKind(n));
|
|
3080
|
+
}
|
|
3081
|
+
/** Returns the selected node. */
|
|
3082
|
+
function useSelectedNode() {
|
|
3083
|
+
const selectedNodeId = useSelectedNodeId();
|
|
3084
|
+
return useNodesInSelectedDrive()?.find((n) => n.id === selectedNodeId);
|
|
3085
|
+
}
|
|
3086
|
+
const selectedTimelineItemEventFunctions = makePHEventFunctions("selectedTimelineItem");
|
|
3087
|
+
selectedTimelineItemEventFunctions.useValue;
|
|
3088
|
+
selectedTimelineItemEventFunctions.setValue;
|
|
3089
|
+
selectedTimelineItemEventFunctions.addEventHandler;
|
|
3090
|
+
const selectedTimelineRevisionEventFunctions = makePHEventFunctions("selectedTimelineRevision");
|
|
3091
|
+
selectedTimelineRevisionEventFunctions.useValue;
|
|
3092
|
+
selectedTimelineRevisionEventFunctions.setValue;
|
|
3093
|
+
selectedTimelineRevisionEventFunctions.addEventHandler;
|
|
3094
|
+
const toastEventFunctions = makePHEventFunctions("toast");
|
|
3095
|
+
/** Returns the toast function */
|
|
3096
|
+
const usePHToast = toastEventFunctions.useValue;
|
|
3097
|
+
toastEventFunctions.setValue;
|
|
3098
|
+
toastEventFunctions.addEventHandler;
|
|
3099
|
+
const vetraPackageManagerFunctions = makePHEventFunctions("vetraPackageManager");
|
|
3100
|
+
const useVetraPackageManager = vetraPackageManagerFunctions.useValue;
|
|
3101
|
+
/** Returns all of the Vetra packages loaded by the Connect instance */
|
|
3102
|
+
const useVetraPackages = () => {
|
|
3103
|
+
const packageManager = useVetraPackageManager();
|
|
3104
|
+
return useSyncExternalStore((cb) => packageManager ? packageManager.subscribe(cb) : () => {}, () => packageManager?.packages ?? []);
|
|
3105
|
+
};
|
|
3106
|
+
vetraPackageManagerFunctions.addEventHandler;
|
|
3107
|
+
function useDocumentModelModules() {
|
|
3108
|
+
return useVetraPackages().flatMap((pkg) => pkg.documentModels).filter((module, index, modules) => modules.findIndex((m) => m.documentModel.global.id === module.documentModel.global.id && m.version === module.version) === index);
|
|
3012
3109
|
}
|
|
3013
3110
|
/**
|
|
3014
|
-
*
|
|
3111
|
+
* Resolves a document model module by document type, mirroring the registry's
|
|
3112
|
+
* semantics (`IDocumentModelRegistry.getModule`): with `version` omitted the
|
|
3113
|
+
* LATEST version of the type wins (`version ?? 1` as each module's default),
|
|
3114
|
+
* with `version` given only an exact match is returned. The reactor resolves
|
|
3115
|
+
* modules the same way when a document is created, so metadata read through
|
|
3116
|
+
* this hook and the version a creation actually uses cannot disagree.
|
|
3015
3117
|
*/
|
|
3016
|
-
function
|
|
3017
|
-
const
|
|
3018
|
-
|
|
3118
|
+
function useDocumentModelModuleById(id, version) {
|
|
3119
|
+
const documentModelModules = useDocumentModelModules();
|
|
3120
|
+
if (!id || !documentModelModules) return void 0;
|
|
3121
|
+
let latestModule;
|
|
3122
|
+
let latestVersion = -1;
|
|
3123
|
+
for (const module of documentModelModules) {
|
|
3124
|
+
if (module.documentModel.global.id !== id) continue;
|
|
3125
|
+
const moduleVersion = module.version ?? 1;
|
|
3126
|
+
if (version !== void 0) {
|
|
3127
|
+
if (moduleVersion === version) return module;
|
|
3128
|
+
continue;
|
|
3129
|
+
}
|
|
3130
|
+
if (moduleVersion > latestVersion) {
|
|
3131
|
+
latestVersion = moduleVersion;
|
|
3132
|
+
latestModule = module;
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
return latestModule;
|
|
3019
3136
|
}
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
const
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
const
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
if (
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
3137
|
+
//#endregion
|
|
3138
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/descriptors.js
|
|
3139
|
+
const normalizeDescriptors = (error) => {
|
|
3140
|
+
CORE_ERROR_PROPS.forEach((propName) => {
|
|
3141
|
+
normalizeDescriptor(error, propName);
|
|
3142
|
+
});
|
|
3143
|
+
};
|
|
3144
|
+
const CORE_ERROR_PROPS = [
|
|
3145
|
+
"name",
|
|
3146
|
+
"message",
|
|
3147
|
+
"stack",
|
|
3148
|
+
"cause",
|
|
3149
|
+
"errors"
|
|
3150
|
+
];
|
|
3151
|
+
const normalizeDescriptor = (error, propName) => {
|
|
3152
|
+
const descriptor = getDescriptor(error, propName);
|
|
3153
|
+
if (descriptor === void 0) return;
|
|
3154
|
+
if (isReadonlyGetter(descriptor)) {
|
|
3155
|
+
setErrorProperty(error, propName, error[propName]);
|
|
3040
3156
|
return;
|
|
3041
3157
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
const
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3158
|
+
if (isInvalidDescriptor(descriptor)) setErrorDescriptor(error, propName, descriptor);
|
|
3159
|
+
};
|
|
3160
|
+
const getDescriptor = (value, propName) => {
|
|
3161
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, propName);
|
|
3162
|
+
if (descriptor !== void 0) return descriptor;
|
|
3163
|
+
const prototype = Object.getPrototypeOf(value);
|
|
3164
|
+
return prototype === null ? void 0 : getDescriptor(prototype, propName);
|
|
3165
|
+
};
|
|
3166
|
+
const isReadonlyGetter = ({ get, set }) => get !== void 0 && set === void 0;
|
|
3167
|
+
const isInvalidDescriptor = ({ enumerable, writable }) => enumerable || !writable;
|
|
3168
|
+
const setErrorProperty = (error, propName, value) => {
|
|
3169
|
+
setErrorDescriptor(error, propName, { value });
|
|
3170
|
+
};
|
|
3171
|
+
const setErrorDescriptor = (error, propName, descriptor) => {
|
|
3172
|
+
Object.defineProperty(error, propName, {
|
|
3173
|
+
...descriptor,
|
|
3174
|
+
..."get" in descriptor || "set" in descriptor ? {} : { writable: true },
|
|
3175
|
+
enumerable: false,
|
|
3176
|
+
configurable: true
|
|
3177
|
+
});
|
|
3178
|
+
};
|
|
3179
|
+
//#endregion
|
|
3180
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/aggregate.js
|
|
3181
|
+
const normalizeAggregate = (error, recurse) => {
|
|
3182
|
+
if (Array.isArray(error.errors)) setErrorProperty(error, "errors", error.errors.filter(isDefined).map(recurse).filter(Boolean));
|
|
3183
|
+
else if (isAggregateError(error)) setErrorProperty(error, "errors", []);
|
|
3184
|
+
else if (error.errors !== void 0) deleteAggregateErrors(error);
|
|
3185
|
+
};
|
|
3186
|
+
const isDefined = (error) => error !== void 0;
|
|
3187
|
+
const isAggregateError = (error) => "AggregateError" in globalThis && (error.name === "AggregateError" || error instanceof AggregateError);
|
|
3188
|
+
const deleteAggregateErrors = (error) => {
|
|
3189
|
+
delete error.errors;
|
|
3190
|
+
if (error.errors !== void 0) setErrorProperty(error, "errors", []);
|
|
3191
|
+
};
|
|
3192
|
+
//#endregion
|
|
3193
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/cause.js
|
|
3194
|
+
const normalizeCause = (error, recurse) => {
|
|
3195
|
+
if (!("cause" in error)) return;
|
|
3196
|
+
const cause = error.cause === void 0 ? error.cause : recurse(error.cause);
|
|
3197
|
+
if (cause === void 0) delete error.cause;
|
|
3198
|
+
else setErrorProperty(error, "cause", cause);
|
|
3199
|
+
};
|
|
3200
|
+
//#endregion
|
|
3201
|
+
//#region ../../node_modules/.pnpm/is-error-instance@3.0.1/node_modules/is-error-instance/build/src/main.js
|
|
3202
|
+
const isErrorInstance = (value) => isInstanceOfError(value) || hasErrorTag(value);
|
|
3203
|
+
const isInstanceOfError = (value) => {
|
|
3204
|
+
try {
|
|
3205
|
+
return value instanceof Error;
|
|
3206
|
+
} catch {
|
|
3207
|
+
return false;
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
const hasErrorTag = (value) => {
|
|
3211
|
+
try {
|
|
3212
|
+
return ERROR_TAGS.has(Object.prototype.toString.call(value));
|
|
3213
|
+
} catch {
|
|
3214
|
+
return false;
|
|
3215
|
+
}
|
|
3216
|
+
};
|
|
3217
|
+
const ERROR_TAGS = new Set([
|
|
3218
|
+
"[object Error]",
|
|
3219
|
+
"[object DOMException]",
|
|
3220
|
+
"[object DOMError]",
|
|
3221
|
+
"[object Exception]"
|
|
3222
|
+
]);
|
|
3223
|
+
//#endregion
|
|
3224
|
+
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
3225
|
+
function isPlainObject(value) {
|
|
3226
|
+
if (typeof value !== "object" || value === null) return false;
|
|
3227
|
+
const prototype = Object.getPrototypeOf(value);
|
|
3228
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
3059
3229
|
}
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3230
|
+
//#endregion
|
|
3231
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/modifiable.js
|
|
3232
|
+
const isNonModifiableError = (error) => !Object.isExtensible(error) || CORE_ERROR_PROPS.some((propName) => isNonConfigurableProp(error, propName) || isThrowingProp(error, propName));
|
|
3233
|
+
const isNonConfigurableProp = (error, propName) => {
|
|
3234
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, propName);
|
|
3235
|
+
return descriptor !== void 0 && !descriptor.configurable;
|
|
3236
|
+
};
|
|
3237
|
+
const isThrowingProp = (error, propName) => {
|
|
3238
|
+
try {
|
|
3239
|
+
error[propName];
|
|
3240
|
+
return false;
|
|
3241
|
+
} catch {
|
|
3242
|
+
return true;
|
|
3243
|
+
}
|
|
3244
|
+
};
|
|
3245
|
+
//#endregion
|
|
3246
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/stack.js
|
|
3247
|
+
const setStack = (error) => {
|
|
3248
|
+
setErrorProperty(error, "stack", getStack(error.message, error.name));
|
|
3249
|
+
};
|
|
3250
|
+
const getStack = (message = "", name = "Error") => {
|
|
3251
|
+
const { stack } = new (getErrorClass(name))(message);
|
|
3252
|
+
return typeof stack === "string" && stack !== "" ? stack : `${name}: ${message}`;
|
|
3253
|
+
};
|
|
3254
|
+
const getErrorClass = (name) => {
|
|
3255
|
+
const descriptor = {
|
|
3256
|
+
value: name,
|
|
3257
|
+
enumerable: false,
|
|
3258
|
+
writable: true,
|
|
3259
|
+
configurable: true
|
|
3260
|
+
};
|
|
3261
|
+
const StackError = Object.defineProperty(class extends Error {}, "name", descriptor);
|
|
3262
|
+
Object.defineProperty(StackError.prototype, "name", descriptor);
|
|
3263
|
+
return StackError;
|
|
3264
|
+
};
|
|
3265
|
+
//#endregion
|
|
3266
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/copy.js
|
|
3267
|
+
const copyObject = (object) => {
|
|
3268
|
+
const objectCopy = {};
|
|
3269
|
+
for (const propName of getPropsToCopy(object)) try {
|
|
3270
|
+
const value = object[propName];
|
|
3271
|
+
const { enumerable, configurable, writable = true } = getDescriptor(object, propName);
|
|
3272
|
+
Object.defineProperty(objectCopy, propName, {
|
|
3273
|
+
value,
|
|
3274
|
+
enumerable,
|
|
3275
|
+
configurable,
|
|
3276
|
+
writable
|
|
3277
|
+
});
|
|
3278
|
+
} catch {}
|
|
3279
|
+
return objectCopy;
|
|
3280
|
+
};
|
|
3281
|
+
const getPropsToCopy = (object) => {
|
|
3282
|
+
const propNames = getOwnKeys(object);
|
|
3283
|
+
for (const propName of CORE_ERROR_PROPS) if (isInheritedProp(object, propName)) propNames.push(propName);
|
|
3284
|
+
return propNames;
|
|
3285
|
+
};
|
|
3286
|
+
const getOwnKeys = (object) => {
|
|
3287
|
+
try {
|
|
3288
|
+
return Reflect.ownKeys(object);
|
|
3289
|
+
} catch {
|
|
3290
|
+
return [];
|
|
3291
|
+
}
|
|
3292
|
+
};
|
|
3293
|
+
const isInheritedProp = (object, propName) => {
|
|
3294
|
+
try {
|
|
3295
|
+
return propName in object && !Object.hasOwn(object, propName);
|
|
3296
|
+
} catch {
|
|
3297
|
+
return false;
|
|
3298
|
+
}
|
|
3299
|
+
};
|
|
3300
|
+
//#endregion
|
|
3301
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/object.js
|
|
3302
|
+
const objectifyError = (object) => {
|
|
3303
|
+
const { name, message, stack, cause, errors, ...objectA } = copyObject(object);
|
|
3304
|
+
const messageA = getMessage(message, objectA);
|
|
3305
|
+
const error = newError(name, messageA);
|
|
3306
|
+
if (message === messageA) assignObjectProps(error, objectA);
|
|
3307
|
+
Object.entries({
|
|
3308
|
+
name,
|
|
3309
|
+
stack,
|
|
3310
|
+
cause,
|
|
3311
|
+
errors
|
|
3312
|
+
}).forEach(([propName, propValue]) => {
|
|
3313
|
+
setNewErrorProperty(error, propName, propValue);
|
|
3314
|
+
});
|
|
3315
|
+
if (stack === void 0) setStack(error);
|
|
3316
|
+
return error;
|
|
3317
|
+
};
|
|
3318
|
+
const getMessage = (message, object) => typeof message === "string" && message !== "" ? message : truncateMessage(safeJsonStringify(object));
|
|
3319
|
+
const safeJsonStringify = (object) => {
|
|
3320
|
+
try {
|
|
3321
|
+
return JSON.stringify(object);
|
|
3322
|
+
} catch {
|
|
3323
|
+
return safeStringify(object);
|
|
3324
|
+
}
|
|
3325
|
+
};
|
|
3326
|
+
const safeStringify = (object) => {
|
|
3327
|
+
try {
|
|
3328
|
+
return String(object);
|
|
3329
|
+
} catch {
|
|
3330
|
+
return "Invalid error";
|
|
3068
3331
|
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3332
|
+
};
|
|
3333
|
+
const truncateMessage = (message) => message.length < MESSAGE_MAX_SIZE ? message : `${message.slice(0, MESSAGE_MAX_SIZE)}...`;
|
|
3334
|
+
const MESSAGE_MAX_SIZE = 1e3;
|
|
3335
|
+
const newError = (name, message) => {
|
|
3336
|
+
if (name === "AggregateError" && "AggregateError" in globalThis) return new AggregateError([], message);
|
|
3337
|
+
if (name in NATIVE_ERRORS) return new NATIVE_ERRORS[name](message);
|
|
3338
|
+
return new Error(message);
|
|
3339
|
+
};
|
|
3340
|
+
const NATIVE_ERRORS = {
|
|
3341
|
+
Error,
|
|
3342
|
+
ReferenceError,
|
|
3343
|
+
TypeError,
|
|
3344
|
+
SyntaxError,
|
|
3345
|
+
RangeError,
|
|
3346
|
+
URIError,
|
|
3347
|
+
EvalError
|
|
3348
|
+
};
|
|
3349
|
+
const assignObjectProps = (error, object) => {
|
|
3350
|
+
for (const propName in object) if (!(propName in error)) error[propName] = object[propName];
|
|
3351
|
+
};
|
|
3352
|
+
const setNewErrorProperty = (error, propName, propValue) => {
|
|
3353
|
+
if (propValue !== void 0) setErrorProperty(error, propName, propValue);
|
|
3354
|
+
};
|
|
3355
|
+
//#endregion
|
|
3356
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/string.js
|
|
3357
|
+
const stringifyError = (value) => {
|
|
3358
|
+
try {
|
|
3359
|
+
const error = new Error(String(value));
|
|
3360
|
+
setStack(error);
|
|
3361
|
+
return error;
|
|
3362
|
+
} catch (error_) {
|
|
3363
|
+
return error_;
|
|
3076
3364
|
}
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
}
|
|
3081
|
-
const
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
}
|
|
3093
|
-
});
|
|
3094
|
-
}
|
|
3095
|
-
let pendingHandler;
|
|
3096
|
-
let pendingTimeout;
|
|
3097
|
-
function cancelPendingDriveSelection() {
|
|
3098
|
-
if (pendingHandler) {
|
|
3099
|
-
window.removeEventListener("ph:drivesUpdated", pendingHandler);
|
|
3100
|
-
pendingHandler = void 0;
|
|
3365
|
+
};
|
|
3366
|
+
//#endregion
|
|
3367
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/main.js
|
|
3368
|
+
const { toString: objectToString } = Object.prototype;
|
|
3369
|
+
const createError = (value) => {
|
|
3370
|
+
if (isErrorPlainObj(value)) return objectifyError(value);
|
|
3371
|
+
if (!isErrorInstance(value)) return stringifyError(value);
|
|
3372
|
+
if (isInvalidError(value)) return objectifyError(value);
|
|
3373
|
+
return value;
|
|
3374
|
+
};
|
|
3375
|
+
const isErrorPlainObj = (value) => {
|
|
3376
|
+
try {
|
|
3377
|
+
return isPlainObject(value);
|
|
3378
|
+
} catch {
|
|
3379
|
+
return false;
|
|
3101
3380
|
}
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3381
|
+
};
|
|
3382
|
+
const isInvalidError = (value) => isProxy(value) || isNonModifiableError(value) || hasInvalidConstructor(value);
|
|
3383
|
+
const isProxy = (value) => {
|
|
3384
|
+
try {
|
|
3385
|
+
return objectToString.call(value) === "[object Object]";
|
|
3386
|
+
} catch {
|
|
3387
|
+
return true;
|
|
3105
3388
|
}
|
|
3106
|
-
}
|
|
3107
|
-
function
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3389
|
+
};
|
|
3390
|
+
const hasInvalidConstructor = (error) => typeof error.constructor !== "function" || typeof error.constructor.name !== "string" || error.constructor.name === "" || error.constructor.prototype !== Object.getPrototypeOf(error);
|
|
3391
|
+
//#endregion
|
|
3392
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/main.js
|
|
3393
|
+
const normalizeException = (error, { shallow = false } = {}) => recurseException(error, [], shallow);
|
|
3394
|
+
const recurseException = (error, parents, shallow) => {
|
|
3395
|
+
if (parents.includes(error)) return;
|
|
3396
|
+
const recurse = shallow ? identity : (innerError) => recurseException(innerError, [...parents, error], shallow);
|
|
3397
|
+
const errorA = createError(error);
|
|
3398
|
+
normalizeProps(errorA, recurse);
|
|
3399
|
+
return errorA;
|
|
3400
|
+
};
|
|
3401
|
+
const identity = (error) => error;
|
|
3402
|
+
const normalizeProps = (error, recurse) => {
|
|
3403
|
+
normalizeName(error);
|
|
3404
|
+
normalizeMessage(error);
|
|
3405
|
+
normalizeStack(error);
|
|
3406
|
+
normalizeCause(error, recurse);
|
|
3407
|
+
normalizeAggregate(error, recurse);
|
|
3408
|
+
normalizeDescriptors(error);
|
|
3409
|
+
};
|
|
3410
|
+
const normalizeName = (error) => {
|
|
3411
|
+
if (isDefinedString(error.name)) return;
|
|
3412
|
+
const prototypeName = Object.getPrototypeOf(error).name;
|
|
3413
|
+
setErrorProperty(error, "name", isDefinedString(prototypeName) ? prototypeName : error.constructor.name);
|
|
3414
|
+
};
|
|
3415
|
+
const normalizeMessage = (error) => {
|
|
3416
|
+
if (!isDefinedString(error.message)) setErrorProperty(error, "message", "");
|
|
3417
|
+
};
|
|
3418
|
+
const normalizeStack = (error) => {
|
|
3419
|
+
if (!isDefinedString(error.stack)) setStack(error);
|
|
3420
|
+
};
|
|
3421
|
+
const isDefinedString = (value) => typeof value === "string" && value !== "";
|
|
3422
|
+
//#endregion
|
|
3423
|
+
//#region ../reactor-browser/dist/index.js
|
|
3424
|
+
var import_lz_string = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3425
|
+
var LZString = (function() {
|
|
3426
|
+
var f = String.fromCharCode;
|
|
3427
|
+
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
3428
|
+
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
|
3429
|
+
var baseReverseDic = {};
|
|
3430
|
+
function getBaseValue(alphabet, character) {
|
|
3431
|
+
if (!baseReverseDic[alphabet]) {
|
|
3432
|
+
baseReverseDic[alphabet] = {};
|
|
3433
|
+
for (var i = 0; i < alphabet.length; i++) baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
3434
|
+
}
|
|
3435
|
+
return baseReverseDic[alphabet][character];
|
|
3436
|
+
}
|
|
3437
|
+
var LZString = {
|
|
3438
|
+
compressToBase64: function(input) {
|
|
3439
|
+
if (input == null) return "";
|
|
3440
|
+
var res = LZString._compress(input, 6, function(a) {
|
|
3441
|
+
return keyStrBase64.charAt(a);
|
|
3442
|
+
});
|
|
3443
|
+
switch (res.length % 4) {
|
|
3444
|
+
default:
|
|
3445
|
+
case 0: return res;
|
|
3446
|
+
case 1: return res + "===";
|
|
3447
|
+
case 2: return res + "==";
|
|
3448
|
+
case 3: return res + "=";
|
|
3449
|
+
}
|
|
3450
|
+
},
|
|
3451
|
+
decompressFromBase64: function(input) {
|
|
3452
|
+
if (input == null) return "";
|
|
3453
|
+
if (input == "") return null;
|
|
3454
|
+
return LZString._decompress(input.length, 32, function(index) {
|
|
3455
|
+
return getBaseValue(keyStrBase64, input.charAt(index));
|
|
3456
|
+
});
|
|
3457
|
+
},
|
|
3458
|
+
compressToUTF16: function(input) {
|
|
3459
|
+
if (input == null) return "";
|
|
3460
|
+
return LZString._compress(input, 15, function(a) {
|
|
3461
|
+
return f(a + 32);
|
|
3462
|
+
}) + " ";
|
|
3463
|
+
},
|
|
3464
|
+
decompressFromUTF16: function(compressed) {
|
|
3465
|
+
if (compressed == null) return "";
|
|
3466
|
+
if (compressed == "") return null;
|
|
3467
|
+
return LZString._decompress(compressed.length, 16384, function(index) {
|
|
3468
|
+
return compressed.charCodeAt(index) - 32;
|
|
3469
|
+
});
|
|
3470
|
+
},
|
|
3471
|
+
compressToUint8Array: function(uncompressed) {
|
|
3472
|
+
var compressed = LZString.compress(uncompressed);
|
|
3473
|
+
var buf = new Uint8Array(compressed.length * 2);
|
|
3474
|
+
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
|
|
3475
|
+
var current_value = compressed.charCodeAt(i);
|
|
3476
|
+
buf[i * 2] = current_value >>> 8;
|
|
3477
|
+
buf[i * 2 + 1] = current_value % 256;
|
|
3478
|
+
}
|
|
3479
|
+
return buf;
|
|
3480
|
+
},
|
|
3481
|
+
decompressFromUint8Array: function(compressed) {
|
|
3482
|
+
if (compressed === null || compressed === void 0) return LZString.decompress(compressed);
|
|
3483
|
+
else {
|
|
3484
|
+
var buf = new Array(compressed.length / 2);
|
|
3485
|
+
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
|
|
3486
|
+
var result = [];
|
|
3487
|
+
buf.forEach(function(c) {
|
|
3488
|
+
result.push(f(c));
|
|
3489
|
+
});
|
|
3490
|
+
return LZString.decompress(result.join(""));
|
|
3491
|
+
}
|
|
3492
|
+
},
|
|
3493
|
+
compressToEncodedURIComponent: function(input) {
|
|
3494
|
+
if (input == null) return "";
|
|
3495
|
+
return LZString._compress(input, 6, function(a) {
|
|
3496
|
+
return keyStrUriSafe.charAt(a);
|
|
3497
|
+
});
|
|
3498
|
+
},
|
|
3499
|
+
decompressFromEncodedURIComponent: function(input) {
|
|
3500
|
+
if (input == null) return "";
|
|
3501
|
+
if (input == "") return null;
|
|
3502
|
+
input = input.replace(/ /g, "+");
|
|
3503
|
+
return LZString._decompress(input.length, 32, function(index) {
|
|
3504
|
+
return getBaseValue(keyStrUriSafe, input.charAt(index));
|
|
3505
|
+
});
|
|
3506
|
+
},
|
|
3507
|
+
compress: function(uncompressed) {
|
|
3508
|
+
return LZString._compress(uncompressed, 16, function(a) {
|
|
3509
|
+
return f(a);
|
|
3510
|
+
});
|
|
3511
|
+
},
|
|
3512
|
+
_compress: function(uncompressed, bitsPerChar, getCharFromInt) {
|
|
3513
|
+
if (uncompressed == null) return "";
|
|
3514
|
+
var i, value, context_dictionary = {}, context_dictionaryToCreate = {}, context_c = "", context_wc = "", context_w = "", context_enlargeIn = 2, context_dictSize = 3, context_numBits = 2, context_data = [], context_data_val = 0, context_data_position = 0, ii;
|
|
3515
|
+
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
3516
|
+
context_c = uncompressed.charAt(ii);
|
|
3517
|
+
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
3518
|
+
context_dictionary[context_c] = context_dictSize++;
|
|
3519
|
+
context_dictionaryToCreate[context_c] = true;
|
|
3520
|
+
}
|
|
3521
|
+
context_wc = context_w + context_c;
|
|
3522
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) context_w = context_wc;
|
|
3523
|
+
else {
|
|
3524
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
3525
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
3526
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3527
|
+
context_data_val = context_data_val << 1;
|
|
3528
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3529
|
+
context_data_position = 0;
|
|
3530
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3531
|
+
context_data_val = 0;
|
|
3532
|
+
} else context_data_position++;
|
|
3533
|
+
}
|
|
3534
|
+
value = context_w.charCodeAt(0);
|
|
3535
|
+
for (i = 0; i < 8; i++) {
|
|
3536
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3537
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3538
|
+
context_data_position = 0;
|
|
3539
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3540
|
+
context_data_val = 0;
|
|
3541
|
+
} else context_data_position++;
|
|
3542
|
+
value = value >> 1;
|
|
3543
|
+
}
|
|
3544
|
+
} else {
|
|
3545
|
+
value = 1;
|
|
3546
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3547
|
+
context_data_val = context_data_val << 1 | value;
|
|
3548
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3549
|
+
context_data_position = 0;
|
|
3550
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3551
|
+
context_data_val = 0;
|
|
3552
|
+
} else context_data_position++;
|
|
3553
|
+
value = 0;
|
|
3554
|
+
}
|
|
3555
|
+
value = context_w.charCodeAt(0);
|
|
3556
|
+
for (i = 0; i < 16; i++) {
|
|
3557
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3558
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3559
|
+
context_data_position = 0;
|
|
3560
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3561
|
+
context_data_val = 0;
|
|
3562
|
+
} else context_data_position++;
|
|
3563
|
+
value = value >> 1;
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
context_enlargeIn--;
|
|
3567
|
+
if (context_enlargeIn == 0) {
|
|
3568
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3569
|
+
context_numBits++;
|
|
3570
|
+
}
|
|
3571
|
+
delete context_dictionaryToCreate[context_w];
|
|
3572
|
+
} else {
|
|
3573
|
+
value = context_dictionary[context_w];
|
|
3574
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3575
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3576
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3577
|
+
context_data_position = 0;
|
|
3578
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3579
|
+
context_data_val = 0;
|
|
3580
|
+
} else context_data_position++;
|
|
3581
|
+
value = value >> 1;
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
context_enlargeIn--;
|
|
3585
|
+
if (context_enlargeIn == 0) {
|
|
3586
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3587
|
+
context_numBits++;
|
|
3588
|
+
}
|
|
3589
|
+
context_dictionary[context_wc] = context_dictSize++;
|
|
3590
|
+
context_w = String(context_c);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
if (context_w !== "") {
|
|
3594
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
3595
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
3596
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3597
|
+
context_data_val = context_data_val << 1;
|
|
3598
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3599
|
+
context_data_position = 0;
|
|
3600
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3601
|
+
context_data_val = 0;
|
|
3602
|
+
} else context_data_position++;
|
|
3603
|
+
}
|
|
3604
|
+
value = context_w.charCodeAt(0);
|
|
3605
|
+
for (i = 0; i < 8; i++) {
|
|
3606
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3607
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3608
|
+
context_data_position = 0;
|
|
3609
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3610
|
+
context_data_val = 0;
|
|
3611
|
+
} else context_data_position++;
|
|
3612
|
+
value = value >> 1;
|
|
3613
|
+
}
|
|
3614
|
+
} else {
|
|
3615
|
+
value = 1;
|
|
3616
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3617
|
+
context_data_val = context_data_val << 1 | value;
|
|
3618
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3619
|
+
context_data_position = 0;
|
|
3620
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3621
|
+
context_data_val = 0;
|
|
3622
|
+
} else context_data_position++;
|
|
3623
|
+
value = 0;
|
|
3624
|
+
}
|
|
3625
|
+
value = context_w.charCodeAt(0);
|
|
3626
|
+
for (i = 0; i < 16; i++) {
|
|
3627
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3628
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3629
|
+
context_data_position = 0;
|
|
3630
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3631
|
+
context_data_val = 0;
|
|
3632
|
+
} else context_data_position++;
|
|
3633
|
+
value = value >> 1;
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
context_enlargeIn--;
|
|
3637
|
+
if (context_enlargeIn == 0) {
|
|
3638
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3639
|
+
context_numBits++;
|
|
3640
|
+
}
|
|
3641
|
+
delete context_dictionaryToCreate[context_w];
|
|
3642
|
+
} else {
|
|
3643
|
+
value = context_dictionary[context_w];
|
|
3644
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3645
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3646
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3647
|
+
context_data_position = 0;
|
|
3648
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3649
|
+
context_data_val = 0;
|
|
3650
|
+
} else context_data_position++;
|
|
3651
|
+
value = value >> 1;
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
context_enlargeIn--;
|
|
3655
|
+
if (context_enlargeIn == 0) {
|
|
3656
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3657
|
+
context_numBits++;
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
value = 2;
|
|
3661
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3662
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3663
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3664
|
+
context_data_position = 0;
|
|
3665
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3666
|
+
context_data_val = 0;
|
|
3667
|
+
} else context_data_position++;
|
|
3668
|
+
value = value >> 1;
|
|
3669
|
+
}
|
|
3670
|
+
while (true) {
|
|
3671
|
+
context_data_val = context_data_val << 1;
|
|
3672
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3673
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3674
|
+
break;
|
|
3675
|
+
} else context_data_position++;
|
|
3676
|
+
}
|
|
3677
|
+
return context_data.join("");
|
|
3678
|
+
},
|
|
3679
|
+
decompress: function(compressed) {
|
|
3680
|
+
if (compressed == null) return "";
|
|
3681
|
+
if (compressed == "") return null;
|
|
3682
|
+
return LZString._decompress(compressed.length, 32768, function(index) {
|
|
3683
|
+
return compressed.charCodeAt(index);
|
|
3684
|
+
});
|
|
3685
|
+
},
|
|
3686
|
+
_decompress: function(length, resetValue, getNextValue) {
|
|
3687
|
+
var dictionary = [], enlargeIn = 4, dictSize = 4, numBits = 3, entry = "", result = [], i, w, bits, resb, maxpower, power, c, data = {
|
|
3688
|
+
val: getNextValue(0),
|
|
3689
|
+
position: resetValue,
|
|
3690
|
+
index: 1
|
|
3691
|
+
};
|
|
3692
|
+
for (i = 0; i < 3; i += 1) dictionary[i] = i;
|
|
3693
|
+
bits = 0;
|
|
3694
|
+
maxpower = Math.pow(2, 2);
|
|
3695
|
+
power = 1;
|
|
3696
|
+
while (power != maxpower) {
|
|
3697
|
+
resb = data.val & data.position;
|
|
3698
|
+
data.position >>= 1;
|
|
3699
|
+
if (data.position == 0) {
|
|
3700
|
+
data.position = resetValue;
|
|
3701
|
+
data.val = getNextValue(data.index++);
|
|
3702
|
+
}
|
|
3703
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3704
|
+
power <<= 1;
|
|
3705
|
+
}
|
|
3706
|
+
switch (bits) {
|
|
3707
|
+
case 0:
|
|
3708
|
+
bits = 0;
|
|
3709
|
+
maxpower = Math.pow(2, 8);
|
|
3710
|
+
power = 1;
|
|
3711
|
+
while (power != maxpower) {
|
|
3712
|
+
resb = data.val & data.position;
|
|
3713
|
+
data.position >>= 1;
|
|
3714
|
+
if (data.position == 0) {
|
|
3715
|
+
data.position = resetValue;
|
|
3716
|
+
data.val = getNextValue(data.index++);
|
|
3717
|
+
}
|
|
3718
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3719
|
+
power <<= 1;
|
|
3720
|
+
}
|
|
3721
|
+
c = f(bits);
|
|
3722
|
+
break;
|
|
3723
|
+
case 1:
|
|
3724
|
+
bits = 0;
|
|
3725
|
+
maxpower = Math.pow(2, 16);
|
|
3726
|
+
power = 1;
|
|
3727
|
+
while (power != maxpower) {
|
|
3728
|
+
resb = data.val & data.position;
|
|
3729
|
+
data.position >>= 1;
|
|
3730
|
+
if (data.position == 0) {
|
|
3731
|
+
data.position = resetValue;
|
|
3732
|
+
data.val = getNextValue(data.index++);
|
|
3733
|
+
}
|
|
3734
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3735
|
+
power <<= 1;
|
|
3736
|
+
}
|
|
3737
|
+
c = f(bits);
|
|
3738
|
+
break;
|
|
3739
|
+
case 2: return "";
|
|
3740
|
+
}
|
|
3741
|
+
dictionary[3] = c;
|
|
3742
|
+
w = c;
|
|
3743
|
+
result.push(c);
|
|
3744
|
+
while (true) {
|
|
3745
|
+
if (data.index > length) return "";
|
|
3746
|
+
bits = 0;
|
|
3747
|
+
maxpower = Math.pow(2, numBits);
|
|
3748
|
+
power = 1;
|
|
3749
|
+
while (power != maxpower) {
|
|
3750
|
+
resb = data.val & data.position;
|
|
3751
|
+
data.position >>= 1;
|
|
3752
|
+
if (data.position == 0) {
|
|
3753
|
+
data.position = resetValue;
|
|
3754
|
+
data.val = getNextValue(data.index++);
|
|
3755
|
+
}
|
|
3756
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3757
|
+
power <<= 1;
|
|
3758
|
+
}
|
|
3759
|
+
switch (c = bits) {
|
|
3760
|
+
case 0:
|
|
3761
|
+
bits = 0;
|
|
3762
|
+
maxpower = Math.pow(2, 8);
|
|
3763
|
+
power = 1;
|
|
3764
|
+
while (power != maxpower) {
|
|
3765
|
+
resb = data.val & data.position;
|
|
3766
|
+
data.position >>= 1;
|
|
3767
|
+
if (data.position == 0) {
|
|
3768
|
+
data.position = resetValue;
|
|
3769
|
+
data.val = getNextValue(data.index++);
|
|
3770
|
+
}
|
|
3771
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3772
|
+
power <<= 1;
|
|
3773
|
+
}
|
|
3774
|
+
dictionary[dictSize++] = f(bits);
|
|
3775
|
+
c = dictSize - 1;
|
|
3776
|
+
enlargeIn--;
|
|
3777
|
+
break;
|
|
3778
|
+
case 1:
|
|
3779
|
+
bits = 0;
|
|
3780
|
+
maxpower = Math.pow(2, 16);
|
|
3781
|
+
power = 1;
|
|
3782
|
+
while (power != maxpower) {
|
|
3783
|
+
resb = data.val & data.position;
|
|
3784
|
+
data.position >>= 1;
|
|
3785
|
+
if (data.position == 0) {
|
|
3786
|
+
data.position = resetValue;
|
|
3787
|
+
data.val = getNextValue(data.index++);
|
|
3788
|
+
}
|
|
3789
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3790
|
+
power <<= 1;
|
|
3791
|
+
}
|
|
3792
|
+
dictionary[dictSize++] = f(bits);
|
|
3793
|
+
c = dictSize - 1;
|
|
3794
|
+
enlargeIn--;
|
|
3795
|
+
break;
|
|
3796
|
+
case 2: return result.join("");
|
|
3797
|
+
}
|
|
3798
|
+
if (enlargeIn == 0) {
|
|
3799
|
+
enlargeIn = Math.pow(2, numBits);
|
|
3800
|
+
numBits++;
|
|
3801
|
+
}
|
|
3802
|
+
if (dictionary[c]) entry = dictionary[c];
|
|
3803
|
+
else if (c === dictSize) entry = w + w.charAt(0);
|
|
3804
|
+
else return null;
|
|
3805
|
+
result.push(entry);
|
|
3806
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
3807
|
+
enlargeIn--;
|
|
3808
|
+
w = entry;
|
|
3809
|
+
if (enlargeIn == 0) {
|
|
3810
|
+
enlargeIn = Math.pow(2, numBits);
|
|
3811
|
+
numBits++;
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3124
3814
|
}
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
};
|
|
3131
|
-
scheduleTick();
|
|
3132
|
-
}
|
|
3133
|
-
function useDropTarget() {
|
|
3134
|
-
const [isDropTarget, setIsDropTarget] = useState(false);
|
|
3135
|
-
const isDragAndDropEnabled = useIsDragAndDropEnabled();
|
|
3136
|
-
const targetSetter = n$1(() => setIsDropTarget(true), {
|
|
3137
|
-
triggerAt: "start",
|
|
3138
|
-
minQuietPeriodMs: 100
|
|
3815
|
+
};
|
|
3816
|
+
return LZString;
|
|
3817
|
+
})();
|
|
3818
|
+
if (typeof define === "function" && define.amd) define(function() {
|
|
3819
|
+
return LZString;
|
|
3139
3820
|
});
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3821
|
+
else if (typeof module !== "undefined" && module != null) module.exports = LZString;
|
|
3822
|
+
else if (typeof angular !== "undefined" && angular != null) angular.module("LZString", []).factory("LZString", function() {
|
|
3823
|
+
return LZString;
|
|
3143
3824
|
});
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
targetSetter.call();
|
|
3148
|
-
}
|
|
3149
|
-
function unsetTarget() {
|
|
3150
|
-
if (!isDragAndDropEnabled) return;
|
|
3151
|
-
targetSetter.cancel();
|
|
3152
|
-
targetUnsetter.call();
|
|
3153
|
-
}
|
|
3154
|
-
return {
|
|
3155
|
-
isDropTarget,
|
|
3156
|
-
setTarget,
|
|
3157
|
-
unsetTarget
|
|
3158
|
-
};
|
|
3159
|
-
}
|
|
3160
|
-
const draggingNodeEventFunctions = makePHEventFunctions("draggingNode");
|
|
3161
|
-
const useDraggingNode = draggingNodeEventFunctions.useValue;
|
|
3162
|
-
const setDraggingNode = draggingNodeEventFunctions.setValue;
|
|
3163
|
-
draggingNodeEventFunctions.addEventHandler;
|
|
3164
|
-
const draggingNodeSetter = n$1((node) => setDraggingNode(node), {
|
|
3165
|
-
reducer: (_, newNode) => newNode,
|
|
3166
|
-
triggerAt: "start",
|
|
3167
|
-
minQuietPeriodMs: 100
|
|
3168
|
-
});
|
|
3169
|
-
const draggingNodeUnsetter = n$1(() => setDraggingNode(void 0), {
|
|
3170
|
-
triggerAt: "start",
|
|
3171
|
-
minQuietPeriodMs: 100
|
|
3172
|
-
});
|
|
3173
|
-
function setDragging(node) {
|
|
3174
|
-
draggingNodeUnsetter.cancel();
|
|
3175
|
-
draggingNodeSetter.call(node);
|
|
3176
|
-
}
|
|
3177
|
-
function unsetDragging() {
|
|
3178
|
-
draggingNodeSetter.cancel();
|
|
3179
|
-
draggingNodeUnsetter.call();
|
|
3180
|
-
}
|
|
3181
|
-
const isNodeDrag = (params) => t$3(params, [({ srcId }) => e$3(e$1)(srcId), e$6(false)], [({ driveId }) => e$3(e$1)(driveId), e$6(false)], [({ driveId, srcId }) => t(driveId, srcId), e$6(false)], e$6(true));
|
|
3182
|
-
function useDragNode(args) {
|
|
3183
|
-
const { srcId, parentId } = args;
|
|
3184
|
-
const driveId = useSelectedDriveId();
|
|
3185
|
-
const draggingNodeId = useDraggingNode()?.srcId;
|
|
3186
|
-
const params = {
|
|
3187
|
-
driveId,
|
|
3188
|
-
srcId,
|
|
3189
|
-
parentId
|
|
3190
|
-
};
|
|
3191
|
-
const draggable = isNodeDrag(params);
|
|
3192
|
-
const isDragging = t$4({
|
|
3193
|
-
srcId,
|
|
3194
|
-
draggingNodeId
|
|
3195
|
-
}, [
|
|
3196
|
-
() => draggable,
|
|
3197
|
-
({ srcId }) => e$2(srcId),
|
|
3198
|
-
({ draggingNodeId }) => e$2(draggingNodeId),
|
|
3199
|
-
({ srcId, draggingNodeId }) => t(srcId, draggingNodeId)
|
|
3200
|
-
]);
|
|
3201
|
-
const onDragStart = () => {
|
|
3202
|
-
if (!draggable) return;
|
|
3203
|
-
setDragging(params);
|
|
3204
|
-
};
|
|
3205
|
-
const onDragEnd = () => {
|
|
3206
|
-
if (!draggable) return;
|
|
3207
|
-
unsetDragging();
|
|
3208
|
-
};
|
|
3209
|
-
return {
|
|
3210
|
-
isDragging,
|
|
3211
|
-
draggable,
|
|
3212
|
-
onDragStart,
|
|
3213
|
-
onDragEnd
|
|
3214
|
-
};
|
|
3215
|
-
}
|
|
3216
|
-
const isNodeDrop = (params) => t$3(params, [({ srcId }) => e$3(e$1)(srcId), e$6(false)], [({ driveId }) => e$3(e$4)(driveId), e$6(false)], [({ srcId, targetId }) => t(srcId, targetId), e$6(false)], [({ driveId, parentId, targetId }) => e$3(e$1)(parentId) && t(targetId, driveId), e$6(false)], [({ targetId, parentId }) => t(targetId, parentId), e$6(false)], e$6(true));
|
|
3217
|
-
function useDropNode(targetId) {
|
|
3218
|
-
const driveId = useSelectedDriveId();
|
|
3219
|
-
const { srcId, parentId } = useDraggingNode() ?? {};
|
|
3220
|
-
const { isDropTarget, setTarget, unsetTarget } = useDropTarget();
|
|
3221
|
-
const params = {
|
|
3222
|
-
driveId,
|
|
3223
|
-
parentId,
|
|
3224
|
-
targetId,
|
|
3225
|
-
srcId
|
|
3226
|
-
};
|
|
3227
|
-
function handleNodeDrop(event, cb) {
|
|
3228
|
-
if (!isNodeDrop(params)) return;
|
|
3229
|
-
event.preventDefault();
|
|
3230
|
-
event.stopPropagation();
|
|
3231
|
-
cb?.();
|
|
3232
|
-
}
|
|
3233
|
-
const onDragEnter = (event) => handleNodeDrop(event);
|
|
3234
|
-
const onDragOver = (event) => handleNodeDrop(event, e(setTarget));
|
|
3235
|
-
const onDragLeave = (event) => handleNodeDrop(event, e(unsetTarget));
|
|
3236
|
-
const onDrop = (event) => handleNodeDrop(event, e(() => {
|
|
3237
|
-
unsetDragging();
|
|
3238
|
-
unsetTarget();
|
|
3239
|
-
moveNodeById(params).catch(console.error);
|
|
3240
|
-
}));
|
|
3241
|
-
return {
|
|
3242
|
-
isDropTarget,
|
|
3243
|
-
onDragEnter,
|
|
3244
|
-
onDragOver,
|
|
3245
|
-
onDragLeave,
|
|
3246
|
-
onDrop
|
|
3247
|
-
};
|
|
3248
|
-
}
|
|
3249
|
-
const graphQLReactorClientEventFunctions = makePHEventFunctions("reactorGraphQLClient");
|
|
3250
|
-
graphQLReactorClientEventFunctions.useValue;
|
|
3251
|
-
graphQLReactorClientEventFunctions.setValue;
|
|
3252
|
-
graphQLReactorClientEventFunctions.addEventHandler;
|
|
3253
|
-
const packageDiscoveryFunctions = makePHEventFunctions("packageDiscoveryService");
|
|
3254
|
-
packageDiscoveryFunctions.useValue;
|
|
3255
|
-
packageDiscoveryFunctions.setValue;
|
|
3256
|
-
packageDiscoveryFunctions.addEventHandler;
|
|
3257
|
-
const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
|
|
3258
|
-
const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
|
|
3259
|
-
/** Returns the reactor client module (in-process or worker-backed) */
|
|
3260
|
-
const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
|
|
3261
|
-
reactorClientModuleEventFunctions.setValue;
|
|
3262
|
-
reactorClientModuleEventFunctions.addEventHandler;
|
|
3263
|
-
reactorClientEventFunctions.useValue;
|
|
3264
|
-
reactorClientEventFunctions.setValue;
|
|
3265
|
-
reactorClientEventFunctions.addEventHandler;
|
|
3266
|
-
const useSync = () => useReactorClientModule()?.reactorModule?.syncModule?.syncManager;
|
|
3267
|
-
const useSyncList = () => {
|
|
3268
|
-
return useSync()?.list() ?? [];
|
|
3269
|
-
};
|
|
3270
|
-
const revisionHistoryEventFunctions = makePHEventFunctions("revisionHistoryVisible");
|
|
3271
|
-
revisionHistoryEventFunctions.useValue;
|
|
3272
|
-
/** Sets revision history visibility */
|
|
3273
|
-
const setRevisionHistoryVisible = revisionHistoryEventFunctions.setValue;
|
|
3274
|
-
revisionHistoryEventFunctions.addEventHandler;
|
|
3275
|
-
/** Shows the revision history */
|
|
3276
|
-
function showRevisionHistory() {
|
|
3277
|
-
setRevisionHistoryVisible(true);
|
|
3278
|
-
}
|
|
3279
|
-
/** Sorts nodes by name. */
|
|
3280
|
-
function sortNodesByName(nodes) {
|
|
3281
|
-
return nodes.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
3282
|
-
}
|
|
3283
|
-
/** Returns whether a node is a file. */
|
|
3284
|
-
function isFileNodeKind(node) {
|
|
3285
|
-
if (!node) return false;
|
|
3286
|
-
return node.kind.toUpperCase() === "FILE";
|
|
3287
|
-
}
|
|
3288
|
-
/** Returns whether a node is a folder. */
|
|
3289
|
-
function isFolderNodeKind(node) {
|
|
3290
|
-
if (!node) return false;
|
|
3291
|
-
return node.kind.toUpperCase() === "FOLDER";
|
|
3292
|
-
}
|
|
3293
|
-
/** Returns the nodes in the selected drive. */
|
|
3294
|
-
function useNodesInSelectedDrive() {
|
|
3295
|
-
const [selectedDrive] = useSelectedDriveSafe();
|
|
3296
|
-
return selectedDrive?.state.global.nodes;
|
|
3297
|
-
}
|
|
3298
|
-
/** Returns the folder nodes in the selected drive. */
|
|
3299
|
-
function useFolderNodesInSelectedDrive() {
|
|
3300
|
-
return useNodesInSelectedDrive()?.filter((n) => isFolderNodeKind(n));
|
|
3301
|
-
}
|
|
3302
|
-
/** Returns the selected node. */
|
|
3303
|
-
function useSelectedNode() {
|
|
3304
|
-
const selectedNodeId = useSelectedNodeId();
|
|
3305
|
-
return useNodesInSelectedDrive()?.find((n) => n.id === selectedNodeId);
|
|
3306
|
-
}
|
|
3307
|
-
const selectedTimelineItemEventFunctions = makePHEventFunctions("selectedTimelineItem");
|
|
3308
|
-
selectedTimelineItemEventFunctions.useValue;
|
|
3309
|
-
selectedTimelineItemEventFunctions.setValue;
|
|
3310
|
-
selectedTimelineItemEventFunctions.addEventHandler;
|
|
3311
|
-
const selectedTimelineRevisionEventFunctions = makePHEventFunctions("selectedTimelineRevision");
|
|
3312
|
-
selectedTimelineRevisionEventFunctions.useValue;
|
|
3313
|
-
selectedTimelineRevisionEventFunctions.setValue;
|
|
3314
|
-
selectedTimelineRevisionEventFunctions.addEventHandler;
|
|
3315
|
-
const toastEventFunctions = makePHEventFunctions("toast");
|
|
3316
|
-
/** Returns the toast function */
|
|
3317
|
-
const usePHToast = toastEventFunctions.useValue;
|
|
3318
|
-
toastEventFunctions.setValue;
|
|
3319
|
-
toastEventFunctions.addEventHandler;
|
|
3320
|
-
const vetraPackageManagerFunctions = makePHEventFunctions("vetraPackageManager");
|
|
3321
|
-
const useVetraPackageManager = vetraPackageManagerFunctions.useValue;
|
|
3322
|
-
/** Returns all of the Vetra packages loaded by the Connect instance */
|
|
3323
|
-
const useVetraPackages = () => {
|
|
3324
|
-
const packageManager = useVetraPackageManager();
|
|
3325
|
-
return useSyncExternalStore((cb) => packageManager ? packageManager.subscribe(cb) : () => {}, () => packageManager?.packages ?? []);
|
|
3326
|
-
};
|
|
3327
|
-
vetraPackageManagerFunctions.addEventHandler;
|
|
3328
|
-
function useDocumentModelModules() {
|
|
3329
|
-
return useVetraPackages().flatMap((pkg) => pkg.documentModels).filter((module, index, modules) => modules.findIndex((m) => m.documentModel.global.id === module.documentModel.global.id && m.version === module.version) === index);
|
|
3330
|
-
}
|
|
3331
|
-
function useDocumentModelModuleById(id) {
|
|
3332
|
-
return useDocumentModelModules()?.find((module) => module.documentModel.global.id === id);
|
|
3333
|
-
}
|
|
3825
|
+
})))(), 1);
|
|
3826
|
+
/** Document types that represent a "drive": a container of nodes. */
|
|
3827
|
+
const DRIVE_DOCUMENT_TYPES = ["powerhouse/document-drive", "powerhouse/reactor-drive"];
|
|
3334
3828
|
function useAllowedDocumentModelModules() {
|
|
3335
3829
|
const documentModelModules = useDocumentModelModules();
|
|
3336
3830
|
const allowedDocumentTypes = useAllowedDocumentTypes();
|
|
@@ -3406,6 +3900,50 @@ function useDocumentOfType(documentId, documentType) {
|
|
|
3406
3900
|
if (document.header.documentType !== documentType) throw new DocumentTypeMismatchError(documentId, documentType, document.header.documentType);
|
|
3407
3901
|
return [document, dispatch];
|
|
3408
3902
|
}
|
|
3903
|
+
/**
|
|
3904
|
+
* Classifies a document's model version against the installed module
|
|
3905
|
+
* versions. Pure logic, extracted for testing.
|
|
3906
|
+
*/
|
|
3907
|
+
function getDocumentVersionStatus(documentVersion, availableVersions, hasUpgradePath) {
|
|
3908
|
+
if (availableVersions.length === 0) return;
|
|
3909
|
+
const sorted = [...availableVersions].sort((a, b) => a - b);
|
|
3910
|
+
const latestVersion = sorted[sorted.length - 1];
|
|
3911
|
+
if (documentVersion > latestVersion) return {
|
|
3912
|
+
kind: "unsupported",
|
|
3913
|
+
documentVersion,
|
|
3914
|
+
availableVersions: sorted
|
|
3915
|
+
};
|
|
3916
|
+
if (documentVersion === latestVersion) return {
|
|
3917
|
+
kind: "current",
|
|
3918
|
+
documentVersion
|
|
3919
|
+
};
|
|
3920
|
+
return {
|
|
3921
|
+
kind: "upgrade-available",
|
|
3922
|
+
documentVersion,
|
|
3923
|
+
latestVersion,
|
|
3924
|
+
canUpgrade: hasUpgradePath(documentVersion, latestVersion)
|
|
3925
|
+
};
|
|
3926
|
+
}
|
|
3927
|
+
/**
|
|
3928
|
+
* Compares the given document's model version against the versions available
|
|
3929
|
+
* from installed Vetra packages. Returns undefined while packages load or
|
|
3930
|
+
* when the document type has no installed modules.
|
|
3931
|
+
*/
|
|
3932
|
+
function useDocumentVersionStatus(document) {
|
|
3933
|
+
const modules = useDocumentModelModules();
|
|
3934
|
+
const registry = useModelRegistry();
|
|
3935
|
+
if (!document || !modules) return;
|
|
3936
|
+
const documentType = document.header.documentType;
|
|
3937
|
+
return getDocumentVersionStatus(document.state.document.version || 1, modules.filter((m) => m.documentModel.global.id === documentType).map((m) => m.version ?? 1), (fromVersion, toVersion) => {
|
|
3938
|
+
if (!registry) return false;
|
|
3939
|
+
try {
|
|
3940
|
+
registry.computeUpgradePath(documentType, fromVersion, toVersion);
|
|
3941
|
+
return true;
|
|
3942
|
+
} catch {
|
|
3943
|
+
return false;
|
|
3944
|
+
}
|
|
3945
|
+
});
|
|
3946
|
+
}
|
|
3409
3947
|
const validateDocument = (document) => {
|
|
3410
3948
|
const errors = [];
|
|
3411
3949
|
if (document.header.documentType !== "powerhouse/document-model") return errors;
|
|
@@ -3511,11 +4049,11 @@ function useNodeActions() {
|
|
|
3511
4049
|
const drives = useDrives();
|
|
3512
4050
|
async function onAddFile(file, parent) {
|
|
3513
4051
|
if (!selectedDriveId) return;
|
|
3514
|
-
return
|
|
4052
|
+
return addFileWithProgress(file, selectedDriveId, file.name.replace(/\..+/gim, ""), resolveNode(selectedDriveId, parent)?.id, void 0, void 0, "duplicate");
|
|
3515
4053
|
}
|
|
3516
4054
|
async function onAddFolder(name, parent) {
|
|
3517
4055
|
if (!selectedDriveId) return;
|
|
3518
|
-
return addFolder(selectedDriveId, name, resolveNode(selectedDriveId, parent)?.id);
|
|
4056
|
+
return addFolder$1(selectedDriveId, name, resolveNode(selectedDriveId, parent)?.id);
|
|
3519
4057
|
}
|
|
3520
4058
|
async function onRenameNode(newName, node) {
|
|
3521
4059
|
if (!selectedDriveId) return;
|
|
@@ -3602,6 +4140,9 @@ function useSelectedNodePath() {
|
|
|
3602
4140
|
function useNodeParentFolderById(id) {
|
|
3603
4141
|
return useFolderById(useNodeById(id)?.parentFolder);
|
|
3604
4142
|
}
|
|
4143
|
+
function useParentFolderForSelectedNode() {
|
|
4144
|
+
return useNodeParentFolderById(useSelectedNode()?.id);
|
|
4145
|
+
}
|
|
3605
4146
|
/** Returns the selected document id */
|
|
3606
4147
|
function useSelectedDocumentId() {
|
|
3607
4148
|
const selectedNode = useSelectedNode();
|
|
@@ -3830,6 +4371,6 @@ function createDebouncedRefreshReactorDataClient(debounceDelayMs = DEFAULT_DEBOU
|
|
|
3830
4371
|
createDebouncedRefreshReactorData();
|
|
3831
4372
|
createDebouncedRefreshReactorDataClient();
|
|
3832
4373
|
//#endregion
|
|
3833
|
-
export {
|
|
4374
|
+
export { showRevisionHistory as A, t$2 as B, addFolder$1 as C, setSelectedNode as D, setSelectedDrive as E, useSelectedDriveId as F, useDocumentById as H, useSelectedDriveSafe as I, useStudioMode as L, useDragNode as M, useDropNode as N, showDeleteNodeModal as O, usePHToast as P, e$1 as R, addDocument as S, isFolderNodeKind as T, t$5 as V, useSelectedNodePath as _, useDownloadDocument as a, useTheme as b, useGetSwitchboardLink as c, useNodeParentFolderById as d, useNodesInSelectedDriveOrFolder as f, useSelectedFolder as g, useSelectedDocumentSafe as h, useDocumentVersionStatus as i, useDisabledEditors as j, showPHModal as k, useNodeActions as l, useSelectedDocumentOfType as m, preloadEditorModule as n, useEditorModules as o, useParentFolderForSelectedNode as p, useAllowedDocumentModelModules as r, useEditorModulesForDocumentType as s, getSyncStatusSync as t, useNodeById as u, useSetPHAppConfig as v, isFileNodeKind as w, useUserPermissions as x, useSetPHDocumentEditorConfig as y, e$4 as z };
|
|
3834
4375
|
|
|
3835
|
-
//# sourceMappingURL=dist-
|
|
4376
|
+
//# sourceMappingURL=dist-CNlIJlyu.mjs.map
|