@powerhousedao/reactor-browser 6.2.3-dev.60 → 6.2.3-dev.62
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/{attachment-service-DG6UkyMv.d.ts → attachment-service-CQ3JygJd.d.ts} +3 -3
- package/dist/{attachment-service-DG6UkyMv.d.ts.map → attachment-service-CQ3JygJd.d.ts.map} +1 -1
- package/dist/{client-Cq5avLW5.js → client-Bwiji4R6.js} +6 -2
- package/dist/client-Bwiji4R6.js.map +1 -0
- package/dist/{dispatch-C1VVTn5S.js → dispatch-BmdzdTwb.js} +15 -11
- package/dist/dispatch-BmdzdTwb.js.map +1 -0
- package/dist/{document-by-id-BRDkvmpn.js → document-by-id-BqNuTx4S.js} +2 -2
- package/dist/{document-by-id-BRDkvmpn.js.map → document-by-id-BqNuTx4S.js.map} +1 -1
- package/dist/{document-model-modules-Gsh1Xr7j.js → document-model-modules-Wjh92XAb.js} +192 -157
- package/dist/document-model-modules-Wjh92XAb.js.map +1 -0
- package/dist/{document-operations-BSzcF0mu.js → document-operations--Z0AOyyy.js} +74 -27
- package/dist/document-operations--Z0AOyyy.js.map +1 -0
- package/dist/{global-BuSwbbY0.d.ts → global-CPJA8ePb.d.ts} +56 -4
- package/dist/global-CPJA8ePb.d.ts.map +1 -0
- package/dist/{index-ewIc3pEO.d.ts → index-DRCTps7m.d.ts} +2 -2
- package/dist/{index-ewIc3pEO.d.ts.map → index-DRCTps7m.d.ts.map} +1 -1
- package/dist/index.d.ts +244 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +305 -37
- package/dist/index.js.map +1 -1
- package/dist/make-ph-event-functions-C1JTfEw1.js +251 -0
- package/dist/make-ph-event-functions-C1JTfEw1.js.map +1 -0
- package/dist/navigation-B4fHR-Tm.js +315 -0
- package/dist/navigation-B4fHR-Tm.js.map +1 -0
- package/dist/{relational-DxHuX41f.js → relational-DZuyKp2y.js} +2 -2
- package/dist/{relational-DxHuX41f.js.map → relational-DZuyKp2y.js.map} +1 -1
- package/dist/{renown-D05wkobG.js → renown-CGQYQsvH.js} +2 -2
- package/dist/{renown-D05wkobG.js.map → renown-CGQYQsvH.js.map} +1 -1
- package/dist/{renown-CPAeJt5L.js → renown-DlkS61Dp.js} +28 -22
- package/dist/{renown-CPAeJt5L.js.map → renown-DlkS61Dp.js.map} +1 -1
- package/dist/src/ai/index.d.ts.map +1 -1
- package/dist/src/ai/index.js +3 -3
- package/dist/src/analytics/index.js +3 -3
- package/dist/src/graphql-client/entry.d.ts +2 -2
- package/dist/src/graphql-client/entry.js +3 -3
- package/dist/src/relational/index.js +1 -1
- package/dist/src/renown/index.d.ts +1 -1
- package/dist/src/renown/index.js +2 -2
- package/dist/src/rpc/index.d.ts +3 -1
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +1 -3
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/{switchboard-3vHbIV5W.js → switchboard-DAvOdf_g.js} +8 -6
- package/dist/switchboard-DAvOdf_g.js.map +1 -0
- package/package.json +10 -10
- package/dist/client-Cq5avLW5.js.map +0 -1
- package/dist/dispatch-C1VVTn5S.js.map +0 -1
- package/dist/document-model-modules-Gsh1Xr7j.js.map +0 -1
- package/dist/document-operations-BSzcF0mu.js.map +0 -1
- package/dist/global-BuSwbbY0.d.ts.map +0 -1
- package/dist/make-ph-event-functions-CdsvEl5t.js +0 -55
- package/dist/make-ph-event-functions-CdsvEl5t.js.map +0 -1
- package/dist/switchboard-3vHbIV5W.js.map +0 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
4
|
-
import { useSyncExternalStore } from "react";
|
|
5
|
-
import slug from "slug";
|
|
1
|
+
import { f as isScopedPHStore, g as warnGlobalSetterInScope, h as usePHStore, n as subscribeToPHValue, t as makePHEventFunctions, u as getPHStore } from "./make-ph-event-functions-C1JTfEw1.js";
|
|
2
|
+
import { _ as isDuplicateManifestError, t as useDispatch, v as isDuplicateModuleError } from "./dispatch-BmdzdTwb.js";
|
|
3
|
+
import { A as extractNodeIdFromSlug, I as makeDriveSlug, N as findDriveBySlug, O as extractDriveSlugFromPath, R as makeNodeSlug, c as getCurrentPathname, f as hasHostNavigation, g as openTargetWith, h as openTarget, j as extractNodeSlugFromPath, v as preloadTarget } from "./navigation-B4fHR-Tm.js";
|
|
4
|
+
import { useCallback, useSyncExternalStore } from "react";
|
|
6
5
|
//#region src/graphql-client/auth.ts
|
|
7
6
|
/** Lifetime requested for an ambient Renown token, in seconds. */
|
|
8
7
|
const ambientTokenExpiresInSeconds = 600;
|
|
@@ -18,7 +17,7 @@ const ambientTokenExpiresInSeconds = 600;
|
|
|
18
17
|
*/
|
|
19
18
|
async function ambientRenownTokenProvider() {
|
|
20
19
|
if (typeof window === "undefined") return;
|
|
21
|
-
const renown =
|
|
20
|
+
const renown = getPHStore()?.renown;
|
|
22
21
|
if (!renown?.user) return;
|
|
23
22
|
return renown.getBearerToken({ expiresIn: ambientTokenExpiresInSeconds });
|
|
24
23
|
}
|
|
@@ -69,77 +68,28 @@ var NoSelectedDocumentError = class extends Error {
|
|
|
69
68
|
}
|
|
70
69
|
};
|
|
71
70
|
//#endregion
|
|
72
|
-
//#region src/
|
|
73
|
-
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return path.replace(basePath, basePath.endsWith("/") ? "/" : "");
|
|
81
|
-
}
|
|
82
|
-
/** Makes a URL component for a drive. */
|
|
83
|
-
function makeDriveUrlComponent(drive) {
|
|
84
|
-
if (!drive) return "";
|
|
85
|
-
return `/d/${slug(drive.header.slug)}`;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Makes a URL component for a node: `<slugged name>-<id>`. The id is kept
|
|
89
|
-
* verbatim, since a v2-required id is case-sensitive base64url.
|
|
90
|
-
*/
|
|
91
|
-
function makeNodeSlug(node) {
|
|
92
|
-
if (!node) return "";
|
|
93
|
-
const nameSlug = node.name ? slug(node.name) : "";
|
|
94
|
-
return nameSlug ? `${nameSlug}-${node.id}` : node.id;
|
|
95
|
-
}
|
|
96
|
-
/** Extracts the node slug from a path.
|
|
97
|
-
*
|
|
98
|
-
* The path is expected to be in the format `/d/<drive-slug>/<node-slug>`.
|
|
99
|
-
*/
|
|
100
|
-
function extractNodeSlugFromPath(path) {
|
|
101
|
-
const currentPath = getPathWithoutBase(path);
|
|
102
|
-
return /^\/d\/[^/]+\/([^/]+)$/.exec(currentPath)?.[1];
|
|
103
|
-
}
|
|
104
|
-
/** Finds a UUID in a string, used for extracting node ids from node slugs in the URL. */
|
|
105
|
-
function findUuid(input) {
|
|
106
|
-
if (!input) return void 0;
|
|
107
|
-
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];
|
|
108
|
-
}
|
|
109
|
-
/** The v2-required document id a slug ends with, if any. */
|
|
110
|
-
function findDerivedId(input) {
|
|
111
|
-
if (!input || input.length < DERIVED_ID_LENGTH) return void 0;
|
|
112
|
-
const start = input.length - DERIVED_ID_LENGTH;
|
|
113
|
-
if (start > 0 && input[start - 1] !== "-") return void 0;
|
|
114
|
-
const candidate = input.slice(start);
|
|
115
|
-
return isDerivedDocumentId(candidate) ? candidate : void 0;
|
|
116
|
-
}
|
|
117
|
-
function extractNodeIdFromSlug(nodeSlug) {
|
|
118
|
-
return findUuid(nodeSlug) ?? findDerivedId(nodeSlug);
|
|
119
|
-
}
|
|
120
|
-
function extractNodeIdFromPath(path) {
|
|
121
|
-
return extractNodeIdFromSlug(extractNodeSlugFromPath(path));
|
|
122
|
-
}
|
|
123
|
-
/** Extracts the drive slug from a path.
|
|
124
|
-
* Used for extracting drive ids from drive slugs in the URL.
|
|
125
|
-
* Expects the path to be in the format `/d/<drive-slug>`.
|
|
126
|
-
*/
|
|
127
|
-
function extractDriveSlugFromPath(path) {
|
|
128
|
-
const currentPath = getPathWithoutBase(path);
|
|
129
|
-
return /^\/d\/([^/]+)/.exec(currentPath)?.[1] ?? "";
|
|
130
|
-
}
|
|
131
|
-
function extractDriveIdFromSlug(driveSlug) {
|
|
132
|
-
return findUuid(driveSlug) ?? findDerivedId(driveSlug);
|
|
71
|
+
//#region src/routing/initial-sync.ts
|
|
72
|
+
/** The store's sync remotes; none before the reactor is ready. */
|
|
73
|
+
function listSyncRemotes(store) {
|
|
74
|
+
try {
|
|
75
|
+
return store?.reactorClientModule?.reactorModule?.syncModule?.syncManager?.list() ?? [];
|
|
76
|
+
} catch {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
133
79
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
80
|
+
function isFirstPullInFlight(remote) {
|
|
81
|
+
try {
|
|
82
|
+
const { state, receivingPages, lastSuccessUtcMs, failureCount } = remote.channel.getConnectionState();
|
|
83
|
+
if (state === "connected") return receivingPages;
|
|
84
|
+
if (state === "reconnecting") return !lastSuccessUtcMs && !failureCount;
|
|
85
|
+
return state === "connecting" && (receivingPages || !lastSuccessUtcMs);
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
136
89
|
}
|
|
137
|
-
/**
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
function createUrlWithPreservedParams(pathname) {
|
|
141
|
-
const search = window.location.search;
|
|
142
|
-
return search ? `${pathname}${search}` : pathname;
|
|
90
|
+
/** Whether a remote, or one syncing `driveId` when given, is in its first pull. */
|
|
91
|
+
function isInitialSyncInFlight(store, driveId) {
|
|
92
|
+
return listSyncRemotes(store).some((remote) => (driveId === void 0 || remote.meta.collectionId.driveId === driveId) && isFirstPullInFlight(remote));
|
|
143
93
|
}
|
|
144
94
|
//#endregion
|
|
145
95
|
//#region src/hooks/drives.ts
|
|
@@ -154,37 +104,109 @@ const addDrivesEventHandler = drivesEventFunctions.addEventHandler;
|
|
|
154
104
|
//#region src/hooks/set-selected-node.ts
|
|
155
105
|
const selectedNodeIdEventFunctions = makePHEventFunctions("selectedNodeId");
|
|
156
106
|
const useSelectedNodeId = selectedNodeIdEventFunctions.useValue;
|
|
107
|
+
/** Sets the selected node id without touching the URL. */
|
|
157
108
|
const setSelectedNodeId = selectedNodeIdEventFunctions.setValue;
|
|
109
|
+
/** @deprecated `ph:setSelectedNodeId` bypasses the URL; use `setSelectedNode`. */
|
|
158
110
|
const addSelectedNodeIdEventHandler = selectedNodeIdEventFunctions.addEventHandler;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
111
|
+
function decodeSlug(slug) {
|
|
112
|
+
try {
|
|
113
|
+
return decodeURIComponent(slug);
|
|
114
|
+
} catch {
|
|
115
|
+
return slug;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function openDriveSlug(store, pathname) {
|
|
119
|
+
const selected = store?.drives?.find((d) => d.header.id === store.selectedDriveId);
|
|
120
|
+
if (selected) return makeDriveSlug(selected);
|
|
121
|
+
const driveSlug = extractDriveSlugFromPath(pathname);
|
|
122
|
+
return driveSlug ? decodeSlug(driveSlug) : void 0;
|
|
123
|
+
}
|
|
124
|
+
function nodeTarget(nodeSlug) {
|
|
125
|
+
const driveSlug = openDriveSlug(getPHStore(), getCurrentPathname());
|
|
126
|
+
if (!driveSlug) return void 0;
|
|
127
|
+
return {
|
|
128
|
+
driveSlug,
|
|
129
|
+
nodeSlug: nodeSlug || void 0
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const toSlug = (node) => typeof node === "string" ? node : makeNodeSlug(node);
|
|
133
|
+
function scopedNodeTarget(store, nodeSlug) {
|
|
134
|
+
const driveSlug = openDriveSlug(store, store.navigation?.location().pathname ?? "");
|
|
135
|
+
if (!driveSlug) return void 0;
|
|
136
|
+
return {
|
|
137
|
+
driveSlug,
|
|
138
|
+
nodeSlug: nodeSlug || void 0
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Selects a node in the app's store, without the scope warning. */
|
|
142
|
+
function selectNode(node, options) {
|
|
143
|
+
const nodeSlug = toSlug(node);
|
|
144
|
+
if (!hasHostNavigation()) setSelectedNodeId(extractNodeIdFromSlug(nodeSlug));
|
|
145
|
+
const target = nodeTarget(nodeSlug);
|
|
146
|
+
if (target) openTarget(target, options);
|
|
147
|
+
}
|
|
148
|
+
/** Selects a node in `store`: a scope's own selection, else the app's. */
|
|
149
|
+
function selectNodeIn(store, node, options) {
|
|
150
|
+
if (!store || !isScopedPHStore(store)) {
|
|
151
|
+
selectNode(node, options);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const nodeSlug = toSlug(node);
|
|
155
|
+
const navigation = store.navigation;
|
|
156
|
+
if (!navigation) {
|
|
157
|
+
store.selectedNodeId = typeof node === "object" ? node.id : extractNodeIdFromSlug(nodeSlug);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const target = scopedNodeTarget(store, nodeSlug);
|
|
161
|
+
if (target) openTargetWith(navigation, target, options);
|
|
162
|
+
}
|
|
163
|
+
/** Sets the selected node (file or folder) of the app's store; `search` sets
|
|
164
|
+
* the params it opens with. Inside a scoped store, use `useSetSelectedNode`. */
|
|
165
|
+
function setSelectedNode(node, options) {
|
|
166
|
+
warnGlobalSetterInScope("setSelectedNode", "useSetSelectedNode");
|
|
167
|
+
selectNode(node, options);
|
|
168
|
+
}
|
|
169
|
+
/** `setSelectedNode` for the store in context, e.g. a scoped editor's. */
|
|
170
|
+
function useSetSelectedNode() {
|
|
171
|
+
const store = usePHStore();
|
|
172
|
+
return useCallback((node, options) => selectNodeIn(store, node, options), [store]);
|
|
173
|
+
}
|
|
174
|
+
/** Opens a node, or with `undefined` its drive, in the store in context. */
|
|
175
|
+
const useOpenNode = useSetSelectedNode;
|
|
176
|
+
/** Where a node of `store`'s open drive navigates to. */
|
|
177
|
+
function getNodeTargetIn(store, node) {
|
|
178
|
+
const nodeSlug = makeNodeSlug(node);
|
|
179
|
+
return store && isScopedPHStore(store) ? scopedNodeTarget(store, nodeSlug) : nodeTarget(nodeSlug);
|
|
180
|
+
}
|
|
181
|
+
/** Where a node of the open drive navigates to. */
|
|
182
|
+
function getNodeTarget(node) {
|
|
183
|
+
return nodeTarget(makeNodeSlug(node));
|
|
184
|
+
}
|
|
185
|
+
function preloadNodeIn(store, node) {
|
|
186
|
+
if (!node) return;
|
|
187
|
+
if (!store || !isScopedPHStore(store)) {
|
|
188
|
+
const target = nodeTarget(makeNodeSlug(node));
|
|
189
|
+
if (target) preloadTarget(target);
|
|
170
190
|
return;
|
|
171
191
|
}
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
|
|
192
|
+
const target = scopedNodeTarget(store, makeNodeSlug(node));
|
|
193
|
+
if (target) store.navigation?.preload?.(target);
|
|
194
|
+
}
|
|
195
|
+
/** Warms a node's view before it is opened, e.g. on hover. */
|
|
196
|
+
function preloadNode(node) {
|
|
197
|
+
warnGlobalSetterInScope("preloadNode", "usePreloadNode");
|
|
198
|
+
preloadNodeIn(void 0, node);
|
|
199
|
+
}
|
|
200
|
+
/** `preloadNode` for the store in context. */
|
|
201
|
+
function usePreloadNode() {
|
|
202
|
+
const store = usePHStore();
|
|
203
|
+
return useCallback((node) => preloadNodeIn(store, node), [store]);
|
|
175
204
|
}
|
|
176
205
|
function addResetSelectedNodeEventHandler() {
|
|
177
|
-
|
|
206
|
+
subscribeToPHValue("selectedDriveId", () => {
|
|
178
207
|
setSelectedNodeId(void 0);
|
|
179
208
|
});
|
|
180
209
|
}
|
|
181
|
-
function addSetSelectedNodeOnPopStateEventHandler() {
|
|
182
|
-
window.addEventListener("popstate", () => {
|
|
183
|
-
const pathname = window.location.pathname;
|
|
184
|
-
const nodeSlug = extractNodeSlugFromPath(pathname);
|
|
185
|
-
if (extractNodeIdFromSlug(nodeSlug) !== window.ph?.selectedNodeId) setSelectedNode(nodeSlug);
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
210
|
//#endregion
|
|
189
211
|
//#region src/hooks/selected-drive.ts
|
|
190
212
|
const selectedDriveIdEventFunctions = makePHEventFunctions("selectedDriveId");
|
|
@@ -192,7 +214,8 @@ const selectedDriveIdEventFunctions = makePHEventFunctions("selectedDriveId");
|
|
|
192
214
|
const useSelectedDriveId = selectedDriveIdEventFunctions.useValue;
|
|
193
215
|
/** Sets the selected drive id */
|
|
194
216
|
const setSelectedDriveId = selectedDriveIdEventFunctions.setValue;
|
|
195
|
-
/** Adds an event handler for the selected drive id
|
|
217
|
+
/** Adds an event handler for the selected drive id
|
|
218
|
+
* @deprecated `ph:setSelectedDriveId` bypasses the URL; use `setSelectedDrive`. */
|
|
196
219
|
const addSelectedDriveIdEventHandler = selectedDriveIdEventFunctions.addEventHandler;
|
|
197
220
|
/** Returns the selected drive */
|
|
198
221
|
function useSelectedDrive() {
|
|
@@ -208,47 +231,75 @@ function useSelectedDriveSafe() {
|
|
|
208
231
|
if (!selectedDrive) return [void 0, void 0];
|
|
209
232
|
return [drive, dispatch];
|
|
210
233
|
}
|
|
234
|
+
/** Selects a drive in the app's store; inside a scoped store, use
|
|
235
|
+
* `useSetSelectedDrive`. */
|
|
211
236
|
function setSelectedDrive(driveOrDriveSlug) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
237
|
+
warnGlobalSetterInScope("setSelectedDrive", "useSetSelectedDrive");
|
|
238
|
+
selectDrive(driveOrDriveSlug);
|
|
239
|
+
}
|
|
240
|
+
/** Selects a drive in `store`: a scope's own selection, else the app's. */
|
|
241
|
+
function selectDriveIn(store, driveOrDriveSlug) {
|
|
242
|
+
if (!store || !isScopedPHStore(store)) {
|
|
243
|
+
selectDrive(driveOrDriveSlug);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const driveSlug = typeof driveOrDriveSlug === "string" ? driveOrDriveSlug : driveOrDriveSlug && makeDriveSlug(driveOrDriveSlug);
|
|
247
|
+
if (store.navigation) {
|
|
248
|
+
openTargetWith(store.navigation, driveSlug ? { driveSlug } : void 0);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
store.selectedDriveId = (typeof driveOrDriveSlug === "object" ? driveOrDriveSlug : findDriveBySlug(store.drives, driveSlug))?.header.id;
|
|
252
|
+
store.selectedNodeId = void 0;
|
|
253
|
+
}
|
|
254
|
+
/** `setSelectedDrive` for the store in context, e.g. a scoped editor's. */
|
|
255
|
+
function useSetSelectedDrive() {
|
|
256
|
+
const store = usePHStore();
|
|
257
|
+
return useCallback((drive) => selectDriveIn(store, drive), [store]);
|
|
258
|
+
}
|
|
259
|
+
/** Selects a drive in the app's store, without the scope warning. */
|
|
260
|
+
function selectDrive(driveOrDriveSlug) {
|
|
261
|
+
const driveSlug = typeof driveOrDriveSlug === "string" ? driveOrDriveSlug : driveOrDriveSlug && makeDriveSlug(driveOrDriveSlug);
|
|
262
|
+
if (hasHostNavigation()) {
|
|
263
|
+
cancelPendingDriveSelection();
|
|
264
|
+
openTarget(driveSlug ? { driveSlug } : void 0);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const drives = getPHStore()?.drives;
|
|
268
|
+
const driveId = (typeof driveOrDriveSlug === "object" && driveOrDriveSlug !== null ? driveOrDriveSlug : findDriveBySlug(drives, driveSlug))?.header.id;
|
|
269
|
+
if (!driveId && driveSlug && extractDriveSlugFromPath(getCurrentPathname()) === driveSlug) {
|
|
270
|
+
if (getPHStore()?.selectedDriveId) setSelectedDriveId(void 0);
|
|
217
271
|
deferDriveSelection(driveSlug);
|
|
218
272
|
return;
|
|
219
273
|
}
|
|
220
274
|
cancelPendingDriveSelection();
|
|
221
275
|
setSelectedDriveId(driveId);
|
|
222
|
-
|
|
223
|
-
const pathname = resolveUrlPathname("/");
|
|
224
|
-
if (pathname === window.location.pathname) return;
|
|
225
|
-
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const pathname = resolveUrlPathname(`/d/${driveSlug}`);
|
|
229
|
-
if (pathname === window.location.pathname) return;
|
|
230
|
-
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
276
|
+
openTarget(driveId && driveSlug ? { driveSlug } : void 0);
|
|
231
277
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
278
|
+
/** Warms a drive's view before it is opened, e.g. on hover. */
|
|
279
|
+
function preloadDrive(drive) {
|
|
280
|
+
warnGlobalSetterInScope("preloadDrive", "usePreloadDrive");
|
|
281
|
+
if (drive) preloadTarget({ driveSlug: makeDriveSlug(drive) });
|
|
282
|
+
}
|
|
283
|
+
/** `preloadDrive` for the store in context. */
|
|
284
|
+
function usePreloadDrive() {
|
|
285
|
+
const store = usePHStore();
|
|
286
|
+
return useCallback((drive) => {
|
|
287
|
+
if (!drive) return;
|
|
288
|
+
if (!isScopedPHStore(store)) {
|
|
289
|
+
preloadTarget({ driveSlug: makeDriveSlug(drive) });
|
|
290
|
+
return;
|
|
243
291
|
}
|
|
244
|
-
|
|
292
|
+
store?.navigation?.preload?.({ driveSlug: makeDriveSlug(drive) });
|
|
293
|
+
}, [store]);
|
|
245
294
|
}
|
|
246
|
-
|
|
295
|
+
const DEFERRED_DRIVE_TICK_MS = 2e3;
|
|
296
|
+
const DEFERRED_DRIVE_MAX_WAIT_MS = 15e3;
|
|
297
|
+
let unsubscribePending;
|
|
247
298
|
let pendingTimeout;
|
|
248
299
|
function cancelPendingDriveSelection() {
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
300
|
+
if (unsubscribePending) {
|
|
301
|
+
unsubscribePending();
|
|
302
|
+
unsubscribePending = void 0;
|
|
252
303
|
}
|
|
253
304
|
if (pendingTimeout) {
|
|
254
305
|
clearTimeout(pendingTimeout);
|
|
@@ -257,44 +308,27 @@ function cancelPendingDriveSelection() {
|
|
|
257
308
|
}
|
|
258
309
|
function deferDriveSelection(driveSlug) {
|
|
259
310
|
cancelPendingDriveSelection();
|
|
260
|
-
const nodeSlug = extractNodeSlugFromPath(
|
|
311
|
+
const nodeSlug = extractNodeSlugFromPath(getCurrentPathname());
|
|
261
312
|
const handler = () => {
|
|
262
|
-
if (!
|
|
313
|
+
if (!findDriveBySlug(getPHStore()?.drives, driveSlug)) return;
|
|
263
314
|
cancelPendingDriveSelection();
|
|
264
|
-
|
|
265
|
-
|
|
315
|
+
selectDrive(driveSlug);
|
|
316
|
+
selectNode(nodeSlug);
|
|
266
317
|
};
|
|
267
|
-
|
|
268
|
-
window.addEventListener("ph:drivesUpdated", handler);
|
|
318
|
+
unsubscribePending = subscribeToPHValue("drives", handler);
|
|
269
319
|
const deadline = Date.now() + DEFERRED_DRIVE_MAX_WAIT_MS;
|
|
270
320
|
const scheduleTick = () => {
|
|
271
321
|
pendingTimeout = setTimeout(() => {
|
|
272
|
-
if (Date.now() < deadline && isInitialSyncInFlight()) {
|
|
322
|
+
if (Date.now() < deadline && isInitialSyncInFlight(getPHStore())) {
|
|
273
323
|
scheduleTick();
|
|
274
324
|
return;
|
|
275
325
|
}
|
|
276
326
|
cancelPendingDriveSelection();
|
|
277
|
-
|
|
278
|
-
if (pathname === window.location.pathname) return;
|
|
279
|
-
window.history.pushState(null, "", createUrlWithPreservedParams(pathname));
|
|
327
|
+
openTarget(void 0);
|
|
280
328
|
}, DEFERRED_DRIVE_TICK_MS);
|
|
281
329
|
};
|
|
282
330
|
scheduleTick();
|
|
283
331
|
}
|
|
284
|
-
function addSetSelectedDriveOnPopStateEventHandler() {
|
|
285
|
-
window.addEventListener("popstate", () => {
|
|
286
|
-
const driveSlug = extractDriveSlugFromPath(window.location.pathname);
|
|
287
|
-
const drives = window.ph?.drives ?? [];
|
|
288
|
-
const selectedId = window.ph?.selectedDriveId;
|
|
289
|
-
const selected = drives.find((drive) => drive.header.id === selectedId);
|
|
290
|
-
if (selectedId && !selected) {
|
|
291
|
-
const named = drives.some((drive) => makeDriveUrlComponent(drive) === `/d/${driveSlug}`);
|
|
292
|
-
if (driveSlug && !named) return;
|
|
293
|
-
}
|
|
294
|
-
const selectedUrl = makeDriveUrlComponent(selected);
|
|
295
|
-
if (`/d/${driveSlug}` !== selectedUrl && (driveSlug || selectedId)) setSelectedDrive(driveSlug || void 0);
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
332
|
//#endregion
|
|
299
333
|
//#region src/hooks/vetra-packages.ts
|
|
300
334
|
const vetraPackageManagerFunctions = makePHEventFunctions("vetraPackageManager");
|
|
@@ -310,7 +344,8 @@ const noPackageManagerUnsubscribe = () => {};
|
|
|
310
344
|
*/
|
|
311
345
|
const useVetraPackages = () => {
|
|
312
346
|
const packageManager = useVetraPackageManager();
|
|
313
|
-
|
|
347
|
+
const getPackages = () => packageManager?.packages ?? EMPTY_VETRA_PACKAGES;
|
|
348
|
+
return useSyncExternalStore((cb) => packageManager ? packageManager.subscribe(cb) : noPackageManagerUnsubscribe, getPackages, getPackages);
|
|
314
349
|
};
|
|
315
350
|
/** Adds the Vetra package manager event handler */
|
|
316
351
|
const addVetraPackageManagerEventHandler = vetraPackageManagerFunctions.addEventHandler;
|
|
@@ -344,7 +379,7 @@ function setVetraPackageManager(packageManager) {
|
|
|
344
379
|
}
|
|
345
380
|
function updateReactorClientDocumentModels(packages) {
|
|
346
381
|
const documentModelModules = packages.flatMap((pkg) => pkg.documentModels).filter((module, index, modules) => modules.findIndex((m) => m.documentModel.global.id === module.documentModel.global.id && (m.version ?? 1) === (module.version ?? 1)) === index);
|
|
347
|
-
const registry =
|
|
382
|
+
const registry = getPHStore()?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
348
383
|
if (!registry || documentModelModules.length === 0) return;
|
|
349
384
|
const results = registry.registerModules(...documentModelModules);
|
|
350
385
|
const duplicateTypes = /* @__PURE__ */ new Set();
|
|
@@ -359,7 +394,7 @@ function updateReactorClientDocumentModels(packages) {
|
|
|
359
394
|
}
|
|
360
395
|
function updateReactorClientUpgradeManifests(packages) {
|
|
361
396
|
const upgradeManifests = packages.flatMap((pkg) => pkg.upgradeManifests).filter((u) => u !== void 0);
|
|
362
|
-
const registry =
|
|
397
|
+
const registry = getPHStore()?.reactorClientModule?.reactorModule?.documentModelRegistry;
|
|
363
398
|
if (!registry || upgradeManifests.length === 0) return;
|
|
364
399
|
const results = registry.registerUpgradeManifests(...upgradeManifests);
|
|
365
400
|
const duplicates = [];
|
|
@@ -406,6 +441,6 @@ function useDocumentModelModuleById(id, version) {
|
|
|
406
441
|
return latestModule;
|
|
407
442
|
}
|
|
408
443
|
//#endregion
|
|
409
|
-
export {
|
|
444
|
+
export { useSetSelectedNode as A, ambientRenownTokenProvider as B, selectNode as C, useOpenNode as D, setSelectedNodeId as E, listSyncRemotes as F, DocumentModelNotFoundError as I, DocumentTypeMismatchError as L, setDrives as M, useDrives as N, usePreloadNode as O, isInitialSyncInFlight as P, NoSelectedDocumentError as R, preloadNode as S, setSelectedNode as T, makeAuthMiddleware as V, useSetSelectedDrive as _, setVetraPackageManager as a, getNodeTarget as b, addSelectedDriveIdEventHandler as c, setSelectedDrive as d, setSelectedDriveId as f, useSelectedDriveSafe as g, useSelectedDriveId as h, onVetraPackageManager as i, addDrivesEventHandler as j, useSelectedNodeId as k, preloadDrive as l, useSelectedDrive as m, useDocumentModelModules as n, useVetraPackageManager as o, usePreloadDrive as p, addVetraPackageManagerEventHandler as r, useVetraPackages as s, useDocumentModelModuleById as t, selectDrive as u, addResetSelectedNodeEventHandler as v, selectNodeIn as w, getNodeTargetIn as x, addSelectedNodeIdEventHandler as y, UnsupportedDocumentTypeError as z };
|
|
410
445
|
|
|
411
|
-
//# sourceMappingURL=document-model-modules-
|
|
446
|
+
//# sourceMappingURL=document-model-modules-Wjh92XAb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-model-modules-Wjh92XAb.js","names":[],"sources":["../src/graphql-client/auth.ts","../src/errors.ts","../src/routing/initial-sync.ts","../src/hooks/drives.ts","../src/hooks/set-selected-node.ts","../src/hooks/selected-drive.ts","../src/hooks/vetra-packages.ts","../src/hooks/document-model-modules.ts"],"sourcesContent":["import { getPHStore } from \"../hooks/ph-store.js\";\nimport type { SdkFunctionWrapper } from \"../graphql/gen/schema.js\";\n\n/**\n * Resolves the bearer token to send with a request.\n *\n * Returning `undefined` (or an empty string) means \"send this request\n * anonymously\": open Switchboards must keep serving reads to logged-out users.\n */\nexport type BearerTokenProvider = () => Promise<string | undefined>;\n\n/** Lifetime requested for an ambient Renown token, in seconds. */\nconst ambientTokenExpiresInSeconds = 600;\n\n/**\n * The default token provider: the token of the currently logged-in Renown user.\n *\n * It is deliberately resolved from `window.ph` on every call rather than\n * captured at construction time, so a client built before login starts sending\n * the token as soon as there is one.\n *\n * The token is requested WITHOUT an `aud` claim - the Switchboard verifier\n * rejects tokens that carry an audience.\n */\nexport async function ambientRenownTokenProvider(): Promise<\n string | undefined\n> {\n if (typeof window === \"undefined\") {\n return undefined;\n }\n\n const renown = getPHStore()?.renown;\n if (!renown?.user) {\n return undefined;\n }\n\n return renown.getBearerToken({ expiresIn: ambientTokenExpiresInSeconds });\n}\n\n/**\n * Builds the SDK middleware that authenticates every request.\n *\n * The token is resolved per request and never cached, so a login, a logout or\n * an expiry between two calls is picked up by the next one. When no token is\n * available the request goes out unauthenticated.\n */\nexport function makeAuthMiddleware(\n tokenProvider: BearerTokenProvider,\n): SdkFunctionWrapper {\n return async (action) => {\n const token = await tokenProvider();\n if (!token) {\n return action();\n }\n\n return action({ authorization: `Bearer ${token}` });\n };\n}\n","export class UnsupportedDocumentTypeError extends Error {\n constructor(documentType: string) {\n super(`Document type ${documentType} is not supported`);\n this.name = \"UnsupportedDocumentTypeError\";\n }\n\n static isError(error: unknown): error is UnsupportedDocumentTypeError {\n return (\n Error.isError(error) && error.name === \"UnsupportedDocumentTypeError\"\n );\n }\n}\n\nexport class DocumentModelNotFoundError extends Error {\n readonly documentType: string;\n readonly name = \"DocumentModelNotFoundError\";\n\n constructor(documentType: string) {\n super(`Document model module for type ${documentType} not found`);\n this.documentType = documentType;\n }\n\n static isError(error: unknown): error is DocumentModelNotFoundError {\n return Error.isError(error) && error.name === \"DocumentModelNotFoundError\";\n }\n}\n\nexport class DocumentTypeMismatchError extends Error {\n constructor(documentId: string, expectedType: string, actualType: string) {\n super(\n `Document ${documentId} is not of type ${expectedType}. Actual type: ${actualType}`,\n );\n }\n}\n\nexport class NoSelectedDocumentError extends Error {\n constructor() {\n super(\n \"There is no selected document. Did you mean to call 'useSelectedDocumentSafe' instead?\",\n );\n }\n}\n","import type { Remote } from \"@powerhousedao/reactor\";\nimport type { PHStore } from \"../hooks/ph-store.js\";\n\n/** The store's sync remotes; none before the reactor is ready. */\nexport function listSyncRemotes(store: PHStore | undefined): Remote[] {\n try {\n return (\n store?.reactorClientModule?.reactorModule?.syncModule?.syncManager?.list() ??\n []\n );\n } catch {\n return [];\n }\n}\n\n// Only a first pull in flight may still bring drives. A connected remote that\n// never polled is paused or answer-only; one failed or failing to reconnect won't soon.\nfunction isFirstPullInFlight(remote: Remote) {\n try {\n const { state, receivingPages, lastSuccessUtcMs, failureCount } =\n remote.channel.getConnectionState();\n if (state === \"connected\") return receivingPages;\n if (state === \"reconnecting\") return !lastSuccessUtcMs && !failureCount;\n return state === \"connecting\" && (receivingPages || !lastSuccessUtcMs);\n } catch {\n return false;\n }\n}\n\n/** Whether a remote, or one syncing `driveId` when given, is in its first pull. */\nexport function isInitialSyncInFlight(\n store: PHStore | undefined,\n driveId?: string,\n) {\n return listSyncRemotes(store).some(\n (remote) =>\n (driveId === undefined || remote.meta.collectionId.driveId === driveId) &&\n isFirstPullInFlight(remote),\n );\n}\n","import type { DocumentDriveDocument } from \"@powerhousedao/shared/document-drive\";\nimport type { SetPHGlobalValue, UsePHGlobalValue } from \"../types/global.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nconst drivesEventFunctions = makePHEventFunctions(\"drives\");\n\n/** Returns all of the drives in the reactor */\nexport const useDrives: UsePHGlobalValue<DocumentDriveDocument[]> =\n drivesEventFunctions.useValue;\n\n/** Sets the drives in the reactor */\nexport const setDrives: SetPHGlobalValue<DocumentDriveDocument[]> =\n drivesEventFunctions.setValue;\n\n/** Adds an event handler for the drives */\nexport const addDrivesEventHandler = drivesEventFunctions.addEventHandler;\n","import type {\n PHNavigateOptions,\n PHNavigationTarget,\n} from \"@powerhousedao/reactor-browser\";\nimport type { Node } from \"@powerhousedao/shared/document-drive\";\nimport {\n extractDriveSlugFromPath,\n extractNodeIdFromSlug,\n makeDriveSlug,\n makeNodeSlug,\n} from \"../utils/url.js\";\nimport {\n makePHEventFunctions,\n subscribeToPHValue,\n} from \"./make-ph-event-functions.js\";\nimport { useCallback } from \"react\";\nimport {\n getCurrentPathname,\n hasHostNavigation,\n openTarget,\n openTargetWith,\n preloadTarget,\n} from \"./navigation.js\";\nimport type { PHStore } from \"./ph-store.js\";\nimport {\n getPHStore,\n isScopedPHStore,\n usePHStore,\n warnGlobalSetterInScope,\n} from \"./ph-store.js\";\n\nconst selectedNodeIdEventFunctions = makePHEventFunctions(\"selectedNodeId\");\nexport const useSelectedNodeId = selectedNodeIdEventFunctions.useValue;\n/** Sets the selected node id without touching the URL. */\nexport const setSelectedNodeId = selectedNodeIdEventFunctions.setValue;\n/** @deprecated `ph:setSelectedNodeId` bypasses the URL; use `setSelectedNode`. */\nexport const addSelectedNodeIdEventHandler =\n selectedNodeIdEventFunctions.addEventHandler;\n\nfunction decodeSlug(slug: string) {\n try {\n return decodeURIComponent(slug);\n } catch {\n return slug;\n }\n}\n\n// The selected drive's slug, else the path's: a pending navigation's path\n// already names its destination, not the drive still shown.\nfunction openDriveSlug(store: PHStore | undefined, pathname: string) {\n const selected = store?.drives?.find(\n (d) => d.header.id === store.selectedDriveId,\n );\n if (selected) return makeDriveSlug(selected);\n const driveSlug = extractDriveSlugFromPath(pathname);\n return driveSlug ? decodeSlug(driveSlug) : undefined;\n}\n\n// The node in the app's open drive.\nfunction nodeTarget(nodeSlug: string): PHNavigationTarget | undefined {\n const driveSlug = openDriveSlug(getPHStore(), getCurrentPathname());\n if (!driveSlug) return undefined;\n return { driveSlug, nodeSlug: nodeSlug || undefined };\n}\n\ntype NodeRef = Node | string | undefined;\n\nconst toSlug = (node: NodeRef) =>\n typeof node === \"string\" ? node : makeNodeSlug(node);\n\n// The node in a scope's open drive.\nfunction scopedNodeTarget(store: PHStore, nodeSlug: string) {\n const pathname = store.navigation?.location().pathname ?? \"\";\n const driveSlug = openDriveSlug(store, pathname);\n if (!driveSlug) return undefined;\n return { driveSlug, nodeSlug: nodeSlug || undefined };\n}\n\n/** Selects a node in the app's store, without the scope warning. */\nexport function selectNode(node: NodeRef, options?: PHNavigateOptions) {\n const nodeSlug = toSlug(node);\n // A host router resolves the node and writes the selection itself.\n if (!hasHostNavigation()) {\n setSelectedNodeId(extractNodeIdFromSlug(nodeSlug));\n }\n const target = nodeTarget(nodeSlug);\n if (target) openTarget(target, options);\n}\n\n/** Selects a node in `store`: a scope's own selection, else the app's. */\nexport function selectNodeIn(\n store: PHStore | undefined,\n node: NodeRef,\n options?: PHNavigateOptions,\n) {\n if (!store || !isScopedPHStore(store)) {\n selectNode(node, options);\n return;\n }\n const nodeSlug = toSlug(node);\n const navigation = store.navigation;\n if (!navigation) {\n store.selectedNodeId =\n typeof node === \"object\" ? node.id : extractNodeIdFromSlug(nodeSlug);\n return;\n }\n const target = scopedNodeTarget(store, nodeSlug);\n if (target) openTargetWith(navigation, target, options);\n}\n\n/** Sets the selected node (file or folder) of the app's store; `search` sets\n * the params it opens with. Inside a scoped store, use `useSetSelectedNode`. */\nexport function setSelectedNode(node: NodeRef, options?: PHNavigateOptions) {\n warnGlobalSetterInScope(\"setSelectedNode\", \"useSetSelectedNode\");\n selectNode(node, options);\n}\n\n/** `setSelectedNode` for the store in context, e.g. a scoped editor's. */\nexport function useSetSelectedNode() {\n const store = usePHStore();\n return useCallback(\n (node: NodeRef, options?: PHNavigateOptions) =>\n selectNodeIn(store, node, options),\n [store],\n );\n}\n\n/** Opens a node, or with `undefined` its drive, in the store in context. */\nexport const useOpenNode: () => (\n node: Node | undefined,\n options?: PHNavigateOptions,\n) => void = useSetSelectedNode;\n\n/** Where a node of `store`'s open drive navigates to. */\nexport function getNodeTargetIn(store: PHStore | undefined, node: Node) {\n const nodeSlug = makeNodeSlug(node);\n return store && isScopedPHStore(store)\n ? scopedNodeTarget(store, nodeSlug)\n : nodeTarget(nodeSlug);\n}\n\n/** Where a node of the open drive navigates to. */\nexport function getNodeTarget(node: Node | undefined) {\n return nodeTarget(makeNodeSlug(node));\n}\n\nfunction preloadNodeIn(store: PHStore | undefined, node: Node | undefined) {\n if (!node) return;\n if (!store || !isScopedPHStore(store)) {\n const target = nodeTarget(makeNodeSlug(node));\n if (target) preloadTarget(target);\n return;\n }\n const target = scopedNodeTarget(store, makeNodeSlug(node));\n if (target) store.navigation?.preload?.(target);\n}\n\n/** Warms a node's view before it is opened, e.g. on hover. */\nexport function preloadNode(node: Node | undefined) {\n warnGlobalSetterInScope(\"preloadNode\", \"usePreloadNode\");\n preloadNodeIn(undefined, node);\n}\n\n/** `preloadNode` for the store in context. */\nexport function usePreloadNode() {\n const store = usePHStore();\n return useCallback(\n (node: Node | undefined) => preloadNodeIn(store, node),\n [store],\n );\n}\n\nexport function addResetSelectedNodeEventHandler() {\n subscribeToPHValue(\"selectedDriveId\", () => {\n setSelectedNodeId(undefined);\n });\n}\n","import type { PHStore } from \"./ph-store.js\";\nimport {\n getPHStore,\n isScopedPHStore,\n usePHStore,\n warnGlobalSetterInScope,\n} from \"./ph-store.js\";\nimport { useCallback } from \"react\";\nimport type { DocumentDispatch } from \"@powerhousedao/reactor-browser\";\nimport type {\n DocumentDriveAction,\n DocumentDriveDocument,\n} from \"@powerhousedao/shared/document-drive\";\nimport {\n extractDriveSlugFromPath,\n extractNodeSlugFromPath,\n findDriveBySlug,\n makeDriveSlug,\n} from \"../utils/url.js\";\nimport { isInitialSyncInFlight } from \"../routing/initial-sync.js\";\nimport { useDispatch } from \"./dispatch.js\";\nimport { useDrives } from \"./drives.js\";\nimport {\n makePHEventFunctions,\n subscribeToPHValue,\n} from \"./make-ph-event-functions.js\";\nimport {\n getCurrentPathname,\n hasHostNavigation,\n openTarget,\n openTargetWith,\n preloadTarget,\n} from \"./navigation.js\";\nimport { selectNode } from \"./set-selected-node.js\";\n\nconst selectedDriveIdEventFunctions = makePHEventFunctions(\"selectedDriveId\");\n\n/** Returns the selected drive id */\nexport const useSelectedDriveId = selectedDriveIdEventFunctions.useValue;\n\n/** Sets the selected drive id */\nexport const setSelectedDriveId = selectedDriveIdEventFunctions.setValue;\n\n/** Adds an event handler for the selected drive id\n * @deprecated `ph:setSelectedDriveId` bypasses the URL; use `setSelectedDrive`. */\nexport const addSelectedDriveIdEventHandler =\n selectedDriveIdEventFunctions.addEventHandler;\n\n/** Returns the selected drive */\nexport function useSelectedDrive() {\n const drive = useSelectedDriveSafe();\n if (!drive[0]) {\n throw new Error(\n \"There is no drive selected. Did you mean to call 'useSelectedDriveSafe'?\",\n );\n }\n\n return drive;\n}\n\n/** Returns the selected drive, or undefined if no drive is selected */\nexport function useSelectedDriveSafe() {\n const selectedDriveId = useSelectedDriveId();\n const drives = useDrives();\n const selectedDrive = drives?.find(\n (drive) => drive.header.id === selectedDriveId,\n );\n\n const [drive, dispatch] = useDispatch(selectedDrive);\n if (!selectedDrive) {\n return [undefined, undefined] as const;\n }\n return [drive, dispatch] as [\n DocumentDriveDocument,\n DocumentDispatch<DocumentDriveAction>,\n ];\n}\n\ntype DriveRef = string | DocumentDriveDocument | undefined;\n\n/** Selects a drive in the app's store; inside a scoped store, use\n * `useSetSelectedDrive`. */\nexport function setSelectedDrive(driveOrDriveSlug: DriveRef) {\n warnGlobalSetterInScope(\"setSelectedDrive\", \"useSetSelectedDrive\");\n selectDrive(driveOrDriveSlug);\n}\n\n/** Selects a drive in `store`: a scope's own selection, else the app's. */\nexport function selectDriveIn(\n store: PHStore | undefined,\n driveOrDriveSlug: DriveRef,\n) {\n if (!store || !isScopedPHStore(store)) {\n selectDrive(driveOrDriveSlug);\n return;\n }\n const driveSlug =\n typeof driveOrDriveSlug === \"string\"\n ? driveOrDriveSlug\n : driveOrDriveSlug && makeDriveSlug(driveOrDriveSlug);\n if (store.navigation) {\n openTargetWith(store.navigation, driveSlug ? { driveSlug } : undefined);\n return;\n }\n const drive =\n typeof driveOrDriveSlug === \"object\"\n ? driveOrDriveSlug\n : findDriveBySlug(store.drives, driveSlug);\n store.selectedDriveId = drive?.header.id;\n store.selectedNodeId = undefined;\n}\n\n/** `setSelectedDrive` for the store in context, e.g. a scoped editor's. */\nexport function useSetSelectedDrive() {\n const store = usePHStore();\n return useCallback((drive: DriveRef) => selectDriveIn(store, drive), [store]);\n}\n\n/** Selects a drive in the app's store, without the scope warning. */\nexport function selectDrive(driveOrDriveSlug: DriveRef) {\n const driveSlug =\n typeof driveOrDriveSlug === \"string\"\n ? driveOrDriveSlug\n : driveOrDriveSlug && makeDriveSlug(driveOrDriveSlug);\n\n // A host router resolves the drive and writes the selection itself.\n if (hasHostNavigation()) {\n cancelPendingDriveSelection();\n openTarget(driveSlug ? { driveSlug } : undefined);\n return;\n }\n\n // A full drive document is selected directly — a just-created drive\n // navigates before the collection refresh. Slugs go through the lookup.\n const drives = getPHStore()?.drives;\n const drive =\n typeof driveOrDriveSlug === \"object\" && driveOrDriveSlug !== null\n ? driveOrDriveSlug\n : findDriveBySlug(drives, driveSlug);\n const driveId = drive?.header.id;\n\n // Deprecated: hosts without a navigation only; route loaders wait for drives.\n // A deep link may predate remote drive registration, so defer the lookup.\n if (\n !driveId &&\n driveSlug &&\n extractDriveSlugFromPath(getCurrentPathname()) === driveSlug\n ) {\n // Clear the previous selection so a stale drive doesn't render against\n // the new URL; the selected node resets with it, the URL is untouched.\n if (getPHStore()?.selectedDriveId) {\n setSelectedDriveId(undefined);\n }\n deferDriveSelection(driveSlug);\n return;\n }\n\n // Any resolved selection supersedes a pending deferred lookup.\n cancelPendingDriveSelection();\n\n setSelectedDriveId(driveId);\n openTarget(driveId && driveSlug ? { driveSlug } : undefined);\n}\n\n/** Warms a drive's view before it is opened, e.g. on hover. */\nexport function preloadDrive(drive: DocumentDriveDocument | undefined) {\n warnGlobalSetterInScope(\"preloadDrive\", \"usePreloadDrive\");\n if (drive) preloadTarget({ driveSlug: makeDriveSlug(drive) });\n}\n\n/** `preloadDrive` for the store in context. */\nexport function usePreloadDrive() {\n const store = usePHStore();\n return useCallback(\n (drive: DocumentDriveDocument | undefined) => {\n if (!drive) return;\n if (!isScopedPHStore(store)) {\n preloadTarget({ driveSlug: makeDriveSlug(drive) });\n return;\n }\n store?.navigation?.preload?.({ driveSlug: makeDriveSlug(drive) });\n },\n [store],\n );\n}\n\n// Tick between unresolved-slug checks; re-armed while a sync is in flight.\nconst DEFERRED_DRIVE_TICK_MS = 2_000;\n// Hard cap so a wedged remote can't pin the deep link forever.\nconst DEFERRED_DRIVE_MAX_WAIT_MS = 15_000;\n\nlet unsubscribePending: (() => void) | undefined;\nlet pendingTimeout: ReturnType<typeof setTimeout> | undefined;\n\nfunction cancelPendingDriveSelection() {\n if (unsubscribePending) {\n unsubscribePending();\n unsubscribePending = undefined;\n }\n if (pendingTimeout) {\n clearTimeout(pendingTimeout);\n pendingTimeout = undefined;\n }\n}\n\n// Deprecated with the no-navigation path: re-runs the slug lookup on drives\n// updates, restores the pinned node, and redirects home once syncs settle.\nfunction deferDriveSelection(driveSlug: string) {\n cancelPendingDriveSelection();\n\n // Capture the node pinned in the deep link before setSelectedDrive\n // rewrites the URL to /d/<driveSlug>, dropping the node segment.\n const nodeSlug = extractNodeSlugFromPath(getCurrentPathname());\n const handler = () => {\n const drive = findDriveBySlug(getPHStore()?.drives, driveSlug);\n if (!drive) {\n return;\n }\n cancelPendingDriveSelection();\n selectDrive(driveSlug);\n selectNode(nodeSlug);\n };\n unsubscribePending = subscribeToPHValue(\"drives\", handler);\n\n const deadline = Date.now() + DEFERRED_DRIVE_MAX_WAIT_MS;\n const scheduleTick = () => {\n pendingTimeout = setTimeout(() => {\n if (Date.now() < deadline && isInitialSyncInFlight(getPHStore())) {\n scheduleTick();\n return;\n }\n cancelPendingDriveSelection();\n openTarget(undefined);\n }, DEFERRED_DRIVE_TICK_MS);\n };\n scheduleTick();\n}\n","import { getPHStore } from \"./ph-store.js\";\nimport type { DocumentModelLib } from \"document-model\";\nimport { useSyncExternalStore } from \"react\";\nimport {\n isDuplicateManifestError,\n isDuplicateModuleError,\n} from \"../reactor-interop.js\";\nimport type { IPackageManager } from \"../types/vetra.js\";\nimport { makePHEventFunctions } from \"./make-ph-event-functions.js\";\n\nconst vetraPackageManagerFunctions = makePHEventFunctions(\n \"vetraPackageManager\",\n);\n\nexport const useVetraPackageManager = vetraPackageManagerFunctions.useValue;\n\nconst EMPTY_VETRA_PACKAGES: DocumentModelLib[] = [];\nconst noPackageManagerUnsubscribe = () => {};\n\n/**\n * Returns all of the Vetra packages loaded by the Connect instance.\n *\n * The snapshot and subscription must keep stable identity while no package\n * manager is registered: `useSyncExternalStore` loops when the snapshot\n * changes on every read, which a fresh `[]` does.\n */\nexport const useVetraPackages = () => {\n const packageManager = useVetraPackageManager();\n const getPackages = () => packageManager?.packages ?? EMPTY_VETRA_PACKAGES;\n\n return useSyncExternalStore(\n (cb) =>\n packageManager\n ? packageManager.subscribe(cb)\n : noPackageManagerUnsubscribe,\n getPackages,\n getPackages,\n );\n};\n\n/** Adds the Vetra package manager event handler */\nexport const addVetraPackageManagerEventHandler =\n vetraPackageManagerFunctions.addEventHandler;\n\n/**\n * Non-react access to the Vetra package manager: calls `callback` once a\n * manager is available - immediately when already set, otherwise when\n * `setVetraPackageManager` publishes one. Returns an unsubscribe. The worker\n * wiring uses this to forward package updates from plain boot code.\n */\nexport function onVetraPackageManager(\n callback: (packageManager: IPackageManager) => void,\n): () => void {\n let delivered: IPackageManager | undefined;\n const deliver = () => {\n const packageManager = vetraPackageManagerFunctions.getSnapshot();\n if (!packageManager || packageManager === delivered) return;\n delivered = packageManager;\n callback(packageManager);\n };\n const unsubscribe = vetraPackageManagerFunctions.subscribeToValue(deliver);\n deliver();\n return unsubscribe;\n}\n\n/** Sets the Vetra package manager and registers its packages */\nexport function setVetraPackageManager(packageManager: IPackageManager) {\n vetraPackageManagerFunctions.setValue(packageManager);\n updateReactorClientDocumentModels(packageManager.packages);\n updateReactorClientUpgradeManifests(packageManager.packages);\n packageManager.subscribe(({ packages }) => {\n updateReactorClientDocumentModels(packages);\n updateReactorClientUpgradeManifests(packages);\n });\n}\n\nfunction updateReactorClientDocumentModels(packages: DocumentModelLib[]) {\n const documentModelModules = packages\n .flatMap((pkg) => pkg.documentModels)\n .filter(\n (module, index, modules) =>\n // dedupe by documentType and version\n modules.findIndex(\n (m) =>\n m.documentModel.global.id === module.documentModel.global.id &&\n (m.version ?? 1) === (module.version ?? 1),\n ) === index,\n );\n\n const registry =\n getPHStore()?.reactorClientModule?.reactorModule?.documentModelRegistry;\n if (!registry || documentModelModules.length === 0) return;\n\n const results = registry.registerModules(...documentModelModules);\n const duplicateTypes = new Set<string>();\n for (const result of results) {\n if (result.status === \"error\") {\n if (isDuplicateModuleError(result.error)) {\n duplicateTypes.add(result.item.documentModel.global.id);\n } else {\n console.error(\n \"Failed to register document model module:\",\n result.error,\n );\n }\n }\n }\n if (duplicateTypes.size > 0) {\n // unregisterModules is type-scoped, so replace the whole version family\n // with the incoming package's modules: re-registering only the duplicated\n // items would purge any new version that registered successfully above.\n registry.unregisterModules(...duplicateTypes);\n registry.registerModules(\n ...documentModelModules.filter((module) =>\n duplicateTypes.has(module.documentModel.global.id),\n ),\n );\n }\n}\n\nfunction updateReactorClientUpgradeManifests(packages: DocumentModelLib[]) {\n const upgradeManifests = packages\n .flatMap((pkg) => pkg.upgradeManifests)\n .filter((u) => u !== undefined);\n\n const registry =\n getPHStore()?.reactorClientModule?.reactorModule?.documentModelRegistry;\n if (!registry || upgradeManifests.length === 0) return;\n\n const results = registry.registerUpgradeManifests(...upgradeManifests);\n const duplicates = [];\n for (const result of results) {\n if (result.status === \"error\") {\n if (isDuplicateManifestError(result.error)) {\n duplicates.push(result);\n } else {\n console.error(\"Failed to register upgrade manifest:\", result.error);\n }\n }\n }\n if (duplicates.length > 0) {\n const duplicateTypes = duplicates\n .map((r) => r.item.documentType)\n .filter((t): t is string => !!t);\n registry.unregisterUpgradeManifests(...duplicateTypes);\n registry.registerUpgradeManifests(...duplicates.map((r) => r.item));\n }\n}\n","import type { DocumentModelModule } from \"document-model\";\nimport { useVetraPackages } from \"./vetra-packages.js\";\n\nexport function useDocumentModelModules(): DocumentModelModule[] | undefined {\n const vetraPackages = useVetraPackages();\n return vetraPackages\n .flatMap((pkg) => pkg.documentModels)\n .filter(\n (module, index, modules) =>\n // deduplicate by documentType and version\n modules.findIndex(\n (m) =>\n m.documentModel.global.id === module.documentModel.global.id &&\n m.version === module.version,\n ) === index,\n );\n}\n\n/**\n * Resolves a document model module by document type, mirroring the registry's\n * semantics (`IDocumentModelRegistry.getModule`): with `version` omitted the\n * LATEST version of the type wins (`version ?? 1` as each module's default),\n * with `version` given only an exact match is returned. The reactor resolves\n * modules the same way when a document is created, so metadata read through\n * this hook and the version a creation actually uses cannot disagree.\n */\nexport function useDocumentModelModuleById(\n id: string | null | undefined,\n version?: number,\n): DocumentModelModule | undefined {\n const documentModelModules = useDocumentModelModules();\n if (!id || !documentModelModules) return undefined;\n\n let latestModule: DocumentModelModule | undefined;\n let latestVersion = -1;\n for (const module of documentModelModules) {\n if (module.documentModel.global.id !== id) continue;\n const moduleVersion = module.version ?? 1;\n if (version !== undefined) {\n if (moduleVersion === version) return module;\n continue;\n }\n if (moduleVersion > latestVersion) {\n latestVersion = moduleVersion;\n latestModule = module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