@canvas-components/list-table 0.3.29 → 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);
@@ -34259,7 +34296,7 @@ var ListTablePersistenceController = class {
34259
34296
  this.options.canvasHost.setContentZoom(nextZoom);
34260
34297
  }
34261
34298
  let currentOptions = this.options.getOptions();
34262
- if (stored.scrollbar) {
34299
+ if (stored.scrollbar && !isSameScrollbarOptions(currentOptions.scrollbar, stored.scrollbar)) {
34263
34300
  currentOptions = { ...currentOptions, scrollbar: stored.scrollbar };
34264
34301
  currentOptions.ui?.onScrollbarChange?.(stored.scrollbar);
34265
34302
  }
@@ -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({
@@ -34335,6 +34375,22 @@ var ListTablePersistenceController = class {
34335
34375
  );
34336
34376
  }
34337
34377
  };
34378
+ function isSameScrollbarOptions(current, stored) {
34379
+ if (current === stored) return true;
34380
+ if (!current || !stored) return false;
34381
+ const currentEntries = Object.entries(current);
34382
+ if (currentEntries.length !== Object.keys(stored).length) return false;
34383
+ return currentEntries.every(([key, value]) => {
34384
+ const next = stored[key];
34385
+ if (value && typeof value === "object" && next && typeof next === "object") {
34386
+ const entries = Object.entries(value);
34387
+ return entries.length === Object.keys(next).length && entries.every(
34388
+ ([axisKey, axisValue]) => Object.is(axisValue, next[axisKey])
34389
+ );
34390
+ }
34391
+ return Object.is(value, next);
34392
+ });
34393
+ }
34338
34394
 
34339
34395
  // src/services/data-source-service.ts
34340
34396
  function getListTableBaseDisplayData(params) {
@@ -37624,10 +37680,14 @@ var ListTableCore = class {
37624
37680
  if (shouldPersistColumnConfig) {
37625
37681
  this.persistenceController.persistColumnConfig();
37626
37682
  } else {
37627
- this.persistenceController.loadStoredConfig({ restoreQueryState: false });
37683
+ this.persistenceController.loadStoredConfig({
37684
+ restoreQueryState: this.persistenceController.needsInitialQueryRestore()
37685
+ });
37628
37686
  }
37629
37687
  this.renderController.render();
37630
- 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
+ ))) {
37631
37691
  host.rowActionController.startColumnVisibilityAnimation({
37632
37692
  previousLeafColumns,
37633
37693
  previousSegments
@@ -37668,7 +37728,9 @@ var ListTableCore = class {
37668
37728
  * 重置排序状态。
37669
37729
  */
37670
37730
  resetSorter() {
37671
- this.headerActionController.resetSort();
37731
+ this.persistenceController.runAfterInitialRestore(
37732
+ () => this.headerActionController.resetSort()
37733
+ );
37672
37734
  }
37673
37735
  /** 获取当前排序状态,供外部设置面板回显。 */
37674
37736
  getSortState() {
@@ -37682,7 +37744,9 @@ var ListTableCore = class {
37682
37744
  * 重置筛选状态。
37683
37745
  */
37684
37746
  resetFilter() {
37685
- this.headerActionController.resetFilters();
37747
+ this.persistenceController.runAfterInitialRestore(
37748
+ () => this.headerActionController.resetFilters()
37749
+ );
37686
37750
  }
37687
37751
  /** 人工重试最近一次仍有效的本地查询失败。 */
37688
37752
  retryQuery() {
@@ -37707,7 +37771,7 @@ var ListTableCore = class {
37707
37771
  * 销毁实例。
37708
37772
  */
37709
37773
  destroy() {
37710
- this.persistenceController.invalidate();
37774
+ this.persistenceController.dispose();
37711
37775
  this.eventController.destroy();
37712
37776
  this.selectionController.destroy();
37713
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);
@@ -34237,7 +34274,7 @@ var ListTablePersistenceController = class {
34237
34274
  this.options.canvasHost.setContentZoom(nextZoom);
34238
34275
  }
34239
34276
  let currentOptions = this.options.getOptions();
34240
- if (stored.scrollbar) {
34277
+ if (stored.scrollbar && !isSameScrollbarOptions(currentOptions.scrollbar, stored.scrollbar)) {
34241
34278
  currentOptions = { ...currentOptions, scrollbar: stored.scrollbar };
34242
34279
  currentOptions.ui?.onScrollbarChange?.(stored.scrollbar);
34243
34280
  }
@@ -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({
@@ -34313,6 +34353,22 @@ var ListTablePersistenceController = class {
34313
34353
  );
34314
34354
  }
34315
34355
  };
34356
+ function isSameScrollbarOptions(current, stored) {
34357
+ if (current === stored) return true;
34358
+ if (!current || !stored) return false;
34359
+ const currentEntries = Object.entries(current);
34360
+ if (currentEntries.length !== Object.keys(stored).length) return false;
34361
+ return currentEntries.every(([key, value]) => {
34362
+ const next = stored[key];
34363
+ if (value && typeof value === "object" && next && typeof next === "object") {
34364
+ const entries = Object.entries(value);
34365
+ return entries.length === Object.keys(next).length && entries.every(
34366
+ ([axisKey, axisValue]) => Object.is(axisValue, next[axisKey])
34367
+ );
34368
+ }
34369
+ return Object.is(value, next);
34370
+ });
34371
+ }
34316
34372
 
34317
34373
  // src/services/data-source-service.ts
34318
34374
  function getListTableBaseDisplayData(params) {
@@ -37602,10 +37658,14 @@ var ListTableCore = class {
37602
37658
  if (shouldPersistColumnConfig) {
37603
37659
  this.persistenceController.persistColumnConfig();
37604
37660
  } else {
37605
- this.persistenceController.loadStoredConfig({ restoreQueryState: false });
37661
+ this.persistenceController.loadStoredConfig({
37662
+ restoreQueryState: this.persistenceController.needsInitialQueryRestore()
37663
+ });
37606
37664
  }
37607
37665
  this.renderController.render();
37608
- 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
+ ))) {
37609
37669
  host.rowActionController.startColumnVisibilityAnimation({
37610
37670
  previousLeafColumns,
37611
37671
  previousSegments
@@ -37646,7 +37706,9 @@ var ListTableCore = class {
37646
37706
  * 重置排序状态。
37647
37707
  */
37648
37708
  resetSorter() {
37649
- this.headerActionController.resetSort();
37709
+ this.persistenceController.runAfterInitialRestore(
37710
+ () => this.headerActionController.resetSort()
37711
+ );
37650
37712
  }
37651
37713
  /** 获取当前排序状态,供外部设置面板回显。 */
37652
37714
  getSortState() {
@@ -37660,7 +37722,9 @@ var ListTableCore = class {
37660
37722
  * 重置筛选状态。
37661
37723
  */
37662
37724
  resetFilter() {
37663
- this.headerActionController.resetFilters();
37725
+ this.persistenceController.runAfterInitialRestore(
37726
+ () => this.headerActionController.resetFilters()
37727
+ );
37664
37728
  }
37665
37729
  /** 人工重试最近一次仍有效的本地查询失败。 */
37666
37730
  retryQuery() {
@@ -37685,7 +37749,7 @@ var ListTableCore = class {
37685
37749
  * 销毁实例。
37686
37750
  */
37687
37751
  destroy() {
37688
- this.persistenceController.invalidate();
37752
+ this.persistenceController.dispose();
37689
37753
  this.eventController.destroy();
37690
37754
  this.selectionController.destroy();
37691
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.29",
3
+ "version": "0.3.31",
4
4
  "description": "Framework-agnostic list table core engine.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,8 +30,8 @@
30
30
  "@canvas-components/barcode": "0.2.2",
31
31
  "@canvas-components/stats": "0.1.4",
32
32
  "@canvas-components/utils": "0.2.8",
33
- "@canvas-components/qrcode": "0.2.2",
34
- "@canvas-components/chart": "0.3.7"
33
+ "@canvas-components/chart": "0.3.7",
34
+ "@canvas-components/qrcode": "0.2.2"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsup --config tsup.config.ts"