df-ae-forms-package 1.0.99 → 1.1.1

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
@@ -4492,7 +4492,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4492
4492
  let entryComponent = entry.components?.[componentIndex];
4493
4493
  if (!entryComponent) {
4494
4494
  // Use entry.id (which is unique) instead of entryIndex to prevent data collisions
4495
- const uniqueId = `${templateComponent.id}-${entry.id}-${componentIndex}`;
4495
+ const uniqueId = `${templateComponent.id || 'comp'}-${entry.id}-${componentIndex}`;
4496
4496
  entryComponent = {
4497
4497
  ...templateComponent,
4498
4498
  id: uniqueId,
@@ -4505,7 +4505,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4505
4505
  else {
4506
4506
  entryComponent = {
4507
4507
  ...entryComponent,
4508
- id: entryComponent.id,
4508
+ id: entryComponent.id || `${templateComponent.id || 'comp'}-${entry.id}-${componentIndex}`,
4509
4509
  basic: {
4510
4510
  ...entryComponent.basic,
4511
4511
  showLabel: columnView // Show label in column view
@@ -4629,7 +4629,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4629
4629
  comp.basic?.label === templateComponent.basic?.label);
4630
4630
  }
4631
4631
  if (!entryComponent) {
4632
- const uniqueId = `${templateComponent.id}-${entry.id}-${componentIndex}`;
4632
+ const uniqueId = `${templateComponent.id || 'comp'}-${entry.id}-${componentIndex}`;
4633
4633
  entryComponent = {
4634
4634
  ...templateComponent,
4635
4635
  id: uniqueId,
@@ -4642,7 +4642,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4642
4642
  else {
4643
4643
  entryComponent = {
4644
4644
  ...entryComponent,
4645
- id: entryComponent.id,
4645
+ id: entryComponent.id || `${templateComponent.id || 'comp'}-${entry.id}-${componentIndex}`,
4646
4646
  basic: {
4647
4647
  ...entryComponent.basic,
4648
4648
  showLabel: columnView // Show label in column view, hide in grid view
@@ -4711,8 +4711,9 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4711
4711
  const [isCollapsed, setIsCollapsed] = useState(false);
4712
4712
  const hasInitialized = useRef(false);
4713
4713
  // Get all components in the grid and sanitize them to ensure no data leaks into templates
4714
- let gridComponents = (properties.templateComponents || []).map(comp => ({
4714
+ let gridComponents = (properties.templateComponents || []).map((comp, index) => ({
4715
4715
  ...comp,
4716
+ id: comp.id || `${id}-template-${index}`, // CRITICAL: Ensure template components have stable IDs
4716
4717
  basic: {
4717
4718
  ...comp.basic,
4718
4719
  // Use an empty string instead of undefined to satisfy component typing
@@ -4723,9 +4724,10 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4723
4724
  const dataEntries = properties.entries || [];
4724
4725
  // Fallback: If no template components but we have entries, extract template from first entry
4725
4726
  if (gridComponents.length === 0 && dataEntries.length > 0 && dataEntries[0].components) {
4726
- gridComponents = dataEntries[0].components.map((comp) => ({
4727
+ gridComponents = dataEntries[0].components.map((comp, index) => ({
4727
4728
  ...comp,
4728
- id: comp.id?.replace(/-entry-\d+$/, '') || comp.id, // Remove entry suffix for template
4729
+ // Remove entry suffix for template, use stable ID if missing
4730
+ id: comp.id?.replace(/-entry-.*$/, '') || `${id}-template-${index}`,
4729
4731
  basic: {
4730
4732
  ...comp.basic,
4731
4733
  // Clear any data values while keeping types happy
@@ -4793,12 +4795,9 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4793
4795
  // Check if entry is missing any template components or if existing components need updates
4794
4796
  return gridComponents.some((templateComp, componentIndex) => {
4795
4797
  const existingComponent = entry.components?.[componentIndex];
4796
- if (!existingComponent) {
4797
- return true; // Missing component at this index
4798
+ if (!existingComponent || !existingComponent.id) {
4799
+ return true; // Missing component or missing ID at this index
4798
4800
  }
4799
- // We don't check for ID matches here anymore
4800
- // const expectedId = `${templateComp.id}-entry-${entry.index}-${componentIndex}`
4801
- // const hasProperId = existingComponent.id === expectedId
4802
4801
  // Check if existing component needs to be updated with new template properties
4803
4802
  // Compare key properties that should be synced
4804
4803
  const needsPropertyUpdate = JSON.stringify(existingComponent.basic?.options) !== JSON.stringify(templateComp.basic?.options) ||
@@ -4806,7 +4805,6 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4806
4805
  existingComponent.basic?.defaultValue !== templateComp.basic?.defaultValue ||
4807
4806
  existingComponent.basic?.label !== templateComp.basic?.label ||
4808
4807
  existingComponent.validation?.required !== templateComp.validation?.required;
4809
- // We do not check for ID mismatch anymore as we want to preserve unique IDs
4810
4808
  return needsPropertyUpdate;
4811
4809
  });
4812
4810
  });
@@ -4827,7 +4825,8 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4827
4825
  // Update existing component with new template properties while ensuring unique ID and preserving form values
4828
4826
  const updatedComponent = {
4829
4827
  ...templateComp,
4830
- id: existingComponent.id, // Preserve existing ID !!
4828
+ // Preserve existing ID or generate one if missing
4829
+ id: existingComponent.id || `${templateComp.id}-${entry.id}-${componentIndex}`,
4831
4830
  basic: {
4832
4831
  ...templateComp.basic,
4833
4832
  showLabel: false, // Hide label in datagrid cells
@@ -5461,7 +5460,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5461
5460
  });
5462
5461
  };
5463
5462
  // Validate component IDs for uniqueness without mutating original props
5464
- const getValidatedComponents = (components) => {
5463
+ const getValidatedComponents = (components, parentId) => {
5465
5464
  return components.map((component, index) => {
5466
5465
  let validatedComponent = { ...component };
5467
5466
  // Ensure component has an ID
@@ -5470,33 +5469,42 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5470
5469
  const name = validatedComponent.name || 'component';
5471
5470
  const label = validatedComponent.basic?.label || '';
5472
5471
  const safeLabel = label.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().substring(0, 10);
5473
- // Generate a unique ID
5474
- validatedComponent.id = `${name}-${safeLabel || 'gen'}-${Date.now()}-${Math.random().toString(36).substr(2, 6)}-${index}`;
5472
+ // Generate a stable unique ID if parentId is provided, otherwise fallback to semi-stable
5473
+ if (parentId) {
5474
+ validatedComponent.id = `${parentId}-${name}-${index}`;
5475
+ }
5476
+ else {
5477
+ // For root components, use label if available for stability
5478
+ const labelPart = safeLabel ? `-${safeLabel}` : '';
5479
+ validatedComponent.id = `${name}${labelPart}-${index}`;
5480
+ }
5475
5481
  console.warn(`[DfFormPreview] Assigned missing ID: ${validatedComponent.id}`);
5476
5482
  }
5477
5483
  else {
5478
5484
  // Check for duplicates
5479
5485
  if (seenIds.has(validatedComponent.id)) {
5480
5486
  console.error(`[DfFormPreview] Duplicate component ID detected: ${validatedComponent.id}`);
5481
- // Generate a unique ID for duplicate
5482
- validatedComponent.id = `${validatedComponent.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
5487
+ // Generate a unique ID for duplicate - using index to keep it somewhat stable
5488
+ validatedComponent.id = `${validatedComponent.id}-dup-${index}`;
5483
5489
  console.warn(`[DfFormPreview] Generated new unique ID: ${validatedComponent.id}`);
5484
5490
  }
5485
5491
  }
5486
5492
  seenIds.add(validatedComponent.id);
5487
5493
  // Recursively validate nested components
5488
5494
  if (validatedComponent.children && Array.isArray(validatedComponent.children)) {
5489
- validatedComponent.children = getValidatedComponents(validatedComponent.children);
5495
+ validatedComponent.children = getValidatedComponents(validatedComponent.children, validatedComponent.id);
5490
5496
  }
5491
5497
  if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
5492
- validatedComponent.cells = validatedComponent.cells.map((row) => {
5498
+ validatedComponent.cells = validatedComponent.cells.map((row, rowIndex) => {
5493
5499
  const normalizedRow = normalizeTableRow(row);
5494
5500
  if (normalizedRow.length > 0) {
5495
- return normalizedRow.map((cell) => {
5501
+ return normalizedRow.map((cell, cellIndex) => {
5496
5502
  if (cell && cell.components && Array.isArray(cell.components)) {
5503
+ // Stable ID for table cells: tableId-row-X-cell-Y
5504
+ const cellContextId = `${validatedComponent.id}-row-${rowIndex}-cell-${cellIndex}`;
5497
5505
  return {
5498
5506
  ...cell,
5499
- components: getValidatedComponents(cell.components)
5507
+ components: getValidatedComponents(cell.components, cellContextId)
5500
5508
  };
5501
5509
  }
5502
5510
  return cell;
@@ -5508,9 +5516,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5508
5516
  if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
5509
5517
  validatedComponent.entries = validatedComponent.entries.map((entry) => {
5510
5518
  if (entry && entry.components && Array.isArray(entry.components)) {
5519
+ // Stable ID for datagrid entries: datagridId-entryId or using entry.id
5511
5520
  return {
5512
5521
  ...entry,
5513
- components: getValidatedComponents(entry.components)
5522
+ components: getValidatedComponents(entry.components, entry.id || `${validatedComponent.id}-entry-${entry.index}`)
5514
5523
  };
5515
5524
  }
5516
5525
  return entry;