@lwc/ssr-runtime 8.6.0 → 8.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/get-read-only-proxy.d.ts +1 -0
- package/dist/index.cjs.js +816 -80
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +812 -80
- package/dist/index.js.map +1 -1
- package/dist/reflection.d.ts +7 -2
- package/dist/render.d.ts +2 -2
- package/dist/stubs.d.ts +0 -1
- package/dist/wire.d.ts +8 -0
- package/package.json +4 -2
package/dist/index.cjs.js
CHANGED
@@ -15,9 +15,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
15
15
|
function api(..._) {
|
16
16
|
throw new Error('@api cannot be used in SSR context.');
|
17
17
|
}
|
18
|
-
function createContextProvider(..._) {
|
19
|
-
throw new Error('createContextProvider cannot be used in SSR context.');
|
20
|
-
}
|
21
18
|
function createElement(..._) {
|
22
19
|
throw new Error('createElement cannot be used in SSR context.');
|
23
20
|
}
|
@@ -69,7 +66,7 @@ function swapTemplate(..._) {
|
|
69
66
|
function track(..._) {
|
70
67
|
throw new Error('@track cannot be used in SSR context.');
|
71
68
|
}
|
72
|
-
function unwrap(..._) {
|
69
|
+
function unwrap$1(..._) {
|
73
70
|
throw new Error('unwrap cannot be used in SSR context.');
|
74
71
|
}
|
75
72
|
function wire(..._) {
|
@@ -270,17 +267,17 @@ freeze,
|
|
270
267
|
/** Detached {@linkcode Object.fromEntries}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries MDN Reference}. */
|
271
268
|
fromEntries,
|
272
269
|
/** Detached {@linkcode Object.getOwnPropertyDescriptor}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor MDN Reference}. */
|
273
|
-
getOwnPropertyDescriptor,
|
270
|
+
getOwnPropertyDescriptor: getOwnPropertyDescriptor$1,
|
274
271
|
/** Detached {@linkcode Object.getOwnPropertyDescriptors}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors MDN Reference}. */
|
275
272
|
getOwnPropertyDescriptors,
|
276
273
|
/** Detached {@linkcode Object.getOwnPropertyNames}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames MDN Reference}. */
|
277
|
-
getOwnPropertyNames,
|
274
|
+
getOwnPropertyNames: getOwnPropertyNames$1,
|
278
275
|
/** Detached {@linkcode Object.getOwnPropertySymbols}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols MDN Reference}. */
|
279
|
-
getOwnPropertySymbols,
|
276
|
+
getOwnPropertySymbols: getOwnPropertySymbols$1,
|
280
277
|
/** Detached {@linkcode Object.getPrototypeOf}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf MDN Reference}. */
|
281
|
-
getPrototypeOf,
|
278
|
+
getPrototypeOf: getPrototypeOf$1,
|
282
279
|
/** Detached {@linkcode Object.hasOwnProperty}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty MDN Reference}. */
|
283
|
-
hasOwnProperty,
|
280
|
+
hasOwnProperty: hasOwnProperty$1,
|
284
281
|
/** Detached {@linkcode Object.isFrozen}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen MDN Reference}. */
|
285
282
|
isFrozen,
|
286
283
|
/** Detached {@linkcode Object.keys}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys MDN Reference}. */
|
@@ -291,16 +288,26 @@ seal,
|
|
291
288
|
setPrototypeOf, } = Object;
|
292
289
|
const {
|
293
290
|
/** Detached {@linkcode Array.isArray}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray MDN Reference}. */
|
294
|
-
isArray,
|
291
|
+
isArray: isArray$1,
|
295
292
|
/** Detached {@linkcode Array.from}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from MDN Reference}. */
|
296
293
|
from: ArrayFrom, } = Array;
|
297
294
|
// For some reason, JSDoc don't get picked up for multiple renamed destructured constants (even
|
298
295
|
// though it works fine for one, e.g. isArray), so comments for these are added to the export
|
299
296
|
// statement, rather than this declaration.
|
300
|
-
const { concat: ArrayConcat, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly!
|
297
|
+
const { concat: ArrayConcat$1, copyWithin: ArrayCopyWithin, every: ArrayEvery, fill: ArrayFill, filter: ArrayFilter, find: ArrayFind, findIndex: ArrayFindIndex, includes: ArrayIncludes, indexOf: ArrayIndexOf, join: ArrayJoin, map: ArrayMap, pop: ArrayPop, push: ArrayPush$1, reduce: ArrayReduce, reverse: ArrayReverse, shift: ArrayShift, slice: ArraySlice, some: ArraySome, sort: ArraySort, splice: ArraySplice, unshift: ArrayUnshift, forEach, // Weird anomaly!
|
301
298
|
} = Array.prototype;
|
299
|
+
/** Detached {@linkcode String.fromCharCode}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode MDN Reference}. */
|
300
|
+
const { fromCharCode: StringFromCharCode } = String;
|
302
301
|
// No JSDocs here - see comment for Array.prototype
|
303
302
|
const { charAt: StringCharAt, charCodeAt: StringCharCodeAt, replace: StringReplace, split: StringSplit, slice: StringSlice, toLowerCase: StringToLowerCase, trim: StringTrim, } = String.prototype;
|
303
|
+
/**
|
304
|
+
* Determines whether the argument is `undefined`.
|
305
|
+
* @param obj Value to test
|
306
|
+
* @returns `true` if the value is `undefined`.
|
307
|
+
*/
|
308
|
+
function isUndefined$1(obj) {
|
309
|
+
return obj === undefined;
|
310
|
+
}
|
304
311
|
/**
|
305
312
|
* Determines whether the argument is `null`.
|
306
313
|
* @param obj Value to test
|
@@ -309,19 +316,27 @@ const { charAt: StringCharAt, charCodeAt: StringCharCodeAt, replace: StringRepla
|
|
309
316
|
function isNull(obj) {
|
310
317
|
return obj === null;
|
311
318
|
}
|
312
|
-
|
319
|
+
/**
|
320
|
+
* Determines whether the argument is a string.
|
321
|
+
* @param obj Value to test
|
322
|
+
* @returns `true` if the value is a string.
|
323
|
+
*/
|
324
|
+
function isString(obj) {
|
325
|
+
return typeof obj === 'string';
|
326
|
+
}
|
327
|
+
const OtS$1 = {}.toString;
|
313
328
|
/**
|
314
329
|
* Converts the argument to a string, safely accounting for objects with "null" prototype.
|
315
330
|
* Note that `toString(null)` returns `"[object Null]"` rather than `"null"`.
|
316
331
|
* @param obj Value to convert to a string.
|
317
332
|
* @returns String representation of the value.
|
318
333
|
*/
|
319
|
-
function toString(obj) {
|
334
|
+
function toString$1(obj) {
|
320
335
|
if (obj?.toString) {
|
321
336
|
// Arrays might hold objects with "null" prototype So using
|
322
337
|
// Array.prototype.toString directly will cause an error Iterate through
|
323
338
|
// all the items and handle individually.
|
324
|
-
if (isArray(obj)) {
|
339
|
+
if (isArray$1(obj)) {
|
325
340
|
// This behavior is slightly different from Array#toString:
|
326
341
|
// 1. Array#toString calls `this.join`, rather than Array#join
|
327
342
|
// Ex: arr = []; arr.join = () => 1; arr.toString() === 1; toString(arr) === ''
|
@@ -332,13 +347,13 @@ function toString(obj) {
|
|
332
347
|
// 4. Array#toString converts recursive references to arrays to ''
|
333
348
|
// Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws
|
334
349
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
335
|
-
return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
|
350
|
+
return ArrayJoin.call(ArrayMap.call(obj, toString$1), ',');
|
336
351
|
}
|
337
352
|
return obj.toString();
|
338
353
|
}
|
339
354
|
else if (typeof obj === 'object') {
|
340
355
|
// This catches null and returns "[object Null]". Weird, but kept for backwards compatibility.
|
341
|
-
return OtS.call(obj);
|
356
|
+
return OtS$1.call(obj);
|
342
357
|
}
|
343
358
|
else {
|
344
359
|
return String(obj);
|
@@ -423,11 +438,114 @@ const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__*/ (
|
|
423
438
|
// Synthetic creation of all AOM property descriptors for Custom Elements
|
424
439
|
forEach.call(AriaPropertyNames, (propName) => {
|
425
440
|
const attrName = StringToLowerCase.call(StringReplace.call(propName, /^aria/, () => 'aria-'));
|
441
|
+
// These type assertions are because the map types are a 1:1 mapping of ariaX to aria-x.
|
442
|
+
// TypeScript knows we have one of ariaX | ariaY and one of aria-x | aria-y, and tries to
|
443
|
+
// prevent us from doing ariaX: aria-y, but we that it's safe.
|
426
444
|
AriaAttrNameToPropNameMap[attrName] = propName;
|
427
445
|
AriaPropNameToAttrNameMap[propName] = attrName;
|
428
446
|
});
|
429
447
|
return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };
|
430
448
|
})();
|
449
|
+
/**
|
450
|
+
*
|
451
|
+
* @param attrName
|
452
|
+
*/
|
453
|
+
function isAriaAttribute(attrName) {
|
454
|
+
return attrName in AriaAttrNameToPropNameMap;
|
455
|
+
}
|
456
|
+
// This list is based on https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
|
457
|
+
const GLOBAL_ATTRIBUTE = /*@__PURE__*/ new Set([
|
458
|
+
'accesskey',
|
459
|
+
'autocapitalize',
|
460
|
+
'autofocus',
|
461
|
+
'class',
|
462
|
+
'contenteditable',
|
463
|
+
'contextmenu',
|
464
|
+
'dir',
|
465
|
+
'draggable',
|
466
|
+
'enterkeyhint',
|
467
|
+
'exportparts',
|
468
|
+
'hidden',
|
469
|
+
'id',
|
470
|
+
'inputmode',
|
471
|
+
'is',
|
472
|
+
'itemid',
|
473
|
+
'itemprop',
|
474
|
+
'itemref',
|
475
|
+
'itemscope',
|
476
|
+
'itemtype',
|
477
|
+
'lang',
|
478
|
+
'nonce',
|
479
|
+
'part',
|
480
|
+
'slot',
|
481
|
+
'spellcheck',
|
482
|
+
'style',
|
483
|
+
'tabindex',
|
484
|
+
'title',
|
485
|
+
'translate',
|
486
|
+
]);
|
487
|
+
/**
|
488
|
+
*
|
489
|
+
* @param attrName
|
490
|
+
*/
|
491
|
+
function isGlobalHtmlAttribute(attrName) {
|
492
|
+
return GLOBAL_ATTRIBUTE.has(attrName);
|
493
|
+
}
|
494
|
+
// These are HTML standard prop/attribute IDL mappings, but are not predictable based on camel/kebab-case conversion
|
495
|
+
const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map([
|
496
|
+
['accessKey', 'accesskey'],
|
497
|
+
['readOnly', 'readonly'],
|
498
|
+
['tabIndex', 'tabindex'],
|
499
|
+
['bgColor', 'bgcolor'],
|
500
|
+
['colSpan', 'colspan'],
|
501
|
+
['rowSpan', 'rowspan'],
|
502
|
+
['contentEditable', 'contenteditable'],
|
503
|
+
['crossOrigin', 'crossorigin'],
|
504
|
+
['dateTime', 'datetime'],
|
505
|
+
['formAction', 'formaction'],
|
506
|
+
['isMap', 'ismap'],
|
507
|
+
['maxLength', 'maxlength'],
|
508
|
+
['minLength', 'minlength'],
|
509
|
+
['noValidate', 'novalidate'],
|
510
|
+
['useMap', 'usemap'],
|
511
|
+
['htmlFor', 'for'],
|
512
|
+
]);
|
513
|
+
/**
|
514
|
+
* Map associating previously transformed HTML property into HTML attribute.
|
515
|
+
*/
|
516
|
+
const CACHED_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map();
|
517
|
+
/**
|
518
|
+
*
|
519
|
+
* @param propName
|
520
|
+
*/
|
521
|
+
function htmlPropertyToAttribute(propName) {
|
522
|
+
const ariaAttributeName = AriaPropNameToAttrNameMap[propName];
|
523
|
+
if (!isUndefined$1(ariaAttributeName)) {
|
524
|
+
return ariaAttributeName;
|
525
|
+
}
|
526
|
+
const specialAttributeName = SPECIAL_PROPERTY_ATTRIBUTE_MAPPING.get(propName);
|
527
|
+
if (!isUndefined$1(specialAttributeName)) {
|
528
|
+
return specialAttributeName;
|
529
|
+
}
|
530
|
+
const cachedAttributeName = CACHED_PROPERTY_ATTRIBUTE_MAPPING.get(propName);
|
531
|
+
if (!isUndefined$1(cachedAttributeName)) {
|
532
|
+
return cachedAttributeName;
|
533
|
+
}
|
534
|
+
let attributeName = '';
|
535
|
+
for (let i = 0, len = propName.length; i < len; i++) {
|
536
|
+
const code = StringCharCodeAt.call(propName, i);
|
537
|
+
if (code >= 65 && // "A"
|
538
|
+
code <= 90 // "Z"
|
539
|
+
) {
|
540
|
+
attributeName += '-' + StringFromCharCode(code + 32);
|
541
|
+
}
|
542
|
+
else {
|
543
|
+
attributeName += StringFromCharCode(code);
|
544
|
+
}
|
545
|
+
}
|
546
|
+
CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
|
547
|
+
return attributeName;
|
548
|
+
}
|
431
549
|
|
432
550
|
/*
|
433
551
|
* Copyright (c) 2020, salesforce.com, inc.
|
@@ -477,7 +595,7 @@ function setHooks(hooks) {
|
|
477
595
|
function flattenStylesheets(stylesheets) {
|
478
596
|
const list = [];
|
479
597
|
for (const stylesheet of stylesheets) {
|
480
|
-
if (!isArray(stylesheet)) {
|
598
|
+
if (!isArray$1(stylesheet)) {
|
481
599
|
list.push(stylesheet);
|
482
600
|
}
|
483
601
|
else {
|
@@ -486,7 +604,7 @@ function flattenStylesheets(stylesheets) {
|
|
486
604
|
}
|
487
605
|
return list;
|
488
606
|
}
|
489
|
-
/** version: 8.
|
607
|
+
/** version: 8.8.0 */
|
490
608
|
|
491
609
|
/*
|
492
610
|
* Copyright (c) 2024, Salesforce, Inc.
|
@@ -647,21 +765,25 @@ const mutationTracker = new MutationTracker();
|
|
647
765
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
648
766
|
*/
|
649
767
|
/**
|
650
|
-
*
|
651
|
-
*
|
768
|
+
* Filters out the following types of properties that should not be set.
|
769
|
+
* - Properties that are not public.
|
770
|
+
* - Properties that are not global.
|
771
|
+
* - Properties that are global but are internally overridden.
|
652
772
|
*/
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
});
|
773
|
+
function filterProperties(props, publicFields, privateFields) {
|
774
|
+
const propsToAssign = create(null);
|
775
|
+
const publicFieldSet = new Set(publicFields);
|
776
|
+
const privateFieldSet = new Set(privateFields);
|
777
|
+
keys(props).forEach((propName) => {
|
778
|
+
const attrName = htmlPropertyToAttribute(propName);
|
779
|
+
if (publicFieldSet.has(propName) ||
|
780
|
+
((isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) &&
|
781
|
+
!privateFieldSet.has(propName))) {
|
782
|
+
propsToAssign[propName] = props[propName];
|
783
|
+
}
|
784
|
+
});
|
785
|
+
return propsToAssign;
|
786
|
+
}
|
665
787
|
/**
|
666
788
|
* Descriptor for IDL attribute reflections that merely reflect the string, e.g. `title`.
|
667
789
|
*/
|
@@ -737,21 +859,11 @@ const ariaDescriptor = (attrName) => ({
|
|
737
859
|
this.removeAttribute(attrName);
|
738
860
|
}
|
739
861
|
else {
|
740
|
-
this.setAttribute(attrName, toString(newValue));
|
862
|
+
this.setAttribute(attrName, toString$1(newValue));
|
741
863
|
}
|
742
864
|
}
|
743
865
|
},
|
744
866
|
});
|
745
|
-
function reflectAttrToProp(instance, attrName, attrValue) {
|
746
|
-
const reflectedPropName = attrsToProps[attrName];
|
747
|
-
// If it is a reflected property and it was not overridden by the instance
|
748
|
-
if (reflectedPropName && !hasOwnProperty.call(instance, reflectedPropName)) {
|
749
|
-
const currentValue = instance[reflectedPropName];
|
750
|
-
if (currentValue !== attrValue) {
|
751
|
-
instance[reflectedPropName] = attrValue;
|
752
|
-
}
|
753
|
-
}
|
754
|
-
}
|
755
867
|
const descriptors = {
|
756
868
|
accessKey: stringDescriptor('accesskey'),
|
757
869
|
dir: stringDescriptor('dir'),
|
@@ -771,7 +883,7 @@ const descriptors = {
|
|
771
883
|
const num = Number(newValue);
|
772
884
|
const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
|
773
885
|
if (normalizedValue !== currentValue) {
|
774
|
-
this.setAttribute('tabindex', toString(newValue));
|
886
|
+
this.setAttribute('tabindex', toString$1(newValue));
|
775
887
|
}
|
776
888
|
},
|
777
889
|
},
|
@@ -820,27 +932,25 @@ class LightningElement {
|
|
820
932
|
return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
|
821
933
|
}
|
822
934
|
setAttribute(attrName, attrValue) {
|
823
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
935
|
+
const normalizedName = StringToLowerCase.call(toString$1(attrName));
|
824
936
|
const normalizedValue = String(attrValue);
|
825
937
|
__classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
|
826
|
-
reflectAttrToProp(this, normalizedName, normalizedValue);
|
827
938
|
mutationTracker.add(this, normalizedName);
|
828
939
|
}
|
829
940
|
getAttribute(attrName) {
|
830
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
831
|
-
if (hasOwnProperty.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
|
941
|
+
const normalizedName = StringToLowerCase.call(toString$1(attrName));
|
942
|
+
if (hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
|
832
943
|
return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
833
944
|
}
|
834
945
|
return null;
|
835
946
|
}
|
836
947
|
hasAttribute(attrName) {
|
837
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
838
|
-
return hasOwnProperty.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
|
948
|
+
const normalizedName = StringToLowerCase.call(toString$1(attrName));
|
949
|
+
return hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
|
839
950
|
}
|
840
951
|
removeAttribute(attrName) {
|
841
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
952
|
+
const normalizedName = StringToLowerCase.call(toString$1(attrName));
|
842
953
|
delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
843
|
-
reflectAttrToProp(this, normalizedName, null);
|
844
954
|
// Track mutations for removal of non-existing attributes
|
845
955
|
mutationTracker.add(this, normalizedName);
|
846
956
|
}
|
@@ -926,36 +1036,42 @@ defineProperties(LightningElement.prototype, descriptors);
|
|
926
1036
|
* SPDX-License-Identifier: MIT
|
927
1037
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
928
1038
|
*/
|
929
|
-
const escapeAttrVal = (
|
930
|
-
function
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
1039
|
+
const escapeAttrVal = (attrValue) => attrValue.replaceAll('&', '&').replaceAll('"', '"');
|
1040
|
+
function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
|
1041
|
+
// The scopeToken is e.g. `lwc-xyz123` which is the token our parent gives us.
|
1042
|
+
// The hostScopeToken is e.g. `lwc-abc456-host` which is the token for our own component.
|
1043
|
+
// It's possible to have both, one, the other, or neither.
|
1044
|
+
const combinedScopeToken = scopeToken && hostScopeToken
|
1045
|
+
? `${scopeToken} ${hostScopeToken}`
|
1046
|
+
: scopeToken || hostScopeToken || '';
|
1047
|
+
let result = '';
|
1048
|
+
let hasClassAttribute = false;
|
1049
|
+
for (const attrName of getOwnPropertyNames$1(attrs)) {
|
1050
|
+
let attrValue = attrs[attrName];
|
1051
|
+
if (isNull(attrValue) || isUndefined$1(attrValue)) {
|
1052
|
+
attrValue = '';
|
938
1053
|
}
|
939
|
-
else if (
|
940
|
-
|
1054
|
+
else if (!isString(attrValue)) {
|
1055
|
+
attrValue = String(attrValue);
|
941
1056
|
}
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
function renderAttrsNoYield(emit, instance, attrs) {
|
946
|
-
if (!attrs) {
|
947
|
-
return;
|
948
|
-
}
|
949
|
-
for (const attrName of Object.getOwnPropertyNames(attrs)) {
|
950
|
-
const attrVal = attrs[attrName];
|
951
|
-
if (typeof attrVal === 'string') {
|
952
|
-
emit(attrVal === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrVal)}"`);
|
953
|
-
}
|
954
|
-
else if (attrVal === null) {
|
955
|
-
emit('');
|
1057
|
+
if (combinedScopeToken && attrName === 'class') {
|
1058
|
+
attrValue += ' ' + combinedScopeToken;
|
1059
|
+
hasClassAttribute = true;
|
956
1060
|
}
|
1061
|
+
result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
|
1062
|
+
}
|
1063
|
+
// If we didn't render any `class` attribute, render one for the scope token(s)
|
1064
|
+
if (!hasClassAttribute && combinedScopeToken) {
|
1065
|
+
result += ` class="${combinedScopeToken}"`;
|
957
1066
|
}
|
958
|
-
|
1067
|
+
result += mutationTracker.renderMutatedAttrs(instance);
|
1068
|
+
return result;
|
1069
|
+
}
|
1070
|
+
function* renderAttrs(instance, attrs, hostScopeToken, scopeToken) {
|
1071
|
+
yield renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken);
|
1072
|
+
}
|
1073
|
+
function renderAttrsNoYield(emit, instance, attrs, hostScopeToken, scopeToken) {
|
1074
|
+
emit(renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken));
|
959
1075
|
}
|
960
1076
|
function* fallbackTmpl(_props, _attrs, _slotted, Cmp, _instance) {
|
961
1077
|
if (Cmp.renderMode !== 'light') {
|
@@ -1109,17 +1225,637 @@ function* toIteratorDirective(iterable) {
|
|
1109
1225
|
}
|
1110
1226
|
}
|
1111
1227
|
|
1228
|
+
/**
|
1229
|
+
* Copyright (C) 2017 salesforce.com, inc.
|
1230
|
+
*/
|
1231
|
+
const { isArray } = Array;
|
1232
|
+
const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
|
1233
|
+
const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
|
1234
|
+
const OtS = {}.toString;
|
1235
|
+
function toString(obj) {
|
1236
|
+
if (obj && obj.toString) {
|
1237
|
+
return obj.toString();
|
1238
|
+
}
|
1239
|
+
else if (typeof obj === 'object') {
|
1240
|
+
return OtS.call(obj);
|
1241
|
+
}
|
1242
|
+
else {
|
1243
|
+
return obj + '';
|
1244
|
+
}
|
1245
|
+
}
|
1246
|
+
function isUndefined(obj) {
|
1247
|
+
return obj === undefined;
|
1248
|
+
}
|
1249
|
+
function isFunction(obj) {
|
1250
|
+
return typeof obj === 'function';
|
1251
|
+
}
|
1252
|
+
const proxyToValueMap = new WeakMap();
|
1253
|
+
function registerProxy(proxy, value) {
|
1254
|
+
proxyToValueMap.set(proxy, value);
|
1255
|
+
}
|
1256
|
+
const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
|
1257
|
+
|
1258
|
+
class BaseProxyHandler {
|
1259
|
+
constructor(membrane, value) {
|
1260
|
+
this.originalTarget = value;
|
1261
|
+
this.membrane = membrane;
|
1262
|
+
}
|
1263
|
+
// Shared utility methods
|
1264
|
+
wrapDescriptor(descriptor) {
|
1265
|
+
if (hasOwnProperty.call(descriptor, 'value')) {
|
1266
|
+
descriptor.value = this.wrapValue(descriptor.value);
|
1267
|
+
}
|
1268
|
+
else {
|
1269
|
+
const { set: originalSet, get: originalGet } = descriptor;
|
1270
|
+
if (!isUndefined(originalGet)) {
|
1271
|
+
descriptor.get = this.wrapGetter(originalGet);
|
1272
|
+
}
|
1273
|
+
if (!isUndefined(originalSet)) {
|
1274
|
+
descriptor.set = this.wrapSetter(originalSet);
|
1275
|
+
}
|
1276
|
+
}
|
1277
|
+
return descriptor;
|
1278
|
+
}
|
1279
|
+
copyDescriptorIntoShadowTarget(shadowTarget, key) {
|
1280
|
+
const { originalTarget } = this;
|
1281
|
+
// Note: a property might get defined multiple times in the shadowTarget
|
1282
|
+
// but it will always be compatible with the previous descriptor
|
1283
|
+
// to preserve the object invariants, which makes these lines safe.
|
1284
|
+
const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
|
1285
|
+
// TODO: it should be impossible for the originalDescriptor to ever be undefined, this `if` can be removed
|
1286
|
+
/* istanbul ignore else */
|
1287
|
+
if (!isUndefined(originalDescriptor)) {
|
1288
|
+
const wrappedDesc = this.wrapDescriptor(originalDescriptor);
|
1289
|
+
ObjectDefineProperty(shadowTarget, key, wrappedDesc);
|
1290
|
+
}
|
1291
|
+
}
|
1292
|
+
lockShadowTarget(shadowTarget) {
|
1293
|
+
const { originalTarget } = this;
|
1294
|
+
const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
|
1295
|
+
targetKeys.forEach((key) => {
|
1296
|
+
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1297
|
+
});
|
1298
|
+
const { membrane: { tagPropertyKey }, } = this;
|
1299
|
+
if (!isUndefined(tagPropertyKey) && !hasOwnProperty.call(shadowTarget, tagPropertyKey)) {
|
1300
|
+
ObjectDefineProperty(shadowTarget, tagPropertyKey, ObjectCreate(null));
|
1301
|
+
}
|
1302
|
+
preventExtensions(shadowTarget);
|
1303
|
+
}
|
1304
|
+
// Shared Traps
|
1305
|
+
// TODO: apply() is never called
|
1306
|
+
/* istanbul ignore next */
|
1307
|
+
apply(shadowTarget, thisArg, argArray) {
|
1308
|
+
/* No op */
|
1309
|
+
}
|
1310
|
+
// TODO: construct() is never called
|
1311
|
+
/* istanbul ignore next */
|
1312
|
+
construct(shadowTarget, argArray, newTarget) {
|
1313
|
+
/* No op */
|
1314
|
+
}
|
1315
|
+
get(shadowTarget, key) {
|
1316
|
+
const { originalTarget, membrane: { valueObserved }, } = this;
|
1317
|
+
const value = originalTarget[key];
|
1318
|
+
valueObserved(originalTarget, key);
|
1319
|
+
return this.wrapValue(value);
|
1320
|
+
}
|
1321
|
+
has(shadowTarget, key) {
|
1322
|
+
const { originalTarget, membrane: { tagPropertyKey, valueObserved }, } = this;
|
1323
|
+
valueObserved(originalTarget, key);
|
1324
|
+
// since key is never going to be undefined, and tagPropertyKey might be undefined
|
1325
|
+
// we can simply compare them as the second part of the condition.
|
1326
|
+
return key in originalTarget || key === tagPropertyKey;
|
1327
|
+
}
|
1328
|
+
ownKeys(shadowTarget) {
|
1329
|
+
const { originalTarget, membrane: { tagPropertyKey }, } = this;
|
1330
|
+
// if the membrane tag key exists and it is not in the original target, we add it to the keys.
|
1331
|
+
const keys = isUndefined(tagPropertyKey) || hasOwnProperty.call(originalTarget, tagPropertyKey)
|
1332
|
+
? []
|
1333
|
+
: [tagPropertyKey];
|
1334
|
+
// small perf optimization using push instead of concat to avoid creating an extra array
|
1335
|
+
ArrayPush.apply(keys, getOwnPropertyNames(originalTarget));
|
1336
|
+
ArrayPush.apply(keys, getOwnPropertySymbols(originalTarget));
|
1337
|
+
return keys;
|
1338
|
+
}
|
1339
|
+
isExtensible(shadowTarget) {
|
1340
|
+
const { originalTarget } = this;
|
1341
|
+
// optimization to avoid attempting to lock down the shadowTarget multiple times
|
1342
|
+
if (!isExtensible(shadowTarget)) {
|
1343
|
+
return false; // was already locked down
|
1344
|
+
}
|
1345
|
+
if (!isExtensible(originalTarget)) {
|
1346
|
+
this.lockShadowTarget(shadowTarget);
|
1347
|
+
return false;
|
1348
|
+
}
|
1349
|
+
return true;
|
1350
|
+
}
|
1351
|
+
getPrototypeOf(shadowTarget) {
|
1352
|
+
const { originalTarget } = this;
|
1353
|
+
return getPrototypeOf(originalTarget);
|
1354
|
+
}
|
1355
|
+
getOwnPropertyDescriptor(shadowTarget, key) {
|
1356
|
+
const { originalTarget, membrane: { valueObserved, tagPropertyKey }, } = this;
|
1357
|
+
// keys looked up via getOwnPropertyDescriptor need to be reactive
|
1358
|
+
valueObserved(originalTarget, key);
|
1359
|
+
let desc = getOwnPropertyDescriptor(originalTarget, key);
|
1360
|
+
if (isUndefined(desc)) {
|
1361
|
+
if (key !== tagPropertyKey) {
|
1362
|
+
return undefined;
|
1363
|
+
}
|
1364
|
+
// if the key is the membrane tag key, and is not in the original target,
|
1365
|
+
// we produce a synthetic descriptor and install it on the shadow target
|
1366
|
+
desc = { value: undefined, writable: false, configurable: false, enumerable: false };
|
1367
|
+
ObjectDefineProperty(shadowTarget, tagPropertyKey, desc);
|
1368
|
+
return desc;
|
1369
|
+
}
|
1370
|
+
if (desc.configurable === false) {
|
1371
|
+
// updating the descriptor to non-configurable on the shadow
|
1372
|
+
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1373
|
+
}
|
1374
|
+
// Note: by accessing the descriptor, the key is marked as observed
|
1375
|
+
// but access to the value, setter or getter (if available) cannot observe
|
1376
|
+
// mutations, just like regular methods, in which case we just do nothing.
|
1377
|
+
return this.wrapDescriptor(desc);
|
1378
|
+
}
|
1379
|
+
}
|
1380
|
+
|
1381
|
+
const getterMap$1 = new WeakMap();
|
1382
|
+
const setterMap$1 = new WeakMap();
|
1383
|
+
const reverseGetterMap = new WeakMap();
|
1384
|
+
const reverseSetterMap = new WeakMap();
|
1385
|
+
class ReactiveProxyHandler extends BaseProxyHandler {
|
1386
|
+
wrapValue(value) {
|
1387
|
+
return this.membrane.getProxy(value);
|
1388
|
+
}
|
1389
|
+
wrapGetter(originalGet) {
|
1390
|
+
const wrappedGetter = getterMap$1.get(originalGet);
|
1391
|
+
if (!isUndefined(wrappedGetter)) {
|
1392
|
+
return wrappedGetter;
|
1393
|
+
}
|
1394
|
+
const handler = this;
|
1395
|
+
const get = function () {
|
1396
|
+
// invoking the original getter with the original target
|
1397
|
+
return handler.wrapValue(originalGet.call(unwrap(this)));
|
1398
|
+
};
|
1399
|
+
getterMap$1.set(originalGet, get);
|
1400
|
+
reverseGetterMap.set(get, originalGet);
|
1401
|
+
return get;
|
1402
|
+
}
|
1403
|
+
wrapSetter(originalSet) {
|
1404
|
+
const wrappedSetter = setterMap$1.get(originalSet);
|
1405
|
+
if (!isUndefined(wrappedSetter)) {
|
1406
|
+
return wrappedSetter;
|
1407
|
+
}
|
1408
|
+
const set = function (v) {
|
1409
|
+
// invoking the original setter with the original target
|
1410
|
+
originalSet.call(unwrap(this), unwrap(v));
|
1411
|
+
};
|
1412
|
+
setterMap$1.set(originalSet, set);
|
1413
|
+
reverseSetterMap.set(set, originalSet);
|
1414
|
+
return set;
|
1415
|
+
}
|
1416
|
+
unwrapDescriptor(descriptor) {
|
1417
|
+
if (hasOwnProperty.call(descriptor, 'value')) {
|
1418
|
+
// dealing with a data descriptor
|
1419
|
+
descriptor.value = unwrap(descriptor.value);
|
1420
|
+
}
|
1421
|
+
else {
|
1422
|
+
const { set, get } = descriptor;
|
1423
|
+
if (!isUndefined(get)) {
|
1424
|
+
descriptor.get = this.unwrapGetter(get);
|
1425
|
+
}
|
1426
|
+
if (!isUndefined(set)) {
|
1427
|
+
descriptor.set = this.unwrapSetter(set);
|
1428
|
+
}
|
1429
|
+
}
|
1430
|
+
return descriptor;
|
1431
|
+
}
|
1432
|
+
unwrapGetter(redGet) {
|
1433
|
+
const reverseGetter = reverseGetterMap.get(redGet);
|
1434
|
+
if (!isUndefined(reverseGetter)) {
|
1435
|
+
return reverseGetter;
|
1436
|
+
}
|
1437
|
+
const handler = this;
|
1438
|
+
const get = function () {
|
1439
|
+
// invoking the red getter with the proxy of this
|
1440
|
+
return unwrap(redGet.call(handler.wrapValue(this)));
|
1441
|
+
};
|
1442
|
+
getterMap$1.set(get, redGet);
|
1443
|
+
reverseGetterMap.set(redGet, get);
|
1444
|
+
return get;
|
1445
|
+
}
|
1446
|
+
unwrapSetter(redSet) {
|
1447
|
+
const reverseSetter = reverseSetterMap.get(redSet);
|
1448
|
+
if (!isUndefined(reverseSetter)) {
|
1449
|
+
return reverseSetter;
|
1450
|
+
}
|
1451
|
+
const handler = this;
|
1452
|
+
const set = function (v) {
|
1453
|
+
// invoking the red setter with the proxy of this
|
1454
|
+
redSet.call(handler.wrapValue(this), handler.wrapValue(v));
|
1455
|
+
};
|
1456
|
+
setterMap$1.set(set, redSet);
|
1457
|
+
reverseSetterMap.set(redSet, set);
|
1458
|
+
return set;
|
1459
|
+
}
|
1460
|
+
set(shadowTarget, key, value) {
|
1461
|
+
const { originalTarget, membrane: { valueMutated }, } = this;
|
1462
|
+
const oldValue = originalTarget[key];
|
1463
|
+
if (oldValue !== value) {
|
1464
|
+
originalTarget[key] = value;
|
1465
|
+
valueMutated(originalTarget, key);
|
1466
|
+
}
|
1467
|
+
else if (key === 'length' && isArray(originalTarget)) {
|
1468
|
+
// fix for issue #236: push will add the new index, and by the time length
|
1469
|
+
// is updated, the internal length is already equal to the new length value
|
1470
|
+
// therefore, the oldValue is equal to the value. This is the forking logic
|
1471
|
+
// to support this use case.
|
1472
|
+
valueMutated(originalTarget, key);
|
1473
|
+
}
|
1474
|
+
return true;
|
1475
|
+
}
|
1476
|
+
deleteProperty(shadowTarget, key) {
|
1477
|
+
const { originalTarget, membrane: { valueMutated }, } = this;
|
1478
|
+
delete originalTarget[key];
|
1479
|
+
valueMutated(originalTarget, key);
|
1480
|
+
return true;
|
1481
|
+
}
|
1482
|
+
setPrototypeOf(shadowTarget, prototype) {
|
1483
|
+
/* istanbul ignore else */
|
1484
|
+
if (process.env.NODE_ENV !== 'production') {
|
1485
|
+
throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
|
1486
|
+
}
|
1487
|
+
}
|
1488
|
+
preventExtensions(shadowTarget) {
|
1489
|
+
if (isExtensible(shadowTarget)) {
|
1490
|
+
const { originalTarget } = this;
|
1491
|
+
preventExtensions(originalTarget);
|
1492
|
+
// if the originalTarget is a proxy itself, it might reject
|
1493
|
+
// the preventExtension call, in which case we should not attempt to lock down
|
1494
|
+
// the shadow target.
|
1495
|
+
// TODO: It should not actually be possible to reach this `if` statement.
|
1496
|
+
// If a proxy rejects extensions, then calling preventExtensions will throw an error:
|
1497
|
+
// https://codepen.io/nolanlawson-the-selector/pen/QWMOjbY
|
1498
|
+
/* istanbul ignore if */
|
1499
|
+
if (isExtensible(originalTarget)) {
|
1500
|
+
return false;
|
1501
|
+
}
|
1502
|
+
this.lockShadowTarget(shadowTarget);
|
1503
|
+
}
|
1504
|
+
return true;
|
1505
|
+
}
|
1506
|
+
defineProperty(shadowTarget, key, descriptor) {
|
1507
|
+
const { originalTarget, membrane: { valueMutated, tagPropertyKey }, } = this;
|
1508
|
+
if (key === tagPropertyKey && !hasOwnProperty.call(originalTarget, key)) {
|
1509
|
+
// To avoid leaking the membrane tag property into the original target, we must
|
1510
|
+
// be sure that the original target doesn't have yet.
|
1511
|
+
// NOTE: we do not return false here because Object.freeze and equivalent operations
|
1512
|
+
// will attempt to set the descriptor to the same value, and expect no to throw. This
|
1513
|
+
// is an small compromise for the sake of not having to diff the descriptors.
|
1514
|
+
return true;
|
1515
|
+
}
|
1516
|
+
ObjectDefineProperty(originalTarget, key, this.unwrapDescriptor(descriptor));
|
1517
|
+
// intentionally testing if false since it could be undefined as well
|
1518
|
+
if (descriptor.configurable === false) {
|
1519
|
+
this.copyDescriptorIntoShadowTarget(shadowTarget, key);
|
1520
|
+
}
|
1521
|
+
valueMutated(originalTarget, key);
|
1522
|
+
return true;
|
1523
|
+
}
|
1524
|
+
}
|
1525
|
+
|
1526
|
+
const getterMap = new WeakMap();
|
1527
|
+
const setterMap = new WeakMap();
|
1528
|
+
class ReadOnlyHandler extends BaseProxyHandler {
|
1529
|
+
wrapValue(value) {
|
1530
|
+
return this.membrane.getReadOnlyProxy(value);
|
1531
|
+
}
|
1532
|
+
wrapGetter(originalGet) {
|
1533
|
+
const wrappedGetter = getterMap.get(originalGet);
|
1534
|
+
if (!isUndefined(wrappedGetter)) {
|
1535
|
+
return wrappedGetter;
|
1536
|
+
}
|
1537
|
+
const handler = this;
|
1538
|
+
const get = function () {
|
1539
|
+
// invoking the original getter with the original target
|
1540
|
+
return handler.wrapValue(originalGet.call(unwrap(this)));
|
1541
|
+
};
|
1542
|
+
getterMap.set(originalGet, get);
|
1543
|
+
return get;
|
1544
|
+
}
|
1545
|
+
wrapSetter(originalSet) {
|
1546
|
+
const wrappedSetter = setterMap.get(originalSet);
|
1547
|
+
if (!isUndefined(wrappedSetter)) {
|
1548
|
+
return wrappedSetter;
|
1549
|
+
}
|
1550
|
+
const handler = this;
|
1551
|
+
const set = function (v) {
|
1552
|
+
/* istanbul ignore else */
|
1553
|
+
if (process.env.NODE_ENV !== 'production') {
|
1554
|
+
const { originalTarget } = handler;
|
1555
|
+
throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
|
1556
|
+
}
|
1557
|
+
};
|
1558
|
+
setterMap.set(originalSet, set);
|
1559
|
+
return set;
|
1560
|
+
}
|
1561
|
+
set(shadowTarget, key, value) {
|
1562
|
+
/* istanbul ignore else */
|
1563
|
+
if (process.env.NODE_ENV !== 'production') {
|
1564
|
+
const { originalTarget } = this;
|
1565
|
+
const msg = isArray(originalTarget)
|
1566
|
+
? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
|
1567
|
+
: `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
|
1568
|
+
throw new Error(msg);
|
1569
|
+
}
|
1570
|
+
/* istanbul ignore next */
|
1571
|
+
return false;
|
1572
|
+
}
|
1573
|
+
deleteProperty(shadowTarget, key) {
|
1574
|
+
/* istanbul ignore else */
|
1575
|
+
if (process.env.NODE_ENV !== 'production') {
|
1576
|
+
const { originalTarget } = this;
|
1577
|
+
throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
|
1578
|
+
}
|
1579
|
+
/* istanbul ignore next */
|
1580
|
+
return false;
|
1581
|
+
}
|
1582
|
+
setPrototypeOf(shadowTarget, prototype) {
|
1583
|
+
/* istanbul ignore else */
|
1584
|
+
if (process.env.NODE_ENV !== 'production') {
|
1585
|
+
const { originalTarget } = this;
|
1586
|
+
throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
|
1587
|
+
}
|
1588
|
+
}
|
1589
|
+
preventExtensions(shadowTarget) {
|
1590
|
+
/* istanbul ignore else */
|
1591
|
+
if (process.env.NODE_ENV !== 'production') {
|
1592
|
+
const { originalTarget } = this;
|
1593
|
+
throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
|
1594
|
+
}
|
1595
|
+
/* istanbul ignore next */
|
1596
|
+
return false;
|
1597
|
+
}
|
1598
|
+
defineProperty(shadowTarget, key, descriptor) {
|
1599
|
+
/* istanbul ignore else */
|
1600
|
+
if (process.env.NODE_ENV !== 'production') {
|
1601
|
+
const { originalTarget } = this;
|
1602
|
+
throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
|
1603
|
+
}
|
1604
|
+
/* istanbul ignore next */
|
1605
|
+
return false;
|
1606
|
+
}
|
1607
|
+
}
|
1608
|
+
|
1609
|
+
function extract(objectOrArray) {
|
1610
|
+
if (isArray(objectOrArray)) {
|
1611
|
+
return objectOrArray.map((item) => {
|
1612
|
+
const original = unwrap(item);
|
1613
|
+
if (original !== item) {
|
1614
|
+
return extract(original);
|
1615
|
+
}
|
1616
|
+
return item;
|
1617
|
+
});
|
1618
|
+
}
|
1619
|
+
const obj = ObjectCreate(getPrototypeOf(objectOrArray));
|
1620
|
+
const names = getOwnPropertyNames(objectOrArray);
|
1621
|
+
return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
|
1622
|
+
const item = objectOrArray[key];
|
1623
|
+
const original = unwrap(item);
|
1624
|
+
if (original !== item) {
|
1625
|
+
seed[key] = extract(original);
|
1626
|
+
}
|
1627
|
+
else {
|
1628
|
+
seed[key] = item;
|
1629
|
+
}
|
1630
|
+
return seed;
|
1631
|
+
}, obj);
|
1632
|
+
}
|
1633
|
+
const formatter = {
|
1634
|
+
header: (plainOrProxy) => {
|
1635
|
+
const originalTarget = unwrap(plainOrProxy);
|
1636
|
+
// if originalTarget is falsy or not unwrappable, exit
|
1637
|
+
if (!originalTarget || originalTarget === plainOrProxy) {
|
1638
|
+
return null;
|
1639
|
+
}
|
1640
|
+
const obj = extract(plainOrProxy);
|
1641
|
+
return ['object', { object: obj }];
|
1642
|
+
},
|
1643
|
+
hasBody: () => {
|
1644
|
+
return false;
|
1645
|
+
},
|
1646
|
+
body: () => {
|
1647
|
+
return null;
|
1648
|
+
},
|
1649
|
+
};
|
1650
|
+
// Inspired from paulmillr/es6-shim
|
1651
|
+
// https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
|
1652
|
+
/* istanbul ignore next */
|
1653
|
+
function getGlobal() {
|
1654
|
+
// the only reliable means to get the global object is `Function('return this')()`
|
1655
|
+
// However, this causes CSP violations in Chrome apps.
|
1656
|
+
if (typeof globalThis !== 'undefined') {
|
1657
|
+
return globalThis;
|
1658
|
+
}
|
1659
|
+
if (typeof self !== 'undefined') {
|
1660
|
+
return self;
|
1661
|
+
}
|
1662
|
+
if (typeof window !== 'undefined') {
|
1663
|
+
return window;
|
1664
|
+
}
|
1665
|
+
if (typeof global !== 'undefined') {
|
1666
|
+
return global;
|
1667
|
+
}
|
1668
|
+
// Gracefully degrade if not able to locate the global object
|
1669
|
+
return {};
|
1670
|
+
}
|
1671
|
+
function init() {
|
1672
|
+
/* istanbul ignore if */
|
1673
|
+
if (process.env.NODE_ENV === 'production') {
|
1674
|
+
// this method should never leak to prod
|
1675
|
+
throw new ReferenceError();
|
1676
|
+
}
|
1677
|
+
const global = getGlobal();
|
1678
|
+
// Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
|
1679
|
+
// - Go to Settings,
|
1680
|
+
// - Under console, select "Enable custom formatters"
|
1681
|
+
// For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
|
1682
|
+
const devtoolsFormatters = global.devtoolsFormatters || [];
|
1683
|
+
ArrayPush.call(devtoolsFormatters, formatter);
|
1684
|
+
global.devtoolsFormatters = devtoolsFormatters;
|
1685
|
+
}
|
1686
|
+
|
1687
|
+
/* istanbul ignore else */
|
1688
|
+
if (process.env.NODE_ENV !== 'production') {
|
1689
|
+
init();
|
1690
|
+
}
|
1691
|
+
function defaultValueIsObservable(value) {
|
1692
|
+
// intentionally checking for null
|
1693
|
+
if (value === null) {
|
1694
|
+
return false;
|
1695
|
+
}
|
1696
|
+
// treat all non-object types, including undefined, as non-observable values
|
1697
|
+
if (typeof value !== 'object') {
|
1698
|
+
return false;
|
1699
|
+
}
|
1700
|
+
if (isArray(value)) {
|
1701
|
+
return true;
|
1702
|
+
}
|
1703
|
+
const proto = getPrototypeOf(value);
|
1704
|
+
return proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null;
|
1705
|
+
}
|
1706
|
+
const defaultValueObserved = (obj, key) => {
|
1707
|
+
/* do nothing */
|
1708
|
+
};
|
1709
|
+
const defaultValueMutated = (obj, key) => {
|
1710
|
+
/* do nothing */
|
1711
|
+
};
|
1712
|
+
function createShadowTarget(value) {
|
1713
|
+
return isArray(value) ? [] : {};
|
1714
|
+
}
|
1715
|
+
class ObservableMembrane {
|
1716
|
+
constructor(options = {}) {
|
1717
|
+
this.readOnlyObjectGraph = new WeakMap();
|
1718
|
+
this.reactiveObjectGraph = new WeakMap();
|
1719
|
+
const { valueMutated, valueObserved, valueIsObservable, tagPropertyKey } = options;
|
1720
|
+
this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
|
1721
|
+
this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
|
1722
|
+
this.valueIsObservable = isFunction(valueIsObservable)
|
1723
|
+
? valueIsObservable
|
1724
|
+
: defaultValueIsObservable;
|
1725
|
+
this.tagPropertyKey = tagPropertyKey;
|
1726
|
+
}
|
1727
|
+
getProxy(value) {
|
1728
|
+
const unwrappedValue = unwrap(value);
|
1729
|
+
if (this.valueIsObservable(unwrappedValue)) {
|
1730
|
+
// When trying to extract the writable version of a readonly we return the readonly.
|
1731
|
+
if (this.readOnlyObjectGraph.get(unwrappedValue) === value) {
|
1732
|
+
return value;
|
1733
|
+
}
|
1734
|
+
return this.getReactiveHandler(unwrappedValue);
|
1735
|
+
}
|
1736
|
+
return unwrappedValue;
|
1737
|
+
}
|
1738
|
+
getReadOnlyProxy(value) {
|
1739
|
+
value = unwrap(value);
|
1740
|
+
if (this.valueIsObservable(value)) {
|
1741
|
+
return this.getReadOnlyHandler(value);
|
1742
|
+
}
|
1743
|
+
return value;
|
1744
|
+
}
|
1745
|
+
unwrapProxy(p) {
|
1746
|
+
return unwrap(p);
|
1747
|
+
}
|
1748
|
+
getReactiveHandler(value) {
|
1749
|
+
let proxy = this.reactiveObjectGraph.get(value);
|
1750
|
+
if (isUndefined(proxy)) {
|
1751
|
+
// caching the proxy after the first time it is accessed
|
1752
|
+
const handler = new ReactiveProxyHandler(this, value);
|
1753
|
+
proxy = new Proxy(createShadowTarget(value), handler);
|
1754
|
+
registerProxy(proxy, value);
|
1755
|
+
this.reactiveObjectGraph.set(value, proxy);
|
1756
|
+
}
|
1757
|
+
return proxy;
|
1758
|
+
}
|
1759
|
+
getReadOnlyHandler(value) {
|
1760
|
+
let proxy = this.readOnlyObjectGraph.get(value);
|
1761
|
+
if (isUndefined(proxy)) {
|
1762
|
+
// caching the proxy after the first time it is accessed
|
1763
|
+
const handler = new ReadOnlyHandler(this, value);
|
1764
|
+
proxy = new Proxy(createShadowTarget(value), handler);
|
1765
|
+
registerProxy(proxy, value);
|
1766
|
+
this.readOnlyObjectGraph.set(value, proxy);
|
1767
|
+
}
|
1768
|
+
return proxy;
|
1769
|
+
}
|
1770
|
+
}
|
1771
|
+
/** version: 2.0.0 */
|
1772
|
+
|
1773
|
+
/*
|
1774
|
+
* Copyright (c) 2024, Salesforce, Inc.
|
1775
|
+
* All rights reserved.
|
1776
|
+
* SPDX-License-Identifier: MIT
|
1777
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1778
|
+
*/
|
1779
|
+
const reactiveMembrane = new ObservableMembrane();
|
1780
|
+
// Modeled after `getReadOnlyProxy` in `membrane.ts` in `engine-core`
|
1781
|
+
// Return a proxy over the given object so that access is immutable
|
1782
|
+
// https://github.com/salesforce/lwc/blob/e9db491/packages/%40lwc/engine-core/src/framework/membrane.ts#L29-L33
|
1783
|
+
function getReadOnlyProxy(value) {
|
1784
|
+
return reactiveMembrane.getReadOnlyProxy(value);
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
/*
|
1788
|
+
* Copyright (c) 2024, salesforce.com, inc.
|
1789
|
+
* All rights reserved.
|
1790
|
+
* SPDX-License-Identifier: MIT
|
1791
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1792
|
+
*/
|
1793
|
+
const contextfulRelationships = new WeakMap();
|
1794
|
+
function establishContextfulRelationship(parentLe, childLe) {
|
1795
|
+
contextfulRelationships.set(childLe, parentLe);
|
1796
|
+
}
|
1797
|
+
function getContextfulStack(le) {
|
1798
|
+
const contextfulParent = contextfulRelationships.get(le);
|
1799
|
+
if (!contextfulParent) {
|
1800
|
+
return [];
|
1801
|
+
}
|
1802
|
+
return [contextfulParent, ...getContextfulStack(contextfulParent)];
|
1803
|
+
}
|
1804
|
+
const contextProviders = new WeakMap();
|
1805
|
+
function registerContextProvider(adapter, attachedLe, consumerCallback) {
|
1806
|
+
let elementMap = contextProviders.get(adapter);
|
1807
|
+
if (!elementMap) {
|
1808
|
+
elementMap = new WeakMap();
|
1809
|
+
contextProviders.set(adapter, elementMap);
|
1810
|
+
}
|
1811
|
+
elementMap.set(attachedLe, consumerCallback);
|
1812
|
+
}
|
1813
|
+
function connectContext(adapter, contextConsumer, onNewValue) {
|
1814
|
+
const elementMap = contextProviders.get(adapter);
|
1815
|
+
if (!elementMap) {
|
1816
|
+
return;
|
1817
|
+
}
|
1818
|
+
const contextfulStack = getContextfulStack(contextConsumer);
|
1819
|
+
for (const ancestor of contextfulStack) {
|
1820
|
+
const onConsumerConnected = elementMap.get(ancestor);
|
1821
|
+
if (onConsumerConnected) {
|
1822
|
+
onConsumerConnected({
|
1823
|
+
provide(newContextValue) {
|
1824
|
+
onNewValue(newContextValue);
|
1825
|
+
},
|
1826
|
+
});
|
1827
|
+
return;
|
1828
|
+
}
|
1829
|
+
}
|
1830
|
+
}
|
1831
|
+
function createContextProvider(adapter) {
|
1832
|
+
return (le, options) => {
|
1833
|
+
if (!(le instanceof LightningElement)) {
|
1834
|
+
throw new Error('Unable to register context provider on provided `elm`.');
|
1835
|
+
}
|
1836
|
+
if (!le.isConnected || !options?.consumerConnectedCallback) {
|
1837
|
+
return;
|
1838
|
+
}
|
1839
|
+
const { consumerConnectedCallback } = options;
|
1840
|
+
registerContextProvider(adapter, le, (consumer) => consumerConnectedCallback(consumer));
|
1841
|
+
};
|
1842
|
+
}
|
1843
|
+
|
1112
1844
|
exports.ClassList = ClassList;
|
1113
1845
|
exports.LightningElement = LightningElement;
|
1114
1846
|
exports.SYMBOL__GENERATE_MARKUP = SYMBOL__GENERATE_MARKUP;
|
1115
1847
|
exports.SYMBOL__SET_INTERNALS = SYMBOL__SET_INTERNALS;
|
1116
1848
|
exports.api = api;
|
1849
|
+
exports.connectContext = connectContext;
|
1117
1850
|
exports.createContextProvider = createContextProvider;
|
1118
1851
|
exports.createElement = createElement;
|
1852
|
+
exports.establishContextfulRelationship = establishContextfulRelationship;
|
1119
1853
|
exports.fallbackTmpl = fallbackTmpl;
|
1120
1854
|
exports.fallbackTmplNoYield = fallbackTmplNoYield;
|
1855
|
+
exports.filterProperties = filterProperties;
|
1121
1856
|
exports.freezeTemplate = freezeTemplate;
|
1122
1857
|
exports.getComponentDef = getComponentDef;
|
1858
|
+
exports.getReadOnlyProxy = getReadOnlyProxy;
|
1123
1859
|
exports.hasScopedStaticStylesheets = hasScopedStaticStylesheets;
|
1124
1860
|
exports.hot = hot;
|
1125
1861
|
exports.htmlEscape = htmlEscape;
|
@@ -1146,8 +1882,8 @@ exports.swapStyle = swapStyle;
|
|
1146
1882
|
exports.swapTemplate = swapTemplate;
|
1147
1883
|
exports.toIteratorDirective = toIteratorDirective;
|
1148
1884
|
exports.track = track;
|
1149
|
-
exports.unwrap = unwrap;
|
1885
|
+
exports.unwrap = unwrap$1;
|
1150
1886
|
exports.validateStyleTextContents = validateStyleTextContents;
|
1151
1887
|
exports.wire = wire;
|
1152
|
-
/** version: 8.
|
1888
|
+
/** version: 8.8.0 */
|
1153
1889
|
//# sourceMappingURL=index.cjs.js.map
|