df-ae-forms-package 1.0.88 → 1.0.90

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
@@ -5304,6 +5304,12 @@ const DfFormTable$1 = React.lazy(() => Promise.resolve().then(function () { retu
5304
5304
  const DfFormPreview = ({ formComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
5305
5305
  // Add component management props for edit mode
5306
5306
  onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, workOrderNumber, assetNumber, isStandalone, user, onCreateIssue, onUpdateIssue }) => {
5307
+ // Local copy of formComponents so structure updates (e.g. table cell init) are reflected immediately
5308
+ const [localFormComponents, setLocalFormComponents] = useState(formComponents);
5309
+ // Sync local state when the prop changes from the parent
5310
+ useEffect(() => {
5311
+ setLocalFormComponents(formComponents);
5312
+ }, [formComponents]);
5307
5313
  // Form state
5308
5314
  const [formValues, setFormValues] = useState({});
5309
5315
  const [validationErrors, setValidationErrors] = useState({});
@@ -5324,7 +5330,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5324
5330
  // Initialize form state
5325
5331
  useEffect(() => {
5326
5332
  initializeFormState();
5327
- }, [formComponents, initialFormData]);
5333
+ }, [localFormComponents, initialFormData]);
5328
5334
  // Recursive function to initialize values from nested components
5329
5335
  const initializeComponentValues = (components, values) => {
5330
5336
  components.forEach(component => {
@@ -5494,11 +5500,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5494
5500
  });
5495
5501
  };
5496
5502
  // Initialize validated components
5497
- let validatedFormComponents = formComponents;
5498
- if (formComponents && formComponents.length > 0) {
5499
- validatedFormComponents = getValidatedComponents(formComponents);
5503
+ let validatedFormComponents = localFormComponents;
5504
+ if (localFormComponents && localFormComponents.length > 0) {
5505
+ validatedFormComponents = getValidatedComponents(localFormComponents);
5500
5506
  // Notifying parent of changed components if they were mutated (IDs added/fixed)
5501
- if (JSON.stringify(validatedFormComponents) !== JSON.stringify(formComponents)) {
5507
+ if (JSON.stringify(validatedFormComponents) !== JSON.stringify(localFormComponents)) {
5502
5508
  onFormDataChange?.(validatedFormComponents);
5503
5509
  }
5504
5510
  }
@@ -5526,7 +5532,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5526
5532
  setComponentAttachments(prev => ({ ...initialAttachments, ...prev }));
5527
5533
  // Conditional logic evaluation disabled temporarily to fix table issues
5528
5534
  // evaluateConditionalLogic()
5529
- }, [initialFormData, formComponents]);
5535
+ }, [initialFormData, localFormComponents]);
5530
5536
  // Conditional logic disabled temporarily - all components are always visible
5531
5537
  const shouldShowComponent = useCallback((_componentId) => {
5532
5538
  return true;
@@ -5539,7 +5545,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5539
5545
  return;
5540
5546
  }
5541
5547
  // CRITICAL: Check if multiple components share this ID (ID collision detection)
5542
- const componentsWithSameId = formComponents.filter(comp => comp.id === change.id);
5548
+ const componentsWithSameId = localFormComponents.filter(comp => comp.id === change.id);
5543
5549
  if (componentsWithSameId.length > 1) {
5544
5550
  console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${change.id}":`, componentsWithSameId.map(c => ({ id: c.id, name: c.name, label: c.basic?.label })));
5545
5551
  // Don't update - this would cause all components with this ID to get the same value
@@ -5560,7 +5566,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5560
5566
  }
5561
5567
  // Clear raised issues for this component when value changes
5562
5568
  // This ensures that if threshold condition changes, user must raise issue again
5563
- const component = formComponents.find(comp => comp.id === change.id);
5569
+ const component = localFormComponents.find(comp => comp.id === change.id);
5564
5570
  if (component) {
5565
5571
  const threshold = component?.threshold;
5566
5572
  if (threshold && threshold.conditions && threshold.conditions.length > 0) {
@@ -5638,7 +5644,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5638
5644
  });
5639
5645
  };
5640
5646
  // Update form components
5641
- const updatedComponents = updateComponentValue(formComponents);
5647
+ const updatedComponents = updateComponentValue(localFormComponents);
5648
+ // CRITICAL: Update local state immediately so structure changes (e.g. table cell init)
5649
+ // are reflected without waiting for Angular parent round-trip
5650
+ setLocalFormComponents(updatedComponents);
5642
5651
  onFormDataChange?.(updatedComponents);
5643
5652
  // Clear validation errors when user starts typing and re-validate
5644
5653
  if (validationErrors[change.id]) {
@@ -5675,7 +5684,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5675
5684
  }
5676
5685
  // Conditional logic evaluation disabled temporarily
5677
5686
  // evaluateConditionalLogic(newFormValues, updatedComponents)
5678
- }, [formComponents, formValues, validationErrors, onFormDataChange]);
5687
+ }, [localFormComponents, formValues, validationErrors, onFormDataChange]);
5679
5688
  // Recursive function to find a component by ID in nested structures
5680
5689
  const findComponentById = useCallback((components, fieldId) => {
5681
5690
  for (const comp of components) {
@@ -5719,7 +5728,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5719
5728
  if (isPreviewMode)
5720
5729
  return;
5721
5730
  // Find component recursively (handles nested components)
5722
- const component = findComponentById(formComponents, fieldId);
5731
+ const component = findComponentById(localFormComponents, fieldId);
5723
5732
  if (!component)
5724
5733
  return;
5725
5734
  // Get current value from form values (real-time input)
@@ -5814,7 +5823,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5814
5823
  ...prev,
5815
5824
  [fieldId]: errorMessage
5816
5825
  }));
5817
- }, [formComponents, isPreviewMode, formValues, findComponentById]);
5826
+ }, [localFormComponents, isPreviewMode, formValues, findComponentById]);
5818
5827
  // Handle form control blur
5819
5828
  const onFormControlBlur = useCallback((fieldId) => {
5820
5829
  setTouchedFields(prev => ({
@@ -5844,11 +5853,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5844
5853
  // useEffect(() => {
5845
5854
  // if (!isPreviewMode && Object.keys(formValues).length > 0) {
5846
5855
  // // Validate all form components when form values change (but not on initial load)
5847
- // formComponents.forEach(component => {
5856
+ // localFormComponents.forEach(component => {
5848
5857
  // validateField(component.id)
5849
5858
  // })
5850
5859
  // }
5851
- // }, [formValues, validateField, isPreviewMode, formComponents])
5860
+ // }, [formValues, validateField, isPreviewMode, localFormComponents])
5852
5861
  // Enhanced form validity check
5853
5862
  const isFormValid = useCallback(() => {
5854
5863
  // Check if there are any validation errors
@@ -5857,7 +5866,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5857
5866
  return false;
5858
5867
  }
5859
5868
  // Check required fields
5860
- return formComponents.every(component => {
5869
+ return localFormComponents.every(component => {
5861
5870
  // Use real-time form values instead of component values
5862
5871
  const currentValue = formValues[component.id] || '';
5863
5872
  // Check if field has a value
@@ -5903,7 +5912,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5903
5912
  }
5904
5913
  return true;
5905
5914
  });
5906
- }, [formComponents, formValues, validationErrors]);
5915
+ }, [localFormComponents, formValues, validationErrors]);
5907
5916
  // Evaluate threshold condition (handles both numeric and string values)
5908
5917
  const evaluateThresholdCondition = useCallback((condition, currentVal) => {
5909
5918
  // Handle array values (for checkbox)
@@ -5957,7 +5966,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5957
5966
  if (isPreviewMode)
5958
5967
  return [];
5959
5968
  const metConditions = [];
5960
- formComponents.forEach(component => {
5969
+ localFormComponents.forEach(component => {
5961
5970
  const condition = component?.condition;
5962
5971
  if (!condition || !condition.conditions || condition.conditions.length === 0) {
5963
5972
  return;
@@ -5983,7 +5992,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5983
5992
  });
5984
5993
  });
5985
5994
  return metConditions;
5986
- }, [formComponents, formValues, isPreviewMode, evaluateThresholdCondition]);
5995
+ }, [localFormComponents, formValues, isPreviewMode, evaluateThresholdCondition]);
5987
5996
  // Validate threshold conditions - check if all met conditions have all mandatory actions completed
5988
5997
  const validateThresholdConditions = useCallback(() => {
5989
5998
  if (isPreviewMode)
@@ -6068,7 +6077,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6068
6077
  let isValid = true;
6069
6078
  setFormSubmitted(true);
6070
6079
  const errors = {};
6071
- formComponents.forEach(component => {
6080
+ localFormComponents.forEach(component => {
6072
6081
  // Use real-time form values instead of component values
6073
6082
  const currentValue = formValues[component.id] || '';
6074
6083
  // Check if field has a value
@@ -6135,13 +6144,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6135
6144
  });
6136
6145
  setValidationErrors(errors);
6137
6146
  return isValid;
6138
- }, [formComponents, isPreviewMode, formValues]);
6147
+ }, [localFormComponents, isPreviewMode, formValues]);
6139
6148
  // Handle form submission
6140
6149
  const handleSubmit = useCallback((status = 'Submitted') => {
6141
6150
  setFormSubmitted(true);
6142
6151
  if (!validateAllFields()) {
6143
6152
  // Focus on the first invalid field
6144
- const firstErrorField = formComponents.find(comp => {
6153
+ const firstErrorField = localFormComponents.find(comp => {
6145
6154
  const currentValue = formValues[comp.id] || '';
6146
6155
  // Check if field has a value
6147
6156
  let hasValue = false;
@@ -6244,12 +6253,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6244
6253
  });
6245
6254
  };
6246
6255
  // Prepare final form data
6247
- const finalFormData = updateComponentValues(formComponents);
6256
+ const finalFormData = updateComponentValues(localFormComponents);
6248
6257
  // Also prepare a clean key-value payload
6249
6258
  const payloadValues = { ...formValues, status };
6250
6259
  // Pass both the updated component tree and the flat values object
6251
6260
  onSubmit?.(finalFormData, payloadValues);
6252
- }, [formComponents, formValues, validateAllFields, onSubmit, componentNotes, componentAttachments]);
6261
+ }, [localFormComponents, formValues, validateAllFields, onSubmit, componentNotes, componentAttachments]);
6253
6262
  // Get preview classes
6254
6263
  const getPreviewClasses = useCallback(() => {
6255
6264
  return {
@@ -6311,7 +6320,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6311
6320
  // Debug: Log if formValue is being shared incorrectly
6312
6321
  if (formValue !== undefined) {
6313
6322
  // Check if this value is being used by multiple components
6314
- const componentsWithSameValue = formComponents.filter(comp => comp.id !== componentId && formValues[comp.id] === formValue);
6323
+ const componentsWithSameValue = localFormComponents.filter(comp => comp.id !== componentId && formValues[comp.id] === formValue);
6315
6324
  if (componentsWithSameValue.length > 0) {
6316
6325
  console.warn(`[DfFormPreview] Component ${componentId} shares form value with other components:`, componentsWithSameValue.map(c => c.id));
6317
6326
  }
@@ -6406,9 +6415,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6406
6415
  return renderFormComponent(field);
6407
6416
  } }));
6408
6417
  case 'table':
6409
- return (jsx(React.Suspense, { fallback: jsx("div", { children: "Loading table..." }), children: jsx(DfFormTable$1, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, validationErrors: validationErrors, touchedFields: touchedFields, formSubmitted: formSubmitted, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, workOrderNumber: workOrderNumber, assetNumber: assetNumber, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue, onNotesChange: (componentId, notes) => {
6418
+ return (jsx(React.Suspense, { fallback: jsx("div", { children: "Loading table..." }), children: jsx(DfFormTable$1, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, validationErrors: validationErrors, touchedFields: touchedFields, formSubmitted: formSubmitted, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, workOrderNumber: workOrderNumber, assetNumber: assetNumber, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue, renderFormComponent: (field) => {
6419
+ return renderFormComponent(field);
6420
+ }, onNotesChange: (componentId, notes) => {
6410
6421
  // Handle notes change for table cell components
6411
- const updatedComponents = formComponents.map(comp => {
6422
+ const updatedComponents = localFormComponents.map(comp => {
6412
6423
  if (comp.id === component.id && comp.cells) {
6413
6424
  const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
6414
6425
  if (cell.components) {
@@ -6435,7 +6446,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6435
6446
  onFormDataChange?.(updatedComponents);
6436
6447
  }, onAttachmentChange: (componentId, attachments) => {
6437
6448
  // Handle attachment change for table cell components
6438
- const updatedComponents = formComponents.map(comp => {
6449
+ const updatedComponents = localFormComponents.map(comp => {
6439
6450
  if (comp.id === component.id && comp.cells) {
6440
6451
  const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map((cell) => {
6441
6452
  if (cell.components) {
@@ -6460,16 +6471,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6460
6471
  return comp;
6461
6472
  });
6462
6473
  onFormDataChange?.(updatedComponents);
6463
- }, renderFormComponent: (field) => {
6464
- // CRITICAL: Pass the field to renderFormComponent which has access to latest formValues
6465
- // renderFormComponent uses formValues[field.id] internally, so it will get the correct value
6466
- return renderFormComponent(field);
6467
6474
  } }) }));
6468
6475
  case 'datagrid':
6469
6476
  return (jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
6470
6477
  handleComponentNotesChange(componentId, notes);
6471
6478
  // Handle notes change for datagrid entry components
6472
- const updatedComponents = formComponents.map(comp => {
6479
+ const updatedComponents = localFormComponents.map(comp => {
6473
6480
  if (comp.id === component.id && comp.entries) {
6474
6481
  const updatedEntries = comp.entries.map((entry) => {
6475
6482
  if (entry.components) {
@@ -6497,7 +6504,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6497
6504
  }, onAttachmentChange: (componentId, attachments) => {
6498
6505
  handleComponentAttachmentChange(componentId, attachments);
6499
6506
  // Handle attachment change for datagrid entry components
6500
- const updatedComponents = formComponents.map(comp => {
6507
+ const updatedComponents = localFormComponents.map(comp => {
6501
6508
  if (comp.id === component.id && comp.entries) {
6502
6509
  const updatedEntries = comp.entries.map((entry) => {
6503
6510
  if (entry.components) {
@@ -6525,8 +6532,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6525
6532
  }, onValueChange: (change) => {
6526
6533
  // Handle datagrid value changes (entries updates)
6527
6534
  if (change.id === component.id && change.value && typeof change.value === 'object' && 'entries' in change.value) {
6528
- // Update formComponents with new entries structure
6529
- const updatedComponents = formComponents.map(comp => {
6535
+ // Update localFormComponents with new entries structure
6536
+ const updatedComponents = localFormComponents.map(comp => {
6530
6537
  if (comp.id === component.id) {
6531
6538
  return {
6532
6539
  ...comp,
@@ -6564,12 +6571,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6564
6571
  }
6565
6572
  }, onEntryAdd: () => {
6566
6573
  // CRITICAL: Entry has already been added via onValueChange in DfFormDataGrid
6567
- // Get the updated component from formComponents (which should have been updated by onValueChange)
6568
- const currentComponent = formComponents.find(comp => comp.id === component.id);
6574
+ // Get the updated component from localFormComponents (which should have been updated by onValueChange)
6575
+ const currentComponent = localFormComponents.find(comp => comp.id === component.id);
6569
6576
  if (currentComponent && currentComponent.entries) {
6570
6577
  // Entry should already be in the component via onValueChange
6571
- // Just ensure formComponents is in sync (no-op if already synced)
6572
- const updatedComponents = formComponents.map(comp => {
6578
+ // Just ensure localFormComponents is in sync (no-op if already synced)
6579
+ const updatedComponents = localFormComponents.map(comp => {
6573
6580
  if (comp.id === component.id) {
6574
6581
  // Ensure entries are properly structured
6575
6582
  return {
@@ -6586,7 +6593,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6586
6593
  setTimeout(() => {
6587
6594
  const datagridValue = formValues[component.id];
6588
6595
  if (datagridValue && typeof datagridValue === 'object' && 'entries' in datagridValue) {
6589
- const updatedComponents = formComponents.map(comp => {
6596
+ const updatedComponents = localFormComponents.map(comp => {
6590
6597
  if (comp.id === component.id) {
6591
6598
  return {
6592
6599
  ...comp,
@@ -6601,7 +6608,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6601
6608
  }
6602
6609
  }, onEntryRemove: (entryIndex) => {
6603
6610
  // Handle entry remove - update form components
6604
- const updatedComponents = formComponents.map(comp => {
6611
+ const updatedComponents = localFormComponents.map(comp => {
6605
6612
  if (comp.id === component.id && comp.entries) {
6606
6613
  const currentEntries = comp.entries || [];
6607
6614
  const updatedEntries = currentEntries
@@ -6643,7 +6650,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6643
6650
  return (jsx("div", { className: "form-group", children: jsxs("div", { className: "form-group-label", children: ["Unsupported Component: ", component.name] }) }));
6644
6651
  }
6645
6652
  };
6646
- return (jsx("div", { className: "form-preview-container", children: jsx("div", { className: "form-preview-wrapper", children: jsxs("div", { className: `form-preview ${Object.entries(getPreviewClasses()).map(([key, value]) => value ? key : '').join(' ')}`, children: [jsx("div", { className: "form-canvas-header" }), formComponents.length === 0 ? (jsx("div", { className: "empty-state", children: jsx("div", { className: "empty-state-card", children: jsx("div", { className: "empty-state-preview-area", children: jsx("span", { className: "empty-state-placeholder", children: "Add components to see the form preview" }) }) }) })) : (jsxs("form", { className: "form-preview-form", onSubmit: (e) => { e.preventDefault(); handleSubmit(); }, children: [(formTitle || formDescription) && (jsxs("div", { className: "form-header", children: [formTitle && (jsx("h1", { className: "form-title", children: formTitle })), formDescription && (jsx("p", { className: "form-description", children: formDescription }))] })), formComponents.map((component) => {
6653
+ return (jsx("div", { className: "form-preview-container", children: jsx("div", { className: "form-preview-wrapper", children: jsxs("div", { className: `form-preview ${Object.entries(getPreviewClasses()).map(([key, value]) => value ? key : '').join(' ')}`, children: [jsx("div", { className: "form-canvas-header" }), localFormComponents.length === 0 ? (jsx("div", { className: "empty-state", children: jsx("div", { className: "empty-state-card", children: jsx("div", { className: "empty-state-preview-area", children: jsx("span", { className: "empty-state-placeholder", children: "Add components to see the form preview" }) }) }) })) : (jsxs("form", { className: "form-preview-form", onSubmit: (e) => { e.preventDefault(); handleSubmit(); }, children: [(formTitle || formDescription) && (jsxs("div", { className: "form-header", children: [formTitle && (jsx("h1", { className: "form-title", children: formTitle })), formDescription && (jsx("p", { className: "form-description", children: formDescription }))] })), localFormComponents.map((component) => {
6647
6654
  const basic = component.basic;
6648
6655
  const formValue = formValues[component.id];
6649
6656
  const isOptionBased = ['select', 'radio', 'checkbox', 'segment'].includes(component.name || '');
@@ -6695,7 +6702,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6695
6702
  // Update local state immediately
6696
6703
  setComponentNotes(prev => ({ ...prev, [component.id]: notes }));
6697
6704
  // Handle notes change for regular components - update component.basic.notes
6698
- const updatedComponents = formComponents.map(comp => {
6705
+ const updatedComponents = localFormComponents.map(comp => {
6699
6706
  if (comp.id === component.id) {
6700
6707
  return {
6701
6708
  ...comp,
@@ -6712,7 +6719,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6712
6719
  // Update local state immediately
6713
6720
  setComponentAttachments(prev => ({ ...prev, [component.id]: attachments || [] }));
6714
6721
  // Handle attachment change for regular components - update component.basic.attachments
6715
- const updatedComponents = formComponents.map(comp => {
6722
+ const updatedComponents = localFormComponents.map(comp => {
6716
6723
  if (comp.id === component.id) {
6717
6724
  return {
6718
6725
  ...comp,