@handsontable/vue3 18.1.2 → 19.0.0-rc2
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/HotColumn.vue.d.ts +3687 -0
- package/HotTable.vue.d.ts +9681 -0
- package/README.md +57 -38
- package/commonjs/vue-handsontable.js +417 -11
- package/dist/vue-handsontable.js +418 -12
- package/dist/vue-handsontable.js.map +1 -1
- package/dist/vue-handsontable.min.js +2 -2
- package/dist/vue-handsontable.min.js.map +1 -1
- package/es/vue-handsontable.mjs +418 -12
- package/helpers.d.ts +127 -0
- package/index.d.ts +4 -0
- package/package.json +18 -15
- package/types.d.ts +9 -0
package/dist/vue-handsontable.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER ARISING FROM
|
|
26
26
|
* USE OR INABILITY TO USE THIS SOFTWARE.
|
|
27
27
|
*
|
|
28
|
-
* Version:
|
|
28
|
+
* Version: 19.0.0-rc2 (built at Tue Nov 17 2026 11:13:14 GMT+0000 (Coordinated Universal Time))
|
|
29
29
|
*/
|
|
30
30
|
(function (global, factory) {
|
|
31
31
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('handsontable/base')) :
|
|
@@ -140,6 +140,29 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
140
140
|
|
|
141
141
|
var unassignedPropSymbol = Symbol('unassigned');
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* The shape `defineComponent()` reads the prop types from, with one entry per option of `Settings`. `type`
|
|
145
|
+
* exists only for the type checker: the runtime schema built by `propFactory()` carries none, so Vue
|
|
146
|
+
* neither validates nor casts a prop.
|
|
147
|
+
*
|
|
148
|
+
* `RemoveIndexSignature` drops the index signature of `Settings`. Left in, it becomes an index signature of
|
|
149
|
+
* the props, and Vue types every prop as `any` again. The mapping also drops `afterChangesObserved`: the
|
|
150
|
+
* settings types list that hook, but core neither registers nor fires it, so a prop for it could never work.
|
|
151
|
+
* `SettingsProp` is what the `settings` prop takes.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* `HotColumn` takes column settings, not grid settings: its `data` is a property name or a getter, where the
|
|
156
|
+
* grid's `data` is an array of rows. Hooks run from the grid-level settings only, and core reads `getValue`
|
|
157
|
+
* from the table meta only, so neither is a prop of a column. The `settings` prop also takes a grid settings
|
|
158
|
+
* object, as it did when every prop was `any`: such an object has no `data` that would clash.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* `HotTable` takes the settings `updateSettings()` takes: a hook prop may be `null`, which removes the
|
|
163
|
+
* callback the earlier props passed for it.
|
|
164
|
+
*/
|
|
165
|
+
|
|
143
166
|
/**
|
|
144
167
|
* Message for the warning thrown if the Handsontable instance has been destroyed.
|
|
145
168
|
*/
|
|
@@ -162,6 +185,13 @@ function hasOwnProperty(object, key) {
|
|
|
162
185
|
* @param {string} source Source for the factory (either 'HotTable' or 'HotColumn').
|
|
163
186
|
* @returns {object}
|
|
164
187
|
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Implementation of the overloads above.
|
|
191
|
+
*
|
|
192
|
+
* @param {string} source Source for the factory (either 'HotTable' or 'HotColumn').
|
|
193
|
+
* @returns {object}
|
|
194
|
+
*/
|
|
165
195
|
function propFactory(source) {
|
|
166
196
|
var registeredHooks = Handsontable__default["default"].hooks.getRegistered();
|
|
167
197
|
var propSchema = {};
|
|
@@ -178,18 +208,43 @@ function propFactory(source) {
|
|
|
178
208
|
"default": unassignedPropSymbol
|
|
179
209
|
};
|
|
180
210
|
}
|
|
211
|
+
|
|
212
|
+
// Documented options that have no entry in `DefaultSettings`, so the loops above never reach them.
|
|
213
|
+
propSchema.handsontable = {
|
|
214
|
+
"default": unassignedPropSymbol
|
|
215
|
+
};
|
|
181
216
|
propSchema.settings = {
|
|
182
217
|
"default": unassignedPropSymbol
|
|
183
218
|
};
|
|
184
219
|
if (source === 'HotTable') {
|
|
220
|
+
// Core reads `getValue` from the table meta only, so a column has no use for it.
|
|
221
|
+
propSchema.getValue = {
|
|
222
|
+
"default": unassignedPropSymbol
|
|
223
|
+
};
|
|
185
224
|
propSchema.id = {
|
|
186
|
-
type: String
|
|
187
|
-
"default": "hot-".concat(Math.random().toString(36).substring(5))
|
|
225
|
+
type: String
|
|
188
226
|
};
|
|
189
227
|
}
|
|
228
|
+
|
|
229
|
+
// The schema is filled at runtime from `DefaultSettings`, the registered hooks, and the options named
|
|
230
|
+
// above, which is why it is built loosely and typed here, from `SettingsUpdate` and `ColumnSettings`, for the template type checker.
|
|
190
231
|
return propSchema;
|
|
191
232
|
}
|
|
192
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Generate a random id for the `HotTable` container. It has to be created on the client only: an id
|
|
236
|
+
* generated on the server never matches the one the browser generates while hydrating.
|
|
237
|
+
*
|
|
238
|
+
* @returns {string} The container id.
|
|
239
|
+
*/
|
|
240
|
+
function generateContainerId() {
|
|
241
|
+
var buffer = new Uint16Array(3);
|
|
242
|
+
globalThis.crypto.getRandomValues(buffer);
|
|
243
|
+
return "hot-".concat(Array.from(buffer, function (value) {
|
|
244
|
+
return value.toString(16).padStart(4, '0');
|
|
245
|
+
}).join(''));
|
|
246
|
+
}
|
|
247
|
+
|
|
193
248
|
/**
|
|
194
249
|
* Filter out all of the unassigned props, and return only the one passed to the component.
|
|
195
250
|
*
|
|
@@ -217,36 +272,329 @@ function filterPassedProps(props) {
|
|
|
217
272
|
return filteredProps;
|
|
218
273
|
}
|
|
219
274
|
|
|
275
|
+
/**
|
|
276
|
+
* List the hooks the props pass a callback for, directly or through the `settings` prop. A key counts as
|
|
277
|
+
* a hook by the rule core's `updateSettings()` uses in `core.ts`: a registered or a deprecated hook name.
|
|
278
|
+
* Only a function or an array of them counts as a callback: core ignores any other value, so a hook prop
|
|
279
|
+
* that holds `false` (`:afterChange="on && logChange"`) is treated as removed.
|
|
280
|
+
*
|
|
281
|
+
* @param {HotTableProps} props The props passed to the component.
|
|
282
|
+
* @returns {string[]} The hook names.
|
|
283
|
+
*/
|
|
284
|
+
function getPassedHookKeys(props) {
|
|
285
|
+
var passedProps = filterPassedProps(props);
|
|
286
|
+
return Object.keys(passedProps).filter(function (key) {
|
|
287
|
+
return (typeof passedProps[key] === 'function' || Array.isArray(passedProps[key])) && (Handsontable__default["default"].hooks.isRegistered(key) || Handsontable__default["default"].hooks.isDeprecated(key));
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* What the wrapper last knew about a setting: the prop value it synced, a copy of its content, and the value the
|
|
293
|
+
* grid held right after. The copy is needed because core edits an array it was given in place (`alter()` splices
|
|
294
|
+
* `colHeaders`), so the prop itself no longer shows what was synced.
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Check if a value is a plain object, one made by an object literal or with no prototype. A class instance is not.
|
|
299
|
+
*
|
|
300
|
+
* @param {unknown} value The value to check.
|
|
301
|
+
* @returns {boolean}
|
|
302
|
+
*/
|
|
303
|
+
function isLiteralObject(value) {
|
|
304
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
var prototype = Object.getPrototypeOf(value);
|
|
308
|
+
return prototype === Object.prototype || prototype === null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Copy the plain objects and arrays of a settings value, and keep every other value (functions, class instances)
|
|
313
|
+
* by reference. The copy is what the next change is compared with, so a value the app edits in place reads as
|
|
314
|
+
* changed. Reactive proxies are unwrapped, and a value with a cycle is copied with the same cycle.
|
|
315
|
+
*
|
|
316
|
+
* @param {unknown} value The value to copy.
|
|
317
|
+
* @param {WeakMap<object, unknown>} [copies] The copies made so far, by original.
|
|
318
|
+
* @returns {unknown} The copy.
|
|
319
|
+
*/
|
|
320
|
+
function copySettingsValue(value) {
|
|
321
|
+
var copies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
|
|
322
|
+
var raw = vue.toRaw(value);
|
|
323
|
+
if (!Array.isArray(raw) && !isLiteralObject(raw)) {
|
|
324
|
+
return raw;
|
|
325
|
+
}
|
|
326
|
+
if (copies.has(raw)) {
|
|
327
|
+
return copies.get(raw);
|
|
328
|
+
}
|
|
329
|
+
if (Array.isArray(raw)) {
|
|
330
|
+
var arrayCopy = [];
|
|
331
|
+
copies.set(raw, arrayCopy);
|
|
332
|
+
raw.forEach(function (item) {
|
|
333
|
+
arrayCopy.push(copySettingsValue(item, copies));
|
|
334
|
+
});
|
|
335
|
+
return arrayCopy;
|
|
336
|
+
}
|
|
337
|
+
var objectCopy = {};
|
|
338
|
+
copies.set(raw, objectCopy);
|
|
339
|
+
Object.keys(raw).forEach(function (key) {
|
|
340
|
+
objectCopy[key] = copySettingsValue(raw[key], copies);
|
|
341
|
+
});
|
|
342
|
+
return objectCopy;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Compare a copy made by `copySettingsValue()` with a value: plain objects and arrays by content, a `RegExp` by
|
|
347
|
+
* its source and flags, anything else by reference. A pair already being compared higher up reads as equal,
|
|
348
|
+
* so a value with a cycle ends.
|
|
349
|
+
*
|
|
350
|
+
* @param {unknown} copied The copy.
|
|
351
|
+
* @param {unknown} value The value to compare it with.
|
|
352
|
+
* @param {WeakMap<object, WeakSet<object>>} [visited] The object pairs on the current comparison path.
|
|
353
|
+
* @returns {boolean} `true` if they hold the same content.
|
|
354
|
+
*/
|
|
355
|
+
function isSameAsCopy(copied, value) {
|
|
356
|
+
var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakMap();
|
|
357
|
+
var raw = vue.toRaw(value);
|
|
358
|
+
if (copied === raw) {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
if (copied instanceof RegExp || raw instanceof RegExp) {
|
|
362
|
+
return copied instanceof RegExp && raw instanceof RegExp && copied.source === raw.source && copied.flags === raw.flags;
|
|
363
|
+
}
|
|
364
|
+
var bothArrays = Array.isArray(copied) && Array.isArray(raw);
|
|
365
|
+
if (!bothArrays && !(isLiteralObject(copied) && isLiteralObject(raw))) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
var copiedObject = copied;
|
|
369
|
+
var rawObject = raw;
|
|
370
|
+
var comparedWith = visited.get(copiedObject);
|
|
371
|
+
if (comparedWith !== null && comparedWith !== void 0 && comparedWith.has(rawObject)) {
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
if (comparedWith) {
|
|
375
|
+
comparedWith.add(rawObject);
|
|
376
|
+
} else {
|
|
377
|
+
visited.set(copiedObject, new WeakSet([rawObject]));
|
|
378
|
+
}
|
|
379
|
+
var keys = Object.keys(copiedObject);
|
|
380
|
+
return keys.length === Object.keys(rawObject).length && keys.every(function (key) {
|
|
381
|
+
return hasOwnProperty(rawObject, key) && isSameAsCopy(copiedObject[key], rawObject[key], visited);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The settings by name, as `SettingBaseline`s. `HotTable` keeps one per instance.
|
|
387
|
+
*/
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Settings the baseline rule leaves alone. The sizes are re-sent whenever they differ from the grid's value,
|
|
391
|
+
* because the user can change them by dragging and the prop re-declares them (the React wrapper does the
|
|
392
|
+
* same). `data` has its own path in `HotTable`, and a baseline would keep the previous array alive.
|
|
393
|
+
*/
|
|
394
|
+
var BASELINE_EXEMPT_KEYS = ['data', 'colWidths', 'rowHeights', 'minRowHeights', 'themeName'];
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Settings whose baseline holds the reference only, with no copy of the content. `sheetsBar` carries every sheet's
|
|
398
|
+
* `data`, which a copy on each reactive change would walk again (`isEqualSetting()` avoids the same walk).
|
|
399
|
+
*/
|
|
400
|
+
var REFERENCE_ONLY_KEYS = ['sheetsBar'];
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Check if the app replaced the value of a setting through the instance (`hot.updateSettings()`) since the
|
|
404
|
+
* wrapper last synced the prop, while the prop itself stayed the same. Such a prop is not sent again: it did
|
|
405
|
+
* not change, and sending it would take back what the app set.
|
|
406
|
+
*
|
|
407
|
+
* @param {string} key The setting name.
|
|
408
|
+
* @param {unknown} propValue The value passed through the props.
|
|
409
|
+
* @param {Handsontable.GridSettings} currentSettings The grid's current settings.
|
|
410
|
+
* @param {SettingBaselines} [baselines] What the wrapper last synced.
|
|
411
|
+
* @returns {boolean} `true` if the app overrode the setting.
|
|
412
|
+
*/
|
|
413
|
+
function isOverriddenByApp(key, propValue, currentSettings, baselines) {
|
|
414
|
+
var baseline = baselines === null || baselines === void 0 ? void 0 : baselines[key];
|
|
415
|
+
|
|
416
|
+
// The cheap check goes first: the content compare runs only for a setting the app replaced.
|
|
417
|
+
return !!currentSettings && !!baseline && !BASELINE_EXEMPT_KEYS.includes(key) && !Object.is(currentSettings[key], baseline.live) && (isSameReference(baseline.prop, propValue) || !REFERENCE_ONLY_KEYS.includes(key) && isSameAsCopy(baseline.copy, propValue));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Record the props the wrapper has just synced with the grid, for the next change to compare with. A setting the
|
|
422
|
+
* app overrode (`overriddenKeys`) keeps its previous baseline, so the override outlives the next changes and
|
|
423
|
+
* is given up only when the prop itself changes.
|
|
424
|
+
*
|
|
425
|
+
* @param {SettingBaselines} baselines What the wrapper last synced. It is updated in place.
|
|
426
|
+
* @param {HotTableProps} props The props passed to the component.
|
|
427
|
+
* @param {Handsontable.GridSettings} currentSettings The grid's current settings.
|
|
428
|
+
* @param {string[]} [overriddenKeys] The settings `prepareSettings()` left out because the app overrode them.
|
|
429
|
+
*/
|
|
430
|
+
function recordSettingBaselines(baselines, props, currentSettings) {
|
|
431
|
+
var overriddenKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
432
|
+
var passedProps = filterPassedProps(props);
|
|
433
|
+
Object.keys(baselines).forEach(function (key) {
|
|
434
|
+
if (!hasOwnProperty(passedProps, key)) {
|
|
435
|
+
delete baselines[key];
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
Object.keys(passedProps).forEach(function (key) {
|
|
439
|
+
if (!overriddenKeys.includes(key) && !BASELINE_EXEMPT_KEYS.includes(key)) {
|
|
440
|
+
baselines[key] = {
|
|
441
|
+
prop: vue.toRaw(passedProps[key]),
|
|
442
|
+
copy: REFERENCE_ONLY_KEYS.includes(key) ? undefined : copySettingsValue(passedProps[key]),
|
|
443
|
+
live: currentSettings[key]
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
220
449
|
/**
|
|
221
450
|
* Prepare the settings object to be used as the settings for Handsontable, based on the props provided to the component.
|
|
222
451
|
*
|
|
452
|
+
* A hook listed in `previousHookKeys` that the props no longer pass a callback for (the prop is removed or
|
|
453
|
+
* `undefined`) is sent as `null`, which removes the callback the props registered.
|
|
454
|
+
*
|
|
455
|
+
* A prop that is the same value the wrapper last synced (`baselines`) is left out when the grid's value for it
|
|
456
|
+
* was replaced since, through `hot.updateSettings()`: the app's value stays until the prop changes.
|
|
457
|
+
*
|
|
223
458
|
* @param {HotTableProps} props The props passed to the component.
|
|
224
459
|
* @param {Handsontable.GridSettings} currentSettings The current Handsontable settings.
|
|
460
|
+
* @param {string[]} previousHookKeys The hooks the previous props passed a callback for.
|
|
461
|
+
* @param {SettingBaselines} [baselines] What the wrapper last synced.
|
|
462
|
+
* @param {string[]} [overriddenKeys] Receives the names of the props left out because the app overrode them.
|
|
225
463
|
* @returns {Handsontable.GridSettings} An object containing the properties, ready to be used within Handsontable.
|
|
226
464
|
*/
|
|
227
465
|
function prepareSettings(props, currentSettings) {
|
|
466
|
+
var previousHookKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
467
|
+
var baselines = arguments.length > 3 ? arguments[3] : undefined;
|
|
468
|
+
var overriddenKeys = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
228
469
|
var assignedProps = filterPassedProps(props);
|
|
229
470
|
var hotSettingsInProps = props.settings ? props.settings : assignedProps;
|
|
230
471
|
var additionalHotSettingsInProps = props.settings ? assignedProps : null;
|
|
231
472
|
var initOnlySettingKeys = (currentSettings === null || currentSettings === void 0 ? void 0 : currentSettings._initOnlySettings) || [];
|
|
232
473
|
var newSettings = {};
|
|
474
|
+
var isOverridden = function isOverridden(key, value) {
|
|
475
|
+
// A direct prop wins over the same key in the `settings` prop, and the baseline holds the winner.
|
|
476
|
+
var effectiveValue = hasOwnProperty(assignedProps, key) ? assignedProps[key] : value;
|
|
477
|
+
var overridden = isOverriddenByApp(key, effectiveValue, currentSettings, baselines);
|
|
478
|
+
if (overridden && !overriddenKeys.includes(key)) {
|
|
479
|
+
overriddenKeys.push(key);
|
|
480
|
+
}
|
|
481
|
+
return overridden;
|
|
482
|
+
};
|
|
233
483
|
|
|
234
484
|
// eslint-disable-next-line no-restricted-syntax
|
|
235
485
|
for (var key in hotSettingsInProps) {
|
|
236
|
-
if (hasOwnProperty(hotSettingsInProps, key) && hotSettingsInProps[key] !==
|
|
486
|
+
if (hasOwnProperty(hotSettingsInProps, key) && hotSettingsInProps[key] !== undefined && !initOnlySettingKeys.includes(key) && !isOverridden(key, hotSettingsInProps[key]) && (currentSettings && key !== 'data' ? !isEqualSetting(key, currentSettings[key], hotSettingsInProps[key], currentSettings) : true)) {
|
|
237
487
|
newSettings[key] = hotSettingsInProps[key];
|
|
238
488
|
}
|
|
239
489
|
}
|
|
240
490
|
|
|
241
491
|
// eslint-disable-next-line no-restricted-syntax
|
|
242
492
|
for (var _key in additionalHotSettingsInProps) {
|
|
243
|
-
if (hasOwnProperty(additionalHotSettingsInProps, _key) && _key !== 'id' && _key !== 'settings' && additionalHotSettingsInProps[_key] !==
|
|
493
|
+
if (hasOwnProperty(additionalHotSettingsInProps, _key) && _key !== 'id' && _key !== 'settings' && additionalHotSettingsInProps[_key] !== undefined && !initOnlySettingKeys.includes(_key) && !isOverridden(_key, additionalHotSettingsInProps[_key]) && (currentSettings && _key !== 'data' ? !isEqualSetting(_key, currentSettings[_key], additionalHotSettingsInProps[_key], currentSettings) : true)) {
|
|
244
494
|
newSettings[_key] = additionalHotSettingsInProps[_key];
|
|
245
495
|
}
|
|
246
496
|
}
|
|
497
|
+
if (previousHookKeys.length > 0) {
|
|
498
|
+
var passedHookKeys = getPassedHookKeys(props);
|
|
499
|
+
previousHookKeys.forEach(function (key) {
|
|
500
|
+
if (!passedHookKeys.includes(key)) {
|
|
501
|
+
newSettings[key] = null;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
247
505
|
return newSettings;
|
|
248
506
|
}
|
|
249
507
|
|
|
508
|
+
/**
|
|
509
|
+
* Compare the grid's current value of a setting with the value passed through the props.
|
|
510
|
+
*
|
|
511
|
+
* `sheetsBar` is compared key by key: a template writes it as an object literal
|
|
512
|
+
* (`:sheetsBar="{ sheets }"`), which is a new object on every render, while the sheets it holds keep
|
|
513
|
+
* every sheet's data, which must not be serialized on each change. The `sheets` array is compared by
|
|
514
|
+
* reference, and an option given as an object literal (`animation: { switch: false }`) by the
|
|
515
|
+
* references of its own keys. A new `sheets` array or a changed option in a new `sheetsBar` object is
|
|
516
|
+
* therefore sent, even when it differs only by a function. A change made inside the same `sheetsBar`
|
|
517
|
+
* object or the same `sheets` array is not sent, and neither are the plugin's own writes into that
|
|
518
|
+
* array. `themeName` is compared with the grid's `theme`, because core moves the name there and
|
|
519
|
+
* `getSettings().themeName` stays `undefined`. Every other setting is compared with `simpleEqual()`.
|
|
520
|
+
*
|
|
521
|
+
* @param {string} key The setting name.
|
|
522
|
+
* @param {unknown} currentValue The grid's current value.
|
|
523
|
+
* @param {unknown} newValue The value passed through the props.
|
|
524
|
+
* @param {Handsontable.GridSettings} currentSettings The grid's current settings.
|
|
525
|
+
* @returns {boolean} `true` if the value does not need to be sent.
|
|
526
|
+
*/
|
|
527
|
+
function isEqualSetting(key, currentValue, newValue, currentSettings) {
|
|
528
|
+
if (key === 'sheetsBar') {
|
|
529
|
+
return haveEqualOwnKeys(currentValue, newValue, function (propName, valueA, valueB) {
|
|
530
|
+
return propName === 'sheets' ? isSameReference(valueA, valueB) : isShallowEqualByReference(valueA, valueB);
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
if (key === 'themeName' && currentValue === undefined) {
|
|
534
|
+
return typeof newValue === 'string' && currentSettings.theme === newValue;
|
|
535
|
+
}
|
|
536
|
+
return simpleEqual(currentValue, newValue);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Compare two values by reference, and two plain objects by the references of their own keys.
|
|
541
|
+
*
|
|
542
|
+
* @param {unknown} valueA First value to compare.
|
|
543
|
+
* @param {unknown} valueB Second value to compare.
|
|
544
|
+
* @returns {boolean} `true` if they're the same, `false` otherwise.
|
|
545
|
+
*/
|
|
546
|
+
function isShallowEqualByReference(valueA, valueB) {
|
|
547
|
+
return haveEqualOwnKeys(valueA, valueB, function (propName, keyValueA, keyValueB) {
|
|
548
|
+
return isSameReference(keyValueA, keyValueB);
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Compare two values by reference, or, when both are plain objects, compare their own keys with the
|
|
554
|
+
* given function. Reactive proxies are compared by their raw objects.
|
|
555
|
+
*
|
|
556
|
+
* @param {unknown} valueA First value to compare.
|
|
557
|
+
* @param {unknown} valueB Second value to compare.
|
|
558
|
+
* @param {Function} isEqualValue Compares the values both objects hold under one key.
|
|
559
|
+
* @returns {boolean} `true` if they're the same, `false` otherwise.
|
|
560
|
+
*/
|
|
561
|
+
function haveEqualOwnKeys(valueA, valueB, isEqualValue) {
|
|
562
|
+
var rawA = vue.toRaw(valueA);
|
|
563
|
+
var rawB = vue.toRaw(valueB);
|
|
564
|
+
if (rawA === rawB) {
|
|
565
|
+
return true;
|
|
566
|
+
}
|
|
567
|
+
if (!isPlainObject(rawA) || !isPlainObject(rawB)) {
|
|
568
|
+
return false;
|
|
569
|
+
}
|
|
570
|
+
var keysA = Object.keys(rawA);
|
|
571
|
+
var keysB = Object.keys(rawB);
|
|
572
|
+
return keysA.length === keysB.length && keysA.every(function (propName) {
|
|
573
|
+
return hasOwnProperty(rawB, propName) && isEqualValue(propName, rawA[propName], rawB[propName]);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Compare two values by reference, with reactive proxies compared by their raw objects.
|
|
579
|
+
*
|
|
580
|
+
* @param {unknown} valueA First value to compare.
|
|
581
|
+
* @param {unknown} valueB Second value to compare.
|
|
582
|
+
* @returns {boolean} `true` if they're the same, `false` otherwise.
|
|
583
|
+
*/
|
|
584
|
+
function isSameReference(valueA, valueB) {
|
|
585
|
+
return vue.toRaw(valueA) === vue.toRaw(valueB);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Check if a value is a plain object.
|
|
590
|
+
*
|
|
591
|
+
* @param {unknown} value The value to check.
|
|
592
|
+
* @returns {boolean}
|
|
593
|
+
*/
|
|
594
|
+
function isPlainObject(value) {
|
|
595
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
596
|
+
}
|
|
597
|
+
|
|
250
598
|
/**
|
|
251
599
|
* Compare two objects using `JSON.stringify`.
|
|
252
600
|
* *Note: * As it's using the stringify function to compare objects, the property order in both objects is
|
|
@@ -303,7 +651,7 @@ function simpleEqual(objectA, objectB) {
|
|
|
303
651
|
}
|
|
304
652
|
}
|
|
305
653
|
|
|
306
|
-
var version="
|
|
654
|
+
var version="19.0.0-rc2";
|
|
307
655
|
|
|
308
656
|
var HotTable = vue.defineComponent({
|
|
309
657
|
name: 'HotTable',
|
|
@@ -315,13 +663,33 @@ var HotTable = vue.defineComponent({
|
|
|
315
663
|
};
|
|
316
664
|
},
|
|
317
665
|
watch: {
|
|
666
|
+
// Vue removes the attribute when `id` is cleared, so put the generated one back after the patch.
|
|
667
|
+
id: {
|
|
668
|
+
handler: function handler(id) {
|
|
669
|
+
if (!id) {
|
|
670
|
+
this.$el.id = this.getGeneratedId();
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
flush: 'post'
|
|
674
|
+
},
|
|
318
675
|
$props: {
|
|
319
676
|
handler: function handler(props) {
|
|
320
|
-
var
|
|
321
|
-
|
|
677
|
+
var overriddenKeys = [];
|
|
678
|
+
var settings = prepareSettings(props, this.hotInstance ? this.hotInstance.getSettings() : undefined, this.miscCache.hookKeys, this.miscCache.baselines, overriddenKeys);
|
|
679
|
+
if (!this.hotInstance || settings === undefined) {
|
|
322
680
|
return;
|
|
323
681
|
}
|
|
324
|
-
|
|
682
|
+
this.miscCache.hookKeys = getPassedHookKeys(props);
|
|
683
|
+
var hasData = settings.data !== undefined;
|
|
684
|
+
var incomingData = hasData ? vue.toRaw(settings.data) : undefined;
|
|
685
|
+
var isNewData = hasData && incomingData !== this.miscCache.lastData.value;
|
|
686
|
+
|
|
687
|
+
// A new array replaces the grid's data: `updateSettings()` runs core's `updateData()`, which fits the
|
|
688
|
+
// index mappers to the new length and keeps their state, unless the same payload changes the column layout.
|
|
689
|
+
if (hasData && !isNewData && incomingData === null) {
|
|
690
|
+
// The prop was already cleared: sending `null` again would reset the grid on every later change.
|
|
691
|
+
delete settings.data;
|
|
692
|
+
} else if (settings.data && !isNewData) {
|
|
325
693
|
if (this.hotInstance.isColumnModificationAllowed() || !this.hotInstance.isColumnModificationAllowed() && this.hotInstance.countSourceCols() === this.miscCache.currentSourceColumns) {
|
|
326
694
|
// If the dataset dimensions change, update the index mappers.
|
|
327
695
|
this.matchHotMappersSize();
|
|
@@ -331,6 +699,12 @@ var HotTable = vue.defineComponent({
|
|
|
331
699
|
}
|
|
332
700
|
}
|
|
333
701
|
|
|
702
|
+
// Recorded before the update: core holds the array as soon as `updateSettings()` starts, so a hook that
|
|
703
|
+
// throws must not leave the old one here, or every later in-place edit would reload the data.
|
|
704
|
+
if (hasData) {
|
|
705
|
+
this.miscCache.lastData.value = incomingData;
|
|
706
|
+
}
|
|
707
|
+
|
|
334
708
|
// If there are another options changed, update the HOT settings, render the table otherwise.
|
|
335
709
|
if (Object.keys(settings).length) {
|
|
336
710
|
this.hotInstance.updateSettings(settings);
|
|
@@ -338,6 +712,7 @@ var HotTable = vue.defineComponent({
|
|
|
338
712
|
this.hotInstance.render();
|
|
339
713
|
}
|
|
340
714
|
this.miscCache.currentSourceColumns = this.hotInstance.countSourceCols();
|
|
715
|
+
recordSettingBaselines(this.miscCache.baselines, props, this.hotInstance.getSettings(), overriddenKeys);
|
|
341
716
|
},
|
|
342
717
|
deep: true,
|
|
343
718
|
immediate: true
|
|
@@ -349,7 +724,16 @@ var HotTable = vue.defineComponent({
|
|
|
349
724
|
__hotInstance: null,
|
|
350
725
|
/* eslint-enable vue/no-reserved-keys */
|
|
351
726
|
miscCache: {
|
|
352
|
-
currentSourceColumns: null
|
|
727
|
+
currentSourceColumns: null,
|
|
728
|
+
generatedId: '',
|
|
729
|
+
hookKeys: [],
|
|
730
|
+
// Holds the grid's own values, so it must not be wrapped in a proxy: the compare is by identity.
|
|
731
|
+
baselines: vue.markRaw({}),
|
|
732
|
+
// The `data` array the grid was last given by the props, compared by identity to tell a new array
|
|
733
|
+
// from an in-place edit. Wrapped in a raw holder so Vue does not proxy the app's array.
|
|
734
|
+
lastData: vue.markRaw({
|
|
735
|
+
value: undefined
|
|
736
|
+
})
|
|
353
737
|
},
|
|
354
738
|
columnSettings: null,
|
|
355
739
|
columnsCache: new Map(),
|
|
@@ -370,6 +754,17 @@ var HotTable = vue.defineComponent({
|
|
|
370
754
|
};
|
|
371
755
|
},
|
|
372
756
|
methods: {
|
|
757
|
+
/**
|
|
758
|
+
* Get the id used when the `id` prop is not passed. It is created once per instance.
|
|
759
|
+
*
|
|
760
|
+
* @returns {string} The generated container id.
|
|
761
|
+
*/
|
|
762
|
+
getGeneratedId: function getGeneratedId() {
|
|
763
|
+
if (!this.miscCache.generatedId) {
|
|
764
|
+
this.miscCache.generatedId = generateContainerId();
|
|
765
|
+
}
|
|
766
|
+
return this.miscCache.generatedId;
|
|
767
|
+
},
|
|
373
768
|
/**
|
|
374
769
|
* Initialize Handsontable.
|
|
375
770
|
*/
|
|
@@ -377,8 +772,13 @@ var HotTable = vue.defineComponent({
|
|
|
377
772
|
var newSettings = prepareSettings(this.$props);
|
|
378
773
|
newSettings.columns = this.columnSettings ? this.columnSettings : newSettings.columns;
|
|
379
774
|
this.hotInstance = vue.markRaw(new Handsontable__default["default"].Core(this.$el, newSettings));
|
|
775
|
+
|
|
776
|
+
// Recorded before `init()`, so a value the app sets in `afterInit` counts as an override of the prop.
|
|
777
|
+
recordSettingBaselines(this.miscCache.baselines, this.$props, this.hotInstance.getSettings());
|
|
380
778
|
this.hotInstance.init();
|
|
381
779
|
this.miscCache.currentSourceColumns = this.hotInstance.countSourceCols();
|
|
780
|
+
this.miscCache.hookKeys = getPassedHookKeys(this.$props);
|
|
781
|
+
this.miscCache.lastData.value = vue.toRaw(newSettings.data);
|
|
382
782
|
},
|
|
383
783
|
matchHotMappersSize: function matchHotMappersSize() {
|
|
384
784
|
var _this = this;
|
|
@@ -462,7 +862,7 @@ var HotTable = vue.defineComponent({
|
|
|
462
862
|
columnSettings = _ref6[1];
|
|
463
863
|
return columnSettings;
|
|
464
864
|
});
|
|
465
|
-
return orderedColumns.length ? orderedColumns :
|
|
865
|
+
return orderedColumns.length ? orderedColumns : undefined;
|
|
466
866
|
},
|
|
467
867
|
/**
|
|
468
868
|
* Re-read the column settings declared by `hot-column` children and push them
|
|
@@ -496,12 +896,18 @@ var HotTable = vue.defineComponent({
|
|
|
496
896
|
}
|
|
497
897
|
_this2.columnSettings = newColumnSettings || null;
|
|
498
898
|
_this2.hotInstance.updateSettings({
|
|
499
|
-
columns: newColumnSettings ||
|
|
899
|
+
columns: newColumnSettings || undefined
|
|
500
900
|
});
|
|
501
901
|
});
|
|
502
902
|
}
|
|
503
903
|
},
|
|
504
904
|
mounted: function mounted() {
|
|
905
|
+
// The auto-generated id is set here, on the client only, and not through a prop default or reactive
|
|
906
|
+
// data: an id created on the server never matches the browser's, which breaks hydration, and a
|
|
907
|
+
// reactive id would re-render every `HotTable` right after mounting.
|
|
908
|
+
if (!this.id) {
|
|
909
|
+
this.$el.id = this.getGeneratedId();
|
|
910
|
+
}
|
|
505
911
|
this.columnSettings = this.getColumnSettings();
|
|
506
912
|
this.hotInit();
|
|
507
913
|
},
|