@opendikw/web-ui 0.1.0-rc.1

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -0
  3. package/dist/auth/index.d.ts +23 -0
  4. package/dist/auth/index.js +118 -0
  5. package/dist/controls/Button.d.ts +14 -0
  6. package/dist/controls/Button.js +16 -0
  7. package/dist/controls/EmptyState.d.ts +8 -0
  8. package/dist/controls/EmptyState.js +5 -0
  9. package/dist/controls/Field.d.ts +23 -0
  10. package/dist/controls/Field.js +11 -0
  11. package/dist/controls/FrontmatterChip.d.ts +16 -0
  12. package/dist/controls/FrontmatterChip.js +16 -0
  13. package/dist/controls/IconButton.d.ts +15 -0
  14. package/dist/controls/IconButton.js +11 -0
  15. package/dist/controls/MetricCard.d.ts +16 -0
  16. package/dist/controls/MetricCard.js +11 -0
  17. package/dist/controls/Notice.d.ts +8 -0
  18. package/dist/controls/Notice.js +13 -0
  19. package/dist/controls/SegmentedControl.d.ts +27 -0
  20. package/dist/controls/SegmentedControl.js +16 -0
  21. package/dist/controls/SoftLabel.d.ts +15 -0
  22. package/dist/controls/SoftLabel.js +14 -0
  23. package/dist/controls/StatusPill.d.ts +6 -0
  24. package/dist/controls/StatusPill.js +8 -0
  25. package/dist/controls/cx.d.ts +6 -0
  26. package/dist/controls/cx.js +8 -0
  27. package/dist/controls/index.d.ts +11 -0
  28. package/dist/controls/index.js +11 -0
  29. package/dist/hooks/index.d.ts +4 -0
  30. package/dist/hooks/index.js +3 -0
  31. package/dist/hooks/useAsyncResource.d.ts +7 -0
  32. package/dist/hooks/useAsyncResource.js +36 -0
  33. package/dist/hooks/useBilingualReader.d.ts +40 -0
  34. package/dist/hooks/useBilingualReader.js +154 -0
  35. package/dist/hooks/usePreviewTranslation.d.ts +24 -0
  36. package/dist/hooks/usePreviewTranslation.js +43 -0
  37. package/dist/reader/BilingualView.d.ts +32 -0
  38. package/dist/reader/BilingualView.js +75 -0
  39. package/dist/reader/MarkdownView.d.ts +12 -0
  40. package/dist/reader/MarkdownView.js +94 -0
  41. package/dist/reader/chart-spec.d.ts +17 -0
  42. package/dist/reader/chart-spec.js +174 -0
  43. package/dist/reader/index.d.ts +5 -0
  44. package/dist/reader/index.js +4 -0
  45. package/dist/reader/markdown-runtime.d.ts +37 -0
  46. package/dist/reader/markdown-runtime.js +701 -0
  47. package/dist/styles/controls.css +546 -0
  48. package/dist/styles/reader.css +701 -0
  49. package/dist/styles/tokens.css +200 -0
  50. package/dist/styles.d.ts +1 -0
  51. package/dist/theme/index.d.ts +12 -0
  52. package/dist/theme/index.js +40 -0
  53. package/package.json +71 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenDIKW contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @opendikw/web-ui
2
+
3
+ Shared React 19 controls, sanitized Markdown and bilingual readers, hooks,
4
+ auth context and application-owned theme preferences. Node 24 or newer is required
5
+ for the build toolchain. React and react-dom are peers supplied by the application;
6
+ the compiled package preserves external imports and a single AuthContext.
7
+
8
+ ```tsx
9
+ import { Button } from "@opendikw/web-ui/controls";
10
+ import { MarkdownView } from "@opendikw/web-ui/reader";
11
+ import { AuthContext, useCanEdit } from "@opendikw/web-ui/auth";
12
+ import { useTheme } from "@opendikw/web-ui/theme";
13
+ import "@opendikw/web-ui/tokens.css";
14
+ import "@opendikw/web-ui/controls.css";
15
+ import "@opendikw/web-ui/reader.css";
16
+ ```
17
+
18
+ Use `/hooks` for async loading and bilingual/preview translation. `/controls`
19
+ does not load Mermaid, ECharts or a Node runtime. `/reader` lazily loads diagram
20
+ and chart engines and uses KaTeX CSS/fonts through the application's bundler.
21
+ Callers provide their own labels, routes and API connection. The package has no
22
+ workbench translations or MB business models.
23
+
24
+ `useTheme({ storageKey })` returns `preference`, `resolved` and `setPreference`.
25
+ It applies the resolved theme, follows OS changes for `system`, and persists an
26
+ explicit selection to that application's key. Mounting does not overwrite a
27
+ stored system preference. `loadAuth` preserves optional public issuer/coreId
28
+ metadata alongside the existing enabled/user/role response.
29
+
30
+ Authenticated applications must mount `AuthContext.Provider` with the result
31
+ of `loadAuth`. `useCanEdit` controls presentation; the server must enforce
32
+ authorization on every request. Without a provider, the context defaults to
33
+ the existing auth-off development mode.
34
+
35
+ Credentialed readers must receive a trusted Core asset base URL and its matching
36
+ token. Asset configuration is supplied by the application and must not come
37
+ from untrusted document metadata; the reader does not enforce an origin policy
38
+ on that configuration.
39
+
40
+ Build explicitly with `npm run build:packages`; CSS is copied explicitly because
41
+ install scripts are disabled. npm publishes compiled ESM, declarations, styles,
42
+ README and the MIT license. Use public exports rather than source deep imports.
43
+
44
+ Source provenance: extracted from OpenDIKW/dikw-web at
45
+ `f245ec43520017f961fcea629a5c4fac97f01862`; original history and authors remain
46
+ in that repository. App shells, GraphCanvas and application layouts stay outside
47
+ the package.
@@ -0,0 +1,23 @@
1
+ import type { AuthState } from "@opendikw/web-client/types";
2
+ export type { AuthRole, AuthUser, AuthState } from "@opendikw/web-client/types";
3
+ /**
4
+ * The boot probe couldn't tell whether auth is on: unreachable, timed out, a
5
+ * server error, or an auth-mode answer without a usable role. The app must not
6
+ * start as auth-off then, which would re-enable the browser-held core connection
7
+ * (a stored token would go straight to core).
8
+ */
9
+ export declare class AuthProbeError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ export declare function loadAuth(): Promise<AuthState>;
13
+ /**
14
+ * Auth mode: a 401 from the same-origin `/v1`, `/agent` or `/web` APIs means the
15
+ * session ended — send the user to sign in again and bring them back here. One
16
+ * wrapper around `fetch` covers every client (DikwClient, AgentClient, the
17
+ * translate / mineru helpers) without threading a callback through each.
18
+ */
19
+ export declare function installUnauthorizedRedirect(): void;
20
+ export declare const AuthContext: import("react").Context<AuthState>;
21
+ export declare function useAuth(): AuthState;
22
+ /** Auth off → everything; auth mode → editors only. */
23
+ export declare function useCanEdit(): boolean;
@@ -0,0 +1,118 @@
1
+ // Opt-in OIDC auth mode (issue #200), browser side. The SPA learns the mode at
2
+ // boot from `GET /web/auth/me` (`{ enabled: false }` when auth is off). In auth
3
+ // mode the server holds the core connection, so the clients go same-origin with
4
+ // no token; the server enforces roles and this only hides what a viewer can't do.
5
+ import { createContext, useContext } from "react";
6
+ const AUTH_OFF = { enabled: false };
7
+ const GUARDED_API = /^\/(v1|agent|web)\//;
8
+ // Cap the boot probe like the branding fetch, so a stalled server can't leave
9
+ // the page blank.
10
+ const AUTH_PROBE_TIMEOUT_MS = 5000;
11
+ /**
12
+ * The boot probe couldn't tell whether auth is on: unreachable, timed out, a
13
+ * server error, or an auth-mode answer without a usable role. The app must not
14
+ * start as auth-off then, which would re-enable the browser-held core connection
15
+ * (a stored token would go straight to core).
16
+ */
17
+ export class AuthProbeError extends Error {
18
+ constructor(message) {
19
+ super(message);
20
+ this.name = "AuthProbeError";
21
+ }
22
+ }
23
+ export async function loadAuth() {
24
+ const controller = new AbortController();
25
+ const timer = setTimeout(() => controller.abort(), AUTH_PROBE_TIMEOUT_MS);
26
+ try {
27
+ return await probeAuth(controller.signal);
28
+ }
29
+ finally {
30
+ clearTimeout(timer);
31
+ }
32
+ }
33
+ async function probeAuth(signal) {
34
+ let response;
35
+ let text;
36
+ try {
37
+ response = await fetch("/web/auth/me", { headers: { Accept: "application/json" }, signal });
38
+ text = await response.text();
39
+ }
40
+ catch {
41
+ throw new AuthProbeError("the server could not be reached");
42
+ }
43
+ if (response.status === 401) {
44
+ // Auth mode, but the session ended between the page load and this probe.
45
+ // Never resolve: the page is navigating to the IdP.
46
+ redirectToLogin();
47
+ return new Promise(() => { });
48
+ }
49
+ // An auth-mode server always answers this route with JSON, so a 404 or an
50
+ // HTML page (a static host's SPA fallback) means a server without auth mode.
51
+ if (response.status === 404) {
52
+ return AUTH_OFF;
53
+ }
54
+ if (!response.ok) {
55
+ throw new AuthProbeError(`sign-in status check failed (${response.status})`);
56
+ }
57
+ let body;
58
+ try {
59
+ body = JSON.parse(text);
60
+ }
61
+ catch {
62
+ return AUTH_OFF;
63
+ }
64
+ if (body?.enabled !== true) {
65
+ return AUTH_OFF;
66
+ }
67
+ if (body.user?.sub && (body.role === "viewer" || body.role === "editor")) {
68
+ const identity = {};
69
+ for (const field of ["issuer", "coreId"]) {
70
+ if (body[field] === undefined)
71
+ continue;
72
+ if (typeof body[field] !== "string" || !body[field].trim()) {
73
+ throw new AuthProbeError(`unusable ${field}`);
74
+ }
75
+ identity[field] = body[field];
76
+ }
77
+ return { enabled: true, user: body.user, role: body.role, ...identity };
78
+ }
79
+ throw new AuthProbeError("unusable sign-in status");
80
+ }
81
+ let redirecting = false;
82
+ function redirectToLogin() {
83
+ if (redirecting)
84
+ return;
85
+ redirecting = true;
86
+ const { pathname, search, hash } = window.location;
87
+ window.location.assign(`/web/auth/login?returnTo=${encodeURIComponent(`${pathname}${search}${hash}`)}`);
88
+ }
89
+ /**
90
+ * Auth mode: a 401 from the same-origin `/v1`, `/agent` or `/web` APIs means the
91
+ * session ended — send the user to sign in again and bring them back here. One
92
+ * wrapper around `fetch` covers every client (DikwClient, AgentClient, the
93
+ * translate / mineru helpers) without threading a callback through each.
94
+ */
95
+ export function installUnauthorizedRedirect() {
96
+ const next = window.fetch;
97
+ window.fetch = async (input, init) => {
98
+ const response = await next(input, init);
99
+ if (response.status === 401 && isGuardedApi(input)) {
100
+ redirectToLogin();
101
+ }
102
+ return response;
103
+ };
104
+ }
105
+ function isGuardedApi(input) {
106
+ const raw = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
107
+ const url = new URL(raw, window.location.href);
108
+ return url.origin === window.location.origin && GUARDED_API.test(url.pathname);
109
+ }
110
+ export const AuthContext = createContext(AUTH_OFF);
111
+ export function useAuth() {
112
+ return useContext(AuthContext);
113
+ }
114
+ /** Auth off → everything; auth mode → editors only. */
115
+ export function useCanEdit() {
116
+ const auth = useAuth();
117
+ return !auth.enabled || auth.role === "editor";
118
+ }
@@ -0,0 +1,14 @@
1
+ import type { ButtonHTMLAttributes } from "react";
2
+ type ButtonVariant = "primary" | "secondary" | "danger";
3
+ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
4
+ /** `primary` = filled petrol, `secondary` = outline, `danger` = outline with red text. */
5
+ variant?: ButtonVariant;
6
+ }
7
+ /**
8
+ * Shared text/action button wrapping the `.primary-button` / `.secondary-button`
9
+ * classes. DOM-identical to the hand-rolled markup it replaces: same element,
10
+ * classes, and passthrough attributes. Defaults `type="button"` so a button
11
+ * inside a form never submits by accident.
12
+ */
13
+ export declare function Button({ variant, type, className, children, ...rest }: ButtonProps): import("react").JSX.Element;
14
+ export {};
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ const VARIANT_CLASS = {
4
+ primary: "primary-button",
5
+ secondary: "secondary-button",
6
+ danger: "secondary-button secondary-button--danger",
7
+ };
8
+ /**
9
+ * Shared text/action button wrapping the `.primary-button` / `.secondary-button`
10
+ * classes. DOM-identical to the hand-rolled markup it replaces: same element,
11
+ * classes, and passthrough attributes. Defaults `type="button"` so a button
12
+ * inside a form never submits by accident.
13
+ */
14
+ export function Button({ variant = "primary", type, className, children, ...rest }) {
15
+ return (_jsx("button", { type: type ?? "button", className: cx(VARIANT_CLASS[variant], className), ...rest, children: children }));
16
+ }
@@ -0,0 +1,8 @@
1
+ import type { LucideIcon } from "lucide-react";
2
+ interface EmptyStateProps {
3
+ title: string;
4
+ detail?: string;
5
+ icon?: LucideIcon;
6
+ }
7
+ export declare function EmptyState({ title, detail, icon: Icon }: EmptyStateProps): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { SearchX } from "lucide-react";
3
+ export function EmptyState({ title, detail, icon: Icon = SearchX }) {
4
+ return (_jsxs("div", { className: "empty-state", children: [_jsx(Icon, { size: 22, "aria-hidden": "true" }), _jsxs("div", { children: [_jsx("div", { className: "empty-state__title", children: title }), detail ? _jsx("div", { className: "empty-state__detail", children: detail }) : null] })] }));
5
+ }
@@ -0,0 +1,23 @@
1
+ import type { LabelHTMLAttributes, ReactNode } from "react";
2
+ interface FieldProps extends Omit<LabelHTMLAttributes<HTMLLabelElement>, "children"> {
3
+ /** Label text rendered in the leading `<span>`. */
4
+ label: ReactNode;
5
+ /** `.field--grow` — flex to fill the row. */
6
+ grow?: boolean;
7
+ /** `.field--small` — fixed narrow width. */
8
+ small?: boolean;
9
+ /** `.field--inline` — label and control on one grid row. */
10
+ inline?: boolean;
11
+ /** `.field--token` — capped-width token input. */
12
+ token?: boolean;
13
+ /** The control: an `<input>`, `<select>`, or `<textarea>`. */
14
+ children: ReactNode;
15
+ }
16
+ /**
17
+ * Shared labeled form field wrapping the `.field` class. Renders the same
18
+ * `<label class="field"><span>{label}</span>{control}</label>` markup the
19
+ * hand-rolled call-sites use; modifier props map to the existing `field--*`
20
+ * classes and any extra `className` is appended.
21
+ */
22
+ export declare function Field({ label, grow, small, inline, token, className, children, ...rest }: FieldProps): import("react").JSX.Element;
23
+ export {};
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ /**
4
+ * Shared labeled form field wrapping the `.field` class. Renders the same
5
+ * `<label class="field"><span>{label}</span>{control}</label>` markup the
6
+ * hand-rolled call-sites use; modifier props map to the existing `field--*`
7
+ * classes and any extra `className` is appended.
8
+ */
9
+ export function Field({ label, grow, small, inline, token, className, children, ...rest }) {
10
+ return (_jsxs("label", { className: cx("field", grow && "field--grow", small && "field--small", inline && "field--inline", token && "field--token", className), ...rest, children: [_jsx("span", { children: label }), children] }));
11
+ }
@@ -0,0 +1,16 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ type FrontmatterChipVariant = "tag" | "source";
3
+ interface FrontmatterChipProps extends HTMLAttributes<HTMLSpanElement> {
4
+ /** `tag` = petrol `#tag`, `source` = mono provenance chip; omit for a plain key/value chip. */
5
+ variant?: FrontmatterChipVariant;
6
+ children: ReactNode;
7
+ }
8
+ /**
9
+ * Shared frontmatter metadata chip wrapping the `.frontmatter-chip` class. Kept
10
+ * separate from {@link SoftLabel} and `StatusPill` — the three are visually
11
+ * distinct and their CSS is not merged. DOM-identical to the markup it replaces:
12
+ * the optional `variant` maps to the existing `frontmatter-chip--*` modifier and
13
+ * any extra `className` is appended.
14
+ */
15
+ export declare function FrontmatterChip({ variant, className, children, ...rest }: FrontmatterChipProps): import("react").JSX.Element;
16
+ export {};
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ const VARIANT_CLASS = {
4
+ tag: "frontmatter-chip--tag",
5
+ source: "frontmatter-chip--source",
6
+ };
7
+ /**
8
+ * Shared frontmatter metadata chip wrapping the `.frontmatter-chip` class. Kept
9
+ * separate from {@link SoftLabel} and `StatusPill` — the three are visually
10
+ * distinct and their CSS is not merged. DOM-identical to the markup it replaces:
11
+ * the optional `variant` maps to the existing `frontmatter-chip--*` modifier and
12
+ * any extra `className` is appended.
13
+ */
14
+ export function FrontmatterChip({ variant, className, children, ...rest }) {
15
+ return (_jsx("span", { className: cx("frontmatter-chip", variant && VARIANT_CLASS[variant], className), ...rest, children: children }));
16
+ }
@@ -0,0 +1,15 @@
1
+ import type { ButtonHTMLAttributes, ReactNode } from "react";
2
+ interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "aria-label"> {
3
+ /** Accessible name — required, since the visible child is an icon only. */
4
+ label: string;
5
+ /** A single icon element. */
6
+ children: ReactNode;
7
+ }
8
+ /**
9
+ * Shared 38px square icon button wrapping the `.icon-button` class. DOM-identical
10
+ * to the markup it replaces; `className` is appended (not replaced) so call-site
11
+ * BEM classes like `agent-session__menu-trigger` survive. `label` is required and
12
+ * becomes `aria-label`, so every icon button keeps an accessible name.
13
+ */
14
+ export declare function IconButton({ label, type, className, children, ...rest }: IconButtonProps): import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ /**
4
+ * Shared 38px square icon button wrapping the `.icon-button` class. DOM-identical
5
+ * to the markup it replaces; `className` is appended (not replaced) so call-site
6
+ * BEM classes like `agent-session__menu-trigger` survive. `label` is required and
7
+ * becomes `aria-label`, so every icon button keeps an accessible name.
8
+ */
9
+ export function IconButton({ label, type, className, children, ...rest }) {
10
+ return (_jsx("button", { type: type ?? "button", className: cx("icon-button", className), "aria-label": label, ...rest, children: children }));
11
+ }
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from "react";
2
+ interface MetricCardProps {
3
+ label: string;
4
+ value: ReactNode;
5
+ detail?: ReactNode;
6
+ /** When set, the whole cell becomes a quiet stretched link to this hash route. */
7
+ href?: string;
8
+ }
9
+ /**
10
+ * One cell of the Overview metric strip. Renders as a `<div>` grouping a `<dt>`
11
+ * label and `<dd>` value (the strip itself is a `<dl>`), so a screen reader
12
+ * announces "label, value" pairs instead of a flat text stream. When `href` is
13
+ * set the value is a stretched link covering the whole cell — no button chrome.
14
+ */
15
+ export declare function MetricCard({ label, value, detail, href }: MetricCardProps): import("react").JSX.Element;
16
+ export {};
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ /**
4
+ * One cell of the Overview metric strip. Renders as a `<div>` grouping a `<dt>`
5
+ * label and `<dd>` value (the strip itself is a `<dl>`), so a screen reader
6
+ * announces "label, value" pairs instead of a flat text stream. When `href` is
7
+ * set the value is a stretched link covering the whole cell — no button chrome.
8
+ */
9
+ export function MetricCard({ label, value, detail, href }) {
10
+ return (_jsxs("div", { className: cx("metric-card", href && "metric-card--link"), children: [_jsx("dt", { className: "metric-card__label", children: label }), _jsx("dd", { className: "metric-card__value", children: href ? (_jsx("a", { className: "metric-card__link", href: href, "aria-label": typeof value === "string" ? `${label} ${value}` : label, children: value })) : (value) }), detail ? _jsx("dd", { className: "metric-card__detail", children: detail }) : null] }));
11
+ }
@@ -0,0 +1,8 @@
1
+ interface NoticeProps {
2
+ title?: string;
3
+ error?: unknown;
4
+ children?: React.ReactNode;
5
+ tone?: "info" | "warn" | "bad";
6
+ }
7
+ export declare function Notice({ title, error, children, tone }: NoticeProps): import("react").JSX.Element;
8
+ export {};
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AlertTriangle, Info } from "lucide-react";
3
+ import { DikwClientError } from "@opendikw/web-client/core";
4
+ export function Notice({ title, error, children, tone = error ? "bad" : "info" }) {
5
+ const Icon = tone === "info" ? Info : AlertTriangle;
6
+ const message = error instanceof DikwClientError
7
+ ? error.message
8
+ : error instanceof Error
9
+ ? error.message
10
+ : null;
11
+ const code = error instanceof DikwClientError ? `${error.status} ${error.code}` : null;
12
+ return (_jsxs("div", { className: `notice notice--${tone}`, role: tone === "bad" ? "alert" : "status", children: [_jsx(Icon, { size: 18, "aria-hidden": "true" }), _jsxs("div", { children: [title ? _jsx("div", { className: "notice__title", children: title }) : null, code ? _jsx("div", { className: "notice__code", children: code }) : null, message ? _jsx("div", { children: message }) : null, children] })] }));
13
+ }
@@ -0,0 +1,27 @@
1
+ import type { ReactNode } from "react";
2
+ interface SegmentedOption<T extends string> {
3
+ value: T;
4
+ label: ReactNode;
5
+ }
6
+ interface SegmentedControlProps<T extends string> {
7
+ /** The currently selected option value. */
8
+ value: T;
9
+ /** Mutually exclusive choices, rendered left to right. */
10
+ options: ReadonlyArray<SegmentedOption<T>>;
11
+ onChange: (value: T) => void;
12
+ /** Accessible name for the track (maps to `aria-label`). */
13
+ ariaLabel: string;
14
+ /** `.segmented-control--settings` — fit-content track used on the Settings page. */
15
+ settings?: boolean;
16
+ className?: string;
17
+ }
18
+ /**
19
+ * Shared segmented control wrapping the `.segmented-control` class — the chosen
20
+ * pattern for mutually exclusive view choices (Settings theme / locale). The
21
+ * track is a named `role="group"` (a bare `<div>` would drop its `aria-label`),
22
+ * and each option is a toggle `<button>` carrying `aria-pressed`, so a
23
+ * screen-reader user hears which option is selected — not three identical
24
+ * buttons. Generic over a string value union so `onChange` stays type-safe.
25
+ */
26
+ export declare function SegmentedControl<T extends string>({ value, options, onChange, ariaLabel, settings, className, }: SegmentedControlProps<T>): import("react").JSX.Element;
27
+ export {};
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ /**
4
+ * Shared segmented control wrapping the `.segmented-control` class — the chosen
5
+ * pattern for mutually exclusive view choices (Settings theme / locale). The
6
+ * track is a named `role="group"` (a bare `<div>` would drop its `aria-label`),
7
+ * and each option is a toggle `<button>` carrying `aria-pressed`, so a
8
+ * screen-reader user hears which option is selected — not three identical
9
+ * buttons. Generic over a string value union so `onChange` stays type-safe.
10
+ */
11
+ export function SegmentedControl({ value, options, onChange, ariaLabel, settings, className, }) {
12
+ return (_jsx("div", { role: "group", className: cx("segmented-control", settings && "segmented-control--settings", className), "aria-label": ariaLabel, children: options.map((option) => {
13
+ const selected = option.value === value;
14
+ return (_jsx("button", { type: "button", "aria-pressed": selected, className: selected ? "is-active" : "", onClick: () => onChange(option.value), children: option.label }, option.value));
15
+ }) }));
16
+ }
@@ -0,0 +1,15 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ interface SoftLabelProps extends HTMLAttributes<HTMLSpanElement> {
3
+ children: ReactNode;
4
+ }
5
+ /**
6
+ * Shared inline meta badge wrapping the `.soft-label` class — the hairline pill
7
+ * used for counts, layers, and short tags. DOM-identical to the hand-rolled
8
+ * `<span className="soft-label">` markup it replaces; `className` is appended
9
+ * (not replaced) so call-site classes like `wiki-backlinks__layer` survive, and
10
+ * any extra attributes (`role`, `aria-live`, …) pass through. Block uses of
11
+ * `.soft-label` on a `<p>` (hints, empty states) are left as raw markup — they
12
+ * borrow the type, they are not badges.
13
+ */
14
+ export declare function SoftLabel({ className, children, ...rest }: SoftLabelProps): import("react").JSX.Element;
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ /**
4
+ * Shared inline meta badge wrapping the `.soft-label` class — the hairline pill
5
+ * used for counts, layers, and short tags. DOM-identical to the hand-rolled
6
+ * `<span className="soft-label">` markup it replaces; `className` is appended
7
+ * (not replaced) so call-site classes like `wiki-backlinks__layer` survive, and
8
+ * any extra attributes (`role`, `aria-live`, …) pass through. Block uses of
9
+ * `.soft-label` on a `<p>` (hints, empty states) are left as raw markup — they
10
+ * borrow the type, they are not badges.
11
+ */
12
+ export function SoftLabel({ className, children, ...rest }) {
13
+ return (_jsx("span", { className: cx("soft-label", className), ...rest, children: children }));
14
+ }
@@ -0,0 +1,6 @@
1
+ interface StatusPillProps {
2
+ status: string;
3
+ label?: string;
4
+ }
5
+ export declare function StatusPill({ status, label }: StatusPillProps): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CheckCircle2, Clock3, HelpCircle, XCircle } from "lucide-react";
3
+ import { statusTone } from "@opendikw/web-client/document";
4
+ export function StatusPill({ status, label }) {
5
+ const tone = statusTone(status);
6
+ const Icon = tone === "ok" ? CheckCircle2 : tone === "bad" ? XCircle : tone === "info" ? Clock3 : HelpCircle;
7
+ return (_jsxs("span", { className: `status-pill status-pill--${tone}`, children: [_jsx(Icon, { size: 14, "aria-hidden": "true" }), label ?? status] }));
8
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Join truthy class-name parts with a single space. Lets a shared component
3
+ * append a call-site's extra classes (`cx("icon-button", props.className)`)
4
+ * instead of replacing them.
5
+ */
6
+ export declare function cx(...parts: Array<string | false | null | undefined>): string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Join truthy class-name parts with a single space. Lets a shared component
3
+ * append a call-site's extra classes (`cx("icon-button", props.className)`)
4
+ * instead of replacing them.
5
+ */
6
+ export function cx(...parts) {
7
+ return parts.filter(Boolean).join(" ");
8
+ }
@@ -0,0 +1,11 @@
1
+ export * from "./Button.js";
2
+ export * from "./IconButton.js";
3
+ export * from "./Field.js";
4
+ export * from "./SegmentedControl.js";
5
+ export * from "./SoftLabel.js";
6
+ export * from "./FrontmatterChip.js";
7
+ export * from "./EmptyState.js";
8
+ export * from "./MetricCard.js";
9
+ export * from "./Notice.js";
10
+ export * from "./StatusPill.js";
11
+ export * from "./cx.js";
@@ -0,0 +1,11 @@
1
+ export * from "./Button.js";
2
+ export * from "./IconButton.js";
3
+ export * from "./Field.js";
4
+ export * from "./SegmentedControl.js";
5
+ export * from "./SoftLabel.js";
6
+ export * from "./FrontmatterChip.js";
7
+ export * from "./EmptyState.js";
8
+ export * from "./MetricCard.js";
9
+ export * from "./Notice.js";
10
+ export * from "./StatusPill.js";
11
+ export * from "./cx.js";
@@ -0,0 +1,4 @@
1
+ /// <reference path="../styles.d.ts" />
2
+ export * from "./useAsyncResource.js";
3
+ export * from "./useBilingualReader.js";
4
+ export * from "./usePreviewTranslation.js";
@@ -0,0 +1,3 @@
1
+ export * from "./useAsyncResource.js";
2
+ export * from "./useBilingualReader.js";
3
+ export * from "./usePreviewTranslation.js";
@@ -0,0 +1,7 @@
1
+ export interface AsyncResource<T> {
2
+ data: T | null;
3
+ error: unknown;
4
+ loading: boolean;
5
+ reload: () => void;
6
+ }
7
+ export declare function useAsyncResource<T>(load: (signal: AbortSignal) => Promise<T>, deps: readonly unknown[]): AsyncResource<T>;
@@ -0,0 +1,36 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ export function useAsyncResource(load, deps) {
3
+ const [data, setData] = useState(null);
4
+ const [error, setError] = useState(null);
5
+ const [loading, setLoading] = useState(true);
6
+ const [reloadId, setReloadId] = useState(0);
7
+ const reload = useCallback(() => {
8
+ setReloadId((value) => value + 1);
9
+ }, []);
10
+ useEffect(() => {
11
+ const controller = new AbortController();
12
+ setLoading(true);
13
+ setError(null);
14
+ load(controller.signal)
15
+ .then((nextData) => {
16
+ if (!controller.signal.aborted) {
17
+ setData(nextData);
18
+ }
19
+ })
20
+ .catch((nextError) => {
21
+ if (!controller.signal.aborted) {
22
+ setError(nextError);
23
+ }
24
+ })
25
+ .finally(() => {
26
+ if (!controller.signal.aborted) {
27
+ setLoading(false);
28
+ }
29
+ });
30
+ return () => {
31
+ controller.abort();
32
+ };
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- deps is a caller-provided spread; the hook intentionally re-runs when any of them change
34
+ }, [load, reloadId, ...deps]);
35
+ return { data, error, loading, reload };
36
+ }