@handsontable/react 0.0.0-next-9588d38-20240209 → 0.0.0-next-0f2b3cd-20240214

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.
@@ -310,23 +310,27 @@ function getExtendedEditorElement(children, editorCache) {
310
310
  * @param {React.ReactElement} rElement React element to be used as a base for the component.
311
311
  * @param {Object} props Props to be passed to the cloned element.
312
312
  * @param {Document} [ownerDocument] The owner document to set the portal up into.
313
+ * @param {String} portalKey The key to be used for the portal.
314
+ * @param {HTMLElement} [cachedContainer] The cached container to be used for the portal.
313
315
  * @returns {{portal: React.ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its container.
314
316
  */
315
317
  function createPortal(rElement, props) {
316
318
  var ownerDocument = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document;
319
+ var portalKey = arguments.length > 3 ? arguments[3] : undefined;
320
+ var cachedContainer = arguments.length > 4 ? arguments[4] : undefined;
317
321
  if (!ownerDocument) {
318
322
  ownerDocument = document;
319
323
  }
320
324
  if (!bulkComponentContainer) {
321
325
  bulkComponentContainer = ownerDocument.createDocumentFragment();
322
326
  }
323
- var portalContainer = ownerDocument.createElement('DIV');
327
+ var portalContainer = cachedContainer !== null && cachedContainer !== void 0 ? cachedContainer : ownerDocument.createElement('DIV');
324
328
  bulkComponentContainer.appendChild(portalContainer);
325
329
  var extendedRendererElement = React__default["default"].cloneElement(rElement, _objectSpread2({
326
330
  key: "".concat(props.row, "-").concat(props.col)
327
331
  }, props));
328
332
  return {
329
- portal: ReactDOM__default["default"].createPortal(extendedRendererElement, portalContainer, "".concat(props.row, "-").concat(props.col, "-").concat(Math.random())),
333
+ portal: ReactDOM__default["default"].createPortal(extendedRendererElement, portalContainer, portalKey),
330
334
  portalContainer: portalContainer
331
335
  };
332
336
  }
@@ -511,7 +515,7 @@ var RenderersPortalManager = /*#__PURE__*/function (_React$Component) {
511
515
  return RenderersPortalManager;
512
516
  }(React__default["default"].Component);
513
517
 
514
- var version="0.0.0-next-9588d38-20240209";
518
+ var version="0.0.0-next-0f2b3cd-20240214";
515
519
 
516
520
  function createCommonjsModule(fn, module) {
517
521
  return module = { exports: {} }, fn(module, module.exports), module.exports;
@@ -1692,9 +1696,17 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1692
1696
  */
1693
1697
  _this.renderersPortalManager = null;
1694
1698
  /**
1695
- * Array containing the portals cashed to be rendered in bulk after Handsontable's render cycle.
1699
+ * Map that stores React portals.
1700
+ * @type {Map<string, React.ReactPortal>}
1696
1701
  */
1697
- _this.portalCacheArray = [];
1702
+ _this.portalCache = new Map();
1703
+ /**
1704
+ * Portal Container Cache
1705
+ *
1706
+ * @private
1707
+ * @type {Map}
1708
+ */
1709
+ _this.portalContainerCache = new Map();
1698
1710
  /**
1699
1711
  * The rendered cells cache.
1700
1712
  *
@@ -1746,6 +1758,16 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1746
1758
  set: function set(hotInstance) {
1747
1759
  this.__hotInstance = hotInstance;
1748
1760
  }
1761
+ /**
1762
+ * Get Portal Container Cache
1763
+ *
1764
+ * @returns {Map}
1765
+ */
1766
+ }, {
1767
+ key: "getPortalContainerCache",
1768
+ value: function getPortalContainerCache() {
1769
+ return this.portalContainerCache;
1770
+ }
1749
1771
  /**
1750
1772
  * Get the rendered table cell cache.
1751
1773
  *
@@ -1810,28 +1832,42 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1810
1832
  var hotTableComponent = this;
1811
1833
  return function (instance, TD, row, col, prop, value, cellProperties) {
1812
1834
  var renderedCellCache = hotTableComponent.getRenderedCellCache();
1813
- if (renderedCellCache.has("".concat(row, "-").concat(col))) {
1814
- TD.innerHTML = renderedCellCache.get("".concat(row, "-").concat(col)).innerHTML;
1835
+ var portalContainerCache = hotTableComponent.getPortalContainerCache();
1836
+ var key = "".concat(row, "-").concat(col);
1837
+ // Handsontable.Core type is missing guid
1838
+ var instanceGuid = instance.guid;
1839
+ var portalContainerKey = "".concat(instanceGuid, "-").concat(key);
1840
+ var portalKey = "".concat(key, "-").concat(instanceGuid);
1841
+ if (renderedCellCache.has(key)) {
1842
+ TD.innerHTML = renderedCellCache.get(key).innerHTML;
1815
1843
  }
1816
1844
  if (TD && !TD.getAttribute('ghost-table')) {
1817
- var _createPortal = createPortal(rendererElement, {
1818
- TD: TD,
1819
- row: row,
1820
- col: col,
1821
- prop: prop,
1822
- value: value,
1823
- cellProperties: cellProperties,
1824
- isRenderer: true
1825
- }, TD.ownerDocument),
1826
- portal = _createPortal.portal,
1827
- portalContainer = _createPortal.portalContainer;
1845
+ var cachedPortal = hotTableComponent.portalCache.get(portalKey);
1846
+ var cachedPortalContainer = portalContainerCache.get(portalContainerKey);
1828
1847
  while (TD.firstChild) {
1829
1848
  TD.removeChild(TD.firstChild);
1830
1849
  }
1831
- TD.appendChild(portalContainer);
1832
- hotTableComponent.portalCacheArray.push(portal);
1850
+ // if portal already exists, do not recreate
1851
+ if (cachedPortal && cachedPortalContainer) {
1852
+ TD.appendChild(cachedPortalContainer);
1853
+ } else {
1854
+ var _createPortal = createPortal(rendererElement, {
1855
+ TD: TD,
1856
+ row: row,
1857
+ col: col,
1858
+ prop: prop,
1859
+ value: value,
1860
+ cellProperties: cellProperties,
1861
+ isRenderer: true
1862
+ }, TD.ownerDocument, portalKey, cachedPortalContainer),
1863
+ portal = _createPortal.portal,
1864
+ portalContainer = _createPortal.portalContainer;
1865
+ portalContainerCache.set(portalContainerKey, portalContainer);
1866
+ TD.appendChild(portalContainer);
1867
+ hotTableComponent.portalCache.set(portalKey, portal);
1868
+ }
1833
1869
  }
1834
- renderedCellCache.set("".concat(row, "-").concat(col), TD);
1870
+ renderedCellCache.set(key, TD);
1835
1871
  return TD;
1836
1872
  };
1837
1873
  }
@@ -1982,6 +2018,7 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1982
2018
  }, {
1983
2019
  key: "handsontableBeforeViewRender",
1984
2020
  value: function handsontableBeforeViewRender() {
2021
+ this.portalCache.clear();
1985
2022
  this.getRenderedCellCache().clear();
1986
2023
  }
1987
2024
  /**
@@ -1990,11 +2027,8 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1990
2027
  }, {
1991
2028
  key: "handsontableAfterViewRender",
1992
2029
  value: function handsontableAfterViewRender() {
1993
- var _this3 = this;
1994
2030
  this.renderersPortalManager.setState({
1995
- portals: _toConsumableArray(this.portalCacheArray)
1996
- }, function () {
1997
- _this3.portalCacheArray = [];
2031
+ portals: _toConsumableArray(this.portalCache.values())
1998
2032
  });
1999
2033
  }
2000
2034
  /**
@@ -2030,14 +2064,14 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
2030
2064
  }, {
2031
2065
  key: "componentDidMount",
2032
2066
  value: function componentDidMount() {
2033
- var _this4 = this;
2067
+ var _this3 = this;
2034
2068
  var newGlobalSettings = this.createNewGlobalSettings();
2035
2069
  this.hotInstance = new Handsontable__default["default"].Core(this.hotElementRef, newGlobalSettings);
2036
2070
  this.hotInstance.addHook('beforeViewRender', function () {
2037
- return _this4.handsontableBeforeViewRender();
2071
+ return _this3.handsontableBeforeViewRender();
2038
2072
  });
2039
2073
  this.hotInstance.addHook('afterViewRender', function () {
2040
- return _this4.handsontableAfterViewRender();
2074
+ return _this3.handsontableAfterViewRender();
2041
2075
  });
2042
2076
  // `init` missing in Handsontable's type definitions.
2043
2077
  this.hotInstance.init();
@@ -2071,7 +2105,7 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
2071
2105
  }, {
2072
2106
  key: "render",
2073
2107
  value: function render() {
2074
- var _this5 = this;
2108
+ var _this4 = this;
2075
2109
  var isHotColumn = function isHotColumn(childNode) {
2076
2110
  return childNode.type === HotColumn;
2077
2111
  };
@@ -2081,14 +2115,14 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
2081
2115
  return isHotColumn(childNode);
2082
2116
  }).map(function (childNode, columnIndex) {
2083
2117
  return React__default["default"].cloneElement(childNode, {
2084
- _componentRendererColumns: _this5.componentRendererColumns,
2085
- _emitColumnSettings: _this5.setHotColumnSettings.bind(_this5),
2118
+ _componentRendererColumns: _this4.componentRendererColumns,
2119
+ _emitColumnSettings: _this4.setHotColumnSettings.bind(_this4),
2086
2120
  _columnIndex: columnIndex,
2087
- _getChildElementByType: getChildElementByType.bind(_this5),
2088
- _getRendererWrapper: _this5.getRendererWrapper.bind(_this5),
2089
- _getEditorClass: _this5.getEditorClass.bind(_this5),
2090
- _getOwnerDocument: _this5.getOwnerDocument.bind(_this5),
2091
- _getEditorCache: _this5.getEditorCache.bind(_this5),
2121
+ _getChildElementByType: getChildElementByType.bind(_this4),
2122
+ _getRendererWrapper: _this4.getRendererWrapper.bind(_this4),
2123
+ _getEditorClass: _this4.getEditorClass.bind(_this4),
2124
+ _getOwnerDocument: _this4.getOwnerDocument.bind(_this4),
2125
+ _getEditorCache: _this4.getEditorCache.bind(_this4),
2092
2126
  children: childNode.props.children
2093
2127
  });
2094
2128
  });
@@ -25,7 +25,7 @@
25
25
  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING FROM
26
26
  * USE OR INABILITY TO USE THIS SOFTWARE.
27
27
  *
28
- * Version: 0.0.0-next-9588d38-20240209 (built at Fri Feb 09 2024 15:16:15 GMT+0000 (Coordinated Universal Time))
28
+ * Version: 0.0.0-next-0f2b3cd-20240214 (built at Wed Feb 14 2024 14:09:17 GMT+0000 (Coordinated Universal Time))
29
29
  */
30
30
  (function (global, factory) {
31
31
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom'), require('handsontable/base')) :
@@ -337,23 +337,27 @@ function getExtendedEditorElement(children, editorCache) {
337
337
  * @param {React.ReactElement} rElement React element to be used as a base for the component.
338
338
  * @param {Object} props Props to be passed to the cloned element.
339
339
  * @param {Document} [ownerDocument] The owner document to set the portal up into.
340
+ * @param {String} portalKey The key to be used for the portal.
341
+ * @param {HTMLElement} [cachedContainer] The cached container to be used for the portal.
340
342
  * @returns {{portal: React.ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its container.
341
343
  */
342
344
  function createPortal(rElement, props) {
343
345
  var ownerDocument = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document;
346
+ var portalKey = arguments.length > 3 ? arguments[3] : undefined;
347
+ var cachedContainer = arguments.length > 4 ? arguments[4] : undefined;
344
348
  if (!ownerDocument) {
345
349
  ownerDocument = document;
346
350
  }
347
351
  if (!bulkComponentContainer) {
348
352
  bulkComponentContainer = ownerDocument.createDocumentFragment();
349
353
  }
350
- var portalContainer = ownerDocument.createElement('DIV');
354
+ var portalContainer = cachedContainer !== null && cachedContainer !== void 0 ? cachedContainer : ownerDocument.createElement('DIV');
351
355
  bulkComponentContainer.appendChild(portalContainer);
352
356
  var extendedRendererElement = React__default["default"].cloneElement(rElement, _objectSpread2({
353
357
  key: "".concat(props.row, "-").concat(props.col)
354
358
  }, props));
355
359
  return {
356
- portal: ReactDOM__default["default"].createPortal(extendedRendererElement, portalContainer, "".concat(props.row, "-").concat(props.col, "-").concat(Math.random())),
360
+ portal: ReactDOM__default["default"].createPortal(extendedRendererElement, portalContainer, portalKey),
357
361
  portalContainer: portalContainer
358
362
  };
359
363
  }
@@ -538,7 +542,7 @@ var RenderersPortalManager = /*#__PURE__*/function (_React$Component) {
538
542
  return RenderersPortalManager;
539
543
  }(React__default["default"].Component);
540
544
 
541
- var version="0.0.0-next-9588d38-20240209";
545
+ var version="0.0.0-next-0f2b3cd-20240214";
542
546
 
543
547
  function createCommonjsModule(fn, module) {
544
548
  return module = { exports: {} }, fn(module, module.exports), module.exports;
@@ -941,9 +945,17 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
941
945
  */
942
946
  _this.renderersPortalManager = null;
943
947
  /**
944
- * Array containing the portals cashed to be rendered in bulk after Handsontable's render cycle.
948
+ * Map that stores React portals.
949
+ * @type {Map<string, React.ReactPortal>}
945
950
  */
946
- _this.portalCacheArray = [];
951
+ _this.portalCache = new Map();
952
+ /**
953
+ * Portal Container Cache
954
+ *
955
+ * @private
956
+ * @type {Map}
957
+ */
958
+ _this.portalContainerCache = new Map();
947
959
  /**
948
960
  * The rendered cells cache.
949
961
  *
@@ -995,6 +1007,16 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
995
1007
  set: function set(hotInstance) {
996
1008
  this.__hotInstance = hotInstance;
997
1009
  }
1010
+ /**
1011
+ * Get Portal Container Cache
1012
+ *
1013
+ * @returns {Map}
1014
+ */
1015
+ }, {
1016
+ key: "getPortalContainerCache",
1017
+ value: function getPortalContainerCache() {
1018
+ return this.portalContainerCache;
1019
+ }
998
1020
  /**
999
1021
  * Get the rendered table cell cache.
1000
1022
  *
@@ -1059,28 +1081,42 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1059
1081
  var hotTableComponent = this;
1060
1082
  return function (instance, TD, row, col, prop, value, cellProperties) {
1061
1083
  var renderedCellCache = hotTableComponent.getRenderedCellCache();
1062
- if (renderedCellCache.has("".concat(row, "-").concat(col))) {
1063
- TD.innerHTML = renderedCellCache.get("".concat(row, "-").concat(col)).innerHTML;
1084
+ var portalContainerCache = hotTableComponent.getPortalContainerCache();
1085
+ var key = "".concat(row, "-").concat(col);
1086
+ // Handsontable.Core type is missing guid
1087
+ var instanceGuid = instance.guid;
1088
+ var portalContainerKey = "".concat(instanceGuid, "-").concat(key);
1089
+ var portalKey = "".concat(key, "-").concat(instanceGuid);
1090
+ if (renderedCellCache.has(key)) {
1091
+ TD.innerHTML = renderedCellCache.get(key).innerHTML;
1064
1092
  }
1065
1093
  if (TD && !TD.getAttribute('ghost-table')) {
1066
- var _createPortal = createPortal(rendererElement, {
1067
- TD: TD,
1068
- row: row,
1069
- col: col,
1070
- prop: prop,
1071
- value: value,
1072
- cellProperties: cellProperties,
1073
- isRenderer: true
1074
- }, TD.ownerDocument),
1075
- portal = _createPortal.portal,
1076
- portalContainer = _createPortal.portalContainer;
1094
+ var cachedPortal = hotTableComponent.portalCache.get(portalKey);
1095
+ var cachedPortalContainer = portalContainerCache.get(portalContainerKey);
1077
1096
  while (TD.firstChild) {
1078
1097
  TD.removeChild(TD.firstChild);
1079
1098
  }
1080
- TD.appendChild(portalContainer);
1081
- hotTableComponent.portalCacheArray.push(portal);
1099
+ // if portal already exists, do not recreate
1100
+ if (cachedPortal && cachedPortalContainer) {
1101
+ TD.appendChild(cachedPortalContainer);
1102
+ } else {
1103
+ var _createPortal = createPortal(rendererElement, {
1104
+ TD: TD,
1105
+ row: row,
1106
+ col: col,
1107
+ prop: prop,
1108
+ value: value,
1109
+ cellProperties: cellProperties,
1110
+ isRenderer: true
1111
+ }, TD.ownerDocument, portalKey, cachedPortalContainer),
1112
+ portal = _createPortal.portal,
1113
+ portalContainer = _createPortal.portalContainer;
1114
+ portalContainerCache.set(portalContainerKey, portalContainer);
1115
+ TD.appendChild(portalContainer);
1116
+ hotTableComponent.portalCache.set(portalKey, portal);
1117
+ }
1082
1118
  }
1083
- renderedCellCache.set("".concat(row, "-").concat(col), TD);
1119
+ renderedCellCache.set(key, TD);
1084
1120
  return TD;
1085
1121
  };
1086
1122
  }
@@ -1231,6 +1267,7 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1231
1267
  }, {
1232
1268
  key: "handsontableBeforeViewRender",
1233
1269
  value: function handsontableBeforeViewRender() {
1270
+ this.portalCache.clear();
1234
1271
  this.getRenderedCellCache().clear();
1235
1272
  }
1236
1273
  /**
@@ -1239,11 +1276,8 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1239
1276
  }, {
1240
1277
  key: "handsontableAfterViewRender",
1241
1278
  value: function handsontableAfterViewRender() {
1242
- var _this3 = this;
1243
1279
  this.renderersPortalManager.setState({
1244
- portals: _toConsumableArray(this.portalCacheArray)
1245
- }, function () {
1246
- _this3.portalCacheArray = [];
1280
+ portals: _toConsumableArray(this.portalCache.values())
1247
1281
  });
1248
1282
  }
1249
1283
  /**
@@ -1279,14 +1313,14 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1279
1313
  }, {
1280
1314
  key: "componentDidMount",
1281
1315
  value: function componentDidMount() {
1282
- var _this4 = this;
1316
+ var _this3 = this;
1283
1317
  var newGlobalSettings = this.createNewGlobalSettings();
1284
1318
  this.hotInstance = new Handsontable__default["default"].Core(this.hotElementRef, newGlobalSettings);
1285
1319
  this.hotInstance.addHook('beforeViewRender', function () {
1286
- return _this4.handsontableBeforeViewRender();
1320
+ return _this3.handsontableBeforeViewRender();
1287
1321
  });
1288
1322
  this.hotInstance.addHook('afterViewRender', function () {
1289
- return _this4.handsontableAfterViewRender();
1323
+ return _this3.handsontableAfterViewRender();
1290
1324
  });
1291
1325
  // `init` missing in Handsontable's type definitions.
1292
1326
  this.hotInstance.init();
@@ -1320,7 +1354,7 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1320
1354
  }, {
1321
1355
  key: "render",
1322
1356
  value: function render() {
1323
- var _this5 = this;
1357
+ var _this4 = this;
1324
1358
  var isHotColumn = function isHotColumn(childNode) {
1325
1359
  return childNode.type === HotColumn;
1326
1360
  };
@@ -1330,14 +1364,14 @@ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1330
1364
  return isHotColumn(childNode);
1331
1365
  }).map(function (childNode, columnIndex) {
1332
1366
  return React__default["default"].cloneElement(childNode, {
1333
- _componentRendererColumns: _this5.componentRendererColumns,
1334
- _emitColumnSettings: _this5.setHotColumnSettings.bind(_this5),
1367
+ _componentRendererColumns: _this4.componentRendererColumns,
1368
+ _emitColumnSettings: _this4.setHotColumnSettings.bind(_this4),
1335
1369
  _columnIndex: columnIndex,
1336
- _getChildElementByType: getChildElementByType.bind(_this5),
1337
- _getRendererWrapper: _this5.getRendererWrapper.bind(_this5),
1338
- _getEditorClass: _this5.getEditorClass.bind(_this5),
1339
- _getOwnerDocument: _this5.getOwnerDocument.bind(_this5),
1340
- _getEditorCache: _this5.getEditorCache.bind(_this5),
1370
+ _getChildElementByType: getChildElementByType.bind(_this4),
1371
+ _getRendererWrapper: _this4.getRendererWrapper.bind(_this4),
1372
+ _getEditorClass: _this4.getEditorClass.bind(_this4),
1373
+ _getOwnerDocument: _this4.getOwnerDocument.bind(_this4),
1374
+ _getEditorCache: _this4.getEditorCache.bind(_this4),
1341
1375
  children: childNode.props.children
1342
1376
  });
1343
1377
  });