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