lightning-base-components 1.21.3-alpha → 1.21.4-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 (183) hide show
  1. package/metadata/raptor.json +49 -0
  2. package/package.json +88 -21
  3. package/scopedImports/@salesforce-label-LightningDatatable.showActions.js +1 -1
  4. package/scopedImports/@salesforce-label-LightningForm.controllerFieldsMessage.js +1 -0
  5. package/scopedImports/@salesforce-label-LightningForm.dependentFieldsHeader.js +1 -0
  6. package/scopedImports/@salesforce-label-LightningForm.dependentFieldsListHeading.js +1 -0
  7. package/scopedImports/@salesforce-label-LightningForm.generalDependentFieldsMessage.js +1 -0
  8. package/scopedImports/@salesforce-label-LightningForm.learnMore.js +1 -0
  9. package/scopedImports/@salesforce-label-LightningForm.okButton.js +1 -0
  10. package/scopedImports/@salesforce-label-LightningLookup.modalCancel.js +1 -0
  11. package/scopedImports/@salesforce-label-LightningLookup.modalSelect.js +1 -0
  12. package/scopedImports/@salesforce-label-LightningProgressIndicator.currentStage.js +1 -1
  13. package/scopedImports/@salesforce-label-LightningProgressIndicator.errorStage.js +1 -0
  14. package/scopedImports/@salesforce-label-LightningProgressIndicator.stageComplete.js +1 -1
  15. package/scopedImports/@salesforce-label-LightningProgressIndicator.stageNotStarted.js +1 -1
  16. package/src/lightning/avatar/avatar.html +1 -0
  17. package/src/lightning/badge/badge.html +3 -3
  18. package/src/lightning/baseCombobox/baseCombobox.html +4 -1
  19. package/src/lightning/baseCombobox/baseCombobox.js +3 -16
  20. package/src/lightning/button/__docs__/button.md +2 -1
  21. package/src/lightning/button/button.js +3 -4
  22. package/src/lightning/buttonIcon/__docs__/buttonIcon.md +1 -0
  23. package/src/lightning/buttonIcon/buttonIcon.html +1 -1
  24. package/src/lightning/buttonIcon/buttonIcon.js +18 -17
  25. package/src/lightning/buttonMenu/buttonMenu.css +5 -0
  26. package/src/lightning/buttonMenu/buttonMenu.js +2 -0
  27. package/src/lightning/colorPickerCustom/colorPickerCustom.js +12 -0
  28. package/src/lightning/colorPickerPanel/colorPickerPanel.js +11 -1
  29. package/src/lightning/combobox/combobox.html +1 -0
  30. package/src/lightning/datatable/__examples__disabled/customComponentWrapper/customComponentWrapper.html +11 -0
  31. package/src/lightning/datatable/__examples__disabled/customComponentWrapper/customComponentWrapper.js +25 -0
  32. package/src/lightning/datatable/__examples__disabled/customComponentWrapper/generateData.js +15 -0
  33. package/src/lightning/datatable/__examples__disabled/myCustomTypeDatatable/customInput.html +4 -0
  34. package/src/lightning/datatable/__examples__disabled/myCustomTypeDatatable/myCustomTypeDatatable.js +17 -0
  35. package/src/lightning/datatable/__examples__disabled/myCustomTypeDatatable/nestedSimpleComponentParent.html +7 -0
  36. package/src/lightning/datatable/__examples__disabled/simpleComponentNested/simpleComponentNested.html +9 -0
  37. package/src/lightning/datatable/__examples__disabled/simpleComponentNested/simpleComponentNested.js +6 -0
  38. package/src/lightning/datatable/autoWidthStrategy.js +8 -36
  39. package/src/lightning/datatable/columnResizer.js +51 -161
  40. package/src/lightning/datatable/columnWidthManager.js +25 -81
  41. package/src/lightning/datatable/columns.js +180 -302
  42. package/src/lightning/datatable/datatable.js +455 -441
  43. package/src/lightning/datatable/errors.js +17 -29
  44. package/src/lightning/datatable/fixedWidthStrategy.js +7 -22
  45. package/src/lightning/datatable/headerActions.js +8 -38
  46. package/src/lightning/datatable/indexes.js +42 -0
  47. package/src/lightning/datatable/infiniteLoading.js +16 -35
  48. package/src/lightning/datatable/inlineEdit.js +125 -156
  49. package/src/lightning/datatable/keyboard.js +226 -282
  50. package/src/lightning/datatable/renderManager.js +0 -4
  51. package/src/lightning/datatable/resizeObserver.js +4 -13
  52. package/src/lightning/datatable/rowLevelActions.js +2 -2
  53. package/src/lightning/datatable/rowNumber.js +21 -59
  54. package/src/lightning/datatable/rowSelection.js +95 -178
  55. package/src/lightning/datatable/rowSelectionShared.js +13 -27
  56. package/src/lightning/datatable/rows.js +171 -418
  57. package/src/lightning/datatable/sort.js +16 -75
  58. package/src/lightning/datatable/templates/div/div.html +12 -4
  59. package/src/lightning/datatable/templates/div/div.lbc.synthetic.css +10 -16
  60. package/src/lightning/datatable/templates/table/table.html +15 -5
  61. package/src/lightning/datatable/tree.js +17 -35
  62. package/src/lightning/datatable/types.js +10 -31
  63. package/src/lightning/datatable/utils.js +49 -24
  64. package/src/lightning/datatable/virtualization.js +2 -5
  65. package/src/lightning/datatable/widthManagerShared.js +0 -20
  66. package/src/lightning/datatable/wrapText.js +29 -60
  67. package/src/lightning/dualListbox/dualListbox.js +7 -8
  68. package/src/lightning/formattedName/formattedName.js +3 -2
  69. package/src/lightning/formattedName/formattedName.js-meta.xml +3 -0
  70. package/src/lightning/formattedNumber/formattedNumber.js +3 -2
  71. package/src/lightning/formattedNumber/formattedNumber.js-meta.xml +3 -0
  72. package/src/lightning/formattedRichText/richTextConfig.js +1 -0
  73. package/src/lightning/helptext/helptext.css +7 -0
  74. package/src/lightning/helptext/helptext.js +3 -4
  75. package/src/lightning/icon/icon.html +1 -1
  76. package/src/lightning/input/input.html +5 -0
  77. package/src/lightning/inputAddress/addressFormat.js +31 -4
  78. package/src/lightning/inputAddress/fieldsLayout.js +6 -0
  79. package/src/lightning/inputAddress/inputAddress.html +19 -1
  80. package/src/lightning/inputAddress/inputAddress.js +74 -3
  81. package/src/lightning/internationalizationLibrary/address/AddressFormat.js +553 -610
  82. package/src/lightning/lookupAddress/lookupAddress.html +6 -1
  83. package/src/lightning/lookupAddress/lookupAddress.js +25 -0
  84. package/src/lightning/modal/__docs__/modal.md +10 -1
  85. package/src/lightning/modal/__modalUtils__/modalContainerTestConstants.js +3 -7
  86. package/src/lightning/modal/__modalUtils__/modalContainerTestMethods.js +39 -133
  87. package/src/lightning/modal/__modalUtils__/modalContainerTestMockData.js +1 -1
  88. package/src/lightning/modal/modal.js +1 -1
  89. package/src/lightning/modalBase/modalBase.html +15 -10
  90. package/src/lightning/modalBase/modalBase.js +131 -146
  91. package/src/lightning/modalBody/modalBody.css +6 -0
  92. package/src/lightning/modalHeader/modalHeader.html +16 -4
  93. package/src/lightning/modalHeader/modalHeader.js +61 -14
  94. package/src/lightning/pill/link.html +1 -0
  95. package/src/lightning/pill/plain.html +1 -0
  96. package/src/lightning/pill/plainLink.html +1 -0
  97. package/src/lightning/primitiveBubble/primitiveBubble.js +42 -0
  98. package/src/lightning/primitiveDatatableCell/primitiveDatatableCell.js +1 -1
  99. package/src/lightning/primitiveHeaderActions/primitiveHeaderActions.html +1 -1
  100. package/src/lightning/primitiveHeaderActions/primitiveHeaderActions.js +13 -0
  101. package/src/lightning/primitiveHeaderFactory/nonsortableHeader.html +19 -6
  102. package/src/lightning/primitiveHeaderFactory/sortableHeader.html +3 -1
  103. package/src/lightning/primitiveResizeHandler/primitiveResizeHandler.css +11 -0
  104. package/src/lightning/primitiveResizeHandler/primitiveResizeHandler.html +2 -1
  105. package/src/lightning/primitiveResizeHandler/primitiveResizeHandler.js +1 -0
  106. package/src/lightning/progressStep/base.html +5 -6
  107. package/src/lightning/progressStep/progressStep.js +14 -9
  108. package/src/lightning/prompt/__docs__/prompt.md +1 -1
  109. package/src/lightning/shadowBaseClassPrivate/shadowBaseClassPrivate.js +0 -2
  110. package/src/lightning/sldsCommon/sldsCommon.css +134 -98
  111. package/src/lightning/sldsUtilsAlignment/sldsUtilsAlignment.css +1 -1
  112. package/src/lightning/sldsUtilsBox/sldsUtilsBox.css +14 -13
  113. package/src/lightning/sldsUtilsGrid/sldsUtilsGrid.css +95 -92
  114. package/src/lightning/sldsUtilsHyphenation/sldsUtilsHyphenation.css +1 -1
  115. package/src/lightning/sldsUtilsMargin/sldsUtilsMargin.css +77 -75
  116. package/src/lightning/sldsUtilsPadding/sldsUtilsPadding.css +73 -73
  117. package/src/lightning/sldsUtilsSizing/sldsUtilsSizing.css +552 -558
  118. package/src/lightning/sldsUtilsVisibility/sldsUtilsVisibility.css +2 -2
  119. package/src/lightning/staticMap/staticMap.js +3 -2
  120. package/src/lightning/tab/tab.js +6 -3
  121. package/src/lightning/tab/tab.js-meta.xml +3 -0
  122. package/src/lightning/tabBar/tabBar.js +10 -5
  123. package/src/lightning/tabset/tabset.html +2 -0
  124. package/src/lightning/tabset/tabset.js-meta.xml +3 -0
  125. package/src/lightning/textarea/textarea.js +6 -1
  126. package/src/lightning/toastContainer/__docs__/toastContainer.md +3 -2
  127. package/src/lightning/tooltipLibrary/tooltipLibrary.js +24 -15
  128. package/src/lightning/verticalNavigation/vertical-navigation.slds.css +14 -0
  129. package/src/lightning/verticalNavigation/verticalNavigation.css +1 -1
  130. package/src/lightning/verticalNavigation/verticalNavigation.html +1 -1
  131. package/src/lightning/verticalNavigation/verticalNavigation.js +66 -28
  132. package/src/lightning/verticalNavigation/verticalNavigation.js-meta.xml +3 -0
  133. package/src/lightning/verticalNavigationItem/vertical-navigation-item.slds.css +63 -0
  134. package/src/lightning/verticalNavigationItem/verticalNavigationItem.css +2 -3
  135. package/src/lightning/verticalNavigationItem/verticalNavigationItem.js +29 -15
  136. package/src/lightning/verticalNavigationItem/verticalNavigationItem.js-meta.xml +3 -0
  137. package/src/lightning/verticalNavigationItem/verticalNavigationItem.lbc.native.css +2 -0
  138. package/src/lightning/verticalNavigationItem/verticalNavigationItem.lbc.synthetic.css +3 -0
  139. package/src/lightning/verticalNavigationItemBadge/badge.slds.css +76 -0
  140. package/src/lightning/verticalNavigationItemBadge/vertical-navigation-item.slds.css +63 -0
  141. package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.css +2 -3
  142. package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.html +1 -1
  143. package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.js +28 -15
  144. package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.js-meta.xml +3 -0
  145. package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.lbc.native.css +5 -0
  146. package/src/lightning/verticalNavigationItemBadge/verticalNavigationItemBadge.lbc.synthetic.css +3 -0
  147. package/src/lightning/verticalNavigationItemIcon/vertical-navigation-item.slds.css +63 -0
  148. package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.css +2 -3
  149. package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.js +29 -15
  150. package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.js-meta.xml +3 -0
  151. package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.lbc.native.css +3 -0
  152. package/src/lightning/verticalNavigationItemIcon/verticalNavigationItemIcon.lbc.synthetic.css +3 -0
  153. package/src/lightning/verticalNavigationOverflow/button.slds.css +503 -0
  154. package/src/lightning/verticalNavigationOverflow/vertical-navigation-item.slds.css +63 -0
  155. package/src/lightning/verticalNavigationOverflow/vertical-navigation-section.slds.css +17 -0
  156. package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.css +2 -1
  157. package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.html +2 -0
  158. package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.js +18 -13
  159. package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.js-meta.xml +3 -0
  160. package/src/lightning/verticalNavigationOverflow/verticalNavigationOverflow.lbc.native.css +5 -0
  161. package/src/lightning/verticalNavigationSection/vertical-navigation-section.slds.css +14 -14
  162. package/src/lightning/verticalNavigationSection/verticalNavigationSection.js-meta.xml +3 -0
  163. package/src/lightning/datatable/inlineEditShared.js +0 -26
  164. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatableWrapper/customDatatableWrapper.html +0 -0
  165. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatableWrapper/customDatatableWrapper.js +0 -0
  166. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeDeleteRowBtn/customDatatypeDeleteRowBtn.html +0 -0
  167. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeDeleteRowBtn/customDatatypeDeleteRowBtn.js +0 -0
  168. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeLink/customDatatypeLink.html +0 -0
  169. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeLink/customDatatypeLink.js +0 -0
  170. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeNumber/customDatatypeNumber.html +0 -0
  171. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeNumber/customDatatypeNumber.js +0 -0
  172. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeRowOrderingBtn/customDatatypeRowOrderingBtn.html +0 -0
  173. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeRowOrderingBtn/customDatatypeRowOrderingBtn.js +0 -0
  174. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customDatatypeTable.js +0 -0
  175. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customLink.html +0 -0
  176. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customName.html +0 -0
  177. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customNumber.html +0 -0
  178. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/customNumberEdit.html +0 -0
  179. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/deleteRow.html +0 -0
  180. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/iconPill.html +0 -0
  181. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customDatatypeTable/orderingButtons.html +0 -0
  182. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customNestedComponent/customNestedComponent.html +0 -0
  183. /package/src/lightning/datatable/{__examples__ → __examples__disabled}/customNestedComponent/customNestedComponent.js +0 -0
@@ -1,33 +1,11 @@
1
- import {
2
- resolveRowClassNames,
3
- getRows,
4
- getRowByKey,
5
- getRowsTotal,
6
- getRowIndexByKey,
7
- rowKeyExists,
8
- } from './rows';
9
- import {
10
- getColumns,
11
- getStateColumnIndex,
12
- SELECTABLE_ROW_CHECKBOX,
13
- } from './columns';
1
+ import { getRowByKey, getRowIndexByKey, HEADER_ROW_KEY } from './indexes';
2
+ import { getStateColumnIndex } from './columns';
14
3
  import { isNonNegativeInteger } from './utils';
15
4
  import {
16
5
  getCurrentSelectionLength,
17
- isSelectedRow,
18
- isDisabledRow,
19
- getRowSelectionInputType,
20
- getMaxRowSelection,
21
6
  getSelectedRowsKeys,
22
- } from './rowSelectionShared';
23
-
24
- export {
25
- getCurrentSelectionLength,
26
- isSelectedRow,
27
7
  isDisabledRow,
28
- getRowSelectionInputType,
29
- getMaxRowSelection,
30
- getSelectedRowsKeys,
8
+ SELECTABLE_HEADER_TYPE,
31
9
  } from './rowSelectionShared';
32
10
 
33
11
  const MAX_ROW_SELECTION_DEFAULT = undefined;
@@ -85,7 +63,7 @@ export function handleSelectRow(event) {
85
63
  ? getLastRowSelection(state) || rowKeyValue
86
64
  : rowKeyValue;
87
65
  markSelectedRowsInterval(state, fromRowKey, rowKeyValue);
88
- setLastRowSelection(state, rowKeyValue);
66
+ state.lastSelectedRowKey = rowKeyValue;
89
67
  this.fireSelectedRowsChange(this.getSelectedRows(), {
90
68
  action: ROWS_ACTION.ROW_SELECT,
91
69
  value: rowKeyValue,
@@ -109,7 +87,7 @@ export function handleDeselectRow(event) {
109
87
  ? getLastRowSelection(state) || rowKeyValue
110
88
  : rowKeyValue;
111
89
  markDeselectedRowsInterval(state, fromRowKey, rowKeyValue);
112
- setLastRowSelection(state, rowKeyValue);
90
+ state.lastSelectedRowKey = rowKeyValue;
113
91
  this.fireSelectedRowsChange(this.getSelectedRows(), {
114
92
  action: ROWS_ACTION.ROW_DESELECT,
115
93
  value: rowKeyValue,
@@ -138,20 +116,19 @@ export function handleRowSelectionChange() {
138
116
  * @param {Object} state - The datatable state
139
117
  */
140
118
  export function markAllRowsSelected(state) {
141
- const rows = getRows(state);
142
- const maxRowSelection = getMaxRowSelection(state);
143
-
144
- resetSelectedRowsKeys(state);
119
+ const { maxRowSelection, rows } = state;
120
+ const selectedRowsKeys = {};
145
121
  for (let i = 0, { length: rowCount } = rows; i < rowCount; i += 1) {
146
122
  const row = rows[i];
147
123
  if (maxRowSelection === undefined || i < maxRowSelection) {
148
- setRowSelectedAttributes(true, row);
149
- addKeyToSelectedRowKeys(state, row.key);
124
+ selectedRowsKeys[row.key] = true;
125
+ setRowSelectedAttributes(row, true);
150
126
  } else {
151
127
  row.isDisabled = true;
152
- setRowSelectedAttributes(false, row);
128
+ setRowSelectedAttributes(row, false);
153
129
  }
154
130
  }
131
+ state.selectedRowsKeys = selectedRowsKeys;
155
132
  }
156
133
 
157
134
  /**
@@ -161,16 +138,15 @@ export function markAllRowsSelected(state) {
161
138
  * the `classnames` for the row to reflect that it is not selected.
162
139
  *
163
140
  * @param {Object} state - The datatable state
164
- * @returns
165
141
  */
166
142
  export function markAllRowsDeselected(state) {
167
- const rows = getRows(state);
168
- resetSelectedRowsKeys(state);
143
+ const { rows } = state;
169
144
  for (let i = 0, { length: rowCount } = rows; i < rowCount; i += 1) {
170
145
  const row = rows[i];
171
146
  row.isDisabled = false;
172
- setRowSelectedAttributes(false, row);
147
+ setRowSelectedAttributes(row, false);
173
148
  }
149
+ state.selectedRowsKeys = {};
174
150
  }
175
151
 
176
152
  /**
@@ -192,9 +168,9 @@ export function markAllRowsDeselected(state) {
192
168
  * @param {String} endRowKey - row key value of the last row that was selected (end of the interval)
193
169
  */
194
170
  function markSelectedRowsInterval(state, startRowKey, endRowKey) {
195
- const rows = getRows(state);
171
+ const { rows } = state;
196
172
  const { start, end } = getRowIntervalIndexes(state, startRowKey, endRowKey);
197
- const total = getMaxRowSelection(state) || getRowsTotal(state);
173
+ const total = state.maxRowSelection || rows.length;
198
174
  let rowIndex = start;
199
175
  let maxSelectionReached;
200
176
  while (rowIndex <= end && !maxSelectionReached) {
@@ -222,11 +198,17 @@ function markSelectedRowsInterval(state, startRowKey, endRowKey) {
222
198
  * @param {String} endRowKey - row key value of the last row that was selected (end of the interval)
223
199
  */
224
200
  function markDeselectedRowsInterval(state, startRowKey, endRowKey) {
225
- const rows = getRows(state);
201
+ const { rows, selectedRowsKeys } = state;
226
202
  const { start, end } = getRowIntervalIndexes(state, startRowKey, endRowKey);
227
203
 
228
204
  for (let rowIndex = start; rowIndex <= end; rowIndex += 1) {
229
- markRowDeselected(state, rows[rowIndex].key);
205
+ const row = rows[rowIndex];
206
+ setRowSelectedAttributes(row, false);
207
+ // Setting to `false` instead of using `delete` for better performance.
208
+ selectedRowsKeys[row.key] = false;
209
+ if (getCurrentSelectionLength(state) === state.maxRowSelection - 1) {
210
+ markDeselectedRowEnabled(state);
211
+ }
230
212
  }
231
213
  }
232
214
 
@@ -249,12 +231,13 @@ function markDeselectedRowsInterval(state, startRowKey, endRowKey) {
249
231
  export function markRowSelected(state, rowKeyValue) {
250
232
  const row = getRowByKey(state, rowKeyValue);
251
233
  const prevSelectionLength = getCurrentSelectionLength(state);
252
- const total = getMaxRowSelection(state) || getRowsTotal(state);
234
+ const total = state.maxRowSelection || state.rows.length;
253
235
 
254
- setRowSelectedAttributes(true, row);
236
+ setRowSelectedAttributes(row, true);
255
237
 
238
+ let { selectedRowsKeys } = state;
256
239
  if (total > 1) {
257
- addKeyToSelectedRowKeys(state, row.key);
240
+ selectedRowsKeys[row.key] = true;
258
241
  if (prevSelectionLength + 1 === total) {
259
242
  markDeselectedRowDisabled(state);
260
243
  }
@@ -262,37 +245,13 @@ export function markRowSelected(state, rowKeyValue) {
262
245
  if (prevSelectionLength === 1) {
263
246
  const prevSelectedRow = getRowByKey(
264
247
  state,
265
- Object.keys(state.selectedRowsKeys)[0]
248
+ Object.keys(selectedRowsKeys)[0]
266
249
  );
267
- setRowSelectedAttributes(false, prevSelectedRow);
268
- resetSelectedRowsKeys(state);
250
+ setRowSelectedAttributes(prevSelectedRow, false);
251
+ selectedRowsKeys = {};
252
+ state.selectedRowsKeys = selectedRowsKeys;
269
253
  }
270
- addKeyToSelectedRowKeys(state, row.key);
271
- }
272
- }
273
-
274
- /**
275
- * Marks a row with the specified row key value as de-selected. This is done by:
276
- * 1. Sets `isSelected`, `ariaSelected` to false and resolves `classnames`
277
- * to that which reflect that the row is not selected, on the row object.
278
- * These are used by the template to render the appropriate values.
279
- * 2. The row key value of this row is removed from list of selected row keys
280
- * 3. Before the current de-selection, if the remaining unselected rows were
281
- * disabled (max-row-selection was reached), enable all unselected rows
282
- * so that they can be selected.
283
- *
284
- * @param {Object} state - datatable's state object
285
- * @param {String} rowKeyValue - row key value of row to mark selected
286
- */
287
- export function markRowDeselected(state, rowKeyValue) {
288
- const row = getRowByKey(state, rowKeyValue);
289
- const maxRowSelection = getMaxRowSelection(state);
290
-
291
- setRowSelectedAttributes(false, row);
292
- removeKeyFromSelectedRowKeys(state, row.key);
293
-
294
- if (getCurrentSelectionLength(state) === maxRowSelection - 1) {
295
- markDeselectedRowEnabled(state);
254
+ selectedRowsKeys[row.key] = true;
296
255
  }
297
256
  }
298
257
 
@@ -308,7 +267,7 @@ export function markRowDeselected(state, rowKeyValue) {
308
267
  function markRowsSelectedByKeys(state, keys) {
309
268
  for (let i = 0, { length } = keys; i < length; i += 1) {
310
269
  const row = getRowByKey(state, keys[i]);
311
- setRowSelectedAttributes(true, row);
270
+ setRowSelectedAttributes(row, true);
312
271
  }
313
272
  }
314
273
 
@@ -325,7 +284,7 @@ function markRowsSelectedByKeys(state, keys) {
325
284
  function markRowsDeselectedByKeys(state, keys) {
326
285
  for (let i = 0, { length } = keys; i < length; i += 1) {
327
286
  const row = getRowByKey(state, keys[i]);
328
- setRowSelectedAttributes(false, row);
287
+ setRowSelectedAttributes(row, false);
329
288
  }
330
289
  }
331
290
 
@@ -338,10 +297,10 @@ function markRowsDeselectedByKeys(state, keys) {
338
297
  * @param {Object} state - datatable's state object
339
298
  */
340
299
  export function markDeselectedRowDisabled(state) {
341
- const rows = getRows(state);
300
+ const { rows, selectedRowsKeys } = state;
342
301
  for (let i = 0, { length: rowCount } = rows; i < rowCount; i += 1) {
343
302
  const row = rows[i];
344
- if (!isSelectedRow(state, row.key)) {
303
+ if (!selectedRowsKeys[row.key]) {
345
304
  row.isDisabled = true;
346
305
  }
347
306
  }
@@ -357,10 +316,10 @@ export function markDeselectedRowDisabled(state) {
357
316
  * @param {Object} state - The datatable state
358
317
  */
359
318
  export function markDeselectedRowEnabled(state) {
360
- const rows = getRows(state);
319
+ const { rows, selectedRowsKeys } = state;
361
320
  for (let i = 0, { length: rowCount } = rows; i < rowCount; i += 1) {
362
321
  const row = rows[i];
363
- if (!isSelectedRow(state, row.key)) {
322
+ if (!selectedRowsKeys[row.key]) {
364
323
  row.isDisabled = false;
365
324
  }
366
325
  }
@@ -388,12 +347,12 @@ export function markDeselectedRowEnabled(state) {
388
347
  * If the previous selection had reached the max limit and the new selection
389
348
  * is less than the limit, re-enable the de-selected rows to allow for new selection.
390
349
  *
391
- * @param {Object} state - datatable's state object
350
+ * @param {Object} state - The datatable state
392
351
  * @param {Array} value - key-field values of rows to set as selected
393
352
  */
394
353
  export function setSelectedRowsKeys(state, value) {
395
354
  if (Array.isArray(value)) {
396
- const maxRowSelection = getMaxRowSelection(state);
355
+ const { maxRowSelection } = state;
397
356
  const previousSelectionLength = getCurrentSelectionLength(state);
398
357
  let selectedRows = filterValidKeys(state, value);
399
358
  if (selectedRows.length > maxRowSelection) {
@@ -447,7 +406,7 @@ export function syncSelectedRowsKeys(state, selectedRows) {
447
406
  let changed = false;
448
407
  const { keyField, selectedRowsKeys } = state;
449
408
  const { length: selectedRowCount } = selectedRows;
450
- if (Object.keys(selectedRowsKeys).length !== selectedRows.length) {
409
+ if (Object.keys(selectedRowsKeys).length !== selectedRowCount) {
451
410
  changed = true;
452
411
  // Untracked state change.
453
412
  state.selectedRowsKeys = updateSelectedRowsKeysFromSelectedRows(
@@ -469,7 +428,7 @@ export function syncSelectedRowsKeys(state, selectedRows) {
469
428
  }
470
429
  }
471
430
  if (changed) {
472
- const total = getMaxRowSelection(state) || getRowsTotal(state);
431
+ const total = state.maxRowSelection || state.rows.length;
473
432
  if (total > 1) {
474
433
  // Tracked state changes.
475
434
  if (selectedRowCount < total) {
@@ -481,7 +440,6 @@ export function syncSelectedRowsKeys(state, selectedRows) {
481
440
  }
482
441
  // Tracked state change.
483
442
  updateBulkSelectionState(state);
484
-
485
443
  return {
486
444
  ifChanged(callback) {
487
445
  if (changed && typeof callback === 'function') {
@@ -500,16 +458,6 @@ function updateSelectedRowsKeysFromSelectedRows(selectedRows, keyField) {
500
458
  return selectedRowsKeys;
501
459
  }
502
460
 
503
- function addKeyToSelectedRowKeys(state, key) {
504
- state.selectedRowsKeys[key] = true;
505
- }
506
-
507
- function removeKeyFromSelectedRowKeys(state, key) {
508
- // not using delete this.state.selectedRowsKeys[key]
509
- // because that causes perf issues
510
- state.selectedRowsKeys[key] = false;
511
- }
512
-
513
461
  function normalizeSelectedRowsKey(keys) {
514
462
  const selectedRowsKeys = {};
515
463
  for (let i = 0, { length } = keys; i < length; i += 1) {
@@ -520,19 +468,19 @@ function normalizeSelectedRowsKey(keys) {
520
468
 
521
469
  function filterValidKeys(state, keys) {
522
470
  const filtered = [];
523
- for (let i = 0, { length } = keys; i < length; i += 1) {
524
- const key = keys[i];
525
- if (rowKeyExists(state, key)) {
526
- filtered.push(key);
471
+ const { rows } = state;
472
+ if (rows.length) {
473
+ const { indexes } = state;
474
+ for (let i = 0, { length } = keys; i < length; i += 1) {
475
+ const key = keys[i];
476
+ if (indexes[key]) {
477
+ filtered.push(key);
478
+ }
527
479
  }
528
480
  }
529
481
  return filtered;
530
482
  }
531
483
 
532
- export function resetSelectedRowsKeys(state) {
533
- state.selectedRowsKeys = {};
534
- }
535
-
536
484
  /************************** LAST SELECTED ROW KEYS **************************/
537
485
 
538
486
  /**
@@ -551,10 +499,6 @@ function getLastRowSelection(state) {
551
499
  return keyIsValid ? lastSelectedRowKey : undefined;
552
500
  }
553
501
 
554
- function setLastRowSelection(state, rowKeyValue) {
555
- state.lastSelectedRowKey = rowKeyValue;
556
- }
557
-
558
502
  /************************** INPUT TYPES **************************/
559
503
 
560
504
  /**
@@ -579,14 +523,18 @@ export function inputTypeNeedsToChange(
579
523
  previousMaxRowSelection === 0 ||
580
524
  newMaxRowSelection === 0 ||
581
525
  (previousMaxRowSelection === 1 &&
582
- isMultiSelection(newMaxRowSelection)) ||
583
- (newMaxRowSelection === 1 && isMultiSelection(previousMaxRowSelection))
526
+ // is newMaxRowSelection multi-selection
527
+ (newMaxRowSelection > 1 || newMaxRowSelection === undefined)) ||
528
+ (newMaxRowSelection === 1 &&
529
+ // is previousMaxRowSelection multi-selection
530
+ (previousMaxRowSelection > 1 ||
531
+ previousMaxRowSelection === undefined))
584
532
  );
585
533
  }
586
534
 
587
535
  export function updateRowSelectionInputType(state) {
588
- const type = getRowSelectionInputType(state);
589
- const rows = getRows(state);
536
+ const type = state.maxRowSelection === 1 ? 'radio' : 'checkbox';
537
+ const { rows } = state;
590
538
 
591
539
  for (let i = 0, { length: rowCount } = rows; i < rowCount; i += 1) {
592
540
  // Tracked state changes.
@@ -614,10 +562,10 @@ export function setMaxRowSelection(state, value) {
614
562
  // Tracked state changes.
615
563
  markAllRowsDeselected(state);
616
564
  if (isNonNegativeInteger(value)) {
617
- const previousMaxRowSelection = getMaxRowSelection(state);
565
+ const previousMaxRowSelection = state.maxRowSelection;
566
+ const newMaxRowSelection = Number(value);
618
567
  // Untracked state change.
619
- state.maxRowSelection = Number(value);
620
- const newMaxRowSelection = getMaxRowSelection(state);
568
+ state.maxRowSelection = newMaxRowSelection;
621
569
  // Reselect up to maxRowSelection rows.
622
570
  const numberOfRows = Math.min(
623
571
  previousSelectedRowsKeys.length,
@@ -628,10 +576,7 @@ export function setMaxRowSelection(state, value) {
628
576
  markRowSelected(state, previousSelectedRowsKeys[i]);
629
577
  }
630
578
  if (
631
- inputTypeNeedsToChange(
632
- previousMaxRowSelection,
633
- getMaxRowSelection(state)
634
- )
579
+ inputTypeNeedsToChange(previousMaxRowSelection, newMaxRowSelection)
635
580
  ) {
636
581
  // Tracked state changes.
637
582
  updateRowSelectionInputType(state);
@@ -653,28 +598,31 @@ export function setMaxRowSelection(state, value) {
653
598
  /************************** BULK SELECTION STATE **************************/
654
599
 
655
600
  export function updateBulkSelectionState(state) {
656
- const { columns } = state;
657
- const colIndex = getSelectBoxesColumnIndex(state);
658
- if (colIndex >= 0) {
601
+ const columns = state.columns || {};
602
+ for (let colIndex = 0; colIndex < columns.length; colIndex += 1) {
659
603
  const col = columns[colIndex];
660
- const updatedCol = Object.assign({}, col);
661
- updatedCol.bulkSelection = getBulkSelectionState(state);
662
- updatedCol.isBulkSelectionDisabled = isBulkSelectionDisabled(state);
663
- columns[colIndex] = updatedCol;
664
- }
665
- }
666
-
667
- function getBulkSelectionState(state) {
668
- const total = getMaxRowSelection(state) || getRowsTotal(state);
669
- const selected = getCurrentSelectionLength(state);
670
- if (selected) {
671
- return selected === total ? 'all' : 'some';
604
+ if (col.type === SELECTABLE_HEADER_TYPE) {
605
+ const {
606
+ maxRowSelection,
607
+ rows: { length: rowCount },
608
+ } = state;
609
+ const total = maxRowSelection || rowCount;
610
+ const selected = getCurrentSelectionLength(state);
611
+ // Force a rerender of this column by replacing the tracked object.
612
+ // Required to pass treegrid unit tests.
613
+ const updatedCol = Object.assign({}, col);
614
+ if (selected) {
615
+ updatedCol.bulkSelection = selected === total ? 'all' : 'some';
616
+ } else {
617
+ updatedCol.bulkSelection = 'none';
618
+ }
619
+ updatedCol.isBulkSelectionDisabled =
620
+ maxRowSelection === 0 || rowCount === 0;
621
+ // Replace old column with shallow cloned and updated column.
622
+ columns[colIndex] = updatedCol;
623
+ return;
624
+ }
672
625
  }
673
- return 'none';
674
- }
675
-
676
- function isBulkSelectionDisabled(state) {
677
- return getRowsTotal(state) === 0 || getMaxRowSelection(state) === 0;
678
626
  }
679
627
 
680
628
  /************************** HELPER FUNCTIONS **************************/
@@ -692,7 +640,9 @@ function isBulkSelectionDisabled(state) {
692
640
  */
693
641
  function getRowIntervalIndexes(state, startRowKey, endRowKey) {
694
642
  const start =
695
- startRowKey === 'HEADER' ? 0 : getRowIndexByKey(state, startRowKey);
643
+ startRowKey === HEADER_ROW_KEY
644
+ ? 0
645
+ : getRowIndexByKey(state, startRowKey);
696
646
  const end = getRowIndexByKey(state, endRowKey);
697
647
 
698
648
  return {
@@ -745,13 +695,15 @@ export function unsetAriaSelectedOnCell(state, rowKeyValue, colKeyValue) {
745
695
  * to one which reflects the selected value of the row on the row object.
746
696
  * These are used by the template to render the appropriate values.
747
697
  *
748
- * @param {Boolean} selectedValue - Whether the row is selected
749
698
  * @param {Object} row - The row
699
+ * @param {Boolean} selectedValue - Whether the row is selected
750
700
  */
751
- function setRowSelectedAttributes(selectedValue, row) {
752
- row.isSelected = selectedValue;
701
+ function setRowSelectedAttributes(row, selectedValue) {
753
702
  row.ariaSelected = selectedValue;
754
- row.classnames = resolveRowClassNames(row);
703
+ row.classnames = `slds-hint-parent${
704
+ selectedValue ? ' slds-is-selected' : ''
705
+ }`;
706
+ row.isSelected = selectedValue;
755
707
  }
756
708
 
757
709
  function getSelectedDiff(state, selectedRows) {
@@ -778,38 +730,3 @@ function getDeselectedDiff(state, value) {
778
730
  }
779
731
  return filtered;
780
732
  }
781
-
782
- function getSelectBoxesColumnIndex(state) {
783
- const columns = getColumns(state) || [];
784
- for (let colIndex = 0; colIndex < columns.length; colIndex += 1) {
785
- const col = columns[colIndex];
786
- if (col.type === SELECTABLE_ROW_CHECKBOX) {
787
- return colIndex;
788
- }
789
- }
790
- return -1;
791
- }
792
-
793
- /**
794
- * Represents whether the select all rows checkbox on the header
795
- * should be visible or not.
796
- * If max-row-selection = 1, then the select all rows checkbox
797
- * should not be visible/rendered.
798
- *
799
- * @param {Object} state - datatable's state object
800
- * @returns
801
- */
802
- export function getHideSelectAllCheckbox(state) {
803
- return getMaxRowSelection(state) === 1;
804
- }
805
-
806
- /**
807
- * Represents whether the datatable should enable multiselection or not
808
- * depending on the max-row-selection value passed in
809
- *
810
- * @param {Number} value - max-row-selection value
811
- * @returns
812
- */
813
- function isMultiSelection(value) {
814
- return value > 1 || value === undefined;
815
- }
@@ -1,3 +1,5 @@
1
+ export const SELECTABLE_HEADER_TYPE = 'SELECTABLE_CHECKBOX';
2
+
1
3
  /**
2
4
  * This file exists in order to get around circular dependencies.
3
5
  * In this case, rowSelection.js has a dependency on rows.js;
@@ -32,8 +34,8 @@ export function isSelectedRow(state, rowKeyValue) {
32
34
  * @returns {Boolean} Whether the row should be disabled or not
33
35
  */
34
36
  export function isDisabledRow(state, rowKeyValue) {
35
- if (!isSelectedRow(state, rowKeyValue)) {
36
- const maxRowSelection = getMaxRowSelection(state);
37
+ if (!state.selectedRowsKeys[rowKeyValue]) {
38
+ const { maxRowSelection } = state;
37
39
 
38
40
  // when selection is 1, we should not disable selection
39
41
  return (
@@ -45,30 +47,6 @@ export function isDisabledRow(state, rowKeyValue) {
45
47
  return false;
46
48
  }
47
49
 
48
- /**
49
- * Returns which input type to use for row selection.
50
- * If `max-row-selection` is 1, use radio buttons. Otherwise, use checkboxes.
51
- *
52
- * @param {Object} state Datatable state object
53
- * @returns {String} `radio` is only one row is allowed to be selected, otherwise `checkbox`
54
- */
55
- export function getRowSelectionInputType(state) {
56
- if (getMaxRowSelection(state) === 1) {
57
- return 'radio';
58
- }
59
- return 'checkbox';
60
- }
61
-
62
- /**
63
- * Retrieves the maximum number of rows that can be selected from state.
64
- *
65
- * @param {Object} state Datatable state object
66
- * @returns {Integer} The maximum rows that can be selected
67
- */
68
- export function getMaxRowSelection(state) {
69
- return state.maxRowSelection;
70
- }
71
-
72
50
  /**
73
51
  * Determines the number of rows currently selected.
74
52
  *
@@ -76,7 +54,15 @@ export function getMaxRowSelection(state) {
76
54
  * @returns {Integer} The number of currently selected rows
77
55
  */
78
56
  export function getCurrentSelectionLength(state) {
79
- return getSelectedRowsKeys(state).length;
57
+ let filteredLength = 0;
58
+ const { selectedRowsKeys } = state;
59
+ const keys = Object.keys(selectedRowsKeys);
60
+ for (let i = 0, { length } = keys; i < length; i += 1) {
61
+ if (selectedRowsKeys[keys[i]]) {
62
+ filteredLength += 1;
63
+ }
64
+ }
65
+ return filteredLength;
80
66
  }
81
67
 
82
68
  /**