@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,227 @@
1
+ import { CSSResult } from 'lit';
2
+ import { LitElement } from 'lit';
3
+ import { nothing } from 'lit';
4
+ import { TemplateResult } from 'lit-html';
5
+
6
+ /** Supported input field types for form widgets. */
7
+ declare type FieldType = 'text' | 'email' | 'password' | 'tel' | 'url' | 'textarea' | 'number' | 'select' | 'multiselect' | 'date' | 'datetime' | 'time' | 'toggle' | 'range' | 'radio' | 'checkbox';
8
+
9
+ /**
10
+ * Translate a u-widget spec into an ECharts option object.
11
+ * This is a pure function with no DOM or ECharts dependency.
12
+ *
13
+ * Supports `options.echarts` passthrough: any key-value pairs in
14
+ * `options.echarts` are deep-merged (one level) into the generated
15
+ * ECharts option, allowing full customization.
16
+ */
17
+ export declare function toEChartsOption(spec: UWidgetSpec): Record<string, unknown>;
18
+
19
+ export declare class UChart extends LitElement {
20
+ static styles: CSSResult[];
21
+ spec: UWidgetSpec | null;
22
+ private _chart;
23
+ private _container;
24
+ private _resizeObserver;
25
+ render(): typeof nothing | TemplateResult<1>;
26
+ protected firstUpdated(): void;
27
+ protected updated(changed: Map<string, unknown>): void;
28
+ private _initChart;
29
+ private _onChartClick;
30
+ private _updateChart;
31
+ private _applyThemeStyle;
32
+ private _readThemeColors;
33
+ private _readCSSVar;
34
+ disconnectedCallback(): void;
35
+ /** Resize the chart (call when container size changes). */
36
+ resize(): void;
37
+ }
38
+
39
+ /**
40
+ * Action button definition.
41
+ *
42
+ * Reserved actions: `"submit"`, `"cancel"`, `"navigate"`.
43
+ * Custom action strings are forwarded to the host via the `u-widget-event`.
44
+ *
45
+ * @example
46
+ * ```json
47
+ * { "label": "Submit", "action": "submit", "style": "primary" }
48
+ * ```
49
+ */
50
+ declare interface UWidgetAction {
51
+ /** Button display text. */
52
+ label: string;
53
+ /** Action identifier emitted in the widget event. */
54
+ action: string;
55
+ /** Visual style hint. */
56
+ style?: 'primary' | 'danger' | 'default';
57
+ /** Whether the button is disabled. */
58
+ disabled?: boolean;
59
+ /** URL for `"navigate"` actions. */
60
+ url?: string;
61
+ }
62
+
63
+ /**
64
+ * Child widget spec inside a compose widget.
65
+ * Inherits `type` and `version` from the parent — no need to repeat them.
66
+ */
67
+ declare interface UWidgetChildSpec extends Omit<UWidgetSpec, 'type' | 'version'> {
68
+ /** Grid column span within the parent compose layout. */
69
+ span?: number;
70
+ /** When true, the child is initially collapsed (uses native `<details>`). */
71
+ collapsed?: boolean;
72
+ }
73
+
74
+ /**
75
+ * Column definition for table widgets.
76
+ *
77
+ * @example
78
+ * ```json
79
+ * { "field": "price", "label": "Price", "format": "currency", "align": "right" }
80
+ * ```
81
+ */
82
+ declare interface UWidgetColumnDefinition {
83
+ /** Data field name to display in this column. */
84
+ field: string;
85
+ /** Display header label. Defaults to the field name. */
86
+ label?: string;
87
+ /** Value formatting hint (e.g., `"currency"`, `"currency:EUR"`, `"percent"`). */
88
+ format?: 'number' | 'currency' | 'percent' | 'date' | 'datetime' | 'bytes';
89
+ /** Text alignment within the column. */
90
+ align?: 'left' | 'center' | 'right';
91
+ }
92
+
93
+ /**
94
+ * Field definition for form/confirm input widgets.
95
+ *
96
+ * @example
97
+ * ```json
98
+ * { "field": "email", "label": "Email", "type": "email", "required": true }
99
+ * ```
100
+ */
101
+ declare interface UWidgetFieldDefinition {
102
+ /** Data field name (maps to `data[field]` for defaults and output). */
103
+ field: string;
104
+ /** Display label. Defaults to the field name. */
105
+ label?: string;
106
+ /** Input type. Defaults to `"text"`. */
107
+ type?: FieldType;
108
+ /** Whether the field must be filled before submit. */
109
+ required?: boolean;
110
+ /** Placeholder text shown when the field is empty. */
111
+ placeholder?: string;
112
+ /** Options for select, multiselect, radio, and checkbox types. */
113
+ options?: string[];
114
+ /** Minimum character length for text inputs. */
115
+ minLength?: number;
116
+ /** Maximum character length for text inputs. */
117
+ maxLength?: number;
118
+ /** Custom regex pattern for validation (e.g. `"^[A-Z]{3}$"`). */
119
+ pattern?: string;
120
+ /** Number of visible rows for textarea type. */
121
+ rows?: number;
122
+ /** Minimum value (number) or date string. */
123
+ min?: number | string;
124
+ /** Maximum value (number) or date string. */
125
+ max?: number | string;
126
+ /** Step increment for number and range inputs. */
127
+ step?: number;
128
+ /** Custom validation error message (overrides locale default). */
129
+ message?: string;
130
+ }
131
+
132
+ /**
133
+ * Mapping connects data fields to visual channels.
134
+ *
135
+ * Which keys are relevant depends on the widget type:
136
+ * - **chart.bar/line/area:** `x`, `y`
137
+ * - **chart.pie/funnel:** `label`, `value`
138
+ * - **chart.scatter:** `x`, `y`, `color`, `size`
139
+ * - **chart.radar:** `axis`, `value`
140
+ * - **table:** `columns`
141
+ * - **list:** `primary`, `secondary`, `avatar`, `icon`, `trailing`
142
+ *
143
+ * When omitted, mapping is auto-inferred from the data shape.
144
+ */
145
+ declare interface UWidgetMapping {
146
+ /** Category axis field (chart x-axis). */
147
+ x?: string;
148
+ /** Value axis field(s). A string for single series, string[] for multi-series. */
149
+ y?: string | string[];
150
+ /** Label field (pie/funnel charts). */
151
+ label?: string;
152
+ /** Value field (pie/funnel/heatmap). */
153
+ value?: string;
154
+ /** Color grouping field (scatter). */
155
+ color?: string;
156
+ /** Size encoding field (scatter bubble). */
157
+ size?: string;
158
+ /** Opacity encoding field (scatter). Maps data values to point opacity (0.1–1.0). */
159
+ opacity?: string;
160
+ /** Axis field (radar chart indicators). */
161
+ axis?: string;
162
+ /** Explicit column definitions for table widgets. */
163
+ columns?: UWidgetColumnDefinition[];
164
+ /** Primary text field (list widget). */
165
+ primary?: string;
166
+ /** Secondary/subtitle text field (list widget). */
167
+ secondary?: string;
168
+ /** Icon letter field (list widget fallback when no avatar). */
169
+ icon?: string;
170
+ /** Avatar image URL field (list widget). */
171
+ avatar?: string;
172
+ /** Trailing value field displayed on the right (list widget). */
173
+ trailing?: string;
174
+ /** Badge/tag field (list widget). */
175
+ badge?: string;
176
+ }
177
+
178
+ /**
179
+ * The u-widget spec envelope — a single, consistent structure for all widgets.
180
+ *
181
+ * Only `widget` is required. All other fields are optional or auto-inferred.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const spec: UWidgetSpec = {
186
+ * widget: 'chart.bar',
187
+ * data: [{ name: 'A', value: 30 }, { name: 'B', value: 70 }],
188
+ * mapping: { x: 'name', y: 'value' },
189
+ * };
190
+ * ```
191
+ */
192
+ declare interface UWidgetSpec {
193
+ /** Widget type identifier (e.g., `"chart.bar"`, `"metric"`, `"form"`). */
194
+ widget: string;
195
+ /** Unique identifier for event correlation and compose children. */
196
+ id?: string;
197
+ /** Optional display title rendered above the widget. */
198
+ title?: string;
199
+ /** Optional description text rendered below the title. */
200
+ description?: string;
201
+ /** Inline data — an object (metric/gauge) or array of records (chart/table). */
202
+ data?: Record<string, unknown> | Record<string, unknown>[];
203
+ /** Maps data fields to visual channels. Auto-inferred when omitted. */
204
+ mapping?: UWidgetMapping;
205
+ /** Field definitions for form/confirm widgets. */
206
+ fields?: UWidgetFieldDefinition[];
207
+ /** Formdown shorthand syntax for form fields (mutually exclusive with `fields`). */
208
+ formdown?: string;
209
+ /** Widget-specific rendering options. */
210
+ options?: Record<string, unknown>;
211
+ /** Action buttons displayed below the widget. */
212
+ actions?: UWidgetAction[];
213
+ /** Interchange format type marker. Always `"u-widget"` if present. */
214
+ type?: 'u-widget';
215
+ /** Interchange format version string. */
216
+ version?: string;
217
+ /** Layout mode for compose widget: `"stack"` (default), `"row"`, or `"grid"`. */
218
+ layout?: 'stack' | 'row' | 'grid';
219
+ /** Number of grid columns for compose `"grid"` layout. Default: 2. */
220
+ columns?: number;
221
+ /** Child widget specs for compose widget. */
222
+ children?: UWidgetChildSpec[];
223
+ /** Grid column span for children inside a compose `"grid"` layout. */
224
+ span?: number;
225
+ }
226
+
227
+ export { }