@shival99/z-ui 1.6.1 → 1.6.3

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.
@@ -255,7 +255,7 @@ class ZTableEditCellComponent {
255
255
  zChange = output();
256
256
  _currentValue = signal(undefined, ...(ngDevMode ? [{ debugName: "_currentValue" }] : []));
257
257
  _valueChange$ = new Subject();
258
- _initialized = false;
258
+ _lastExternalValue = undefined;
259
259
  _pendingBlurValue = undefined;
260
260
  _hasPendingBlur = false;
261
261
  _inputControl = null;
@@ -283,18 +283,41 @@ class ZTableEditCellComponent {
283
283
  }, ...(ngDevMode ? [{ debugName: "size" }] : []));
284
284
  placeholder = computed(() => {
285
285
  const config = this.editConfig();
286
- return config?.placeholder ?? '';
286
+ const placeholderConfig = config?.placeholder;
287
+ if (!placeholderConfig) {
288
+ return '';
289
+ }
290
+ if (typeof placeholderConfig === 'function') {
291
+ return placeholderConfig(this.zRow());
292
+ }
293
+ return placeholderConfig;
287
294
  }, ...(ngDevMode ? [{ debugName: "placeholder" }] : []));
295
+ allowClear = computed(() => {
296
+ const config = this.editConfig();
297
+ return config?.allowClear ?? false;
298
+ }, ...(ngDevMode ? [{ debugName: "allowClear" }] : []));
288
299
  selectOptions = computed(() => {
289
300
  const config = this.editConfig();
290
301
  const optionsConfig = config?.options;
291
302
  if (!optionsConfig) {
292
303
  return [];
293
304
  }
294
- if (typeof optionsConfig === 'function') {
295
- return optionsConfig(this.zRow());
305
+ const rawOptions = typeof optionsConfig === 'function' ? optionsConfig(this.zRow()) : optionsConfig;
306
+ const labelKey = config?.optionLabelKey;
307
+ const valueKey = config?.optionValueKey;
308
+ if (!labelKey && !valueKey) {
309
+ return rawOptions;
296
310
  }
297
- return optionsConfig;
311
+ return rawOptions.map((opt) => {
312
+ if (typeof opt !== 'object' || opt === null) {
313
+ return { label: String(opt), value: opt };
314
+ }
315
+ const obj = opt;
316
+ return {
317
+ label: String(obj[labelKey ?? 'label'] ?? ''),
318
+ value: obj[valueKey ?? 'value'],
319
+ };
320
+ });
298
321
  }, ...(ngDevMode ? [{ debugName: "selectOptions" }] : []));
299
322
  isDisabled = computed(() => {
300
323
  const config = this.editConfig();
@@ -317,10 +340,13 @@ class ZTableEditCellComponent {
317
340
  return config.readonly;
318
341
  }, ...(ngDevMode ? [{ debugName: "isReadonly" }] : []));
319
342
  value = computed(() => {
320
- if (this._initialized) {
321
- return this._currentValue();
343
+ const externalValue = this.zValue();
344
+ if (externalValue !== this._lastExternalValue) {
345
+ this._lastExternalValue = externalValue;
346
+ this._currentValue.set(externalValue);
347
+ return externalValue;
322
348
  }
323
- return this.zValue();
349
+ return this._currentValue();
324
350
  }, ...(ngDevMode ? [{ debugName: "value" }] : []));
325
351
  stringValue = computed(() => {
326
352
  const val = this.value();
@@ -355,7 +381,6 @@ class ZTableEditCellComponent {
355
381
  onValueChange(newValue) {
356
382
  const oldValue = this.zValue();
357
383
  this._currentValue.set(newValue);
358
- this._initialized = true;
359
384
  const config = this.editConfig();
360
385
  if (config?.blurEdit) {
361
386
  this._pendingBlurValue = newValue;
@@ -377,32 +402,27 @@ class ZTableEditCellComponent {
377
402
  this._emitChange(oldValue, this._pendingBlurValue);
378
403
  }
379
404
  onToggleChange(checked) {
380
- const oldValue = this.zValue();
381
- this._currentValue.set(checked);
382
- this._initialized = true;
383
- this._emitChange(oldValue, checked);
405
+ this._handleImmediateChange(checked);
384
406
  }
385
407
  onSelectChange(newValue) {
386
- const oldValue = this.zValue();
387
- let finalValue = newValue;
388
- if (typeof newValue === 'object' && newValue !== null && 'value' in newValue) {
389
- finalValue = newValue.value;
390
- }
391
- this._currentValue.set(finalValue);
392
- this._initialized = true;
393
- this._emitChange(oldValue, finalValue);
408
+ const isWrappedObject = typeof newValue === 'object' && newValue !== null && 'value' in newValue;
409
+ const finalValue = isWrappedObject ? newValue.value : newValue;
410
+ this._handleImmediateChange(finalValue);
394
411
  }
395
412
  onDateChange(newValue) {
396
- const oldValue = this.zValue();
397
- this._currentValue.set(newValue);
398
- this._initialized = true;
399
- this._emitChange(oldValue, newValue);
413
+ this._handleImmediateChange(newValue);
400
414
  }
401
415
  onCheckboxChange(checked) {
416
+ this._handleImmediateChange(checked);
417
+ }
418
+ /**
419
+ * Handles immediate value changes (non-debounced).
420
+ * Used by checkbox, toggle, select, and date controls.
421
+ */
422
+ _handleImmediateChange(newValue) {
402
423
  const oldValue = this.zValue();
403
- this._currentValue.set(checked);
404
- this._initialized = true;
405
- this._emitChange(oldValue, checked);
424
+ this._currentValue.set(newValue);
425
+ this._emitChange(oldValue, newValue);
406
426
  }
407
427
  _emitChange(oldValue, newValue) {
408
428
  this.zChange.emit({
@@ -482,6 +502,7 @@ class ZTableEditCellComponent {
482
502
  [zWrap]="false"
483
503
  [zScrollClose]="true"
484
504
  [zOptions]="selectOptions()"
505
+ [zAllowClear]="allowClear()"
485
506
  [zDisabled]="isDisabled() || isReadonly()"
486
507
  [ngModel]="value()"
487
508
  [zPlaceholder]="placeholder()"
@@ -580,6 +601,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
580
601
  [zWrap]="false"
581
602
  [zScrollClose]="true"
582
603
  [zOptions]="selectOptions()"
604
+ [zAllowClear]="allowClear()"
583
605
  [zDisabled]="isDisabled() || isReadonly()"
584
606
  [ngModel]="value()"
585
607
  [zPlaceholder]="placeholder()"