@plasmicapp/react-web 0.2.102 → 0.2.103
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/README.md +13 -0
- package/dist/all.d.ts +11 -3
- package/dist/index.d.ts +1 -0
- package/dist/react-web.cjs.development.js +394 -347
- package/dist/react-web.cjs.development.js.map +1 -1
- package/dist/react-web.cjs.production.min.js +1 -1
- package/dist/react-web.cjs.production.min.js.map +1 -1
- package/dist/react-web.esm.js +392 -347
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/helpers.d.ts +9 -0
- package/dist/states/index.d.ts +4 -6
- package/dist/stories/PlasmicImg.stories.d.ts +2 -2
- package/dist/stories/UseDollarState.stories.d.ts +33 -0
- package/package.json +8 -3
- package/skinny/dist/index.d.ts +1 -0
- package/skinny/dist/index.js +5 -2
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/states/helpers.d.ts +9 -0
- package/skinny/dist/states/index.d.ts +4 -6
- package/skinny/dist/stories/UseDollarState.stories.d.ts +34 -0
- package/README +0 -8
package/dist/react-web.esm.js
CHANGED
|
@@ -18,7 +18,7 @@ import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
|
|
|
18
18
|
import { useSelectState } from '@react-stately/select';
|
|
19
19
|
import { useSwitch as useSwitch$1 } from '@react-aria/switch';
|
|
20
20
|
import { useOverlay, useOverlayPosition, DismissButton } from '@react-aria/overlays';
|
|
21
|
-
import
|
|
21
|
+
import _get from 'dlv';
|
|
22
22
|
import { dset } from 'dset';
|
|
23
23
|
|
|
24
24
|
function _extends() {
|
|
@@ -1199,6 +1199,96 @@ function isInternalHref(href) {
|
|
|
1199
1199
|
return /^\/(?!\/)/.test(href);
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
|
+
var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
1203
|
+
|
|
1204
|
+
function isIterable(val) {
|
|
1205
|
+
return val != null && typeof val[Symbol.iterator] === "function";
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
function genTranslatableString(elt) {
|
|
1209
|
+
var components = {};
|
|
1210
|
+
var componentsCount = 0;
|
|
1211
|
+
|
|
1212
|
+
var getText = function getText(node) {
|
|
1213
|
+
if (!node) {
|
|
1214
|
+
return "";
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
|
|
1218
|
+
return node.toString();
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
if (typeof node !== "object") {
|
|
1222
|
+
return "";
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
if (Array.isArray(node) || isIterable(node)) {
|
|
1226
|
+
return Array.from(node).map(function (child) {
|
|
1227
|
+
return getText(child);
|
|
1228
|
+
}).filter(function (child) {
|
|
1229
|
+
return !!child;
|
|
1230
|
+
}).join("");
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
|
|
1234
|
+
var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
|
|
1235
|
+
return getText(child);
|
|
1236
|
+
}).filter(function (child) {
|
|
1237
|
+
return !!child;
|
|
1238
|
+
}).join("");
|
|
1239
|
+
|
|
1240
|
+
if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
|
|
1241
|
+
return contents;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
var componentId = componentsCount + 1;
|
|
1245
|
+
componentsCount++;
|
|
1246
|
+
components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
|
|
1247
|
+
key: componentId,
|
|
1248
|
+
children: undefined
|
|
1249
|
+
}) : node;
|
|
1250
|
+
return "<" + componentId + ">" + contents + "</" + componentId + ">";
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1253
|
+
var str = getText(elt);
|
|
1254
|
+
return {
|
|
1255
|
+
str: str,
|
|
1256
|
+
components: components,
|
|
1257
|
+
componentsCount: componentsCount
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
function Trans(_ref) {
|
|
1261
|
+
var children = _ref.children;
|
|
1262
|
+
|
|
1263
|
+
var _t = React__default.useContext(PlasmicTranslatorContext);
|
|
1264
|
+
|
|
1265
|
+
if (!_t) {
|
|
1266
|
+
warnNoTranslationFunctionAtMostOnce();
|
|
1267
|
+
return children;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
var _genTranslatableStrin = genTranslatableString(children),
|
|
1271
|
+
str = _genTranslatableStrin.str,
|
|
1272
|
+
components = _genTranslatableStrin.components,
|
|
1273
|
+
componentsCount = _genTranslatableStrin.componentsCount;
|
|
1274
|
+
|
|
1275
|
+
return _t(str, componentsCount > 0 ? {
|
|
1276
|
+
components: components
|
|
1277
|
+
} : undefined);
|
|
1278
|
+
}
|
|
1279
|
+
var hasWarned = false;
|
|
1280
|
+
|
|
1281
|
+
function warnNoTranslationFunctionAtMostOnce() {
|
|
1282
|
+
if (!hasWarned) {
|
|
1283
|
+
console.warn("Using Plasmic Translation but no translation function has been provided");
|
|
1284
|
+
hasWarned = true;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
function hasKey(v, key) {
|
|
1289
|
+
return typeof v === "object" && v !== null && key in v;
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1202
1292
|
function PlasmicSlot(props) {
|
|
1203
1293
|
return renderPlasmicSlot(props);
|
|
1204
1294
|
}
|
|
@@ -1242,7 +1332,8 @@ function renderPlasmicSlot(opts) {
|
|
|
1242
1332
|
|
|
1243
1333
|
function maybeAsString(node) {
|
|
1244
1334
|
// Unwrap fragments
|
|
1245
|
-
if (isValidElement(node) &&
|
|
1335
|
+
if (isValidElement(node) && ( // Fragment and Trans don't render DOM elements
|
|
1336
|
+
node.type === Fragment || node.type === Trans)) {
|
|
1246
1337
|
return maybeAsString(node.props.children);
|
|
1247
1338
|
}
|
|
1248
1339
|
|
|
@@ -1353,96 +1444,6 @@ function createUseScreenVariants(isMulti, screenQueries) {
|
|
|
1353
1444
|
};
|
|
1354
1445
|
}
|
|
1355
1446
|
|
|
1356
|
-
var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
1357
|
-
|
|
1358
|
-
function isIterable(val) {
|
|
1359
|
-
return val != null && typeof val[Symbol.iterator] === "function";
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
function genTranslatableString(elt) {
|
|
1363
|
-
var components = {};
|
|
1364
|
-
var componentsCount = 0;
|
|
1365
|
-
|
|
1366
|
-
var getText = function getText(node) {
|
|
1367
|
-
if (!node) {
|
|
1368
|
-
return "";
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
|
|
1372
|
-
return node.toString();
|
|
1373
|
-
}
|
|
1374
|
-
|
|
1375
|
-
if (typeof node !== "object") {
|
|
1376
|
-
return "";
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
if (Array.isArray(node) || isIterable(node)) {
|
|
1380
|
-
return Array.from(node).map(function (child) {
|
|
1381
|
-
return getText(child);
|
|
1382
|
-
}).filter(function (child) {
|
|
1383
|
-
return !!child;
|
|
1384
|
-
}).join("");
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
|
|
1388
|
-
var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
|
|
1389
|
-
return getText(child);
|
|
1390
|
-
}).filter(function (child) {
|
|
1391
|
-
return !!child;
|
|
1392
|
-
}).join("");
|
|
1393
|
-
|
|
1394
|
-
if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
|
|
1395
|
-
return contents;
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
var componentId = componentsCount + 1;
|
|
1399
|
-
componentsCount++;
|
|
1400
|
-
components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
|
|
1401
|
-
key: componentId,
|
|
1402
|
-
children: undefined
|
|
1403
|
-
}) : node;
|
|
1404
|
-
return "<" + componentId + ">" + contents + "</" + componentId + ">";
|
|
1405
|
-
};
|
|
1406
|
-
|
|
1407
|
-
var str = getText(elt);
|
|
1408
|
-
return {
|
|
1409
|
-
str: str,
|
|
1410
|
-
components: components,
|
|
1411
|
-
componentsCount: componentsCount
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
function Trans(_ref) {
|
|
1415
|
-
var children = _ref.children;
|
|
1416
|
-
|
|
1417
|
-
var _t = React__default.useContext(PlasmicTranslatorContext);
|
|
1418
|
-
|
|
1419
|
-
if (!_t) {
|
|
1420
|
-
warnNoTranslationFunctionAtMostOnce();
|
|
1421
|
-
return children;
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
var _genTranslatableStrin = genTranslatableString(children),
|
|
1425
|
-
str = _genTranslatableStrin.str,
|
|
1426
|
-
components = _genTranslatableStrin.components,
|
|
1427
|
-
componentsCount = _genTranslatableStrin.componentsCount;
|
|
1428
|
-
|
|
1429
|
-
return _t(str, componentsCount > 0 ? {
|
|
1430
|
-
components: components
|
|
1431
|
-
} : undefined);
|
|
1432
|
-
}
|
|
1433
|
-
var hasWarned = false;
|
|
1434
|
-
|
|
1435
|
-
function warnNoTranslationFunctionAtMostOnce() {
|
|
1436
|
-
if (!hasWarned) {
|
|
1437
|
-
console.warn("Using Plasmic Translation but no translation function has been provided");
|
|
1438
|
-
hasWarned = true;
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
function hasKey(v, key) {
|
|
1443
|
-
return typeof v === "object" && v !== null && key in v;
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
1447
|
var PlasmicRootContext = /*#__PURE__*/createContext(undefined);
|
|
1447
1448
|
function PlasmicRootProvider(props) {
|
|
1448
1449
|
var platform = props.platform,
|
|
@@ -3117,40 +3118,24 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
|
|
|
3117
3118
|
};
|
|
3118
3119
|
}
|
|
3119
3120
|
|
|
3120
|
-
|
|
3121
|
-
function
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
for (var _iterator = _createForOfIteratorHelperLoose(list), _step; !(_step = _iterator()).done;) {
|
|
3125
|
-
var val = _step.value;
|
|
3126
|
-
keyedObject[keyFunc(val)] = val;
|
|
3127
|
-
}
|
|
3128
|
-
|
|
3129
|
-
return keyedObject;
|
|
3121
|
+
function generateStateOnChangeProp($state, stateName, dataReps) {
|
|
3122
|
+
return function (val, path) {
|
|
3123
|
+
return dset($state, [stateName].concat(dataReps, path), val);
|
|
3124
|
+
};
|
|
3130
3125
|
}
|
|
3126
|
+
/**
|
|
3127
|
+
* This function generate the state value prop for repeated states
|
|
3128
|
+
* Example:
|
|
3129
|
+
* - parent[][].counter[].count
|
|
3130
|
+
* We need to pass `parent[index1][index2].counter to the child component
|
|
3131
|
+
*/
|
|
3131
3132
|
|
|
3132
|
-
function
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
if (parts2.length === 0) {
|
|
3137
|
-
return $state;
|
|
3138
|
-
}
|
|
3139
|
-
|
|
3140
|
-
var existing = get($state, parts2);
|
|
3141
|
-
|
|
3142
|
-
if (existing) {
|
|
3143
|
-
return existing;
|
|
3144
|
-
}
|
|
3145
|
-
|
|
3146
|
-
var newObj = {};
|
|
3147
|
-
dset($state, parts2, newObj);
|
|
3148
|
-
return newObj;
|
|
3133
|
+
function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
3134
|
+
) {
|
|
3135
|
+
return _get($state, path);
|
|
3149
3136
|
}
|
|
3150
3137
|
|
|
3151
|
-
|
|
3152
|
-
return !!React__default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current;
|
|
3153
|
-
}
|
|
3138
|
+
var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
|
|
3154
3139
|
|
|
3155
3140
|
function shallowEqual(a1, a2) {
|
|
3156
3141
|
if (a1.length !== a2.length) {
|
|
@@ -3166,289 +3151,349 @@ function shallowEqual(a1, a2) {
|
|
|
3166
3151
|
return true;
|
|
3167
3152
|
}
|
|
3168
3153
|
|
|
3169
|
-
function
|
|
3170
|
-
|
|
3154
|
+
var isNum = function isNum(value) {
|
|
3155
|
+
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
3156
|
+
};
|
|
3157
|
+
|
|
3158
|
+
function mkProxy(specs, maybeHandlers) {
|
|
3159
|
+
var handlers = maybeHandlers != null ? maybeHandlers : function () {
|
|
3171
3160
|
return {
|
|
3172
|
-
|
|
3173
|
-
return [
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
spec.initFunc ? UNINITIALIZED : spec.initVal];
|
|
3179
|
-
})),
|
|
3180
|
-
initStateValues: Object.fromEntries(specs.filter(function (spec) {
|
|
3181
|
-
return !spec.initFunc;
|
|
3182
|
-
}).map(function (spec) {
|
|
3183
|
-
return [spec.path, spec.initVal];
|
|
3184
|
-
})),
|
|
3185
|
-
initStateDeps: {},
|
|
3186
|
-
fireOnChange: {}
|
|
3161
|
+
get: function get(target, property) {
|
|
3162
|
+
return target[property];
|
|
3163
|
+
},
|
|
3164
|
+
set: function set(target, property, value) {
|
|
3165
|
+
return (target[property] = value) || true;
|
|
3166
|
+
}
|
|
3187
3167
|
};
|
|
3188
|
-
}),
|
|
3189
|
-
_$$state = _React$useState[0],
|
|
3190
|
-
set$$State = _React$useState[1]; // We have a weird scheme here to reduce the number of state updates.
|
|
3191
|
-
// Whenever user does a $state get() or set(), we may end up initializing
|
|
3192
|
-
// a bunch of values. We don't want to call set$$State() a bunch of times.
|
|
3193
|
-
// Instead, we will fork as we need to, and call set$$State() at the end of
|
|
3194
|
-
// the hook and at the end of get() / set() as appropriate.
|
|
3195
|
-
// $$state here is going to be copied-on-write; once copied, it will
|
|
3196
|
-
// be directly mutated. Since $state will always be directly proxying $$state,
|
|
3197
|
-
// that means you can "read what you wrote": after $state.count = $state.count + 1,
|
|
3198
|
-
// if you read $state.count again, it will reflect the latest value.
|
|
3199
|
-
//
|
|
3200
|
-
// There are three places where we might actually call set$$State():
|
|
3201
|
-
// 1. At the end of a "top-level" get(): we may have ended up initializing
|
|
3202
|
-
// some state values.
|
|
3203
|
-
// 2. At the end of a "top-level" set(): we mutated this value, but also
|
|
3204
|
-
// may have reset some other state values that depended on this one.
|
|
3205
|
-
// 3. At the end of the hook, where we compare the new initial value with
|
|
3206
|
-
// the previous initial value.
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
var $$state = _extends({}, _$$state);
|
|
3210
|
-
|
|
3211
|
-
var dirtyFields = {
|
|
3212
|
-
stateValues: false,
|
|
3213
|
-
initStateValues: false,
|
|
3214
|
-
initStateDeps: false,
|
|
3215
|
-
fireOnChange: false
|
|
3216
3168
|
};
|
|
3217
3169
|
|
|
3218
|
-
function
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3170
|
+
var rec = function rec(currPath) {
|
|
3171
|
+
var nextParts = Object.fromEntries(specs.filter(function (spec) {
|
|
3172
|
+
return shallowEqual(currPath.map(function (p) {
|
|
3173
|
+
return isNum(p) ? "[]" : p;
|
|
3174
|
+
}), spec.path.slice(0, currPath.length));
|
|
3175
|
+
}).map(function (spec) {
|
|
3176
|
+
var nextPart = spec.path[currPath.length];
|
|
3177
|
+
|
|
3178
|
+
if (spec.path.length === currPath.length + 1) {
|
|
3179
|
+
return [nextPart, {
|
|
3180
|
+
isLast: true,
|
|
3181
|
+
spec: spec
|
|
3182
|
+
}];
|
|
3183
|
+
} else {
|
|
3184
|
+
return [nextPart, {
|
|
3185
|
+
isLast: false,
|
|
3186
|
+
spec: spec
|
|
3187
|
+
}];
|
|
3188
|
+
}
|
|
3189
|
+
}));
|
|
3190
|
+
return new Proxy("[]" in nextParts ? [] : {}, {
|
|
3191
|
+
get: function get(target, property, receiver) {
|
|
3192
|
+
if ("[]" in nextParts && isNum(property)) {
|
|
3193
|
+
if (!(property in target)) {
|
|
3194
|
+
target[property] = rec([].concat(currPath, [+property]));
|
|
3195
|
+
}
|
|
3196
|
+
} else if (property in nextParts) {
|
|
3197
|
+
if (nextParts[property].isLast) {
|
|
3198
|
+
var _handlers$get, _handlers;
|
|
3199
|
+
|
|
3200
|
+
return handlers == null ? void 0 : (_handlers$get = (_handlers = handlers({
|
|
3201
|
+
path: [].concat(currPath, [property]),
|
|
3202
|
+
spec: nextParts[property].spec
|
|
3203
|
+
})).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
|
|
3204
|
+
} else if (!(property in target)) {
|
|
3205
|
+
target[property] = rec([].concat(currPath, [property]));
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3224
3208
|
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3209
|
+
return target[property];
|
|
3210
|
+
},
|
|
3211
|
+
set: function set(target, property, value, receiver) {
|
|
3212
|
+
if (!(property in target) && property in nextParts) {
|
|
3213
|
+
if (nextParts[property].isLast) {
|
|
3214
|
+
var _handlers$set, _handlers$set2, _handlers2;
|
|
3215
|
+
|
|
3216
|
+
return (_handlers$set = (_handlers$set2 = (_handlers2 = handlers({
|
|
3217
|
+
path: [].concat(currPath, [property]),
|
|
3218
|
+
spec: nextParts[property].spec
|
|
3219
|
+
})).set) == null ? void 0 : _handlers$set2.call(_handlers2, target, property, value, receiver)) != null ? _handlers$set : false;
|
|
3220
|
+
} else {
|
|
3221
|
+
throw new Error("You can't set a value in the middle of the path");
|
|
3222
|
+
}
|
|
3223
|
+
} else {
|
|
3224
|
+
target[property] = value;
|
|
3225
|
+
return true;
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
3228
|
});
|
|
3229
|
-
|
|
3230
|
-
$$state.stateValues[path] = value; // If any other state depends on this one, then reset their
|
|
3231
|
-
// values to their initial as well
|
|
3232
|
-
|
|
3233
|
-
for (var _i = 0, _Object$entries = Object.entries($$state.initStateDeps); _i < _Object$entries.length; _i++) {
|
|
3234
|
-
var _Object$entries$_i = _Object$entries[_i],
|
|
3235
|
-
key = _Object$entries$_i[0],
|
|
3236
|
-
deps = _Object$entries$_i[1];
|
|
3229
|
+
};
|
|
3237
3230
|
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
}
|
|
3241
|
-
}
|
|
3231
|
+
return rec([]);
|
|
3232
|
+
}
|
|
3242
3233
|
|
|
3243
|
-
|
|
3234
|
+
function cloneProxy(specs, states, obj) {
|
|
3235
|
+
var newObj = mkProxy(specs);
|
|
3236
|
+
Object.values(states).forEach(function (_ref) {
|
|
3237
|
+
var path = _ref.path;
|
|
3244
3238
|
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
// the state of another component during rendering.
|
|
3250
|
-
// Instead, we save it into our internal state, and fire
|
|
3251
|
-
// it later in a layout effect.
|
|
3252
|
-
updateFireOnChange(spec.path, value);
|
|
3253
|
-
} else {
|
|
3254
|
-
var _props$spec$onChangeP;
|
|
3239
|
+
dset(newObj, path, _get(obj, path));
|
|
3240
|
+
});
|
|
3241
|
+
return newObj;
|
|
3242
|
+
}
|
|
3255
3243
|
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
(_props$spec$onChangeP = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP.call(props, value);
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3244
|
+
function saveState(state, states) {
|
|
3245
|
+
states[JSON.stringify(state.path)] = state;
|
|
3246
|
+
}
|
|
3263
3247
|
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
});
|
|
3268
|
-
console.log("UPDATE initValue:", path, value);
|
|
3269
|
-
$$state.initStateValues[path] = value;
|
|
3270
|
-
}
|
|
3248
|
+
function hasState(state, states) {
|
|
3249
|
+
return JSON.stringify(state.path) in states;
|
|
3250
|
+
}
|
|
3271
3251
|
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
$$state.initStateDeps[path] = deps;
|
|
3278
|
-
}
|
|
3252
|
+
var transformPathStringToObj = function transformPathStringToObj(str) {
|
|
3253
|
+
// "c[][]" -> ["c", "[]", "[]"]
|
|
3254
|
+
var splitStatePathPart = function splitStatePathPart(state) {
|
|
3255
|
+
return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
|
|
3256
|
+
};
|
|
3279
3257
|
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
return x;
|
|
3283
|
-
})) {
|
|
3284
|
-
console.log("UPDATE $$STATE");
|
|
3285
|
-
set$$State($$state);
|
|
3286
|
-
}
|
|
3287
|
-
}
|
|
3258
|
+
return str.split(".").flatMap(splitStatePathPart);
|
|
3259
|
+
};
|
|
3288
3260
|
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3261
|
+
function useVanillaDollarState(_specs, props) {
|
|
3262
|
+
var specs = _specs.map(function (_ref2) {
|
|
3263
|
+
var pathStr = _ref2.path,
|
|
3264
|
+
spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
|
|
3265
|
+
|
|
3266
|
+
return _extends({}, spec, {
|
|
3267
|
+
pathStr: pathStr,
|
|
3268
|
+
path: transformPathStringToObj(pathStr),
|
|
3269
|
+
isRepeated: pathStr.split(".").some(function (part) {
|
|
3270
|
+
return part.endsWith("[]");
|
|
3271
|
+
})
|
|
3292
3272
|
});
|
|
3293
|
-
|
|
3294
|
-
}
|
|
3273
|
+
});
|
|
3295
3274
|
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
return spec.path;
|
|
3300
|
-
});
|
|
3301
|
-
}, [specs]);
|
|
3302
|
-
var stateAccessStack = [{}];
|
|
3303
|
-
var $props = props;
|
|
3304
|
-
/**
|
|
3305
|
-
* Runs spec.initFunc, keeping track of the state accesses
|
|
3306
|
-
* that occurred while running it
|
|
3307
|
-
*/
|
|
3308
|
-
|
|
3309
|
-
function trackedInit(spec) {
|
|
3310
|
-
var _$$state$initStateDep;
|
|
3311
|
-
|
|
3312
|
-
var stateAccess = {};
|
|
3313
|
-
stateAccessStack.push(stateAccess);
|
|
3314
|
-
var res = spec.initFunc($props, $state);
|
|
3315
|
-
var deps = Object.keys(stateAccess);
|
|
3316
|
-
|
|
3317
|
-
if (!shallowEqual(deps, (_$$state$initStateDep = $$state.initStateDeps[spec.path]) != null ? _$$state$initStateDep : [])) {
|
|
3318
|
-
updateInitStateDeps(spec.path, deps);
|
|
3319
|
-
}
|
|
3275
|
+
var _React$useState = React__default.useState(function () {
|
|
3276
|
+
var stateValues = mkProxy(specs);
|
|
3277
|
+
var initStates = {};
|
|
3320
3278
|
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
}
|
|
3324
|
-
/**
|
|
3325
|
-
* Resets the value for this state
|
|
3326
|
-
*/
|
|
3279
|
+
for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
|
|
3280
|
+
var spec = _step.value;
|
|
3327
3281
|
|
|
3282
|
+
if (spec.valueProp || spec.isRepeated) {
|
|
3283
|
+
continue;
|
|
3284
|
+
} else if (spec.initFunc) {
|
|
3285
|
+
dset(stateValues, spec.path, UNINITIALIZED);
|
|
3286
|
+
} else {
|
|
3287
|
+
var _spec$initVal;
|
|
3328
3288
|
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
var spec = specByPath[path];
|
|
3332
|
-
var initValue = trackedInit(spec);
|
|
3289
|
+
dset(stateValues, spec.path, (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
|
|
3290
|
+
}
|
|
3333
3291
|
|
|
3334
|
-
|
|
3335
|
-
|
|
3292
|
+
saveState({
|
|
3293
|
+
path: spec.path,
|
|
3294
|
+
spec: spec
|
|
3295
|
+
}, initStates);
|
|
3336
3296
|
}
|
|
3337
3297
|
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3298
|
+
var deps = fillUninitializedStateValues(specs, props, stateValues, initStates);
|
|
3299
|
+
return {
|
|
3300
|
+
stateValues: stateValues,
|
|
3301
|
+
initStateDeps: deps,
|
|
3302
|
+
initStateValues: cloneProxy(specs, initStates, stateValues),
|
|
3303
|
+
states: initStates
|
|
3304
|
+
};
|
|
3305
|
+
}),
|
|
3306
|
+
$$state = _React$useState[0],
|
|
3307
|
+
set$$State = _React$useState[1];
|
|
3341
3308
|
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3309
|
+
var $state = mkProxy(specs, function (state) {
|
|
3310
|
+
return {
|
|
3311
|
+
get: function get(_target, _property) {
|
|
3312
|
+
if (state.spec.valueProp) {
|
|
3313
|
+
if (!state.spec.isRepeated) {
|
|
3314
|
+
return props[state.spec.valueProp];
|
|
3315
|
+
} else {
|
|
3316
|
+
return _get(props[state.spec.valueProp], state.path.slice(1));
|
|
3317
|
+
}
|
|
3318
|
+
}
|
|
3346
3319
|
|
|
3320
|
+
if (!hasState(state, $$state.states)) {
|
|
3321
|
+
var _state$spec$initVal;
|
|
3347
3322
|
|
|
3348
|
-
|
|
3349
|
-
var $state = {};
|
|
3323
|
+
saveState(state, $$state.states);
|
|
3350
3324
|
|
|
3351
|
-
|
|
3352
|
-
var spec = _step2.value;
|
|
3353
|
-
var parts = spec.path.split(".");
|
|
3354
|
-
var name = parts[parts.length - 1];
|
|
3355
|
-
var obj = getObjectAtPath($state, spec.path); // Define get() and set() for this state cell
|
|
3325
|
+
dset($$state.stateValues, state.path, state.spec.initFunc ? UNINITIALIZED : (_state$spec$initVal = state.spec.initVal) != null ? _state$spec$initVal : undefined);
|
|
3356
3326
|
|
|
3357
|
-
|
|
3358
|
-
get: function get() {
|
|
3359
|
-
if (spec.valueProp) {
|
|
3360
|
-
return props[spec.valueProp];
|
|
3361
|
-
}
|
|
3327
|
+
var deps = state.spec.initFunc ? fillUninitializedStateValues(specs, props, $$state.stateValues, $$state.states) : {};
|
|
3362
3328
|
|
|
3363
|
-
|
|
3364
|
-
var value = $$state.stateValues[spec.path];
|
|
3329
|
+
dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
|
|
3365
3330
|
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3331
|
+
set$$State(function (prev) {
|
|
3332
|
+
return {
|
|
3333
|
+
initStateValues: cloneProxy(specs, prev.states, prev.stateValues),
|
|
3334
|
+
stateValues: cloneProxy(specs, prev.states, prev.initStateValues),
|
|
3335
|
+
initStateDeps: _extends({}, prev.initStateDeps, deps),
|
|
3336
|
+
states: _extends({}, prev.states)
|
|
3337
|
+
};
|
|
3338
|
+
});
|
|
3339
|
+
}
|
|
3372
3340
|
|
|
3341
|
+
return _get($$state.stateValues, state.path);
|
|
3342
|
+
},
|
|
3343
|
+
set: function set(_target, _property, newValue) {
|
|
3344
|
+
saveState(state, $$state.states);
|
|
3373
3345
|
|
|
3374
|
-
|
|
3375
|
-
|
|
3346
|
+
if (newValue !== _get($$state.stateValues, state.path)) {
|
|
3347
|
+
dset($$state.stateValues, state.path, newValue);
|
|
3376
3348
|
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3349
|
+
for (var _i = 0, _Object$entries = Object.entries($$state.initStateDeps); _i < _Object$entries.length; _i++) {
|
|
3350
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
3351
|
+
key = _Object$entries$_i[0],
|
|
3352
|
+
deps = _Object$entries$_i[1];
|
|
3380
3353
|
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3354
|
+
if (deps.includes(JSON.stringify(state.path))) {
|
|
3355
|
+
dset($$state.stateValues, JSON.parse(key), UNINITIALIZED);
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3385
3358
|
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3359
|
+
var newDeps = fillUninitializedStateValues(specs, props, $$state.stateValues, $$state.states);
|
|
3360
|
+
set$$State(function (prev) {
|
|
3361
|
+
return {
|
|
3362
|
+
initStateValues: _extends({}, prev.initStateValues),
|
|
3363
|
+
stateValues: cloneProxy(specs, prev.states, prev.stateValues),
|
|
3364
|
+
initStateDeps: _extends({}, prev.initStateDeps, newDeps),
|
|
3365
|
+
states: _extends({}, prev.states)
|
|
3366
|
+
};
|
|
3367
|
+
});
|
|
3389
3368
|
|
|
3390
|
-
|
|
3369
|
+
if (state.spec.onChangeProp) {
|
|
3370
|
+
var _props$state$spec$onC;
|
|
3391
3371
|
|
|
3392
|
-
|
|
3393
|
-
|
|
3372
|
+
(_props$state$spec$onC = props[state.spec.onChangeProp]) == null ? void 0 : _props$state$spec$onC.call(props, newValue, state.path);
|
|
3373
|
+
}
|
|
3394
3374
|
}
|
|
3395
|
-
}
|
|
3396
|
-
});
|
|
3397
|
-
};
|
|
3398
3375
|
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3376
|
+
return true;
|
|
3377
|
+
}
|
|
3378
|
+
};
|
|
3379
|
+
}); // For each spec with an initFunc, evaluate it and see if
|
|
3402
3380
|
// the init value has changed. If so, reset its state.
|
|
3403
3381
|
|
|
3382
|
+
var newStateValues = undefined;
|
|
3383
|
+
var resetSpecs = [];
|
|
3404
3384
|
|
|
3405
|
-
for (var
|
|
3406
|
-
var
|
|
3385
|
+
for (var _i2 = 0, _Object$values = Object.values($$state.states); _i2 < _Object$values.length; _i2++) {
|
|
3386
|
+
var _Object$values$_i = _Object$values[_i2],
|
|
3387
|
+
path = _Object$values$_i.path,
|
|
3388
|
+
spec = _Object$values$_i.spec;
|
|
3407
3389
|
|
|
3408
3390
|
if (spec.initFunc) {
|
|
3409
|
-
var newInit = spec.initFunc(
|
|
3391
|
+
var newInit = spec.initFunc(props, $state);
|
|
3410
3392
|
|
|
3411
|
-
if (newInit !== $$state.initStateValues
|
|
3412
|
-
console.log("init changed for " +
|
|
3413
|
-
|
|
3414
|
-
|
|
3393
|
+
if (newInit !== _get($$state.initStateValues, path)) {
|
|
3394
|
+
console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
|
|
3395
|
+
resetSpecs.push({
|
|
3396
|
+
path: path,
|
|
3397
|
+
spec: spec
|
|
3398
|
+
});
|
|
3415
3399
|
|
|
3416
|
-
if (
|
|
3417
|
-
|
|
3400
|
+
if (!newStateValues) {
|
|
3401
|
+
newStateValues = cloneProxy(specs, $$state.states, $$state.stateValues);
|
|
3418
3402
|
}
|
|
3403
|
+
|
|
3404
|
+
dset(newStateValues, path, UNINITIALIZED);
|
|
3419
3405
|
}
|
|
3420
3406
|
}
|
|
3421
3407
|
}
|
|
3422
3408
|
|
|
3423
|
-
var fireOnChange = $$state.fireOnChange;
|
|
3424
3409
|
React__default.useLayoutEffect(function () {
|
|
3425
|
-
if (
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3410
|
+
if (newStateValues !== undefined) {
|
|
3411
|
+
var newDeps = fillUninitializedStateValues(specs, props, newStateValues, $$state.states);
|
|
3412
|
+
set$$State(function (prev) {
|
|
3413
|
+
var initStateValues = cloneProxy(specs, prev.states, prev.initStateValues);
|
|
3414
|
+
resetSpecs.forEach(function (_ref3) {
|
|
3415
|
+
var path = _ref3.path;
|
|
3416
|
+
|
|
3417
|
+
dset(initStateValues, path, _get(newStateValues, path));
|
|
3418
|
+
});
|
|
3419
|
+
return {
|
|
3420
|
+
stateValues: cloneProxy(specs, prev.states, newStateValues),
|
|
3421
|
+
initStateDeps: _extends({}, prev.initStateDeps, newDeps),
|
|
3422
|
+
initStateValues: initStateValues,
|
|
3423
|
+
states: _extends({}, prev.states)
|
|
3424
|
+
};
|
|
3425
|
+
});
|
|
3426
|
+
|
|
3427
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose(resetSpecs), _step2; !(_step2 = _iterator2()).done;) {
|
|
3428
|
+
var _step2$value = _step2.value,
|
|
3429
|
+
_path = _step2$value.path,
|
|
3430
|
+
_spec = _step2$value.spec;
|
|
3431
3431
|
|
|
3432
|
-
if (
|
|
3433
|
-
var _props$
|
|
3432
|
+
if (_spec.onChangeProp) {
|
|
3433
|
+
var _props$_spec$onChange;
|
|
3434
3434
|
|
|
3435
|
-
(
|
|
3435
|
+
console.log("Firing onChange for reset init value: " + _spec.path, _get(newStateValues, _path));
|
|
3436
|
+
(_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
|
|
3436
3437
|
}
|
|
3437
3438
|
}
|
|
3438
|
-
|
|
3439
|
-
set$$State(function (prev) {
|
|
3440
|
-
return _extends({}, prev, {
|
|
3441
|
-
fireOnChange: {}
|
|
3442
|
-
});
|
|
3443
|
-
});
|
|
3444
3439
|
}
|
|
3445
|
-
}, [
|
|
3446
|
-
|
|
3447
|
-
updateInternalStateIfDirty();
|
|
3440
|
+
}, [newStateValues, props, resetSpecs, specs]);
|
|
3448
3441
|
return $state;
|
|
3449
3442
|
}
|
|
3450
3443
|
|
|
3451
|
-
|
|
3444
|
+
function fillUninitializedStateValues(specs, props, stateValues, states) {
|
|
3445
|
+
var stateAccessStack = [new Set()];
|
|
3446
|
+
var initFuncDeps = {};
|
|
3447
|
+
var $state = mkProxy(specs, function (state) {
|
|
3448
|
+
return {
|
|
3449
|
+
get: function get(_target, _property) {
|
|
3450
|
+
if (state.spec.valueProp) {
|
|
3451
|
+
if (!state.spec.isRepeated) {
|
|
3452
|
+
return props[state.spec.valueProp];
|
|
3453
|
+
} else {
|
|
3454
|
+
return _get(props[state.spec.valueProp], state.path.slice(1));
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
|
|
3458
|
+
var value = _get(stateValues, state.path);
|
|
3459
|
+
|
|
3460
|
+
if (value === UNINITIALIZED) {
|
|
3461
|
+
// This value has a init expression; need to be evaluated.
|
|
3462
|
+
value = tracked(state);
|
|
3463
|
+
|
|
3464
|
+
dset(stateValues, state.path, value);
|
|
3465
|
+
} // Record that this field had just been accessed; for
|
|
3466
|
+
// trackInit() to know what fields were used to compute
|
|
3467
|
+
// the init value
|
|
3468
|
+
|
|
3469
|
+
|
|
3470
|
+
stateAccessStack[stateAccessStack.length - 1].add(JSON.stringify(state.path));
|
|
3471
|
+
return value;
|
|
3472
|
+
},
|
|
3473
|
+
set: function set() {
|
|
3474
|
+
throw new Error("Cannot update state values during initialization");
|
|
3475
|
+
}
|
|
3476
|
+
};
|
|
3477
|
+
});
|
|
3478
|
+
|
|
3479
|
+
function tracked(state) {
|
|
3480
|
+
stateAccessStack.push(new Set());
|
|
3481
|
+
var res = state.spec.initFunc(props, $state);
|
|
3482
|
+
var deps = stateAccessStack.pop();
|
|
3483
|
+
initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
|
|
3484
|
+
return res;
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
for (var _i3 = 0, _Object$values2 = Object.values(states); _i3 < _Object$values2.length; _i3++) {
|
|
3488
|
+
var path = _Object$values2[_i3].path;
|
|
3489
|
+
|
|
3490
|
+
if (_get(stateValues, path) === UNINITIALIZED) {
|
|
3491
|
+
_get($state, path);
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
return initFuncDeps;
|
|
3496
|
+
}
|
|
3452
3497
|
|
|
3453
|
-
export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, Stack, Trans, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
|
|
3498
|
+
export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, Stack, Trans, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useVanillaDollarState as useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
|
|
3454
3499
|
//# sourceMappingURL=react-web.esm.js.map
|