ain-ui 0.2.3 → 1.0.3
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/NOTICE +37 -0
- package/README.md +179 -77
- package/dist/agent.d.ts +131 -0
- package/dist/agent.js +802 -0
- package/dist/ainui.d.ts +15 -1
- package/dist/ainui.js +48 -10
- package/dist/basic.d.ts +5 -47
- package/dist/basic.js +11 -25
- package/dist/catalog/standard.gen.d.ts +5 -0
- package/dist/catalog/standard.gen.js +6 -0
- package/dist/catalog-v1.json +2560 -0
- package/dist/catalog.json +19917 -2061
- package/dist/chat.js +6 -7
- package/dist/expression.d.ts +23 -0
- package/dist/expression.js +222 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/macros.d.ts +12 -0
- package/dist/macros.js +57 -0
- package/dist/payment.js +6 -7
- package/dist/pickers.d.ts +158 -0
- package/dist/pickers.js +110 -0
- package/dist/protocol.d.ts +100 -0
- package/dist/protocol.js +232 -0
- package/dist/react/ain.d.ts +1 -0
- package/dist/react/ain.js +225 -0
- package/dist/react/catalog.d.ts +9 -0
- package/dist/react/catalog.js +23 -0
- package/dist/react/core.d.ts +84 -0
- package/dist/react/core.js +158 -0
- package/dist/react/functions.d.ts +2 -0
- package/dist/react/functions.js +29 -0
- package/dist/react/standard/composites.d.ts +1 -0
- package/dist/react/standard/composites.js +110 -0
- package/dist/react/standard/data.d.ts +1 -0
- package/dist/react/standard/data.js +481 -0
- package/dist/react/standard/feedback.d.ts +11 -0
- package/dist/react/standard/feedback.js +111 -0
- package/dist/react/standard/inputs.d.ts +5 -0
- package/dist/react/standard/inputs.js +467 -0
- package/dist/react/standard/layout.d.ts +5 -0
- package/dist/react/standard/layout.js +104 -0
- package/dist/react/standard/media.d.ts +33 -0
- package/dist/react/standard/media.js +208 -0
- package/dist/react/standard/rich.d.ts +1 -0
- package/dist/react/standard/rich.js +146 -0
- package/dist/react/standard/text.d.ts +9 -0
- package/dist/react/standard/text.js +209 -0
- package/dist/react/surface.d.ts +44 -0
- package/dist/react/surface.js +134 -0
- package/dist/react.d.ts +3 -35
- package/dist/react.js +3 -272
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +299 -4
- package/dist/styles.css +805 -20
- package/package.json +28 -11
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What every AIN-UI React component is built from.
|
|
3
|
+
*
|
|
4
|
+
* A2UI owns state, bindings, validation and the surface lifecycle (`@a2ui/web_core`); `@a2ui/react` turns a
|
|
5
|
+
* component's properties into resolved React props. A view here receives `props` with every binding already
|
|
6
|
+
* resolved, a `setX` for each bindable `x`, an action as a function, and children as ids to hand to `buildChild`.
|
|
7
|
+
*/
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { type ComponentContext } from "@a2ui/web_core";
|
|
10
|
+
import { type ReactComponentImplementation } from "@a2ui/react";
|
|
11
|
+
import type { AssetRef } from "../ainui.js";
|
|
12
|
+
/** The AINUI catalog as published: names, props and descriptions. Views are attached in ./catalog.ts. */
|
|
13
|
+
export declare const STANDARD: import("@a2ui/web_core").CatalogApi;
|
|
14
|
+
export type ChildRef = string | {
|
|
15
|
+
id: string;
|
|
16
|
+
basePath?: string;
|
|
17
|
+
};
|
|
18
|
+
export type BuildChild = (id: string, basePath?: string) => React.ReactNode;
|
|
19
|
+
export type ViewProps<P = Record<string, any>> = {
|
|
20
|
+
props: P & Record<string, any>;
|
|
21
|
+
buildChild: BuildChild;
|
|
22
|
+
/** For an action that needs extra context (see `fire`) or the raw, unresolved properties. */
|
|
23
|
+
context: ComponentContext;
|
|
24
|
+
accessibilityRef?: (element: Element | null) => void;
|
|
25
|
+
validationErrorsRef?: (element: Element | null) => void;
|
|
26
|
+
};
|
|
27
|
+
/** A view for one component of the catalog. The name must exist in standard.json or ain.json. */
|
|
28
|
+
export declare function standard<P = Record<string, any>>(name: string, View: React.FC<ViewProps<P>>): ReactComponentImplementation;
|
|
29
|
+
/** One child, by the reference the binder resolved: an id, or a template instance `{id, basePath}`. */
|
|
30
|
+
export declare const kid: (buildChild: BuildChild, ref: ChildRef | undefined | null) => React.ReactNode;
|
|
31
|
+
/** A resolved child list, in order. */
|
|
32
|
+
export declare function Kids({ of, buildChild }: {
|
|
33
|
+
of: unknown;
|
|
34
|
+
buildChild: BuildChild;
|
|
35
|
+
}): React.JSX.Element;
|
|
36
|
+
export declare const cx: (...names: Array<string | false | null | undefined>) => string;
|
|
37
|
+
/** Spacing: a number is 4px steps, a string is CSS as written. */
|
|
38
|
+
export declare const space: (v: unknown) => string | undefined;
|
|
39
|
+
/** Size: a number is pixels, a string is CSS as written. */
|
|
40
|
+
export declare const px: (v: unknown) => string | undefined;
|
|
41
|
+
export declare function radius(v: unknown): string | undefined;
|
|
42
|
+
/** A colour token (`success`, `danger`, `muted`, `surface-secondary`, `info-solid`, …) or any CSS colour. */
|
|
43
|
+
export declare function color(v: unknown): string | undefined;
|
|
44
|
+
/** Background for a tone: the soft tint, or the solid colour for `x-solid`. */
|
|
45
|
+
export declare function surfaceColor(v: unknown): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The layout props every container shares (gap, padding, background, border, radius, sizes, flex, scrolling) as
|
|
48
|
+
* inline style. Containers pass their own defaults first: `{ ...defaults, ...boxStyle(props) }`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function boxStyle(p: Record<string, any>): React.CSSProperties;
|
|
51
|
+
/**
|
|
52
|
+
* Sends the component's action with extra context merged in — a follow-up's text, the id of the row that was
|
|
53
|
+
* clicked. For an action that needs nothing extra, call the resolved prop (`props.onClick?.()`) instead.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fire(context: ComponentContext, prop: string, extra?: Record<string, unknown>): Promise<void>;
|
|
56
|
+
/** The data-model path a property is bound to, or undefined for a literal. */
|
|
57
|
+
export declare function boundPath(context: ComponentContext, prop: string): string | undefined;
|
|
58
|
+
export type AssetResolver = (asset: AssetRef["$asset"], options?: {
|
|
59
|
+
download?: boolean;
|
|
60
|
+
}) => string;
|
|
61
|
+
export type FileViewRenderer = (file: {
|
|
62
|
+
src: string;
|
|
63
|
+
download: string;
|
|
64
|
+
name: string;
|
|
65
|
+
mime: string;
|
|
66
|
+
size?: number;
|
|
67
|
+
}) => React.ReactNode;
|
|
68
|
+
/** What the host application lends to components. Everything is optional; a missing one degrades quietly. */
|
|
69
|
+
export type Host = {
|
|
70
|
+
/** Turns a private asset reference into a URL the viewer is authorized to load. */
|
|
71
|
+
resolveAsset: AssetResolver;
|
|
72
|
+
renderFile?: FileViewRenderer;
|
|
73
|
+
/** A follow-up pill or suggestion: send this text as the user's next message. */
|
|
74
|
+
sendMessage?: (text: string) => void;
|
|
75
|
+
/** Open a link. Defaults to a new tab with `noopener`. */
|
|
76
|
+
openUrl?: (href: string) => void;
|
|
77
|
+
};
|
|
78
|
+
export declare const HostContext: React.Context<Host>;
|
|
79
|
+
export declare const useHost: () => Host;
|
|
80
|
+
/** Only http(s), site-relative and blob URLs are drawn; anything else (javascript:, data:) is dropped. */
|
|
81
|
+
export declare function safeUrl(value: unknown): string;
|
|
82
|
+
/** A media value: a URL, or a private asset reference resolved by the host. */
|
|
83
|
+
export declare function mediaUrl(value: unknown, host: Host, download?: boolean): string;
|
|
84
|
+
export declare function openUrl(host: Host, href: unknown): void;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* What every AIN-UI React component is built from.
|
|
5
|
+
*
|
|
6
|
+
* A2UI owns state, bindings, validation and the surface lifecycle (`@a2ui/web_core`); `@a2ui/react` turns a
|
|
7
|
+
* component's properties into resolved React props. A view here receives `props` with every binding already
|
|
8
|
+
* resolved, a `setX` for each bindable `x`, an action as a function, and children as ids to hand to `buildChild`.
|
|
9
|
+
*/
|
|
10
|
+
import React, { createContext, useContext } from "react";
|
|
11
|
+
import { Catalog } from "@a2ui/web_core";
|
|
12
|
+
import { createComponentImplementation } from "@a2ui/react";
|
|
13
|
+
import { AINUI_CATALOG_DOCUMENT } from "../catalog/standard.gen.js";
|
|
14
|
+
/** The AINUI catalog as published: names, props and descriptions. Views are attached in ./catalog.ts. */
|
|
15
|
+
export const STANDARD = Catalog.fromJson(AINUI_CATALOG_DOCUMENT, "1.0");
|
|
16
|
+
/** A view for one component of the catalog. The name must exist in standard.json or ain.json. */
|
|
17
|
+
export function standard(name, View) {
|
|
18
|
+
const api = STANDARD.components.get(name);
|
|
19
|
+
if (!api)
|
|
20
|
+
throw new Error(`"${name}" is not in the AINUI catalog`);
|
|
21
|
+
View.displayName = name;
|
|
22
|
+
return createComponentImplementation(api, View);
|
|
23
|
+
}
|
|
24
|
+
/** One child, by the reference the binder resolved: an id, or a template instance `{id, basePath}`. */
|
|
25
|
+
export const kid = (buildChild, ref) => ref == null || ref === "" ? null : typeof ref === "string" ? buildChild(ref) : buildChild(ref.id, ref.basePath);
|
|
26
|
+
/** A resolved child list, in order. */
|
|
27
|
+
export function Kids({ of, buildChild }) {
|
|
28
|
+
const list = Array.isArray(of) ? of : [];
|
|
29
|
+
return _jsx(_Fragment, { children: list.map((ref, i) => _jsx(React.Fragment, { children: kid(buildChild, ref) }, typeof ref === "string" ? ref : `${ref.id}:${ref.basePath ?? i}`)) });
|
|
30
|
+
}
|
|
31
|
+
export const cx = (...names) => names.filter(Boolean).join(" ");
|
|
32
|
+
/** Spacing: a number is 4px steps, a string is CSS as written. */
|
|
33
|
+
export const space = (v) => (typeof v === "number" ? `${v * 4}px` : typeof v === "string" && v ? v : undefined);
|
|
34
|
+
/** Size: a number is pixels, a string is CSS as written. */
|
|
35
|
+
export const px = (v) => (typeof v === "number" ? `${v}px` : typeof v === "string" && v ? v : undefined);
|
|
36
|
+
const RADIUS = { "2xs": "2px", xs: "4px", sm: "6px", md: "8px", lg: "12px", xl: "16px", "2xl": "20px", "3xl": "24px", "4xl": "32px", full: "9999px" };
|
|
37
|
+
export function radius(v) {
|
|
38
|
+
if (v == null || v === "")
|
|
39
|
+
return undefined;
|
|
40
|
+
if (typeof v === "number")
|
|
41
|
+
return `${v}px`;
|
|
42
|
+
if (typeof v === "string")
|
|
43
|
+
return RADIUS[v] ?? v;
|
|
44
|
+
const r = v;
|
|
45
|
+
const one = (x) => (x ? RADIUS[x] ?? x : "0");
|
|
46
|
+
return `${one(r.topLeft)} ${one(r.topRight)} ${one(r.bottomRight)} ${one(r.bottomLeft)}`;
|
|
47
|
+
}
|
|
48
|
+
const TONES = ["info", "success", "warning", "caution", "danger", "discovery", "primary", "secondary"];
|
|
49
|
+
/** A colour token (`success`, `danger`, `muted`, `surface-secondary`, `info-solid`, …) or any CSS colour. */
|
|
50
|
+
export function color(v) {
|
|
51
|
+
if (typeof v !== "string" || !v)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (v === "default" || v === "surface")
|
|
54
|
+
return "var(--ainui-surface)";
|
|
55
|
+
if (v === "surface-secondary" || v === "subtle")
|
|
56
|
+
return "var(--ainui-surface-2)";
|
|
57
|
+
if (v === "strong")
|
|
58
|
+
return "var(--ainui-border-strong)";
|
|
59
|
+
if (v === "muted" || v === "tertiary")
|
|
60
|
+
return "var(--ainui-muted)";
|
|
61
|
+
if (v.endsWith("-solid") && TONES.includes(v.slice(0, -6)))
|
|
62
|
+
return `var(--ainui-${v.slice(0, -6)})`;
|
|
63
|
+
if (TONES.includes(v))
|
|
64
|
+
return `var(--ainui-${v})`;
|
|
65
|
+
return v;
|
|
66
|
+
}
|
|
67
|
+
/** Background for a tone: the soft tint, or the solid colour for `x-solid`. */
|
|
68
|
+
export function surfaceColor(v) {
|
|
69
|
+
if (typeof v !== "string" || !v)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (TONES.includes(v))
|
|
72
|
+
return `var(--ainui-${v}-soft)`;
|
|
73
|
+
return color(v);
|
|
74
|
+
}
|
|
75
|
+
const ALIGN = { start: "flex-start", center: "center", end: "flex-end", baseline: "baseline", stretch: "stretch" };
|
|
76
|
+
const JUSTIFY = { start: "flex-start", center: "center", end: "flex-end", spaceBetween: "space-between", spaceAround: "space-around", spaceEvenly: "space-evenly", stretch: "stretch" };
|
|
77
|
+
/**
|
|
78
|
+
* The layout props every container shares (gap, padding, background, border, radius, sizes, flex, scrolling) as
|
|
79
|
+
* inline style. Containers pass their own defaults first: `{ ...defaults, ...boxStyle(props) }`.
|
|
80
|
+
*/
|
|
81
|
+
export function boxStyle(p) {
|
|
82
|
+
const s = {};
|
|
83
|
+
const set = (k, v) => { if (v !== undefined && v !== null && v !== "")
|
|
84
|
+
s[k] = v; };
|
|
85
|
+
set("alignItems", ALIGN[p.align]);
|
|
86
|
+
set("justifyContent", JUSTIFY[p.justify]);
|
|
87
|
+
set("flexWrap", p.wrap);
|
|
88
|
+
set("gap", space(p.gap));
|
|
89
|
+
set("rowGap", space(p.rowGap));
|
|
90
|
+
set("columnGap", space(p.columnGap));
|
|
91
|
+
set("padding", space(p.padding));
|
|
92
|
+
set("background", surfaceColor(p.background));
|
|
93
|
+
if (p.border)
|
|
94
|
+
set("border", `1px solid ${color(p.borderColor) && p.borderColor !== "default" ? color(p.borderColor) : "var(--ainui-border)"}`);
|
|
95
|
+
set("borderRadius", radius(p.radius));
|
|
96
|
+
set("width", px(p.width));
|
|
97
|
+
set("height", px(p.height));
|
|
98
|
+
set("minWidth", px(p.minWidth ?? p.minSize));
|
|
99
|
+
set("maxWidth", px(p.maxWidth ?? p.maxSize));
|
|
100
|
+
set("minHeight", px(p.minHeight));
|
|
101
|
+
set("maxHeight", px(p.maxHeight));
|
|
102
|
+
if (typeof (p.flex ?? p.weight) === "number") {
|
|
103
|
+
set("flex", `${p.flex ?? p.weight} 1 0%`);
|
|
104
|
+
if (s.minWidth === undefined)
|
|
105
|
+
s.minWidth = 0;
|
|
106
|
+
}
|
|
107
|
+
set("aspectRatio", p.aspectRatio);
|
|
108
|
+
if (p.scrollable)
|
|
109
|
+
set("overflow", "auto");
|
|
110
|
+
else if (p.clip)
|
|
111
|
+
set("overflow", "hidden");
|
|
112
|
+
if (p.shadow)
|
|
113
|
+
set("boxShadow", "var(--ainui-shadow)");
|
|
114
|
+
if (p.inline)
|
|
115
|
+
set("display", "inline-flex");
|
|
116
|
+
return s;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Sends the component's action with extra context merged in — a follow-up's text, the id of the row that was
|
|
120
|
+
* clicked. For an action that needs nothing extra, call the resolved prop (`props.onClick?.()`) instead.
|
|
121
|
+
*/
|
|
122
|
+
export async function fire(context, prop, extra = {}) {
|
|
123
|
+
const raw = context.componentModel.properties[prop];
|
|
124
|
+
if (!raw)
|
|
125
|
+
return;
|
|
126
|
+
const action = context.dataContext.resolveAction(raw, { userActivation: true });
|
|
127
|
+
const resolved = action && typeof action.then === "function" ? await action : action;
|
|
128
|
+
if (resolved?.event)
|
|
129
|
+
await context.dispatchAction({ event: { ...resolved.event, context: { ...resolved.event.context, ...extra } } });
|
|
130
|
+
}
|
|
131
|
+
/** The data-model path a property is bound to, or undefined for a literal. */
|
|
132
|
+
export function boundPath(context, prop) {
|
|
133
|
+
const raw = context.componentModel.properties[prop];
|
|
134
|
+
return raw && typeof raw === "object" ? raw["@path"] ?? (typeof raw.path === "string" && Object.keys(raw).length === 1 ? raw.path : undefined) : undefined;
|
|
135
|
+
}
|
|
136
|
+
export const HostContext = createContext({ resolveAsset: () => "" });
|
|
137
|
+
export const useHost = () => useContext(HostContext);
|
|
138
|
+
/** Only http(s), site-relative and blob URLs are drawn; anything else (javascript:, data:) is dropped. */
|
|
139
|
+
export function safeUrl(value) {
|
|
140
|
+
if (typeof value !== "string")
|
|
141
|
+
return "";
|
|
142
|
+
const v = value.trim();
|
|
143
|
+
return /^\/(?!\/)/.test(v) || /^https?:\/\//i.test(v) || /^blob:/i.test(v) ? v : "";
|
|
144
|
+
}
|
|
145
|
+
/** A media value: a URL, or a private asset reference resolved by the host. */
|
|
146
|
+
export function mediaUrl(value, host, download = false) {
|
|
147
|
+
const raw = value && typeof value === "object" && "$asset" in value ? host.resolveAsset(value.$asset, { download }) : value;
|
|
148
|
+
return safeUrl(raw);
|
|
149
|
+
}
|
|
150
|
+
export function openUrl(host, href) {
|
|
151
|
+
const url = safeUrl(href);
|
|
152
|
+
if (!url)
|
|
153
|
+
return;
|
|
154
|
+
if (host.openUrl)
|
|
155
|
+
host.openUrl(url);
|
|
156
|
+
else
|
|
157
|
+
globalThis.open?.(url, "_blank", "noopener,noreferrer");
|
|
158
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the catalog's functions do in the renderer. The catalog document only declares them; without these a
|
|
3
|
+
* `formatString`, a validation check or a `calc` would resolve to nothing.
|
|
4
|
+
*/
|
|
5
|
+
import { createFunctionImplementation } from "@a2ui/web_core";
|
|
6
|
+
import { basicCatalog } from "@a2ui/web_core/catalogs/basic/v1";
|
|
7
|
+
import { evaluate, series } from "../expression.js";
|
|
8
|
+
import { STANDARD } from "./core.js";
|
|
9
|
+
const own = {
|
|
10
|
+
// An expression that cannot be evaluated shows as nothing rather than breaking the surface.
|
|
11
|
+
calc: ({ expression, ...variables }) => { try {
|
|
12
|
+
return evaluate(String(expression ?? ""), variables);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
} },
|
|
17
|
+
series: (args) => { try {
|
|
18
|
+
return series(args);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return [];
|
|
22
|
+
} },
|
|
23
|
+
};
|
|
24
|
+
/** One implementation per function the catalog declares: A2UI's own for the basic ones, ours for the rest. */
|
|
25
|
+
export const functionImplementations = [...STANDARD.functions.values()].flatMap((api) => {
|
|
26
|
+
const basic = basicCatalog.functions.get(api.name);
|
|
27
|
+
const execute = own[api.name] ?? basic?.execute;
|
|
28
|
+
return execute ? [createFunctionImplementation(api, execute)] : [];
|
|
29
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const composites: import("@a2ui/react").ReactComponentImplementation<import("zod").ZodTypeAny>[];
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
/** Standard catalog — composites: link previews, citations, follow-up prompts, entity cards, image galleries. */
|
|
4
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { cx, fire, mediaUrl, openUrl, px, safeUrl, space, standard, useHost } from "../core.js";
|
|
6
|
+
import { Lightbox, SiteIcon, siteHost } from "./media.js";
|
|
7
|
+
const str = (v) => (typeof v === "string" ? v : typeof v === "number" && Number.isFinite(v) ? String(v) : "");
|
|
8
|
+
const num = (v) => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
9
|
+
const list = (v) => (Array.isArray(v) ? v : []);
|
|
10
|
+
const obj = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : {});
|
|
11
|
+
/** An image that removes itself when it does not load. */
|
|
12
|
+
function Thumb({ src, alt = "", className }) {
|
|
13
|
+
const [failed, setFailed] = useState("");
|
|
14
|
+
return src && failed !== src ? _jsx("img", { className: className, src: src, alt: alt, loading: "lazy", onError: () => setFailed(src) }) : null;
|
|
15
|
+
}
|
|
16
|
+
const LinkCard = standard("LinkCard", ({ props }) => {
|
|
17
|
+
const host = useHost();
|
|
18
|
+
const href = safeUrl(props.href);
|
|
19
|
+
const title = str(props.title), description = str(props.description);
|
|
20
|
+
const domain = str(props.domain) || siteHost(href);
|
|
21
|
+
const image = mediaUrl(props.image, host);
|
|
22
|
+
const body = _jsxs(_Fragment, { children: [_jsxs("span", { className: "ainui-link-card-body", children: [(domain || (props.favicon !== false && href)) && _jsxs("span", { className: "ainui-link-card-source", children: [props.favicon !== false && _jsx(SiteIcon, { url: href || domain, size: 16 }), domain && _jsx("span", { className: "ainui-link-card-domain", children: domain })] }), _jsx("span", { className: "ainui-link-card-title", children: title || domain || href }), description && _jsx("span", { className: "ainui-link-card-description", children: description })] }), _jsx(Thumb, { className: "ainui-link-card-image", src: image })] });
|
|
23
|
+
if (props.onClick || !href) {
|
|
24
|
+
return _jsx("button", { type: "button", className: "ainui-link-card", disabled: !props.onClick, onClick: () => void props.onClick?.(), children: body });
|
|
25
|
+
}
|
|
26
|
+
return _jsx("a", { className: "ainui-link-card", href: href, target: "_blank", rel: "noopener noreferrer", onClick: host.openUrl ? (e) => { e.preventDefault(); openUrl(host, href); } : undefined, children: body });
|
|
27
|
+
});
|
|
28
|
+
const Citation = standard("Citation", ({ props }) => {
|
|
29
|
+
const host = useHost();
|
|
30
|
+
const id = useId();
|
|
31
|
+
const wrap = useRef(null);
|
|
32
|
+
const [hover, setHover] = useState(false);
|
|
33
|
+
const [pinned, setPinned] = useState(false);
|
|
34
|
+
const open = hover || pinned;
|
|
35
|
+
const url = safeUrl(props.url);
|
|
36
|
+
const marker = str(props.label) || String(num(props.index) ?? 1);
|
|
37
|
+
const title = str(props.title), snippet = str(props.snippet), source = str(props.source) || siteHost(url);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!pinned)
|
|
40
|
+
return;
|
|
41
|
+
const away = (e) => { if (wrap.current && !wrap.current.contains(e.target))
|
|
42
|
+
setPinned(false); };
|
|
43
|
+
document.addEventListener("mousedown", away);
|
|
44
|
+
return () => document.removeEventListener("mousedown", away);
|
|
45
|
+
}, [pinned]);
|
|
46
|
+
const leave = (e) => { if (!wrap.current?.contains(e.relatedTarget)) {
|
|
47
|
+
setHover(false);
|
|
48
|
+
setPinned(false);
|
|
49
|
+
} };
|
|
50
|
+
return _jsxs("span", { ref: wrap, className: "ainui-citation", onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), onFocus: () => setHover(true), onBlur: leave, onKeyDown: (e) => { if (e.key === "Escape") {
|
|
51
|
+
setHover(false);
|
|
52
|
+
setPinned(false);
|
|
53
|
+
} }, children: [_jsxs("button", { type: "button", className: "ainui-citation-marker", "aria-expanded": open, "aria-controls": open ? id : undefined, "aria-label": `Source ${marker}${title ? `: ${title}` : ""}`, onClick: () => setPinned((v) => !v), children: ["[", marker, "]"] }), open && _jsxs("span", { id: id, role: "note", className: "ainui-citation-popover", children: [source && _jsxs("span", { className: "ainui-citation-source", children: [_jsx(SiteIcon, { url: url || source, size: 14 }), source] }), title && _jsx("span", { className: "ainui-citation-title", children: title }), snippet && _jsx("span", { className: "ainui-citation-snippet", children: snippet }), url && _jsx("a", { className: "ainui-citation-link", href: url, target: "_blank", rel: "noopener noreferrer", onClick: host.openUrl ? (e) => { e.preventDefault(); openUrl(host, url); } : undefined, children: "Open source" })] })] });
|
|
54
|
+
});
|
|
55
|
+
const FollowUp = standard("FollowUp", ({ props, context }) => {
|
|
56
|
+
const host = useHost();
|
|
57
|
+
const items = list(props.items).map((it) => (typeof it === "string" ? { label: it, message: it } : { label: str(obj(it).label), message: str(obj(it).message) || str(obj(it).label) }))
|
|
58
|
+
.filter((it) => it.label);
|
|
59
|
+
const title = str(props.title);
|
|
60
|
+
const id = useId();
|
|
61
|
+
if (!items.length)
|
|
62
|
+
return null;
|
|
63
|
+
const send = (message) => { host.sendMessage?.(message); if (props.onFollowUp)
|
|
64
|
+
void fire(context, "onFollowUp", { message }); };
|
|
65
|
+
return _jsxs("div", { className: "ainui-follow-up", role: "group", "aria-labelledby": title ? id : undefined, "aria-label": title ? undefined : "Suggested follow-ups", children: [title && _jsx("span", { id: id, className: "ainui-follow-up-title", children: title }), _jsx("span", { className: "ainui-follow-up-items", children: items.map((it, i) => _jsx("button", { type: "button", className: "ainui-follow-up-item", onClick: () => send(it.message), children: it.label }, i)) })] });
|
|
66
|
+
});
|
|
67
|
+
const BADGE_TONES = ["secondary", "success", "danger", "warning", "info", "discovery"];
|
|
68
|
+
const BUTTON_VARIANTS = ["solid", "soft", "outline", "ghost"];
|
|
69
|
+
function Stars({ rating, count }) {
|
|
70
|
+
const value = Math.max(0, Math.min(5, rating));
|
|
71
|
+
const shown = Math.round(value * 10) / 10;
|
|
72
|
+
return _jsxs("span", { className: "ainui-entity-card-rating", role: "img", "aria-label": `Rated ${shown} out of 5${count !== undefined ? `, ${count.toLocaleString()} ${count === 1 ? "rating" : "ratings"}` : ""}`, children: [_jsxs("span", { className: "ainui-entity-card-stars", "aria-hidden": "true", children: ["\u2605\u2605\u2605\u2605\u2605", _jsx("span", { className: "ainui-entity-card-stars-on", style: { width: `${(value / 5) * 100}%` }, children: "\u2605\u2605\u2605\u2605\u2605" })] }), _jsx("span", { className: "ainui-entity-card-rating-value", "aria-hidden": "true", children: shown }), count !== undefined && _jsxs("span", { className: "ainui-entity-card-rating-count", "aria-hidden": "true", children: ["(", count.toLocaleString(), ")"] })] });
|
|
73
|
+
}
|
|
74
|
+
const EntityCard = standard("EntityCard", ({ props, context }) => {
|
|
75
|
+
const host = useHost();
|
|
76
|
+
const href = safeUrl(props.href);
|
|
77
|
+
const title = str(props.title);
|
|
78
|
+
const image = mediaUrl(props.image, host);
|
|
79
|
+
const badge = obj(props.badge);
|
|
80
|
+
const rating = num(props.rating);
|
|
81
|
+
const count = num(props.ratingCount);
|
|
82
|
+
const actions = list(props.actions).map((a) => obj(a)).filter((a) => str(a.label)).slice(0, 3);
|
|
83
|
+
const horizontal = props.layout === "horizontal";
|
|
84
|
+
const clickable = !!href || !!props.onClick;
|
|
85
|
+
// The title carries the card's link; its hit area is stretched over the card in CSS, under the buttons.
|
|
86
|
+
const heading = href
|
|
87
|
+
? _jsx("a", { className: "ainui-entity-card-title ainui-entity-card-hit", href: href, target: "_blank", rel: "noopener noreferrer", onClick: host.openUrl ? (e) => { e.preventDefault(); openUrl(host, href); } : undefined, children: title })
|
|
88
|
+
: props.onClick ? _jsx("button", { type: "button", className: "ainui-entity-card-title ainui-entity-card-hit", onClick: () => void props.onClick(), children: title })
|
|
89
|
+
: _jsx("span", { className: "ainui-entity-card-title", children: title });
|
|
90
|
+
return _jsxs("article", { className: cx("ainui-entity-card", `ainui-entity-card-${horizontal ? "horizontal" : "vertical"}`, clickable && "ainui-entity-card-clickable"), style: { width: px(props.width) }, children: [image && _jsx("span", { className: "ainui-entity-card-media", style: { aspectRatio: str(props.imageAspectRatio) || "4 / 3" }, children: _jsx(Thumb, { src: image }) }), _jsxs("div", { className: "ainui-entity-card-body", children: [str(badge.label) && _jsx("span", { className: cx("ainui-entity-card-badge", `ainui-entity-card-badge-${BADGE_TONES.includes(badge.color) ? badge.color : "secondary"}`), children: str(badge.label) }), heading, str(props.subtitle) && _jsx("span", { className: "ainui-entity-card-subtitle", children: str(props.subtitle) }), rating !== undefined && _jsx(Stars, { rating: rating, count: count }), str(props.description) && _jsx("p", { className: "ainui-entity-card-description", children: str(props.description) }), str(props.meta) && _jsx("span", { className: "ainui-entity-card-meta", children: str(props.meta) }), actions.length > 0 && _jsx("div", { className: "ainui-entity-card-actions", children: actions.map((a, i) => {
|
|
91
|
+
const label = str(a.label), link = safeUrl(a.href);
|
|
92
|
+
const className = cx("ainui-entity-card-action", `ainui-entity-card-action-${BUTTON_VARIANTS.includes(a.variant) ? a.variant : i === 0 ? "solid" : "outline"}`);
|
|
93
|
+
return link
|
|
94
|
+
? _jsx("a", { className: className, href: link, target: "_blank", rel: "noopener noreferrer", onClick: host.openUrl ? (e) => { e.preventDefault(); openUrl(host, link); } : undefined, children: label }, i)
|
|
95
|
+
: _jsx("button", { type: "button", className: className, onClick: () => void fire(context, "onAction", { action: str(a.id) || label, label }), children: label }, i);
|
|
96
|
+
}) })] })] });
|
|
97
|
+
});
|
|
98
|
+
const ImageGrid = standard("ImageGrid", ({ props }) => {
|
|
99
|
+
const host = useHost();
|
|
100
|
+
const [open, setOpen] = useState(null);
|
|
101
|
+
const images = list(props.images).map((im) => (typeof im === "string" ? { url: im } : obj(im)))
|
|
102
|
+
.map((im) => ({ src: mediaUrl(im.url, host), alt: str(im.description), caption: str(im.caption), href: safeUrl(im.href) })).filter((im) => im.src);
|
|
103
|
+
if (!images.length)
|
|
104
|
+
return null;
|
|
105
|
+
const columns = Math.max(1, Math.min(12, Math.floor(num(props.columns) ?? 3)));
|
|
106
|
+
const bento = props.layout === "bento";
|
|
107
|
+
const ratio = str(props.aspectRatio) || "1 / 1";
|
|
108
|
+
return _jsxs("div", { className: cx("ainui-image-grid", bento && "ainui-image-grid-bento"), style: { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`, gap: space(props.gap) ?? "8px" }, children: [images.map((im, i) => _jsxs("figure", { className: "ainui-image-grid-item", style: bento && i === 0 && columns > 1 ? { gridColumn: "span 2", gridRow: "span 2" } : undefined, children: [_jsx("button", { type: "button", className: "ainui-image-grid-open", "aria-label": im.alt ? `Open image: ${im.alt}` : `Open image ${i + 1}`, onClick: () => setOpen(i), style: { aspectRatio: bento && i === 0 && columns > 1 ? undefined : ratio }, children: _jsx("img", { src: im.src, alt: im.alt, loading: "lazy" }) }), (im.caption || im.href) && _jsx("figcaption", { className: "ainui-image-grid-caption", children: im.href ? _jsx("a", { href: im.href, target: "_blank", rel: "noopener noreferrer", onClick: host.openUrl ? (e) => { e.preventDefault(); openUrl(host, im.href); } : undefined, children: im.caption || siteHost(im.href) || "Open" }) : im.caption })] }, i)), open !== null && _jsx(Lightbox, { images: images, index: open, onIndex: setOpen, onClose: () => setOpen(null) })] });
|
|
109
|
+
});
|
|
110
|
+
export const composites = [LinkCard, Citation, FollowUp, EntityCard, ImageGrid];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const data: import("@a2ui/react").ReactComponentImplementation<import("zod").ZodTypeAny>[];
|