lightning-base-components 1.14.2-alpha → 1.14.6-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.
- package/metadata/raptor.json +33 -1
- package/package.json +20 -4
- package/scopedImports/@salesforce-label-LightningDualListbox.movedOptionsPlural.js +1 -0
- package/scopedImports/@salesforce-label-LightningDualListbox.movedOptionsSingular.js +1 -0
- package/scopedImports/@salesforce-label-LightningErrorMessage.validitySelectAtleastOne.js +1 -0
- package/scopedImports/@salesforce-label-LightningMap.titleWithAddress.js +1 -0
- package/scopedImports/@salesforce-label-LightningModalBase.cancelandclose.js +1 -0
- package/src/lightning/ariaObserver/__component__/ariaObserver.spec.js +9 -0
- package/src/lightning/ariaObserver/__docs__/ariaObserver.md +142 -0
- package/src/lightning/ariaObserver/ariaObserver.js +24 -35
- package/src/lightning/baseFormattedText/baseFormattedText.html +6 -1
- package/src/lightning/baseFormattedText/baseFormattedText.js +5 -0
- package/src/lightning/buttonMenu/keyboard.js +0 -10
- package/src/lightning/card/card.html +6 -0
- package/src/lightning/checkboxGroup/checkboxGroup.html +2 -2
- package/src/lightning/checkboxGroup/checkboxGroup.js +6 -1
- package/src/lightning/colorPickerCustom/colorPickerCustom.js +20 -1
- package/src/lightning/datatable/__docs__/datatable.md +55 -0
- package/src/lightning/datatable/__examples__/basic/basic.html +1 -1
- package/src/lightning/datatable/__examples__/withInfiniteLoading/fetchDataHelper.js +21 -0
- package/src/lightning/datatable/__examples__/withInfiniteLoading/withInfiniteLoading.html +13 -0
- package/src/lightning/datatable/__examples__/withInfiniteLoading/withInfiniteLoading.js +42 -0
- package/src/lightning/datatable/autoWidthStrategy.js +170 -61
- package/src/lightning/datatable/{resizer.js → columnResizer.js} +0 -0
- package/src/lightning/datatable/columnWidthManager.js +226 -44
- package/src/lightning/datatable/columns-shared.js +1 -1
- package/src/lightning/datatable/datatable.js +104 -33
- package/src/lightning/datatable/errors.js +20 -9
- package/src/lightning/datatable/fixedWidthStrategy.js +43 -8
- package/src/lightning/datatable/headerActions.js +77 -49
- package/src/lightning/datatable/infiniteLoading.js +100 -28
- package/src/lightning/datatable/inlineEdit.js +505 -379
- package/src/lightning/datatable/inlineEditShared.js +24 -0
- package/src/lightning/datatable/keyboard.js +162 -127
- package/src/lightning/datatable/renderManager.js +208 -133
- package/src/lightning/datatable/{datatableResizeObserver.js → resizeObserver.js} +46 -29
- package/src/lightning/datatable/resizeSensor.js +8 -0
- package/src/lightning/datatable/rowLevelActions.js +17 -13
- package/src/lightning/datatable/rowNumber.js +54 -20
- package/src/lightning/datatable/rowSelection.js +760 -0
- package/src/lightning/datatable/rowSelectionShared.js +79 -0
- package/src/lightning/datatable/rows.js +17 -6
- package/src/lightning/datatable/state.js +16 -2
- package/src/lightning/datatable/templates/div/div.css +4 -0
- package/src/lightning/datatable/templates/div/div.html +128 -117
- package/src/lightning/datatable/templates/table/table.html +5 -0
- package/src/lightning/datatable/utils.js +14 -0
- package/src/lightning/datatable/widthManagerShared.js +27 -3
- package/src/lightning/datatable/wrapText.js +77 -47
- package/src/lightning/dualListbox/dualListbox.html +1 -1
- package/src/lightning/dualListbox/dualListbox.js +42 -0
- package/src/lightning/formattedDateTime/__docs__/formattedDateTime.md +36 -3
- package/src/lightning/formattedDateTime/__examples__/datetime/datetime.html +2 -2
- package/src/lightning/formattedDateTime/__examples__/datetime/datetime.js +3 -1
- package/src/lightning/formattedDateTime/__examples__/time/time.html +1 -1
- package/src/lightning/formattedDateTime/__examples__/time/time.js +3 -1
- package/src/lightning/formattedDateTime/formattedDateTime.js +1 -0
- package/src/lightning/input/input.html +2 -5
- package/src/lightning/inputUtils/validity.js +12 -1
- package/src/lightning/pillContainer/__docs__/pillContainer.md +45 -1
- package/src/lightning/positionLibrary/positionLibrary.js +31 -43
- package/src/lightning/primitiveCellActions/primitiveCellActions.js +69 -12
- package/src/lightning/primitiveCellFactory/cellWithStandardLayout.html +13 -11
- package/src/lightning/primitiveCellFactory/primitiveCellFactory.js +13 -8
- package/src/lightning/primitiveDatatableIeditPanel/primitiveDatatableIeditPanel.html +17 -14
- package/src/lightning/primitiveDatatableIeditPanel/primitiveDatatableIeditPanel.js +167 -98
- package/src/lightning/primitiveDatatableIeditTypeFactory/primitiveDatatableIeditTypeFactory.js +94 -69
- package/src/lightning/primitiveDatatableStatusBar/primitiveDatatableStatusBar.html +4 -4
- package/src/lightning/primitiveDatatableStatusBar/primitiveDatatableStatusBar.js +4 -4
- package/src/lightning/primitiveHeaderActions/primitiveHeaderActions.js +99 -37
- package/src/lightning/progressIndicator/progressIndicator.js +1 -1
- package/src/lightning/progressStep/progressStep.js +1 -1
- package/src/lightning/spinner/spinner.html +1 -1
- package/src/lightning/spinner/spinner.js +12 -0
- package/src/lightning/staticMap/staticMap.html +1 -0
- package/src/lightning/staticMap/staticMap.js +39 -2
- package/src/lightning/utils/classSet.js +4 -1
- package/src/lightning/utilsPrivate/phonify.js +1 -1
- package/scopedImports/@salesforce-label-LightningModalBase.close.js +0 -1
- package/src/lightning/datatable/inlineEdit-shared.js +0 -14
- package/src/lightning/datatable/selector-shared.js +0 -38
- package/src/lightning/datatable/selector.js +0 -527
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { getScrollOffsetFromTableEnd } from './utils';
|
|
1
|
+
import { getScrollOffsetFromTableEnd, normalizeNumberAttribute } from './utils';
|
|
2
2
|
import { LightningResizeObserver } from 'lightning/resizeObserver';
|
|
3
|
-
import { normalizeBoolean } from 'lightning/utilsPrivate';
|
|
3
|
+
import { normalizeBoolean, normalizeString } from 'lightning/utilsPrivate';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
export const DEFAULT_ROW_HEIGHT = 30.5;
|
|
6
|
+
const DEFAULT_BUFFER_SIZE = 5;
|
|
7
|
+
const ROW_THRESHOLD = 10;
|
|
8
|
+
const DEFAULT_SCROLL_THRESHOLD = ROW_THRESHOLD * DEFAULT_ROW_HEIGHT;
|
|
9
|
+
const VERTICAL_VIRTUALIZATION = 'vertical';
|
|
8
10
|
|
|
9
11
|
export function setViewportRendering(state, value) {
|
|
10
12
|
state.enableViewportRendering = normalizeBoolean(value);
|
|
@@ -14,39 +16,30 @@ export function isViewportRenderingEnabled(state) {
|
|
|
14
16
|
return state.enableViewportRendering;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* Updates and normalizes the configuration for this RenderManager
|
|
26
|
-
*
|
|
27
|
-
* @param {LightningDatatable} dt
|
|
28
|
-
* @param {RenderManager} renderManager
|
|
29
|
-
* @param {RenderManagerConfig} config
|
|
30
|
-
*
|
|
31
|
-
* @returns {RenderManager}
|
|
32
|
-
*/
|
|
33
|
-
function normalizeAndProcessConfig(dt, renderManager, config) {
|
|
34
|
-
const { viewportRendering, rowHeight } = config;
|
|
35
|
-
|
|
36
|
-
if (viewportRendering && typeof viewportRendering === 'boolean') {
|
|
37
|
-
renderManager.initializeResizeObserver(dt);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (typeof rowHeight === 'number') {
|
|
41
|
-
renderManager.rowHeight = rowHeight;
|
|
42
|
-
renderManager.threshold = calculateThreshold(rowHeight);
|
|
19
|
+
export function setVirtualize(state, value) {
|
|
20
|
+
if (state.renderModeRoleBased) {
|
|
21
|
+
state.virtualize = normalizeString(value, {
|
|
22
|
+
fallbackValue: '', //no virtualization enabled
|
|
23
|
+
validValues: [VERTICAL_VIRTUALIZATION],
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
state.virtualize = '';
|
|
43
27
|
}
|
|
28
|
+
}
|
|
44
29
|
|
|
45
|
-
|
|
30
|
+
export function getDTWrapperHeight() {
|
|
31
|
+
return this.template.querySelector('.slds-scrollable_x').offsetHeight;
|
|
46
32
|
}
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
|
|
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);
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
function getDefaultPreviousInfo() {
|
|
@@ -57,6 +50,15 @@ function getDefaultPreviousInfo() {
|
|
|
57
50
|
};
|
|
58
51
|
}
|
|
59
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @typedef RenderManagerConfig
|
|
55
|
+
* @type {object}
|
|
56
|
+
* @property {boolean} viewportRendering - specifies whether to use viewport rendering
|
|
57
|
+
* @property {number} rowHeight - specifies the height of a row, in px
|
|
58
|
+
* @property {number|string} bufferSize - specifies the number of additional rows to render above/below what's visible on screen
|
|
59
|
+
* @property {string} virtualize - string representing what kind of virtualization to enable; currently only 'vertical' is available
|
|
60
|
+
*/
|
|
61
|
+
|
|
60
62
|
/**
|
|
61
63
|
* Handles any custom rendering in datatable.
|
|
62
64
|
*
|
|
@@ -66,38 +68,167 @@ function getDefaultPreviousInfo() {
|
|
|
66
68
|
*/
|
|
67
69
|
export class RenderManager {
|
|
68
70
|
constructor() {
|
|
69
|
-
this.rowHeight = DEFAULT_ROW_HEIGHT;
|
|
70
71
|
this.threshold = DEFAULT_SCROLL_THRESHOLD;
|
|
71
72
|
this.wrapperHeight = 0;
|
|
72
73
|
this.previousCache = getDefaultPreviousInfo();
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/**
|
|
77
|
+
* Updates and normalizes configuration for RenderManager
|
|
78
|
+
* Used when setting renderConfig for datatable
|
|
79
|
+
* @param {Object} state - datatable state
|
|
80
|
+
* @param {Function} getWrapperHeight - function to get height of datatable wrapper
|
|
81
|
+
* @param {RenderManagerConfig} config - set of properties used for render management
|
|
82
|
+
*/
|
|
83
|
+
configure(state, getWrapperHeight, config) {
|
|
84
|
+
const { viewportRendering, rowHeight, virtualize, bufferSize } = config;
|
|
85
|
+
setVirtualize(state, virtualize);
|
|
86
|
+
|
|
87
|
+
if (normalizeBoolean(viewportRendering) || state.virtualize) {
|
|
88
|
+
this.initializeResizeObserver(state, getWrapperHeight);
|
|
89
|
+
}
|
|
90
|
+
state.bufferSize = normalizeNumberAttribute(
|
|
91
|
+
'bufferSize',
|
|
92
|
+
bufferSize || DEFAULT_BUFFER_SIZE,
|
|
93
|
+
'non-negative',
|
|
94
|
+
DEFAULT_BUFFER_SIZE
|
|
95
|
+
);
|
|
96
|
+
if (typeof rowHeight === 'number') {
|
|
97
|
+
state.rowHeight = rowHeight;
|
|
98
|
+
this.threshold = ROW_THRESHOLD * state.rowHeight;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Render only rows that fit within the viewport
|
|
76
104
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
105
|
+
* If data has changed (verifying only row 1), reset everything
|
|
106
|
+
* Otherwise, if total row count has increased and we are within the scroll threshold,
|
|
107
|
+
* append a viewport's worth of rows to the currently rendered rows. This happens when
|
|
108
|
+
* the user has added more data to the datatable (e.g when a loadMore is triggered)
|
|
109
|
+
*
|
|
110
|
+
* @param {Object} state - datatable state
|
|
111
|
+
* @param {Node} gridContainer - node containing datatable header and rows
|
|
112
|
+
* @param {Boolean} forceUpdate - always recalculates row count if true
|
|
79
113
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
114
|
+
updateViewportRendering(state, gridContainer, forceUpdate) {
|
|
115
|
+
if (this.hasDataChanged(state.rows) || forceUpdate) {
|
|
116
|
+
this.updateRenderedRows(state, this.getRowCountWithBuffer(state));
|
|
117
|
+
} else if (
|
|
118
|
+
this.previousCache.totalRowCount < state.rows.length &&
|
|
119
|
+
this.isWithinThreshold(gridContainer)
|
|
120
|
+
) {
|
|
121
|
+
this.updateRenderedRows(
|
|
122
|
+
state,
|
|
123
|
+
this.previousCache.renderedRowCount +
|
|
124
|
+
this.getRowCountWithBuffer(state)
|
|
125
|
+
);
|
|
126
|
+
} else {
|
|
127
|
+
this.updateRenderedRows(state, this.previousCache.renderedRowCount);
|
|
128
|
+
}
|
|
82
129
|
}
|
|
83
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Handles scroll event on datatable if viewport rendering enabled
|
|
133
|
+
* If the scroll is within a specified threshold of the bottom,
|
|
134
|
+
* calculate and render the next batch of rows
|
|
135
|
+
*
|
|
136
|
+
* @param {Object} state - datatable state
|
|
137
|
+
* @param {Event} event - scroll event
|
|
138
|
+
*/
|
|
139
|
+
handleScroll(state, event) {
|
|
140
|
+
const { rows, renderedRowCount } = state;
|
|
141
|
+
if (
|
|
142
|
+
this.isWithinThreshold(event.target.firstChild) &&
|
|
143
|
+
renderedRowCount < rows.length
|
|
144
|
+
) {
|
|
145
|
+
this.updateRenderedRows(
|
|
146
|
+
state,
|
|
147
|
+
renderedRowCount + this.getRowCountWithBuffer(state)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* calculates the range of rows that should be rendered based on the
|
|
154
|
+
* first visible index, buffer size and number of rendered rows
|
|
155
|
+
*
|
|
156
|
+
* @param {Object} state - datatable state
|
|
157
|
+
* @returns {Object} object with firstIndex and lastIndex of rendered range of rows
|
|
158
|
+
*/
|
|
159
|
+
getRenderedRange(state) {
|
|
160
|
+
const { firstVisibleIndex, bufferSize, renderedRowCount, rows } = state;
|
|
161
|
+
const firstIndex = Math.max(firstVisibleIndex - bufferSize, 0);
|
|
162
|
+
let lastIndex = firstVisibleIndex - bufferSize + renderedRowCount;
|
|
163
|
+
// without this, we may render too few rows when there
|
|
164
|
+
// aren't enough rows for virtualization to be needed
|
|
165
|
+
if (
|
|
166
|
+
renderedRowCount === rows.length &&
|
|
167
|
+
lastIndex <= rows.length - bufferSize
|
|
168
|
+
) {
|
|
169
|
+
lastIndex = renderedRowCount - 1;
|
|
170
|
+
}
|
|
171
|
+
return { firstIndex, lastIndex };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Updates internal cache of row counts and first key
|
|
176
|
+
*
|
|
177
|
+
* @param {Object} state - datatable state
|
|
178
|
+
* @param {Number} rowCount - max number of rows to set renderedRowCount to
|
|
179
|
+
*/
|
|
180
|
+
updateRenderedRows(state, rowCount) {
|
|
181
|
+
const rows = state.rows;
|
|
182
|
+
const totalRows = rows.length;
|
|
183
|
+
const normalizedRowCount = rowCount
|
|
184
|
+
? Math.min(rowCount, totalRows)
|
|
185
|
+
: totalRows;
|
|
186
|
+
state.renderedRowCount = normalizedRowCount;
|
|
187
|
+
|
|
188
|
+
// Update our internal cache
|
|
189
|
+
this.previousCache.renderedRowCount = normalizedRowCount;
|
|
190
|
+
this.previousCache.totalRowCount = totalRows;
|
|
191
|
+
|
|
192
|
+
if (rows.length > 0) {
|
|
193
|
+
this.previousCache.firstRowKey = rows[0].key;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Caches the height of the wrapper in Datatable to avoid
|
|
199
|
+
* unnecessary reflows
|
|
200
|
+
*
|
|
201
|
+
* @param {Function} getWrapperHeight - function to get height of datatable wrapper
|
|
202
|
+
*/
|
|
203
|
+
updateWrapperHeight(getWrapperHeight) {
|
|
204
|
+
this.wrapperHeight = getWrapperHeight();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/************************** OBSERVER MANAGEMENT **************************/
|
|
208
|
+
|
|
84
209
|
/**
|
|
85
210
|
* Initializes a resize observer to update the wrapper height
|
|
86
211
|
* when the datatable component's height changes
|
|
87
212
|
*
|
|
88
|
-
* @param {
|
|
213
|
+
* @param {Object} state - datatable state
|
|
214
|
+
* @param {Function} getWrapperHeight - function to get height of datatable wrapper
|
|
89
215
|
*/
|
|
90
|
-
initializeResizeObserver(
|
|
216
|
+
initializeResizeObserver(state, getWrapperHeight) {
|
|
91
217
|
if (!this._heightResizeObserver) {
|
|
92
218
|
this._heightResizeObserver = new LightningResizeObserver(() => {
|
|
93
219
|
if (this._resizeObserverConnected) {
|
|
94
|
-
this.updateWrapperHeight(
|
|
220
|
+
this.updateWrapperHeight(getWrapperHeight);
|
|
95
221
|
|
|
96
|
-
// If the wrapper is now larger than the table
|
|
97
|
-
// the rendered rows so users can continue scrolling
|
|
98
|
-
const rowCountWithBuffer =
|
|
99
|
-
|
|
100
|
-
|
|
222
|
+
// If the wrapper is now larger than the table or virtualization enabled,
|
|
223
|
+
// we need to update the rendered rows so users can continue scrolling
|
|
224
|
+
const rowCountWithBuffer =
|
|
225
|
+
this.getRowCountWithBuffer(state);
|
|
226
|
+
|
|
227
|
+
if (
|
|
228
|
+
rowCountWithBuffer > state.renderedRowCount ||
|
|
229
|
+
state.virtualize
|
|
230
|
+
) {
|
|
231
|
+
this.updateRenderedRows(state, rowCountWithBuffer);
|
|
101
232
|
}
|
|
102
233
|
}
|
|
103
234
|
});
|
|
@@ -107,13 +238,10 @@ export class RenderManager {
|
|
|
107
238
|
/**
|
|
108
239
|
* Connect the resize observer to the correct element
|
|
109
240
|
*
|
|
110
|
-
* @param {
|
|
241
|
+
* @param {Node} resizeTarget
|
|
111
242
|
*/
|
|
112
|
-
connectResizeObserver(
|
|
243
|
+
connectResizeObserver(resizeTarget) {
|
|
113
244
|
if (this._heightResizeObserver) {
|
|
114
|
-
const resizeTarget = dt.template.querySelector(
|
|
115
|
-
'div.dt-outer-container'
|
|
116
|
-
);
|
|
117
245
|
this._heightResizeObserver.observe(resizeTarget);
|
|
118
246
|
this._resizeObserverConnected = true;
|
|
119
247
|
}
|
|
@@ -129,104 +257,51 @@ export class RenderManager {
|
|
|
129
257
|
}
|
|
130
258
|
}
|
|
131
259
|
|
|
132
|
-
|
|
133
|
-
return !!this.wrapperHeight;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Caches the height of the wrapper in Datatable to avoid
|
|
138
|
-
* unnecessary reflows
|
|
139
|
-
*
|
|
140
|
-
* @param {LightningDatatable} dt
|
|
141
|
-
*/
|
|
142
|
-
updateWrapperHeight(dt) {
|
|
143
|
-
this.wrapperHeight =
|
|
144
|
-
dt.template.querySelector('.slds-scrollable_x').offsetHeight;
|
|
145
|
-
}
|
|
260
|
+
/************************* HELPER FUNCTIONS **************************/
|
|
146
261
|
|
|
147
262
|
/**
|
|
148
263
|
* Calculates how many rows fits within the current wrapper
|
|
149
264
|
*/
|
|
150
|
-
getRowCountInViewport() {
|
|
151
|
-
return Math.
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getRowCountWithBuffer() {
|
|
155
|
-
return this.getRowCountInViewport() + BUFFER_ROW_COUNT;
|
|
265
|
+
getRowCountInViewport(state) {
|
|
266
|
+
return Math.ceil(this.wrapperHeight / state.rowHeight);
|
|
156
267
|
}
|
|
157
268
|
|
|
158
269
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
* If data has changed (verifying only row 1), reset everything
|
|
162
|
-
* Otherwise, if total row count has increased and we are within the scroll threshold,
|
|
163
|
-
* append a viewport's worth of rows to the currently rendered rows. This happens when
|
|
164
|
-
* the user has added more data to the datatable (e.g when a loadMore is triggered)
|
|
165
|
-
*
|
|
166
|
-
* @param {LightningDatatable} dt
|
|
270
|
+
* Calculates how many rows fit in current wrapper with an added buffer
|
|
271
|
+
* Used to determine how many additional rows to render
|
|
167
272
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
174
|
-
)
|
|
175
|
-
this.updateRenderedRows(
|
|
176
|
-
dt,
|
|
177
|
-
this.previousCache.renderedRowCount +
|
|
178
|
-
this.getRowCountWithBuffer()
|
|
179
|
-
);
|
|
180
|
-
} else {
|
|
181
|
-
this.updateRenderedRows(dt, this.previousCache.renderedRowCount);
|
|
182
|
-
}
|
|
273
|
+
getRowCountWithBuffer(state) {
|
|
274
|
+
// buffer is before and after with virtualization
|
|
275
|
+
// but only after with viewport rendering
|
|
276
|
+
const multiplier = state.virtualize ? 2 : 1;
|
|
277
|
+
return (
|
|
278
|
+
this.getRowCountInViewport(state) + state.bufferSize * multiplier
|
|
279
|
+
);
|
|
183
280
|
}
|
|
184
281
|
|
|
185
282
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* @param {LightningDatatable} dt
|
|
190
|
-
* @param {Event} event - scroll event
|
|
283
|
+
* Checks if offset is within threshold of end of table
|
|
284
|
+
* Used when determining if additional rows should be rendered
|
|
285
|
+
* @returns {boolean} true if offset is within threshold
|
|
191
286
|
*/
|
|
192
|
-
handleScroll(dt, event) {
|
|
193
|
-
const currentLength = dt._renderedRowCount;
|
|
194
|
-
if (
|
|
195
|
-
this.isWithinThreshold(event.target.firstChild) &&
|
|
196
|
-
currentLength < dt.state.rows.length
|
|
197
|
-
) {
|
|
198
|
-
this.updateRenderedRows(
|
|
199
|
-
dt,
|
|
200
|
-
currentLength + this.getRowCountWithBuffer()
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
updateRenderedRows(dt, rowCount) {
|
|
206
|
-
const totalRows = dt.state.rows.length;
|
|
207
|
-
const normalizedRowCount = rowCount
|
|
208
|
-
? Math.min(rowCount, totalRows)
|
|
209
|
-
: totalRows;
|
|
210
|
-
dt._renderedRowCount = normalizedRowCount;
|
|
211
|
-
|
|
212
|
-
// Update our internal cache
|
|
213
|
-
this.previousCache.renderedRowCount = normalizedRowCount;
|
|
214
|
-
this.previousCache.totalRowCount = totalRows;
|
|
215
|
-
|
|
216
|
-
if (dt.state.rows.length > 0) {
|
|
217
|
-
this.previousCache.firstRowKey = dt.state.rows[0].key;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
287
|
isWithinThreshold(target) {
|
|
222
288
|
const offset = getScrollOffsetFromTableEnd(target);
|
|
223
|
-
return offset
|
|
289
|
+
return offset <= this.threshold;
|
|
224
290
|
}
|
|
225
291
|
|
|
226
|
-
|
|
292
|
+
/**
|
|
293
|
+
* Checks key of first row to determine if data has changed
|
|
294
|
+
* Used to determine if viewport rendering should be reset
|
|
295
|
+
* @param {Array} rows
|
|
296
|
+
* @returns {Boolean} true if key of first row has changed
|
|
297
|
+
*/
|
|
298
|
+
hasDataChanged(rows) {
|
|
227
299
|
return (
|
|
228
|
-
|
|
229
|
-
this.previousCache.firstRowKey !== dt.state.rows[0].key
|
|
300
|
+
rows.length > 0 && this.previousCache.firstRowKey !== rows[0].key
|
|
230
301
|
);
|
|
231
302
|
}
|
|
303
|
+
|
|
304
|
+
hasWrapperHeight() {
|
|
305
|
+
return !!this.wrapperHeight;
|
|
306
|
+
}
|
|
232
307
|
}
|
|
@@ -1,44 +1,25 @@
|
|
|
1
1
|
import { LightningResizeObserver } from 'lightning/resizeObserver';
|
|
2
|
-
import { isTableRenderedVisible } from './
|
|
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
|
|
55
|
-
this._resizeSensor =
|
|
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
|
*/
|
|
@@ -3,39 +3,43 @@ import { getUserRowByCellKeys } from './rows';
|
|
|
3
3
|
import { getUserColumnIndex } from './columns';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
+
* Handles the `privatecellactiontriggered` event on lightning-datatable
|
|
6
7
|
*
|
|
7
|
-
* @param {CustomEvent} event -
|
|
8
|
+
* @param {CustomEvent} event - `privatecellactiontriggered`
|
|
8
9
|
*/
|
|
9
10
|
export function handleRowActionTriggered(event) {
|
|
10
|
-
|
|
11
|
+
event.stopPropagation();
|
|
12
|
+
|
|
13
|
+
const { action, colKeyValue, rowKeyValue } = event.detail;
|
|
11
14
|
const selectedRow = getUserRowByCellKeys(
|
|
12
15
|
this.state,
|
|
13
16
|
rowKeyValue,
|
|
14
17
|
colKeyValue
|
|
15
18
|
);
|
|
16
19
|
|
|
17
|
-
event.stopPropagation();
|
|
18
|
-
|
|
19
20
|
this.dispatchEvent(
|
|
20
21
|
new CustomEvent('rowaction', {
|
|
21
22
|
detail: {
|
|
22
|
-
row: unwrap(selectedRow),
|
|
23
23
|
action: unwrap(action),
|
|
24
|
+
row: unwrap(selectedRow),
|
|
24
25
|
},
|
|
25
26
|
})
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
/**
|
|
31
|
+
* Handles the `privatecellactionmenuopening` event on lightning-datatable
|
|
30
32
|
*
|
|
31
|
-
* @param {CustomEvent} event -
|
|
33
|
+
* @param {CustomEvent} event - `privatecellactionmenuopening`
|
|
32
34
|
*/
|
|
33
35
|
export function handleLoadDynamicActions(event) {
|
|
36
|
+
event.stopPropagation();
|
|
37
|
+
|
|
34
38
|
const {
|
|
35
|
-
rowKeyValue,
|
|
36
|
-
colKeyValue,
|
|
37
39
|
actionsProviderFunction,
|
|
40
|
+
colKeyValue,
|
|
38
41
|
doneCallback,
|
|
42
|
+
rowKeyValue,
|
|
39
43
|
saveContainerPosition,
|
|
40
44
|
} = event.detail;
|
|
41
45
|
const selectedRow = getUserRowByCellKeys(
|
|
@@ -45,18 +49,18 @@ export function handleLoadDynamicActions(event) {
|
|
|
45
49
|
);
|
|
46
50
|
|
|
47
51
|
saveContainerPosition(this.getViewableRect());
|
|
48
|
-
|
|
49
|
-
event.stopPropagation();
|
|
50
52
|
actionsProviderFunction(unwrap(selectedRow), doneCallback);
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/**
|
|
56
|
+
* Handles the `privatecellbuttonclicked` event on lightning-datatable
|
|
54
57
|
*
|
|
55
|
-
* @param {CustomEvent} event -
|
|
58
|
+
* @param {CustomEvent} event - `privatecellbuttonclicked`
|
|
56
59
|
*/
|
|
57
60
|
export function handleCellButtonClick(event) {
|
|
58
61
|
event.stopPropagation();
|
|
59
|
-
|
|
62
|
+
|
|
63
|
+
const { colKeyValue, rowKeyValue } = event.detail;
|
|
60
64
|
const row = getUserRowByCellKeys(this.state, rowKeyValue, colKeyValue);
|
|
61
65
|
const userColumnIndex = getUserColumnIndex(this.state, colKeyValue);
|
|
62
66
|
const userColumnDefinition = this._columns[userColumnIndex];
|
|
@@ -64,8 +68,8 @@ export function handleCellButtonClick(event) {
|
|
|
64
68
|
this.dispatchEvent(
|
|
65
69
|
new CustomEvent('rowaction', {
|
|
66
70
|
detail: {
|
|
67
|
-
row: unwrap(row),
|
|
68
71
|
action: unwrap(userColumnDefinition.typeAttributes),
|
|
72
|
+
row: unwrap(row),
|
|
69
73
|
},
|
|
70
74
|
})
|
|
71
75
|
);
|