lwc 2.50.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -8
- package/aria-reflection.d.ts +7 -0
- package/aria-reflection.js +7 -0
- package/babel-plugin-component.d.ts +7 -0
- package/babel-plugin-component.js +7 -0
- package/compiler.d.ts +7 -0
- package/compiler.js +7 -0
- package/engine-core.d.ts +7 -0
- package/engine-core.js +7 -0
- package/engine-dom.d.ts +7 -0
- package/engine-dom.js +7 -0
- package/engine-server.d.ts +7 -0
- package/engine-server.js +7 -0
- package/errors.d.ts +7 -0
- package/errors.js +7 -0
- package/features.d.ts +7 -0
- package/features.js +7 -0
- package/{types.d.ts → index.d.ts} +1 -1
- package/index.js +2 -85
- package/module-resolver.d.ts +7 -0
- package/module-resolver.js +7 -0
- package/package.json +42 -29
- package/rollup-plugin.d.ts +7 -0
- package/rollup-plugin.js +7 -0
- package/shared.d.ts +7 -0
- package/shared.js +7 -0
- package/style-compiler.d.ts +7 -0
- package/style-compiler.js +7 -0
- package/synthetic-shadow.d.ts +7 -0
- package/synthetic-shadow.js +7 -0
- package/template-compiler.d.ts +7 -0
- package/template-compiler.js +7 -0
- package/wire-service.d.ts +7 -0
- package/wire-service.js +7 -0
- package/dist/engine-dom/esm/es2017/engine-dom.js +0 -8391
- package/dist/engine-dom/esm/es2017/engine-dom.js.map +0 -1
- package/dist/engine-dom/iife/es2017/engine-dom.js +0 -8429
- package/dist/engine-dom/iife/es2017/engine-dom.js.map +0 -1
- package/dist/engine-dom/iife/es2017/engine-dom.min.js +0 -2
- package/dist/engine-dom/iife/es2017/engine-dom.min.js.map +0 -1
- package/dist/engine-dom/iife/es2017/engine-dom_debug.js +0 -6912
- package/dist/engine-dom/iife/es2017/engine-dom_debug.js.map +0 -1
- package/dist/engine-dom/iife/es5/engine-dom.js +0 -8815
- package/dist/engine-dom/iife/es5/engine-dom.js.map +0 -1
- package/dist/engine-dom/iife/es5/engine-dom.min.js +0 -2
- package/dist/engine-dom/iife/es5/engine-dom.min.js.map +0 -1
- package/dist/engine-dom/iife/es5/engine-dom_debug.js +0 -7325
- package/dist/engine-dom/iife/es5/engine-dom_debug.js.map +0 -1
- package/dist/engine-dom/umd/es2017/engine-dom.js +0 -8430
- package/dist/engine-dom/umd/es2017/engine-dom.js.map +0 -1
- package/dist/engine-dom/umd/es2017/engine-dom.min.js +0 -2
- package/dist/engine-dom/umd/es2017/engine-dom.min.js.map +0 -1
- package/dist/engine-dom/umd/es2017/engine-dom_debug.js +0 -6913
- package/dist/engine-dom/umd/es2017/engine-dom_debug.js.map +0 -1
- package/dist/engine-dom/umd/es5/engine-dom.js +0 -8816
- package/dist/engine-dom/umd/es5/engine-dom.js.map +0 -1
- package/dist/engine-dom/umd/es5/engine-dom.min.js +0 -2
- package/dist/engine-dom/umd/es5/engine-dom.min.js.map +0 -1
- package/dist/engine-dom/umd/es5/engine-dom_debug.js +0 -7326
- package/dist/engine-dom/umd/es5/engine-dom_debug.js.map +0 -1
- package/dist/engine-server/commonjs/es2017/engine-server.js +0 -14541
- package/dist/engine-server/commonjs/es2017/engine-server.js.map +0 -1
- package/dist/engine-server/commonjs/es2017/engine-server.min.js +0 -2
- package/dist/engine-server/commonjs/es2017/engine-server.min.js.map +0 -1
- package/dist/engine-server/esm/es2017/engine-server.js +0 -14517
- package/dist/engine-server/esm/es2017/engine-server.js.map +0 -1
- package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +0 -4757
- package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js.map +0 -1
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +0 -4762
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js.map +0 -1
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +0 -49
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js.map +0 -1
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +0 -4574
- package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js.map +0 -1
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +0 -4737
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js.map +0 -1
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +0 -49
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js.map +0 -1
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +0 -4538
- package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js.map +0 -1
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +0 -4764
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js.map +0 -1
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +0 -49
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js.map +0 -1
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +0 -4576
- package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js.map +0 -1
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +0 -4739
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js.map +0 -1
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +0 -49
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js.map +0 -1
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +0 -4540
- package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js.map +0 -1
- package/dist/wire-service/esm/es2017/wire-service.js +0 -195
- package/dist/wire-service/esm/es2017/wire-service.js.map +0 -1
- package/dist/wire-service/iife/es2017/wire-service.js +0 -204
- package/dist/wire-service/iife/es2017/wire-service.js.map +0 -1
- package/dist/wire-service/iife/es2017/wire-service.min.js +0 -2
- package/dist/wire-service/iife/es2017/wire-service.min.js.map +0 -1
- package/dist/wire-service/iife/es2017/wire-service_debug.js +0 -204
- package/dist/wire-service/iife/es2017/wire-service_debug.js.map +0 -1
- package/dist/wire-service/iife/es5/wire-service.js +0 -247
- package/dist/wire-service/iife/es5/wire-service.js.map +0 -1
- package/dist/wire-service/iife/es5/wire-service.min.js +0 -2
- package/dist/wire-service/iife/es5/wire-service.min.js.map +0 -1
- package/dist/wire-service/iife/es5/wire-service_debug.js +0 -247
- package/dist/wire-service/iife/es5/wire-service_debug.js.map +0 -1
- package/dist/wire-service/umd/es2017/wire-service.js +0 -205
- package/dist/wire-service/umd/es2017/wire-service.js.map +0 -1
- package/dist/wire-service/umd/es2017/wire-service.min.js +0 -2
- package/dist/wire-service/umd/es2017/wire-service.min.js.map +0 -1
- package/dist/wire-service/umd/es2017/wire-service_debug.js +0 -205
- package/dist/wire-service/umd/es2017/wire-service_debug.js.map +0 -1
- package/dist/wire-service/umd/es5/wire-service.js +0 -248
- package/dist/wire-service/umd/es5/wire-service.js.map +0 -1
- package/dist/wire-service/umd/es5/wire-service.min.js +0 -2
- package/dist/wire-service/umd/es5/wire-service.min.js.map +0 -1
- package/dist/wire-service/umd/es5/wire-service_debug.js +0 -248
- package/dist/wire-service/umd/es5/wire-service_debug.js.map +0 -1
|
@@ -1,4764 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
3
|
-
factory();
|
|
4
|
-
})((function () { 'use strict';
|
|
5
|
-
|
|
6
|
-
/* proxy-compat-disable */
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (C) 2023 salesforce.com, inc.
|
|
9
|
-
*/
|
|
10
|
-
/* proxy-compat-disable */
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (C) 2023 salesforce.com, inc.
|
|
13
|
-
*/
|
|
14
|
-
/*
|
|
15
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
16
|
-
* All rights reserved.
|
|
17
|
-
* SPDX-License-Identifier: MIT
|
|
18
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
19
|
-
*/
|
|
20
|
-
function invariant(value, msg) {
|
|
21
|
-
if (!value) {
|
|
22
|
-
throw new Error(`Invariant Violation: ${msg}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function isTrue$1(value, msg) {
|
|
26
|
-
if (!value) {
|
|
27
|
-
throw new Error(`Assert Violation: ${msg}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function isFalse$1(value, msg) {
|
|
31
|
-
if (value) {
|
|
32
|
-
throw new Error(`Assert Violation: ${msg}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function fail(msg) {
|
|
36
|
-
throw new Error(msg);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var assert = /*#__PURE__*/Object.freeze({
|
|
40
|
-
__proto__: null,
|
|
41
|
-
fail: fail,
|
|
42
|
-
invariant: invariant,
|
|
43
|
-
isFalse: isFalse$1,
|
|
44
|
-
isTrue: isTrue$1
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
49
|
-
* All rights reserved.
|
|
50
|
-
* SPDX-License-Identifier: MIT
|
|
51
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
52
|
-
*/
|
|
53
|
-
const { assign, create, defineProperties, defineProperty, freeze, getOwnPropertyDescriptor, getOwnPropertyNames, getPrototypeOf, hasOwnProperty, isFrozen, keys, seal, setPrototypeOf, } = Object;
|
|
54
|
-
const { isArray } = Array;
|
|
55
|
-
const { concat: ArrayConcat, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, } = Array.prototype;
|
|
56
|
-
const { charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, } = String.prototype;
|
|
57
|
-
function isUndefined(obj) {
|
|
58
|
-
return obj === undefined;
|
|
59
|
-
}
|
|
60
|
-
function isNull(obj) {
|
|
61
|
-
return obj === null;
|
|
62
|
-
}
|
|
63
|
-
function isTrue(obj) {
|
|
64
|
-
return obj === true;
|
|
65
|
-
}
|
|
66
|
-
function isFalse(obj) {
|
|
67
|
-
return obj === false;
|
|
68
|
-
}
|
|
69
|
-
function isFunction(obj) {
|
|
70
|
-
return typeof obj === 'function';
|
|
71
|
-
}
|
|
72
|
-
function isObject(obj) {
|
|
73
|
-
return typeof obj === 'object';
|
|
74
|
-
}
|
|
75
|
-
const OtS = {}.toString;
|
|
76
|
-
function toString(obj) {
|
|
77
|
-
if (obj && obj.toString) {
|
|
78
|
-
// Arrays might hold objects with "null" prototype So using
|
|
79
|
-
// Array.prototype.toString directly will cause an error Iterate through
|
|
80
|
-
// all the items and handle individually.
|
|
81
|
-
if (isArray(obj)) {
|
|
82
|
-
return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
|
|
83
|
-
}
|
|
84
|
-
return obj.toString();
|
|
85
|
-
}
|
|
86
|
-
else if (typeof obj === 'object') {
|
|
87
|
-
return OtS.call(obj);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
return obj + '';
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/*
|
|
95
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
96
|
-
* All rights reserved.
|
|
97
|
-
* SPDX-License-Identifier: MIT
|
|
98
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
99
|
-
*/
|
|
100
|
-
// See browser support for globalThis:
|
|
101
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
|
|
102
|
-
/* istanbul ignore next */
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
const _globalThis = typeof globalThis === 'object' ? globalThis : window;
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
108
|
-
* All rights reserved.
|
|
109
|
-
* SPDX-License-Identifier: MIT
|
|
110
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
111
|
-
*/
|
|
112
|
-
const KEY__IS_NATIVE_SHADOW_ROOT_DEFINED = '$isNativeShadowRootDefined$';
|
|
113
|
-
const KEY__SHADOW_RESOLVER = '$shadowResolver$';
|
|
114
|
-
const KEY__SHADOW_RESOLVER_PRIVATE = '$$ShadowResolverKey$$';
|
|
115
|
-
const KEY__SHADOW_STATIC = '$shadowStaticNode$';
|
|
116
|
-
const KEY__SHADOW_STATIC_PRIVATE = '$shadowStaticNodeKey$';
|
|
117
|
-
const KEY__SHADOW_TOKEN = '$shadowToken$';
|
|
118
|
-
const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
|
|
119
|
-
const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
|
|
120
|
-
const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
|
|
121
|
-
const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
|
|
122
|
-
|
|
123
|
-
/*
|
|
124
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
125
|
-
* All rights reserved.
|
|
126
|
-
* SPDX-License-Identifier: MIT
|
|
127
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
128
|
-
*/
|
|
129
|
-
// We use this to detect symbol support in order to avoid the expensive symbol polyfill. Note that
|
|
130
|
-
// we can't use typeof since it will fail when transpiling.
|
|
131
|
-
const hasNativeSymbolSupport = /*@__PURE__*/ (() => Symbol('x').toString() === 'Symbol(x)')();
|
|
132
|
-
/** version: 2.50.0 */
|
|
133
|
-
|
|
134
|
-
/* proxy-compat-disable */
|
|
135
|
-
/**
|
|
136
|
-
* Copyright (C) 2023 salesforce.com, inc.
|
|
137
|
-
*/
|
|
138
|
-
// eslint-disable-next-line no-restricted-properties
|
|
139
|
-
if (!_globalThis.lwcRuntimeFlags) {
|
|
140
|
-
Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
|
|
141
|
-
}
|
|
142
|
-
/** version: 2.50.0 */
|
|
143
|
-
|
|
144
|
-
/*
|
|
145
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
146
|
-
* All rights reserved.
|
|
147
|
-
* SPDX-License-Identifier: MIT
|
|
148
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
149
|
-
*/
|
|
150
|
-
// TODO [#2472]: Remove this workaround when appropriate.
|
|
151
|
-
// eslint-disable-next-line @lwc/lwc-internal/no-global-node
|
|
152
|
-
const _Node = Node;
|
|
153
|
-
const nodePrototype = _Node.prototype;
|
|
154
|
-
const { DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_PRECEDING, DOCUMENT_POSITION_FOLLOWING, ELEMENT_NODE, TEXT_NODE, CDATA_SECTION_NODE, PROCESSING_INSTRUCTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, } = _Node;
|
|
155
|
-
const { appendChild, cloneNode, compareDocumentPosition, insertBefore, removeChild, replaceChild, hasChildNodes, } = nodePrototype;
|
|
156
|
-
const { contains } = HTMLElement.prototype;
|
|
157
|
-
const firstChildGetter = getOwnPropertyDescriptor(nodePrototype, 'firstChild').get;
|
|
158
|
-
const lastChildGetter = getOwnPropertyDescriptor(nodePrototype, 'lastChild').get;
|
|
159
|
-
const textContentGetter = getOwnPropertyDescriptor(nodePrototype, 'textContent').get;
|
|
160
|
-
const parentNodeGetter = getOwnPropertyDescriptor(nodePrototype, 'parentNode').get;
|
|
161
|
-
const ownerDocumentGetter = getOwnPropertyDescriptor(nodePrototype, 'ownerDocument').get;
|
|
162
|
-
const parentElementGetter = hasOwnProperty.call(nodePrototype, 'parentElement')
|
|
163
|
-
? getOwnPropertyDescriptor(nodePrototype, 'parentElement').get
|
|
164
|
-
: getOwnPropertyDescriptor(HTMLElement.prototype, 'parentElement').get; // IE11
|
|
165
|
-
const textContextSetter = getOwnPropertyDescriptor(nodePrototype, 'textContent').set;
|
|
166
|
-
const childNodesGetter = hasOwnProperty.call(nodePrototype, 'childNodes')
|
|
167
|
-
? getOwnPropertyDescriptor(nodePrototype, 'childNodes').get
|
|
168
|
-
: getOwnPropertyDescriptor(HTMLElement.prototype, 'childNodes').get; // IE11
|
|
169
|
-
const isConnected = hasOwnProperty.call(nodePrototype, 'isConnected')
|
|
170
|
-
? getOwnPropertyDescriptor(nodePrototype, 'isConnected').get
|
|
171
|
-
: function () {
|
|
172
|
-
const doc = ownerDocumentGetter.call(this);
|
|
173
|
-
// IE11
|
|
174
|
-
return (
|
|
175
|
-
// if doc is null, it means `this` is actually a document instance which
|
|
176
|
-
// is always connected
|
|
177
|
-
doc === null ||
|
|
178
|
-
(compareDocumentPosition.call(doc, this) & DOCUMENT_POSITION_CONTAINED_BY) !== 0);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/*
|
|
182
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
183
|
-
* All rights reserved.
|
|
184
|
-
* SPDX-License-Identifier: MIT
|
|
185
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
186
|
-
*/
|
|
187
|
-
const { getAttribute, getBoundingClientRect, getElementsByTagName: getElementsByTagName$1, getElementsByTagNameNS: getElementsByTagNameNS$1, hasAttribute, querySelector, querySelectorAll: querySelectorAll$1, removeAttribute, setAttribute, } = Element.prototype;
|
|
188
|
-
const attachShadow$1 = hasOwnProperty.call(Element.prototype, 'attachShadow')
|
|
189
|
-
? Element.prototype.attachShadow
|
|
190
|
-
: () => {
|
|
191
|
-
throw new TypeError('attachShadow() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill and use Lightning Web Components');
|
|
192
|
-
};
|
|
193
|
-
const childElementCountGetter = getOwnPropertyDescriptor(Element.prototype, 'childElementCount').get;
|
|
194
|
-
const firstElementChildGetter = getOwnPropertyDescriptor(Element.prototype, 'firstElementChild').get;
|
|
195
|
-
const lastElementChildGetter = getOwnPropertyDescriptor(Element.prototype, 'lastElementChild').get;
|
|
196
|
-
const innerTextDescriptor = getOwnPropertyDescriptor(HTMLElement.prototype, 'innerText');
|
|
197
|
-
const innerTextGetter = innerTextDescriptor
|
|
198
|
-
? innerTextDescriptor.get
|
|
199
|
-
: null;
|
|
200
|
-
const innerTextSetter = innerTextDescriptor
|
|
201
|
-
? innerTextDescriptor.set
|
|
202
|
-
: null;
|
|
203
|
-
// Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText
|
|
204
|
-
const outerTextDescriptor = getOwnPropertyDescriptor(HTMLElement.prototype, 'outerText');
|
|
205
|
-
const outerTextGetter = outerTextDescriptor
|
|
206
|
-
? outerTextDescriptor.get
|
|
207
|
-
: null;
|
|
208
|
-
const outerTextSetter = outerTextDescriptor
|
|
209
|
-
? outerTextDescriptor.set
|
|
210
|
-
: null;
|
|
211
|
-
const innerHTMLDescriptor = hasOwnProperty.call(Element.prototype, 'innerHTML')
|
|
212
|
-
? getOwnPropertyDescriptor(Element.prototype, 'innerHTML')
|
|
213
|
-
: getOwnPropertyDescriptor(HTMLElement.prototype, 'innerHTML'); // IE11
|
|
214
|
-
const innerHTMLGetter = innerHTMLDescriptor.get;
|
|
215
|
-
const innerHTMLSetter = innerHTMLDescriptor.set;
|
|
216
|
-
const outerHTMLDescriptor = hasOwnProperty.call(Element.prototype, 'outerHTML')
|
|
217
|
-
? getOwnPropertyDescriptor(Element.prototype, 'outerHTML')
|
|
218
|
-
: getOwnPropertyDescriptor(HTMLElement.prototype, 'outerHTML'); // IE11
|
|
219
|
-
const outerHTMLGetter = outerHTMLDescriptor.get;
|
|
220
|
-
const outerHTMLSetter = outerHTMLDescriptor.set;
|
|
221
|
-
const tagNameGetter = getOwnPropertyDescriptor(Element.prototype, 'tagName').get;
|
|
222
|
-
const tabIndexDescriptor = getOwnPropertyDescriptor(HTMLElement.prototype, 'tabIndex');
|
|
223
|
-
const tabIndexGetter = tabIndexDescriptor.get;
|
|
224
|
-
const tabIndexSetter = tabIndexDescriptor.set;
|
|
225
|
-
const matches = hasOwnProperty.call(Element.prototype, 'matches')
|
|
226
|
-
? Element.prototype.matches
|
|
227
|
-
: Element.prototype.msMatchesSelector; // IE11
|
|
228
|
-
const childrenGetter = hasOwnProperty.call(Element.prototype, 'children')
|
|
229
|
-
? getOwnPropertyDescriptor(Element.prototype, 'children').get
|
|
230
|
-
: getOwnPropertyDescriptor(HTMLElement.prototype, 'children').get; // IE11
|
|
231
|
-
// for IE11, access from HTMLElement
|
|
232
|
-
// for all other browsers access the method from the parent Element interface
|
|
233
|
-
const { getElementsByClassName: getElementsByClassName$1 } = HTMLElement.prototype;
|
|
234
|
-
const shadowRootGetter = hasOwnProperty.call(Element.prototype, 'shadowRoot')
|
|
235
|
-
? getOwnPropertyDescriptor(Element.prototype, 'shadowRoot').get
|
|
236
|
-
: () => null;
|
|
237
|
-
const assignedSlotGetter$1 = hasOwnProperty.call(Element.prototype, 'assignedSlot')
|
|
238
|
-
? getOwnPropertyDescriptor(Element.prototype, 'assignedSlot').get
|
|
239
|
-
: () => null;
|
|
240
|
-
|
|
241
|
-
/*
|
|
242
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
243
|
-
* All rights reserved.
|
|
244
|
-
* SPDX-License-Identifier: MIT
|
|
245
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
246
|
-
*/
|
|
247
|
-
let assignedNodes, assignedElements;
|
|
248
|
-
if (typeof HTMLSlotElement !== 'undefined') {
|
|
249
|
-
assignedNodes = HTMLSlotElement.prototype.assignedNodes;
|
|
250
|
-
assignedElements = HTMLSlotElement.prototype.assignedElements;
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
assignedNodes = () => {
|
|
254
|
-
throw new TypeError("assignedNodes() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill to start using <slot> elements in your Lightning Web Component's template");
|
|
255
|
-
};
|
|
256
|
-
assignedElements = () => {
|
|
257
|
-
throw new TypeError("assignedElements() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill to start using <slot> elements in your Lightning Web Component's template");
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/*
|
|
262
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
263
|
-
* All rights reserved.
|
|
264
|
-
* SPDX-License-Identifier: MIT
|
|
265
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
266
|
-
*/
|
|
267
|
-
const eventTargetGetter = getOwnPropertyDescriptor(Event.prototype, 'target').get;
|
|
268
|
-
const eventCurrentTargetGetter = getOwnPropertyDescriptor(Event.prototype, 'currentTarget').get;
|
|
269
|
-
const focusEventRelatedTargetGetter = getOwnPropertyDescriptor(FocusEvent.prototype, 'relatedTarget').get;
|
|
270
|
-
// IE does not implement composedPath() but that's ok because we only use this instead of our
|
|
271
|
-
// composedPath() polyfill when dealing with native shadow DOM components in mixed mode. Defaulting
|
|
272
|
-
// to a NOOP just to be safe, even though this is almost guaranteed to be defined such a scenario.
|
|
273
|
-
const composedPath = hasOwnProperty.call(Event.prototype, 'composedPath')
|
|
274
|
-
? Event.prototype.composedPath
|
|
275
|
-
: () => [];
|
|
276
|
-
|
|
277
|
-
/*
|
|
278
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
279
|
-
* All rights reserved.
|
|
280
|
-
* SPDX-License-Identifier: MIT
|
|
281
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
282
|
-
*/
|
|
283
|
-
const DocumentPrototypeActiveElement = getOwnPropertyDescriptor(Document.prototype, 'activeElement').get;
|
|
284
|
-
const elementFromPoint = hasOwnProperty.call(Document.prototype, 'elementFromPoint')
|
|
285
|
-
? Document.prototype.elementFromPoint
|
|
286
|
-
: Document.prototype.msElementFromPoint; // IE11
|
|
287
|
-
const elementsFromPoint = hasOwnProperty.call(Document.prototype, 'elementsFromPoint')
|
|
288
|
-
? Document.prototype.elementsFromPoint
|
|
289
|
-
: Document.prototype.msElementsFromPoint; // IE11
|
|
290
|
-
// defaultView can be null when a document has no browsing context. For example, the owner document
|
|
291
|
-
// of a node in a template doesn't have a default view: https://jsfiddle.net/hv9z0q5a/
|
|
292
|
-
const defaultViewGetter = getOwnPropertyDescriptor(Document.prototype, 'defaultView').get;
|
|
293
|
-
const { createComment, querySelectorAll, getElementById, getElementsByClassName, getElementsByTagName, getElementsByTagNameNS, } = Document.prototype;
|
|
294
|
-
// In Firefox v57 and lower, getElementsByName is defined on HTMLDocument.prototype
|
|
295
|
-
// In all other browsers have the method on Document.prototype
|
|
296
|
-
const { getElementsByName } = HTMLDocument.prototype;
|
|
297
|
-
|
|
298
|
-
/*
|
|
299
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
300
|
-
* All rights reserved.
|
|
301
|
-
* SPDX-License-Identifier: MIT
|
|
302
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
303
|
-
*/
|
|
304
|
-
const { addEventListener: windowAddEventListener, removeEventListener: windowRemoveEventListener, getComputedStyle: windowGetComputedStyle, getSelection: windowGetSelection, } = window;
|
|
305
|
-
|
|
306
|
-
/*
|
|
307
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
308
|
-
* All rights reserved.
|
|
309
|
-
* SPDX-License-Identifier: MIT
|
|
310
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
311
|
-
*/
|
|
312
|
-
// There is code in the polyfills that requires access to the unpatched
|
|
313
|
-
// Mutation Observer constructor, this the code for that.
|
|
314
|
-
// Eventually, the polyfill should uses the patched version, and this file can be removed.
|
|
315
|
-
const MO = MutationObserver;
|
|
316
|
-
const MutationObserverObserve = MO.prototype.observe;
|
|
317
|
-
|
|
318
|
-
/*
|
|
319
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
320
|
-
* All rights reserved.
|
|
321
|
-
* SPDX-License-Identifier: MIT
|
|
322
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
323
|
-
*/
|
|
324
|
-
let NativeShadowRoot = null;
|
|
325
|
-
if (typeof ShadowRoot !== 'undefined') {
|
|
326
|
-
NativeShadowRoot = ShadowRoot;
|
|
327
|
-
}
|
|
328
|
-
const isNativeShadowRootDefined = !isNull(NativeShadowRoot);
|
|
329
|
-
const isInstanceOfNativeShadowRoot = isNull(NativeShadowRoot)
|
|
330
|
-
? () => false
|
|
331
|
-
: (node) => node instanceof NativeShadowRoot;
|
|
332
|
-
|
|
333
|
-
/*
|
|
334
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
335
|
-
* All rights reserved.
|
|
336
|
-
* SPDX-License-Identifier: MIT
|
|
337
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
338
|
-
*/
|
|
339
|
-
function detect$4 () {
|
|
340
|
-
return typeof HTMLSlotElement === 'undefined';
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/*
|
|
344
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
345
|
-
* All rights reserved.
|
|
346
|
-
* SPDX-License-Identifier: MIT
|
|
347
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
348
|
-
*/
|
|
349
|
-
const { createElement } = Document.prototype;
|
|
350
|
-
const CHAR_S = 115;
|
|
351
|
-
const CHAR_L = 108;
|
|
352
|
-
const CHAR_O = 111;
|
|
353
|
-
const CHAR_T = 116;
|
|
354
|
-
function apply$4() {
|
|
355
|
-
// IE11 does not have this element definition
|
|
356
|
-
// we don't care much about the construction phase, just the prototype
|
|
357
|
-
class HTMLSlotElement {
|
|
358
|
-
}
|
|
359
|
-
// prototype inheritance dance
|
|
360
|
-
setPrototypeOf(HTMLSlotElement, HTMLElement.constructor);
|
|
361
|
-
setPrototypeOf(HTMLSlotElement.prototype, HTMLElement.prototype);
|
|
362
|
-
Window.prototype.HTMLSlotElement = HTMLSlotElement;
|
|
363
|
-
// IE11 doesn't have HTMLSlotElement, in which case we
|
|
364
|
-
// need to patch Document.prototype.createElement to remap `slot`
|
|
365
|
-
// elements to the right prototype
|
|
366
|
-
defineProperty(Document.prototype, 'createElement', {
|
|
367
|
-
value: function (tagName, _options) {
|
|
368
|
-
const elm = createElement.apply(this, ArraySlice.call(arguments));
|
|
369
|
-
if (tagName.length === 4 &&
|
|
370
|
-
StringCharCodeAt.call(tagName, 0) === CHAR_S &&
|
|
371
|
-
StringCharCodeAt.call(tagName, 1) === CHAR_L &&
|
|
372
|
-
StringCharCodeAt.call(tagName, 2) === CHAR_O &&
|
|
373
|
-
StringCharCodeAt.call(tagName, 3) === CHAR_T) {
|
|
374
|
-
// the new element is the `slot`, resetting the proto chain
|
|
375
|
-
// the new newly created global HTMLSlotElement.prototype
|
|
376
|
-
setPrototypeOf(elm, HTMLSlotElement.prototype);
|
|
377
|
-
}
|
|
378
|
-
return elm;
|
|
379
|
-
},
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/*
|
|
384
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
385
|
-
* All rights reserved.
|
|
386
|
-
* SPDX-License-Identifier: MIT
|
|
387
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
388
|
-
*/
|
|
389
|
-
if (detect$4()) {
|
|
390
|
-
apply$4();
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/*
|
|
394
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
395
|
-
* All rights reserved.
|
|
396
|
-
* SPDX-License-Identifier: MIT
|
|
397
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
398
|
-
*/
|
|
399
|
-
// Helpful for tests running with jsdom
|
|
400
|
-
function getOwnerDocument(node) {
|
|
401
|
-
const doc = ownerDocumentGetter.call(node);
|
|
402
|
-
// if doc is null, it means `this` is actually a document instance
|
|
403
|
-
return doc === null ? node : doc;
|
|
404
|
-
}
|
|
405
|
-
function getOwnerWindow(node) {
|
|
406
|
-
const doc = getOwnerDocument(node);
|
|
407
|
-
const win = defaultViewGetter.call(doc);
|
|
408
|
-
if (win === null) {
|
|
409
|
-
// this method should never be called with a node that is not part
|
|
410
|
-
// of a qualifying connected node.
|
|
411
|
-
throw new TypeError();
|
|
412
|
-
}
|
|
413
|
-
return win;
|
|
414
|
-
}
|
|
415
|
-
let skipGlobalPatching;
|
|
416
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
417
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
418
|
-
function isGlobalPatchingSkipped(node) {
|
|
419
|
-
// we lazily compute this value instead of doing it during evaluation, this helps
|
|
420
|
-
// for apps that are setting this after the engine code is evaluated.
|
|
421
|
-
if (isUndefined(skipGlobalPatching)) {
|
|
422
|
-
const ownerDocument = getOwnerDocument(node);
|
|
423
|
-
skipGlobalPatching =
|
|
424
|
-
ownerDocument.body &&
|
|
425
|
-
getAttribute.call(ownerDocument.body, 'data-global-patching-bypass') ===
|
|
426
|
-
'temporary-bypass';
|
|
427
|
-
}
|
|
428
|
-
return isTrue(skipGlobalPatching);
|
|
429
|
-
}
|
|
430
|
-
function arrayFromCollection(collection) {
|
|
431
|
-
const size = collection.length;
|
|
432
|
-
const cloned = [];
|
|
433
|
-
if (size > 0) {
|
|
434
|
-
for (let i = 0; i < size; i++) {
|
|
435
|
-
cloned[i] = collection[i];
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return cloned;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/*
|
|
442
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
443
|
-
* All rights reserved.
|
|
444
|
-
* SPDX-License-Identifier: MIT
|
|
445
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
446
|
-
*/
|
|
447
|
-
const eventTargetPrototype = typeof EventTarget !== 'undefined' ? EventTarget.prototype : _Node.prototype;
|
|
448
|
-
const { addEventListener, dispatchEvent, removeEventListener } = eventTargetPrototype;
|
|
449
|
-
|
|
450
|
-
/*
|
|
451
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
452
|
-
* All rights reserved.
|
|
453
|
-
* SPDX-License-Identifier: MIT
|
|
454
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
455
|
-
*/
|
|
456
|
-
// Used as a back reference to identify the host element
|
|
457
|
-
const HostElementKey = '$$HostElementKey$$';
|
|
458
|
-
const ShadowedNodeKey = '$$ShadowedNodeKey$$';
|
|
459
|
-
function fastDefineProperty(node, propName, config) {
|
|
460
|
-
const shadowedNode = node;
|
|
461
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
462
|
-
// in dev, we are more restrictive
|
|
463
|
-
defineProperty(shadowedNode, propName, config);
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
const { value } = config;
|
|
467
|
-
// in prod, we prioritize performance
|
|
468
|
-
shadowedNode[propName] = value;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
function setNodeOwnerKey(node, value) {
|
|
472
|
-
fastDefineProperty(node, HostElementKey, { value, configurable: true });
|
|
473
|
-
}
|
|
474
|
-
function setNodeKey(node, value) {
|
|
475
|
-
fastDefineProperty(node, ShadowedNodeKey, { value });
|
|
476
|
-
}
|
|
477
|
-
function getNodeOwnerKey(node) {
|
|
478
|
-
return node[HostElementKey];
|
|
479
|
-
}
|
|
480
|
-
function getNodeNearestOwnerKey(node) {
|
|
481
|
-
let host = node;
|
|
482
|
-
let hostKey;
|
|
483
|
-
// search for the first element with owner identity
|
|
484
|
-
// in case of manually inserted elements and elements slotted from Light DOM
|
|
485
|
-
while (!isNull(host)) {
|
|
486
|
-
hostKey = getNodeOwnerKey(host);
|
|
487
|
-
if (!isUndefined(hostKey)) {
|
|
488
|
-
return hostKey;
|
|
489
|
-
}
|
|
490
|
-
host = parentNodeGetter.call(host);
|
|
491
|
-
if (!isNull(host) && isSyntheticSlotElement(host)) {
|
|
492
|
-
return undefined;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
function getNodeKey(node) {
|
|
497
|
-
return node[ShadowedNodeKey];
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* This function does not traverse up for performance reasons, but is sufficient for most use
|
|
501
|
-
* cases. If we need to traverse up and verify those nodes that don't have owner key, use
|
|
502
|
-
* isNodeDeepShadowed instead.
|
|
503
|
-
*/
|
|
504
|
-
function isNodeShadowed(node) {
|
|
505
|
-
return !isUndefined(getNodeOwnerKey(node));
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/*
|
|
509
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
510
|
-
* All rights reserved.
|
|
511
|
-
* SPDX-License-Identifier: MIT
|
|
512
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
513
|
-
*/
|
|
514
|
-
// when finding a slot in the DOM, we can fold it if it is contained
|
|
515
|
-
// inside another slot.
|
|
516
|
-
function foldSlotElement(slot) {
|
|
517
|
-
let parent = parentElementGetter.call(slot);
|
|
518
|
-
while (!isNull(parent) && isSlotElement(parent)) {
|
|
519
|
-
slot = parent;
|
|
520
|
-
parent = parentElementGetter.call(slot);
|
|
521
|
-
}
|
|
522
|
-
return slot;
|
|
523
|
-
}
|
|
524
|
-
function isNodeSlotted(host, node) {
|
|
525
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
526
|
-
if (!(host instanceof HTMLElement)) {
|
|
527
|
-
// eslint-disable-next-line no-console
|
|
528
|
-
console.error(`isNodeSlotted() should be called with a host as the first argument`);
|
|
529
|
-
}
|
|
530
|
-
if (!(node instanceof _Node)) {
|
|
531
|
-
// eslint-disable-next-line no-console
|
|
532
|
-
console.error(`isNodeSlotted() should be called with a node as the second argument`);
|
|
533
|
-
}
|
|
534
|
-
if (!(compareDocumentPosition.call(node, host) & DOCUMENT_POSITION_CONTAINS)) {
|
|
535
|
-
// eslint-disable-next-line no-console
|
|
536
|
-
console.error(`isNodeSlotted() should never be called with a node that is not a child node of the given host`);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
const hostKey = getNodeKey(host);
|
|
540
|
-
// this routine assumes that the node is coming from a different shadow (it is not owned by the host)
|
|
541
|
-
// just in case the provided node is not an element
|
|
542
|
-
let currentElement = node instanceof Element ? node : parentElementGetter.call(node);
|
|
543
|
-
while (!isNull(currentElement) && currentElement !== host) {
|
|
544
|
-
const elmOwnerKey = getNodeNearestOwnerKey(currentElement);
|
|
545
|
-
const parent = parentElementGetter.call(currentElement);
|
|
546
|
-
if (elmOwnerKey === hostKey) {
|
|
547
|
-
// we have reached an element inside the host's template, and only if
|
|
548
|
-
// that element is an slot, then the node is considered slotted
|
|
549
|
-
return isSlotElement(currentElement);
|
|
550
|
-
}
|
|
551
|
-
else if (parent === host) {
|
|
552
|
-
return false;
|
|
553
|
-
}
|
|
554
|
-
else if (!isNull(parent) && getNodeNearestOwnerKey(parent) !== elmOwnerKey) {
|
|
555
|
-
// we are crossing a boundary of some sort since the elm and its parent
|
|
556
|
-
// have different owner key. for slotted elements, this is possible
|
|
557
|
-
// if the parent happens to be a slot.
|
|
558
|
-
if (isSlotElement(parent)) {
|
|
559
|
-
/**
|
|
560
|
-
* the slot parent might be allocated inside another slot, think of:
|
|
561
|
-
* <x-root> (<--- root element)
|
|
562
|
-
* <x-parent> (<--- own by x-root)
|
|
563
|
-
* <x-child> (<--- own by x-root)
|
|
564
|
-
* <slot> (<--- own by x-child)
|
|
565
|
-
* <slot> (<--- own by x-parent)
|
|
566
|
-
* <div> (<--- own by x-root)
|
|
567
|
-
*
|
|
568
|
-
* while checking if x-parent has the div slotted, we need to traverse
|
|
569
|
-
* up, but when finding the first slot, we skip that one in favor of the
|
|
570
|
-
* most outer slot parent before jumping into its corresponding host.
|
|
571
|
-
*/
|
|
572
|
-
currentElement = getNodeOwner(foldSlotElement(parent));
|
|
573
|
-
if (!isNull(currentElement)) {
|
|
574
|
-
if (currentElement === host) {
|
|
575
|
-
// the slot element is a top level element inside the shadow
|
|
576
|
-
// of a host that was allocated into host in question
|
|
577
|
-
return true;
|
|
578
|
-
}
|
|
579
|
-
else if (getNodeNearestOwnerKey(currentElement) === hostKey) {
|
|
580
|
-
// the slot element is an element inside the shadow
|
|
581
|
-
// of a host that was allocated into host in question
|
|
582
|
-
return true;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
return false;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
else {
|
|
591
|
-
currentElement = parent;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
return false;
|
|
595
|
-
}
|
|
596
|
-
function getNodeOwner(node) {
|
|
597
|
-
if (!(node instanceof _Node)) {
|
|
598
|
-
return null;
|
|
599
|
-
}
|
|
600
|
-
const ownerKey = getNodeNearestOwnerKey(node);
|
|
601
|
-
if (isUndefined(ownerKey)) {
|
|
602
|
-
return null;
|
|
603
|
-
}
|
|
604
|
-
let nodeOwner = node;
|
|
605
|
-
// At this point, node is a valid node with owner identity, now we need to find the owner node
|
|
606
|
-
// search for a custom element with a VM that owns the first element with owner identity attached to it
|
|
607
|
-
while (!isNull(nodeOwner) && getNodeKey(nodeOwner) !== ownerKey) {
|
|
608
|
-
nodeOwner = parentNodeGetter.call(nodeOwner);
|
|
609
|
-
}
|
|
610
|
-
if (isNull(nodeOwner)) {
|
|
611
|
-
return null;
|
|
612
|
-
}
|
|
613
|
-
return nodeOwner;
|
|
614
|
-
}
|
|
615
|
-
function isSyntheticSlotElement(node) {
|
|
616
|
-
return isSlotElement(node) && isNodeShadowed(node);
|
|
617
|
-
}
|
|
618
|
-
function isSlotElement(node) {
|
|
619
|
-
return node instanceof HTMLSlotElement;
|
|
620
|
-
}
|
|
621
|
-
function isNodeOwnedBy(owner, node) {
|
|
622
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
623
|
-
if (!(owner instanceof HTMLElement)) {
|
|
624
|
-
// eslint-disable-next-line no-console
|
|
625
|
-
console.error(`isNodeOwnedBy() should be called with an element as the first argument`);
|
|
626
|
-
}
|
|
627
|
-
if (!(node instanceof _Node)) {
|
|
628
|
-
// eslint-disable-next-line no-console
|
|
629
|
-
console.error(`isNodeOwnedBy() should be called with a node as the second argument`);
|
|
630
|
-
}
|
|
631
|
-
if (!(compareDocumentPosition.call(node, owner) & DOCUMENT_POSITION_CONTAINS)) {
|
|
632
|
-
// eslint-disable-next-line no-console
|
|
633
|
-
console.error(`isNodeOwnedBy() should never be called with a node that is not a child node of of the given owner`);
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
const ownerKey = getNodeNearestOwnerKey(node);
|
|
637
|
-
if (isUndefined(ownerKey)) {
|
|
638
|
-
// in case of root level light DOM element slotting into a synthetic shadow
|
|
639
|
-
const host = parentNodeGetter.call(node);
|
|
640
|
-
if (!isNull(host) && isSyntheticSlotElement(host)) {
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
// in case of manually inserted elements
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
return getNodeKey(owner) === ownerKey;
|
|
647
|
-
}
|
|
648
|
-
function shadowRootChildNodes(root) {
|
|
649
|
-
const elm = getHost(root);
|
|
650
|
-
return getAllMatches(elm, arrayFromCollection(childNodesGetter.call(elm)));
|
|
651
|
-
}
|
|
652
|
-
function getAllSlottedMatches(host, nodeList) {
|
|
653
|
-
const filteredAndPatched = [];
|
|
654
|
-
for (let i = 0, len = nodeList.length; i < len; i += 1) {
|
|
655
|
-
const node = nodeList[i];
|
|
656
|
-
if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
|
|
657
|
-
ArrayPush.call(filteredAndPatched, node);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
return filteredAndPatched;
|
|
661
|
-
}
|
|
662
|
-
function getFirstSlottedMatch(host, nodeList) {
|
|
663
|
-
for (let i = 0, len = nodeList.length; i < len; i += 1) {
|
|
664
|
-
const node = nodeList[i];
|
|
665
|
-
if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) {
|
|
666
|
-
return node;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
return null;
|
|
670
|
-
}
|
|
671
|
-
function getAllMatches(owner, nodeList) {
|
|
672
|
-
const filteredAndPatched = [];
|
|
673
|
-
for (let i = 0, len = nodeList.length; i < len; i += 1) {
|
|
674
|
-
const node = nodeList[i];
|
|
675
|
-
const isOwned = isNodeOwnedBy(owner, node);
|
|
676
|
-
if (isOwned) {
|
|
677
|
-
// Patch querySelector, querySelectorAll, etc
|
|
678
|
-
// if element is owned by VM
|
|
679
|
-
ArrayPush.call(filteredAndPatched, node);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return filteredAndPatched;
|
|
683
|
-
}
|
|
684
|
-
function getFirstMatch(owner, nodeList) {
|
|
685
|
-
for (let i = 0, len = nodeList.length; i < len; i += 1) {
|
|
686
|
-
if (isNodeOwnedBy(owner, nodeList[i])) {
|
|
687
|
-
return nodeList[i];
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
return null;
|
|
691
|
-
}
|
|
692
|
-
function shadowRootQuerySelector(root, selector) {
|
|
693
|
-
const elm = getHost(root);
|
|
694
|
-
const nodeList = arrayFromCollection(querySelectorAll$1.call(elm, selector));
|
|
695
|
-
return getFirstMatch(elm, nodeList);
|
|
696
|
-
}
|
|
697
|
-
function shadowRootQuerySelectorAll(root, selector) {
|
|
698
|
-
const elm = getHost(root);
|
|
699
|
-
const nodeList = querySelectorAll$1.call(elm, selector);
|
|
700
|
-
return getAllMatches(elm, arrayFromCollection(nodeList));
|
|
701
|
-
}
|
|
702
|
-
function getFilteredChildNodes(node) {
|
|
703
|
-
if (!isSyntheticShadowHost(node) && !isSlotElement(node)) {
|
|
704
|
-
// regular element - fast path
|
|
705
|
-
const children = childNodesGetter.call(node);
|
|
706
|
-
return arrayFromCollection(children);
|
|
707
|
-
}
|
|
708
|
-
if (isSyntheticShadowHost(node)) {
|
|
709
|
-
// we need to get only the nodes that were slotted
|
|
710
|
-
const slots = arrayFromCollection(querySelectorAll$1.call(node, 'slot'));
|
|
711
|
-
const resolver = getShadowRootResolver(getShadowRoot(node));
|
|
712
|
-
// Typescript is inferring the wrong function type for this particular
|
|
713
|
-
// overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
|
|
714
|
-
// @ts-ignore type-mismatch
|
|
715
|
-
return ArrayReduce.call(slots, (seed, slot) => {
|
|
716
|
-
if (resolver === getShadowRootResolver(slot)) {
|
|
717
|
-
ArrayPush.apply(seed, getFilteredSlotAssignedNodes(slot));
|
|
718
|
-
}
|
|
719
|
-
return seed;
|
|
720
|
-
}, []);
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
// slot element
|
|
724
|
-
const children = arrayFromCollection(childNodesGetter.call(node));
|
|
725
|
-
const resolver = getShadowRootResolver(node);
|
|
726
|
-
return ArrayFilter.call(children, (child) => resolver === getShadowRootResolver(child));
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
function getFilteredSlotAssignedNodes(slot) {
|
|
730
|
-
const owner = getNodeOwner(slot);
|
|
731
|
-
if (isNull(owner)) {
|
|
732
|
-
return [];
|
|
733
|
-
}
|
|
734
|
-
const childNodes = arrayFromCollection(childNodesGetter.call(slot));
|
|
735
|
-
return ArrayFilter.call(childNodes, (child) => !isNodeShadowed(child) || !isNodeOwnedBy(owner, child));
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
/*
|
|
739
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
740
|
-
* All rights reserved.
|
|
741
|
-
* SPDX-License-Identifier: MIT
|
|
742
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
743
|
-
*/
|
|
744
|
-
/**
|
|
745
|
-
@license
|
|
746
|
-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
747
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
748
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
749
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
750
|
-
Code distributed by Google as part of the polymer project is also
|
|
751
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
752
|
-
*/
|
|
753
|
-
// This code is inspired by Polymer ShadyDOM Polyfill
|
|
754
|
-
function getInnerHTML(node) {
|
|
755
|
-
let s = '';
|
|
756
|
-
const childNodes = getFilteredChildNodes(node);
|
|
757
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
758
|
-
s += getOuterHTML(childNodes[i]);
|
|
759
|
-
}
|
|
760
|
-
return s;
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
/*
|
|
764
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
765
|
-
* All rights reserved.
|
|
766
|
-
* SPDX-License-Identifier: MIT
|
|
767
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
768
|
-
*/
|
|
769
|
-
/**
|
|
770
|
-
@license
|
|
771
|
-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
772
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
773
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
774
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
775
|
-
Code distributed by Google as part of the polymer project is also
|
|
776
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
777
|
-
*/
|
|
778
|
-
// This code is inspired by Polymer ShadyDOM Polyfill
|
|
779
|
-
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#escapingString
|
|
780
|
-
const escapeAttrRegExp = /[&\u00A0"]/g;
|
|
781
|
-
const escapeDataRegExp = /[&\u00A0<>]/g;
|
|
782
|
-
const { replace, toLowerCase } = String.prototype;
|
|
783
|
-
function escapeReplace(c) {
|
|
784
|
-
switch (c) {
|
|
785
|
-
case '&':
|
|
786
|
-
return '&';
|
|
787
|
-
case '<':
|
|
788
|
-
return '<';
|
|
789
|
-
case '>':
|
|
790
|
-
return '>';
|
|
791
|
-
case '"':
|
|
792
|
-
return '"';
|
|
793
|
-
case '\u00A0':
|
|
794
|
-
return ' ';
|
|
795
|
-
default:
|
|
796
|
-
return '';
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
function escapeAttr(s) {
|
|
800
|
-
return replace.call(s, escapeAttrRegExp, escapeReplace);
|
|
801
|
-
}
|
|
802
|
-
function escapeData(s) {
|
|
803
|
-
return replace.call(s, escapeDataRegExp, escapeReplace);
|
|
804
|
-
}
|
|
805
|
-
// http://www.whatwg.org/specs/web-apps/current-work/#void-elements
|
|
806
|
-
const voidElements = new Set([
|
|
807
|
-
'AREA',
|
|
808
|
-
'BASE',
|
|
809
|
-
'BR',
|
|
810
|
-
'COL',
|
|
811
|
-
'COMMAND',
|
|
812
|
-
'EMBED',
|
|
813
|
-
'HR',
|
|
814
|
-
'IMG',
|
|
815
|
-
'INPUT',
|
|
816
|
-
'KEYGEN',
|
|
817
|
-
'LINK',
|
|
818
|
-
'META',
|
|
819
|
-
'PARAM',
|
|
820
|
-
'SOURCE',
|
|
821
|
-
'TRACK',
|
|
822
|
-
'WBR',
|
|
823
|
-
]);
|
|
824
|
-
const plaintextParents = new Set([
|
|
825
|
-
'STYLE',
|
|
826
|
-
'SCRIPT',
|
|
827
|
-
'XMP',
|
|
828
|
-
'IFRAME',
|
|
829
|
-
'NOEMBED',
|
|
830
|
-
'NOFRAMES',
|
|
831
|
-
'PLAINTEXT',
|
|
832
|
-
'NOSCRIPT',
|
|
833
|
-
]);
|
|
834
|
-
function getOuterHTML(node) {
|
|
835
|
-
switch (node.nodeType) {
|
|
836
|
-
case ELEMENT_NODE: {
|
|
837
|
-
const { attributes: attrs } = node;
|
|
838
|
-
const tagName = tagNameGetter.call(node);
|
|
839
|
-
let s = '<' + toLowerCase.call(tagName);
|
|
840
|
-
for (let i = 0, attr; (attr = attrs[i]); i++) {
|
|
841
|
-
s += ' ' + attr.name + '="' + escapeAttr(attr.value) + '"';
|
|
842
|
-
}
|
|
843
|
-
s += '>';
|
|
844
|
-
if (voidElements.has(tagName)) {
|
|
845
|
-
return s;
|
|
846
|
-
}
|
|
847
|
-
return s + getInnerHTML(node) + '</' + toLowerCase.call(tagName) + '>';
|
|
848
|
-
}
|
|
849
|
-
case TEXT_NODE: {
|
|
850
|
-
const { data, parentNode } = node;
|
|
851
|
-
if (parentNode instanceof Element &&
|
|
852
|
-
plaintextParents.has(tagNameGetter.call(parentNode))) {
|
|
853
|
-
return data;
|
|
854
|
-
}
|
|
855
|
-
return escapeData(data);
|
|
856
|
-
}
|
|
857
|
-
case CDATA_SECTION_NODE: {
|
|
858
|
-
return `<!CDATA[[${node.data}]]>`;
|
|
859
|
-
}
|
|
860
|
-
case PROCESSING_INSTRUCTION_NODE: {
|
|
861
|
-
return `<?${node.target} ${node.data}?>`;
|
|
862
|
-
}
|
|
863
|
-
case COMMENT_NODE: {
|
|
864
|
-
return `<!--${node.data}-->`;
|
|
865
|
-
}
|
|
866
|
-
default: {
|
|
867
|
-
// intentionally ignoring unknown node types
|
|
868
|
-
// Note: since this routine is always invoked for childNodes
|
|
869
|
-
// we can safety ignore type 9, 10 and 99 (document, fragment and doctype)
|
|
870
|
-
return '';
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
/*
|
|
876
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
877
|
-
* All rights reserved.
|
|
878
|
-
* SPDX-License-Identifier: MIT
|
|
879
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
880
|
-
*/
|
|
881
|
-
/**
|
|
882
|
-
@license
|
|
883
|
-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
884
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
885
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
886
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
887
|
-
Code distributed by Google as part of the polymer project is also
|
|
888
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
889
|
-
*/
|
|
890
|
-
// This code is inspired by Polymer ShadyDOM Polyfill
|
|
891
|
-
function getTextContent(node) {
|
|
892
|
-
switch (node.nodeType) {
|
|
893
|
-
case ELEMENT_NODE: {
|
|
894
|
-
const childNodes = getFilteredChildNodes(node);
|
|
895
|
-
let content = '';
|
|
896
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
897
|
-
const currentNode = childNodes[i];
|
|
898
|
-
if (currentNode.nodeType !== COMMENT_NODE) {
|
|
899
|
-
content += getTextContent(currentNode);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
return content;
|
|
903
|
-
}
|
|
904
|
-
default:
|
|
905
|
-
return node.nodeValue;
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
/*
|
|
910
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
911
|
-
* All rights reserved.
|
|
912
|
-
* SPDX-License-Identifier: MIT
|
|
913
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
914
|
-
*/
|
|
915
|
-
const Items$1 = new WeakMap();
|
|
916
|
-
function StaticNodeList() {
|
|
917
|
-
throw new TypeError('Illegal constructor');
|
|
918
|
-
}
|
|
919
|
-
StaticNodeList.prototype = create(NodeList.prototype, {
|
|
920
|
-
constructor: {
|
|
921
|
-
writable: true,
|
|
922
|
-
configurable: true,
|
|
923
|
-
value: StaticNodeList,
|
|
924
|
-
},
|
|
925
|
-
item: {
|
|
926
|
-
writable: true,
|
|
927
|
-
enumerable: true,
|
|
928
|
-
configurable: true,
|
|
929
|
-
value(index) {
|
|
930
|
-
return this[index];
|
|
931
|
-
},
|
|
932
|
-
},
|
|
933
|
-
length: {
|
|
934
|
-
enumerable: true,
|
|
935
|
-
configurable: true,
|
|
936
|
-
get() {
|
|
937
|
-
return Items$1.get(this).length;
|
|
938
|
-
},
|
|
939
|
-
},
|
|
940
|
-
// Iterator protocol
|
|
941
|
-
forEach: {
|
|
942
|
-
writable: true,
|
|
943
|
-
enumerable: true,
|
|
944
|
-
configurable: true,
|
|
945
|
-
value(cb, thisArg) {
|
|
946
|
-
forEach.call(Items$1.get(this), cb, thisArg);
|
|
947
|
-
},
|
|
948
|
-
},
|
|
949
|
-
entries: {
|
|
950
|
-
writable: true,
|
|
951
|
-
enumerable: true,
|
|
952
|
-
configurable: true,
|
|
953
|
-
value() {
|
|
954
|
-
return ArrayMap.call(Items$1.get(this), (v, i) => [i, v]);
|
|
955
|
-
},
|
|
956
|
-
},
|
|
957
|
-
keys: {
|
|
958
|
-
writable: true,
|
|
959
|
-
enumerable: true,
|
|
960
|
-
configurable: true,
|
|
961
|
-
value() {
|
|
962
|
-
return ArrayMap.call(Items$1.get(this), (_v, i) => i);
|
|
963
|
-
},
|
|
964
|
-
},
|
|
965
|
-
values: {
|
|
966
|
-
writable: true,
|
|
967
|
-
enumerable: true,
|
|
968
|
-
configurable: true,
|
|
969
|
-
value() {
|
|
970
|
-
return Items$1.get(this);
|
|
971
|
-
},
|
|
972
|
-
},
|
|
973
|
-
[Symbol.iterator]: {
|
|
974
|
-
writable: true,
|
|
975
|
-
configurable: true,
|
|
976
|
-
value() {
|
|
977
|
-
let nextIndex = 0;
|
|
978
|
-
return {
|
|
979
|
-
next: () => {
|
|
980
|
-
const items = Items$1.get(this);
|
|
981
|
-
return nextIndex < items.length
|
|
982
|
-
? {
|
|
983
|
-
value: items[nextIndex++],
|
|
984
|
-
done: false,
|
|
985
|
-
}
|
|
986
|
-
: {
|
|
987
|
-
done: true,
|
|
988
|
-
};
|
|
989
|
-
},
|
|
990
|
-
};
|
|
991
|
-
},
|
|
992
|
-
},
|
|
993
|
-
[Symbol.toStringTag]: {
|
|
994
|
-
configurable: true,
|
|
995
|
-
get() {
|
|
996
|
-
return 'NodeList';
|
|
997
|
-
},
|
|
998
|
-
},
|
|
999
|
-
// IE11 doesn't support Symbol.toStringTag, in which case we
|
|
1000
|
-
// provide the regular toString method.
|
|
1001
|
-
toString: {
|
|
1002
|
-
writable: true,
|
|
1003
|
-
configurable: true,
|
|
1004
|
-
value() {
|
|
1005
|
-
return '[object NodeList]';
|
|
1006
|
-
},
|
|
1007
|
-
},
|
|
1008
|
-
});
|
|
1009
|
-
// prototype inheritance dance
|
|
1010
|
-
setPrototypeOf(StaticNodeList, NodeList);
|
|
1011
|
-
function createStaticNodeList(items) {
|
|
1012
|
-
const nodeList = create(StaticNodeList.prototype);
|
|
1013
|
-
Items$1.set(nodeList, items);
|
|
1014
|
-
// setting static indexes
|
|
1015
|
-
forEach.call(items, (item, index) => {
|
|
1016
|
-
defineProperty(nodeList, index, {
|
|
1017
|
-
value: item,
|
|
1018
|
-
enumerable: true,
|
|
1019
|
-
configurable: true,
|
|
1020
|
-
});
|
|
1021
|
-
});
|
|
1022
|
-
return nodeList;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
/*
|
|
1026
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1027
|
-
* All rights reserved.
|
|
1028
|
-
* SPDX-License-Identifier: MIT
|
|
1029
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1030
|
-
*/
|
|
1031
|
-
// Walk up the DOM tree, collecting all shadow roots plus the document root
|
|
1032
|
-
function getAllRootNodes(node) {
|
|
1033
|
-
var _a;
|
|
1034
|
-
const rootNodes = [];
|
|
1035
|
-
let currentRootNode = node.getRootNode();
|
|
1036
|
-
while (!isUndefined(currentRootNode)) {
|
|
1037
|
-
rootNodes.push(currentRootNode);
|
|
1038
|
-
currentRootNode = (_a = currentRootNode.host) === null || _a === void 0 ? void 0 : _a.getRootNode();
|
|
1039
|
-
}
|
|
1040
|
-
return rootNodes;
|
|
1041
|
-
}
|
|
1042
|
-
// Keep searching up the host tree until we find an element that is within the immediate shadow root
|
|
1043
|
-
const findAncestorHostInImmediateShadowRoot = (rootNode, targetRootNode) => {
|
|
1044
|
-
let host;
|
|
1045
|
-
while (!isUndefined((host = rootNode.host))) {
|
|
1046
|
-
const thisRootNode = host.getRootNode();
|
|
1047
|
-
if (thisRootNode === targetRootNode) {
|
|
1048
|
-
return host;
|
|
1049
|
-
}
|
|
1050
|
-
rootNode = thisRootNode;
|
|
1051
|
-
}
|
|
1052
|
-
};
|
|
1053
|
-
function fauxElementsFromPoint(context, doc, left, top) {
|
|
1054
|
-
const elements = elementsFromPoint.call(doc, left, top);
|
|
1055
|
-
const result = [];
|
|
1056
|
-
const rootNodes = getAllRootNodes(context);
|
|
1057
|
-
// Filter the elements array to only include those elements that are in this shadow root or in one of its
|
|
1058
|
-
// ancestor roots. This matches Chrome and Safari's implementation (but not Firefox's, which only includes
|
|
1059
|
-
// elements in the immediate shadow root: https://crbug.com/1207863#c4).
|
|
1060
|
-
if (!isNull(elements)) {
|
|
1061
|
-
// can be null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint#browser_compatibility
|
|
1062
|
-
for (let i = 0; i < elements.length; i++) {
|
|
1063
|
-
const element = elements[i];
|
|
1064
|
-
if (isSyntheticSlotElement(element)) {
|
|
1065
|
-
continue;
|
|
1066
|
-
}
|
|
1067
|
-
const elementRootNode = element.getRootNode();
|
|
1068
|
-
if (ArrayIndexOf.call(rootNodes, elementRootNode) !== -1) {
|
|
1069
|
-
ArrayPush.call(result, element);
|
|
1070
|
-
continue;
|
|
1071
|
-
}
|
|
1072
|
-
// In cases where the host element is not visible but its shadow descendants are, then
|
|
1073
|
-
// we may get the shadow descendant instead of the host element here. (The
|
|
1074
|
-
// browser doesn't know the difference in synthetic shadow DOM.)
|
|
1075
|
-
// In native shadow DOM, however, elementsFromPoint would return the host but not
|
|
1076
|
-
// the child. So we need to detect if this shadow element's host is accessible from
|
|
1077
|
-
// the context's shadow root. Note we also need to be careful not to add the host
|
|
1078
|
-
// multiple times.
|
|
1079
|
-
const ancestorHost = findAncestorHostInImmediateShadowRoot(elementRootNode, rootNodes[0]);
|
|
1080
|
-
if (!isUndefined(ancestorHost) &&
|
|
1081
|
-
ArrayIndexOf.call(elements, ancestorHost) === -1 &&
|
|
1082
|
-
ArrayIndexOf.call(result, ancestorHost) === -1) {
|
|
1083
|
-
ArrayPush.call(result, ancestorHost);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
return result;
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
/*
|
|
1091
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1092
|
-
* All rights reserved.
|
|
1093
|
-
* SPDX-License-Identifier: MIT
|
|
1094
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1095
|
-
*/
|
|
1096
|
-
const Items = new WeakMap();
|
|
1097
|
-
function StaticHTMLCollection() {
|
|
1098
|
-
throw new TypeError('Illegal constructor');
|
|
1099
|
-
}
|
|
1100
|
-
StaticHTMLCollection.prototype = create(HTMLCollection.prototype, {
|
|
1101
|
-
constructor: {
|
|
1102
|
-
writable: true,
|
|
1103
|
-
configurable: true,
|
|
1104
|
-
value: StaticHTMLCollection,
|
|
1105
|
-
},
|
|
1106
|
-
item: {
|
|
1107
|
-
writable: true,
|
|
1108
|
-
enumerable: true,
|
|
1109
|
-
configurable: true,
|
|
1110
|
-
value(index) {
|
|
1111
|
-
return this[index];
|
|
1112
|
-
},
|
|
1113
|
-
},
|
|
1114
|
-
length: {
|
|
1115
|
-
enumerable: true,
|
|
1116
|
-
configurable: true,
|
|
1117
|
-
get() {
|
|
1118
|
-
return Items.get(this).length;
|
|
1119
|
-
},
|
|
1120
|
-
},
|
|
1121
|
-
// https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem-key
|
|
1122
|
-
namedItem: {
|
|
1123
|
-
writable: true,
|
|
1124
|
-
enumerable: true,
|
|
1125
|
-
configurable: true,
|
|
1126
|
-
value(name) {
|
|
1127
|
-
if (name === '') {
|
|
1128
|
-
return null;
|
|
1129
|
-
}
|
|
1130
|
-
const items = Items.get(this);
|
|
1131
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
1132
|
-
const item = items[len];
|
|
1133
|
-
if (name === getAttribute.call(item, 'id') ||
|
|
1134
|
-
name === getAttribute.call(item, 'name')) {
|
|
1135
|
-
return item;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
return null;
|
|
1139
|
-
},
|
|
1140
|
-
},
|
|
1141
|
-
[Symbol.toStringTag]: {
|
|
1142
|
-
configurable: true,
|
|
1143
|
-
get() {
|
|
1144
|
-
return 'HTMLCollection';
|
|
1145
|
-
},
|
|
1146
|
-
},
|
|
1147
|
-
// IE11 doesn't support Symbol.toStringTag, in which case we
|
|
1148
|
-
// provide the regular toString method.
|
|
1149
|
-
toString: {
|
|
1150
|
-
writable: true,
|
|
1151
|
-
configurable: true,
|
|
1152
|
-
value() {
|
|
1153
|
-
return '[object HTMLCollection]';
|
|
1154
|
-
},
|
|
1155
|
-
},
|
|
1156
|
-
});
|
|
1157
|
-
// prototype inheritance dance
|
|
1158
|
-
setPrototypeOf(StaticHTMLCollection, HTMLCollection);
|
|
1159
|
-
function createStaticHTMLCollection(items) {
|
|
1160
|
-
const collection = create(StaticHTMLCollection.prototype);
|
|
1161
|
-
Items.set(collection, items);
|
|
1162
|
-
// setting static indexes
|
|
1163
|
-
forEach.call(items, (item, index) => {
|
|
1164
|
-
defineProperty(collection, index, {
|
|
1165
|
-
value: item,
|
|
1166
|
-
enumerable: true,
|
|
1167
|
-
configurable: true,
|
|
1168
|
-
});
|
|
1169
|
-
});
|
|
1170
|
-
return collection;
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
/*
|
|
1174
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1175
|
-
* All rights reserved.
|
|
1176
|
-
* SPDX-License-Identifier: MIT
|
|
1177
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1178
|
-
*/
|
|
1179
|
-
/**
|
|
1180
|
-
* This method checks whether or not the content of the node is computed
|
|
1181
|
-
* based on the light-dom slotting mechanism. This applies to synthetic slot elements
|
|
1182
|
-
* and elements with shadow dom attached to them. It doesn't apply to native slot elements
|
|
1183
|
-
* because we don't want to patch the children getters for those elements.
|
|
1184
|
-
*/
|
|
1185
|
-
function hasMountedChildren(node) {
|
|
1186
|
-
return isSyntheticSlotElement(node) || isSyntheticShadowHost(node);
|
|
1187
|
-
}
|
|
1188
|
-
function getShadowParent(node, value) {
|
|
1189
|
-
const owner = getNodeOwner(node);
|
|
1190
|
-
if (value === owner) {
|
|
1191
|
-
// walking up via parent chain might end up in the shadow root element
|
|
1192
|
-
return getShadowRoot(owner);
|
|
1193
|
-
}
|
|
1194
|
-
else if (value instanceof Element) {
|
|
1195
|
-
if (getNodeNearestOwnerKey(node) === getNodeNearestOwnerKey(value)) {
|
|
1196
|
-
// the element and its parent node belong to the same shadow root
|
|
1197
|
-
return value;
|
|
1198
|
-
}
|
|
1199
|
-
else if (!isNull(owner) && isSlotElement(value)) {
|
|
1200
|
-
// slotted elements must be top level childNodes of the slot element
|
|
1201
|
-
// where they slotted into, but its shadowed parent is always the
|
|
1202
|
-
// owner of the slot.
|
|
1203
|
-
const slotOwner = getNodeOwner(value);
|
|
1204
|
-
if (!isNull(slotOwner) && isNodeOwnedBy(owner, slotOwner)) {
|
|
1205
|
-
// it is a slotted element, and therefore its parent is always going to be the host of the slot
|
|
1206
|
-
return slotOwner;
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
return null;
|
|
1211
|
-
}
|
|
1212
|
-
function hasChildNodesPatched() {
|
|
1213
|
-
return getInternalChildNodes(this).length > 0;
|
|
1214
|
-
}
|
|
1215
|
-
function firstChildGetterPatched() {
|
|
1216
|
-
const childNodes = getInternalChildNodes(this);
|
|
1217
|
-
return childNodes[0] || null;
|
|
1218
|
-
}
|
|
1219
|
-
function lastChildGetterPatched() {
|
|
1220
|
-
const childNodes = getInternalChildNodes(this);
|
|
1221
|
-
return childNodes[childNodes.length - 1] || null;
|
|
1222
|
-
}
|
|
1223
|
-
function textContentGetterPatched() {
|
|
1224
|
-
return getTextContent(this);
|
|
1225
|
-
}
|
|
1226
|
-
function textContentSetterPatched(value) {
|
|
1227
|
-
textContextSetter.call(this, value);
|
|
1228
|
-
}
|
|
1229
|
-
function parentNodeGetterPatched() {
|
|
1230
|
-
const value = parentNodeGetter.call(this);
|
|
1231
|
-
if (isNull(value)) {
|
|
1232
|
-
return value;
|
|
1233
|
-
}
|
|
1234
|
-
// TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
|
|
1235
|
-
return getShadowParent(this, value);
|
|
1236
|
-
}
|
|
1237
|
-
function parentElementGetterPatched() {
|
|
1238
|
-
const value = parentNodeGetter.call(this);
|
|
1239
|
-
if (isNull(value)) {
|
|
1240
|
-
return null;
|
|
1241
|
-
}
|
|
1242
|
-
const parentNode = getShadowParent(this, value);
|
|
1243
|
-
// it could be that the parentNode is the shadowRoot, in which case
|
|
1244
|
-
// we need to return null.
|
|
1245
|
-
// TODO [#1635]: this needs optimization, maybe implementing it based on this.assignedSlot
|
|
1246
|
-
return parentNode instanceof Element ? parentNode : null;
|
|
1247
|
-
}
|
|
1248
|
-
function compareDocumentPositionPatched(otherNode) {
|
|
1249
|
-
if (this === otherNode) {
|
|
1250
|
-
return 0;
|
|
1251
|
-
}
|
|
1252
|
-
else if (this.getRootNode() === otherNode) {
|
|
1253
|
-
// "this" is in a shadow tree where the shadow root is the "otherNode".
|
|
1254
|
-
return 10; // Node.DOCUMENT_POSITION_CONTAINS | Node.DOCUMENT_POSITION_PRECEDING
|
|
1255
|
-
}
|
|
1256
|
-
else if (getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
|
|
1257
|
-
// "this" and "otherNode" belongs to 2 different shadow tree.
|
|
1258
|
-
return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
|
|
1259
|
-
}
|
|
1260
|
-
// Since "this" and "otherNode" are part of the same shadow tree we can safely rely to the native
|
|
1261
|
-
// Node.compareDocumentPosition implementation.
|
|
1262
|
-
return compareDocumentPosition.call(this, otherNode);
|
|
1263
|
-
}
|
|
1264
|
-
function containsPatched(otherNode) {
|
|
1265
|
-
if (otherNode == null || getNodeOwnerKey(this) !== getNodeOwnerKey(otherNode)) {
|
|
1266
|
-
// it is from another shadow
|
|
1267
|
-
return false;
|
|
1268
|
-
}
|
|
1269
|
-
return (compareDocumentPosition.call(this, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !== 0;
|
|
1270
|
-
}
|
|
1271
|
-
function cloneNodePatched(deep) {
|
|
1272
|
-
const clone = cloneNode.call(this, false);
|
|
1273
|
-
// Per spec, browsers only care about truthy values
|
|
1274
|
-
// Not strict true or false
|
|
1275
|
-
if (!deep) {
|
|
1276
|
-
return clone;
|
|
1277
|
-
}
|
|
1278
|
-
const childNodes = getInternalChildNodes(this);
|
|
1279
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
1280
|
-
clone.appendChild(childNodes[i].cloneNode(true));
|
|
1281
|
-
}
|
|
1282
|
-
return clone;
|
|
1283
|
-
}
|
|
1284
|
-
/**
|
|
1285
|
-
* This method only applies to elements with a shadow or slots
|
|
1286
|
-
*/
|
|
1287
|
-
function childNodesGetterPatched() {
|
|
1288
|
-
if (isSyntheticShadowHost(this)) {
|
|
1289
|
-
const owner = getNodeOwner(this);
|
|
1290
|
-
const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
|
|
1291
|
-
if (process.env.NODE_ENV !== 'production' &&
|
|
1292
|
-
isFalse(hasNativeSymbolSupport) &&
|
|
1293
|
-
isExternalChildNodeAccessorFlagOn()) {
|
|
1294
|
-
// inserting a comment node as the first childNode to trick the IE11
|
|
1295
|
-
// DevTool to show the content of the shadowRoot, this should only happen
|
|
1296
|
-
// in dev-mode and in IE11 (which we detect by looking at the symbol).
|
|
1297
|
-
// Plus it should only be in place if we know it is an external invoker.
|
|
1298
|
-
ArrayUnshift.call(childNodes, getIE11FakeShadowRootPlaceholder(this));
|
|
1299
|
-
}
|
|
1300
|
-
return createStaticNodeList(childNodes);
|
|
1301
|
-
}
|
|
1302
|
-
// nothing to do here since this does not have a synthetic shadow attached to it
|
|
1303
|
-
// TODO [#1636]: what about slot elements?
|
|
1304
|
-
return childNodesGetter.call(this);
|
|
1305
|
-
}
|
|
1306
|
-
const nativeGetRootNode = _Node.prototype.getRootNode;
|
|
1307
|
-
/**
|
|
1308
|
-
* Get the root by climbing up the dom tree, beyond the shadow root
|
|
1309
|
-
* If Node.prototype.getRootNode is supported, use it
|
|
1310
|
-
* else, assume we are working in non-native shadow mode and climb using parentNode
|
|
1311
|
-
*/
|
|
1312
|
-
const getDocumentOrRootNode = !isUndefined(nativeGetRootNode)
|
|
1313
|
-
? nativeGetRootNode
|
|
1314
|
-
: function () {
|
|
1315
|
-
let node = this;
|
|
1316
|
-
let nodeParent;
|
|
1317
|
-
while (!isNull((nodeParent = parentNodeGetter.call(node)))) {
|
|
1318
|
-
node = nodeParent;
|
|
1319
|
-
}
|
|
1320
|
-
return node;
|
|
1321
|
-
};
|
|
1322
|
-
/**
|
|
1323
|
-
* Get the shadow root
|
|
1324
|
-
* getNodeOwner() returns the host element that owns the given node
|
|
1325
|
-
* Note: getNodeOwner() returns null when running in native-shadow mode.
|
|
1326
|
-
* Fallback to using the native getRootNode() to discover the root node.
|
|
1327
|
-
* This is because, it is not possible to inspect the node and decide if it is part
|
|
1328
|
-
* of a native shadow or the synthetic shadow.
|
|
1329
|
-
* @param {Node} node
|
|
1330
|
-
*/
|
|
1331
|
-
function getNearestRoot(node) {
|
|
1332
|
-
const ownerNode = getNodeOwner(node);
|
|
1333
|
-
if (isNull(ownerNode)) {
|
|
1334
|
-
// we hit a wall, either we are in native shadow mode or the node is not in lwc boundary.
|
|
1335
|
-
return getDocumentOrRootNode.call(node);
|
|
1336
|
-
}
|
|
1337
|
-
return getShadowRoot(ownerNode);
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* If looking for a root node beyond shadow root by calling `node.getRootNode({composed: true})`, use the original `Node.prototype.getRootNode` method
|
|
1341
|
-
* to return the root of the dom tree. In IE11 and Edge, Node.prototype.getRootNode is
|
|
1342
|
-
* [not supported](https://developer.mozilla.org/en-US/docs/Web/API/Node/getRootNode#Browser_compatibility). The root node is discovered by manually
|
|
1343
|
-
* climbing up the dom tree.
|
|
1344
|
-
*
|
|
1345
|
-
* If looking for a shadow root of a node by calling `node.getRootNode({composed: false})` or `node.getRootNode()`,
|
|
1346
|
-
*
|
|
1347
|
-
* 1. Try to identify the host element that owns the give node.
|
|
1348
|
-
* i. Identify the shadow tree that the node belongs to
|
|
1349
|
-
* ii. If the node belongs to a shadow tree created by engine, return the shadowRoot of the host element that owns the shadow tree
|
|
1350
|
-
* 2. The host identification logic returns null in two cases:
|
|
1351
|
-
* i. The node does not belong to a shadow tree created by engine
|
|
1352
|
-
* ii. The engine is running in native shadow dom mode
|
|
1353
|
-
* If so, use the original Node.prototype.getRootNode to fetch the root node(or manually climb up the dom tree where getRootNode() is unsupported)
|
|
1354
|
-
*
|
|
1355
|
-
* _Spec_: https://dom.spec.whatwg.org/#dom-node-getrootnode
|
|
1356
|
-
*
|
|
1357
|
-
**/
|
|
1358
|
-
function getRootNodePatched(options) {
|
|
1359
|
-
const composed = isUndefined(options) ? false : !!options.composed;
|
|
1360
|
-
return isTrue(composed) ? getDocumentOrRootNode.call(this, options) : getNearestRoot(this);
|
|
1361
|
-
}
|
|
1362
|
-
// Non-deep-traversing patches: this descriptor map includes all descriptors that
|
|
1363
|
-
// do not give access to nodes beyond the immediate children.
|
|
1364
|
-
defineProperties(_Node.prototype, {
|
|
1365
|
-
firstChild: {
|
|
1366
|
-
get() {
|
|
1367
|
-
if (hasMountedChildren(this)) {
|
|
1368
|
-
return firstChildGetterPatched.call(this);
|
|
1369
|
-
}
|
|
1370
|
-
return firstChildGetter.call(this);
|
|
1371
|
-
},
|
|
1372
|
-
enumerable: true,
|
|
1373
|
-
configurable: true,
|
|
1374
|
-
},
|
|
1375
|
-
lastChild: {
|
|
1376
|
-
get() {
|
|
1377
|
-
if (hasMountedChildren(this)) {
|
|
1378
|
-
return lastChildGetterPatched.call(this);
|
|
1379
|
-
}
|
|
1380
|
-
return lastChildGetter.call(this);
|
|
1381
|
-
},
|
|
1382
|
-
enumerable: true,
|
|
1383
|
-
configurable: true,
|
|
1384
|
-
},
|
|
1385
|
-
textContent: {
|
|
1386
|
-
get() {
|
|
1387
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
1388
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
1389
|
-
if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
|
|
1390
|
-
return textContentGetterPatched.call(this);
|
|
1391
|
-
}
|
|
1392
|
-
return textContentGetter.call(this);
|
|
1393
|
-
},
|
|
1394
|
-
set: textContentSetterPatched,
|
|
1395
|
-
enumerable: true,
|
|
1396
|
-
configurable: true,
|
|
1397
|
-
},
|
|
1398
|
-
parentNode: {
|
|
1399
|
-
get() {
|
|
1400
|
-
if (isNodeShadowed(this)) {
|
|
1401
|
-
return parentNodeGetterPatched.call(this);
|
|
1402
|
-
}
|
|
1403
|
-
const parentNode = parentNodeGetter.call(this);
|
|
1404
|
-
// Handle the case where a top level light DOM element is slotted into a synthetic
|
|
1405
|
-
// shadow slot.
|
|
1406
|
-
if (!isNull(parentNode) && isSyntheticSlotElement(parentNode)) {
|
|
1407
|
-
return getNodeOwner(parentNode);
|
|
1408
|
-
}
|
|
1409
|
-
return parentNode;
|
|
1410
|
-
},
|
|
1411
|
-
enumerable: true,
|
|
1412
|
-
configurable: true,
|
|
1413
|
-
},
|
|
1414
|
-
parentElement: {
|
|
1415
|
-
get() {
|
|
1416
|
-
if (isNodeShadowed(this)) {
|
|
1417
|
-
return parentElementGetterPatched.call(this);
|
|
1418
|
-
}
|
|
1419
|
-
const parentElement = parentElementGetter.call(this);
|
|
1420
|
-
// Handle the case where a top level light DOM element is slotted into a synthetic
|
|
1421
|
-
// shadow slot.
|
|
1422
|
-
if (!isNull(parentElement) && isSyntheticSlotElement(parentElement)) {
|
|
1423
|
-
return getNodeOwner(parentElement);
|
|
1424
|
-
}
|
|
1425
|
-
return parentElement;
|
|
1426
|
-
},
|
|
1427
|
-
enumerable: true,
|
|
1428
|
-
configurable: true,
|
|
1429
|
-
},
|
|
1430
|
-
childNodes: {
|
|
1431
|
-
get() {
|
|
1432
|
-
if (hasMountedChildren(this)) {
|
|
1433
|
-
return childNodesGetterPatched.call(this);
|
|
1434
|
-
}
|
|
1435
|
-
return childNodesGetter.call(this);
|
|
1436
|
-
},
|
|
1437
|
-
enumerable: true,
|
|
1438
|
-
configurable: true,
|
|
1439
|
-
},
|
|
1440
|
-
hasChildNodes: {
|
|
1441
|
-
value() {
|
|
1442
|
-
if (hasMountedChildren(this)) {
|
|
1443
|
-
return hasChildNodesPatched.call(this);
|
|
1444
|
-
}
|
|
1445
|
-
return hasChildNodes.call(this);
|
|
1446
|
-
},
|
|
1447
|
-
enumerable: true,
|
|
1448
|
-
writable: true,
|
|
1449
|
-
configurable: true,
|
|
1450
|
-
},
|
|
1451
|
-
compareDocumentPosition: {
|
|
1452
|
-
value(otherNode) {
|
|
1453
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
1454
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
1455
|
-
if (isGlobalPatchingSkipped(this)) {
|
|
1456
|
-
return compareDocumentPosition.call(this, otherNode);
|
|
1457
|
-
}
|
|
1458
|
-
return compareDocumentPositionPatched.call(this, otherNode);
|
|
1459
|
-
},
|
|
1460
|
-
enumerable: true,
|
|
1461
|
-
writable: true,
|
|
1462
|
-
configurable: true,
|
|
1463
|
-
},
|
|
1464
|
-
contains: {
|
|
1465
|
-
value(otherNode) {
|
|
1466
|
-
// 1. Node.prototype.contains() returns true if otherNode is an inclusive descendant
|
|
1467
|
-
// spec: https://dom.spec.whatwg.org/#dom-node-contains
|
|
1468
|
-
// 2. This normalizes the behavior of this api across all browsers.
|
|
1469
|
-
// In IE11, a disconnected dom element without children invoking contains() on self, returns false
|
|
1470
|
-
if (this === otherNode) {
|
|
1471
|
-
return true;
|
|
1472
|
-
}
|
|
1473
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
1474
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
1475
|
-
if (otherNode == null) {
|
|
1476
|
-
return false;
|
|
1477
|
-
}
|
|
1478
|
-
if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
|
|
1479
|
-
return containsPatched.call(this, otherNode);
|
|
1480
|
-
}
|
|
1481
|
-
return contains.call(this, otherNode);
|
|
1482
|
-
},
|
|
1483
|
-
enumerable: true,
|
|
1484
|
-
writable: true,
|
|
1485
|
-
configurable: true,
|
|
1486
|
-
},
|
|
1487
|
-
cloneNode: {
|
|
1488
|
-
value(deep) {
|
|
1489
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
1490
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
1491
|
-
if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
|
|
1492
|
-
return cloneNodePatched.call(this, deep);
|
|
1493
|
-
}
|
|
1494
|
-
return cloneNode.call(this, deep);
|
|
1495
|
-
},
|
|
1496
|
-
enumerable: true,
|
|
1497
|
-
writable: true,
|
|
1498
|
-
configurable: true,
|
|
1499
|
-
},
|
|
1500
|
-
getRootNode: {
|
|
1501
|
-
value: getRootNodePatched,
|
|
1502
|
-
enumerable: true,
|
|
1503
|
-
configurable: true,
|
|
1504
|
-
writable: true,
|
|
1505
|
-
},
|
|
1506
|
-
isConnected: {
|
|
1507
|
-
enumerable: true,
|
|
1508
|
-
configurable: true,
|
|
1509
|
-
get() {
|
|
1510
|
-
return isConnected.call(this);
|
|
1511
|
-
},
|
|
1512
|
-
},
|
|
1513
|
-
});
|
|
1514
|
-
let internalChildNodeAccessorFlag = false;
|
|
1515
|
-
/**
|
|
1516
|
-
* These 2 methods are providing a machinery to understand who is accessing the
|
|
1517
|
-
* .childNodes member property of a node. If it is used from inside the synthetic shadow
|
|
1518
|
-
* or from an external invoker. This helps to produce the right output in one very peculiar
|
|
1519
|
-
* case, the IE11 debugging comment for shadowRoot representation on the devtool.
|
|
1520
|
-
*/
|
|
1521
|
-
function isExternalChildNodeAccessorFlagOn() {
|
|
1522
|
-
return !internalChildNodeAccessorFlag;
|
|
1523
|
-
}
|
|
1524
|
-
const getInternalChildNodes = process.env.NODE_ENV !== 'production' && isFalse(hasNativeSymbolSupport)
|
|
1525
|
-
? function (node) {
|
|
1526
|
-
internalChildNodeAccessorFlag = true;
|
|
1527
|
-
let childNodes;
|
|
1528
|
-
let error = null;
|
|
1529
|
-
try {
|
|
1530
|
-
childNodes = node.childNodes;
|
|
1531
|
-
}
|
|
1532
|
-
catch (e) {
|
|
1533
|
-
// childNodes accessor should never throw, but just in case!
|
|
1534
|
-
error = e;
|
|
1535
|
-
}
|
|
1536
|
-
finally {
|
|
1537
|
-
internalChildNodeAccessorFlag = false;
|
|
1538
|
-
if (!isNull(error)) {
|
|
1539
|
-
// re-throwing after restoring the state machinery for setInternalChildNodeAccessorFlag
|
|
1540
|
-
throw error; // eslint-disable-line no-unsafe-finally
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
return childNodes;
|
|
1544
|
-
}
|
|
1545
|
-
: function (node) {
|
|
1546
|
-
return node.childNodes;
|
|
1547
|
-
};
|
|
1548
|
-
// IE11 extra patches for wrong prototypes
|
|
1549
|
-
if (hasOwnProperty.call(HTMLElement.prototype, 'contains')) {
|
|
1550
|
-
defineProperty(HTMLElement.prototype, 'contains', getOwnPropertyDescriptor(_Node.prototype, 'contains'));
|
|
1551
|
-
}
|
|
1552
|
-
if (hasOwnProperty.call(HTMLElement.prototype, 'parentElement')) {
|
|
1553
|
-
defineProperty(HTMLElement.prototype, 'parentElement', getOwnPropertyDescriptor(_Node.prototype, 'parentElement'));
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
/*
|
|
1557
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1558
|
-
* All rights reserved.
|
|
1559
|
-
* SPDX-License-Identifier: MIT
|
|
1560
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1561
|
-
*/
|
|
1562
|
-
const EventListenerMap = new WeakMap();
|
|
1563
|
-
const ComposedPathMap = new WeakMap();
|
|
1564
|
-
function isEventListenerOrEventListenerObject$1(fnOrObj) {
|
|
1565
|
-
return (isFunction(fnOrObj) ||
|
|
1566
|
-
(isObject(fnOrObj) &&
|
|
1567
|
-
!isNull(fnOrObj) &&
|
|
1568
|
-
isFunction(fnOrObj.handleEvent)));
|
|
1569
|
-
}
|
|
1570
|
-
function shouldInvokeListener(event, target, currentTarget) {
|
|
1571
|
-
// Subsequent logic assumes that `currentTarget` must be contained in the composed path for the listener to be
|
|
1572
|
-
// invoked, but this is not always the case. `composedPath()` will sometimes return an empty array, even when the
|
|
1573
|
-
// listener should be invoked (e.g., a disconnected instance of EventTarget, an instance of XMLHttpRequest, etc).
|
|
1574
|
-
if (target === currentTarget) {
|
|
1575
|
-
return true;
|
|
1576
|
-
}
|
|
1577
|
-
let composedPath = ComposedPathMap.get(event);
|
|
1578
|
-
if (isUndefined(composedPath)) {
|
|
1579
|
-
composedPath = event.composedPath();
|
|
1580
|
-
ComposedPathMap.set(event, composedPath);
|
|
1581
|
-
}
|
|
1582
|
-
return composedPath.includes(currentTarget);
|
|
1583
|
-
}
|
|
1584
|
-
function getEventListenerWrapper(fnOrObj) {
|
|
1585
|
-
if (!isEventListenerOrEventListenerObject$1(fnOrObj)) {
|
|
1586
|
-
return fnOrObj;
|
|
1587
|
-
}
|
|
1588
|
-
let wrapperFn = EventListenerMap.get(fnOrObj);
|
|
1589
|
-
if (isUndefined(wrapperFn)) {
|
|
1590
|
-
wrapperFn = function (event) {
|
|
1591
|
-
// This function is invoked from an event listener and currentTarget is always defined.
|
|
1592
|
-
const currentTarget = eventCurrentTargetGetter.call(event);
|
|
1593
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1594
|
-
assert.invariant(isFalse(isSyntheticShadowHost(currentTarget)), 'This routine should not be used to wrap event listeners for host elements and shadow roots.');
|
|
1595
|
-
}
|
|
1596
|
-
const actualTarget = getActualTarget(event);
|
|
1597
|
-
if (!shouldInvokeListener(event, actualTarget, currentTarget)) {
|
|
1598
|
-
return;
|
|
1599
|
-
}
|
|
1600
|
-
return isFunction(fnOrObj)
|
|
1601
|
-
? fnOrObj.call(this, event)
|
|
1602
|
-
: fnOrObj.handleEvent && fnOrObj.handleEvent(event);
|
|
1603
|
-
};
|
|
1604
|
-
EventListenerMap.set(fnOrObj, wrapperFn);
|
|
1605
|
-
}
|
|
1606
|
-
return wrapperFn;
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
/*
|
|
1610
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1611
|
-
* All rights reserved.
|
|
1612
|
-
* SPDX-License-Identifier: MIT
|
|
1613
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1614
|
-
*/
|
|
1615
|
-
const eventToContextMap = new WeakMap();
|
|
1616
|
-
function getEventHandler(listener) {
|
|
1617
|
-
if (isFunction(listener)) {
|
|
1618
|
-
return listener;
|
|
1619
|
-
}
|
|
1620
|
-
else {
|
|
1621
|
-
return listener.handleEvent;
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
function isEventListenerOrEventListenerObject(listener) {
|
|
1625
|
-
return isFunction(listener) || isFunction(listener === null || listener === void 0 ? void 0 : listener.handleEvent);
|
|
1626
|
-
}
|
|
1627
|
-
const customElementToWrappedListeners = new WeakMap();
|
|
1628
|
-
function getEventMap(elm) {
|
|
1629
|
-
let listenerInfo = customElementToWrappedListeners.get(elm);
|
|
1630
|
-
if (isUndefined(listenerInfo)) {
|
|
1631
|
-
listenerInfo = create(null);
|
|
1632
|
-
customElementToWrappedListeners.set(elm, listenerInfo);
|
|
1633
|
-
}
|
|
1634
|
-
return listenerInfo;
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* Events dispatched on shadow roots actually end up being dispatched on their hosts. This means that the event.target
|
|
1638
|
-
* property of events dispatched on shadow roots always resolve to their host. This function understands this
|
|
1639
|
-
* abstraction and properly returns a reference to the shadow root when appropriate.
|
|
1640
|
-
*/
|
|
1641
|
-
function getActualTarget(event) {
|
|
1642
|
-
var _a;
|
|
1643
|
-
return (_a = eventToShadowRootMap.get(event)) !== null && _a !== void 0 ? _a : eventTargetGetter.call(event);
|
|
1644
|
-
}
|
|
1645
|
-
const shadowRootEventListenerMap = new WeakMap();
|
|
1646
|
-
function getManagedShadowRootListener(listener) {
|
|
1647
|
-
if (!isEventListenerOrEventListenerObject(listener)) {
|
|
1648
|
-
throw new TypeError(); // avoiding problems with non-valid listeners
|
|
1649
|
-
}
|
|
1650
|
-
let managedListener = shadowRootEventListenerMap.get(listener);
|
|
1651
|
-
if (isUndefined(managedListener)) {
|
|
1652
|
-
managedListener = {
|
|
1653
|
-
identity: listener,
|
|
1654
|
-
placement: 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */,
|
|
1655
|
-
handleEvent(event) {
|
|
1656
|
-
// currentTarget is always defined inside an event listener
|
|
1657
|
-
let currentTarget = eventCurrentTargetGetter.call(event);
|
|
1658
|
-
// If currentTarget is not an instance of a native shadow root then we're dealing with a
|
|
1659
|
-
// host element whose synthetic shadow root must be accessed via getShadowRoot().
|
|
1660
|
-
if (!isInstanceOfNativeShadowRoot(currentTarget)) {
|
|
1661
|
-
currentTarget = getShadowRoot(currentTarget);
|
|
1662
|
-
}
|
|
1663
|
-
const actualTarget = getActualTarget(event);
|
|
1664
|
-
if (shouldInvokeListener(event, actualTarget, currentTarget)) {
|
|
1665
|
-
getEventHandler(listener).call(currentTarget, event);
|
|
1666
|
-
}
|
|
1667
|
-
},
|
|
1668
|
-
};
|
|
1669
|
-
shadowRootEventListenerMap.set(listener, managedListener);
|
|
1670
|
-
}
|
|
1671
|
-
return managedListener;
|
|
1672
|
-
}
|
|
1673
|
-
const customElementEventListenerMap = new WeakMap();
|
|
1674
|
-
function getManagedCustomElementListener(listener) {
|
|
1675
|
-
if (!isEventListenerOrEventListenerObject(listener)) {
|
|
1676
|
-
throw new TypeError(); // avoiding problems with non-valid listeners
|
|
1677
|
-
}
|
|
1678
|
-
let managedListener = customElementEventListenerMap.get(listener);
|
|
1679
|
-
if (isUndefined(managedListener)) {
|
|
1680
|
-
managedListener = {
|
|
1681
|
-
identity: listener,
|
|
1682
|
-
placement: 0 /* EventListenerContext.CUSTOM_ELEMENT_LISTENER */,
|
|
1683
|
-
handleEvent(event) {
|
|
1684
|
-
// currentTarget is always defined inside an event listener
|
|
1685
|
-
const currentTarget = eventCurrentTargetGetter.call(event);
|
|
1686
|
-
const actualTarget = getActualTarget(event);
|
|
1687
|
-
if (shouldInvokeListener(event, actualTarget, currentTarget)) {
|
|
1688
|
-
getEventHandler(listener).call(currentTarget, event);
|
|
1689
|
-
}
|
|
1690
|
-
},
|
|
1691
|
-
};
|
|
1692
|
-
customElementEventListenerMap.set(listener, managedListener);
|
|
1693
|
-
}
|
|
1694
|
-
return managedListener;
|
|
1695
|
-
}
|
|
1696
|
-
function indexOfManagedListener(listeners, listener) {
|
|
1697
|
-
return ArrayFindIndex.call(listeners, (l) => l.identity === listener.identity);
|
|
1698
|
-
}
|
|
1699
|
-
function domListener(evt) {
|
|
1700
|
-
let immediatePropagationStopped = false;
|
|
1701
|
-
let propagationStopped = false;
|
|
1702
|
-
const { type, stopImmediatePropagation, stopPropagation } = evt;
|
|
1703
|
-
// currentTarget is always defined
|
|
1704
|
-
const currentTarget = eventCurrentTargetGetter.call(evt);
|
|
1705
|
-
const listenerMap = getEventMap(currentTarget);
|
|
1706
|
-
const listeners = listenerMap[type]; // it must have listeners at this point
|
|
1707
|
-
defineProperty(evt, 'stopImmediatePropagation', {
|
|
1708
|
-
value() {
|
|
1709
|
-
immediatePropagationStopped = true;
|
|
1710
|
-
stopImmediatePropagation.call(evt);
|
|
1711
|
-
},
|
|
1712
|
-
writable: true,
|
|
1713
|
-
enumerable: true,
|
|
1714
|
-
configurable: true,
|
|
1715
|
-
});
|
|
1716
|
-
defineProperty(evt, 'stopPropagation', {
|
|
1717
|
-
value() {
|
|
1718
|
-
propagationStopped = true;
|
|
1719
|
-
stopPropagation.call(evt);
|
|
1720
|
-
},
|
|
1721
|
-
writable: true,
|
|
1722
|
-
enumerable: true,
|
|
1723
|
-
configurable: true,
|
|
1724
|
-
});
|
|
1725
|
-
// in case a listener adds or removes other listeners during invocation
|
|
1726
|
-
const bookkeeping = ArraySlice.call(listeners);
|
|
1727
|
-
function invokeListenersByPlacement(placement) {
|
|
1728
|
-
forEach.call(bookkeeping, (listener) => {
|
|
1729
|
-
if (isFalse(immediatePropagationStopped) && listener.placement === placement) {
|
|
1730
|
-
// making sure that the listener was not removed from the original listener queue
|
|
1731
|
-
if (indexOfManagedListener(listeners, listener) !== -1) {
|
|
1732
|
-
// all handlers on the custom element should be called with undefined 'this'
|
|
1733
|
-
listener.handleEvent.call(undefined, evt);
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
});
|
|
1737
|
-
}
|
|
1738
|
-
eventToContextMap.set(evt, 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */);
|
|
1739
|
-
invokeListenersByPlacement(1 /* EventListenerContext.SHADOW_ROOT_LISTENER */);
|
|
1740
|
-
if (isFalse(immediatePropagationStopped) && isFalse(propagationStopped)) {
|
|
1741
|
-
// doing the second iteration only if the first one didn't interrupt the event propagation
|
|
1742
|
-
eventToContextMap.set(evt, 0 /* EventListenerContext.CUSTOM_ELEMENT_LISTENER */);
|
|
1743
|
-
invokeListenersByPlacement(0 /* EventListenerContext.CUSTOM_ELEMENT_LISTENER */);
|
|
1744
|
-
}
|
|
1745
|
-
eventToContextMap.set(evt, 2 /* EventListenerContext.UNKNOWN_LISTENER */);
|
|
1746
|
-
}
|
|
1747
|
-
function attachDOMListener(elm, type, managedListener) {
|
|
1748
|
-
const listenerMap = getEventMap(elm);
|
|
1749
|
-
let listeners = listenerMap[type];
|
|
1750
|
-
if (isUndefined(listeners)) {
|
|
1751
|
-
listeners = listenerMap[type] = [];
|
|
1752
|
-
}
|
|
1753
|
-
// Prevent identical listeners from subscribing to the same event type.
|
|
1754
|
-
// TODO [#1824]: Options will also play a factor in deduping if we introduce options support
|
|
1755
|
-
if (indexOfManagedListener(listeners, managedListener) !== -1) {
|
|
1756
|
-
return;
|
|
1757
|
-
}
|
|
1758
|
-
// only add to DOM if there is no other listener on the same placement yet
|
|
1759
|
-
if (listeners.length === 0) {
|
|
1760
|
-
addEventListener.call(elm, type, domListener);
|
|
1761
|
-
}
|
|
1762
|
-
ArrayPush.call(listeners, managedListener);
|
|
1763
|
-
}
|
|
1764
|
-
function detachDOMListener(elm, type, managedListener) {
|
|
1765
|
-
const listenerMap = getEventMap(elm);
|
|
1766
|
-
let index;
|
|
1767
|
-
let listeners;
|
|
1768
|
-
if (!isUndefined((listeners = listenerMap[type])) &&
|
|
1769
|
-
(index = indexOfManagedListener(listeners, managedListener)) !== -1) {
|
|
1770
|
-
ArraySplice.call(listeners, index, 1);
|
|
1771
|
-
// only remove from DOM if there is no other listener on the same placement
|
|
1772
|
-
if (listeners.length === 0) {
|
|
1773
|
-
removeEventListener.call(elm, type, domListener);
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
function addCustomElementEventListener(type, listener, _options) {
|
|
1778
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1779
|
-
if (!isEventListenerOrEventListenerObject(listener)) {
|
|
1780
|
-
throw new TypeError(`Invalid second argument for Element.addEventListener() in ${toString(this)} for event "${type}". Expected EventListener or EventListenerObject but received ${listener}.`);
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
if (isEventListenerOrEventListenerObject(listener)) {
|
|
1784
|
-
const managedListener = getManagedCustomElementListener(listener);
|
|
1785
|
-
attachDOMListener(this, type, managedListener);
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
function removeCustomElementEventListener(type, listener, _options) {
|
|
1789
|
-
if (isEventListenerOrEventListenerObject(listener)) {
|
|
1790
|
-
const managedListener = getManagedCustomElementListener(listener);
|
|
1791
|
-
detachDOMListener(this, type, managedListener);
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
function addShadowRootEventListener(sr, type, listener, _options) {
|
|
1795
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1796
|
-
if (!isEventListenerOrEventListenerObject(listener)) {
|
|
1797
|
-
throw new TypeError(`Invalid second argument for ShadowRoot.addEventListener() in ${toString(sr)} for event "${type}". Expected EventListener or EventListenerObject but received ${listener}.`);
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
|
-
if (isEventListenerOrEventListenerObject(listener)) {
|
|
1801
|
-
const elm = getHost(sr);
|
|
1802
|
-
const managedListener = getManagedShadowRootListener(listener);
|
|
1803
|
-
attachDOMListener(elm, type, managedListener);
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
function removeShadowRootEventListener(sr, type, listener, _options) {
|
|
1807
|
-
if (isEventListenerOrEventListenerObject(listener)) {
|
|
1808
|
-
const elm = getHost(sr);
|
|
1809
|
-
const managedListener = getManagedShadowRootListener(listener);
|
|
1810
|
-
detachDOMListener(elm, type, managedListener);
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
|
|
1814
|
-
/*
|
|
1815
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
1816
|
-
* All rights reserved.
|
|
1817
|
-
* SPDX-License-Identifier: MIT
|
|
1818
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
1819
|
-
*/
|
|
1820
|
-
const InternalSlot = new WeakMap();
|
|
1821
|
-
const { createDocumentFragment } = document;
|
|
1822
|
-
function hasInternalSlot(root) {
|
|
1823
|
-
return InternalSlot.has(root);
|
|
1824
|
-
}
|
|
1825
|
-
function getInternalSlot(root) {
|
|
1826
|
-
const record = InternalSlot.get(root);
|
|
1827
|
-
if (isUndefined(record)) {
|
|
1828
|
-
throw new TypeError();
|
|
1829
|
-
}
|
|
1830
|
-
return record;
|
|
1831
|
-
}
|
|
1832
|
-
defineProperty(_Node.prototype, KEY__SHADOW_RESOLVER, {
|
|
1833
|
-
set(fn) {
|
|
1834
|
-
if (isUndefined(fn))
|
|
1835
|
-
return;
|
|
1836
|
-
this[KEY__SHADOW_RESOLVER_PRIVATE] = fn;
|
|
1837
|
-
// TODO [#1164]: temporary propagation of the key
|
|
1838
|
-
setNodeOwnerKey(this, fn.nodeKey);
|
|
1839
|
-
},
|
|
1840
|
-
get() {
|
|
1841
|
-
return this[KEY__SHADOW_RESOLVER_PRIVATE];
|
|
1842
|
-
},
|
|
1843
|
-
configurable: true,
|
|
1844
|
-
enumerable: true,
|
|
1845
|
-
});
|
|
1846
|
-
defineProperty(_globalThis, KEY__IS_NATIVE_SHADOW_ROOT_DEFINED, {
|
|
1847
|
-
value: isNativeShadowRootDefined,
|
|
1848
|
-
});
|
|
1849
|
-
// The isUndefined check is because two copies of synthetic shadow may be loaded on the same page, and this
|
|
1850
|
-
// would throw an error if we tried to redefine it. Plus the whole point is to expose the native method.
|
|
1851
|
-
if (isUndefined(_globalThis[KEY__NATIVE_GET_ELEMENT_BY_ID])) {
|
|
1852
|
-
defineProperty(_globalThis, KEY__NATIVE_GET_ELEMENT_BY_ID, {
|
|
1853
|
-
value: getElementById,
|
|
1854
|
-
configurable: true,
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
|
-
// See note above.
|
|
1858
|
-
if (isUndefined(_globalThis[KEY__NATIVE_QUERY_SELECTOR_ALL])) {
|
|
1859
|
-
defineProperty(_globalThis, KEY__NATIVE_QUERY_SELECTOR_ALL, {
|
|
1860
|
-
value: querySelectorAll,
|
|
1861
|
-
configurable: true,
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
function getShadowRootResolver(node) {
|
|
1865
|
-
return node[KEY__SHADOW_RESOLVER];
|
|
1866
|
-
}
|
|
1867
|
-
function setShadowRootResolver(node, fn) {
|
|
1868
|
-
node[KEY__SHADOW_RESOLVER] = fn;
|
|
1869
|
-
}
|
|
1870
|
-
function isDelegatingFocus(host) {
|
|
1871
|
-
return getInternalSlot(host).delegatesFocus;
|
|
1872
|
-
}
|
|
1873
|
-
function getHost(root) {
|
|
1874
|
-
return getInternalSlot(root).host;
|
|
1875
|
-
}
|
|
1876
|
-
function getShadowRoot(elm) {
|
|
1877
|
-
return getInternalSlot(elm).shadowRoot;
|
|
1878
|
-
}
|
|
1879
|
-
// Intentionally adding `Node` here in addition to `Element` since this check is harmless for nodes
|
|
1880
|
-
// and we can avoid having to cast the type before calling this method in a few places.
|
|
1881
|
-
function isSyntheticShadowHost(node) {
|
|
1882
|
-
const shadowRootRecord = InternalSlot.get(node);
|
|
1883
|
-
return !isUndefined(shadowRootRecord) && node === shadowRootRecord.host;
|
|
1884
|
-
}
|
|
1885
|
-
function isSyntheticShadowRoot(node) {
|
|
1886
|
-
const shadowRootRecord = InternalSlot.get(node);
|
|
1887
|
-
return !isUndefined(shadowRootRecord) && node === shadowRootRecord.shadowRoot;
|
|
1888
|
-
}
|
|
1889
|
-
let uid = 0;
|
|
1890
|
-
function attachShadow(elm, options) {
|
|
1891
|
-
if (InternalSlot.has(elm)) {
|
|
1892
|
-
throw new Error(`Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree.`);
|
|
1893
|
-
}
|
|
1894
|
-
const { mode, delegatesFocus } = options;
|
|
1895
|
-
// creating a real fragment for shadowRoot instance
|
|
1896
|
-
const doc = getOwnerDocument(elm);
|
|
1897
|
-
const sr = createDocumentFragment.call(doc);
|
|
1898
|
-
// creating shadow internal record
|
|
1899
|
-
const record = {
|
|
1900
|
-
mode,
|
|
1901
|
-
delegatesFocus: !!delegatesFocus,
|
|
1902
|
-
host: elm,
|
|
1903
|
-
shadowRoot: sr,
|
|
1904
|
-
};
|
|
1905
|
-
InternalSlot.set(sr, record);
|
|
1906
|
-
InternalSlot.set(elm, record);
|
|
1907
|
-
const shadowResolver = () => sr;
|
|
1908
|
-
const x = (shadowResolver.nodeKey = uid++);
|
|
1909
|
-
setNodeKey(elm, x);
|
|
1910
|
-
setShadowRootResolver(sr, shadowResolver);
|
|
1911
|
-
// correcting the proto chain
|
|
1912
|
-
setPrototypeOf(sr, SyntheticShadowRoot.prototype);
|
|
1913
|
-
return sr;
|
|
1914
|
-
}
|
|
1915
|
-
const SyntheticShadowRootDescriptors = {
|
|
1916
|
-
constructor: {
|
|
1917
|
-
writable: true,
|
|
1918
|
-
configurable: true,
|
|
1919
|
-
value: SyntheticShadowRoot,
|
|
1920
|
-
},
|
|
1921
|
-
toString: {
|
|
1922
|
-
writable: true,
|
|
1923
|
-
configurable: true,
|
|
1924
|
-
value() {
|
|
1925
|
-
return `[object ShadowRoot]`;
|
|
1926
|
-
},
|
|
1927
|
-
},
|
|
1928
|
-
synthetic: {
|
|
1929
|
-
writable: false,
|
|
1930
|
-
enumerable: false,
|
|
1931
|
-
configurable: false,
|
|
1932
|
-
value: true,
|
|
1933
|
-
},
|
|
1934
|
-
};
|
|
1935
|
-
const ShadowRootDescriptors = {
|
|
1936
|
-
activeElement: {
|
|
1937
|
-
enumerable: true,
|
|
1938
|
-
configurable: true,
|
|
1939
|
-
get() {
|
|
1940
|
-
const host = getHost(this);
|
|
1941
|
-
const doc = getOwnerDocument(host);
|
|
1942
|
-
const activeElement = DocumentPrototypeActiveElement.call(doc);
|
|
1943
|
-
if (isNull(activeElement)) {
|
|
1944
|
-
return activeElement;
|
|
1945
|
-
}
|
|
1946
|
-
if ((compareDocumentPosition.call(host, activeElement) &
|
|
1947
|
-
DOCUMENT_POSITION_CONTAINED_BY) ===
|
|
1948
|
-
0) {
|
|
1949
|
-
return null;
|
|
1950
|
-
}
|
|
1951
|
-
// activeElement must be child of the host and owned by it
|
|
1952
|
-
let node = activeElement;
|
|
1953
|
-
while (!isNodeOwnedBy(host, node)) {
|
|
1954
|
-
// parentElement is always an element because we are talking up the tree knowing
|
|
1955
|
-
// that it is a child of the host.
|
|
1956
|
-
node = parentElementGetter.call(node);
|
|
1957
|
-
}
|
|
1958
|
-
// If we have a slot element here that means that we were dealing
|
|
1959
|
-
// with an element that was passed to one of our slots. In this
|
|
1960
|
-
// case, activeElement returns null.
|
|
1961
|
-
if (isSlotElement(node)) {
|
|
1962
|
-
return null;
|
|
1963
|
-
}
|
|
1964
|
-
return node;
|
|
1965
|
-
},
|
|
1966
|
-
},
|
|
1967
|
-
delegatesFocus: {
|
|
1968
|
-
configurable: true,
|
|
1969
|
-
get() {
|
|
1970
|
-
return getInternalSlot(this).delegatesFocus;
|
|
1971
|
-
},
|
|
1972
|
-
},
|
|
1973
|
-
elementFromPoint: {
|
|
1974
|
-
writable: true,
|
|
1975
|
-
enumerable: true,
|
|
1976
|
-
configurable: true,
|
|
1977
|
-
value(left, top) {
|
|
1978
|
-
const host = getHost(this);
|
|
1979
|
-
const doc = getOwnerDocument(host);
|
|
1980
|
-
return fauxElementFromPoint(this, doc, left, top);
|
|
1981
|
-
},
|
|
1982
|
-
},
|
|
1983
|
-
elementsFromPoint: {
|
|
1984
|
-
writable: true,
|
|
1985
|
-
enumerable: true,
|
|
1986
|
-
configurable: true,
|
|
1987
|
-
value(left, top) {
|
|
1988
|
-
const host = getHost(this);
|
|
1989
|
-
const doc = getOwnerDocument(host);
|
|
1990
|
-
return fauxElementsFromPoint(this, doc, left, top);
|
|
1991
|
-
},
|
|
1992
|
-
},
|
|
1993
|
-
getSelection: {
|
|
1994
|
-
writable: true,
|
|
1995
|
-
enumerable: true,
|
|
1996
|
-
configurable: true,
|
|
1997
|
-
value() {
|
|
1998
|
-
throw new Error('Disallowed method "getSelection" on ShadowRoot.');
|
|
1999
|
-
},
|
|
2000
|
-
},
|
|
2001
|
-
host: {
|
|
2002
|
-
enumerable: true,
|
|
2003
|
-
configurable: true,
|
|
2004
|
-
get() {
|
|
2005
|
-
return getHost(this);
|
|
2006
|
-
},
|
|
2007
|
-
},
|
|
2008
|
-
mode: {
|
|
2009
|
-
configurable: true,
|
|
2010
|
-
get() {
|
|
2011
|
-
return getInternalSlot(this).mode;
|
|
2012
|
-
},
|
|
2013
|
-
},
|
|
2014
|
-
styleSheets: {
|
|
2015
|
-
enumerable: true,
|
|
2016
|
-
configurable: true,
|
|
2017
|
-
get() {
|
|
2018
|
-
throw new Error();
|
|
2019
|
-
},
|
|
2020
|
-
},
|
|
2021
|
-
};
|
|
2022
|
-
const eventToShadowRootMap = new WeakMap();
|
|
2023
|
-
const NodePatchDescriptors = {
|
|
2024
|
-
insertBefore: {
|
|
2025
|
-
writable: true,
|
|
2026
|
-
enumerable: true,
|
|
2027
|
-
configurable: true,
|
|
2028
|
-
value(newChild, refChild) {
|
|
2029
|
-
insertBefore.call(getHost(this), newChild, refChild);
|
|
2030
|
-
return newChild;
|
|
2031
|
-
},
|
|
2032
|
-
},
|
|
2033
|
-
removeChild: {
|
|
2034
|
-
writable: true,
|
|
2035
|
-
enumerable: true,
|
|
2036
|
-
configurable: true,
|
|
2037
|
-
value(oldChild) {
|
|
2038
|
-
removeChild.call(getHost(this), oldChild);
|
|
2039
|
-
return oldChild;
|
|
2040
|
-
},
|
|
2041
|
-
},
|
|
2042
|
-
appendChild: {
|
|
2043
|
-
writable: true,
|
|
2044
|
-
enumerable: true,
|
|
2045
|
-
configurable: true,
|
|
2046
|
-
value(newChild) {
|
|
2047
|
-
appendChild.call(getHost(this), newChild);
|
|
2048
|
-
return newChild;
|
|
2049
|
-
},
|
|
2050
|
-
},
|
|
2051
|
-
replaceChild: {
|
|
2052
|
-
writable: true,
|
|
2053
|
-
enumerable: true,
|
|
2054
|
-
configurable: true,
|
|
2055
|
-
value(newChild, oldChild) {
|
|
2056
|
-
replaceChild.call(getHost(this), newChild, oldChild);
|
|
2057
|
-
return oldChild;
|
|
2058
|
-
},
|
|
2059
|
-
},
|
|
2060
|
-
addEventListener: {
|
|
2061
|
-
writable: true,
|
|
2062
|
-
enumerable: true,
|
|
2063
|
-
configurable: true,
|
|
2064
|
-
value(type, listener, options) {
|
|
2065
|
-
addShadowRootEventListener(this, type, listener);
|
|
2066
|
-
},
|
|
2067
|
-
},
|
|
2068
|
-
dispatchEvent: {
|
|
2069
|
-
writable: true,
|
|
2070
|
-
enumerable: true,
|
|
2071
|
-
configurable: true,
|
|
2072
|
-
value(evt) {
|
|
2073
|
-
eventToShadowRootMap.set(evt, this);
|
|
2074
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2075
|
-
// @ts-ignore type-mismatch
|
|
2076
|
-
return dispatchEvent.apply(getHost(this), arguments);
|
|
2077
|
-
},
|
|
2078
|
-
},
|
|
2079
|
-
removeEventListener: {
|
|
2080
|
-
writable: true,
|
|
2081
|
-
enumerable: true,
|
|
2082
|
-
configurable: true,
|
|
2083
|
-
value(type, listener, options) {
|
|
2084
|
-
removeShadowRootEventListener(this, type, listener);
|
|
2085
|
-
},
|
|
2086
|
-
},
|
|
2087
|
-
baseURI: {
|
|
2088
|
-
enumerable: true,
|
|
2089
|
-
configurable: true,
|
|
2090
|
-
get() {
|
|
2091
|
-
return getHost(this).baseURI;
|
|
2092
|
-
},
|
|
2093
|
-
},
|
|
2094
|
-
childNodes: {
|
|
2095
|
-
enumerable: true,
|
|
2096
|
-
configurable: true,
|
|
2097
|
-
get() {
|
|
2098
|
-
return createStaticNodeList(shadowRootChildNodes(this));
|
|
2099
|
-
},
|
|
2100
|
-
},
|
|
2101
|
-
cloneNode: {
|
|
2102
|
-
writable: true,
|
|
2103
|
-
enumerable: true,
|
|
2104
|
-
configurable: true,
|
|
2105
|
-
value() {
|
|
2106
|
-
throw new Error('Disallowed method "cloneNode" on ShadowRoot.');
|
|
2107
|
-
},
|
|
2108
|
-
},
|
|
2109
|
-
compareDocumentPosition: {
|
|
2110
|
-
writable: true,
|
|
2111
|
-
enumerable: true,
|
|
2112
|
-
configurable: true,
|
|
2113
|
-
value(otherNode) {
|
|
2114
|
-
const host = getHost(this);
|
|
2115
|
-
if (this === otherNode) {
|
|
2116
|
-
// "this" and "otherNode" are the same shadow root.
|
|
2117
|
-
return 0;
|
|
2118
|
-
}
|
|
2119
|
-
else if (this.contains(otherNode)) {
|
|
2120
|
-
// "otherNode" belongs to the shadow tree where "this" is the shadow root.
|
|
2121
|
-
return 20; // Node.DOCUMENT_POSITION_CONTAINED_BY | Node.DOCUMENT_POSITION_FOLLOWING
|
|
2122
|
-
}
|
|
2123
|
-
else if (compareDocumentPosition.call(host, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) {
|
|
2124
|
-
// "otherNode" is in a different shadow tree contained by the shadow tree where "this" is the shadow root.
|
|
2125
|
-
return 37; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_FOLLOWING | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
|
|
2126
|
-
}
|
|
2127
|
-
else {
|
|
2128
|
-
// "otherNode" is in a different shadow tree that is not contained by the shadow tree where "this" is the shadow root.
|
|
2129
|
-
return 35; // Node.DOCUMENT_POSITION_DISCONNECTED | Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
|
|
2130
|
-
}
|
|
2131
|
-
},
|
|
2132
|
-
},
|
|
2133
|
-
contains: {
|
|
2134
|
-
writable: true,
|
|
2135
|
-
enumerable: true,
|
|
2136
|
-
configurable: true,
|
|
2137
|
-
value(otherNode) {
|
|
2138
|
-
if (this === otherNode) {
|
|
2139
|
-
return true;
|
|
2140
|
-
}
|
|
2141
|
-
const host = getHost(this);
|
|
2142
|
-
// must be child of the host and owned by it.
|
|
2143
|
-
return ((compareDocumentPosition.call(host, otherNode) & DOCUMENT_POSITION_CONTAINED_BY) !==
|
|
2144
|
-
0 && isNodeOwnedBy(host, otherNode));
|
|
2145
|
-
},
|
|
2146
|
-
},
|
|
2147
|
-
firstChild: {
|
|
2148
|
-
enumerable: true,
|
|
2149
|
-
configurable: true,
|
|
2150
|
-
get() {
|
|
2151
|
-
const childNodes = getInternalChildNodes(this);
|
|
2152
|
-
return childNodes[0] || null;
|
|
2153
|
-
},
|
|
2154
|
-
},
|
|
2155
|
-
lastChild: {
|
|
2156
|
-
enumerable: true,
|
|
2157
|
-
configurable: true,
|
|
2158
|
-
get() {
|
|
2159
|
-
const childNodes = getInternalChildNodes(this);
|
|
2160
|
-
return childNodes[childNodes.length - 1] || null;
|
|
2161
|
-
},
|
|
2162
|
-
},
|
|
2163
|
-
hasChildNodes: {
|
|
2164
|
-
writable: true,
|
|
2165
|
-
enumerable: true,
|
|
2166
|
-
configurable: true,
|
|
2167
|
-
value() {
|
|
2168
|
-
const childNodes = getInternalChildNodes(this);
|
|
2169
|
-
return childNodes.length > 0;
|
|
2170
|
-
},
|
|
2171
|
-
},
|
|
2172
|
-
isConnected: {
|
|
2173
|
-
enumerable: true,
|
|
2174
|
-
configurable: true,
|
|
2175
|
-
get() {
|
|
2176
|
-
return isConnected.call(getHost(this));
|
|
2177
|
-
},
|
|
2178
|
-
},
|
|
2179
|
-
nextSibling: {
|
|
2180
|
-
enumerable: true,
|
|
2181
|
-
configurable: true,
|
|
2182
|
-
get() {
|
|
2183
|
-
return null;
|
|
2184
|
-
},
|
|
2185
|
-
},
|
|
2186
|
-
previousSibling: {
|
|
2187
|
-
enumerable: true,
|
|
2188
|
-
configurable: true,
|
|
2189
|
-
get() {
|
|
2190
|
-
return null;
|
|
2191
|
-
},
|
|
2192
|
-
},
|
|
2193
|
-
nodeName: {
|
|
2194
|
-
enumerable: true,
|
|
2195
|
-
configurable: true,
|
|
2196
|
-
get() {
|
|
2197
|
-
return '#document-fragment';
|
|
2198
|
-
},
|
|
2199
|
-
},
|
|
2200
|
-
nodeType: {
|
|
2201
|
-
enumerable: true,
|
|
2202
|
-
configurable: true,
|
|
2203
|
-
get() {
|
|
2204
|
-
return 11; // Node.DOCUMENT_FRAGMENT_NODE
|
|
2205
|
-
},
|
|
2206
|
-
},
|
|
2207
|
-
nodeValue: {
|
|
2208
|
-
enumerable: true,
|
|
2209
|
-
configurable: true,
|
|
2210
|
-
get() {
|
|
2211
|
-
return null;
|
|
2212
|
-
},
|
|
2213
|
-
},
|
|
2214
|
-
ownerDocument: {
|
|
2215
|
-
enumerable: true,
|
|
2216
|
-
configurable: true,
|
|
2217
|
-
get() {
|
|
2218
|
-
return getHost(this).ownerDocument;
|
|
2219
|
-
},
|
|
2220
|
-
},
|
|
2221
|
-
parentElement: {
|
|
2222
|
-
enumerable: true,
|
|
2223
|
-
configurable: true,
|
|
2224
|
-
get() {
|
|
2225
|
-
return null;
|
|
2226
|
-
},
|
|
2227
|
-
},
|
|
2228
|
-
parentNode: {
|
|
2229
|
-
enumerable: true,
|
|
2230
|
-
configurable: true,
|
|
2231
|
-
get() {
|
|
2232
|
-
return null;
|
|
2233
|
-
},
|
|
2234
|
-
},
|
|
2235
|
-
textContent: {
|
|
2236
|
-
enumerable: true,
|
|
2237
|
-
configurable: true,
|
|
2238
|
-
get() {
|
|
2239
|
-
const childNodes = getInternalChildNodes(this);
|
|
2240
|
-
let textContent = '';
|
|
2241
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
2242
|
-
const currentNode = childNodes[i];
|
|
2243
|
-
if (currentNode.nodeType !== COMMENT_NODE) {
|
|
2244
|
-
textContent += getTextContent(currentNode);
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
return textContent;
|
|
2248
|
-
},
|
|
2249
|
-
set(v) {
|
|
2250
|
-
const host = getHost(this);
|
|
2251
|
-
textContextSetter.call(host, v);
|
|
2252
|
-
},
|
|
2253
|
-
},
|
|
2254
|
-
// Since the synthetic shadow root is a detached DocumentFragment, short-circuit the getRootNode behavior
|
|
2255
|
-
getRootNode: {
|
|
2256
|
-
writable: true,
|
|
2257
|
-
enumerable: true,
|
|
2258
|
-
configurable: true,
|
|
2259
|
-
value(options) {
|
|
2260
|
-
return !isUndefined(options) && isTrue(options.composed)
|
|
2261
|
-
? getHost(this).getRootNode(options)
|
|
2262
|
-
: this;
|
|
2263
|
-
},
|
|
2264
|
-
},
|
|
2265
|
-
};
|
|
2266
|
-
const ElementPatchDescriptors = {
|
|
2267
|
-
innerHTML: {
|
|
2268
|
-
enumerable: true,
|
|
2269
|
-
configurable: true,
|
|
2270
|
-
get() {
|
|
2271
|
-
const childNodes = getInternalChildNodes(this);
|
|
2272
|
-
let innerHTML = '';
|
|
2273
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
2274
|
-
innerHTML += getOuterHTML(childNodes[i]);
|
|
2275
|
-
}
|
|
2276
|
-
return innerHTML;
|
|
2277
|
-
},
|
|
2278
|
-
set(v) {
|
|
2279
|
-
const host = getHost(this);
|
|
2280
|
-
innerHTMLSetter.call(host, v);
|
|
2281
|
-
},
|
|
2282
|
-
},
|
|
2283
|
-
};
|
|
2284
|
-
const ParentNodePatchDescriptors = {
|
|
2285
|
-
childElementCount: {
|
|
2286
|
-
enumerable: true,
|
|
2287
|
-
configurable: true,
|
|
2288
|
-
get() {
|
|
2289
|
-
return this.children.length;
|
|
2290
|
-
},
|
|
2291
|
-
},
|
|
2292
|
-
children: {
|
|
2293
|
-
enumerable: true,
|
|
2294
|
-
configurable: true,
|
|
2295
|
-
get() {
|
|
2296
|
-
return createStaticHTMLCollection(ArrayFilter.call(shadowRootChildNodes(this), (elm) => elm instanceof Element));
|
|
2297
|
-
},
|
|
2298
|
-
},
|
|
2299
|
-
firstElementChild: {
|
|
2300
|
-
enumerable: true,
|
|
2301
|
-
configurable: true,
|
|
2302
|
-
get() {
|
|
2303
|
-
return this.children[0] || null;
|
|
2304
|
-
},
|
|
2305
|
-
},
|
|
2306
|
-
lastElementChild: {
|
|
2307
|
-
enumerable: true,
|
|
2308
|
-
configurable: true,
|
|
2309
|
-
get() {
|
|
2310
|
-
const { children } = this;
|
|
2311
|
-
return children.item(children.length - 1) || null;
|
|
2312
|
-
},
|
|
2313
|
-
},
|
|
2314
|
-
getElementById: {
|
|
2315
|
-
writable: true,
|
|
2316
|
-
enumerable: true,
|
|
2317
|
-
configurable: true,
|
|
2318
|
-
value() {
|
|
2319
|
-
throw new Error('Disallowed method "getElementById" on ShadowRoot.');
|
|
2320
|
-
},
|
|
2321
|
-
},
|
|
2322
|
-
querySelector: {
|
|
2323
|
-
writable: true,
|
|
2324
|
-
enumerable: true,
|
|
2325
|
-
configurable: true,
|
|
2326
|
-
value(selectors) {
|
|
2327
|
-
return shadowRootQuerySelector(this, selectors);
|
|
2328
|
-
},
|
|
2329
|
-
},
|
|
2330
|
-
querySelectorAll: {
|
|
2331
|
-
writable: true,
|
|
2332
|
-
enumerable: true,
|
|
2333
|
-
configurable: true,
|
|
2334
|
-
value(selectors) {
|
|
2335
|
-
return createStaticNodeList(shadowRootQuerySelectorAll(this, selectors));
|
|
2336
|
-
},
|
|
2337
|
-
},
|
|
2338
|
-
};
|
|
2339
|
-
assign(SyntheticShadowRootDescriptors, NodePatchDescriptors, ParentNodePatchDescriptors, ElementPatchDescriptors, ShadowRootDescriptors);
|
|
2340
|
-
function SyntheticShadowRoot() {
|
|
2341
|
-
throw new TypeError('Illegal constructor');
|
|
2342
|
-
}
|
|
2343
|
-
SyntheticShadowRoot.prototype = create(DocumentFragment.prototype, SyntheticShadowRootDescriptors);
|
|
2344
|
-
// `this.shadowRoot instanceof ShadowRoot` should evaluate to true even for synthetic shadow
|
|
2345
|
-
defineProperty(SyntheticShadowRoot, Symbol.hasInstance, {
|
|
2346
|
-
value: function (object) {
|
|
2347
|
-
// Technically we should walk up the entire prototype chain, but with SyntheticShadowRoot
|
|
2348
|
-
// it's reasonable to assume that no one is doing any deep subclasses here.
|
|
2349
|
-
return (isObject(object) &&
|
|
2350
|
-
!isNull(object) &&
|
|
2351
|
-
(isInstanceOfNativeShadowRoot(object) ||
|
|
2352
|
-
getPrototypeOf(object) === SyntheticShadowRoot.prototype));
|
|
2353
|
-
},
|
|
2354
|
-
});
|
|
2355
|
-
/**
|
|
2356
|
-
* This method is only intended to be used in non-production mode in IE11
|
|
2357
|
-
* and its role is to produce a 1-1 mapping between a shadowRoot instance
|
|
2358
|
-
* and a comment node that is intended to use to trick the IE11 DevTools
|
|
2359
|
-
* to show the content of the shadowRoot in the DOM Explorer.
|
|
2360
|
-
*/
|
|
2361
|
-
function getIE11FakeShadowRootPlaceholder(host) {
|
|
2362
|
-
const shadowRoot = getShadowRoot(host);
|
|
2363
|
-
// @ts-ignore this $$placeholder$$ is not a security issue because you must
|
|
2364
|
-
// have access to the shadowRoot in order to extract the fake node, which give
|
|
2365
|
-
// you access to the same childNodes of the shadowRoot, so, who cares.
|
|
2366
|
-
let c = shadowRoot.$$placeholder$$;
|
|
2367
|
-
if (!isUndefined(c)) {
|
|
2368
|
-
return c;
|
|
2369
|
-
}
|
|
2370
|
-
const doc = getOwnerDocument(host);
|
|
2371
|
-
// @ts-ignore $$placeholder$$ is fine, read the node above.
|
|
2372
|
-
c = shadowRoot.$$placeholder$$ = createComment.call(doc, '');
|
|
2373
|
-
defineProperties(c, {
|
|
2374
|
-
childNodes: {
|
|
2375
|
-
get() {
|
|
2376
|
-
return shadowRoot.childNodes;
|
|
2377
|
-
},
|
|
2378
|
-
enumerable: true,
|
|
2379
|
-
configurable: true,
|
|
2380
|
-
},
|
|
2381
|
-
tagName: {
|
|
2382
|
-
get() {
|
|
2383
|
-
return `#shadow-root (${shadowRoot.mode})`;
|
|
2384
|
-
},
|
|
2385
|
-
enumerable: true,
|
|
2386
|
-
configurable: true,
|
|
2387
|
-
},
|
|
2388
|
-
});
|
|
2389
|
-
return c;
|
|
2390
|
-
}
|
|
2391
|
-
|
|
2392
|
-
/*
|
|
2393
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2394
|
-
* All rights reserved.
|
|
2395
|
-
* SPDX-License-Identifier: MIT
|
|
2396
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2397
|
-
*/
|
|
2398
|
-
/**
|
|
2399
|
-
@license
|
|
2400
|
-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
2401
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
2402
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
2403
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
2404
|
-
Code distributed by Google as part of the polymer project is also
|
|
2405
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
2406
|
-
*/
|
|
2407
|
-
function pathComposer(startNode, composed) {
|
|
2408
|
-
const composedPath = [];
|
|
2409
|
-
let startRoot;
|
|
2410
|
-
if (startNode instanceof Window) {
|
|
2411
|
-
startRoot = startNode;
|
|
2412
|
-
}
|
|
2413
|
-
else if (startNode instanceof _Node) {
|
|
2414
|
-
startRoot = startNode.getRootNode();
|
|
2415
|
-
}
|
|
2416
|
-
else {
|
|
2417
|
-
return composedPath;
|
|
2418
|
-
}
|
|
2419
|
-
let current = startNode;
|
|
2420
|
-
while (!isNull(current)) {
|
|
2421
|
-
composedPath.push(current);
|
|
2422
|
-
if (current instanceof Element || current instanceof Text) {
|
|
2423
|
-
const assignedSlot = current.assignedSlot;
|
|
2424
|
-
if (!isNull(assignedSlot)) {
|
|
2425
|
-
current = assignedSlot;
|
|
2426
|
-
}
|
|
2427
|
-
else {
|
|
2428
|
-
current = current.parentNode;
|
|
2429
|
-
}
|
|
2430
|
-
}
|
|
2431
|
-
else if ((isSyntheticShadowRoot(current) || isInstanceOfNativeShadowRoot(current)) &&
|
|
2432
|
-
(composed || current !== startRoot)) {
|
|
2433
|
-
current = current.host;
|
|
2434
|
-
}
|
|
2435
|
-
else if (current instanceof _Node) {
|
|
2436
|
-
current = current.parentNode;
|
|
2437
|
-
}
|
|
2438
|
-
else {
|
|
2439
|
-
// could be Window
|
|
2440
|
-
current = null;
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
let doc;
|
|
2444
|
-
if (startNode instanceof Window) {
|
|
2445
|
-
doc = startNode.document;
|
|
2446
|
-
}
|
|
2447
|
-
else {
|
|
2448
|
-
doc = getOwnerDocument(startNode);
|
|
2449
|
-
}
|
|
2450
|
-
// event composedPath includes window when startNode's ownerRoot is document
|
|
2451
|
-
if (composedPath[composedPath.length - 1] === doc) {
|
|
2452
|
-
composedPath.push(window);
|
|
2453
|
-
}
|
|
2454
|
-
return composedPath;
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
/*
|
|
2458
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2459
|
-
* All rights reserved.
|
|
2460
|
-
* SPDX-License-Identifier: MIT
|
|
2461
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2462
|
-
*/
|
|
2463
|
-
/**
|
|
2464
|
-
@license
|
|
2465
|
-
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
|
|
2466
|
-
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
|
|
2467
|
-
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
|
|
2468
|
-
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
|
|
2469
|
-
Code distributed by Google as part of the polymer project is also
|
|
2470
|
-
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
|
|
2471
|
-
*/
|
|
2472
|
-
function retarget(refNode, path) {
|
|
2473
|
-
if (isNull(refNode)) {
|
|
2474
|
-
return null;
|
|
2475
|
-
}
|
|
2476
|
-
// If ANCESTOR's root is not a shadow root or ANCESTOR's root is BASE's
|
|
2477
|
-
// shadow-including inclusive ancestor, return ANCESTOR.
|
|
2478
|
-
const refNodePath = pathComposer(refNode, true);
|
|
2479
|
-
const p$ = path;
|
|
2480
|
-
for (let i = 0, ancestor, lastRoot, root, rootIdx; i < p$.length; i++) {
|
|
2481
|
-
ancestor = p$[i];
|
|
2482
|
-
root = ancestor instanceof Window ? ancestor : ancestor.getRootNode();
|
|
2483
|
-
if (root !== lastRoot) {
|
|
2484
|
-
rootIdx = refNodePath.indexOf(root);
|
|
2485
|
-
lastRoot = root;
|
|
2486
|
-
}
|
|
2487
|
-
if (!isSyntheticShadowRoot(root) || (!isUndefined(rootIdx) && rootIdx > -1)) {
|
|
2488
|
-
return ancestor;
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2491
|
-
return null;
|
|
2492
|
-
}
|
|
2493
|
-
|
|
2494
|
-
/*
|
|
2495
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2496
|
-
* All rights reserved.
|
|
2497
|
-
* SPDX-License-Identifier: MIT
|
|
2498
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2499
|
-
*/
|
|
2500
|
-
function fauxElementFromPoint(context, doc, left, top) {
|
|
2501
|
-
const element = elementFromPoint.call(doc, left, top);
|
|
2502
|
-
if (isNull(element)) {
|
|
2503
|
-
return element;
|
|
2504
|
-
}
|
|
2505
|
-
return retarget(context, pathComposer(element, true));
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
/*
|
|
2509
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2510
|
-
* All rights reserved.
|
|
2511
|
-
* SPDX-License-Identifier: MIT
|
|
2512
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2513
|
-
*/
|
|
2514
|
-
function elemFromPoint(left, top) {
|
|
2515
|
-
return fauxElementFromPoint(this, this, left, top);
|
|
2516
|
-
}
|
|
2517
|
-
Document.prototype.elementFromPoint = elemFromPoint;
|
|
2518
|
-
function elemsFromPoint(left, top) {
|
|
2519
|
-
return fauxElementsFromPoint(this, this, left, top);
|
|
2520
|
-
}
|
|
2521
|
-
Document.prototype.elementsFromPoint = elemsFromPoint;
|
|
2522
|
-
// Go until we reach to top of the LWC tree
|
|
2523
|
-
defineProperty(Document.prototype, 'activeElement', {
|
|
2524
|
-
get() {
|
|
2525
|
-
let node = DocumentPrototypeActiveElement.call(this);
|
|
2526
|
-
if (isNull(node)) {
|
|
2527
|
-
return node;
|
|
2528
|
-
}
|
|
2529
|
-
while (!isUndefined(getNodeOwnerKey(node))) {
|
|
2530
|
-
node = parentElementGetter.call(node);
|
|
2531
|
-
if (isNull(node)) {
|
|
2532
|
-
return null;
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
if (node.tagName === 'HTML') {
|
|
2536
|
-
// IE 11. Active element should never be html element
|
|
2537
|
-
node = this.body;
|
|
2538
|
-
}
|
|
2539
|
-
return node;
|
|
2540
|
-
},
|
|
2541
|
-
enumerable: true,
|
|
2542
|
-
configurable: true,
|
|
2543
|
-
});
|
|
2544
|
-
// The following patched methods hide shadowed elements from global
|
|
2545
|
-
// traversing mechanisms. They are simplified for performance reasons to
|
|
2546
|
-
// filter by ownership and do not account for slotted elements. This
|
|
2547
|
-
// compromise is fine for our synthetic shadow dom because root elements
|
|
2548
|
-
// cannot have slotted elements.
|
|
2549
|
-
// Another compromise here is that all these traversing methods will return
|
|
2550
|
-
// static HTMLCollection or static NodeList. We decided that this compromise
|
|
2551
|
-
// is not a big problem considering the amount of code that is relying on
|
|
2552
|
-
// the liveliness of these results are rare.
|
|
2553
|
-
defineProperty(Document.prototype, 'getElementById', {
|
|
2554
|
-
value() {
|
|
2555
|
-
const elm = getElementById.apply(this, ArraySlice.call(arguments));
|
|
2556
|
-
if (isNull(elm)) {
|
|
2557
|
-
return null;
|
|
2558
|
-
}
|
|
2559
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2560
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2561
|
-
return isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm) ? elm : null;
|
|
2562
|
-
},
|
|
2563
|
-
writable: true,
|
|
2564
|
-
enumerable: true,
|
|
2565
|
-
configurable: true,
|
|
2566
|
-
});
|
|
2567
|
-
defineProperty(Document.prototype, 'querySelector', {
|
|
2568
|
-
value() {
|
|
2569
|
-
const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
|
|
2570
|
-
const filtered = ArrayFind.call(elements,
|
|
2571
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2572
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2573
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
|
|
2574
|
-
return !isUndefined(filtered) ? filtered : null;
|
|
2575
|
-
},
|
|
2576
|
-
writable: true,
|
|
2577
|
-
enumerable: true,
|
|
2578
|
-
configurable: true,
|
|
2579
|
-
});
|
|
2580
|
-
defineProperty(Document.prototype, 'querySelectorAll', {
|
|
2581
|
-
value() {
|
|
2582
|
-
const elements = arrayFromCollection(querySelectorAll.apply(this, ArraySlice.call(arguments)));
|
|
2583
|
-
const filtered = ArrayFilter.call(elements,
|
|
2584
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2585
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2586
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
|
|
2587
|
-
return createStaticNodeList(filtered);
|
|
2588
|
-
},
|
|
2589
|
-
writable: true,
|
|
2590
|
-
enumerable: true,
|
|
2591
|
-
configurable: true,
|
|
2592
|
-
});
|
|
2593
|
-
defineProperty(Document.prototype, 'getElementsByClassName', {
|
|
2594
|
-
value() {
|
|
2595
|
-
const elements = arrayFromCollection(getElementsByClassName.apply(this, ArraySlice.call(arguments)));
|
|
2596
|
-
const filtered = ArrayFilter.call(elements,
|
|
2597
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2598
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2599
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
|
|
2600
|
-
return createStaticHTMLCollection(filtered);
|
|
2601
|
-
},
|
|
2602
|
-
writable: true,
|
|
2603
|
-
enumerable: true,
|
|
2604
|
-
configurable: true,
|
|
2605
|
-
});
|
|
2606
|
-
defineProperty(Document.prototype, 'getElementsByTagName', {
|
|
2607
|
-
value() {
|
|
2608
|
-
const elements = arrayFromCollection(getElementsByTagName.apply(this, ArraySlice.call(arguments)));
|
|
2609
|
-
const filtered = ArrayFilter.call(elements,
|
|
2610
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2611
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2612
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
|
|
2613
|
-
return createStaticHTMLCollection(filtered);
|
|
2614
|
-
},
|
|
2615
|
-
writable: true,
|
|
2616
|
-
enumerable: true,
|
|
2617
|
-
configurable: true,
|
|
2618
|
-
});
|
|
2619
|
-
defineProperty(Document.prototype, 'getElementsByTagNameNS', {
|
|
2620
|
-
value() {
|
|
2621
|
-
const elements = arrayFromCollection(getElementsByTagNameNS.apply(this, ArraySlice.call(arguments)));
|
|
2622
|
-
const filtered = ArrayFilter.call(elements,
|
|
2623
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2624
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2625
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
|
|
2626
|
-
return createStaticHTMLCollection(filtered);
|
|
2627
|
-
},
|
|
2628
|
-
writable: true,
|
|
2629
|
-
enumerable: true,
|
|
2630
|
-
configurable: true,
|
|
2631
|
-
});
|
|
2632
|
-
defineProperty(
|
|
2633
|
-
// In Firefox v57 and lower, getElementsByName is defined on HTMLDocument.prototype
|
|
2634
|
-
getOwnPropertyDescriptor(HTMLDocument.prototype, 'getElementsByName')
|
|
2635
|
-
? HTMLDocument.prototype
|
|
2636
|
-
: Document.prototype, 'getElementsByName', {
|
|
2637
|
-
value() {
|
|
2638
|
-
const elements = arrayFromCollection(getElementsByName.apply(this, ArraySlice.call(arguments)));
|
|
2639
|
-
const filtered = ArrayFilter.call(elements,
|
|
2640
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
2641
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
2642
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(elm));
|
|
2643
|
-
return createStaticNodeList(filtered);
|
|
2644
|
-
},
|
|
2645
|
-
writable: true,
|
|
2646
|
-
enumerable: true,
|
|
2647
|
-
configurable: true,
|
|
2648
|
-
});
|
|
2649
|
-
|
|
2650
|
-
/*
|
|
2651
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2652
|
-
* All rights reserved.
|
|
2653
|
-
* SPDX-License-Identifier: MIT
|
|
2654
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2655
|
-
*/
|
|
2656
|
-
Object.defineProperty(window, 'ShadowRoot', {
|
|
2657
|
-
value: SyntheticShadowRoot,
|
|
2658
|
-
configurable: true,
|
|
2659
|
-
writable: true,
|
|
2660
|
-
});
|
|
2661
|
-
|
|
2662
|
-
/*
|
|
2663
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2664
|
-
* All rights reserved.
|
|
2665
|
-
* SPDX-License-Identifier: MIT
|
|
2666
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2667
|
-
*/
|
|
2668
|
-
const composedDescriptor = Object.getOwnPropertyDescriptor(Event.prototype, 'composed');
|
|
2669
|
-
function detect$3() {
|
|
2670
|
-
if (!composedDescriptor) {
|
|
2671
|
-
// No need to apply this polyfill if this client completely lacks
|
|
2672
|
-
// support for the composed property.
|
|
2673
|
-
return false;
|
|
2674
|
-
}
|
|
2675
|
-
// Assigning a throwaway click event here to suppress a ts error when we
|
|
2676
|
-
// pass clickEvent into the composed getter below. The error is:
|
|
2677
|
-
// [ts] Variable 'clickEvent' is used before being assigned.
|
|
2678
|
-
let clickEvent = new Event('click');
|
|
2679
|
-
const button = document.createElement('button');
|
|
2680
|
-
button.addEventListener('click', (event) => (clickEvent = event));
|
|
2681
|
-
button.click();
|
|
2682
|
-
return !composedDescriptor.get.call(clickEvent);
|
|
2683
|
-
}
|
|
2684
|
-
|
|
2685
|
-
/*
|
|
2686
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2687
|
-
* All rights reserved.
|
|
2688
|
-
* SPDX-License-Identifier: MIT
|
|
2689
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2690
|
-
*/
|
|
2691
|
-
const originalClickDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'click');
|
|
2692
|
-
function handleClick(event) {
|
|
2693
|
-
Object.defineProperty(event, 'composed', {
|
|
2694
|
-
configurable: true,
|
|
2695
|
-
enumerable: true,
|
|
2696
|
-
get() {
|
|
2697
|
-
return true;
|
|
2698
|
-
},
|
|
2699
|
-
});
|
|
2700
|
-
}
|
|
2701
|
-
function apply$3() {
|
|
2702
|
-
HTMLElement.prototype.click = function () {
|
|
2703
|
-
addEventListener.call(this, 'click', handleClick);
|
|
2704
|
-
try {
|
|
2705
|
-
originalClickDescriptor.value.call(this);
|
|
2706
|
-
}
|
|
2707
|
-
finally {
|
|
2708
|
-
removeEventListener.call(this, 'click', handleClick);
|
|
2709
|
-
}
|
|
2710
|
-
};
|
|
2711
|
-
}
|
|
2712
|
-
|
|
2713
|
-
/*
|
|
2714
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2715
|
-
* All rights reserved.
|
|
2716
|
-
* SPDX-License-Identifier: MIT
|
|
2717
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2718
|
-
*/
|
|
2719
|
-
if (detect$3()) {
|
|
2720
|
-
apply$3();
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
|
-
/*
|
|
2724
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2725
|
-
* All rights reserved.
|
|
2726
|
-
* SPDX-License-Identifier: MIT
|
|
2727
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2728
|
-
*/
|
|
2729
|
-
function detect$2() {
|
|
2730
|
-
return new Event('test', { composed: true }).composed !== true;
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
/*
|
|
2734
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2735
|
-
* All rights reserved.
|
|
2736
|
-
* SPDX-License-Identifier: MIT
|
|
2737
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2738
|
-
*/
|
|
2739
|
-
function apply$2() {
|
|
2740
|
-
// https://github.com/w3c/webcomponents/issues/513#issuecomment-224183937
|
|
2741
|
-
const composedEvents = assign(create(null), {
|
|
2742
|
-
beforeinput: 1,
|
|
2743
|
-
blur: 1,
|
|
2744
|
-
click: 1,
|
|
2745
|
-
compositionend: 1,
|
|
2746
|
-
compositionstart: 1,
|
|
2747
|
-
compositionupdate: 1,
|
|
2748
|
-
copy: 1,
|
|
2749
|
-
cut: 1,
|
|
2750
|
-
dblclick: 1,
|
|
2751
|
-
DOMActivate: 1,
|
|
2752
|
-
DOMFocusIn: 1,
|
|
2753
|
-
DOMFocusOut: 1,
|
|
2754
|
-
drag: 1,
|
|
2755
|
-
dragend: 1,
|
|
2756
|
-
dragenter: 1,
|
|
2757
|
-
dragleave: 1,
|
|
2758
|
-
dragover: 1,
|
|
2759
|
-
dragstart: 1,
|
|
2760
|
-
drop: 1,
|
|
2761
|
-
focus: 1,
|
|
2762
|
-
focusin: 1,
|
|
2763
|
-
focusout: 1,
|
|
2764
|
-
gotpointercapture: 1,
|
|
2765
|
-
input: 1,
|
|
2766
|
-
keydown: 1,
|
|
2767
|
-
keypress: 1,
|
|
2768
|
-
keyup: 1,
|
|
2769
|
-
lostpointercapture: 1,
|
|
2770
|
-
mousedown: 1,
|
|
2771
|
-
mouseenter: 1,
|
|
2772
|
-
mouseleave: 1,
|
|
2773
|
-
mousemove: 1,
|
|
2774
|
-
mouseout: 1,
|
|
2775
|
-
mouseover: 1,
|
|
2776
|
-
mouseup: 1,
|
|
2777
|
-
paste: 1,
|
|
2778
|
-
pointercancel: 1,
|
|
2779
|
-
pointerdown: 1,
|
|
2780
|
-
pointerenter: 1,
|
|
2781
|
-
pointerleave: 1,
|
|
2782
|
-
pointermove: 1,
|
|
2783
|
-
pointerout: 1,
|
|
2784
|
-
pointerover: 1,
|
|
2785
|
-
pointerup: 1,
|
|
2786
|
-
touchcancel: 1,
|
|
2787
|
-
touchend: 1,
|
|
2788
|
-
touchmove: 1,
|
|
2789
|
-
touchstart: 1,
|
|
2790
|
-
wheel: 1,
|
|
2791
|
-
});
|
|
2792
|
-
const EventConstructor = Event;
|
|
2793
|
-
// Patch Event constructor to add the composed property on events created via new Event.
|
|
2794
|
-
function PatchedEvent(type, eventInitDict) {
|
|
2795
|
-
const event = new EventConstructor(type, eventInitDict);
|
|
2796
|
-
const isComposed = !!(eventInitDict && eventInitDict.composed);
|
|
2797
|
-
Object.defineProperties(event, {
|
|
2798
|
-
composed: {
|
|
2799
|
-
get() {
|
|
2800
|
-
return isComposed;
|
|
2801
|
-
},
|
|
2802
|
-
configurable: true,
|
|
2803
|
-
enumerable: true,
|
|
2804
|
-
},
|
|
2805
|
-
});
|
|
2806
|
-
return event;
|
|
2807
|
-
}
|
|
2808
|
-
PatchedEvent.prototype = EventConstructor.prototype;
|
|
2809
|
-
PatchedEvent.AT_TARGET = EventConstructor.AT_TARGET;
|
|
2810
|
-
PatchedEvent.BUBBLING_PHASE = EventConstructor.BUBBLING_PHASE;
|
|
2811
|
-
PatchedEvent.CAPTURING_PHASE = EventConstructor.CAPTURING_PHASE;
|
|
2812
|
-
PatchedEvent.NONE = EventConstructor.NONE;
|
|
2813
|
-
window.Event = PatchedEvent;
|
|
2814
|
-
// Patch the Event prototype to add the composed property on user agent dispatched event.
|
|
2815
|
-
Object.defineProperties(Event.prototype, {
|
|
2816
|
-
composed: {
|
|
2817
|
-
get() {
|
|
2818
|
-
const { type } = this;
|
|
2819
|
-
return composedEvents[type] === 1;
|
|
2820
|
-
},
|
|
2821
|
-
configurable: true,
|
|
2822
|
-
enumerable: true,
|
|
2823
|
-
},
|
|
2824
|
-
});
|
|
2825
|
-
}
|
|
2826
|
-
|
|
2827
|
-
/*
|
|
2828
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2829
|
-
* All rights reserved.
|
|
2830
|
-
* SPDX-License-Identifier: MIT
|
|
2831
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2832
|
-
*/
|
|
2833
|
-
if (detect$2()) {
|
|
2834
|
-
apply$2();
|
|
2835
|
-
}
|
|
2836
|
-
|
|
2837
|
-
/*
|
|
2838
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2839
|
-
* All rights reserved.
|
|
2840
|
-
* SPDX-License-Identifier: MIT
|
|
2841
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2842
|
-
*/
|
|
2843
|
-
const CustomEventConstructor = CustomEvent;
|
|
2844
|
-
function PatchedCustomEvent(type, eventInitDict) {
|
|
2845
|
-
const event = new CustomEventConstructor(type, eventInitDict);
|
|
2846
|
-
const isComposed = !!(eventInitDict && eventInitDict.composed);
|
|
2847
|
-
Object.defineProperties(event, {
|
|
2848
|
-
composed: {
|
|
2849
|
-
get() {
|
|
2850
|
-
return isComposed;
|
|
2851
|
-
},
|
|
2852
|
-
configurable: true,
|
|
2853
|
-
enumerable: true,
|
|
2854
|
-
},
|
|
2855
|
-
});
|
|
2856
|
-
return event;
|
|
2857
|
-
}
|
|
2858
|
-
PatchedCustomEvent.prototype = CustomEventConstructor.prototype;
|
|
2859
|
-
window.CustomEvent = PatchedCustomEvent;
|
|
2860
|
-
|
|
2861
|
-
/*
|
|
2862
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2863
|
-
* All rights reserved.
|
|
2864
|
-
* SPDX-License-Identifier: MIT
|
|
2865
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2866
|
-
*/
|
|
2867
|
-
if (typeof ClipboardEvent !== 'undefined') {
|
|
2868
|
-
const isComposedType = assign(create(null), {
|
|
2869
|
-
copy: 1,
|
|
2870
|
-
cut: 1,
|
|
2871
|
-
paste: 1,
|
|
2872
|
-
});
|
|
2873
|
-
// Patch the prototype to override the composed property on user-agent dispatched events
|
|
2874
|
-
defineProperties(ClipboardEvent.prototype, {
|
|
2875
|
-
composed: {
|
|
2876
|
-
get() {
|
|
2877
|
-
const { type } = this;
|
|
2878
|
-
return isComposedType[type] === 1;
|
|
2879
|
-
},
|
|
2880
|
-
configurable: true,
|
|
2881
|
-
enumerable: true,
|
|
2882
|
-
},
|
|
2883
|
-
});
|
|
2884
|
-
}
|
|
2885
|
-
|
|
2886
|
-
/*
|
|
2887
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2888
|
-
* All rights reserved.
|
|
2889
|
-
* SPDX-License-Identifier: MIT
|
|
2890
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2891
|
-
*/
|
|
2892
|
-
function detect$1() {
|
|
2893
|
-
// Note: when using this in mobile apps, we might have a DOM that does not support iframes.
|
|
2894
|
-
const hasIframe = typeof HTMLIFrameElement !== 'undefined';
|
|
2895
|
-
// This polyfill should only apply in compat mode; see https://github.com/salesforce/lwc/issues/1513
|
|
2896
|
-
const isCompat = typeof Proxy !== 'undefined' && isTrue(Proxy.isCompat);
|
|
2897
|
-
return hasIframe && isCompat;
|
|
2898
|
-
}
|
|
2899
|
-
|
|
2900
|
-
/*
|
|
2901
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2902
|
-
* All rights reserved.
|
|
2903
|
-
* SPDX-License-Identifier: MIT
|
|
2904
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2905
|
-
*/
|
|
2906
|
-
function apply$1() {
|
|
2907
|
-
// the iframe property descriptor for `contentWindow` should always be available, otherwise this method should never be called
|
|
2908
|
-
const desc = getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow');
|
|
2909
|
-
const { get: originalGetter } = desc;
|
|
2910
|
-
desc.get = function () {
|
|
2911
|
-
const original = originalGetter.call(this);
|
|
2912
|
-
// If the original iframe element is not a keyed node, then do not wrap it
|
|
2913
|
-
if (isNull(original) || isUndefined(getNodeOwnerKey(this))) {
|
|
2914
|
-
return original;
|
|
2915
|
-
}
|
|
2916
|
-
// only if the element is an iframe inside a shadowRoot, we care about this problem
|
|
2917
|
-
// because in that case, the code that is accessing the iframe, is very likely code
|
|
2918
|
-
// compiled with proxy-compat transformation. It is true that other code without those
|
|
2919
|
-
// transformations might also access an iframe from within a shadowRoot, but in that,
|
|
2920
|
-
// case, which is more rare, we still return the wrapper, and it should work the same,
|
|
2921
|
-
// this part is just an optimization.
|
|
2922
|
-
return wrapIframeWindow(original);
|
|
2923
|
-
};
|
|
2924
|
-
defineProperty(HTMLIFrameElement.prototype, 'contentWindow', desc);
|
|
2925
|
-
}
|
|
2926
|
-
function wrapIframeWindow(win) {
|
|
2927
|
-
return {
|
|
2928
|
-
addEventListener() {
|
|
2929
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2930
|
-
// @ts-ignore type-mismatch
|
|
2931
|
-
return win.addEventListener.apply(win, arguments);
|
|
2932
|
-
},
|
|
2933
|
-
blur() {
|
|
2934
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2935
|
-
// @ts-ignore type-mismatch
|
|
2936
|
-
return win.blur.apply(win, arguments);
|
|
2937
|
-
},
|
|
2938
|
-
close() {
|
|
2939
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2940
|
-
// @ts-ignore type-mismatch
|
|
2941
|
-
return win.close.apply(win, arguments);
|
|
2942
|
-
},
|
|
2943
|
-
focus() {
|
|
2944
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2945
|
-
// @ts-ignore type-mismatch
|
|
2946
|
-
return win.focus.apply(win, arguments);
|
|
2947
|
-
},
|
|
2948
|
-
postMessage() {
|
|
2949
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2950
|
-
// @ts-ignore type-mismatch
|
|
2951
|
-
return win.postMessage.apply(win, arguments);
|
|
2952
|
-
},
|
|
2953
|
-
removeEventListener() {
|
|
2954
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
2955
|
-
// @ts-ignore type-mismatch
|
|
2956
|
-
return win.removeEventListener.apply(win, arguments);
|
|
2957
|
-
},
|
|
2958
|
-
get closed() {
|
|
2959
|
-
return win.closed;
|
|
2960
|
-
},
|
|
2961
|
-
get frames() {
|
|
2962
|
-
return win.frames;
|
|
2963
|
-
},
|
|
2964
|
-
get length() {
|
|
2965
|
-
return win.length;
|
|
2966
|
-
},
|
|
2967
|
-
get location() {
|
|
2968
|
-
return win.location;
|
|
2969
|
-
},
|
|
2970
|
-
set location(value) {
|
|
2971
|
-
win.location = value;
|
|
2972
|
-
},
|
|
2973
|
-
get opener() {
|
|
2974
|
-
return win.opener;
|
|
2975
|
-
},
|
|
2976
|
-
get parent() {
|
|
2977
|
-
return win.parent;
|
|
2978
|
-
},
|
|
2979
|
-
get self() {
|
|
2980
|
-
return win.self;
|
|
2981
|
-
},
|
|
2982
|
-
get top() {
|
|
2983
|
-
return win.top;
|
|
2984
|
-
},
|
|
2985
|
-
get window() {
|
|
2986
|
-
return win.window;
|
|
2987
|
-
},
|
|
2988
|
-
}; // this is limited
|
|
2989
|
-
}
|
|
2990
|
-
|
|
2991
|
-
/*
|
|
2992
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
2993
|
-
* All rights reserved.
|
|
2994
|
-
* SPDX-License-Identifier: MIT
|
|
2995
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
2996
|
-
*/
|
|
2997
|
-
if (detect$1()) {
|
|
2998
|
-
apply$1();
|
|
2999
|
-
}
|
|
3000
|
-
|
|
3001
|
-
/*
|
|
3002
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3003
|
-
* All rights reserved.
|
|
3004
|
-
* SPDX-License-Identifier: MIT
|
|
3005
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3006
|
-
*/
|
|
3007
|
-
const OriginalMutationObserver = MutationObserver;
|
|
3008
|
-
const { disconnect: originalDisconnect, observe: originalObserve, takeRecords: originalTakeRecords, } = OriginalMutationObserver.prototype;
|
|
3009
|
-
// Internal fields to maintain relationships
|
|
3010
|
-
const wrapperLookupField = '$$lwcObserverCallbackWrapper$$';
|
|
3011
|
-
const observerLookupField = '$$lwcNodeObservers$$';
|
|
3012
|
-
const observerToNodesMap = new WeakMap();
|
|
3013
|
-
function getNodeObservers(node) {
|
|
3014
|
-
return node[observerLookupField];
|
|
3015
|
-
}
|
|
3016
|
-
function setNodeObservers(node, observers) {
|
|
3017
|
-
node[observerLookupField] = observers;
|
|
3018
|
-
}
|
|
3019
|
-
/**
|
|
3020
|
-
* Retarget the mutation record's target value to its shadowRoot
|
|
3021
|
-
* @param {MutationRecord} originalRecord
|
|
3022
|
-
*/
|
|
3023
|
-
function retargetMutationRecord(originalRecord) {
|
|
3024
|
-
const { addedNodes, removedNodes, target, type } = originalRecord;
|
|
3025
|
-
const retargetedRecord = create(MutationRecord.prototype);
|
|
3026
|
-
defineProperties(retargetedRecord, {
|
|
3027
|
-
addedNodes: {
|
|
3028
|
-
get() {
|
|
3029
|
-
return addedNodes;
|
|
3030
|
-
},
|
|
3031
|
-
enumerable: true,
|
|
3032
|
-
configurable: true,
|
|
3033
|
-
},
|
|
3034
|
-
removedNodes: {
|
|
3035
|
-
get() {
|
|
3036
|
-
return removedNodes;
|
|
3037
|
-
},
|
|
3038
|
-
enumerable: true,
|
|
3039
|
-
configurable: true,
|
|
3040
|
-
},
|
|
3041
|
-
type: {
|
|
3042
|
-
get() {
|
|
3043
|
-
return type;
|
|
3044
|
-
},
|
|
3045
|
-
enumerable: true,
|
|
3046
|
-
configurable: true,
|
|
3047
|
-
},
|
|
3048
|
-
target: {
|
|
3049
|
-
get() {
|
|
3050
|
-
return target.shadowRoot;
|
|
3051
|
-
},
|
|
3052
|
-
enumerable: true,
|
|
3053
|
-
configurable: true,
|
|
3054
|
-
},
|
|
3055
|
-
});
|
|
3056
|
-
return retargetedRecord;
|
|
3057
|
-
}
|
|
3058
|
-
/**
|
|
3059
|
-
* Utility to identify if a target node is being observed by the given observer
|
|
3060
|
-
* Start at the current node, if the observer is registered to observe the current node, the mutation qualifies
|
|
3061
|
-
* @param {MutationObserver} observer
|
|
3062
|
-
* @param {Node} target
|
|
3063
|
-
*/
|
|
3064
|
-
function isQualifiedObserver(observer, target) {
|
|
3065
|
-
let parentNode = target;
|
|
3066
|
-
while (!isNull(parentNode)) {
|
|
3067
|
-
const parentNodeObservers = getNodeObservers(parentNode);
|
|
3068
|
-
if (!isUndefined(parentNodeObservers) &&
|
|
3069
|
-
(parentNodeObservers[0] === observer || // perf optimization to check for the first item is a match
|
|
3070
|
-
ArrayIndexOf.call(parentNodeObservers, observer) !== -1)) {
|
|
3071
|
-
return true;
|
|
3072
|
-
}
|
|
3073
|
-
parentNode = parentNode.parentNode;
|
|
3074
|
-
}
|
|
3075
|
-
return false;
|
|
3076
|
-
}
|
|
3077
|
-
/**
|
|
3078
|
-
* This function provides a shadow dom compliant filtered view of mutation records for a given observer.
|
|
3079
|
-
*
|
|
3080
|
-
* The key logic here is to determine if a given observer has been registered to observe any nodes
|
|
3081
|
-
* between the target node of a mutation record to the target's root node.
|
|
3082
|
-
* This function also retargets records when mutations occur directly under the shadow root
|
|
3083
|
-
* @param {MutationRecords[]} mutations
|
|
3084
|
-
* @param {MutationObserver} observer
|
|
3085
|
-
*/
|
|
3086
|
-
function filterMutationRecords(mutations, observer) {
|
|
3087
|
-
return ArrayReduce.call(mutations, (filteredSet, record) => {
|
|
3088
|
-
const { target, addedNodes, removedNodes, type } = record;
|
|
3089
|
-
// If target is an lwc host,
|
|
3090
|
-
// Determine if the mutations affected the host or the shadowRoot
|
|
3091
|
-
// Mutations affecting host: changes to slot content
|
|
3092
|
-
// Mutations affecting shadowRoot: changes to template content
|
|
3093
|
-
if (type === 'childList' && !isUndefined(getNodeKey(target))) {
|
|
3094
|
-
// In case of added nodes, we can climb up the tree and determine eligibility
|
|
3095
|
-
if (addedNodes.length > 0) {
|
|
3096
|
-
// Optimization: Peek in and test one node to decide if the MutationRecord qualifies
|
|
3097
|
-
// The remaining nodes in this MutationRecord will have the same ownerKey
|
|
3098
|
-
const sampleNode = addedNodes[0];
|
|
3099
|
-
if (isQualifiedObserver(observer, sampleNode)) {
|
|
3100
|
-
// If the target was being observed, then return record as-is
|
|
3101
|
-
// this will be the case for slot content
|
|
3102
|
-
const nodeObservers = getNodeObservers(target);
|
|
3103
|
-
if (nodeObservers &&
|
|
3104
|
-
(nodeObservers[0] === observer ||
|
|
3105
|
-
ArrayIndexOf.call(nodeObservers, observer) !== -1)) {
|
|
3106
|
-
ArrayPush.call(filteredSet, record);
|
|
3107
|
-
}
|
|
3108
|
-
else {
|
|
3109
|
-
// else, must be observing the shadowRoot
|
|
3110
|
-
ArrayPush.call(filteredSet, retargetMutationRecord(record));
|
|
3111
|
-
}
|
|
3112
|
-
}
|
|
3113
|
-
}
|
|
3114
|
-
else {
|
|
3115
|
-
// In the case of removed nodes, climbing the tree is not an option as the nodes are disconnected
|
|
3116
|
-
// We can only check if either the host or shadow root was observed and qualify the record
|
|
3117
|
-
const shadowRoot = target.shadowRoot;
|
|
3118
|
-
const sampleNode = removedNodes[0];
|
|
3119
|
-
if (getNodeNearestOwnerKey(target) === getNodeNearestOwnerKey(sampleNode) && // trickery: sampleNode is slot content
|
|
3120
|
-
isQualifiedObserver(observer, target) // use target as a close enough reference to climb up
|
|
3121
|
-
) {
|
|
3122
|
-
ArrayPush.call(filteredSet, record);
|
|
3123
|
-
}
|
|
3124
|
-
else if (shadowRoot) {
|
|
3125
|
-
const shadowRootObservers = getNodeObservers(shadowRoot);
|
|
3126
|
-
if (shadowRootObservers &&
|
|
3127
|
-
(shadowRootObservers[0] === observer ||
|
|
3128
|
-
ArrayIndexOf.call(shadowRootObservers, observer) !== -1)) {
|
|
3129
|
-
ArrayPush.call(filteredSet, retargetMutationRecord(record));
|
|
3130
|
-
}
|
|
3131
|
-
}
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3134
|
-
else {
|
|
3135
|
-
// Mutation happened under a root node(shadow root or document) and the decision is straighforward
|
|
3136
|
-
// Ascend the tree starting from target and check if observer is qualified
|
|
3137
|
-
if (isQualifiedObserver(observer, target)) {
|
|
3138
|
-
ArrayPush.call(filteredSet, record);
|
|
3139
|
-
}
|
|
3140
|
-
}
|
|
3141
|
-
return filteredSet;
|
|
3142
|
-
}, []);
|
|
3143
|
-
}
|
|
3144
|
-
function getWrappedCallback(callback) {
|
|
3145
|
-
let wrappedCallback = callback[wrapperLookupField];
|
|
3146
|
-
if (isUndefined(wrappedCallback)) {
|
|
3147
|
-
wrappedCallback = callback[wrapperLookupField] = (mutations, observer) => {
|
|
3148
|
-
// Filter mutation records
|
|
3149
|
-
const filteredRecords = filterMutationRecords(mutations, observer);
|
|
3150
|
-
// If not records are eligible for the observer, do not invoke callback
|
|
3151
|
-
if (filteredRecords.length === 0) {
|
|
3152
|
-
return;
|
|
3153
|
-
}
|
|
3154
|
-
callback.call(observer, filteredRecords, observer);
|
|
3155
|
-
};
|
|
3156
|
-
}
|
|
3157
|
-
return wrappedCallback;
|
|
3158
|
-
}
|
|
3159
|
-
/**
|
|
3160
|
-
* Patched MutationObserver constructor.
|
|
3161
|
-
* 1. Wrap the callback to filter out MutationRecords based on dom ownership
|
|
3162
|
-
* 2. Add a property field to track all observed targets of the observer instance
|
|
3163
|
-
* @param {MutationCallback} callback
|
|
3164
|
-
*/
|
|
3165
|
-
function PatchedMutationObserver(callback) {
|
|
3166
|
-
const wrappedCallback = getWrappedCallback(callback);
|
|
3167
|
-
const observer = new OriginalMutationObserver(wrappedCallback);
|
|
3168
|
-
return observer;
|
|
3169
|
-
}
|
|
3170
|
-
function patchedDisconnect() {
|
|
3171
|
-
originalDisconnect.call(this);
|
|
3172
|
-
// Clear the node to observer reference which is a strong references
|
|
3173
|
-
const observedNodes = observerToNodesMap.get(this);
|
|
3174
|
-
if (!isUndefined(observedNodes)) {
|
|
3175
|
-
forEach.call(observedNodes, (observedNode) => {
|
|
3176
|
-
const observers = observedNode[observerLookupField];
|
|
3177
|
-
if (!isUndefined(observers)) {
|
|
3178
|
-
const index = ArrayIndexOf.call(observers, this);
|
|
3179
|
-
if (index !== -1) {
|
|
3180
|
-
ArraySplice.call(observers, index, 1);
|
|
3181
|
-
}
|
|
3182
|
-
}
|
|
3183
|
-
});
|
|
3184
|
-
observedNodes.length = 0;
|
|
3185
|
-
}
|
|
3186
|
-
}
|
|
3187
|
-
/**
|
|
3188
|
-
* A single mutation observer can observe multiple nodes(target).
|
|
3189
|
-
* Maintain a list of all targets that the observer chooses to observe
|
|
3190
|
-
* @param {Node} target
|
|
3191
|
-
* @param {Object} options
|
|
3192
|
-
*/
|
|
3193
|
-
function patchedObserve(target, options) {
|
|
3194
|
-
let targetObservers = getNodeObservers(target);
|
|
3195
|
-
// Maintain a list of all observers that want to observe a node
|
|
3196
|
-
if (isUndefined(targetObservers)) {
|
|
3197
|
-
targetObservers = [];
|
|
3198
|
-
setNodeObservers(target, targetObservers);
|
|
3199
|
-
}
|
|
3200
|
-
// Same observer trying to observe the same node
|
|
3201
|
-
if (ArrayIndexOf.call(targetObservers, this) === -1) {
|
|
3202
|
-
ArrayPush.call(targetObservers, this);
|
|
3203
|
-
} // else There is more bookkeeping to do here https://dom.spec.whatwg.org/#dom-mutationobserver-observe Step #7
|
|
3204
|
-
// SyntheticShadowRoot instances are not actually a part of the DOM so observe the host instead.
|
|
3205
|
-
if (isSyntheticShadowRoot(target)) {
|
|
3206
|
-
target = target.host;
|
|
3207
|
-
}
|
|
3208
|
-
// maintain a list of all nodes observed by this observer
|
|
3209
|
-
if (observerToNodesMap.has(this)) {
|
|
3210
|
-
const observedNodes = observerToNodesMap.get(this);
|
|
3211
|
-
if (ArrayIndexOf.call(observedNodes, target) === -1) {
|
|
3212
|
-
ArrayPush.call(observedNodes, target);
|
|
3213
|
-
}
|
|
3214
|
-
}
|
|
3215
|
-
else {
|
|
3216
|
-
observerToNodesMap.set(this, [target]);
|
|
3217
|
-
}
|
|
3218
|
-
return originalObserve.call(this, target, options);
|
|
3219
|
-
}
|
|
3220
|
-
/**
|
|
3221
|
-
* Patch the takeRecords() api to filter MutationRecords based on the observed targets
|
|
3222
|
-
*/
|
|
3223
|
-
function patchedTakeRecords() {
|
|
3224
|
-
return filterMutationRecords(originalTakeRecords.call(this), this);
|
|
3225
|
-
}
|
|
3226
|
-
PatchedMutationObserver.prototype = OriginalMutationObserver.prototype;
|
|
3227
|
-
PatchedMutationObserver.prototype.disconnect = patchedDisconnect;
|
|
3228
|
-
PatchedMutationObserver.prototype.observe = patchedObserve;
|
|
3229
|
-
PatchedMutationObserver.prototype.takeRecords = patchedTakeRecords;
|
|
3230
|
-
defineProperty(window, 'MutationObserver', {
|
|
3231
|
-
value: PatchedMutationObserver,
|
|
3232
|
-
configurable: true,
|
|
3233
|
-
writable: true,
|
|
3234
|
-
});
|
|
3235
|
-
|
|
3236
|
-
/*
|
|
3237
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3238
|
-
* All rights reserved.
|
|
3239
|
-
* SPDX-License-Identifier: MIT
|
|
3240
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3241
|
-
*/
|
|
3242
|
-
function patchedAddEventListener$1(type, listener, optionsOrCapture) {
|
|
3243
|
-
if (isSyntheticShadowHost(this)) {
|
|
3244
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
3245
|
-
// @ts-ignore type-mismatch
|
|
3246
|
-
return addCustomElementEventListener.apply(this, arguments);
|
|
3247
|
-
}
|
|
3248
|
-
if (arguments.length < 2) {
|
|
3249
|
-
// Slow path, unlikely to be called frequently. We expect modern browsers to throw:
|
|
3250
|
-
// https://googlechrome.github.io/samples/event-listeners-mandatory-arguments/
|
|
3251
|
-
const args = ArraySlice.call(arguments);
|
|
3252
|
-
if (args.length > 1) {
|
|
3253
|
-
args[1] = getEventListenerWrapper(args[1]);
|
|
3254
|
-
}
|
|
3255
|
-
// Ignore types because we're passing through to native method
|
|
3256
|
-
// @ts-ignore type-mismatch
|
|
3257
|
-
return addEventListener.apply(this, args);
|
|
3258
|
-
}
|
|
3259
|
-
// Fast path. This function is optimized to avoid ArraySlice because addEventListener is called
|
|
3260
|
-
// very frequently, and it provides a measurable perf boost to avoid so much array cloning.
|
|
3261
|
-
const wrappedListener = getEventListenerWrapper(listener);
|
|
3262
|
-
// The third argument is optional, so passing in `undefined` for `optionsOrCapture` gives capture=false
|
|
3263
|
-
return addEventListener.call(this, type, wrappedListener, optionsOrCapture);
|
|
3264
|
-
}
|
|
3265
|
-
function patchedRemoveEventListener$1(_type, _listener, _optionsOrCapture) {
|
|
3266
|
-
if (isSyntheticShadowHost(this)) {
|
|
3267
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
3268
|
-
// @ts-ignore type-mismatch
|
|
3269
|
-
return removeCustomElementEventListener.apply(this, arguments);
|
|
3270
|
-
}
|
|
3271
|
-
const args = ArraySlice.call(arguments);
|
|
3272
|
-
if (arguments.length > 1) {
|
|
3273
|
-
args[1] = getEventListenerWrapper(args[1]);
|
|
3274
|
-
}
|
|
3275
|
-
// Ignore types because we're passing through to native method
|
|
3276
|
-
// @ts-ignore type-mismatch
|
|
3277
|
-
removeEventListener.apply(this, args);
|
|
3278
|
-
// Account for listeners that were added before this polyfill was applied
|
|
3279
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
3280
|
-
// @ts-ignore type-mismatch
|
|
3281
|
-
removeEventListener.apply(this, arguments);
|
|
3282
|
-
}
|
|
3283
|
-
defineProperties(eventTargetPrototype, {
|
|
3284
|
-
addEventListener: {
|
|
3285
|
-
value: patchedAddEventListener$1,
|
|
3286
|
-
enumerable: true,
|
|
3287
|
-
writable: true,
|
|
3288
|
-
configurable: true,
|
|
3289
|
-
},
|
|
3290
|
-
removeEventListener: {
|
|
3291
|
-
value: patchedRemoveEventListener$1,
|
|
3292
|
-
enumerable: true,
|
|
3293
|
-
writable: true,
|
|
3294
|
-
configurable: true,
|
|
3295
|
-
},
|
|
3296
|
-
});
|
|
3297
|
-
|
|
3298
|
-
/*
|
|
3299
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3300
|
-
* All rights reserved.
|
|
3301
|
-
* SPDX-License-Identifier: MIT
|
|
3302
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3303
|
-
*/
|
|
3304
|
-
function detect() {
|
|
3305
|
-
return typeof EventTarget === 'undefined';
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
/*
|
|
3309
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3310
|
-
* All rights reserved.
|
|
3311
|
-
* SPDX-License-Identifier: MIT
|
|
3312
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3313
|
-
*/
|
|
3314
|
-
function patchedAddEventListener(_type, _listener, _options) {
|
|
3315
|
-
if (arguments.length > 1) {
|
|
3316
|
-
const args = ArraySlice.call(arguments);
|
|
3317
|
-
args[1] = getEventListenerWrapper(args[1]);
|
|
3318
|
-
// Ignore types because we're passing through to native method
|
|
3319
|
-
// @ts-ignore type-mismatch
|
|
3320
|
-
return windowAddEventListener.apply(this, args);
|
|
3321
|
-
}
|
|
3322
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
3323
|
-
// @ts-ignore type-mismatch
|
|
3324
|
-
return windowAddEventListener.apply(this, arguments);
|
|
3325
|
-
}
|
|
3326
|
-
function patchedRemoveEventListener(_type, _listener, _options) {
|
|
3327
|
-
if (arguments.length > 1) {
|
|
3328
|
-
const args = ArraySlice.call(arguments);
|
|
3329
|
-
args[1] = getEventListenerWrapper(args[1]);
|
|
3330
|
-
// Ignore types because we're passing through to native method
|
|
3331
|
-
// @ts-ignore type-mismatch
|
|
3332
|
-
windowRemoveEventListener.apply(this, args);
|
|
3333
|
-
}
|
|
3334
|
-
// Account for listeners that were added before this polyfill was applied
|
|
3335
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
3336
|
-
// @ts-ignore type-mismatch
|
|
3337
|
-
windowRemoveEventListener.apply(this, arguments);
|
|
3338
|
-
}
|
|
3339
|
-
function apply() {
|
|
3340
|
-
defineProperties(Window.prototype, {
|
|
3341
|
-
addEventListener: {
|
|
3342
|
-
value: patchedAddEventListener,
|
|
3343
|
-
enumerable: true,
|
|
3344
|
-
writable: true,
|
|
3345
|
-
configurable: true,
|
|
3346
|
-
},
|
|
3347
|
-
removeEventListener: {
|
|
3348
|
-
value: patchedRemoveEventListener,
|
|
3349
|
-
enumerable: true,
|
|
3350
|
-
writable: true,
|
|
3351
|
-
configurable: true,
|
|
3352
|
-
},
|
|
3353
|
-
});
|
|
3354
|
-
}
|
|
3355
|
-
|
|
3356
|
-
/*
|
|
3357
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3358
|
-
* All rights reserved.
|
|
3359
|
-
* SPDX-License-Identifier: MIT
|
|
3360
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3361
|
-
*/
|
|
3362
|
-
if (detect()) {
|
|
3363
|
-
apply();
|
|
3364
|
-
}
|
|
3365
|
-
|
|
3366
|
-
/*
|
|
3367
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3368
|
-
* All rights reserved.
|
|
3369
|
-
* SPDX-License-Identifier: MIT
|
|
3370
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3371
|
-
*/
|
|
3372
|
-
function patchedCurrentTargetGetter() {
|
|
3373
|
-
const currentTarget = eventCurrentTargetGetter.call(this);
|
|
3374
|
-
if (isNull(currentTarget)) {
|
|
3375
|
-
return null;
|
|
3376
|
-
}
|
|
3377
|
-
if (eventToContextMap.get(this) === 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */) {
|
|
3378
|
-
return getShadowRoot(currentTarget);
|
|
3379
|
-
}
|
|
3380
|
-
return currentTarget;
|
|
3381
|
-
}
|
|
3382
|
-
function patchedTargetGetter() {
|
|
3383
|
-
const originalTarget = eventTargetGetter.call(this);
|
|
3384
|
-
if (!(originalTarget instanceof _Node)) {
|
|
3385
|
-
return originalTarget;
|
|
3386
|
-
}
|
|
3387
|
-
const doc = getOwnerDocument(originalTarget);
|
|
3388
|
-
const composedPath = pathComposer(originalTarget, this.composed);
|
|
3389
|
-
const originalCurrentTarget = eventCurrentTargetGetter.call(this);
|
|
3390
|
-
// Handle cases where the currentTarget is null (for async events), and when an event has been
|
|
3391
|
-
// added to Window
|
|
3392
|
-
if (!(originalCurrentTarget instanceof _Node)) {
|
|
3393
|
-
// TODO [#1511]: Special escape hatch to support legacy behavior. Should be fixed.
|
|
3394
|
-
// If the event's target is being accessed async and originalTarget is not a keyed element, do not retarget
|
|
3395
|
-
if (isNull(originalCurrentTarget) && isUndefined(getNodeOwnerKey(originalTarget))) {
|
|
3396
|
-
return originalTarget;
|
|
3397
|
-
}
|
|
3398
|
-
return retarget(doc, composedPath);
|
|
3399
|
-
}
|
|
3400
|
-
else if (originalCurrentTarget === doc || originalCurrentTarget === doc.body) {
|
|
3401
|
-
// TODO [#1530]: If currentTarget is document or document.body (Third party libraries that have global event listeners)
|
|
3402
|
-
// and the originalTarget is not a keyed element, do not retarget
|
|
3403
|
-
if (isUndefined(getNodeOwnerKey(originalTarget))) {
|
|
3404
|
-
return originalTarget;
|
|
3405
|
-
}
|
|
3406
|
-
return retarget(doc, composedPath);
|
|
3407
|
-
}
|
|
3408
|
-
let actualCurrentTarget = originalCurrentTarget;
|
|
3409
|
-
let actualPath = composedPath;
|
|
3410
|
-
// Address the possibility that `currentTarget` is a shadow root
|
|
3411
|
-
if (isSyntheticShadowHost(originalCurrentTarget)) {
|
|
3412
|
-
const context = eventToContextMap.get(this);
|
|
3413
|
-
if (context === 1 /* EventListenerContext.SHADOW_ROOT_LISTENER */) {
|
|
3414
|
-
actualCurrentTarget = getShadowRoot(originalCurrentTarget);
|
|
3415
|
-
}
|
|
3416
|
-
}
|
|
3417
|
-
// Address the possibility that `target` is a shadow root
|
|
3418
|
-
if (isSyntheticShadowHost(originalTarget) && eventToShadowRootMap.has(this)) {
|
|
3419
|
-
actualPath = pathComposer(getShadowRoot(originalTarget), this.composed);
|
|
3420
|
-
}
|
|
3421
|
-
return retarget(actualCurrentTarget, actualPath);
|
|
3422
|
-
}
|
|
3423
|
-
function patchedComposedPathValue() {
|
|
3424
|
-
const originalTarget = eventTargetGetter.call(this);
|
|
3425
|
-
// Account for events with targets that are not instances of Node (e.g., when a readystatechange
|
|
3426
|
-
// handler is listening on an instance of XMLHttpRequest).
|
|
3427
|
-
if (!(originalTarget instanceof _Node)) {
|
|
3428
|
-
return [];
|
|
3429
|
-
}
|
|
3430
|
-
// If the original target is inside a native shadow root, then just call the native
|
|
3431
|
-
// composePath() method. The event is already retargeted and this causes our composedPath()
|
|
3432
|
-
// polyfill to compute the wrong value. This is only an issue when you have a native web
|
|
3433
|
-
// component inside an LWC component (see test in same commit) but this scenario is unlikely
|
|
3434
|
-
// because we don't yet support that. Workaround specifically for W-9846457. Mixed mode solution
|
|
3435
|
-
// will likely be more involved.
|
|
3436
|
-
const hasShadowRoot = Boolean(originalTarget.shadowRoot);
|
|
3437
|
-
const hasSyntheticShadowRootAttached = hasInternalSlot(originalTarget);
|
|
3438
|
-
if (hasShadowRoot && !hasSyntheticShadowRootAttached) {
|
|
3439
|
-
return composedPath.call(this);
|
|
3440
|
-
}
|
|
3441
|
-
const originalCurrentTarget = eventCurrentTargetGetter.call(this);
|
|
3442
|
-
// If the event has completed propagation, the composedPath should be an empty array.
|
|
3443
|
-
if (isNull(originalCurrentTarget)) {
|
|
3444
|
-
return [];
|
|
3445
|
-
}
|
|
3446
|
-
// Address the possibility that `target` is a shadow root
|
|
3447
|
-
let actualTarget = originalTarget;
|
|
3448
|
-
if (isSyntheticShadowHost(originalTarget) && eventToShadowRootMap.has(this)) {
|
|
3449
|
-
actualTarget = getShadowRoot(originalTarget);
|
|
3450
|
-
}
|
|
3451
|
-
return pathComposer(actualTarget, this.composed);
|
|
3452
|
-
}
|
|
3453
|
-
defineProperties(Event.prototype, {
|
|
3454
|
-
target: {
|
|
3455
|
-
get: patchedTargetGetter,
|
|
3456
|
-
enumerable: true,
|
|
3457
|
-
configurable: true,
|
|
3458
|
-
},
|
|
3459
|
-
currentTarget: {
|
|
3460
|
-
get: patchedCurrentTargetGetter,
|
|
3461
|
-
enumerable: true,
|
|
3462
|
-
configurable: true,
|
|
3463
|
-
},
|
|
3464
|
-
composedPath: {
|
|
3465
|
-
value: patchedComposedPathValue,
|
|
3466
|
-
writable: true,
|
|
3467
|
-
enumerable: true,
|
|
3468
|
-
configurable: true,
|
|
3469
|
-
},
|
|
3470
|
-
// Non-standard but widely supported for backwards-compatibility
|
|
3471
|
-
srcElement: {
|
|
3472
|
-
get: patchedTargetGetter,
|
|
3473
|
-
enumerable: true,
|
|
3474
|
-
configurable: true,
|
|
3475
|
-
},
|
|
3476
|
-
// Non-standard but implemented in Chrome and continues to exist for backwards-compatibility
|
|
3477
|
-
// https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/dom/events/event.idl;l=58?q=event.idl&ss=chromium
|
|
3478
|
-
path: {
|
|
3479
|
-
get: patchedComposedPathValue,
|
|
3480
|
-
enumerable: true,
|
|
3481
|
-
configurable: true,
|
|
3482
|
-
},
|
|
3483
|
-
});
|
|
3484
|
-
|
|
3485
|
-
/*
|
|
3486
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3487
|
-
* All rights reserved.
|
|
3488
|
-
* SPDX-License-Identifier: MIT
|
|
3489
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3490
|
-
*/
|
|
3491
|
-
function retargetRelatedTarget(Ctor) {
|
|
3492
|
-
const relatedTargetGetter = getOwnPropertyDescriptor(Ctor.prototype, 'relatedTarget')
|
|
3493
|
-
.get;
|
|
3494
|
-
defineProperty(Ctor.prototype, 'relatedTarget', {
|
|
3495
|
-
get() {
|
|
3496
|
-
const relatedTarget = relatedTargetGetter.call(this);
|
|
3497
|
-
if (isNull(relatedTarget)) {
|
|
3498
|
-
return null;
|
|
3499
|
-
}
|
|
3500
|
-
if (!(relatedTarget instanceof _Node) || !isNodeShadowed(relatedTarget)) {
|
|
3501
|
-
return relatedTarget;
|
|
3502
|
-
}
|
|
3503
|
-
let pointOfReference = eventCurrentTargetGetter.call(this);
|
|
3504
|
-
if (isNull(pointOfReference)) {
|
|
3505
|
-
pointOfReference = getOwnerDocument(relatedTarget);
|
|
3506
|
-
}
|
|
3507
|
-
return retarget(pointOfReference, pathComposer(relatedTarget, true));
|
|
3508
|
-
},
|
|
3509
|
-
enumerable: true,
|
|
3510
|
-
configurable: true,
|
|
3511
|
-
});
|
|
3512
|
-
}
|
|
3513
|
-
|
|
3514
|
-
/*
|
|
3515
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3516
|
-
* All rights reserved.
|
|
3517
|
-
* SPDX-License-Identifier: MIT
|
|
3518
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3519
|
-
*/
|
|
3520
|
-
retargetRelatedTarget(FocusEvent);
|
|
3521
|
-
|
|
3522
|
-
/*
|
|
3523
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3524
|
-
* All rights reserved.
|
|
3525
|
-
* SPDX-License-Identifier: MIT
|
|
3526
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3527
|
-
*/
|
|
3528
|
-
retargetRelatedTarget(MouseEvent);
|
|
3529
|
-
|
|
3530
|
-
/*
|
|
3531
|
-
* Copyright (c) 2021, salesforce.com, inc.
|
|
3532
|
-
* All rights reserved.
|
|
3533
|
-
* SPDX-License-Identifier: MIT
|
|
3534
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3535
|
-
*/
|
|
3536
|
-
const assignedSlotGetter = hasOwnProperty.call(Text.prototype, 'assignedSlot')
|
|
3537
|
-
? getOwnPropertyDescriptor(Text.prototype, 'assignedSlot').get
|
|
3538
|
-
: () => null;
|
|
3539
|
-
|
|
3540
|
-
/*
|
|
3541
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3542
|
-
* All rights reserved.
|
|
3543
|
-
* SPDX-License-Identifier: MIT
|
|
3544
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3545
|
-
*/
|
|
3546
|
-
// We can use a single observer without having to worry about leaking because
|
|
3547
|
-
// "Registered observers in a node’s registered observer list have a weak
|
|
3548
|
-
// reference to the node."
|
|
3549
|
-
// https://dom.spec.whatwg.org/#garbage-collection
|
|
3550
|
-
let observer;
|
|
3551
|
-
const observerConfig = { childList: true };
|
|
3552
|
-
const SlotChangeKey = new WeakMap();
|
|
3553
|
-
function initSlotObserver() {
|
|
3554
|
-
return new MO((mutations) => {
|
|
3555
|
-
const slots = [];
|
|
3556
|
-
forEach.call(mutations, (mutation) => {
|
|
3557
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
3558
|
-
assert.invariant(mutation.type === 'childList', `Invalid mutation type: ${mutation.type}. This mutation handler for slots should only handle "childList" mutations.`);
|
|
3559
|
-
}
|
|
3560
|
-
const { target: slot } = mutation;
|
|
3561
|
-
if (ArrayIndexOf.call(slots, slot) === -1) {
|
|
3562
|
-
ArrayPush.call(slots, slot);
|
|
3563
|
-
dispatchEvent.call(slot, new CustomEvent('slotchange'));
|
|
3564
|
-
}
|
|
3565
|
-
});
|
|
3566
|
-
});
|
|
3567
|
-
}
|
|
3568
|
-
function getFilteredSlotFlattenNodes(slot) {
|
|
3569
|
-
const childNodes = arrayFromCollection(childNodesGetter.call(slot));
|
|
3570
|
-
// Typescript is inferring the wrong function type for this particular
|
|
3571
|
-
// overloaded method: https://github.com/Microsoft/TypeScript/issues/27972
|
|
3572
|
-
// @ts-ignore type-mismatch
|
|
3573
|
-
return ArrayReduce.call(childNodes, (seed, child) => {
|
|
3574
|
-
if (child instanceof Element && isSlotElement(child)) {
|
|
3575
|
-
ArrayPush.apply(seed, getFilteredSlotFlattenNodes(child));
|
|
3576
|
-
}
|
|
3577
|
-
else {
|
|
3578
|
-
ArrayPush.call(seed, child);
|
|
3579
|
-
}
|
|
3580
|
-
return seed;
|
|
3581
|
-
}, []);
|
|
3582
|
-
}
|
|
3583
|
-
function assignedSlotGetterPatched() {
|
|
3584
|
-
const parentNode = parentNodeGetter.call(this);
|
|
3585
|
-
// use original assignedSlot if parent has a native shdow root
|
|
3586
|
-
if (parentNode instanceof Element) {
|
|
3587
|
-
const sr = shadowRootGetter.call(parentNode);
|
|
3588
|
-
if (isInstanceOfNativeShadowRoot(sr)) {
|
|
3589
|
-
if (this instanceof Text) {
|
|
3590
|
-
return assignedSlotGetter.call(this);
|
|
3591
|
-
}
|
|
3592
|
-
return assignedSlotGetter$1.call(this);
|
|
3593
|
-
}
|
|
3594
|
-
}
|
|
3595
|
-
/**
|
|
3596
|
-
* The node is assigned to a slot if:
|
|
3597
|
-
* - it has a parent and its parent is a slot element
|
|
3598
|
-
* - and if the slot owner key is different than the node owner key.
|
|
3599
|
-
*
|
|
3600
|
-
* When the slot and the slotted node are 2 different shadow trees, the owner keys will be
|
|
3601
|
-
* different. When the slot is in a shadow tree and the slotted content is a light DOM node,
|
|
3602
|
-
* the light DOM node doesn't have an owner key and therefor the slot owner key will be
|
|
3603
|
-
* different than the node owner key (always `undefined`).
|
|
3604
|
-
*/
|
|
3605
|
-
if (!isNull(parentNode) &&
|
|
3606
|
-
isSlotElement(parentNode) &&
|
|
3607
|
-
getNodeOwnerKey(parentNode) !== getNodeOwnerKey(this)) {
|
|
3608
|
-
return parentNode;
|
|
3609
|
-
}
|
|
3610
|
-
return null;
|
|
3611
|
-
}
|
|
3612
|
-
defineProperties(HTMLSlotElement.prototype, {
|
|
3613
|
-
addEventListener: {
|
|
3614
|
-
value(type, listener, options) {
|
|
3615
|
-
// super.addEventListener - but that doesn't work with typescript
|
|
3616
|
-
HTMLElement.prototype.addEventListener.call(this, type, listener, options);
|
|
3617
|
-
if (type === 'slotchange' && !SlotChangeKey.get(this)) {
|
|
3618
|
-
SlotChangeKey.set(this, true);
|
|
3619
|
-
if (!observer) {
|
|
3620
|
-
observer = initSlotObserver();
|
|
3621
|
-
}
|
|
3622
|
-
MutationObserverObserve.call(observer, this, observerConfig);
|
|
3623
|
-
}
|
|
3624
|
-
},
|
|
3625
|
-
writable: true,
|
|
3626
|
-
enumerable: true,
|
|
3627
|
-
configurable: true,
|
|
3628
|
-
},
|
|
3629
|
-
assignedElements: {
|
|
3630
|
-
value(options) {
|
|
3631
|
-
if (isNodeShadowed(this)) {
|
|
3632
|
-
const flatten = !isUndefined(options) && isTrue(options.flatten);
|
|
3633
|
-
const nodes = flatten
|
|
3634
|
-
? getFilteredSlotFlattenNodes(this)
|
|
3635
|
-
: getFilteredSlotAssignedNodes(this);
|
|
3636
|
-
return ArrayFilter.call(nodes, (node) => node instanceof Element);
|
|
3637
|
-
}
|
|
3638
|
-
else {
|
|
3639
|
-
return assignedElements.apply(this, ArraySlice.call(arguments));
|
|
3640
|
-
}
|
|
3641
|
-
},
|
|
3642
|
-
writable: true,
|
|
3643
|
-
enumerable: true,
|
|
3644
|
-
configurable: true,
|
|
3645
|
-
},
|
|
3646
|
-
assignedNodes: {
|
|
3647
|
-
value(options) {
|
|
3648
|
-
if (isNodeShadowed(this)) {
|
|
3649
|
-
const flatten = !isUndefined(options) && isTrue(options.flatten);
|
|
3650
|
-
return flatten
|
|
3651
|
-
? getFilteredSlotFlattenNodes(this)
|
|
3652
|
-
: getFilteredSlotAssignedNodes(this);
|
|
3653
|
-
}
|
|
3654
|
-
else {
|
|
3655
|
-
return assignedNodes.apply(this, ArraySlice.call(arguments));
|
|
3656
|
-
}
|
|
3657
|
-
},
|
|
3658
|
-
writable: true,
|
|
3659
|
-
enumerable: true,
|
|
3660
|
-
configurable: true,
|
|
3661
|
-
},
|
|
3662
|
-
name: {
|
|
3663
|
-
get() {
|
|
3664
|
-
const name = getAttribute.call(this, 'name');
|
|
3665
|
-
return isNull(name) ? '' : name;
|
|
3666
|
-
},
|
|
3667
|
-
set(value) {
|
|
3668
|
-
setAttribute.call(this, 'name', value);
|
|
3669
|
-
},
|
|
3670
|
-
enumerable: true,
|
|
3671
|
-
configurable: true,
|
|
3672
|
-
},
|
|
3673
|
-
childNodes: {
|
|
3674
|
-
get() {
|
|
3675
|
-
if (isNodeShadowed(this)) {
|
|
3676
|
-
const owner = getNodeOwner(this);
|
|
3677
|
-
const childNodes = isNull(owner)
|
|
3678
|
-
? []
|
|
3679
|
-
: getAllMatches(owner, getFilteredChildNodes(this));
|
|
3680
|
-
return createStaticNodeList(childNodes);
|
|
3681
|
-
}
|
|
3682
|
-
return childNodesGetter.call(this);
|
|
3683
|
-
},
|
|
3684
|
-
enumerable: true,
|
|
3685
|
-
configurable: true,
|
|
3686
|
-
},
|
|
3687
|
-
});
|
|
3688
|
-
|
|
3689
|
-
/*
|
|
3690
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3691
|
-
* All rights reserved.
|
|
3692
|
-
* SPDX-License-Identifier: MIT
|
|
3693
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3694
|
-
*/
|
|
3695
|
-
// Non-deep-traversing patches: this descriptor map includes all descriptors that
|
|
3696
|
-
// do not five access to nodes beyond the immediate children.
|
|
3697
|
-
defineProperties(Text.prototype, {
|
|
3698
|
-
assignedSlot: {
|
|
3699
|
-
get: assignedSlotGetterPatched,
|
|
3700
|
-
enumerable: true,
|
|
3701
|
-
configurable: true,
|
|
3702
|
-
},
|
|
3703
|
-
});
|
|
3704
|
-
|
|
3705
|
-
/*
|
|
3706
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3707
|
-
* All rights reserved.
|
|
3708
|
-
* SPDX-License-Identifier: MIT
|
|
3709
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3710
|
-
*/
|
|
3711
|
-
/**
|
|
3712
|
-
* This methods filters out elements that are not in the same shadow root of context.
|
|
3713
|
-
* It does not enforce shadow dom semantics if $context is not managed by LWC
|
|
3714
|
-
*/
|
|
3715
|
-
function getNonPatchedFilteredArrayOfNodes(context, unfilteredNodes) {
|
|
3716
|
-
let filtered;
|
|
3717
|
-
const ownerKey = getNodeOwnerKey(context);
|
|
3718
|
-
// a node inside a shadow.
|
|
3719
|
-
if (!isUndefined(ownerKey)) {
|
|
3720
|
-
if (isSyntheticShadowHost(context)) {
|
|
3721
|
-
// element with shadowRoot attached
|
|
3722
|
-
const owner = getNodeOwner(context);
|
|
3723
|
-
if (isNull(owner)) {
|
|
3724
|
-
filtered = [];
|
|
3725
|
-
}
|
|
3726
|
-
else if (getNodeKey(context)) {
|
|
3727
|
-
// it is a custom element, and we should then filter by slotted elements
|
|
3728
|
-
filtered = getAllSlottedMatches(context, unfilteredNodes);
|
|
3729
|
-
}
|
|
3730
|
-
else {
|
|
3731
|
-
// regular element, we should then filter by ownership
|
|
3732
|
-
filtered = getAllMatches(owner, unfilteredNodes);
|
|
3733
|
-
}
|
|
3734
|
-
}
|
|
3735
|
-
else {
|
|
3736
|
-
// context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
|
|
3737
|
-
filtered = ArrayFilter.call(unfilteredNodes, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
|
|
3738
|
-
}
|
|
3739
|
-
}
|
|
3740
|
-
else if (context instanceof HTMLBodyElement) {
|
|
3741
|
-
// `context` is document.body which is already patched.
|
|
3742
|
-
filtered = ArrayFilter.call(unfilteredNodes,
|
|
3743
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
3744
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
3745
|
-
(elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
|
|
3746
|
-
}
|
|
3747
|
-
else {
|
|
3748
|
-
// `context` is outside the lwc boundary, return unfiltered list.
|
|
3749
|
-
filtered = ArraySlice.call(unfilteredNodes);
|
|
3750
|
-
}
|
|
3751
|
-
return filtered;
|
|
3752
|
-
}
|
|
3753
|
-
|
|
3754
|
-
/*
|
|
3755
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
3756
|
-
* All rights reserved.
|
|
3757
|
-
* SPDX-License-Identifier: MIT
|
|
3758
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
3759
|
-
*/
|
|
3760
|
-
function innerHTMLGetterPatched() {
|
|
3761
|
-
const childNodes = getInternalChildNodes(this);
|
|
3762
|
-
let innerHTML = '';
|
|
3763
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
3764
|
-
innerHTML += getOuterHTML(childNodes[i]);
|
|
3765
|
-
}
|
|
3766
|
-
return innerHTML;
|
|
3767
|
-
}
|
|
3768
|
-
function outerHTMLGetterPatched() {
|
|
3769
|
-
return getOuterHTML(this);
|
|
3770
|
-
}
|
|
3771
|
-
function attachShadowPatched(options) {
|
|
3772
|
-
// To retain native behavior of the API, provide synthetic shadowRoot only when specified
|
|
3773
|
-
if (options[KEY__SYNTHETIC_MODE]) {
|
|
3774
|
-
return attachShadow(this, options);
|
|
3775
|
-
}
|
|
3776
|
-
return attachShadow$1.call(this, options);
|
|
3777
|
-
}
|
|
3778
|
-
function shadowRootGetterPatched() {
|
|
3779
|
-
if (isSyntheticShadowHost(this)) {
|
|
3780
|
-
const shadow = getShadowRoot(this);
|
|
3781
|
-
if (shadow.mode === 'open') {
|
|
3782
|
-
return shadow;
|
|
3783
|
-
}
|
|
3784
|
-
}
|
|
3785
|
-
return shadowRootGetter.call(this);
|
|
3786
|
-
}
|
|
3787
|
-
function childrenGetterPatched() {
|
|
3788
|
-
const owner = getNodeOwner(this);
|
|
3789
|
-
const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this));
|
|
3790
|
-
return createStaticHTMLCollection(ArrayFilter.call(childNodes, (node) => node instanceof Element));
|
|
3791
|
-
}
|
|
3792
|
-
function childElementCountGetterPatched() {
|
|
3793
|
-
return this.children.length;
|
|
3794
|
-
}
|
|
3795
|
-
function firstElementChildGetterPatched() {
|
|
3796
|
-
return this.children[0] || null;
|
|
3797
|
-
}
|
|
3798
|
-
function lastElementChildGetterPatched() {
|
|
3799
|
-
const { children } = this;
|
|
3800
|
-
return children.item(children.length - 1) || null;
|
|
3801
|
-
}
|
|
3802
|
-
// Non-deep-traversing patches: this descriptor map includes all descriptors that
|
|
3803
|
-
// do not five access to nodes beyond the immediate children.
|
|
3804
|
-
defineProperties(Element.prototype, {
|
|
3805
|
-
innerHTML: {
|
|
3806
|
-
get() {
|
|
3807
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
3808
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
3809
|
-
if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
|
|
3810
|
-
return innerHTMLGetterPatched.call(this);
|
|
3811
|
-
}
|
|
3812
|
-
return innerHTMLGetter.call(this);
|
|
3813
|
-
},
|
|
3814
|
-
set(v) {
|
|
3815
|
-
innerHTMLSetter.call(this, v);
|
|
3816
|
-
},
|
|
3817
|
-
enumerable: true,
|
|
3818
|
-
configurable: true,
|
|
3819
|
-
},
|
|
3820
|
-
outerHTML: {
|
|
3821
|
-
get() {
|
|
3822
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
3823
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
3824
|
-
if (isNodeShadowed(this) || isSyntheticShadowHost(this)) {
|
|
3825
|
-
return outerHTMLGetterPatched.call(this);
|
|
3826
|
-
}
|
|
3827
|
-
return outerHTMLGetter.call(this);
|
|
3828
|
-
},
|
|
3829
|
-
set(v) {
|
|
3830
|
-
outerHTMLSetter.call(this, v);
|
|
3831
|
-
},
|
|
3832
|
-
enumerable: true,
|
|
3833
|
-
configurable: true,
|
|
3834
|
-
},
|
|
3835
|
-
attachShadow: {
|
|
3836
|
-
value: attachShadowPatched,
|
|
3837
|
-
enumerable: true,
|
|
3838
|
-
writable: true,
|
|
3839
|
-
configurable: true,
|
|
3840
|
-
},
|
|
3841
|
-
shadowRoot: {
|
|
3842
|
-
get: shadowRootGetterPatched,
|
|
3843
|
-
enumerable: true,
|
|
3844
|
-
configurable: true,
|
|
3845
|
-
},
|
|
3846
|
-
// patched in HTMLElement if exists (IE11 is the one off here)
|
|
3847
|
-
children: {
|
|
3848
|
-
get() {
|
|
3849
|
-
if (hasMountedChildren(this)) {
|
|
3850
|
-
return childrenGetterPatched.call(this);
|
|
3851
|
-
}
|
|
3852
|
-
return childrenGetter.call(this);
|
|
3853
|
-
},
|
|
3854
|
-
enumerable: true,
|
|
3855
|
-
configurable: true,
|
|
3856
|
-
},
|
|
3857
|
-
childElementCount: {
|
|
3858
|
-
get() {
|
|
3859
|
-
if (hasMountedChildren(this)) {
|
|
3860
|
-
return childElementCountGetterPatched.call(this);
|
|
3861
|
-
}
|
|
3862
|
-
return childElementCountGetter.call(this);
|
|
3863
|
-
},
|
|
3864
|
-
enumerable: true,
|
|
3865
|
-
configurable: true,
|
|
3866
|
-
},
|
|
3867
|
-
firstElementChild: {
|
|
3868
|
-
get() {
|
|
3869
|
-
if (hasMountedChildren(this)) {
|
|
3870
|
-
return firstElementChildGetterPatched.call(this);
|
|
3871
|
-
}
|
|
3872
|
-
return firstElementChildGetter.call(this);
|
|
3873
|
-
},
|
|
3874
|
-
enumerable: true,
|
|
3875
|
-
configurable: true,
|
|
3876
|
-
},
|
|
3877
|
-
lastElementChild: {
|
|
3878
|
-
get() {
|
|
3879
|
-
if (hasMountedChildren(this)) {
|
|
3880
|
-
return lastElementChildGetterPatched.call(this);
|
|
3881
|
-
}
|
|
3882
|
-
return lastElementChildGetter.call(this);
|
|
3883
|
-
},
|
|
3884
|
-
enumerable: true,
|
|
3885
|
-
configurable: true,
|
|
3886
|
-
},
|
|
3887
|
-
assignedSlot: {
|
|
3888
|
-
get: assignedSlotGetterPatched,
|
|
3889
|
-
enumerable: true,
|
|
3890
|
-
configurable: true,
|
|
3891
|
-
},
|
|
3892
|
-
});
|
|
3893
|
-
// IE11 extra patches for wrong prototypes
|
|
3894
|
-
if (hasOwnProperty.call(HTMLElement.prototype, 'innerHTML')) {
|
|
3895
|
-
defineProperty(HTMLElement.prototype, 'innerHTML', getOwnPropertyDescriptor(Element.prototype, 'innerHTML'));
|
|
3896
|
-
}
|
|
3897
|
-
if (hasOwnProperty.call(HTMLElement.prototype, 'outerHTML')) {
|
|
3898
|
-
defineProperty(HTMLElement.prototype, 'outerHTML', getOwnPropertyDescriptor(Element.prototype, 'outerHTML'));
|
|
3899
|
-
}
|
|
3900
|
-
if (hasOwnProperty.call(HTMLElement.prototype, 'children')) {
|
|
3901
|
-
defineProperty(HTMLElement.prototype, 'children', getOwnPropertyDescriptor(Element.prototype, 'children'));
|
|
3902
|
-
}
|
|
3903
|
-
// Deep-traversing patches from this point on:
|
|
3904
|
-
function querySelectorPatched() {
|
|
3905
|
-
const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
|
|
3906
|
-
if (isSyntheticShadowHost(this)) {
|
|
3907
|
-
// element with shadowRoot attached
|
|
3908
|
-
const owner = getNodeOwner(this);
|
|
3909
|
-
if (!isUndefined(getNodeKey(this))) {
|
|
3910
|
-
// it is a custom element, and we should then filter by slotted elements
|
|
3911
|
-
return getFirstSlottedMatch(this, nodeList);
|
|
3912
|
-
}
|
|
3913
|
-
else if (isNull(owner)) {
|
|
3914
|
-
return null;
|
|
3915
|
-
}
|
|
3916
|
-
else {
|
|
3917
|
-
// regular element, we should then filter by ownership
|
|
3918
|
-
return getFirstMatch(owner, nodeList);
|
|
3919
|
-
}
|
|
3920
|
-
}
|
|
3921
|
-
else if (isNodeShadowed(this)) {
|
|
3922
|
-
// element inside a shadowRoot
|
|
3923
|
-
const ownerKey = getNodeOwnerKey(this);
|
|
3924
|
-
if (!isUndefined(ownerKey)) {
|
|
3925
|
-
// `this` is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
|
|
3926
|
-
const elm = ArrayFind.call(nodeList, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
|
|
3927
|
-
return isUndefined(elm) ? null : elm;
|
|
3928
|
-
}
|
|
3929
|
-
else {
|
|
3930
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
3931
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
3932
|
-
// `this` is a manually inserted element inside a shadowRoot, return the first element.
|
|
3933
|
-
return nodeList.length === 0 ? null : nodeList[0];
|
|
3934
|
-
}
|
|
3935
|
-
}
|
|
3936
|
-
else {
|
|
3937
|
-
if (!(this instanceof HTMLBodyElement)) {
|
|
3938
|
-
const elm = nodeList[0];
|
|
3939
|
-
return isUndefined(elm) ? null : elm;
|
|
3940
|
-
}
|
|
3941
|
-
// element belonging to the document
|
|
3942
|
-
const elm = ArrayFind.call(nodeList, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(this));
|
|
3943
|
-
return isUndefined(elm) ? null : elm;
|
|
3944
|
-
}
|
|
3945
|
-
}
|
|
3946
|
-
function getFilteredArrayOfNodes(context, unfilteredNodes) {
|
|
3947
|
-
let filtered;
|
|
3948
|
-
if (isSyntheticShadowHost(context)) {
|
|
3949
|
-
// element with shadowRoot attached
|
|
3950
|
-
const owner = getNodeOwner(context);
|
|
3951
|
-
if (!isUndefined(getNodeKey(context))) {
|
|
3952
|
-
// it is a custom element, and we should then filter by slotted elements
|
|
3953
|
-
filtered = getAllSlottedMatches(context, unfilteredNodes);
|
|
3954
|
-
}
|
|
3955
|
-
else if (isNull(owner)) {
|
|
3956
|
-
filtered = [];
|
|
3957
|
-
}
|
|
3958
|
-
else {
|
|
3959
|
-
// regular element, we should then filter by ownership
|
|
3960
|
-
filtered = getAllMatches(owner, unfilteredNodes);
|
|
3961
|
-
}
|
|
3962
|
-
}
|
|
3963
|
-
else if (isNodeShadowed(context)) {
|
|
3964
|
-
// element inside a shadowRoot
|
|
3965
|
-
const ownerKey = getNodeOwnerKey(context);
|
|
3966
|
-
if (!isUndefined(ownerKey)) {
|
|
3967
|
-
// context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
|
|
3968
|
-
filtered = ArrayFilter.call(unfilteredNodes, (elm) => getNodeNearestOwnerKey(elm) === ownerKey);
|
|
3969
|
-
}
|
|
3970
|
-
else {
|
|
3971
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
3972
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
3973
|
-
// context is manually inserted without lwc:dom-manual, return everything
|
|
3974
|
-
filtered = ArraySlice.call(unfilteredNodes);
|
|
3975
|
-
}
|
|
3976
|
-
}
|
|
3977
|
-
else {
|
|
3978
|
-
if (context instanceof HTMLBodyElement) {
|
|
3979
|
-
// `context` is document.body or element belonging to the document with the patch enabled
|
|
3980
|
-
filtered = ArrayFilter.call(unfilteredNodes, (elm) => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context));
|
|
3981
|
-
}
|
|
3982
|
-
else {
|
|
3983
|
-
// `context` is outside the lwc boundary and patch is not enabled.
|
|
3984
|
-
filtered = ArraySlice.call(unfilteredNodes);
|
|
3985
|
-
}
|
|
3986
|
-
}
|
|
3987
|
-
return filtered;
|
|
3988
|
-
}
|
|
3989
|
-
// The following patched methods hide shadowed elements from global
|
|
3990
|
-
// traversing mechanisms. They are simplified for performance reasons to
|
|
3991
|
-
// filter by ownership and do not account for slotted elements. This
|
|
3992
|
-
// compromise is fine for our synthetic shadow dom because root elements
|
|
3993
|
-
// cannot have slotted elements.
|
|
3994
|
-
// Another compromise here is that all these traversing methods will return
|
|
3995
|
-
// static HTMLCollection or static NodeList. We decided that this compromise
|
|
3996
|
-
// is not a big problem considering the amount of code that is relying on
|
|
3997
|
-
// the liveliness of these results are rare.
|
|
3998
|
-
defineProperties(Element.prototype, {
|
|
3999
|
-
querySelector: {
|
|
4000
|
-
value: querySelectorPatched,
|
|
4001
|
-
writable: true,
|
|
4002
|
-
enumerable: true,
|
|
4003
|
-
configurable: true,
|
|
4004
|
-
},
|
|
4005
|
-
querySelectorAll: {
|
|
4006
|
-
value() {
|
|
4007
|
-
const nodeList = arrayFromCollection(querySelectorAll$1.apply(this, ArraySlice.call(arguments)));
|
|
4008
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
4009
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
4010
|
-
const filteredResults = getFilteredArrayOfNodes(this, nodeList);
|
|
4011
|
-
return createStaticNodeList(filteredResults);
|
|
4012
|
-
},
|
|
4013
|
-
writable: true,
|
|
4014
|
-
enumerable: true,
|
|
4015
|
-
configurable: true,
|
|
4016
|
-
},
|
|
4017
|
-
});
|
|
4018
|
-
// The following APIs are used directly by Jest internally so we avoid patching them during testing.
|
|
4019
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
4020
|
-
defineProperties(Element.prototype, {
|
|
4021
|
-
getElementsByClassName: {
|
|
4022
|
-
value() {
|
|
4023
|
-
const elements = arrayFromCollection(getElementsByClassName$1.apply(this, ArraySlice.call(arguments)));
|
|
4024
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
4025
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
4026
|
-
return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
|
|
4027
|
-
},
|
|
4028
|
-
writable: true,
|
|
4029
|
-
enumerable: true,
|
|
4030
|
-
configurable: true,
|
|
4031
|
-
},
|
|
4032
|
-
getElementsByTagName: {
|
|
4033
|
-
value() {
|
|
4034
|
-
const elements = arrayFromCollection(getElementsByTagName$1.apply(this, ArraySlice.call(arguments)));
|
|
4035
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
4036
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
4037
|
-
return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
|
|
4038
|
-
},
|
|
4039
|
-
writable: true,
|
|
4040
|
-
enumerable: true,
|
|
4041
|
-
configurable: true,
|
|
4042
|
-
},
|
|
4043
|
-
getElementsByTagNameNS: {
|
|
4044
|
-
value() {
|
|
4045
|
-
const elements = arrayFromCollection(getElementsByTagNameNS$1.apply(this, ArraySlice.call(arguments)));
|
|
4046
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
4047
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
4048
|
-
return createStaticHTMLCollection(getNonPatchedFilteredArrayOfNodes(this, elements));
|
|
4049
|
-
},
|
|
4050
|
-
writable: true,
|
|
4051
|
-
enumerable: true,
|
|
4052
|
-
configurable: true,
|
|
4053
|
-
},
|
|
4054
|
-
});
|
|
4055
|
-
}
|
|
4056
|
-
// IE11 extra patches for wrong prototypes
|
|
4057
|
-
if (hasOwnProperty.call(HTMLElement.prototype, 'getElementsByClassName')) {
|
|
4058
|
-
defineProperty(HTMLElement.prototype, 'getElementsByClassName', getOwnPropertyDescriptor(Element.prototype, 'getElementsByClassName'));
|
|
4059
|
-
}
|
|
4060
|
-
|
|
4061
|
-
/*
|
|
4062
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
4063
|
-
* All rights reserved.
|
|
4064
|
-
* SPDX-License-Identifier: MIT
|
|
4065
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4066
|
-
*/
|
|
4067
|
-
const FocusableSelector = `
|
|
4068
|
-
[contenteditable],
|
|
4069
|
-
[tabindex],
|
|
4070
|
-
a[href],
|
|
4071
|
-
area[href],
|
|
4072
|
-
audio[controls],
|
|
4073
|
-
button,
|
|
4074
|
-
iframe,
|
|
4075
|
-
input,
|
|
4076
|
-
select,
|
|
4077
|
-
textarea,
|
|
4078
|
-
video[controls]
|
|
4079
|
-
`;
|
|
4080
|
-
const formElementTagNames = new Set(['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA']);
|
|
4081
|
-
function filterSequentiallyFocusableElements(elements) {
|
|
4082
|
-
return elements.filter((element) => {
|
|
4083
|
-
if (hasAttribute.call(element, 'tabindex')) {
|
|
4084
|
-
// Even though LWC only supports tabindex values of 0 or -1,
|
|
4085
|
-
// passing through elements with tabindex="0" is a tighter criteria
|
|
4086
|
-
// than filtering out elements based on tabindex="-1".
|
|
4087
|
-
return getAttribute.call(element, 'tabindex') === '0';
|
|
4088
|
-
}
|
|
4089
|
-
if (formElementTagNames.has(tagNameGetter.call(element))) {
|
|
4090
|
-
return !hasAttribute.call(element, 'disabled');
|
|
4091
|
-
}
|
|
4092
|
-
return true;
|
|
4093
|
-
});
|
|
4094
|
-
}
|
|
4095
|
-
const DidAddMouseEventListeners = new WeakMap();
|
|
4096
|
-
// Due to browser differences, it is impossible to know what is focusable until
|
|
4097
|
-
// we actually try to focus it. We need to refactor our focus delegation logic
|
|
4098
|
-
// to verify whether or not the target was actually focused instead of trying
|
|
4099
|
-
// to predict focusability like we do here.
|
|
4100
|
-
function isVisible(element) {
|
|
4101
|
-
const { width, height } = getBoundingClientRect.call(element);
|
|
4102
|
-
const noZeroSize = width > 0 || height > 0;
|
|
4103
|
-
// The area element can be 0x0 and focusable. Hardcoding this is not ideal
|
|
4104
|
-
// but it will minimize changes in the current behavior.
|
|
4105
|
-
const isAreaElement = element.tagName === 'AREA';
|
|
4106
|
-
return (noZeroSize || isAreaElement) && getComputedStyle(element).visibility !== 'hidden';
|
|
4107
|
-
}
|
|
4108
|
-
// This function based on https://allyjs.io/data-tables/focusable.html
|
|
4109
|
-
// It won't catch everything, but should be good enough
|
|
4110
|
-
// There are a lot of edge cases here that we can't realistically handle
|
|
4111
|
-
// Determines if a particular element is tabbable, as opposed to simply focusable
|
|
4112
|
-
function isTabbable(element) {
|
|
4113
|
-
if (isSyntheticShadowHost(element) && isDelegatingFocus(element)) {
|
|
4114
|
-
return false;
|
|
4115
|
-
}
|
|
4116
|
-
return matches.call(element, FocusableSelector) && isVisible(element);
|
|
4117
|
-
}
|
|
4118
|
-
function hostElementFocus() {
|
|
4119
|
-
const _rootNode = this.getRootNode();
|
|
4120
|
-
if (_rootNode === this) {
|
|
4121
|
-
// We invoke the focus() method even if the host is disconnected in order to eliminate
|
|
4122
|
-
// observable differences for component authors between synthetic and native.
|
|
4123
|
-
const focusable = querySelector.call(this, FocusableSelector);
|
|
4124
|
-
if (!isNull(focusable)) {
|
|
4125
|
-
// @ts-ignore type-mismatch
|
|
4126
|
-
focusable.focus.apply(focusable, arguments);
|
|
4127
|
-
}
|
|
4128
|
-
return;
|
|
4129
|
-
}
|
|
4130
|
-
// If the root node is not the host element then it's either the document or a shadow root.
|
|
4131
|
-
const rootNode = _rootNode;
|
|
4132
|
-
if (rootNode.activeElement === this) {
|
|
4133
|
-
// The focused element should not change if the focus method is invoked
|
|
4134
|
-
// on the shadow-including ancestor of the currently focused element.
|
|
4135
|
-
return;
|
|
4136
|
-
}
|
|
4137
|
-
const focusables = arrayFromCollection(querySelectorAll$1.call(this, FocusableSelector));
|
|
4138
|
-
let didFocus = false;
|
|
4139
|
-
while (!didFocus && focusables.length !== 0) {
|
|
4140
|
-
const focusable = focusables.shift();
|
|
4141
|
-
// @ts-ignore type-mismatch
|
|
4142
|
-
focusable.focus.apply(focusable, arguments);
|
|
4143
|
-
// Get the root node of the current focusable in case it was slotted.
|
|
4144
|
-
const currentRootNode = focusable.getRootNode();
|
|
4145
|
-
didFocus = currentRootNode.activeElement === focusable;
|
|
4146
|
-
}
|
|
4147
|
-
}
|
|
4148
|
-
function getTabbableSegments(host) {
|
|
4149
|
-
const doc = getOwnerDocument(host);
|
|
4150
|
-
const all = filterSequentiallyFocusableElements(arrayFromCollection(querySelectorAll.call(doc, FocusableSelector)));
|
|
4151
|
-
const inner = filterSequentiallyFocusableElements(arrayFromCollection(querySelectorAll$1.call(host, FocusableSelector)));
|
|
4152
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4153
|
-
assert.invariant(getAttribute.call(host, 'tabindex') === '-1' || isDelegatingFocus(host), `The focusin event is only relevant when the tabIndex property is -1 on the host.`);
|
|
4154
|
-
}
|
|
4155
|
-
const firstChild = inner[0];
|
|
4156
|
-
const lastChild = inner[inner.length - 1];
|
|
4157
|
-
const hostIndex = ArrayIndexOf.call(all, host);
|
|
4158
|
-
// Host element can show up in our "previous" section if its tabindex is 0
|
|
4159
|
-
// We want to filter that out here
|
|
4160
|
-
const firstChildIndex = hostIndex > -1 ? hostIndex : ArrayIndexOf.call(all, firstChild);
|
|
4161
|
-
// Account for an empty inner list
|
|
4162
|
-
const lastChildIndex = inner.length === 0 ? firstChildIndex + 1 : ArrayIndexOf.call(all, lastChild) + 1;
|
|
4163
|
-
const prev = ArraySlice.call(all, 0, firstChildIndex);
|
|
4164
|
-
const next = ArraySlice.call(all, lastChildIndex);
|
|
4165
|
-
return {
|
|
4166
|
-
prev,
|
|
4167
|
-
inner,
|
|
4168
|
-
next,
|
|
4169
|
-
};
|
|
4170
|
-
}
|
|
4171
|
-
function getActiveElement(host) {
|
|
4172
|
-
const doc = getOwnerDocument(host);
|
|
4173
|
-
const activeElement = DocumentPrototypeActiveElement.call(doc);
|
|
4174
|
-
if (isNull(activeElement)) {
|
|
4175
|
-
return activeElement;
|
|
4176
|
-
}
|
|
4177
|
-
// activeElement must be child of the host and owned by it
|
|
4178
|
-
return (compareDocumentPosition.call(host, activeElement) & DOCUMENT_POSITION_CONTAINED_BY) !==
|
|
4179
|
-
0
|
|
4180
|
-
? activeElement
|
|
4181
|
-
: null;
|
|
4182
|
-
}
|
|
4183
|
-
function relatedTargetPosition(host, relatedTarget) {
|
|
4184
|
-
// assert: target must be child of host
|
|
4185
|
-
const pos = compareDocumentPosition.call(host, relatedTarget);
|
|
4186
|
-
if (pos & DOCUMENT_POSITION_CONTAINED_BY) {
|
|
4187
|
-
// focus remains inside the host
|
|
4188
|
-
return 0;
|
|
4189
|
-
}
|
|
4190
|
-
else if (pos & DOCUMENT_POSITION_PRECEDING) {
|
|
4191
|
-
// focus is coming from above
|
|
4192
|
-
return 1;
|
|
4193
|
-
}
|
|
4194
|
-
else if (pos & DOCUMENT_POSITION_FOLLOWING) {
|
|
4195
|
-
// focus is coming from below
|
|
4196
|
-
return 2;
|
|
4197
|
-
}
|
|
4198
|
-
// we don't know what's going on.
|
|
4199
|
-
return -1;
|
|
4200
|
-
}
|
|
4201
|
-
function muteEvent(event) {
|
|
4202
|
-
event.preventDefault();
|
|
4203
|
-
event.stopPropagation();
|
|
4204
|
-
}
|
|
4205
|
-
function muteFocusEventsDuringExecution(win, func) {
|
|
4206
|
-
windowAddEventListener.call(win, 'focusin', muteEvent, true);
|
|
4207
|
-
windowAddEventListener.call(win, 'focusout', muteEvent, true);
|
|
4208
|
-
func();
|
|
4209
|
-
windowRemoveEventListener.call(win, 'focusin', muteEvent, true);
|
|
4210
|
-
windowRemoveEventListener.call(win, 'focusout', muteEvent, true);
|
|
4211
|
-
}
|
|
4212
|
-
function focusOnNextOrBlur(segment, target, relatedTarget) {
|
|
4213
|
-
const win = getOwnerWindow(relatedTarget);
|
|
4214
|
-
const next = getNextTabbable(segment, relatedTarget);
|
|
4215
|
-
if (isNull(next)) {
|
|
4216
|
-
// nothing to focus on, blur to invalidate the operation
|
|
4217
|
-
muteFocusEventsDuringExecution(win, () => {
|
|
4218
|
-
target.blur();
|
|
4219
|
-
});
|
|
4220
|
-
}
|
|
4221
|
-
else {
|
|
4222
|
-
muteFocusEventsDuringExecution(win, () => {
|
|
4223
|
-
next.focus();
|
|
4224
|
-
});
|
|
4225
|
-
}
|
|
4226
|
-
}
|
|
4227
|
-
let letBrowserHandleFocus = false;
|
|
4228
|
-
function disableKeyboardFocusNavigationRoutines() {
|
|
4229
|
-
letBrowserHandleFocus = true;
|
|
4230
|
-
}
|
|
4231
|
-
function enableKeyboardFocusNavigationRoutines() {
|
|
4232
|
-
letBrowserHandleFocus = false;
|
|
4233
|
-
}
|
|
4234
|
-
function isKeyboardFocusNavigationRoutineEnabled() {
|
|
4235
|
-
return !letBrowserHandleFocus;
|
|
4236
|
-
}
|
|
4237
|
-
function skipHostHandler(event) {
|
|
4238
|
-
if (letBrowserHandleFocus) {
|
|
4239
|
-
return;
|
|
4240
|
-
}
|
|
4241
|
-
const host = eventCurrentTargetGetter.call(event);
|
|
4242
|
-
const target = eventTargetGetter.call(event);
|
|
4243
|
-
// If the host delegating focus with tabindex=0 is not the target, we know
|
|
4244
|
-
// that the event was dispatched on a descendant node of the host. This
|
|
4245
|
-
// means the focus is coming from below and we don't need to do anything.
|
|
4246
|
-
if (host !== target) {
|
|
4247
|
-
// Focus is coming from above
|
|
4248
|
-
return;
|
|
4249
|
-
}
|
|
4250
|
-
const relatedTarget = focusEventRelatedTargetGetter.call(event);
|
|
4251
|
-
if (isNull(relatedTarget)) {
|
|
4252
|
-
// If relatedTarget is null, the user is most likely tabbing into the document from the
|
|
4253
|
-
// browser chrome. We could probably deduce whether focus is coming in from the top or the
|
|
4254
|
-
// bottom by comparing the position of the target to all tabbable elements. This is an edge
|
|
4255
|
-
// case and only comes up if the custom element is the first or last tabbable element in the
|
|
4256
|
-
// document.
|
|
4257
|
-
return;
|
|
4258
|
-
}
|
|
4259
|
-
const segments = getTabbableSegments(host);
|
|
4260
|
-
const position = relatedTargetPosition(host, relatedTarget);
|
|
4261
|
-
if (position === 1) {
|
|
4262
|
-
// Focus is coming from above
|
|
4263
|
-
const findTabbableElms = isTabbableFrom.bind(null, host.getRootNode());
|
|
4264
|
-
const first = ArrayFind.call(segments.inner, findTabbableElms);
|
|
4265
|
-
if (!isUndefined(first)) {
|
|
4266
|
-
const win = getOwnerWindow(first);
|
|
4267
|
-
muteFocusEventsDuringExecution(win, () => {
|
|
4268
|
-
first.focus();
|
|
4269
|
-
});
|
|
4270
|
-
}
|
|
4271
|
-
else {
|
|
4272
|
-
focusOnNextOrBlur(segments.next, target, relatedTarget);
|
|
4273
|
-
}
|
|
4274
|
-
}
|
|
4275
|
-
else if (host === target) {
|
|
4276
|
-
// Host is receiving focus from below, either from its shadow or from a sibling
|
|
4277
|
-
focusOnNextOrBlur(ArrayReverse.call(segments.prev), target, relatedTarget);
|
|
4278
|
-
}
|
|
4279
|
-
}
|
|
4280
|
-
function skipShadowHandler(event) {
|
|
4281
|
-
if (letBrowserHandleFocus) {
|
|
4282
|
-
return;
|
|
4283
|
-
}
|
|
4284
|
-
const relatedTarget = focusEventRelatedTargetGetter.call(event);
|
|
4285
|
-
if (isNull(relatedTarget)) {
|
|
4286
|
-
// If relatedTarget is null, the user is most likely tabbing into the document from the
|
|
4287
|
-
// browser chrome. We could probably deduce whether focus is coming in from the top or the
|
|
4288
|
-
// bottom by comparing the position of the target to all tabbable elements. This is an edge
|
|
4289
|
-
// case and only comes up if the custom element is the first or last tabbable element in the
|
|
4290
|
-
// document.
|
|
4291
|
-
return;
|
|
4292
|
-
}
|
|
4293
|
-
const host = eventCurrentTargetGetter.call(event);
|
|
4294
|
-
const segments = getTabbableSegments(host);
|
|
4295
|
-
if (ArrayIndexOf.call(segments.inner, relatedTarget) !== -1) {
|
|
4296
|
-
// If relatedTarget is contained by the host's subtree we can assume that the user is
|
|
4297
|
-
// tabbing between elements inside of the shadow. Do nothing.
|
|
4298
|
-
return;
|
|
4299
|
-
}
|
|
4300
|
-
const target = eventTargetGetter.call(event);
|
|
4301
|
-
// Determine where the focus is coming from (Tab or Shift+Tab)
|
|
4302
|
-
const position = relatedTargetPosition(host, relatedTarget);
|
|
4303
|
-
if (position === 1) {
|
|
4304
|
-
// Focus is coming from above
|
|
4305
|
-
focusOnNextOrBlur(segments.next, target, relatedTarget);
|
|
4306
|
-
}
|
|
4307
|
-
if (position === 2) {
|
|
4308
|
-
// Focus is coming from below
|
|
4309
|
-
focusOnNextOrBlur(ArrayReverse.call(segments.prev), target, relatedTarget);
|
|
4310
|
-
}
|
|
4311
|
-
}
|
|
4312
|
-
// Use this function to determine whether you can start from one root and end up
|
|
4313
|
-
// at another element via tabbing.
|
|
4314
|
-
function isTabbableFrom(fromRoot, toElm) {
|
|
4315
|
-
if (!isTabbable(toElm)) {
|
|
4316
|
-
return false;
|
|
4317
|
-
}
|
|
4318
|
-
const ownerDocument = getOwnerDocument(toElm);
|
|
4319
|
-
let root = toElm.getRootNode();
|
|
4320
|
-
while (root !== ownerDocument && root !== fromRoot) {
|
|
4321
|
-
const sr = root;
|
|
4322
|
-
const host = sr.host;
|
|
4323
|
-
if (getAttribute.call(host, 'tabindex') === '-1') {
|
|
4324
|
-
return false;
|
|
4325
|
-
}
|
|
4326
|
-
root = host && host.getRootNode();
|
|
4327
|
-
}
|
|
4328
|
-
return true;
|
|
4329
|
-
}
|
|
4330
|
-
function getNextTabbable(tabbables, relatedTarget) {
|
|
4331
|
-
const len = tabbables.length;
|
|
4332
|
-
if (len > 0) {
|
|
4333
|
-
for (let i = 0; i < len; i += 1) {
|
|
4334
|
-
const next = tabbables[i];
|
|
4335
|
-
if (isTabbableFrom(relatedTarget.getRootNode(), next)) {
|
|
4336
|
-
return next;
|
|
4337
|
-
}
|
|
4338
|
-
}
|
|
4339
|
-
}
|
|
4340
|
-
return null;
|
|
4341
|
-
}
|
|
4342
|
-
// Skips the host element
|
|
4343
|
-
function handleFocus(elm) {
|
|
4344
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4345
|
-
assert.invariant(isDelegatingFocus(elm), `Invalid attempt to handle focus event for ${toString(elm)}. ${toString(elm)} should have delegates focus true, but is not delegating focus`);
|
|
4346
|
-
}
|
|
4347
|
-
bindDocumentMousedownMouseupHandlers(elm);
|
|
4348
|
-
// Unbind any focusin listeners we may have going on
|
|
4349
|
-
ignoreFocusIn(elm);
|
|
4350
|
-
addEventListener.call(elm, 'focusin', skipHostHandler, true);
|
|
4351
|
-
}
|
|
4352
|
-
function ignoreFocus(elm) {
|
|
4353
|
-
removeEventListener.call(elm, 'focusin', skipHostHandler, true);
|
|
4354
|
-
}
|
|
4355
|
-
function bindDocumentMousedownMouseupHandlers(elm) {
|
|
4356
|
-
const ownerDocument = getOwnerDocument(elm);
|
|
4357
|
-
if (!DidAddMouseEventListeners.get(ownerDocument)) {
|
|
4358
|
-
DidAddMouseEventListeners.set(ownerDocument, true);
|
|
4359
|
-
addEventListener.call(ownerDocument, 'mousedown', disableKeyboardFocusNavigationRoutines, true);
|
|
4360
|
-
addEventListener.call(ownerDocument, 'mouseup', () => {
|
|
4361
|
-
// We schedule this as an async task in the mouseup handler (as
|
|
4362
|
-
// opposed to the mousedown handler) because we want to guarantee
|
|
4363
|
-
// that it will never run before the focusin handler:
|
|
4364
|
-
//
|
|
4365
|
-
// Click form element | Click form element label
|
|
4366
|
-
// ==================================================
|
|
4367
|
-
// mousedown | mousedown
|
|
4368
|
-
// FOCUSIN | mousedown-setTimeout
|
|
4369
|
-
// mousedown-setTimeout | mouseup
|
|
4370
|
-
// mouseup | FOCUSIN
|
|
4371
|
-
// mouseup-setTimeout | mouseup-setTimeout
|
|
4372
|
-
setTimeout(enableKeyboardFocusNavigationRoutines);
|
|
4373
|
-
}, true);
|
|
4374
|
-
// [W-7824445] If the element is draggable, the mousedown event is dispatched before the
|
|
4375
|
-
// element is starting to be dragged, which disable the keyboard focus navigation routine.
|
|
4376
|
-
// But by specification, the mouseup event is never dispatched once the element is dropped.
|
|
4377
|
-
//
|
|
4378
|
-
// For all draggable element, we need to add an event listener to re-enable the keyboard
|
|
4379
|
-
// navigation routine after dragging starts.
|
|
4380
|
-
addEventListener.call(ownerDocument, 'dragstart', enableKeyboardFocusNavigationRoutines, true);
|
|
4381
|
-
}
|
|
4382
|
-
}
|
|
4383
|
-
// Skips the shadow tree
|
|
4384
|
-
function handleFocusIn(elm) {
|
|
4385
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
4386
|
-
assert.invariant(tabIndexGetter.call(elm) === -1, `Invalid attempt to handle focus in ${toString(elm)}. ${toString(elm)} should have tabIndex -1, but has tabIndex ${tabIndexGetter.call(elm)}`);
|
|
4387
|
-
}
|
|
4388
|
-
bindDocumentMousedownMouseupHandlers(elm);
|
|
4389
|
-
// Unbind any focus listeners we may have going on
|
|
4390
|
-
ignoreFocus(elm);
|
|
4391
|
-
// This focusin listener is to catch focusin events from keyboard interactions
|
|
4392
|
-
// A better solution would perhaps be to listen for keydown events, but
|
|
4393
|
-
// the keydown event happens on whatever element already has focus (or no element
|
|
4394
|
-
// at all in the case of the location bar. So, instead we have to assume that focusin
|
|
4395
|
-
// without a mousedown means keyboard navigation
|
|
4396
|
-
addEventListener.call(elm, 'focusin', skipShadowHandler, true);
|
|
4397
|
-
}
|
|
4398
|
-
function ignoreFocusIn(elm) {
|
|
4399
|
-
removeEventListener.call(elm, 'focusin', skipShadowHandler, true);
|
|
4400
|
-
}
|
|
4401
|
-
|
|
4402
|
-
/*
|
|
4403
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
4404
|
-
* All rights reserved.
|
|
4405
|
-
* SPDX-License-Identifier: MIT
|
|
4406
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4407
|
-
*/
|
|
4408
|
-
const { blur, focus } = HTMLElement.prototype;
|
|
4409
|
-
/**
|
|
4410
|
-
* This method only applies to elements with a shadow attached to them
|
|
4411
|
-
*/
|
|
4412
|
-
function tabIndexGetterPatched() {
|
|
4413
|
-
if (isDelegatingFocus(this) && isFalse(hasAttribute.call(this, 'tabindex'))) {
|
|
4414
|
-
// this covers the case where the default tabindex should be 0 because the
|
|
4415
|
-
// custom element is delegating its focus
|
|
4416
|
-
return 0;
|
|
4417
|
-
}
|
|
4418
|
-
return tabIndexGetter.call(this);
|
|
4419
|
-
}
|
|
4420
|
-
/**
|
|
4421
|
-
* This method only applies to elements with a shadow attached to them
|
|
4422
|
-
*/
|
|
4423
|
-
function tabIndexSetterPatched(value) {
|
|
4424
|
-
// This tabIndex setter might be confusing unless it is understood that HTML
|
|
4425
|
-
// elements have default tabIndex property values. Natively focusable elements have
|
|
4426
|
-
// a default tabIndex value of 0 and all other elements have a default tabIndex
|
|
4427
|
-
// value of -1. For example, the tabIndex property value is -1 for both <x-foo> and
|
|
4428
|
-
// <x-foo tabindex="-1">, but our delegatesFocus polyfill should only kick in for
|
|
4429
|
-
// the latter case when the value of the tabindex attribute is -1.
|
|
4430
|
-
const delegatesFocus = isDelegatingFocus(this);
|
|
4431
|
-
// Record the state of things before invoking component setter.
|
|
4432
|
-
const prevValue = tabIndexGetter.call(this);
|
|
4433
|
-
const prevHasAttr = hasAttribute.call(this, 'tabindex');
|
|
4434
|
-
tabIndexSetter.call(this, value);
|
|
4435
|
-
// Record the state of things after invoking component setter.
|
|
4436
|
-
const currValue = tabIndexGetter.call(this);
|
|
4437
|
-
const currHasAttr = hasAttribute.call(this, 'tabindex');
|
|
4438
|
-
const didValueChange = prevValue !== currValue;
|
|
4439
|
-
// If the tabindex attribute is initially rendered, we can assume that this setter has
|
|
4440
|
-
// previously executed and a listener has been added. We must remove that listener if
|
|
4441
|
-
// the tabIndex property value has changed or if the component no longer renders a
|
|
4442
|
-
// tabindex attribute.
|
|
4443
|
-
if (prevHasAttr && (didValueChange || isFalse(currHasAttr))) {
|
|
4444
|
-
if (prevValue === -1) {
|
|
4445
|
-
ignoreFocusIn(this);
|
|
4446
|
-
}
|
|
4447
|
-
if (prevValue === 0 && delegatesFocus) {
|
|
4448
|
-
ignoreFocus(this);
|
|
4449
|
-
}
|
|
4450
|
-
}
|
|
4451
|
-
// If a tabindex attribute was not rendered after invoking its setter, it means the
|
|
4452
|
-
// component is taking control. Do nothing.
|
|
4453
|
-
if (isFalse(currHasAttr)) {
|
|
4454
|
-
return;
|
|
4455
|
-
}
|
|
4456
|
-
// If the tabindex attribute is initially rendered, we can assume that this setter has
|
|
4457
|
-
// previously executed and a listener has been added. If the tabindex attribute is still
|
|
4458
|
-
// rendered after invoking the setter AND the tabIndex property value has not changed,
|
|
4459
|
-
// we don't need to do any work.
|
|
4460
|
-
if (prevHasAttr && currHasAttr && isFalse(didValueChange)) {
|
|
4461
|
-
return;
|
|
4462
|
-
}
|
|
4463
|
-
// At this point we know that a tabindex attribute was rendered after invoking the
|
|
4464
|
-
// setter and that either:
|
|
4465
|
-
// 1) This is the first time this setter is being invoked.
|
|
4466
|
-
// 2) This is not the first time this setter is being invoked and the value is changing.
|
|
4467
|
-
// We need to add the appropriate listeners in either case.
|
|
4468
|
-
if (currValue === -1) {
|
|
4469
|
-
// Add the magic to skip the shadow tree
|
|
4470
|
-
handleFocusIn(this);
|
|
4471
|
-
}
|
|
4472
|
-
if (currValue === 0 && delegatesFocus) {
|
|
4473
|
-
// Add the magic to skip the host element
|
|
4474
|
-
handleFocus(this);
|
|
4475
|
-
}
|
|
4476
|
-
}
|
|
4477
|
-
/**
|
|
4478
|
-
* This method only applies to elements with a shadow attached to them
|
|
4479
|
-
*/
|
|
4480
|
-
function blurPatched() {
|
|
4481
|
-
if (isDelegatingFocus(this)) {
|
|
4482
|
-
const currentActiveElement = getActiveElement(this);
|
|
4483
|
-
if (!isNull(currentActiveElement)) {
|
|
4484
|
-
// if there is an active element, blur it (intentionally using the dot notation in case the user defines the blur routine)
|
|
4485
|
-
currentActiveElement.blur();
|
|
4486
|
-
return;
|
|
4487
|
-
}
|
|
4488
|
-
}
|
|
4489
|
-
return blur.call(this);
|
|
4490
|
-
}
|
|
4491
|
-
function focusPatched() {
|
|
4492
|
-
// Save enabled state
|
|
4493
|
-
const originallyEnabled = isKeyboardFocusNavigationRoutineEnabled();
|
|
4494
|
-
// Change state by disabling if originally enabled
|
|
4495
|
-
if (originallyEnabled) {
|
|
4496
|
-
disableKeyboardFocusNavigationRoutines();
|
|
4497
|
-
}
|
|
4498
|
-
if (isSyntheticShadowHost(this) && isDelegatingFocus(this)) {
|
|
4499
|
-
hostElementFocus.call(this);
|
|
4500
|
-
return;
|
|
4501
|
-
}
|
|
4502
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
4503
|
-
// @ts-ignore type-mismatch
|
|
4504
|
-
focus.apply(this, arguments);
|
|
4505
|
-
// Restore state by enabling if originally enabled
|
|
4506
|
-
if (originallyEnabled) {
|
|
4507
|
-
enableKeyboardFocusNavigationRoutines();
|
|
4508
|
-
}
|
|
4509
|
-
}
|
|
4510
|
-
// Non-deep-traversing patches: this descriptor map includes all descriptors that
|
|
4511
|
-
// do not five access to nodes beyond the immediate children.
|
|
4512
|
-
defineProperties(HTMLElement.prototype, {
|
|
4513
|
-
tabIndex: {
|
|
4514
|
-
get() {
|
|
4515
|
-
if (isSyntheticShadowHost(this)) {
|
|
4516
|
-
return tabIndexGetterPatched.call(this);
|
|
4517
|
-
}
|
|
4518
|
-
return tabIndexGetter.call(this);
|
|
4519
|
-
},
|
|
4520
|
-
set(v) {
|
|
4521
|
-
if (isSyntheticShadowHost(this)) {
|
|
4522
|
-
return tabIndexSetterPatched.call(this, v);
|
|
4523
|
-
}
|
|
4524
|
-
return tabIndexSetter.call(this, v);
|
|
4525
|
-
},
|
|
4526
|
-
enumerable: true,
|
|
4527
|
-
configurable: true,
|
|
4528
|
-
},
|
|
4529
|
-
blur: {
|
|
4530
|
-
value() {
|
|
4531
|
-
if (isSyntheticShadowHost(this)) {
|
|
4532
|
-
return blurPatched.call(this);
|
|
4533
|
-
}
|
|
4534
|
-
blur.call(this);
|
|
4535
|
-
},
|
|
4536
|
-
enumerable: true,
|
|
4537
|
-
writable: true,
|
|
4538
|
-
configurable: true,
|
|
4539
|
-
},
|
|
4540
|
-
focus: {
|
|
4541
|
-
value() {
|
|
4542
|
-
// Typescript does not like it when you treat the `arguments` object as an array
|
|
4543
|
-
// @ts-ignore type-mismatch
|
|
4544
|
-
focusPatched.apply(this, arguments);
|
|
4545
|
-
},
|
|
4546
|
-
enumerable: true,
|
|
4547
|
-
writable: true,
|
|
4548
|
-
configurable: true,
|
|
4549
|
-
},
|
|
4550
|
-
});
|
|
4551
|
-
// Note: In JSDOM innerText is not implemented: https://github.com/jsdom/jsdom/issues/1245
|
|
4552
|
-
if (innerTextGetter !== null && innerTextSetter !== null) {
|
|
4553
|
-
defineProperty(HTMLElement.prototype, 'innerText', {
|
|
4554
|
-
get() {
|
|
4555
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
4556
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
4557
|
-
return innerTextGetter.call(this);
|
|
4558
|
-
},
|
|
4559
|
-
set(v) {
|
|
4560
|
-
innerTextSetter.call(this, v);
|
|
4561
|
-
},
|
|
4562
|
-
enumerable: true,
|
|
4563
|
-
configurable: true,
|
|
4564
|
-
});
|
|
4565
|
-
}
|
|
4566
|
-
// Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText
|
|
4567
|
-
if (outerTextGetter !== null && outerTextSetter !== null) {
|
|
4568
|
-
// From https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText :
|
|
4569
|
-
// HTMLElement.outerText is a non-standard property. As a getter, it returns the same value as Node.innerText.
|
|
4570
|
-
// As a setter, it removes the current node and replaces it with the given text.
|
|
4571
|
-
defineProperty(HTMLElement.prototype, 'outerText', {
|
|
4572
|
-
get() {
|
|
4573
|
-
// Note: we deviate from native shadow here, but are not fixing
|
|
4574
|
-
// due to backwards compat: https://github.com/salesforce/lwc/pull/3103
|
|
4575
|
-
return outerTextGetter.call(this);
|
|
4576
|
-
},
|
|
4577
|
-
set(v) {
|
|
4578
|
-
// Invoking the `outerText` setter on a host element should trigger its disconnection, but until we merge node reactions, it will not work.
|
|
4579
|
-
// We could reimplement the outerText setter in JavaScript ([blink implementation](https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/html/html_element.cc;l=841-879;drc=6e8b402a6231405b753919029c9027404325ea00;bpv=0;bpt=1))
|
|
4580
|
-
// but the benefits don't worth the efforts.
|
|
4581
|
-
outerTextSetter.call(this, v);
|
|
4582
|
-
},
|
|
4583
|
-
enumerable: true,
|
|
4584
|
-
configurable: true,
|
|
4585
|
-
});
|
|
4586
|
-
}
|
|
4587
|
-
|
|
4588
|
-
/*
|
|
4589
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
4590
|
-
* All rights reserved.
|
|
4591
|
-
* SPDX-License-Identifier: MIT
|
|
4592
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4593
|
-
*/
|
|
4594
|
-
function getShadowToken(node) {
|
|
4595
|
-
return node[KEY__SHADOW_TOKEN];
|
|
4596
|
-
}
|
|
4597
|
-
function setShadowToken(node, shadowToken) {
|
|
4598
|
-
node[KEY__SHADOW_TOKEN] = shadowToken;
|
|
4599
|
-
}
|
|
4600
|
-
/**
|
|
4601
|
-
* Patching Element.prototype.$shadowToken$ to mark elements a portal:
|
|
4602
|
-
*
|
|
4603
|
-
* - we use a property to allow engines to set a custom attribute that should be
|
|
4604
|
-
* placed into the element to sandbox the css rules defined for the template.
|
|
4605
|
-
*
|
|
4606
|
-
* - this custom attribute must be unique.
|
|
4607
|
-
*
|
|
4608
|
-
**/
|
|
4609
|
-
defineProperty(Element.prototype, KEY__SHADOW_TOKEN, {
|
|
4610
|
-
set(shadowToken) {
|
|
4611
|
-
const oldShadowToken = this[KEY__SHADOW_TOKEN_PRIVATE];
|
|
4612
|
-
if (!isUndefined(oldShadowToken) && oldShadowToken !== shadowToken) {
|
|
4613
|
-
removeAttribute.call(this, oldShadowToken);
|
|
4614
|
-
}
|
|
4615
|
-
if (!isUndefined(shadowToken)) {
|
|
4616
|
-
setAttribute.call(this, shadowToken, '');
|
|
4617
|
-
}
|
|
4618
|
-
this[KEY__SHADOW_TOKEN_PRIVATE] = shadowToken;
|
|
4619
|
-
},
|
|
4620
|
-
get() {
|
|
4621
|
-
return this[KEY__SHADOW_TOKEN_PRIVATE];
|
|
4622
|
-
},
|
|
4623
|
-
configurable: true,
|
|
4624
|
-
});
|
|
4625
|
-
function recursivelySetShadowResolver(node, fn) {
|
|
4626
|
-
node[KEY__SHADOW_RESOLVER] = fn;
|
|
4627
|
-
const childNodes = childNodesGetter.call(node);
|
|
4628
|
-
for (let i = 0, n = childNodes.length; i < n; i++) {
|
|
4629
|
-
recursivelySetShadowResolver(childNodes[i], fn);
|
|
4630
|
-
}
|
|
4631
|
-
}
|
|
4632
|
-
defineProperty(Element.prototype, KEY__SHADOW_STATIC, {
|
|
4633
|
-
set(v) {
|
|
4634
|
-
// Marking an element as static will propagate the shadow resolver to the children.
|
|
4635
|
-
if (v) {
|
|
4636
|
-
const fn = this[KEY__SHADOW_RESOLVER];
|
|
4637
|
-
recursivelySetShadowResolver(this, fn);
|
|
4638
|
-
}
|
|
4639
|
-
this[KEY__SHADOW_STATIC_PRIVATE] = v;
|
|
4640
|
-
},
|
|
4641
|
-
get() {
|
|
4642
|
-
return this[KEY__SHADOW_STATIC_PRIVATE];
|
|
4643
|
-
},
|
|
4644
|
-
configurable: true,
|
|
4645
|
-
});
|
|
4646
|
-
|
|
4647
|
-
/*
|
|
4648
|
-
* Copyright (c) 2018, salesforce.com, inc.
|
|
4649
|
-
* All rights reserved.
|
|
4650
|
-
* SPDX-License-Identifier: MIT
|
|
4651
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
|
4652
|
-
*/
|
|
4653
|
-
const DomManualPrivateKey = '$$DomManualKey$$';
|
|
4654
|
-
// Resolver function used when a node is removed from within a portal
|
|
4655
|
-
const DocumentResolverFn = function () { };
|
|
4656
|
-
// We can use a single observer without having to worry about leaking because
|
|
4657
|
-
// "Registered observers in a node’s registered observer list have a weak
|
|
4658
|
-
// reference to the node."
|
|
4659
|
-
// https://dom.spec.whatwg.org/#garbage-collection
|
|
4660
|
-
let portalObserver;
|
|
4661
|
-
const portalObserverConfig = {
|
|
4662
|
-
childList: true,
|
|
4663
|
-
};
|
|
4664
|
-
function adoptChildNode(node, fn, shadowToken) {
|
|
4665
|
-
const previousNodeShadowResolver = getShadowRootResolver(node);
|
|
4666
|
-
if (previousNodeShadowResolver === fn) {
|
|
4667
|
-
return; // nothing to do here, it is already correctly patched
|
|
4668
|
-
}
|
|
4669
|
-
setShadowRootResolver(node, fn);
|
|
4670
|
-
if (node instanceof Element) {
|
|
4671
|
-
setShadowToken(node, shadowToken);
|
|
4672
|
-
if (isSyntheticShadowHost(node)) {
|
|
4673
|
-
// Root LWC elements can't get content slotted into them, therefore we don't observe their children.
|
|
4674
|
-
return;
|
|
4675
|
-
}
|
|
4676
|
-
if (isUndefined(previousNodeShadowResolver)) {
|
|
4677
|
-
// we only care about Element without shadowResolver (no MO.observe has been called)
|
|
4678
|
-
MutationObserverObserve.call(portalObserver, node, portalObserverConfig);
|
|
4679
|
-
}
|
|
4680
|
-
// recursively patching all children as well
|
|
4681
|
-
const childNodes = childNodesGetter.call(node);
|
|
4682
|
-
for (let i = 0, len = childNodes.length; i < len; i += 1) {
|
|
4683
|
-
adoptChildNode(childNodes[i], fn, shadowToken);
|
|
4684
|
-
}
|
|
4685
|
-
}
|
|
4686
|
-
}
|
|
4687
|
-
function initPortalObserver() {
|
|
4688
|
-
return new MO((mutations) => {
|
|
4689
|
-
forEach.call(mutations, (mutation) => {
|
|
4690
|
-
/**
|
|
4691
|
-
* This routine will process all nodes added or removed from elm (which is marked as a portal)
|
|
4692
|
-
* When adding a node to the portal element, we should add the ownership.
|
|
4693
|
-
* When removing a node from the portal element, this ownership should be removed.
|
|
4694
|
-
*
|
|
4695
|
-
* There is some special cases in which MutationObserver may call with stacked mutations (the same node
|
|
4696
|
-
* will be in addedNodes and removedNodes) or with false positives (a node that is removed and re-appended
|
|
4697
|
-
* in the same tick) for those cases, we cover by checking that the node is contained
|
|
4698
|
-
* (or not in the case of removal) by the element.
|
|
4699
|
-
*/
|
|
4700
|
-
const { target: elm, addedNodes, removedNodes } = mutation;
|
|
4701
|
-
// the target of the mutation should always have a ShadowRootResolver attached to it
|
|
4702
|
-
const fn = getShadowRootResolver(elm);
|
|
4703
|
-
const shadowToken = getShadowToken(elm);
|
|
4704
|
-
// Process removals first to handle the case where an element is removed and reinserted
|
|
4705
|
-
for (let i = 0, len = removedNodes.length; i < len; i += 1) {
|
|
4706
|
-
const node = removedNodes[i];
|
|
4707
|
-
if (!(compareDocumentPosition.call(elm, node) & _Node.DOCUMENT_POSITION_CONTAINED_BY)) {
|
|
4708
|
-
adoptChildNode(node, DocumentResolverFn, undefined);
|
|
4709
|
-
}
|
|
4710
|
-
}
|
|
4711
|
-
for (let i = 0, len = addedNodes.length; i < len; i += 1) {
|
|
4712
|
-
const node = addedNodes[i];
|
|
4713
|
-
if (compareDocumentPosition.call(elm, node) & _Node.DOCUMENT_POSITION_CONTAINED_BY) {
|
|
4714
|
-
adoptChildNode(node, fn, shadowToken);
|
|
4715
|
-
}
|
|
4716
|
-
}
|
|
4717
|
-
});
|
|
4718
|
-
});
|
|
4719
|
-
}
|
|
4720
|
-
function markElementAsPortal(elm) {
|
|
4721
|
-
if (isUndefined(portalObserver)) {
|
|
4722
|
-
portalObserver = initPortalObserver();
|
|
4723
|
-
}
|
|
4724
|
-
if (isUndefined(getShadowRootResolver(elm))) {
|
|
4725
|
-
// only an element from a within a shadowRoot should be used here
|
|
4726
|
-
throw new Error(`Invalid Element`);
|
|
4727
|
-
}
|
|
4728
|
-
// install mutation observer for portals
|
|
4729
|
-
MutationObserverObserve.call(portalObserver, elm, portalObserverConfig);
|
|
4730
|
-
// TODO [#1253]: optimization to synchronously adopt new child nodes added
|
|
4731
|
-
// to this elm, we can do that by patching the most common operations
|
|
4732
|
-
// on the node itself
|
|
4733
|
-
}
|
|
4734
|
-
/**
|
|
4735
|
-
* Patching Element.prototype.$domManual$ to mark elements as portal:
|
|
4736
|
-
*
|
|
4737
|
-
* - we use a property to allow engines to signal that a particular element in
|
|
4738
|
-
* a shadow supports manual insertion of child nodes.
|
|
4739
|
-
*
|
|
4740
|
-
* - this signal comes as a boolean value, and we use it to install the MO instance
|
|
4741
|
-
* onto the element, to propagate the $ownerKey$ and $shadowToken$ to all new
|
|
4742
|
-
* child nodes.
|
|
4743
|
-
*
|
|
4744
|
-
* - at the moment, there is no way to undo this operation, once the element is
|
|
4745
|
-
* marked as $domManual$, setting it to false does nothing.
|
|
4746
|
-
*
|
|
4747
|
-
**/
|
|
4748
|
-
// TODO [#1306]: rename this to $observerConnection$
|
|
4749
|
-
defineProperty(Element.prototype, '$domManual$', {
|
|
4750
|
-
set(v) {
|
|
4751
|
-
this[DomManualPrivateKey] = v;
|
|
4752
|
-
if (isTrue(v)) {
|
|
4753
|
-
markElementAsPortal(this);
|
|
4754
|
-
}
|
|
4755
|
-
},
|
|
4756
|
-
get() {
|
|
4757
|
-
return this[DomManualPrivateKey];
|
|
4758
|
-
},
|
|
4759
|
-
configurable: true,
|
|
4760
|
-
});
|
|
4761
|
-
/** version: 2.50.0 */
|
|
4762
|
-
|
|
4763
|
-
}));
|
|
4764
|
-
//# sourceMappingURL=synthetic-shadow.js.map
|