@dashspec/renderer 0.1.9 → 0.1.11

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/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  BUILT_IN_DATASOURCE_TYPES,
11
11
  BarChartContract,
12
12
  BreakdownContract,
13
+ ButtonContract,
13
14
  Callback,
14
15
  CardContract,
15
16
  CardGridContract,
@@ -115,7 +116,7 @@ import {
115
116
  translator,
116
117
  validateDocument,
117
118
  widgetChecks
118
- } from "./chunk-5EYC4E5K.js";
119
+ } from "./chunk-RSIUW5J4.js";
119
120
  import {
120
121
  createStateProxy,
121
122
  getPath,
@@ -4098,6 +4099,7 @@ function PanelFrameInner({ id, nested }) {
4098
4099
  const tone2 = def.style?.tone ?? (widget?.frame === "plain" ? "plain" : "default");
4099
4100
  const headerKids = slotChildren(def, "header");
4100
4101
  const footerKids = slotChildren(def, "footer");
4102
+ const toolbarKids = slotChildren(def, "toolbar");
4101
4103
  const hideHeader = Boolean(def.style?.hideHeader) || !title && !meta2 && !live2 && drill.length === 0 && controls.length === 0 && !view.stale && headerKids.length === 0;
4102
4104
  const dnd = Boolean(options.onDropOnPanel);
4103
4105
  let body;
@@ -4149,7 +4151,9 @@ function PanelFrameInner({ id, nested }) {
4149
4151
  const defaultSlot = widget?.slots ? Object.keys(widget.slots)[0] ?? "header" : "header";
4150
4152
  const dropTarget = (target, x, y) => {
4151
4153
  const own = `[data-slot][data-owner="${CSS.escape(id)}"]`;
4152
- const el = target?.closest(own) ?? frameRef.current?.querySelector(`${own}:not([data-slot="header"]):not([data-slot="footer"])`) ?? void 0;
4154
+ const el = target?.closest(own) ?? frameRef.current?.querySelector(
4155
+ `${own}:not([data-slot="header"]):not([data-slot="footer"]):not([data-slot="toolbar"])`
4156
+ ) ?? void 0;
4153
4157
  const name = el?.getAttribute("data-slot") ?? defaultSlot;
4154
4158
  return { slot: name, index: el ? indexIn(el, x, y) : void 0 };
4155
4159
  };
@@ -4250,6 +4254,7 @@ function PanelFrameInner({ id, nested }) {
4250
4254
  ))
4251
4255
  ] })
4252
4256
  ] }),
4257
+ toolbarKids.length > 0 && /* @__PURE__ */ jsx14(Slot, { name: "toolbar", className: "ds-panel-toolbar" }),
4253
4258
  /* @__PURE__ */ jsx14("div", { className: "ds-panel-body", ref: bodyRef, children: body }),
4254
4259
  footerKids.length > 0 && /* @__PURE__ */ jsx14(Slot, { name: "footer", className: "ds-panel-foot" })
4255
4260
  ]
@@ -5038,8 +5043,47 @@ var Table = defineWidget({
5038
5043
  ]
5039
5044
  }
5040
5045
  ),
5041
- pageSize && /* @__PURE__ */ jsxs16("div", { className: "ds-pager", children: [
5042
- /* @__PURE__ */ jsxs16("span", { className: "ds-pager-size", children: [
5046
+ pageSize && (pg?.layout === "simple" ? /* @__PURE__ */ jsxs16("div", { className: "ds-pager", "data-layout": "simple", children: [
5047
+ /* @__PURE__ */ jsxs16("span", { className: "ds-pager-range", children: [
5048
+ "Showing ",
5049
+ rowTotal === 0 ? 0 : (current - 1) * pageSize + 1,
5050
+ "\u2013",
5051
+ Math.min(current * pageSize, rowTotal),
5052
+ " of",
5053
+ " ",
5054
+ helpers.fmt.number(rowTotal),
5055
+ " rows"
5056
+ ] }),
5057
+ /* @__PURE__ */ jsx21(
5058
+ "button",
5059
+ {
5060
+ type: "button",
5061
+ className: "ds-button",
5062
+ "data-size": "sm",
5063
+ disabled: current <= 1,
5064
+ onClick: () => update({ page: current - 1 }),
5065
+ children: "Previous"
5066
+ }
5067
+ ),
5068
+ /* @__PURE__ */ jsxs16("span", { className: "ds-pager-of", children: [
5069
+ "Page ",
5070
+ current,
5071
+ " of ",
5072
+ Math.max(1, pages)
5073
+ ] }),
5074
+ /* @__PURE__ */ jsx21(
5075
+ "button",
5076
+ {
5077
+ type: "button",
5078
+ className: "ds-button",
5079
+ "data-size": "sm",
5080
+ disabled: current >= pages,
5081
+ onClick: () => update({ page: current + 1 }),
5082
+ children: "Next"
5083
+ }
5084
+ )
5085
+ ] }) : /* @__PURE__ */ jsxs16("div", { className: "ds-pager", children: [
5086
+ pg?.sizes !== false && /* @__PURE__ */ jsxs16("span", { className: "ds-pager-size", children: [
5043
5087
  "Rows",
5044
5088
  /* @__PURE__ */ jsx21(
5045
5089
  SelectControl,
@@ -5095,7 +5139,7 @@ var Table = defineWidget({
5095
5139
  }
5096
5140
  )
5097
5141
  ] })
5098
- ] })
5142
+ ] }))
5099
5143
  ] });
5100
5144
  }
5101
5145
  });
@@ -5111,7 +5155,10 @@ var Tiles = defineWidget({
5111
5155
  events: ["click", "hover", "select"],
5112
5156
  parts: ["tile"],
5113
5157
  defaults: { label: "name", value: "value" },
5114
- component: function TilesWidget({ spec, data, emit, helpers }) {
5158
+ component: function TilesWidget({ spec, data, emit, helpers, panelId }) {
5159
+ const hasClick = useClickable(panelId, () => {
5160
+ }).role === "button";
5161
+ const clickable = spec.selectable || hasClick;
5115
5162
  const rows = asRows(data);
5116
5163
  const caption = (row) => {
5117
5164
  if (!spec.caption) return void 0;
@@ -5152,6 +5199,7 @@ var Tiles = defineWidget({
5152
5199
  "aria-checked": spec.selectable ? active : void 0,
5153
5200
  "data-active": active || void 0,
5154
5201
  "data-muted": mutedTile || void 0,
5202
+ "data-clickable": clickable || void 0,
5155
5203
  "data-highlight": lit ? spec.highlightTone ?? "warn" : void 0,
5156
5204
  onClick: () => {
5157
5205
  emit("click", "tile", { datum: r, value: label, index: i });
@@ -5164,18 +5212,28 @@ var Tiles = defineWidget({
5164
5212
  String(label ?? ""),
5165
5213
  spec.count && /* @__PURE__ */ jsx22("span", { className: "ds-chip-count", children: String(field(r, spec.count) ?? "") })
5166
5214
  ] }),
5167
- /* @__PURE__ */ jsxs17(
5168
- "span",
5169
- {
5170
- className: "ds-tile-value",
5171
- style: vt ? { color: vt === "muted" ? "var(--ds-color-text-disabled)" : tone(vt).fg } : void 0,
5172
- children: [
5173
- /* @__PURE__ */ jsx22(CountUp, { value: v, render: (x) => formatValue(x, helpers, spec.format, spec.decimals) }),
5174
- spec.unit && /* @__PURE__ */ jsx22("span", { className: "ds-kpi-unit", children: spec.unit })
5175
- ]
5176
- }
5177
- ),
5178
- spec.caption && /* @__PURE__ */ jsx22("span", { className: "ds-tile-caption", children: caption(r) }),
5215
+ (() => {
5216
+ const valueEl = v === "" ? null : /* @__PURE__ */ jsxs17(
5217
+ "span",
5218
+ {
5219
+ className: "ds-tile-value",
5220
+ style: vt ? { color: vt === "muted" ? "var(--ds-color-text-disabled)" : tone(vt).fg } : void 0,
5221
+ children: [
5222
+ /* @__PURE__ */ jsx22(CountUp, { value: v, render: (x) => formatValue(x, helpers, spec.format, spec.decimals) }),
5223
+ spec.unit && /* @__PURE__ */ jsx22("span", { className: "ds-kpi-unit", children: spec.unit })
5224
+ ]
5225
+ }
5226
+ );
5227
+ const cap = spec.caption ? caption(r) : "";
5228
+ const capEl = cap ? /* @__PURE__ */ jsx22("span", { className: "ds-tile-caption", children: cap }) : null;
5229
+ return spec.captionInline ? /* @__PURE__ */ jsxs17("span", { className: "ds-tile-main", children: [
5230
+ valueEl,
5231
+ capEl
5232
+ ] }) : /* @__PURE__ */ jsxs17(Fragment6, { children: [
5233
+ valueEl,
5234
+ capEl
5235
+ ] });
5236
+ })(),
5179
5237
  /* @__PURE__ */ jsx22(Chips, { chips: spec.chips, vars, helpers })
5180
5238
  ]
5181
5239
  },
@@ -5321,6 +5379,51 @@ var Divider = defineWidget({
5321
5379
  return /* @__PURE__ */ jsx23("hr", { className: "ds-atom-divider", "data-dir": spec.direction, "data-dashed": spec.dashed || void 0 });
5322
5380
  }
5323
5381
  });
5382
+ var Button = defineWidget({
5383
+ ...ButtonContract,
5384
+ implements: "button",
5385
+ frame: "plain",
5386
+ meta: meta("Button", 2, 1),
5387
+ events: ["click"],
5388
+ component: function ButtonAtom({ spec, emit }) {
5389
+ const icon2 = spec.icon ? /* @__PURE__ */ jsx23(
5390
+ "svg",
5391
+ {
5392
+ viewBox: "0 0 24 24",
5393
+ width: spec.size === "sm" ? 14 : 16,
5394
+ height: spec.size === "sm" ? 14 : 16,
5395
+ fill: "none",
5396
+ stroke: "currentColor",
5397
+ strokeWidth: "2",
5398
+ strokeLinecap: "round",
5399
+ strokeLinejoin: "round",
5400
+ "aria-hidden": "true",
5401
+ children: /* @__PURE__ */ jsx23("path", { d: ICONS[spec.icon] ?? "" })
5402
+ }
5403
+ ) : null;
5404
+ return /* @__PURE__ */ jsxs18(
5405
+ "button",
5406
+ {
5407
+ type: "button",
5408
+ className: "ds-button",
5409
+ "data-variant": spec.variant,
5410
+ "data-size": spec.size,
5411
+ "data-icon-only": !spec.label || void 0,
5412
+ disabled: spec.disabled,
5413
+ "aria-label": spec.ariaLabel ?? spec.label,
5414
+ onClick: (e) => {
5415
+ e.stopPropagation();
5416
+ emit("click", "button", {});
5417
+ },
5418
+ children: [
5419
+ !spec.iconAfter && icon2,
5420
+ spec.label,
5421
+ spec.iconAfter && icon2
5422
+ ]
5423
+ }
5424
+ );
5425
+ }
5426
+ });
5324
5427
 
5325
5428
  // src/widgets/builtins/charts.tsx
5326
5429
  import { useMemo as useMemo6 } from "react";
@@ -5415,6 +5518,7 @@ function EChart({
5415
5518
  }) {
5416
5519
  const el = useRef8(null);
5417
5520
  const chart = useRef8(null);
5521
+ const lastCats = useRef8(void 0);
5418
5522
  const tokens = useThemeTokens();
5419
5523
  const theme = useMemo5(() => tokens ? echartsTheme(tokens.theme, tokens.mode) : void 0, [tokens]);
5420
5524
  const handlers = useRef8({ emit, rows });
@@ -5474,6 +5578,9 @@ function EChart({
5474
5578
  const legend = merged.legend ?? {};
5475
5579
  merged.legend = { ...legend, selected: Object.fromEntries(hiddenSeries.map((s) => [s, false])) };
5476
5580
  }
5581
+ const cats = JSON.stringify(axisCategories(merged));
5582
+ if (lastCats.current !== void 0 && cats !== lastCats.current && !reduce) c.clear();
5583
+ lastCats.current = cats;
5477
5584
  c.setOption(merged, { notMerge: true, lazyUpdate: true });
5478
5585
  }, [option, extra, hiddenSeries, theme, part]);
5479
5586
  useEffect7(() => {
@@ -5487,6 +5594,14 @@ function EChart({
5487
5594
  }, [highlightIndex, theme, part]);
5488
5595
  return /* @__PURE__ */ jsx24("div", { ref: el, role: "img", "aria-label": ariaLabel, style: { width: "100%", height: Math.max(80, height) } });
5489
5596
  }
5597
+ function axisCategories(o) {
5598
+ for (const k of ["xAxis", "yAxis"]) {
5599
+ const a = o[k];
5600
+ const axis = Array.isArray(a) ? a[0] : a;
5601
+ if (axis && axis.type === "category") return axis.data;
5602
+ }
5603
+ return void 0;
5604
+ }
5490
5605
 
5491
5606
  // src/widgets/shared/cartesian.ts
5492
5607
  function cartesian(data, source, spec, type, h, colors) {
@@ -6113,7 +6228,8 @@ var builtInWidgets = [
6113
6228
  Value,
6114
6229
  Progress,
6115
6230
  Icon,
6116
- Divider
6231
+ Divider,
6232
+ Button
6117
6233
  ];
6118
6234
 
6119
6235
  // src/components/Grid.tsx
@@ -6913,8 +7029,9 @@ var RENDERER_CSS = `
6913
7029
  .ds-tiles[data-wrap="off"] > * { scroll-snap-align: start; }
6914
7030
  .ds-tile { min-width: 0; overflow-wrap: anywhere; }
6915
7031
  .ds-tile { display: flex; flex-direction: column; gap: 6px; padding: var(--ds-space-md) var(--ds-space-md) var(--ds-space-md); border: 1px solid var(--ds-color-border-default); border-radius: var(--ds-radius-control); background: var(--ds-color-surface-card); text-align: left; min-height: 0; transition: border-color 120ms, background 120ms; }
6916
- .ds-tile:hover { border-color: var(--ds-color-action-primary); }
7032
+ .ds-tile[data-clickable]:hover { border-color: var(--ds-color-action-primary); }
6917
7033
  .ds-tile[data-active] { border-color: var(--ds-color-action-primary); background: var(--ds-color-surface-selection); box-shadow: none; }
7034
+ .ds-tile-main { display: flex; align-items: baseline; gap: var(--ds-space-xs); flex-wrap: wrap; }
6918
7035
  .ds-tile[data-active] .ds-tile-label { color: var(--ds-color-text-primary); font-weight: 600; }
6919
7036
  .ds-tile-label { font-size: var(--ds-type-label-size); color: var(--ds-color-text-subtle); text-transform: none; gap: 2px; }
6920
7037
  .ds-tile-value { font-family: var(--ds-type-kpi-family); font-size: 24px; line-height: 30px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--ds-color-text-primary); }
@@ -6957,7 +7074,8 @@ var RENDERER_CSS = `
6957
7074
  .ds-panel-body > :not(.ds-skeleton):not(.ds-loading) { animation: ds-fade 360ms ease both; }
6958
7075
  .ds-filters, .ds-header { animation: ds-fade 400ms ease both; }
6959
7076
  .ds-tile { transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease; }
6960
- .ds-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(21, 121, 190, .10); }
7077
+ .ds-tile[data-clickable]:hover { transform: translateY(-2px); box-shadow: 0 6px 16px color-mix(in srgb, var(--ds-color-action-primary) 10%, transparent); }
7078
+ .ds-tile:not([data-clickable]) { cursor: default; }
6961
7079
  .ds-tile:active { transform: translateY(0); }
6962
7080
  .ds-kpi-main { transition: opacity 160ms ease; }
6963
7081
  .ds-kpi-main[data-clickable]:hover .ds-kpi-value { color: var(--ds-color-action-primary); transition: color 160ms ease; }
@@ -7215,6 +7333,20 @@ var RENDERER_CSS = `
7215
7333
  .ds-panel[data-tone="plain"] > .ds-panel-body { container-type: normal; }
7216
7334
  /* Slots: nodes inside nodes */
7217
7335
  .ds-slot { min-width: 0; }
7336
+ .ds-pager[data-layout="simple"] { display: flex; align-items: center; justify-content: flex-end; gap: var(--ds-space-sm); flex-wrap: wrap; color: var(--ds-color-text-subtle); font-size: var(--ds-type-label-size); }
7337
+ .ds-pager[data-layout="simple"] .ds-pager-range { margin-right: var(--ds-space-xs); }
7338
+ .ds-slot[data-slot="toolbar"] { display: flex; flex-wrap: wrap; gap: var(--ds-space-sm); align-items: center; margin-bottom: var(--ds-space-sm); }
7339
+ .ds-button { display: inline-flex; align-items: center; justify-content: center; gap: var(--ds-space-xs); height: var(--ds-control-height, 36px); padding: 0 var(--ds-space-md); border: 1px solid var(--ds-color-border-default); border-radius: var(--ds-radius-control); background: var(--ds-color-surface-card); color: var(--ds-color-text-primary); font: 500 var(--ds-type-label-size)/1 var(--ds-font-body); cursor: pointer; white-space: nowrap; transition: background 140ms ease, border-color 140ms ease, opacity 140ms ease; }
7340
+ .ds-button[data-size="sm"] { height: calc(var(--ds-control-height, 36px) - 8px); padding: 0 var(--ds-space-sm); }
7341
+ .ds-button[data-icon-only] { padding: 0; width: var(--ds-control-height, 36px); }
7342
+ .ds-button[data-icon-only][data-size="sm"] { width: calc(var(--ds-control-height, 36px) - 8px); }
7343
+ .ds-button[data-variant="primary"] { background: var(--ds-color-action-primary); border-color: var(--ds-color-action-primary); color: var(--ds-color-action-on-primary); }
7344
+ .ds-button[data-variant="subtle"] { background: var(--ds-color-surface-selection); border-color: transparent; color: var(--ds-color-action-primary); }
7345
+ .ds-button[data-variant="link"] { background: none; border-color: transparent; color: var(--ds-color-action-primary); padding: 0; height: auto; }
7346
+ .ds-button:hover:not(:disabled) { border-color: var(--ds-color-action-primary); }
7347
+ .ds-button[data-variant="link"]:hover:not(:disabled) { text-decoration: underline; }
7348
+ .ds-button:disabled { opacity: .4; cursor: default; }
7349
+ .ds-button:focus-visible { outline: 2px solid var(--ds-color-border-focus); outline-offset: 1px; }
7218
7350
  .ds-slot[data-slot="footer"] { margin-top: var(--ds-space-sm); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
7219
7351
  .ds-slot[data-empty] { display: grid; place-items: center; min-height: 44px; border: 1.5px dashed var(--ds-color-border-control); border-radius: var(--ds-radius-control); color: var(--ds-color-text-subtle); font-size: var(--ds-type-label-size); padding: 8px; }
7220
7352
  .ds-slot-hint { pointer-events: none; }