@canvas-components/list-table 0.3.30 → 0.3.31

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
@@ -24371,7 +24371,8 @@ function resolveExpandedRowHeight2(height, record, index) {
24371
24371
  // src/services/layout-service.ts
24372
24372
  var AUTO_ROW_HEIGHT_SAMPLE_COUNT = 200;
24373
24373
  function buildListTableRenderSnapshot(params) {
24374
- if (params.cache?.snapshot && params.cache.snapshot.groupIndex === params.cache.groupIndex && isSameRenderCacheInputs(params.cache.inputs, params)) {
24374
+ if (params.cache?.snapshot && // 动画结束后的首帧必须重建,清除上一帧的位移、拖拽残影及插入线。
24375
+ !params.cache.snapshot.swapAnimation && params.cache.snapshot.groupIndex === params.cache.groupIndex && isSameRenderCacheInputs(params.cache.inputs, params)) {
24375
24376
  const snapshotStartedAt2 = resolvePerformanceNow3();
24376
24377
  const cached = params.cache.snapshot;
24377
24378
  const snapshot2 = !cached.swapAnimation && cached.scroll.left === params.scroll.left && cached.scroll.top === params.scroll.top ? cached : updateListTableRenderSnapshotScroll({
@@ -34195,14 +34196,35 @@ var ListTablePersistenceController = class {
34195
34196
  __publicField(this, "revision", 0);
34196
34197
  __publicField(this, "pendingWrite");
34197
34198
  __publicField(this, "restoredStorageKey");
34199
+ __publicField(this, "restoredQueryStorageKey");
34198
34200
  __publicField(this, "hasRestoredPreferences", false);
34199
34201
  __publicField(this, "restoring", false);
34202
+ __publicField(this, "initialActions", []);
34200
34203
  this.options = options;
34201
34204
  }
34205
+ /** 初始化期间的重置等待缓存恢复,避免将默认列和空排序写回缓存。 */
34206
+ runAfterInitialRestore(run) {
34207
+ const storageKey = this.options.getOptions().storageKey;
34208
+ if (storageKey && this.needsInitialQueryRestore()) {
34209
+ this.initialActions.push({ storageKey, run });
34210
+ } else {
34211
+ run();
34212
+ }
34213
+ }
34214
+ /** 销毁时丢弃等待中的交互,避免已卸载表格再次写入缓存。 */
34215
+ dispose() {
34216
+ this.invalidate();
34217
+ this.initialActions = [];
34218
+ }
34202
34219
  /** 缓存恢复完成之前保留上一帧,避免默认配置先于缓存绘制。 */
34203
34220
  isRestoring() {
34204
34221
  return this.restoring;
34205
34222
  }
34223
+ /** 首次缓存读取被配置更新打断时,后续读取仍需恢复该表的查询状态。 */
34224
+ needsInitialQueryRestore() {
34225
+ const storageKey = this.options.getOptions().storageKey;
34226
+ return Boolean(storageKey && this.restoredQueryStorageKey !== storageKey);
34227
+ }
34206
34228
  /** 使尚未完成的缓存恢复失效。 */
34207
34229
  invalidate() {
34208
34230
  this.revision += 1;
@@ -34211,6 +34233,9 @@ var ListTablePersistenceController = class {
34211
34233
  async loadStoredConfig(options = {}) {
34212
34234
  const { restoreQueryState = true } = options;
34213
34235
  const tableOptions = this.options.getOptions();
34236
+ this.initialActions = this.initialActions.filter(
34237
+ (action) => action.storageKey === tableOptions.storageKey
34238
+ );
34214
34239
  const revision = ++this.revision;
34215
34240
  this.restoring = Boolean(tableOptions.storageKey);
34216
34241
  if (!this.restoring) return;
@@ -34222,6 +34247,14 @@ var ListTablePersistenceController = class {
34222
34247
  if (revision === this.revision) {
34223
34248
  this.restoring = false;
34224
34249
  if (this.options.getOptions().storageKey === tableOptions.storageKey) {
34250
+ if (restoreQueryState) {
34251
+ this.restoredQueryStorageKey = tableOptions.storageKey;
34252
+ const actions = this.initialActions;
34253
+ this.initialActions = [];
34254
+ actions.forEach((action) => {
34255
+ if (action.storageKey === tableOptions.storageKey) action.run();
34256
+ });
34257
+ }
34225
34258
  this.options.requestRender();
34226
34259
  }
34227
34260
  }
@@ -34242,6 +34275,9 @@ var ListTablePersistenceController = class {
34242
34275
  columns: tableOptions.columns
34243
34276
  });
34244
34277
  if (!stored || !isCurrent()) {
34278
+ if (!stored && isCurrent() && restoreQueryState) {
34279
+ this.restoredQueryStorageKey = storageKey;
34280
+ }
34245
34281
  return;
34246
34282
  }
34247
34283
  this.restoredStorageKey = storageKey;
@@ -34252,6 +34288,7 @@ var ListTablePersistenceController = class {
34252
34288
  if (restoreQueryState && stored.filterState) {
34253
34289
  this.options.setFilterState(stored.filterState);
34254
34290
  }
34291
+ if (restoreQueryState) this.restoredQueryStorageKey = storageKey;
34255
34292
  if (stored.zoom != null) {
34256
34293
  const nextZoom = normalizeContextMenuZoom(stored.zoom);
34257
34294
  this.options.setTableZoom(nextZoom);
@@ -34308,16 +34345,19 @@ var ListTablePersistenceController = class {
34308
34345
  }
34309
34346
  this.options.refreshRuntimeColumns();
34310
34347
  currentOptions.ui?.onColumnSettingsChange?.(
34311
- cloneColumns(currentOptions.columns)
34348
+ cloneColumns(currentOptions.columns),
34349
+ "restore"
34312
34350
  );
34313
34351
  }
34314
34352
  persistColumnConfig() {
34315
34353
  this.invalidate();
34316
34354
  const tableOptions = this.options.getOptions();
34317
34355
  tableOptions.ui?.onColumnSettingsChange?.(
34318
- cloneColumns(tableOptions.columns)
34356
+ cloneColumns(tableOptions.columns),
34357
+ "persist"
34319
34358
  );
34320
34359
  this.restoredStorageKey = tableOptions.storageKey;
34360
+ this.restoredQueryStorageKey = tableOptions.storageKey;
34321
34361
  this.hasRestoredPreferences = true;
34322
34362
  this.pendingWrite = Promise.resolve(
34323
34363
  persistListTableColumnConfig({
@@ -37640,10 +37680,14 @@ var ListTableCore = class {
37640
37680
  if (shouldPersistColumnConfig) {
37641
37681
  this.persistenceController.persistColumnConfig();
37642
37682
  } else {
37643
- this.persistenceController.loadStoredConfig({ restoreQueryState: false });
37683
+ this.persistenceController.loadStoredConfig({
37684
+ restoreQueryState: this.persistenceController.needsInitialQueryRestore()
37685
+ });
37644
37686
  }
37645
37687
  this.renderController.render();
37646
- if (shouldPersistColumnConfig && haveVisibleLeafColumnsChanged(previousLeafColumns, host.leafColumns)) {
37688
+ if (shouldPersistColumnConfig && (haveVisibleLeafColumnsChanged(previousLeafColumns, host.leafColumns) || previousLeafColumns.some(
37689
+ (column, index) => column.key !== host.leafColumns[index]?.key
37690
+ ))) {
37647
37691
  host.rowActionController.startColumnVisibilityAnimation({
37648
37692
  previousLeafColumns,
37649
37693
  previousSegments
@@ -37684,7 +37728,9 @@ var ListTableCore = class {
37684
37728
  * 重置排序状态。
37685
37729
  */
37686
37730
  resetSorter() {
37687
- this.headerActionController.resetSort();
37731
+ this.persistenceController.runAfterInitialRestore(
37732
+ () => this.headerActionController.resetSort()
37733
+ );
37688
37734
  }
37689
37735
  /** 获取当前排序状态,供外部设置面板回显。 */
37690
37736
  getSortState() {
@@ -37698,7 +37744,9 @@ var ListTableCore = class {
37698
37744
  * 重置筛选状态。
37699
37745
  */
37700
37746
  resetFilter() {
37701
- this.headerActionController.resetFilters();
37747
+ this.persistenceController.runAfterInitialRestore(
37748
+ () => this.headerActionController.resetFilters()
37749
+ );
37702
37750
  }
37703
37751
  /** 人工重试最近一次仍有效的本地查询失败。 */
37704
37752
  retryQuery() {
@@ -37723,7 +37771,7 @@ var ListTableCore = class {
37723
37771
  * 销毁实例。
37724
37772
  */
37725
37773
  destroy() {
37726
- this.persistenceController.invalidate();
37774
+ this.persistenceController.dispose();
37727
37775
  this.eventController.destroy();
37728
37776
  this.selectionController.destroy();
37729
37777
  this.asAssemblyHost().rowDragController.destroy();
package/dist/index.d.cts CHANGED
@@ -2130,7 +2130,7 @@ interface ListTableUiOptions<RecordType = unknown> {
2130
2130
  /** 恢复持久化滚动条配置后同步到适配层。 */
2131
2131
  onScrollbarChange?: (scrollbar: ListTableScrollbarOptions) => void;
2132
2132
  /** 同步恢复或内部修改后的列设置到适配层。 */
2133
- onColumnSettingsChange?: (columns: ListTableColumn<RecordType>[]) => void;
2133
+ onColumnSettingsChange?: (columns: ListTableColumn<RecordType>[], source?: "restore" | "persist") => void;
2134
2134
  /** 同步列设置缓存开关。 */
2135
2135
  onColumnSettingsCacheChange?: (enabled: boolean) => void;
2136
2136
  /** 同步各类配置的缓存偏好。 */
package/dist/index.d.ts CHANGED
@@ -2130,7 +2130,7 @@ interface ListTableUiOptions<RecordType = unknown> {
2130
2130
  /** 恢复持久化滚动条配置后同步到适配层。 */
2131
2131
  onScrollbarChange?: (scrollbar: ListTableScrollbarOptions) => void;
2132
2132
  /** 同步恢复或内部修改后的列设置到适配层。 */
2133
- onColumnSettingsChange?: (columns: ListTableColumn<RecordType>[]) => void;
2133
+ onColumnSettingsChange?: (columns: ListTableColumn<RecordType>[], source?: "restore" | "persist") => void;
2134
2134
  /** 同步列设置缓存开关。 */
2135
2135
  onColumnSettingsCacheChange?: (enabled: boolean) => void;
2136
2136
  /** 同步各类配置的缓存偏好。 */
package/dist/index.js CHANGED
@@ -24349,7 +24349,8 @@ function resolveExpandedRowHeight2(height, record, index) {
24349
24349
  // src/services/layout-service.ts
24350
24350
  var AUTO_ROW_HEIGHT_SAMPLE_COUNT = 200;
24351
24351
  function buildListTableRenderSnapshot(params) {
24352
- if (params.cache?.snapshot && params.cache.snapshot.groupIndex === params.cache.groupIndex && isSameRenderCacheInputs(params.cache.inputs, params)) {
24352
+ if (params.cache?.snapshot && // 动画结束后的首帧必须重建,清除上一帧的位移、拖拽残影及插入线。
24353
+ !params.cache.snapshot.swapAnimation && params.cache.snapshot.groupIndex === params.cache.groupIndex && isSameRenderCacheInputs(params.cache.inputs, params)) {
24353
24354
  const snapshotStartedAt2 = resolvePerformanceNow3();
24354
24355
  const cached = params.cache.snapshot;
24355
24356
  const snapshot2 = !cached.swapAnimation && cached.scroll.left === params.scroll.left && cached.scroll.top === params.scroll.top ? cached : updateListTableRenderSnapshotScroll({
@@ -34173,14 +34174,35 @@ var ListTablePersistenceController = class {
34173
34174
  __publicField(this, "revision", 0);
34174
34175
  __publicField(this, "pendingWrite");
34175
34176
  __publicField(this, "restoredStorageKey");
34177
+ __publicField(this, "restoredQueryStorageKey");
34176
34178
  __publicField(this, "hasRestoredPreferences", false);
34177
34179
  __publicField(this, "restoring", false);
34180
+ __publicField(this, "initialActions", []);
34178
34181
  this.options = options;
34179
34182
  }
34183
+ /** 初始化期间的重置等待缓存恢复,避免将默认列和空排序写回缓存。 */
34184
+ runAfterInitialRestore(run) {
34185
+ const storageKey = this.options.getOptions().storageKey;
34186
+ if (storageKey && this.needsInitialQueryRestore()) {
34187
+ this.initialActions.push({ storageKey, run });
34188
+ } else {
34189
+ run();
34190
+ }
34191
+ }
34192
+ /** 销毁时丢弃等待中的交互,避免已卸载表格再次写入缓存。 */
34193
+ dispose() {
34194
+ this.invalidate();
34195
+ this.initialActions = [];
34196
+ }
34180
34197
  /** 缓存恢复完成之前保留上一帧,避免默认配置先于缓存绘制。 */
34181
34198
  isRestoring() {
34182
34199
  return this.restoring;
34183
34200
  }
34201
+ /** 首次缓存读取被配置更新打断时,后续读取仍需恢复该表的查询状态。 */
34202
+ needsInitialQueryRestore() {
34203
+ const storageKey = this.options.getOptions().storageKey;
34204
+ return Boolean(storageKey && this.restoredQueryStorageKey !== storageKey);
34205
+ }
34184
34206
  /** 使尚未完成的缓存恢复失效。 */
34185
34207
  invalidate() {
34186
34208
  this.revision += 1;
@@ -34189,6 +34211,9 @@ var ListTablePersistenceController = class {
34189
34211
  async loadStoredConfig(options = {}) {
34190
34212
  const { restoreQueryState = true } = options;
34191
34213
  const tableOptions = this.options.getOptions();
34214
+ this.initialActions = this.initialActions.filter(
34215
+ (action) => action.storageKey === tableOptions.storageKey
34216
+ );
34192
34217
  const revision = ++this.revision;
34193
34218
  this.restoring = Boolean(tableOptions.storageKey);
34194
34219
  if (!this.restoring) return;
@@ -34200,6 +34225,14 @@ var ListTablePersistenceController = class {
34200
34225
  if (revision === this.revision) {
34201
34226
  this.restoring = false;
34202
34227
  if (this.options.getOptions().storageKey === tableOptions.storageKey) {
34228
+ if (restoreQueryState) {
34229
+ this.restoredQueryStorageKey = tableOptions.storageKey;
34230
+ const actions = this.initialActions;
34231
+ this.initialActions = [];
34232
+ actions.forEach((action) => {
34233
+ if (action.storageKey === tableOptions.storageKey) action.run();
34234
+ });
34235
+ }
34203
34236
  this.options.requestRender();
34204
34237
  }
34205
34238
  }
@@ -34220,6 +34253,9 @@ var ListTablePersistenceController = class {
34220
34253
  columns: tableOptions.columns
34221
34254
  });
34222
34255
  if (!stored || !isCurrent()) {
34256
+ if (!stored && isCurrent() && restoreQueryState) {
34257
+ this.restoredQueryStorageKey = storageKey;
34258
+ }
34223
34259
  return;
34224
34260
  }
34225
34261
  this.restoredStorageKey = storageKey;
@@ -34230,6 +34266,7 @@ var ListTablePersistenceController = class {
34230
34266
  if (restoreQueryState && stored.filterState) {
34231
34267
  this.options.setFilterState(stored.filterState);
34232
34268
  }
34269
+ if (restoreQueryState) this.restoredQueryStorageKey = storageKey;
34233
34270
  if (stored.zoom != null) {
34234
34271
  const nextZoom = normalizeContextMenuZoom(stored.zoom);
34235
34272
  this.options.setTableZoom(nextZoom);
@@ -34286,16 +34323,19 @@ var ListTablePersistenceController = class {
34286
34323
  }
34287
34324
  this.options.refreshRuntimeColumns();
34288
34325
  currentOptions.ui?.onColumnSettingsChange?.(
34289
- cloneColumns(currentOptions.columns)
34326
+ cloneColumns(currentOptions.columns),
34327
+ "restore"
34290
34328
  );
34291
34329
  }
34292
34330
  persistColumnConfig() {
34293
34331
  this.invalidate();
34294
34332
  const tableOptions = this.options.getOptions();
34295
34333
  tableOptions.ui?.onColumnSettingsChange?.(
34296
- cloneColumns(tableOptions.columns)
34334
+ cloneColumns(tableOptions.columns),
34335
+ "persist"
34297
34336
  );
34298
34337
  this.restoredStorageKey = tableOptions.storageKey;
34338
+ this.restoredQueryStorageKey = tableOptions.storageKey;
34299
34339
  this.hasRestoredPreferences = true;
34300
34340
  this.pendingWrite = Promise.resolve(
34301
34341
  persistListTableColumnConfig({
@@ -37618,10 +37658,14 @@ var ListTableCore = class {
37618
37658
  if (shouldPersistColumnConfig) {
37619
37659
  this.persistenceController.persistColumnConfig();
37620
37660
  } else {
37621
- this.persistenceController.loadStoredConfig({ restoreQueryState: false });
37661
+ this.persistenceController.loadStoredConfig({
37662
+ restoreQueryState: this.persistenceController.needsInitialQueryRestore()
37663
+ });
37622
37664
  }
37623
37665
  this.renderController.render();
37624
- if (shouldPersistColumnConfig && haveVisibleLeafColumnsChanged(previousLeafColumns, host.leafColumns)) {
37666
+ if (shouldPersistColumnConfig && (haveVisibleLeafColumnsChanged(previousLeafColumns, host.leafColumns) || previousLeafColumns.some(
37667
+ (column, index) => column.key !== host.leafColumns[index]?.key
37668
+ ))) {
37625
37669
  host.rowActionController.startColumnVisibilityAnimation({
37626
37670
  previousLeafColumns,
37627
37671
  previousSegments
@@ -37662,7 +37706,9 @@ var ListTableCore = class {
37662
37706
  * 重置排序状态。
37663
37707
  */
37664
37708
  resetSorter() {
37665
- this.headerActionController.resetSort();
37709
+ this.persistenceController.runAfterInitialRestore(
37710
+ () => this.headerActionController.resetSort()
37711
+ );
37666
37712
  }
37667
37713
  /** 获取当前排序状态,供外部设置面板回显。 */
37668
37714
  getSortState() {
@@ -37676,7 +37722,9 @@ var ListTableCore = class {
37676
37722
  * 重置筛选状态。
37677
37723
  */
37678
37724
  resetFilter() {
37679
- this.headerActionController.resetFilters();
37725
+ this.persistenceController.runAfterInitialRestore(
37726
+ () => this.headerActionController.resetFilters()
37727
+ );
37680
37728
  }
37681
37729
  /** 人工重试最近一次仍有效的本地查询失败。 */
37682
37730
  retryQuery() {
@@ -37701,7 +37749,7 @@ var ListTableCore = class {
37701
37749
  * 销毁实例。
37702
37750
  */
37703
37751
  destroy() {
37704
- this.persistenceController.invalidate();
37752
+ this.persistenceController.dispose();
37705
37753
  this.eventController.destroy();
37706
37754
  this.selectionController.destroy();
37707
37755
  this.asAssemblyHost().rowDragController.destroy();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canvas-components/list-table",
3
- "version": "0.3.30",
3
+ "version": "0.3.31",
4
4
  "description": "Framework-agnostic list table core engine.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@ant-design/icons-svg": "4.6.0",
30
- "@canvas-components/qrcode": "0.2.2",
31
- "@canvas-components/utils": "0.2.8",
32
30
  "@canvas-components/barcode": "0.2.2",
31
+ "@canvas-components/stats": "0.1.4",
32
+ "@canvas-components/utils": "0.2.8",
33
33
  "@canvas-components/chart": "0.3.7",
34
- "@canvas-components/stats": "0.1.4"
34
+ "@canvas-components/qrcode": "0.2.2"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsup --config tsup.config.ts"