akanjs 3.1.0-rc.14 → 3.1.0-rc.16
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/client/makePageProto.tsx +3 -2
- package/client/translator.ts +16 -0
- package/client/viewportMeta.ts +23 -8
- package/package.json +1 -1
- package/store/agent/StoreSurfaceSource.ts +8 -3
- package/types/client/translator.d.ts +2 -0
- package/types/ui/Agent/Composer.d.ts +2 -0
- package/types/ui/Agent/Menu.d.ts +2 -0
- package/types/ui/CsrImage.d.ts +2 -0
- package/types/ui/Image.d.ts +3 -1
- package/types/webkit/useDebounce.d.ts +1 -1
- package/ui/Agent/Chat.tsx +1 -0
- package/ui/Agent/Composer.tsx +2 -0
- package/ui/Agent/Menu.tsx +5 -1
- package/ui/Agent/useReferenceMenu.ts +1 -0
- package/ui/Agent/useSlashMenu.ts +1 -0
- package/ui/CsrImage.tsx +3 -1
- package/ui/Image.tsx +4 -4
- package/ui/styles.css +10 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeBridge.swift +3 -2
- package/webkit/RenderLayer.tsx +23 -4
- package/webkit/useDebounce.ts +23 -14
package/client/makePageProto.tsx
CHANGED
|
@@ -28,11 +28,12 @@ const getPageInfo = (): { locale: string; path: string } => {
|
|
|
28
28
|
const activePath = Translator.getActivePath();
|
|
29
29
|
if (activePath) return { locale: activeLocale ?? defaultLocale, path: activePath };
|
|
30
30
|
if (getEnv().side !== "server") {
|
|
31
|
-
const
|
|
31
|
+
const pathname = Translator.getRenderPath() ?? csrLocation.pathname;
|
|
32
|
+
const [, firstSegment = "", ...rest] = pathname.split("/");
|
|
32
33
|
const hasLocalePrefix = localeSet.has(firstSegment);
|
|
33
34
|
|
|
34
35
|
const locale = activeLocale ?? (hasLocalePrefix ? firstSegment : defaultLocale);
|
|
35
|
-
return { locale, path:
|
|
36
|
+
return { locale, path: hasLocalePrefix ? `/${rest.join("/")}` : pathname };
|
|
36
37
|
}
|
|
37
38
|
const h = untrackedHeaders();
|
|
38
39
|
|
package/client/translator.ts
CHANGED
|
@@ -18,6 +18,8 @@ interface TranslatorState {
|
|
|
18
18
|
activeLocale?: string;
|
|
19
19
|
|
|
20
20
|
activePath?: string;
|
|
21
|
+
|
|
22
|
+
renderPath?: string;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const TRANSLATOR_STATE_KEY = "__AKAN_TRANSLATOR_STATE__";
|
|
@@ -57,6 +59,20 @@ export class Translator {
|
|
|
57
59
|
static getActivePath(): string | undefined {
|
|
58
60
|
return getTranslatorState().activePath;
|
|
59
61
|
}
|
|
62
|
+
static renderAt<T>(path: string | undefined, render: () => T): T {
|
|
63
|
+
if (!path) return render();
|
|
64
|
+
const state = getTranslatorState();
|
|
65
|
+
const outer = state.renderPath;
|
|
66
|
+
state.renderPath = path;
|
|
67
|
+
try {
|
|
68
|
+
return render();
|
|
69
|
+
} finally {
|
|
70
|
+
state.renderPath = outer;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
static getRenderPath(): string | undefined {
|
|
74
|
+
return getTranslatorState().renderPath;
|
|
75
|
+
}
|
|
60
76
|
static markHydrated() {
|
|
61
77
|
delete getTranslatorState().activePath;
|
|
62
78
|
}
|
package/client/viewportMeta.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface ThemeColorTag {
|
|
|
7
7
|
|
|
8
8
|
/** Turns a root layout's `.viewport()` into the `viewport` and `theme-color` meta tags every document shell writes. */
|
|
9
9
|
export class ViewportMeta {
|
|
10
|
+
static readonly #offMedia = "not all";
|
|
11
|
+
static readonly #ownAttr = "data-akan-theme-color";
|
|
12
|
+
|
|
10
13
|
static content(viewport: RouteViewport | undefined, { native = false }: { native?: boolean } = {}): string {
|
|
11
14
|
const parts = ["width=device-width", "initial-scale=1"];
|
|
12
15
|
if (viewport?.fitCover ?? native) parts.push("viewport-fit=cover");
|
|
@@ -39,18 +42,30 @@ export class ViewportMeta {
|
|
|
39
42
|
const tags = ViewportMeta.themeColors(viewport, theme);
|
|
40
43
|
if (!tags.length) return;
|
|
41
44
|
const existing = [...document.head.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]')];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
const live = existing.filter((meta) => meta.getAttribute("media") !== ViewportMeta.#offMedia);
|
|
46
|
+
const isCurrent =
|
|
47
|
+
live.length === tags.length &&
|
|
48
|
+
tags.every(
|
|
49
|
+
(tag, idx) => live[idx]?.content === tag.content && live[idx]?.getAttribute("media") === (tag.media ?? null),
|
|
50
|
+
);
|
|
51
|
+
if (isCurrent) return;
|
|
52
|
+
|
|
53
|
+
for (const meta of existing) {
|
|
54
|
+
if (meta.hasAttribute(ViewportMeta.#ownAttr)) meta.remove();
|
|
55
|
+
else meta.setAttribute("media", ViewportMeta.#offMedia);
|
|
56
|
+
}
|
|
57
|
+
for (const tag of tags) {
|
|
58
|
+
const meta = document.createElement("meta");
|
|
59
|
+
meta.name = "theme-color";
|
|
46
60
|
meta.content = tag.content;
|
|
47
61
|
if (tag.media) meta.setAttribute("media", tag.media);
|
|
48
|
-
|
|
49
|
-
|
|
62
|
+
meta.setAttribute(ViewportMeta.#ownAttr, "");
|
|
63
|
+
document.head.appendChild(meta);
|
|
64
|
+
}
|
|
50
65
|
}
|
|
51
66
|
|
|
52
|
-
static #ensureMeta(name: string
|
|
53
|
-
const found =
|
|
67
|
+
static #ensureMeta(name: string): HTMLMetaElement {
|
|
68
|
+
const found = document.head.querySelector<HTMLMetaElement>(`meta[name="${name}"]`);
|
|
54
69
|
if (found) return found;
|
|
55
70
|
const meta = document.createElement("meta");
|
|
56
71
|
meta.name = name;
|
package/package.json
CHANGED
|
@@ -162,14 +162,19 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
162
162
|
|
|
163
163
|
static #viewImage(viewKey: string): ToolEntry {
|
|
164
164
|
const absent = (src: string) =>
|
|
165
|
-
`No picture at ${src} is on screen now. Call readScreen with images: true and pass
|
|
165
|
+
`No picture at ${src} is on screen now. Call readScreen with images: true and pass the <address> of an [image: <alt>](<address>) it prints; a picture that has left the screen cannot be viewed.`;
|
|
166
166
|
return {
|
|
167
167
|
name: "viewImage",
|
|
168
168
|
description:
|
|
169
|
-
"Look at one picture on screen, to answer from what it shows rather than from its caption.
|
|
169
|
+
"Look at one picture on screen, to answer from what it shows rather than from its caption. readScreen with `images: true` prints each picture as `[image: <alt>](<address>)`, or `[image](<address>)` when it has no alt; pass that address. Each picture costs this turn over a thousand tokens, so view only the ones the answer needs.",
|
|
170
170
|
parameters: {
|
|
171
171
|
type: "object",
|
|
172
|
-
properties: {
|
|
172
|
+
properties: {
|
|
173
|
+
src: {
|
|
174
|
+
type: "string",
|
|
175
|
+
description: "The <address> of an [image: <alt>](<address>) readScreen printed, without the parentheses.",
|
|
176
|
+
},
|
|
177
|
+
},
|
|
173
178
|
required: ["src"],
|
|
174
179
|
additionalProperties: false,
|
|
175
180
|
},
|
|
@@ -14,6 +14,8 @@ export declare class Translator {
|
|
|
14
14
|
static getActiveLocale(): string | undefined;
|
|
15
15
|
static setActivePath(path: string | undefined): void;
|
|
16
16
|
static getActivePath(): string | undefined;
|
|
17
|
+
static renderAt<T>(path: string | undefined, render: () => T): T;
|
|
18
|
+
static getRenderPath(): string | undefined;
|
|
17
19
|
static markHydrated(): void;
|
|
18
20
|
static translateByLocale(lang: string, key: string, param?: Record<string, string | number>): string;
|
|
19
21
|
static withDefaultLocale(allDictionary: AllDictionary, lang: string): Dictionary | undefined;
|
|
@@ -31,6 +31,8 @@ export interface ComposerProps {
|
|
|
31
31
|
inputRef?: RefObject<HTMLTextAreaElement | null>;
|
|
32
32
|
/** Draws each `@` pointer as its name; set only when the chat has `reference` sources. */
|
|
33
33
|
mentions?: boolean;
|
|
34
|
+
/** A `/` or `@` menu is up and `onKeyDown` picks from it: an override that takes Enter for a newline passes it on. */
|
|
35
|
+
isMenuOpen?: boolean;
|
|
34
36
|
/** Filled by whichever input is drawn. An override that draws its own textarea leaves it null and `inputRef` answers. */
|
|
35
37
|
handleRef?: RefObject<ComposerHandle | null>;
|
|
36
38
|
}
|
package/types/ui/Agent/Menu.d.ts
CHANGED
package/types/ui/CsrImage.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ type CsrImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "alt" | "src"> &
|
|
|
14
14
|
quality?: number;
|
|
15
15
|
unoptimized?: boolean;
|
|
16
16
|
fill?: boolean;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
blurDataURL?: string;
|
|
17
19
|
};
|
|
18
20
|
export declare const CsrImage: ({ src, alt, file, className, abstractData, ...props }: CsrImageProps) => import("react").JSX.Element;
|
|
19
21
|
export {};
|
package/types/ui/Image.d.ts
CHANGED
|
@@ -7,14 +7,16 @@ type ImageLikeFile = ProtoLightFile | {
|
|
|
7
7
|
} | null;
|
|
8
8
|
type NativeImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "alt" | "src" | "srcSet"> & {
|
|
9
9
|
fill?: boolean;
|
|
10
|
+
/** Accepted for next/image compatibility; an `<img>` has no such attribute, so it draws nothing. */
|
|
10
11
|
placeholder?: string;
|
|
12
|
+
/** Accepted for next/image compatibility; an `<img>` has no such attribute, so it draws nothing. */
|
|
11
13
|
blurDataURL?: string;
|
|
12
14
|
};
|
|
13
15
|
type AkanImageProps = NativeImageProps & {
|
|
14
16
|
/** Takes precedence over `file.url`. */
|
|
15
17
|
src?: string;
|
|
16
18
|
file?: ImageLikeFile;
|
|
17
|
-
/** Overrides `file.abstractData
|
|
19
|
+
/** Overrides `file.abstractData`, which no render path draws as a placeholder. */
|
|
18
20
|
abstractData?: string | null;
|
|
19
21
|
/** Defaults to "image". */
|
|
20
22
|
alt?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useDebounce: <Args extends unknown[], Return>(callback: (...args: Args) => Return,
|
|
1
|
+
export declare const useDebounce: <Args extends unknown[], Return>(callback: (...args: Args) => Return, _states?: unknown[], wait?: number) => (...args: Args) => void;
|
package/ui/Agent/Chat.tsx
CHANGED
|
@@ -533,6 +533,7 @@ export const DefaultChat = ({
|
|
|
533
533
|
draft={draft}
|
|
534
534
|
handleRef={handleRef}
|
|
535
535
|
inputRef={inputRef}
|
|
536
|
+
isMenuOpen={!!list.at()}
|
|
536
537
|
mentions={mentions ?? !!reference?.length}
|
|
537
538
|
{...(speech.canListen ? { mic: { listening: speech.listening, onToggle: speech.toggle } } : {})}
|
|
538
539
|
onDraft={write}
|
package/ui/Agent/Composer.tsx
CHANGED
|
@@ -39,6 +39,8 @@ export interface ComposerProps {
|
|
|
39
39
|
inputRef?: RefObject<HTMLTextAreaElement | null>;
|
|
40
40
|
/** Draws each `@` pointer as its name; set only when the chat has `reference` sources. */
|
|
41
41
|
mentions?: boolean;
|
|
42
|
+
/** A `/` or `@` menu is up and `onKeyDown` picks from it: an override that takes Enter for a newline passes it on. */
|
|
43
|
+
isMenuOpen?: boolean;
|
|
42
44
|
/** Filled by whichever input is drawn. An override that draws its own textarea leaves it null and `inputRef` answers. */
|
|
43
45
|
handleRef?: RefObject<ComposerHandle | null>;
|
|
44
46
|
}
|
package/ui/Agent/Menu.tsx
CHANGED
|
@@ -3,6 +3,8 @@ import { cn } from "akanjs/client";
|
|
|
3
3
|
import { createOverridable } from "../UiOverride";
|
|
4
4
|
|
|
5
5
|
export interface MenuRow {
|
|
6
|
+
/** Unique among the rows; `name` repeats when two records share a title. */
|
|
7
|
+
id: string;
|
|
6
8
|
name: string;
|
|
7
9
|
description?: string;
|
|
8
10
|
/** The argument names a row takes. */
|
|
@@ -36,8 +38,10 @@ export const DefaultAgentMenu = ({ className, rows, selected, prefix = "/", onPi
|
|
|
36
38
|
"flex items-baseline gap-2 px-4 py-1.5 text-left hover:bg-muted",
|
|
37
39
|
idx === selected && "bg-muted",
|
|
38
40
|
)}
|
|
39
|
-
key={row.
|
|
41
|
+
key={row.id}
|
|
40
42
|
onClick={() => onPick(row)}
|
|
43
|
+
|
|
44
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
41
45
|
role="option"
|
|
42
46
|
type="button"
|
|
43
47
|
>
|
|
@@ -68,6 +68,7 @@ export const useReferenceMenu = ({ draft, sources, session, l, onWrite }: Refere
|
|
|
68
68
|
setRows(
|
|
69
69
|
found.flatMap((candidates, at) =>
|
|
70
70
|
candidates.map((candidate) => ({
|
|
71
|
+
id: `${current[at].refName}/${candidate.refId}`,
|
|
71
72
|
name: candidate.label,
|
|
72
73
|
description: candidate.description ?? current[at].label,
|
|
73
74
|
pick: () => write(candidate, current[at]),
|
package/ui/Agent/useSlashMenu.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const useSlashMenu = ({ draft, l, onCommand }: SlashMenuSetup) => {
|
|
|
19
19
|
? ChatCommands.list(l)
|
|
20
20
|
.filter((command) => `/${command.name}`.startsWith(query))
|
|
21
21
|
.map((command) => ({
|
|
22
|
+
id: command.name,
|
|
22
23
|
name: command.name,
|
|
23
24
|
description: command.description,
|
|
24
25
|
pick: () => onCommand(command),
|
package/ui/CsrImage.tsx
CHANGED
|
@@ -13,6 +13,8 @@ type CsrImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "alt" | "src"> &
|
|
|
13
13
|
quality?: number;
|
|
14
14
|
unoptimized?: boolean;
|
|
15
15
|
fill?: boolean;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
blurDataURL?: string;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
const EMPTY_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
|
@@ -24,7 +26,7 @@ export const CsrImage = ({ src, alt, file, className, abstractData, ...props }:
|
|
|
24
26
|
const defaultAbstractData =
|
|
25
27
|
"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFklEQVR42mN8//HLfwYiAOOoQvoqBABbWyZJf74GZgAAAABJRU5ErkJggg==";
|
|
26
28
|
const blurDataURL = abstractData ?? file?.abstractData ?? defaultAbstractData;
|
|
27
|
-
const { priority, preload, quality, unoptimized, fill, ...csrProps } = props;
|
|
29
|
+
const { priority, preload, quality, unoptimized, fill, placeholder, blurDataURL: _blurDataURL, ...csrProps } = props;
|
|
28
30
|
return (
|
|
29
31
|
<img
|
|
30
32
|
src={url ?? EMPTY_IMAGE}
|
package/ui/Image.tsx
CHANGED
|
@@ -19,7 +19,9 @@ const EMPTY_IMAGE = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAAL
|
|
|
19
19
|
|
|
20
20
|
type NativeImageProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "alt" | "src" | "srcSet"> & {
|
|
21
21
|
fill?: boolean;
|
|
22
|
+
/** Accepted for next/image compatibility; an `<img>` has no such attribute, so it draws nothing. */
|
|
22
23
|
placeholder?: string;
|
|
24
|
+
/** Accepted for next/image compatibility; an `<img>` has no such attribute, so it draws nothing. */
|
|
23
25
|
blurDataURL?: string;
|
|
24
26
|
};
|
|
25
27
|
|
|
@@ -27,7 +29,7 @@ type AkanImageProps = NativeImageProps & {
|
|
|
27
29
|
/** Takes precedence over `file.url`. */
|
|
28
30
|
src?: string;
|
|
29
31
|
file?: ImageLikeFile;
|
|
30
|
-
/** Overrides `file.abstractData
|
|
32
|
+
/** Overrides `file.abstractData`, which no render path draws as a placeholder. */
|
|
31
33
|
abstractData?: string | null;
|
|
32
34
|
/** Defaults to "image". */
|
|
33
35
|
alt?: string;
|
|
@@ -63,7 +65,6 @@ export const Image = (
|
|
|
63
65
|
const url = src || file?.url || null;
|
|
64
66
|
const [width, height] = [props.width ?? file?.imageSize[0], props.height ?? file?.imageSize[1]];
|
|
65
67
|
|
|
66
|
-
const blurDataURL = abstractData ?? file?.abstractData;
|
|
67
68
|
const isPriority = Boolean(priority || preload);
|
|
68
69
|
|
|
69
70
|
const optimized = url
|
|
@@ -79,7 +80,7 @@ export const Image = (
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
const { fill, ...imgProps } = props;
|
|
83
|
+
const { fill, placeholder, blurDataURL, ...imgProps } = props;
|
|
83
84
|
|
|
84
85
|
return (
|
|
85
86
|
<img
|
|
@@ -93,7 +94,6 @@ export const Image = (
|
|
|
93
94
|
loading={props.loading ?? (isPriority ? "eager" : "lazy")}
|
|
94
95
|
decoding={props.decoding ?? "async"}
|
|
95
96
|
fetchPriority={props.fetchPriority ?? (isPriority ? "high" : undefined)}
|
|
96
|
-
{...(blurDataURL ? { placeholder: "blur", blurDataURL } : {})}
|
|
97
97
|
{...imgProps}
|
|
98
98
|
/>
|
|
99
99
|
);
|
package/ui/styles.css
CHANGED
|
@@ -140,6 +140,16 @@ body {
|
|
|
140
140
|
-webkit-user-select: none; */
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/* An installed web app's document does not rubber-band; in a browser tab the page keeps the browser's own feel. */
|
|
144
|
+
@layer base {
|
|
145
|
+
@media (display-mode: standalone) {
|
|
146
|
+
html,
|
|
147
|
+
body {
|
|
148
|
+
overscroll-behavior-y: none;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
143
153
|
html.akan-mobile-document,
|
|
144
154
|
body.akan-mobile-document {
|
|
145
155
|
width: 100%;
|
|
@@ -194,8 +194,9 @@ final class AkanNativeBridge: NSObject {
|
|
|
194
194
|
return AkanNativeLog.info("emit \(plugin).\(event): data is not JSON, dropped")
|
|
195
195
|
}
|
|
196
196
|
// Arguments go in as values, so no JS string escaping is involved.
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
// The ObjC method: below an iOS 18.4 target Swift's Result overlay links libswiftWebKit.dylib, absent on iOS 18.5.
|
|
198
|
+
webView.__callAsyncJavaScript("window.__AKAN_NATIVE__ && window.__AKAN_NATIVE__.receive(m)", arguments: ["m": text], inFrame: nil, in: .page) { _, error in
|
|
199
|
+
if let error { AkanNativeLog.info("emit \(plugin).\(event) failed: \(error)") }
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
|
package/webkit/RenderLayer.tsx
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
csrLocation,
|
|
4
|
+
debugFrame,
|
|
5
|
+
RouteDefinition,
|
|
6
|
+
type RouteRender,
|
|
7
|
+
router,
|
|
8
|
+
Translator,
|
|
9
|
+
usePathCtx,
|
|
10
|
+
} from "akanjs/client";
|
|
3
11
|
import { isThenable, Logger } from "akanjs/common";
|
|
4
12
|
import { createContext, createElement, memo, type ReactNode, useContext, useEffect, useRef, useState } from "react";
|
|
5
13
|
import { CsrFrameDump } from "./csrFrameDump";
|
|
@@ -64,7 +72,10 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
64
72
|
};
|
|
65
73
|
}, [activity]);
|
|
66
74
|
|
|
67
|
-
const
|
|
75
|
+
const location = (usePathCtx() as Partial<ReturnType<typeof usePathCtx>>).location;
|
|
76
|
+
const path = location?.pathRoute.path ?? "the root";
|
|
77
|
+
|
|
78
|
+
const renderPath = entryPathOf(location?.pathname);
|
|
68
79
|
if (isAsyncRender && routeRender) {
|
|
69
80
|
const argsKey = RouteDefinition.renderArgsKey(
|
|
70
81
|
routeRender.render,
|
|
@@ -84,7 +95,10 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
84
95
|
const redirectsBefore = router.redirectCount();
|
|
85
96
|
const layer = `${routeRender.kind ?? "layout"} ${index} of ${path}`;
|
|
86
97
|
const result = reportFailure(
|
|
87
|
-
|
|
98
|
+
Translator.renderAt(
|
|
99
|
+
renderPath,
|
|
100
|
+
() => routeRender.render({ children: layerOutlet, params, searchParams } as never) ?? null,
|
|
101
|
+
),
|
|
88
102
|
layer,
|
|
89
103
|
);
|
|
90
104
|
const next: RenderedRoute = {
|
|
@@ -133,7 +147,7 @@ export const RenderLayer = memo((props: RenderLayerProps) => {
|
|
|
133
147
|
}}
|
|
134
148
|
/>
|
|
135
149
|
);
|
|
136
|
-
if (!value) return <>{composeLoadingFallback(renders.slice(index), params)}</>;
|
|
150
|
+
if (!value) return <>{Translator.renderAt(renderPath, () => composeLoadingFallback(renders.slice(index), params))}</>;
|
|
137
151
|
return frame(<layerChildContext.Provider value={children}>{value}</layerChildContext.Provider>);
|
|
138
152
|
});
|
|
139
153
|
|
|
@@ -152,6 +166,11 @@ function reportFailure(result: ReactNode | Promise<ReactNode>, layer: string): R
|
|
|
152
166
|
return result;
|
|
153
167
|
}
|
|
154
168
|
|
|
169
|
+
function entryPathOf(pathname: string | undefined): string | undefined {
|
|
170
|
+
if (!pathname || csrLocation.isMemory) return pathname;
|
|
171
|
+
return new URL(`http://localhost${pathname}`).pathname;
|
|
172
|
+
}
|
|
173
|
+
|
|
155
174
|
function isAsyncRouteRender(routeRender?: RouteRender): boolean {
|
|
156
175
|
return Boolean(routeRender?.isAsync || routeRender?.render.constructor.name === "AsyncFunction");
|
|
157
176
|
}
|
package/webkit/useDebounce.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback } from "react";
|
|
3
|
-
|
|
4
|
-
const debounce = <Args extends unknown[], Return>(callback: (...args: Args) => Return, wait = 500) => {
|
|
5
|
-
let timer: NodeJS.Timeout;
|
|
6
|
-
return (...args: Args) => {
|
|
7
|
-
clearTimeout(timer);
|
|
8
|
-
timer = setTimeout(() => {
|
|
9
|
-
callback(...args);
|
|
10
|
-
}, wait);
|
|
11
|
-
};
|
|
12
|
-
};
|
|
2
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
13
3
|
|
|
14
4
|
export const useDebounce = <Args extends unknown[], Return>(
|
|
15
5
|
callback: (...args: Args) => Return,
|
|
16
|
-
|
|
6
|
+
_states: unknown[] = [],
|
|
17
7
|
wait = 100,
|
|
18
8
|
) => {
|
|
19
|
-
const
|
|
20
|
-
|
|
9
|
+
const savedCallback = useRef(callback);
|
|
10
|
+
const pending = useRef<{ timer: ReturnType<typeof setTimeout>; args: Args } | null>(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
savedCallback.current = callback;
|
|
13
|
+
}, [callback]);
|
|
14
|
+
const flush = useCallback(() => {
|
|
15
|
+
const call = pending.current;
|
|
16
|
+
if (!call) return;
|
|
17
|
+
clearTimeout(call.timer);
|
|
18
|
+
pending.current = null;
|
|
19
|
+
savedCallback.current(...call.args);
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
useEffect(() => flush, []);
|
|
23
|
+
return useCallback(
|
|
24
|
+
(...args: Args) => {
|
|
25
|
+
if (pending.current) clearTimeout(pending.current.timer);
|
|
26
|
+
pending.current = { timer: setTimeout(flush, wait), args };
|
|
27
|
+
},
|
|
28
|
+
[wait],
|
|
29
|
+
);
|
|
21
30
|
};
|