UNPKG

lwc

Version:

Lightning Web Components (LWC)

1,074 lines (1,072 loc) 188 kB
(function (factory) { typeof define === 'function' && define.amd ? define(factory) : factory(); }((function () { 'use strict'; /* proxy-compat-disable */ var _b, _c; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var assign$1 = Object.assign, create$1 = Object.create, defineProperties$1 = Object.defineProperties, defineProperty$1 = Object.defineProperty, getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor, hasOwnProperty$1 = Object.hasOwnProperty, setPrototypeOf$1 = Object.setPrototypeOf; var _d = Array.prototype, ArrayFilter = _d.filter, ArrayFind = _d.find, ArrayIndexOf = _d.indexOf, ArrayMap = _d.map, ArrayPush = _d.push, ArrayReduce = _d.reduce, ArrayReverse = _d.reverse, ArraySlice = _d.slice, ArraySplice = _d.splice, forEach = _d.forEach; var _e = String.prototype, StringCharCodeAt = _e.charCodeAt; function isUndefined(obj) { return obj === undefined; } function isNull(obj) { return obj === null; } function isTrue(obj) { return obj === true; } function isFalse(obj) { return obj === false; } function isFunction(obj) { return typeof obj === 'function'; } function isObject(obj) { return typeof obj === 'object'; } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // We use this to detect symbol support in order to avoid the expensive symbol polyfill. Note that // we can't use typeof since it will fail when transpiling. var hasNativeSymbolSupport = /*@__PURE__*/ (function () { return Symbol('x').toString() === 'Symbol(x)'; })(); /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // This method abstracts the creation of symbols, so we can fallback to strings when native symbols // are not supported. function createHiddenField(key, namespace) { return hasNativeSymbolSupport ? Symbol(key) : "$$lwc-" + namespace + "-" + key + "$$"; } var hiddenFieldsMap = new WeakMap(); function setHiddenField(o, field, value) { var valuesByField = hiddenFieldsMap.get(o); if (isUndefined(valuesByField)) { valuesByField = create$1(null); hiddenFieldsMap.set(o, valuesByField); } valuesByField[field] = value; } function getHiddenField(o, field) { var valuesByField = hiddenFieldsMap.get(o); if (!isUndefined(valuesByField)) { return valuesByField[field]; } } /** version: 2.1.2 */ /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var DOCUMENT_POSITION_CONTAINED_BY = Node.DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_PRECEDING = Node.DOCUMENT_POSITION_PRECEDING, DOCUMENT_POSITION_FOLLOWING = Node.DOCUMENT_POSITION_FOLLOWING, ELEMENT_NODE = Node.ELEMENT_NODE, TEXT_NODE = Node.TEXT_NODE, CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE, PROCESSING_INSTRUCTION_NODE = Node.PROCESSING_INSTRUCTION_NODE, COMMENT_NODE = Node.COMMENT_NODE; var _f = Node.prototype, appendChild = _f.appendChild, cloneNode = _f.cloneNode, compareDocumentPosition = _f.compareDocumentPosition, insertBefore = _f.insertBefore, removeChild = _f.removeChild, replaceChild = _f.replaceChild, hasChildNodes = _f.hasChildNodes; var contains = HTMLElement.prototype.contains; var firstChildGetter = getOwnPropertyDescriptor$1(Node.prototype, 'firstChild').get; var lastChildGetter = getOwnPropertyDescriptor$1(Node.prototype, 'lastChild').get; var textContentGetter = getOwnPropertyDescriptor$1(Node.prototype, 'textContent').get; var parentNodeGetter = getOwnPropertyDescriptor$1(Node.prototype, 'parentNode').get; var ownerDocumentGetter = getOwnPropertyDescriptor$1(Node.prototype, 'ownerDocument').get; var parentElementGetter = hasOwnProperty$1.call(Node.prototype, 'parentElement') ? getOwnPropertyDescriptor$1(Node.prototype, 'parentElement').get : getOwnPropertyDescriptor$1(HTMLElement.prototype, 'parentElement').get; // IE11 var textContextSetter = getOwnPropertyDescriptor$1(Node.prototype, 'textContent').set; var childNodesGetter = hasOwnProperty$1.call(Node.prototype, 'childNodes') ? getOwnPropertyDescriptor$1(Node.prototype, 'childNodes').get : getOwnPropertyDescriptor$1(HTMLElement.prototype, 'childNodes').get; // IE11 var isConnected = hasOwnProperty$1.call(Node.prototype, 'isConnected') ? getOwnPropertyDescriptor$1(Node.prototype, 'isConnected').get : function () { var doc = ownerDocumentGetter.call(this); // IE11 return ( // if doc is null, it means `this` is actually a document instance which // is always connected doc === null || (compareDocumentPosition.call(doc, this) & DOCUMENT_POSITION_CONTAINED_BY) !== 0); }; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var _g = Element.prototype, getAttribute = _g.getAttribute, getBoundingClientRect = _g.getBoundingClientRect, getElementsByTagName$1 = _g.getElementsByTagName, getElementsByTagNameNS$1 = _g.getElementsByTagNameNS, hasAttribute = _g.hasAttribute, querySelector = _g.querySelector, querySelectorAll$1 = _g.querySelectorAll, removeAttribute = _g.removeAttribute, setAttribute = _g.setAttribute; var attachShadow$1 = hasOwnProperty$1.call(Element.prototype, 'attachShadow') ? Element.prototype.attachShadow : function () { throw new TypeError('attachShadow() is not supported in current browser. Load the @lwc/synthetic-shadow polyfill and use Lightning Web Components'); }; var childElementCountGetter = getOwnPropertyDescriptor$1(Element.prototype, 'childElementCount').get; var firstElementChildGetter = getOwnPropertyDescriptor$1(Element.prototype, 'firstElementChild').get; var lastElementChildGetter = getOwnPropertyDescriptor$1(Element.prototype, 'lastElementChild').get; var innerTextDescriptor = getOwnPropertyDescriptor$1(HTMLElement.prototype, 'innerText'); var innerTextGetter = innerTextDescriptor ? innerTextDescriptor.get : null; var innerTextSetter = innerTextDescriptor ? innerTextDescriptor.set : null; // Note: Firefox does not have outerText, https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/outerText var outerTextDescriptor = getOwnPropertyDescriptor$1(HTMLElement.prototype, 'outerText'); var outerTextGetter = outerTextDescriptor ? outerTextDescriptor.get : null; var outerTextSetter = outerTextDescriptor ? outerTextDescriptor.set : null; var innerHTMLDescriptor = hasOwnProperty$1.call(Element.prototype, 'innerHTML') ? getOwnPropertyDescriptor$1(Element.prototype, 'innerHTML') : getOwnPropertyDescriptor$1(HTMLElement.prototype, 'innerHTML'); // IE11 var innerHTMLGetter = innerHTMLDescriptor.get; var innerHTMLSetter = innerHTMLDescriptor.set; var outerHTMLDescriptor = hasOwnProperty$1.call(Element.prototype, 'outerHTML') ? getOwnPropertyDescriptor$1(Element.prototype, 'outerHTML') : getOwnPropertyDescriptor$1(HTMLElement.prototype, 'outerHTML'); // IE11 var outerHTMLGetter = outerHTMLDescriptor.get; var outerHTMLSetter = outerHTMLDescriptor.set; var tagNameGetter = getOwnPropertyDescriptor$1(Element.prototype, 'tagName').get; var tabIndexDescriptor = getOwnPropertyDescriptor$1(HTMLElement.prototype, 'tabIndex'); var tabIndexGetter = tabIndexDescriptor.get; var tabIndexSetter = tabIndexDescriptor.set; var matches = hasOwnProperty$1.call(Element.prototype, 'matches') ? Element.prototype.matches : Element.prototype.msMatchesSelector; // IE11 var childrenGetter = hasOwnProperty$1.call(Element.prototype, 'children') ? getOwnPropertyDescriptor$1(Element.prototype, 'children').get : getOwnPropertyDescriptor$1(HTMLElement.prototype, 'children').get; // IE11 // for IE11, access from HTMLElement // for all other browsers access the method from the parent Element interface var getElementsByClassName$1 = HTMLElement.prototype.getElementsByClassName; var shadowRootGetter = hasOwnProperty$1.call(Element.prototype, 'shadowRoot') ? getOwnPropertyDescriptor$1(Element.prototype, 'shadowRoot').get : function () { return null; }; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var assignedNodes, assignedElements; if (typeof HTMLSlotElement !== 'undefined') { assignedNodes = HTMLSlotElement.prototype.assignedNodes; assignedElements = HTMLSlotElement.prototype.assignedElements; } else { assignedNodes = function () { 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"); }; assignedElements = function () { 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"); }; } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var eventTargetGetter = getOwnPropertyDescriptor$1(Event.prototype, 'target').get; var eventCurrentTargetGetter = getOwnPropertyDescriptor$1(Event.prototype, 'currentTarget').get; var focusEventRelatedTargetGetter = getOwnPropertyDescriptor$1(FocusEvent.prototype, 'relatedTarget').get; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var DocumentPrototypeActiveElement = getOwnPropertyDescriptor$1(Document.prototype, 'activeElement').get; var elementFromPoint = hasOwnProperty$1.call(Document.prototype, 'elementFromPoint') ? Document.prototype.elementFromPoint : Document.prototype.msElementFromPoint; // IE11 // defaultView can be null when a document has no browsing context. For example, the owner document // of a node in a template doesn't have a default view: https://jsfiddle.net/hv9z0q5a/ var defaultViewGetter = getOwnPropertyDescriptor$1(Document.prototype, 'defaultView').get; var _h = Document.prototype, querySelectorAll = _h.querySelectorAll, getElementById = _h.getElementById, getElementsByClassName = _h.getElementsByClassName, getElementsByTagName = _h.getElementsByTagName, getElementsByTagNameNS = _h.getElementsByTagNameNS; // In Firefox v57 and lower, getElementsByName is defined on HTMLDocument.prototype // In all other browsers have the method on Document.prototype var getElementsByName = HTMLDocument.prototype.getElementsByName; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var windowAddEventListener = window.addEventListener, windowRemoveEventListener = window.removeEventListener, windowGetComputedStyle = window.getComputedStyle, windowGetSelection = window.getSelection; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // There is code in the polyfills that requires access to the unpatched // Mutation Observer constructor, this the code for that. // Eventually, the polyfill should uses the patched version, and this file can be removed. var MO = MutationObserver; var MutationObserverObserve = MO.prototype.observe; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var NativeShadowRoot = null; if (typeof ShadowRoot !== 'undefined') { NativeShadowRoot = ShadowRoot; } var isInstanceOfNativeShadowRoot = isNull(NativeShadowRoot) ? function () { return false; } : function (node) { return node instanceof NativeShadowRoot; }; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ function detect$4() { return typeof HTMLSlotElement === 'undefined'; } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var createElement = Document.prototype.createElement; var CHAR_S = 115; var CHAR_L = 108; var CHAR_O = 111; var CHAR_T = 116; function apply$4() { // IE11 does not have this element definition // we don't care much about the construction phase, just the prototype var HTMLSlotElement = /** @class */ (function () { function HTMLSlotElement() { } return HTMLSlotElement; }()); // prototype inheritance dance setPrototypeOf$1(HTMLSlotElement, HTMLElement.constructor); setPrototypeOf$1(HTMLSlotElement.prototype, HTMLElement.prototype); Window.prototype.HTMLSlotElement = HTMLSlotElement; // IE11 doesn't have HTMLSlotElement, in which case we // need to patch Document.prototype.createElement to remap `slot` // elements to the right prototype defineProperty$1(Document.prototype, 'createElement', { value: function (tagName, _options) { var elm = createElement.apply(this, ArraySlice.call(arguments)); if (tagName.length === 4 && StringCharCodeAt.call(tagName, 0) === CHAR_S && StringCharCodeAt.call(tagName, 1) === CHAR_L && StringCharCodeAt.call(tagName, 2) === CHAR_O && StringCharCodeAt.call(tagName, 3) === CHAR_T) { // the new element is the `slot`, resetting the proto chain // the new newly created global HTMLSlotElement.prototype setPrototypeOf$1(elm, HTMLSlotElement.prototype); } return elm; } }); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ if (detect$4()) { apply$4(); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ function getOwnerDocument(node) { var doc = ownerDocumentGetter.call(node); // if doc is null, it means `this` is actually a document instance return doc === null ? node : doc; } function getOwnerWindow(node) { var doc = getOwnerDocument(node); var win = defaultViewGetter.call(doc); if (win === null) { // this method should never be called with a node that is not part // of a qualifying connected node. throw new TypeError(); } return win; } var skipGlobalPatching; // TODO [#1222]: remove global bypass function isGlobalPatchingSkipped(node) { // we lazily compute this value instead of doing it during evaluation, this helps // for apps that are setting this after the engine code is evaluated. if (isUndefined(skipGlobalPatching)) { var ownerDocument = getOwnerDocument(node); skipGlobalPatching = ownerDocument.body && getAttribute.call(ownerDocument.body, 'data-global-patching-bypass') === 'temporary-bypass'; } return isTrue(skipGlobalPatching); } function arrayFromCollection(collection) { var size = collection.length; var cloned = []; if (size > 0) { for (var i = 0; i < size; i++) { cloned[i] = collection[i]; } } return cloned; } /** * Copyright (C) 2018 salesforce.com, inc. */ /** * Copyright (C) 2018 salesforce.com, inc. */ /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var create = Object.create; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // Inspired from: https://mathiasbynens.be/notes/globalthis var _globalThis = /*@__PURE__*/ function () { // On recent browsers, `globalThis` is already defined. In this case return it directly. if (typeof globalThis === 'object') { return globalThis; } var _globalThis; try { // eslint-disable-next-line no-extend-native Object.defineProperty(Object.prototype, '__magic__', { get: function () { return this; }, configurable: true }); // __magic__ is undefined in Safari 10 and IE10 and older. // @ts-ignore // eslint-disable-next-line no-undef _globalThis = __magic__; // @ts-ignore delete Object.prototype.__magic__; } catch (ex) { // In IE8, Object.defineProperty only works on DOM objects. } finally { // If the magic above fails for some reason we assume that we are in a legacy browser. // Assume `window` exists in this case. if (typeof _globalThis === 'undefined') { // @ts-ignore _globalThis = window; } } return _globalThis; }(); /** version: 2.1.2 */ /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ if (!_globalThis.lwcRuntimeFlags) { Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) }); } var runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for /** version: 2.1.2 */ /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var eventTargetPrototype = typeof EventTarget !== 'undefined' ? EventTarget.prototype : Node.prototype; var addEventListener = eventTargetPrototype.addEventListener, dispatchEvent = eventTargetPrototype.dispatchEvent, removeEventListener = eventTargetPrototype.removeEventListener; /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var EventListenerMap = new WeakMap(); var ComposedPathMap = new WeakMap(); function isEventListenerOrEventListenerObject(fnOrObj) { return isFunction(fnOrObj) || isObject(fnOrObj) && !isNull(fnOrObj) && isFunction(fnOrObj.handleEvent); } function shouldInvokeListener(event, target, currentTarget) { // Subsequent logic assumes that `currentTarget` must be contained in the composed path for the listener to be // invoked, but this is not always the case. `composedPath()` will sometimes return an empty array, even when the // listener should be invoked (e.g., a disconnected instance of EventTarget, an instance of XMLHttpRequest, etc). if (target === currentTarget) { return true; } var composedPath = ComposedPathMap.get(event); if (isUndefined(composedPath)) { composedPath = event.composedPath(); ComposedPathMap.set(event, composedPath); } return composedPath.includes(currentTarget); } function getEventListenerWrapper(fnOrObj) { if (!isEventListenerOrEventListenerObject(fnOrObj)) { return fnOrObj; } var wrapperFn = EventListenerMap.get(fnOrObj); if (isUndefined(wrapperFn)) { wrapperFn = function (event) { // This function is invoked from an event listener and currentTarget is always defined. var currentTarget = eventCurrentTargetGetter.call(event); var composed = event.composed; var shouldInvoke; if (runtimeFlags.ENABLE_NON_COMPOSED_EVENTS_LEAKAGE) { shouldInvoke = !(eventToShadowRootMap.has(event) && isFalse(composed)); } else { var actualTarget = getActualTarget(event); shouldInvoke = shouldInvokeListener(event, actualTarget, currentTarget); } if (!shouldInvoke) { return; } return isFunction(fnOrObj) ? fnOrObj.call(this, event) : fnOrObj.handleEvent && fnOrObj.handleEvent(event); }; EventListenerMap.set(fnOrObj, wrapperFn); } return wrapperFn; } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var EventListenerContext; (function (EventListenerContext) { EventListenerContext[EventListenerContext["CUSTOM_ELEMENT_LISTENER"] = 0] = "CUSTOM_ELEMENT_LISTENER"; EventListenerContext[EventListenerContext["SHADOW_ROOT_LISTENER"] = 1] = "SHADOW_ROOT_LISTENER"; EventListenerContext[EventListenerContext["UNKNOWN_LISTENER"] = 2] = "UNKNOWN_LISTENER"; })(EventListenerContext || (EventListenerContext = {})); var eventToContextMap = new WeakMap(); function isChildNode(root, node) { return !!(compareDocumentPosition.call(root, node) & DOCUMENT_POSITION_CONTAINED_BY); } var GET_ROOT_NODE_CONFIG_FALSE = { composed: false }; function getRootNodeHost(node, options) { var rootNode = node.getRootNode(options); // is SyntheticShadowRootInterface if ('mode' in rootNode && 'delegatesFocus' in rootNode) { rootNode = getHost(rootNode); } return rootNode; } var customElementToWrappedListeners = new WeakMap(); function getEventMap(elm) { var listenerInfo = customElementToWrappedListeners.get(elm); if (isUndefined(listenerInfo)) { listenerInfo = create$1(null); customElementToWrappedListeners.set(elm, listenerInfo); } return listenerInfo; } /** * Events dispatched on shadow roots actually end up being dispatched on their hosts. This means that the event.target * property of events dispatched on shadow roots always resolve to their host. This function understands this * abstraction and properly returns a reference to the shadow root when appropriate. */ function getActualTarget(event) { var _a; return (_a = eventToShadowRootMap.get(event)) !== null && _a !== void 0 ? _a : eventTargetGetter.call(event); } var shadowRootEventListenerMap = new WeakMap(); function getWrappedShadowRootListener(listener) { if (!isFunction(listener)) { throw new TypeError(); // avoiding problems with non-valid listeners } var shadowRootWrappedListener = shadowRootEventListenerMap.get(listener); if (isUndefined(shadowRootWrappedListener)) { shadowRootWrappedListener = function (event) { // currentTarget is always defined inside an event listener var currentTarget = eventCurrentTargetGetter.call(event); // If currentTarget is not an instance of a native shadow root then we're dealing with a // host element whose synthetic shadow root must be accessed via getShadowRoot(). if (!isInstanceOfNativeShadowRoot(currentTarget)) { currentTarget = getShadowRoot(currentTarget); } var shouldInvoke; if (runtimeFlags.ENABLE_NON_COMPOSED_EVENTS_LEAKAGE) { shouldInvoke = shouldInvokeShadowRootListener(event); } else { var actualTarget = getActualTarget(event); shouldInvoke = shouldInvokeListener(event, actualTarget, currentTarget); } if (shouldInvoke) { listener.call(currentTarget, event); } }; shadowRootWrappedListener.placement = EventListenerContext.SHADOW_ROOT_LISTENER; shadowRootEventListenerMap.set(listener, shadowRootWrappedListener); } return shadowRootWrappedListener; } var customElementEventListenerMap = new WeakMap(); function getWrappedCustomElementListener(listener) { if (!isFunction(listener)) { throw new TypeError(); // avoiding problems with non-valid listeners } var customElementWrappedListener = customElementEventListenerMap.get(listener); if (isUndefined(customElementWrappedListener)) { customElementWrappedListener = function (event) { // currentTarget is always defined inside an event listener var currentTarget = eventCurrentTargetGetter.call(event); var shouldInvoke; if (runtimeFlags.ENABLE_NON_COMPOSED_EVENTS_LEAKAGE) { shouldInvoke = shouldInvokeCustomElementListener(event); } else { var actualTarget = getActualTarget(event); shouldInvoke = shouldInvokeListener(event, actualTarget, currentTarget); } if (shouldInvoke) { listener.call(currentTarget, event); } }; customElementWrappedListener.placement = EventListenerContext.CUSTOM_ELEMENT_LISTENER; customElementEventListenerMap.set(listener, customElementWrappedListener); } return customElementWrappedListener; } function domListener(evt) { var immediatePropagationStopped = false; var propagationStopped = false; var type = evt.type, stopImmediatePropagation = evt.stopImmediatePropagation, stopPropagation = evt.stopPropagation; // currentTarget is always defined var currentTarget = eventCurrentTargetGetter.call(evt); var listenerMap = getEventMap(currentTarget); var listeners = listenerMap[type]; // it must have listeners at this point defineProperty$1(evt, 'stopImmediatePropagation', { value: function () { immediatePropagationStopped = true; stopImmediatePropagation.call(evt); }, writable: true, enumerable: true, configurable: true }); defineProperty$1(evt, 'stopPropagation', { value: function () { propagationStopped = true; stopPropagation.call(evt); }, writable: true, enumerable: true, configurable: true }); // in case a listener adds or removes other listeners during invocation var bookkeeping = ArraySlice.call(listeners); function invokeListenersByPlacement(placement) { forEach.call(bookkeeping, function (listener) { if (isFalse(immediatePropagationStopped) && listener.placement === placement) { // making sure that the listener was not removed from the original listener queue if (ArrayIndexOf.call(listeners, listener) !== -1) { // all handlers on the custom element should be called with undefined 'this' listener.call(undefined, evt); } } }); } eventToContextMap.set(evt, EventListenerContext.SHADOW_ROOT_LISTENER); invokeListenersByPlacement(EventListenerContext.SHADOW_ROOT_LISTENER); if (isFalse(immediatePropagationStopped) && isFalse(propagationStopped)) { // doing the second iteration only if the first one didn't interrupt the event propagation eventToContextMap.set(evt, EventListenerContext.CUSTOM_ELEMENT_LISTENER); invokeListenersByPlacement(EventListenerContext.CUSTOM_ELEMENT_LISTENER); } eventToContextMap.set(evt, EventListenerContext.UNKNOWN_LISTENER); } function attachDOMListener(elm, type, wrappedListener) { var listenerMap = getEventMap(elm); var cmpEventHandlers = listenerMap[type]; if (isUndefined(cmpEventHandlers)) { cmpEventHandlers = listenerMap[type] = []; } // Prevent identical listeners from subscribing to the same event type. // TODO [#1824]: Options will also play a factor when we introduce support for them (#1824). if (ArrayIndexOf.call(cmpEventHandlers, wrappedListener) !== -1) { return; } // only add to DOM if there is no other listener on the same placement yet if (cmpEventHandlers.length === 0) { // super.addEventListener() - this will not work on addEventListener.call(elm, type, domListener); } ArrayPush.call(cmpEventHandlers, wrappedListener); } function detachDOMListener(elm, type, wrappedListener) { var listenerMap = getEventMap(elm); var p; var listeners; if (!isUndefined(listeners = listenerMap[type]) && (p = ArrayIndexOf.call(listeners, wrappedListener)) !== -1) { ArraySplice.call(listeners, p, 1); // only remove from DOM if there is no other listener on the same placement if (listeners.length === 0) { removeEventListener.call(elm, type, domListener); } } } function shouldInvokeCustomElementListener(event) { var composed = event.composed; if (isTrue(composed)) { // Listeners on host elements should always be invoked for {composed: true} events. return true; } // If this {composed: false} event was dispatched on any root. if (eventToShadowRootMap.has(event)) { return false; } var target = eventTargetGetter.call(event); var currentTarget = eventCurrentTargetGetter.call(event); // If this {composed: false} event was dispatched on the current target host. if (target === currentTarget) { return true; } // At this point the event must be {bubbles: true, composed: false} and was dispatched from a // shadow-excluding descendant node. In this case, we only invoke the listener if the target // host was assigned to a slot in the composed subtree of the current target host. var targetHost = getRootNodeHost(target, GET_ROOT_NODE_CONFIG_FALSE); var currentTargetHost = currentTarget; return isChildNode(targetHost, currentTargetHost); } function shouldInvokeShadowRootListener(event) { var composed = event.composed; var target = eventTargetGetter.call(event); var currentTarget = eventCurrentTargetGetter.call(event); // If the event was dispatched on the host or its root. if (target === currentTarget) { // Invoke the listener if the event was dispatched directly on the root. return eventToShadowRootMap.get(event) === getShadowRoot(target); } // At this point the event is {bubbles: true} and was dispatched from a shadow-including descendant node. if (isTrue(composed)) { // Invoke the listener if the event is {composed: true}. return true; } // At this point the event must be {bubbles: true, composed: false}. if (isTrue(eventToShadowRootMap.has(event))) { // Don't invoke the listener because the event was dispatched on a descendant root. return false; } var targetHost = getRootNodeHost(target, GET_ROOT_NODE_CONFIG_FALSE); var currentTargetHost = currentTarget; var isCurrentTargetSlotted = isChildNode(targetHost, currentTargetHost); // At this point the event must be {bubbles: true, composed: false} and was dispatched from a // shadow-excluding descendant node. In this case, we only invoke the listener if the target // host was assigned to a slot in the composed subtree of the current target host, or the // descendant node is in the shadow tree of the current root. return isCurrentTargetSlotted || targetHost === currentTargetHost; } function addCustomElementEventListener(type, listener, _options) { if (isFunction(listener)) { var wrappedListener = getWrappedCustomElementListener(listener); attachDOMListener(this, type, wrappedListener); } } function removeCustomElementEventListener(type, listener, _options) { // TODO [#1824]: Lift this restriction on the option parameter if (isFunction(listener)) { var wrappedListener = getWrappedCustomElementListener(listener); detachDOMListener(this, type, wrappedListener); } } function addShadowRootEventListener(sr, type, listener, _options) { if (isFunction(listener)) { var elm = getHost(sr); var wrappedListener = getWrappedShadowRootListener(listener); attachDOMListener(elm, type, wrappedListener); } } function removeShadowRootEventListener(sr, type, listener, _options) { // TODO [#1824]: Lift this restriction on the option parameter if (isFunction(listener)) { var elm = getHost(sr); var wrappedListener = getWrappedShadowRootListener(listener); detachDOMListener(elm, type, wrappedListener); } } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var HostElementKey = '$$HostElementKey$$'; var ShadowedNodeKey = '$$ShadowedNodeKey$$'; function fastDefineProperty(node, propName, config) { var shadowedNode = node; { var value = config.value; // in prod, we prioritize performance shadowedNode[propName] = value; } } function setNodeOwnerKey(node, value) { fastDefineProperty(node, HostElementKey, { value: value, configurable: true }); } function setNodeKey(node, value) { fastDefineProperty(node, ShadowedNodeKey, { value: value }); } function getNodeOwnerKey(node) { return node[HostElementKey]; } function getNodeNearestOwnerKey(node) { var host = node; var hostKey; // search for the first element with owner identity (just in case of manually inserted elements) while (!isNull(host)) { hostKey = getNodeOwnerKey(host); if (!isUndefined(hostKey)) { return hostKey; } host = parentNodeGetter.call(host); } } function getNodeKey(node) { return node[ShadowedNodeKey]; } /** * This function does not traverse up for performance reasons, but is sufficient for most use * cases. If we need to traverse up and verify those nodes that don't have owner key, use * isNodeDeepShadowed instead. */ function isNodeShadowed(node) { return !isUndefined(getNodeOwnerKey(node)); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ // inside another slot. function foldSlotElement(slot) { var parent = parentElementGetter.call(slot); while (!isNull(parent) && isSlotElement(parent)) { slot = parent; parent = parentElementGetter.call(slot); } return slot; } function isNodeSlotted(host, node) { var hostKey = getNodeKey(host); // this routine assumes that the node is coming from a different shadow (it is not owned by the host) // just in case the provided node is not an element var currentElement = node instanceof Element ? node : parentElementGetter.call(node); while (!isNull(currentElement) && currentElement !== host) { var elmOwnerKey = getNodeNearestOwnerKey(currentElement); var parent = parentElementGetter.call(currentElement); if (elmOwnerKey === hostKey) { // we have reached an element inside the host's template, and only if // that element is an slot, then the node is considered slotted return isSlotElement(currentElement); } else if (parent === host) { return false; } else if (!isNull(parent) && getNodeNearestOwnerKey(parent) !== elmOwnerKey) { // we are crossing a boundary of some sort since the elm and its parent // have different owner key. for slotted elements, this is possible // if the parent happens to be a slot. if (isSlotElement(parent)) { /** * the slot parent might be allocated inside another slot, think of: * <x-root> (<--- root element) * <x-parent> (<--- own by x-root) * <x-child> (<--- own by x-root) * <slot> (<--- own by x-child) * <slot> (<--- own by x-parent) * <div> (<--- own by x-root) * * while checking if x-parent has the div slotted, we need to traverse * up, but when finding the first slot, we skip that one in favor of the * most outer slot parent before jumping into its corresponding host. */ currentElement = getNodeOwner(foldSlotElement(parent)); if (!isNull(currentElement)) { if (currentElement === host) { // the slot element is a top level element inside the shadow // of a host that was allocated into host in question return true; } else if (getNodeNearestOwnerKey(currentElement) === hostKey) { // the slot element is an element inside the shadow // of a host that was allocated into host in question return true; } } } else { return false; } } else { currentElement = parent; } } return false; } function getNodeOwner(node) { if (!(node instanceof Node)) { return null; } var ownerKey = getNodeNearestOwnerKey(node); if (isUndefined(ownerKey)) { return null; } var nodeOwner = node; // At this point, node is a valid node with owner identity, now we need to find the owner node // search for a custom element with a VM that owns the first element with owner identity attached to it while (!isNull(nodeOwner) && getNodeKey(nodeOwner) !== ownerKey) { nodeOwner = parentNodeGetter.call(nodeOwner); } if (isNull(nodeOwner)) { return null; } return nodeOwner; } function isSlotElement(node) { return node instanceof HTMLSlotElement; } function isNodeOwnedBy(owner, node) { var ownerKey = getNodeNearestOwnerKey(node); return isUndefined(ownerKey) || getNodeKey(owner) === ownerKey; } function shadowRootChildNodes(root) { var elm = getHost(root); return getAllMatches(elm, arrayFromCollection(childNodesGetter.call(elm))); } function getAllSlottedMatches(host, nodeList) { var filteredAndPatched = []; for (var i = 0, len = nodeList.length; i < len; i += 1) { var node = nodeList[i]; if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) { ArrayPush.call(filteredAndPatched, node); } } return filteredAndPatched; } function getFirstSlottedMatch(host, nodeList) { for (var i = 0, len = nodeList.length; i < len; i += 1) { var node = nodeList[i]; if (!isNodeOwnedBy(host, node) && isNodeSlotted(host, node)) { return node; } } return null; } function getAllMatches(owner, nodeList) { var filteredAndPatched = []; for (var i = 0, len = nodeList.length; i < len; i += 1) { var node = nodeList[i]; var isOwned = isNodeOwnedBy(owner, node); if (isOwned) { // Patch querySelector, querySelectorAll, etc // if element is owned by VM ArrayPush.call(filteredAndPatched, node); } } return filteredAndPatched; } function getFirstMatch(owner, nodeList) { for (var i = 0, len = nodeList.length; i < len; i += 1) { if (isNodeOwnedBy(owner, nodeList[i])) { return nodeList[i]; } } return null; } function shadowRootQuerySelector(root, selector) { var elm = getHost(root); var nodeList = arrayFromCollection(querySelectorAll$1.call(elm, selector)); return getFirstMatch(elm, nodeList); } function shadowRootQuerySelectorAll(root, selector) { var elm = getHost(root); var nodeList = querySelectorAll$1.call(elm, selector); return getAllMatches(elm, arrayFromCollection(nodeList)); } function getFilteredChildNodes(node) { var children; if (!isHostElement(node) && !isSlotElement(node)) { // regular element - fast path children = childNodesGetter.call(node); return arrayFromCollection(children); } if (isHostElement(node)) { // we need to get only the nodes that were slotted var slots = arrayFromCollection(querySelectorAll$1.call(node, 'slot')); var resolver_1 = getShadowRootResolver(getShadowRoot(node)); // Typescript is inferring the wrong function type for this particular // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972 // @ts-ignore type-mismatch return ArrayReduce.call(slots, function (seed, slot) { if (resolver_1 === getShadowRootResolver(slot)) { ArrayPush.apply(seed, getFilteredSlotAssignedNodes(slot)); } return seed; }, []); } else { // slot element children = arrayFromCollection(childNodesGetter.call(node)); var resolver_2 = getShadowRootResolver(node); // Typescript is inferring the wrong function type for this particular // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972 // @ts-ignore type-mismatch return ArrayReduce.call(children, function (seed, child) { if (resolver_2 === getShadowRootResolver(child)) { ArrayPush.call(seed, child); } return seed; }, []); } } function getFilteredSlotAssignedNodes(slot) { var owner = getNodeOwner(slot); if (isNull(owner)) { return []; } var childNodes = arrayFromCollection(childNodesGetter.call(slot)); // Typescript is inferring the wrong function type for this particular // overloaded method: https://github.com/Microsoft/TypeScript/issues/27972 // @ts-ignore type-mismatch return ArrayReduce.call(childNodes, function (seed, child) { if (!isNodeOwnedBy(owner, child)) { ArrayPush.call(seed, child); } return seed; }, []); } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ function getTextContent(node) { switch (node.nodeType) { case ELEMENT_NODE: { var childNodes = getFilteredChildNodes(node); var content = ''; for (var i = 0, len = childNodes.length; i < len; i += 1) { var currentNode = childNodes[i]; if (currentNode.nodeType !== COMMENT_NODE) { content += getTextContent(currentNode); } } return content; } default: return node.nodeValue; } } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var Items$1 = createHiddenField('StaticNodeListItems', 'synthetic-shadow'); function StaticNodeList() { throw new TypeError('Illegal constructor'); } StaticNodeList.prototype = create$1(NodeList.prototype, (_b = { constructor: { writable: true, configurable: true, value: StaticNodeList }, item: { writable: true, enumerable: true, configurable: true, value: function (index) { return this[index]; } }, length: { enumerable: true, configurable: true, get: function () { return getHiddenField(this, Items$1).length; } }, // Iterator protocol forEach: { writable: true, enumerable: true, configurable: true, value: function (cb, thisArg) { forEach.call(getHiddenField(this, Items$1), cb, thisArg); } }, entries: { writable: true, enumerable: true, configurable: true, value: function () { return ArrayMap.call(getHiddenField(this, Items$1), function (v, i) { return [i, v]; }); } }, keys: { writable: true, enumerable: true, configurable: true, value: function () { return ArrayMap.call(getHiddenField(this, Items$1), function (_v, i) { return i; }); } }, values: { writable: true, enumerable: true, configurable: true, value: function () { return getHiddenField(this, Items$1); } } }, _b[Symbol.iterator] = { writable: true, configurable: true, value: function () { var _this = this; var nextIndex = 0; return { next: function () { var items = getHiddenField(_this, Items$1); return nextIndex < items.length ? { value: items[nextIndex++], done: false } : { done: true }; } }; } }, _b[Symbol.toStringTag] = { configurable: true, get: function () { return 'NodeList'; } }, // IE11 doesn't support Symbol.toStringTag, in which case we // provide the regular toString method. _b.toString = { writable: true, configurable: true, value: function () { return '[object NodeList]'; } }, _b)); // prototype inheritance dance setPrototypeOf$1(StaticNodeList, NodeList); function createStaticNodeList(items) { var nodeList = create$1(StaticNodeList.prototype); setHiddenField(nodeList, Items$1, items); // setting static indexes forEach.call(items, function (item, index) { defineProperty$1(nodeList, index, { value: item, enumerable: true, configurable: true }); }); return nodeList; } /* * Copyright (c) 2018, salesforce.com, inc. * All rights reserved. * SPDX-License-Identifier: MIT * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ var Items = createHiddenField('StaticHTMLCollectionItems', 'synthetic-shadow'); function StaticHTMLCollection() { throw new TypeError('Illegal constructor'); } StaticHTMLCollection.prototype = create$1(HTMLCollection.prototype, (_c = { constructor: { writable: true, configurable: true, value: StaticHTMLCollection }, item: { writable: true, enumerable: true, configurable: true,