@lwc/ssr-runtime 8.7.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 +673 -85
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +670 -84
- package/dist/index.js.map +1 -1
- 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/clone-and-deep-freeze.d.ts +0 -1
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,13 +288,13 @@ 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;
|
302
299
|
/** Detached {@linkcode String.fromCharCode}; see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode MDN Reference}. */
|
303
300
|
const { fromCharCode: StringFromCharCode } = String;
|
@@ -308,7 +305,7 @@ const { charAt: StringCharAt, charCodeAt: StringCharCodeAt, replace: StringRepla
|
|
308
305
|
* @param obj Value to test
|
309
306
|
* @returns `true` if the value is `undefined`.
|
310
307
|
*/
|
311
|
-
function isUndefined(obj) {
|
308
|
+
function isUndefined$1(obj) {
|
312
309
|
return obj === undefined;
|
313
310
|
}
|
314
311
|
/**
|
@@ -320,26 +317,26 @@ function isNull(obj) {
|
|
320
317
|
return obj === null;
|
321
318
|
}
|
322
319
|
/**
|
323
|
-
* Determines whether the argument is
|
320
|
+
* Determines whether the argument is a string.
|
324
321
|
* @param obj Value to test
|
325
|
-
* @returns `true` if the value is
|
322
|
+
* @returns `true` if the value is a string.
|
326
323
|
*/
|
327
|
-
function
|
328
|
-
return typeof obj === '
|
324
|
+
function isString(obj) {
|
325
|
+
return typeof obj === 'string';
|
329
326
|
}
|
330
|
-
const OtS = {}.toString;
|
327
|
+
const OtS$1 = {}.toString;
|
331
328
|
/**
|
332
329
|
* Converts the argument to a string, safely accounting for objects with "null" prototype.
|
333
330
|
* Note that `toString(null)` returns `"[object Null]"` rather than `"null"`.
|
334
331
|
* @param obj Value to convert to a string.
|
335
332
|
* @returns String representation of the value.
|
336
333
|
*/
|
337
|
-
function toString(obj) {
|
334
|
+
function toString$1(obj) {
|
338
335
|
if (obj?.toString) {
|
339
336
|
// Arrays might hold objects with "null" prototype So using
|
340
337
|
// Array.prototype.toString directly will cause an error Iterate through
|
341
338
|
// all the items and handle individually.
|
342
|
-
if (isArray(obj)) {
|
339
|
+
if (isArray$1(obj)) {
|
343
340
|
// This behavior is slightly different from Array#toString:
|
344
341
|
// 1. Array#toString calls `this.join`, rather than Array#join
|
345
342
|
// Ex: arr = []; arr.join = () => 1; arr.toString() === 1; toString(arr) === ''
|
@@ -350,13 +347,13 @@ function toString(obj) {
|
|
350
347
|
// 4. Array#toString converts recursive references to arrays to ''
|
351
348
|
// Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws
|
352
349
|
// Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
|
353
|
-
return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
|
350
|
+
return ArrayJoin.call(ArrayMap.call(obj, toString$1), ',');
|
354
351
|
}
|
355
352
|
return obj.toString();
|
356
353
|
}
|
357
354
|
else if (typeof obj === 'object') {
|
358
355
|
// This catches null and returns "[object Null]". Weird, but kept for backwards compatibility.
|
359
|
-
return OtS.call(obj);
|
356
|
+
return OtS$1.call(obj);
|
360
357
|
}
|
361
358
|
else {
|
362
359
|
return String(obj);
|
@@ -523,15 +520,15 @@ const CACHED_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map();
|
|
523
520
|
*/
|
524
521
|
function htmlPropertyToAttribute(propName) {
|
525
522
|
const ariaAttributeName = AriaPropNameToAttrNameMap[propName];
|
526
|
-
if (!isUndefined(ariaAttributeName)) {
|
523
|
+
if (!isUndefined$1(ariaAttributeName)) {
|
527
524
|
return ariaAttributeName;
|
528
525
|
}
|
529
526
|
const specialAttributeName = SPECIAL_PROPERTY_ATTRIBUTE_MAPPING.get(propName);
|
530
|
-
if (!isUndefined(specialAttributeName)) {
|
527
|
+
if (!isUndefined$1(specialAttributeName)) {
|
531
528
|
return specialAttributeName;
|
532
529
|
}
|
533
530
|
const cachedAttributeName = CACHED_PROPERTY_ATTRIBUTE_MAPPING.get(propName);
|
534
|
-
if (!isUndefined(cachedAttributeName)) {
|
531
|
+
if (!isUndefined$1(cachedAttributeName)) {
|
535
532
|
return cachedAttributeName;
|
536
533
|
}
|
537
534
|
let attributeName = '';
|
@@ -598,7 +595,7 @@ function setHooks(hooks) {
|
|
598
595
|
function flattenStylesheets(stylesheets) {
|
599
596
|
const list = [];
|
600
597
|
for (const stylesheet of stylesheets) {
|
601
|
-
if (!isArray(stylesheet)) {
|
598
|
+
if (!isArray$1(stylesheet)) {
|
602
599
|
list.push(stylesheet);
|
603
600
|
}
|
604
601
|
else {
|
@@ -607,7 +604,7 @@ function flattenStylesheets(stylesheets) {
|
|
607
604
|
}
|
608
605
|
return list;
|
609
606
|
}
|
610
|
-
/** version: 8.
|
607
|
+
/** version: 8.8.0 */
|
611
608
|
|
612
609
|
/*
|
613
610
|
* Copyright (c) 2024, Salesforce, Inc.
|
@@ -862,7 +859,7 @@ const ariaDescriptor = (attrName) => ({
|
|
862
859
|
this.removeAttribute(attrName);
|
863
860
|
}
|
864
861
|
else {
|
865
|
-
this.setAttribute(attrName, toString(newValue));
|
862
|
+
this.setAttribute(attrName, toString$1(newValue));
|
866
863
|
}
|
867
864
|
}
|
868
865
|
},
|
@@ -886,7 +883,7 @@ const descriptors = {
|
|
886
883
|
const num = Number(newValue);
|
887
884
|
const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
|
888
885
|
if (normalizedValue !== currentValue) {
|
889
|
-
this.setAttribute('tabindex', toString(newValue));
|
886
|
+
this.setAttribute('tabindex', toString$1(newValue));
|
890
887
|
}
|
891
888
|
},
|
892
889
|
},
|
@@ -935,24 +932,24 @@ class LightningElement {
|
|
935
932
|
return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
|
936
933
|
}
|
937
934
|
setAttribute(attrName, attrValue) {
|
938
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
935
|
+
const normalizedName = StringToLowerCase.call(toString$1(attrName));
|
939
936
|
const normalizedValue = String(attrValue);
|
940
937
|
__classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
|
941
938
|
mutationTracker.add(this, normalizedName);
|
942
939
|
}
|
943
940
|
getAttribute(attrName) {
|
944
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
945
|
-
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)) {
|
946
943
|
return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
947
944
|
}
|
948
945
|
return null;
|
949
946
|
}
|
950
947
|
hasAttribute(attrName) {
|
951
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
952
|
-
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);
|
953
950
|
}
|
954
951
|
removeAttribute(attrName) {
|
955
|
-
const normalizedName = StringToLowerCase.call(toString(attrName));
|
952
|
+
const normalizedName = StringToLowerCase.call(toString$1(attrName));
|
956
953
|
delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
|
957
954
|
// Track mutations for removal of non-existing attributes
|
958
955
|
mutationTracker.add(this, normalizedName);
|
@@ -1039,36 +1036,42 @@ defineProperties(LightningElement.prototype, descriptors);
|
|
1039
1036
|
* SPDX-License-Identifier: MIT
|
1040
1037
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1041
1038
|
*/
|
1042
|
-
const escapeAttrVal = (
|
1043
|
-
function
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
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 = '';
|
1051
1053
|
}
|
1052
|
-
else if (
|
1053
|
-
|
1054
|
+
else if (!isString(attrValue)) {
|
1055
|
+
attrValue = String(attrValue);
|
1054
1056
|
}
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
function renderAttrsNoYield(emit, instance, attrs) {
|
1059
|
-
if (!attrs) {
|
1060
|
-
return;
|
1061
|
-
}
|
1062
|
-
for (const attrName of Object.getOwnPropertyNames(attrs)) {
|
1063
|
-
const attrVal = attrs[attrName];
|
1064
|
-
if (typeof attrVal === 'string') {
|
1065
|
-
emit(attrVal === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrVal)}"`);
|
1066
|
-
}
|
1067
|
-
else if (attrVal === null) {
|
1068
|
-
emit('');
|
1057
|
+
if (combinedScopeToken && attrName === 'class') {
|
1058
|
+
attrValue += ' ' + combinedScopeToken;
|
1059
|
+
hasClassAttribute = true;
|
1069
1060
|
}
|
1061
|
+
result += attrValue === '' ? ` ${attrName}` : ` ${attrName}="${escapeAttrVal(attrValue)}"`;
|
1070
1062
|
}
|
1071
|
-
|
1063
|
+
// If we didn't render any `class` attribute, render one for the scope token(s)
|
1064
|
+
if (!hasClassAttribute && combinedScopeToken) {
|
1065
|
+
result += ` class="${combinedScopeToken}"`;
|
1066
|
+
}
|
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));
|
1072
1075
|
}
|
1073
1076
|
function* fallbackTmpl(_props, _attrs, _slotted, Cmp, _instance) {
|
1074
1077
|
if (Cmp.renderMode !== 'light') {
|
@@ -1222,52 +1225,637 @@ function* toIteratorDirective(iterable) {
|
|
1222
1225
|
}
|
1223
1226
|
}
|
1224
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
|
+
|
1225
1773
|
/*
|
1226
1774
|
* Copyright (c) 2024, Salesforce, Inc.
|
1227
1775
|
* All rights reserved.
|
1228
1776
|
* SPDX-License-Identifier: MIT
|
1229
1777
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
|
1230
1778
|
*/
|
1231
|
-
|
1232
|
-
//
|
1233
|
-
//
|
1234
|
-
//
|
1235
|
-
function
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
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 [];
|
1243
1801
|
}
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
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;
|
1251
1817
|
}
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
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
|
+
}
|
1255
1829
|
}
|
1256
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
|
+
}
|
1257
1843
|
|
1258
1844
|
exports.ClassList = ClassList;
|
1259
1845
|
exports.LightningElement = LightningElement;
|
1260
1846
|
exports.SYMBOL__GENERATE_MARKUP = SYMBOL__GENERATE_MARKUP;
|
1261
1847
|
exports.SYMBOL__SET_INTERNALS = SYMBOL__SET_INTERNALS;
|
1262
1848
|
exports.api = api;
|
1263
|
-
exports.
|
1849
|
+
exports.connectContext = connectContext;
|
1264
1850
|
exports.createContextProvider = createContextProvider;
|
1265
1851
|
exports.createElement = createElement;
|
1852
|
+
exports.establishContextfulRelationship = establishContextfulRelationship;
|
1266
1853
|
exports.fallbackTmpl = fallbackTmpl;
|
1267
1854
|
exports.fallbackTmplNoYield = fallbackTmplNoYield;
|
1268
1855
|
exports.filterProperties = filterProperties;
|
1269
1856
|
exports.freezeTemplate = freezeTemplate;
|
1270
1857
|
exports.getComponentDef = getComponentDef;
|
1858
|
+
exports.getReadOnlyProxy = getReadOnlyProxy;
|
1271
1859
|
exports.hasScopedStaticStylesheets = hasScopedStaticStylesheets;
|
1272
1860
|
exports.hot = hot;
|
1273
1861
|
exports.htmlEscape = htmlEscape;
|
@@ -1294,8 +1882,8 @@ exports.swapStyle = swapStyle;
|
|
1294
1882
|
exports.swapTemplate = swapTemplate;
|
1295
1883
|
exports.toIteratorDirective = toIteratorDirective;
|
1296
1884
|
exports.track = track;
|
1297
|
-
exports.unwrap = unwrap;
|
1885
|
+
exports.unwrap = unwrap$1;
|
1298
1886
|
exports.validateStyleTextContents = validateStyleTextContents;
|
1299
1887
|
exports.wire = wire;
|
1300
|
-
/** version: 8.
|
1888
|
+
/** version: 8.8.0 */
|
1301
1889
|
//# sourceMappingURL=index.cjs.js.map
|