@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
@@ -18,6 +18,8 @@ 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 _get from 'dlv';
22
+ import { dset } from 'dset';
21
23
 
22
24
  function _extends() {
23
25
  _extends = Object.assign || function (target) {
@@ -1197,6 +1199,96 @@ function isInternalHref(href) {
1197
1199
  return /^\/(?!\/)/.test(href);
1198
1200
  }
1199
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
+
1200
1292
  function PlasmicSlot(props) {
1201
1293
  return renderPlasmicSlot(props);
1202
1294
  }
@@ -1240,7 +1332,8 @@ function renderPlasmicSlot(opts) {
1240
1332
 
1241
1333
  function maybeAsString(node) {
1242
1334
  // Unwrap fragments
1243
- if (isValidElement(node) && node.type === Fragment) {
1335
+ if (isValidElement(node) && ( // Fragment and Trans don't render DOM elements
1336
+ node.type === Fragment || node.type === Trans)) {
1244
1337
  return maybeAsString(node.props.children);
1245
1338
  }
1246
1339
 
@@ -1351,96 +1444,6 @@ function createUseScreenVariants(isMulti, screenQueries) {
1351
1444
  };
1352
1445
  }
1353
1446
 
1354
- var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
1355
-
1356
- function isIterable(val) {
1357
- return val != null && typeof val[Symbol.iterator] === "function";
1358
- }
1359
-
1360
- function genTranslatableString(elt) {
1361
- var components = {};
1362
- var componentsCount = 0;
1363
-
1364
- var getText = function getText(node) {
1365
- if (!node) {
1366
- return "";
1367
- }
1368
-
1369
- if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
1370
- return node.toString();
1371
- }
1372
-
1373
- if (typeof node !== "object") {
1374
- return "";
1375
- }
1376
-
1377
- if (Array.isArray(node) || isIterable(node)) {
1378
- return Array.from(node).map(function (child) {
1379
- return getText(child);
1380
- }).filter(function (child) {
1381
- return !!child;
1382
- }).join("");
1383
- }
1384
-
1385
- var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
1386
- var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
1387
- return getText(child);
1388
- }).filter(function (child) {
1389
- return !!child;
1390
- }).join("");
1391
-
1392
- if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
1393
- return contents;
1394
- }
1395
-
1396
- var componentId = componentsCount + 1;
1397
- componentsCount++;
1398
- components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
1399
- key: componentId,
1400
- children: undefined
1401
- }) : node;
1402
- return "<" + componentId + ">" + contents + "</" + componentId + ">";
1403
- };
1404
-
1405
- var str = getText(elt);
1406
- return {
1407
- str: str,
1408
- components: components,
1409
- componentsCount: componentsCount
1410
- };
1411
- }
1412
- function Trans(_ref) {
1413
- var children = _ref.children;
1414
-
1415
- var _t = React__default.useContext(PlasmicTranslatorContext);
1416
-
1417
- if (!_t) {
1418
- warnNoTranslationFunctionAtMostOnce();
1419
- return children;
1420
- }
1421
-
1422
- var _genTranslatableStrin = genTranslatableString(children),
1423
- str = _genTranslatableStrin.str,
1424
- components = _genTranslatableStrin.components,
1425
- componentsCount = _genTranslatableStrin.componentsCount;
1426
-
1427
- return _t(str, componentsCount > 0 ? {
1428
- components: components
1429
- } : undefined);
1430
- }
1431
- var hasWarned = false;
1432
-
1433
- function warnNoTranslationFunctionAtMostOnce() {
1434
- if (!hasWarned) {
1435
- console.warn("Using Plasmic Translation but no translation function has been provided");
1436
- hasWarned = true;
1437
- }
1438
- }
1439
-
1440
- function hasKey(v, key) {
1441
- return typeof v === "object" && v !== null && key in v;
1442
- }
1443
-
1444
1447
  var PlasmicRootContext = /*#__PURE__*/createContext(undefined);
1445
1448
  function PlasmicRootProvider(props) {
1446
1449
  var platform = props.platform,
@@ -3115,5 +3118,474 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
3115
3118
  };
3116
3119
  }
3117
3120
 
3118
- export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, Stack, Trans, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3121
+ function generateStateOnChangeProp($state, stateName, dataReps) {
3122
+ return function (val, path) {
3123
+ return dset($state, [stateName].concat(dataReps, path), val);
3124
+ };
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
+ */
3132
+
3133
+ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
3134
+ ) {
3135
+ return _get($state, path);
3136
+ }
3137
+
3138
+ var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
3139
+
3140
+ function shallowEqual(a1, a2) {
3141
+ if (a1.length !== a2.length) {
3142
+ return false;
3143
+ }
3144
+
3145
+ for (var i = 0; i < a1.length; i++) {
3146
+ if (a1[i] !== a2[i]) {
3147
+ return false;
3148
+ }
3149
+ }
3150
+
3151
+ return true;
3152
+ }
3153
+
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 () {
3160
+ return {
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
+ }
3167
+ };
3168
+ };
3169
+
3170
+ var getNextParts = function getNextParts(currPath) {
3171
+ return Object.fromEntries(Object.values(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
+ specKey: spec.pathStr
3182
+ }];
3183
+ } else {
3184
+ return [nextPart, {
3185
+ isLast: false,
3186
+ specKey: spec.pathStr
3187
+ }];
3188
+ }
3189
+ }));
3190
+ };
3191
+ /**
3192
+ * We use this function when we're setting a value in the middle of the state path.
3193
+ * We can't just set the value, because we need to keep the proxy properties, so
3194
+ * we use the specs to walk through the object and just set the value in the end of the path
3195
+ **/
3196
+
3197
+
3198
+ var cloneValue = function cloneValue(target, currPath, value) {
3199
+ if (typeof value !== "object") {
3200
+ return;
3201
+ }
3202
+
3203
+ var nextParts = getNextParts(currPath);
3204
+
3205
+ for (var _i = 0, _Object$entries = Object.entries(nextParts); _i < _Object$entries.length; _i++) {
3206
+ var _Object$entries$_i = _Object$entries[_i],
3207
+ nextPart = _Object$entries$_i[0],
3208
+ _Object$entries$_i$ = _Object$entries$_i[1],
3209
+ isLast = _Object$entries$_i$.isLast,
3210
+ specKey = _Object$entries$_i$.specKey;
3211
+
3212
+ if (nextPart === "[]" && Array.isArray(value)) {
3213
+ for (var i = 0; i < value.length; i++) {
3214
+ cloneValue(target[i], [].concat(currPath, [i]), value[i]);
3215
+ }
3216
+ } else if (nextPart in value) {
3217
+ if (isLast) {
3218
+ var _handlers$set, _handlers;
3219
+
3220
+ handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
3221
+ specKey: specKey,
3222
+ path: [].concat(currPath, [nextPart])
3223
+ })).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
3224
+ } else {
3225
+ cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
3226
+ }
3227
+ }
3228
+ }
3229
+ };
3230
+
3231
+ var rec = function rec(currPath) {
3232
+ var nextParts = getNextParts(currPath);
3233
+ return new Proxy("[]" in nextParts ? [] : {}, {
3234
+ deleteProperty: function deleteProperty(target, property) {
3235
+ if ("[]" in nextParts && isNum(property)) {
3236
+ var _handlers$deletePrope, _handlers2;
3237
+
3238
+ delete target[property];
3239
+ handlers == null ? void 0 : (_handlers$deletePrope = (_handlers2 = handlers({
3240
+ path: [].concat(currPath, [+property]),
3241
+ specKey: nextParts["[]"].specKey
3242
+ })).deleteProperty) == null ? void 0 : _handlers$deletePrope.call(_handlers2, target, property);
3243
+ } else {
3244
+ throw new Error("You can't delete a non-repeated property in the middle of the path");
3245
+ }
3246
+
3247
+ return true;
3248
+ },
3249
+ get: function get(target, property, receiver) {
3250
+ if ("[]" in nextParts && isNum(property)) {
3251
+ if (!(property in target)) {
3252
+ target[property] = rec([].concat(currPath, [+property]));
3253
+ }
3254
+ } else if (property in nextParts) {
3255
+ if (nextParts[property].isLast) {
3256
+ var _handlers$get, _handlers3;
3257
+
3258
+ return target[property] = handlers == null ? void 0 : (_handlers$get = (_handlers3 = handlers({
3259
+ path: [].concat(currPath, [property]),
3260
+ specKey: nextParts[property].specKey
3261
+ })).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
3262
+ } else if (!(property in target)) {
3263
+ target[property] = rec([].concat(currPath, [property]));
3264
+ }
3265
+ }
3266
+
3267
+ return target[property];
3268
+ },
3269
+ set: function set(target, property, value, receiver) {
3270
+ if ("[]" in nextParts && isNum(property)) {
3271
+ if (!(property in target)) {
3272
+ target[property] = rec([].concat(currPath, [+property]));
3273
+ }
3274
+ } else if (property in nextParts) {
3275
+ if (nextParts[property].isLast) {
3276
+ var _handlers$set2, _handlers$set3, _handlers4;
3277
+
3278
+ target[property] = value;
3279
+ return (_handlers$set2 = (_handlers$set3 = (_handlers4 = handlers({
3280
+ path: [].concat(currPath, [property]),
3281
+ specKey: nextParts[property].specKey
3282
+ })).set) == null ? void 0 : _handlers$set3.call(_handlers4, target, property, value, receiver)) != null ? _handlers$set2 : false;
3283
+ }
3284
+ }
3285
+
3286
+ if (property === "registerInitFunc") {
3287
+ target[property] = value;
3288
+ } else if (typeof value === "object") {
3289
+ cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
3290
+ }
3291
+
3292
+ return true;
3293
+ }
3294
+ });
3295
+ };
3296
+
3297
+ return rec([]);
3298
+ }
3299
+
3300
+ function cloneProxy(specs, states, obj) {
3301
+ var newObj = mkProxy(specs);
3302
+ Object.values(states).forEach(function (_ref) {
3303
+ var path = _ref.path;
3304
+
3305
+ dset(newObj, path, _get(obj, path));
3306
+ });
3307
+ return newObj;
3308
+ }
3309
+
3310
+ function saveState(state, states) {
3311
+ states[JSON.stringify(state.path)] = state;
3312
+ }
3313
+
3314
+ function hasState(state, states) {
3315
+ return JSON.stringify(state.path) in states;
3316
+ }
3317
+
3318
+ var transformPathStringToObj = function transformPathStringToObj(str) {
3319
+ // "c[][]" -> ["c", "[]", "[]"]
3320
+ var splitStatePathPart = function splitStatePathPart(state) {
3321
+ return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
3322
+ };
3323
+
3324
+ return str.split(".").flatMap(splitStatePathPart);
3325
+ };
3326
+
3327
+ function useVanillaDollarState(_specs, props) {
3328
+ var forceRender = React__default.useState(0)[1];
3329
+ var $$state = React__default.useMemo(function () {
3330
+ var specs = Object.fromEntries(_specs.map(function (_ref2) {
3331
+ var pathStr = _ref2.path,
3332
+ spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
3333
+
3334
+ return [pathStr, _extends({}, spec, {
3335
+ pathStr: pathStr,
3336
+ path: transformPathStringToObj(pathStr),
3337
+ isRepeated: pathStr.split(".").some(function (part) {
3338
+ return part.endsWith("[]");
3339
+ })
3340
+ })];
3341
+ }));
3342
+ return {
3343
+ stateValues: mkProxy(specs),
3344
+ initStateDeps: {},
3345
+ initStateValues: mkProxy(specs),
3346
+ states: {},
3347
+ specs: specs
3348
+ };
3349
+ }, []);
3350
+ var $state = Object.assign(mkProxy($$state.specs, function (state) {
3351
+ return {
3352
+ deleteProperty: function deleteProperty(_target, _property) {
3353
+ var prefixPath = state.path;
3354
+
3355
+ for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
3356
+ var _Object$entries2$_i = _Object$entries2[_i2],
3357
+ key = _Object$entries2$_i[0],
3358
+ existingState = _Object$entries2$_i[1];
3359
+
3360
+ if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
3361
+ delete $$state.states[key];
3362
+ }
3363
+ }
3364
+
3365
+ forceRender(function (r) {
3366
+ return r + 1;
3367
+ });
3368
+ return true;
3369
+ },
3370
+ get: function get(_target, _property) {
3371
+ var spec = $$state.specs[state.specKey];
3372
+
3373
+ if (spec.valueProp) {
3374
+ if (!spec.isRepeated) {
3375
+ return props[spec.valueProp];
3376
+ } else {
3377
+ return _get(props[spec.valueProp], state.path.slice(1));
3378
+ }
3379
+ }
3380
+
3381
+ if (!hasState(state, $$state.states)) {
3382
+ var _spec$initVal;
3383
+
3384
+ saveState(state, $$state.states);
3385
+
3386
+ dset($$state.stateValues, state.path, spec.initFunc ? UNINITIALIZED : (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
3387
+
3388
+ var deps = spec.initFunc ? fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states) : {};
3389
+
3390
+ dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
3391
+
3392
+ $$state.initStateDeps = _extends({}, $$state.initStateDeps, deps);
3393
+ forceRender(function (r) {
3394
+ return r + 1;
3395
+ });
3396
+ return spec.initFunc ? spec.initFunc(props, $state) : spec.initVal;
3397
+ }
3398
+
3399
+ return _get($$state.stateValues, state.path);
3400
+ },
3401
+ set: function set(_target, _property, newValue) {
3402
+ if (newValue !== _get($$state.stateValues, state.path)) {
3403
+ saveState(state, $$state.states);
3404
+
3405
+ dset($$state.stateValues, state.path, newValue);
3406
+
3407
+ for (var _i3 = 0, _Object$entries3 = Object.entries($$state.initStateDeps); _i3 < _Object$entries3.length; _i3++) {
3408
+ var _Object$entries3$_i = _Object$entries3[_i3],
3409
+ key = _Object$entries3$_i[0],
3410
+ deps = _Object$entries3$_i[1];
3411
+
3412
+ if (deps.includes(JSON.stringify(state.path))) {
3413
+ dset($$state.stateValues, JSON.parse(key), UNINITIALIZED);
3414
+ }
3415
+ }
3416
+
3417
+ var newDeps = fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states);
3418
+ $$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
3419
+ forceRender(function (r) {
3420
+ return r + 1;
3421
+ });
3422
+ }
3423
+
3424
+ var spec = $$state.specs[state.specKey];
3425
+
3426
+ if (spec.onChangeProp) {
3427
+ var _props$spec$onChangeP;
3428
+
3429
+ (_props$spec$onChangeP = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP.call(props, newValue, state.path);
3430
+ }
3431
+
3432
+ return true;
3433
+ }
3434
+ };
3435
+ }), {
3436
+ registerInitFunc: function registerInitFunc(pathStr, f) {
3437
+ if (Object.values($$state.states).filter(function (_ref3) {
3438
+ var specKey = _ref3.specKey;
3439
+ return specKey === pathStr;
3440
+ }).some(function (_ref4) {
3441
+ var path = _ref4.path;
3442
+ return _get($$state.stateValues, path) !== f(props, $state);
3443
+ })) {
3444
+ $$state.specs[pathStr] = _extends({}, $$state.specs[pathStr], {
3445
+ initFunc: f
3446
+ });
3447
+ forceRender(function (r) {
3448
+ return r + 1;
3449
+ });
3450
+ }
3451
+ }
3452
+ }); // For each spec with an initFunc, evaluate it and see if
3453
+ // the init value has changed. If so, reset its state.
3454
+
3455
+ var newStateValues = undefined;
3456
+ var resetSpecs = [];
3457
+
3458
+ for (var _i4 = 0, _Object$values = Object.values($$state.states); _i4 < _Object$values.length; _i4++) {
3459
+ var _Object$values$_i = _Object$values[_i4],
3460
+ path = _Object$values$_i.path,
3461
+ specKey = _Object$values$_i.specKey;
3462
+ var spec = $$state.specs[specKey];
3463
+
3464
+ if (spec.initFunc) {
3465
+ var newInit = spec.initFunc(props, $state);
3466
+
3467
+ if (newInit !== _get($$state.initStateValues, path)) {
3468
+ console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
3469
+ resetSpecs.push({
3470
+ path: path,
3471
+ specKey: specKey
3472
+ });
3473
+
3474
+ if (!newStateValues) {
3475
+ newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
3476
+ }
3477
+
3478
+ dset(newStateValues, path, UNINITIALIZED);
3479
+ }
3480
+ }
3481
+ }
3482
+
3483
+ React__default.useLayoutEffect(function () {
3484
+ if (newStateValues !== undefined) {
3485
+ var newDeps = fillUninitializedStateValues($$state.specs, props, newStateValues, $$state.states);
3486
+ var initStateValues = cloneProxy($$state.specs, $$state.states, $$state.initStateValues);
3487
+ resetSpecs.forEach(function (_ref5) {
3488
+ var path = _ref5.path;
3489
+
3490
+ dset(initStateValues, path, _get(newStateValues, path));
3491
+ });
3492
+ $$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
3493
+ $$state.initStateValues = initStateValues;
3494
+ $$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
3495
+ forceRender(function (r) {
3496
+ return r + 1;
3497
+ });
3498
+
3499
+ for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
3500
+ var _step$value = _step.value,
3501
+ _path = _step$value.path,
3502
+ _specKey = _step$value.specKey;
3503
+ var _spec = $$state.specs[_specKey];
3504
+
3505
+ if (_spec.onChangeProp) {
3506
+ var _props$_spec$onChange;
3507
+
3508
+ console.log("Firing onChange for reset init value: " + _spec.path, _get(newStateValues, _path));
3509
+ (_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
3510
+ }
3511
+ }
3512
+ }
3513
+ }, [newStateValues, props, resetSpecs, $$state.specs]);
3514
+ /* *
3515
+ * Initialize all known states. (we need to do it for repeated states
3516
+ * because they're created only after the first get/set operation)
3517
+ * If we don't initialize them, we won't be able to consume the repeated states properly.
3518
+ * For example, let's say the consumer is just mapping the repeated states. The first operation
3519
+ * is to get the length of the array which will always be 0 because the existing states
3520
+ * weren't allocated yet -- they're only stored in internal state)
3521
+ * */
3522
+
3523
+ for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
3524
+ var _path2 = _Object$values2[_i5].path;
3525
+
3526
+ _get($state, _path2);
3527
+ }
3528
+
3529
+ return $state;
3530
+ }
3531
+
3532
+ function fillUninitializedStateValues(specs, props, stateValues, states) {
3533
+ var stateAccessStack = [new Set()];
3534
+ var initFuncDeps = {};
3535
+ var $state = Object.assign(mkProxy(specs, function (state) {
3536
+ return {
3537
+ get: function get(_target, _property) {
3538
+ var spec = specs[state.specKey];
3539
+
3540
+ if (spec.valueProp) {
3541
+ if (!spec.isRepeated) {
3542
+ return props[spec.valueProp];
3543
+ } else {
3544
+ return _get(props[spec.valueProp], state.path.slice(1));
3545
+ }
3546
+ }
3547
+
3548
+ var value = _get(stateValues, state.path);
3549
+
3550
+ if (value === UNINITIALIZED) {
3551
+ // This value has a init expression; need to be evaluated.
3552
+ value = tracked(state);
3553
+
3554
+ dset(stateValues, state.path, value);
3555
+ } // Record that this field had just been accessed; for
3556
+ // trackInit() to know what fields were used to compute
3557
+ // the init value
3558
+
3559
+
3560
+ stateAccessStack[stateAccessStack.length - 1].add(JSON.stringify(state.path));
3561
+ return value;
3562
+ },
3563
+ set: function set() {
3564
+ throw new Error("Cannot update state values during initialization");
3565
+ }
3566
+ };
3567
+ }), {
3568
+ registerInitFunc: function registerInitFunc() {}
3569
+ });
3570
+
3571
+ function tracked(state) {
3572
+ stateAccessStack.push(new Set());
3573
+ var res = specs[state.specKey].initFunc(props, $state);
3574
+ var deps = stateAccessStack.pop();
3575
+ initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
3576
+ return res;
3577
+ }
3578
+
3579
+ for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
3580
+ var path = _Object$values3[_i6].path;
3581
+
3582
+ if (_get(stateValues, path) === UNINITIALIZED) {
3583
+ _get($state, path);
3584
+ }
3585
+ }
3586
+
3587
+ return initFuncDeps;
3588
+ }
3589
+
3590
+ 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 };
3119
3591
  //# sourceMappingURL=react-web.esm.js.map