@lwc/engine-core 2.37.3 → 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.
@@ -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.
@@ -6866,5 +6834,27 @@ function getComponentConstructor(elm) {
6866
6834
  return ctor;
6867
6835
  }
6868
6836
 
6869
- 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 };
6870
- /* version: 2.37.3 */
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