@handsontable/react 0.0.0-next-eaf150e-20240823 → 0.0.0-next-0306a1a-20240826

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 (42) hide show
  1. package/commonjs/react-handsontable.js +747 -1096
  2. package/commonjs/src/helpers.d.ts +105 -0
  3. package/commonjs/src/hotColumn.d.ts +5 -0
  4. package/commonjs/src/hotColumnContext.d.ts +16 -0
  5. package/commonjs/src/hotEditor.d.ts +33 -0
  6. package/commonjs/src/hotTable.d.ts +29 -0
  7. package/commonjs/src/hotTableContext.d.ts +55 -0
  8. package/commonjs/src/hotTableInner.d.ts +5 -0
  9. package/commonjs/src/index.d.ts +5 -0
  10. package/commonjs/src/renderersPortalManager.d.ts +6 -0
  11. package/commonjs/src/settingsMapper.d.ts +18 -0
  12. package/commonjs/src/types.d.ts +78 -0
  13. package/dist/react-handsontable.js +747 -1096
  14. package/dist/react-handsontable.js.map +1 -1
  15. package/dist/react-handsontable.min.js +2 -2
  16. package/dist/react-handsontable.min.js.map +1 -1
  17. package/dist/src/helpers.d.ts +105 -0
  18. package/dist/src/hotColumn.d.ts +5 -0
  19. package/dist/src/hotColumnContext.d.ts +16 -0
  20. package/dist/src/hotEditor.d.ts +33 -0
  21. package/dist/src/hotTable.d.ts +29 -0
  22. package/dist/src/hotTableContext.d.ts +55 -0
  23. package/dist/src/hotTableInner.d.ts +5 -0
  24. package/dist/src/index.d.ts +5 -0
  25. package/dist/src/renderersPortalManager.d.ts +6 -0
  26. package/dist/src/settingsMapper.d.ts +18 -0
  27. package/dist/src/types.d.ts +78 -0
  28. package/es/react-handsontable.mjs +745 -1094
  29. package/helpers.d.ts +47 -33
  30. package/hotColumn.d.ts +4 -41
  31. package/hotColumnContext.d.ts +16 -0
  32. package/hotEditor.d.ts +33 -0
  33. package/hotTable.d.ts +22 -3
  34. package/hotTableContext.d.ts +55 -0
  35. package/hotTableInner.d.ts +5 -0
  36. package/index.d.ts +1 -2
  37. package/package.json +5 -5
  38. package/renderersPortalManager.d.ts +3 -9
  39. package/settingsMapper.d.ts +1 -1
  40. package/types.d.ts +55 -27
  41. package/baseEditorComponent.d.ts +0 -50
  42. package/hotTableClass.d.ts +0 -260
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var ReactDOM = require('react-dom');
7
7
  var Handsontable = require('handsontable/base');
8
- var registry$1 = require('handsontable/renderers/registry');
9
- var registry = require('handsontable/editors/registry');
8
+ var registry = require('handsontable/renderers/registry');
9
+ var registry$1 = require('handsontable/editors/registry');
10
10
 
11
11
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
12
12
 
@@ -14,11 +14,198 @@ var React__default = /*#__PURE__*/_interopDefaultCompat(React);
14
14
  var ReactDOM__default = /*#__PURE__*/_interopDefaultCompat(ReactDOM);
15
15
  var Handsontable__default = /*#__PURE__*/_interopDefaultCompat(Handsontable);
16
16
 
17
+ var bulkComponentContainer = null;
18
+ /**
19
+ * Warning message for the `autoRowSize`/`autoColumnSize` compatibility check.
20
+ */
21
+ var AUTOSIZE_WARNING = 'Your `HotTable` configuration includes `autoRowSize`/`autoColumnSize` options, which are not compatible with ' + ' the component-based renderers`. Disable `autoRowSize` and `autoColumnSize` to prevent row and column misalignment.';
22
+ /**
23
+ * Warning message for the `hot-renderer` obsolete renderer passing method.
24
+ */
25
+ var OBSOLETE_HOTRENDERER_WARNING = 'Providing a component-based renderer using `hot-renderer`-annotated component is no longer supported. ' + 'Pass your component using `renderer` prop of the `HotTable` or `HotColumn` component instead.';
26
+ /**
27
+ * Warning message for the `hot-editor` obsolete editor passing method.
28
+ */
29
+ var OBSOLETE_HOTEDITOR_WARNING = 'Providing a component-based editor using `hot-editor`-annotated component is no longer supported. ' + 'Pass your component using `editor` prop of the `HotTable` or `HotColumn` component instead.';
30
+ /**
31
+ * Warning message for the unexpected children of HotTable component.
32
+ */
33
+ var UNEXPECTED_HOTTABLE_CHILDREN_WARNING = 'Unexpected children nodes found in HotTable component. ' + 'Only HotColumn components are allowed.';
34
+ /**
35
+ * Warning message for the unexpected children of HotColumn component.
36
+ */
37
+ var UNEXPECTED_HOTCOLUMN_CHILDREN_WARNING = 'Unexpected children nodes found in HotColumn component. ' + 'HotColumn components do not support any children.';
38
+ /**
39
+ * Message for the warning thrown if the Handsontable instance has been destroyed.
40
+ */
41
+ var HOT_DESTROYED_WARNING = 'The Handsontable instance bound to this component was destroyed and cannot be' + ' used properly.';
42
+ /**
43
+ * Default classname given to the wrapper container.
44
+ */
45
+ var DEFAULT_CLASSNAME = 'hot-wrapper-editor-container';
46
+ /**
47
+ * Logs warn to the console if the `console` object is exposed.
48
+ *
49
+ * @param {...*} args Values which will be logged.
50
+ */
51
+ function warn() {
52
+ if (typeof console !== 'undefined') {
53
+ var _console;
54
+ (_console = console).warn.apply(_console, arguments);
55
+ }
56
+ }
57
+ /**
58
+ * Detect if `hot-renderer` or `hot-editor` is defined, and if so, throw an incompatibility warning.
59
+ *
60
+ * @returns {boolean} 'true' if the warning was issued
61
+ */
62
+ function displayObsoleteRenderersEditorsWarning(children) {
63
+ if (hasChildElementOfType(children, 'hot-renderer')) {
64
+ warn(OBSOLETE_HOTRENDERER_WARNING);
65
+ return true;
66
+ }
67
+ if (hasChildElementOfType(children, 'hot-editor')) {
68
+ warn(OBSOLETE_HOTEDITOR_WARNING);
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ /**
74
+ * Detect if children of specified type are defined, and if so, throw an incompatibility warning.
75
+ *
76
+ * @param {React.ReactNode} children Component children nodes
77
+ * @param {React.ComponentType} Component Component type to check
78
+ * @returns {boolean} 'true' if the warning was issued
79
+ */
80
+ function displayChildrenOfTypeWarning(children, Component) {
81
+ var childrenArray = React__default["default"].Children.toArray(children);
82
+ if (childrenArray.some(function (child) {
83
+ return child.type !== Component;
84
+ })) {
85
+ warn(UNEXPECTED_HOTTABLE_CHILDREN_WARNING);
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ /**
91
+ * Detect if children is defined, and if so, throw an incompatibility warning.
92
+ *
93
+ * @param {React.ReactNode} children Component children nodes
94
+ * @returns {boolean} 'true' if the warning was issued
95
+ */
96
+ function displayAnyChildrenWarning(children) {
97
+ var childrenArray = React__default["default"].Children.toArray(children);
98
+ if (childrenArray.length) {
99
+ warn(UNEXPECTED_HOTCOLUMN_CHILDREN_WARNING);
100
+ return true;
101
+ }
102
+ return false;
103
+ }
104
+ /**
105
+ * Check the existence of elements of the provided `type` from the `HotColumn` component's children.
106
+ *
107
+ * @param {React.ReactNode} children HotTable children array.
108
+ * @param {String} type Either `'hot-renderer'` or `'hot-editor'`.
109
+ * @returns {boolean} `true` if the child of that type was found, `false` otherwise.
110
+ */
111
+ function hasChildElementOfType(children, type) {
112
+ var childrenArray = React__default["default"].Children.toArray(children);
113
+ return childrenArray.some(function (child) {
114
+ return child.props[type] !== void 0;
115
+ });
116
+ }
117
+ /**
118
+ * Create an editor portal.
119
+ *
120
+ * @param {Document} doc Document to be used.
121
+ * @param {React.ComponentType} Editor Editor component or render function.
122
+ * @returns {React.ReactPortal} The portal for the editor.
123
+ */
124
+ function createEditorPortal(doc, Editor) {
125
+ if (!doc || !Editor) {
126
+ return null;
127
+ }
128
+ var editorElement = React__default["default"].createElement(Editor, null);
129
+ var containerProps = getContainerAttributesProps({}, false);
130
+ containerProps.className = "".concat(DEFAULT_CLASSNAME, " ").concat(containerProps.className);
131
+ return ReactDOM__default["default"].createPortal(React__default["default"].createElement("div", Object.assign({}, containerProps), editorElement), doc.body);
132
+ }
133
+ /**
134
+ * Render a cell component to an external DOM node.
135
+ *
136
+ * @param {React.ReactElement} rElement React element to be used as a base for the component.
137
+ * @param {Document} [ownerDocument] The owner document to set the portal up into.
138
+ * @param {String} portalKey The key to be used for the portal.
139
+ * @param {HTMLElement} [cachedContainer] The cached container to be used for the portal.
140
+ * @returns {{portal: React.ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its container.
141
+ */
142
+ function createPortal(rElement) {
143
+ var ownerDocument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
144
+ var portalKey = arguments.length > 2 ? arguments[2] : undefined;
145
+ var cachedContainer = arguments.length > 3 ? arguments[3] : undefined;
146
+ if (!ownerDocument) {
147
+ ownerDocument = document;
148
+ }
149
+ if (!bulkComponentContainer) {
150
+ bulkComponentContainer = ownerDocument.createDocumentFragment();
151
+ }
152
+ var portalContainer = cachedContainer !== null && cachedContainer !== void 0 ? cachedContainer : ownerDocument.createElement('DIV');
153
+ bulkComponentContainer.appendChild(portalContainer);
154
+ return {
155
+ portal: ReactDOM__default["default"].createPortal(rElement, portalContainer, portalKey),
156
+ portalContainer: portalContainer
157
+ };
158
+ }
159
+ /**
160
+ * Get an object containing the `id`, `className` and `style` keys, representing the corresponding props passed to the
161
+ * component.
162
+ *
163
+ * @param {HotTableProps} props Object containing the React element props.
164
+ * @param {Boolean} randomizeId If set to `true`, the function will randomize the `id` property when no `id` was present in the `prop` object.
165
+ * @returns An object containing the `id`, `className` and `style` keys, representing the corresponding props passed to the
166
+ * component.
167
+ */
168
+ function getContainerAttributesProps(props) {
169
+ var randomizeId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
170
+ return {
171
+ id: props.id || (randomizeId ? 'hot-' + Math.random().toString(36).substring(5) : undefined),
172
+ className: props.className || '',
173
+ style: props.style || {}
174
+ };
175
+ }
176
+ /**
177
+ * Checks if the environment that the code runs in is a browser.
178
+ *
179
+ * @returns {boolean}
180
+ */
181
+ function isCSR() {
182
+ return typeof window !== 'undefined';
183
+ }
184
+ /**
185
+ * A variant of React.useEffect hook that does not trigger on initial mount, only updates
186
+ *
187
+ * @param effect Effect function
188
+ * @param deps Effect dependencies
189
+ */
190
+ function useUpdateEffect(effect, deps) {
191
+ var notInitialRender = React__default["default"].useRef(false);
192
+ React__default["default"].useEffect(function () {
193
+ if (notInitialRender.current) {
194
+ return effect();
195
+ } else {
196
+ notInitialRender.current = true;
197
+ }
198
+ }, deps);
199
+ }
200
+
17
201
  function _arrayLikeToArray(r, a) {
18
202
  (null == a || a > r.length) && (a = r.length);
19
203
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
20
204
  return n;
21
205
  }
206
+ function _arrayWithHoles(r) {
207
+ if (Array.isArray(r)) return r;
208
+ }
22
209
  function _arrayWithoutHoles(r) {
23
210
  if (Array.isArray(r)) return _arrayLikeToArray(r);
24
211
  }
@@ -79,6 +266,33 @@ function _isNativeReflectConstruct() {
79
266
  function _iterableToArray(r) {
80
267
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
81
268
  }
269
+ function _iterableToArrayLimit(r, l) {
270
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
271
+ if (null != t) {
272
+ var e,
273
+ n,
274
+ i,
275
+ u,
276
+ a = [],
277
+ f = !0,
278
+ o = !1;
279
+ try {
280
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
281
+ } catch (r) {
282
+ o = !0, n = r;
283
+ } finally {
284
+ try {
285
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
286
+ } finally {
287
+ if (o) throw n;
288
+ }
289
+ }
290
+ return a;
291
+ }
292
+ }
293
+ function _nonIterableRest() {
294
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
295
+ }
82
296
  function _nonIterableSpread() {
83
297
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
84
298
  }
@@ -109,8 +323,8 @@ function _objectWithoutProperties(e, t) {
109
323
  r,
110
324
  i = _objectWithoutPropertiesLoose(e, t);
111
325
  if (Object.getOwnPropertySymbols) {
112
- var s = Object.getOwnPropertySymbols(e);
113
- for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
326
+ var n = Object.getOwnPropertySymbols(e);
327
+ for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
114
328
  }
115
329
  return i;
116
330
  }
@@ -118,7 +332,7 @@ function _objectWithoutPropertiesLoose(r, e) {
118
332
  if (null == r) return {};
119
333
  var t = {};
120
334
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
121
- if (e.includes(n)) continue;
335
+ if (e.indexOf(n) >= 0) continue;
122
336
  t[n] = r[n];
123
337
  }
124
338
  return t;
@@ -133,6 +347,9 @@ function _setPrototypeOf(t, e) {
133
347
  return t.__proto__ = e, t;
134
348
  }, _setPrototypeOf(t, e);
135
349
  }
350
+ function _slicedToArray(r, e) {
351
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
352
+ }
136
353
  function _toConsumableArray(r) {
137
354
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
138
355
  }
@@ -140,11 +357,11 @@ function _toPrimitive(t, r) {
140
357
  if ("object" != typeof t || !t) return t;
141
358
  var e = t[Symbol.toPrimitive];
142
359
  if (void 0 !== e) {
143
- var i = e.call(t, r );
360
+ var i = e.call(t, r || "default");
144
361
  if ("object" != typeof i) return i;
145
362
  throw new TypeError("@@toPrimitive must return a primitive value.");
146
363
  }
147
- return (String )(t);
364
+ return ("string" === r ? String : Number)(t);
148
365
  }
149
366
  function _toPropertyKey(t) {
150
367
  var i = _toPrimitive(t, "string");
@@ -167,167 +384,6 @@ function _unsupportedIterableToArray(r, a) {
167
384
  }
168
385
  }
169
386
 
170
- var bulkComponentContainer = null;
171
- /**
172
- * Warning message for the `autoRowSize`/`autoColumnSize` compatibility check.
173
- */
174
- var AUTOSIZE_WARNING = 'Your `HotTable` configuration includes `autoRowSize`/`autoColumnSize` options, which are not compatible with ' + ' the component-based renderers`. Disable `autoRowSize` and `autoColumnSize` to prevent row and column misalignment.';
175
- /**
176
- * Message for the warning thrown if the Handsontable instance has been destroyed.
177
- */
178
- var HOT_DESTROYED_WARNING = 'The Handsontable instance bound to this component was destroyed and cannot be' + ' used properly.';
179
- /**
180
- * String identifier for the global-scoped editor components.
181
- */
182
- var GLOBAL_EDITOR_SCOPE = 'global';
183
- /**
184
- * Default classname given to the wrapper container.
185
- */
186
- var DEFAULT_CLASSNAME = 'hot-wrapper-editor-container';
187
- /**
188
- * Logs warn to the console if the `console` object is exposed.
189
- *
190
- * @param {...*} args Values which will be logged.
191
- */
192
- function warn() {
193
- if (typeof console !== 'undefined') {
194
- var _console;
195
- (_console = console).warn.apply(_console, arguments);
196
- }
197
- }
198
- /**
199
- * Filter out and return elements of the provided `type` from the `HotColumn` component's children.
200
- *
201
- * @param {React.ReactNode} children HotTable children array.
202
- * @param {String} type Either `'hot-renderer'` or `'hot-editor'`.
203
- * @returns {Object|null} A child (React node) or `null`, if no child of that type was found.
204
- */
205
- function getChildElementByType(children, type) {
206
- var childrenArray = React__default["default"].Children.toArray(children);
207
- var childrenCount = React__default["default"].Children.count(children);
208
- var wantedChild = null;
209
- if (childrenCount !== 0) {
210
- if (childrenCount === 1 && childrenArray[0].props[type]) {
211
- wantedChild = childrenArray[0];
212
- } else {
213
- wantedChild = childrenArray.find(function (child) {
214
- return child.props[type] !== void 0;
215
- });
216
- }
217
- }
218
- return wantedChild || null;
219
- }
220
- /**
221
- * Get the reference to the original editor class.
222
- *
223
- * @param {React.ReactElement} editorElement React element of the editor class.
224
- * @returns {Function} Original class of the editor component.
225
- */
226
- function getOriginalEditorClass(editorElement) {
227
- if (!editorElement) {
228
- return null;
229
- }
230
- return editorElement.type.WrappedComponent ? editorElement.type.WrappedComponent : editorElement.type;
231
- }
232
- /**
233
- * Create an editor portal.
234
- *
235
- * @param {Document} doc Document to be used.
236
- * @param {React.ReactElement} editorElement Editor's element.
237
- * @returns {React.ReactPortal} The portal for the editor.
238
- */
239
- function createEditorPortal(doc, editorElement) {
240
- if (typeof doc === 'undefined' || editorElement === null) {
241
- return null;
242
- }
243
- var containerProps = getContainerAttributesProps(editorElement.props, false);
244
- containerProps.className = "".concat(DEFAULT_CLASSNAME, " ").concat(containerProps.className);
245
- return ReactDOM__default["default"].createPortal(React__default["default"].createElement("div", Object.assign({}, containerProps), editorElement), doc.body);
246
- }
247
- /**
248
- * Get an editor element extended with an instance-emitting method.
249
- *
250
- * @param {React.ReactNode} children Component children.
251
- * @param {Map} editorCache Component's editor cache.
252
- * @param {EditorScopeIdentifier} [editorColumnScope] The editor scope (column index or a 'global' string). Defaults to
253
- * 'global'.
254
- * @returns {React.ReactElement} An editor element containing the additional methods.
255
- */
256
- function getExtendedEditorElement(children, editorCache) {
257
- var editorColumnScope = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : GLOBAL_EDITOR_SCOPE;
258
- var editorElement = getChildElementByType(children, 'hot-editor');
259
- var editorClass = getOriginalEditorClass(editorElement);
260
- if (!editorElement) {
261
- return null;
262
- }
263
- return React__default["default"].cloneElement(editorElement, {
264
- emitEditorInstance: function emitEditorInstance(editorInstance, editorColumnScope) {
265
- if (!editorCache.get(editorClass)) {
266
- editorCache.set(editorClass, new Map());
267
- }
268
- var cacheEntry = editorCache.get(editorClass);
269
- cacheEntry.set(editorColumnScope !== null && editorColumnScope !== void 0 ? editorColumnScope : GLOBAL_EDITOR_SCOPE, editorInstance);
270
- },
271
- editorColumnScope: editorColumnScope,
272
- isEditor: true
273
- });
274
- }
275
- /**
276
- * Create a react component and render it to an external DOM done.
277
- *
278
- * @param {React.ReactElement} rElement React element to be used as a base for the component.
279
- * @param {Object} props Props to be passed to the cloned element.
280
- * @param {Document} [ownerDocument] The owner document to set the portal up into.
281
- * @param {String} portalKey The key to be used for the portal.
282
- * @param {HTMLElement} [cachedContainer] The cached container to be used for the portal.
283
- * @returns {{portal: React.ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its container.
284
- */
285
- function createPortal(rElement, props) {
286
- var ownerDocument = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document;
287
- var portalKey = arguments.length > 3 ? arguments[3] : undefined;
288
- var cachedContainer = arguments.length > 4 ? arguments[4] : undefined;
289
- if (!ownerDocument) {
290
- ownerDocument = document;
291
- }
292
- if (!bulkComponentContainer) {
293
- bulkComponentContainer = ownerDocument.createDocumentFragment();
294
- }
295
- var portalContainer = cachedContainer !== null && cachedContainer !== void 0 ? cachedContainer : ownerDocument.createElement('DIV');
296
- bulkComponentContainer.appendChild(portalContainer);
297
- var extendedRendererElement = React__default["default"].cloneElement(rElement, _objectSpread2({
298
- key: "".concat(props.row, "-").concat(props.col)
299
- }, props));
300
- return {
301
- portal: ReactDOM__default["default"].createPortal(extendedRendererElement, portalContainer, portalKey),
302
- portalContainer: portalContainer
303
- };
304
- }
305
- /**
306
- * Get an object containing the `id`, `className` and `style` keys, representing the corresponding props passed to the
307
- * component.
308
- *
309
- * @param {Object} props Object containing the react element props.
310
- * @param {Boolean} randomizeId If set to `true`, the function will randomize the `id` property when no `id` was present in the `prop` object.
311
- * @returns An object containing the `id`, `className` and `style` keys, representing the corresponding props passed to the
312
- * component.
313
- */
314
- function getContainerAttributesProps(props) {
315
- var randomizeId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
316
- return {
317
- id: props.id || (randomizeId ? 'hot-' + Math.random().toString(36).substring(5) : undefined),
318
- className: props.className || '',
319
- style: props.style || {}
320
- };
321
- }
322
- /**
323
- * Checks if the environment that the code runs in is a browser.
324
- *
325
- * @returns {boolean}
326
- */
327
- function isCSR() {
328
- return typeof window !== 'undefined';
329
- }
330
-
331
387
  var SettingsMapper = /*#__PURE__*/function () {
332
388
  function SettingsMapper() {
333
389
  _classCallCheck(this, SettingsMapper);
@@ -336,7 +392,7 @@ var SettingsMapper = /*#__PURE__*/function () {
336
392
  key: "getSettings",
337
393
  value:
338
394
  /**
339
- * Parse component settings into Handosntable-compatible settings.
395
+ * Parse component settings into Handsontable-compatible settings.
340
396
  *
341
397
  * @param {Object} properties Object containing properties from the HotTable object.
342
398
  * @param {Object} additionalSettings Additional settings.
@@ -345,32 +401,14 @@ var SettingsMapper = /*#__PURE__*/function () {
345
401
  * @returns {Object} Handsontable-compatible settings object.
346
402
  */
347
403
  function getSettings(properties) {
348
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
349
- _ref$prevProps = _ref.prevProps,
350
- prevProps = _ref$prevProps === void 0 ? {} : _ref$prevProps,
351
- _ref$isInit = _ref.isInit,
352
- isInit = _ref$isInit === void 0 ? false : _ref$isInit,
353
- _ref$initOnlySettingK = _ref.initOnlySettingKeys,
354
- initOnlySettingKeys = _ref$initOnlySettingK === void 0 ? [] : _ref$initOnlySettingK;
355
- var shouldSkipProp = function shouldSkipProp(key) {
356
- // Omit settings that can be set only during initialization and are intentionally modified.
357
- if (!isInit && initOnlySettingKeys.includes(key)) {
358
- return prevProps[key] === properties[key];
359
- }
360
- return false;
361
- };
404
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
405
+ _ref.prevProps;
406
+ _ref.isInit;
407
+ _ref.initOnlySettingKeys;
362
408
  var newSettings = {};
363
- if (properties.settings) {
364
- var settings = properties.settings;
365
- for (var key in settings) {
366
- if (settings.hasOwnProperty(key) && !shouldSkipProp(key)) {
367
- newSettings[key] = settings[key];
368
- }
369
- }
370
- }
371
- for (var _key in properties) {
372
- if (_key !== 'settings' && _key !== 'children' && !shouldSkipProp(_key) && properties.hasOwnProperty(_key)) {
373
- newSettings[_key] = properties[_key];
409
+ for (var key in properties) {
410
+ if (key !== 'children' && properties.hasOwnProperty(key)) {
411
+ newSettings[key] = properties[key];
374
412
  }
375
413
  }
376
414
  return newSettings;
@@ -378,126 +416,358 @@ var SettingsMapper = /*#__PURE__*/function () {
378
416
  }]);
379
417
  }();
380
418
 
381
- var HotColumn = /*#__PURE__*/function (_React$Component) {
382
- function HotColumn() {
383
- _classCallCheck(this, HotColumn);
384
- return _callSuper(this, HotColumn, arguments);
385
- }
386
- _inherits(HotColumn, _React$Component);
387
- return _createClass(HotColumn, [{
388
- key: "getSettingsProps",
389
- value:
390
- /**
391
- * Filter out all the internal properties and return an object with just the Handsontable-related props.
392
- *
393
- * @returns {Object}
394
- */
395
- function getSettingsProps() {
396
- var _this = this;
397
- this.internalProps = ['_componentRendererColumns', '_emitColumnSettings', '_columnIndex', '_getChildElementByType', '_getRendererWrapper', '_getEditorClass', '_getEditorCache', '_getOwnerDocument', 'hot-renderer', 'hot-editor', 'children'];
398
- return Object.keys(this.props).filter(function (key) {
399
- return !_this.internalProps.includes(key);
400
- }).reduce(function (obj, key) {
401
- obj[key] = _this.props[key];
402
- return obj;
403
- }, {});
404
- }
405
- /**
406
- * Get the editor element for the current column.
407
- *
408
- * @returns {React.ReactElement} React editor component element.
409
- */
410
- }, {
411
- key: "getLocalEditorElement",
412
- value: function getLocalEditorElement() {
413
- return getExtendedEditorElement(this.props.children, this.props._getEditorCache(), this.props._columnIndex);
414
- }
415
- /**
416
- * Create the column settings based on the data provided to the `HotColumn` component and it's child components.
417
- */
418
- }, {
419
- key: "createColumnSettings",
420
- value: function createColumnSettings() {
421
- var rendererElement = this.props._getChildElementByType(this.props.children, 'hot-renderer');
422
- var editorElement = this.getLocalEditorElement();
423
- this.columnSettings = SettingsMapper.getSettings(this.getSettingsProps());
424
- if (rendererElement !== null) {
425
- this.columnSettings.renderer = this.props._getRendererWrapper(rendererElement);
426
- this.props._componentRendererColumns.set(this.props._columnIndex, true);
427
- }
428
- if (editorElement !== null) {
429
- this.columnSettings.editor = this.props._getEditorClass(editorElement, this.props._columnIndex);
419
+ var HotTableContext = React__default["default"].createContext(undefined);
420
+ var HotTableContextProvider = function HotTableContextProvider(_ref) {
421
+ var children = _ref.children;
422
+ var columnsSettings = React__default["default"].useRef([]);
423
+ var setHotColumnSettings = React__default["default"].useCallback(function (columnSettings, columnIndex) {
424
+ columnsSettings.current[columnIndex] = columnSettings;
425
+ }, []);
426
+ var componentRendererColumns = React__default["default"].useRef(new Map());
427
+ var renderedCellCache = React__default["default"].useRef(new Map());
428
+ var clearRenderedCellCache = React__default["default"].useCallback(function () {
429
+ return renderedCellCache.current.clear();
430
+ }, []);
431
+ var portalCache = React__default["default"].useRef(new Map());
432
+ var clearPortalCache = React__default["default"].useCallback(function () {
433
+ return portalCache.current.clear();
434
+ }, []);
435
+ var portalContainerCache = React__default["default"].useRef(new Map());
436
+ var getRendererWrapper = React__default["default"].useCallback(function (Renderer) {
437
+ return function __internalRenderer(instance, TD, row, col, prop, value, cellProperties) {
438
+ var key = "".concat(row, "-").concat(col);
439
+ // Handsontable.Core type is missing guid
440
+ var instanceGuid = instance.guid;
441
+ var portalContainerKey = "".concat(instanceGuid, "-").concat(key);
442
+ var portalKey = "".concat(key, "-").concat(instanceGuid);
443
+ if (renderedCellCache.current.has(key)) {
444
+ TD.innerHTML = renderedCellCache.current.get(key).innerHTML;
445
+ }
446
+ if (TD && !TD.getAttribute('ghost-table')) {
447
+ var cachedPortal = portalCache.current.get(portalKey);
448
+ var cachedPortalContainer = portalContainerCache.current.get(portalContainerKey);
449
+ while (TD.firstChild) {
450
+ TD.removeChild(TD.firstChild);
451
+ }
452
+ // if portal already exists, do not recreate
453
+ if (cachedPortal && cachedPortalContainer) {
454
+ TD.appendChild(cachedPortalContainer);
455
+ } else {
456
+ var rendererElement = React__default["default"].createElement(Renderer, {
457
+ instance: instance,
458
+ TD: TD,
459
+ row: row,
460
+ col: col,
461
+ prop: prop,
462
+ value: value,
463
+ cellProperties: cellProperties
464
+ });
465
+ var _createPortal = createPortal(rendererElement, TD.ownerDocument, portalKey, cachedPortalContainer),
466
+ portal = _createPortal.portal,
467
+ portalContainer = _createPortal.portalContainer;
468
+ portalContainerCache.current.set(portalContainerKey, portalContainer);
469
+ TD.appendChild(portalContainer);
470
+ portalCache.current.set(portalKey, portal);
471
+ }
430
472
  }
431
- }
432
- /**
433
- * Emit the column settings to the parent using a prop passed from the parent.
434
- */
435
- }, {
436
- key: "emitColumnSettings",
437
- value: function emitColumnSettings() {
438
- this.props._emitColumnSettings(this.columnSettings, this.props._columnIndex);
439
- }
440
- /*
441
- ---------------------------------------
442
- ------- React lifecycle methods -------
443
- ---------------------------------------
444
- */
445
- /**
446
- * Logic performed after the mounting of the HotColumn component.
447
- */
448
- }, {
449
- key: "componentDidMount",
450
- value: function componentDidMount() {
451
- this.createColumnSettings();
452
- this.emitColumnSettings();
453
- }
473
+ renderedCellCache.current.set("".concat(row, "-").concat(col), TD);
474
+ return TD;
475
+ };
476
+ }, []);
477
+ var renderersPortalManager = React__default["default"].useRef(function () {
478
+ return undefined;
479
+ });
480
+ var setRenderersPortalManagerRef = React__default["default"].useCallback(function (pmComponent) {
481
+ renderersPortalManager.current = pmComponent;
482
+ }, []);
483
+ var pushCellPortalsIntoPortalManager = React__default["default"].useCallback(function () {
484
+ renderersPortalManager.current(_toConsumableArray(portalCache.current.values()));
485
+ }, []);
486
+ var contextImpl = React__default["default"].useMemo(function () {
487
+ return {
488
+ componentRendererColumns: componentRendererColumns.current,
489
+ columnsSettings: columnsSettings.current,
490
+ emitColumnSettings: setHotColumnSettings,
491
+ getRendererWrapper: getRendererWrapper,
492
+ clearPortalCache: clearPortalCache,
493
+ clearRenderedCellCache: clearRenderedCellCache,
494
+ setRenderersPortalManagerRef: setRenderersPortalManagerRef,
495
+ pushCellPortalsIntoPortalManager: pushCellPortalsIntoPortalManager
496
+ };
497
+ }, [setHotColumnSettings, getRendererWrapper, clearRenderedCellCache, setRenderersPortalManagerRef, pushCellPortalsIntoPortalManager]);
498
+ return React__default["default"].createElement(HotTableContext.Provider, {
499
+ value: contextImpl
500
+ }, children);
501
+ };
502
+ /**
503
+ * Exposes the table context object to components
504
+ *
505
+ * @returns HotTableContext
506
+ */
507
+ function useHotTableContext() {
508
+ return React__default["default"].useContext(HotTableContext);
509
+ }
510
+
511
+ var HotColumnContext = React__default["default"].createContext(undefined);
512
+ var HotColumnContextProvider = function HotColumnContextProvider(_ref) {
513
+ var columnIndex = _ref.columnIndex,
514
+ getOwnerDocument = _ref.getOwnerDocument,
515
+ children = _ref.children;
516
+ var contextImpl = React__default["default"].useMemo(function () {
517
+ return {
518
+ columnIndex: columnIndex,
519
+ getOwnerDocument: getOwnerDocument
520
+ };
521
+ }, [columnIndex, getOwnerDocument]);
522
+ return React__default["default"].createElement(HotColumnContext.Provider, {
523
+ value: contextImpl
524
+ }, children);
525
+ };
526
+ var useHotColumnContext = function useHotColumnContext() {
527
+ return React__default["default"].useContext(HotColumnContext);
528
+ };
529
+
530
+ var AbstractMethods = ["close", "focus", "open"];
531
+ var ExcludedMethods = ["getValue", "setValue"];
532
+ var MethodsMap = {
533
+ open: "onOpen",
534
+ close: "onClose",
535
+ prepare: "onPrepare",
536
+ focus: "onFocus"
537
+ };
538
+ /**
539
+ * Create a class to be passed to the Handsontable's settings.
540
+ *
541
+ * @param {React.RefObject<HotEditorHooks>} hooksRef Reference to component-based editor overridden hooks object.
542
+ * @param {React.RefObject} instanceRef Reference to Handsontable-native custom editor class instance.
543
+ * @returns {Function} A class to be passed to the Handsontable editor settings.
544
+ */
545
+ function makeEditorClass(hooksRef, instanceRef) {
546
+ return /*#__PURE__*/function (_Handsontable$editors) {
547
+ function CustomEditor(hotInstance) {
548
+ var _this;
549
+ _classCallCheck(this, CustomEditor);
550
+ _this = _callSuper(this, CustomEditor, [hotInstance]);
551
+ instanceRef.current = _this;
552
+ Object.getOwnPropertyNames(Handsontable__default["default"].editors.BaseEditor.prototype).forEach(function (propName) {
553
+ if (propName === "constructor" || ExcludedMethods.includes(propName)) {
554
+ return;
555
+ }
556
+ var baseMethod = Handsontable__default["default"].editors.BaseEditor.prototype[propName];
557
+ CustomEditor.prototype[propName] = function () {
558
+ var _hooksRef$current;
559
+ var result;
560
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
561
+ args[_key] = arguments[_key];
562
+ }
563
+ if (!AbstractMethods.includes(propName)) {
564
+ result = baseMethod.call.apply(baseMethod, [this].concat(args)); // call super
565
+ }
566
+ if (MethodsMap[propName] && (_hooksRef$current = hooksRef.current) !== null && _hooksRef$current !== void 0 && _hooksRef$current[MethodsMap[propName]]) {
567
+ var _hooksRef$current$Met;
568
+ result = (_hooksRef$current$Met = hooksRef.current[MethodsMap[propName]]).call.apply(_hooksRef$current$Met, [this].concat(args));
569
+ }
570
+ return result;
571
+ }.bind(_this);
572
+ });
573
+ return _this;
574
+ }
575
+ _inherits(CustomEditor, _Handsontable$editors);
576
+ return _createClass(CustomEditor, [{
577
+ key: "focus",
578
+ value: function focus() {}
579
+ }, {
580
+ key: "getValue",
581
+ value: function getValue() {
582
+ return this.value;
583
+ }
584
+ }, {
585
+ key: "setValue",
586
+ value: function setValue(newValue) {
587
+ this.value = newValue;
588
+ }
589
+ }, {
590
+ key: "open",
591
+ value: function open() {}
592
+ }, {
593
+ key: "close",
594
+ value: function close() {}
595
+ }]);
596
+ }(Handsontable__default["default"].editors.BaseEditor);
597
+ }
598
+ /**
599
+ * Context to provide Handsontable-native custom editor class instance to overridden hooks object.
600
+ */
601
+ var EditorContext = React__default["default"].createContext(undefined);
602
+ /**
603
+ * Provider of the context that exposes Handsontable-native editor instance and passes hooks object
604
+ * for custom editor components.
605
+ *
606
+ * @param {React.Ref} hooksRef Reference for component-based editor overridden hooks object.
607
+ * @param {React.RefObject} hotCustomEditorInstanceRef Reference to Handsontable-native editor instance.
608
+ */
609
+ var EditorContextProvider = function EditorContextProvider(_ref) {
610
+ var hooksRef = _ref.hooksRef,
611
+ hotCustomEditorInstanceRef = _ref.hotCustomEditorInstanceRef,
612
+ children = _ref.children;
613
+ return React__default["default"].createElement(EditorContext.Provider, {
614
+ value: {
615
+ hooksRef: hooksRef,
616
+ hotCustomEditorInstanceRef: hotCustomEditorInstanceRef
617
+ }
618
+ }, children);
619
+ };
620
+ /**
621
+ * Hook that allows encapsulating custom behaviours of component-based editor by customizing passed ref with overridden hooks object.
622
+ *
623
+ * @param {HotEditorHooks} overriddenHooks Overrides specific for the custom editor.
624
+ * @param {React.DependencyList} deps Overridden hooks object React dependency list.
625
+ * @returns {UseHotEditorImpl} Editor API methods
626
+ */
627
+ function useHotEditor(overriddenHooks, deps) {
628
+ var _React$useContext = React__default["default"].useContext(EditorContext),
629
+ hooksRef = _React$useContext.hooksRef,
630
+ hotCustomEditorInstanceRef = _React$useContext.hotCustomEditorInstanceRef;
631
+ var _React$useState = React__default["default"].useState(0),
632
+ _React$useState2 = _slicedToArray(_React$useState, 2),
633
+ rerenderTrigger = _React$useState2[0],
634
+ setRerenderTrigger = _React$useState2[1];
635
+ var _React$useState3 = React__default["default"].useState(),
636
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
637
+ editorValue = _React$useState4[0],
638
+ setEditorValue = _React$useState4[1];
639
+ // return a deferred value that allows for optimizing performance by delaying the update of a value until the next render.
640
+ var deferredValue = React.useDeferredValue(editorValue);
641
+ React__default["default"].useImperativeHandle(hooksRef, function () {
642
+ return _objectSpread2(_objectSpread2({}, overriddenHooks), {}, {
643
+ onOpen: function onOpen() {
644
+ var _hotCustomEditorInsta, _overriddenHooks$onOp;
645
+ setEditorValue((_hotCustomEditorInsta = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta === void 0 ? void 0 : _hotCustomEditorInsta.getValue());
646
+ overriddenHooks === null || overriddenHooks === void 0 || (_overriddenHooks$onOp = overriddenHooks.onOpen) === null || _overriddenHooks$onOp === void 0 || _overriddenHooks$onOp.call(overriddenHooks);
647
+ setRerenderTrigger(function (t) {
648
+ return t + 1;
649
+ });
650
+ }
651
+ });
652
+ }, deps);
653
+ return React__default["default"].useMemo(function () {
654
+ return {
655
+ get value() {
656
+ return deferredValue;
657
+ },
658
+ setValue: function setValue(newValue) {
659
+ var _hotCustomEditorInsta2;
660
+ setEditorValue(newValue);
661
+ (_hotCustomEditorInsta2 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta2 === void 0 || _hotCustomEditorInsta2.setValue(newValue);
662
+ },
663
+ get isOpen() {
664
+ var _hotCustomEditorInsta3, _hotCustomEditorInsta4;
665
+ return (_hotCustomEditorInsta3 = (_hotCustomEditorInsta4 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta4 === void 0 ? void 0 : _hotCustomEditorInsta4.isOpened()) !== null && _hotCustomEditorInsta3 !== void 0 ? _hotCustomEditorInsta3 : false;
666
+ },
667
+ finishEditing: function finishEditing() {
668
+ var _hotCustomEditorInsta5;
669
+ (_hotCustomEditorInsta5 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta5 === void 0 || _hotCustomEditorInsta5.finishEditing();
670
+ },
671
+ get row() {
672
+ var _hotCustomEditorInsta6;
673
+ return (_hotCustomEditorInsta6 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta6 === void 0 ? void 0 : _hotCustomEditorInsta6.row;
674
+ },
675
+ get col() {
676
+ var _hotCustomEditorInsta7;
677
+ return (_hotCustomEditorInsta7 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta7 === void 0 ? void 0 : _hotCustomEditorInsta7.col;
678
+ }
679
+ };
680
+ }, [rerenderTrigger, hotCustomEditorInstanceRef, deferredValue]);
681
+ }
682
+
683
+ var isHotColumn = function isHotColumn(childNode) {
684
+ return childNode.type === HotColumn;
685
+ };
686
+ var internalProps = ['_columnIndex', '_getOwnerDocument', 'children'];
687
+ var HotColumn = function HotColumn(props) {
688
+ var _useHotTableContext = useHotTableContext(),
689
+ componentRendererColumns = _useHotTableContext.componentRendererColumns,
690
+ emitColumnSettings = _useHotTableContext.emitColumnSettings,
691
+ getRendererWrapper = _useHotTableContext.getRendererWrapper;
692
+ var _useHotColumnContext = useHotColumnContext(),
693
+ columnIndex = _useHotColumnContext.columnIndex,
694
+ getOwnerDocument = _useHotColumnContext.getOwnerDocument;
695
+ /**
696
+ * Reference to component-based editor overridden hooks object.
697
+ */
698
+ var localEditorHooksRef = React__default["default"].useRef(null);
699
+ /**
700
+ * Reference to HOT-native custom editor class instance.
701
+ */
702
+ var localEditorClassInstance = React__default["default"].useRef(null);
703
+ /**
704
+ * Logic performed after mounting & updating of the HotColumn component.
705
+ */
706
+ React__default["default"].useEffect(function () {
454
707
  /**
455
- * Logic performed after the updating of the HotColumn component.
708
+ * Filter out all the internal properties and return an object with just the Handsontable-related props.
709
+ *
710
+ * @returns {Object}
456
711
  */
457
- }, {
458
- key: "componentDidUpdate",
459
- value: function componentDidUpdate() {
460
- this.createColumnSettings();
461
- this.emitColumnSettings();
462
- }
712
+ var getSettingsProps = function getSettingsProps() {
713
+ return Object.keys(props).filter(function (key) {
714
+ return !internalProps.includes(key);
715
+ }).reduce(function (obj, key) {
716
+ obj[key] = props[key];
717
+ return obj;
718
+ }, {});
719
+ };
463
720
  /**
464
- * Render the portals of the editors, if there are any.
465
- *
466
- * @returns {React.ReactElement}
721
+ * Create the column settings based on the data provided to the `HotColumn` component and its child components.
467
722
  */
468
- }, {
469
- key: "render",
470
- value: function render() {
471
- var ownerDocument = this.props._getOwnerDocument();
472
- var editorPortal = createEditorPortal(ownerDocument, this.getLocalEditorElement());
473
- return React__default["default"].createElement(React__default["default"].Fragment, null, editorPortal);
723
+ var createColumnSettings = function createColumnSettings() {
724
+ var columnSettings = SettingsMapper.getSettings(getSettingsProps());
725
+ if (props.renderer) {
726
+ columnSettings.renderer = getRendererWrapper(props.renderer);
727
+ componentRendererColumns.set(columnIndex, true);
728
+ } else if (props.hotRenderer) {
729
+ columnSettings.renderer = props.hotRenderer;
730
+ }
731
+ if (props.editor) {
732
+ columnSettings.editor = makeEditorClass(localEditorHooksRef, localEditorClassInstance);
733
+ } else if (props.hotEditor) {
734
+ columnSettings.editor = props.hotEditor;
735
+ }
736
+ return columnSettings;
737
+ };
738
+ var columnSettings = createColumnSettings();
739
+ emitColumnSettings(columnSettings, columnIndex);
740
+ if (!displayObsoleteRenderersEditorsWarning(props.children)) {
741
+ displayAnyChildrenWarning(props.children);
474
742
  }
475
- }]);
476
- }(React__default["default"].Component);
743
+ });
744
+ var editorPortal = createEditorPortal(getOwnerDocument(), props.editor);
745
+ /**
746
+ * Render the portals of the editors, if there are any.
747
+ *
748
+ * @returns {React.ReactElement}
749
+ */
750
+ return React__default["default"].createElement(EditorContextProvider, {
751
+ hooksRef: localEditorHooksRef,
752
+ hotCustomEditorInstanceRef: localEditorClassInstance
753
+ }, editorPortal);
754
+ };
755
+
756
+ var version="0.0.0-next-0306a1a-20240826";
477
757
 
478
758
  /**
479
- * Component class used to manage the renderer component portals.
759
+ * Component used to manage the renderer component portals.
480
760
  */
481
- var RenderersPortalManager = /*#__PURE__*/function (_React$Component) {
482
- function RenderersPortalManager() {
483
- var _this;
484
- _classCallCheck(this, RenderersPortalManager);
485
- _this = _callSuper(this, RenderersPortalManager, arguments);
486
- _this.state = {
487
- portals: []
488
- };
489
- return _this;
490
- }
491
- _inherits(RenderersPortalManager, _React$Component);
492
- return _createClass(RenderersPortalManager, [{
493
- key: "render",
494
- value: function render() {
495
- return React__default["default"].createElement(React__default["default"].Fragment, null, this.state.portals);
496
- }
497
- }]);
498
- }(React__default["default"].Component);
499
-
500
- var version="0.0.0-next-eaf150e-20240823";
761
+ var RenderersPortalManager = React__default["default"].forwardRef(function (_, ref) {
762
+ var _React$useState = React__default["default"].useState([]),
763
+ _React$useState2 = _slicedToArray(_React$useState, 2),
764
+ portals = _React$useState2[0],
765
+ setPortals = _React$useState2[1];
766
+ React__default["default"].useImperativeHandle(ref, function () {
767
+ return setPortals;
768
+ });
769
+ return React__default["default"].createElement(React__default["default"].Fragment, null, portals);
770
+ });
501
771
 
502
772
  function getDefaultExportFromCjs (x) {
503
773
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -1622,837 +1892,218 @@ if (process.env.NODE_ENV !== 'production') {
1622
1892
  var propTypesExports = propTypes.exports;
1623
1893
  var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
1624
1894
 
1625
- /**
1626
- * A Handsontable-ReactJS wrapper.
1627
- *
1628
- * To implement, use the `HotTable` tag with properties corresponding to Handsontable options.
1629
- * For example:
1630
- *
1631
- * ```js
1632
- * <HotTable id="hot" data={dataObject} contextMenu={true} colHeaders={true} width={600} height={300} stretchH="all" />
1633
- *
1634
- * // is analogous to
1635
- * let hot = new Handsontable(document.getElementById('hot'), {
1636
- * data: dataObject,
1637
- * contextMenu: true,
1638
- * colHeaders: true,
1639
- * width: 600
1640
- * height: 300
1641
- * });
1642
- *
1643
- * ```
1644
- *
1645
- * @class HotTableCB
1646
- */
1647
- var HotTableClass = /*#__PURE__*/function (_React$Component) {
1648
- function HotTableClass() {
1649
- var _this;
1650
- _classCallCheck(this, HotTableClass);
1651
- _this = _callSuper(this, HotTableClass, arguments);
1652
- /**
1653
- * The `id` of the main Handsontable DOM element.
1654
- *
1655
- * @type {String}
1656
- */
1657
- _this.id = null;
1658
- /**
1659
- * Reference to the Handsontable instance.
1660
- *
1661
- * @private
1662
- * @type {Object}
1663
- */
1664
- _this.__hotInstance = null;
1665
- /**
1666
- * Reference to the main Handsontable DOM element.
1667
- *
1668
- * @type {HTMLElement}
1669
- */
1670
- _this.hotElementRef = null;
1671
- /**
1672
- * Array of object containing the column settings.
1673
- *
1674
- * @type {Array}
1675
- */
1676
- _this.columnSettings = [];
1677
- /**
1678
- * Component used to manage the renderer portals.
1679
- *
1680
- * @type {React.Component}
1681
- */
1682
- _this.renderersPortalManager = null;
1683
- /**
1684
- * Map that stores React portals.
1685
- * @type {Map<string, React.ReactPortal>}
1686
- */
1687
- _this.portalCache = new Map();
1688
- /**
1689
- * Portal Container Cache
1690
- *
1691
- * @private
1692
- * @type {Map}
1693
- */
1694
- _this.portalContainerCache = new Map();
1695
- /**
1696
- * The rendered cells cache.
1697
- *
1698
- * @private
1699
- * @type {Map}
1700
- */
1701
- _this.renderedCellCache = new Map();
1702
- /**
1703
- * Editor cache.
1704
- *
1705
- * @private
1706
- * @type {Map}
1707
- */
1708
- _this.editorCache = new Map();
1709
- /**
1710
- * Map with column indexes (or a string = 'global') as keys, and booleans as values. Each key represents a component-based editor
1711
- * declared for the used column index, or a global one, if the key is the `global` string.
1712
- *
1713
- * @private
1714
- * @type {Map}
1715
- */
1716
- _this.componentRendererColumns = new Map();
1717
- return _this;
1718
- }
1895
+ var HotTableInner = React__default["default"].forwardRef(function (props, ref) {
1719
1896
  /**
1720
- * Package version getter.
1721
- *
1722
- * @returns The version number of the package.
1897
+ * Reference to the Handsontable instance.
1723
1898
  */
1724
- _inherits(HotTableClass, _React$Component);
1725
- return _createClass(HotTableClass, [{
1726
- key: "hotInstance",
1727
- get:
1728
- /**
1729
- * Getter for the property storing the Handsontable instance.
1730
- */
1731
- function get() {
1732
- if (!this.__hotInstance || this.__hotInstance && !this.__hotInstance.isDestroyed) {
1733
- // Will return the Handsontable instance or `null` if it's not yet been created.
1734
- return this.__hotInstance;
1735
- } else {
1736
- console.warn(HOT_DESTROYED_WARNING);
1737
- return null;
1738
- }
1739
- }
1740
- /**
1741
- * Returns `true` if the `hotInstance` exists, but was destroyed.
1742
- *
1743
- * @private
1744
- * @returns {boolean}
1745
- */,
1746
- set:
1747
- /**
1748
- * Setter for the property storing the Handsontable instance.
1749
- * @param {Handsontable} hotInstance The Handsontable instance.
1750
- */
1751
- function set(hotInstance) {
1752
- this.__hotInstance = hotInstance;
1753
- }
1754
- /**
1755
- * Get Portal Container Cache
1756
- *
1757
- * @returns {Map}
1758
- */
1759
- }, {
1760
- key: "_isHotInstanceDestroyed",
1761
- value: function _isHotInstanceDestroyed() {
1762
- return this.__hotInstance && this.__hotInstance.isDestroyed;
1763
- }
1764
- }, {
1765
- key: "getPortalContainerCache",
1766
- value: function getPortalContainerCache() {
1767
- return this.portalContainerCache;
1768
- }
1769
- /**
1770
- * Get the rendered table cell cache.
1771
- *
1772
- * @returns {Map}
1773
- */
1774
- }, {
1775
- key: "getRenderedCellCache",
1776
- value: function getRenderedCellCache() {
1777
- return this.renderedCellCache;
1778
- }
1779
- /**
1780
- * Get the editor cache and return it.
1781
- *
1782
- * @returns {Map}
1783
- */
1784
- }, {
1785
- key: "getEditorCache",
1786
- value: function getEditorCache() {
1787
- return this.editorCache;
1788
- }
1789
- /**
1790
- * Clear both the editor and the renderer cache.
1791
- */
1792
- }, {
1793
- key: "clearCache",
1794
- value: function clearCache() {
1795
- this.getRenderedCellCache().clear();
1796
- this.componentRendererColumns.clear();
1797
- }
1798
- /**
1799
- * Get the `Document` object corresponding to the main component element.
1800
- *
1801
- * @returns The `Document` object used by the component.
1802
- */
1803
- }, {
1804
- key: "getOwnerDocument",
1805
- value: function getOwnerDocument() {
1806
- if (isCSR()) {
1807
- return this.hotElementRef ? this.hotElementRef.ownerDocument : document;
1808
- }
1899
+ var __hotInstance = React__default["default"].useRef(null);
1900
+ /**
1901
+ * Reference to the main Handsontable DOM element.
1902
+ */
1903
+ var hotElementRef = React__default["default"].useRef(null);
1904
+ /**
1905
+ * Reference to component-based editor overridden hooks object.
1906
+ */
1907
+ var globalEditorHooksRef = React__default["default"].useRef(null);
1908
+ /**
1909
+ * Reference to HOT-native custom editor class instance.
1910
+ */
1911
+ var globalEditorClassInstance = React__default["default"].useRef(null);
1912
+ /**
1913
+ * HotTable context exposing helper functions.
1914
+ */
1915
+ var context = useHotTableContext();
1916
+ /**
1917
+ * Getter for the property storing the Handsontable instance.
1918
+ */
1919
+ var getHotInstance = React__default["default"].useCallback(function () {
1920
+ if (!__hotInstance.current || !__hotInstance.current.isDestroyed) {
1921
+ // Will return the Handsontable instance or `null` if it's not yet been created.
1922
+ return __hotInstance.current;
1923
+ } else {
1924
+ console.warn(HOT_DESTROYED_WARNING);
1809
1925
  return null;
1810
1926
  }
1811
- /**
1812
- * Set the reference to the main Handsontable DOM element.
1813
- *
1814
- * @param {HTMLElement} element The main Handsontable DOM element.
1815
- */
1816
- }, {
1817
- key: "setHotElementRef",
1818
- value: function setHotElementRef(element) {
1819
- this.hotElementRef = element;
1820
- }
1821
- /**
1822
- * Return a renderer wrapper function for the provided renderer component.
1823
- *
1824
- * @param {React.ReactElement} rendererElement React renderer component.
1825
- * @returns {Handsontable.renderers.Base} The Handsontable rendering function.
1826
- */
1827
- }, {
1828
- key: "getRendererWrapper",
1829
- value: function getRendererWrapper(rendererElement) {
1830
- var hotTableComponent = this;
1831
- return function __internalRenderer(instance, TD, row, col, prop, value, cellProperties) {
1832
- var renderedCellCache = hotTableComponent.getRenderedCellCache();
1833
- var portalContainerCache = hotTableComponent.getPortalContainerCache();
1834
- var key = "".concat(row, "-").concat(col);
1835
- // Handsontable.Core type is missing guid
1836
- var instanceGuid = instance.guid;
1837
- var portalContainerKey = "".concat(instanceGuid, "-").concat(key);
1838
- var portalKey = "".concat(key, "-").concat(instanceGuid);
1839
- if (renderedCellCache.has(key)) {
1840
- TD.innerHTML = renderedCellCache.get(key).innerHTML;
1841
- }
1842
- if (TD && !TD.getAttribute('ghost-table')) {
1843
- var cachedPortal = hotTableComponent.portalCache.get(portalKey);
1844
- var cachedPortalContainer = portalContainerCache.get(portalContainerKey);
1845
- while (TD.firstChild) {
1846
- TD.removeChild(TD.firstChild);
1847
- }
1848
- // if portal already exists, do not recreate
1849
- if (cachedPortal && cachedPortalContainer) {
1850
- TD.appendChild(cachedPortalContainer);
1851
- } else {
1852
- var _createPortal = createPortal(rendererElement, {
1853
- TD: TD,
1854
- row: row,
1855
- col: col,
1856
- prop: prop,
1857
- value: value,
1858
- cellProperties: cellProperties,
1859
- isRenderer: true
1860
- }, TD.ownerDocument, portalKey, cachedPortalContainer),
1861
- portal = _createPortal.portal,
1862
- portalContainer = _createPortal.portalContainer;
1863
- portalContainerCache.set(portalContainerKey, portalContainer);
1864
- TD.appendChild(portalContainer);
1865
- hotTableComponent.portalCache.set(portalKey, portal);
1866
- }
1867
- }
1868
- renderedCellCache.set(key, TD);
1869
- return TD;
1870
- };
1871
- }
1872
- /**
1873
- * Create a fresh class to be used as an editor, based on the provided editor React element.
1874
- *
1875
- * @param {React.ReactElement} editorElement React editor component.
1876
- * @param {string|number} [editorColumnScope] The editor scope (column index or a 'global' string). Defaults to
1877
- * 'global'.
1878
- * @returns {Function} A class to be passed to the Handsontable editor settings.
1879
- */
1880
- }, {
1881
- key: "getEditorClass",
1882
- value: function getEditorClass(editorElement) {
1883
- var _this$getEditorCache$;
1884
- var editorColumnScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GLOBAL_EDITOR_SCOPE;
1885
- var editorClass = getOriginalEditorClass(editorElement);
1886
- var cachedComponent = (_this$getEditorCache$ = this.getEditorCache().get(editorClass)) === null || _this$getEditorCache$ === void 0 ? void 0 : _this$getEditorCache$.get(editorColumnScope);
1887
- return this.makeEditorClass(cachedComponent);
1888
- }
1889
- /**
1890
- * Create a class to be passed to the Handsontable's settings.
1891
- *
1892
- * @param {React.ReactElement} editorComponent React editor component.
1893
- * @returns {Function} A class to be passed to the Handsontable editor settings.
1894
- */
1895
- }, {
1896
- key: "makeEditorClass",
1897
- value: function makeEditorClass(editorComponent) {
1898
- var customEditorClass = /*#__PURE__*/function (_Handsontable$editors) {
1899
- function CustomEditor(hotInstance) {
1900
- var _this2;
1901
- _classCallCheck(this, CustomEditor);
1902
- _this2 = _callSuper(this, CustomEditor, [hotInstance]);
1903
- editorComponent.hotCustomEditorInstance = _this2;
1904
- _this2.editorComponent = editorComponent;
1905
- return _this2;
1906
- }
1907
- _inherits(CustomEditor, _Handsontable$editors);
1908
- return _createClass(CustomEditor, [{
1909
- key: "focus",
1910
- value: function focus() {}
1911
- }, {
1912
- key: "getValue",
1913
- value: function getValue() {}
1914
- }, {
1915
- key: "setValue",
1916
- value: function setValue() {}
1917
- }, {
1918
- key: "open",
1919
- value: function open() {}
1920
- }, {
1921
- key: "close",
1922
- value: function close() {}
1923
- }]);
1924
- }(Handsontable__default["default"].editors.BaseEditor);
1925
- // Fill with the rest of the BaseEditor methods
1926
- Object.getOwnPropertyNames(Handsontable__default["default"].editors.BaseEditor.prototype).forEach(function (propName) {
1927
- if (propName === 'constructor') {
1928
- return;
1929
- }
1930
- customEditorClass.prototype[propName] = function () {
1931
- var _editorComponent$prop;
1932
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1933
- args[_key] = arguments[_key];
1934
- }
1935
- return (_editorComponent$prop = editorComponent[propName]).call.apply(_editorComponent$prop, [editorComponent].concat(args));
1936
- };
1937
- });
1938
- return customEditorClass;
1939
- }
1940
- /**
1941
- * Get the renderer element for the entire HotTable instance.
1942
- *
1943
- * @returns {React.ReactElement} React renderer component element.
1944
- */
1945
- }, {
1946
- key: "getGlobalRendererElement",
1947
- value: function getGlobalRendererElement() {
1948
- return getChildElementByType(this.props.children, 'hot-renderer');
1927
+ }, [__hotInstance]);
1928
+ /**
1929
+ * Clear both the editor and the renderer cache.
1930
+ */
1931
+ var clearCache = React__default["default"].useCallback(function () {
1932
+ context.clearRenderedCellCache();
1933
+ context.componentRendererColumns.clear();
1934
+ }, [context]);
1935
+ /**
1936
+ * Get the `Document` object corresponding to the main component element.
1937
+ *
1938
+ * @returns The `Document` object used by the component.
1939
+ */
1940
+ var getOwnerDocument = React__default["default"].useCallback(function () {
1941
+ if (isCSR()) {
1942
+ return hotElementRef.current ? hotElementRef.current.ownerDocument : document;
1949
1943
  }
1950
- /**
1951
- * Get the editor element for the entire HotTable instance.
1952
- *
1953
- * @param {React.ReactNode} [children] Children of the HotTable instance. Defaults to `this.props.children`.
1954
- * @returns {React.ReactElement} React editor component element.
1955
- */
1956
- }, {
1957
- key: "getGlobalEditorElement",
1958
- value: function getGlobalEditorElement() {
1959
- return getExtendedEditorElement(this.props.children, this.getEditorCache());
1944
+ return null;
1945
+ }, [hotElementRef]);
1946
+ /**
1947
+ * Create a new settings object containing the column settings and global editors and renderers.
1948
+ *
1949
+ * @returns {Handsontable.GridSettings} New global set of settings for Handsontable.
1950
+ */
1951
+ var createNewGlobalSettings = function createNewGlobalSettings() {
1952
+ var newSettings = SettingsMapper.getSettings(props);
1953
+ newSettings.columns = context.columnsSettings.length ? context.columnsSettings : newSettings.columns;
1954
+ if (props.renderer) {
1955
+ newSettings.renderer = context.getRendererWrapper(props.renderer);
1956
+ context.componentRendererColumns.set('global', true);
1957
+ } else {
1958
+ newSettings.renderer = props.hotRenderer || registry.getRenderer('text');
1960
1959
  }
1961
- /**
1962
- * Create a new settings object containing the column settings and global editors and renderers.
1963
- *
1964
- * @param {boolean} [init=false] `true` if called on Handsontable initialization.
1965
- * @param {HotTableProps} [prevProps] The previous properties object.
1966
- * @returns {Handsontable.GridSettings} New global set of settings for Handsontable.
1967
- */
1968
- }, {
1969
- key: "createNewGlobalSettings",
1970
- value: function createNewGlobalSettings() {
1971
- var _this$hotInstance;
1972
- var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
1973
- var prevProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1974
- var initOnlySettingKeys = !this._isHotInstanceDestroyed() ?
1975
- // Needed for React's double-rendering.
1976
- ((_this$hotInstance = this.hotInstance) === null || _this$hotInstance === void 0 || (_this$hotInstance = _this$hotInstance.getSettings()) === null || _this$hotInstance === void 0 ? void 0 : _this$hotInstance._initOnlySettings) || [] : [];
1977
- var newSettings = SettingsMapper.getSettings(this.props, {
1978
- prevProps: prevProps,
1979
- isInit: init,
1980
- initOnlySettingKeys: initOnlySettingKeys
1981
- });
1982
- var globalRendererNode = this.getGlobalRendererElement();
1983
- var globalEditorNode = this.getGlobalEditorElement();
1984
- newSettings.columns = this.columnSettings.length ? this.columnSettings : newSettings.columns;
1985
- if (globalEditorNode) {
1986
- newSettings.editor = this.getEditorClass(globalEditorNode, GLOBAL_EDITOR_SCOPE);
1987
- } else {
1988
- var _this$props$settings;
1989
- if (this.props.editor || (_this$props$settings = this.props.settings) !== null && _this$props$settings !== void 0 && _this$props$settings.editor) {
1990
- newSettings.editor = this.props.editor || this.props.settings.editor;
1991
- } else {
1992
- newSettings.editor = registry.getEditor('text');
1993
- }
1994
- }
1995
- if (globalRendererNode) {
1996
- newSettings.renderer = this.getRendererWrapper(globalRendererNode);
1997
- this.componentRendererColumns.set('global', true);
1998
- } else {
1999
- var _this$props$settings2;
2000
- if (this.props.renderer || (_this$props$settings2 = this.props.settings) !== null && _this$props$settings2 !== void 0 && _this$props$settings2.renderer) {
2001
- newSettings.renderer = this.props.renderer || this.props.settings.renderer;
2002
- } else {
2003
- newSettings.renderer = registry$1.getRenderer('text');
2004
- }
2005
- }
2006
- return newSettings;
1960
+ if (props.editor) {
1961
+ newSettings.editor = makeEditorClass(globalEditorHooksRef, globalEditorClassInstance);
1962
+ } else {
1963
+ newSettings.editor = props.hotEditor || registry$1.getEditor('text');
2007
1964
  }
2008
- /**
2009
- * Detect if `autoRowSize` or `autoColumnSize` is defined, and if so, throw an incompatibility warning.
2010
- *
2011
- * @param {Handsontable.GridSettings} newGlobalSettings New global settings passed as Handsontable config.
2012
- */
2013
- }, {
2014
- key: "displayAutoSizeWarning",
2015
- value: function displayAutoSizeWarning(newGlobalSettings) {
2016
- var _this$hotInstance$get, _this$hotInstance$get2;
2017
- if (this.hotInstance && ((_this$hotInstance$get = this.hotInstance.getPlugin('autoRowSize')) !== null && _this$hotInstance$get !== void 0 && _this$hotInstance$get.enabled || (_this$hotInstance$get2 = this.hotInstance.getPlugin('autoColumnSize')) !== null && _this$hotInstance$get2 !== void 0 && _this$hotInstance$get2.enabled)) {
2018
- if (this.componentRendererColumns.size > 0) {
2019
- warn(AUTOSIZE_WARNING);
2020
- }
1965
+ return newSettings;
1966
+ };
1967
+ /**
1968
+ * Detect if `autoRowSize` or `autoColumnSize` is defined, and if so, throw an incompatibility warning.
1969
+ */
1970
+ var displayAutoSizeWarning = function displayAutoSizeWarning(hotInstance) {
1971
+ var _hotInstance$getPlugi, _hotInstance$getPlugi2;
1972
+ if (hotInstance && ((_hotInstance$getPlugi = hotInstance.getPlugin('autoRowSize')) !== null && _hotInstance$getPlugi !== void 0 && _hotInstance$getPlugi.enabled || (_hotInstance$getPlugi2 = hotInstance.getPlugin('autoColumnSize')) !== null && _hotInstance$getPlugi2 !== void 0 && _hotInstance$getPlugi2.enabled)) {
1973
+ if (context.componentRendererColumns.size > 0) {
1974
+ warn(AUTOSIZE_WARNING);
2021
1975
  }
2022
1976
  }
2023
- /**
2024
- * Sets the column settings based on information received from HotColumn.
2025
- *
2026
- * @param {HotTableProps} columnSettings Column settings object.
2027
- * @param {Number} columnIndex Column index.
2028
- */
2029
- }, {
2030
- key: "setHotColumnSettings",
2031
- value: function setHotColumnSettings(columnSettings, columnIndex) {
2032
- this.columnSettings[columnIndex] = columnSettings;
2033
- }
1977
+ };
1978
+ /**
1979
+ * Initialize Handsontable after the component has mounted.
1980
+ */
1981
+ React__default["default"].useEffect(function () {
1982
+ var newGlobalSettings = createNewGlobalSettings();
1983
+ __hotInstance.current = new Handsontable__default["default"].Core(hotElementRef.current, newGlobalSettings);
2034
1984
  /**
2035
1985
  * Handsontable's `beforeViewRender` hook callback.
2036
1986
  */
2037
- }, {
2038
- key: "handsontableBeforeViewRender",
2039
- value: function handsontableBeforeViewRender() {
2040
- this.portalCache.clear();
2041
- this.getRenderedCellCache().clear();
2042
- }
1987
+ __hotInstance.current.addHook('beforeViewRender', function () {
1988
+ context.clearPortalCache();
1989
+ context.clearRenderedCellCache();
1990
+ });
2043
1991
  /**
2044
1992
  * Handsontable's `afterViewRender` hook callback.
2045
1993
  */
2046
- }, {
2047
- key: "handsontableAfterViewRender",
2048
- value: function handsontableAfterViewRender() {
2049
- this.renderersPortalManager.setState({
2050
- portals: _toConsumableArray(this.portalCache.values())
2051
- });
2052
- }
2053
- /**
2054
- * Call the `updateSettings` method for the Handsontable instance.
2055
- *
2056
- * @param {Object} newSettings The settings object.
2057
- */
2058
- }, {
2059
- key: "updateHot",
2060
- value: function updateHot(newSettings) {
2061
- if (this.hotInstance) {
2062
- this.hotInstance.updateSettings(newSettings, false);
2063
- }
2064
- }
2065
- /**
2066
- * Set the renderers portal manager ref.
2067
- *
2068
- * @param {React.ReactComponent} pmComponent The PortalManager component.
2069
- */
2070
- }, {
2071
- key: "setRenderersPortalManagerRef",
2072
- value: function setRenderersPortalManagerRef(pmComponent) {
2073
- this.renderersPortalManager = pmComponent;
2074
- }
2075
- /*
2076
- ---------------------------------------
2077
- ------- React lifecycle methods -------
2078
- ---------------------------------------
2079
- */
2080
- /**
2081
- * Initialize Handsontable after the component has mounted.
2082
- */
2083
- }, {
2084
- key: "componentDidMount",
2085
- value: function componentDidMount() {
2086
- var _this3 = this;
2087
- var newGlobalSettings = this.createNewGlobalSettings(true);
2088
- this.hotInstance = new Handsontable__default["default"].Core(this.hotElementRef, newGlobalSettings);
2089
- this.hotInstance.addHook('beforeViewRender', function () {
2090
- return _this3.handsontableBeforeViewRender();
2091
- });
2092
- this.hotInstance.addHook('afterViewRender', function () {
2093
- return _this3.handsontableAfterViewRender();
2094
- });
2095
- // `init` missing in Handsontable's type definitions.
2096
- this.hotInstance.init();
2097
- this.displayAutoSizeWarning(newGlobalSettings);
2098
- }
2099
- /**
2100
- * Logic performed after the component update.
2101
- */
2102
- }, {
2103
- key: "componentDidUpdate",
2104
- value: function componentDidUpdate(prevProps) {
2105
- this.clearCache();
2106
- var newGlobalSettings = this.createNewGlobalSettings(false, prevProps);
2107
- this.updateHot(newGlobalSettings);
2108
- this.displayAutoSizeWarning(newGlobalSettings);
1994
+ __hotInstance.current.addHook('afterViewRender', function () {
1995
+ context.pushCellPortalsIntoPortalManager();
1996
+ });
1997
+ __hotInstance.current.init();
1998
+ displayAutoSizeWarning(__hotInstance.current);
1999
+ if (!displayObsoleteRenderersEditorsWarning(props.children)) {
2000
+ displayChildrenOfTypeWarning(props.children, HotColumn);
2109
2001
  }
2110
2002
  /**
2111
2003
  * Destroy the Handsontable instance when the parent component unmounts.
2112
2004
  */
2113
- }, {
2114
- key: "componentWillUnmount",
2115
- value: function componentWillUnmount() {
2116
- this.clearCache();
2117
- if (this.hotInstance) {
2118
- this.hotInstance.destroy();
2005
+ return function () {
2006
+ var _getHotInstance;
2007
+ clearCache();
2008
+ (_getHotInstance = getHotInstance()) === null || _getHotInstance === void 0 || _getHotInstance.destroy();
2009
+ };
2010
+ }, []);
2011
+ /**
2012
+ * Logic performed after the component update.
2013
+ */
2014
+ useUpdateEffect(function () {
2015
+ clearCache();
2016
+ var hotInstance = getHotInstance();
2017
+ var newGlobalSettings = createNewGlobalSettings();
2018
+ hotInstance === null || hotInstance === void 0 || hotInstance.updateSettings(newGlobalSettings, false);
2019
+ displayAutoSizeWarning(hotInstance);
2020
+ displayObsoleteRenderersEditorsWarning(props.children);
2021
+ });
2022
+ /**
2023
+ * Interface exposed to parent components by HotTable instance via React ref
2024
+ */
2025
+ React__default["default"].useImperativeHandle(ref, function () {
2026
+ return {
2027
+ get hotElementRef() {
2028
+ return hotElementRef.current;
2029
+ },
2030
+ get hotInstance() {
2031
+ return getHotInstance();
2119
2032
  }
2120
- }
2121
- /**
2122
- * Render the component.
2123
- */
2124
- }, {
2125
- key: "render",
2126
- value: function render() {
2127
- var _this4 = this;
2128
- var isHotColumn = function isHotColumn(childNode) {
2129
- return childNode.type === HotColumn;
2130
- };
2131
- var children = React__default["default"].Children.toArray(this.props.children);
2132
- // clone the HotColumn nodes and extend them with the callbacks
2133
- var hotColumnClones = children.filter(function (childNode) {
2134
- return isHotColumn(childNode);
2135
- }).map(function (childNode, columnIndex) {
2136
- return React__default["default"].cloneElement(childNode, {
2137
- _componentRendererColumns: _this4.componentRendererColumns,
2138
- _emitColumnSettings: _this4.setHotColumnSettings.bind(_this4),
2139
- _columnIndex: columnIndex,
2140
- _getChildElementByType: getChildElementByType.bind(_this4),
2141
- _getRendererWrapper: _this4.getRendererWrapper.bind(_this4),
2142
- _getEditorClass: _this4.getEditorClass.bind(_this4),
2143
- _getOwnerDocument: _this4.getOwnerDocument.bind(_this4),
2144
- _getEditorCache: _this4.getEditorCache.bind(_this4),
2145
- children: childNode.props.children
2146
- });
2147
- });
2148
- var containerProps = getContainerAttributesProps(this.props);
2149
- var editorPortal = createEditorPortal(this.getOwnerDocument(), this.getGlobalEditorElement());
2150
- return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", Object.assign({
2151
- ref: this.setHotElementRef.bind(this)
2152
- }, containerProps), hotColumnClones), React__default["default"].createElement(RenderersPortalManager, {
2153
- ref: this.setRenderersPortalManagerRef.bind(this)
2154
- }), editorPortal);
2155
- }
2156
- }], [{
2157
- key: "version",
2158
- get: function get() {
2159
- return version;
2160
- }
2161
- }]);
2162
- }(React__default["default"].Component);
2033
+ };
2034
+ });
2035
+ /**
2036
+ * Render the component.
2037
+ */
2038
+ var hotColumnWrapped = React__default["default"].Children.toArray(props.children).filter(isHotColumn).map(function (childNode, columnIndex) {
2039
+ return React__default["default"].createElement(HotColumnContextProvider, {
2040
+ columnIndex: columnIndex,
2041
+ getOwnerDocument: getOwnerDocument,
2042
+ key: columnIndex
2043
+ }, childNode);
2044
+ });
2045
+ var containerProps = getContainerAttributesProps(props);
2046
+ var editorPortal = createEditorPortal(getOwnerDocument(), props.editor);
2047
+ return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement("div", Object.assign({
2048
+ ref: hotElementRef
2049
+ }, containerProps), hotColumnWrapped), React__default["default"].createElement(RenderersPortalManager, {
2050
+ ref: context.setRenderersPortalManagerRef
2051
+ }), React__default["default"].createElement(EditorContextProvider, {
2052
+ hooksRef: globalEditorHooksRef,
2053
+ hotCustomEditorInstanceRef: globalEditorClassInstance
2054
+ }, editorPortal));
2055
+ });
2163
2056
  /**
2164
2057
  * Prop types to be checked at runtime.
2165
2058
  */
2166
- HotTableClass.propTypes = {
2059
+ HotTableInner.propTypes = {
2167
2060
  style: PropTypes.object,
2168
2061
  id: PropTypes.string,
2169
2062
  className: PropTypes.string
2170
2063
  };
2171
2064
 
2172
2065
  var _excluded = ["children"];
2173
- // Use global React variable for `forwardRef` access (React 16 support)
2066
+ /**
2067
+ * A Handsontable-ReactJS wrapper.
2068
+ *
2069
+ * To implement, use the `HotTable` tag with properties corresponding to Handsontable options.
2070
+ * For example:
2071
+ *
2072
+ * ```js
2073
+ * <HotTable id="hot" data={dataObject} contextMenu={true} colHeaders={true} width={600} height={300} stretchH="all" />
2074
+ *
2075
+ * // is analogous to
2076
+ * let hot = new Handsontable(document.getElementById('hot'), {
2077
+ * data: dataObject,
2078
+ * contextMenu: true,
2079
+ * colHeaders: true,
2080
+ * width: 600
2081
+ * height: 300
2082
+ * });
2083
+ *
2084
+ * ```
2085
+ */
2174
2086
  var HotTable = React__default["default"].forwardRef(function (_ref, ref) {
2175
2087
  var _props$id;
2176
2088
  var children = _ref.children,
2177
2089
  props = _objectWithoutProperties(_ref, _excluded);
2178
2090
  var generatedId = typeof React__default["default"].useId === 'function' ? React__default["default"].useId() : undefined;
2179
2091
  var componentId = (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generatedId;
2180
- return React__default["default"].createElement(HotTableClass, Object.assign({
2092
+ return React__default["default"].createElement(HotTableContextProvider, null, React__default["default"].createElement(HotTableInner, Object.assign({
2181
2093
  id: componentId
2182
2094
  }, props, {
2183
2095
  ref: ref
2184
- }), children);
2096
+ }), children));
2185
2097
  });
2186
- HotTable.version = HotTableClass.version;
2187
-
2188
- var BaseEditorComponent = /*#__PURE__*/function (_React$Component) {
2189
- function BaseEditorComponent() {
2190
- var _this;
2191
- _classCallCheck(this, BaseEditorComponent);
2192
- _this = _callSuper(this, BaseEditorComponent, arguments);
2193
- _this.name = 'BaseEditorComponent';
2194
- _this.instance = null;
2195
- _this.row = null;
2196
- _this.col = null;
2197
- _this.prop = null;
2198
- _this.TD = null;
2199
- _this.originalValue = null;
2200
- _this.cellProperties = null;
2201
- _this.state = null;
2202
- _this.hotInstance = null;
2203
- _this.hotCustomEditorInstance = null;
2204
- _this.hot = null;
2205
- return _this;
2206
- }
2207
- _inherits(BaseEditorComponent, _React$Component);
2208
- return _createClass(BaseEditorComponent, [{
2209
- key: "componentDidMount",
2210
- value: function componentDidMount() {
2211
- if (this.props.emitEditorInstance) {
2212
- this.props.emitEditorInstance(this, this.props.editorColumnScope);
2213
- }
2214
- }
2215
- }, {
2216
- key: "componentDidUpdate",
2217
- value: function componentDidUpdate() {
2218
- if (this.props.emitEditorInstance) {
2219
- this.props.emitEditorInstance(this, this.props.editorColumnScope);
2220
- }
2221
- }
2222
- // BaseEditor methods:
2223
- }, {
2224
- key: "_fireCallbacks",
2225
- value: function _fireCallbacks() {
2226
- var _Handsontable$editors;
2227
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2228
- args[_key] = arguments[_key];
2229
- }
2230
- (_Handsontable$editors = Handsontable__default["default"].editors.BaseEditor.prototype._fireCallbacks).call.apply(_Handsontable$editors, [this.hotCustomEditorInstance].concat(args));
2231
- }
2232
- }, {
2233
- key: "beginEditing",
2234
- value: function beginEditing() {
2235
- var _Handsontable$editors2;
2236
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2237
- args[_key2] = arguments[_key2];
2238
- }
2239
- return (_Handsontable$editors2 = Handsontable__default["default"].editors.BaseEditor.prototype.beginEditing).call.apply(_Handsontable$editors2, [this.hotCustomEditorInstance].concat(args));
2240
- }
2241
- }, {
2242
- key: "cancelChanges",
2243
- value: function cancelChanges() {
2244
- var _Handsontable$editors3;
2245
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
2246
- args[_key3] = arguments[_key3];
2247
- }
2248
- return (_Handsontable$editors3 = Handsontable__default["default"].editors.BaseEditor.prototype.cancelChanges).call.apply(_Handsontable$editors3, [this.hotCustomEditorInstance].concat(args));
2249
- }
2250
- }, {
2251
- key: "checkEditorSection",
2252
- value: function checkEditorSection() {
2253
- var _Handsontable$editors4;
2254
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
2255
- args[_key4] = arguments[_key4];
2256
- }
2257
- return (_Handsontable$editors4 = Handsontable__default["default"].editors.BaseEditor.prototype.checkEditorSection).call.apply(_Handsontable$editors4, [this.hotCustomEditorInstance].concat(args));
2258
- }
2259
- }, {
2260
- key: "close",
2261
- value: function close() {
2262
- var _Handsontable$editors5;
2263
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
2264
- args[_key5] = arguments[_key5];
2265
- }
2266
- return (_Handsontable$editors5 = Handsontable__default["default"].editors.BaseEditor.prototype.close).call.apply(_Handsontable$editors5, [this.hotCustomEditorInstance].concat(args));
2267
- }
2268
- }, {
2269
- key: "discardEditor",
2270
- value: function discardEditor() {
2271
- var _Handsontable$editors6;
2272
- for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
2273
- args[_key6] = arguments[_key6];
2274
- }
2275
- return (_Handsontable$editors6 = Handsontable__default["default"].editors.BaseEditor.prototype.discardEditor).call.apply(_Handsontable$editors6, [this.hotCustomEditorInstance].concat(args));
2276
- }
2277
- }, {
2278
- key: "enableFullEditMode",
2279
- value: function enableFullEditMode() {
2280
- var _Handsontable$editors7;
2281
- for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
2282
- args[_key7] = arguments[_key7];
2283
- }
2284
- return (_Handsontable$editors7 = Handsontable__default["default"].editors.BaseEditor.prototype.enableFullEditMode).call.apply(_Handsontable$editors7, [this.hotCustomEditorInstance].concat(args));
2285
- }
2286
- }, {
2287
- key: "extend",
2288
- value: function extend() {
2289
- var _Handsontable$editors8;
2290
- for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
2291
- args[_key8] = arguments[_key8];
2292
- }
2293
- return (_Handsontable$editors8 = Handsontable__default["default"].editors.BaseEditor.prototype.extend).call.apply(_Handsontable$editors8, [this.hotCustomEditorInstance].concat(args));
2294
- }
2295
- }, {
2296
- key: "finishEditing",
2297
- value: function finishEditing() {
2298
- var _Handsontable$editors9;
2299
- for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
2300
- args[_key9] = arguments[_key9];
2301
- }
2302
- return (_Handsontable$editors9 = Handsontable__default["default"].editors.BaseEditor.prototype.finishEditing).call.apply(_Handsontable$editors9, [this.hotCustomEditorInstance].concat(args));
2303
- }
2304
- }, {
2305
- key: "focus",
2306
- value: function focus() {
2307
- var _Handsontable$editors10;
2308
- for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
2309
- args[_key10] = arguments[_key10];
2310
- }
2311
- return (_Handsontable$editors10 = Handsontable__default["default"].editors.BaseEditor.prototype.focus).call.apply(_Handsontable$editors10, [this.hotCustomEditorInstance].concat(args));
2312
- }
2313
- }, {
2314
- key: "getValue",
2315
- value: function getValue() {
2316
- var _Handsontable$editors11;
2317
- for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
2318
- args[_key11] = arguments[_key11];
2319
- }
2320
- return (_Handsontable$editors11 = Handsontable__default["default"].editors.BaseEditor.prototype.getValue).call.apply(_Handsontable$editors11, [this.hotCustomEditorInstance].concat(args));
2321
- }
2322
- }, {
2323
- key: "init",
2324
- value: function init() {
2325
- var _Handsontable$editors12;
2326
- for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
2327
- args[_key12] = arguments[_key12];
2328
- }
2329
- return (_Handsontable$editors12 = Handsontable__default["default"].editors.BaseEditor.prototype.init).call.apply(_Handsontable$editors12, [this.hotCustomEditorInstance].concat(args));
2330
- }
2331
- }, {
2332
- key: "isInFullEditMode",
2333
- value: function isInFullEditMode() {
2334
- var _Handsontable$editors13;
2335
- for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
2336
- args[_key13] = arguments[_key13];
2337
- }
2338
- return (_Handsontable$editors13 = Handsontable__default["default"].editors.BaseEditor.prototype.isInFullEditMode).call.apply(_Handsontable$editors13, [this.hotCustomEditorInstance].concat(args));
2339
- }
2340
- }, {
2341
- key: "isOpened",
2342
- value: function isOpened() {
2343
- var _Handsontable$editors14;
2344
- for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
2345
- args[_key14] = arguments[_key14];
2346
- }
2347
- return (_Handsontable$editors14 = Handsontable__default["default"].editors.BaseEditor.prototype.isOpened).call.apply(_Handsontable$editors14, [this.hotCustomEditorInstance].concat(args));
2348
- }
2349
- }, {
2350
- key: "isWaiting",
2351
- value: function isWaiting() {
2352
- var _Handsontable$editors15;
2353
- for (var _len15 = arguments.length, args = new Array(_len15), _key15 = 0; _key15 < _len15; _key15++) {
2354
- args[_key15] = arguments[_key15];
2355
- }
2356
- return (_Handsontable$editors15 = Handsontable__default["default"].editors.BaseEditor.prototype.isWaiting).call.apply(_Handsontable$editors15, [this.hotCustomEditorInstance].concat(args));
2357
- }
2358
- }, {
2359
- key: "open",
2360
- value: function open() {
2361
- var _Handsontable$editors16;
2362
- for (var _len16 = arguments.length, args = new Array(_len16), _key16 = 0; _key16 < _len16; _key16++) {
2363
- args[_key16] = arguments[_key16];
2364
- }
2365
- return (_Handsontable$editors16 = Handsontable__default["default"].editors.BaseEditor.prototype.open).call.apply(_Handsontable$editors16, [this.hotCustomEditorInstance].concat(args));
2366
- }
2367
- }, {
2368
- key: "prepare",
2369
- value: function prepare(row, col, prop, TD, originalValue, cellProperties) {
2370
- this.hotInstance = cellProperties.instance;
2371
- this.row = row;
2372
- this.col = col;
2373
- this.prop = prop;
2374
- this.TD = TD;
2375
- this.originalValue = originalValue;
2376
- this.cellProperties = cellProperties;
2377
- return Handsontable__default["default"].editors.BaseEditor.prototype.prepare.call(this.hotCustomEditorInstance, row, col, prop, TD, originalValue, cellProperties);
2378
- }
2379
- }, {
2380
- key: "saveValue",
2381
- value: function saveValue() {
2382
- var _Handsontable$editors17;
2383
- for (var _len17 = arguments.length, args = new Array(_len17), _key17 = 0; _key17 < _len17; _key17++) {
2384
- args[_key17] = arguments[_key17];
2385
- }
2386
- return (_Handsontable$editors17 = Handsontable__default["default"].editors.BaseEditor.prototype.saveValue).call.apply(_Handsontable$editors17, [this.hotCustomEditorInstance].concat(args));
2387
- }
2388
- }, {
2389
- key: "setValue",
2390
- value: function setValue() {
2391
- var _Handsontable$editors18;
2392
- for (var _len18 = arguments.length, args = new Array(_len18), _key18 = 0; _key18 < _len18; _key18++) {
2393
- args[_key18] = arguments[_key18];
2394
- }
2395
- return (_Handsontable$editors18 = Handsontable__default["default"].editors.BaseEditor.prototype.setValue).call.apply(_Handsontable$editors18, [this.hotCustomEditorInstance].concat(args));
2396
- }
2397
- }, {
2398
- key: "addHook",
2399
- value: function addHook() {
2400
- var _Handsontable$editors19;
2401
- for (var _len19 = arguments.length, args = new Array(_len19), _key19 = 0; _key19 < _len19; _key19++) {
2402
- args[_key19] = arguments[_key19];
2403
- }
2404
- return (_Handsontable$editors19 = Handsontable__default["default"].editors.BaseEditor.prototype.addHook).call.apply(_Handsontable$editors19, [this.hotCustomEditorInstance].concat(args));
2405
- }
2406
- }, {
2407
- key: "removeHooksByKey",
2408
- value: function removeHooksByKey() {
2409
- var _Handsontable$editors20;
2410
- for (var _len20 = arguments.length, args = new Array(_len20), _key20 = 0; _key20 < _len20; _key20++) {
2411
- args[_key20] = arguments[_key20];
2412
- }
2413
- return (_Handsontable$editors20 = Handsontable__default["default"].editors.BaseEditor.prototype.removeHooksByKey).call.apply(_Handsontable$editors20, [this.hotCustomEditorInstance].concat(args));
2414
- }
2415
- }, {
2416
- key: "clearHooks",
2417
- value: function clearHooks() {
2418
- var _Handsontable$editors21;
2419
- for (var _len21 = arguments.length, args = new Array(_len21), _key21 = 0; _key21 < _len21; _key21++) {
2420
- args[_key21] = arguments[_key21];
2421
- }
2422
- return (_Handsontable$editors21 = Handsontable__default["default"].editors.BaseEditor.prototype.clearHooks).call.apply(_Handsontable$editors21, [this.hotCustomEditorInstance].concat(args));
2423
- }
2424
- }, {
2425
- key: "getEditedCell",
2426
- value: function getEditedCell() {
2427
- var _Handsontable$editors22;
2428
- for (var _len22 = arguments.length, args = new Array(_len22), _key22 = 0; _key22 < _len22; _key22++) {
2429
- args[_key22] = arguments[_key22];
2430
- }
2431
- return (_Handsontable$editors22 = Handsontable__default["default"].editors.BaseEditor.prototype.getEditedCell).call.apply(_Handsontable$editors22, [this.hotCustomEditorInstance].concat(args));
2432
- }
2433
- }, {
2434
- key: "getEditedCellRect",
2435
- value: function getEditedCellRect() {
2436
- var _Handsontable$editors23;
2437
- for (var _len23 = arguments.length, args = new Array(_len23), _key23 = 0; _key23 < _len23; _key23++) {
2438
- args[_key23] = arguments[_key23];
2439
- }
2440
- return (_Handsontable$editors23 = Handsontable__default["default"].editors.BaseEditor.prototype.getEditedCellRect).call.apply(_Handsontable$editors23, [this.hotCustomEditorInstance].concat(args));
2441
- }
2442
- }, {
2443
- key: "getEditedCellsZIndex",
2444
- value: function getEditedCellsZIndex() {
2445
- var _Handsontable$editors24;
2446
- for (var _len24 = arguments.length, args = new Array(_len24), _key24 = 0; _key24 < _len24; _key24++) {
2447
- args[_key24] = arguments[_key24];
2448
- }
2449
- return (_Handsontable$editors24 = Handsontable__default["default"].editors.BaseEditor.prototype.getEditedCellsZIndex).call.apply(_Handsontable$editors24, [this.hotCustomEditorInstance].concat(args));
2450
- }
2451
- }]);
2452
- }(React__default["default"].Component);
2098
+ /**
2099
+ * Package version.
2100
+ *
2101
+ * @returns The version number of the package.
2102
+ */
2103
+ HotTable.version = version;
2453
2104
 
2454
- exports.BaseEditorComponent = BaseEditorComponent;
2455
2105
  exports.HotColumn = HotColumn;
2456
2106
  exports.HotTable = HotTable;
2457
- exports.HotTableClass = HotTableClass;
2458
2107
  exports["default"] = HotTable;
2108
+ exports.isHotColumn = isHotColumn;
2109
+ exports.useHotEditor = useHotEditor;