handsontable 14.0.0-next-5fd908e-20231030 → 14.0.0-next-f88c253-20231106

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 (34) hide show
  1. package/base.js +2 -2
  2. package/base.mjs +2 -2
  3. package/dist/handsontable.css +2 -2
  4. package/dist/handsontable.full.css +2 -2
  5. package/dist/handsontable.full.js +2069 -3358
  6. package/dist/handsontable.full.min.css +2 -2
  7. package/dist/handsontable.full.min.js +57 -64
  8. package/dist/handsontable.js +2071 -3360
  9. package/dist/handsontable.min.css +2 -2
  10. package/dist/handsontable.min.js +16 -23
  11. package/helpers/mixed.js +2 -2
  12. package/helpers/mixed.mjs +2 -2
  13. package/package.json +1 -1
  14. package/pluginHooks.d.ts +6 -28
  15. package/pluginHooks.js +62 -116
  16. package/pluginHooks.mjs +62 -116
  17. package/plugins/copyPaste/clipboardData.js +18 -0
  18. package/plugins/copyPaste/clipboardData.mjs +14 -0
  19. package/plugins/copyPaste/copyPaste.js +92 -38
  20. package/plugins/copyPaste/copyPaste.mjs +94 -40
  21. package/plugins/copyPaste/pasteEvent.js +14 -0
  22. package/plugins/copyPaste/pasteEvent.mjs +9 -0
  23. package/plugins/nestedHeaders/nestedHeaders.js +22 -21
  24. package/plugins/nestedHeaders/nestedHeaders.mjs +22 -21
  25. package/utils/parseTable.js +83 -527
  26. package/utils/parseTable.mjs +82 -523
  27. package/plugins/copyPaste/clipboardData/clipboardData.js +0 -516
  28. package/plugins/copyPaste/clipboardData/clipboardData.mjs +0 -512
  29. package/plugins/copyPaste/clipboardData/copyClipboardData.js +0 -69
  30. package/plugins/copyPaste/clipboardData/copyClipboardData.mjs +0 -65
  31. package/plugins/copyPaste/clipboardData/index.js +0 -9
  32. package/plugins/copyPaste/clipboardData/index.mjs +0 -4
  33. package/plugins/copyPaste/clipboardData/pasteClipboardData.js +0 -81
  34. package/plugins/copyPaste/clipboardData/pasteClipboardData.mjs +0 -77
package/pluginHooks.mjs CHANGED
@@ -1503,35 +1503,26 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1503
1503
  * Fired by {@link CopyPaste} plugin before copying the values to the clipboard and before clearing values of
1504
1504
  * the selected cells. This hook is fired when {@link Options#copyPaste} option is enabled.
1505
1505
  *
1506
- * Note: Please keep in mind since @14.0.0 the method arguments has been changed.
1507
- *
1508
1506
  * @event Hooks#beforeCut
1509
- * @param {object} clipboardData Information about cut action which is going to happen.
1510
- * @param {Function} clipboardData.removeRow Remove row from the copied dataset.
1511
- * @param {Function} clipboardData.removeColumn Remove column from the copied dataset.
1512
- * @param {Function} clipboardData.insertAtRow Insert values at row index.
1513
- * @param {Function} clipboardData.insertAtColumn Insert values at column index.
1514
- * @param {Function} clipboardData.setCellAt Change headers or cells in the copied dataset.
1515
- * @param {Function} clipboardData.getCellAt Get headers or cells from the copied dataset.
1516
- * @param {Function} clipboardData.getData Gets copied data stored as array of arrays.
1517
- * @param {Function} clipboardData.getMetaInfo Gets meta information for the copied data.
1518
- * @param {Function} clipboardData.getRanges Returns ranges related to copied part of Handsontable.
1507
+ * @param {Array[]} data An array of arrays which contains data to cut.
1508
+ * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
1509
+ * which will be cut out.
1519
1510
  * @returns {*} If returns `false` then operation of the cutting out is canceled.
1520
1511
  * @example
1521
1512
  * ::: only-for javascript
1522
1513
  * ```js
1523
- * // To disregard a single row or column, remove it from copied dataset using `removeRows`/`removeColumns` method on the object from the first callback argument.
1514
+ * // To disregard a single row, remove it from the array using data.splice(i, 1).
1524
1515
  * new Handsontable(element, {
1525
- * beforeCut: function(clipboardData) {
1526
- * // clipboardData.getData() -> [[1, 2, 3], [4, 5, 6]]
1527
- * clipboardData.removeRows([0]);
1528
- * clipboardData.removeColumns([0]);
1529
- * // clipboardData.getData() -> [[5, 6]]
1516
+ * beforeCut: function(data, coords) {
1517
+ * // data -> [[1, 2, 3], [4, 5, 6]]
1518
+ * data.splice(0, 1);
1519
+ * // data -> [[4, 5, 6]]
1520
+ * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
1530
1521
  * }
1531
1522
  * });
1532
1523
  * // To cancel a cutting action, just return `false`.
1533
1524
  * new Handsontable(element, {
1534
- * beforeCut: function(clipboardData) {
1525
+ * beforeCut: function(data, coords) {
1535
1526
  * return false;
1536
1527
  * }
1537
1528
  * });
@@ -1540,18 +1531,18 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1540
1531
  *
1541
1532
  * ::: only-for react
1542
1533
  * ```jsx
1543
- * // To disregard a single row or column, remove it from copied dataset using `removeRows`/`removeColumns` method on the object from the first callback argument.
1534
+ * // To disregard a single row, remove it from the array using data.splice(i, 1).
1544
1535
  * <HotTable
1545
- * beforeCut={(clipboardData) => {
1546
- * // clipboardData.getData() -> [[1, 2, 3], [4, 5, 6]]
1547
- * clipboardData.removeRows([0]);
1548
- * clipboardData.removeColumns([0]);
1549
- * // clipboardData.getData() -> [[5, 6]]
1536
+ * beforeCut={(data, coords) => {
1537
+ * // data -> [[1, 2, 3], [4, 5, 6]]
1538
+ * data.splice(0, 1);
1539
+ * // data -> [[4, 5, 6]]
1540
+ * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
1550
1541
  * }}
1551
1542
  * />
1552
1543
  * // To cancel a cutting action, just return `false`.
1553
1544
  * <HotTable
1554
- * beforeCut={(clipboardData) => {
1545
+ * beforeCut={(data, coords) => {
1555
1546
  * return false;
1556
1547
  * }}
1557
1548
  * />
@@ -1563,50 +1554,33 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1563
1554
  * Fired by {@link CopyPaste} plugin after data was cut out from the table. This hook is fired when
1564
1555
  * {@link Options#copyPaste} option is enabled.
1565
1556
  *
1566
- * Note: Please keep in mind since @14.0.0 the method arguments has been changed.
1567
- *
1568
1557
  * @event Hooks#afterCut
1569
- * @param {object} clipboardData Information about already performed cut action.
1570
- * @param {Function} clipboardData.removeRow Remove row from the copied dataset.
1571
- * @param {Function} clipboardData.removeColumn Remove column from the copied dataset.
1572
- * @param {Function} clipboardData.insertAtRow Insert values at row index.
1573
- * @param {Function} clipboardData.insertAtColumn Insert values at column index.
1574
- * @param {Function} clipboardData.setCellAt Change headers or cells in the copied dataset.
1575
- * @param {Function} clipboardData.getCellAt Get headers or cells from the copied dataset.
1576
- * @param {Function} clipboardData.getData Gets copied data stored as array of arrays.
1577
- * @param {Function} clipboardData.getMetaInfo Gets meta information for the copied data.
1578
- * @param {Function} clipboardData.getRanges Returns ranges related to copied part of Handsontable.
1558
+ * @param {Array[]} data An array of arrays with the cut data.
1559
+ * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
1560
+ * which was cut out.
1579
1561
  */
1580
1562
  'afterCut',
1581
1563
  /**
1582
1564
  * Fired before values are copied to the clipboard.
1583
1565
  *
1584
- * Note: Please keep in mind since @14.0.0 the method arguments has been changed.
1585
- *
1586
1566
  * @event Hooks#beforeCopy
1587
- * @param {object} clipboardData Information about copy action which is going to happen.
1588
- * @param {Function} clipboardData.removeRow Remove row from the copied dataset.
1589
- * @param {Function} clipboardData.removeColumn Remove column from the copied dataset.
1590
- * @param {Function} clipboardData.insertAtRow Insert values at row index.
1591
- * @param {Function} clipboardData.insertAtColumn Insert values at column index.
1592
- * @param {Function} clipboardData.setCellAt Change headers or cells in the copied dataset.
1593
- * @param {Function} clipboardData.getCellAt Get headers or cells from the copied dataset.
1594
- * @param {Function} clipboardData.getData Gets copied data stored as array of arrays.
1595
- * @param {Function} clipboardData.getMetaInfo Gets meta information for the copied data.
1596
- * @param {Function} clipboardData.getRanges Returns ranges related to copied part of Handsontable.
1567
+ * @param {Array[]} data An array of arrays which contains data to copied.
1568
+ * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
1569
+ * which will copied.
1570
+ * @param {{ columnHeadersCount: number }} copiedHeadersCount (Since 12.3.0) The number of copied column headers.
1597
1571
  * @returns {*} If returns `false` then copying is canceled.
1598
1572
  *
1599
1573
  * @example
1600
1574
  * ::: only-for javascript
1601
1575
  * ```js
1602
- * // To disregard a single row or column, remove it from copied dataset using `removeRows`/`removeColumns` method on the object from the first callback argument.
1576
+ * // To disregard a single row, remove it from array using data.splice(i, 1).
1603
1577
  * ...
1604
1578
  * new Handsontable(document.getElementById('example'), {
1605
- * beforeCopy: (clipboardData) => {
1606
- * // clipboardData.getData() -> [[1, 2, 3], [4, 5, 6]]
1607
- * clipboardData.removeRows([0]);
1608
- * clipboardData.removeColumns([0]);
1609
- * // clipboardData.getData() -> [[5, 6]]
1579
+ * beforeCopy: (data, coords) => {
1580
+ * // data -> [[1, 2, 3], [4, 5, 6]]
1581
+ * data.splice(0, 1);
1582
+ * // data -> [[4, 5, 6]]
1583
+ * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
1610
1584
  * }
1611
1585
  * });
1612
1586
  * ...
@@ -1614,7 +1588,7 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1614
1588
  * // To cancel copying, return false from the callback.
1615
1589
  * ...
1616
1590
  * new Handsontable(document.getElementById('example'), {
1617
- * beforeCopy: (clipboardData) => {
1591
+ * beforeCopy: (data, coords) => {
1618
1592
  * return false;
1619
1593
  * }
1620
1594
  * });
@@ -1624,14 +1598,14 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1624
1598
  *
1625
1599
  * ::: only-for react
1626
1600
  * ```jsx
1627
- * // To disregard a single row or column, remove it from copied dataset using `removeRows`/`removeColumns` method on the object from the first callback argument.
1601
+ * // To disregard a single row, remove it from array using data.splice(i, 1).
1628
1602
  * ...
1629
1603
  * <HotTable
1630
- * beforeCopy={(clipboardData) => {
1631
- * // clipboardData.getData() -> [[1, 2, 3], [4, 5, 6]]
1632
- * clipboardData.removeRows([0]);
1633
- * clipboardData.removeColumns([0]);
1634
- * // clipboardData.getData() -> [[5, 6]]
1604
+ * beforeCopy={(data, coords) => {
1605
+ * // data -> [[1, 2, 3], [4, 5, 6]]
1606
+ * data.splice(0, 1);
1607
+ * // data -> [[4, 5, 6]]
1608
+ * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
1635
1609
  * }}
1636
1610
  * />
1637
1611
  * ...
@@ -1639,7 +1613,7 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1639
1613
  * // To cancel copying, return false from the callback.
1640
1614
  * ...
1641
1615
  * <HotTable
1642
- * beforeCopy={(clipboardData) => {
1616
+ * beforeCopy={(data, coords) => {
1643
1617
  * return false;
1644
1618
  * }}
1645
1619
  * />
@@ -1652,55 +1626,37 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1652
1626
  * Fired by {@link CopyPaste} plugin after data are pasted into table. This hook is fired when {@link Options#copyPaste}
1653
1627
  * option is enabled.
1654
1628
  *
1655
- * Note: Please keep in mind since @14.0.0 the method arguments has been changed.
1656
- *
1657
1629
  * @event Hooks#afterCopy
1658
- * @param {object} clipboardData Information about already performed copy action.
1659
- * @param {Function} clipboardData.removeRow Remove row from the copied dataset.
1660
- * @param {Function} clipboardData.removeColumn Remove column from the copied dataset.
1661
- * @param {Function} clipboardData.insertAtRow Insert values at row index.
1662
- * @param {Function} clipboardData.insertAtColumn Insert values at column index.
1663
- * @param {Function} clipboardData.setCellAt Change headers or cells in the copied dataset.
1664
- * @param {Function} clipboardData.getCellAt Get headers or cells from the copied dataset.
1665
- * @param {Function} clipboardData.getData Gets copied data stored as array of arrays.
1666
- * @param {Function} clipboardData.getMetaInfo Gets meta information for the copied data.
1667
- * @param {Function} clipboardData.getRanges Returns ranges related to copied part of Handsontable.
1630
+ * @param {Array[]} data An array of arrays which contains the copied data.
1631
+ * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
1632
+ * which was copied.
1633
+ * @param {{ columnHeadersCount: number }} copiedHeadersCount (Since 12.3.0) The number of copied column headers.
1668
1634
  */
1669
1635
  'afterCopy',
1670
1636
  /**
1671
1637
  * Fired by {@link CopyPaste} plugin before values are pasted into table. This hook is fired when
1672
1638
  * {@link Options#copyPaste} option is enabled.
1673
1639
  *
1674
- * Note: Please keep in mind since @14.0.0 the method arguments has been changed.
1675
- *
1676
1640
  * @event Hooks#beforePaste
1677
- * @param {object} clipboardData Information about paste action which is going to happen.
1678
- * @param {Function} clipboardData.removeRow Remove row from the pasted dataset.
1679
- * @param {Function} clipboardData.removeColumn Remove column from the pasted dataset.
1680
- * @param {Function} clipboardData.insertAtRow Insert values at row index.
1681
- * @param {Function} clipboardData.insertAtColumn Insert values at column index.
1682
- * @param {Function} clipboardData.setCellAt Change headers or cells in the pasted dataset.
1683
- * @param {Function} clipboardData.getCellAt Get headers or cells from the pasted dataset.
1684
- * @param {Function} clipboardData.getData Gets copied data stored as array of arrays.
1685
- * @param {Function} clipboardData.getMetaInfo Gets meta information for the copied data.
1686
- * @param {Function} clipboardData.getSource Gets information about source of the copied data
1687
- * (Handsontable, table or string).
1641
+ * @param {Array[]} data An array of arrays which contains data to paste.
1642
+ * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
1643
+ * that correspond to the previously selected area.
1688
1644
  * @returns {*} If returns `false` then pasting is canceled.
1689
1645
  * @example
1690
1646
  * ```js
1691
1647
  * ::: only-for javascript
1692
- * // To disregard a single row or column, remove it from copied dataset using `removeRows`/`removeColumns` method on the object from the first callback argument.
1648
+ * // To disregard a single row, remove it from array using data.splice(i, 1).
1693
1649
  * new Handsontable(example, {
1694
- * beforePaste: (clipboardData) => {
1695
- * // clipboardData.getData() -> [[1, 2, 3], [4, 5, 6]]
1696
- * clipboardData.removeRows([0]);
1697
- * clipboardData.removeColumns([0]);
1698
- * // clipboardData.getData() -> [[5, 6]]
1650
+ * beforePaste: (data, coords) => {
1651
+ * // data -> [[1, 2, 3], [4, 5, 6]]
1652
+ * data.splice(0, 1);
1653
+ * // data -> [[4, 5, 6]]
1654
+ * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
1699
1655
  * }
1700
1656
  * });
1701
1657
  * // To cancel pasting, return false from the callback.
1702
1658
  * new Handsontable(example, {
1703
- * beforePaste: (clipboardData) => {
1659
+ * beforePaste: (data, coords) => {
1704
1660
  * return false;
1705
1661
  * }
1706
1662
  * });
@@ -1709,18 +1665,18 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1709
1665
  *
1710
1666
  * ::: only-for react
1711
1667
  * ```jsx
1712
- * // To disregard a single row or column, remove it from copied dataset using `removeRows`/`removeColumns` method on the object from the first callback argument.
1668
+ * // To disregard a single row, remove it from array using data.splice(i, 1).
1713
1669
  * <HotTable
1714
- * beforePaste={(clipboardData) => {
1715
- * // clipboardData.getData() -> [[1, 2, 3], [4, 5, 6]]
1716
- * clipboardData.removeRows([0]);
1717
- * clipboardData.removeColumns([0]);
1718
- * // clipboardData.getData() -> [[5, 6]]
1670
+ * beforePaste={(data, coords) => {
1671
+ * // data -> [[1, 2, 3], [4, 5, 6]]
1672
+ * data.splice(0, 1);
1673
+ * // data -> [[4, 5, 6]]
1674
+ * // coords -> [{startRow: 0, startCol: 0, endRow: 1, endCol: 2}]
1719
1675
  * }}
1720
1676
  * />
1721
1677
  * // To cancel pasting, return false from the callback.
1722
1678
  * <HotTable
1723
- * beforePaste={(clipboardData) => {
1679
+ * beforePaste={(data, coords) => {
1724
1680
  * return false;
1725
1681
  * }}
1726
1682
  * />
@@ -1732,20 +1688,10 @@ const REGISTERED_HOOKS = [/* eslint-disable jsdoc/require-description-complete-s
1732
1688
  * Fired by {@link CopyPaste} plugin after values are pasted into table. This hook is fired when
1733
1689
  * {@link Options#copyPaste} option is enabled.
1734
1690
  *
1735
- * Note: Please keep in mind since @14.0.0 the method arguments has been changed.
1736
- *
1737
1691
  * @event Hooks#afterPaste
1738
- * @param {object} clipboardData Information about already performed paste action.
1739
- * @param {Function} clipboardData.removeRow Remove row from the pasted dataset.
1740
- * @param {Function} clipboardData.removeColumn Remove column from the pasted dataset.
1741
- * @param {Function} clipboardData.insertAtRow Insert values at row index.
1742
- * @param {Function} clipboardData.insertAtColumn Insert values at column index.
1743
- * @param {Function} clipboardData.setCellAt Change headers or cells in the pasted dataset.
1744
- * @param {Function} clipboardData.getCellAt Get headers or cells from the pasted dataset.
1745
- * @param {Function} clipboardData.getData Gets copied data stored as array of arrays.
1746
- * @param {Function} clipboardData.getMetaInfo Gets meta information for the copied data.
1747
- * @param {Function} clipboardData.getSource Gets information about source of the copied data
1748
- * (Handsontable, table or string).
1692
+ * @param {Array[]} data An array of arrays with the pasted data.
1693
+ * @param {object[]} coords An array of objects with ranges of the visual indexes (`startRow`, `startCol`, `endRow`, `endCol`)
1694
+ * that correspond to the previously selected area.
1749
1695
  */
1750
1696
  'afterPaste',
1751
1697
  /**
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ /**
5
+ * @private
6
+ */
7
+ class ClipboardData {
8
+ constructor() {
9
+ this.data = {};
10
+ }
11
+ setData(type, value) {
12
+ this.data[type] = value;
13
+ }
14
+ getData(type) {
15
+ return this.data[type] || void 0;
16
+ }
17
+ }
18
+ exports.default = ClipboardData;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @private
3
+ */
4
+ export default class ClipboardData {
5
+ constructor() {
6
+ this.data = {};
7
+ }
8
+ setData(type, value) {
9
+ this.data[type] = value;
10
+ }
11
+ getData(type) {
12
+ return this.data[type] || void 0;
13
+ }
14
+ }
@@ -6,6 +6,7 @@ require("core-js/modules/es.error.cause.js");
6
6
  var _base = require("../base");
7
7
  var _pluginHooks = _interopRequireDefault(require("../../pluginHooks"));
8
8
  var _SheetClip = require("../../3rdparty/SheetClip");
9
+ var _array = require("../../helpers/array");
9
10
  var _string = require("../../helpers/string");
10
11
  var _element = require("../../helpers/dom/element");
11
12
  var _browser = require("../../helpers/browser");
@@ -14,10 +15,10 @@ var _copyColumnHeadersOnly = _interopRequireDefault(require("./contextMenuItem/c
14
15
  var _copyWithColumnGroupHeaders = _interopRequireDefault(require("./contextMenuItem/copyWithColumnGroupHeaders"));
15
16
  var _copyWithColumnHeaders = _interopRequireDefault(require("./contextMenuItem/copyWithColumnHeaders"));
16
17
  var _cut = _interopRequireDefault(require("./contextMenuItem/cut"));
18
+ var _pasteEvent = _interopRequireDefault(require("./pasteEvent"));
17
19
  var _copyableRanges = require("./copyableRanges");
18
20
  var _parseTable = require("../../utils/parseTable");
19
21
  var _eventManager = _interopRequireDefault(require("../../eventManager"));
20
- var _clipboardData = require("./clipboardData");
21
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
23
24
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
@@ -42,6 +43,7 @@ _pluginHooks.default.getSingleton().register('afterCopy');
42
43
  const PLUGIN_KEY = exports.PLUGIN_KEY = 'copyPaste';
43
44
  const PLUGIN_PRIORITY = exports.PLUGIN_PRIORITY = 80;
44
45
  const SETTING_KEYS = ['fragmentSelection'];
46
+ const META_HEAD = ['<meta name="generator" content="Handsontable"/>', '<style type="text/css">td{white-space:normal}br{mso-data-placement:same-cell}</style>'].join('');
45
47
 
46
48
  /* eslint-disable jsdoc/require-description-complete-sentence */
47
49
  /**
@@ -86,6 +88,7 @@ var _isTriggeredByCopy = /*#__PURE__*/new WeakMap();
86
88
  var _isTriggeredByCut = /*#__PURE__*/new WeakMap();
87
89
  var _copyableRangesFactory = /*#__PURE__*/new WeakMap();
88
90
  var _ensureClipboardEventsGetTriggered = /*#__PURE__*/new WeakSet();
91
+ var _countCopiedHeaders = /*#__PURE__*/new WeakSet();
89
92
  var _addContentEditableToHighlightedCell = /*#__PURE__*/new WeakSet();
90
93
  var _removeContentEditableFromHighlightedCell = /*#__PURE__*/new WeakSet();
91
94
  class CopyPaste extends _base.BasePlugin {
@@ -99,6 +102,15 @@ class CopyPaste extends _base.BasePlugin {
99
102
  * Add the `contenteditable` attribute to the highlighted cell and select its content.
100
103
  */
101
104
  _classPrivateMethodInitSpec(this, _addContentEditableToHighlightedCell);
105
+ /**
106
+ * Counts how many column headers will be copied based on the passed range.
107
+ *
108
+ * @private
109
+ * @param {Array<{startRow: number, startCol: number, endRow: number, endCol: number}>} ranges Array of objects with properties `startRow`, `startCol`, `endRow` and `endCol`.
110
+ * @returns {{ columnHeadersCount: number }} Returns an object with keys that holds
111
+ * information with the number of copied headers.
112
+ */
113
+ _classPrivateMethodInitSpec(this, _countCopiedHeaders);
102
114
  /**
103
115
  * Ensure that the `copy`/`cut` events get triggered properly in Safari.
104
116
  *
@@ -383,14 +395,26 @@ class CopyPaste extends _base.BasePlugin {
383
395
  * @returns {Array[]} An array of arrays that will be copied to the clipboard.
384
396
  */
385
397
  getRangedData(ranges) {
398
+ const data = [];
386
399
  const {
387
400
  rows,
388
401
  columns
389
402
  } = (0, _copyableRanges.normalizeRanges)(ranges);
390
- return (0, _parseTable.getDataByCoords)(this.hot, {
391
- rows,
392
- columns
403
+
404
+ // concatenate all rows and columns data defined in ranges into one copyable string
405
+ (0, _array.arrayEach)(rows, row => {
406
+ const rowSet = [];
407
+ (0, _array.arrayEach)(columns, column => {
408
+ if (row < 0) {
409
+ // `row` as the second argument acts here as the `headerLevel` argument
410
+ rowSet.push(this.hot.getColHeader(column, row));
411
+ } else {
412
+ rowSet.push(this.hot.getCopyableData(row, column));
413
+ }
414
+ });
415
+ data.push(rowSet);
393
416
  });
417
+ return data;
394
418
  }
395
419
 
396
420
  /**
@@ -407,17 +431,7 @@ class CopyPaste extends _base.BasePlugin {
407
431
  if (!pastableText && !pastableHtml) {
408
432
  return;
409
433
  }
410
- const pasteData = {
411
- clipboardData: {
412
- data: {},
413
- setData(type, value) {
414
- this.data[type] = value;
415
- },
416
- getData(type) {
417
- return this.data[type];
418
- }
419
- }
420
- };
434
+ const pasteData = new _pasteEvent.default();
421
435
  if (pastableText) {
422
436
  pasteData.clipboardData.setData('text/plain', pastableText);
423
437
  }
@@ -556,7 +570,7 @@ class CopyPaste extends _base.BasePlugin {
556
570
  /**
557
571
  * `copy` event callback on textarea element.
558
572
  *
559
- * @param {ClipboardEvent} event ClipboardEvent.
573
+ * @param {Event} event ClipboardEvent.
560
574
  * @private
561
575
  */
562
576
  onCopy(event) {
@@ -565,12 +579,19 @@ class CopyPaste extends _base.BasePlugin {
565
579
  }
566
580
  this.setCopyableText();
567
581
  _classPrivateFieldSet(this, _isTriggeredByCopy, false);
568
- const copyClipboardData = new _clipboardData.CopyClipboardData(this.hot, this.copyableRanges);
569
- const allowCopying = !!this.hot.runHooks('beforeCopy', copyClipboardData);
582
+ const data = this.getRangedData(this.copyableRanges);
583
+ const copiedHeadersCount = _classPrivateMethodGet(this, _countCopiedHeaders, _countCopiedHeaders2).call(this, this.copyableRanges);
584
+ const allowCopying = !!this.hot.runHooks('beforeCopy', data, this.copyableRanges, copiedHeadersCount);
570
585
  if (allowCopying) {
571
- event.clipboardData.setData('text/plain', (0, _SheetClip.stringify)(copyClipboardData.getData()));
572
- event.clipboardData.setData('text/html', [copyClipboardData.getType() === 'handsontable' ? _clipboardData.META_HEAD : '', (0, _parseTable.getHTMLFromConfig)(copyClipboardData.getMetaInfo())].join(''));
573
- this.hot.runHooks('afterCopy', copyClipboardData);
586
+ const textPlain = (0, _SheetClip.stringify)(data);
587
+ if (event && event.clipboardData) {
588
+ const textHTML = (0, _parseTable._dataToHTML)(data, this.hot.rootDocument);
589
+ event.clipboardData.setData('text/plain', textPlain);
590
+ event.clipboardData.setData('text/html', [META_HEAD, textHTML].join(''));
591
+ } else if (typeof ClipboardEvent === 'undefined') {
592
+ this.hot.rootWindow.clipboardData.setData('Text', textPlain);
593
+ }
594
+ this.hot.runHooks('afterCopy', data, this.copyableRanges, copiedHeadersCount);
574
595
  }
575
596
  _classPrivateFieldSet(this, _copyMode, 'cells-only');
576
597
  event.preventDefault();
@@ -579,7 +600,7 @@ class CopyPaste extends _base.BasePlugin {
579
600
  /**
580
601
  * `cut` event callback on textarea element.
581
602
  *
582
- * @param {ClipboardEvent} event ClipboardEvent.
603
+ * @param {Event} event ClipboardEvent.
583
604
  * @private
584
605
  */
585
606
  onCut(event) {
@@ -588,13 +609,19 @@ class CopyPaste extends _base.BasePlugin {
588
609
  }
589
610
  this.setCopyableText();
590
611
  _classPrivateFieldSet(this, _isTriggeredByCut, false);
591
- const copyClipboardData = new _clipboardData.CopyClipboardData(this.hot, this.copyableRanges);
592
- const allowCuttingOut = !!this.hot.runHooks('beforeCut', copyClipboardData);
612
+ const rangedData = this.getRangedData(this.copyableRanges);
613
+ const allowCuttingOut = !!this.hot.runHooks('beforeCut', rangedData, this.copyableRanges);
593
614
  if (allowCuttingOut) {
594
- event.clipboardData.setData('text/plain', (0, _SheetClip.stringify)(copyClipboardData.getData()));
595
- event.clipboardData.setData('text/html', [copyClipboardData.getType() === 'handsontable' ? _clipboardData.META_HEAD : '', (0, _parseTable.getHTMLFromConfig)(copyClipboardData.getMetaInfo())].join(''));
615
+ const textPlain = (0, _SheetClip.stringify)(rangedData);
616
+ if (event && event.clipboardData) {
617
+ const textHTML = (0, _parseTable._dataToHTML)(rangedData, this.hot.rootDocument);
618
+ event.clipboardData.setData('text/plain', textPlain);
619
+ event.clipboardData.setData('text/html', [META_HEAD, textHTML].join(''));
620
+ } else if (typeof ClipboardEvent === 'undefined') {
621
+ this.hot.rootWindow.clipboardData.setData('Text', textPlain);
622
+ }
596
623
  this.hot.emptySelectedCells('CopyPaste.cut');
597
- this.hot.runHooks('afterCut', copyClipboardData);
624
+ this.hot.runHooks('afterCut', rangedData, this.copyableRanges);
598
625
  }
599
626
  event.preventDefault();
600
627
  }
@@ -612,22 +639,34 @@ class CopyPaste extends _base.BasePlugin {
612
639
  if (event && event.preventDefault) {
613
640
  event.preventDefault();
614
641
  }
615
- const html = (0, _string.sanitize)(event.clipboardData.getData('text/html'), {
616
- ADD_TAGS: ['meta'],
617
- ADD_ATTR: ['content'],
618
- FORCE_BODY: true
619
- });
620
- const pasteClipboardData = new _clipboardData.PasteClipboardData(event.clipboardData.getData('text/plain'), html);
621
- if (this.hot.runHooks('beforePaste', pasteClipboardData) === false) {
642
+ let pastedData;
643
+ if (event && typeof event.clipboardData !== 'undefined') {
644
+ const textHTML = (0, _string.sanitize)(event.clipboardData.getData('text/html'), {
645
+ ADD_TAGS: ['meta'],
646
+ ADD_ATTR: ['content'],
647
+ FORCE_BODY: true
648
+ });
649
+ if (textHTML && /(<table)|(<TABLE)/g.test(textHTML)) {
650
+ const parsedConfig = (0, _parseTable.htmlToGridSettings)(textHTML, this.hot.rootDocument);
651
+ pastedData = parsedConfig.data;
652
+ } else {
653
+ pastedData = event.clipboardData.getData('text/plain');
654
+ }
655
+ } else if (typeof ClipboardEvent === 'undefined' && typeof this.hot.rootWindow.clipboardData !== 'undefined') {
656
+ pastedData = this.hot.rootWindow.clipboardData.getData('Text');
657
+ }
658
+ if (typeof pastedData === 'string') {
659
+ pastedData = (0, _SheetClip.parse)(pastedData);
660
+ }
661
+ if (pastedData === void 0 || pastedData && pastedData.length === 0) {
622
662
  return;
623
663
  }
624
- const pastedTable = pasteClipboardData.getData();
625
- if (pastedTable.length === 0) {
664
+ if (this.hot.runHooks('beforePaste', pastedData, this.copyableRanges) === false) {
626
665
  return;
627
666
  }
628
- const [startRow, startColumn, endRow, endColumn] = this.populateValues(pastedTable);
667
+ const [startRow, startColumn, endRow, endColumn] = this.populateValues(pastedData);
629
668
  this.hot.selectCell(startRow, startColumn, Math.min(this.hot.countRows() - 1, endRow), Math.min(this.hot.countCols() - 1, endColumn));
630
- this.hot.runHooks('afterPaste', pasteClipboardData);
669
+ this.hot.runHooks('afterPaste', pastedData, this.copyableRanges);
631
670
  }
632
671
 
633
672
  /**
@@ -724,6 +763,21 @@ function _ensureClipboardEventsGetTriggered2(eventName) {
724
763
  this.hot.rootDocument.execCommand(eventName);
725
764
  }
726
765
  }
766
+ function _countCopiedHeaders2(ranges) {
767
+ const {
768
+ rows
769
+ } = (0, _copyableRanges.normalizeRanges)(ranges);
770
+ let columnHeadersCount = 0;
771
+ for (let row = 0; row < rows.length; row++) {
772
+ if (rows[row] >= 0) {
773
+ break;
774
+ }
775
+ columnHeadersCount += 1;
776
+ }
777
+ return {
778
+ columnHeadersCount
779
+ };
780
+ }
727
781
  function _addContentEditableToHighlightedCell2() {
728
782
  if (this.hot.isListening()) {
729
783
  const lastSelectedRange = this.hot.getSelectedRangeLast();