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