df-ae-forms-package 1.0.97 → 1.0.99

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
@@ -6495,12 +6495,9 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6495
6495
  onFormDataChange?.(updatedComponents);
6496
6496
  } }) }));
6497
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
6502
6498
  return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
6503
6499
  handleComponentNotesChange(componentId, notes);
6500
+ // Handle notes change for datagrid entry components
6504
6501
  const updatedComponents = localFormComponents.map(comp => {
6505
6502
  if (comp.id === component.id && comp.entries) {
6506
6503
  const updatedEntries = comp.entries.map((entry) => {
@@ -6528,6 +6525,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6528
6525
  onFormDataChange?.(updatedComponents);
6529
6526
  }, onAttachmentChange: (componentId, attachments) => {
6530
6527
  handleComponentAttachmentChange(componentId, attachments);
6528
+ // Handle attachment change for datagrid entry components
6531
6529
  const updatedComponents = localFormComponents.map(comp => {
6532
6530
  if (comp.id === component.id && comp.entries) {
6533
6531
  const updatedEntries = comp.entries.map((entry) => {
@@ -6553,7 +6551,116 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6553
6551
  return comp;
6554
6552
  });
6555
6553
  onFormDataChange?.(updatedComponents);
6556
- }, onValueChange: onFormValueChange, renderFormComponent: (field) => {
6554
+ }, onValueChange: (change) => {
6555
+ console.log('[DfFormPreview] datagrid onValueChange received:', change.id, 'hasEntries:', change.value && typeof change.value === 'object' && 'entries' in change.value);
6556
+ // Handle datagrid value changes (entries updates)
6557
+ if (change.id === component.id && change.value && typeof change.value === 'object' && 'entries' in change.value) {
6558
+ console.log('[DfFormPreview] datagrid entries update - entries count:', change.value.entries?.length);
6559
+ // Update localFormComponents with new entries structure
6560
+ const updatedComponents = localFormComponents.map(comp => {
6561
+ if (comp.id === component.id) {
6562
+ return {
6563
+ ...comp,
6564
+ ...change.value
6565
+ };
6566
+ }
6567
+ return comp;
6568
+ });
6569
+ // CRITICAL: Update local state immediately so new entries render without Angular round-trip
6570
+ setLocalFormComponents(updatedComponents);
6571
+ onFormDataChange?.(updatedComponents);
6572
+ // Also update formValues for nested components
6573
+ if (change.value.entries && Array.isArray(change.value.entries)) {
6574
+ change.value.entries.forEach((entry) => {
6575
+ if (entry.components && Array.isArray(entry.components)) {
6576
+ entry.components.forEach((nestedComp) => {
6577
+ const nestedValue = formValues[nestedComp.id];
6578
+ if (nestedValue !== undefined) ;
6579
+ else {
6580
+ // Initialize with defaultValue if available
6581
+ const defaultValue = nestedComp.basic?.defaultValue;
6582
+ if (defaultValue !== undefined) {
6583
+ setFormValues(prev => ({
6584
+ ...prev,
6585
+ [nestedComp.id]: defaultValue
6586
+ }));
6587
+ }
6588
+ }
6589
+ });
6590
+ }
6591
+ });
6592
+ }
6593
+ }
6594
+ else {
6595
+ // For nested component value changes, use the regular handler
6596
+ onFormValueChange(change);
6597
+ }
6598
+ }, onEntryAdd: () => {
6599
+ // CRITICAL: Entry has already been added via onValueChange in DfFormDataGrid
6600
+ // Get the updated component from localFormComponents (which should have been updated by onValueChange)
6601
+ const currentComponent = localFormComponents.find(comp => comp.id === component.id);
6602
+ if (currentComponent && currentComponent.entries) {
6603
+ // Entry should already be in the component via onValueChange
6604
+ // Just ensure localFormComponents is in sync (no-op if already synced)
6605
+ const updatedComponents = localFormComponents.map(comp => {
6606
+ if (comp.id === component.id) {
6607
+ // Ensure entries are properly structured
6608
+ return {
6609
+ ...comp,
6610
+ entries: comp.entries || []
6611
+ };
6612
+ }
6613
+ return comp;
6614
+ });
6615
+ onFormDataChange?.(updatedComponents);
6616
+ }
6617
+ else {
6618
+ // Fallback: If component doesn't have entries yet, try to get from formValues
6619
+ setTimeout(() => {
6620
+ const datagridValue = formValues[component.id];
6621
+ if (datagridValue && typeof datagridValue === 'object' && 'entries' in datagridValue) {
6622
+ const updatedComponents = localFormComponents.map(comp => {
6623
+ if (comp.id === component.id) {
6624
+ return {
6625
+ ...comp,
6626
+ entries: datagridValue.entries
6627
+ };
6628
+ }
6629
+ return comp;
6630
+ });
6631
+ onFormDataChange?.(updatedComponents);
6632
+ }
6633
+ }, 100);
6634
+ }
6635
+ }, onEntryRemove: (entryIndex) => {
6636
+ // Handle entry remove - update form components
6637
+ const updatedComponents = localFormComponents.map(comp => {
6638
+ if (comp.id === component.id && comp.entries) {
6639
+ const currentEntries = comp.entries || [];
6640
+ const updatedEntries = currentEntries
6641
+ .filter((_, index) => index !== entryIndex)
6642
+ .map((entry, index) => ({
6643
+ ...entry,
6644
+ index,
6645
+ id: `entry-${comp.id}-${index}`,
6646
+ components: entry.components?.map((comp, compIndex) => {
6647
+ const templateComp = (comp.templateComponents || [])[compIndex];
6648
+ return {
6649
+ ...comp,
6650
+ id: templateComp ? `${templateComp.id}-entry-${index}-${compIndex}` : comp.id
6651
+ };
6652
+ }) || []
6653
+ }));
6654
+ return {
6655
+ ...comp,
6656
+ entries: updatedEntries
6657
+ };
6658
+ }
6659
+ return comp;
6660
+ });
6661
+ onFormDataChange?.(updatedComponents);
6662
+ }, renderFormComponent: (field) => {
6663
+ // Ensure the nested component gets the proper form value
6557
6664
  return renderFormComponent(field);
6558
6665
  } }));
6559
6666
  case 'file':