df-ae-forms-package 1.0.72 → 1.0.73

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
@@ -6245,11 +6245,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6245
6245
  const evaluateComponentConditionalLogic = (components, visibility, currentFormValues, fullSchema) => {
6246
6246
  components.forEach(component => {
6247
6247
  if (component.id) {
6248
- // Skip conditional logic for table and datagrid components - they are always visible
6249
- if (component.name === 'table' || component.name === 'datagrid') {
6250
- visibility[component.id] = true;
6251
- }
6252
- else if (component.conditional) {
6248
+ // Handle conditional logic for all components including table and datagrid
6249
+ if (component.conditional) {
6253
6250
  // Use the proper conditional logic service
6254
6251
  const result = conditionalLogicService.evaluateConditionalLogic(component.conditional, fullSchema, currentFormValues);
6255
6252
  visibility[component.id] = result.shouldShow;
@@ -6266,6 +6263,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6266
6263
  if (component.basic?.label)
6267
6264
  visibility[component.basic.label] = true;
6268
6265
  }
6266
+ // Process nested components in table and datagrid regardless of parent visibility
6267
+ if (component.name === 'table' || component.name === 'datagrid') {
6268
+ // Still add the parent to visibility map (as visible if no conditional logic)
6269
+ if (!component.conditional) {
6270
+ visibility[component.id] = true;
6271
+ }
6272
+ }
6269
6273
  }
6270
6274
  // Handle nested components in table cells
6271
6275
  if (component.cells && Array.isArray(component.cells)) {
@@ -6319,11 +6323,24 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6319
6323
  }, [formComponents, formValues]);
6320
6324
  // Check if a component should be visible based on conditional logic
6321
6325
  const shouldShowComponent = useCallback((componentId) => {
6322
- // Check the visibility map first
6326
+ // Check the visibility map first for the exact ID
6323
6327
  if (componentVisibility.hasOwnProperty(componentId)) {
6324
6328
  return componentVisibility[componentId] === true;
6325
6329
  }
6326
- // If not in visibility map, component should be visible by default
6330
+ // If not found by exact ID, try to find the component in formComponents
6331
+ // and check if it exists in visibility map by other identifiers (_id, label)
6332
+ const component = conditionalLogicService.findComponent(formComponents, componentId);
6333
+ if (component) {
6334
+ // Check visibility by _id if available
6335
+ if (component._id && componentVisibility.hasOwnProperty(component._id)) {
6336
+ return componentVisibility[component._id] === true;
6337
+ }
6338
+ // Check visibility by label if available
6339
+ if (component.basic?.label && componentVisibility.hasOwnProperty(component.basic.label)) {
6340
+ return componentVisibility[component.basic.label] === true;
6341
+ }
6342
+ }
6343
+ // If not found in visibility map by any identifier, component should be visible by default
6327
6344
  return true;
6328
6345
  }, [componentVisibility, formComponents]);
6329
6346
  // Handle form value changes and re-evaluate conditional logic
@@ -6401,13 +6418,28 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6401
6418
  if (component.name === 'table' && component.cells) {
6402
6419
  return {
6403
6420
  ...component,
6404
- cells: component.cells.map((row) => row.map((cell) => {
6405
- const updatedCell = { ...cell };
6406
- if (updatedCell.components) {
6407
- updatedCell.components = updateComponentValue(updatedCell.components);
6421
+ cells: component.cells.map((rowOrCell) => {
6422
+ // Handle 2D array (standard)
6423
+ if (Array.isArray(rowOrCell)) {
6424
+ return rowOrCell.map((cell) => {
6425
+ const updatedCell = { ...cell };
6426
+ if (updatedCell.components) {
6427
+ updatedCell.components = updateComponentValue(updatedCell.components);
6428
+ }
6429
+ return updatedCell;
6430
+ });
6431
+ }
6432
+ // Handle 1D array (flat)
6433
+ else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
6434
+ const cell = rowOrCell;
6435
+ const updatedCell = { ...cell };
6436
+ if (updatedCell.components) {
6437
+ updatedCell.components = updateComponentValue(updatedCell.components);
6438
+ }
6439
+ return updatedCell;
6408
6440
  }
6409
- return updatedCell;
6410
- }))
6441
+ return rowOrCell;
6442
+ })
6411
6443
  };
6412
6444
  }
6413
6445
  if (component.name === 'datagrid' && component.entries) {
@@ -7634,8 +7666,18 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
7634
7666
  };
7635
7667
  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 }) => {
7636
7668
  const [isCollapsed, setIsCollapsed] = useState(false); // Always start expanded to show drop zones
7637
- // Check if table has any components in any cells
7638
- const hasAnyComponents = properties.cells?.some(row => row.some(cell => cell.components && cell.components.length > 0)) || false;
7669
+ // Check if table has any components in any cells - handle both 2D and 1D structures
7670
+ const hasAnyComponents = properties.cells?.some((rowOrCell) => {
7671
+ // Handle 2D array structure (each row is an array of cells)
7672
+ if (Array.isArray(rowOrCell)) {
7673
+ return rowOrCell.some((cell) => cell.components && cell.components.length > 0);
7674
+ }
7675
+ // Handle 1D array structure (each element is a cell)
7676
+ else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
7677
+ return rowOrCell.components && rowOrCell.components.length > 0;
7678
+ }
7679
+ return false;
7680
+ }) || false;
7639
7681
  // Initialize and update table cells when rows/columns change
7640
7682
  // CRITICAL: Skip cell initialization updates to prevent flickering when user types
7641
7683
  useEffect(() => {
@@ -7657,17 +7699,34 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7657
7699
  };
7658
7700
  const handleComponentDelete = useCallback((component, event) => {
7659
7701
  event.stopPropagation();
7660
- // Find and remove the component from the table cell
7661
- const updatedCells = properties.cells.map(row => row.map(cell => {
7662
- if (cell.components && cell.components.some(comp => comp.id === component.id)) {
7663
- const filteredComponents = cell.components.filter(comp => comp.id !== component.id);
7664
- return {
7665
- ...cell,
7666
- components: filteredComponents
7667
- };
7702
+ // Find and remove the component from the table cell - handle both 2D and 1D structures
7703
+ const updatedCells = properties.cells.map((rowOrCell) => {
7704
+ // Handle 2D array structure (each row is an array of cells)
7705
+ if (Array.isArray(rowOrCell)) {
7706
+ return rowOrCell.map((cell) => {
7707
+ if (cell.components && cell.components.some((comp) => comp.id === component.id)) {
7708
+ const filteredComponents = cell.components.filter((comp) => comp.id !== component.id);
7709
+ return {
7710
+ ...cell,
7711
+ components: filteredComponents
7712
+ };
7713
+ }
7714
+ return cell;
7715
+ });
7668
7716
  }
7669
- return cell;
7670
- }));
7717
+ // Handle 1D array structure (each element is a cell)
7718
+ else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
7719
+ if (rowOrCell.components && rowOrCell.components.some((comp) => comp.id === component.id)) {
7720
+ const filteredComponents = rowOrCell.components.filter((comp) => comp.id !== component.id);
7721
+ return {
7722
+ ...rowOrCell,
7723
+ components: filteredComponents
7724
+ };
7725
+ }
7726
+ return rowOrCell;
7727
+ }
7728
+ return rowOrCell;
7729
+ });
7671
7730
  // Update the table with the modified cells
7672
7731
  if (onValueChange) {
7673
7732
  onValueChange({
@@ -7683,26 +7742,56 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7683
7742
  const cellsWithIds = useMemo(() => {
7684
7743
  if (!properties.cells)
7685
7744
  return [];
7686
- return properties.cells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
7687
- ...cell,
7688
- components: (cell.components && Array.isArray(cell.components))
7689
- ? cell.components.map((comp, compIndex) => {
7690
- // CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
7691
- // This prevents component remounting and losing input state
7692
- if (comp.id && typeof comp.id === 'string' && comp.id.trim() !== '') {
7693
- // ID already exists - keep it as is
7694
- return comp;
7695
- }
7696
- // Generate unique ID that includes table ID, row, cell, and component index
7697
- // This ensures no conflicts with other components
7698
- const uniqueId = `${comp.name || 'component'}-table-${id}-row-${rowIndex}-cell-${cellIndex}-comp-${compIndex}`;
7699
- return {
7700
- ...comp,
7701
- id: uniqueId
7702
- };
7703
- })
7704
- : []
7705
- })));
7745
+ return properties.cells.map((rowOrCell, rowIndex) => {
7746
+ // Handle 2D array structure (each row is an array of cells)
7747
+ if (Array.isArray(rowOrCell)) {
7748
+ return rowOrCell.map((cell, cellIndex) => ({
7749
+ ...cell,
7750
+ components: (cell.components && Array.isArray(cell.components))
7751
+ ? cell.components.map((comp, compIndex) => {
7752
+ // CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
7753
+ // This prevents component remounting and losing input state
7754
+ if (comp.id && typeof comp.id === 'string' && comp.id.trim() !== '') {
7755
+ // ID already exists - keep it as is
7756
+ return comp;
7757
+ }
7758
+ // Generate unique ID that includes table ID, row, cell, and component index
7759
+ // This ensures no conflicts with other components
7760
+ const uniqueId = `${comp.name || 'component'}-table-${id}-row-${rowIndex}-cell-${cellIndex}-comp-${compIndex}`;
7761
+ return {
7762
+ ...comp,
7763
+ id: uniqueId
7764
+ };
7765
+ })
7766
+ : []
7767
+ }));
7768
+ }
7769
+ // Handle 1D array structure (each element is a cell)
7770
+ else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
7771
+ const cell = rowOrCell;
7772
+ return {
7773
+ ...cell,
7774
+ components: (cell.components && Array.isArray(cell.components))
7775
+ ? cell.components.map((comp, compIndex) => {
7776
+ // CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
7777
+ // This prevents component remounting and losing input state
7778
+ if (comp.id && typeof comp.id === 'string' && comp.id.trim() !== '') {
7779
+ // ID already exists - keep it as is
7780
+ return comp;
7781
+ }
7782
+ // Generate unique ID that includes table ID, row, cell, and component index
7783
+ // This ensures no conflicts with other components
7784
+ const uniqueId = `${comp.name || 'component'}-table-${id}-row-${rowIndex}-cell-0-comp-${compIndex}`;
7785
+ return {
7786
+ ...comp,
7787
+ id: uniqueId
7788
+ };
7789
+ })
7790
+ : []
7791
+ };
7792
+ }
7793
+ return [];
7794
+ });
7706
7795
  }, [properties.cells, id]); // Only recalculate if cells or table ID changes
7707
7796
  // CRITICAL FIX: Update the parent component with the cells that have proper IDs
7708
7797
  // Skip this in package to prevent flickering - cells are managed by parent
@@ -7831,7 +7920,17 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7831
7920
  fontSize: '14px',
7832
7921
  textAlign: 'center'
7833
7922
  }, children: columnName }, `header-${colIndex}`));
7834
- }) }) })), jsx("tbody", { children: cellsWithIds.map((row, rowIndex) => (jsx("tr", { className: "table-row", children: row.map((cell) => (jsx(TableCellComponent, { cell: cell, mode: mode, onComponentSelect: onComponentSelect || (() => { }), onComponentDelete: handleComponentDelete, onComponentEdit: onComponentEdit, selectedComponent: selectedComponent || null, renderFormComponent: renderComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, tableId: id, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, cell.id))) }, rowIndex))) })] })] }))] }));
7923
+ }) }) })), jsx("tbody", { children: cellsWithIds.map((rowOrCell, rowIndex) => {
7924
+ // Handle 2D array structure (each row is an array of cells)
7925
+ if (Array.isArray(rowOrCell)) {
7926
+ return (jsx("tr", { className: "table-row", children: rowOrCell.map((cell) => (jsx(TableCellComponent, { cell: cell, mode: mode, onComponentSelect: onComponentSelect || (() => { }), onComponentDelete: handleComponentDelete, onComponentEdit: onComponentEdit, selectedComponent: selectedComponent || null, renderFormComponent: renderComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, tableId: id, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, cell.id))) }, rowIndex));
7927
+ }
7928
+ // Handle 1D array structure (each element is a cell)
7929
+ else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
7930
+ return (jsx("tr", { className: "table-row", children: jsx(TableCellComponent, { cell: rowOrCell, mode: mode, onComponentSelect: onComponentSelect || (() => { }), onComponentDelete: handleComponentDelete, onComponentEdit: onComponentEdit, selectedComponent: selectedComponent || null, renderFormComponent: renderComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, tableId: id, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, rowOrCell.id) }, rowIndex));
7931
+ }
7932
+ return null;
7933
+ }) })] })] }))] }));
7835
7934
  };
7836
7935
 
7837
7936
  var dfFormTable = /*#__PURE__*/Object.freeze({