df-ae-forms-package 1.0.69 → 1.0.71

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,9 +176,21 @@ class ConditionalLogicService {
176
176
  if (found)
177
177
  return found;
178
178
  }
179
- if (comp.name === 'table' && comp.cells) {
180
- for (const row of comp.cells) {
181
- for (const cell of row) {
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;
182
194
  if (cell.components) {
183
195
  const found = this.findComponent(cell.components, componentId);
184
196
  if (found)
@@ -220,9 +232,18 @@ class ConditionalLogicService {
220
232
  traverse(item.children);
221
233
  if (item.templateComponents)
222
234
  traverse(item.templateComponents);
223
- if (item.cells) {
224
- for (const row of item.cells) {
225
- for (const cell of row) {
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;
226
247
  if (cell.components)
227
248
  traverse(cell.components);
228
249
  }
@@ -5997,17 +6018,35 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5997
6018
  values[component.id] = '';
5998
6019
  }
5999
6020
  }
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
+ }
6000
6031
  }
6001
6032
  // Handle nested components in table cells
6002
6033
  if (component.cells && Array.isArray(component.cells)) {
6003
- component.cells.forEach((row, _rowIndex) => {
6004
- if (Array.isArray(row)) {
6005
- row.forEach((cell, _cellIndex) => {
6034
+ component.cells.forEach((rowOrCell, _rowIndex) => {
6035
+ // Handle 2D array (standard)
6036
+ if (Array.isArray(rowOrCell)) {
6037
+ rowOrCell.forEach((cell, _cellIndex) => {
6006
6038
  if (cell && cell.components && Array.isArray(cell.components)) {
6007
6039
  initializeComponentValues(cell.components, values);
6008
6040
  }
6009
6041
  });
6010
6042
  }
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
+ }
6011
6050
  });
6012
6051
  }
6013
6052
  // Handle nested components in datagrid entries
@@ -6068,11 +6107,23 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6068
6107
  // Recurse
6069
6108
  if (comp.children)
6070
6109
  extractNotesAndAttachments(comp.children);
6071
- if (comp.cells)
6072
- comp.cells.forEach((row) => row.forEach((cell) => {
6073
- if (cell.components)
6074
- extractNotesAndAttachments(cell.components);
6075
- }));
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
+ }
6076
6127
  if (comp.entries)
6077
6128
  comp.entries.forEach((entry) => {
6078
6129
  if (entry.components)
@@ -6109,9 +6160,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6109
6160
  validatedComponent.children = getValidatedComponents(validatedComponent.children);
6110
6161
  }
6111
6162
  if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
6112
- validatedComponent.cells = validatedComponent.cells.map((row) => {
6113
- if (Array.isArray(row)) {
6114
- return row.map((cell) => {
6163
+ validatedComponent.cells = validatedComponent.cells.map((rowOrCell) => {
6164
+ // Handle 2D array
6165
+ if (Array.isArray(rowOrCell)) {
6166
+ return rowOrCell.map((cell) => {
6115
6167
  if (cell && cell.components && Array.isArray(cell.components)) {
6116
6168
  return {
6117
6169
  ...cell,
@@ -6121,7 +6173,18 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6121
6173
  return cell;
6122
6174
  });
6123
6175
  }
6124
- return row;
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;
6125
6188
  });
6126
6189
  }
6127
6190
  if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
@@ -6169,8 +6232,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6169
6232
  // Initialize notes and attachments state
6170
6233
  setComponentNotes(prev => ({ ...initialNotes, ...prev }));
6171
6234
  setComponentAttachments(prev => ({ ...initialAttachments, ...prev }));
6172
- // Evaluate initial conditional logic
6173
- evaluateConditionalLogic();
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);
6174
6239
  }, [initialFormData, formComponents]);
6175
6240
  // Synchronize component visibility whenever form values or components change
6176
6241
  useEffect(() => {