@iyulab/u-widgets 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ /** Supported input field types for form widgets. */
2
+ declare type FieldType = 'text' | 'email' | 'password' | 'tel' | 'url' | 'textarea' | 'number' | 'select' | 'multiselect' | 'date' | 'datetime' | 'time' | 'toggle' | 'range' | 'radio' | 'checkbox';
3
+
4
+ declare interface FormdownField {
5
+ name: string;
6
+ type: string;
7
+ label?: string;
8
+ required?: boolean;
9
+ placeholder?: string;
10
+ options?: string[];
11
+ attributes?: Record<string, string>;
12
+ }
13
+
14
+ export declare function mapActions(actions: FormdownField[]): UWidgetAction[];
15
+
16
+ export declare function mapFields(fields: FormdownField[]): UWidgetFieldDefinition[];
17
+
18
+ /**
19
+ * Action button definition.
20
+ *
21
+ * Reserved actions: `"submit"`, `"cancel"`, `"navigate"`.
22
+ * Custom action strings are forwarded to the host via the `u-widget-event`.
23
+ *
24
+ * @example
25
+ * ```json
26
+ * { "label": "Submit", "action": "submit", "style": "primary" }
27
+ * ```
28
+ */
29
+ declare interface UWidgetAction {
30
+ /** Button display text. */
31
+ label: string;
32
+ /** Action identifier emitted in the widget event. */
33
+ action: string;
34
+ /** Visual style hint. */
35
+ style?: 'primary' | 'danger' | 'default';
36
+ /** Whether the button is disabled. */
37
+ disabled?: boolean;
38
+ /** URL for `"navigate"` actions. */
39
+ url?: string;
40
+ }
41
+
42
+ /**
43
+ * Field definition for form/confirm input widgets.
44
+ *
45
+ * @example
46
+ * ```json
47
+ * { "field": "email", "label": "Email", "type": "email", "required": true }
48
+ * ```
49
+ */
50
+ declare interface UWidgetFieldDefinition {
51
+ /** Data field name (maps to `data[field]` for defaults and output). */
52
+ field: string;
53
+ /** Display label. Defaults to the field name. */
54
+ label?: string;
55
+ /** Input type. Defaults to `"text"`. */
56
+ type?: FieldType;
57
+ /** Whether the field must be filled before submit. */
58
+ required?: boolean;
59
+ /** Placeholder text shown when the field is empty. */
60
+ placeholder?: string;
61
+ /** Options for select, multiselect, radio, and checkbox types. */
62
+ options?: string[];
63
+ /** Minimum character length for text inputs. */
64
+ minLength?: number;
65
+ /** Maximum character length for text inputs. */
66
+ maxLength?: number;
67
+ /** Custom regex pattern for validation (e.g. `"^[A-Z]{3}$"`). */
68
+ pattern?: string;
69
+ /** Number of visible rows for textarea type. */
70
+ rows?: number;
71
+ /** Minimum value (number) or date string. */
72
+ min?: number | string;
73
+ /** Maximum value (number) or date string. */
74
+ max?: number | string;
75
+ /** Step increment for number and range inputs. */
76
+ step?: number;
77
+ /** Custom validation error message (overrides locale default). */
78
+ message?: string;
79
+ }
80
+
81
+ export { }
@@ -0,0 +1,59 @@
1
+ import { FormManager as n } from "@formdown/core/form-manager";
2
+ import { r as a } from "./formdown-BWJ6QGJs.js";
3
+ const l = {
4
+ text: "text",
5
+ email: "email",
6
+ password: "password",
7
+ tel: "tel",
8
+ url: "url",
9
+ textarea: "textarea",
10
+ number: "number",
11
+ select: "select",
12
+ multiselect: "multiselect",
13
+ date: "date",
14
+ datetime: "datetime",
15
+ "datetime-local": "datetime",
16
+ time: "time",
17
+ toggle: "toggle",
18
+ range: "range",
19
+ radio: "radio",
20
+ checkbox: "checkbox"
21
+ };
22
+ function m(i) {
23
+ return l[i] ?? "text";
24
+ }
25
+ function o(i) {
26
+ return i.map((e) => {
27
+ const t = {
28
+ field: e.name,
29
+ type: m(e.type)
30
+ };
31
+ if (e.label && (t.label = e.label), e.required && (t.required = !0), e.placeholder && (t.placeholder = e.placeholder), e.options && e.options.length > 0 && (t.options = e.options), e.attributes) {
32
+ const r = e.attributes;
33
+ r.min != null && (t.min = isNaN(Number(r.min)) ? r.min : Number(r.min)), r.max != null && (t.max = isNaN(Number(r.max)) ? r.max : Number(r.max)), r.step != null && (t.step = Number(r.step)), r.maxlength != null && (t.maxLength = Number(r.maxlength)), r.rows != null && (t.rows = Number(r.rows));
34
+ }
35
+ return t;
36
+ });
37
+ }
38
+ function s(i) {
39
+ return i.map((e) => {
40
+ const t = {
41
+ action: e.name === "reset" ? "cancel" : e.name,
42
+ label: e.label || e.name
43
+ };
44
+ return e.name === "submit" ? t.style = "primary" : e.name === "reset" && (t.style = "default"), t;
45
+ });
46
+ }
47
+ function u(i, e) {
48
+ const t = new n();
49
+ return t.parse(i), e && t.setDefaults(e), {
50
+ fields: o(t.getInputFields()),
51
+ actions: s(t.getActions())
52
+ };
53
+ }
54
+ a(u);
55
+ export {
56
+ s as mapActions,
57
+ o as mapFields
58
+ };
59
+ //# sourceMappingURL=u-widgets-forms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"u-widgets-forms.js","sources":["../src/adapters/formdown-adapter.ts","../src/forms.ts"],"sourcesContent":["// @formdown/core Field → u-widgets type adapter\n// Uses structural typing so @formdown/core install is not required at compile time.\n\nimport type { UWidgetFieldDefinition, UWidgetAction, FieldType } from '../core/types.js';\n\n// Structural interface matching @formdown/core Field shape\nexport interface FormdownField {\n name: string;\n type: string;\n label?: string;\n required?: boolean;\n placeholder?: string;\n options?: string[];\n attributes?: Record<string, string>;\n}\n\nconst FIELD_TYPE_MAP: Record<string, FieldType> = {\n text: 'text',\n email: 'email',\n password: 'password',\n tel: 'tel',\n url: 'url',\n textarea: 'textarea',\n number: 'number',\n select: 'select',\n multiselect: 'multiselect',\n date: 'date',\n datetime: 'datetime',\n 'datetime-local': 'datetime',\n time: 'time',\n toggle: 'toggle',\n range: 'range',\n radio: 'radio',\n checkbox: 'checkbox',\n};\n\nexport function mapFieldType(type: string): FieldType {\n return FIELD_TYPE_MAP[type] ?? 'text';\n}\n\nexport function mapFields(fields: FormdownField[]): UWidgetFieldDefinition[] {\n return fields.map((f) => {\n const def: UWidgetFieldDefinition = {\n field: f.name,\n type: mapFieldType(f.type),\n };\n if (f.label) def.label = f.label;\n if (f.required) def.required = true;\n if (f.placeholder) def.placeholder = f.placeholder;\n if (f.options && f.options.length > 0) def.options = f.options;\n\n // Extract numeric/string attributes\n if (f.attributes) {\n const a = f.attributes;\n if (a.min != null) def.min = isNaN(Number(a.min)) ? a.min : Number(a.min);\n if (a.max != null) def.max = isNaN(Number(a.max)) ? a.max : Number(a.max);\n if (a.step != null) def.step = Number(a.step);\n if (a.maxlength != null) def.maxLength = Number(a.maxlength);\n if (a.rows != null) def.rows = Number(a.rows);\n }\n\n return def;\n });\n}\n\nexport function mapActions(actions: FormdownField[]): UWidgetAction[] {\n return actions.map((a) => {\n const action: UWidgetAction = {\n action: a.name === 'reset' ? 'cancel' : a.name,\n label: a.label || a.name,\n };\n if (a.name === 'submit') action.style = 'primary';\n else if (a.name === 'reset') action.style = 'default';\n return action;\n });\n}\n","/**\n * @module u-widgets/forms\n *\n * Integration entry point for `@formdown/core`. Import this module to replace\n * the built-in formdown parser with the full `@formdown/core` parser, enabling\n * richer form syntax support.\n *\n * @example\n * ```ts\n * import 'u-widgets';\n * import 'u-widgets/forms';\n *\n * el.spec = { widget: 'form', formdown: '@name*(Name): []\\\\n@email: @[]' };\n * ```\n */\n\nimport { FormManager } from '@formdown/core/form-manager';\nimport { registerFormdownParser } from './core/formdown.js';\nimport { mapFields, mapActions } from './adapters/formdown-adapter.js';\nimport type { FormdownResult } from './core/formdown.js';\n\nfunction parseWithFormdownCore(input: string, data?: Record<string, unknown>): FormdownResult {\n const fm = new FormManager();\n fm.parse(input);\n if (data) fm.setDefaults(data);\n return {\n fields: mapFields(fm.getInputFields()),\n actions: mapActions(fm.getActions()),\n };\n}\n\nregisterFormdownParser(parseWithFormdownCore);\n\nexport { mapFields, mapActions } from './adapters/formdown-adapter.js';\n"],"names":["FIELD_TYPE_MAP","mapFieldType","type","mapFields","fields","f","def","a","mapActions","actions","action","parseWithFormdownCore","input","data","fm","FormManager","registerFormdownParser"],"mappings":";;AAgBA,MAAMA,IAA4C;AAAA,EAChD,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,KAAK;AAAA,EACL,KAAK;AAAA,EACL,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,UAAU;AAAA,EACV,kBAAkB;AAAA,EAClB,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AAAA,EACP,UAAU;AACZ;AAEO,SAASC,EAAaC,GAAyB;AACpD,SAAOF,EAAeE,CAAI,KAAK;AACjC;AAEO,SAASC,EAAUC,GAAmD;AAC3E,SAAOA,EAAO,IAAI,CAACC,MAAM;AACvB,UAAMC,IAA8B;AAAA,MAClC,OAAOD,EAAE;AAAA,MACT,MAAMJ,EAAaI,EAAE,IAAI;AAAA,IAAA;AAQ3B,QANIA,EAAE,UAAOC,EAAI,QAAQD,EAAE,QACvBA,EAAE,aAAUC,EAAI,WAAW,KAC3BD,EAAE,gBAAaC,EAAI,cAAcD,EAAE,cACnCA,EAAE,WAAWA,EAAE,QAAQ,SAAS,MAAGC,EAAI,UAAUD,EAAE,UAGnDA,EAAE,YAAY;AAChB,YAAME,IAAIF,EAAE;AACZ,MAAIE,EAAE,OAAO,SAAMD,EAAI,MAAM,MAAM,OAAOC,EAAE,GAAG,CAAC,IAAIA,EAAE,MAAM,OAAOA,EAAE,GAAG,IACpEA,EAAE,OAAO,SAAMD,EAAI,MAAM,MAAM,OAAOC,EAAE,GAAG,CAAC,IAAIA,EAAE,MAAM,OAAOA,EAAE,GAAG,IACpEA,EAAE,QAAQ,WAAU,OAAO,OAAOA,EAAE,IAAI,IACxCA,EAAE,aAAa,WAAU,YAAY,OAAOA,EAAE,SAAS,IACvDA,EAAE,QAAQ,WAAU,OAAO,OAAOA,EAAE,IAAI;AAAA,IAC9C;AAEA,WAAOD;AAAA,EACT,CAAC;AACH;AAEO,SAASE,EAAWC,GAA2C;AACpE,SAAOA,EAAQ,IAAI,CAACF,MAAM;AACxB,UAAMG,IAAwB;AAAA,MAC5B,QAAQH,EAAE,SAAS,UAAU,WAAWA,EAAE;AAAA,MAC1C,OAAOA,EAAE,SAASA,EAAE;AAAA,IAAA;AAEtB,WAAIA,EAAE,SAAS,WAAUG,EAAO,QAAQ,YAC/BH,EAAE,SAAS,YAASG,EAAO,QAAQ,YACrCA;AAAA,EACT,CAAC;AACH;ACtDA,SAASC,EAAsBC,GAAeC,GAAgD;AAC5F,QAAMC,IAAK,IAAIC,EAAA;AACf,SAAAD,EAAG,MAAMF,CAAK,GACVC,KAAMC,EAAG,YAAYD,CAAI,GACtB;AAAA,IACL,QAAQV,EAAUW,EAAG,gBAAgB;AAAA,IACrC,SAASN,EAAWM,EAAG,WAAA,CAAY;AAAA,EAAA;AAEvC;AAEAE,EAAuBL,CAAqB;"}
@@ -0,0 +1,400 @@
1
+ /** Action property descriptions (from schema $defs/action). */
2
+ export declare const ACTION_PROP_DOCS: Readonly<Record<string, string>>;
3
+
4
+ /**
5
+ * Generate a complete spec suggestion from data.
6
+ *
7
+ * Convenience wrapper: picks the top suggestion and returns a ready-to-use spec.
8
+ *
9
+ * @param data - The data to analyze.
10
+ * @returns A complete spec, or `undefined` if no suggestion could be made.
11
+ */
12
+ export declare function autoSpec(data: Record<string, unknown> | Record<string, unknown>[]): UWidgetSpec | undefined;
13
+
14
+ /**
15
+ * Well-known data field descriptions.
16
+ * Unlike schema-bound registries, these cover common keys used across widgets.
17
+ * Not enforced by schema tests — new keys appear with type only until added here.
18
+ */
19
+ export declare const DATA_FIELD_DOCS: Readonly<Record<string, string>>;
20
+
21
+ /** Data field descriptor for well-known widget data properties. */
22
+ export declare interface DataFieldInfo {
23
+ readonly key: string;
24
+ readonly type: string;
25
+ readonly desc: string;
26
+ readonly required?: boolean;
27
+ }
28
+
29
+ /** Field definition property descriptions (from schema $defs/fieldDefinition). */
30
+ export declare const FIELD_PROP_DOCS: Readonly<Record<string, string>>;
31
+
32
+ /** Supported input field types for form widgets. */
33
+ declare type FieldType = 'text' | 'email' | 'password' | 'tel' | 'url' | 'textarea' | 'number' | 'select' | 'multiselect' | 'date' | 'datetime' | 'time' | 'toggle' | 'range' | 'radio' | 'checkbox';
34
+
35
+ /** Get the event types emitted by a widget. Resolves `chart.*` → `chart`. */
36
+ export declare function getWidgetEvents(widget: string): readonly string[];
37
+
38
+ /**
39
+ * Get the widget catalog.
40
+ *
41
+ * - No argument → list all widgets (`WidgetInfo[]`).
42
+ * - Exact widget name → full detail (`WidgetDetail`).
43
+ * - Category or prefix → filtered list (`WidgetInfo[]`).
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * help() // → all widget descriptions
48
+ * help('chart') // → all chart types (WidgetInfo[])
49
+ * help('chart.bar') // → full detail (WidgetDetail)
50
+ * ```
51
+ */
52
+ export declare function help(): WidgetInfo[];
53
+
54
+ export declare function help(widget: string): WidgetInfo[] | WidgetDetail;
55
+
56
+ /** Mapping key descriptions (from schema $defs/mapping.properties). */
57
+ export declare const MAPPING_DOCS: Readonly<Record<string, string>>;
58
+
59
+ /** A widget + mapping recommendation. */
60
+ export declare interface MappingSuggestion {
61
+ /** Recommended widget type. */
62
+ widget: string;
63
+ /** Suggested mapping for the widget. */
64
+ mapping?: UWidgetMapping;
65
+ /** Confidence score (0–1). Higher means better fit. */
66
+ confidence: number;
67
+ /** Human-readable reason for this suggestion. */
68
+ reason: string;
69
+ }
70
+
71
+ /**
72
+ * Well-known options descriptions.
73
+ * Covers widget-specific rendering options used across the catalog.
74
+ */
75
+ export declare const OPTION_DOCS: Readonly<Record<string, string>>;
76
+
77
+ /**
78
+ * Runtime spec scanner that extracts the full property surface from widget specs.
79
+ *
80
+ * `specSurface()` is the single function shared by both the MCP server and
81
+ * the demo props panel — it scans an array of spec objects and returns every
82
+ * key actually used, merged with descriptions from `widget-meta.ts`.
83
+ *
84
+ * Structural guarantee: if a spec uses a property, `specSurface()` reports it.
85
+ */
86
+ /** A single discovered property with its inferred type and optional description. */
87
+ export declare interface PropInfo {
88
+ key: string;
89
+ /** Inferred runtime type: `"number"`, `"string"`, `"boolean"`, `"object[]"`, etc. */
90
+ type: string;
91
+ /** Description from the registry when available. */
92
+ desc?: string;
93
+ }
94
+
95
+ /** The full property surface extracted from a set of specs. */
96
+ export declare interface SpecSurface {
97
+ /** Top-level spec keys used (data, mapping, options, …). */
98
+ specKeys: string[];
99
+ /** `data.*` keys with inferred types. */
100
+ dataFields: PropInfo[];
101
+ /** `mapping.*` keys with schema descriptions. */
102
+ mappingKeys: PropInfo[];
103
+ /** `options.*` keys with inferred types. */
104
+ optionKeys: PropInfo[];
105
+ /** `fields[].*` keys with schema descriptions. */
106
+ fieldProps: PropInfo[];
107
+ /** Distinct `fields[].type` values used. */
108
+ fieldTypes: string[];
109
+ /** Distinct `actions[].style` values used. */
110
+ actionStyles: string[];
111
+ /** Events emitted by this widget category. */
112
+ events: readonly string[];
113
+ }
114
+
115
+ /**
116
+ * Scan an array of spec objects and collect their full property surface.
117
+ *
118
+ * @param specs - Array of widget spec objects (e.g. variant values).
119
+ * @param widget - Optional widget type string for event lookup.
120
+ * @returns The collected {@link SpecSurface}.
121
+ */
122
+ export declare function specSurface(specs: object[], widget?: string): SpecSurface;
123
+
124
+ /**
125
+ * Suggest widget type and mapping from data alone.
126
+ *
127
+ * Analyzes data structure (keys, types, shape) and returns
128
+ * ranked suggestions. If a widget type is provided, only suggests
129
+ * a mapping for that specific widget.
130
+ *
131
+ * @param data - The data to analyze (object or array of records).
132
+ * @param widget - Optional widget type to constrain the suggestion.
133
+ * @returns Array of suggestions sorted by confidence (highest first).
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * suggestMapping([{ name: 'A', value: 30 }, { name: 'B', value: 70 }])
138
+ * // → [{ widget: 'chart.bar', mapping: { x: 'name', y: 'value' }, confidence: 0.9, ... }, ...]
139
+ * ```
140
+ */
141
+ export declare function suggestMapping(data: Record<string, unknown> | Record<string, unknown>[], widget?: string): MappingSuggestion[];
142
+
143
+ /**
144
+ * Generate a minimal template spec for a widget type.
145
+ *
146
+ * Returns a complete, valid spec with sample data that can be
147
+ * used as a starting point. Returns `undefined` for unknown types.
148
+ *
149
+ * @param widget - Widget type identifier (e.g., `"chart.bar"`, `"metric"`).
150
+ * @returns A deep-copied template spec, or `undefined`.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * template('metric')
155
+ * // → { widget: 'metric', data: { value: 1284, unit: 'users', ... } }
156
+ * ```
157
+ */
158
+ export declare function template(widget: string): UWidgetSpec | undefined;
159
+
160
+ /**
161
+ * Action button definition.
162
+ *
163
+ * Reserved actions: `"submit"`, `"cancel"`, `"navigate"`.
164
+ * Custom action strings are forwarded to the host via the `u-widget-event`.
165
+ *
166
+ * @example
167
+ * ```json
168
+ * { "label": "Submit", "action": "submit", "style": "primary" }
169
+ * ```
170
+ */
171
+ declare interface UWidgetAction {
172
+ /** Button display text. */
173
+ label: string;
174
+ /** Action identifier emitted in the widget event. */
175
+ action: string;
176
+ /** Visual style hint. */
177
+ style?: 'primary' | 'danger' | 'default';
178
+ /** Whether the button is disabled. */
179
+ disabled?: boolean;
180
+ /** URL for `"navigate"` actions. */
181
+ url?: string;
182
+ }
183
+
184
+ /**
185
+ * Child widget spec inside a compose widget.
186
+ * Inherits `type` and `version` from the parent — no need to repeat them.
187
+ */
188
+ declare interface UWidgetChildSpec extends Omit<UWidgetSpec, 'type' | 'version'> {
189
+ /** Grid column span within the parent compose layout. */
190
+ span?: number;
191
+ /** When true, the child is initially collapsed (uses native `<details>`). */
192
+ collapsed?: boolean;
193
+ }
194
+
195
+ /**
196
+ * Column definition for table widgets.
197
+ *
198
+ * @example
199
+ * ```json
200
+ * { "field": "price", "label": "Price", "format": "currency", "align": "right" }
201
+ * ```
202
+ */
203
+ declare interface UWidgetColumnDefinition {
204
+ /** Data field name to display in this column. */
205
+ field: string;
206
+ /** Display header label. Defaults to the field name. */
207
+ label?: string;
208
+ /** Value formatting hint (e.g., `"currency"`, `"currency:EUR"`, `"percent"`). */
209
+ format?: 'number' | 'currency' | 'percent' | 'date' | 'datetime' | 'bytes';
210
+ /** Text alignment within the column. */
211
+ align?: 'left' | 'center' | 'right';
212
+ }
213
+
214
+ /**
215
+ * Field definition for form/confirm input widgets.
216
+ *
217
+ * @example
218
+ * ```json
219
+ * { "field": "email", "label": "Email", "type": "email", "required": true }
220
+ * ```
221
+ */
222
+ declare interface UWidgetFieldDefinition {
223
+ /** Data field name (maps to `data[field]` for defaults and output). */
224
+ field: string;
225
+ /** Display label. Defaults to the field name. */
226
+ label?: string;
227
+ /** Input type. Defaults to `"text"`. */
228
+ type?: FieldType;
229
+ /** Whether the field must be filled before submit. */
230
+ required?: boolean;
231
+ /** Placeholder text shown when the field is empty. */
232
+ placeholder?: string;
233
+ /** Options for select, multiselect, radio, and checkbox types. */
234
+ options?: string[];
235
+ /** Minimum character length for text inputs. */
236
+ minLength?: number;
237
+ /** Maximum character length for text inputs. */
238
+ maxLength?: number;
239
+ /** Custom regex pattern for validation (e.g. `"^[A-Z]{3}$"`). */
240
+ pattern?: string;
241
+ /** Number of visible rows for textarea type. */
242
+ rows?: number;
243
+ /** Minimum value (number) or date string. */
244
+ min?: number | string;
245
+ /** Maximum value (number) or date string. */
246
+ max?: number | string;
247
+ /** Step increment for number and range inputs. */
248
+ step?: number;
249
+ /** Custom validation error message (overrides locale default). */
250
+ message?: string;
251
+ }
252
+
253
+ /**
254
+ * Mapping connects data fields to visual channels.
255
+ *
256
+ * Which keys are relevant depends on the widget type:
257
+ * - **chart.bar/line/area:** `x`, `y`
258
+ * - **chart.pie/funnel:** `label`, `value`
259
+ * - **chart.scatter:** `x`, `y`, `color`, `size`
260
+ * - **chart.radar:** `axis`, `value`
261
+ * - **table:** `columns`
262
+ * - **list:** `primary`, `secondary`, `avatar`, `icon`, `trailing`
263
+ *
264
+ * When omitted, mapping is auto-inferred from the data shape.
265
+ */
266
+ declare interface UWidgetMapping {
267
+ /** Category axis field (chart x-axis). */
268
+ x?: string;
269
+ /** Value axis field(s). A string for single series, string[] for multi-series. */
270
+ y?: string | string[];
271
+ /** Label field (pie/funnel charts). */
272
+ label?: string;
273
+ /** Value field (pie/funnel/heatmap). */
274
+ value?: string;
275
+ /** Color grouping field (scatter). */
276
+ color?: string;
277
+ /** Size encoding field (scatter bubble). */
278
+ size?: string;
279
+ /** Opacity encoding field (scatter). Maps data values to point opacity (0.1–1.0). */
280
+ opacity?: string;
281
+ /** Axis field (radar chart indicators). */
282
+ axis?: string;
283
+ /** Explicit column definitions for table widgets. */
284
+ columns?: UWidgetColumnDefinition[];
285
+ /** Primary text field (list widget). */
286
+ primary?: string;
287
+ /** Secondary/subtitle text field (list widget). */
288
+ secondary?: string;
289
+ /** Icon letter field (list widget fallback when no avatar). */
290
+ icon?: string;
291
+ /** Avatar image URL field (list widget). */
292
+ avatar?: string;
293
+ /** Trailing value field displayed on the right (list widget). */
294
+ trailing?: string;
295
+ /** Badge/tag field (list widget). */
296
+ badge?: string;
297
+ }
298
+
299
+ /**
300
+ * The u-widget spec envelope — a single, consistent structure for all widgets.
301
+ *
302
+ * Only `widget` is required. All other fields are optional or auto-inferred.
303
+ *
304
+ * @example
305
+ * ```ts
306
+ * const spec: UWidgetSpec = {
307
+ * widget: 'chart.bar',
308
+ * data: [{ name: 'A', value: 30 }, { name: 'B', value: 70 }],
309
+ * mapping: { x: 'name', y: 'value' },
310
+ * };
311
+ * ```
312
+ */
313
+ declare interface UWidgetSpec {
314
+ /** Widget type identifier (e.g., `"chart.bar"`, `"metric"`, `"form"`). */
315
+ widget: string;
316
+ /** Unique identifier for event correlation and compose children. */
317
+ id?: string;
318
+ /** Optional display title rendered above the widget. */
319
+ title?: string;
320
+ /** Optional description text rendered below the title. */
321
+ description?: string;
322
+ /** Inline data — an object (metric/gauge) or array of records (chart/table). */
323
+ data?: Record<string, unknown> | Record<string, unknown>[];
324
+ /** Maps data fields to visual channels. Auto-inferred when omitted. */
325
+ mapping?: UWidgetMapping;
326
+ /** Field definitions for form/confirm widgets. */
327
+ fields?: UWidgetFieldDefinition[];
328
+ /** Formdown shorthand syntax for form fields (mutually exclusive with `fields`). */
329
+ formdown?: string;
330
+ /** Widget-specific rendering options. */
331
+ options?: Record<string, unknown>;
332
+ /** Action buttons displayed below the widget. */
333
+ actions?: UWidgetAction[];
334
+ /** Interchange format type marker. Always `"u-widget"` if present. */
335
+ type?: 'u-widget';
336
+ /** Interchange format version string. */
337
+ version?: string;
338
+ /** Layout mode for compose widget: `"stack"` (default), `"row"`, or `"grid"`. */
339
+ layout?: 'stack' | 'row' | 'grid';
340
+ /** Number of grid columns for compose `"grid"` layout. Default: 2. */
341
+ columns?: number;
342
+ /** Child widget specs for compose widget. */
343
+ children?: UWidgetChildSpec[];
344
+ /** Grid column span for children inside a compose `"grid"` layout. */
345
+ span?: number;
346
+ }
347
+
348
+ /**
349
+ * Well-known data fields per widget type.
350
+ * Charts/table/list use user-defined fields so they are omitted.
351
+ */
352
+ export declare const WIDGET_DATA_FIELDS: Readonly<Record<string, readonly DataFieldInfo[]>>;
353
+
354
+ /** Events emitted per widget category. */
355
+ export declare const WIDGET_EVENTS: Readonly<Record<string, readonly string[]>>;
356
+
357
+ /** Auto-inference hints — tells LLM what can be omitted. */
358
+ export declare const WIDGET_INFERENCE: Readonly<Record<string, string>>;
359
+
360
+ /** Relevant option keys per widget type. Only lists keys from OPTION_DOCS. */
361
+ export declare const WIDGET_OPTIONS: Readonly<Record<string, readonly string[]>>;
362
+
363
+ /** Extended detail returned when `help()` is called with an exact widget name. */
364
+ export declare interface WidgetDetail extends WidgetInfo {
365
+ /** One-line hint telling LLM what can be omitted via auto-inference. */
366
+ autoInference: string;
367
+ /** Well-known data fields (display/content widgets). Empty for user-defined data. */
368
+ dataFields: DataFieldInfo[];
369
+ /** Mapping key descriptions relevant to this widget. */
370
+ mappingDocs: Record<string, string>;
371
+ /** Option key descriptions relevant to this widget. */
372
+ optionDocs: Record<string, string>;
373
+ /** Field definition property docs (form/confirm only). */
374
+ fieldDocs?: Record<string, string>;
375
+ /** Action property docs (form/confirm only). */
376
+ actionDocs?: Record<string, string>;
377
+ /** Event types emitted by this widget. */
378
+ events: readonly string[];
379
+ /** Example specs (minimal template + feature-rich). */
380
+ examples: {
381
+ label: string;
382
+ spec: UWidgetSpec;
383
+ }[];
384
+ }
385
+
386
+ /** Describes a single widget type in the catalog. */
387
+ export declare interface WidgetInfo {
388
+ /** Widget type identifier (e.g., `"chart.bar"`). */
389
+ widget: string;
390
+ /** Human-readable category. */
391
+ category: 'chart' | 'display' | 'input' | 'content' | 'composition';
392
+ /** Short description of the widget's purpose. */
393
+ description: string;
394
+ /** Which mapping keys are relevant for this widget. */
395
+ mappingKeys: string[];
396
+ /** Expected data shape. */
397
+ dataShape: 'object' | 'array' | 'none';
398
+ }
399
+
400
+ export { }