df-ae-forms-package 1.0.86 → 1.0.88

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/dist/index.esm.js CHANGED
@@ -4476,7 +4476,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4476
4476
  whiteSpace: 'nowrap',
4477
4477
  overflow: 'hidden',
4478
4478
  textOverflow: 'ellipsis'
4479
- }, children: component.basic?.label || `Column ${index + 1}` }, `header-${component.id}`))) })), dataEntries.length > 0 ? (dataEntries.map((entry, entryIndex) => (jsxs("div", { className: "table-row", style: {
4479
+ }, children: component.basic?.label || `Column ${index + 1}` }, `header-${component.id || index}`))) })), dataEntries.length > 0 ? (dataEntries.map((entry, entryIndex) => (jsxs("div", { className: "table-row", style: {
4480
4480
  // Use flex column for column view, grid for row view
4481
4481
  display: columnView ? 'flex' : 'grid',
4482
4482
  flexDirection: columnView ? 'column' : 'row',
@@ -5420,11 +5420,14 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5420
5420
  // Recurse
5421
5421
  if (comp.children)
5422
5422
  extractNotesAndAttachments(comp.children);
5423
- if (comp.cells)
5424
- comp.cells.forEach((row) => row.forEach((cell) => {
5425
- if (cell.components)
5426
- extractNotesAndAttachments(cell.components);
5427
- }));
5423
+ if (comp.cells && Array.isArray(comp.cells))
5424
+ comp.cells.forEach((row) => {
5425
+ if (Array.isArray(row))
5426
+ row.forEach((cell) => {
5427
+ if (cell && cell.components)
5428
+ extractNotesAndAttachments(cell.components);
5429
+ });
5430
+ });
5428
5431
  if (comp.entries)
5429
5432
  comp.entries.forEach((entry) => {
5430
5433
  if (entry.components)
@@ -5610,13 +5613,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5610
5613
  if (component.name === 'table' && component.cells) {
5611
5614
  return {
5612
5615
  ...component,
5613
- cells: component.cells.map((row) => row.map((cell) => {
5616
+ cells: component.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
5614
5617
  const updatedCell = { ...cell };
5615
5618
  if (updatedCell.components) {
5616
5619
  updatedCell.components = updateComponentValue(updatedCell.components);
5617
5620
  }
5618
5621
  return updatedCell;
5619
- }))
5622
+ }) : row)
5620
5623
  };
5621
5624
  }
5622
5625
  if (component.name === 'datagrid' && component.entries) {
@@ -6220,13 +6223,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6220
6223
  updatedComponent.children = updateComponentValues(updatedComponent.children);
6221
6224
  }
6222
6225
  if (updatedComponent.name === 'table' && updatedComponent.cells) {
6223
- updatedComponent.cells = updatedComponent.cells.map((row) => row.map((cell) => {
6226
+ updatedComponent.cells = updatedComponent.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
6224
6227
  const updatedCell = { ...cell };
6225
6228
  if (updatedCell.components) {
6226
6229
  updatedCell.components = updateComponentValues(updatedCell.components);
6227
6230
  }
6228
6231
  return updatedCell;
6229
- }));
6232
+ }) : row);
6230
6233
  }
6231
6234
  if (updatedComponent.name === 'datagrid' && updatedComponent.entries) {
6232
6235
  updatedComponent.entries = updatedComponent.entries.map((entry) => {
@@ -6407,7 +6410,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6407
6410
  // Handle notes change for table cell components
6408
6411
  const updatedComponents = formComponents.map(comp => {
6409
6412
  if (comp.id === component.id && comp.cells) {
6410
- const updatedCells = comp.cells.map((row) => row.map((cell) => {
6413
+ const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
6411
6414
  if (cell.components) {
6412
6415
  const updatedCellComponents = cell.components.map((cellComp) => {
6413
6416
  if (cellComp.id === componentId) {
@@ -6424,7 +6427,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6424
6427
  return { ...cell, components: updatedCellComponents };
6425
6428
  }
6426
6429
  return cell;
6427
- }));
6430
+ }) : row);
6428
6431
  return { ...comp, cells: updatedCells };
6429
6432
  }
6430
6433
  return comp;
@@ -6434,7 +6437,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6434
6437
  // Handle attachment change for table cell components
6435
6438
  const updatedComponents = formComponents.map(comp => {
6436
6439
  if (comp.id === component.id && comp.cells) {
6437
- const updatedCells = comp.cells.map((row) => row.map((cell) => {
6440
+ const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
6438
6441
  if (cell.components) {
6439
6442
  const updatedCellComponents = cell.components.map((cellComp) => {
6440
6443
  if (cellComp.id === componentId) {
@@ -6451,7 +6454,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6451
6454
  return { ...cell, components: updatedCellComponents };
6452
6455
  }
6453
6456
  return cell;
6454
- }));
6457
+ }) : row);
6455
6458
  return { ...comp, cells: updatedCells };
6456
6459
  }
6457
6460
  return comp;
@@ -6846,7 +6849,7 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
6846
6849
  const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationErrors = {}, touchedFields = {}, formSubmitted = false, onValueChange, onSelect, isSelected = false, className = '', onTableSelect, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
6847
6850
  const [isCollapsed, setIsCollapsed] = useState(false); // Always start expanded to show drop zones
6848
6851
  // Check if table has any components in any cells
6849
- const hasAnyComponents = properties.cells?.some(row => row.some(cell => cell.components && cell.components.length > 0)) || false;
6852
+ const hasAnyComponents = properties.cells?.some((row) => Array.isArray(row) && row.some((cell) => cell.components && cell.components.length > 0)) || false;
6850
6853
  // Initialize and update table cells when rows/columns change
6851
6854
  // Only trigger when cells are truly missing or structure doesn't match rows/columns
6852
6855
  useEffect(() => {
@@ -6855,10 +6858,9 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6855
6858
  const currentColumns = Number(properties.table?.columns || properties.basic?.columns || 3);
6856
6859
  const currentCells = properties.cells || [];
6857
6860
  // Check if we need to update the table structure
6858
- // Only update if cells are empty or row/column count doesn't match
6859
6861
  const needsUpdate = currentCells.length === 0 ||
6860
6862
  currentCells.length !== currentRows ||
6861
- (currentCells.length > 0 && currentCells[0].length !== currentColumns);
6863
+ (currentCells.length > 0 && Array.isArray(currentCells[0]) && currentCells[0].length !== currentColumns);
6862
6864
  if (needsUpdate) {
6863
6865
  const newCells = [];
6864
6866
  for (let row = 0; row < currentRows; row++) {
@@ -6867,7 +6869,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6867
6869
  const cellId = `cell-${row}-${col}`;
6868
6870
  // Try to preserve existing components if the cell exists
6869
6871
  let existingComponents = [];
6870
- if (currentCells[row] && currentCells[row][col]) {
6872
+ if (Array.isArray(currentCells[row]) && currentCells[row][col]) {
6871
6873
  existingComponents = (currentCells[row][col].components || []).map(ensureComponentHasId);
6872
6874
  }
6873
6875
  rowCells.push({
@@ -6885,7 +6887,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6885
6887
  value: { ...properties, cells: newCells }
6886
6888
  });
6887
6889
  }
6888
- }, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns, properties.cells?.length, id, onValueChange]); // Watch rows/columns changes and cells length for initial init
6890
+ }, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns, properties.cells?.length, id, onValueChange]);
6889
6891
  const handleTableClick = useCallback((event) => {
6890
6892
  event.stopPropagation();
6891
6893
  onSelect?.();
@@ -6902,16 +6904,16 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6902
6904
  const handleComponentDelete = useCallback((component, event) => {
6903
6905
  event.stopPropagation();
6904
6906
  // Find and remove the component from the table cell
6905
- const updatedCells = properties.cells.map(row => row.map(cell => {
6906
- if (cell.components && cell.components.some(comp => comp.id === component.id)) {
6907
- const filteredComponents = cell.components.filter(comp => comp.id !== component.id);
6907
+ const updatedCells = properties.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
6908
+ if (cell.components && cell.components.some((comp) => comp.id === component.id)) {
6909
+ const filteredComponents = cell.components.filter((comp) => comp.id !== component.id);
6908
6910
  return {
6909
6911
  ...cell,
6910
6912
  components: filteredComponents
6911
6913
  };
6912
6914
  }
6913
6915
  return cell;
6914
- }));
6916
+ }) : row);
6915
6917
  // Update the table with the modified cells
6916
6918
  if (onValueChange) {
6917
6919
  onValueChange({
@@ -6927,7 +6929,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6927
6929
  const cellsWithIds = useMemo(() => {
6928
6930
  if (!properties.cells)
6929
6931
  return [];
6930
- return properties.cells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
6932
+ return properties.cells.map((row, rowIndex) => Array.isArray(row) ? row.map((cell, cellIndex) => ({
6931
6933
  ...cell,
6932
6934
  components: (cell.components && Array.isArray(cell.components))
6933
6935
  ? cell.components.map((comp, compIndex) => {
@@ -6946,7 +6948,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6946
6948
  };
6947
6949
  })
6948
6950
  : []
6949
- })));
6951
+ })) : []);
6950
6952
  }, [properties.cells, id]); // Only recalculate if cells or table ID changes
6951
6953
  // CRITICAL FIX: Update the parent component with the cells that have proper IDs
6952
6954
  // Skip this in package to prevent flickering - cells are managed by parent
@@ -6957,10 +6959,12 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6957
6959
  // Always defined to avoid conditional hook calls (React hooks rule)
6958
6960
  const fallbackRenderComponent = useCallback((field) => {
6959
6961
  // CRITICAL: Only ensure ID if it's missing - don't regenerate existing IDs
6962
+ // This prevents component remounting and losing input state
6960
6963
  const componentWithId = field.id ? field : ensureComponentHasId(field);
6961
6964
  // Get form value - directly access formData from closure (matches main app)
6962
6965
  const formValue = formData[componentWithId.id] || ('defaultValue' in componentWithId.basic ? componentWithId.basic.defaultValue || '' : '');
6963
6966
  // CRITICAL: Ensure formValue is always a string for number inputs
6967
+ // This prevents validation errors when formValue is a number type
6964
6968
  let normalizedFormValue = formValue;
6965
6969
  if (componentWithId.name === 'number-input' && typeof formValue === 'number') {
6966
6970
  normalizedFormValue = String(formValue);
@@ -6992,18 +6996,21 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6992
6996
  case 'textarea':
6993
6997
  return jsx(DfFormTextarea, { ...commonProps, properties: componentWithId, readonly: false, disabled: false });
6994
6998
  case 'select':
6999
+ // Map basic.options to top-level options for select component
6995
7000
  const selectProps = {
6996
7001
  ...componentWithId,
6997
7002
  options: componentWithId.basic?.options || []
6998
7003
  };
6999
7004
  return jsx(DfFormSelect, { ...commonProps, properties: selectProps, disabled: false });
7000
7005
  case 'checkbox':
7006
+ // Map basic.options to top-level options for checkbox component
7001
7007
  const checkboxProps = {
7002
7008
  ...componentWithId,
7003
7009
  options: componentWithId.basic?.options || []
7004
7010
  };
7005
7011
  return jsx(DfFormCheckbox, { ...commonProps, properties: checkboxProps, formValue: [], disabled: false });
7006
7012
  case 'radio':
7013
+ // Map basic.options to top-level options for radio component
7007
7014
  const radioProps = {
7008
7015
  ...componentWithId,
7009
7016
  options: componentWithId.basic?.options || []
@@ -7025,6 +7032,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7025
7032
  case 'datagrid':
7026
7033
  return (jsx(DfFormDataGrid, { ...commonProps, properties: componentWithId, formData: formData, mode: mode, onNotesChange: () => { }, onAttachmentChange: () => { } }));
7027
7034
  case 'segment':
7035
+ // Map basic.options for segment
7028
7036
  const segmentProps = {
7029
7037
  ...componentWithId,
7030
7038
  options: componentWithId.basic?.options || []