lightning-base-components 1.14.3-alpha → 1.15.1-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 +37 -4
- package/package.json +11 -4
- package/scopedImports/@salesforce-internal-core.appVersion.js +1 -1
- package/scopedImports/@salesforce-label-LightningModalBase.cancelandclose.js +1 -0
- package/scopedImports/@salesforce-label-LightningProgressBar.progressBar.js +1 -0
- package/src/lightning/alert/__docs__/alert.md +101 -0
- package/src/lightning/alert/__examples__disabled/basic/basic.css +7 -0
- package/src/lightning/alert/__examples__disabled/basic/basic.html +8 -0
- package/src/lightning/alert/__examples__disabled/basic/basic.js +14 -0
- package/src/lightning/alert/alert.html +3 -0
- package/src/lightning/alert/alert.js +78 -0
- package/src/lightning/alert/alert.js-meta.xml +6 -0
- package/src/lightning/ariaObserver/__component__/ariaObserver.spec.js +9 -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/button/__wdio__/utam/utam.html +3 -0
- package/src/lightning/button/__wdio__/utam/utam.js +3 -0
- package/src/lightning/button/__wdio__/utam/utam.spec.js +20 -0
- package/src/lightning/buttonMenu/buttonMenu.js +12 -0
- package/src/lightning/confirm/__docs__/confirm.md +100 -0
- package/src/lightning/confirm/__examples__disabled/basic/basic.css +7 -0
- package/src/lightning/confirm/__examples__disabled/basic/basic.html +8 -0
- package/src/lightning/confirm/__examples__disabled/basic/basic.js +14 -0
- package/src/lightning/confirm/confirm.html +3 -0
- package/src/lightning/confirm/confirm.js +80 -0
- package/src/lightning/confirm/confirm.js-meta.xml +6 -0
- 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/__wdio__/utam/utam.html +17 -0
- package/src/lightning/datatable/__wdio__/utam/utam.js +91 -0
- package/src/lightning/datatable/__wdio__/utam/utam.spec.js +189 -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.js +166 -71
- package/src/lightning/datatable/datatable.js +136 -60
- package/src/lightning/datatable/fixedWidthStrategy.js +43 -8
- package/src/lightning/datatable/headerActions.js +2 -2
- package/src/lightning/datatable/infiniteLoading.js +100 -28
- package/src/lightning/datatable/inlineEdit.js +21 -30
- package/src/lightning/datatable/keyboard.js +166 -131
- package/src/lightning/datatable/renderManager.js +117 -122
- package/src/lightning/datatable/{datatableResizeObserver.js → resizeObserver.js} +46 -29
- package/src/lightning/datatable/resizeSensor.js +19 -3
- package/src/lightning/datatable/rowSelection.js +1 -1
- package/src/lightning/datatable/rowSelectionShared.js +33 -20
- package/src/lightning/datatable/rows.js +9 -8
- package/src/lightning/datatable/sort.js +8 -8
- package/src/lightning/datatable/state.js +14 -2
- package/src/lightning/datatable/templates/div/div.html +133 -119
- package/src/lightning/datatable/templates/table/table.html +10 -2
- package/src/lightning/datatable/tree.js +25 -0
- package/src/lightning/datatable/types.js +77 -9
- package/src/lightning/datatable/utils.js +51 -24
- package/src/lightning/datatable/virtualization.js +319 -0
- package/src/lightning/datatable/widthManagerShared.js +27 -3
- package/src/lightning/datatable/wrapText.js +115 -48
- package/src/lightning/datepicker/__perf__DISABLED/datepickerWithCalendarOpen.perf.js +55 -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/iconSvgTemplates/buildTemplates/standard/dashboard_component.html +7 -0
- package/src/lightning/iconSvgTemplates/buildTemplates/standard/slack.html +7 -0
- package/src/lightning/iconSvgTemplates/buildTemplates/standard/tableau.html +7 -0
- package/src/lightning/iconSvgTemplates/buildTemplates/standard/travel_mode.html +2 -2
- package/src/lightning/iconSvgTemplates/buildTemplates/templates.js +8 -1
- package/src/lightning/iconSvgTemplates/buildTemplates/utility/data_model.html +7 -0
- package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product.html +1 -1
- package/src/lightning/iconSvgTemplates/buildTemplates/utility/serialized_product_transaction.html +2 -1
- package/src/lightning/iconSvgTemplates/buildTemplates/utility/slack.html +7 -0
- package/src/lightning/iconSvgTemplates/buildTemplates/utility/tableau.html +7 -0
- package/src/lightning/iconSvgTemplates/buildTemplates/utility/video_off.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/dashboard_component.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/slack.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/tableau.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/standard/travel_mode.html +2 -2
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/templates.js +8 -1
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/data_model.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product.html +1 -1
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/slack.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/tableau.html +7 -0
- package/src/lightning/iconSvgTemplatesRtl/buildTemplates/utility/video_off.html +7 -0
- package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/dashboard_component.html +7 -0
- package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/slack.html +7 -0
- package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/tableau.html +7 -0
- package/src/lightning/iconSvgTemplatesStandard/buildTemplates/standard/travel_mode.html +2 -2
- package/src/lightning/iconSvgTemplatesStandard/buildTemplates/templates.js +4 -1
- package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/dashboard_component.html +7 -0
- package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/slack.html +7 -0
- package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/tableau.html +7 -0
- package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/standard/travel_mode.html +2 -2
- package/src/lightning/iconSvgTemplatesStandardRtl/buildTemplates/templates.js +4 -1
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/templates.js +5 -1
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/data_model.html +7 -0
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product.html +1 -1
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/serialized_product_transaction.html +2 -1
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/slack.html +7 -0
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/tableau.html +7 -0
- package/src/lightning/iconSvgTemplatesUtility/buildTemplates/utility/video_off.html +7 -0
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/templates.js +5 -1
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/data_model.html +7 -0
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product.html +1 -1
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/serialized_product_transaction.html +2 -1
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/slack.html +7 -0
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/tableau.html +7 -0
- package/src/lightning/iconSvgTemplatesUtilityRtl/buildTemplates/utility/video_off.html +7 -0
- package/src/lightning/input/__docs__/input.md +2 -0
- package/src/lightning/input/input.html +2 -5
- package/src/lightning/interactiveDialogBase/interactiveDialogBase.css +494 -0
- package/src/lightning/interactiveDialogBase/interactiveDialogBase.html +63 -0
- package/src/lightning/interactiveDialogBase/interactiveDialogBase.js +200 -0
- package/src/lightning/menuItem/menuItem.js +4 -1
- package/src/lightning/modalBase/modalBase.css +20 -0
- package/src/lightning/modalBase/modalBase.html +54 -0
- package/src/lightning/modalBase/modalBase.js +1039 -0
- package/src/lightning/overlay/__docs__/overlay.md +90 -0
- package/src/lightning/overlay/__examples__/alert/alert.html +27 -0
- package/src/lightning/overlay/__examples__/alert/alert.js +33 -0
- package/src/lightning/overlay/__examples__/basic/basic.css +7 -0
- package/src/lightning/overlay/__examples__/basic/basic.html +18 -0
- package/src/lightning/overlay/__examples__/basic/basic.js +61 -0
- package/src/lightning/overlay/__examples__/demo/demo.html +29 -0
- package/src/lightning/overlay/__examples__/demo/demo.js +40 -0
- package/src/lightning/overlay/__examples__/panel/panel.html +17 -0
- package/src/lightning/overlay/__examples__/panel/panel.js +21 -0
- package/src/lightning/overlay/overlay.html +3 -0
- package/src/lightning/overlay/overlay.js +45 -0
- package/src/lightning/overlayContainer/__docs__/overlayContainer.md +0 -0
- package/src/lightning/overlayContainer/overlayContainer.html +3 -0
- package/src/lightning/overlayContainer/overlayContainer.js +138 -0
- package/src/lightning/overlayManager/overlayManager.js +54 -0
- package/src/lightning/overlayUtils/overlayUtils.js +17 -0
- package/src/lightning/progressBar/progressBar.html +2 -1
- package/src/lightning/progressBar/progressBar.js +18 -1
- package/src/lightning/prompt/__docs__/prompt.md +102 -0
- package/src/lightning/prompt/__examples__disabled/basic/basic.css +7 -0
- package/src/lightning/prompt/__examples__disabled/basic/basic.html +8 -0
- package/src/lightning/prompt/__examples__disabled/basic/basic.js +15 -0
- package/src/lightning/prompt/prompt.css +81 -0
- package/src/lightning/prompt/prompt.html +8 -0
- package/src/lightning/prompt/prompt.js +92 -0
- package/src/lightning/prompt/prompt.js-meta.xml +6 -0
- package/src/lightning/spinner/spinner.html +1 -1
- package/src/lightning/spinner/spinner.js +12 -0
- package/src/lightning/utilsPrivate/phonify.js +1 -1
- package/scopedImports/@salesforce-label-LightningModalBase.close.js +0 -1
|
@@ -7,29 +7,71 @@ import { clamp } from './utils';
|
|
|
7
7
|
const MIN_MAX_THRESHOLD = 0.5;
|
|
8
8
|
const TRUNCATION_ALLOWANCE = 20;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Determines if a column exists at a specified index
|
|
12
|
+
*
|
|
13
|
+
* @param {Array} columns An array of columns
|
|
14
|
+
* @param {Integer} colIndex The column index to locate
|
|
15
|
+
* @returns {Boolean} Whether the column exists at the specified index
|
|
16
|
+
*/
|
|
10
17
|
function hasColumn(columns, colIndex) {
|
|
11
18
|
return columns.some((current) => current === colIndex);
|
|
12
19
|
}
|
|
13
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Calculates the total width of all columns
|
|
23
|
+
*
|
|
24
|
+
* @param {Array} columnWidths An array of column widths
|
|
25
|
+
* @returns {Number} The total width of all columns
|
|
26
|
+
*/
|
|
14
27
|
function getTotalColumnWidth(columnWidths) {
|
|
15
28
|
return columnWidths.reduce((acc, value) => acc + value, 0);
|
|
16
29
|
}
|
|
17
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Determines whether or not a specified width can be removed from a column
|
|
33
|
+
*
|
|
34
|
+
* @param {Number} currentWidth The current width of the column in pixels
|
|
35
|
+
* @param {Number} widthToRemove The proposed amount of width to remove in pixels
|
|
36
|
+
* @param {Number} minColumnWidth The minimum width the column can be in pixels
|
|
37
|
+
* @returns {Boolean} Whether or not the specified width can be removed
|
|
38
|
+
*/
|
|
18
39
|
function canRemoveWidth(currentWidth, widthToRemove, minColumnWidth) {
|
|
19
40
|
return currentWidth - widthToRemove >= minColumnWidth;
|
|
20
41
|
}
|
|
21
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether or not a specified width can be added to a column
|
|
45
|
+
*
|
|
46
|
+
* @param {Number} currentWidth The current width of the column in pixels
|
|
47
|
+
* @param {Number} widthToAdd The proposed amount of width to add in pixels
|
|
48
|
+
* @param {Number} maxColumnWidth The maximum width the column can be in pixels
|
|
49
|
+
* @returns {Boolean} Whether or not the specified width can be added
|
|
50
|
+
*/
|
|
22
51
|
function canAddWidth(currentWidth, widthToAdd, maxColumnWidth) {
|
|
23
52
|
return currentWidth + widthToAdd <= maxColumnWidth;
|
|
24
53
|
}
|
|
25
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Determines the expected table width
|
|
57
|
+
*
|
|
58
|
+
* @param {Number} availableWidth The available width for the entire table
|
|
59
|
+
* @param {Object} widthsMetadata The widths metadata object
|
|
60
|
+
* @returns {Number} The expected width of the table
|
|
61
|
+
*/
|
|
26
62
|
function getExpectedTableWidth(availableWidth, widthsMetadata) {
|
|
27
63
|
const minExpectedTableWidth = getMinExpectedTableWidth(widthsMetadata);
|
|
28
|
-
return
|
|
64
|
+
return widthsMetadata.totalFlexibleColumns === 0
|
|
29
65
|
? minExpectedTableWidth
|
|
30
66
|
: Math.max(minExpectedTableWidth, availableWidth);
|
|
31
67
|
}
|
|
32
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Determines the minimum expected table width
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} widthsMetadata The widths metadata object
|
|
73
|
+
* @returns {Number} The minimum expected table width
|
|
74
|
+
*/
|
|
33
75
|
function getMinExpectedTableWidth(widthsMetadata) {
|
|
34
76
|
const {
|
|
35
77
|
totalFixedWidth,
|
|
@@ -41,23 +83,27 @@ function getMinExpectedTableWidth(widthsMetadata) {
|
|
|
41
83
|
return minTotalFlexibleWidth + totalFixedWidth + totalResizedWidth;
|
|
42
84
|
}
|
|
43
85
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Strategy for columns that automatically determine their widths.
|
|
88
|
+
*/
|
|
48
89
|
export class AutoWidthStrategy {
|
|
90
|
+
// Private variables
|
|
91
|
+
|
|
49
92
|
// Instance array to hold column width ratios either calculated from visual distribution of column labels
|
|
50
|
-
// or from distribution of data amongst the columns
|
|
51
|
-
//
|
|
52
|
-
// at which point they are recalculated
|
|
93
|
+
// or from distribution of data amongst the columns. These ratios are reused except when datatable reacts
|
|
94
|
+
// to changes in data or columns and other variablesat which point they are recalculated.
|
|
53
95
|
_columnWidthRatios = [];
|
|
54
|
-
|
|
55
|
-
//
|
|
96
|
+
|
|
97
|
+
// Object used to store `minColumnWidth`, `maxColumnWidth`, along with other metadata like `totalFixedColumns`
|
|
98
|
+
// Refer: widthManagerShared.js getTotalWidthsMetadata
|
|
56
99
|
_columnWidthMetaData = {};
|
|
100
|
+
|
|
57
101
|
// Object which holds columns with min width (+ threshold) and columns with max width (-threshold)
|
|
58
102
|
// It is used in redistribution of extra space that is left or taken up while calculating auto widths
|
|
59
103
|
_columnWidthsDistribution = {};
|
|
60
104
|
|
|
105
|
+
/************************** LIFECYCLE HOOKS **************************/
|
|
106
|
+
|
|
61
107
|
constructor(minColumnWidth, maxColumnWidth, wrapTextMaxLines = 3) {
|
|
62
108
|
this._columnWidthMetaData = {
|
|
63
109
|
minColumnWidth,
|
|
@@ -68,36 +114,69 @@ export class AutoWidthStrategy {
|
|
|
68
114
|
this.columnWidthsDistribution.colsWithMaxWidth = [];
|
|
69
115
|
}
|
|
70
116
|
|
|
117
|
+
/************************** PRIVATE SETTERS **************************/
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Sets the minimum column width
|
|
121
|
+
*
|
|
122
|
+
* @param {Number} value The minimum column width in pixels
|
|
123
|
+
*/
|
|
71
124
|
set minColumnWidth(value) {
|
|
72
125
|
this._columnWidthMetaData.minColumnWidth = value;
|
|
73
126
|
}
|
|
74
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Sets the maximum column width
|
|
130
|
+
*
|
|
131
|
+
* @param {Number} value The maximum column width in pixels
|
|
132
|
+
*/
|
|
75
133
|
set maxColumnWidth(value) {
|
|
76
134
|
this._columnWidthMetaData.maxColumnWidth = value;
|
|
77
135
|
}
|
|
78
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Sets the maximum number of lines text can wrap on to
|
|
139
|
+
*
|
|
140
|
+
* @param {Number} value The maximum number of lines
|
|
141
|
+
*/
|
|
79
142
|
set wrapTextMaxLines(value) {
|
|
80
143
|
this._columnWidthMetaData.wrapTextMaxLines = value;
|
|
81
144
|
}
|
|
82
145
|
|
|
146
|
+
/************************** PRIVATE GETTERS **************************/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Gets the column width ratios
|
|
150
|
+
* See `_columnWidthRatios` in Private Variables for more information.
|
|
151
|
+
*
|
|
152
|
+
* @returns {Array} An array of column width ratios
|
|
153
|
+
*/
|
|
83
154
|
get columnWidthRatios() {
|
|
84
155
|
return this._columnWidthRatios;
|
|
85
156
|
}
|
|
86
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Gets the column width distribution.
|
|
160
|
+
* See `_columnWidthsDistribution` in Private Variables for more information.
|
|
161
|
+
*
|
|
162
|
+
* @returns {Object} An object of column width distributions
|
|
163
|
+
*/
|
|
87
164
|
get columnWidthsDistribution() {
|
|
88
165
|
return this._columnWidthsDistribution;
|
|
89
166
|
}
|
|
90
167
|
|
|
168
|
+
/************************* HELPER FUNCTIONS **************************/
|
|
169
|
+
|
|
91
170
|
/**
|
|
92
171
|
* Get adjusted column widths from existing ratios which are based on data cells room taken
|
|
93
|
-
* or based on column labels space in headers
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param datatableInterface
|
|
98
|
-
* @param columnDefs
|
|
99
|
-
* @param recomputeAutoWidthRatios
|
|
100
|
-
* @returns {
|
|
172
|
+
* or based on column labels space in headers. If `recomputeAutoWidthRatios` is true or ratios
|
|
173
|
+
* are empty, new ratios are calculated. Widths are distributed as per defined widths or as per
|
|
174
|
+
* ratio. Any remaining space or extra space taken is then redistributed in second pass.
|
|
175
|
+
*
|
|
176
|
+
* @param {Object} datatableInterface Interface to datatable with callbacks giving width information
|
|
177
|
+
* @param {Object} columnDefs Column definitions array with defined widths and other attributes
|
|
178
|
+
* @param {Boolean} recomputeAutoWidthRatios Whether ratios should be recalculated
|
|
179
|
+
* @returns {Object} columnWidths: [], expectedTableWidth: (number)
|
|
101
180
|
*/
|
|
102
181
|
getAdjustedColumnWidths(
|
|
103
182
|
datatableInterface,
|
|
@@ -128,7 +207,7 @@ export class AutoWidthStrategy {
|
|
|
128
207
|
}
|
|
129
208
|
|
|
130
209
|
let columnWidths = [];
|
|
131
|
-
//
|
|
210
|
+
// If the lengths don't match, return
|
|
132
211
|
if (
|
|
133
212
|
recomputeAutoWidthRatios &&
|
|
134
213
|
this.columnWidthRatios.length !== columnDefs.length
|
|
@@ -136,8 +215,7 @@ export class AutoWidthStrategy {
|
|
|
136
215
|
return { expectedTableWidth, columnWidths };
|
|
137
216
|
}
|
|
138
217
|
|
|
139
|
-
//
|
|
140
|
-
// defined widths if there are any
|
|
218
|
+
// First pass - Distribute widths as per ratios or defined widths if there are any
|
|
141
219
|
columnWidths = this._distributeWidthFromRatios(
|
|
142
220
|
expectedTableWidth,
|
|
143
221
|
columnDefs,
|
|
@@ -146,20 +224,20 @@ export class AutoWidthStrategy {
|
|
|
146
224
|
|
|
147
225
|
let columnWidthsSum = getTotalColumnWidth(columnWidths);
|
|
148
226
|
|
|
149
|
-
//
|
|
150
|
-
// or we might have used more space due to clamping to minWidth in certain cases
|
|
151
|
-
//
|
|
152
|
-
// that columns get extreme widths i.e min or max
|
|
153
|
-
//
|
|
227
|
+
// Second pass - There could be excess width remaining due to clamping to `maxWidth`
|
|
228
|
+
// or we might have used more space due to clamping to `minWidth `in certain cases.
|
|
229
|
+
// This could be more prominent in `autoWidthStrategy` than in `fixedWidthStrategy`
|
|
230
|
+
// that columns get extreme widths (i.e `min` or `max`).
|
|
231
|
+
// We need to redistribute this space using below methods.
|
|
154
232
|
if (expectedTableWidth > columnWidthsSum) {
|
|
155
|
-
//
|
|
233
|
+
// We have more space, let's redistribute space
|
|
156
234
|
this._redistributeExtraWidth(
|
|
157
235
|
expectedTableWidth,
|
|
158
236
|
columnWidths,
|
|
159
237
|
columnDefs
|
|
160
238
|
);
|
|
161
239
|
} else if (expectedTableWidth < columnWidthsSum) {
|
|
162
|
-
//
|
|
240
|
+
// We have to take away used space
|
|
163
241
|
this._redistributeDeficitWidth(
|
|
164
242
|
expectedTableWidth,
|
|
165
243
|
columnWidths,
|
|
@@ -169,18 +247,34 @@ export class AutoWidthStrategy {
|
|
|
169
247
|
return { columnWidths, expectedTableWidth };
|
|
170
248
|
}
|
|
171
249
|
|
|
250
|
+
/**
|
|
251
|
+
* @private
|
|
252
|
+
* Calculates the ratios for each cell based on available space for a given row.
|
|
253
|
+
*
|
|
254
|
+
* @param {Array} cellWidths An array of the cell widths
|
|
255
|
+
* @param {Number} totalWidth The total available width
|
|
256
|
+
* @returns {Array} An array of cell width ratios
|
|
257
|
+
*/
|
|
172
258
|
_getRatios(cellWidths, totalWidth) {
|
|
173
259
|
return cellWidths.map((cellWidth) => {
|
|
174
260
|
return (100 * cellWidth) / totalWidth;
|
|
175
261
|
});
|
|
176
262
|
}
|
|
177
263
|
|
|
264
|
+
/**
|
|
265
|
+
* @private
|
|
266
|
+
* Calculates and sets the column width ratios object.
|
|
267
|
+
*
|
|
268
|
+
* @param {Object} datatableInterface The datatable
|
|
269
|
+
* @param {Array} columnDefs The column definitions
|
|
270
|
+
* @param {Object} widthsMetadata The widths metadata object
|
|
271
|
+
*/
|
|
178
272
|
_calculateColumnWidthRatios(
|
|
179
273
|
datatableInterface,
|
|
180
274
|
columnDefs,
|
|
181
275
|
widthsMetadata
|
|
182
276
|
) {
|
|
183
|
-
//
|
|
277
|
+
// Take into account columns with text wrapping
|
|
184
278
|
const dataCellWidths = datatableInterface
|
|
185
279
|
.getDataCellWidths()
|
|
186
280
|
.map((width, index) => {
|
|
@@ -201,13 +295,22 @@ export class AutoWidthStrategy {
|
|
|
201
295
|
);
|
|
202
296
|
}
|
|
203
297
|
|
|
298
|
+
/**
|
|
299
|
+
* @private
|
|
300
|
+
* Calculates and creates the column width ratios array.
|
|
301
|
+
*
|
|
302
|
+
* @param {Number} tableScrollWidth The width of the table that is hidden behind a hotizontal scroll
|
|
303
|
+
* @param {Array} dataCellWidths An array of the widths of the data cells
|
|
304
|
+
* @param {Array} headerCellWidths An array of the widths of the header cells
|
|
305
|
+
* @param {Object} widthsMetadata The raw widths metadata object
|
|
306
|
+
*/
|
|
204
307
|
_setColumnWidthRatios(
|
|
205
308
|
tableScrollWidth,
|
|
206
309
|
dataCellWidths,
|
|
207
310
|
headerCellWidths,
|
|
208
311
|
widthsMetadata
|
|
209
312
|
) {
|
|
210
|
-
//
|
|
313
|
+
// Reset ratios
|
|
211
314
|
this._columnWidthRatios = [];
|
|
212
315
|
|
|
213
316
|
if (tableScrollWidth > 0) {
|
|
@@ -225,7 +328,7 @@ export class AutoWidthStrategy {
|
|
|
225
328
|
|
|
226
329
|
const totalFlexibleWidth =
|
|
227
330
|
totalHeaderWidth - totalFixedWidth - totalResizedWidth;
|
|
228
|
-
//
|
|
331
|
+
// Calculate ratio from header cells
|
|
229
332
|
this._columnWidthRatios = this._getRatios(
|
|
230
333
|
headerCellWidths,
|
|
231
334
|
totalFlexibleWidth
|
|
@@ -241,7 +344,7 @@ export class AutoWidthStrategy {
|
|
|
241
344
|
totalFixedWidth -
|
|
242
345
|
totalResizedWidth;
|
|
243
346
|
|
|
244
|
-
//
|
|
347
|
+
// Calculate ratio from data cells
|
|
245
348
|
this._columnWidthRatios = this._getRatios(
|
|
246
349
|
dataCellWidths,
|
|
247
350
|
totalFlexibleWidth
|
|
@@ -250,17 +353,22 @@ export class AutoWidthStrategy {
|
|
|
250
353
|
}
|
|
251
354
|
}
|
|
252
355
|
|
|
356
|
+
/**
|
|
357
|
+
* @private
|
|
358
|
+
* Resets the column width distribution.
|
|
359
|
+
*/
|
|
253
360
|
_resetColumnWidthsDistribution() {
|
|
254
361
|
this.columnWidthsDistribution.colsWithMinWidth = [];
|
|
255
362
|
this.columnWidthsDistribution.colsWithMaxWidth = [];
|
|
256
363
|
}
|
|
257
364
|
|
|
258
365
|
/**
|
|
259
|
-
* Allocates width to a column as per defined width or as per ratio
|
|
260
|
-
* @param availableWidth {number} - available width for the table
|
|
261
|
-
* @param columnDefs {object} - column defs in state
|
|
262
|
-
* @param widthsMetadata {object} - metadata regarding widths includes max, min, flexiblewidth, fixedwidth
|
|
263
366
|
* @private
|
|
367
|
+
* Allocates width to a column as per defined width or as per ratio.
|
|
368
|
+
*
|
|
369
|
+
* @param {Number} availableWidth Available width for the table
|
|
370
|
+
* @param {Object} columnDefs Column definitions in state
|
|
371
|
+
* @param {Object} widthsMetadata Metadata regarding widths includes `max`, `min`, `flexiblewidth`, `fixedwidth`
|
|
264
372
|
*/
|
|
265
373
|
_distributeWidthFromRatios(availableWidth, columnDefs, widthsMetadata) {
|
|
266
374
|
const columnWidths = [];
|
|
@@ -278,13 +386,14 @@ export class AutoWidthStrategy {
|
|
|
278
386
|
}
|
|
279
387
|
|
|
280
388
|
/**
|
|
281
|
-
* Calculates column width of a given column from the ratio
|
|
282
|
-
* Clamps to minColWidth and maxColWidth
|
|
283
|
-
* Also sets housekeeping data for colsWithMaxWidth threshold and colsWithMinWidth threshold
|
|
284
|
-
* @param availableWidth {number} - available width for the table
|
|
285
|
-
* @param widthsMetadata {object} - metadata regarding widths includes max, min, flexiblewidth, fixedwidth
|
|
286
|
-
* @param colIndex {number} - column number
|
|
287
389
|
* @private
|
|
390
|
+
* Calculates column width of a given column from the ratio.
|
|
391
|
+
* Clamps to `minColWidth` and `maxColWidth`.
|
|
392
|
+
* Also sets housekeeping data for `colsWithMaxWidth` threshold and `colsWithMinWidth` threshold.
|
|
393
|
+
*
|
|
394
|
+
* @param {Number} availableWidth Available width for the table
|
|
395
|
+
* @param {Object} widthsMetadata Metadata regarding widths includes max, min, flexiblewidth, fixedwidth
|
|
396
|
+
* @param {Number} colIndex Column number
|
|
288
397
|
*/
|
|
289
398
|
_getColumnWidthFromRatio(availableWidth, widthsMetadata, colIndex) {
|
|
290
399
|
const ratios = this.columnWidthRatios;
|
|
@@ -322,14 +431,14 @@ export class AutoWidthStrategy {
|
|
|
322
431
|
}
|
|
323
432
|
|
|
324
433
|
/**
|
|
325
|
-
* This method gives extra width that was remaining by
|
|
326
|
-
* first giving width to columns with max width or within threshold of max width
|
|
327
|
-
* then by giving from all columns possible - excluding fixed width columns, columns that
|
|
328
|
-
* can become max width after redistribution
|
|
329
|
-
* @param expectedTableWidth {number} - width taken by the table in the dom
|
|
330
|
-
* @param columnWidths {array} - widths array
|
|
331
|
-
* @param columnDefs {array} - columnDefs from state
|
|
332
434
|
* @private
|
|
435
|
+
* This method gives extra width that was remaining by first giving width to columns with
|
|
436
|
+
* max width or within threshold of max width then by giving from all columns possible,
|
|
437
|
+
* excluding fixed width columns, columns that can become max width after redistribution.
|
|
438
|
+
*
|
|
439
|
+
* @param {Number} expectedTableWidth Width taken by the table in the DOM
|
|
440
|
+
* @param {Array} columnWidths Column widths array
|
|
441
|
+
* @param {Object} columnDefs Column definitions from state
|
|
333
442
|
*/
|
|
334
443
|
_redistributeExtraWidth(expectedTableWidth, columnWidths, columnDefs) {
|
|
335
444
|
const { colsWithMinWidth } = this.columnWidthsDistribution;
|
|
@@ -346,7 +455,7 @@ export class AutoWidthStrategy {
|
|
|
346
455
|
let totalColsToDistribute = 0;
|
|
347
456
|
let extraWidthPerColumn = 0;
|
|
348
457
|
|
|
349
|
-
//
|
|
458
|
+
// First distribute space to columns with min width or threshold of min width
|
|
350
459
|
if (colsWithMinWidth.length > 0) {
|
|
351
460
|
totalColsToDistribute = colsWithMinWidth.length;
|
|
352
461
|
extraWidthPerColumn = Math.floor(
|
|
@@ -371,9 +480,9 @@ export class AutoWidthStrategy {
|
|
|
371
480
|
extraSpace = expectedTableWidth - columnWidthsSum;
|
|
372
481
|
const totalFixedWidthColumns = totalResizedColumns + totalFixedColumns;
|
|
373
482
|
|
|
374
|
-
//
|
|
483
|
+
// Now distribute to every column possible excluding columns with defined widths
|
|
375
484
|
// after this distribution its still possible we might have more space remaining
|
|
376
|
-
// since we
|
|
485
|
+
// since we couldn't add widths to majority of columns.
|
|
377
486
|
if (extraSpace > 0) {
|
|
378
487
|
totalColsToDistribute = columnDefs.length - totalFixedWidthColumns;
|
|
379
488
|
|
|
@@ -400,14 +509,14 @@ export class AutoWidthStrategy {
|
|
|
400
509
|
}
|
|
401
510
|
|
|
402
511
|
/**
|
|
403
|
-
* This method removes extra space that was taken by
|
|
404
|
-
* first taking away width from columns with max width or within threshold of max width
|
|
405
|
-
* then by taking away from all columns possible - excluding fixed width columns, column with min width or
|
|
406
|
-
* can become min width after taking away
|
|
407
|
-
* @param expectedTableWidth {number} - width taken by the table in the dom
|
|
408
|
-
* @param columnWidths - widths array
|
|
409
|
-
* @param columnDefs - columnDefs from state
|
|
410
512
|
* @private
|
|
513
|
+
* This method removes extra space that was taken by first taking away width from columns with
|
|
514
|
+
* max width or within threshold of max width then by taking away from all columns possible,
|
|
515
|
+
* excluding fixed width columns, column with min width or can become min width after taking away.
|
|
516
|
+
*
|
|
517
|
+
* @param {Number} expectedTableWidth Width taken by the table in the DOM
|
|
518
|
+
* @param {Array} columnWidths Column widths array
|
|
519
|
+
* @param {Object} columnDefs Column definitions from state
|
|
411
520
|
*/
|
|
412
521
|
_redistributeDeficitWidth(expectedTableWidth, columnWidths, columnDefs) {
|
|
413
522
|
const { colsWithMinWidth, colsWithMaxWidth } =
|
|
@@ -424,7 +533,7 @@ export class AutoWidthStrategy {
|
|
|
424
533
|
let totalColsToDistribute = 0;
|
|
425
534
|
let extraWidthPerColumn = 0;
|
|
426
535
|
|
|
427
|
-
//
|
|
536
|
+
// First take away width from columns with max width or threshold of max width
|
|
428
537
|
if (colsWithMaxWidth.length > 0) {
|
|
429
538
|
totalColsToDistribute = colsWithMaxWidth.length;
|
|
430
539
|
extraWidthPerColumn = Math.floor(
|
|
@@ -450,7 +559,7 @@ export class AutoWidthStrategy {
|
|
|
450
559
|
extraSpace = expectedTableWidth - columnWidthsSum;
|
|
451
560
|
const totalFixedWidthColumns = totalResizedColumns + totalFixedColumns;
|
|
452
561
|
|
|
453
|
-
//
|
|
562
|
+
// Now from every column possible excluding columns with defined widths
|
|
454
563
|
// and excluding columns within minWidthThreshold
|
|
455
564
|
// after this distribution its still possible we might have used more space
|
|
456
565
|
// since we couldnt take away widths from majority of columns
|
|
File without changes
|