df-ae-forms-package 1.0.90 → 1.0.91
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 +67 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +67 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -5301,6 +5301,18 @@ const DfFormSection = ({ id, properties, mode = 'edit', formData = {}, onValueCh
|
|
|
5301
5301
|
|
|
5302
5302
|
// Dynamic imports to avoid circular dependencies
|
|
5303
5303
|
const DfFormTable$1 = React.lazy(() => Promise.resolve().then(function () { return dfFormTable; }));
|
|
5304
|
+
// Normalize a table row from API format (object with numeric keys) into a proper array.
|
|
5305
|
+
// The API may return cells as [{"0": {cell}, "1": {cell}}, ...] instead of [[cell, cell], ...].
|
|
5306
|
+
const normalizeTableRow = (row) => {
|
|
5307
|
+
if (Array.isArray(row))
|
|
5308
|
+
return row;
|
|
5309
|
+
if (row && typeof row === 'object') {
|
|
5310
|
+
const keys = Object.keys(row).filter(k => !isNaN(Number(k))).sort((a, b) => Number(a) - Number(b));
|
|
5311
|
+
if (keys.length > 0)
|
|
5312
|
+
return keys.map(k => row[k]);
|
|
5313
|
+
}
|
|
5314
|
+
return [];
|
|
5315
|
+
};
|
|
5304
5316
|
const DfFormPreview = ({ formComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
|
|
5305
5317
|
// Add component management props for edit mode
|
|
5306
5318
|
onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, workOrderNumber, assetNumber, isStandalone, user, onCreateIssue, onUpdateIssue }) => {
|
|
@@ -5359,13 +5371,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
5359
5371
|
// Handle nested components in table cells
|
|
5360
5372
|
if (component.cells && Array.isArray(component.cells)) {
|
|
5361
5373
|
component.cells.forEach((row, _rowIndex) => {
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
});
|
|
5368
|
-
}
|
|
5374
|
+
normalizeTableRow(row).forEach((cell, _cellIndex) => {
|
|
5375
|
+
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
5376
|
+
initializeComponentValues(cell.components, values);
|
|
5377
|
+
}
|
|
5378
|
+
});
|
|
5369
5379
|
});
|
|
5370
5380
|
}
|
|
5371
5381
|
// Handle nested components in datagrid entries
|
|
@@ -5428,11 +5438,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
5428
5438
|
extractNotesAndAttachments(comp.children);
|
|
5429
5439
|
if (comp.cells && Array.isArray(comp.cells))
|
|
5430
5440
|
comp.cells.forEach((row) => {
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
});
|
|
5441
|
+
normalizeTableRow(row).forEach((cell) => {
|
|
5442
|
+
if (cell && cell.components)
|
|
5443
|
+
extractNotesAndAttachments(cell.components);
|
|
5444
|
+
});
|
|
5436
5445
|
});
|
|
5437
5446
|
if (comp.entries)
|
|
5438
5447
|
comp.entries.forEach((entry) => {
|
|
@@ -5471,8 +5480,9 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
5471
5480
|
}
|
|
5472
5481
|
if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
|
|
5473
5482
|
validatedComponent.cells = validatedComponent.cells.map((row) => {
|
|
5474
|
-
|
|
5475
|
-
|
|
5483
|
+
const normalizedRow = normalizeTableRow(row);
|
|
5484
|
+
if (normalizedRow.length > 0) {
|
|
5485
|
+
return normalizedRow.map((cell) => {
|
|
5476
5486
|
if (cell && cell.components && Array.isArray(cell.components)) {
|
|
5477
5487
|
return {
|
|
5478
5488
|
...cell,
|
|
@@ -5619,13 +5629,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
5619
5629
|
if (component.name === 'table' && component.cells) {
|
|
5620
5630
|
return {
|
|
5621
5631
|
...component,
|
|
5622
|
-
cells: component.cells.map((row) =>
|
|
5632
|
+
cells: component.cells.map((row) => normalizeTableRow(row).map((cell) => {
|
|
5623
5633
|
const updatedCell = { ...cell };
|
|
5624
5634
|
if (updatedCell.components) {
|
|
5625
5635
|
updatedCell.components = updateComponentValue(updatedCell.components);
|
|
5626
5636
|
}
|
|
5627
5637
|
return updatedCell;
|
|
5628
|
-
})
|
|
5638
|
+
}))
|
|
5629
5639
|
};
|
|
5630
5640
|
}
|
|
5631
5641
|
if (component.name === 'datagrid' && component.entries) {
|
|
@@ -6232,13 +6242,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6232
6242
|
updatedComponent.children = updateComponentValues(updatedComponent.children);
|
|
6233
6243
|
}
|
|
6234
6244
|
if (updatedComponent.name === 'table' && updatedComponent.cells) {
|
|
6235
|
-
updatedComponent.cells = updatedComponent.cells.map((row) =>
|
|
6245
|
+
updatedComponent.cells = updatedComponent.cells.map((row) => normalizeTableRow(row).map((cell) => {
|
|
6236
6246
|
const updatedCell = { ...cell };
|
|
6237
6247
|
if (updatedCell.components) {
|
|
6238
6248
|
updatedCell.components = updateComponentValues(updatedCell.components);
|
|
6239
6249
|
}
|
|
6240
6250
|
return updatedCell;
|
|
6241
|
-
})
|
|
6251
|
+
}));
|
|
6242
6252
|
}
|
|
6243
6253
|
if (updatedComponent.name === 'datagrid' && updatedComponent.entries) {
|
|
6244
6254
|
updatedComponent.entries = updatedComponent.entries.map((entry) => {
|
|
@@ -6421,7 +6431,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6421
6431
|
// Handle notes change for table cell components
|
|
6422
6432
|
const updatedComponents = localFormComponents.map(comp => {
|
|
6423
6433
|
if (comp.id === component.id && comp.cells) {
|
|
6424
|
-
const updatedCells = comp.cells.map((row) =>
|
|
6434
|
+
const updatedCells = comp.cells.map((row) => normalizeTableRow(row).map((cell) => {
|
|
6425
6435
|
if (cell.components) {
|
|
6426
6436
|
const updatedCellComponents = cell.components.map((cellComp) => {
|
|
6427
6437
|
if (cellComp.id === componentId) {
|
|
@@ -6438,7 +6448,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6438
6448
|
return { ...cell, components: updatedCellComponents };
|
|
6439
6449
|
}
|
|
6440
6450
|
return cell;
|
|
6441
|
-
})
|
|
6451
|
+
}));
|
|
6442
6452
|
return { ...comp, cells: updatedCells };
|
|
6443
6453
|
}
|
|
6444
6454
|
return comp;
|
|
@@ -6448,7 +6458,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6448
6458
|
// Handle attachment change for table cell components
|
|
6449
6459
|
const updatedComponents = localFormComponents.map(comp => {
|
|
6450
6460
|
if (comp.id === component.id && comp.cells) {
|
|
6451
|
-
const updatedCells = comp.cells.map((row) =>
|
|
6461
|
+
const updatedCells = comp.cells.map((row) => normalizeTableRow(row).map((cell) => {
|
|
6452
6462
|
if (cell.components) {
|
|
6453
6463
|
const updatedCellComponents = cell.components.map((cellComp) => {
|
|
6454
6464
|
if (cellComp.id === componentId) {
|
|
@@ -6465,7 +6475,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6465
6475
|
return { ...cell, components: updatedCellComponents };
|
|
6466
6476
|
}
|
|
6467
6477
|
return cell;
|
|
6468
|
-
})
|
|
6478
|
+
}));
|
|
6469
6479
|
return { ...comp, cells: updatedCells };
|
|
6470
6480
|
}
|
|
6471
6481
|
return comp;
|
|
@@ -6771,6 +6781,26 @@ const DfFormComments = ({ comment = '', onSave, placeholder = 'Enter your reason
|
|
|
6771
6781
|
return (jsxs("div", { className: `df-form-comments ${className}`, children: [jsxs("div", { className: "df-form-comments__header", children: [jsx("h3", { className: "df-form-comments__title", children: "Comments" }), jsx("button", { className: "df-form-comments__toggle", type: "button", onClick: toggleComments, "aria-expanded": isExpanded, "aria-label": "Toggle comments section", disabled: disabled, children: isExpanded ? (jsx("span", { className: "df-form-comments__toggle-icon", children: "\u25BC" })) : (jsx("span", { className: "df-form-comments__toggle-icon", children: "\u25B6" })) })] }), jsx("div", { className: `df-form-comments__content ${isExpanded ? 'df-form-comments__content--expanded' : ''}`, children: jsx("div", { className: "df-form-comments__input-container", children: jsx("div", { className: "df-form-comments__input-line", children: jsx("input", { type: "text", id: "comment-input", className: "df-form-comments__input", value: currentComment, onChange: handleInputChange, onBlur: handleInputBlur, onFocus: handleInputFocus, placeholder: placeholder, disabled: disabled }) }) }) })] }));
|
|
6772
6782
|
};
|
|
6773
6783
|
|
|
6784
|
+
// Normalize a row from the API format (object with numeric keys) into a proper TableCell array.
|
|
6785
|
+
// The API may return cells as [{"0": {cell}, "1": {cell}}, ...] instead of [[cell, cell], ...].
|
|
6786
|
+
const normalizeRow = (row) => {
|
|
6787
|
+
if (Array.isArray(row))
|
|
6788
|
+
return row;
|
|
6789
|
+
if (row && typeof row === 'object') {
|
|
6790
|
+
// Convert object with numeric keys to array, sorted by key
|
|
6791
|
+
const keys = Object.keys(row).filter(k => !isNaN(Number(k))).sort((a, b) => Number(a) - Number(b));
|
|
6792
|
+
if (keys.length > 0) {
|
|
6793
|
+
return keys.map(k => row[k]);
|
|
6794
|
+
}
|
|
6795
|
+
}
|
|
6796
|
+
return [];
|
|
6797
|
+
};
|
|
6798
|
+
// Normalize the entire cells structure from API format to TableCell[][]
|
|
6799
|
+
const normalizeCells = (cells) => {
|
|
6800
|
+
if (!cells || !Array.isArray(cells))
|
|
6801
|
+
return [];
|
|
6802
|
+
return cells.map(normalizeRow);
|
|
6803
|
+
};
|
|
6774
6804
|
// Function to ensure table cell components have proper IDs
|
|
6775
6805
|
const ensureComponentHasId = (component) => {
|
|
6776
6806
|
if (!component.id) {
|
|
@@ -6855,19 +6885,22 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
6855
6885
|
};
|
|
6856
6886
|
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 }) => {
|
|
6857
6887
|
const [isCollapsed, setIsCollapsed] = useState(false); // Always start expanded to show drop zones
|
|
6888
|
+
// CRITICAL: Normalize cells from API format (object with numeric keys) to proper 2D array
|
|
6889
|
+
// The API may return cells as [{"0": {cell}, "1": {cell}}, ...] instead of [[cell, cell], ...]
|
|
6890
|
+
const normalizedCells = useMemo(() => normalizeCells(properties.cells), [properties.cells]);
|
|
6858
6891
|
// Check if table has any components in any cells
|
|
6859
|
-
const hasAnyComponents =
|
|
6892
|
+
const hasAnyComponents = normalizedCells.some((row) => row.some((cell) => cell.components && cell.components.length > 0)) || false;
|
|
6860
6893
|
// Initialize and update table cells when rows/columns change
|
|
6861
6894
|
// Only trigger when cells are truly missing or structure doesn't match rows/columns
|
|
6862
6895
|
useEffect(() => {
|
|
6863
6896
|
// Get rows and columns from table properties (where they're actually stored)
|
|
6864
6897
|
const currentRows = Number(properties.table?.rows || properties.basic?.rows || 3);
|
|
6865
6898
|
const currentColumns = Number(properties.table?.columns || properties.basic?.columns || 3);
|
|
6866
|
-
const currentCells =
|
|
6899
|
+
const currentCells = normalizedCells;
|
|
6867
6900
|
// Check if we need to update the table structure
|
|
6868
6901
|
const needsUpdate = currentCells.length === 0 ||
|
|
6869
6902
|
currentCells.length !== currentRows ||
|
|
6870
|
-
(currentCells.length > 0 &&
|
|
6903
|
+
(currentCells.length > 0 && currentCells[0].length !== currentColumns);
|
|
6871
6904
|
if (needsUpdate) {
|
|
6872
6905
|
const newCells = [];
|
|
6873
6906
|
for (let row = 0; row < currentRows; row++) {
|
|
@@ -6876,7 +6909,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6876
6909
|
const cellId = `cell-${row}-${col}`;
|
|
6877
6910
|
// Try to preserve existing components if the cell exists
|
|
6878
6911
|
let existingComponents = [];
|
|
6879
|
-
if (
|
|
6912
|
+
if (currentCells[row] && currentCells[row][col]) {
|
|
6880
6913
|
existingComponents = (currentCells[row][col].components || []).map(ensureComponentHasId);
|
|
6881
6914
|
}
|
|
6882
6915
|
rowCells.push({
|
|
@@ -6894,7 +6927,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6894
6927
|
value: { ...properties, cells: newCells }
|
|
6895
6928
|
});
|
|
6896
6929
|
}
|
|
6897
|
-
}, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns,
|
|
6930
|
+
}, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns, normalizedCells, id, onValueChange]);
|
|
6898
6931
|
const handleTableClick = useCallback((event) => {
|
|
6899
6932
|
event.stopPropagation();
|
|
6900
6933
|
onSelect?.();
|
|
@@ -6911,7 +6944,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6911
6944
|
const handleComponentDelete = useCallback((component, event) => {
|
|
6912
6945
|
event.stopPropagation();
|
|
6913
6946
|
// Find and remove the component from the table cell
|
|
6914
|
-
const updatedCells =
|
|
6947
|
+
const updatedCells = normalizedCells.map((row) => row.map((cell) => {
|
|
6915
6948
|
if (cell.components && cell.components.some((comp) => comp.id === component.id)) {
|
|
6916
6949
|
const filteredComponents = cell.components.filter((comp) => comp.id !== component.id);
|
|
6917
6950
|
return {
|
|
@@ -6920,7 +6953,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6920
6953
|
};
|
|
6921
6954
|
}
|
|
6922
6955
|
return cell;
|
|
6923
|
-
})
|
|
6956
|
+
}));
|
|
6924
6957
|
// Update the table with the modified cells
|
|
6925
6958
|
if (onValueChange) {
|
|
6926
6959
|
onValueChange({
|
|
@@ -6930,13 +6963,13 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6930
6963
|
}
|
|
6931
6964
|
// Don't call parent delete handler for table cell components
|
|
6932
6965
|
// The parent delete handler is for deleting entire fields, not components within table cells
|
|
6933
|
-
}, [onComponentDelete, properties, onValueChange, id]);
|
|
6966
|
+
}, [onComponentDelete, normalizedCells, properties, onValueChange, id]);
|
|
6934
6967
|
// CRITICAL FIX: Ensure all table cell components have proper IDs with table and cell position
|
|
6935
6968
|
// Use useMemo to prevent ID regeneration on every render
|
|
6936
6969
|
const cellsWithIds = useMemo(() => {
|
|
6937
|
-
if (
|
|
6970
|
+
if (normalizedCells.length === 0)
|
|
6938
6971
|
return [];
|
|
6939
|
-
return
|
|
6972
|
+
return normalizedCells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
|
|
6940
6973
|
...cell,
|
|
6941
6974
|
components: (cell.components && Array.isArray(cell.components))
|
|
6942
6975
|
? cell.components.map((comp, compIndex) => {
|
|
@@ -6955,8 +6988,8 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6955
6988
|
};
|
|
6956
6989
|
})
|
|
6957
6990
|
: []
|
|
6958
|
-
}))
|
|
6959
|
-
}, [
|
|
6991
|
+
})));
|
|
6992
|
+
}, [normalizedCells, id]); // Only recalculate if cells or table ID changes
|
|
6960
6993
|
// CRITICAL FIX: Update the parent component with the cells that have proper IDs
|
|
6961
6994
|
// Skip this in package to prevent flickering - cells are managed by parent
|
|
6962
6995
|
// useEffect(() => {
|