df-ae-forms-package 1.1.2 → 1.1.3

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
@@ -4593,7 +4593,11 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4593
4593
  position: 'sticky',
4594
4594
  bottom: 0,
4595
4595
  zIndex: 5
4596
- }, children: jsxRuntime.jsxs("button", { onClick: () => { console.log('[TableView] Add Entry button clicked (grid view)', 'entries:', dataEntries.length, 'max:', maxEntries); onAddEntry(); }, disabled: dataEntries.length >= maxEntries, style: {
4596
+ }, children: jsxRuntime.jsxs("button", { onClick: (e) => {
4597
+ e.stopPropagation();
4598
+ console.log('[TableView] Add Entry button clicked (grid view)', 'entries:', dataEntries.length, 'max:', maxEntries);
4599
+ onAddEntry();
4600
+ }, disabled: dataEntries.length >= maxEntries, style: {
4597
4601
  padding: '8px 16px',
4598
4602
  backgroundColor: dataEntries.length >= maxEntries ? '#f3f4f6' : '#10b981',
4599
4603
  color: dataEntries.length >= maxEntries ? '#9ca3af' : '#ffffff',
@@ -4715,7 +4719,11 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4715
4719
  borderRadius: '8px',
4716
4720
  display: 'flex',
4717
4721
  justifyContent: 'center'
4718
- }, children: jsxRuntime.jsxs("button", { onClick: () => { console.log('[TableView] Add Entry button clicked (list view)', 'entries:', dataEntries.length, 'max:', maxEntries); onAddEntry(); }, disabled: dataEntries.length >= maxEntries, style: {
4722
+ }, children: jsxRuntime.jsxs("button", { onClick: (e) => {
4723
+ e.stopPropagation();
4724
+ console.log('[TableView] Add Entry button clicked (list view)', 'entries:', dataEntries.length, 'max:', maxEntries);
4725
+ onAddEntry();
4726
+ }, disabled: dataEntries.length >= maxEntries, style: {
4719
4727
  padding: '8px 16px',
4720
4728
  backgroundColor: dataEntries.length >= maxEntries ? '#f3f4f6' : '#10b981',
4721
4729
  color: dataEntries.length >= maxEntries ? '#9ca3af' : '#ffffff',
@@ -4739,7 +4747,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4739
4747
  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 }) => {
4740
4748
  const [isCollapsed, setIsCollapsed] = React.useState(false);
4741
4749
  const hasInitialized = React.useRef(false);
4742
- const gridId = ensureStringId$2(id);
4750
+ const gridId = ensureStringId$2(id) || properties._id || (typeof id === 'string' ? id : 'datagrid-id');
4743
4751
  // Get all components in the grid and sanitize them to ensure no data leaks into templates
4744
4752
  let gridComponents = (properties.templateComponents || []).map((comp, index) => ({
4745
4753
  ...comp,
@@ -4967,16 +4975,18 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4967
4975
  // In edit/preview modes, don't handle value changes as components are read-only
4968
4976
  }, [mode, onValueChange]);
4969
4977
  const handleAddEntry = React.useCallback(() => {
4970
- console.log('[DfFormDataGrid] handleAddEntry called');
4971
- console.log('[DfFormDataGrid] gridComponents:', gridComponents.length, gridComponents.map(c => c.id));
4972
- console.log('[DfFormDataGrid] current entries:', properties.entries?.length);
4978
+ console.log('[DfFormDataGrid] handleAddEntry called - Component ID:', id);
4979
+ // Safety check: ensure we have entries array
4980
+ const currentEntries = Array.isArray(properties.entries) ? properties.entries : [];
4981
+ console.log('[DfFormDataGrid] gridComponents:', gridComponents.length);
4982
+ console.log('[DfFormDataGrid] current entries count:', currentEntries.length);
4973
4983
  console.log('[DfFormDataGrid] onValueChange exists:', !!onValueChange);
4974
4984
  // Use timestamp and random string to ensure uniqueness even if entries are deleted
4975
4985
  const uniqueSuffix = `${Date.now()}-${Math.random().toString(36).substr(2, 5)}`;
4976
4986
  const newEntryId = `entry-${uniqueSuffix}`;
4977
4987
  const newEntry = {
4978
4988
  id: newEntryId,
4979
- index: properties.entries.length,
4989
+ index: currentEntries.length,
4980
4990
  components: gridComponents.map((comp, componentIndex) => {
4981
4991
  const componentId = `${ensureStringId$2(comp.id)}-${newEntryId}-${componentIndex}`;
4982
4992
  return {
@@ -4985,7 +4995,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4985
4995
  id: componentId,
4986
4996
  basic: {
4987
4997
  ...comp.basic,
4988
- value: '', // Explicitly clear value for new entries
4998
+ value: comp.basic?.defaultValue || '', // Use defaultValue if available, else empty
4989
4999
  showLabel: false // Hide label in datagrid cells
4990
5000
  }
4991
5001
  };
@@ -4993,31 +5003,41 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4993
5003
  styles: {}
4994
5004
  };
4995
5005
  console.log('[DfFormDataGrid] newEntry created:', newEntry.id, 'with', newEntry.components.length, 'components');
4996
- const updatedEntries = [...properties.entries, newEntry];
5006
+ const updatedEntries = [...currentEntries, newEntry];
4997
5007
  console.log('[DfFormDataGrid] updatedEntries count:', updatedEntries.length);
4998
5008
  if (onValueChange) {
4999
- console.log('[DfFormDataGrid] calling onValueChange with updated entries');
5009
+ console.log('[DfFormDataGrid] calling onValueChange with updated datagrid structure - Entries:', updatedEntries.length);
5000
5010
  onValueChange({
5001
- id,
5002
- value: { ...properties, entries: updatedEntries }
5011
+ id: gridId, // Use sanitized gridId
5012
+ value: {
5013
+ ...properties,
5014
+ entries: updatedEntries
5015
+ }
5003
5016
  });
5017
+ // Notify parent if callback provided
5018
+ if (onEntryAdd) {
5019
+ console.log('[DfFormDataGrid] calling onEntryAdd callback');
5020
+ onEntryAdd();
5021
+ }
5004
5022
  }
5005
5023
  else {
5006
- console.log('[DfFormDataGrid] WARNING: onValueChange is not defined!');
5024
+ console.warn('[DfFormDataGrid] Cannot add entry: onValueChange is missing');
5007
5025
  }
5008
- onEntryAdd?.();
5009
- }, [properties, onValueChange, id, onEntryAdd, gridComponents]);
5026
+ }, [onValueChange, properties, gridId, gridComponents, onEntryAdd]);
5010
5027
  const handleRemoveEntry = React.useCallback((entryIndex) => {
5011
- const updatedEntries = properties.entries
5028
+ // Safety check: ensure we have entries array
5029
+ const currentEntries = Array.isArray(properties.entries) ? properties.entries : [];
5030
+ const updatedEntries = currentEntries
5012
5031
  .filter((_, index) => index !== entryIndex)
5013
5032
  .map((entry, index) => ({ ...entry, index })); // Only update index, preserve unique ID
5014
5033
  if (onValueChange) {
5034
+ console.log('[DfFormDataGrid] Removing entry at index:', entryIndex, 'New count:', updatedEntries.length);
5015
5035
  onValueChange({
5016
- id,
5036
+ id: gridId, // Use sanitized gridId
5017
5037
  value: { ...properties, entries: updatedEntries }
5018
5038
  });
5019
5039
  }
5020
- }, [properties, onValueChange, id, onEntryRemove]);
5040
+ }, [properties.entries, onValueChange, gridId, properties]);
5021
5041
  // Use our own render function to ensure proper onComponentUpdate handling
5022
5042
  const renderComponent = React.useCallback((field, hideLabel = false) => {
5023
5043
  const formValue = mode === 'test' ? (formData[field.id] || ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '')) : ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
@@ -5608,6 +5628,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5608
5628
  return entry;
5609
5629
  });
5610
5630
  }
5631
+ // CRITICAL: Also validate templateComponents for datagrids
5632
+ if (validatedComponent.name === 'datagrid' && validatedComponent.templateComponents && Array.isArray(validatedComponent.templateComponents)) {
5633
+ const datagridId = ensureStringId$1(validatedComponent.id);
5634
+ validatedComponent.templateComponents = getValidatedComponents(validatedComponent.templateComponents, `${datagridId}-template`);
5635
+ }
5611
5636
  return validatedComponent;
5612
5637
  });
5613
5638
  };
@@ -5615,8 +5640,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5615
5640
  let validatedFormComponents = localFormComponents;
5616
5641
  if (localFormComponents && localFormComponents.length > 0) {
5617
5642
  validatedFormComponents = getValidatedComponents(localFormComponents);
5618
- // Notifying parent of changed components if they were mutated (IDs added/fixed)
5643
+ // Synchronize local state if components were mutated (IDs added/fixed)
5619
5644
  if (JSON.stringify(validatedFormComponents) !== JSON.stringify(localFormComponents)) {
5645
+ console.log('[DfFormPreview] Synchronizing local components after ID validation');
5646
+ setLocalFormComponents(validatedFormComponents);
5620
5647
  onFormDataChange?.(validatedFormComponents);
5621
5648
  }
5622
5649
  }
@@ -6528,12 +6555,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6528
6555
  return renderFormComponent(field);
6529
6556
  }, onNotesChange: (componentId, notes) => {
6530
6557
  // Handle notes change for table cell components
6558
+ const targetTableId = ensureStringId$1(component.id);
6531
6559
  const updatedComponents = localFormComponents.map(comp => {
6532
- if (comp.id === component.id && comp.cells) {
6560
+ if (ensureStringId$1(comp.id) === targetTableId && comp.cells) {
6533
6561
  const updatedCells = comp.cells.map((row) => normalizeTableRow(row).map((cell) => {
6534
6562
  if (cell.components) {
6535
6563
  const updatedCellComponents = cell.components.map((cellComp) => {
6536
- if (cellComp.id === componentId) {
6564
+ if (ensureStringId$1(cellComp.id) === componentId) {
6537
6565
  return {
6538
6566
  ...cellComp,
6539
6567
  basic: {
@@ -6555,12 +6583,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6555
6583
  onFormDataChange?.(updatedComponents);
6556
6584
  }, onAttachmentChange: (componentId, attachments) => {
6557
6585
  // Handle attachment change for table cell components
6586
+ const targetTableId = ensureStringId$1(component.id);
6558
6587
  const updatedComponents = localFormComponents.map(comp => {
6559
- if (comp.id === component.id && comp.cells) {
6588
+ if (ensureStringId$1(comp.id) === targetTableId && comp.cells) {
6560
6589
  const updatedCells = comp.cells.map((row) => normalizeTableRow(row).map((cell) => {
6561
6590
  if (cell.components) {
6562
6591
  const updatedCellComponents = cell.components.map((cellComp) => {
6563
- if (cellComp.id === componentId) {
6592
+ if (ensureStringId$1(cellComp.id) === componentId) {
6564
6593
  return {
6565
6594
  ...cellComp,
6566
6595
  basic: {
@@ -6585,12 +6614,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6585
6614
  return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
6586
6615
  handleComponentNotesChange(componentId, notes);
6587
6616
  // Handle notes change for datagrid entry components
6617
+ const targetGridId = ensureStringId$1(component.id);
6588
6618
  const updatedComponents = localFormComponents.map(comp => {
6589
- if (comp.id === component.id && comp.entries) {
6619
+ if (ensureStringId$1(comp.id) === targetGridId && comp.entries) {
6590
6620
  const updatedEntries = comp.entries.map((entry) => {
6591
6621
  if (entry.components) {
6592
6622
  const updatedEntryComponents = entry.components.map((entryComp) => {
6593
- if (entryComp.id === componentId) {
6623
+ if (ensureStringId$1(entryComp.id) === componentId) {
6594
6624
  return {
6595
6625
  ...entryComp,
6596
6626
  basic: {
@@ -6613,12 +6643,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6613
6643
  }, onAttachmentChange: (componentId, attachments) => {
6614
6644
  handleComponentAttachmentChange(componentId, attachments);
6615
6645
  // Handle attachment change for datagrid entry components
6646
+ const targetGridId = ensureStringId$1(component.id);
6616
6647
  const updatedComponents = localFormComponents.map(comp => {
6617
- if (comp.id === component.id && comp.entries) {
6648
+ if (ensureStringId$1(comp.id) === targetGridId && comp.entries) {
6618
6649
  const updatedEntries = comp.entries.map((entry) => {
6619
6650
  if (entry.components) {
6620
6651
  const updatedEntryComponents = entry.components.map((entryComp) => {
6621
- if (entryComp.id === componentId) {
6652
+ if (ensureStringId$1(entryComp.id) === componentId) {
6622
6653
  return {
6623
6654
  ...entryComp,
6624
6655
  basic: {
@@ -6639,13 +6670,16 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6639
6670
  });
6640
6671
  onFormDataChange?.(updatedComponents);
6641
6672
  }, onValueChange: (change) => {
6642
- console.log('[DfFormPreview] datagrid onValueChange received:', change.id, 'hasEntries:', change.value && typeof change.value === 'object' && 'entries' in change.value);
6673
+ const changeId = ensureStringId$1(change.id);
6674
+ const componentId = ensureStringId$1(component.id);
6675
+ console.log(`[DfFormPreview] datagrid onValueChange - Target: ${changeId}, Component: ${componentId}`);
6643
6676
  // Handle datagrid value changes (entries updates)
6644
- if (change.id === component.id && change.value && typeof change.value === 'object' && 'entries' in change.value) {
6677
+ if (changeId === componentId && change.value && typeof change.value === 'object' && 'entries' in change.value) {
6645
6678
  console.log('[DfFormPreview] datagrid entries update - entries count:', change.value.entries?.length);
6646
6679
  // Update localFormComponents with new entries structure
6647
6680
  const updatedComponents = localFormComponents.map(comp => {
6648
- if (comp.id === component.id) {
6681
+ const currentCompId = ensureStringId$1(comp.id);
6682
+ if (currentCompId === componentId) {
6649
6683
  return {
6650
6684
  ...comp,
6651
6685
  ...change.value
@@ -6656,26 +6690,37 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6656
6690
  // CRITICAL: Update local state immediately so new entries render without Angular round-trip
6657
6691
  setLocalFormComponents(updatedComponents);
6658
6692
  onFormDataChange?.(updatedComponents);
6659
- // Also update formValues for nested components
6693
+ // Also update formValues for nested components to prevent undefined values
6660
6694
  if (change.value.entries && Array.isArray(change.value.entries)) {
6695
+ const newValues = { ...formValues };
6696
+ let valuesChanged = false;
6661
6697
  change.value.entries.forEach((entry) => {
6662
6698
  if (entry.components && Array.isArray(entry.components)) {
6663
6699
  entry.components.forEach((nestedComp) => {
6664
- const nestedValue = formValues[nestedComp.id];
6665
- if (nestedValue !== undefined) ;
6666
- else {
6667
- // Initialize with defaultValue if available
6700
+ const nestedId = ensureStringId$1(nestedComp.id);
6701
+ if (!nestedId)
6702
+ return;
6703
+ if (newValues[nestedId] === undefined) {
6704
+ // Initialize with defaultValue if available, otherwise empty string/array
6668
6705
  const defaultValue = nestedComp.basic?.defaultValue;
6669
6706
  if (defaultValue !== undefined) {
6670
- setFormValues(prev => ({
6671
- ...prev,
6672
- [nestedComp.id]: defaultValue
6673
- }));
6707
+ newValues[nestedId] = defaultValue;
6708
+ }
6709
+ else if (nestedComp.name === 'checkbox' || nestedComp.name === 'select') {
6710
+ newValues[nestedId] = [];
6674
6711
  }
6712
+ else {
6713
+ newValues[nestedId] = '';
6714
+ }
6715
+ valuesChanged = true;
6675
6716
  }
6676
6717
  });
6677
6718
  }
6678
6719
  });
6720
+ if (valuesChanged) {
6721
+ console.log('[DfFormPreview] Initializing form values for new datagrid entries');
6722
+ setFormValues(newValues);
6723
+ }
6679
6724
  }
6680
6725
  }
6681
6726
  else {