df-ae-forms-package 1.0.83 → 1.0.85

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.js CHANGED
@@ -180,19 +180,7 @@ class ConditionalLogicService {
180
180
  }
181
181
  if (comp.name === 'table' && comp.cells) {
182
182
  for (const row of comp.cells) {
183
- // Check if row is iterable (array)
184
- if (Array.isArray(row)) {
185
- for (const cell of row) {
186
- if (cell.components) {
187
- const found = this.findComponent(cell.components, componentId);
188
- if (found)
189
- return found;
190
- }
191
- }
192
- }
193
- else {
194
- // Handle case where cells is a 1D array (row is actually a cell)
195
- const cell = row;
183
+ for (const cell of row) {
196
184
  if (cell.components) {
197
185
  const found = this.findComponent(cell.components, componentId);
198
186
  if (found)
@@ -236,14 +224,7 @@ class ConditionalLogicService {
236
224
  traverse(item.templateComponents);
237
225
  if (item.cells) {
238
226
  for (const row of item.cells) {
239
- if (Array.isArray(row)) {
240
- for (const cell of row) {
241
- if (cell.components)
242
- traverse(cell.components);
243
- }
244
- }
245
- else {
246
- const cell = row;
227
+ for (const cell of row) {
247
228
  if (cell.components)
248
229
  traverse(cell.components);
249
230
  }
@@ -5146,7 +5127,7 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
5146
5127
  whiteSpace: 'nowrap',
5147
5128
  overflow: 'hidden',
5148
5129
  textOverflow: 'ellipsis'
5149
- }, children: component.basic?.label || `Column ${index + 1}` }, `header-${component.id || index}`))) })), dataEntries.length > 0 ? (dataEntries.map((entry, entryIndex) => (jsxRuntime.jsxs("div", { className: "table-row", style: {
5130
+ }, children: component.basic?.label || `Column ${index + 1}` }, `header-${component.id}`))) })), dataEntries.length > 0 ? (dataEntries.map((entry, entryIndex) => (jsxRuntime.jsxs("div", { className: "table-row", style: {
5150
5131
  // Use flex column for column view, grid for row view
5151
5132
  display: columnView ? 'flex' : 'grid',
5152
5133
  flexDirection: columnView ? 'column' : 'row',
@@ -5971,47 +5952,9 @@ const DfFormSection = ({ id, properties, mode = 'edit', formData = {}, onValueCh
5971
5952
 
5972
5953
  // Dynamic imports to avoid circular dependencies
5973
5954
  const DfFormTable$1 = React.lazy(() => Promise.resolve().then(function () { return dfFormTable; }));
5974
- const DfFormPreview = ({ formComponents: rawFormComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
5955
+ const DfFormPreview = ({ formComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
5975
5956
  // Add component management props for edit mode
5976
5957
  onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, workOrderNumber, assetNumber, isStandalone, user, onCreateIssue, onUpdateIssue }) => {
5977
- // Ensure all components have IDs (matching main website approach)
5978
- const formComponents = React.useMemo(() => {
5979
- const ensureIds = (components) => {
5980
- return components.map(comp => {
5981
- // Reuse existing ID or generate one
5982
- const id = comp.id || `generated-${Math.random().toString(36).substr(2, 9)}`;
5983
- const newComp = { ...comp, id };
5984
- // Recursively handle nested components
5985
- if (newComp.children && Array.isArray(newComp.children)) {
5986
- newComp.children = ensureIds(newComp.children);
5987
- }
5988
- if (newComp.cells && Array.isArray(newComp.cells)) {
5989
- newComp.cells = newComp.cells.map((row) => {
5990
- if (Array.isArray(row)) {
5991
- return row.map((cell) => ({
5992
- ...cell,
5993
- components: cell.components ? ensureIds(cell.components) : []
5994
- }));
5995
- }
5996
- // Handle flat 1D cell (not wrapped in row array)
5997
- const cell = row;
5998
- return {
5999
- ...cell,
6000
- components: cell.components ? ensureIds(cell.components) : []
6001
- };
6002
- });
6003
- }
6004
- if (newComp.entries && Array.isArray(newComp.entries)) {
6005
- newComp.entries = newComp.entries.map((entry) => ({
6006
- ...entry,
6007
- components: entry.components ? ensureIds(entry.components) : []
6008
- }));
6009
- }
6010
- return newComp;
6011
- });
6012
- };
6013
- return ensureIds(rawFormComponents || []);
6014
- }, [rawFormComponents]);
6015
5958
  // Form state
6016
5959
  const [formValues, setFormValues] = React.useState({});
6017
5960
  const [validationErrors, setValidationErrors] = React.useState({});
@@ -6057,11 +6000,11 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6057
6000
  }
6058
6001
  }
6059
6002
  }
6060
- // Handle nested components in table cells (2D array: row → cell → components)
6003
+ // Handle nested components in table cells
6061
6004
  if (component.cells && Array.isArray(component.cells)) {
6062
- component.cells.forEach((row) => {
6005
+ component.cells.forEach((row, _rowIndex) => {
6063
6006
  if (Array.isArray(row)) {
6064
- row.forEach((cell) => {
6007
+ row.forEach((cell, _cellIndex) => {
6065
6008
  if (cell && cell.components && Array.isArray(cell.components)) {
6066
6009
  initializeComponentValues(cell.components, values);
6067
6010
  }
@@ -6112,6 +6055,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6112
6055
  const initialValues = {};
6113
6056
  const initialNotes = {};
6114
6057
  const initialAttachments = {};
6058
+ const seenIds = new Set();
6115
6059
  // Helper to extract notes and attachments recursively
6116
6060
  const extractNotesAndAttachments = (components) => {
6117
6061
  components.forEach(comp => {
@@ -6127,20 +6071,10 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6127
6071
  if (comp.children)
6128
6072
  extractNotesAndAttachments(comp.children);
6129
6073
  if (comp.cells)
6130
- comp.cells.forEach((row) => {
6131
- if (Array.isArray(row)) {
6132
- row.forEach((cell) => {
6133
- if (cell.components)
6134
- extractNotesAndAttachments(cell.components);
6135
- });
6136
- }
6137
- else {
6138
- // Handle 1D array structure (row is actually a cell)
6139
- const cell = row;
6140
- if (cell.components)
6141
- extractNotesAndAttachments(cell.components);
6142
- }
6143
- });
6074
+ comp.cells.forEach((row) => row.forEach((cell) => {
6075
+ if (cell.components)
6076
+ extractNotesAndAttachments(cell.components);
6077
+ }));
6144
6078
  if (comp.entries)
6145
6079
  comp.entries.forEach((entry) => {
6146
6080
  if (entry.components)
@@ -6148,16 +6082,86 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6148
6082
  });
6149
6083
  });
6150
6084
  };
6151
- // IDs are already ensured by the useMemo at the top - no need for getValidatedComponents
6152
- // Initialize form values from initial data
6085
+ // Validate component IDs for uniqueness without mutating original props
6086
+ const getValidatedComponents = (components) => {
6087
+ return components.map((component, index) => {
6088
+ let validatedComponent = { ...component };
6089
+ // Ensure component has an ID
6090
+ if (!validatedComponent.id || typeof validatedComponent.id !== 'string' || validatedComponent.id.trim() === '') {
6091
+ // Determine a base name for the ID
6092
+ const name = validatedComponent.name || 'component';
6093
+ const label = validatedComponent.basic?.label || '';
6094
+ const safeLabel = label.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().substring(0, 10);
6095
+ // Generate a unique ID
6096
+ validatedComponent.id = `${name}-${safeLabel || 'gen'}-${Date.now()}-${Math.random().toString(36).substr(2, 6)}-${index}`;
6097
+ console.warn(`[DfFormPreview] Assigned missing ID: ${validatedComponent.id}`);
6098
+ }
6099
+ else {
6100
+ // Check for duplicates
6101
+ if (seenIds.has(validatedComponent.id)) {
6102
+ console.error(`[DfFormPreview] Duplicate component ID detected: ${validatedComponent.id}`);
6103
+ // Generate a unique ID for duplicate
6104
+ validatedComponent.id = `${validatedComponent.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
6105
+ console.warn(`[DfFormPreview] Generated new unique ID: ${validatedComponent.id}`);
6106
+ }
6107
+ }
6108
+ seenIds.add(validatedComponent.id);
6109
+ // Recursively validate nested components
6110
+ if (validatedComponent.children && Array.isArray(validatedComponent.children)) {
6111
+ validatedComponent.children = getValidatedComponents(validatedComponent.children);
6112
+ }
6113
+ if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
6114
+ validatedComponent.cells = validatedComponent.cells.map((row) => {
6115
+ if (Array.isArray(row)) {
6116
+ return row.map((cell) => {
6117
+ if (cell && cell.components && Array.isArray(cell.components)) {
6118
+ return {
6119
+ ...cell,
6120
+ components: getValidatedComponents(cell.components)
6121
+ };
6122
+ }
6123
+ return cell;
6124
+ });
6125
+ }
6126
+ return row;
6127
+ });
6128
+ }
6129
+ if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
6130
+ validatedComponent.entries = validatedComponent.entries.map((entry) => {
6131
+ if (entry && entry.components && Array.isArray(entry.components)) {
6132
+ return {
6133
+ ...entry,
6134
+ components: getValidatedComponents(entry.components)
6135
+ };
6136
+ }
6137
+ return entry;
6138
+ });
6139
+ }
6140
+ return validatedComponent;
6141
+ });
6142
+ };
6143
+ // Initialize validated components
6144
+ let validatedFormComponents = formComponents;
6145
+ if (formComponents && formComponents.length > 0) {
6146
+ validatedFormComponents = getValidatedComponents(formComponents);
6147
+ // Notifying parent of changed components if they were mutated (IDs added/fixed)
6148
+ if (JSON.stringify(validatedFormComponents) !== JSON.stringify(formComponents)) {
6149
+ onFormDataChange?.(validatedFormComponents);
6150
+ }
6151
+ }
6152
+ let validatedInitialFormData = initialFormData;
6153
6153
  if (initialFormData && initialFormData.length > 0) {
6154
- initializeComponentValues(initialFormData, initialValues);
6154
+ validatedInitialFormData = getValidatedComponents(initialFormData);
6155
+ }
6156
+ // Initialize form values from initial data
6157
+ if (validatedInitialFormData && validatedInitialFormData.length > 0) {
6158
+ initializeComponentValues(validatedInitialFormData, initialValues);
6155
6159
  }
6156
6160
  // Initialize form values from form components (for submitted data or pre-filled forms)
6157
6161
  // CRITICAL: This must run AFTER initialFormData to pick up any values embedded in the components themselves
6158
- if (formComponents && formComponents.length > 0) {
6159
- initializeComponentValues(formComponents, initialValues);
6160
- extractNotesAndAttachments(formComponents);
6162
+ if (validatedFormComponents && validatedFormComponents.length > 0) {
6163
+ initializeComponentValues(validatedFormComponents, initialValues);
6164
+ extractNotesAndAttachments(validatedFormComponents);
6161
6165
  }
6162
6166
  // Set the state
6163
6167
  setFormValues(prev => {
@@ -6200,23 +6204,14 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6200
6204
  visibility[component.basic.label] = true;
6201
6205
  }
6202
6206
  }
6203
- // Handle nested components in table cells (2D: row → cell → components)
6207
+ // Handle nested components in table cells
6204
6208
  if (component.cells && Array.isArray(component.cells)) {
6205
6209
  component.cells.forEach((row) => {
6206
- if (Array.isArray(row)) {
6207
- row.forEach((cell) => {
6208
- if (cell && cell.components && Array.isArray(cell.components)) {
6209
- evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6210
- }
6211
- });
6212
- }
6213
- else {
6214
- // Handle flat 1D cell
6215
- const cell = row;
6216
- if (cell && cell.components && Array.isArray(cell.components)) {
6210
+ row.forEach((cell) => {
6211
+ if (cell.components && Array.isArray(cell.components)) {
6217
6212
  evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6218
6213
  }
6219
- }
6214
+ });
6220
6215
  });
6221
6216
  }
6222
6217
  // Handle nested components in datagrid entries
@@ -6282,19 +6277,26 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6282
6277
  // Debug: Log value changes to identify ID collisions
6283
6278
  const existingValue = formValues[change.id];
6284
6279
  if (existingValue !== undefined && existingValue !== change.value) ;
6280
+ // CRITICAL: Check if this is a table/datagrid structure update (cells, entries, etc.)
6281
+ // These should NOT be stored in formValues - they update the component structure only
6282
+ const isStructureUpdate = change.value && typeof change.value === 'object' &&
6283
+ ('cells' in change.value || ('entries' in change.value && 'name' in change.value));
6285
6284
  // Use the service's recursive find to find the component and update BOTH IDs in formValues
6286
6285
  const targetComponent = conditionalLogicService.findComponent(formComponents, change.id);
6287
6286
  const newFormValues = { ...formValues };
6288
- newFormValues[change.id] = change.value;
6289
- if (targetComponent) {
6290
- if (targetComponent.id)
6291
- newFormValues[targetComponent.id] = change.value;
6292
- if (targetComponent._id)
6293
- newFormValues[targetComponent._id] = change.value;
6294
- if (targetComponent.basic?.label)
6295
- newFormValues[targetComponent.basic.label] = change.value;
6296
- }
6297
- setFormValues(newFormValues);
6287
+ // Only update formValues for actual value changes, not structure updates
6288
+ if (!isStructureUpdate) {
6289
+ newFormValues[change.id] = change.value;
6290
+ if (targetComponent) {
6291
+ if (targetComponent.id)
6292
+ newFormValues[targetComponent.id] = change.value;
6293
+ if (targetComponent._id)
6294
+ newFormValues[targetComponent._id] = change.value;
6295
+ if (targetComponent.basic?.label)
6296
+ newFormValues[targetComponent.basic.label] = change.value;
6297
+ }
6298
+ setFormValues(newFormValues);
6299
+ }
6298
6300
  // Re-evaluate conditional logic after form value changes
6299
6301
  // Use setTimeout to ensure state update has completed
6300
6302
  setTimeout(() => {
@@ -6319,6 +6321,21 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6319
6321
  const updateComponentValue = (components) => {
6320
6322
  return components.map(component => {
6321
6323
  if (component.id === change.id) {
6324
+ // CRITICAL: Handle table/datagrid structure updates (cells, entries, etc.)
6325
+ // When a table sends onValueChange with cells data, update the whole component structure
6326
+ if (change.value && typeof change.value === 'object' && 'cells' in change.value) {
6327
+ return {
6328
+ ...component,
6329
+ ...change.value
6330
+ };
6331
+ }
6332
+ // Handle datagrid structure updates
6333
+ if (change.value && typeof change.value === 'object' && 'entries' in change.value) {
6334
+ return {
6335
+ ...component,
6336
+ ...change.value
6337
+ };
6338
+ }
6322
6339
  if ('defaultValue' in component.basic) {
6323
6340
  return {
6324
6341
  ...component,
@@ -6340,24 +6357,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6340
6357
  if (component.name === 'table' && component.cells) {
6341
6358
  return {
6342
6359
  ...component,
6343
- cells: component.cells.map((row) => {
6344
- if (Array.isArray(row)) {
6345
- return row.map((cell) => {
6346
- const updatedCell = { ...cell };
6347
- if (updatedCell.components) {
6348
- updatedCell.components = updateComponentValue(updatedCell.components);
6349
- }
6350
- return updatedCell;
6351
- });
6352
- }
6353
- // Handle flat 1D cell
6354
- const cell = row;
6360
+ cells: component.cells.map((row) => row.map((cell) => {
6355
6361
  const updatedCell = { ...cell };
6356
6362
  if (updatedCell.components) {
6357
6363
  updatedCell.components = updateComponentValue(updatedCell.components);
6358
6364
  }
6359
6365
  return updatedCell;
6360
- })
6366
+ }))
6361
6367
  };
6362
6368
  }
6363
6369
  if (component.name === 'datagrid' && component.entries) {
@@ -6429,19 +6435,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6429
6435
  // Check nested components in table cells
6430
6436
  if (comp.name === 'table' && comp.cells) {
6431
6437
  for (const row of comp.cells) {
6432
- if (Array.isArray(row)) {
6433
- for (const cell of row) {
6434
- if (cell && cell.components) {
6435
- const found = findComponentById(cell.components, fieldId);
6436
- if (found)
6437
- return found;
6438
- }
6439
- }
6440
- }
6441
- else {
6442
- // Handle flat 1D cell
6443
- const cell = row;
6444
- if (cell && cell.components) {
6438
+ for (const cell of row) {
6439
+ if (cell.components) {
6445
6440
  const found = findComponentById(cell.components, fieldId);
6446
6441
  if (found)
6447
6442
  return found;
@@ -6972,25 +6967,13 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6972
6967
  updatedComponent.children = updateComponentValues(updatedComponent.children);
6973
6968
  }
6974
6969
  if (updatedComponent.name === 'table' && updatedComponent.cells) {
6975
- updatedComponent.cells = updatedComponent.cells.map((rowOrCell) => {
6976
- if (Array.isArray(rowOrCell)) {
6977
- return rowOrCell.map((cell) => {
6978
- const updatedCell = { ...cell };
6979
- if (updatedCell.components) {
6980
- updatedCell.components = updateComponentValues(updatedCell.components);
6981
- }
6982
- return updatedCell;
6983
- });
6984
- }
6985
- else {
6986
- // 1D flat cell
6987
- const updatedCell = { ...rowOrCell };
6988
- if (updatedCell.components) {
6989
- updatedCell.components = updateComponentValues(updatedCell.components);
6990
- }
6991
- return updatedCell;
6970
+ updatedComponent.cells = updatedComponent.cells.map((row) => row.map((cell) => {
6971
+ const updatedCell = { ...cell };
6972
+ if (updatedCell.components) {
6973
+ updatedCell.components = updateComponentValues(updatedCell.components);
6992
6974
  }
6993
- });
6975
+ return updatedCell;
6976
+ }));
6994
6977
  }
6995
6978
  if (updatedComponent.name === 'datagrid' && updatedComponent.entries) {
6996
6979
  updatedComponent.entries = updatedComponent.entries.map((entry) => {
@@ -7168,48 +7151,64 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
7168
7151
  } }));
7169
7152
  case 'table':
7170
7153
  return (jsxRuntime.jsx(React.Suspense, { fallback: jsxRuntime.jsx("div", { children: "Loading table..." }), children: jsxRuntime.jsx(DfFormTable$1, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, validationErrors: validationErrors, touchedFields: touchedFields, formSubmitted: formSubmitted, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, workOrderNumber: workOrderNumber, assetNumber: assetNumber, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue, onNotesChange: (componentId, notes) => {
7154
+ // Handle notes change for table cell components
7171
7155
  const updatedComponents = formComponents.map(comp => {
7172
7156
  if (comp.id === component.id && comp.cells) {
7173
- const updateCell = (cell) => {
7157
+ const updatedCells = comp.cells.map((row) => row.map((cell) => {
7174
7158
  if (cell.components) {
7175
- return {
7176
- ...cell,
7177
- components: cell.components.map((cellComp) => cellComp.id === componentId
7178
- ? { ...cellComp, basic: { ...cellComp.basic, notes } }
7179
- : cellComp)
7180
- };
7159
+ const updatedCellComponents = cell.components.map((cellComp) => {
7160
+ if (cellComp.id === componentId) {
7161
+ return {
7162
+ ...cellComp,
7163
+ basic: {
7164
+ ...cellComp.basic,
7165
+ notes
7166
+ }
7167
+ };
7168
+ }
7169
+ return cellComp;
7170
+ });
7171
+ return { ...cell, components: updatedCellComponents };
7181
7172
  }
7182
7173
  return cell;
7183
- };
7184
- const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
7174
+ }));
7185
7175
  return { ...comp, cells: updatedCells };
7186
7176
  }
7187
7177
  return comp;
7188
7178
  });
7189
7179
  onFormDataChange?.(updatedComponents);
7190
7180
  }, onAttachmentChange: (componentId, attachments) => {
7181
+ // Handle attachment change for table cell components
7191
7182
  const updatedComponents = formComponents.map(comp => {
7192
7183
  if (comp.id === component.id && comp.cells) {
7193
- const updateCell = (cell) => {
7184
+ const updatedCells = comp.cells.map((row) => row.map((cell) => {
7194
7185
  if (cell.components) {
7195
- return {
7196
- ...cell,
7197
- components: cell.components.map((cellComp) => cellComp.id === componentId
7198
- ? { ...cellComp, basic: { ...cellComp.basic, attachments: attachments || [] } }
7199
- : cellComp)
7200
- };
7186
+ const updatedCellComponents = cell.components.map((cellComp) => {
7187
+ if (cellComp.id === componentId) {
7188
+ return {
7189
+ ...cellComp,
7190
+ basic: {
7191
+ ...cellComp.basic,
7192
+ attachments: attachments || []
7193
+ }
7194
+ };
7195
+ }
7196
+ return cellComp;
7197
+ });
7198
+ return { ...cell, components: updatedCellComponents };
7201
7199
  }
7202
7200
  return cell;
7203
- };
7204
- const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
7201
+ }));
7205
7202
  return { ...comp, cells: updatedCells };
7206
7203
  }
7207
7204
  return comp;
7208
7205
  });
7209
7206
  onFormDataChange?.(updatedComponents);
7210
7207
  }, renderFormComponent: (field) => {
7208
+ // CRITICAL: Pass the field to renderFormComponent which has access to latest formValues
7209
+ // renderFormComponent uses formValues[field.id] internally, so it will get the correct value
7211
7210
  return renderFormComponent(field);
7212
- }, shouldShowComponent: shouldShowComponent }) }));
7211
+ } }) }));
7213
7212
  case 'datagrid':
7214
7213
  return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: component, formData: formValues, formTemplateId: formTemplateId, mode: commonProps.mode, onThresholdActionCompletion: handleThresholdActionCompletion, onThresholdIssueRaised: handleThresholdIssueRaised, onNotesChange: (componentId, notes) => {
7215
7214
  handleComponentNotesChange(componentId, notes);
@@ -7519,13 +7518,12 @@ const ensureComponentHasId = (component) => {
7519
7518
  }
7520
7519
  return component;
7521
7520
  };
7522
- const SimpleTableComponent = ({ component, mode, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue, shouldShowComponent }) => {
7521
+ const SimpleTableComponent = ({ component, mode, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
7523
7522
  const formValue = formData[component.id];
7524
- const isVisible = shouldShowComponent ? shouldShowComponent(component.id) : true;
7525
7523
  // Check if component has notes or attachments for submission view
7526
7524
  const hasSubmissionData = mode === 'preview' && ((component.basic?.notes && component.basic.notes.trim().length > 0) ||
7527
7525
  (component.basic?.attachments && Array.isArray(component.basic.attachments) && component.basic.attachments.length > 0));
7528
- return (jsxRuntime.jsxs("div", { className: `simple-table-component ${(!isVisible && mode !== 'edit') ? 'conditionally-hidden' : ''}`, style: { display: (isVisible || mode === 'edit') ? undefined : 'none' }, children: [renderFormComponent(component), mode === 'test' && !['section', 'table', 'heading', 'file', 'instructions', 'signature', 'location', 'datagrid'].includes(component.name) && (jsxRuntime.jsx(ComponentActionFeatures, { component: component, mode: "test", formTemplateId: formTemplateId, formValue: formValue, formData: formData, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange ? (notes) => onNotesChange(component.id, notes) : undefined, onAttachmentChange: onAttachmentChange ? (attachments) => onAttachmentChange(component.id, attachments) : undefined, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue })), hasSubmissionData && (jsxRuntime.jsx(ComponentSubmissionActions, { component: component }))] }));
7526
+ return (jsxRuntime.jsxs("div", { className: "simple-table-component", children: [renderFormComponent(component), !['section', 'table', 'heading', 'file', 'instructions', 'signature', 'location', 'datagrid'].includes(component.name) && (jsxRuntime.jsx(ComponentActionFeatures, { component: component, mode: "test", formTemplateId: formTemplateId, formValue: formValue, formData: formData, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange ? (notes) => onNotesChange(component.id, notes) : undefined, onAttachmentChange: onAttachmentChange ? (attachments) => onAttachmentChange(component.id, attachments) : undefined, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue })), hasSubmissionData && (jsxRuntime.jsx(ComponentSubmissionActions, { component: component }))] }));
7529
7527
  };
7530
7528
  const DraggableTableComponent = ({ component, selectedComponent, mode, onComponentSelect, onComponentDelete, onComponentEdit, renderFormComponent, isOverlay = false, }) => {
7531
7529
  const { attributes, listeners, setNodeRef, transform, transition, isDragging, isSorting, } = sortable.useSortable({
@@ -7546,7 +7544,7 @@ const DraggableTableComponent = ({ component, selectedComponent, mode, onCompone
7546
7544
  onComponentDelete(component, e);
7547
7545
  }, type: "button", title: "Delete Component", children: jsxRuntime.jsx(lucideReact.Trash2, { size: 12 }) })] }))] }));
7548
7546
  };
7549
- const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, tableId, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue, shouldShowComponent }) => {
7547
+ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formData = {}, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, tableId, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
7550
7548
  const dropZoneId = `table-cell-${tableId}-${cell.row}-${cell.column}`;
7551
7549
  const { setNodeRef, isOver } = core.useDroppable({
7552
7550
  id: dropZoneId,
@@ -7581,7 +7579,7 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
7581
7579
  cell.components.map((component) => {
7582
7580
  // Only ensure ID if it's truly missing - don't regenerate existing IDs
7583
7581
  const componentWithId = component.id ? component : ensureComponentHasId(component);
7584
- return (jsxRuntime.jsx(SimpleTableComponent, { component: componentWithId, mode: mode, renderFormComponent: renderFormComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue, shouldShowComponent: shouldShowComponent }, componentWithId.id));
7582
+ return (jsxRuntime.jsx(SimpleTableComponent, { component: componentWithId, mode: mode, renderFormComponent: renderFormComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, componentWithId.id));
7585
7583
  }))) : (
7586
7584
  // Only show drop zone content in edit mode
7587
7585
  mode === 'edit' ? (jsxRuntime.jsx("div", { className: "empty-cell-placeholder", children: jsxRuntime.jsxs("div", { className: "cell-info", children: [jsxRuntime.jsx("span", { className: "drop-zone-text", children: "Drag and Drop a form component" }), jsxRuntime.jsxs("span", { className: "cell-coordinates", children: ["Cell (", cell.row + 1, ", ", cell.column + 1, ")"] })] }) })) : (
@@ -7592,17 +7590,22 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
7592
7590
  visibility: 'hidden' // Hide content but maintain space
7593
7591
  }, children: "\u00A0" }))) }) }));
7594
7592
  };
7595
- const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationErrors = {}, touchedFields = {}, formSubmitted = false, onValueChange, onSelect, isSelected = false, className = '', onTableSelect, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue, shouldShowComponent }) => {
7596
- const [isCollapsed, setIsCollapsed] = React.useState(false);
7597
- // Initialize and update table cells when rows/columns change (matching main website)
7593
+ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationErrors = {}, touchedFields = {}, formSubmitted = false, onValueChange, onSelect, isSelected = false, className = '', onTableSelect, onComponentSelect, onComponentDelete, onComponentEdit, selectedComponent, renderFormComponent, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, workOrderNumber, assetNumber, user, onCreateIssue, onUpdateIssue }) => {
7594
+ const [isCollapsed, setIsCollapsed] = React.useState(false); // Always start expanded to show drop zones
7595
+ // Check if table has any components in any cells
7596
+ const hasAnyComponents = properties.cells?.some(row => row.some(cell => cell.components && cell.components.length > 0)) || false;
7597
+ // Initialize and update table cells when rows/columns change
7598
+ // Only trigger when cells are truly missing or structure doesn't match rows/columns
7598
7599
  React.useEffect(() => {
7600
+ // Get rows and columns from table properties (where they're actually stored)
7599
7601
  const currentRows = Number(properties.table?.rows || properties.basic?.rows || 3);
7600
7602
  const currentColumns = Number(properties.table?.columns || properties.basic?.columns || 3);
7601
7603
  const currentCells = properties.cells || [];
7602
7604
  // Check if we need to update the table structure
7605
+ // Only update if cells are empty or row/column count doesn't match
7603
7606
  const needsUpdate = currentCells.length === 0 ||
7604
7607
  currentCells.length !== currentRows ||
7605
- (currentCells.length > 0 && Array.isArray(currentCells[0]) && currentCells[0].length !== currentColumns);
7608
+ (currentCells.length > 0 && currentCells[0].length !== currentColumns);
7606
7609
  if (needsUpdate) {
7607
7610
  const newCells = [];
7608
7611
  for (let row = 0; row < currentRows; row++) {
@@ -7611,7 +7614,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7611
7614
  const cellId = `cell-${row}-${col}`;
7612
7615
  // Try to preserve existing components if the cell exists
7613
7616
  let existingComponents = [];
7614
- if (currentCells[row] && Array.isArray(currentCells[row]) && currentCells[row][col]) {
7617
+ if (currentCells[row] && currentCells[row][col]) {
7615
7618
  existingComponents = (currentCells[row][col].components || []).map(ensureComponentHasId);
7616
7619
  }
7617
7620
  rowCells.push({
@@ -7624,23 +7627,12 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7624
7627
  }
7625
7628
  newCells.push(rowCells);
7626
7629
  }
7627
- if (onValueChange) {
7628
- onValueChange({
7629
- id,
7630
- value: { ...properties, cells: newCells }
7631
- });
7632
- }
7630
+ onValueChange?.({
7631
+ id,
7632
+ value: { ...properties, cells: newCells }
7633
+ });
7633
7634
  }
7634
- }, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns, properties.cells, id, onValueChange]);
7635
- // Check if table has any components in any cells
7636
- const hasAnyComponents = properties.cells?.some((row) => {
7637
- if (Array.isArray(row)) {
7638
- return row.some((cell) => cell && cell.components && cell.components.length > 0);
7639
- }
7640
- // Handle flat 1D cell
7641
- const cell = row;
7642
- return cell && cell.components && cell.components.length > 0;
7643
- }) || false;
7635
+ }, [properties.table?.rows, properties.table?.columns, properties.basic?.rows, properties.basic?.columns, properties.cells?.length, id, onValueChange]); // Watch rows/columns changes and cells length for initial init
7644
7636
  const handleTableClick = React.useCallback((event) => {
7645
7637
  event.stopPropagation();
7646
7638
  onSelect?.();
@@ -7656,68 +7648,66 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7656
7648
  };
7657
7649
  const handleComponentDelete = React.useCallback((component, event) => {
7658
7650
  event.stopPropagation();
7659
- const updatedCells = properties.cells.map((row) => {
7660
- if (Array.isArray(row)) {
7661
- return row.map((cell) => {
7662
- if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
7663
- return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
7664
- }
7665
- return cell;
7666
- });
7667
- }
7668
- // Handle flat 1D cell
7669
- const cell = row;
7670
- if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
7671
- return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
7651
+ // Find and remove the component from the table cell
7652
+ const updatedCells = properties.cells.map(row => row.map(cell => {
7653
+ if (cell.components && cell.components.some(comp => comp.id === component.id)) {
7654
+ const filteredComponents = cell.components.filter(comp => comp.id !== component.id);
7655
+ return {
7656
+ ...cell,
7657
+ components: filteredComponents
7658
+ };
7672
7659
  }
7673
7660
  return cell;
7674
- });
7675
- onValueChange?.({ id, value: { ...properties, cells: updatedCells } });
7676
- }, [onComponentDelete, properties, onValueChange, id]);
7677
- // Ensure all table cell components have IDs (matching website ensureTableCellComponentsHaveIds)
7678
- const ensureCellComponentIds = (cell) => ({
7679
- ...cell,
7680
- components: (cell?.components || []).map((comp) => {
7681
- if (!comp.id || comp.id.trim() === '') {
7682
- return { ...comp, id: `table-cell-${comp.name}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}` };
7683
- }
7684
- return comp;
7685
- })
7686
- });
7687
- const ensureTableCellComponentsHaveIds = (cells) => {
7688
- return cells.map((row) => {
7689
- if (Array.isArray(row)) {
7690
- return row.map(ensureCellComponentIds);
7691
- }
7692
- // Handle flat 1D cell
7693
- return ensureCellComponentIds(row);
7694
- });
7695
- };
7696
- const cellsWithIds = properties.cells && properties.cells.length > 0
7697
- ? ensureTableCellComponentsHaveIds(properties.cells)
7698
- : [];
7699
- // CRITICAL FIX: Update the parent component with the cells that have proper IDs (matching main website)
7700
- React.useEffect(() => {
7701
- if (cellsWithIds.length > 0 && JSON.stringify(cellsWithIds) !== JSON.stringify(properties.cells)) {
7702
- onValueChange?.({
7703
- id: id,
7704
- value: {
7705
- ...properties,
7706
- cells: cellsWithIds
7707
- }
7661
+ }));
7662
+ // Update the table with the modified cells
7663
+ if (onValueChange) {
7664
+ onValueChange({
7665
+ id,
7666
+ value: { ...properties, cells: updatedCells }
7708
7667
  });
7709
7668
  }
7710
- }, [cellsWithIds, properties.cells, id, onValueChange]);
7711
- // CRITICAL: Create a stable renderComponent that doesn't recreate on every render
7712
- // Match main app implementation - directly access formData from closure
7713
- const renderComponent = renderFormComponent || React.useCallback((field) => {
7669
+ // Don't call parent delete handler for table cell components
7670
+ // The parent delete handler is for deleting entire fields, not components within table cells
7671
+ }, [onComponentDelete, properties, onValueChange, id]);
7672
+ // CRITICAL FIX: Ensure all table cell components have proper IDs with table and cell position
7673
+ // Use useMemo to prevent ID regeneration on every render
7674
+ const cellsWithIds = React.useMemo(() => {
7675
+ if (!properties.cells)
7676
+ return [];
7677
+ return properties.cells.map((row, rowIndex) => row.map((cell, cellIndex) => ({
7678
+ ...cell,
7679
+ components: (cell.components && Array.isArray(cell.components))
7680
+ ? cell.components.map((comp, compIndex) => {
7681
+ // CRITICAL: Only generate ID if it's missing - never regenerate existing IDs
7682
+ // This prevents component remounting and losing input state
7683
+ if (comp.id && typeof comp.id === 'string' && comp.id.trim() !== '') {
7684
+ // ID already exists - keep it as is
7685
+ return comp;
7686
+ }
7687
+ // Generate unique ID that includes table ID, row, cell, and component index
7688
+ // This ensures no conflicts with other components
7689
+ const uniqueId = `${comp.name || 'component'}-table-${id}-row-${rowIndex}-cell-${cellIndex}-comp-${compIndex}`;
7690
+ return {
7691
+ ...comp,
7692
+ id: uniqueId
7693
+ };
7694
+ })
7695
+ : []
7696
+ })));
7697
+ }, [properties.cells, id]); // Only recalculate if cells or table ID changes
7698
+ // CRITICAL FIX: Update the parent component with the cells that have proper IDs
7699
+ // Skip this in package to prevent flickering - cells are managed by parent
7700
+ // useEffect(() => {
7701
+ // // Disabled to prevent flickering when user types
7702
+ // }, [])
7703
+ // Fallback renderer for when no renderFormComponent is provided by parent
7704
+ // Always defined to avoid conditional hook calls (React hooks rule)
7705
+ const fallbackRenderComponent = React.useCallback((field) => {
7714
7706
  // CRITICAL: Only ensure ID if it's missing - don't regenerate existing IDs
7715
- // This prevents component remounting and losing input state
7716
7707
  const componentWithId = field.id ? field : ensureComponentHasId(field);
7717
7708
  // Get form value - directly access formData from closure (matches main app)
7718
7709
  const formValue = formData[componentWithId.id] || ('defaultValue' in componentWithId.basic ? componentWithId.basic.defaultValue || '' : '');
7719
7710
  // CRITICAL: Ensure formValue is always a string for number inputs
7720
- // This prevents validation errors when formValue is a number type
7721
7711
  let normalizedFormValue = formValue;
7722
7712
  if (componentWithId.name === 'number-input' && typeof formValue === 'number') {
7723
7713
  normalizedFormValue = String(formValue);
@@ -7749,21 +7739,18 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7749
7739
  case 'textarea':
7750
7740
  return jsxRuntime.jsx(DfFormTextarea, { ...commonProps, properties: componentWithId, readonly: false, disabled: false });
7751
7741
  case 'select':
7752
- // Map basic.options to top-level options for select component
7753
7742
  const selectProps = {
7754
7743
  ...componentWithId,
7755
7744
  options: componentWithId.basic?.options || []
7756
7745
  };
7757
7746
  return jsxRuntime.jsx(DfFormSelect, { ...commonProps, properties: selectProps, disabled: false });
7758
7747
  case 'checkbox':
7759
- // Map basic.options to top-level options for checkbox component
7760
7748
  const checkboxProps = {
7761
7749
  ...componentWithId,
7762
7750
  options: componentWithId.basic?.options || []
7763
7751
  };
7764
7752
  return jsxRuntime.jsx(DfFormCheckbox, { ...commonProps, properties: checkboxProps, formValue: [], disabled: false });
7765
7753
  case 'radio':
7766
- // Map basic.options to top-level options for radio component
7767
7754
  const radioProps = {
7768
7755
  ...componentWithId,
7769
7756
  options: componentWithId.basic?.options || []
@@ -7785,7 +7772,6 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7785
7772
  case 'datagrid':
7786
7773
  return (jsxRuntime.jsx(DfFormDataGrid, { ...commonProps, properties: componentWithId, formData: formData, mode: mode, onNotesChange: () => { }, onAttachmentChange: () => { } }));
7787
7774
  case 'segment':
7788
- // Map basic.options for segment
7789
7775
  const segmentProps = {
7790
7776
  ...componentWithId,
7791
7777
  options: componentWithId.basic?.options || []
@@ -7794,7 +7780,9 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7794
7780
  default:
7795
7781
  return jsxRuntime.jsxs("div", { className: "unknown-component", children: ["Unknown component: ", componentWithId.name] });
7796
7782
  }
7797
- }, [renderFormComponent, mode, formData, onValueChange]); // Include renderFormComponent, formData and onValueChange to ensure latest values are used
7783
+ }, [mode, formData, onValueChange]);
7784
+ // Use parent-provided renderFormComponent if available, otherwise use fallback
7785
+ const renderComponent = renderFormComponent || fallbackRenderComponent;
7798
7786
  const tableStyle = {
7799
7787
  backgroundColor: properties.styles?.backgroundColor || 'var(--df-color-fb-container)',
7800
7788
  borderColor: properties.styles?.borderColor || 'var(--df-color-fb-border)',
@@ -7815,22 +7803,22 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7815
7803
  if (!hasAnyComponents && mode === 'preview') {
7816
7804
  return null;
7817
7805
  }
7818
- return (jsxRuntime.jsxs("div", { className: `form-group df-form-table ${isSelected ? 'selected' : ''} ${mode === 'preview' ? 'preview-mode' : mode === 'test' ? 'test-mode' : ''} ${className}`, onClick: handleTableClick, style: tableStyle, children: [jsxRuntime.jsx("div", { className: "table-header", children: jsxRuntime.jsx("div", { className: "table-title", onClick: toggleCollapse, children: jsxRuntime.jsxs("div", { className: "title-content", children: [isCollapsed ? jsxRuntime.jsx(lucideReact.ChevronRight, { size: 16 }) : jsxRuntime.jsx(lucideReact.ChevronDown, { size: 16 }), jsxRuntime.jsx(lucideReact.Table, { size: 16 }), jsxRuntime.jsx("span", { className: "table-label", children: properties.basic?.label || 'Table' }), properties.validation?.required && (jsxRuntime.jsx("span", { className: "required-indicator", children: "*" }))] }) }) }), properties.basic?.description && !isCollapsed && (jsxRuntime.jsx("div", { className: "table-description", children: properties.basic.description })), !isCollapsed && (jsxRuntime.jsx("div", { className: "table-content", children: jsxRuntime.jsxs("table", { style: tableElementStyle, children: [properties.table?.displayAsTable && (mode === 'edit' || properties.table?.showColumns) && (jsxRuntime.jsx("thead", { children: jsxRuntime.jsx("tr", { className: "table-header-row", children: Array.from({ length: properties.table?.columns || properties.basic?.columns || 3 }, (_, colIndex) => {
7819
- const columnNames = properties.table?.columnNames?.split(',').map((name) => name.trim()) || [];
7820
- const columnName = columnNames[colIndex] || `Column ${colIndex + 1}`;
7821
- return (jsxRuntime.jsx("th", { className: "table-header-cell", style: {
7822
- backgroundColor: 'var(--df-color-fb-container)',
7823
- color: properties.styles.headerTextColor || 'var(--df-color-text-dark)',
7824
- padding: '12px',
7825
- border: '1px solid var(--df-color-fb-border)',
7826
- fontWeight: '600',
7827
- fontSize: '14px',
7828
- textAlign: 'center'
7829
- }, children: columnName }, `header-${colIndex}`));
7830
- }) }) })), jsxRuntime.jsx("tbody", { children: cellsWithIds.map((row, rowIndex) => {
7831
- const rowCells = Array.isArray(row) ? row : [row];
7832
- return (jsxRuntime.jsx("tr", { className: "table-row", children: rowCells.map((cell) => (jsxRuntime.jsx(TableCellComponent, { cell: cell, mode: mode, onComponentSelect: onComponentSelect || (() => { }), onComponentDelete: handleComponentDelete, onComponentEdit: onComponentEdit, selectedComponent: selectedComponent || null, renderFormComponent: renderComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, tableId: id, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue, shouldShowComponent: shouldShowComponent }, cell.id))) }, rowIndex));
7833
- }) })] }) }))] }));
7806
+ return (jsxRuntime.jsxs("div", { className: `form-group df-form-table ${isSelected ? 'selected' : ''} ${mode === 'preview' ? 'preview-mode' : mode === 'test' ? 'test-mode' : ''} ${className}`, onClick: handleTableClick, style: tableStyle, children: [jsxRuntime.jsx("div", { className: "table-header", children: jsxRuntime.jsx("div", { className: "table-title", onClick: toggleCollapse, children: jsxRuntime.jsxs("div", { className: "title-content", children: [isCollapsed ? jsxRuntime.jsx(lucideReact.ChevronRight, { size: 16 }) : jsxRuntime.jsx(lucideReact.ChevronDown, { size: 16 }), jsxRuntime.jsx(lucideReact.Table, { size: 16 }), jsxRuntime.jsx("span", { className: "table-label", children: properties.basic?.label || 'Table' }), properties.validation?.required && (jsxRuntime.jsx("span", { className: "required-indicator", children: "*" }))] }) }) }), properties.basic?.description && !isCollapsed && (jsxRuntime.jsx("div", { className: "table-description", children: properties.basic.description })), !isCollapsed && (jsxRuntime.jsxs("div", { className: "table-content", children: [(() => {
7807
+ return null;
7808
+ })(), jsxRuntime.jsxs("table", { style: tableElementStyle, children: [properties.table?.displayAsTable && (mode === 'edit' || properties.table?.showColumns) && (jsxRuntime.jsx("thead", { children: jsxRuntime.jsx("tr", { className: "table-header-row", children: Array.from({ length: properties.table?.columns || properties.basic?.columns || 3 }, (_, colIndex) => {
7809
+ // Parse column names from the comma-separated string
7810
+ const columnNames = properties.table?.columnNames?.split(',').map(name => name.trim()) || [];
7811
+ const columnName = columnNames[colIndex] || `Column ${colIndex + 1}`;
7812
+ return (jsxRuntime.jsx("th", { className: "table-header-cell", style: {
7813
+ backgroundColor: properties.styles.headerBackgroundColor || (mode === 'preview' || mode === 'test') ? 'var(--df-color-fb-container)' : 'var(--df-color-fb-container)',
7814
+ color: properties.styles.headerTextColor || 'var(--df-color-text-dark)',
7815
+ padding: '12px',
7816
+ border: (mode === 'preview' || mode === 'test') ? '1px solid var(--df-color-fb-border)' : '1px solid var(--df-color-fb-border)',
7817
+ fontWeight: '600',
7818
+ fontSize: '14px',
7819
+ textAlign: 'center'
7820
+ }, children: columnName }, `header-${colIndex}`));
7821
+ }) }) })), jsxRuntime.jsx("tbody", { children: cellsWithIds.map((row, rowIndex) => (jsxRuntime.jsx("tr", { className: "table-row", children: row.map((cell) => (jsxRuntime.jsx(TableCellComponent, { cell: cell, mode: mode, onComponentSelect: onComponentSelect || (() => { }), onComponentDelete: handleComponentDelete, onComponentEdit: onComponentEdit, selectedComponent: selectedComponent || null, renderFormComponent: renderComponent, formData: formData, formTemplateId: formTemplateId, onThresholdActionCompletion: onThresholdActionCompletion, onThresholdIssueRaised: onThresholdIssueRaised, tableId: id, onNotesChange: onNotesChange, onAttachmentChange: onAttachmentChange, workOrderNumber: workOrderNumber, assetNumber: assetNumber, user: user, onCreateIssue: onCreateIssue, onUpdateIssue: onUpdateIssue }, cell.id))) }, rowIndex))) })] })] }))] }));
7834
7822
  };
7835
7823
 
7836
7824
  var dfFormTable = /*#__PURE__*/Object.freeze({