df-ae-forms-package 1.0.94 → 1.0.95

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,13 @@ 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
+ // 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]);
4714
4720
  // Get all components in the grid and sanitize them to ensure no data leaks into templates
4715
4721
  let gridComponents = (properties.templateComponents || []).map(comp => ({
4716
4722
  ...comp,
@@ -4925,9 +4931,9 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4925
4931
  // Handle component value change for form data updates (test mode)
4926
4932
  const handleComponentValueChange = useCallback((change) => {
4927
4933
  if (mode === 'test') {
4928
- // CRITICAL: Update local formData immediately so the value persists in the UI
4934
+ // CRITICAL: Update localFormDataRef immediately so the value persists in the UI
4929
4935
  // without waiting for the parent round-trip (which resets values for entry 2+)
4930
- setLocalFormData(prev => ({ ...prev, [change.id]: change.value }));
4936
+ localFormDataRef.current = { ...localFormDataRef.current, [change.id]: change.value };
4931
4937
  // Also propagate up to parent for persistence
4932
4938
  if (onValueChange) {
4933
4939
  onValueChange({
@@ -4992,9 +4998,12 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4992
4998
  }, [properties, onValueChange, id, onEntryRemove]);
4993
4999
  // Use our own render function to ensure proper onComponentUpdate handling
4994
5000
  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 || '' : '');
5001
+ // CRITICAL: Use localFormDataRef (not formData prop) so values persist in entry 2+ immediately
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 || '' : '');
4998
5007
  const commonProps = {
4999
5008
  id: field.id,
5000
5009
  properties: field,
@@ -5051,7 +5060,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
5051
5060
  default:
5052
5061
  return jsxs("div", { className: "unknown-component", children: ["Unknown component: ", field.name] });
5053
5062
  }
5054
- }, [mode, handleComponentValueChange, formData, localFormData]);
5063
+ }, [mode, handleComponentValueChange, formData]);
5055
5064
  const gridStyle = {
5056
5065
  backgroundColor: properties.styles.backgroundColor || 'var(--df-color-fb-container)',
5057
5066
  borderColor: properties.styles.borderColor || 'var(--df-color-fb-border)',