df-ae-forms-package 1.0.95 → 1.0.96
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 +8 -96
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -96
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -4710,13 +4710,8 @@ 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
|
-
//
|
|
4714
|
-
|
|
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]);
|
|
4713
|
+
// Track local form values for entry components to prevent value loss during parent round-trip
|
|
4714
|
+
const localFormValuesRef = useRef({});
|
|
4720
4715
|
// Get all components in the grid and sanitize them to ensure no data leaks into templates
|
|
4721
4716
|
let gridComponents = (properties.templateComponents || []).map(comp => ({
|
|
4722
4717
|
...comp,
|
|
@@ -4794,87 +4789,6 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
4794
4789
|
}
|
|
4795
4790
|
}
|
|
4796
4791
|
}
|
|
4797
|
-
else {
|
|
4798
|
-
// Update existing entries to include all template components and sync their properties
|
|
4799
|
-
const needsUpdate = dataEntries.some(entry => {
|
|
4800
|
-
// Check if entry is missing any template components or if existing components need updates
|
|
4801
|
-
return gridComponents.some((templateComp, componentIndex) => {
|
|
4802
|
-
const existingComponent = entry.components?.[componentIndex];
|
|
4803
|
-
if (!existingComponent) {
|
|
4804
|
-
return true; // Missing component at this index
|
|
4805
|
-
}
|
|
4806
|
-
// We don't check for ID matches here anymore
|
|
4807
|
-
// const expectedId = `${templateComp.id}-entry-${entry.index}-${componentIndex}`
|
|
4808
|
-
// const hasProperId = existingComponent.id === expectedId
|
|
4809
|
-
// Check if existing component needs to be updated with new template properties
|
|
4810
|
-
// Compare key properties that should be synced
|
|
4811
|
-
const needsPropertyUpdate = JSON.stringify(existingComponent.basic?.options) !== JSON.stringify(templateComp.basic?.options) ||
|
|
4812
|
-
existingComponent.basic?.placeholder !== templateComp.basic?.placeholder ||
|
|
4813
|
-
existingComponent.basic?.defaultValue !== templateComp.basic?.defaultValue ||
|
|
4814
|
-
existingComponent.basic?.label !== templateComp.basic?.label ||
|
|
4815
|
-
existingComponent.validation?.required !== templateComp.validation?.required;
|
|
4816
|
-
// We do not check for ID mismatch anymore as we want to preserve unique IDs
|
|
4817
|
-
return needsPropertyUpdate;
|
|
4818
|
-
});
|
|
4819
|
-
});
|
|
4820
|
-
if (needsUpdate && onValueChange) {
|
|
4821
|
-
const updatedEntries = dataEntries.map(entry => {
|
|
4822
|
-
// Use index-based matching to ensure each template component maps to the correct entry component
|
|
4823
|
-
const updatedComponents = gridComponents.map((templateComp, componentIndex) => {
|
|
4824
|
-
// Find existing component by index first
|
|
4825
|
-
let existingComponent = entry.components?.[componentIndex];
|
|
4826
|
-
// If no component at this index, try to find by name+label (for backward compatibility)
|
|
4827
|
-
if (!existingComponent) {
|
|
4828
|
-
existingComponent = entry.components?.find((comp) => comp.name === templateComp.name &&
|
|
4829
|
-
comp.basic?.label === templateComp.basic?.label);
|
|
4830
|
-
}
|
|
4831
|
-
// Always ensure a valid ID exists, but respect existing one if possible
|
|
4832
|
-
// const uniqueId = `${templateComp.id}-entry-${entry.index}-${componentIndex}`
|
|
4833
|
-
if (existingComponent) {
|
|
4834
|
-
// Update existing component with new template properties while ensuring unique ID and preserving form values
|
|
4835
|
-
const updatedComponent = {
|
|
4836
|
-
...templateComp,
|
|
4837
|
-
id: existingComponent.id, // Preserve existing ID !!
|
|
4838
|
-
basic: {
|
|
4839
|
-
...templateComp.basic,
|
|
4840
|
-
showLabel: false, // Hide label in datagrid cells
|
|
4841
|
-
// Preserve any user-entered values
|
|
4842
|
-
value: existingComponent.basic?.value || templateComp.basic?.defaultValue || ''
|
|
4843
|
-
}
|
|
4844
|
-
};
|
|
4845
|
-
return updatedComponent;
|
|
4846
|
-
}
|
|
4847
|
-
else {
|
|
4848
|
-
// Create new component based on template
|
|
4849
|
-
// Only for NEW components in existing entries (e.g. column added) do we generate a new ID
|
|
4850
|
-
const uniqueSuffix = `${Date.now()}-${Math.random().toString(36).substr(2, 5)}`;
|
|
4851
|
-
const newId = `${templateComp.id}-${uniqueSuffix}-${componentIndex}`;
|
|
4852
|
-
const newComponent = {
|
|
4853
|
-
...templateComp,
|
|
4854
|
-
id: newId,
|
|
4855
|
-
basic: {
|
|
4856
|
-
...templateComp.basic,
|
|
4857
|
-
showLabel: false // Hide label in datagrid cells
|
|
4858
|
-
}
|
|
4859
|
-
};
|
|
4860
|
-
return newComponent;
|
|
4861
|
-
}
|
|
4862
|
-
});
|
|
4863
|
-
return {
|
|
4864
|
-
...entry,
|
|
4865
|
-
components: updatedComponents
|
|
4866
|
-
};
|
|
4867
|
-
});
|
|
4868
|
-
const newValue = { ...properties, entries: updatedEntries };
|
|
4869
|
-
// Only call onValueChange if the data actually changed
|
|
4870
|
-
if (JSON.stringify(newValue) !== JSON.stringify(properties)) {
|
|
4871
|
-
onValueChange({
|
|
4872
|
-
id,
|
|
4873
|
-
value: newValue
|
|
4874
|
-
});
|
|
4875
|
-
}
|
|
4876
|
-
}
|
|
4877
|
-
}
|
|
4878
4792
|
}
|
|
4879
4793
|
}, [gridComponents, dataEntries, id, onValueChange, properties, mode, properties.templateComponents]);
|
|
4880
4794
|
const handleDataGridClick = useCallback((event) => {
|
|
@@ -4931,9 +4845,8 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
4931
4845
|
// Handle component value change for form data updates (test mode)
|
|
4932
4846
|
const handleComponentValueChange = useCallback((change) => {
|
|
4933
4847
|
if (mode === 'test') {
|
|
4934
|
-
// CRITICAL:
|
|
4935
|
-
|
|
4936
|
-
localFormDataRef.current = { ...localFormDataRef.current, [change.id]: change.value };
|
|
4848
|
+
// CRITICAL: Store value locally to prevent loss during parent round-trip
|
|
4849
|
+
localFormValuesRef.current[change.id] = change.value;
|
|
4937
4850
|
// Also propagate up to parent for persistence
|
|
4938
4851
|
if (onValueChange) {
|
|
4939
4852
|
onValueChange({
|
|
@@ -4998,11 +4911,10 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
4998
4911
|
}, [properties, onValueChange, id, onEntryRemove]);
|
|
4999
4912
|
// Use our own render function to ensure proper onComponentUpdate handling
|
|
5000
4913
|
const renderComponent = useCallback((field, hideLabel = false) => {
|
|
5001
|
-
// CRITICAL: Use
|
|
5002
|
-
//
|
|
5003
|
-
const effectiveFormData = { ...formData, ...localFormDataRef.current };
|
|
4914
|
+
// CRITICAL: Use local values first, then fall back to formData prop, then defaults
|
|
4915
|
+
// This ensures typed values in entry 2+ persist immediately
|
|
5004
4916
|
const formValue = mode === 'test'
|
|
5005
|
-
? (
|
|
4917
|
+
? (localFormValuesRef.current[field.id] ?? formData[field.id] ?? field.basic?.value ?? ('defaultValue' in field.basic ? field.basic.defaultValue || '' : ''))
|
|
5006
4918
|
: ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
|
|
5007
4919
|
const commonProps = {
|
|
5008
4920
|
id: field.id,
|
|
@@ -5060,7 +4972,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
|
|
|
5060
4972
|
default:
|
|
5061
4973
|
return jsxs("div", { className: "unknown-component", children: ["Unknown component: ", field.name] });
|
|
5062
4974
|
}
|
|
5063
|
-
}, [mode, handleComponentValueChange
|
|
4975
|
+
}, [mode, handleComponentValueChange]);
|
|
5064
4976
|
const gridStyle = {
|
|
5065
4977
|
backgroundColor: properties.styles.backgroundColor || 'var(--df-color-fb-container)',
|
|
5066
4978
|
borderColor: properties.styles.borderColor || 'var(--df-color-fb-border)',
|