df-ae-forms-package 1.0.87 → 1.0.89

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