@handsontable/react 14.0.0 → 14.1.0-next-514dcd3-20240109

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.
@@ -2,6 +2,17 @@ import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import Handsontable from 'handsontable/base';
4
4
 
5
+ function _callSuper(t, o, e) {
6
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
7
+ }
8
+ function _isNativeReflectConstruct() {
9
+ try {
10
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
11
+ } catch (t) {}
12
+ return (_isNativeReflectConstruct = function () {
13
+ return !!t;
14
+ })();
15
+ }
5
16
  function ownKeys(e, r) {
6
17
  var t = Object.keys(e);
7
18
  if (Object.getOwnPropertySymbols) {
@@ -23,6 +34,20 @@ function _objectSpread2(e) {
23
34
  }
24
35
  return e;
25
36
  }
37
+ function _toPrimitive(t, r) {
38
+ if ("object" != typeof t || !t) return t;
39
+ var e = t[Symbol.toPrimitive];
40
+ if (void 0 !== e) {
41
+ var i = e.call(t, r || "default");
42
+ if ("object" != typeof i) return i;
43
+ throw new TypeError("@@toPrimitive must return a primitive value.");
44
+ }
45
+ return ("string" === r ? String : Number)(t);
46
+ }
47
+ function _toPropertyKey(t) {
48
+ var i = _toPrimitive(t, "string");
49
+ return "symbol" == typeof i ? i : String(i);
50
+ }
26
51
  function _typeof(o) {
27
52
  "@babel/helpers - typeof";
28
53
 
@@ -97,16 +122,32 @@ function _setPrototypeOf(o, p) {
97
122
  };
98
123
  return _setPrototypeOf(o, p);
99
124
  }
100
- function _isNativeReflectConstruct() {
101
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
102
- if (Reflect.construct.sham) return false;
103
- if (typeof Proxy === "function") return true;
104
- try {
105
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
106
- return true;
107
- } catch (e) {
108
- return false;
125
+ function _objectWithoutPropertiesLoose(source, excluded) {
126
+ if (source == null) return {};
127
+ var target = {};
128
+ var sourceKeys = Object.keys(source);
129
+ var key, i;
130
+ for (i = 0; i < sourceKeys.length; i++) {
131
+ key = sourceKeys[i];
132
+ if (excluded.indexOf(key) >= 0) continue;
133
+ target[key] = source[key];
134
+ }
135
+ return target;
136
+ }
137
+ function _objectWithoutProperties(source, excluded) {
138
+ if (source == null) return {};
139
+ var target = _objectWithoutPropertiesLoose(source, excluded);
140
+ var key, i;
141
+ if (Object.getOwnPropertySymbols) {
142
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
143
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
144
+ key = sourceSymbolKeys[i];
145
+ if (excluded.indexOf(key) >= 0) continue;
146
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
147
+ target[key] = source[key];
148
+ }
109
149
  }
150
+ return target;
110
151
  }
111
152
  function _assertThisInitialized(self) {
112
153
  if (self === void 0) {
@@ -122,20 +163,6 @@ function _possibleConstructorReturn(self, call) {
122
163
  }
123
164
  return _assertThisInitialized(self);
124
165
  }
125
- function _createSuper(Derived) {
126
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
127
- return function _createSuperInternal() {
128
- var Super = _getPrototypeOf(Derived),
129
- result;
130
- if (hasNativeReflectConstruct) {
131
- var NewTarget = _getPrototypeOf(this).constructor;
132
- result = Reflect.construct(Super, arguments, NewTarget);
133
- } else {
134
- result = Super.apply(this, arguments);
135
- }
136
- return _possibleConstructorReturn(this, result);
137
- };
138
- }
139
166
  function _toConsumableArray(arr) {
140
167
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
141
168
  }
@@ -161,20 +188,6 @@ function _arrayLikeToArray(arr, len) {
161
188
  function _nonIterableSpread() {
162
189
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
163
190
  }
164
- function _toPrimitive(input, hint) {
165
- if (typeof input !== "object" || input === null) return input;
166
- var prim = input[Symbol.toPrimitive];
167
- if (prim !== undefined) {
168
- var res = prim.call(input, hint || "default");
169
- if (typeof res !== "object") return res;
170
- throw new TypeError("@@toPrimitive must return a primitive value.");
171
- }
172
- return (hint === "string" ? String : Number)(input);
173
- }
174
- function _toPropertyKey(arg) {
175
- var key = _toPrimitive(arg, "string");
176
- return typeof key === "symbol" ? key : String(key);
177
- }
178
191
 
179
192
  var bulkComponentContainer = null;
180
193
  /**
@@ -241,14 +254,12 @@ function getOriginalEditorClass(editorElement) {
241
254
  /**
242
255
  * Create an editor portal.
243
256
  *
244
- * @param {Document} [doc] Document to be used.
257
+ * @param {Document} doc Document to be used.
245
258
  * @param {React.ReactElement} editorElement Editor's element.
246
259
  * @returns {React.ReactPortal} The portal for the editor.
247
260
  */
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) {
261
+ function createEditorPortal(doc, editorElement) {
262
+ if (typeof doc === 'undefined' || editorElement === null) {
252
263
  return null;
253
264
  }
254
265
  var containerProps = getContainerAttributesProps(editorElement.props, false);
@@ -321,11 +332,19 @@ function createPortal(rElement, props) {
321
332
  function getContainerAttributesProps(props) {
322
333
  var randomizeId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
323
334
  return {
324
- id: props.id || (randomizeId ? 'hot-' + Math.random().toString(36).substring(5) : void 0),
335
+ id: props.id || (randomizeId ? 'hot-' + Math.random().toString(36).substring(5) : undefined),
325
336
  className: props.className || '',
326
337
  style: props.style || {}
327
338
  };
328
339
  }
340
+ /**
341
+ * Checks if the environment that the code runs in is a browser.
342
+ *
343
+ * @returns {boolean}
344
+ */
345
+ function isCSR() {
346
+ return typeof window !== 'undefined';
347
+ }
329
348
 
330
349
  var SettingsMapper = /*#__PURE__*/function () {
331
350
  function SettingsMapper() {
@@ -363,10 +382,9 @@ var SettingsMapper = /*#__PURE__*/function () {
363
382
 
364
383
  var HotColumn = /*#__PURE__*/function (_React$Component) {
365
384
  _inherits(HotColumn, _React$Component);
366
- var _super = _createSuper(HotColumn);
367
385
  function HotColumn() {
368
386
  _classCallCheck(this, HotColumn);
369
- return _super.apply(this, arguments);
387
+ return _callSuper(this, HotColumn, arguments);
370
388
  }
371
389
  _createClass(HotColumn, [{
372
390
  key: "getSettingsProps",
@@ -465,11 +483,10 @@ var HotColumn = /*#__PURE__*/function (_React$Component) {
465
483
  */
466
484
  var RenderersPortalManager = /*#__PURE__*/function (_React$Component) {
467
485
  _inherits(RenderersPortalManager, _React$Component);
468
- var _super = _createSuper(RenderersPortalManager);
469
486
  function RenderersPortalManager() {
470
487
  var _this;
471
488
  _classCallCheck(this, RenderersPortalManager);
472
- _this = _super.apply(this, arguments);
489
+ _this = _callSuper(this, RenderersPortalManager, arguments);
473
490
  _this.state = {
474
491
  portals: []
475
492
  };
@@ -484,7 +501,7 @@ var RenderersPortalManager = /*#__PURE__*/function (_React$Component) {
484
501
  return RenderersPortalManager;
485
502
  }(React.Component);
486
503
 
487
- var version="14.0.0";
504
+ var version="14.1.0-next-514dcd3-20240109";
488
505
 
489
506
  function createCommonjsModule(fn, module) {
490
507
  return module = { exports: {} }, fn(module, module.exports), module.exports;
@@ -1625,15 +1642,14 @@ var PropTypes = propTypes;
1625
1642
  *
1626
1643
  * ```
1627
1644
  *
1628
- * @class HotTable
1645
+ * @class HotTableCB
1629
1646
  */
1630
- var HotTable = /*#__PURE__*/function (_React$Component) {
1631
- _inherits(HotTable, _React$Component);
1632
- var _super = _createSuper(HotTable);
1633
- function HotTable() {
1647
+ var HotTableClass = /*#__PURE__*/function (_React$Component) {
1648
+ _inherits(HotTableClass, _React$Component);
1649
+ function HotTableClass() {
1634
1650
  var _this;
1635
- _classCallCheck(this, HotTable);
1636
- _this = _super.apply(this, arguments);
1651
+ _classCallCheck(this, HotTableClass);
1652
+ _this = _callSuper(this, HotTableClass, arguments);
1637
1653
  /**
1638
1654
  * The `id` of the main Handsontable DOM element.
1639
1655
  *
@@ -1698,7 +1714,7 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1698
1714
  *
1699
1715
  * @returns The version number of the package.
1700
1716
  */
1701
- _createClass(HotTable, [{
1717
+ _createClass(HotTableClass, [{
1702
1718
  key: "hotInstance",
1703
1719
  get:
1704
1720
  /**
@@ -1757,7 +1773,10 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1757
1773
  }, {
1758
1774
  key: "getOwnerDocument",
1759
1775
  value: function getOwnerDocument() {
1760
- return this.hotElementRef ? this.hotElementRef.ownerDocument : document;
1776
+ if (isCSR()) {
1777
+ return this.hotElementRef ? this.hotElementRef.ownerDocument : document;
1778
+ }
1779
+ return null;
1761
1780
  }
1762
1781
  /**
1763
1782
  * Set the reference to the main Handsontable DOM element.
@@ -1834,11 +1853,10 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
1834
1853
  value: function makeEditorClass(editorComponent) {
1835
1854
  var customEditorClass = /*#__PURE__*/function (_Handsontable$editors) {
1836
1855
  _inherits(CustomEditor, _Handsontable$editors);
1837
- var _super2 = _createSuper(CustomEditor);
1838
1856
  function CustomEditor(hotInstance) {
1839
1857
  var _this2;
1840
1858
  _classCallCheck(this, CustomEditor);
1841
- _this2 = _super2.call(this, hotInstance);
1859
+ _this2 = _callSuper(this, CustomEditor, [hotInstance]);
1842
1860
  editorComponent.hotCustomEditorInstance = _assertThisInitialized(_this2);
1843
1861
  _this2.editorComponent = editorComponent;
1844
1862
  return _this2;
@@ -2044,7 +2062,6 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2044
2062
  key: "render",
2045
2063
  value: function render() {
2046
2064
  var _this5 = this;
2047
- var containerProps = getContainerAttributesProps(this.props);
2048
2065
  var isHotColumn = function isHotColumn(childNode) {
2049
2066
  return childNode.type === HotColumn;
2050
2067
  };
@@ -2065,6 +2082,7 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2065
2082
  children: childNode.props.children
2066
2083
  });
2067
2084
  });
2085
+ var containerProps = getContainerAttributesProps(this.props);
2068
2086
  var editorPortal = createEditorPortal(this.getOwnerDocument(), this.getGlobalEditorElement());
2069
2087
  return React.createElement(React.Fragment, null, React.createElement("div", Object.assign({
2070
2088
  ref: this.setHotElementRef.bind(this)
@@ -2078,24 +2096,39 @@ var HotTable = /*#__PURE__*/function (_React$Component) {
2078
2096
  return version;
2079
2097
  }
2080
2098
  }]);
2081
- return HotTable;
2099
+ return HotTableClass;
2082
2100
  }(React.Component);
2083
2101
  /**
2084
2102
  * Prop types to be checked at runtime.
2085
2103
  */
2086
- HotTable.propTypes = {
2104
+ HotTableClass.propTypes = {
2087
2105
  style: PropTypes.object,
2088
2106
  id: PropTypes.string,
2089
2107
  className: PropTypes.string
2090
2108
  };
2091
2109
 
2110
+ var _excluded = ["children"];
2111
+ // Use global React variable for `forwardRef` access (React 16 support)
2112
+ var HotTable = React.forwardRef(function (_ref, ref) {
2113
+ var _props$id;
2114
+ var children = _ref.children,
2115
+ props = _objectWithoutProperties(_ref, _excluded);
2116
+ var generatedId = typeof React.useId === 'function' ? React.useId() : undefined;
2117
+ var componentId = (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generatedId;
2118
+ return React.createElement(HotTableClass, Object.assign({
2119
+ id: componentId
2120
+ }, props, {
2121
+ ref: ref
2122
+ }), children);
2123
+ });
2124
+ HotTable.version = HotTableClass.version;
2125
+
2092
2126
  var BaseEditorComponent = /*#__PURE__*/function (_React$Component) {
2093
2127
  _inherits(BaseEditorComponent, _React$Component);
2094
- var _super = _createSuper(BaseEditorComponent);
2095
2128
  function BaseEditorComponent() {
2096
2129
  var _this;
2097
2130
  _classCallCheck(this, BaseEditorComponent);
2098
- _this = _super.apply(this, arguments);
2131
+ _this = _callSuper(this, BaseEditorComponent, arguments);
2099
2132
  _this.name = 'BaseEditorComponent';
2100
2133
  _this.instance = null;
2101
2134
  _this.row = null;
package/helpers.d.ts CHANGED
@@ -40,7 +40,7 @@ export declare function getOriginalEditorClass(editorElement: HotEditorElement):
40
40
  /**
41
41
  * Create an editor portal.
42
42
  *
43
- * @param {Document} [doc] Document to be used.
43
+ * @param {Document} doc Document to be used.
44
44
  * @param {React.ReactElement} editorElement Editor's element.
45
45
  * @returns {React.ReactPortal} The portal for the editor.
46
46
  */
@@ -81,3 +81,9 @@ export declare function getContainerAttributesProps(props: any, randomizeId?: bo
81
81
  className: string;
82
82
  style: object;
83
83
  };
84
+ /**
85
+ * Checks if the environment that the code runs in is a browser.
86
+ *
87
+ * @returns {boolean}
88
+ */
89
+ export declare function isCSR(): boolean;
package/hotTable.d.ts CHANGED
@@ -1,237 +1,10 @@
1
- import React from 'react';
2
- import Handsontable from 'handsontable/base';
3
- import { RenderersPortalManager } from './renderersPortalManager';
4
- import { HotTableProps, HotEditorElement, HotEditorCache, EditorScopeIdentifier } from './types';
5
- /**
6
- * A Handsontable-ReactJS wrapper.
7
- *
8
- * To implement, use the `HotTable` tag with properties corresponding to Handsontable options.
9
- * For example:
10
- *
11
- * ```js
12
- * <HotTable id="hot" data={dataObject} contextMenu={true} colHeaders={true} width={600} height={300} stretchH="all" />
13
- *
14
- * // is analogous to
15
- * let hot = new Handsontable(document.getElementById('hot'), {
16
- * data: dataObject,
17
- * contextMenu: true,
18
- * colHeaders: true,
19
- * width: 600
20
- * height: 300
21
- * });
22
- *
23
- * ```
24
- *
25
- * @class HotTable
26
- */
27
- declare class HotTable extends React.Component<HotTableProps, {}> {
28
- /**
29
- * The `id` of the main Handsontable DOM element.
30
- *
31
- * @type {String}
32
- */
33
- id: string;
34
- /**
35
- * Reference to the Handsontable instance.
36
- *
37
- * @private
38
- * @type {Object}
39
- */
40
- __hotInstance: Handsontable | null;
41
- /**
42
- * Reference to the main Handsontable DOM element.
43
- *
44
- * @type {HTMLElement}
45
- */
46
- hotElementRef: HTMLElement;
47
- /**
48
- * Class name added to the component DOM element.
49
- *
50
- * @type {String}
51
- */
52
- className: string;
53
- /**
54
- * Style object passed to the component.
55
- *
56
- * @type {React.CSSProperties}
57
- */
58
- style: React.CSSProperties;
59
- /**
60
- * Array of object containing the column settings.
61
- *
62
- * @type {Array}
63
- */
64
- columnSettings: Handsontable.ColumnSettings[];
65
- /**
66
- * Component used to manage the renderer portals.
67
- *
68
- * @type {React.Component}
69
- */
70
- renderersPortalManager: RenderersPortalManager;
71
- /**
72
- * Array containing the portals cashed to be rendered in bulk after Handsontable's render cycle.
73
- */
74
- portalCacheArray: React.ReactPortal[];
75
- /**
76
- * The rendered cells cache.
77
- *
78
- * @private
79
- * @type {Map}
80
- */
81
- private renderedCellCache;
82
- /**
83
- * Editor cache.
84
- *
85
- * @private
86
- * @type {Map}
87
- */
88
- private editorCache;
89
- /**
90
- * Map with column indexes (or a string = 'global') as keys, and booleans as values. Each key represents a component-based editor
91
- * declared for the used column index, or a global one, if the key is the `global` string.
92
- *
93
- * @private
94
- * @type {Map}
95
- */
96
- private componentRendererColumns;
97
- /**
98
- * Package version getter.
99
- *
100
- * @returns The version number of the package.
101
- */
102
- static get version(): string;
103
- /**
104
- * Getter for the property storing the Handsontable instance.
105
- */
106
- get hotInstance(): Handsontable | null;
107
- /**
108
- * Setter for the property storing the Handsontable instance.
109
- * @param {Handsontable} hotInstance The Handsontable instance.
110
- */
111
- set hotInstance(hotInstance: Handsontable | null);
112
- /**
113
- * Prop types to be checked at runtime.
114
- */
115
- static propTypes: object;
116
- /**
117
- * Get the rendered table cell cache.
118
- *
119
- * @returns {Map}
120
- */
121
- getRenderedCellCache(): Map<string, HTMLTableCellElement>;
122
- /**
123
- * Get the editor cache and return it.
124
- *
125
- * @returns {Map}
126
- */
127
- getEditorCache(): HotEditorCache;
128
- /**
129
- * Clear both the editor and the renderer cache.
130
- */
131
- clearCache(): void;
132
- /**
133
- * Get the `Document` object corresponding to the main component element.
134
- *
135
- * @returns The `Document` object used by the component.
136
- */
137
- getOwnerDocument(): Document;
138
- /**
139
- * Set the reference to the main Handsontable DOM element.
140
- *
141
- * @param {HTMLElement} element The main Handsontable DOM element.
142
- */
143
- private setHotElementRef;
144
- /**
145
- * Return a renderer wrapper function for the provided renderer component.
146
- *
147
- * @param {React.ReactElement} rendererElement React renderer component.
148
- * @returns {Handsontable.renderers.Base} The Handsontable rendering function.
149
- */
150
- getRendererWrapper(rendererElement: React.ReactElement): typeof Handsontable.renderers.BaseRenderer | any;
151
- /**
152
- * Create a fresh class to be used as an editor, based on the provided editor React element.
153
- *
154
- * @param {React.ReactElement} editorElement React editor component.
155
- * @param {string|number} [editorColumnScope] The editor scope (column index or a 'global' string). Defaults to
156
- * 'global'.
157
- * @returns {Function} A class to be passed to the Handsontable editor settings.
158
- */
159
- getEditorClass(editorElement: HotEditorElement, editorColumnScope?: EditorScopeIdentifier): typeof Handsontable.editors.BaseEditor;
160
- /**
161
- * Create a class to be passed to the Handsontable's settings.
162
- *
163
- * @param {React.ReactElement} editorComponent React editor component.
164
- * @returns {Function} A class to be passed to the Handsontable editor settings.
165
- */
166
- makeEditorClass(editorComponent: React.Component): typeof Handsontable.editors.BaseEditor;
167
- /**
168
- * Get the renderer element for the entire HotTable instance.
169
- *
170
- * @returns {React.ReactElement} React renderer component element.
171
- */
172
- getGlobalRendererElement(): React.ReactElement;
173
- /**
174
- * Get the editor element for the entire HotTable instance.
175
- *
176
- * @param {React.ReactNode} [children] Children of the HotTable instance. Defaults to `this.props.children`.
177
- * @returns {React.ReactElement} React editor component element.
178
- */
179
- getGlobalEditorElement(): HotEditorElement | null;
180
- /**
181
- * Create a new settings object containing the column settings and global editors and renderers.
182
- *
183
- * @returns {Handsontable.GridSettings} New global set of settings for Handsontable.
184
- */
185
- createNewGlobalSettings(): Handsontable.GridSettings;
186
- /**
187
- * Detect if `autoRowSize` or `autoColumnSize` is defined, and if so, throw an incompatibility warning.
188
- *
189
- * @param {Handsontable.GridSettings} newGlobalSettings New global settings passed as Handsontable config.
190
- */
191
- displayAutoSizeWarning(newGlobalSettings: Handsontable.GridSettings): void;
192
- /**
193
- * Sets the column settings based on information received from HotColumn.
194
- *
195
- * @param {HotTableProps} columnSettings Column settings object.
196
- * @param {Number} columnIndex Column index.
197
- */
198
- setHotColumnSettings(columnSettings: Handsontable.ColumnSettings, columnIndex: number): void;
199
- /**
200
- * Handsontable's `beforeViewRender` hook callback.
201
- */
202
- handsontableBeforeViewRender(): void;
203
- /**
204
- * Handsontable's `afterViewRender` hook callback.
205
- */
206
- handsontableAfterViewRender(): void;
207
- /**
208
- * Call the `updateSettings` method for the Handsontable instance.
209
- *
210
- * @param {Object} newSettings The settings object.
211
- */
212
- private updateHot;
213
- /**
214
- * Set the renderers portal manager ref.
215
- *
216
- * @param {React.ReactComponent} pmComponent The PortalManager component.
217
- */
218
- private setRenderersPortalManagerRef;
219
- /**
220
- * Initialize Handsontable after the component has mounted.
221
- */
222
- componentDidMount(): void;
223
- /**
224
- * Logic performed after the component update.
225
- */
226
- componentDidUpdate(): void;
227
- /**
228
- * Destroy the Handsontable instance when the parent component unmounts.
229
- */
230
- componentWillUnmount(): void;
231
- /**
232
- * Render the component.
233
- */
234
- render(): React.ReactElement;
1
+ import { ForwardRefExoticComponent, RefAttributes } from 'react';
2
+ import { HotTableClass } from './hotTableClass';
3
+ import { HotTableProps } from './types';
4
+ interface Version {
5
+ version?: string;
235
6
  }
7
+ declare type HotTable = ForwardRefExoticComponent<HotTableProps & RefAttributes<HotTableClass>> & Version;
8
+ declare const HotTable: HotTable;
236
9
  export default HotTable;
237
10
  export { HotTable };