@handsontable/react-wrapper 18.1.2-rc2 → 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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import React, { useEffect, useContext, useRef, useCallback, useMemo, createContext, useState, useImperativeHandle, forwardRef, Fragment, Children, useId } from 'react';
|
|
2
3
|
import ReactDOM from 'react-dom';
|
|
3
|
-
import Handsontable from 'handsontable/base';
|
|
4
|
-
import { getRenderer } from 'handsontable/renderers/registry';
|
|
5
4
|
import { getEditor } from 'handsontable/editors/registry';
|
|
5
|
+
import Handsontable from 'handsontable/base';
|
|
6
6
|
|
|
7
7
|
function _arrayLikeToArray(r, a) {
|
|
8
8
|
(null == a || a > r.length) && (a = r.length);
|
|
@@ -12,9 +12,6 @@ function _arrayLikeToArray(r, a) {
|
|
|
12
12
|
function _arrayWithHoles(r) {
|
|
13
13
|
if (Array.isArray(r)) return r;
|
|
14
14
|
}
|
|
15
|
-
function _arrayWithoutHoles(r) {
|
|
16
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
17
|
-
}
|
|
18
15
|
function _assertThisInitialized(e) {
|
|
19
16
|
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
20
17
|
return e;
|
|
@@ -78,9 +75,6 @@ function _isNativeReflectConstruct() {
|
|
|
78
75
|
return !!t;
|
|
79
76
|
})();
|
|
80
77
|
}
|
|
81
|
-
function _iterableToArray(r) {
|
|
82
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
83
|
-
}
|
|
84
78
|
function _iterableToArrayLimit(r, l) {
|
|
85
79
|
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
86
80
|
if (null != t) {
|
|
@@ -108,9 +102,6 @@ function _iterableToArrayLimit(r, l) {
|
|
|
108
102
|
function _nonIterableRest() {
|
|
109
103
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
110
104
|
}
|
|
111
|
-
function _nonIterableSpread() {
|
|
112
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
113
|
-
}
|
|
114
105
|
function ownKeys(e, r) {
|
|
115
106
|
var t = Object.keys(e);
|
|
116
107
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -165,9 +156,6 @@ function _setPrototypeOf(t, e) {
|
|
|
165
156
|
function _slicedToArray(r, e) {
|
|
166
157
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
167
158
|
}
|
|
168
|
-
function _toConsumableArray(r) {
|
|
169
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
170
|
-
}
|
|
171
159
|
function _toPrimitive(t, r) {
|
|
172
160
|
if ("object" != typeof t || !t) return t;
|
|
173
161
|
var e = t[Symbol.toPrimitive];
|
|
@@ -204,17 +192,17 @@ var bulkComponentContainer = null;
|
|
|
204
192
|
/**
|
|
205
193
|
* Warning message for the `autoRowSize`/`autoColumnSize` compatibility check.
|
|
206
194
|
*/
|
|
207
|
-
var AUTOSIZE_WARNING = 'Your `HotTable` configuration includes `autoRowSize`/`autoColumnSize` options, which are not compatible with
|
|
195
|
+
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.';
|
|
208
196
|
|
|
209
197
|
/**
|
|
210
198
|
* Warning message for the `hot-renderer` obsolete renderer passing method.
|
|
211
199
|
*/
|
|
212
|
-
var OBSOLETE_HOTRENDERER_WARNING = 'Providing a component-based renderer using `hot-renderer`-annotated component is no longer supported.
|
|
200
|
+
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.';
|
|
213
201
|
|
|
214
202
|
/**
|
|
215
203
|
* Warning message for the `hot-editor` obsolete editor passing method.
|
|
216
204
|
*/
|
|
217
|
-
var OBSOLETE_HOTEDITOR_WARNING = 'Providing a component-based editor using `hot-editor`-annotated component is no longer supported.
|
|
205
|
+
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.';
|
|
218
206
|
|
|
219
207
|
/**
|
|
220
208
|
* Warning message for the unexpected children of HotTable component.
|
|
@@ -226,6 +214,21 @@ var UNEXPECTED_HOTTABLE_CHILDREN_WARNING = 'Unexpected children nodes found in H
|
|
|
226
214
|
*/
|
|
227
215
|
var UNEXPECTED_HOTCOLUMN_CHILDREN_WARNING = 'Unexpected children nodes found in HotColumn component. ' + 'HotColumn components do not support any children.';
|
|
228
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Warning when a Handsontable function renderer is passed to the React `renderer` prop.
|
|
219
|
+
*
|
|
220
|
+
* That prop is a React component. A classic function renderer belongs on `hotRenderer`.
|
|
221
|
+
*/
|
|
222
|
+
var CLASSIC_FUNCTION_RENDERER_WARNING = 'The `renderer` prop expects a React component. ' + 'Pass a Handsontable function renderer to `hotRenderer` instead.';
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Warning when a Handsontable editor (an editor class or a registered editor name) is passed to the
|
|
226
|
+
* React `editor` prop.
|
|
227
|
+
*
|
|
228
|
+
* That prop is a React component. A Handsontable editor belongs on `hotEditor`.
|
|
229
|
+
*/
|
|
230
|
+
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.';
|
|
231
|
+
|
|
229
232
|
/**
|
|
230
233
|
* Message for the warning thrown if the Handsontable instance has been destroyed.
|
|
231
234
|
*/
|
|
@@ -236,6 +239,17 @@ var HOT_DESTROYED_WARNING = 'The Handsontable instance bound to this component w
|
|
|
236
239
|
*/
|
|
237
240
|
var DEFAULT_CLASSNAME = 'hot-wrapper-editor-container';
|
|
238
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Classname for the stable host that holds React editor portals.
|
|
244
|
+
* Distinct from `DEFAULT_CLASSNAME` so page CSS and `querySelector` do not hit both nodes.
|
|
245
|
+
*/
|
|
246
|
+
var EDITOR_PORTAL_HOST_CLASSNAME = 'hot-wrapper-editor-portal-host';
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Warning when the editor portal host cannot be moved into `rootPortalElement`.
|
|
250
|
+
*/
|
|
251
|
+
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.';
|
|
252
|
+
|
|
239
253
|
/**
|
|
240
254
|
* Logs warn to the console if the `console` object is exposed.
|
|
241
255
|
*
|
|
@@ -248,9 +262,38 @@ function warn() {
|
|
|
248
262
|
}
|
|
249
263
|
}
|
|
250
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Function renderers that already produced `CLASSIC_FUNCTION_RENDERER_WARNING`.
|
|
267
|
+
* Keyed by the function, so one function warns once no matter how many cells render it.
|
|
268
|
+
*/
|
|
269
|
+
var warnedClassicFunctionRenderers = new WeakSet();
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Warn when `renderer` holds a Handsontable function renderer.
|
|
273
|
+
*
|
|
274
|
+
* A React component is called with one props object, so its `length` stays below 3.
|
|
275
|
+
* A classic renderer declares `(instance, td, row, col, prop, value, cellProperties)`,
|
|
276
|
+
* so its `length` is at least 3. The prop is still rendered as a component. Picking
|
|
277
|
+
* the call style from `length` would change behavior, because a component with default
|
|
278
|
+
* parameters reports `length` 0.
|
|
279
|
+
*
|
|
280
|
+
* @param {ComponentType} renderer Component passed through the `renderer` prop.
|
|
281
|
+
*/
|
|
282
|
+
function warnAboutClassicFunctionRenderer(renderer) {
|
|
283
|
+
if (typeof renderer !== 'function' || renderer.length < 3) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (warnedClassicFunctionRenderers.has(renderer)) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
warnedClassicFunctionRenderers.add(renderer);
|
|
290
|
+
warn(CLASSIC_FUNCTION_RENDERER_WARNING);
|
|
291
|
+
}
|
|
292
|
+
|
|
251
293
|
/**
|
|
252
294
|
* Detect if `hot-renderer` or `hot-editor` is defined, and if so, throw an incompatibility warning.
|
|
253
295
|
*
|
|
296
|
+
* @param {ReactNode} children Component children nodes.
|
|
254
297
|
* @returns {boolean} 'true' if the warning was issued
|
|
255
298
|
*/
|
|
256
299
|
function displayObsoleteRenderersEditorsWarning(children) {
|
|
@@ -302,31 +345,178 @@ function displayAnyChildrenWarning(children) {
|
|
|
302
345
|
* Check the existence of elements of the provided `type` from the `HotColumn` component's children.
|
|
303
346
|
*
|
|
304
347
|
* @param {ReactNode} children HotTable children array.
|
|
305
|
-
* @param {
|
|
348
|
+
* @param {string} type Either `'hot-renderer'` or `'hot-editor'`.
|
|
306
349
|
* @returns {boolean} `true` if the child of that type was found, `false` otherwise.
|
|
307
350
|
*/
|
|
308
351
|
function hasChildElementOfType(children, type) {
|
|
309
352
|
var childrenArray = React.Children.toArray(children);
|
|
310
353
|
return childrenArray.some(function (child) {
|
|
311
|
-
return child.props[type] !==
|
|
354
|
+
return child.props[type] !== undefined;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Check whether the `editor` prop holds a component editor, as opposed to a boolean flag or a
|
|
360
|
+
* Handsontable editor passed there by mistake.
|
|
361
|
+
*
|
|
362
|
+
* Both editor props accept a boolean, so a truthy check alone is not enough to tell a component
|
|
363
|
+
* apart from a bare `editor={true}`. An editor class or editor name is not a component either (see
|
|
364
|
+
* `isNativeEditor()`).
|
|
365
|
+
*
|
|
366
|
+
* @param {HotTableProps['editor']} editor The `editor` prop.
|
|
367
|
+
* @returns {boolean} `true` when the prop carries a React component to render.
|
|
368
|
+
*/
|
|
369
|
+
function isComponentEditor(editor) {
|
|
370
|
+
return !!editor && typeof editor !== 'boolean' && !isNativeEditor(editor);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Methods every Handsontable editor class inherits from `BaseEditor`.
|
|
375
|
+
*/
|
|
376
|
+
var NATIVE_EDITOR_METHODS = ['prepare', 'beginEditing', 'getValue', 'setValue', 'open', 'close'];
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Check whether a value is a Handsontable editor: a registered editor name or an editor class.
|
|
380
|
+
*
|
|
381
|
+
* A class is recognized by the `BaseEditor` methods on its prototype rather than with `instanceof`,
|
|
382
|
+
* so a class built on another copy of Handsontable is still recognized. A React class component
|
|
383
|
+
* carries `prototype.isReactComponent`, and a function component does not have these methods, so
|
|
384
|
+
* neither one matches.
|
|
385
|
+
*
|
|
386
|
+
* @param {*} editor The value to check.
|
|
387
|
+
* @returns {boolean} `true` when the value is a Handsontable editor.
|
|
388
|
+
*/
|
|
389
|
+
function isNativeEditor(editor) {
|
|
390
|
+
if (typeof editor === 'string') {
|
|
391
|
+
return editor !== '';
|
|
392
|
+
}
|
|
393
|
+
if (typeof editor !== 'function') {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
var prototype = editor.prototype;
|
|
397
|
+
if (!prototype || prototype.isReactComponent) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
return NATIVE_EDITOR_METHODS.every(function (method) {
|
|
401
|
+
return typeof prototype[method] === 'function';
|
|
312
402
|
});
|
|
313
403
|
}
|
|
314
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Check whether an editor is registered under a name.
|
|
407
|
+
*
|
|
408
|
+
* It asks `getEditor()`, which throws for an unknown name, instead of `hasEditor()`: the UMD build
|
|
409
|
+
* maps the editor registry to `Handsontable.editors`, which exposes `getEditor()` only.
|
|
410
|
+
*
|
|
411
|
+
* @param {string} name The editor name.
|
|
412
|
+
* @returns {boolean} `true` when an editor is registered under the name.
|
|
413
|
+
*/
|
|
414
|
+
function isRegisteredEditorName(name) {
|
|
415
|
+
try {
|
|
416
|
+
getEditor(name);
|
|
417
|
+
return true;
|
|
418
|
+
} catch (_unused) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Editor classes that already produced `NATIVE_EDITOR_IN_EDITOR_PROP_WARNING`.
|
|
425
|
+
*/
|
|
426
|
+
var warnedNativeEditorClasses = new WeakSet();
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Editor names that already produced `NATIVE_EDITOR_IN_EDITOR_PROP_WARNING`.
|
|
430
|
+
*/
|
|
431
|
+
var warnedNativeEditorNames = new Set();
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Warn once per value that a Handsontable editor was passed to the `editor` prop.
|
|
435
|
+
*
|
|
436
|
+
* @param {Function|string} editor The editor class or editor name.
|
|
437
|
+
*/
|
|
438
|
+
function warnAboutNativeEditorInEditorProp(editor) {
|
|
439
|
+
if (typeof editor === 'string') {
|
|
440
|
+
if (warnedNativeEditorNames.has(editor)) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
warnedNativeEditorNames.add(editor);
|
|
444
|
+
} else {
|
|
445
|
+
if (warnedNativeEditorClasses.has(editor)) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
warnedNativeEditorClasses.add(editor);
|
|
449
|
+
}
|
|
450
|
+
warn(NATIVE_EDITOR_IN_EDITOR_PROP_WARNING);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Resolve the Handsontable `editor` setting from the two editor props.
|
|
455
|
+
*
|
|
456
|
+
* `editor` carries the component editor and `hotEditor` the Handsontable-native one, but both accept
|
|
457
|
+
* a boolean:
|
|
458
|
+
*
|
|
459
|
+
* - `false` disables editing.
|
|
460
|
+
* - `true` names no editor, so it is treated as if the prop were not provided. It must never reach
|
|
461
|
+
* the core, which accepts only a string or a constructor and throws on anything else.
|
|
462
|
+
* - Any other nullish or falsy value (`null`, `0`, `''`) is also treated as "not provided", so a
|
|
463
|
+
* column written as `editor={cond ? MyEditor : null}` inherits instead of locking.
|
|
464
|
+
*
|
|
465
|
+
* `hotEditor` is resolved before a falsy `editor`, so an editor named there still wins over a bare
|
|
466
|
+
* `editor={false}` — the behavior in every released version, where `editor={false}` fell through to
|
|
467
|
+
* the `hotEditor` value. A component `editor` outranks both: it is picked by `isComponentEditor()`
|
|
468
|
+
* before this function is reached, so `editor={MyComponent} hotEditor={false}` keeps the component.
|
|
469
|
+
*
|
|
470
|
+
* A Handsontable editor (a class or a registered name) passed to `editor` is a mistake: that prop
|
|
471
|
+
* renders a React component. It is used as if it were passed to `hotEditor`, with a one-time
|
|
472
|
+
* warning. A `hotEditor` value that names an editor or disables editing still wins over it. A name
|
|
473
|
+
* that no editor is registered under is dropped after the warning, so a typo does not make the core
|
|
474
|
+
* throw.
|
|
475
|
+
*
|
|
476
|
+
* @param {HotTableProps['editor']} editor The `editor` prop.
|
|
477
|
+
* @param {HotTableProps['hotEditor']} hotEditor The `hotEditor` prop.
|
|
478
|
+
* @returns {*} The editor setting, or `undefined` when neither prop names one.
|
|
479
|
+
*/
|
|
480
|
+
function resolveEditorSetting(editor, hotEditor) {
|
|
481
|
+
if (hotEditor === false) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// `true` names no editor, so it must fall through to "not provided" rather than hard-setting the
|
|
486
|
+
// default one — otherwise it would override the editor a column's `type` or the grid supplies.
|
|
487
|
+
if (hotEditor && hotEditor !== true) {
|
|
488
|
+
return hotEditor;
|
|
489
|
+
}
|
|
490
|
+
if (isNativeEditor(editor)) {
|
|
491
|
+
warnAboutNativeEditorInEditorProp(editor);
|
|
492
|
+
|
|
493
|
+
// An unregistered name (a typo) would make the core throw on every selection of the cell, so
|
|
494
|
+
// it is dropped and the cell keeps the editor its column type or the grid supplies.
|
|
495
|
+
if (typeof editor === 'string' && !isRegisteredEditorName(editor)) {
|
|
496
|
+
return undefined;
|
|
497
|
+
}
|
|
498
|
+
return editor;
|
|
499
|
+
}
|
|
500
|
+
return editor === false ? false : undefined;
|
|
501
|
+
}
|
|
502
|
+
|
|
315
503
|
/**
|
|
316
504
|
* Create an editor portal.
|
|
317
505
|
*
|
|
318
506
|
* @param {Document} doc Document to be used.
|
|
319
507
|
* @param {ComponentType} Editor Editor component or render function.
|
|
508
|
+
* @param {HTMLElement} portalHost Host element to portal into. Required – do not fall back to `doc.body`.
|
|
320
509
|
* @returns {ReactPortal} The portal for the editor.
|
|
321
510
|
*/
|
|
322
|
-
function createEditorPortal(doc, Editor) {
|
|
323
|
-
if (!doc || !
|
|
511
|
+
function createEditorPortal(doc, Editor, portalHost) {
|
|
512
|
+
if (!doc || !portalHost || !isComponentEditor(Editor)) {
|
|
324
513
|
return null;
|
|
325
514
|
}
|
|
326
|
-
var
|
|
515
|
+
var EditorComponent = Editor;
|
|
516
|
+
var editorElement = /*#__PURE__*/React.createElement(EditorComponent, null);
|
|
327
517
|
var containerProps = getContainerAttributesProps({}, false);
|
|
328
518
|
containerProps.className = "".concat(DEFAULT_CLASSNAME, " ").concat(containerProps.className);
|
|
329
|
-
return /*#__PURE__*/ReactDOM.createPortal(/*#__PURE__*/React.createElement("div", containerProps, editorElement),
|
|
519
|
+
return /*#__PURE__*/ReactDOM.createPortal(/*#__PURE__*/React.createElement("div", containerProps, editorElement), portalHost);
|
|
330
520
|
}
|
|
331
521
|
|
|
332
522
|
/**
|
|
@@ -334,9 +524,10 @@ function createEditorPortal(doc, Editor) {
|
|
|
334
524
|
*
|
|
335
525
|
* @param {React.ReactElement} rElement React element to be used as a base for the component.
|
|
336
526
|
* @param {Document} [ownerDocument] The owner document to set the portal up into.
|
|
337
|
-
* @param {
|
|
527
|
+
* @param {string} portalKey The key to be used for the portal.
|
|
338
528
|
* @param {HTMLElement} [cachedContainer] The cached container to be used for the portal.
|
|
339
|
-
* @returns {{portal: ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its
|
|
529
|
+
* @returns {{portal: ReactPortal, portalContainer: HTMLElement}} An object containing the portal and its
|
|
530
|
+
* container.
|
|
340
531
|
*/
|
|
341
532
|
function createPortal(rElement) {
|
|
342
533
|
var ownerDocument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document;
|
|
@@ -368,14 +559,15 @@ function createPortal(rElement) {
|
|
|
368
559
|
* component.
|
|
369
560
|
*
|
|
370
561
|
* @param {HotTableProps} props Object containing the React element props.
|
|
371
|
-
* @param {
|
|
372
|
-
*
|
|
373
|
-
*
|
|
562
|
+
* @param {boolean} randomizeId If set to `true`, the function will randomize the `id` property when no `id` was
|
|
563
|
+
* present in the `prop` object.
|
|
564
|
+
* @returns {{id?: string, className: string, style: CSSProperties}} An object containing the `id`, `className`
|
|
565
|
+
* and `style` keys, representing the corresponding props passed to the component.
|
|
374
566
|
*/
|
|
375
567
|
function getContainerAttributesProps(props) {
|
|
376
568
|
var randomizeId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
377
569
|
return {
|
|
378
|
-
id: props.id || (randomizeId ?
|
|
570
|
+
id: props.id || (randomizeId ? "hot-".concat(Math.random().toString(36).substring(5)) : undefined),
|
|
379
571
|
className: props.className || '',
|
|
380
572
|
style: props.style || {}
|
|
381
573
|
};
|
|
@@ -384,14 +576,28 @@ function getContainerAttributesProps(props) {
|
|
|
384
576
|
/**
|
|
385
577
|
* Checks if the environment that the code runs in is a browser.
|
|
386
578
|
*
|
|
387
|
-
* @returns {boolean}
|
|
579
|
+
* @returns {boolean} `true` when running in a browser environment.
|
|
388
580
|
*/
|
|
389
581
|
function isCSR() {
|
|
390
582
|
return typeof window !== 'undefined';
|
|
391
583
|
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Checks whether the value is an object or `null`.
|
|
587
|
+
*
|
|
588
|
+
* @param {unknown} value Value to check.
|
|
589
|
+
* @returns {boolean} `true` when the value is an object.
|
|
590
|
+
*/
|
|
392
591
|
function isObjectLike(value) {
|
|
393
592
|
return _typeof(value) === 'object' && value !== null;
|
|
394
593
|
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* Checks whether the value is a plain object (an object literal or one created with `Object.create(null)`).
|
|
597
|
+
*
|
|
598
|
+
* @param {unknown} value Value to check.
|
|
599
|
+
* @returns {boolean} `true` when the value is a plain object.
|
|
600
|
+
*/
|
|
395
601
|
function isPlainObject(value) {
|
|
396
602
|
if (!isObjectLike(value)) {
|
|
397
603
|
return false;
|
|
@@ -399,18 +605,30 @@ function isPlainObject(value) {
|
|
|
399
605
|
var prototype = Object.getPrototypeOf(value);
|
|
400
606
|
return prototype === Object.prototype || prototype === null;
|
|
401
607
|
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Checks whether the value is an array.
|
|
611
|
+
*
|
|
612
|
+
* @param {unknown} value Value to check.
|
|
613
|
+
* @returns {boolean} `true` when the value is an array.
|
|
614
|
+
*/
|
|
402
615
|
function isArray(value) {
|
|
403
616
|
return Array.isArray(value);
|
|
404
617
|
}
|
|
405
618
|
|
|
406
619
|
/**
|
|
407
|
-
* Deep-compare plain objects and arrays used by wrapper settings.
|
|
620
|
+
* Deep-compare plain objects and arrays used by wrapper settings. Functions, class instances and any
|
|
621
|
+
* other value are compared by reference, and a `RegExp` by its source and flags. A pair of objects
|
|
622
|
+
* already being compared higher up reads as equal, so a value with a cycle (tree rows with a `parent`
|
|
623
|
+
* link) ends instead of overflowing the stack.
|
|
408
624
|
*
|
|
409
625
|
* @param {unknown} previousValue Previous value.
|
|
410
626
|
* @param {unknown} currentValue Current value.
|
|
627
|
+
* @param {WeakMap<object, WeakSet<object>>} [visited] The object pairs on the current comparison path.
|
|
411
628
|
* @returns {boolean} `true` if values are equivalent.
|
|
412
629
|
*/
|
|
413
630
|
function areEquivalentSettingsValue(previousValue, currentValue) {
|
|
631
|
+
var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakMap();
|
|
414
632
|
if (previousValue === currentValue) {
|
|
415
633
|
return true;
|
|
416
634
|
}
|
|
@@ -420,48 +638,66 @@ function areEquivalentSettingsValue(previousValue, currentValue) {
|
|
|
420
638
|
}
|
|
421
639
|
return previousValue.source === currentValue.source && previousValue.flags === currentValue.flags;
|
|
422
640
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
}
|
|
427
|
-
for (var index = 0; index < previousValue.length; index++) {
|
|
428
|
-
if (!areEquivalentSettingsValue(previousValue[index], currentValue[index])) {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return true;
|
|
433
|
-
}
|
|
434
|
-
if (isArray(previousValue) || isArray(currentValue)) {
|
|
641
|
+
var bothArrays = isArray(previousValue) && isArray(currentValue);
|
|
642
|
+
var bothPlainObjects = !isArray(previousValue) && !isArray(currentValue) && isPlainObject(previousValue) && isPlainObject(currentValue);
|
|
643
|
+
if (!bothArrays && !bothPlainObjects) {
|
|
435
644
|
return false;
|
|
436
645
|
}
|
|
437
|
-
|
|
438
|
-
|
|
646
|
+
var previousObject = previousValue;
|
|
647
|
+
var currentObject = currentValue;
|
|
648
|
+
var comparedWith = visited.get(previousObject);
|
|
649
|
+
if (comparedWith !== null && comparedWith !== void 0 && comparedWith.has(currentObject)) {
|
|
650
|
+
return true;
|
|
439
651
|
}
|
|
440
|
-
if (
|
|
441
|
-
|
|
652
|
+
if (comparedWith) {
|
|
653
|
+
comparedWith.add(currentObject);
|
|
654
|
+
} else {
|
|
655
|
+
visited.set(previousObject, new WeakSet([currentObject]));
|
|
442
656
|
}
|
|
443
|
-
var previousKeys = Object.keys(
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
657
|
+
var previousKeys = Object.keys(previousObject);
|
|
658
|
+
return previousKeys.length === Object.keys(currentObject).length && previousKeys.every(function (key) {
|
|
659
|
+
return Object.prototype.hasOwnProperty.call(currentObject, key) && areEquivalentSettingsValue(previousObject[key], currentObject[key], visited);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Copies the plain objects and arrays of a settings value, keeping every other value (functions, class
|
|
665
|
+
* instances) by reference. The copy is what an update compares the next value with, so a value the app
|
|
666
|
+
* changes in place reads as changed. A value with a cycle is copied with the same cycle.
|
|
667
|
+
*
|
|
668
|
+
* @param {unknown} value The value to copy.
|
|
669
|
+
* @param {WeakMap<object, unknown>} [copies] The copies made so far, by original.
|
|
670
|
+
* @returns {unknown} The copy.
|
|
671
|
+
*/
|
|
672
|
+
function copySettingsValue(value) {
|
|
673
|
+
var copies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
|
|
674
|
+
if (!isArray(value) && !isPlainObject(value)) {
|
|
675
|
+
return value;
|
|
447
676
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
677
|
+
if (copies.has(value)) {
|
|
678
|
+
return copies.get(value);
|
|
679
|
+
}
|
|
680
|
+
if (isArray(value)) {
|
|
681
|
+
var _copy = [];
|
|
682
|
+
copies.set(value, _copy);
|
|
683
|
+
value.forEach(function (item) {
|
|
684
|
+
_copy.push(copySettingsValue(item, copies));
|
|
685
|
+
});
|
|
686
|
+
return _copy;
|
|
456
687
|
}
|
|
457
|
-
|
|
688
|
+
var copy = {};
|
|
689
|
+
copies.set(value, copy);
|
|
690
|
+
Object.keys(value).forEach(function (key) {
|
|
691
|
+
copy[key] = copySettingsValue(value[key], copies);
|
|
692
|
+
});
|
|
693
|
+
return copy;
|
|
458
694
|
}
|
|
459
695
|
|
|
460
696
|
/**
|
|
461
697
|
* A variant of useEffect hook that does not trigger on initial mount, only updates
|
|
462
698
|
*
|
|
463
|
-
* @param effect Effect function
|
|
464
|
-
* @param deps Effect dependencies
|
|
699
|
+
* @param {EffectCallback} effect Effect function
|
|
700
|
+
* @param {DependencyList} [deps] Effect dependencies
|
|
465
701
|
*/
|
|
466
702
|
function useUpdateEffect(effect, deps) {
|
|
467
703
|
var notInitialRender = React.useRef(false);
|
|
@@ -475,12 +711,165 @@ function useUpdateEffect(effect, deps) {
|
|
|
475
711
|
}
|
|
476
712
|
|
|
477
713
|
/**
|
|
478
|
-
*
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
714
|
+
* The class of the wrapper the grid puts around a cell's content in a row rendered at an exact height.
|
|
715
|
+
*/
|
|
716
|
+
var CELL_CLIP_CLASS = 'htCellClip';
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Returns the element a cell's content belongs in: the grid's clipping wrapper when the cell holds
|
|
720
|
+
* exactly that wrapper, and the cell itself otherwise.
|
|
721
|
+
*
|
|
722
|
+
* @param {HTMLElement} TD The table cell.
|
|
723
|
+
* @returns {Element}
|
|
724
|
+
*/
|
|
725
|
+
function getCellContentRoot(TD) {
|
|
726
|
+
var firstChild = TD.firstElementChild;
|
|
727
|
+
if (firstChild !== null && TD.childNodes.length === 1 && firstChild.classList.contains(CELL_CLIP_CLASS)) {
|
|
728
|
+
return firstChild;
|
|
729
|
+
}
|
|
730
|
+
return TD;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* These settings are compared with the previous props, or for the size settings with the grid's live
|
|
735
|
+
* value, by the rules below. Every other setting but `data` is compared with a copy of the value last
|
|
736
|
+
* passed to the grid (`isSameAsForwarded()`).
|
|
737
|
+
*
|
|
738
|
+
* `rowHeights`, `minRowHeights` (the row height floor) and `colWidths` are here because passing any
|
|
739
|
+
* of them re-declares the sizes and discards the ones the user produced by dragging
|
|
740
|
+
* (`ManualRowResize` / `ManualColumnResize`). A re-render must not do that, and a React app commonly
|
|
741
|
+
* writes the value inline (`rowHeights={[50, 50]}`), which is a new array on every render and never
|
|
742
|
+
* reference-equal. All three hold plain numbers, strings or arrays of them, so the deep walk is
|
|
743
|
+
* cheap. The Vue wrapper already skips unchanged keys this way.
|
|
744
|
+
*/
|
|
745
|
+
var DEEP_COMPARABLE_SETTINGS = ['dataSchema', 'columns', 'rowHeights', 'minRowHeights', 'colWidths'];
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* The size settings are compared against the grid's live settings rather than the previous props,
|
|
749
|
+
* which is what the Angular and Vue wrappers already do. Comparing against props alone would stop
|
|
750
|
+
* re-asserting the prop after anything changed the size through the instance ref.
|
|
751
|
+
*/
|
|
752
|
+
var COMPARED_AGAINST_LIVE_SETTINGS = ['rowHeights', 'minRowHeights', 'colWidths'];
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Settings that core resets only on `null`. For these, core reads `undefined` as "leave the current
|
|
756
|
+
* value", so forwarding the `undefined` default would keep the old size on the root element. `null`
|
|
757
|
+
* restores the root element's initial inline size, which is what a fresh mount without the prop gives.
|
|
758
|
+
*/
|
|
759
|
+
var CLEARED_BY_NULL_SETTINGS = new Set(['height', 'width']);
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Settings forwarded on every update, changed or not. An app may change the rows of its `data` array
|
|
763
|
+
* in place and re-render to show them, and passing the array again is what reloads them.
|
|
764
|
+
*/
|
|
765
|
+
var ALWAYS_FORWARDED_SETTINGS = ['data'];
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Settings compared by reference only. The sheets bar writes renames and added sheets into the
|
|
769
|
+
* `sheets` array it was given, so a new array is a new workbook even when its content matches, and
|
|
770
|
+
* walking every sheet's rows on each render would cost as much as the data itself. The Vue wrapper
|
|
771
|
+
* compares `sheets` the same way.
|
|
772
|
+
*/
|
|
773
|
+
var REFERENCE_COMPARED_SETTINGS = ['sheetsBar'];
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Copies of the values last passed to the grid, by setting name. The component keeps one per grid
|
|
777
|
+
* instance and passes it to every update.
|
|
778
|
+
*/
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Checks whether an update would pass a setting with the value it passed last time. Passing it again
|
|
782
|
+
* is not a no-op: core re-applies the plugins it names, and a plugin re-applied with its own settings
|
|
783
|
+
* drops the state the user gave it (Filters' conditions, Pagination's page, the server total of a
|
|
784
|
+
* `dataProvider` grid, and a refetch). A React app passes every prop on each render, often as an
|
|
785
|
+
* inline object, so the value is compared by content (`areEquivalentSettingsValue()`: functions and
|
|
786
|
+
* class instances by reference). The comparison is with a copy of the value last passed, not with the
|
|
787
|
+
* grid's live value: an object the app changed in place is the same reference the grid holds, so only
|
|
788
|
+
* the copy shows the change, and with the sheets bar on the live value is the visible sheet's own.
|
|
789
|
+
*
|
|
790
|
+
* @param {string} key The setting name.
|
|
791
|
+
* @param {*} value The value the update would pass.
|
|
792
|
+
* @param {ForwardedSettings} [forwardedSettings] The values last passed to the grid.
|
|
793
|
+
* @returns {boolean}
|
|
794
|
+
*/
|
|
795
|
+
function isSameAsForwarded(key, value, forwardedSettings) {
|
|
796
|
+
if (!(forwardedSettings !== null && forwardedSettings !== void 0 && forwardedSettings.has(key)) || ALWAYS_FORWARDED_SETTINGS.includes(key)) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
var forwardedValue = forwardedSettings.get(key);
|
|
800
|
+
return REFERENCE_COMPARED_SETTINGS.includes(key) ? forwardedValue === value : areEquivalentSettingsValue(forwardedValue, value);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Records the value an update passes to the grid, for the next update to compare with.
|
|
805
|
+
*
|
|
806
|
+
* @param {string} key The setting name.
|
|
807
|
+
* @param {*} value The value passed.
|
|
808
|
+
* @param {ForwardedSettings} [forwardedSettings] The values last passed to the grid.
|
|
809
|
+
*/
|
|
810
|
+
function recordForwarded(key, value, forwardedSettings) {
|
|
811
|
+
if (!forwardedSettings || ALWAYS_FORWARDED_SETTINGS.includes(key)) {
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
forwardedSettings.set(key, REFERENCE_COMPARED_SETTINGS.includes(key) ? value : copySettingsValue(value));
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Checks whether a setting is a hook, by the rule core's `updateSettings()` uses in `core.ts`: a
|
|
819
|
+
* registered or a deprecated hook name.
|
|
820
|
+
*
|
|
821
|
+
* @param {string} key The setting name.
|
|
822
|
+
* @returns {boolean}
|
|
823
|
+
*/
|
|
824
|
+
function isHookKey(key) {
|
|
825
|
+
return Handsontable.hooks.isRegistered(key) || Handsontable.hooks.isDeprecated(key);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Returns the value that clears a setting whose prop went from a value to `undefined`: `null` for a
|
|
830
|
+
* hook (it removes the callback) and for `height` and `width` (it resets the root element's size),
|
|
831
|
+
* and the option's default for anything else.
|
|
832
|
+
*
|
|
833
|
+
* @param {string} key The setting name.
|
|
834
|
+
* @returns {*} The value to forward to `updateSettings()`.
|
|
835
|
+
*/
|
|
836
|
+
function getClearedValue(key) {
|
|
837
|
+
if (isHookKey(key) || CLEARED_BY_NULL_SETTINGS.has(key)) {
|
|
838
|
+
return null;
|
|
839
|
+
}
|
|
840
|
+
return Handsontable.DefaultSettings[key];
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* Checks whether a hook value holds a callback core registers: a function or an array of them. Core
|
|
845
|
+
* ignores any other value for a hook, so `false` from `afterChange={on && logChange}` would leave the
|
|
846
|
+
* previous callback running.
|
|
847
|
+
*
|
|
848
|
+
* @param {*} value The hook value.
|
|
849
|
+
* @returns {boolean}
|
|
850
|
+
*/
|
|
851
|
+
function isHookCallback(value) {
|
|
852
|
+
return typeof value === 'function' || Array.isArray(value);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Returns the value to forward for a prop that is passed: the option's cleared value for `undefined`,
|
|
857
|
+
* `null` for a hook prop that holds no callback on an update, and the prop value otherwise.
|
|
858
|
+
*
|
|
859
|
+
* @param {string} key The setting name.
|
|
860
|
+
* @param {*} value The prop value.
|
|
861
|
+
* @param {boolean} isInit Whether the grid is being initialized.
|
|
862
|
+
* @returns {*} The value to forward to `updateSettings()`.
|
|
482
863
|
*/
|
|
483
|
-
|
|
864
|
+
function getForwardedValue(key, value, isInit) {
|
|
865
|
+
if (value === undefined) {
|
|
866
|
+
return getClearedValue(key);
|
|
867
|
+
}
|
|
868
|
+
if (!isInit && isHookKey(key) && !isHookCallback(value)) {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
return value;
|
|
872
|
+
}
|
|
484
873
|
var SettingsMapper = /*#__PURE__*/function () {
|
|
485
874
|
function SettingsMapper() {
|
|
486
875
|
_classCallCheck(this, SettingsMapper);
|
|
@@ -491,11 +880,27 @@ var SettingsMapper = /*#__PURE__*/function () {
|
|
|
491
880
|
/**
|
|
492
881
|
* Parse component settings into Handsontable-compatible settings.
|
|
493
882
|
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
883
|
+
* A prop whose value is `undefined` counts as not passed and is left out, so the option keeps its
|
|
884
|
+
* default. An own `undefined` key would shadow that default in the settings cascade. On an update
|
|
885
|
+
* of a prop that had a value in the previous props, the option's default is forwarded instead, so
|
|
886
|
+
* the grid matches a fresh mount with the same props (`copyPaste={on ? false : undefined}` turns
|
|
887
|
+
* copy and paste back on). `height` and `width` are forwarded as `null`, because core leaves the
|
|
888
|
+
* size in place for `undefined` (`height={full ? undefined : 400}` clears the height).
|
|
889
|
+
* A hook has no default to fall back to, so a hook prop that had a callback and is now `undefined`
|
|
890
|
+
* is forwarded as `null`, which removes the callback (`afterChange={on ? logChange : undefined}`).
|
|
891
|
+
* So is a hook prop that had a callback and is no longer passed at all, and, on an update, a hook
|
|
892
|
+
* prop that holds anything but a callback (`afterChange={on && logChange}` gives `false`).
|
|
893
|
+
* For an option that is not a hook, `null` and `false` are real values and are forwarded.
|
|
894
|
+
*
|
|
895
|
+
* @param {object} properties Object containing properties from the HotTable object.
|
|
896
|
+
* @param {object} additionalSettings Additional settings.
|
|
496
897
|
* @param {boolean} additionalSettings.isInit Flag determining whether the settings are being set during initialization.
|
|
497
898
|
* @param {string[]} additionalSettings.initOnlySettingKeys Array of keys that can be set only during initialization.
|
|
498
|
-
* @
|
|
899
|
+
* @param {HotTableProps} additionalSettings.prevProps The component's props before the current update.
|
|
900
|
+
* @param {Handsontable.GridSettings} additionalSettings.currentSettings The grid's current live settings.
|
|
901
|
+
* @param {ForwardedSettings} additionalSettings.forwardedSettings The values last passed to the grid. A
|
|
902
|
+
* setting whose value equals the one recorded there is left out, and every setting passed is recorded.
|
|
903
|
+
* @returns {object} Handsontable-compatible settings object.
|
|
499
904
|
*/
|
|
500
905
|
function getSettings(properties) {
|
|
501
906
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
@@ -504,21 +909,47 @@ var SettingsMapper = /*#__PURE__*/function () {
|
|
|
504
909
|
_ref$isInit = _ref.isInit,
|
|
505
910
|
isInit = _ref$isInit === void 0 ? false : _ref$isInit,
|
|
506
911
|
_ref$initOnlySettingK = _ref.initOnlySettingKeys,
|
|
507
|
-
initOnlySettingKeys = _ref$initOnlySettingK === void 0 ? [] : _ref$initOnlySettingK
|
|
912
|
+
initOnlySettingKeys = _ref$initOnlySettingK === void 0 ? [] : _ref$initOnlySettingK,
|
|
913
|
+
currentSettings = _ref.currentSettings,
|
|
914
|
+
forwardedSettings = _ref.forwardedSettings;
|
|
508
915
|
var shouldSkipProp = function shouldSkipProp(key) {
|
|
509
|
-
if (
|
|
510
|
-
return
|
|
916
|
+
if (isInit) {
|
|
917
|
+
return false;
|
|
511
918
|
}
|
|
512
|
-
|
|
919
|
+
|
|
920
|
+
// Checked before the value comparison below. The two lists do not overlap today, but a
|
|
921
|
+
// changed deep-comparable key used to return early and skip this guard entirely, which would
|
|
922
|
+
// have forwarded an init-only key to `updateSettings` as soon as one joined both lists.
|
|
923
|
+
if (initOnlySettingKeys.includes(key)) {
|
|
513
924
|
return true;
|
|
514
925
|
}
|
|
926
|
+
if (DEEP_COMPARABLE_SETTINGS.includes(key)) {
|
|
927
|
+
var comparedValue = currentSettings && COMPARED_AGAINST_LIVE_SETTINGS.includes(key) ? currentSettings[key] : prevProps[key];
|
|
928
|
+
return areEquivalentSettingsValue(comparedValue, properties[key]);
|
|
929
|
+
}
|
|
515
930
|
return false;
|
|
516
931
|
};
|
|
932
|
+
var isNotPassed = function isNotPassed(key) {
|
|
933
|
+
return properties[key] === undefined && (isInit || prevProps[key] === undefined);
|
|
934
|
+
};
|
|
517
935
|
var newSettings = {};
|
|
518
|
-
|
|
519
|
-
if (key !== 'children' && !
|
|
520
|
-
|
|
936
|
+
Object.keys(properties).forEach(function (key) {
|
|
937
|
+
if (key !== 'children' && !isNotPassed(key) && !shouldSkipProp(key)) {
|
|
938
|
+
var settingKey = key;
|
|
939
|
+
var value = getForwardedValue(key, properties[key], isInit);
|
|
940
|
+
if (isInit || DEEP_COMPARABLE_SETTINGS.includes(settingKey) || !isSameAsForwarded(settingKey, value, forwardedSettings)) {
|
|
941
|
+
newSettings[key] = value;
|
|
942
|
+
recordForwarded(settingKey, value, forwardedSettings);
|
|
943
|
+
}
|
|
521
944
|
}
|
|
945
|
+
});
|
|
946
|
+
if (!isInit) {
|
|
947
|
+
Object.keys(prevProps).forEach(function (key) {
|
|
948
|
+
if (!Object.hasOwn(properties, key) && prevProps[key] !== undefined && isHookKey(key)) {
|
|
949
|
+
newSettings[key] = null;
|
|
950
|
+
recordForwarded(key, null, forwardedSettings);
|
|
951
|
+
}
|
|
952
|
+
});
|
|
522
953
|
}
|
|
523
954
|
return newSettings;
|
|
524
955
|
}
|
|
@@ -536,39 +967,100 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
536
967
|
columnsSettings.current.length = length;
|
|
537
968
|
}, []);
|
|
538
969
|
var componentRendererColumns = useRef(new Map());
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
970
|
+
// One entry per cell the grid shows with a component renderer: the cell element, the container in
|
|
971
|
+
// it, and the portal that renders the component into the container. Keyed by the portal container key.
|
|
972
|
+
var cellPortals = useRef(new Map());
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* The renderer function made for each renderer component. It reads everything else through refs, so
|
|
976
|
+
* one function serves every render, and an update that passes the same `<HotColumn>` settings again
|
|
977
|
+
* finds them unchanged and leaves `columns` out.
|
|
978
|
+
*/
|
|
979
|
+
var rendererWrappers = useRef(new WeakMap());
|
|
545
980
|
// Keys of the portal containers rendered in the current view-render pass.
|
|
546
|
-
// Reset every `beforeViewRender` and used after the render to
|
|
547
|
-
//
|
|
981
|
+
// Reset every `beforeViewRender` and used after the render to tell the cells
|
|
982
|
+
// the pass painted from the ones it did not (see pushCellPortalsIntoPortalManager).
|
|
548
983
|
var renderedPortalContainerKeys = useRef(new Set());
|
|
549
|
-
|
|
550
|
-
|
|
984
|
+
// Cell elements the grid painted in the current view-render pass, with any renderer. A cell element
|
|
985
|
+
// the grid reuses for another cell keeps a component container when the new renderer does not clear
|
|
986
|
+
// the element, so a connected container alone does not prove its cell is still shown.
|
|
987
|
+
var paintedCells = useRef(new Set());
|
|
988
|
+
var resetRenderedPortals = useCallback(function () {
|
|
551
989
|
renderedPortalContainerKeys.current.clear();
|
|
990
|
+
paintedCells.current.clear();
|
|
991
|
+
}, []);
|
|
992
|
+
var markCellPainted = useCallback(function (TD) {
|
|
993
|
+
if (cellPortals.current.size > 0) {
|
|
994
|
+
paintedCells.current.add(TD);
|
|
995
|
+
}
|
|
552
996
|
}, []);
|
|
553
997
|
var getPortalContainerCacheSize = useCallback(function () {
|
|
554
|
-
return
|
|
998
|
+
return cellPortals.current.size;
|
|
999
|
+
}, []);
|
|
1000
|
+
|
|
1001
|
+
// Stable id per table element the grid draws into. Handsontable renders the
|
|
1002
|
+
// same cell once per table it appears in — the master table plus an overlay
|
|
1003
|
+
// table for every fixed row/column edge — and each draw gets its own TD.
|
|
1004
|
+
var tableIds = useRef(new WeakMap());
|
|
1005
|
+
var nextTableId = useRef(0);
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* Identify the table a rendered cell belongs to, so the master table and the
|
|
1009
|
+
* overlay tables get separate portal containers for the same cell.
|
|
1010
|
+
*
|
|
1011
|
+
* @param {HTMLTableCellElement} TD The cell being rendered.
|
|
1012
|
+
* @returns {number} The id of the table the cell belongs to.
|
|
1013
|
+
*/
|
|
1014
|
+
var getTableId = useCallback(function (TD) {
|
|
1015
|
+
var _TD$parentElement$par, _TD$parentElement;
|
|
1016
|
+
// TD -> TR -> TBODY. The section belongs to exactly one table, and the
|
|
1017
|
+
// overlay tables are built once and never hand their cells to another
|
|
1018
|
+
// table, so it is a stable identity for the draw. Two property hops rather
|
|
1019
|
+
// than a selector walk, because this runs for every component-rendered
|
|
1020
|
+
// cell on every render.
|
|
1021
|
+
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;
|
|
1022
|
+
var cachedId = tableIds.current.get(tableSection);
|
|
1023
|
+
if (cachedId !== undefined) {
|
|
1024
|
+
return cachedId;
|
|
1025
|
+
}
|
|
1026
|
+
var id = nextTableId.current;
|
|
1027
|
+
nextTableId.current += 1;
|
|
1028
|
+
tableIds.current.set(tableSection, id);
|
|
1029
|
+
return id;
|
|
555
1030
|
}, []);
|
|
556
1031
|
var getRendererWrapper = useCallback(function (Renderer) {
|
|
557
|
-
|
|
1032
|
+
var cachedWrapper = rendererWrappers.current.get(Renderer);
|
|
1033
|
+
if (cachedWrapper) {
|
|
1034
|
+
return cachedWrapper;
|
|
1035
|
+
}
|
|
1036
|
+
warnAboutClassicFunctionRenderer(Renderer);
|
|
1037
|
+
var wrapper = function __internalRenderer(instance, TD, row, col, prop, value, cellProperties) {
|
|
558
1038
|
var key = "".concat(row, "-").concat(col);
|
|
559
1039
|
|
|
560
1040
|
// Handsontable.Core type is missing guid
|
|
561
1041
|
var instanceGuid = instance.guid;
|
|
562
|
-
var portalContainerKey = "".concat(instanceGuid, "-").concat(key);
|
|
563
|
-
var portalKey = "".concat(key, "-").concat(instanceGuid);
|
|
564
1042
|
if (TD && !TD.getAttribute('ghost-table')) {
|
|
565
|
-
var
|
|
1043
|
+
var _cellPortals$current$;
|
|
1044
|
+
// The table has to be part of the key. A cell that sits in a fixed
|
|
1045
|
+
// column is drawn both in the master table and in the inline-start
|
|
1046
|
+
// overlay; keyed by coordinates alone, both draws share one container,
|
|
1047
|
+
// which then moves into whichever table rendered last and leaves the
|
|
1048
|
+
// other cell empty. The two tables then size their rows from different
|
|
1049
|
+
// content and stop lining up (see issue #9063).
|
|
1050
|
+
var tableId = getTableId(TD);
|
|
1051
|
+
var portalContainerKey = "".concat(instanceGuid, "-").concat(tableId, "-").concat(key);
|
|
1052
|
+
var portalKey = "".concat(key, "-").concat(tableId, "-").concat(instanceGuid);
|
|
1053
|
+
var cachedPortalContainer = (_cellPortals$current$ = cellPortals.current.get(portalContainerKey)) === null || _cellPortals$current$ === void 0 ? void 0 : _cellPortals$current$.container;
|
|
566
1054
|
// When the cached portal container is still attached to the same
|
|
567
1055
|
// TD as the previous render, the DOM is already correct and must
|
|
568
1056
|
// not be wiped. Wiping detaches the React-managed children, which
|
|
569
1057
|
// forces a full remount of the renderer component on every grid
|
|
570
1058
|
// render (see issue #10800).
|
|
571
|
-
|
|
1059
|
+
// A row rendered at an exact height (the `rowHeights` option) keeps the cell's content inside a
|
|
1060
|
+
// `div.htCellClip` wrapper that the grid adds after this renderer ran. The container then sits in
|
|
1061
|
+
// the wrapper, and wiping the cell on the next render would detach it all over again.
|
|
1062
|
+
var contentRoot = getCellContentRoot(TD);
|
|
1063
|
+
var containerInPlace = !!cachedPortalContainer && cachedPortalContainer.parentNode === contentRoot;
|
|
572
1064
|
var rendererElement = /*#__PURE__*/React.createElement(Renderer, {
|
|
573
1065
|
instance: instance,
|
|
574
1066
|
TD: TD,
|
|
@@ -582,19 +1074,23 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
582
1074
|
portal = _createPortal.portal,
|
|
583
1075
|
portalContainer = _createPortal.portalContainer;
|
|
584
1076
|
if (!containerInPlace) {
|
|
585
|
-
while (
|
|
586
|
-
|
|
1077
|
+
while (contentRoot.firstChild) {
|
|
1078
|
+
contentRoot.removeChild(contentRoot.firstChild);
|
|
587
1079
|
}
|
|
588
|
-
|
|
1080
|
+
contentRoot.appendChild(portalContainer);
|
|
589
1081
|
}
|
|
590
|
-
|
|
1082
|
+
cellPortals.current.set(portalContainerKey, {
|
|
1083
|
+
TD: TD,
|
|
1084
|
+
container: portalContainer,
|
|
1085
|
+
portal: portal
|
|
1086
|
+
});
|
|
591
1087
|
renderedPortalContainerKeys.current.add(portalContainerKey);
|
|
592
|
-
portalCache.current.set(portalKey, portal);
|
|
593
1088
|
}
|
|
594
|
-
renderedCellCache.current.set(key, TD);
|
|
595
1089
|
return TD;
|
|
596
1090
|
};
|
|
597
|
-
|
|
1091
|
+
rendererWrappers.current.set(Renderer, wrapper);
|
|
1092
|
+
return wrapper;
|
|
1093
|
+
}, [getTableId]);
|
|
598
1094
|
var renderersPortalManager = useRef(function () {
|
|
599
1095
|
return undefined;
|
|
600
1096
|
});
|
|
@@ -602,19 +1098,29 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
602
1098
|
renderersPortalManager.current = pmComponent;
|
|
603
1099
|
}, []);
|
|
604
1100
|
var pushCellPortalsIntoPortalManager = useCallback(function () {
|
|
605
|
-
//
|
|
606
|
-
//
|
|
607
|
-
//
|
|
608
|
-
//
|
|
609
|
-
//
|
|
610
|
-
//
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
1101
|
+
// A cell this pass did not paint with its component either left the grid or
|
|
1102
|
+
// was skipped. The grid skips a cell that did not change (`renderMode:
|
|
1103
|
+
// 'onChange'`) and leaves its element as it is, so the portal must stay or
|
|
1104
|
+
// React unmounts the component and the cell goes blank. A cell that left the
|
|
1105
|
+
// grid had its element removed (the container is detached), or its element
|
|
1106
|
+
// was painted for another cell this pass (with a renderer that may not clear
|
|
1107
|
+
// the element): evict those, or the cache leaks O(rows × cols) nodes and a
|
|
1108
|
+
// stale component stays visible. Kept entries also preserve the in-place
|
|
1109
|
+
// reuse that avoids remounting renderer components on every grid render
|
|
1110
|
+
// (#10800).
|
|
1111
|
+
var paintedKeys = renderedPortalContainerKeys.current;
|
|
1112
|
+
var portals = [];
|
|
1113
|
+
cellPortals.current.forEach(function (_ref2, cacheKey) {
|
|
1114
|
+
var TD = _ref2.TD,
|
|
1115
|
+
container = _ref2.container,
|
|
1116
|
+
portal = _ref2.portal;
|
|
1117
|
+
if (!paintedKeys.has(cacheKey) && (!container.isConnected || paintedCells.current.has(TD))) {
|
|
1118
|
+
cellPortals.current["delete"](cacheKey);
|
|
1119
|
+
return;
|
|
615
1120
|
}
|
|
1121
|
+
portals.push(portal);
|
|
616
1122
|
});
|
|
617
|
-
renderersPortalManager.current(
|
|
1123
|
+
renderersPortalManager.current(portals);
|
|
618
1124
|
}, []);
|
|
619
1125
|
var contextImpl = useMemo(function () {
|
|
620
1126
|
return {
|
|
@@ -623,13 +1129,13 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
623
1129
|
emitColumnSettings: setHotColumnSettings,
|
|
624
1130
|
trimColumnSettings: trimColumnSettings,
|
|
625
1131
|
getRendererWrapper: getRendererWrapper,
|
|
626
|
-
|
|
627
|
-
|
|
1132
|
+
resetRenderedPortals: resetRenderedPortals,
|
|
1133
|
+
markCellPainted: markCellPainted,
|
|
628
1134
|
getPortalContainerCacheSize: getPortalContainerCacheSize,
|
|
629
1135
|
setRenderersPortalManagerRef: setRenderersPortalManagerRef,
|
|
630
1136
|
pushCellPortalsIntoPortalManager: pushCellPortalsIntoPortalManager
|
|
631
1137
|
};
|
|
632
|
-
}, [setHotColumnSettings, trimColumnSettings, getRendererWrapper,
|
|
1138
|
+
}, [setHotColumnSettings, trimColumnSettings, getRendererWrapper, resetRenderedPortals, markCellPainted, getPortalContainerCacheSize, setRenderersPortalManagerRef, pushCellPortalsIntoPortalManager]);
|
|
633
1139
|
return /*#__PURE__*/React.createElement(HotTableContext.Provider, {
|
|
634
1140
|
value: contextImpl
|
|
635
1141
|
}, children);
|
|
@@ -638,7 +1144,7 @@ var HotTableContextProvider = function HotTableContextProvider(_ref) {
|
|
|
638
1144
|
/**
|
|
639
1145
|
* Exposes the table context object to components
|
|
640
1146
|
*
|
|
641
|
-
* @returns HotTableContext
|
|
1147
|
+
* @returns {HotTableContextImpl} HotTableContext
|
|
642
1148
|
*/
|
|
643
1149
|
function useHotTableContext() {
|
|
644
1150
|
return useContext(HotTableContext);
|
|
@@ -648,13 +1154,15 @@ var HotColumnContext = /*#__PURE__*/createContext(undefined);
|
|
|
648
1154
|
var HotColumnContextProvider = function HotColumnContextProvider(_ref) {
|
|
649
1155
|
var columnIndex = _ref.columnIndex,
|
|
650
1156
|
getOwnerDocument = _ref.getOwnerDocument,
|
|
1157
|
+
getEditorPortalHost = _ref.getEditorPortalHost,
|
|
651
1158
|
children = _ref.children;
|
|
652
1159
|
var contextImpl = useMemo(function () {
|
|
653
1160
|
return {
|
|
654
1161
|
columnIndex: columnIndex,
|
|
655
|
-
getOwnerDocument: getOwnerDocument
|
|
1162
|
+
getOwnerDocument: getOwnerDocument,
|
|
1163
|
+
getEditorPortalHost: getEditorPortalHost
|
|
656
1164
|
};
|
|
657
|
-
}, [columnIndex, getOwnerDocument]);
|
|
1165
|
+
}, [columnIndex, getOwnerDocument, getEditorPortalHost]);
|
|
658
1166
|
return /*#__PURE__*/React.createElement(HotColumnContext.Provider, {
|
|
659
1167
|
value: contextImpl
|
|
660
1168
|
}, children);
|
|
@@ -673,14 +1181,26 @@ var MethodsMap = {
|
|
|
673
1181
|
};
|
|
674
1182
|
|
|
675
1183
|
/**
|
|
676
|
-
*
|
|
1184
|
+
* The editor class made for each component's hooks reference. The class reads the hooks and the instance
|
|
1185
|
+
* through those references when it runs, so one class serves every render of the component, and an
|
|
1186
|
+
* update that passes the same class is left out like any other unchanged setting.
|
|
1187
|
+
*/
|
|
1188
|
+
var editorClasses = new WeakMap();
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Create a class to be passed to the Handsontable's settings, or return the one made for the same hooks
|
|
1192
|
+
* reference.
|
|
677
1193
|
*
|
|
678
1194
|
* @param {RefObject<HotEditorHooks>} hooksRef Reference to component-based editor overridden hooks object.
|
|
679
1195
|
* @param {RefObject} instanceRef Reference to Handsontable-native custom editor class instance.
|
|
680
1196
|
* @returns {Function} A class to be passed to the Handsontable editor settings.
|
|
681
1197
|
*/
|
|
682
1198
|
function makeEditorClass(hooksRef, instanceRef) {
|
|
683
|
-
|
|
1199
|
+
var cachedEditorClass = editorClasses.get(hooksRef);
|
|
1200
|
+
if (cachedEditorClass) {
|
|
1201
|
+
return cachedEditorClass;
|
|
1202
|
+
}
|
|
1203
|
+
var EditorClass = /*#__PURE__*/function (_Handsontable$editors) {
|
|
684
1204
|
function CustomEditor(hotInstance) {
|
|
685
1205
|
var _this;
|
|
686
1206
|
_classCallCheck(this, CustomEditor);
|
|
@@ -732,6 +1252,8 @@ function makeEditorClass(hooksRef, instanceRef) {
|
|
|
732
1252
|
value: function close() {}
|
|
733
1253
|
}]);
|
|
734
1254
|
}(Handsontable.editors.BaseEditor);
|
|
1255
|
+
editorClasses.set(hooksRef, EditorClass);
|
|
1256
|
+
return EditorClass;
|
|
735
1257
|
}
|
|
736
1258
|
/**
|
|
737
1259
|
* Context to provide Handsontable-native custom editor class instance to overridden hooks object.
|
|
@@ -741,8 +1263,11 @@ var EditorContext = /*#__PURE__*/createContext(undefined);
|
|
|
741
1263
|
* Provider of the context that exposes Handsontable-native editor instance and passes hooks object
|
|
742
1264
|
* for custom editor components.
|
|
743
1265
|
*
|
|
744
|
-
* @param {
|
|
745
|
-
* @param {
|
|
1266
|
+
* @param {object} root0 The provider props.
|
|
1267
|
+
* @param {Ref} root0.hooksRef Reference for component-based editor overridden hooks object.
|
|
1268
|
+
* @param {RefObject} root0.hotCustomEditorInstanceRef Reference to Handsontable-native editor instance.
|
|
1269
|
+
* @param {ReactNode} root0.children The provider's children.
|
|
1270
|
+
* @returns {ReactElement} The provider component.
|
|
746
1271
|
*/
|
|
747
1272
|
var EditorContextProvider = function EditorContextProvider(_ref3) {
|
|
748
1273
|
var hooksRef = _ref3.hooksRef,
|
|
@@ -757,7 +1282,13 @@ var EditorContextProvider = function EditorContextProvider(_ref3) {
|
|
|
757
1282
|
};
|
|
758
1283
|
/**
|
|
759
1284
|
* Applies editor overlay position/dimensions to an element.
|
|
760
|
-
*
|
|
1285
|
+
*
|
|
1286
|
+
* @param {HTMLElement} el The editor's main element.
|
|
1287
|
+
* @param {EditorWithPosition} editor The editor instance.
|
|
1288
|
+
* @param {Handsontable.Core} hot The Handsontable instance.
|
|
1289
|
+
* @param {Element | null | undefined} td The edited cell's TD element.
|
|
1290
|
+
* @returns {boolean} `true` if position was applied, `false` if editor should close (e.g. cell no longer
|
|
1291
|
+
* available).
|
|
761
1292
|
*/
|
|
762
1293
|
function applyEditorPosition(el, editor, hot, td) {
|
|
763
1294
|
var _rootWindow$pageXOffs, _rootWindow$pageYOffs;
|
|
@@ -809,7 +1340,7 @@ function applyEditorPosition(el, editor, hot, td) {
|
|
|
809
1340
|
}
|
|
810
1341
|
|
|
811
1342
|
/**
|
|
812
|
-
* Hook that allows encapsulating custom
|
|
1343
|
+
* Hook that allows encapsulating custom behaviors of component-based editor by customizing passed ref with overridden hooks object.
|
|
813
1344
|
*
|
|
814
1345
|
* @param {HotEditorHooks} overriddenHooks Overrides specific for the custom editor.
|
|
815
1346
|
* @param {DependencyList} deps Overridden hooks object React dependency list.
|
|
@@ -827,15 +1358,12 @@ function useHotEditor(overriddenHooks, deps) {
|
|
|
827
1358
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
828
1359
|
editorValue = _useState4[0],
|
|
829
1360
|
setEditorValue = _useState4[1];
|
|
830
|
-
|
|
831
|
-
// return a deferred value that allows for optimizing performance by delaying the update of a value until the next render.
|
|
832
|
-
var deferredValue = useDeferredValue(editorValue);
|
|
833
1361
|
useImperativeHandle(hooksRef, function () {
|
|
834
1362
|
return _objectSpread2(_objectSpread2({}, overriddenHooks), {}, {
|
|
835
|
-
onOpen: function onOpen() {
|
|
1363
|
+
onOpen: function onOpen(event) {
|
|
836
1364
|
var _hotCustomEditorInsta, _overriddenHooks$onOp;
|
|
837
1365
|
setEditorValue((_hotCustomEditorInsta = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta === void 0 ? void 0 : _hotCustomEditorInsta.getValue());
|
|
838
|
-
overriddenHooks === null || overriddenHooks === void 0 || (_overriddenHooks$onOp = overriddenHooks.onOpen) === null || _overriddenHooks$onOp === void 0 || _overriddenHooks$onOp.call(overriddenHooks);
|
|
1366
|
+
overriddenHooks === null || overriddenHooks === void 0 || (_overriddenHooks$onOp = overriddenHooks.onOpen) === null || _overriddenHooks$onOp === void 0 || _overriddenHooks$onOp.call(overriddenHooks, event);
|
|
839
1367
|
setRerenderTrigger(function (t) {
|
|
840
1368
|
return t + 1;
|
|
841
1369
|
});
|
|
@@ -845,7 +1373,7 @@ function useHotEditor(overriddenHooks, deps) {
|
|
|
845
1373
|
return useMemo(function () {
|
|
846
1374
|
return {
|
|
847
1375
|
get value() {
|
|
848
|
-
return
|
|
1376
|
+
return editorValue;
|
|
849
1377
|
},
|
|
850
1378
|
setValue: function setValue(newValue) {
|
|
851
1379
|
var _hotCustomEditorInsta2;
|
|
@@ -871,21 +1399,35 @@ function useHotEditor(overriddenHooks, deps) {
|
|
|
871
1399
|
return col !== null && col !== void 0 ? col : undefined;
|
|
872
1400
|
}
|
|
873
1401
|
};
|
|
874
|
-
}, [rerenderTrigger, hotCustomEditorInstanceRef,
|
|
1402
|
+
}, [rerenderTrigger, hotCustomEditorInstanceRef, editorValue]);
|
|
875
1403
|
}
|
|
876
1404
|
|
|
877
1405
|
// Render prop function type
|
|
878
1406
|
|
|
879
1407
|
// EditorComponent props - children typed to work with JSX syntax
|
|
880
1408
|
|
|
1409
|
+
/**
|
|
1410
|
+
* Component-based editor. Renders the `children` render prop inside the editor's positioned overlay
|
|
1411
|
+
* and wires up its shortcuts and scroll-repositioning.
|
|
1412
|
+
*
|
|
1413
|
+
* @param {object} root0 The component props.
|
|
1414
|
+
* @param {Function} [root0.onPrepare] Called when the editor is prepared for a cell.
|
|
1415
|
+
* @param {Function} [root0.onClose] Called when the editor closes.
|
|
1416
|
+
* @param {Function} [root0.onOpen] Called when the editor opens. Receives the DOM event that opened the editor. It is `undefined` when you call `beginEditing()`.
|
|
1417
|
+
* @param {Function} [root0.onFocus] Called when the editor is focused.
|
|
1418
|
+
* @param {EditorRenderProp} [root0.children] Render prop returning the editor's UI.
|
|
1419
|
+
* @param {string} [root0.shortcutsGroup] The shortcuts group name to register under.
|
|
1420
|
+
* @param {Array} [root0.shortcuts] The editor's keyboard shortcuts.
|
|
1421
|
+
* @returns {React.ReactElement} The editor overlay element.
|
|
1422
|
+
*/
|
|
881
1423
|
function EditorComponent(_ref5) {
|
|
882
1424
|
var _onPrepare = _ref5.onPrepare,
|
|
883
1425
|
_onClose = _ref5.onClose,
|
|
884
|
-
|
|
1426
|
+
onOpen = _ref5.onOpen,
|
|
885
1427
|
_onFocus = _ref5.onFocus,
|
|
886
1428
|
children = _ref5.children,
|
|
887
1429
|
_ref5$shortcutsGroup = _ref5.shortcutsGroup,
|
|
888
|
-
shortcutsGroup = _ref5$shortcutsGroup === void 0 ?
|
|
1430
|
+
shortcutsGroup = _ref5$shortcutsGroup === void 0 ? 'custom-editor' : _ref5$shortcutsGroup,
|
|
889
1431
|
shortcuts = _ref5.shortcuts;
|
|
890
1432
|
var mainElementRef = useRef(null);
|
|
891
1433
|
var currentValue = useRef(undefined);
|
|
@@ -897,8 +1439,10 @@ function EditorComponent(_ref5) {
|
|
|
897
1439
|
hotCustomEditorInstanceRef = _ref6.hotCustomEditorInstanceRef;
|
|
898
1440
|
var registerShortcuts = useCallback(function () {
|
|
899
1441
|
var _hotCustomEditorInsta8, _hotCustomEditorInsta9, _hotCustomEditorInsta0;
|
|
900
|
-
if (!((_hotCustomEditorInsta8 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta8 !== void 0 && _hotCustomEditorInsta8.hot))
|
|
901
|
-
|
|
1442
|
+
if (!((_hotCustomEditorInsta8 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta8 !== void 0 && _hotCustomEditorInsta8.hot)) {
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
(_hotCustomEditorInsta9 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta9 === void 0 || (_hotCustomEditorInsta9 = _hotCustomEditorInsta9.hot) === null || _hotCustomEditorInsta9 === void 0 || _hotCustomEditorInsta9.getShortcutManager().setActiveContextName('editor');
|
|
902
1446
|
var shortcutManager = (_hotCustomEditorInsta0 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta0 === void 0 || (_hotCustomEditorInsta0 = _hotCustomEditorInsta0.hot) === null || _hotCustomEditorInsta0 === void 0 ? void 0 : _hotCustomEditorInsta0.getShortcutManager();
|
|
903
1447
|
var editorContext = shortcutManager.getContext('editor');
|
|
904
1448
|
var contextConfig = {
|
|
@@ -918,61 +1462,97 @@ function EditorComponent(_ref5) {
|
|
|
918
1462
|
}, event);
|
|
919
1463
|
}
|
|
920
1464
|
});
|
|
921
|
-
}),
|
|
922
|
-
//@ts-ignore
|
|
923
|
-
contextConfig);
|
|
1465
|
+
}), contextConfig);
|
|
924
1466
|
}
|
|
925
1467
|
}, [shortcuts]);
|
|
926
1468
|
var unRegisterShortcuts = useCallback(function () {
|
|
927
1469
|
var _hotCustomEditorInsta1, _hotCustomEditorInsta10;
|
|
928
|
-
if (!((_hotCustomEditorInsta1 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta1 !== void 0 && _hotCustomEditorInsta1.hot))
|
|
1470
|
+
if (!((_hotCustomEditorInsta1 = hotCustomEditorInstanceRef.current) !== null && _hotCustomEditorInsta1 !== void 0 && _hotCustomEditorInsta1.hot)) {
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
929
1473
|
var shortcutManager = (_hotCustomEditorInsta10 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta10 === void 0 || (_hotCustomEditorInsta10 = _hotCustomEditorInsta10.hot) === null || _hotCustomEditorInsta10 === void 0 ? void 0 : _hotCustomEditorInsta10.getShortcutManager();
|
|
930
|
-
var editorContext = shortcutManager.getContext(
|
|
1474
|
+
var editorContext = shortcutManager.getContext('editor');
|
|
931
1475
|
editorContext.removeShortcutsByGroup(shortcutsGroup);
|
|
932
1476
|
}, [shortcuts]);
|
|
933
1477
|
var refreshDimensions = useCallback(function () {
|
|
934
1478
|
var editor = hotCustomEditorInstanceRef.current;
|
|
935
1479
|
var el = mainElementRef.current;
|
|
936
|
-
if (!editor || !el)
|
|
1480
|
+
if (!editor || !el) {
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
937
1483
|
var hot = editor.hot;
|
|
938
|
-
if (!hot)
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1484
|
+
if (!hot) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
if (typeof editor.isOpened !== 'function' || !editor.isOpened()) {
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
// Leave an editor that waits for an async validator alone, as core `TextEditor` does. The scroll
|
|
1492
|
+
// hooks call this without core's wait, and a cancel here would not stop the pending validation:
|
|
1493
|
+
// a rejected value then put the editor back in edit mode while it was closed.
|
|
1494
|
+
if (editor.state !== 'STATE_EDITING') {
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// The edited cell is not rendered (it scrolled out of view). End the edit without saving and reset
|
|
1499
|
+
// the editor, so the next key starts a new edit. A bare `close()` hid the element but left the
|
|
1500
|
+
// editor open, so it never showed again and kept the keyboard.
|
|
1501
|
+
if (!applyEditorPosition(el, editor, hot)) {
|
|
1502
|
+
editor.cancelChanges();
|
|
942
1503
|
}
|
|
943
1504
|
}, []);
|
|
944
1505
|
var unRegisterScrollHooks = useCallback(function () {
|
|
945
1506
|
var editor = hotCustomEditorInstanceRef.current;
|
|
946
1507
|
var hot = editor === null || editor === void 0 ? void 0 : editor.hot;
|
|
947
|
-
if (!hot || typeof hot.removeHook !== 'function')
|
|
1508
|
+
if (!hot || typeof hot.removeHook !== 'function') {
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
948
1511
|
hot.removeHook('afterScrollHorizontally', refreshDimensions);
|
|
949
1512
|
hot.removeHook('afterScrollVertically', refreshDimensions);
|
|
950
1513
|
}, [refreshDimensions]);
|
|
951
1514
|
var registerScrollHooks = useCallback(function () {
|
|
952
1515
|
var editor = hotCustomEditorInstanceRef.current;
|
|
953
1516
|
var hot = editor === null || editor === void 0 ? void 0 : editor.hot;
|
|
954
|
-
if (!hot || typeof hot.addHook !== 'function')
|
|
1517
|
+
if (!hot || typeof hot.addHook !== 'function') {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
955
1520
|
hot.addHook('afterScrollHorizontally', refreshDimensions);
|
|
956
1521
|
hot.addHook('afterScrollVertically', refreshDimensions);
|
|
957
1522
|
}, [refreshDimensions]);
|
|
958
1523
|
var _useHotEditor = useHotEditor({
|
|
959
|
-
onOpen: function
|
|
1524
|
+
onOpen: function (_onOpen) {
|
|
1525
|
+
function onOpen(_x) {
|
|
1526
|
+
return _onOpen.apply(this, arguments);
|
|
1527
|
+
}
|
|
1528
|
+
onOpen.toString = function () {
|
|
1529
|
+
return _onOpen.toString();
|
|
1530
|
+
};
|
|
1531
|
+
return onOpen;
|
|
1532
|
+
}(function (event) {
|
|
960
1533
|
var _hotCustomEditorInsta11;
|
|
961
|
-
if (!mainElementRef.current)
|
|
1534
|
+
if (!mainElementRef.current) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
962
1537
|
var themeName = (_hotCustomEditorInsta11 = hotCustomEditorInstanceRef.current) === null || _hotCustomEditorInsta11 === void 0 ? void 0 : _hotCustomEditorInsta11.hot.getCurrentThemeName();
|
|
963
|
-
if (themeName)
|
|
1538
|
+
if (themeName) {
|
|
1539
|
+
setThemeClassName(themeName);
|
|
1540
|
+
}
|
|
964
1541
|
mainElementRef.current.style.display = 'block';
|
|
965
|
-
_onOpen === null || _onOpen === void 0 || _onOpen();
|
|
966
1542
|
var el = mainElementRef.current;
|
|
967
1543
|
var editor = hotCustomEditorInstanceRef.current;
|
|
968
1544
|
if (el && editor !== null && editor !== void 0 && editor.hot) {
|
|
969
1545
|
applyEditorPosition(el, editor, editor.hot);
|
|
1546
|
+
editor.refreshDimensions = refreshDimensions;
|
|
970
1547
|
}
|
|
1548
|
+
onOpen === null || onOpen === void 0 || onOpen(event);
|
|
971
1549
|
registerShortcuts();
|
|
972
1550
|
registerScrollHooks();
|
|
973
|
-
},
|
|
1551
|
+
}),
|
|
974
1552
|
onClose: function onClose() {
|
|
975
|
-
if (!mainElementRef.current)
|
|
1553
|
+
if (!mainElementRef.current) {
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
976
1556
|
mainElementRef.current.style.display = 'none';
|
|
977
1557
|
_onClose === null || _onClose === void 0 || _onClose();
|
|
978
1558
|
unRegisterShortcuts();
|
|
@@ -1031,7 +1611,8 @@ var HotColumn = function HotColumn(props) {
|
|
|
1031
1611
|
getRendererWrapper = _useHotTableContext.getRendererWrapper;
|
|
1032
1612
|
var _useHotColumnContext = useHotColumnContext(),
|
|
1033
1613
|
columnIndex = _useHotColumnContext.columnIndex,
|
|
1034
|
-
getOwnerDocument = _useHotColumnContext.getOwnerDocument
|
|
1614
|
+
getOwnerDocument = _useHotColumnContext.getOwnerDocument,
|
|
1615
|
+
getEditorPortalHost = _useHotColumnContext.getEditorPortalHost;
|
|
1035
1616
|
|
|
1036
1617
|
/**
|
|
1037
1618
|
* Reference to component-based editor overridden hooks object.
|
|
@@ -1050,7 +1631,7 @@ var HotColumn = function HotColumn(props) {
|
|
|
1050
1631
|
/**
|
|
1051
1632
|
* Filter out all the internal properties and return an object with just the Handsontable-related props.
|
|
1052
1633
|
*
|
|
1053
|
-
* @returns {
|
|
1634
|
+
* @returns {object}
|
|
1054
1635
|
*/
|
|
1055
1636
|
var getSettingsProps = function getSettingsProps() {
|
|
1056
1637
|
return Object.keys(props).filter(function (key) {
|
|
@@ -1063,6 +1644,8 @@ var HotColumn = function HotColumn(props) {
|
|
|
1063
1644
|
|
|
1064
1645
|
/**
|
|
1065
1646
|
* Create the column settings based on the data provided to the `HotColumn` component and its child components.
|
|
1647
|
+
*
|
|
1648
|
+
* @returns {object} The column settings object.
|
|
1066
1649
|
*/
|
|
1067
1650
|
var createColumnSettings = function createColumnSettings() {
|
|
1068
1651
|
var columnSettings = SettingsMapper.getSettings(getSettingsProps());
|
|
@@ -1072,10 +1655,17 @@ var HotColumn = function HotColumn(props) {
|
|
|
1072
1655
|
} else if (props.hotRenderer) {
|
|
1073
1656
|
columnSettings.renderer = props.hotRenderer;
|
|
1074
1657
|
}
|
|
1075
|
-
if (props.editor) {
|
|
1658
|
+
if (isComponentEditor(props.editor)) {
|
|
1076
1659
|
columnSettings.editor = makeEditorClass(localEditorHooksRef, localEditorClassInstance);
|
|
1077
|
-
} else
|
|
1078
|
-
|
|
1660
|
+
} else {
|
|
1661
|
+
var editorSetting = resolveEditorSetting(props.editor, props.hotEditor);
|
|
1662
|
+
if (editorSetting === undefined) {
|
|
1663
|
+
// Neither prop named an editor. Drop whatever the settings mapper copied over — it can be
|
|
1664
|
+
// a bare `true`, which the core rejects — and let the column inherit the grid editor.
|
|
1665
|
+
delete columnSettings.editor;
|
|
1666
|
+
} else {
|
|
1667
|
+
columnSettings.editor = editorSetting;
|
|
1668
|
+
}
|
|
1079
1669
|
}
|
|
1080
1670
|
return columnSettings;
|
|
1081
1671
|
};
|
|
@@ -1085,7 +1675,7 @@ var HotColumn = function HotColumn(props) {
|
|
|
1085
1675
|
displayAnyChildrenWarning(props.children);
|
|
1086
1676
|
}
|
|
1087
1677
|
});
|
|
1088
|
-
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor);
|
|
1678
|
+
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor, getEditorPortalHost());
|
|
1089
1679
|
|
|
1090
1680
|
/**
|
|
1091
1681
|
* Render the portals of the editors, if there are any.
|
|
@@ -1098,21 +1688,7 @@ var HotColumn = function HotColumn(props) {
|
|
|
1098
1688
|
}, editorPortal);
|
|
1099
1689
|
};
|
|
1100
1690
|
|
|
1101
|
-
var version="
|
|
1102
|
-
|
|
1103
|
-
/**
|
|
1104
|
-
* Component used to manage the renderer component portals.
|
|
1105
|
-
*/
|
|
1106
|
-
var RenderersPortalManager = /*#__PURE__*/forwardRef(function (_, ref) {
|
|
1107
|
-
var _useState = useState([]),
|
|
1108
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
1109
|
-
portals = _useState2[0],
|
|
1110
|
-
setPortals = _useState2[1];
|
|
1111
|
-
useImperativeHandle(ref, function () {
|
|
1112
|
-
return setPortals;
|
|
1113
|
-
});
|
|
1114
|
-
return /*#__PURE__*/React.createElement(Fragment, null, portals);
|
|
1115
|
-
});
|
|
1691
|
+
var version="19.0.0-rc1";
|
|
1116
1692
|
|
|
1117
1693
|
function getDefaultExportFromCjs (x) {
|
|
1118
1694
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -2237,6 +2813,20 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2237
2813
|
var propTypesExports = propTypes.exports;
|
|
2238
2814
|
var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
|
|
2239
2815
|
|
|
2816
|
+
/**
|
|
2817
|
+
* Component used to manage the renderer component portals.
|
|
2818
|
+
*/
|
|
2819
|
+
var RenderersPortalManager = /*#__PURE__*/forwardRef(function (_, ref) {
|
|
2820
|
+
var _useState = useState([]),
|
|
2821
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2822
|
+
portals = _useState2[0],
|
|
2823
|
+
setPortals = _useState2[1];
|
|
2824
|
+
useImperativeHandle(ref, function () {
|
|
2825
|
+
return setPortals;
|
|
2826
|
+
});
|
|
2827
|
+
return /*#__PURE__*/React.createElement(Fragment, null, portals);
|
|
2828
|
+
});
|
|
2829
|
+
|
|
2240
2830
|
var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
2241
2831
|
/**
|
|
2242
2832
|
* Reference to the Handsontable instance.
|
|
@@ -2258,11 +2848,36 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2258
2848
|
*/
|
|
2259
2849
|
var globalEditorClassInstance = useRef(null);
|
|
2260
2850
|
|
|
2851
|
+
/**
|
|
2852
|
+
* Stable host for React editor portals. Appended to `rootPortalElement` after init
|
|
2853
|
+
* so core treats editor UI as inside the grid (see `#isPathWithinGrid`).
|
|
2854
|
+
*/
|
|
2855
|
+
var editorPortalHostRef = useRef(null);
|
|
2856
|
+
|
|
2261
2857
|
/**
|
|
2262
2858
|
* Reference to the previous props object.
|
|
2263
2859
|
*/
|
|
2264
2860
|
var prevProps = useRef();
|
|
2265
2861
|
|
|
2862
|
+
/**
|
|
2863
|
+
* A copy of the `HotColumn` settings last passed to the grid. The children write their settings
|
|
2864
|
+
* into one array that the grid also holds, so the array itself cannot tell whether they changed.
|
|
2865
|
+
*/
|
|
2866
|
+
var forwardedColumnsSettings = useRef(null);
|
|
2867
|
+
|
|
2868
|
+
/**
|
|
2869
|
+
* Copies of the settings last passed to the grid, compared with on every update so an unchanged prop
|
|
2870
|
+
* is left out (`SettingsMapper.getSettings()`). Started again for every new instance.
|
|
2871
|
+
*/
|
|
2872
|
+
var forwardedSettings = useRef(new Map());
|
|
2873
|
+
|
|
2874
|
+
/**
|
|
2875
|
+
* Whether the settings last passed to the grid named a grid-level editor (`editor`, `hotEditor`) and a
|
|
2876
|
+
* grid-level renderer (`renderer`, `hotRenderer`).
|
|
2877
|
+
*/
|
|
2878
|
+
var namedGlobalEditor = useRef(false);
|
|
2879
|
+
var namedGlobalRenderer = useRef(false);
|
|
2880
|
+
|
|
2266
2881
|
/**
|
|
2267
2882
|
* HotTable context exposing helper functions.
|
|
2268
2883
|
*/
|
|
@@ -2288,7 +2903,6 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2288
2903
|
* Clear both the editor and the renderer cache.
|
|
2289
2904
|
*/
|
|
2290
2905
|
var clearCache = useCallback(function () {
|
|
2291
|
-
context.clearRenderedCellCache();
|
|
2292
2906
|
context.componentRendererColumns.clear();
|
|
2293
2907
|
}, [context]);
|
|
2294
2908
|
|
|
@@ -2304,42 +2918,94 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2304
2918
|
return null;
|
|
2305
2919
|
}, [hotElementRef]);
|
|
2306
2920
|
|
|
2921
|
+
/**
|
|
2922
|
+
* Get or create the stable editor portal host.
|
|
2923
|
+
*
|
|
2924
|
+
* @returns {HTMLElement | null} The host element, or `null` before a document is available.
|
|
2925
|
+
*/
|
|
2926
|
+
var getEditorPortalHost = useCallback(function () {
|
|
2927
|
+
var doc = getOwnerDocument();
|
|
2928
|
+
if (!doc) {
|
|
2929
|
+
return null;
|
|
2930
|
+
}
|
|
2931
|
+
if (!editorPortalHostRef.current) {
|
|
2932
|
+
var host = doc.createElement('div');
|
|
2933
|
+
host.className = EDITOR_PORTAL_HOST_CLASSNAME;
|
|
2934
|
+
doc.body.appendChild(host);
|
|
2935
|
+
editorPortalHostRef.current = host;
|
|
2936
|
+
} else if (!editorPortalHostRef.current.isConnected) {
|
|
2937
|
+
doc.body.appendChild(editorPortalHostRef.current);
|
|
2938
|
+
}
|
|
2939
|
+
return editorPortalHostRef.current;
|
|
2940
|
+
}, [getOwnerDocument]);
|
|
2941
|
+
|
|
2307
2942
|
/**
|
|
2308
2943
|
* Create a new settings object containing the column settings and global editors and renderers.
|
|
2309
2944
|
*
|
|
2945
|
+
* @param {boolean} init `true` when called during the initial mount.
|
|
2946
|
+
* @param {HotTableProps} previousProps The component's props before the current update.
|
|
2310
2947
|
* @returns {Handsontable.GridSettings} New global set of settings for Handsontable.
|
|
2311
2948
|
*/
|
|
2312
2949
|
var createNewGlobalSettings = function createNewGlobalSettings() {
|
|
2313
2950
|
var _getHotInstance;
|
|
2314
2951
|
var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
2315
|
-
var
|
|
2316
|
-
var
|
|
2317
|
-
|
|
2318
|
-
|
|
2952
|
+
var previousProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2953
|
+
var liveSettings = !isHotInstanceDestroyed() ? (_getHotInstance = getHotInstance()) === null || _getHotInstance === void 0 ? void 0 : _getHotInstance.getSettings() : undefined;
|
|
2954
|
+
var initOnlySettingKeys = (liveSettings === null || liveSettings === void 0 ? void 0 : liveSettings._initOnlySettings) || [];
|
|
2955
|
+
if (init) {
|
|
2956
|
+
forwardedSettings.current = new Map();
|
|
2957
|
+
}
|
|
2319
2958
|
var newSettings = SettingsMapper.getSettings(props, {
|
|
2320
|
-
prevProps:
|
|
2959
|
+
prevProps: previousProps,
|
|
2321
2960
|
isInit: init,
|
|
2322
|
-
initOnlySettingKeys: initOnlySettingKeys
|
|
2961
|
+
initOnlySettingKeys: initOnlySettingKeys,
|
|
2962
|
+
currentSettings: liveSettings,
|
|
2963
|
+
forwardedSettings: forwardedSettings.current
|
|
2323
2964
|
});
|
|
2324
2965
|
if (context.columnsSettings.length) {
|
|
2325
|
-
|
|
2966
|
+
if (init || !areEquivalentSettingsValue(forwardedColumnsSettings.current, context.columnsSettings)) {
|
|
2967
|
+
newSettings.columns = context.columnsSettings;
|
|
2968
|
+
forwardedColumnsSettings.current = copySettingsValue(context.columnsSettings);
|
|
2969
|
+
} else {
|
|
2970
|
+
delete newSettings.columns;
|
|
2971
|
+
}
|
|
2326
2972
|
}
|
|
2973
|
+
|
|
2974
|
+
// The grid-level `type` supplies the editor and the renderer no prop names, so an unnamed one is left out
|
|
2975
|
+
// of the payload. When the prop that named one is removed, `undefined` is sent: core reads it as "unset"
|
|
2976
|
+
// and the current `type` supplies the editor or the renderer again.
|
|
2977
|
+
var applyUnnamedSetting = function applyUnnamedSetting(key, wasNamed) {
|
|
2978
|
+
if (wasNamed) {
|
|
2979
|
+
newSettings[key] = undefined;
|
|
2980
|
+
} else {
|
|
2981
|
+
delete newSettings[key];
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2327
2984
|
if (props.renderer) {
|
|
2328
2985
|
newSettings.renderer = context.getRendererWrapper(props.renderer);
|
|
2329
2986
|
context.componentRendererColumns.set('global', true);
|
|
2987
|
+
} else if (props.hotRenderer) {
|
|
2988
|
+
newSettings.renderer = props.hotRenderer;
|
|
2330
2989
|
} else {
|
|
2331
|
-
|
|
2990
|
+
applyUnnamedSetting('renderer', namedGlobalRenderer.current);
|
|
2332
2991
|
}
|
|
2333
|
-
|
|
2334
|
-
|
|
2992
|
+
namedGlobalRenderer.current = Boolean(props.renderer || props.hotRenderer);
|
|
2993
|
+
var editorSetting = isComponentEditor(props.editor) ? makeEditorClass(globalEditorHooksRef, globalEditorClassInstance) : resolveEditorSetting(props.editor, props.hotEditor);
|
|
2994
|
+
|
|
2995
|
+
// `undefined` means neither prop named an editor.
|
|
2996
|
+
if (editorSetting === undefined) {
|
|
2997
|
+
applyUnnamedSetting('editor', namedGlobalEditor.current);
|
|
2335
2998
|
} else {
|
|
2336
|
-
newSettings.editor =
|
|
2999
|
+
newSettings.editor = editorSetting;
|
|
2337
3000
|
}
|
|
3001
|
+
namedGlobalEditor.current = editorSetting !== undefined;
|
|
2338
3002
|
return newSettings;
|
|
2339
3003
|
};
|
|
2340
3004
|
|
|
2341
3005
|
/**
|
|
2342
3006
|
* Detect if `autoRowSize` or `autoColumnSize` is defined, and if so, throw an incompatibility warning.
|
|
3007
|
+
*
|
|
3008
|
+
* @param {Handsontable | null} hotInstance The Handsontable instance to check.
|
|
2343
3009
|
*/
|
|
2344
3010
|
var displayAutoSizeWarning = function displayAutoSizeWarning(hotInstance) {
|
|
2345
3011
|
var _hotInstance$getPlugi, _hotInstance$getPlugi2;
|
|
@@ -2370,8 +3036,15 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2370
3036
|
* Handsontable's `beforeViewRender` hook callback.
|
|
2371
3037
|
*/
|
|
2372
3038
|
__hotInstance.current.addHook('beforeViewRender', function () {
|
|
2373
|
-
context.
|
|
2374
|
-
|
|
3039
|
+
context.resetRenderedPortals();
|
|
3040
|
+
});
|
|
3041
|
+
|
|
3042
|
+
/**
|
|
3043
|
+
* Handsontable's `beforeRenderer` hook callback. It runs for every cell the grid paints, whatever
|
|
3044
|
+
* the cell's renderer.
|
|
3045
|
+
*/
|
|
3046
|
+
__hotInstance.current.addHook('beforeRenderer', function (TD) {
|
|
3047
|
+
context.markCellPainted(TD);
|
|
2375
3048
|
});
|
|
2376
3049
|
|
|
2377
3050
|
/**
|
|
@@ -2381,6 +3054,15 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2381
3054
|
context.pushCellPortalsIntoPortalManager();
|
|
2382
3055
|
});
|
|
2383
3056
|
__hotInstance.current.init();
|
|
3057
|
+
var portalHost = editorPortalHostRef.current;
|
|
3058
|
+
var rootPortalElement = __hotInstance.current.rootPortalElement;
|
|
3059
|
+
if (portalHost && rootPortalElement) {
|
|
3060
|
+
if (portalHost.parentNode !== rootPortalElement) {
|
|
3061
|
+
rootPortalElement.appendChild(portalHost);
|
|
3062
|
+
}
|
|
3063
|
+
} else if (portalHost && !rootPortalElement) {
|
|
3064
|
+
warn(MISSING_ROOT_PORTAL_WARNING);
|
|
3065
|
+
}
|
|
2384
3066
|
displayAutoSizeWarning(__hotInstance.current);
|
|
2385
3067
|
if (!displayObsoleteRenderersEditorsWarning(props.children)) {
|
|
2386
3068
|
displayChildrenOfTypeWarning(props.children, HotColumn);
|
|
@@ -2390,7 +3072,8 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2390
3072
|
* Destroy the Handsontable instance when the parent component unmounts.
|
|
2391
3073
|
*/
|
|
2392
3074
|
return function () {
|
|
2393
|
-
var _getHotInstance2;
|
|
3075
|
+
var _editorPortalHostRef$, _getHotInstance2;
|
|
3076
|
+
(_editorPortalHostRef$ = editorPortalHostRef.current) === null || _editorPortalHostRef$ === void 0 || _editorPortalHostRef$.remove();
|
|
2394
3077
|
clearCache();
|
|
2395
3078
|
(_getHotInstance2 = getHotInstance()) === null || _getHotInstance2 === void 0 || _getHotInstance2.destroy();
|
|
2396
3079
|
};
|
|
@@ -2439,11 +3122,12 @@ var HotTableInner = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
2439
3122
|
return /*#__PURE__*/React.createElement(HotColumnContextProvider, {
|
|
2440
3123
|
columnIndex: columnIndex,
|
|
2441
3124
|
getOwnerDocument: getOwnerDocument,
|
|
3125
|
+
getEditorPortalHost: getEditorPortalHost,
|
|
2442
3126
|
key: columnIndex
|
|
2443
3127
|
}, childNode);
|
|
2444
3128
|
});
|
|
2445
3129
|
var containerProps = getContainerAttributesProps(props);
|
|
2446
|
-
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor);
|
|
3130
|
+
var editorPortal = createEditorPortal(getOwnerDocument(), props.editor, getEditorPortalHost());
|
|
2447
3131
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
2448
3132
|
ref: hotElementRef
|
|
2449
3133
|
}, containerProps, {
|
|
@@ -2492,7 +3176,10 @@ var HotTable = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
2492
3176
|
var _props$id;
|
|
2493
3177
|
var children = _ref.children,
|
|
2494
3178
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
2495
|
-
|
|
3179
|
+
// `useId()` must run unconditionally on every render (never only when `id` is missing), or React
|
|
3180
|
+
// sees a different hook count between renders and throws "Rendered fewer hooks than expected".
|
|
3181
|
+
var generatedId = useId();
|
|
3182
|
+
var componentId = (_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : generatedId;
|
|
2496
3183
|
return /*#__PURE__*/React.createElement(HotTableContextProvider, null, /*#__PURE__*/React.createElement(HotTableInner, _extends({
|
|
2497
3184
|
id: componentId
|
|
2498
3185
|
}, props, {
|