@lwc/ssr-runtime 8.11.0 → 8.12.1
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.
- package/dist/index.cjs.js +942 -996
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +941 -997
- package/dist/index.js.map +1 -1
- package/dist/render-text-content.d.ts +5 -0
- package/dist/render.d.ts +3 -3
- package/package.json +6 -3
package/dist/index.cjs.js
CHANGED
@@ -316,6 +316,14 @@ function isUndefined$1(obj) {
|
|
316
316
|
function isNull(obj) {
|
317
317
|
return obj === null;
|
318
318
|
}
|
319
|
+
/**
|
320
|
+
* Determines whether the argument is an object or null.
|
321
|
+
* @param obj Value to test
|
322
|
+
* @returns `true` if the value is an object or null.
|
323
|
+
*/
|
324
|
+
function isObject(obj) {
|
325
|
+
return typeof obj === 'object';
|
326
|
+
}
|
319
327
|
/**
|
320
328
|
* Determines whether the argument is a string.
|
321
329
|
* @param obj Value to test
|
@@ -324,14 +332,14 @@ function isNull(obj) {
|
|
324
332
|
function isString(obj) {
|
325
333
|
return typeof obj === 'string';
|
326
334
|
}
|
327
|
-
const OtS
|
335
|
+
const OtS = {}.toString;
|
328
336
|
/**
|
329
337
|
* Converts the argument to a string, safely accounting for objects with "null" prototype.
|
330
338
|
* Note that `toString(null)` returns `"[object Null]"` rather than `"null"`.
|
331
339
|
* @param obj Value to convert to a string.
|
332
340
|
* @returns String representation of the value.
|
333
341
|
*/
|
334
|
-
function toString
|
342
|
+
function toString(obj) {
|
335
343
|
if (obj?.toString) {
|
336
344
|
// Arrays might hold objects with "null" prototype So using
|
337
345
|
// Array.prototype.toString directly will cause an error Iterate through
|
@@ -347,13 +355,13 @@ function toString$1(obj) {
|
|
347
355
|
// 4. Array#toString converts recursive references to arrays to ''
|
348
356
|
// Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws
|
349
357
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
350
|
-
return ArrayJoin.call(ArrayMap.call(obj, toString
|
358
|
+
return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
|
351
359
|
}
|
352
360
|
return obj.toString();
|
353
361
|
}
|
354
362
|
else if (typeof obj === 'object') {
|
355
363
|
// This catches null and returns "[object Null]". Weird, but kept for backwards compatibility.
|
356
|
-
return OtS
|
364
|
+
return OtS.call(obj);
|
357
365
|
}
|
358
366
|
else {
|
359
367
|
return String(obj);
|
@@ -569,6 +577,52 @@ function htmlEscape(str, attrMode = false) {
|
|
569
577
|
return str.replace(searchValue, (char) => ESCAPED_CHARS[char]);
|
570
578
|
}
|
571
579
|
|
580
|
+
/*
|
581
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
582
|
+
* All rights reserved.
|
583
|
+
* SPDX-License-Identifier: MIT
|
584
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
585
|
+
*/
|
586
|
+
/**
|
587
|
+
* [ncls] - Normalize class name attribute.
|
588
|
+
*
|
589
|
+
* Transforms the provided class property value from an object/string into a string the diffing algo
|
590
|
+
* can operate on.
|
591
|
+
*
|
592
|
+
* This implementation is borrowed from Vue:
|
593
|
+
* https://github.com/vuejs/core/blob/e790e1bdd7df7be39e14780529db86e4da47a3db/packages/shared/src/normalizeProp.ts#L63-L82
|
594
|
+
*/
|
595
|
+
function normalizeClass(value) {
|
596
|
+
if (isUndefined$1(value) || isNull(value)) {
|
597
|
+
// Returning undefined here improves initial render cost, because the old vnode's class will be considered
|
598
|
+
// undefined in the `patchClassAttribute` routine, so `oldClass === newClass` will be true so we return early
|
599
|
+
return undefined;
|
600
|
+
}
|
601
|
+
let res = '';
|
602
|
+
if (isString(value)) {
|
603
|
+
res = value;
|
604
|
+
}
|
605
|
+
else if (isArray$1(value)) {
|
606
|
+
for (let i = 0; i < value.length; i++) {
|
607
|
+
const normalized = normalizeClass(value[i]);
|
608
|
+
if (normalized) {
|
609
|
+
res += normalized + ' ';
|
610
|
+
}
|
611
|
+
}
|
612
|
+
}
|
613
|
+
else if (isObject(value) && !isNull(value)) {
|
614
|
+
// Iterate own enumerable keys of the object
|
615
|
+
const _keys = keys(value);
|
616
|
+
for (let i = 0; i < _keys.length; i += 1) {
|
617
|
+
const key = _keys[i];
|
618
|
+
if (value[key]) {
|
619
|
+
res += key + ' ';
|
620
|
+
}
|
621
|
+
}
|
622
|
+
}
|
623
|
+
return StringTrim.call(res);
|
624
|
+
}
|
625
|
+
|
572
626
|
/*
|
573
627
|
* Copyright (c) 2024, Salesforce, Inc.
|
574
628
|
* All rights reserved.
|
@@ -599,7 +653,7 @@ function setHooks(hooks) {
|
|
599
653
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
600
654
|
*/
|
601
655
|
const DEFAULT_SSR_MODE = 'sync';
|
602
|
-
/** version: 8.
|
656
|
+
/** version: 8.12.1 */
|
603
657
|
|
604
658
|
/*
|
605
659
|
* Copyright (c) 2024, Salesforce, Inc.
|
@@ -677,444 +731,418 @@ class ClassList {
|
|
677
731
|
}
|
678
732
|
}
|
679
733
|
|
680
|
-
|
681
|
-
Copyright (
|
682
|
-
|
683
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
684
|
-
purpose with or without fee is hereby granted.
|
685
|
-
|
686
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
687
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
688
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
689
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
690
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
691
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
692
|
-
PERFORMANCE OF THIS SOFTWARE.
|
693
|
-
***************************************************************************** */
|
694
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
695
|
-
|
696
|
-
|
697
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
698
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
699
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
700
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
701
|
-
}
|
702
|
-
|
703
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
704
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
705
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
706
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
707
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
708
|
-
}
|
709
|
-
|
710
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
711
|
-
var e = new Error(message);
|
712
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
713
|
-
};
|
714
|
-
|
715
|
-
/*
|
716
|
-
* Copyright (c) 2024, Salesforce, Inc.
|
717
|
-
* All rights reserved.
|
718
|
-
* SPDX-License-Identifier: MIT
|
719
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
734
|
+
/**
|
735
|
+
* Copyright (C) 2017 salesforce.com, inc.
|
720
736
|
*/
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
737
|
+
const { isArray } = Array;
|
738
|
+
const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
|
739
|
+
const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
|
740
|
+
function isUndefined(obj) {
|
741
|
+
return obj === undefined;
|
742
|
+
}
|
743
|
+
function isFunction(obj) {
|
744
|
+
return typeof obj === 'function';
|
745
|
+
}
|
746
|
+
const proxyToValueMap = new WeakMap();
|
747
|
+
function registerProxy(proxy, value) {
|
748
|
+
proxyToValueMap.set(proxy, value);
|
749
|
+
}
|
750
|
+
const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
|
751
|
+
|
752
|
+
class BaseProxyHandler {
|
753
|
+
constructor(membrane, value) {
|
754
|
+
this.originalTarget = value;
|
755
|
+
this.membrane = membrane;
|
726
756
|
}
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
757
|
+
// Shared utility methods
|
758
|
+
wrapDescriptor(descriptor) {
|
759
|
+
if (hasOwnProperty.call(descriptor, 'value')) {
|
760
|
+
descriptor.value = this.wrapValue(descriptor.value);
|
761
|
+
}
|
762
|
+
else {
|
763
|
+
const { set: originalSet, get: originalGet } = descriptor;
|
764
|
+
if (!isUndefined(originalGet)) {
|
765
|
+
descriptor.get = this.wrapGetter(originalGet);
|
766
|
+
}
|
767
|
+
if (!isUndefined(originalSet)) {
|
768
|
+
descriptor.set = this.wrapSetter(originalSet);
|
733
769
|
}
|
734
|
-
mutatedAttrs.add(attrName.toLowerCase());
|
735
770
|
}
|
771
|
+
return descriptor;
|
736
772
|
}
|
737
|
-
|
738
|
-
|
773
|
+
copyDescriptorIntoShadowTarget(shadowTarget, key) {
|
774
|
+
const { originalTarget } = this;
|
775
|
+
// Note: a property might get defined multiple times in the shadowTarget
|
776
|
+
// but it will always be compatible with the previous descriptor
|
777
|
+
// to preserve the object invariants, which makes these lines safe.
|
778
|
+
const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
|
779
|
+
// TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
|
780
|
+
/* istanbul ignore else */
|
781
|
+
if (!isUndefined(originalDescriptor)) {
|
782
|
+
const wrappedDesc = this.wrapDescriptor(originalDescriptor);
|
783
|
+
ObjectDefineProperty(shadowTarget, key, wrappedDesc);
|
784
|
+
}
|
739
785
|
}
|
740
|
-
|
741
|
-
|
786
|
+
lockShadowTarget(shadowTarget) {
|
787
|
+
const { originalTarget } = this;
|
788
|
+
const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
|
789
|
+
targetKeys.forEach((key) => {
|
790
|
+
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
791
|
+
});
|
792
|
+
const { membrane: { tagPropertyKey }, } = this;
|
793
|
+
if (!isUndefined(tagPropertyKey) && !hasOwnProperty.call(shadowTarget, tagPropertyKey)) {
|
794
|
+
ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
|
795
|
+
}
|
796
|
+
preventExtensions(shadowTarget);
|
742
797
|
}
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
798
|
+
// Shared Traps
|
799
|
+
// TODO: apply() is never called
|
800
|
+
/* istanbul ignore next */
|
801
|
+
apply(shadowTarget, thisArg, argArray) {
|
802
|
+
/* No op */
|
803
|
+
}
|
804
|
+
// TODO: construct() is never called
|
805
|
+
/* istanbul ignore next */
|
806
|
+
construct(shadowTarget, argArray, newTarget) {
|
807
|
+
/* No op */
|
808
|
+
}
|
809
|
+
get(shadowTarget, key) {
|
810
|
+
const { originalTarget, membrane: { valueObserved }, } = this;
|
811
|
+
const value = originalTarget[key];
|
812
|
+
valueObserved(originalTarget, key);
|
813
|
+
return this.wrapValue(value);
|
814
|
+
}
|
815
|
+
has(shadowTarget, key) {
|
816
|
+
const { originalTarget, membrane: { tagPropertyKey, valueObserved }, } = this;
|
817
|
+
valueObserved(originalTarget, key);
|
818
|
+
// since key is never going to be undefined, and tagPropertyKey might be undefined
|
819
|
+
// we can simply compare them as the second part of the condition.
|
820
|
+
return key in originalTarget || key === tagPropertyKey;
|
821
|
+
}
|
822
|
+
ownKeys(shadowTarget) {
|
823
|
+
const { originalTarget, membrane: { tagPropertyKey }, } = this;
|
824
|
+
// if the membrane tag key exists and it is not in the original target, we add it to the keys.
|
825
|
+
const keys = isUndefined(tagPropertyKey) || hasOwnProperty.call(originalTarget, tagPropertyKey)
|
826
|
+
? []
|
827
|
+
: [tagPropertyKey];
|
828
|
+
// small perf optimization using push instead of concat to avoid creating an extra array
|
829
|
+
ArrayPush.apply(keys, getOwnPropertyNames(originalTarget));
|
830
|
+
ArrayPush.apply(keys, getOwnPropertySymbols(originalTarget));
|
831
|
+
return keys;
|
832
|
+
}
|
833
|
+
isExtensible(shadowTarget) {
|
834
|
+
const { originalTarget } = this;
|
835
|
+
// optimization to avoid attempting to lock down the shadowTarget multiple times
|
836
|
+
if (!isExtensible(shadowTarget)) {
|
837
|
+
return false; // was already locked down
|
747
838
|
}
|
748
|
-
|
749
|
-
|
839
|
+
if (!isExtensible(originalTarget)) {
|
840
|
+
this.lockShadowTarget(shadowTarget);
|
841
|
+
return false;
|
842
|
+
}
|
843
|
+
return true;
|
844
|
+
}
|
845
|
+
getPrototypeOf(shadowTarget) {
|
846
|
+
const { originalTarget } = this;
|
847
|
+
return getPrototypeOf(originalTarget);
|
848
|
+
}
|
849
|
+
getOwnPropertyDescriptor(shadowTarget, key) {
|
850
|
+
const { originalTarget, membrane: { valueObserved, tagPropertyKey }, } = this;
|
851
|
+
// keys looked up via getOwnPropertyDescriptor need to be reactive
|
852
|
+
valueObserved(originalTarget, key);
|
853
|
+
let desc = getOwnPropertyDescriptor(originalTarget, key);
|
854
|
+
if (isUndefined(desc)) {
|
855
|
+
if (key !== tagPropertyKey) {
|
856
|
+
return undefined;
|
857
|
+
}
|
858
|
+
// if the key is the membrane tag key, and is not in the original target,
|
859
|
+
// we produce a synthetic descriptor and install it on the shadow target
|
860
|
+
desc = { value: undefined, writable: false, configurable: false, enumerable: false };
|
861
|
+
ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
|
862
|
+
return desc;
|
750
863
|
}
|
864
|
+
if (desc.configurable === false) {
|
865
|
+
// updating the descriptor to non-configurable on the shadow
|
866
|
+
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
867
|
+
}
|
868
|
+
// Note: by accessing the descriptor, the key is marked as observed
|
869
|
+
// but access to the value, setter or getter (if available) cannot observe
|
870
|
+
// mutations, just like regular methods, in which case we just do nothing.
|
871
|
+
return this.wrapDescriptor(desc);
|
751
872
|
}
|
752
873
|
}
|
753
|
-
_MutationTracker_enabledSet = new WeakMap(), _MutationTracker_mutationMap = new WeakMap();
|
754
|
-
const mutationTracker = new MutationTracker();
|
755
874
|
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
function filterProperties(props, publicFields, privateFields) {
|
769
|
-
const propsToAssign = create(null);
|
770
|
-
const publicFieldSet = new Set(publicFields);
|
771
|
-
const privateFieldSet = new Set(privateFields);
|
772
|
-
keys(props).forEach((propName) => {
|
773
|
-
const attrName = htmlPropertyToAttribute(propName);
|
774
|
-
if (publicFieldSet.has(propName) ||
|
775
|
-
((isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) &&
|
776
|
-
!privateFieldSet.has(propName))) {
|
777
|
-
propsToAssign[propName] = props[propName];
|
875
|
+
const getterMap$1 = new WeakMap();
|
876
|
+
const setterMap$1 = new WeakMap();
|
877
|
+
const reverseGetterMap = new WeakMap();
|
878
|
+
const reverseSetterMap = new WeakMap();
|
879
|
+
class ReactiveProxyHandler extends BaseProxyHandler {
|
880
|
+
wrapValue(value) {
|
881
|
+
return this.membrane.getProxy(value);
|
882
|
+
}
|
883
|
+
wrapGetter(originalGet) {
|
884
|
+
const wrappedGetter = getterMap$1.get(originalGet);
|
885
|
+
if (!isUndefined(wrappedGetter)) {
|
886
|
+
return wrappedGetter;
|
778
887
|
}
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
const currentValue = this.getAttribute(attrName);
|
793
|
-
const normalizedValue = String(newValue);
|
794
|
-
if (normalizedValue !== currentValue) {
|
795
|
-
this.setAttribute(attrName, normalizedValue);
|
796
|
-
}
|
797
|
-
},
|
798
|
-
});
|
799
|
-
/** Descriptor for a boolean that checks for `attr="true"` or `attr="false"`, e.g. `spellcheck` and `draggable`. */
|
800
|
-
const explicitBooleanDescriptor = (attrName, defaultValue) => ({
|
801
|
-
configurable: true,
|
802
|
-
enumerable: true,
|
803
|
-
get() {
|
804
|
-
const value = this.getAttribute(attrName);
|
805
|
-
if (value === null)
|
806
|
-
return defaultValue;
|
807
|
-
// spellcheck=false => false, everything else => true
|
808
|
-
// draggable=true => true, everything else => false
|
809
|
-
return value.toLowerCase() === String(defaultValue) ? defaultValue : !defaultValue;
|
810
|
-
},
|
811
|
-
set(newValue) {
|
812
|
-
const currentValue = this.getAttribute(attrName);
|
813
|
-
const normalizedValue = String(Boolean(newValue));
|
814
|
-
if (normalizedValue !== currentValue) {
|
815
|
-
this.setAttribute(attrName, normalizedValue);
|
888
|
+
const handler = this;
|
889
|
+
const get = function () {
|
890
|
+
// invoking the original getter with the original target
|
891
|
+
return handler.wrapValue(originalGet.call(unwrap(this)));
|
892
|
+
};
|
893
|
+
getterMap$1.set(originalGet, get);
|
894
|
+
reverseGetterMap.set(get, originalGet);
|
895
|
+
return get;
|
896
|
+
}
|
897
|
+
wrapSetter(originalSet) {
|
898
|
+
const wrappedSetter = setterMap$1.get(originalSet);
|
899
|
+
if (!isUndefined(wrappedSetter)) {
|
900
|
+
return wrappedSetter;
|
816
901
|
}
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
const hasAttribute = this.hasAttribute(attrName);
|
830
|
-
if (newValue) {
|
831
|
-
if (!hasAttribute) {
|
832
|
-
this.setAttribute(attrName, '');
|
833
|
-
}
|
902
|
+
const set = function (v) {
|
903
|
+
// invoking the original setter with the original target
|
904
|
+
originalSet.call(unwrap(this), unwrap(v));
|
905
|
+
};
|
906
|
+
setterMap$1.set(originalSet, set);
|
907
|
+
reverseSetterMap.set(set, originalSet);
|
908
|
+
return set;
|
909
|
+
}
|
910
|
+
unwrapDescriptor(descriptor) {
|
911
|
+
if (hasOwnProperty.call(descriptor, 'value')) {
|
912
|
+
// dealing with a data descriptor
|
913
|
+
descriptor.value = unwrap(descriptor.value);
|
834
914
|
}
|
835
915
|
else {
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
}
|
840
|
-
},
|
841
|
-
});
|
842
|
-
/**
|
843
|
-
* Descriptor for ARIA reflections, e.g. `ariaLabel` and `role`.
|
844
|
-
*/
|
845
|
-
const ariaDescriptor = (attrName) => ({
|
846
|
-
configurable: true,
|
847
|
-
enumerable: true,
|
848
|
-
get() {
|
849
|
-
return this.getAttribute(attrName);
|
850
|
-
},
|
851
|
-
set(newValue) {
|
852
|
-
const currentValue = this.getAttribute(attrName);
|
853
|
-
if (newValue !== currentValue) {
|
854
|
-
// TODO [#3284]: According to the spec, IDL nullable type values
|
855
|
-
// (null and undefined) should remove the attribute; however, we
|
856
|
-
// only do so in the case of null for historical reasons.
|
857
|
-
if (isNull(newValue)) {
|
858
|
-
this.removeAttribute(attrName);
|
916
|
+
const { set, get } = descriptor;
|
917
|
+
if (!isUndefined(get)) {
|
918
|
+
descriptor.get = this.unwrapGetter(get);
|
859
919
|
}
|
860
|
-
|
861
|
-
this.
|
920
|
+
if (!isUndefined(set)) {
|
921
|
+
descriptor.set = this.unwrapSetter(set);
|
862
922
|
}
|
863
923
|
}
|
864
|
-
|
865
|
-
});
|
866
|
-
const tabIndexDescriptor = () => ({
|
867
|
-
configurable: true,
|
868
|
-
enumerable: true,
|
869
|
-
get() {
|
870
|
-
const str = this.getAttribute('tabindex');
|
871
|
-
const num = Number(str);
|
872
|
-
return isFinite(num) ? Math.trunc(num) : -1;
|
873
|
-
},
|
874
|
-
set(newValue) {
|
875
|
-
const currentValue = this.getAttribute('tabindex');
|
876
|
-
const num = Number(newValue);
|
877
|
-
const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
|
878
|
-
if (normalizedValue !== currentValue) {
|
879
|
-
this.setAttribute('tabindex', toString$1(newValue));
|
880
|
-
}
|
881
|
-
},
|
882
|
-
});
|
883
|
-
const descriptors = {
|
884
|
-
accessKey: stringDescriptor('accesskey'),
|
885
|
-
dir: stringDescriptor('dir'),
|
886
|
-
draggable: explicitBooleanDescriptor('draggable', true),
|
887
|
-
hidden: booleanAttributeDescriptor('hidden'),
|
888
|
-
id: stringDescriptor('id'),
|
889
|
-
lang: stringDescriptor('lang'),
|
890
|
-
spellcheck: explicitBooleanDescriptor('spellcheck', false),
|
891
|
-
tabIndex: tabIndexDescriptor(),
|
892
|
-
title: stringDescriptor('title'),
|
893
|
-
};
|
894
|
-
// Add descriptors for ARIA attributes
|
895
|
-
for (const [attrName, propName] of entries(AriaAttrNameToPropNameMap)) {
|
896
|
-
descriptors[propName] = ariaDescriptor(attrName);
|
897
|
-
}
|
898
|
-
|
899
|
-
/*
|
900
|
-
* Copyright (c) 2024, salesforce.com, inc.
|
901
|
-
* All rights reserved.
|
902
|
-
* SPDX-License-Identifier: MIT
|
903
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
904
|
-
*/
|
905
|
-
var _LightningElement_attrs, _LightningElement_classList;
|
906
|
-
const SYMBOL__SET_INTERNALS = Symbol('set-internals');
|
907
|
-
const SYMBOL__GENERATE_MARKUP = Symbol('generate-markup');
|
908
|
-
const SYMBOL__DEFAULT_TEMPLATE = Symbol('default-template');
|
909
|
-
class LightningElement {
|
910
|
-
constructor(propsAvailableAtConstruction) {
|
911
|
-
this.isConnected = false;
|
912
|
-
this.className = '';
|
913
|
-
_LightningElement_attrs.set(this, void 0);
|
914
|
-
_LightningElement_classList.set(this, null);
|
915
|
-
assign(this, propsAvailableAtConstruction);
|
916
|
-
}
|
917
|
-
[(_LightningElement_attrs = new WeakMap(), _LightningElement_classList = new WeakMap(), SYMBOL__SET_INTERNALS)](props, attrs) {
|
918
|
-
__classPrivateFieldSet(this, _LightningElement_attrs, attrs, "f");
|
919
|
-
assign(this, props);
|
920
|
-
defineProperty(this, 'className', {
|
921
|
-
get() {
|
922
|
-
return props.class ?? '';
|
923
|
-
},
|
924
|
-
set(newVal) {
|
925
|
-
props.class = newVal;
|
926
|
-
attrs.class = newVal;
|
927
|
-
mutationTracker.add(this, 'class');
|
928
|
-
},
|
929
|
-
});
|
924
|
+
return descriptor;
|
930
925
|
}
|
931
|
-
|
932
|
-
|
933
|
-
|
926
|
+
unwrapGetter(redGet) {
|
927
|
+
const reverseGetter = reverseGetterMap.get(redGet);
|
928
|
+
if (!isUndefined(reverseGetter)) {
|
929
|
+
return reverseGetter;
|
934
930
|
}
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
931
|
+
const handler = this;
|
932
|
+
const get = function () {
|
933
|
+
// invoking the red getter with the proxy of this
|
934
|
+
return unwrap(redGet.call(handler.wrapValue(this)));
|
935
|
+
};
|
936
|
+
getterMap$1.set(get, redGet);
|
937
|
+
reverseGetterMap.set(redGet, get);
|
938
|
+
return get;
|
942
939
|
}
|
943
|
-
|
944
|
-
const
|
945
|
-
if (
|
946
|
-
return
|
940
|
+
unwrapSetter(redSet) {
|
941
|
+
const reverseSetter = reverseSetterMap.get(redSet);
|
942
|
+
if (!isUndefined(reverseSetter)) {
|
943
|
+
return reverseSetter;
|
947
944
|
}
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
957
|
-
// Track mutations for removal of non-existing attributes
|
958
|
-
mutationTracker.add(this, normalizedName);
|
959
|
-
}
|
960
|
-
addEventListener(_type, _listener, _options) {
|
961
|
-
// noop
|
962
|
-
}
|
963
|
-
removeEventListener(_type, _listener, _options) {
|
964
|
-
// noop
|
965
|
-
}
|
966
|
-
// ----------------------------------------------------------- //
|
967
|
-
// Props/methods explicitly not available in this environment //
|
968
|
-
// Getters are named "get*" for parity with @lwc/engine-server //
|
969
|
-
// ----------------------------------------------------------- //
|
970
|
-
get children() {
|
971
|
-
throw new TypeError('"getChildren" is not supported in this environment');
|
972
|
-
}
|
973
|
-
get childNodes() {
|
974
|
-
throw new TypeError('"getChildNodes" is not supported in this environment');
|
975
|
-
}
|
976
|
-
get firstChild() {
|
977
|
-
throw new TypeError('"getFirstChild" is not supported in this environment');
|
978
|
-
}
|
979
|
-
get firstElementChild() {
|
980
|
-
throw new TypeError('"getFirstElementChild" is not supported in this environment');
|
981
|
-
}
|
982
|
-
get hostElement() {
|
983
|
-
// Intentionally different to match @lwc/engine-*core*
|
984
|
-
throw new TypeError('this.hostElement is not supported in this environment');
|
985
|
-
}
|
986
|
-
get lastChild() {
|
987
|
-
throw new TypeError('"getLastChild" is not supported in this environment');
|
988
|
-
}
|
989
|
-
get lastElementChild() {
|
990
|
-
throw new TypeError('"getLastElementChild" is not supported in this environment');
|
945
|
+
const handler = this;
|
946
|
+
const set = function (v) {
|
947
|
+
// invoking the red setter with the proxy of this
|
948
|
+
redSet.call(handler.wrapValue(this), handler.wrapValue(v));
|
949
|
+
};
|
950
|
+
setterMap$1.set(set, redSet);
|
951
|
+
reverseSetterMap.set(redSet, set);
|
952
|
+
return set;
|
991
953
|
}
|
992
|
-
|
993
|
-
|
994
|
-
|
954
|
+
set(shadowTarget, key, value) {
|
955
|
+
const { originalTarget, membrane: { valueMutated }, } = this;
|
956
|
+
const oldValue = originalTarget[key];
|
957
|
+
if (oldValue !== value) {
|
958
|
+
originalTarget[key] = value;
|
959
|
+
valueMutated(originalTarget, key);
|
960
|
+
}
|
961
|
+
else if (key === 'length' && isArray(originalTarget)) {
|
962
|
+
// fix for issue #236: push will add the new index, and by the time length
|
963
|
+
// is updated, the internal length is already equal to the new length value
|
964
|
+
// therefore, the oldValue is equal to the value. This is the forking logic
|
965
|
+
// to support this use case.
|
966
|
+
valueMutated(originalTarget, key);
|
967
|
+
}
|
968
|
+
return true;
|
995
969
|
}
|
996
|
-
|
997
|
-
|
998
|
-
|
970
|
+
deleteProperty(shadowTarget, key) {
|
971
|
+
const { originalTarget, membrane: { valueMutated }, } = this;
|
972
|
+
delete originalTarget[key];
|
973
|
+
valueMutated(originalTarget, key);
|
974
|
+
return true;
|
999
975
|
}
|
1000
|
-
|
1001
|
-
throw new TypeError('"attachInternals" is not supported in this environment');
|
976
|
+
setPrototypeOf(shadowTarget, prototype) {
|
1002
977
|
}
|
1003
|
-
|
1004
|
-
|
978
|
+
preventExtensions(shadowTarget) {
|
979
|
+
if (isExtensible(shadowTarget)) {
|
980
|
+
const { originalTarget } = this;
|
981
|
+
preventExtensions(originalTarget);
|
982
|
+
// if the originalTarget is a proxy itself, it might reject
|
983
|
+
// the preventExtension call, in which case we should not attempt to lock down
|
984
|
+
// the shadow target.
|
985
|
+
// TODO: It should not actually be possible to reach this `if` statement.
|
986
|
+
// If a proxy rejects extensions, then calling preventExtensions will throw an error:
|
987
|
+
// https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
|
988
|
+
/* istanbul ignore if */
|
989
|
+
if (isExtensible(originalTarget)) {
|
990
|
+
return false;
|
991
|
+
}
|
992
|
+
this.lockShadowTarget(shadowTarget);
|
993
|
+
}
|
994
|
+
return true;
|
1005
995
|
}
|
1006
|
-
|
1007
|
-
|
996
|
+
defineProperty(shadowTarget, key, descriptor) {
|
997
|
+
const { originalTarget, membrane: { valueMutated, tagPropertyKey }, } = this;
|
998
|
+
if (key === tagPropertyKey && !hasOwnProperty.call(originalTarget, key)) {
|
999
|
+
// To avoid leaking the membrane tag property into the original target, we must
|
1000
|
+
// be sure that the original target doesn't have yet.
|
1001
|
+
// NOTE: we do not return false here because Object.freeze and equivalent operations
|
1002
|
+
// will attempt to set the descriptor to the same value, and expect no to throw. This
|
1003
|
+
// is an small compromise for the sake of not having to diff the descriptors.
|
1004
|
+
return true;
|
1005
|
+
}
|
1006
|
+
ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor));
|
1007
|
+
// intentionally testing if false since it could be undefined as well
|
1008
|
+
if (descriptor.configurable === false) {
|
1009
|
+
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1010
|
+
}
|
1011
|
+
valueMutated(originalTarget, key);
|
1012
|
+
return true;
|
1008
1013
|
}
|
1009
|
-
|
1010
|
-
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
const getterMap = new WeakMap();
|
1017
|
+
const setterMap = new WeakMap();
|
1018
|
+
class ReadOnlyHandler extends BaseProxyHandler {
|
1019
|
+
wrapValue(value) {
|
1020
|
+
return this.membrane.getReadOnlyProxy(value);
|
1011
1021
|
}
|
1012
|
-
|
1013
|
-
|
1022
|
+
wrapGetter(originalGet) {
|
1023
|
+
const wrappedGetter = getterMap.get(originalGet);
|
1024
|
+
if (!isUndefined(wrappedGetter)) {
|
1025
|
+
return wrappedGetter;
|
1026
|
+
}
|
1027
|
+
const handler = this;
|
1028
|
+
const get = function () {
|
1029
|
+
// invoking the original getter with the original target
|
1030
|
+
return handler.wrapValue(originalGet.call(unwrap(this)));
|
1031
|
+
};
|
1032
|
+
getterMap.set(originalGet, get);
|
1033
|
+
return get;
|
1014
1034
|
}
|
1015
|
-
|
1016
|
-
|
1035
|
+
wrapSetter(originalSet) {
|
1036
|
+
const wrappedSetter = setterMap.get(originalSet);
|
1037
|
+
if (!isUndefined(wrappedSetter)) {
|
1038
|
+
return wrappedSetter;
|
1039
|
+
}
|
1040
|
+
const set = function (v) {
|
1041
|
+
};
|
1042
|
+
setterMap.set(originalSet, set);
|
1043
|
+
return set;
|
1017
1044
|
}
|
1018
|
-
|
1019
|
-
|
1045
|
+
set(shadowTarget, key, value) {
|
1046
|
+
/* istanbul ignore next */
|
1047
|
+
return false;
|
1020
1048
|
}
|
1021
|
-
|
1022
|
-
|
1049
|
+
deleteProperty(shadowTarget, key) {
|
1050
|
+
/* istanbul ignore next */
|
1051
|
+
return false;
|
1023
1052
|
}
|
1024
|
-
|
1025
|
-
throw new Error('Method "hasAttributeNS" not implemented.');
|
1053
|
+
setPrototypeOf(shadowTarget, prototype) {
|
1026
1054
|
}
|
1027
|
-
|
1028
|
-
|
1055
|
+
preventExtensions(shadowTarget) {
|
1056
|
+
/* istanbul ignore next */
|
1057
|
+
return false;
|
1029
1058
|
}
|
1030
|
-
|
1031
|
-
|
1059
|
+
defineProperty(shadowTarget, key, descriptor) {
|
1060
|
+
/* istanbul ignore next */
|
1061
|
+
return false;
|
1032
1062
|
}
|
1033
1063
|
}
|
1034
|
-
defineProperties(LightningElement.prototype, descriptors);
|
1035
1064
|
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1041
|
-
*/
|
1042
|
-
const escapeAttrVal = (attrValue) => attrValue.replaceAll('&', '&').replaceAll('"', '"');
|
1043
|
-
function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
|
1044
|
-
// The scopeToken is e.g. `lwc-xyz123` which is the token our parent gives us.
|
1045
|
-
// The hostScopeToken is e.g. `lwc-abc456-host` which is the token for our own component.
|
1046
|
-
// It's possible to have both, one, the other, or neither.
|
1047
|
-
const combinedScopeToken = scopeToken && hostScopeToken
|
1048
|
-
? `${scopeToken} ${hostScopeToken}`
|
1049
|
-
: scopeToken || hostScopeToken || '';
|
1050
|
-
let result = '';
|
1051
|
-
let hasClassAttribute = false;
|
1052
|
-
for (const attrName of getOwnPropertyNames$1(attrs)) {
|
1053
|
-
let attrValue = attrs[attrName];
|
1054
|
-
if (isNull(attrValue) || isUndefined$1(attrValue)) {
|
1055
|
-
attrValue = '';
|
1056
|
-
}
|
1057
|
-
else if (!isString(attrValue)) {
|
1058
|
-
attrValue = String(attrValue);
|
1059
|
-
}
|
1060
|
-
if (combinedScopeToken && attrName === 'class') {
|
1061
|
-
attrValue += ' ' + combinedScopeToken;
|
1062
|
-
hasClassAttribute = true;
|
1063
|
-
}
|
1064
|
-
result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
|
1065
|
+
function defaultValueIsObservable(value) {
|
1066
|
+
// intentionally checking for null
|
1067
|
+
if (value === null) {
|
1068
|
+
return false;
|
1065
1069
|
}
|
1066
|
-
//
|
1067
|
-
if (
|
1068
|
-
|
1070
|
+
// treat all non-object types, including undefined, as non-observable values
|
1071
|
+
if (typeof value !== 'object') {
|
1072
|
+
return false;
|
1069
1073
|
}
|
1070
|
-
|
1071
|
-
|
1072
|
-
result += ` data-lwc-host-scope-token="${hostScopeToken}"`;
|
1074
|
+
if (isArray(value)) {
|
1075
|
+
return true;
|
1073
1076
|
}
|
1074
|
-
|
1075
|
-
return
|
1076
|
-
}
|
1077
|
-
function* renderAttrs(instance, attrs, hostScopeToken, scopeToken) {
|
1078
|
-
yield renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken);
|
1079
|
-
}
|
1080
|
-
function renderAttrsNoYield(emit, instance, attrs, hostScopeToken, scopeToken) {
|
1081
|
-
emit(renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken));
|
1077
|
+
const proto = getPrototypeOf(value);
|
1078
|
+
return proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null;
|
1082
1079
|
}
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1080
|
+
const defaultValueObserved = (obj, key) => {
|
1081
|
+
/* do nothing */
|
1082
|
+
};
|
1083
|
+
const defaultValueMutated = (obj, key) => {
|
1084
|
+
/* do nothing */
|
1085
|
+
};
|
1086
|
+
function createShadowTarget(value) {
|
1087
|
+
return isArray(value) ? [] : {};
|
1087
1088
|
}
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1089
|
+
class ObservableMembrane {
|
1090
|
+
constructor(options = {}) {
|
1091
|
+
this.readOnlyObjectGraph = new WeakMap();
|
1092
|
+
this.reactiveObjectGraph = new WeakMap();
|
1093
|
+
const { valueMutated, valueObserved, valueIsObservable, tagPropertyKey } = options;
|
1094
|
+
this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
|
1095
|
+
this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
|
1096
|
+
this.valueIsObservable = isFunction(valueIsObservable)
|
1097
|
+
? valueIsObservable
|
1098
|
+
: defaultValueIsObservable;
|
1099
|
+
this.tagPropertyKey = tagPropertyKey;
|
1091
1100
|
}
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1101
|
+
getProxy(value) {
|
1102
|
+
const unwrappedValue = unwrap(value);
|
1103
|
+
if (this.valueIsObservable(unwrappedValue)) {
|
1104
|
+
// When trying to extract the writable version of a readonly we return the readonly.
|
1105
|
+
if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
|
1106
|
+
return value;
|
1107
|
+
}
|
1108
|
+
return this.getReactiveHandler(unwrappedValue);
|
1109
|
+
}
|
1110
|
+
return unwrappedValue;
|
1096
1111
|
}
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
};
|
1102
|
-
if (mode === 'asyncYield') {
|
1103
|
-
for await (const segment of generateMarkup(tagName, props, null, null, null)) {
|
1104
|
-
markup += segment;
|
1112
|
+
getReadOnlyProxy(value) {
|
1113
|
+
value = unwrap(value);
|
1114
|
+
if (this.valueIsObservable(value)) {
|
1115
|
+
return this.getReadOnlyHandler(value);
|
1105
1116
|
}
|
1117
|
+
return value;
|
1106
1118
|
}
|
1107
|
-
|
1108
|
-
|
1119
|
+
unwrapProxy(p) {
|
1120
|
+
return unwrap(p);
|
1109
1121
|
}
|
1110
|
-
|
1111
|
-
|
1122
|
+
getReactiveHandler(value) {
|
1123
|
+
let proxy = this.reactiveObjectGraph.get(value);
|
1124
|
+
if (isUndefined(proxy)) {
|
1125
|
+
// caching the proxy after the first time it is accessed
|
1126
|
+
const handler = new ReactiveProxyHandler(this, value);
|
1127
|
+
proxy = new Proxy(createShadowTarget(value), handler);
|
1128
|
+
registerProxy(proxy, value);
|
1129
|
+
this.reactiveObjectGraph.set(value, proxy);
|
1130
|
+
}
|
1131
|
+
return proxy;
|
1112
1132
|
}
|
1113
|
-
|
1114
|
-
|
1133
|
+
getReadOnlyHandler(value) {
|
1134
|
+
let proxy = this.readOnlyObjectGraph.get(value);
|
1135
|
+
if (isUndefined(proxy)) {
|
1136
|
+
// caching the proxy after the first time it is accessed
|
1137
|
+
const handler = new ReadOnlyHandler(this, value);
|
1138
|
+
proxy = new Proxy(createShadowTarget(value), handler);
|
1139
|
+
registerProxy(proxy, value);
|
1140
|
+
this.readOnlyObjectGraph.set(value, proxy);
|
1141
|
+
}
|
1142
|
+
return proxy;
|
1115
1143
|
}
|
1116
|
-
return markup;
|
1117
1144
|
}
|
1145
|
+
/** version: 2.0.0 */
|
1118
1146
|
|
1119
1147
|
/*
|
1120
1148
|
* Copyright (c) 2024, Salesforce, Inc.
|
@@ -1122,90 +1150,231 @@ async function serverSideRenderComponent(tagName, Component, props = {}, mode =
|
|
1122
1150
|
* SPDX-License-Identifier: MIT
|
1123
1151
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1124
1152
|
*/
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
* > - U+0009 CHARACTER TABULATION (tab)
|
1132
|
-
* > - U+000A LINE FEED (LF)
|
1133
|
-
* > - U+000C FORM FEED (FF)
|
1134
|
-
* > - U+000D CARRIAGE RETURN (CR)
|
1135
|
-
* > - U+0020 SPACE
|
1136
|
-
* > - U+003E GREATER-THAN SIGN (>), or
|
1137
|
-
* > - U+002F SOLIDUS (/)
|
1138
|
-
* @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
|
1139
|
-
*/
|
1140
|
-
const INVALID_STYLE_CONTENT = /<\/style[\t\n\f\r >/]/i;
|
1141
|
-
/**
|
1142
|
-
* The text content inside `<style>` is a special case. It is _only_ rendered by the LWC engine itself; `<style>` tags
|
1143
|
-
* are disallowed inside of HTML templates.
|
1144
|
-
*
|
1145
|
-
* The `<style>` tag is unusual in how it's defined in HTML. Like `<script>`, it is considered a "raw text element,"
|
1146
|
-
* which means that it is parsed as raw text, but certain character sequences are disallowed, namely to avoid XSS
|
1147
|
-
* attacks like `</style><script>alert("pwned")</script>`.
|
1148
|
-
*
|
1149
|
-
* This also means that we cannot use "normal" HTML escaping inside `<style>` tags, e.g. we cannot use `<`,
|
1150
|
-
* `>`, etc., because these are treated as-is by the HTML parser.
|
1151
|
-
*
|
1152
|
-
*
|
1153
|
-
* @param contents CSS source to validate
|
1154
|
-
* @throws Throws if the contents provided are not valid.
|
1155
|
-
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
1156
|
-
* @see https://github.com/salesforce/lwc/issues/3439
|
1157
|
-
* @example
|
1158
|
-
* validateStyleTextContents('div { color: red }') // Ok
|
1159
|
-
* validateStyleTextContents('</style><script>alert("pwned")</script>') // Throws
|
1160
|
-
*/
|
1161
|
-
function validateStyleTextContents(contents) {
|
1162
|
-
if (INVALID_STYLE_CONTENT.test(contents)) {
|
1163
|
-
throw new Error('CSS contains unsafe characters and cannot be serialized inside a style element');
|
1164
|
-
}
|
1153
|
+
const reactiveMembrane = new ObservableMembrane();
|
1154
|
+
// Modeled after `getReadOnlyProxy` in `membrane.ts` in `engine-core`
|
1155
|
+
// Return a proxy over the given object so that access is immutable
|
1156
|
+
// https://github.com/salesforce/lwc/blob/e9db491/packages/%40lwc/engine-core/src/framework/membrane.ts#L29-L33
|
1157
|
+
function getReadOnlyProxy(value) {
|
1158
|
+
return reactiveMembrane.getReadOnlyProxy(value);
|
1165
1159
|
}
|
1166
1160
|
|
1161
|
+
/******************************************************************************
|
1162
|
+
Copyright (c) Microsoft Corporation.
|
1163
|
+
|
1164
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
1165
|
+
purpose with or without fee is hereby granted.
|
1166
|
+
|
1167
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
1168
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
1169
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
1170
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
1171
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
1172
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
1173
|
+
PERFORMANCE OF THIS SOFTWARE.
|
1174
|
+
***************************************************************************** */
|
1175
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
1176
|
+
|
1177
|
+
|
1178
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
1179
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
1180
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
1181
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
1185
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
1186
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
1187
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
1188
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
1189
|
+
}
|
1190
|
+
|
1191
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
1192
|
+
var e = new Error(message);
|
1193
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
1194
|
+
};
|
1195
|
+
|
1167
1196
|
/*
|
1168
1197
|
* Copyright (c) 2024, Salesforce, Inc.
|
1169
1198
|
* All rights reserved.
|
1170
1199
|
* SPDX-License-Identifier: MIT
|
1171
1200
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1172
1201
|
*/
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1202
|
+
var _MutationTracker_enabledSet, _MutationTracker_mutationMap;
|
1203
|
+
class MutationTracker {
|
1204
|
+
constructor() {
|
1205
|
+
_MutationTracker_enabledSet.set(this, new WeakSet());
|
1206
|
+
_MutationTracker_mutationMap.set(this, new WeakMap());
|
1207
|
+
}
|
1208
|
+
add(instance, attrName) {
|
1209
|
+
if (__classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").has(instance)) {
|
1210
|
+
let mutatedAttrs = __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").get(instance);
|
1211
|
+
if (!mutatedAttrs) {
|
1212
|
+
mutatedAttrs = new Set();
|
1213
|
+
__classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").set(instance, mutatedAttrs);
|
1214
|
+
}
|
1215
|
+
mutatedAttrs.add(attrName.toLowerCase());
|
1178
1216
|
}
|
1179
1217
|
}
|
1180
|
-
|
1181
|
-
|
1218
|
+
enable(instance) {
|
1219
|
+
__classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").add(instance);
|
1220
|
+
}
|
1221
|
+
disable(instance) {
|
1222
|
+
__classPrivateFieldGet(this, _MutationTracker_enabledSet, "f").delete(instance);
|
1223
|
+
}
|
1224
|
+
renderMutatedAttrs(instance) {
|
1225
|
+
const mutatedAttrs = __classPrivateFieldGet(this, _MutationTracker_mutationMap, "f").get(instance);
|
1226
|
+
if (mutatedAttrs) {
|
1227
|
+
return ` data-lwc-host-mutated="${[...mutatedAttrs].sort().join(' ')}"`;
|
1228
|
+
}
|
1229
|
+
else {
|
1230
|
+
return '';
|
1231
|
+
}
|
1182
1232
|
}
|
1183
1233
|
}
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1234
|
+
_MutationTracker_enabledSet = new WeakMap(), _MutationTracker_mutationMap = new WeakMap();
|
1235
|
+
const mutationTracker = new MutationTracker();
|
1236
|
+
|
1237
|
+
/*
|
1238
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
1239
|
+
* All rights reserved.
|
1240
|
+
* SPDX-License-Identifier: MIT
|
1241
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1242
|
+
*/
|
1243
|
+
/**
|
1244
|
+
* Filters out the following types of properties that should not be set.
|
1245
|
+
* - Properties that are not public.
|
1246
|
+
* - Properties that are not global.
|
1247
|
+
* - Properties that are global but are internally overridden.
|
1248
|
+
*/
|
1249
|
+
function filterProperties(props, publicFields, privateFields) {
|
1250
|
+
const propsToAssign = create(null);
|
1251
|
+
const publicFieldSet = new Set(publicFields);
|
1252
|
+
const privateFieldSet = new Set(privateFields);
|
1253
|
+
keys(props).forEach((propName) => {
|
1254
|
+
const attrName = htmlPropertyToAttribute(propName);
|
1255
|
+
if (publicFieldSet.has(propName) ||
|
1256
|
+
((isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) &&
|
1257
|
+
!privateFieldSet.has(propName))) {
|
1258
|
+
propsToAssign[propName] = props[propName];
|
1259
|
+
}
|
1188
1260
|
});
|
1189
|
-
return
|
1261
|
+
return propsToAssign;
|
1190
1262
|
}
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1263
|
+
/**
|
1264
|
+
* Descriptor for IDL attribute reflections that merely reflect the string, e.g. `title`.
|
1265
|
+
*/
|
1266
|
+
const stringDescriptor = (attrName) => ({
|
1267
|
+
configurable: true,
|
1268
|
+
enumerable: true,
|
1269
|
+
get() {
|
1270
|
+
return this.getAttribute(attrName);
|
1271
|
+
},
|
1272
|
+
set(newValue) {
|
1273
|
+
const currentValue = this.getAttribute(attrName);
|
1274
|
+
const normalizedValue = String(newValue);
|
1275
|
+
if (normalizedValue !== currentValue) {
|
1276
|
+
this.setAttribute(attrName, normalizedValue);
|
1277
|
+
}
|
1278
|
+
},
|
1279
|
+
});
|
1280
|
+
/** Descriptor for a boolean that checks for `attr="true"` or `attr="false"`, e.g. `spellcheck` and `draggable`. */
|
1281
|
+
const explicitBooleanDescriptor = (attrName, defaultValue) => ({
|
1282
|
+
configurable: true,
|
1283
|
+
enumerable: true,
|
1284
|
+
get() {
|
1285
|
+
const value = this.getAttribute(attrName);
|
1286
|
+
if (value === null)
|
1287
|
+
return defaultValue;
|
1288
|
+
// spellcheck=false => false, everything else => true
|
1289
|
+
// draggable=true => true, everything else => false
|
1290
|
+
return value.toLowerCase() === String(defaultValue) ? defaultValue : !defaultValue;
|
1291
|
+
},
|
1292
|
+
set(newValue) {
|
1293
|
+
const currentValue = this.getAttribute(attrName);
|
1294
|
+
const normalizedValue = String(Boolean(newValue));
|
1295
|
+
if (normalizedValue !== currentValue) {
|
1296
|
+
this.setAttribute(attrName, normalizedValue);
|
1297
|
+
}
|
1298
|
+
},
|
1299
|
+
});
|
1300
|
+
/**
|
1301
|
+
* Descriptor for a "true" boolean attribute that checks solely for presence, e.g. `hidden`.
|
1302
|
+
*/
|
1303
|
+
const booleanAttributeDescriptor = (attrName) => ({
|
1304
|
+
configurable: true,
|
1305
|
+
enumerable: true,
|
1306
|
+
get() {
|
1307
|
+
return this.hasAttribute(attrName);
|
1308
|
+
},
|
1309
|
+
set(newValue) {
|
1310
|
+
const hasAttribute = this.hasAttribute(attrName);
|
1311
|
+
if (newValue) {
|
1312
|
+
if (!hasAttribute) {
|
1313
|
+
this.setAttribute(attrName, '');
|
1314
|
+
}
|
1315
|
+
}
|
1316
|
+
else {
|
1317
|
+
if (hasAttribute) {
|
1318
|
+
this.removeAttribute(attrName);
|
1319
|
+
}
|
1320
|
+
}
|
1321
|
+
},
|
1322
|
+
});
|
1323
|
+
/**
|
1324
|
+
* Descriptor for ARIA reflections, e.g. `ariaLabel` and `role`.
|
1325
|
+
*/
|
1326
|
+
const ariaDescriptor = (attrName) => ({
|
1327
|
+
configurable: true,
|
1328
|
+
enumerable: true,
|
1329
|
+
get() {
|
1330
|
+
return this.getAttribute(attrName);
|
1331
|
+
},
|
1332
|
+
set(newValue) {
|
1333
|
+
const currentValue = this.getAttribute(attrName);
|
1334
|
+
if (newValue !== currentValue) {
|
1335
|
+
// TODO [#3284]: According to the spec, IDL nullable type values
|
1336
|
+
// (null and undefined) should remove the attribute; however, we
|
1337
|
+
// only do so in the case of null for historical reasons.
|
1338
|
+
if (isNull(newValue)) {
|
1339
|
+
this.removeAttribute(attrName);
|
1340
|
+
}
|
1341
|
+
else {
|
1342
|
+
this.setAttribute(attrName, toString(newValue));
|
1343
|
+
}
|
1344
|
+
}
|
1345
|
+
},
|
1346
|
+
});
|
1347
|
+
const tabIndexDescriptor = () => ({
|
1348
|
+
configurable: true,
|
1349
|
+
enumerable: true,
|
1350
|
+
get() {
|
1351
|
+
const str = this.getAttribute('tabindex');
|
1352
|
+
const num = Number(str);
|
1353
|
+
return isFinite(num) ? Math.trunc(num) : -1;
|
1354
|
+
},
|
1355
|
+
set(newValue) {
|
1356
|
+
const currentValue = this.getAttribute('tabindex');
|
1357
|
+
const num = Number(newValue);
|
1358
|
+
const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
|
1359
|
+
if (normalizedValue !== currentValue) {
|
1360
|
+
this.setAttribute('tabindex', toString(newValue));
|
1361
|
+
}
|
1362
|
+
},
|
1363
|
+
});
|
1364
|
+
const descriptors = {
|
1365
|
+
accessKey: stringDescriptor('accesskey'),
|
1366
|
+
dir: stringDescriptor('dir'),
|
1367
|
+
draggable: explicitBooleanDescriptor('draggable', true),
|
1368
|
+
hidden: booleanAttributeDescriptor('hidden'),
|
1369
|
+
id: stringDescriptor('id'),
|
1370
|
+
lang: stringDescriptor('lang'),
|
1371
|
+
spellcheck: explicitBooleanDescriptor('spellcheck', false),
|
1372
|
+
tabIndex: tabIndexDescriptor(),
|
1373
|
+
title: stringDescriptor('title'),
|
1374
|
+
};
|
1375
|
+
// Add descriptors for ARIA attributes
|
1376
|
+
for (const [attrName, propName] of entries(AriaAttrNameToPropNameMap)) {
|
1377
|
+
descriptors[propName] = ariaDescriptor(attrName);
|
1209
1378
|
}
|
1210
1379
|
|
1211
1380
|
/*
|
@@ -1214,581 +1383,225 @@ function renderStylesheets(defaultStylesheets, defaultScopedStylesheets, staticS
|
|
1214
1383
|
* SPDX-License-Identifier: MIT
|
1215
1384
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1216
1385
|
*/
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
}
|
1229
|
-
const iterator = iterable[Symbol.iterator]();
|
1230
|
-
let next = iterator.next();
|
1231
|
-
let index = 0;
|
1232
|
-
let { value, done: last = false } = next;
|
1233
|
-
while (last === false) {
|
1234
|
-
// using a look-back approach because we need to know if the element is the last
|
1235
|
-
next = iterator.next();
|
1236
|
-
last = next.done ?? false;
|
1237
|
-
yield {
|
1238
|
-
value,
|
1239
|
-
index,
|
1240
|
-
first: index === 0,
|
1241
|
-
last,
|
1242
|
-
};
|
1243
|
-
index += 1;
|
1244
|
-
value = next.value;
|
1245
|
-
}
|
1246
|
-
}
|
1247
|
-
|
1248
|
-
/**
|
1249
|
-
* Copyright (C) 2017 salesforce.com, inc.
|
1250
|
-
*/
|
1251
|
-
const { isArray } = Array;
|
1252
|
-
const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
|
1253
|
-
const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
|
1254
|
-
const OtS = {}.toString;
|
1255
|
-
function toString(obj) {
|
1256
|
-
if (obj && obj.toString) {
|
1257
|
-
return obj.toString();
|
1258
|
-
}
|
1259
|
-
else if (typeof obj === 'object') {
|
1260
|
-
return OtS.call(obj);
|
1261
|
-
}
|
1262
|
-
else {
|
1263
|
-
return obj + '';
|
1386
|
+
var _LightningElement_attrs, _LightningElement_classList;
|
1387
|
+
const SYMBOL__SET_INTERNALS = Symbol('set-internals');
|
1388
|
+
const SYMBOL__GENERATE_MARKUP = Symbol('generate-markup');
|
1389
|
+
const SYMBOL__DEFAULT_TEMPLATE = Symbol('default-template');
|
1390
|
+
class LightningElement {
|
1391
|
+
constructor(propsAvailableAtConstruction) {
|
1392
|
+
this.isConnected = false;
|
1393
|
+
this.className = '';
|
1394
|
+
_LightningElement_attrs.set(this, void 0);
|
1395
|
+
_LightningElement_classList.set(this, null);
|
1396
|
+
assign(this, propsAvailableAtConstruction);
|
1264
1397
|
}
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
}
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
class BaseProxyHandler {
|
1279
|
-
constructor(membrane, value) {
|
1280
|
-
this.originalTarget = value;
|
1281
|
-
this.membrane = membrane;
|
1398
|
+
[(_LightningElement_attrs = new WeakMap(), _LightningElement_classList = new WeakMap(), SYMBOL__SET_INTERNALS)](props, attrs) {
|
1399
|
+
__classPrivateFieldSet(this, _LightningElement_attrs, attrs, "f");
|
1400
|
+
assign(this, props);
|
1401
|
+
defineProperty(this, 'className', {
|
1402
|
+
get() {
|
1403
|
+
return props.class ?? '';
|
1404
|
+
},
|
1405
|
+
set(newVal) {
|
1406
|
+
props.class = newVal;
|
1407
|
+
attrs.class = newVal;
|
1408
|
+
mutationTracker.add(this, 'class');
|
1409
|
+
},
|
1410
|
+
});
|
1282
1411
|
}
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
descriptor.value = this.wrapValue(descriptor.value);
|
1287
|
-
}
|
1288
|
-
else {
|
1289
|
-
const { set: originalSet, get: originalGet } = descriptor;
|
1290
|
-
if (!isUndefined(originalGet)) {
|
1291
|
-
descriptor.get = this.wrapGetter(originalGet);
|
1292
|
-
}
|
1293
|
-
if (!isUndefined(originalSet)) {
|
1294
|
-
descriptor.set = this.wrapSetter(originalSet);
|
1295
|
-
}
|
1412
|
+
get classList() {
|
1413
|
+
if (__classPrivateFieldGet(this, _LightningElement_classList, "f")) {
|
1414
|
+
return __classPrivateFieldGet(this, _LightningElement_classList, "f");
|
1296
1415
|
}
|
1297
|
-
return
|
1416
|
+
return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
|
1298
1417
|
}
|
1299
|
-
|
1300
|
-
const
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
|
1305
|
-
// TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
|
1306
|
-
/* istanbul ignore else */
|
1307
|
-
if (!isUndefined(originalDescriptor)) {
|
1308
|
-
const wrappedDesc = this.wrapDescriptor(originalDescriptor);
|
1309
|
-
ObjectDefineProperty(shadowTarget, key, wrappedDesc);
|
1310
|
-
}
|
1418
|
+
setAttribute(attrName, attrValue) {
|
1419
|
+
const normalizedName = StringToLowerCase.call(toString(attrName));
|
1420
|
+
const normalizedValue = String(attrValue);
|
1421
|
+
__classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
|
1422
|
+
mutationTracker.add(this, normalizedName);
|
1311
1423
|
}
|
1312
|
-
|
1313
|
-
const
|
1314
|
-
|
1315
|
-
|
1316
|
-
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1317
|
-
});
|
1318
|
-
const { membrane: { tagPropertyKey }, } = this;
|
1319
|
-
if (!isUndefined(tagPropertyKey) && !hasOwnProperty.call(shadowTarget, tagPropertyKey)) {
|
1320
|
-
ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
|
1424
|
+
getAttribute(attrName) {
|
1425
|
+
const normalizedName = StringToLowerCase.call(toString(attrName));
|
1426
|
+
if (hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
|
1427
|
+
return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
1321
1428
|
}
|
1322
|
-
|
1323
|
-
}
|
1324
|
-
// Shared Traps
|
1325
|
-
// TODO: apply() is never called
|
1326
|
-
/* istanbul ignore next */
|
1327
|
-
apply(shadowTarget, thisArg, argArray) {
|
1328
|
-
/* No op */
|
1329
|
-
}
|
1330
|
-
// TODO: construct() is never called
|
1331
|
-
/* istanbul ignore next */
|
1332
|
-
construct(shadowTarget, argArray, newTarget) {
|
1333
|
-
/* No op */
|
1334
|
-
}
|
1335
|
-
get(shadowTarget, key) {
|
1336
|
-
const { originalTarget, membrane: { valueObserved }, } = this;
|
1337
|
-
const value = originalTarget[key];
|
1338
|
-
valueObserved(originalTarget, key);
|
1339
|
-
return this.wrapValue(value);
|
1340
|
-
}
|
1341
|
-
has(shadowTarget, key) {
|
1342
|
-
const { originalTarget, membrane: { tagPropertyKey, valueObserved }, } = this;
|
1343
|
-
valueObserved(originalTarget, key);
|
1344
|
-
// since key is never going to be undefined, and tagPropertyKey might be undefined
|
1345
|
-
// we can simply compare them as the second part of the condition.
|
1346
|
-
return key in originalTarget || key === tagPropertyKey;
|
1347
|
-
}
|
1348
|
-
ownKeys(shadowTarget) {
|
1349
|
-
const { originalTarget, membrane: { tagPropertyKey }, } = this;
|
1350
|
-
// if the membrane tag key exists and it is not in the original target, we add it to the keys.
|
1351
|
-
const keys = isUndefined(tagPropertyKey) || hasOwnProperty.call(originalTarget, tagPropertyKey)
|
1352
|
-
? []
|
1353
|
-
: [tagPropertyKey];
|
1354
|
-
// small perf optimization using push instead of concat to avoid creating an extra array
|
1355
|
-
ArrayPush.apply(keys, getOwnPropertyNames(originalTarget));
|
1356
|
-
ArrayPush.apply(keys, getOwnPropertySymbols(originalTarget));
|
1357
|
-
return keys;
|
1429
|
+
return null;
|
1358
1430
|
}
|
1359
|
-
|
1360
|
-
const
|
1361
|
-
|
1362
|
-
if (!isExtensible(shadowTarget)) {
|
1363
|
-
return false; // was already locked down
|
1364
|
-
}
|
1365
|
-
if (!isExtensible(originalTarget)) {
|
1366
|
-
this.lockShadowTarget(shadowTarget);
|
1367
|
-
return false;
|
1368
|
-
}
|
1369
|
-
return true;
|
1431
|
+
hasAttribute(attrName) {
|
1432
|
+
const normalizedName = StringToLowerCase.call(toString(attrName));
|
1433
|
+
return hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
|
1370
1434
|
}
|
1371
|
-
|
1372
|
-
const
|
1373
|
-
|
1435
|
+
removeAttribute(attrName) {
|
1436
|
+
const normalizedName = StringToLowerCase.call(toString(attrName));
|
1437
|
+
delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
1438
|
+
// Track mutations for removal of non-existing attributes
|
1439
|
+
mutationTracker.add(this, normalizedName);
|
1374
1440
|
}
|
1375
|
-
|
1376
|
-
|
1377
|
-
// keys looked up via getOwnPropertyDescriptor need to be reactive
|
1378
|
-
valueObserved(originalTarget, key);
|
1379
|
-
let desc = getOwnPropertyDescriptor(originalTarget, key);
|
1380
|
-
if (isUndefined(desc)) {
|
1381
|
-
if (key !== tagPropertyKey) {
|
1382
|
-
return undefined;
|
1383
|
-
}
|
1384
|
-
// if the key is the membrane tag key, and is not in the original target,
|
1385
|
-
// we produce a synthetic descriptor and install it on the shadow target
|
1386
|
-
desc = { value: undefined, writable: false, configurable: false, enumerable: false };
|
1387
|
-
ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
|
1388
|
-
return desc;
|
1389
|
-
}
|
1390
|
-
if (desc.configurable === false) {
|
1391
|
-
// updating the descriptor to non-configurable on the shadow
|
1392
|
-
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1393
|
-
}
|
1394
|
-
// Note: by accessing the descriptor, the key is marked as observed
|
1395
|
-
// but access to the value, setter or getter (if available) cannot observe
|
1396
|
-
// mutations, just like regular methods, in which case we just do nothing.
|
1397
|
-
return this.wrapDescriptor(desc);
|
1441
|
+
addEventListener(_type, _listener, _options) {
|
1442
|
+
// noop
|
1398
1443
|
}
|
1399
|
-
|
1400
|
-
|
1401
|
-
const getterMap$1 = new WeakMap();
|
1402
|
-
const setterMap$1 = new WeakMap();
|
1403
|
-
const reverseGetterMap = new WeakMap();
|
1404
|
-
const reverseSetterMap = new WeakMap();
|
1405
|
-
class ReactiveProxyHandler extends BaseProxyHandler {
|
1406
|
-
wrapValue(value) {
|
1407
|
-
return this.membrane.getProxy(value);
|
1444
|
+
removeEventListener(_type, _listener, _options) {
|
1445
|
+
// noop
|
1408
1446
|
}
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
const get = function () {
|
1416
|
-
// invoking the original getter with the original target
|
1417
|
-
return handler.wrapValue(originalGet.call(unwrap(this)));
|
1418
|
-
};
|
1419
|
-
getterMap$1.set(originalGet, get);
|
1420
|
-
reverseGetterMap.set(get, originalGet);
|
1421
|
-
return get;
|
1447
|
+
// ----------------------------------------------------------- //
|
1448
|
+
// Props/methods explicitly not available in this environment //
|
1449
|
+
// Getters are named "get*" for parity with @lwc/engine-server //
|
1450
|
+
// ----------------------------------------------------------- //
|
1451
|
+
get children() {
|
1452
|
+
throw new TypeError('"getChildren" is not supported in this environment');
|
1422
1453
|
}
|
1423
|
-
|
1424
|
-
|
1425
|
-
if (!isUndefined(wrappedSetter)) {
|
1426
|
-
return wrappedSetter;
|
1427
|
-
}
|
1428
|
-
const set = function (v) {
|
1429
|
-
// invoking the original setter with the original target
|
1430
|
-
originalSet.call(unwrap(this), unwrap(v));
|
1431
|
-
};
|
1432
|
-
setterMap$1.set(originalSet, set);
|
1433
|
-
reverseSetterMap.set(set, originalSet);
|
1434
|
-
return set;
|
1454
|
+
get childNodes() {
|
1455
|
+
throw new TypeError('"getChildNodes" is not supported in this environment');
|
1435
1456
|
}
|
1436
|
-
|
1437
|
-
|
1438
|
-
// dealing with a data descriptor
|
1439
|
-
descriptor.value = unwrap(descriptor.value);
|
1440
|
-
}
|
1441
|
-
else {
|
1442
|
-
const { set, get } = descriptor;
|
1443
|
-
if (!isUndefined(get)) {
|
1444
|
-
descriptor.get = this.unwrapGetter(get);
|
1445
|
-
}
|
1446
|
-
if (!isUndefined(set)) {
|
1447
|
-
descriptor.set = this.unwrapSetter(set);
|
1448
|
-
}
|
1449
|
-
}
|
1450
|
-
return descriptor;
|
1457
|
+
get firstChild() {
|
1458
|
+
throw new TypeError('"getFirstChild" is not supported in this environment');
|
1451
1459
|
}
|
1452
|
-
|
1453
|
-
|
1454
|
-
if (!isUndefined(reverseGetter)) {
|
1455
|
-
return reverseGetter;
|
1456
|
-
}
|
1457
|
-
const handler = this;
|
1458
|
-
const get = function () {
|
1459
|
-
// invoking the red getter with the proxy of this
|
1460
|
-
return unwrap(redGet.call(handler.wrapValue(this)));
|
1461
|
-
};
|
1462
|
-
getterMap$1.set(get, redGet);
|
1463
|
-
reverseGetterMap.set(redGet, get);
|
1464
|
-
return get;
|
1460
|
+
get firstElementChild() {
|
1461
|
+
throw new TypeError('"getFirstElementChild" is not supported in this environment');
|
1465
1462
|
}
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
return reverseSetter;
|
1470
|
-
}
|
1471
|
-
const handler = this;
|
1472
|
-
const set = function (v) {
|
1473
|
-
// invoking the red setter with the proxy of this
|
1474
|
-
redSet.call(handler.wrapValue(this), handler.wrapValue(v));
|
1475
|
-
};
|
1476
|
-
setterMap$1.set(set, redSet);
|
1477
|
-
reverseSetterMap.set(redSet, set);
|
1478
|
-
return set;
|
1463
|
+
get hostElement() {
|
1464
|
+
// Intentionally different to match @lwc/engine-*core*
|
1465
|
+
throw new TypeError('this.hostElement is not supported in this environment');
|
1479
1466
|
}
|
1480
|
-
|
1481
|
-
|
1482
|
-
const oldValue = originalTarget[key];
|
1483
|
-
if (oldValue !== value) {
|
1484
|
-
originalTarget[key] = value;
|
1485
|
-
valueMutated(originalTarget, key);
|
1486
|
-
}
|
1487
|
-
else if (key === 'length' && isArray(originalTarget)) {
|
1488
|
-
// fix for issue #236: push will add the new index, and by the time length
|
1489
|
-
// is updated, the internal length is already equal to the new length value
|
1490
|
-
// therefore, the oldValue is equal to the value. This is the forking logic
|
1491
|
-
// to support this use case.
|
1492
|
-
valueMutated(originalTarget, key);
|
1493
|
-
}
|
1494
|
-
return true;
|
1467
|
+
get lastChild() {
|
1468
|
+
throw new TypeError('"getLastChild" is not supported in this environment');
|
1495
1469
|
}
|
1496
|
-
|
1497
|
-
|
1498
|
-
delete originalTarget[key];
|
1499
|
-
valueMutated(originalTarget, key);
|
1500
|
-
return true;
|
1470
|
+
get lastElementChild() {
|
1471
|
+
throw new TypeError('"getLastElementChild" is not supported in this environment');
|
1501
1472
|
}
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
|
1506
|
-
}
|
1473
|
+
get ownerDocument() {
|
1474
|
+
// Intentionally not "get*" to match @lwc/engine-server
|
1475
|
+
throw new TypeError('"ownerDocument" is not supported in this environment');
|
1507
1476
|
}
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
preventExtensions(originalTarget);
|
1512
|
-
// if the originalTarget is a proxy itself, it might reject
|
1513
|
-
// the preventExtension call, in which case we should not attempt to lock down
|
1514
|
-
// the shadow target.
|
1515
|
-
// TODO: It should not actually be possible to reach this `if` statement.
|
1516
|
-
// If a proxy rejects extensions, then calling preventExtensions will throw an error:
|
1517
|
-
// https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
|
1518
|
-
/* istanbul ignore if */
|
1519
|
-
if (isExtensible(originalTarget)) {
|
1520
|
-
return false;
|
1521
|
-
}
|
1522
|
-
this.lockShadowTarget(shadowTarget);
|
1523
|
-
}
|
1524
|
-
return true;
|
1477
|
+
get style() {
|
1478
|
+
// Intentionally not "get*" to match @lwc/engine-server
|
1479
|
+
throw new TypeError('"style" is not supported in this environment');
|
1525
1480
|
}
|
1526
|
-
|
1527
|
-
|
1528
|
-
if (key === tagPropertyKey && !hasOwnProperty.call(originalTarget, key)) {
|
1529
|
-
// To avoid leaking the membrane tag property into the original target, we must
|
1530
|
-
// be sure that the original target doesn't have yet.
|
1531
|
-
// NOTE: we do not return false here because Object.freeze and equivalent operations
|
1532
|
-
// will attempt to set the descriptor to the same value, and expect no to throw. This
|
1533
|
-
// is an small compromise for the sake of not having to diff the descriptors.
|
1534
|
-
return true;
|
1535
|
-
}
|
1536
|
-
ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor));
|
1537
|
-
// intentionally testing if false since it could be undefined as well
|
1538
|
-
if (descriptor.configurable === false) {
|
1539
|
-
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1540
|
-
}
|
1541
|
-
valueMutated(originalTarget, key);
|
1542
|
-
return true;
|
1481
|
+
attachInternals() {
|
1482
|
+
throw new TypeError('"attachInternals" is not supported in this environment');
|
1543
1483
|
}
|
1544
|
-
|
1545
|
-
|
1546
|
-
const getterMap = new WeakMap();
|
1547
|
-
const setterMap = new WeakMap();
|
1548
|
-
class ReadOnlyHandler extends BaseProxyHandler {
|
1549
|
-
wrapValue(value) {
|
1550
|
-
return this.membrane.getReadOnlyProxy(value);
|
1484
|
+
dispatchEvent(_event) {
|
1485
|
+
throw new TypeError('"dispatchEvent" is not supported in this environment');
|
1551
1486
|
}
|
1552
|
-
|
1553
|
-
|
1554
|
-
if (!isUndefined(wrappedGetter)) {
|
1555
|
-
return wrappedGetter;
|
1556
|
-
}
|
1557
|
-
const handler = this;
|
1558
|
-
const get = function () {
|
1559
|
-
// invoking the original getter with the original target
|
1560
|
-
return handler.wrapValue(originalGet.call(unwrap(this)));
|
1561
|
-
};
|
1562
|
-
getterMap.set(originalGet, get);
|
1563
|
-
return get;
|
1487
|
+
getBoundingClientRect() {
|
1488
|
+
throw new TypeError('"getBoundingClientRect" is not supported in this environment');
|
1564
1489
|
}
|
1565
|
-
|
1566
|
-
|
1567
|
-
if (!isUndefined(wrappedSetter)) {
|
1568
|
-
return wrappedSetter;
|
1569
|
-
}
|
1570
|
-
const handler = this;
|
1571
|
-
const set = function (v) {
|
1572
|
-
/* istanbul ignore else */
|
1573
|
-
if (process.env.NODE_ENV !== 'production') {
|
1574
|
-
const { originalTarget } = handler;
|
1575
|
-
throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
|
1576
|
-
}
|
1577
|
-
};
|
1578
|
-
setterMap.set(originalSet, set);
|
1579
|
-
return set;
|
1490
|
+
getElementsByClassName(_classNames) {
|
1491
|
+
throw new TypeError('"getElementsByClassName" is not supported in this environment');
|
1580
1492
|
}
|
1581
|
-
|
1582
|
-
|
1583
|
-
if (process.env.NODE_ENV !== 'production') {
|
1584
|
-
const { originalTarget } = this;
|
1585
|
-
const msg = isArray(originalTarget)
|
1586
|
-
? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
|
1587
|
-
: `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
|
1588
|
-
throw new Error(msg);
|
1589
|
-
}
|
1590
|
-
/* istanbul ignore next */
|
1591
|
-
return false;
|
1493
|
+
getElementsByTagName(_qualifiedName) {
|
1494
|
+
throw new TypeError('"getElementsByTagName" is not supported in this environment');
|
1592
1495
|
}
|
1593
|
-
|
1594
|
-
|
1595
|
-
if (process.env.NODE_ENV !== 'production') {
|
1596
|
-
const { originalTarget } = this;
|
1597
|
-
throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
|
1598
|
-
}
|
1599
|
-
/* istanbul ignore next */
|
1600
|
-
return false;
|
1496
|
+
querySelector(_selectors) {
|
1497
|
+
throw new TypeError('"querySelector" is not supported in this environment');
|
1601
1498
|
}
|
1602
|
-
|
1603
|
-
|
1604
|
-
if (process.env.NODE_ENV !== 'production') {
|
1605
|
-
const { originalTarget } = this;
|
1606
|
-
throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
|
1607
|
-
}
|
1499
|
+
querySelectorAll(_selectors) {
|
1500
|
+
throw new TypeError('"querySelectorAll" is not supported in this environment');
|
1608
1501
|
}
|
1609
|
-
|
1610
|
-
|
1611
|
-
if (process.env.NODE_ENV !== 'production') {
|
1612
|
-
const { originalTarget } = this;
|
1613
|
-
throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
|
1614
|
-
}
|
1615
|
-
/* istanbul ignore next */
|
1616
|
-
return false;
|
1502
|
+
getAttributeNS(_namespace, _localName) {
|
1503
|
+
throw new Error('Method "getAttributeNS" not implemented.');
|
1617
1504
|
}
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1505
|
+
hasAttributeNS(_namespace, _localName) {
|
1506
|
+
throw new Error('Method "hasAttributeNS" not implemented.');
|
1507
|
+
}
|
1508
|
+
removeAttributeNS(_namespace, _localName) {
|
1509
|
+
throw new Error('Method "removeAttributeNS" not implemented.');
|
1510
|
+
}
|
1511
|
+
setAttributeNS(_namespace, _qualifiedName, _value) {
|
1512
|
+
throw new Error('Method "setAttributeNS" not implemented.');
|
1626
1513
|
}
|
1627
1514
|
}
|
1515
|
+
defineProperties(LightningElement.prototype, descriptors);
|
1628
1516
|
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
const
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1517
|
+
/*
|
1518
|
+
* Copyright (c) 2024, salesforce.com, inc.
|
1519
|
+
* All rights reserved.
|
1520
|
+
* SPDX-License-Identifier: MIT
|
1521
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1522
|
+
*/
|
1523
|
+
const escapeAttrVal = (attrValue) => attrValue.replaceAll('&', '&').replaceAll('"', '"');
|
1524
|
+
function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
|
1525
|
+
// The scopeToken is e.g. `lwc-xyz123` which is the token our parent gives us.
|
1526
|
+
// The hostScopeToken is e.g. `lwc-abc456-host` which is the token for our own component.
|
1527
|
+
// It's possible to have both, one, the other, or neither.
|
1528
|
+
const combinedScopeToken = scopeToken && hostScopeToken
|
1529
|
+
? `${scopeToken} ${hostScopeToken}`
|
1530
|
+
: scopeToken || hostScopeToken || '';
|
1531
|
+
let result = '';
|
1532
|
+
let hasClassAttribute = false;
|
1533
|
+
for (const attrName of getOwnPropertyNames$1(attrs)) {
|
1534
|
+
let attrValue = attrs[attrName];
|
1535
|
+
if (isNull(attrValue) || isUndefined$1(attrValue)) {
|
1536
|
+
attrValue = '';
|
1646
1537
|
}
|
1647
|
-
else {
|
1648
|
-
|
1538
|
+
else if (!isString(attrValue)) {
|
1539
|
+
attrValue = String(attrValue);
|
1649
1540
|
}
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1541
|
+
if (attrName === 'class') {
|
1542
|
+
if (attrValue === '') {
|
1543
|
+
// If the class attribute is empty, we don't render it.
|
1544
|
+
continue;
|
1545
|
+
}
|
1546
|
+
if (combinedScopeToken) {
|
1547
|
+
attrValue += ' ' + combinedScopeToken;
|
1548
|
+
hasClassAttribute = true;
|
1549
|
+
}
|
1659
1550
|
}
|
1660
|
-
|
1661
|
-
return ['object', { object: obj }];
|
1662
|
-
},
|
1663
|
-
hasBody: () => {
|
1664
|
-
return false;
|
1665
|
-
},
|
1666
|
-
body: () => {
|
1667
|
-
return null;
|
1668
|
-
},
|
1669
|
-
};
|
1670
|
-
// Inspired from paulmillr/es6-shim
|
1671
|
-
// https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
|
1672
|
-
/* istanbul ignore next */
|
1673
|
-
function getGlobal() {
|
1674
|
-
// the only reliable means to get the global object is `Function('return this')()`
|
1675
|
-
// However, this causes CSP violations in Chrome apps.
|
1676
|
-
if (typeof globalThis !== 'undefined') {
|
1677
|
-
return globalThis;
|
1678
|
-
}
|
1679
|
-
if (typeof self !== 'undefined') {
|
1680
|
-
return self;
|
1681
|
-
}
|
1682
|
-
if (typeof window !== 'undefined') {
|
1683
|
-
return window;
|
1684
|
-
}
|
1685
|
-
if (typeof global !== 'undefined') {
|
1686
|
-
return global;
|
1687
|
-
}
|
1688
|
-
// Gracefully degrade if not able to locate the global object
|
1689
|
-
return {};
|
1690
|
-
}
|
1691
|
-
function init() {
|
1692
|
-
/* istanbul ignore if */
|
1693
|
-
if (process.env.NODE_ENV === 'production') {
|
1694
|
-
// this method should never leak to prod
|
1695
|
-
throw new ReferenceError();
|
1696
|
-
}
|
1697
|
-
const global = getGlobal();
|
1698
|
-
// Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
|
1699
|
-
// - Go to Settings,
|
1700
|
-
// - Under console, select "Enable custom formatters"
|
1701
|
-
// For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
|
1702
|
-
const devtoolsFormatters = global.devtoolsFormatters || [];
|
1703
|
-
ArrayPush.call(devtoolsFormatters, formatter);
|
1704
|
-
global.devtoolsFormatters = devtoolsFormatters;
|
1705
|
-
}
|
1706
|
-
|
1707
|
-
/* istanbul ignore else */
|
1708
|
-
if (process.env.NODE_ENV !== 'production') {
|
1709
|
-
init();
|
1710
|
-
}
|
1711
|
-
function defaultValueIsObservable(value) {
|
1712
|
-
// intentionally checking for null
|
1713
|
-
if (value === null) {
|
1714
|
-
return false;
|
1551
|
+
result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
|
1715
1552
|
}
|
1716
|
-
//
|
1717
|
-
if (
|
1718
|
-
|
1553
|
+
// If we didn't render any `class` attribute, render one for the scope token(s)
|
1554
|
+
if (!hasClassAttribute && combinedScopeToken) {
|
1555
|
+
result += ` class="${combinedScopeToken}"`;
|
1719
1556
|
}
|
1720
|
-
|
1721
|
-
|
1557
|
+
// For the host scope token only, we encode a special attribute for hydration
|
1558
|
+
if (hostScopeToken) {
|
1559
|
+
result += ` data-lwc-host-scope-token="${hostScopeToken}"`;
|
1722
1560
|
}
|
1723
|
-
|
1724
|
-
return
|
1561
|
+
result += mutationTracker.renderMutatedAttrs(instance);
|
1562
|
+
return result;
|
1725
1563
|
}
|
1726
|
-
|
1727
|
-
|
1728
|
-
};
|
1729
|
-
const defaultValueMutated = (obj, key) => {
|
1730
|
-
/* do nothing */
|
1731
|
-
};
|
1732
|
-
function createShadowTarget(value) {
|
1733
|
-
return isArray(value) ? [] : {};
|
1564
|
+
function* renderAttrs(instance, attrs, hostScopeToken, scopeToken) {
|
1565
|
+
yield renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken);
|
1734
1566
|
}
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
|
1742
|
-
this.valueIsObservable = isFunction(valueIsObservable)
|
1743
|
-
? valueIsObservable
|
1744
|
-
: defaultValueIsObservable;
|
1745
|
-
this.tagPropertyKey = tagPropertyKey;
|
1567
|
+
function renderAttrsNoYield(emit, instance, attrs, hostScopeToken, scopeToken) {
|
1568
|
+
emit(renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken));
|
1569
|
+
}
|
1570
|
+
function* fallbackTmpl(_props, _attrs, _shadowSlottedContent, _lightSlottedContent, Cmp, _instance) {
|
1571
|
+
if (Cmp.renderMode !== 'light') {
|
1572
|
+
yield '<template shadowrootmode="open"></template>';
|
1746
1573
|
}
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
|
1752
|
-
return value;
|
1753
|
-
}
|
1754
|
-
return this.getReactiveHandler(unwrappedValue);
|
1755
|
-
}
|
1756
|
-
return unwrappedValue;
|
1574
|
+
}
|
1575
|
+
function fallbackTmplNoYield(emit, _props, _attrs, _shadowSlottedContent, _lightSlottedContent, Cmp, _instance) {
|
1576
|
+
if (Cmp.renderMode !== 'light') {
|
1577
|
+
emit('<template shadowrootmode="open"></template>');
|
1757
1578
|
}
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1579
|
+
}
|
1580
|
+
async function serverSideRenderComponent(tagName, Component, props = {}, mode = DEFAULT_SSR_MODE) {
|
1581
|
+
if (typeof tagName !== 'string') {
|
1582
|
+
throw new Error(`tagName must be a string, found: ${tagName}`);
|
1583
|
+
}
|
1584
|
+
const generateMarkup = Component[SYMBOL__GENERATE_MARKUP];
|
1585
|
+
let markup = '';
|
1586
|
+
const emit = (segment) => {
|
1587
|
+
markup += segment;
|
1588
|
+
};
|
1589
|
+
if (mode === 'asyncYield') {
|
1590
|
+
for await (const segment of generateMarkup(tagName, props, null, null, null, null, null, null)) {
|
1591
|
+
markup += segment;
|
1762
1592
|
}
|
1763
|
-
return value;
|
1764
1593
|
}
|
1765
|
-
|
1766
|
-
|
1594
|
+
else if (mode === 'async') {
|
1595
|
+
await generateMarkup(emit, tagName, props, null, null, null, null, null, null);
|
1767
1596
|
}
|
1768
|
-
|
1769
|
-
|
1770
|
-
if (isUndefined(proxy)) {
|
1771
|
-
// caching the proxy after the first time it is accessed
|
1772
|
-
const handler = new ReactiveProxyHandler(this, value);
|
1773
|
-
proxy = new Proxy(createShadowTarget(value), handler);
|
1774
|
-
registerProxy(proxy, value);
|
1775
|
-
this.reactiveObjectGraph.set(value, proxy);
|
1776
|
-
}
|
1777
|
-
return proxy;
|
1597
|
+
else if (mode === 'sync') {
|
1598
|
+
generateMarkup(emit, tagName, props, null, null, null, null, null, null);
|
1778
1599
|
}
|
1779
|
-
|
1780
|
-
|
1781
|
-
if (isUndefined(proxy)) {
|
1782
|
-
// caching the proxy after the first time it is accessed
|
1783
|
-
const handler = new ReadOnlyHandler(this, value);
|
1784
|
-
proxy = new Proxy(createShadowTarget(value), handler);
|
1785
|
-
registerProxy(proxy, value);
|
1786
|
-
this.readOnlyObjectGraph.set(value, proxy);
|
1787
|
-
}
|
1788
|
-
return proxy;
|
1600
|
+
else {
|
1601
|
+
throw new Error(`Invalid mode: ${mode}`);
|
1789
1602
|
}
|
1603
|
+
return markup;
|
1790
1604
|
}
|
1791
|
-
/** version: 2.0.0 */
|
1792
1605
|
|
1793
1606
|
/*
|
1794
1607
|
* Copyright (c) 2024, Salesforce, Inc.
|
@@ -1796,12 +1609,143 @@ class ObservableMembrane {
|
|
1796
1609
|
* SPDX-License-Identifier: MIT
|
1797
1610
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1798
1611
|
*/
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
function
|
1804
|
-
|
1612
|
+
/**
|
1613
|
+
* Given an object, render it for use as a text content node.
|
1614
|
+
* @param value
|
1615
|
+
*/
|
1616
|
+
function massageTextContent(value) {
|
1617
|
+
// Using non strict equality to align with original implementation (ex. undefined == null)
|
1618
|
+
// See: https://github.com/salesforce/lwc/blob/348130f/packages/%40lwc/engine-core/src/framework/api.ts#L548
|
1619
|
+
return value == null ? '' : String(value);
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
/*
|
1623
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
1624
|
+
* All rights reserved.
|
1625
|
+
* SPDX-License-Identifier: MIT
|
1626
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1627
|
+
*/
|
1628
|
+
/**
|
1629
|
+
* Per the HTML spec on restrictions for "raw text elements" like `<style>`:
|
1630
|
+
*
|
1631
|
+
* > The text in raw text and escapable raw text elements must not contain any occurrences of the string
|
1632
|
+
* > "</" (U+003C LESS-THAN SIGN, U+002F SOLIDUS) followed by characters that case-insensitively match the tag name of
|
1633
|
+
* > the element followed by one of:
|
1634
|
+
* > - U+0009 CHARACTER TABULATION (tab)
|
1635
|
+
* > - U+000A LINE FEED (LF)
|
1636
|
+
* > - U+000C FORM FEED (FF)
|
1637
|
+
* > - U+000D CARRIAGE RETURN (CR)
|
1638
|
+
* > - U+0020 SPACE
|
1639
|
+
* > - U+003E GREATER-THAN SIGN (>), or
|
1640
|
+
* > - U+002F SOLIDUS (/)
|
1641
|
+
* @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
|
1642
|
+
*/
|
1643
|
+
const INVALID_STYLE_CONTENT = /<\/style[\t\n\f\r >/]/i;
|
1644
|
+
/**
|
1645
|
+
* The text content inside `<style>` is a special case. It is _only_ rendered by the LWC engine itself; `<style>` tags
|
1646
|
+
* are disallowed inside of HTML templates.
|
1647
|
+
*
|
1648
|
+
* The `<style>` tag is unusual in how it's defined in HTML. Like `<script>`, it is considered a "raw text element,"
|
1649
|
+
* which means that it is parsed as raw text, but certain character sequences are disallowed, namely to avoid XSS
|
1650
|
+
* attacks like `</style><script>alert("pwned")</script>`.
|
1651
|
+
*
|
1652
|
+
* This also means that we cannot use "normal" HTML escaping inside `<style>` tags, e.g. we cannot use `<`,
|
1653
|
+
* `>`, etc., because these are treated as-is by the HTML parser.
|
1654
|
+
*
|
1655
|
+
*
|
1656
|
+
* @param contents CSS source to validate
|
1657
|
+
* @throws Throws if the contents provided are not valid.
|
1658
|
+
* @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
|
1659
|
+
* @see https://github.com/salesforce/lwc/issues/3439
|
1660
|
+
* @example
|
1661
|
+
* validateStyleTextContents('div { color: red }') // Ok
|
1662
|
+
* validateStyleTextContents('</style><script>alert("pwned")</script>') // Throws
|
1663
|
+
*/
|
1664
|
+
function validateStyleTextContents(contents) {
|
1665
|
+
if (INVALID_STYLE_CONTENT.test(contents)) {
|
1666
|
+
throw new Error('CSS contains unsafe characters and cannot be serialized inside a style element');
|
1667
|
+
}
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
/*
|
1671
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
1672
|
+
* All rights reserved.
|
1673
|
+
* SPDX-License-Identifier: MIT
|
1674
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1675
|
+
*/
|
1676
|
+
// Traverse in the same order as `flattenStylesheets` but without creating unnecessary additional arrays
|
1677
|
+
function traverseStylesheets(stylesheets, callback) {
|
1678
|
+
if (isArray$1(stylesheets)) {
|
1679
|
+
for (let i = 0; i < stylesheets.length; i++) {
|
1680
|
+
traverseStylesheets(stylesheets[i], callback);
|
1681
|
+
}
|
1682
|
+
}
|
1683
|
+
else if (stylesheets) {
|
1684
|
+
callback(stylesheets);
|
1685
|
+
}
|
1686
|
+
}
|
1687
|
+
function hasScopedStaticStylesheets(Component) {
|
1688
|
+
let scoped = false;
|
1689
|
+
traverseStylesheets(Component.stylesheets, (stylesheet) => {
|
1690
|
+
scoped ||= !!stylesheet.$scoped$;
|
1691
|
+
});
|
1692
|
+
return scoped;
|
1693
|
+
}
|
1694
|
+
function renderStylesheets(defaultStylesheets, defaultScopedStylesheets, staticStylesheets, scopeToken, Component, hasScopedTemplateStyles) {
|
1695
|
+
const hasAnyScopedStyles = hasScopedTemplateStyles || hasScopedStaticStylesheets(Component);
|
1696
|
+
const { renderMode } = Component;
|
1697
|
+
let result = '';
|
1698
|
+
const renderStylesheet = (stylesheet) => {
|
1699
|
+
const { $scoped$: scoped } = stylesheet;
|
1700
|
+
const token = scoped ? scopeToken : undefined;
|
1701
|
+
const useActualHostSelector = !scoped || renderMode !== 'light';
|
1702
|
+
const useNativeDirPseudoclass = true;
|
1703
|
+
const styleContents = stylesheet(token, useActualHostSelector, useNativeDirPseudoclass);
|
1704
|
+
validateStyleTextContents(styleContents);
|
1705
|
+
// TODO [#2869]: `<style>`s should not have scope token classes
|
1706
|
+
result += `<style${hasAnyScopedStyles ? ` class="${scopeToken}"` : ''} type="text/css">${styleContents}</style>`;
|
1707
|
+
};
|
1708
|
+
traverseStylesheets(defaultStylesheets, renderStylesheet);
|
1709
|
+
traverseStylesheets(defaultScopedStylesheets, renderStylesheet);
|
1710
|
+
traverseStylesheets(staticStylesheets, renderStylesheet);
|
1711
|
+
return result;
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
/*
|
1715
|
+
* Copyright (c) 2024, salesforce.com, inc.
|
1716
|
+
* All rights reserved.
|
1717
|
+
* SPDX-License-Identifier: MIT
|
1718
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1719
|
+
*/
|
1720
|
+
/**
|
1721
|
+
* Converts an iterable into one that emits the object used by the [`iterator` directive](
|
1722
|
+
* https://lwc.dev/guide/html_templates#iterator).
|
1723
|
+
*/
|
1724
|
+
function* toIteratorDirective(iterable) {
|
1725
|
+
if (iterable === undefined || iterable === null)
|
1726
|
+
return;
|
1727
|
+
if (!iterable[Symbol.iterator]) {
|
1728
|
+
throw new Error(
|
1729
|
+
// Mimic error message from "[i]terable node" in engine-core's api.ts
|
1730
|
+
`Invalid template iteration for value \`${iterable}\`. It must be an array-like object.`);
|
1731
|
+
}
|
1732
|
+
const iterator = iterable[Symbol.iterator]();
|
1733
|
+
let next = iterator.next();
|
1734
|
+
let index = 0;
|
1735
|
+
let { value, done: last = false } = next;
|
1736
|
+
while (last === false) {
|
1737
|
+
// using a look-back approach because we need to know if the element is the last
|
1738
|
+
next = iterator.next();
|
1739
|
+
last = next.done ?? false;
|
1740
|
+
yield {
|
1741
|
+
value,
|
1742
|
+
index,
|
1743
|
+
first: index === 0,
|
1744
|
+
last,
|
1745
|
+
};
|
1746
|
+
index += 1;
|
1747
|
+
value = next.value;
|
1748
|
+
}
|
1805
1749
|
}
|
1806
1750
|
|
1807
1751
|
/*
|
@@ -1881,7 +1825,9 @@ exports.hasScopedStaticStylesheets = hasScopedStaticStylesheets;
|
|
1881
1825
|
exports.hot = hot;
|
1882
1826
|
exports.htmlEscape = htmlEscape;
|
1883
1827
|
exports.isComponentConstructor = isComponentConstructor;
|
1828
|
+
exports.massageTextContent = massageTextContent;
|
1884
1829
|
exports.mutationTracker = mutationTracker;
|
1830
|
+
exports.normalizeClass = normalizeClass;
|
1885
1831
|
exports.parseFragment = parseFragment;
|
1886
1832
|
exports.parseSVGFragment = parseSVGFragment;
|
1887
1833
|
exports.readonly = readonly;
|
@@ -1906,5 +1852,5 @@ exports.track = track;
|
|
1906
1852
|
exports.unwrap = unwrap$1;
|
1907
1853
|
exports.validateStyleTextContents = validateStyleTextContents;
|
1908
1854
|
exports.wire = wire;
|
1909
|
-
/** version: 8.
|
1855
|
+
/** version: 8.12.1 */
|
1910
1856
|
//# sourceMappingURL=index.cjs.js.map
|