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