@lwc/engine-core 2.33.0 → 2.35.0
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/dist/engine-core.cjs.js +879 -523
- package/dist/engine-core.js +880 -525
- package/package.json +4 -4
- package/types/framework/base-lightning-element.d.ts +2 -0
- package/types/framework/main.d.ts +1 -0
- package/types/framework/reporting.d.ts +31 -0
- package/types/framework/template.d.ts +2 -1
- package/types/framework/vm.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/patches/detect-synthetic-cross-root-aria.d.ts +1 -0
- package/types/shared/logger.d.ts +1 -0
package/dist/engine-core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* proxy-compat-disable */
|
|
2
2
|
import { lwcRuntimeFlags } from '@lwc/features';
|
|
3
3
|
export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
|
|
4
|
-
import {
|
|
4
|
+
import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isFunction as isFunction$1, hasOwnProperty as hasOwnProperty$1, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, assert, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, isArray as isArray$1, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
|
|
5
5
|
import { applyAriaReflection } from '@lwc/aria-reflection';
|
|
6
6
|
|
|
7
7
|
/*
|
|
@@ -33,94 +33,167 @@ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
|
|
|
33
33
|
* SPDX-License-Identifier: MIT
|
|
34
34
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
/** Callbacks to invoke when reporting is enabled **/
|
|
37
|
+
const onReportingEnabledCallbacks = [];
|
|
38
|
+
/** The currently assigned reporting dispatcher. */
|
|
39
|
+
let currentDispatcher$1 = noop;
|
|
40
|
+
/**
|
|
41
|
+
* Whether reporting is enabled.
|
|
42
|
+
*
|
|
43
|
+
* Note that this may seem redundant, given you can just check if the currentDispatcher is undefined,
|
|
44
|
+
* but it turns out that Terser only strips out unused code if we use this explicit boolean.
|
|
45
|
+
*/
|
|
46
|
+
let enabled$1 = false;
|
|
47
|
+
const reportingControl = {
|
|
48
|
+
/**
|
|
49
|
+
* Attach a new reporting control (aka dispatcher).
|
|
50
|
+
*
|
|
51
|
+
* @param dispatcher - reporting control
|
|
52
|
+
*/
|
|
53
|
+
attachDispatcher(dispatcher) {
|
|
54
|
+
enabled$1 = true;
|
|
55
|
+
currentDispatcher$1 = dispatcher;
|
|
56
|
+
for (const callback of onReportingEnabledCallbacks) {
|
|
57
|
+
try {
|
|
58
|
+
callback();
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
// This should never happen. But if it does, we don't want one callback to cause another to fail
|
|
62
|
+
// eslint-disable-next-line no-console
|
|
63
|
+
console.error('Could not invoke callback', err);
|
|
64
|
+
}
|
|
44
65
|
}
|
|
66
|
+
onReportingEnabledCallbacks.length = 0; // clear the array
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Detach the current reporting control (aka dispatcher).
|
|
70
|
+
*/
|
|
71
|
+
detachDispatcher() {
|
|
72
|
+
enabled$1 = false;
|
|
73
|
+
currentDispatcher$1 = noop;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Call a callback when reporting is enabled, or immediately if reporting is already enabled.
|
|
78
|
+
* Will only ever be called once.
|
|
79
|
+
* @param callback
|
|
80
|
+
*/
|
|
81
|
+
function onReportingEnabled(callback) {
|
|
82
|
+
if (enabled$1) {
|
|
83
|
+
// call immediately
|
|
84
|
+
callback();
|
|
45
85
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
callbacks[i]();
|
|
86
|
+
else {
|
|
87
|
+
// call later
|
|
88
|
+
onReportingEnabledCallbacks.push(callback);
|
|
50
89
|
}
|
|
51
90
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Report to the current dispatcher, if there is one.
|
|
93
|
+
* @param reportingEventId
|
|
94
|
+
* @param vm
|
|
95
|
+
*/
|
|
96
|
+
function report(reportingEventId, vm) {
|
|
97
|
+
if (enabled$1) {
|
|
98
|
+
currentDispatcher$1(reportingEventId, vm.tagName, vm.idx);
|
|
60
99
|
}
|
|
61
|
-
ArrayPush$1.call(nextTickCallbackQueue, callback);
|
|
62
100
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
104
|
+
* All rights reserved.
|
|
105
|
+
* SPDX-License-Identifier: MIT
|
|
106
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
107
|
+
*/
|
|
108
|
+
function getComponentTag(vm) {
|
|
109
|
+
return `<${StringToLowerCase.call(vm.tagName)}>`;
|
|
110
|
+
}
|
|
111
|
+
// TODO [#1695]: Unify getComponentStack and getErrorComponentStack
|
|
112
|
+
function getComponentStack(vm) {
|
|
113
|
+
const stack = [];
|
|
114
|
+
let prefix = '';
|
|
115
|
+
while (!isNull(vm.owner)) {
|
|
116
|
+
ArrayPush$1.call(stack, prefix + getComponentTag(vm));
|
|
117
|
+
vm = vm.owner;
|
|
118
|
+
prefix += '\t';
|
|
68
119
|
}
|
|
69
|
-
return
|
|
120
|
+
return ArrayJoin.call(stack, '\n');
|
|
70
121
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const declarations = cssText.split(DECLARATION_DELIMITER);
|
|
78
|
-
for (const declaration of declarations) {
|
|
79
|
-
if (declaration) {
|
|
80
|
-
const [prop, value] = declaration.split(PROPERTY_DELIMITER);
|
|
81
|
-
if (prop !== undefined && value !== undefined) {
|
|
82
|
-
styleMap[prop.trim()] = value.trim();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
122
|
+
function getErrorComponentStack(vm) {
|
|
123
|
+
const wcStack = [];
|
|
124
|
+
let currentVm = vm;
|
|
125
|
+
while (!isNull(currentVm)) {
|
|
126
|
+
ArrayPush$1.call(wcStack, getComponentTag(currentVm));
|
|
127
|
+
currentVm = currentVm.owner;
|
|
85
128
|
}
|
|
86
|
-
return
|
|
129
|
+
return wcStack.reverse().join('\n\t');
|
|
87
130
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
134
|
+
* All rights reserved.
|
|
135
|
+
* SPDX-License-Identifier: MIT
|
|
136
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
137
|
+
*/
|
|
138
|
+
function addErrorComponentStack(vm, error) {
|
|
139
|
+
if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
|
|
140
|
+
const wcStack = getErrorComponentStack(vm);
|
|
141
|
+
defineProperty(error, 'wcStack', {
|
|
142
|
+
get() {
|
|
143
|
+
return wcStack;
|
|
144
|
+
},
|
|
145
|
+
});
|
|
95
146
|
}
|
|
96
|
-
return result;
|
|
97
147
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
148
|
+
|
|
149
|
+
/*
|
|
150
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
151
|
+
* All rights reserved.
|
|
152
|
+
* SPDX-License-Identifier: MIT
|
|
153
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
154
|
+
*/
|
|
155
|
+
const alreadyLoggedMessages = new Set();
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
window.__lwcResetAlreadyLoggedMessages = () => {
|
|
160
|
+
alreadyLoggedMessages.clear();
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function log(method, message, vm, once) {
|
|
164
|
+
let msg = `[LWC ${method}]: ${message}`;
|
|
165
|
+
if (!isUndefined$1(vm)) {
|
|
166
|
+
msg = `${msg}\n${getComponentStack(vm)}`;
|
|
167
|
+
}
|
|
168
|
+
if (once) {
|
|
169
|
+
if (alreadyLoggedMessages.has(msg)) {
|
|
170
|
+
return;
|
|
106
171
|
}
|
|
172
|
+
alreadyLoggedMessages.add(msg);
|
|
107
173
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
throw new Error('refVNodes must be defined when setting a ref');
|
|
174
|
+
// In Jest tests, reduce the warning and error verbosity by not printing the callstack
|
|
175
|
+
if (process.env.NODE_ENV === 'test') {
|
|
176
|
+
/* eslint-disable-next-line no-console */
|
|
177
|
+
console[method](msg);
|
|
178
|
+
return;
|
|
114
179
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
refVNodes[ref] = vnode;
|
|
180
|
+
try {
|
|
181
|
+
throw new Error(msg);
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
/* eslint-disable-next-line no-console */
|
|
185
|
+
console[method](e);
|
|
122
186
|
}
|
|
123
187
|
}
|
|
188
|
+
function logError(message, vm) {
|
|
189
|
+
log('error', message, vm, false);
|
|
190
|
+
}
|
|
191
|
+
function logWarn(message, vm) {
|
|
192
|
+
log('warn', message, vm, false);
|
|
193
|
+
}
|
|
194
|
+
function logWarnOnce(message, vm) {
|
|
195
|
+
log('warn', message, vm, true);
|
|
196
|
+
}
|
|
124
197
|
|
|
125
198
|
/*
|
|
126
199
|
* Copyright (c) 2019, salesforce.com, inc.
|
|
@@ -256,81 +329,98 @@ function createReactiveObserver(callback) {
|
|
|
256
329
|
* SPDX-License-Identifier: MIT
|
|
257
330
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
258
331
|
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
function
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
vm = vm.owner;
|
|
269
|
-
prefix += '\t';
|
|
270
|
-
}
|
|
271
|
-
return ArrayJoin.call(stack, '\n');
|
|
272
|
-
}
|
|
273
|
-
function getErrorComponentStack(vm) {
|
|
274
|
-
const wcStack = [];
|
|
275
|
-
let currentVm = vm;
|
|
276
|
-
while (!isNull(currentVm)) {
|
|
277
|
-
ArrayPush$1.call(wcStack, getComponentTag(currentVm));
|
|
278
|
-
currentVm = currentVm.owner;
|
|
332
|
+
let nextTickCallbackQueue = [];
|
|
333
|
+
const SPACE_CHAR = 32;
|
|
334
|
+
const EmptyObject = seal(create(null));
|
|
335
|
+
const EmptyArray = seal([]);
|
|
336
|
+
function flushCallbackQueue() {
|
|
337
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
338
|
+
if (nextTickCallbackQueue.length === 0) {
|
|
339
|
+
throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`);
|
|
340
|
+
}
|
|
279
341
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
285
|
-
* All rights reserved.
|
|
286
|
-
* SPDX-License-Identifier: MIT
|
|
287
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
288
|
-
*/
|
|
289
|
-
function addErrorComponentStack(vm, error) {
|
|
290
|
-
if (!isFrozen(error) && isUndefined$1(error.wcStack)) {
|
|
291
|
-
const wcStack = getErrorComponentStack(vm);
|
|
292
|
-
defineProperty(error, 'wcStack', {
|
|
293
|
-
get() {
|
|
294
|
-
return wcStack;
|
|
295
|
-
},
|
|
296
|
-
});
|
|
342
|
+
const callbacks = nextTickCallbackQueue;
|
|
343
|
+
nextTickCallbackQueue = []; // reset to a new queue
|
|
344
|
+
for (let i = 0, len = callbacks.length; i < len; i += 1) {
|
|
345
|
+
callbacks[i]();
|
|
297
346
|
}
|
|
298
347
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
305
|
-
*/
|
|
306
|
-
function log(method, message, vm) {
|
|
307
|
-
let msg = `[LWC ${method}]: ${message}`;
|
|
308
|
-
if (!isUndefined$1(vm)) {
|
|
309
|
-
msg = `${msg}\n${getComponentStack(vm)}`;
|
|
310
|
-
}
|
|
311
|
-
if (process.env.NODE_ENV === 'test') {
|
|
312
|
-
/* eslint-disable-next-line no-console */
|
|
313
|
-
console[method](msg);
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
try {
|
|
317
|
-
throw new Error(msg);
|
|
348
|
+
function addCallbackToNextTick(callback) {
|
|
349
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
350
|
+
if (!isFunction$1(callback)) {
|
|
351
|
+
throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`);
|
|
352
|
+
}
|
|
318
353
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
console[method](e);
|
|
354
|
+
if (nextTickCallbackQueue.length === 0) {
|
|
355
|
+
Promise.resolve().then(flushCallbackQueue);
|
|
322
356
|
}
|
|
357
|
+
ArrayPush$1.call(nextTickCallbackQueue, callback);
|
|
323
358
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
359
|
+
function guid() {
|
|
360
|
+
function s4() {
|
|
361
|
+
return Math.floor((1 + Math.random()) * 0x10000)
|
|
362
|
+
.toString(16)
|
|
363
|
+
.substring(1);
|
|
364
|
+
}
|
|
365
|
+
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
329
366
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
367
|
+
// Borrowed from Vue template compiler.
|
|
368
|
+
// https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
|
|
369
|
+
const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
|
|
370
|
+
const PROPERTY_DELIMITER = /:(.+)/;
|
|
371
|
+
function parseStyleText(cssText) {
|
|
372
|
+
const styleMap = {};
|
|
373
|
+
const declarations = cssText.split(DECLARATION_DELIMITER);
|
|
374
|
+
for (const declaration of declarations) {
|
|
375
|
+
if (declaration) {
|
|
376
|
+
const [prop, value] = declaration.split(PROPERTY_DELIMITER);
|
|
377
|
+
if (prop !== undefined && value !== undefined) {
|
|
378
|
+
styleMap[prop.trim()] = value.trim();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return styleMap;
|
|
383
|
+
}
|
|
384
|
+
// Make a shallow copy of an object but omit the given key
|
|
385
|
+
function cloneAndOmitKey(object, keyToOmit) {
|
|
386
|
+
const result = {};
|
|
387
|
+
for (const key of Object.keys(object)) {
|
|
388
|
+
if (key !== keyToOmit) {
|
|
389
|
+
result[key] = object[key];
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
function flattenStylesheets(stylesheets) {
|
|
395
|
+
const list = [];
|
|
396
|
+
for (const stylesheet of stylesheets) {
|
|
397
|
+
if (!Array.isArray(stylesheet)) {
|
|
398
|
+
list.push(stylesheet);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
list.push(...flattenStylesheets(stylesheet));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return list;
|
|
405
|
+
}
|
|
406
|
+
// Set a ref (lwc:ref) on a VM, from a template API
|
|
407
|
+
function setRefVNode(vm, ref, vnode) {
|
|
408
|
+
if (process.env.NODE_ENV !== 'production' && isUndefined$1(vm.refVNodes)) {
|
|
409
|
+
throw new Error('refVNodes must be defined when setting a ref');
|
|
410
|
+
}
|
|
411
|
+
// If this method is called, then vm.refVNodes is set as the template has refs.
|
|
412
|
+
// If not, then something went wrong and we threw an error above.
|
|
413
|
+
const refVNodes = vm.refVNodes;
|
|
414
|
+
// In cases of conflict (two elements with the same ref), prefer, the last one,
|
|
415
|
+
// in depth-first traversal order.
|
|
416
|
+
if (!(ref in refVNodes) || refVNodes[ref].key < vnode.key) {
|
|
417
|
+
refVNodes[ref] = vnode;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/*
|
|
422
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
423
|
+
* All rights reserved.
|
|
334
424
|
* SPDX-License-Identifier: MIT
|
|
335
425
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
336
426
|
*/
|
|
@@ -377,7 +467,10 @@ function offsetPropertyErrorMessage(name) {
|
|
|
377
467
|
// Global HTML Attributes & Properties
|
|
378
468
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
|
|
379
469
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
|
380
|
-
|
|
470
|
+
//
|
|
471
|
+
// If you update this list, check for test files that recapitulate the same list. Searching the codebase
|
|
472
|
+
// for e.g. "dropzone" should suffice.
|
|
473
|
+
const globalHTMLProperties = {
|
|
381
474
|
accessKey: {
|
|
382
475
|
attribute: 'accesskey',
|
|
383
476
|
},
|
|
@@ -462,7 +555,7 @@ const globalHTMLProperties = assign(create(null), {
|
|
|
462
555
|
role: {
|
|
463
556
|
attribute: 'role',
|
|
464
557
|
},
|
|
465
|
-
}
|
|
558
|
+
};
|
|
466
559
|
let controlledElement = null;
|
|
467
560
|
let controlledAttributeName;
|
|
468
561
|
function isAttributeLocked(elm, attrName) {
|
|
@@ -1926,89 +2019,377 @@ function createObservedFieldPropertyDescriptor(key) {
|
|
|
1926
2019
|
* SPDX-License-Identifier: MIT
|
|
1927
2020
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1928
2021
|
*/
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2022
|
+
const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
|
|
2023
|
+
const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
|
|
2024
|
+
const WIRE_DEBUG_ENTRY = '@wire';
|
|
2025
|
+
const WireMetaMap = new Map();
|
|
2026
|
+
class WireContextRegistrationEvent extends CustomEvent {
|
|
2027
|
+
constructor(adapterToken, {
|
|
2028
|
+
setNewContext,
|
|
2029
|
+
setDisconnectedCallback
|
|
2030
|
+
}) {
|
|
2031
|
+
super(adapterToken, {
|
|
2032
|
+
bubbles: true,
|
|
2033
|
+
composed: true
|
|
2034
|
+
});
|
|
2035
|
+
defineProperties(this, {
|
|
2036
|
+
setNewContext: {
|
|
2037
|
+
value: setNewContext
|
|
2038
|
+
},
|
|
2039
|
+
setDisconnectedCallback: {
|
|
2040
|
+
value: setDisconnectedCallback
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
}
|
|
1934
2044
|
}
|
|
1935
|
-
function
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
if (isBeingConstructed(vm)) {
|
|
1940
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1941
|
-
logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
|
|
1942
|
-
}
|
|
1943
|
-
return;
|
|
1944
|
-
}
|
|
1945
|
-
componentValueObserved(vm, key);
|
|
1946
|
-
return vm.cmpProps[key];
|
|
1947
|
-
},
|
|
1948
|
-
set(newValue) {
|
|
1949
|
-
const vm = getAssociatedVM(this);
|
|
1950
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1951
|
-
const vmBeingRendered = getVMBeingRendered();
|
|
1952
|
-
assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
1953
|
-
assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
1954
|
-
}
|
|
1955
|
-
vm.cmpProps[key] = newValue;
|
|
1956
|
-
componentValueMutated(vm, key);
|
|
1957
|
-
},
|
|
1958
|
-
enumerable: true,
|
|
1959
|
-
configurable: true,
|
|
1960
|
-
};
|
|
2045
|
+
function createFieldDataCallback(vm, name) {
|
|
2046
|
+
return value => {
|
|
2047
|
+
updateComponentValue(vm, name, value);
|
|
2048
|
+
};
|
|
1961
2049
|
}
|
|
1962
|
-
function
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2050
|
+
function createMethodDataCallback(vm, method) {
|
|
2051
|
+
return value => {
|
|
2052
|
+
// dispatching new value into the wired method
|
|
2053
|
+
runWithBoundaryProtection(vm, vm.owner, noop, () => {
|
|
2054
|
+
// job
|
|
2055
|
+
method.call(vm.component, value);
|
|
2056
|
+
}, noop);
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
|
|
2060
|
+
let hasPendingConfig = false;
|
|
2061
|
+
// creating the reactive observer for reactive params when needed
|
|
2062
|
+
const ro = createReactiveObserver(() => {
|
|
2063
|
+
if (hasPendingConfig === false) {
|
|
2064
|
+
hasPendingConfig = true;
|
|
2065
|
+
// collect new config in the micro-task
|
|
2066
|
+
Promise.resolve().then(() => {
|
|
2067
|
+
hasPendingConfig = false;
|
|
2068
|
+
// resetting current reactive params
|
|
2069
|
+
ro.reset();
|
|
2070
|
+
// dispatching a new config due to a change in the configuration
|
|
2071
|
+
computeConfigAndUpdate();
|
|
2072
|
+
});
|
|
1969
2073
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
1984
|
-
}
|
|
1985
|
-
if (set) {
|
|
1986
|
-
set.call(this, newValue);
|
|
1987
|
-
}
|
|
1988
|
-
else if (process.env.NODE_ENV !== 'production') {
|
|
1989
|
-
assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
|
|
1990
|
-
}
|
|
1991
|
-
},
|
|
1992
|
-
enumerable,
|
|
1993
|
-
configurable,
|
|
1994
|
-
};
|
|
2074
|
+
});
|
|
2075
|
+
const computeConfigAndUpdate = () => {
|
|
2076
|
+
let config;
|
|
2077
|
+
ro.observe(() => config = configCallback(component));
|
|
2078
|
+
// eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
|
|
2079
|
+
// TODO: dev-mode validation of config based on the adapter.configSchema
|
|
2080
|
+
// @ts-ignore it is assigned in the observe() callback
|
|
2081
|
+
callbackWhenConfigIsReady(config);
|
|
2082
|
+
};
|
|
2083
|
+
return {
|
|
2084
|
+
computeConfigAndUpdate,
|
|
2085
|
+
ro
|
|
2086
|
+
};
|
|
1995
2087
|
}
|
|
2088
|
+
function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
|
|
2089
|
+
const {
|
|
2090
|
+
adapter
|
|
2091
|
+
} = wireDef;
|
|
2092
|
+
const adapterContextToken = getAdapterToken(adapter);
|
|
2093
|
+
if (isUndefined$1(adapterContextToken)) {
|
|
2094
|
+
return; // no provider found, nothing to be done
|
|
2095
|
+
}
|
|
1996
2096
|
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
return getReactiveProxy(target);
|
|
2097
|
+
const {
|
|
2098
|
+
elm,
|
|
2099
|
+
context: {
|
|
2100
|
+
wiredConnecting,
|
|
2101
|
+
wiredDisconnecting
|
|
2102
|
+
},
|
|
2103
|
+
renderer: {
|
|
2104
|
+
dispatchEvent
|
|
2006
2105
|
}
|
|
2106
|
+
} = vm;
|
|
2107
|
+
// waiting for the component to be connected to formally request the context via the token
|
|
2108
|
+
ArrayPush$1.call(wiredConnecting, () => {
|
|
2109
|
+
// This event is responsible for connecting the host element with another
|
|
2110
|
+
// element in the composed path that is providing contextual data. The provider
|
|
2111
|
+
// must be listening for a special dom event with the name corresponding to the value of
|
|
2112
|
+
// `adapterContextToken`, which will remain secret and internal to this file only to
|
|
2113
|
+
// guarantee that the linkage can be forged.
|
|
2114
|
+
const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
|
|
2115
|
+
setNewContext(newContext) {
|
|
2116
|
+
// eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
|
|
2117
|
+
// TODO: dev-mode validation of config based on the adapter.contextSchema
|
|
2118
|
+
callbackWhenContextIsReady(newContext);
|
|
2119
|
+
},
|
|
2120
|
+
setDisconnectedCallback(disconnectCallback) {
|
|
2121
|
+
// adds this callback into the disconnect bucket so it gets disconnected from parent
|
|
2122
|
+
// the the element hosting the wire is disconnected
|
|
2123
|
+
ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
dispatchEvent(elm, contextRegistrationEvent);
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
function createConnector(vm, name, wireDef) {
|
|
2130
|
+
const {
|
|
2131
|
+
method,
|
|
2132
|
+
adapter,
|
|
2133
|
+
configCallback,
|
|
2134
|
+
dynamic
|
|
2135
|
+
} = wireDef;
|
|
2136
|
+
let debugInfo;
|
|
2137
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2138
|
+
const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
|
|
2139
|
+
debugInfo = create(null);
|
|
2140
|
+
debugInfo.wasDataProvisionedForConfig = false;
|
|
2141
|
+
vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
|
|
2142
|
+
}
|
|
2143
|
+
const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
|
|
2144
|
+
const dataCallback = value => {
|
|
2007
2145
|
if (process.env.NODE_ENV !== 'production') {
|
|
2008
|
-
|
|
2146
|
+
debugInfo.data = value;
|
|
2147
|
+
// Note: most of the time, the data provided is for the current config, but there may be
|
|
2148
|
+
// some conditions in which it does not, ex:
|
|
2149
|
+
// race conditions in a poor network while the adapter does not cancel a previous request.
|
|
2150
|
+
debugInfo.wasDataProvisionedForConfig = true;
|
|
2009
2151
|
}
|
|
2010
|
-
|
|
2011
|
-
}
|
|
2152
|
+
fieldOrMethodCallback(value);
|
|
2153
|
+
};
|
|
2154
|
+
let context;
|
|
2155
|
+
let connector;
|
|
2156
|
+
// Workaround to pass the component element associated to this wire adapter instance.
|
|
2157
|
+
defineProperty(dataCallback, DeprecatedWiredElementHost, {
|
|
2158
|
+
value: vm.elm
|
|
2159
|
+
});
|
|
2160
|
+
defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
|
|
2161
|
+
value: dynamic
|
|
2162
|
+
});
|
|
2163
|
+
runWithBoundaryProtection(vm, vm, noop, () => {
|
|
2164
|
+
// job
|
|
2165
|
+
connector = new adapter(dataCallback);
|
|
2166
|
+
}, noop);
|
|
2167
|
+
const updateConnectorConfig = config => {
|
|
2168
|
+
// every time the config is recomputed due to tracking,
|
|
2169
|
+
// this callback will be invoked with the new computed config
|
|
2170
|
+
runWithBoundaryProtection(vm, vm, noop, () => {
|
|
2171
|
+
// job
|
|
2172
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2173
|
+
debugInfo.config = config;
|
|
2174
|
+
debugInfo.context = context;
|
|
2175
|
+
debugInfo.wasDataProvisionedForConfig = false;
|
|
2176
|
+
}
|
|
2177
|
+
connector.update(config, context);
|
|
2178
|
+
}, noop);
|
|
2179
|
+
};
|
|
2180
|
+
// Computes the current wire config and calls the update method on the wire adapter.
|
|
2181
|
+
// If it has params, we will need to observe changes in the next tick.
|
|
2182
|
+
const {
|
|
2183
|
+
computeConfigAndUpdate,
|
|
2184
|
+
ro
|
|
2185
|
+
} = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
|
|
2186
|
+
// if the adapter needs contextualization, we need to watch for new context and push it alongside the config
|
|
2187
|
+
if (!isUndefined$1(adapter.contextSchema)) {
|
|
2188
|
+
createContextWatcher(vm, wireDef, newContext => {
|
|
2189
|
+
// every time the context is pushed into this component,
|
|
2190
|
+
// this callback will be invoked with the new computed context
|
|
2191
|
+
if (context !== newContext) {
|
|
2192
|
+
context = newContext;
|
|
2193
|
+
// Note: when new context arrives, the config will be recomputed and pushed along side the new
|
|
2194
|
+
// context, this is to preserve the identity characteristics, config should not have identity
|
|
2195
|
+
// (ever), while context can have identity
|
|
2196
|
+
if (vm.state === 1 /* VMState.connected */) {
|
|
2197
|
+
computeConfigAndUpdate();
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
return {
|
|
2203
|
+
// @ts-ignore the boundary protection executes sync, connector is always defined
|
|
2204
|
+
connector,
|
|
2205
|
+
computeConfigAndUpdate,
|
|
2206
|
+
resetConfigWatcher: () => ro.reset()
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
const AdapterToTokenMap = new Map();
|
|
2210
|
+
function getAdapterToken(adapter) {
|
|
2211
|
+
return AdapterToTokenMap.get(adapter);
|
|
2212
|
+
}
|
|
2213
|
+
function setAdapterToken(adapter, token) {
|
|
2214
|
+
AdapterToTokenMap.set(adapter, token);
|
|
2215
|
+
}
|
|
2216
|
+
function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
|
|
2217
|
+
// support for callable adapters
|
|
2218
|
+
if (adapter.adapter) {
|
|
2219
|
+
adapter = adapter.adapter;
|
|
2220
|
+
}
|
|
2221
|
+
const method = descriptor.value;
|
|
2222
|
+
const def = {
|
|
2223
|
+
adapter,
|
|
2224
|
+
method,
|
|
2225
|
+
configCallback,
|
|
2226
|
+
dynamic
|
|
2227
|
+
};
|
|
2228
|
+
WireMetaMap.set(descriptor, def);
|
|
2229
|
+
}
|
|
2230
|
+
function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
|
|
2231
|
+
// support for callable adapters
|
|
2232
|
+
if (adapter.adapter) {
|
|
2233
|
+
adapter = adapter.adapter;
|
|
2234
|
+
}
|
|
2235
|
+
const def = {
|
|
2236
|
+
adapter,
|
|
2237
|
+
configCallback,
|
|
2238
|
+
dynamic
|
|
2239
|
+
};
|
|
2240
|
+
WireMetaMap.set(descriptor, def);
|
|
2241
|
+
}
|
|
2242
|
+
function installWireAdapters(vm) {
|
|
2243
|
+
const {
|
|
2244
|
+
context,
|
|
2245
|
+
def: {
|
|
2246
|
+
wire
|
|
2247
|
+
}
|
|
2248
|
+
} = vm;
|
|
2249
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2250
|
+
vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
|
|
2251
|
+
}
|
|
2252
|
+
const wiredConnecting = context.wiredConnecting = [];
|
|
2253
|
+
const wiredDisconnecting = context.wiredDisconnecting = [];
|
|
2254
|
+
for (const fieldNameOrMethod in wire) {
|
|
2255
|
+
const descriptor = wire[fieldNameOrMethod];
|
|
2256
|
+
const wireDef = WireMetaMap.get(descriptor);
|
|
2257
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2258
|
+
assert.invariant(wireDef, `Internal Error: invalid wire definition found.`);
|
|
2259
|
+
}
|
|
2260
|
+
if (!isUndefined$1(wireDef)) {
|
|
2261
|
+
const {
|
|
2262
|
+
connector,
|
|
2263
|
+
computeConfigAndUpdate,
|
|
2264
|
+
resetConfigWatcher
|
|
2265
|
+
} = createConnector(vm, fieldNameOrMethod, wireDef);
|
|
2266
|
+
const hasDynamicParams = wireDef.dynamic.length > 0;
|
|
2267
|
+
ArrayPush$1.call(wiredConnecting, () => {
|
|
2268
|
+
connector.connect();
|
|
2269
|
+
if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
|
|
2270
|
+
if (hasDynamicParams) {
|
|
2271
|
+
Promise.resolve().then(computeConfigAndUpdate);
|
|
2272
|
+
return;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
computeConfigAndUpdate();
|
|
2276
|
+
});
|
|
2277
|
+
ArrayPush$1.call(wiredDisconnecting, () => {
|
|
2278
|
+
connector.disconnect();
|
|
2279
|
+
resetConfigWatcher();
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
function connectWireAdapters(vm) {
|
|
2285
|
+
const {
|
|
2286
|
+
wiredConnecting
|
|
2287
|
+
} = vm.context;
|
|
2288
|
+
for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
|
|
2289
|
+
wiredConnecting[i]();
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
function disconnectWireAdapters(vm) {
|
|
2293
|
+
const {
|
|
2294
|
+
wiredDisconnecting
|
|
2295
|
+
} = vm.context;
|
|
2296
|
+
runWithBoundaryProtection(vm, vm, noop, () => {
|
|
2297
|
+
// job
|
|
2298
|
+
for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
|
|
2299
|
+
wiredDisconnecting[i]();
|
|
2300
|
+
}
|
|
2301
|
+
}, noop);
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
/*
|
|
2305
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
2306
|
+
* All rights reserved.
|
|
2307
|
+
* SPDX-License-Identifier: MIT
|
|
2308
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2309
|
+
*/
|
|
2310
|
+
function api$1() {
|
|
2311
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2312
|
+
assert.fail(`@api decorator can only be used as a decorator function.`);
|
|
2313
|
+
}
|
|
2314
|
+
throw new Error();
|
|
2315
|
+
}
|
|
2316
|
+
function createPublicPropertyDescriptor(key) {
|
|
2317
|
+
return {
|
|
2318
|
+
get() {
|
|
2319
|
+
const vm = getAssociatedVM(this);
|
|
2320
|
+
if (isBeingConstructed(vm)) {
|
|
2321
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2322
|
+
logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
|
|
2323
|
+
}
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
componentValueObserved(vm, key);
|
|
2327
|
+
return vm.cmpProps[key];
|
|
2328
|
+
},
|
|
2329
|
+
set(newValue) {
|
|
2330
|
+
const vm = getAssociatedVM(this);
|
|
2331
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2332
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
2333
|
+
assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
2334
|
+
assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
2335
|
+
}
|
|
2336
|
+
vm.cmpProps[key] = newValue;
|
|
2337
|
+
componentValueMutated(vm, key);
|
|
2338
|
+
},
|
|
2339
|
+
enumerable: true,
|
|
2340
|
+
configurable: true,
|
|
2341
|
+
};
|
|
2342
|
+
}
|
|
2343
|
+
function createPublicAccessorDescriptor(key, descriptor) {
|
|
2344
|
+
const { get, set, enumerable, configurable } = descriptor;
|
|
2345
|
+
if (!isFunction$1(get)) {
|
|
2346
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2347
|
+
assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
|
|
2348
|
+
}
|
|
2349
|
+
throw new Error();
|
|
2350
|
+
}
|
|
2351
|
+
return {
|
|
2352
|
+
get() {
|
|
2353
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2354
|
+
// Assert that the this value is an actual Component with an associated VM.
|
|
2355
|
+
getAssociatedVM(this);
|
|
2356
|
+
}
|
|
2357
|
+
return get.call(this);
|
|
2358
|
+
},
|
|
2359
|
+
set(newValue) {
|
|
2360
|
+
const vm = getAssociatedVM(this);
|
|
2361
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2362
|
+
const vmBeingRendered = getVMBeingRendered();
|
|
2363
|
+
assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
2364
|
+
assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
|
|
2365
|
+
}
|
|
2366
|
+
if (set) {
|
|
2367
|
+
set.call(this, newValue);
|
|
2368
|
+
}
|
|
2369
|
+
else if (process.env.NODE_ENV !== 'production') {
|
|
2370
|
+
assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
|
|
2371
|
+
}
|
|
2372
|
+
},
|
|
2373
|
+
enumerable,
|
|
2374
|
+
configurable,
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
/*
|
|
2379
|
+
* Copyright (c) 2018, salesforce.com, inc.
|
|
2380
|
+
* All rights reserved.
|
|
2381
|
+
* SPDX-License-Identifier: MIT
|
|
2382
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2383
|
+
*/
|
|
2384
|
+
function track(target) {
|
|
2385
|
+
if (arguments.length === 1) {
|
|
2386
|
+
return getReactiveProxy(target);
|
|
2387
|
+
}
|
|
2388
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2389
|
+
assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
|
|
2390
|
+
}
|
|
2391
|
+
throw new Error();
|
|
2392
|
+
}
|
|
2012
2393
|
function internalTrackDecorator(key) {
|
|
2013
2394
|
return {
|
|
2014
2395
|
get() {
|
|
@@ -2971,6 +3352,9 @@ function updateStylesheetToken(vm, template) {
|
|
|
2971
3352
|
stylesheets: newStylesheets,
|
|
2972
3353
|
stylesheetToken: newStylesheetToken
|
|
2973
3354
|
} = template;
|
|
3355
|
+
const {
|
|
3356
|
+
stylesheets: newVmStylesheets
|
|
3357
|
+
} = vm;
|
|
2974
3358
|
const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
|
|
2975
3359
|
const {
|
|
2976
3360
|
hasScopedStyles
|
|
@@ -2994,7 +3378,9 @@ function updateStylesheetToken(vm, template) {
|
|
|
2994
3378
|
}
|
|
2995
3379
|
// Apply the new template styling token to the host element, if the new template has any
|
|
2996
3380
|
// associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
|
|
2997
|
-
|
|
3381
|
+
const hasNewStylesheets = hasStyles(newStylesheets);
|
|
3382
|
+
const hasNewVmStylesheets = hasStyles(newVmStylesheets);
|
|
3383
|
+
if (hasNewStylesheets || hasNewVmStylesheets) {
|
|
2998
3384
|
newToken = newStylesheetToken;
|
|
2999
3385
|
}
|
|
3000
3386
|
// Set the new styling token on the host element
|
|
@@ -3066,10 +3452,17 @@ function getStylesheetsContent(vm, template) {
|
|
|
3066
3452
|
stylesheets,
|
|
3067
3453
|
stylesheetToken
|
|
3068
3454
|
} = template;
|
|
3455
|
+
const {
|
|
3456
|
+
stylesheets: vmStylesheets
|
|
3457
|
+
} = vm;
|
|
3069
3458
|
let content = [];
|
|
3070
|
-
if (
|
|
3459
|
+
if (hasStyles(stylesheets)) {
|
|
3071
3460
|
content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
|
|
3072
3461
|
}
|
|
3462
|
+
// VM (component) stylesheets apply after template stylesheets
|
|
3463
|
+
if (hasStyles(vmStylesheets)) {
|
|
3464
|
+
ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
|
|
3465
|
+
}
|
|
3073
3466
|
return content;
|
|
3074
3467
|
}
|
|
3075
3468
|
// It might be worth caching this to avoid doing the lookup repeatedly, but
|
|
@@ -3107,10 +3500,13 @@ function getStylesheetTokenHost(vnode) {
|
|
|
3107
3500
|
const {
|
|
3108
3501
|
template
|
|
3109
3502
|
} = getComponentInternalDef(vnode.ctor);
|
|
3503
|
+
const {
|
|
3504
|
+
vm
|
|
3505
|
+
} = vnode;
|
|
3110
3506
|
const {
|
|
3111
3507
|
stylesheetToken
|
|
3112
3508
|
} = template;
|
|
3113
|
-
return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
|
|
3509
|
+
return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
|
|
3114
3510
|
}
|
|
3115
3511
|
function getNearestNativeShadowComponent(vm) {
|
|
3116
3512
|
const owner = getNearestShadowComponent(vm);
|
|
@@ -3727,6 +4123,28 @@ function patchCustomElement(n1, n2, parent, renderer) {
|
|
|
3727
4123
|
// in fallback mode, the allocation will always set children to
|
|
3728
4124
|
// empty and delegate the real allocation to the slot elements
|
|
3729
4125
|
allocateChildren(n2, vm);
|
|
4126
|
+
// Solves an edge case with slotted VFragments in native shadow mode.
|
|
4127
|
+
//
|
|
4128
|
+
// During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
|
|
4129
|
+
// to avoid interfering with native slot behavior. When this happens, if any of the fragments
|
|
4130
|
+
// were not stable, the children must go through the dynamic diffing algo.
|
|
4131
|
+
//
|
|
4132
|
+
// If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
|
|
4133
|
+
// the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
|
|
4134
|
+
// nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
|
|
4135
|
+
// mark the new children dynamic.
|
|
4136
|
+
//
|
|
4137
|
+
// Example:
|
|
4138
|
+
// n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
|
|
4139
|
+
// n2.children: [div, null, div] => [div, null, div] // marked ???
|
|
4140
|
+
const {
|
|
4141
|
+
shadowMode,
|
|
4142
|
+
renderMode
|
|
4143
|
+
} = vm;
|
|
4144
|
+
if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
|
|
4145
|
+
// No-op if children has already been marked dynamic by 'allocateChildren()'.
|
|
4146
|
+
markAsDynamicChildren(n2.children);
|
|
4147
|
+
}
|
|
3730
4148
|
}
|
|
3731
4149
|
// in fallback mode, the children will be always empty, so, nothing
|
|
3732
4150
|
// will happen, but in native, it does allocate the light dom
|
|
@@ -3919,7 +4337,6 @@ function allocateChildren(vnode, vm) {
|
|
|
3919
4337
|
//
|
|
3920
4338
|
// In case #2, we will always get a fresh VCustomElement.
|
|
3921
4339
|
const children = vnode.aChildren || vnode.children;
|
|
3922
|
-
vm.aChildren = children;
|
|
3923
4340
|
const {
|
|
3924
4341
|
renderMode,
|
|
3925
4342
|
shadowMode
|
|
@@ -3932,20 +4349,66 @@ function allocateChildren(vnode, vm) {
|
|
|
3932
4349
|
logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
|
|
3933
4350
|
}
|
|
3934
4351
|
}
|
|
4352
|
+
// If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
|
|
4353
|
+
// children VFragments to avoid them interfering with default slot behavior.
|
|
4354
|
+
const allocatedChildren = flattenFragmentsInChildren(children);
|
|
4355
|
+
vnode.children = allocatedChildren;
|
|
4356
|
+
vm.aChildren = allocatedChildren;
|
|
3935
4357
|
if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
|
|
3936
4358
|
// slow path
|
|
3937
|
-
allocateInSlot(vm,
|
|
4359
|
+
allocateInSlot(vm, allocatedChildren, vnode.owner);
|
|
3938
4360
|
// save the allocated children in case this vnode is reused.
|
|
3939
|
-
vnode.aChildren =
|
|
4361
|
+
vnode.aChildren = allocatedChildren;
|
|
3940
4362
|
// every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
|
|
3941
4363
|
vnode.children = EmptyArray;
|
|
3942
4364
|
}
|
|
3943
4365
|
}
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
4366
|
+
/**
|
|
4367
|
+
* Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
|
|
4368
|
+
* marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
|
|
4369
|
+
* and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
|
|
4370
|
+
*
|
|
4371
|
+
* With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
|
|
4372
|
+
*
|
|
4373
|
+
* This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
|
|
4374
|
+
*/
|
|
4375
|
+
function flattenFragmentsInChildren(children) {
|
|
4376
|
+
const flattenedChildren = [];
|
|
4377
|
+
// Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
|
|
4378
|
+
// If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
|
|
4379
|
+
const nodeStack = [];
|
|
4380
|
+
let fragmentFound = false;
|
|
4381
|
+
for (let i = children.length - 1; i > -1; i -= 1) {
|
|
4382
|
+
const child = children[i];
|
|
4383
|
+
ArrayPush$1.call(nodeStack, child);
|
|
4384
|
+
fragmentFound = fragmentFound || !!(child && isVFragment(child));
|
|
4385
|
+
}
|
|
4386
|
+
if (!fragmentFound) {
|
|
4387
|
+
return children;
|
|
4388
|
+
}
|
|
4389
|
+
let currentNode;
|
|
4390
|
+
while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
|
|
4391
|
+
if (!isNull(currentNode) && isVFragment(currentNode)) {
|
|
4392
|
+
const fChildren = currentNode.children;
|
|
4393
|
+
// Ignore the start and end text node delimiters
|
|
4394
|
+
for (let i = fChildren.length - 2; i > 0; i -= 1) {
|
|
4395
|
+
ArrayPush$1.call(nodeStack, fChildren[i]);
|
|
4396
|
+
}
|
|
4397
|
+
} else {
|
|
4398
|
+
ArrayPush$1.call(flattenedChildren, currentNode);
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
// We always mark the children as dynamic because nothing generates stable VFragments yet.
|
|
4402
|
+
// If/when stable VFragments are generated by the compiler, this code should be updated to
|
|
4403
|
+
// not mark dynamic if all flattened VFragments were stable.
|
|
4404
|
+
markAsDynamicChildren(flattenedChildren);
|
|
4405
|
+
return flattenedChildren;
|
|
4406
|
+
}
|
|
4407
|
+
function createViewModelHook(elm, vnode, renderer) {
|
|
4408
|
+
let vm = getAssociatedVMIfPresent(elm);
|
|
4409
|
+
// There is a possibility that a custom element is registered under tagName, in which case, the
|
|
4410
|
+
// initialization is already carry on, and there is nothing else to do here since this hook is
|
|
4411
|
+
// called right after invoking `document.createElement`.
|
|
3949
4412
|
if (!isUndefined$1(vm)) {
|
|
3950
4413
|
return vm;
|
|
3951
4414
|
}
|
|
@@ -3965,22 +4428,20 @@ function createViewModelHook(elm, vnode, renderer) {
|
|
|
3965
4428
|
}
|
|
3966
4429
|
return vm;
|
|
3967
4430
|
}
|
|
3968
|
-
|
|
3969
|
-
* Collects all slots into a SlotSet, traversing through VFragment Nodes
|
|
3970
|
-
*/
|
|
3971
|
-
function collectSlots(vm, children, cmpSlotsMapping) {
|
|
4431
|
+
function allocateInSlot(vm, children, owner) {
|
|
3972
4432
|
var _a, _b;
|
|
4433
|
+
const {
|
|
4434
|
+
cmpSlots: {
|
|
4435
|
+
slotAssignments: oldSlotsMapping
|
|
4436
|
+
}
|
|
4437
|
+
} = vm;
|
|
4438
|
+
const cmpSlotsMapping = create(null);
|
|
4439
|
+
// Collect all slots into cmpSlotsMapping
|
|
3973
4440
|
for (let i = 0, len = children.length; i < len; i += 1) {
|
|
3974
4441
|
const vnode = children[i];
|
|
3975
4442
|
if (isNull(vnode)) {
|
|
3976
4443
|
continue;
|
|
3977
4444
|
}
|
|
3978
|
-
// Dive further iff the content is wrapped in a VFragment
|
|
3979
|
-
if (isVFragment(vnode)) {
|
|
3980
|
-
// Remove the text delimiter nodes to avoid overriding default slot content
|
|
3981
|
-
collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
|
|
3982
|
-
continue;
|
|
3983
|
-
}
|
|
3984
4445
|
let slotName = '';
|
|
3985
4446
|
if (isVBaseElement(vnode)) {
|
|
3986
4447
|
slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
|
|
@@ -3990,15 +4451,6 @@ function collectSlots(vm, children, cmpSlotsMapping) {
|
|
|
3990
4451
|
const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
|
|
3991
4452
|
ArrayPush$1.call(vnodes, vnode);
|
|
3992
4453
|
}
|
|
3993
|
-
}
|
|
3994
|
-
function allocateInSlot(vm, children, owner) {
|
|
3995
|
-
const {
|
|
3996
|
-
cmpSlots: {
|
|
3997
|
-
slotAssignments: oldSlotsMapping
|
|
3998
|
-
}
|
|
3999
|
-
} = vm;
|
|
4000
|
-
const cmpSlotsMapping = create(null);
|
|
4001
|
-
collectSlots(vm, children, cmpSlotsMapping);
|
|
4002
4454
|
vm.cmpSlots = {
|
|
4003
4455
|
owner,
|
|
4004
4456
|
slotAssignments: cmpSlotsMapping
|
|
@@ -4029,14 +4481,14 @@ function allocateInSlot(vm, children, owner) {
|
|
|
4029
4481
|
}
|
|
4030
4482
|
}
|
|
4031
4483
|
// Using a WeakMap instead of a WeakSet because this one works in IE11 :(
|
|
4032
|
-
const
|
|
4033
|
-
// dynamic children means it was generated by an iteration
|
|
4034
|
-
//
|
|
4484
|
+
const DynamicChildren = new WeakMap();
|
|
4485
|
+
// dynamic children means it was either generated by an iteration in a template
|
|
4486
|
+
// or part of an unstable fragment, and will require a more complex diffing algo.
|
|
4035
4487
|
function markAsDynamicChildren(children) {
|
|
4036
|
-
|
|
4488
|
+
DynamicChildren.set(children, 1);
|
|
4037
4489
|
}
|
|
4038
4490
|
function hasDynamicChildren(children) {
|
|
4039
|
-
return
|
|
4491
|
+
return DynamicChildren.has(children);
|
|
4040
4492
|
}
|
|
4041
4493
|
function createKeyToOldIdx(children, beginIdx, endIdx) {
|
|
4042
4494
|
const map = {};
|
|
@@ -4902,7 +5354,7 @@ function evaluateTemplate(vm, html) {
|
|
|
4902
5354
|
// Create a brand new template cache for the swapped templated.
|
|
4903
5355
|
context.tplCache = create(null);
|
|
4904
5356
|
// Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
|
|
4905
|
-
context.hasScopedStyles = computeHasScopedStyles(html);
|
|
5357
|
+
context.hasScopedStyles = computeHasScopedStyles(html, vm);
|
|
4906
5358
|
// Update the scoping token on the host element.
|
|
4907
5359
|
updateStylesheetToken(vm, html);
|
|
4908
5360
|
// Evaluate, create stylesheet and cache the produced VNode for future
|
|
@@ -4945,9 +5397,8 @@ function evaluateTemplate(vm, html) {
|
|
|
4945
5397
|
}
|
|
4946
5398
|
return vnodes;
|
|
4947
5399
|
}
|
|
4948
|
-
function
|
|
4949
|
-
|
|
4950
|
-
if (!isUndefined$1(stylesheets)) {
|
|
5400
|
+
function computeHasScopedStylesInStylesheets(stylesheets) {
|
|
5401
|
+
if (hasStyles(stylesheets)) {
|
|
4951
5402
|
for (let i = 0; i < stylesheets.length; i++) {
|
|
4952
5403
|
if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
|
|
4953
5404
|
return true;
|
|
@@ -4956,6 +5407,15 @@ function computeHasScopedStyles(template) {
|
|
|
4956
5407
|
}
|
|
4957
5408
|
return false;
|
|
4958
5409
|
}
|
|
5410
|
+
function computeHasScopedStyles(template, vm) {
|
|
5411
|
+
const { stylesheets } = template;
|
|
5412
|
+
const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
|
|
5413
|
+
return (computeHasScopedStylesInStylesheets(stylesheets) ||
|
|
5414
|
+
computeHasScopedStylesInStylesheets(vmStylesheets));
|
|
5415
|
+
}
|
|
5416
|
+
function hasStyles(stylesheets) {
|
|
5417
|
+
return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
|
|
5418
|
+
}
|
|
4959
5419
|
|
|
4960
5420
|
/*
|
|
4961
5421
|
* Copyright (c) 2018, salesforce.com, inc.
|
|
@@ -5271,6 +5731,7 @@ function createVM(elm, ctor, renderer, options) {
|
|
|
5271
5731
|
// Properties set right after VM creation.
|
|
5272
5732
|
tro: null,
|
|
5273
5733
|
shadowMode: null,
|
|
5734
|
+
stylesheets: null,
|
|
5274
5735
|
// Properties set by the LightningElement constructor.
|
|
5275
5736
|
component: null,
|
|
5276
5737
|
shadowRoot: null,
|
|
@@ -5283,6 +5744,7 @@ function createVM(elm, ctor, renderer, options) {
|
|
|
5283
5744
|
if (process.env.NODE_ENV !== 'production') {
|
|
5284
5745
|
vm.debugInfo = create(null);
|
|
5285
5746
|
}
|
|
5747
|
+
vm.stylesheets = computeStylesheets(vm, def.ctor);
|
|
5286
5748
|
vm.shadowMode = computeShadowMode(vm, renderer);
|
|
5287
5749
|
vm.tro = getTemplateReactiveObserver(vm);
|
|
5288
5750
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -5301,6 +5763,42 @@ function createVM(elm, ctor, renderer, options) {
|
|
|
5301
5763
|
}
|
|
5302
5764
|
return vm;
|
|
5303
5765
|
}
|
|
5766
|
+
function validateComponentStylesheets(vm, stylesheets) {
|
|
5767
|
+
let valid = true;
|
|
5768
|
+
const validate = arrayOrStylesheet => {
|
|
5769
|
+
if (isArray$1(arrayOrStylesheet)) {
|
|
5770
|
+
for (let i = 0; i < arrayOrStylesheet.length; i++) {
|
|
5771
|
+
validate(arrayOrStylesheet[i]);
|
|
5772
|
+
}
|
|
5773
|
+
} else if (!isFunction$1(arrayOrStylesheet)) {
|
|
5774
|
+
// function assumed to be a stylesheet factory
|
|
5775
|
+
valid = false;
|
|
5776
|
+
}
|
|
5777
|
+
};
|
|
5778
|
+
if (!isArray$1(stylesheets)) {
|
|
5779
|
+
valid = false;
|
|
5780
|
+
} else {
|
|
5781
|
+
validate(stylesheets);
|
|
5782
|
+
}
|
|
5783
|
+
return valid;
|
|
5784
|
+
}
|
|
5785
|
+
// Validate and flatten any stylesheets defined as `static stylesheets`
|
|
5786
|
+
function computeStylesheets(vm, ctor) {
|
|
5787
|
+
if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
|
|
5788
|
+
const {
|
|
5789
|
+
stylesheets
|
|
5790
|
+
} = ctor;
|
|
5791
|
+
if (!isUndefined$1(stylesheets)) {
|
|
5792
|
+
const valid = validateComponentStylesheets(vm, stylesheets);
|
|
5793
|
+
if (valid) {
|
|
5794
|
+
return flattenStylesheets(stylesheets);
|
|
5795
|
+
} else if (process.env.NODE_ENV !== 'production') {
|
|
5796
|
+
logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
|
|
5797
|
+
}
|
|
5798
|
+
}
|
|
5799
|
+
}
|
|
5800
|
+
return null;
|
|
5801
|
+
}
|
|
5304
5802
|
function computeShadowMode(vm, renderer) {
|
|
5305
5803
|
const {
|
|
5306
5804
|
def
|
|
@@ -5671,286 +6169,143 @@ function forceRehydration(vm) {
|
|
|
5671
6169
|
* SPDX-License-Identifier: MIT
|
|
5672
6170
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
5673
6171
|
*/
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
|
|
5693
|
-
|
|
5694
|
-
|
|
5695
|
-
|
|
6172
|
+
//
|
|
6173
|
+
// The goal of this code is to detect invalid cross-root ARIA references in synthetic shadow DOM.
|
|
6174
|
+
// These invalid references should be fixed before the offending components can be migrated to native shadow DOM.
|
|
6175
|
+
// When invalid usage is detected, we warn in dev mode and call the reporting API if enabled.
|
|
6176
|
+
// See: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates
|
|
6177
|
+
//
|
|
6178
|
+
// Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
|
|
6179
|
+
const getElementById = globalThis$1[KEY__NATIVE_GET_ELEMENT_BY_ID];
|
|
6180
|
+
const querySelectorAll = globalThis$1[KEY__NATIVE_QUERY_SELECTOR_ALL];
|
|
6181
|
+
function isSyntheticShadowRootInstance(rootNode) {
|
|
6182
|
+
return rootNode !== document && isTrue(rootNode.synthetic);
|
|
6183
|
+
}
|
|
6184
|
+
function reportViolation(source, target, attrName) {
|
|
6185
|
+
// The vm is either for the source, the target, or both. Either one or both must be using synthetic
|
|
6186
|
+
// shadow for a violation to be detected.
|
|
6187
|
+
let vm = getAssociatedVMIfPresent(source.getRootNode().host);
|
|
6188
|
+
if (isUndefined$1(vm)) {
|
|
6189
|
+
vm = getAssociatedVMIfPresent(target.getRootNode().host);
|
|
6190
|
+
}
|
|
6191
|
+
if (isUndefined$1(vm)) {
|
|
6192
|
+
// vm should never be undefined here, but just to be safe, bail out and don't report
|
|
6193
|
+
return;
|
|
6194
|
+
}
|
|
6195
|
+
report(0 /* ReportingEventId.CrossRootAriaInSyntheticShadow */, vm);
|
|
6196
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
6197
|
+
// Avoid excessively logging to the console in the case of duplicates.
|
|
6198
|
+
logWarnOnce(`Element <${source.tagName.toLowerCase()}> uses attribute "${attrName}" to reference element ` +
|
|
6199
|
+
`<${target.tagName.toLowerCase()}>, which is not in the same shadow root. This will break in native shadow DOM. ` +
|
|
6200
|
+
`For details, see: https://lwc.dev/guide/accessibility#link-ids-and-aria-attributes-from-different-templates`, vm);
|
|
6201
|
+
}
|
|
5696
6202
|
}
|
|
5697
|
-
function
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
};
|
|
6203
|
+
function parseIdRefAttributeValue(attrValue) {
|
|
6204
|
+
// split on whitespace and skip empty strings after splitting
|
|
6205
|
+
return isString(attrValue) ? ArrayFilter.call(StringSplit.call(attrValue, /\s+/), Boolean) : [];
|
|
5701
6206
|
}
|
|
5702
|
-
function
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
// job
|
|
5707
|
-
method.call(vm.component, value);
|
|
5708
|
-
}, noop);
|
|
5709
|
-
};
|
|
5710
|
-
}
|
|
5711
|
-
function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
|
|
5712
|
-
let hasPendingConfig = false;
|
|
5713
|
-
// creating the reactive observer for reactive params when needed
|
|
5714
|
-
const ro = createReactiveObserver(() => {
|
|
5715
|
-
if (hasPendingConfig === false) {
|
|
5716
|
-
hasPendingConfig = true;
|
|
5717
|
-
// collect new config in the micro-task
|
|
5718
|
-
Promise.resolve().then(() => {
|
|
5719
|
-
hasPendingConfig = false;
|
|
5720
|
-
// resetting current reactive params
|
|
5721
|
-
ro.reset();
|
|
5722
|
-
// dispatching a new config due to a change in the configuration
|
|
5723
|
-
computeConfigAndUpdate();
|
|
5724
|
-
});
|
|
6207
|
+
function detectSyntheticCrossRootAria(elm, attrName, attrValue) {
|
|
6208
|
+
const root = elm.getRootNode();
|
|
6209
|
+
if (!isSyntheticShadowRootInstance(root)) {
|
|
6210
|
+
return;
|
|
5725
6211
|
}
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5733
|
-
|
|
5734
|
-
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
5740
|
-
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
6212
|
+
if (attrName === 'id') {
|
|
6213
|
+
// elm is the target, find the source
|
|
6214
|
+
if (!isString(attrValue) || attrValue.length === 0) {
|
|
6215
|
+
// if our id is null or empty, nobody can reference us
|
|
6216
|
+
return;
|
|
6217
|
+
}
|
|
6218
|
+
for (const idRefAttrName of ID_REFERENCING_ATTRIBUTES_SET) {
|
|
6219
|
+
// Query all global elements with this attribute. The attribute selector syntax `~=` is for values
|
|
6220
|
+
// that reference multiple IDs, separated by whitespace.
|
|
6221
|
+
const query = `[${idRefAttrName}~="${CSS.escape(attrValue)}"]`;
|
|
6222
|
+
const sourceElements = querySelectorAll.call(document, query);
|
|
6223
|
+
for (let i = 0; i < sourceElements.length; i++) {
|
|
6224
|
+
const sourceElement = sourceElements[i];
|
|
6225
|
+
const sourceRoot = sourceElement.getRootNode();
|
|
6226
|
+
if (sourceRoot !== root) {
|
|
6227
|
+
reportViolation(sourceElement, elm, idRefAttrName);
|
|
6228
|
+
break;
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
}
|
|
6232
|
+
}
|
|
6233
|
+
else {
|
|
6234
|
+
// elm is the source, find the target
|
|
6235
|
+
const ids = parseIdRefAttributeValue(attrValue);
|
|
6236
|
+
for (const id of ids) {
|
|
6237
|
+
const target = getElementById.call(document, id);
|
|
6238
|
+
if (!isNull(target)) {
|
|
6239
|
+
const targetRoot = target.getRootNode();
|
|
6240
|
+
if (targetRoot !== root) {
|
|
6241
|
+
// target element's shadow root is not the same as ours
|
|
6242
|
+
reportViolation(elm, target, attrName);
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
5757
6246
|
}
|
|
5758
|
-
} = vm;
|
|
5759
|
-
// waiting for the component to be connected to formally request the context via the token
|
|
5760
|
-
ArrayPush$1.call(wiredConnecting, () => {
|
|
5761
|
-
// This event is responsible for connecting the host element with another
|
|
5762
|
-
// element in the composed path that is providing contextual data. The provider
|
|
5763
|
-
// must be listening for a special dom event with the name corresponding to the value of
|
|
5764
|
-
// `adapterContextToken`, which will remain secret and internal to this file only to
|
|
5765
|
-
// guarantee that the linkage can be forged.
|
|
5766
|
-
const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
|
|
5767
|
-
setNewContext(newContext) {
|
|
5768
|
-
// eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
|
|
5769
|
-
// TODO: dev-mode validation of config based on the adapter.contextSchema
|
|
5770
|
-
callbackWhenContextIsReady(newContext);
|
|
5771
|
-
},
|
|
5772
|
-
setDisconnectedCallback(disconnectCallback) {
|
|
5773
|
-
// adds this callback into the disconnect bucket so it gets disconnected from parent
|
|
5774
|
-
// the the element hosting the wire is disconnected
|
|
5775
|
-
ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
|
|
5776
|
-
}
|
|
5777
|
-
});
|
|
5778
|
-
dispatchEvent(elm, contextRegistrationEvent);
|
|
5779
|
-
});
|
|
5780
6247
|
}
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
} = wireDef;
|
|
5788
|
-
let debugInfo;
|
|
5789
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5790
|
-
const wiredPropOrMethod = isUndefined$1(method) ? name : method.name;
|
|
5791
|
-
debugInfo = create(null);
|
|
5792
|
-
debugInfo.wasDataProvisionedForConfig = false;
|
|
5793
|
-
vm.debugInfo[WIRE_DEBUG_ENTRY][wiredPropOrMethod] = debugInfo;
|
|
5794
|
-
}
|
|
5795
|
-
const fieldOrMethodCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
|
|
5796
|
-
const dataCallback = value => {
|
|
5797
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5798
|
-
debugInfo.data = value;
|
|
5799
|
-
// Note: most of the time, the data provided is for the current config, but there may be
|
|
5800
|
-
// some conditions in which it does not, ex:
|
|
5801
|
-
// race conditions in a poor network while the adapter does not cancel a previous request.
|
|
5802
|
-
debugInfo.wasDataProvisionedForConfig = true;
|
|
6248
|
+
let enabled = false;
|
|
6249
|
+
// We want to avoid patching globals whenever possible, so this should be tree-shaken out in prod-mode and if
|
|
6250
|
+
// reporting is not enabled. It should also only run once
|
|
6251
|
+
function enableDetection() {
|
|
6252
|
+
if (enabled) {
|
|
6253
|
+
return; // don't double-apply the patches
|
|
5803
6254
|
}
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
});
|
|
5815
|
-
runWithBoundaryProtection(vm, vm, noop, () => {
|
|
5816
|
-
// job
|
|
5817
|
-
connector = new adapter(dataCallback);
|
|
5818
|
-
}, noop);
|
|
5819
|
-
const updateConnectorConfig = config => {
|
|
5820
|
-
// every time the config is recomputed due to tracking,
|
|
5821
|
-
// this callback will be invoked with the new computed config
|
|
5822
|
-
runWithBoundaryProtection(vm, vm, noop, () => {
|
|
5823
|
-
// job
|
|
5824
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5825
|
-
debugInfo.config = config;
|
|
5826
|
-
debugInfo.context = context;
|
|
5827
|
-
debugInfo.wasDataProvisionedForConfig = false;
|
|
5828
|
-
}
|
|
5829
|
-
connector.update(config, context);
|
|
5830
|
-
}, noop);
|
|
5831
|
-
};
|
|
5832
|
-
// Computes the current wire config and calls the update method on the wire adapter.
|
|
5833
|
-
// If it has params, we will need to observe changes in the next tick.
|
|
5834
|
-
const {
|
|
5835
|
-
computeConfigAndUpdate,
|
|
5836
|
-
ro
|
|
5837
|
-
} = createConfigWatcher(vm.component, configCallback, updateConnectorConfig);
|
|
5838
|
-
// if the adapter needs contextualization, we need to watch for new context and push it alongside the config
|
|
5839
|
-
if (!isUndefined$1(adapter.contextSchema)) {
|
|
5840
|
-
createContextWatcher(vm, wireDef, newContext => {
|
|
5841
|
-
// every time the context is pushed into this component,
|
|
5842
|
-
// this callback will be invoked with the new computed context
|
|
5843
|
-
if (context !== newContext) {
|
|
5844
|
-
context = newContext;
|
|
5845
|
-
// Note: when new context arrives, the config will be recomputed and pushed along side the new
|
|
5846
|
-
// context, this is to preserve the identity characteristics, config should not have identity
|
|
5847
|
-
// (ever), while context can have identity
|
|
5848
|
-
if (vm.state === 1 /* VMState.connected */) {
|
|
5849
|
-
computeConfigAndUpdate();
|
|
5850
|
-
}
|
|
5851
|
-
}
|
|
6255
|
+
enabled = true;
|
|
6256
|
+
const { setAttribute } = Element.prototype;
|
|
6257
|
+
// Detect calling `setAttribute` to set an idref or an id
|
|
6258
|
+
assign(Element.prototype, {
|
|
6259
|
+
setAttribute(attrName, attrValue) {
|
|
6260
|
+
setAttribute.call(this, attrName, attrValue);
|
|
6261
|
+
if (attrName === 'id' || ID_REFERENCING_ATTRIBUTES_SET.has(attrName)) {
|
|
6262
|
+
detectSyntheticCrossRootAria(this, attrName, attrValue);
|
|
6263
|
+
}
|
|
6264
|
+
},
|
|
5852
6265
|
});
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
6266
|
+
// Detect `elm.id = 'foo'`
|
|
6267
|
+
const idDescriptor = getOwnPropertyDescriptor$1(Element.prototype, 'id');
|
|
6268
|
+
if (!isUndefined$1(idDescriptor)) {
|
|
6269
|
+
const { get, set } = idDescriptor;
|
|
6270
|
+
// These should always be a getter and a setter, but if someone is monkeying with the global descriptor, ignore it
|
|
6271
|
+
if (isFunction$1(get) && isFunction$1(set)) {
|
|
6272
|
+
defineProperty(Element.prototype, 'id', {
|
|
6273
|
+
get() {
|
|
6274
|
+
return get.call(this);
|
|
6275
|
+
},
|
|
6276
|
+
set(value) {
|
|
6277
|
+
set.call(this, value);
|
|
6278
|
+
detectSyntheticCrossRootAria(this, 'id', value);
|
|
6279
|
+
},
|
|
6280
|
+
// On the default descriptor for 'id', enumerable and configurable are true
|
|
6281
|
+
enumerable: true,
|
|
6282
|
+
configurable: true,
|
|
6283
|
+
});
|
|
6284
|
+
}
|
|
6285
|
+
}
|
|
5867
6286
|
}
|
|
5868
|
-
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
}
|
|
5873
|
-
const method = descriptor.value;
|
|
5874
|
-
const def = {
|
|
5875
|
-
adapter,
|
|
5876
|
-
method,
|
|
5877
|
-
configCallback,
|
|
5878
|
-
dynamic
|
|
5879
|
-
};
|
|
5880
|
-
WireMetaMap.set(descriptor, def);
|
|
6287
|
+
// Our detection logic relies on some modern browser features. We can just skip reporting the data
|
|
6288
|
+
// for unsupported browsers
|
|
6289
|
+
function supportsCssEscape() {
|
|
6290
|
+
return typeof CSS !== 'undefined' && isFunction$1(CSS.escape);
|
|
5881
6291
|
}
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
adapter,
|
|
5889
|
-
configCallback,
|
|
5890
|
-
dynamic
|
|
5891
|
-
};
|
|
5892
|
-
WireMetaMap.set(descriptor, def);
|
|
6292
|
+
// If this page is not using synthetic shadow, then we don't need to install detection. Note
|
|
6293
|
+
// that we are assuming synthetic shadow is loaded before LWC.
|
|
6294
|
+
function isSyntheticShadowLoaded() {
|
|
6295
|
+
// We should probably be calling `renderer.isSyntheticShadowDefined`, but 1) we don't have access to the renderer,
|
|
6296
|
+
// and 2) this code needs to run in @lwc/engine-core, so it can access `logWarn()` and `report()`.
|
|
6297
|
+
return hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN);
|
|
5893
6298
|
}
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
def: {
|
|
5898
|
-
wire
|
|
5899
|
-
}
|
|
5900
|
-
} = vm;
|
|
5901
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5902
|
-
vm.debugInfo[WIRE_DEBUG_ENTRY] = create(null);
|
|
5903
|
-
}
|
|
5904
|
-
const wiredConnecting = context.wiredConnecting = [];
|
|
5905
|
-
const wiredDisconnecting = context.wiredDisconnecting = [];
|
|
5906
|
-
for (const fieldNameOrMethod in wire) {
|
|
5907
|
-
const descriptor = wire[fieldNameOrMethod];
|
|
5908
|
-
const wireDef = WireMetaMap.get(descriptor);
|
|
6299
|
+
// Detecting cross-root ARIA in synthetic shadow only makes sense for the browser
|
|
6300
|
+
if (process.env.IS_BROWSER && supportsCssEscape() && isSyntheticShadowLoaded()) {
|
|
6301
|
+
// Always run detection in dev mode, so we can at least print to the console
|
|
5909
6302
|
if (process.env.NODE_ENV !== 'production') {
|
|
5910
|
-
|
|
6303
|
+
enableDetection();
|
|
5911
6304
|
}
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
computeConfigAndUpdate,
|
|
5916
|
-
resetConfigWatcher
|
|
5917
|
-
} = createConnector(vm, fieldNameOrMethod, wireDef);
|
|
5918
|
-
const hasDynamicParams = wireDef.dynamic.length > 0;
|
|
5919
|
-
ArrayPush$1.call(wiredConnecting, () => {
|
|
5920
|
-
connector.connect();
|
|
5921
|
-
if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
|
|
5922
|
-
if (hasDynamicParams) {
|
|
5923
|
-
Promise.resolve().then(computeConfigAndUpdate);
|
|
5924
|
-
return;
|
|
5925
|
-
}
|
|
5926
|
-
}
|
|
5927
|
-
computeConfigAndUpdate();
|
|
5928
|
-
});
|
|
5929
|
-
ArrayPush$1.call(wiredDisconnecting, () => {
|
|
5930
|
-
connector.disconnect();
|
|
5931
|
-
resetConfigWatcher();
|
|
5932
|
-
});
|
|
5933
|
-
}
|
|
5934
|
-
}
|
|
5935
|
-
}
|
|
5936
|
-
function connectWireAdapters(vm) {
|
|
5937
|
-
const {
|
|
5938
|
-
wiredConnecting
|
|
5939
|
-
} = vm.context;
|
|
5940
|
-
for (let i = 0, len = wiredConnecting.length; i < len; i += 1) {
|
|
5941
|
-
wiredConnecting[i]();
|
|
5942
|
-
}
|
|
5943
|
-
}
|
|
5944
|
-
function disconnectWireAdapters(vm) {
|
|
5945
|
-
const {
|
|
5946
|
-
wiredDisconnecting
|
|
5947
|
-
} = vm.context;
|
|
5948
|
-
runWithBoundaryProtection(vm, vm, noop, () => {
|
|
5949
|
-
// job
|
|
5950
|
-
for (let i = 0, len = wiredDisconnecting.length; i < len; i += 1) {
|
|
5951
|
-
wiredDisconnecting[i]();
|
|
6305
|
+
else {
|
|
6306
|
+
// In prod mode, only enable detection if reporting is enabled
|
|
6307
|
+
onReportingEnabled(enableDetection);
|
|
5952
6308
|
}
|
|
5953
|
-
}, noop);
|
|
5954
6309
|
}
|
|
5955
6310
|
|
|
5956
6311
|
/*
|
|
@@ -6623,5 +6978,5 @@ function getComponentConstructor(elm) {
|
|
|
6623
6978
|
return ctor;
|
|
6624
6979
|
}
|
|
6625
6980
|
|
|
6626
|
-
export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
|
|
6627
|
-
/* version: 2.
|
|
6981
|
+
export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
|
|
6982
|
+
/* version: 2.35.0 */
|