@plasmicapp/react-web 0.2.102 → 0.2.105
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 +471 -108
- package/dist/index.d.ts +1 -0
- package/dist/plume/menu-button/menu-trigger.d.ts +1 -1
- package/dist/plume/select/index.d.ts +1 -0
- package/dist/plume/triggered-overlay/index.d.ts +1 -0
- package/dist/react-web.cjs.development.js +480 -339
- 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 +476 -339
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/triggers.d.ts +4 -4
- package/dist/states/helpers.d.ts +9 -0
- package/dist/states/index.d.ts +7 -7
- package/dist/stories/PlasmicImg.stories.d.ts +2 -2
- package/dist/stories/UseDollarState.stories.d.ts +40 -0
- package/package.json +27 -21
- package/skinny/dist/collection-utils-3487dd27.js +238 -0
- package/skinny/dist/collection-utils-3487dd27.js.map +1 -0
- package/skinny/dist/collection-utils-47e89cbe.js +238 -0
- package/skinny/dist/collection-utils-47e89cbe.js.map +1 -0
- package/skinny/dist/collection-utils-4dae6efa.js +292 -0
- package/skinny/dist/collection-utils-4dae6efa.js.map +1 -0
- package/skinny/dist/collection-utils-57c273dc.js +238 -0
- package/skinny/dist/collection-utils-57c273dc.js.map +1 -0
- package/skinny/dist/collection-utils-57ec40f9.js +292 -0
- package/skinny/dist/collection-utils-57ec40f9.js.map +1 -0
- package/skinny/dist/collection-utils-96cde83c.js +238 -0
- package/skinny/dist/collection-utils-96cde83c.js.map +1 -0
- package/skinny/dist/collection-utils-b0b8f30e.js +291 -0
- package/skinny/dist/collection-utils-b0b8f30e.js.map +1 -0
- package/skinny/dist/common-182a0b0c.js +201 -0
- package/skinny/dist/common-182a0b0c.js.map +1 -0
- package/skinny/dist/index.d.ts +1 -0
- package/skinny/dist/index.js +68 -45
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/button/index.js +5 -5
- package/skinny/dist/plume/button/index.js.map +1 -1
- package/skinny/dist/plume/checkbox/index.js +6 -6
- package/skinny/dist/plume/checkbox/index.js.map +1 -1
- package/skinny/dist/plume/menu/index.js +11 -11
- package/skinny/dist/plume/menu/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/index.js +6 -6
- package/skinny/dist/plume/menu-button/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/menu-trigger.d.ts +1 -1
- package/skinny/dist/plume/select/index.d.ts +1 -0
- package/skinny/dist/plume/select/index.js +12 -12
- package/skinny/dist/plume/select/index.js.map +1 -1
- package/skinny/dist/plume/switch/index.js +6 -6
- package/skinny/dist/plume/switch/index.js.map +1 -1
- package/skinny/dist/plume/text-input/index.js +5 -5
- package/skinny/dist/plume/text-input/index.js.map +1 -1
- package/skinny/dist/plume/triggered-overlay/index.d.ts +1 -0
- package/skinny/dist/plume/triggered-overlay/index.js +8 -7
- package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
- package/skinny/dist/plume-utils-5c413fd1.js +35 -0
- package/skinny/dist/plume-utils-5c413fd1.js.map +1 -0
- package/skinny/dist/plume-utils-623b91cc.js +35 -0
- package/skinny/dist/plume-utils-623b91cc.js.map +1 -0
- package/skinny/dist/props-utils-4633caf6.js +8 -0
- package/skinny/dist/props-utils-4633caf6.js.map +1 -0
- package/skinny/dist/props-utils-5c0ad25a.js +59 -0
- package/skinny/dist/props-utils-5c0ad25a.js.map +1 -0
- package/skinny/dist/props-utils-754f655a.js +39 -0
- package/skinny/dist/props-utils-754f655a.js.map +1 -0
- package/skinny/dist/props-utils-b2ad4997.js +8 -0
- package/skinny/dist/props-utils-b2ad4997.js.map +1 -0
- package/skinny/dist/props-utils-c632595f.js +59 -0
- package/skinny/dist/props-utils-c632595f.js.map +1 -0
- package/skinny/dist/props-utils-fd5f444e.js +59 -0
- package/skinny/dist/props-utils-fd5f444e.js.map +1 -0
- package/skinny/dist/react-utils-118d8539.js +190 -0
- package/skinny/dist/react-utils-118d8539.js.map +1 -0
- package/skinny/dist/react-utils-2a2fd6c9.js +339 -0
- package/skinny/dist/react-utils-2a2fd6c9.js.map +1 -0
- package/skinny/dist/react-utils-2d70bbbe.js +172 -0
- package/skinny/dist/react-utils-2d70bbbe.js.map +1 -0
- package/skinny/dist/react-utils-35cb2a4e.js +201 -0
- package/skinny/dist/react-utils-35cb2a4e.js.map +1 -0
- package/skinny/dist/react-utils-675565b4.js +334 -0
- package/skinny/dist/react-utils-675565b4.js.map +1 -0
- package/skinny/dist/render/PlasmicImg/index.js +3 -3
- package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
- package/skinny/dist/render/PlasmicImg.d.ts +62 -0
- package/skinny/dist/render/triggers.d.ts +4 -4
- package/skinny/dist/ssr-64e38713.js +108 -0
- package/skinny/dist/ssr-64e38713.js.map +1 -0
- package/skinny/dist/ssr-902d1292.js +105 -0
- package/skinny/dist/ssr-902d1292.js.map +1 -0
- package/skinny/dist/ssr-a8081074.js +108 -0
- package/skinny/dist/ssr-a8081074.js.map +1 -0
- package/skinny/dist/ssr-d2fd94f2.js +31 -0
- package/skinny/dist/ssr-d2fd94f2.js.map +1 -0
- package/skinny/dist/states/helpers.d.ts +9 -0
- package/skinny/dist/states/index.d.ts +7 -7
- package/skinny/dist/stories/UseDollarState.stories.d.ts +41 -0
- package/skinny/dist/tslib.es6-00014098.js +148 -0
- package/skinny/dist/tslib.es6-00014098.js.map +1 -0
- package/skinny/dist/tslib.es6-73236e8e.js +141 -0
- package/skinny/dist/tslib.es6-73236e8e.js.map +1 -0
- package/README +0 -8
|
@@ -25,7 +25,7 @@ var listbox = require('@react-aria/listbox');
|
|
|
25
25
|
var select$1 = require('@react-stately/select');
|
|
26
26
|
var _switch = require('@react-aria/switch');
|
|
27
27
|
var overlays = require('@react-aria/overlays');
|
|
28
|
-
var
|
|
28
|
+
var _get = _interopDefault(require('dlv'));
|
|
29
29
|
var dset = require('dset');
|
|
30
30
|
|
|
31
31
|
function _extends() {
|
|
@@ -1206,6 +1206,96 @@ function isInternalHref(href) {
|
|
|
1206
1206
|
return /^\/(?!\/)/.test(href);
|
|
1207
1207
|
}
|
|
1208
1208
|
|
|
1209
|
+
var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
1210
|
+
|
|
1211
|
+
function isIterable(val) {
|
|
1212
|
+
return val != null && typeof val[Symbol.iterator] === "function";
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
function genTranslatableString(elt) {
|
|
1216
|
+
var components = {};
|
|
1217
|
+
var componentsCount = 0;
|
|
1218
|
+
|
|
1219
|
+
var getText = function getText(node) {
|
|
1220
|
+
if (!node) {
|
|
1221
|
+
return "";
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
|
|
1225
|
+
return node.toString();
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
if (typeof node !== "object") {
|
|
1229
|
+
return "";
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
if (Array.isArray(node) || isIterable(node)) {
|
|
1233
|
+
return Array.from(node).map(function (child) {
|
|
1234
|
+
return getText(child);
|
|
1235
|
+
}).filter(function (child) {
|
|
1236
|
+
return !!child;
|
|
1237
|
+
}).join("");
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
|
|
1241
|
+
var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
|
|
1242
|
+
return getText(child);
|
|
1243
|
+
}).filter(function (child) {
|
|
1244
|
+
return !!child;
|
|
1245
|
+
}).join("");
|
|
1246
|
+
|
|
1247
|
+
if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
|
|
1248
|
+
return contents;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
var componentId = componentsCount + 1;
|
|
1252
|
+
componentsCount++;
|
|
1253
|
+
components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
|
|
1254
|
+
key: componentId,
|
|
1255
|
+
children: undefined
|
|
1256
|
+
}) : node;
|
|
1257
|
+
return "<" + componentId + ">" + contents + "</" + componentId + ">";
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
var str = getText(elt);
|
|
1261
|
+
return {
|
|
1262
|
+
str: str,
|
|
1263
|
+
components: components,
|
|
1264
|
+
componentsCount: componentsCount
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
function Trans(_ref) {
|
|
1268
|
+
var children = _ref.children;
|
|
1269
|
+
|
|
1270
|
+
var _t = React__default.useContext(PlasmicTranslatorContext);
|
|
1271
|
+
|
|
1272
|
+
if (!_t) {
|
|
1273
|
+
warnNoTranslationFunctionAtMostOnce();
|
|
1274
|
+
return children;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
var _genTranslatableStrin = genTranslatableString(children),
|
|
1278
|
+
str = _genTranslatableStrin.str,
|
|
1279
|
+
components = _genTranslatableStrin.components,
|
|
1280
|
+
componentsCount = _genTranslatableStrin.componentsCount;
|
|
1281
|
+
|
|
1282
|
+
return _t(str, componentsCount > 0 ? {
|
|
1283
|
+
components: components
|
|
1284
|
+
} : undefined);
|
|
1285
|
+
}
|
|
1286
|
+
var hasWarned = false;
|
|
1287
|
+
|
|
1288
|
+
function warnNoTranslationFunctionAtMostOnce() {
|
|
1289
|
+
if (!hasWarned) {
|
|
1290
|
+
console.warn("Using Plasmic Translation but no translation function has been provided");
|
|
1291
|
+
hasWarned = true;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
function hasKey(v, key) {
|
|
1296
|
+
return typeof v === "object" && v !== null && key in v;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1209
1299
|
function PlasmicSlot(props) {
|
|
1210
1300
|
return renderPlasmicSlot(props);
|
|
1211
1301
|
}
|
|
@@ -1249,7 +1339,8 @@ function renderPlasmicSlot(opts) {
|
|
|
1249
1339
|
|
|
1250
1340
|
function maybeAsString(node) {
|
|
1251
1341
|
// Unwrap fragments
|
|
1252
|
-
if (React.isValidElement(node) &&
|
|
1342
|
+
if (React.isValidElement(node) && ( // Fragment and Trans don't render DOM elements
|
|
1343
|
+
node.type === React.Fragment || node.type === Trans)) {
|
|
1253
1344
|
return maybeAsString(node.props.children);
|
|
1254
1345
|
}
|
|
1255
1346
|
|
|
@@ -1360,96 +1451,6 @@ function createUseScreenVariants(isMulti, screenQueries) {
|
|
|
1360
1451
|
};
|
|
1361
1452
|
}
|
|
1362
1453
|
|
|
1363
|
-
var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
|
|
1364
|
-
|
|
1365
|
-
function isIterable(val) {
|
|
1366
|
-
return val != null && typeof val[Symbol.iterator] === "function";
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
function genTranslatableString(elt) {
|
|
1370
|
-
var components = {};
|
|
1371
|
-
var componentsCount = 0;
|
|
1372
|
-
|
|
1373
|
-
var getText = function getText(node) {
|
|
1374
|
-
if (!node) {
|
|
1375
|
-
return "";
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
|
|
1379
|
-
return node.toString();
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
if (typeof node !== "object") {
|
|
1383
|
-
return "";
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
if (Array.isArray(node) || isIterable(node)) {
|
|
1387
|
-
return Array.from(node).map(function (child) {
|
|
1388
|
-
return getText(child);
|
|
1389
|
-
}).filter(function (child) {
|
|
1390
|
-
return !!child;
|
|
1391
|
-
}).join("");
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
|
|
1395
|
-
var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
|
|
1396
|
-
return getText(child);
|
|
1397
|
-
}).filter(function (child) {
|
|
1398
|
-
return !!child;
|
|
1399
|
-
}).join("");
|
|
1400
|
-
|
|
1401
|
-
if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
|
|
1402
|
-
return contents;
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
var componentId = componentsCount + 1;
|
|
1406
|
-
componentsCount++;
|
|
1407
|
-
components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
|
|
1408
|
-
key: componentId,
|
|
1409
|
-
children: undefined
|
|
1410
|
-
}) : node;
|
|
1411
|
-
return "<" + componentId + ">" + contents + "</" + componentId + ">";
|
|
1412
|
-
};
|
|
1413
|
-
|
|
1414
|
-
var str = getText(elt);
|
|
1415
|
-
return {
|
|
1416
|
-
str: str,
|
|
1417
|
-
components: components,
|
|
1418
|
-
componentsCount: componentsCount
|
|
1419
|
-
};
|
|
1420
|
-
}
|
|
1421
|
-
function Trans(_ref) {
|
|
1422
|
-
var children = _ref.children;
|
|
1423
|
-
|
|
1424
|
-
var _t = React__default.useContext(PlasmicTranslatorContext);
|
|
1425
|
-
|
|
1426
|
-
if (!_t) {
|
|
1427
|
-
warnNoTranslationFunctionAtMostOnce();
|
|
1428
|
-
return children;
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
var _genTranslatableStrin = genTranslatableString(children),
|
|
1432
|
-
str = _genTranslatableStrin.str,
|
|
1433
|
-
components = _genTranslatableStrin.components,
|
|
1434
|
-
componentsCount = _genTranslatableStrin.componentsCount;
|
|
1435
|
-
|
|
1436
|
-
return _t(str, componentsCount > 0 ? {
|
|
1437
|
-
components: components
|
|
1438
|
-
} : undefined);
|
|
1439
|
-
}
|
|
1440
|
-
var hasWarned = false;
|
|
1441
|
-
|
|
1442
|
-
function warnNoTranslationFunctionAtMostOnce() {
|
|
1443
|
-
if (!hasWarned) {
|
|
1444
|
-
console.warn("Using Plasmic Translation but no translation function has been provided");
|
|
1445
|
-
hasWarned = true;
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
function hasKey(v, key) {
|
|
1450
|
-
return typeof v === "object" && v !== null && key in v;
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
1454
|
var PlasmicRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
1454
1455
|
function PlasmicRootProvider(props) {
|
|
1455
1456
|
var platform = props.platform,
|
|
@@ -3124,40 +3125,24 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
|
|
|
3124
3125
|
};
|
|
3125
3126
|
}
|
|
3126
3127
|
|
|
3127
|
-
|
|
3128
|
-
function
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
for (var _iterator = _createForOfIteratorHelperLoose(list), _step; !(_step = _iterator()).done;) {
|
|
3132
|
-
var val = _step.value;
|
|
3133
|
-
keyedObject[keyFunc(val)] = val;
|
|
3134
|
-
}
|
|
3135
|
-
|
|
3136
|
-
return keyedObject;
|
|
3128
|
+
function generateStateOnChangeProp($state, stateName, dataReps) {
|
|
3129
|
+
return function (val, path) {
|
|
3130
|
+
return dset.dset($state, [stateName].concat(dataReps, path), val);
|
|
3131
|
+
};
|
|
3137
3132
|
}
|
|
3133
|
+
/**
|
|
3134
|
+
* This function generate the state value prop for repeated states
|
|
3135
|
+
* Example:
|
|
3136
|
+
* - parent[][].counter[].count
|
|
3137
|
+
* We need to pass `parent[index1][index2].counter to the child component
|
|
3138
|
+
*/
|
|
3138
3139
|
|
|
3139
|
-
function
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
if (parts2.length === 0) {
|
|
3144
|
-
return $state;
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
var existing = get($state, parts2);
|
|
3148
|
-
|
|
3149
|
-
if (existing) {
|
|
3150
|
-
return existing;
|
|
3151
|
-
}
|
|
3152
|
-
|
|
3153
|
-
var newObj = {};
|
|
3154
|
-
dset.dset($state, parts2, newObj);
|
|
3155
|
-
return newObj;
|
|
3140
|
+
function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
3141
|
+
) {
|
|
3142
|
+
return _get($state, path);
|
|
3156
3143
|
}
|
|
3157
3144
|
|
|
3158
|
-
|
|
3159
|
-
return !!React__default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current;
|
|
3160
|
-
}
|
|
3145
|
+
var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
|
|
3161
3146
|
|
|
3162
3147
|
function shallowEqual(a1, a2) {
|
|
3163
3148
|
if (a1.length !== a2.length) {
|
|
@@ -3173,289 +3158,441 @@ function shallowEqual(a1, a2) {
|
|
|
3173
3158
|
return true;
|
|
3174
3159
|
}
|
|
3175
3160
|
|
|
3176
|
-
function
|
|
3177
|
-
|
|
3161
|
+
var isNum = function isNum(value) {
|
|
3162
|
+
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
3163
|
+
};
|
|
3164
|
+
|
|
3165
|
+
function mkProxy(specs, maybeHandlers) {
|
|
3166
|
+
var handlers = maybeHandlers != null ? maybeHandlers : function () {
|
|
3178
3167
|
return {
|
|
3179
|
-
|
|
3180
|
-
return [
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
spec.initFunc ? UNINITIALIZED : spec.initVal];
|
|
3186
|
-
})),
|
|
3187
|
-
initStateValues: Object.fromEntries(specs.filter(function (spec) {
|
|
3188
|
-
return !spec.initFunc;
|
|
3189
|
-
}).map(function (spec) {
|
|
3190
|
-
return [spec.path, spec.initVal];
|
|
3191
|
-
})),
|
|
3192
|
-
initStateDeps: {},
|
|
3193
|
-
fireOnChange: {}
|
|
3168
|
+
get: function get(target, property) {
|
|
3169
|
+
return target[property];
|
|
3170
|
+
},
|
|
3171
|
+
set: function set(target, property, value) {
|
|
3172
|
+
return (target[property] = value) || true;
|
|
3173
|
+
}
|
|
3194
3174
|
};
|
|
3195
|
-
}),
|
|
3196
|
-
_$$state = _React$useState[0],
|
|
3197
|
-
set$$State = _React$useState[1]; // We have a weird scheme here to reduce the number of state updates.
|
|
3198
|
-
// Whenever user does a $state get() or set(), we may end up initializing
|
|
3199
|
-
// a bunch of values. We don't want to call set$$State() a bunch of times.
|
|
3200
|
-
// Instead, we will fork as we need to, and call set$$State() at the end of
|
|
3201
|
-
// the hook and at the end of get() / set() as appropriate.
|
|
3202
|
-
// $$state here is going to be copied-on-write; once copied, it will
|
|
3203
|
-
// be directly mutated. Since $state will always be directly proxying $$state,
|
|
3204
|
-
// that means you can "read what you wrote": after $state.count = $state.count + 1,
|
|
3205
|
-
// if you read $state.count again, it will reflect the latest value.
|
|
3206
|
-
//
|
|
3207
|
-
// There are three places where we might actually call set$$State():
|
|
3208
|
-
// 1. At the end of a "top-level" get(): we may have ended up initializing
|
|
3209
|
-
// some state values.
|
|
3210
|
-
// 2. At the end of a "top-level" set(): we mutated this value, but also
|
|
3211
|
-
// may have reset some other state values that depended on this one.
|
|
3212
|
-
// 3. At the end of the hook, where we compare the new initial value with
|
|
3213
|
-
// the previous initial value.
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
var $$state = _extends({}, _$$state);
|
|
3217
|
-
|
|
3218
|
-
var dirtyFields = {
|
|
3219
|
-
stateValues: false,
|
|
3220
|
-
initStateValues: false,
|
|
3221
|
-
initStateDeps: false,
|
|
3222
|
-
fireOnChange: false
|
|
3223
3175
|
};
|
|
3224
3176
|
|
|
3225
|
-
function
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3177
|
+
var getNextParts = function getNextParts(currPath) {
|
|
3178
|
+
return Object.fromEntries(Object.values(specs).filter(function (spec) {
|
|
3179
|
+
return shallowEqual(currPath.map(function (p) {
|
|
3180
|
+
return isNum(p) ? "[]" : p;
|
|
3181
|
+
}), spec.path.slice(0, currPath.length));
|
|
3182
|
+
}).map(function (spec) {
|
|
3183
|
+
var nextPart = spec.path[currPath.length];
|
|
3184
|
+
|
|
3185
|
+
if (spec.path.length === currPath.length + 1) {
|
|
3186
|
+
return [nextPart, {
|
|
3187
|
+
isLast: true,
|
|
3188
|
+
specKey: spec.pathStr
|
|
3189
|
+
}];
|
|
3190
|
+
} else {
|
|
3191
|
+
return [nextPart, {
|
|
3192
|
+
isLast: false,
|
|
3193
|
+
specKey: spec.pathStr
|
|
3194
|
+
}];
|
|
3195
|
+
}
|
|
3196
|
+
}));
|
|
3197
|
+
};
|
|
3198
|
+
/**
|
|
3199
|
+
* We use this function when we're setting a value in the middle of the state path.
|
|
3200
|
+
* We can't just set the value, because we need to keep the proxy properties, so
|
|
3201
|
+
* we use the specs to walk through the object and just set the value in the end of the path
|
|
3202
|
+
**/
|
|
3239
3203
|
|
|
3240
|
-
for (var _i = 0, _Object$entries = Object.entries($$state.initStateDeps); _i < _Object$entries.length; _i++) {
|
|
3241
|
-
var _Object$entries$_i = _Object$entries[_i],
|
|
3242
|
-
key = _Object$entries$_i[0],
|
|
3243
|
-
deps = _Object$entries$_i[1];
|
|
3244
3204
|
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3205
|
+
var cloneValue = function cloneValue(target, currPath, value) {
|
|
3206
|
+
if (typeof value !== "object") {
|
|
3207
|
+
return;
|
|
3248
3208
|
}
|
|
3249
3209
|
|
|
3250
|
-
var
|
|
3210
|
+
var nextParts = getNextParts(currPath);
|
|
3251
3211
|
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3212
|
+
for (var _i = 0, _Object$entries = Object.entries(nextParts); _i < _Object$entries.length; _i++) {
|
|
3213
|
+
var _Object$entries$_i = _Object$entries[_i],
|
|
3214
|
+
nextPart = _Object$entries$_i[0],
|
|
3215
|
+
_Object$entries$_i$ = _Object$entries$_i[1],
|
|
3216
|
+
isLast = _Object$entries$_i$.isLast,
|
|
3217
|
+
specKey = _Object$entries$_i$.specKey;
|
|
3218
|
+
|
|
3219
|
+
if (nextPart === "[]" && Array.isArray(value)) {
|
|
3220
|
+
for (var i = 0; i < value.length; i++) {
|
|
3221
|
+
cloneValue(target[i], [].concat(currPath, [i]), value[i]);
|
|
3222
|
+
}
|
|
3223
|
+
} else if (nextPart in value) {
|
|
3224
|
+
if (isLast) {
|
|
3225
|
+
var _handlers$set, _handlers;
|
|
3226
|
+
|
|
3227
|
+
handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
|
|
3228
|
+
specKey: specKey,
|
|
3229
|
+
path: [].concat(currPath, [nextPart])
|
|
3230
|
+
})).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
|
|
3231
|
+
} else {
|
|
3232
|
+
cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
|
|
3233
|
+
}
|
|
3267
3234
|
}
|
|
3268
3235
|
}
|
|
3269
|
-
}
|
|
3236
|
+
};
|
|
3270
3237
|
|
|
3271
|
-
function
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3238
|
+
var rec = function rec(currPath) {
|
|
3239
|
+
var nextParts = getNextParts(currPath);
|
|
3240
|
+
return new Proxy("[]" in nextParts ? [] : {}, {
|
|
3241
|
+
deleteProperty: function deleteProperty(target, property) {
|
|
3242
|
+
if ("[]" in nextParts && isNum(property)) {
|
|
3243
|
+
var _handlers$deletePrope, _handlers2;
|
|
3244
|
+
|
|
3245
|
+
delete target[property];
|
|
3246
|
+
handlers == null ? void 0 : (_handlers$deletePrope = (_handlers2 = handlers({
|
|
3247
|
+
path: [].concat(currPath, [+property]),
|
|
3248
|
+
specKey: nextParts["[]"].specKey
|
|
3249
|
+
})).deleteProperty) == null ? void 0 : _handlers$deletePrope.call(_handlers2, target, property);
|
|
3250
|
+
} else {
|
|
3251
|
+
throw new Error("You can't delete a non-repeated property in the middle of the path");
|
|
3252
|
+
}
|
|
3278
3253
|
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3254
|
+
return true;
|
|
3255
|
+
},
|
|
3256
|
+
get: function get(target, property, receiver) {
|
|
3257
|
+
if ("[]" in nextParts && isNum(property)) {
|
|
3258
|
+
if (!(property in target)) {
|
|
3259
|
+
target[property] = rec([].concat(currPath, [+property]));
|
|
3260
|
+
}
|
|
3261
|
+
} else if (property in nextParts) {
|
|
3262
|
+
if (nextParts[property].isLast) {
|
|
3263
|
+
var _handlers$get, _handlers3;
|
|
3264
|
+
|
|
3265
|
+
return target[property] = handlers == null ? void 0 : (_handlers$get = (_handlers3 = handlers({
|
|
3266
|
+
path: [].concat(currPath, [property]),
|
|
3267
|
+
specKey: nextParts[property].specKey
|
|
3268
|
+
})).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
|
|
3269
|
+
} else if (!(property in target)) {
|
|
3270
|
+
target[property] = rec([].concat(currPath, [property]));
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3286
3273
|
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3274
|
+
return target[property];
|
|
3275
|
+
},
|
|
3276
|
+
set: function set(target, property, value, receiver) {
|
|
3277
|
+
if ("[]" in nextParts && isNum(property)) {
|
|
3278
|
+
if (!(property in target)) {
|
|
3279
|
+
target[property] = rec([].concat(currPath, [+property]));
|
|
3280
|
+
}
|
|
3281
|
+
} else if (property in nextParts) {
|
|
3282
|
+
if (nextParts[property].isLast) {
|
|
3283
|
+
var _handlers$set2, _handlers$set3, _handlers4;
|
|
3284
|
+
|
|
3285
|
+
target[property] = value;
|
|
3286
|
+
return (_handlers$set2 = (_handlers$set3 = (_handlers4 = handlers({
|
|
3287
|
+
path: [].concat(currPath, [property]),
|
|
3288
|
+
specKey: nextParts[property].specKey
|
|
3289
|
+
})).set) == null ? void 0 : _handlers$set3.call(_handlers4, target, property, value, receiver)) != null ? _handlers$set2 : false;
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3295
3292
|
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
}
|
|
3293
|
+
if (property === "registerInitFunc") {
|
|
3294
|
+
target[property] = value;
|
|
3295
|
+
} else if (typeof value === "object") {
|
|
3296
|
+
cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
|
|
3297
|
+
}
|
|
3302
3298
|
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
return keyBy(specs, function (spec) {
|
|
3306
|
-
return spec.path;
|
|
3299
|
+
return true;
|
|
3300
|
+
}
|
|
3307
3301
|
});
|
|
3308
|
-
}
|
|
3309
|
-
var stateAccessStack = [{}];
|
|
3310
|
-
var $props = props;
|
|
3311
|
-
/**
|
|
3312
|
-
* Runs spec.initFunc, keeping track of the state accesses
|
|
3313
|
-
* that occurred while running it
|
|
3314
|
-
*/
|
|
3315
|
-
|
|
3316
|
-
function trackedInit(spec) {
|
|
3317
|
-
var _$$state$initStateDep;
|
|
3302
|
+
};
|
|
3318
3303
|
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
var res = spec.initFunc($props, $state);
|
|
3322
|
-
var deps = Object.keys(stateAccess);
|
|
3304
|
+
return rec([]);
|
|
3305
|
+
}
|
|
3323
3306
|
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3307
|
+
function cloneProxy(specs, states, obj) {
|
|
3308
|
+
var newObj = mkProxy(specs);
|
|
3309
|
+
Object.values(states).forEach(function (_ref) {
|
|
3310
|
+
var path = _ref.path;
|
|
3327
3311
|
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
* Resets the value for this state
|
|
3333
|
-
*/
|
|
3312
|
+
dset.dset(newObj, path, _get(obj, path));
|
|
3313
|
+
});
|
|
3314
|
+
return newObj;
|
|
3315
|
+
}
|
|
3334
3316
|
|
|
3317
|
+
function saveState(state, states) {
|
|
3318
|
+
states[JSON.stringify(state.path)] = state;
|
|
3319
|
+
}
|
|
3335
3320
|
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
var initValue = trackedInit(spec);
|
|
3321
|
+
function hasState(state, states) {
|
|
3322
|
+
return JSON.stringify(state.path) in states;
|
|
3323
|
+
}
|
|
3340
3324
|
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3325
|
+
var transformPathStringToObj = function transformPathStringToObj(str) {
|
|
3326
|
+
// "c[][]" -> ["c", "[]", "[]"]
|
|
3327
|
+
var splitStatePathPart = function splitStatePathPart(state) {
|
|
3328
|
+
return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
|
|
3329
|
+
};
|
|
3344
3330
|
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
}
|
|
3331
|
+
return str.split(".").flatMap(splitStatePathPart);
|
|
3332
|
+
};
|
|
3348
3333
|
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3334
|
+
function useVanillaDollarState(_specs, props) {
|
|
3335
|
+
var forceRender = React__default.useState(0)[1];
|
|
3336
|
+
var $$state = React__default.useMemo(function () {
|
|
3337
|
+
var specs = Object.fromEntries(_specs.map(function (_ref2) {
|
|
3338
|
+
var pathStr = _ref2.path,
|
|
3339
|
+
spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
|
|
3340
|
+
|
|
3341
|
+
return [pathStr, _extends({}, spec, {
|
|
3342
|
+
pathStr: pathStr,
|
|
3343
|
+
path: transformPathStringToObj(pathStr),
|
|
3344
|
+
isRepeated: pathStr.split(".").some(function (part) {
|
|
3345
|
+
return part.endsWith("[]");
|
|
3346
|
+
})
|
|
3347
|
+
})];
|
|
3348
|
+
}));
|
|
3349
|
+
return {
|
|
3350
|
+
stateValues: mkProxy(specs),
|
|
3351
|
+
initStateDeps: {},
|
|
3352
|
+
initStateValues: mkProxy(specs),
|
|
3353
|
+
states: {},
|
|
3354
|
+
specs: specs
|
|
3355
|
+
};
|
|
3356
|
+
}, []);
|
|
3357
|
+
var $state = Object.assign(mkProxy($$state.specs, function (state) {
|
|
3358
|
+
return {
|
|
3359
|
+
deleteProperty: function deleteProperty(_target, _property) {
|
|
3360
|
+
var prefixPath = state.path;
|
|
3353
3361
|
|
|
3362
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
|
|
3363
|
+
var _Object$entries2$_i = _Object$entries2[_i2],
|
|
3364
|
+
key = _Object$entries2$_i[0],
|
|
3365
|
+
existingState = _Object$entries2$_i[1];
|
|
3354
3366
|
|
|
3355
|
-
|
|
3356
|
-
|
|
3367
|
+
if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
|
|
3368
|
+
delete $$state.states[key];
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3357
3371
|
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3372
|
+
forceRender(function (r) {
|
|
3373
|
+
return r + 1;
|
|
3374
|
+
});
|
|
3375
|
+
return true;
|
|
3376
|
+
},
|
|
3377
|
+
get: function get(_target, _property) {
|
|
3378
|
+
var spec = $$state.specs[state.specKey];
|
|
3363
3379
|
|
|
3364
|
-
Object.defineProperty(obj, name, {
|
|
3365
|
-
get: function get() {
|
|
3366
3380
|
if (spec.valueProp) {
|
|
3367
|
-
|
|
3381
|
+
if (!spec.isRepeated) {
|
|
3382
|
+
return props[spec.valueProp];
|
|
3383
|
+
} else {
|
|
3384
|
+
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3385
|
+
}
|
|
3368
3386
|
}
|
|
3369
3387
|
|
|
3370
|
-
|
|
3371
|
-
|
|
3388
|
+
if (!hasState(state, $$state.states)) {
|
|
3389
|
+
var _spec$initVal;
|
|
3372
3390
|
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
} // Record that this field had just been accessed; for
|
|
3377
|
-
// trackInit() to know what fields were used to compute
|
|
3378
|
-
// the init value
|
|
3391
|
+
saveState(state, $$state.states);
|
|
3392
|
+
|
|
3393
|
+
dset.dset($$state.stateValues, state.path, spec.initFunc ? UNINITIALIZED : (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
|
|
3379
3394
|
|
|
3395
|
+
var deps = spec.initFunc ? fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states) : {};
|
|
3380
3396
|
|
|
3381
|
-
|
|
3382
|
-
accessLevel -= 1;
|
|
3397
|
+
dset.dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
|
|
3383
3398
|
|
|
3384
|
-
|
|
3385
|
-
|
|
3399
|
+
$$state.initStateDeps = _extends({}, $$state.initStateDeps, deps);
|
|
3400
|
+
forceRender(function (r) {
|
|
3401
|
+
return r + 1;
|
|
3402
|
+
});
|
|
3403
|
+
return spec.initFunc ? spec.initFunc(props, $state) : spec.initVal;
|
|
3386
3404
|
}
|
|
3387
3405
|
|
|
3388
|
-
return
|
|
3406
|
+
return _get($$state.stateValues, state.path);
|
|
3389
3407
|
},
|
|
3390
|
-
set: function set(newValue) {
|
|
3391
|
-
|
|
3408
|
+
set: function set(_target, _property, newValue) {
|
|
3409
|
+
if (newValue !== _get($$state.stateValues, state.path)) {
|
|
3410
|
+
saveState(state, $$state.states);
|
|
3411
|
+
|
|
3412
|
+
dset.dset($$state.stateValues, state.path, newValue);
|
|
3413
|
+
|
|
3414
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries($$state.initStateDeps); _i3 < _Object$entries3.length; _i3++) {
|
|
3415
|
+
var _Object$entries3$_i = _Object$entries3[_i3],
|
|
3416
|
+
key = _Object$entries3$_i[0],
|
|
3417
|
+
deps = _Object$entries3$_i[1];
|
|
3392
3418
|
|
|
3393
|
-
|
|
3394
|
-
|
|
3419
|
+
if (deps.includes(JSON.stringify(state.path))) {
|
|
3420
|
+
dset.dset($$state.stateValues, JSON.parse(key), UNINITIALIZED);
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
var newDeps = fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states);
|
|
3425
|
+
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3426
|
+
forceRender(function (r) {
|
|
3427
|
+
return r + 1;
|
|
3428
|
+
});
|
|
3395
3429
|
}
|
|
3396
3430
|
|
|
3397
|
-
|
|
3431
|
+
var spec = $$state.specs[state.specKey];
|
|
3398
3432
|
|
|
3399
|
-
if (
|
|
3400
|
-
|
|
3433
|
+
if (spec.onChangeProp) {
|
|
3434
|
+
var _props$spec$onChangeP;
|
|
3435
|
+
|
|
3436
|
+
(_props$spec$onChangeP = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP.call(props, newValue, state.path);
|
|
3401
3437
|
}
|
|
3402
|
-
}
|
|
3403
|
-
});
|
|
3404
|
-
};
|
|
3405
3438
|
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3439
|
+
return true;
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
}), {
|
|
3443
|
+
registerInitFunc: function registerInitFunc(pathStr, f) {
|
|
3444
|
+
if (Object.values($$state.states).filter(function (_ref3) {
|
|
3445
|
+
var specKey = _ref3.specKey;
|
|
3446
|
+
return specKey === pathStr;
|
|
3447
|
+
}).some(function (_ref4) {
|
|
3448
|
+
var path = _ref4.path;
|
|
3449
|
+
return _get($$state.stateValues, path) !== f(props, $state);
|
|
3450
|
+
})) {
|
|
3451
|
+
$$state.specs[pathStr] = _extends({}, $$state.specs[pathStr], {
|
|
3452
|
+
initFunc: f
|
|
3453
|
+
});
|
|
3454
|
+
forceRender(function (r) {
|
|
3455
|
+
return r + 1;
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
}); // For each spec with an initFunc, evaluate it and see if
|
|
3409
3460
|
// the init value has changed. If so, reset its state.
|
|
3410
3461
|
|
|
3462
|
+
var newStateValues = undefined;
|
|
3463
|
+
var resetSpecs = [];
|
|
3411
3464
|
|
|
3412
|
-
for (var
|
|
3413
|
-
var
|
|
3465
|
+
for (var _i4 = 0, _Object$values = Object.values($$state.states); _i4 < _Object$values.length; _i4++) {
|
|
3466
|
+
var _Object$values$_i = _Object$values[_i4],
|
|
3467
|
+
path = _Object$values$_i.path,
|
|
3468
|
+
specKey = _Object$values$_i.specKey;
|
|
3469
|
+
var spec = $$state.specs[specKey];
|
|
3414
3470
|
|
|
3415
3471
|
if (spec.initFunc) {
|
|
3416
|
-
var newInit = spec.initFunc(
|
|
3472
|
+
var newInit = spec.initFunc(props, $state);
|
|
3417
3473
|
|
|
3418
|
-
if (newInit !== $$state.initStateValues
|
|
3419
|
-
console.log("init changed for " +
|
|
3420
|
-
|
|
3421
|
-
|
|
3474
|
+
if (newInit !== _get($$state.initStateValues, path)) {
|
|
3475
|
+
console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
|
|
3476
|
+
resetSpecs.push({
|
|
3477
|
+
path: path,
|
|
3478
|
+
specKey: specKey
|
|
3479
|
+
});
|
|
3422
3480
|
|
|
3423
|
-
if (
|
|
3424
|
-
|
|
3481
|
+
if (!newStateValues) {
|
|
3482
|
+
newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
|
|
3425
3483
|
}
|
|
3484
|
+
|
|
3485
|
+
dset.dset(newStateValues, path, UNINITIALIZED);
|
|
3426
3486
|
}
|
|
3427
3487
|
}
|
|
3428
3488
|
}
|
|
3429
3489
|
|
|
3430
|
-
var fireOnChange = $$state.fireOnChange;
|
|
3431
3490
|
React__default.useLayoutEffect(function () {
|
|
3432
|
-
if (
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
var spec = specByPath[path];
|
|
3491
|
+
if (newStateValues !== undefined) {
|
|
3492
|
+
var newDeps = fillUninitializedStateValues($$state.specs, props, newStateValues, $$state.states);
|
|
3493
|
+
var initStateValues = cloneProxy($$state.specs, $$state.states, $$state.initStateValues);
|
|
3494
|
+
resetSpecs.forEach(function (_ref5) {
|
|
3495
|
+
var path = _ref5.path;
|
|
3438
3496
|
|
|
3439
|
-
|
|
3440
|
-
|
|
3497
|
+
dset.dset(initStateValues, path, _get(newStateValues, path));
|
|
3498
|
+
});
|
|
3499
|
+
$$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
|
|
3500
|
+
$$state.initStateValues = initStateValues;
|
|
3501
|
+
$$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
|
|
3502
|
+
forceRender(function (r) {
|
|
3503
|
+
return r + 1;
|
|
3504
|
+
});
|
|
3505
|
+
|
|
3506
|
+
for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
|
|
3507
|
+
var _step$value = _step.value,
|
|
3508
|
+
_path = _step$value.path,
|
|
3509
|
+
_specKey = _step$value.specKey;
|
|
3510
|
+
var _spec = $$state.specs[_specKey];
|
|
3511
|
+
|
|
3512
|
+
if (_spec.onChangeProp) {
|
|
3513
|
+
var _props$_spec$onChange;
|
|
3441
3514
|
|
|
3442
|
-
(
|
|
3515
|
+
console.log("Firing onChange for reset init value: " + _spec.path, _get(newStateValues, _path));
|
|
3516
|
+
(_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
|
|
3443
3517
|
}
|
|
3444
3518
|
}
|
|
3445
|
-
|
|
3446
|
-
set$$State(function (prev) {
|
|
3447
|
-
return _extends({}, prev, {
|
|
3448
|
-
fireOnChange: {}
|
|
3449
|
-
});
|
|
3450
|
-
});
|
|
3451
3519
|
}
|
|
3452
|
-
}, [
|
|
3520
|
+
}, [newStateValues, props, resetSpecs, $$state.specs]);
|
|
3521
|
+
/* *
|
|
3522
|
+
* Initialize all known states. (we need to do it for repeated states
|
|
3523
|
+
* because they're created only after the first get/set operation)
|
|
3524
|
+
* If we don't initialize them, we won't be able to consume the repeated states properly.
|
|
3525
|
+
* For example, let's say the consumer is just mapping the repeated states. The first operation
|
|
3526
|
+
* is to get the length of the array which will always be 0 because the existing states
|
|
3527
|
+
* weren't allocated yet -- they're only stored in internal state)
|
|
3528
|
+
* */
|
|
3529
|
+
|
|
3530
|
+
for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
|
|
3531
|
+
var _path2 = _Object$values2[_i5].path;
|
|
3532
|
+
|
|
3533
|
+
_get($state, _path2);
|
|
3534
|
+
}
|
|
3453
3535
|
|
|
3454
|
-
updateInternalStateIfDirty();
|
|
3455
3536
|
return $state;
|
|
3456
3537
|
}
|
|
3457
3538
|
|
|
3458
|
-
|
|
3539
|
+
function fillUninitializedStateValues(specs, props, stateValues, states) {
|
|
3540
|
+
var stateAccessStack = [new Set()];
|
|
3541
|
+
var initFuncDeps = {};
|
|
3542
|
+
var $state = Object.assign(mkProxy(specs, function (state) {
|
|
3543
|
+
return {
|
|
3544
|
+
get: function get(_target, _property) {
|
|
3545
|
+
var spec = specs[state.specKey];
|
|
3546
|
+
|
|
3547
|
+
if (spec.valueProp) {
|
|
3548
|
+
if (!spec.isRepeated) {
|
|
3549
|
+
return props[spec.valueProp];
|
|
3550
|
+
} else {
|
|
3551
|
+
return _get(props[spec.valueProp], state.path.slice(1));
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
|
|
3555
|
+
var value = _get(stateValues, state.path);
|
|
3556
|
+
|
|
3557
|
+
if (value === UNINITIALIZED) {
|
|
3558
|
+
// This value has a init expression; need to be evaluated.
|
|
3559
|
+
value = tracked(state);
|
|
3560
|
+
|
|
3561
|
+
dset.dset(stateValues, state.path, value);
|
|
3562
|
+
} // Record that this field had just been accessed; for
|
|
3563
|
+
// trackInit() to know what fields were used to compute
|
|
3564
|
+
// the init value
|
|
3565
|
+
|
|
3566
|
+
|
|
3567
|
+
stateAccessStack[stateAccessStack.length - 1].add(JSON.stringify(state.path));
|
|
3568
|
+
return value;
|
|
3569
|
+
},
|
|
3570
|
+
set: function set() {
|
|
3571
|
+
throw new Error("Cannot update state values during initialization");
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
}), {
|
|
3575
|
+
registerInitFunc: function registerInitFunc() {}
|
|
3576
|
+
});
|
|
3577
|
+
|
|
3578
|
+
function tracked(state) {
|
|
3579
|
+
stateAccessStack.push(new Set());
|
|
3580
|
+
var res = specs[state.specKey].initFunc(props, $state);
|
|
3581
|
+
var deps = stateAccessStack.pop();
|
|
3582
|
+
initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
|
|
3583
|
+
return res;
|
|
3584
|
+
}
|
|
3585
|
+
|
|
3586
|
+
for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
|
|
3587
|
+
var path = _Object$values3[_i6].path;
|
|
3588
|
+
|
|
3589
|
+
if (_get(stateValues, path) === UNINITIALIZED) {
|
|
3590
|
+
_get($state, path);
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
return initFuncDeps;
|
|
3595
|
+
}
|
|
3459
3596
|
|
|
3460
3597
|
exports.DropdownMenu = DropdownMenu;
|
|
3461
3598
|
exports.PlasmicIcon = PlasmicIcon;
|
|
@@ -3463,14 +3600,18 @@ exports.PlasmicImg = PlasmicImg;
|
|
|
3463
3600
|
exports.PlasmicLink = PlasmicLink;
|
|
3464
3601
|
exports.PlasmicRootProvider = PlasmicRootProvider;
|
|
3465
3602
|
exports.PlasmicSlot = PlasmicSlot;
|
|
3603
|
+
exports.SelectContext = SelectContext;
|
|
3466
3604
|
exports.Stack = Stack;
|
|
3467
3605
|
exports.Trans = Trans;
|
|
3606
|
+
exports.TriggeredOverlayContext = TriggeredOverlayContext;
|
|
3468
3607
|
exports.classNames = classNames;
|
|
3469
3608
|
exports.createPlasmicElementProxy = createPlasmicElementProxy;
|
|
3470
3609
|
exports.createUseScreenVariants = createUseScreenVariants;
|
|
3471
3610
|
exports.deriveRenderOpts = deriveRenderOpts;
|
|
3472
3611
|
exports.ensureGlobalVariants = ensureGlobalVariants;
|
|
3473
3612
|
exports.genTranslatableString = genTranslatableString;
|
|
3613
|
+
exports.generateStateOnChangeProp = generateStateOnChangeProp;
|
|
3614
|
+
exports.generateStateValueProp = generateStateValueProp;
|
|
3474
3615
|
exports.getDataProps = getDataProps;
|
|
3475
3616
|
exports.hasVariant = hasVariant;
|
|
3476
3617
|
exports.makeFragment = makeFragment;
|
|
@@ -3480,7 +3621,7 @@ exports.renderPlasmicSlot = renderPlasmicSlot;
|
|
|
3480
3621
|
exports.setPlumeStrictMode = setPlumeStrictMode;
|
|
3481
3622
|
exports.useButton = useButton;
|
|
3482
3623
|
exports.useCheckbox = useCheckbox;
|
|
3483
|
-
exports.useDollarState =
|
|
3624
|
+
exports.useDollarState = useVanillaDollarState;
|
|
3484
3625
|
exports.useIsSSR = useIsSSR;
|
|
3485
3626
|
exports.useMenu = useMenu;
|
|
3486
3627
|
exports.useMenuButton = useMenuButton;
|