@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.
@@ -1801,6 +1801,14 @@ LightningElement.prototype = {
1801
1801
  }
1802
1802
  return renderer.getLastElementChild(vm.elm);
1803
1803
  },
1804
+ get ownerDocument() {
1805
+ const vm = getAssociatedVM(this);
1806
+ const renderer = vm.renderer;
1807
+ if (process.env.NODE_ENV !== 'production') {
1808
+ warnIfInvokedDuringConstruction(vm, 'ownerDocument');
1809
+ }
1810
+ return renderer.ownerDocument(vm.elm);
1811
+ },
1804
1812
  render() {
1805
1813
  const vm = getAssociatedVM(this);
1806
1814
  return vm.def.template;
@@ -1876,31 +1884,84 @@ function createObservedFieldPropertyDescriptor(key) {
1876
1884
  }
1877
1885
 
1878
1886
  /*
1879
- * Copyright (c) 2018, salesforce.com, inc.
1887
+ * Copyright (c) 2023, salesforce.com, inc.
1880
1888
  * All rights reserved.
1881
1889
  * SPDX-License-Identifier: MIT
1882
1890
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1883
1891
  */
1884
- const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
1885
- const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
1886
- const WIRE_DEBUG_ENTRY = '@wire';
1887
- const WireMetaMap = new Map();
1888
- class WireContextRegistrationEvent extends CustomEvent {
1889
- constructor(adapterToken, { setNewContext, setDisconnectedCallback }) {
1890
- super(adapterToken, {
1891
- bubbles: true,
1892
- composed: true,
1892
+ const AdapterToTokenMap = new Map();
1893
+ function createContextProviderWithRegister(adapter, registerContextProvider) {
1894
+ let adapterContextToken = AdapterToTokenMap.get(adapter);
1895
+ if (!shared.isUndefined(adapterContextToken)) {
1896
+ throw new Error(`Adapter already has a context provider.`);
1897
+ }
1898
+ adapterContextToken = guid();
1899
+ AdapterToTokenMap.set(adapter, adapterContextToken);
1900
+ const providers = new WeakSet();
1901
+ return (elmOrComponent, options) => {
1902
+ if (providers.has(elmOrComponent)) {
1903
+ throw new Error(`Adapter was already installed on ${elmOrComponent}.`);
1904
+ }
1905
+ providers.add(elmOrComponent);
1906
+ const { consumerConnectedCallback, consumerDisconnectedCallback } = options;
1907
+ registerContextProvider(elmOrComponent, adapterContextToken, (subscriptionPayload) => {
1908
+ const { setNewContext, setDisconnectedCallback } = subscriptionPayload;
1909
+ const consumer = {
1910
+ provide(newContext) {
1911
+ setNewContext(newContext);
1912
+ },
1913
+ };
1914
+ const disconnectCallback = () => {
1915
+ if (!shared.isUndefined(consumerDisconnectedCallback)) {
1916
+ consumerDisconnectedCallback(consumer);
1917
+ }
1918
+ };
1919
+ setDisconnectedCallback(disconnectCallback);
1920
+ consumerConnectedCallback(consumer);
1893
1921
  });
1894
- shared.defineProperties(this, {
1895
- setNewContext: {
1896
- value: setNewContext,
1922
+ };
1923
+ }
1924
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
1925
+ const { adapter } = wireDef;
1926
+ const adapterContextToken = AdapterToTokenMap.get(adapter);
1927
+ if (shared.isUndefined(adapterContextToken)) {
1928
+ return; // no provider found, nothing to be done
1929
+ }
1930
+ const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { registerContextConsumer }, } = vm;
1931
+ // waiting for the component to be connected to formally request the context via the token
1932
+ shared.ArrayPush.call(wiredConnecting, () => {
1933
+ // This will attempt to connect the current element with one of its anscestors
1934
+ // that can provide context for the given wire adapter. This relationship is
1935
+ // keyed on the secret & internal value of `adapterContextToken`, which is unique
1936
+ // to a given wire adapter.
1937
+ //
1938
+ // Depending on the runtime environment, this connection is made using either DOM
1939
+ // events (in the browser) or a custom traversal (on the server).
1940
+ registerContextConsumer(elm, adapterContextToken, {
1941
+ setNewContext(newContext) {
1942
+ // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1943
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
1944
+ callbackWhenContextIsReady(newContext);
1897
1945
  },
1898
- setDisconnectedCallback: {
1899
- value: setDisconnectedCallback,
1946
+ setDisconnectedCallback(disconnectCallback) {
1947
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
1948
+ // the the element hosting the wire is disconnected
1949
+ shared.ArrayPush.call(wiredDisconnecting, disconnectCallback);
1900
1950
  },
1901
1951
  });
1902
- }
1952
+ });
1903
1953
  }
1954
+
1955
+ /*
1956
+ * Copyright (c) 2023, salesforce.com, inc.
1957
+ * All rights reserved.
1958
+ * SPDX-License-Identifier: MIT
1959
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1960
+ */
1961
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
1962
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
1963
+ const WIRE_DEBUG_ENTRY = '@wire';
1964
+ const WireMetaMap = new Map();
1904
1965
  function createFieldDataCallback(vm, name) {
1905
1966
  return (value) => {
1906
1967
  updateComponentValue(vm, name, value);
@@ -1944,35 +2005,6 @@ function createConfigWatcher(component, configCallback, callbackWhenConfigIsRead
1944
2005
  ro,
1945
2006
  };
1946
2007
  }
1947
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
1948
- const { adapter } = wireDef;
1949
- const adapterContextToken = getAdapterToken(adapter);
1950
- if (shared.isUndefined(adapterContextToken)) {
1951
- return; // no provider found, nothing to be done
1952
- }
1953
- const { elm, context: { wiredConnecting, wiredDisconnecting }, renderer: { dispatchEvent }, } = vm;
1954
- // waiting for the component to be connected to formally request the context via the token
1955
- shared.ArrayPush.call(wiredConnecting, () => {
1956
- // This event is responsible for connecting the host element with another
1957
- // element in the composed path that is providing contextual data. The provider
1958
- // must be listening for a special dom event with the name corresponding to the value of
1959
- // `adapterContextToken`, which will remain secret and internal to this file only to
1960
- // guarantee that the linkage can be forged.
1961
- const contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
1962
- setNewContext(newContext) {
1963
- // eslint-disable-next-line @lwc/lwc-internal/no-invalid-todo
1964
- // TODO: dev-mode validation of config based on the adapter.contextSchema
1965
- callbackWhenContextIsReady(newContext);
1966
- },
1967
- setDisconnectedCallback(disconnectCallback) {
1968
- // adds this callback into the disconnect bucket so it gets disconnected from parent
1969
- // the the element hosting the wire is disconnected
1970
- shared.ArrayPush.call(wiredDisconnecting, disconnectCallback);
1971
- },
1972
- });
1973
- dispatchEvent(elm, contextRegistrationEvent);
1974
- });
1975
- }
1976
2008
  function createConnector(vm, name, wireDef) {
1977
2009
  const { method, adapter, configCallback, dynamic } = wireDef;
1978
2010
  let debugInfo;
@@ -2047,13 +2079,6 @@ function createConnector(vm, name, wireDef) {
2047
2079
  resetConfigWatcher: () => ro.reset(),
2048
2080
  };
2049
2081
  }
2050
- const AdapterToTokenMap = new Map();
2051
- function getAdapterToken(adapter) {
2052
- return AdapterToTokenMap.get(adapter);
2053
- }
2054
- function setAdapterToken(adapter, token) {
2055
- AdapterToTokenMap.set(adapter, token);
2056
- }
2057
2082
  function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
2058
2083
  // support for callable adapters
2059
2084
  if (adapter.adapter) {
@@ -5870,6 +5895,10 @@ function forceRehydration(vm) {
5870
5895
  // Use the unpatched native getElementById/querySelectorAll rather than the synthetic one
5871
5896
  const getElementById = shared.globalThis[shared.KEY__NATIVE_GET_ELEMENT_BY_ID];
5872
5897
  const querySelectorAll = shared.globalThis[shared.KEY__NATIVE_QUERY_SELECTOR_ALL];
5898
+ // This is a "handoff" from synthetic-shadow to engine-core – we want to clean up after ourselves
5899
+ // so nobody else can misuse these global APIs.
5900
+ delete shared.globalThis[shared.KEY__NATIVE_GET_ELEMENT_BY_ID];
5901
+ delete shared.globalThis[shared.KEY__NATIVE_QUERY_SELECTOR_ALL];
5873
5902
  function isSyntheticShadowRootInstance(rootNode) {
5874
5903
  return rootNode !== document && shared.isTrue(rootNode.synthetic);
5875
5904
  }
@@ -6117,67 +6146,6 @@ if (process.env.IS_BROWSER) {
6117
6146
  }
6118
6147
  }
6119
6148
 
6120
- /*
6121
- * Copyright (c) 2018, salesforce.com, inc.
6122
- * All rights reserved.
6123
- * SPDX-License-Identifier: MIT
6124
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6125
- */
6126
- // this is lwc internal implementation
6127
- function createContextProvider(adapter) {
6128
- let adapterContextToken = getAdapterToken(adapter);
6129
- if (!shared.isUndefined(adapterContextToken)) {
6130
- throw new Error(`Adapter already has a context provider.`);
6131
- }
6132
- adapterContextToken = guid();
6133
- setAdapterToken(adapter, adapterContextToken);
6134
- const providers = new WeakSet();
6135
- return (elm, options) => {
6136
- if (providers.has(elm)) {
6137
- throw new Error(`Adapter was already installed on ${elm}.`);
6138
- }
6139
- providers.add(elm);
6140
- const { consumerConnectedCallback, consumerDisconnectedCallback } = options;
6141
- elm.addEventListener(adapterContextToken, ((evt) => {
6142
- const { setNewContext, setDisconnectedCallback } = evt;
6143
- const consumer = {
6144
- provide(newContext) {
6145
- setNewContext(newContext);
6146
- },
6147
- };
6148
- const disconnectCallback = () => {
6149
- if (!shared.isUndefined(consumerDisconnectedCallback)) {
6150
- consumerDisconnectedCallback(consumer);
6151
- }
6152
- };
6153
- setDisconnectedCallback(disconnectCallback);
6154
- consumerConnectedCallback(consumer);
6155
- evt.stopImmediatePropagation();
6156
- }));
6157
- };
6158
- }
6159
-
6160
- /*
6161
- * Copyright (c) 2018, salesforce.com, inc.
6162
- * All rights reserved.
6163
- * SPDX-License-Identifier: MIT
6164
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6165
- */
6166
- /**
6167
- * EXPERIMENTAL: This function allows you to create a reactive readonly
6168
- * membrane around any object value. This API is subject to change or
6169
- * being removed.
6170
- */
6171
- function readonly(obj) {
6172
- if (process.env.NODE_ENV !== 'production') {
6173
- // TODO [#1292]: Remove the readonly decorator
6174
- if (arguments.length !== 1) {
6175
- shared.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.');
6176
- }
6177
- }
6178
- return getReadOnlyProxy(obj);
6179
- }
6180
-
6181
6149
  /*
6182
6150
  * Copyright (c) 2022, salesforce.com, inc.
6183
6151
  * All rights reserved.
@@ -6868,6 +6836,27 @@ function getComponentConstructor(elm) {
6868
6836
  return ctor;
6869
6837
  }
6870
6838
 
6839
+ /*
6840
+ * Copyright (c) 2018, salesforce.com, inc.
6841
+ * All rights reserved.
6842
+ * SPDX-License-Identifier: MIT
6843
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6844
+ */
6845
+ /**
6846
+ * EXPERIMENTAL: This function allows you to create a reactive readonly
6847
+ * membrane around any object value. This API is subject to change or
6848
+ * being removed.
6849
+ */
6850
+ function readonly(obj) {
6851
+ if (process.env.NODE_ENV !== 'production') {
6852
+ // TODO [#1292]: Remove the readonly decorator
6853
+ if (arguments.length !== 1) {
6854
+ shared.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.');
6855
+ }
6856
+ }
6857
+ return getReadOnlyProxy(obj);
6858
+ }
6859
+
6871
6860
  Object.defineProperty(exports, 'setFeatureFlag', {
6872
6861
  enumerable: true,
6873
6862
  get: function () { return features.setFeatureFlag; }
@@ -6881,7 +6870,7 @@ exports.__unstable__ProfilerControl = profilerControl;
6881
6870
  exports.__unstable__ReportingControl = reportingControl;
6882
6871
  exports.api = api$1;
6883
6872
  exports.connectRootElement = connectRootElement;
6884
- exports.createContextProvider = createContextProvider;
6873
+ exports.createContextProviderWithRegister = createContextProviderWithRegister;
6885
6874
  exports.createVM = createVM;
6886
6875
  exports.disconnectRootElement = disconnectRootElement;
6887
6876
  exports.freezeTemplate = freezeTemplate;
@@ -6906,4 +6895,5 @@ exports.swapTemplate = swapTemplate;
6906
6895
  exports.track = track;
6907
6896
  exports.unwrap = unwrap;
6908
6897
  exports.wire = wire;
6909
- /* version: 2.37.3 */
6898
+ /* version: 2.38.0 */
6899
+ //# sourceMappingURL=engine-core.cjs.js.map