@lwc/synthetic-shadow 3.0.2 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ export declare function getLegacyShadowToken(node: Node): string | undefined;
2
+ export declare function setLegacyShadowToken(node: Node, shadowToken: string | undefined): void;
package/dist/index.cjs.js CHANGED
@@ -111,10 +111,13 @@ const KEY__SHADOW_STATIC = '$shadowStaticNode$';
111
111
  const KEY__SHADOW_STATIC_PRIVATE = '$shadowStaticNodeKey$';
112
112
  const KEY__SHADOW_TOKEN = '$shadowToken$';
113
113
  const KEY__SHADOW_TOKEN_PRIVATE = '$$ShadowTokenKey$$';
114
+ // TODO [#3733]: remove support for legacy scope tokens
115
+ const KEY__LEGACY_SHADOW_TOKEN = '$legacyShadowToken$';
116
+ const KEY__LEGACY_SHADOW_TOKEN_PRIVATE = '$$LegacyShadowTokenKey$$';
114
117
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
115
118
  const KEY__NATIVE_GET_ELEMENT_BY_ID = '$nativeGetElementById$';
116
119
  const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
117
- /** version: 3.0.2 */
120
+ /** version: 3.0.4 */
118
121
 
119
122
  /**
120
123
  * Copyright (C) 2023 salesforce.com, inc.
@@ -123,7 +126,7 @@ const KEY__NATIVE_QUERY_SELECTOR_ALL = '$nativeQuerySelectorAll$';
123
126
  if (!_globalThis.lwcRuntimeFlags) {
124
127
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
125
128
  }
126
- /** version: 3.0.2 */
129
+ /** version: 3.0.4 */
127
130
 
128
131
  /*
129
132
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4353,6 +4356,40 @@ defineProperty(Element.prototype, KEY__SHADOW_STATIC, {
4353
4356
  configurable: true,
4354
4357
  });
4355
4358
 
4359
+ /*
4360
+ * Copyright (c) 2023, salesforce.com, inc.
4361
+ * All rights reserved.
4362
+ * SPDX-License-Identifier: MIT
4363
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4364
+ */
4365
+ // TODO [#3733]: remove this entire file when we can remove legacy scope tokens
4366
+ function getLegacyShadowToken(node) {
4367
+ return node[KEY__LEGACY_SHADOW_TOKEN];
4368
+ }
4369
+ function setLegacyShadowToken(node, shadowToken) {
4370
+ node[KEY__LEGACY_SHADOW_TOKEN] = shadowToken;
4371
+ }
4372
+ /**
4373
+ * Patching Element.prototype.$legacyShadowToken$ to mark elements a portal:
4374
+ * Same as $shadowToken$ but for legacy CSS scope tokens.
4375
+ **/
4376
+ defineProperty(Element.prototype, KEY__LEGACY_SHADOW_TOKEN, {
4377
+ set(shadowToken) {
4378
+ const oldShadowToken = this[KEY__LEGACY_SHADOW_TOKEN_PRIVATE];
4379
+ if (!isUndefined(oldShadowToken) && oldShadowToken !== shadowToken) {
4380
+ removeAttribute.call(this, oldShadowToken);
4381
+ }
4382
+ if (!isUndefined(shadowToken)) {
4383
+ setAttribute.call(this, shadowToken, '');
4384
+ }
4385
+ this[KEY__LEGACY_SHADOW_TOKEN_PRIVATE] = shadowToken;
4386
+ },
4387
+ get() {
4388
+ return this[KEY__LEGACY_SHADOW_TOKEN_PRIVATE];
4389
+ },
4390
+ configurable: true,
4391
+ });
4392
+
4356
4393
  /*
4357
4394
  * Copyright (c) 2018, salesforce.com, inc.
4358
4395
  * All rights reserved.
@@ -4370,7 +4407,8 @@ let portalObserver;
4370
4407
  const portalObserverConfig = {
4371
4408
  childList: true,
4372
4409
  };
4373
- function adoptChildNode(node, fn, shadowToken) {
4410
+ // TODO [#3733]: remove support for legacy scope tokens
4411
+ function adoptChildNode(node, fn, shadowToken, legacyShadowToken) {
4374
4412
  const previousNodeShadowResolver = getShadowRootResolver(node);
4375
4413
  if (previousNodeShadowResolver === fn) {
4376
4414
  return; // nothing to do here, it is already correctly patched
@@ -4378,6 +4416,9 @@ function adoptChildNode(node, fn, shadowToken) {
4378
4416
  setShadowRootResolver(node, fn);
4379
4417
  if (node instanceof Element) {
4380
4418
  setShadowToken(node, shadowToken);
4419
+ if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
4420
+ setLegacyShadowToken(node, legacyShadowToken);
4421
+ }
4381
4422
  if (isSyntheticShadowHost(node)) {
4382
4423
  // Root LWC elements can't get content slotted into them, therefore we don't observe their children.
4383
4424
  return;
@@ -4389,7 +4430,7 @@ function adoptChildNode(node, fn, shadowToken) {
4389
4430
  // recursively patching all children as well
4390
4431
  const childNodes = childNodesGetter.call(node);
4391
4432
  for (let i = 0, len = childNodes.length; i < len; i += 1) {
4392
- adoptChildNode(childNodes[i], fn, shadowToken);
4433
+ adoptChildNode(childNodes[i], fn, shadowToken, legacyShadowToken);
4393
4434
  }
4394
4435
  }
4395
4436
  }
@@ -4410,17 +4451,20 @@ function initPortalObserver() {
4410
4451
  // the target of the mutation should always have a ShadowRootResolver attached to it
4411
4452
  const fn = getShadowRootResolver(elm);
4412
4453
  const shadowToken = getShadowToken(elm);
4454
+ const legacyShadowToken = lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS
4455
+ ? getLegacyShadowToken(elm)
4456
+ : undefined;
4413
4457
  // Process removals first to handle the case where an element is removed and reinserted
4414
4458
  for (let i = 0, len = removedNodes.length; i < len; i += 1) {
4415
4459
  const node = removedNodes[i];
4416
4460
  if (!(compareDocumentPosition.call(elm, node) & _Node.DOCUMENT_POSITION_CONTAINED_BY)) {
4417
- adoptChildNode(node, DocumentResolverFn, undefined);
4461
+ adoptChildNode(node, DocumentResolverFn, undefined, undefined);
4418
4462
  }
4419
4463
  }
4420
4464
  for (let i = 0, len = addedNodes.length; i < len; i += 1) {
4421
4465
  const node = addedNodes[i];
4422
4466
  if (compareDocumentPosition.call(elm, node) & _Node.DOCUMENT_POSITION_CONTAINED_BY) {
4423
- adoptChildNode(node, fn, shadowToken);
4467
+ adoptChildNode(node, fn, shadowToken, legacyShadowToken);
4424
4468
  }
4425
4469
  }
4426
4470
  });
@@ -4467,5 +4511,5 @@ defineProperty(Element.prototype, '$domManual$', {
4467
4511
  },
4468
4512
  configurable: true,
4469
4513
  });
4470
- /** version: 3.0.2 */
4514
+ /** version: 3.0.4 */
4471
4515
  //# sourceMappingURL=index.cjs.js.map