@powerhousedao/powerhouse-vetra-packages 6.2.2-dev.3 → 6.2.2-dev.31
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-DHGZGzZJ.js → entry-Dk9VPWLt.js} +3 -2
- package/dist/browser/assets/{projection-entry-BLjins10.js → projection-entry-MT1aNJTP.js} +3 -3
- package/dist/browser/{connect-CV-z3DqA.js → connect-18dnhTvv.js} +7 -7
- package/dist/browser/{connect-CV-z3DqA.js.map → connect-18dnhTvv.js.map} +1 -1
- 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/browser/{dist-BEs8jMgM.js → dist-Bb4BpVo4.js} +1587 -1446
- package/dist/browser/dist-Bb4BpVo4.js.map +1 -0
- package/dist/browser/{dist-D8H48e8N.js → dist-D0oeNPlN.js} +1 -1
- package/dist/browser/{dist-D8H48e8N.js.map → dist-D0oeNPlN.js.map} +1 -1
- package/dist/browser/{document-drive-sTKoi6L4.js → document-drive-QCAIGn3V.js} +661 -115
- package/dist/browser/document-drive-QCAIGn3V.js.map +1 -0
- package/dist/browser/document-models/index.js +1 -1
- package/dist/browser/{documents-D4ek7Ubv.js → documents-j_qy61X1.js} +23 -622
- package/dist/browser/documents-j_qy61X1.js.map +1 -0
- package/dist/browser/{editor-Cw38euRs.js → editor-D51YfIF2.js} +10 -10
- package/dist/browser/{editor-Cw38euRs.js.map → editor-D51YfIF2.js.map} +1 -1
- package/dist/browser/{editor-DY3JsQJ3.js → editor-DjSiIu0z.js} +5 -5
- package/dist/browser/{editor-DY3JsQJ3.js.map → editor-DjSiIu0z.js.map} +1 -1
- package/dist/browser/editors/document-model-editor/module.js +1 -1
- package/dist/browser/editors/generic-drive-explorer/index.js +11 -11
- package/dist/browser/editors/generic-drive-explorer/index.js.map +1 -1
- package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
- package/dist/browser/{folder-view-BQWrt8wh.js → folder-view-ChRoMADe.js} +4 -4
- package/dist/browser/{folder-view-BQWrt8wh.js.map → folder-view-ChRoMADe.js.map} +1 -1
- package/dist/browser/{graphql-editor-B-dNI5hD.js → graphql-editor-w2rhkOCs.js} +8 -7
- package/dist/browser/{graphql-editor-B-dNI5hD.js.map → graphql-editor-w2rhkOCs.js.map} +1 -1
- package/dist/browser/{hooks-CORHBNHb.js → hooks-BgIeO-WG.js} +2 -2
- package/dist/browser/{hooks-CORHBNHb.js.map → hooks-BgIeO-WG.js.map} +1 -1
- package/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/{json-editor-v_MnzQVs.js → json-editor-DRf8YDRR.js} +4 -4
- package/dist/browser/{json-editor-v_MnzQVs.js.map → json-editor-DRf8YDRR.js.map} +1 -1
- package/dist/browser/{lib-C-f3izXz.js → lib-Dx4DRbGl.js} +2 -2
- package/dist/browser/lib-Dx4DRbGl.js.map +1 -0
- package/dist/browser/{linting-Dn6pXRkK.js → linting-nOwKxGXw.js} +6 -5
- package/dist/browser/{linting-Dn6pXRkK.js.map → linting-nOwKxGXw.js.map} +1 -1
- 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-ClCYFYSx.js} +2 -2
- package/dist/browser/{schema-context-DY-GEGnY.js.map → schema-context-ClCYFYSx.js.map} +1 -1
- package/dist/browser/{state-schemas-65Tp0ZuG.js → state-schemas-B85E8mUI.js} +7 -7
- package/dist/browser/{state-schemas-65Tp0ZuG.js.map → state-schemas-B85E8mUI.js.map} +1 -1
- package/dist/node/{connect-Bbi5wHyR.mjs → connect-gtpzJcyJ.mjs} +6 -6
- package/dist/node/{connect-Bbi5wHyR.mjs.map → connect-gtpzJcyJ.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/{dist-8nCvrie2.mjs → dist-WP8o0IHv.mjs} +1592 -1446
- package/dist/node/dist-WP8o0IHv.mjs.map +1 -0
- package/dist/node/{document-drive-DjL9iikf.mjs → document-drive-DIiMiIkb.mjs} +661 -115
- package/dist/node/document-drive-DIiMiIkb.mjs.map +1 -0
- package/dist/node/document-models/index.mjs +1 -1
- package/dist/node/{documents-BFBPmyw1.mjs → documents-Bh_lxLTV.mjs} +21 -21
- package/dist/node/{documents-BFBPmyw1.mjs.map → documents-Bh_lxLTV.mjs.map} +1 -1
- package/dist/node/{editor-DkT0krRE.mjs → editor-BsQ46sh0.mjs} +9 -9
- package/dist/node/{editor-DkT0krRE.mjs.map → editor-BsQ46sh0.mjs.map} +1 -1
- package/dist/node/{editor-BH2gCDjt.mjs → editor-FWPVCfe3.mjs} +5 -5
- package/dist/node/{editor-BH2gCDjt.mjs.map → editor-FWPVCfe3.mjs.map} +1 -1
- package/dist/node/editors/document-model-editor/module.mjs +1 -1
- package/dist/node/editors/generic-drive-explorer/index.mjs +11 -11
- package/dist/node/editors/generic-drive-explorer/index.mjs.map +1 -1
- package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
- package/dist/node/{folder-view-DjKO1mAh.mjs → folder-view-BSTPPsS1.mjs} +3 -3
- package/dist/node/{folder-view-DjKO1mAh.mjs.map → folder-view-BSTPPsS1.mjs.map} +1 -1
- 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-x-d_DoqN.mjs → graphql-editor-DH27mK8m.mjs} +7 -7
- package/dist/node/{graphql-editor-x-d_DoqN.mjs.map → graphql-editor-DH27mK8m.mjs.map} +1 -1
- package/dist/node/{hooks-DJrjfVaS.mjs → hooks-B7KF2A2g.mjs} +2 -2
- package/dist/node/{hooks-DJrjfVaS.mjs.map → hooks-B7KF2A2g.mjs.map} +1 -1
- package/dist/node/index.mjs +2 -2
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/{json-editor-D8QbP3jl.mjs → json-editor-DmlYJpDQ.mjs} +4 -4
- package/dist/node/{json-editor-D8QbP3jl.mjs.map → json-editor-DmlYJpDQ.mjs.map} +1 -1
- package/dist/node/{linting-Dx50GuLN.mjs → linting-D6drcQHM.mjs} +6 -6
- package/dist/node/{linting-Dx50GuLN.mjs.map → linting-D6drcQHM.mjs.map} +1 -1
- package/dist/node/{main-D82dkD7g.mjs → main-CfVS_PlH.mjs} +4 -4
- package/dist/node/main-CfVS_PlH.mjs.map +1 -0
- package/dist/node/{schema-context-CX5ml_9t.mjs → schema-context-pefmG2VW.mjs} +3 -3
- package/dist/node/{schema-context-CX5ml_9t.mjs.map → schema-context-pefmG2VW.mjs.map} +1 -1
- package/dist/node/{state-schemas-BwvZVEhR.mjs → state-schemas-D_NQwzNn.mjs} +7 -7
- package/dist/node/{state-schemas-BwvZVEhR.mjs.map → state-schemas-D_NQwzNn.mjs.map} +1 -1
- package/package.json +6 -6
- package/dist/browser/dist-BEs8jMgM.js.map +0 -1
- package/dist/browser/document-drive-sTKoi6L4.js.map +0 -1
- package/dist/browser/documents-D4ek7Ubv.js.map +0 -1
- package/dist/browser/lib-C-f3izXz.js.map +0 -1
- package/dist/node/dist-8nCvrie2.mjs.map +0 -1
- package/dist/node/document-drive-DjL9iikf.mjs.map +0 -1
- package/dist/node/main-D82dkD7g.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 { H as setName, N as replayDocumentVersioned, Q as generateId, X as validateModules, Y as validateInitialState, Z as validateStateSchemaName, _ as baseLoadFromInput, a as handleTargetNameCollisions, b as buildSignedAction, c as moveNode, d as logger, h as assertAuthPreservedOnDuplicate, i as generateNodesCopy, l as updateNode, n as copyNode, o as isFileNode, s as isFolderNode, t as addFolder, v as baseLoadFromInputVersioned, w as createZip, x as createPresignedHeader, y as baseSaveToFileHandle } from "./document-drive-QCAIGn3V.js";
|
|
3
|
+
import { a as SyncStatus, o as DriveCollectionId, s as ModuleNotFoundError, t as gql } from "./lib-Dx4DRbGl.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-RNQCGkYh.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.getDocumentModelModule(document.header.documentType)).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-B1Af81HB.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
|
|
@@ -737,8 +771,17 @@ function extractQueryParts(doc, fallbackBody) {
|
|
|
737
771
|
extractSelectionSet(GetDocumentOperationsDocument, "documentOperations", "{ items { index } }");
|
|
738
772
|
extractQueryParts(GetDocumentDocument, "document(identifier: $identifier) { document { id name documentType state revisionsList { scope revision } createdAtUtcIso lastModifiedAtUtcIso } childIds }");
|
|
739
773
|
//#endregion
|
|
740
|
-
//#region ../reactor-browser/dist/renown-
|
|
774
|
+
//#region ../reactor-browser/dist/renown-BZabzj4l.js
|
|
741
775
|
const { useValue: useLoading, setValue: setLoading, addEventHandler: addLoadingEventHandler } = makePHEventFunctions("loading");
|
|
776
|
+
const RenownInitialUserContext = createContext({ state: "unknown" });
|
|
777
|
+
/** First-render auth as a three-state value; use this to skip a spinner when anonymous. */
|
|
778
|
+
function useRenownInitialAuth() {
|
|
779
|
+
return useContext(RenownInitialUserContext);
|
|
780
|
+
}
|
|
781
|
+
function useRenownInitialUser() {
|
|
782
|
+
const initial = useRenownInitialAuth();
|
|
783
|
+
return initial.state === "authenticated" ? initial.user : void 0;
|
|
784
|
+
}
|
|
742
785
|
const renownEventFunctions = makePHEventFunctions("renown");
|
|
743
786
|
renownEventFunctions.addEventHandler;
|
|
744
787
|
/** Returns the renown instance */
|
|
@@ -747,41 +790,17 @@ renownEventFunctions.setValue;
|
|
|
747
790
|
/** Returns the current user from the renown instance, subscribing to user events */
|
|
748
791
|
function useUser() {
|
|
749
792
|
const renown = useRenown();
|
|
750
|
-
const
|
|
793
|
+
const initialUser = useRenownInitialUser();
|
|
794
|
+
const instance = renown ? renown : void 0;
|
|
795
|
+
const [user, setUser] = useState(instance ? instance.user : initialUser);
|
|
751
796
|
useEffect(() => {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
const merged = { ...parentProps };
|
|
760
|
-
for (const key of Object.keys(childProps)) {
|
|
761
|
-
const parentValue = parentProps[key];
|
|
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;
|
|
775
|
-
}
|
|
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";
|
|
797
|
+
if (instance) {
|
|
798
|
+
setUser(instance.user);
|
|
799
|
+
return instance.on("user", setUser);
|
|
800
|
+
}
|
|
801
|
+
}, [instance]);
|
|
802
|
+
return instance ? user : initialUser ?? user;
|
|
803
|
+
}
|
|
785
804
|
//#endregion
|
|
786
805
|
//#region ../../node_modules/.pnpm/remeda@2.33.7/node_modules/remeda/dist/lazyDataLastImpl-DtF3cihj.js
|
|
787
806
|
function e$8(e, t, n) {
|
|
@@ -906,6 +925,32 @@ function e(e) {
|
|
|
906
925
|
let t = !1, n;
|
|
907
926
|
return () => (t ||= (n = e(), !0), n);
|
|
908
927
|
}
|
|
928
|
+
var CloseCode = /* @__PURE__ */ ((CloseCode2) => {
|
|
929
|
+
CloseCode2[CloseCode2["InternalServerError"] = 4500] = "InternalServerError";
|
|
930
|
+
CloseCode2[CloseCode2["InternalClientError"] = 4005] = "InternalClientError";
|
|
931
|
+
CloseCode2[CloseCode2["BadRequest"] = 4400] = "BadRequest";
|
|
932
|
+
CloseCode2[CloseCode2["BadResponse"] = 4004] = "BadResponse";
|
|
933
|
+
CloseCode2[CloseCode2["Unauthorized"] = 4401] = "Unauthorized";
|
|
934
|
+
CloseCode2[CloseCode2["Forbidden"] = 4403] = "Forbidden";
|
|
935
|
+
CloseCode2[CloseCode2["SubprotocolNotAcceptable"] = 4406] = "SubprotocolNotAcceptable";
|
|
936
|
+
CloseCode2[CloseCode2["ConnectionInitialisationTimeout"] = 4408] = "ConnectionInitialisationTimeout";
|
|
937
|
+
CloseCode2[CloseCode2["ConnectionAcknowledgementTimeout"] = 4504] = "ConnectionAcknowledgementTimeout";
|
|
938
|
+
CloseCode2[CloseCode2["SubscriberAlreadyExists"] = 4409] = "SubscriberAlreadyExists";
|
|
939
|
+
CloseCode2[CloseCode2["TooManyInitialisationRequests"] = 4429] = "TooManyInitialisationRequests";
|
|
940
|
+
return CloseCode2;
|
|
941
|
+
})(CloseCode || {});
|
|
942
|
+
var MessageType = /* @__PURE__ */ ((MessageType2) => {
|
|
943
|
+
MessageType2["ConnectionInit"] = "connection_init";
|
|
944
|
+
MessageType2["ConnectionAck"] = "connection_ack";
|
|
945
|
+
MessageType2["Ping"] = "ping";
|
|
946
|
+
MessageType2["Pong"] = "pong";
|
|
947
|
+
MessageType2["Subscribe"] = "subscribe";
|
|
948
|
+
MessageType2["Next"] = "next";
|
|
949
|
+
MessageType2["Error"] = "error";
|
|
950
|
+
MessageType2["Complete"] = "complete";
|
|
951
|
+
return MessageType2;
|
|
952
|
+
})(MessageType || {});
|
|
953
|
+
Error;
|
|
909
954
|
//#endregion
|
|
910
955
|
//#region ../../node_modules/.pnpm/slug@11.0.1/node_modules/slug/slug.js
|
|
911
956
|
let base64;
|
|
@@ -1693,1075 +1738,450 @@ slug.setLocale = function(locale) {
|
|
|
1693
1738
|
defaultLocale = locales[locale] || {};
|
|
1694
1739
|
};
|
|
1695
1740
|
//#endregion
|
|
1696
|
-
//#region
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
};
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
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;
|
|
1741
|
+
//#region ../reactor-browser/dist/document-operations-nKk9cG3V.js
|
|
1742
|
+
var DocumentModelNotFoundError = class extends Error {
|
|
1743
|
+
documentType;
|
|
1744
|
+
name = "DocumentModelNotFoundError";
|
|
1745
|
+
constructor(documentType) {
|
|
1746
|
+
super(`Document model module for type ${documentType} not found`);
|
|
1747
|
+
this.documentType = documentType;
|
|
1748
|
+
}
|
|
1749
|
+
static isError(error) {
|
|
1750
|
+
return Error.isError(error) && error.name === "DocumentModelNotFoundError";
|
|
1715
1751
|
}
|
|
1716
|
-
if (isInvalidDescriptor(descriptor)) setErrorDescriptor(error, propName, descriptor);
|
|
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
1752
|
};
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
const isInstanceOfError = (value) => {
|
|
1762
|
-
try {
|
|
1763
|
-
return value instanceof Error;
|
|
1764
|
-
} catch {
|
|
1765
|
-
return false;
|
|
1753
|
+
var DocumentTypeMismatchError = class extends Error {
|
|
1754
|
+
constructor(documentId, expectedType, actualType) {
|
|
1755
|
+
super(`Document ${documentId} is not of type ${expectedType}. Actual type: ${actualType}`);
|
|
1766
1756
|
}
|
|
1767
1757
|
};
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
} catch {
|
|
1772
|
-
return false;
|
|
1758
|
+
var NoSelectedDocumentError = class extends Error {
|
|
1759
|
+
constructor() {
|
|
1760
|
+
super("There is no selected document. Did you mean to call 'useSelectedDocumentSafe' instead?");
|
|
1773
1761
|
}
|
|
1774
1762
|
};
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
1763
|
+
function getUserPermissions() {
|
|
1764
|
+
const user = window.ph?.renown?.user;
|
|
1765
|
+
const allowList = window.ph?.allowList;
|
|
1766
|
+
if (!allowList) return {
|
|
1767
|
+
isAllowedToCreateDocuments: true,
|
|
1768
|
+
isAllowedToEditDocuments: true
|
|
1769
|
+
};
|
|
1770
|
+
return {
|
|
1771
|
+
isAllowedToCreateDocuments: allowList.includes(user?.address ?? ""),
|
|
1772
|
+
isAllowedToEditDocuments: allowList.includes(user?.address ?? "")
|
|
1773
|
+
};
|
|
1787
1774
|
}
|
|
1788
|
-
|
|
1789
|
-
|
|
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) => {
|
|
1775
|
+
const NON_DOMAIN_SCOPES = new Set(["auth", "document"]);
|
|
1776
|
+
async function downloadFile(document, fileName) {
|
|
1796
1777
|
try {
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1778
|
+
const data = await createZip(document);
|
|
1779
|
+
const blob = new Blob([new Uint8Array(data)], { type: "application/zip" });
|
|
1780
|
+
const link = window.document.createElement("a");
|
|
1781
|
+
link.style.display = "none";
|
|
1782
|
+
link.href = URL.createObjectURL(blob);
|
|
1783
|
+
link.download = fileName;
|
|
1784
|
+
window.document.body.appendChild(link);
|
|
1785
|
+
link.click();
|
|
1786
|
+
window.document.body.removeChild(link);
|
|
1787
|
+
} catch (e) {
|
|
1788
|
+
logger.error(e instanceof Error ? e.message : String(e));
|
|
1801
1789
|
}
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
const
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
Object.defineProperty(objectCopy, propName, {
|
|
1831
|
-
value,
|
|
1832
|
-
enumerable,
|
|
1833
|
-
configurable,
|
|
1834
|
-
writable
|
|
1790
|
+
}
|
|
1791
|
+
async function getDocumentExtension(document) {
|
|
1792
|
+
const documentType = document.header.documentType;
|
|
1793
|
+
let rawExtension;
|
|
1794
|
+
if (documentType === "powerhouse/document-model") rawExtension = document.state.global?.extension;
|
|
1795
|
+
else {
|
|
1796
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
1797
|
+
if (reactorClient) {
|
|
1798
|
+
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
1799
|
+
rawExtension = documentModelModules.find((m) => m.documentModel.global.id === documentType)?.utils.fileExtension;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
return (rawExtension ?? "").replace(/^\.+|\.+$/g, "");
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Fetches all operations for a document using cursor-based pagination.
|
|
1806
|
+
* The reactor client handles multi-scope cursors transparently via
|
|
1807
|
+
* composite cursors, so all scopes are fetched in a single paginated stream.
|
|
1808
|
+
*/
|
|
1809
|
+
async function fetchDocumentOperations(reactorClient, document, pageSize = 100) {
|
|
1810
|
+
const scopes = Object.keys(document.state);
|
|
1811
|
+
const operations = {};
|
|
1812
|
+
for (const scope of scopes) operations[scope] = [];
|
|
1813
|
+
let cursor = "";
|
|
1814
|
+
do {
|
|
1815
|
+
const page = await reactorClient.getOperations(document.header.id, { scopes }, void 0, {
|
|
1816
|
+
cursor,
|
|
1817
|
+
limit: pageSize
|
|
1835
1818
|
});
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
return
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1819
|
+
for (const op of page.results) {
|
|
1820
|
+
const scope = op.action.scope ?? "global";
|
|
1821
|
+
if (operations[scope]) operations[scope].push(op);
|
|
1822
|
+
}
|
|
1823
|
+
cursor = page.nextCursor ?? "";
|
|
1824
|
+
} while (cursor);
|
|
1825
|
+
return operations;
|
|
1826
|
+
}
|
|
1827
|
+
function extractInitialState(documentScopeOps) {
|
|
1828
|
+
const upgradeOp = documentScopeOps.find((op) => op.action.type === "UPGRADE_DOCUMENT");
|
|
1829
|
+
if (!upgradeOp) throw new Error("No UPGRADE_DOCUMENT operation found — document is invalid");
|
|
1830
|
+
const input = upgradeOp.action.input;
|
|
1831
|
+
const initialState = input.initialState ?? input.state;
|
|
1832
|
+
if (!initialState) throw new Error("UPGRADE_DOCUMENT operation has no initialState — document is invalid");
|
|
1833
|
+
return initialState;
|
|
1834
|
+
}
|
|
1835
|
+
function filterDomainOperations(operations) {
|
|
1836
|
+
return Object.fromEntries(Object.entries(operations).filter(([scope]) => !NON_DOMAIN_SCOPES.has(scope)));
|
|
1837
|
+
}
|
|
1838
|
+
async function exportFile(document, suggestedName) {
|
|
1839
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1840
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1841
|
+
const operations = await fetchDocumentOperations(reactorClient, document);
|
|
1842
|
+
const initialState = extractInitialState(operations["document"] ?? []);
|
|
1843
|
+
const documentWithOps = {
|
|
1844
|
+
...document,
|
|
1845
|
+
operations,
|
|
1846
|
+
initialState
|
|
1847
|
+
};
|
|
1848
|
+
const extension = await getDocumentExtension(documentWithOps);
|
|
1849
|
+
const baseName = suggestedName || documentWithOps.header.name || "Untitled";
|
|
1850
|
+
const name = extension ? `${baseName}.${extension}.phd` : `${baseName}.phd`;
|
|
1851
|
+
if (!window.showSaveFilePicker) return await downloadFile(documentWithOps, name);
|
|
1845
1852
|
try {
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
return
|
|
1853
|
+
const fileHandle = await window.showSaveFilePicker({ suggestedName: name });
|
|
1854
|
+
await baseSaveToFileHandle(documentWithOps, fileHandle);
|
|
1855
|
+
return fileHandle;
|
|
1856
|
+
} catch (e) {
|
|
1857
|
+
if (!(e instanceof DOMException && e.name === "AbortError")) throw e;
|
|
1849
1858
|
}
|
|
1850
|
-
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
};
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
const
|
|
1861
|
-
const {
|
|
1862
|
-
const
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
}
|
|
1871
|
-
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Loads a document file and replays it with version-aware reducers from the registry.
|
|
1862
|
+
* Falls back to single-version legacy replay when no upgrade manifest is registered for
|
|
1863
|
+
* the document type.
|
|
1864
|
+
*/
|
|
1865
|
+
async function loadFile(path) {
|
|
1866
|
+
const baseDocument = await baseLoadFromInput(path, (state) => state, { checkHashes: true });
|
|
1867
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
1868
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1869
|
+
const documentType = baseDocument.header.documentType;
|
|
1870
|
+
const { results: documentModelModules } = await reactorClient.getDocumentModelModules();
|
|
1871
|
+
const modulesForType = documentModelModules.filter((module) => module.documentModel.global.id === documentType);
|
|
1872
|
+
if (modulesForType.length === 0) throw new DocumentModelNotFoundError(documentType);
|
|
1873
|
+
const reducers = {};
|
|
1874
|
+
for (const module of modulesForType) reducers[module.version ?? 1] = module.reducer;
|
|
1875
|
+
const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
1876
|
+
let upgradeManifest;
|
|
1877
|
+
if (registry) try {
|
|
1878
|
+
upgradeManifest = registry.getUpgradeManifest(documentType);
|
|
1879
|
+
} catch {}
|
|
1880
|
+
return baseLoadFromInputVersioned(path, {
|
|
1881
|
+
reducers,
|
|
1882
|
+
upgradeManifest
|
|
1872
1883
|
});
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
};
|
|
1876
|
-
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1884
|
+
}
|
|
1885
|
+
async function addDocument(driveId, name, documentType, parentFolder, document, id, preferredEditor) {
|
|
1886
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1887
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create documents");
|
|
1888
|
+
const reactorClient = window.ph?.reactorClientModule?.client;
|
|
1889
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1890
|
+
const documentModelModule = await reactorClient.getDocumentModelModule(documentType);
|
|
1891
|
+
const newDocument = document ?? documentModelModule.utils.createDocument();
|
|
1892
|
+
newDocument.header.name = name;
|
|
1893
|
+
if (preferredEditor) newDocument.header.meta = {
|
|
1894
|
+
...newDocument.header.meta,
|
|
1895
|
+
preferredEditor
|
|
1896
|
+
};
|
|
1897
|
+
let newDoc;
|
|
1885
1898
|
try {
|
|
1886
|
-
|
|
1887
|
-
} catch {
|
|
1888
|
-
|
|
1899
|
+
newDoc = await reactorClient.drives.addFile(driveId, newDocument, parentFolder);
|
|
1900
|
+
} catch (e) {
|
|
1901
|
+
logger.error("Error adding document: @error", e);
|
|
1902
|
+
throw new Error("There was an error adding document", { cause: e });
|
|
1889
1903
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
};
|
|
1907
|
-
const assignObjectProps = (error, object) => {
|
|
1908
|
-
for (const propName in object) if (!(propName in error)) error[propName] = object[propName];
|
|
1909
|
-
};
|
|
1910
|
-
const setNewErrorProperty = (error, propName, propValue) => {
|
|
1911
|
-
if (propValue !== void 0) setErrorProperty(error, propName, propValue);
|
|
1912
|
-
};
|
|
1913
|
-
//#endregion
|
|
1914
|
-
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/string.js
|
|
1915
|
-
const stringifyError = (value) => {
|
|
1904
|
+
return {
|
|
1905
|
+
id: newDoc.header.id,
|
|
1906
|
+
name: newDoc.header.name,
|
|
1907
|
+
documentType,
|
|
1908
|
+
parentFolder: parentFolder ?? null,
|
|
1909
|
+
kind: "file"
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
async function addFile(file, driveId, name, parentFolder) {
|
|
1913
|
+
logger.verbose(`addFile(drive: ${driveId}, name: ${name}, folder: ${parentFolder})`);
|
|
1914
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1915
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create files");
|
|
1916
|
+
const document = await loadFile(file);
|
|
1917
|
+
let duplicateId = false;
|
|
1918
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1919
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1916
1920
|
try {
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1921
|
+
await reactorClient.get(document.header.id);
|
|
1922
|
+
duplicateId = true;
|
|
1923
|
+
} catch {}
|
|
1924
|
+
const documentId = duplicateId ? generateId() : document.header.id;
|
|
1925
|
+
const header = createPresignedHeader(documentId, document.header.documentType);
|
|
1926
|
+
header.lastModifiedAtUtcIso = document.header.createdAtUtcIso;
|
|
1927
|
+
header.meta = document.header.meta;
|
|
1928
|
+
header.name = name || document.header.name;
|
|
1929
|
+
const initialDocument = {
|
|
1930
|
+
...document,
|
|
1931
|
+
header,
|
|
1932
|
+
state: document.initialState,
|
|
1933
|
+
operations: Object.keys(document.operations).reduce((acc, key) => {
|
|
1934
|
+
acc[key] = [];
|
|
1935
|
+
return acc;
|
|
1936
|
+
}, {})
|
|
1937
|
+
};
|
|
1938
|
+
await addDocument(driveId, name || document.header.name, document.header.documentType, parentFolder, initialDocument, documentId, document.header.meta?.preferredEditor);
|
|
1939
|
+
await uploadOperations(documentId, filterDomainOperations(document.operations), queueOperations);
|
|
1940
|
+
}
|
|
1941
|
+
async function addFolder$1(driveId, name, parentFolder) {
|
|
1942
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1943
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to create folders");
|
|
1944
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1945
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1946
|
+
await reactorClient.get(driveId);
|
|
1947
|
+
const folderId = generateId();
|
|
1948
|
+
const node = (await reactorClient.execute(driveId, "main", [addFolder({
|
|
1949
|
+
id: folderId,
|
|
1950
|
+
name,
|
|
1951
|
+
parentFolder
|
|
1952
|
+
})])).state.global.nodes.find((node) => node.id === folderId);
|
|
1953
|
+
if (!node || !isFolderNode(node)) throw new Error("There was an error adding folder");
|
|
1954
|
+
return node;
|
|
1955
|
+
}
|
|
1956
|
+
async function renameNode(driveId, nodeId, name) {
|
|
1957
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1958
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
1959
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1960
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1961
|
+
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
1962
|
+
const node = (await reactorClient.execute(driveId, "main", [updateNode({
|
|
1963
|
+
id: nodeId,
|
|
1964
|
+
name
|
|
1965
|
+
})])).state.global.nodes.find((n) => n.id === nodeId);
|
|
1966
|
+
if (!node) throw new Error("There was an error renaming node in the drive");
|
|
1967
|
+
return node;
|
|
1968
|
+
}
|
|
1969
|
+
async function renameDriveNode(driveId, nodeId, name) {
|
|
1970
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1971
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to rename documents");
|
|
1972
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1973
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1974
|
+
if ((await reactorClient.execute(nodeId, "main", [setName({ name })])).header.name !== name) throw new Error("There was an error renaming the node");
|
|
1975
|
+
await reactorClient.execute(driveId, "main", [updateNode({
|
|
1976
|
+
id: nodeId,
|
|
1977
|
+
name
|
|
1978
|
+
})]);
|
|
1979
|
+
return (await reactorClient.get(driveId)).state.global.nodes.find((n) => n.id === nodeId);
|
|
1980
|
+
}
|
|
1981
|
+
async function moveNodeById(args) {
|
|
1982
|
+
const { driveId, srcId, targetId } = args;
|
|
1983
|
+
if (!driveId || !srcId) return;
|
|
1984
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1985
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
1986
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1987
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
1988
|
+
const targetParentFolder = t$3(targetId, [e$3(e$4), e$6(void 0)], [t(driveId), e$6(void 0)], e$6(targetId));
|
|
1989
|
+
if (t(targetParentFolder, srcId)) return;
|
|
1990
|
+
return await reactorClient.execute(driveId, "main", [moveNode({
|
|
1991
|
+
srcFolder: srcId,
|
|
1992
|
+
targetParentFolder
|
|
1993
|
+
})]);
|
|
1994
|
+
}
|
|
1995
|
+
async function moveNode$1(driveId, src, target) {
|
|
1996
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
1997
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to move documents");
|
|
1998
|
+
const reactorClient = window.ph?.reactorClient;
|
|
1999
|
+
if (!reactorClient) throw new Error("ReactorClient not initialized");
|
|
2000
|
+
return await reactorClient.execute(driveId, "main", [moveNode({
|
|
2001
|
+
srcFolder: src.id,
|
|
2002
|
+
targetParentFolder: target?.id
|
|
2003
|
+
})]);
|
|
2004
|
+
}
|
|
2005
|
+
/**
|
|
2006
|
+
* Duplicates a document under a new id using version-aware replay.
|
|
2007
|
+
* Falls back gracefully when no upgrade manifest is registered for the document type.
|
|
2008
|
+
*/
|
|
2009
|
+
async function _duplicateDocument(reactor, document, newId = generateId()) {
|
|
2010
|
+
const documentType = document.header.documentType;
|
|
2011
|
+
const { results: allModules } = await reactor.getDocumentModelModules();
|
|
2012
|
+
const modulesForType = allModules.filter((m) => m.documentModel.global.id === documentType);
|
|
2013
|
+
const reducers = {};
|
|
2014
|
+
for (const m of modulesForType) reducers[m.version ?? 1] = m.reducer;
|
|
2015
|
+
if (Object.keys(reducers).length === 0) throw new Error(`Document model module not found for type: ${documentType}`);
|
|
2016
|
+
const registry = window.ph?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
2017
|
+
let upgradeManifest;
|
|
2018
|
+
if (registry) try {
|
|
2019
|
+
upgradeManifest = registry.getUpgradeManifest(documentType);
|
|
2020
|
+
} catch {}
|
|
2021
|
+
const config = {
|
|
2022
|
+
reducers,
|
|
2023
|
+
upgradeManifest
|
|
2024
|
+
};
|
|
2025
|
+
const header = createPresignedHeader(newId, documentType);
|
|
2026
|
+
const duplicated = replayDocumentVersioned(document.initialState, document.operations, config, header);
|
|
2027
|
+
assertAuthPreservedOnDuplicate(document.header.id, document.state.auth, duplicated.state.auth);
|
|
2028
|
+
return duplicated;
|
|
2029
|
+
}
|
|
2030
|
+
async function copyNode$1(driveId, src, target) {
|
|
2031
|
+
const reactor = window.ph?.reactorClientModule?.client;
|
|
2032
|
+
if (!reactor) return;
|
|
2033
|
+
const { isAllowedToCreateDocuments } = getUserPermissions();
|
|
2034
|
+
if (!isAllowedToCreateDocuments) throw new Error("User is not allowed to copy documents");
|
|
2035
|
+
const drive = await reactor.get(driveId);
|
|
2036
|
+
const copyNodesInput = generateNodesCopy({
|
|
2037
|
+
srcId: src.id,
|
|
2038
|
+
targetParentFolder: target?.id,
|
|
2039
|
+
targetName: src.name
|
|
2040
|
+
}, () => generateId(), drive.state.global.nodes);
|
|
2041
|
+
const resolvedNamesMap = /* @__PURE__ */ new Map();
|
|
2042
|
+
for (const copyNodeInput of copyNodesInput) {
|
|
2043
|
+
const node = drive.state.global.nodes.find((n) => n.id === copyNodeInput.srcId);
|
|
2044
|
+
if (node) {
|
|
2045
|
+
const resolvedName = handleTargetNameCollisions({
|
|
2046
|
+
nodes: drive.state.global.nodes,
|
|
2047
|
+
srcName: copyNodeInput.targetName || node.name,
|
|
2048
|
+
srcKind: isFileNode(node) ? "file" : "folder",
|
|
2049
|
+
targetParentFolder: copyNodeInput.targetParentFolder || null
|
|
2050
|
+
});
|
|
2051
|
+
resolvedNamesMap.set(copyNodeInput.targetId, resolvedName);
|
|
2052
|
+
}
|
|
1922
2053
|
}
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
const
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
}
|
|
1933
|
-
|
|
1934
|
-
try {
|
|
1935
|
-
return isPlainObject(value);
|
|
1936
|
-
} catch {
|
|
1937
|
-
return false;
|
|
1938
|
-
}
|
|
1939
|
-
};
|
|
1940
|
-
const isInvalidError = (value) => isProxy(value) || isNonModifiableError(value) || hasInvalidConstructor(value);
|
|
1941
|
-
const isProxy = (value) => {
|
|
1942
|
-
try {
|
|
1943
|
-
return objectToString.call(value) === "[object Object]";
|
|
1944
|
-
} catch {
|
|
1945
|
-
return true;
|
|
2054
|
+
const fileNodesToCopy = copyNodesInput.filter((copyNodeInput) => {
|
|
2055
|
+
const node = drive.state.global.nodes.find((node) => node.id === copyNodeInput.srcId);
|
|
2056
|
+
return node !== void 0 && isFileNode(node);
|
|
2057
|
+
});
|
|
2058
|
+
for (const fileNodeToCopy of fileNodesToCopy) try {
|
|
2059
|
+
const duplicatedDocument = await _duplicateDocument(reactor, await reactor.get(fileNodeToCopy.srcId), fileNodeToCopy.targetId);
|
|
2060
|
+
const resolvedName = resolvedNamesMap.get(fileNodeToCopy.targetId);
|
|
2061
|
+
if (resolvedName) duplicatedDocument.header.name = resolvedName;
|
|
2062
|
+
await reactor.drives.addFile(driveId, duplicatedDocument, target?.id);
|
|
2063
|
+
} catch (e) {
|
|
2064
|
+
logger.error(`Error copying document ${fileNodeToCopy.srcId}: ${String(e)}`);
|
|
1946
2065
|
}
|
|
2066
|
+
return await queueActions(drive, copyNodesInput.map((copyNodeInput) => copyNode(copyNodeInput)));
|
|
2067
|
+
}
|
|
2068
|
+
const modalEventFunctions = makePHEventFunctions("modal");
|
|
2069
|
+
modalEventFunctions.useValue;
|
|
2070
|
+
/** Sets the current modal */
|
|
2071
|
+
const setPHModal = modalEventFunctions.setValue;
|
|
2072
|
+
modalEventFunctions.addEventHandler;
|
|
2073
|
+
/** Shows a modal */
|
|
2074
|
+
function showPHModal(modal) {
|
|
2075
|
+
setPHModal(modal);
|
|
2076
|
+
}
|
|
2077
|
+
/** Shows the create document modal */
|
|
2078
|
+
function showCreateDocumentModal(documentType) {
|
|
2079
|
+
setPHModal({
|
|
2080
|
+
type: "createDocument",
|
|
2081
|
+
documentType
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
/** Shows the delete node modal */
|
|
2085
|
+
function showDeleteNodeModal(nodeOrId) {
|
|
2086
|
+
setPHModal({
|
|
2087
|
+
type: "deleteItem",
|
|
2088
|
+
id: typeof nodeOrId === "string" ? nodeOrId : nodeOrId.id
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
gql`
|
|
2092
|
+
mutation MutateDocumentWithOperations(
|
|
2093
|
+
$documentIdentifier: String!
|
|
2094
|
+
$actions: [JSONObject!]!
|
|
2095
|
+
$view: ViewFilterInput
|
|
2096
|
+
$sinceRevision: Int
|
|
2097
|
+
$scopes: [String!]
|
|
2098
|
+
$branch: String
|
|
2099
|
+
) {
|
|
2100
|
+
mutateDocument(
|
|
2101
|
+
documentIdentifier: $documentIdentifier
|
|
2102
|
+
actions: $actions
|
|
2103
|
+
view: $view
|
|
2104
|
+
) {
|
|
2105
|
+
...PHDocumentFields
|
|
2106
|
+
operations(
|
|
2107
|
+
filter: {
|
|
2108
|
+
sinceRevision: $sinceRevision
|
|
2109
|
+
scopes: $scopes
|
|
2110
|
+
branch: $branch
|
|
2111
|
+
}
|
|
2112
|
+
) {
|
|
2113
|
+
items {
|
|
2114
|
+
...ReactorOperationFields
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
${PhDocumentFieldsFragmentDoc}
|
|
2120
|
+
${gql`
|
|
2121
|
+
fragment ReactorOperationFields on ReactorOperation {
|
|
2122
|
+
index
|
|
2123
|
+
timestampUtcMs
|
|
2124
|
+
hash
|
|
2125
|
+
skip
|
|
2126
|
+
error
|
|
2127
|
+
id
|
|
2128
|
+
action {
|
|
2129
|
+
id
|
|
2130
|
+
type
|
|
2131
|
+
timestampUtcMs
|
|
2132
|
+
input
|
|
2133
|
+
scope
|
|
2134
|
+
context {
|
|
2135
|
+
signer {
|
|
2136
|
+
user {
|
|
2137
|
+
address
|
|
2138
|
+
networkId
|
|
2139
|
+
chainId
|
|
2140
|
+
}
|
|
2141
|
+
app {
|
|
2142
|
+
name
|
|
2143
|
+
key
|
|
2144
|
+
}
|
|
2145
|
+
signatures
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
`}
|
|
2151
|
+
`;
|
|
2152
|
+
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;
|
|
2153
|
+
PropagationMode.Cascade, PropagationMode.Orphan;
|
|
2154
|
+
const isExternalControlsEnabledEventFunctions = makePHEventFunctions("isExternalControlsEnabled");
|
|
2155
|
+
/** Sets whether external controls are enabled for a given editor. */
|
|
2156
|
+
const setIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.setValue;
|
|
2157
|
+
/** Gets whether external controls are enabled for a given editor. */
|
|
2158
|
+
const useIsExternalControlsEnabled = isExternalControlsEnabledEventFunctions.useValue;
|
|
2159
|
+
isExternalControlsEnabledEventFunctions.addEventHandler;
|
|
2160
|
+
const isDragAndDropEnabledEventFunctions = makePHEventFunctions("isDragAndDropEnabled");
|
|
2161
|
+
/** Sets whether drag and drop is enabled for a given app. */
|
|
2162
|
+
const setIsDragAndDropEnabled = isDragAndDropEnabledEventFunctions.setValue;
|
|
2163
|
+
/** Gets whether drag and drop is enabled for a given app. */
|
|
2164
|
+
const useIsDragAndDropEnabled = isDragAndDropEnabledEventFunctions.useValue;
|
|
2165
|
+
isDragAndDropEnabledEventFunctions.addEventHandler;
|
|
2166
|
+
const allowedDocumentTypesEventFunctions = makePHEventFunctions("allowedDocumentTypes");
|
|
2167
|
+
/** Sets the allowed document types for a given app. */
|
|
2168
|
+
const setAllowedDocumentTypes = allowedDocumentTypesEventFunctions.setValue;
|
|
2169
|
+
/** Defines the document types a drive supports.
|
|
2170
|
+
*
|
|
2171
|
+
* Defaults to all of the document types registered in the reactor.
|
|
2172
|
+
*/
|
|
2173
|
+
function useAllowedDocumentTypes() {
|
|
2174
|
+
return allowedDocumentTypesEventFunctions.useValue();
|
|
2175
|
+
}
|
|
2176
|
+
allowedDocumentTypesEventFunctions.addEventHandler;
|
|
2177
|
+
const phAppConfigSetters = {
|
|
2178
|
+
allowedDocumentTypes: setAllowedDocumentTypes,
|
|
2179
|
+
isDragAndDropEnabled: setIsDragAndDropEnabled
|
|
1947
2180
|
};
|
|
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
|
|
2181
|
+
const phDocumentEditorConfigSetters = { isExternalControlsEnabled: setIsExternalControlsEnabled };
|
|
2182
|
+
const phAppConfigHooks = {
|
|
2183
|
+
allowedDocumentTypes: useAllowedDocumentTypes,
|
|
2184
|
+
isDragAndDropEnabled: useIsDragAndDropEnabled
|
|
2765
2185
|
};
|
|
2766
2186
|
const phDocumentEditorConfigHooks = { isExternalControlsEnabled: useIsExternalControlsEnabled };
|
|
2767
2187
|
const { useValue: useRouterBasename, setValue: setRouterBasename, addEventHandler: addRouterBasenameEventHandler } = makePHEventFunctions("routerBasename");
|
|
@@ -2796,6 +2216,8 @@ const { useValue: useIsDriveAnalyticsEnabled, setValue: setIsDriveAnalyticsEnabl
|
|
|
2796
2216
|
const { useValue: useRenownUrl, setValue: setRenownUrl, addEventHandler: addRenownUrlEventHandler } = makePHEventFunctions("renownUrl");
|
|
2797
2217
|
const { useValue: useRenownNetworkId, setValue: setRenownNetworkId, addEventHandler: addRenownNetworkIdEventHandler } = makePHEventFunctions("renownNetworkId");
|
|
2798
2218
|
const { useValue: useRenownChainId, setValue: setRenownChainId, addEventHandler: addRenownChainIdEventHandler } = makePHEventFunctions("renownChainId");
|
|
2219
|
+
const { useValue: useSwitchboardUrl, setValue: setSwitchboardUrl, addEventHandler: addSwitchboardUrlEventHandler } = makePHEventFunctions("switchboardUrl");
|
|
2220
|
+
const { useValue: useRenownAdapters, setValue: setRenownAdapters, addEventHandler: addRenownAdaptersEventHandler } = makePHEventFunctions("renownAdapters");
|
|
2799
2221
|
const { useValue: useSentryRelease, setValue: setSentryRelease, addEventHandler: addSentryReleaseEventHandler } = makePHEventFunctions("sentryRelease");
|
|
2800
2222
|
const { useValue: useSentryDsn, setValue: setSentryDsn, addEventHandler: addSentryDsnEventHandler } = makePHEventFunctions("sentryDsn");
|
|
2801
2223
|
const { useValue: useSentryEnv, setValue: setSentryEnv, addEventHandler: addSentryEnvEventHandler } = makePHEventFunctions("sentryEnv");
|
|
@@ -2893,6 +2315,8 @@ const nonUserConfigSetters = {
|
|
|
2893
2315
|
renownUrl: setRenownUrl,
|
|
2894
2316
|
renownNetworkId: setRenownNetworkId,
|
|
2895
2317
|
renownChainId: setRenownChainId,
|
|
2318
|
+
switchboardUrl: setSwitchboardUrl,
|
|
2319
|
+
renownAdapters: setRenownAdapters,
|
|
2896
2320
|
sentryRelease: setSentryRelease,
|
|
2897
2321
|
sentryDsn: setSentryDsn,
|
|
2898
2322
|
sentryEnv: setSentryEnv,
|
|
@@ -2941,6 +2365,8 @@ const nonUserConfigHooks = {
|
|
|
2941
2365
|
renownUrl: useRenownUrl,
|
|
2942
2366
|
renownNetworkId: useRenownNetworkId,
|
|
2943
2367
|
renownChainId: useRenownChainId,
|
|
2368
|
+
switchboardUrl: useSwitchboardUrl,
|
|
2369
|
+
renownAdapters: useRenownAdapters,
|
|
2944
2370
|
sentryRelease: useSentryRelease,
|
|
2945
2371
|
sentryDsn: useSentryDsn,
|
|
2946
2372
|
sentryEnv: useSentryEnv,
|
|
@@ -2962,374 +2388,1089 @@ const nonUserConfigHooks = {
|
|
|
2962
2388
|
...phDocumentEditorConfigHooks,
|
|
2963
2389
|
...nonUserConfigHooks
|
|
2964
2390
|
});
|
|
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;
|
|
2391
|
+
const attachmentServiceEventFunctions = makePHEventFunctions("attachmentService");
|
|
2392
|
+
attachmentServiceEventFunctions.useValue;
|
|
2393
|
+
attachmentServiceEventFunctions.setValue;
|
|
2394
|
+
attachmentServiceEventFunctions.addEventHandler;
|
|
2395
|
+
const featuresEventFunctions = makePHEventFunctions("features");
|
|
2396
|
+
featuresEventFunctions.useValue;
|
|
2397
|
+
featuresEventFunctions.setValue;
|
|
2398
|
+
featuresEventFunctions.addEventHandler;
|
|
2399
|
+
function resolveUrlPathname(path) {
|
|
2400
|
+
return new URL(path.replace(/^\/+/, ""), window.location.origin + (window.ph?.basePath ?? "/")).pathname;
|
|
2401
|
+
}
|
|
2402
|
+
/** Returns the current path without the base path */
|
|
2403
|
+
function getPathWithoutBase(path) {
|
|
2404
|
+
const basePath = window.ph?.basePath ?? "/";
|
|
2405
|
+
return path.replace(basePath, basePath.endsWith("/") ? "/" : "");
|
|
2406
|
+
}
|
|
2407
|
+
/** Makes a URL component for a node. */
|
|
2408
|
+
function makeNodeSlug(node) {
|
|
2409
|
+
if (!node) return "";
|
|
2410
|
+
const nodeName = node.name;
|
|
2411
|
+
if (!nodeName) return slug(node.id);
|
|
2412
|
+
return slug(`${nodeName}-${node.id}`);
|
|
2413
|
+
}
|
|
2414
|
+
/** Extracts the node slug from a path.
|
|
2415
|
+
*
|
|
2416
|
+
* The path is expected to be in the format `/d/<drive-slug>/<node-slug>`.
|
|
2417
|
+
*/
|
|
2418
|
+
function extractNodeSlugFromPath(path) {
|
|
2419
|
+
const currentPath = getPathWithoutBase(path);
|
|
2420
|
+
return /^\/d\/[^/]+\/([^/]+)$/.exec(currentPath)?.[1];
|
|
2421
|
+
}
|
|
2422
|
+
/** Finds a UUID in a string, used for extracting node ids from node slugs in the URL. */
|
|
2423
|
+
function findUuid(input) {
|
|
2424
|
+
if (!input) return void 0;
|
|
2425
|
+
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];
|
|
2426
|
+
}
|
|
2427
|
+
function extractNodeIdFromSlug(nodeSlug) {
|
|
2428
|
+
return findUuid(nodeSlug);
|
|
2429
|
+
}
|
|
2430
|
+
/** Extracts the drive slug from a path.
|
|
2431
|
+
* Used for extracting drive ids from drive slugs in the URL.
|
|
2432
|
+
* Expects the path to be in the format `/d/<drive-slug>`.
|
|
2433
|
+
*/
|
|
2434
|
+
function extractDriveSlugFromPath(path) {
|
|
2435
|
+
const currentPath = getPathWithoutBase(path);
|
|
2436
|
+
return /^\/d\/([^/]+)/.exec(currentPath)?.[1] ?? "";
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Creates a URL string with the given pathname while preserving existing query parameters.
|
|
2440
|
+
*/
|
|
2441
|
+
function createUrlWithPreservedParams(pathname) {
|
|
2442
|
+
const search = window.location.search;
|
|
2443
|
+
return search ? `${pathname}${search}` : pathname;
|
|
2444
|
+
}
|
|
2445
|
+
const drivesEventFunctions = makePHEventFunctions("drives");
|
|
2446
|
+
/** Returns all of the drives in the reactor */
|
|
2447
|
+
const useDrives = drivesEventFunctions.useValue;
|
|
2448
|
+
/** Sets the drives in the reactor */
|
|
2449
|
+
const setDrives = drivesEventFunctions.setValue;
|
|
2450
|
+
drivesEventFunctions.addEventHandler;
|
|
2451
|
+
const selectedNodeIdEventFunctions = makePHEventFunctions("selectedNodeId");
|
|
2452
|
+
const useSelectedNodeId = selectedNodeIdEventFunctions.useValue;
|
|
2453
|
+
const setSelectedNodeId = selectedNodeIdEventFunctions.setValue;
|
|
2454
|
+
selectedNodeIdEventFunctions.addEventHandler;
|
|
2455
|
+
/** Sets the selected node (file or folder). */
|
|
2456
|
+
function setSelectedNode(nodeOrNodeSlug) {
|
|
2457
|
+
const nodeSlug = typeof nodeOrNodeSlug === "string" ? nodeOrNodeSlug : makeNodeSlug(nodeOrNodeSlug);
|
|
2458
|
+
setSelectedNodeId(extractNodeIdFromSlug(nodeSlug));
|
|
2459
|
+
const driveSlugFromPath = extractDriveSlugFromPath(window.location.pathname);
|
|
2460
|
+
if (!driveSlugFromPath) return;
|
|
2461
|
+
if (!nodeSlug) {
|
|
2462
|
+
const pathname = resolveUrlPathname(`/d/${driveSlugFromPath}`);
|
|
2463
|
+
if (pathname === window.location.pathname) return;
|
|
2464
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2465
|
+
return;
|
|
2466
|
+
}
|
|
2467
|
+
const pathname = resolveUrlPathname(`/d/${driveSlugFromPath}/${nodeSlug}`);
|
|
2468
|
+
if (pathname === window.location.pathname) return;
|
|
2469
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2470
|
+
}
|
|
2471
|
+
const selectedDriveIdEventFunctions = makePHEventFunctions("selectedDriveId");
|
|
2472
|
+
/** Returns the selected drive id */
|
|
2473
|
+
const useSelectedDriveId = selectedDriveIdEventFunctions.useValue;
|
|
2474
|
+
/** Sets the selected drive id */
|
|
2475
|
+
const setSelectedDriveId = selectedDriveIdEventFunctions.setValue;
|
|
2476
|
+
selectedDriveIdEventFunctions.addEventHandler;
|
|
2477
|
+
/** Returns the selected drive, or undefined if no drive is selected */
|
|
2478
|
+
function useSelectedDriveSafe() {
|
|
2479
|
+
const selectedDriveId = useSelectedDriveId();
|
|
2480
|
+
const selectedDrive = useDrives()?.find((drive) => drive.header.id === selectedDriveId);
|
|
2481
|
+
const [drive, dispatch] = useDispatch(selectedDrive);
|
|
2482
|
+
if (!selectedDrive) return [void 0, void 0];
|
|
2483
|
+
return [drive, dispatch];
|
|
2484
|
+
}
|
|
2485
|
+
function setSelectedDrive(driveOrDriveSlug) {
|
|
2486
|
+
const driveSlug = typeof driveOrDriveSlug === "string" ? driveOrDriveSlug : driveOrDriveSlug?.header.slug;
|
|
2487
|
+
const drives = window.ph?.drives;
|
|
2488
|
+
const driveId = (typeof driveOrDriveSlug === "object" && driveOrDriveSlug !== null ? driveOrDriveSlug : drives?.find((d) => d.header.slug === driveSlug))?.header.id;
|
|
2489
|
+
if (!driveId && driveSlug && extractDriveSlugFromPath(window.location.pathname) === driveSlug) {
|
|
2490
|
+
if (window.ph?.selectedDriveId) setSelectedDriveId(void 0);
|
|
2491
|
+
deferDriveSelection(driveSlug);
|
|
2492
|
+
return;
|
|
2493
|
+
}
|
|
2494
|
+
cancelPendingDriveSelection();
|
|
2495
|
+
setSelectedDriveId(driveId);
|
|
2496
|
+
if (!driveId) {
|
|
2497
|
+
const pathname = resolveUrlPathname("/");
|
|
2498
|
+
if (pathname === window.location.pathname) return;
|
|
2499
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
const pathname = resolveUrlPathname(`/d/${driveSlug}`);
|
|
2503
|
+
if (pathname === window.location.pathname) return;
|
|
2504
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2505
|
+
}
|
|
2506
|
+
const DEFERRED_DRIVE_TICK_MS = 2e3;
|
|
2507
|
+
const DEFERRED_DRIVE_MAX_WAIT_MS = 15e3;
|
|
2508
|
+
function isInitialSyncInFlight() {
|
|
2509
|
+
const remotes = window.ph?.reactorClientModule?.reactorModule?.syncModule?.syncManager?.list();
|
|
2510
|
+
if (!remotes?.length) return false;
|
|
2511
|
+
return remotes.some((remote) => {
|
|
2512
|
+
try {
|
|
2513
|
+
const snapshot = remote.channel.getConnectionState();
|
|
2514
|
+
return snapshot.receivingPages || !snapshot.lastSuccessUtcMs && snapshot.state !== "error";
|
|
2515
|
+
} catch {
|
|
2516
|
+
return false;
|
|
2517
|
+
}
|
|
2518
|
+
});
|
|
2519
|
+
}
|
|
2520
|
+
let pendingHandler;
|
|
2521
|
+
let pendingTimeout;
|
|
2522
|
+
function cancelPendingDriveSelection() {
|
|
2523
|
+
if (pendingHandler) {
|
|
2524
|
+
window.removeEventListener("ph:drivesUpdated", pendingHandler);
|
|
2525
|
+
pendingHandler = void 0;
|
|
2526
|
+
}
|
|
2527
|
+
if (pendingTimeout) {
|
|
2528
|
+
clearTimeout(pendingTimeout);
|
|
2529
|
+
pendingTimeout = void 0;
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
function deferDriveSelection(driveSlug) {
|
|
2533
|
+
cancelPendingDriveSelection();
|
|
2534
|
+
const nodeSlug = extractNodeSlugFromPath(window.location.pathname);
|
|
2535
|
+
const handler = () => {
|
|
2536
|
+
if (!window.ph?.drives?.find((d) => d.header.slug === driveSlug)) return;
|
|
2537
|
+
cancelPendingDriveSelection();
|
|
2538
|
+
setSelectedDrive(driveSlug);
|
|
2539
|
+
setSelectedNode(nodeSlug);
|
|
2540
|
+
};
|
|
2541
|
+
pendingHandler = handler;
|
|
2542
|
+
window.addEventListener("ph:drivesUpdated", handler);
|
|
2543
|
+
const deadline = Date.now() + DEFERRED_DRIVE_MAX_WAIT_MS;
|
|
2544
|
+
const scheduleTick = () => {
|
|
2545
|
+
pendingTimeout = setTimeout(() => {
|
|
2546
|
+
if (Date.now() < deadline && isInitialSyncInFlight()) {
|
|
2547
|
+
scheduleTick();
|
|
2548
|
+
return;
|
|
2549
|
+
}
|
|
2550
|
+
cancelPendingDriveSelection();
|
|
2551
|
+
const pathname = resolveUrlPathname("/");
|
|
2552
|
+
if (pathname === window.location.pathname) return;
|
|
2553
|
+
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
2554
|
+
}, DEFERRED_DRIVE_TICK_MS);
|
|
2555
|
+
};
|
|
2556
|
+
scheduleTick();
|
|
2557
|
+
}
|
|
2558
|
+
function useDropTarget() {
|
|
2559
|
+
const [isDropTarget, setIsDropTarget] = useState(false);
|
|
2560
|
+
const isDragAndDropEnabled = useIsDragAndDropEnabled();
|
|
2561
|
+
const targetSetter = n$1(() => setIsDropTarget(true), {
|
|
2562
|
+
triggerAt: "start",
|
|
2563
|
+
minQuietPeriodMs: 100
|
|
2564
|
+
});
|
|
2565
|
+
const targetUnsetter = n$1(() => setIsDropTarget(false), {
|
|
2566
|
+
triggerAt: "start",
|
|
2567
|
+
minQuietPeriodMs: 100
|
|
2568
|
+
});
|
|
2569
|
+
function setTarget() {
|
|
2570
|
+
if (!isDragAndDropEnabled) return;
|
|
2571
|
+
targetUnsetter.cancel();
|
|
2572
|
+
targetSetter.call();
|
|
2573
|
+
}
|
|
2574
|
+
function unsetTarget() {
|
|
2575
|
+
if (!isDragAndDropEnabled) return;
|
|
2576
|
+
targetSetter.cancel();
|
|
2577
|
+
targetUnsetter.call();
|
|
2578
|
+
}
|
|
2579
|
+
return {
|
|
2580
|
+
isDropTarget,
|
|
2581
|
+
setTarget,
|
|
2582
|
+
unsetTarget
|
|
2583
|
+
};
|
|
2584
|
+
}
|
|
2585
|
+
const draggingNodeEventFunctions = makePHEventFunctions("draggingNode");
|
|
2586
|
+
const useDraggingNode = draggingNodeEventFunctions.useValue;
|
|
2587
|
+
const setDraggingNode = draggingNodeEventFunctions.setValue;
|
|
2588
|
+
draggingNodeEventFunctions.addEventHandler;
|
|
2589
|
+
const draggingNodeSetter = n$1((node) => setDraggingNode(node), {
|
|
2590
|
+
reducer: (_, newNode) => newNode,
|
|
2591
|
+
triggerAt: "start",
|
|
2592
|
+
minQuietPeriodMs: 100
|
|
2593
|
+
});
|
|
2594
|
+
const draggingNodeUnsetter = n$1(() => setDraggingNode(void 0), {
|
|
2595
|
+
triggerAt: "start",
|
|
2596
|
+
minQuietPeriodMs: 100
|
|
2597
|
+
});
|
|
2598
|
+
function setDragging(node) {
|
|
2599
|
+
draggingNodeUnsetter.cancel();
|
|
2600
|
+
draggingNodeSetter.call(node);
|
|
2975
2601
|
}
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
return path.replace(basePath, basePath.endsWith("/") ? "/" : "");
|
|
2602
|
+
function unsetDragging() {
|
|
2603
|
+
draggingNodeSetter.cancel();
|
|
2604
|
+
draggingNodeUnsetter.call();
|
|
2980
2605
|
}
|
|
2981
|
-
|
|
2982
|
-
function
|
|
2983
|
-
|
|
2984
|
-
const
|
|
2985
|
-
|
|
2986
|
-
|
|
2606
|
+
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));
|
|
2607
|
+
function useDragNode(args) {
|
|
2608
|
+
const { srcId, parentId } = args;
|
|
2609
|
+
const driveId = useSelectedDriveId();
|
|
2610
|
+
const draggingNodeId = useDraggingNode()?.srcId;
|
|
2611
|
+
const params = {
|
|
2612
|
+
driveId,
|
|
2613
|
+
srcId,
|
|
2614
|
+
parentId
|
|
2615
|
+
};
|
|
2616
|
+
const draggable = isNodeDrag(params);
|
|
2617
|
+
const isDragging = t$4({
|
|
2618
|
+
srcId,
|
|
2619
|
+
draggingNodeId
|
|
2620
|
+
}, [
|
|
2621
|
+
() => draggable,
|
|
2622
|
+
({ srcId }) => e$2(srcId),
|
|
2623
|
+
({ draggingNodeId }) => e$2(draggingNodeId),
|
|
2624
|
+
({ srcId, draggingNodeId }) => t(srcId, draggingNodeId)
|
|
2625
|
+
]);
|
|
2626
|
+
const onDragStart = () => {
|
|
2627
|
+
if (!draggable) return;
|
|
2628
|
+
setDragging(params);
|
|
2629
|
+
};
|
|
2630
|
+
const onDragEnd = () => {
|
|
2631
|
+
if (!draggable) return;
|
|
2632
|
+
unsetDragging();
|
|
2633
|
+
};
|
|
2634
|
+
return {
|
|
2635
|
+
isDragging,
|
|
2636
|
+
draggable,
|
|
2637
|
+
onDragStart,
|
|
2638
|
+
onDragEnd
|
|
2639
|
+
};
|
|
2987
2640
|
}
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
const
|
|
2994
|
-
|
|
2641
|
+
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));
|
|
2642
|
+
function useDropNode(targetId) {
|
|
2643
|
+
const driveId = useSelectedDriveId();
|
|
2644
|
+
const { srcId, parentId } = useDraggingNode() ?? {};
|
|
2645
|
+
const { isDropTarget, setTarget, unsetTarget } = useDropTarget();
|
|
2646
|
+
const params = {
|
|
2647
|
+
driveId,
|
|
2648
|
+
parentId,
|
|
2649
|
+
targetId,
|
|
2650
|
+
srcId
|
|
2651
|
+
};
|
|
2652
|
+
function handleNodeDrop(event, cb) {
|
|
2653
|
+
if (!isNodeDrop(params)) return;
|
|
2654
|
+
event.preventDefault();
|
|
2655
|
+
event.stopPropagation();
|
|
2656
|
+
cb?.();
|
|
2657
|
+
}
|
|
2658
|
+
const onDragEnter = (event) => handleNodeDrop(event);
|
|
2659
|
+
const onDragOver = (event) => handleNodeDrop(event, e(setTarget));
|
|
2660
|
+
const onDragLeave = (event) => handleNodeDrop(event, e(unsetTarget));
|
|
2661
|
+
const onDrop = (event) => handleNodeDrop(event, e(() => {
|
|
2662
|
+
unsetDragging();
|
|
2663
|
+
unsetTarget();
|
|
2664
|
+
moveNodeById(params).catch(console.error);
|
|
2665
|
+
}));
|
|
2666
|
+
return {
|
|
2667
|
+
isDropTarget,
|
|
2668
|
+
onDragEnter,
|
|
2669
|
+
onDragOver,
|
|
2670
|
+
onDragLeave,
|
|
2671
|
+
onDrop
|
|
2672
|
+
};
|
|
2995
2673
|
}
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
2674
|
+
const graphQLReactorClientEventFunctions = makePHEventFunctions("reactorGraphQLClient");
|
|
2675
|
+
graphQLReactorClientEventFunctions.useValue;
|
|
2676
|
+
graphQLReactorClientEventFunctions.setValue;
|
|
2677
|
+
graphQLReactorClientEventFunctions.addEventHandler;
|
|
2678
|
+
const packageDiscoveryFunctions = makePHEventFunctions("packageDiscoveryService");
|
|
2679
|
+
packageDiscoveryFunctions.useValue;
|
|
2680
|
+
packageDiscoveryFunctions.setValue;
|
|
2681
|
+
packageDiscoveryFunctions.addEventHandler;
|
|
2682
|
+
const reactorClientModuleEventFunctions = makePHEventFunctions("reactorClientModule");
|
|
2683
|
+
const reactorClientEventFunctions = makePHEventFunctions("reactorClient");
|
|
2684
|
+
/** Returns the reactor client module (in-process or worker-backed) */
|
|
2685
|
+
const useReactorClientModule = reactorClientModuleEventFunctions.useValue;
|
|
2686
|
+
reactorClientModuleEventFunctions.setValue;
|
|
2687
|
+
reactorClientModuleEventFunctions.addEventHandler;
|
|
2688
|
+
reactorClientEventFunctions.useValue;
|
|
2689
|
+
reactorClientEventFunctions.setValue;
|
|
2690
|
+
reactorClientEventFunctions.addEventHandler;
|
|
2691
|
+
const useSync = () => useReactorClientModule()?.reactorModule?.syncModule?.syncManager;
|
|
2692
|
+
const useSyncList = () => {
|
|
2693
|
+
return useSync()?.list() ?? [];
|
|
2694
|
+
};
|
|
2695
|
+
const revisionHistoryEventFunctions = makePHEventFunctions("revisionHistoryVisible");
|
|
2696
|
+
revisionHistoryEventFunctions.useValue;
|
|
2697
|
+
/** Sets revision history visibility */
|
|
2698
|
+
const setRevisionHistoryVisible = revisionHistoryEventFunctions.setValue;
|
|
2699
|
+
revisionHistoryEventFunctions.addEventHandler;
|
|
2700
|
+
/** Shows the revision history */
|
|
2701
|
+
function showRevisionHistory() {
|
|
2702
|
+
setRevisionHistoryVisible(true);
|
|
3000
2703
|
}
|
|
3001
|
-
|
|
3002
|
-
|
|
2704
|
+
/** Sorts nodes by name. */
|
|
2705
|
+
function sortNodesByName(nodes) {
|
|
2706
|
+
return nodes.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
2707
|
+
}
|
|
2708
|
+
/** Returns whether a node is a file. */
|
|
2709
|
+
function isFileNodeKind(node) {
|
|
2710
|
+
if (!node) return false;
|
|
2711
|
+
return node.kind.toUpperCase() === "FILE";
|
|
2712
|
+
}
|
|
2713
|
+
/** Returns whether a node is a folder. */
|
|
2714
|
+
function isFolderNodeKind(node) {
|
|
2715
|
+
if (!node) return false;
|
|
2716
|
+
return node.kind.toUpperCase() === "FOLDER";
|
|
2717
|
+
}
|
|
2718
|
+
/** Returns the nodes in the selected drive. */
|
|
2719
|
+
function useNodesInSelectedDrive() {
|
|
2720
|
+
const [selectedDrive] = useSelectedDriveSafe();
|
|
2721
|
+
return selectedDrive?.state.global.nodes;
|
|
2722
|
+
}
|
|
2723
|
+
/** Returns the folder nodes in the selected drive. */
|
|
2724
|
+
function useFolderNodesInSelectedDrive() {
|
|
2725
|
+
return useNodesInSelectedDrive()?.filter((n) => isFolderNodeKind(n));
|
|
2726
|
+
}
|
|
2727
|
+
/** Returns the selected node. */
|
|
2728
|
+
function useSelectedNode() {
|
|
2729
|
+
const selectedNodeId = useSelectedNodeId();
|
|
2730
|
+
return useNodesInSelectedDrive()?.find((n) => n.id === selectedNodeId);
|
|
3003
2731
|
}
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
2732
|
+
const selectedTimelineItemEventFunctions = makePHEventFunctions("selectedTimelineItem");
|
|
2733
|
+
selectedTimelineItemEventFunctions.useValue;
|
|
2734
|
+
selectedTimelineItemEventFunctions.setValue;
|
|
2735
|
+
selectedTimelineItemEventFunctions.addEventHandler;
|
|
2736
|
+
const selectedTimelineRevisionEventFunctions = makePHEventFunctions("selectedTimelineRevision");
|
|
2737
|
+
selectedTimelineRevisionEventFunctions.useValue;
|
|
2738
|
+
selectedTimelineRevisionEventFunctions.setValue;
|
|
2739
|
+
selectedTimelineRevisionEventFunctions.addEventHandler;
|
|
2740
|
+
const toastEventFunctions = makePHEventFunctions("toast");
|
|
2741
|
+
/** Returns the toast function */
|
|
2742
|
+
const usePHToast = toastEventFunctions.useValue;
|
|
2743
|
+
toastEventFunctions.setValue;
|
|
2744
|
+
toastEventFunctions.addEventHandler;
|
|
2745
|
+
const vetraPackageManagerFunctions = makePHEventFunctions("vetraPackageManager");
|
|
2746
|
+
const useVetraPackageManager = vetraPackageManagerFunctions.useValue;
|
|
2747
|
+
/** Returns all of the Vetra packages loaded by the Connect instance */
|
|
2748
|
+
const useVetraPackages = () => {
|
|
2749
|
+
const packageManager = useVetraPackageManager();
|
|
2750
|
+
return useSyncExternalStore((cb) => packageManager ? packageManager.subscribe(cb) : () => {}, () => packageManager?.packages ?? []);
|
|
2751
|
+
};
|
|
2752
|
+
vetraPackageManagerFunctions.addEventHandler;
|
|
2753
|
+
function useDocumentModelModules() {
|
|
2754
|
+
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
2755
|
}
|
|
3012
2756
|
/**
|
|
3013
|
-
*
|
|
2757
|
+
* Resolves a document model module by document type, mirroring the registry's
|
|
2758
|
+
* semantics (`IDocumentModelRegistry.getModule`): with `version` omitted the
|
|
2759
|
+
* LATEST version of the type wins (`version ?? 1` as each module's default),
|
|
2760
|
+
* with `version` given only an exact match is returned. The reactor resolves
|
|
2761
|
+
* modules the same way when a document is created, so metadata read through
|
|
2762
|
+
* this hook and the version a creation actually uses cannot disagree.
|
|
3014
2763
|
*/
|
|
3015
|
-
function
|
|
3016
|
-
const
|
|
3017
|
-
|
|
2764
|
+
function useDocumentModelModuleById(id, version) {
|
|
2765
|
+
const documentModelModules = useDocumentModelModules();
|
|
2766
|
+
if (!id || !documentModelModules) return void 0;
|
|
2767
|
+
let latestModule;
|
|
2768
|
+
let latestVersion = -1;
|
|
2769
|
+
for (const module of documentModelModules) {
|
|
2770
|
+
if (module.documentModel.global.id !== id) continue;
|
|
2771
|
+
const moduleVersion = module.version ?? 1;
|
|
2772
|
+
if (version !== void 0) {
|
|
2773
|
+
if (moduleVersion === version) return module;
|
|
2774
|
+
continue;
|
|
2775
|
+
}
|
|
2776
|
+
if (moduleVersion > latestVersion) {
|
|
2777
|
+
latestVersion = moduleVersion;
|
|
2778
|
+
latestModule = module;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
return latestModule;
|
|
3018
2782
|
}
|
|
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));
|
|
2783
|
+
//#endregion
|
|
2784
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/descriptors.js
|
|
2785
|
+
const normalizeDescriptors = (error) => {
|
|
2786
|
+
CORE_ERROR_PROPS.forEach((propName) => {
|
|
2787
|
+
normalizeDescriptor(error, propName);
|
|
2788
|
+
});
|
|
2789
|
+
};
|
|
2790
|
+
const CORE_ERROR_PROPS = [
|
|
2791
|
+
"name",
|
|
2792
|
+
"message",
|
|
2793
|
+
"stack",
|
|
2794
|
+
"cause",
|
|
2795
|
+
"errors"
|
|
2796
|
+
];
|
|
2797
|
+
const normalizeDescriptor = (error, propName) => {
|
|
2798
|
+
const descriptor = getDescriptor(error, propName);
|
|
2799
|
+
if (descriptor === void 0) return;
|
|
2800
|
+
if (isReadonlyGetter(descriptor)) {
|
|
2801
|
+
setErrorProperty(error, propName, error[propName]);
|
|
3039
2802
|
return;
|
|
3040
2803
|
}
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
const
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
2804
|
+
if (isInvalidDescriptor(descriptor)) setErrorDescriptor(error, propName, descriptor);
|
|
2805
|
+
};
|
|
2806
|
+
const getDescriptor = (value, propName) => {
|
|
2807
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, propName);
|
|
2808
|
+
if (descriptor !== void 0) return descriptor;
|
|
2809
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2810
|
+
return prototype === null ? void 0 : getDescriptor(prototype, propName);
|
|
2811
|
+
};
|
|
2812
|
+
const isReadonlyGetter = ({ get, set }) => get !== void 0 && set === void 0;
|
|
2813
|
+
const isInvalidDescriptor = ({ enumerable, writable }) => enumerable || !writable;
|
|
2814
|
+
const setErrorProperty = (error, propName, value) => {
|
|
2815
|
+
setErrorDescriptor(error, propName, { value });
|
|
2816
|
+
};
|
|
2817
|
+
const setErrorDescriptor = (error, propName, descriptor) => {
|
|
2818
|
+
Object.defineProperty(error, propName, {
|
|
2819
|
+
...descriptor,
|
|
2820
|
+
..."get" in descriptor || "set" in descriptor ? {} : { writable: true },
|
|
2821
|
+
enumerable: false,
|
|
2822
|
+
configurable: true
|
|
2823
|
+
});
|
|
2824
|
+
};
|
|
2825
|
+
//#endregion
|
|
2826
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/aggregate.js
|
|
2827
|
+
const normalizeAggregate = (error, recurse) => {
|
|
2828
|
+
if (Array.isArray(error.errors)) setErrorProperty(error, "errors", error.errors.filter(isDefined).map(recurse).filter(Boolean));
|
|
2829
|
+
else if (isAggregateError(error)) setErrorProperty(error, "errors", []);
|
|
2830
|
+
else if (error.errors !== void 0) deleteAggregateErrors(error);
|
|
2831
|
+
};
|
|
2832
|
+
const isDefined = (error) => error !== void 0;
|
|
2833
|
+
const isAggregateError = (error) => "AggregateError" in globalThis && (error.name === "AggregateError" || error instanceof AggregateError);
|
|
2834
|
+
const deleteAggregateErrors = (error) => {
|
|
2835
|
+
delete error.errors;
|
|
2836
|
+
if (error.errors !== void 0) setErrorProperty(error, "errors", []);
|
|
2837
|
+
};
|
|
2838
|
+
//#endregion
|
|
2839
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/cause.js
|
|
2840
|
+
const normalizeCause = (error, recurse) => {
|
|
2841
|
+
if (!("cause" in error)) return;
|
|
2842
|
+
const cause = error.cause === void 0 ? error.cause : recurse(error.cause);
|
|
2843
|
+
if (cause === void 0) delete error.cause;
|
|
2844
|
+
else setErrorProperty(error, "cause", cause);
|
|
2845
|
+
};
|
|
2846
|
+
//#endregion
|
|
2847
|
+
//#region ../../node_modules/.pnpm/is-error-instance@3.0.1/node_modules/is-error-instance/build/src/main.js
|
|
2848
|
+
const isErrorInstance = (value) => isInstanceOfError(value) || hasErrorTag(value);
|
|
2849
|
+
const isInstanceOfError = (value) => {
|
|
2850
|
+
try {
|
|
2851
|
+
return value instanceof Error;
|
|
2852
|
+
} catch {
|
|
2853
|
+
return false;
|
|
2854
|
+
}
|
|
2855
|
+
};
|
|
2856
|
+
const hasErrorTag = (value) => {
|
|
2857
|
+
try {
|
|
2858
|
+
return ERROR_TAGS.has(Object.prototype.toString.call(value));
|
|
2859
|
+
} catch {
|
|
2860
|
+
return false;
|
|
2861
|
+
}
|
|
2862
|
+
};
|
|
2863
|
+
const ERROR_TAGS = new Set([
|
|
2864
|
+
"[object Error]",
|
|
2865
|
+
"[object DOMException]",
|
|
2866
|
+
"[object DOMError]",
|
|
2867
|
+
"[object Exception]"
|
|
2868
|
+
]);
|
|
2869
|
+
//#endregion
|
|
2870
|
+
//#region ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
|
|
2871
|
+
function isPlainObject(value) {
|
|
2872
|
+
if (typeof value !== "object" || value === null) return false;
|
|
2873
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2874
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
3058
2875
|
}
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
2876
|
+
//#endregion
|
|
2877
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/modifiable.js
|
|
2878
|
+
const isNonModifiableError = (error) => !Object.isExtensible(error) || CORE_ERROR_PROPS.some((propName) => isNonConfigurableProp(error, propName) || isThrowingProp(error, propName));
|
|
2879
|
+
const isNonConfigurableProp = (error, propName) => {
|
|
2880
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, propName);
|
|
2881
|
+
return descriptor !== void 0 && !descriptor.configurable;
|
|
2882
|
+
};
|
|
2883
|
+
const isThrowingProp = (error, propName) => {
|
|
2884
|
+
try {
|
|
2885
|
+
error[propName];
|
|
2886
|
+
return false;
|
|
2887
|
+
} catch {
|
|
2888
|
+
return true;
|
|
2889
|
+
}
|
|
2890
|
+
};
|
|
2891
|
+
//#endregion
|
|
2892
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/stack.js
|
|
2893
|
+
const setStack = (error) => {
|
|
2894
|
+
setErrorProperty(error, "stack", getStack(error.message, error.name));
|
|
2895
|
+
};
|
|
2896
|
+
const getStack = (message = "", name = "Error") => {
|
|
2897
|
+
const { stack } = new (getErrorClass(name))(message);
|
|
2898
|
+
return typeof stack === "string" && stack !== "" ? stack : `${name}: ${message}`;
|
|
2899
|
+
};
|
|
2900
|
+
const getErrorClass = (name) => {
|
|
2901
|
+
const descriptor = {
|
|
2902
|
+
value: name,
|
|
2903
|
+
enumerable: false,
|
|
2904
|
+
writable: true,
|
|
2905
|
+
configurable: true
|
|
2906
|
+
};
|
|
2907
|
+
const StackError = Object.defineProperty(class extends Error {}, "name", descriptor);
|
|
2908
|
+
Object.defineProperty(StackError.prototype, "name", descriptor);
|
|
2909
|
+
return StackError;
|
|
2910
|
+
};
|
|
2911
|
+
//#endregion
|
|
2912
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/copy.js
|
|
2913
|
+
const copyObject = (object) => {
|
|
2914
|
+
const objectCopy = {};
|
|
2915
|
+
for (const propName of getPropsToCopy(object)) try {
|
|
2916
|
+
const value = object[propName];
|
|
2917
|
+
const { enumerable, configurable, writable = true } = getDescriptor(object, propName);
|
|
2918
|
+
Object.defineProperty(objectCopy, propName, {
|
|
2919
|
+
value,
|
|
2920
|
+
enumerable,
|
|
2921
|
+
configurable,
|
|
2922
|
+
writable
|
|
2923
|
+
});
|
|
2924
|
+
} catch {}
|
|
2925
|
+
return objectCopy;
|
|
2926
|
+
};
|
|
2927
|
+
const getPropsToCopy = (object) => {
|
|
2928
|
+
const propNames = getOwnKeys(object);
|
|
2929
|
+
for (const propName of CORE_ERROR_PROPS) if (isInheritedProp(object, propName)) propNames.push(propName);
|
|
2930
|
+
return propNames;
|
|
2931
|
+
};
|
|
2932
|
+
const getOwnKeys = (object) => {
|
|
2933
|
+
try {
|
|
2934
|
+
return Reflect.ownKeys(object);
|
|
2935
|
+
} catch {
|
|
2936
|
+
return [];
|
|
2937
|
+
}
|
|
2938
|
+
};
|
|
2939
|
+
const isInheritedProp = (object, propName) => {
|
|
2940
|
+
try {
|
|
2941
|
+
return propName in object && !Object.hasOwn(object, propName);
|
|
2942
|
+
} catch {
|
|
2943
|
+
return false;
|
|
2944
|
+
}
|
|
2945
|
+
};
|
|
2946
|
+
//#endregion
|
|
2947
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/object.js
|
|
2948
|
+
const objectifyError = (object) => {
|
|
2949
|
+
const { name, message, stack, cause, errors, ...objectA } = copyObject(object);
|
|
2950
|
+
const messageA = getMessage(message, objectA);
|
|
2951
|
+
const error = newError(name, messageA);
|
|
2952
|
+
if (message === messageA) assignObjectProps(error, objectA);
|
|
2953
|
+
Object.entries({
|
|
2954
|
+
name,
|
|
2955
|
+
stack,
|
|
2956
|
+
cause,
|
|
2957
|
+
errors
|
|
2958
|
+
}).forEach(([propName, propValue]) => {
|
|
2959
|
+
setNewErrorProperty(error, propName, propValue);
|
|
2960
|
+
});
|
|
2961
|
+
if (stack === void 0) setStack(error);
|
|
2962
|
+
return error;
|
|
2963
|
+
};
|
|
2964
|
+
const getMessage = (message, object) => typeof message === "string" && message !== "" ? message : truncateMessage(safeJsonStringify(object));
|
|
2965
|
+
const safeJsonStringify = (object) => {
|
|
2966
|
+
try {
|
|
2967
|
+
return JSON.stringify(object);
|
|
2968
|
+
} catch {
|
|
2969
|
+
return safeStringify(object);
|
|
3067
2970
|
}
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
return;
|
|
2971
|
+
};
|
|
2972
|
+
const safeStringify = (object) => {
|
|
2973
|
+
try {
|
|
2974
|
+
return String(object);
|
|
2975
|
+
} catch {
|
|
2976
|
+
return "Invalid error";
|
|
3075
2977
|
}
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
if (
|
|
3098
|
-
|
|
3099
|
-
|
|
2978
|
+
};
|
|
2979
|
+
const truncateMessage = (message) => message.length < MESSAGE_MAX_SIZE ? message : `${message.slice(0, MESSAGE_MAX_SIZE)}...`;
|
|
2980
|
+
const MESSAGE_MAX_SIZE = 1e3;
|
|
2981
|
+
const newError = (name, message) => {
|
|
2982
|
+
if (name === "AggregateError" && "AggregateError" in globalThis) return new AggregateError([], message);
|
|
2983
|
+
if (name in NATIVE_ERRORS) return new NATIVE_ERRORS[name](message);
|
|
2984
|
+
return new Error(message);
|
|
2985
|
+
};
|
|
2986
|
+
const NATIVE_ERRORS = {
|
|
2987
|
+
Error,
|
|
2988
|
+
ReferenceError,
|
|
2989
|
+
TypeError,
|
|
2990
|
+
SyntaxError,
|
|
2991
|
+
RangeError,
|
|
2992
|
+
URIError,
|
|
2993
|
+
EvalError
|
|
2994
|
+
};
|
|
2995
|
+
const assignObjectProps = (error, object) => {
|
|
2996
|
+
for (const propName in object) if (!(propName in error)) error[propName] = object[propName];
|
|
2997
|
+
};
|
|
2998
|
+
const setNewErrorProperty = (error, propName, propValue) => {
|
|
2999
|
+
if (propValue !== void 0) setErrorProperty(error, propName, propValue);
|
|
3000
|
+
};
|
|
3001
|
+
//#endregion
|
|
3002
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/string.js
|
|
3003
|
+
const stringifyError = (value) => {
|
|
3004
|
+
try {
|
|
3005
|
+
const error = new Error(String(value));
|
|
3006
|
+
setStack(error);
|
|
3007
|
+
return error;
|
|
3008
|
+
} catch (error_) {
|
|
3009
|
+
return error_;
|
|
3100
3010
|
}
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3011
|
+
};
|
|
3012
|
+
//#endregion
|
|
3013
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/create/main.js
|
|
3014
|
+
const { toString: objectToString } = Object.prototype;
|
|
3015
|
+
const createError = (value) => {
|
|
3016
|
+
if (isErrorPlainObj(value)) return objectifyError(value);
|
|
3017
|
+
if (!isErrorInstance(value)) return stringifyError(value);
|
|
3018
|
+
if (isInvalidError(value)) return objectifyError(value);
|
|
3019
|
+
return value;
|
|
3020
|
+
};
|
|
3021
|
+
const isErrorPlainObj = (value) => {
|
|
3022
|
+
try {
|
|
3023
|
+
return isPlainObject(value);
|
|
3024
|
+
} catch {
|
|
3025
|
+
return false;
|
|
3104
3026
|
}
|
|
3105
|
-
}
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3027
|
+
};
|
|
3028
|
+
const isInvalidError = (value) => isProxy(value) || isNonModifiableError(value) || hasInvalidConstructor(value);
|
|
3029
|
+
const isProxy = (value) => {
|
|
3030
|
+
try {
|
|
3031
|
+
return objectToString.call(value) === "[object Object]";
|
|
3032
|
+
} catch {
|
|
3033
|
+
return true;
|
|
3034
|
+
}
|
|
3035
|
+
};
|
|
3036
|
+
const hasInvalidConstructor = (error) => typeof error.constructor !== "function" || typeof error.constructor.name !== "string" || error.constructor.name === "" || error.constructor.prototype !== Object.getPrototypeOf(error);
|
|
3037
|
+
//#endregion
|
|
3038
|
+
//#region ../../node_modules/.pnpm/normalize-exception@4.0.1/node_modules/normalize-exception/build/src/main.js
|
|
3039
|
+
const normalizeException = (error, { shallow = false } = {}) => recurseException(error, [], shallow);
|
|
3040
|
+
const recurseException = (error, parents, shallow) => {
|
|
3041
|
+
if (parents.includes(error)) return;
|
|
3042
|
+
const recurse = shallow ? identity : (innerError) => recurseException(innerError, [...parents, error], shallow);
|
|
3043
|
+
const errorA = createError(error);
|
|
3044
|
+
normalizeProps(errorA, recurse);
|
|
3045
|
+
return errorA;
|
|
3046
|
+
};
|
|
3047
|
+
const identity = (error) => error;
|
|
3048
|
+
const normalizeProps = (error, recurse) => {
|
|
3049
|
+
normalizeName(error);
|
|
3050
|
+
normalizeMessage(error);
|
|
3051
|
+
normalizeStack(error);
|
|
3052
|
+
normalizeCause(error, recurse);
|
|
3053
|
+
normalizeAggregate(error, recurse);
|
|
3054
|
+
normalizeDescriptors(error);
|
|
3055
|
+
};
|
|
3056
|
+
const normalizeName = (error) => {
|
|
3057
|
+
if (isDefinedString(error.name)) return;
|
|
3058
|
+
const prototypeName = Object.getPrototypeOf(error).name;
|
|
3059
|
+
setErrorProperty(error, "name", isDefinedString(prototypeName) ? prototypeName : error.constructor.name);
|
|
3060
|
+
};
|
|
3061
|
+
const normalizeMessage = (error) => {
|
|
3062
|
+
if (!isDefinedString(error.message)) setErrorProperty(error, "message", "");
|
|
3063
|
+
};
|
|
3064
|
+
const normalizeStack = (error) => {
|
|
3065
|
+
if (!isDefinedString(error.stack)) setStack(error);
|
|
3066
|
+
};
|
|
3067
|
+
const isDefinedString = (value) => typeof value === "string" && value !== "";
|
|
3068
|
+
//#endregion
|
|
3069
|
+
//#region ../reactor-browser/dist/index.js
|
|
3070
|
+
var import_lz_string = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3071
|
+
var LZString = (function() {
|
|
3072
|
+
var f = String.fromCharCode;
|
|
3073
|
+
var keyStrBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
3074
|
+
var keyStrUriSafe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$";
|
|
3075
|
+
var baseReverseDic = {};
|
|
3076
|
+
function getBaseValue(alphabet, character) {
|
|
3077
|
+
if (!baseReverseDic[alphabet]) {
|
|
3078
|
+
baseReverseDic[alphabet] = {};
|
|
3079
|
+
for (var i = 0; i < alphabet.length; i++) baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
3080
|
+
}
|
|
3081
|
+
return baseReverseDic[alphabet][character];
|
|
3082
|
+
}
|
|
3083
|
+
var LZString = {
|
|
3084
|
+
compressToBase64: function(input) {
|
|
3085
|
+
if (input == null) return "";
|
|
3086
|
+
var res = LZString._compress(input, 6, function(a) {
|
|
3087
|
+
return keyStrBase64.charAt(a);
|
|
3088
|
+
});
|
|
3089
|
+
switch (res.length % 4) {
|
|
3090
|
+
default:
|
|
3091
|
+
case 0: return res;
|
|
3092
|
+
case 1: return res + "===";
|
|
3093
|
+
case 2: return res + "==";
|
|
3094
|
+
case 3: return res + "=";
|
|
3095
|
+
}
|
|
3096
|
+
},
|
|
3097
|
+
decompressFromBase64: function(input) {
|
|
3098
|
+
if (input == null) return "";
|
|
3099
|
+
if (input == "") return null;
|
|
3100
|
+
return LZString._decompress(input.length, 32, function(index) {
|
|
3101
|
+
return getBaseValue(keyStrBase64, input.charAt(index));
|
|
3102
|
+
});
|
|
3103
|
+
},
|
|
3104
|
+
compressToUTF16: function(input) {
|
|
3105
|
+
if (input == null) return "";
|
|
3106
|
+
return LZString._compress(input, 15, function(a) {
|
|
3107
|
+
return f(a + 32);
|
|
3108
|
+
}) + " ";
|
|
3109
|
+
},
|
|
3110
|
+
decompressFromUTF16: function(compressed) {
|
|
3111
|
+
if (compressed == null) return "";
|
|
3112
|
+
if (compressed == "") return null;
|
|
3113
|
+
return LZString._decompress(compressed.length, 16384, function(index) {
|
|
3114
|
+
return compressed.charCodeAt(index) - 32;
|
|
3115
|
+
});
|
|
3116
|
+
},
|
|
3117
|
+
compressToUint8Array: function(uncompressed) {
|
|
3118
|
+
var compressed = LZString.compress(uncompressed);
|
|
3119
|
+
var buf = new Uint8Array(compressed.length * 2);
|
|
3120
|
+
for (var i = 0, TotalLen = compressed.length; i < TotalLen; i++) {
|
|
3121
|
+
var current_value = compressed.charCodeAt(i);
|
|
3122
|
+
buf[i * 2] = current_value >>> 8;
|
|
3123
|
+
buf[i * 2 + 1] = current_value % 256;
|
|
3124
|
+
}
|
|
3125
|
+
return buf;
|
|
3126
|
+
},
|
|
3127
|
+
decompressFromUint8Array: function(compressed) {
|
|
3128
|
+
if (compressed === null || compressed === void 0) return LZString.decompress(compressed);
|
|
3129
|
+
else {
|
|
3130
|
+
var buf = new Array(compressed.length / 2);
|
|
3131
|
+
for (var i = 0, TotalLen = buf.length; i < TotalLen; i++) buf[i] = compressed[i * 2] * 256 + compressed[i * 2 + 1];
|
|
3132
|
+
var result = [];
|
|
3133
|
+
buf.forEach(function(c) {
|
|
3134
|
+
result.push(f(c));
|
|
3135
|
+
});
|
|
3136
|
+
return LZString.decompress(result.join(""));
|
|
3137
|
+
}
|
|
3138
|
+
},
|
|
3139
|
+
compressToEncodedURIComponent: function(input) {
|
|
3140
|
+
if (input == null) return "";
|
|
3141
|
+
return LZString._compress(input, 6, function(a) {
|
|
3142
|
+
return keyStrUriSafe.charAt(a);
|
|
3143
|
+
});
|
|
3144
|
+
},
|
|
3145
|
+
decompressFromEncodedURIComponent: function(input) {
|
|
3146
|
+
if (input == null) return "";
|
|
3147
|
+
if (input == "") return null;
|
|
3148
|
+
input = input.replace(/ /g, "+");
|
|
3149
|
+
return LZString._decompress(input.length, 32, function(index) {
|
|
3150
|
+
return getBaseValue(keyStrUriSafe, input.charAt(index));
|
|
3151
|
+
});
|
|
3152
|
+
},
|
|
3153
|
+
compress: function(uncompressed) {
|
|
3154
|
+
return LZString._compress(uncompressed, 16, function(a) {
|
|
3155
|
+
return f(a);
|
|
3156
|
+
});
|
|
3157
|
+
},
|
|
3158
|
+
_compress: function(uncompressed, bitsPerChar, getCharFromInt) {
|
|
3159
|
+
if (uncompressed == null) return "";
|
|
3160
|
+
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;
|
|
3161
|
+
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
3162
|
+
context_c = uncompressed.charAt(ii);
|
|
3163
|
+
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
3164
|
+
context_dictionary[context_c] = context_dictSize++;
|
|
3165
|
+
context_dictionaryToCreate[context_c] = true;
|
|
3166
|
+
}
|
|
3167
|
+
context_wc = context_w + context_c;
|
|
3168
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) context_w = context_wc;
|
|
3169
|
+
else {
|
|
3170
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
3171
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
3172
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3173
|
+
context_data_val = context_data_val << 1;
|
|
3174
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3175
|
+
context_data_position = 0;
|
|
3176
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3177
|
+
context_data_val = 0;
|
|
3178
|
+
} else context_data_position++;
|
|
3179
|
+
}
|
|
3180
|
+
value = context_w.charCodeAt(0);
|
|
3181
|
+
for (i = 0; i < 8; i++) {
|
|
3182
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3183
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3184
|
+
context_data_position = 0;
|
|
3185
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3186
|
+
context_data_val = 0;
|
|
3187
|
+
} else context_data_position++;
|
|
3188
|
+
value = value >> 1;
|
|
3189
|
+
}
|
|
3190
|
+
} else {
|
|
3191
|
+
value = 1;
|
|
3192
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3193
|
+
context_data_val = context_data_val << 1 | value;
|
|
3194
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3195
|
+
context_data_position = 0;
|
|
3196
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3197
|
+
context_data_val = 0;
|
|
3198
|
+
} else context_data_position++;
|
|
3199
|
+
value = 0;
|
|
3200
|
+
}
|
|
3201
|
+
value = context_w.charCodeAt(0);
|
|
3202
|
+
for (i = 0; i < 16; i++) {
|
|
3203
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3204
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3205
|
+
context_data_position = 0;
|
|
3206
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3207
|
+
context_data_val = 0;
|
|
3208
|
+
} else context_data_position++;
|
|
3209
|
+
value = value >> 1;
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
context_enlargeIn--;
|
|
3213
|
+
if (context_enlargeIn == 0) {
|
|
3214
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3215
|
+
context_numBits++;
|
|
3216
|
+
}
|
|
3217
|
+
delete context_dictionaryToCreate[context_w];
|
|
3218
|
+
} else {
|
|
3219
|
+
value = context_dictionary[context_w];
|
|
3220
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3221
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3222
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3223
|
+
context_data_position = 0;
|
|
3224
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3225
|
+
context_data_val = 0;
|
|
3226
|
+
} else context_data_position++;
|
|
3227
|
+
value = value >> 1;
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
context_enlargeIn--;
|
|
3231
|
+
if (context_enlargeIn == 0) {
|
|
3232
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3233
|
+
context_numBits++;
|
|
3234
|
+
}
|
|
3235
|
+
context_dictionary[context_wc] = context_dictSize++;
|
|
3236
|
+
context_w = String(context_c);
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
if (context_w !== "") {
|
|
3240
|
+
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
3241
|
+
if (context_w.charCodeAt(0) < 256) {
|
|
3242
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3243
|
+
context_data_val = context_data_val << 1;
|
|
3244
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3245
|
+
context_data_position = 0;
|
|
3246
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3247
|
+
context_data_val = 0;
|
|
3248
|
+
} else context_data_position++;
|
|
3249
|
+
}
|
|
3250
|
+
value = context_w.charCodeAt(0);
|
|
3251
|
+
for (i = 0; i < 8; i++) {
|
|
3252
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3253
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3254
|
+
context_data_position = 0;
|
|
3255
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3256
|
+
context_data_val = 0;
|
|
3257
|
+
} else context_data_position++;
|
|
3258
|
+
value = value >> 1;
|
|
3259
|
+
}
|
|
3260
|
+
} else {
|
|
3261
|
+
value = 1;
|
|
3262
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3263
|
+
context_data_val = context_data_val << 1 | value;
|
|
3264
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3265
|
+
context_data_position = 0;
|
|
3266
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3267
|
+
context_data_val = 0;
|
|
3268
|
+
} else context_data_position++;
|
|
3269
|
+
value = 0;
|
|
3270
|
+
}
|
|
3271
|
+
value = context_w.charCodeAt(0);
|
|
3272
|
+
for (i = 0; i < 16; i++) {
|
|
3273
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3274
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3275
|
+
context_data_position = 0;
|
|
3276
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3277
|
+
context_data_val = 0;
|
|
3278
|
+
} else context_data_position++;
|
|
3279
|
+
value = value >> 1;
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
context_enlargeIn--;
|
|
3283
|
+
if (context_enlargeIn == 0) {
|
|
3284
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3285
|
+
context_numBits++;
|
|
3286
|
+
}
|
|
3287
|
+
delete context_dictionaryToCreate[context_w];
|
|
3288
|
+
} else {
|
|
3289
|
+
value = context_dictionary[context_w];
|
|
3290
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3291
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3292
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3293
|
+
context_data_position = 0;
|
|
3294
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3295
|
+
context_data_val = 0;
|
|
3296
|
+
} else context_data_position++;
|
|
3297
|
+
value = value >> 1;
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
context_enlargeIn--;
|
|
3301
|
+
if (context_enlargeIn == 0) {
|
|
3302
|
+
context_enlargeIn = Math.pow(2, context_numBits);
|
|
3303
|
+
context_numBits++;
|
|
3304
|
+
}
|
|
3305
|
+
}
|
|
3306
|
+
value = 2;
|
|
3307
|
+
for (i = 0; i < context_numBits; i++) {
|
|
3308
|
+
context_data_val = context_data_val << 1 | value & 1;
|
|
3309
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3310
|
+
context_data_position = 0;
|
|
3311
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3312
|
+
context_data_val = 0;
|
|
3313
|
+
} else context_data_position++;
|
|
3314
|
+
value = value >> 1;
|
|
3315
|
+
}
|
|
3316
|
+
while (true) {
|
|
3317
|
+
context_data_val = context_data_val << 1;
|
|
3318
|
+
if (context_data_position == bitsPerChar - 1) {
|
|
3319
|
+
context_data.push(getCharFromInt(context_data_val));
|
|
3320
|
+
break;
|
|
3321
|
+
} else context_data_position++;
|
|
3322
|
+
}
|
|
3323
|
+
return context_data.join("");
|
|
3324
|
+
},
|
|
3325
|
+
decompress: function(compressed) {
|
|
3326
|
+
if (compressed == null) return "";
|
|
3327
|
+
if (compressed == "") return null;
|
|
3328
|
+
return LZString._decompress(compressed.length, 32768, function(index) {
|
|
3329
|
+
return compressed.charCodeAt(index);
|
|
3330
|
+
});
|
|
3331
|
+
},
|
|
3332
|
+
_decompress: function(length, resetValue, getNextValue) {
|
|
3333
|
+
var dictionary = [], enlargeIn = 4, dictSize = 4, numBits = 3, entry = "", result = [], i, w, bits, resb, maxpower, power, c, data = {
|
|
3334
|
+
val: getNextValue(0),
|
|
3335
|
+
position: resetValue,
|
|
3336
|
+
index: 1
|
|
3337
|
+
};
|
|
3338
|
+
for (i = 0; i < 3; i += 1) dictionary[i] = i;
|
|
3339
|
+
bits = 0;
|
|
3340
|
+
maxpower = Math.pow(2, 2);
|
|
3341
|
+
power = 1;
|
|
3342
|
+
while (power != maxpower) {
|
|
3343
|
+
resb = data.val & data.position;
|
|
3344
|
+
data.position >>= 1;
|
|
3345
|
+
if (data.position == 0) {
|
|
3346
|
+
data.position = resetValue;
|
|
3347
|
+
data.val = getNextValue(data.index++);
|
|
3348
|
+
}
|
|
3349
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3350
|
+
power <<= 1;
|
|
3351
|
+
}
|
|
3352
|
+
switch (bits) {
|
|
3353
|
+
case 0:
|
|
3354
|
+
bits = 0;
|
|
3355
|
+
maxpower = Math.pow(2, 8);
|
|
3356
|
+
power = 1;
|
|
3357
|
+
while (power != maxpower) {
|
|
3358
|
+
resb = data.val & data.position;
|
|
3359
|
+
data.position >>= 1;
|
|
3360
|
+
if (data.position == 0) {
|
|
3361
|
+
data.position = resetValue;
|
|
3362
|
+
data.val = getNextValue(data.index++);
|
|
3363
|
+
}
|
|
3364
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3365
|
+
power <<= 1;
|
|
3366
|
+
}
|
|
3367
|
+
c = f(bits);
|
|
3368
|
+
break;
|
|
3369
|
+
case 1:
|
|
3370
|
+
bits = 0;
|
|
3371
|
+
maxpower = Math.pow(2, 16);
|
|
3372
|
+
power = 1;
|
|
3373
|
+
while (power != maxpower) {
|
|
3374
|
+
resb = data.val & data.position;
|
|
3375
|
+
data.position >>= 1;
|
|
3376
|
+
if (data.position == 0) {
|
|
3377
|
+
data.position = resetValue;
|
|
3378
|
+
data.val = getNextValue(data.index++);
|
|
3379
|
+
}
|
|
3380
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3381
|
+
power <<= 1;
|
|
3382
|
+
}
|
|
3383
|
+
c = f(bits);
|
|
3384
|
+
break;
|
|
3385
|
+
case 2: return "";
|
|
3386
|
+
}
|
|
3387
|
+
dictionary[3] = c;
|
|
3388
|
+
w = c;
|
|
3389
|
+
result.push(c);
|
|
3390
|
+
while (true) {
|
|
3391
|
+
if (data.index > length) return "";
|
|
3392
|
+
bits = 0;
|
|
3393
|
+
maxpower = Math.pow(2, numBits);
|
|
3394
|
+
power = 1;
|
|
3395
|
+
while (power != maxpower) {
|
|
3396
|
+
resb = data.val & data.position;
|
|
3397
|
+
data.position >>= 1;
|
|
3398
|
+
if (data.position == 0) {
|
|
3399
|
+
data.position = resetValue;
|
|
3400
|
+
data.val = getNextValue(data.index++);
|
|
3401
|
+
}
|
|
3402
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3403
|
+
power <<= 1;
|
|
3404
|
+
}
|
|
3405
|
+
switch (c = bits) {
|
|
3406
|
+
case 0:
|
|
3407
|
+
bits = 0;
|
|
3408
|
+
maxpower = Math.pow(2, 8);
|
|
3409
|
+
power = 1;
|
|
3410
|
+
while (power != maxpower) {
|
|
3411
|
+
resb = data.val & data.position;
|
|
3412
|
+
data.position >>= 1;
|
|
3413
|
+
if (data.position == 0) {
|
|
3414
|
+
data.position = resetValue;
|
|
3415
|
+
data.val = getNextValue(data.index++);
|
|
3416
|
+
}
|
|
3417
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3418
|
+
power <<= 1;
|
|
3419
|
+
}
|
|
3420
|
+
dictionary[dictSize++] = f(bits);
|
|
3421
|
+
c = dictSize - 1;
|
|
3422
|
+
enlargeIn--;
|
|
3423
|
+
break;
|
|
3424
|
+
case 1:
|
|
3425
|
+
bits = 0;
|
|
3426
|
+
maxpower = Math.pow(2, 16);
|
|
3427
|
+
power = 1;
|
|
3428
|
+
while (power != maxpower) {
|
|
3429
|
+
resb = data.val & data.position;
|
|
3430
|
+
data.position >>= 1;
|
|
3431
|
+
if (data.position == 0) {
|
|
3432
|
+
data.position = resetValue;
|
|
3433
|
+
data.val = getNextValue(data.index++);
|
|
3434
|
+
}
|
|
3435
|
+
bits |= (resb > 0 ? 1 : 0) * power;
|
|
3436
|
+
power <<= 1;
|
|
3437
|
+
}
|
|
3438
|
+
dictionary[dictSize++] = f(bits);
|
|
3439
|
+
c = dictSize - 1;
|
|
3440
|
+
enlargeIn--;
|
|
3441
|
+
break;
|
|
3442
|
+
case 2: return result.join("");
|
|
3443
|
+
}
|
|
3444
|
+
if (enlargeIn == 0) {
|
|
3445
|
+
enlargeIn = Math.pow(2, numBits);
|
|
3446
|
+
numBits++;
|
|
3447
|
+
}
|
|
3448
|
+
if (dictionary[c]) entry = dictionary[c];
|
|
3449
|
+
else if (c === dictSize) entry = w + w.charAt(0);
|
|
3450
|
+
else return null;
|
|
3451
|
+
result.push(entry);
|
|
3452
|
+
dictionary[dictSize++] = w + entry.charAt(0);
|
|
3453
|
+
enlargeIn--;
|
|
3454
|
+
w = entry;
|
|
3455
|
+
if (enlargeIn == 0) {
|
|
3456
|
+
enlargeIn = Math.pow(2, numBits);
|
|
3457
|
+
numBits++;
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3123
3460
|
}
|
|
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
|
|
3461
|
+
};
|
|
3462
|
+
return LZString;
|
|
3463
|
+
})();
|
|
3464
|
+
if (typeof define === "function" && define.amd) define(function() {
|
|
3465
|
+
return LZString;
|
|
3138
3466
|
});
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3467
|
+
else if (typeof module !== "undefined" && module != null) module.exports = LZString;
|
|
3468
|
+
else if (typeof angular !== "undefined" && angular != null) angular.module("LZString", []).factory("LZString", function() {
|
|
3469
|
+
return LZString;
|
|
3142
3470
|
});
|
|
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
|
-
}
|
|
3471
|
+
})))(), 1);
|
|
3472
|
+
/** Document types that represent a "drive": a container of nodes. */
|
|
3473
|
+
const DRIVE_DOCUMENT_TYPES = ["powerhouse/document-drive", "powerhouse/reactor-drive"];
|
|
3333
3474
|
function useAllowedDocumentModelModules() {
|
|
3334
3475
|
const documentModelModules = useDocumentModelModules();
|
|
3335
3476
|
const allowedDocumentTypes = useAllowedDocumentTypes();
|
|
@@ -3514,7 +3655,7 @@ function useNodeActions() {
|
|
|
3514
3655
|
}
|
|
3515
3656
|
async function onAddFolder(name, parent) {
|
|
3516
3657
|
if (!selectedDriveId) return;
|
|
3517
|
-
return addFolder(selectedDriveId, name, resolveNode(selectedDriveId, parent)?.id);
|
|
3658
|
+
return addFolder$1(selectedDriveId, name, resolveNode(selectedDriveId, parent)?.id);
|
|
3518
3659
|
}
|
|
3519
3660
|
async function onRenameNode(newName, node) {
|
|
3520
3661
|
if (!selectedDriveId) return;
|
|
@@ -3829,6 +3970,6 @@ function createDebouncedRefreshReactorDataClient(debounceDelayMs = DEFAULT_DEBOU
|
|
|
3829
3970
|
createDebouncedRefreshReactorData();
|
|
3830
3971
|
createDebouncedRefreshReactorDataClient();
|
|
3831
3972
|
//#endregion
|
|
3832
|
-
export {
|
|
3973
|
+
export { usePHToast as A, setSelectedNode as C, useDisabledEditors as D, showRevisionHistory as E, t$2 as F, t$5 as I, useDocumentById as L, useSelectedDriveSafe as M, e$1 as N, useDragNode as O, e$4 as P, setSelectedDrive as S, showDeleteNodeModal as T, useTheme as _, useEditorModules as a, isFileNodeKind as b, useNodeActions as c, useNodesInSelectedDriveOrFolder as d, useSelectedDocumentOfType as f, useSetPHDocumentEditorConfig as g, useSetPHAppConfig as h, useDownloadDocument as i, useSelectedDriveId as j, useDropNode as k, useNodeById as l, useSelectedNodePath as m, preloadEditorModule as n, useEditorModulesForDocumentType as o, useSelectedDocumentSafe as p, useAllowedDocumentModelModules as r, useGetSwitchboardLink as s, getSyncStatusSync as t, useNodeParentFolderById as u, useUserPermissions as v, showCreateDocumentModal as w, isFolderNodeKind as x, addFolder$1 as y };
|
|
3833
3974
|
|
|
3834
|
-
//# sourceMappingURL=dist-
|
|
3975
|
+
//# sourceMappingURL=dist-Bb4BpVo4.js.map
|