@handsontable/react 0.0.0-next-95920ca-20230215 → 0.0.0-next-460cf29-20230220

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.
@@ -223,49 +223,6 @@ function getOriginalEditorClass(editorElement) {
223
223
  }
224
224
  return editorElement.type.WrappedComponent ? editorElement.type.WrappedComponent : editorElement.type;
225
225
  }
226
- /**
227
- * Remove editor containers from DOM.
228
- *
229
- * @param {Document} [doc] Document to be used.
230
- * @param {Map} editorCache The editor cache reference.
231
- */
232
- function removeEditorContainers() {
233
- var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
234
- doc.querySelectorAll("[class^=\"".concat(DEFAULT_CLASSNAME, "\"]")).forEach(function (domNode) {
235
- if (domNode.parentNode) {
236
- domNode.parentNode.removeChild(domNode);
237
- }
238
- });
239
- }
240
- /**
241
- * Create an editor portal.
242
- *
243
- * @param {Document} [doc] Document to be used.
244
- * @param {React.ReactElement} editorElement Editor's element.
245
- * @param {Map} editorCache The editor cache reference.
246
- * @returns {React.ReactPortal} The portal for the editor.
247
- */
248
- function createEditorPortal() {
249
- var doc = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
250
- var editorElement = arguments.length > 1 ? arguments[1] : undefined;
251
- if (editorElement === null) {
252
- return;
253
- }
254
- var editorContainer = doc.createElement('DIV');
255
- var _getContainerAttribut = getContainerAttributesProps(editorElement.props, false),
256
- id = _getContainerAttribut.id,
257
- className = _getContainerAttribut.className,
258
- style = _getContainerAttribut.style;
259
- if (id) {
260
- editorContainer.id = id;
261
- }
262
- editorContainer.className = [DEFAULT_CLASSNAME, className].join(' ');
263
- if (style) {
264
- Object.assign(editorContainer.style, style);
265
- }
266
- doc.body.appendChild(editorContainer);
267
- return ReactDOM__default["default"].createPortal(editorElement, editorContainer);
268
- }
269
226
  /**
270
227
  * Get an editor element extended with a instance-emitting method.
271
228
  *
@@ -299,12 +256,11 @@ function getExtendedEditorElement(children, editorCache) {
299
256
  *
300
257
  * @param {React.ReactElement} rElement React element to be used as a base for the component.
301
258
  * @param {Object} props Props to be passed to the cloned element.
302
- * @param {Function} callback Callback to be called after the component has been mounted.
303
259
  * @param {Document} [ownerDocument] The owner document to set the portal up into.
304
260
  * @returns {{portal: React.ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its container.
305
261
  */
306
- function createPortal(rElement, props, callback) {
307
- var ownerDocument = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : document;
262
+ function createPortal(rElement, props) {
263
+ var ownerDocument = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document;
308
264
  if (!ownerDocument) {
309
265
  ownerDocument = document;
310
266
  }
@@ -338,23 +294,6 @@ function getContainerAttributesProps(props) {
338
294
  style: props.style || {}
339
295
  };
340
296
  }
341
- /**
342
- * Add the `UNSAFE_` prefixes to the deprecated lifecycle methods for React >= 16.3.
343
- *
344
- * @param {Object} instance Instance to have the methods renamed.
345
- */
346
- function addUnsafePrefixes(instance) {
347
- var reactSemverArray = React__default["default"].version.split('.').map(function (v) {
348
- return parseInt(v);
349
- });
350
- var shouldPrefix = reactSemverArray[0] >= 16 && reactSemverArray[1] >= 3 || reactSemverArray[0] >= 17;
351
- if (shouldPrefix) {
352
- instance.UNSAFE_componentWillUpdate = instance.componentWillUpdate;
353
- instance.componentWillUpdate = void 0;
354
- instance.UNSAFE_componentWillMount = instance.componentWillMount;
355
- instance.componentWillMount = void 0;
356
- }
357
- }
358
297
 
359
298
  var SettingsMapper = /*#__PURE__*/function () {
360
299
  function SettingsMapper() {
@@ -390,63 +329,41 @@ var SettingsMapper = /*#__PURE__*/function () {
390
329
  return SettingsMapper;
391
330
  }();
392
331
 
332
+ /**
333
+ * Component provides an editor container for custom editors.
334
+ */
335
+ function EditorHolder(_ref) {
336
+ var editorElement = _ref.editorElement;
337
+ if (editorElement === null) {
338
+ return null;
339
+ }
340
+ var containerProps = getContainerAttributesProps(editorElement.props, false);
341
+ containerProps.className = [DEFAULT_CLASSNAME, containerProps.className].join(' ');
342
+ return React__default["default"].createElement("div", Object.assign({}, containerProps), editorElement);
343
+ }
344
+
393
345
  var HotColumn = /*#__PURE__*/function (_React$Component) {
394
346
  _inherits(HotColumn, _React$Component);
395
347
  var _super = _createSuper(HotColumn);
396
- /**
397
- * HotColumn class constructor.
398
- *
399
- * @param {HotColumnProps} props Component props.
400
- * @param {*} [context] Component context.
401
- */
402
- function HotColumn(props, context) {
403
- var _this;
348
+ function HotColumn() {
404
349
  _classCallCheck(this, HotColumn);
405
- _this = _super.call(this, props, context);
406
- /**
407
- * Local editor portal cache.
408
- *
409
- * @private
410
- * @type {ReactPortal}
411
- */
412
- _this.localEditorPortal = null;
413
- addUnsafePrefixes(_assertThisInitialized(_this));
414
- return _this;
350
+ return _super.apply(this, arguments);
415
351
  }
416
- /**
417
- * Get the local editor portal cache property.
418
- *
419
- * @return {ReactPortal} Local editor portal.
420
- */
421
352
  _createClass(HotColumn, [{
422
- key: "getLocalEditorPortal",
423
- value: function getLocalEditorPortal() {
424
- return this.localEditorPortal;
425
- }
426
- /**
427
- * Set the local editor portal cache property.
428
- *
429
- * @param {ReactPortal} portal Local editor portal.
430
- */
431
- }, {
432
- key: "setLocalEditorPortal",
433
- value: function setLocalEditorPortal(portal) {
434
- this.localEditorPortal = portal;
435
- }
353
+ key: "getSettingsProps",
354
+ value:
436
355
  /**
437
356
  * Filter out all the internal properties and return an object with just the Handsontable-related props.
438
357
  *
439
358
  * @returns {Object}
440
359
  */
441
- }, {
442
- key: "getSettingsProps",
443
- value: function getSettingsProps() {
444
- var _this2 = this;
360
+ function getSettingsProps() {
361
+ var _this = this;
445
362
  this.internalProps = ['__componentRendererColumns', '_emitColumnSettings', '_columnIndex', '_getChildElementByType', '_getRendererWrapper', '_getEditorClass', '_getEditorCache', '_getOwnerDocument', 'hot-renderer', 'hot-editor', 'children'];
446
363
  return Object.keys(this.props).filter(function (key) {
447
- return !_this2.internalProps.includes(key);
364
+ return !_this.internalProps.includes(key);
448
365
  }).reduce(function (obj, key) {
449
- obj[key] = _this2.props[key];
366
+ obj[key] = _this.props[key];
450
367
  return obj;
451
368
  }, {});
452
369
  }
@@ -477,21 +394,6 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
477
394
  this.columnSettings.editor = this.props._getEditorClass(editorElement, this.props._columnIndex);
478
395
  }
479
396
  }
480
- /**
481
- * Create the local editor portal and its destination HTML element if needed.
482
- *
483
- * @param {React.ReactNode} [children] Children of the HotTable instance. Defaults to `this.props.children`.
484
- */
485
- }, {
486
- key: "createLocalEditorPortal",
487
- value: function createLocalEditorPortal() {
488
- var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props.children;
489
- var editorCache = this.props._getEditorCache();
490
- var localEditorElement = getExtendedEditorElement(children, editorCache, this.props._columnIndex);
491
- if (localEditorElement) {
492
- this.setLocalEditorPortal(createEditorPortal(this.props._getOwnerDocument(), localEditorElement, editorCache));
493
- }
494
- }
495
397
  /**
496
398
  * Emit the column settings to the parent using a prop passed from the parent.
497
399
  */
@@ -505,14 +407,6 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
505
407
  ------- React lifecycle methods -------
506
408
  ---------------------------------------
507
409
  */
508
- /**
509
- * Logic performed before the mounting of the HotColumn component.
510
- */
511
- }, {
512
- key: "componentWillMount",
513
- value: function componentWillMount() {
514
- this.createLocalEditorPortal();
515
- }
516
410
  /**
517
411
  * Logic performed after the mounting of the HotColumn component.
518
412
  */
@@ -522,14 +416,6 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
522
416
  this.createColumnSettings();
523
417
  this.emitColumnSettings();
524
418
  }
525
- /**
526
- * Logic performed before the updating of the HotColumn component.
527
- */
528
- }, {
529
- key: "componentWillUpdate",
530
- value: function componentWillUpdate(nextProps, nextState, nextContext) {
531
- this.createLocalEditorPortal(nextProps.children);
532
- }
533
419
  /**
534
420
  * Logic performed after the updating of the HotColumn component.
535
421
  */
@@ -547,7 +433,9 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
547
433
  }, {
548
434
  key: "render",
549
435
  value: function render() {
550
- return React__default["default"].createElement(React__default["default"].Fragment, null, this.getLocalEditorPortal());
436
+ return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(EditorHolder, {
437
+ editorElement: this.getLocalEditorElement()
438
+ }));
551
439
  }
552
440
  }]);
553
441
  return HotColumn;
@@ -559,10 +447,10 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
559
447
  var PortalManager = /*#__PURE__*/function (_React$Component) {
560
448
  _inherits(PortalManager, _React$Component);
561
449
  var _super = _createSuper(PortalManager);
562
- function PortalManager(props) {
450
+ function PortalManager() {
563
451
  var _this;
564
452
  _classCallCheck(this, PortalManager);
565
- _this = _super.call(this, props);
453
+ _this = _super.apply(this, arguments);
566
454
  _this.state = {
567
455
  portals: []
568
456
  };
@@ -577,7 +465,7 @@ var PortalManager = /*#__PURE__*/function (_React$Component) {
577
465
  return PortalManager;
578
466
  }(React__default["default"].Component);
579
467
 
580
- var version="0.0.0-next-95920ca-20230215";
468
+ var version="0.0.0-next-460cf29-20230220";
581
469
 
582
470
  function createCommonjsModule(fn, module) {
583
471
  return module = { exports: {} }, fn(module, module.exports), module.exports;
@@ -1723,16 +1611,10 @@ var PropTypes = propTypes;
1723
1611
  var HotTable = /*#__PURE__*/function (_React$Component) {
1724
1612
  _inherits(HotTable, _React$Component);
1725
1613
  var _super = _createSuper(HotTable);
1726
- /**
1727
- * HotTable class constructor.
1728
- *
1729
- * @param {HotTableProps} props Component props.
1730
- * @param {*} [context] Component context.
1731
- */
1732
- function HotTable(props, context) {
1614
+ function HotTable() {
1733
1615
  var _this;
1734
1616
  _classCallCheck(this, HotTable);
1735
- _this = _super.call(this, props, context);
1617
+ _this = _super.apply(this, arguments);
1736
1618
  /**
1737
1619
  * The `id` of the main Handsontable DOM element.
1738
1620
  *
@@ -1768,13 +1650,6 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1768
1650
  * Array containing the portals cashed to be rendered in bulk after Handsontable's render cycle.
1769
1651
  */
1770
1652
  _this.portalCacheArray = [];
1771
- /**
1772
- * Global editor portal cache.
1773
- *
1774
- * @private
1775
- * @type {React.ReactPortal}
1776
- */
1777
- _this.globalEditorPortal = null;
1778
1653
  /**
1779
1654
  * The rendered cells cache.
1780
1655
  *
@@ -1797,7 +1672,6 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1797
1672
  * @type {Map}
1798
1673
  */
1799
1674
  _this.componentRendererColumns = new Map();
1800
- addUnsafePrefixes(_assertThisInitialized(_this));
1801
1675
  return _this;
1802
1676
  }
1803
1677
  /**
@@ -1847,37 +1721,14 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1847
1721
  value: function getEditorCache() {
1848
1722
  return this.editorCache;
1849
1723
  }
1850
- /**
1851
- * Get the global editor portal property.
1852
- *
1853
- * @return {React.ReactPortal} The global editor portal.
1854
- */
1855
- }, {
1856
- key: "getGlobalEditorPortal",
1857
- value: function getGlobalEditorPortal() {
1858
- return this.globalEditorPortal;
1859
- }
1860
- /**
1861
- * Set the private editor portal cache property.
1862
- *
1863
- * @param {React.ReactPortal} portal Global editor portal.
1864
- */
1865
- }, {
1866
- key: "setGlobalEditorPortal",
1867
- value: function setGlobalEditorPortal(portal) {
1868
- this.globalEditorPortal = portal;
1869
- }
1870
1724
  /**
1871
1725
  * Clear both the editor and the renderer cache.
1872
1726
  */
1873
1727
  }, {
1874
1728
  key: "clearCache",
1875
1729
  value: function clearCache() {
1876
- var renderedCellCache = this.getRenderedCellCache();
1877
- this.setGlobalEditorPortal(null);
1878
- removeEditorContainers(this.getOwnerDocument());
1879
1730
  this.getEditorCache().clear();
1880
- renderedCellCache.clear();
1731
+ this.getRenderedCellCache().clear();
1881
1732
  this.componentRendererColumns.clear();
1882
1733
  }
1883
1734
  /**
@@ -1924,7 +1775,7 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1924
1775
  value: value,
1925
1776
  cellProperties: cellProperties,
1926
1777
  isRenderer: true
1927
- }, function () {}, TD.ownerDocument),
1778
+ }, TD.ownerDocument),
1928
1779
  portal = _createPortal.portal,
1929
1780
  portalContainer = _createPortal.portalContainer;
1930
1781
  while (TD.firstChild) {
@@ -2016,34 +1867,17 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2016
1867
  }, {
2017
1868
  key: "getGlobalRendererElement",
2018
1869
  value: function getGlobalRendererElement() {
2019
- var hotTableSlots = this.props.children;
2020
- return getChildElementByType(hotTableSlots, 'hot-renderer');
1870
+ return getChildElementByType(this.props.children, 'hot-renderer');
2021
1871
  }
2022
1872
  /**
2023
1873
  * Get the editor element for the entire HotTable instance.
2024
1874
  *
2025
- * @param {React.ReactNode} [children] Children of the HotTable instance. Defaults to `this.props.children`.
2026
1875
  * @returns {React.ReactElement} React editor component element.
2027
1876
  */
2028
1877
  }, {
2029
1878
  key: "getGlobalEditorElement",
2030
1879
  value: function getGlobalEditorElement() {
2031
- var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props.children;
2032
- return getExtendedEditorElement(children, this.getEditorCache());
2033
- }
2034
- /**
2035
- * Create the global editor portal and its destination HTML element if needed.
2036
- *
2037
- * @param {React.ReactNode} [children] Children of the HotTable instance. Defaults to `this.props.children`.
2038
- */
2039
- }, {
2040
- key: "createGlobalEditorPortal",
2041
- value: function createGlobalEditorPortal() {
2042
- var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props.children;
2043
- var globalEditorElement = this.getGlobalEditorElement(children);
2044
- if (globalEditorElement) {
2045
- this.setGlobalEditorPortal(createEditorPortal(this.getOwnerDocument(), globalEditorElement, this.getEditorCache()));
2046
- }
1880
+ return getExtendedEditorElement(this.props.children, this.getEditorCache());
2047
1881
  }
2048
1882
  /**
2049
1883
  * Create a new settings object containing the column settings and global editors and renderers.
@@ -2146,44 +1980,25 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2146
1980
  ------- React lifecycle methods -------
2147
1981
  ---------------------------------------
2148
1982
  */
2149
- /**
2150
- * Logic performed before the mounting of the component.
2151
- */
2152
- }, {
2153
- key: "componentWillMount",
2154
- value: function componentWillMount() {
2155
- this.clearCache();
2156
- this.createGlobalEditorPortal();
2157
- }
2158
1983
  /**
2159
1984
  * Initialize Handsontable after the component has mounted.
2160
1985
  */
2161
1986
  }, {
2162
1987
  key: "componentDidMount",
2163
1988
  value: function componentDidMount() {
2164
- var hotTableComponent = this;
1989
+ var _this4 = this;
2165
1990
  var newGlobalSettings = this.createNewGlobalSettings();
2166
1991
  this.hotInstance = new Handsontable__default["default"].Core(this.hotElementRef, newGlobalSettings);
2167
- this.hotInstance.addHook('beforeViewRender', function (isForced) {
2168
- hotTableComponent.handsontableBeforeViewRender();
1992
+ this.hotInstance.addHook('beforeViewRender', function () {
1993
+ return _this4.handsontableBeforeViewRender();
2169
1994
  });
2170
1995
  this.hotInstance.addHook('afterViewRender', function () {
2171
- hotTableComponent.handsontableAfterViewRender();
1996
+ return _this4.handsontableAfterViewRender();
2172
1997
  });
2173
1998
  // `init` missing in Handsontable's type definitions.
2174
1999
  this.hotInstance.init();
2175
2000
  this.displayAutoSizeWarning(newGlobalSettings);
2176
2001
  }
2177
- /**
2178
- * Logic performed before the component update.
2179
- */
2180
- }, {
2181
- key: "componentWillUpdate",
2182
- value: function componentWillUpdate(nextProps, nextState, nextContext) {
2183
- this.clearCache();
2184
- removeEditorContainers(this.getOwnerDocument());
2185
- this.createGlobalEditorPortal(nextProps.children);
2186
- }
2187
2002
  /**
2188
2003
  * Logic performed after the component update.
2189
2004
  */
@@ -2200,10 +2015,10 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2200
2015
  }, {
2201
2016
  key: "componentWillUnmount",
2202
2017
  value: function componentWillUnmount() {
2018
+ this.clearCache();
2203
2019
  if (this.hotInstance) {
2204
2020
  this.hotInstance.destroy();
2205
2021
  }
2206
- removeEditorContainers(this.getOwnerDocument());
2207
2022
  }
2208
2023
  /**
2209
2024
  * Render the component.
@@ -2211,11 +2026,8 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2211
2026
  }, {
2212
2027
  key: "render",
2213
2028
  value: function render() {
2214
- var _this4 = this;
2215
- var _getContainerAttribut = getContainerAttributesProps(this.props),
2216
- id = _getContainerAttribut.id,
2217
- className = _getContainerAttribut.className,
2218
- style = _getContainerAttribut.style;
2029
+ var _this5 = this;
2030
+ var containerProps = getContainerAttributesProps(this.props);
2219
2031
  var isHotColumn = function isHotColumn(childNode) {
2220
2032
  return childNode.type === HotColumn;
2221
2033
  };
@@ -2227,25 +2039,22 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2227
2039
  // clone the HotColumn nodes and extend them with the callbacks
2228
2040
  var childClones = children.map(function (childNode, columnIndex) {
2229
2041
  return React__default["default"].cloneElement(childNode, {
2230
- _componentRendererColumns: _this4.componentRendererColumns,
2231
- _emitColumnSettings: _this4.setHotColumnSettings.bind(_this4),
2042
+ _componentRendererColumns: _this5.componentRendererColumns,
2043
+ _emitColumnSettings: _this5.setHotColumnSettings.bind(_this5),
2232
2044
  _columnIndex: columnIndex,
2233
- _getChildElementByType: getChildElementByType.bind(_this4),
2234
- _getRendererWrapper: _this4.getRendererWrapper.bind(_this4),
2235
- _getEditorClass: _this4.getEditorClass.bind(_this4),
2236
- _getOwnerDocument: _this4.getOwnerDocument.bind(_this4),
2237
- _getEditorCache: _this4.getEditorCache.bind(_this4),
2045
+ _getChildElementByType: getChildElementByType.bind(_this5),
2046
+ _getRendererWrapper: _this5.getRendererWrapper.bind(_this5),
2047
+ _getEditorClass: _this5.getEditorClass.bind(_this5),
2048
+ _getOwnerDocument: _this5.getOwnerDocument.bind(_this5),
2049
+ _getEditorCache: _this5.getEditorCache.bind(_this5),
2238
2050
  children: childNode.props.children
2239
2051
  });
2240
2052
  });
2241
- // add the global editor to the list of children
2242
- childClones.push(this.getGlobalEditorPortal());
2243
- return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", {
2244
- ref: this.setHotElementRef.bind(this),
2245
- id: id,
2246
- className: className,
2247
- style: style
2248
- }, childClones), React__default["default"].createElement(PortalManager, {
2053
+ return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", Object.assign({
2054
+ ref: this.setHotElementRef.bind(this)
2055
+ }, containerProps), childClones, React__default["default"].createElement(EditorHolder, {
2056
+ editorElement: this.getGlobalEditorElement()
2057
+ })), React__default["default"].createElement(PortalManager, {
2249
2058
  ref: this.setPortalManagerRef.bind(this)
2250
2059
  }));
2251
2060
  }