@handsontable/react-wrapper 18.1.2 → 19.0.0-rc1
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.
- package/README.md +36 -17
- package/commonjs/react-handsontable.js +877 -190
- package/dist/react-handsontable.js +880 -193
- package/dist/react-handsontable.js.map +1 -1
- package/dist/react-handsontable.min.js +2 -2
- package/dist/react-handsontable.min.js.map +1 -1
- package/es/react-handsontable.mjs +878 -191
- package/helpers.d.ts +125 -12
- package/hotColumnContext.d.ts +6 -0
- package/hotEditor.d.ts +24 -6
- package/hotTableContext.d.ts +10 -8
- package/package.json +15 -4
- package/settingsMapper.d.ts +27 -4
- package/types.d.ts +41 -4
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING FROM
|
|
26
26
|
* USE OR INABILITY TO USE THIS SOFTWARE.
|
|
27
27
|
*
|
|
28
|
-
* Version:
|
|
28
|
+
* Version: 19.0.0-rc1 (built at Mon Nov 16 2026 16:19:19 GMT+0000 (Coordinated Universal Time))
|
|
29
29
|
*/
|
|
30
30
|
(function (global, factory) {
|
|
31
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom'), require('handsontable/
|
|
32
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom', 'handsontable/
|
|
33
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Handsontable = global.Handsontable || {}, global.Handsontable.react = {}), global.React, global.ReactDOM, global.Handsontable
|
|
34
|
-
})(this, (function (exports, React, ReactDOM,
|
|
31
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom'), require('handsontable/editors/registry'), require('handsontable/base')) :
|
|
32
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom', 'handsontable/editors/registry', 'handsontable/base'], factory) :
|
|
33
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Handsontable = global.Handsontable || {}, global.Handsontable.react = {}), global.React, global.ReactDOM, global.Handsontable.editors, global.Handsontable));
|
|
34
|
+
})(this, (function (exports, React, ReactDOM, registry, Handsontable) { 'use strict';
|
|
35
35
|
|
|
36
36
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
37
37
|
|
|
@@ -47,9 +47,6 @@ function _arrayLikeToArray(r, a) {
|
|
|
47
47
|
function _arrayWithHoles(r) {
|
|
48
48
|
if (Array.isArray(r)) return r;
|
|
49
49
|
}
|
|
50
|
-
function _arrayWithoutHoles(r) {
|
|
51
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
52
|
-
}
|
|
53
50
|
function _assertThisInitialized(e) {
|
|
54
51
|
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
55
52
|
return e;
|
|
@@ -113,9 +110,6 @@ function _isNativeReflectConstruct() {
|
|
|
113
110
|
return !!t;
|
|
114
111
|
})();
|
|
115
112
|
}
|
|
116
|
-
function _iterableToArray(r) {
|
|
117
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
118
|
-
}
|
|
119
113
|
function _iterableToArrayLimit(r, l) {
|
|
120
114
|
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
121
115
|
if (null != t) {
|
|
@@ -143,9 +137,6 @@ function _iterableToArrayLimit(r, l) {
|
|
|
143
137
|
function _nonIterableRest() {
|
|
144
138
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
145
139
|
}
|
|
146
|
-
function _nonIterableSpread() {
|
|
147
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
148
|
-
}
|
|
149
140
|
function ownKeys(e, r) {
|
|
150
141
|
var t = Object.keys(e);
|
|
151
142
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -200,9 +191,6 @@ function _setPrototypeOf(t, e) {
|
|
|
200
191
|
function _slicedToArray(r, e) {
|
|
201
192
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
202
193
|
}
|
|
203
|
-
function _toConsumableArray(r) {
|
|
204
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
205
|
-
}
|
|
206
194
|
function _toPrimitive(t, r) {
|
|
207
195
|
if ("object" != typeof t || !t) return t;
|
|
208
196
|
var e = t[Symbol.toPrimitive];
|
|
@@ -239,17 +227,17 @@ var bulkComponentContainer = null;
|
|
|
239
227
|
/**
|
|
240
228
|
* Warning message for the `autoRowSize`/`autoColumnSize` compatibility check.
|
|
241
229
|
*/
|
|
242
|
-
var AUTOSIZE_WARNING = 'Your `HotTable` configuration includes `autoRowSize`/`autoColumnSize` options, which are not compatible with
|
|
230
|
+
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.';
|
|
243
231
|
|
|
244
232
|
/**
|
|
245
233
|
* Warning message for the `hot-renderer` obsolete renderer passing method.
|
|
246
234
|
*/
|
|
247
|
-
var OBSOLETE_HOTRENDERER_WARNING = 'Providing a component-based renderer using `hot-renderer`-annotated component is no longer supported.
|
|
235
|
+
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.';
|
|
248
236
|
|
|
249
237
|
/**
|
|
250
238
|
* Warning message for the `hot-editor` obsolete editor passing method.
|
|
251
239
|
*/
|
|
252
|
-
var OBSOLETE_HOTEDITOR_WARNING = 'Providing a component-based editor using `hot-editor`-annotated component is no longer supported.
|
|
240
|
+
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.';
|
|
253
241
|
|
|
254
242
|
/**
|
|
255
243
|
* Warning message for the unexpected children of HotTable component.
|
|
@@ -261,6 +249,21 @@ var UNEXPECTED_HOTTABLE_CHILDREN_WARNING = 'Unexpected children nodes found in H
|
|
|
261
249
|
*/
|
|
262
250
|
var UNEXPECTED_HOTCOLUMN_CHILDREN_WARNING = 'Unexpected children nodes found in HotColumn component. ' + 'HotColumn components do not support any children.';
|
|
263
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Warning when a Handsontable function renderer is passed to the React `renderer` prop.
|
|
254
|
+
*
|
|
255
|
+
* That prop is a React component. A classic function renderer belongs on `hotRenderer`.
|
|
256
|
+
*/
|
|
257
|
+
var CLASSIC_FUNCTION_RENDERER_WARNING = 'The `renderer` prop expects a React component. ' + 'Pass a Handsontable function renderer to `hotRenderer` instead.';
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Warning when a Handsontable editor (an editor class or a registered editor name) is passed to the
|
|
261
|
+
* React `editor` prop.
|
|
262
|
+
*
|
|
263
|
+
* That prop is a React component. A Handsontable editor belongs on `hotEditor`.
|
|
264
|
+
*/
|
|
265
|
+
var NATIVE_EDITOR_IN_EDITOR_PROP_WARNING = 'The `editor` prop expects a React component. ' + 'Pass a Handsontable editor class or editor name to `hotEditor` instead.';
|
|
266
|
+
|
|
264
267
|
/**
|
|
265
268
|
* Message for the warning thrown if the Handsontable instance has been destroyed.
|
|
266
269
|
*/
|
|
@@ -271,6 +274,17 @@ var HOT_DESTROYED_WARNING = 'The Handsontable instance bound to this component w
|
|
|
271
274
|
*/
|
|
272
275
|
var DEFAULT_CLASSNAME = 'hot-wrapper-editor-container';
|
|
273
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Classname for the stable host that holds React editor portals.
|
|
279
|
+
* Distinct from `DEFAULT_CLASSNAME` so page CSS and `querySelector` do not hit both nodes.
|
|
280
|
+
*/
|
|
281
|
+
var EDITOR_PORTAL_HOST_CLASSNAME = 'hot-wrapper-editor-portal-host';
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Warning when the editor portal host cannot be moved into `rootPortalElement`.
|
|
285
|
+
*/
|
|
286
|
+
var MISSING_ROOT_PORTAL_WARNING = 'The React editor portal host could not be attached to ' + '`rootPortalElement`. The editor stays on `document.body` and clicks on it may fail to commit.';
|
|
287
|
+
|
|
274
288
|
/**
|
|
275
289
|
* Logs warn to the console if the `console` object is exposed.
|
|
276
290
|
*
|
|
@@ -283,9 +297,38 @@ function warn() {
|
|
|
283
297
|
}
|
|
284
298
|
}
|
|
285
299
|
|
|
300
|
+
/**
|
|
301
|
+
* Function renderers that already produced `CLASSIC_FUNCTION_RENDERER_WARNING`.
|
|
302
|
+
* Keyed by the function, so one function warns once no matter how many cells render it.
|
|
303
|
+
*/
|
|
304
|
+
var warnedClassicFunctionRenderers = new WeakSet();
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Warn when `renderer` holds a Handsontable function renderer.
|
|
308
|
+
*
|
|
309
|
+
* A React component is called with one props object, so its `length` stays below 3.
|
|
310
|
+
* A classic renderer declares `(instance, td, row, col, prop, value, cellProperties)`,
|
|
311
|
+
* so its `length` is at least 3. The prop is still rendered as a component. Picking
|
|
312
|
+
* the call style from `length` would change behavior, because a component with default
|
|
313
|
+
* parameters reports `length` 0.
|
|
314
|
+
*
|
|
315
|
+
* @param {ComponentType} renderer Component passed through the `renderer` prop.
|
|
316
|
+
*/
|
|
317
|
+
function warnAboutClassicFunctionRenderer(renderer) {
|
|
318
|
+
if (typeof renderer !== 'function' || renderer.length < 3) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (warnedClassicFunctionRenderers.has(renderer)) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
warnedClassicFunctionRenderers.add(renderer);
|
|
325
|
+
warn(CLASSIC_FUNCTION_RENDERER_WARNING);
|
|
326
|
+
}
|
|
327
|
+
|
|
286
328
|
/**
|
|
287
329
|
* Detect if `hot-renderer` or `hot-editor` is defined, and if so, throw an incompatibility warning.
|
|
288
330
|
*
|
|
331
|
+
* @param {ReactNode} children Component children nodes.
|
|
289
332
|
* @returns {boolean} 'true' if the warning was issued
|
|
290
333
|
*/
|
|
291
334
|
function displayObsoleteRenderersEditorsWarning(children) {
|
|
@@ -337,31 +380,178 @@ function displayAnyChildrenWarning(children) {
|
|
|
337
380
|
* Check the existence of elements of the provided `type` from the `HotColumn` component's children.
|
|
338
381
|
*
|
|
339
382
|
* @param {ReactNode} children HotTable children array.
|
|
340
|
-
* @param {
|
|
383
|
+
* @param {string} type Either `'hot-renderer'` or `'hot-editor'`.
|
|
341
384
|
* @returns {boolean} `true` if the child of that type was found, `false` otherwise.
|
|
342
385
|
*/
|
|
343
386
|
function hasChildElementOfType(children, type) {
|
|
344
387
|
var childrenArray = React__default["default"].Children.toArray(children);
|
|
345
388
|
return childrenArray.some(function (child) {
|
|
346
|
-
return child.props[type] !==
|
|
389
|
+
return child.props[type] !== undefined;
|
|
347
390
|
});
|
|
348
391
|
}
|
|
349
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Check whether the `editor` prop holds a component editor, as opposed to a boolean flag or a
|
|
395
|
+
* Handsontable editor passed there by mistake.
|
|
396
|
+
*
|
|
397
|
+
* Both editor props accept a boolean, so a truthy check alone is not enough to tell a component
|
|
398
|
+
* apart from a bare `editor={true}`. An editor class or editor name is not a component either (see
|
|
399
|
+
* `isNativeEditor()`).
|
|
400
|
+
*
|
|
401
|
+
* @param {HotTableProps['editor']} editor The `editor` prop.
|
|
402
|
+
* @returns {boolean} `true` when the prop carries a React component to render.
|
|
403
|
+
*/
|
|
404
|
+
function isComponentEditor(editor) {
|
|
405
|
+
return !!editor && typeof editor !== 'boolean' && !isNativeEditor(editor);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Methods every Handsontable editor class inherits from `BaseEditor`.
|
|
410
|
+
*/
|
|
411
|
+
var NATIVE_EDITOR_METHODS = ['prepare', 'beginEditing', 'getValue', 'setValue', 'open', 'close'];
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Check whether a value is a Handsontable editor: a registered editor name or an editor class.
|
|
415
|
+
*
|
|
416
|
+
* A class is recognized by the `BaseEditor` methods on its prototype rather than with `instanceof`,
|
|
417
|
+
* so a class built on another copy of Handsontable is still recognized. A React class component
|
|
418
|
+
* carries `prototype.isReactComponent`, and a function component does not have these methods, so
|
|
419
|
+
* neither one matches.
|
|
420
|
+
*
|
|
421
|
+
* @param {*} editor The value to check.
|
|
422
|
+
* @returns {boolean} `true` when the value is a Handsontable editor.
|
|
423
|
+
*/
|
|
424
|
+
function isNativeEditor(editor) {
|
|
425
|
+
if (typeof editor === 'string') {
|
|
426
|
+
return editor !== '';
|
|
427
|
+
}
|
|
428
|
+
if (typeof editor !== 'function') {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
var prototype = editor.prototype;
|
|
432
|
+
if (!prototype || prototype.isReactComponent) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
return NATIVE_EDITOR_METHODS.every(function (method) {
|
|
436
|
+
return typeof prototype[method] === 'function';
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Check whether an editor is registered under a name.
|
|
442
|
+
*
|
|
443
|
+
* It asks `getEditor()`, which throws for an unknown name, instead of `hasEditor()`: the UMD build
|
|
444
|
+
* maps the editor registry to `Handsontable.editors`, which exposes `getEditor()` only.
|
|
445
|
+
*
|
|
446
|
+
* @param {string} name The editor name.
|
|
447
|
+
* @returns {boolean} `true` when an editor is registered under the name.
|
|
448
|
+
*/
|
|
449
|
+
function isRegisteredEditorName(name) {
|
|
450
|
+
try {
|
|
451
|
+
registry.getEditor(name);
|
|
452
|
+
return true;
|
|
453
|
+
} catch (_unused) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Editor classes that already produced `NATIVE_EDITOR_IN_EDITOR_PROP_WARNING`.
|
|
460
|
+
*/
|
|
461
|
+
var warnedNativeEditorClasses = new WeakSet();
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Editor names that already produced `NATIVE_EDITOR_IN_EDITOR_PROP_WARNING`.
|
|
465
|
+
*/
|
|
466
|
+
var warnedNativeEditorNames = new Set();
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Warn once per value that a Handsontable editor was passed to the `editor` prop.
|
|
470
|
+
*
|
|
471
|
+
* @param {Function|string} editor The editor class or editor name.
|
|
472
|
+
*/
|
|
473
|
+
function warnAboutNativeEditorInEditorProp(editor) {
|
|
474
|
+
if (typeof editor === 'string') {
|
|
475
|
+
if (warnedNativeEditorNames.has(editor)) {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
warnedNativeEditorNames.add(editor);
|
|
479
|
+
} else {
|
|
480
|
+
if (warnedNativeEditorClasses.has(editor)) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
warnedNativeEditorClasses.add(editor);
|
|
484
|
+
}
|
|
485
|
+
warn(NATIVE_EDITOR_IN_EDITOR_PROP_WARNING);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Resolve the Handsontable `editor` setting from the two editor props.
|
|
490
|
+
*
|
|
491
|
+
* `editor` carries the component editor and `hotEditor` the Handsontable-native one, but both accept
|
|
492
|
+
* a boolean:
|
|
493
|
+
*
|
|
494
|
+
* - `false` disables editing.
|
|
495
|
+
* - `true` names no editor, so it is treated as if the prop were not provided. It must never reach
|
|
496
|
+
* the core, which accepts only a string or a constructor and throws on anything else.
|
|
497
|
+
* - Any other nullish or falsy value (`null`, `0`, `''`) is also treated as "not provided", so a
|
|
498
|
+
* column written as `editor={cond ? MyEditor : null}` inherits instead of locking.
|
|
499
|
+
*
|
|
500
|
+
* `hotEditor` is resolved before a falsy `editor`, so an editor named there still wins over a bare
|
|
501
|
+
* `editor={false}` — the behavior in every released version, where `editor={false}` fell through to
|
|
502
|
+
* the `hotEditor` value. A component `editor` outranks both: it is picked by `isComponentEditor()`
|
|
503
|
+
* before this function is reached, so `editor={MyComponent} hotEditor={false}` keeps the component.
|
|
504
|
+
*
|
|
505
|
+
* A Handsontable editor (a class or a registered name) passed to `editor` is a mistake: that prop
|
|
506
|
+
* renders a React component. It is used as if it were passed to `hotEditor`, with a one-time
|
|
507
|
+
* warning. A `hotEditor` value that names an editor or disables editing still wins over it. A name
|
|
508
|
+
* that no editor is registered under is dropped after the warning, so a typo does not make the core
|
|
509
|
+
* throw.
|
|
510
|
+
*
|
|
511
|
+
* @param {HotTableProps['editor']} editor The `editor` prop.
|
|
512
|
+
* @param {HotTableProps['hotEditor']} hotEditor The `hotEditor` prop.
|
|
513
|
+
* @returns {*} The editor setting, or `undefined` when neither prop names one.
|
|
514
|
+
*/
|
|
515
|
+
function resolveEditorSetting(editor, hotEditor) {
|
|
516
|
+
if (hotEditor === false) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// `true` names no editor, so it must fall through to "not provided" rather than hard-setting the
|
|
521
|
+
// default one — otherwise it would override the editor a column's `type` or the grid supplies.
|
|
522
|
+
if (hotEditor && hotEditor !== true) {
|
|
523
|
+
return hotEditor;
|
|
524
|
+
}
|
|
525
|
+
if (isNativeEditor(editor)) {
|
|
526
|
+
warnAboutNativeEditorInEditorProp(editor);
|
|
527
|
+
|
|
528
|
+
// An unregistered name (a typo) would make the core throw on every selection of the cell, so
|
|
529
|
+
// it is dropped and the cell keeps the editor its column type or the grid supplies.
|
|
530
|
+
if (typeof editor === 'string' && !isRegisteredEditorName(editor)) {
|
|
531
|
+
return undefined;
|
|
532
|
+
}
|
|
533
|
+
return editor;
|
|
534
|
+
}
|
|
535
|
+
return editor === false ? false : undefined;
|
|
536
|
+
}
|
|
537
|
+
|
|
350
538
|
/**
|
|
351
539
|
* Create an editor portal.
|
|
352
540
|
*
|
|
353
541
|
* @param {Document} doc Document to be used.
|
|
354
542
|
* @param {ComponentType} Editor Editor component or render function.
|
|
543
|
+
* @param {HTMLElement} portalHost Host element to portal into. Required – do not fall back to `doc.body`.
|
|
355
544
|
* @returns {ReactPortal} The portal for the editor.
|
|
356
545
|
*/
|
|
357
|
-
function createEditorPortal(doc, Editor) {
|
|
358
|
-
if (!doc || !
|
|
546
|
+
function createEditorPortal(doc, Editor, portalHost) {
|
|
547
|
+
if (!doc || !portalHost || !isComponentEditor(Editor)) {
|
|
359
548
|
return null;
|
|
360
549
|
}
|
|
361
|
-
var
|
|
550
|
+
var EditorComponent = Editor;
|
|
551
|
+
var editorElement = /*#__PURE__*/React__default["default"].createElement(EditorComponent, null);
|
|
362
552
|
var containerProps = getContainerAttributesProps({}, false);
|
|
363
553
|
containerProps.className = "".concat(DEFAULT_CLASSNAME, " ").concat(containerProps.className);
|
|
364
|
-
return /*#__PURE__*/ReactDOM__default["default"].createPortal(/*#__PURE__*/React__default["default"].createElement("div", containerProps, editorElement),
|
|
554
|
+
return /*#__PURE__*/ReactDOM__default["default"].createPortal(/*#__PURE__*/React__default["default"].createElement("div", containerProps, editorElement), portalHost);
|
|
365
555
|
}
|
|
366
556
|
|
|
367
557
|
/**
|
|
@@ -369,9 +559,10 @@ function createEditorPortal(doc, Editor) {
|
|
|
369
559
|
*
|
|
370
560
|
* @param {React.ReactElement} rElement React element to be used as a base for the component.
|
|
371
561
|
* @param {Document} [ownerDocument] The owner document to set the portal up into.
|
|
372
|
-
* @param {
|
|
562
|
+
* @param {string} portalKey The key to be used for the portal.
|
|
373
563
|
* @param {HTMLElement} [cachedContainer] The cached container to be used for the portal.
|
|
374
|
-
* @returns {{portal: ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its
|
|
564
|
+
* @returns {{portal: ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its
|
|
565
|
+
* container.
|
|
375
566
|
*/
|
|
376
567
|
function createPortal(rElement) {
|
|
377
568
|
var ownerDocument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
|
|
@@ -403,14 +594,15 @@ function createPortal(rElement) {
|
|
|
403
594
|
* component.
|
|
404
595
|
*
|
|
405
596
|
* @param {HotTableProps} props Object containing the React element props.
|
|
406
|
-
* @param {
|
|
407
|
-
*
|
|
408
|
-
*
|
|
597
|
+
* @param {boolean} randomizeId If set to `true`, the function will randomize the `id` property when no `id` was
|
|
598
|
+
* present in the `prop` object.
|
|
599
|
+
* @returns {{id?: string, className: string, style: CSSProperties}} An object containing the `id`, `className`
|
|
600
|
+
* and `style` keys, representing the corresponding props passed to the component.
|
|
409
601
|
*/
|
|
410
602
|
function getContainerAttributesProps(props) {
|
|
411
603
|
var randomizeId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
412
604
|
return {
|
|
413
|
-
id: props.id || (randomizeId ?
|
|
605
|
+
id: props.id || (randomizeId ? "hot-".concat(Math.random().toString(36).substring(5)) : undefined),
|
|
414
606
|
className: props.className || '',
|
|
415
607
|
style: props.style || {}
|
|
416
608
|
};
|
|
@@ -419,14 +611,28 @@ function getContainerAttributesProps(props) {
|
|
|
419
611
|
/**
|
|
420
612
|
* Checks if the environment that the code runs in is a browser.
|
|
421
613
|
*
|
|
422
|
-
* @returns {boolean}
|
|
614
|
+
* @returns {boolean} `true` when running in a browser environment.
|
|
423
615
|
*/
|
|
424
616
|
function isCSR() {
|
|
425
617
|
return typeof window !== 'undefined';
|
|
426
618
|
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Checks whether the value is an object or `null`.
|
|
622
|
+
*
|
|
623
|
+
* @param {unknown} value Value to check.
|
|
624
|
+
* @returns {boolean} `true` when the value is an object.
|
|
625
|
+
*/
|
|
427
626
|
function isObjectLike(value) {
|
|
428
627
|
return _typeof(value) === 'object' && value !== null;
|
|
429
628
|
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Checks whether the value is a plain object (an object literal or one created with `Object.create(null)`).
|
|
632
|
+
*
|
|
633
|
+
* @param {unknown} value Value to check.
|
|
634
|
+
* @returns {boolean} `true` when the value is a plain object.
|
|
635
|
+
*/
|
|
430
636
|
function isPlainObject(value) {
|
|
431
637
|
if (!isObjectLike(value)) {
|
|
432
638
|
return false;
|
|
@@ -434,18 +640,30 @@ function isPlainObject(value) {
|
|
|
434
640
|
var prototype = Object.getPrototypeOf(value);
|
|
435
641
|
return prototype === Object.prototype || prototype === null;
|
|
436
642
|
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Checks whether the value is an array.
|
|
646
|
+
*
|
|
647
|
+
* @param {unknown} value Value to check.
|
|
648
|
+
* @returns {boolean} `true` when the value is an array.
|
|
649
|
+
*/
|
|
437
650
|
function isArray(value) {
|
|
438
651
|
return Array.isArray(value);
|
|
439
652
|
}
|
|
440
653
|
|
|
441
654
|
/**
|
|
442
|
-
* Deep-compare plain objects and arrays used by wrapper settings.
|
|
655
|
+
* Deep-compare plain objects and arrays used by wrapper settings. Functions, class instances and any
|
|
656
|
+
* other value are compared by reference, and a `RegExp` by its source and flags. A pair of objects
|
|
657
|
+
* already being compared higher up reads as equal, so a value with a cycle (tree rows with a `parent`
|
|
658
|
+
* link) ends instead of overflowing the stack.
|
|
443
659
|
*
|
|
444
660
|
* @param {unknown} previousValue Previous value.
|
|
445
661
|
* @param {unknown} currentValue Current value.
|
|
662
|
+
* @param {WeakMap<object, WeakSet<object>>} [visited] The object pairs on the current comparison path.
|
|
446
663
|
* @returns {boolean} `true` if values are equivalent.
|
|
447
664
|
*/
|
|
448
665
|
function areEquivalentSettingsValue(previousValue, currentValue) {
|
|
666
|
+
var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakMap();
|
|
449
667
|
if (previousValue === currentValue) {
|
|
450
668
|
return true;
|
|
451
669
|
}
|
|
@@ -455,48 +673,66 @@ function areEquivalentSettingsValue(previousValue, currentValue) {
|
|
|
455
673
|
}
|
|
456
674
|
return previousValue.source === currentValue.source && previousValue.flags === currentValue.flags;
|
|
457
675
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
for (var index = 0; index < previousValue.length; index++) {
|
|
463
|
-
if (!areEquivalentSettingsValue(previousValue[index], currentValue[index])) {
|
|
464
|
-
return false;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
return true;
|
|
468
|
-
}
|
|
469
|
-
if (isArray(previousValue) || isArray(currentValue)) {
|
|
676
|
+
var bothArrays = isArray(previousValue) && isArray(currentValue);
|
|
677
|
+
var bothPlainObjects = !isArray(previousValue) && !isArray(currentValue) && isPlainObject(previousValue) && isPlainObject(currentValue);
|
|
678
|
+
if (!bothArrays && !bothPlainObjects) {
|
|
470
679
|
return false;
|
|
471
680
|
}
|
|
472
|
-
|
|
473
|
-
|
|
681
|
+
var previousObject = previousValue;
|
|
682
|
+
var currentObject = currentValue;
|
|
683
|
+
var comparedWith = visited.get(previousObject);
|
|
684
|
+
if (comparedWith !== null && comparedWith !== void 0 && comparedWith.has(currentObject)) {
|
|
685
|
+
return true;
|
|
474
686
|
}
|
|
475
|
-
if (
|
|
476
|
-
|
|
687
|
+
if (comparedWith) {
|
|
688
|
+
comparedWith.add(currentObject);
|
|
689
|
+
} else {
|
|
690
|
+
visited.set(previousObject, new WeakSet([currentObject]));
|
|
477
691
|
}
|
|
478
|
-
var previousKeys = Object.keys(
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
692
|
+
var previousKeys = Object.keys(previousObject);
|
|
693
|
+
return previousKeys.length === Object.keys(currentObject).length && previousKeys.every(function (key) {
|
|
694
|
+
return Object.prototype.hasOwnProperty.call(currentObject, key) && areEquivalentSettingsValue(previousObject[key], currentObject[key], visited);
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Copies the plain objects and arrays of a settings value, keeping every other value (functions, class
|
|
700
|
+
* instances) by reference. The copy is what an update compares the next value with, so a value the app
|
|
701
|
+
* changes in place reads as changed. A value with a cycle is copied with the same cycle.
|
|
702
|
+
*
|
|
703
|
+
* @param {unknown} value The value to copy.
|
|
704
|
+
* @param {WeakMap<object, unknown>} [copies] The copies made so far, by original.
|
|
705
|
+
* @returns {unknown} The copy.
|
|
706
|
+
*/
|
|
707
|
+
function copySettingsValue(value) {
|
|
708
|
+
var copies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
|
|
709
|
+
if (!isArray(value) && !isPlainObject(value)) {
|
|
710
|
+
return value;
|
|
482
711
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
712
|
+
if (copies.has(value)) {
|
|
713
|
+
return copies.get(value);
|
|
714
|
+
}
|
|
715
|
+
if (isArray(value)) {
|
|
716
|
+
var _copy = [];
|
|
717
|
+
copies.set(value, _copy);
|
|
718
|
+
value.forEach(function (item) {
|
|
719
|
+
_copy.push(copySettingsValue(item, copies));
|
|
720
|
+
});
|
|
721
|
+
return _copy;
|
|
491
722
|
}
|
|
492
|
-
|
|
723
|
+
var copy = {};
|
|
724
|
+
copies.set(value, copy);
|
|
725
|
+
Object.keys(value).forEach(function (key) {
|
|
726
|
+
copy[key] = copySettingsValue(value[key], copies);
|
|
727
|
+
});
|
|
728
|
+
return copy;
|
|
493
729
|
}
|
|
494
730
|
|
|
495
731
|
/**
|
|
496
732
|
* A variant of useEffect hook that does not trigger on initial mount, only updates
|
|
497
733
|
*
|
|
498
|
-
* @param effect Effect function
|
|
499
|
-
* @param deps Effect dependencies
|
|
734
|
+
* @param {EffectCallback} effect Effect function
|
|
735
|
+
* @param {DependencyList} [deps] Effect dependencies
|
|
500
736
|
*/
|
|
501
737
|
function useUpdateEffect(effect, deps) {
|
|
502
738
|
var notInitialRender = React__default["default"].useRef(false);
|
|
@@ -510,12 +746,165 @@ function useUpdateEffect(effect, deps) {
|
|
|
510
746
|
}
|
|
511
747
|
|
|
512
748
|
/**
|
|
513
|
-
*
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
749
|
+
* The class of the wrapper the grid puts around a cell's content in a row rendered at an exact height.
|
|
750
|
+
*/
|
|
751
|
+
var CELL_CLIP_CLASS = 'htCellClip';
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Returns the element a cell's content belongs in: the grid's clipping wrapper when the cell holds
|
|
755
|
+
* exactly that wrapper, and the cell itself otherwise.
|
|
756
|
+
*
|
|
757
|
+
* @param {HTMLElement} TD The table cell.
|
|
758
|
+
* @returns {Element}
|
|
759
|
+
*/
|
|
760
|
+
function getCellContentRoot(TD) {
|
|
761
|
+
var firstChild = TD.firstElementChild;
|
|
762
|
+
if (firstChild !== null && TD.childNodes.length === 1 && firstChild.classList.contains(CELL_CLIP_CLASS)) {
|
|
763
|
+
return firstChild;
|
|
764
|
+
}
|
|
765
|
+
return TD;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* These settings are compared with the previous props, or for the size settings with the grid's live
|
|
770
|
+
* value, by the rules below. Every other setting but `data` is compared with a copy of the value last
|
|
771
|
+
* passed to the grid (`isSameAsForwarded()`).
|
|
772
|
+
*
|
|
773
|
+
* `rowHeights`, `minRowHeights` (the row height floor) and `colWidths` are here because passing any
|
|
774
|
+
* of them re-declares the sizes and discards the ones the user produced by dragging
|
|
775
|
+
* (`ManualRowResize` / `ManualColumnResize`). A re-render must not do that, and a React app commonly
|
|
776
|
+
* writes the value inline (`rowHeights={[50, 50]}`), which is a new array on every render and never
|
|
777
|
+
* reference-equal. All three hold plain numbers, strings or arrays of them, so the deep walk is
|
|
778
|
+
* cheap. The Vue wrapper already skips unchanged keys this way.
|
|
779
|
+
*/
|
|
780
|
+
var DEEP_COMPARABLE_SETTINGS = ['dataSchema', 'columns', 'rowHeights', 'minRowHeights', 'colWidths'];
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* The size settings are compared against the grid's live settings rather than the previous props,
|
|
784
|
+
* which is what the Angular and Vue wrappers already do. Comparing against props alone would stop
|
|
785
|
+
* re-asserting the prop after anything changed the size through the instance ref.
|
|
786
|
+
*/
|
|
787
|
+
var COMPARED_AGAINST_LIVE_SETTINGS = ['rowHeights', 'minRowHeights', 'colWidths'];
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Settings that core resets only on `null`. For these, core reads `undefined` as "leave the current
|
|
791
|
+
* value", so forwarding the `undefined` default would keep the old size on the root element. `null`
|
|
792
|
+
* restores the root element's initial inline size, which is what a fresh mount without the prop gives.
|
|
793
|
+
*/
|
|
794
|
+
var CLEARED_BY_NULL_SETTINGS = new Set(['height', 'width']);
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Settings forwarded on every update, changed or not. An app may change the rows of its `data` array
|
|
798
|
+
* in place and re-render to show them, and passing the array again is what reloads them.
|
|
799
|
+
*/
|
|
800
|
+
var ALWAYS_FORWARDED_SETTINGS = ['data'];
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* Settings compared by reference only. The sheets bar writes renames and added sheets into the
|
|
804
|
+
* `sheets` array it was given, so a new array is a new workbook even when its content matches, and
|
|
805
|
+
* walking every sheet's rows on each render would cost as much as the data itself. The Vue wrapper
|
|
806
|
+
* compares `sheets` the same way.
|
|
807
|
+
*/
|
|
808
|
+
var REFERENCE_COMPARED_SETTINGS = ['sheetsBar'];
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* Copies of the values last passed to the grid, by setting name. The component keeps one per grid
|
|
812
|
+
* instance and passes it to every update.
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Checks whether an update would pass a setting with the value it passed last time. Passing it again
|
|
817
|
+
* is not a no-op: core re-applies the plugins it names, and a plugin re-applied with its own settings
|
|
818
|
+
* drops the state the user gave it (Filters' conditions, Pagination's page, the server total of a
|
|
819
|
+
* `dataProvider` grid, and a refetch). A React app passes every prop on each render, often as an
|
|
820
|
+
* inline object, so the value is compared by content (`areEquivalentSettingsValue()`: functions and
|
|
821
|
+
* class instances by reference). The comparison is with a copy of the value last passed, not with the
|
|
822
|
+
* grid's live value: an object the app changed in place is the same reference the grid holds, so only
|
|
823
|
+
* the copy shows the change, and with the sheets bar on the live value is the visible sheet's own.
|
|
824
|
+
*
|
|
825
|
+
* @param {string} key The setting name.
|
|
826
|
+
* @param {*} value The value the update would pass.
|
|
827
|
+
* @param {ForwardedSettings} [forwardedSettings] The values last passed to the grid.
|
|
828
|
+
* @returns {boolean}
|
|
517
829
|
*/
|
|
518
|
-
|
|
830
|
+
function isSameAsForwarded(key, value, forwardedSettings) {
|
|
831
|
+
if (!(forwardedSettings !== null && forwardedSettings !== void 0 && forwardedSettings.has(key)) || ALWAYS_FORWARDED_SETTINGS.includes(key)) {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
var forwardedValue = forwardedSettings.get(key);
|
|
835
|
+
return REFERENCE_COMPARED_SETTINGS.includes(key) ? forwardedValue === value : areEquivalentSettingsValue(forwardedValue, value);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Records the value an update passes to the grid, for the next update to compare with.
|
|
840
|
+
*
|
|
841
|
+
* @param {string} key The setting name.
|
|
842
|
+
* @param {*} value The value passed.
|
|
843
|
+
* @param {ForwardedSettings} [forwardedSettings] The values last passed to the grid.
|
|
844
|
+
*/
|
|
845
|
+
function recordForwarded(key, value, forwardedSettings) {
|
|
846
|
+
if (!forwardedSettings || ALWAYS_FORWARDED_SETTINGS.includes(key)) {
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
forwardedSettings.set(key, REFERENCE_COMPARED_SETTINGS.includes(key) ? value : copySettingsValue(value));
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Checks whether a setting is a hook, by the rule core's `updateSettings()` uses in `core.ts`: a
|
|
854
|
+
* registered or a deprecated hook name.
|
|
855
|
+
*
|
|
856
|
+
* @param {string} key The setting name.
|
|
857
|
+
* @returns {boolean}
|
|
858
|
+
*/
|
|
859
|
+
function isHookKey(key) {
|
|
860
|
+
return Handsontable__default["default"].hooks.isRegistered(key) || Handsontable__default["default"].hooks.isDeprecated(key);
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Returns the value that clears a setting whose prop went from a value to `undefined`: `null` for a
|
|
865
|
+
* hook (it removes the callback) and for `height` and `width` (it resets the root element's size),
|
|
866
|
+
* and the option's default for anything else.
|
|
867
|
+
*
|
|
868
|
+
* @param {string} key The setting name.
|
|
869
|
+
* @returns {*} The value to forward to `updateSettings()`.
|
|
870
|
+
*/
|
|
871
|
+
function getClearedValue(key) {
|
|
872
|
+
if (isHookKey(key) || CLEARED_BY_NULL_SETTINGS.has(key)) {
|
|
873
|
+
return null;
|
|
874
|
+
}
|
|
875
|
+
return Handsontable__default["default"].DefaultSettings[key];
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Checks whether a hook value holds a callback core registers: a function or an array of them. Core
|
|
880
|
+
* ignores any other value for a hook, so `false` from `afterChange={on && logChange}` would leave the
|
|
881
|
+
* previous callback running.
|
|
882
|
+
*
|
|
883
|
+
* @param {*} value The hook value.
|
|
884
|
+
* @returns {boolean}
|
|
885
|
+
*/
|
|
886
|
+
function isHookCallback(value) {
|
|
887
|
+
return typeof value === 'function' || Array.isArray(value);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Returns the value to forward for a prop that is passed: the option's cleared value for `undefined`,
|
|
892
|
+
* `null` for a hook prop that holds no callback on an update, and the prop value otherwise.
|
|
893
|
+
*
|
|
894
|
+
* @param {string} key The setting name.
|
|
895
|
+
* @param {*} value The prop value.
|
|
896
|
+
* @param {boolean} isInit Whether the grid is being initialized.
|
|
897
|
+
* @returns {*} The value to forward to `updateSettings()`.
|
|
898
|
+
*/
|
|
899
|
+
function getForwardedValue(key, value, isInit) {
|
|
900
|
+
if (value === undefined) {
|
|
901
|
+
return getClearedValue(key);
|
|
902
|
+
}
|
|
903
|
+
if (!isInit && isHookKey(key) && !isHookCallback(value)) {
|
|
904
|
+
return null;
|
|
905
|
+
}
|
|
906
|
+
return value;
|
|
907
|
+
}
|
|
519
908
|
var SettingsMapper = /*#__PURE__*/function () {
|
|
520
909
|
function SettingsMapper() {
|
|
521
910
|
_classCallCheck(this, SettingsMapper);
|
|
@@ -526,11 +915,27 @@ var SettingsMapper = /*#__PURE__*/function () {
|
|
|
526
915
|
/**
|
|
527
916
|
* Parse component settings into Handsontable-compatible settings.
|
|
528
917
|
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
918
|
+
* A prop whose value is `undefined` counts as not passed and is left out, so the option keeps its
|
|
919
|
+
* default. An own `undefined` key would shadow that default in the settings cascade. On an update
|
|
920
|
+
* of a prop that had a value in the previous props, the option's default is forwarded instead, so
|
|
921
|
+
* the grid matches a fresh mount with the same props (`copyPaste={on ? false : undefined}` turns
|
|
922
|
+
* copy and paste back on). `height` and `width` are forwarded as `null`, because core leaves the
|
|
923
|
+
* size in place for `undefined` (`height={full ? undefined : 400}` clears the height).
|
|
924
|
+
* A hook has no default to fall back to, so a hook prop that had a callback and is now `undefined`
|
|
925
|
+
* is forwarded as `null`, which removes the callback (`afterChange={on ? logChange : undefined}`).
|
|
926
|
+
* So is a hook prop that had a callback and is no longer passed at all, and, on an update, a hook
|
|
927
|
+
* prop that holds anything but a callback (`afterChange={on && logChange}` gives `false`).
|
|
928
|
+
* For an option that is not a hook, `null` and `false` are real values and are forwarded.
|
|
929
|
+
*
|
|
930
|
+
* @param {object} properties Object containing properties from the HotTable object.
|
|
931
|
+
* @param {object} additionalSettings Additional settings.
|
|
531
932
|
* @param {boolean} additionalSettings.isInit Flag determining whether the settings are being set during initialization.
|
|
532
933
|
* @param {string[]} additionalSettings.initOnlySettingKeys Array of keys that can be set only during initialization.
|
|
533
|
-
* @
|
|
934
|
+
* @param {HotTableProps} additionalSettings.prevProps The component's props before the current update.
|
|
935
|
+
* @param {Handsontable.GridSettings} additionalSettings.currentSettings The grid's current live settings.
|
|
936
|
+
* @param {ForwardedSettings} additionalSettings.forwardedSettings The values last passed to the grid. A
|
|
937
|
+
* setting whose value equals the one recorded there is left out, and every setting passed is recorded.
|
|
938
|
+
* @returns {object} Handsontable-compatible settings object.
|
|
534
939
|
*/
|
|
535
940
|
function getSettings(properties) {
|
|
536
941
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
@@ -539,21 +944,47 @@ var SettingsMapper = /*#__PURE__*/function () {
|
|
|
539
944
|
_ref$isInit = _ref.isInit,
|
|
540
945
|
isInit = _ref$isInit === void 0 ? false : _ref$isInit,
|
|
541
946
|
_ref$initOnlySettingK = _ref.initOnlySettingKeys,
|
|
542
|
-
initOnlySettingKeys = _ref$initOnlySettingK === void 0 ? [] : _ref$initOnlySettingK
|
|
947
|
+
initOnlySettingKeys = _ref$initOnlySettingK === void 0 ? [] : _ref$initOnlySettingK,
|
|
948
|
+
currentSettings = _ref.currentSettings,
|
|
949
|
+
forwardedSettings = _ref.forwardedSettings;
|
|
543
950
|
var shouldSkipProp = function shouldSkipProp(key) {
|
|
544
|
-
if (
|
|
545
|
-
return
|
|
951
|
+
if (isInit) {
|
|
952
|
+
return false;
|
|
546
953
|
}
|
|
547
|
-
|
|
954
|
+
|
|
955
|
+
// Checked before the value comparison below. The two lists do not overlap today, but a
|
|
956
|
+
// changed deep-comparable key used to return early and skip this guard entirely, which would
|
|
957
|
+
// have forwarded an init-only key to `updateSettings` as soon as one joined both lists.
|
|
958
|
+
if (initOnlySettingKeys.includes(key)) {
|
|
548
959
|
return true;
|
|
549
960
|
}
|
|
961
|
+
if (DEEP_COMPARABLE_SETTINGS.includes(key)) {
|
|
962
|
+
var comparedValue = currentSettings && COMPARED_AGAINST_LIVE_SETTINGS.includes(key) ? currentSettings[key] : prevProps[key];
|
|
963
|
+
return areEquivalentSettingsValue(comparedValue, properties[key]);
|
|
964
|
+
}
|
|
550
965
|
return false;
|
|
551
966
|
};
|
|
967
|
+
var isNotPassed = function isNotPassed(key) {
|
|
968
|
+
return properties[key] === undefined && (isInit || prevProps[key] === undefined);
|
|
969
|
+
};
|
|
552
970
|
var newSettings = {};
|
|
553
|
-
|
|
554
|
-
if (key !== 'children' && !
|
|
555
|
-
|
|
971
|
+
Object.keys(properties).forEach(function (key) {
|
|
972
|
+
if (key !== 'children' && !isNotPassed(key) && !shouldSkipProp(key)) {
|
|
973
|
+
var settingKey = key;
|
|
974
|
+
var value = getForwardedValue(key, properties[key], isInit);
|
|
975
|
+
if (isInit || DEEP_COMPARABLE_SETTINGS.includes(settingKey) || !isSameAsForwarded(settingKey, value, forwardedSettings)) {
|
|
976
|
+
newSettings[key] = value;
|
|
977
|
+
recordForwarded(settingKey, value, forwardedSettings);
|
|
978
|
+
}
|
|
556
979
|
}
|
|
980
|
+
});
|
|
981
|
+
if (!isInit) {
|
|
982
|
+
Object.keys(prevProps).forEach(function (key) {
|
|
983
|
+
if (!Object.hasOwn(properties, key) && prevProps[key] !== undefined && isHookKey(key)) {
|
|
984
|
+
newSettings[key] = null;
|
|
985
|
+
recordForwarded(key, null, forwardedSettings);
|
|
986
|
+
}
|
|
987
|
+
});
|
|
557
988
|
}
|
|
558
989
|
return newSettings;
|
|
559
990
|
}
|
|
@@ -571,39 +1002,100 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
571
1002
|
columnsSettings.current.length = length;
|
|
572
1003
|
}, []);
|
|
573
1004
|
var componentRendererColumns = React.useRef(new Map());
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
1005
|
+
// One entry per cell the grid shows with a component renderer: the cell element, the container in
|
|
1006
|
+
// it, and the portal that renders the component into the container. Keyed by the portal container key.
|
|
1007
|
+
var cellPortals = React.useRef(new Map());
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* The renderer function made for each renderer component. It reads everything else through refs, so
|
|
1011
|
+
* one function serves every render, and an update that passes the same `<HotColumn>` settings again
|
|
1012
|
+
* finds them unchanged and leaves `columns` out.
|
|
1013
|
+
*/
|
|
1014
|
+
var rendererWrappers = React.useRef(new WeakMap());
|
|
580
1015
|
// Keys of the portal containers rendered in the current view-render pass.
|
|
581
|
-
// Reset every `beforeViewRender` and used after the render to
|
|
582
|
-
//
|
|
1016
|
+
// Reset every `beforeViewRender` and used after the render to tell the cells
|
|
1017
|
+
// the pass painted from the ones it did not (see pushCellPortalsIntoPortalManager).
|
|
583
1018
|
var renderedPortalContainerKeys = React.useRef(new Set());
|
|
584
|
-
|
|
585
|
-
|
|
1019
|
+
// Cell elements the grid painted in the current view-render pass, with any renderer. A cell element
|
|
1020
|
+
// the grid reuses for another cell keeps a component container when the new renderer does not clear
|
|
1021
|
+
// the element, so a connected container alone does not prove its cell is still shown.
|
|
1022
|
+
var paintedCells = React.useRef(new Set());
|
|
1023
|
+
var resetRenderedPortals = React.useCallback(function () {
|
|
586
1024
|
renderedPortalContainerKeys.current.clear();
|
|
1025
|
+
paintedCells.current.clear();
|
|
1026
|
+
}, []);
|
|
1027
|
+
var markCellPainted = React.useCallback(function (TD) {
|
|
1028
|
+
if (cellPortals.current.size > 0) {
|
|
1029
|
+
paintedCells.current.add(TD);
|
|
1030
|
+
}
|
|
587
1031
|
}, []);
|
|
588
1032
|
var getPortalContainerCacheSize = React.useCallback(function () {
|
|
589
|
-
return
|
|
1033
|
+
return cellPortals.current.size;
|
|
1034
|
+
}, []);
|
|
1035
|
+
|
|
1036
|
+
// Stable id per table element the grid draws into. Handsontable renders the
|
|
1037
|
+
// same cell once per table it appears in — the master table plus an overlay
|
|
1038
|
+
// table for every fixed row/column edge — and each draw gets its own TD.
|
|
1039
|
+
var tableIds = React.useRef(new WeakMap());
|
|
1040
|
+
var nextTableId = React.useRef(0);
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Identify the table a rendered cell belongs to, so the master table and the
|
|
1044
|
+
* overlay tables get separate portal containers for the same cell.
|
|
1045
|
+
*
|
|
1046
|
+
* @param {HTMLTableCellElement} TD The cell being rendered.
|
|
1047
|
+
* @returns {number} The id of the table the cell belongs to.
|
|
1048
|
+
*/
|
|
1049
|
+
var getTableId = React.useCallback(function (TD) {
|
|
1050
|
+
var _TD$parentElement$par, _TD$parentElement;
|
|
1051
|
+
// TD -> TR -> TBODY. The section belongs to exactly one table, and the
|
|
1052
|
+
// overlay tables are built once and never hand their cells to another
|
|
1053
|
+
// table, so it is a stable identity for the draw. Two property hops rather
|
|
1054
|
+
// than a selector walk, because this runs for every component-rendered
|
|
1055
|
+
// cell on every render.
|
|
1056
|
+
var tableSection = (_TD$parentElement$par = (_TD$parentElement = TD.parentElement) === null || _TD$parentElement === void 0 ? void 0 : _TD$parentElement.parentElement) !== null && _TD$parentElement$par !== void 0 ? _TD$parentElement$par : TD;
|
|
1057
|
+
var cachedId = tableIds.current.get(tableSection);
|
|
1058
|
+
if (cachedId !== undefined) {
|
|
1059
|
+
return cachedId;
|
|
1060
|
+
}
|
|
1061
|
+
var id = nextTableId.current;
|
|
1062
|
+
nextTableId.current += 1;
|
|
1063
|
+
tableIds.current.set(tableSection, id);
|
|
1064
|
+
return id;
|
|
590
1065
|
}, []);
|
|
591
1066
|
var getRendererWrapper = React.useCallback(function (Renderer) {
|
|
592
|
-
|
|
1067
|
+
var cachedWrapper = rendererWrappers.current.get(Renderer);
|
|
1068
|
+
if (cachedWrapper) {
|
|
1069
|
+
return cachedWrapper;
|
|
1070
|
+
}
|
|
1071
|
+
warnAboutClassicFunctionRenderer(Renderer);
|
|
1072
|
+
var wrapper = function __internalRenderer(instance, TD, row, col, prop, value, cellProperties) {
|
|
593
1073
|
var key = "".concat(row, "-").concat(col);
|
|
594
1074
|
|
|
595
1075
|
// Handsontable.Core type is missing guid
|
|
596
1076
|
var instanceGuid = instance.guid;
|
|
597
|
-
var portalContainerKey = "".concat(instanceGuid, "-").concat(key);
|
|
598
|
-
var portalKey = "".concat(key, "-").concat(instanceGuid);
|
|
599
1077
|
if (TD && !TD.getAttribute('ghost-table')) {
|
|
600
|
-
var
|
|
1078
|
+
var _cellPortals$current$;
|
|
1079
|
+
// The table has to be part of the key. A cell that sits in a fixed
|
|
1080
|
+
// column is drawn both in the master table and in the inline-start
|
|
1081
|
+
// overlay; keyed by coordinates alone, both draws share one container,
|
|
1082
|
+
// which then moves into whichever table rendered last and leaves the
|
|
1083
|
+
// other cell empty. The two tables then size their rows from different
|
|
1084
|
+
// content and stop lining up (see issue #9063).
|
|
1085
|
+
var tableId = getTableId(TD);
|
|
1086
|
+
var portalContainerKey = "".concat(instanceGuid, "-").concat(tableId, "-").concat(key);
|
|
1087
|
+
var portalKey = "".concat(key, "-").concat(tableId, "-").concat(instanceGuid);
|
|
1088
|
+
var cachedPortalContainer = (_cellPortals$current$ = cellPortals.current.get(portalContainerKey)) === null || _cellPortals$current$ === void 0 ? void 0 : _cellPortals$current$.container;
|
|
601
1089
|
// When the cached portal container is still attached to the same
|
|
602
1090
|
// TD as the previous render, the DOM is already correct and must
|
|
603
1091
|
// not be wiped. Wiping detaches the React-managed children, which
|
|
604
1092
|
// forces a full remount of the renderer component on every grid
|
|
605
1093
|
// render (see issue #10800).
|
|
606
|
-
|
|
1094
|
+
// A row rendered at an exact height (the `rowHeights` option) keeps the cell's content inside a
|
|
1095
|
+
// `div.htCellClip` wrapper that the grid adds after this renderer ran. The container then sits in
|
|
1096
|
+
// the wrapper, and wiping the cell on the next render would detach it all over again.
|
|
1097
|
+
var contentRoot = getCellContentRoot(TD);
|
|
1098
|
+
var containerInPlace = !!cachedPortalContainer && cachedPortalContainer.parentNode === contentRoot;
|
|
607
1099
|
var rendererElement = /*#__PURE__*/React__default["default"].createElement(Renderer, {
|
|
608
1100
|
instance: instance,
|
|
609
1101
|
TD: TD,
|
|
@@ -617,19 +1109,23 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
617
1109
|
portal = _createPortal.portal,
|
|
618
1110
|
portalContainer = _createPortal.portalContainer;
|
|
619
1111
|
if (!containerInPlace) {
|
|
620
|
-
while (
|
|
621
|
-
|
|
1112
|
+
while (contentRoot.firstChild) {
|
|
1113
|
+
contentRoot.removeChild(contentRoot.firstChild);
|
|
622
1114
|
}
|
|
623
|
-
|
|
1115
|
+
contentRoot.appendChild(portalContainer);
|
|
624
1116
|
}
|
|
625
|
-
|
|
1117
|
+
cellPortals.current.set(portalContainerKey, {
|
|
1118
|
+
TD: TD,
|
|
1119
|
+
container: portalContainer,
|
|
1120
|
+
portal: portal
|
|
1121
|
+
});
|
|
626
1122
|
renderedPortalContainerKeys.current.add(portalContainerKey);
|
|
627
|
-
portalCache.current.set(portalKey, portal);
|
|
628
1123
|
}
|
|
629
|
-
renderedCellCache.current.set(key, TD);
|
|
630
1124
|
return TD;
|
|
631
1125
|
};
|
|
632
|
-
|
|
1126
|
+
rendererWrappers.current.set(Renderer, wrapper);
|
|
1127
|
+
return wrapper;
|
|
1128
|
+
}, [getTableId]);
|
|
633
1129
|
var renderersPortalManager = React.useRef(function () {
|
|
634
1130
|
return undefined;
|
|
635
1131
|
});
|
|
@@ -637,19 +1133,29 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
637
1133
|
renderersPortalManager.current = pmComponent;
|
|
638
1134
|
}, []);
|
|
639
1135
|
var pushCellPortalsIntoPortalManager = React.useCallback(function () {
|
|
640
|
-
//
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
//
|
|
644
|
-
//
|
|
645
|
-
//
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
1136
|
+
// A cell this pass did not paint with its component either left the grid or
|
|
1137
|
+
// was skipped. The grid skips a cell that did not change (`renderMode:
|
|
1138
|
+
// 'onChange'`) and leaves its element as it is, so the portal must stay or
|
|
1139
|
+
// React unmounts the component and the cell goes blank. A cell that left the
|
|
1140
|
+
// grid had its element removed (the container is detached), or its element
|
|
1141
|
+
// was painted for another cell this pass (with a renderer that may not clear
|
|
1142
|
+
// the element): evict those, or the cache leaks O(rows × cols) nodes and a
|
|
1143
|
+
// stale component stays visible. Kept entries also preserve the in-place
|
|
1144
|
+
// reuse that avoids remounting renderer components on every grid render
|
|
1145
|
+
// (#10800).
|
|
1146
|
+
var paintedKeys = renderedPortalContainerKeys.current;
|
|
1147
|
+
var portals = [];
|
|
1148
|
+
cellPortals.current.forEach(function (_ref2, cacheKey) {
|
|
1149
|
+
var TD = _ref2.TD,
|
|
1150
|
+
container = _ref2.container,
|
|
1151
|
+
portal = _ref2.portal;
|
|
1152
|
+
if (!paintedKeys.has(cacheKey) && (!container.isConnected || paintedCells.current.has(TD))) {
|
|
1153
|
+
cellPortals.current["delete"](cacheKey);
|
|
1154
|
+
return;
|
|
650
1155
|
}
|
|
1156
|
+
portals.push(portal);
|
|
651
1157
|
});
|
|
652
|
-
renderersPortalManager.current(
|
|
1158
|
+
renderersPortalManager.current(portals);
|
|
653
1159
|
}, []);
|
|
654
1160
|
var contextImpl = React.useMemo(function () {
|
|
655
1161
|
return {
|
|
@@ -658,13 +1164,13 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
658
1164
|
emitColumnSettings: setHotColumnSettings,
|
|
659
1165
|
trimColumnSettings: trimColumnSettings,
|
|
660
1166
|
getRendererWrapper: getRendererWrapper,
|
|
661
|
-
|
|
662
|
-
|
|
1167
|
+
resetRenderedPortals: resetRenderedPortals,
|
|
1168
|
+
markCellPainted: markCellPainted,
|
|
663
1169
|
getPortalContainerCacheSize: getPortalContainerCacheSize,
|
|
664
1170
|
setRenderersPortalManagerRef: setRenderersPortalManagerRef,
|
|
665
1171
|
pushCellPortalsIntoPortalManager: pushCellPortalsIntoPortalManager
|
|
666
1172
|
};
|
|
667
|
-
}, [setHotColumnSettings, trimColumnSettings, getRendererWrapper,
|
|
1173
|
+
}, [setHotColumnSettings, trimColumnSettings, getRendererWrapper, resetRenderedPortals, markCellPainted, getPortalContainerCacheSize, setRenderersPortalManagerRef, pushCellPortalsIntoPortalManager]);
|
|
668
1174
|
return /*#__PURE__*/React__default["default"].createElement(HotTableContext.Provider, {
|
|
669
1175
|
value: contextImpl
|
|
670
1176
|
}, children);
|
|
@@ -673,7 +1179,7 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
673
1179
|
/**
|
|
674
1180
|
* Exposes the table context object to components
|
|
675
1181
|
*
|
|
676
|
-
* @returns HotTableContext
|
|
1182
|
+
* @returns {HotTableContextImpl} HotTableContext
|
|
677
1183
|
*/
|
|
678
1184
|
function useHotTableContext() {
|
|
679
1185
|
return React.useContext(HotTableContext);
|
|
@@ -683,13 +1189,15 @@ var HotColumnContext = /*#__PURE__*/React.createContext(undefined);
|
|
|
683
1189
|
var HotColumnContextProvider = function HotColumnContextProvider(_ref) {
|
|
684
1190
|
var columnIndex = _ref.columnIndex,
|
|
685
1191
|
getOwnerDocument = _ref.getOwnerDocument,
|
|
1192
|
+
getEditorPortalHost = _ref.getEditorPortalHost,
|
|
686
1193
|
children = _ref.children;
|
|
687
1194
|
var contextImpl = React.useMemo(function () {
|
|
688
1195
|
return {
|
|
689
1196
|
columnIndex: columnIndex,
|
|
690
|
-
getOwnerDocument: getOwnerDocument
|
|
1197
|
+
getOwnerDocument: getOwnerDocument,
|
|
1198
|
+
getEditorPortalHost: getEditorPortalHost
|
|
691
1199
|
};
|
|
692
|
-
}, [columnIndex, getOwnerDocument]);
|
|
1200
|
+
}, [columnIndex, getOwnerDocument, getEditorPortalHost]);
|
|
693
1201
|
return /*#__PURE__*/React__default["default"].createElement(HotColumnContext.Provider, {
|
|
694
1202
|
value: contextImpl
|
|
695
1203
|
}, children);
|
|
@@ -708,14 +1216,26 @@ var MethodsMap = {
|
|
|
708
1216
|
};
|
|
709
1217
|
|
|
710
1218
|
/**
|
|
711
|
-
*
|
|
1219
|
+
* The editor class made for each component's hooks reference. The class reads the hooks and the instance
|
|
1220
|
+
* through those references when it runs, so one class serves every render of the component, and an
|
|
1221
|
+
* update that passes the same class is left out like any other unchanged setting.
|
|
1222
|
+
*/
|
|
1223
|
+
var editorClasses = new WeakMap();
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Create a class to be passed to the Handsontable's settings, or return the one made for the same hooks
|
|
1227
|
+
* reference.
|
|
712
1228
|
*
|
|
713
1229
|
* @param {RefObject<HotEditorHooks>} hooksRef Reference to component-based editor overridden hooks object.
|
|
714
1230
|
* @param {RefObject} instanceRef Reference to Handsontable-native custom editor class instance.
|
|
715
1231
|
* @returns {Function} A class to be passed to the Handsontable editor settings.
|
|
716
1232
|
*/
|
|
717
1233
|
function makeEditorClass(hooksRef, instanceRef) {
|
|
718
|
-
|
|
1234
|
+
var cachedEditorClass = editorClasses.get(hooksRef);
|
|
1235
|
+
if (cachedEditorClass) {
|
|
1236
|
+
return cachedEditorClass;
|
|
1237
|
+
}
|
|
1238
|
+
var EditorClass = /*#__PURE__*/function (_Handsontable$editors) {
|
|
719
1239
|
function CustomEditor(hotInstance) {
|
|
720
1240
|
var _this;
|
|
721
1241
|
_classCallCheck(this, CustomEditor);
|
|
@@ -767,6 +1287,8 @@ function makeEditorClass(hooksRef, instanceRef) {
|
|
|
767
1287
|
value: function close() {}
|
|
768
1288
|
}]);
|
|
769
1289
|
}(Handsontable__default["default"].editors.BaseEditor);
|
|
1290
|
+
editorClasses.set(hooksRef, EditorClass);
|
|
1291
|
+
return EditorClass;
|
|
770
1292
|
}
|
|
771
1293
|
/**
|
|
772
1294
|
* Context to provide Handsontable-native custom editor class instance to overridden hooks object.
|
|
@@ -776,8 +1298,11 @@ var EditorContext = /*#__PURE__*/React.createContext(undefined);
|
|
|
776
1298
|
* Provider of the context that exposes Handsontable-native editor instance and passes hooks object
|
|
777
1299
|
* for custom editor components.
|
|
778
1300
|
*
|
|
779
|
-
* @param {
|
|
780
|
-
* @param {
|
|
1301
|
+
* @param {object} root0 The provider props.
|
|
1302
|
+
* @param {Ref} root0.hooksRef Reference for component-based editor overridden hooks object.
|
|
1303
|
+
* @param {RefObject} root0.hotCustomEditorInstanceRef Reference to Handsontable-native editor instance.
|
|
1304
|
+
* @param {ReactNode} root0.children The provider's children.
|
|
1305
|
+
* @returns {ReactElement} The provider component.
|
|
781
1306
|
*/
|
|
782
1307
|
var EditorContextProvider = function EditorContextProvider(_ref3) {
|
|
783
1308
|
var hooksRef = _ref3.hooksRef,
|
|
@@ -792,7 +1317,13 @@ var EditorContextProvider = function EditorContextProvider(_ref3) {
|
|
|
792
1317
|
};
|
|
793
1318
|
/**
|
|
794
1319
|
* Applies editor overlay position/dimensions to an element.
|
|
795
|
-
*
|
|
1320
|
+
*
|
|
1321
|
+
* @param {HTMLElement} el The editor's main element.
|
|
1322
|
+
* @param {EditorWithPosition} editor The editor instance.
|
|
1323
|
+
* @param {Handsontable.Core} hot The Handsontable instance.
|
|
1324
|
+
* @param {Element | null | undefined} td The edited cell's TD element.
|
|
1325
|
+
* @returns {boolean} `true` if position was applied, `false` if editor should close (e.g. cell no longer
|
|
1326
|
+
* available).
|
|
796
1327
|
*/
|
|
797
1328
|
function applyEditorPosition(el, editor, hot, td) {
|
|
798
1329
|
var _rootWindow$pageXOffs, _rootWindow$pageYOffs;
|
|
@@ -844,7 +1375,7 @@ function applyEditorPosition(el, editor, hot, td) {
|
|
|
844
1375
|
}
|
|
845
1376
|
|
|
846
1377
|
/**
|
|
847
|
-
* Hook that allows encapsulating custom
|
|
1378
|
+
* Hook that allows encapsulating custom behaviors of component-based editor by customizing passed ref with overridden hooks object.
|
|
848
1379
|
*
|
|
849
1380
|
* @param {HotEditorHooks} overriddenHooks Overrides specific for the custom editor.
|
|
850
1381
|
* @param {DependencyList} deps Overridden hooks object React dependency list.
|
|
@@ -862,15 +1393,12 @@ function useHotEditor(overriddenHooks, deps) {
|
|
|
862
1393
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
863
1394
|
editorValue = _useState4[0],
|
|
864
1395
|
setEditorValue = _useState4[1];
|
|
865
|
-
|
|
866
|
-
// return a deferred value that allows for optimizing performance by delaying the update of a value until the next render.
|
|
867
|
-
var deferredValue = React.useDeferredValue(editorValue);
|
|
868
1396
|
React.useImperativeHandle(hooksRef, function () {
|
|
869
1397
|
return _objectSpread2(_objectSpread2({}, overriddenHooks), {}, {
|
|
870
|
-
onOpen: function onOpen() {
|
|
1398
|
+
onOpen: function onOpen(event) {
|
|
871
1399
|
var _hotCustomEditorInsta, _overriddenHooks$onOp;
|
|
872
1400
|
setEditorValue((_hotCustomEditorInsta = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta === void 0 ? void 0 : _hotCustomEditorInsta.getValue());
|
|
873
|
-
overriddenHooks === null || overriddenHooks === void 0 || (_overriddenHooks$onOp = overriddenHooks.onOpen) === null || _overriddenHooks$onOp === void 0 || _overriddenHooks$onOp.call(overriddenHooks);
|
|
1401
|
+
overriddenHooks === null || overriddenHooks === void 0 || (_overriddenHooks$onOp = overriddenHooks.onOpen) === null || _overriddenHooks$onOp === void 0 || _overriddenHooks$onOp.call(overriddenHooks, event);
|
|
874
1402
|
setRerenderTrigger(function (t) {
|
|
875
1403
|
return t + 1;
|
|
876
1404
|
});
|
|
@@ -880,7 +1408,7 @@ function useHotEditor(overriddenHooks, deps) {
|
|
|
880
1408
|
return React.useMemo(function () {
|
|
881
1409
|
return {
|
|
882
1410
|
get value() {
|
|
883
|
-
return
|
|
1411
|
+
return editorValue;
|
|
884
1412
|
},
|
|
885
1413
|
setValue: function setValue(newValue) {
|
|
886
1414
|
var _hotCustomEditorInsta2;
|
|
@@ -906,21 +1434,35 @@ function useHotEditor(overriddenHooks, deps) {
|
|
|
906
1434
|
return col !== null && col !== void 0 ? col : undefined;
|
|
907
1435
|
}
|
|
908
1436
|
};
|
|
909
|
-
}, [rerenderTrigger, hotCustomEditorInstanceRef,
|
|
1437
|
+
}, [rerenderTrigger, hotCustomEditorInstanceRef, editorValue]);
|
|
910
1438
|
}
|
|
911
1439
|
|
|
912
1440
|
// Render prop function type
|
|
913
1441
|
|
|
914
1442
|
// EditorComponent props - children typed to work with JSX syntax
|
|
915
1443
|
|
|
1444
|
+
/**
|
|
1445
|
+
* Component-based editor. Renders the `children` render prop inside the editor's positioned overlay
|
|
1446
|
+
* and wires up its shortcuts and scroll-repositioning.
|
|
1447
|
+
*
|
|
1448
|
+
* @param {object} root0 The component props.
|
|
1449
|
+
* @param {Function} [root0.onPrepare] Called when the editor is prepared for a cell.
|
|
1450
|
+
* @param {Function} [root0.onClose] Called when the editor closes.
|
|
1451
|
+
* @param {Function} [root0.onOpen] Called when the editor opens. Receives the DOM event that opened the editor. It is `undefined` when you call `beginEditing()`.
|
|
1452
|
+
* @param {Function} [root0.onFocus] Called when the editor is focused.
|
|
1453
|
+
* @param {EditorRenderProp} [root0.children] Render prop returning the editor's UI.
|
|
1454
|
+
* @param {string} [root0.shortcutsGroup] The shortcuts group name to register under.
|
|
1455
|
+
* @param {Array} [root0.shortcuts] The editor's keyboard shortcuts.
|
|
1456
|
+
* @returns {React.ReactElement} The editor overlay element.
|
|
1457
|
+
*/
|
|
916
1458
|
function EditorComponent(_ref5) {
|
|
917
1459
|
var _onPrepare = _ref5.onPrepare,
|
|
918
1460
|
_onClose = _ref5.onClose,
|
|
919
|
-
|
|
1461
|
+
onOpen = _ref5.onOpen,
|
|
920
1462
|
_onFocus = _ref5.onFocus,
|
|
921
1463
|
children = _ref5.children,
|
|
922
1464
|
_ref5$shortcutsGroup = _ref5.shortcutsGroup,
|
|
923
|
-
shortcutsGroup = _ref5$shortcutsGroup === void 0 ?
|
|
1465
|
+
shortcutsGroup = _ref5$shortcutsGroup === void 0 ? 'custom-editor' : _ref5$shortcutsGroup,
|
|
924
1466
|
shortcuts = _ref5.shortcuts;
|
|
925
1467
|
var mainElementRef = React.useRef(null);
|
|
926
1468
|
var currentValue = React.useRef(undefined);
|
|
@@ -932,8 +1474,10 @@ function EditorComponent(_ref5) {
|
|
|
932
1474
|
hotCustomEditorInstanceRef = _ref6.hotCustomEditorInstanceRef;
|
|
933
1475
|
var registerShortcuts = React.useCallback(function () {
|
|
934
1476
|
var _hotCustomEditorInsta8, _hotCustomEditorInsta9, _hotCustomEditorInsta0;
|
|
935
|
-
if (!((_hotCustomEditorInsta8 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta8 !== void 0 && _hotCustomEditorInsta8.hot))
|
|
936
|
-
|
|
1477
|
+
if (!((_hotCustomEditorInsta8 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta8 !== void 0 && _hotCustomEditorInsta8.hot)) {
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
(_hotCustomEditorInsta9 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta9 === void 0 || (_hotCustomEditorInsta9 = _hotCustomEditorInsta9.hot) === null || _hotCustomEditorInsta9 === void 0 || _hotCustomEditorInsta9.getShortcutManager().setActiveContextName('editor');
|
|
937
1481
|
var shortcutManager = (_hotCustomEditorInsta0 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta0 === void 0 || (_hotCustomEditorInsta0 = _hotCustomEditorInsta0.hot) === null || _hotCustomEditorInsta0 === void 0 ? void 0 : _hotCustomEditorInsta0.getShortcutManager();
|
|
938
1482
|
var editorContext = shortcutManager.getContext('editor');
|
|
939
1483
|
var contextConfig = {
|
|
@@ -953,61 +1497,97 @@ function EditorComponent(_ref5) {
|
|
|
953
1497
|
}, event);
|
|
954
1498
|
}
|
|
955
1499
|
});
|
|
956
|
-
}),
|
|
957
|
-
//@ts-ignore
|
|
958
|
-
contextConfig);
|
|
1500
|
+
}), contextConfig);
|
|
959
1501
|
}
|
|
960
1502
|
}, [shortcuts]);
|
|
961
1503
|
var unRegisterShortcuts = React.useCallback(function () {
|
|
962
1504
|
var _hotCustomEditorInsta1, _hotCustomEditorInsta10;
|
|
963
|
-
if (!((_hotCustomEditorInsta1 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta1 !== void 0 && _hotCustomEditorInsta1.hot))
|
|
1505
|
+
if (!((_hotCustomEditorInsta1 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta1 !== void 0 && _hotCustomEditorInsta1.hot)) {
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
964
1508
|
var shortcutManager = (_hotCustomEditorInsta10 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta10 === void 0 || (_hotCustomEditorInsta10 = _hotCustomEditorInsta10.hot) === null || _hotCustomEditorInsta10 === void 0 ? void 0 : _hotCustomEditorInsta10.getShortcutManager();
|
|
965
|
-
var editorContext = shortcutManager.getContext(
|
|
1509
|
+
var editorContext = shortcutManager.getContext('editor');
|
|
966
1510
|
editorContext.removeShortcutsByGroup(shortcutsGroup);
|
|
967
1511
|
}, [shortcuts]);
|
|
968
1512
|
var refreshDimensions = React.useCallback(function () {
|
|
969
1513
|
var editor = hotCustomEditorInstanceRef.current;
|
|
970
1514
|
var el = mainElementRef.current;
|
|
971
|
-
if (!editor || !el)
|
|
1515
|
+
if (!editor || !el) {
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
972
1518
|
var hot = editor.hot;
|
|
973
|
-
if (!hot)
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1519
|
+
if (!hot) {
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
if (typeof editor.isOpened !== 'function' || !editor.isOpened()) {
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// Leave an editor that waits for an async validator alone, as core `TextEditor` does. The scroll
|
|
1527
|
+
// hooks call this without core's wait, and a cancel here would not stop the pending validation:
|
|
1528
|
+
// a rejected value then put the editor back in edit mode while it was closed.
|
|
1529
|
+
if (editor.state !== 'STATE_EDITING') {
|
|
1530
|
+
return;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
// The edited cell is not rendered (it scrolled out of view). End the edit without saving and reset
|
|
1534
|
+
// the editor, so the next key starts a new edit. A bare `close()` hid the element but left the
|
|
1535
|
+
// editor open, so it never showed again and kept the keyboard.
|
|
1536
|
+
if (!applyEditorPosition(el, editor, hot)) {
|
|
1537
|
+
editor.cancelChanges();
|
|
977
1538
|
}
|
|
978
1539
|
}, []);
|
|
979
1540
|
var unRegisterScrollHooks = React.useCallback(function () {
|
|
980
1541
|
var editor = hotCustomEditorInstanceRef.current;
|
|
981
1542
|
var hot = editor === null || editor === void 0 ? void 0 : editor.hot;
|
|
982
|
-
if (!hot || typeof hot.removeHook !== 'function')
|
|
1543
|
+
if (!hot || typeof hot.removeHook !== 'function') {
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
983
1546
|
hot.removeHook('afterScrollHorizontally', refreshDimensions);
|
|
984
1547
|
hot.removeHook('afterScrollVertically', refreshDimensions);
|
|
985
1548
|
}, [refreshDimensions]);
|
|
986
1549
|
var registerScrollHooks = React.useCallback(function () {
|
|
987
1550
|
var editor = hotCustomEditorInstanceRef.current;
|
|
988
1551
|
var hot = editor === null || editor === void 0 ? void 0 : editor.hot;
|
|
989
|
-
if (!hot || typeof hot.addHook !== 'function')
|
|
1552
|
+
if (!hot || typeof hot.addHook !== 'function') {
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
990
1555
|
hot.addHook('afterScrollHorizontally', refreshDimensions);
|
|
991
1556
|
hot.addHook('afterScrollVertically', refreshDimensions);
|
|
992
1557
|
}, [refreshDimensions]);
|
|
993
1558
|
var _useHotEditor = useHotEditor({
|
|
994
|
-
onOpen: function
|
|
1559
|
+
onOpen: function (_onOpen) {
|
|
1560
|
+
function onOpen(_x) {
|
|
1561
|
+
return _onOpen.apply(this, arguments);
|
|
1562
|
+
}
|
|
1563
|
+
onOpen.toString = function () {
|
|
1564
|
+
return _onOpen.toString();
|
|
1565
|
+
};
|
|
1566
|
+
return onOpen;
|
|
1567
|
+
}(function (event) {
|
|
995
1568
|
var _hotCustomEditorInsta11;
|
|
996
|
-
if (!mainElementRef.current)
|
|
1569
|
+
if (!mainElementRef.current) {
|
|
1570
|
+
return;
|
|
1571
|
+
}
|
|
997
1572
|
var themeName = (_hotCustomEditorInsta11 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta11 === void 0 ? void 0 : _hotCustomEditorInsta11.hot.getCurrentThemeName();
|
|
998
|
-
if (themeName)
|
|
1573
|
+
if (themeName) {
|
|
1574
|
+
setThemeClassName(themeName);
|
|
1575
|
+
}
|
|
999
1576
|
mainElementRef.current.style.display = 'block';
|
|
1000
|
-
_onOpen === null || _onOpen === void 0 || _onOpen();
|
|
1001
1577
|
var el = mainElementRef.current;
|
|
1002
1578
|
var editor = hotCustomEditorInstanceRef.current;
|
|
1003
1579
|
if (el && editor !== null && editor !== void 0 && editor.hot) {
|
|
1004
1580
|
applyEditorPosition(el, editor, editor.hot);
|
|
1581
|
+
editor.refreshDimensions = refreshDimensions;
|
|
1005
1582
|
}
|
|
1583
|
+
onOpen === null || onOpen === void 0 || onOpen(event);
|
|
1006
1584
|
registerShortcuts();
|
|
1007
1585
|
registerScrollHooks();
|
|
1008
|
-
},
|
|
1586
|
+
}),
|
|
1009
1587
|
onClose: function onClose() {
|
|
1010
|
-
if (!mainElementRef.current)
|
|
1588
|
+
if (!mainElementRef.current) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1011
1591
|
mainElementRef.current.style.display = 'none';
|
|
1012
1592
|
_onClose === null || _onClose === void 0 || _onClose();
|
|
1013
1593
|
unRegisterShortcuts();
|
|
@@ -1066,7 +1646,8 @@ var HotColumn = function HotColumn(props) {
|
|
|
1066
1646
|
getRendererWrapper = _useHotTableContext.getRendererWrapper;
|
|
1067
1647
|
var _useHotColumnContext = useHotColumnContext(),
|
|
1068
1648
|
columnIndex = _useHotColumnContext.columnIndex,
|
|
1069
|
-
getOwnerDocument = _useHotColumnContext.getOwnerDocument
|
|
1649
|
+
getOwnerDocument = _useHotColumnContext.getOwnerDocument,
|
|
1650
|
+
getEditorPortalHost = _useHotColumnContext.getEditorPortalHost;
|
|
1070
1651
|
|
|
1071
1652
|
/**
|
|
1072
1653
|
* Reference to component-based editor overridden hooks object.
|
|
@@ -1085,7 +1666,7 @@ var HotColumn = function HotColumn(props) {
|
|
|
1085
1666
|
/**
|
|
1086
1667
|
* Filter out all the internal properties and return an object with just the Handsontable-related props.
|
|
1087
1668
|
*
|
|
1088
|
-
* @returns {
|
|
1669
|
+
* @returns {object}
|
|
1089
1670
|
*/
|
|
1090
1671
|
var getSettingsProps = function getSettingsProps() {
|
|
1091
1672
|
return Object.keys(props).filter(function (key) {
|
|
@@ -1098,6 +1679,8 @@ var HotColumn = function HotColumn(props) {
|
|
|
1098
1679
|
|
|
1099
1680
|
/**
|
|
1100
1681
|
* Create the column settings based on the data provided to the `HotColumn` component and its child components.
|
|
1682
|
+
*
|
|
1683
|
+
* @returns {object} The column settings object.
|
|
1101
1684
|
*/
|
|
1102
1685
|
var createColumnSettings = function createColumnSettings() {
|
|
1103
1686
|
var columnSettings = SettingsMapper.getSettings(getSettingsProps());
|
|
@@ -1107,10 +1690,17 @@ var HotColumn = function HotColumn(props) {
|
|
|
1107
1690
|
} else if (props.hotRenderer) {
|
|
1108
1691
|
columnSettings.renderer = props.hotRenderer;
|
|
1109
1692
|
}
|
|
1110
|
-
if (props.editor) {
|
|
1693
|
+
if (isComponentEditor(props.editor)) {
|
|
1111
1694
|
columnSettings.editor = makeEditorClass(localEditorHooksRef, localEditorClassInstance);
|
|
1112
|
-
} else
|
|
1113
|
-
|
|
1695
|
+
} else {
|
|
1696
|
+
var editorSetting = resolveEditorSetting(props.editor, props.hotEditor);
|
|
1697
|
+
if (editorSetting === undefined) {
|
|
1698
|
+
// Neither prop named an editor. Drop whatever the settings mapper copied over — it can be
|
|
1699
|
+
// a bare `true`, which the core rejects — and let the column inherit the grid editor.
|
|
1700
|
+
delete columnSettings.editor;
|
|
1701
|
+
} else {
|
|
1702
|
+
columnSettings.editor = editorSetting;
|
|
1703
|
+
}
|
|
1114
1704
|
}
|
|
1115
1705
|
return columnSettings;
|
|
1116
1706
|
};
|
|
@@ -1120,7 +1710,7 @@ var HotColumn = function HotColumn(props) {
|
|
|
1120
1710
|
displayAnyChildrenWarning(props.children);
|
|
1121
1711
|
}
|
|
1122
1712
|
});
|
|
1123
|
-
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor);
|
|
1713
|
+
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor, getEditorPortalHost());
|
|
1124
1714
|
|
|
1125
1715
|
/**
|
|
1126
1716
|
* Render the portals of the editors, if there are any.
|
|
@@ -1133,21 +1723,7 @@ var HotColumn = function HotColumn(props) {
|
|
|
1133
1723
|
}, editorPortal);
|
|
1134
1724
|
};
|
|
1135
1725
|
|
|
1136
|
-
var version="
|
|
1137
|
-
|
|
1138
|
-
/**
|
|
1139
|
-
* Component used to manage the renderer component portals.
|
|
1140
|
-
*/
|
|
1141
|
-
var RenderersPortalManager = /*#__PURE__*/React.forwardRef(function (_, ref) {
|
|
1142
|
-
var _useState = React.useState([]),
|
|
1143
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
1144
|
-
portals = _useState2[0],
|
|
1145
|
-
setPortals = _useState2[1];
|
|
1146
|
-
React.useImperativeHandle(ref, function () {
|
|
1147
|
-
return setPortals;
|
|
1148
|
-
});
|
|
1149
|
-
return /*#__PURE__*/React__default["default"].createElement(React.Fragment, null, portals);
|
|
1150
|
-
});
|
|
1726
|
+
var version="19.0.0-rc1";
|
|
1151
1727
|
|
|
1152
1728
|
function getDefaultExportFromCjs (x) {
|
|
1153
1729
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -1245,6 +1821,20 @@ function requireFactoryWithThrowingShims() {
|
|
|
1245
1821
|
var propTypesExports = propTypes.exports;
|
|
1246
1822
|
var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
|
|
1247
1823
|
|
|
1824
|
+
/**
|
|
1825
|
+
* Component used to manage the renderer component portals.
|
|
1826
|
+
*/
|
|
1827
|
+
var RenderersPortalManager = /*#__PURE__*/React.forwardRef(function (_, ref) {
|
|
1828
|
+
var _useState = React.useState([]),
|
|
1829
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1830
|
+
portals = _useState2[0],
|
|
1831
|
+
setPortals = _useState2[1];
|
|
1832
|
+
React.useImperativeHandle(ref, function () {
|
|
1833
|
+
return setPortals;
|
|
1834
|
+
});
|
|
1835
|
+
return /*#__PURE__*/React__default["default"].createElement(React.Fragment, null, portals);
|
|
1836
|
+
});
|
|
1837
|
+
|
|
1248
1838
|
var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
1249
1839
|
/**
|
|
1250
1840
|
* Reference to the Handsontable instance.
|
|
@@ -1266,11 +1856,36 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1266
1856
|
*/
|
|
1267
1857
|
var globalEditorClassInstance = React.useRef(null);
|
|
1268
1858
|
|
|
1859
|
+
/**
|
|
1860
|
+
* Stable host for React editor portals. Appended to `rootPortalElement` after init
|
|
1861
|
+
* so core treats editor UI as inside the grid (see `#isPathWithinGrid`).
|
|
1862
|
+
*/
|
|
1863
|
+
var editorPortalHostRef = React.useRef(null);
|
|
1864
|
+
|
|
1269
1865
|
/**
|
|
1270
1866
|
* Reference to the previous props object.
|
|
1271
1867
|
*/
|
|
1272
1868
|
var prevProps = React.useRef();
|
|
1273
1869
|
|
|
1870
|
+
/**
|
|
1871
|
+
* A copy of the `HotColumn` settings last passed to the grid. The children write their settings
|
|
1872
|
+
* into one array that the grid also holds, so the array itself cannot tell whether they changed.
|
|
1873
|
+
*/
|
|
1874
|
+
var forwardedColumnsSettings = React.useRef(null);
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
* Copies of the settings last passed to the grid, compared with on every update so an unchanged prop
|
|
1878
|
+
* is left out (`SettingsMapper.getSettings()`). Started again for every new instance.
|
|
1879
|
+
*/
|
|
1880
|
+
var forwardedSettings = React.useRef(new Map());
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* Whether the settings last passed to the grid named a grid-level editor (`editor`, `hotEditor`) and a
|
|
1884
|
+
* grid-level renderer (`renderer`, `hotRenderer`).
|
|
1885
|
+
*/
|
|
1886
|
+
var namedGlobalEditor = React.useRef(false);
|
|
1887
|
+
var namedGlobalRenderer = React.useRef(false);
|
|
1888
|
+
|
|
1274
1889
|
/**
|
|
1275
1890
|
* HotTable context exposing helper functions.
|
|
1276
1891
|
*/
|
|
@@ -1296,7 +1911,6 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1296
1911
|
* Clear both the editor and the renderer cache.
|
|
1297
1912
|
*/
|
|
1298
1913
|
var clearCache = React.useCallback(function () {
|
|
1299
|
-
context.clearRenderedCellCache();
|
|
1300
1914
|
context.componentRendererColumns.clear();
|
|
1301
1915
|
}, [context]);
|
|
1302
1916
|
|
|
@@ -1312,42 +1926,94 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1312
1926
|
return null;
|
|
1313
1927
|
}, [hotElementRef]);
|
|
1314
1928
|
|
|
1929
|
+
/**
|
|
1930
|
+
* Get or create the stable editor portal host.
|
|
1931
|
+
*
|
|
1932
|
+
* @returns {HTMLElement | null} The host element, or `null` before a document is available.
|
|
1933
|
+
*/
|
|
1934
|
+
var getEditorPortalHost = React.useCallback(function () {
|
|
1935
|
+
var doc = getOwnerDocument();
|
|
1936
|
+
if (!doc) {
|
|
1937
|
+
return null;
|
|
1938
|
+
}
|
|
1939
|
+
if (!editorPortalHostRef.current) {
|
|
1940
|
+
var host = doc.createElement('div');
|
|
1941
|
+
host.className = EDITOR_PORTAL_HOST_CLASSNAME;
|
|
1942
|
+
doc.body.appendChild(host);
|
|
1943
|
+
editorPortalHostRef.current = host;
|
|
1944
|
+
} else if (!editorPortalHostRef.current.isConnected) {
|
|
1945
|
+
doc.body.appendChild(editorPortalHostRef.current);
|
|
1946
|
+
}
|
|
1947
|
+
return editorPortalHostRef.current;
|
|
1948
|
+
}, [getOwnerDocument]);
|
|
1949
|
+
|
|
1315
1950
|
/**
|
|
1316
1951
|
* Create a new settings object containing the column settings and global editors and renderers.
|
|
1317
1952
|
*
|
|
1953
|
+
* @param {boolean} init `true` when called during the initial mount.
|
|
1954
|
+
* @param {HotTableProps} previousProps The component's props before the current update.
|
|
1318
1955
|
* @returns {Handsontable.GridSettings} New global set of settings for Handsontable.
|
|
1319
1956
|
*/
|
|
1320
1957
|
var createNewGlobalSettings = function createNewGlobalSettings() {
|
|
1321
1958
|
var _getHotInstance;
|
|
1322
1959
|
var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
1323
|
-
var
|
|
1324
|
-
var
|
|
1325
|
-
|
|
1326
|
-
|
|
1960
|
+
var previousProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1961
|
+
var liveSettings = !isHotInstanceDestroyed() ? (_getHotInstance = getHotInstance()) === null || _getHotInstance === void 0 ? void 0 : _getHotInstance.getSettings() : undefined;
|
|
1962
|
+
var initOnlySettingKeys = (liveSettings === null || liveSettings === void 0 ? void 0 : liveSettings._initOnlySettings) || [];
|
|
1963
|
+
if (init) {
|
|
1964
|
+
forwardedSettings.current = new Map();
|
|
1965
|
+
}
|
|
1327
1966
|
var newSettings = SettingsMapper.getSettings(props, {
|
|
1328
|
-
prevProps:
|
|
1967
|
+
prevProps: previousProps,
|
|
1329
1968
|
isInit: init,
|
|
1330
|
-
initOnlySettingKeys: initOnlySettingKeys
|
|
1969
|
+
initOnlySettingKeys: initOnlySettingKeys,
|
|
1970
|
+
currentSettings: liveSettings,
|
|
1971
|
+
forwardedSettings: forwardedSettings.current
|
|
1331
1972
|
});
|
|
1332
1973
|
if (context.columnsSettings.length) {
|
|
1333
|
-
|
|
1974
|
+
if (init || !areEquivalentSettingsValue(forwardedColumnsSettings.current, context.columnsSettings)) {
|
|
1975
|
+
newSettings.columns = context.columnsSettings;
|
|
1976
|
+
forwardedColumnsSettings.current = copySettingsValue(context.columnsSettings);
|
|
1977
|
+
} else {
|
|
1978
|
+
delete newSettings.columns;
|
|
1979
|
+
}
|
|
1334
1980
|
}
|
|
1981
|
+
|
|
1982
|
+
// The grid-level `type` supplies the editor and the renderer no prop names, so an unnamed one is left out
|
|
1983
|
+
// of the payload. When the prop that named one is removed, `undefined` is sent: core reads it as "unset"
|
|
1984
|
+
// and the current `type` supplies the editor or the renderer again.
|
|
1985
|
+
var applyUnnamedSetting = function applyUnnamedSetting(key, wasNamed) {
|
|
1986
|
+
if (wasNamed) {
|
|
1987
|
+
newSettings[key] = undefined;
|
|
1988
|
+
} else {
|
|
1989
|
+
delete newSettings[key];
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1335
1992
|
if (props.renderer) {
|
|
1336
1993
|
newSettings.renderer = context.getRendererWrapper(props.renderer);
|
|
1337
1994
|
context.componentRendererColumns.set('global', true);
|
|
1995
|
+
} else if (props.hotRenderer) {
|
|
1996
|
+
newSettings.renderer = props.hotRenderer;
|
|
1338
1997
|
} else {
|
|
1339
|
-
|
|
1998
|
+
applyUnnamedSetting('renderer', namedGlobalRenderer.current);
|
|
1340
1999
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
2000
|
+
namedGlobalRenderer.current = Boolean(props.renderer || props.hotRenderer);
|
|
2001
|
+
var editorSetting = isComponentEditor(props.editor) ? makeEditorClass(globalEditorHooksRef, globalEditorClassInstance) : resolveEditorSetting(props.editor, props.hotEditor);
|
|
2002
|
+
|
|
2003
|
+
// `undefined` means neither prop named an editor.
|
|
2004
|
+
if (editorSetting === undefined) {
|
|
2005
|
+
applyUnnamedSetting('editor', namedGlobalEditor.current);
|
|
1343
2006
|
} else {
|
|
1344
|
-
newSettings.editor =
|
|
2007
|
+
newSettings.editor = editorSetting;
|
|
1345
2008
|
}
|
|
2009
|
+
namedGlobalEditor.current = editorSetting !== undefined;
|
|
1346
2010
|
return newSettings;
|
|
1347
2011
|
};
|
|
1348
2012
|
|
|
1349
2013
|
/**
|
|
1350
2014
|
* Detect if `autoRowSize` or `autoColumnSize` is defined, and if so, throw an incompatibility warning.
|
|
2015
|
+
*
|
|
2016
|
+
* @param {Handsontable | null} hotInstance The Handsontable instance to check.
|
|
1351
2017
|
*/
|
|
1352
2018
|
var displayAutoSizeWarning = function displayAutoSizeWarning(hotInstance) {
|
|
1353
2019
|
var _hotInstance$getPlugi, _hotInstance$getPlugi2;
|
|
@@ -1378,8 +2044,15 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1378
2044
|
* Handsontable's `beforeViewRender` hook callback.
|
|
1379
2045
|
*/
|
|
1380
2046
|
__hotInstance.current.addHook('beforeViewRender', function () {
|
|
1381
|
-
context.
|
|
1382
|
-
|
|
2047
|
+
context.resetRenderedPortals();
|
|
2048
|
+
});
|
|
2049
|
+
|
|
2050
|
+
/**
|
|
2051
|
+
* Handsontable's `beforeRenderer` hook callback. It runs for every cell the grid paints, whatever
|
|
2052
|
+
* the cell's renderer.
|
|
2053
|
+
*/
|
|
2054
|
+
__hotInstance.current.addHook('beforeRenderer', function (TD) {
|
|
2055
|
+
context.markCellPainted(TD);
|
|
1383
2056
|
});
|
|
1384
2057
|
|
|
1385
2058
|
/**
|
|
@@ -1389,6 +2062,15 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1389
2062
|
context.pushCellPortalsIntoPortalManager();
|
|
1390
2063
|
});
|
|
1391
2064
|
__hotInstance.current.init();
|
|
2065
|
+
var portalHost = editorPortalHostRef.current;
|
|
2066
|
+
var rootPortalElement = __hotInstance.current.rootPortalElement;
|
|
2067
|
+
if (portalHost && rootPortalElement) {
|
|
2068
|
+
if (portalHost.parentNode !== rootPortalElement) {
|
|
2069
|
+
rootPortalElement.appendChild(portalHost);
|
|
2070
|
+
}
|
|
2071
|
+
} else if (portalHost && !rootPortalElement) {
|
|
2072
|
+
warn(MISSING_ROOT_PORTAL_WARNING);
|
|
2073
|
+
}
|
|
1392
2074
|
displayAutoSizeWarning(__hotInstance.current);
|
|
1393
2075
|
if (!displayObsoleteRenderersEditorsWarning(props.children)) {
|
|
1394
2076
|
displayChildrenOfTypeWarning(props.children, HotColumn);
|
|
@@ -1398,7 +2080,8 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1398
2080
|
* Destroy the Handsontable instance when the parent component unmounts.
|
|
1399
2081
|
*/
|
|
1400
2082
|
return function () {
|
|
1401
|
-
var _getHotInstance2;
|
|
2083
|
+
var _editorPortalHostRef$, _getHotInstance2;
|
|
2084
|
+
(_editorPortalHostRef$ = editorPortalHostRef.current) === null || _editorPortalHostRef$ === void 0 || _editorPortalHostRef$.remove();
|
|
1402
2085
|
clearCache();
|
|
1403
2086
|
(_getHotInstance2 = getHotInstance()) === null || _getHotInstance2 === void 0 || _getHotInstance2.destroy();
|
|
1404
2087
|
};
|
|
@@ -1447,11 +2130,12 @@ var HotTableInner = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
1447
2130
|
return /*#__PURE__*/React__default["default"].createElement(HotColumnContextProvider, {
|
|
1448
2131
|
columnIndex: columnIndex,
|
|
1449
2132
|
getOwnerDocument: getOwnerDocument,
|
|
2133
|
+
getEditorPortalHost: getEditorPortalHost,
|
|
1450
2134
|
key: columnIndex
|
|
1451
2135
|
}, childNode);
|
|
1452
2136
|
});
|
|
1453
2137
|
var containerProps = getContainerAttributesProps(props);
|
|
1454
|
-
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor);
|
|
2138
|
+
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor, getEditorPortalHost());
|
|
1455
2139
|
return /*#__PURE__*/React__default["default"].createElement(React.Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", _extends({
|
|
1456
2140
|
ref: hotElementRef
|
|
1457
2141
|
}, containerProps, {
|
|
@@ -1500,7 +2184,10 @@ var HotTable = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1500
2184
|
var _props$id;
|
|
1501
2185
|
var children = _ref.children,
|
|
1502
2186
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
1503
|
-
|
|
2187
|
+
// `useId()` must run unconditionally on every render (never only when `id` is missing), or React
|
|
2188
|
+
// sees a different hook count between renders and throws "Rendered fewer hooks than expected".
|
|
2189
|
+
var generatedId = React.useId();
|
|
2190
|
+
var componentId = (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generatedId;
|
|
1504
2191
|
return /*#__PURE__*/React__default["default"].createElement(HotTableContextProvider, null, /*#__PURE__*/React__default["default"].createElement(HotTableInner, _extends({
|
|
1505
2192
|
id: componentId
|
|
1506
2193
|
}, props, {
|