@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.
Files changed (102) hide show
  1. package/README.md +13 -0
  2. package/dist/all.d.ts +471 -108
  3. package/dist/index.d.ts +1 -0
  4. package/dist/plume/menu-button/menu-trigger.d.ts +1 -1
  5. package/dist/plume/select/index.d.ts +1 -0
  6. package/dist/plume/triggered-overlay/index.d.ts +1 -0
  7. package/dist/react-web.cjs.development.js +480 -339
  8. package/dist/react-web.cjs.development.js.map +1 -1
  9. package/dist/react-web.cjs.production.min.js +1 -1
  10. package/dist/react-web.cjs.production.min.js.map +1 -1
  11. package/dist/react-web.esm.js +476 -339
  12. package/dist/react-web.esm.js.map +1 -1
  13. package/dist/render/triggers.d.ts +4 -4
  14. package/dist/states/helpers.d.ts +9 -0
  15. package/dist/states/index.d.ts +7 -7
  16. package/dist/stories/PlasmicImg.stories.d.ts +2 -2
  17. package/dist/stories/UseDollarState.stories.d.ts +40 -0
  18. package/package.json +27 -21
  19. package/skinny/dist/collection-utils-3487dd27.js +238 -0
  20. package/skinny/dist/collection-utils-3487dd27.js.map +1 -0
  21. package/skinny/dist/collection-utils-47e89cbe.js +238 -0
  22. package/skinny/dist/collection-utils-47e89cbe.js.map +1 -0
  23. package/skinny/dist/collection-utils-4dae6efa.js +292 -0
  24. package/skinny/dist/collection-utils-4dae6efa.js.map +1 -0
  25. package/skinny/dist/collection-utils-57c273dc.js +238 -0
  26. package/skinny/dist/collection-utils-57c273dc.js.map +1 -0
  27. package/skinny/dist/collection-utils-57ec40f9.js +292 -0
  28. package/skinny/dist/collection-utils-57ec40f9.js.map +1 -0
  29. package/skinny/dist/collection-utils-96cde83c.js +238 -0
  30. package/skinny/dist/collection-utils-96cde83c.js.map +1 -0
  31. package/skinny/dist/collection-utils-b0b8f30e.js +291 -0
  32. package/skinny/dist/collection-utils-b0b8f30e.js.map +1 -0
  33. package/skinny/dist/common-182a0b0c.js +201 -0
  34. package/skinny/dist/common-182a0b0c.js.map +1 -0
  35. package/skinny/dist/index.d.ts +1 -0
  36. package/skinny/dist/index.js +68 -45
  37. package/skinny/dist/index.js.map +1 -1
  38. package/skinny/dist/plume/button/index.js +5 -5
  39. package/skinny/dist/plume/button/index.js.map +1 -1
  40. package/skinny/dist/plume/checkbox/index.js +6 -6
  41. package/skinny/dist/plume/checkbox/index.js.map +1 -1
  42. package/skinny/dist/plume/menu/index.js +11 -11
  43. package/skinny/dist/plume/menu/index.js.map +1 -1
  44. package/skinny/dist/plume/menu-button/index.js +6 -6
  45. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  46. package/skinny/dist/plume/menu-button/menu-trigger.d.ts +1 -1
  47. package/skinny/dist/plume/select/index.d.ts +1 -0
  48. package/skinny/dist/plume/select/index.js +12 -12
  49. package/skinny/dist/plume/select/index.js.map +1 -1
  50. package/skinny/dist/plume/switch/index.js +6 -6
  51. package/skinny/dist/plume/switch/index.js.map +1 -1
  52. package/skinny/dist/plume/text-input/index.js +5 -5
  53. package/skinny/dist/plume/text-input/index.js.map +1 -1
  54. package/skinny/dist/plume/triggered-overlay/index.d.ts +1 -0
  55. package/skinny/dist/plume/triggered-overlay/index.js +8 -7
  56. package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
  57. package/skinny/dist/plume-utils-5c413fd1.js +35 -0
  58. package/skinny/dist/plume-utils-5c413fd1.js.map +1 -0
  59. package/skinny/dist/plume-utils-623b91cc.js +35 -0
  60. package/skinny/dist/plume-utils-623b91cc.js.map +1 -0
  61. package/skinny/dist/props-utils-4633caf6.js +8 -0
  62. package/skinny/dist/props-utils-4633caf6.js.map +1 -0
  63. package/skinny/dist/props-utils-5c0ad25a.js +59 -0
  64. package/skinny/dist/props-utils-5c0ad25a.js.map +1 -0
  65. package/skinny/dist/props-utils-754f655a.js +39 -0
  66. package/skinny/dist/props-utils-754f655a.js.map +1 -0
  67. package/skinny/dist/props-utils-b2ad4997.js +8 -0
  68. package/skinny/dist/props-utils-b2ad4997.js.map +1 -0
  69. package/skinny/dist/props-utils-c632595f.js +59 -0
  70. package/skinny/dist/props-utils-c632595f.js.map +1 -0
  71. package/skinny/dist/props-utils-fd5f444e.js +59 -0
  72. package/skinny/dist/props-utils-fd5f444e.js.map +1 -0
  73. package/skinny/dist/react-utils-118d8539.js +190 -0
  74. package/skinny/dist/react-utils-118d8539.js.map +1 -0
  75. package/skinny/dist/react-utils-2a2fd6c9.js +339 -0
  76. package/skinny/dist/react-utils-2a2fd6c9.js.map +1 -0
  77. package/skinny/dist/react-utils-2d70bbbe.js +172 -0
  78. package/skinny/dist/react-utils-2d70bbbe.js.map +1 -0
  79. package/skinny/dist/react-utils-35cb2a4e.js +201 -0
  80. package/skinny/dist/react-utils-35cb2a4e.js.map +1 -0
  81. package/skinny/dist/react-utils-675565b4.js +334 -0
  82. package/skinny/dist/react-utils-675565b4.js.map +1 -0
  83. package/skinny/dist/render/PlasmicImg/index.js +3 -3
  84. package/skinny/dist/render/PlasmicImg/index.js.map +1 -1
  85. package/skinny/dist/render/PlasmicImg.d.ts +62 -0
  86. package/skinny/dist/render/triggers.d.ts +4 -4
  87. package/skinny/dist/ssr-64e38713.js +108 -0
  88. package/skinny/dist/ssr-64e38713.js.map +1 -0
  89. package/skinny/dist/ssr-902d1292.js +105 -0
  90. package/skinny/dist/ssr-902d1292.js.map +1 -0
  91. package/skinny/dist/ssr-a8081074.js +108 -0
  92. package/skinny/dist/ssr-a8081074.js.map +1 -0
  93. package/skinny/dist/ssr-d2fd94f2.js +31 -0
  94. package/skinny/dist/ssr-d2fd94f2.js.map +1 -0
  95. package/skinny/dist/states/helpers.d.ts +9 -0
  96. package/skinny/dist/states/index.d.ts +7 -7
  97. package/skinny/dist/stories/UseDollarState.stories.d.ts +41 -0
  98. package/skinny/dist/tslib.es6-00014098.js +148 -0
  99. package/skinny/dist/tslib.es6-00014098.js.map +1 -0
  100. package/skinny/dist/tslib.es6-73236e8e.js +141 -0
  101. package/skinny/dist/tslib.es6-73236e8e.js.map +1 -0
  102. package/README +0 -8
@@ -18,7 +18,7 @@ import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
18
18
  import { useSelectState } from '@react-stately/select';
19
19
  import { useSwitch as useSwitch$1 } from '@react-aria/switch';
20
20
  import { useOverlay, useOverlayPosition, DismissButton } from '@react-aria/overlays';
21
- import get from 'dlv';
21
+ import _get from 'dlv';
22
22
  import { dset } from 'dset';
23
23
 
24
24
  function _extends() {
@@ -1199,6 +1199,96 @@ function isInternalHref(href) {
1199
1199
  return /^\/(?!\/)/.test(href);
1200
1200
  }
1201
1201
 
1202
+ var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
1203
+
1204
+ function isIterable(val) {
1205
+ return val != null && typeof val[Symbol.iterator] === "function";
1206
+ }
1207
+
1208
+ function genTranslatableString(elt) {
1209
+ var components = {};
1210
+ var componentsCount = 0;
1211
+
1212
+ var getText = function getText(node) {
1213
+ if (!node) {
1214
+ return "";
1215
+ }
1216
+
1217
+ if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
1218
+ return node.toString();
1219
+ }
1220
+
1221
+ if (typeof node !== "object") {
1222
+ return "";
1223
+ }
1224
+
1225
+ if (Array.isArray(node) || isIterable(node)) {
1226
+ return Array.from(node).map(function (child) {
1227
+ return getText(child);
1228
+ }).filter(function (child) {
1229
+ return !!child;
1230
+ }).join("");
1231
+ }
1232
+
1233
+ var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
1234
+ var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
1235
+ return getText(child);
1236
+ }).filter(function (child) {
1237
+ return !!child;
1238
+ }).join("");
1239
+
1240
+ if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
1241
+ return contents;
1242
+ }
1243
+
1244
+ var componentId = componentsCount + 1;
1245
+ componentsCount++;
1246
+ components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
1247
+ key: componentId,
1248
+ children: undefined
1249
+ }) : node;
1250
+ return "<" + componentId + ">" + contents + "</" + componentId + ">";
1251
+ };
1252
+
1253
+ var str = getText(elt);
1254
+ return {
1255
+ str: str,
1256
+ components: components,
1257
+ componentsCount: componentsCount
1258
+ };
1259
+ }
1260
+ function Trans(_ref) {
1261
+ var children = _ref.children;
1262
+
1263
+ var _t = React__default.useContext(PlasmicTranslatorContext);
1264
+
1265
+ if (!_t) {
1266
+ warnNoTranslationFunctionAtMostOnce();
1267
+ return children;
1268
+ }
1269
+
1270
+ var _genTranslatableStrin = genTranslatableString(children),
1271
+ str = _genTranslatableStrin.str,
1272
+ components = _genTranslatableStrin.components,
1273
+ componentsCount = _genTranslatableStrin.componentsCount;
1274
+
1275
+ return _t(str, componentsCount > 0 ? {
1276
+ components: components
1277
+ } : undefined);
1278
+ }
1279
+ var hasWarned = false;
1280
+
1281
+ function warnNoTranslationFunctionAtMostOnce() {
1282
+ if (!hasWarned) {
1283
+ console.warn("Using Plasmic Translation but no translation function has been provided");
1284
+ hasWarned = true;
1285
+ }
1286
+ }
1287
+
1288
+ function hasKey(v, key) {
1289
+ return typeof v === "object" && v !== null && key in v;
1290
+ }
1291
+
1202
1292
  function PlasmicSlot(props) {
1203
1293
  return renderPlasmicSlot(props);
1204
1294
  }
@@ -1242,7 +1332,8 @@ function renderPlasmicSlot(opts) {
1242
1332
 
1243
1333
  function maybeAsString(node) {
1244
1334
  // Unwrap fragments
1245
- if (isValidElement(node) && node.type === Fragment) {
1335
+ if (isValidElement(node) && ( // Fragment and Trans don't render DOM elements
1336
+ node.type === Fragment || node.type === Trans)) {
1246
1337
  return maybeAsString(node.props.children);
1247
1338
  }
1248
1339
 
@@ -1353,96 +1444,6 @@ function createUseScreenVariants(isMulti, screenQueries) {
1353
1444
  };
1354
1445
  }
1355
1446
 
1356
- var PlasmicTranslatorContext = /*#__PURE__*/React__default.createContext(undefined);
1357
-
1358
- function isIterable(val) {
1359
- return val != null && typeof val[Symbol.iterator] === "function";
1360
- }
1361
-
1362
- function genTranslatableString(elt) {
1363
- var components = {};
1364
- var componentsCount = 0;
1365
-
1366
- var getText = function getText(node) {
1367
- if (!node) {
1368
- return "";
1369
- }
1370
-
1371
- if (typeof node === "number" || typeof node === "boolean" || typeof node === "string") {
1372
- return node.toString();
1373
- }
1374
-
1375
- if (typeof node !== "object") {
1376
- return "";
1377
- }
1378
-
1379
- if (Array.isArray(node) || isIterable(node)) {
1380
- return Array.from(node).map(function (child) {
1381
- return getText(child);
1382
- }).filter(function (child) {
1383
- return !!child;
1384
- }).join("");
1385
- }
1386
-
1387
- var nodeChildren = hasKey(node, "props") && hasKey(node.props, "children") && node.props.children || hasKey(node, "children") && node.children || [];
1388
- var contents = "" + React__default.Children.toArray(nodeChildren).map(function (child) {
1389
- return getText(child);
1390
- }).filter(function (child) {
1391
- return !!child;
1392
- }).join("");
1393
-
1394
- if (React__default.isValidElement(node) && node.type === React__default.Fragment) {
1395
- return contents;
1396
- }
1397
-
1398
- var componentId = componentsCount + 1;
1399
- componentsCount++;
1400
- components[componentId] = React__default.isValidElement(node) ? React__default.cloneElement(node, {
1401
- key: componentId,
1402
- children: undefined
1403
- }) : node;
1404
- return "<" + componentId + ">" + contents + "</" + componentId + ">";
1405
- };
1406
-
1407
- var str = getText(elt);
1408
- return {
1409
- str: str,
1410
- components: components,
1411
- componentsCount: componentsCount
1412
- };
1413
- }
1414
- function Trans(_ref) {
1415
- var children = _ref.children;
1416
-
1417
- var _t = React__default.useContext(PlasmicTranslatorContext);
1418
-
1419
- if (!_t) {
1420
- warnNoTranslationFunctionAtMostOnce();
1421
- return children;
1422
- }
1423
-
1424
- var _genTranslatableStrin = genTranslatableString(children),
1425
- str = _genTranslatableStrin.str,
1426
- components = _genTranslatableStrin.components,
1427
- componentsCount = _genTranslatableStrin.componentsCount;
1428
-
1429
- return _t(str, componentsCount > 0 ? {
1430
- components: components
1431
- } : undefined);
1432
- }
1433
- var hasWarned = false;
1434
-
1435
- function warnNoTranslationFunctionAtMostOnce() {
1436
- if (!hasWarned) {
1437
- console.warn("Using Plasmic Translation but no translation function has been provided");
1438
- hasWarned = true;
1439
- }
1440
- }
1441
-
1442
- function hasKey(v, key) {
1443
- return typeof v === "object" && v !== null && key in v;
1444
- }
1445
-
1446
1447
  var PlasmicRootContext = /*#__PURE__*/createContext(undefined);
1447
1448
  function PlasmicRootProvider(props) {
1448
1449
  var platform = props.platform,
@@ -3117,40 +3118,24 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef) {
3117
3118
  };
3118
3119
  }
3119
3120
 
3120
- var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
3121
- function keyBy(list, keyFunc) {
3122
- var keyedObject = {};
3123
-
3124
- for (var _iterator = _createForOfIteratorHelperLoose(list), _step; !(_step = _iterator()).done;) {
3125
- var val = _step.value;
3126
- keyedObject[keyFunc(val)] = val;
3127
- }
3128
-
3129
- return keyedObject;
3121
+ function generateStateOnChangeProp($state, stateName, dataReps) {
3122
+ return function (val, path) {
3123
+ return dset($state, [stateName].concat(dataReps, path), val);
3124
+ };
3130
3125
  }
3126
+ /**
3127
+ * This function generate the state value prop for repeated states
3128
+ * Example:
3129
+ * - parent[][].counter[].count
3130
+ * We need to pass `parent[index1][index2].counter to the child component
3131
+ */
3131
3132
 
3132
- function getObjectAtPath($state, path) {
3133
- var parts = path.split(".");
3134
- var parts2 = parts.slice(0, parts.length - 1);
3135
-
3136
- if (parts2.length === 0) {
3137
- return $state;
3138
- }
3139
-
3140
- var existing = get($state, parts2);
3141
-
3142
- if (existing) {
3143
- return existing;
3144
- }
3145
-
3146
- var newObj = {};
3147
- dset($state, parts2, newObj);
3148
- return newObj;
3133
+ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
3134
+ ) {
3135
+ return _get($state, path);
3149
3136
  }
3150
3137
 
3151
- function isRendering() {
3152
- return !!React__default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current;
3153
- }
3138
+ var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
3154
3139
 
3155
3140
  function shallowEqual(a1, a2) {
3156
3141
  if (a1.length !== a2.length) {
@@ -3166,289 +3151,441 @@ function shallowEqual(a1, a2) {
3166
3151
  return true;
3167
3152
  }
3168
3153
 
3169
- function useVanillaDollarState(specs, props) {
3170
- var _React$useState = React__default.useState(function () {
3154
+ var isNum = function isNum(value) {
3155
+ return typeof value === "symbol" ? false : !isNaN(+value);
3156
+ };
3157
+
3158
+ function mkProxy(specs, maybeHandlers) {
3159
+ var handlers = maybeHandlers != null ? maybeHandlers : function () {
3171
3160
  return {
3172
- stateValues: Object.fromEntries(specs.map(function (spec) {
3173
- return [spec.path, // If the initial value depends on initFunc, then we initialize
3174
- // it to this special UNINITIALIZED symbol. We can't just run
3175
- // spec.initFunc() here, because the expression may read from
3176
- // $state, which is not yet initialized. Instead, we will
3177
- // lazily compute and initialize this at get() time.
3178
- spec.initFunc ? UNINITIALIZED : spec.initVal];
3179
- })),
3180
- initStateValues: Object.fromEntries(specs.filter(function (spec) {
3181
- return !spec.initFunc;
3182
- }).map(function (spec) {
3183
- return [spec.path, spec.initVal];
3184
- })),
3185
- initStateDeps: {},
3186
- fireOnChange: {}
3161
+ get: function get(target, property) {
3162
+ return target[property];
3163
+ },
3164
+ set: function set(target, property, value) {
3165
+ return (target[property] = value) || true;
3166
+ }
3187
3167
  };
3188
- }),
3189
- _$$state = _React$useState[0],
3190
- set$$State = _React$useState[1]; // We have a weird scheme here to reduce the number of state updates.
3191
- // Whenever user does a $state get() or set(), we may end up initializing
3192
- // a bunch of values. We don't want to call set$$State() a bunch of times.
3193
- // Instead, we will fork as we need to, and call set$$State() at the end of
3194
- // the hook and at the end of get() / set() as appropriate.
3195
- // $$state here is going to be copied-on-write; once copied, it will
3196
- // be directly mutated. Since $state will always be directly proxying $$state,
3197
- // that means you can "read what you wrote": after $state.count = $state.count + 1,
3198
- // if you read $state.count again, it will reflect the latest value.
3199
- //
3200
- // There are three places where we might actually call set$$State():
3201
- // 1. At the end of a "top-level" get(): we may have ended up initializing
3202
- // some state values.
3203
- // 2. At the end of a "top-level" set(): we mutated this value, but also
3204
- // may have reset some other state values that depended on this one.
3205
- // 3. At the end of the hook, where we compare the new initial value with
3206
- // the previous initial value.
3207
-
3208
-
3209
- var $$state = _extends({}, _$$state);
3210
-
3211
- var dirtyFields = {
3212
- stateValues: false,
3213
- initStateValues: false,
3214
- initStateDeps: false,
3215
- fireOnChange: false
3216
3168
  };
3217
3169
 
3218
- function makeDirty(field, copy) {
3219
- if (!dirtyFields[field]) {
3220
- dirtyFields[field] = true;
3221
- $$state[field] = copy($$state[field]);
3222
- }
3223
- }
3224
-
3225
- function updateStateValue(path, value) {
3226
- makeDirty("stateValues", function (x) {
3227
- return _extends({}, x);
3228
- });
3229
- console.log("UPDATE state value:", path, value);
3230
- $$state.stateValues[path] = value; // If any other state depends on this one, then reset their
3231
- // values to their initial as well
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
+ **/
3232
3196
 
3233
- for (var _i = 0, _Object$entries = Object.entries($$state.initStateDeps); _i < _Object$entries.length; _i++) {
3234
- var _Object$entries$_i = _Object$entries[_i],
3235
- key = _Object$entries$_i[0],
3236
- deps = _Object$entries$_i[1];
3237
3197
 
3238
- if (deps.includes(path)) {
3239
- resetPath(key);
3240
- }
3198
+ var cloneValue = function cloneValue(target, currPath, value) {
3199
+ if (typeof value !== "object") {
3200
+ return;
3241
3201
  }
3242
3202
 
3243
- var spec = specByPath[path];
3203
+ var nextParts = getNextParts(currPath);
3244
3204
 
3245
- if (spec.onChangeProp) {
3246
- if (isRendering()) {
3247
- // If we're currently rendering this component, then we
3248
- // CANNOT fire the event handler, as it is illegal to set
3249
- // the state of another component during rendering.
3250
- // Instead, we save it into our internal state, and fire
3251
- // it later in a layout effect.
3252
- updateFireOnChange(spec.path, value);
3253
- } else {
3254
- var _props$spec$onChangeP;
3255
-
3256
- // Most of the time, state changes outside of rendering
3257
- // (in an event handler), and we just directly call the
3258
- // onChange
3259
- (_props$spec$onChangeP = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP.call(props, value);
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
+ }
3260
3227
  }
3261
3228
  }
3262
- }
3229
+ };
3263
3230
 
3264
- function updateInitStateValue(path, value) {
3265
- makeDirty("initStateValues", function (x) {
3266
- return _extends({}, x);
3267
- });
3268
- console.log("UPDATE initValue:", path, value);
3269
- $$state.initStateValues[path] = value;
3270
- }
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
+ }
3271
3246
 
3272
- function updateInitStateDeps(path, deps) {
3273
- makeDirty("initStateDeps", function (x) {
3274
- return _extends({}, x);
3275
- });
3276
- console.log("UPDATE DEPS: " + path, deps);
3277
- $$state.initStateDeps[path] = deps;
3278
- }
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
+ }
3279
3266
 
3280
- function updateInternalStateIfDirty() {
3281
- if (Object.values(dirtyFields).some(function (x) {
3282
- return x;
3283
- })) {
3284
- console.log("UPDATE $$STATE");
3285
- set$$State($$state);
3286
- }
3287
- }
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
+ }
3288
3285
 
3289
- function updateFireOnChange(path, value) {
3290
- makeDirty("fireOnChange", function (x) {
3291
- return _extends({}, x);
3292
- });
3293
- $$state.fireOnChange[path] = value;
3294
- }
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
+ }
3295
3291
 
3296
- console.log("useDollarState", _extends({}, _$$state));
3297
- var specByPath = React__default.useMemo(function () {
3298
- return keyBy(specs, function (spec) {
3299
- return spec.path;
3292
+ return true;
3293
+ }
3300
3294
  });
3301
- }, [specs]);
3302
- var stateAccessStack = [{}];
3303
- var $props = props;
3304
- /**
3305
- * Runs spec.initFunc, keeping track of the state accesses
3306
- * that occurred while running it
3307
- */
3308
-
3309
- function trackedInit(spec) {
3310
- var _$$state$initStateDep;
3295
+ };
3311
3296
 
3312
- var stateAccess = {};
3313
- stateAccessStack.push(stateAccess);
3314
- var res = spec.initFunc($props, $state);
3315
- var deps = Object.keys(stateAccess);
3297
+ return rec([]);
3298
+ }
3316
3299
 
3317
- if (!shallowEqual(deps, (_$$state$initStateDep = $$state.initStateDeps[spec.path]) != null ? _$$state$initStateDep : [])) {
3318
- updateInitStateDeps(spec.path, deps);
3319
- }
3300
+ function cloneProxy(specs, states, obj) {
3301
+ var newObj = mkProxy(specs);
3302
+ Object.values(states).forEach(function (_ref) {
3303
+ var path = _ref.path;
3320
3304
 
3321
- stateAccessStack.pop();
3322
- return res;
3323
- }
3324
- /**
3325
- * Resets the value for this state
3326
- */
3305
+ dset(newObj, path, _get(obj, path));
3306
+ });
3307
+ return newObj;
3308
+ }
3327
3309
 
3310
+ function saveState(state, states) {
3311
+ states[JSON.stringify(state.path)] = state;
3312
+ }
3328
3313
 
3329
- function resetPath(path) {
3330
- // Resets the value for this state
3331
- var spec = specByPath[path];
3332
- var initValue = trackedInit(spec);
3314
+ function hasState(state, states) {
3315
+ return JSON.stringify(state.path) in states;
3316
+ }
3333
3317
 
3334
- if (initValue !== $$state.stateValues[spec.path]) {
3335
- updateStateValue(spec.path, initValue);
3336
- }
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
+ };
3337
3323
 
3338
- if (initValue !== $$state.initStateValues[spec.path]) {
3339
- updateInitStateValue(spec.path, initValue);
3340
- }
3324
+ return str.split(".").flatMap(splitStatePathPart);
3325
+ };
3341
3326
 
3342
- return initValue;
3343
- } // Since a get() or a set() may result in other get() or set(),
3344
- // we keep track of whether we're at the "top-level" so we know
3345
- // whether to update state at the end.
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;
3346
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];
3347
3359
 
3348
- var accessLevel = 0;
3349
- var $state = {};
3360
+ if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
3361
+ delete $$state.states[key];
3362
+ }
3363
+ }
3350
3364
 
3351
- var _loop = function _loop() {
3352
- var spec = _step2.value;
3353
- var parts = spec.path.split(".");
3354
- var name = parts[parts.length - 1];
3355
- var obj = getObjectAtPath($state, spec.path); // Define get() and set() for this state cell
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];
3356
3372
 
3357
- Object.defineProperty(obj, name, {
3358
- get: function get() {
3359
3373
  if (spec.valueProp) {
3360
- return props[spec.valueProp];
3374
+ if (!spec.isRepeated) {
3375
+ return props[spec.valueProp];
3376
+ } else {
3377
+ return _get(props[spec.valueProp], state.path.slice(1));
3378
+ }
3361
3379
  }
3362
3380
 
3363
- accessLevel += 1;
3364
- var value = $$state.stateValues[spec.path];
3381
+ if (!hasState(state, $$state.states)) {
3382
+ var _spec$initVal;
3365
3383
 
3366
- if (value === UNINITIALIZED) {
3367
- // This value has a init expression; need to be evaluated.
3368
- value = resetPath(spec.path);
3369
- } // Record that this field had just been accessed; for
3370
- // trackInit() to know what fields were used to compute
3371
- // the init value
3384
+ saveState(state, $$state.states);
3385
+
3386
+ dset($$state.stateValues, state.path, spec.initFunc ? UNINITIALIZED : (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
3372
3387
 
3388
+ var deps = spec.initFunc ? fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states) : {};
3373
3389
 
3374
- stateAccessStack[stateAccessStack.length - 1][spec.path] = true;
3375
- accessLevel -= 1;
3390
+ dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
3376
3391
 
3377
- if (accessLevel === 0) {
3378
- updateInternalStateIfDirty();
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;
3379
3397
  }
3380
3398
 
3381
- return value;
3399
+ return _get($$state.stateValues, state.path);
3382
3400
  },
3383
- set: function set(newValue) {
3384
- accessLevel += 1;
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];
3385
3411
 
3386
- if (newValue !== $$state.stateValues[spec.path]) {
3387
- updateStateValue(spec.path, newValue);
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
+ });
3388
3422
  }
3389
3423
 
3390
- accessLevel -= 1;
3424
+ var spec = $$state.specs[state.specKey];
3391
3425
 
3392
- if (accessLevel === 0) {
3393
- updateInternalStateIfDirty();
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);
3394
3430
  }
3395
- }
3396
- });
3397
- };
3398
3431
 
3399
- for (var _iterator2 = _createForOfIteratorHelperLoose(specs), _step2; !(_step2 = _iterator2()).done;) {
3400
- _loop();
3401
- } // For each spec with an initFunc, evaluate it and see if
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
3402
3453
  // the init value has changed. If so, reset its state.
3403
3454
 
3455
+ var newStateValues = undefined;
3456
+ var resetSpecs = [];
3404
3457
 
3405
- for (var _iterator3 = _createForOfIteratorHelperLoose(specs), _step3; !(_step3 = _iterator3()).done;) {
3406
- var spec = _step3.value;
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];
3407
3463
 
3408
3464
  if (spec.initFunc) {
3409
- var newInit = spec.initFunc($props, $state);
3465
+ var newInit = spec.initFunc(props, $state);
3410
3466
 
3411
- if (newInit !== $$state.initStateValues[spec.path]) {
3412
- console.log("init changed for " + spec.path + " from " + $$state.initStateValues[spec.path] + " to " + newInit + "; resetting state");
3413
- updateInitStateValue(spec.path, newInit);
3414
- updateStateValue(spec.path, newInit);
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
+ });
3415
3473
 
3416
- if (spec.onChangeProp) {
3417
- updateFireOnChange(spec.path, newInit);
3474
+ if (!newStateValues) {
3475
+ newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
3418
3476
  }
3477
+
3478
+ dset(newStateValues, path, UNINITIALIZED);
3419
3479
  }
3420
3480
  }
3421
3481
  }
3422
3482
 
3423
- var fireOnChange = $$state.fireOnChange;
3424
3483
  React__default.useLayoutEffect(function () {
3425
- if (Object.keys(fireOnChange).length > 0) {
3426
- for (var _i2 = 0, _Object$entries2 = Object.entries(fireOnChange); _i2 < _Object$entries2.length; _i2++) {
3427
- var _Object$entries2$_i = _Object$entries2[_i2],
3428
- path = _Object$entries2$_i[0],
3429
- value = _Object$entries2$_i[1];
3430
- var spec = specByPath[path];
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;
3431
3489
 
3432
- if (spec.onChangeProp) {
3433
- var _props$spec$onChangeP2;
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;
3434
3507
 
3435
- (_props$spec$onChangeP2 = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP2.call(props, value);
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));
3436
3510
  }
3437
3511
  }
3438
-
3439
- set$$State(function (prev) {
3440
- return _extends({}, prev, {
3441
- fireOnChange: {}
3442
- });
3443
- });
3444
3512
  }
3445
- }, [fireOnChange, props, specByPath]); // update state if the above did some writes.
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
+ }
3446
3528
 
3447
- updateInternalStateIfDirty();
3448
3529
  return $state;
3449
3530
  }
3450
3531
 
3451
- var useDollarState = useVanillaDollarState;
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
+ }
3452
3589
 
3453
- export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, Stack, Trans, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3590
+ export { DropdownMenu, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, omit, pick, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useVanillaDollarState as useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3454
3591
  //# sourceMappingURL=react-web.esm.js.map