@powerhousedao/reactor-browser 6.2.3-dev.71 → 6.2.3-dev.73
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-CAf9N-15.d.ts → attachment-service-0L7kHOC-.d.ts} +23 -4
- package/dist/attachment-service-0L7kHOC-.d.ts.map +1 -0
- package/dist/{dispatch-Dd_WEz35.js → dispatch-COa-7Cnf.js} +134 -4
- package/dist/dispatch-COa-7Cnf.js.map +1 -0
- package/dist/{document-by-id-DqAyjr9P.js → document-by-id-1mRv91Zu.js} +2 -2
- package/dist/{document-by-id-DqAyjr9P.js.map → document-by-id-1mRv91Zu.js.map} +1 -1
- package/dist/{document-model-modules-DROQT_yu.js → document-model-modules-BN6ps-J2.js} +2 -2
- package/dist/{document-model-modules-DROQT_yu.js.map → document-model-modules-BN6ps-J2.js.map} +1 -1
- package/dist/{document-operations-C6khz2If.js → document-operations-BY6lqh4g.js} +65 -9
- package/dist/document-operations-BY6lqh4g.js.map +1 -0
- package/dist/{global-D-VZTZRz.d.ts → global-DgCDUQH2.d.ts} +32 -6
- package/dist/global-DgCDUQH2.d.ts.map +1 -0
- package/dist/{index-XfcUiODQ.d.ts → index-Dfr257W2.d.ts} +2 -2
- package/dist/{index-XfcUiODQ.d.ts.map → index-Dfr257W2.d.ts.map} +1 -1
- package/dist/index.d.ts +54 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +85 -48
- package/dist/index.js.map +1 -1
- package/dist/navigation-BqphkrOB.js.map +1 -1
- package/dist/src/ai/index.js +2 -2
- package/dist/src/analytics/index.js +1 -1
- package/dist/src/graphql-client/entry.d.ts +2 -2
- package/dist/src/graphql-client/entry.js +3 -3
- package/dist/src/renown/index.d.ts +1 -1
- package/dist/src/rpc/index.d.ts +44 -10
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +199 -35
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/{switchboard-cwUp3FxP.js → switchboard-BxnVm77m.js} +3 -3
- package/dist/{switchboard-cwUp3FxP.js.map → switchboard-BxnVm77m.js.map} +1 -1
- package/package.json +10 -9
- package/dist/attachment-service-CAf9N-15.d.ts.map +0 -1
- package/dist/dispatch-Dd_WEz35.js.map +0 -1
- package/dist/document-operations-C6khz2If.js.map +0 -1
- package/dist/global-D-VZTZRz.d.ts.map +0 -1
package/dist/{document-model-modules-DROQT_yu.js.map → document-model-modules-BN6ps-J2.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-model-modules-DROQT_yu.js","names":[],"sources":["../src/graphql-client/auth.ts","../src/errors.ts","../src/routing/initial-sync.ts","../src/hooks/drive-context.tsx","../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 {\n DocumentDriveAction,\n DocumentDriveDocument,\n FolderNode,\n Node,\n} from \"@powerhousedao/shared/document-drive\";\nimport type { DocumentDispatch } from \"@powerhousedao/shared/document-model\";\nimport type { ReactNode } from \"react\";\nimport { createContext, useContext } from \"react\";\nimport type { PHNavigateOptions } from \"../types/global.js\";\n\n/** The drive a drive app shows. `open`/`preload` replace the app's navigation,\n * e.g. for a host that keeps the open node in local state. */\nexport type DriveContextValue = {\n drive: DocumentDriveDocument;\n dispatch: DocumentDispatch<DocumentDriveAction>;\n /** The open folder; undefined at the drive's root or on a document. */\n folder?: FolderNode;\n /** The open node, a folder or a document. */\n nodeId?: string;\n open?: (node: Node | undefined, options?: PHNavigateOptions) => void;\n preload?: (node: Node | undefined) => void;\n};\n\nconst DriveContext = createContext<DriveContextValue | undefined>(undefined);\n\n/** Hosts render a drive app inside this; `useSelectedDrive`, `useSelectedNode`\n * and `useSelectedFolder` below read it, and opening nodes calls its `open`. */\nexport function DriveProvider(props: {\n value: DriveContextValue;\n children: ReactNode;\n}) {\n return (\n <DriveContext.Provider value={props.value}>\n {props.children}\n </DriveContext.Provider>\n );\n}\n\n/** The nearest drive app's drive, or undefined outside one. */\nexport function useDriveContext() {\n return useContext(DriveContext);\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 {\n DocumentDriveDocument,\n Node,\n} 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 { useDriveContext } from \"./drive-context.js\";\nimport {\n getCurrentPathname,\n hasHostNavigation,\n openTarget,\n preloadTarget,\n} from \"./navigation.js\";\nimport type { PHStore } from \"./ph-store.js\";\nimport { getPHStore } from \"./ph-store.js\";\n\nconst selectedNodeIdEventFunctions = makePHEventFunctions(\"selectedNodeId\");\nconst useStoreSelectedNodeId = selectedNodeIdEventFunctions.useValue;\n\n/** The selected node id: the drive app's open node, else the app's selection. */\nexport function useSelectedNodeId() {\n const context = useDriveContext();\n const selectedNodeId = useStoreSelectedNodeId();\n return context ? context.nodeId : selectedNodeId;\n}\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 `drive`, else in the app's open drive.\nfunction nodeTarget(\n nodeSlug: string,\n drive?: DocumentDriveDocument,\n): PHNavigationTarget | undefined {\n const driveSlug = drive\n ? makeDriveSlug(drive)\n : 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/** Selects a node in `drive`, else in the app's open drive. */\nexport function selectNode(\n node: NodeRef,\n options?: PHNavigateOptions,\n drive?: DocumentDriveDocument,\n) {\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, drive);\n if (target) openTarget(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 drive app, use `useSetSelectedNode`. */\nexport function setSelectedNode(node: NodeRef, options?: PHNavigateOptions) {\n selectNode(node, options);\n}\n\nfunction findNode(drive: DocumentDriveDocument, node: NodeRef) {\n if (typeof node !== \"string\") return node;\n const id = extractNodeIdFromSlug(node);\n return drive.state.global.nodes.find((n) => n.id === id);\n}\n\n/** Opens a node: through the drive app's `open` when it has one, else the\n * app's navigation in the drive app's drive. */\nexport function useSetSelectedNode() {\n const context = useDriveContext();\n return useCallback(\n (node: NodeRef, options?: PHNavigateOptions) => {\n if (context?.open) {\n context.open(findNode(context.drive, node), options);\n return;\n }\n selectNode(node, options, context?.drive);\n },\n [context],\n );\n}\n\n/** Opens a node, or with `undefined` its drive. */\nexport const useOpenNode: () => (\n node: Node | undefined,\n options?: PHNavigateOptions,\n) => void = useSetSelectedNode;\n\n/** Where a node of `drive`, else of the open drive, navigates to. */\nexport function getNodeTarget(\n node: Node | undefined,\n drive?: DocumentDriveDocument,\n) {\n return nodeTarget(makeNodeSlug(node), drive);\n}\n\n/** Where a node navigates to: in the drive app's drive, else the open drive. */\nexport function useNodeTarget(node: Node | undefined) {\n const context = useDriveContext();\n return getNodeTarget(node, context?.drive);\n}\n\n/** Warms a node's view before it is opened, e.g. on hover. */\nexport function preloadNode(\n node: Node | undefined,\n drive?: DocumentDriveDocument,\n) {\n if (!node) return;\n const target = nodeTarget(makeNodeSlug(node), drive);\n if (target) preloadTarget(target);\n}\n\n/** `preloadNode` through the drive app's `preload`, if it has one. */\nexport function usePreloadNode() {\n const context = useDriveContext();\n return useCallback(\n (node: Node | undefined) => {\n if (context?.preload) context.preload(node);\n else if (!context?.open) preloadNode(node, context?.drive);\n },\n [context],\n );\n}\n\nexport function addResetSelectedNodeEventHandler() {\n subscribeToPHValue(\"selectedDriveId\", () => {\n setSelectedNodeId(undefined);\n });\n}\n","import { getPHStore } 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 { useDriveContext } from \"./drive-context.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 preloadTarget,\n} from \"./navigation.js\";\nimport { selectNode } from \"./set-selected-node.js\";\n\nconst selectedDriveIdEventFunctions = makePHEventFunctions(\"selectedDriveId\");\nconst useStoreSelectedDriveId = selectedDriveIdEventFunctions.useValue;\n\n/** Returns the selected drive id: the drive app's drive, else the app's selection. */\nexport function useSelectedDriveId() {\n const context = useDriveContext();\n const selectedDriveId = useStoreSelectedDriveId();\n return context ? context.drive.header.id : selectedDriveId;\n}\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 context = useDriveContext();\n const selectedDriveId = useStoreSelectedDriveId();\n const drives = useDrives();\n const selectedDrive = context\n ? undefined\n : drives?.find((drive) => drive.header.id === selectedDriveId);\n\n const [drive, dispatch] = useDispatch(selectedDrive);\n if (context) {\n return [context.drive, context.dispatch] as [\n DocumentDriveDocument,\n DocumentDispatch<DocumentDriveAction>,\n ];\n }\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. */\nexport function setSelectedDrive(driveOrDriveSlug: DriveRef) {\n selectDrive(driveOrDriveSlug);\n}\n\n/** `setSelectedDrive`, as a hook. */\nexport function useSetSelectedDrive() {\n return useCallback((drive: DriveRef) => selectDrive(drive), []);\n}\n\n/** Selects a drive in the app's store. */\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 if (drive) preloadTarget({ driveSlug: makeDriveSlug(drive) });\n}\n\n/** `preloadDrive`, as a hook. */\nexport function usePreloadDrive() {\n return useCallback(\n (drive: DocumentDriveDocument | undefined) => preloadDrive(drive),\n [],\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;\n }\n }\n return latestModule;\n}\n"],"mappings":";;;;;;;AAYA,MAAM,+BAA+B;;;;;;;;;;;AAYrC,eAAsB,6BAEpB;CACA,IAAI,OAAO,WAAW,aACpB;CAGF,MAAM,SAAS,WAAW,CAAC,EAAE;CAC7B,IAAI,CAAC,QAAQ,MACX;CAGF,OAAO,OAAO,eAAe,EAAE,WAAW,6BAA6B,CAAC;AAC1E;;;;;;;;AASA,SAAgB,mBACd,eACoB;CACpB,OAAO,OAAO,WAAW;EACvB,MAAM,QAAQ,MAAM,cAAc;EAClC,IAAI,CAAC,OACH,OAAO,OAAO;EAGhB,OAAO,OAAO,EAAE,eAAe,UAAU,QAAQ,CAAC;CACpD;AACF;;;ACzDA,IAAa,+BAAb,cAAkD,MAAM;CACtD,YAAY,cAAsB;EAChC,MAAM,iBAAiB,aAAa,kBAAkB;EACtD,KAAK,OAAO;CACd;CAEA,OAAO,QAAQ,OAAuD;EACpE,OACE,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;CAE3C;AACF;AAEA,IAAa,6BAAb,cAAgD,MAAM;CACpD;CACA,OAAgB;CAEhB,YAAY,cAAsB;EAChC,MAAM,kCAAkC,aAAa,WAAW;EAChE,KAAK,eAAe;CACtB;CAEA,OAAO,QAAQ,OAAqD;EAClE,OAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS;CAChD;AACF;AAEA,IAAa,4BAAb,cAA+C,MAAM;CACnD,YAAY,YAAoB,cAAsB,YAAoB;EACxE,MACE,YAAY,WAAW,kBAAkB,aAAa,iBAAiB,YACzE;CACF;AACF;AAEA,IAAa,0BAAb,c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OAAO,KAAK,GACvC,WAAW,KAAK,MAAM;OAEtB,QAAQ,MAAM,wCAAwC,OAAO,KAAK;CAEtE;CAEF,IAAI,WAAW,SAAS,GAAG;EACzB,MAAM,iBAAiB,WACpB,KAAK,MAAM,EAAE,KAAK,YAAY,CAAC,CAC/B,QAAQ,MAAmB,CAAC,CAAC,CAAC;EACjC,SAAS,2BAA2B,GAAG,cAAc;EACrD,SAAS,yBAAyB,GAAG,WAAW,KAAK,MAAM,EAAE,IAAI,CAAC;CACpE;AACF;;;AChJA,SAAgB,0BAA6D;CAE3E,OADsB,iBACH,CAAC,CACjB,SAAS,QAAQ,IAAI,cAAc,CAAC,CACpC,QACE,QAAQ,OAAO,YAEd,QAAQ,WACL,MACC,EAAE,cAAc,OAAO,OAAO,OAAO,cAAc,OAAO,MAC1D,EAAE,YAAY,OAAO,OACzB,MAAM,KACV;AACJ;;;;;;;;;AAUA,SAAgB,2BACd,IACA,SACiC;CACjC,MAAM,uBAAuB,wBAAwB;CACrD,IAAI,CAAC,MAAM,CAAC,sBAAsB,OAAO,KAAA;CAEzC,IAAI;CACJ,IAAI,gBAAgB;CACpB,KAAK,MAAM,UAAU,sBAAsB;EACzC,IAAI,OAAO,cAAc,OAAO,OAAO,IAAI;EAC3C,MAAM,gBAAgB,OAAO,WAAW;EACxC,IAAI,YAAY,KAAA,GAAW;GACzB,IAAI,kBAAkB,SAAS,OAAO;GACtC;EACF;EACA,IAAI,gBAAgB,eAAe;GACjC,gBAAgB;GAChB,eAAe;EACjB;CACF;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"document-model-modules-BN6ps-J2.js","names":[],"sources":["../src/graphql-client/auth.ts","../src/errors.ts","../src/routing/initial-sync.ts","../src/hooks/drive-context.tsx","../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 {\n DocumentDriveAction,\n DocumentDriveDocument,\n FolderNode,\n Node,\n} from \"@powerhousedao/shared/document-drive\";\nimport type { DocumentDispatch } from \"@powerhousedao/shared/document-model\";\nimport type { ReactNode } from \"react\";\nimport { createContext, useContext } from \"react\";\nimport type { PHNavigateOptions } from \"../types/global.js\";\n\n/** The drive a drive app shows. `open`/`preload` replace the app's navigation,\n * e.g. for a host that keeps the open node in local state. */\nexport type DriveContextValue = {\n drive: DocumentDriveDocument;\n dispatch: DocumentDispatch<DocumentDriveAction>;\n /** The open folder; undefined at the drive's root or on a document. */\n folder?: FolderNode;\n /** The open node, a folder or a document. */\n nodeId?: string;\n open?: (node: Node | undefined, options?: PHNavigateOptions) => void;\n preload?: (node: Node | undefined) => void;\n};\n\nconst DriveContext = createContext<DriveContextValue | undefined>(undefined);\n\n/** Hosts render a drive app inside this; `useSelectedDrive`, `useSelectedNode`\n * and `useSelectedFolder` below read it, and opening nodes calls its `open`. */\nexport function DriveProvider(props: {\n value: DriveContextValue;\n children: ReactNode;\n}) {\n return (\n <DriveContext.Provider value={props.value}>\n {props.children}\n </DriveContext.Provider>\n );\n}\n\n/** The nearest drive app's drive, or undefined outside one. */\nexport function useDriveContext() {\n return useContext(DriveContext);\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 {\n DocumentDriveDocument,\n Node,\n} 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 { useDriveContext } from \"./drive-context.js\";\nimport {\n getCurrentPathname,\n hasHostNavigation,\n openTarget,\n preloadTarget,\n} from \"./navigation.js\";\nimport type { PHStore } from \"./ph-store.js\";\nimport { getPHStore } from \"./ph-store.js\";\n\nconst selectedNodeIdEventFunctions = makePHEventFunctions(\"selectedNodeId\");\nconst useStoreSelectedNodeId = selectedNodeIdEventFunctions.useValue;\n\n/** The selected node id: the drive app's open node, else the app's selection. */\nexport function useSelectedNodeId() {\n const context = useDriveContext();\n const selectedNodeId = useStoreSelectedNodeId();\n return context ? context.nodeId : selectedNodeId;\n}\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 `drive`, else in the app's open drive.\nfunction nodeTarget(\n nodeSlug: string,\n drive?: DocumentDriveDocument,\n): PHNavigationTarget | undefined {\n const driveSlug = drive\n ? makeDriveSlug(drive)\n : 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/** Selects a node in `drive`, else in the app's open drive. */\nexport function selectNode(\n node: NodeRef,\n options?: PHNavigateOptions,\n drive?: DocumentDriveDocument,\n) {\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, drive);\n if (target) openTarget(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 drive app, use `useSetSelectedNode`. */\nexport function setSelectedNode(node: NodeRef, options?: PHNavigateOptions) {\n selectNode(node, options);\n}\n\nfunction findNode(drive: DocumentDriveDocument, node: NodeRef) {\n if (typeof node !== \"string\") return node;\n const id = extractNodeIdFromSlug(node);\n return drive.state.global.nodes.find((n) => n.id === id);\n}\n\n/** Opens a node: through the drive app's `open` when it has one, else the\n * app's navigation in the drive app's drive. */\nexport function useSetSelectedNode() {\n const context = useDriveContext();\n return useCallback(\n (node: NodeRef, options?: PHNavigateOptions) => {\n if (context?.open) {\n context.open(findNode(context.drive, node), options);\n return;\n }\n selectNode(node, options, context?.drive);\n },\n [context],\n );\n}\n\n/** Opens a node, or with `undefined` its drive. */\nexport const useOpenNode: () => (\n node: Node | undefined,\n options?: PHNavigateOptions,\n) => void = useSetSelectedNode;\n\n/** Where a node of `drive`, else of the open drive, navigates to. */\nexport function getNodeTarget(\n node: Node | undefined,\n drive?: DocumentDriveDocument,\n) {\n return nodeTarget(makeNodeSlug(node), drive);\n}\n\n/** Where a node navigates to: in the drive app's drive, else the open drive. */\nexport function useNodeTarget(node: Node | undefined) {\n const context = useDriveContext();\n return getNodeTarget(node, context?.drive);\n}\n\n/** Warms a node's view before it is opened, e.g. on hover. */\nexport function preloadNode(\n node: Node | undefined,\n drive?: DocumentDriveDocument,\n) {\n if (!node) return;\n const target = nodeTarget(makeNodeSlug(node), drive);\n if (target) preloadTarget(target);\n}\n\n/** `preloadNode` through the drive app's `preload`, if it has one. */\nexport function usePreloadNode() {\n const context = useDriveContext();\n return useCallback(\n (node: Node | undefined) => {\n if (context?.preload) context.preload(node);\n else if (!context?.open) preloadNode(node, context?.drive);\n },\n [context],\n );\n}\n\nexport function addResetSelectedNodeEventHandler() {\n subscribeToPHValue(\"selectedDriveId\", () => {\n setSelectedNodeId(undefined);\n });\n}\n","import { getPHStore } 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 { useDriveContext } from \"./drive-context.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 preloadTarget,\n} from \"./navigation.js\";\nimport { selectNode } from \"./set-selected-node.js\";\n\nconst selectedDriveIdEventFunctions = makePHEventFunctions(\"selectedDriveId\");\nconst useStoreSelectedDriveId = selectedDriveIdEventFunctions.useValue;\n\n/** Returns the selected drive id: the drive app's drive, else the app's selection. */\nexport function useSelectedDriveId() {\n const context = useDriveContext();\n const selectedDriveId = useStoreSelectedDriveId();\n return context ? context.drive.header.id : selectedDriveId;\n}\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 context = useDriveContext();\n const selectedDriveId = useStoreSelectedDriveId();\n const drives = useDrives();\n const selectedDrive = context\n ? undefined\n : drives?.find((drive) => drive.header.id === selectedDriveId);\n\n const [drive, dispatch] = useDispatch(selectedDrive);\n if (context) {\n return [context.drive, context.dispatch] as [\n DocumentDriveDocument,\n DocumentDispatch<DocumentDriveAction>,\n ];\n }\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. */\nexport function setSelectedDrive(driveOrDriveSlug: DriveRef) {\n selectDrive(driveOrDriveSlug);\n}\n\n/** `setSelectedDrive`, as a hook. */\nexport function useSetSelectedDrive() {\n return useCallback((drive: DriveRef) => selectDrive(drive), []);\n}\n\n/** Selects a drive in the app's store. */\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 if (drive) preloadTarget({ driveSlug: makeDriveSlug(drive) });\n}\n\n/** `preloadDrive`, as a hook. */\nexport function usePreloadDrive() {\n return useCallback(\n (drive: DocumentDriveDocument | undefined) => preloadDrive(drive),\n [],\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;\n }\n }\n return latestModule;\n}\n"],"mappings":";;;;;;;AAYA,MAAM,+BAA+B;;;;;;;;;;;AAYrC,eAAsB,6BAEpB;CACA,IAAI,OAAO,WAAW,aACpB;CAGF,MAAM,SAAS,WAAW,CAAC,EAAE;CAC7B,IAAI,CAAC,QAAQ,MACX;CAGF,OAAO,OAAO,eAAe,EAAE,WAAW,6BAA6B,CAAC;AAC1E;;;;;;;;AASA,SAAgB,mBACd,eACoB;CACpB,OAAO,OAAO,WAAW;EACvB,MAAM,QAAQ,MAAM,cAAc;EAClC,IAAI,CAAC,OACH,OA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BAAuB,wBAAwB;CACrD,IAAI,CAAC,MAAM,CAAC,sBAAsB,OAAO,KAAA;CAEzC,IAAI;CACJ,IAAI,gBAAgB;CACpB,KAAK,MAAM,UAAU,sBAAsB;EACzC,IAAI,OAAO,cAAc,OAAO,OAAO,IAAI;EAC3C,MAAM,gBAAgB,OAAO,WAAW;EACxC,IAAI,YAAY,KAAA,GAAW;GACzB,IAAI,kBAAkB,SAAS,OAAO;GACtC;EACF;EACA,IAAI,gBAAgB,eAAe;GACjC,gBAAgB;GAChB,eAAe;EACjB;CACF;CACA,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as getPHStore, t as makePHEventFunctions } from "./make-ph-event-functions-B5GU5xcR.js";
|
|
2
|
-
import {
|
|
3
|
-
import { A as addDrivesEventHandler, B as UnsupportedDocumentTypeError, H as makeAuthMiddleware, L as DocumentModelNotFoundError, V as ambientRenownTokenProvider, a as setVetraPackageManager, c as addSelectedDriveIdEventHandler, f as setSelectedDriveId, h as useSelectedDriveId, r as addVetraPackageManagerEventHandler, u as selectDrive, v as addResetSelectedNodeEventHandler, w as setSelectedNodeId, y as addSelectedNodeIdEventHandler } from "./document-model-modules-
|
|
4
|
-
import { A as extractNodeIdFromSlug, N as findDriveBySlug, O as extractDriveSlugFromPath, S as setBrowserOpenSync, c as getCurrentPathname, d as hasHostNavigation, j as extractNodeSlugFromPath, l as getPHNavigation, m as openTarget, v as recordToSearch, x as searchToRecord } from "./navigation-BqphkrOB.js";
|
|
1
|
+
import { c as getPHStore, f as usePHStore, t as makePHEventFunctions } from "./make-ph-event-functions-B5GU5xcR.js";
|
|
2
|
+
import { D as uploadOperations, E as queueOperations, T as queueActions, _ as isOperationCache, f as DocumentCache, i as setDocumentCache, m as IDLE_OPERATIONS_ENTRY, o as useDocumentCache, r as addDocumentCacheEventHandler, y as DOCUMENT_CHANGE_TYPE } from "./dispatch-COa-7Cnf.js";
|
|
3
|
+
import { A as addDrivesEventHandler, B as UnsupportedDocumentTypeError, H as makeAuthMiddleware, L as DocumentModelNotFoundError, V as ambientRenownTokenProvider, a as setVetraPackageManager, c as addSelectedDriveIdEventHandler, f as setSelectedDriveId, h as useSelectedDriveId, r as addVetraPackageManagerEventHandler, u as selectDrive, v as addResetSelectedNodeEventHandler, w as setSelectedNodeId, y as addSelectedNodeIdEventHandler } from "./document-model-modules-BN6ps-J2.js";
|
|
4
|
+
import { A as extractNodeIdFromSlug, N as findDriveBySlug, O as extractDriveSlugFromPath, S as setBrowserOpenSync, c as getCurrentPathname, d as hasHostNavigation, h as openTargetWith, j as extractNodeSlugFromPath, l as getPHNavigation, m as openTarget, v as recordToSearch, w as targetPathname, x as searchToRecord } from "./navigation-BqphkrOB.js";
|
|
5
5
|
import { i as PhDocumentFieldsFragmentDoc, n as DocumentChangesDocument, t as createClient$1 } from "./client-CXDpILj6.js";
|
|
6
6
|
import { f as addLoadingEventHandler, t as addRenownEventHandler } from "./renown-BxkZYzbQ.js";
|
|
7
7
|
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
@@ -14,6 +14,47 @@ import { GraphQLClient } from "graphql-request";
|
|
|
14
14
|
import { gql } from "graphql-tag";
|
|
15
15
|
import { Kind, print } from "graphql";
|
|
16
16
|
import { createClient } from "graphql-ws/client";
|
|
17
|
+
//#region src/hooks/url-state.ts
|
|
18
|
+
/** The nearest store's navigation, else the bound store's, else the browser's.
|
|
19
|
+
* Hosts set it once, so hook order holds. */
|
|
20
|
+
function usePHNavigation() {
|
|
21
|
+
return usePHStore()?.navigation ?? getPHNavigation();
|
|
22
|
+
}
|
|
23
|
+
/** The current query params. */
|
|
24
|
+
function useSearchParams() {
|
|
25
|
+
return usePHNavigation().useSearchParams();
|
|
26
|
+
}
|
|
27
|
+
/** Sets query params: an object merges into them, a function returns them all. */
|
|
28
|
+
function useSetSearchParams() {
|
|
29
|
+
return usePHNavigation().useSetSearchParams();
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/hooks/link-props.ts
|
|
33
|
+
/** A plain primary click; modified and other-button clicks stay the browser's. */
|
|
34
|
+
function isPlainClick(event) {
|
|
35
|
+
return !event.defaultPrevented && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
36
|
+
}
|
|
37
|
+
/** Props for an `<a>` that opens `target` in the app on a plain click, and
|
|
38
|
+
* leaves new tabs and windows to the browser; acts on the store in context. */
|
|
39
|
+
function useLinkProps(target, open) {
|
|
40
|
+
const navigation = usePHNavigation();
|
|
41
|
+
const href = navigation.hrefFor?.(target) ?? targetPathname(target);
|
|
42
|
+
const isCurrent = navigation.useIsCurrent?.(target) ?? false;
|
|
43
|
+
const preload = () => navigation.preload?.(target);
|
|
44
|
+
const openTarget = open ?? (() => openTargetWith(navigation, target));
|
|
45
|
+
return {
|
|
46
|
+
href,
|
|
47
|
+
onClick: (event) => {
|
|
48
|
+
if (!isPlainClick(event)) return;
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
openTarget();
|
|
51
|
+
},
|
|
52
|
+
onMouseEnter: preload,
|
|
53
|
+
onFocus: preload,
|
|
54
|
+
"aria-current": isCurrent ? "page" : void 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
17
58
|
//#region src/hooks/modals.ts
|
|
18
59
|
const modalEventFunctions = makePHEventFunctions("modal");
|
|
19
60
|
/** Returns the current modal */
|
|
@@ -27,13 +68,15 @@ const MODAL_SEARCH_PARAM = "modal";
|
|
|
27
68
|
const MODAL_ROUTES = {
|
|
28
69
|
createDocument: {
|
|
29
70
|
id: "create-document",
|
|
30
|
-
toSearch: ({ documentType, documentModelVersion }) => ({
|
|
71
|
+
toSearch: ({ documentType, documentModelVersion, driveId }) => ({
|
|
31
72
|
documentType,
|
|
32
|
-
...documentModelVersion !== void 0 && { documentModelVersion: String(documentModelVersion) }
|
|
73
|
+
...documentModelVersion !== void 0 && { documentModelVersion: String(documentModelVersion) },
|
|
74
|
+
...driveId && { driveId }
|
|
33
75
|
}),
|
|
34
76
|
fromSearch: (search) => ({
|
|
35
77
|
documentType: search.documentType ?? "",
|
|
36
|
-
...search.documentModelVersion && { documentModelVersion: Number(search.documentModelVersion) }
|
|
78
|
+
...search.documentModelVersion && { documentModelVersion: Number(search.documentModelVersion) },
|
|
79
|
+
...search.driveId && { driveId: search.driveId }
|
|
37
80
|
})
|
|
38
81
|
},
|
|
39
82
|
login: { id: "login" },
|
|
@@ -121,6 +164,19 @@ function modalHref(modal) {
|
|
|
121
164
|
};
|
|
122
165
|
return `${pathname}${recordToSearch(next)}`;
|
|
123
166
|
}
|
|
167
|
+
/** Props for an `<a>` that opens a routed `modal` over the current page on a
|
|
168
|
+
* plain click; new tabs and copied links get its URL. */
|
|
169
|
+
function useModalLinkProps(modal) {
|
|
170
|
+
useSearchParams();
|
|
171
|
+
return {
|
|
172
|
+
href: modalHref(modal),
|
|
173
|
+
onClick: (event) => {
|
|
174
|
+
if (!isPlainClick(event)) return;
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
showPHModal(modal);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
124
180
|
/** Shows the create document modal */
|
|
125
181
|
function showCreateDocumentModal(documentType, documentModelVersion) {
|
|
126
182
|
showPHModal({
|
|
@@ -3352,6 +3408,6 @@ function useDocumentOperations(documentId, scope, options = {}) {
|
|
|
3352
3408
|
return legacy ? legacyResult : primary;
|
|
3353
3409
|
}
|
|
3354
3410
|
//#endregion
|
|
3355
|
-
export { addIsAnalyticsExternalProcessorsEnabledEventHandler as $, isRoutedModal as $i, useIsEditorDebugModeEnabled as $n, signStampedAction as $r, setIsDeleteLocalDrivesEnabled as $t, useDropTarget as A, renameDriveNode as Ai, useAnalyticsDatabaseName as An, phDocumentEditorConfigHooks as Ar, addVersionEventHandler as At, addCliVersionEventHandler as B, setFullReactorClient as Bi, useIsAddDriveEnabled as Bn, isGraphQLReactorClient as Br, setDrivesPreserveStrategy as Bt, usePackageDiscoveryService as C, deleteNode as Ci, setSentryRelease as Cn, useWarnOutdatedApp as Cr, addRouterBasenameEventHandler as Ct, addDraggingNodeEventHandler as D, getDocumentExtension as Di, setVersionCheckInterval as Dn, isExternalControlsEnabledEventFunctions as Dr, addStudioModeEventHandler as Dt, useGraphQLReactorClient as E, fetchDocumentOperations as Ei, setVersion as En, addIsExternalControlsEnabledEventHandler as Er, addSentryReleaseEventHandler as Et, setAttachmentService as F, isDocumentTypeSupported as Fi, useDrivesPreserveStrategy as Fn, useAllowedDocumentTypes as Fr, setAnalyticsDatabaseName as Ft, addFileUploadOperationsChunkSizeEventHandler as G, usePGlite as Gi, useIsAnalyticsExternalProcessorsEnabled as Gn, subscriptionsUrlFromGraphqlUrl as Gr, setIsAddDriveEnabled as Gt, addDisabledEditorsEventHandler as H, setReactorClientModule as Hi, useIsAddPublicDrivesEnabled as Hn, isAuthRefusalClose as Hr, setFileUploadOperationsChunkSize as Ht, useAttachmentService as I, addFullReactorClientEventHandler as Ii, useEnabledEditors as In, useIsDragAndDropEnabled as Ir, setBasePath as It, addIsAddDriveEnabledEventHandler as J, useSync as Ji, useIsDeleteLocalDrivesEnabled as Jn, subgraphUrlFromGraphqlUrl as Jr, setIsAnalyticsDatabaseWorkerEnabled as Jt, addGaTrackingIdEventHandler as K, useReactorClient as Ki, useIsCloudDrivesEnabled as Kn, SubgraphSdkRegistry as Kr, setIsAddLocalDrivesEnabled as Kt, addAllowListEventHandler as L, addReactorClientEventHandler as Li, useFileUploadOperationsChunkSize as Ln, useIsExternalControlsEnabled as Lr, setCliVersion as Lt, setFeatures as M, setPreferredEditorOnNode as Mi, useCliVersion as Mn, setAllowedDocumentTypes as Mr, phGlobalConfigHooks as Mt, useFeatures as N, upgradeDocument as Ni, useDefaultDrivesUrl as Nn, setIsDragAndDropEnabled as Nr, phGlobalConfigSetters as Nt, useDragNode as O, loadFile as Oi, setWarnOutdatedApp as On, phAppConfigHooks as Or, addSwitchboardUrlEventHandler as Ot, addAttachmentServiceEventHandler as P, getUserPermissions as Pi, useDisabledEditors as Pn, setIsExternalControlsEnabled as Pr, setAllowList as Pt, addIsAnalyticsEnabledEventHandler as Q, closePHModal as Qi, useIsDriveAnalyticsEnabled as Qn, prepareSignedActions as Qr, setIsDeleteCloudDrivesEnabled as Qt, addAnalyticsDatabaseNameEventHandler as R, addReactorClientModuleEventHandler as Ri, useGaTrackingId as Rn, GraphQLReactorClient as Rr, setDefaultDrivesUrl as Rt, setPackageDiscoveryService as S, copyNode$1 as Si, setSentryEnv as Sn, useVersionCheckInterval as Sr, addRequiresHardRefreshEventHandler as St, setGraphQLReactorClient as T, extractInitialState as Ti, setSwitchboardUrl as Tn, addIsDragAndDropEnabledEventHandler as Tr, addSentryEnvEventHandler as Tt, addDrivesPreserveStrategyEventHandler as U, useDatabase as Ui, useIsAnalyticsDatabaseWorkerEnabled as Un, makeAuthConnectionParams as Ur, setGaTrackingId as Ut, addDefaultDrivesUrlEventHandler as V, setReactorClient as Vi, useIsAddLocalDrivesEnabled as Vn, viewFilterInputFromViewFilter as Vr, setEnabledEditors as Vt, addEnabledEditorsEventHandler as W, useModelRegistry as Wi, useIsAnalyticsEnabled as Wn, startDocumentChangesSubscription as Wr, setIsAddCloudDrivesEnabled as Wt, addIsAddPublicDrivesEnabledEventHandler as X, MODAL_SEARCH_PARAM as Xi, useIsDiffAnalyticsEnabled as Xn, packageFromDocumentModels as Xr, setIsAnalyticsExternalProcessorsEnabled as Xt, addIsAddLocalDrivesEnabledEventHandler as Y, useSyncList as Yi, useIsDeletePublicDrivesEnabled as Yn, StaticPackageManager as Yr, setIsAnalyticsEnabled as Yt, addIsAnalyticsDatabaseWorkerEnabledEventHandler as Z, addModalEventHandler as Zi, useIsDocumentModelSelectionSettingsEnabled as Zn, resolveDocumentModelModule as Zr, setIsCloudDrivesEnabled as Zt, addSetSelectedDriveOnPopStateEventHandler as _, DEFAULT_DRIVE_EDITOR_ID as _i, setRenownNetworkId as _n, useSentryEnv as _r, addLogLevelEventHandler as _t, addPHEventHandlers as a, showDeleteNodeModal as aa, GraphQLWrongBackendError as ai, setIsEditorReadModeEnabled as an, useIsPublicDrivesEnabled as ar, addIsDocumentModelSelectionSettingsEnabledEventHandler as at, syncSelectionFromPath as b, addFileWithProgress as bi, setRouterBasename as bn, useSwitchboardUrl as br, addRenownNetworkIdEventHandler as bt, addToastEventHandler as c,
|
|
3411
|
+
export { addIsAnalyticsExternalProcessorsEnabledEventHandler as $, isRoutedModal as $i, useIsEditorDebugModeEnabled as $n, signStampedAction as $r, setIsDeleteLocalDrivesEnabled as $t, useDropTarget as A, renameDriveNode as Ai, useAnalyticsDatabaseName as An, phDocumentEditorConfigHooks as Ar, addVersionEventHandler as At, addCliVersionEventHandler as B, setFullReactorClient as Bi, useIsAddDriveEnabled as Bn, isGraphQLReactorClient as Br, setDrivesPreserveStrategy as Bt, usePackageDiscoveryService as C, deleteNode as Ci, setSentryRelease as Cn, useWarnOutdatedApp as Cr, addRouterBasenameEventHandler as Ct, addDraggingNodeEventHandler as D, getDocumentExtension as Di, setVersionCheckInterval as Dn, isExternalControlsEnabledEventFunctions as Dr, addStudioModeEventHandler as Dt, useGraphQLReactorClient as E, fetchDocumentOperations as Ei, setVersion as En, addIsExternalControlsEnabledEventHandler as Er, addSentryReleaseEventHandler as Et, setAttachmentService as F, isDocumentTypeSupported as Fi, useDrivesPreserveStrategy as Fn, useAllowedDocumentTypes as Fr, setAnalyticsDatabaseName as Ft, addFileUploadOperationsChunkSizeEventHandler as G, usePGlite as Gi, useIsAnalyticsExternalProcessorsEnabled as Gn, subscriptionsUrlFromGraphqlUrl as Gr, setIsAddDriveEnabled as Gt, addDisabledEditorsEventHandler as H, setReactorClientModule as Hi, useIsAddPublicDrivesEnabled as Hn, isAuthRefusalClose as Hr, setFileUploadOperationsChunkSize as Ht, useAttachmentService as I, addFullReactorClientEventHandler as Ii, useEnabledEditors as In, useIsDragAndDropEnabled as Ir, setBasePath as It, addIsAddDriveEnabledEventHandler as J, useSync as Ji, useIsDeleteLocalDrivesEnabled as Jn, subgraphUrlFromGraphqlUrl as Jr, setIsAnalyticsDatabaseWorkerEnabled as Jt, addGaTrackingIdEventHandler as K, useReactorClient as Ki, useIsCloudDrivesEnabled as Kn, SubgraphSdkRegistry as Kr, setIsAddLocalDrivesEnabled as Kt, addAllowListEventHandler as L, addReactorClientEventHandler as Li, useFileUploadOperationsChunkSize as Ln, useIsExternalControlsEnabled as Lr, setCliVersion as Lt, setFeatures as M, setPreferredEditorOnNode as Mi, useCliVersion as Mn, setAllowedDocumentTypes as Mr, phGlobalConfigHooks as Mt, useFeatures as N, upgradeDocument as Ni, useDefaultDrivesUrl as Nn, setIsDragAndDropEnabled as Nr, phGlobalConfigSetters as Nt, useDragNode as O, loadFile as Oi, setWarnOutdatedApp as On, phAppConfigHooks as Or, addSwitchboardUrlEventHandler as Ot, addAttachmentServiceEventHandler as P, getUserPermissions as Pi, useDisabledEditors as Pn, setIsExternalControlsEnabled as Pr, setAllowList as Pt, addIsAnalyticsEnabledEventHandler as Q, closePHModal as Qi, useIsDriveAnalyticsEnabled as Qn, prepareSignedActions as Qr, setIsDeleteCloudDrivesEnabled as Qt, addAnalyticsDatabaseNameEventHandler as R, addReactorClientModuleEventHandler as Ri, useGaTrackingId as Rn, GraphQLReactorClient as Rr, setDefaultDrivesUrl as Rt, setPackageDiscoveryService as S, copyNode$1 as Si, setSentryEnv as Sn, useVersionCheckInterval as Sr, addRequiresHardRefreshEventHandler as St, setGraphQLReactorClient as T, extractInitialState as Ti, setSwitchboardUrl as Tn, addIsDragAndDropEnabledEventHandler as Tr, addSentryEnvEventHandler as Tt, addDrivesPreserveStrategyEventHandler as U, useDatabase as Ui, useIsAnalyticsDatabaseWorkerEnabled as Un, makeAuthConnectionParams as Ur, setGaTrackingId as Ut, addDefaultDrivesUrlEventHandler as V, setReactorClient as Vi, useIsAddLocalDrivesEnabled as Vn, viewFilterInputFromViewFilter as Vr, setEnabledEditors as Vt, addEnabledEditorsEventHandler as W, useModelRegistry as Wi, useIsAnalyticsEnabled as Wn, startDocumentChangesSubscription as Wr, setIsAddCloudDrivesEnabled as Wt, addIsAddPublicDrivesEnabledEventHandler as X, MODAL_SEARCH_PARAM as Xi, useIsDiffAnalyticsEnabled as Xn, packageFromDocumentModels as Xr, setIsAnalyticsExternalProcessorsEnabled as Xt, addIsAddLocalDrivesEnabledEventHandler as Y, useSyncList as Yi, useIsDeletePublicDrivesEnabled as Yn, StaticPackageManager as Yr, setIsAnalyticsEnabled as Yt, addIsAnalyticsDatabaseWorkerEnabledEventHandler as Z, addModalEventHandler as Zi, useIsDocumentModelSelectionSettingsEnabled as Zn, resolveDocumentModelModule as Zr, setIsCloudDrivesEnabled as Zt, addSetSelectedDriveOnPopStateEventHandler as _, DEFAULT_DRIVE_EDITOR_ID as _i, setRenownNetworkId as _n, useSentryEnv as _r, addLogLevelEventHandler as _t, addPHEventHandlers as a, showDeleteNodeModal as aa, GraphQLWrongBackendError as ai, setIsEditorReadModeEnabled as an, useIsPublicDrivesEnabled as ar, addIsDocumentModelSelectionSettingsEnabledEventHandler as at, syncSelectionFromPath as b, addFileWithProgress as bi, setRouterBasename as bn, useSwitchboardUrl as br, addRenownNetworkIdEventHandler as bt, addToastEventHandler as c, usePHModal as ca, phDocumentFromMutation as ci, setIsExternalRelationalProcessorsEnabled as cn, useLocalDrivesEnabled as cr, addIsEditorReadModeEnabledEventHandler as ct, addSelectedTimelineRevisionEventHandler as d, useLinkProps as da, buildPulledDocument as di, setIsRelationalProcessorsEnabled as dn, useRenownChainId as dr, addIsExternalRelationalProcessorsEnabledEventHandler as dt, modalFromSearch as ea, stampAction as ei, setIsDeletePublicDrivesEnabled as en, useIsEditorReadModeEnabled as er, addIsCloudDrivesEnabledEventHandler as et, setSelectedTimelineRevision as f, usePHNavigation as fa, convertRemoteOperations as fi, setIsSentryTracingEnabled as fn, useRenownNetworkId as fr, addIsLocalDrivesEnabledEventHandler as ft, useSelectedTimelineItem as g, COMMON_PACKAGE_ID as gi, setRenownChainId as gn, useSentryDsn as gr, addLocalDrivesEnabledEventHandler as gt, setSelectedTimelineItem as h, screamingSnakeToCamel as hi, setRenownAdapters as hn, useRouterBasename as hr, addIsSentryTracingEnabledEventHandler as ht, useSwitchboardClient as i, showCreateDocumentModal as ia, GraphQLOperationNotSupportedError as ii, setIsEditorDebugModeEnabled as in, useIsLocalDrivesEnabled as ir, addIsDiffAnalyticsEnabledEventHandler as it, addFeaturesEventHandler as j, renameNode as ji, useBasePath as jn, phDocumentEditorConfigSetters as jr, addWarnOutdatedAppEventHandler as jt, useDropNode as k, moveNode$1 as ki, useAllowList as kn, phAppConfigSetters as kr, addVersionCheckIntervalEventHandler as kt, setPHToast as l, withoutModalSearch as la, revisionMapFromRevisionsList as li, setIsLocalDrivesEnabled as ln, useLogLevel as lr, addIsExternalPackagesEnabledEventHandler as lt, addSelectedTimelineItemEventHandler as m, useSetSearchParams as ma, hasRevisionConflict as mi, setLogLevel as mn, useRequiresHardRefresh as mr, addIsRelationalProcessorsEnabledEventHandler as mt, GraphQLReactorProvider as n, modalSearch as na, ReactorOperationFieldsFragmentDoc as ni, setIsDocumentModelSelectionSettingsEnabled as nn, useIsExternalProcessorsEnabled as nr, addIsDeleteLocalDrivesEnabledEventHandler as nt, callEventHandlerRegisterFunctions as o, showPHModal as oa, isoStringFromDateTime as oi, setIsExternalPackagesEnabled as on, useIsRelationalProcessorsEnabled as or, addIsDriveAnalyticsEnabledEventHandler as ot, useSelectedTimelineRevision as p, useSearchParams as pa, extractRevisionMap as pi, setLocalDrivesEnabled as pn, useRenownUrl as pr, addIsPublicDrivesEnabledEventHandler as pt, addIsAddCloudDrivesEnabledEventHandler as q, useReactorClientModule as qi, useIsDeleteCloudDrivesEnabled as qn, describeGraphQLDocument as qr, setIsAddPublicDrivesEnabled as qt, ensurePHEventHandlers as r, setPHModal as ra, BatchJobFailedError as ri, setIsDriveAnalyticsEnabled as rn, useIsExternalRelationalProcessorsEnabled as rr, addIsDeletePublicDrivesEnabledEventHandler as rt, commonGlobalEventHandlerFunctions as s, useModalLinkProps as sa, phDocumentFromGetDocument as si, setIsExternalProcessorsEnabled as sn, useIsSentryTracingEnabled as sr, addIsEditorDebugModeEnabledEventHandler as st, useDocumentOperations as t, modalHref as ta, MutateDocumentWithOperationsDocument as ti, setIsDiffAnalyticsEnabled as tn, useIsExternalPackagesEnabled as tr, addIsDeleteCloudDrivesEnabledEventHandler as tt, usePHToast as u, isPlainClick as ua, ConflictError as ui, setIsPublicDrivesEnabled as un, useRenownAdapters as ur, addIsExternalProcessorsEnabledEventHandler as ut, addSetSelectedNodeOnPopStateEventHandler as v, DRIVE_DOCUMENT_TYPES as vi, setRenownUrl as vn, useSentryRelease as vr, addRenownAdaptersEventHandler as vt, addGraphQLReactorClientEventHandler as w, exportFile as wi, setStudioMode as wn, addAllowedDocumentTypesEventHandler as wr, addSentryDsnEventHandler as wt, addPackageDiscoveryServiceEventHandler as x, addFolder$1 as xi, setSentryDsn as xn, useVersion as xr, addRenownUrlEventHandler as xt, addSyncSelectionOnPopStateEventHandler as y, addDocument as yi, setRequiresHardRefresh as yn, useStudioMode as yr, addRenownChainIdEventHandler as yt, addBasePathEventHandler as z, getFullReactorClient as zi, useIsAddCloudDrivesEnabled as zn, findIsServableOverGraphQL as zr, setDisabledEditors as zt };
|
|
3356
3412
|
|
|
3357
|
-
//# sourceMappingURL=document-operations-
|
|
3413
|
+
//# sourceMappingURL=document-operations-BY6lqh4g.js.map
|