@lwc/engine-core 2.37.2 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /* proxy-compat-disable */
2
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
2
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, forEach, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, htmlAttributeToProperty, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, ArrayUnshift, globalThis as globalThis$1, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, htmlEscape, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse, ArrayShift } from '@lwc/shared';
3
3
  import { applyAriaReflection } from '@lwc/aria-reflection';
4
4
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
5
5
 
@@ -1799,6 +1799,14 @@ LightningElement.prototype = {
1799
1799
  }
1800
1800
  return renderer.getLastElementChild(vm.elm);
1801
1801
  },
1802
+ get ownerDocument() {
1803
+ const vm = getAssociatedVM(this);
1804
+ const renderer = vm.renderer;
1805
+ if (process.env.NODE_ENV !== 'production') {
1806
+ warnIfInvokedDuringConstruction(vm, 'ownerDocument');
1807
+ }
1808
+ return renderer.ownerDocument(vm.elm);
1809
+ },
1802
1810
  render() {
1803
1811
  const vm = getAssociatedVM(this);
1804
1812
  return vm.def.template;
@@ -1874,31 +1882,84 @@ function createObservedFieldPropertyDescriptor(key) {
1874
1882
  }
1875
1883
 
1876
1884
  /*
1877
- * Copyright (c) 2018, salesforce.com, inc.
1885
+ * Copyright (c) 2023, salesforce.com, inc.
1878
1886
  * All rights reserved.
1879
1887
  * SPDX-License-Identifier: MIT
1880
1888
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1881
1889
  */
1882
- const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
1883
- const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
1884
- const WIRE_DEBUG_ENTRY = '@wire';
1885
- const WireMetaMap = new Map();
1886
- class WireContextRegistrationEvent extends CustomEvent {
1887
- constructor(adapterToken, { setNewContext, setDisconnectedCallback }) {
1888
- super(adapterToken, {
1889
- bubbles: true,
1890
- composed: true,
1890
+ const AdapterToTokenMap = new Map();
1891
+ function createContextProviderWithRegister(adapter, registerContextProvider) {
1892
+ let adapterContextToken = AdapterToTokenMap.get(adapter);
1893
+ if (!isUndefined$1(adapterContextToken)) {
1894
+ throw new Error(`Adapter already has a context provider.`);
1895
+ }
1896
+ adapterContextToken = guid();
1897
+ AdapterToTokenMap.set(adapter, adapterContextToken);
1898
+ const providers = new WeakSet();
1899
+ return (elmOrComponent, options) => {
1900
+ if (providers.has(elmOrComponent)) {
1901
+ throw new Error(`Adapter was already installed on ${elmOrComponent}.`);
1902
+ }
1903
+ providers.add(elmOrComponent);
1904
+ const { consumerConnectedCallback, consumerDisconnectedCallback } = options;
1905
+ registerContextProvider(elmOrComponent, adapterContextToken, (subscriptionPayload) => {
1906
+ const { setNewContext, setDisconnectedCallback } = subscriptionPayload;
1907
+ const consumer = {
1908
+ provide(newContext) {
1909
+ setNewContext(newContext);
1910
+ },
1911
+ };
1912
+ const disconnectCallback = () => {
1913
+ if (!isUndefined$1(consumerDisconnectedCallback)) {
1914
+ consumerDisconnectedCallback(consumer);
1915
+ }
1916
+ };
1917
+ setDisconnectedCallback(disconnectCallback);
1918
+ consumerConnectedCallback(consumer);
1891
1919
  });
1892
- defineProperties(this, {
1893
- setNewContext: {
1894
- value: setNewContext,
1920
+ };
1921
+ }
1922
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
1923
+ const { adapter } = wireDef;
1924
+ const adapterContextToken = AdapterToTokenMap.get(adapter);
1925
+ if (isUndefined$1(adapterContextToken)) {
1926
+ return; // no provider found, nothing to be done
1927
+ }
1928
+ const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { registerContextConsumer }, } = vm;
1929
+ // waiting for the component to be connected to formally request the context via the token
1930
+ ArrayPush$1.call(wiredConnecting, () => {
1931
+ // This will attempt to connect the current element with one of its anscestors
1932
+ // that can provide context for the given wire adapter. This relationship is
1933
+ // keyed on the secret & internal value of `adapterContextToken`, which is unique
1934
+ // to a given wire adapter.
1935
+ //
1936
+ // Depending on the runtime environment, this connection is made using either DOM
1937
+ // events (in the browser) or a custom traversal (on the server).
1938
+ registerContextConsumer(elm, adapterContextToken, {
1939
+ setNewContext(newContext) {
1940
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1941
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
1942
+ callbackWhenContextIsReady(newContext);
1895
1943
  },
1896
- setDisconnectedCallback: {
1897
- value: setDisconnectedCallback,
1944
+ setDisconnectedCallback(disconnectCallback) {
1945
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
1946
+ // the the element hosting the wire is disconnected
1947
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
1898
1948
  },
1899
1949
  });
1900
- }
1950
+ });
1901
1951
  }
1952
+
1953
+ /*
1954
+ * Copyright (c) 2023, salesforce.com, inc.
1955
+ * All rights reserved.
1956
+ * SPDX-License-Identifier: MIT
1957
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1958
+ */
1959
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
1960
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
1961
+ const WIRE_DEBUG_ENTRY = '@wire';
1962
+ const WireMetaMap = new Map();
1902
1963
  function createFieldDataCallback(vm, name) {
1903
1964
  return (value) => {
1904
1965
  updateComponentValue(vm, name, value);
@@ -1942,35 +2003,6 @@ function createConfigWatcher(component, configCallback, callbackWhenConfigIsRead
1942
2003
  ro,
1943
2004
  };
1944
2005
  }
1945
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
1946
- const { adapter } = wireDef;
1947
- const adapterContextToken = getAdapterToken(adapter);
1948
- if (isUndefined$1(adapterContextToken)) {
1949
- return; // no provider found, nothing to be done
1950
- }
1951
- const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { dispatchEvent }, } = vm;
1952
- // waiting for the component to be connected to formally request the context via the token
1953
- ArrayPush$1.call(wiredConnecting, () => {
1954
- // This event is responsible for connecting the host element with another
1955
- // element in the composed path that is providing contextual data. The provider
1956
- // must be listening for a special dom event with the name corresponding to the value of
1957
- // `adapterContextToken`, which will remain secret and internal to this file only to
1958
- // guarantee that the linkage can be forged.
1959
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
1960
- setNewContext(newContext) {
1961
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1962
- // TODO: dev-mode validation of config based on the adapter.contextSchema
1963
- callbackWhenContextIsReady(newContext);
1964
- },
1965
- setDisconnectedCallback(disconnectCallback) {
1966
- // adds this callback into the disconnect bucket so it gets disconnected from parent
1967
- // the the element hosting the wire is disconnected
1968
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
1969
- },
1970
- });
1971
- dispatchEvent(elm, contextRegistrationEvent);
1972
- });
1973
- }
1974
2006
  function createConnector(vm, name, wireDef) {
1975
2007
  const { method, adapter, configCallback, dynamic } = wireDef;
1976
2008
  let debugInfo;
@@ -2045,13 +2077,6 @@ function createConnector(vm, name, wireDef) {
2045
2077
  resetConfigWatcher: () => ro.reset(),
2046
2078
  };
2047
2079
  }
2048
- const AdapterToTokenMap = new Map();
2049
- function getAdapterToken(adapter) {
2050
- return AdapterToTokenMap.get(adapter);
2051
- }
2052
- function setAdapterToken(adapter, token) {
2053
- AdapterToTokenMap.set(adapter, token);
2054
- }
2055
2080
  function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2056
2081
  // support for callable adapters
2057
2082
  if (adapter.adapter) {
@@ -5868,6 +5893,10 @@ function forceRehydration(vm) {
5868
5893
  // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
5869
5894
  const getElementById = globalThis$1[KEY__NATIVE_GET_ELEMENT_BY_ID];
5870
5895
  const querySelectorAll = globalThis$1[KEY__NATIVE_QUERY_SELECTOR_ALL];
5896
+ // This is a "handoff" from synthetic-shadow to engine-core – we want to clean up after ourselves
5897
+ // so nobody else can misuse these global APIs.
5898
+ delete globalThis$1[KEY__NATIVE_GET_ELEMENT_BY_ID];
5899
+ delete globalThis$1[KEY__NATIVE_QUERY_SELECTOR_ALL];
5871
5900
  function isSyntheticShadowRootInstance(rootNode) {
5872
5901
  return rootNode !== document && isTrue(rootNode.synthetic);
5873
5902
  }
@@ -6115,67 +6144,6 @@ if (process.env.IS_BROWSER) {
6115
6144
  }
6116
6145
  }
6117
6146
 
6118
- /*
6119
- * Copyright (c) 2018, salesforce.com, inc.
6120
- * All rights reserved.
6121
- * SPDX-License-Identifier: MIT
6122
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6123
- */
6124
- // this is lwc internal implementation
6125
- function createContextProvider(adapter) {
6126
- let adapterContextToken = getAdapterToken(adapter);
6127
- if (!isUndefined$1(adapterContextToken)) {
6128
- throw new Error(`Adapter already has a context provider.`);
6129
- }
6130
- adapterContextToken = guid();
6131
- setAdapterToken(adapter, adapterContextToken);
6132
- const providers = new WeakSet();
6133
- return (elm, options) => {
6134
- if (providers.has(elm)) {
6135
- throw new Error(`Adapter was already installed on ${elm}.`);
6136
- }
6137
- providers.add(elm);
6138
- const { consumerConnectedCallback, consumerDisconnectedCallback } = options;
6139
- elm.addEventListener(adapterContextToken, ((evt) => {
6140
- const { setNewContext, setDisconnectedCallback } = evt;
6141
- const consumer = {
6142
- provide(newContext) {
6143
- setNewContext(newContext);
6144
- },
6145
- };
6146
- const disconnectCallback = () => {
6147
- if (!isUndefined$1(consumerDisconnectedCallback)) {
6148
- consumerDisconnectedCallback(consumer);
6149
- }
6150
- };
6151
- setDisconnectedCallback(disconnectCallback);
6152
- consumerConnectedCallback(consumer);
6153
- evt.stopImmediatePropagation();
6154
- }));
6155
- };
6156
- }
6157
-
6158
- /*
6159
- * Copyright (c) 2018, salesforce.com, inc.
6160
- * All rights reserved.
6161
- * SPDX-License-Identifier: MIT
6162
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6163
- */
6164
- /**
6165
- * EXPERIMENTAL: This function allows you to create a reactive readonly
6166
- * membrane around any object value. This API is subject to change or
6167
- * being removed.
6168
- */
6169
- function readonly(obj) {
6170
- if (process.env.NODE_ENV !== 'production') {
6171
- // TODO [#1292]: Remove the readonly decorator
6172
- if (arguments.length !== 1) {
6173
- assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6174
- }
6175
- }
6176
- return getReadOnlyProxy(obj);
6177
- }
6178
-
6179
6147
  /*
6180
6148
  * Copyright (c) 2022, salesforce.com, inc.
6181
6149
  * All rights reserved.
@@ -6229,15 +6197,44 @@ function hydrateNode(node, vnode, renderer) {
6229
6197
  return renderer.nextSibling(hydratedNode);
6230
6198
  }
6231
6199
  const NODE_VALUE_PROP = 'nodeValue';
6200
+ const PARENT_NODE_PROP = 'parentNode';
6201
+ const TAG_NAME_PROP = 'tagName';
6202
+ function textNodeContentsAreEqual(node, vnode, renderer) {
6203
+ const { getProperty } = renderer;
6204
+ const nodeValue = getProperty(node, NODE_VALUE_PROP);
6205
+ if (nodeValue === vnode.text) {
6206
+ return true;
6207
+ }
6208
+ // Special case for empty text nodes – these are serialized differently on the server
6209
+ // See https://github.com/salesforce/lwc/pull/2656
6210
+ if (nodeValue === '\u200D' && vnode.text === '') {
6211
+ return true;
6212
+ }
6213
+ // Special case for text nodes inside `<style>` tags – these are escaped when rendered server-size,
6214
+ // but not when generated by the engine client-side.
6215
+ const parentNode = getProperty(node, PARENT_NODE_PROP);
6216
+ // Should never be null, but just to be safe, we check.
6217
+ /* istanbul ignore else */
6218
+ if (!isNull(parentNode)) {
6219
+ const tagName = getProperty(parentNode, TAG_NAME_PROP);
6220
+ // If the tagName is STYLE, then the following condition should always be true.
6221
+ // The LWC compiler blocks using `<style>`s inside of templates, so it should be impossible
6222
+ // for component authors to render different `<style>` text content on the client and server.
6223
+ // But just to be safe, we check.
6224
+ /* istanbul ignore next */
6225
+ if (tagName === 'STYLE' && htmlEscape(vnode.text) === nodeValue) {
6226
+ return true;
6227
+ }
6228
+ }
6229
+ return false;
6230
+ }
6232
6231
  function hydrateText(node, vnode, renderer) {
6233
6232
  var _a;
6234
6233
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6235
6234
  return handleMismatch(node, vnode, renderer);
6236
6235
  }
6237
6236
  if (process.env.NODE_ENV !== 'production') {
6238
- const { getProperty } = renderer;
6239
- const nodeValue = getProperty(node, NODE_VALUE_PROP);
6240
- if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
6237
+ if (!textNodeContentsAreEqual(node, vnode, renderer)) {
6241
6238
  logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
6242
6239
  }
6243
6240
  }
@@ -6417,6 +6414,19 @@ function isMatchingElement(vnode, elm, renderer) {
6417
6414
  const hasIncompatibleStyle = validateStyleAttr(vnode, elm, renderer);
6418
6415
  return hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6419
6416
  }
6417
+ function attributeValuesAreEqual(vnodeValue, value) {
6418
+ const vnodeValueAsString = String(vnodeValue);
6419
+ if (vnodeValueAsString === value) {
6420
+ return true;
6421
+ }
6422
+ // If the expected value is null, this means that the attribute does not exist. In that case,
6423
+ // we accept any nullish value (undefined or null).
6424
+ if (isNull(value) && (isUndefined$1(vnodeValue) || isNull(vnodeValue))) {
6425
+ return true;
6426
+ }
6427
+ // In all other cases, the two values are not considered equal
6428
+ return false;
6429
+ }
6420
6430
  function validateAttrs(vnode, elm, renderer) {
6421
6431
  const { data: { attrs = {} }, } = vnode;
6422
6432
  let nodesAreCompatible = true;
@@ -6426,10 +6436,10 @@ function validateAttrs(vnode, elm, renderer) {
6426
6436
  const { owner } = vnode;
6427
6437
  const { getAttribute } = renderer;
6428
6438
  const elmAttrValue = getAttribute(elm, attrName);
6429
- if (String(attrValue) !== elmAttrValue) {
6439
+ if (!attributeValuesAreEqual(attrValue, elmAttrValue)) {
6430
6440
  if (process.env.NODE_ENV !== 'production') {
6431
6441
  const { getProperty } = renderer;
6432
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, owner);
6442
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found ${isNull(elmAttrValue) ? 'null' : `"${elmAttrValue}"`}`, owner);
6433
6443
  }
6434
6444
  nodesAreCompatible = false;
6435
6445
  }
@@ -6824,5 +6834,27 @@ function getComponentConstructor(elm) {
6824
6834
  return ctor;
6825
6835
  }
6826
6836
 
6827
- export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6828
- /* version: 2.37.2 */
6837
+ /*
6838
+ * Copyright (c) 2018, salesforce.com, inc.
6839
+ * All rights reserved.
6840
+ * SPDX-License-Identifier: MIT
6841
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6842
+ */
6843
+ /**
6844
+ * EXPERIMENTAL: This function allows you to create a reactive readonly
6845
+ * membrane around any object value. This API is subject to change or
6846
+ * being removed.
6847
+ */
6848
+ function readonly(obj) {
6849
+ if (process.env.NODE_ENV !== 'production') {
6850
+ // TODO [#1292]: Remove the readonly decorator
6851
+ if (arguments.length !== 1) {
6852
+ assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
6853
+ }
6854
+ }
6855
+ return getReadOnlyProxy(obj);
6856
+ }
6857
+
6858
+ export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6859
+ /* version: 2.38.0 */
6860
+ //# sourceMappingURL=engine-core.js.map