df-ae-forms-package 1.0.90 → 1.0.92
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 +70 -35
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +70 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -5060,7 +5060,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
5060
5060
|
, {
|
|
5061
5061
|
// Cast to FormComponentType[] to satisfy TableView typing; gridComponents
|
|
5062
5062
|
// are always child form components of the datagrid.
|
|
5063
|
-
templateComponents: gridComponents, dataEntries: dataEntries, renderFormComponent: renderFormComponent || renderComponent, mode: mode, allowAddRemoveEntries: properties.datagrid?.allowAddRemoveEntries ?? true, addAnotherText: properties.datagrid?.addAnotherText ?? 'Add Entry', removeText: properties.datagrid?.removeText ?? 'Remove', maxEntries: properties.datagrid?.maxEntries ?? 10, minEntries: properties.datagrid?.minEntries ?? 1, displayAsGrid: properties.datagrid?.displayAsGrid ?? true, onAddEntry:
|
|
5063
|
+
templateComponents: gridComponents, dataEntries: dataEntries, renderFormComponent: renderFormComponent || renderComponent, mode: mode, allowAddRemoveEntries: properties.datagrid?.allowAddRemoveEntries ?? true, addAnotherText: properties.datagrid?.addAnotherText ?? 'Add Entry', removeText: properties.datagrid?.removeText ?? 'Remove', maxEntries: properties.datagrid?.maxEntries ?? 10, minEntries: properties.datagrid?.minEntries ?? 1, displayAsGrid: properties.datagrid?.displayAsGrid ?? true, onAddEntry: handleAddEntry, onRemoveEntry: handleRemoveEntry, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, columnView: properties.datagrid?.columnView, shouldShowComponent: shouldShowComponent })) }))] }));
|
|
5064
5064
|
};
|
|
5065
5065
|
|
|
5066
5066
|
const DraggableChild = ({ child, selectedChild, mode, onChildSelect, onChildDelete, renderFormComponent, isOverlay = false, isChildrenEditMode = false, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
|
|
@@ -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;
|
|
@@ -6542,6 +6552,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6542
6552
|
}
|
|
6543
6553
|
return comp;
|
|
6544
6554
|
});
|
|
6555
|
+
// CRITICAL: Update local state immediately so new entries render without Angular round-trip
|
|
6556
|
+
setLocalFormComponents(updatedComponents);
|
|
6545
6557
|
onFormDataChange?.(updatedComponents);
|
|
6546
6558
|
// Also update formValues for nested components
|
|
6547
6559
|
if (change.value.entries && Array.isArray(change.value.entries)) {
|
|
@@ -6771,6 +6783,26 @@ const DfFormComments = ({ comment = '', onSave, placeholder = 'Enter your reason
|
|
|
6771
6783
|
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
6784
|
};
|
|
6773
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
|
+
};
|
|
6774
6806
|
// Function to ensure table cell components have proper IDs
|
|
6775
6807
|
const ensureComponentHasId = (component) => {
|
|
6776
6808
|
if (!component.id) {
|
|
@@ -6855,19 +6887,22 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
|
|
|
6855
6887
|
};
|
|
6856
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 }) => {
|
|
6857
6889
|
const [isCollapsed, setIsCollapsed] = 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 = useMemo(() => normalizeCells(properties.cells), [properties.cells]);
|
|
6858
6893
|
// Check if table has any components in any cells
|
|
6859
|
-
const hasAnyComponents =
|
|
6894
|
+
const hasAnyComponents = normalizedCells.some((row) => row.some((cell) => cell.components && cell.components.length > 0)) || false;
|
|
6860
6895
|
// Initialize and update table cells when rows/columns change
|
|
6861
6896
|
// Only trigger when cells are truly missing or structure doesn't match rows/columns
|
|
6862
6897
|
useEffect(() => {
|
|
6863
6898
|
// Get rows and columns from table properties (where they're actually stored)
|
|
6864
6899
|
const currentRows = Number(properties.table?.rows || properties.basic?.rows || 3);
|
|
6865
6900
|
const currentColumns = Number(properties.table?.columns || properties.basic?.columns || 3);
|
|
6866
|
-
const currentCells =
|
|
6901
|
+
const currentCells = normalizedCells;
|
|
6867
6902
|
// Check if we need to update the table structure
|
|
6868
6903
|
const needsUpdate = currentCells.length === 0 ||
|
|
6869
6904
|
currentCells.length !== currentRows ||
|
|
6870
|
-
(currentCells.length > 0 &&
|
|
6905
|
+
(currentCells.length > 0 && currentCells[0].length !== currentColumns);
|
|
6871
6906
|
if (needsUpdate) {
|
|
6872
6907
|
const newCells = [];
|
|
6873
6908
|
for (let row = 0; row < currentRows; row++) {
|
|
@@ -6876,7 +6911,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6876
6911
|
const cellId = `cell-${row}-${col}`;
|
|
6877
6912
|
// Try to preserve existing components if the cell exists
|
|
6878
6913
|
let existingComponents = [];
|
|
6879
|
-
if (
|
|
6914
|
+
if (currentCells[row] && currentCells[row][col]) {
|
|
6880
6915
|
existingComponents = (currentCells[row][col].components || []).map(ensureComponentHasId);
|
|
6881
6916
|
}
|
|
6882
6917
|
rowCells.push({
|
|
@@ -6894,7 +6929,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6894
6929
|
value: { ...properties, cells: newCells }
|
|
6895
6930
|
});
|
|
6896
6931
|
}
|
|
6897
|
-
}, [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]);
|
|
6898
6933
|
const handleTableClick = useCallback((event) => {
|
|
6899
6934
|
event.stopPropagation();
|
|
6900
6935
|
onSelect?.();
|
|
@@ -6911,7 +6946,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6911
6946
|
const handleComponentDelete = useCallback((component, event) => {
|
|
6912
6947
|
event.stopPropagation();
|
|
6913
6948
|
// Find and remove the component from the table cell
|
|
6914
|
-
const updatedCells =
|
|
6949
|
+
const updatedCells = normalizedCells.map((row) => row.map((cell) => {
|
|
6915
6950
|
if (cell.components && cell.components.some((comp) => comp.id === component.id)) {
|
|
6916
6951
|
const filteredComponents = cell.components.filter((comp) => comp.id !== component.id);
|
|
6917
6952
|
return {
|
|
@@ -6920,7 +6955,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6920
6955
|
};
|
|
6921
6956
|
}
|
|
6922
6957
|
return cell;
|
|
6923
|
-
})
|
|
6958
|
+
}));
|
|
6924
6959
|
// Update the table with the modified cells
|
|
6925
6960
|
if (onValueChange) {
|
|
6926
6961
|
onValueChange({
|
|
@@ -6930,13 +6965,13 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6930
6965
|
}
|
|
6931
6966
|
// Don't call parent delete handler for table cell components
|
|
6932
6967
|
// The parent delete handler is for deleting entire fields, not components within table cells
|
|
6933
|
-
}, [onComponentDelete, properties, onValueChange, id]);
|
|
6968
|
+
}, [onComponentDelete, normalizedCells, properties, onValueChange, id]);
|
|
6934
6969
|
// CRITICAL FIX: Ensure all table cell components have proper IDs with table and cell position
|
|
6935
6970
|
// Use useMemo to prevent ID regeneration on every render
|
|
6936
6971
|
const cellsWithIds = useMemo(() => {
|
|
6937
|
-
if (
|
|
6972
|
+
if (normalizedCells.length === 0)
|
|
6938
6973
|
return [];
|
|
6939
|
-
return
|
|
6974
|
+
return normalizedCells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
|
|
6940
6975
|
...cell,
|
|
6941
6976
|
components: (cell.components && Array.isArray(cell.components))
|
|
6942
6977
|
? cell.components.map((comp, compIndex) => {
|
|
@@ -6955,8 +6990,8 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
|
|
|
6955
6990
|
};
|
|
6956
6991
|
})
|
|
6957
6992
|
: []
|
|
6958
|
-
}))
|
|
6959
|
-
}, [
|
|
6993
|
+
})));
|
|
6994
|
+
}, [normalizedCells, id]); // Only recalculate if cells or table ID changes
|
|
6960
6995
|
// CRITICAL FIX: Update the parent component with the cells that have proper IDs
|
|
6961
6996
|
// Skip this in package to prevent flickering - cells are managed by parent
|
|
6962
6997
|
// useEffect(() => {
|