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