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