UNPKG

lwc

Version:

Lightning Web Components (LWC)

1,785 lines (1,485 loc) 222 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /* proxy-compat-disable */ /** * 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 */ const { assign: assign$2, create: create$3, defineProperties: defineProperties$2, defineProperty: defineProperty$2, freeze: freeze$2, getOwnPropertyDescriptor: getOwnPropertyDescriptor$3, getOwnPropertyNames: getOwnPropertyNames$3, getPrototypeOf: getPrototypeOf$3, hasOwnProperty: hasOwnProperty$3, isFrozen: isFrozen$2, keys: keys$2, seal: seal$2, setPrototypeOf: setPrototypeOf$2 } = Object; const { filter: ArrayFilter$1, find: ArrayFind$1, indexOf: ArrayIndexOf$2, join: ArrayJoin$1, map: ArrayMap$2, push: ArrayPush$3, reduce: ArrayReduce$1, reverse: ArrayReverse$1, slice: ArraySlice$1, splice: ArraySplice$2, unshift: ArrayUnshift$1, forEach: forEach$1 } = Array.prototype; const { fromCharCode: StringFromCharCode$1 } = String; const { charCodeAt: StringCharCodeAt$1, replace: StringReplace$1, slice: StringSlice$1, toLowerCase: StringToLowerCase$1 } = String.prototype; function isUndefined$4(obj) { return obj === undefined; } function isNull$1(obj) { return obj === null; } function isFunction$2(obj) { return typeof obj === 'function'; } function isObject$1(obj) { return typeof obj === 'object'; } function isString$1(obj) { return typeof obj === 'string'; } /* * 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 */ /** * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and * ariaGrabbed) are deprecated: * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes * * The above list of 46 aria attributes is consistent with the following resources: * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060 * https://wicg.github.io/aom/spec/aria-reflection.html */ const AriaPropertyNames$1 = ['ariaActiveDescendant', 'ariaAtomic', 'ariaAutoComplete', 'ariaBusy', 'ariaChecked', 'ariaColCount', 'ariaColIndex', 'ariaColSpan', 'ariaControls', 'ariaCurrent', 'ariaDescribedBy', 'ariaDetails', 'ariaDisabled', 'ariaErrorMessage', 'ariaExpanded', 'ariaFlowTo', 'ariaHasPopup', 'ariaHidden', 'ariaInvalid', 'ariaKeyShortcuts', 'ariaLabel', 'ariaLabelledBy', 'ariaLevel', 'ariaLive', 'ariaModal', 'ariaMultiLine', 'ariaMultiSelectable', 'ariaOrientation', 'ariaOwns', 'ariaPlaceholder', 'ariaPosInSet', 'ariaPressed', 'ariaReadOnly', 'ariaRelevant', 'ariaRequired', 'ariaRoleDescription', 'ariaRowCount', 'ariaRowIndex', 'ariaRowSpan', 'ariaSelected', 'ariaSetSize', 'ariaSort', 'ariaValueMax', 'ariaValueMin', 'ariaValueNow', 'ariaValueText', 'role']; const { AriaAttrNameToPropNameMap: AriaAttrNameToPropNameMap$1, AriaPropNameToAttrNameMap: AriaPropNameToAttrNameMap$1 } = /*@__PURE__*/(() => { const AriaAttrNameToPropNameMap = create$3(null); const AriaPropNameToAttrNameMap = create$3(null); // Synthetic creation of all AOM property descriptors for Custom Elements forEach$1.call(AriaPropertyNames$1, propName => { const attrName = StringToLowerCase$1.call(StringReplace$1.call(propName, /^aria/, () => 'aria-')); AriaAttrNameToPropNameMap[attrName] = propName; AriaPropNameToAttrNameMap[propName] = attrName; }); return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap }; })(); function isAriaAttribute(attrName) { return attrName in AriaAttrNameToPropNameMap$1; } /* * 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 const _globalThis$1 = /*@__PURE__*/function () { // On recent browsers, `globalThis` is already defined. In this case return it directly. if (typeof globalThis === 'object') { return globalThis; } let _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; }(); /* * Copyright (c) 2020, 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 */ // The following list contains a mix of both void elements from the HTML and the XML namespace // without distinction. const VOID_ELEMENTS = ['area', 'base', 'br', 'circle', 'col', 'ellipse', 'feBlend', 'feColorMatrix', 'feFuncR', 'feFuncG', 'feFuncB', 'feFuncA', 'feImage', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDropShadow', 'feFlood', 'feGaussianBlur', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'feSpecularLighting', 'feTile', 'feTurbulence', 'fePointLight', 'embed', 'hr', 'img', 'input', 'keygen', 'line', 'link', 'menuitem', 'meta', 'param', 'rect', 'source', 'track', 'wbr']; const VOID_ELEMENTS_SET = new Set(VOID_ELEMENTS); function isVoidElement(name) { return VOID_ELEMENTS_SET.has(name); } /* * Copyright (c) 2020, 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 */ /** * Maps boolean attribute name to supported tags: 'boolean attr name' => Set of allowed tag names * that supports them. */ const BOOLEAN_ATTRIBUTES = new Map([['autofocus', new Set(['button', 'input', 'keygen', 'select', 'textarea'])], ['autoplay', new Set(['audio', 'video'])], ['checked', new Set(['command', 'input'])], ['disabled', new Set(['button', 'command', 'fieldset', 'input', 'keygen', 'optgroup', 'select', 'textarea'])], ['formnovalidate', new Set(['button'])], ['hidden', new Set()], ['loop', new Set(['audio', 'bgsound', 'marquee', 'video'])], ['multiple', new Set(['input', 'select'])], ['muted', new Set(['audio', 'video'])], ['novalidate', new Set(['form'])], ['open', new Set(['details'])], ['readonly', new Set(['input', 'textarea'])], ['required', new Set(['input', 'select', 'textarea'])], ['reversed', new Set(['ol'])], ['selected', new Set(['option'])]]); function isBooleanAttribute(attrName, tagName) { const allowedTagNames = BOOLEAN_ATTRIBUTES.get(attrName); return allowedTagNames !== undefined && (allowedTagNames.size === 0 || allowedTagNames.has(tagName)); } const GLOBAL_ATTRIBUTE = new Set(['role', 'accesskey', 'class', 'contenteditable', 'contextmenu', 'dir', 'draggable', 'dropzone', 'hidden', 'id', 'itemprop', 'lang', 'slot', 'spellcheck', 'style', 'tabindex', 'title']); function isGlobalHtmlAttribute(attrName) { return GLOBAL_ATTRIBUTE.has(attrName); } /** * Map composed of properties to attributes not following the HTML property to attribute mapping * convention. */ const NO_STANDARD_PROPERTY_ATTRIBUTE_MAPPING$1 = new Map([['accessKey', 'accesskey'], ['readOnly', 'readonly'], ['tabIndex', 'tabindex'], ['bgColor', 'bgcolor'], ['colSpan', 'colspan'], ['rowSpan', 'rowspan'], ['contentEditable', 'contenteditable'], ['crossOrigin', 'crossorigin'], ['dateTime', 'datetime'], ['formAction', 'formaction'], ['isMap', 'ismap'], ['maxLength', 'maxlength'], ['minLength', 'minlength'], ['noValidate', 'novalidate'], ['useMap', 'usemap'], ['htmlFor', 'for']]); /** * Map associating previously transformed HTML property into HTML attribute. */ const CACHED_PROPERTY_ATTRIBUTE_MAPPING$1 = new Map(); function htmlPropertyToAttribute$1(propName) { const ariaAttributeName = AriaPropNameToAttrNameMap$1[propName]; if (!isUndefined$4(ariaAttributeName)) { return ariaAttributeName; } const specialAttributeName = NO_STANDARD_PROPERTY_ATTRIBUTE_MAPPING$1.get(propName); if (!isUndefined$4(specialAttributeName)) { return specialAttributeName; } const cachedAttributeName = CACHED_PROPERTY_ATTRIBUTE_MAPPING$1.get(propName); if (!isUndefined$4(cachedAttributeName)) { return cachedAttributeName; } let attributeName = ''; for (let i = 0, len = propName.length; i < len; i++) { const code = StringCharCodeAt$1.call(propName, i); if (code >= 65 && // "A" code <= 90 // "Z" ) { attributeName += '-' + StringFromCharCode$1(code + 32); } else { attributeName += StringFromCharCode$1(code); } } CACHED_PROPERTY_ATTRIBUTE_MAPPING$1.set(propName, attributeName); return attributeName; } /** version: 2.1.2 */ /* * Copyright (c) 2020, 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 */ /** * The following constructor might be used in either the constructor or the connectedCallback. In * order to ensure that the component evaluates, we attach those mock constructors to the global * object. */ if (typeof Event !== 'function' && typeof CustomEvent !== 'function') { class Event {} class CustomEvent extends Event {} defineProperties$2(_globalThis$1, { Event: { value: Event, configurable: true, writable: true }, CustomEvent: { value: CustomEvent, configurable: true, writable: true } }); } /* proxy-compat-disable */ /** * 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 */ function invariant(value, msg) { if (!value) { throw new Error(`Invariant Violation: ${msg}`); } } function isTrue$1(value, msg) { if (!value) { throw new Error(`Assert Violation: ${msg}`); } } function isFalse$1(value, msg) { if (value) { throw new Error(`Assert Violation: ${msg}`); } } function fail(msg) { throw new Error(msg); } var assert = /*#__PURE__*/Object.freeze({ __proto__: null, invariant: invariant, isTrue: isTrue$1, isFalse: isFalse$1, fail: fail }); /* * 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 */ const { assign: assign$1, create: create$2, defineProperties: defineProperties$1, defineProperty: defineProperty$1, freeze: freeze$1, getOwnPropertyDescriptor: getOwnPropertyDescriptor$2, getOwnPropertyNames: getOwnPropertyNames$2, getPrototypeOf: getPrototypeOf$2, hasOwnProperty: hasOwnProperty$2, isFrozen: isFrozen$1, keys: keys$1, seal: seal$1, setPrototypeOf: setPrototypeOf$1 } = Object; const { isArray: isArray$1 } = Array; const { filter: ArrayFilter, find: ArrayFind, indexOf: ArrayIndexOf$1, join: ArrayJoin, map: ArrayMap$1, push: ArrayPush$2, reduce: ArrayReduce, reverse: ArrayReverse, slice: ArraySlice, splice: ArraySplice$1, unshift: ArrayUnshift, forEach } = Array.prototype; const { fromCharCode: StringFromCharCode } = String; const { charCodeAt: StringCharCodeAt, replace: StringReplace, slice: StringSlice, toLowerCase: StringToLowerCase } = String.prototype; function isUndefined$3(obj) { return obj === undefined; } function isNull(obj) { return obj === null; } function isTrue$2(obj) { return obj === true; } function isFalse$2(obj) { return obj === false; } function isFunction$1(obj) { return typeof obj === 'function'; } function isObject(obj) { return typeof obj === 'object'; } function isString(obj) { return typeof obj === 'string'; } function isNumber(obj) { return typeof obj === 'number'; } const OtS$1 = {}.toString; function toString$1(obj) { if (obj && obj.toString) { // Arrays might hold objects with "null" prototype So using // Array.prototype.toString directly will cause an error Iterate through // all the items and handle individually. if (isArray$1(obj)) { return ArrayJoin.call(ArrayMap$1.call(obj, toString$1), ','); } return obj.toString(); } else if (typeof obj === 'object') { return OtS$1.call(obj); } else { return obj + ''; } } function getPropertyDescriptor(o, p) { do { const d = getOwnPropertyDescriptor$2(o, p); if (!isUndefined$3(d)) { return d; } o = getPrototypeOf$2(o); } while (o !== 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 */ /** * According to the following list, there are 48 aria attributes of which two (ariaDropEffect and * ariaGrabbed) are deprecated: * https://www.w3.org/TR/wai-aria-1.1/#x6-6-definitions-of-states-and-properties-all-aria-attributes * * The above list of 46 aria attributes is consistent with the following resources: * https://github.com/w3c/aria/pull/708/files#diff-eacf331f0ffc35d4b482f1d15a887d3bR11060 * https://wicg.github.io/aom/spec/aria-reflection.html */ const AriaPropertyNames = ['ariaActiveDescendant', 'ariaAtomic', 'ariaAutoComplete', 'ariaBusy', 'ariaChecked', 'ariaColCount', 'ariaColIndex', 'ariaColSpan', 'ariaControls', 'ariaCurrent', 'ariaDescribedBy', 'ariaDetails', 'ariaDisabled', 'ariaErrorMessage', 'ariaExpanded', 'ariaFlowTo', 'ariaHasPopup', 'ariaHidden', 'ariaInvalid', 'ariaKeyShortcuts', 'ariaLabel', 'ariaLabelledBy', 'ariaLevel', 'ariaLive', 'ariaModal', 'ariaMultiLine', 'ariaMultiSelectable', 'ariaOrientation', 'ariaOwns', 'ariaPlaceholder', 'ariaPosInSet', 'ariaPressed', 'ariaReadOnly', 'ariaRelevant', 'ariaRequired', 'ariaRoleDescription', 'ariaRowCount', 'ariaRowIndex', 'ariaRowSpan', 'ariaSelected', 'ariaSetSize', 'ariaSort', 'ariaValueMax', 'ariaValueMin', 'ariaValueNow', 'ariaValueText', 'role']; const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__*/(() => { const AriaAttrNameToPropNameMap = create$2(null); const AriaPropNameToAttrNameMap = create$2(null); // Synthetic creation of all AOM property descriptors for Custom Elements forEach.call(AriaPropertyNames, propName => { const attrName = StringToLowerCase.call(StringReplace.call(propName, /^aria/, () => 'aria-')); AriaAttrNameToPropNameMap[attrName] = propName; AriaPropNameToAttrNameMap[propName] = attrName; }); return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap }; })(); /* * 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. const hasNativeSymbolSupport = /*@__PURE__*/(() => 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}$$`; } const hiddenFieldsMap = new WeakMap(); function setHiddenField(o, field, value) { let valuesByField = hiddenFieldsMap.get(o); if (isUndefined$3(valuesByField)) { valuesByField = create$2(null); hiddenFieldsMap.set(o, valuesByField); } valuesByField[field] = value; } function getHiddenField(o, field) { const valuesByField = hiddenFieldsMap.get(o); if (!isUndefined$3(valuesByField)) { return valuesByField[field]; } } /** * Map composed of properties to attributes not following the HTML property to attribute mapping * convention. */ const NO_STANDARD_PROPERTY_ATTRIBUTE_MAPPING = new Map([['accessKey', 'accesskey'], ['readOnly', 'readonly'], ['tabIndex', 'tabindex'], ['bgColor', 'bgcolor'], ['colSpan', 'colspan'], ['rowSpan', 'rowspan'], ['contentEditable', 'contenteditable'], ['crossOrigin', 'crossorigin'], ['dateTime', 'datetime'], ['formAction', 'formaction'], ['isMap', 'ismap'], ['maxLength', 'maxlength'], ['minLength', 'minlength'], ['noValidate', 'novalidate'], ['useMap', 'usemap'], ['htmlFor', 'for']]); /** * Map associating previously transformed HTML property into HTML attribute. */ const CACHED_PROPERTY_ATTRIBUTE_MAPPING = new Map(); function htmlPropertyToAttribute(propName) { const ariaAttributeName = AriaPropNameToAttrNameMap[propName]; if (!isUndefined$3(ariaAttributeName)) { return ariaAttributeName; } const specialAttributeName = NO_STANDARD_PROPERTY_ATTRIBUTE_MAPPING.get(propName); if (!isUndefined$3(specialAttributeName)) { return specialAttributeName; } const cachedAttributeName = CACHED_PROPERTY_ATTRIBUTE_MAPPING.get(propName); if (!isUndefined$3(cachedAttributeName)) { return cachedAttributeName; } let attributeName = ''; for (let i = 0, len = propName.length; i < len; i++) { const code = StringCharCodeAt.call(propName, i); if (code >= 65 && // "A" code <= 90 // "Z" ) { attributeName += '-' + StringFromCharCode(code + 32); } else { attributeName += StringFromCharCode(code); } } CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName); return attributeName; } /** 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 */ let nextTickCallbackQueue = []; const SPACE_CHAR = 32; const EmptyObject = seal$1(create$2(null)); const EmptyArray = seal$1([]); function flushCallbackQueue() { if (process.env.NODE_ENV !== 'production') { if (nextTickCallbackQueue.length === 0) { throw new Error(`Internal Error: If callbackQueue is scheduled, it is because there must be at least one callback on this pending queue.`); } } const callbacks = nextTickCallbackQueue; nextTickCallbackQueue = []; // reset to a new queue for (let i = 0, len = callbacks.length; i < len; i += 1) { callbacks[i](); } } function addCallbackToNextTick(callback) { if (process.env.NODE_ENV !== 'production') { if (!isFunction$1(callback)) { throw new Error(`Internal Error: addCallbackToNextTick() can only accept a function callback`); } } if (nextTickCallbackQueue.length === 0) { Promise.resolve().then(flushCallbackQueue); } ArrayPush$2.call(nextTickCallbackQueue, callback); } function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } /* * Copyright (c) 2019, 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 */ const { create: create$1 } = Object; const { splice: ArraySplice, indexOf: ArrayIndexOf, push: ArrayPush$1 } = Array.prototype; const TargetToReactiveRecordMap = new WeakMap(); function isUndefined$2(obj) { return obj === undefined; } function getReactiveRecord(target) { let reactiveRecord = TargetToReactiveRecordMap.get(target); if (isUndefined$2(reactiveRecord)) { const newRecord = create$1(null); reactiveRecord = newRecord; TargetToReactiveRecordMap.set(target, newRecord); } return reactiveRecord; } let currentReactiveObserver = null; function valueMutated(target, key) { const reactiveRecord = TargetToReactiveRecordMap.get(target); if (!isUndefined$2(reactiveRecord)) { const reactiveObservers = reactiveRecord[key]; if (!isUndefined$2(reactiveObservers)) { for (let i = 0, len = reactiveObservers.length; i < len; i += 1) { const ro = reactiveObservers[i]; ro.notify(); } } } } function valueObserved(target, key) { // We should determine if an active Observing Record is present to track mutations. if (currentReactiveObserver === null) { return; } const ro = currentReactiveObserver; const reactiveRecord = getReactiveRecord(target); let reactiveObservers = reactiveRecord[key]; if (isUndefined$2(reactiveObservers)) { reactiveObservers = []; reactiveRecord[key] = reactiveObservers; } else if (reactiveObservers[0] === ro) { return; // perf optimization considering that most subscriptions will come from the same record } if (ArrayIndexOf.call(reactiveObservers, ro) === -1) { ro.link(reactiveObservers); } } class ReactiveObserver { constructor(callback) { this.listeners = []; this.callback = callback; } observe(job) { const inceptionReactiveRecord = currentReactiveObserver; currentReactiveObserver = this; let error; try { job(); } catch (e) { error = Object(e); } finally { currentReactiveObserver = inceptionReactiveRecord; if (error !== undefined) { throw error; // eslint-disable-line no-unsafe-finally } } } /** * This method is responsible for disconnecting the Reactive Observer * from any Reactive Record that has a reference to it, to prevent future * notifications about previously recorded access. */ reset() { const { listeners } = this; const len = listeners.length; if (len > 0) { for (let i = 0; i < len; i += 1) { const set = listeners[i]; const pos = ArrayIndexOf.call(listeners[i], this); ArraySplice.call(set, pos, 1); } listeners.length = 0; } } // friend methods notify() { this.callback.call(undefined, this); } link(reactiveObservers) { ArrayPush$1.call(reactiveObservers, this); // we keep track of observing records where the observing record was added to so we can do some clean up later on ArrayPush$1.call(this.listeners, reactiveObservers); } } /* * 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 componentValueMutated(vm, key) { valueMutated(vm.component, key); } function componentValueObserved(vm, key) { valueObserved(vm.component, key); } /* * 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 getComponentTag(vm) { return `<${StringToLowerCase.call(vm.tagName)}>`; } // TODO [#1695]: Unify getComponentStack and getErrorComponentStack function getComponentStack(vm) { const stack = []; let prefix = ''; while (!isNull(vm.owner)) { ArrayPush$2.call(stack, prefix + getComponentTag(vm)); vm = vm.owner; prefix += '\t'; } return ArrayJoin.call(stack, '\n'); } function getErrorComponentStack(vm) { const wcStack = []; let currentVm = vm; while (!isNull(currentVm)) { ArrayPush$2.call(wcStack, getComponentTag(currentVm)); currentVm = currentVm.owner; } return wcStack.reverse().join('\n\t'); } /* * 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 logError(message, vm) { let msg = `[LWC error]: ${message}`; if (!isUndefined$3(vm)) { msg = `${msg}\n${getComponentStack(vm)}`; } if (process.env.NODE_ENV === 'test') { /* eslint-disable-next-line no-console */ console.error(msg); return; } try { throw new Error(msg); } catch (e) { /* eslint-disable-next-line no-console */ console.error(e); } } /* * 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 handleEvent(event, vnode) { const { type } = event; const { data: { on } } = vnode; const handler = on && on[type]; // call event handler if exists if (handler) { handler.call(undefined, event); } } function createListener() { return function handler(event) { handleEvent(event, handler.vnode); }; } function updateAllEventListeners(oldVnode, vnode) { if (isUndefined$3(oldVnode.listener)) { createAllEventListeners(vnode); } else { vnode.listener = oldVnode.listener; vnode.listener.vnode = vnode; } } function createAllEventListeners(vnode) { const { elm, data: { on }, owner: { renderer } } = vnode; if (isUndefined$3(on)) { return; } const listener = vnode.listener = createListener(); listener.vnode = vnode; let name; for (name in on) { renderer.addEventListener(elm, name, listener); } } var modEvents = { update: updateAllEventListeners, create: createAllEventListeners }; /* * 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 */ const defaultDefHTMLPropertyNames = ['accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title']; function offsetPropertyErrorMessage(name) { return `Using the \`${name}\` property is an anti-pattern because it rounds the value to an integer. Instead, use the \`getBoundingClientRect\` method to obtain fractional values for the size of an element and its position relative to the viewport.`; } // Global HTML Attributes & Properties // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement const globalHTMLProperties = assign$1(create$2(null), { accessKey: { attribute: 'accesskey' }, accessKeyLabel: { readOnly: true }, className: { attribute: 'class', error: 'Using the `className` property is an anti-pattern because of slow runtime behavior and potential conflicts with classes provided by the owner element. Use the `classList` API instead.' }, contentEditable: { attribute: 'contenteditable' }, dataset: { readOnly: true, error: "Using the `dataset` property is an anti-pattern because it can't be statically analyzed. Expose each property individually using the `@api` decorator instead." }, dir: { attribute: 'dir' }, draggable: { attribute: 'draggable' }, dropzone: { attribute: 'dropzone', readOnly: true }, hidden: { attribute: 'hidden' }, id: { attribute: 'id' }, inputMode: { attribute: 'inputmode' }, lang: { attribute: 'lang' }, slot: { attribute: 'slot', error: 'Using the `slot` property is an anti-pattern.' }, spellcheck: { attribute: 'spellcheck' }, style: { attribute: 'style' }, tabIndex: { attribute: 'tabindex' }, title: { attribute: 'title' }, translate: { attribute: 'translate' }, // additional "global attributes" that are not present in the link above. isContentEditable: { readOnly: true }, offsetHeight: { readOnly: true, error: offsetPropertyErrorMessage('offsetHeight') }, offsetLeft: { readOnly: true, error: offsetPropertyErrorMessage('offsetLeft') }, offsetParent: { readOnly: true }, offsetTop: { readOnly: true, error: offsetPropertyErrorMessage('offsetTop') }, offsetWidth: { readOnly: true, error: offsetPropertyErrorMessage('offsetWidth') }, role: { attribute: 'role' } }); let controlledElement = null; let controlledAttributeName; function isAttributeLocked(elm, attrName) { return elm !== controlledElement || attrName !== controlledAttributeName; } function lockAttribute(_elm, _key) { controlledElement = null; controlledAttributeName = undefined; } function unlockAttribute(elm, key) { controlledElement = elm; controlledAttributeName = key; } /* * 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 */ const xlinkNS = 'http://www.w3.org/1999/xlink'; const xmlNS = 'http://www.w3.org/XML/1998/namespace'; const ColonCharCode = 58; function updateAttrs(oldVnode, vnode) { const { data: { attrs }, owner: { renderer } } = vnode; if (isUndefined$3(attrs)) { return; } let { data: { attrs: oldAttrs } } = oldVnode; if (oldAttrs === attrs) { return; } if (process.env.NODE_ENV !== 'production') { assert.invariant(isUndefined$3(oldAttrs) || keys$1(oldAttrs).join(',') === keys$1(attrs).join(','), `vnode.data.attrs cannot change shape.`); } const elm = vnode.elm; const { setAttribute, removeAttribute } = renderer; let key; oldAttrs = isUndefined$3(oldAttrs) ? EmptyObject : oldAttrs; // update modified attributes, add new attributes // this routine is only useful for data-* attributes in all kind of elements // and aria-* in standard elements (custom elements will use props for these) for (key in attrs) { const cur = attrs[key]; const old = oldAttrs[key]; if (old !== cur) { unlockAttribute(elm, key); if (StringCharCodeAt.call(key, 3) === ColonCharCode) { // Assume xml namespace setAttribute(elm, key, cur, xmlNS); } else if (StringCharCodeAt.call(key, 5) === ColonCharCode) { // Assume xlink namespace setAttribute(elm, key, cur, xlinkNS); } else if (isNull(cur)) { removeAttribute(elm, key); } else { setAttribute(elm, key, cur); } lockAttribute(); } } } const emptyVNode$3 = { data: {} }; var modAttrs = { create: vnode => updateAttrs(emptyVNode$3, vnode), update: updateAttrs }; /* * 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 isLiveBindingProp(sel, key) { // For properties with live bindings, we read values from the DOM element // instead of relying on internally tracked values. return sel === 'input' && (key === 'value' || key === 'checked'); } function update(oldVnode, vnode) { const props = vnode.data.props; if (isUndefined$3(props)) { return; } const oldProps = oldVnode.data.props; if (oldProps === props) { return; } if (process.env.NODE_ENV !== 'production') { assert.invariant(isUndefined$3(oldProps) || keys$1(oldProps).join(',') === keys$1(props).join(','), 'vnode.data.props cannot change shape.'); } const isFirstPatch = isUndefined$3(oldProps); const { elm, sel, owner: { renderer } } = vnode; for (const key in props) { const cur = props[key]; // if it is the first time this element is patched, or the current value is different to the previous value... if (isFirstPatch || cur !== (isLiveBindingProp(sel, key) ? renderer.getProperty(elm, key) : oldProps[key])) { renderer.setProperty(elm, key, cur); } } } const emptyVNode$2 = { data: {} }; var modProps = { create: vnode => update(emptyVNode$2, vnode), update }; /* * 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 */ const classNameToClassMap = create$2(null); function getMapFromClassName(className) { // Intentionally using == to match undefined and null values from computed style attribute if (className == null) { return EmptyObject; } // computed class names must be string className = isString(className) ? className : className + ''; let map = classNameToClassMap[className]; if (map) { return map; } map = create$2(null); let start = 0; let o; const len = className.length; for (o = 0; o < len; o++) { if (StringCharCodeAt.call(className, o) === SPACE_CHAR) { if (o > start) { map[StringSlice.call(className, start, o)] = true; } start = o + 1; } } if (o > start) { map[StringSlice.call(className, start, o)] = true; } classNameToClassMap[className] = map; if (process.env.NODE_ENV !== 'production') { // just to make sure that this object never changes as part of the diffing algo freeze$1(map); } return map; } function updateClassAttribute(oldVnode, vnode) { const { elm, data: { className: newClass }, owner: { renderer } } = vnode; const { data: { className: oldClass } } = oldVnode; if (oldClass === newClass) { return; } const classList = renderer.getClassList(elm); const newClassMap = getMapFromClassName(newClass); const oldClassMap = getMapFromClassName(oldClass); let name; for (name in oldClassMap) { // remove only if it is not in the new class collection and it is not set from within the instance if (isUndefined$3(newClassMap[name])) { classList.remove(name); } } for (name in newClassMap) { if (isUndefined$3(oldClassMap[name])) { classList.add(name); } } } const emptyVNode$1 = { data: {} }; var modComputedClassName = { create: vnode => updateClassAttribute(emptyVNode$1, vnode), update: updateClassAttribute }; /* * 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 updateStyleAttribute(oldVnode, vnode) { const { elm, data: { style: newStyle }, owner: { renderer } } = vnode; const { setAttribute, removeAttribute } = renderer; if (oldVnode.data.style === newStyle) { return; } if (!isString(newStyle) || newStyle === '') { removeAttribute(elm, 'style'); } else { setAttribute(elm, 'style', newStyle); } } const emptyVNode = { data: {} }; var modComputedStyle = { create: vnode => updateStyleAttribute(emptyVNode, vnode), update: updateStyleAttribute }; /* * 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 */ // The compiler takes care of transforming the inline classnames into an object. It's faster to set the // different classnames properties individually instead of via a string. function createClassAttribute(vnode) { const { elm, data: { classMap }, owner: { renderer } } = vnode; if (isUndefined$3(classMap)) { return; } const classList = renderer.getClassList(elm); for (const name in classMap) { classList.add(name); } } var modStaticClassName = { create: createClassAttribute }; /* * 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 */ // The compiler takes care of transforming the inline style into an object. It's faster to set the // different style properties individually instead of via a string. function createStyleAttribute(vnode) { const { elm, data: { styleMap }, owner: { renderer } } = vnode; if (isUndefined$3(styleMap)) { return; } for (const name in styleMap) { renderer.setCSSStyleProperty(elm, name, styleMap[name]); } } var modStaticStyle = { create: createStyleAttribute }; /* * 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 */ /** @license Copyright (c) 2015 Simon Friis Vindum. This code may only be used under the MIT License found at https://github.com/snabbdom/snabbdom/blob/master/LICENSE Code distributed by Snabbdom as part of the Snabbdom project at https://github.com/snabbdom/snabbdom/ */ function isUndef(s) { return s === undefined; } function sameVnode(vnode1, vnode2) { return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel; } function isVNode(vnode) { return vnode != null; } function createKeyToOldIdx(children, beginIdx, endIdx) { const map = {}; let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys for (j = beginIdx; j <= endIdx; ++j) { ch = children[j]; if (isVNode(ch)) { key = ch.key; if (key !== undefined) { map[key] = j; } } } return map; } function addVnodes(parentElm, before, vnodes, startIdx, endIdx) { for (; startIdx <= endIdx; ++startIdx) { const ch = vnodes[startIdx]; if (isVNode(ch)) { ch.hook.create(ch); ch.hook.insert(ch, parentElm, before); } } } function removeVnodes(parentElm, vnodes, startIdx, endIdx) { for (; startIdx <= endIdx; ++startIdx) { const ch = vnodes[startIdx]; // text nodes do not have logic associated to them if (isVNode(ch)) { ch.hook.remove(ch, parentElm); } } } function updateDynamicChildren(parentElm, oldCh, newCh) { let oldStartIdx = 0; let newStartIdx = 0; let oldEndIdx = oldCh.length - 1; let oldStartVnode = oldCh[0]; let oldEndVnode = oldCh[oldEndIdx]; const newChEnd = newCh.length - 1; let newEndIdx = newChEnd; let newStartVnode = newCh[0]; let newEndVnode = newCh[newEndIdx]; let oldKeyToIdx; let idxInOld; let elmToMove; let before; while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) { if (!isVNode(oldStartVnode)) { oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left } else if (!isVNode(oldEndVnode)) { oldEndVnode = oldCh[--oldEndIdx]; } else if (!isVNode(newStartVnode)) { newStartVnode = newCh[++newStartIdx]; } else if (!isVNode(newEndVnode)) { newEndVnode = newCh[--newEndIdx]; } else if (sameVnode(oldStartVnode, newStartVnode)) { patchVnode(oldStartVnode, newStartVnode); oldStartVnode = oldCh[++oldStartIdx]; newStartVnode = newCh[++newStartIdx]; } else if (sameVnode(oldEndVnode, newEndVnode)) { patchVnode(oldEndVnode, newEndVnode); oldEndVnode = oldCh[--oldEndIdx]; newEndVnode = newCh[--newEndIdx]; } else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right patchVnode(oldStartVnode, newEndVnode); newEndVnode.hook.move(oldStartVnode, parentElm, oldEndVnode.owner.renderer.nextSibling(oldEndVnode.elm)); oldStartVnode = oldCh[++oldStartIdx]; newEndVnode = newCh[--newEndIdx]; } else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left patchVnode(oldEndVnode, newStartVnode); newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm); oldEndVnode = oldCh[--oldEndIdx]; newStartVnode = newCh[++newStartIdx]; } else { if (oldKeyToIdx === undefined) { oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx); } idxInOld = oldKeyToIdx[newStartVnode.key]; if (isUndef(idxInOld)) { // New element newStartVnode.hook.create(newStartVnode); newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm); newStartVnode = newCh[++newStartIdx]; } else { elmToMove = oldCh[idxInOld]; if (isVNode(elmToMove)) { if (elmToMove.sel !== newStartVnode.sel) { // New element newStartVnode.hook.create(newStartVnode); newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm); } else { patchVnode(elmToMove, newStartVnode); oldCh[idxInOld] = undefined; newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm); } } newStartVnode = newCh[++newStartIdx]; } } } if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) { if (oldStartIdx > oldEndIdx) { // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode. let i = newEndIdx; let n; do { n = newCh[++i]; } while (!isVNode(n) && i < newChEnd); before = isVNode(n) ? n.elm : null; addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx); } else { removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx); } } } function updateStaticChildren(parentElm, oldCh, newCh) { const oldChLength = oldCh.length; const newChLength = newCh.length; if (oldChLength === 0) { // the old list is empty, we can directly insert anything new addVnodes(parentElm, null, newCh, 0, newChLength); return; } if (newChLength === 0) { // the old list is nonempty and the new list is empty so we can directly remove all old nodes // this is the case in which the dynamic children of an if-directive should be removed removeVnodes(parentElm, oldCh, 0, oldChLength); return; } // if the old list is not empty, the new list MUST have the same // amount of nodes, that's why we call this static children let referenceElm = null; for (let i = newChLength - 1; i >= 0; i -= 1) { const vnode = newCh[i]; const oldVNode = oldCh[i]; if (vnode !== oldVNode) { if (isVNode(oldVNode)) { if (isVNode(vnode)) { // both vnodes must be equivalent, and se just need to patch them patchVnode(oldVNode, vnode); referenceElm = vnode.elm; } else { // removing the old vnode since the new one is null oldVNode.hook.remove(oldVNode, parentElm); } } else if (isVNode(vnode)) { // this condition is unnecessary vnode.hook.create(vnode); // insert the new node one since the old one is null vnode.hook.insert(vnode, parentElm, referenceElm); referenceElm = vnode.elm; } } } } function patchVnode(oldVnode, vnode) { if (oldVnode !== vnode) { vnode.elm = oldVnode.elm; vnode.hook.update(oldVnode, vnode); } } /* * 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 generateDataDescriptor(options) { return assign$1({ configurable: true, enumerable: true, writable: true }, options); } function generateAccessorDescriptor(options) { return assign$1({ configurable: true, enumerable: true }, options); } let isDomMutationAllowed = false; function unlockDomMutation() { if (process.env.NODE_ENV === 'production') { // this method should never leak to prod throw new ReferenceError(); } isDomMutationAllowed = true; } function lockDomMutation() { if (process.env.NODE_ENV === 'production') { // this method should never leak to prod throw new ReferenceError(); } isDomMutationAllowed = false; } function logMissingPortalError(name, type) { return logError(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`); } function patchElementWithRestrictions(elm, options) { if (process.env.NODE_ENV === 'production') { // this method should never leak to prod throw new ReferenceError(); } const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML'); const descriptors = { outerHTML: generateAccessorDescriptor({ get() { return originalOuterHTMLDescriptor.get.call(this); }, set(_value) { throw new TypeError(`Invalid attempt to set outerHTML on Element.`); } }) }; // Apply extra restriction related to DOM manipulation if the element is not a portal. if (isFalse$2(options.isPortal)) { const { appendChild, insertBefore, removeChild, replaceChild } = elm; const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue'); const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML'); const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent'); assign$1(descriptors, { appendChild: generateDataDescriptor({ value(aChild) { logMissingPortalError('appendChild', 'method'); return appendChild.call(this, aChild); } }), insertBefore: generateDataDescriptor({ value(newNode, referenceNode) { if (!isDomMutationAllowed) { logMissingPortalError('insertBefore', 'method'); } return insertBefore.call(this, newNode, referenceNode); } }), removeChild: generateDataDescriptor({ value(aChild) { if (!isDomMutationAllowed) { logMissingPortalError('removeChild', 'method'); } return removeChild.call(this, aChild); } }), replaceChild: generateDataDescriptor({ value(newChild, oldChild) { logMissingPortalError('replaceChild', 'method'); return replaceChild.call(this, newChild, oldChild); } }), nodeValue: generateAccessorDescriptor({ get() { return originalNodeValueDescriptor.get.call(this); }, set(value) { if (!isDomMutationAllowed) { logMissingPortalError('nodeValue', 'property'); } originalNodeValueDescriptor.set.call(this, value); } }), textContent: generateAccessorDescriptor({ get() { return originalTextContentDescriptor.get.call(this); }, set(value) { logMissingPortalError('textContent', 'property'); originalTextContentDescriptor.set.call(this, value); } }), innerHTML: generateAccessorDescriptor({ get() { return originalInnerHTMLDescriptor.get.call(this); }, set(value) { logMissingPortalError('innerHTML', 'property'); return originalInnerHTMLDescriptor.set.call(this, value); } }) }); } defineProperties$1(elm, descriptors); } function getShadowRootRestrictionsDescriptors(sr) { if (process.env.NODE_ENV === 'production') { // this method should never leak to prod throw new ReferenceError(); } // Disallowing properties in dev mode only to avoid people doing the wrong // thing when using the real shadow root, because if that's the case, // the component will not work when running with synthetic shadow. const originalAddEventListener = sr.addEventListener; const originalInnerHTMLDescriptor = getPropertyDescriptor(sr, 'innerHTML'); const originalTextContentDescriptor = getPropertyDescriptor(sr, 'textContent'); return { innerHTML: generateAccessorDescriptor({ get() { return originalInnerHTMLDescriptor.get.call(this); }, set(_value) { throw new TypeError(`Invalid attempt to set innerHTML on ShadowRoot.`); } }), textContent: generateAccessorDescriptor({ get() { return originalTextContentDescriptor.get.call(this); }, set(_value) { throw new TypeError(`Invalid attempt to set textContent on ShadowRoot.`); } }), addEventListener: generateDataDescriptor({ value(type, listener, options) { // TODO [#420]: this is triggered when the component author attempts to add a listener // programmatically into its Component's shadow root if (!isUndefined$3(options)) { logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this)); } // Typescript does not like it when you treat the `arguments` object as an array // @ts-ignore type-mismatch return originalAddEventListener.apply(this, arguments); } }) }; } // Custom Elements Restrictions: // ----------------------------- function getCustomElementRestrictionsDescriptors(elm) { if (process.env.NODE_ENV === 'production') { // this method should never leak to prod throw new ReferenceError(); } const originalAddEventListener = elm.addEventListener; const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');