@archbase/components 4.0.38 → 4.0.40

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archbase/components",
3
- "version": "4.0.38",
3
+ "version": "4.0.40",
4
4
  "description": "UI Components for Archbase React v3 - Form editors, data visualization, and business components",
5
5
  "author": "Edson Martins <edsonmartins2005@gmail.com>",
6
6
  "license": "MIT",
@@ -118,9 +118,9 @@
118
118
  "vis-timeline": "^7.7.3",
119
119
  "xlsx": "^0.18.5",
120
120
  "yet-another-react-lightbox": "^3.21.0",
121
- "@archbase/core": "4.0.38",
122
- "@archbase/data": "4.0.38",
123
- "@archbase/layout": "4.0.38"
121
+ "@archbase/core": "4.0.40",
122
+ "@archbase/data": "4.0.40",
123
+ "@archbase/layout": "4.0.40"
124
124
  },
125
125
  "devDependencies": {
126
126
  "@types/d3": "^7.4.3",
@@ -9,7 +9,7 @@ import {
9
9
  import { DataSourceEventNames } from '@archbase/data';
10
10
  import { useArchbaseDidUpdate } from '@archbase/data';
11
11
  import { useArchbaseV1V2Compatibility } from '@archbase/data';
12
- import { useValidationErrors } from '@archbase/core';
12
+ import { convertISOStringToDate, convertDateToISOString, useValidationErrors } from '@archbase/core';
13
13
 
14
14
  type OmittedDateTimePickerProps = Omit<DateTimePickerProps, 'value' | 'onChange'>;
15
15
 
@@ -67,6 +67,9 @@ import {
67
67
  const [currentValue, setCurrentValue] = useState<Date | null>(value || null);
68
68
  const [internalError, setInternalError] = useState<string | undefined>(undefined);
69
69
  const forceUpdate = useForceUpdate();
70
+ // Previne que eventos síncronos do datasource (disparados durante setFieldValue)
71
+ // sobrescrevam o valor recém-definido pelo usuário com o valor antigo
72
+ const isUserChanging = useRef(false);
70
73
 
71
74
  // 🔄 MIGRAÇÃO V1/V2: Hook de compatibilidade
72
75
  const v1v2Compatibility = useArchbaseV1V2Compatibility<Date | null>(
@@ -98,6 +101,10 @@ import {
98
101
  }, [error]);
99
102
 
100
103
  const loadDataSourceFieldValue = () => {
104
+ // Não recarregar durante uma mudança iniciada pelo usuário — evita que eventos
105
+ // síncronos do datasource sobrescrevam o valor recém-definido com o valor antigo
106
+ if (isUserChanging.current) return;
107
+
101
108
  let initialValue: Date | null = currentValue;
102
109
 
103
110
  if (dataSource && dataField) {
@@ -108,9 +115,9 @@ import {
108
115
  // Verificar se é uma data válida
109
116
  initialValue = isNaN(rawValue.getTime()) ? null : rawValue;
110
117
  } else if (typeof rawValue === 'string') {
111
- // Converter string ISO para Date
112
- const date = new Date(rawValue);
113
- initialValue = isNaN(date.getTime()) ? null : date;
118
+ // Converter string para Date (trata formato ISO e formato Mantine "YYYY-MM-DD HH:mm:ss")
119
+ const date = convertISOStringToDate(rawValue);
120
+ initialValue = date && !isNaN(date.getTime()) ? date : null;
114
121
  } else {
115
122
  initialValue = null;
116
123
  }
@@ -182,22 +189,32 @@ useEffect(() => {
182
189
  loadDataSourceFieldValue();
183
190
  }, []);
184
191
 
185
- const handleChange = (changedValue: string | null) => {
186
- // ✅ Limpa erro quando usuário edita o campo (tanto do estado local quanto do contexto)
192
+ const handleChange = (changedValue: string | Date | null) => {
187
193
  const hasError = internalError || contextError;
188
194
  if (hasError) {
189
195
  setInternalError(undefined);
190
196
  validationContext?.clearError(fieldKey);
191
197
  }
192
198
 
193
- // Mantine DateTimePicker retorna string | null, converter para Date
194
- const dateValue = changedValue ? new Date(changedValue) : null;
195
- // Validar se a data é válida
196
- const validDate = dateValue && !isNaN(dateValue.getTime()) ? dateValue : null;
199
+ // Mantine 9.x passa string "YYYY-MM-DD HH:mm:ss" via assignTime; por segurança trata também Date
200
+ let validDate: Date | null = null;
201
+ if (changedValue instanceof Date) {
202
+ validDate = !isNaN(changedValue.getTime()) ? changedValue : null;
203
+ } else if (typeof changedValue === 'string' && changedValue) {
204
+ const parsed = convertISOStringToDate(changedValue);
205
+ validDate = parsed && !isNaN(parsed.getTime()) ? parsed : null;
206
+ }
207
+
197
208
  setCurrentValue(validDate);
198
209
 
199
- // 🔄 MIGRAÇÃO V1/V2: Usar handleValueChange do padrão de compatibilidade
200
- v1v2Compatibility.handleValueChange(validDate);
210
+ // Armazena ISO string no datasource (campos de data são string, não Date)
211
+ // Evita o bug do V1 datasource onde parseISO(Date) produz Invalid Date → null na serialização
212
+ const isoValue = validDate ? convertDateToISOString(validDate) : null;
213
+ isUserChanging.current = true;
214
+ if (dataSource && !dataSource.isBrowsing() && dataField) {
215
+ dataSource.setFieldValue(dataField, isoValue);
216
+ }
217
+ isUserChanging.current = false;
201
218
 
202
219
  if (onChange) {
203
220
  onChange(validDate);
@@ -361,7 +361,19 @@ export function ArchbaseRichTextEdit<T, ID>({
361
361
  onChangeValue(content);
362
362
  }
363
363
  };
364
- const handleOnBlur = (event: FocusEvent, _editorContents: string) => {
364
+ const handleOnBlur = (event: FocusEvent, editorContents: string) => {
365
+ // Garante que o conteúdo final seja salvo ao perder foco (ex: troca rápida de aba),
366
+ // pois o SunEditor pode não ter disparado onChange para os últimos keystrokes.
367
+ if (dataSource && !dataSource.isBrowsing() && dataField) {
368
+ const valueToSave = disabledBase64Convertion ? editorContents : btoa(editorContents);
369
+ if (dataSource.getFieldValue(dataField) !== valueToSave) {
370
+ v1v2Compatibility.handleValueChange(valueToSave);
371
+ setCurrentValue(editorContents);
372
+ }
373
+ }
374
+ if (onChangeValue) {
375
+ onChangeValue(editorContents);
376
+ }
365
377
  if (onFocusExit) {
366
378
  onFocusExit(event);
367
379
  }
Binary file