@plasmicapp/react-web 0.2.101 → 0.2.104

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.
Files changed (91) hide show
  1. package/README.md +13 -0
  2. package/dist/all.d.ts +140 -105
  3. package/dist/index.d.ts +2 -0
  4. package/dist/plume/menu-button/menu-trigger.d.ts +1 -1
  5. package/dist/react-web.cjs.development.js +566 -91
  6. package/dist/react-web.cjs.development.js.map +1 -1
  7. package/dist/react-web.cjs.production.min.js +1 -1
  8. package/dist/react-web.cjs.production.min.js.map +1 -1
  9. package/dist/react-web.esm.js +564 -92
  10. package/dist/react-web.esm.js.map +1 -1
  11. package/dist/render/triggers.d.ts +4 -4
  12. package/dist/states/helpers.d.ts +9 -0
  13. package/dist/states/index.d.ts +15 -0
  14. package/dist/stories/PlasmicImg.stories.d.ts +2 -2
  15. package/dist/stories/UseDollarState.stories.d.ts +40 -0
  16. package/package.json +31 -22
  17. package/skinny/dist/{collection-utils-3487dd27.js → collection-utils-57c273dc.js} +5 -5
  18. package/skinny/dist/collection-utils-57c273dc.js.map +1 -0
  19. package/skinny/dist/common-182a0b0c.js +201 -0
  20. package/skinny/dist/common-182a0b0c.js.map +1 -0
  21. package/skinny/dist/index.d.ts +2 -0
  22. package/skinny/dist/index.js +68 -45
  23. package/skinny/dist/index.js.map +1 -1
  24. package/skinny/dist/plume/button/index.js +5 -5
  25. package/skinny/dist/plume/button/index.js.map +1 -1
  26. package/skinny/dist/plume/checkbox/index.js +6 -6
  27. package/skinny/dist/plume/checkbox/index.js.map +1 -1
  28. package/skinny/dist/plume/menu/index.js +11 -11
  29. package/skinny/dist/plume/menu/index.js.map +1 -1
  30. package/skinny/dist/plume/menu-button/index.js +6 -6
  31. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  32. package/skinny/dist/plume/menu-button/menu-trigger.d.ts +1 -1
  33. package/skinny/dist/plume/select/index.js +11 -11
  34. package/skinny/dist/plume/select/index.js.map +1 -1
  35. package/skinny/dist/plume/switch/index.js +6 -6
  36. package/skinny/dist/plume/switch/index.js.map +1 -1
  37. package/skinny/dist/plume/text-input/index.js +5 -5
  38. package/skinny/dist/plume/text-input/index.js.map +1 -1
  39. package/skinny/dist/plume/triggered-overlay/index.js +7 -7
  40. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  41. package/skinny/dist/{plume-utils-5c413fd1.js → plume-utils-623b91cc.js} +2 -2
  42. package/skinny/dist/{plume-utils-5c413fd1.js.map → plume-utils-623b91cc.js.map} +1 -1
  43. package/skinny/dist/{props-utils-4633caf6.js → props-utils-b2ad4997.js} +2 -2
  44. package/skinny/dist/{props-utils-4633caf6.js.map → props-utils-b2ad4997.js.map} +1 -1
  45. package/skinny/dist/{react-utils-2d70bbbe.js → react-utils-35cb2a4e.js} +43 -14
  46. package/skinny/dist/{react-utils-2d70bbbe.js.map → react-utils-35cb2a4e.js.map} +1 -1
  47. package/skinny/dist/render/PlasmicImg/index.js +3 -3
  48. package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
  49. package/skinny/dist/render/triggers.d.ts +4 -4
  50. package/skinny/dist/states/helpers.d.ts +9 -0
  51. package/skinny/dist/states/index.d.ts +15 -0
  52. package/skinny/dist/stories/UseDollarState.stories.d.ts +41 -0
  53. package/README +0 -8
  54. package/skinny/dist/collection-utils-3487dd27.js.map +0 -1
  55. package/skinny/dist/collection-utils-47e89cbe.js +0 -238
  56. package/skinny/dist/collection-utils-47e89cbe.js.map +0 -1
  57. package/skinny/dist/collection-utils-4dae6efa.js +0 -292
  58. package/skinny/dist/collection-utils-4dae6efa.js.map +0 -1
  59. package/skinny/dist/collection-utils-57ec40f9.js +0 -292
  60. package/skinny/dist/collection-utils-57ec40f9.js.map +0 -1
  61. package/skinny/dist/collection-utils-96cde83c.js +0 -238
  62. package/skinny/dist/collection-utils-96cde83c.js.map +0 -1
  63. package/skinny/dist/collection-utils-b0b8f30e.js +0 -291
  64. package/skinny/dist/collection-utils-b0b8f30e.js.map +0 -1
  65. package/skinny/dist/props-utils-5c0ad25a.js +0 -59
  66. package/skinny/dist/props-utils-5c0ad25a.js.map +0 -1
  67. package/skinny/dist/props-utils-754f655a.js +0 -39
  68. package/skinny/dist/props-utils-754f655a.js.map +0 -1
  69. package/skinny/dist/props-utils-c632595f.js +0 -59
  70. package/skinny/dist/props-utils-c632595f.js.map +0 -1
  71. package/skinny/dist/props-utils-fd5f444e.js +0 -59
  72. package/skinny/dist/props-utils-fd5f444e.js.map +0 -1
  73. package/skinny/dist/react-utils-118d8539.js +0 -190
  74. package/skinny/dist/react-utils-118d8539.js.map +0 -1
  75. package/skinny/dist/react-utils-2a2fd6c9.js +0 -339
  76. package/skinny/dist/react-utils-2a2fd6c9.js.map +0 -1
  77. package/skinny/dist/react-utils-675565b4.js +0 -334
  78. package/skinny/dist/react-utils-675565b4.js.map +0 -1
  79. package/skinny/dist/render/PlasmicImg.d.ts +0 -62
  80. package/skinny/dist/ssr-64e38713.js +0 -108
  81. package/skinny/dist/ssr-64e38713.js.map +0 -1
  82. package/skinny/dist/ssr-902d1292.js +0 -105
  83. package/skinny/dist/ssr-902d1292.js.map +0 -1
  84. package/skinny/dist/ssr-a8081074.js +0 -108
  85. package/skinny/dist/ssr-a8081074.js.map +0 -1
  86. package/skinny/dist/ssr-d2fd94f2.js +0 -31
  87. package/skinny/dist/ssr-d2fd94f2.js.map +0 -1
  88. package/skinny/dist/tslib.es6-00014098.js +0 -148
  89. package/skinny/dist/tslib.es6-00014098.js.map +0 -1
  90. package/skinny/dist/tslib.es6-73236e8e.js +0 -141
  91. package/skinny/dist/tslib.es6-73236e8e.js.map +0 -1
@@ -25,6 +25,8 @@ 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 _get = _interopDefault(require('dlv'));
29
+ var dset = require('dset');
28
30
 
29
31
  function _extends() {
30
32
  _extends = Object.assign || function (target) {
@@ -1204,6 +1206,96 @@ function isInternalHref(href) {
1204
1206
  return /^\/(?!\/)/.test(href);
1205
1207
  }
1206
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
+
1207
1299
  function PlasmicSlot(props) {
1208
1300
  return renderPlasmicSlot(props);
1209
1301
  }
@@ -1247,7 +1339,8 @@ function renderPlasmicSlot(opts) {
1247
1339
 
1248
1340
  function maybeAsString(node) {
1249
1341
  // Unwrap fragments
1250
- if (React.isValidElement(node) && node.type === React.Fragment) {
1342
+ if (React.isValidElement(node) && ( // Fragment and Trans don't render DOM elements
1343
+ node.type === React.Fragment || node.type === Trans)) {
1251
1344
  return maybeAsString(node.props.children);
1252
1345
  }
1253
1346
 
@@ -1358,96 +1451,6 @@ function createUseScreenVariants(isMulti, screenQueries) {
1358
1451
  };
1359
1452
  }
1360
1453
 
1361
- var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
1362
-
1363
- function isIterable(val) {
1364
- return val != null && typeof val[Symbol.iterator] === "function";
1365
- }
1366
-
1367
- function genTranslatableString(elt) {
1368
- var components = {};
1369
- var componentsCount = 0;
1370
-
1371
- var getText = function getText(node) {
1372
- if (!node) {
1373
- return "";
1374
- }
1375
-
1376
- if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
1377
- return node.toString();
1378
- }
1379
-
1380
- if (typeof node !== "object") {
1381
- return "";
1382
- }
1383
-
1384
- if (Array.isArray(node) || isIterable(node)) {
1385
- return Array.from(node).map(function (child) {
1386
- return getText(child);
1387
- }).filter(function (child) {
1388
- return !!child;
1389
- }).join("");
1390
- }
1391
-
1392
- var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
1393
- var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
1394
- return getText(child);
1395
- }).filter(function (child) {
1396
- return !!child;
1397
- }).join("");
1398
-
1399
- if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
1400
- return contents;
1401
- }
1402
-
1403
- var componentId = componentsCount + 1;
1404
- componentsCount++;
1405
- components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
1406
- key: componentId,
1407
- children: undefined
1408
- }) : node;
1409
- return "<" + componentId + ">" + contents + "</" + componentId + ">";
1410
- };
1411
-
1412
- var str = getText(elt);
1413
- return {
1414
- str: str,
1415
- components: components,
1416
- componentsCount: componentsCount
1417
- };
1418
- }
1419
- function Trans(_ref) {
1420
- var children = _ref.children;
1421
-
1422
- var _t = React__default.useContext(PlasmicTranslatorContext);
1423
-
1424
- if (!_t) {
1425
- warnNoTranslationFunctionAtMostOnce();
1426
- return children;
1427
- }
1428
-
1429
- var _genTranslatableStrin = genTranslatableString(children),
1430
- str = _genTranslatableStrin.str,
1431
- components = _genTranslatableStrin.components,
1432
- componentsCount = _genTranslatableStrin.componentsCount;
1433
-
1434
- return _t(str, componentsCount > 0 ? {
1435
- components: components
1436
- } : undefined);
1437
- }
1438
- var hasWarned = false;
1439
-
1440
- function warnNoTranslationFunctionAtMostOnce() {
1441
- if (!hasWarned) {
1442
- console.warn("Using Plasmic Translation but no translation function has been provided");
1443
- hasWarned = true;
1444
- }
1445
- }
1446
-
1447
- function hasKey(v, key) {
1448
- return typeof v === "object" && v !== null && key in v;
1449
- }
1450
-
1451
1454
  var PlasmicRootContext = /*#__PURE__*/React.createContext(undefined);
1452
1455
  function PlasmicRootProvider(props) {
1453
1456
  var platform = props.platform,
@@ -3122,6 +3125,475 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
3122
3125
  };
3123
3126
  }
3124
3127
 
3128
+ function generateStateOnChangeProp($state, stateName, dataReps) {
3129
+ return function (val, path) {
3130
+ return dset.dset($state, [stateName].concat(dataReps, path), val);
3131
+ };
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
+ */
3139
+
3140
+ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
3141
+ ) {
3142
+ return _get($state, path);
3143
+ }
3144
+
3145
+ var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
3146
+
3147
+ function shallowEqual(a1, a2) {
3148
+ if (a1.length !== a2.length) {
3149
+ return false;
3150
+ }
3151
+
3152
+ for (var i = 0; i < a1.length; i++) {
3153
+ if (a1[i] !== a2[i]) {
3154
+ return false;
3155
+ }
3156
+ }
3157
+
3158
+ return true;
3159
+ }
3160
+
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 () {
3167
+ return {
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
+ }
3174
+ };
3175
+ };
3176
+
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
+ **/
3203
+
3204
+
3205
+ var cloneValue = function cloneValue(target, currPath, value) {
3206
+ if (typeof value !== "object") {
3207
+ return;
3208
+ }
3209
+
3210
+ var nextParts = getNextParts(currPath);
3211
+
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
+ }
3234
+ }
3235
+ }
3236
+ };
3237
+
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
+ }
3253
+
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
+ }
3273
+
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
+ }
3292
+
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
+ }
3298
+
3299
+ return true;
3300
+ }
3301
+ });
3302
+ };
3303
+
3304
+ return rec([]);
3305
+ }
3306
+
3307
+ function cloneProxy(specs, states, obj) {
3308
+ var newObj = mkProxy(specs);
3309
+ Object.values(states).forEach(function (_ref) {
3310
+ var path = _ref.path;
3311
+
3312
+ dset.dset(newObj, path, _get(obj, path));
3313
+ });
3314
+ return newObj;
3315
+ }
3316
+
3317
+ function saveState(state, states) {
3318
+ states[JSON.stringify(state.path)] = state;
3319
+ }
3320
+
3321
+ function hasState(state, states) {
3322
+ return JSON.stringify(state.path) in states;
3323
+ }
3324
+
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
+ };
3330
+
3331
+ return str.split(".").flatMap(splitStatePathPart);
3332
+ };
3333
+
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;
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];
3366
+
3367
+ if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
3368
+ delete $$state.states[key];
3369
+ }
3370
+ }
3371
+
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];
3379
+
3380
+ if (spec.valueProp) {
3381
+ if (!spec.isRepeated) {
3382
+ return props[spec.valueProp];
3383
+ } else {
3384
+ return _get(props[spec.valueProp], state.path.slice(1));
3385
+ }
3386
+ }
3387
+
3388
+ if (!hasState(state, $$state.states)) {
3389
+ var _spec$initVal;
3390
+
3391
+ saveState(state, $$state.states);
3392
+
3393
+ dset.dset($$state.stateValues, state.path, spec.initFunc ? UNINITIALIZED : (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
3394
+
3395
+ var deps = spec.initFunc ? fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states) : {};
3396
+
3397
+ dset.dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
3398
+
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;
3404
+ }
3405
+
3406
+ return _get($$state.stateValues, state.path);
3407
+ },
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];
3418
+
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
+ });
3429
+ }
3430
+
3431
+ var spec = $$state.specs[state.specKey];
3432
+
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);
3437
+ }
3438
+
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
3460
+ // the init value has changed. If so, reset its state.
3461
+
3462
+ var newStateValues = undefined;
3463
+ var resetSpecs = [];
3464
+
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];
3470
+
3471
+ if (spec.initFunc) {
3472
+ var newInit = spec.initFunc(props, $state);
3473
+
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
+ });
3480
+
3481
+ if (!newStateValues) {
3482
+ newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
3483
+ }
3484
+
3485
+ dset.dset(newStateValues, path, UNINITIALIZED);
3486
+ }
3487
+ }
3488
+ }
3489
+
3490
+ React__default.useLayoutEffect(function () {
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;
3496
+
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;
3514
+
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));
3517
+ }
3518
+ }
3519
+ }
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
+ }
3535
+
3536
+ return $state;
3537
+ }
3538
+
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
+ }
3596
+
3125
3597
  exports.DropdownMenu = DropdownMenu;
3126
3598
  exports.PlasmicIcon = PlasmicIcon;
3127
3599
  exports.PlasmicImg = PlasmicImg;
@@ -3136,6 +3608,8 @@ exports.createUseScreenVariants = createUseScreenVariants;
3136
3608
  exports.deriveRenderOpts = deriveRenderOpts;
3137
3609
  exports.ensureGlobalVariants = ensureGlobalVariants;
3138
3610
  exports.genTranslatableString = genTranslatableString;
3611
+ exports.generateStateOnChangeProp = generateStateOnChangeProp;
3612
+ exports.generateStateValueProp = generateStateValueProp;
3139
3613
  exports.getDataProps = getDataProps;
3140
3614
  exports.hasVariant = hasVariant;
3141
3615
  exports.makeFragment = makeFragment;
@@ -3145,6 +3619,7 @@ exports.renderPlasmicSlot = renderPlasmicSlot;
3145
3619
  exports.setPlumeStrictMode = setPlumeStrictMode;
3146
3620
  exports.useButton = useButton;
3147
3621
  exports.useCheckbox = useCheckbox;
3622
+ exports.useDollarState = useVanillaDollarState;
3148
3623
  exports.useIsSSR = useIsSSR;
3149
3624
  exports.useMenu = useMenu;
3150
3625
  exports.useMenuButton = useMenuButton;