@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/es/vue-handsontable.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, markRaw, openBlock, createElementBlock, createCommentVNode, renderSlot } from 'vue';
|
|
1
|
+
import { toRaw, defineComponent, markRaw, openBlock, createElementBlock, createCommentVNode, renderSlot } from 'vue';
|
|
2
2
|
import Handsontable from 'handsontable/base';
|
|
3
3
|
|
|
4
4
|
function _arrayLikeToArray(r, a) {
|
|
@@ -104,6 +104,29 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
104
104
|
|
|
105
105
|
var unassignedPropSymbol = Symbol('unassigned');
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The shape `defineComponent()` reads the prop types from, with one entry per option of `Settings`. `type`
|
|
109
|
+
* exists only for the type checker: the runtime schema built by `propFactory()` carries none, so Vue
|
|
110
|
+
* neither validates nor casts a prop.
|
|
111
|
+
*
|
|
112
|
+
* `RemoveIndexSignature` drops the index signature of `Settings`. Left in, it becomes an index signature of
|
|
113
|
+
* the props, and Vue types every prop as `any` again. The mapping also drops `afterChangesObserved`: the
|
|
114
|
+
* settings types list that hook, but core neither registers nor fires it, so a prop for it could never work.
|
|
115
|
+
* `SettingsProp` is what the `settings` prop takes.
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `HotColumn` takes column settings, not grid settings: its `data` is a property name or a getter, where the
|
|
120
|
+
* grid's `data` is an array of rows. Hooks run from the grid-level settings only, and core reads `getValue`
|
|
121
|
+
* from the table meta only, so neither is a prop of a column. The `settings` prop also takes a grid settings
|
|
122
|
+
* object, as it did when every prop was `any`: such an object has no `data` that would clash.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* `HotTable` takes the settings `updateSettings()` takes: a hook prop may be `null`, which removes the
|
|
127
|
+
* callback the earlier props passed for it.
|
|
128
|
+
*/
|
|
129
|
+
|
|
107
130
|
/**
|
|
108
131
|
* Message for the warning thrown if the Handsontable instance has been destroyed.
|
|
109
132
|
*/
|
|
@@ -126,6 +149,13 @@ function hasOwnProperty(object, key) {
|
|
|
126
149
|
* @param {string} source Source for the factory (either 'HotTable' or 'HotColumn').
|
|
127
150
|
* @returns {object}
|
|
128
151
|
*/
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Implementation of the overloads above.
|
|
155
|
+
*
|
|
156
|
+
* @param {string} source Source for the factory (either 'HotTable' or 'HotColumn').
|
|
157
|
+
* @returns {object}
|
|
158
|
+
*/
|
|
129
159
|
function propFactory(source) {
|
|
130
160
|
var registeredHooks = Handsontable.hooks.getRegistered();
|
|
131
161
|
var propSchema = {};
|
|
@@ -142,18 +172,43 @@ function propFactory(source) {
|
|
|
142
172
|
"default": unassignedPropSymbol
|
|
143
173
|
};
|
|
144
174
|
}
|
|
175
|
+
|
|
176
|
+
// Documented options that have no entry in `DefaultSettings`, so the loops above never reach them.
|
|
177
|
+
propSchema.handsontable = {
|
|
178
|
+
"default": unassignedPropSymbol
|
|
179
|
+
};
|
|
145
180
|
propSchema.settings = {
|
|
146
181
|
"default": unassignedPropSymbol
|
|
147
182
|
};
|
|
148
183
|
if (source === 'HotTable') {
|
|
184
|
+
// Core reads `getValue` from the table meta only, so a column has no use for it.
|
|
185
|
+
propSchema.getValue = {
|
|
186
|
+
"default": unassignedPropSymbol
|
|
187
|
+
};
|
|
149
188
|
propSchema.id = {
|
|
150
|
-
type: String
|
|
151
|
-
"default": "hot-".concat(Math.random().toString(36).substring(5))
|
|
189
|
+
type: String
|
|
152
190
|
};
|
|
153
191
|
}
|
|
192
|
+
|
|
193
|
+
// The schema is filled at runtime from `DefaultSettings`, the registered hooks, and the options named
|
|
194
|
+
// above, which is why it is built loosely and typed here, from `SettingsUpdate` and `ColumnSettings`, for the template type checker.
|
|
154
195
|
return propSchema;
|
|
155
196
|
}
|
|
156
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Generate a random id for the `HotTable` container. It has to be created on the client only: an id
|
|
200
|
+
* generated on the server never matches the one the browser generates while hydrating.
|
|
201
|
+
*
|
|
202
|
+
* @returns {string} The container id.
|
|
203
|
+
*/
|
|
204
|
+
function generateContainerId() {
|
|
205
|
+
var buffer = new Uint16Array(3);
|
|
206
|
+
globalThis.crypto.getRandomValues(buffer);
|
|
207
|
+
return "hot-".concat(Array.from(buffer, function (value) {
|
|
208
|
+
return value.toString(16).padStart(4, '0');
|
|
209
|
+
}).join(''));
|
|
210
|
+
}
|
|
211
|
+
|
|
157
212
|
/**
|
|
158
213
|
* Filter out all of the unassigned props, and return only the one passed to the component.
|
|
159
214
|
*
|
|
@@ -181,36 +236,329 @@ function filterPassedProps(props) {
|
|
|
181
236
|
return filteredProps;
|
|
182
237
|
}
|
|
183
238
|
|
|
239
|
+
/**
|
|
240
|
+
* List the hooks the props pass a callback for, directly or through the `settings` prop. A key counts as
|
|
241
|
+
* a hook by the rule core's `updateSettings()` uses in `core.ts`: a registered or a deprecated hook name.
|
|
242
|
+
* Only a function or an array of them counts as a callback: core ignores any other value, so a hook prop
|
|
243
|
+
* that holds `false` (`:afterChange="on && logChange"`) is treated as removed.
|
|
244
|
+
*
|
|
245
|
+
* @param {HotTableProps} props The props passed to the component.
|
|
246
|
+
* @returns {string[]} The hook names.
|
|
247
|
+
*/
|
|
248
|
+
function getPassedHookKeys(props) {
|
|
249
|
+
var passedProps = filterPassedProps(props);
|
|
250
|
+
return Object.keys(passedProps).filter(function (key) {
|
|
251
|
+
return (typeof passedProps[key] === 'function' || Array.isArray(passedProps[key])) && (Handsontable.hooks.isRegistered(key) || Handsontable.hooks.isDeprecated(key));
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* What the wrapper last knew about a setting: the prop value it synced, a copy of its content, and the value the
|
|
257
|
+
* grid held right after. The copy is needed because core edits an array it was given in place (`alter()` splices
|
|
258
|
+
* `colHeaders`), so the prop itself no longer shows what was synced.
|
|
259
|
+
*/
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Check if a value is a plain object, one made by an object literal or with no prototype. A class instance is not.
|
|
263
|
+
*
|
|
264
|
+
* @param {unknown} value The value to check.
|
|
265
|
+
* @returns {boolean}
|
|
266
|
+
*/
|
|
267
|
+
function isLiteralObject(value) {
|
|
268
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
var prototype = Object.getPrototypeOf(value);
|
|
272
|
+
return prototype === Object.prototype || prototype === null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Copy the plain objects and arrays of a settings value, and keep every other value (functions, class instances)
|
|
277
|
+
* by reference. The copy is what the next change is compared with, so a value the app edits in place reads as
|
|
278
|
+
* changed. Reactive proxies are unwrapped, and a value with a cycle is copied with the same cycle.
|
|
279
|
+
*
|
|
280
|
+
* @param {unknown} value The value to copy.
|
|
281
|
+
* @param {WeakMap<object, unknown>} [copies] The copies made so far, by original.
|
|
282
|
+
* @returns {unknown} The copy.
|
|
283
|
+
*/
|
|
284
|
+
function copySettingsValue(value) {
|
|
285
|
+
var copies = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new WeakMap();
|
|
286
|
+
var raw = toRaw(value);
|
|
287
|
+
if (!Array.isArray(raw) && !isLiteralObject(raw)) {
|
|
288
|
+
return raw;
|
|
289
|
+
}
|
|
290
|
+
if (copies.has(raw)) {
|
|
291
|
+
return copies.get(raw);
|
|
292
|
+
}
|
|
293
|
+
if (Array.isArray(raw)) {
|
|
294
|
+
var arrayCopy = [];
|
|
295
|
+
copies.set(raw, arrayCopy);
|
|
296
|
+
raw.forEach(function (item) {
|
|
297
|
+
arrayCopy.push(copySettingsValue(item, copies));
|
|
298
|
+
});
|
|
299
|
+
return arrayCopy;
|
|
300
|
+
}
|
|
301
|
+
var objectCopy = {};
|
|
302
|
+
copies.set(raw, objectCopy);
|
|
303
|
+
Object.keys(raw).forEach(function (key) {
|
|
304
|
+
objectCopy[key] = copySettingsValue(raw[key], copies);
|
|
305
|
+
});
|
|
306
|
+
return objectCopy;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Compare a copy made by `copySettingsValue()` with a value: plain objects and arrays by content, a `RegExp` by
|
|
311
|
+
* its source and flags, anything else by reference. A pair already being compared higher up reads as equal,
|
|
312
|
+
* so a value with a cycle ends.
|
|
313
|
+
*
|
|
314
|
+
* @param {unknown} copied The copy.
|
|
315
|
+
* @param {unknown} value The value to compare it with.
|
|
316
|
+
* @param {WeakMap<object, WeakSet<object>>} [visited] The object pairs on the current comparison path.
|
|
317
|
+
* @returns {boolean} `true` if they hold the same content.
|
|
318
|
+
*/
|
|
319
|
+
function isSameAsCopy(copied, value) {
|
|
320
|
+
var visited = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new WeakMap();
|
|
321
|
+
var raw = toRaw(value);
|
|
322
|
+
if (copied === raw) {
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
if (copied instanceof RegExp || raw instanceof RegExp) {
|
|
326
|
+
return copied instanceof RegExp && raw instanceof RegExp && copied.source === raw.source && copied.flags === raw.flags;
|
|
327
|
+
}
|
|
328
|
+
var bothArrays = Array.isArray(copied) && Array.isArray(raw);
|
|
329
|
+
if (!bothArrays && !(isLiteralObject(copied) && isLiteralObject(raw))) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
var copiedObject = copied;
|
|
333
|
+
var rawObject = raw;
|
|
334
|
+
var comparedWith = visited.get(copiedObject);
|
|
335
|
+
if (comparedWith !== null && comparedWith !== void 0 && comparedWith.has(rawObject)) {
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
if (comparedWith) {
|
|
339
|
+
comparedWith.add(rawObject);
|
|
340
|
+
} else {
|
|
341
|
+
visited.set(copiedObject, new WeakSet([rawObject]));
|
|
342
|
+
}
|
|
343
|
+
var keys = Object.keys(copiedObject);
|
|
344
|
+
return keys.length === Object.keys(rawObject).length && keys.every(function (key) {
|
|
345
|
+
return hasOwnProperty(rawObject, key) && isSameAsCopy(copiedObject[key], rawObject[key], visited);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The settings by name, as `SettingBaseline`s. `HotTable` keeps one per instance.
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Settings the baseline rule leaves alone. The sizes are re-sent whenever they differ from the grid's value,
|
|
355
|
+
* because the user can change them by dragging and the prop re-declares them (the React wrapper does the
|
|
356
|
+
* same). `data` has its own path in `HotTable`, and a baseline would keep the previous array alive.
|
|
357
|
+
*/
|
|
358
|
+
var BASELINE_EXEMPT_KEYS = ['data', 'colWidths', 'rowHeights', 'minRowHeights', 'themeName'];
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Settings whose baseline holds the reference only, with no copy of the content. `sheetsBar` carries every sheet's
|
|
362
|
+
* `data`, which a copy on each reactive change would walk again (`isEqualSetting()` avoids the same walk).
|
|
363
|
+
*/
|
|
364
|
+
var REFERENCE_ONLY_KEYS = ['sheetsBar'];
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Check if the app replaced the value of a setting through the instance (`hot.updateSettings()`) since the
|
|
368
|
+
* wrapper last synced the prop, while the prop itself stayed the same. Such a prop is not sent again: it did
|
|
369
|
+
* not change, and sending it would take back what the app set.
|
|
370
|
+
*
|
|
371
|
+
* @param {string} key The setting name.
|
|
372
|
+
* @param {unknown} propValue The value passed through the props.
|
|
373
|
+
* @param {Handsontable.GridSettings} currentSettings The grid's current settings.
|
|
374
|
+
* @param {SettingBaselines} [baselines] What the wrapper last synced.
|
|
375
|
+
* @returns {boolean} `true` if the app overrode the setting.
|
|
376
|
+
*/
|
|
377
|
+
function isOverriddenByApp(key, propValue, currentSettings, baselines) {
|
|
378
|
+
var baseline = baselines === null || baselines === void 0 ? void 0 : baselines[key];
|
|
379
|
+
|
|
380
|
+
// The cheap check goes first: the content compare runs only for a setting the app replaced.
|
|
381
|
+
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));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Record the props the wrapper has just synced with the grid, for the next change to compare with. A setting the
|
|
386
|
+
* app overrode (`overriddenKeys`) keeps its previous baseline, so the override outlives the next changes and
|
|
387
|
+
* is given up only when the prop itself changes.
|
|
388
|
+
*
|
|
389
|
+
* @param {SettingBaselines} baselines What the wrapper last synced. It is updated in place.
|
|
390
|
+
* @param {HotTableProps} props The props passed to the component.
|
|
391
|
+
* @param {Handsontable.GridSettings} currentSettings The grid's current settings.
|
|
392
|
+
* @param {string[]} [overriddenKeys] The settings `prepareSettings()` left out because the app overrode them.
|
|
393
|
+
*/
|
|
394
|
+
function recordSettingBaselines(baselines, props, currentSettings) {
|
|
395
|
+
var overriddenKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
396
|
+
var passedProps = filterPassedProps(props);
|
|
397
|
+
Object.keys(baselines).forEach(function (key) {
|
|
398
|
+
if (!hasOwnProperty(passedProps, key)) {
|
|
399
|
+
delete baselines[key];
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
Object.keys(passedProps).forEach(function (key) {
|
|
403
|
+
if (!overriddenKeys.includes(key) && !BASELINE_EXEMPT_KEYS.includes(key)) {
|
|
404
|
+
baselines[key] = {
|
|
405
|
+
prop: toRaw(passedProps[key]),
|
|
406
|
+
copy: REFERENCE_ONLY_KEYS.includes(key) ? undefined : copySettingsValue(passedProps[key]),
|
|
407
|
+
live: currentSettings[key]
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
184
413
|
/**
|
|
185
414
|
* Prepare the settings object to be used as the settings for Handsontable, based on the props provided to the component.
|
|
186
415
|
*
|
|
416
|
+
* A hook listed in `previousHookKeys` that the props no longer pass a callback for (the prop is removed or
|
|
417
|
+
* `undefined`) is sent as `null`, which removes the callback the props registered.
|
|
418
|
+
*
|
|
419
|
+
* A prop that is the same value the wrapper last synced (`baselines`) is left out when the grid's value for it
|
|
420
|
+
* was replaced since, through `hot.updateSettings()`: the app's value stays until the prop changes.
|
|
421
|
+
*
|
|
187
422
|
* @param {HotTableProps} props The props passed to the component.
|
|
188
423
|
* @param {Handsontable.GridSettings} currentSettings The current Handsontable settings.
|
|
424
|
+
* @param {string[]} previousHookKeys The hooks the previous props passed a callback for.
|
|
425
|
+
* @param {SettingBaselines} [baselines] What the wrapper last synced.
|
|
426
|
+
* @param {string[]} [overriddenKeys] Receives the names of the props left out because the app overrode them.
|
|
189
427
|
* @returns {Handsontable.GridSettings} An object containing the properties, ready to be used within Handsontable.
|
|
190
428
|
*/
|
|
191
429
|
function prepareSettings(props, currentSettings) {
|
|
430
|
+
var previousHookKeys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
431
|
+
var baselines = arguments.length > 3 ? arguments[3] : undefined;
|
|
432
|
+
var overriddenKeys = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
192
433
|
var assignedProps = filterPassedProps(props);
|
|
193
434
|
var hotSettingsInProps = props.settings ? props.settings : assignedProps;
|
|
194
435
|
var additionalHotSettingsInProps = props.settings ? assignedProps : null;
|
|
195
436
|
var initOnlySettingKeys = (currentSettings === null || currentSettings === void 0 ? void 0 : currentSettings._initOnlySettings) || [];
|
|
196
437
|
var newSettings = {};
|
|
438
|
+
var isOverridden = function isOverridden(key, value) {
|
|
439
|
+
// A direct prop wins over the same key in the `settings` prop, and the baseline holds the winner.
|
|
440
|
+
var effectiveValue = hasOwnProperty(assignedProps, key) ? assignedProps[key] : value;
|
|
441
|
+
var overridden = isOverriddenByApp(key, effectiveValue, currentSettings, baselines);
|
|
442
|
+
if (overridden && !overriddenKeys.includes(key)) {
|
|
443
|
+
overriddenKeys.push(key);
|
|
444
|
+
}
|
|
445
|
+
return overridden;
|
|
446
|
+
};
|
|
197
447
|
|
|
198
448
|
// eslint-disable-next-line no-restricted-syntax
|
|
199
449
|
for (var key in hotSettingsInProps) {
|
|
200
|
-
if (hasOwnProperty(hotSettingsInProps, key) && hotSettingsInProps[key] !==
|
|
450
|
+
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)) {
|
|
201
451
|
newSettings[key] = hotSettingsInProps[key];
|
|
202
452
|
}
|
|
203
453
|
}
|
|
204
454
|
|
|
205
455
|
// eslint-disable-next-line no-restricted-syntax
|
|
206
456
|
for (var _key in additionalHotSettingsInProps) {
|
|
207
|
-
if (hasOwnProperty(additionalHotSettingsInProps, _key) && _key !== 'id' && _key !== 'settings' && additionalHotSettingsInProps[_key] !==
|
|
457
|
+
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)) {
|
|
208
458
|
newSettings[_key] = additionalHotSettingsInProps[_key];
|
|
209
459
|
}
|
|
210
460
|
}
|
|
461
|
+
if (previousHookKeys.length > 0) {
|
|
462
|
+
var passedHookKeys = getPassedHookKeys(props);
|
|
463
|
+
previousHookKeys.forEach(function (key) {
|
|
464
|
+
if (!passedHookKeys.includes(key)) {
|
|
465
|
+
newSettings[key] = null;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
211
469
|
return newSettings;
|
|
212
470
|
}
|
|
213
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Compare the grid's current value of a setting with the value passed through the props.
|
|
474
|
+
*
|
|
475
|
+
* `sheetsBar` is compared key by key: a template writes it as an object literal
|
|
476
|
+
* (`:sheetsBar="{ sheets }"`), which is a new object on every render, while the sheets it holds keep
|
|
477
|
+
* every sheet's data, which must not be serialized on each change. The `sheets` array is compared by
|
|
478
|
+
* reference, and an option given as an object literal (`animation: { switch: false }`) by the
|
|
479
|
+
* references of its own keys. A new `sheets` array or a changed option in a new `sheetsBar` object is
|
|
480
|
+
* therefore sent, even when it differs only by a function. A change made inside the same `sheetsBar`
|
|
481
|
+
* object or the same `sheets` array is not sent, and neither are the plugin's own writes into that
|
|
482
|
+
* array. `themeName` is compared with the grid's `theme`, because core moves the name there and
|
|
483
|
+
* `getSettings().themeName` stays `undefined`. Every other setting is compared with `simpleEqual()`.
|
|
484
|
+
*
|
|
485
|
+
* @param {string} key The setting name.
|
|
486
|
+
* @param {unknown} currentValue The grid's current value.
|
|
487
|
+
* @param {unknown} newValue The value passed through the props.
|
|
488
|
+
* @param {Handsontable.GridSettings} currentSettings The grid's current settings.
|
|
489
|
+
* @returns {boolean} `true` if the value does not need to be sent.
|
|
490
|
+
*/
|
|
491
|
+
function isEqualSetting(key, currentValue, newValue, currentSettings) {
|
|
492
|
+
if (key === 'sheetsBar') {
|
|
493
|
+
return haveEqualOwnKeys(currentValue, newValue, function (propName, valueA, valueB) {
|
|
494
|
+
return propName === 'sheets' ? isSameReference(valueA, valueB) : isShallowEqualByReference(valueA, valueB);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (key === 'themeName' && currentValue === undefined) {
|
|
498
|
+
return typeof newValue === 'string' && currentSettings.theme === newValue;
|
|
499
|
+
}
|
|
500
|
+
return simpleEqual(currentValue, newValue);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Compare two values by reference, and two plain objects by the references of their own keys.
|
|
505
|
+
*
|
|
506
|
+
* @param {unknown} valueA First value to compare.
|
|
507
|
+
* @param {unknown} valueB Second value to compare.
|
|
508
|
+
* @returns {boolean} `true` if they're the same, `false` otherwise.
|
|
509
|
+
*/
|
|
510
|
+
function isShallowEqualByReference(valueA, valueB) {
|
|
511
|
+
return haveEqualOwnKeys(valueA, valueB, function (propName, keyValueA, keyValueB) {
|
|
512
|
+
return isSameReference(keyValueA, keyValueB);
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Compare two values by reference, or, when both are plain objects, compare their own keys with the
|
|
518
|
+
* given function. Reactive proxies are compared by their raw objects.
|
|
519
|
+
*
|
|
520
|
+
* @param {unknown} valueA First value to compare.
|
|
521
|
+
* @param {unknown} valueB Second value to compare.
|
|
522
|
+
* @param {Function} isEqualValue Compares the values both objects hold under one key.
|
|
523
|
+
* @returns {boolean} `true` if they're the same, `false` otherwise.
|
|
524
|
+
*/
|
|
525
|
+
function haveEqualOwnKeys(valueA, valueB, isEqualValue) {
|
|
526
|
+
var rawA = toRaw(valueA);
|
|
527
|
+
var rawB = toRaw(valueB);
|
|
528
|
+
if (rawA === rawB) {
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
if (!isPlainObject(rawA) || !isPlainObject(rawB)) {
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
var keysA = Object.keys(rawA);
|
|
535
|
+
var keysB = Object.keys(rawB);
|
|
536
|
+
return keysA.length === keysB.length && keysA.every(function (propName) {
|
|
537
|
+
return hasOwnProperty(rawB, propName) && isEqualValue(propName, rawA[propName], rawB[propName]);
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Compare two values by reference, with reactive proxies compared by their raw objects.
|
|
543
|
+
*
|
|
544
|
+
* @param {unknown} valueA First value to compare.
|
|
545
|
+
* @param {unknown} valueB Second value to compare.
|
|
546
|
+
* @returns {boolean} `true` if they're the same, `false` otherwise.
|
|
547
|
+
*/
|
|
548
|
+
function isSameReference(valueA, valueB) {
|
|
549
|
+
return toRaw(valueA) === toRaw(valueB);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Check if a value is a plain object.
|
|
554
|
+
*
|
|
555
|
+
* @param {unknown} value The value to check.
|
|
556
|
+
* @returns {boolean}
|
|
557
|
+
*/
|
|
558
|
+
function isPlainObject(value) {
|
|
559
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
560
|
+
}
|
|
561
|
+
|
|
214
562
|
/**
|
|
215
563
|
* Compare two objects using `JSON.stringify`.
|
|
216
564
|
* *Note: * As it's using the stringify function to compare objects, the property order in both objects is
|
|
@@ -267,7 +615,7 @@ function simpleEqual(objectA, objectB) {
|
|
|
267
615
|
}
|
|
268
616
|
}
|
|
269
617
|
|
|
270
|
-
var version="
|
|
618
|
+
var version="19.0.0-rc2";
|
|
271
619
|
|
|
272
620
|
var HotTable = defineComponent({
|
|
273
621
|
name: 'HotTable',
|
|
@@ -279,13 +627,33 @@ var HotTable = defineComponent({
|
|
|
279
627
|
};
|
|
280
628
|
},
|
|
281
629
|
watch: {
|
|
630
|
+
// Vue removes the attribute when `id` is cleared, so put the generated one back after the patch.
|
|
631
|
+
id: {
|
|
632
|
+
handler: function handler(id) {
|
|
633
|
+
if (!id) {
|
|
634
|
+
this.$el.id = this.getGeneratedId();
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
flush: 'post'
|
|
638
|
+
},
|
|
282
639
|
$props: {
|
|
283
640
|
handler: function handler(props) {
|
|
284
|
-
var
|
|
285
|
-
|
|
641
|
+
var overriddenKeys = [];
|
|
642
|
+
var settings = prepareSettings(props, this.hotInstance ? this.hotInstance.getSettings() : undefined, this.miscCache.hookKeys, this.miscCache.baselines, overriddenKeys);
|
|
643
|
+
if (!this.hotInstance || settings === undefined) {
|
|
286
644
|
return;
|
|
287
645
|
}
|
|
288
|
-
|
|
646
|
+
this.miscCache.hookKeys = getPassedHookKeys(props);
|
|
647
|
+
var hasData = settings.data !== undefined;
|
|
648
|
+
var incomingData = hasData ? toRaw(settings.data) : undefined;
|
|
649
|
+
var isNewData = hasData && incomingData !== this.miscCache.lastData.value;
|
|
650
|
+
|
|
651
|
+
// A new array replaces the grid's data: `updateSettings()` runs core's `updateData()`, which fits the
|
|
652
|
+
// index mappers to the new length and keeps their state, unless the same payload changes the column layout.
|
|
653
|
+
if (hasData && !isNewData && incomingData === null) {
|
|
654
|
+
// The prop was already cleared: sending `null` again would reset the grid on every later change.
|
|
655
|
+
delete settings.data;
|
|
656
|
+
} else if (settings.data && !isNewData) {
|
|
289
657
|
if (this.hotInstance.isColumnModificationAllowed() || !this.hotInstance.isColumnModificationAllowed() && this.hotInstance.countSourceCols() === this.miscCache.currentSourceColumns) {
|
|
290
658
|
// If the dataset dimensions change, update the index mappers.
|
|
291
659
|
this.matchHotMappersSize();
|
|
@@ -295,6 +663,12 @@ var HotTable = defineComponent({
|
|
|
295
663
|
}
|
|
296
664
|
}
|
|
297
665
|
|
|
666
|
+
// Recorded before the update: core holds the array as soon as `updateSettings()` starts, so a hook that
|
|
667
|
+
// throws must not leave the old one here, or every later in-place edit would reload the data.
|
|
668
|
+
if (hasData) {
|
|
669
|
+
this.miscCache.lastData.value = incomingData;
|
|
670
|
+
}
|
|
671
|
+
|
|
298
672
|
// If there are another options changed, update the HOT settings, render the table otherwise.
|
|
299
673
|
if (Object.keys(settings).length) {
|
|
300
674
|
this.hotInstance.updateSettings(settings);
|
|
@@ -302,6 +676,7 @@ var HotTable = defineComponent({
|
|
|
302
676
|
this.hotInstance.render();
|
|
303
677
|
}
|
|
304
678
|
this.miscCache.currentSourceColumns = this.hotInstance.countSourceCols();
|
|
679
|
+
recordSettingBaselines(this.miscCache.baselines, props, this.hotInstance.getSettings(), overriddenKeys);
|
|
305
680
|
},
|
|
306
681
|
deep: true,
|
|
307
682
|
immediate: true
|
|
@@ -313,7 +688,16 @@ var HotTable = defineComponent({
|
|
|
313
688
|
__hotInstance: null,
|
|
314
689
|
/* eslint-enable vue/no-reserved-keys */
|
|
315
690
|
miscCache: {
|
|
316
|
-
currentSourceColumns: null
|
|
691
|
+
currentSourceColumns: null,
|
|
692
|
+
generatedId: '',
|
|
693
|
+
hookKeys: [],
|
|
694
|
+
// Holds the grid's own values, so it must not be wrapped in a proxy: the compare is by identity.
|
|
695
|
+
baselines: markRaw({}),
|
|
696
|
+
// The `data` array the grid was last given by the props, compared by identity to tell a new array
|
|
697
|
+
// from an in-place edit. Wrapped in a raw holder so Vue does not proxy the app's array.
|
|
698
|
+
lastData: markRaw({
|
|
699
|
+
value: undefined
|
|
700
|
+
})
|
|
317
701
|
},
|
|
318
702
|
columnSettings: null,
|
|
319
703
|
columnsCache: new Map(),
|
|
@@ -334,6 +718,17 @@ var HotTable = defineComponent({
|
|
|
334
718
|
};
|
|
335
719
|
},
|
|
336
720
|
methods: {
|
|
721
|
+
/**
|
|
722
|
+
* Get the id used when the `id` prop is not passed. It is created once per instance.
|
|
723
|
+
*
|
|
724
|
+
* @returns {string} The generated container id.
|
|
725
|
+
*/
|
|
726
|
+
getGeneratedId: function getGeneratedId() {
|
|
727
|
+
if (!this.miscCache.generatedId) {
|
|
728
|
+
this.miscCache.generatedId = generateContainerId();
|
|
729
|
+
}
|
|
730
|
+
return this.miscCache.generatedId;
|
|
731
|
+
},
|
|
337
732
|
/**
|
|
338
733
|
* Initialize Handsontable.
|
|
339
734
|
*/
|
|
@@ -341,8 +736,13 @@ var HotTable = defineComponent({
|
|
|
341
736
|
var newSettings = prepareSettings(this.$props);
|
|
342
737
|
newSettings.columns = this.columnSettings ? this.columnSettings : newSettings.columns;
|
|
343
738
|
this.hotInstance = markRaw(new Handsontable.Core(this.$el, newSettings));
|
|
739
|
+
|
|
740
|
+
// Recorded before `init()`, so a value the app sets in `afterInit` counts as an override of the prop.
|
|
741
|
+
recordSettingBaselines(this.miscCache.baselines, this.$props, this.hotInstance.getSettings());
|
|
344
742
|
this.hotInstance.init();
|
|
345
743
|
this.miscCache.currentSourceColumns = this.hotInstance.countSourceCols();
|
|
744
|
+
this.miscCache.hookKeys = getPassedHookKeys(this.$props);
|
|
745
|
+
this.miscCache.lastData.value = toRaw(newSettings.data);
|
|
346
746
|
},
|
|
347
747
|
matchHotMappersSize: function matchHotMappersSize() {
|
|
348
748
|
var _this = this;
|
|
@@ -426,7 +826,7 @@ var HotTable = defineComponent({
|
|
|
426
826
|
columnSettings = _ref6[1];
|
|
427
827
|
return columnSettings;
|
|
428
828
|
});
|
|
429
|
-
return orderedColumns.length ? orderedColumns :
|
|
829
|
+
return orderedColumns.length ? orderedColumns : undefined;
|
|
430
830
|
},
|
|
431
831
|
/**
|
|
432
832
|
* Re-read the column settings declared by `hot-column` children and push them
|
|
@@ -460,12 +860,18 @@ var HotTable = defineComponent({
|
|
|
460
860
|
}
|
|
461
861
|
_this2.columnSettings = newColumnSettings || null;
|
|
462
862
|
_this2.hotInstance.updateSettings({
|
|
463
|
-
columns: newColumnSettings ||
|
|
863
|
+
columns: newColumnSettings || undefined
|
|
464
864
|
});
|
|
465
865
|
});
|
|
466
866
|
}
|
|
467
867
|
},
|
|
468
868
|
mounted: function mounted() {
|
|
869
|
+
// The auto-generated id is set here, on the client only, and not through a prop default or reactive
|
|
870
|
+
// data: an id created on the server never matches the browser's, which breaks hydration, and a
|
|
871
|
+
// reactive id would re-render every `HotTable` right after mounting.
|
|
872
|
+
if (!this.id) {
|
|
873
|
+
this.$el.id = this.getGeneratedId();
|
|
874
|
+
}
|
|
469
875
|
this.columnSettings = this.getColumnSettings();
|
|
470
876
|
this.hotInit();
|
|
471
877
|
},
|