df-ae-forms-package 1.0.72 → 1.0.74

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
@@ -176,21 +176,9 @@ class ConditionalLogicService {
176
176
  if (found)
177
177
  return found;
178
178
  }
179
- if (comp.name === 'table' && comp.cells && Array.isArray(comp.cells)) {
180
- for (const rowOrCell of comp.cells) {
181
- // Handle 2D array structure (standard: cells[row][col])
182
- if (Array.isArray(rowOrCell)) {
183
- for (const cell of rowOrCell) {
184
- if (cell.components) {
185
- const found = this.findComponent(cell.components, componentId);
186
- if (found)
187
- return found;
188
- }
189
- }
190
- }
191
- // Handle 1D array structure (flat: cells[i]) - robust fallback
192
- else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
193
- const cell = rowOrCell;
179
+ if (comp.name === 'table' && comp.cells) {
180
+ for (const row of comp.cells) {
181
+ for (const cell of row) {
194
182
  if (cell.components) {
195
183
  const found = this.findComponent(cell.components, componentId);
196
184
  if (found)
@@ -232,18 +220,9 @@ class ConditionalLogicService {
232
220
  traverse(item.children);
233
221
  if (item.templateComponents)
234
222
  traverse(item.templateComponents);
235
- if (item.cells && Array.isArray(item.cells)) {
236
- for (const rowOrCell of item.cells) {
237
- // Handle 2D array structure (standard)
238
- if (Array.isArray(rowOrCell)) {
239
- for (const cell of rowOrCell) {
240
- if (cell.components)
241
- traverse(cell.components);
242
- }
243
- }
244
- // Handle 1D array structure (flat)
245
- else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
246
- const cell = rowOrCell;
223
+ if (item.cells) {
224
+ for (const row of item.cells) {
225
+ for (const cell of row) {
247
226
  if (cell.components)
248
227
  traverse(cell.components);
249
228
  }
@@ -6018,35 +5997,17 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6018
5997
  values[component.id] = '';
6019
5998
  }
6020
5999
  }
6021
- // CRITICAL: Also store by label and _id so conditional logic can find values.
6022
- // condition.when stores the component LABEL (set in ConditionalLogicComponent.tsx line 163).
6023
- // getComponentValue() checks formValues[label] first, so we must populate it here
6024
- // to ensure show/hide logic evaluates correctly on initial load (before any user interaction).
6025
- if (component.basic?.label) {
6026
- values[component.basic.label] = values[component.id];
6027
- }
6028
- if (component._id) {
6029
- values[component._id] = values[component.id];
6030
- }
6031
6000
  }
6032
6001
  // Handle nested components in table cells
6033
6002
  if (component.cells && Array.isArray(component.cells)) {
6034
- component.cells.forEach((rowOrCell, _rowIndex) => {
6035
- // Handle 2D array (standard)
6036
- if (Array.isArray(rowOrCell)) {
6037
- rowOrCell.forEach((cell, _cellIndex) => {
6003
+ component.cells.forEach((row, _rowIndex) => {
6004
+ if (Array.isArray(row)) {
6005
+ row.forEach((cell, _cellIndex) => {
6038
6006
  if (cell && cell.components && Array.isArray(cell.components)) {
6039
6007
  initializeComponentValues(cell.components, values);
6040
6008
  }
6041
6009
  });
6042
6010
  }
6043
- // Handle 1D array (flat)
6044
- else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
6045
- const cell = rowOrCell;
6046
- if (cell && cell.components && Array.isArray(cell.components)) {
6047
- initializeComponentValues(cell.components, values);
6048
- }
6049
- }
6050
6011
  });
6051
6012
  }
6052
6013
  // Handle nested components in datagrid entries
@@ -6107,23 +6068,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6107
6068
  // Recurse
6108
6069
  if (comp.children)
6109
6070
  extractNotesAndAttachments(comp.children);
6110
- if (comp.cells && Array.isArray(comp.cells)) {
6111
- comp.cells.forEach((rowOrCell) => {
6112
- // Handle 2D array
6113
- if (Array.isArray(rowOrCell)) {
6114
- rowOrCell.forEach((cell) => {
6115
- if (cell.components)
6116
- extractNotesAndAttachments(cell.components);
6117
- });
6118
- }
6119
- // Handle 1D array
6120
- else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
6121
- const cell = rowOrCell;
6122
- if (cell.components)
6123
- extractNotesAndAttachments(cell.components);
6124
- }
6125
- });
6126
- }
6071
+ if (comp.cells)
6072
+ comp.cells.forEach((row) => row.forEach((cell) => {
6073
+ if (cell.components)
6074
+ extractNotesAndAttachments(cell.components);
6075
+ }));
6127
6076
  if (comp.entries)
6128
6077
  comp.entries.forEach((entry) => {
6129
6078
  if (entry.components)
@@ -6160,10 +6109,9 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6160
6109
  validatedComponent.children = getValidatedComponents(validatedComponent.children);
6161
6110
  }
6162
6111
  if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
6163
- validatedComponent.cells = validatedComponent.cells.map((rowOrCell) => {
6164
- // Handle 2D array
6165
- if (Array.isArray(rowOrCell)) {
6166
- return rowOrCell.map((cell) => {
6112
+ validatedComponent.cells = validatedComponent.cells.map((row) => {
6113
+ if (Array.isArray(row)) {
6114
+ return row.map((cell) => {
6167
6115
  if (cell && cell.components && Array.isArray(cell.components)) {
6168
6116
  return {
6169
6117
  ...cell,
@@ -6173,18 +6121,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6173
6121
  return cell;
6174
6122
  });
6175
6123
  }
6176
- // Handle 1D array
6177
- else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
6178
- const cell = rowOrCell;
6179
- if (cell && cell.components && Array.isArray(cell.components)) {
6180
- return {
6181
- ...cell,
6182
- components: getValidatedComponents(cell.components)
6183
- };
6184
- }
6185
- return cell;
6186
- }
6187
- return rowOrCell;
6124
+ return row;
6188
6125
  });
6189
6126
  }
6190
6127
  if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
@@ -6232,10 +6169,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6232
6169
  // Initialize notes and attachments state
6233
6170
  setComponentNotes(prev => ({ ...initialNotes, ...prev }));
6234
6171
  setComponentAttachments(prev => ({ ...initialAttachments, ...prev }));
6235
- // Evaluate initial conditional logic with the freshly computed initialValues.
6236
- // We pass initialValues explicitly because setFormValues is async and formValues
6237
- // in the closure is still the old state at this point.
6238
- evaluateConditionalLogic(initialValues, validatedFormComponents);
6172
+ // Evaluate initial conditional logic
6173
+ evaluateConditionalLogic();
6239
6174
  }, [initialFormData, formComponents]);
6240
6175
  // Synchronize component visibility whenever form values or components change
6241
6176
  useEffect(() => {
@@ -6269,22 +6204,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6269
6204
  }
6270
6205
  // Handle nested components in table cells
6271
6206
  if (component.cells && Array.isArray(component.cells)) {
6272
- component.cells.forEach((rowOrCell) => {
6273
- // Handle 2D array (standard)
6274
- if (Array.isArray(rowOrCell)) {
6275
- rowOrCell.forEach((cell) => {
6276
- if (cell.components && Array.isArray(cell.components)) {
6277
- evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6278
- }
6279
- });
6280
- }
6281
- // Handle 1D array (flat)
6282
- else if (typeof rowOrCell === 'object' && rowOrCell !== null) {
6283
- const cell = rowOrCell;
6207
+ component.cells.forEach((row) => {
6208
+ row.forEach((cell) => {
6284
6209
  if (cell.components && Array.isArray(cell.components)) {
6285
6210
  evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6286
6211
  }
6287
- }
6212
+ });
6288
6213
  });
6289
6214
  }
6290
6215
  // Handle nested components in datagrid entries
@@ -6319,12 +6244,19 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6319
6244
  }, [formComponents, formValues]);
6320
6245
  // Check if a component should be visible based on conditional logic
6321
6246
  const shouldShowComponent = useCallback((componentId) => {
6322
- // Check the visibility map first
6323
- if (componentVisibility.hasOwnProperty(componentId)) {
6324
- return componentVisibility[componentId] === true;
6247
+ // Recursive find to get the component to check its type and alternate ID
6248
+ // We need this because formComponents might only be top-level
6249
+ const component = conditionalLogicService.findComponent(formComponents, componentId);
6250
+ // Table and datagrid components are always visible at the root level (their contents handle logic)
6251
+ if (component && (component.name === 'table' || component.name === 'datagrid')) {
6252
+ return true;
6325
6253
  }
6326
- // If not in visibility map, component should be visible by default
6327
- return true;
6254
+ // Default to visible if not explicitly hidden
6255
+ // Check both id and _id for maximum resilience
6256
+ const isVisible = (componentVisibility[componentId] !== false) &&
6257
+ (!component?._id || componentVisibility[component._id] !== false) &&
6258
+ (!component?.id || componentVisibility[component.id] !== false);
6259
+ return isVisible;
6328
6260
  }, [componentVisibility, formComponents]);
6329
6261
  // Handle form value changes and re-evaluate conditional logic
6330
6262
  const onFormValueChange = useCallback((change) => {
@@ -6461,6 +6393,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6461
6393
  validateField(change.id);
6462
6394
  }, 150);
6463
6395
  }
6396
+ // Re-evaluate immediately to ensure responsive UI
6397
+ evaluateConditionalLogic(newFormValues, updatedComponents);
6464
6398
  }, [formComponents, formValues, validationErrors, onFormDataChange, evaluateConditionalLogic]);
6465
6399
  // Recursive function to find a component by ID in nested structures
6466
6400
  const findComponentById = useCallback((components, fieldId) => {