@shival99/z-ui 2.0.38 → 2.0.40

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.
@@ -4685,7 +4685,8 @@ class ZTableComponent {
4685
4685
  _bulkBarTimer = null;
4686
4686
  _activeColumnVisibilityPopover = signal(null, ...(ngDevMode ? [{ debugName: "_activeColumnVisibilityPopover" }] : []));
4687
4687
  _hasInitializedColumnPinning = false;
4688
- _fitColumnFrame = null;
4688
+ _fitColumnScheduleId = 0;
4689
+ _isFitColumnScheduled = false;
4689
4690
  _isApplyingFitColumnSizing = false;
4690
4691
  // ─── Template-bound State ─────────────────────────────────────────────────
4691
4692
  /** Merged loading state from both zLoading input and config.loading */
@@ -4711,36 +4712,12 @@ class ZTableComponent {
4711
4712
  rowPinning = signal({ top: [], bottom: [] }, ...(ngDevMode ? [{ debugName: "rowPinning" }] : []));
4712
4713
  columnFilters = signal([], ...(ngDevMode ? [{ debugName: "columnFilters" }] : []));
4713
4714
  globalFilter = signal('', ...(ngDevMode ? [{ debugName: "globalFilter" }] : []));
4714
- // Synchronize initial column sizes from configuration to prevent layout shift.
4715
- // Use previous state to check if column structure has changed, avoiding sizing resets on reload.
4715
+ // Giữ kích thước cột đã ổn định khi config được tạo lại trong lúc tải dữ liệu.
4716
4716
  columnSizingState = linkedSignal({ ...(ngDevMode ? { debugName: "columnSizingState" } : {}), source: () => this._columns(),
4717
- computation: (cols, previous) => {
4718
- if (previous && this._areColumnsEquivalent(previous.source, cols)) {
4719
- return previous.value;
4720
- }
4721
- const initialSizing = {};
4722
- for (const col of cols) {
4723
- if (col.id) {
4724
- initialSizing[col.id] = col.size ?? Math.max(col.minSize ?? 100, 150);
4725
- }
4726
- }
4727
- return initialSizing;
4728
- } });
4729
- // Synchronize initial base sizing for column distribution or stretching.
4730
- // Use previous state to check for changes similar to columnSizingState to prevent resets.
4717
+ computation: (cols, previous) => this._reconcileColumnSizing(cols, previous) });
4718
+ // Tách kích thước gốc khỏi phần chiều rộng được phân bổ thêm theo container.
4731
4719
  _columnBaseSizing = linkedSignal({ ...(ngDevMode ? { debugName: "_columnBaseSizing" } : {}), source: () => this._columns(),
4732
- computation: (cols, previous) => {
4733
- if (previous && this._areColumnsEquivalent(previous.source, cols)) {
4734
- return previous.value;
4735
- }
4736
- const initialSizing = {};
4737
- for (const col of cols) {
4738
- if (col.id) {
4739
- initialSizing[col.id] = col.size ?? Math.max(col.minSize ?? 100, 150);
4740
- }
4741
- }
4742
- return initialSizing;
4743
- } });
4720
+ computation: (cols, previous) => this._reconcileColumnSizing(cols, previous) });
4744
4721
  /** Note: pageIndex is 1-based here; converted to 0-based for TanStack via _tanstackPagination */
4745
4722
  pagination = signal({ pageIndex: 1, pageSize: 10 }, ...(ngDevMode ? [{ debugName: "pagination" }] : []));
4746
4723
  sorting = signal([], ...(ngDevMode ? [{ debugName: "sorting" }] : []));
@@ -4924,24 +4901,29 @@ class ZTableComponent {
4924
4901
  }
4925
4902
  const { config } = actionCol;
4926
4903
  const maxVisible = config.maxVisible ?? Z_TABLE_DEFAULT_MAX_VISIBLE_ACTIONS;
4927
- const data = this._actionColumnRows();
4928
4904
  let buttonCount = 0;
4929
- for (const row of data) {
4930
- const actions = typeof config.actions === 'function' ? config.actions(row) : config.actions;
4931
- const visibleActions = actions.filter(action => {
4932
- if (typeof action.hidden === 'function') {
4933
- return !action.hidden(row);
4905
+ if (Array.isArray(config.actions)) {
4906
+ const possibleVisibleCount = config.actions.filter(action => action.hidden !== true).length;
4907
+ buttonCount = possibleVisibleCount > maxVisible ? 1 : possibleVisibleCount;
4908
+ }
4909
+ if (typeof config.actions === 'function') {
4910
+ const data = this._actionColumnRows();
4911
+ for (const row of data) {
4912
+ const visibleActions = config.actions(row).filter(action => {
4913
+ if (typeof action.hidden === 'function') {
4914
+ return !action.hidden(row);
4915
+ }
4916
+ return !action.hidden;
4917
+ });
4918
+ const rowButtonCount = visibleActions.length > maxVisible ? 1 : visibleActions.length;
4919
+ buttonCount = Math.max(buttonCount, rowButtonCount);
4920
+ if (buttonCount === maxVisible) {
4921
+ break;
4934
4922
  }
4935
- return !action.hidden;
4936
- });
4937
- const rowButtonCount = visibleActions.length > maxVisible ? 1 : visibleActions.length;
4938
- buttonCount = Math.max(buttonCount, rowButtonCount);
4939
- if (buttonCount === maxVisible) {
4940
- break;
4941
4923
  }
4942
- }
4943
- if (data.length === 0) {
4944
- buttonCount = maxVisible;
4924
+ if (data.length === 0) {
4925
+ buttonCount = maxVisible;
4926
+ }
4945
4927
  }
4946
4928
  const buttonWidth = Z_TABLE_DEFAULT_ACTION_BUTTON_WIDTH;
4947
4929
  const gap = 4;
@@ -6079,7 +6061,7 @@ class ZTableComponent {
6079
6061
  this._resizeObserver.disconnect();
6080
6062
  this._resizeObserver = null;
6081
6063
  }
6082
- this._cancelFitColumnFrame();
6064
+ this._cancelFitColumnSchedule();
6083
6065
  });
6084
6066
  }
6085
6067
  });
@@ -6616,30 +6598,22 @@ class ZTableComponent {
6616
6598
  this._columnBaseSizing.set(nextBaseSizing);
6617
6599
  }
6618
6600
  _scheduleFitColumnWidths() {
6619
- if (this._fitColumnFrame !== null) {
6601
+ if (this._isFitColumnScheduled) {
6620
6602
  return;
6621
6603
  }
6622
- const run = () => {
6623
- this._fitColumnFrame = null;
6604
+ this._isFitColumnScheduled = true;
6605
+ const scheduleId = ++this._fitColumnScheduleId;
6606
+ queueMicrotask(() => {
6607
+ if (scheduleId !== this._fitColumnScheduleId) {
6608
+ return;
6609
+ }
6610
+ this._isFitColumnScheduled = false;
6624
6611
  this._applyFitColumnWidths();
6625
- };
6626
- if (typeof requestAnimationFrame === 'function') {
6627
- this._fitColumnFrame = requestAnimationFrame(run);
6628
- return;
6629
- }
6630
- this._fitColumnFrame = setTimeout(run, 0);
6612
+ });
6631
6613
  }
6632
- _cancelFitColumnFrame() {
6633
- if (this._fitColumnFrame === null) {
6634
- return;
6635
- }
6636
- if (typeof cancelAnimationFrame === 'function' && typeof this._fitColumnFrame === 'number') {
6637
- cancelAnimationFrame(this._fitColumnFrame);
6638
- this._fitColumnFrame = null;
6639
- return;
6640
- }
6641
- clearTimeout(this._fitColumnFrame);
6642
- this._fitColumnFrame = null;
6614
+ _cancelFitColumnSchedule() {
6615
+ this._fitColumnScheduleId += 1;
6616
+ this._isFitColumnScheduled = false;
6643
6617
  }
6644
6618
  _applyFitColumnWidths() {
6645
6619
  this._syncColumnBaseSizing();
@@ -6686,19 +6660,25 @@ class ZTableComponent {
6686
6660
  }
6687
6661
  return leftKeys.every(key => left[key] === right[key]);
6688
6662
  }
6689
- // Compare old and new column definition structures to avoid resetting sizing state
6690
- _areColumnsEquivalent(oldCols, newCols) {
6691
- if (oldCols.length !== newCols.length) {
6692
- return false;
6693
- }
6694
- for (let i = 0; i < oldCols.length; i++) {
6695
- const o = oldCols[i];
6696
- const n = newCols[i];
6697
- if (o.id !== n.id || o.size !== n.size || o.minSize !== n.minSize || o.maxSize !== n.maxSize) {
6698
- return false;
6663
+ _reconcileColumnSizing(columns, previous) {
6664
+ const previousColumns = new Map(previous?.source.map(column => [column.id, column]));
6665
+ const nextSizing = {};
6666
+ for (const column of columns) {
6667
+ if (!column.id) {
6668
+ continue;
6669
+ }
6670
+ const previousColumn = previousColumns.get(column.id);
6671
+ const canKeepPreviousSize = previousColumn &&
6672
+ previousColumn.size === column.size &&
6673
+ previousColumn.minSize === column.minSize &&
6674
+ previousColumn.maxSize === column.maxSize;
6675
+ if (canKeepPreviousSize && previous?.value[column.id] !== undefined) {
6676
+ nextSizing[column.id] = previous.value[column.id];
6677
+ continue;
6699
6678
  }
6679
+ nextSizing[column.id] = column.size ?? Math.max(column.minSize ?? Z_DEFAULT_COLUMN_MIN_SIZE, 150);
6700
6680
  }
6701
- return true;
6681
+ return nextSizing;
6702
6682
  }
6703
6683
  _checkHorizontalScroll() {
6704
6684
  const containerEl = this.tbodyContainer()?.nativeElement;