df-ae-forms-package 1.0.71 → 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 +160 -58
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +160 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
//
|
|
6249
|
-
if (component.
|
|
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,15 +6263,32 @@ 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)) {
|
|
6272
|
-
component.cells.forEach((
|
|
6273
|
-
|
|
6276
|
+
component.cells.forEach((rowOrCell) => {
|
|
6277
|
+
// Handle 2D array (standard)
|
|
6278
|
+
if (Array.isArray(rowOrCell)) {
|
|
6279
|
+
rowOrCell.forEach((cell) => {
|
|
6280
|
+
if (cell.components && Array.isArray(cell.components)) {
|
|
6281
|
+
evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
|
|
6282
|
+
}
|
|
6283
|
+
});
|
|
6284
|
+
}
|
|
6285
|
+
// Handle 1D array (flat)
|
|
6286
|
+
else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
|
|
6287
|
+
const cell = rowOrCell;
|
|
6274
6288
|
if (cell.components && Array.isArray(cell.components)) {
|
|
6275
6289
|
evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
|
|
6276
6290
|
}
|
|
6277
|
-
}
|
|
6291
|
+
}
|
|
6278
6292
|
});
|
|
6279
6293
|
}
|
|
6280
6294
|
// Handle nested components in datagrid entries
|
|
@@ -6309,19 +6323,25 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6309
6323
|
}, [formComponents, formValues]);
|
|
6310
6324
|
// Check if a component should be visible based on conditional logic
|
|
6311
6325
|
const shouldShowComponent = useCallback((componentId) => {
|
|
6312
|
-
//
|
|
6313
|
-
|
|
6326
|
+
// Check the visibility map first for the exact ID
|
|
6327
|
+
if (componentVisibility.hasOwnProperty(componentId)) {
|
|
6328
|
+
return componentVisibility[componentId] === true;
|
|
6329
|
+
}
|
|
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)
|
|
6314
6332
|
const component = conditionalLogicService.findComponent(formComponents, componentId);
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
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
|
+
}
|
|
6318
6342
|
}
|
|
6319
|
-
//
|
|
6320
|
-
|
|
6321
|
-
const isVisible = (componentVisibility[componentId] !== false) &&
|
|
6322
|
-
(!component?._id || componentVisibility[component._id] !== false) &&
|
|
6323
|
-
(!component?.id || componentVisibility[component.id] !== false);
|
|
6324
|
-
return isVisible;
|
|
6343
|
+
// If not found in visibility map by any identifier, component should be visible by default
|
|
6344
|
+
return true;
|
|
6325
6345
|
}, [componentVisibility, formComponents]);
|
|
6326
6346
|
// Handle form value changes and re-evaluate conditional logic
|
|
6327
6347
|
const onFormValueChange = useCallback((change) => {
|
|
@@ -6398,13 +6418,28 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6398
6418
|
if (component.name === 'table' && component.cells) {
|
|
6399
6419
|
return {
|
|
6400
6420
|
...component,
|
|
6401
|
-
cells: component.cells.map((
|
|
6402
|
-
|
|
6403
|
-
if (
|
|
6404
|
-
|
|
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;
|
|
6405
6440
|
}
|
|
6406
|
-
return
|
|
6407
|
-
})
|
|
6441
|
+
return rowOrCell;
|
|
6442
|
+
})
|
|
6408
6443
|
};
|
|
6409
6444
|
}
|
|
6410
6445
|
if (component.name === 'datagrid' && component.entries) {
|
|
@@ -7631,8 +7666,18 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
7631
7666
|
};
|
|
7632
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 }) => {
|
|
7633
7668
|
const [isCollapsed, setIsCollapsed] = useState(false); // Always start expanded to show drop zones
|
|
7634
|
-
// Check if table has any components in any cells
|
|
7635
|
-
const hasAnyComponents = properties.cells?.some(
|
|
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;
|
|
7636
7681
|
// Initialize and update table cells when rows/columns change
|
|
7637
7682
|
// CRITICAL: Skip cell initialization updates to prevent flickering when user types
|
|
7638
7683
|
useEffect(() => {
|
|
@@ -7654,17 +7699,34 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7654
7699
|
};
|
|
7655
7700
|
const handleComponentDelete = useCallback((component, event) => {
|
|
7656
7701
|
event.stopPropagation();
|
|
7657
|
-
// Find and remove the component from the table cell
|
|
7658
|
-
const updatedCells = properties.cells.map(
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
return {
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
|
|
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
|
+
});
|
|
7665
7716
|
}
|
|
7666
|
-
|
|
7667
|
-
|
|
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
|
+
});
|
|
7668
7730
|
// Update the table with the modified cells
|
|
7669
7731
|
if (onValueChange) {
|
|
7670
7732
|
onValueChange({
|
|
@@ -7680,26 +7742,56 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7680
7742
|
const cellsWithIds = useMemo(() => {
|
|
7681
7743
|
if (!properties.cells)
|
|
7682
7744
|
return [];
|
|
7683
|
-
return properties.cells.map((
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
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
|
+
});
|
|
7703
7795
|
}, [properties.cells, id]); // Only recalculate if cells or table ID changes
|
|
7704
7796
|
// CRITICAL FIX: Update the parent component with the cells that have proper IDs
|
|
7705
7797
|
// Skip this in package to prevent flickering - cells are managed by parent
|
|
@@ -7828,7 +7920,17 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
7828
7920
|
fontSize: '14px',
|
|
7829
7921
|
textAlign: 'center'
|
|
7830
7922
|
}, children: columnName }, `header-${colIndex}`));
|
|
7831
|
-
}) }) })), jsx("tbody", { children: cellsWithIds.map((
|
|
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
|
+
}) })] })] }))] }));
|
|
7832
7934
|
};
|
|
7833
7935
|
|
|
7834
7936
|
var dfFormTable = /*#__PURE__*/Object.freeze({
|