@solcre-org/core-ui 2.12.37 → 2.12.39

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.
@@ -2154,6 +2154,8 @@ class SelectFieldComponent extends BaseFieldComponent {
2154
2154
  selectionChange = output();
2155
2155
  isInitialized = signal(false);
2156
2156
  hasValue = signal(false);
2157
+ userHasInteracted = signal(false);
2158
+ lastDynamicValue = undefined;
2157
2159
  computedValue = computed(() => {
2158
2160
  const value = this.value();
2159
2161
  if (this.field().multiple && !Array.isArray(value)) {
@@ -2207,17 +2209,13 @@ class SelectFieldComponent extends BaseFieldComponent {
2207
2209
  const formValue = this.formValue();
2208
2210
  if ('dynamicValue' in fieldCfg && typeof fieldCfg.dynamicValue === 'function' && formValue) {
2209
2211
  const newValue = fieldCfg.dynamicValue(formValue);
2210
- const currentValue = this.formControl().value;
2211
- if (newValue !== null && newValue !== undefined && newValue !== currentValue) {
2212
- setTimeout(() => {
2213
- this.formControl().setValue(newValue, { emitEvent: true });
2214
- this.valueChange.emit(newValue);
2215
- }, 0);
2216
- }
2212
+ this.scheduleDynamicValue(newValue);
2217
2213
  }
2218
2214
  });
2219
2215
  }
2220
2216
  ngOnInit() {
2217
+ this.userHasInteracted.set(false);
2218
+ this.lastDynamicValue = undefined;
2221
2219
  super.ngOnInit();
2222
2220
  const currentInitialValue = this.formControl().value;
2223
2221
  if (!this.field().multiple && typeof currentInitialValue === 'string' && currentInitialValue.trim() === '') {
@@ -2229,7 +2227,9 @@ class SelectFieldComponent extends BaseFieldComponent {
2229
2227
  String(opt.value) === String(currentInitialValue));
2230
2228
  if (matchingOption) {
2231
2229
  setTimeout(() => {
2232
- this.formControl().setValue(currentInitialValue, { emitEvent: false });
2230
+ this.formControl().setValue(currentInitialValue, { emitEvent: true });
2231
+ this.valueChange.emit(currentInitialValue);
2232
+ this.hasValue.set(true);
2233
2233
  this.isInitialized.set(true);
2234
2234
  }, 0);
2235
2235
  }
@@ -2239,13 +2239,14 @@ class SelectFieldComponent extends BaseFieldComponent {
2239
2239
  const formValue = this.formValue();
2240
2240
  if ('dynamicValue' in fieldCfg && typeof fieldCfg.dynamicValue === 'function' && formValue) {
2241
2241
  const newValue = fieldCfg.dynamicValue(formValue);
2242
- const currentValue = this.formControl().value;
2243
- if (newValue !== null && newValue !== undefined && newValue !== currentValue) {
2244
- this.formControl().setValue(newValue, { emitEvent: true });
2245
- this.valueChange.emit(newValue);
2246
- }
2242
+ this.scheduleDynamicValue(newValue);
2247
2243
  }
2248
- }, 10);
2244
+ const finalValue = this.formControl().value;
2245
+ if (finalValue !== null && finalValue !== undefined && finalValue !== '') {
2246
+ const hasValidValue = !Array.isArray(finalValue) || finalValue.length > 0;
2247
+ this.hasValue.set(hasValidValue);
2248
+ }
2249
+ }, 100);
2249
2250
  }
2250
2251
  compareWith = (item, selected) => {
2251
2252
  if (!item || selected === null || selected === undefined) {
@@ -2285,6 +2286,17 @@ class SelectFieldComponent extends BaseFieldComponent {
2285
2286
  else {
2286
2287
  finalValue = newValue;
2287
2288
  }
2289
+ const hasValidValue = finalValue !== null &&
2290
+ finalValue !== undefined &&
2291
+ finalValue !== '' &&
2292
+ (!Array.isArray(finalValue) || finalValue.length > 0);
2293
+ this.hasValue.set(hasValidValue);
2294
+ if (this.formControl().dirty && !this.userHasInteracted()) {
2295
+ this.userHasInteracted.set(true);
2296
+ }
2297
+ if (!this.areValuesEqual(finalValue, this.lastDynamicValue)) {
2298
+ this.lastDynamicValue = undefined;
2299
+ }
2288
2300
  const fieldConfig = this.field();
2289
2301
  if (fieldConfig.onSelectionChange && this.formValue()) {
2290
2302
  try {
@@ -2331,6 +2343,72 @@ class SelectFieldComponent extends BaseFieldComponent {
2331
2343
  onBlurInput() {
2332
2344
  this.onBlur();
2333
2345
  }
2346
+ scheduleDynamicValue(newValue, delay = 0) {
2347
+ const control = this.formControl();
2348
+ if (!control)
2349
+ return;
2350
+ const currentValue = control.value;
2351
+ if (!this.shouldApplyDynamicValue(newValue, currentValue)) {
2352
+ if (!this.userHasInteracted() && this.areValuesEqual(newValue, currentValue)) {
2353
+ this.lastDynamicValue = this.cloneValue(newValue);
2354
+ }
2355
+ return;
2356
+ }
2357
+ setTimeout(() => {
2358
+ const ctrl = this.formControl();
2359
+ if (!ctrl)
2360
+ return;
2361
+ const latestValue = ctrl.value;
2362
+ if (!this.shouldApplyDynamicValue(newValue, latestValue)) {
2363
+ if (!this.userHasInteracted() && this.areValuesEqual(newValue, latestValue)) {
2364
+ this.lastDynamicValue = this.cloneValue(newValue);
2365
+ }
2366
+ return;
2367
+ }
2368
+ ctrl.setValue(newValue, { emitEvent: true });
2369
+ ctrl.markAsPristine();
2370
+ this.lastDynamicValue = this.cloneValue(newValue);
2371
+ this.hasValue.set(this.hasMeaningfulValue(newValue));
2372
+ }, delay);
2373
+ }
2374
+ shouldApplyDynamicValue(newValue, currentValue) {
2375
+ if (newValue === undefined || newValue === null)
2376
+ return false;
2377
+ if (this.userHasInteracted())
2378
+ return false;
2379
+ const hasCurrentValue = this.hasMeaningfulValue(currentValue);
2380
+ const currentMatchesLastDynamic = this.areValuesEqual(currentValue, this.lastDynamicValue);
2381
+ if (hasCurrentValue && !currentMatchesLastDynamic) {
2382
+ return false;
2383
+ }
2384
+ return !this.areValuesEqual(newValue, currentValue);
2385
+ }
2386
+ hasMeaningfulValue(value) {
2387
+ if (value === null || value === undefined) {
2388
+ return false;
2389
+ }
2390
+ if (Array.isArray(value)) {
2391
+ return value.length > 0;
2392
+ }
2393
+ if (typeof value === 'string') {
2394
+ return value.trim() !== '';
2395
+ }
2396
+ return true;
2397
+ }
2398
+ areValuesEqual(a, b) {
2399
+ if (Array.isArray(a) && Array.isArray(b)) {
2400
+ if (a.length !== b.length)
2401
+ return false;
2402
+ return a.every((item, index) => item === b[index]);
2403
+ }
2404
+ return a === b;
2405
+ }
2406
+ cloneValue(value) {
2407
+ if (Array.isArray(value)) {
2408
+ return [...value];
2409
+ }
2410
+ return value;
2411
+ }
2334
2412
  onSelectChange(value) {
2335
2413
  const hasValidValue = value !== null &&
2336
2414
  value !== undefined &&
@@ -5460,14 +5538,17 @@ class GenericModalComponent {
5460
5538
  const payloadKey = (field.keyToPayload ?? field.key);
5461
5539
  const modeConfig = field.modes?.[this.mode()];
5462
5540
  const defaultValue = modeConfig?.defaultValue ?? field.defaultValue;
5541
+ let initialValue = newInstance[fieldKey];
5463
5542
  if (this.mode() === ModalMode.CREATE) {
5464
- if (defaultValue !== undefined && newInstance[fieldKey] === undefined) {
5543
+ if (defaultValue !== undefined) {
5465
5544
  if (typeof defaultValue === 'function') {
5466
5545
  const computedValue = defaultValue(newInstance);
5467
5546
  newInstance[payloadKey] = computedValue;
5547
+ initialValue = computedValue;
5468
5548
  }
5469
5549
  else {
5470
5550
  newInstance[payloadKey] = defaultValue;
5551
+ initialValue = defaultValue;
5471
5552
  }
5472
5553
  }
5473
5554
  }
@@ -5475,42 +5556,51 @@ class GenericModalComponent {
5475
5556
  if (typeof defaultValue === 'function') {
5476
5557
  const computedValue = defaultValue(newInstance);
5477
5558
  newInstance[payloadKey] = computedValue;
5559
+ initialValue = computedValue;
5478
5560
  }
5479
5561
  }
5480
5562
  const validators = modeConfig?.validators ?? field.validators ?? [];
5481
- formGroup[fieldKey] = [newInstance[fieldKey], validators];
5563
+ formGroup[fieldKey] = [initialValue, validators];
5482
5564
  });
5483
5565
  this.form.set(this.formBuilder.group(formGroup));
5484
- this.allFields().forEach(field => {
5485
- const fieldKey = field.key;
5486
- const payloadKey = (field.keyToPayload ?? field.key);
5487
- if ('dynamicValue' in field && typeof field.dynamicValue === 'function') {
5488
- const dynamicVal = field.dynamicValue(newInstance);
5489
- if (dynamicVal !== undefined) {
5490
- newInstance[payloadKey] = dynamicVal;
5491
- const control = this.form().get(fieldKey);
5492
- if (control) {
5493
- control.setValue(dynamicVal, { emitEvent: false });
5566
+ setTimeout(() => {
5567
+ this.allFields().forEach(field => {
5568
+ const fieldKey = field.key;
5569
+ const payloadKey = (field.keyToPayload ?? field.key);
5570
+ const modeConfig = field.modes?.[this.mode()];
5571
+ const dynamicValueFn = (modeConfig?.dynamicValue ?? field.dynamicValue);
5572
+ if (typeof dynamicValueFn === 'function') {
5573
+ const dynamicVal = dynamicValueFn(newInstance);
5574
+ if (dynamicVal !== undefined && dynamicVal !== null) {
5575
+ newInstance[payloadKey] = dynamicVal;
5576
+ const control = this.form().get(fieldKey);
5577
+ if (control) {
5578
+ control.setValue(dynamicVal, { emitEvent: true });
5579
+ }
5494
5580
  }
5495
5581
  }
5496
- }
5497
- });
5498
- setTimeout(() => {
5582
+ });
5583
+ this.allFields().forEach(field => {
5584
+ const fieldKey = field.key;
5585
+ const control = this.form().get(fieldKey);
5586
+ if (control && control.value !== undefined && control.value !== null) {
5587
+ const payloadKey = (field.keyToPayload ?? field.key);
5588
+ newInstance[payloadKey] = control.value;
5589
+ }
5590
+ });
5499
5591
  Object.values(this.form().controls).forEach(control => {
5500
5592
  control.markAsUntouched();
5501
5593
  });
5502
5594
  this.fieldErrors.set({});
5503
5595
  this.internalErrors.set([]);
5504
- }, 0);
5505
- this.editedData.set(newInstance);
5506
- if (this.mode() !== ModalMode.VIEW) {
5507
- const originalCopy = Object.create(Object.getPrototypeOf(newInstance));
5508
- Object.assign(originalCopy, newInstance);
5509
- this.originalData.set(originalCopy);
5510
- }
5511
- setTimeout(() => {
5596
+ this.editedData.set(newInstance);
5597
+ if (this.mode() !== ModalMode.VIEW) {
5598
+ const originalCopy = Object.create(Object.getPrototypeOf(newInstance));
5599
+ Object.assign(originalCopy, newInstance);
5600
+ this.originalData.set(originalCopy);
5601
+ }
5512
5602
  this.modalData.emit(newInstance);
5513
- }, 1);
5603
+ }, 50);
5514
5604
  }
5515
5605
  initializeActiveTabAndStep() {
5516
5606
  if (this.hasTabs()) {
@@ -13267,11 +13357,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.6", ngImpor
13267
13357
  // Este archivo es generado automáticamente por scripts/update-version.js
13268
13358
  // No edites manualmente este archivo
13269
13359
  const VERSION = {
13270
- full: '2.12.37',
13360
+ full: '2.12.39',
13271
13361
  major: 2,
13272
13362
  minor: 12,
13273
- patch: 37,
13274
- timestamp: '2025-09-17T13:18:31.604Z',
13363
+ patch: 39,
13364
+ timestamp: '2025-09-17T15:15:12.462Z',
13275
13365
  buildDate: '17/9/2025'
13276
13366
  };
13277
13367