@lynx-js/genui 0.0.1-rc.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/LICENSE +202 -0
- package/README.md +170 -0
- package/a2ui/README.md +140 -0
- package/a2ui/dist/catalog/Button/catalog.json +156 -0
- package/a2ui/dist/catalog/Button/index.d.ts +35 -0
- package/a2ui/dist/catalog/Button/index.js +35 -0
- package/a2ui/dist/catalog/Button/index.js.map +1 -0
- package/a2ui/dist/catalog/Card/catalog.json +24 -0
- package/a2ui/dist/catalog/Card/index.d.ts +11 -0
- package/a2ui/dist/catalog/Card/index.js +19 -0
- package/a2ui/dist/catalog/Card/index.js.map +1 -0
- package/a2ui/dist/catalog/CheckBox/catalog.json +170 -0
- package/a2ui/dist/catalog/CheckBox/index.d.ts +32 -0
- package/a2ui/dist/catalog/CheckBox/index.js +24 -0
- package/a2ui/dist/catalog/CheckBox/index.js.map +1 -0
- package/a2ui/dist/catalog/Column/catalog.json +57 -0
- package/a2ui/dist/catalog/Column/index.d.ts +15 -0
- package/a2ui/dist/catalog/Column/index.js +55 -0
- package/a2ui/dist/catalog/Column/index.js.map +1 -0
- package/a2ui/dist/catalog/Divider/catalog.json +14 -0
- package/a2ui/dist/catalog/Divider/index.d.ts +9 -0
- package/a2ui/dist/catalog/Divider/index.js +8 -0
- package/a2ui/dist/catalog/Divider/index.js.map +1 -0
- package/a2ui/dist/catalog/Icon/catalog.json +45 -0
- package/a2ui/dist/catalog/Icon/index.d.ts +14 -0
- package/a2ui/dist/catalog/Icon/index.js +11 -0
- package/a2ui/dist/catalog/Icon/index.js.map +1 -0
- package/a2ui/dist/catalog/Image/catalog.json +62 -0
- package/a2ui/dist/catalog/Image/index.d.ts +16 -0
- package/a2ui/dist/catalog/Image/index.js +30 -0
- package/a2ui/dist/catalog/Image/index.js.map +1 -0
- package/a2ui/dist/catalog/LineChart/catalog.json +98 -0
- package/a2ui/dist/catalog/LineChart/index.d.ts +31 -0
- package/a2ui/dist/catalog/LineChart/index.js +195 -0
- package/a2ui/dist/catalog/LineChart/index.js.map +1 -0
- package/a2ui/dist/catalog/List/catalog.json +52 -0
- package/a2ui/dist/catalog/List/index.d.ts +15 -0
- package/a2ui/dist/catalog/List/index.js +53 -0
- package/a2ui/dist/catalog/List/index.js.map +1 -0
- package/a2ui/dist/catalog/Modal/catalog.json +18 -0
- package/a2ui/dist/catalog/Modal/index.d.ts +12 -0
- package/a2ui/dist/catalog/Modal/index.js +33 -0
- package/a2ui/dist/catalog/Modal/index.js.map +1 -0
- package/a2ui/dist/catalog/PieChart/catalog.json +87 -0
- package/a2ui/dist/catalog/PieChart/index.d.ts +37 -0
- package/a2ui/dist/catalog/PieChart/index.js +131 -0
- package/a2ui/dist/catalog/PieChart/index.js.map +1 -0
- package/a2ui/dist/catalog/RadioGroup/catalog.json +184 -0
- package/a2ui/dist/catalog/RadioGroup/index.d.ts +36 -0
- package/a2ui/dist/catalog/RadioGroup/index.js +36 -0
- package/a2ui/dist/catalog/RadioGroup/index.js.map +1 -0
- package/a2ui/dist/catalog/Row/catalog.json +57 -0
- package/a2ui/dist/catalog/Row/index.d.ts +15 -0
- package/a2ui/dist/catalog/Row/index.js +28 -0
- package/a2ui/dist/catalog/Row/index.js.map +1 -0
- package/a2ui/dist/catalog/Slider/catalog.json +183 -0
- package/a2ui/dist/catalog/Slider/index.d.ts +41 -0
- package/a2ui/dist/catalog/Slider/index.js +39 -0
- package/a2ui/dist/catalog/Slider/index.js.map +1 -0
- package/a2ui/dist/catalog/Slider/utils.d.ts +11 -0
- package/a2ui/dist/catalog/Slider/utils.js +58 -0
- package/a2ui/dist/catalog/Slider/utils.js.map +1 -0
- package/a2ui/dist/catalog/Tabs/catalog.json +28 -0
- package/a2ui/dist/catalog/Tabs/index.d.ts +12 -0
- package/a2ui/dist/catalog/Tabs/index.js +32 -0
- package/a2ui/dist/catalog/Tabs/index.js.map +1 -0
- package/a2ui/dist/catalog/Text/catalog.json +74 -0
- package/a2ui/dist/catalog/Text/index.d.ts +18 -0
- package/a2ui/dist/catalog/Text/index.js +27 -0
- package/a2ui/dist/catalog/Text/index.js.map +1 -0
- package/a2ui/dist/catalog/TextField/catalog.json +147 -0
- package/a2ui/dist/catalog/TextField/index.d.ts +35 -0
- package/a2ui/dist/catalog/TextField/index.js +43 -0
- package/a2ui/dist/catalog/TextField/index.js.map +1 -0
- package/a2ui/dist/catalog/TextField/utils.d.ts +7 -0
- package/a2ui/dist/catalog/TextField/utils.js +51 -0
- package/a2ui/dist/catalog/TextField/utils.js.map +1 -0
- package/a2ui/dist/catalog/defineCatalog.d.ts +119 -0
- package/a2ui/dist/catalog/defineCatalog.js +196 -0
- package/a2ui/dist/catalog/defineCatalog.js.map +1 -0
- package/a2ui/dist/catalog/index.d.ts +20 -0
- package/a2ui/dist/catalog/index.js +26 -0
- package/a2ui/dist/catalog/index.js.map +1 -0
- package/a2ui/dist/catalog/utils/chart.d.ts +3 -0
- package/a2ui/dist/catalog/utils/chart.js +28 -0
- package/a2ui/dist/catalog/utils/chart.js.map +1 -0
- package/a2ui/dist/functions/index.d.ts +19 -0
- package/a2ui/dist/functions/index.js +87 -0
- package/a2ui/dist/functions/index.js.map +1 -0
- package/a2ui/dist/index.d.ts +11 -0
- package/a2ui/dist/index.js +35 -0
- package/a2ui/dist/index.js.map +1 -0
- package/a2ui/dist/react/A2UI.d.ts +77 -0
- package/a2ui/dist/react/A2UI.js +159 -0
- package/a2ui/dist/react/A2UI.js.map +1 -0
- package/a2ui/dist/react/A2UIProvider.d.ts +25 -0
- package/a2ui/dist/react/A2UIProvider.js +20 -0
- package/a2ui/dist/react/A2UIProvider.js.map +1 -0
- package/a2ui/dist/react/A2UIRenderer.d.ts +34 -0
- package/a2ui/dist/react/A2UIRenderer.js +161 -0
- package/a2ui/dist/react/A2UIRenderer.js.map +1 -0
- package/a2ui/dist/react/FormContext.d.ts +10 -0
- package/a2ui/dist/react/FormContext.js +12 -0
- package/a2ui/dist/react/FormContext.js.map +1 -0
- package/a2ui/dist/react/index.d.ts +8 -0
- package/a2ui/dist/react/index.js +23 -0
- package/a2ui/dist/react/index.js.map +1 -0
- package/a2ui/dist/react/useA2UIContext.d.ts +7 -0
- package/a2ui/dist/react/useA2UIContext.js +19 -0
- package/a2ui/dist/react/useA2UIContext.js.map +1 -0
- package/a2ui/dist/react/useAction.d.ts +9 -0
- package/a2ui/dist/react/useAction.js +38 -0
- package/a2ui/dist/react/useAction.js.map +1 -0
- package/a2ui/dist/react/useCatalog.d.ts +7 -0
- package/a2ui/dist/react/useCatalog.js +13 -0
- package/a2ui/dist/react/useCatalog.js.map +1 -0
- package/a2ui/dist/react/useChecks.d.ts +27 -0
- package/a2ui/dist/react/useChecks.js +76 -0
- package/a2ui/dist/react/useChecks.js.map +1 -0
- package/a2ui/dist/react/useDataBinding.d.ts +10 -0
- package/a2ui/dist/react/useDataBinding.js +175 -0
- package/a2ui/dist/react/useDataBinding.js.map +1 -0
- package/a2ui/dist/store/FormController.d.ts +23 -0
- package/a2ui/dist/store/FormController.js +40 -0
- package/a2ui/dist/store/FormController.js.map +1 -0
- package/a2ui/dist/store/FunctionRegistry.d.ts +47 -0
- package/a2ui/dist/store/FunctionRegistry.js +23 -0
- package/a2ui/dist/store/FunctionRegistry.js.map +1 -0
- package/a2ui/dist/store/MessageProcessor.d.ts +28 -0
- package/a2ui/dist/store/MessageProcessor.js +408 -0
- package/a2ui/dist/store/MessageProcessor.js.map +1 -0
- package/a2ui/dist/store/MessageStore.d.ts +38 -0
- package/a2ui/dist/store/MessageStore.js +37 -0
- package/a2ui/dist/store/MessageStore.js.map +1 -0
- package/a2ui/dist/store/Resource.d.ts +45 -0
- package/a2ui/dist/store/Resource.js +80 -0
- package/a2ui/dist/store/Resource.js.map +1 -0
- package/a2ui/dist/store/SignalStore.d.ts +10 -0
- package/a2ui/dist/store/SignalStore.js +29 -0
- package/a2ui/dist/store/SignalStore.js.map +1 -0
- package/a2ui/dist/store/index.d.ts +14 -0
- package/a2ui/dist/store/index.js +15 -0
- package/a2ui/dist/store/index.js.map +1 -0
- package/a2ui/dist/store/payloadNormalizer.d.ts +27 -0
- package/a2ui/dist/store/payloadNormalizer.js +179 -0
- package/a2ui/dist/store/payloadNormalizer.js.map +1 -0
- package/a2ui/dist/store/resolveFunctionCall.d.ts +18 -0
- package/a2ui/dist/store/resolveFunctionCall.js +131 -0
- package/a2ui/dist/store/resolveFunctionCall.js.map +1 -0
- package/a2ui/dist/store/types.d.ts +68 -0
- package/a2ui/dist/store/types.js +2 -0
- package/a2ui/dist/store/types.js.map +1 -0
- package/a2ui/dist/tsconfig.build.tsbuildinfo +1 -0
- package/a2ui/styles/catalog/Button.css +83 -0
- package/a2ui/styles/catalog/Card.css +49 -0
- package/a2ui/styles/catalog/CheckBox.css +46 -0
- package/a2ui/styles/catalog/Column.css +89 -0
- package/a2ui/styles/catalog/Divider.css +20 -0
- package/a2ui/styles/catalog/Icon.css +39 -0
- package/a2ui/styles/catalog/Image.css +54 -0
- package/a2ui/styles/catalog/LineChart.css +116 -0
- package/a2ui/styles/catalog/List.css +38 -0
- package/a2ui/styles/catalog/Modal.css +60 -0
- package/a2ui/styles/catalog/PieChart.css +109 -0
- package/a2ui/styles/catalog/RadioGroup.css +123 -0
- package/a2ui/styles/catalog/Row.css +83 -0
- package/a2ui/styles/catalog/Slider.css +96 -0
- package/a2ui/styles/catalog/Tabs.css +46 -0
- package/a2ui/styles/catalog/Text.css +121 -0
- package/a2ui/styles/catalog/TextField.css +48 -0
- package/a2ui/styles/theme.css +62 -0
- package/a2ui-catalog-extractor/README.md +605 -0
- package/a2ui-catalog-extractor/bin/a2ui-catalog-extractor.js +6 -0
- package/a2ui-catalog-extractor/dist/cli.d.ts +12 -0
- package/a2ui-catalog-extractor/dist/cli.js +171 -0
- package/a2ui-catalog-extractor/dist/cli.js.map +1 -0
- package/a2ui-catalog-extractor/dist/index.d.ts +140 -0
- package/a2ui-catalog-extractor/dist/index.js +755 -0
- package/a2ui-catalog-extractor/dist/index.js.map +1 -0
- package/a2ui-catalog-extractor/dist/tsconfig.build.tsbuildinfo +1 -0
- package/a2ui-catalog-extractor/skills/a2ui-catalog-extractor/SKILL.md +30 -0
- package/a2ui-prompt/README.md +65 -0
- package/a2ui-prompt/dist/index.d.ts +91 -0
- package/a2ui-prompt/dist/index.js +767 -0
- package/cli/README.md +88 -0
- package/cli/bin/cli.js +271 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/index.ts +114 -0
- package/openui/README.md +211 -0
- package/openui/dist/catalog/Action/index.d.ts +20 -0
- package/openui/dist/catalog/Action/index.js +23 -0
- package/openui/dist/catalog/Action/index.js.map +1 -0
- package/openui/dist/catalog/Button/index.d.ts +64 -0
- package/openui/dist/catalog/Button/index.js +75 -0
- package/openui/dist/catalog/Button/index.js.map +1 -0
- package/openui/dist/catalog/Card/index.d.ts +34 -0
- package/openui/dist/catalog/Card/index.js +69 -0
- package/openui/dist/catalog/Card/index.js.map +1 -0
- package/openui/dist/catalog/CardHeader/index.d.ts +5 -0
- package/openui/dist/catalog/CardHeader/index.js +18 -0
- package/openui/dist/catalog/CardHeader/index.js.map +1 -0
- package/openui/dist/catalog/Separator/index.d.ts +2 -0
- package/openui/dist/catalog/Separator/index.js +13 -0
- package/openui/dist/catalog/Separator/index.js.map +1 -0
- package/openui/dist/catalog/Stack/index.d.ts +29 -0
- package/openui/dist/catalog/Stack/index.js +61 -0
- package/openui/dist/catalog/Stack/index.js.map +1 -0
- package/openui/dist/catalog/Tag/index.d.ts +4 -0
- package/openui/dist/catalog/Tag/index.js +15 -0
- package/openui/dist/catalog/Tag/index.js.map +1 -0
- package/openui/dist/catalog/TextContent/index.d.ts +11 -0
- package/openui/dist/catalog/TextContent/index.js +33 -0
- package/openui/dist/catalog/TextContent/index.js.map +1 -0
- package/openui/dist/catalog/index.d.ts +7 -0
- package/openui/dist/catalog/index.js +11 -0
- package/openui/dist/catalog/index.js.map +1 -0
- package/openui/dist/catalog/utils.d.ts +2 -0
- package/openui/dist/catalog/utils.js +17 -0
- package/openui/dist/catalog/utils.js.map +1 -0
- package/openui/dist/core/context.d.ts +112 -0
- package/openui/dist/core/context.js +99 -0
- package/openui/dist/core/context.js.map +1 -0
- package/openui/dist/core/createLibrary.d.ts +10 -0
- package/openui/dist/core/createLibrary.js +36 -0
- package/openui/dist/core/createLibrary.js.map +1 -0
- package/openui/dist/core/hooks/index.d.ts +4 -0
- package/openui/dist/core/hooks/index.js +6 -0
- package/openui/dist/core/hooks/index.js.map +1 -0
- package/openui/dist/core/hooks/useFormValidation.d.ts +13 -0
- package/openui/dist/core/hooks/useFormValidation.js +76 -0
- package/openui/dist/core/hooks/useFormValidation.js.map +1 -0
- package/openui/dist/core/hooks/useOpenUIState.d.ts +33 -0
- package/openui/dist/core/hooks/useOpenUIState.js +413 -0
- package/openui/dist/core/hooks/useOpenUIState.js.map +1 -0
- package/openui/dist/core/hooks/useStateField.d.ts +2 -0
- package/openui/dist/core/hooks/useStateField.js +11 -0
- package/openui/dist/core/hooks/useStateField.js.map +1 -0
- package/openui/dist/core/index.d.ts +7 -0
- package/openui/dist/core/index.js +8 -0
- package/openui/dist/core/index.js.map +1 -0
- package/openui/dist/core/library.d.ts +20 -0
- package/openui/dist/core/library.js +13 -0
- package/openui/dist/core/library.js.map +1 -0
- package/openui/dist/core/renderer.css +271 -0
- package/openui/dist/core/renderer.d.ts +9 -0
- package/openui/dist/core/renderer.js +139 -0
- package/openui/dist/core/renderer.js.map +1 -0
- package/openui/dist/core/utils.d.ts +1 -0
- package/openui/dist/core/utils.js +76 -0
- package/openui/dist/core/utils.js.map +1 -0
- package/package.json +120 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
{
|
|
2
|
+
"TextField": {
|
|
3
|
+
"properties": {
|
|
4
|
+
"label": {
|
|
5
|
+
"oneOf": [
|
|
6
|
+
{
|
|
7
|
+
"type": "string"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"path": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"required": [
|
|
17
|
+
"path"
|
|
18
|
+
],
|
|
19
|
+
"additionalProperties": false
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"description": "The text label for the input field."
|
|
23
|
+
},
|
|
24
|
+
"value": {
|
|
25
|
+
"oneOf": [
|
|
26
|
+
{
|
|
27
|
+
"type": "string"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"path": {
|
|
33
|
+
"type": "string"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"required": [
|
|
37
|
+
"path"
|
|
38
|
+
],
|
|
39
|
+
"additionalProperties": false
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"description": "The value of the text field."
|
|
43
|
+
},
|
|
44
|
+
"variant": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"enum": [
|
|
47
|
+
"number",
|
|
48
|
+
"longText",
|
|
49
|
+
"shortText",
|
|
50
|
+
"obscured"
|
|
51
|
+
],
|
|
52
|
+
"description": "The type of input field to display."
|
|
53
|
+
},
|
|
54
|
+
"validationRegexp": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"description": "A regular expression used for client-side validation of the input."
|
|
57
|
+
},
|
|
58
|
+
"checks": {
|
|
59
|
+
"type": "array",
|
|
60
|
+
"items": {
|
|
61
|
+
"type": "object",
|
|
62
|
+
"properties": {
|
|
63
|
+
"condition": {
|
|
64
|
+
"oneOf": [
|
|
65
|
+
{
|
|
66
|
+
"type": "boolean"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"type": "object",
|
|
70
|
+
"properties": {
|
|
71
|
+
"path": {
|
|
72
|
+
"type": "string"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"required": [
|
|
76
|
+
"path"
|
|
77
|
+
],
|
|
78
|
+
"additionalProperties": false
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"type": "object",
|
|
82
|
+
"properties": {
|
|
83
|
+
"call": {
|
|
84
|
+
"type": "string"
|
|
85
|
+
},
|
|
86
|
+
"args": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"additionalProperties": {
|
|
89
|
+
"oneOf": [
|
|
90
|
+
{
|
|
91
|
+
"type": "string"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"type": "number"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"type": "boolean"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"type": "object",
|
|
101
|
+
"properties": {
|
|
102
|
+
"path": {
|
|
103
|
+
"type": "string"
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
"required": [
|
|
107
|
+
"path"
|
|
108
|
+
],
|
|
109
|
+
"additionalProperties": false
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"returnType": {
|
|
115
|
+
"type": "string",
|
|
116
|
+
"enum": [
|
|
117
|
+
"boolean"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"required": [
|
|
122
|
+
"call"
|
|
123
|
+
],
|
|
124
|
+
"additionalProperties": false
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"description": "The condition that indicates whether the check passes."
|
|
128
|
+
},
|
|
129
|
+
"message": {
|
|
130
|
+
"type": "string",
|
|
131
|
+
"description": "The error message to display if the check fails."
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"required": [
|
|
135
|
+
"condition",
|
|
136
|
+
"message"
|
|
137
|
+
],
|
|
138
|
+
"additionalProperties": false
|
|
139
|
+
},
|
|
140
|
+
"description": "A list of checks to perform."
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"required": [
|
|
144
|
+
"label"
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { GenericComponentProps } from '../../store/types.js';
|
|
2
|
+
import '../../../styles/catalog/TextField.css';
|
|
3
|
+
/**
|
|
4
|
+
* @a2uiCatalog TextField
|
|
5
|
+
*/
|
|
6
|
+
export interface TextFieldProps extends GenericComponentProps {
|
|
7
|
+
/** The text label for the input field. */
|
|
8
|
+
label: string | {
|
|
9
|
+
path: string;
|
|
10
|
+
};
|
|
11
|
+
/** The value of the text field. */
|
|
12
|
+
value?: string | {
|
|
13
|
+
path: string;
|
|
14
|
+
};
|
|
15
|
+
/** The type of input field to display. */
|
|
16
|
+
variant?: 'longText' | 'number' | 'shortText' | 'obscured';
|
|
17
|
+
/** A regular expression used for client-side validation of the input. */
|
|
18
|
+
validationRegexp?: string;
|
|
19
|
+
/** A list of checks to perform. */
|
|
20
|
+
checks?: Array<{
|
|
21
|
+
/** The condition that indicates whether the check passes. */
|
|
22
|
+
condition: boolean | {
|
|
23
|
+
path: string;
|
|
24
|
+
} | {
|
|
25
|
+
call: string;
|
|
26
|
+
args?: Record<string, string | number | boolean | {
|
|
27
|
+
path: string;
|
|
28
|
+
}>;
|
|
29
|
+
returnType?: 'boolean';
|
|
30
|
+
};
|
|
31
|
+
/** The error message to display if the check fails. */
|
|
32
|
+
message: string;
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export declare function TextField(props: TextFieldProps): import('@lynx-js/react').ReactNode;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@lynx-js/react/jsx-runtime";
|
|
2
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
3
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
// LICENSE file in the root directory of this source tree.
|
|
5
|
+
import { Input, TextArea } from '@lynx-js/lynx-ui';
|
|
6
|
+
import { useEffect, useState } from '@lynx-js/react';
|
|
7
|
+
import { getTextFieldInputType, isTextFieldValueValid, normalizeTextFieldValue, normalizeTextFieldVariant, } from './utils.js';
|
|
8
|
+
import '../../../styles/catalog/TextField.css';
|
|
9
|
+
export function TextField(props) {
|
|
10
|
+
const { id, label, setValue, validationRegexp } = props;
|
|
11
|
+
const textFieldType = props['textFieldType'];
|
|
12
|
+
const variant = normalizeTextFieldVariant(props.variant, textFieldType);
|
|
13
|
+
const resolvedValue = normalizeTextFieldValue(props.value);
|
|
14
|
+
const labelText = normalizeTextFieldValue(label);
|
|
15
|
+
const [draftValue, setDraftValue] = useState(resolvedValue);
|
|
16
|
+
const [touched, setTouched] = useState(false);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setDraftValue(resolvedValue);
|
|
19
|
+
return undefined;
|
|
20
|
+
}, [resolvedValue]);
|
|
21
|
+
const handleInput = (nextValue) => {
|
|
22
|
+
setTouched(true);
|
|
23
|
+
setDraftValue(nextValue);
|
|
24
|
+
setValue?.('value', nextValue);
|
|
25
|
+
};
|
|
26
|
+
const handleBlur = () => {
|
|
27
|
+
setTouched(true);
|
|
28
|
+
};
|
|
29
|
+
const invalid = !isTextFieldValueValid(draftValue, validationRegexp);
|
|
30
|
+
const showInvalid = touched && invalid;
|
|
31
|
+
const rootClassName = showInvalid
|
|
32
|
+
? `textfield textfield-${variant} textfield-invalid`
|
|
33
|
+
: `textfield textfield-${variant}`;
|
|
34
|
+
const controlClassName = variant === 'longText'
|
|
35
|
+
? 'textfield-control textfield-textarea'
|
|
36
|
+
: 'textfield-control';
|
|
37
|
+
const controlId = id ? `${id}-control` : undefined;
|
|
38
|
+
const controlIdProps = controlId ? { id: controlId } : {};
|
|
39
|
+
return (_jsxs("view", { className: rootClassName, children: [_jsx("text", { className: 'textfield-label', children: labelText }), variant === 'longText'
|
|
40
|
+
? (_jsx(TextArea, { ...controlIdProps, className: controlClassName, value: draftValue, maxLines: 6, confirmType: 'done', onInput: handleInput, onBlur: handleBlur }))
|
|
41
|
+
: (_jsx(Input, { ...controlIdProps, className: controlClassName, value: draftValue, type: getTextFieldInputType(variant), confirmType: 'done', onInput: handleInput, onBlur: handleBlur })), showInvalid && _jsx("text", { className: 'textfield-error', children: "Invalid value" })] }, id));
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/catalog/TextField/index.tsx"],"names":[],"mappings":";AAAA,wDAAwD;AACxD,yEAAyE;AACzE,0DAA0D;AAC1D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,YAAY,CAAC;AAGpB,OAAO,uCAAuC,CAAC;AA8B/C,MAAM,UAAU,SAAS,CACvB,KAAqB;IAErB,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IACxD,MAAM,aAAa,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,yBAAyB,CAAC,KAAK,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACxE,MAAM,aAAa,GAAG,uBAAuB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC5D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,SAAS,CAAC,GAAG,EAAE;QACb,aAAa,CAAC,aAAa,CAAC,CAAC;QAC7B,OAAO,S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C,CAAC,CACA,KAAC,KAAK,OACA,cAAc,EAClB,SAAS,EAAE,gBAAgB,EAC3B,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC,EACpC,WAAW,EAAC,MAAM,EAClB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,GAClB,CACH,EACF,WAAW,IAAI,eAAM,SAAS,EAAC,iBAAiB,8BAAqB,KAzB7D,EAAE,CA0BN,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type TextFieldVariant = 'longText' | 'number' | 'obscured' | 'shortText';
|
|
2
|
+
export declare const TEXT_FIELD_VARIANTS: readonly TextFieldVariant[];
|
|
3
|
+
export type TextFieldInputType = 'number' | 'password' | 'text';
|
|
4
|
+
export declare function normalizeTextFieldVariant(variant: unknown, textFieldType?: unknown): TextFieldVariant;
|
|
5
|
+
export declare function getTextFieldInputType(variant: TextFieldVariant): TextFieldInputType;
|
|
6
|
+
export declare function normalizeTextFieldValue(value: unknown): string;
|
|
7
|
+
export declare function isTextFieldValueValid(value: string, validationRegexp: unknown): boolean;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const TEXT_FIELD_VARIANTS = [
|
|
2
|
+
'longText',
|
|
3
|
+
'number',
|
|
4
|
+
'shortText',
|
|
5
|
+
'obscured',
|
|
6
|
+
];
|
|
7
|
+
export function normalizeTextFieldVariant(variant, textFieldType) {
|
|
8
|
+
const preferred = typeof variant === 'string' ? variant : undefined;
|
|
9
|
+
const fallback = typeof textFieldType === 'string'
|
|
10
|
+
? textFieldType
|
|
11
|
+
: undefined;
|
|
12
|
+
if (isTextFieldVariant(preferred))
|
|
13
|
+
return preferred;
|
|
14
|
+
if (isTextFieldVariant(fallback))
|
|
15
|
+
return fallback;
|
|
16
|
+
return 'shortText';
|
|
17
|
+
}
|
|
18
|
+
export function getTextFieldInputType(variant) {
|
|
19
|
+
if (variant === 'number')
|
|
20
|
+
return 'number';
|
|
21
|
+
if (variant === 'obscured')
|
|
22
|
+
return 'password';
|
|
23
|
+
return 'text';
|
|
24
|
+
}
|
|
25
|
+
export function normalizeTextFieldValue(value) {
|
|
26
|
+
if (value === null || value === undefined)
|
|
27
|
+
return '';
|
|
28
|
+
if (typeof value === 'string')
|
|
29
|
+
return value;
|
|
30
|
+
if (typeof value === 'number'
|
|
31
|
+
|| typeof value === 'boolean'
|
|
32
|
+
|| typeof value === 'bigint') {
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
export function isTextFieldValueValid(value, validationRegexp) {
|
|
38
|
+
if (typeof validationRegexp !== 'string' || validationRegexp.length === 0) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return new RegExp(validationRegexp).test(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function isTextFieldVariant(value) {
|
|
49
|
+
return TEXT_FIELD_VARIANTS.includes(value);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/catalog/TextField/utils.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,mBAAmB,GAAgC;IAC9D,UAAU;IACV,QAAQ;IACR,WAAW;IACX,UAAU;CACX,CAAC;AAIF,MAAM,UAAU,yBAAyB,CACvC,OAAgB,EAChB,aAAuB;IAEvB,MAAM,SAAS,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACpE,MAAM,QAAQ,GAAG,OAAO,aAAa,KAAK,QAAQ;QAChD,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,kBAAkB,CAAC,SAAS,CAAC;QA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inition, FunctionImpl } from '../store/FunctionRegistry.js';
|
|
3
|
+
import type { GenericComponentProps } from '../store/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* JSON Schema fragment describing a component's props. Produced at build time
|
|
6
|
+
* by `@lynx-js/genui/a2ui-catalog-extractor` from the component's TypeScript
|
|
7
|
+
* interface marked with `@a2uiCatalog <Name>`. Optional at runtime — entries
|
|
8
|
+
* that ship without a schema serialize to just `{ name }`.
|
|
9
|
+
*/
|
|
10
|
+
export type CatalogSchema = Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* The shape produced by the extractor as `dist/catalog/<Name>/catalog.json`.
|
|
13
|
+
* The single top-level key is the component's protocol name; the value is
|
|
14
|
+
* its schema. Importing the JSON gives you both, in one declaration.
|
|
15
|
+
*/
|
|
16
|
+
export type CatalogManifest = Record<string, CatalogSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* Loose component type — entries receive runtime-shaped props from the
|
|
19
|
+
* protocol stream, so we don't enforce per-component prop typing here.
|
|
20
|
+
*/
|
|
21
|
+
export type CatalogComponent = ComponentType<GenericComponentProps>;
|
|
22
|
+
/**
|
|
23
|
+
* A function-definition manifest as emitted by the extractor under
|
|
24
|
+
* `dist/catalog/functions/<name>.json`.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* The structured function definition that flows from the extractor (or the
|
|
28
|
+
* upstream basic-catalog manifests) into the catalog and out to the agent
|
|
29
|
+
* during the handshake. Aliased onto the store's `FunctionDefinition` so
|
|
30
|
+
* `functionRegistry.register({ definition })` accepts catalog entries
|
|
31
|
+
* directly without re-shaping.
|
|
32
|
+
*/
|
|
33
|
+
export type CatalogFunctionDefinition = FunctionDefinition;
|
|
34
|
+
export type FunctionManifest = Record<string, CatalogFunctionDefinition>;
|
|
35
|
+
/**
|
|
36
|
+
* A function entry — pair an impl with its name, plus an optional manifest
|
|
37
|
+
* so the handshake can announce the schema to the agent.
|
|
38
|
+
*/
|
|
39
|
+
export interface CatalogFunctionEntry {
|
|
40
|
+
kind: 'function';
|
|
41
|
+
name: string;
|
|
42
|
+
impl: FunctionImpl;
|
|
43
|
+
definition?: CatalogFunctionDefinition;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a function entry for `defineCatalog`. Either pair the impl with the
|
|
47
|
+
* extracted manifest, or pass just the impl (the registry still routes
|
|
48
|
+
* calls; the agent just won't see the parameter schema).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const requiredEntry = defineFunction(required, requiredManifest);
|
|
52
|
+
* const catalog = defineCatalog([Text, Button, requiredEntry]);
|
|
53
|
+
*/
|
|
54
|
+
export declare function defineFunction(impl: FunctionImpl, manifest?: FunctionManifest): CatalogFunctionEntry;
|
|
55
|
+
/**
|
|
56
|
+
* What the developer passes into `defineCatalog`. Components and function
|
|
57
|
+
* entries can be intermixed.
|
|
58
|
+
*/
|
|
59
|
+
export type CatalogInput = CatalogComponent | readonly [CatalogComponent, CatalogManifest] | ResolvedCatalogEntry | CatalogFunctionEntry;
|
|
60
|
+
/**
|
|
61
|
+
* A resolved catalog entry. Internal representation; consumers don't usually
|
|
62
|
+
* construct these directly — they pass `CatalogInput`s to `defineCatalog`.
|
|
63
|
+
*/
|
|
64
|
+
export interface ResolvedCatalogEntry {
|
|
65
|
+
name: string;
|
|
66
|
+
component: CatalogComponent;
|
|
67
|
+
schema?: CatalogSchema;
|
|
68
|
+
}
|
|
69
|
+
export interface Catalog {
|
|
70
|
+
readonly components: readonly ResolvedCatalogEntry[];
|
|
71
|
+
readonly functions: readonly CatalogFunctionEntry[];
|
|
72
|
+
}
|
|
73
|
+
/** The serialized payload sent to the agent during channel handshake. */
|
|
74
|
+
export interface SerializedCatalog {
|
|
75
|
+
version: '0.9';
|
|
76
|
+
components: Array<{
|
|
77
|
+
name: string;
|
|
78
|
+
schema?: CatalogSchema;
|
|
79
|
+
}>;
|
|
80
|
+
functions?: CatalogFunctionDefinition[];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build a catalog from a list of components, `[component, manifest]` pairs,
|
|
84
|
+
* and/or function entries. Duplicate names within the same kind are rejected.
|
|
85
|
+
* Function entries register their impls into `functionRegistry` immediately,
|
|
86
|
+
* so any `executeFunctionCall` after `defineCatalog` can route to them.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* import { Text, Button } from '@lynx-js/genui/a2ui';
|
|
90
|
+
* import { defineCatalog, defineFunction } from '@lynx-js/genui/a2ui';
|
|
91
|
+
* import { required } from '@lynx-js/genui/a2ui/functions';
|
|
92
|
+
* import textManifest from '@lynx-js/genui/a2ui/catalog/Text/catalog.json'
|
|
93
|
+
* with { type: 'json' };
|
|
94
|
+
*
|
|
95
|
+
* const catalog = defineCatalog([
|
|
96
|
+
* [Text, textManifest],
|
|
97
|
+
* Button,
|
|
98
|
+
* defineFunction(required),
|
|
99
|
+
* ]);
|
|
100
|
+
*/
|
|
101
|
+
export declare function defineCatalog(inputs: readonly CatalogInput[]): Catalog;
|
|
102
|
+
/**
|
|
103
|
+
* Merge multiple catalogs. Last write wins on duplicate names — useful when
|
|
104
|
+
* a page-level catalog overrides a brand-level one which overrides built-ins.
|
|
105
|
+
*/
|
|
106
|
+
export declare function mergeCatalogs(...catalogs: Catalog[]): Catalog;
|
|
107
|
+
/**
|
|
108
|
+
* Build a name → component lookup map from a catalog. The renderer uses
|
|
109
|
+
* this to resolve `{ component: 'Text', ... }` from the protocol stream.
|
|
110
|
+
*/
|
|
111
|
+
export declare function resolveCatalog(catalog: Catalog): ReadonlyMap<string, CatalogComponent>;
|
|
112
|
+
/**
|
|
113
|
+
* Produce the JSON manifest the client should announce to the agent during
|
|
114
|
+
* channel handshake. Component entries without an attached schema serialize
|
|
115
|
+
* to `{ name }` only — useful for letting the agent at least know what's
|
|
116
|
+
* renderable. Function entries serialize with their parameter schema when
|
|
117
|
+
* available.
|
|
118
|
+
*/
|
|
119
|
+
export declare function serializeCatalog(catalog: Catalog): SerializedCatalog;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { functionRegistry } from '../store/FunctionRegistry.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build a function entry for `defineCatalog`. Either pair the impl with the
|
|
4
|
+
* extracted manifest, or pass just the impl (the registry still routes
|
|
5
|
+
* calls; the agent just won't see the parameter schema).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const requiredEntry = defineFunction(required, requiredManifest);
|
|
9
|
+
* const catalog = defineCatalog([Text, Button, requiredEntry]);
|
|
10
|
+
*/
|
|
11
|
+
export function defineFunction(impl, manifest) {
|
|
12
|
+
if (manifest) {
|
|
13
|
+
const keys = Object.keys(manifest);
|
|
14
|
+
if (keys.length === 0) {
|
|
15
|
+
throw new Error('[a2ui] Empty manifest passed to defineFunction; expected '
|
|
16
|
+
+ '`{ <functionName>: definition }`.');
|
|
17
|
+
}
|
|
18
|
+
const name = keys[0];
|
|
19
|
+
const definition = manifest[name];
|
|
20
|
+
return {
|
|
21
|
+
kind: 'function',
|
|
22
|
+
name,
|
|
23
|
+
impl,
|
|
24
|
+
definition,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const name = impl.displayName
|
|
28
|
+
?? impl.name;
|
|
29
|
+
if (!name) {
|
|
30
|
+
throw new Error('[a2ui] Cannot add a function to the catalog: no name available. '
|
|
31
|
+
+ 'Pair it with its manifest as `defineFunction(impl, manifest)`, '
|
|
32
|
+
+ 'or set `impl.displayName = "..."`.');
|
|
33
|
+
}
|
|
34
|
+
return { kind: 'function', name, impl };
|
|
35
|
+
}
|
|
36
|
+
function isFunctionEntry(input) {
|
|
37
|
+
return typeof input === 'object'
|
|
38
|
+
&& input !== null
|
|
39
|
+
&& !Array.isArray(input)
|
|
40
|
+
&& input.kind === 'function';
|
|
41
|
+
}
|
|
42
|
+
function isResolvedEntry(input) {
|
|
43
|
+
return typeof input === 'object'
|
|
44
|
+
&& input !== null
|
|
45
|
+
&& !Array.isArray(input)
|
|
46
|
+
&& 'component' in input
|
|
47
|
+
&& 'name' in input
|
|
48
|
+
&& !isFunctionEntry(input);
|
|
49
|
+
}
|
|
50
|
+
function isTuple(input) {
|
|
51
|
+
return Array.isArray(input);
|
|
52
|
+
}
|
|
53
|
+
function deriveBareName(component) {
|
|
54
|
+
const name = component.displayName
|
|
55
|
+
?? component.name;
|
|
56
|
+
if (!name) {
|
|
57
|
+
throw new Error('[a2ui] Cannot add a component to the catalog: no displayName or '
|
|
58
|
+
+ 'function name. This typically happens when the bundler '
|
|
59
|
+
+ 'minifies function names. Set `Foo.displayName = "Foo"` after '
|
|
60
|
+
+ 'the component declaration (the string literal survives '
|
|
61
|
+
+ 'minification), or pair it with its `catalog.json` manifest as '
|
|
62
|
+
+ '`[Foo, fooManifest]`.');
|
|
63
|
+
}
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
66
|
+
function resolveComponentInput(input) {
|
|
67
|
+
if (isResolvedEntry(input))
|
|
68
|
+
return input;
|
|
69
|
+
if (isTuple(input)) {
|
|
70
|
+
const [component, manifest] = input;
|
|
71
|
+
const keys = Object.keys(manifest);
|
|
72
|
+
if (keys.length === 0) {
|
|
73
|
+
throw new Error('[a2ui] Empty manifest passed to defineCatalog; expected '
|
|
74
|
+
+ '`{ <ComponentName>: schema }`.');
|
|
75
|
+
}
|
|
76
|
+
const name = keys[0];
|
|
77
|
+
const entry = { name, component: component };
|
|
78
|
+
const schema = manifest[name];
|
|
79
|
+
if (schema !== undefined)
|
|
80
|
+
entry.schema = schema;
|
|
81
|
+
return entry;
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
name: deriveBareName(input),
|
|
85
|
+
component: input,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Build a catalog from a list of components, `[component, manifest]` pairs,
|
|
90
|
+
* and/or function entries. Duplicate names within the same kind are rejected.
|
|
91
|
+
* Function entries register their impls into `functionRegistry` immediately,
|
|
92
|
+
* so any `executeFunctionCall` after `defineCatalog` can route to them.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* import { Text, Button } from '@lynx-js/genui/a2ui';
|
|
96
|
+
* import { defineCatalog, defineFunction } from '@lynx-js/genui/a2ui';
|
|
97
|
+
* import { required } from '@lynx-js/genui/a2ui/functions';
|
|
98
|
+
* import textManifest from '@lynx-js/genui/a2ui/catalog/Text/catalog.json'
|
|
99
|
+
* with { type: 'json' };
|
|
100
|
+
*
|
|
101
|
+
* const catalog = defineCatalog([
|
|
102
|
+
* [Text, textManifest],
|
|
103
|
+
* Button,
|
|
104
|
+
* defineFunction(required),
|
|
105
|
+
* ]);
|
|
106
|
+
*/
|
|
107
|
+
export function defineCatalog(inputs) {
|
|
108
|
+
const components = [];
|
|
109
|
+
const functions = [];
|
|
110
|
+
const seenComponents = new Set();
|
|
111
|
+
const seenFunctions = new Set();
|
|
112
|
+
for (const input of inputs) {
|
|
113
|
+
if (isFunctionEntry(input)) {
|
|
114
|
+
if (seenFunctions.has(input.name)) {
|
|
115
|
+
throw new Error(`[a2ui] Duplicate function name in catalog: "${input.name}". `
|
|
116
|
+
+ `Use mergeCatalogs() if you intend to override.`);
|
|
117
|
+
}
|
|
118
|
+
seenFunctions.add(input.name);
|
|
119
|
+
functions.push(input);
|
|
120
|
+
functionRegistry.register({
|
|
121
|
+
name: input.name,
|
|
122
|
+
impl: input.impl,
|
|
123
|
+
...(input.definition ? { definition: input.definition } : {}),
|
|
124
|
+
});
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const entry = resolveComponentInput(input);
|
|
128
|
+
if (seenComponents.has(entry.name)) {
|
|
129
|
+
throw new Error(`[a2ui] Duplicate component name in catalog: "${entry.name}". `
|
|
130
|
+
+ `Use mergeCatalogs() if you intend to override.`);
|
|
131
|
+
}
|
|
132
|
+
seenComponents.add(entry.name);
|
|
133
|
+
components.push(entry);
|
|
134
|
+
}
|
|
135
|
+
return { components, functions };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Merge multiple catalogs. Last write wins on duplicate names — useful when
|
|
139
|
+
* a page-level catalog overrides a brand-level one which overrides built-ins.
|
|
140
|
+
*/
|
|
141
|
+
export function mergeCatalogs(...catalogs) {
|
|
142
|
+
const componentMap = new Map();
|
|
143
|
+
const functionMap = new Map();
|
|
144
|
+
for (const cat of catalogs) {
|
|
145
|
+
for (const entry of cat.components)
|
|
146
|
+
componentMap.set(entry.name, entry);
|
|
147
|
+
for (const fn of cat.functions)
|
|
148
|
+
functionMap.set(fn.name, fn);
|
|
149
|
+
}
|
|
150
|
+
// Re-register so the registry tracks the merged set.
|
|
151
|
+
for (const fn of functionMap.values()) {
|
|
152
|
+
functionRegistry.register({
|
|
153
|
+
name: fn.name,
|
|
154
|
+
impl: fn.impl,
|
|
155
|
+
...(fn.definition ? { definition: fn.definition } : {}),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
components: Array.from(componentMap.values()),
|
|
160
|
+
functions: Array.from(functionMap.values()),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Build a name → component lookup map from a catalog. The renderer uses
|
|
165
|
+
* this to resolve `{ component: 'Text', ... }` from the protocol stream.
|
|
166
|
+
*/
|
|
167
|
+
export function resolveCatalog(catalog) {
|
|
168
|
+
const map = new Map();
|
|
169
|
+
for (const entry of catalog.components)
|
|
170
|
+
map.set(entry.name, entry.component);
|
|
171
|
+
return map;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Produce the JSON manifest the client should announce to the agent during
|
|
175
|
+
* channel handshake. Component entries without an attached schema serialize
|
|
176
|
+
* to `{ name }` only — useful for letting the agent at least know what's
|
|
177
|
+
* renderable. Function entries serialize with their parameter schema when
|
|
178
|
+
* available.
|
|
179
|
+
*/
|
|
180
|
+
export function serializeCatalog(catalog) {
|
|
181
|
+
const components = [];
|
|
182
|
+
for (const entry of catalog.components) {
|
|
183
|
+
const out = { name: entry.name };
|
|
184
|
+
if (entry.schema !== undefined)
|
|
185
|
+
out.schema = entry.schema;
|
|
186
|
+
components.push(out);
|
|
187
|
+
}
|
|
188
|
+
const serialized = { version: '0.9', components };
|
|
189
|
+
const functions = catalog.functions
|
|
190
|
+
.filter(fn => fn.definition !== undefined)
|
|
191
|
+
.map(fn => fn.definition);
|
|
192
|
+
if (functions.length > 0)
|
|
193
|
+
serialized.functions = functions;
|
|
194
|
+
return serialized;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=defineCatalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineCatalog.js","sourceRoot":"","sources":["../../src/catalog/defineCatalog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAsDhE;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAkB,EAClB,QAA2B;IAE3B,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,2DAA2D;kBACvD,mCAAmC,CACxC,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;QACtB,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAE,CAAC;QACnC,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,IAAI;YACJ,IAAI;YACJ,UAAU;SACX,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAI,IAAgD,CAAC,WAAW;WACpE,IAA0B,CAAC,IAAI,CAAC;IACtC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,kEAAkE;cAC9D,iEAAiE;cACjE,oCAAoC,CACzC,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,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MAAM,GAAG,CAAC;QAAE,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC;IAC3D,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { defineCatalog, defineFunction, mergeCatalogs, resolveCatalog, serializeCatalog, } from './defineCatalog.js';
|
|
2
|
+
export type { Catalog, CatalogComponent, CatalogFunctionDefinition, CatalogFunctionEntry, CatalogInput, CatalogManifest, CatalogSchema, FunctionManifest, ResolvedCatalogEntry, SerializedCatalog, } from './defineCatalog.js';
|
|
3
|
+
export { Button } from './Button/index.js';
|
|
4
|
+
export { Card } from './Card/index.js';
|
|
5
|
+
export { CheckBox } from './CheckBox/index.js';
|
|
6
|
+
export { LineChart } from './LineChart/index.js';
|
|
7
|
+
export { PieChart } from './PieChart/index.js';
|
|
8
|
+
export { Column } from './Column/index.js';
|
|
9
|
+
export { Divider } from './Divider/index.js';
|
|
10
|
+
export { Icon } from './Icon/index.js';
|
|
11
|
+
export { Image } from './Image/index.js';
|
|
12
|
+
export { List } from './List/index.js';
|
|
13
|
+
export { Modal } from './Modal/index.js';
|
|
14
|
+
export { RadioGroup } from './RadioGroup/index.js';
|
|
15
|
+
export { Row } from './Row/index.js';
|
|
16
|
+
export { Slider } from './Slider/index.js';
|
|
17
|
+
export { Tabs } from './Tabs/index.js';
|
|
18
|
+
export { Text } from './Text/index.js';
|
|
19
|
+
export { TextField } from './TextField/index.js';
|
|
20
|
+
export { DEFAULT_CHART_COLORS, escapeXml, formatValue } from './utils/chart.js';
|