handsontable 0.0.0-next-820d8a2-20221122 → 0.0.0-next-6812ce6-20221122

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of handsontable might be problematic. Click here for more details.

Files changed (57) hide show
  1. package/3rdparty/walkontable/src/cell/range.js +8 -0
  2. package/3rdparty/walkontable/src/cell/range.mjs +8 -0
  3. package/base.js +2 -2
  4. package/base.mjs +2 -2
  5. package/core.d.ts +1 -1
  6. package/core.js +37 -29
  7. package/core.mjs +37 -29
  8. package/dist/handsontable.css +2 -2
  9. package/dist/handsontable.full.css +2 -2
  10. package/dist/handsontable.full.js +3135 -2444
  11. package/dist/handsontable.full.min.css +2 -2
  12. package/dist/handsontable.full.min.js +62 -62
  13. package/dist/handsontable.js +2563 -1872
  14. package/dist/handsontable.min.css +2 -2
  15. package/dist/handsontable.min.js +3 -3
  16. package/dist/languages/all.js +1 -1
  17. package/dist/languages/all.min.js +1 -1
  18. package/dist/languages/en-US.js +1 -1
  19. package/dist/languages/en-US.min.js +1 -1
  20. package/helpers/mixed.js +1 -1
  21. package/helpers/mixed.mjs +1 -1
  22. package/i18n/constants.js +49 -42
  23. package/i18n/constants.mjs +45 -41
  24. package/i18n/languages/en-US.js +1 -1
  25. package/i18n/languages/en-US.mjs +1 -1
  26. package/languages/all.js +1 -1
  27. package/languages/en-US.js +1 -1
  28. package/languages/en-US.mjs +1 -1
  29. package/languages/index.js +1 -1
  30. package/package.json +1 -1
  31. package/pluginHooks.d.ts +7 -2
  32. package/pluginHooks.js +23 -3
  33. package/pluginHooks.mjs +23 -3
  34. package/plugins/contextMenu/contextMenu.d.ts +4 -3
  35. package/plugins/copyPaste/contextMenuItem/copy.js +4 -16
  36. package/plugins/copyPaste/contextMenuItem/copy.mjs +4 -4
  37. package/plugins/copyPaste/contextMenuItem/copyColumnHeadersOnly.js +35 -0
  38. package/plugins/copyPaste/contextMenuItem/copyColumnHeadersOnly.mjs +31 -0
  39. package/plugins/copyPaste/contextMenuItem/copyWithColumnGroupHeaders.js +35 -0
  40. package/plugins/copyPaste/contextMenuItem/copyWithColumnGroupHeaders.mjs +31 -0
  41. package/plugins/copyPaste/contextMenuItem/copyWithColumnHeaders.js +35 -0
  42. package/plugins/copyPaste/contextMenuItem/copyWithColumnHeaders.mjs +31 -0
  43. package/plugins/copyPaste/copyPaste.d.ts +10 -2
  44. package/plugins/copyPaste/copyPaste.js +263 -173
  45. package/plugins/copyPaste/copyPaste.mjs +263 -173
  46. package/plugins/copyPaste/copyableRanges.js +260 -0
  47. package/plugins/copyPaste/copyableRanges.mjs +255 -0
  48. package/plugins/nestedHeaders/nestedHeaders.js +114 -11
  49. package/plugins/nestedHeaders/nestedHeaders.mjs +114 -11
  50. package/plugins/nestedHeaders/stateManager/headersTree.js +1 -0
  51. package/plugins/nestedHeaders/stateManager/headersTree.mjs +1 -0
  52. package/plugins/nestedHeaders/stateManager/index.js +21 -10
  53. package/plugins/nestedHeaders/stateManager/index.mjs +21 -10
  54. package/selection/selection.js +2 -1
  55. package/selection/selection.mjs +2 -1
  56. package/tableView.js +133 -63
  57. package/tableView.mjs +133 -63
@@ -17,15 +17,29 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
17
17
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
18
18
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
19
19
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
21
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
22
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
23
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
25
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
26
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
27
+ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
28
+ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
29
+ function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
30
+ import "core-js/modules/es.array.join.js";
31
+ import "core-js/modules/es.array.concat.js";
20
32
  import "core-js/modules/es.array.iterator.js";
33
+ import "core-js/modules/es.map.js";
21
34
  import "core-js/modules/es.object.to-string.js";
22
35
  import "core-js/modules/es.string.iterator.js";
23
- import "core-js/modules/es.weak-map.js";
24
36
  import "core-js/modules/web.dom-collections.iterator.js";
25
- import "core-js/modules/es.array.join.js";
26
- import "core-js/modules/es.array.index-of.js";
37
+ import "core-js/modules/es.array.map.js";
38
+ import "core-js/modules/es.array.filter.js";
39
+ import "core-js/modules/es.array.from.js";
27
40
  import "core-js/modules/es.regexp.exec.js";
28
- import "core-js/modules/es.array.concat.js";
41
+ import "core-js/modules/es.weak-map.js";
42
+ import "core-js/modules/es.weak-set.js";
29
43
  import "core-js/modules/es.object.set-prototype-of.js";
30
44
  import "core-js/modules/es.object.get-prototype-of.js";
31
45
  import "core-js/modules/es.reflect.construct.js";
@@ -36,18 +50,20 @@ import "core-js/modules/es.symbol.description.js";
36
50
  import "core-js/modules/es.symbol.iterator.js";
37
51
  import "core-js/modules/es.array.slice.js";
38
52
  import "core-js/modules/es.function.name.js";
39
- import "core-js/modules/es.array.from.js";
40
53
  import { BasePlugin } from "../base/index.mjs";
41
54
  import Hooks from "../../pluginHooks.mjs";
42
55
  import { stringify, parse } from "../../3rdparty/SheetClip/index.mjs";
43
56
  import { arrayEach } from "../../helpers/array.mjs";
44
- import { rangeEach } from "../../helpers/number.mjs";
45
57
  import { sanitize } from "../../helpers/string.mjs";
46
58
  import { getSelectionText } from "../../helpers/dom/element.mjs";
47
59
  import copyItem from "./contextMenuItem/copy.mjs";
60
+ import copyColumnHeadersOnlyItem from "./contextMenuItem/copyColumnHeadersOnly.mjs";
61
+ import copyWithColumnGroupHeadersItem from "./contextMenuItem/copyWithColumnGroupHeaders.mjs";
62
+ import copyWithColumnHeadersItem from "./contextMenuItem/copyWithColumnHeaders.mjs";
48
63
  import cutItem from "./contextMenuItem/cut.mjs";
49
64
  import PasteEvent from "./pasteEvent.mjs";
50
65
  import { createElement, destroyElement } from "./focusableElement.mjs";
66
+ import { CopyableRangesFactory, normalizeRanges } from "./copyableRanges.mjs";
51
67
  import { _dataToHTML, htmlToGridSettings } from "../../utils/parseTable.mjs";
52
68
  Hooks.getSingleton().register('afterCopyLimit');
53
69
  Hooks.getSingleton().register('modifyCopyableRange');
@@ -60,9 +76,6 @@ Hooks.getSingleton().register('afterCopy');
60
76
  export var PLUGIN_KEY = 'copyPaste';
61
77
  export var PLUGIN_PRIORITY = 80;
62
78
  var SETTING_KEYS = ['fragmentSelection'];
63
- var ROWS_LIMIT = Infinity;
64
- var COLUMNS_LIMIT = Infinity;
65
- var privatePool = new WeakMap();
66
79
  var META_HEAD = ['<meta name="generator" content="Handsontable"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>'].join('');
67
80
 
68
81
  /* eslint-disable jsdoc/require-description-complete-sentence */
@@ -78,6 +91,9 @@ var META_HEAD = ['<meta name="generator" content="Handsontable"/>', '<style type
78
91
  * * `'columnsLimit'` (see {@link CopyPaste#columnsLimit})
79
92
  * * `'rowsLimit'` (see {@link CopyPaste#rowsLimit})
80
93
  * * `'pasteMode'` (see {@link CopyPaste#pasteMode})
94
+ * * `'copyColumnHeaders'`
95
+ * * `'copyColumnGroupHeaders'`
96
+ * * `'copyColumnHeadersOnly'`
81
97
  * * `'uiContainer'` (see {@link CopyPaste#uiContainer}).
82
98
  *
83
99
  * See [the copy/paste demo](@/guides/cell-features/clipboard.md) for examples.
@@ -91,82 +107,96 @@ var META_HEAD = ['<meta name="generator" content="Handsontable"/>', '<style type
91
107
  * columnsLimit: 25,
92
108
  * rowsLimit: 50,
93
109
  * pasteMode: 'shift_down',
110
+ * copyColumnHeaders: true,
111
+ * copyColumnGroupHeaders: true,
112
+ * copyColumnHeadersOnly: true,
94
113
  * uiContainer: document.body,
95
114
  * },
96
115
  * ```
97
116
  * @class CopyPaste
98
117
  * @plugin CopyPaste
99
118
  */
119
+ var _enableCopyColumnHeaders = /*#__PURE__*/new WeakMap();
120
+ var _enableCopyColumnGroupHeaders = /*#__PURE__*/new WeakMap();
121
+ var _enableCopyColumnHeadersOnly = /*#__PURE__*/new WeakMap();
122
+ var _copyMode = /*#__PURE__*/new WeakMap();
123
+ var _isTriggeredByCopy = /*#__PURE__*/new WeakMap();
124
+ var _isTriggeredByCut = /*#__PURE__*/new WeakMap();
125
+ var _copyableRangesFactory = /*#__PURE__*/new WeakMap();
126
+ var _countCopiedHeaders = /*#__PURE__*/new WeakSet();
100
127
  export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
101
128
  _inherits(CopyPaste, _BasePlugin);
102
129
  var _super = _createSuper(CopyPaste);
103
- function CopyPaste(hotInstance) {
130
+ function CopyPaste() {
104
131
  var _this;
105
132
  _classCallCheck(this, CopyPaste);
106
- _this = _super.call(this, hotInstance);
107
- /**
108
- * Maximum number of columns than can be copied to clipboard using <kbd>**Ctrl**</kbd>/<kbd>**Cmd**</kbd> + <kbd>**C**</kbd>.
109
- *
110
- * @type {number}
111
- * @default Infinity
112
- */
113
- _this.columnsLimit = COLUMNS_LIMIT;
114
- /**
115
- * Ranges of the cells coordinates, which should be used to copy/cut/paste actions.
116
- *
117
- * @private
118
- * @type {Array}
119
- */
120
- _this.copyableRanges = [];
121
- /**
122
- * Provides focusable element to support IME and copy/paste/cut actions.
123
- *
124
- * @private
125
- * @type {FocusableWrapper}
126
- */
127
- _this.focusableElement = void 0;
128
- /**
129
- * Defines paste (<kbd>**Ctrl**</kbd>/<kbd>**Cmd**</kbd> + <kbd>**V**</kbd>) behavior.
130
- * * Default value `"overwrite"` will paste clipboard value over current selection.
131
- * * When set to `"shift_down"`, clipboard data will be pasted in place of current selection, while all selected cells are moved down.
132
- * * When set to `"shift_right"`, clipboard data will be pasted in place of current selection, while all selected cells are moved right.
133
- *
134
- * @type {string}
135
- * @default 'overwrite'
136
- */
137
- _this.pasteMode = 'overwrite';
138
- /**
139
- * Maximum number of rows than can be copied to clipboard using <kbd>**Ctrl**</kbd>/<kbd>**Cmd**</kbd> + <kbd>**C**</kbd>.
140
- *
141
- * @type {number}
142
- * @default Infinity
143
- */
144
- _this.rowsLimit = ROWS_LIMIT;
145
-
146
- /**
147
- * UI container for the secondary focusable element.
148
- *
149
- * @type {HTMLElement}
150
- */
151
- _this.uiContainer = _this.hot.rootDocument.body;
152
- privatePool.set(_assertThisInitialized(_this), {
153
- isTriggeredByCopy: false,
154
- isTriggeredByCut: false,
155
- isBeginEditing: false,
156
- isFragmentSelectionEnabled: false
133
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
134
+ args[_key] = arguments[_key];
135
+ }
136
+ _this = _super.call.apply(_super, [this].concat(args));
137
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _countCopiedHeaders);
138
+ _defineProperty(_assertThisInitialized(_this), "columnsLimit", Infinity);
139
+ _defineProperty(_assertThisInitialized(_this), "rowsLimit", Infinity);
140
+ _defineProperty(_assertThisInitialized(_this), "pasteMode", 'overwrite');
141
+ _defineProperty(_assertThisInitialized(_this), "uiContainer", _this.hot.rootDocument.body);
142
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _enableCopyColumnHeaders, {
143
+ writable: true,
144
+ value: false
145
+ });
146
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _enableCopyColumnGroupHeaders, {
147
+ writable: true,
148
+ value: false
149
+ });
150
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _enableCopyColumnHeadersOnly, {
151
+ writable: true,
152
+ value: false
153
+ });
154
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _copyMode, {
155
+ writable: true,
156
+ value: 'cells-only'
157
+ });
158
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _isTriggeredByCopy, {
159
+ writable: true,
160
+ value: false
161
+ });
162
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _isTriggeredByCut, {
163
+ writable: true,
164
+ value: false
165
+ });
166
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _copyableRangesFactory, {
167
+ writable: true,
168
+ value: new CopyableRangesFactory({
169
+ countRows: function countRows() {
170
+ return _this.hot.countRows();
171
+ },
172
+ countColumns: function countColumns() {
173
+ return _this.hot.countCols();
174
+ },
175
+ rowsLimit: function rowsLimit() {
176
+ return _this.rowsLimit;
177
+ },
178
+ columnsLimit: function columnsLimit() {
179
+ return _this.columnsLimit;
180
+ },
181
+ countColumnHeaders: function countColumnHeaders() {
182
+ return _this.hot.view.getColumnHeadersCount();
183
+ }
184
+ })
157
185
  });
186
+ _defineProperty(_assertThisInitialized(_this), "copyableRanges", []);
187
+ _defineProperty(_assertThisInitialized(_this), "focusableElement", void 0);
158
188
  return _this;
159
189
  }
160
-
161
- /**
162
- * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
163
- * hook and if it returns `true` then the {@link CopyPaste#enablePlugin} method is called.
164
- *
165
- * @returns {boolean}
166
- */
167
190
  _createClass(CopyPaste, [{
168
191
  key: "isEnabled",
169
- value: function isEnabled() {
192
+ value:
193
+ /**
194
+ * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit}
195
+ * hook and if it returns `true` then the {@link CopyPaste#enablePlugin} method is called.
196
+ *
197
+ * @returns {boolean}
198
+ */
199
+ function isEnabled() {
170
200
  return !!this.hot.getSettings()[PLUGIN_KEY];
171
201
  }
172
202
 
@@ -181,15 +211,16 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
181
211
  return;
182
212
  }
183
213
  var _this$hot$getSettings = this.hot.getSettings(),
184
- settings = _this$hot$getSettings[PLUGIN_KEY],
185
- fragmentSelection = _this$hot$getSettings.fragmentSelection;
186
- var priv = privatePool.get(this);
187
- priv.isFragmentSelectionEnabled = !!fragmentSelection;
214
+ settings = _this$hot$getSettings[PLUGIN_KEY];
188
215
  if (_typeof(settings) === 'object') {
189
- this.pasteMode = settings.pasteMode || this.pasteMode;
216
+ var _settings$pasteMode, _settings$uiContainer;
217
+ this.pasteMode = (_settings$pasteMode = settings.pasteMode) !== null && _settings$pasteMode !== void 0 ? _settings$pasteMode : this.pasteMode;
190
218
  this.rowsLimit = isNaN(settings.rowsLimit) ? this.rowsLimit : settings.rowsLimit;
191
219
  this.columnsLimit = isNaN(settings.columnsLimit) ? this.columnsLimit : settings.columnsLimit;
192
- this.uiContainer = settings.uiContainer || this.uiContainer;
220
+ _classPrivateFieldSet(this, _enableCopyColumnHeaders, !!settings.copyColumnHeaders);
221
+ _classPrivateFieldSet(this, _enableCopyColumnGroupHeaders, !!settings.copyColumnGroupHeaders);
222
+ _classPrivateFieldSet(this, _enableCopyColumnHeadersOnly, !!settings.copyColumnHeadersOnly);
223
+ this.uiContainer = (_settings$uiContainer = settings.uiContainer) !== null && _settings$uiContainer !== void 0 ? _settings$uiContainer : this.uiContainer;
193
224
  }
194
225
  this.addHook('afterContextMenuDefaultOptions', function (options) {
195
226
  return _this2.onAfterContextMenuDefaultOptions(options);
@@ -243,105 +274,110 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
243
274
  }
244
275
 
245
276
  /**
246
- * Copies the selected cell into the clipboard.
277
+ * Copies the selected cell with or without column headers into the clipboard.
278
+ *
279
+ * @param {'cells-only' | 'column-headers-only' | 'with-all-column-headers' | 'with-column-headers'} [copyMode='cells-only']
280
+ * Defines the data range to copy. Possible values: `cells-only` (copy selected cells only),
281
+ * `column-headers-only` (copy the most-bottom column headers only), `with-all-column-headers` (copy cells
282
+ * with all column headers levels) or `with-column-headers` (copy cells with the most-bottom column headers).
247
283
  */
248
284
  }, {
249
285
  key: "copy",
250
286
  value: function copy() {
251
- var priv = privatePool.get(this);
252
- priv.isTriggeredByCopy = true;
287
+ var copyMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'cells-only';
288
+ _classPrivateFieldSet(this, _copyMode, copyMode);
289
+ _classPrivateFieldSet(this, _isTriggeredByCopy, true);
253
290
  this.getOrCreateFocusableElement();
254
291
  this.focusableElement.focus();
255
292
  this.hot.rootDocument.execCommand('copy');
256
293
  }
257
294
 
295
+ /**
296
+ * Copies the selected cell/cells into the clipboard.
297
+ */
298
+ }, {
299
+ key: "copyCellsOnly",
300
+ value: function copyCellsOnly() {
301
+ this.copy('cells-only');
302
+ }
303
+ /**
304
+ * Copies only the most-bottom column headers into the clipboard.
305
+ */
306
+ }, {
307
+ key: "copyColumnHeadersOnly",
308
+ value: function copyColumnHeadersOnly() {
309
+ this.copy('column-headers-only');
310
+ }
311
+ /**
312
+ * Copies the selected cell/cells and all column headers levels (including column group) into the clipboard.
313
+ */
314
+ }, {
315
+ key: "copyWithAllColumnHeaders",
316
+ value: function copyWithAllColumnHeaders() {
317
+ this.copy('with-column-group-headers');
318
+ }
319
+ /**
320
+ * Copies the selected cell/cells and most-bottom column headers into the clipboard.
321
+ */
322
+ }, {
323
+ key: "copyWithColumnHeaders",
324
+ value: function copyWithColumnHeaders() {
325
+ this.copy('with-column-headers');
326
+ }
327
+
258
328
  /**
259
329
  * Cuts the selected cell into the clipboard.
260
330
  */
261
331
  }, {
262
332
  key: "cut",
263
333
  value: function cut() {
264
- var priv = privatePool.get(this);
265
- priv.isTriggeredByCut = true;
334
+ _classPrivateFieldSet(this, _isTriggeredByCut, true);
266
335
  this.getOrCreateFocusableElement();
267
336
  this.focusableElement.focus();
268
337
  this.hot.rootDocument.execCommand('cut');
269
338
  }
270
339
 
271
340
  /**
272
- * Creates copyable text releated to range objects.
341
+ * Creates copyable text related to range objects.
273
342
  *
274
- * @param {object[]} ranges Array of objects with properties `startRow`, `endRow`, `startCol` and `endCol`.
343
+ * @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} ranges Array of objects with properties `startRow`, `endRow`, `startCol` and `endCol`.
275
344
  * @returns {string} Returns string which will be copied into clipboard.
276
345
  */
277
346
  }, {
278
347
  key: "getRangedCopyableData",
279
348
  value: function getRangedCopyableData(ranges) {
280
- var _this3 = this;
281
- var dataSet = [];
282
- var copyableRows = [];
283
- var copyableColumns = [];
284
-
285
- // Count all copyable rows and columns
286
- arrayEach(ranges, function (range) {
287
- rangeEach(range.startRow, range.endRow, function (row) {
288
- if (copyableRows.indexOf(row) === -1) {
289
- copyableRows.push(row);
290
- }
291
- });
292
- rangeEach(range.startCol, range.endCol, function (column) {
293
- if (copyableColumns.indexOf(column) === -1) {
294
- copyableColumns.push(column);
295
- }
296
- });
297
- });
298
- // Concat all rows and columns data defined in ranges into one copyable string
299
- arrayEach(copyableRows, function (row) {
300
- var rowSet = [];
301
- arrayEach(copyableColumns, function (column) {
302
- rowSet.push(_this3.hot.getCopyableData(row, column));
303
- });
304
- dataSet.push(rowSet);
305
- });
306
- return stringify(dataSet);
349
+ return stringify(this.getRangedData(ranges));
307
350
  }
308
351
 
309
352
  /**
310
- * Creates copyable text releated to range objects.
353
+ * Creates copyable text related to range objects.
311
354
  *
312
- * @param {object[]} ranges Array of objects with properties `startRow`, `startCol`, `endRow` and `endCol`.
355
+ * @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} ranges Array of objects with properties `startRow`, `startCol`, `endRow` and `endCol`.
313
356
  * @returns {Array[]} Returns array of arrays which will be copied into clipboard.
314
357
  */
315
358
  }, {
316
359
  key: "getRangedData",
317
360
  value: function getRangedData(ranges) {
318
- var _this4 = this;
319
- var dataSet = [];
320
- var copyableRows = [];
321
- var copyableColumns = [];
361
+ var _this3 = this;
362
+ var data = [];
363
+ var _normalizeRanges = normalizeRanges(ranges),
364
+ rows = _normalizeRanges.rows,
365
+ columns = _normalizeRanges.columns;
322
366
 
323
- // Count all copyable rows and columns
324
- arrayEach(ranges, function (range) {
325
- rangeEach(range.startRow, range.endRow, function (row) {
326
- if (copyableRows.indexOf(row) === -1) {
327
- copyableRows.push(row);
328
- }
329
- });
330
- rangeEach(range.startCol, range.endCol, function (column) {
331
- if (copyableColumns.indexOf(column) === -1) {
332
- copyableColumns.push(column);
333
- }
334
- });
335
- });
336
367
  // Concat all rows and columns data defined in ranges into one copyable string
337
- arrayEach(copyableRows, function (row) {
368
+ arrayEach(rows, function (row) {
338
369
  var rowSet = [];
339
- arrayEach(copyableColumns, function (column) {
340
- rowSet.push(_this4.hot.getCopyableData(row, column));
370
+ arrayEach(columns, function (column) {
371
+ if (row < 0) {
372
+ // 'row' as the second argument act here as 'headerLevel' argument
373
+ rowSet.push(_this3.hot.getColHeader(column, row));
374
+ } else {
375
+ rowSet.push(_this3.hot.getCopyableData(row, column));
376
+ }
341
377
  });
342
- dataSet.push(rowSet);
378
+ data.push(rowSet);
343
379
  });
344
- return dataSet;
380
+ return data;
345
381
  }
346
382
 
347
383
  /**
@@ -377,27 +413,43 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
377
413
  }, {
378
414
  key: "setCopyableText",
379
415
  value: function setCopyableText() {
380
- var selRange = this.hot.getSelectedRangeLast();
381
- if (!selRange) {
416
+ var selectionRange = this.hot.getSelectedRangeLast();
417
+ if (!selectionRange) {
382
418
  return;
383
419
  }
384
- var topStart = selRange.getTopStartCorner();
385
- var bottomEnd = selRange.getBottomEndCorner();
386
- var startRow = topStart.row;
387
- var startCol = topStart.col;
388
- var endRow = bottomEnd.row;
389
- var endCol = bottomEnd.col;
390
- var finalEndRow = Math.min(endRow, startRow + this.rowsLimit - 1);
391
- var finalEndCol = Math.min(endCol, startCol + this.columnsLimit - 1);
392
- this.copyableRanges.length = 0;
393
- this.copyableRanges.push({
394
- startRow: startRow,
395
- startCol: startCol,
396
- endRow: finalEndRow,
397
- endCol: finalEndCol
420
+ _classPrivateFieldGet(this, _copyableRangesFactory).setSelectedRange(selectionRange);
421
+ var groupedRanges = new Map([['headers', null], ['cells', null]]);
422
+ if (_classPrivateFieldGet(this, _copyMode) === 'column-headers-only') {
423
+ groupedRanges.set('headers', _classPrivateFieldGet(this, _copyableRangesFactory).getMostBottomColumnHeadersRange());
424
+ } else {
425
+ if (_classPrivateFieldGet(this, _copyMode) === 'with-column-headers') {
426
+ groupedRanges.set('headers', _classPrivateFieldGet(this, _copyableRangesFactory).getMostBottomColumnHeadersRange());
427
+ } else if (_classPrivateFieldGet(this, _copyMode) === 'with-column-group-headers') {
428
+ groupedRanges.set('headers', _classPrivateFieldGet(this, _copyableRangesFactory).getAllColumnHeadersRange());
429
+ }
430
+ groupedRanges.set('cells', _classPrivateFieldGet(this, _copyableRangesFactory).getCellsRange());
431
+ }
432
+ this.copyableRanges = Array.from(groupedRanges.values()).filter(function (range) {
433
+ return range !== null;
434
+ }).map(function (_ref) {
435
+ var startRow = _ref.startRow,
436
+ startCol = _ref.startCol,
437
+ endRow = _ref.endRow,
438
+ endCol = _ref.endCol;
439
+ return {
440
+ startRow: startRow,
441
+ startCol: startCol,
442
+ endRow: endRow,
443
+ endCol: endCol
444
+ };
398
445
  });
399
446
  this.copyableRanges = this.hot.runHooks('modifyCopyableRange', this.copyableRanges);
400
- if (endRow !== finalEndRow || endCol !== finalEndCol) {
447
+ var cellsRange = groupedRanges.get('cells');
448
+ if (cellsRange !== null && cellsRange.isRangeTrimmed) {
449
+ var startRow = cellsRange.startRow,
450
+ startCol = cellsRange.startCol,
451
+ endRow = cellsRange.endRow,
452
+ endCol = cellsRange.endCol;
401
453
  this.hot.runHooks('afterCopyLimit', endRow - startRow + 1, endCol - startCol + 1, this.rowsLimit, this.columnsLimit);
402
454
  }
403
455
  }
@@ -410,8 +462,8 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
410
462
  }, {
411
463
  key: "getOrCreateFocusableElement",
412
464
  value: function getOrCreateFocusableElement() {
413
- var editor = this.hot.getActiveEditor();
414
- var editableElement = editor ? editor.TEXTAREA : void 0;
465
+ var _this$hot$getActiveEd;
466
+ var editableElement = (_this$hot$getActiveEd = this.hot.getActiveEditor()) === null || _this$hot$getActiveEd === void 0 ? void 0 : _this$hot$getActiveEd.TEXTAREA;
415
467
  if (editableElement) {
416
468
  this.focusableElement.setFocusableElement(editableElement);
417
469
  } else {
@@ -428,10 +480,21 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
428
480
  }, {
429
481
  key: "isEditorOpened",
430
482
  value: function isEditorOpened() {
431
- var editor = this.hot.getActiveEditor();
432
- return editor && editor.isOpened();
483
+ var _this$hot$getActiveEd2;
484
+ return (_this$hot$getActiveEd2 = this.hot.getActiveEditor()) === null || _this$hot$getActiveEd2 === void 0 ? void 0 : _this$hot$getActiveEd2.isOpened();
433
485
  }
434
486
 
487
+ /**
488
+ * Counts how many column headers will be copied based on the passed range.
489
+ *
490
+ * @private
491
+ * @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} ranges Array of objects with properties `startRow`, `startCol`, `endRow` and `endCol`.
492
+ * @returns {{ columnHeadersCount: number }} Returns an object with keys that holds
493
+ * information with the number of copied headers.
494
+ */
495
+ }, {
496
+ key: "populateValues",
497
+ value:
435
498
  /**
436
499
  * Prepares new values to populate them into datasource.
437
500
  *
@@ -440,9 +503,7 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
440
503
  * @param {Array} [selection] The selection which indicates from what position the data will be populated.
441
504
  * @returns {Array} Range coordinates after populate data.
442
505
  */
443
- }, {
444
- key: "populateValues",
445
- value: function populateValues(inputArray) {
506
+ function populateValues(inputArray) {
446
507
  var selection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.hot.getSelectedRangeLast();
447
508
  if (!inputArray.length) {
448
509
  return;
@@ -505,25 +566,26 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
505
566
  }, {
506
567
  key: "onCopy",
507
568
  value: function onCopy(event) {
508
- var priv = privatePool.get(this);
509
- if (!this.hot.isListening() && !priv.isTriggeredByCopy || this.isEditorOpened()) {
569
+ if (!this.hot.isListening() && !_classPrivateFieldGet(this, _isTriggeredByCopy) || this.isEditorOpened()) {
510
570
  return;
511
571
  }
512
572
  this.setCopyableText();
513
- priv.isTriggeredByCopy = false;
514
- var rangedData = this.getRangedData(this.copyableRanges);
515
- var allowCopying = !!this.hot.runHooks('beforeCopy', rangedData, this.copyableRanges);
573
+ _classPrivateFieldSet(this, _isTriggeredByCopy, false);
574
+ var data = this.getRangedData(this.copyableRanges);
575
+ var copiedHeadersCount = _classPrivateMethodGet(this, _countCopiedHeaders, _countCopiedHeaders2).call(this, this.copyableRanges);
576
+ var allowCopying = !!this.hot.runHooks('beforeCopy', data, this.copyableRanges, copiedHeadersCount);
516
577
  if (allowCopying) {
517
- var textPlain = stringify(rangedData);
578
+ var textPlain = stringify(data);
518
579
  if (event && event.clipboardData) {
519
- var textHTML = _dataToHTML(rangedData, this.hot.rootDocument);
580
+ var textHTML = _dataToHTML(data, this.hot.rootDocument);
520
581
  event.clipboardData.setData('text/plain', textPlain);
521
582
  event.clipboardData.setData('text/html', [META_HEAD, textHTML].join(''));
522
583
  } else if (typeof ClipboardEvent === 'undefined') {
523
584
  this.hot.rootWindow.clipboardData.setData('Text', textPlain);
524
585
  }
525
- this.hot.runHooks('afterCopy', rangedData, this.copyableRanges);
586
+ this.hot.runHooks('afterCopy', data, this.copyableRanges, copiedHeadersCount);
526
587
  }
588
+ _classPrivateFieldSet(this, _copyMode, 'cells-only');
527
589
  event.preventDefault();
528
590
  }
529
591
 
@@ -536,12 +598,11 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
536
598
  }, {
537
599
  key: "onCut",
538
600
  value: function onCut(event) {
539
- var priv = privatePool.get(this);
540
- if (!this.hot.isListening() && !priv.isTriggeredByCut || this.isEditorOpened()) {
601
+ if (!this.hot.isListening() && !_classPrivateFieldGet(this, _isTriggeredByCut) || this.isEditorOpened()) {
541
602
  return;
542
603
  }
543
604
  this.setCopyableText();
544
- priv.isTriggeredByCut = false;
605
+ _classPrivateFieldSet(this, _isTriggeredByCut, false);
545
606
  var rangedData = this.getRangedData(this.copyableRanges);
546
607
  var allowCuttingOut = !!this.hot.runHooks('beforeCut', rangedData, this.copyableRanges);
547
608
  if (allowCuttingOut) {
@@ -620,7 +681,17 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
620
681
  value: function onAfterContextMenuDefaultOptions(options) {
621
682
  options.items.push({
622
683
  name: '---------'
623
- }, copyItem(this), cutItem(this));
684
+ }, copyItem(this));
685
+ if (_classPrivateFieldGet(this, _enableCopyColumnHeaders)) {
686
+ options.items.push(copyWithColumnHeadersItem(this));
687
+ }
688
+ if (_classPrivateFieldGet(this, _enableCopyColumnGroupHeaders)) {
689
+ options.items.push(copyWithColumnGroupHeadersItem(this));
690
+ }
691
+ if (_classPrivateFieldGet(this, _enableCopyColumnHeadersOnly)) {
692
+ options.items.push(copyColumnHeadersOnlyItem(this));
693
+ }
694
+ options.items.push(cutItem(this));
624
695
  }
625
696
 
626
697
  /**
@@ -648,13 +719,11 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
648
719
  }, {
649
720
  key: "onAfterSelectionEnd",
650
721
  value: function onAfterSelectionEnd() {
651
- var _privatePool$get = privatePool.get(this),
652
- isFragmentSelectionEnabled = _privatePool$get.isFragmentSelectionEnabled;
653
722
  if (this.isEditorOpened()) {
654
723
  return;
655
724
  }
656
725
  this.getOrCreateFocusableElement();
657
- if (isFragmentSelectionEnabled && this.focusableElement.getFocusableElement() !== this.hot.rootDocument.activeElement && getSelectionText()) {
726
+ if (this.hot.getSettings().fragmentSelection && this.focusableElement.getFocusableElement() !== this.hot.rootDocument.activeElement && getSelectionText()) {
658
727
  return;
659
728
  }
660
729
  this.setCopyableText();
@@ -708,6 +777,27 @@ export var CopyPaste = /*#__PURE__*/function (_BasePlugin) {
708
777
  get: function get() {
709
778
  return PLUGIN_PRIORITY;
710
779
  }
780
+
781
+ /**
782
+ * Maximum number of columns than can be copied to clipboard using <kbd>**Ctrl**</kbd>/<kbd>**Cmd**</kbd> + <kbd>**C**</kbd>.
783
+ *
784
+ * @type {number}
785
+ * @default Infinity
786
+ */
711
787
  }]);
712
788
  return CopyPaste;
713
- }(BasePlugin);
789
+ }(BasePlugin);
790
+ function _countCopiedHeaders2(ranges) {
791
+ var _normalizeRanges2 = normalizeRanges(ranges),
792
+ rows = _normalizeRanges2.rows;
793
+ var columnHeadersCount = 0;
794
+ for (var row = 0; row < rows.length; row++) {
795
+ if (rows[row] >= 0) {
796
+ break;
797
+ }
798
+ columnHeadersCount += 1;
799
+ }
800
+ return {
801
+ columnHeadersCount: columnHeadersCount
802
+ };
803
+ }