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,127 +1,34 @@
1
+ import labelRowNumber from '@salesforce/label/LightningDatatable.rowNumber';
2
+ import rowActionsDefaultAriaLabel from '@salesforce/label/LightningDatatable.rowActionsDefaultAriaLabel';
1
3
  import { normalizeBoolean } from 'lightning/utilsPrivate';
2
4
  import { isObjectLike } from './utils';
3
- import {
4
- getRowNumberColumnDef,
5
- hasRowNumberColumn,
6
- setShowRowNumberColumn,
7
- } from './rowNumber';
8
- import { isTreeType, isValidTypeForTree } from './types';
9
- import { updateColumnSortingState } from './sort';
10
- import rowActionsDefaultAriaLabel from '@salesforce/label/LightningDatatable.rowActionsDefaultAriaLabel';
5
+ import { ROW_NUMBER_INITIAL_WIDTH } from './rowNumber';
6
+ import { SELECTABLE_HEADER_TYPE } from './rowSelectionShared';
11
7
 
12
8
  const i18n = {
13
9
  rowActionsDefaultAriaLabel,
10
+ rowNumber: labelRowNumber,
14
11
  };
15
12
 
16
- export const SELECTABLE_ROW_CHECKBOX = 'SELECTABLE_CHECKBOX';
13
+ const ROW_NUMBER_COLUMN = {
14
+ type: 'rowNumber',
15
+ ariaLabel: i18n.rowNumber,
16
+ initialWidth: ROW_NUMBER_INITIAL_WIDTH,
17
+ internal: true,
18
+ minWidth: 52,
19
+ maxWidth: 1000,
20
+ resizable: false,
21
+ sortable: false,
22
+ tabIndex: -1,
23
+ };
17
24
 
18
25
  const SELECTABLE_COLUMN = {
19
- type: SELECTABLE_ROW_CHECKBOX,
26
+ type: SELECTABLE_HEADER_TYPE,
20
27
  fixedWidth: 32,
21
- tabIndex: -1,
22
28
  internal: true,
29
+ tabIndex: -1,
23
30
  };
24
31
 
25
- /**
26
- * Returns the columns default state.
27
- *
28
- * @returns {Object} The default column state.
29
- */
30
- export function getColumnsDefaultState() {
31
- return {
32
- columns: [],
33
- };
34
- }
35
-
36
- /**
37
- * Returns whether or not the datatable has columns.
38
- *
39
- * @param {Object} state The datatable's state.
40
- * @returns {Boolean} Whether the datatable has columns.
41
- */
42
- export function hasColumns(state) {
43
- return getColumns(state).length > 0;
44
- }
45
-
46
- /**
47
- * Returns whether or not the column has been specified by the customer.
48
- *
49
- * @param {Object} column The column definition object.
50
- * @returns {Boolean} Whether the column is customer defined or not.
51
- */
52
- export function isCustomerColumn(column) {
53
- return column.internal !== true;
54
- }
55
-
56
- /**
57
- * Returns the datatable's columns from state.
58
- *
59
- * @param {Object} state The datatable's state.
60
- * @returns {Array} The datatable's columns definition.
61
- */
62
- export function getColumns(state) {
63
- return state.columns;
64
- }
65
-
66
- /**
67
- * Returns whether any of the datatable's columns are editable.
68
- *
69
- * @param {Array} columns The datatable's column definition.
70
- * @returns {Boolean} Whether any of the columns are editable.
71
- */
72
- export function hasEditableColumn(columns) {
73
- const { length: colCount } = columns;
74
- for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
75
- if (columns[colIndex].editable) {
76
- return true;
77
- }
78
- }
79
- return false;
80
- }
81
-
82
- /**
83
- * Given an array of column definitions, returns a filtered array containing only those
84
- * elements from the original array that are editable. For any two columns, C_1 and C_2,
85
- * that are present in both the input and output array, the relative ordering between
86
- * them that existed in the input array is maintained in the output array.
87
- *
88
- * @param {Array} columns The datatable's column definition. Must be truthy and must be
89
- * filled with truthy column definition objects.
90
- */
91
- export function getEditableColumns(columns) {
92
- const editableColumns = [];
93
- for (let i = 0, { length } = columns; i < length; i += 1) {
94
- const col = columns[i];
95
- if (col.editable) {
96
- editableColumns.push(col);
97
- }
98
- }
99
- return editableColumns;
100
- }
101
-
102
- /**
103
- * Normalizes the editable property of the column after checking whether the column type
104
- * is a valid editable standard type or if it's a customType and uses standardCellLayout.
105
- * If column.editable is associated with an object that also has a 'fieldName' key, then
106
- * the invocation of this function results in a no-op because we instead rely on later
107
- * row level checks to determine cell editability.
108
- *
109
- * @param {Object} column The column definition object.
110
- * @param {Object} types The DatatableTypes object.
111
- */
112
- export function normalizeEditable(column, types) {
113
- if (types.isEditableType(column.type)) {
114
- const { editable } = column;
115
- if (!(editable && editable.fieldName)) {
116
- column.editable = normalizeBoolean(editable);
117
- }
118
- column.editTemplate = types.getCustomTypeEditTemplate(column.type);
119
- } else {
120
- column.editable = false;
121
- column.editTemplate = undefined;
122
- }
123
- }
124
-
125
32
  /**
126
33
  * Steps through and corrects column definitions inconsistencies.
127
34
  *
@@ -132,110 +39,179 @@ export function normalizeEditable(column, types) {
132
39
  * For tree-types, we verify all sub-type attributes are within our allowed
133
40
  * parameters. See `getNormalizedSubTypeAttribute`.
134
41
  *
135
- * @param {Object} state The datatable state.
136
- * @param {Array} columns The datatable's column definitions.
137
- * @param {Object} types The type handling factory.
42
+ * @param {Object} state - The datatable state
43
+ * @param {Array} rawColumns - The user provided column definitions to normalize
44
+ * @param {Object} types - The type handling factory
138
45
  */
139
- export function normalizeColumns(state, columns, types) {
140
- const { length: colCount } = columns;
141
- if (colCount !== 0) {
142
- let firstColumnForReaders = 0;
143
- let normColCount = colCount;
144
- let { showRowNumberColumn } = state;
145
- const notHideCheckboxColumn = !state.hideCheckboxColumn;
46
+ export function normalizeColumns(state, rawColumns, types) {
47
+ const { length: colCount } = rawColumns;
48
+ if (colCount === 0) {
49
+ // Tracked state change.
50
+ state.columns = [];
51
+ return;
52
+ }
53
+ let normColCount = colCount;
54
+ let { showRowNumberColumn } = state;
55
+ const notHideCheckboxColumn = !state.hideCheckboxColumn;
146
56
 
147
- if (notHideCheckboxColumn) {
148
- normColCount += 1;
57
+ if (!showRowNumberColumn) {
58
+ for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
59
+ if (rawColumns[colIndex].editable) {
60
+ showRowNumberColumn = true;
61
+ // Untracked state change.
62
+ state.showRowNumberColumn = true;
63
+ break;
64
+ }
149
65
  }
66
+ }
67
+ if (showRowNumberColumn) {
68
+ normColCount += 1;
69
+ }
70
+ if (notHideCheckboxColumn) {
71
+ normColCount += 1;
72
+ }
73
+ const normalizedColumns = Array(normColCount);
74
+
75
+ // Tracked state change.
76
+ state.columns = normalizedColumns;
77
+
78
+ let firstColumnForReaders = 0;
79
+ if (showRowNumberColumn) {
80
+ normalizedColumns[firstColumnForReaders] = Object.assign(
81
+ {},
82
+ ROW_NUMBER_COLUMN
83
+ );
84
+ firstColumnForReaders += 1;
85
+ }
86
+ if (notHideCheckboxColumn) {
87
+ normalizedColumns[firstColumnForReaders] = Object.assign(
88
+ {},
89
+ SELECTABLE_COLUMN
90
+ );
91
+ firstColumnForReaders += 1;
92
+ }
93
+ for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
94
+ normalizedColumns[colIndex + firstColumnForReaders] =
95
+ rawColumns[colIndex];
96
+ }
150
97
 
151
- if (hasRowNumberColumn(state) || hasEditableColumn(columns)) {
152
- setShowRowNumberColumn(state, true);
153
- normColCount += 1;
154
- }
155
- const normalizedColumns = Array(normColCount);
98
+ const { defaultSortDirection, sortedBy, sortedDirection } = state;
99
+ const seenColumnKeys = new Set();
156
100
 
157
- // Tracked state change.
158
- state.columns = normalizedColumns;
101
+ for (let colIndex = 0; colIndex < normColCount; colIndex += 1) {
102
+ const refCol = normalizedColumns[colIndex];
103
+ const { columnKey } = refCol;
159
104
 
160
- if (notHideCheckboxColumn) {
161
- normalizedColumns[firstColumnForReaders] = Object.assign(
162
- {},
163
- SELECTABLE_COLUMN
105
+ // Verify `columnKey` is unique
106
+ if (columnKey && seenColumnKeys.has(columnKey)) {
107
+ console.error(
108
+ `The "columnKey" column property must be unique. Found a duplicate of columnKey "${columnKey}".`
164
109
  );
165
- firstColumnForReaders += 1;
166
- }
167
- if (showRowNumberColumn) {
168
- normalizedColumns[firstColumnForReaders] = getRowNumberColumnDef();
169
- firstColumnForReaders += 1;
170
110
  }
171
- for (let colIndex = 0; colIndex < colCount; colIndex += 1) {
172
- normalizedColumns[colIndex + firstColumnForReaders] =
173
- columns[colIndex];
111
+ seenColumnKeys.add(columnKey);
112
+
113
+ const { type: refColumnType } = refCol;
114
+ const colName = columnKey || refCol.fieldName;
115
+
116
+ // Normalize columns.
117
+ const normCol = {
118
+ ariaLabel: '',
119
+ cellAttributes: {},
120
+ resizable: true,
121
+ type: 'text',
122
+ typeAttributes: {},
123
+ subType: '',
124
+ };
125
+ if (refColumnType === 'action') {
126
+ normCol.ariaLabel = i18n.rowActionsDefaultAriaLabel;
127
+ normCol.fixedWidth = 50;
128
+ normCol.resizable = false;
129
+ } else if (refColumnType === 'tree') {
130
+ normCol.subType = 'text';
174
131
  }
132
+ Object.assign(normCol, refCol);
175
133
 
176
- const seenColumnKeys = new Set();
177
- for (let colIndex = 0; colIndex < normColCount; colIndex += 1) {
178
- const column = normalizedColumns[colIndex];
179
- const { columnKey } = column;
180
-
181
- // state.columns = normalizedColumns.map((column, index) => {
182
- // Verify `columnKey` is unique
183
- if (columnKey && seenColumnKeys.has(columnKey)) {
184
- console.error(
185
- `The "columnKey" column property must be unique. Found a duplicate of columnKey "${columnKey}".`
186
- );
187
- }
188
- seenColumnKeys.add(columnKey);
134
+ // Store in caches early so data can be referenced by other methods
135
+ // during initialization.
136
+ normalizedColumns[colIndex] = normCol;
189
137
 
190
- const normCol = Object.assign(getColumnDefaults(column), column);
191
- normalizedColumns[colIndex] = normCol;
192
- normCol.ariaLabel = normCol.label || normCol.ariaLabel || null;
138
+ let { type: columnType } = normCol;
193
139
 
194
- let { type: columnType } = normCol;
195
- // `customType` attribute is needed to render default iedit component
196
- normCol.editableCustomType =
197
- types.isStandardCellLayoutForCustomType(columnType);
140
+ normCol.ariaLabel = normCol.label || normCol.ariaLabel || null;
141
+ // `customType` attribute is needed to render default inline edit component
142
+ normCol.editableCustomType =
143
+ types.isStandardCellLayoutForCustomType(columnType);
198
144
 
199
- if (isCustomerColumn(normCol)) {
200
- normalizeColumnDataType(normCol, types);
201
- normalizeEditable(normCol, types);
202
- updateColumnSortingState(normCol, state);
145
+ // normalize customer column
146
+ if (!normCol.internal) {
147
+ // normalize column dataType
148
+ if (!types.isValidType(columnType)) {
149
+ columnType = 'text';
150
+ normCol.type = columnType;
203
151
  }
204
-
205
- if (isTreeType(normCol.type)) {
206
- normCol.typeAttributes = getNormalizedSubTypeAttribute(
207
- normCol.type,
208
- normCol.typeAttributes
209
- );
152
+ // normalize editable
153
+ if (types.isEditableType(columnType)) {
154
+ const { editable } = normCol;
155
+ if (!(editable && editable.fieldName)) {
156
+ normCol.editable = normalizeBoolean(editable);
157
+ }
158
+ normCol.editTemplate =
159
+ types.getCustomTypeEditTemplate(columnType);
160
+ } else {
161
+ normCol.editable = false;
162
+ normCol.editTemplate = undefined;
210
163
  }
164
+ // update column sorting state
165
+ const { sortable } = normCol;
166
+ if (sortable && colName === sortedBy) {
167
+ normCol.sorted = true;
168
+ normCol.sortAriaLabel =
169
+ sortedDirection === 'desc' ? 'descending' : 'ascending';
170
+ normCol.sortedDirection = sortedDirection;
171
+ } else {
172
+ normCol.sorted = false;
173
+ normCol.sortAriaLabel = sortable ? 'other' : null;
174
+ normCol.sortedDirection = defaultSortDirection;
175
+ }
176
+ }
211
177
 
212
- // Generate colKeyValue after normalizing customer column.
213
- normCol.colKeyValue = generateColKeyValue(normCol, colIndex);
214
- normCol.isScopeCol = colIndex === firstColumnForReaders;
215
- normCol.tabIndex = -1;
178
+ // Generate colKeyValue after normalizing customer column.
179
+ normCol.colKeyValue = generateColKeyValue(normCol, colIndex);
180
+ normCol.isScopeCol = colIndex === firstColumnForReaders;
181
+ normCol.isLastCol = colIndex === normColCount - 1;
182
+ normCol.tabIndex = -1;
183
+
184
+ // normalize tree column
185
+ if (normCol.type === 'tree') {
186
+ // normalized subType attributes
187
+ const { typeAttributes } = normCol;
188
+ const typeAttributesOverrides = {};
189
+ if (!types.isValidTypeForTree(typeAttributes.subType)) {
190
+ typeAttributesOverrides.subType = 'text';
191
+ }
192
+ if (!typeAttributes.subTypeAttributes) {
193
+ typeAttributesOverrides.subTypeAttributes = {};
194
+ }
195
+ normCol.typeAttributes = Object.assign(
196
+ {},
197
+ typeAttributes,
198
+ typeAttributesOverrides
199
+ );
216
200
  }
217
- } else {
218
- state.columns = [];
219
- }
220
- }
221
201
 
222
- /**
223
- * Normalizes the subType and subTypeAttributes in the typeAttributes.
224
- *
225
- * @param {String} type The type of this column
226
- * @param {Object} typeAttributes The type attributes of the column
227
- * @returns {Object} A new typeAttributes object with the sybtype and subTypeAttributes normalized.
228
- */
229
- export function getNormalizedSubTypeAttribute(type, typeAttributes) {
230
- const typeAttributesOverrides = {};
231
- if (!isValidTypeForTree(typeAttributes.subType)) {
232
- typeAttributesOverrides.subType = getColumnDefaults({ type }).subType;
202
+ // partially inline updateHeaderInternalActions from datatable/headerActions
203
+ const { actions } = normCol;
204
+ const isLastColumn = colIndex === normColCount - 1;
205
+ normCol.actions = {
206
+ menuAlignment:
207
+ isLastColumn ||
208
+ normalizedColumns[colIndex + 1].type === 'action'
209
+ ? 'auto-right'
210
+ : 'auto-left',
211
+ customerActions: Array.isArray(actions) ? actions : [],
212
+ internalActions: undefined,
213
+ };
233
214
  }
234
- if (!typeAttributes.subTypeAttributes) {
235
- typeAttributesOverrides.subTypeAttributes = {};
236
- }
237
-
238
- return Object.assign({}, typeAttributes, typeAttributesOverrides);
239
215
  }
240
216
 
241
217
  /**
@@ -245,10 +221,8 @@ export function getNormalizedSubTypeAttribute(type, typeAttributes) {
245
221
  * @returns Type attributes for the given column, if they exist.
246
222
  */
247
223
  export function getTypeAttributesValues(column) {
248
- if (isObjectLike(column.typeAttributes)) {
249
- return column.typeAttributes;
250
- }
251
- return {};
224
+ const { typeAttributes } = column;
225
+ return isObjectLike(typeAttributes) ? typeAttributes : {};
252
226
  }
253
227
 
254
228
  /**
@@ -258,10 +232,8 @@ export function getTypeAttributesValues(column) {
258
232
  * @returns {Object} Sub-type attributes for the given column, if they exist.
259
233
  */
260
234
  export function getSubTypeAttributesValues(column) {
261
- if (isObjectLike(column.typeAttributes.subTypeAttributes)) {
262
- return column.typeAttributes.subTypeAttributes;
263
- }
264
- return {};
235
+ const { subTypeAttributes } = column.typeAttributes;
236
+ return isObjectLike(subTypeAttributes) ? subTypeAttributes : {};
265
237
  }
266
238
 
267
239
  /**
@@ -271,10 +243,8 @@ export function getSubTypeAttributesValues(column) {
271
243
  * @returns {Object} Cell attributes for the given column, if they exist.
272
244
  */
273
245
  export function getCellAttributesValues(column) {
274
- if (isObjectLike(column.cellAttributes)) {
275
- return column.cellAttributes;
276
- }
277
- return {};
246
+ const { cellAttributes } = column;
247
+ return isObjectLike(cellAttributes) ? cellAttributes : {};
278
248
  }
279
249
 
280
250
  /**
@@ -300,14 +270,14 @@ export function generateColKeyValue(columnMetadata, index) {
300
270
  */
301
271
  export function getUserColumnIndex(state, colKeyValue) {
302
272
  const { columns } = state;
303
- const colIndex = getStateColumnIndex(state, colKeyValue);
273
+ const colIndex = state.headerIndexes[colKeyValue];
304
274
  if (columns[colIndex].internal) {
305
275
  return -1;
306
276
  }
307
277
  let internalColumns = 0;
308
278
  for (let i = 0; i < colIndex; i += 1) {
309
279
  if (columns[i].internal) {
310
- internalColumns++;
280
+ internalColumns += 1;
311
281
  }
312
282
  }
313
283
 
@@ -341,95 +311,3 @@ export const generateHeaderIndexes = function (columns) {
341
311
  export function getStateColumnIndex(state, colKeyValue) {
342
312
  return state.headerIndexes[colKeyValue];
343
313
  }
344
-
345
- /**
346
- * Retrieves a column index number by its key.
347
- *
348
- * @param {Object} state The datatable state
349
- * @param {String} key The key of the column. Defaults to field name if 'columnKey' is not provided.
350
- * @returns {Number} The index in state.columns, -1 if it does not exist
351
- */
352
- export function getColumnIndexByColumnKey(state, key) {
353
- const columns = getColumns(state);
354
- for (let colIndex = 0; colIndex < columns.length; colIndex += 1) {
355
- const col = columns[colIndex];
356
- if (
357
- col.columnKey === key ||
358
- (!col.columnKey && col.fieldName === key)
359
- ) {
360
- return colIndex;
361
- }
362
- }
363
- return -1;
364
- }
365
-
366
- /************************** PRIVATE METHODS ***************************/
367
-
368
- /**
369
- * If the specified column type is not supported, resets it to default.
370
- *
371
- * @param {Object} column The column definition object.
372
- * @param {Object} types The type handling factory.
373
- */
374
- function normalizeColumnDataType(column, types) {
375
- if (!types.isValidType(column.type)) {
376
- column.type = getRegularColumnDefaults().type;
377
- }
378
- }
379
-
380
- /**
381
- * Returns the column defaults based on its type.
382
- *
383
- * @param {Object} column The column definition object.
384
- * @returns {Object} The column defaults.
385
- */
386
- function getColumnDefaults(column) {
387
- switch (column.type) {
388
- case 'action':
389
- return getActionColumnDefaults();
390
- case 'tree':
391
- return getTreeColumnDefaults();
392
- default:
393
- return getRegularColumnDefaults();
394
- }
395
- }
396
-
397
- /**
398
- * Retrieves the defaults for regular columns.
399
- *
400
- * @returns {Object} Regular column defaults
401
- */
402
- function getRegularColumnDefaults() {
403
- return {
404
- type: 'text',
405
- typeAttributes: {},
406
- cellAttributes: {},
407
- };
408
- }
409
-
410
- /**
411
- * Retrieves the defaults for action columns.
412
- *
413
- * @returns {Object} Action column defaults
414
- */
415
- function getActionColumnDefaults() {
416
- return {
417
- fixedWidth: 50,
418
- resizable: false,
419
- ariaLabel: i18n.rowActionsDefaultAriaLabel,
420
- };
421
- }
422
-
423
- /**
424
- * Retrieves the defaults for tree columns.
425
- *
426
- * @returns {Object} Tree column defaults
427
- */
428
- function getTreeColumnDefaults() {
429
- return {
430
- type: 'tree',
431
- subType: 'text',
432
- typeAttributes: {},
433
- cellAttributes: {},
434
- };
435
- }