lightning-base-components 1.14.6-alpha → 1.14.7-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 (115) hide show
  1. package/metadata/raptor.json +5 -3
  2. package/package.json +8 -1
  3. package/scopedImports/@salesforce-label-LightningProgressBar.progressBar.js +1 -0
  4. package/src/lightning/alert/__docs__/alert.md +101 -0
  5. package/src/lightning/alert/__examples__disabled/basic/basic.css +7 -0
  6. package/src/lightning/alert/__examples__disabled/basic/basic.html +8 -0
  7. package/src/lightning/alert/__examples__disabled/basic/basic.js +14 -0
  8. package/src/lightning/alert/alert.html +3 -0
  9. package/src/lightning/alert/alert.js +78 -0
  10. package/src/lightning/alert/alert.js-meta.xml +6 -0
  11. package/src/lightning/buttonMenu/buttonMenu.js +12 -0
  12. package/src/lightning/confirm/__docs__/confirm.md +100 -0
  13. package/src/lightning/confirm/__examples__disabled/basic/basic.css +7 -0
  14. package/src/lightning/confirm/__examples__disabled/basic/basic.html +8 -0
  15. package/src/lightning/confirm/__examples__disabled/basic/basic.js +14 -0
  16. package/src/lightning/confirm/confirm.html +3 -0
  17. package/src/lightning/confirm/confirm.js +80 -0
  18. package/src/lightning/confirm/confirm.js-meta.xml +6 -0
  19. package/src/lightning/datatable/columns.js +166 -71
  20. package/src/lightning/datatable/datatable.js +94 -20
  21. package/src/lightning/datatable/headerActions.js +2 -2
  22. package/src/lightning/datatable/keyboard.js +10 -10
  23. package/src/lightning/datatable/renderManager.js +45 -13
  24. package/src/lightning/datatable/resizeSensor.js +11 -3
  25. package/src/lightning/datatable/rowSelection.js +1 -1
  26. package/src/lightning/datatable/rowSelectionShared.js +33 -20
  27. package/src/lightning/datatable/rows.js +1 -2
  28. package/src/lightning/datatable/sort.js +8 -8
  29. package/src/lightning/datatable/state.js +8 -1
  30. package/src/lightning/datatable/tree.js +25 -0
  31. package/src/lightning/datatable/types.js +77 -9
  32. package/src/lightning/datatable/utils.js +51 -24
  33. package/src/lightning/datatable/virtualization.js +319 -0
  34. package/src/lightning/datatable/wrapText.js +53 -16
  35. package/src/lightning/iconSvgTemplates/buildTemplates/standard/dashboard_component.html +7 -0
  36. package/src/lightning/iconSvgTemplates/buildTemplates/standard/slack.html +7 -0
  37. package/src/lightning/iconSvgTemplates/buildTemplates/standard/tableau.html +7 -0
  38. package/src/lightning/iconSvgTemplates/buildTemplates/standard/travel_mode.html +2 -2
  39. package/src/lightning/iconSvgTemplates/buildTemplates/templates.js +8 -1
  40. package/src/lightning/iconSvgTemplates/buildTemplates/utility/data_model.html +7 -0
  41. package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product.html +1 -1
  42. package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product_transaction.html +2 -1
  43. package/src/lightning/iconSvgTemplates/buildTemplates/utility/slack.html +7 -0
  44. package/src/lightning/iconSvgTemplates/buildTemplates/utility/tableau.html +7 -0
  45. package/src/lightning/iconSvgTemplates/buildTemplates/utility/video_off.html +7 -0
  46. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/dashboard_component.html +7 -0
  47. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/slack.html +7 -0
  48. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/tableau.html +7 -0
  49. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/travel_mode.html +2 -2
  50. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/templates.js +8 -1
  51. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/data_model.html +7 -0
  52. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product.html +1 -1
  53. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
  54. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/slack.html +7 -0
  55. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/tableau.html +7 -0
  56. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/video_off.html +7 -0
  57. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/dashboard_component.html +7 -0
  58. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/slack.html +7 -0
  59. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/tableau.html +7 -0
  60. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/travel_mode.html +2 -2
  61. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/templates.js +4 -1
  62. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/dashboard_component.html +7 -0
  63. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/slack.html +7 -0
  64. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/tableau.html +7 -0
  65. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/travel_mode.html +2 -2
  66. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/templates.js +4 -1
  67. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/templates.js +5 -1
  68. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/data_model.html +7 -0
  69. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product.html +1 -1
  70. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product_transaction.html +2 -1
  71. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/slack.html +7 -0
  72. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/tableau.html +7 -0
  73. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/video_off.html +7 -0
  74. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/templates.js +5 -1
  75. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/data_model.html +7 -0
  76. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product.html +1 -1
  77. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
  78. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/slack.html +7 -0
  79. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/tableau.html +7 -0
  80. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/video_off.html +7 -0
  81. package/src/lightning/input/__docs__/input.md +2 -0
  82. package/src/lightning/interactiveDialogBase/interactiveDialogBase.css +494 -0
  83. package/src/lightning/interactiveDialogBase/interactiveDialogBase.html +63 -0
  84. package/src/lightning/interactiveDialogBase/interactiveDialogBase.js +200 -0
  85. package/src/lightning/menuItem/menuItem.js +4 -1
  86. package/src/lightning/modalBase/modalBase.css +20 -0
  87. package/src/lightning/modalBase/modalBase.html +54 -0
  88. package/src/lightning/modalBase/modalBase.js +1039 -0
  89. package/src/lightning/overlay/__docs__/overlay.md +90 -0
  90. package/src/lightning/overlay/__examples__/alert/alert.html +27 -0
  91. package/src/lightning/overlay/__examples__/alert/alert.js +33 -0
  92. package/src/lightning/overlay/__examples__/basic/basic.css +7 -0
  93. package/src/lightning/overlay/__examples__/basic/basic.html +18 -0
  94. package/src/lightning/overlay/__examples__/basic/basic.js +61 -0
  95. package/src/lightning/overlay/__examples__/demo/demo.html +29 -0
  96. package/src/lightning/overlay/__examples__/demo/demo.js +40 -0
  97. package/src/lightning/overlay/__examples__/panel/panel.html +17 -0
  98. package/src/lightning/overlay/__examples__/panel/panel.js +21 -0
  99. package/src/lightning/overlay/overlay.html +3 -0
  100. package/src/lightning/overlay/overlay.js +45 -0
  101. package/src/lightning/overlayContainer/__docs__/overlayContainer.md +0 -0
  102. package/src/lightning/overlayContainer/overlayContainer.html +3 -0
  103. package/src/lightning/overlayContainer/overlayContainer.js +138 -0
  104. package/src/lightning/overlayManager/overlayManager.js +54 -0
  105. package/src/lightning/overlayUtils/overlayUtils.js +17 -0
  106. package/src/lightning/progressBar/progressBar.html +2 -1
  107. package/src/lightning/progressBar/progressBar.js +18 -1
  108. package/src/lightning/prompt/__docs__/prompt.md +102 -0
  109. package/src/lightning/prompt/__examples__disabled/basic/basic.css +7 -0
  110. package/src/lightning/prompt/__examples__disabled/basic/basic.html +8 -0
  111. package/src/lightning/prompt/__examples__disabled/basic/basic.js +15 -0
  112. package/src/lightning/prompt/prompt.css +81 -0
  113. package/src/lightning/prompt/prompt.html +8 -0
  114. package/src/lightning/prompt/prompt.js +92 -0
  115. package/src/lightning/prompt/prompt.js-meta.xml +6 -0
@@ -1,6 +1,7 @@
1
1
  import { getScrollOffsetFromTableEnd, normalizeNumberAttribute } from './utils';
2
2
  import { LightningResizeObserver } from 'lightning/resizeObserver';
3
3
  import { normalizeBoolean, normalizeString } from 'lightning/utilsPrivate';
4
+ import { resetRowHeights } from './virtualization';
4
5
 
5
6
  export const DEFAULT_ROW_HEIGHT = 30.5;
6
7
  const DEFAULT_BUFFER_SIZE = 5;
@@ -31,17 +32,6 @@ export function getDTWrapperHeight() {
31
32
  return this.template.querySelector('.slds-scrollable_x').offsetHeight;
32
33
  }
33
34
 
34
- /**
35
- * Sets the first visible index in the datatable state based on
36
- * a given scrollTop value and the current rowHeight
37
- *
38
- * @param {Object} state - datatable state
39
- * @param {Number} scrollTop - scroll top to calculate first visible index for
40
- */
41
- export function setFirstVisibleIndex(state, scrollTop) {
42
- state.firstVisibleIndex = Math.floor(scrollTop / state.rowHeight);
43
- }
44
-
45
35
  function getDefaultPreviousInfo() {
46
36
  return {
47
37
  renderedRowCount: 0,
@@ -81,7 +71,13 @@ export class RenderManager {
81
71
  * @param {RenderManagerConfig} config - set of properties used for render management
82
72
  */
83
73
  configure(state, getWrapperHeight, config) {
84
- const { viewportRendering, rowHeight, virtualize, bufferSize } = config;
74
+ const {
75
+ viewportRendering,
76
+ rowHeight,
77
+ virtualize,
78
+ bufferSize,
79
+ fixedHeight,
80
+ } = config;
85
81
  setVirtualize(state, virtualize);
86
82
 
87
83
  if (normalizeBoolean(viewportRendering) || state.virtualize) {
@@ -93,6 +89,7 @@ export class RenderManager {
93
89
  'non-negative',
94
90
  DEFAULT_BUFFER_SIZE
95
91
  );
92
+ state.fixedHeight = normalizeBoolean(fixedHeight);
96
93
  if (typeof rowHeight === 'number') {
97
94
  state.rowHeight = rowHeight;
98
95
  this.threshold = ROW_THRESHOLD * state.rowHeight;
@@ -157,9 +154,42 @@ export class RenderManager {
157
154
  * @returns {Object} object with firstIndex and lastIndex of rendered range of rows
158
155
  */
159
156
  getRenderedRange(state) {
160
- const { firstVisibleIndex, bufferSize, renderedRowCount, rows } = state;
157
+ const {
158
+ firstVisibleIndex,
159
+ bufferSize,
160
+ renderedRowCount,
161
+ rows,
162
+ fixedHeight,
163
+ rowHeight,
164
+ heightCache,
165
+ } = state;
166
+
161
167
  const firstIndex = Math.max(firstVisibleIndex - bufferSize, 0);
162
168
  let lastIndex = firstVisibleIndex - bufferSize + renderedRowCount;
169
+ const firstVisibleKey =
170
+ rows[firstVisibleIndex] && rows[firstVisibleIndex].key;
171
+
172
+ if (!fixedHeight && heightCache[firstVisibleKey]) {
173
+ let i = firstVisibleIndex;
174
+ let currentHeight = 0;
175
+ const knownRowHeight = rows[i] && heightCache[rows[i].key];
176
+ // loop through rows until we find last row based on wrapper height
177
+ while (knownRowHeight && currentHeight < this.wrapperHeight) {
178
+ currentHeight += knownRowHeight;
179
+ i = i + 1;
180
+ }
181
+ if (currentHeight >= this.wrapperHeight) {
182
+ // row heights were measured; i represents last visible index
183
+ lastIndex = i + bufferSize - 1;
184
+ } else {
185
+ // row heights not yet measured, i is last visible index with known height
186
+ // guess lastIndex based on default row height
187
+ const extraRowEstimate =
188
+ (this.wrapperHeight - currentHeight) / rowHeight;
189
+ lastIndex = i + extraRowEstimate + bufferSize;
190
+ }
191
+ }
192
+
163
193
  // without this, we may render too few rows when there
164
194
  // aren't enough rows for virtualization to be needed
165
195
  if (
@@ -224,6 +254,8 @@ export class RenderManager {
224
254
  const rowCountWithBuffer =
225
255
  this.getRowCountWithBuffer(state);
226
256
 
257
+ resetRowHeights(state);
258
+
227
259
  if (
228
260
  rowCountWithBuffer > state.renderedRowCount ||
229
261
  state.virtualize
@@ -40,7 +40,8 @@ class EventQueue {
40
40
 
41
41
  /**
42
42
  * Get element size
43
- * @param {HTMLElement} element - element to return the size.
43
+ *
44
+ * @param {HTMLElement} element Element to return the size.
44
45
  * @returns {Object} {width, height}
45
46
  */
46
47
  function getElementSize(element) {
@@ -73,9 +74,10 @@ function createResizeSensor() {
73
74
  }
74
75
 
75
76
  /**
77
+ * Attaches the resize event to an element
76
78
  *
77
- * @param {HTMLElement} element - element to listen resize.
78
- * @param {Function} resizeListener - resize event listener.
79
+ * @param {HTMLElement} element Element to listen resize
80
+ * @param {Function} resizeListener Resize event listener
79
81
  */
80
82
  function attachResizeEvent(element, resizeListener) {
81
83
  if (!element) {
@@ -192,6 +194,12 @@ function attachResizeEvent(element, resizeListener) {
192
194
  requestAnimationFrame(reset);
193
195
  }
194
196
 
197
+ /**
198
+ * Removes a resize event from an element.
199
+ *
200
+ * @param {HTMLElement} element Element to remove resize listener from
201
+ * @param {Event} event The event to remove
202
+ */
195
203
  function detach(elem, ev) {
196
204
  if (!elem) {
197
205
  return;
@@ -497,7 +497,7 @@ export function resetSelectedRowsKeys(state) {
497
497
  * Returns undefined if the row key value is invalid
498
498
  *
499
499
  * @param {Object} state - the datatable state.
500
- * @return {String | undefined } the row key or undefined.
500
+ * @returns {String | undefined } the row key or undefined.
501
501
  */
502
502
  function getLastRowSelection(state) {
503
503
  const lastSelectedRowKey = state.lastSelectedRowKey;
@@ -9,31 +9,27 @@
9
9
  */
10
10
 
11
11
  /**
12
- * Returns whether or not the row is selected using the state and the rowKeyValue
13
- * The state maintains the list of selected rows from which
14
- * this value can be retrieved.
12
+ * Returns whether or not the row is selected using the state and the `rowKeyValue`.
13
+ * The state maintains the list of selected rows from which this value can be retrieved.
15
14
  *
16
- * @param {Object} state - datatable state object
17
- * @param {String} rowKeyValue
18
- * @returns
15
+ * @param {Object} state Datatable state object
16
+ * @param {String} rowKeyValue The row key value to lookup
17
+ * @returns {Boolean} Whether the row is currently selected
19
18
  */
20
19
  export function isSelectedRow(state, rowKeyValue) {
21
20
  return !!state.selectedRowsKeys[rowKeyValue];
22
21
  }
23
22
 
24
23
  /**
25
- * Returns whether the row (whose row key value is specified)
26
- * should be disabled or not.
27
- * Should not disable if the row is selected.
28
- * If the particular row is not selected, the row should be disabled
29
- * when max-row-selection > 1 and the selection limit is reached
24
+ * Returns whether the row (whose row key value is specified) should be disabled or not.
25
+ * Should not disable if the row is selected. If the particular row is not selected, the
26
+ * row should be disabled when `max-row-selection` > 1 and the selection limit is reached.
30
27
  *
31
- * Note: Do not disable selection when max-row-selection = 1 and
32
- * a row has been selected.
28
+ * NOTE: Do not disable selection when `max-row-selection` is 1 and a row has been selected.
33
29
  *
34
- * @param {Object} state
35
- * @param {String} rowKeyValue
36
- * @returns {Boolean} whether the row should be disabled or not
30
+ * @param {Object} state Datatable state object
31
+ * @param {String} rowKeyValue The row key value to lookup
32
+ * @returns {Boolean} Whether the row should be disabled or not
37
33
  */
38
34
  export function isDisabledRow(state, rowKeyValue) {
39
35
  if (!isSelectedRow(state, rowKeyValue)) {
@@ -51,11 +47,10 @@ export function isDisabledRow(state, rowKeyValue) {
51
47
 
52
48
  /**
53
49
  * Returns which input type to use for row selection.
54
- * If max-row-selection = 1, use radio buttons,
55
- * otherwise, use checkboxes.
50
+ * If `max-row-selection` is 1, use radio buttons. Otherwise, use checkboxes.
56
51
  *
57
- * @param {Object} state - datatable's state object
58
- * @returns
52
+ * @param {Object} state Datatable state object
53
+ * @returns {String} `radio` is only one row is allowed to be selected, otherwise `checkbox`
59
54
  */
60
55
  export function getRowSelectionInputType(state) {
61
56
  if (getMaxRowSelection(state) === 1) {
@@ -64,14 +59,32 @@ export function getRowSelectionInputType(state) {
64
59
  return 'checkbox';
65
60
  }
66
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
+ */
67
68
  export function getMaxRowSelection(state) {
68
69
  return state.maxRowSelection;
69
70
  }
70
71
 
72
+ /**
73
+ * Determines the number of rows currently selected.
74
+ *
75
+ * @param {Object} state Datatable state object
76
+ * @returns {Integer} The number of currently selected rows
77
+ */
71
78
  export function getCurrentSelectionLength(state) {
72
79
  return getSelectedRowsKeys(state).length;
73
80
  }
74
81
 
82
+ /**
83
+ * Retrieves the row keys that are currently selected.
84
+ *
85
+ * @param {Object} state Datatable state object
86
+ * @returns {Array} An array of the row keys that are currently selected
87
+ */
75
88
  export function getSelectedRowsKeys(state) {
76
89
  return Object.keys(state.selectedRowsKeys).filter(
77
90
  (key) => state.selectedRowsKeys[key]
@@ -76,8 +76,7 @@ export function resolveRowClassNames(row) {
76
76
  * @param {object} state - data table state
77
77
  * @param {string} rowKeyValue - computed id for the row
78
78
  * @param {string} colKeyValue - computed id for the column
79
- *
80
- * @return {object} The user row that its related to the action.
79
+ * @returns {object} The user row that its related to the action.
81
80
  */
82
81
  export function getUserRowByCellKeys(state, rowKeyValue, colKeyValue) {
83
82
  const rowIndex = state.indexes[rowKeyValue][colKeyValue][0];
@@ -10,8 +10,8 @@ const VALID_SORT_DIRECTIONS = {
10
10
  * Determines if the supplied sort direction is valid.
11
11
  * Refer to `VALID_SORT_DIRECTIONS` for valid solid directions.
12
12
  *
13
- * @param {string} value The sort direction to validate
14
- * @return {boolean} Whether the supplied sort direction is valid
13
+ * @param {String} value The sort direction to validate
14
+ * @returns {Boolean} Whether the supplied sort direction is valid
15
15
  */
16
16
  export function isValidSortDirection(value) {
17
17
  return !!VALID_SORT_DIRECTIONS[value];
@@ -22,7 +22,7 @@ export function isValidSortDirection(value) {
22
22
  * the default sort direction is applied first. Clicking again reverses it
23
23
  *
24
24
  * @param {Object} state The current datatable state
25
- * @return {string} The default sort direction
25
+ * @returns {String} The default sort direction
26
26
  */
27
27
  export function getDefaultSortDirection(state) {
28
28
  return state.defaultSortDirection;
@@ -33,7 +33,7 @@ export function getDefaultSortDirection(state) {
33
33
  * the default sort direction is applied first. Clicking again reverses it
34
34
  *
35
35
  * @param {Object} state The current datatable state
36
- * @param {string} value The value to update the default sort direction to
36
+ * @param {String} value The value to update the default sort direction to
37
37
  */
38
38
  export function setDefaultSortDirection(state, value) {
39
39
  assert(
@@ -51,7 +51,7 @@ export function setDefaultSortDirection(state, value) {
51
51
  * Gets the current sort direction
52
52
  *
53
53
  * @param {Object} state The current datatable state
54
- * @return {string} The current sort direction
54
+ * @returns {String} The current sort direction
55
55
  */
56
56
  export function getSortedDirection(state) {
57
57
  return state.sortedDirection;
@@ -64,7 +64,7 @@ export function getSortedDirection(state) {
64
64
  * `sortedDirection` will be `undefined`
65
65
  *
66
66
  * @param {Object} state The current datatable state
67
- * @param {string} value The value to update the sort direction to
67
+ * @param {String} value The value to update the sort direction to
68
68
  */
69
69
  export function setSortedDirection(state, value) {
70
70
  assert(
@@ -81,7 +81,7 @@ export function setSortedDirection(state, value) {
81
81
  * of a given column in the datatable
82
82
  *
83
83
  * @param {Object} state The current datatable state
84
- * @return {string} The current sort value
84
+ * @returns {String} The current sort value
85
85
  */
86
86
  export function getSortedBy(state) {
87
87
  return state.sortedBy;
@@ -94,7 +94,7 @@ export function getSortedBy(state) {
94
94
  * to `undefined`
95
95
  *
96
96
  * @param {Object} state The current datatable state
97
- * @param {string} value The value to update the sort state to
97
+ * @param {String} value The value to update the sort state to
98
98
  */
99
99
  export function setSortedBy(state, value) {
100
100
  if (typeof value === 'string') {
@@ -3,7 +3,8 @@
3
3
  * The state object is further manipulated while it is passed around by datatable
4
4
  *
5
5
  * TODO: Check to see if there are other items that need to be added to the default state
6
- * @returns {Object} - intial state of the datatable
6
+ *
7
+ * @returns {Object} Intial state of the datatable
7
8
  */
8
9
  export const getDefaultState = function () {
9
10
  return {
@@ -62,6 +63,12 @@ export const getDefaultState = function () {
62
63
  rowHeight: 30.5,
63
64
  renderedRowCount: 0,
64
65
  firstVisibleIndex: 0, // first row that should be visible in viewport
66
+ fixedHeight: false, // by default, assume that not all rows are same height
67
+ heightCache: {}, // cache of row heights
68
+ offsets: [0],
69
+ offsetRanges: [],
70
+ firstRowOffset: 0, // how many pixels scrollTop is from top of first visible row
71
+ tableHeight: 0,
65
72
 
66
73
  // inline edit
67
74
  inlineEdit: {
@@ -1,6 +1,13 @@
1
1
  import { getColumns } from './columns';
2
2
  import { isTreeType } from './types';
3
3
 
4
+ /**
5
+ * Retrieves the default values for the tree state indicator field names.
6
+ * These values are used to make logic decisions later and may be updated
7
+ * during normal operation.
8
+ *
9
+ * @returns {Object} The default tree state indicator field names
10
+ */
4
11
  export function getTreeStateIndicatorFieldNames() {
5
12
  return {
6
13
  children: 'hasChildren',
@@ -11,6 +18,12 @@ export function getTreeStateIndicatorFieldNames() {
11
18
  };
12
19
  }
13
20
 
21
+ /**
22
+ * Determines if any of the columns in the datatable are of a tree-type.
23
+ *
24
+ * @param {Object} state The datatable state
25
+ * @returns {Boolean} Whether any of the columns are of a tree-type
26
+ */
14
27
  export function hasTreeDataType(state) {
15
28
  const columns = getColumns(state);
16
29
  return columns.some((column) => {
@@ -18,6 +31,12 @@ export function hasTreeDataType(state) {
18
31
  });
19
32
  }
20
33
 
34
+ /**
35
+ * Retrieves the first tree-type column from the state.
36
+ *
37
+ * @param {Object} state The datatable state
38
+ * @returns {Object} The first tree-type column, else `null`
39
+ */
21
40
  export function getStateTreeColumn(state) {
22
41
  const columns = getColumns(state);
23
42
  for (let i = 0; i < columns.length; i++) {
@@ -28,6 +47,12 @@ export function getStateTreeColumn(state) {
28
47
  return null;
29
48
  }
30
49
 
50
+ /**
51
+ * Dispatches an event when a row is toggled to be expanded or collapsed.
52
+ *
53
+ * @param {String} rowKeyValue The row key being acted upon
54
+ * @param {Boolean} expanded The current expand/collapse state of the row
55
+ */
31
56
  export function fireRowToggleEvent(rowKeyValue, expanded) {
32
57
  const customEvent = new CustomEvent('privatetogglecell', {
33
58
  bubbles: true,
@@ -102,35 +102,66 @@ const EDITABLE_STANDARD_TYPES = {
102
102
  date: true,
103
103
  };
104
104
 
105
+ /**
106
+ * Determines if a supplied type is a valid datatable type.
107
+ *
108
+ * @param {String} typeName The type to validate
109
+ * @returns {Boolean} Whether the supplied type is valid
110
+ */
105
111
  export function isValidType(typeName) {
106
112
  return !!STANDARD_TYPES[typeName];
107
113
  }
108
114
 
115
+ /**
116
+ * Determines if a supplied type is a tree type.
117
+ *
118
+ * @param {String} typeName The type to validate
119
+ * @returns {Boolean} Whether the supplied type is a tree type
120
+ */
109
121
  export function isTreeType(typeName) {
110
122
  return typeName === 'tree';
111
123
  }
112
124
 
125
+ /**
126
+ * Determines if a supplied type is valid for a tree type datatable.
127
+ *
128
+ * @param {String} typeName The type to validate
129
+ * @returns {Boolean} Whether the supplied type is valid for a tree
130
+ */
131
+ export function isValidTypeForTree(typeName) {
132
+ return !!TREE_SUPPORTED_TYPES[typeName];
133
+ }
134
+
135
+ /**
136
+ * Retrieves the attributes for a given type. Additionally, verifies
137
+ * the supplied type is valid.
138
+ *
139
+ * @param {String} typeName The type to get the attributes for
140
+ * @returns {Array} An array of attributes for the supplied type
141
+ */
113
142
  export function getAttributesNames(typeName) {
114
143
  assert(
115
144
  isValidType(typeName),
116
- `your are trying to access an invalid type (${typeName})`
145
+ `You are trying to access an invalid type (${typeName})`
117
146
  );
118
-
119
- return Array.isArray(STANDARD_TYPES[typeName])
120
- ? STANDARD_TYPES[typeName]
121
- : [];
122
- }
123
-
124
- export function isValidTypeForTree(dataType) {
125
- return !!TREE_SUPPORTED_TYPES[dataType];
147
+ return getStandardTypeAttributesNames(typeName);
126
148
  }
127
149
 
150
+ /**
151
+ * Retrieves the attributes for a given type.
152
+ *
153
+ * @param {String} typeName The type to get the attributes for
154
+ * @returns {Array} An array of attributes for the supplied type
155
+ */
128
156
  function getStandardTypeAttributesNames(typeName) {
129
157
  return Array.isArray(STANDARD_TYPES[typeName])
130
158
  ? STANDARD_TYPES[typeName]
131
159
  : [];
132
160
  }
133
161
 
162
+ /**
163
+ * A class for handling valid datatable types.
164
+ */
134
165
  export default class DatatableTypes {
135
166
  privateCustomTypes = {};
136
167
  isValidTypeForTree = isValidTypeForTree;
@@ -156,6 +187,13 @@ export default class DatatableTypes {
156
187
  }
157
188
  }
158
189
 
190
+ /**
191
+ * Retrieves a type. If the specified type is not a custom type,
192
+ * lookup the type in our standard types. Otherwise, return undefined.
193
+ *
194
+ * @param {String} typeName The type to retrieve
195
+ * @returns {Object | Undefined} The type metadata
196
+ */
159
197
  getType(typeName) {
160
198
  if (this.privateCustomTypes[typeName]) {
161
199
  return this.privateCustomTypes[typeName];
@@ -169,6 +207,12 @@ export default class DatatableTypes {
169
207
  return undefined;
170
208
  }
171
209
 
210
+ /**
211
+ * Retrieves a custom type's edit template if it exists.
212
+ *
213
+ * @param {String} typeName The custom type to retrieve
214
+ * @returns {Object | Undefined} The custom type's edit template
215
+ */
172
216
  getCustomTypeEditTemplate(typeName) {
173
217
  if (this.privateCustomTypes[typeName]) {
174
218
  return this.privateCustomTypes[typeName].editTemplate;
@@ -176,10 +220,22 @@ export default class DatatableTypes {
176
220
  return undefined;
177
221
  }
178
222
 
223
+ /**
224
+ * Determines if a type is a valid custom or standard type.
225
+ *
226
+ * @param {String} typeName The type to validate
227
+ * @returns {Boolean} Whether the type is valid
228
+ */
179
229
  isValidType(typeName) {
180
230
  return !!this.getType(typeName);
181
231
  }
182
232
 
233
+ /**
234
+ * Determines if a given type is editable.
235
+ *
236
+ * @param {String} typeName The type to test
237
+ * @returns {Boolean} Whether the type is editable
238
+ */
183
239
  isEditableType(typeName) {
184
240
  return (
185
241
  !!EDITABLE_STANDARD_TYPES[typeName] ||
@@ -187,12 +243,24 @@ export default class DatatableTypes {
187
243
  );
188
244
  }
189
245
 
246
+ /**
247
+ * Determines if a given type is a non-standard type.
248
+ *
249
+ * @param {String} typeName The type to test
250
+ * @returns {Boolean} Whether the type is a non-standard type
251
+ */
190
252
  isCustomType(typeName) {
191
253
  return (
192
254
  this.getType(typeName) && this.getType(typeName).type === 'custom'
193
255
  );
194
256
  }
195
257
 
258
+ /**
259
+ * Determines whether or not a given custom type is using a standard cell layout.
260
+ *
261
+ * @param {String} typeName The custom type to test
262
+ * @returns {Boolean} Whether the custom type is using a standard cell layout
263
+ */
196
264
  isStandardCellLayoutForCustomType(typeName) {
197
265
  return (
198
266
  this.isCustomType(typeName) &&
@@ -1,8 +1,4 @@
1
- export const isObjectLike = function (value) {
2
- return typeof value === 'object' && value !== null;
3
- };
4
-
5
- const proto = {
1
+ const CLASSSET_PROTOTYPE = {
6
2
  add(className) {
7
3
  if (typeof className === 'string') {
8
4
  this[className] = true;
@@ -24,32 +20,59 @@ const proto = {
24
20
  },
25
21
  };
26
22
 
23
+ /**
24
+ * Determines if a given value is object-like.
25
+ *
26
+ * @param {*} value Any value to check for object-like status
27
+ * @returns {Boolean} Whether the value is object-like
28
+ */
29
+ export const isObjectLike = function (value) {
30
+ return typeof value === 'object' && value !== null;
31
+ };
32
+
33
+ /**
34
+ * Creates an object of CSS class names based on a given config.
35
+ * Then, attaches an interface for managing the classes.
36
+ *
37
+ * @param {String | Object} config The initial class configuration
38
+ * @returns An interface, as defined in the `proto` method.
39
+ */
27
40
  export const classSet = function (config) {
28
41
  if (typeof config === 'string') {
29
42
  const key = config;
30
43
  config = {};
31
44
  config[key] = true;
32
45
  }
33
- return Object.assign(Object.create(proto), config);
46
+ return Object.assign(Object.create(CLASSSET_PROTOTYPE), config);
34
47
  };
35
48
 
49
+ /**
50
+ * Clamps a value between a minimum and maximum value
51
+ *
52
+ * @param {Number} num The input number
53
+ * @param {Number} min The minimum value the number can be
54
+ * @param {Number} max The maximum value the number can be
55
+ * @returns The clamped number
56
+ */
36
57
  export const clamp = function (num, min, max) {
37
58
  return num <= min ? min : num >= max ? max : num;
38
59
  };
39
60
 
40
61
  /**
41
- * Tests if the value passed in is a value greater than 0
42
- * @param {Integer} value - value to test
43
- * @returns {Boolean} - true if value is > 0
62
+ * Tests if the value passed in is a value greater than 0.
63
+ *
64
+ * @param {Integer} value Value to test
65
+ * @returns {Boolean} Whether the value is greater than 0
44
66
  */
45
67
  export const isPositiveInteger = function (value) {
46
68
  return /^[0-9]*[1-9][0-9]*$/.test(value);
47
69
  };
48
70
 
49
71
  /**
50
- * Tests if the value passed in is 0 or a number greater than 0
51
- * @param {Integer} value - value to test
52
- * @returns {Boolean} - true if value is >= 0
72
+ * Tests if the value passed in is 0 or a number greater than 0.
73
+ *
74
+ * @param {Integer} value Value to test
75
+ * @returns {Boolean} Whether the value is greater than or equal to 0
53
76
  */
54
77
  export const isNonNegativeInteger = function (value) {
55
78
  return /^\d+$/.test(value);
@@ -62,11 +85,11 @@ export const isNonNegativeInteger = function (value) {
62
85
  * b. numberType - non-negative: if value >= 0
63
86
  * If the value fails the test, the fallback value is returned
64
87
  *
65
- * @param {String} attrName - name of attribute to normalize
66
- * @param {Integer/String} value - value to normalize
67
- * @param {String} numberType - number type to validate against: positive / non-negative
68
- * @param {Integer} fallback - value to return if validation fails
69
- * @returns {Integer} - Returns normalized value if validation passes; else returns fallback
88
+ * @param {String} attrName Name of attribute to normalize
89
+ * @param {Integer | String} value Value to normalize
90
+ * @param {String} numberType Number type to validate against: positive / non-negative
91
+ * @param {Integer} fallback Value to return if validation fails
92
+ * @returns {Integer} Returns normalized value if validation passes; else returns fallback
70
93
  */
71
94
  export function normalizeNumberAttribute(
72
95
  attrName,
@@ -98,11 +121,14 @@ export function normalizeNumberAttribute(
98
121
  return fallback;
99
122
  }
100
123
 
101
- // TODO: move into scroller-specific utility when more scroll-related functionality
102
- // needs to be shared between libraries
103
124
  /**
104
- * Utility for calculating the scroll offset
105
- * @param {HTMLElement} el - target element of the scroll
125
+ * Utility for calculating the scroll offset.
126
+ *
127
+ * TODO: move into scroller-specific utility when more scroll-related functionality
128
+ * needs to be shared between libraries.
129
+ *
130
+ * @param {HTMLElement} el Target element of the scroll
131
+ * @returns {Number} The scroll offset from the table's end
106
132
  */
107
133
  export function getScrollOffsetFromTableEnd(el) {
108
134
  return (
@@ -111,9 +137,10 @@ export function getScrollOffsetFromTableEnd(el) {
111
137
  }
112
138
 
113
139
  /**
114
- * Utility for converting arrays and plain objects to style strings
115
- * @param {Array|Object} style
116
- * @returns {string} representing array/object as a string
140
+ * Utility for converting arrays and plain objects to style strings.
141
+ *
142
+ * @param {Array | Object} style The CSS style array/object
143
+ * @returns {String} Representing array/object as a string
117
144
  */
118
145
  export function styleToString(style) {
119
146
  if (!Array.isArray(style)) {