@assistant-ui/react-generative-ui 0.0.6 → 0.0.8
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/dist/JSONGenerativeUI.client.d.ts +4 -2
- package/dist/JSONGenerativeUI.client.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.client.js +9 -2
- package/dist/JSONGenerativeUI.client.js.map +1 -1
- package/dist/JSONGenerativeUI.server.d.ts +0 -1
- package/dist/JSONGenerativeUI.server.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.shared.d.ts +8 -1
- package/dist/JSONGenerativeUI.shared.d.ts.map +1 -1
- package/dist/JSONGenerativeUI.shared.js.map +1 -1
- package/dist/actionRegistry.d.ts +32 -0
- package/dist/actionRegistry.d.ts.map +1 -0
- package/dist/actionRegistry.js +41 -0
- package/dist/actionRegistry.js.map +1 -0
- package/dist/buildPresentParameters.d.ts +5 -5
- package/dist/buildPresentParameters.d.ts.map +1 -1
- package/dist/buildPresentParameters.js +20 -6
- package/dist/buildPresentParameters.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/defineGenerativeComponents.d.ts +0 -1
- package/dist/defineGenerativeComponents.d.ts.map +1 -1
- package/dist/generativeUIToJSX.d.ts +15 -10
- package/dist/generativeUIToJSX.d.ts.map +1 -1
- package/dist/generativeUIToJSX.js +47 -17
- package/dist/generativeUIToJSX.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +5 -2
- package/dist/index.server.d.ts +13 -0
- package/dist/index.server.js +10 -0
- package/dist/index.shared.d.ts +11 -0
- package/dist/index.shared.js +9 -0
- package/dist/ir.d.ts +115 -0
- package/dist/ir.d.ts.map +1 -0
- package/dist/ir.js +175 -0
- package/dist/ir.js.map +1 -0
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts +3 -3
- package/dist/node_modules/.pnpm/@types_json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts.map +1 -1
- package/dist/renderGenerativeUI.d.ts +5 -5
- package/dist/renderGenerativeUI.d.ts.map +1 -1
- package/dist/renderGenerativeUI.js +18 -45
- package/dist/renderGenerativeUI.js.map +1 -1
- package/dist/slack/constants.d.ts +111 -0
- package/dist/slack/constants.d.ts.map +1 -0
- package/dist/slack/constants.js +168 -0
- package/dist/slack/constants.js.map +1 -0
- package/dist/slack/decodeBlockAction.d.ts +11 -0
- package/dist/slack/decodeBlockAction.d.ts.map +1 -0
- package/dist/slack/decodeBlockAction.js +40 -0
- package/dist/slack/decodeBlockAction.js.map +1 -0
- package/dist/slack/fromSlackBlocks.d.ts +30 -0
- package/dist/slack/fromSlackBlocks.d.ts.map +1 -0
- package/dist/slack/fromSlackBlocks.js +447 -0
- package/dist/slack/fromSlackBlocks.js.map +1 -0
- package/dist/slack/toSlackBlocks.d.ts +7 -0
- package/dist/slack/toSlackBlocks.d.ts.map +1 -0
- package/dist/slack/toSlackBlocks.js +649 -0
- package/dist/slack/toSlackBlocks.js.map +1 -0
- package/dist/slack/types.d.ts +178 -0
- package/dist/slack/types.d.ts.map +1 -0
- package/dist/slack/types.js +0 -0
- package/dist/slack.d.ts +5 -0
- package/dist/slack.js +4 -0
- package/dist/teams/boundSpec.d.ts +20 -0
- package/dist/teams/boundSpec.d.ts.map +1 -0
- package/dist/teams/boundSpec.js +67 -0
- package/dist/teams/boundSpec.js.map +1 -0
- package/dist/teams/constants.d.ts +57 -0
- package/dist/teams/constants.d.ts.map +1 -0
- package/dist/teams/constants.js +92 -0
- package/dist/teams/constants.js.map +1 -0
- package/dist/teams/decodeSubmitData.d.ts +25 -0
- package/dist/teams/decodeSubmitData.d.ts.map +1 -0
- package/dist/teams/decodeSubmitData.js +44 -0
- package/dist/teams/decodeSubmitData.js.map +1 -0
- package/dist/teams/toAdaptiveCard.d.ts +39 -0
- package/dist/teams/toAdaptiveCard.d.ts.map +1 -0
- package/dist/teams/toAdaptiveCard.js +496 -0
- package/dist/teams/toAdaptiveCard.js.map +1 -0
- package/dist/teams/toTeamsAttachments.d.ts +13 -0
- package/dist/teams/toTeamsAttachments.d.ts.map +1 -0
- package/dist/teams/toTeamsAttachments.js +95 -0
- package/dist/teams/toTeamsAttachments.js.map +1 -0
- package/dist/teams/types.d.ts +196 -0
- package/dist/teams/types.d.ts.map +1 -0
- package/dist/teams/types.js +0 -0
- package/dist/teams.d.ts +5 -0
- package/dist/teams.js +4 -0
- package/dist/types.d.ts +41 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/vocabulary/alert.d.ts +28 -0
- package/dist/vocabulary/alert.d.ts.map +1 -0
- package/dist/vocabulary/alert.js +58 -0
- package/dist/vocabulary/alert.js.map +1 -0
- package/dist/vocabulary/collectFormValues.d.ts +23 -0
- package/dist/vocabulary/collectFormValues.d.ts.map +1 -0
- package/dist/vocabulary/collectFormValues.js +32 -0
- package/dist/vocabulary/collectFormValues.js.map +1 -0
- package/dist/vocabulary/data.d.ts +52 -0
- package/dist/vocabulary/data.d.ts.map +1 -0
- package/dist/vocabulary/data.js +294 -0
- package/dist/vocabulary/data.js.map +1 -0
- package/dist/vocabulary/dispatch.d.ts +11 -0
- package/dist/vocabulary/dispatch.d.ts.map +1 -0
- package/dist/vocabulary/dispatch.js +21 -0
- package/dist/vocabulary/dispatch.js.map +1 -0
- package/dist/vocabulary/fact.d.ts +15 -0
- package/dist/vocabulary/fact.d.ts.map +1 -0
- package/dist/vocabulary/fact.js +24 -0
- package/dist/vocabulary/fact.js.map +1 -0
- package/dist/vocabulary/form.d.ts +14 -0
- package/dist/vocabulary/form.d.ts.map +1 -0
- package/dist/vocabulary/form.js +23 -0
- package/dist/vocabulary/form.js.map +1 -0
- package/dist/vocabulary/icon.d.ts +44 -0
- package/dist/vocabulary/icon.d.ts.map +1 -0
- package/dist/vocabulary/icon.js +272 -0
- package/dist/vocabulary/icon.js.map +1 -0
- package/dist/vocabulary/index.d.ts +15 -0
- package/dist/vocabulary/index.d.ts.map +1 -0
- package/dist/vocabulary/index.js +36 -0
- package/dist/vocabulary/index.js.map +1 -0
- package/dist/vocabulary/interactive.d.ts +93 -0
- package/dist/vocabulary/interactive.d.ts.map +1 -0
- package/dist/vocabulary/interactive.js +172 -0
- package/dist/vocabulary/interactive.js.map +1 -0
- package/dist/vocabulary/layout.d.ts +82 -0
- package/dist/vocabulary/layout.d.ts.map +1 -0
- package/dist/vocabulary/layout.js +136 -0
- package/dist/vocabulary/layout.js.map +1 -0
- package/dist/vocabulary/list.d.ts +17 -0
- package/dist/vocabulary/list.d.ts.map +1 -0
- package/dist/vocabulary/list.js +48 -0
- package/dist/vocabulary/list.js.map +1 -0
- package/dist/vocabulary/media.d.ts +28 -0
- package/dist/vocabulary/media.d.ts.map +1 -0
- package/dist/vocabulary/media.js +42 -0
- package/dist/vocabulary/media.js.map +1 -0
- package/dist/vocabulary/text.d.ts +60 -0
- package/dist/vocabulary/text.d.ts.map +1 -0
- package/dist/vocabulary/text.js +48 -0
- package/dist/vocabulary/text.js.map +1 -0
- package/package.json +21 -13
- package/src/JSONGenerativeUI.client.tsx +10 -2
- package/src/JSONGenerativeUI.shared.ts +8 -0
- package/src/actionRegistry.test.ts +90 -0
- package/src/actionRegistry.ts +88 -0
- package/src/buildPresentParameters.ts +38 -16
- package/src/generativeUIToJSX.test.ts +186 -0
- package/src/generativeUIToJSX.ts +112 -21
- package/src/index.server.ts +2 -0
- package/src/index.shared.ts +61 -0
- package/src/index.ts +2 -26
- package/src/ir.test.ts +203 -0
- package/src/ir.ts +279 -0
- package/src/renderGenerativeUI.test.tsx +69 -2
- package/src/renderGenerativeUI.tsx +49 -82
- package/src/slack/constants.ts +217 -0
- package/src/slack/decodeBlockAction.test.ts +135 -0
- package/src/slack/decodeBlockAction.ts +66 -0
- package/src/slack/fromSlackBlocks.test.ts +1145 -0
- package/src/slack/fromSlackBlocks.ts +709 -0
- package/src/slack/toSlackBlocks.test.ts +1936 -0
- package/src/slack/toSlackBlocks.ts +1319 -0
- package/src/slack/types.ts +230 -0
- package/src/slack.ts +37 -0
- package/src/teams/boundSpec.ts +102 -0
- package/src/teams/constants.ts +127 -0
- package/src/teams/decodeSubmitData.test.ts +148 -0
- package/src/teams/decodeSubmitData.ts +57 -0
- package/src/teams/toAdaptiveCard.test.ts +1410 -0
- package/src/teams/toAdaptiveCard.ts +762 -0
- package/src/teams/toTeamsAttachments.test.ts +29 -0
- package/src/teams/toTeamsAttachments.ts +137 -0
- package/src/teams/types.ts +237 -0
- package/src/teams.ts +34 -0
- package/src/types.ts +57 -42
- package/src/vocabulary/alert.test.tsx +136 -0
- package/src/vocabulary/alert.tsx +66 -0
- package/src/vocabulary/collectFormValues.test.ts +127 -0
- package/src/vocabulary/collectFormValues.ts +58 -0
- package/src/vocabulary/data.test.tsx +567 -0
- package/src/vocabulary/data.tsx +494 -0
- package/src/vocabulary/dispatch.ts +22 -0
- package/src/vocabulary/fact.test.tsx +15 -0
- package/src/vocabulary/fact.tsx +22 -0
- package/src/vocabulary/form.test.tsx +112 -0
- package/src/vocabulary/form.tsx +34 -0
- package/src/vocabulary/icon.test.tsx +64 -0
- package/src/vocabulary/icon.tsx +174 -0
- package/src/vocabulary/index.test.ts +63 -0
- package/src/vocabulary/index.ts +33 -0
- package/src/vocabulary/interactive.dispatch.test.tsx +352 -0
- package/src/vocabulary/interactive.test.tsx +248 -0
- package/src/vocabulary/interactive.tsx +269 -0
- package/src/vocabulary/layout.test.tsx +289 -0
- package/src/vocabulary/layout.tsx +229 -0
- package/src/vocabulary/list.test.tsx +195 -0
- package/src/vocabulary/list.tsx +48 -0
- package/src/vocabulary/media.test.tsx +85 -0
- package/src/vocabulary/media.tsx +56 -0
- package/src/vocabulary/text.test.tsx +73 -0
- package/src/vocabulary/text.tsx +59 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ALERT_TONES } from "../ir.js";
|
|
2
|
+
import { Children } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/vocabulary/alert.tsx
|
|
6
|
+
const MAX_CARDS = 10;
|
|
7
|
+
const alertVocabulary = {
|
|
8
|
+
Alert: {
|
|
9
|
+
description: "A highlighted message conveying urgency. `tone` drives the severity.",
|
|
10
|
+
properties: z.object({
|
|
11
|
+
title: z.string().optional().describe("Alert title."),
|
|
12
|
+
description: z.string().optional().describe("Supporting description text."),
|
|
13
|
+
tone: z.enum(ALERT_TONES).optional().describe("Severity tone; defaults to `info`.")
|
|
14
|
+
}),
|
|
15
|
+
render: ({ title, description, tone, children }) => /* @__PURE__ */ jsxs("div", {
|
|
16
|
+
"data-aui": "alert",
|
|
17
|
+
"data-aui-tone": tone ?? "info",
|
|
18
|
+
role: "alert",
|
|
19
|
+
children: [
|
|
20
|
+
title ? /* @__PURE__ */ jsx("header", {
|
|
21
|
+
"data-aui": "alert-title",
|
|
22
|
+
children: title
|
|
23
|
+
}) : null,
|
|
24
|
+
description ? /* @__PURE__ */ jsx("p", {
|
|
25
|
+
"data-aui": "alert-desc",
|
|
26
|
+
children: description
|
|
27
|
+
}) : null,
|
|
28
|
+
children
|
|
29
|
+
]
|
|
30
|
+
})
|
|
31
|
+
},
|
|
32
|
+
Carousel: {
|
|
33
|
+
description: "A horizontally scrollable group of `Card` children (max 10). Set `label` for an accessible name.",
|
|
34
|
+
properties: z.object({ label: z.string().optional().describe("Accessible label for the carousel.") }),
|
|
35
|
+
render: ({ label, children }) => {
|
|
36
|
+
const cards = Children.toArray(children).slice(0, MAX_CARDS);
|
|
37
|
+
const n = cards.length;
|
|
38
|
+
return /* @__PURE__ */ jsx("div", {
|
|
39
|
+
"data-aui": "carousel",
|
|
40
|
+
role: label ? "region" : "group",
|
|
41
|
+
"aria-roledescription": "carousel",
|
|
42
|
+
"aria-label": label,
|
|
43
|
+
tabIndex: 0,
|
|
44
|
+
children: cards.map((card, i) => /* @__PURE__ */ jsx("div", {
|
|
45
|
+
"data-aui": "carousel-slide",
|
|
46
|
+
role: "group",
|
|
47
|
+
"aria-roledescription": "slide",
|
|
48
|
+
"aria-label": `${i + 1} of ${n}`,
|
|
49
|
+
children: card
|
|
50
|
+
}, i))
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { alertVocabulary };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=alert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert.js","names":[],"sources":["../../src/vocabulary/alert.tsx"],"sourcesContent":["import { Children } from \"react\";\nimport { z } from \"zod\";\nimport type { GenerativeUILibrary } from \"../types\";\nimport { ALERT_TONES } from \"../ir\";\n\nconst MAX_CARDS = 10;\n\nexport const alertVocabulary = {\n Alert: {\n description:\n \"A highlighted message conveying urgency. `tone` drives the severity.\",\n properties: z.object({\n title: z.string().optional().describe(\"Alert title.\"),\n description: z\n .string()\n .optional()\n .describe(\"Supporting description text.\"),\n tone: z\n .enum(ALERT_TONES)\n .optional()\n .describe(\"Severity tone; defaults to `info`.\"),\n }),\n render: ({ title, description, tone, children }) => (\n <div data-aui=\"alert\" data-aui-tone={tone ?? \"info\"} role=\"alert\">\n {title ? <header data-aui=\"alert-title\">{title}</header> : null}\n {description ? <p data-aui=\"alert-desc\">{description}</p> : null}\n {children}\n </div>\n ),\n },\n Carousel: {\n description:\n \"A horizontally scrollable group of `Card` children (max 10). Set `label` for an accessible name.\",\n properties: z.object({\n label: z\n .string()\n .optional()\n .describe(\"Accessible label for the carousel.\"),\n }),\n render: ({ label, children }) => {\n const cards = Children.toArray(children).slice(0, MAX_CARDS);\n const n = cards.length;\n return (\n <div\n data-aui=\"carousel\"\n role={label ? \"region\" : \"group\"}\n aria-roledescription=\"carousel\"\n aria-label={label}\n tabIndex={0}\n >\n {cards.map((card, i) => (\n <div\n key={i}\n data-aui=\"carousel-slide\"\n role=\"group\"\n aria-roledescription=\"slide\"\n aria-label={`${i + 1} of ${n}`}\n >\n {card}\n </div>\n ))}\n </div>\n );\n },\n },\n} satisfies GenerativeUILibrary;\n"],"mappings":";;;;;AAKA,MAAM,YAAY;AAElB,MAAa,kBAAkB;CAC7B,OAAO;EACL,aACE;EACF,YAAY,EAAE,OAAO;GACnB,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,cAAc;GACpD,aAAa,EACV,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,8BAA8B;GAC1C,MAAM,EACH,KAAK,WAAW,CAAC,CACjB,SAAS,CAAC,CACV,SAAS,oCAAoC;EAClD,CAAC;EACD,SAAS,EAAE,OAAO,aAAa,MAAM,eACnC,qBAAC,OAAD;GAAK,YAAS;GAAQ,iBAAe,QAAQ;GAAQ,MAAK;aAA1D;IACG,QAAQ,oBAAC,UAAD;KAAQ,YAAS;eAAe;IAAc,CAAA,IAAI;IAC1D,cAAc,oBAAC,KAAD;KAAG,YAAS;eAAc;IAAe,CAAA,IAAI;IAC3D;GACE;;CAET;CACA,UAAU;EACR,aACE;EACF,YAAY,EAAE,OAAO,EACnB,OAAO,EACJ,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,oCAAoC,EAClD,CAAC;EACD,SAAS,EAAE,OAAO,eAAe;GAC/B,MAAM,QAAQ,SAAS,QAAQ,QAAQ,CAAC,CAAC,MAAM,GAAG,SAAS;GAC3D,MAAM,IAAI,MAAM;GAChB,OACE,oBAAC,OAAD;IACE,YAAS;IACT,MAAM,QAAQ,WAAW;IACzB,wBAAqB;IACrB,cAAY;IACZ,UAAU;cAET,MAAM,KAAK,MAAM,MAChB,oBAAC,OAAD;KAEE,YAAS;KACT,MAAK;KACL,wBAAqB;KACrB,cAAY,GAAG,IAAI,EAAE,MAAM;eAE1B;IACE,GAPE,CAOF,CACN;GACE,CAAA;EAET;CACF;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FormEvent } from "react";
|
|
2
|
+
//#region src/vocabulary/collectFormValues.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The subset of `HTMLInputElement`/`HTMLSelectElement`/`HTMLTextAreaElement` that {@link collectFormValues} reads. A structural type rather than the DOM interfaces themselves, so a plain object can stand in for a form control in tests.
|
|
5
|
+
*/
|
|
6
|
+
type FormControlElementLike = {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly type: string;
|
|
9
|
+
readonly value: string;
|
|
10
|
+
readonly checked?: boolean;
|
|
11
|
+
readonly disabled: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Collects a submitted form's named control values into a plain object, keyed by `name`, in document order. Reads each control's live DOM state rather than `FormData`, so a checkbox resolves to its `checked` boolean instead of an on/off string. A radio group resolves to its checked option's `value`, or `undefined` if none is checked. Any other repeated `name` resolves to an array of its controls' values, in document order. Controls without a `name`, or that are `disabled`, are skipped entirely.
|
|
15
|
+
*/
|
|
16
|
+
declare function collectFormValues(elements: ArrayLike<FormControlElementLike>): Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Convenience wrapper around {@link collectFormValues} for a native form submit event; the cast from `HTMLFormControlsCollection` to `ArrayLike<FormControlElementLike>` lives here once instead of at every call site.
|
|
19
|
+
*/
|
|
20
|
+
declare function collectFormValuesFromEvent(event: FormEvent<HTMLFormElement>): Record<string, unknown>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { FormControlElementLike, collectFormValues, collectFormValuesFromEvent };
|
|
23
|
+
//# sourceMappingURL=collectFormValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectFormValues.d.ts","names":[],"sources":["../../src/vocabulary/collectFormValues.ts"],"mappings":";;;;;KAKY;WACD;WACA;WACA;WACA;WACA;;;;;iBAMK,kBACd,UAAU,UAAU,0BACnB;;;;iBAgCa,2BACd,OAAO,UAAU,mBAChB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/vocabulary/collectFormValues.ts
|
|
2
|
+
/**
|
|
3
|
+
* Collects a submitted form's named control values into a plain object, keyed by `name`, in document order. Reads each control's live DOM state rather than `FormData`, so a checkbox resolves to its `checked` boolean instead of an on/off string. A radio group resolves to its checked option's `value`, or `undefined` if none is checked. Any other repeated `name` resolves to an array of its controls' values, in document order. Controls without a `name`, or that are `disabled`, are skipped entirely.
|
|
4
|
+
*/
|
|
5
|
+
function collectFormValues(elements) {
|
|
6
|
+
const values = Object.create(null);
|
|
7
|
+
for (const element of Array.from(elements)) {
|
|
8
|
+
const { name, disabled } = element;
|
|
9
|
+
if (!name || disabled) continue;
|
|
10
|
+
if (element.type === "radio") {
|
|
11
|
+
if (element.checked) values[name] = element.value;
|
|
12
|
+
else if (!Object.hasOwn(values, name)) values[name] = void 0;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const value = element.type === "checkbox" ? element.checked ?? false : element.value;
|
|
16
|
+
if (Object.hasOwn(values, name)) {
|
|
17
|
+
const existing = values[name];
|
|
18
|
+
values[name] = Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
19
|
+
} else values[name] = value;
|
|
20
|
+
}
|
|
21
|
+
return values;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Convenience wrapper around {@link collectFormValues} for a native form submit event; the cast from `HTMLFormControlsCollection` to `ArrayLike<FormControlElementLike>` lives here once instead of at every call site.
|
|
25
|
+
*/
|
|
26
|
+
function collectFormValuesFromEvent(event) {
|
|
27
|
+
return collectFormValues(event.currentTarget.elements);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { collectFormValues, collectFormValuesFromEvent };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=collectFormValues.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectFormValues.js","names":[],"sources":["../../src/vocabulary/collectFormValues.ts"],"sourcesContent":["import type { FormEvent } from \"react\";\n\n/**\n * The subset of `HTMLInputElement`/`HTMLSelectElement`/`HTMLTextAreaElement` that {@link collectFormValues} reads. A structural type rather than the DOM interfaces themselves, so a plain object can stand in for a form control in tests.\n */\nexport type FormControlElementLike = {\n readonly name: string;\n readonly type: string;\n readonly value: string;\n readonly checked?: boolean;\n readonly disabled: boolean;\n};\n\n/**\n * Collects a submitted form's named control values into a plain object, keyed by `name`, in document order. Reads each control's live DOM state rather than `FormData`, so a checkbox resolves to its `checked` boolean instead of an on/off string. A radio group resolves to its checked option's `value`, or `undefined` if none is checked. Any other repeated `name` resolves to an array of its controls' values, in document order. Controls without a `name`, or that are `disabled`, are skipped entirely.\n */\nexport function collectFormValues(\n elements: ArrayLike<FormControlElementLike>,\n): Record<string, unknown> {\n const values: Record<string, unknown> = Object.create(null);\n\n for (const element of Array.from(elements)) {\n const { name, disabled } = element;\n if (!name || disabled) continue;\n\n if (element.type === \"radio\") {\n if (element.checked) values[name] = element.value;\n else if (!Object.hasOwn(values, name)) values[name] = undefined;\n continue;\n }\n\n const value: string | boolean =\n element.type === \"checkbox\" ? (element.checked ?? false) : element.value;\n\n if (Object.hasOwn(values, name)) {\n const existing = values[name];\n values[name] = Array.isArray(existing)\n ? [...existing, value]\n : [existing, value];\n } else {\n values[name] = value;\n }\n }\n\n return values;\n}\n\n/**\n * Convenience wrapper around {@link collectFormValues} for a native form submit event; the cast from `HTMLFormControlsCollection` to `ArrayLike<FormControlElementLike>` lives here once instead of at every call site.\n */\nexport function collectFormValuesFromEvent(\n event: FormEvent<HTMLFormElement>,\n): Record<string, unknown> {\n return collectFormValues(\n event.currentTarget\n .elements as unknown as ArrayLike<FormControlElementLike>,\n );\n}\n"],"mappings":";;;;AAgBA,SAAgB,kBACd,UACyB;CACzB,MAAM,SAAkC,OAAO,OAAO,IAAI;CAE1D,KAAK,MAAM,WAAW,MAAM,KAAK,QAAQ,GAAG;EAC1C,MAAM,EAAE,MAAM,aAAa;EAC3B,IAAI,CAAC,QAAQ,UAAU;EAEvB,IAAI,QAAQ,SAAS,SAAS;GAC5B,IAAI,QAAQ,SAAS,OAAO,QAAQ,QAAQ;QACvC,IAAI,CAAC,OAAO,OAAO,QAAQ,IAAI,GAAG,OAAO,QAAQ,KAAA;GACtD;EACF;EAEA,MAAM,QACJ,QAAQ,SAAS,aAAc,QAAQ,WAAW,QAAS,QAAQ;EAErE,IAAI,OAAO,OAAO,QAAQ,IAAI,GAAG;GAC/B,MAAM,WAAW,OAAO;GACxB,OAAO,QAAQ,MAAM,QAAQ,QAAQ,IACjC,CAAC,GAAG,UAAU,KAAK,IACnB,CAAC,UAAU,KAAK;EACtB,OACE,OAAO,QAAQ;CAEnB;CAEA,OAAO;AACT;;;;AAKA,SAAgB,2BACd,OACyB;CACzB,OAAO,kBACL,MAAM,cACH,QACL;AACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/vocabulary/data.d.ts
|
|
3
|
+
declare const dataVocabulary: {
|
|
4
|
+
Table: {
|
|
5
|
+
description: string;
|
|
6
|
+
properties: z.ZodObject<{
|
|
7
|
+
columns: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
8
|
+
label: z.ZodString;
|
|
9
|
+
}, z.core.$strip>>>;
|
|
10
|
+
rows: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
render: ({ columns, rows, children }: any) => import("react").JSX.Element;
|
|
13
|
+
};
|
|
14
|
+
Markdown: {
|
|
15
|
+
description: string;
|
|
16
|
+
properties: z.ZodObject<{
|
|
17
|
+
value: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
streamProperties: true;
|
|
20
|
+
render: ({ value, children }: any) => import("react").JSX.Element;
|
|
21
|
+
};
|
|
22
|
+
Chart: {
|
|
23
|
+
description: string;
|
|
24
|
+
properties: z.ZodObject<{
|
|
25
|
+
variant: z.ZodEnum<{
|
|
26
|
+
bar: "bar";
|
|
27
|
+
line: "line";
|
|
28
|
+
sparkline: "sparkline";
|
|
29
|
+
area: "area";
|
|
30
|
+
}>;
|
|
31
|
+
data: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
32
|
+
label: z.ZodOptional<z.ZodString>;
|
|
33
|
+
value: z.ZodNumber;
|
|
34
|
+
}, z.core.$strip>>>;
|
|
35
|
+
series: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
36
|
+
label: z.ZodOptional<z.ZodString>;
|
|
37
|
+
data: z.ZodArray<z.ZodObject<{
|
|
38
|
+
label: z.ZodOptional<z.ZodString>;
|
|
39
|
+
value: z.ZodNumber;
|
|
40
|
+
}, z.core.$strip>>;
|
|
41
|
+
}, z.core.$strip>>>;
|
|
42
|
+
stacked: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
showAxis: z.ZodOptional<z.ZodBoolean>;
|
|
44
|
+
showLegend: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
color: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
render: ({ variant, data, series, stacked, showAxis, showLegend, color }: any) => import("react").JSX.Element;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { dataVocabulary };
|
|
52
|
+
//# sourceMappingURL=data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.d.ts","names":[],"sources":["../../src/vocabulary/data.tsx"],"mappings":";;cA8Qa"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/vocabulary/data.tsx
|
|
4
|
+
const columnSchema = z.object({ label: z.string().describe("Column header label.") });
|
|
5
|
+
const cellSchema = z.union([
|
|
6
|
+
z.string(),
|
|
7
|
+
z.number(),
|
|
8
|
+
z.boolean()
|
|
9
|
+
]).describe("A cell value.");
|
|
10
|
+
const CHART_HEIGHT = 40;
|
|
11
|
+
const CHART_WIDTH = 100;
|
|
12
|
+
const clampValue = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0;
|
|
13
|
+
const yFor = (value, max) => max > 0 ? CHART_HEIGHT - value / max * CHART_HEIGHT : CHART_HEIGHT;
|
|
14
|
+
const pointSchema = z.object({
|
|
15
|
+
label: z.string().optional().describe("Point label."),
|
|
16
|
+
value: z.number().describe("Point value.")
|
|
17
|
+
});
|
|
18
|
+
const seriesSchema = z.object({
|
|
19
|
+
label: z.string().optional().describe("Series label, shown in the legend."),
|
|
20
|
+
data: z.array(pointSchema).describe("Data points for this series.")
|
|
21
|
+
});
|
|
22
|
+
/** Pads every series to the longest series' length, treating a shorter series' missing points as `{ value: 0 }` so mismatched series never misalign or throw. */
|
|
23
|
+
function normalizeSeries(seriesProp, dataProp) {
|
|
24
|
+
const rawSeries = Array.isArray(seriesProp) && seriesProp.length > 0 ? seriesProp : [{ data: Array.isArray(dataProp) ? dataProp : [] }];
|
|
25
|
+
const count = rawSeries.reduce((max, s) => {
|
|
26
|
+
const len = Array.isArray(s?.data) ? s.data.length : 0;
|
|
27
|
+
return Math.max(max, len);
|
|
28
|
+
}, 0);
|
|
29
|
+
return {
|
|
30
|
+
count,
|
|
31
|
+
series: rawSeries.map((s) => {
|
|
32
|
+
const points = Array.isArray(s?.data) ? s.data : [];
|
|
33
|
+
const values = [];
|
|
34
|
+
const labels = [];
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
const point = points[i];
|
|
37
|
+
values.push(clampValue(point?.value));
|
|
38
|
+
labels.push(typeof point?.label === "string" ? point.label : void 0);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
label: typeof s?.label === "string" ? s.label : void 0,
|
|
42
|
+
values,
|
|
43
|
+
labels
|
|
44
|
+
};
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function computeMax(series, count, stacked) {
|
|
49
|
+
if (stacked) {
|
|
50
|
+
let max = 0;
|
|
51
|
+
for (let i = 0; i < count; i++) {
|
|
52
|
+
let sum = 0;
|
|
53
|
+
for (const s of series) sum += s.values[i] ?? 0;
|
|
54
|
+
max = Math.max(max, sum);
|
|
55
|
+
}
|
|
56
|
+
return max;
|
|
57
|
+
}
|
|
58
|
+
let max = 0;
|
|
59
|
+
for (const s of series) for (const v of s.values) max = Math.max(max, v);
|
|
60
|
+
return max;
|
|
61
|
+
}
|
|
62
|
+
const NICE_MULTIPLES = [
|
|
63
|
+
1,
|
|
64
|
+
2,
|
|
65
|
+
5
|
|
66
|
+
];
|
|
67
|
+
/** The smallest of `{1, 2, 5} × 10^n` that is `>= max`, so axis ticks land on round numbers. */
|
|
68
|
+
function niceMax(max) {
|
|
69
|
+
if (max <= 0) return 0;
|
|
70
|
+
const exponent = Math.floor(Math.log10(max));
|
|
71
|
+
for (const multiple of NICE_MULTIPLES) {
|
|
72
|
+
const candidate = multiple * 10 ** exponent;
|
|
73
|
+
if (candidate >= max) return candidate;
|
|
74
|
+
}
|
|
75
|
+
return 10 ** (exponent + 1);
|
|
76
|
+
}
|
|
77
|
+
const TICK_COUNT = 5;
|
|
78
|
+
/** `TICK_COUNT` evenly spaced ticks from `max` down to `0`, for a top-to-bottom y-axis column. */
|
|
79
|
+
function tickValues(max) {
|
|
80
|
+
const ticks = [];
|
|
81
|
+
for (let i = 0; i < TICK_COUNT; i++) ticks.push(max * (TICK_COUNT - 1 - i) / (TICK_COUNT - 1));
|
|
82
|
+
return ticks;
|
|
83
|
+
}
|
|
84
|
+
function formatTick(value) {
|
|
85
|
+
return (Math.round(value * 100) / 100).toLocaleString("en-US");
|
|
86
|
+
}
|
|
87
|
+
const SERIES_PALETTE_SIZE = 5;
|
|
88
|
+
function renderSeriesMarks(variant, series, count, scaleMax, stacked) {
|
|
89
|
+
if (variant === "bar") {
|
|
90
|
+
const slot = count > 0 ? CHART_WIDTH / count : 0;
|
|
91
|
+
const gap = slot * .2;
|
|
92
|
+
const groupWidth = slot - gap;
|
|
93
|
+
const seriesCount = series.length;
|
|
94
|
+
const perSeriesWidth = stacked || seriesCount <= 1 ? groupWidth : groupWidth / seriesCount;
|
|
95
|
+
const cumulative = new Array(count).fill(0);
|
|
96
|
+
return series.map((s, seriesIndex) => {
|
|
97
|
+
const marks = s.values.map((value, i) => {
|
|
98
|
+
const height = scaleMax > 0 ? value / scaleMax * CHART_HEIGHT : 0;
|
|
99
|
+
const belowHeight = stacked && scaleMax > 0 ? (cumulative[i] ?? 0) / scaleMax * CHART_HEIGHT : 0;
|
|
100
|
+
return /* @__PURE__ */ jsx("rect", {
|
|
101
|
+
x: stacked || seriesCount <= 1 ? i * slot + gap / 2 : i * slot + gap / 2 + seriesIndex * perSeriesWidth,
|
|
102
|
+
y: CHART_HEIGHT - belowHeight - height,
|
|
103
|
+
width: perSeriesWidth,
|
|
104
|
+
height,
|
|
105
|
+
fill: "currentColor"
|
|
106
|
+
}, i);
|
|
107
|
+
});
|
|
108
|
+
if (stacked) for (let i = 0; i < count; i++) cumulative[i] = (cumulative[i] ?? 0) + (s.values[i] ?? 0);
|
|
109
|
+
return /* @__PURE__ */ jsx("g", {
|
|
110
|
+
"data-aui": "chart-series",
|
|
111
|
+
"data-aui-series": seriesIndex % SERIES_PALETTE_SIZE,
|
|
112
|
+
children: marks
|
|
113
|
+
}, seriesIndex);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (variant === "area") {
|
|
117
|
+
const cumulative = new Array(count).fill(0);
|
|
118
|
+
return series.map((s, seriesIndex) => {
|
|
119
|
+
const bottoms = stacked ? cumulative.slice() : new Array(count).fill(0);
|
|
120
|
+
if (stacked) for (let i = 0; i < count; i++) cumulative[i] = (cumulative[i] ?? 0) + (s.values[i] ?? 0);
|
|
121
|
+
const tops = stacked ? cumulative.slice() : s.values.slice();
|
|
122
|
+
if (count === 1) {
|
|
123
|
+
const y = yFor(tops[0] ?? 0, scaleMax);
|
|
124
|
+
return /* @__PURE__ */ jsx("g", {
|
|
125
|
+
"data-aui": "chart-series",
|
|
126
|
+
"data-aui-series": seriesIndex % SERIES_PALETTE_SIZE,
|
|
127
|
+
children: /* @__PURE__ */ jsx("circle", {
|
|
128
|
+
cx: CHART_WIDTH / 2,
|
|
129
|
+
cy: y,
|
|
130
|
+
r: 2,
|
|
131
|
+
fill: "currentColor"
|
|
132
|
+
})
|
|
133
|
+
}, seriesIndex);
|
|
134
|
+
}
|
|
135
|
+
if (count === 0) return /* @__PURE__ */ jsx("g", {
|
|
136
|
+
"data-aui": "chart-series",
|
|
137
|
+
"data-aui-series": seriesIndex % SERIES_PALETTE_SIZE
|
|
138
|
+
}, seriesIndex);
|
|
139
|
+
const topPoints = tops.map((v, i) => `${i / (count - 1) * CHART_WIDTH},${yFor(v, scaleMax)}`);
|
|
140
|
+
const bottomPoints = bottoms.map((v, i) => `${i / (count - 1) * CHART_WIDTH},${yFor(v, scaleMax)}`).reverse();
|
|
141
|
+
return /* @__PURE__ */ jsx("g", {
|
|
142
|
+
"data-aui": "chart-series",
|
|
143
|
+
"data-aui-series": seriesIndex % SERIES_PALETTE_SIZE,
|
|
144
|
+
children: /* @__PURE__ */ jsx("polygon", {
|
|
145
|
+
points: [...topPoints, ...bottomPoints].join(" "),
|
|
146
|
+
fill: "currentColor",
|
|
147
|
+
fillOpacity: "0.25",
|
|
148
|
+
stroke: "currentColor"
|
|
149
|
+
})
|
|
150
|
+
}, seriesIndex);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return series.map((s, seriesIndex) => /* @__PURE__ */ jsx("g", {
|
|
154
|
+
"data-aui": "chart-series",
|
|
155
|
+
"data-aui-series": seriesIndex % SERIES_PALETTE_SIZE,
|
|
156
|
+
children: count === 1 ? /* @__PURE__ */ jsx("circle", {
|
|
157
|
+
cx: CHART_WIDTH / 2,
|
|
158
|
+
cy: yFor(s.values[0] ?? 0, scaleMax),
|
|
159
|
+
r: 2,
|
|
160
|
+
fill: "currentColor"
|
|
161
|
+
}) : count > 1 ? /* @__PURE__ */ jsx("polyline", {
|
|
162
|
+
points: s.values.map((v, i) => `${i / (count - 1) * CHART_WIDTH},${yFor(v, scaleMax)}`).join(" "),
|
|
163
|
+
fill: "none",
|
|
164
|
+
stroke: "currentColor"
|
|
165
|
+
}) : null
|
|
166
|
+
}, seriesIndex));
|
|
167
|
+
}
|
|
168
|
+
const dataVocabulary = {
|
|
169
|
+
Table: {
|
|
170
|
+
description: "Tabular data. Provide `columns` and `rows`; each row is an array of cells matching the columns.",
|
|
171
|
+
properties: z.object({
|
|
172
|
+
columns: z.array(columnSchema).optional().describe("Column definitions."),
|
|
173
|
+
rows: z.array(z.array(cellSchema)).optional().describe("Rows of cells.")
|
|
174
|
+
}),
|
|
175
|
+
render: ({ columns, rows, children }) => /* @__PURE__ */ jsxs("table", {
|
|
176
|
+
"data-aui": "table",
|
|
177
|
+
children: [
|
|
178
|
+
columns?.length ? /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((c, i) => /* @__PURE__ */ jsx("th", {
|
|
179
|
+
"data-aui": "table-col",
|
|
180
|
+
children: c.label
|
|
181
|
+
}, i)) }) }) : null,
|
|
182
|
+
rows?.length ? /* @__PURE__ */ jsx("tbody", { children: rows.map((row, r) => /* @__PURE__ */ jsx("tr", { children: row.map((cell, c) => /* @__PURE__ */ jsx("td", { children: String(cell) }, c)) }, r)) }) : null,
|
|
183
|
+
children
|
|
184
|
+
]
|
|
185
|
+
})
|
|
186
|
+
},
|
|
187
|
+
Markdown: {
|
|
188
|
+
description: "A markdown string. Rendered as-is by default; override this component for a full markdown renderer.",
|
|
189
|
+
properties: z.object({ value: z.string().describe("Markdown source.") }),
|
|
190
|
+
streamProperties: true,
|
|
191
|
+
render: ({ value, children }) => /* @__PURE__ */ jsxs("div", {
|
|
192
|
+
"data-aui": "markdown",
|
|
193
|
+
children: [value, children]
|
|
194
|
+
})
|
|
195
|
+
},
|
|
196
|
+
Chart: {
|
|
197
|
+
description: "A chart. `variant` selects bar, line, sparkline, or area rendering. Provide `data` for a single series, or `series` for multiple named series (`series` takes precedence over `data` when both are present). Set `stacked` to accumulate series values instead of overlaying them, and `showAxis`/`showLegend` to add y-axis ticks, x-axis point labels, and a legend.",
|
|
198
|
+
properties: z.object({
|
|
199
|
+
variant: z.enum([
|
|
200
|
+
"bar",
|
|
201
|
+
"line",
|
|
202
|
+
"sparkline",
|
|
203
|
+
"area"
|
|
204
|
+
]).describe("Chart variant."),
|
|
205
|
+
data: z.array(pointSchema).optional().describe("Data points for a single series."),
|
|
206
|
+
series: z.array(seriesSchema).optional().describe("Multiple named series; takes precedence over `data` when present."),
|
|
207
|
+
stacked: z.boolean().optional().describe("Accumulate series values instead of overlaying them (bar and area variants; ignored for line and sparkline)."),
|
|
208
|
+
showAxis: z.boolean().optional().describe("Show y-axis ticks and x-axis point labels."),
|
|
209
|
+
showLegend: z.boolean().optional().describe("Show a legend mapping each series to its color."),
|
|
210
|
+
color: z.string().optional().describe("Series color (single-series mode only). One of `emphasis`, `secondary`, `alpha-70`, `white`, `white-70`, or `white-50`, matching Text's `color` tokens; other values have no visual effect.")
|
|
211
|
+
}),
|
|
212
|
+
render: ({ variant, data, series, stacked, showAxis, showLegend, color }) => {
|
|
213
|
+
if (!(variant === "area" || !!stacked || !!showAxis || !!showLegend || Array.isArray(series) && series.length > 0)) {
|
|
214
|
+
const points = Array.isArray(data) ? data : [];
|
|
215
|
+
const n = points.length;
|
|
216
|
+
const values = points.map((d) => clampValue(d?.value));
|
|
217
|
+
const max = values.reduce((m, v) => Math.max(m, v), 0);
|
|
218
|
+
const slot = n > 0 ? CHART_WIDTH / n : 0;
|
|
219
|
+
const gap = slot * .2;
|
|
220
|
+
const barWidth = slot - gap;
|
|
221
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
222
|
+
"data-aui": "chart",
|
|
223
|
+
"data-aui-variant": variant,
|
|
224
|
+
"data-aui-color": color,
|
|
225
|
+
role: "img",
|
|
226
|
+
"aria-label": `${variant} chart with ${n} data points`,
|
|
227
|
+
viewBox: `0 0 ${CHART_WIDTH} ${CHART_HEIGHT}`,
|
|
228
|
+
preserveAspectRatio: "none",
|
|
229
|
+
children: variant === "bar" ? values.map((v, i) => {
|
|
230
|
+
const height = max > 0 ? v / max * CHART_HEIGHT : 0;
|
|
231
|
+
return /* @__PURE__ */ jsx("rect", {
|
|
232
|
+
x: i * slot + gap / 2,
|
|
233
|
+
y: CHART_HEIGHT - height,
|
|
234
|
+
width: barWidth,
|
|
235
|
+
height,
|
|
236
|
+
fill: "currentColor"
|
|
237
|
+
}, i);
|
|
238
|
+
}) : n === 1 ? /* @__PURE__ */ jsx("circle", {
|
|
239
|
+
cx: CHART_WIDTH / 2,
|
|
240
|
+
cy: yFor(values[0] ?? 0, max),
|
|
241
|
+
r: 2,
|
|
242
|
+
fill: "currentColor"
|
|
243
|
+
}) : n > 1 ? /* @__PURE__ */ jsx("polyline", {
|
|
244
|
+
points: values.map((v, i) => `${i / (n - 1) * CHART_WIDTH},${yFor(v, max)}`).join(" "),
|
|
245
|
+
fill: "none",
|
|
246
|
+
stroke: "currentColor"
|
|
247
|
+
}) : null
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const { count, series: normalized } = normalizeSeries(series, data);
|
|
251
|
+
const stackedScale = !!stacked && (variant === "bar" || variant === "area");
|
|
252
|
+
const rawMax = computeMax(normalized, count, stackedScale);
|
|
253
|
+
const scaleMax = showAxis ? niceMax(rawMax) : rawMax;
|
|
254
|
+
const marks = renderSeriesMarks(variant, normalized, count, scaleMax, stackedScale);
|
|
255
|
+
const svg = /* @__PURE__ */ jsx("svg", {
|
|
256
|
+
"data-aui": "chart",
|
|
257
|
+
"data-aui-variant": variant,
|
|
258
|
+
"data-aui-color": color,
|
|
259
|
+
role: "img",
|
|
260
|
+
"aria-label": `${variant} chart with ${count} data points`,
|
|
261
|
+
viewBox: `0 0 ${CHART_WIDTH} ${CHART_HEIGHT}`,
|
|
262
|
+
preserveAspectRatio: "none",
|
|
263
|
+
children: marks
|
|
264
|
+
});
|
|
265
|
+
if (!showAxis && !showLegend) return svg;
|
|
266
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
267
|
+
"data-aui": "chart-frame",
|
|
268
|
+
children: [
|
|
269
|
+
showAxis ? /* @__PURE__ */ jsx("div", {
|
|
270
|
+
"data-aui": "chart-ticks",
|
|
271
|
+
children: tickValues(scaleMax).map((tick, i) => /* @__PURE__ */ jsx("div", { children: formatTick(tick) }, i))
|
|
272
|
+
}) : null,
|
|
273
|
+
svg,
|
|
274
|
+
showAxis ? /* @__PURE__ */ jsx("div", {
|
|
275
|
+
"data-aui": "chart-xlabels",
|
|
276
|
+
children: (normalized[0]?.labels ?? []).map((label, i) => /* @__PURE__ */ jsx("div", { children: label ?? "" }, i))
|
|
277
|
+
}) : null,
|
|
278
|
+
showLegend ? /* @__PURE__ */ jsx("div", {
|
|
279
|
+
"data-aui": "chart-legend",
|
|
280
|
+
children: normalized.map((s, i) => /* @__PURE__ */ jsxs("span", {
|
|
281
|
+
"data-aui": "chart-legend-item",
|
|
282
|
+
"data-aui-series": i % SERIES_PALETTE_SIZE,
|
|
283
|
+
children: [/* @__PURE__ */ jsx("span", { "data-aui": "chart-legend-swatch" }), s.label ?? `Series ${i + 1}`]
|
|
284
|
+
}, i))
|
|
285
|
+
}) : null
|
|
286
|
+
]
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
//#endregion
|
|
292
|
+
export { dataVocabulary };
|
|
293
|
+
|
|
294
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","names":[],"sources":["../../src/vocabulary/data.tsx"],"sourcesContent":["import { z } from \"zod\";\nimport type { GenerativeUILibrary } from \"../types\";\n\nconst columnSchema = z.object({\n label: z.string().describe(\"Column header label.\"),\n});\n\nconst cellSchema = z\n .union([z.string(), z.number(), z.boolean()])\n .describe(\"A cell value.\");\n\nconst CHART_HEIGHT = 40;\nconst CHART_WIDTH = 100;\n\nconst clampValue = (value: unknown): number =>\n typeof value === \"number\" && Number.isFinite(value) ? Math.max(0, value) : 0;\n\nconst yFor = (value: number, max: number): number =>\n max > 0 ? CHART_HEIGHT - (value / max) * CHART_HEIGHT : CHART_HEIGHT;\n\nconst pointSchema = z.object({\n label: z.string().optional().describe(\"Point label.\"),\n value: z.number().describe(\"Point value.\"),\n});\n\nconst seriesSchema = z.object({\n label: z.string().optional().describe(\"Series label, shown in the legend.\"),\n data: z.array(pointSchema).describe(\"Data points for this series.\"),\n});\n\ntype ChartPoint = { label?: string; value: number };\ntype ChartSeriesInput = { label?: string; data: ChartPoint[] };\ntype NormalizedChartSeries = {\n label: string | undefined;\n values: number[];\n labels: (string | undefined)[];\n};\n\n/** Pads every series to the longest series' length, treating a shorter series' missing points as `{ value: 0 }` so mismatched series never misalign or throw. */\nfunction normalizeSeries(\n seriesProp: unknown,\n dataProp: unknown,\n): { count: number; series: NormalizedChartSeries[] } {\n const rawSeries: ChartSeriesInput[] =\n Array.isArray(seriesProp) && seriesProp.length > 0\n ? (seriesProp as ChartSeriesInput[])\n : [{ data: Array.isArray(dataProp) ? (dataProp as ChartPoint[]) : [] }];\n\n const count = rawSeries.reduce((max, s) => {\n const len = Array.isArray(s?.data) ? s.data.length : 0;\n return Math.max(max, len);\n }, 0);\n\n const series = rawSeries.map((s) => {\n const points = Array.isArray(s?.data) ? s.data : [];\n const values: number[] = [];\n const labels: (string | undefined)[] = [];\n for (let i = 0; i < count; i++) {\n const point = points[i];\n values.push(clampValue(point?.value));\n labels.push(typeof point?.label === \"string\" ? point.label : undefined);\n }\n return {\n label: typeof s?.label === \"string\" ? s.label : undefined,\n values,\n labels,\n };\n });\n\n return { count, series };\n}\n\nfunction computeMax(\n series: NormalizedChartSeries[],\n count: number,\n stacked: boolean,\n): number {\n if (stacked) {\n let max = 0;\n for (let i = 0; i < count; i++) {\n let sum = 0;\n for (const s of series) sum += s.values[i] ?? 0;\n max = Math.max(max, sum);\n }\n return max;\n }\n let max = 0;\n for (const s of series) for (const v of s.values) max = Math.max(max, v);\n return max;\n}\n\nconst NICE_MULTIPLES = [1, 2, 5];\n\n/** The smallest of `{1, 2, 5} × 10^n` that is `>= max`, so axis ticks land on round numbers. */\nfunction niceMax(max: number): number {\n if (max <= 0) return 0;\n const exponent = Math.floor(Math.log10(max));\n for (const multiple of NICE_MULTIPLES) {\n const candidate = multiple * 10 ** exponent;\n if (candidate >= max) return candidate;\n }\n return 10 ** (exponent + 1);\n}\n\nconst TICK_COUNT = 5;\n\n/** `TICK_COUNT` evenly spaced ticks from `max` down to `0`, for a top-to-bottom y-axis column. */\nfunction tickValues(max: number): number[] {\n const ticks: number[] = [];\n for (let i = 0; i < TICK_COUNT; i++) {\n ticks.push((max * (TICK_COUNT - 1 - i)) / (TICK_COUNT - 1));\n }\n return ticks;\n}\n\nfunction formatTick(value: number): string {\n return (Math.round(value * 100) / 100).toLocaleString(\"en-US\");\n}\n\ntype ChartVariant = \"bar\" | \"line\" | \"sparkline\" | \"area\";\n\nconst SERIES_PALETTE_SIZE = 5;\n\nfunction renderSeriesMarks(\n variant: ChartVariant,\n series: NormalizedChartSeries[],\n count: number,\n scaleMax: number,\n stacked: boolean,\n) {\n if (variant === \"bar\") {\n const slot = count > 0 ? CHART_WIDTH / count : 0;\n const gap = slot * 0.2;\n const groupWidth = slot - gap;\n const seriesCount = series.length;\n const perSeriesWidth =\n stacked || seriesCount <= 1 ? groupWidth : groupWidth / seriesCount;\n const cumulative = new Array(count).fill(0) as number[];\n\n return series.map((s, seriesIndex) => {\n const marks = s.values.map((value, i) => {\n const height = scaleMax > 0 ? (value / scaleMax) * CHART_HEIGHT : 0;\n const belowHeight =\n stacked && scaleMax > 0\n ? ((cumulative[i] ?? 0) / scaleMax) * CHART_HEIGHT\n : 0;\n const x =\n stacked || seriesCount <= 1\n ? i * slot + gap / 2\n : i * slot + gap / 2 + seriesIndex * perSeriesWidth;\n return (\n <rect\n key={i}\n x={x}\n y={CHART_HEIGHT - belowHeight - height}\n width={perSeriesWidth}\n height={height}\n fill=\"currentColor\"\n />\n );\n });\n if (stacked) {\n for (let i = 0; i < count; i++) {\n cumulative[i] = (cumulative[i] ?? 0) + (s.values[i] ?? 0);\n }\n }\n return (\n <g\n key={seriesIndex}\n data-aui=\"chart-series\"\n data-aui-series={seriesIndex % SERIES_PALETTE_SIZE}\n >\n {marks}\n </g>\n );\n });\n }\n\n if (variant === \"area\") {\n const cumulative = new Array(count).fill(0) as number[];\n\n return series.map((s, seriesIndex) => {\n const bottoms = stacked\n ? cumulative.slice()\n : (new Array(count).fill(0) as number[]);\n if (stacked) {\n for (let i = 0; i < count; i++) {\n cumulative[i] = (cumulative[i] ?? 0) + (s.values[i] ?? 0);\n }\n }\n const tops = stacked ? cumulative.slice() : s.values.slice();\n\n if (count === 1) {\n const y = yFor(tops[0] ?? 0, scaleMax);\n return (\n <g\n key={seriesIndex}\n data-aui=\"chart-series\"\n data-aui-series={seriesIndex % SERIES_PALETTE_SIZE}\n >\n <circle cx={CHART_WIDTH / 2} cy={y} r={2} fill=\"currentColor\" />\n </g>\n );\n }\n if (count === 0) {\n return (\n <g\n key={seriesIndex}\n data-aui=\"chart-series\"\n data-aui-series={seriesIndex % SERIES_PALETTE_SIZE}\n />\n );\n }\n\n const topPoints = tops.map(\n (v, i) => `${(i / (count - 1)) * CHART_WIDTH},${yFor(v, scaleMax)}`,\n );\n const bottomPoints = bottoms\n .map(\n (v, i) => `${(i / (count - 1)) * CHART_WIDTH},${yFor(v, scaleMax)}`,\n )\n .reverse();\n\n return (\n <g\n key={seriesIndex}\n data-aui=\"chart-series\"\n data-aui-series={seriesIndex % SERIES_PALETTE_SIZE}\n >\n <polygon\n points={[...topPoints, ...bottomPoints].join(\" \")}\n fill=\"currentColor\"\n fillOpacity=\"0.25\"\n stroke=\"currentColor\"\n />\n </g>\n );\n });\n }\n\n // line / sparkline: each series is always drawn independently. Stacking a line has no single standard meaning, so `stacked` is ignored (the caller never passes it for these variants).\n return series.map((s, seriesIndex) => (\n <g\n key={seriesIndex}\n data-aui=\"chart-series\"\n data-aui-series={seriesIndex % SERIES_PALETTE_SIZE}\n >\n {count === 1 ? (\n <circle\n cx={CHART_WIDTH / 2}\n cy={yFor(s.values[0] ?? 0, scaleMax)}\n r={2}\n fill=\"currentColor\"\n />\n ) : count > 1 ? (\n <polyline\n points={s.values\n .map(\n (v, i) =>\n `${(i / (count - 1)) * CHART_WIDTH},${yFor(v, scaleMax)}`,\n )\n .join(\" \")}\n fill=\"none\"\n stroke=\"currentColor\"\n />\n ) : null}\n </g>\n ));\n}\n\nexport const dataVocabulary = {\n Table: {\n description:\n \"Tabular data. Provide `columns` and `rows`; each row is an array of cells matching the columns.\",\n properties: z.object({\n columns: z.array(columnSchema).optional().describe(\"Column definitions.\"),\n rows: z.array(z.array(cellSchema)).optional().describe(\"Rows of cells.\"),\n }),\n render: ({ columns, rows, children }) => (\n <table data-aui=\"table\">\n {columns?.length ? (\n <thead>\n <tr>\n {columns.map((c: { label: string }, i: number) => (\n <th key={i} data-aui=\"table-col\">\n {c.label}\n </th>\n ))}\n </tr>\n </thead>\n ) : null}\n {rows?.length ? (\n <tbody>\n {rows.map((row: (string | number | boolean)[], r: number) => (\n <tr key={r}>\n {row.map((cell: string | number | boolean, c: number) => (\n <td key={c}>{String(cell)}</td>\n ))}\n </tr>\n ))}\n </tbody>\n ) : null}\n {children}\n </table>\n ),\n },\n Markdown: {\n description:\n \"A markdown string. Rendered as-is by default; override this component for a full markdown renderer.\",\n properties: z.object({\n value: z.string().describe(\"Markdown source.\"),\n }),\n streamProperties: true,\n render: ({ value, children }) => (\n <div data-aui=\"markdown\">\n {value}\n {children}\n </div>\n ),\n },\n Chart: {\n description:\n \"A chart. `variant` selects bar, line, sparkline, or area rendering. Provide `data` for a single series, or `series` for multiple named series (`series` takes precedence over `data` when both are present). Set `stacked` to accumulate series values instead of overlaying them, and `showAxis`/`showLegend` to add y-axis ticks, x-axis point labels, and a legend.\",\n properties: z.object({\n variant: z\n .enum([\"bar\", \"line\", \"sparkline\", \"area\"])\n .describe(\"Chart variant.\"),\n data: z\n .array(pointSchema)\n .optional()\n .describe(\"Data points for a single series.\"),\n series: z\n .array(seriesSchema)\n .optional()\n .describe(\n \"Multiple named series; takes precedence over `data` when present.\",\n ),\n stacked: z\n .boolean()\n .optional()\n .describe(\n \"Accumulate series values instead of overlaying them (bar and area variants; ignored for line and sparkline).\",\n ),\n showAxis: z\n .boolean()\n .optional()\n .describe(\"Show y-axis ticks and x-axis point labels.\"),\n showLegend: z\n .boolean()\n .optional()\n .describe(\"Show a legend mapping each series to its color.\"),\n color: z\n .string()\n .optional()\n .describe(\n \"Series color (single-series mode only). One of `emphasis`, `secondary`, `alpha-70`, `white`, `white-70`, or `white-50`, matching Text's `color` tokens; other values have no visual effect.\",\n ),\n }),\n render: ({\n variant,\n data,\n series,\n stacked,\n showAxis,\n showLegend,\n color,\n }) => {\n const usesExtendedFeatures =\n variant === \"area\" ||\n !!stacked ||\n !!showAxis ||\n !!showLegend ||\n (Array.isArray(series) && series.length > 0);\n\n if (!usesExtendedFeatures) {\n const points = Array.isArray(data) ? data : [];\n const n = points.length;\n const values = points.map((d) => clampValue(d?.value));\n const max = values.reduce((m, v) => Math.max(m, v), 0);\n const slot = n > 0 ? CHART_WIDTH / n : 0;\n const gap = slot * 0.2;\n const barWidth = slot - gap;\n\n return (\n <svg\n data-aui=\"chart\"\n data-aui-variant={variant}\n data-aui-color={color}\n role=\"img\"\n aria-label={`${variant} chart with ${n} data points`}\n viewBox={`0 0 ${CHART_WIDTH} ${CHART_HEIGHT}`}\n preserveAspectRatio=\"none\"\n >\n {variant === \"bar\" ? (\n values.map((v, i) => {\n const height = max > 0 ? (v / max) * CHART_HEIGHT : 0;\n return (\n <rect\n key={i}\n x={i * slot + gap / 2}\n y={CHART_HEIGHT - height}\n width={barWidth}\n height={height}\n fill=\"currentColor\"\n />\n );\n })\n ) : n === 1 ? (\n <circle\n cx={CHART_WIDTH / 2}\n cy={yFor(values[0] ?? 0, max)}\n r={2}\n fill=\"currentColor\"\n />\n ) : n > 1 ? (\n <polyline\n points={values\n .map(\n (v, i) => `${(i / (n - 1)) * CHART_WIDTH},${yFor(v, max)}`,\n )\n .join(\" \")}\n fill=\"none\"\n stroke=\"currentColor\"\n />\n ) : null}\n </svg>\n );\n }\n\n const { count, series: normalized } = normalizeSeries(series, data);\n const stackedScale =\n !!stacked && (variant === \"bar\" || variant === \"area\");\n const rawMax = computeMax(normalized, count, stackedScale);\n const scaleMax = showAxis ? niceMax(rawMax) : rawMax;\n const marks = renderSeriesMarks(\n variant,\n normalized,\n count,\n scaleMax,\n stackedScale,\n );\n\n const svg = (\n <svg\n data-aui=\"chart\"\n data-aui-variant={variant}\n data-aui-color={color}\n role=\"img\"\n aria-label={`${variant} chart with ${count} data points`}\n viewBox={`0 0 ${CHART_WIDTH} ${CHART_HEIGHT}`}\n preserveAspectRatio=\"none\"\n >\n {marks}\n </svg>\n );\n\n if (!showAxis && !showLegend) return svg;\n\n return (\n <div data-aui=\"chart-frame\">\n {showAxis ? (\n <div data-aui=\"chart-ticks\">\n {tickValues(scaleMax).map((tick, i) => (\n <div key={i}>{formatTick(tick)}</div>\n ))}\n </div>\n ) : null}\n {svg}\n {showAxis ? (\n <div data-aui=\"chart-xlabels\">\n {(normalized[0]?.labels ?? []).map((label, i) => (\n <div key={i}>{label ?? \"\"}</div>\n ))}\n </div>\n ) : null}\n {showLegend ? (\n <div data-aui=\"chart-legend\">\n {normalized.map((s, i) => (\n <span\n key={i}\n data-aui=\"chart-legend-item\"\n data-aui-series={i % SERIES_PALETTE_SIZE}\n >\n <span data-aui=\"chart-legend-swatch\" />\n {s.label ?? `Series ${i + 1}`}\n </span>\n ))}\n </div>\n ) : null}\n </div>\n );\n },\n },\n} satisfies GenerativeUILibrary;\n"],"mappings":";;;AAGA,MAAM,eAAe,EAAE,OAAO,EAC5B,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,sBAAs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U,IAAI,GACtB;SANC,CAMD,CACP;KACE,CAAA,IACH;IACD;;EAET;CACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action } from "../ir.js";
|
|
2
|
+
import { GenerativeUIDispatch } from "../types.js";
|
|
3
|
+
//#region src/vocabulary/dispatch.d.ts
|
|
4
|
+
declare const actionAttr: (a: Action | undefined) => string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Fires `$action` through `$dispatch` when both are present, merging a runtime value into the payload under the reserved `$input` key (not `value`) so the user's input never clobbers a model-supplied `value` field. No-op when no registry is wired. The returned promise from an async handler is caught and re-thrown on a microtask so rejections surface rather than going unhandled.
|
|
7
|
+
*/
|
|
8
|
+
declare const fire: ($action: Action | undefined, $dispatch: GenerativeUIDispatch | undefined, input?: unknown) => void;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { actionAttr, fire };
|
|
11
|
+
//# sourceMappingURL=dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.d.ts","names":[],"sources":["../../src/vocabulary/dispatch.ts"],"mappings":";;;cAGa,aAAc,GAAG;;;;cAMjB,OACX,SAAS,oBACT,WAAW,kCACX"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/vocabulary/dispatch.ts
|
|
2
|
+
const actionAttr = (a) => a ? JSON.stringify(a) : void 0;
|
|
3
|
+
/**
|
|
4
|
+
* Fires `$action` through `$dispatch` when both are present, merging a runtime value into the payload under the reserved `$input` key (not `value`) so the user's input never clobbers a model-supplied `value` field. No-op when no registry is wired. The returned promise from an async handler is caught and re-thrown on a microtask so rejections surface rather than going unhandled.
|
|
5
|
+
*/
|
|
6
|
+
const fire = ($action, $dispatch, input) => {
|
|
7
|
+
if (!$action || !$dispatch) return;
|
|
8
|
+
const payload = input === void 0 ? $action : {
|
|
9
|
+
...$action,
|
|
10
|
+
$input: input
|
|
11
|
+
};
|
|
12
|
+
Promise.resolve($dispatch(payload)).catch((error) => {
|
|
13
|
+
queueMicrotask(() => {
|
|
14
|
+
throw error;
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { actionAttr, fire };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","names":[],"sources":["../../src/vocabulary/dispatch.ts"],"sourcesContent":["import type { Action } from \"../ir\";\nimport type { GenerativeUIDispatch } from \"../types\";\n\nexport const actionAttr = (a: Action | undefined): string | undefined =>\n a ? JSON.stringify(a) : undefined;\n\n/**\n * Fires `$action` through `$dispatch` when both are present, merging a runtime value into the payload under the reserved `$input` key (not `value`) so the user's input never clobbers a model-supplied `value` field. No-op when no registry is wired. The returned promise from an async handler is caught and re-thrown on a microtask so rejections surface rather than going unhandled.\n */\nexport const fire = (\n $action: Action | undefined,\n $dispatch: GenerativeUIDispatch | undefined,\n input?: unknown,\n) => {\n if (!$action || !$dispatch) return;\n const payload = input === undefined ? $action : { ...$action, $input: input };\n void Promise.resolve($dispatch(payload)).catch((error) => {\n queueMicrotask(() => {\n throw error;\n });\n });\n};\n"],"mappings":";AAGA,MAAa,cAAc,MACzB,IAAI,KAAK,UAAU,CAAC,IAAI,KAAA;;;;AAK1B,MAAa,QACX,SACA,WACA,UACG;CACH,IAAI,CAAC,WAAW,CAAC,WAAW;CAC5B,MAAM,UAAU,UAAU,KAAA,IAAY,UAAU;EAAE,GAAG;EAAS,QAAQ;CAAM;CAC5E,QAAa,QAAQ,UAAU,OAAO,CAAC,CAAC,CAAC,OAAO,UAAU;EACxD,qBAAqB;GACnB,MAAM;EACR,CAAC;CACH,CAAC;AACH"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/vocabulary/fact.d.ts
|
|
3
|
+
declare const factVocabulary: {
|
|
4
|
+
Fact: {
|
|
5
|
+
description: string;
|
|
6
|
+
properties: z.ZodObject<{
|
|
7
|
+
label: z.ZodString;
|
|
8
|
+
value: z.ZodString;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
render: ({ label, value, children }: any) => import("react").JSX.Element;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { factVocabulary };
|
|
15
|
+
//# sourceMappingURL=fact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fact.d.ts","names":[],"sources":["../../src/vocabulary/fact.tsx"],"mappings":";;cAGa"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/vocabulary/fact.tsx
|
|
4
|
+
const factVocabulary = { Fact: {
|
|
5
|
+
description: "A label/value pair, rendered as a key followed by its value. Use for compact metadata.",
|
|
6
|
+
properties: z.object({
|
|
7
|
+
label: z.string().describe("The fact label (key)."),
|
|
8
|
+
value: z.string().describe("The fact value.")
|
|
9
|
+
}),
|
|
10
|
+
render: ({ label, value, children }) => /* @__PURE__ */ jsxs("dl", {
|
|
11
|
+
"data-aui": "fact",
|
|
12
|
+
children: [/* @__PURE__ */ jsx("dt", {
|
|
13
|
+
"data-aui": "fact-label",
|
|
14
|
+
children: label
|
|
15
|
+
}), /* @__PURE__ */ jsxs("dd", {
|
|
16
|
+
"data-aui": "fact-value",
|
|
17
|
+
children: [value, children]
|
|
18
|
+
})]
|
|
19
|
+
})
|
|
20
|
+
} };
|
|
21
|
+
//#endregion
|
|
22
|
+
export { factVocabulary };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=fact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fact.js","names":[],"sources":["../../src/vocabulary/fact.tsx"],"sourcesContent":["import { z } from \"zod\";\nimport type { GenerativeUILibrary } from \"../types\";\n\nexport const factVocabulary = {\n Fact: {\n description:\n \"A label/value pair, rendered as a key followed by its value. Use for compact metadata.\",\n properties: z.object({\n label: z.string().describe(\"The fact label (key).\"),\n value: z.string().describe(\"The fact value.\"),\n }),\n render: ({ label, value, children }) => (\n <dl data-aui=\"fact\">\n <dt data-aui=\"fact-label\">{label}</dt>\n <dd data-aui=\"fact-value\">\n {value}\n {children}\n </dd>\n </dl>\n ),\n },\n} satisfies GenerativeUILibrary;\n"],"mappings":";;;AAGA,MAAa,iBAAiB,EAC5B,MAAM;CACJ,aACE;CACF,YAAY,EAAE,OAAO;EACnB,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,uBAAuB;EAClD,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,iBAAiB;CAC9C,CAAC;CACD,SAAS,EAAE,OAAO,OAAO,eACvB,qBAAC,MAAD;EAAI,YAAS;YAAb,CACE,oBAAC,MAAD;GAAI,YAAS;aAAc;EAAU,CAAA,GACrC,qBAAC,MAAD;GAAI,YAAS;aAAb,CACG,OACA,QACC;IACF;;AAER,EACF"}
|