df-ae-forms-package 1.0.81 → 1.0.82

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
@@ -5971,9 +5971,47 @@ const DfFormSection = ({ id, properties, mode = 'edit', formData = {}, onValueCh
5971
5971
 
5972
5972
  // Dynamic imports to avoid circular dependencies
5973
5973
  const DfFormTable$1 = React.lazy(() => Promise.resolve().then(function () { return dfFormTable; }));
5974
- const DfFormPreview = ({ formComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
5974
+ const DfFormPreview = ({ formComponents: rawFormComponents = [], currentDevice = 'desktop', isPreviewMode = false, initialFormData = [], onSubmit, onFormDataChange, formTitle, formDescription, formTemplateId,
5975
5975
  // Add component management props for edit mode
5976
5976
  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]);
5977
6015
  // Form state
5978
6016
  const [formValues, setFormValues] = React.useState({});
5979
6017
  const [validationErrors, setValidationErrors] = React.useState({});
@@ -6074,7 +6112,6 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6074
6112
  const initialValues = {};
6075
6113
  const initialNotes = {};
6076
6114
  const initialAttachments = {};
6077
- const seenIds = new Set();
6078
6115
  // Helper to extract notes and attachments recursively
6079
6116
  const extractNotesAndAttachments = (components) => {
6080
6117
  components.forEach(comp => {
@@ -6111,76 +6148,16 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6111
6148
  });
6112
6149
  });
6113
6150
  };
6114
- // Validate component IDs for uniqueness without mutating original props
6115
- const getValidatedComponents = (components) => {
6116
- return components.map((component, index) => {
6117
- let validatedComponent = { ...component };
6118
- // Ensure component has an ID
6119
- if (!validatedComponent.id || typeof validatedComponent.id !== 'string' || validatedComponent.id.trim() === '') {
6120
- // Determine a base name for the ID
6121
- const name = validatedComponent.name || 'component';
6122
- const label = validatedComponent.basic?.label || '';
6123
- const safeLabel = label.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().substring(0, 10);
6124
- // Generate a unique ID
6125
- validatedComponent.id = `${name}-${safeLabel || 'gen'}-${Date.now()}-${Math.random().toString(36).substr(2, 6)}-${index}`;
6126
- console.warn(`[DfFormPreview] Assigned missing ID: ${validatedComponent.id}`);
6127
- }
6128
- else {
6129
- // Check for duplicates
6130
- if (seenIds.has(validatedComponent.id)) {
6131
- console.error(`[DfFormPreview] Duplicate component ID detected: ${validatedComponent.id}`);
6132
- // Generate a unique ID for duplicate
6133
- validatedComponent.id = `${validatedComponent.id}-duplicate-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
6134
- console.warn(`[DfFormPreview] Generated new unique ID: ${validatedComponent.id}`);
6135
- }
6136
- }
6137
- seenIds.add(validatedComponent.id);
6138
- // Recursively validate nested components
6139
- if (validatedComponent.children && Array.isArray(validatedComponent.children)) {
6140
- validatedComponent.children = getValidatedComponents(validatedComponent.children);
6141
- }
6142
- if (validatedComponent.cells && Array.isArray(validatedComponent.cells)) {
6143
- validatedComponent.cells = validatedComponent.cells.map((row) => row.map((cell) => ({
6144
- ...cell,
6145
- components: cell.components ? getValidatedComponents(cell.components) : []
6146
- })));
6147
- }
6148
- if (validatedComponent.entries && Array.isArray(validatedComponent.entries)) {
6149
- validatedComponent.entries = validatedComponent.entries.map((entry) => {
6150
- if (entry && entry.components && Array.isArray(entry.components)) {
6151
- return {
6152
- ...entry,
6153
- components: getValidatedComponents(entry.components)
6154
- };
6155
- }
6156
- return entry;
6157
- });
6158
- }
6159
- return validatedComponent;
6160
- });
6161
- };
6162
- // Initialize validated components
6163
- let validatedFormComponents = formComponents;
6164
- if (formComponents && formComponents.length > 0) {
6165
- validatedFormComponents = getValidatedComponents(formComponents);
6166
- // Notifying parent of changed components if they were mutated (IDs added/fixed)
6167
- if (JSON.stringify(validatedFormComponents) !== JSON.stringify(formComponents)) {
6168
- onFormDataChange?.(validatedFormComponents);
6169
- }
6170
- }
6171
- let validatedInitialFormData = initialFormData;
6172
- if (initialFormData && initialFormData.length > 0) {
6173
- validatedInitialFormData = getValidatedComponents(initialFormData);
6174
- }
6151
+ // IDs are already ensured by the useMemo at the top - no need for getValidatedComponents
6175
6152
  // Initialize form values from initial data
6176
- if (validatedInitialFormData && validatedInitialFormData.length > 0) {
6177
- initializeComponentValues(validatedInitialFormData, initialValues);
6153
+ if (initialFormData && initialFormData.length > 0) {
6154
+ initializeComponentValues(initialFormData, initialValues);
6178
6155
  }
6179
6156
  // Initialize form values from form components (for submitted data or pre-filled forms)
6180
6157
  // CRITICAL: This must run AFTER initialFormData to pick up any values embedded in the components themselves
6181
- if (validatedFormComponents && validatedFormComponents.length > 0) {
6182
- initializeComponentValues(validatedFormComponents, initialValues);
6183
- extractNotesAndAttachments(validatedFormComponents);
6158
+ if (formComponents && formComponents.length > 0) {
6159
+ initializeComponentValues(formComponents, initialValues);
6160
+ extractNotesAndAttachments(formComponents);
6184
6161
  }
6185
6162
  // Set the state
6186
6163
  setFormValues(prev => {
@@ -6228,11 +6205,18 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6228
6205
  component.cells.forEach((row) => {
6229
6206
  if (Array.isArray(row)) {
6230
6207
  row.forEach((cell) => {
6231
- if (cell.components && Array.isArray(cell.components)) {
6208
+ if (cell && cell.components && Array.isArray(cell.components)) {
6232
6209
  evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6233
6210
  }
6234
6211
  });
6235
6212
  }
6213
+ else {
6214
+ // Handle flat 1D cell
6215
+ const cell = row;
6216
+ if (cell && cell.components && Array.isArray(cell.components)) {
6217
+ evaluateComponentConditionalLogic(cell.components, visibility, currentFormValues, fullSchema);
6218
+ }
6219
+ }
6236
6220
  });
6237
6221
  }
6238
6222
  // Handle nested components in datagrid entries
@@ -6356,13 +6340,24 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6356
6340
  if (component.name === 'table' && component.cells) {
6357
6341
  return {
6358
6342
  ...component,
6359
- cells: component.cells.map((row) => row.map((cell) => {
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
6355
  const updatedCell = { ...cell };
6361
6356
  if (updatedCell.components) {
6362
6357
  updatedCell.components = updateComponentValue(updatedCell.components);
6363
6358
  }
6364
6359
  return updatedCell;
6365
- }))
6360
+ })
6366
6361
  };
6367
6362
  }
6368
6363
  if (component.name === 'datagrid' && component.entries) {
@@ -6434,8 +6429,19 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
6434
6429
  // Check nested components in table cells
6435
6430
  if (comp.name === 'table' && comp.cells) {
6436
6431
  for (const row of comp.cells) {
6437
- for (const cell of row) {
6438
- if (cell.components) {
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) {
6439
6445
  const found = findComponentById(cell.components, fieldId);
6440
6446
  if (found)
6441
6447
  return found;
@@ -7164,7 +7170,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
7164
7170
  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) => {
7165
7171
  const updatedComponents = formComponents.map(comp => {
7166
7172
  if (comp.id === component.id && comp.cells) {
7167
- const updatedCells = comp.cells.map((row) => row.map((cell) => {
7173
+ const updateCell = (cell) => {
7168
7174
  if (cell.components) {
7169
7175
  return {
7170
7176
  ...cell,
@@ -7174,7 +7180,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
7174
7180
  };
7175
7181
  }
7176
7182
  return cell;
7177
- }));
7183
+ };
7184
+ const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
7178
7185
  return { ...comp, cells: updatedCells };
7179
7186
  }
7180
7187
  return comp;
@@ -7183,7 +7190,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
7183
7190
  }, onAttachmentChange: (componentId, attachments) => {
7184
7191
  const updatedComponents = formComponents.map(comp => {
7185
7192
  if (comp.id === component.id && comp.cells) {
7186
- const updatedCells = comp.cells.map((row) => row.map((cell) => {
7193
+ const updateCell = (cell) => {
7187
7194
  if (cell.components) {
7188
7195
  return {
7189
7196
  ...cell,
@@ -7193,7 +7200,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
7193
7200
  };
7194
7201
  }
7195
7202
  return cell;
7196
- }));
7203
+ };
7204
+ const updatedCells = comp.cells.map((row) => Array.isArray(row) ? row.map(updateCell) : updateCell(row));
7197
7205
  return { ...comp, cells: updatedCells };
7198
7206
  }
7199
7207
  return comp;
@@ -7586,11 +7594,17 @@ const TableCellComponent = ({ cell, mode, onComponentSelect, onComponentDelete,
7586
7594
  };
7587
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 }) => {
7588
7596
  const [isCollapsed, setIsCollapsed] = React.useState(false);
7589
- // By the time cells arrive here, DfFormPreview.getValidatedComponents has already
7590
- // normalized them from 1D flat (API format) to proper 2D arrays.
7591
- // So we can use properties.cells directly, exactly like the website version.
7597
+ // Cells may be 2D (row arrays) or 1D (flat cells) depending on API format.
7598
+ // The useMemo in DfFormPreview ensures IDs, but structure may still vary.
7592
7599
  // Check if table has any components in any cells
7593
- const hasAnyComponents = properties.cells?.some((row) => Array.isArray(row) && row.some((cell) => cell && cell.components && cell.components.length > 0)) || false;
7600
+ const hasAnyComponents = properties.cells?.some((row) => {
7601
+ if (Array.isArray(row)) {
7602
+ return row.some((cell) => cell && cell.components && cell.components.length > 0);
7603
+ }
7604
+ // Handle flat 1D cell
7605
+ const cell = row;
7606
+ return cell && cell.components && cell.components.length > 0;
7607
+ }) || false;
7594
7608
  const handleTableClick = React.useCallback((event) => {
7595
7609
  event.stopPropagation();
7596
7610
  onSelect?.();
@@ -7606,25 +7620,42 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7606
7620
  };
7607
7621
  const handleComponentDelete = React.useCallback((component, event) => {
7608
7622
  event.stopPropagation();
7609
- const updatedCells = properties.cells.map((row) => row.map((cell) => {
7623
+ const updatedCells = properties.cells.map((row) => {
7624
+ if (Array.isArray(row)) {
7625
+ return row.map((cell) => {
7626
+ if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
7627
+ return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
7628
+ }
7629
+ return cell;
7630
+ });
7631
+ }
7632
+ // Handle flat 1D cell
7633
+ const cell = row;
7610
7634
  if (cell && cell.components && cell.components.some((comp) => comp.id === component.id)) {
7611
7635
  return { ...cell, components: cell.components.filter((comp) => comp.id !== component.id) };
7612
7636
  }
7613
7637
  return cell;
7614
- }));
7638
+ });
7615
7639
  onValueChange?.({ id, value: { ...properties, cells: updatedCells } });
7616
7640
  }, [onComponentDelete, properties, onValueChange, id]);
7617
7641
  // Ensure all table cell components have IDs (matching website ensureTableCellComponentsHaveIds)
7642
+ const ensureCellComponentIds = (cell) => ({
7643
+ ...cell,
7644
+ components: (cell?.components || []).map((comp) => {
7645
+ if (!comp.id || comp.id.trim() === '') {
7646
+ return { ...comp, id: `table-cell-${comp.name}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}` };
7647
+ }
7648
+ return comp;
7649
+ })
7650
+ });
7618
7651
  const ensureTableCellComponentsHaveIds = (cells) => {
7619
- return cells.map((row) => (Array.isArray(row) ? row : []).map((cell) => ({
7620
- ...cell,
7621
- components: (cell?.components || []).map((comp) => {
7622
- if (!comp.id || comp.id.trim() === '') {
7623
- return { ...comp, id: `table-cell-${comp.name}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}` };
7624
- }
7625
- return comp;
7626
- })
7627
- })));
7652
+ return cells.map((row) => {
7653
+ if (Array.isArray(row)) {
7654
+ return row.map(ensureCellComponentIds);
7655
+ }
7656
+ // Handle flat 1D cell
7657
+ return ensureCellComponentIds(row);
7658
+ });
7628
7659
  };
7629
7660
  const cellsWithIds = properties.cells && properties.cells.length > 0
7630
7661
  ? ensureTableCellComponentsHaveIds(properties.cells)
@@ -7756,7 +7787,7 @@ const DfFormTable = ({ id, properties, mode = 'edit', formData = {}, validationE
7756
7787
  fontSize: '14px',
7757
7788
  textAlign: 'center'
7758
7789
  }, children: columnName }, `header-${colIndex}`));
7759
- }) }) })), jsxRuntime.jsx("tbody", { children: cellsWithIds.filter(row => Array.isArray(row) && row.length > 0).map((row, rowIndex) => (jsxRuntime.jsx("tr", { className: "table-row", children: row.filter(cell => cell != null).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))) })] })] }))] }));
7790
+ }) }) })), jsxRuntime.jsx("tbody", { children: cellsWithIds.filter((row) => Array.isArray(row) && row.length > 0).map((row, rowIndex) => (jsxRuntime.jsx("tr", { className: "table-row", children: row.filter((cell) => cell != null).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))) })] })] }))] }));
7760
7791
  };
7761
7792
 
7762
7793
  var dfFormTable = /*#__PURE__*/Object.freeze({