df-ae-forms-package 1.0.95 → 1.0.97

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,13 +4712,6 @@ 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
- // Use a ref for localFormData so renderComponent doesn't need it in deps
4716
- // This prevents DfFormInput from resetting its internal state on every keystroke
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]);
4722
4715
  // Get all components in the grid and sanitize them to ensure no data leaks into templates
4723
4716
  let gridComponents = (properties.templateComponents || []).map(comp => ({
4724
4717
  ...comp,
@@ -4933,10 +4926,8 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4933
4926
  // Handle component value change for form data updates (test mode)
4934
4927
  const handleComponentValueChange = React.useCallback((change) => {
4935
4928
  if (mode === 'test') {
4936
- // CRITICAL: Update localFormDataRef immediately so the value persists in the UI
4937
- // without waiting for the parent round-trip (which resets values for entry 2+)
4938
- localFormDataRef.current = { ...localFormDataRef.current, [change.id]: change.value };
4939
- // Also propagate up to parent for persistence
4929
+ // In test mode, update form data through the parent's onValueChange
4930
+ // This allows the form data to be updated for interactive components
4940
4931
  if (onValueChange) {
4941
4932
  onValueChange({
4942
4933
  id: change.id,
@@ -5000,12 +4991,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
5000
4991
  }, [properties, onValueChange, id, onEntryRemove]);
5001
4992
  // Use our own render function to ensure proper onComponentUpdate handling
5002
4993
  const renderComponent = React.useCallback((field, hideLabel = false) => {
5003
- // CRITICAL: Use localFormDataRef (not formData prop) so values persist in entry 2+ immediately
5004
- // Also fall back to field.basic.value which is updated by DfFormPreview's updateComponentValue after round-trip
5005
- const effectiveFormData = { ...formData, ...localFormDataRef.current };
5006
- const formValue = mode === 'test'
5007
- ? (effectiveFormData[field.id] ?? field.basic?.value ?? ('defaultValue' in field.basic ? field.basic.defaultValue || '' : ''))
5008
- : ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
4994
+ const formValue = mode === 'test' ? (formData[field.id] || ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '')) : ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
5009
4995
  const commonProps = {
5010
4996
  id: field.id,
5011
4997
  properties: field,
@@ -5062,7 +5048,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
5062
5048
  default:
5063
5049
  return jsxRuntime.jsxs("div", { className: "unknown-component", children: ["Unknown component: ", field.name] });
5064
5050
  }
5065
- }, [mode, handleComponentValueChange, formData]);
5051
+ }, [mode, handleComponentValueChange]);
5066
5052
  const gridStyle = {
5067
5053
  backgroundColor: properties.styles.backgroundColor || 'var(--df-color-fb-container)',
5068
5054
  borderColor: properties.styles.borderColor || 'var(--df-color-fb-border)',
@@ -6509,9 +6495,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6509
6495
  onFormDataChange?.(updatedComponents);
6510
6496
  } }) }));
6511
6497
  case 'datagrid':
6498
+ // Align package datagrid wiring with main app behaviour:
6499
+ // - Let DfFormDataGrid manage entry structure via onValueChange
6500
+ // - Use the shared onFormValueChange handler for nested field values
6501
+ // - Keep notes/attachments wiring as before
6512
6502
  return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
6513
6503
  handleComponentNotesChange(componentId, notes);
6514
- // Handle notes change for datagrid entry components
6515
6504
  const updatedComponents = localFormComponents.map(comp => {
6516
6505
  if (comp.id === component.id && comp.entries) {
6517
6506
  const updatedEntries = comp.entries.map((entry) => {
@@ -6539,7 +6528,6 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6539
6528
  onFormDataChange?.(updatedComponents);
6540
6529
  }, onAttachmentChange: (componentId, attachments) => {
6541
6530
  handleComponentAttachmentChange(componentId, attachments);
6542
- // Handle attachment change for datagrid entry components
6543
6531
  const updatedComponents = localFormComponents.map(comp => {
6544
6532
  if (comp.id === component.id && comp.entries) {
6545
6533
  const updatedEntries = comp.entries.map((entry) => {
@@ -6565,116 +6553,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6565
6553
  return comp;
6566
6554
  });
6567
6555
  onFormDataChange?.(updatedComponents);
6568
- }, onValueChange: (change) => {
6569
- console.log('[DfFormPreview] datagrid onValueChange received:', change.id, 'hasEntries:', change.value && typeof change.value === 'object' && 'entries' in change.value);
6570
- // Handle datagrid value changes (entries updates)
6571
- if (change.id === component.id && change.value && typeof change.value === 'object' && 'entries' in change.value) {
6572
- console.log('[DfFormPreview] datagrid entries update - entries count:', change.value.entries?.length);
6573
- // Update localFormComponents with new entries structure
6574
- const updatedComponents = localFormComponents.map(comp => {
6575
- if (comp.id === component.id) {
6576
- return {
6577
- ...comp,
6578
- ...change.value
6579
- };
6580
- }
6581
- return comp;
6582
- });
6583
- // CRITICAL: Update local state immediately so new entries render without Angular round-trip
6584
- setLocalFormComponents(updatedComponents);
6585
- onFormDataChange?.(updatedComponents);
6586
- // Also update formValues for nested components
6587
- if (change.value.entries && Array.isArray(change.value.entries)) {
6588
- change.value.entries.forEach((entry) => {
6589
- if (entry.components && Array.isArray(entry.components)) {
6590
- entry.components.forEach((nestedComp) => {
6591
- const nestedValue = formValues[nestedComp.id];
6592
- if (nestedValue !== undefined) ;
6593
- else {
6594
- // Initialize with defaultValue if available
6595
- const defaultValue = nestedComp.basic?.defaultValue;
6596
- if (defaultValue !== undefined) {
6597
- setFormValues(prev => ({
6598
- ...prev,
6599
- [nestedComp.id]: defaultValue
6600
- }));
6601
- }
6602
- }
6603
- });
6604
- }
6605
- });
6606
- }
6607
- }
6608
- else {
6609
- // For nested component value changes, use the regular handler
6610
- onFormValueChange(change);
6611
- }
6612
- }, onEntryAdd: () => {
6613
- // CRITICAL: Entry has already been added via onValueChange in DfFormDataGrid
6614
- // Get the updated component from localFormComponents (which should have been updated by onValueChange)
6615
- const currentComponent = localFormComponents.find(comp => comp.id === component.id);
6616
- if (currentComponent && currentComponent.entries) {
6617
- // Entry should already be in the component via onValueChange
6618
- // Just ensure localFormComponents is in sync (no-op if already synced)
6619
- const updatedComponents = localFormComponents.map(comp => {
6620
- if (comp.id === component.id) {
6621
- // Ensure entries are properly structured
6622
- return {
6623
- ...comp,
6624
- entries: comp.entries || []
6625
- };
6626
- }
6627
- return comp;
6628
- });
6629
- onFormDataChange?.(updatedComponents);
6630
- }
6631
- else {
6632
- // Fallback: If component doesn't have entries yet, try to get from formValues
6633
- setTimeout(() => {
6634
- const datagridValue = formValues[component.id];
6635
- if (datagridValue && typeof datagridValue === 'object' && 'entries' in datagridValue) {
6636
- const updatedComponents = localFormComponents.map(comp => {
6637
- if (comp.id === component.id) {
6638
- return {
6639
- ...comp,
6640
- entries: datagridValue.entries
6641
- };
6642
- }
6643
- return comp;
6644
- });
6645
- onFormDataChange?.(updatedComponents);
6646
- }
6647
- }, 100);
6648
- }
6649
- }, onEntryRemove: (entryIndex) => {
6650
- // Handle entry remove - update form components
6651
- const updatedComponents = localFormComponents.map(comp => {
6652
- if (comp.id === component.id && comp.entries) {
6653
- const currentEntries = comp.entries || [];
6654
- const updatedEntries = currentEntries
6655
- .filter((_, index) => index !== entryIndex)
6656
- .map((entry, index) => ({
6657
- ...entry,
6658
- index,
6659
- id: `entry-${comp.id}-${index}`,
6660
- components: entry.components?.map((comp, compIndex) => {
6661
- const templateComp = (comp.templateComponents || [])[compIndex];
6662
- return {
6663
- ...comp,
6664
- id: templateComp ? `${templateComp.id}-entry-${index}-${compIndex}` : comp.id
6665
- };
6666
- }) || []
6667
- }));
6668
- return {
6669
- ...comp,
6670
- entries: updatedEntries
6671
- };
6672
- }
6673
- return comp;
6674
- });
6675
- onFormDataChange?.(updatedComponents);
6676
- }, renderFormComponent: (field) => {
6677
- // Ensure the nested component gets the proper form value
6556
+ }, onValueChange: onFormValueChange, renderFormComponent: (field) => {
6678
6557
  return renderFormComponent(field);
6679
6558
  } }));
6680
6559
  case 'file':