@powerhousedao/reactor-browser 6.2.3-dev.70 → 6.2.3-dev.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +21 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/navigation-BqphkrOB.js.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-BqphkrOB.js","names":[],"sources":["../src/utils/url.ts","../src/hooks/navigation.ts"],"sourcesContent":["import { getPHStore } from \"../hooks/ph-store.js\";\nimport type {\n DocumentDriveDocument,\n Node,\n} from \"@powerhousedao/shared/document-drive\";\nimport { isDerivedDocumentId } from \"@powerhousedao/shared/document-model\";\nimport slug from \"slug\";\n\n// Length of the base64url id a v2-required document gets.\nconst DERIVED_ID_LENGTH = 43;\n\n// Returns url with base path plus provided path\nexport function resolveUrlPathname(path: string) {\n return new URL(\n path.replace(/^\\/+/, \"\"),\n window.location.origin + (getPHStore()?.basePath ?? \"/\"),\n ).pathname;\n}\n\n/** Returns the path without a leading base path */\nexport function getPathWithoutBase(path: string) {\n const basePath = getPHStore()?.basePath ?? \"/\";\n if (!path.startsWith(basePath)) return path;\n const rest = path.slice(basePath.length);\n if (basePath.endsWith(\"/\")) return `/${rest}`;\n return rest === \"\" || rest.startsWith(\"/\") ? rest : path;\n}\n\n/** Makes a URL component for a drive.\n * @deprecated Open drives through the store's `navigation`; it builds the path. */\nexport function makeDriveUrlComponent(\n drive: DocumentDriveDocument | undefined,\n) {\n if (!drive) return \"\";\n return `/d/${slug(drive.header.slug)}`;\n}\n\n/** A drive's URL component: its slug, else its id, prefixed with the slugged\n * name as `<name>-<id>` when the id is opaque (a UUID or derived id). */\nexport function makeDriveSlug(drive: DocumentDriveDocument) {\n const { id, slug: driveSlug } = drive.header;\n if (driveSlug && driveSlug !== id) return driveSlug;\n return isOpaqueId(id) ? namedDriveSlug(drive) : id;\n}\n\nfunction isOpaqueId(id: string) {\n return findUuid(id) !== undefined || isDerivedDocumentId(id);\n}\n\nfunction namedDriveSlug(drive: DocumentDriveDocument) {\n const name = drive.state.global.name || drive.header.name;\n return namedSlug(drive, name, drive.header.id);\n}\n\nconst namedSlugs = new WeakMap<\n object,\n { name: string; id: string; value: string }\n>();\n\n// `<slugged name>-<id>`, cached per drive or node; inputs are rechecked.\nfunction namedSlug(owner: object, name: string, id: string) {\n const cached = namedSlugs.get(owner);\n if (cached?.name === name && cached.id === id) return cached.value;\n const nameSlug = name ? slug(name) : \"\";\n const value = nameSlug ? `${nameSlug}-${id}` : id;\n namedSlugs.set(owner, { name, id, value });\n return value;\n}\n\n/** The drive a URL slug names: its own slug, its id, or `<name>-<id>`. */\nexport function findDriveBySlug(\n drives: readonly DocumentDriveDocument[] | undefined,\n ref: string | undefined,\n) {\n if (!drives || !ref) return undefined;\n const exact = drives.find(\n (d) => d.header.slug === ref || d.header.id === ref,\n );\n if (exact) return exact;\n const id = extractDriveIdFromSlug(ref);\n if (id !== undefined) {\n const byId = drives.find((d) => d.header.id === id);\n if (byId) return byId;\n }\n // `<name>-<id>` also for a readable id, as older links wrote it.\n return drives.find(\n (d) =>\n (!d.header.slug || d.header.slug === d.header.id) &&\n ref.endsWith(d.header.id) &&\n namedDriveSlug(d) === ref,\n );\n}\n\n/**\n * Makes a URL component for a node: `<slugged name>-<id>`. The id is kept\n * verbatim, since a v2-required id is case-sensitive base64url.\n */\nexport function makeNodeSlug(node: Node | undefined) {\n if (!node) return \"\";\n return namedSlug(node, node.name, node.id);\n}\n\n/** Extracts the node slug from a path.\n *\n * The path is expected to be in the format `/d/<drive-slug>/<node-slug>`.\n */\nexport function extractNodeSlugFromPath(path: string) {\n const currentPath = getPathWithoutBase(path);\n const match = /^\\/d\\/[^/]+\\/([^/]+)$/.exec(currentPath);\n return match?.[1];\n}\n\n/** Finds a UUID in a string, used for extracting node ids from node slugs in the URL. */\nexport function findUuid(input: string | undefined) {\n if (!input) return undefined;\n const uuidRegex =\n /\\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/;\n const match = uuidRegex.exec(input);\n return match?.[0];\n}\n\n/** The v2-required document id a slug ends with, if any. */\nexport function findDerivedId(input: string | undefined) {\n if (!input || input.length < DERIVED_ID_LENGTH) return undefined;\n const start = input.length - DERIVED_ID_LENGTH;\n if (start > 0 && input[start - 1] !== \"-\") return undefined;\n const candidate = input.slice(start);\n return isDerivedDocumentId(candidate) ? candidate : undefined;\n}\n\nexport function extractNodeIdFromSlug(nodeSlug: string | undefined) {\n return findUuid(nodeSlug) ?? findDerivedId(nodeSlug);\n}\n\n/** @deprecated Route loaders resolve the node; use `extractNodeIdFromSlug`. */\nexport function extractNodeIdFromPath(path: string) {\n const nodeSlug = extractNodeSlugFromPath(path);\n const nodeId = extractNodeIdFromSlug(nodeSlug);\n return nodeId;\n}\n\n/** Extracts the drive slug from a path.\n * Used for extracting drive ids from drive slugs in the URL.\n * Expects the path to be in the format `/d/<drive-slug>`.\n */\nexport function extractDriveSlugFromPath(path: string) {\n const currentPath = getPathWithoutBase(path);\n const match = /^\\/d\\/([^/]+)/.exec(currentPath);\n return match?.[1] ?? \"\";\n}\n\nexport function extractDriveIdFromSlug(driveSlug: string | undefined) {\n return findUuid(driveSlug) ?? findDerivedId(driveSlug);\n}\n\n/** @deprecated Route loaders resolve the drive; use `extractDriveIdFromSlug`. */\nexport function extractDriveIdFromPath(path: string) {\n const driveSlug = extractDriveSlugFromPath(path);\n const driveId = extractDriveIdFromSlug(driveSlug);\n return driveId;\n}\n\n/** Creates a URL string with the given pathname, keeping the query string.\n * @deprecated The store's `navigation` keeps global params across navigations. */\nexport function createUrlWithPreservedParams(pathname: string): string {\n const search = window.location.search;\n return search ? `${pathname}${search}` : pathname;\n}\n","import type {\n PHNavigateOptions,\n PHNavigation,\n PHNavigationTarget,\n PHSearchUpdate,\n PHSettingsTarget,\n SearchParamsUpdate,\n} from \"@powerhousedao/reactor-browser\";\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport { resolveUrlPathname } from \"../utils/url.js\";\nimport { getPHStore } from \"./ph-store.js\";\n\nconst isServer = typeof window === \"undefined\";\n\n/** Fired on `window` when the fallback navigator rewrites the URL. */\nexport const PH_LOCATION_CHANGE_EVENT = \"ph:locationchange\";\n\n/** Params read at boot or app-wide; they survive every navigation. Others,\n * e.g. a document's own, are dropped when the target changes. */\nexport const GLOBAL_SEARCH_PARAMS = [\n // A remote drive to add on boot.\n \"driveUrl\",\n // The theme override read by the inline theme boot script.\n \"theme\",\n // Embedded mode, which hides Connect's chrome.\n \"embed\",\n // Log level override for the feature-flag provider.\n \"LOG_LEVEL\",\n // The reactor worker runtime flag override.\n \"reactorWorker\",\n] as const;\n\n/** Feature flags are any `FEATURE_*` param, so they are retained by prefix. */\nexport const FEATURE_FLAG_PARAM_PREFIX = \"FEATURE_\";\n\n/** Whether `key` is a param every navigation keeps. */\nexport function isGlobalSearchParam(key: string) {\n return (\n (GLOBAL_SEARCH_PARAMS as readonly string[]).includes(key) ||\n key.startsWith(FEATURE_FLAG_PARAM_PREFIX)\n );\n}\n\nfunction globalSearch(search: string) {\n return Object.fromEntries(\n Object.entries(searchToRecord(search)).filter(([key]) =>\n isGlobalSearchParam(key),\n ),\n );\n}\n\n/** A query string's params; repeated keys keep their last value. */\nexport function searchToRecord(search: string): Record<string, string> {\n return Object.fromEntries(new URLSearchParams(search));\n}\n\n/** `prev` with `update` applied; an `undefined` value removes the key. */\nexport function applySearchUpdate(\n prev: Record<string, string>,\n update: PHSearchUpdate,\n): Record<string, string> {\n const next = { ...prev };\n for (const [key, value] of Object.entries(update)) {\n if (value === undefined) delete next[key];\n else next[key] = value;\n }\n return next;\n}\n\n/** `params` as a query string, with an empty value as a bare key: `history`, not `history=`. */\nexport function searchParamsToString(params: URLSearchParams) {\n return params.toString().replace(/=(?=&|$)/g, \"\");\n}\n\n/** `?a=1&b=2`, or an empty string for no params. */\nexport function recordToSearch(record: Record<string, string>) {\n const search = searchParamsToString(new URLSearchParams(record));\n return search ? `?${search}` : \"\";\n}\n\n/** The settings page's path; its tabs are below it. */\nexport const SETTINGS_PATH = \"/settings\";\n\nexport function isSettingsTarget(\n target: PHNavigationTarget | undefined,\n): target is PHSettingsTarget {\n return !!target && \"settings\" in target;\n}\n\n/** The pathname a target opens at, base path included. */\nexport function targetPathname(target: PHNavigationTarget | undefined) {\n if (!target) return resolveUrlPathname(\"/\");\n if (isSettingsTarget(target)) {\n const { settings } = target;\n return resolveUrlPathname(\n settings === true ? SETTINGS_PATH : `${SETTINGS_PATH}/${settings}`,\n );\n }\n const { driveSlug, nodeSlug } = target;\n return resolveUrlPathname(\n nodeSlug ? `/d/${driveSlug}/${nodeSlug}` : `/d/${driveSlug}`,\n );\n}\n\n/** History state key: the index of the entry a document was opened from. */\nexport const OPENED_FROM_STATE_KEY = \"phOpenedFrom\";\n\n// The fallback numbers its own entries; a router's history has its own index.\ntype BrowserEntryState = { phIndex?: number; phOpenedFrom?: number };\n\nfunction browserEntryState(): BrowserEntryState {\n const state: unknown = window.history.state;\n return state && typeof state === \"object\" ? (state as BrowserEntryState) : {};\n}\n\n/** The index to go back to from `index`, when it lies before it. */\nexport function openedFromIndex(\n state: object | undefined,\n index: number,\n): number | undefined {\n const from = (state as Record<string, unknown> | undefined)?.[\n OPENED_FROM_STATE_KEY\n ];\n return typeof from === \"number\" && from >= 0 && from < index\n ? from\n : undefined;\n}\n\n// `openedFrom` \"keep\" carries the current entry's, as an in-document write does.\nfunction writeBrowserUrl(\n href: string,\n replace: boolean | undefined,\n openedFrom: number | \"keep\" | undefined,\n) {\n const prev = browserEntryState();\n const index = prev.phIndex ?? 0;\n const from = openedFrom === \"keep\" ? prev.phOpenedFrom : openedFrom;\n // Keeps the entry's state, e.g. a router's history key, on a replace.\n if (replace) {\n window.history.replaceState(\n { ...prev, phIndex: index, phOpenedFrom: from },\n \"\",\n href,\n );\n } else {\n window.history.pushState(\n { phIndex: index + 1, phOpenedFrom: from },\n \"\",\n href,\n );\n }\n window.dispatchEvent(new Event(PH_LOCATION_CHANGE_EVENT));\n}\n\nfunction subscribeToLocation(onChange: () => void) {\n window.addEventListener(\"popstate\", onChange);\n window.addEventListener(PH_LOCATION_CHANGE_EVENT, onChange);\n return () => {\n window.removeEventListener(\"popstate\", onChange);\n window.removeEventListener(PH_LOCATION_CHANGE_EVENT, onChange);\n };\n}\n\nconst readSearch = () => window.location.search;\nconst readPathname = () => window.location.pathname;\nconst readServerPathname = () => \"\";\nconst readServerSearch = () => \"\";\n\nfunction setBrowserSearch(\n update: (prev: Record<string, string>) => PHSearchUpdate,\n options?: { replace?: boolean },\n) {\n const prev = searchToRecord(window.location.search);\n const next = recordToSearch(applySearchUpdate({}, update(prev)));\n if (next === recordToSearch(prev)) return;\n // Like a router's search update, this drops the hash.\n writeBrowserUrl(\n `${window.location.pathname}${next}`,\n options?.replace,\n \"keep\",\n );\n}\n\nfunction setBrowserSearchParams(\n update: SearchParamsUpdate,\n options?: { replace?: boolean },\n) {\n setBrowserSearch((prev) => resolveSearchUpdate(prev, update), options);\n}\n\n/** The fallback without a host: `window.location` and `window.history`. Only\n * the global params carry over to another target, as with a router. */\n// Set by sync-selection.ts, which imports this module: importing it here would be a cycle.\nlet syncSelectionAfterOpen = () => {};\n\n/** @internal Selects what the browser fallback opens; sync-selection.ts sets it. */\nexport function setBrowserOpenSync(sync: () => void) {\n syncSelectionAfterOpen = sync;\n}\n\nexport const browserNavigation: PHNavigation = {\n location: () => window.location,\n hrefFor: (target) =>\n `${targetPathname(target)}${recordToSearch(globalSearch(window.location.search))}`,\n useIsCurrent(target) {\n const pathname = useSyncExternalStore(\n subscribeToLocation,\n readPathname,\n readServerPathname,\n );\n return pathname === targetPathname(target);\n },\n open: (target, options) => {\n const prev = globalSearch(window.location.search);\n const search = options?.search\n ? applySearchUpdate(prev, options.search)\n : prev;\n const entry = browserEntryState();\n writeBrowserUrl(\n `${targetPathname(target)}${recordToSearch(search)}`,\n options?.replace,\n options?.replace ? entry.phOpenedFrom : (entry.phIndex ?? 0),\n );\n // No router selects for it, and pushState fires no popstate.\n syncSelectionAfterOpen();\n },\n closeOpened: () => {\n const entry = browserEntryState();\n const index = entry.phIndex ?? 0;\n const from = openedFromIndex(entry, index);\n if (from === undefined) return false;\n window.history.go(from - index);\n return true;\n },\n setSearch: setBrowserSearch,\n useSearchParams() {\n const search = useSyncExternalStore(\n subscribeToLocation,\n readSearch,\n readServerSearch,\n );\n return useMemo(() => searchToRecord(search), [search]);\n },\n useSetSearchParams: () => setBrowserSearchParams,\n};\n\n/** True when the store has a host navigation, not the browser fallback. */\nexport function hasHostNavigation() {\n return !isServer && getPHStore()?.navigation !== undefined;\n}\n\n/** The app store's navigation, else the browser fallback. */\nexport function getPHNavigation(): PHNavigation {\n return getPHStore()?.navigation ?? browserNavigation;\n}\n\n/** The current pathname as the navigation sees it, base path included. */\nexport function getCurrentPathname() {\n return getPHNavigation().location().pathname;\n}\n\n/** Opens `target`; without `search`, a target already open is left alone. */\nexport function openTarget(\n target: PHNavigationTarget | undefined,\n options?: PHNavigateOptions,\n) {\n openTargetWith(getPHNavigation(), target, options);\n}\n\n/** Opens `target` through `navigation`, unless it is open already. */\nexport function openTargetWith(\n navigation: PHNavigation,\n target: PHNavigationTarget | undefined,\n options?: PHNavigateOptions,\n) {\n const pathname = navigation.location().pathname;\n const targetPath = targetPathname(target);\n // On any tab, the settings page is open.\n const open =\n targetPath === pathname ||\n (isSettingsTarget(target) &&\n target.settings === true &&\n pathname.startsWith(`${targetPath}/`));\n if (!options?.search && open) return;\n navigation.open(target, options);\n}\n\n/** Asks the host navigation to warm `target`; a no-op without one. */\nexport function preloadTarget(target: PHNavigationTarget | undefined) {\n if (!hasHostNavigation()) return;\n getPHNavigation().preload?.(target);\n}\n\n/** The href `target` opens at through `navigation`, base path included. */\nexport function getTargetHref(\n target: PHNavigationTarget | undefined,\n navigation: PHNavigation = getPHNavigation(),\n) {\n return navigation.hrefFor?.(target) ?? targetPathname(target);\n}\n\nexport function resolveSearchUpdate(\n prev: Record<string, string>,\n update: SearchParamsUpdate,\n): Record<string, string> {\n return typeof update === \"function\"\n ? applySearchUpdate({}, update(prev))\n : applySearchUpdate(prev, update);\n}\n\n/** Rewrites the current query params through the app store's navigation. */\nexport function setSearchParams(\n update: SearchParamsUpdate,\n options?: { replace?: boolean },\n) {\n getPHNavigation().setSearch(\n (prev) => resolveSearchUpdate(prev, update),\n options,\n );\n}\n"],"mappings":";;;;;AASA,MAAM,oBAAoB;AAG1B,SAAgB,mBAAmB,MAAc;CAC/C,OAAO,IAAI,IACT,KAAK,QAAQ,QAAQ,EAAE,GACvB,OAAO,SAAS,UAAU,WAAW,CAAC,EAAE,YAAY,IACtD,CAAC,CAAC;AACJ;;AAGA,SAAgB,mBAAmB,MAAc;CAC/C,MAAM,WAAW,WAAW,CAAC,EAAE,YAAY;CAC3C,IAAI,CAAC,KAAK,WAAW,QAAQ,GAAG,OAAO;CACvC,MAAM,OAAO,KAAK,MAAM,SAAS,MAAM;CACvC,IAAI,SAAS,SAAS,GAAG,GAAG,OAAO,IAAI;CACvC,OAAO,SAAS,MAAM,KAAK,WAAW,GAAG,IAAI,OAAO;AACtD;;;AAIA,SAAgB,sBACd,OACA;CACA,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,MAAM,KAAK,MAAM,OAAO,IAAI;AACrC;;;AAIA,SAAgB,cAAc,OAA8B;CAC1D,MAAM,EAAE,IAAI,MAAM,cAAc,MAAM;CACtC,IAAI,aAAa,cAAc,IAAI,OAAO;CAC1C,OAAO,WAAW,EAAE,IAAI,eAAe,KAAK,IAAI;AAClD;AAEA,SAAS,WAAW,IAAY;CAC9B,OAAO,SAAS,EAAE,MAAM,KAAA,KAAa,oBAAoB,EAAE;AAC7D;AAEA,SAAS,eAAe,OAA8B;CAEpD,OAAO,UAAU,OADJ,MAAM,MAAM,OAAO,QAAQ,MA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3C;CACA,OAAO,WAAW,UAAU,MAAM,KAAK,eAAe,MAAM;AAC9D;AAEA,SAAgB,oBACd,MACA,QACwB;CACxB,OAAO,OAAO,WAAW,aACrB,kBAAkB,CAAC,GAAG,OAAO,IAAI,CAAC,IAClC,kBAAkB,MAAM,MAAM;AACpC;;AAGA,SAAgB,gBACd,QACA,SACA;CACA,gBAAgB,CAAC,CAAC,WACf,SAAS,oBAAoB,MAAM,MAAM,GAC1C,OACF;AACF"}
|
|
1
|
+
{"version":3,"file":"navigation-BqphkrOB.js","names":[],"sources":["../src/utils/url.ts","../src/hooks/navigation.ts"],"sourcesContent":["import { getPHStore } from \"../hooks/ph-store.js\";\nimport type {\n DocumentDriveDocument,\n Node,\n} from \"@powerhousedao/shared/document-drive\";\nimport { isDerivedDocumentId } from \"@powerhousedao/shared/document-model\";\nimport slug from \"slug\";\n\n// Length of the base64url id a v2-required document gets.\nconst DERIVED_ID_LENGTH = 43;\n\n// Returns url with base path plus provided path\nexport function resolveUrlPathname(path: string) {\n return new URL(\n path.replace(/^\\/+/, \"\"),\n window.location.origin + (getPHStore()?.basePath ?? \"/\"),\n ).pathname;\n}\n\n/** Returns the path without a leading base path */\nexport function getPathWithoutBase(path: string) {\n const basePath = getPHStore()?.basePath ?? \"/\";\n if (!path.startsWith(basePath)) return path;\n const rest = path.slice(basePath.length);\n if (basePath.endsWith(\"/\")) return `/${rest}`;\n return rest === \"\" || rest.startsWith(\"/\") ? rest : path;\n}\n\n/** Makes a URL component for a drive.\n * @deprecated Open drives through the store's `navigation`; it builds the path. */\nexport function makeDriveUrlComponent(\n drive: DocumentDriveDocument | undefined,\n) {\n if (!drive) return \"\";\n return `/d/${slug(drive.header.slug)}`;\n}\n\n/** A drive's URL component: its slug, else its id, prefixed with the slugged\n * name as `<name>-<id>` when the id is opaque (a UUID or derived id). */\nexport function makeDriveSlug(drive: DocumentDriveDocument) {\n const { id, slug: driveSlug } = drive.header;\n if (driveSlug && driveSlug !== id) return driveSlug;\n return isOpaqueId(id) ? namedDriveSlug(drive) : id;\n}\n\nfunction isOpaqueId(id: string) {\n return findUuid(id) !== undefined || isDerivedDocumentId(id);\n}\n\nfunction namedDriveSlug(drive: DocumentDriveDocument) {\n const name = drive.state.global.name || drive.header.name;\n return namedSlug(drive, name, drive.header.id);\n}\n\nconst namedSlugs = new WeakMap<\n object,\n { name: string; id: string; value: string }\n>();\n\n// `<slugged name>-<id>`, cached per drive or node; inputs are rechecked.\nfunction namedSlug(owner: object, name: string, id: string) {\n const cached = namedSlugs.get(owner);\n if (cached?.name === name && cached.id === id) return cached.value;\n const nameSlug = name ? slug(name) : \"\";\n const value = nameSlug ? `${nameSlug}-${id}` : id;\n namedSlugs.set(owner, { name, id, value });\n return value;\n}\n\n/** The drive a URL slug names: its own slug, its id, or `<name>-<id>`. */\nexport function findDriveBySlug(\n drives: readonly DocumentDriveDocument[] | undefined,\n ref: string | undefined,\n): DocumentDriveDocument | undefined {\n if (!drives || !ref) return undefined;\n const exact = drives.find(\n (d) => d.header.slug === ref || d.header.id === ref,\n );\n if (exact) return exact;\n const id = extractDriveIdFromSlug(ref);\n if (id !== undefined) {\n const byId = drives.find((d) => d.header.id === id);\n if (byId) return byId;\n }\n // `<name>-<id>` also for a readable id, as older links wrote it.\n return drives.find(\n (d) =>\n (!d.header.slug || d.header.slug === d.header.id) &&\n ref.endsWith(d.header.id) &&\n namedDriveSlug(d) === ref,\n );\n}\n\n/**\n * Makes a URL component for a node: `<slugged name>-<id>`. The id is kept\n * verbatim, since a v2-required id is case-sensitive base64url.\n */\nexport function makeNodeSlug(node: Node | undefined) {\n if (!node) return \"\";\n return namedSlug(node, node.name, node.id);\n}\n\n/** Extracts the node slug from a path.\n *\n * The path is expected to be in the format `/d/<drive-slug>/<node-slug>`.\n */\nexport function extractNodeSlugFromPath(path: string) {\n const currentPath = getPathWithoutBase(path);\n const match = /^\\/d\\/[^/]+\\/([^/]+)$/.exec(currentPath);\n return match?.[1];\n}\n\n/** Finds a UUID in a string, used for extracting node ids from node slugs in the URL. */\nexport function findUuid(input: string | undefined) {\n if (!input) return undefined;\n const uuidRegex =\n /\\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/;\n const match = uuidRegex.exec(input);\n return match?.[0];\n}\n\n/** The v2-required document id a slug ends with, if any. */\nexport function findDerivedId(input: string | undefined) {\n if (!input || input.length < DERIVED_ID_LENGTH) return undefined;\n const start = input.length - DERIVED_ID_LENGTH;\n if (start > 0 && input[start - 1] !== \"-\") return undefined;\n const candidate = input.slice(start);\n return isDerivedDocumentId(candidate) ? candidate : undefined;\n}\n\nexport function extractNodeIdFromSlug(nodeSlug: string | undefined) {\n return findUuid(nodeSlug) ?? findDerivedId(nodeSlug);\n}\n\n/** @deprecated Route loaders resolve the node; use `extractNodeIdFromSlug`. */\nexport function extractNodeIdFromPath(path: string) {\n const nodeSlug = extractNodeSlugFromPath(path);\n const nodeId = extractNodeIdFromSlug(nodeSlug);\n return nodeId;\n}\n\n/** Extracts the drive slug from a path.\n * Used for extracting drive ids from drive slugs in the URL.\n * Expects the path to be in the format `/d/<drive-slug>`.\n */\nexport function extractDriveSlugFromPath(path: string) {\n const currentPath = getPathWithoutBase(path);\n const match = /^\\/d\\/([^/]+)/.exec(currentPath);\n return match?.[1] ?? \"\";\n}\n\nexport function extractDriveIdFromSlug(driveSlug: string | undefined) {\n return findUuid(driveSlug) ?? findDerivedId(driveSlug);\n}\n\n/** @deprecated Route loaders resolve the drive; use `extractDriveIdFromSlug`. */\nexport function extractDriveIdFromPath(path: string) {\n const driveSlug = extractDriveSlugFromPath(path);\n const driveId = extractDriveIdFromSlug(driveSlug);\n return driveId;\n}\n\n/** Creates a URL string with the given pathname, keeping the query string.\n * @deprecated The store's `navigation` keeps global params across navigations. */\nexport function createUrlWithPreservedParams(pathname: string): string {\n const search = window.location.search;\n return search ? `${pathname}${search}` : pathname;\n}\n","import type {\n PHNavigateOptions,\n PHNavigation,\n PHNavigationTarget,\n PHSearchUpdate,\n PHSettingsTarget,\n SearchParamsUpdate,\n} from \"@powerhousedao/reactor-browser\";\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport { resolveUrlPathname } from \"../utils/url.js\";\nimport { getPHStore } from \"./ph-store.js\";\n\nconst isServer = typeof window === \"undefined\";\n\n/** Fired on `window` when the fallback navigator rewrites the URL. */\nexport const PH_LOCATION_CHANGE_EVENT = \"ph:locationchange\";\n\n/** Params read at boot or app-wide; they survive every navigation. Others,\n * e.g. a document's own, are dropped when the target changes. */\nexport const GLOBAL_SEARCH_PARAMS = [\n // A remote drive to add on boot.\n \"driveUrl\",\n // The theme override read by the inline theme boot script.\n \"theme\",\n // Embedded mode, which hides Connect's chrome.\n \"embed\",\n // Log level override for the feature-flag provider.\n \"LOG_LEVEL\",\n // The reactor worker runtime flag override.\n \"reactorWorker\",\n] as const;\n\n/** Feature flags are any `FEATURE_*` param, so they are retained by prefix. */\nexport const FEATURE_FLAG_PARAM_PREFIX = \"FEATURE_\";\n\n/** Whether `key` is a param every navigation keeps. */\nexport function isGlobalSearchParam(key: string) {\n return (\n (GLOBAL_SEARCH_PARAMS as readonly string[]).includes(key) ||\n key.startsWith(FEATURE_FLAG_PARAM_PREFIX)\n );\n}\n\nfunction globalSearch(search: string) {\n return Object.fromEntries(\n Object.entries(searchToRecord(search)).filter(([key]) =>\n isGlobalSearchParam(key),\n ),\n );\n}\n\n/** A query string's params; repeated keys keep their last value. */\nexport function searchToRecord(search: string): Record<string, string> {\n return Object.fromEntries(new URLSearchParams(search));\n}\n\n/** `prev` with `update` applied; an `undefined` value removes the key. */\nexport function applySearchUpdate(\n prev: Record<string, string>,\n update: PHSearchUpdate,\n): Record<string, string> {\n const next = { ...prev };\n for (const [key, value] of Object.entries(update)) {\n if (value === undefined) delete next[key];\n else next[key] = value;\n }\n return next;\n}\n\n/** `params` as a query string, with an empty value as a bare key: `history`, not `history=`. */\nexport function searchParamsToString(params: URLSearchParams) {\n return params.toString().replace(/=(?=&|$)/g, \"\");\n}\n\n/** `?a=1&b=2`, or an empty string for no params. */\nexport function recordToSearch(record: Record<string, string>) {\n const search = searchParamsToString(new URLSearchParams(record));\n return search ? `?${search}` : \"\";\n}\n\n/** The settings page's path; its tabs are below it. */\nexport const SETTINGS_PATH = \"/settings\";\n\nexport function isSettingsTarget(\n target: PHNavigationTarget | undefined,\n): target is PHSettingsTarget {\n return !!target && \"settings\" in target;\n}\n\n/** The pathname a target opens at, base path included. */\nexport function targetPathname(target: PHNavigationTarget | undefined) {\n if (!target) return resolveUrlPathname(\"/\");\n if (isSettingsTarget(target)) {\n const { settings } = target;\n return resolveUrlPathname(\n settings === true ? SETTINGS_PATH : `${SETTINGS_PATH}/${settings}`,\n );\n }\n const { driveSlug, nodeSlug } = target;\n return resolveUrlPathname(\n nodeSlug ? `/d/${driveSlug}/${nodeSlug}` : `/d/${driveSlug}`,\n );\n}\n\n/** History state key: the index of the entry a document was opened from. */\nexport const OPENED_FROM_STATE_KEY = \"phOpenedFrom\";\n\n// The fallback numbers its own entries; a router's history has its own index.\ntype BrowserEntryState = { phIndex?: number; phOpenedFrom?: number };\n\nfunction browserEntryState(): BrowserEntryState {\n const state: unknown = window.history.state;\n return state && typeof state === \"object\" ? (state as BrowserEntryState) : {};\n}\n\n/** The index to go back to from `index`, when it lies before it. */\nexport function openedFromIndex(\n state: object | undefined,\n index: number,\n): number | undefined {\n const from = (state as Record<string, unknown> | undefined)?.[\n OPENED_FROM_STATE_KEY\n ];\n return typeof from === \"number\" && from >= 0 && from < index\n ? from\n : undefined;\n}\n\n// `openedFrom` \"keep\" carries the current entry's, as an in-document write does.\nfunction writeBrowserUrl(\n href: string,\n replace: boolean | undefined,\n openedFrom: number | \"keep\" | undefined,\n) {\n const prev = browserEntryState();\n const index = prev.phIndex ?? 0;\n const from = openedFrom === \"keep\" ? prev.phOpenedFrom : openedFrom;\n // Keeps the entry's state, e.g. a router's history key, on a replace.\n if (replace) {\n window.history.replaceState(\n { ...prev, phIndex: index, phOpenedFrom: from },\n \"\",\n href,\n );\n } else {\n window.history.pushState(\n { phIndex: index + 1, phOpenedFrom: from },\n \"\",\n href,\n );\n }\n window.dispatchEvent(new Event(PH_LOCATION_CHANGE_EVENT));\n}\n\nfunction subscribeToLocation(onChange: () => void) {\n window.addEventListener(\"popstate\", onChange);\n window.addEventListener(PH_LOCATION_CHANGE_EVENT, onChange);\n return () => {\n window.removeEventListener(\"popstate\", onChange);\n window.removeEventListener(PH_LOCATION_CHANGE_EVENT, onChange);\n };\n}\n\nconst readSearch = () => window.location.search;\nconst readPathname = () => window.location.pathname;\nconst readServerPathname = () => \"\";\nconst readServerSearch = () => \"\";\n\nfunction setBrowserSearch(\n update: (prev: Record<string, string>) => PHSearchUpdate,\n options?: { replace?: boolean },\n) {\n const prev = searchToRecord(window.location.search);\n const next = recordToSearch(applySearchUpdate({}, update(prev)));\n if (next === recordToSearch(prev)) return;\n // Like a router's search update, this drops the hash.\n writeBrowserUrl(\n `${window.location.pathname}${next}`,\n options?.replace,\n \"keep\",\n );\n}\n\nfunction setBrowserSearchParams(\n update: SearchParamsUpdate,\n options?: { replace?: boolean },\n) {\n setBrowserSearch((prev) => resolveSearchUpdate(prev, update), options);\n}\n\n/** The fallback without a host: `window.location` and `window.history`. Only\n * the global params carry over to another target, as with a router. */\n// Set by sync-selection.ts, which imports this module: importing it here would be a cycle.\nlet syncSelectionAfterOpen = () => {};\n\n/** @internal Selects what the browser fallback opens; sync-selection.ts sets it. */\nexport function setBrowserOpenSync(sync: () => void) {\n syncSelectionAfterOpen = sync;\n}\n\nexport const browserNavigation: PHNavigation = {\n location: () => window.location,\n hrefFor: (target) =>\n `${targetPathname(target)}${recordToSearch(globalSearch(window.location.search))}`,\n useIsCurrent(target) {\n const pathname = useSyncExternalStore(\n subscribeToLocation,\n readPathname,\n readServerPathname,\n );\n return pathname === targetPathname(target);\n },\n open: (target, options) => {\n const prev = globalSearch(window.location.search);\n const search = options?.search\n ? applySearchUpdate(prev, options.search)\n : prev;\n const entry = browserEntryState();\n writeBrowserUrl(\n `${targetPathname(target)}${recordToSearch(search)}`,\n options?.replace,\n options?.replace ? entry.phOpenedFrom : (entry.phIndex ?? 0),\n );\n // No router selects for it, and pushState fires no popstate.\n syncSelectionAfterOpen();\n },\n closeOpened: () => {\n const entry = browserEntryState();\n const index = entry.phIndex ?? 0;\n const from = openedFromIndex(entry, index);\n if (from === undefined) return false;\n window.history.go(from - index);\n return true;\n },\n setSearch: setBrowserSearch,\n useSearchParams() {\n const search = useSyncExternalStore(\n subscribeToLocation,\n readSearch,\n readServerSearch,\n );\n return useMemo(() => searchToRecord(search), [search]);\n },\n useSetSearchParams: () => setBrowserSearchParams,\n};\n\n/** True when the store has a host navigation, not the browser fallback. */\nexport function hasHostNavigation() {\n return !isServer && getPHStore()?.navigation !== undefined;\n}\n\n/** The app store's navigation, else the browser fallback. */\nexport function getPHNavigation(): PHNavigation {\n return getPHStore()?.navigation ?? browserNavigation;\n}\n\n/** The current pathname as the navigation sees it, base path included. */\nexport function getCurrentPathname() {\n return getPHNavigation().location().pathname;\n}\n\n/** Opens `target`; without `search`, a target already open is left alone. */\nexport function openTarget(\n target: PHNavigationTarget | undefined,\n options?: PHNavigateOptions,\n) {\n openTargetWith(getPHNavigation(), target, options);\n}\n\n/** Opens `target` through `navigation`, unless it is open already. */\nexport function openTargetWith(\n navigation: PHNavigation,\n target: PHNavigationTarget | undefined,\n options?: PHNavigateOptions,\n) {\n const pathname = navigation.location().pathname;\n const targetPath = targetPathname(target);\n // On any tab, the settings page is open.\n const open =\n targetPath === pathname ||\n (isSettingsTarget(target) &&\n target.settings === true &&\n pathname.startsWith(`${targetPath}/`));\n if (!options?.search && open) return;\n navigation.open(target, options);\n}\n\n/** Asks the host navigation to warm `target`; a no-op without one. */\nexport function preloadTarget(target: PHNavigationTarget | undefined) {\n if (!hasHostNavigation()) return;\n getPHNavigation().preload?.(target);\n}\n\n/** The href `target` opens at through `navigation`, base path included. */\nexport function getTargetHref(\n target: PHNavigationTarget | undefined,\n navigation: PHNavigation = getPHNavigation(),\n) {\n return navigation.hrefFor?.(target) ?? targetPathname(target);\n}\n\nexport function resolveSearchUpdate(\n prev: Record<string, string>,\n update: SearchParamsUpdate,\n): Record<string, string> {\n return typeof update === \"function\"\n ? applySearchUpdate({}, update(prev))\n : applySearchUpdate(prev, update);\n}\n\n/** Rewrites the current query params through the app store's navigation. */\nexport function setSearchParams(\n update: SearchParamsUpdate,\n options?: { replace?: boolean },\n) {\n getPHNavigation().setSearch(\n (prev) => resolveSearchUpdate(prev, update),\n options,\n );\n}\n"],"mappings":";;;;;AASA,MAAM,oBAAoB;AAG1B,SAAgB,mBAAmB,MAAc;CAC/C,OAAO,IAAI,IACT,KAAK,QAAQ,QAAQ,EAAE,GACvB,OAAO,SAAS,UAAU,WAAW,CAAC,EAAE,YAAY,IACtD,CAAC,CAAC;AACJ;;AAGA,SAAgB,mBAAmB,MAAc;CAC/C,MAAM,WAAW,WAAW,CAAC,EAAE,YAAY;CAC3C,IAAI,CAAC,KAAK,WAAW,QAAQ,GAAG,OAAO;CACvC,MAAM,OAAO,KAAK,MAAM,SAAS,MAAM;CACvC,IAAI,SAAS,SAAS,GAAG,GAAG,OAAO,IAAI;CACvC,OAAO,SAAS,MAAM,KAAK,WAAW,GAAG,IAAI,OAAO;AACtD;;;AAIA,SAAgB,sBACd,OACA;CACA,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO,MAAM,KAAK,MAAM,OAAO,IAAI;AACrC;;;AAIA,SAAgB,cAAc,OAA8B;CAC1D,MAAM,EAAE,IAAI,MAAM,cAAc,MAAM;CACtC,IAAI,aAAa,cAAc,IAAI,OAAO;CAC1C,OAAO,WAAW,EAAE,IAAI,eAAe,KAAK,IAAI;AAClD;AAEA,SAAS,WAAW,IAAY;CAC9B,OAAO,SAAS,EAAE,MAAM,KAAA,KAAa,oBAAoB,EAAE;AAC7D;AAEA,SAAS,eAAe,OAA8B;CAE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M;AACpC;;AAGA,SAAgB,cACd,QACA,aAA2B,gBAAgB,GAC3C;CACA,OAAO,WAAW,UAAU,MAAM,KAAK,eAAe,MAAM;AAC9D;AAEA,SAAgB,oBACd,MACA,QACwB;CACxB,OAAO,OAAO,WAAW,aACrB,kBAAkB,CAAC,GAAG,OAAO,IAAI,CAAC,IAClC,kBAAkB,MAAM,MAAM;AACpC;;AAGA,SAAgB,gBACd,QACA,SACA;CACA,gBAAgB,CAAC,CAAC,WACf,SAAS,oBAAoB,MAAM,MAAM,GAC1C,OACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/reactor-browser",
|
|
3
|
-
"version": "6.2.3-dev.
|
|
3
|
+
"version": "6.2.3-dev.71",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"sideEffects": false,
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@ai-sdk/openai-compatible": "3.0.37",
|
|
67
|
-
"@powerhousedao/analytics-engine-browser": "6.2.3-dev.
|
|
68
|
-
"@powerhousedao/analytics-engine-core": "6.2.3-dev.
|
|
69
|
-
"@powerhousedao/reactor": "6.2.3-dev.
|
|
70
|
-
"@powerhousedao/reactor-attachments": "6.2.3-dev.
|
|
71
|
-
"@powerhousedao/reactor-drive": "6.2.3-dev.
|
|
72
|
-
"@powerhousedao/shared": "6.2.3-dev.
|
|
73
|
-
"@renown/sdk": "6.2.3-dev.
|
|
67
|
+
"@powerhousedao/analytics-engine-browser": "6.2.3-dev.71",
|
|
68
|
+
"@powerhousedao/analytics-engine-core": "6.2.3-dev.71",
|
|
69
|
+
"@powerhousedao/reactor": "6.2.3-dev.71",
|
|
70
|
+
"@powerhousedao/reactor-attachments": "6.2.3-dev.71",
|
|
71
|
+
"@powerhousedao/reactor-drive": "6.2.3-dev.71",
|
|
72
|
+
"@powerhousedao/shared": "6.2.3-dev.71",
|
|
73
|
+
"@renown/sdk": "6.2.3-dev.71",
|
|
74
74
|
"@tanstack/react-query": "^5.49.2",
|
|
75
75
|
"ai": "7.0.83",
|
|
76
76
|
"change-case": "5.4.4",
|
|
77
|
-
"document-model": "6.2.3-dev.
|
|
77
|
+
"document-model": "6.2.3-dev.71",
|
|
78
78
|
"graphql-request": "7.4.0",
|
|
79
79
|
"graphql-ws": "6.0.7",
|
|
80
80
|
"kysely": "0.28.16",
|