lightning-base-components 1.14.3-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 (144) hide show
  1. package/metadata/raptor.json +37 -4
  2. package/package.json +11 -4
  3. package/scopedImports/@salesforce-label-LightningModalBase.cancelandclose.js +1 -0
  4. package/scopedImports/@salesforce-label-LightningProgressBar.progressBar.js +1 -0
  5. package/src/lightning/alert/__docs__/alert.md +101 -0
  6. package/src/lightning/alert/__examples__disabled/basic/basic.css +7 -0
  7. package/src/lightning/alert/__examples__disabled/basic/basic.html +8 -0
  8. package/src/lightning/alert/__examples__disabled/basic/basic.js +14 -0
  9. package/src/lightning/alert/alert.html +3 -0
  10. package/src/lightning/alert/alert.js +78 -0
  11. package/src/lightning/alert/alert.js-meta.xml +6 -0
  12. package/src/lightning/ariaObserver/__component__/ariaObserver.spec.js +9 -0
  13. package/src/lightning/ariaObserver/ariaObserver.js +24 -35
  14. package/src/lightning/baseFormattedText/baseFormattedText.html +6 -1
  15. package/src/lightning/baseFormattedText/baseFormattedText.js +5 -0
  16. package/src/lightning/buttonMenu/buttonMenu.js +12 -0
  17. package/src/lightning/confirm/__docs__/confirm.md +100 -0
  18. package/src/lightning/confirm/__examples__disabled/basic/basic.css +7 -0
  19. package/src/lightning/confirm/__examples__disabled/basic/basic.html +8 -0
  20. package/src/lightning/confirm/__examples__disabled/basic/basic.js +14 -0
  21. package/src/lightning/confirm/confirm.html +3 -0
  22. package/src/lightning/confirm/confirm.js +80 -0
  23. package/src/lightning/confirm/confirm.js-meta.xml +6 -0
  24. package/src/lightning/datatable/__examples__/withInfiniteLoading/fetchDataHelper.js +21 -0
  25. package/src/lightning/datatable/__examples__/withInfiniteLoading/withInfiniteLoading.html +13 -0
  26. package/src/lightning/datatable/__examples__/withInfiniteLoading/withInfiniteLoading.js +42 -0
  27. package/src/lightning/datatable/autoWidthStrategy.js +170 -61
  28. package/src/lightning/datatable/{resizer.js → columnResizer.js} +0 -0
  29. package/src/lightning/datatable/columnWidthManager.js +226 -44
  30. package/src/lightning/datatable/columns.js +166 -71
  31. package/src/lightning/datatable/datatable.js +132 -60
  32. package/src/lightning/datatable/fixedWidthStrategy.js +43 -8
  33. package/src/lightning/datatable/headerActions.js +2 -2
  34. package/src/lightning/datatable/infiniteLoading.js +100 -28
  35. package/src/lightning/datatable/inlineEdit.js +21 -30
  36. package/src/lightning/datatable/keyboard.js +166 -131
  37. package/src/lightning/datatable/renderManager.js +117 -122
  38. package/src/lightning/datatable/{datatableResizeObserver.js → resizeObserver.js} +46 -29
  39. package/src/lightning/datatable/resizeSensor.js +19 -3
  40. package/src/lightning/datatable/rowSelection.js +1 -1
  41. package/src/lightning/datatable/rowSelectionShared.js +33 -20
  42. package/src/lightning/datatable/rows.js +7 -8
  43. package/src/lightning/datatable/sort.js +8 -8
  44. package/src/lightning/datatable/state.js +14 -2
  45. package/src/lightning/datatable/templates/div/div.html +127 -117
  46. package/src/lightning/datatable/templates/table/table.html +5 -0
  47. package/src/lightning/datatable/tree.js +25 -0
  48. package/src/lightning/datatable/types.js +77 -9
  49. package/src/lightning/datatable/utils.js +51 -24
  50. package/src/lightning/datatable/virtualization.js +319 -0
  51. package/src/lightning/datatable/widthManagerShared.js +27 -3
  52. package/src/lightning/datatable/wrapText.js +115 -48
  53. package/src/lightning/formattedDateTime/__docs__/formattedDateTime.md +36 -3
  54. package/src/lightning/formattedDateTime/__examples__/datetime/datetime.html +2 -2
  55. package/src/lightning/formattedDateTime/__examples__/datetime/datetime.js +3 -1
  56. package/src/lightning/formattedDateTime/__examples__/time/time.html +1 -1
  57. package/src/lightning/formattedDateTime/__examples__/time/time.js +3 -1
  58. package/src/lightning/formattedDateTime/formattedDateTime.js +1 -0
  59. package/src/lightning/iconSvgTemplates/buildTemplates/standard/dashboard_component.html +7 -0
  60. package/src/lightning/iconSvgTemplates/buildTemplates/standard/slack.html +7 -0
  61. package/src/lightning/iconSvgTemplates/buildTemplates/standard/tableau.html +7 -0
  62. package/src/lightning/iconSvgTemplates/buildTemplates/standard/travel_mode.html +2 -2
  63. package/src/lightning/iconSvgTemplates/buildTemplates/templates.js +8 -1
  64. package/src/lightning/iconSvgTemplates/buildTemplates/utility/data_model.html +7 -0
  65. package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product.html +1 -1
  66. package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product_transaction.html +2 -1
  67. package/src/lightning/iconSvgTemplates/buildTemplates/utility/slack.html +7 -0
  68. package/src/lightning/iconSvgTemplates/buildTemplates/utility/tableau.html +7 -0
  69. package/src/lightning/iconSvgTemplates/buildTemplates/utility/video_off.html +7 -0
  70. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/dashboard_component.html +7 -0
  71. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/slack.html +7 -0
  72. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/tableau.html +7 -0
  73. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/travel_mode.html +2 -2
  74. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/templates.js +8 -1
  75. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/data_model.html +7 -0
  76. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product.html +1 -1
  77. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
  78. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/slack.html +7 -0
  79. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/tableau.html +7 -0
  80. package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/video_off.html +7 -0
  81. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/dashboard_component.html +7 -0
  82. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/slack.html +7 -0
  83. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/tableau.html +7 -0
  84. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/travel_mode.html +2 -2
  85. package/src/lightning/iconSvgTemplatesStandard/buildTemplates/templates.js +4 -1
  86. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/dashboard_component.html +7 -0
  87. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/slack.html +7 -0
  88. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/tableau.html +7 -0
  89. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/travel_mode.html +2 -2
  90. package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/templates.js +4 -1
  91. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/templates.js +5 -1
  92. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/data_model.html +7 -0
  93. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product.html +1 -1
  94. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product_transaction.html +2 -1
  95. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/slack.html +7 -0
  96. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/tableau.html +7 -0
  97. package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/video_off.html +7 -0
  98. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/templates.js +5 -1
  99. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/data_model.html +7 -0
  100. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product.html +1 -1
  101. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
  102. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/slack.html +7 -0
  103. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/tableau.html +7 -0
  104. package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/video_off.html +7 -0
  105. package/src/lightning/input/__docs__/input.md +2 -0
  106. package/src/lightning/input/input.html +2 -5
  107. package/src/lightning/interactiveDialogBase/interactiveDialogBase.css +494 -0
  108. package/src/lightning/interactiveDialogBase/interactiveDialogBase.html +63 -0
  109. package/src/lightning/interactiveDialogBase/interactiveDialogBase.js +200 -0
  110. package/src/lightning/menuItem/menuItem.js +4 -1
  111. package/src/lightning/modalBase/modalBase.css +20 -0
  112. package/src/lightning/modalBase/modalBase.html +54 -0
  113. package/src/lightning/modalBase/modalBase.js +1039 -0
  114. package/src/lightning/overlay/__docs__/overlay.md +90 -0
  115. package/src/lightning/overlay/__examples__/alert/alert.html +27 -0
  116. package/src/lightning/overlay/__examples__/alert/alert.js +33 -0
  117. package/src/lightning/overlay/__examples__/basic/basic.css +7 -0
  118. package/src/lightning/overlay/__examples__/basic/basic.html +18 -0
  119. package/src/lightning/overlay/__examples__/basic/basic.js +61 -0
  120. package/src/lightning/overlay/__examples__/demo/demo.html +29 -0
  121. package/src/lightning/overlay/__examples__/demo/demo.js +40 -0
  122. package/src/lightning/overlay/__examples__/panel/panel.html +17 -0
  123. package/src/lightning/overlay/__examples__/panel/panel.js +21 -0
  124. package/src/lightning/overlay/overlay.html +3 -0
  125. package/src/lightning/overlay/overlay.js +45 -0
  126. package/src/lightning/overlayContainer/__docs__/overlayContainer.md +0 -0
  127. package/src/lightning/overlayContainer/overlayContainer.html +3 -0
  128. package/src/lightning/overlayContainer/overlayContainer.js +138 -0
  129. package/src/lightning/overlayManager/overlayManager.js +54 -0
  130. package/src/lightning/overlayUtils/overlayUtils.js +17 -0
  131. package/src/lightning/progressBar/progressBar.html +2 -1
  132. package/src/lightning/progressBar/progressBar.js +18 -1
  133. package/src/lightning/prompt/__docs__/prompt.md +102 -0
  134. package/src/lightning/prompt/__examples__disabled/basic/basic.css +7 -0
  135. package/src/lightning/prompt/__examples__disabled/basic/basic.html +8 -0
  136. package/src/lightning/prompt/__examples__disabled/basic/basic.js +15 -0
  137. package/src/lightning/prompt/prompt.css +81 -0
  138. package/src/lightning/prompt/prompt.html +8 -0
  139. package/src/lightning/prompt/prompt.js +92 -0
  140. package/src/lightning/prompt/prompt.js-meta.xml +6 -0
  141. package/src/lightning/spinner/spinner.html +1 -1
  142. package/src/lightning/spinner/spinner.js +12 -0
  143. package/src/lightning/utilsPrivate/phonify.js +1 -1
  144. package/scopedImports/@salesforce-label-LightningModalBase.close.js +0 -1
@@ -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;
@@ -16,23 +17,15 @@ export function isViewportRenderingEnabled(state) {
16
17
  return state.enableViewportRendering;
17
18
  }
18
19
 
19
- export function normalizeVirtualization(value) {
20
- return normalizeString(value, {
21
- fallbackValue: '', //no virtualization enabled
22
- validValues: [VERTICAL_VIRTUALIZATION],
23
- });
24
- }
25
-
26
- export function getDTRows() {
27
- return this.state.rows;
28
- }
29
-
30
- export function getDTRenderedRowCount() {
31
- return this._renderedRowCount;
32
- }
33
-
34
- export function setDTRenderedRowCount(renderedRowCount) {
35
- this._renderedRowCount = renderedRowCount;
20
+ export function setVirtualize(state, value) {
21
+ if (state.renderModeRoleBased) {
22
+ state.virtualize = normalizeString(value, {
23
+ fallbackValue: '', //no virtualization enabled
24
+ validValues: [VERTICAL_VIRTUALIZATION],
25
+ });
26
+ } else {
27
+ state.virtualize = '';
28
+ }
36
29
  }
37
30
 
38
31
  export function getDTWrapperHeight() {
@@ -52,6 +45,8 @@ function getDefaultPreviousInfo() {
52
45
  * @type {object}
53
46
  * @property {boolean} viewportRendering - specifies whether to use viewport rendering
54
47
  * @property {number} rowHeight - specifies the height of a row, in px
48
+ * @property {number|string} bufferSize - specifies the number of additional rows to render above/below what's visible on screen
49
+ * @property {string} virtualize - string representing what kind of virtualization to enable; currently only 'vertical' is available
55
50
  */
56
51
 
57
52
  /**
@@ -63,49 +58,41 @@ function getDefaultPreviousInfo() {
63
58
  */
64
59
  export class RenderManager {
65
60
  constructor() {
66
- this.bufferSize = DEFAULT_BUFFER_SIZE;
67
- this.rowHeight = DEFAULT_ROW_HEIGHT;
68
61
  this.threshold = DEFAULT_SCROLL_THRESHOLD;
69
62
  this.wrapperHeight = 0;
70
- this.virtualize = '';
71
63
  this.previousCache = getDefaultPreviousInfo();
72
64
  }
73
65
 
74
66
  /**
75
67
  * Updates and normalizes configuration for RenderManager
76
68
  * Used when setting renderConfig for datatable
77
- * @param {Function} getRows
78
- * @param {Function} getWrapperHeight
79
- * @param {Number} renderedRowCount
80
- * @param {Function} setRenderedRowCount
81
- * @param {RenderManagerConfig} config
69
+ * @param {Object} state - datatable state
70
+ * @param {Function} getWrapperHeight - function to get height of datatable wrapper
71
+ * @param {RenderManagerConfig} config - set of properties used for render management
82
72
  */
83
- configure(
84
- getRows,
85
- getWrapperHeight,
86
- renderedRowCount,
87
- setRenderedRowCount,
88
- config
89
- ) {
90
- const { viewportRendering, rowHeight, virtualize, bufferSize } = config;
91
- this.virtualize = normalizeVirtualization(virtualize);
92
- if (normalizeBoolean(viewportRendering) || this.virtualize) {
93
- this.initializeResizeObserver(
94
- getRows,
95
- getWrapperHeight,
96
- renderedRowCount,
97
- setRenderedRowCount
98
- );
73
+ configure(state, getWrapperHeight, config) {
74
+ const {
75
+ viewportRendering,
76
+ rowHeight,
77
+ virtualize,
78
+ bufferSize,
79
+ fixedHeight,
80
+ } = config;
81
+ setVirtualize(state, virtualize);
82
+
83
+ if (normalizeBoolean(viewportRendering) || state.virtualize) {
84
+ this.initializeResizeObserver(state, getWrapperHeight);
99
85
  }
100
- this.bufferSize = normalizeNumberAttribute(
86
+ state.bufferSize = normalizeNumberAttribute(
101
87
  'bufferSize',
102
88
  bufferSize || DEFAULT_BUFFER_SIZE,
103
89
  'non-negative',
104
90
  DEFAULT_BUFFER_SIZE
105
91
  );
92
+ state.fixedHeight = normalizeBoolean(fixedHeight);
106
93
  if (typeof rowHeight === 'number') {
107
- this.rowHeight = rowHeight;
108
- this.threshold = ROW_THRESHOLD * this.rowHeight;
94
+ state.rowHeight = rowHeight;
95
+ this.threshold = ROW_THRESHOLD * state.rowHeight;
109
96
  }
110
97
  }
111
98
 
@@ -117,39 +104,24 @@ export class RenderManager {
117
104
  * append a viewport's worth of rows to the currently rendered rows. This happens when
118
105
  * the user has added more data to the datatable (e.g when a loadMore is triggered)
119
106
  *
120
- * @param {Array} rows
121
- * @param {Function} setRenderedRowCount
122
- * @param {Node} gridContainer
123
- * @param {Boolean} forceUpdate
107
+ * @param {Object} state - datatable state
108
+ * @param {Node} gridContainer - node containing datatable header and rows
109
+ * @param {Boolean} forceUpdate - always recalculates row count if true
124
110
  */
125
- updateViewportRendering(
126
- rows,
127
- setRenderedRowCount,
128
- gridContainer,
129
- forceUpdate
130
- ) {
131
- if (this.hasDataChanged(rows) || forceUpdate) {
132
- this.updateRenderedRows(
133
- rows,
134
- setRenderedRowCount,
135
- this.getRowCountWithBuffer()
136
- );
111
+ updateViewportRendering(state, gridContainer, forceUpdate) {
112
+ if (this.hasDataChanged(state.rows) || forceUpdate) {
113
+ this.updateRenderedRows(state, this.getRowCountWithBuffer(state));
137
114
  } else if (
138
- this.previousCache.totalRowCount < rows.length &&
115
+ this.previousCache.totalRowCount < state.rows.length &&
139
116
  this.isWithinThreshold(gridContainer)
140
117
  ) {
141
118
  this.updateRenderedRows(
142
- rows,
143
- setRenderedRowCount,
119
+ state,
144
120
  this.previousCache.renderedRowCount +
145
- this.getRowCountWithBuffer()
121
+ this.getRowCountWithBuffer(state)
146
122
  );
147
123
  } else {
148
- this.updateRenderedRows(
149
- rows,
150
- setRenderedRowCount,
151
- this.previousCache.renderedRowCount
152
- );
124
+ this.updateRenderedRows(state, this.previousCache.renderedRowCount);
153
125
  }
154
126
  }
155
127
 
@@ -158,62 +130,90 @@ export class RenderManager {
158
130
  * If the scroll is within a specified threshold of the bottom,
159
131
  * calculate and render the next batch of rows
160
132
  *
161
- * @param {Array} rows
162
- * @param {Number} currentLength
163
- * @param {Function} setRenderedRowCount
133
+ * @param {Object} state - datatable state
164
134
  * @param {Event} event - scroll event
165
135
  */
166
- handleScroll(rows, currentLength, setRenderedRowCount, event) {
136
+ handleScroll(state, event) {
137
+ const { rows, renderedRowCount } = state;
167
138
  if (
168
139
  this.isWithinThreshold(event.target.firstChild) &&
169
- currentLength < rows.length
140
+ renderedRowCount < rows.length
170
141
  ) {
171
142
  this.updateRenderedRows(
172
- rows,
173
- setRenderedRowCount,
174
- currentLength + this.getRowCountWithBuffer()
143
+ state,
144
+ renderedRowCount + this.getRowCountWithBuffer(state)
175
145
  );
176
146
  }
177
147
  }
178
148
 
179
- /**
180
- * gets the index of the first row that should be visible in the viewport
181
- *
182
- * @param {Event} event
183
- * @returns {number} index of first row visible in viewport
184
- */
185
- getFirstVisibleIndex(event) {
186
- return event.target.scrollTop / this.rowHeight;
187
- }
188
-
189
149
  /**
190
150
  * calculates the range of rows that should be rendered based on the
191
- * first visible index, buffer size and datatable height
151
+ * first visible index, buffer size and number of rendered rows
192
152
  *
193
- * @param {number} firstVisibleIndex
153
+ * @param {Object} state - datatable state
194
154
  * @returns {Object} object with firstIndex and lastIndex of rendered range of rows
195
155
  */
196
- getRenderedRange(firstVisibleIndex) {
197
- const firstIndex = Math.max(firstVisibleIndex - this.bufferSize, 0);
198
- const lastIndex =
199
- firstVisibleIndex - this.bufferSize + this.getRowCountWithBuffer();
156
+ getRenderedRange(state) {
157
+ const {
158
+ firstVisibleIndex,
159
+ bufferSize,
160
+ renderedRowCount,
161
+ rows,
162
+ fixedHeight,
163
+ rowHeight,
164
+ heightCache,
165
+ } = state;
166
+
167
+ const firstIndex = Math.max(firstVisibleIndex - bufferSize, 0);
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
+ }
200
192
 
193
+ // without this, we may render too few rows when there
194
+ // aren't enough rows for virtualization to be needed
195
+ if (
196
+ renderedRowCount === rows.length &&
197
+ lastIndex <= rows.length - bufferSize
198
+ ) {
199
+ lastIndex = renderedRowCount - 1;
200
+ }
201
201
  return { firstIndex, lastIndex };
202
202
  }
203
203
 
204
204
  /**
205
205
  * Updates internal cache of row counts and first key
206
206
  *
207
- * @param {Array} rows
208
- * @param {Function} setRenderedRowCount
209
- * @param {Number} rowCount
207
+ * @param {Object} state - datatable state
208
+ * @param {Number} rowCount - max number of rows to set renderedRowCount to
210
209
  */
211
- updateRenderedRows(rows, setRenderedRowCount, rowCount) {
210
+ updateRenderedRows(state, rowCount) {
211
+ const rows = state.rows;
212
212
  const totalRows = rows.length;
213
213
  const normalizedRowCount = rowCount
214
214
  ? Math.min(rowCount, totalRows)
215
215
  : totalRows;
216
- setRenderedRowCount(normalizedRowCount);
216
+ state.renderedRowCount = normalizedRowCount;
217
217
 
218
218
  // Update our internal cache
219
219
  this.previousCache.renderedRowCount = normalizedRowCount;
@@ -228,7 +228,7 @@ export class RenderManager {
228
228
  * Caches the height of the wrapper in Datatable to avoid
229
229
  * unnecessary reflows
230
230
  *
231
- * @param {Function} getWrapperHeight
231
+ * @param {Function} getWrapperHeight - function to get height of datatable wrapper
232
232
  */
233
233
  updateWrapperHeight(getWrapperHeight) {
234
234
  this.wrapperHeight = getWrapperHeight();
@@ -240,17 +240,10 @@ export class RenderManager {
240
240
  * Initializes a resize observer to update the wrapper height
241
241
  * when the datatable component's height changes
242
242
  *
243
- * @param {Function} getRows
244
- * @param {Function} getWrapperHeight
245
- * @param {Function} getRenderedRowCount
246
- * @param {Function} setRenderedRowCount
243
+ * @param {Object} state - datatable state
244
+ * @param {Function} getWrapperHeight - function to get height of datatable wrapper
247
245
  */
248
- initializeResizeObserver(
249
- getRows,
250
- getWrapperHeight,
251
- getRenderedRowCount,
252
- setRenderedRowCount
253
- ) {
246
+ initializeResizeObserver(state, getWrapperHeight) {
254
247
  if (!this._heightResizeObserver) {
255
248
  this._heightResizeObserver = new LightningResizeObserver(() => {
256
249
  if (this._resizeObserverConnected) {
@@ -258,16 +251,16 @@ export class RenderManager {
258
251
 
259
252
  // If the wrapper is now larger than the table or virtualization enabled,
260
253
  // we need to update the rendered rows so users can continue scrolling
261
- const rowCountWithBuffer = this.getRowCountWithBuffer();
254
+ const rowCountWithBuffer =
255
+ this.getRowCountWithBuffer(state);
256
+
257
+ resetRowHeights(state);
258
+
262
259
  if (
263
- rowCountWithBuffer > getRenderedRowCount() ||
264
- this.virtualize
260
+ rowCountWithBuffer > state.renderedRowCount ||
261
+ state.virtualize
265
262
  ) {
266
- this.updateRenderedRows(
267
- getRows(),
268
- setRenderedRowCount,
269
- rowCountWithBuffer
270
- );
263
+ this.updateRenderedRows(state, rowCountWithBuffer);
271
264
  }
272
265
  }
273
266
  });
@@ -301,19 +294,21 @@ export class RenderManager {
301
294
  /**
302
295
  * Calculates how many rows fits within the current wrapper
303
296
  */
304
- getRowCountInViewport() {
305
- return Math.ceil(this.wrapperHeight / this.rowHeight);
297
+ getRowCountInViewport(state) {
298
+ return Math.ceil(this.wrapperHeight / state.rowHeight);
306
299
  }
307
300
 
308
301
  /**
309
302
  * Calculates how many rows fit in current wrapper with an added buffer
310
303
  * Used to determine how many additional rows to render
311
304
  */
312
- getRowCountWithBuffer() {
305
+ getRowCountWithBuffer(state) {
313
306
  // buffer is before and after with virtualization
314
307
  // but only after with viewport rendering
315
- const multiplier = this.virtualize ? 2 : 1;
316
- return this.getRowCountInViewport() + this.bufferSize * multiplier;
308
+ const multiplier = state.virtualize ? 2 : 1;
309
+ return (
310
+ this.getRowCountInViewport(state) + state.bufferSize * multiplier
311
+ );
317
312
  }
318
313
 
319
314
  /**
@@ -1,44 +1,25 @@
1
1
  import { LightningResizeObserver } from 'lightning/resizeObserver';
2
- import { isTableRenderedVisible } from './resizer';
2
+ import { isTableRenderedVisible } from './columnResizer';
3
3
  import { ResizeSensor } from './resizeSensor';
4
4
  import { debounce } from 'lightning/inputUtils';
5
5
  import { getColumns } from './columns';
6
6
 
7
7
  const WIDTH_OBSERVER_SELECTOR = '.dt-width-observer';
8
8
 
9
- function createResizeSensor(
10
- dtObserver,
11
- columnWidthManager,
12
- template,
13
- state,
14
- widthsData,
15
- resizeTarget
16
- ) {
17
- return new ResizeSensor(
18
- resizeTarget,
19
- debounce(() => {
20
- // since this event handler is debounced, it might be the case that at the time the handler is called,
21
- // the element is disconnected (this.hasDetachedListeners)
22
- // the scroll event which the ResizeSensor uses can happen when table is hidden (as in console when switching tabs)
23
- // and hence the need for isTableRenderedVisible check
24
- if (dtObserver.isConnected() && isTableRenderedVisible(template)) {
25
- columnWidthManager.adjustColumnsSizeAfterResize(
26
- template,
27
- getColumns(state),
28
- widthsData
29
- );
30
- }
31
- }, 200)
32
- );
33
- }
34
-
35
9
  export class LightningDatatableResizeObserver {
36
10
  _connected = false;
37
11
  _resizeObserverAvailable = typeof ResizeObserver === 'function';
38
12
 
13
+ /**
14
+ * Depending on the browser/availability, this will create either a (standard)
15
+ * ResizeObserver via LightningResizeObserver or fallback to the ResizeSensor
16
+ */
39
17
  constructor(template, state, widthsData, columnWidthManager) {
40
18
  const resizeTarget = template.querySelector(WIDTH_OBSERVER_SELECTOR);
41
19
 
20
+ // If ResizeObserver is available on the browser, create one and begin observing for changes
21
+ // Calculate and modify the column widths when there are changes to the dimensions
22
+ // and when the table is rendered and visible on screen
42
23
  if (this._resizeObserverAvailable) {
43
24
  this._resizeObserver = new LightningResizeObserver(() => {
44
25
  if (this._connected && isTableRenderedVisible(template)) {
@@ -51,8 +32,8 @@ export class LightningDatatableResizeObserver {
51
32
  });
52
33
  this._resizeObserver.observe(resizeTarget);
53
34
  } else {
54
- // fallback behavior for IE11 and Safari using existing resize sensor functionality (less performant)
55
- this._resizeSensor = createResizeSensor(
35
+ // fallback behavior for IE11 using existing resize sensor functionality (less performant)
36
+ this._resizeSensor = createResizeSensorForIE11(
56
37
  this,
57
38
  columnWidthManager,
58
39
  template,
@@ -65,6 +46,7 @@ export class LightningDatatableResizeObserver {
65
46
  this._connected = true;
66
47
  }
67
48
 
49
+ // Begins observing the specified element for changes in dimension
68
50
  observe(template) {
69
51
  const targetElement = template.querySelector(WIDTH_OBSERVER_SELECTOR);
70
52
 
@@ -77,6 +59,7 @@ export class LightningDatatableResizeObserver {
77
59
  this._connected = true;
78
60
  }
79
61
 
62
+ // Stops observing any/all observed elements for changes in dimension
80
63
  disconnect() {
81
64
  if (this._resizeObserver) {
82
65
  this._resizeObserver.disconnect();
@@ -92,3 +75,37 @@ export class LightningDatatableResizeObserver {
92
75
  return this._connected;
93
76
  }
94
77
  }
78
+
79
+ /**
80
+ * Creates a ResizeSensor which is used to observe the dimensions of an element.
81
+ *
82
+ * This ResizeSensor is only used in the event that the standard ResizeObserver
83
+ * is NOT available on the browser.
84
+ * Currently only IE11 does not support the ResizeObserver. We should be able to
85
+ * remove this once we fully drop support of IE11.
86
+ */
87
+ function createResizeSensorForIE11(
88
+ dtObserver,
89
+ columnWidthManager,
90
+ template,
91
+ state,
92
+ widthsData,
93
+ resizeTarget
94
+ ) {
95
+ return new ResizeSensor(
96
+ resizeTarget,
97
+ debounce(() => {
98
+ // since this event handler is debounced, it might be the case that at the time the handler is called,
99
+ // the element is disconnected (this.hasDetachedListeners)
100
+ // the scroll event which the ResizeSensor uses can happen when table is hidden (as in console when switching tabs)
101
+ // and hence the need for isTableRenderedVisible check
102
+ if (dtObserver.isConnected() && isTableRenderedVisible(template)) {
103
+ columnWidthManager.adjustColumnsSizeAfterResize(
104
+ template,
105
+ getColumns(state),
106
+ widthsData
107
+ );
108
+ }
109
+ }, 200)
110
+ );
111
+ }
@@ -1,3 +1,11 @@
1
+ /**
2
+ * IMPORTANT: This ResizeSensor is only used in the event that the standard ResizeObserver
3
+ * is NOT available on the browser.
4
+ *
5
+ * Currently only IE11 does not support the ResizeObserver. We should be able to
6
+ * remove this once we fully drop support of IE11.
7
+ */
8
+
1
9
  /**
2
10
  * Based on Marc J. Schmidt library: https://github.com/marcj/css-element-queries/blob/master
3
11
  */
@@ -32,7 +40,8 @@ class EventQueue {
32
40
 
33
41
  /**
34
42
  * Get element size
35
- * @param {HTMLElement} element - element to return the size.
43
+ *
44
+ * @param {HTMLElement} element Element to return the size.
36
45
  * @returns {Object} {width, height}
37
46
  */
38
47
  function getElementSize(element) {
@@ -65,9 +74,10 @@ function createResizeSensor() {
65
74
  }
66
75
 
67
76
  /**
77
+ * Attaches the resize event to an element
68
78
  *
69
- * @param {HTMLElement} element - element to listen resize.
70
- * @param {Function} resizeListener - resize event listener.
79
+ * @param {HTMLElement} element Element to listen resize
80
+ * @param {Function} resizeListener Resize event listener
71
81
  */
72
82
  function attachResizeEvent(element, resizeListener) {
73
83
  if (!element) {
@@ -184,6 +194,12 @@ function attachResizeEvent(element, resizeListener) {
184
194
  requestAnimationFrame(reset);
185
195
  }
186
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
+ */
187
203
  function detach(elem, ev) {
188
204
  if (!elem) {
189
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]