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