@lmzhen/dsh-evolution-client-kit 0.47.0 → 0.49.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/lib/generated/i18n/evolution-merge.js +48 -16
- package/lib/index.js +59 -319
- package/lib/types/generated/contracts.generated.d.ts +0 -2
- package/lib/types/generated/i18n/evolution-merge.d.ts +40 -8
- package/lib/types/generated/i18n/evolution-merge.js +48 -16
- package/lib/types/generated/i18n.generated.d.ts +40 -8
- package/lib/types/index.d.ts +3 -9
- package/lib/types/index.js +3 -7
- package/lib/types/locale.d.ts +17 -0
- package/lib/types/locale.js +53 -0
- package/lib/types/panel.d.ts +2 -3
- package/lib/types/panel.js +4 -47
- package/lib/types/presentation/action-menu.d.ts +0 -14
- package/lib/types/presentation/action-menu.js +0 -25
- package/lib/types/styles.d.ts +4 -0
- package/lib/types/styles.js +13 -0
- package/lib/types/workbench-view.js +4 -43
- package/package.json +1 -1
- package/lib/types/action.d.ts +0 -42
- package/lib/types/action.js +0 -46
- package/lib/types/async-resource.d.ts +0 -48
- package/lib/types/async-resource.js +0 -96
- package/lib/types/notice.d.ts +0 -18
- package/lib/types/notice.js +0 -17
- package/lib/types/presentation/chips.d.ts +0 -23
- package/lib/types/presentation/chips.js +0 -24
- package/lib/types/presentation/disclosure-group.d.ts +0 -13
- package/lib/types/presentation/disclosure-group.js +0 -11
- package/lib/types/presentation/time-text.d.ts +0 -15
- package/lib/types/presentation/time-text.js +0 -20
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const FALLBACK_LOCALE = 'en';
|
|
2
|
+
function interpolate(text, values) {
|
|
3
|
+
if (values === undefined)
|
|
4
|
+
return text;
|
|
5
|
+
return text.replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ''));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Fill `{slot}` placeholders, keeping an unmatched placeholder visible.
|
|
9
|
+
* This is the panel-copy contract (a missing value is a bug to see, not an empty string).
|
|
10
|
+
*/
|
|
11
|
+
export function fillTemplate(text, values) {
|
|
12
|
+
if (values === undefined)
|
|
13
|
+
return text;
|
|
14
|
+
return text.replace(/\{(\w+)\}/g, (match, key) => {
|
|
15
|
+
const value = values[key];
|
|
16
|
+
return value === undefined ? match : String(value);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/** Register one namespace's dictionaries and bind a fallback-first lookup. */
|
|
20
|
+
export function bindLocale(ctx, namespace, dictionaries, fallback = FALLBACK_LOCALE, register = true) {
|
|
21
|
+
const seam = ctx;
|
|
22
|
+
let registered = !register;
|
|
23
|
+
if (register) {
|
|
24
|
+
ctx.effect(() => {
|
|
25
|
+
try {
|
|
26
|
+
const dispose = seam.locale.register(namespace, dictionaries);
|
|
27
|
+
registered = true;
|
|
28
|
+
return dispose;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
ctx.logger.warn(namespace + ': the locale seat refused the dictionary (' + String(error) + '); falls back to the bundle copy');
|
|
32
|
+
return () => { };
|
|
33
|
+
}
|
|
34
|
+
}, namespace + ': locale');
|
|
35
|
+
}
|
|
36
|
+
const own = dictionaries[fallback] ?? dictionaries.en;
|
|
37
|
+
const lookup = (key) => {
|
|
38
|
+
const fallbackText = own[key] ?? key;
|
|
39
|
+
if (!registered)
|
|
40
|
+
return fallbackText;
|
|
41
|
+
try {
|
|
42
|
+
return seam.locale.bind(namespace)(key);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return fallbackText;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
t: (key, values) => interpolate(lookup(key), values),
|
|
50
|
+
label: () => lookup('entry.label'),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=locale.js.map
|
package/lib/types/panel.d.ts
CHANGED
|
@@ -6,10 +6,9 @@ import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
|
6
6
|
import type { ReactNode } from 'react';
|
|
7
7
|
import type { ClientSeam, LocaleDictionaries } from './seam.ts';
|
|
8
8
|
import type { SupportedLocale } from './generated/i18n.generated.ts';
|
|
9
|
-
|
|
10
|
-
export type Translate
|
|
9
|
+
import { type Translate } from './locale.ts';
|
|
10
|
+
export type { Translate } from './locale.ts';
|
|
11
11
|
/** The feature-specific part of one sidebar panel. */
|
|
12
|
-
export declare const FALLBACK_LOCALE: "en";
|
|
13
12
|
export interface SidebarPanelSpec<Face> {
|
|
14
13
|
/** The row id; the keyed main body uses the same value. */
|
|
15
14
|
id: string;
|
package/lib/types/panel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { bindLocale, FALLBACK_LOCALE } from "./locale.js";
|
|
2
|
+
import { injectPluginStyles } from "./styles.js";
|
|
3
3
|
/** Fail loud when a client bundle is mounted without the shell seats it consumes. */
|
|
4
4
|
export function requireClientSeats(ctx, owner) {
|
|
5
5
|
const candidate = ctx;
|
|
@@ -8,24 +8,6 @@ export function requireClientSeats(ctx, owner) {
|
|
|
8
8
|
}
|
|
9
9
|
return candidate;
|
|
10
10
|
}
|
|
11
|
-
function interpolate(text, values) {
|
|
12
|
-
if (values === undefined)
|
|
13
|
-
return text;
|
|
14
|
-
return text.replace(/\{(\w+)\}/g, (_match, key) => String(values[key] ?? ''));
|
|
15
|
-
}
|
|
16
|
-
function injectStyles(doc, css, tagId) {
|
|
17
|
-
if (doc === undefined)
|
|
18
|
-
return () => { };
|
|
19
|
-
const previous = doc.querySelector('style[data-plugin-css="' + tagId + '"]');
|
|
20
|
-
// P2-29: a new owner must OUTLIVE the old owner's disposer. Replace the tag
|
|
21
|
-
// instead of reusing it: the old disposer then removes a detached node.
|
|
22
|
-
previous?.remove();
|
|
23
|
-
const tag = doc.createElement('style');
|
|
24
|
-
tag.setAttribute('data-plugin-css', tagId);
|
|
25
|
-
tag.textContent = css;
|
|
26
|
-
doc.head.append(tag);
|
|
27
|
-
return () => { tag.remove(); };
|
|
28
|
-
}
|
|
29
11
|
/**
|
|
30
12
|
* Register one sidebar row and its main body under one lifecycle.
|
|
31
13
|
* @param ctx - the client context carrying the slots and locale seats.
|
|
@@ -33,33 +15,8 @@ function injectStyles(doc, css, tagId) {
|
|
|
33
15
|
*/
|
|
34
16
|
export function registerSidebarPanel(ctx, spec) {
|
|
35
17
|
const seam = ctx;
|
|
36
|
-
|
|
37
|
-
ctx.
|
|
38
|
-
try {
|
|
39
|
-
const dispose = seam.locale.register(spec.namespace, spec.dictionaries);
|
|
40
|
-
registered = true;
|
|
41
|
-
return dispose;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
ctx.logger.warn(spec.namespace + ': the locale seat refused the dictionary (' + String(error) + '); the panel falls back to the bundle copy');
|
|
45
|
-
return () => { };
|
|
46
|
-
}
|
|
47
|
-
}, spec.namespace + ': locale');
|
|
48
|
-
ctx.effect(() => injectStyles(typeof document === 'undefined' ? undefined : document, spec.styles.css, spec.styles.tagId), spec.namespace + ': styles');
|
|
49
|
-
const fallback = spec.dictionaries[spec.fallback ?? FALLBACK_LOCALE] ?? spec.dictionaries.en;
|
|
50
|
-
const lookup = (key) => {
|
|
51
|
-
const own = fallback[key] ?? key;
|
|
52
|
-
if (!registered)
|
|
53
|
-
return own;
|
|
54
|
-
try {
|
|
55
|
-
return seam.locale.bind(spec.namespace)(key);
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
return own;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const t = (key, values) => interpolate(lookup(key), values);
|
|
62
|
-
const label = () => lookup('entry.label');
|
|
18
|
+
ctx.effect(() => injectPluginStyles(typeof document === 'undefined' ? undefined : document, spec.styles.css, spec.styles.tagId), spec.namespace + ': styles');
|
|
19
|
+
const { t, label } = bindLocale(ctx, spec.namespace, spec.dictionaries, spec.fallback ?? FALLBACK_LOCALE);
|
|
63
20
|
seam.slots.inject('sidebar.panellist', function* () {
|
|
64
21
|
yield seam.slots.register({ name: 'sidebar.panellist', id: spec.id, order: spec.order, label }, spec.icon);
|
|
65
22
|
yield seam.slots.register({
|
|
@@ -30,20 +30,6 @@ export interface RowMenuAction {
|
|
|
30
30
|
readonly disabled?: boolean | undefined;
|
|
31
31
|
readonly danger?: boolean | undefined;
|
|
32
32
|
}
|
|
33
|
-
/** Props for the shared action menu. */
|
|
34
|
-
export interface ActionMenuProps {
|
|
35
|
-
readonly actions: readonly RowMenuAction[];
|
|
36
|
-
readonly label: string;
|
|
37
|
-
readonly style?: Record<string, string | number> | undefined;
|
|
38
|
-
readonly className?: string | undefined;
|
|
39
|
-
readonly primitives?: MenuPrimitives | undefined;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Render the coordinate/action menu through the platform primitives, or a plain fallback.
|
|
43
|
-
* @param props - rows, accessible label, position/style and optional primitive override.
|
|
44
|
-
* @returns the menu element.
|
|
45
|
-
*/
|
|
46
|
-
export declare function ActionMenu({ actions, label, style, className, primitives }: ActionMenuProps): ReactNode;
|
|
47
33
|
/**
|
|
48
34
|
* Render the platform menu directly. Kept exported for callers that already own the primitive row.
|
|
49
35
|
* @param primitives - platform MenuSurface/MenuItemButton pair.
|
|
@@ -4,31 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { createElement } from 'react';
|
|
6
6
|
const PLATFORM_UI_MODULE = '@deepseek-ai/dsh-client-ui-primitives';
|
|
7
|
-
/**
|
|
8
|
-
* Render the coordinate/action menu through the platform primitives, or a plain fallback.
|
|
9
|
-
* @param props - rows, accessible label, position/style and optional primitive override.
|
|
10
|
-
* @returns the menu element.
|
|
11
|
-
*/
|
|
12
|
-
export function ActionMenu({ actions, label, style, className, primitives = PLATFORM_MENU }) {
|
|
13
|
-
if (primitives !== undefined)
|
|
14
|
-
return renderPlatformMenu(primitives, actions, label, style ?? {}, className);
|
|
15
|
-
return createElement('div', {
|
|
16
|
-
'data-role': 'action-menu-fallback',
|
|
17
|
-
role: 'menu',
|
|
18
|
-
'aria-label': label,
|
|
19
|
-
...(style === undefined ? {} : { style }),
|
|
20
|
-
...(className === undefined ? {} : { className }),
|
|
21
|
-
}, actions.map(action => createElement('button', {
|
|
22
|
-
key: action.id,
|
|
23
|
-
type: 'button',
|
|
24
|
-
role: 'menuitem',
|
|
25
|
-
disabled: action.disabled === true,
|
|
26
|
-
'data-danger': action.danger === true ? 'true' : 'false',
|
|
27
|
-
...(action.separatorBefore === true ? { 'data-separator-before': 'true' } : {}),
|
|
28
|
-
onClick: () => { if (action.disabled !== true)
|
|
29
|
-
action.onSelect(); },
|
|
30
|
-
}, action.label)));
|
|
31
|
-
}
|
|
32
7
|
/**
|
|
33
8
|
* Render the platform menu directly. Kept exported for callers that already own the primitive row.
|
|
34
9
|
* @param primitives - platform MenuSurface/MenuItemButton pair.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The one owner of plugin `<style>` tags; a new owner replaces the old tag so the
|
|
2
|
+
* old disposer only removes a detached node. */
|
|
3
|
+
export declare function injectPluginStyles(doc: Document | undefined, css: string, tagId: string): () => void;
|
|
4
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The one owner of plugin `<style>` tags; a new owner replaces the old tag so the
|
|
2
|
+
* old disposer only removes a detached node. */
|
|
3
|
+
export function injectPluginStyles(doc, css, tagId) {
|
|
4
|
+
if (doc === undefined)
|
|
5
|
+
return () => { };
|
|
6
|
+
doc.querySelector('style[data-plugin-css="' + tagId + '"]')?.remove();
|
|
7
|
+
const tag = doc.createElement('style');
|
|
8
|
+
tag.setAttribute('data-plugin-css', tagId);
|
|
9
|
+
tag.textContent = css;
|
|
10
|
+
doc.head.append(tag);
|
|
11
|
+
return () => { tag.remove(); };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=styles.js.map
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
if (doc === undefined)
|
|
4
|
-
return () => { };
|
|
5
|
-
const previous = doc.querySelector('style[data-plugin-css="' + tagId + '"]');
|
|
6
|
-
previous?.remove();
|
|
7
|
-
const tag = doc.createElement('style');
|
|
8
|
-
tag.setAttribute('data-plugin-css', tagId);
|
|
9
|
-
tag.textContent = css;
|
|
10
|
-
doc.head.appendChild(tag);
|
|
11
|
-
return () => { tag.remove(); };
|
|
12
|
-
}
|
|
1
|
+
import { bindLocale } from "./locale.js";
|
|
2
|
+
import { injectPluginStyles } from "./styles.js";
|
|
13
3
|
/**
|
|
14
4
|
* Register one view into `evolution.workbench.view`.
|
|
15
5
|
* @param ctx - client cordis context.
|
|
@@ -17,37 +7,8 @@ function injectStyles(doc, css, tagId) {
|
|
|
17
7
|
*/
|
|
18
8
|
export function registerWorkbenchView(ctx, spec) {
|
|
19
9
|
const seam = ctx;
|
|
20
|
-
|
|
21
|
-
ctx.
|
|
22
|
-
try {
|
|
23
|
-
const dispose = seam.locale.register(spec.namespace, spec.dictionaries);
|
|
24
|
-
registered = true;
|
|
25
|
-
return dispose;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
ctx.logger.warn(spec.namespace + ': locale refused (' + String(error) + '); the view falls back to the bundle copy');
|
|
29
|
-
return () => { };
|
|
30
|
-
}
|
|
31
|
-
}, spec.namespace + ': locale');
|
|
32
|
-
ctx.effect(() => injectStyles(typeof document === 'undefined' ? undefined : document, spec.styles.css, spec.styles.tagId), spec.namespace + ': styles');
|
|
33
|
-
const fallback = spec.dictionaries[FALLBACK_LOCALE];
|
|
34
|
-
const lookup = (key) => {
|
|
35
|
-
const own = fallback[key] ?? key;
|
|
36
|
-
if (!registered)
|
|
37
|
-
return own;
|
|
38
|
-
try {
|
|
39
|
-
return seam.locale.bind(spec.namespace)(key);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return own;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const t = (key, values) => {
|
|
46
|
-
const template = lookup(key);
|
|
47
|
-
if (values === undefined)
|
|
48
|
-
return template;
|
|
49
|
-
return template.replace(/\{(\w+)\}/g, (match, slot) => values[slot] === undefined ? match : String(values[slot]));
|
|
50
|
-
};
|
|
10
|
+
ctx.effect(() => injectPluginStyles(typeof document === 'undefined' ? undefined : document, spec.styles.css, spec.styles.tagId), spec.namespace + ': styles');
|
|
11
|
+
const { t } = bindLocale(ctx, spec.namespace, spec.dictionaries);
|
|
51
12
|
seam.slots.inject('evolution.workbench.view', function* () {
|
|
52
13
|
yield seam.slots.register({
|
|
53
14
|
name: 'evolution.workbench.view',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-evolution-client-kit",
|
|
3
3
|
"description": "Shared browser seams and lifecycle for the evolution family sidebar panels (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.49.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
package/lib/types/action.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
|
-
/** One user-facing action whose effect is copying an exact command. */
|
|
3
|
-
export interface ActionRef {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
readonly label: string;
|
|
6
|
-
readonly command: string;
|
|
7
|
-
/** False renders the action disabled with no clipboard attempt. */
|
|
8
|
-
readonly enabled?: boolean;
|
|
9
|
-
/** Optional in-UI confirmation before the write; the callback owns the dialog. */
|
|
10
|
-
readonly confirm?: (action: ActionRef) => boolean;
|
|
11
|
-
}
|
|
12
|
-
/** User-facing copy states; `copied` is set only after the clipboard accepted the text. */
|
|
13
|
-
export type CopyStatus = 'idle' | 'copying' | 'copied' | 'failed';
|
|
14
|
-
/** Labels the host surface supplies in its own language. */
|
|
15
|
-
export interface CommandCopyLabels {
|
|
16
|
-
readonly copy: string;
|
|
17
|
-
readonly copying: string;
|
|
18
|
-
readonly copied: string;
|
|
19
|
-
readonly failed: string;
|
|
20
|
-
}
|
|
21
|
-
/** Props for the shared copy control. */
|
|
22
|
-
export interface CommandCopyButtonProps {
|
|
23
|
-
readonly action: ActionRef;
|
|
24
|
-
readonly writeClipboard: (text: string) => Promise<boolean>;
|
|
25
|
-
readonly labels: CommandCopyLabels;
|
|
26
|
-
readonly className?: string | undefined;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Copy one command and report the host verdict.
|
|
30
|
-
* @param action - the command action.
|
|
31
|
-
* @param writeClipboard - platform clipboard writer.
|
|
32
|
-
* @param confirm - optional in-UI confirmation.
|
|
33
|
-
* @returns the settled copy status.
|
|
34
|
-
*/
|
|
35
|
-
export declare function copyAction(action: ActionRef, writeClipboard: (text: string) => Promise<boolean>, confirm?: (action: ActionRef) => boolean): Promise<CopyStatus>;
|
|
36
|
-
/**
|
|
37
|
-
* Render one command-copy action with real success/failure feedback.
|
|
38
|
-
* @param props - action, clipboard writer, and localized labels.
|
|
39
|
-
* @returns the button and its status line.
|
|
40
|
-
*/
|
|
41
|
-
export declare function CommandCopyButton({ action, writeClipboard, labels, className }: CommandCopyButtonProps): ReactNode;
|
|
42
|
-
//# sourceMappingURL=action.d.ts.map
|
package/lib/types/action.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Command-only actions. Approval decisions are a separate host API and must never
|
|
3
|
-
* be represented as a copyable command here.
|
|
4
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
5
|
-
*/
|
|
6
|
-
import { createElement, useState } from 'react';
|
|
7
|
-
/**
|
|
8
|
-
* Copy one command and report the host verdict.
|
|
9
|
-
* @param action - the command action.
|
|
10
|
-
* @param writeClipboard - platform clipboard writer.
|
|
11
|
-
* @param confirm - optional in-UI confirmation.
|
|
12
|
-
* @returns the settled copy status.
|
|
13
|
-
*/
|
|
14
|
-
export async function copyAction(action, writeClipboard, confirm) {
|
|
15
|
-
if (action.enabled === false)
|
|
16
|
-
return 'idle';
|
|
17
|
-
if (confirm !== undefined && !confirm(action))
|
|
18
|
-
return 'idle';
|
|
19
|
-
if (action.confirm !== undefined && !action.confirm(action))
|
|
20
|
-
return 'idle';
|
|
21
|
-
try {
|
|
22
|
-
return await writeClipboard(action.command) ? 'copied' : 'failed';
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return 'failed';
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Render one command-copy action with real success/failure feedback.
|
|
30
|
-
* @param props - action, clipboard writer, and localized labels.
|
|
31
|
-
* @returns the button and its status line.
|
|
32
|
-
*/
|
|
33
|
-
export function CommandCopyButton({ action, writeClipboard, labels, className }) {
|
|
34
|
-
const [status, setStatus] = useState('idle');
|
|
35
|
-
const text = status === 'copying' ? labels.copying : status === 'copied' ? labels.copied : status === 'failed' ? labels.failed : labels.copy;
|
|
36
|
-
return createElement('span', { className }, createElement('button', {
|
|
37
|
-
type: 'button',
|
|
38
|
-
disabled: action.enabled === false || status === 'copying',
|
|
39
|
-
'aria-label': action.label,
|
|
40
|
-
onClick: () => {
|
|
41
|
-
setStatus('copying');
|
|
42
|
-
void copyAction(action, writeClipboard).then(setStatus);
|
|
43
|
-
},
|
|
44
|
-
}, action.label), createElement('span', { role: 'status', 'aria-live': 'polite' }, text === labels.copy ? '' : text));
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=action.js.map
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One read operation's lifecycle: initial load, background refresh, stale-answer
|
|
3
|
-
* suppression, and an explicit failure slot. Consumers derive `empty` from a
|
|
4
|
-
* successful `data` value; this type never conflates "not loaded yet" with
|
|
5
|
-
* "loaded and empty".
|
|
6
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
7
|
-
*/
|
|
8
|
-
/** The three settled states; `refreshing` is orthogonal so old data can stay visible. */
|
|
9
|
-
export type AsyncStatus = 'loading' | 'ready' | 'error';
|
|
10
|
-
/** Immutable snapshot published to render hooks. */
|
|
11
|
-
export interface AsyncState<T> {
|
|
12
|
-
readonly status: AsyncStatus;
|
|
13
|
-
/** A newer read is in flight while `data` remains the previous successful value. */
|
|
14
|
-
readonly refreshing: boolean;
|
|
15
|
-
/** Last successful value; undefined before the first success or after reset. */
|
|
16
|
-
readonly data: T | undefined;
|
|
17
|
-
/** Latest failure, cleared by the next successful read. */
|
|
18
|
-
readonly failure: unknown;
|
|
19
|
-
/** Monotonic request id; only the latest generation may publish. */
|
|
20
|
-
readonly generation: number;
|
|
21
|
-
}
|
|
22
|
-
/** A loader may use the signal to cancel work when a newer read supersedes it. */
|
|
23
|
-
export type AsyncLoader<T> = (signal: AbortSignal) => Promise<T>;
|
|
24
|
-
/**
|
|
25
|
-
* Serialize one resource's reads without remounting the consumer.
|
|
26
|
-
*/
|
|
27
|
-
export declare class AsyncResource<T> {
|
|
28
|
-
#private;
|
|
29
|
-
/** @returns the stable snapshot for uSES. */
|
|
30
|
-
getSnapshot(): AsyncState<T>;
|
|
31
|
-
/**
|
|
32
|
-
* Observe snapshot replacements.
|
|
33
|
-
* @param listener - called after each publish.
|
|
34
|
-
* @returns the disposer.
|
|
35
|
-
*/
|
|
36
|
-
subscribe(listener: () => void): () => void;
|
|
37
|
-
/**
|
|
38
|
-
* Run one read. A prior read is aborted; only this generation may publish.
|
|
39
|
-
* @param load - loader receiving the cancellation signal.
|
|
40
|
-
* @returns settlement after this generation commits or is superseded.
|
|
41
|
-
*/
|
|
42
|
-
load(load: AsyncLoader<T>): Promise<void>;
|
|
43
|
-
/** Drop the current value and return to the initial loading state. */
|
|
44
|
-
reset(): void;
|
|
45
|
-
/** Abort the in-flight read and stop notifying. */
|
|
46
|
-
dispose(): void;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=async-resource.d.ts.map
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One read operation's lifecycle: initial load, background refresh, stale-answer
|
|
3
|
-
* suppression, and an explicit failure slot. Consumers derive `empty` from a
|
|
4
|
-
* successful `data` value; this type never conflates "not loaded yet" with
|
|
5
|
-
* "loaded and empty".
|
|
6
|
-
* @module @lmzhen/dsh-evolution-client-kit
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Serialize one resource's reads without remounting the consumer.
|
|
10
|
-
*/
|
|
11
|
-
export class AsyncResource {
|
|
12
|
-
#state = Object.freeze({
|
|
13
|
-
status: 'loading',
|
|
14
|
-
refreshing: false,
|
|
15
|
-
data: undefined,
|
|
16
|
-
failure: undefined,
|
|
17
|
-
generation: 0,
|
|
18
|
-
});
|
|
19
|
-
#listeners = new Set();
|
|
20
|
-
#generation = 0;
|
|
21
|
-
#controller;
|
|
22
|
-
#disposed = false;
|
|
23
|
-
/** @returns the stable snapshot for uSES. */
|
|
24
|
-
getSnapshot() {
|
|
25
|
-
return this.#state;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Observe snapshot replacements.
|
|
29
|
-
* @param listener - called after each publish.
|
|
30
|
-
* @returns the disposer.
|
|
31
|
-
*/
|
|
32
|
-
subscribe(listener) {
|
|
33
|
-
this.#listeners.add(listener);
|
|
34
|
-
return () => { this.#listeners.delete(listener); };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Run one read. A prior read is aborted; only this generation may publish.
|
|
38
|
-
* @param load - loader receiving the cancellation signal.
|
|
39
|
-
* @returns settlement after this generation commits or is superseded.
|
|
40
|
-
*/
|
|
41
|
-
async load(load) {
|
|
42
|
-
if (this.#disposed)
|
|
43
|
-
return;
|
|
44
|
-
const generation = this.#generation + 1;
|
|
45
|
-
this.#generation = generation;
|
|
46
|
-
this.#controller?.abort();
|
|
47
|
-
const controller = new AbortController();
|
|
48
|
-
this.#controller = controller;
|
|
49
|
-
const previous = this.#state;
|
|
50
|
-
this.#publish({
|
|
51
|
-
status: previous.data === undefined ? 'loading' : 'ready',
|
|
52
|
-
refreshing: previous.data !== undefined,
|
|
53
|
-
data: previous.data,
|
|
54
|
-
failure: previous.failure,
|
|
55
|
-
generation,
|
|
56
|
-
});
|
|
57
|
-
try {
|
|
58
|
-
const data = await load(controller.signal);
|
|
59
|
-
if (this.#disposed || generation !== this.#generation)
|
|
60
|
-
return;
|
|
61
|
-
this.#publish({ status: 'ready', refreshing: false, data, failure: undefined, generation });
|
|
62
|
-
}
|
|
63
|
-
catch (failure) {
|
|
64
|
-
if (this.#disposed || generation !== this.#generation || controller.signal.aborted)
|
|
65
|
-
return;
|
|
66
|
-
this.#publish({
|
|
67
|
-
status: previous.data === undefined ? 'error' : 'ready',
|
|
68
|
-
refreshing: false,
|
|
69
|
-
data: previous.data,
|
|
70
|
-
failure,
|
|
71
|
-
generation,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/** Drop the current value and return to the initial loading state. */
|
|
76
|
-
reset() {
|
|
77
|
-
this.#generation += 1;
|
|
78
|
-
this.#controller?.abort();
|
|
79
|
-
this.#controller = undefined;
|
|
80
|
-
this.#publish({ status: 'loading', refreshing: false, data: undefined, failure: undefined, generation: this.#generation });
|
|
81
|
-
}
|
|
82
|
-
/** Abort the in-flight read and stop notifying. */
|
|
83
|
-
dispose() {
|
|
84
|
-
this.#disposed = true;
|
|
85
|
-
this.#generation += 1;
|
|
86
|
-
this.#controller?.abort();
|
|
87
|
-
this.#controller = undefined;
|
|
88
|
-
this.#listeners.clear();
|
|
89
|
-
}
|
|
90
|
-
#publish(state) {
|
|
91
|
-
this.#state = Object.freeze(state);
|
|
92
|
-
for (const listener of this.#listeners)
|
|
93
|
-
listener();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=async-resource.js.map
|
package/lib/types/notice.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** One inline state notice: semantic tone plus text, no surface-specific styling. */
|
|
2
|
-
import { type ReactNode } from 'react';
|
|
3
|
-
export type StateNoticeTone = 'info' | 'warning' | 'error';
|
|
4
|
-
export interface StateNoticeProps {
|
|
5
|
-
readonly tone: StateNoticeTone;
|
|
6
|
-
readonly text: string;
|
|
7
|
-
/** Optional count shown after the sentence (e.g. "2 expired"). */
|
|
8
|
-
readonly count?: number | undefined;
|
|
9
|
-
readonly className?: string | undefined;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Render one informative/warning/error line. The caller owns the surface class and CSS;
|
|
13
|
-
* this leaf owns only the accessible role and the fact/count split.
|
|
14
|
-
* @param props - tone, text, optional count/class.
|
|
15
|
-
* @returns a semantic state notice.
|
|
16
|
-
*/
|
|
17
|
-
export declare function StateNotice({ tone, text, count, className }: StateNoticeProps): ReactNode;
|
|
18
|
-
//# sourceMappingURL=notice.d.ts.map
|
package/lib/types/notice.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** One inline state notice: semantic tone plus text, no surface-specific styling. */
|
|
2
|
-
import { createElement } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* Render one informative/warning/error line. The caller owns the surface class and CSS;
|
|
5
|
-
* this leaf owns only the accessible role and the fact/count split.
|
|
6
|
-
* @param props - tone, text, optional count/class.
|
|
7
|
-
* @returns a semantic state notice.
|
|
8
|
-
*/
|
|
9
|
-
export function StateNotice({ tone, text, count, className }) {
|
|
10
|
-
return createElement('div', {
|
|
11
|
-
'data-role': 'state-notice',
|
|
12
|
-
'data-tone': tone,
|
|
13
|
-
role: tone === 'error' ? 'alert' : 'status',
|
|
14
|
-
...(className === undefined ? {} : { className }),
|
|
15
|
-
}, createElement('span', { 'data-role': 'state-notice-text' }, text), count === undefined ? null : createElement('span', { 'data-role': 'state-notice-count' }, String(count)));
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=notice.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** Read-only status chips and toggleable filter chips. */
|
|
2
|
-
import { type ReactNode } from 'react';
|
|
3
|
-
import type { PresentationTone } from './types.ts';
|
|
4
|
-
/** Props for one non-interactive status chip. */
|
|
5
|
-
export interface StatusChipProps {
|
|
6
|
-
readonly label: string;
|
|
7
|
-
readonly tone?: PresentationTone | undefined;
|
|
8
|
-
readonly className?: string | undefined;
|
|
9
|
-
}
|
|
10
|
-
/** Render one semantic status word. */
|
|
11
|
-
export declare function StatusChip({ label, tone, className }: StatusChipProps): ReactNode;
|
|
12
|
-
/** Props for a filter chip that only changes the visible list. */
|
|
13
|
-
export interface FilterChipProps {
|
|
14
|
-
readonly label: string;
|
|
15
|
-
readonly active: boolean;
|
|
16
|
-
readonly onClick: () => void;
|
|
17
|
-
readonly count?: number | undefined;
|
|
18
|
-
readonly disabled?: boolean | undefined;
|
|
19
|
-
readonly className?: string | undefined;
|
|
20
|
-
}
|
|
21
|
-
/** Render a toggleable filter with the pressed state exposed to assistive tech. */
|
|
22
|
-
export declare function FilterChip({ label, active, onClick, count, disabled, className }: FilterChipProps): ReactNode;
|
|
23
|
-
//# sourceMappingURL=chips.d.ts.map
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** Read-only status chips and toggleable filter chips. */
|
|
2
|
-
import { createElement } from 'react';
|
|
3
|
-
/** Render one semantic status word. */
|
|
4
|
-
export function StatusChip({ label, tone = 'neutral', className }) {
|
|
5
|
-
return createElement('span', {
|
|
6
|
-
'data-role': 'status-chip',
|
|
7
|
-
'data-tone': tone,
|
|
8
|
-
...(className === undefined ? {} : { className }),
|
|
9
|
-
}, label);
|
|
10
|
-
}
|
|
11
|
-
/** Render a toggleable filter with the pressed state exposed to assistive tech. */
|
|
12
|
-
export function FilterChip({ label, active, onClick, count, disabled = false, className }) {
|
|
13
|
-
return createElement('button', {
|
|
14
|
-
type: 'button',
|
|
15
|
-
'data-role': 'filter-chip',
|
|
16
|
-
'data-active': active ? 'true' : 'false',
|
|
17
|
-
'aria-pressed': active ? 'true' : 'false',
|
|
18
|
-
disabled,
|
|
19
|
-
...(className === undefined ? {} : { className }),
|
|
20
|
-
onClick: () => { if (!disabled)
|
|
21
|
-
onClick(); },
|
|
22
|
-
}, createElement('span', { 'data-role': 'filter-chip-label' }, label), count === undefined ? null : createElement('span', { 'data-role': 'filter-chip-count' }, String(count)));
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=chips.js.map
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** A native details group for normal/secondary facts. */
|
|
2
|
-
import { type ReactNode } from 'react';
|
|
3
|
-
/** Props for the shared disclosure group. */
|
|
4
|
-
export interface DisclosureGroupProps {
|
|
5
|
-
readonly summary: string;
|
|
6
|
-
readonly count?: number | undefined;
|
|
7
|
-
readonly children: ReactNode;
|
|
8
|
-
readonly defaultOpen?: boolean | undefined;
|
|
9
|
-
readonly className?: string | undefined;
|
|
10
|
-
}
|
|
11
|
-
/** Render a closed-by-default disclosure without introducing another accordion model. */
|
|
12
|
-
export declare function DisclosureGroup({ summary, count, children, defaultOpen, className }: DisclosureGroupProps): ReactNode;
|
|
13
|
-
//# sourceMappingURL=disclosure-group.d.ts.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** A native details group for normal/secondary facts. */
|
|
2
|
-
import { createElement } from 'react';
|
|
3
|
-
/** Render a closed-by-default disclosure without introducing another accordion model. */
|
|
4
|
-
export function DisclosureGroup({ summary, count, children, defaultOpen = false, className }) {
|
|
5
|
-
return createElement('details', {
|
|
6
|
-
'data-role': 'disclosure-group',
|
|
7
|
-
...(defaultOpen ? { open: true } : {}),
|
|
8
|
-
...(className === undefined ? {} : { className }),
|
|
9
|
-
}, createElement('summary', { 'data-role': 'disclosure-summary' }, createElement('span', { 'data-role': 'disclosure-title' }, summary), count === undefined ? null : createElement('span', { 'data-role': 'disclosure-count' }, String(count))), createElement('div', { 'data-role': 'disclosure-content' }, children));
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=disclosure-group.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** The one local-time presentation used by reading surfaces. */
|
|
2
|
-
import { type ReactNode } from 'react';
|
|
3
|
-
/** Props for the shared time text. */
|
|
4
|
-
export interface TimeTextProps {
|
|
5
|
-
readonly value: string | number | null | undefined;
|
|
6
|
-
readonly seconds?: boolean | undefined;
|
|
7
|
-
readonly className?: string | undefined;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Render a local wall time, or a neutral dash when the fact is unknown.
|
|
11
|
-
* @param props - ISO/epoch value and seconds preference.
|
|
12
|
-
* @returns a time element with the raw value in dateTime when valid.
|
|
13
|
-
*/
|
|
14
|
-
export declare function TimeText({ value, seconds, className }: TimeTextProps): ReactNode;
|
|
15
|
-
//# sourceMappingURL=time-text.d.ts.map
|