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