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