@vanstack/solid-ark 0.0.46 → 0.0.47

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.
@@ -2,7 +2,7 @@ import "../solid-ark.css";
2
2
  import { t as e } from "../button-Br_upy12.js";
3
3
  import { t } from "../badge-Dt0uZnmA.js";
4
4
  import { t as n } from "../form-CnlzjZZ1.js";
5
- import { t as r } from "../table-ByBUErrC.js";
5
+ import { t as r } from "../table-CtYq69-7.js";
6
6
  import { className as i, createComponent as a, effect as o, insert as s, memo as c, setAttribute as l, setStyleProperty as u, template as d, use as f } from "solid-js/web";
7
7
  import { For as p, Show as m, createEffect as ee, createMemo as h, createSignal as g, mergeProps as _, on as v, onCleanup as te, onMount as y } from "solid-js";
8
8
  import { formatDate as b, formatDateTime as ne, formatShortDateTime as re } from "@vanstack/shared";
@@ -75,8 +75,9 @@ interface DataTableBaseProps<TData, TSearch extends Record<string, unknown>, TQu
75
75
  rowId?: (row: TData) => string;
76
76
  /** 是否显示选择列,默认取 !!onSelectionChange */
77
77
  selectable?: boolean;
78
- /** 初始选中行 ID */
78
+ /** 选中行 ID;传入后进入受控选择模式,不传则由组件内部维护 */
79
79
  selectedRowIds?: string[];
80
+ /** 选择变化回调;受控模式下父组件应将结果回写到 selectedRowIds */
80
81
  onSelectionChange?: (ids: string[]) => void;
81
82
  /** 受控模式的加载态;内部模式由组件自行管理 */
82
83
  loading?: boolean;
@@ -1,3 +1,3 @@
1
1
  import "../solid-ark.css";
2
- import { t as e } from "../table-ByBUErrC.js";
2
+ import { t as e } from "../table-CtYq69-7.js";
3
3
  export { e as Table };
@@ -0,0 +1,9 @@
1
+ import { RowSelectionState } from '@tanstack/solid-table';
2
+ interface RowSelectionProps {
3
+ selectedRowIds?: string[];
4
+ }
5
+ export declare function createRowSelection(props: RowSelectionProps): {
6
+ applyRowSelection: (next: RowSelectionState) => string[];
7
+ rowSelection: () => RowSelectionState;
8
+ };
9
+ export {};
@@ -7,12 +7,12 @@ export interface TableProps<TData> {
7
7
  onSortingChange?: (sorting: SortingState) => void;
8
8
  /** 是否启用行选择 */
9
9
  selectable?: boolean;
10
- /** 初始选中行 ID */
10
+ /** 选中行 ID;传入后进入受控选择模式,不传则由组件内部维护 */
11
11
  selectedRowIds?: string[];
12
+ /** 选择变化通知;受控模式下父组件应将结果回写到 selectedRowIds */
13
+ onSelectionChange?: (selectedIds: string[]) => void;
12
14
  /** 行 ID 提取函数,默认取 row.id */
13
15
  rowId?: (row: TData) => string;
14
- /** 选择变化通知 */
15
- onSelectionChange?: (selectedIds: string[]) => void;
16
16
  /** 加载态 */
17
17
  loading?: boolean;
18
18
  /** 空状态文案 */
@@ -3,20 +3,32 @@ import { addEventListener as e, className as t, createComponent as n, delegateEv
3
3
  import { For as u, Show as d, createSignal as f, mergeProps as p } from "solid-js";
4
4
  import { Checkbox as m } from "@ark-ui/solid/checkbox";
5
5
  import { createSolidTable as h, flexRender as g, getCoreRowModel as _, getSortedRowModel as v } from "@tanstack/solid-table";
6
+ //#region src/table/selection.ts
7
+ function y(e) {
8
+ return Object.fromEntries((e ?? []).map((e) => [e, !0]));
9
+ }
10
+ function b(e) {
11
+ let t = () => e.selectedRowIds !== void 0, [n, r] = f(y(e.selectedRowIds));
12
+ return {
13
+ applyRowSelection: (e) => (t() || r(e), Object.keys(e).filter((t) => e[t])),
14
+ rowSelection: () => t() ? y(e.selectedRowIds) : n()
15
+ };
16
+ }
17
+ //#endregion
6
18
  //#region src/table/Table.tsx
7
- var y = /*#__PURE__*/ l("<svg class=van-table-sort-icon viewBox=\"0 0 8 14\"xmlns=http://www.w3.org/2000/svg><polyline fill=none points=\"1,5 4,2 7,5\"stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=1.5></polyline><polyline fill=none points=\"1,9 4,12 7,9\"stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=1.5>"), b = /*#__PURE__*/ l("<svg class=van-table-check-icon fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=3 viewBox=\"0 0 24 24\"><path d=\"M5 12l5 5l10 -10\">"), x = /*#__PURE__*/ l("<svg class=van-table-check-icon fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=3 viewBox=\"0 0 24 24\"><path d=\"M5 12h14\">"), S = /*#__PURE__*/ l("<tr>"), C = /*#__PURE__*/ l("<th>"), w = /*#__PURE__*/ l("<span class=van-table-th-content>"), T = /*#__PURE__*/ l("<td>"), E = /*#__PURE__*/ l("<div class=van-table-loading-mask><div class=van-table-spinner>"), D = /*#__PURE__*/ l("<div><div class=van-table-container><table class=van-table><thead></thead><tbody>"), O = /*#__PURE__*/ l("<tr><td class=van-table-empty>");
8
- function k(e, t) {
19
+ var x = /*#__PURE__*/ l("<svg class=van-table-sort-icon viewBox=\"0 0 8 14\"xmlns=http://www.w3.org/2000/svg><polyline fill=none points=\"1,5 4,2 7,5\"stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=1.5></polyline><polyline fill=none points=\"1,9 4,12 7,9\"stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=1.5>"), S = /*#__PURE__*/ l("<svg class=van-table-check-icon fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=3 viewBox=\"0 0 24 24\"><path d=\"M5 12l5 5l10 -10\">"), C = /*#__PURE__*/ l("<svg class=van-table-check-icon fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=3 viewBox=\"0 0 24 24\"><path d=\"M5 12h14\">"), w = /*#__PURE__*/ l("<tr>"), T = /*#__PURE__*/ l("<th>"), E = /*#__PURE__*/ l("<span class=van-table-th-content>"), D = /*#__PURE__*/ l("<td>"), O = /*#__PURE__*/ l("<div class=van-table-loading-mask><div class=van-table-spinner>"), k = /*#__PURE__*/ l("<div><div class=van-table-container><table class=van-table><thead></thead><tbody>"), A = /*#__PURE__*/ l("<tr><td class=van-table-empty>");
20
+ function j(e, t) {
9
21
  return typeof e == "function" ? e(t) : e;
10
22
  }
11
- function A(e) {
23
+ function M(e) {
12
24
  let t = {};
13
25
  e.columnDef.size !== void 0 && (t.width = `${e.columnDef.size}px`, t["min-width"] = `${e.columnDef.size}px`, t["max-width"] = `${e.columnDef.size}px`);
14
26
  let n = e.columnDef.meta;
15
27
  return n?.align && (t["text-align"] = n.align), n?.nowrap && (t["white-space"] = "nowrap"), Object.keys(t).length > 0 ? t : void 0;
16
28
  }
17
- function j(e) {
29
+ function N(e) {
18
30
  return (() => {
19
- var t = y(), n = t.firstChild, r = n.nextSibling;
31
+ var t = x(), n = t.firstChild, r = n.nextSibling;
20
32
  return i((t) => {
21
33
  var i = `van-table-sort-arrow${e.state === "asc" ? " van-table-sort-active" : ""}`, a = `van-table-sort-arrow${e.state === "desc" ? " van-table-sort-active" : ""}`;
22
34
  return i !== t.e && s(n, "class", t.e = i), a !== t.t && s(r, "class", t.t = a), t;
@@ -26,27 +38,27 @@ function j(e) {
26
38
  }), t;
27
39
  })();
28
40
  }
29
- function M() {
30
- return b();
41
+ function P() {
42
+ return S();
31
43
  }
32
- function N() {
33
- return x();
44
+ function F() {
45
+ return C();
34
46
  }
35
- function P(r) {
47
+ function I(r) {
36
48
  let l = p({
37
49
  emptyText: "暂无数据",
38
50
  selectable: !1,
39
51
  loading: !1,
40
52
  rowId: (e) => e.id
41
- }, r), [y, b] = f([]), [x, P] = f(l.selectedRowIds?.length ? Object.fromEntries(l.selectedRowIds.map((e) => [e, !0])) : {}), F = {
53
+ }, r), [y, x] = f([]), { applyRowSelection: S, rowSelection: C } = b(r), I = {
42
54
  id: "__select__",
43
55
  header: () => n(m.Root, {
44
56
  get checked() {
45
- return o(() => !!I.getIsAllPageRowsSelected())() ? !0 : I.getIsSomePageRowsSelected() ? "indeterminate" : !1;
57
+ return o(() => !!L.getIsAllPageRowsSelected())() ? !0 : L.getIsSomePageRowsSelected() ? "indeterminate" : !1;
46
58
  },
47
59
  onCheckedChange: (e) => {
48
60
  let t = e.checked !== "indeterminate" && e.checked;
49
- I.toggleAllPageRowsSelected(t);
61
+ L.toggleAllPageRowsSelected(t);
50
62
  },
51
63
  onClick: (e) => e.stopPropagation(),
52
64
  get children() {
@@ -56,13 +68,13 @@ function P(r) {
56
68
  return [n(m.Indicator, {
57
69
  class: "van-table-checkbox-indicator",
58
70
  get children() {
59
- return n(M, {});
71
+ return n(P, {});
60
72
  }
61
73
  }), n(m.Indicator, {
62
74
  class: "van-table-checkbox-indicator",
63
75
  indeterminate: !0,
64
76
  get children() {
65
- return n(N, {});
77
+ return n(F, {});
66
78
  }
67
79
  })];
68
80
  }
@@ -82,7 +94,7 @@ function P(r) {
82
94
  return n(m.Indicator, {
83
95
  class: "van-table-checkbox-indicator",
84
96
  get children() {
85
- return n(M, {});
97
+ return n(P, {});
86
98
  }
87
99
  });
88
100
  }
@@ -95,43 +107,43 @@ function P(r) {
95
107
  enableSorting: !1,
96
108
  enableColumnFilter: !1,
97
109
  enableHiding: !1
98
- }, I = h({
110
+ }, L = h({
99
111
  get data() {
100
112
  return l.data;
101
113
  },
102
114
  get columns() {
103
- return l.selectable ? [F, ...l.columns] : l.columns;
115
+ return l.selectable ? [I, ...l.columns] : l.columns;
104
116
  },
105
117
  state: {
106
118
  get sorting() {
107
119
  return y();
108
120
  },
109
121
  get rowSelection() {
110
- return x();
122
+ return C();
111
123
  }
112
124
  },
113
125
  onSortingChange: (e) => {
114
- b(e), l.onSortingChange?.(k(e, y()));
126
+ x(e), l.onSortingChange?.(j(e, y()));
115
127
  },
116
128
  onRowSelectionChange: (e) => {
117
- let t = k(e, x());
118
- P(t), l.onSelectionChange?.(Object.keys(t).filter((e) => t[e]));
129
+ let t = j(e, C());
130
+ l.onSelectionChange?.(S(t));
119
131
  },
120
132
  getCoreRowModel: _(),
121
133
  getSortedRowModel: v(),
122
134
  enableRowSelection: l.selectable,
123
135
  getRowId: (e) => l.rowId(e),
124
136
  defaultColumn: { enableSorting: !1 }
125
- }), L = (e) => e === "__select__";
126
- function R(r) {
137
+ }), R = (e) => e === "__select__";
138
+ function z(r) {
127
139
  return (() => {
128
- var o = S();
140
+ var o = w();
129
141
  return a(o, n(u, {
130
142
  get each() {
131
143
  return r.headerGroup.headers;
132
144
  },
133
145
  children: (r) => (() => {
134
- var o = C();
146
+ var o = T();
135
147
  return e(o, "click", r.column.getToggleSortingHandler(), !0), a(o, n(d, {
136
148
  get when() {
137
149
  return !r.isPlaceholder;
@@ -140,13 +152,13 @@ function P(r) {
140
152
  return n(d, {
141
153
  get fallback() {
142
154
  return (() => {
143
- var e = w();
155
+ var e = E();
144
156
  return a(e, () => g(r.column.columnDef.header, r.getContext()), null), a(e, n(d, {
145
157
  get when() {
146
158
  return r.column.getCanSort();
147
159
  },
148
160
  get children() {
149
- return n(j, { get state() {
161
+ return n(N, { get state() {
150
162
  return r.column.getIsSorted();
151
163
  } });
152
164
  }
@@ -154,7 +166,7 @@ function P(r) {
154
166
  })();
155
167
  },
156
168
  get when() {
157
- return L(r.column.id);
169
+ return R(r.column.id);
158
170
  },
159
171
  get children() {
160
172
  return g(r.column.columnDef.header, r.getContext());
@@ -162,7 +174,7 @@ function P(r) {
162
174
  });
163
175
  }
164
176
  })), i((e) => {
165
- var n = `van-table-th${r.column.getCanSort() ? " van-table-th-sortable" : ""}${L(r.column.id) ? " van-table-th-select" : ""}`, i = r.colSpan, a = A(r.column);
177
+ var n = `van-table-th${r.column.getCanSort() ? " van-table-th-sortable" : ""}${R(r.column.id) ? " van-table-th-select" : ""}`, i = r.colSpan, a = M(r.column);
166
178
  return n !== e.e && t(o, e.e = n), i !== e.t && s(o, "colspan", e.t = i), e.a = c(o, a, e.a), e;
167
179
  }, {
168
180
  e: void 0,
@@ -173,17 +185,17 @@ function P(r) {
173
185
  })), o;
174
186
  })();
175
187
  }
176
- function z(r) {
188
+ function B(r) {
177
189
  return (() => {
178
- var o = S();
190
+ var o = w();
179
191
  return e(o, "click", l.onRowClick ? () => l.onRowClick(r.row.original, r.index) : void 0, !0), a(o, n(u, {
180
192
  get each() {
181
193
  return r.row.getVisibleCells();
182
194
  },
183
195
  children: (e) => (() => {
184
- var n = T();
196
+ var n = D();
185
197
  return a(n, () => g(e.column.columnDef.cell, e.getContext())), i((r) => {
186
- var i = `van-table-td${L(e.column.id) ? " van-table-td-select" : ""}`, a = A(e.column);
198
+ var i = `van-table-td${R(e.column.id) ? " van-table-td-select" : ""}`, a = M(e.column);
187
199
  return i !== r.e && t(n, r.e = i), r.t = c(n, a, r.t), r;
188
200
  }, {
189
201
  e: void 0,
@@ -199,37 +211,37 @@ function P(r) {
199
211
  }), o;
200
212
  })();
201
213
  }
202
- let B = () => l.columns.length + +!!l.selectable;
214
+ let V = () => l.columns.length + +!!l.selectable;
203
215
  return (() => {
204
- var e = D(), o = e.firstChild, c = o.firstChild, f = c.firstChild, p = f.nextSibling;
216
+ var e = k(), o = e.firstChild, c = o.firstChild, f = c.firstChild, p = f.nextSibling;
205
217
  return a(o, n(d, {
206
218
  get when() {
207
219
  return l.loading;
208
220
  },
209
221
  get children() {
210
- return E();
222
+ return O();
211
223
  }
212
224
  }), c), a(f, n(u, {
213
225
  get each() {
214
- return I.getHeaderGroups();
226
+ return L.getHeaderGroups();
215
227
  },
216
- children: (e) => n(R, { headerGroup: e })
228
+ children: (e) => n(z, { headerGroup: e })
217
229
  })), a(p, n(d, {
218
230
  get fallback() {
219
231
  return (() => {
220
- var e = O(), t = e.firstChild;
221
- return a(t, () => l.emptyText), i(() => s(t, "colspan", B())), e;
232
+ var e = A(), t = e.firstChild;
233
+ return a(t, () => l.emptyText), i(() => s(t, "colspan", V())), e;
222
234
  })();
223
235
  },
224
236
  get when() {
225
- return I.getRowModel().rows.length > 0;
237
+ return L.getRowModel().rows.length > 0;
226
238
  },
227
239
  get children() {
228
240
  return n(u, {
229
241
  get each() {
230
- return I.getRowModel().rows;
242
+ return L.getRowModel().rows;
231
243
  },
232
- children: (e, t) => n(z, {
244
+ children: (e, t) => n(B, {
233
245
  get index() {
234
246
  return t();
235
247
  },
@@ -242,4 +254,4 @@ function P(r) {
242
254
  }
243
255
  r(["click"]);
244
256
  //#endregion
245
- export { P as t };
257
+ export { I as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanstack/solid-ark",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -72,10 +72,10 @@
72
72
  "vite-plugin-solid": "^2.11.0",
73
73
  "vitest": "^4.1.10",
74
74
  "zod": "^4.4.0",
75
- "@vanstack/vite-config": "0.0.2",
76
- "@vanstack/prettier-config": "0.0.1",
77
75
  "@vanstack/eslint-config": "0.0.1",
78
- "@vanstack/tsconfig": "0.0.1"
76
+ "@vanstack/tsconfig": "0.0.1",
77
+ "@vanstack/vite-config": "0.0.2",
78
+ "@vanstack/prettier-config": "0.0.1"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsc --noEmit && vite build",