@iyulab/u-widgets 0.4.1 → 0.6.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 +45 -0
- package/dist/themes/shadcn.css +36 -0
- package/dist/u-widgets-charts.d.ts +10 -1
- package/dist/u-widgets-tools.d.ts +10 -1
- package/dist/u-widgets-tools.js +5 -4
- package/dist/u-widgets-tools.js.map +1 -1
- package/dist/u-widgets.d.ts +72 -1
- package/dist/u-widgets.js +734 -677
- package/dist/u-widgets.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# u-widgets
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@iyulab/u-widgets)
|
|
4
|
+
[](https://www.npmjs.com/package/@iyulab/u-widgets-mcp)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](https://www.jsdelivr.com/package/npm/@iyulab/u-widgets)
|
|
7
|
+
|
|
3
8
|
Declarative, data-driven widget system for visualization and input.
|
|
4
9
|
|
|
5
10
|
Define your data. Map it to visual channels. The renderer does the rest.
|
|
@@ -83,6 +88,46 @@ AI assistants can use u-widgets via [MCP server](docs/mcp-server.md):
|
|
|
83
88
|
npx @iyulab/u-widgets-mcp
|
|
84
89
|
```
|
|
85
90
|
|
|
91
|
+
## Framework Integration
|
|
92
|
+
|
|
93
|
+
u-widgets is a browser-only Web Component library — it requires DOM APIs (`customElements`, `HTMLElement`) and cannot run in Node.js or server-side environments.
|
|
94
|
+
|
|
95
|
+
### Next.js (App Router)
|
|
96
|
+
|
|
97
|
+
Create a client-side wrapper component:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
// components/widget.tsx
|
|
101
|
+
"use client";
|
|
102
|
+
import "@iyulab/u-widgets";
|
|
103
|
+
|
|
104
|
+
export function Widget({ spec }: { spec: object }) {
|
|
105
|
+
return <u-widget spec={JSON.stringify(spec)} />;
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Use the wrapper from Server Components:
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
// app/dashboard/page.tsx
|
|
113
|
+
import { Widget } from "@/components/widget";
|
|
114
|
+
|
|
115
|
+
export default async function Page() {
|
|
116
|
+
const data = await fetchData();
|
|
117
|
+
return <Widget spec={{ widget: "stat-group", data }} />;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
For pages where SSR hydration mismatch is a concern, use dynamic import:
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import dynamic from "next/dynamic";
|
|
125
|
+
const Widget = dynamic(
|
|
126
|
+
() => import("@/components/widget").then((m) => m.Widget),
|
|
127
|
+
{ ssr: false }
|
|
128
|
+
);
|
|
129
|
+
```
|
|
130
|
+
|
|
86
131
|
## Documentation
|
|
87
132
|
|
|
88
133
|
- [Widget Reference](docs/widgets.md) — Schema, mapping, options, theming
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* u-widgets Shadcn/ui + Tailwind CSS v4 Theme Preset
|
|
3
|
+
*
|
|
4
|
+
* Usage (CSS/PostCSS):
|
|
5
|
+
* @import "@iyulab/u-widgets/themes/shadcn.css";
|
|
6
|
+
*
|
|
7
|
+
* Or (JavaScript):
|
|
8
|
+
* import "@iyulab/u-widgets/themes/shadcn.css";
|
|
9
|
+
*
|
|
10
|
+
* Apply AFTER your Shadcn globals.css.
|
|
11
|
+
* Requires Shadcn/ui globals.css to define --primary, --background, etc.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
:root {
|
|
15
|
+
--u-widget-bg: hsl(var(--background));
|
|
16
|
+
--u-widget-surface: hsl(var(--muted));
|
|
17
|
+
--u-widget-text: hsl(var(--foreground));
|
|
18
|
+
--u-widget-text-secondary: hsl(var(--muted-foreground));
|
|
19
|
+
--u-widget-border: hsl(var(--border));
|
|
20
|
+
--u-widget-primary: hsl(var(--primary));
|
|
21
|
+
--u-widget-negative: hsl(var(--destructive));
|
|
22
|
+
/* Shadcn does not define --success / --warning; u-widget defaults remain */
|
|
23
|
+
--u-widget-radius: var(--radius, 6px);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* Dark mode: syncs with Shadcn .dark class */
|
|
27
|
+
.dark {
|
|
28
|
+
--u-widget-bg: hsl(var(--background));
|
|
29
|
+
--u-widget-surface: hsl(var(--muted));
|
|
30
|
+
--u-widget-text: hsl(var(--foreground));
|
|
31
|
+
--u-widget-text-secondary: hsl(var(--muted-foreground));
|
|
32
|
+
--u-widget-border: hsl(var(--border));
|
|
33
|
+
--u-widget-primary: hsl(var(--primary));
|
|
34
|
+
--u-widget-negative: hsl(var(--destructive));
|
|
35
|
+
--u-widget-radius: var(--radius, 6px);
|
|
36
|
+
}
|
|
@@ -206,7 +206,16 @@ declare interface UWidgetSpec {
|
|
|
206
206
|
fields?: UWidgetFieldDefinition[];
|
|
207
207
|
/** Formdown shorthand syntax for form fields (mutually exclusive with `fields`). */
|
|
208
208
|
formdown?: string;
|
|
209
|
-
/**
|
|
209
|
+
/**
|
|
210
|
+
* Widget-specific rendering options.
|
|
211
|
+
*
|
|
212
|
+
* Chart widgets support an `echarts` sub-key for native ECharts option passthrough:
|
|
213
|
+
* ```json
|
|
214
|
+
* { "options": { "echarts": { "tooltip": { "trigger": "axis" } } } }
|
|
215
|
+
* ```
|
|
216
|
+
* All keys in `options.echarts` are deep-merged into the generated ECharts option.
|
|
217
|
+
* @see https://echarts.apache.org/en/option.html
|
|
218
|
+
*/
|
|
210
219
|
options?: Record<string, unknown>;
|
|
211
220
|
/** Action buttons displayed below the widget. */
|
|
212
221
|
actions?: UWidgetAction[];
|
|
@@ -327,7 +327,16 @@ declare interface UWidgetSpec {
|
|
|
327
327
|
fields?: UWidgetFieldDefinition[];
|
|
328
328
|
/** Formdown shorthand syntax for form fields (mutually exclusive with `fields`). */
|
|
329
329
|
formdown?: string;
|
|
330
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
* Widget-specific rendering options.
|
|
332
|
+
*
|
|
333
|
+
* Chart widgets support an `echarts` sub-key for native ECharts option passthrough:
|
|
334
|
+
* ```json
|
|
335
|
+
* { "options": { "echarts": { "tooltip": { "trigger": "axis" } } } }
|
|
336
|
+
* ```
|
|
337
|
+
* All keys in `options.echarts` are deep-merged into the generated ECharts option.
|
|
338
|
+
* @see https://echarts.apache.org/en/option.html
|
|
339
|
+
*/
|
|
331
340
|
options?: Record<string, unknown>;
|
|
332
341
|
/** Action buttons displayed below the widget. */
|
|
333
342
|
actions?: UWidgetAction[];
|
package/dist/u-widgets-tools.js
CHANGED
|
@@ -6,6 +6,7 @@ const v = {
|
|
|
6
6
|
value: "Value field (pie/funnel/heatmap)",
|
|
7
7
|
color: "Color grouping field (scatter)",
|
|
8
8
|
size: "Size encoding field (scatter bubble)",
|
|
9
|
+
opacity: "Opacity encoding field (scatter bubble)",
|
|
9
10
|
axis: "Axis field (radar indicators)",
|
|
10
11
|
columns: "Column definitions (table)",
|
|
11
12
|
primary: "Primary text field (list)",
|
|
@@ -336,7 +337,7 @@ const y = [
|
|
|
336
337
|
// Composition
|
|
337
338
|
{ widget: "compose", category: "composition", description: "Combine multiple widgets with layout hints", mappingKeys: [], dataShape: "none" }
|
|
338
339
|
];
|
|
339
|
-
function
|
|
340
|
+
function O(e) {
|
|
340
341
|
if (!e) return [...y];
|
|
341
342
|
const i = y.find((o) => o.widget === e);
|
|
342
343
|
if (i) return T(i);
|
|
@@ -1130,7 +1131,7 @@ function T(e) {
|
|
|
1130
1131
|
examples: s
|
|
1131
1132
|
};
|
|
1132
1133
|
}
|
|
1133
|
-
function
|
|
1134
|
+
function E(e) {
|
|
1134
1135
|
const i = A[e];
|
|
1135
1136
|
if (i)
|
|
1136
1137
|
return JSON.parse(JSON.stringify(i));
|
|
@@ -1364,9 +1365,9 @@ export {
|
|
|
1364
1365
|
N as WIDGET_OPTIONS,
|
|
1365
1366
|
j as autoSpec,
|
|
1366
1367
|
S as getWidgetEvents,
|
|
1367
|
-
|
|
1368
|
+
O as help,
|
|
1368
1369
|
I as specSurface,
|
|
1369
1370
|
q as suggestMapping,
|
|
1370
|
-
|
|
1371
|
+
E as template
|
|
1371
1372
|
};
|
|
1372
1373
|
//# sourceMappingURL=u-widgets-tools.js.map
|