df-ae-forms-package 1.0.95 → 1.0.97
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 +9 -130
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +9 -130
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -4710,13 +4710,6 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
|
|
|
4710
4710
|
const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueChange, onSelect, isSelected = false, className = '', onDataGridSelect, onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, renderFormComponent, onEntryAdd, onEntryRemove, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, shouldShowComponent }) => {
|
|
4711
4711
|
const [isCollapsed, setIsCollapsed] = useState(false);
|
|
4712
4712
|
const hasInitialized = useRef(false);
|
|
4713
|
-
// Use a ref for localFormData so renderComponent doesn't need it in deps
|
|
4714
|
-
// This prevents DfFormInput from resetting its internal state on every keystroke
|
|
4715
|
-
const localFormDataRef = useRef({ ...formData });
|
|
4716
|
-
// Keep ref in sync with formData prop (parent updates), but never overwrite user-typed values
|
|
4717
|
-
useEffect(() => {
|
|
4718
|
-
localFormDataRef.current = { ...formData, ...localFormDataRef.current };
|
|
4719
|
-
}, [formData]);
|
|
4720
4713
|
// Get all components in the grid and sanitize them to ensure no data leaks into templates
|
|
4721
4714
|
let gridComponents = (properties.templateComponents || []).map(comp => ({
|
|
4722
4715
|
...comp,
|
|
@@ -4931,10 +4924,8 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
4931
4924
|
// Handle component value change for form data updates (test mode)
|
|
4932
4925
|
const handleComponentValueChange = useCallback((change) => {
|
|
4933
4926
|
if (mode === 'test') {
|
|
4934
|
-
//
|
|
4935
|
-
//
|
|
4936
|
-
localFormDataRef.current = { ...localFormDataRef.current, [change.id]: change.value };
|
|
4937
|
-
// Also propagate up to parent for persistence
|
|
4927
|
+
// In test mode, update form data through the parent's onValueChange
|
|
4928
|
+
// This allows the form data to be updated for interactive components
|
|
4938
4929
|
if (onValueChange) {
|
|
4939
4930
|
onValueChange({
|
|
4940
4931
|
id: change.id,
|
|
@@ -4998,12 +4989,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
4998
4989
|
}, [properties, onValueChange, id, onEntryRemove]);
|
|
4999
4990
|
// Use our own render function to ensure proper onComponentUpdate handling
|
|
5000
4991
|
const renderComponent = useCallback((field, hideLabel = false) => {
|
|
5001
|
-
|
|
5002
|
-
// Also fall back to field.basic.value which is updated by DfFormPreview's updateComponentValue after round-trip
|
|
5003
|
-
const effectiveFormData = { ...formData, ...localFormDataRef.current };
|
|
5004
|
-
const formValue = mode === 'test'
|
|
5005
|
-
? (effectiveFormData[field.id] ?? field.basic?.value ?? ('defaultValue' in field.basic ? field.basic.defaultValue || '' : ''))
|
|
5006
|
-
: ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
|
|
4992
|
+
const formValue = mode === 'test' ? (formData[field.id] || ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '')) : ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
|
|
5007
4993
|
const commonProps = {
|
|
5008
4994
|
id: field.id,
|
|
5009
4995
|
properties: field,
|
|
@@ -5060,7 +5046,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
5060
5046
|
default:
|
|
5061
5047
|
return jsxs("div", { className: "unknown-component", children: ["Unknown component: ", field.name] });
|
|
5062
5048
|
}
|
|
5063
|
-
}, [mode, handleComponentValueChange
|
|
5049
|
+
}, [mode, handleComponentValueChange]);
|
|
5064
5050
|
const gridStyle = {
|
|
5065
5051
|
backgroundColor: properties.styles.backgroundColor || 'var(--df-color-fb-container)',
|
|
5066
5052
|
borderColor: properties.styles.borderColor || 'var(--df-color-fb-border)',
|
|
@@ -6507,9 +6493,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6507
6493
|
onFormDataChange?.(updatedComponents);
|
|
6508
6494
|
} }) }));
|
|
6509
6495
|
case 'datagrid':
|
|
6496
|
+
// Align package datagrid wiring with main app behaviour:
|
|
6497
|
+
// - Let DfFormDataGrid manage entry structure via onValueChange
|
|
6498
|
+
// - Use the shared onFormValueChange handler for nested field values
|
|
6499
|
+
// - Keep notes/attachments wiring as before
|
|
6510
6500
|
return (jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
|
|
6511
6501
|
handleComponentNotesChange(componentId, notes);
|
|
6512
|
-
// Handle notes change for datagrid entry components
|
|
6513
6502
|
const updatedComponents = localFormComponents.map(comp => {
|
|
6514
6503
|
if (comp.id === component.id && comp.entries) {
|
|
6515
6504
|
const updatedEntries = comp.entries.map((entry) => {
|
|
@@ -6537,7 +6526,6 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6537
6526
|
onFormDataChange?.(updatedComponents);
|
|
6538
6527
|
}, onAttachmentChange: (componentId, attachments) => {
|
|
6539
6528
|
handleComponentAttachmentChange(componentId, attachments);
|
|
6540
|
-
// Handle attachment change for datagrid entry components
|
|
6541
6529
|
const updatedComponents = localFormComponents.map(comp => {
|
|
6542
6530
|
if (comp.id === component.id && comp.entries) {
|
|
6543
6531
|
const updatedEntries = comp.entries.map((entry) => {
|
|
@@ -6563,116 +6551,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
|
|
|
6563
6551
|
return comp;
|
|
6564
6552
|
});
|
|
6565
6553
|
onFormDataChange?.(updatedComponents);
|
|
6566
|
-
}, onValueChange: (
|
|
6567
|
-
console.log('[DfFormPreview] datagrid onValueChange received:', change.id, 'hasEntries:', change.value && typeof change.value === 'object' && 'entries' in change.value);
|
|
6568
|
-
// Handle datagrid value changes (entries updates)
|
|
6569
|
-
if (change.id === component.id && change.value && typeof change.value === 'object' && 'entries' in change.value) {
|
|
6570
|
-
console.log('[DfFormPreview] datagrid entries update - entries count:', change.value.entries?.length);
|
|
6571
|
-
// Update localFormComponents with new entries structure
|
|
6572
|
-
const updatedComponents = localFormComponents.map(comp => {
|
|
6573
|
-
if (comp.id === component.id) {
|
|
6574
|
-
return {
|
|
6575
|
-
...comp,
|
|
6576
|
-
...change.value
|
|
6577
|
-
};
|
|
6578
|
-
}
|
|
6579
|
-
return comp;
|
|
6580
|
-
});
|
|
6581
|
-
// CRITICAL: Update local state immediately so new entries render without Angular round-trip
|
|
6582
|
-
setLocalFormComponents(updatedComponents);
|
|
6583
|
-
onFormDataChange?.(updatedComponents);
|
|
6584
|
-
// Also update formValues for nested components
|
|
6585
|
-
if (change.value.entries && Array.isArray(change.value.entries)) {
|
|
6586
|
-
change.value.entries.forEach((entry) => {
|
|
6587
|
-
if (entry.components && Array.isArray(entry.components)) {
|
|
6588
|
-
entry.components.forEach((nestedComp) => {
|
|
6589
|
-
const nestedValue = formValues[nestedComp.id];
|
|
6590
|
-
if (nestedValue !== undefined) ;
|
|
6591
|
-
else {
|
|
6592
|
-
// Initialize with defaultValue if available
|
|
6593
|
-
const defaultValue = nestedComp.basic?.defaultValue;
|
|
6594
|
-
if (defaultValue !== undefined) {
|
|
6595
|
-
setFormValues(prev => ({
|
|
6596
|
-
...prev,
|
|
6597
|
-
[nestedComp.id]: defaultValue
|
|
6598
|
-
}));
|
|
6599
|
-
}
|
|
6600
|
-
}
|
|
6601
|
-
});
|
|
6602
|
-
}
|
|
6603
|
-
});
|
|
6604
|
-
}
|
|
6605
|
-
}
|
|
6606
|
-
else {
|
|
6607
|
-
// For nested component value changes, use the regular handler
|
|
6608
|
-
onFormValueChange(change);
|
|
6609
|
-
}
|
|
6610
|
-
}, onEntryAdd: () => {
|
|
6611
|
-
// CRITICAL: Entry has already been added via onValueChange in DfFormDataGrid
|
|
6612
|
-
// Get the updated component from localFormComponents (which should have been updated by onValueChange)
|
|
6613
|
-
const currentComponent = localFormComponents.find(comp => comp.id === component.id);
|
|
6614
|
-
if (currentComponent && currentComponent.entries) {
|
|
6615
|
-
// Entry should already be in the component via onValueChange
|
|
6616
|
-
// Just ensure localFormComponents is in sync (no-op if already synced)
|
|
6617
|
-
const updatedComponents = localFormComponents.map(comp => {
|
|
6618
|
-
if (comp.id === component.id) {
|
|
6619
|
-
// Ensure entries are properly structured
|
|
6620
|
-
return {
|
|
6621
|
-
...comp,
|
|
6622
|
-
entries: comp.entries || []
|
|
6623
|
-
};
|
|
6624
|
-
}
|
|
6625
|
-
return comp;
|
|
6626
|
-
});
|
|
6627
|
-
onFormDataChange?.(updatedComponents);
|
|
6628
|
-
}
|
|
6629
|
-
else {
|
|
6630
|
-
// Fallback: If component doesn't have entries yet, try to get from formValues
|
|
6631
|
-
setTimeout(() => {
|
|
6632
|
-
const datagridValue = formValues[component.id];
|
|
6633
|
-
if (datagridValue && typeof datagridValue === 'object' && 'entries' in datagridValue) {
|
|
6634
|
-
const updatedComponents = localFormComponents.map(comp => {
|
|
6635
|
-
if (comp.id === component.id) {
|
|
6636
|
-
return {
|
|
6637
|
-
...comp,
|
|
6638
|
-
entries: datagridValue.entries
|
|
6639
|
-
};
|
|
6640
|
-
}
|
|
6641
|
-
return comp;
|
|
6642
|
-
});
|
|
6643
|
-
onFormDataChange?.(updatedComponents);
|
|
6644
|
-
}
|
|
6645
|
-
}, 100);
|
|
6646
|
-
}
|
|
6647
|
-
}, onEntryRemove: (entryIndex) => {
|
|
6648
|
-
// Handle entry remove - update form components
|
|
6649
|
-
const updatedComponents = localFormComponents.map(comp => {
|
|
6650
|
-
if (comp.id === component.id && comp.entries) {
|
|
6651
|
-
const currentEntries = comp.entries || [];
|
|
6652
|
-
const updatedEntries = currentEntries
|
|
6653
|
-
.filter((_, index) => index !== entryIndex)
|
|
6654
|
-
.map((entry, index) => ({
|
|
6655
|
-
...entry,
|
|
6656
|
-
index,
|
|
6657
|
-
id: `entry-${comp.id}-${index}`,
|
|
6658
|
-
components: entry.components?.map((comp, compIndex) => {
|
|
6659
|
-
const templateComp = (comp.templateComponents || [])[compIndex];
|
|
6660
|
-
return {
|
|
6661
|
-
...comp,
|
|
6662
|
-
id: templateComp ? `${templateComp.id}-entry-${index}-${compIndex}` : comp.id
|
|
6663
|
-
};
|
|
6664
|
-
}) || []
|
|
6665
|
-
}));
|
|
6666
|
-
return {
|
|
6667
|
-
...comp,
|
|
6668
|
-
entries: updatedEntries
|
|
6669
|
-
};
|
|
6670
|
-
}
|
|
6671
|
-
return comp;
|
|
6672
|
-
});
|
|
6673
|
-
onFormDataChange?.(updatedComponents);
|
|
6674
|
-
}, renderFormComponent: (field) => {
|
|
6675
|
-
// Ensure the nested component gets the proper form value
|
|
6554
|
+
}, onValueChange: onFormValueChange, renderFormComponent: (field) => {
|
|
6676
6555
|
return renderFormComponent(field);
|
|
6677
6556
|
} }));
|
|
6678
6557
|
case 'file':
|