@iyulab/u-widgets 0.7.1 → 0.8.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.
@@ -15,7 +15,7 @@ const v = {
15
15
  avatar: "Avatar image URL field (list)",
16
16
  trailing: "Trailing value field (list)",
17
17
  badge: "Badge/tag field (list)"
18
- }, k = {
18
+ }, S = {
19
19
  field: "Key name in submitted data",
20
20
  label: "Display label",
21
21
  type: "Input type",
@@ -87,8 +87,11 @@ const v = {
87
87
  colors: "Custom color palette",
88
88
  colorRange: "Heatmap color gradient",
89
89
  histogram: "Histogram mode (bar)",
90
+ bins: "Number of histogram bins (auto: Sturges rule)",
90
91
  referenceLines: "Reference/threshold lines",
91
92
  series: "Per-series overrides [{color?, lineStyle?, symbol?, label?}]",
93
+ conditionalStyles: "Per-point conditional styling rules [{field, above?, below?, color, symbol?, symbolSize?}]",
94
+ subtitle: "Static subtitle text (gauge)",
92
95
  step: "Step interpolation (line)",
93
96
  legend: "Show/hide legend",
94
97
  grid: "Show/hide grid lines",
@@ -129,20 +132,21 @@ const v = {
129
132
  disabled: "Whether disabled",
130
133
  url: "URL for navigate action"
131
134
  }, N = {
132
- "chart.bar": ["stack", "horizontal", "histogram", "colors", "series", "referenceLines", "legend", "grid", "animate", "showLabel"],
133
- "chart.line": ["smooth", "stack", "step", "colors", "series", "referenceLines", "legend", "grid", "animate", "showLabel"],
134
- "chart.area": ["smooth", "stack", "colors", "series", "legend", "grid", "animate", "showLabel"],
135
+ "chart.bar": ["stack", "horizontal", "histogram", "colors", "series", "referenceLines", "conditionalStyles", "legend", "grid", "animate", "showLabel"],
136
+ "chart.line": ["smooth", "stack", "step", "colors", "series", "referenceLines", "conditionalStyles", "legend", "grid", "animate", "showLabel"],
137
+ "chart.area": ["smooth", "stack", "colors", "series", "conditionalStyles", "legend", "grid", "animate", "showLabel"],
135
138
  "chart.pie": ["donut", "colors", "legend", "animate", "showLabel"],
136
- "chart.scatter": ["colors", "legend", "grid", "animate", "showLabel"],
139
+ "chart.scatter": ["colors", "referenceLines", "conditionalStyles", "legend", "grid", "animate", "showLabel"],
137
140
  "chart.radar": ["colors", "legend", "animate", "showLabel"],
138
141
  "chart.heatmap": ["colorRange", "legend", "grid", "animate", "showLabel"],
139
142
  "chart.box": ["colors", "legend", "grid", "animate"],
140
143
  "chart.funnel": ["colors", "legend", "animate", "showLabel"],
141
144
  "chart.waterfall": ["colors", "legend", "grid", "animate", "showLabel"],
142
145
  "chart.treemap": ["colors", "animate", "showLabel"],
146
+ "chart.histogram": ["bins", "colors", "referenceLines", "legend", "grid", "animate"],
143
147
  metric: [],
144
148
  "stat-group": [],
145
- gauge: ["min", "max", "unit", "thresholds", "label"],
149
+ gauge: ["min", "max", "unit", "thresholds", "label", "subtitle"],
146
150
  progress: ["min", "max", "unit", "thresholds", "label"],
147
151
  table: ["pageSize", "compact", "searchable"],
148
152
  list: ["compact"],
@@ -163,7 +167,7 @@ const v = {
163
167
  actions: ["layout"],
164
168
  divider: [],
165
169
  header: []
166
- }, M = {
170
+ }, P = {
167
171
  metric: [
168
172
  { key: "value", type: "number | string", desc: "Primary value", required: !0 },
169
173
  { key: "label", type: "string", desc: "Display label" },
@@ -247,7 +251,7 @@ const v = {
247
251
  { key: "value", type: "string", desc: "Status value", required: !0 },
248
252
  { key: "level", type: '"info" | "success" | "warning" | "error" | "neutral"', desc: "Severity level (default info)" }
249
253
  ]
250
- }, P = {
254
+ }, M = {
251
255
  "chart.bar": "mapping omittable. First string → x, number fields → y.",
252
256
  "chart.line": "mapping omittable. First string → x, numbers → y. Date-like preferred for x.",
253
257
  "chart.area": "mapping omittable. Same as line — first string → x, numbers → y.",
@@ -259,6 +263,7 @@ const v = {
259
263
  "chart.funnel": "mapping omittable. First string → label, first number → value.",
260
264
  "chart.waterfall": "mapping omittable. First string → x, first number → y.",
261
265
  "chart.treemap": "No mapping. data is [{name, value, children?}].",
266
+ "chart.histogram": "Flat number[] or objects with single numeric field → frequency distribution",
262
267
  metric: "No mapping needed. data is {value, label?, unit?, change?, trend?}.",
263
268
  "stat-group": "No mapping needed. data is [{label, value, ...}]. Optional: icon (emoji), description (sub-label).",
264
269
  gauge: "No mapping needed. data is {value}. Set min/max/unit in options.",
@@ -292,7 +297,7 @@ const v = {
292
297
  rating: ["submit"],
293
298
  actions: ["action"]
294
299
  };
295
- function S(e) {
300
+ function k(e) {
296
301
  return x[e] ?? x[e.split(".")[0]] ?? [];
297
302
  }
298
303
  const y = [
@@ -309,6 +314,7 @@ const y = [
309
314
  { widget: "chart.funnel", category: "chart", description: "Funnel chart for sequential stages", mappingKeys: ["label", "value"], dataShape: "array" },
310
315
  { widget: "chart.waterfall", category: "chart", description: "Waterfall chart for cumulative values", mappingKeys: ["x", "y"], dataShape: "array" },
311
316
  { widget: "chart.treemap", category: "chart", description: "Treemap for hierarchical data", mappingKeys: [], dataShape: "array" },
317
+ { widget: "chart.histogram", category: "chart", description: "Histogram for frequency distribution with auto-binning", mappingKeys: ["value"], dataShape: "array" },
312
318
  // Display
313
319
  { widget: "metric", category: "display", description: "Single KPI value with optional trend", mappingKeys: [], dataShape: "object" },
314
320
  { widget: "stat-group", category: "display", description: "Multiple KPI values in a row", mappingKeys: [], dataShape: "array" },
@@ -338,12 +344,12 @@ const y = [
338
344
  // Composition
339
345
  { widget: "compose", category: "composition", description: "Combine multiple widgets with layout hints", mappingKeys: [], dataShape: "none" }
340
346
  ];
341
- function O(e) {
347
+ function E(e) {
342
348
  if (!e) return [...y];
343
349
  const i = y.find((o) => o.widget === e);
344
- if (i) return T(i);
345
- const p = y.filter((o) => o.category === e);
346
- return p.length > 0 ? p : y.filter((o) => o.widget.startsWith(e));
350
+ if (i) return K(i);
351
+ const d = y.filter((o) => o.category === e);
352
+ return d.length > 0 ? d : y.filter((o) => o.widget.startsWith(e));
347
353
  }
348
354
  const A = {
349
355
  "chart.bar": {
@@ -405,6 +411,10 @@ const A = {
405
411
  widget: "chart.treemap",
406
412
  data: [{ name: "Group A", value: 100 }, { name: "Group B", value: 80 }]
407
413
  },
414
+ "chart.histogram": {
415
+ widget: "chart.histogram",
416
+ data: [12, 15, 22, 28, 35, 42, 48, 55, 62, 68, 72, 78]
417
+ },
408
418
  metric: {
409
419
  widget: "metric",
410
420
  data: { value: 1284, unit: "users", change: 12.5, trend: "up" }
@@ -542,7 +552,7 @@ console.log(x);`, language: "javascript" }
542
552
  { widget: "metric", data: { value: 95, unit: "%" } }
543
553
  ]
544
554
  }
545
- }, R = {
555
+ }, q = {
546
556
  "chart.bar": [
547
557
  {
548
558
  label: "Stacked multi-series",
@@ -699,6 +709,21 @@ console.log(x);`, language: "javascript" }
699
709
  }
700
710
  }
701
711
  ],
712
+ "chart.histogram": [
713
+ {
714
+ label: "Custom bins + referenceLines",
715
+ spec: {
716
+ widget: "chart.histogram",
717
+ data: [10, 15, 20, 22, 25, 30, 35, 40, 42, 45, 50, 55, 60, 65, 70, 75],
718
+ options: {
719
+ bins: 5,
720
+ referenceLines: [
721
+ { axis: "y", value: 4, label: "Expected", color: "#6366f1", style: "dashed" }
722
+ ]
723
+ }
724
+ }
725
+ }
726
+ ],
702
727
  "chart.treemap": [
703
728
  {
704
729
  label: "Nested hierarchy",
@@ -1107,43 +1132,43 @@ LIMIT 10;`,
1107
1132
  }
1108
1133
  ]
1109
1134
  };
1110
- function T(e) {
1111
- const i = e.widget, p = {};
1135
+ function K(e) {
1136
+ const i = e.widget, d = {};
1112
1137
  for (const a of e.mappingKeys)
1113
- v[a] && (p[a] = v[a]);
1114
- const d = {};
1138
+ v[a] && (d[a] = v[a]);
1139
+ const p = {};
1115
1140
  for (const a of N[i] ?? [])
1116
- w[a] && (d[a] = w[a]);
1117
- const o = i === "form" || i === "confirm", s = [], n = A[i];
1118
- n && s.push({ label: "Minimal", spec: JSON.parse(JSON.stringify(n)) });
1119
- const r = R[i];
1141
+ w[a] && (p[a] = w[a]);
1142
+ const o = i === "form" || i === "confirm", l = [], n = A[i];
1143
+ n && l.push({ label: "Minimal", spec: JSON.parse(JSON.stringify(n)) });
1144
+ const r = q[i];
1120
1145
  if (r)
1121
1146
  for (const a of r)
1122
- s.push({ label: a.label, spec: JSON.parse(JSON.stringify(a.spec)) });
1147
+ l.push({ label: a.label, spec: JSON.parse(JSON.stringify(a.spec)) });
1123
1148
  return {
1124
1149
  ...e,
1125
- autoInference: P[i] ?? "",
1126
- dataFields: [...M[i] ?? []],
1127
- mappingDocs: p,
1128
- optionDocs: d,
1129
- ...o ? { fieldDocs: { ...k } } : {},
1150
+ autoInference: M[i] ?? "",
1151
+ dataFields: [...P[i] ?? []],
1152
+ mappingDocs: d,
1153
+ optionDocs: p,
1154
+ ...o ? { fieldDocs: { ...S } } : {},
1130
1155
  ...o ? { actionDocs: { ...L } } : {},
1131
- events: S(i),
1132
- examples: s
1156
+ events: k(i),
1157
+ examples: l
1133
1158
  };
1134
1159
  }
1135
- function E(e) {
1160
+ function O(e) {
1136
1161
  const i = A[e];
1137
1162
  if (i)
1138
1163
  return JSON.parse(JSON.stringify(i));
1139
1164
  }
1140
- function q(e, i) {
1165
+ function R(e, i) {
1141
1166
  if (e == null) return [];
1142
- const p = Array.isArray(e) ? e : [e];
1143
- if (p.length === 0) return [];
1144
- const d = p[0], o = Object.keys(d);
1167
+ const d = Array.isArray(e) ? e : [e];
1168
+ if (d.length === 0) return [];
1169
+ const p = d[0], o = Object.keys(p);
1145
1170
  if (o.length === 0) return [];
1146
- const s = o.filter((t) => typeof d[t] == "string"), n = o.filter((t) => typeof d[t] == "number"), r = Array.isArray(e);
1171
+ const l = o.filter((t) => typeof p[t] == "string"), n = o.filter((t) => typeof p[t] == "number"), r = Array.isArray(e);
1147
1172
  if (i) {
1148
1173
  const t = g(i, e);
1149
1174
  return t ? [{ widget: i, mapping: t, confidence: 0.8, reason: `Auto-inferred mapping for ${i}` }] : [{ widget: i, confidence: 0.3, reason: `No mapping could be inferred for ${i} from this data shape` }];
@@ -1154,7 +1179,7 @@ function q(e, i) {
1154
1179
  confidence: 0.95,
1155
1180
  reason: 'Object data with "value" key is ideal for a metric widget'
1156
1181
  }), !r && !n.includes("value") && o.length >= 2 && o.every((m) => {
1157
- const c = d[m];
1182
+ const c = p[m];
1158
1183
  return typeof c == "string" || typeof c == "number" || typeof c == "boolean";
1159
1184
  }) && a.push({
1160
1185
  widget: "kv",
@@ -1164,7 +1189,7 @@ function q(e, i) {
1164
1189
  widget: "kv",
1165
1190
  confidence: 0.88,
1166
1191
  reason: 'Array with "key" and "value" fields matches key-value pair pattern'
1167
- }), r && s.length >= 1 && n.length >= 1) {
1192
+ }), r && l.length >= 1 && n.length >= 1) {
1168
1193
  const t = g("chart.bar", e);
1169
1194
  a.push({
1170
1195
  widget: "chart.bar",
@@ -1173,7 +1198,7 @@ function q(e, i) {
1173
1198
  reason: "Category × value pattern detected"
1174
1199
  });
1175
1200
  }
1176
- if (r && s.length >= 1 && n.length >= 2) {
1201
+ if (r && l.length >= 1 && n.length >= 2) {
1177
1202
  const t = g("chart.line", e);
1178
1203
  a.push({
1179
1204
  widget: "chart.line",
@@ -1182,7 +1207,7 @@ function q(e, i) {
1182
1207
  reason: "Category × multiple values pattern detected (multi-series)"
1183
1208
  });
1184
1209
  }
1185
- if (r && s.length >= 1 && n.length >= 1 && s.some((m) => D(String(p[0][m])))) {
1210
+ if (r && l.length >= 1 && n.length >= 1 && l.some((m) => D(String(d[0][m])))) {
1186
1211
  const m = g("chart.area", e);
1187
1212
  a.push({
1188
1213
  widget: "chart.area",
@@ -1191,7 +1216,7 @@ function q(e, i) {
1191
1216
  reason: "Date-like category field detected — suitable for time-series area chart"
1192
1217
  });
1193
1218
  }
1194
- if (r && s.length >= 1 && n.length === 1) {
1219
+ if (r && l.length >= 1 && n.length === 1) {
1195
1220
  const t = g("chart.pie", e);
1196
1221
  a.push({
1197
1222
  widget: "chart.pie",
@@ -1200,7 +1225,7 @@ function q(e, i) {
1200
1225
  reason: "Label + value pattern could work as proportions"
1201
1226
  });
1202
1227
  }
1203
- if (r && n.length >= 2 && s.length === 0) {
1228
+ if (r && n.length >= 2 && l.length === 0) {
1204
1229
  const t = g("chart.scatter", e);
1205
1230
  a.push({
1206
1231
  widget: "chart.scatter",
@@ -1214,7 +1239,7 @@ function q(e, i) {
1214
1239
  mapping: g("table", e),
1215
1240
  confidence: 0.75,
1216
1241
  reason: "Multi-field array renders well as a table"
1217
- }), r && s.length >= 1) {
1242
+ }), r && l.length >= 1) {
1218
1243
  const t = g("list", e);
1219
1244
  a.push({
1220
1245
  widget: "list",
@@ -1231,7 +1256,7 @@ function q(e, i) {
1231
1256
  widget: "gauge",
1232
1257
  confidence: 0.7,
1233
1258
  reason: 'Object with "value" can display as a gauge'
1234
- }), r && s.length >= 1 && n.length >= 2) {
1259
+ }), r && l.length >= 1 && n.length >= 2) {
1235
1260
  const t = g("chart.radar", e);
1236
1261
  t && a.push({
1237
1262
  widget: "chart.radar",
@@ -1240,7 +1265,7 @@ function q(e, i) {
1240
1265
  reason: "Category × multiple values can display as a radar chart"
1241
1266
  });
1242
1267
  }
1243
- if (r && s.length >= 2 && n.length >= 1) {
1268
+ if (r && l.length >= 2 && n.length >= 1) {
1244
1269
  const t = g("chart.heatmap", e);
1245
1270
  t && a.push({
1246
1271
  widget: "chart.heatmap",
@@ -1258,7 +1283,7 @@ function q(e, i) {
1258
1283
  reason: "Five or more numeric fields fit a box plot (min/q1/median/q3/max)"
1259
1284
  });
1260
1285
  }
1261
- if (r && s.length >= 1 && n.length === 1) {
1286
+ if (r && l.length >= 1 && n.length === 1) {
1262
1287
  const t = g("chart.funnel", e);
1263
1288
  t && a.push({
1264
1289
  widget: "chart.funnel",
@@ -1267,7 +1292,7 @@ function q(e, i) {
1267
1292
  reason: "Label + value pattern can display as a funnel"
1268
1293
  });
1269
1294
  }
1270
- if (r && s.length >= 1 && n.length >= 1) {
1295
+ if (r && l.length >= 1 && n.length >= 1) {
1271
1296
  const t = g("chart.waterfall", e);
1272
1297
  t && a.push({
1273
1298
  widget: "chart.waterfall",
@@ -1276,7 +1301,7 @@ function q(e, i) {
1276
1301
  reason: "Category × value pattern can display as a waterfall chart"
1277
1302
  });
1278
1303
  }
1279
- if (r && s.length >= 1 && n.length >= 1) {
1304
+ if (r && l.length >= 1 && n.length >= 1) {
1280
1305
  const t = g("chart.treemap", e);
1281
1306
  t && a.push({
1282
1307
  widget: "chart.treemap",
@@ -1292,12 +1317,12 @@ function q(e, i) {
1292
1317
  }), a.sort((t, m) => m.confidence - t.confidence), a;
1293
1318
  }
1294
1319
  function j(e) {
1295
- const i = q(e);
1320
+ const i = R(e);
1296
1321
  if (i.length === 0) return;
1297
- const p = i[0];
1298
- if (p.confidence < 0.7) return;
1299
- const d = { widget: p.widget, data: e };
1300
- return p.mapping && (d.mapping = p.mapping), d;
1322
+ const d = i[0];
1323
+ if (d.confidence < 0.7) return;
1324
+ const p = { widget: d.widget, data: e };
1325
+ return d.mapping && (p.mapping = d.mapping), p;
1301
1326
  }
1302
1327
  function b(e) {
1303
1328
  if (e == null) return "null";
@@ -1309,66 +1334,66 @@ function b(e) {
1309
1334
  return typeof e;
1310
1335
  }
1311
1336
  function I(e, i) {
1312
- const p = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
1337
+ const d = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
1313
1338
  for (const m of e) {
1314
1339
  const c = m;
1315
- for (const l of Object.keys(c))
1316
- l !== "widget" && p.add(l);
1340
+ for (const s of Object.keys(c))
1341
+ s !== "widget" && d.add(s);
1317
1342
  const h = c.data;
1318
1343
  if (Array.isArray(h)) {
1319
- for (const l of h)
1320
- if (l && typeof l == "object")
1321
- for (const [u, f] of Object.entries(l))
1322
- d.set(u, b(f));
1344
+ for (const s of h)
1345
+ if (s && typeof s == "object")
1346
+ for (const [u, f] of Object.entries(s))
1347
+ p.set(u, b(f));
1323
1348
  } else if (h && typeof h == "object")
1324
- for (const [l, u] of Object.entries(h))
1325
- d.set(l, b(u));
1349
+ for (const [s, u] of Object.entries(h))
1350
+ p.set(s, b(u));
1326
1351
  if (c.mapping && typeof c.mapping == "object")
1327
- for (const [l, u] of Object.entries(c.mapping))
1328
- o.set(l, Array.isArray(u) ? "string[]" : typeof u);
1352
+ for (const [s, u] of Object.entries(c.mapping))
1353
+ o.set(s, Array.isArray(u) ? "string[]" : typeof u);
1329
1354
  if (c.options && typeof c.options == "object")
1330
- for (const [l, u] of Object.entries(c.options))
1331
- s.set(l, b(u));
1355
+ for (const [s, u] of Object.entries(c.options))
1356
+ l.set(s, b(u));
1332
1357
  if (Array.isArray(c.fields))
1333
- for (const l of c.fields) {
1334
- for (const [u, f] of Object.entries(l))
1358
+ for (const s of c.fields) {
1359
+ for (const [u, f] of Object.entries(s))
1335
1360
  n.set(u, u === "options" ? "string[]" : b(f));
1336
- typeof l.type == "string" && r.add(l.type);
1361
+ typeof s.type == "string" && r.add(s.type);
1337
1362
  }
1338
1363
  if (Array.isArray(c.actions))
1339
- for (const l of c.actions)
1340
- typeof l.style == "string" && a.add(l.style);
1364
+ for (const s of c.actions)
1365
+ typeof s.style == "string" && a.add(s.style);
1341
1366
  }
1342
- const t = (m, c) => [...m.entries()].map(([h, l]) => {
1367
+ const t = (m, c) => [...m.entries()].map(([h, s]) => {
1343
1368
  const u = c[h];
1344
- return u ? { key: h, type: l, desc: u } : { key: h, type: l };
1369
+ return u ? { key: h, type: s, desc: u } : { key: h, type: s };
1345
1370
  });
1346
1371
  return {
1347
- specKeys: [...p],
1348
- dataFields: t(d, C),
1372
+ specKeys: [...d],
1373
+ dataFields: t(p, C),
1349
1374
  mappingKeys: t(o, v),
1350
- optionKeys: t(s, w),
1351
- fieldProps: t(n, k),
1375
+ optionKeys: t(l, w),
1376
+ fieldProps: t(n, S),
1352
1377
  fieldTypes: [...r],
1353
1378
  actionStyles: [...a],
1354
- events: i ? S(i) : []
1379
+ events: i ? k(i) : []
1355
1380
  };
1356
1381
  }
1357
1382
  export {
1358
1383
  L as ACTION_PROP_DOCS,
1359
1384
  C as DATA_FIELD_DOCS,
1360
- k as FIELD_PROP_DOCS,
1385
+ S as FIELD_PROP_DOCS,
1361
1386
  v as MAPPING_DOCS,
1362
1387
  w as OPTION_DOCS,
1363
- M as WIDGET_DATA_FIELDS,
1388
+ P as WIDGET_DATA_FIELDS,
1364
1389
  x as WIDGET_EVENTS,
1365
- P as WIDGET_INFERENCE,
1390
+ M as WIDGET_INFERENCE,
1366
1391
  N as WIDGET_OPTIONS,
1367
1392
  j as autoSpec,
1368
- S as getWidgetEvents,
1369
- O as help,
1393
+ k as getWidgetEvents,
1394
+ E as help,
1370
1395
  I as specSurface,
1371
- q as suggestMapping,
1372
- E as template
1396
+ R as suggestMapping,
1397
+ O as template
1373
1398
  };
1374
1399
  //# sourceMappingURL=u-widgets-tools.js.map