lightning-base-components 1.21.2-alpha → 1.21.3-alpha

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.
Files changed (222) hide show
  1. package/metadata/raptor.json +28 -1
  2. package/package.json +28 -2
  3. package/scopedImports/@salesforce-label-LightningRichTextEditor.colorPicker.js +1 -0
  4. package/src/lightning/accordion/accordion-section.slds.css +3 -3
  5. package/src/lightning/accordion/accordion.slds.css +1 -2
  6. package/src/lightning/accordionSection/accordion-section.slds.css +3 -3
  7. package/src/lightning/accordionSection/accordionSection.js +3 -1
  8. package/src/lightning/accordionSection/button.slds.css +1 -1
  9. package/src/lightning/badge/badge.js +1 -0
  10. package/src/lightning/badge/badge.js-meta.xml +3 -0
  11. package/src/lightning/baseCombobox/base-combobox.slds.css +11 -6
  12. package/src/lightning/baseCombobox/baseCombobox.html +1 -1
  13. package/src/lightning/baseCombobox/baseCombobox.js +2 -2
  14. package/src/lightning/baseCombobox/baseCombobox.js-meta.xml +6 -0
  15. package/src/lightning/baseCombobox/input-text.slds.css +41 -68
  16. package/src/lightning/baseCombobox/keyboard.js +12 -4
  17. package/src/lightning/baseCombobox/listbox.slds.css +51 -99
  18. package/src/lightning/baseCombobox/spinner.slds.css +62 -62
  19. package/src/lightning/baseComboboxFormattedText/baseComboboxFormattedText.js-meta.xml +6 -0
  20. package/src/lightning/baseComboboxItem/baseComboboxItem.js +10 -6
  21. package/src/lightning/baseComboboxItem/baseComboboxItem.js-meta.xml +6 -0
  22. package/src/lightning/baseComboboxItem/listbox.slds.css +51 -99
  23. package/src/lightning/baseFormattedText/baseFormattedText.js +2 -2
  24. package/src/lightning/button/button.js +2 -1
  25. package/src/lightning/button/button.slds.css +1 -1
  26. package/src/lightning/buttonIcon/button-icon.slds.css +1 -1
  27. package/src/lightning/buttonIconStateful/button-icon-stateful.slds.css +4 -2
  28. package/src/lightning/buttonIconStateful/button-icon.slds.css +1 -1
  29. package/src/lightning/buttonIconStateful/button.slds.css +1 -1
  30. package/src/lightning/buttonMenu/button-icon.slds.css +1 -1
  31. package/src/lightning/buttonMenu/button-menu.slds.css +8 -2
  32. package/src/lightning/buttonMenu/button.slds.css +1 -1
  33. package/src/lightning/buttonStateful/button-stateful.slds.css +6 -2
  34. package/src/lightning/buttonStateful/button.slds.css +1 -1
  35. package/src/lightning/buttonStateful/buttonStateful.js +4 -1
  36. package/src/lightning/calendar/calendar.js-meta.xml +6 -0
  37. package/src/lightning/calendar/calendar.slds.css +9 -2
  38. package/src/lightning/colorPickerCustom/color-picker-custom.slds.css +22 -23
  39. package/src/lightning/colorPickerCustom/input-text.slds.css +41 -68
  40. package/src/lightning/colorPickerPanel/color-picker-panel.slds.css +9 -10
  41. package/src/lightning/colorPickerPanel/popover.slds.css +0 -2
  42. package/src/lightning/combobox/combobox.slds.css +1 -2
  43. package/src/lightning/combobox/form-element.slds.css +54 -54
  44. package/src/lightning/datatable/__examples__/customDatatableWrapper/customDatatableWrapper.js +0 -69
  45. package/src/lightning/datatable/__examples__/customDatatypeDeleteRowBtn/customDatatypeDeleteRowBtn.html +1 -1
  46. package/src/lightning/datatable/__examples__/customDatatypeDeleteRowBtn/customDatatypeDeleteRowBtn.js +1 -16
  47. package/src/lightning/datatable/__examples__/customDatatypeLink/customDatatypeLink.html +3 -3
  48. package/src/lightning/datatable/__examples__/customDatatypeRowOrderingBtn/customDatatypeRowOrderingBtn.html +1 -8
  49. package/src/lightning/datatable/__examples__/customDatatypeRowOrderingBtn/customDatatypeRowOrderingBtn.js +2 -39
  50. package/src/lightning/datatable/__examples__/customDatatypeTable/customNumber.html +1 -1
  51. package/src/lightning/datatable/__examples__/customDatatypeTable/customNumberEdit.html +2 -0
  52. package/src/lightning/datatable/__examples__/customDatatypeTable/deleteRow.html +3 -2
  53. package/src/lightning/datatable/__examples__/customDatatypeTable/iconPill.html +1 -1
  54. package/src/lightning/datatable/__examples__/customNestedComponent/customNestedComponent.html +10 -0
  55. package/src/lightning/datatable/__examples__/customNestedComponent/customNestedComponent.js +12 -0
  56. package/src/lightning/datatable/autoWidthStrategy.js +147 -191
  57. package/src/lightning/datatable/columnResizer.js +35 -35
  58. package/src/lightning/datatable/columnWidthManager.js +118 -177
  59. package/src/lightning/datatable/columns.js +90 -59
  60. package/src/lightning/datatable/datagrid.slds.css +187 -0
  61. package/src/lightning/datatable/datatable.js +248 -229
  62. package/src/lightning/datatable/errors.js +3 -0
  63. package/src/lightning/datatable/fixedWidthStrategy.js +22 -29
  64. package/src/lightning/datatable/headerActions.js +7 -9
  65. package/src/lightning/datatable/infiniteLoading.js +15 -15
  66. package/src/lightning/datatable/inlineEdit.js +255 -235
  67. package/src/lightning/datatable/keyboard.js +318 -282
  68. package/src/lightning/datatable/renderManager.js +10 -7
  69. package/src/lightning/datatable/resizeObserver.js +11 -59
  70. package/src/lightning/datatable/rowLevelActions.js +6 -5
  71. package/src/lightning/datatable/rowNumber.js +23 -23
  72. package/src/lightning/datatable/rowSelection.js +173 -145
  73. package/src/lightning/datatable/rowSelectionShared.js +13 -6
  74. package/src/lightning/datatable/rows.js +231 -196
  75. package/src/lightning/datatable/sort.js +26 -22
  76. package/src/lightning/datatable/templates/div/div.css +2 -57
  77. package/src/lightning/datatable/templates/div/div.html +13 -6
  78. package/src/lightning/datatable/templates/div/div.lbc.native.css +3 -0
  79. package/src/lightning/datatable/templates/div/div.lbc.synthetic.css +86 -0
  80. package/src/lightning/datatable/templates/table/table.html +1 -0
  81. package/src/lightning/datatable/utils.js +5 -5
  82. package/src/lightning/datatable/widthManagerShared.js +24 -21
  83. package/src/lightning/datatable/wrapText.js +25 -26
  84. package/src/lightning/datepicker/datepicker.js +32 -9
  85. package/src/lightning/datepicker/datepicker.js-meta.xml +6 -0
  86. package/src/lightning/datepicker/form-element.slds.css +54 -54
  87. package/src/lightning/datepicker/input-text.slds.css +41 -68
  88. package/src/lightning/datetimepicker/datetimepicker.js-meta.xml +6 -0
  89. package/src/lightning/datetimepicker/form-element.slds.css +54 -54
  90. package/src/lightning/datetimepicker/input-text.slds.css +41 -68
  91. package/src/lightning/dualListbox/dual-listbox.slds.css +7 -2
  92. package/src/lightning/dualListbox/form-element.slds.css +54 -54
  93. package/src/lightning/dualListbox/listbox.slds.css +51 -99
  94. package/src/lightning/dynamicIcon/dynamic-icon-strength.slds.css +1 -2
  95. package/src/lightning/dynamicIcon/dynamic-icon-trend.slds.css +1 -2
  96. package/src/lightning/formattedDateTime/formattedDateTime.js +7 -62
  97. package/src/lightning/formattedDateTime/formattedDateTime.js-meta.xml +3 -0
  98. package/src/lightning/formattedLocation/formattedLocation.html +1 -3
  99. package/src/lightning/formattedLocation/formattedLocation.js +3 -25
  100. package/src/lightning/formattedLookup/events.js +2 -4
  101. package/src/lightning/formattedNumber/formattedNumber.js +2 -49
  102. package/src/lightning/formattedRichText/formattedRichText.js +5 -5
  103. package/src/lightning/formattedRichText/linkTextNodes.js +58 -0
  104. package/src/lightning/groupedCombobox/form-element.slds.css +54 -54
  105. package/src/lightning/groupedCombobox/grouped-combobox.slds.css +0 -2
  106. package/src/lightning/groupedCombobox/groupedCombobox.js-meta.xml +1 -1
  107. package/src/lightning/groupedCombobox/input-text.slds.css +41 -68
  108. package/src/lightning/helptext/button-icon.slds.css +1 -1
  109. package/src/lightning/helptext/form-element.slds.css +54 -54
  110. package/src/lightning/icon/icon.slds.css +12 -25
  111. package/src/lightning/input/form-element.slds.css +54 -54
  112. package/src/lightning/inputAddress/form-element.slds.css +54 -54
  113. package/src/lightning/inputAddress/input-address.slds.css +1 -2
  114. package/src/lightning/inputAddress/input-text.slds.css +41 -68
  115. package/src/lightning/inputAddress/inputAddress.js +1 -0
  116. package/src/lightning/inputAddress/inputAddress.js-meta.xml +3 -0
  117. package/src/lightning/inputLocation/form-element.slds.css +54 -54
  118. package/src/lightning/inputLocation/input-location.slds.css +1 -2
  119. package/src/lightning/inputLocation/input-text.slds.css +41 -68
  120. package/src/lightning/inputName/form-element.slds.css +54 -54
  121. package/src/lightning/inputName/input-text.slds.css +41 -68
  122. package/src/lightning/interactiveDialogBase/interactive-dialog-base.slds.css +0 -3
  123. package/src/lightning/interactiveDialogBase/interactiveDialogBase.js-meta.xml +6 -0
  124. package/src/lightning/lookupAddress/form-element.slds.css +54 -54
  125. package/src/lightning/lookupAddress/listbox.slds.css +51 -99
  126. package/src/lightning/lookupAddress/location.js +2 -0
  127. package/src/lightning/lookupAddress/lookup-address.slds.css +0 -2
  128. package/src/lightning/lookupAddress/lookupAddress.js +15 -10
  129. package/src/lightning/menuDivider/menu-divider.slds.css +0 -2
  130. package/src/lightning/menuItem/menu-item.slds.css +8 -2
  131. package/src/lightning/menuSubheader/menu-subheader.slds.css +1 -2
  132. package/src/lightning/modalBase/modal-base.slds.css +3 -3
  133. package/src/lightning/modalBase/modalBase.js +0 -8
  134. package/src/lightning/modalBase/modalBase.js-meta.xml +6 -0
  135. package/src/lightning/modalBody/modal-body.slds.css +1 -2
  136. package/src/lightning/modalFooter/modal-footer.slds.css +2 -2
  137. package/src/lightning/modalFooter/modalFooter.js +0 -21
  138. package/src/lightning/modalHeader/modal-header.slds.css +1 -2
  139. package/src/lightning/modalHeader/modalHeader.js +0 -22
  140. package/src/lightning/overlay/overlay.js-meta.xml +6 -0
  141. package/src/lightning/pill/pill.slds.css +32 -58
  142. package/src/lightning/pillContainer/button.slds.css +1 -1
  143. package/src/lightning/pillContainer/listbox.slds.css +51 -99
  144. package/src/lightning/pillContainer/pill-container.slds.css +6 -10
  145. package/src/lightning/pillContainer/pill.slds.css +32 -58
  146. package/src/lightning/popup/popover.slds.css +0 -2
  147. package/src/lightning/primitiveBubble/primitiveBubble.js-meta.xml +6 -0
  148. package/src/lightning/primitiveButton/primitiveButoon.js-meta.xml +6 -0
  149. package/src/lightning/primitiveCellCheckbox/checkbox.css +2 -0
  150. package/src/lightning/primitiveColorpickerButton/color-picker-button.slds.css +16 -38
  151. package/src/lightning/primitiveCustomCell/primitiveCustomCell.js +26 -1
  152. package/src/lightning/primitiveHeaderFactory/nonsortableHeader.css +1 -0
  153. package/src/lightning/primitiveHeaderFactory/selectableHeader.css +2 -0
  154. package/src/lightning/primitiveIcon/icon.slds.css +12 -25
  155. package/src/lightning/primitiveIcon/primitiveIcon.js-meta.xml +6 -0
  156. package/src/lightning/primitiveIframe/primitiveIframe.js +3 -1
  157. package/src/lightning/primitiveInputCheckbox/form-element.slds.css +54 -54
  158. package/src/lightning/primitiveInputCheckbox/primitiveInputCheckbox.js +5 -2
  159. package/src/lightning/primitiveInputCheckbox/primitiveInputCheckbox.js-meta.xml +6 -0
  160. package/src/lightning/primitiveInputCheckboxButton/form-element.slds.css +54 -54
  161. package/src/lightning/primitiveInputCheckboxButton/input-checkbox-button.slds.css +6 -4
  162. package/src/lightning/primitiveInputCheckboxButton/primitiveInputCheckboxButton.js +5 -2
  163. package/src/lightning/primitiveInputCheckboxButton/primitiveInputCheckboxButton.js-meta.xml +6 -0
  164. package/src/lightning/primitiveInputColor/form-element.slds.css +54 -54
  165. package/src/lightning/primitiveInputColor/input-color.slds.css +2 -3
  166. package/src/lightning/primitiveInputColor/input-text.slds.css +41 -68
  167. package/src/lightning/primitiveInputColor/primitiveInputColor.js +5 -2
  168. package/src/lightning/primitiveInputColor/primitiveInputColor.js-meta.xml +6 -0
  169. package/src/lightning/primitiveInputFile/button.slds.css +1 -1
  170. package/src/lightning/primitiveInputFile/form-element.slds.css +54 -54
  171. package/src/lightning/primitiveInputFile/input-file.slds.css +1 -4
  172. package/src/lightning/primitiveInputFile/primitiveInputFile.js +4 -2
  173. package/src/lightning/primitiveInputFile/primitiveInputFile.js-meta.xml +6 -0
  174. package/src/lightning/primitiveInputRadio/primitiveInputRadio.js +4 -2
  175. package/src/lightning/primitiveInputSimple/form-element.slds.css +54 -54
  176. package/src/lightning/primitiveInputSimple/input-text.slds.css +41 -68
  177. package/src/lightning/primitiveInputSimple/primitiveInputSimple.js-meta.xml +6 -0
  178. package/src/lightning/primitiveInputToggle/form-element.slds.css +54 -54
  179. package/src/lightning/primitiveInputToggle/input-toggle.slds.css +50 -27
  180. package/src/lightning/primitiveInputToggle/primitiveInputToggle.js +5 -2
  181. package/src/lightning/primitiveInputToggle/primitiveInputToggle.js-meta.xml +6 -0
  182. package/src/lightning/progressBar/progress-bar.slds.css +8 -10
  183. package/src/lightning/progressRing/progress-ring.slds.css +0 -23
  184. package/src/lightning/progressStep/progressStep.js +1 -14
  185. package/src/lightning/radioGroup/form-element.slds.css +54 -54
  186. package/src/lightning/radioGroup/radioGroup.html +1 -2
  187. package/src/lightning/radioGroup/radioGroup.js +1 -0
  188. package/src/lightning/routingService/routingService.js +31 -5
  189. package/src/lightning/select/form-element.slds.css +54 -54
  190. package/src/lightning/select/select.slds.css +4 -2
  191. package/src/lightning/sldsUtilsVisibility/sldsUtilsVisibility.css +4 -0
  192. package/src/lightning/spinner/spinner.slds.css +62 -62
  193. package/src/lightning/tab/tab.js +4 -2
  194. package/src/lightning/tab/tab.slds.css +14 -7
  195. package/src/lightning/tabBar/tab-bar.slds.css +16 -6
  196. package/src/lightning/tabset/__docs__/tabset.md +24 -1
  197. package/src/lightning/tabset/tabset.js +25 -38
  198. package/src/lightning/tabset/tabset.slds.css +0 -2
  199. package/src/lightning/textarea/form-element.slds.css +54 -54
  200. package/src/lightning/textarea/textarea.js +5 -1
  201. package/src/lightning/textarea/textarea.slds.css +22 -9
  202. package/src/lightning/timepicker/form-element.slds.css +54 -54
  203. package/src/lightning/timepicker/timepicker.js-meta.xml +6 -0
  204. package/src/lightning/timepicker/timepicker.slds.css +2 -2
  205. package/src/lightning/toast/__docs__/toast.md +20 -22
  206. package/src/lightning/toast/button-icon.slds.css +1 -1
  207. package/src/lightning/toast/icon.slds.css +12 -25
  208. package/src/lightning/toast/toast.js +15 -12
  209. package/src/lightning/toast/toast.slds.css +6 -18
  210. package/src/lightning/toastContainer/toast.slds.css +6 -18
  211. package/src/lightning/toastContainer/toastContainer.js +25 -17
  212. package/src/lightning/tooltipLibrary/tooltipLibrary.js +12 -9
  213. package/src/lightning/tree/tree.js +2 -0
  214. package/src/lightning/utils/classSet.js +9 -3
  215. package/src/lightning/utilsPrivate/formatUtils.js +158 -0
  216. package/src/lightning/utilsPrivate/textUtils.js +16 -0
  217. package/src/lightning/utilsPrivate/utilsPrivate.js +56 -15
  218. package/src/lightning/utilsPrivate/validationUtils.js +59 -0
  219. package/src/lightning/verticalNavigationSection/vertical-navigation-section.slds.css +0 -2
  220. package/src/lightning/datatable/resizeSensor.js +0 -244
  221. package/src/lightning/formattedRichText/linkify.js +0 -43
  222. package/src/lightning/utilsPrivate/smartSetAttribute.js +0 -19
@@ -40,13 +40,13 @@ export function getKeyField(state) {
40
40
  }
41
41
 
42
42
  export function setKeyField(state, value) {
43
- assert(
44
- typeof value === 'string',
45
- `The "keyField" value expected in lightning:datatable must be type String.`
46
- );
47
43
  if (typeof value === 'string') {
48
44
  state.keyField = value;
49
45
  } else {
46
+ assert(
47
+ false,
48
+ `The "keyField" value expected in lightning:datatable must be type String.`
49
+ );
50
50
  state.keyField = undefined;
51
51
  }
52
52
  }
@@ -63,12 +63,7 @@ export function hasValidKeyField(state) {
63
63
  * @returns {string} the classSet string
64
64
  */
65
65
  export function resolveRowClassNames(row) {
66
- const classes = classSet('slds-hint-parent');
67
- if (row.isSelected) {
68
- classes.add('slds-is-selected');
69
- }
70
-
71
- return classes.toString();
66
+ return `slds-hint-parent${row.isSelected ? ' slds-is-selected' : ''}`;
72
67
  }
73
68
 
74
69
  /**
@@ -118,93 +113,124 @@ export function updateRowsAndCellIndexes() {
118
113
  const data = getData(state);
119
114
  const columns = getColumns(state);
120
115
  const computeUniqueRowKey = uniqueRowKeyGenerator(keyField);
121
- const scopeCol = columns.find(
122
- (colData) => types.isValidType(colData.type) && colData.isScopeCol
123
- );
116
+ const { length: rowCount } = data;
117
+ const { length: colCount } = columns;
118
+
119
+ let scopeCol;
120
+ for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
121
+ const col = columns[colIndex];
122
+ if (col.isScopeCol && types.isValidType(col.type)) {
123
+ scopeCol = col;
124
+ break;
125
+ }
126
+ }
127
+
124
128
  // initializing indexes
125
129
  state.indexes = {};
126
130
 
127
- state.rows = data.reduce((prev, rowData, rowIndex) => {
131
+ const rows = Array(rowCount);
132
+ state.rows = rows;
133
+
134
+ for (let rowIndex = 0; rowIndex < rowCount; rowIndex += 1) {
135
+ const rowData = data[rowIndex];
136
+ const key = computeUniqueRowKey(rowData);
137
+ const rowErrors = getRowError(state, key);
138
+
139
+ state.indexes[key] = { rowIndex };
140
+
141
+ const isRowSelected = isSelectedRow(state, key);
142
+ const rowNumber = rowIndex + 1;
143
+ const cells = Array(colCount);
144
+
128
145
  const row = {
129
- key: computeUniqueRowKey(rowData), // attaching unique key to the row
130
- cells: [],
146
+ key,
147
+ cells,
148
+ rowIndex,
149
+ rowNumber, // for UTAM since methods are base-1
150
+ ariaRowIndex: rowIndex + 2, // aria attrs are base-1 and also count header as a row
151
+ inputType: getRowSelectionInputType(state),
152
+ isSelected: isRowSelected,
153
+ ariaSelected: isRowSelected ? 'true' : false,
154
+ isDisabled: isDisabledRow(state, key),
155
+ classnames: resolveRowClassNames(rowData),
156
+ tabIndex: -1,
157
+ style: virtualize
158
+ ? styleToString({
159
+ position: 'absolute',
160
+ top: `${rowIndex * rowHeight}px`,
161
+ })
162
+ : '',
163
+ level: undefined,
164
+ posInSet: undefined,
165
+ setSize: undefined,
166
+ isExpanded: undefined,
167
+ hasChildren: undefined,
131
168
  };
132
- const rowErrors = getRowError(state, row.key);
133
-
134
- state.indexes[row.key] = { rowIndex };
135
-
136
- row.rowIndex = rowIndex;
137
- row.rowNumber = rowIndex + 1; // for UTAM since methods are base-1
138
- row.ariaRowIndex = rowIndex + 2; // aria attrs are base-1 and also count header as a row
139
- row.inputType = getRowSelectionInputType(state);
140
- row.isSelected = isSelectedRow(state, row.key);
141
- row.ariaSelected = row.isSelected ? 'true' : false;
142
- row.isDisabled = isDisabledRow(state, row.key);
143
- row.classnames = resolveRowClassNames(row);
169
+
170
+ // Add tree specific row properties.
144
171
  Object.assign(row, getRowStateForTree(rowData, state));
145
- row.tabIndex = -1;
146
- if (virtualize) {
147
- row.style = styleToString({
148
- position: 'absolute',
149
- top: `${rowIndex * rowHeight}px`,
150
- });
151
- }
152
172
 
153
- columns.reduce((currentRow, colData, colIndex) => {
154
- const { fieldName } = colData;
155
- const colKeyValue = generateColKeyValue(colData, colIndex);
173
+ rows[rowIndex] = row;
174
+
175
+ // Add cell indexes.
176
+ for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
177
+ const col = columns[colIndex];
178
+ const {
179
+ fieldName,
180
+ isScopeCol,
181
+ label: dataLabel,
182
+ type: columnType,
183
+ typeAttributes,
184
+ } = col;
185
+ const colKeyValue = generateColKeyValue(col, colIndex);
186
+ const columnSubType = typeAttributes
187
+ ? typeAttributes.subType
188
+ : undefined;
156
189
  const dirtyValue = getDirtyValueFromCell(
157
190
  state,
158
191
  row.key,
159
192
  colKeyValue
160
193
  );
161
- const cellHasErrors = hasCellErrors(
162
- rowErrors,
163
- colData.fieldName,
164
- colData.columnKey
165
- );
166
- const computedCellValue =
167
- dirtyValue !== undefined ? dirtyValue : rowData[fieldName];
194
+ const hasError = hasCellErrors(rowErrors, fieldName, col.columnKey);
195
+ // value based on the fieldName
196
+ const value =
197
+ dirtyValue === undefined ? rowData[fieldName] : dirtyValue;
198
+ const isValidType = types.isValidType(columnType);
199
+ const isCheckbox = columnType === 'SELECTABLE_CHECKBOX';
200
+ const isDataType = isValidType && !isScopeCol;
201
+ const isDataTypeScope = isValidType && isScopeCol;
202
+
168
203
  // cell object creation
169
204
  const cell = {
170
- columnType: colData.type,
171
- columnSubType: colData.typeAttributes
172
- ? colData.typeAttributes.subType
173
- : undefined,
174
- dataLabel: colData.label,
175
- value: computedCellValue, // value based on the fieldName
176
- displayValue: rowData.displayValue ? rowData.displayValue : '',
205
+ columnType,
206
+ columnSubType,
207
+ dataLabel,
208
+ value,
209
+ displayValue: rowData.displayValue || '',
177
210
  rowKeyValue: row.key, // unique row key value
178
211
  colKeyValue, // unique column key value
179
- tabIndex: -1, // tabindex
180
- isCheckbox: colData.type === 'SELECTABLE_CHECKBOX',
212
+ tabIndex: -1,
213
+ isCheckbox,
181
214
  class: computeCellClassNames(
182
215
  rowData,
183
- colData,
184
- cellHasErrors,
216
+ col,
217
+ hasError,
185
218
  dirtyValue,
186
219
  renderModeRoleBased
187
220
  ),
188
- hasError: cellHasErrors,
189
- isDataType:
190
- types.isValidType(colData.type) && !colData.isScopeCol,
191
- isDataTypeScope:
192
- types.isValidType(colData.type) && colData.isScopeCol,
221
+ hasError,
222
+ isDataType,
223
+ isDataTypeScope,
193
224
  wrapText: state.wrapText[colKeyValue], // wrapText state
194
225
  wrapTextMaxLines: state.wrapText[colKeyValue]
195
226
  ? state.wrapTextMaxLines
196
227
  : undefined,
197
- style: computeCellStyles(types, colData, renderModeRoleBased),
228
+ style: computeCellStyles(types, col, renderModeRoleBased),
198
229
  };
199
- if (isCustomerColumn(colData)) {
200
- assignCustomerColumnAttributes(
201
- cell,
202
- row,
203
- rowData,
204
- colData,
205
- types
206
- );
207
- } else if (isRowNumberColumn(colData)) {
230
+
231
+ if (isCustomerColumn(col)) {
232
+ assignCustomerColumnAttributes(cell, row, rowData, col, types);
233
+ } else if (isRowNumberColumn(col)) {
208
234
  assignRowNumberColumnAttributes(
209
235
  cell,
210
236
  rowData,
@@ -218,14 +244,9 @@ export function updateRowsAndCellIndexes() {
218
244
  // Keeping the hash for backward compatibility, but we need to have 2 indexes, 1 for columns and one for rows,
219
245
  // because of memory usage and also at certain point we might have the data but not the columns
220
246
  state.indexes[row.key][colKeyValue] = [rowIndex, colIndex];
221
-
222
- currentRow.push(cell);
223
- return currentRow;
224
- }, row.cells);
225
-
226
- prev.push(row);
227
- return prev;
228
- }, []);
247
+ cells[colIndex] = cell;
248
+ }
249
+ }
229
250
  }
230
251
 
231
252
  /**
@@ -238,11 +259,11 @@ export function updateRowsAndCellIndexes() {
238
259
  * as column identifiers.
239
260
  */
240
261
  function hasCellErrors(rowErrors, fieldName, columnKey) {
241
- const rowErrorsHasColumnKey = rowErrors.cells && rowErrors.cells[columnKey];
242
- const rowErrorsHasFieldName =
243
- rowErrors.fieldNames && rowErrors.fieldNames.includes(fieldName);
244
-
245
- return rowErrorsHasColumnKey || (!columnKey && rowErrorsHasFieldName);
262
+ const cellErrors = rowErrors.cells;
263
+ const errorFieldNames = rowErrors.fieldNames;
264
+ return columnKey
265
+ ? !!(cellErrors && cellErrors[columnKey])
266
+ : !!(errorFieldNames && errorFieldNames.includes(fieldName));
246
267
  }
247
268
 
248
269
  /**
@@ -315,18 +336,20 @@ function assignRowNumberColumnAttributes(
315
336
  * This object that contains the resolved mapping is then set in the `cell` object
316
337
  * in each row.
317
338
  *
318
- * @param {Object} row - current row data. Required for cases cellAttributes refers to a fieldName in a row
319
- * @param {Object} column - column definition
339
+ * @param {Object} rowData - current row data. Required for cases cellAttributes refers to a fieldName in a row
340
+ * @param {Object} col - column definition
320
341
  * @returns {Object} - contains the resolved mapping of cellAttributes and their values
321
342
  */
322
- export function computeCellAttributes(row, column) {
323
- const cellAttributesValues = getCellAttributesValues(column);
324
- return Object.keys(cellAttributesValues).reduce((attrs, attrName) => {
325
- const attrValue = cellAttributesValues[attrName];
326
- attrs[attrName] = resolveAttributeValue(attrValue, row);
327
-
328
- return attrs;
329
- }, {});
343
+ export function computeCellAttributes(rowData, col) {
344
+ const cellAttrs = {};
345
+ const cellAttributes = getCellAttributesValues(col);
346
+ const keys = Object.keys(cellAttributes);
347
+ for (let i = 0, { length } = keys; i < length; i += 1) {
348
+ const attrName = keys[i];
349
+ const attrValue = cellAttributes[attrName];
350
+ cellAttrs[attrName] = resolveAttributeValue(attrValue, rowData);
351
+ }
352
+ return cellAttrs;
330
353
  }
331
354
 
332
355
  /**
@@ -347,43 +370,47 @@ export function computeCellAttributes(row, column) {
347
370
  * type-attribute-1={cell.typeAttribute1}
348
371
  * ...
349
372
  *
350
- * @param {Object} row - current row data. Required for cases typeAttributes refers to a fieldName in a row
351
- * @param {Object} column - column definition
373
+ * @param {Object} rowData - current row data. Required for cases typeAttributes refers to a fieldName in a row
374
+ * @param {Object} col - column definition
352
375
  * @param {Object} types - instance of DatatableTypes from `./types.js`
353
376
  * @returns {Object} - object containing all the typeAttributes{index} and their mapped values
354
377
  */
355
- export function computeCellTypeAttributes(row, column, types) {
356
- if (column.typeAttributes && column.typeAttributes.subType) {
357
- return computeCellSubTypeAttributes(row, column);
378
+ export function computeCellTypeAttributes(rowData, column, types) {
379
+ const { typeAttributes } = column;
380
+ if (typeAttributes && typeAttributes.subType) {
381
+ return computeCellSubTypeAttributes(rowData, column);
358
382
  }
359
- const attributesNames = types.getType(column.type).typeAttributes;
360
- const typeAttributesValues = getTypeAttributesValues(column);
361
-
362
- return attributesNames.reduce((attrs, attrName, index) => {
363
- const typeAttributeName = `typeAttribute${index}`;
364
-
365
- attrs[typeAttributeName] = resolveAttributeValue(
366
- typeAttributesValues[attrName],
367
- row
383
+ const attributeNames = types.getType(column.type).typeAttributes;
384
+ const attributeValues = getTypeAttributesValues(column);
385
+
386
+ const cellAttrs = {};
387
+ const attributeNamesLength = attributeNames ? attributeNames.length : 0;
388
+ for (let i = 0; i < attributeNamesLength; i += 1) {
389
+ const attrName = attributeNames[i];
390
+ const attrValue = attributeValues[attrName];
391
+ cellAttrs[`typeAttribute${i}`] = resolveAttributeValue(
392
+ attrValue,
393
+ rowData
368
394
  );
369
-
370
- return attrs;
371
- }, {});
395
+ }
396
+ return cellAttrs;
372
397
  }
373
398
 
374
- export function computeCellSubTypeAttributes(row, column) {
375
- const attributesNames = getAttributesNames(column.typeAttributes.subType);
376
- const typeAttributesValues = getSubTypeAttributesValues(column);
399
+ function computeCellSubTypeAttributes(rowData, column) {
400
+ const attributeNames = getAttributesNames(column.typeAttributes.subType);
401
+ const attributeValues = getSubTypeAttributesValues(column);
377
402
 
378
- return attributesNames.reduce((attrs, attrName, index) => {
379
- const typeAttributeName = `typeAttribute${index}`;
380
- attrs[typeAttributeName] = resolveAttributeValue(
381
- typeAttributesValues[attrName],
382
- row
403
+ const cellAttrs = {};
404
+ const attributeNamesLength = attributeNames ? attributeNames.length : 0;
405
+ for (let i = 0; i < attributeNamesLength; i += 1) {
406
+ const attrName = attributeNames[i];
407
+ const attrValue = attributeValues[attrName];
408
+ cellAttrs[`typeAttribute${i}`] = resolveAttributeValue(
409
+ attrValue,
410
+ rowData
383
411
  );
384
-
385
- return attrs;
386
- }, {});
412
+ }
413
+ return cellAttrs;
387
414
  }
388
415
 
389
416
  function computeCellEditable(row, column) {
@@ -401,16 +428,16 @@ function computeCellEditable(row, column) {
401
428
  *
402
429
  * Returns false in all other cases.
403
430
  *
404
- * @param {object} row - a row data object stored in datatable state. Must be truthy.
405
- * @param {object} column - a column data object stored in datatable state. Must be truthy.
431
+ * @param {object} rowData - a row data object stored in datatable state. Must be truthy.
432
+ * @param {object} col - a column data object stored in datatable state. Must be truthy.
406
433
  */
407
- export function isCellEditable(row, column) {
408
- return !!resolveAttributeValue(column.editable, row);
434
+ export function isCellEditable(rowData, col) {
435
+ return !!resolveAttributeValue(col.editable, rowData);
409
436
  }
410
437
 
411
- function computeCellDisplayReadOnlyIcon(column) {
438
+ function computeCellDisplayReadOnlyIcon(col) {
412
439
  return {
413
- displayReadOnlyIcon: !!column.displayReadOnlyIcon,
440
+ displayReadOnlyIcon: !!col.displayReadOnlyIcon,
414
441
  };
415
442
  }
416
443
 
@@ -422,52 +449,61 @@ function computeCellDisplayReadOnlyIcon(column) {
422
449
  * managed by ourselves unlike the <table> version.
423
450
  *
424
451
  * @param {Object} types - instance of DatatableTypes from `./types.js`
425
- * @param {Object} colData - column definition
452
+ * @param {Object} col - column definition
426
453
  * @param {Boolean} renderModeRoleBased - render mode of datatable (div || table)
427
454
  * @returns {String} - styles to be set on the cell
428
455
  */
429
- function computeCellStyles(types, colData, renderModeRoleBased) {
430
- let style = '';
431
- const columnType = colData.type;
456
+ function computeCellStyles(types, col, renderModeRoleBased) {
457
+ const columnType = col.type;
432
458
 
433
- // When a custom type is not using the standard layout,
434
- // remove the padding that comes with the standard layout
459
+ let cellStyle = '';
435
460
  if (
436
461
  types.isCustomType(columnType) &&
437
462
  !types.isStandardCellLayoutForCustomType(columnType)
438
463
  ) {
439
- style = 'padding: 0;';
464
+ // When a custom type is not using the standard layout,
465
+ // remove the padding that comes with the standard layout
466
+ cellStyle = 'padding: 0;';
440
467
  }
441
468
 
442
469
  // Width needs to be managed when rendering as divs
443
470
  if (renderModeRoleBased) {
444
- const columnWidth = colData.columnWidth;
445
- style += columnWidth > 0 ? `width:${columnWidth}px;` : '';
471
+ const { columnWidth } = col.columnWidth;
472
+ if (columnWidth > 0) {
473
+ cellStyle += `width:${columnWidth}px;`;
474
+ }
446
475
  }
447
476
 
448
- return style;
477
+ return cellStyle;
449
478
  }
450
479
 
451
480
  function computeCellClassNames(
452
481
  row,
453
482
  column,
454
- cellHasErrors,
483
+ hasError,
455
484
  dirtyValue,
456
485
  renderModeRoleBased
457
486
  ) {
458
- const classNames = classSet('');
459
487
  // TODO: With the current SLDS design, the 'slds-cell-edit' class is required on a cell in cases
460
488
  // where the read only icon is to be displayed. This is an issue with their design that will need to
461
489
  // be addressed on their end, so once they do that we can modify this code accordingly.
462
- classNames.add({
463
- 'slds-cell-edit':
464
- isCellEditable(row, column) || column.displayReadOnlyIcon,
465
- 'slds-tree__item': isTreeType(column.type),
466
- 'slds-has-error': cellHasErrors,
467
- 'slds-is-edited': dirtyValue !== undefined,
468
- cell: renderModeRoleBased,
469
- });
470
- return classNames.toString();
490
+ let cellClass = '';
491
+ if (column.displayReadOnlyIcon || isCellEditable(row, column)) {
492
+ cellClass += 'slds-cell-edit';
493
+ }
494
+ if (isTreeType(column.type)) {
495
+ cellClass += (cellClass.length ? ' ' : '') + 'slds-tree__item';
496
+ }
497
+ if (hasError) {
498
+ cellClass += (cellClass.length ? ' ' : '') + 'slds-has-error';
499
+ }
500
+ if (dirtyValue !== undefined) {
501
+ cellClass += (cellClass.length ? ' ' : '') + 'slds-is-edited';
502
+ }
503
+ if (renderModeRoleBased) {
504
+ cellClass += (cellClass.length ? ' ' : '') + 'cell';
505
+ }
506
+ return cellClass;
471
507
  }
472
508
 
473
509
  /**
@@ -506,11 +542,11 @@ export function getRowsTotal(state) {
506
542
  return getRows(state).length;
507
543
  }
508
544
 
509
- function resolveAttributeValue(attrValue, row) {
545
+ function resolveAttributeValue(attrValue, rowData) {
510
546
  if (isObjectLike(attrValue)) {
511
- const fieldName = attrValue.fieldName;
547
+ const { fieldName } = attrValue;
512
548
  if (fieldName) {
513
- return row[fieldName];
549
+ return rowData[fieldName];
514
550
  }
515
551
  }
516
552
 
@@ -518,69 +554,68 @@ function resolveAttributeValue(attrValue, row) {
518
554
  }
519
555
 
520
556
  function getRowStateForTree(row, state) {
557
+ const _row = {};
521
558
  const column = getStateTreeColumn(state);
522
559
  if (column) {
523
- return {
524
- level: getRowLevel(column, row),
525
- posInSet: getRowPosInSet(column, row),
526
- setSize: getRowSetSize(column, row),
527
- isExpanded: isRowExpanded(column, row),
528
- hasChildren: getRowHasChildren(column, row),
529
- };
560
+ _row.hasChildren = getRowHasChildren(column, row);
561
+ _row.isExpanded = isRowExpanded(column, row);
562
+ _row.level = getRowLevel(column, row);
563
+ _row.posInSet = getRowPosInSet(column, row);
564
+ _row.setSize = getRowSetSize(column, row);
530
565
  }
531
- return {};
566
+ return _row;
532
567
  }
533
568
 
534
- export function getRowLevel(column, row) {
535
- const typeAttributesValues = getTypeAttributesValues(column);
536
- const attrValue = resolveAttributeValue(
537
- typeAttributesValues[getTreeStateIndicatorFieldNames().level],
538
- row
569
+ export function getRowLevel(column, rowData) {
570
+ const treeColTypeAttrs = getTypeAttributesValues(column);
571
+ return (
572
+ resolveAttributeValue(
573
+ treeColTypeAttrs[getTreeStateIndicatorFieldNames().level],
574
+ rowData
575
+ ) || 1
539
576
  );
540
- return attrValue ? attrValue : 1;
541
577
  }
542
578
 
543
579
  function getRowPosInSet(column, row) {
544
- const typeAttributesValues = getTypeAttributesValues(column);
545
- const attrValue = resolveAttributeValue(
546
- typeAttributesValues[getTreeStateIndicatorFieldNames().position],
547
- row
580
+ const treeColTypeAttrs = getTypeAttributesValues(column);
581
+ return (
582
+ resolveAttributeValue(
583
+ treeColTypeAttrs[getTreeStateIndicatorFieldNames().position],
584
+ row
585
+ ) || 1
548
586
  );
549
- return attrValue ? attrValue : 1;
550
587
  }
551
588
 
552
589
  function getRowSetSize(column, row) {
553
- const typeAttributesValues = getTypeAttributesValues(column);
554
- const attrValue = resolveAttributeValue(
555
- typeAttributesValues[getTreeStateIndicatorFieldNames().setsize],
556
- row
590
+ const treeColTypeAttrs = getTypeAttributesValues(column);
591
+ return (
592
+ resolveAttributeValue(
593
+ treeColTypeAttrs[getTreeStateIndicatorFieldNames().setsize],
594
+ row
595
+ ) || 1
557
596
  );
558
- return attrValue ? attrValue : 1;
559
597
  }
560
598
 
561
- export function isRowExpanded(column, row) {
562
- const typeAttributesValues = getTypeAttributesValues(column);
599
+ export function isRowExpanded(column, rowData) {
600
+ const treeColTypeAttrs = getTypeAttributesValues(column);
563
601
  const hasChildren = resolveAttributeValue(
564
- typeAttributesValues[getTreeStateIndicatorFieldNames().children],
565
- row
602
+ treeColTypeAttrs[getTreeStateIndicatorFieldNames().children],
603
+ rowData
566
604
  );
567
- if (hasChildren) {
568
- const attrValue = resolveAttributeValue(
569
- typeAttributesValues[getTreeStateIndicatorFieldNames().expanded],
570
- row
571
- );
572
- return !!attrValue + '';
573
- }
574
- return undefined;
575
- }
576
-
577
- export function getRowHasChildren(column, row) {
578
- const typeAttributesValues = getTypeAttributesValues(column);
579
- const hasChildren = resolveAttributeValue(
580
- typeAttributesValues[getTreeStateIndicatorFieldNames().children],
581
- row
605
+ return hasChildren
606
+ ? `${!!resolveAttributeValue(
607
+ treeColTypeAttrs[getTreeStateIndicatorFieldNames().expanded],
608
+ rowData
609
+ )}`
610
+ : undefined;
611
+ }
612
+
613
+ function getRowHasChildren(column, rowData) {
614
+ const treeColTypeAttrs = getTypeAttributesValues(column);
615
+ return !!resolveAttributeValue(
616
+ treeColTypeAttrs[getTreeStateIndicatorFieldNames().children],
617
+ rowData
582
618
  );
583
- return !!hasChildren;
584
619
  }
585
620
 
586
621
  /**