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