@myrtex-org/form 1.1.92 → 1.1.94

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.
@@ -1264,8 +1264,51 @@ class ComponentFactoryDirective {
1264
1264
  }
1265
1265
  }
1266
1266
  applyValues(values) {
1267
- if (this.dynamicComponent) {
1268
- this.dynamicComponent.instance.values = values;
1267
+ if (!this.dynamicComponent) {
1268
+ return;
1269
+ }
1270
+ // Сохраняем базовое поведение системы Myrtex
1271
+ this.dynamicComponent.instance.values = values;
1272
+ // ХАК ДЛЯ РЕЖИМА МОДАЛКИ (MANUAL):
1273
+ // Принудительно инициализируем компоненты дат в обход пустого Стора
1274
+ const currentMode = this.valueMode || this.dynamicComponent.instance.valueMode;
1275
+ if (currentMode === 'manual' && values && this.data) {
1276
+ const targetField = values.find((v) => v.sysName === this.data?.sysName);
1277
+ const instance = this.dynamicComponent.instance;
1278
+ if (targetField && targetField.value !== undefined && targetField.value !== null) {
1279
+ const componentOptions = this.data?.options;
1280
+ // Специфичный хак для InputDate с range: true
1281
+ if (this.type === 'inputDate' && componentOptions?.range && Array.isArray(targetField.value)) {
1282
+ // Проверяем, что лежит внутри массива. Если там строки, заворачиваем их в объекты, которые ждет компонент
1283
+ const firstElement = targetField.value[0];
1284
+ const secondElement = targetField.value[1];
1285
+ const startValue = firstElement?.sysName ? firstElement.value : firstElement;
1286
+ const endValue = secondElement?.sysName ? secondElement.value : secondElement;
1287
+ // Формируем полноценные структуры ComponentValueModel
1288
+ instance.modelStart = {
1289
+ sysName: targetField.sysName,
1290
+ type: targetField.type,
1291
+ valueType: targetField.valueType,
1292
+ value: startValue || null
1293
+ };
1294
+ instance.modelEnd = {
1295
+ sysName: targetField.sysName,
1296
+ type: targetField.type,
1297
+ valueType: targetField.valueType,
1298
+ value: endValue || null
1299
+ };
1300
+ if (typeof instance._customInit === 'function') {
1301
+ instance._customInit();
1302
+ }
1303
+ }
1304
+ else if (this.type === 'inputDate') {
1305
+ // Для одиночной даты
1306
+ instance.model = structuredClone(targetField);
1307
+ if (typeof instance._customInit === 'function') {
1308
+ instance._customInit();
1309
+ }
1310
+ }
1311
+ }
1269
1312
  }
1270
1313
  }
1271
1314
  applyValueMode(valueMode) {
@@ -2509,43 +2552,26 @@ class InputTableComponent {
2509
2552
  return;
2510
2553
  const rowModel = structuredClone(localRow);
2511
2554
  const gridData = event.row?.data || event.data;
2512
- // СИНХРОНИЗАЦИЯ И РАСПАКОВКА ДЛЯ ДИСПЕНСЕРА МОДАЛКИ
2513
2555
  if (rowModel.data && Array.isArray(rowModel.data)) {
2514
- const patchedData = [];
2515
- rowModel.data.forEach((cell) => {
2556
+ rowModel.data = rowModel.data.map((cell) => {
2516
2557
  if (gridData && gridData[cell.sysName] !== undefined) {
2517
2558
  const currentValue = gridData[cell.sysName];
2518
- // Если это рендж-дата и в гриде лежит наш сохраненный массив из 2-х элементов
2519
- if (cell.type === 'inputDate' && Array.isArray(currentValue) && currentValue.length === 2) {
2520
- // 1. Записываем массив в основной cell.value (на случай, если диспенсер обновился)
2521
- cell.value = structuredClone(currentValue);
2522
- patchedData.push(cell);
2523
- // 2. ИСКУССТВЕННО ДОБАВЛЯЕМ СТАРТ И КОНЕЦ ДЛЯ ИНИЦИАЛИЗАЦИИ ВНУТРИ КАЛЕНДАРЯ
2524
- // Многие версии Myrtex UI ищут именно суффиксы при range: true
2525
- patchedData.push({
2526
- ...cell,
2527
- sysName: `${cell.sysName}_start`,
2528
- value: currentValue[0]
2529
- });
2530
- patchedData.push({
2531
- ...cell,
2532
- sysName: `${cell.sysName}_end`,
2533
- value: currentValue[1]
2534
- });
2559
+ // Если это range-дата и в гриде лежит массив из 2-х элементов
2560
+ if (cell.type === 'inputDate' && cell.options?.range && Array.isArray(currentValue)) {
2561
+ // Формируем структуру [ modelStart, modelEnd ], которую ждет InputDateComponent
2562
+ cell.value = [
2563
+ { sysName: cell.sysName, type: cell.type, valueType: cell.valueType, value: currentValue[0] },
2564
+ { sysName: cell.sysName, type: cell.type, valueType: cell.valueType, value: currentValue[1] }
2565
+ ];
2535
2566
  }
2536
2567
  else {
2537
- // Для всех остальных типов полей просто копируем значение из Грида
2538
2568
  cell.value = structuredClone(currentValue);
2539
- patchedData.push(cell);
2540
2569
  }
2541
2570
  }
2542
- else {
2543
- patchedData.push(cell);
2544
- }
2571
+ return cell;
2545
2572
  });
2546
- rowModel.data = patchedData;
2547
2573
  }
2548
- console.log('[Table -> Edit Row] Подготовленная rowModel для диспенсера:', rowModel);
2574
+ console.log('[Table -> Edit Row] Чистая модель для модалки:', structuredClone(rowModel));
2549
2575
  this._modalService.open(InputTableModalComponent, {
2550
2576
  title: 'Редактирование строки',
2551
2577
  okText: 'Сохранить',
@@ -2554,10 +2580,15 @@ class InputTableComponent {
2554
2580
  isCheckRequired: this._isCheckRequired
2555
2581
  }).afterClosed().subscribe(resolve => {
2556
2582
  if (resolve && resolve.result && resolve.rowModel) {
2557
- // Перед сохранением очищаем наши искусственные _start и _end поля,
2558
- // оставляя только чистое основное поле с массивом дат
2583
+ // При сохранении вытаскиваем из структуры [modelStart, modelEnd] чистый массив дат обратно для грида
2559
2584
  if (resolve.rowModel.data && Array.isArray(resolve.rowModel.data)) {
2560
- resolve.rowModel.data = resolve.rowModel.data.filter((cell) => !cell.sysName.endsWith('_start') && !cell.sysName.endsWith('_end'));
2585
+ resolve.rowModel.data = resolve.rowModel.data.map((cell) => {
2586
+ if (cell.type === 'inputDate' && cell.options?.range && Array.isArray(cell.value)) {
2587
+ // Если там прилетел массив моделей (или массив строк от componentValueChanged)
2588
+ cell.value = cell.value.map((item) => item?.sysName ? item.value : item);
2589
+ }
2590
+ return cell;
2591
+ });
2561
2592
  }
2562
2593
  this._rows = this._rows.map((r) => r.id === rowId ? resolve.rowModel : r);
2563
2594
  this._initDataSource(this._rows);