@carbon/ibm-products 1.27.0 → 1.32.0

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 (167) hide show
  1. package/css/index-full-carbon.css +570 -80
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +942 -23
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +3 -3
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +569 -79
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +570 -80
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/AddSelect/AddSelect.js +0 -3
  18. package/es/components/AddSelect/AddSelectBody.js +20 -3
  19. package/es/components/AddSelect/AddSelectBreadcrumbs.js +11 -3
  20. package/es/components/AddSelect/AddSelectColumn.js +4 -3
  21. package/es/components/AddSelect/AddSelectFilter.js +4 -3
  22. package/es/components/AddSelect/AddSelectList.js +40 -14
  23. package/es/components/Card/Card.js +16 -6
  24. package/es/components/Card/CardFooter.js +3 -1
  25. package/es/components/Card/CardHeader.js +20 -1
  26. package/es/components/DataSpreadsheet/DataSpreadsheet.js +63 -11
  27. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +2 -1
  28. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +7 -0
  29. package/es/components/DataSpreadsheet/utils/handleCellDeletion.js +31 -0
  30. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +1 -1
  31. package/es/components/Datagrid/Datagrid/Datagrid.js +10 -38
  32. package/es/components/Datagrid/Datagrid/DatagridContent.js +127 -0
  33. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +9 -1
  34. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +10 -3
  35. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +12 -3
  36. package/es/components/Datagrid/Datagrid/DraggableElement.js +5 -1
  37. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +5 -40
  38. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +35 -10
  39. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +61 -24
  40. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +3 -2
  41. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +60 -0
  42. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/index.js +1 -0
  43. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +467 -0
  44. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/index.js +1 -0
  45. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.js +112 -0
  46. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/getCellIdAsObject.js +27 -0
  47. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/index.js +1 -0
  48. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +39 -0
  49. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridFocus.js +19 -0
  50. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +263 -0
  51. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleMultipleKeys.js +66 -0
  52. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +6 -5
  53. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -2
  54. package/es/components/Datagrid/index.js +3 -1
  55. package/es/components/Datagrid/useActionsColumn.js +28 -12
  56. package/es/components/Datagrid/useColumnOrder.js +8 -0
  57. package/es/components/Datagrid/useCustomizeColumns.js +5 -0
  58. package/es/components/Datagrid/useDisableSelectRows.js +6 -2
  59. package/es/components/Datagrid/useExpandedRow.js +0 -1
  60. package/es/components/Datagrid/useInlineEdit.js +71 -0
  61. package/es/components/Datagrid/useNestedRowExpander.js +42 -0
  62. package/es/components/Datagrid/useNestedRows.js +2 -2
  63. package/es/components/Datagrid/useRowSize.js +17 -6
  64. package/es/components/Datagrid/useSelectAllToggle.js +17 -4
  65. package/es/components/Datagrid/useSelectRows.js +12 -2
  66. package/es/components/Datagrid/useStickyColumn.js +11 -0
  67. package/es/components/Datagrid/utils/DatagridActions.js +121 -0
  68. package/es/components/Datagrid/utils/DatagridPagination.js +33 -0
  69. package/es/components/Datagrid/utils/Wrapper.js +21 -0
  70. package/es/components/Datagrid/utils/getArgTypes.js +85 -0
  71. package/es/components/Datagrid/utils/getInlineEditColumns.js +121 -0
  72. package/es/components/Datagrid/utils/makeData.js +17 -1
  73. package/es/components/ImportModal/ImportModal.js +2 -2
  74. package/es/components/InlineEdit/InlineEdit.js +4 -2
  75. package/es/components/ProductiveCard/ProductiveCard.js +5 -0
  76. package/es/components/index.js +1 -1
  77. package/es/global/js/hooks/useClickOutside.js +1 -1
  78. package/es/global/js/package-settings.js +3 -3
  79. package/es/global/js/utils/rangeWithCallback.js +13 -0
  80. package/es/global/js/utils/story-helper.js +5 -1
  81. package/es/global/js/utils/uuidv4.spec.js +4 -0
  82. package/lib/components/AddSelect/AddSelect.js +0 -4
  83. package/lib/components/AddSelect/AddSelectBody.js +20 -3
  84. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +14 -3
  85. package/lib/components/AddSelect/AddSelectColumn.js +3 -2
  86. package/lib/components/AddSelect/AddSelectFilter.js +3 -2
  87. package/lib/components/AddSelect/AddSelectList.js +39 -13
  88. package/lib/components/Card/Card.js +16 -6
  89. package/lib/components/Card/CardFooter.js +3 -1
  90. package/lib/components/Card/CardHeader.js +21 -1
  91. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +63 -10
  92. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +2 -1
  93. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +7 -0
  94. package/lib/components/DataSpreadsheet/utils/handleCellDeletion.js +42 -0
  95. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +1 -1
  96. package/lib/components/Datagrid/Datagrid/Datagrid.js +12 -45
  97. package/lib/components/Datagrid/Datagrid/DatagridContent.js +160 -0
  98. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +9 -1
  99. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +12 -3
  100. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +14 -3
  101. package/lib/components/Datagrid/Datagrid/DraggableElement.js +5 -1
  102. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +12 -41
  103. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +47 -25
  104. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +59 -23
  105. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +3 -2
  106. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +76 -0
  107. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/index.js +13 -0
  108. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +491 -0
  109. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/index.js +13 -0
  110. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.js +129 -0
  111. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/getCellIdAsObject.js +36 -0
  112. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/index.js +19 -0
  113. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +45 -0
  114. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridFocus.js +28 -0
  115. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +272 -0
  116. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleMultipleKeys.js +78 -0
  117. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +6 -5
  118. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -2
  119. package/lib/components/Datagrid/index.js +17 -1
  120. package/lib/components/Datagrid/useActionsColumn.js +28 -13
  121. package/lib/components/Datagrid/useColumnOrder.js +17 -0
  122. package/lib/components/Datagrid/useCustomizeColumns.js +5 -0
  123. package/lib/components/Datagrid/useDisableSelectRows.js +6 -2
  124. package/lib/components/Datagrid/useExpandedRow.js +0 -1
  125. package/lib/components/Datagrid/useInlineEdit.js +85 -0
  126. package/lib/components/Datagrid/useNestedRowExpander.js +57 -0
  127. package/lib/components/Datagrid/useNestedRows.js +3 -3
  128. package/lib/components/Datagrid/useRowSize.js +18 -13
  129. package/lib/components/Datagrid/useSelectAllToggle.js +18 -4
  130. package/lib/components/Datagrid/useSelectRows.js +12 -2
  131. package/lib/components/Datagrid/useStickyColumn.js +11 -0
  132. package/lib/components/Datagrid/utils/DatagridActions.js +139 -0
  133. package/lib/components/Datagrid/utils/DatagridPagination.js +46 -0
  134. package/lib/components/Datagrid/utils/Wrapper.js +33 -0
  135. package/lib/components/Datagrid/utils/getArgTypes.js +93 -0
  136. package/lib/components/Datagrid/utils/getInlineEditColumns.js +133 -0
  137. package/lib/components/Datagrid/utils/makeData.js +17 -1
  138. package/lib/components/ImportModal/ImportModal.js +2 -2
  139. package/lib/components/InlineEdit/InlineEdit.js +4 -2
  140. package/lib/components/ProductiveCard/ProductiveCard.js +5 -0
  141. package/lib/components/index.js +12 -0
  142. package/lib/global/js/hooks/useClickOutside.js +1 -1
  143. package/lib/global/js/package-settings.js +3 -3
  144. package/lib/global/js/utils/rangeWithCallback.js +22 -0
  145. package/lib/global/js/utils/story-helper.js +5 -1
  146. package/lib/global/js/utils/uuidv4.spec.js +4 -0
  147. package/package.json +13 -13
  148. package/scss/components/AddSelect/_add-select.scss +126 -28
  149. package/scss/components/Card/_card.scss +1 -0
  150. package/scss/components/Cascade/_cascade.scss +1 -1
  151. package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
  152. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +18 -1
  153. package/scss/components/Datagrid/_storybook-styles.scss +1 -1
  154. package/scss/components/Datagrid/styles/_datagrid.scss +27 -4
  155. package/scss/components/Datagrid/styles/_draggableElement.scss +26 -9
  156. package/scss/components/Datagrid/styles/_index.scss +1 -0
  157. package/scss/components/Datagrid/styles/_useActionsColumn.scss +12 -0
  158. package/scss/components/Datagrid/styles/_useExpandedRow.scss +30 -0
  159. package/scss/components/Datagrid/styles/_useInlineEdit.scss +211 -0
  160. package/scss/components/Datagrid/styles/_useNestedRows.scss +15 -1
  161. package/scss/components/Datagrid/styles/_useStickyColumn.scss +30 -2
  162. package/scss/components/Datagrid/styles/addons/_CustomizeColumnsModal.scss +44 -6
  163. package/scss/components/NotificationsPanel/_notifications-panel.scss +5 -6
  164. package/scss/components/ProductiveCard/_productive-card.scss +39 -0
  165. package/scss/components/RemoveModal/_remove-modal.scss +0 -4
  166. package/scss/components/SidePanel/_side-panel.scss +4 -6
  167. package/scss/components/_index-released-only.scss +1 -0
@@ -0,0 +1,467 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
+
9
+ /**
10
+ * Copyright IBM Corp. 2022, 2022
11
+ *
12
+ * This source code is licensed under the Apache-2.0 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
15
+ import React, { useState, useRef, useEffect, useContext, useCallback } from 'react';
16
+ import PropTypes from 'prop-types';
17
+ import { TextInput, NumberInput, Dropdown, DatePicker, DatePickerInput } from 'carbon-components-react';
18
+ import { Edit16, CaretSort16, ChevronDown16, Calendar16 } from '@carbon/icons-react';
19
+ import { InlineEditButton } from '../InlineEditButton';
20
+ import { pkg } from '../../../../../../settings';
21
+ import cx from 'classnames';
22
+ import { InlineEditContext } from '../InlineEditContext';
23
+ import { usePreviousValue } from '../../../../../../global/js/hooks';
24
+ import { prepareProps } from '../../../../../../global/js/utils/props-helper';
25
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
26
+ export var InlineEditCell = function InlineEditCell(_ref) {
27
+ var _cx3;
28
+
29
+ var cell = _ref.cell,
30
+ config = _ref.config,
31
+ instance = _ref.instance,
32
+ _ref$placeholder = _ref.placeholder,
33
+ placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
34
+ tabIndex = _ref.tabIndex,
35
+ value = _ref.value,
36
+ nonEditCell = _ref.nonEditCell,
37
+ totalInlineEditColumns = _ref.totalInlineEditColumns,
38
+ type = _ref.type;
39
+ var columnId = cell.column.id;
40
+ var columnIndex = instance.columns.findIndex(function (col) {
41
+ return col.id === columnId;
42
+ });
43
+ var cellId = "column-".concat(columnIndex, "-row-").concat(cell.row.index);
44
+ var totalColumns = instance.columns.length;
45
+
46
+ var _useContext = useContext(InlineEditContext),
47
+ state = _useContext.state,
48
+ dispatch = _useContext.dispatch;
49
+
50
+ var _useState = useState(false),
51
+ _useState2 = _slicedToArray(_useState, 2),
52
+ inEditMode = _useState2[0],
53
+ setInEditMode = _useState2[1];
54
+
55
+ var _useState3 = useState(value),
56
+ _useState4 = _slicedToArray(_useState3, 2),
57
+ cellValue = _useState4[0],
58
+ setCellValue = _useState4[1];
59
+
60
+ var _useState5 = useState(),
61
+ _useState6 = _slicedToArray(_useState5, 2),
62
+ initialValue = _useState6[0],
63
+ setInitialValue = _useState6[1];
64
+
65
+ var _useState7 = useState(),
66
+ _useState8 = _slicedToArray(_useState7, 2),
67
+ cellLabel = _useState8[0],
68
+ setCellLabel = _useState8[1];
69
+
70
+ var activeCellId = state.activeCellId,
71
+ editId = state.editId;
72
+ var previousState = usePreviousValue({
73
+ editId: editId,
74
+ activeCellId: activeCellId
75
+ });
76
+
77
+ var _ref2 = config || {},
78
+ inputProps = _ref2.inputProps;
79
+
80
+ var textInputRef = useRef();
81
+ var numberInputRef = useRef();
82
+ var dropdownRef = useRef();
83
+ var datePickerRef = useRef();
84
+ var outerButtonElement = useRef();
85
+ useEffect(function () {
86
+ setInitialValue(value);
87
+ var columnId = cell.column.id;
88
+ var columnLabel = instance.columns.find(function (item) {
89
+ return item.id === columnId;
90
+ });
91
+ setCellLabel(typeof columnLabel.Header === 'string' ? columnLabel.Header : 'Inline edit cell label'); // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ }, []); // If you are in edit mode and click outside of the cell,
93
+ // this changes the cell back to the InlineEditButton
94
+
95
+ useEffect(function () {
96
+ if (activeCellId !== cellId || !editId) {
97
+ setInEditMode(false);
98
+ }
99
+
100
+ if (activeCellId === cellId && editId === cellId && !nonEditCell) {
101
+ setInEditMode(true);
102
+ saveCellData(cellValue);
103
+ }
104
+ }, [activeCellId, cellId, nonEditCell, editId, cellValue, saveCellData]);
105
+
106
+ var openDropdown = function openDropdown(type) {
107
+ var _datePickerRef$curren;
108
+
109
+ var dropdownTrigger = type === 'selection' ? dropdownRef === null || dropdownRef === void 0 ? void 0 : dropdownRef.current : datePickerRef === null || datePickerRef === void 0 ? void 0 : (_datePickerRef$curren = datePickerRef.current) === null || _datePickerRef$curren === void 0 ? void 0 : _datePickerRef$curren.inputField;
110
+ dropdownTrigger.click();
111
+
112
+ if (type === 'date') {
113
+ // datePickerRef.current.cal.calendarContainer.focus();
114
+ dropdownTrigger === null || dropdownTrigger === void 0 ? void 0 : dropdownTrigger.focus();
115
+ }
116
+ }; // Re-initializes initialValue if clicking outside of a cell that was previously
117
+ // in edit mode, otherwise `initialValue` becomes stale
118
+
119
+
120
+ useEffect(function () {
121
+ if ((previousState === null || previousState === void 0 ? void 0 : previousState.editId) === cellId && (previousState === null || previousState === void 0 ? void 0 : previousState.activeCellId) === cellId && activeCellId !== cellId) {
122
+ setInitialValue(cellValue);
123
+ }
124
+ }, [previousState, cellId, cellValue, activeCellId]);
125
+
126
+ var handleInlineCellClick = function handleInlineCellClick() {
127
+ if (!inEditMode) {
128
+ dispatch({
129
+ type: 'ENTER_EDIT_MODE',
130
+ payload: {
131
+ activeCellId: cellId,
132
+ editId: cellId
133
+ }
134
+ });
135
+ setInEditMode(true);
136
+ setTimeout(function () {
137
+ if (type === 'selection' || type === 'date') {
138
+ openDropdown(type);
139
+ }
140
+ }, 1);
141
+ }
142
+ };
143
+
144
+ var rowSize = instance.rowSize,
145
+ onDataUpdate = instance.onDataUpdate; // Auto focus text input when entering edit mode
146
+
147
+ useEffect(function () {
148
+ if (inEditMode) {
149
+ if (type === 'text') {
150
+ textInputRef.current.focus();
151
+ }
152
+
153
+ if (type === 'number') {
154
+ numberInputRef.current.focus();
155
+ }
156
+ }
157
+ }, [inEditMode, type]); // Initialize cellValue from value prop
158
+
159
+ useEffect(function () {
160
+ setCellValue(value);
161
+ }, [value]); // Saves the new cell data, onDataUpdate is a required function to be
162
+ // passed to useDatagrid when using useInlineEdit
163
+
164
+ var saveCellData = useCallback(function (newValue) {
165
+ var columnId = cell.column.id;
166
+ var rowIndex = cell.row.index;
167
+ onDataUpdate(function (prev) {
168
+ return prev.map(function (row, index) {
169
+ if (index === rowIndex) {
170
+ return _objectSpread(_objectSpread({}, prev[rowIndex]), {}, _defineProperty({}, columnId, newValue));
171
+ }
172
+
173
+ return row;
174
+ });
175
+ });
176
+ }, [cell, onDataUpdate]);
177
+
178
+ var sendFocusBackToGrid = function sendFocusBackToGrid() {
179
+ // Allows the onKeyDown listener to go back to the entire grid area
180
+ var inlineEditArea = document.querySelector("#".concat(instance.tableId, " .").concat(blockClass, "__table-with-inline-edit"));
181
+ inlineEditArea.focus();
182
+ };
183
+
184
+ var getNewCellId = function getNewCellId(key) {
185
+ var totalRows = instance.rows.length;
186
+ var newCellId = key === 'Enter' ? "column-".concat(columnIndex, "-row-").concat(cell.row.index < totalRows - 1 ? cell.row.index + 1 : cell.row.index) : "column-".concat(columnIndex < instance.columns.length - 1 ? columnIndex + 1 : columnIndex, "-row-").concat(cell.row.index);
187
+ return newCellId;
188
+ };
189
+
190
+ var handleKeyDown = function handleKeyDown(event) {
191
+ var key = event.key;
192
+
193
+ switch (key) {
194
+ // Save cell contents to data
195
+ case 'Tab':
196
+ case 'Enter':
197
+ {
198
+ if (inEditMode) {
199
+ // Dropdown saves are handled in the Dropdown's/DatePicker's onChange prop
200
+ if (type === 'selection' || type === 'date') {
201
+ return;
202
+ }
203
+
204
+ var newCellId = getNewCellId(key);
205
+ saveCellData(cellValue);
206
+ setInitialValue(cellValue);
207
+ dispatch({
208
+ type: 'EXIT_EDIT_MODE',
209
+ payload: newCellId
210
+ });
211
+ setInEditMode(false);
212
+ sendFocusBackToGrid();
213
+ }
214
+
215
+ break;
216
+ }
217
+
218
+ case 'Escape':
219
+ {
220
+ if (inEditMode) {
221
+ dispatch({
222
+ type: 'EXIT_EDIT_MODE',
223
+ payload: cellId
224
+ });
225
+ setCellValue(initialValue);
226
+ saveCellData(initialValue);
227
+ setInEditMode(false);
228
+ sendFocusBackToGrid();
229
+ }
230
+
231
+ break;
232
+ }
233
+
234
+ default:
235
+ return;
236
+ }
237
+ };
238
+
239
+ var addActiveState = function addActiveState() {
240
+ dispatch({
241
+ type: 'UPDATE_ACTIVE_CELL_ID',
242
+ payload: cellId
243
+ });
244
+ };
245
+
246
+ var renderDropdownItem = function renderDropdownItem(item) {
247
+ var includesIcon = !!(item !== null && item !== void 0 && item.icon);
248
+ return includesIcon ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(item.icon), /*#__PURE__*/React.createElement("span", {
249
+ className: cx("".concat(blockClass, "__inline-edit--select-item"))
250
+ }, item === null || item === void 0 ? void 0 : item.text)) : item === null || item === void 0 ? void 0 : item.text;
251
+ };
252
+
253
+ var renderSelectCell = function renderSelectCell() {
254
+ var _ref3 = config || {},
255
+ inputProps = _ref3.inputProps;
256
+
257
+ return /*#__PURE__*/React.createElement(Dropdown, _extends({
258
+ id: cellId,
259
+ label: cellLabel || 'Dropdown menu options',
260
+ ariaLabel: cellLabel || 'Dropdown menu options'
261
+ }, inputProps, {
262
+ hideLabel: true,
263
+ style: {
264
+ width: cell.column.totalWidth
265
+ },
266
+ className: cx("".concat(blockClass, "__inline-edit--select"), _defineProperty({}, "".concat(blockClass, "__inline-edit--select-").concat(rowSize), rowSize)),
267
+ items: (inputProps === null || inputProps === void 0 ? void 0 : inputProps.items) || [],
268
+ initialSelectedItem: cell.value,
269
+ itemToElement: function itemToElement(item) {
270
+ return renderDropdownItem(item);
271
+ },
272
+ renderSelectedItem: function renderSelectedItem(item) {
273
+ return renderDropdownItem(item);
274
+ },
275
+ onChange: function onChange(item) {
276
+ var _inputProps$onChange;
277
+
278
+ var newCellId = getNewCellId('Enter');
279
+ saveCellData(item.selectedItem);
280
+ setCellValue(item.selectedItem);
281
+ dispatch({
282
+ type: 'EXIT_EDIT_MODE',
283
+ payload: newCellId
284
+ });
285
+ setInEditMode(false);
286
+ sendFocusBackToGrid();
287
+ inputProps === null || inputProps === void 0 ? void 0 : (_inputProps$onChange = inputProps.onChange) === null || _inputProps$onChange === void 0 ? void 0 : _inputProps$onChange.call(inputProps, item.selectedItem);
288
+ },
289
+ downshiftProps: {
290
+ onStateChange: function onStateChange(downshiftState) {
291
+ var _ref4 = downshiftState || {},
292
+ isOpen = _ref4.isOpen; // !isOpen does not work in this case because a state change occurs on hover of the
293
+ // menu items and isOpen is changed to undefined which causes dispatch to be called unexpectedly
294
+
295
+
296
+ if (isOpen === false) {
297
+ dispatch({
298
+ type: 'EXIT_EDIT_MODE',
299
+ payload: cellId
300
+ });
301
+ setInEditMode(false);
302
+ sendFocusBackToGrid();
303
+ }
304
+ }
305
+ },
306
+ ref: dropdownRef
307
+ }));
308
+ };
309
+
310
+ var setRenderIcon = function setRenderIcon() {
311
+ if (type === 'text') {
312
+ return Edit16;
313
+ }
314
+
315
+ if (type === 'number') {
316
+ return CaretSort16;
317
+ }
318
+
319
+ if (type === 'selection') {
320
+ return ChevronDown16;
321
+ }
322
+
323
+ if (type === 'date') {
324
+ return Calendar16;
325
+ }
326
+ };
327
+
328
+ var renderDateCell = function renderDateCell() {
329
+ var _config$inputProps, _outerButtonElement$c;
330
+
331
+ var datePickerPreparedProps = prepareProps(config.inputProps, ['datePickerInputProps']);
332
+ var datePickerInputProps = config === null || config === void 0 ? void 0 : (_config$inputProps = config.inputProps) === null || _config$inputProps === void 0 ? void 0 : _config$inputProps.datePickerInputProps;
333
+ return /*#__PURE__*/React.createElement(DatePicker, _extends({}, datePickerPreparedProps, {
334
+ appendTo: outerButtonElement === null || outerButtonElement === void 0 ? void 0 : (_outerButtonElement$c = outerButtonElement.current) === null || _outerButtonElement$c === void 0 ? void 0 : _outerButtonElement$c.parentElement,
335
+ ref: datePickerRef,
336
+ style: {
337
+ width: cell.column.totalWidth
338
+ },
339
+ datePickerType: "single",
340
+ className: cx("".concat(blockClass, "__inline-edit--date"), _defineProperty({}, "".concat(blockClass, "__inline-edit--date-").concat(rowSize), rowSize)),
341
+ onChange: function onChange(newDate) {
342
+ var _datePickerPreparedPr;
343
+
344
+ var newDateObj = newDate[0];
345
+ datePickerPreparedProps === null || datePickerPreparedProps === void 0 ? void 0 : (_datePickerPreparedPr = datePickerPreparedProps.onChange) === null || _datePickerPreparedPr === void 0 ? void 0 : _datePickerPreparedPr.call(datePickerPreparedProps, newDateObj, cell);
346
+ var newCellId = getNewCellId('Enter');
347
+ saveCellData(newDateObj);
348
+ setCellValue(newDateObj);
349
+ setInEditMode(false);
350
+ sendFocusBackToGrid();
351
+ dispatch({
352
+ type: 'EXIT_EDIT_MODE',
353
+ payload: newCellId
354
+ });
355
+ },
356
+ value: cell.value
357
+ }), /*#__PURE__*/React.createElement(DatePickerInput, _extends({}, datePickerInputProps, {
358
+ style: {
359
+ position: 'static'
360
+ },
361
+ placeholder: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.placeholder) || 'mm/dd/yyyy',
362
+ labelText: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.labelText) || cellLabel || 'Set date',
363
+ id: datePickerInputProps.id || "".concat(blockClass, "__inline-edit--date-picker--").concat(cell.row.index),
364
+ hideLabel: true
365
+ })));
366
+ }; // Ensures that months and days are all 2 digits, prefixes 0 if `num` is a single digit
367
+
368
+
369
+ var padTo2Digits = function padTo2Digits(num) {
370
+ return num.toString().padStart(2, '0');
371
+ };
372
+
373
+ var buildDate = function buildDate(value) {
374
+ if (value instanceof Date) {
375
+ var _config$dateFormat = config.dateFormat,
376
+ dateFormat = _config$dateFormat === void 0 ? 'm/d/Y' : _config$dateFormat;
377
+ var maskedFullYear = value.getFullYear();
378
+ var maskedMonth = padTo2Digits(value.getMonth() + 1);
379
+ var maskedDay = padTo2Digits(value.getDate());
380
+
381
+ if (dateFormat === 'm/d/Y' || dateFormat === 'm/d/y') {
382
+ return [maskedMonth, maskedDay, maskedFullYear].join('/');
383
+ }
384
+
385
+ if (dateFormat === 'd/m/Y' || dateFormat === 'd/m/y') {
386
+ return [maskedDay, maskedMonth, maskedFullYear].join('/');
387
+ }
388
+ }
389
+
390
+ return null;
391
+ };
392
+
393
+ return (
394
+ /*#__PURE__*/
395
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
396
+ React.createElement("div", {
397
+ ref: outerButtonElement,
398
+ "data-cell-id": cellId,
399
+ "data-column-index": columnIndex,
400
+ "data-row-index": cell.row.index,
401
+ "data-disabled": nonEditCell,
402
+ "data-inline-type": type,
403
+ onClick: !nonEditCell ? handleInlineCellClick : addActiveState,
404
+ onKeyDown: !nonEditCell ? handleKeyDown : null,
405
+ className: cx("".concat(blockClass, "__inline-edit--outer-cell-button"), (_cx3 = {}, _defineProperty(_cx3, "".concat(blockClass, "__inline-edit--outer-cell-button--").concat(rowSize), rowSize), _defineProperty(_cx3, "".concat(blockClass, "__inline-edit--outer-cell-button--lg"), !rowSize), _cx3))
406
+ }, !inEditMode && /*#__PURE__*/React.createElement(InlineEditButton, {
407
+ isActiveCell: cellId === activeCellId,
408
+ renderIcon: setRenderIcon(),
409
+ label: type === 'selection' ? value.text : type === 'date' ? buildDate(value) : value,
410
+ labelIcon: (value === null || value === void 0 ? void 0 : value.icon) || null,
411
+ placeholder: placeholder,
412
+ tabIndex: tabIndex,
413
+ nonEditCell: nonEditCell,
414
+ columnConfig: cell.column,
415
+ totalInlineEditColumns: totalInlineEditColumns,
416
+ totalColumns: totalColumns,
417
+ type: type
418
+ }), !nonEditCell && inEditMode && cellId === activeCellId && /*#__PURE__*/React.createElement(React.Fragment, null, type === 'text' && /*#__PURE__*/React.createElement(TextInput, _extends({
419
+ labelText: cellLabel,
420
+ placeholder: placeholder
421
+ }, inputProps, {
422
+ id: cellId,
423
+ hideLabel: true,
424
+ defaultValue: cellValue,
425
+ onChange: function onChange(event) {
426
+ setCellValue(event.target.value);
427
+
428
+ if (inputProps.onChange) {
429
+ inputProps.onChange(event.target.value);
430
+ }
431
+ },
432
+ ref: textInputRef
433
+ })), type === 'number' && /*#__PURE__*/React.createElement(NumberInput, _extends({
434
+ placeholder: placeholder,
435
+ label: cellLabel
436
+ }, inputProps, {
437
+ id: cellId,
438
+ hideLabel: true,
439
+ defaultValue: cellValue,
440
+ onChange: function onChange(event) {
441
+ setCellValue(event.imaginaryTarget.value);
442
+
443
+ if (inputProps.onChange) {
444
+ inputProps.onChange(event.imaginaryTarget.value);
445
+ }
446
+ },
447
+ ref: numberInputRef
448
+ })), type === 'selection' && renderSelectCell(), type === 'date' && renderDateCell()))
449
+ );
450
+ };
451
+ InlineEditCell.propTypes = {
452
+ cell: PropTypes.object,
453
+ config: PropTypes.object,
454
+ instance: PropTypes.shape({
455
+ columns: PropTypes.arrayOf(PropTypes.object),
456
+ onDataUpdate: PropTypes.func,
457
+ rows: PropTypes.arrayOf(PropTypes.object),
458
+ rowSize: PropTypes.string,
459
+ tableId: PropTypes.string
460
+ }),
461
+ nonEditCell: PropTypes.bool,
462
+ placeholder: PropTypes.string,
463
+ tabIndex: PropTypes.number,
464
+ totalInlineEditColumns: PropTypes.number,
465
+ type: PropTypes.oneOf(['text', 'number', 'selection', 'date']),
466
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.object])
467
+ };
@@ -0,0 +1 @@
1
+ export { InlineEditCell } from './InlineEditCell';
@@ -0,0 +1,112 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+
4
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
+
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+
8
+ /**
9
+ * Copyright IBM Corp. 2022, 2022
10
+ *
11
+ * This source code is licensed under the Apache-2.0 license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ */
14
+ import React, { createContext, useReducer } from 'react';
15
+ import PropTypes from 'prop-types';
16
+ import { returnUpdatedActiveCell } from './returnUpdatedActiveCell';
17
+ import { getCellIdAsObject } from './getCellIdAsObject';
18
+ export var InlineEditContext = /*#__PURE__*/createContext();
19
+
20
+ var inlineEditReducer = function inlineEditReducer(state, action) {
21
+ switch (action.type) {
22
+ case 'ADD_GRID_ACTIVE_FOCUS':
23
+ {
24
+ return _objectSpread(_objectSpread({}, state), {}, {
25
+ gridActive: true,
26
+ activeCellId: action.payload,
27
+ // set default active cell when grid receives focus
28
+ previousActiveCellId: null
29
+ });
30
+ }
31
+
32
+ case 'REMOVE_GRID_ACTIVE_FOCUS':
33
+ {
34
+ return _objectSpread(_objectSpread({}, state), {}, {
35
+ gridActive: false,
36
+ editId: null,
37
+ activeCellId: null,
38
+ previousActiveCellId: action.payload
39
+ });
40
+ }
41
+
42
+ case 'ENTER_EDIT_MODE':
43
+ {
44
+ return _objectSpread(_objectSpread({}, state), {}, {
45
+ activeCellId: action.payload.activeCellId,
46
+ editId: action.payload.editId
47
+ });
48
+ }
49
+
50
+ case 'EXIT_EDIT_MODE':
51
+ {
52
+ return _objectSpread(_objectSpread({}, state), {}, {
53
+ activeCellId: action.payload,
54
+ editId: null
55
+ });
56
+ }
57
+
58
+ case 'UPDATE_ACTIVE_CELL_ID':
59
+ {
60
+ var _action$payload = action.payload,
61
+ direction = _action$payload.direction,
62
+ oldId = _action$payload.oldId,
63
+ instance = _action$payload.instance;
64
+
65
+ if (!action.payload.direction) {
66
+ return _objectSpread(_objectSpread({}, state), {}, {
67
+ activeCellId: action.payload,
68
+ editId: null
69
+ });
70
+ }
71
+
72
+ if (direction && typeof direction === 'string') {
73
+ var activeCellCoords = getCellIdAsObject(oldId);
74
+ var totalVisibleColumns = instance.visibleColumns.filter(function (item) {
75
+ return item.id !== 'spacer';
76
+ });
77
+ return returnUpdatedActiveCell({
78
+ activeCellCoords: activeCellCoords,
79
+ direction: direction,
80
+ totalVisibleColumns: totalVisibleColumns,
81
+ state: state,
82
+ instance: instance
83
+ });
84
+ }
85
+
86
+ break;
87
+ }
88
+
89
+ default:
90
+ return state;
91
+ }
92
+ };
93
+
94
+ export var InlineEditProvider = function InlineEditProvider(_ref) {
95
+ var children = _ref.children;
96
+ var initialState = {};
97
+
98
+ var _useReducer = useReducer(inlineEditReducer, initialState),
99
+ _useReducer2 = _slicedToArray(_useReducer, 2),
100
+ state = _useReducer2[0],
101
+ dispatch = _useReducer2[1];
102
+
103
+ return /*#__PURE__*/React.createElement(InlineEditContext.Provider, {
104
+ value: {
105
+ state: state,
106
+ dispatch: dispatch
107
+ }
108
+ }, children);
109
+ };
110
+ InlineEditProvider.propTypes = {
111
+ children: PropTypes.element
112
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ // Turns activeCellId into an object to be able to
8
+ // update cell coordinates more easily
9
+ export var getCellIdAsObject = function getCellIdAsObject(oldId) {
10
+ var oldIdArr = oldId.split('-');
11
+ var updatedOldValuesArray = oldIdArr.map(function (item) {
12
+ if (isNaN(item)) {
13
+ return item;
14
+ }
15
+
16
+ return Number(item);
17
+ });
18
+ var indexArray = updatedOldValuesArray.filter(Number.isFinite);
19
+ var keyArray = updatedOldValuesArray.filter(function (item) {
20
+ return typeof item === 'string';
21
+ });
22
+ var activeCellCoords = {};
23
+ keyArray.forEach(function (element, index) {
24
+ activeCellCoords[element] = indexArray[index];
25
+ });
26
+ return activeCellCoords;
27
+ };
@@ -0,0 +1 @@
1
+ export { InlineEditProvider, InlineEditContext } from './InlineEditContext';
@@ -0,0 +1,39 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+
7
+ /**
8
+ * Copyright IBM Corp. 2022, 2022
9
+ *
10
+ * This source code is licensed under the Apache-2.0 license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+ import { pkg } from '../../../../../../settings';
14
+ var blockClass = "".concat(pkg.prefix, "--datagrid"); // This function returns the state back to the reducer after
15
+ // determining the new active cell value
16
+
17
+ export var returnUpdatedActiveCell = function returnUpdatedActiveCell(_ref) {
18
+ var activeCellCoords = _ref.activeCellCoords,
19
+ direction = _ref.direction,
20
+ totalVisibleColumns = _ref.totalVisibleColumns,
21
+ state = _ref.state,
22
+ instance = _ref.instance;
23
+
24
+ var newActiveCoords = _objectSpread(_objectSpread({}, activeCellCoords), {}, {
25
+ column: direction === 'right' ? activeCellCoords.column < totalVisibleColumns.length - 1 ? activeCellCoords.column + 1 : activeCellCoords.column : direction === 'left' ? activeCellCoords.column === 0 ? 0 : activeCellCoords.column - 1 : activeCellCoords.column,
26
+ row: direction === 'up' ? activeCellCoords.row === 0 ? 0 : activeCellCoords.row - 1 : direction === 'down' ? activeCellCoords.row < instance.rows.length - 1 ? activeCellCoords.row + 1 : activeCellCoords.row : activeCellCoords.row
27
+ });
28
+
29
+ var newActiveCellId = "column-".concat(newActiveCoords.column, "-row-").concat(newActiveCoords.row);
30
+ var newCellIdButton = document.querySelector("#".concat(instance.tableId, " .").concat(blockClass, "__table-with-inline-edit [data-cell-id=\"").concat(newActiveCellId, "\"] .").concat(blockClass, "__inline-edit-button")); // Allows scrollable area to keep focused/active cell id visible
31
+
32
+ if (newCellIdButton) {
33
+ newCellIdButton === null || newCellIdButton === void 0 ? void 0 : newCellIdButton.focus();
34
+ }
35
+
36
+ return _objectSpread(_objectSpread({}, state), {}, {
37
+ activeCellId: newActiveCellId
38
+ });
39
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export var handleGridFocus = function handleGridFocus(state, dispatch) {
8
+ var gridActive = state.gridActive,
9
+ previousActiveCellId = state.previousActiveCellId;
10
+
11
+ if (!gridActive) {
12
+ // Initialize grid active state
13
+ dispatch({
14
+ type: 'ADD_GRID_ACTIVE_FOCUS',
15
+ payload: previousActiveCellId || 'column-0-row-0' // If there is a previous active cell id that is found use that, otherwise use the first cell in the grid area
16
+
17
+ });
18
+ }
19
+ };