@assistant-ui/react-generative-ui 0.0.23 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/a2ui.d.ts +1 -4
- package/dist/a2ui.d.ts.map +1 -1
- package/dist/a2ui.js +1 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.server.d.ts +1 -2
- package/dist/index.server.d.ts.map +1 -1
- package/dist/index.server.js +1 -10
- package/dist/ir.d.ts +1 -111
- package/dist/ir.d.ts.map +1 -1
- package/dist/ir.js +1 -175
- package/dist/slack.d.ts +1 -4
- package/dist/slack.d.ts.map +1 -1
- package/dist/slack.js +1 -4
- package/dist/teams.d.ts +1 -4
- package/dist/teams.d.ts.map +1 -1
- package/dist/teams.js +1 -4
- package/package.json +5 -5
- package/src/a2ui.ts +1 -22
- package/src/index.server.ts +1 -2
- package/src/index.test.ts +75 -0
- package/src/index.ts +1 -2
- package/src/ir.ts +1 -279
- package/src/slack.ts +1 -39
- package/src/teams.ts +1 -35
- package/dist/JSONGenerativeUI.client.d.ts +0 -28
- package/dist/JSONGenerativeUI.client.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.client.js +0 -101
- package/dist/JSONGenerativeUI.client.js.map +0 -1
- package/dist/JSONGenerativeUI.server.d.ts +0 -21
- package/dist/JSONGenerativeUI.server.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.server.js +0 -32
- package/dist/JSONGenerativeUI.server.js.map +0 -1
- package/dist/JSONGenerativeUI.shared.d.ts +0 -63
- package/dist/JSONGenerativeUI.shared.d.ts.map +0 -1
- package/dist/JSONGenerativeUI.shared.js +0 -31
- package/dist/JSONGenerativeUI.shared.js.map +0 -1
- package/dist/RadioGroupScope.d.ts +0 -6
- package/dist/RadioGroupScope.d.ts.map +0 -1
- package/dist/RadioGroupScope.js +0 -25
- package/dist/RadioGroupScope.js.map +0 -1
- package/dist/a2ui/BindingContext.d.ts +0 -11
- package/dist/a2ui/BindingContext.d.ts.map +0 -1
- package/dist/a2ui/BindingContext.js +0 -12
- package/dist/a2ui/BindingContext.js.map +0 -1
- package/dist/a2ui/PresentRenderer.d.ts +0 -11
- package/dist/a2ui/PresentRenderer.d.ts.map +0 -1
- package/dist/a2ui/PresentRenderer.js +0 -39
- package/dist/a2ui/PresentRenderer.js.map +0 -1
- package/dist/a2ui/convert.d.ts +0 -15
- package/dist/a2ui/convert.d.ts.map +0 -1
- package/dist/a2ui/convert.js +0 -728
- package/dist/a2ui/convert.js.map +0 -1
- package/dist/a2ui/dataModel.d.ts +0 -9
- package/dist/a2ui/dataModel.d.ts.map +0 -1
- package/dist/a2ui/dataModel.js +0 -44
- package/dist/a2ui/dataModel.js.map +0 -1
- package/dist/a2ui/reducer.d.ts +0 -8
- package/dist/a2ui/reducer.d.ts.map +0 -1
- package/dist/a2ui/reducer.js +0 -242
- package/dist/a2ui/reducer.js.map +0 -1
- package/dist/a2ui/snapshot.d.ts +0 -3
- package/dist/a2ui/snapshot.d.ts.map +0 -1
- package/dist/a2ui/snapshot.js +0 -33
- package/dist/a2ui/snapshot.js.map +0 -1
- package/dist/a2ui/types.d.ts +0 -88
- package/dist/a2ui/types.d.ts.map +0 -1
- package/dist/a2ui/types.js +0 -6
- package/dist/a2ui/types.js.map +0 -1
- package/dist/a2ui/valueFunctions.d.ts +0 -16
- package/dist/a2ui/valueFunctions.d.ts.map +0 -1
- package/dist/a2ui/valueFunctions.js +0 -332
- package/dist/a2ui/valueFunctions.js.map +0 -1
- package/dist/actionRegistry.d.ts +0 -29
- package/dist/actionRegistry.d.ts.map +0 -1
- package/dist/actionRegistry.js +0 -41
- package/dist/actionRegistry.js.map +0 -1
- package/dist/answeredValues.d.ts +0 -16
- package/dist/answeredValues.d.ts.map +0 -1
- package/dist/answeredValues.js +0 -37
- package/dist/answeredValues.js.map +0 -1
- package/dist/buildPresentParameters.d.ts +0 -21
- package/dist/buildPresentParameters.d.ts.map +0 -1
- package/dist/buildPresentParameters.js +0 -95
- package/dist/buildPresentParameters.js.map +0 -1
- package/dist/constants.d.ts +0 -15
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -19
- package/dist/constants.js.map +0 -1
- package/dist/convert/boundSpec.d.ts +0 -48
- package/dist/convert/boundSpec.d.ts.map +0 -1
- package/dist/convert/boundSpec.js +0 -108
- package/dist/convert/boundSpec.js.map +0 -1
- package/dist/convert/copyBounded.d.ts +0 -25
- package/dist/convert/copyBounded.d.ts.map +0 -1
- package/dist/convert/copyBounded.js +0 -38
- package/dist/convert/copyBounded.js.map +0 -1
- package/dist/convert/isElement.d.ts +0 -3
- package/dist/convert/isElement.d.ts.map +0 -1
- package/dist/convert/isElement.js +0 -6
- package/dist/convert/isElement.js.map +0 -1
- package/dist/convert/takeRun.d.ts +0 -6
- package/dist/convert/takeRun.d.ts.map +0 -1
- package/dist/convert/takeRun.js +0 -20
- package/dist/convert/takeRun.js.map +0 -1
- package/dist/defineGenerativeComponents.d.ts +0 -29
- package/dist/defineGenerativeComponents.d.ts.map +0 -1
- package/dist/defineGenerativeComponents.js +0 -34
- package/dist/defineGenerativeComponents.js.map +0 -1
- package/dist/fieldReferences.d.ts +0 -9
- package/dist/fieldReferences.d.ts.map +0 -1
- package/dist/fieldReferences.js +0 -53
- package/dist/fieldReferences.js.map +0 -1
- package/dist/generativeUIToJSX.d.ts +0 -18
- package/dist/generativeUIToJSX.d.ts.map +0 -1
- package/dist/generativeUIToJSX.js +0 -76
- package/dist/generativeUIToJSX.js.map +0 -1
- package/dist/index.shared.d.ts +0 -15
- package/dist/index.shared.d.ts.map +0 -1
- package/dist/index.shared.js +0 -9
- package/dist/ir.js.map +0 -1
- package/dist/renderGenerativeUI.d.ts +0 -14
- package/dist/renderGenerativeUI.d.ts.map +0 -1
- package/dist/renderGenerativeUI.js +0 -83
- package/dist/renderGenerativeUI.js.map +0 -1
- package/dist/scopeSchema.d.ts +0 -6
- package/dist/scopeSchema.d.ts.map +0 -1
- package/dist/scopeSchema.js +0 -56
- package/dist/scopeSchema.js.map +0 -1
- package/dist/slack/constants.d.ts +0 -93
- package/dist/slack/constants.d.ts.map +0 -1
- package/dist/slack/constants.js +0 -146
- package/dist/slack/constants.js.map +0 -1
- package/dist/slack/decodeBlockAction.d.ts +0 -10
- package/dist/slack/decodeBlockAction.d.ts.map +0 -1
- package/dist/slack/decodeBlockAction.js +0 -129
- package/dist/slack/decodeBlockAction.js.map +0 -1
- package/dist/slack/fromSlackBlocks.d.ts +0 -27
- package/dist/slack/fromSlackBlocks.d.ts.map +0 -1
- package/dist/slack/fromSlackBlocks.js +0 -483
- package/dist/slack/fromSlackBlocks.js.map +0 -1
- package/dist/slack/toSlackBlocks.d.ts +0 -4
- package/dist/slack/toSlackBlocks.d.ts.map +0 -1
- package/dist/slack/toSlackBlocks.js +0 -901
- package/dist/slack/toSlackBlocks.js.map +0 -1
- package/dist/slack/types.d.ts +0 -204
- package/dist/slack/types.d.ts.map +0 -1
- package/dist/slack/types.js +0 -0
- package/dist/teams/constants.d.ts +0 -34
- package/dist/teams/constants.d.ts.map +0 -1
- package/dist/teams/constants.js +0 -68
- package/dist/teams/constants.js.map +0 -1
- package/dist/teams/decodeSubmitData.d.ts +0 -26
- package/dist/teams/decodeSubmitData.d.ts.map +0 -1
- package/dist/teams/decodeSubmitData.js +0 -70
- package/dist/teams/decodeSubmitData.js.map +0 -1
- package/dist/teams/temporalId.d.ts +0 -5
- package/dist/teams/temporalId.d.ts.map +0 -1
- package/dist/teams/temporalId.js +0 -28
- package/dist/teams/temporalId.js.map +0 -1
- package/dist/teams/toAdaptiveCard.d.ts +0 -45
- package/dist/teams/toAdaptiveCard.d.ts.map +0 -1
- package/dist/teams/toAdaptiveCard.js +0 -642
- package/dist/teams/toAdaptiveCard.js.map +0 -1
- package/dist/teams/toTeamsAttachments.d.ts +0 -10
- package/dist/teams/toTeamsAttachments.d.ts.map +0 -1
- package/dist/teams/toTeamsAttachments.js +0 -99
- package/dist/teams/toTeamsAttachments.js.map +0 -1
- package/dist/teams/types.d.ts +0 -224
- package/dist/teams/types.d.ts.map +0 -1
- package/dist/teams/types.js +0 -0
- package/dist/temporal.d.ts +0 -33
- package/dist/temporal.d.ts.map +0 -1
- package/dist/temporal.js +0 -152
- package/dist/temporal.js.map +0 -1
- package/dist/types.d.ts +0 -99
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -0
- package/dist/vocabulary/alert.d.ts +0 -32
- package/dist/vocabulary/alert.d.ts.map +0 -1
- package/dist/vocabulary/alert.js +0 -160
- package/dist/vocabulary/alert.js.map +0 -1
- package/dist/vocabulary/collectFormValues.d.ts +0 -23
- package/dist/vocabulary/collectFormValues.d.ts.map +0 -1
- package/dist/vocabulary/collectFormValues.js +0 -44
- package/dist/vocabulary/collectFormValues.js.map +0 -1
- package/dist/vocabulary/data.d.ts +0 -66
- package/dist/vocabulary/data.d.ts.map +0 -1
- package/dist/vocabulary/data.js +0 -503
- package/dist/vocabulary/data.js.map +0 -1
- package/dist/vocabulary/dispatch.d.ts +0 -9
- package/dist/vocabulary/dispatch.d.ts.map +0 -1
- package/dist/vocabulary/dispatch.js +0 -50
- package/dist/vocabulary/dispatch.js.map +0 -1
- package/dist/vocabulary/fact.d.ts +0 -19
- package/dist/vocabulary/fact.d.ts.map +0 -1
- package/dist/vocabulary/fact.js +0 -51
- package/dist/vocabulary/fact.js.map +0 -1
- package/dist/vocabulary/form.d.ts +0 -11
- package/dist/vocabulary/form.d.ts.map +0 -1
- package/dist/vocabulary/form.js +0 -23
- package/dist/vocabulary/form.js.map +0 -1
- package/dist/vocabulary/formatValue.d.ts +0 -7
- package/dist/vocabulary/formatValue.d.ts.map +0 -1
- package/dist/vocabulary/formatValue.js +0 -76
- package/dist/vocabulary/formatValue.js.map +0 -1
- package/dist/vocabulary/icon.d.ts +0 -41
- package/dist/vocabulary/icon.d.ts.map +0 -1
- package/dist/vocabulary/icon.js +0 -272
- package/dist/vocabulary/icon.js.map +0 -1
- package/dist/vocabulary/index.d.ts +0 -12
- package/dist/vocabulary/index.d.ts.map +0 -1
- package/dist/vocabulary/index.js +0 -36
- package/dist/vocabulary/index.js.map +0 -1
- package/dist/vocabulary/interactive.d.ts +0 -230
- package/dist/vocabulary/interactive.d.ts.map +0 -1
- package/dist/vocabulary/interactive.js +0 -530
- package/dist/vocabulary/interactive.js.map +0 -1
- package/dist/vocabulary/layout.d.ts +0 -79
- package/dist/vocabulary/layout.d.ts.map +0 -1
- package/dist/vocabulary/layout.js +0 -139
- package/dist/vocabulary/layout.js.map +0 -1
- package/dist/vocabulary/list.d.ts +0 -14
- package/dist/vocabulary/list.d.ts.map +0 -1
- package/dist/vocabulary/list.js +0 -50
- package/dist/vocabulary/list.js.map +0 -1
- package/dist/vocabulary/media.d.ts +0 -25
- package/dist/vocabulary/media.d.ts.map +0 -1
- package/dist/vocabulary/media.js +0 -42
- package/dist/vocabulary/media.js.map +0 -1
- package/dist/vocabulary/text.d.ts +0 -57
- package/dist/vocabulary/text.d.ts.map +0 -1
- package/dist/vocabulary/text.js +0 -49
- package/dist/vocabulary/text.js.map +0 -1
- package/dist/vocabulary/toTextContent.d.ts +0 -2
- package/dist/vocabulary/toTextContent.d.ts.map +0 -1
- package/dist/vocabulary/toTextContent.js +0 -6
- package/dist/vocabulary/toTextContent.js.map +0 -1
- package/src/JSONGenerativeUI.client.tsx +0 -168
- package/src/JSONGenerativeUI.server.tsx +0 -39
- package/src/JSONGenerativeUI.shared.ts +0 -90
- package/src/JSONGenerativeUI.test.tsx +0 -1298
- package/src/RadioGroupScope.server.test.tsx +0 -24
- package/src/RadioGroupScope.tsx +0 -34
- package/src/a2ui/BindingContext.ts +0 -26
- package/src/a2ui/PresentRenderer.tsx +0 -83
- package/src/a2ui/convert.test.ts +0 -2923
- package/src/a2ui/convert.ts +0 -1207
- package/src/a2ui/dataModel.ts +0 -69
- package/src/a2ui/reducer.test.ts +0 -422
- package/src/a2ui/reducer.ts +0 -363
- package/src/a2ui/snapshot.test.ts +0 -52
- package/src/a2ui/snapshot.ts +0 -52
- package/src/a2ui/types.ts +0 -114
- package/src/a2ui/valueFunctions.test.ts +0 -271
- package/src/a2ui/valueFunctions.ts +0 -523
- package/src/actionRegistry.test.ts +0 -90
- package/src/actionRegistry.ts +0 -88
- package/src/answeredValues.test.ts +0 -33
- package/src/answeredValues.tsx +0 -70
- package/src/buildPresentParameters.test.ts +0 -246
- package/src/buildPresentParameters.ts +0 -130
- package/src/constants.ts +0 -17
- package/src/convert/boundSpec.test.ts +0 -192
- package/src/convert/boundSpec.ts +0 -134
- package/src/convert/copyBounded.test.ts +0 -131
- package/src/convert/copyBounded.ts +0 -38
- package/src/convert/isElement.ts +0 -6
- package/src/convert/takeRun.test.ts +0 -64
- package/src/convert/takeRun.ts +0 -19
- package/src/defineGenerativeComponents.ts +0 -38
- package/src/fieldReferences.test.ts +0 -66
- package/src/fieldReferences.ts +0 -83
- package/src/generativeUIToJSX.test.ts +0 -268
- package/src/generativeUIToJSX.ts +0 -152
- package/src/index.server.test.ts +0 -106
- package/src/index.shared.ts +0 -61
- package/src/ir.test.ts +0 -203
- package/src/renderGenerativeUI.test.tsx +0 -373
- package/src/renderGenerativeUI.tsx +0 -165
- package/src/scopeSchema.test.ts +0 -72
- package/src/scopeSchema.ts +0 -71
- package/src/slack/a2uiSlack.test.ts +0 -198
- package/src/slack/constants.ts +0 -194
- package/src/slack/datePicker.test.ts +0 -612
- package/src/slack/decodeBlockAction.test.ts +0 -233
- package/src/slack/decodeBlockAction.ts +0 -232
- package/src/slack/fromSlackBlocks.test.ts +0 -1465
- package/src/slack/fromSlackBlocks.ts +0 -789
- package/src/slack/toSlackBlocks.test.ts +0 -3065
- package/src/slack/toSlackBlocks.ts +0 -1818
- package/src/slack/types.ts +0 -264
- package/src/teams/constants.ts +0 -93
- package/src/teams/decodeSubmitData.test.ts +0 -397
- package/src/teams/decodeSubmitData.ts +0 -110
- package/src/teams/temporal.test.ts +0 -766
- package/src/teams/temporalId.ts +0 -56
- package/src/teams/toAdaptiveCard.test.ts +0 -1897
- package/src/teams/toAdaptiveCard.ts +0 -1057
- package/src/teams/toTeamsAttachments.test.ts +0 -74
- package/src/teams/toTeamsAttachments.ts +0 -133
- package/src/teams/types.ts +0 -266
- package/src/temporal.test.ts +0 -319
- package/src/temporal.ts +0 -259
- package/src/types.ts +0 -119
- package/src/vocabulary/alert.test.tsx +0 -427
- package/src/vocabulary/alert.tsx +0 -217
- package/src/vocabulary/collectFormValues.test.ts +0 -389
- package/src/vocabulary/collectFormValues.ts +0 -116
- package/src/vocabulary/data.test.tsx +0 -858
- package/src/vocabulary/data.tsx +0 -819
- package/src/vocabulary/datepicker.dom.test.tsx +0 -1148
- package/src/vocabulary/dispatch.ts +0 -83
- package/src/vocabulary/fact.test.tsx +0 -94
- package/src/vocabulary/fact.tsx +0 -54
- package/src/vocabulary/form.test.tsx +0 -113
- package/src/vocabulary/form.tsx +0 -39
- package/src/vocabulary/formatValue.test.ts +0 -72
- package/src/vocabulary/formatValue.ts +0 -127
- package/src/vocabulary/icon.test.tsx +0 -64
- package/src/vocabulary/icon.tsx +0 -174
- package/src/vocabulary/index.test.ts +0 -65
- package/src/vocabulary/index.ts +0 -33
- package/src/vocabulary/interactive.dispatch.test.tsx +0 -454
- package/src/vocabulary/interactive.dom.test.tsx +0 -1747
- package/src/vocabulary/interactive.test.tsx +0 -377
- package/src/vocabulary/interactive.tsx +0 -1048
- package/src/vocabulary/layout.test.tsx +0 -323
- package/src/vocabulary/layout.tsx +0 -247
- package/src/vocabulary/list.test.tsx +0 -222
- package/src/vocabulary/list.tsx +0 -50
- package/src/vocabulary/media.test.tsx +0 -85
- package/src/vocabulary/media.tsx +0 -56
- package/src/vocabulary/text.test.tsx +0 -102
- package/src/vocabulary/text.tsx +0 -60
- package/src/vocabulary/toTextContent.ts +0 -2
|
@@ -1,1048 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import {
|
|
4
|
-
CHECKBOX_GROUP_ATTR,
|
|
5
|
-
FIELD_NAME_ATTR,
|
|
6
|
-
FIELD_VALUE_ATTR,
|
|
7
|
-
GENERATED_NAME_ATTR,
|
|
8
|
-
} from "../constants";
|
|
9
|
-
import type { Action } from "../ir";
|
|
10
|
-
import { BUTTON_STYLES } from "../ir";
|
|
11
|
-
import type {
|
|
12
|
-
GenerativeUIDispatch,
|
|
13
|
-
GenerativeUILibrary,
|
|
14
|
-
GenerativeUIStatus,
|
|
15
|
-
} from "../types";
|
|
16
|
-
import { A2uiBindingContext, useA2uiBinding } from "../a2ui/BindingContext";
|
|
17
|
-
import { useAnsweredValue } from "../answeredValues";
|
|
18
|
-
import { actionAttr, fire } from "./dispatch";
|
|
19
|
-
import { toTextContent } from "./toTextContent";
|
|
20
|
-
import { useRadioGroupName } from "../RadioGroupScope";
|
|
21
|
-
import {
|
|
22
|
-
classifyTemporal,
|
|
23
|
-
fromLocalDateTime,
|
|
24
|
-
getTemporalInputStep,
|
|
25
|
-
normalizeTemporalInputValue,
|
|
26
|
-
toLocalDateTime,
|
|
27
|
-
toPickerLocalDateTime,
|
|
28
|
-
} from "../temporal";
|
|
29
|
-
|
|
30
|
-
const optionSchema = z.object({
|
|
31
|
-
label: z.string(),
|
|
32
|
-
value: z.string(),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const describedOptionSchema = optionSchema.extend({
|
|
36
|
-
description: z.string().optional(),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
type Option = { label: string; description?: string; value: string };
|
|
40
|
-
|
|
41
|
-
const isOption = (option: unknown): option is Option =>
|
|
42
|
-
option !== null &&
|
|
43
|
-
typeof option === "object" &&
|
|
44
|
-
"label" in option &&
|
|
45
|
-
typeof option.label === "string" &&
|
|
46
|
-
(!("description" in option) || typeof option.description === "string") &&
|
|
47
|
-
"value" in option &&
|
|
48
|
-
typeof option.value === "string";
|
|
49
|
-
|
|
50
|
-
const mapOptions = (
|
|
51
|
-
options: unknown,
|
|
52
|
-
render: (option: Option, key: string) => React.ReactNode,
|
|
53
|
-
) => {
|
|
54
|
-
const occurrences = new Map<string, number>();
|
|
55
|
-
return (Array.isArray(options) ? options : []).map((option) => {
|
|
56
|
-
if (!isOption(option)) return null;
|
|
57
|
-
const occurrence = occurrences.get(option.value) ?? 0;
|
|
58
|
-
occurrences.set(option.value, occurrence + 1);
|
|
59
|
-
return render(option, JSON.stringify([option.value, occurrence]));
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
type RadioGroupRenderProps = {
|
|
64
|
-
value?: string;
|
|
65
|
-
options: Option[];
|
|
66
|
-
name?: string;
|
|
67
|
-
label?: string;
|
|
68
|
-
defaultValue?: string;
|
|
69
|
-
children?: React.ReactNode;
|
|
70
|
-
$status: GenerativeUIStatus;
|
|
71
|
-
$action?: Action;
|
|
72
|
-
$dispatch?: GenerativeUIDispatch;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
function RadioGroupRender({
|
|
76
|
-
value,
|
|
77
|
-
options,
|
|
78
|
-
name,
|
|
79
|
-
label,
|
|
80
|
-
defaultValue,
|
|
81
|
-
children,
|
|
82
|
-
$action,
|
|
83
|
-
$dispatch,
|
|
84
|
-
}: RadioGroupRenderProps) {
|
|
85
|
-
const groupName = useRadioGroupName(name);
|
|
86
|
-
const answeredValue = useAnsweredValue(name);
|
|
87
|
-
const updateBinding = useA2uiBinding(name);
|
|
88
|
-
const isBound = updateBinding !== undefined;
|
|
89
|
-
const initialValue =
|
|
90
|
-
typeof answeredValue === "string" ? answeredValue : defaultValue;
|
|
91
|
-
return (
|
|
92
|
-
<fieldset
|
|
93
|
-
key={initialValue}
|
|
94
|
-
data-aui="radiogroup"
|
|
95
|
-
data-aui-action={actionAttr($action)}
|
|
96
|
-
aria-label={label}
|
|
97
|
-
>
|
|
98
|
-
{mapOptions(options, (option, key) => (
|
|
99
|
-
<label key={key} data-aui="radiogroup-option">
|
|
100
|
-
<input
|
|
101
|
-
type="radio"
|
|
102
|
-
name={groupName}
|
|
103
|
-
{...{ [FIELD_NAME_ATTR]: name }}
|
|
104
|
-
{...(name == null ? { [GENERATED_NAME_ATTR]: "" } : {})}
|
|
105
|
-
value={option.value}
|
|
106
|
-
{...(isBound
|
|
107
|
-
? { checked: (answeredValue ?? value) === option.value }
|
|
108
|
-
: { defaultChecked: initialValue === option.value })}
|
|
109
|
-
onChange={(e) => {
|
|
110
|
-
updateBinding?.(option.value);
|
|
111
|
-
fire($action, $dispatch, option.value, e.currentTarget);
|
|
112
|
-
}}
|
|
113
|
-
/>
|
|
114
|
-
{option.description ? (
|
|
115
|
-
<span data-aui="option-content">
|
|
116
|
-
<span data-aui="option-label">{option.label}</span>
|
|
117
|
-
<span data-aui="option-description">{option.description}</span>
|
|
118
|
-
</span>
|
|
119
|
-
) : (
|
|
120
|
-
option.label
|
|
121
|
-
)}
|
|
122
|
-
</label>
|
|
123
|
-
))}
|
|
124
|
-
{children}
|
|
125
|
-
</fieldset>
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
type CheckboxGroupRenderProps = {
|
|
130
|
-
value?: string[];
|
|
131
|
-
options: Option[];
|
|
132
|
-
name?: string;
|
|
133
|
-
label?: string;
|
|
134
|
-
defaultValue?: string[];
|
|
135
|
-
children?: React.ReactNode;
|
|
136
|
-
$status: GenerativeUIStatus;
|
|
137
|
-
$action?: Action;
|
|
138
|
-
$dispatch?: GenerativeUIDispatch;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const checkedGroupValues = (input: HTMLInputElement): string[] =>
|
|
142
|
-
Array.from(
|
|
143
|
-
input
|
|
144
|
-
.closest("fieldset")
|
|
145
|
-
?.querySelectorAll<HTMLInputElement>(
|
|
146
|
-
`:scope > label > input[${CHECKBOX_GROUP_ATTR}]:checked`,
|
|
147
|
-
) ?? [],
|
|
148
|
-
(checkbox) => checkbox.value,
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
function CheckboxGroupRender({
|
|
152
|
-
value,
|
|
153
|
-
options,
|
|
154
|
-
name,
|
|
155
|
-
label,
|
|
156
|
-
defaultValue,
|
|
157
|
-
children,
|
|
158
|
-
$action,
|
|
159
|
-
$dispatch,
|
|
160
|
-
}: CheckboxGroupRenderProps) {
|
|
161
|
-
const generatedName = React.useId();
|
|
162
|
-
const fieldName = name ?? generatedName;
|
|
163
|
-
const answeredValue = useAnsweredValue(name);
|
|
164
|
-
const updateBinding = useA2uiBinding(name);
|
|
165
|
-
const isBound = updateBinding !== undefined;
|
|
166
|
-
const checkedValues =
|
|
167
|
-
Array.isArray(answeredValue) &&
|
|
168
|
-
answeredValue.every((value): value is string => typeof value === "string")
|
|
169
|
-
? answeredValue
|
|
170
|
-
: Array.isArray(defaultValue)
|
|
171
|
-
? defaultValue
|
|
172
|
-
: [];
|
|
173
|
-
return (
|
|
174
|
-
<fieldset
|
|
175
|
-
key={JSON.stringify(checkedValues)}
|
|
176
|
-
data-aui="checkboxgroup"
|
|
177
|
-
data-aui-action={actionAttr($action)}
|
|
178
|
-
aria-label={label}
|
|
179
|
-
>
|
|
180
|
-
{mapOptions(options, (option, key) => (
|
|
181
|
-
<label key={key} data-aui="checkboxgroup-option">
|
|
182
|
-
<input
|
|
183
|
-
type="checkbox"
|
|
184
|
-
name={fieldName}
|
|
185
|
-
{...{ [CHECKBOX_GROUP_ATTR]: "" }}
|
|
186
|
-
{...(name == null ? { [GENERATED_NAME_ATTR]: "" } : {})}
|
|
187
|
-
value={option.value}
|
|
188
|
-
{...(isBound
|
|
189
|
-
? {
|
|
190
|
-
checked: (Array.isArray(answeredValue)
|
|
191
|
-
? checkedValues
|
|
192
|
-
: (value ?? [])
|
|
193
|
-
).includes(option.value),
|
|
194
|
-
}
|
|
195
|
-
: { defaultChecked: checkedValues.includes(option.value) })}
|
|
196
|
-
onChange={(e) => {
|
|
197
|
-
const selected = checkedGroupValues(e.currentTarget);
|
|
198
|
-
updateBinding?.(selected);
|
|
199
|
-
fire($action, $dispatch, selected, e.currentTarget);
|
|
200
|
-
}}
|
|
201
|
-
/>
|
|
202
|
-
{option.description ? (
|
|
203
|
-
<span data-aui="option-content">
|
|
204
|
-
<span data-aui="option-label">{option.label}</span>
|
|
205
|
-
<span data-aui="option-description">{option.description}</span>
|
|
206
|
-
</span>
|
|
207
|
-
) : (
|
|
208
|
-
option.label
|
|
209
|
-
)}
|
|
210
|
-
</label>
|
|
211
|
-
))}
|
|
212
|
-
{children}
|
|
213
|
-
</fieldset>
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
type SelectRenderProps = {
|
|
218
|
-
value?: string;
|
|
219
|
-
options: Option[];
|
|
220
|
-
placeholder?: string;
|
|
221
|
-
label?: string;
|
|
222
|
-
name?: string;
|
|
223
|
-
defaultValue?: string;
|
|
224
|
-
children?: React.ReactNode;
|
|
225
|
-
$status: GenerativeUIStatus;
|
|
226
|
-
$action?: Action;
|
|
227
|
-
$dispatch?: GenerativeUIDispatch;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
function SelectRender({
|
|
231
|
-
value,
|
|
232
|
-
options,
|
|
233
|
-
placeholder,
|
|
234
|
-
label,
|
|
235
|
-
name,
|
|
236
|
-
defaultValue,
|
|
237
|
-
$action,
|
|
238
|
-
$dispatch,
|
|
239
|
-
children,
|
|
240
|
-
}: SelectRenderProps) {
|
|
241
|
-
const answeredValue = useAnsweredValue(name);
|
|
242
|
-
const updateBinding = useA2uiBinding(name);
|
|
243
|
-
const isBound = updateBinding !== undefined;
|
|
244
|
-
const placeholderText = toTextContent(placeholder);
|
|
245
|
-
const initialValue =
|
|
246
|
-
typeof answeredValue === "string"
|
|
247
|
-
? answeredValue
|
|
248
|
-
: typeof defaultValue === "string"
|
|
249
|
-
? defaultValue
|
|
250
|
-
: "";
|
|
251
|
-
return (
|
|
252
|
-
<select
|
|
253
|
-
key={initialValue}
|
|
254
|
-
data-aui="select"
|
|
255
|
-
data-aui-action={actionAttr($action)}
|
|
256
|
-
name={name}
|
|
257
|
-
aria-label={label}
|
|
258
|
-
{...(isBound
|
|
259
|
-
? {
|
|
260
|
-
value:
|
|
261
|
-
typeof answeredValue === "string" ? answeredValue : (value ?? ""),
|
|
262
|
-
}
|
|
263
|
-
: { defaultValue: initialValue })}
|
|
264
|
-
onChange={(e) => {
|
|
265
|
-
updateBinding?.(e.currentTarget.value);
|
|
266
|
-
fire($action, $dispatch, e.currentTarget.value, e.currentTarget);
|
|
267
|
-
}}
|
|
268
|
-
>
|
|
269
|
-
{placeholderText ? (
|
|
270
|
-
<option value="" disabled>
|
|
271
|
-
{placeholderText}
|
|
272
|
-
</option>
|
|
273
|
-
) : null}
|
|
274
|
-
{mapOptions(options, (option, key) => (
|
|
275
|
-
<option key={key} value={option.value}>
|
|
276
|
-
{option.label}
|
|
277
|
-
</option>
|
|
278
|
-
))}
|
|
279
|
-
{children}
|
|
280
|
-
</select>
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
type InputRenderProps = {
|
|
285
|
-
value?: string;
|
|
286
|
-
inputType?: "text" | "password" | "number";
|
|
287
|
-
placeholder?: string;
|
|
288
|
-
multiline?: boolean;
|
|
289
|
-
label?: string;
|
|
290
|
-
name?: string;
|
|
291
|
-
defaultValue?: string;
|
|
292
|
-
$status: GenerativeUIStatus;
|
|
293
|
-
$action?: Action;
|
|
294
|
-
$dispatch?: GenerativeUIDispatch;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
function InputRender({
|
|
298
|
-
value,
|
|
299
|
-
inputType,
|
|
300
|
-
placeholder,
|
|
301
|
-
multiline,
|
|
302
|
-
label,
|
|
303
|
-
name,
|
|
304
|
-
defaultValue,
|
|
305
|
-
$action,
|
|
306
|
-
$dispatch,
|
|
307
|
-
}: InputRenderProps) {
|
|
308
|
-
const answeredValue = useAnsweredValue(name);
|
|
309
|
-
const updateBinding = useA2uiBinding(name);
|
|
310
|
-
const isBound = updateBinding !== undefined;
|
|
311
|
-
const initialValue =
|
|
312
|
-
typeof answeredValue === "string" ? answeredValue : defaultValue;
|
|
313
|
-
const submit = (control: HTMLInputElement | HTMLTextAreaElement) =>
|
|
314
|
-
fire($action, $dispatch, control.value, control);
|
|
315
|
-
return multiline && (inputType === undefined || inputType === "text") ? (
|
|
316
|
-
<textarea
|
|
317
|
-
key={initialValue}
|
|
318
|
-
data-aui="input"
|
|
319
|
-
data-aui-multiline
|
|
320
|
-
data-aui-action={actionAttr($action)}
|
|
321
|
-
name={name}
|
|
322
|
-
aria-label={label}
|
|
323
|
-
placeholder={placeholder}
|
|
324
|
-
{...(isBound
|
|
325
|
-
? {
|
|
326
|
-
value:
|
|
327
|
-
typeof answeredValue === "string" ? answeredValue : (value ?? ""),
|
|
328
|
-
}
|
|
329
|
-
: { defaultValue: initialValue })}
|
|
330
|
-
onChange={
|
|
331
|
-
updateBinding ? (e) => updateBinding(e.currentTarget.value) : undefined
|
|
332
|
-
}
|
|
333
|
-
onKeyDown={(e) => {
|
|
334
|
-
if (
|
|
335
|
-
e.key !== "Enter" ||
|
|
336
|
-
!(e.ctrlKey || e.metaKey) ||
|
|
337
|
-
e.nativeEvent.isComposing
|
|
338
|
-
)
|
|
339
|
-
return;
|
|
340
|
-
if (e.currentTarget.form) {
|
|
341
|
-
e.preventDefault();
|
|
342
|
-
HTMLFormElement.prototype.requestSubmit.call(e.currentTarget.form);
|
|
343
|
-
} else {
|
|
344
|
-
submit(e.currentTarget);
|
|
345
|
-
}
|
|
346
|
-
}}
|
|
347
|
-
/>
|
|
348
|
-
) : (
|
|
349
|
-
<input
|
|
350
|
-
key={initialValue}
|
|
351
|
-
type={inputType}
|
|
352
|
-
step={inputType === "number" ? "any" : undefined}
|
|
353
|
-
data-aui="input"
|
|
354
|
-
data-aui-action={actionAttr($action)}
|
|
355
|
-
name={name}
|
|
356
|
-
aria-label={label}
|
|
357
|
-
placeholder={placeholder}
|
|
358
|
-
{...(isBound
|
|
359
|
-
? {
|
|
360
|
-
value:
|
|
361
|
-
typeof answeredValue === "string" ? answeredValue : (value ?? ""),
|
|
362
|
-
}
|
|
363
|
-
: { defaultValue: initialValue })}
|
|
364
|
-
onChange={
|
|
365
|
-
updateBinding ? (e) => updateBinding(e.currentTarget.value) : undefined
|
|
366
|
-
}
|
|
367
|
-
onKeyDown={(e) => {
|
|
368
|
-
if (
|
|
369
|
-
e.key === "Enter" &&
|
|
370
|
-
!e.nativeEvent.isComposing &&
|
|
371
|
-
!e.currentTarget.form
|
|
372
|
-
)
|
|
373
|
-
submit(e.currentTarget);
|
|
374
|
-
}}
|
|
375
|
-
/>
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
type DatePickerRenderProps = {
|
|
380
|
-
inputType?: "date" | "datetime" | "time";
|
|
381
|
-
value?: string;
|
|
382
|
-
min?: string;
|
|
383
|
-
max?: string;
|
|
384
|
-
label?: string;
|
|
385
|
-
name?: string;
|
|
386
|
-
$status: GenerativeUIStatus;
|
|
387
|
-
$action?: Action;
|
|
388
|
-
$dispatch?: GenerativeUIDispatch;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const subscribeToHydration = () => () => {};
|
|
392
|
-
const clientHydrationSnapshot = () => true;
|
|
393
|
-
const serverHydrationSnapshot = () => false;
|
|
394
|
-
|
|
395
|
-
function DatePickerRender({
|
|
396
|
-
inputType = "date",
|
|
397
|
-
value,
|
|
398
|
-
min,
|
|
399
|
-
max,
|
|
400
|
-
label,
|
|
401
|
-
name,
|
|
402
|
-
$action,
|
|
403
|
-
$dispatch,
|
|
404
|
-
}: DatePickerRenderProps) {
|
|
405
|
-
const answeredValue = useAnsweredValue(name);
|
|
406
|
-
const updateBinding = useA2uiBinding(name);
|
|
407
|
-
const isBound = updateBinding !== undefined;
|
|
408
|
-
const initialValue =
|
|
409
|
-
typeof answeredValue === "string" ? answeredValue : value;
|
|
410
|
-
const [selection, setSelection] = React.useState({
|
|
411
|
-
initialValue,
|
|
412
|
-
value: initialValue,
|
|
413
|
-
anchor: initialValue,
|
|
414
|
-
});
|
|
415
|
-
if (selection.initialValue !== initialValue) {
|
|
416
|
-
setSelection({
|
|
417
|
-
initialValue,
|
|
418
|
-
value: initialValue,
|
|
419
|
-
anchor:
|
|
420
|
-
isBound && initialValue === selection.value
|
|
421
|
-
? selection.anchor
|
|
422
|
-
: initialValue,
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
const currentValue = isBound ? initialValue : selection.value;
|
|
426
|
-
const temporal = classifyTemporal(currentValue ?? "");
|
|
427
|
-
const anchor = classifyTemporal(selection.anchor ?? "");
|
|
428
|
-
const hasInstantAnchor =
|
|
429
|
-
inputType === "datetime" && anchor.kind === "instant";
|
|
430
|
-
const canonicalFieldValue = (value: string | undefined) => {
|
|
431
|
-
const current = value ?? "";
|
|
432
|
-
const kind = classifyTemporal(current).kind;
|
|
433
|
-
if (inputType === "time")
|
|
434
|
-
return kind === "time" && normalizeTemporalInputValue(current) !== current
|
|
435
|
-
? value
|
|
436
|
-
: undefined;
|
|
437
|
-
if (inputType !== "datetime") return undefined;
|
|
438
|
-
if (kind === "instant") return value;
|
|
439
|
-
if (hasInstantAnchor) return selection.anchor;
|
|
440
|
-
return kind === "floating" &&
|
|
441
|
-
normalizeTemporalInputValue(current) !== current
|
|
442
|
-
? value
|
|
443
|
-
: undefined;
|
|
444
|
-
};
|
|
445
|
-
const minimum = classifyTemporal(min ?? "");
|
|
446
|
-
const maximum = classifyTemporal(max ?? "");
|
|
447
|
-
const hydrated = React.useSyncExternalStore(
|
|
448
|
-
subscribeToHydration,
|
|
449
|
-
clientHydrationSnapshot,
|
|
450
|
-
serverHydrationSnapshot,
|
|
451
|
-
);
|
|
452
|
-
const showRawValue =
|
|
453
|
-
inputType === "datetime" && temporal.kind === "instant" && !hydrated;
|
|
454
|
-
const displayValue =
|
|
455
|
-
currentValue === undefined
|
|
456
|
-
? undefined
|
|
457
|
-
: inputType === "datetime" && hydrated
|
|
458
|
-
? toPickerLocalDateTime(currentValue)
|
|
459
|
-
: normalizeTemporalInputValue(currentValue);
|
|
460
|
-
return (
|
|
461
|
-
<input
|
|
462
|
-
key={isBound ? undefined : initialValue}
|
|
463
|
-
type={
|
|
464
|
-
showRawValue
|
|
465
|
-
? "text"
|
|
466
|
-
: inputType === "datetime"
|
|
467
|
-
? "datetime-local"
|
|
468
|
-
: inputType
|
|
469
|
-
}
|
|
470
|
-
readOnly={showRawValue || undefined}
|
|
471
|
-
data-aui="datepicker"
|
|
472
|
-
data-aui-action={actionAttr($action)}
|
|
473
|
-
{...{
|
|
474
|
-
[FIELD_VALUE_ATTR]: canonicalFieldValue(currentValue),
|
|
475
|
-
}}
|
|
476
|
-
name={name}
|
|
477
|
-
aria-label={label}
|
|
478
|
-
{...(isBound || inputType === "datetime"
|
|
479
|
-
? { value: displayValue ?? "" }
|
|
480
|
-
: { defaultValue: displayValue })}
|
|
481
|
-
min={
|
|
482
|
-
inputType === "datetime" && hydrated && min !== undefined
|
|
483
|
-
? normalizeTemporalInputValue(
|
|
484
|
-
toLocalDateTime(
|
|
485
|
-
min,
|
|
486
|
-
minimum.kind === "instant" ? minimum.precision : undefined,
|
|
487
|
-
),
|
|
488
|
-
)
|
|
489
|
-
: min === undefined
|
|
490
|
-
? undefined
|
|
491
|
-
: normalizeTemporalInputValue(min)
|
|
492
|
-
}
|
|
493
|
-
max={
|
|
494
|
-
inputType === "datetime" && hydrated && max !== undefined
|
|
495
|
-
? normalizeTemporalInputValue(
|
|
496
|
-
toLocalDateTime(
|
|
497
|
-
max,
|
|
498
|
-
maximum.kind === "instant" ? maximum.precision : undefined,
|
|
499
|
-
),
|
|
500
|
-
)
|
|
501
|
-
: max === undefined
|
|
502
|
-
? undefined
|
|
503
|
-
: normalizeTemporalInputValue(max)
|
|
504
|
-
}
|
|
505
|
-
step={
|
|
506
|
-
inputType !== "date"
|
|
507
|
-
? getTemporalInputStep(selection.anchor, currentValue, min, max)
|
|
508
|
-
: undefined
|
|
509
|
-
}
|
|
510
|
-
onChange={(e) => {
|
|
511
|
-
const inputValue = normalizeTemporalInputValue(e.currentTarget.value);
|
|
512
|
-
const nextValue =
|
|
513
|
-
inputType === "datetime"
|
|
514
|
-
? fromLocalDateTime(inputValue, selection.anchor)
|
|
515
|
-
: inputValue;
|
|
516
|
-
const canonical = canonicalFieldValue(nextValue);
|
|
517
|
-
if (canonical !== undefined) {
|
|
518
|
-
e.currentTarget.setAttribute(FIELD_VALUE_ATTR, canonical);
|
|
519
|
-
} else {
|
|
520
|
-
e.currentTarget.removeAttribute(FIELD_VALUE_ATTR);
|
|
521
|
-
}
|
|
522
|
-
setSelection({
|
|
523
|
-
initialValue,
|
|
524
|
-
value: nextValue,
|
|
525
|
-
anchor: selection.anchor,
|
|
526
|
-
});
|
|
527
|
-
updateBinding?.(nextValue);
|
|
528
|
-
fire($action, $dispatch, nextValue, e.currentTarget);
|
|
529
|
-
}}
|
|
530
|
-
/>
|
|
531
|
-
);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
type CheckboxRenderProps = {
|
|
535
|
-
checked?: boolean;
|
|
536
|
-
label: string;
|
|
537
|
-
name?: string;
|
|
538
|
-
defaultChecked?: boolean;
|
|
539
|
-
variant?: "checkbox" | "switch";
|
|
540
|
-
$status: GenerativeUIStatus;
|
|
541
|
-
$action?: Action;
|
|
542
|
-
$dispatch?: GenerativeUIDispatch;
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
function CheckboxRender({
|
|
546
|
-
checked,
|
|
547
|
-
label,
|
|
548
|
-
name,
|
|
549
|
-
defaultChecked,
|
|
550
|
-
variant = "checkbox",
|
|
551
|
-
$action,
|
|
552
|
-
$dispatch,
|
|
553
|
-
}: CheckboxRenderProps) {
|
|
554
|
-
const answeredValue = useAnsweredValue(name);
|
|
555
|
-
const updateBinding = useA2uiBinding(name);
|
|
556
|
-
const isBound = updateBinding !== undefined;
|
|
557
|
-
const initialChecked =
|
|
558
|
-
typeof answeredValue === "boolean" ? answeredValue : defaultChecked;
|
|
559
|
-
return (
|
|
560
|
-
<label
|
|
561
|
-
data-aui="checkbox"
|
|
562
|
-
data-aui-variant={variant === "switch" ? variant : undefined}
|
|
563
|
-
>
|
|
564
|
-
<input
|
|
565
|
-
key={String(initialChecked)}
|
|
566
|
-
type="checkbox"
|
|
567
|
-
role={variant === "switch" ? "switch" : undefined}
|
|
568
|
-
data-aui-action={actionAttr($action)}
|
|
569
|
-
name={name}
|
|
570
|
-
{...(isBound
|
|
571
|
-
? {
|
|
572
|
-
checked:
|
|
573
|
-
typeof answeredValue === "boolean"
|
|
574
|
-
? answeredValue
|
|
575
|
-
: checked === true,
|
|
576
|
-
}
|
|
577
|
-
: { defaultChecked: initialChecked })}
|
|
578
|
-
onChange={(e) => {
|
|
579
|
-
updateBinding?.(e.currentTarget.checked);
|
|
580
|
-
fire($action, $dispatch, e.currentTarget.checked, e.currentTarget);
|
|
581
|
-
}}
|
|
582
|
-
/>
|
|
583
|
-
<span data-aui="checkbox-label">{toTextContent(label)}</span>
|
|
584
|
-
</label>
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
const finiteNumber = (value: unknown): value is number =>
|
|
589
|
-
typeof value === "number" && Number.isFinite(value);
|
|
590
|
-
|
|
591
|
-
const clamp = (value: number, min: number, max: number): number =>
|
|
592
|
-
Math.min(Math.max(value, min), max);
|
|
593
|
-
|
|
594
|
-
type SliderRenderProps = {
|
|
595
|
-
value?: number;
|
|
596
|
-
name?: string;
|
|
597
|
-
label?: string;
|
|
598
|
-
min: number;
|
|
599
|
-
max: number;
|
|
600
|
-
step?: number;
|
|
601
|
-
defaultValue?: number;
|
|
602
|
-
unit?: string;
|
|
603
|
-
$status: GenerativeUIStatus;
|
|
604
|
-
$action?: Action;
|
|
605
|
-
$dispatch?: GenerativeUIDispatch;
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
type SliderControlProps = {
|
|
609
|
-
controlledValue?: number;
|
|
610
|
-
name?: string;
|
|
611
|
-
label?: string;
|
|
612
|
-
min: number;
|
|
613
|
-
max: number;
|
|
614
|
-
step: number;
|
|
615
|
-
initialValue: number;
|
|
616
|
-
unit?: string;
|
|
617
|
-
$action?: Action;
|
|
618
|
-
$dispatch?: GenerativeUIDispatch;
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
function SliderControl({
|
|
622
|
-
controlledValue,
|
|
623
|
-
name,
|
|
624
|
-
label,
|
|
625
|
-
min,
|
|
626
|
-
max,
|
|
627
|
-
step,
|
|
628
|
-
initialValue,
|
|
629
|
-
unit,
|
|
630
|
-
$action,
|
|
631
|
-
$dispatch,
|
|
632
|
-
}: SliderControlProps) {
|
|
633
|
-
const updateBinding = useA2uiBinding(name);
|
|
634
|
-
const [localValue, setValue] = React.useState(initialValue);
|
|
635
|
-
const value = controlledValue ?? localValue;
|
|
636
|
-
const pointerActive = React.useRef(false);
|
|
637
|
-
const keyboardActive = React.useRef(false);
|
|
638
|
-
const lastCommitted = React.useRef(initialValue);
|
|
639
|
-
const currentValue = (input: HTMLInputElement) =>
|
|
640
|
-
clamp(Number(input.value), min, max);
|
|
641
|
-
const commit = (input: HTMLInputElement) => {
|
|
642
|
-
if (controlledValue !== undefined) return;
|
|
643
|
-
const nextValue = currentValue(input);
|
|
644
|
-
setValue(nextValue);
|
|
645
|
-
if (lastCommitted.current === nextValue) return;
|
|
646
|
-
lastCommitted.current = nextValue;
|
|
647
|
-
fire($action, $dispatch, nextValue, input);
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
return (
|
|
651
|
-
<label data-aui="slider-field">
|
|
652
|
-
{label ? <span data-aui="slider-label">{label}</span> : null}
|
|
653
|
-
<input
|
|
654
|
-
type="range"
|
|
655
|
-
data-aui="slider"
|
|
656
|
-
data-aui-action={actionAttr($action)}
|
|
657
|
-
name={name}
|
|
658
|
-
aria-label={label}
|
|
659
|
-
aria-valuetext={unit ? `${value} ${unit}` : String(value)}
|
|
660
|
-
min={min}
|
|
661
|
-
max={max}
|
|
662
|
-
step={step}
|
|
663
|
-
{...(controlledValue !== undefined
|
|
664
|
-
? { value }
|
|
665
|
-
: { defaultValue: initialValue })}
|
|
666
|
-
onInput={(e) => {
|
|
667
|
-
const nextValue = currentValue(e.currentTarget);
|
|
668
|
-
if (controlledValue !== undefined) updateBinding?.(nextValue);
|
|
669
|
-
else setValue(nextValue);
|
|
670
|
-
}}
|
|
671
|
-
onPointerDown={() => {
|
|
672
|
-
pointerActive.current = true;
|
|
673
|
-
}}
|
|
674
|
-
onPointerUp={(e) => {
|
|
675
|
-
pointerActive.current = false;
|
|
676
|
-
commit(e.currentTarget);
|
|
677
|
-
}}
|
|
678
|
-
onKeyDown={(e) => {
|
|
679
|
-
keyboardActive.current = [
|
|
680
|
-
"ArrowDown",
|
|
681
|
-
"ArrowLeft",
|
|
682
|
-
"ArrowRight",
|
|
683
|
-
"ArrowUp",
|
|
684
|
-
"End",
|
|
685
|
-
"Home",
|
|
686
|
-
"PageDown",
|
|
687
|
-
"PageUp",
|
|
688
|
-
].includes(e.key);
|
|
689
|
-
}}
|
|
690
|
-
onKeyUp={(e) => {
|
|
691
|
-
if (!keyboardActive.current) return;
|
|
692
|
-
keyboardActive.current = false;
|
|
693
|
-
commit(e.currentTarget);
|
|
694
|
-
}}
|
|
695
|
-
onChange={(e) => {
|
|
696
|
-
if (!pointerActive.current && !keyboardActive.current)
|
|
697
|
-
commit(e.currentTarget);
|
|
698
|
-
}}
|
|
699
|
-
/>
|
|
700
|
-
<output data-aui="slider-value">
|
|
701
|
-
{value}
|
|
702
|
-
{unit ? ` ${unit}` : ""}
|
|
703
|
-
</output>
|
|
704
|
-
</label>
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
function SliderRender({
|
|
709
|
-
value,
|
|
710
|
-
name,
|
|
711
|
-
label,
|
|
712
|
-
min,
|
|
713
|
-
max,
|
|
714
|
-
step,
|
|
715
|
-
defaultValue,
|
|
716
|
-
unit,
|
|
717
|
-
$action,
|
|
718
|
-
$dispatch,
|
|
719
|
-
}: SliderRenderProps) {
|
|
720
|
-
const answeredValue = useAnsweredValue(name);
|
|
721
|
-
const updateBinding = useA2uiBinding(name);
|
|
722
|
-
const isBound = updateBinding !== undefined;
|
|
723
|
-
const safeMin = finiteNumber(min) ? min : 0;
|
|
724
|
-
const safeMax = finiteNumber(max) ? Math.max(max, safeMin) : safeMin + 100;
|
|
725
|
-
const safeStep = finiteNumber(step) && step > 0 ? step : 1;
|
|
726
|
-
const defaultNumber = finiteNumber(isBound ? value : defaultValue)
|
|
727
|
-
? isBound
|
|
728
|
-
? value!
|
|
729
|
-
: defaultValue!
|
|
730
|
-
: safeMin;
|
|
731
|
-
const initialValue = clamp(
|
|
732
|
-
finiteNumber(answeredValue) ? answeredValue : defaultNumber,
|
|
733
|
-
safeMin,
|
|
734
|
-
safeMax,
|
|
735
|
-
);
|
|
736
|
-
return (
|
|
737
|
-
<SliderControl
|
|
738
|
-
key={`${safeMin}:${safeMax}:${safeStep}:${isBound ? "bound" : initialValue}`}
|
|
739
|
-
{...(isBound ? { controlledValue: initialValue } : {})}
|
|
740
|
-
min={safeMin}
|
|
741
|
-
max={safeMax}
|
|
742
|
-
step={safeStep}
|
|
743
|
-
initialValue={initialValue}
|
|
744
|
-
{...(name !== undefined ? { name } : {})}
|
|
745
|
-
{...(label !== undefined ? { label } : {})}
|
|
746
|
-
{...(unit !== undefined ? { unit } : {})}
|
|
747
|
-
{...($action !== undefined ? { $action } : {})}
|
|
748
|
-
{...($dispatch !== undefined ? { $dispatch } : {})}
|
|
749
|
-
/>
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
const UNDO_WINDOW_SECONDS = 5;
|
|
754
|
-
|
|
755
|
-
type ButtonRenderProps = {
|
|
756
|
-
label: string;
|
|
757
|
-
buttonStyle?: (typeof BUTTON_STYLES)[number];
|
|
758
|
-
block?: boolean;
|
|
759
|
-
submit?: boolean;
|
|
760
|
-
undoable?: boolean;
|
|
761
|
-
children?: React.ReactNode;
|
|
762
|
-
$status: GenerativeUIStatus;
|
|
763
|
-
$action?: Action;
|
|
764
|
-
$dispatch?: GenerativeUIDispatch;
|
|
765
|
-
};
|
|
766
|
-
|
|
767
|
-
function ButtonRender({
|
|
768
|
-
label,
|
|
769
|
-
buttonStyle,
|
|
770
|
-
block,
|
|
771
|
-
submit,
|
|
772
|
-
undoable,
|
|
773
|
-
children,
|
|
774
|
-
$action,
|
|
775
|
-
$dispatch,
|
|
776
|
-
}: ButtonRenderProps) {
|
|
777
|
-
const bindings = React.useContext(A2uiBindingContext!)?.fields;
|
|
778
|
-
const bindingsRef = React.useRef(bindings);
|
|
779
|
-
bindingsRef.current = bindings;
|
|
780
|
-
const [remaining, setRemaining] = React.useState<number | undefined>(
|
|
781
|
-
undefined,
|
|
782
|
-
);
|
|
783
|
-
const labelText = String(toTextContent(label) ?? "");
|
|
784
|
-
const undoLabel = labelText.trim();
|
|
785
|
-
const pendingAction = React.useRef<
|
|
786
|
-
| {
|
|
787
|
-
$action: Action;
|
|
788
|
-
$dispatch: GenerativeUIDispatch;
|
|
789
|
-
source: HTMLButtonElement;
|
|
790
|
-
}
|
|
791
|
-
| undefined
|
|
792
|
-
>(undefined);
|
|
793
|
-
const canUndo =
|
|
794
|
-
undoable && !submit && $action !== undefined && $dispatch !== undefined;
|
|
795
|
-
|
|
796
|
-
React.useEffect(() => {
|
|
797
|
-
if (remaining === undefined) return;
|
|
798
|
-
const timer = setTimeout(() => {
|
|
799
|
-
if (remaining > 1) {
|
|
800
|
-
setRemaining(remaining - 1);
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
const action = pendingAction.current;
|
|
804
|
-
pendingAction.current = undefined;
|
|
805
|
-
setRemaining(undefined);
|
|
806
|
-
if (action)
|
|
807
|
-
fire(
|
|
808
|
-
action.$action,
|
|
809
|
-
action.$dispatch,
|
|
810
|
-
undefined,
|
|
811
|
-
action.source,
|
|
812
|
-
bindingsRef.current,
|
|
813
|
-
);
|
|
814
|
-
}, 1_000);
|
|
815
|
-
return () => clearTimeout(timer);
|
|
816
|
-
}, [remaining]);
|
|
817
|
-
|
|
818
|
-
const cancelUndo = () => {
|
|
819
|
-
pendingAction.current = undefined;
|
|
820
|
-
setRemaining(undefined);
|
|
821
|
-
};
|
|
822
|
-
|
|
823
|
-
return (
|
|
824
|
-
<button
|
|
825
|
-
type={submit ? "submit" : "button"}
|
|
826
|
-
data-aui="button"
|
|
827
|
-
data-aui-style={buttonStyle}
|
|
828
|
-
data-aui-block={block || undefined}
|
|
829
|
-
data-aui-submit={submit || undefined}
|
|
830
|
-
data-aui-state={remaining === undefined ? undefined : "pending"}
|
|
831
|
-
data-aui-action={actionAttr($action)}
|
|
832
|
-
aria-label={
|
|
833
|
-
remaining === undefined
|
|
834
|
-
? undefined
|
|
835
|
-
: undoLabel
|
|
836
|
-
? `Undo ${undoLabel}`
|
|
837
|
-
: "Undo"
|
|
838
|
-
}
|
|
839
|
-
onClick={
|
|
840
|
-
submit
|
|
841
|
-
? undefined
|
|
842
|
-
: canUndo
|
|
843
|
-
? (e) => {
|
|
844
|
-
if (remaining !== undefined) {
|
|
845
|
-
cancelUndo();
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
pendingAction.current = {
|
|
849
|
-
$action,
|
|
850
|
-
$dispatch,
|
|
851
|
-
source: e.currentTarget,
|
|
852
|
-
};
|
|
853
|
-
setRemaining(UNDO_WINDOW_SECONDS);
|
|
854
|
-
}
|
|
855
|
-
: (e) =>
|
|
856
|
-
fire($action, $dispatch, undefined, e.currentTarget, bindings)
|
|
857
|
-
}
|
|
858
|
-
onKeyDown={
|
|
859
|
-
canUndo
|
|
860
|
-
? (e) => {
|
|
861
|
-
if (e.key !== "Escape" || remaining === undefined) return;
|
|
862
|
-
e.preventDefault();
|
|
863
|
-
cancelUndo();
|
|
864
|
-
}
|
|
865
|
-
: undefined
|
|
866
|
-
}
|
|
867
|
-
>
|
|
868
|
-
{remaining === undefined ? (
|
|
869
|
-
<>
|
|
870
|
-
{labelText}
|
|
871
|
-
{children}
|
|
872
|
-
</>
|
|
873
|
-
) : (
|
|
874
|
-
<>
|
|
875
|
-
Undo <span data-aui="button-countdown">{remaining}</span>
|
|
876
|
-
<span data-aui="button-undo-status" role="status">
|
|
877
|
-
{labelText} in {UNDO_WINDOW_SECONDS} seconds
|
|
878
|
-
</span>
|
|
879
|
-
</>
|
|
880
|
-
)}
|
|
881
|
-
</button>
|
|
882
|
-
);
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
export const interactiveVocabulary = {
|
|
886
|
-
Button: {
|
|
887
|
-
description:
|
|
888
|
-
"A clickable button. Carries `$action` describing the side effect or resume value. Set `submit` to submit an ancestor Form/Card instead of firing `$action` on click.",
|
|
889
|
-
properties: z.object({
|
|
890
|
-
label: z.string().describe("Button label."),
|
|
891
|
-
buttonStyle: z.enum(BUTTON_STYLES).optional().describe("Visual style."),
|
|
892
|
-
block: z
|
|
893
|
-
.boolean()
|
|
894
|
-
.optional()
|
|
895
|
-
.describe("Whether the button spans the full width."),
|
|
896
|
-
submit: z
|
|
897
|
-
.boolean()
|
|
898
|
-
.optional()
|
|
899
|
-
.describe(
|
|
900
|
-
"Render as a submit button for an ancestor Form/Card instead of a click button.",
|
|
901
|
-
),
|
|
902
|
-
undoable: z
|
|
903
|
-
.boolean()
|
|
904
|
-
.optional()
|
|
905
|
-
.describe(
|
|
906
|
-
"Delay the action with an undo control, for sends and other hard-to-reverse actions.",
|
|
907
|
-
),
|
|
908
|
-
}),
|
|
909
|
-
render: ButtonRender,
|
|
910
|
-
},
|
|
911
|
-
Select: {
|
|
912
|
-
description:
|
|
913
|
-
"A dropdown selector. Carries `$action` describing the on-select behavior.",
|
|
914
|
-
properties: z.object({
|
|
915
|
-
options: z.array(optionSchema).describe("Selectable options."),
|
|
916
|
-
placeholder: z
|
|
917
|
-
.string()
|
|
918
|
-
.optional()
|
|
919
|
-
.describe("Placeholder shown when nothing is selected."),
|
|
920
|
-
label: z
|
|
921
|
-
.string()
|
|
922
|
-
.optional()
|
|
923
|
-
.describe("Accessible label for the control."),
|
|
924
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
925
|
-
defaultValue: z.string().optional().describe("Initially selected value."),
|
|
926
|
-
}),
|
|
927
|
-
render: SelectRender,
|
|
928
|
-
},
|
|
929
|
-
Input: {
|
|
930
|
-
description:
|
|
931
|
-
"A text input. Carries `$action` describing the on-submit behavior.",
|
|
932
|
-
properties: z.object({
|
|
933
|
-
inputType: z
|
|
934
|
-
.enum(["text", "password", "number"])
|
|
935
|
-
.optional()
|
|
936
|
-
.describe("Single-line input type. Values remain strings."),
|
|
937
|
-
placeholder: z.string().optional().describe("Placeholder text."),
|
|
938
|
-
multiline: z
|
|
939
|
-
.boolean()
|
|
940
|
-
.optional()
|
|
941
|
-
.describe(
|
|
942
|
-
'Render a textarea instead of a single-line input; ignored when `inputType` is `"password"` or `"number"`.',
|
|
943
|
-
),
|
|
944
|
-
label: z
|
|
945
|
-
.string()
|
|
946
|
-
.optional()
|
|
947
|
-
.describe("Accessible label for the control."),
|
|
948
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
949
|
-
defaultValue: z.string().optional().describe("Initial text."),
|
|
950
|
-
}),
|
|
951
|
-
render: InputRender,
|
|
952
|
-
},
|
|
953
|
-
DatePicker: {
|
|
954
|
-
description:
|
|
955
|
-
"A date, datetime, or time input. Carries `$action` describing the on-select behavior.",
|
|
956
|
-
properties: z.object({
|
|
957
|
-
inputType: z
|
|
958
|
-
.enum(["date", "datetime", "time"])
|
|
959
|
-
.optional()
|
|
960
|
-
.describe(
|
|
961
|
-
'Temporal input type. Defaults to "date". Values remain strings.',
|
|
962
|
-
),
|
|
963
|
-
value: z
|
|
964
|
-
.string()
|
|
965
|
-
.optional()
|
|
966
|
-
.describe(
|
|
967
|
-
"Initial value: YYYY-MM-DD for date, HH:mm or HH:mm:ss with optional fraction of at most 9 digits for time, YYYY-MM-DDTHH:mm with optional :ss and fraction of at most 9 digits for datetime. A datetime with Z or ±HH:mm is an instant, displayed in the viewer's time zone and submitted with the same offset and precision. A datetime without an offset is local and submitted unchanged. An empty datetime submits with the viewer's offset and seconds.",
|
|
968
|
-
),
|
|
969
|
-
min: z
|
|
970
|
-
.string()
|
|
971
|
-
.optional()
|
|
972
|
-
.describe(
|
|
973
|
-
"Minimum value: YYYY-MM-DD for date, HH:mm or HH:mm:ss with optional fraction of at most 9 digits for time, YYYY-MM-DDTHH:mm with optional :ss and fraction of at most 9 digits for datetime. Datetimes with Z or ±HH:mm are converted to the viewer's time zone.",
|
|
974
|
-
),
|
|
975
|
-
max: z
|
|
976
|
-
.string()
|
|
977
|
-
.optional()
|
|
978
|
-
.describe(
|
|
979
|
-
"Maximum value: YYYY-MM-DD for date, HH:mm or HH:mm:ss with optional fraction of at most 9 digits for time, YYYY-MM-DDTHH:mm with optional :ss and fraction of at most 9 digits for datetime. Datetimes with Z or ±HH:mm are converted to the viewer's time zone.",
|
|
980
|
-
),
|
|
981
|
-
label: z
|
|
982
|
-
.string()
|
|
983
|
-
.optional()
|
|
984
|
-
.describe("Accessible label for the control."),
|
|
985
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
986
|
-
}),
|
|
987
|
-
render: DatePickerRender,
|
|
988
|
-
},
|
|
989
|
-
Checkbox: {
|
|
990
|
-
description:
|
|
991
|
-
"A checkbox with a label. Carries `$action` describing the on-change behavior.",
|
|
992
|
-
properties: z.object({
|
|
993
|
-
label: z.string().describe("Label text next to the checkbox."),
|
|
994
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
995
|
-
defaultChecked: z
|
|
996
|
-
.boolean()
|
|
997
|
-
.optional()
|
|
998
|
-
.describe("Whether the checkbox starts checked."),
|
|
999
|
-
variant: z
|
|
1000
|
-
.enum(["checkbox", "switch"])
|
|
1001
|
-
.optional()
|
|
1002
|
-
.describe("Whether to render a checkbox or switch."),
|
|
1003
|
-
}),
|
|
1004
|
-
render: CheckboxRender,
|
|
1005
|
-
},
|
|
1006
|
-
Slider: {
|
|
1007
|
-
description:
|
|
1008
|
-
"A numeric range control. Carries `$action` describing the committed value.",
|
|
1009
|
-
properties: z.object({
|
|
1010
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
1011
|
-
label: z
|
|
1012
|
-
.string()
|
|
1013
|
-
.optional()
|
|
1014
|
-
.describe("Accessible label for the control."),
|
|
1015
|
-
min: z.number().describe("Minimum value."),
|
|
1016
|
-
max: z.number().describe("Maximum value."),
|
|
1017
|
-
step: z.number().optional().describe("Value increment. Defaults to 1."),
|
|
1018
|
-
defaultValue: z.number().optional().describe("Initial value."),
|
|
1019
|
-
unit: z.string().optional().describe("Unit shown with the value."),
|
|
1020
|
-
}),
|
|
1021
|
-
render: SliderRender,
|
|
1022
|
-
},
|
|
1023
|
-
RadioGroup: {
|
|
1024
|
-
description:
|
|
1025
|
-
"A group of mutually exclusive radio options. Carries `$action` describing the on-change behavior.",
|
|
1026
|
-
properties: z.object({
|
|
1027
|
-
options: z.array(describedOptionSchema).describe("Selectable options."),
|
|
1028
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
1029
|
-
label: z.string().optional().describe("Accessible name for the group."),
|
|
1030
|
-
defaultValue: z.string().optional().describe("Initially selected value."),
|
|
1031
|
-
}),
|
|
1032
|
-
render: RadioGroupRender,
|
|
1033
|
-
},
|
|
1034
|
-
CheckboxGroup: {
|
|
1035
|
-
description:
|
|
1036
|
-
"A group of checkbox options where any number can be checked. Carries `$action` describing the on-change behavior.",
|
|
1037
|
-
properties: z.object({
|
|
1038
|
-
options: z.array(describedOptionSchema).describe("Selectable options."),
|
|
1039
|
-
name: z.string().optional().describe("Field name used inside a Form."),
|
|
1040
|
-
label: z.string().optional().describe("Accessible name for the group."),
|
|
1041
|
-
defaultValue: z
|
|
1042
|
-
.array(z.string())
|
|
1043
|
-
.optional()
|
|
1044
|
-
.describe("Initially checked values."),
|
|
1045
|
-
}),
|
|
1046
|
-
render: CheckboxGroupRender,
|
|
1047
|
-
},
|
|
1048
|
-
} satisfies GenerativeUILibrary;
|