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