@shival99/z-ui 2.0.44 → 2.0.46

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.
@@ -4874,96 +4874,45 @@ class ZTableComponent {
4874
4874
  }
4875
4875
  return !this.hasBodyRowSpan();
4876
4876
  }, ...(ngDevMode ? [{ debugName: "isRowDragEnabled" }] : []));
4877
- actionColumnInfo = linkedSignal({ ...(ngDevMode ? { debugName: "actionColumnInfo" } : {}), source: () => ({
4878
- columns: this.zConfig().columns ?? [],
4879
- isPending: this.isLoading() || this.isProcessing(),
4880
- rows: this._actionColumnRows(),
4881
- }),
4882
- computation: ({ columns, isPending, rows }, previous) => {
4883
- const findActionColumn = (cols) => {
4884
- for (const col of cols) {
4885
- if (isBodyConfig(col.body)) {
4886
- const actionConfig = this._getActionColumnConfig(col.body);
4887
- if (actionConfig) {
4888
- const actionKeys = Array.isArray(actionConfig.actions)
4889
- ? actionConfig.actions.map(action => action.key)
4890
- : ['dynamic'];
4891
- const schemaKey = JSON.stringify([
4892
- col.id,
4893
- col.size,
4894
- col.minSize,
4895
- col.maxSize,
4896
- actionConfig.maxVisible ?? Z_TABLE_DEFAULT_MAX_VISIBLE_ACTIONS,
4897
- actionKeys,
4898
- ]);
4899
- return { columnId: col.id, config: actionConfig, schemaKey };
4900
- }
4901
- }
4902
- if (col.columns?.length) {
4903
- const found = findActionColumn(col.columns);
4904
- if (found) {
4905
- return found;
4906
- }
4877
+ actionColumnInfo = computed(() => {
4878
+ const columns = this.zConfig().columns ?? [];
4879
+ const findActionColumn = (cols) => {
4880
+ for (const col of cols) {
4881
+ if (isBodyConfig(col.body)) {
4882
+ const actionConfig = this._getActionColumnConfig(col.body);
4883
+ if (actionConfig) {
4884
+ return { columnId: col.id, config: actionConfig };
4907
4885
  }
4908
4886
  }
4909
- return null;
4910
- };
4911
- const actionCol = findActionColumn(columns);
4912
- if (!actionCol) {
4913
- return null;
4914
- }
4915
- const previousValue = previous?.value;
4916
- if (previousValue?.schemaKey === actionCol.schemaKey && (isPending || rows.length === 0)) {
4917
- return {
4918
- ...previousValue,
4919
- config: actionCol.config,
4920
- };
4921
- }
4922
- const { config } = actionCol;
4923
- const maxVisible = config.maxVisible ?? Z_TABLE_DEFAULT_MAX_VISIBLE_ACTIONS;
4924
- let buttonCount = 0;
4925
- for (const row of rows) {
4926
- const actions = typeof config.actions === 'function' ? config.actions(row) : config.actions;
4927
- const visibleActions = actions.filter(action => {
4928
- if (typeof action.hidden === 'function') {
4929
- return !action.hidden(row);
4887
+ if (col.columns?.length) {
4888
+ const found = findActionColumn(col.columns);
4889
+ if (found) {
4890
+ return found;
4930
4891
  }
4931
- return !action.hidden;
4932
- });
4933
- const rowButtonCount = visibleActions.length > maxVisible ? 1 : visibleActions.length;
4934
- buttonCount = Math.max(buttonCount, rowButtonCount);
4935
- if (buttonCount === maxVisible) {
4936
- break;
4937
4892
  }
4938
4893
  }
4939
- if (rows.length === 0 && Array.isArray(config.actions)) {
4940
- const possibleVisibleCount = config.actions.filter(action => action.hidden !== true).length;
4941
- buttonCount = possibleVisibleCount > maxVisible ? 1 : possibleVisibleCount;
4942
- }
4943
- if (rows.length === 0 && typeof config.actions === 'function') {
4944
- buttonCount = maxVisible;
4945
- }
4946
- const buttonWidth = Z_TABLE_DEFAULT_ACTION_BUTTON_WIDTH;
4947
- const gap = 4;
4948
- const padding = 16;
4949
- const width = buttonCount * buttonWidth + Math.max(0, buttonCount - 1) * gap + padding;
4950
- return {
4951
- columnId: actionCol.columnId,
4952
- config: actionCol.config,
4953
- schemaKey: actionCol.schemaKey,
4954
- width,
4955
- };
4956
- } });
4957
- _actionColumnRows = computed(() => {
4958
- const data = this._data();
4959
- const config = this.zConfig();
4960
- if (config.mode === 'server' || !config.pagination?.enabled) {
4961
- return data;
4894
+ return null;
4895
+ };
4896
+ const actionCol = findActionColumn(columns);
4897
+ if (!actionCol) {
4898
+ return null;
4962
4899
  }
4963
- const { pageIndex, pageSize } = this.pagination();
4964
- const start = Math.max(0, pageIndex - 1) * pageSize;
4965
- return data.slice(start, start + pageSize);
4966
- }, ...(ngDevMode ? [{ debugName: "_actionColumnRows" }] : []));
4900
+ const { config } = actionCol;
4901
+ const maxVisible = config.maxVisible ?? Z_TABLE_DEFAULT_MAX_VISIBLE_ACTIONS;
4902
+ const possibleActionCount = Array.isArray(config.actions)
4903
+ ? config.actions.filter(action => action.hidden !== true).length
4904
+ : maxVisible;
4905
+ const buttonCount = Math.min(possibleActionCount, maxVisible);
4906
+ const buttonWidth = Z_TABLE_DEFAULT_ACTION_BUTTON_WIDTH;
4907
+ const gap = 4;
4908
+ const padding = 16;
4909
+ const width = buttonCount * buttonWidth + Math.max(0, buttonCount - 1) * gap + padding;
4910
+ return {
4911
+ columnId: actionCol.columnId,
4912
+ config: actionCol.config,
4913
+ width,
4914
+ };
4915
+ }, ...(ngDevMode ? [{ debugName: "actionColumnInfo" }] : []));
4967
4916
  _fixedColumnPinning = computed(() => {
4968
4917
  const actionColumnId = this.actionColumnInfo()?.columnId;
4969
4918
  const configuredColumnIds = new Set();
@@ -7105,7 +7054,7 @@ class ZTableComponent {
7105
7054
  showVerticalBorder: this.showVerticalBorder(),
7106
7055
  };
7107
7056
  try {
7108
- ZCacheService.set(`table-config-${key}`, config);
7057
+ ZCacheService.set(this._getConfigCacheKey(key), config);
7109
7058
  }
7110
7059
  catch (error) {
7111
7060
  console.error('Failed to save table config:', error);
@@ -7134,12 +7083,22 @@ class ZTableComponent {
7134
7083
  return false;
7135
7084
  }
7136
7085
  try {
7137
- const config = ZCacheService.get(`table-config-${key}`);
7086
+ const cacheKey = this._getConfigCacheKey(key);
7087
+ let config = ZCacheService.get(cacheKey);
7088
+ if (!config) {
7089
+ const legacyCacheKey = `table-config-${key}`;
7090
+ const legacyConfig = ZCacheService.get(legacyCacheKey);
7091
+ if (legacyConfig && this._isColumnConfigValid(legacyConfig.columnInfo)) {
7092
+ config = legacyConfig;
7093
+ ZCacheService.set(cacheKey, legacyConfig);
7094
+ ZCacheService.delete(legacyCacheKey);
7095
+ }
7096
+ }
7138
7097
  if (!config) {
7139
7098
  return false;
7140
7099
  }
7141
7100
  if (!this._isColumnConfigValid(config.columnInfo)) {
7142
- ZCacheService.delete(`table-config-${key}`);
7101
+ ZCacheService.delete(cacheKey);
7143
7102
  return false;
7144
7103
  }
7145
7104
  if (config.columnOrder && config.columnOrder.length > 0) {
@@ -7171,6 +7130,20 @@ class ZTableComponent {
7171
7130
  return false;
7172
7131
  }
7173
7132
  }
7133
+ _getConfigCacheKey(key) {
7134
+ const collectSchema = (columns) => columns.map(column => [
7135
+ column.id,
7136
+ column.accessorKey ?? '',
7137
+ column.columns ? collectSchema(column.columns) : null,
7138
+ ]);
7139
+ const schema = JSON.stringify(collectSchema(this.zConfig().columns ?? []));
7140
+ let fingerprint = 2166136261;
7141
+ for (let index = 0; index < schema.length; index++) {
7142
+ fingerprint ^= schema.charCodeAt(index);
7143
+ fingerprint = Math.imul(fingerprint, 16777619);
7144
+ }
7145
+ return `table-config-${key}-${(fingerprint >>> 0).toString(36)}`;
7146
+ }
7174
7147
  /**
7175
7148
  * Validates cached column info against current config.
7176
7149
  * Returns false if columns have been added/removed/renamed since cache was saved,