@shival99/z-ui 1.6.2 → 1.6.4

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.
@@ -2,7 +2,7 @@ import { moveItemInArray, CdkDropList, CdkDrag } from '@angular/cdk/drag-drop';
2
2
  import { ScrollingModule } from '@angular/cdk/scrolling';
3
3
  import { NgClass, NgStyle, NgTemplateOutlet } from '@angular/common';
4
4
  import * as i0 from '@angular/core';
5
- import { input, output, computed, ChangeDetectionStrategy, Component, inject, DestroyRef, Injector, signal, ElementRef, Renderer2, Directive, NgZone, Pipe, TemplateRef, viewChild, viewChildren, untracked, effect, afterNextRender } from '@angular/core';
5
+ import { input, output, computed, ChangeDetectionStrategy, Component, inject, DestroyRef, Injector, signal, effect, ElementRef, Renderer2, Directive, NgZone, Pipe, TemplateRef, viewChild, viewChildren, untracked, afterNextRender } from '@angular/core';
6
6
  import { TranslatePipe } from '@ngx-translate/core';
7
7
  import { injectVirtualizer } from '@shival99/angular-virtual';
8
8
  import { ZButtonComponent } from '@shival99/z-ui/components/z-button';
@@ -255,10 +255,15 @@ class ZTableEditCellComponent {
255
255
  zChange = output();
256
256
  _currentValue = signal(undefined, ...(ngDevMode ? [{ debugName: "_currentValue" }] : []));
257
257
  _valueChange$ = new Subject();
258
- _initialized = false;
259
258
  _pendingBlurValue = undefined;
260
259
  _hasPendingBlur = false;
261
260
  _inputControl = null;
261
+ constructor() {
262
+ effect(() => {
263
+ const externalValue = this.zValue();
264
+ this._currentValue.set(externalValue);
265
+ });
266
+ }
262
267
  editConfig = computed(() => {
263
268
  const config = this.zEditConfig();
264
269
  if (!config || typeof config === 'boolean') {
@@ -302,28 +307,22 @@ class ZTableEditCellComponent {
302
307
  if (!optionsConfig) {
303
308
  return [];
304
309
  }
305
- let rawOptions;
306
- if (typeof optionsConfig === 'function') {
307
- rawOptions = optionsConfig(this.zRow());
308
- }
309
- else {
310
- rawOptions = optionsConfig;
311
- }
310
+ const rawOptions = typeof optionsConfig === 'function' ? optionsConfig(this.zRow()) : optionsConfig;
312
311
  const labelKey = config?.optionLabelKey;
313
312
  const valueKey = config?.optionValueKey;
314
- if (labelKey || valueKey) {
315
- return rawOptions.map((opt) => {
316
- if (typeof opt !== 'object' || opt === null) {
317
- return { label: String(opt), value: opt };
318
- }
319
- const obj = opt;
320
- return {
321
- label: String(obj[labelKey ?? 'label'] ?? ''),
322
- value: obj[valueKey ?? 'value'],
323
- };
324
- });
313
+ if (!labelKey && !valueKey) {
314
+ return rawOptions;
325
315
  }
326
- return rawOptions;
316
+ return rawOptions.map((opt) => {
317
+ if (typeof opt !== 'object' || opt === null) {
318
+ return { label: String(opt), value: opt };
319
+ }
320
+ const obj = opt;
321
+ return {
322
+ label: String(obj[labelKey ?? 'label'] ?? ''),
323
+ value: obj[valueKey ?? 'value'],
324
+ };
325
+ });
327
326
  }, ...(ngDevMode ? [{ debugName: "selectOptions" }] : []));
328
327
  isDisabled = computed(() => {
329
328
  const config = this.editConfig();
@@ -345,12 +344,7 @@ class ZTableEditCellComponent {
345
344
  }
346
345
  return config.readonly;
347
346
  }, ...(ngDevMode ? [{ debugName: "isReadonly" }] : []));
348
- value = computed(() => {
349
- if (this._initialized) {
350
- return this._currentValue();
351
- }
352
- return this.zValue();
353
- }, ...(ngDevMode ? [{ debugName: "value" }] : []));
347
+ value = computed(() => this._currentValue(), ...(ngDevMode ? [{ debugName: "value" }] : []));
354
348
  stringValue = computed(() => {
355
349
  const val = this.value();
356
350
  if (val === null || val === undefined) {
@@ -384,7 +378,6 @@ class ZTableEditCellComponent {
384
378
  onValueChange(newValue) {
385
379
  const oldValue = this.zValue();
386
380
  this._currentValue.set(newValue);
387
- this._initialized = true;
388
381
  const config = this.editConfig();
389
382
  if (config?.blurEdit) {
390
383
  this._pendingBlurValue = newValue;
@@ -406,32 +399,27 @@ class ZTableEditCellComponent {
406
399
  this._emitChange(oldValue, this._pendingBlurValue);
407
400
  }
408
401
  onToggleChange(checked) {
409
- const oldValue = this.zValue();
410
- this._currentValue.set(checked);
411
- this._initialized = true;
412
- this._emitChange(oldValue, checked);
402
+ this._handleImmediateChange(checked);
413
403
  }
414
404
  onSelectChange(newValue) {
415
- const oldValue = this.zValue();
416
- let finalValue = newValue;
417
- if (typeof newValue === 'object' && newValue !== null && 'value' in newValue) {
418
- finalValue = newValue.value;
419
- }
420
- this._currentValue.set(finalValue);
421
- this._initialized = true;
422
- this._emitChange(oldValue, finalValue);
405
+ const isWrappedObject = typeof newValue === 'object' && newValue !== null && 'value' in newValue;
406
+ const finalValue = isWrappedObject ? newValue.value : newValue;
407
+ this._handleImmediateChange(finalValue);
423
408
  }
424
409
  onDateChange(newValue) {
425
- const oldValue = this.zValue();
426
- this._currentValue.set(newValue);
427
- this._initialized = true;
428
- this._emitChange(oldValue, newValue);
410
+ this._handleImmediateChange(newValue);
429
411
  }
430
412
  onCheckboxChange(checked) {
413
+ this._handleImmediateChange(checked);
414
+ }
415
+ /**
416
+ * Handles immediate value changes (non-debounced).
417
+ * Used by checkbox, toggle, select, and date controls.
418
+ */
419
+ _handleImmediateChange(newValue) {
431
420
  const oldValue = this.zValue();
432
- this._currentValue.set(checked);
433
- this._initialized = true;
434
- this._emitChange(oldValue, checked);
421
+ this._currentValue.set(newValue);
422
+ this._emitChange(oldValue, newValue);
435
423
  }
436
424
  _emitChange(oldValue, newValue) {
437
425
  this.zChange.emit({
@@ -663,7 +651,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
663
651
  `, changeDetection: ChangeDetectionStrategy.OnPush, host: {
664
652
  class: 'z-table-edit-cell block',
665
653
  }, styles: [":host{display:block;width:100%}\n"] }]
666
- }], propDecorators: { zRow: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRow", required: true }] }], zRowId: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRowId", required: true }] }], zRowIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRowIndex", required: true }] }], zColumnId: [{ type: i0.Input, args: [{ isSignal: true, alias: "zColumnId", required: true }] }], zValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "zValue", required: false }] }], zEditConfig: [{ type: i0.Input, args: [{ isSignal: true, alias: "zEditConfig", required: false }] }], zChange: [{ type: i0.Output, args: ["zChange"] }] } });
654
+ }], ctorParameters: () => [], propDecorators: { zRow: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRow", required: true }] }], zRowId: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRowId", required: true }] }], zRowIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "zRowIndex", required: true }] }], zColumnId: [{ type: i0.Input, args: [{ isSignal: true, alias: "zColumnId", required: true }] }], zValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "zValue", required: false }] }], zEditConfig: [{ type: i0.Input, args: [{ isSignal: true, alias: "zEditConfig", required: false }] }], zChange: [{ type: i0.Output, args: ["zChange"] }] } });
667
655
 
668
656
  class ZTableFilterComponent {
669
657
  zColumn = input.required(...(ngDevMode ? [{ debugName: "zColumn" }] : []));