df-ae-forms-package 1.0.87 → 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
@@ -6851,7 +6851,7 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
6851
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 }) => {
6852
6852
  const [isCollapsed, setIsCollapsed] = React.useState(false); // Always start expanded to show drop zones
6853
6853
  // Check if table has any components in any cells
6854
- 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;
6855
6855
  // Initialize and update table cells when rows/columns change
6856
6856
  // Only trigger when cells are truly missing or structure doesn't match rows/columns
6857
6857
  React.useEffect(() => {
@@ -6860,10 +6860,9 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6860
6860
  const currentColumns = Number(properties.table?.columns || properties.basic?.columns || 3);
6861
6861
  const currentCells = properties.cells || [];
6862
6862
  // Check if we need to update the table structure
6863
- // Only update if cells are empty or row/column count doesn't match
6864
6863
  const needsUpdate = currentCells.length === 0 ||
6865
6864
  currentCells.length !== currentRows ||
6866
- (currentCells.length > 0 && currentCells[0].length !== currentColumns);
6865
+ (currentCells.length > 0 && Array.isArray(currentCells[0]) && currentCells[0].length !== currentColumns);
6867
6866
  if (needsUpdate) {
6868
6867
  const newCells = [];
6869
6868
  for (let row = 0; row < currentRows; row++) {
@@ -6872,7 +6871,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6872
6871
  const cellId = `cell-${row}-${col}`;
6873
6872
  // Try to preserve existing components if the cell exists
6874
6873
  let existingComponents = [];
6875
- if (currentCells[row] && currentCells[row][col]) {
6874
+ if (Array.isArray(currentCells[row]) && currentCells[row][col]) {
6876
6875
  existingComponents = (currentCells[row][col].components || []).map(ensureComponentHasId);
6877
6876
  }
6878
6877
  rowCells.push({
@@ -6890,7 +6889,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6890
6889
  value: { ...properties, cells: newCells }
6891
6890
  });
6892
6891
  }
6893
- }, [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]);
6894
6893
  const handleTableClick = React.useCallback((event) => {
6895
6894
  event.stopPropagation();
6896
6895
  onSelect?.();
@@ -6907,16 +6906,16 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6907
6906
  const handleComponentDelete = React.useCallback((component, event) => {
6908
6907
  event.stopPropagation();
6909
6908
  // Find and remove the component from the table cell
6910
- const updatedCells = properties.cells.map(row => row.map(cell => {
6911
- if (cell.components && cell.components.some(comp => comp.id === component.id)) {
6912
- 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);
6913
6912
  return {
6914
6913
  ...cell,
6915
6914
  components: filteredComponents
6916
6915
  };
6917
6916
  }
6918
6917
  return cell;
6919
- }));
6918
+ }) : row);
6920
6919
  // Update the table with the modified cells
6921
6920
  if (onValueChange) {
6922
6921
  onValueChange({
@@ -6932,7 +6931,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6932
6931
  const cellsWithIds = React.useMemo(() => {
6933
6932
  if (!properties.cells)
6934
6933
  return [];
6935
- return properties.cells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
6934
+ return properties.cells.map((row, rowIndex) => Array.isArray(row) ? row.map((cell, cellIndex) => ({
6936
6935
  ...cell,
6937
6936
  components: (cell.components && Array.isArray(cell.components))
6938
6937
  ? cell.components.map((comp, compIndex) => {
@@ -6951,7 +6950,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6951
6950
  };
6952
6951
  })
6953
6952
  : []
6954
- })));
6953
+ })) : []);
6955
6954
  }, [properties.cells, id]); // Only recalculate if cells or table ID changes
6956
6955
  // CRITICAL FIX: Update the parent component with the cells that have proper IDs
6957
6956
  // Skip this in package to prevent flickering - cells are managed by parent
@@ -6962,10 +6961,12 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6962
6961
  // Always defined to avoid conditional hook calls (React hooks rule)
6963
6962
  const fallbackRenderComponent = React.useCallback((field) => {
6964
6963
  // CRITICAL: Only ensure ID if it's missing - don't regenerate existing IDs
6964
+ // This prevents component remounting and losing input state
6965
6965
  const componentWithId = field.id ? field : ensureComponentHasId(field);
6966
6966
  // Get form value - directly access formData from closure (matches main app)
6967
6967
  const formValue = formData[componentWithId.id] || ('defaultValue' in componentWithId.basic ? componentWithId.basic.defaultValue || '' : '');
6968
6968
  // CRITICAL: Ensure formValue is always a string for number inputs
6969
+ // This prevents validation errors when formValue is a number type
6969
6970
  let normalizedFormValue = formValue;
6970
6971
  if (componentWithId.name === 'number-input' && typeof formValue === 'number') {
6971
6972
  normalizedFormValue = String(formValue);
@@ -6997,18 +6998,21 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
6997
6998
  case 'textarea':
6998
6999
  return jsxRuntime.jsx(DfFormTextarea, { ...commonProps, properties: componentWithId, readonly: false, disabled: false });
6999
7000
  case 'select':
7001
+ // Map basic.options to top-level options for select component
7000
7002
  const selectProps = {
7001
7003
  ...componentWithId,
7002
7004
  options: componentWithId.basic?.options || []
7003
7005
  };
7004
7006
  return jsxRuntime.jsx(DfFormSelect, { ...commonProps, properties: selectProps, disabled: false });
7005
7007
  case 'checkbox':
7008
+ // Map basic.options to top-level options for checkbox component
7006
7009
  const checkboxProps = {
7007
7010
  ...componentWithId,
7008
7011
  options: componentWithId.basic?.options || []
7009
7012
  };
7010
7013
  return jsxRuntime.jsx(DfFormCheckbox, { ...commonProps, properties: checkboxProps, formValue: [], disabled: false });
7011
7014
  case 'radio':
7015
+ // Map basic.options to top-level options for radio component
7012
7016
  const radioProps = {
7013
7017
  ...componentWithId,
7014
7018
  options: componentWithId.basic?.options || []
@@ -7030,6 +7034,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7030
7034
  case 'datagrid':
7031
7035
  return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: componentWithId, formData: formData, mode: mode, onNotesChange: () => { }, onAttachmentChange: () => { } }));
7032
7036
  case 'segment':
7037
+ // Map basic.options for segment
7033
7038
  const segmentProps = {
7034
7039
  ...componentWithId,
7035
7040
  options: componentWithId.basic?.options || []