@archbase/components 4.0.0 → 4.0.2

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.0",
3
+ "version": "4.0.2",
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",
@@ -38,9 +38,9 @@
38
38
  "react-dom": "^18.3.0 || ^19.2.0"
39
39
  },
40
40
  "dependencies": {
41
- "@archbase/core": "4.0.0",
42
- "@archbase/data": "4.0.0",
43
- "@archbase/layout": "4.0.0",
41
+ "@archbase/core": "4.0.2",
42
+ "@archbase/data": "4.0.2",
43
+ "@archbase/layout": "4.0.2",
44
44
  "@fortune-sheet/core": "^1.0.4",
45
45
  "@fortune-sheet/react": "^1.0.4",
46
46
  "@pdfme/ui": "^5.3.6",
@@ -143,7 +143,7 @@
143
143
  "@types/react-mentions": "^4.1.13"
144
144
  },
145
145
  "publishConfig": {
146
- "registry": "http://192.168.1.110:4873"
146
+ "registry": "http://192.168.100.5:4873"
147
147
  },
148
148
  "scripts": {
149
149
  "dev": "NODE_OPTIONS=\"--max-old-space-size=16384\" vite build --watch",
@@ -260,12 +260,15 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
260
260
  });
261
261
 
262
262
  // Estado para paginação com limitação de tamanho de página (MIT version)
263
- const [paginationModel, setPaginationModel] = useState({
264
- page: Number.isFinite(getCurrentPageFromDataSource(dataSource)) ? getCurrentPageFromDataSource(dataSource) : pageIndex,
265
- pageSize: Math.min(
266
- Number.isFinite(dataSource?.getPageSize?.()) ? dataSource.getPageSize() : pageSize,
267
- MAX_PAGE_SIZE_MIT
268
- )
263
+ const [paginationModel, setPaginationModel] = useState(() => {
264
+ const page = getCurrentPageFromDataSource(dataSource);
265
+ return {
266
+ page: Number.isFinite(page) ? page : pageIndex,
267
+ pageSize: Math.min(
268
+ Number.isFinite(dataSource?.getPageSize?.()) ? dataSource.getPageSize() : pageSize,
269
+ MAX_PAGE_SIZE_MIT
270
+ )
271
+ };
269
272
  });
270
273
 
271
274
  const [sortModel, setSortModel] = useState(() => getInitialSortModel(dataSource))
@@ -312,6 +315,13 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
312
315
  rowHeight,
313
316
  detailPanelMinHeight
314
317
  })
318
+ // Ref que mantém sempre os valores mais recentes para uso no handler do DataSource.
319
+ // Evita que o listener useEffect precise re-registrar o handler a cada mudança de deps instáveis.
320
+ const handlerDepsRef = useRef<any>({})
321
+ useEffect(() => {
322
+ handlerDepsRef.current = { rows, getRowId, columns, apiRef, onSelectedRowsChanged, closeAllDetailPanels }
323
+ })
324
+
315
325
  // Refs para controle de operações internas
316
326
  const syncInProgress = useRef<boolean>(false)
317
327
  const keyboardNavDebounceTimer = useRef<NodeJS.Timeout | null>(null)
@@ -776,6 +786,10 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
776
786
 
777
787
  // Scrollbar nativa (fallback) - estilo Mantine
778
788
  '& .MuiDataGrid-virtualScroller': {
789
+ paddingBottom: '0px !important',
790
+ display: 'flex',
791
+ flexDirection: 'column',
792
+ backgroundColor: `${colorScheme === 'dark' ? theme.colors.dark[6] : theme.white} !important`,
779
793
  '&::-webkit-scrollbar': {
780
794
  width: '8px',
781
795
  height: '8px',
@@ -926,13 +940,6 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
926
940
  width: '100%'
927
941
  },
928
942
 
929
- '& .MuiDataGrid-virtualScroller': {
930
- paddingBottom: '0px !important',
931
- display: 'flex',
932
- flexDirection: 'column',
933
- backgroundColor: `${colorScheme === 'dark' ? theme.colors.dark[6] : theme.white} !important`,
934
- },
935
-
936
943
  '& .MuiDataGrid-virtualScrollerContent': {
937
944
  flexBasis: 'auto !important',
938
945
  flexGrow: '1 !important',
@@ -1259,9 +1266,8 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1259
1266
  setRows(getRecordsFromDataSource<T>(dataSource));
1260
1267
 
1261
1268
  // Validar valores da paginação
1262
- const currentPage = Number.isFinite(getCurrentPageFromDataSource(dataSource))
1263
- ? getCurrentPageFromDataSource(dataSource)
1264
- : 0;
1269
+ const rawPage = getCurrentPageFromDataSource(dataSource);
1270
+ const currentPage = Number.isFinite(rawPage) ? rawPage : 0;
1265
1271
 
1266
1272
  const pageSize = Number.isFinite(dataSource.getPageSize?.())
1267
1273
  ? Math.min(Math.max(1, dataSource.getPageSize()), MAX_PAGE_SIZE_MIT)
@@ -1281,7 +1287,7 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1281
1287
  setIsLoadingInternal(false);
1282
1288
 
1283
1289
  // Fechar todos os painéis quando os dados são atualizados
1284
- closeAllDetailPanels();
1290
+ handlerDepsRef.current.closeAllDetailPanels();
1285
1291
  }
1286
1292
  // Quando os dados são modificados
1287
1293
  else if (
@@ -1294,9 +1300,8 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1294
1300
  setRows(getRecordsFromDataSource<T>(dataSource));
1295
1301
 
1296
1302
  // Validar valores da paginação
1297
- const currentPage = Number.isFinite(getCurrentPageFromDataSource(dataSource))
1298
- ? getCurrentPageFromDataSource(dataSource)
1299
- : 0;
1303
+ const rawPage = getCurrentPageFromDataSource(dataSource);
1304
+ const currentPage = Number.isFinite(rawPage) ? rawPage : 0;
1300
1305
 
1301
1306
  const pageSize = Number.isFinite(dataSource.getPageSize?.())
1302
1307
  ? Math.min(Math.max(1, dataSource.getPageSize()), MAX_PAGE_SIZE_MIT)
@@ -1316,7 +1321,7 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1316
1321
  setIsLoadingInternal(false);
1317
1322
 
1318
1323
  // Fechar todos os painéis quando os dados são modificados
1319
- closeAllDetailPanels();
1324
+ handlerDepsRef.current.closeAllDetailPanels();
1320
1325
  }
1321
1326
  // Quando o registro atual do dataSource muda
1322
1327
  else if (event.type === DataSourceEventNames.afterScroll) {
@@ -1326,13 +1331,14 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1326
1331
  const currentRecord = dataSource.getCurrentRecord()
1327
1332
  if (currentRecord) {
1328
1333
  try {
1329
- const currentId = safeGetRowId(currentRecord, getRowId)
1334
+ const { rows: currentRows, getRowId: currentGetRowId, columns: currentColumns, apiRef: currentApiRef, onSelectedRowsChanged: currentOnSelectedRowsChanged } = handlerDepsRef.current
1335
+ const currentId = safeGetRowId(currentRecord, currentGetRowId)
1330
1336
 
1331
1337
  if (currentId !== undefined) {
1332
1338
  // Encontrar a primeira coluna disponível
1333
- const firstField = columns[0]?.field
1339
+ const firstField = currentColumns[0]?.field
1334
1340
 
1335
- if (firstField && apiRef.current) {
1341
+ if (firstField && currentApiRef.current) {
1336
1342
  // Iniciar o processo de sincronização
1337
1343
  syncInProgress.current = true
1338
1344
 
@@ -1342,27 +1348,28 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1342
1348
  setRowSelection(newSelection)
1343
1349
 
1344
1350
  // Encontrar o objeto de linha e atualizá-lo na lista de linhas selecionadas
1345
- const rowData = rows.find(
1346
- (row) => String(safeGetRowId(row, getRowId)) === String(currentId)
1351
+ const rowData = currentRows.find(
1352
+ (row) => String(safeGetRowId(row, currentGetRowId)) === String(currentId)
1347
1353
  )
1348
1354
 
1349
1355
  if (rowData) {
1350
1356
  setSelectedRows([rowData])
1351
1357
 
1352
- if (onSelectedRowsChanged) {
1353
- onSelectedRowsChanged([rowData])
1358
+ if (currentOnSelectedRowsChanged) {
1359
+ currentOnSelectedRowsChanged([rowData])
1354
1360
  }
1355
1361
  }
1356
1362
 
1357
1363
  // Opcional: também atualizar o foco para a célula
1358
1364
  setTimeout(() => {
1359
1365
  try {
1360
- apiRef.current.scrollToIndexes({
1361
- rowIndex: rows.findIndex(
1362
- (row) => String(safeGetRowId(row, getRowId)) === String(currentId)
1366
+ const { rows: latestRows, getRowId: latestGetRowId, apiRef: latestApiRef } = handlerDepsRef.current
1367
+ latestApiRef.current.scrollToIndexes({
1368
+ rowIndex: latestRows.findIndex(
1369
+ (row) => String(safeGetRowId(row, latestGetRowId)) === String(currentId)
1363
1370
  )
1364
1371
  })
1365
- apiRef.current.setCellFocus(currentId, firstField)
1372
+ latestApiRef.current.setCellFocus(currentId, firstField)
1366
1373
  } catch (error) {
1367
1374
  console.error('[DATASOURCE] Erro ao ajustar foco:', error)
1368
1375
  }
@@ -1391,7 +1398,7 @@ function ArchbaseDataGrid<T extends object = any, ID = any>(props: ArchbaseDataG
1391
1398
  return () => {
1392
1399
  dataSource.removeListener(handleDataSourceEvent)
1393
1400
  }
1394
- }, [dataSource, getRowId, columns, rows, apiRef, onSelectedRowsChanged, closeAllDetailPanels])
1401
+ }, [dataSource])
1395
1402
 
1396
1403
  // Criar os modais para exportação e impressão
1397
1404
  const modalColumns = useMemo(() => {
@@ -329,10 +329,6 @@ export function ArchbaseDatePickerEdit<T, ID>(props: ArchbaseDatePickerEditProps
329
329
  null
330
330
  );
331
331
 
332
- // 🔄 DEBUG: Log da versão detectada (apenas desenvolvimento)
333
- if (process.env.NODE_ENV === 'development' && dataSource) {
334
- }
335
-
336
332
  // Contexto de validação (opcional - pode não existir)
337
333
  const validationContext = useValidationErrors();
338
334
 
@@ -362,8 +358,8 @@ export function ArchbaseDatePickerEdit<T, ID>(props: ArchbaseDatePickerEditProps
362
358
  };
363
359
 
364
360
  const [_value, setValue, controlled] = useUncontrolled({
365
- value: processValue(value),
366
- defaultValue: processValue(defaultValue),
361
+ value: value !== undefined ? processValue(value) : undefined,
362
+ defaultValue: defaultValue !== undefined ? processValue(defaultValue) : undefined,
367
363
  finalValue: null,
368
364
  onChange,
369
365
  });
@@ -469,12 +465,23 @@ export function ArchbaseDatePickerEdit<T, ID>(props: ArchbaseDatePickerEditProps
469
465
 
470
466
  const setDataSourceFieldValue = useCallback((value: Date | undefined | null | string) => {
471
467
  if (dataSource && dataField) {
472
- // 🔄 MIGRAÇÃO V1/V2: Para compatibilidade V1, usar strings formatadas ao invés de ISO
473
468
  let processedValue: any = value;
474
469
 
475
- if (value && typeof value !== 'string') {
476
- // Se for Date, converter para string formatada (formato do input)
477
- processedValue = formatValue(value);
470
+ if (value && value !== '') {
471
+ if (typeof value === 'string') {
472
+ // Parsear string formatada (ex: "16/05/2026") e converter para ISO (yyyy-MM-dd)
473
+ try {
474
+ const parsedDate = dateFormats[dateFormat!].parse(value);
475
+ if (!isNaN(parsedDate.getTime())) {
476
+ processedValue = dayjs(parsedDate).format('YYYY-MM-DD');
477
+ }
478
+ } catch {
479
+ processedValue = value;
480
+ }
481
+ } else {
482
+ // Date object → ISO
483
+ processedValue = dayjs(value as Date).format('YYYY-MM-DD');
484
+ }
478
485
  }
479
486
 
480
487
  v1v2Compatibility.handleValueChange(processedValue);
@@ -645,7 +652,8 @@ export function ArchbaseDatePickerEdit<T, ID>(props: ArchbaseDatePickerEditProps
645
652
  };
646
653
 
647
654
  const _getDayProps = (dayString: DateStringValue) => {
648
- const day = new Date(dayString);
655
+ const [y, m, d] = (dayString as string).split('-').map(Number);
656
+ const day = new Date(y, m - 1, d);
649
657
  return {
650
658
  ...getDayProps?.(dayString),
651
659
  selected: dayjs(_value).isSame(day, 'day'),