@sia.soul/sia-react-ui 0.1.64 → 0.1.65

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
@@ -13092,7 +13092,6 @@ function TableSelectedItemsPanel({
13092
13092
  }
13093
13093
  function createSelectionPlugin(options = {}) {
13094
13094
  const { mode = "multiple", childrenColumnName = "children" } = options;
13095
- const preservedRows = /* @__PURE__ */ new Map();
13096
13095
  function selected(context) {
13097
13096
  return options.selectedKeys ?? context.state.selectedKeys ?? [];
13098
13097
  }
@@ -13103,6 +13102,7 @@ function createSelectionPlugin(options = {}) {
13103
13102
  return flattenRecords(context.sourceData, childrenColumnName);
13104
13103
  }
13105
13104
  function entriesForKeys(keys, context) {
13105
+ const preservedRows = context.state.preservedRows;
13106
13106
  const records = allRecords(context);
13107
13107
  const currentRows = new Map(
13108
13108
  records.map(
@@ -13137,7 +13137,7 @@ function createSelectionPlugin(options = {}) {
13137
13137
  return entriesForKeys(keys, context).map((entry) => entry.record);
13138
13138
  }
13139
13139
  function setKeys(keys, context) {
13140
- if (keys.length === 0) preservedRows.clear();
13140
+ if (keys.length === 0) context.state.preservedRows.clear();
13141
13141
  context.setState((state) => ({
13142
13142
  ...state,
13143
13143
  selectedKeys: keys,
@@ -13153,7 +13153,7 @@ function createSelectionPlugin(options = {}) {
13153
13153
  (key) => pageKeys.has(key)
13154
13154
  );
13155
13155
  setKeys(currentPageKeys, context);
13156
- preservedRows.clear();
13156
+ context.state.preservedRows.clear();
13157
13157
  }
13158
13158
  context.setState((state) => ({
13159
13159
  ...state,
@@ -13175,11 +13175,13 @@ function createSelectionPlugin(options = {}) {
13175
13175
  return {
13176
13176
  id: "selection",
13177
13177
  order: 20,
13178
- initialState: {
13178
+ // 用工厂给每个表格创建独立缓存,避免同一插件对象被多个表格复用时串数据。
13179
+ initialState: () => ({
13180
+ preservedRows: /* @__PURE__ */ new Map(),
13179
13181
  selectedKeys: options.defaultSelectedKeys ?? [],
13180
13182
  preserveSelectedRowKeys: options.preserveSelectedRowKeys ?? false,
13181
13183
  panelOpen: false
13182
- },
13184
+ }),
13183
13185
  transformColumns(columns, context) {
13184
13186
  if (mode === "row") return columns;
13185
13187
  const selectionColumn = {
@@ -13327,7 +13329,7 @@ function createSelectionPlugin(options = {}) {
13327
13329
  const records = allRecords(context);
13328
13330
  const record = records.find(
13329
13331
  (item, index) => Object.is(context.getRowKey(item, index), key)
13330
- ) ?? preservedRows.get(key);
13332
+ ) ?? context.state.preservedRows.get(key);
13331
13333
  if (record) toggle(key, record, context, checked);
13332
13334
  },
13333
13335
  getSelectedRows: () => rowsForKeys(selected(context), context),
package/dist/index.d.cts CHANGED
@@ -2430,7 +2430,9 @@ interface TableSelectionPluginOptions<T> {
2430
2430
  childrenColumnName?: string;
2431
2431
  }
2432
2432
  /** 行勾选和已选面板状态。 */
2433
- interface SelectionState {
2433
+ interface SelectionState<T> {
2434
+ /** 当前表格独立保存的跨页行缓存,重建插件时保留,表格卸载后释放。 */
2435
+ preservedRows: Map<TableKey, T>;
2434
2436
  /** 当前选中的行标识。 */
2435
2437
  selectedKeys: readonly TableKey[];
2436
2438
  /** 是否跨页保留选中行。 */
@@ -2455,8 +2457,8 @@ interface TableSelectionApi<T> {
2455
2457
  /** 设置是否跨页保留选中行。 */
2456
2458
  setPreserveSelectedRowKeys: (preserve: boolean) => void;
2457
2459
  }
2458
- /** 创建表格行勾选插件。将返回值加入 Table 的 plugins 后生效。 */
2459
- declare function createSelectionPlugin<T extends Record<string, unknown>>(options?: TableSelectionPluginOptions<T>): TablePlugin<T, SelectionState, TableSelectionApi<T>>;
2460
+ /** 创建表格行勾选插件。将返回值加入 Table 的 plugins 后生效;跨页行缓存属于表格实例,重新创建插件不会清空缓存,不同表格互不共享。 */
2461
+ declare function createSelectionPlugin<T extends Record<string, unknown>>(options?: TableSelectionPluginOptions<T>): TablePlugin<T, SelectionState<T>, TableSelectionApi<T>>;
2460
2462
  /** TableSort的插件配置。 */
2461
2463
  interface TableSortPluginOptions {
2462
2464
  /** 展示或交互模式;可选值见类型定义。 */
package/dist/index.d.ts CHANGED
@@ -2430,7 +2430,9 @@ interface TableSelectionPluginOptions<T> {
2430
2430
  childrenColumnName?: string;
2431
2431
  }
2432
2432
  /** 行勾选和已选面板状态。 */
2433
- interface SelectionState {
2433
+ interface SelectionState<T> {
2434
+ /** 当前表格独立保存的跨页行缓存,重建插件时保留,表格卸载后释放。 */
2435
+ preservedRows: Map<TableKey, T>;
2434
2436
  /** 当前选中的行标识。 */
2435
2437
  selectedKeys: readonly TableKey[];
2436
2438
  /** 是否跨页保留选中行。 */
@@ -2455,8 +2457,8 @@ interface TableSelectionApi<T> {
2455
2457
  /** 设置是否跨页保留选中行。 */
2456
2458
  setPreserveSelectedRowKeys: (preserve: boolean) => void;
2457
2459
  }
2458
- /** 创建表格行勾选插件。将返回值加入 Table 的 plugins 后生效。 */
2459
- declare function createSelectionPlugin<T extends Record<string, unknown>>(options?: TableSelectionPluginOptions<T>): TablePlugin<T, SelectionState, TableSelectionApi<T>>;
2460
+ /** 创建表格行勾选插件。将返回值加入 Table 的 plugins 后生效;跨页行缓存属于表格实例,重新创建插件不会清空缓存,不同表格互不共享。 */
2461
+ declare function createSelectionPlugin<T extends Record<string, unknown>>(options?: TableSelectionPluginOptions<T>): TablePlugin<T, SelectionState<T>, TableSelectionApi<T>>;
2460
2462
  /** TableSort的插件配置。 */
2461
2463
  interface TableSortPluginOptions {
2462
2464
  /** 展示或交互模式;可选值见类型定义。 */
package/dist/index.js CHANGED
@@ -5719,7 +5719,6 @@ function TableSelectedItemsPanel({
5719
5719
  }
5720
5720
  function createSelectionPlugin(options = {}) {
5721
5721
  const { mode = "multiple", childrenColumnName = "children" } = options;
5722
- const preservedRows = /* @__PURE__ */ new Map();
5723
5722
  function selected(context) {
5724
5723
  return options.selectedKeys ?? context.state.selectedKeys ?? [];
5725
5724
  }
@@ -5730,6 +5729,7 @@ function createSelectionPlugin(options = {}) {
5730
5729
  return flattenRecords(context.sourceData, childrenColumnName);
5731
5730
  }
5732
5731
  function entriesForKeys(keys, context) {
5732
+ const preservedRows = context.state.preservedRows;
5733
5733
  const records = allRecords(context);
5734
5734
  const currentRows = new Map(
5735
5735
  records.map(
@@ -5764,7 +5764,7 @@ function createSelectionPlugin(options = {}) {
5764
5764
  return entriesForKeys(keys, context).map((entry) => entry.record);
5765
5765
  }
5766
5766
  function setKeys(keys, context) {
5767
- if (keys.length === 0) preservedRows.clear();
5767
+ if (keys.length === 0) context.state.preservedRows.clear();
5768
5768
  context.setState((state) => ({
5769
5769
  ...state,
5770
5770
  selectedKeys: keys,
@@ -5780,7 +5780,7 @@ function createSelectionPlugin(options = {}) {
5780
5780
  (key) => pageKeys.has(key)
5781
5781
  );
5782
5782
  setKeys(currentPageKeys, context);
5783
- preservedRows.clear();
5783
+ context.state.preservedRows.clear();
5784
5784
  }
5785
5785
  context.setState((state) => ({
5786
5786
  ...state,
@@ -5802,11 +5802,13 @@ function createSelectionPlugin(options = {}) {
5802
5802
  return {
5803
5803
  id: "selection",
5804
5804
  order: 20,
5805
- initialState: {
5805
+ // 用工厂给每个表格创建独立缓存,避免同一插件对象被多个表格复用时串数据。
5806
+ initialState: () => ({
5807
+ preservedRows: /* @__PURE__ */ new Map(),
5806
5808
  selectedKeys: options.defaultSelectedKeys ?? [],
5807
5809
  preserveSelectedRowKeys: options.preserveSelectedRowKeys ?? false,
5808
5810
  panelOpen: false
5809
- },
5811
+ }),
5810
5812
  transformColumns(columns, context) {
5811
5813
  if (mode === "row") return columns;
5812
5814
  const selectionColumn = {
@@ -5954,7 +5956,7 @@ function createSelectionPlugin(options = {}) {
5954
5956
  const records = allRecords(context);
5955
5957
  const record = records.find(
5956
5958
  (item, index) => Object.is(context.getRowKey(item, index), key)
5957
- ) ?? preservedRows.get(key);
5959
+ ) ?? context.state.preservedRows.get(key);
5958
5960
  if (record) toggle(key, record, context, checked);
5959
5961
  },
5960
5962
  getSelectedRows: () => rowsForKeys(selected(context), context),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sia.soul/sia-react-ui",
3
- "version": "0.1.64",
3
+ "version": "0.1.65",
4
4
  "description": "Sia Design components and tokens for React",
5
5
  "publishConfig": {
6
6
  "access": "public",