@sia.soul/sia-react-ui 0.1.83 → 0.1.84

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.cjs CHANGED
@@ -1578,7 +1578,7 @@ function Steps({ items, current = 0, initial: initial3 = 0, direction = "horizon
1578
1578
  ] }, index);
1579
1579
  }) });
1580
1580
  }
1581
- function Segmented({ options, value, defaultValue, size: sizeProp, block = false, vertical = false, disabled = false, onChange, className = "", onKeyDown, ...props }) {
1581
+ function Segmented({ options, value, defaultValue, variant = "default", size: sizeProp, block = false, vertical = false, disabled = false, onChange, className = "", onKeyDown, ...props }) {
1582
1582
  const size = useControlSize(sizeProp);
1583
1583
  const normalized = (0, import_react5.useMemo)(() => options.map((option) => typeof option === "object" ? option : { label: option, value: option }), [options]);
1584
1584
  const [current, setCurrent] = useControllableState({ value, defaultValue: defaultValue ?? normalized[0]?.value, onChange: (next) => next !== void 0 && onChange?.(next) });
@@ -1591,7 +1591,7 @@ function Segmented({ options, value, defaultValue, size: sizeProp, block = false
1591
1591
  const next = event.key === "ArrowRight" || event.key === "ArrowDown" ? enabled[(index + 1) % enabled.length] : enabled[(index - 1 + enabled.length) % enabled.length];
1592
1592
  if (next) setCurrent(next.value);
1593
1593
  }
1594
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: `sia-segmented sia-segmented--${size}${block ? " sia-segmented--block" : ""}${vertical ? " sia-segmented--vertical" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), role: "radiogroup", onKeyDown: keyboard, ...withTitleTooltip(props), children: normalized.map((option) => /* @__PURE__ */ (0, import_react6.createElement)("button", { type: "button", role: "radio", "aria-checked": option.value === current, ...withTitleTooltip({ title: option.title }), className: option.value === current ? "is-selected" : "", disabled: disabled || option.disabled, key: option.value, onClick: () => setCurrent(option.value) }, option.icon, /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: option.label ?? option.value }))) });
1594
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: `sia-segmented sia-segmented--${size}${variant === "zigzag" && !vertical && normalized.length === 2 ? " sia-segmented--zigzag" : ""}${block ? " sia-segmented--block" : ""}${vertical ? " sia-segmented--vertical" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), role: "radiogroup", onKeyDown: keyboard, ...withTitleTooltip(props), children: normalized.map((option) => /* @__PURE__ */ (0, import_react6.createElement)("button", { type: "button", role: "radio", "aria-checked": option.value === current, ...withTitleTooltip({ title: option.title }), className: option.value === current ? "is-selected" : "", disabled: disabled || option.disabled, key: option.value, onClick: () => setCurrent(option.value) }, option.icon, /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: option.label ?? option.value }))) });
1595
1595
  }
1596
1596
 
1597
1597
  // src/components/Dropdown.tsx
@@ -12666,6 +12666,29 @@ function mergeColumnSettings(columns, saved, active) {
12666
12666
  return [...merged.values()].sort((left, right) => left.order - right.order);
12667
12667
  }
12668
12668
 
12669
+ // src/components/settingsPersistence.ts
12670
+ var queues = /* @__PURE__ */ new WeakMap();
12671
+ function saveSettingsPatch(adapter, scope, patch) {
12672
+ let scoped = queues.get(adapter);
12673
+ if (!scoped) {
12674
+ scoped = /* @__PURE__ */ new Map();
12675
+ queues.set(adapter, scoped);
12676
+ }
12677
+ const key = JSON.stringify([scope.moduleName, scope.businessKey]);
12678
+ const previous = scoped.get(key) ?? Promise.resolve();
12679
+ const task = previous.catch(() => void 0).then(async () => {
12680
+ const current = await adapter.load(scope);
12681
+ const defined = Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== void 0));
12682
+ await adapter.save(scope, { ...current, ...defined });
12683
+ });
12684
+ scoped.set(key, task);
12685
+ const cleanup2 = () => {
12686
+ if (scoped.get(key) === task) scoped.delete(key);
12687
+ };
12688
+ void task.then(cleanup2, cleanup2);
12689
+ return task;
12690
+ }
12691
+
12669
12692
  // src/components/Table/plugins.tsx
12670
12693
  var import_jsx_runtime51 = require("react/jsx-runtime");
12671
12694
  function TableCheckbox({
@@ -14758,7 +14781,7 @@ function createColumnSettingPlugin(options = {}) {
14758
14781
  return items.filter((item) => keys.has(item.key));
14759
14782
  };
14760
14783
  const currentItems = (context) => reconcileColumnSettings(context.baseColumns, baseItems(context), context.state.items ?? []);
14761
- const save = (snapshot) => options.adapter && options.scope ? options.adapter.save(options.scope, snapshot).catch(() => void 0) : Promise.resolve();
14784
+ const save = (snapshot) => options.adapter && options.scope ? saveSettingsPatch(options.adapter, options.scope, snapshot).catch(() => void 0) : Promise.resolve();
14762
14785
  function apply(items, context, persist = true) {
14763
14786
  const normalized = orderColumnSettings(
14764
14787
  editableItems(items, context).sort((a, b) => a.order - b.order)
@@ -23804,10 +23827,318 @@ var InputSelect = (0, import_react93.forwardRef)(function InputSelect2({
23804
23827
  });
23805
23828
 
23806
23829
  // src/components/QueryForm.tsx
23830
+ var import_react96 = require("react");
23831
+
23832
+ // src/components/QueryFormSettings.tsx
23833
+ var import_react95 = require("react");
23834
+
23835
+ // src/components/useQueryFieldSort.ts
23807
23836
  var import_react94 = require("react");
23837
+ function getQuerySortPreview(keys, rects, from, dy, gap) {
23838
+ const center = rects[from].top + rects[from].height / 2 + dy;
23839
+ const rest = keys.map((_, index) => index).filter((index) => index !== from);
23840
+ const to = rest.filter((index) => center > rects[index].top + rects[index].height / 2).length;
23841
+ const ordered = [...keys];
23842
+ ordered.splice(to, 0, ordered.splice(from, 1)[0]);
23843
+ const offsets = {};
23844
+ const last = rects[rects.length - 1];
23845
+ const boundedDy = Math.max(rects[0].top - rects[from].top, Math.min(dy, last.top + last.height - rects[from].height - rects[from].top));
23846
+ let top = rects[0].top;
23847
+ for (const key of ordered) {
23848
+ const index = keys.indexOf(key);
23849
+ offsets[key] = index === from ? boundedDy : top - rects[index].top;
23850
+ top += rects[index].height + gap;
23851
+ }
23852
+ return { ordered, offsets };
23853
+ }
23854
+ function useQueryFieldSort(keys, enabled, onCommit) {
23855
+ const listRef = (0, import_react94.useRef)(null);
23856
+ const cancelRef = (0, import_react94.useRef)();
23857
+ const commitRef = (0, import_react94.useRef)(onCommit);
23858
+ commitRef.current = onCommit;
23859
+ const [preview, setPreview] = (0, import_react94.useState)();
23860
+ const signature = JSON.stringify(keys);
23861
+ (0, import_react94.useEffect)(() => {
23862
+ cancelRef.current?.();
23863
+ return () => cancelRef.current?.();
23864
+ }, [enabled, signature]);
23865
+ function start(event, key) {
23866
+ if (!enabled || event.button !== 0 || event.target.closest("button, input, label")) return;
23867
+ const list = listRef.current;
23868
+ const from = keys.indexOf(key);
23869
+ if (!list || from < 0) return;
23870
+ cancelRef.current?.();
23871
+ const elements = [...list.querySelectorAll(".sia-query-settings__item")];
23872
+ if (elements.length !== keys.length) return;
23873
+ const rects = elements.map((element) => element.getBoundingClientRect());
23874
+ const gap = parseFloat(getComputedStyle(list).rowGap) || 0;
23875
+ const original = [...keys];
23876
+ const target = event.currentTarget;
23877
+ const pointerId = event.pointerId;
23878
+ const startY = event.clientY;
23879
+ const initialScroll = list.scrollTop;
23880
+ const maxScroll = Math.max(0, list.scrollHeight - list.clientHeight);
23881
+ const originalUserSelect = document.body.style.userSelect;
23882
+ let lastY = startY;
23883
+ let moved = false;
23884
+ let ended = false;
23885
+ let ordered = original;
23886
+ let frame = 0;
23887
+ target.setPointerCapture(pointerId);
23888
+ const update = () => {
23889
+ const dy = lastY - startY + list.scrollTop - initialScroll;
23890
+ if (!moved && Math.abs(dy) < 4) return;
23891
+ moved = true;
23892
+ document.body.style.userSelect = "none";
23893
+ const next = getQuerySortPreview(original, rects, from, dy, gap);
23894
+ ordered = next.ordered;
23895
+ setPreview({ key, offsets: next.offsets });
23896
+ };
23897
+ const tick = () => {
23898
+ if (moved) {
23899
+ const bounds = list.getBoundingClientRect();
23900
+ const delta = lastY < bounds.top + 32 ? -10 : lastY > bounds.bottom - 32 ? 10 : 0;
23901
+ const nextScroll = Math.max(0, Math.min(maxScroll, list.scrollTop + delta));
23902
+ if (delta && nextScroll !== list.scrollTop) {
23903
+ list.scrollTop = nextScroll;
23904
+ update();
23905
+ }
23906
+ }
23907
+ frame = requestAnimationFrame(tick);
23908
+ };
23909
+ const move = (next) => {
23910
+ if (next.pointerId === pointerId) {
23911
+ lastY = next.clientY;
23912
+ update();
23913
+ }
23914
+ };
23915
+ const finish = (commit) => {
23916
+ if (ended) return;
23917
+ ended = true;
23918
+ document.removeEventListener("pointermove", move);
23919
+ document.removeEventListener("pointerup", up);
23920
+ document.removeEventListener("pointercancel", cancelPointer);
23921
+ target.removeEventListener("lostpointercapture", cancel);
23922
+ window.removeEventListener("blur", cancel);
23923
+ window.removeEventListener("keydown", escape, true);
23924
+ cancelAnimationFrame(frame);
23925
+ if (target.hasPointerCapture(pointerId)) target.releasePointerCapture(pointerId);
23926
+ document.body.style.userSelect = originalUserSelect;
23927
+ cancelRef.current = void 0;
23928
+ setPreview(void 0);
23929
+ if (commit && moved) commitRef.current(ordered);
23930
+ };
23931
+ const up = (next) => {
23932
+ if (next.pointerId === pointerId) {
23933
+ lastY = next.clientY;
23934
+ update();
23935
+ finish(true);
23936
+ }
23937
+ };
23938
+ const cancel = () => finish(false);
23939
+ const cancelPointer = (next) => {
23940
+ if (next.pointerId === pointerId) cancel();
23941
+ };
23942
+ const escape = (next) => {
23943
+ if (next.key === "Escape") {
23944
+ next.preventDefault();
23945
+ next.stopImmediatePropagation();
23946
+ cancel();
23947
+ }
23948
+ };
23949
+ cancelRef.current = cancel;
23950
+ document.addEventListener("pointermove", move);
23951
+ document.addEventListener("pointerup", up);
23952
+ document.addEventListener("pointercancel", cancelPointer);
23953
+ target.addEventListener("lostpointercapture", cancel);
23954
+ window.addEventListener("blur", cancel);
23955
+ window.addEventListener("keydown", escape, true);
23956
+ frame = requestAnimationFrame(tick);
23957
+ }
23958
+ return { listRef, preview, start };
23959
+ }
23960
+
23961
+ // src/components/queryFormSettingsUtils.ts
23962
+ function reconcileQueryFields(keys, saved = []) {
23963
+ const stored = new Map(saved.map((item) => [item.key, item]));
23964
+ return keys.map((key, index) => ({
23965
+ key,
23966
+ visible: stored.get(key)?.visible !== false,
23967
+ order: Number.isFinite(stored.get(key)?.order) ? stored.get(key).order : Infinity,
23968
+ index
23969
+ })).sort((a, b) => a.order - b.order || a.index - b.index).map(({ key, visible }, order) => ({ key, visible, order }));
23970
+ }
23971
+ function mergeQueryFields(saved, active) {
23972
+ const current = new Set(active.map((item) => item.key));
23973
+ return [...active, ...saved.filter((item) => !current.has(item.key))];
23974
+ }
23975
+
23976
+ // src/components/QueryFormSettings.tsx
23808
23977
  var import_jsx_runtime91 = require("react/jsx-runtime");
23978
+ function useQueryFormSettings(config, fields, defaultCollapsed, applyCollapsed, disabled) {
23979
+ const [snapshot, setSnapshot] = (0, import_react95.useState)();
23980
+ const [draft, setDraft] = (0, import_react95.useState)({ fields: [], defaultCollapsed });
23981
+ const [open, setOpen] = (0, import_react95.useState)(false);
23982
+ const [loading, setLoading] = (0, import_react95.useState)(false);
23983
+ const [saving, setSaving] = (0, import_react95.useState)(false);
23984
+ const [error, setError] = (0, import_react95.useState)("");
23985
+ const [loadFailed, setLoadFailed] = (0, import_react95.useState)(false);
23986
+ const token = (0, import_react95.useRef)(0);
23987
+ const saveLock = (0, import_react95.useRef)(false);
23988
+ const latest = (0, import_react95.useRef)({ config, fields, defaultCollapsed, applyCollapsed });
23989
+ latest.current = { config, fields, defaultCollapsed, applyCollapsed };
23990
+ const moduleName = config?.scope.moduleName;
23991
+ const businessKey = config?.scope.businessKey;
23992
+ const adapter = config?.adapter;
23993
+ async function load(edit) {
23994
+ const current = latest.current;
23995
+ if (!current.config) return;
23996
+ const request = ++token.current;
23997
+ setLoading(true);
23998
+ setError("");
23999
+ setLoadFailed(false);
24000
+ try {
24001
+ const stored = (await current.config.adapter.load(current.config.scope))?.queryForm;
24002
+ if (request !== token.current) return;
24003
+ const next = stored ?? { fields: [], defaultCollapsed: current.defaultCollapsed };
24004
+ setSnapshot(next);
24005
+ setDraft({ ...next, fields: reconcileQueryFields(latest.current.fields.map((field) => field.key), next.fields) });
24006
+ if (!edit) latest.current.applyCollapsed(next.defaultCollapsed);
24007
+ } catch (reason) {
24008
+ if (request !== token.current) return;
24009
+ setLoadFailed(true);
24010
+ setError(reason instanceof Error ? reason.message : "\u8BFB\u53D6\u67E5\u8BE2\u8BBE\u7F6E\u5931\u8D25");
24011
+ current.config.onError?.(reason, "load");
24012
+ } finally {
24013
+ if (request === token.current) setLoading(false);
24014
+ }
24015
+ }
24016
+ (0, import_react95.useEffect)(() => {
24017
+ setSnapshot(void 0);
24018
+ setOpen(false);
24019
+ setError("");
24020
+ setLoadFailed(false);
24021
+ setLoading(false);
24022
+ setSaving(false);
24023
+ saveLock.current = false;
24024
+ latest.current.applyCollapsed(latest.current.defaultCollapsed);
24025
+ if (adapter) void load(false);
24026
+ return () => {
24027
+ token.current++;
24028
+ };
24029
+ }, [adapter, moduleName, businessKey]);
24030
+ async function save() {
24031
+ const current = latest.current;
24032
+ if (!current.config || loading || loadFailed || disabled || saveLock.current) return false;
24033
+ saveLock.current = true;
24034
+ setSaving(true);
24035
+ setError("");
24036
+ const request = token.current;
24037
+ const active = reconcileQueryFields(current.fields.map((field) => field.key), draft.fields);
24038
+ const next = { ...draft, fields: mergeQueryFields(snapshot?.fields ?? [], active) };
24039
+ try {
24040
+ await saveSettingsPatch(current.config.adapter, current.config.scope, { queryForm: next });
24041
+ if (request !== token.current) return false;
24042
+ setSnapshot(next);
24043
+ current.applyCollapsed(next.defaultCollapsed);
24044
+ setOpen(false);
24045
+ return true;
24046
+ } catch (reason) {
24047
+ if (request !== token.current) return false;
24048
+ setError(reason instanceof Error ? reason.message : "\u4FDD\u5B58\u67E5\u8BE2\u8BBE\u7F6E\u5931\u8D25");
24049
+ current.config.onError?.(reason, "save");
24050
+ return false;
24051
+ } finally {
24052
+ if (request === token.current) {
24053
+ saveLock.current = false;
24054
+ setSaving(false);
24055
+ }
24056
+ }
24057
+ }
24058
+ const visibleDraft = reconcileQueryFields(fields.map((field) => field.key), draft.fields);
24059
+ const labels = new Map(fields.map((field) => [field.key, field.label]));
24060
+ const locked = loading || saving || loadFailed || disabled;
24061
+ const move = (from, to) => {
24062
+ if (locked || from === to || to < 0 || to >= visibleDraft.length) return;
24063
+ const next = [...visibleDraft];
24064
+ next.splice(to, 0, next.splice(from, 1)[0]);
24065
+ setDraft((current) => ({ ...current, fields: next.map((item, order) => ({ ...item, order })) }));
24066
+ };
24067
+ const sort = useQueryFieldSort(visibleDraft.map((item) => item.key), open && !locked, (keys) => {
24068
+ const items = new Map(visibleDraft.map((item) => [item.key, item]));
24069
+ setDraft((current) => ({ ...current, fields: keys.map((key, order) => ({ ...items.get(key), order })) }));
24070
+ });
24071
+ const control = config ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24072
+ Button,
24073
+ {
24074
+ type: "button",
24075
+ className: "sia-query-settings__trigger",
24076
+ title: "\u67E5\u8BE2\u8BBE\u7F6E",
24077
+ "aria-label": "\u67E5\u8BE2\u8BBE\u7F6E",
24078
+ disabled: disabled || saving,
24079
+ loading: loading && !open,
24080
+ icon: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Icon, { name: "more-vertical" }),
24081
+ onClick: () => {
24082
+ setOpen(true);
24083
+ void load(true);
24084
+ }
24085
+ }
24086
+ ) : null;
24087
+ const panel = config ? /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)(import_jsx_runtime91.Fragment, { children: [
24088
+ !open && error ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("span", { className: "sia-query-form__error", role: "alert", children: "\u67E5\u8BE2\u8BBE\u7F6E\u8BFB\u53D6\u5931\u8D25\uFF0C\u8BF7\u6253\u5F00\u8BBE\u7F6E\u91CD\u8BD5" }) : null,
24089
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24090
+ Modal2,
24091
+ {
24092
+ title: "\u67E5\u8BE2\u8BBE\u7F6E",
24093
+ open,
24094
+ width: 520,
24095
+ okText: "\u4FDD\u5B58",
24096
+ confirmLoading: saving,
24097
+ okButtonProps: { disabled: locked },
24098
+ onOk: save,
24099
+ onOpenChange: (next) => {
24100
+ if (!saveLock.current) setOpen(next);
24101
+ },
24102
+ children: /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { className: "sia-query-settings", children: [
24103
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("p", { role: "status", children: "\u6B63\u5728\u8BFB\u53D6\u67E5\u8BE2\u8BBE\u7F6E\u2026" }) : null,
24104
+ error ? /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { role: "alert", className: "sia-query-form__error", children: [
24105
+ error,
24106
+ loadFailed ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Button, { type: "button", variant: "link", onClick: () => void load(true), children: "\u91CD\u8BD5" }) : null
24107
+ ] }) : null,
24108
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Checkbox2, { checked: draft.defaultCollapsed, disabled: locked, onChange: (checked) => setDraft((current) => ({ ...current, defaultCollapsed: checked })), children: "\u9ED8\u8BA4\u6536\u8D77\u67E5\u8BE2\u6761\u4EF6" }),
24109
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("p", { className: "sia-query-settings__hint", children: "\u52FE\u9009\u9700\u8981\u663E\u793A\u7684\u6761\u4EF6\uFF0C\u62D6\u52A8\u6216\u4F7F\u7528\u4E0A\u4E0B\u6309\u94AE\u8C03\u6574\u987A\u5E8F\u3002" }),
24110
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("div", { ref: sort.listRef, className: `sia-query-settings__list${sort.preview ? " is-sorting" : ""}`, children: visibleDraft.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)(
24111
+ "div",
24112
+ {
24113
+ "data-query-field-key": item.key,
24114
+ className: `sia-query-settings__item${sort.preview?.key === item.key ? " is-dragging" : ""}${locked ? " is-disabled" : ""}`,
24115
+ style: sort.preview ? { transform: `translateY(${sort.preview.offsets[item.key] ?? 0}px)` } : void 0,
24116
+ onPointerDown: (event) => sort.start(event, item.key),
24117
+ children: [
24118
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Icon, { name: "menu", size: 15 }),
24119
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Checkbox2, { "aria-label": `\u663E\u793A ${item.key}`, checked: item.visible, disabled: locked, onChange: (checked) => setDraft((current) => ({ ...current, fields: visibleDraft.map((field) => field.key === item.key ? { ...field, visible: checked } : field) })) }),
24120
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("span", { className: "sia-query-settings__name", children: labels.get(item.key) ?? item.key }),
24121
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { className: "sia-query-settings__order", children: [
24122
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Button, { type: "button", size: "small", variant: "text", "aria-label": `\u4E0A\u79FB ${item.key}`, disabled: locked || index === 0, icon: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Icon, { name: "chevron-up" }), onClick: () => move(index, index - 1) }),
24123
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Button, { type: "button", size: "small", variant: "text", "aria-label": `\u4E0B\u79FB ${item.key}`, disabled: locked || index === visibleDraft.length - 1, icon: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Icon, { name: "chevron-down" }), onClick: () => move(index, index + 1) })
24124
+ ] })
24125
+ ]
24126
+ },
24127
+ item.key
24128
+ )) }),
24129
+ /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Button, { type: "button", disabled: locked, onClick: () => setDraft({ fields: reconcileQueryFields(fields.map((field) => field.key)), defaultCollapsed }), children: "\u6062\u590D\u9ED8\u8BA4" })
24130
+ ] })
24131
+ }
24132
+ )
24133
+ ] }) : null;
24134
+ return { snapshot, control, panel };
24135
+ }
24136
+
24137
+ // src/components/QueryForm.tsx
24138
+ var import_jsx_runtime92 = require("react/jsx-runtime");
23809
24139
  function QueryForm({
23810
24140
  fields,
24141
+ settings,
23811
24142
  children,
23812
24143
  form: providedForm,
23813
24144
  onSearch,
@@ -23838,39 +24169,51 @@ function QueryForm({
23838
24169
  ...formProps
23839
24170
  }) {
23840
24171
  const [form] = useForm(providedForm);
23841
- const [internalCollapsed, setInternalCollapsed] = (0, import_react94.useState)(defaultCollapsed);
23842
- const [needsCollapse, setNeedsCollapse] = (0, import_react94.useState)(false);
24172
+ const [internalCollapsed, setInternalCollapsed] = (0, import_react96.useState)(defaultCollapsed);
24173
+ const [needsCollapse, setNeedsCollapse] = (0, import_react96.useState)(false);
23843
24174
  const collapsed = collapsible && needsCollapse && (controlledCollapsed ?? internalCollapsed);
23844
- const [searching, setSearching] = (0, import_react94.useState)(false);
23845
- const [saving, setSaving] = (0, import_react94.useState)(false);
23846
- const [removing, setRemoving] = (0, import_react94.useState)(false);
23847
- const [saveOpen, setSaveOpen] = (0, import_react94.useState)(false);
23848
- const [saveName, setSaveName] = (0, import_react94.useState)("");
23849
- const [saveError, setSaveError] = (0, import_react94.useState)("");
23850
- const [error, setError] = (0, import_react94.useState)("");
23851
- const [activeShortcut, setActiveShortcut] = (0, import_react94.useState)("");
23852
- const source = (0, import_react94.useRef)({ source: "submit" });
23853
- const searchLock = (0, import_react94.useRef)(false);
23854
- const saveLock = (0, import_react94.useRef)(false);
23855
- const removeLock = (0, import_react94.useRef)(false);
23856
- const snapshot = (0, import_react94.useRef)();
24175
+ const [searching, setSearching] = (0, import_react96.useState)(false);
24176
+ const [saving, setSaving] = (0, import_react96.useState)(false);
24177
+ const [removing, setRemoving] = (0, import_react96.useState)(false);
24178
+ const [saveOpen, setSaveOpen] = (0, import_react96.useState)(false);
24179
+ const [saveName, setSaveName] = (0, import_react96.useState)("");
24180
+ const [saveError, setSaveError] = (0, import_react96.useState)("");
24181
+ const [error, setError] = (0, import_react96.useState)("");
24182
+ const [activeShortcut, setActiveShortcut] = (0, import_react96.useState)("");
24183
+ const source = (0, import_react96.useRef)({ source: "submit" });
24184
+ const searchLock = (0, import_react96.useRef)(false);
24185
+ const saveLock = (0, import_react96.useRef)(false);
24186
+ const removeLock = (0, import_react96.useRef)(false);
24187
+ const snapshot = (0, import_react96.useRef)();
23857
24188
  const busy = disabled || loading || searching;
23858
24189
  const shortcutBusy = busy || shortcutsLoading || saving || removing;
23859
- const entries = fields ? fields.map(({ key, width, ...item }) => ({
24190
+ const fieldLabel = (content) => {
24191
+ if (!(0, import_react96.isValidElement)(content)) return void 0;
24192
+ return content.props.label ?? content.props.placeholder ?? fieldLabel(content.props.children);
24193
+ };
24194
+ const sourceEntries = fields ? fields.map(({ key, width, settingsLabel, ...item }) => ({
23860
24195
  key,
23861
24196
  width,
23862
- content: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Form.Item, { noStyle: true, ...item })
23863
- })) : import_react94.Children.toArray(children).map((content, index) => ({
23864
- key: String(index),
24197
+ label: settingsLabel ?? item.label ?? (typeof item.children === "function" ? void 0 : fieldLabel(item.children)) ?? key,
24198
+ content: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(Form.Item, { noStyle: true, ...item })
24199
+ })) : import_react96.Children.toArray(children).map((content, index) => ({
24200
+ key: (0, import_react96.isValidElement)(content) && content.key != null ? String(content.key) : String(index),
23865
24201
  width: void 0,
24202
+ label: fieldLabel(content) ?? `\u6761\u4EF6 ${index + 1}`,
23866
24203
  content
23867
24204
  }));
24205
+ const cloudSettings = useQueryFormSettings(settings, sourceEntries, defaultCollapsed, setInternalCollapsed, disabled);
24206
+ const configured = reconcileQueryFields(sourceEntries.map((entry) => entry.key), cloudSettings.snapshot?.fields);
24207
+ const entriesByKey = new Map(sourceEntries.map((entry) => [entry.key, entry]));
24208
+ let visibleIndex = 0;
24209
+ const entries = configured.map((item) => ({ ...entriesByKey.get(item.key), visible: item.visible, visibleIndex: item.visible ? visibleIndex++ : -1 }));
24210
+ const layoutKey = JSON.stringify(configured);
23868
24211
  const limit = Math.max(1, Math.floor(collapsedCount));
23869
- const rowRef = (0, import_react94.useRef)(null);
23870
- const actionsRef = (0, import_react94.useRef)(null);
23871
- const toggleRef = (0, import_react94.useRef)(null);
23872
- const [fittingCount, setFittingCount] = (0, import_react94.useState)(limit);
23873
- (0, import_react94.useLayoutEffect)(() => {
24212
+ const rowRef = (0, import_react96.useRef)(null);
24213
+ const actionsRef = (0, import_react96.useRef)(null);
24214
+ const toggleRef = (0, import_react96.useRef)(null);
24215
+ const [fittingCount, setFittingCount] = (0, import_react96.useState)(limit);
24216
+ (0, import_react96.useLayoutEffect)(() => {
23874
24217
  const row = rowRef.current;
23875
24218
  const actions = actionsRef.current;
23876
24219
  if (!row || !actions) return;
@@ -23878,7 +24221,7 @@ function QueryForm({
23878
24221
  if (!row || !actions) return;
23879
24222
  const gap = parseFloat(getComputedStyle(row).columnGap) || 0;
23880
24223
  const allFields = Array.from(
23881
- row.querySelectorAll(":scope > .sia-query-form__field")
24224
+ row.querySelectorAll(":scope > .sia-query-form__field:not([data-settings-hidden])")
23882
24225
  );
23883
24226
  const hiddenFields = allFields.filter((field) => field.hidden);
23884
24227
  const wasCollapsed = row.classList.contains("is-collapsed");
@@ -23920,6 +24263,7 @@ function QueryForm({
23920
24263
  return () => observer.disconnect();
23921
24264
  }, [
23922
24265
  collapsed,
24266
+ layoutKey,
23923
24267
  needsCollapse,
23924
24268
  collapsible,
23925
24269
  limit,
@@ -24008,8 +24352,8 @@ function QueryForm({
24008
24352
  setRemoving(false);
24009
24353
  }
24010
24354
  }
24011
- return /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { className: `sia-query-form ${className}`.trim(), children: [
24012
- /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)(
24355
+ return /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)("div", { className: `sia-query-form ${className}`.trim(), children: [
24356
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(
24013
24357
  Form,
24014
24358
  {
24015
24359
  ...formProps,
@@ -24028,8 +24372,8 @@ function QueryForm({
24028
24372
  onValuesChange?.(changed, values);
24029
24373
  },
24030
24374
  children: [
24031
- quickQueries.length ? /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { className: "sia-query-form__quick", "aria-label": "\u9884\u8BBE\u5FEB\u6377\u67E5\u8BE2", children: [
24032
- quickQueries.map((query) => /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24375
+ quickQueries.length ? /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)("div", { className: "sia-query-form__quick", "aria-label": "\u9884\u8BBE\u5FEB\u6377\u67E5\u8BE2", children: [
24376
+ quickQueries.map((query) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24033
24377
  Badge,
24034
24378
  {
24035
24379
  className: "sia-query-form__quick-badge",
@@ -24038,7 +24382,7 @@ function QueryForm({
24038
24382
  title: query.count === void 0 ? void 0 : `\u5171 ${query.count} \u6761`,
24039
24383
  ...query.badgeProps,
24040
24384
  count: query.count,
24041
- children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24385
+ children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24042
24386
  Button,
24043
24387
  {
24044
24388
  size: query.size ?? quickQuerySize,
@@ -24054,7 +24398,7 @@ function QueryForm({
24054
24398
  )),
24055
24399
  " "
24056
24400
  ] }) : null,
24057
- /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)(
24401
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(
24058
24402
  "div",
24059
24403
  {
24060
24404
  ref: rowRef,
@@ -24063,11 +24407,12 @@ function QueryForm({
24063
24407
  "--sia-query-field-width": typeof fieldWidth === "number" ? `${fieldWidth}px` : fieldWidth
24064
24408
  },
24065
24409
  children: [
24066
- entries.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24410
+ entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24067
24411
  "div",
24068
24412
  {
24069
24413
  className: "sia-query-form__field",
24070
- hidden: collapsed && index >= Math.min(limit, fittingCount),
24414
+ "data-settings-hidden": !entry.visible || void 0,
24415
+ hidden: !entry.visible || collapsed && entry.visibleIndex >= Math.min(limit, fittingCount),
24071
24416
  style: entry.width !== void 0 ? {
24072
24417
  "--sia-query-item-width": typeof entry.width === "number" ? `${entry.width}px` : entry.width
24073
24418
  } : void 0,
@@ -24075,9 +24420,9 @@ function QueryForm({
24075
24420
  },
24076
24421
  entry.key
24077
24422
  )),
24078
- /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { ref: actionsRef, className: "sia-query-form__actions", children: [
24079
- /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)(Space.Compact, { children: [
24080
- /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24423
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)("div", { ref: actionsRef, className: "sia-query-form__actions", children: [
24424
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(Space.Compact, { children: [
24425
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24081
24426
  Button,
24082
24427
  {
24083
24428
  type: "submit",
@@ -24087,8 +24432,8 @@ function QueryForm({
24087
24432
  children: searchText
24088
24433
  }
24089
24434
  ),
24090
- /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Button, { disabled: busy, onClick: reset, children: resetText }),
24091
- onSaveQuery ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24435
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(Button, { disabled: busy, onClick: reset, children: resetText }),
24436
+ onSaveQuery ? /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24092
24437
  Button,
24093
24438
  {
24094
24439
  disabled: shortcutBusy,
@@ -24100,14 +24445,15 @@ function QueryForm({
24100
24445
  },
24101
24446
  children: saveText
24102
24447
  }
24103
- ) : null
24448
+ ) : null,
24449
+ cloudSettings.control
24104
24450
  ] }),
24105
- collapsible && entries.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("span", { ref: toggleRef, hidden: !needsCollapse, children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24451
+ collapsible && entries.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("span", { ref: toggleRef, hidden: !needsCollapse, children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24106
24452
  Button,
24107
24453
  {
24108
24454
  variant: "link",
24109
24455
  "aria-expanded": !collapsed,
24110
- icon: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Icon, { name: collapsed ? "chevron-down" : "chevron-up" }),
24456
+ icon: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(Icon, { name: collapsed ? "chevron-down" : "chevron-up" }),
24111
24457
  iconPosition: "end",
24112
24458
  onClick: () => {
24113
24459
  setInternalCollapsed(!collapsed);
@@ -24116,13 +24462,14 @@ function QueryForm({
24116
24462
  children: collapsed ? "\u5C55\u5F00" : "\u6536\u8D77"
24117
24463
  }
24118
24464
  ) }) : null,
24119
- actionsExtra
24465
+ actionsExtra,
24466
+ cloudSettings.panel
24120
24467
  ] })
24121
24468
  ]
24122
24469
  }
24123
24470
  ),
24124
- savedQueries.length ? /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)("div", { className: "sia-query-form__saved", "aria-label": "\u5DF2\u4FDD\u5B58\u5FEB\u6377\u67E5\u8BE2", children: [
24125
- savedQueries.map((query, index) => /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24471
+ savedQueries.length ? /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)("div", { className: "sia-query-form__saved", "aria-label": "\u5DF2\u4FDD\u5B58\u5FEB\u6377\u67E5\u8BE2", children: [
24472
+ savedQueries.map((query, index) => /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24126
24473
  Tag,
24127
24474
  {
24128
24475
  status: query.status ?? ["processing", "success", "warning", "error"][index % 4],
@@ -24148,11 +24495,11 @@ function QueryForm({
24148
24495
  )),
24149
24496
  " "
24150
24497
  ] }) : null,
24151
- error ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("p", { className: "sia-query-form__error", role: "alert", children: error }) : null
24498
+ error ? /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("p", { className: "sia-query-form__error", role: "alert", children: error }) : null
24152
24499
  ]
24153
24500
  }
24154
24501
  ),
24155
- /* @__PURE__ */ (0, import_jsx_runtime91.jsxs)(
24502
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(
24156
24503
  Modal2,
24157
24504
  {
24158
24505
  open: saveOpen,
@@ -24164,7 +24511,7 @@ function QueryForm({
24164
24511
  if (!saveLock.current) setSaveOpen(next);
24165
24512
  },
24166
24513
  children: [
24167
- /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
24514
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24168
24515
  Input,
24169
24516
  {
24170
24517
  autoFocus: true,
@@ -24183,7 +24530,7 @@ function QueryForm({
24183
24530
  }
24184
24531
  }
24185
24532
  ),
24186
- saveError ? /* @__PURE__ */ (0, import_jsx_runtime91.jsx)("p", { className: "sia-query-form__error", role: "alert", children: saveError }) : null
24533
+ saveError ? /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("p", { className: "sia-query-form__error", role: "alert", children: saveError }) : null
24187
24534
  ]
24188
24535
  }
24189
24536
  )
@@ -24191,9 +24538,9 @@ function QueryForm({
24191
24538
  }
24192
24539
 
24193
24540
  // src/components/NumberRange.tsx
24194
- var import_react95 = require("react");
24195
- var import_jsx_runtime92 = require("react/jsx-runtime");
24196
- var NumberRange = (0, import_react95.forwardRef)(function NumberRange2({
24541
+ var import_react97 = require("react");
24542
+ var import_jsx_runtime93 = require("react/jsx-runtime");
24543
+ var NumberRange = (0, import_react97.forwardRef)(function NumberRange2({
24197
24544
  value,
24198
24545
  defaultValue = [null, null],
24199
24546
  onChange,
@@ -24221,7 +24568,7 @@ var NumberRange = (0, import_react95.forwardRef)(function NumberRange2({
24221
24568
  setValue2(index === 0 ? [next, range[1]] : [range[0], next]);
24222
24569
  }
24223
24570
  const inputProps = { min, max, step, precision, size, status, disabled, readOnly, placeholderMode, controls: false };
24224
- return /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(
24571
+ return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
24225
24572
  "span",
24226
24573
  {
24227
24574
  ...props,
@@ -24230,7 +24577,7 @@ var NumberRange = (0, import_react95.forwardRef)(function NumberRange2({
24230
24577
  "aria-disabled": disabled || void 0,
24231
24578
  className: `sia-number-range sia-number-range--${size} sia-number-range--${status}${disabled ? " is-disabled" : ""} ${className}`.trim(),
24232
24579
  children: [
24233
- /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24580
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
24234
24581
  InputNumber,
24235
24582
  {
24236
24583
  ...inputProps,
@@ -24242,8 +24589,8 @@ var NumberRange = (0, import_react95.forwardRef)(function NumberRange2({
24242
24589
  onChange: (next) => change(0, next)
24243
24590
  }
24244
24591
  ),
24245
- /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(Icon, { className: "sia-number-range__separator", name: "tilde", size: 12, strokeWidth: 1.5, "aria-hidden": "true" }),
24246
- /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
24592
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(Icon, { className: "sia-number-range__separator", name: "tilde", size: 12, strokeWidth: 1.5, "aria-hidden": "true" }),
24593
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
24247
24594
  InputNumber,
24248
24595
  {
24249
24596
  ...inputProps,
@@ -24255,7 +24602,7 @@ var NumberRange = (0, import_react95.forwardRef)(function NumberRange2({
24255
24602
  onChange: (next) => change(1, next)
24256
24603
  }
24257
24604
  ),
24258
- allowClear && !disabled && !readOnly && range.some((item) => item !== null) ? /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("button", { type: "button", className: "sia-number-range__clear", "aria-label": "\u6E05\u9664\u6570\u5B57\u533A\u95F4", onClick: () => setValue2([null, null]), children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null
24605
+ allowClear && !disabled && !readOnly && range.some((item) => item !== null) ? /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("button", { type: "button", className: "sia-number-range__clear", "aria-label": "\u6E05\u9664\u6570\u5B57\u533A\u95F4", onClick: () => setValue2([null, null]), children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null
24259
24606
  ]
24260
24607
  }
24261
24608
  );