@handsontable/react 0.0.0-next-c812b69-20230413 → 0.0.0-next-f981fa2-20230418

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.
@@ -146,31 +146,6 @@ function _createSuper(Derived) {
146
146
  return _possibleConstructorReturn(this, result);
147
147
  };
148
148
  }
149
- function _toConsumableArray(arr) {
150
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
151
- }
152
- function _arrayWithoutHoles(arr) {
153
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
154
- }
155
- function _iterableToArray(iter) {
156
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
157
- }
158
- function _unsupportedIterableToArray(o, minLen) {
159
- if (!o) return;
160
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
161
- var n = Object.prototype.toString.call(o).slice(8, -1);
162
- if (n === "Object" && o.constructor) n = o.constructor.name;
163
- if (n === "Map" || n === "Set") return Array.from(o);
164
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
165
- }
166
- function _arrayLikeToArray(arr, len) {
167
- if (len == null || len > arr.length) len = arr.length;
168
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
169
- return arr2;
170
- }
171
- function _nonIterableSpread() {
172
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
173
- }
174
149
  function _toPrimitive(input, hint) {
175
150
  if (typeof input !== "object" || input === null) return input;
176
151
  var prim = input[Symbol.toPrimitive];
@@ -371,28 +346,69 @@ var SettingsMapper = /*#__PURE__*/function () {
371
346
  return SettingsMapper;
372
347
  }();
373
348
 
349
+ /**
350
+ * Component class used to manage the editor component portals.
351
+ */
352
+ var EditorsPortalManager = /*#__PURE__*/function (_React$Component) {
353
+ _inherits(EditorsPortalManager, _React$Component);
354
+ var _super = _createSuper(EditorsPortalManager);
355
+ function EditorsPortalManager() {
356
+ var _this;
357
+ _classCallCheck(this, EditorsPortalManager);
358
+ _this = _super.apply(this, arguments);
359
+ _this.state = {
360
+ portals: []
361
+ };
362
+ return _this;
363
+ }
364
+ _createClass(EditorsPortalManager, [{
365
+ key: "render",
366
+ value: function render() {
367
+ return React__default["default"].createElement(React__default["default"].Fragment, null, this.state.portals);
368
+ }
369
+ }]);
370
+ return EditorsPortalManager;
371
+ }(React__default["default"].Component);
372
+
374
373
  var HotColumn = /*#__PURE__*/function (_React$Component) {
375
374
  _inherits(HotColumn, _React$Component);
376
375
  var _super = _createSuper(HotColumn);
377
376
  function HotColumn() {
377
+ var _this;
378
378
  _classCallCheck(this, HotColumn);
379
- return _super.apply(this, arguments);
379
+ _this = _super.apply(this, arguments);
380
+ /**
381
+ * Component used to manage the editor portals.
382
+ *
383
+ * @type {React.Component}
384
+ */
385
+ _this.editorsPortalManager = null;
386
+ return _this;
380
387
  }
388
+ /**
389
+ * Set the editors portal manager ref.
390
+ *
391
+ * @param {React.ReactComponent} pmComponent The PortalManager component.
392
+ */
381
393
  _createClass(HotColumn, [{
382
- key: "getSettingsProps",
383
- value:
394
+ key: "setEditorsPortalManagerRef",
395
+ value: function setEditorsPortalManagerRef(pmComponent) {
396
+ this.editorsPortalManager = pmComponent;
397
+ }
384
398
  /**
385
399
  * Filter out all the internal properties and return an object with just the Handsontable-related props.
386
400
  *
387
401
  * @returns {Object}
388
402
  */
389
- function getSettingsProps() {
390
- var _this = this;
403
+ }, {
404
+ key: "getSettingsProps",
405
+ value: function getSettingsProps() {
406
+ var _this2 = this;
391
407
  this.internalProps = ['_componentRendererColumns', '_emitColumnSettings', '_columnIndex', '_getChildElementByType', '_getRendererWrapper', '_getEditorClass', '_getEditorCache', '_getOwnerDocument', 'hot-renderer', 'hot-editor', 'children'];
392
408
  return Object.keys(this.props).filter(function (key) {
393
- return !_this.internalProps.includes(key);
409
+ return !_this2.internalProps.includes(key);
394
410
  }).reduce(function (obj, key) {
395
- obj[key] = _this.props[key];
411
+ obj[key] = _this2.props[key];
396
412
  return obj;
397
413
  }, {});
398
414
  }
@@ -423,6 +439,21 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
423
439
  this.columnSettings.editor = this.props._getEditorClass(editorElement, this.props._columnIndex);
424
440
  }
425
441
  }
442
+ /**
443
+ * Creates the local editor portal and renders it within the editors portal manager component.
444
+ *
445
+ * @param {Function} callback Callback to call which is triggered after the editors portal is rendered.
446
+ */
447
+ }, {
448
+ key: "renderLocalEditorPortal",
449
+ value: function renderLocalEditorPortal(callback) {
450
+ var editorCache = this.props._getEditorCache();
451
+ var localEditorElement = getExtendedEditorElement(this.props.children, editorCache, this.props._columnIndex);
452
+ var editorPortal = createEditorPortal(this.props._getOwnerDocument(), localEditorElement);
453
+ this.editorsPortalManager.setState({
454
+ portals: [editorPortal]
455
+ }, callback);
456
+ }
426
457
  /**
427
458
  * Emit the column settings to the parent using a prop passed from the parent.
428
459
  */
@@ -442,8 +473,11 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
442
473
  }, {
443
474
  key: "componentDidMount",
444
475
  value: function componentDidMount() {
445
- this.createColumnSettings();
446
- this.emitColumnSettings();
476
+ var _this3 = this;
477
+ this.renderLocalEditorPortal(function () {
478
+ _this3.createColumnSettings();
479
+ _this3.emitColumnSettings();
480
+ });
447
481
  }
448
482
  /**
449
483
  * Logic performed after the updating of the HotColumn component.
@@ -451,8 +485,11 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
451
485
  }, {
452
486
  key: "componentDidUpdate",
453
487
  value: function componentDidUpdate() {
454
- this.createColumnSettings();
455
- this.emitColumnSettings();
488
+ var _this4 = this;
489
+ this.renderLocalEditorPortal(function () {
490
+ _this4.createColumnSettings();
491
+ _this4.emitColumnSettings();
492
+ });
456
493
  }
457
494
  /**
458
495
  * Render the portals of the editors, if there are any.
@@ -462,9 +499,9 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
462
499
  }, {
463
500
  key: "render",
464
501
  value: function render() {
465
- var ownerDocument = this.props._getOwnerDocument();
466
- var editorPortal = createEditorPortal(ownerDocument, this.getLocalEditorElement());
467
- return React__default["default"].createElement(React__default["default"].Fragment, null, editorPortal);
502
+ return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(EditorsPortalManager, {
503
+ ref: this.setEditorsPortalManagerRef.bind(this)
504
+ }));
468
505
  }
469
506
  }]);
470
507
  return HotColumn;
@@ -494,7 +531,7 @@ var RenderersPortalManager = /*#__PURE__*/function (_React$Component) {
494
531
  return RenderersPortalManager;
495
532
  }(React__default["default"].Component);
496
533
 
497
- var version="0.0.0-next-c812b69-20230413";
534
+ var version="0.0.0-next-f981fa2-20230418";
498
535
 
499
536
  function createCommonjsModule(fn, module) {
500
537
  return module = { exports: {} }, fn(module, module.exports), module.exports;
@@ -1675,6 +1712,12 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1675
1712
  * @type {React.Component}
1676
1713
  */
1677
1714
  _this.renderersPortalManager = null;
1715
+ /**
1716
+ * Component used to manage the editor portals.
1717
+ *
1718
+ * @type {React.Component}
1719
+ */
1720
+ _this.editorsPortalManager = null;
1678
1721
  /**
1679
1722
  * Array containing the portals cashed to be rendered in bulk after Handsontable's render cycle.
1680
1723
  */
@@ -1756,6 +1799,7 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1756
1799
  }, {
1757
1800
  key: "clearCache",
1758
1801
  value: function clearCache() {
1802
+ this.getEditorCache().clear();
1759
1803
  this.getRenderedCellCache().clear();
1760
1804
  this.componentRendererColumns.clear();
1761
1805
  }
@@ -1907,6 +1951,20 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1907
1951
  value: function getGlobalEditorElement() {
1908
1952
  return getExtendedEditorElement(this.props.children, this.getEditorCache());
1909
1953
  }
1954
+ /**
1955
+ * Creates the global editor portal and renders it within the editors portal manager component.
1956
+ *
1957
+ * @param {Function} callback Callback to call which is triggered after the editors portal is rendered.
1958
+ */
1959
+ }, {
1960
+ key: "renderGlobalEditorPortal",
1961
+ value: function renderGlobalEditorPortal(callback) {
1962
+ var globalEditorElement = this.getGlobalEditorElement();
1963
+ var editorPortal = createEditorPortal(this.getOwnerDocument(), globalEditorElement);
1964
+ this.editorsPortalManager.setState({
1965
+ portals: [editorPortal]
1966
+ }, callback);
1967
+ }
1910
1968
  /**
1911
1969
  * Create a new settings object containing the column settings and global editors and renderers.
1912
1970
  *
@@ -1973,10 +2031,12 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1973
2031
  key: "handsontableAfterViewRender",
1974
2032
  value: function handsontableAfterViewRender() {
1975
2033
  var _this3 = this;
1976
- this.renderersPortalManager.setState({
1977
- portals: _toConsumableArray(this.portalCacheArray)
2034
+ this.renderersPortalManager.setState(function () {
2035
+ return Object.assign({}, {
2036
+ portals: _this3.portalCacheArray
2037
+ });
1978
2038
  }, function () {
1979
- _this3.portalCacheArray = [];
2039
+ _this3.portalCacheArray.length = 0;
1980
2040
  });
1981
2041
  }
1982
2042
  /**
@@ -2001,6 +2061,16 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2001
2061
  value: function setRenderersPortalManagerRef(pmComponent) {
2002
2062
  this.renderersPortalManager = pmComponent;
2003
2063
  }
2064
+ /**
2065
+ * Set the editors portal manager ref.
2066
+ *
2067
+ * @param {React.ReactComponent} pmComponent The PortalManager component.
2068
+ */
2069
+ }, {
2070
+ key: "setEditorsPortalManagerRef",
2071
+ value: function setEditorsPortalManagerRef(pmComponent) {
2072
+ this.editorsPortalManager = pmComponent;
2073
+ }
2004
2074
  /*
2005
2075
  ---------------------------------------
2006
2076
  ------- React lifecycle methods -------
@@ -2013,17 +2083,25 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2013
2083
  key: "componentDidMount",
2014
2084
  value: function componentDidMount() {
2015
2085
  var _this4 = this;
2016
- var newGlobalSettings = this.createNewGlobalSettings();
2017
- this.hotInstance = new Handsontable__default["default"].Core(this.hotElementRef, newGlobalSettings);
2018
- this.hotInstance.addHook('beforeViewRender', function () {
2019
- return _this4.handsontableBeforeViewRender();
2020
- });
2021
- this.hotInstance.addHook('afterViewRender', function () {
2022
- return _this4.handsontableAfterViewRender();
2086
+ this.clearCache();
2087
+ this.renderGlobalEditorPortal(function () {
2088
+ // In React strict mode the mount/unmount is triggered twice. The `if` prevents
2089
+ // creating two Handsontable instances for the same component in that mode.
2090
+ if (_this4.hotInstance) {
2091
+ return;
2092
+ }
2093
+ var newGlobalSettings = _this4.createNewGlobalSettings();
2094
+ _this4.hotInstance = new Handsontable__default["default"].Core(_this4.hotElementRef, newGlobalSettings);
2095
+ _this4.hotInstance.addHook('beforeViewRender', function () {
2096
+ return _this4.handsontableBeforeViewRender();
2097
+ });
2098
+ _this4.hotInstance.addHook('afterViewRender', function () {
2099
+ return _this4.handsontableAfterViewRender();
2100
+ });
2101
+ // `init` missing in Handsontable's type definitions.
2102
+ _this4.hotInstance.init();
2103
+ _this4.displayAutoSizeWarning(newGlobalSettings);
2023
2104
  });
2024
- // `init` missing in Handsontable's type definitions.
2025
- this.hotInstance.init();
2026
- this.displayAutoSizeWarning(newGlobalSettings);
2027
2105
  }
2028
2106
  /**
2029
2107
  * Logic performed after the component update.
@@ -2031,10 +2109,13 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2031
2109
  }, {
2032
2110
  key: "componentDidUpdate",
2033
2111
  value: function componentDidUpdate() {
2112
+ var _this5 = this;
2034
2113
  this.clearCache();
2035
- var newGlobalSettings = this.createNewGlobalSettings();
2036
- this.updateHot(newGlobalSettings);
2037
- this.displayAutoSizeWarning(newGlobalSettings);
2114
+ this.renderGlobalEditorPortal(function () {
2115
+ var newGlobalSettings = _this5.createNewGlobalSettings();
2116
+ _this5.updateHot(newGlobalSettings);
2117
+ _this5.displayAutoSizeWarning(newGlobalSettings);
2118
+ });
2038
2119
  }
2039
2120
  /**
2040
2121
  * Destroy the Handsontable instance when the parent component unmounts.
@@ -2042,7 +2123,6 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2042
2123
  }, {
2043
2124
  key: "componentWillUnmount",
2044
2125
  value: function componentWillUnmount() {
2045
- this.clearCache();
2046
2126
  if (this.hotInstance) {
2047
2127
  this.hotInstance.destroy();
2048
2128
  }
@@ -2053,34 +2133,37 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2053
2133
  }, {
2054
2134
  key: "render",
2055
2135
  value: function render() {
2056
- var _this5 = this;
2136
+ var _this6 = this;
2057
2137
  var containerProps = getContainerAttributesProps(this.props);
2058
2138
  var isHotColumn = function isHotColumn(childNode) {
2059
2139
  return childNode.type === HotColumn;
2060
2140
  };
2061
2141
  var children = React__default["default"].Children.toArray(this.props.children);
2062
- // clone the HotColumn nodes and extend them with the callbacks
2063
- var hotColumnClones = children.filter(function (childNode) {
2142
+ // filter out anything that's not a HotColumn
2143
+ children = children.filter(function (childNode) {
2064
2144
  return isHotColumn(childNode);
2065
- }).map(function (childNode, columnIndex) {
2145
+ });
2146
+ // clone the HotColumn nodes and extend them with the callbacks
2147
+ var childClones = children.map(function (childNode, columnIndex) {
2066
2148
  return React__default["default"].cloneElement(childNode, {
2067
- _componentRendererColumns: _this5.componentRendererColumns,
2068
- _emitColumnSettings: _this5.setHotColumnSettings.bind(_this5),
2149
+ _componentRendererColumns: _this6.componentRendererColumns,
2150
+ _emitColumnSettings: _this6.setHotColumnSettings.bind(_this6),
2069
2151
  _columnIndex: columnIndex,
2070
- _getChildElementByType: getChildElementByType.bind(_this5),
2071
- _getRendererWrapper: _this5.getRendererWrapper.bind(_this5),
2072
- _getEditorClass: _this5.getEditorClass.bind(_this5),
2073
- _getOwnerDocument: _this5.getOwnerDocument.bind(_this5),
2074
- _getEditorCache: _this5.getEditorCache.bind(_this5),
2152
+ _getChildElementByType: getChildElementByType.bind(_this6),
2153
+ _getRendererWrapper: _this6.getRendererWrapper.bind(_this6),
2154
+ _getEditorClass: _this6.getEditorClass.bind(_this6),
2155
+ _getOwnerDocument: _this6.getOwnerDocument.bind(_this6),
2156
+ _getEditorCache: _this6.getEditorCache.bind(_this6),
2075
2157
  children: childNode.props.children
2076
2158
  });
2077
2159
  });
2078
- var editorPortal = createEditorPortal(this.getOwnerDocument(), this.getGlobalEditorElement());
2079
2160
  return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", Object.assign({
2080
2161
  ref: this.setHotElementRef.bind(this)
2081
- }, containerProps), hotColumnClones), React__default["default"].createElement(RenderersPortalManager, {
2162
+ }, containerProps), childClones), React__default["default"].createElement(RenderersPortalManager, {
2082
2163
  ref: this.setRenderersPortalManagerRef.bind(this)
2083
- }), editorPortal);
2164
+ }), React__default["default"].createElement(EditorsPortalManager, {
2165
+ ref: this.setEditorsPortalManagerRef.bind(this)
2166
+ }));
2084
2167
  }
2085
2168
  }], [{
2086
2169
  key: "version",