aberdeen 1.17.0 → 2.0.0
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/src/aberdeen.d.ts +928 -944
- package/dist/src/aberdeen.js +1693 -1704
- package/dist/src/aberdeen.js.map +3 -3
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +10 -0
- package/dist/src/prediction.d.ts +7 -4
- package/dist/src/prediction.js +18 -23
- package/dist/src/prediction.js.map +3 -3
- package/dist/src/route.d.ts +112 -99
- package/dist/src/route.js +254 -254
- package/dist/src/route.js.map +3 -3
- package/dist/src/server-dom.d.ts +158 -0
- package/dist/src/server-dom.js +458 -0
- package/dist/src/server-dom.js.map +10 -0
- package/dist/src/server.d.ts +55 -0
- package/dist/src/server.js +25 -0
- package/dist/src/server.js.map +10 -0
- package/dist/src/transitions.js +7 -4
- package/dist/src/transitions.js.map +3 -3
- package/dist/tests/environment.d.ts +24 -0
- package/dist/tests/{fakedom.js → environment.js} +239 -288
- package/dist/tests/environment.js.map +11 -0
- package/dist/tests/helpers.d.ts +15 -3
- package/dist/tests/helpers.js +277 -306
- package/dist/tests/helpers.js.map +6 -5
- package/dist-docs/Tutorial/index.html +30 -30
- package/dist-docs/aberdeen/Aberdeen/index.html +350 -0
- package/dist-docs/aberdeen/InitOptions/index.html +4 -0
- package/dist-docs/aberdeen/KeyToString/index.html +2 -0
- package/dist-docs/aberdeen/PromiseProxy/index.html +6 -6
- package/dist-docs/aberdeen/SortKeyType/index.html +2 -0
- package/dist-docs/aberdeen/TargetType/index.html +2 -0
- package/dist-docs/aberdeen/ValueRef/index.html +2 -0
- package/dist-docs/aberdeen/WindowLike/index.html +5 -0
- package/dist-docs/aberdeen/{clone → createA}/index.html +10 -5
- package/dist-docs/aberdeen/index.html +13 -54
- package/dist-docs/assets/aberdeen/aberdeen.d.ts +928 -944
- package/dist-docs/assets/aberdeen/aberdeen.js +1693 -1704
- package/dist-docs/assets/aberdeen/aberdeen.js.map +3 -3
- package/dist-docs/assets/aberdeen/index.d.ts +12 -0
- package/dist-docs/assets/aberdeen/index.js +11 -0
- package/dist-docs/assets/aberdeen/index.js.map +10 -0
- package/dist-docs/assets/aberdeen/prediction.d.ts +7 -4
- package/dist-docs/assets/aberdeen/prediction.js +18 -23
- package/dist-docs/assets/aberdeen/prediction.js.map +3 -3
- package/dist-docs/assets/aberdeen/route.d.ts +112 -99
- package/dist-docs/assets/aberdeen/route.js +254 -254
- package/dist-docs/assets/aberdeen/route.js.map +3 -3
- package/dist-docs/assets/aberdeen/server-dom.d.ts +158 -0
- package/dist-docs/assets/aberdeen/server-dom.js +458 -0
- package/dist-docs/assets/aberdeen/server-dom.js.map +10 -0
- package/dist-docs/assets/aberdeen/server.d.ts +55 -0
- package/dist-docs/assets/aberdeen/server.js +25 -0
- package/dist-docs/assets/aberdeen/server.js.map +10 -0
- package/dist-docs/assets/aberdeen/transitions.js +7 -4
- package/dist-docs/assets/aberdeen/transitions.js.map +3 -3
- package/dist-docs/assets/navigation.js +1 -1
- package/dist-docs/assets/search.js +1 -1
- package/dist-docs/dispatcher/Dispatcher/index.html +5 -6
- package/dist-docs/dispatcher/MATCH_FAILED/index.html +2 -2
- package/dist-docs/dispatcher/MATCH_REST/index.html +2 -2
- package/dist-docs/dispatcher/index.html +2 -2
- package/dist-docs/hierarchy.html +1 -1
- package/dist-docs/index-1/index.html +2 -0
- package/dist-docs/index.html +2 -2
- package/dist-docs/media/CHANGELOG.md +14 -2
- package/dist-docs/modules.html +1 -1
- package/dist-docs/prediction/applyCanon/index.html +4 -3
- package/dist-docs/prediction/applyPrediction/index.html +4 -3
- package/dist-docs/prediction/index.html +2 -2
- package/dist-docs/route/Route/index.html +9 -9
- package/dist-docs/route/RouteApi/index.html +60 -0
- package/dist-docs/route/index.html +6 -15
- package/dist-docs/route/init/index.html +5 -0
- package/dist-docs/server/RenderToStringOptions/index.html +6 -0
- package/dist-docs/server/RenderToStringResult/index.html +6 -0
- package/dist-docs/server/index.html +4 -0
- package/dist-docs/server/renderToString/index.html +6 -0
- package/dist-docs/sitemap.xml +51 -155
- package/dist-docs/transitions/grow/index.html +2 -2
- package/dist-docs/transitions/index.html +2 -2
- package/dist-docs/transitions/shrink/index.html +2 -2
- package/package.json +17 -7
- package/skill/SKILL.md +28 -28
- package/skill/aberdeen.md +471 -3448
- package/skill/dispatcher.md +6 -16
- package/skill/prediction.md +17 -5
- package/skill/route.md +95 -77
- package/skill/transitions.md +3 -3
- package/src/aberdeen.ts +1226 -740
- package/src/index.ts +13 -0
- package/src/prediction.ts +25 -24
- package/src/route.ts +192 -142
- package/src/server-dom.ts +508 -0
- package/src/server.ts +74 -0
- package/src/transitions.ts +9 -3
- package/dist/tests/fakedom.d.ts +0 -9
- package/dist/tests/fakedom.js.map +0 -10
- package/dist-docs/aberdeen/A/index.html +0 -115
- package/dist-docs/aberdeen/CUSTOM_DUMP/index.html +0 -7
- package/dist-docs/aberdeen/NO_COPY/index.html +0 -2
- package/dist-docs/aberdeen/OPAQUE/index.html +0 -12
- package/dist-docs/aberdeen/clean/index.html +0 -11
- package/dist-docs/aberdeen/copy/index.html +0 -22
- package/dist-docs/aberdeen/count/index.html +0 -7
- package/dist-docs/aberdeen/cssVars/index.html +0 -11
- package/dist-docs/aberdeen/darkMode/index.html +0 -9
- package/dist-docs/aberdeen/default/index.html +0 -341
- package/dist-docs/aberdeen/derive/index.html +0 -18
- package/dist-docs/aberdeen/disableCreateDestroy/index.html +0 -6
- package/dist-docs/aberdeen/dump/index.html +0 -11
- package/dist-docs/aberdeen/insertCss/index.html +0 -30
- package/dist-docs/aberdeen/insertGlobalCss/index.html +0 -19
- package/dist-docs/aberdeen/invertString/index.html +0 -13
- package/dist-docs/aberdeen/isEmpty/index.html +0 -12
- package/dist-docs/aberdeen/map/index.html +0 -26
- package/dist-docs/aberdeen/merge/index.html +0 -11
- package/dist-docs/aberdeen/mount/index.html +0 -17
- package/dist-docs/aberdeen/multiMap/index.html +0 -28
- package/dist-docs/aberdeen/onEach/index.html +0 -19
- package/dist-docs/aberdeen/partition/index.html +0 -36
- package/dist-docs/aberdeen/peek/index.html +0 -40
- package/dist-docs/aberdeen/proxy/index.html +0 -35
- package/dist-docs/aberdeen/ref/index.html +0 -13
- package/dist-docs/aberdeen/runQueue/index.html +0 -13
- package/dist-docs/aberdeen/setErrorHandler/index.html +0 -16
- package/dist-docs/aberdeen/setSpacingCssVars/index.html +0 -8
- package/dist-docs/aberdeen/unmountAll/index.html +0 -5
- package/dist-docs/aberdeen/unproxy/index.html +0 -11
- package/dist-docs/route/back/index.html +0 -4
- package/dist-docs/route/current/index.html +0 -2
- package/dist-docs/route/go/index.html +0 -14
- package/dist-docs/route/interceptLinks/index.html +0 -8
- package/dist-docs/route/matchCurrent/index.html +0 -10
- package/dist-docs/route/persistScroll/index.html +0 -6
- package/dist-docs/route/push/index.html +0 -6
- package/dist-docs/route/setLog/index.html +0 -3
- package/dist-docs/route/up/index.html +0 -5
package/dist/src/route.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/route.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import A, {leakScope} from \"./aberdeen.js\";\n\ntype NavType = \"load\" | \"back\" | \"forward\" | \"go\" | \"push\";\n\n/**\n* The class for the global `route` object.\n*/\nexport interface Route {\n\t/** The current path of the URL as a string. For instance `\"/\"` or `\"/users/123/feed\"`. Paths are normalized to always start with a `/` and never end with a `/` (unless it's the root path). */\n\tpath: string;\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', '123', 'feed']` (for `\"/users/123/feed\"`). */\n\tp: string[];\n\t/** The hash fragment including the leading `#`, or an empty string. For instance `\"#my_section\"` or `\"\"`. */\n\thash: string;\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\"}`. */\n\tsearch: Record<string, string>;\n\t/** An object to be used for any additional data you want to associate with the current page. Data should be JSON-compatible. */\n\tstate: Record<string, any>;\n\t/** The navigation depth of the current session. Starts at 1. Writing to this property has no effect. */\n\tdepth: number;\n\t/** The navigation action that got us to this page. Writing to this property has no effect.\n\t- `\"load\"`: An initial page load.\n\t- `\"back\"` or `\"forward\"`: When we navigated backwards or forwards in the stack.\n\t- `\"go\"`: When we added a new page on top of the stack.\n\t- `\"push\"`: When we added a new page on top of the stack, merging with the current page.\n\tMostly useful for page transition animations. Writing to this property has no effect.\n\t*/\n\tnav: NavType;\n}\n\nlet log: (...args: any) => void = () => {};\n\n/**\n * Configure logging on route changes.\n * @param value `true` to enable logging to console, `false` to disable logging, or a custom logging function. Defaults to `false`.\n */\nexport function setLog(value: boolean | ((...args: any[]) => void)) {\n\tif (value === true) {\n\t\tlog = console.log.bind(console, 'aberdeen router');\n\t} else if (value === false) {\n\t\tlog = () => {};\n\t} else {\n\t\tlog = value;\n\t}\n}\n\ndeclare const ABERDEEN_FAKE_WINDOW: Window | undefined;\nconst windowE = typeof ABERDEEN_FAKE_WINDOW !== 'undefined'? ABERDEEN_FAKE_WINDOW : window;\nconst locationE = windowE.location;\nconst historyE = windowE.history;\n\nfunction getRouteFromBrowser(): Route {\n\treturn toCanonRoute({\n\t\tpath: locationE.pathname,\n\t\thash: locationE.hash,\n\t\tsearch: Object.fromEntries(new URLSearchParams(locationE.search)),\n\t\tstate: \thistoryE.state?.state || {},\n\t}, \"load\", (historyE.state?.stack?.length || 0) + 1);\n}\n\n/**\n* Deep compare `a` and `b`. If `partial` is true, objects contained in `b` may be a subset\n* of their counterparts in `a` and still be considered equal.\n*/\nfunction equal(a: any, b: any, partial: boolean): boolean {\n\tif (a===b) return true;\n\tif (typeof a !== \"object\" || !a || typeof b !== \"object\" || !b) return false; // otherwise they would have been equal\n\tif (a.constructor !== b.constructor) return false;\n\tif (b instanceof Array) {\n\t\tif (a.length !== b.length) return false;\n\t\tfor(let i = 0; i < b.length; i++) {\n\t\t\tif (!equal(a[i], b[i], partial)) return false;\n\t\t}\n\t} else {\n\t\tfor(const k of Object.keys(b)) {\n\t\t\tif (!equal(a[k], b[k], partial)) return false;\n\t\t}\n\t\tif (!partial) {\n\t\t\tfor(const k of Object.keys(a)) {\n\t\t\t\tif (!b.hasOwnProperty(k)) return false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction getUrl(target: Route) {\n\tconst search = new URLSearchParams(target.search).toString();\n\treturn (search ? `${target.path}?${search}` : target.path) + target.hash;\n}\n\nfunction toCanonRoute(target: Partial<Route>, nav: NavType, depth: number): Route {\n\tlet path = target.path || (target.p || []).join(\"/\") || \"/\";\n\tpath = (\"\"+path).replace(/\\/+$/, \"\");\n\tif (!path.startsWith(\"/\")) path = `/${path}`;\n\t\n\treturn {\n\t\tpath,\n\t\thash: target.hash && target.hash !==\"#\" ? (target.hash.startsWith(\"#\") ? target.hash : \"#\" + target.hash) : \"\",\n\t\tp: path.length > 1 ? path.slice(1).replace(/\\/+$/, \"\").split(\"/\") : [],\n\t\tnav,\n\t\tsearch: typeof target.search === 'object' && target.search ? A.clone(target.search) : {},\n\t\tstate: typeof target.state === 'object' && target.state ? A.clone(target.state) : {},\n\t\tdepth,\n\t};\n}\n\n\ntype RouteTarget = string | (string|number)[] | Partial<Omit<Omit<Route,\"p\">,\"search\"> & {\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', 123, 'feed']` (for `\"/users/123/feed\"`). Values may be integers but will be converted to strings.*/\n\tp: (string|number)[],\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\", c: 42}`. Values may be integers but will be converted to strings. */\n\tsearch: Record<string,string|number>,\n}>;\n\nfunction targetToPartial(target: RouteTarget, undefinedOnExternal: true): Partial<Route> | undefined;\nfunction targetToPartial(target: RouteTarget): Partial<Route>;\n\n\nfunction targetToPartial(target: RouteTarget, undefinedOnExternal: boolean=false) {\n\t// Convert shortcut values to objects\n\tif (typeof target === 'string') {\n\t\t// Parse using URL to handle both absolute and relative paths correctly\t\t\n\t\tconst url = new URL(target, locationE.href);\n\t\tif (url.host !== locationE.host) {\n\t\t\tif (undefinedOnExternal) return;\n\t\t\tthrow new Error(`Unexpected external URL: ${url.host} != ${locationE.host}`);\n\t\t}\n\t\ttarget = {\n\t\t\tpath: url.pathname,\n\t\t\tsearch: Object.fromEntries(url.searchParams),\n\t\t\thash: url.hash,\n\t\t};\n\t} else if (target instanceof Array) {\n\t\ttarget = {p: target};\n\t}\n\t// Convert numbers in p and search to strings\n\tif (target.p) {\n\t\ttarget.p = target.p.map(String);\n\t}\n\tif (target.search) {\n\t\tfor(const key of Object.keys(target.search)) {\n\t\t\ttarget.search[key] = String(target.search[key]);\n\t\t}\n\t}\n\treturn target as Partial<Route>;\n}\n\n\n/**\n* Navigate to a new URL by pushing a new history entry.\n* \n* Note that this happens synchronously, immediately updating `route` and processing any reactive updates based on that.\n* \n* @param target A subset of the {@link Route} properties to navigate to. If neither `p` nor `path` is given, the current path is used. For other properties, an empty/default value is assumed if not given. For convenience:\n* - You may pass a string instead of an object, which is interpreted as the `path`.\n* - You may pass an array instead of an object, which is interpreted as the `p` array.\n* - If you pass `p`, it may contain numbers, which will be converted to strings.\n* - If you pass `search`, its values may be numbers, which will be converted to strings.\n* \n* Examples:\n* ```js\n* // Navigate to /users/123\n* route.go(\"/users/123\");\n* \n* // Navigate to /users/123?tab=feed#top\n* route.go({p: [\"users\", 123], search: {tab: \"feed\"}, hash: \"top\"});\n* ```\n*/\nexport function go(target: RouteTarget, nav: NavType = \"go\"): void {\n\tpendingGoOffset = 0;\n\tconst stack: string[] = historyE.state?.stack || [];\n\n\tprevStack = stack.concat(JSON.stringify(A.unproxy(current)));\n\t\n\tconst newRoute: Route = toCanonRoute(targetToPartial(target), nav, prevStack.length + 1);\n\tA.copy(current, newRoute);\n\t\n\tlog(nav, newRoute);\n\thistoryE.pushState({state: newRoute.state, stack: prevStack}, \"\", getUrl(newRoute));\n\t\n\tA.runQueue();\n}\n\n/**\n * Returns `true` if the current route matches `target`.\n *\n * Path must match exactly. Any search params specified in `target` must be present\n * in the current URL, but extra params in the current URL are allowed.\n *\n * Reactive: only reevaluates when the path changes to/from the target path, and\n * when target k/v search pairs are (un)set.\n * \n * Primary usage: 'active' status for menu items.\n *\n * @example\n * ```js\n * // This example assumes interceptLinks() has been called\n * A('a.my-button text=Users href=/users .is-active=', route.matchCurrent('/users'));\n * \n * // Alternatively a route object can be given\n * route.matchCurrent({path: '/users', search: {tab: 'profile'}});\n * ```\n */\nexport function matchCurrent(target: RouteTarget): boolean {\n\tconst partial = targetToPartial(target, true);\n\tif (!partial) return false; // External link\n\n\tif (partial.path != null || partial.p != null) {\n\t\tlet path = partial.path || (partial.p || []).join(\"/\") || \"/\";\n\t\tpath = (\"\"+path).replace(/\\/+$/, \"\");\n\t\tif (!path.startsWith(\"/\")) path = `/${path}`;\n\t\tif (!currentRouteParts[path]) return false;\n\t}\n\n\tif (partial.search) {\n\t\tfor(const [k,v] of Object.entries(partial.search)) {\n\t\t\tif (!currentRouteParts[`${k}=${v}`]) return false;\n\t\t}\n\t}\n\treturn true;\n}\n\n/**\n * Modify the current route by merging `target` into it (using {@link aberdeen.merge | A.merge}), pushing a new history entry.\n * \n * This is useful for things like opening modals or side panels, where you want a browser back action to return to the previous state.\n * \n * @param target Same as for {@link go}, but merged into the current route instead deleting all state.\n * @param nav The navigation type to use. Defaults to `undefined`, meaning the navigation type is unchanged from the current route,\n * preventing unwanted page transition animations.\n */\nexport function push(target: RouteTarget, nav?: NavType): void {\n\tconst c = A.clone(A.unproxy(current));\n\tA.merge(c, targetToPartial(target));\n\tgo(c, nav || c.nav);\n}\n\n/**\n * Try to go back in history to the first entry that matches the given target. If none is found, the given state will replace the current page. This is useful for \"cancel\" or \"close\" actions that should return to the previous page if possible, but create a new page if not (for instance when arriving at the current page through a direct link).\n * \n * Consider using {@link up} to go up in the path hierarchy.\n * \n * @param target The target route to go back to. May be a subset of {@link Route}, or a string (for `path`), or an array of strings (for `p`).\n */\nexport function back(target: RouteTarget = {}): void {\n\tconst partial = targetToPartial(target);\n\tconst stack: string[] = historyE.state?.stack || [];\n\tconst effectiveLen = stack.length + pendingGoOffset;\n\tfor(let i = effectiveLen - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (equal(histRoute, partial, true)) {\n\t\t\tconst pages = i - effectiveLen;\n\t\t\tlog(`back`, pages, histRoute);\n\t\t\tscheduleHistoryGo(pages);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst newRoute = toCanonRoute(partial, \"back\", effectiveLen + 1);\n\tlog(`back not found, replacing`, partial);\n\tA.copy(current, newRoute);\n}\n\n/**\n* Navigate up in the path hierarchy, by going back to the first history entry\n* that has a shorter path than the current one. If there's none, we just shorten\n* the current path.\n* \n* Note that going back in browser history happens asynchronously, so `route` will not be updated immediately.\n*/\nexport function up(stripCount: number = 1): void {\n\tconst currentP = A.unproxy(current).p;\n\tconst stack: string[] = historyE.state?.stack || [];\n\tconst effectiveLen = stack.length + pendingGoOffset;\n\tfor(let i = effectiveLen - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (histRoute.p.length < currentP.length && equal(histRoute.p, currentP.slice(0, histRoute.p.length), false)) {\n\t\t\t// This route is shorter and matches the start of the current path\n\t\t\tlog(`up to ${i+1} / ${effectiveLen}`, histRoute);\n\t\t\tscheduleHistoryGo(i - effectiveLen);\n\t\t\treturn;\n\t\t}\n\t}\n\t// Replace current route with /\n\tconst newRoute = toCanonRoute({p: currentP.slice(0, currentP.length - stripCount)}, \"back\", effectiveLen + 1);\n\tlog(`up not found, replacing`, newRoute);\n\tA.copy(current, newRoute);\n}\n\n\nlet prevStack: string[];\n\n// Track pending historyE.go() offset. Multiple back()/up() calls before the event loop\n// processes them are batched into a single historyE.go() via queueMicrotask.\nlet pendingGoOffset = 0;\n\nfunction scheduleHistoryGo(delta: number) {\n\tpendingGoOffset += delta;\n\tsetTimeout(() => {\n\t\tif (pendingGoOffset) {\n\t\t\tconst offset = pendingGoOffset;\n\t\t\tpendingGoOffset = 0;\n\t\t\thistoryE.go(offset);\n\t\t}\n\t}, 0);\n}\n\n/**\n* The global {@link Route} object reflecting the current URL and browser history state. Changes you make to this affect the current browser history item (modifying the URL if needed).\n*/\nexport const current: Route = A.proxy({}) as Route;\n\n// Proxied object with keys for the current path and \"k=v\" search pairs.\n// Used by matchCurrent to subscribe only to relevant route changes.\nconst currentRouteParts = A.proxy({} as Record<string,true>);\n\n/**\n * Reset the router to its initial state, based on the current browser state. Intended for testing purposes only.\n * @internal\n * */\nexport function reset() {\n\tprevStack = historyE.state?.stack || [];\n\tconst initRoute = getRouteFromBrowser();\n\tlog('initial', initRoute);\n\tA.copy(A.unproxy(current), initRoute);\n}\nreset();\n\n// Handle browser history back and forward\nwindowE.addEventListener(\"popstate\", function(event: PopStateEvent) {\n\tpendingGoOffset = 0;\n\tconst newRoute = getRouteFromBrowser();\n\t\n\t// If the stack length changes, and at least the top-most shared entry is the same,\n\t// we'll interpret this as a \"back\" or \"forward\" navigation.\n\tconst stack: string[] = historyE.state?.stack || [];\n\tif (stack.length !== prevStack.length) {\n\t\tconst maxIndex = Math.min(prevStack.length, stack.length) - 1;\n\t\tif (maxIndex < 0 || stack[maxIndex] === prevStack[maxIndex]) {\n\t\t\tnewRoute.nav = stack.length < prevStack.length ? \"back\" : \"forward\";\n\t\t}\n\t}\n\t// else nav will be \"load\"\n\t\n\tprevStack = stack;\n\tlog('popstate', newRoute);\n\tA.copy(current, newRoute);\n\t\n\tA.runQueue();\n});\n\n// Make sure these observers are never cleaned up, not even by `unmountAll`.\nleakScope(() => {\n\t// Sync `p` to `path`. We need to do this in a separate, higher-priority observer,\n\t// so that setting `route.p` will not be immediately overruled by the pre-existing `route.path`.\n\tA(() => {\n\t\tcurrent.path = \"/\" + Array.from(current.p).join(\"/\");\n\t});\n\n\t// Do a replaceState based on changes to A.proxy\n\tA(() => {\n\t\t// First normalize `route`\n\t\tconst stack = historyE.state?.stack || [];\n\t\tconst newRoute = toCanonRoute(current, A.unproxy(current).nav, stack.length + 1);\n\t\tA.copy(current, newRoute);\n\t\t\n\t\t// Then replace the current browser state if something actually changed\n\t\tconst state = {state: newRoute.state, stack};\n\t\tconst url = getUrl(newRoute);\n\t\tif (url !== locationE.pathname + locationE.search + locationE.hash || !equal(historyE.state, state, false)) {\n\t\t\tlog('replaceState', newRoute, state, url);\n\t\t\thistoryE.replaceState(state, \"\", url);\n\t\t}\n\t});\n\n\t// Keep currentRouteParts in sync with the current path and search params.\n\tA(() => {\n\t\tconst n = {} as Record<string,true>;\n\t\tn[current.path] = true;\n\t\tfor(const [k,v] of Object.entries(current.search)) {\n\t\t\tn[`${k}=${v}`] = true;\n\t\t}\n\t\tA.copy(currentRouteParts, n);\n\t});\n});\n\n\n/**\n* Restore and store the vertical and horizontal scroll position for\n* the parent element to the page state.\n*\n* @param {string} name - A unique (within this page) name for this\n* scrollable element. Defaults to 'main'.\n*\n* The scroll position will be persisted in `route.aux.scroll.<name>`.\n*/\nexport function persistScroll(name = \"main\") {\n\tconst el = A()!;\n\tA('scroll=', onScroll);\n\t\n\tconst restore = A.unproxy(current).state.scroll?.[name];\n\tif (restore) {\n\t\tlog(\"restoring scroll\", name, restore);\n\t\tObject.assign(el, restore);\n\t}\n\t\n\tfunction onScroll() {\n\t\t(current.state.scroll ||= {})[name] = {\n\t\t\tscrollTop: el.scrollTop,\n\t\t\tscrollLeft: el.scrollLeft,\n\t\t};\n\t}\n}\n\n/**\n * Intercept clicks and Enter key presses on links (`<a>` tags) and use Aberdeen routing\n * instead of browser navigation for local paths (paths without a protocol or host).\n * \n * This allows you to use regular HTML anchor tags for navigation without needing to\n * manually attach click handlers to each link.\n * \n * @example\n * ```js\n * // In your root component:\n * route.interceptLinks();\n * \n * // Now you can use regular anchor tags:\n * A('a text=About href=/corporate/about');\n * ```\n */\nexport function interceptLinks() {\n\tA({\n\t\tclick: handleEvent,\n\t\tkeydown: handleKeyEvent,\n\t});\n\t\n\tfunction handleKeyEvent(e: KeyboardEvent) {\n\t\tif (e.key === \"Enter\") {\n\t\t\thandleEvent(e);\n\t\t}\n\t}\n\t\n\tfunction handleEvent(e: Event) {\n\t\t// Find the closest <a> tag\n\t\tlet target = e.target as HTMLElement | null;\n\t\twhile (target && target.tagName?.toUpperCase() !== \"A\") {\n\t\t\ttarget = target.parentElement;\n\t\t}\n\t\t\n\t\tif (!target) return;\n\t\t\n\t\tconst anchor = target as HTMLAnchorElement;\n\t\tconst href = anchor.getAttribute(\"href\");\n\t\t\n\t\tif (!href) return;\n\t\t\n\t\t// Skip hash-only links\n\t\tif (href.startsWith(\"#\")) return;\n\t\t\n\t\t// Skip if it has a protocol or is protocol-relative (// or contains : before any / ? #)\n\t\tif (href.startsWith(\"//\") || /^[^/?#]+:/.test(href)) return;\n\t\t\n\t\t// Skip if the link has target or download attribute\n\t\tif (anchor.getAttribute(\"target\") || anchor.getAttribute(\"download\")) return;\n\t\t\n\t\t// Skip if modifier keys are pressed (Ctrl/Cmd click to open in new tab)\n\t\tif (typeof MouseEvent !== 'undefined' && e instanceof MouseEvent && (e.ctrlKey || e.metaKey || e.shiftKey)) return;\n\t\t\n\t\te.preventDefault();\n\t\tgo(href);\n\t}\n}\n"
|
|
5
|
+
"type NavType = \"load\" | \"back\" | \"forward\" | \"go\" | \"push\";\n\n/**\n* The class for the global `route` object.\n*/\nexport interface Route {\n\t/** The current path of the URL as a string. For instance `\"/\"` or `\"/users/123/feed\"`. Paths are normalized to always start with a `/` and never end with a `/` (unless it's the root path). */\n\tpath: string;\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', '123', 'feed']` (for `\"/users/123/feed\"`). */\n\tp: string[];\n\t/** The hash fragment including the leading `#`, or an empty string. For instance `\"#my_section\"` or `\"\"`. */\n\thash: string;\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\"}`. */\n\tsearch: Record<string, string>;\n\t/** An object to be used for any additional data you want to associate with the current page. Data should be JSON-compatible. */\n\tstate: Record<string, any>;\n\t/** The navigation depth of the current session. Starts at 1. Writing to this property has no effect. */\n\tdepth: number;\n\t/** The navigation action that got us to this page. Writing to this property has no effect.\n\t- `\"load\"`: An initial page load.\n\t- `\"back\"` or `\"forward\"`: When we navigated backwards or forwards in the stack.\n\t- `\"go\"`: When we added a new page on top of the stack.\n\t- `\"push\"`: When we added a new page on top of the stack, merging with the current page.\n\tMostly useful for page transition animations. Writing to this property has no effect.\n\t*/\n\tnav: NavType;\n}\n\ntype RouteTarget = string | (string|number)[] | Partial<Omit<Omit<Route,\"p\">,\"search\"> & {\n\t/** An convenience array containing path segments, mapping to `path`. For instance `[]` (for `\"/\"`) or `['users', 123, 'feed']` (for `\"/users/123/feed\"`). Values may be integers but will be converted to strings.*/\n\tp: (string|number)[],\n\t/** The query string interpreted as search parameters. So `\"a=x&b=y\"` becomes `{a: \"x\", b: \"y\", c: 42}`. Values may be integers but will be converted to strings. */\n\tsearch: Record<string,string|number>,\n}>;\n\n/**\n * The router API returned by {@link init}, bound to a specific Aberdeen instance's window.\n */\nexport interface RouteApi {\n\t/**\n\t* The global {@link Route} object reflecting the current URL and browser history state. Changes you make to this affect the current browser history item (modifying the URL if needed).\n\t*/\n\tcurrent: Route;\n\t/**\n\t * Configure logging on route changes.\n\t * @param value `true` to enable logging to console, `false` to disable logging, or a custom logging function. Defaults to `false`.\n\t */\n\tsetLog(value: boolean | ((...args: any[]) => void)): void;\n\t/**\n\t* Navigate to a new URL by pushing a new history entry.\n\t* \n\t* Note that this happens synchronously, immediately updating `route` and processing any reactive updates based on that.\n\t* \n\t* @param target A subset of the {@link Route} properties to navigate to. If neither `p` nor `path` is given, the current path is used. For other properties, an empty/default value is assumed if not given. For convenience:\n\t* - You may pass a string instead of an object, which is interpreted as the `path`.\n\t* - You may pass an array instead of an object, which is interpreted as the `p` array.\n\t* - If you pass `p`, it may contain numbers, which will be converted to strings.\n\t* - If you pass `search`, its values may be numbers, which will be converted to strings.\n\t* \n\t* Examples:\n\t* ```js\n\t* // Navigate to /users/123\n\t* route.go(\"/users/123\");\n\t* \n\t* // Navigate to /users/123?tab=feed#top\n\t* route.go({p: [\"users\", 123], search: {tab: \"feed\"}, hash: \"top\"});\n\t* ```\n\t*/\n\tgo(target: RouteTarget, nav?: NavType): void;\n\t/**\n\t * Returns `true` if the current route matches `target`.\n\t *\n\t * Path must match exactly. Any search params specified in `target` must be present\n\t * in the current URL, but extra params in the current URL are allowed.\n\t *\n\t * Reactive: only reevaluates when the path changes to/from the target path, and\n\t * when target k/v search pairs are (un)set.\n\t * \n\t * Primary usage: 'active' status for menu items.\n\t *\n\t * @example\n\t * ```js\n\t * // This example assumes interceptLinks() has been called\n\t * A('a.my-button text=Users href=/users .is-active=', route.matchCurrent('/users'));\n\t * \n\t * // Alternatively a route object can be given\n\t * route.matchCurrent({path: '/users', search: {tab: 'profile'}});\n\t * ```\n\t */\n\tmatchCurrent(target: RouteTarget): boolean;\n\t/**\n\t * Modify the current route by merging `target` into it (using {@link aberdeen!Aberdeen.merge | A.merge}), pushing a new history entry.\n\t * \n\t * This is useful for things like opening modals or side panels, where you want a browser back action to return to the previous state.\n\t * \n\t * @param target Same as for {@link go}, but merged into the current route instead deleting all state.\n\t * @param nav The navigation type to use. Defaults to `undefined`, meaning the navigation type is unchanged from the current route,\n\t * preventing unwanted page transition animations.\n\t */\n\tpush(target: RouteTarget, nav?: NavType): void;\n\t/**\n\t * Try to go back in history to the first entry that matches the given target. If none is found, the given state will replace the current page. This is useful for \"cancel\" or \"close\" actions that should return to the previous page if possible, but create a new page if not (for instance when arriving at the current page through a direct link).\n\t * \n\t * Consider using {@link up} to go up in the path hierarchy.\n\t * \n\t * @param target The target route to go back to. May be a subset of {@link Route}, or a string (for `path`), or an array of strings (for `p`).\n\t */\n\tback(target?: RouteTarget): void;\n\t/**\n\t* Navigate up in the path hierarchy, by going back to the first history entry\n\t* that has a shorter path than the current one. If there's none, we just shorten\n\t* the current path.\n\t* \n\t* Note that going back in browser history happens asynchronously, so `route` will not be updated immediately.\n\t*/\n\tup(stripCount?: number): void;\n\t/** @internal */\n\treset(): void;\n\t/**\n\t * Run the router's browser-dependent setup: sync the `route` proxy to the current URL,\n\t * start listening for `popstate`, and start the observers that keep the browser URL in sync\n\t * with `route`. Safe to call multiple times (subsequent calls are no-ops).\n\t *\n\t * This runs automatically on import in a browser. Outside a browser it is a no-op until a\n\t * window has been provided via `setWindow`, after which you should call it yourself (or call\n\t * `reset` to re-sync to a new request URL). See the `aberdeen/server` SSR entry point.\n\t * @internal\n\t */\n\tinitRouter(): void;\n\t/**\n\t* Restore and store the vertical and horizontal scroll position for\n\t* the parent element to the page state.\n\t*\n\t* @param {string} name - A unique (within this page) name for this\n\t* scrollable element. Defaults to 'main'.\n\t*\n\t* The scroll position will be persisted in `route.aux.scroll.<name>`.\n\t*/\n\tpersistScroll(name?: string): void;\n\t/**\n\t * Intercept clicks and Enter key presses on links (`<a>` tags) and use Aberdeen routing\n\t * instead of browser navigation for local paths (paths without a protocol or host).\n\t * \n\t * This allows you to use regular HTML anchor tags for navigation without needing to\n\t * manually attach click handlers to each link.\n\t * \n\t * @example\n\t * ```js\n\t * // In your root component:\n\t * route.interceptLinks();\n\t * \n\t * // Now you can use regular anchor tags:\n\t * A('a text=About href=/corporate/about');\n\t * ```\n\t */\n\tinterceptLinks(): void;\n}\n\n/**\n * Initialise routing for an Aberdeen instance and return the router API, bound to that\n * instance's window. In the browser, use the default instance: `init(A)`. For server-side\n * rendering, pass the instance provided by `aberdeen/server`'s render callback.\n *\n * @param A An Aberdeen instance (the default export of `aberdeen`, or one from `init`).\n */\nexport function init(A: any): RouteApi {\n\nlet log: (...args: any) => void = () => {};\n\nfunction setLog(value: boolean | ((...args: any[]) => void)) {\n\tif (value === true) {\n\t\tlog = console.log.bind(console, 'aberdeen router');\n\t} else if (value === false) {\n\t\tlog = () => {};\n\t} else {\n\t\tlog = value;\n\t}\n}\n\n// The window/location/history are resolved lazily (rather than captured at import time) so\n// that this module can be imported in a non-browser environment and have a window injected\n// later via `setWindow` (see the `aberdeen/server` SSR entry point).\nconst windowE = () => A.window;\nconst locationE = () => A.window.location;\nconst historyE = () => A.window.history;\n\nfunction getRouteFromBrowser(): Route {\n\treturn toCanonRoute({\n\t\tpath: locationE().pathname,\n\t\thash: locationE().hash,\n\t\tsearch: Object.fromEntries(new URLSearchParams(locationE().search)),\n\t\tstate: \thistoryE().state?.state || {},\n\t}, \"load\", (historyE().state?.stack?.length || 0) + 1);\n}\n\n/**\n* Deep compare `a` and `b`. If `partial` is true, objects contained in `b` may be a subset\n* of their counterparts in `a` and still be considered equal.\n*/\nfunction equal(a: any, b: any, partial: boolean): boolean {\n\tif (a===b) return true;\n\tif (typeof a !== \"object\" || !a || typeof b !== \"object\" || !b) return false; // otherwise they would have been equal\n\tif (a.constructor !== b.constructor) return false;\n\tif (b instanceof Array) {\n\t\tif (a.length !== b.length) return false;\n\t\tfor(let i = 0; i < b.length; i++) {\n\t\t\tif (!equal(a[i], b[i], partial)) return false;\n\t\t}\n\t} else {\n\t\tfor(const k of Object.keys(b)) {\n\t\t\tif (!equal(a[k], b[k], partial)) return false;\n\t\t}\n\t\tif (!partial) {\n\t\t\tfor(const k of Object.keys(a)) {\n\t\t\t\tif (!b.hasOwnProperty(k)) return false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction getUrl(target: Route) {\n\tconst search = new URLSearchParams(target.search).toString();\n\treturn (search ? `${target.path}?${search}` : target.path) + target.hash;\n}\n\nfunction toCanonRoute(target: Partial<Route>, nav: NavType, depth: number): Route {\n\tlet path = target.path || (target.p || []).join(\"/\") || \"/\";\n\tpath = (\"\"+path).replace(/\\/+$/, \"\");\n\tif (!path.startsWith(\"/\")) path = `/${path}`;\n\t\n\treturn {\n\t\tpath,\n\t\thash: target.hash && target.hash !==\"#\" ? (target.hash.startsWith(\"#\") ? target.hash : \"#\" + target.hash) : \"\",\n\t\tp: path.length > 1 ? path.slice(1).replace(/\\/+$/, \"\").split(\"/\") : [],\n\t\tnav,\n\t\tsearch: typeof target.search === 'object' && target.search ? A.clone(target.search) : {},\n\t\tstate: typeof target.state === 'object' && target.state ? A.clone(target.state) : {},\n\t\tdepth,\n\t};\n}\n\n\nfunction targetToPartial(target: RouteTarget, undefinedOnExternal: true): Partial<Route> | undefined;\nfunction targetToPartial(target: RouteTarget): Partial<Route>;\n\n\nfunction targetToPartial(target: RouteTarget, undefinedOnExternal: boolean=false) {\n\t// Convert shortcut values to objects\n\tif (typeof target === 'string') {\n\t\t// Parse using URL to handle both absolute and relative paths correctly\t\t\n\t\tconst url = new URL(target, locationE().href);\n\t\tif (url.host !== locationE().host) {\n\t\t\tif (undefinedOnExternal) return;\n\t\t\tthrow new Error(`Unexpected external URL: ${url.host} != ${locationE().host}`);\n\t\t}\n\t\ttarget = {\n\t\t\tpath: url.pathname,\n\t\t\tsearch: Object.fromEntries(url.searchParams),\n\t\t\thash: url.hash,\n\t\t};\n\t} else if (target instanceof Array) {\n\t\ttarget = {p: target};\n\t}\n\t// Convert numbers in p and search to strings\n\tif (target.p) {\n\t\ttarget.p = target.p.map(String);\n\t}\n\tif (target.search) {\n\t\tfor(const key of Object.keys(target.search)) {\n\t\t\ttarget.search[key] = String(target.search[key]);\n\t\t}\n\t}\n\treturn target as Partial<Route>;\n}\n\n\nfunction go(target: RouteTarget, nav: NavType = \"go\"): void {\n\tpendingGoOffset = 0;\n\tconst stack: string[] = historyE().state?.stack || [];\n\n\tprevStack = stack.concat(JSON.stringify(A.unproxy(current)));\n\t\n\tconst newRoute: Route = toCanonRoute(targetToPartial(target), nav, prevStack.length + 1);\n\tA.copy(current, newRoute);\n\t\n\tlog(nav, newRoute);\n\thistoryE().pushState({state: newRoute.state, stack: prevStack}, \"\", getUrl(newRoute));\n\t\n\tA.runQueue();\n}\n\nfunction matchCurrent(target: RouteTarget): boolean {\n\tconst partial = targetToPartial(target, true);\n\tif (!partial) return false; // External link\n\n\tif (partial.path != null || partial.p != null) {\n\t\tlet path = partial.path || (partial.p || []).join(\"/\") || \"/\";\n\t\tpath = (\"\"+path).replace(/\\/+$/, \"\");\n\t\tif (!path.startsWith(\"/\")) path = `/${path}`;\n\t\tif (!currentRouteParts[path]) return false;\n\t}\n\n\tif (partial.search) {\n\t\tfor(const [k,v] of Object.entries(partial.search)) {\n\t\t\tif (!currentRouteParts[`${k}=${v}`]) return false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfunction push(target: RouteTarget, nav?: NavType): void {\n\tconst c = A.clone(A.unproxy(current));\n\tA.merge(c, targetToPartial(target));\n\tgo(c, nav || c.nav);\n}\n\nfunction back(target: RouteTarget = {}): void {\n\tconst partial = targetToPartial(target);\n\tconst stack: string[] = historyE().state?.stack || [];\n\tconst effectiveLen = stack.length + pendingGoOffset;\n\tfor(let i = effectiveLen - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (equal(histRoute, partial, true)) {\n\t\t\tconst pages = i - effectiveLen;\n\t\t\tlog(`back`, pages, histRoute);\n\t\t\tscheduleHistoryGo(pages);\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst newRoute = toCanonRoute(partial, \"back\", effectiveLen + 1);\n\tlog(`back not found, replacing`, partial);\n\tA.copy(current, newRoute);\n}\n\nfunction up(stripCount: number = 1): void {\n\tconst currentP = A.unproxy(current).p;\n\tconst stack: string[] = historyE().state?.stack || [];\n\tconst effectiveLen = stack.length + pendingGoOffset;\n\tfor(let i = effectiveLen - 1; i >= 0; i--) {\n\t\tconst histRoute: Route = JSON.parse(stack[i]);\n\t\tif (histRoute.p.length < currentP.length && equal(histRoute.p, currentP.slice(0, histRoute.p.length), false)) {\n\t\t\t// This route is shorter and matches the start of the current path\n\t\t\tlog(`up to ${i+1} / ${effectiveLen}`, histRoute);\n\t\t\tscheduleHistoryGo(i - effectiveLen);\n\t\t\treturn;\n\t\t}\n\t}\n\t// Replace current route with /\n\tconst newRoute = toCanonRoute({p: currentP.slice(0, currentP.length - stripCount)}, \"back\", effectiveLen + 1);\n\tlog(`up not found, replacing`, newRoute);\n\tA.copy(current, newRoute);\n}\n\n\nlet prevStack: string[];\n\n// Track pending historyE().go() offset. Multiple back()/up() calls before the event loop\n// processes them are batched into a single historyE().go() via queueMicrotask.\nlet pendingGoOffset = 0;\n\nfunction scheduleHistoryGo(delta: number) {\n\tpendingGoOffset += delta;\n\t(A.window.setTimeout ?? setTimeout)(() => {\n\t\tif (pendingGoOffset) {\n\t\t\tconst offset = pendingGoOffset;\n\t\t\tpendingGoOffset = 0;\n\t\t\thistoryE().go(offset);\n\t\t}\n\t}, 0);\n}\n\nconst current: Route = A.proxy({}) as Route;\n\n// Proxied object with keys for the current path and \"k=v\" search pairs.\n// Used by matchCurrent to subscribe only to relevant route changes.\nconst currentRouteParts = A.proxy({} as Record<string,true>);\n\n/**\n * Reset the router to its initial state, based on the current browser state. Intended for testing purposes only.\n * @internal\n * */\nfunction reset() {\n\tprevStack = historyE().state?.stack || [];\n\tconst initRoute = getRouteFromBrowser();\n\tlog('initial', initRoute);\n\tA.copy(A.unproxy(current), initRoute);\n}\nlet routerInited = false;\n\nfunction initRouter() {\n\tif (routerInited || !A.window) return;\n\trouterInited = true;\n\n\treset();\n\n\t// Handle browser history back and forward\n\twindowE().addEventListener(\"popstate\", function(event: PopStateEvent) {\n\tpendingGoOffset = 0;\n\tconst newRoute = getRouteFromBrowser();\n\t\n\t// If the stack length changes, and at least the top-most shared entry is the same,\n\t// we'll interpret this as a \"back\" or \"forward\" navigation.\n\tconst stack: string[] = historyE().state?.stack || [];\n\tif (stack.length !== prevStack.length) {\n\t\tconst maxIndex = Math.min(prevStack.length, stack.length) - 1;\n\t\tif (maxIndex < 0 || stack[maxIndex] === prevStack[maxIndex]) {\n\t\t\tnewRoute.nav = stack.length < prevStack.length ? \"back\" : \"forward\";\n\t\t}\n\t}\n\t// else nav will be \"load\"\n\t\n\tprevStack = stack;\n\tlog('popstate', newRoute);\n\tA.copy(current, newRoute);\n\t\n\tA.runQueue();\n});\n\n// Make sure these observers are never cleaned up, not even by `unmountAll`.\nA.leakScope(() => {\n\t// Sync `p` to `path`. We need to do this in a separate, higher-priority observer,\n\t// so that setting `route.p` will not be immediately overruled by the pre-existing `route.path`.\n\tA(() => {\n\t\tcurrent.path = \"/\" + Array.from(current.p).join(\"/\");\n\t});\n\n\t// Do a replaceState based on changes to A.proxy\n\tA(() => {\n\t\t// First normalize `route`\n\t\tconst stack = historyE().state?.stack || [];\n\t\tconst newRoute = toCanonRoute(current, A.unproxy(current).nav, stack.length + 1);\n\t\tA.copy(current, newRoute);\n\t\t\n\t\t// Then replace the current browser state if something actually changed\n\t\tconst state = {state: newRoute.state, stack};\n\t\tconst url = getUrl(newRoute);\n\t\tif (url !== locationE().pathname + locationE().search + locationE().hash || !equal(historyE().state, state, false)) {\n\t\t\tlog('replaceState', newRoute, state, url);\n\t\t\thistoryE().replaceState(state, \"\", url);\n\t\t}\n\t});\n\n\t// Keep currentRouteParts in sync with the current path and search params.\n\tA(() => {\n\t\tconst n = {} as Record<string,true>;\n\t\tn[current.path] = true;\n\t\tfor(const [k,v] of Object.entries(current.search)) {\n\t\t\tn[`${k}=${v}`] = true;\n\t\t}\n\t\tA.copy(currentRouteParts, n);\n\t});\n});\n}\n\n// Initialise immediately in a browser; a no-op (until `setWindow`) on the server.\ninitRouter();\n\n\nfunction persistScroll(name = \"main\") {\n\tconst el = A()!;\n\tA('scroll=', onScroll);\n\t\n\tconst restore = A.unproxy(current).state.scroll?.[name];\n\tif (restore) {\n\t\tlog(\"restoring scroll\", name, restore);\n\t\tObject.assign(el, restore);\n\t}\n\t\n\tfunction onScroll() {\n\t\t(current.state.scroll ||= {})[name] = {\n\t\t\tscrollTop: el.scrollTop,\n\t\t\tscrollLeft: el.scrollLeft,\n\t\t};\n\t}\n}\n\nfunction interceptLinks() {\n\tA({\n\t\tclick: handleEvent,\n\t\tkeydown: handleKeyEvent,\n\t});\n\t\n\tfunction handleKeyEvent(e: KeyboardEvent) {\n\t\tif (e.key === \"Enter\") {\n\t\t\thandleEvent(e);\n\t\t}\n\t}\n\t\n\tfunction handleEvent(e: Event) {\n\t\t// Find the closest <a> tag\n\t\tlet target = e.target as HTMLElement | null;\n\t\twhile (target && target.tagName?.toUpperCase() !== \"A\") {\n\t\t\ttarget = target.parentElement;\n\t\t}\n\t\t\n\t\tif (!target) return;\n\t\t\n\t\tconst anchor = target as HTMLAnchorElement;\n\t\tconst href = anchor.getAttribute(\"href\");\n\t\t\n\t\tif (!href) return;\n\t\t\n\t\t// Skip hash-only links\n\t\tif (href.startsWith(\"#\")) return;\n\t\t\n\t\t// Skip if it has a protocol or is protocol-relative (// or contains : before any / ? #)\n\t\tif (href.startsWith(\"//\") || /^[^/?#]+:/.test(href)) return;\n\t\t\n\t\t// Skip if the link has target or download attribute\n\t\tif (anchor.getAttribute(\"target\") || anchor.getAttribute(\"download\")) return;\n\t\t\n\t\t// Skip if modifier keys are pressed (Ctrl/Cmd click to open in new tab)\n\t\tif (typeof MouseEvent !== 'undefined' && e instanceof MouseEvent && (e.ctrlKey || e.metaKey || e.shiftKey)) return;\n\t\t\n\t\te.preventDefault();\n\t\tgo(href);\n\t}\n}\n\n\treturn { current, setLog, go, matchCurrent, push, back, up, reset, initRouter, persistScroll, interceptLinks } as unknown as RouteApi;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAAA
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAqKO,SAAS,IAAI,CAAC,GAAkB;AAAA,EAEvC,IAAI,MAA8B,MAAM;AAAA,EAExC,SAAS,MAAM,CAAC,OAA6C;AAAA,IAC5D,IAAI,UAAU,MAAM;AAAA,MACnB,MAAM,QAAQ,IAAI,KAAK,SAAS,iBAAiB;AAAA,IAClD,EAAO,SAAI,UAAU,OAAO;AAAA,MAC3B,MA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,OAAO,SAAS,YAAY,MAAM,KAAK;AAAA,QACvD,SAAS,OAAO;AAAA,MACjB;AAAA,MAEA,IAAI,CAAC;AAAA,QAAQ;AAAA,MAEb,MAAM,SAAS;AAAA,MACf,MAAM,OAAO,OAAO,aAAa,MAAM;AAAA,MAEvC,IAAI,CAAC;AAAA,QAAM;AAAA,MAGX,IAAI,KAAK,WAAW,GAAG;AAAA,QAAG;AAAA,MAG1B,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,KAAK,IAAI;AAAA,QAAG;AAAA,MAGrD,IAAI,OAAO,aAAa,QAAQ,KAAK,OAAO,aAAa,UAAU;AAAA,QAAG;AAAA,MAGtE,IAAI,OAAO,eAAe,eAAe,aAAa,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE;AAAA,QAAW;AAAA,MAE5G,EAAE,eAAe;AAAA,MACjB,GAAG,IAAI;AAAA;AAAA;AAAA,EAIR,OAAO,EAAE,SAAS,QAAQ,IAAI,cAAc,MAAM,MAAM,IAAI,OAAO,YAAY,eAAe,eAAe;AAAA;",
|
|
8
|
+
"debugId": "CA3A70B43BF6BD7864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal, dependency-free DOM implementation that Aberdeen can render into when no
|
|
3
|
+
* real browser DOM is available (server-side rendering, automated tests).
|
|
4
|
+
*
|
|
5
|
+
* It implements just enough of the `Node`/`Element`/`Text` interfaces for Aberdeen's
|
|
6
|
+
* renderer, plus two serializers:
|
|
7
|
+
* - {@link serializeHtml} produces real HTML (used for SSR output).
|
|
8
|
+
* - `Element.toString()` produces a terse, test-oriented representation (used by the
|
|
9
|
+
* test suite's `assertBody`).
|
|
10
|
+
*
|
|
11
|
+
* The same classes back both the test fake-DOM (`tests/fakedom.ts`) and the public
|
|
12
|
+
* `aberdeen/server` entry point, so there is a single source of truth for DOM behaviour.
|
|
13
|
+
*/
|
|
14
|
+
export declare const resetCounts: () => void;
|
|
15
|
+
export declare const getCounts: () => {
|
|
16
|
+
new: number;
|
|
17
|
+
changed: number;
|
|
18
|
+
};
|
|
19
|
+
export declare class Node {
|
|
20
|
+
parentNode: Element | null;
|
|
21
|
+
childNodes: Node[];
|
|
22
|
+
/** The document that created this node; its `defaultView` is the owning window. */
|
|
23
|
+
ownerDocument: any;
|
|
24
|
+
get nextSibling(): Node | undefined;
|
|
25
|
+
get previousSibling(): Node | undefined;
|
|
26
|
+
getSibling(delta: number): Node | undefined;
|
|
27
|
+
}
|
|
28
|
+
type ClassList = {
|
|
29
|
+
add: (...names: string[]) => void;
|
|
30
|
+
remove: (...names: string[]) => void;
|
|
31
|
+
toggle: (name: string, force?: boolean) => void;
|
|
32
|
+
contains: (name: string) => boolean;
|
|
33
|
+
};
|
|
34
|
+
export declare class Element extends Node {
|
|
35
|
+
tagName: string;
|
|
36
|
+
namespaceURI?: string;
|
|
37
|
+
_style: Record<string, string>;
|
|
38
|
+
attrs: Record<string, string>;
|
|
39
|
+
events: Record<string, Set<Function>>;
|
|
40
|
+
_classList?: ClassList;
|
|
41
|
+
_scrollTop?: number;
|
|
42
|
+
_scrollLeft?: number;
|
|
43
|
+
constructor(tag: string, namespaceURI?: string);
|
|
44
|
+
appendChild(node: Node): void;
|
|
45
|
+
insertBefore(node: Node, ref: Node | null): void;
|
|
46
|
+
removeChild(node: Node): void;
|
|
47
|
+
remove(): void;
|
|
48
|
+
replaceChild(newNode: Node, oldNode: Node): void;
|
|
49
|
+
setAttribute(k: string, v: any): void;
|
|
50
|
+
getAttribute(k: string): string | undefined;
|
|
51
|
+
removeAttribute(k: string): void;
|
|
52
|
+
get classList(): ClassList;
|
|
53
|
+
get parentElement(): Element | undefined;
|
|
54
|
+
_getClassSet(): Set<string>;
|
|
55
|
+
_setClassSet(map: Set<string>): void;
|
|
56
|
+
get firstChild(): Node | undefined;
|
|
57
|
+
get lastChild(): Node | undefined;
|
|
58
|
+
set textContent(text: string);
|
|
59
|
+
get textContent(): string;
|
|
60
|
+
querySelectorAll(selector: string): Element[];
|
|
61
|
+
private _querySelectorAllRecursive;
|
|
62
|
+
set innerHTML(html: string);
|
|
63
|
+
set style(val: string);
|
|
64
|
+
get style(): Record<string, string>;
|
|
65
|
+
set className(v: string);
|
|
66
|
+
get offsetHeight(): number;
|
|
67
|
+
get offsetWidth(): number;
|
|
68
|
+
get scrollTop(): number;
|
|
69
|
+
set scrollTop(value: number);
|
|
70
|
+
get scrollLeft(): number;
|
|
71
|
+
set scrollLeft(value: number);
|
|
72
|
+
/**
|
|
73
|
+
* Terse, test-oriented serialization (NOT valid HTML). Shows attributes (`=`),
|
|
74
|
+
* DOM properties (`->`), styles (`:`) and nested children. Used by `assertBody`.
|
|
75
|
+
*/
|
|
76
|
+
toString(): string;
|
|
77
|
+
addEventListener(name: string, func: Function): void;
|
|
78
|
+
removeEventListener(name: string, func: Function): void;
|
|
79
|
+
event(info: string | {
|
|
80
|
+
type: string;
|
|
81
|
+
[key: string]: any;
|
|
82
|
+
}): void;
|
|
83
|
+
getElementById(id: string): Element | undefined;
|
|
84
|
+
}
|
|
85
|
+
export declare class TextNode extends Node {
|
|
86
|
+
textContent: string;
|
|
87
|
+
constructor(textContent: string);
|
|
88
|
+
toString(): string;
|
|
89
|
+
remove(): void;
|
|
90
|
+
}
|
|
91
|
+
export interface ServerDocument {
|
|
92
|
+
createElement(tag: string): Element;
|
|
93
|
+
createElementNS(namespaceURI: string, tag: string): Element;
|
|
94
|
+
createTextNode(text: string): TextNode;
|
|
95
|
+
head: Element;
|
|
96
|
+
body: Element;
|
|
97
|
+
/** The owning window, set by {@link createWindow}. */
|
|
98
|
+
defaultView: any;
|
|
99
|
+
}
|
|
100
|
+
/** Create a fresh, isolated document. Use one per SSR request to avoid cross-request state. */
|
|
101
|
+
export declare function createDocument(): ServerDocument;
|
|
102
|
+
/**
|
|
103
|
+
* Serialize a node (and its descendants) to an HTML string.
|
|
104
|
+
*
|
|
105
|
+
* Notes/limitations:
|
|
106
|
+
* - Event listeners are dropped (they are client-only by design).
|
|
107
|
+
* - DOM properties set directly on elements (e.g. `input.value` via `value:` arg) are not
|
|
108
|
+
* reflected as attributes and therefore do not appear in the output.
|
|
109
|
+
*/
|
|
110
|
+
export declare function serializeHtml(node: Node): string;
|
|
111
|
+
/** Serialize the children of a container element to an HTML string (the container tag itself is omitted). */
|
|
112
|
+
export declare function serializeChildren(node: Element): string;
|
|
113
|
+
export declare class ServerLocation {
|
|
114
|
+
private _href;
|
|
115
|
+
constructor(href?: string);
|
|
116
|
+
get href(): string;
|
|
117
|
+
set href(value: string);
|
|
118
|
+
get origin(): string;
|
|
119
|
+
get host(): string;
|
|
120
|
+
get pathname(): string;
|
|
121
|
+
set pathname(v: string);
|
|
122
|
+
get search(): string;
|
|
123
|
+
set search(v: string);
|
|
124
|
+
get hash(): string;
|
|
125
|
+
set hash(v: string);
|
|
126
|
+
}
|
|
127
|
+
export declare class ServerHistory {
|
|
128
|
+
private location;
|
|
129
|
+
state: any;
|
|
130
|
+
constructor(location: ServerLocation);
|
|
131
|
+
pushState(state: any, _title: string, url: string): void;
|
|
132
|
+
replaceState(state: any, _title: string, url: string): void;
|
|
133
|
+
go(_delta: number): void;
|
|
134
|
+
back(): void;
|
|
135
|
+
forward(): void;
|
|
136
|
+
}
|
|
137
|
+
export interface ServerWindow {
|
|
138
|
+
document: ServerDocument;
|
|
139
|
+
Node: typeof Node;
|
|
140
|
+
Element: typeof Element;
|
|
141
|
+
location: ServerLocation;
|
|
142
|
+
history: ServerHistory;
|
|
143
|
+
addEventListener(type: string, listener: Function): void;
|
|
144
|
+
removeEventListener(type: string, listener: Function): void;
|
|
145
|
+
dispatchEvent(event: any): void;
|
|
146
|
+
matchMedia(query: string): {
|
|
147
|
+
matches: boolean;
|
|
148
|
+
media: string;
|
|
149
|
+
addEventListener(): void;
|
|
150
|
+
removeEventListener(): void;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create a fresh, isolated window (carrying its own document and the `Node`/`Element`
|
|
155
|
+
* constructors) bound to `url`. Use one per SSR request. Satisfies Aberdeen's `WindowLike`.
|
|
156
|
+
*/
|
|
157
|
+
export declare function createWindow(url?: string): ServerWindow;
|
|
158
|
+
export {};
|