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
@@ -0,0 +1,14 @@
1
+ import { LightningElement } from 'lwc';
2
+ import LightningConfirm from 'lightning/confirm';
3
+
4
+ export default class ConfirmBasic extends LightningElement {
5
+ handleConfirmModal() {
6
+ LightningConfirm.open({
7
+ message: 'this is the confirm message',
8
+ label: 'Please Confirm',
9
+ theme: 'warning',
10
+ }).then((result) => {
11
+ console.log('confirm result', result);
12
+ });
13
+ }
14
+ }
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <p>{message}</p>
3
+ </template>
@@ -0,0 +1,80 @@
1
+ import { api } from 'lwc';
2
+ import LightningInteractiveDialogBase from 'lightning/interactiveDialogBase';
3
+ import { parent, instanceName, secure } from 'lightning/overlayUtils';
4
+ import LightningOverlay from 'lightning/overlay';
5
+ import labelDefault from '@salesforce/label/LightningConfirm.defaultLabel';
6
+
7
+ /**
8
+ * Create a confirm modal within your component that asks the user
9
+ * to respond before they continue.
10
+ */
11
+
12
+ export default class LightningConfirm extends LightningOverlay {
13
+ static [instanceName] = 'lightning-confirm';
14
+ static [parent] = LightningInteractiveDialogBase;
15
+
16
+ /**
17
+ * value to use for header text in "header" variant
18
+ * or aria-label in "headerless" variant
19
+ * @type {string}
20
+ * @default "Confirm" (translated accordingly)
21
+ */
22
+ @api label = labelDefault;
23
+
24
+ /**
25
+ * text to display in body of modal
26
+ */
27
+ @api message = '';
28
+
29
+ /**
30
+ * variant to use for alert; may be
31
+ * set to "header" or "headerless"
32
+ */
33
+ @api variant = 'header';
34
+
35
+ /**
36
+ * theme to use when variant is "header"
37
+ * valid values are based on SLDS themes and are
38
+ * listed in "themeOptions" of interactiveDialogBase.js
39
+ */
40
+ @api theme = 'default';
41
+
42
+ /**
43
+ * Dispatches privateclose event
44
+ * and closes dialog
45
+ */
46
+ close(result) {
47
+ const promise = new Promise((resolve) => {
48
+ this.dispatchEvent(
49
+ new CustomEvent('privateclose', {
50
+ detail: {
51
+ resolve,
52
+ [secure]: true,
53
+ },
54
+ bubbles: true,
55
+ })
56
+ );
57
+ });
58
+ super.close(result, promise);
59
+ }
60
+
61
+ /**
62
+ * Dispatches privatechildrender event
63
+ * with data parent needs to correctly render
64
+ */
65
+ renderedCallback() {
66
+ const evt = new CustomEvent('privatechildrender', {
67
+ bubbles: true,
68
+ detail: {
69
+ message: this.message,
70
+ label: this.label,
71
+ hideCancel: false,
72
+ showDescription: true,
73
+ getOkValue: () => true,
74
+ getCancelValue: () => false,
75
+ role: 'alertdialog',
76
+ },
77
+ });
78
+ this.dispatchEvent(evt);
79
+ }
80
+ }
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3
+ <isExposed>true</isExposed>
4
+ <minApiVersion>54.0</minApiVersion>
5
+ <support>GA</support>
6
+ </LightningComponentBundle>
@@ -0,0 +1,21 @@
1
+ const recordMetadata = {
2
+ name: 'name',
3
+ email: 'email',
4
+ website: 'url',
5
+ amount: 'currency',
6
+ phone: 'phoneNumber',
7
+ closeAt: 'dateInFuture',
8
+ };
9
+
10
+ export default function fetchData(amountOfRecords) {
11
+ return fetch('https://data-faker.herokuapp.com/collection', {
12
+ method: 'POST',
13
+ headers: {
14
+ 'Content-Type': 'application/json; charset=utf-8',
15
+ },
16
+ body: JSON.stringify({
17
+ amountOfRecords,
18
+ recordMetadata,
19
+ }),
20
+ }).then((response) => response.json());
21
+ }
@@ -0,0 +1,13 @@
1
+ <template>
2
+ <p>Total Rows: {data.length}</p>
3
+ <div style="height: 300px;">
4
+ <lightning-datatable
5
+ key-field="id"
6
+ data={data}
7
+ columns={columns}
8
+ enable-infinite-loading
9
+ onloadmore={handleLoadMore}>
10
+ </lightning-datatable>
11
+ </div>
12
+ <p>{loadMoreStatus}</p>
13
+ </template>
@@ -0,0 +1,42 @@
1
+ import { LightningElement } from 'lwc';
2
+ import fetchData from './fetchDataHelper';
3
+
4
+ const columns = [
5
+ { label: 'Label', fieldName: 'name' },
6
+ { label: 'Website', fieldName: 'website', type: 'url' },
7
+ { label: 'Phone', fieldName: 'phone', type: 'phone' },
8
+ { label: 'Balance', fieldName: 'amount', type: 'currency' },
9
+ { label: 'CloseAt', fieldName: 'closeAt', type: 'date' },
10
+ ];
11
+
12
+ export default class DatatableWithInfiniteLoading extends LightningElement {
13
+ data = [];
14
+ columns = columns;
15
+ loadMoreStatus;
16
+ totalNumberOfRows = 250;
17
+
18
+ // eslint-disable-next-line @lwc/lwc/no-async-await
19
+ async connectedCallback() {
20
+ const data = await fetchData(100);
21
+ this.data = data;
22
+ }
23
+
24
+ // eslint-disable-next-line @lwc/lwc/no-async-await
25
+ async handleLoadMore(event) {
26
+ const datatable = event.target;
27
+ //Displays a spinner to signal that data is being loaded
28
+ datatable.isLoading = true;
29
+ //Displays "Loading" text when more data is being loaded
30
+ this.loadMoreStatus = 'Loading';
31
+
32
+ const newData = await fetchData(50);
33
+ if (this.data.length >= this.totalNumberOfRows) {
34
+ datatable.enableInfiniteLoading = false;
35
+ this.loadMoreStatus = 'No more data to load';
36
+ } else {
37
+ this.data = this.data.concat(newData);
38
+ this.loadMoreStatus = '';
39
+ }
40
+ datatable.isLoading = false;
41
+ }
42
+ }
@@ -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 hasNoFlexibleColumns(widthsMetadata)
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
- function hasNoFlexibleColumns(widthsMetadata) {
45
- return widthsMetadata.totalFlexibleColumns === 0;
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
- // These ratios are reused except when datatable reacts to changes in data or columns and other variables
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
- // Object used to store minColumnWidth, maxColumnWidth along with other metadata like totalFixedColumns
55
- // refer widthManagerShared getTotalWidthsMetadata
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
- * If recomputeAutoWidthRatios is true or ratios are empty, new ratios are calculated
95
- * Widths are distributed as per defined widths or as per ratio
96
- * Any remaining space or extra space taken is then redistributed in second pass
97
- * @param datatableInterface - interface to datatable with callbacks giving width information
98
- * @param columnDefs - column definitions array with defined widths and other attributes
99
- * @param recomputeAutoWidthRatios - boolean indicating if ratios should be recalculated
100
- * @returns {object} with columnWidths: [], expectedTableWidth: (number)
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
- // if the lengths dont match return
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
- // first pass - do distribute widths as per ratios or
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
- // second pass - there could be excess width remaining due to clamping to maxWidth
150
- // or we might have used more space due to clamping to minWidth in certain cases
151
- // this could be more prominent in autoWidthStrategy than in fixedWidthStrategy
152
- // that columns get extreme widths i.e min or max
153
- // we need to redistribute this space using below methods
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
- // we have more space lets redistribute space
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
- // we have to take away used space
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
- // take into account columns with text wrapping
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
- // reset ratios
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
- // calculate ratio from header cells
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
- // calculate ratio from data cells
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
- // first distribute space to columns with min width or threshold of min width
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
- // now distribute to every column possible excluding columns with defined widths
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 couldnt add widths to majority of columns
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
- // first take away width from columns with max width or threshold of max width
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
- // now from every column possible excluding columns with defined widths
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