@worm-print-platform/echarts 1.6.4 → 1.6.5

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/ui.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.6.4
2
+ * @worm-print-platform/echarts v1.6.5
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -109,6 +109,8 @@ var zh_CN_default = {
109
109
  "echarts.panel.labelLine.length2": "\u7B2C\u4E8C\u6BB5\u957F\u5EA6",
110
110
  "echarts.panel.labelLine.smooth": "\u5E73\u6ED1\u5F15\u5BFC\u7EBF",
111
111
  "echarts.panel.dataSourceTitle": "\u6570\u636E\u6E90",
112
+ "echarts.panel.selectField": "\u9009\u62E9\u5B57\u6BB5",
113
+ "echarts.panel.autoSource": "\u81EA\u52A8",
112
114
  "echarts.panel.categoryField": "\u7C7B\u76EE\u5B57\u6BB5",
113
115
  "echarts.panel.removeField": "\u5220\u9664\u8BE5\u5B57\u6BB5",
114
116
  "echarts.panel.addField": "+ \u6DFB\u52A0\u5B57\u6BB5",
@@ -264,6 +266,8 @@ var en_US_default = {
264
266
  "echarts.panel.labelLine.length2": "Second segment length",
265
267
  "echarts.panel.labelLine.smooth": "Smooth label line",
266
268
  "echarts.panel.dataSourceTitle": "Data source",
269
+ "echarts.panel.selectField": "Select field",
270
+ "echarts.panel.autoSource": "Auto",
267
271
  "echarts.panel.categoryField": "Category field",
268
272
  "echarts.panel.removeField": "Remove this field",
269
273
  "echarts.panel.addField": "+ Add field",
@@ -419,6 +423,8 @@ var th_TH_default = {
419
423
  "echarts.panel.labelLine.length2": "\u0E04\u0E27\u0E32\u0E21\u0E22\u0E32\u0E27\u0E17\u0E48\u0E2D\u0E19\u0E17\u0E35\u0E48\u0E2A\u0E2D\u0E07",
420
424
  "echarts.panel.labelLine.smooth": "\u0E40\u0E2A\u0E49\u0E19\u0E1B\u0E49\u0E32\u0E22\u0E42\u0E04\u0E49\u0E07",
421
425
  "echarts.panel.dataSourceTitle": "\u0E41\u0E2B\u0E25\u0E48\u0E07\u0E02\u0E49\u0E2D\u0E21\u0E39\u0E25",
426
+ "echarts.panel.selectField": "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E1F\u0E34\u0E25\u0E14\u0E4C",
427
+ "echarts.panel.autoSource": "\u0E2D\u0E31\u0E15\u0E42\u0E19\u0E21\u0E31\u0E15\u0E34",
422
428
  "echarts.panel.categoryField": "\u0E1F\u0E34\u0E25\u0E14\u0E4C\u0E2B\u0E21\u0E27\u0E14\u0E2B\u0E21\u0E39\u0E48",
423
429
  "echarts.panel.removeField": "\u0E25\u0E1A\u0E1F\u0E34\u0E25\u0E14\u0E4C\u0E19\u0E35\u0E49",
424
430
  "echarts.panel.addField": "+ \u0E40\u0E1E\u0E34\u0E48\u0E21\u0E1F\u0E34\u0E25\u0E14\u0E4C",
@@ -959,8 +965,8 @@ function chartFactoryDefaults(type, partial) {
959
965
  title: def?.label ?? "\u56FE\u8868",
960
966
  chartOption: createDefaultChartOption(type),
961
967
  chartDataSource: "",
962
- chartCategoryField: "name",
963
- chartValueFields: ["value"],
968
+ chartCategoryField: "",
969
+ chartValueFields: [],
964
970
  chartSeriesField: "",
965
971
  ...partial
966
972
  };
@@ -1630,18 +1636,9 @@ var CANVAS_STYLE = "width:100%;height:100%;min-width:0;min-height:0;pointer-even
1630
1636
  var STYLES = [
1631
1637
  ".echarts-canvas-element{overflow:hidden}",
1632
1638
  ".echarts-field-row{display:flex;gap:6px;align-items:center}",
1639
+ ".echarts-field-current{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--pd-text-secondary,#6b7280)}",
1633
1640
  ".echarts-field-row>.pd-input{flex:1;min-width:0}",
1634
1641
  ".echarts-field-row>.pd-button{flex:none}",
1635
- ".echarts-dropdown-trigger{display:flex;align-items:center;justify-content:space-between;gap:6px;width:100%;height:26px;min-height:26px;padding:3px 6px;border:1px solid var(--pd-border,#d9dde6);border-radius:6px;background:var(--pd-input-bg,#fff);color:inherit;font:inherit;box-sizing:border-box;cursor:pointer;text-align:left}",
1636
- ".echarts-dropdown-trigger:hover{border-color:var(--pd-text-faint,#b4b9c4)}",
1637
- '.echarts-dropdown-trigger[aria-expanded="true"]{border-color:var(--pd-accent,#165dff);box-shadow:0 0 0 2px rgb(22 93 255 / 12%)}',
1638
- ".echarts-dropdown-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}",
1639
- ".echarts-dropdown-arrow{flex:none;color:var(--pd-text-muted,#909399);font-size:10px;transition:transform .14s}",
1640
- '.echarts-dropdown-trigger[aria-expanded="true"] .echarts-dropdown-arrow{transform:rotate(180deg)}',
1641
- ".echarts-dropdown-panel{position:fixed;z-index:1200;max-height:240px;overflow:auto;padding:3px;border:1px solid var(--pd-border,#d9dde6);border-radius:6px;background:var(--pd-input-bg,#fff);box-shadow:0 6px 18px rgb(0 0 0 / 14%);box-sizing:border-box}",
1642
- ".echarts-dropdown-option{padding:5px 8px;border-radius:4px;cursor:pointer;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
1643
- ".echarts-dropdown-option:hover{background:var(--pd-accent-soft,rgb(22 93 255 / 9%))}",
1644
- ".echarts-dropdown-option.is-active{background:var(--pd-accent-soft,rgb(22 93 255 / 9%));color:var(--pd-accent,#165dff)}",
1645
1642
  ".echarts-label-group{margin-top:8px;border-top:1px solid var(--pd-border,#e5e7eb);padding-top:8px}",
1646
1643
  ".echarts-label-group>summary{display:flex;align-items:center;cursor:pointer;list-style:none;font-size:12px;font-weight:600}",
1647
1644
  ".echarts-label-summary>.pd-field{flex:1;margin:0;font-weight:400}",
@@ -1722,22 +1719,6 @@ function valueFieldsLabel(def, limit) {
1722
1719
  if (def?.seriesType === "radar") return t2("echarts.panel.field.dimension");
1723
1720
  return limit === 1 ? t2("echarts.panel.field.value") : t2("echarts.panel.field.valueMulti");
1724
1721
  }
1725
- function dataSourceCandidates(data, fields) {
1726
- const first = data?.[0];
1727
- const keys = first ? Object.keys(first).filter((key) => Array.isArray(first[key])) : [];
1728
- for (const field2 of fields ?? []) {
1729
- if (field2.fieldType === "list" && field2.fieldKey && !keys.includes(field2.fieldKey)) keys.push(field2.fieldKey);
1730
- }
1731
- return keys;
1732
- }
1733
- function dataRowFields(data, dataSource) {
1734
- const first = data?.[0];
1735
- if (!first) return [];
1736
- const key = dataSource ? Array.isArray(first[dataSource]) ? dataSource : "" : Object.keys(first).find((k) => Array.isArray(first[k]));
1737
- if (!key) return [];
1738
- const rows = first[key];
1739
- return rows.length > 0 && typeof rows[0] === "object" && rows[0] !== null ? Object.keys(rows[0]) : [];
1740
- }
1741
1722
  function fieldLabelMap(fields) {
1742
1723
  const map = /* @__PURE__ */ new Map();
1743
1724
  for (const field2 of fields ?? []) {
@@ -1745,17 +1726,41 @@ function fieldLabelMap(fields) {
1745
1726
  }
1746
1727
  return map;
1747
1728
  }
1748
- function optionLabel(value, labels, fallbackSuffix) {
1749
- if (!value) return fallbackSuffix ?? t2("echarts.panel.default");
1729
+ function optionLabel(value, labels) {
1730
+ if (!value) return t2("echarts.panel.default");
1750
1731
  const name = labels.get(value);
1751
- const base = name ? `${name}\uFF08${value}\uFF09` : value;
1752
- return fallbackSuffix ? `${base}${fallbackSuffix}` : base;
1753
- }
1754
- function dropdownOptions(candidates, current, labels = /* @__PURE__ */ new Map()) {
1755
- const opts = candidates.map((value) => ({ value, label: optionLabel(value, labels) }));
1756
- if (current && !candidates.includes(current)) opts.unshift({ value: current, label: optionLabel(current, labels, t2("echarts.panel.current")) });
1757
- if (!current) opts.unshift({ value: "", label: t2("echarts.panel.defaultFirstArray") });
1758
- return opts;
1732
+ return name ? `${name}\uFF08${value}\uFF09` : value;
1733
+ }
1734
+ function fieldBindingKey(next) {
1735
+ if (next.binding) return next.binding;
1736
+ const matched = /^\{\s*([^{}]+?)\s*\}$/.exec(next.formatter?.trim() ?? "");
1737
+ return matched?.[1]?.trim() ?? "";
1738
+ }
1739
+ function fieldPicker(ctx, current, targetPath, fields, labels, onSelect, allowAuto = false) {
1740
+ const row = el("div", "echarts-field-row");
1741
+ const display = el(
1742
+ "span",
1743
+ "echarts-field-current",
1744
+ current ? optionLabel(current, labels) : allowAuto ? t2("echarts.panel.autoSource") : t2("echarts.panel.default")
1745
+ );
1746
+ const picker = el("button", "pd-button small echarts-field-picker", t2("echarts.panel.selectField"));
1747
+ picker.type = "button";
1748
+ picker.addEventListener("click", () => ctx.openExpression({
1749
+ elementId: ctx.element.id,
1750
+ targetPath,
1751
+ value: current ? `{${current}}` : "",
1752
+ binding: current || void 0,
1753
+ fieldOnly: true,
1754
+ fields
1755
+ }, (next) => onSelect(fieldBindingKey(next))));
1756
+ row.append(display, picker);
1757
+ if (allowAuto) {
1758
+ const auto = el("button", "pd-button small echarts-auto-source", t2("echarts.panel.autoSource"));
1759
+ auto.type = "button";
1760
+ auto.addEventListener("click", () => onSelect(""));
1761
+ row.appendChild(auto);
1762
+ }
1763
+ return row;
1759
1764
  }
1760
1765
  function seriesList(option) {
1761
1766
  return Array.isArray(option.series) ? option.series : [];
@@ -1835,84 +1840,6 @@ function selectInput(options, value, onCommit) {
1835
1840
  select.addEventListener("change", () => onCommit(select.value));
1836
1841
  return select;
1837
1842
  }
1838
- var activeDropdown = null;
1839
- function composedPathOf(ev) {
1840
- const composed = typeof ev.composedPath === "function" ? ev.composedPath() : [];
1841
- return composed.length ? composed : [ev.target];
1842
- }
1843
- function dropdownSelect(options, value, onCommit) {
1844
- const current = options.find((item) => item.value === value) ?? { value, label: value || t2("echarts.panel.optionDefault") };
1845
- const trigger = el("button", "echarts-dropdown-trigger");
1846
- trigger.type = "button";
1847
- trigger.setAttribute("aria-haspopup", "listbox");
1848
- trigger.setAttribute("aria-expanded", "false");
1849
- const valueEl = el("span", "echarts-dropdown-value", current.label);
1850
- const arrow = el("span", "echarts-dropdown-arrow", "\u25BE");
1851
- trigger.appendChild(valueEl);
1852
- trigger.appendChild(arrow);
1853
- let panel = null;
1854
- let off = [];
1855
- const close = () => {
1856
- off.forEach((fn) => fn());
1857
- off = [];
1858
- panel?.remove();
1859
- panel = null;
1860
- trigger.setAttribute("aria-expanded", "false");
1861
- if (activeDropdown?.close === close) activeDropdown = null;
1862
- };
1863
- const open = () => {
1864
- activeDropdown?.close();
1865
- const root = trigger.getRootNode();
1866
- const mount = root instanceof ShadowRoot ? root : document.body;
1867
- panel = el("div", "echarts-dropdown-panel");
1868
- panel.setAttribute("role", "listbox");
1869
- for (const item of options) {
1870
- const optionEl = el("div", `echarts-dropdown-option${item.value === value ? " is-active" : ""}`, item.label);
1871
- optionEl.setAttribute("role", "option");
1872
- optionEl.setAttribute("aria-selected", item.value === value ? "true" : "false");
1873
- optionEl.addEventListener("click", (ev) => {
1874
- ev.stopPropagation();
1875
- close();
1876
- onCommit(item.value);
1877
- });
1878
- panel.appendChild(optionEl);
1879
- }
1880
- mount.appendChild(panel);
1881
- const rect = trigger.getBoundingClientRect();
1882
- panel.style.left = `${rect.left}px`;
1883
- panel.style.top = `${rect.bottom + 4}px`;
1884
- panel.style.minWidth = `${rect.width}px`;
1885
- trigger.setAttribute("aria-expanded", "true");
1886
- activeDropdown = { close };
1887
- const onPointerDown = (ev) => {
1888
- const path = composedPathOf(ev);
1889
- if (path.includes(trigger) || path.includes(panel)) return;
1890
- close();
1891
- };
1892
- const onKeydown = (ev) => {
1893
- if (ev.key === "Escape") close();
1894
- };
1895
- const onScroll = () => close();
1896
- document.addEventListener("pointerdown", onPointerDown, true);
1897
- document.addEventListener("keydown", onKeydown);
1898
- window.addEventListener("scroll", onScroll, true);
1899
- window.addEventListener("resize", onScroll);
1900
- root.addEventListener("scroll", onScroll, true);
1901
- off.push(
1902
- () => document.removeEventListener("pointerdown", onPointerDown, true),
1903
- () => document.removeEventListener("keydown", onKeydown),
1904
- () => window.removeEventListener("scroll", onScroll, true),
1905
- () => window.removeEventListener("resize", onScroll),
1906
- () => root.removeEventListener("scroll", onScroll, true)
1907
- );
1908
- };
1909
- trigger.addEventListener("click", (ev) => {
1910
- ev.stopPropagation();
1911
- if (panel) close();
1912
- else open();
1913
- });
1914
- return trigger;
1915
- }
1916
1843
  var overflowOptions = () => [
1917
1844
  { value: "", label: t2("echarts.panel.overflow.default") },
1918
1845
  { value: "none", label: t2("echarts.panel.overflow.none") },
@@ -2094,60 +2021,67 @@ function renderProperty(ctx) {
2094
2021
  return withTranslator(ctx.t, () => renderPropertyInner(ctx));
2095
2022
  }
2096
2023
  function renderPropertyInner(ctx) {
2024
+ if (!ctx.openExpression) throw new Error("[echarts] \u56FE\u8868\u5C5E\u6027\u9762\u677F\u9700\u8981\u5BBF\u4E3B\u63D0\u4F9B openExpression\uFF08\u5B57\u6BB5\u9009\u62E9\u4EC5\u652F\u6301\u8868\u8FBE\u5F0F\u5F39\u6846\uFF09");
2097
2025
  const element = ctx.element;
2098
2026
  const type = elementType(element);
2099
2027
  const def = getChartKindDefinition(type);
2100
- const fields = resolveChartPanelFields(type);
2101
- const has = (key) => fields.includes(key);
2028
+ const panelFields = resolveChartPanelFields(type);
2029
+ const has = (key) => panelFields.includes(key);
2102
2030
  const options = element.options;
2103
2031
  const widthMm = Number(options.width) || 0;
2104
2032
  const heightMm = Number(options.height) || 0;
2105
2033
  const limit = maxValueFields(def);
2106
2034
  const palettes = getChartPalettes();
2107
2035
  const fieldLabels = fieldLabelMap(ctx.fields);
2036
+ const allFields = ctx.fields ?? [];
2037
+ const sourceFields = allFields.filter((field2) => field2.fieldType === "list");
2038
+ const bound = String(options.chartDataSource ?? "");
2039
+ const prefixed = bound ? allFields.filter((field2) => field2.fieldKey.startsWith(`${bound}.`)) : [];
2040
+ const rowFields = prefixed.length > 0 ? prefixed : allFields.filter((field2) => field2.fieldType !== "list");
2108
2041
  const root = el("div", "echarts-property");
2109
2042
  const form = el("form", "pd-form");
2110
2043
  form.addEventListener("submit", (event) => event.preventDefault());
2111
2044
  root.appendChild(form);
2112
2045
  if (has("dataSource")) {
2113
2046
  const wrap = field(t2("echarts.panel.dataSourceTitle"));
2114
- const current = String(options.chartDataSource ?? "");
2115
- wrap.appendChild(
2116
- dropdownSelect(
2117
- dropdownOptions(dataSourceCandidates(ctx.data, ctx.fields), current, fieldLabels),
2118
- current,
2119
- (value) => commitOption(ctx, type, panelOption(element), { chartDataSource: value })
2120
- )
2121
- );
2047
+ wrap.appendChild(fieldPicker(
2048
+ ctx,
2049
+ String(options.chartDataSource ?? ""),
2050
+ "options.chartDataSource",
2051
+ sourceFields,
2052
+ fieldLabels,
2053
+ (value) => commitOption(ctx, type, panelOption(element), { chartDataSource: value }),
2054
+ true
2055
+ ));
2122
2056
  form.appendChild(wrap);
2123
2057
  }
2124
2058
  if (has("categoryField")) {
2125
2059
  const wrap = field(t2("echarts.panel.categoryField"));
2126
- const current = String(options.chartCategoryField ?? "");
2127
- wrap.appendChild(
2128
- dropdownSelect(
2129
- dropdownOptions(dataRowFields(ctx.data, String(options.chartDataSource ?? "")), current, fieldLabels),
2130
- current,
2131
- (value) => commitOption(ctx, type, panelOption(element), { chartCategoryField: value })
2132
- )
2133
- );
2060
+ wrap.appendChild(fieldPicker(
2061
+ ctx,
2062
+ String(options.chartCategoryField ?? ""),
2063
+ "options.chartCategoryField",
2064
+ rowFields,
2065
+ fieldLabels,
2066
+ (value) => commitOption(ctx, type, panelOption(element), { chartCategoryField: value })
2067
+ ));
2134
2068
  form.appendChild(wrap);
2135
2069
  }
2136
2070
  if (has("valueFields")) {
2137
2071
  const wrap = field(valueFieldsLabel(def, limit));
2138
2072
  const fieldsNow = readValueFields(element);
2139
2073
  fieldsNow.forEach((value, index) => {
2140
- const row = el("div", "echarts-field-row");
2141
- row.appendChild(
2142
- dropdownSelect(
2143
- dropdownOptions(dataRowFields(ctx.data, String(options.chartDataSource ?? "")), value, fieldLabels),
2144
- value,
2145
- (next) => {
2146
- const list = readValueFields(element);
2147
- list[index] = next;
2148
- syncValueFields(ctx, type, list);
2149
- }
2150
- )
2074
+ const row = fieldPicker(
2075
+ ctx,
2076
+ value,
2077
+ `options.chartValueFields.${index}`,
2078
+ rowFields,
2079
+ fieldLabels,
2080
+ (next) => {
2081
+ const list = readValueFields(element);
2082
+ list[index] = next;
2083
+ syncValueFields(ctx, type, list);
2084
+ }
2151
2085
  );
2152
2086
  if (fieldsNow.length > 1) {
2153
2087
  const remove = el("button", "pd-button small", "\u2212");
@@ -2168,12 +2102,14 @@ function renderPropertyInner(ctx) {
2168
2102
  }
2169
2103
  if (has("seriesField")) {
2170
2104
  const wrap = field(t2("echarts.panel.seriesField"));
2171
- wrap.appendChild(
2172
- textInput(
2173
- { value: String(options.chartSeriesField ?? ""), placeholder: t2("echarts.panel.seriesFieldHint") },
2174
- (value) => commitOption(ctx, type, panelOption(element), { chartSeriesField: value })
2175
- )
2176
- );
2105
+ wrap.appendChild(fieldPicker(
2106
+ ctx,
2107
+ String(options.chartSeriesField ?? ""),
2108
+ "options.chartSeriesField",
2109
+ rowFields,
2110
+ fieldLabels,
2111
+ (value) => commitOption(ctx, type, panelOption(element), { chartSeriesField: value })
2112
+ ));
2177
2113
  form.appendChild(wrap);
2178
2114
  }
2179
2115
  if (has("bubble")) {
package/dist/ui.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.6.4
2
+ * @worm-print-platform/echarts v1.6.5
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT