akanjs 3.3.0-rc.52 → 3.3.0-rc.53
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/README.ko.md +1 -0
- package/README.md +1 -0
- package/client/csrLocation.ts +21 -6
- package/client/csrRuntimeParams.ts +33 -0
- package/client/csrTypes.ts +12 -0
- package/client/frameConfig.ts +9 -0
- package/client/index.ts +2 -0
- package/client/router.ts +21 -18
- package/client/shellState.ts +151 -0
- package/client/shellStateHooks.ts +2 -0
- package/index.ts +10 -0
- package/package.json +1 -1
- package/server/akanServer.ts +9 -1
- package/server/di/diLifecycle.ts +25 -186
- package/server/di/moduleSelection.ts +202 -0
- package/server/htmlResultCache.ts +57 -34
- package/server/lifecycle/buildEnv.ts +2 -0
- package/server/resolver/unmountedRoutes.ts +55 -0
- package/server/routeCacheTally.ts +4 -0
- package/server/serverConfig.ts +1 -0
- package/store/baseSt.ts +7 -6
- package/store/shellMirror.ts +49 -0
- package/test/signalTestRuntime.ts +4 -1
- package/test/testServer.ts +7 -1
- package/types/client/csrLocation.d.ts +5 -2
- package/types/client/csrRuntimeParams.d.ts +6 -0
- package/types/client/csrTypes.d.ts +11 -0
- package/types/client/index.d.ts +2 -1
- package/types/client/router.d.ts +7 -0
- package/types/client/shellState.d.ts +54 -0
- package/types/client/shellStateHooks.d.ts +1 -0
- package/types/index.d.ts +10 -0
- package/types/server/akanServer.d.ts +2 -0
- package/types/server/di/diLifecycle.d.ts +2 -1
- package/types/server/di/moduleSelection.d.ts +22 -0
- package/types/server/lifecycle/buildEnv.d.ts +1 -0
- package/types/server/resolver/unmountedRoutes.d.ts +6 -0
- package/types/server/routeCacheTally.d.ts +1 -1
- package/types/store/baseSt.d.ts +1 -1
- package/types/store/shellMirror.d.ts +8 -0
- package/types/test/signalTestRuntime.d.ts +1 -1
- package/types/test/testServer.d.ts +2 -0
- package/types/webkit/csrSlide.d.ts +1 -0
- package/ui/Copy.tsx +5 -3
- package/ui/Link/Anchor.tsx +12 -3
- package/ui/Link/activePath.ts +2 -3
- package/ui/System/CSR.tsx +9 -4
- package/ui/System/Client.tsx +13 -32
- package/ui/System/Messages.tsx +5 -6
- package/ui/agentAttrs.ts +1 -1
- package/webkit/csrSlide.ts +39 -14
- package/webkit/useCsrTransitions.ts +65 -17
- package/webkit/usePageLocation.ts +4 -5
- package/CHANGELOG.md +0 -5703
- package/CODE_OF_CONDUCT.md +0 -54
- package/CONTRIBUTING.md +0 -109
- package/vendor/@akanjs/native/CHANGELOG.md +0 -33
- package/vendor/use-agentic/CHANGELOG.md +0 -728
package/README.ko.md
CHANGED
|
@@ -107,6 +107,7 @@ cd dist/apps/<app> && PORT=3000 bun main.js
|
|
|
107
107
|
- `akanjs`는 npm 패키지 하나입니다. subpath(`akanjs/base`, `akanjs/client`, `akanjs/signal`, `akanjs/ui`, …)가 서버
|
|
108
108
|
전용, 클라이언트 전용, UI, 툴링 코드를 나누고([패키지 레퍼런스](https://akanjs.com/references/akanjs/base)), 툴링은
|
|
109
109
|
`@akanjs/cli`와 `@akanjs/devkit`으로 나옵니다.
|
|
110
|
+
- 버전별 변경: [`CHANGELOG.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CHANGELOG.md).
|
|
110
111
|
- 기여: [`CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md)와
|
|
111
112
|
[행동 강령](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md). 라이선스: MIT
|
|
112
113
|
([`LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE)).
|
package/README.md
CHANGED
|
@@ -106,6 +106,7 @@ you are running on a public URL.
|
|
|
106
106
|
- `akanjs` is one npm package. Its subpaths (`akanjs/base`, `akanjs/client`, `akanjs/signal`, `akanjs/ui`, …) keep
|
|
107
107
|
server-only, client-only, UI and tooling code apart, and the [package reference](https://akanjs.com/references/akanjs/base)
|
|
108
108
|
covers them; the tooling ships as `@akanjs/cli` and `@akanjs/devkit`.
|
|
109
|
+
- Changes by version: [`CHANGELOG.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CHANGELOG.md).
|
|
109
110
|
- Contributing: [`CONTRIBUTING.md`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CONTRIBUTING.md) and
|
|
110
111
|
the [code of conduct](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/CODE_OF_CONDUCT.md). License: MIT
|
|
111
112
|
([`LICENSE`](https://github.com/akan-team/akanjs/blob/main/pkgs/akanjs/LICENSE)).
|
package/client/csrLocation.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare global {
|
|
|
8
8
|
export class CsrLocation {
|
|
9
9
|
|
|
10
10
|
#view: URL | null = null;
|
|
11
|
-
#entry: { idx: number | undefined; href: string } | null = null;
|
|
11
|
+
#entry: { idx: number | undefined; href: string; from: string | undefined } | null = null;
|
|
12
12
|
#onBack: ((idx: number) => void) | null = null;
|
|
13
13
|
|
|
14
14
|
/** Reads `href`, a path on the app's origin, as this document's location from now on; a view never moves. */
|
|
@@ -44,25 +44,28 @@ export class CsrLocation {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* The entry on screen as of the last write or traversal,
|
|
48
|
-
*
|
|
47
|
+
* The entry on screen as of the last write or traversal, its index, and `from`, the address a push stacked it on
|
|
48
|
+
* (none for an entry a document load or a fragment link made); during a `popstate` it is still the entry left,
|
|
49
|
+
* which `state` no longer reads.
|
|
49
50
|
*/
|
|
50
51
|
entry() {
|
|
51
52
|
return this.#entry ?? this.observe();
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
observe() {
|
|
55
|
-
|
|
56
|
+
const state = window.history?.state;
|
|
57
|
+
this.#entry = { idx: CsrLocation.idxOf(state), href: this.href, from: CsrLocation.#fromOf(state) };
|
|
56
58
|
return this.#entry;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
push(state: unknown, href: string) {
|
|
60
|
-
|
|
62
|
+
const stacked = CsrLocation.#indexed(state, (this.entry().idx ?? 0) + 1) as { __akanRouter?: object };
|
|
63
|
+
window.history.pushState({ ...stacked, __akanRouter: { ...stacked.__akanRouter, from: this.href } }, "", href);
|
|
61
64
|
this.observe();
|
|
62
65
|
}
|
|
63
66
|
|
|
64
67
|
replace(state: unknown, href?: string) {
|
|
65
|
-
const indexed = CsrLocation.#indexed(state, this.entry().idx ?? 0);
|
|
68
|
+
const indexed = CsrLocation.#rewritten(CsrLocation.#indexed(state, this.entry().idx ?? 0), window.history.state);
|
|
66
69
|
if (href === undefined) window.history.replaceState(indexed, "");
|
|
67
70
|
else window.history.replaceState(indexed, "", href);
|
|
68
71
|
this.observe();
|
|
@@ -73,6 +76,18 @@ export class CsrLocation {
|
|
|
73
76
|
return Number.isInteger(idx) ? (idx as number) : undefined;
|
|
74
77
|
}
|
|
75
78
|
|
|
79
|
+
static #fromOf(state: unknown) {
|
|
80
|
+
const from = (state as { __akanRouter?: { from?: unknown } } | null)?.__akanRouter?.from;
|
|
81
|
+
return typeof from === "string" ? from : undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static #rewritten(state: unknown, live: unknown) {
|
|
85
|
+
const from = CsrLocation.#fromOf(live);
|
|
86
|
+
if (from === undefined || CsrLocation.#fromOf(state) !== undefined) return state;
|
|
87
|
+
const record = (state ?? {}) as { __akanRouter?: object };
|
|
88
|
+
return { ...record, __akanRouter: { ...record.__akanRouter, from } };
|
|
89
|
+
}
|
|
90
|
+
|
|
76
91
|
static #indexed(state: unknown, idx: number) {
|
|
77
92
|
if (CsrLocation.idxOf(state) !== undefined) return state;
|
|
78
93
|
const record = (state ?? {}) as { __akanRouter?: object };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { csrLocation } from "./csrLocation";
|
|
2
|
+
import { Href } from "./href";
|
|
3
|
+
|
|
4
|
+
/** The params a CSR boot reads off its address (`?csr=true`), which every address it moves to carries along. */
|
|
5
|
+
export class CsrRuntimeParams {
|
|
6
|
+
static readonly #names = ["csr", "akanMobileTarget", "akanMobileBasePath", "akanMobileIndexPath"] as const;
|
|
7
|
+
|
|
8
|
+
static carry(href: string) {
|
|
9
|
+
const currentSearch = new URLSearchParams(csrLocation.search);
|
|
10
|
+
if (currentSearch.get("csr") !== "true" || Href.hasWebScheme(href)) return href;
|
|
11
|
+
|
|
12
|
+
const [hrefWithoutHash, hash = ""] = href.split("#");
|
|
13
|
+
const [pathname, search = ""] = hrefWithoutHash.split("?");
|
|
14
|
+
const nextSearch = new URLSearchParams(search);
|
|
15
|
+
for (const param of CsrRuntimeParams.#names) {
|
|
16
|
+
if (nextSearch.has(param)) continue;
|
|
17
|
+
const value = currentSearch.get(param);
|
|
18
|
+
if (value !== null) nextSearch.set(param, value);
|
|
19
|
+
}
|
|
20
|
+
const query = nextSearch.toString();
|
|
21
|
+
return `${pathname}${query ? `?${query}` : ""}${hash ? `#${hash}` : ""}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static sameRoute(a: string, b: string) {
|
|
25
|
+
const [left, right] = [a, b].map((href) => {
|
|
26
|
+
const url = new URL(href, "http://route.invalid");
|
|
27
|
+
for (const param of CsrRuntimeParams.#names) url.searchParams.delete(param);
|
|
28
|
+
url.searchParams.sort();
|
|
29
|
+
return `${url.pathname}?${url.searchParams.toString()}${url.hash}`;
|
|
30
|
+
});
|
|
31
|
+
return left === right;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/client/csrTypes.ts
CHANGED
|
@@ -21,6 +21,9 @@ export type PageSafeAreaConfig =
|
|
|
21
21
|
};
|
|
22
22
|
/** The sides whose chrome the page runs under instead of below. */
|
|
23
23
|
export type PageOverlayConfig = boolean | "top" | "bottom";
|
|
24
|
+
|
|
25
|
+
/** How a page's navbar moves when it transitions; see `PageConfig.navbarMotion`. */
|
|
26
|
+
export type NavbarMotion = "crossfade" | "page";
|
|
24
27
|
/** `"stream"` flushes the shell (`Loading` included) then streams; a redirect in suspended content becomes a client one.
|
|
25
28
|
* `"block"` buffers the whole document, so an error in slow content can still render a clean error page. */
|
|
26
29
|
export type SsrRenderMode = "stream" | "block";
|
|
@@ -42,6 +45,13 @@ export interface PageConfig {
|
|
|
42
45
|
* and an overlaid side's safe area defaults to transparent.
|
|
43
46
|
*/
|
|
44
47
|
overlay?: PageOverlayConfig;
|
|
48
|
+
/**
|
|
49
|
+
* How the navbar (`Layout.Navbar`'s top inset and its back button) moves when this page transitions.
|
|
50
|
+
* `"crossfade"`, the default, keeps one bar in place and crossfades the two pages' bars, as UIKit's does; between a
|
|
51
|
+
* page with a bar and one without, the bar's height folds away. `"page"` moves each bar with its page, as a part of
|
|
52
|
+
* the page, for a bar that is the page's own surface (translucent, or with no fill of its own).
|
|
53
|
+
*/
|
|
54
|
+
navbarMotion?: NavbarMotion;
|
|
45
55
|
gesture?: boolean;
|
|
46
56
|
cache?: boolean;
|
|
47
57
|
/** Initial full-document SSR strategy. Defaults to `"stream"`. */
|
|
@@ -77,6 +87,8 @@ export interface CsrState {
|
|
|
77
87
|
/** Web only: the sides whose safe area `env(safe-area-inset-*)` measures, since a browser tells script nothing. */
|
|
78
88
|
safeAreaEnv?: { top: boolean; bottom: boolean };
|
|
79
89
|
overlay?: { top: boolean; bottom: boolean };
|
|
90
|
+
/** Set when the page declares one; left out, the navbar crossfades. */
|
|
91
|
+
navbarMotion?: NavbarMotion;
|
|
80
92
|
gesture: boolean;
|
|
81
93
|
cache: boolean;
|
|
82
94
|
ssr: SsrRenderMode;
|
package/client/frameConfig.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isRecord, trimSlashes } from "akanjs/common";
|
|
2
2
|
import type {
|
|
3
|
+
NavbarMotion,
|
|
3
4
|
PageConfig,
|
|
4
5
|
PageOverlayConfig,
|
|
5
6
|
PageSafeAreaConfig,
|
|
@@ -46,6 +47,7 @@ const pageConfigKeys = new Set<keyof PageConfig>([
|
|
|
46
47
|
"topInset",
|
|
47
48
|
"bottomInset",
|
|
48
49
|
"overlay",
|
|
50
|
+
"navbarMotion",
|
|
49
51
|
"gesture",
|
|
50
52
|
"cache",
|
|
51
53
|
"ssr",
|
|
@@ -58,6 +60,7 @@ const pageConfigKeys = new Set<keyof PageConfig>([
|
|
|
58
60
|
|
|
59
61
|
const buildPageConfigKeys = new Set<keyof PageConfig>(["devOnly"]);
|
|
60
62
|
const ssrRenderModes = new Set<SsrRenderMode>(["stream", "block"]);
|
|
63
|
+
const navbarMotions = new Set<NavbarMotion>(["crossfade", "page"]);
|
|
61
64
|
const DEFAULT_BOOLEAN_INSET = 48;
|
|
62
65
|
|
|
63
66
|
const hasOwn = <Key extends PropertyKey>(value: object, key: Key) => Object.hasOwn(value, key);
|
|
@@ -78,6 +81,11 @@ export const validatePageConfig = (routeKey: string, config?: PageConfig) => {
|
|
|
78
81
|
if (pageConfig.transition !== undefined && !transitionTypes.includes(pageConfig.transition)) {
|
|
79
82
|
throw new Error(`[route-convention] unsupported pageConfig.transition "${pageConfig.transition}" in ${routeKey}`);
|
|
80
83
|
}
|
|
84
|
+
if (pageConfig.navbarMotion !== undefined && !navbarMotions.has(pageConfig.navbarMotion)) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`[route-convention] pageConfig.navbarMotion in ${routeKey} must be "crossfade" or "page", not "${pageConfig.navbarMotion}".`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
81
89
|
if (pageConfig.ssr !== undefined && !ssrRenderModes.has(pageConfig.ssr)) {
|
|
82
90
|
throw new Error(`[route-convention] unsupported pageConfig.ssr "${pageConfig.ssr}" in ${routeKey}`);
|
|
83
91
|
}
|
|
@@ -229,6 +237,7 @@ export const resolvePageState = ({
|
|
|
229
237
|
: {}),
|
|
230
238
|
...(safeAreaEnv ? { safeAreaEnv } : {}),
|
|
231
239
|
...(overlay ? { overlay } : {}),
|
|
240
|
+
...(config.navbarMotion ? { navbarMotion: config.navbarMotion } : {}),
|
|
232
241
|
gesture: explicitKeys.gesture
|
|
233
242
|
? (config.gesture ?? false)
|
|
234
243
|
: transition === "none"
|
package/client/index.ts
CHANGED
|
@@ -75,6 +75,7 @@ export {
|
|
|
75
75
|
type LayoutRender,
|
|
76
76
|
type Location,
|
|
77
77
|
type LocationState,
|
|
78
|
+
type NavbarMotion,
|
|
78
79
|
type NavigationIntent,
|
|
79
80
|
type PageActivity,
|
|
80
81
|
type PageActivityState,
|
|
@@ -222,6 +223,7 @@ export {
|
|
|
222
223
|
} from "./rscNavigation";
|
|
223
224
|
export { scriptHashes, scriptNonce } from "./scriptPolicy";
|
|
224
225
|
export { sharedContext } from "./sharedContext";
|
|
226
|
+
export { type ShellMessage, ShellState, type ShellStateValue } from "./shellState";
|
|
225
227
|
export { secretStorage, storage } from "./storage";
|
|
226
228
|
export { type TransitionType, transitionTypes } from "./transitionTypes";
|
|
227
229
|
export { type AllDictionary, type Dictionary, Translator } from "./translator";
|
package/client/router.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "akanjs/common";
|
|
12
12
|
import { closeAppOpenedTab } from "./appOpenedTab";
|
|
13
13
|
import { CsrLocation, csrLocation } from "./csrLocation";
|
|
14
|
+
import { CsrRuntimeParams } from "./csrRuntimeParams";
|
|
14
15
|
import { Href } from "./href";
|
|
15
16
|
import { isMcpView } from "./mcpView";
|
|
16
17
|
import { type NavigationAttempt, type NavigationGuard, NavigationGuards, NavigationRefused } from "./navigationGuards";
|
|
@@ -128,7 +129,6 @@ export const getRequestRoutePath = (lang: string): string | undefined => {
|
|
|
128
129
|
};
|
|
129
130
|
|
|
130
131
|
const shouldExposeBasePath = () => getEnv().operationMode === "local";
|
|
131
|
-
const CSR_RUNTIME_SEARCH_PARAMS = ["csr", "akanMobileTarget", "akanMobileBasePath", "akanMobileIndexPath"] as const;
|
|
132
132
|
|
|
133
133
|
const normalizeRoutePath = (path: string | undefined) => {
|
|
134
134
|
const normalized = path?.trim();
|
|
@@ -303,14 +303,14 @@ class Router {
|
|
|
303
303
|
push: (href: string, routeOptions) => {
|
|
304
304
|
const { path, pathname, hash, href: fullHref } = this.#getPathInfo(href);
|
|
305
305
|
this.postPathChange({ path, pathname, hash });
|
|
306
|
-
return options.router.push(
|
|
306
|
+
return options.router.push(CsrRuntimeParams.carry(fullHref), routeOptions);
|
|
307
307
|
},
|
|
308
308
|
replace: (href: string, routeOptions) => {
|
|
309
309
|
const { path, pathname, hash, href: fullHref } = this.#getPathInfo(href);
|
|
310
310
|
this.postPathChange({ path, pathname, hash });
|
|
311
311
|
|
|
312
312
|
setTimeout(() => {
|
|
313
|
-
options.router.replace(
|
|
313
|
+
options.router.replace(CsrRuntimeParams.carry(fullHref), routeOptions);
|
|
314
314
|
}, 0);
|
|
315
315
|
},
|
|
316
316
|
back: (routeOptions) => {
|
|
@@ -447,21 +447,6 @@ class Router {
|
|
|
447
447
|
#getNavigationPathInfo(href: string) {
|
|
448
448
|
return this.#getPathInfo(href, shouldExposeBasePath() ? this.#prefix : "");
|
|
449
449
|
}
|
|
450
|
-
#withCsrRuntimeSearchParams(href: string) {
|
|
451
|
-
const currentSearch = new URLSearchParams(csrLocation.search);
|
|
452
|
-
if (currentSearch.get("csr") !== "true" || Href.hasWebScheme(href)) return href;
|
|
453
|
-
|
|
454
|
-
const [hrefWithoutHash, hash = ""] = href.split("#");
|
|
455
|
-
const [pathname, search = ""] = hrefWithoutHash.split("?");
|
|
456
|
-
const nextSearch = new URLSearchParams(search);
|
|
457
|
-
for (const param of CSR_RUNTIME_SEARCH_PARAMS) {
|
|
458
|
-
if (nextSearch.has(param)) continue;
|
|
459
|
-
const value = currentSearch.get(param);
|
|
460
|
-
if (value !== null) nextSearch.set(param, value);
|
|
461
|
-
}
|
|
462
|
-
const query = nextSearch.toString();
|
|
463
|
-
return `${pathname}${query ? `?${query}` : ""}${hash ? `#${hash}` : ""}`;
|
|
464
|
-
}
|
|
465
450
|
#getVisiblePathInfo(href: string, lang = this.#lang) {
|
|
466
451
|
return getPathInfo(href, lang, shouldExposeBasePath() ? this.#prefix : "", this.#localePrefix());
|
|
467
452
|
}
|
|
@@ -660,6 +645,24 @@ class Router {
|
|
|
660
645
|
this.replace(fallbackHref, routeOptions);
|
|
661
646
|
return undefined as never;
|
|
662
647
|
}
|
|
648
|
+
/**
|
|
649
|
+
* Leaves a state of the page a `push` opened — a record in `?id=`, a sheet: steps back when the entry under this one
|
|
650
|
+
* is `href`, and rewrites this entry to `href` otherwise. A CSR stack rewrites a push that keeps the pathname rather
|
|
651
|
+
* than stacking it, and a visitor may have opened this address directly, so `back()` alone would leave the page.
|
|
652
|
+
* Only the one entry under this one is looked at, and the rewrite keeps the scroll unless `scrollToTop` is set.
|
|
653
|
+
*/
|
|
654
|
+
backTo(href: string, routeOptions?: RouteOptions) {
|
|
655
|
+
if (getEnv().side === "server") throw new Error("backTo is only available in client side");
|
|
656
|
+
this.#checkInitialized();
|
|
657
|
+
const { from } = csrLocation.entry();
|
|
658
|
+
const isUnder =
|
|
659
|
+
from !== undefined &&
|
|
660
|
+
this.canGoBack() &&
|
|
661
|
+
CsrRuntimeParams.sameRoute(this.#routeShown(from), Router.#routeHref(this.#getPathInfo(href)));
|
|
662
|
+
if (isUnder) this.back(routeOptions);
|
|
663
|
+
else this.replace(href, { scrollToTop: false, ...routeOptions });
|
|
664
|
+
return undefined as never;
|
|
665
|
+
}
|
|
663
666
|
back(routeOptions?: RouteOptions) {
|
|
664
667
|
if (getEnv().side === "server") throw new Error("back is only available in client side");
|
|
665
668
|
this.#checkInitialized();
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { parseSearchParams } from "akanjs/common";
|
|
2
|
+
import type { PageState } from "./csrTypes";
|
|
3
|
+
import { defaultPageState } from "./frameConfig";
|
|
4
|
+
import { useSyncExternalStore } from "./shellStateHooks";
|
|
5
|
+
|
|
6
|
+
export interface ShellMessage {
|
|
7
|
+
type: "info" | "success" | "error" | "warning" | "loading";
|
|
8
|
+
content: string;
|
|
9
|
+
/** Seconds. */
|
|
10
|
+
duration: number;
|
|
11
|
+
key: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ShellStateValue {
|
|
15
|
+
path: string;
|
|
16
|
+
pathname: string;
|
|
17
|
+
params: { [key: string]: string };
|
|
18
|
+
searchParams: { [key: string]: string | string[] };
|
|
19
|
+
theme: string;
|
|
20
|
+
uiOperation: "sleep" | "loading" | "idle";
|
|
21
|
+
messages: ShellMessage[];
|
|
22
|
+
keyboardHeight: number;
|
|
23
|
+
pageState: PageState;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface ShellStateStore {
|
|
27
|
+
state: ShellStateValue;
|
|
28
|
+
initial: ShellStateValue;
|
|
29
|
+
listeners: Set<() => void>;
|
|
30
|
+
mounts: number;
|
|
31
|
+
mountListeners: Set<() => void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare global {
|
|
35
|
+
var __AKAN_SHELL_STATE__: ShellStateStore | undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const shownMessageLimit = 7;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* What the page shell (`System`, `Link`, the toasts) reads and writes, so a page that uses no store does not load one.
|
|
42
|
+
* `akanjs/store` copies each key to and from its own state of the same name once it is on the page.
|
|
43
|
+
*/
|
|
44
|
+
export class ShellState {
|
|
45
|
+
static readonly keys = [
|
|
46
|
+
"path",
|
|
47
|
+
"pathname",
|
|
48
|
+
"params",
|
|
49
|
+
"searchParams",
|
|
50
|
+
"theme",
|
|
51
|
+
"uiOperation",
|
|
52
|
+
"messages",
|
|
53
|
+
"keyboardHeight",
|
|
54
|
+
"pageState",
|
|
55
|
+
] as const satisfies readonly (keyof ShellStateValue)[];
|
|
56
|
+
|
|
57
|
+
static initial(): ShellStateValue {
|
|
58
|
+
return {
|
|
59
|
+
path: "/",
|
|
60
|
+
pathname: typeof window !== "undefined" ? window.location.pathname : "/",
|
|
61
|
+
params: {},
|
|
62
|
+
|
|
63
|
+
searchParams: typeof window !== "undefined" ? parseSearchParams(window.location.search) : {},
|
|
64
|
+
theme: "system",
|
|
65
|
+
uiOperation: "sleep",
|
|
66
|
+
messages: [],
|
|
67
|
+
keyboardHeight: 0,
|
|
68
|
+
pageState: { ...defaultPageState },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static #store(): ShellStateStore {
|
|
73
|
+
if (!globalThis.__AKAN_SHELL_STATE__) {
|
|
74
|
+
const initial = ShellState.initial();
|
|
75
|
+
globalThis.__AKAN_SHELL_STATE__ = {
|
|
76
|
+
state: initial,
|
|
77
|
+
initial,
|
|
78
|
+
listeners: new Set(),
|
|
79
|
+
mounts: 0,
|
|
80
|
+
mountListeners: new Set(),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return globalThis.__AKAN_SHELL_STATE__;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
static get(): ShellStateValue {
|
|
87
|
+
return ShellState.#store().state;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static set(patch: Partial<ShellStateValue>) {
|
|
91
|
+
|
|
92
|
+
if (typeof window === "undefined") return;
|
|
93
|
+
const store = ShellState.#store();
|
|
94
|
+
const keys = (Object.keys(patch) as (keyof ShellStateValue)[]).filter(
|
|
95
|
+
(key) => !Object.is(store.state[key], patch[key]),
|
|
96
|
+
);
|
|
97
|
+
if (!keys.length) return;
|
|
98
|
+
store.state = { ...store.state, ...patch };
|
|
99
|
+
for (const listener of [...store.listeners]) listener();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static subscribe(listener: () => void) {
|
|
103
|
+
const { listeners } = ShellState.#store();
|
|
104
|
+
listeners.add(listener);
|
|
105
|
+
return () => {
|
|
106
|
+
listeners.delete(listener);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static use<Key extends keyof ShellStateValue>(key: Key): ShellStateValue[Key] {
|
|
111
|
+
return useSyncExternalStore(
|
|
112
|
+
ShellState.subscribe,
|
|
113
|
+
() => ShellState.#store().state[key],
|
|
114
|
+
() => ShellState.#store().initial[key],
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static messagesWith(messages: ShellMessage[], message: ShellMessage): ShellMessage[] {
|
|
119
|
+
if (messages.some((shown) => shown.key === message.key))
|
|
120
|
+
return messages.map((shown) => (shown.key === message.key ? message : shown));
|
|
121
|
+
return [...(messages.length >= shownMessageLimit ? messages.slice(1) : messages), message];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static showMessage(message: Omit<Partial<ShellMessage>, "content"> & { content: string | string[] }) {
|
|
125
|
+
const key = message.key ?? Math.random().toString(36).slice(2, 15);
|
|
126
|
+
const shown = { type: "info", duration: 3, ...message, key };
|
|
127
|
+
ShellState.set({ messages: ShellState.messagesWith(ShellState.get().messages, shown as ShellMessage) });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static hideMessage(key: string) {
|
|
131
|
+
ShellState.set({ messages: ShellState.get().messages.filter((message) => message.key !== key) });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static mount() {
|
|
135
|
+
const store = ShellState.#store();
|
|
136
|
+
store.mounts += 1;
|
|
137
|
+
for (const listener of [...store.mountListeners]) listener();
|
|
138
|
+
return () => {
|
|
139
|
+
store.mounts -= 1;
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static onMount(listener: () => void) {
|
|
144
|
+
const store = ShellState.#store();
|
|
145
|
+
store.mountListeners.add(listener);
|
|
146
|
+
if (store.mounts > 0) listener();
|
|
147
|
+
return () => {
|
|
148
|
+
store.mountListeners.delete(listener);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
package/index.ts
CHANGED
|
@@ -13,9 +13,16 @@ export interface DockerImageConfig {
|
|
|
13
13
|
image: string | { [key in Arch]?: string };
|
|
14
14
|
/** Runs before `bun install`, so a system package a native dependency needs is there for the install. */
|
|
15
15
|
preRuns: DockerRun[];
|
|
16
|
+
/** Runs in the layer of `bun install`, so what a step deletes from `node_modules` never reaches the image. */
|
|
17
|
+
installRuns: DockerRun[];
|
|
16
18
|
/** Runs after `bun install`, before the app files are copied. */
|
|
17
19
|
postRuns: DockerRun[];
|
|
18
20
|
command: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Installs in a stage of the build machine's own architecture, for the target's: `docker buildx build --platform`
|
|
23
|
+
* for another architecture then never runs Bun emulated. A dependency's lifecycle script runs on the build machine.
|
|
24
|
+
*/
|
|
25
|
+
crossBuild: boolean;
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
/** The string form is taken verbatim: nothing is merged into it, not even a lib's `docker` steps. */
|
|
@@ -26,6 +33,7 @@ export type DockerOption = string | Partial<DockerImageConfig>;
|
|
|
26
33
|
/** Steps every app mounting the lib inherits; a lib never picks the base image or the command. */
|
|
27
34
|
export interface LibDockerConfig {
|
|
28
35
|
preRuns: DockerRun[];
|
|
36
|
+
installRuns: DockerRun[];
|
|
29
37
|
postRuns: DockerRun[];
|
|
30
38
|
}
|
|
31
39
|
|
|
@@ -80,6 +88,8 @@ export interface AkanRouteDomains {
|
|
|
80
88
|
export interface AkanRouteConfig {
|
|
81
89
|
basePath?: string;
|
|
82
90
|
domains: AkanRouteDomains;
|
|
91
|
+
/** The lib pages this `basePath` mounts in place of the app's `syncPageLibs`: `false` none, an array exactly those libs. */
|
|
92
|
+
syncPageLibs?: string[] | boolean;
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
/** `ssr`: the RSC/SSR renderer with its bundles and RSC worker; `csr`: the SPA shell the native apps ship and `/__csr` serves. */
|
package/package.json
CHANGED
package/server/akanServer.ts
CHANGED
|
@@ -52,6 +52,8 @@ export interface AkanServerOptions {
|
|
|
52
52
|
mcp?: boolean | McpServerOption;
|
|
53
53
|
/** Boot only these modules and what they reach; omitted or empty mounts every enabled module. */
|
|
54
54
|
modules?: string[];
|
|
55
|
+
/** Mount these whatever their `enabled` or `operationMode` says: how a test server reaches a gated module. */
|
|
56
|
+
enableModules?: string[];
|
|
55
57
|
/** Mount all but these and whatever reaches them; applied after `modules`, so one named by both stays out. */
|
|
56
58
|
disableModules?: string[];
|
|
57
59
|
/** Like `disableModules`, by owning lib, so it does not drift as the lib gains modules. */
|
|
@@ -209,7 +211,13 @@ export class AkanServer {
|
|
|
209
211
|
this.disableModules = options?.disableModules ?? ServerConfig.envList("AKAN_DISABLE_MODULES") ?? [];
|
|
210
212
|
this.disableLibs = options?.disableLibs ?? ServerConfig.envList("AKAN_DISABLE_LIBS") ?? [];
|
|
211
213
|
this.#di = new DiLifecycle(
|
|
212
|
-
{
|
|
214
|
+
{
|
|
215
|
+
env: this.env,
|
|
216
|
+
modules: this.modules,
|
|
217
|
+
enableModules: options?.enableModules,
|
|
218
|
+
disableModules: this.disableModules,
|
|
219
|
+
disableLibs: this.disableLibs,
|
|
220
|
+
},
|
|
213
221
|
...libs,
|
|
214
222
|
);
|
|
215
223
|
const webRouter = () => this.#webRouter;
|