@plasmicapp/react-web 0.2.110 → 0.2.112

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 (74) hide show
  1. package/dist/all.d.ts +30 -13
  2. package/dist/index-common.d.ts +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/react-web.cjs.development.js +366 -342
  5. package/dist/react-web.cjs.development.js.map +1 -1
  6. package/dist/react-web.cjs.production.min.js +1 -1
  7. package/dist/react-web.cjs.production.min.js.map +1 -1
  8. package/dist/react-web.esm.js +363 -342
  9. package/dist/react-web.esm.js.map +1 -1
  10. package/dist/render/elements.d.ts +5 -0
  11. package/dist/states/helpers.d.ts +5 -0
  12. package/dist/states/index.d.ts +1 -1
  13. package/dist/states/valtio.d.ts +16 -0
  14. package/dist/stories/UseDollarState.stories.d.ts +11 -0
  15. package/package.json +6 -2
  16. package/skinny/dist/collection-utils-42de4441.js +244 -0
  17. package/skinny/dist/collection-utils-42de4441.js.map +1 -0
  18. package/skinny/dist/{collection-utils-3487dd27.js → collection-utils-bf37b8fb.js} +5 -5
  19. package/skinny/dist/collection-utils-bf37b8fb.js.map +1 -0
  20. package/skinny/dist/common-98719219.js +68 -0
  21. package/skinny/dist/common-98719219.js.map +1 -0
  22. package/skinny/dist/common-9efbae57.js +201 -0
  23. package/skinny/dist/common-9efbae57.js.map +1 -0
  24. package/skinny/dist/context-4ca6f5cd.js +6 -0
  25. package/skinny/dist/context-4ca6f5cd.js.map +1 -0
  26. package/skinny/dist/index-common.d.ts +1 -1
  27. package/skinny/dist/index.d.ts +1 -1
  28. package/skinny/dist/index.js +17 -4
  29. package/skinny/dist/index.js.map +1 -1
  30. package/skinny/dist/plume/checkbox/index.js +2 -1
  31. package/skinny/dist/plume/checkbox/index.js.map +1 -1
  32. package/skinny/dist/plume/menu/index.js +2 -1
  33. package/skinny/dist/plume/menu/index.js.map +1 -1
  34. package/skinny/dist/plume/menu-button/index.js +2 -1
  35. package/skinny/dist/plume/menu-button/index.js.map +1 -1
  36. package/skinny/dist/plume/select/index.js +2 -1
  37. package/skinny/dist/plume/select/index.js.map +1 -1
  38. package/skinny/dist/plume/switch/index.js +2 -1
  39. package/skinny/dist/plume/switch/index.js.map +1 -1
  40. package/skinny/dist/plume-utils-1e225de5.js +25 -0
  41. package/skinny/dist/plume-utils-1e225de5.js.map +1 -0
  42. package/skinny/dist/plume-utils-d2476af1.js +35 -0
  43. package/skinny/dist/plume-utils-d2476af1.js.map +1 -0
  44. package/skinny/dist/props-utils-c60d3105.js +8 -0
  45. package/skinny/dist/props-utils-c60d3105.js.map +1 -0
  46. package/skinny/dist/props-utils-cac0cccf.js +8 -0
  47. package/skinny/dist/props-utils-cac0cccf.js.map +1 -0
  48. package/skinny/dist/react-utils-6050fadc.js +201 -0
  49. package/skinny/dist/react-utils-6050fadc.js.map +1 -0
  50. package/skinny/dist/react-utils-b5dc6320.js +155 -0
  51. package/skinny/dist/react-utils-b5dc6320.js.map +1 -0
  52. package/skinny/dist/render/elements.d.ts +5 -0
  53. package/skinny/dist/{ssr-84e27ffb.js → ssr-68913b60.js} +34 -37
  54. package/skinny/dist/ssr-68913b60.js.map +1 -0
  55. package/skinny/dist/{ssr-b1615b80.js → ssr-d3321868.js} +9 -4
  56. package/skinny/dist/ssr-d3321868.js.map +1 -0
  57. package/skinny/dist/states/helpers.d.ts +5 -0
  58. package/skinny/dist/states/index.d.ts +1 -1
  59. package/skinny/dist/states/valtio copy.d.ts +15 -0
  60. package/skinny/dist/states/valtio.d.ts +16 -0
  61. package/skinny/dist/stories/UseDollarState.stories.d.ts +11 -0
  62. package/skinny/dist/stories/UseDollarState.test.d.ts +11 -0
  63. package/skinny/dist/stories/UseDollarState2.stories.d.ts +7 -0
  64. package/skinny/dist/collection-utils-3487dd27.js.map +0 -1
  65. package/skinny/dist/ssr-14264281.js +0 -158
  66. package/skinny/dist/ssr-14264281.js.map +0 -1
  67. package/skinny/dist/ssr-5141fc77.js +0 -158
  68. package/skinny/dist/ssr-5141fc77.js.map +0 -1
  69. package/skinny/dist/ssr-579df58f.js +0 -158
  70. package/skinny/dist/ssr-579df58f.js.map +0 -1
  71. package/skinny/dist/ssr-84e27ffb.js.map +0 -1
  72. package/skinny/dist/ssr-b1615b80.js.map +0 -1
  73. package/skinny/dist/ssr-d2fd94f2.js +0 -31
  74. package/skinny/dist/ssr-d2fd94f2.js.map +0 -1
@@ -1,7 +1,9 @@
1
1
  import classNames$1 from 'classnames';
2
+ import _get from 'dlv';
2
3
  import * as React from 'react';
3
4
  import React__default, { forwardRef, createElement, Fragment, isValidElement, useContext, createContext, useState, useRef, useMemo, useImperativeHandle, useCallback, cloneElement } from 'react';
4
5
  import ReactDOM__default, { createPortal } from 'react-dom';
6
+ import { PlasmicDataSourceContextProvider } from '@plasmicapp/data-sources-context';
5
7
  import { SSRProvider, useIsSSR as useIsSSR$1 } from '@react-aria/ssr';
6
8
  import { useFocusRing, useFocusable, FocusScope } from '@react-aria/focus';
7
9
  import { useCheckbox as useCheckbox$1 } from '@react-aria/checkbox';
@@ -18,8 +20,9 @@ import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
18
20
  import { useSelectState } from '@react-stately/select';
19
21
  import { useSwitch as useSwitch$1 } from '@react-aria/switch';
20
22
  import { useOverlay, useOverlayPosition, DismissButton } from '@react-aria/overlays';
21
- import _get from 'dlv';
22
- import { dset } from 'dset';
23
+ import deepEqual from 'fast-deep-equal';
24
+ import { proxy, ref, useSnapshot } from 'valtio';
25
+ import { subscribeKey } from 'valtio/utils';
23
26
 
24
27
  function _extends() {
25
28
  _extends = Object.assign || function (target) {
@@ -685,6 +688,14 @@ function mergeVariants(v1, v2) {
685
688
  return _extends({}, v1, v2);
686
689
  }
687
690
 
691
+ function mergeVariantsWithStates(variants, $state, linkedStates) {
692
+ return _extends({}, variants, Object.fromEntries(linkedStates.map(function (_ref) {
693
+ var variantGroup = _ref.variantGroup,
694
+ statePath = _ref.statePath;
695
+ return [variantGroup, _get($state, statePath)];
696
+ })));
697
+ }
698
+
688
699
  function mergeArgs(a1, a2) {
689
700
  if (!a1 || !a2) {
690
701
  return a1 || a2 || {};
@@ -710,7 +721,7 @@ function mergeFlexOverrides(o1, o2) {
710
721
  }
711
722
 
712
723
  function mergeFlexOverride(fo1, fo2) {
713
- var _o1$props, _ref;
724
+ var _o1$props, _ref2;
714
725
 
715
726
  if (!fo1) {
716
727
  return fo2;
@@ -746,7 +757,7 @@ function mergeFlexOverride(fo1, fo2) {
746
757
  } // "as" will take precedence
747
758
 
748
759
 
749
- var as = (_ref = o2.type === "as" ? o2.as : undefined) != null ? _ref : o1.type === "as" ? o1.as : undefined;
760
+ var as = (_ref2 = o2.type === "as" ? o2.as : undefined) != null ? _ref2 : o1.type === "as" ? o1.as : undefined;
750
761
  return _extends({
751
762
  props: props,
752
763
  wrap: wrap,
@@ -1531,19 +1542,27 @@ function createUseScreenVariants(isMulti, screenQueries) {
1531
1542
  var PlasmicRootContext = /*#__PURE__*/createContext(undefined);
1532
1543
  function PlasmicRootProvider(props) {
1533
1544
  var platform = props.platform,
1534
- children = props.children;
1545
+ children = props.children,
1546
+ userAuthToken = props.userAuthToken;
1535
1547
  var context = useMemo(function () {
1536
1548
  return {
1537
1549
  platform: platform
1538
1550
  };
1539
1551
  }, [platform]);
1552
+ var dataSourceContextValue = useMemo(function () {
1553
+ return {
1554
+ userAuthToken: userAuthToken
1555
+ };
1556
+ }, [userAuthToken]);
1540
1557
  return createElement(PlasmicRootContext.Provider, {
1541
1558
  value: context
1542
- }, createElement(SSRProvider, null, createElement(PlasmicTranslatorContext.Provider, {
1559
+ }, createElement(SSRProvider, null, createElement(PlasmicDataSourceContextProvider, {
1560
+ value: dataSourceContextValue
1561
+ }, createElement(PlasmicTranslatorContext.Provider, {
1543
1562
  value: props.translator
1544
1563
  }, createElement(PlasmicHeadContext.Provider, {
1545
1564
  value: props.Head
1546
- }, children))));
1565
+ }, children)))));
1547
1566
  }
1548
1567
  var useIsSSR = useIsSSR$1;
1549
1568
  function useHasPlasmicRoot() {
@@ -3210,7 +3229,7 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
3210
3229
 
3211
3230
  function generateStateOnChangeProp($state, stateName, dataReps) {
3212
3231
  return function (val, path) {
3213
- return dset($state, [stateName].concat(dataReps, path), val);
3232
+ return set($state, [stateName].concat(dataReps, path), val);
3214
3233
  };
3215
3234
  }
3216
3235
  /**
@@ -3224,8 +3243,51 @@ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
3224
3243
  ) {
3225
3244
  return _get($state, path);
3226
3245
  }
3246
+ /**
3247
+ * Forked from https://github.com/lukeed/dset
3248
+ * Changes: fixed setting a deep value to a proxy object
3249
+ */
3227
3250
 
3228
- var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
3251
+ function set(obj, keys, val) {
3252
+ keys = keys.split ? keys.split(".") : keys;
3253
+ var i = 0,
3254
+ l = keys.length,
3255
+ t = obj,
3256
+ x,
3257
+ k;
3258
+
3259
+ while (i < l) {
3260
+ k = keys[i++];
3261
+ if (k === "__proto__" || k === "constructor" || k === "prototype") break;
3262
+
3263
+ if (i === l) {
3264
+ t[k] = val;
3265
+ t = t[k];
3266
+ } else {
3267
+ if (typeof (x = t[k]) === typeof keys) {
3268
+ t = t[k] = x;
3269
+ } else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
3270
+ t[k] = {};
3271
+ t = t[k];
3272
+ } else {
3273
+ t[k] = [];
3274
+ t = t[k];
3275
+ }
3276
+ }
3277
+ }
3278
+ }
3279
+
3280
+ var mkUntrackedValue = function mkUntrackedValue(o) {
3281
+ return typeof o === "object" ? ref(o) : o;
3282
+ };
3283
+
3284
+ var transformPathStringToObj = function transformPathStringToObj(str) {
3285
+ var splitStatePathPart = function splitStatePathPart(state) {
3286
+ return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
3287
+ };
3288
+
3289
+ return str.split(".").flatMap(splitStatePathPart);
3290
+ };
3229
3291
 
3230
3292
  function shallowEqual(a1, a2) {
3231
3293
  if (a1.length !== a2.length) {
@@ -3241,145 +3303,144 @@ function shallowEqual(a1, a2) {
3241
3303
  return true;
3242
3304
  }
3243
3305
 
3244
- var isNum = function isNum(value) {
3306
+ function isNum(value) {
3245
3307
  return typeof value === "symbol" ? false : !isNaN(+value);
3246
- };
3308
+ }
3247
3309
 
3248
- function mkProxy(specs, maybeHandlers) {
3249
- var handlers = maybeHandlers != null ? maybeHandlers : function () {
3250
- return {
3251
- get: function get(target, property) {
3252
- return target[property];
3253
- },
3254
- set: function set(target, property, value) {
3255
- return (target[property] = value) || true;
3256
- }
3257
- };
3258
- };
3310
+ function saveNewState($$state, path, spec) {
3311
+ var key = JSON.stringify(path);
3312
+ $$state.existingStates.set(key, {
3313
+ path: path,
3314
+ specKey: spec.path
3315
+ });
3316
+
3317
+ if (!$$state.statesInstanceBySpec.has(spec.path)) {
3318
+ $$state.statesInstanceBySpec.set(spec.path, []);
3319
+ }
3320
+
3321
+ $$state.statesInstanceBySpec.get(spec.path).push({
3322
+ path: path,
3323
+ specKey: spec.path
3324
+ });
3325
+ }
3259
3326
 
3260
- var getNextParts = function getNextParts(currPath) {
3261
- return Object.fromEntries(Object.values(specs).filter(function (spec) {
3327
+ function create$StateProxy($$state, handlers) {
3328
+ var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
3329
+ return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
3262
3330
  return shallowEqual(currPath.map(function (p) {
3263
3331
  return isNum(p) ? "[]" : p;
3264
- }), spec.path.slice(0, currPath.length));
3265
- }).map(function (spec) {
3266
- var nextPart = spec.path[currPath.length];
3267
-
3268
- if (spec.path.length === currPath.length + 1) {
3269
- return [nextPart, {
3270
- isLast: true,
3271
- specKey: spec.pathStr
3272
- }];
3273
- } else {
3274
- return [nextPart, {
3275
- isLast: false,
3276
- specKey: spec.pathStr
3277
- }];
3332
+ }), spec.pathObj.slice(0, currPath.length));
3333
+ }).reduce(function (agg, spec) {
3334
+ var nextKey = spec.pathObj[currPath.length];
3335
+
3336
+ if (!(nextKey in agg)) {
3337
+ agg[nextKey] = [];
3278
3338
  }
3279
- }));
3280
- };
3281
- /**
3282
- * We use this function when we're setting a value in the middle of the state path.
3283
- * We can't just set the value, because we need to keep the proxy properties, so
3284
- * we use the specs to walk through the object and just set the value in the end of the path
3285
- **/
3286
3339
 
3340
+ agg[nextKey].push(spec);
3341
+ return agg;
3342
+ }, {})));
3343
+ };
3287
3344
 
3288
- var cloneValue = function cloneValue(target, currPath, value) {
3289
- if (typeof value !== "object") {
3290
- return;
3291
- }
3345
+ var rec = function rec(currPath) {
3346
+ var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
3292
3347
 
3293
- var nextParts = getNextParts(currPath);
3348
+ var getSpecForProperty = function getSpecForProperty(property) {
3349
+ var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
3294
3350
 
3295
- for (var _i = 0, _Object$entries = Object.entries(nextParts); _i < _Object$entries.length; _i++) {
3296
- var _Object$entries$_i = _Object$entries[_i],
3297
- nextPart = _Object$entries$_i[0],
3298
- _Object$entries$_i$ = _Object$entries$_i[1],
3299
- isLast = _Object$entries$_i$.isLast,
3300
- specKey = _Object$entries$_i$.specKey;
3351
+ return nextKeyToSpecs.has("[]") && isNum(property) ? (_nextKeyToSpecs$get = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get[0] : typeof property === "string" && nextKeyToSpecs.has(property) ? (_nextKeyToSpecs$get2 = nextKeyToSpecs.get(property)) == null ? void 0 : _nextKeyToSpecs$get2[0] : undefined;
3352
+ };
3301
3353
 
3302
- if (nextPart === "[]" && Array.isArray(value)) {
3303
- for (var i = 0; i < value.length; i++) {
3304
- cloneValue(target[i], [].concat(currPath, [i]), value[i]);
3305
- }
3306
- } else if (nextPart in value) {
3307
- if (isLast) {
3308
- var _handlers$set, _handlers;
3309
-
3310
- handlers == null ? void 0 : (_handlers$set = (_handlers = handlers({
3311
- specKey: specKey,
3312
- path: [].concat(currPath, [nextPart])
3313
- })).set) == null ? void 0 : _handlers$set.call(_handlers, target, nextPart, value[nextPart], undefined);
3314
- } else {
3315
- cloneValue(target[nextPart], [].concat(currPath, [nextPart]), value[nextPart]);
3316
- }
3317
- }
3318
- }
3319
- };
3354
+ var getNextPath = function getNextPath(property) {
3355
+ return [].concat(currPath, [isNum(property) ? +property : property]);
3356
+ };
3320
3357
 
3321
- var rec = function rec(currPath) {
3322
- var nextParts = getNextParts(currPath);
3323
- return new Proxy("[]" in nextParts ? [] : {}, {
3358
+ return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
3324
3359
  deleteProperty: function deleteProperty(target, property) {
3325
- if ("[]" in nextParts && isNum(property)) {
3326
- var _handlers$deletePrope, _handlers2;
3327
-
3328
- delete target[property];
3329
- handlers == null ? void 0 : (_handlers$deletePrope = (_handlers2 = handlers({
3330
- path: [].concat(currPath, [+property]),
3331
- specKey: nextParts["[]"].specKey
3332
- })).deleteProperty) == null ? void 0 : _handlers$deletePrope.call(_handlers2, target, property);
3333
- } else {
3334
- throw new Error("You can't delete a non-repeated property in the middle of the path");
3335
- }
3360
+ var prefixPath = getNextPath(property);
3361
+ var specKeysToUpdate = new Set();
3362
+ $$state.existingStates.forEach(function (_ref) {
3363
+ var path = _ref.path,
3364
+ specKey = _ref.specKey;
3365
+
3366
+ if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
3367
+ deleteState($$state, path);
3368
+ specKeysToUpdate.add(specKey);
3369
+ }
3370
+ });
3371
+ specKeysToUpdate.forEach(function (specKey) {
3372
+ var spec = $$state.specsByKey[specKey];
3336
3373
 
3337
- return true;
3374
+ if (spec.onChangeProp) {
3375
+ var _$$state$props$spec$o, _$$state$props;
3376
+
3377
+ (_$$state$props$spec$o = (_$$state$props = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o.call(_$$state$props, _get($$state.stateValues, currPath), currPath);
3378
+ }
3379
+ });
3380
+ return Reflect.deleteProperty(target, property);
3338
3381
  },
3339
3382
  get: function get(target, property, receiver) {
3340
- if ("[]" in nextParts && isNum(property)) {
3341
- if (!(property in target)) {
3342
- target[property] = rec([].concat(currPath, [+property]));
3343
- }
3344
- } else if (property in nextParts) {
3345
- if (nextParts[property].isLast) {
3346
- var _handlers$get, _handlers3;
3347
-
3348
- return target[property] = handlers == null ? void 0 : (_handlers$get = (_handlers3 = handlers({
3349
- path: [].concat(currPath, [property]),
3350
- specKey: nextParts[property].specKey
3351
- })).get) == null ? void 0 : _handlers$get.call(_handlers3, target, property, receiver);
3383
+ var spec = getSpecForProperty(property);
3384
+
3385
+ if (spec && typeof property !== "symbol") {
3386
+ var nextPath = getNextPath(property);
3387
+
3388
+ if (spec.pathObj.length === currPath.length + 1) {
3389
+ var _handlers$get, _handlers;
3390
+
3391
+ // reached the end of the spec
3392
+ target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
3352
3393
  } else if (!(property in target)) {
3353
- target[property] = rec([].concat(currPath, [property]));
3394
+ target[property] = rec(nextPath);
3354
3395
  }
3355
3396
  }
3356
3397
 
3357
- return target[property];
3398
+ return Reflect.get(target, property, receiver);
3358
3399
  },
3359
- set: function set(target, property, value, receiver) {
3360
- if ("[]" in nextParts && isNum(property)) {
3361
- if (!(property in target)) {
3362
- target[property] = rec([].concat(currPath, [+property]));
3363
- }
3364
- } else if (property in nextParts) {
3365
- if (nextParts[property].isLast) {
3366
- var _handlers$set2, _handlers$set3, _handlers4;
3367
-
3368
- target[property] = value;
3369
- return (_handlers$set2 = (_handlers$set3 = (_handlers4 = handlers({
3370
- path: [].concat(currPath, [property]),
3371
- specKey: nextParts[property].specKey
3372
- })).set) == null ? void 0 : _handlers$set3.call(_handlers4, target, property, value, receiver)) != null ? _handlers$set2 : false;
3400
+ set: function set$1(target, property, value, receiver) {
3401
+ var spec = getSpecForProperty(property);
3402
+ var nextPath = getNextPath(property);
3403
+
3404
+ if (spec && typeof property !== "symbol") {
3405
+ if (spec.pathObj.length === currPath.length + 1) {
3406
+ var _handlers$set, _handlers2;
3407
+
3408
+ // reached the end of the spec
3409
+ target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
3410
+ return Reflect.set(target, property, value, receiver);
3411
+ } else if (typeof value === "object") {
3412
+ target[property] = rec(nextPath);
3413
+
3414
+ for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
3415
+ var key = _Object$keys[_i];
3416
+ target[property][key] = value[key];
3417
+ }
3418
+
3419
+ return true;
3373
3420
  }
3374
3421
  }
3375
3422
 
3376
- if (property === "registerInitFunc") {
3377
- target[property] = value;
3378
- } else if (typeof value === "object") {
3379
- cloneValue(target[property], [].concat(currPath, [isNum(property) ? +property : property]), value);
3423
+ if (property === "registerInitFunc" && currPath.length === 0) {
3424
+ return Reflect.set(target, property, value, receiver);
3380
3425
  }
3381
3426
 
3382
- return true;
3427
+ if (nextKeyToSpecs.has("[]")) {
3428
+ var _nextKeyToSpecs$get3;
3429
+
3430
+ set($$state.stateValues, nextPath, value);
3431
+
3432
+ (_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
3433
+ if (spec != null && spec.onChangeProp) {
3434
+ var _$$state$props$spec$o2, _$$state$props2;
3435
+
3436
+ (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
3437
+ }
3438
+ });
3439
+ return Reflect.set(target, property, value, receiver);
3440
+ } // invalid setting a value that doesn't make part of the spec
3441
+
3442
+
3443
+ return false;
3383
3444
  }
3384
3445
  });
3385
3446
  };
@@ -3387,136 +3448,136 @@ function mkProxy(specs, maybeHandlers) {
3387
3448
  return rec([]);
3388
3449
  }
3389
3450
 
3390
- function cloneProxy(specs, states, obj) {
3391
- var newObj = mkProxy(specs);
3392
- Object.values(states).forEach(function (_ref) {
3393
- var path = _ref.path;
3451
+ var deleteState = function deleteState($$state, path) {
3452
+ var _$$state$unsubscripti;
3394
3453
 
3395
- dset(newObj, path, _get(obj, path));
3454
+ var key = JSON.stringify(path);
3455
+ (_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
3456
+ return f();
3396
3457
  });
3397
- return newObj;
3398
- }
3458
+ delete $$state.unsubscriptionsByState[key];
3459
+ $$state.existingStates["delete"](key); // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
3460
+ // delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
3461
+ };
3399
3462
 
3400
- function saveState(state, states) {
3401
- states[JSON.stringify(state.path)] = state;
3402
- }
3463
+ var getIndexes = function getIndexes(path, spec) {
3464
+ var indexes = [];
3403
3465
 
3404
- function hasState(state, states) {
3405
- return JSON.stringify(state.path) in states;
3406
- }
3466
+ if (path.length !== spec.pathObj.length) {
3467
+ throw new Error("Unexpected error: state path and spec path have different lengths");
3468
+ }
3407
3469
 
3408
- var transformPathStringToObj = function transformPathStringToObj(str) {
3409
- // "c[][]" -> ["c", "[]", "[]"]
3410
- var splitStatePathPart = function splitStatePathPart(state) {
3411
- return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
3412
- };
3470
+ for (var i = 0; i < spec.pathObj.length; i++) {
3471
+ if (spec.pathObj[i] === "[]") {
3472
+ indexes.push(path[i]);
3473
+ }
3474
+ }
3413
3475
 
3414
- return str.split(".").flatMap(splitStatePathPart);
3476
+ return indexes;
3415
3477
  };
3416
3478
 
3417
- function useVanillaDollarState(_specs, props) {
3418
- var forceRender = React__default.useState(0)[1];
3419
- var $$state = React__default.useMemo(function () {
3420
- var specs = Object.fromEntries(_specs.map(function (_ref2) {
3421
- var pathStr = _ref2.path,
3422
- spec = _objectWithoutPropertiesLoose(_ref2, ["path"]);
3423
-
3424
- return [pathStr, _extends({}, spec, {
3425
- pathStr: pathStr,
3426
- path: transformPathStringToObj(pathStr),
3427
- isRepeated: pathStr.split(".").some(function (part) {
3428
- return part.endsWith("[]");
3429
- })
3430
- })];
3431
- }));
3432
- return {
3433
- stateValues: mkProxy(specs),
3434
- initStateDeps: {},
3435
- initStateValues: mkProxy(specs),
3436
- states: {},
3437
- specs: specs
3438
- };
3439
- }, []);
3440
- var $state = Object.assign(mkProxy($$state.specs, function (state) {
3441
- return {
3442
- deleteProperty: function deleteProperty(_target, _property) {
3443
- var prefixPath = state.path;
3444
-
3445
- for (var _i2 = 0, _Object$entries2 = Object.entries($$state.states); _i2 < _Object$entries2.length; _i2++) {
3446
- var _Object$entries2$_i = _Object$entries2[_i2],
3447
- key = _Object$entries2$_i[0],
3448
- existingState = _Object$entries2$_i[1];
3479
+ function initializeStateValue($$state, initialStatePath, initialSpec) {
3480
+ var _$$state$unsubscripti2;
3449
3481
 
3450
- if (existingState.path.length >= prefixPath.length && shallowEqual(existingState.path.slice(0, prefixPath.length), prefixPath)) {
3451
- delete $$state.states[key];
3452
- }
3453
- }
3454
-
3455
- forceRender(function (r) {
3456
- return r + 1;
3482
+ var initialStateKey = JSON.stringify(initialStatePath);
3483
+ var stateAccess = new Set();
3484
+ var $state = create$StateProxy($$state, function (path, spec) {
3485
+ return {
3486
+ get: function get() {
3487
+ var key = JSON.stringify(path);
3488
+ stateAccess.add({
3489
+ path: path,
3490
+ spec: spec
3457
3491
  });
3458
- return true;
3459
- },
3460
- get: function get(_target, _property) {
3461
- var spec = $$state.specs[state.specKey];
3462
3492
 
3463
3493
  if (spec.valueProp) {
3464
- if (!spec.isRepeated) {
3465
- return props[spec.valueProp];
3466
- } else {
3467
- return _get(props[spec.valueProp], state.path.slice(1));
3468
- }
3494
+ return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
3469
3495
  }
3470
3496
 
3471
- if (!hasState(state, $$state.states)) {
3472
- var _spec$initVal;
3497
+ if ($$state.existingStates.has(key)) {
3498
+ // is already initialized
3499
+ return _get($$state.stateValues, path);
3500
+ } else if (spec.initFunc) {
3501
+ initializeStateValue($$state, path, spec);
3502
+ }
3473
3503
 
3474
- saveState(state, $$state.states);
3504
+ return _get($$state.stateValues, path);
3505
+ },
3506
+ set: function set() {
3507
+ throw new Error("Cannot update state values during initialization");
3508
+ }
3509
+ };
3510
+ });
3511
+ (_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
3512
+ return f();
3513
+ });
3514
+ $$state.unsubscriptionsByState[initialStateKey] = [];
3515
+ stateAccess.forEach(function (_ref2) {
3516
+ var path = _ref2.path,
3517
+ spec = _ref2.spec;
3518
+ var unsubscribe = subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
3519
+ return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
3520
+ });
3521
+ $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
3522
+ });
3523
+ var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
3475
3524
 
3476
- dset($$state.stateValues, state.path, spec.initFunc ? UNINITIALIZED : (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined);
3525
+ set($$state.initStateValues, initialStatePath, untrackedInitialValue);
3477
3526
 
3478
- var deps = spec.initFunc ? fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states) : {};
3527
+ set($$state.stateValues, initialStatePath, untrackedInitialValue);
3479
3528
 
3480
- dset($$state.initStateValues, state.path, _get($$state.stateValues, state.path));
3529
+ return untrackedInitialValue;
3530
+ }
3481
3531
 
3482
- $$state.initStateDeps = _extends({}, $$state.initStateDeps, deps);
3483
- forceRender(function (r) {
3484
- return r + 1;
3485
- });
3486
- return spec.initFunc ? spec.initFunc(props, $state) : spec.initVal;
3487
- }
3532
+ function useDollarState(specs, props) {
3533
+ var $$state = React__default.useRef(proxy({
3534
+ stateValues: {},
3535
+ initStateValues: {},
3536
+ specsByKey: Object.fromEntries(specs.map(function (spec) {
3537
+ return [spec.path, _extends({}, spec, {
3538
+ pathObj: transformPathStringToObj(spec.path),
3539
+ isRepeated: spec.path.split(".").some(function (part) {
3540
+ return part.endsWith("[]");
3541
+ })
3542
+ })];
3543
+ })),
3544
+ statesInstanceBySpec: new Map(),
3545
+ existingStates: new Map(),
3546
+ unsubscriptionsByState: {},
3547
+ props: undefined,
3548
+ registrationsQueue: []
3549
+ })).current;
3550
+ $$state.props = mkUntrackedValue(props);
3551
+ var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
3552
+ var key = JSON.stringify(path);
3488
3553
 
3489
- return _get($$state.stateValues, state.path);
3490
- },
3491
- set: function set(_target, _property, newValue) {
3492
- if (newValue !== _get($$state.stateValues, state.path)) {
3493
- saveState(state, $$state.states);
3554
+ if (!$$state.existingStates.has(key)) {
3555
+ var _spec$initVal;
3494
3556
 
3495
- dset($$state.stateValues, state.path, newValue);
3557
+ saveNewState($$state, path, spec);
3558
+ var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
3496
3559
 
3497
- for (var _i3 = 0, _Object$entries3 = Object.entries($$state.initStateDeps); _i3 < _Object$entries3.length; _i3++) {
3498
- var _Object$entries3$_i = _Object$entries3[_i3],
3499
- key = _Object$entries3$_i[0],
3500
- deps = _Object$entries3$_i[1];
3560
+ set($$state.stateValues, path, untrackedValue);
3501
3561
 
3502
- if (deps.includes(JSON.stringify(state.path))) {
3503
- dset($$state.stateValues, JSON.parse(key), UNINITIALIZED);
3504
- }
3505
- }
3562
+ set($$state.initStateValues, path, untrackedValue);
3563
+ }
3506
3564
 
3507
- var newDeps = fillUninitializedStateValues($$state.specs, props, $$state.stateValues, $$state.states);
3508
- $$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
3509
- forceRender(function (r) {
3510
- return r + 1;
3511
- });
3565
+ return {
3566
+ get: function get() {
3567
+ if (spec.valueProp) {
3568
+ var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
3569
+ return value;
3570
+ } else {
3571
+ return _get($$state.stateValues, path);
3512
3572
  }
3513
-
3514
- var spec = $$state.specs[state.specKey];
3573
+ },
3574
+ set: function set$1(_t, _p, value) {
3575
+ set($$state.stateValues, path, mkUntrackedValue(value));
3515
3576
 
3516
3577
  if (spec.onChangeProp) {
3517
- var _props$spec$onChangeP;
3578
+ var _$$state$props$spec$o3, _$$state$props3;
3518
3579
 
3519
- (_props$spec$onChangeP = props[spec.onChangeProp]) == null ? void 0 : _props$spec$onChangeP.call(props, newValue, state.path);
3580
+ (_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
3520
3581
  }
3521
3582
 
3522
3583
  return true;
@@ -3524,158 +3585,118 @@ function useVanillaDollarState(_specs, props) {
3524
3585
  };
3525
3586
  }), {
3526
3587
  registerInitFunc: function registerInitFunc(pathStr, f) {
3527
- if (Object.values($$state.states).filter(function (_ref3) {
3528
- var specKey = _ref3.specKey;
3529
- return specKey === pathStr;
3530
- }).some(function (_ref4) {
3531
- var path = _ref4.path;
3532
- return _get($$state.stateValues, path) !== f(props, $state);
3588
+ var _$$state$statesInstan;
3589
+
3590
+ if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
3591
+ var path = _ref3.path,
3592
+ specKey = _ref3.specKey;
3593
+ return !deepEqual(_get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
3533
3594
  })) {
3534
- $$state.specs[pathStr] = _extends({}, $$state.specs[pathStr], {
3535
- initFunc: f
3536
- });
3537
- forceRender(function (r) {
3538
- return r + 1;
3595
+ $$state.registrationsQueue.push({
3596
+ pathStr: pathStr,
3597
+ f: f
3539
3598
  });
3540
3599
  }
3541
3600
  }
3542
- }); // For each spec with an initFunc, evaluate it and see if
3601
+ })).current; // For each spec with an initFunc, evaluate it and see if
3543
3602
  // the init value has changed. If so, reset its state.
3544
3603
 
3545
- var newStateValues = undefined;
3546
3604
  var resetSpecs = [];
3547
-
3548
- for (var _i4 = 0, _Object$values = Object.values($$state.states); _i4 < _Object$values.length; _i4++) {
3549
- var _Object$values$_i = _Object$values[_i4],
3550
- path = _Object$values$_i.path,
3551
- specKey = _Object$values$_i.specKey;
3552
- var spec = $$state.specs[specKey];
3605
+ $$state.existingStates.forEach(function (_ref4) {
3606
+ var path = _ref4.path,
3607
+ specKey = _ref4.specKey;
3608
+ var spec = $$state.specsByKey[specKey];
3553
3609
 
3554
3610
  if (spec.initFunc) {
3555
- var newInit = spec.initFunc(props, $state);
3611
+ var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
3556
3612
 
3557
- if (newInit !== _get($$state.initStateValues, path)) {
3558
- console.log("init changed for " + JSON.stringify(path) + " from " + _get($$state.initStateValues, path) + " to " + newInit + "; resetting state");
3613
+ if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
3559
3614
  resetSpecs.push({
3560
3615
  path: path,
3561
- specKey: specKey
3616
+ spec: spec
3562
3617
  });
3563
-
3564
- if (!newStateValues) {
3565
- newStateValues = cloneProxy($$state.specs, $$state.states, $$state.stateValues);
3566
- }
3567
-
3568
- dset(newStateValues, path, UNINITIALIZED);
3569
3618
  }
3570
3619
  }
3571
- }
3572
-
3620
+ });
3573
3621
  React__default.useLayoutEffect(function () {
3574
- if (newStateValues !== undefined) {
3575
- var newDeps = fillUninitializedStateValues($$state.specs, props, newStateValues, $$state.states);
3576
- var initStateValues = cloneProxy($$state.specs, $$state.states, $$state.initStateValues);
3577
- resetSpecs.forEach(function (_ref5) {
3578
- var path = _ref5.path;
3579
-
3580
- dset(initStateValues, path, _get(newStateValues, path));
3581
- });
3582
- $$state.stateValues = cloneProxy($$state.specs, $$state.states, newStateValues);
3583
- $$state.initStateValues = initStateValues;
3584
- $$state.initStateDeps = _extends({}, $$state.initStateDeps, newDeps);
3585
- forceRender(function (r) {
3586
- return r + 1;
3587
- });
3588
-
3589
- for (var _iterator = _createForOfIteratorHelperLoose(resetSpecs), _step; !(_step = _iterator()).done;) {
3590
- var _step$value = _step.value,
3591
- _path = _step$value.path,
3592
- _specKey = _step$value.specKey;
3593
- var _spec = $$state.specs[_specKey];
3622
+ resetSpecs.forEach(function (_ref5) {
3623
+ var path = _ref5.path,
3624
+ spec = _ref5.spec;
3625
+ var newInit = initializeStateValue($$state, path, spec);
3594
3626
 
3595
- if (_spec.onChangeProp) {
3596
- var _props$_spec$onChange;
3627
+ if (spec.onChangeProp) {
3628
+ var _$$state$props$spec$o4, _$$state$props4;
3597
3629
 
3598
- console.log("Firing onChange for reset init value: " + _spec.path, _get(newStateValues, _path));
3599
- (_props$_spec$onChange = props[_spec.onChangeProp]) == null ? void 0 : _props$_spec$onChange.call(props, _get(newStateValues, _path));
3600
- }
3630
+ (_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
3601
3631
  }
3602
- }
3603
- }, [newStateValues, props, resetSpecs, $$state.specs]);
3604
- /* *
3605
- * Initialize all known states. (we need to do it for repeated states
3606
- * because they're created only after the first get/set operation)
3607
- * If we don't initialize them, we won't be able to consume the repeated states properly.
3608
- * For example, let's say the consumer is just mapping the repeated states. The first operation
3609
- * is to get the length of the array which will always be 0 because the existing states
3610
- * weren't allocated yet -- they're only stored in internal state)
3611
- * */
3612
-
3613
- for (var _i5 = 0, _Object$values2 = Object.values($$state.states); _i5 < _Object$values2.length; _i5++) {
3614
- var _path2 = _Object$values2[_i5].path;
3615
-
3616
- _get($state, _path2);
3617
- }
3632
+ });
3633
+ }, [props, resetSpecs]);
3634
+ React__default.useLayoutEffect(function () {
3635
+ $$state.registrationsQueue.forEach(function (_ref6) {
3636
+ var f = _ref6.f,
3637
+ pathStr = _ref6.pathStr;
3638
+ $$state.specsByKey[pathStr].initFunc = f;
3639
+ });
3640
+ $$state.registrationsQueue = [];
3641
+ }, [$$state.registrationsQueue]); // Re-render if any value changed in one of these objects
3618
3642
 
3643
+ useSnapshot($$state.stateValues, {
3644
+ sync: true
3645
+ });
3646
+ useSnapshot($$state.specsByKey, {
3647
+ sync: true
3648
+ });
3619
3649
  return $state;
3620
3650
  }
3621
3651
 
3622
- function fillUninitializedStateValues(specs, props, stateValues, states) {
3623
- var stateAccessStack = [new Set()];
3624
- var initFuncDeps = {};
3625
- var $state = Object.assign(mkProxy(specs, function (state) {
3652
+ function useCanvasDollarState(specs, props) {
3653
+ var $$state = proxy({
3654
+ stateValues: {},
3655
+ initStateValues: {},
3656
+ specsByKey: Object.fromEntries(specs.map(function (spec) {
3657
+ return [spec.path, _extends({}, spec, {
3658
+ pathObj: transformPathStringToObj(spec.path),
3659
+ isRepeated: spec.path.split(".").some(function (part) {
3660
+ return part.endsWith("[]");
3661
+ })
3662
+ })];
3663
+ })),
3664
+ statesInstanceBySpec: new Map(),
3665
+ existingStates: new Map(),
3666
+ unsubscriptionsByState: {},
3667
+ props: undefined,
3668
+ registrationsQueue: []
3669
+ });
3670
+ $$state.props = mkUntrackedValue(props);
3671
+ var $state = create$StateProxy($$state, function (path, spec) {
3626
3672
  return {
3627
- get: function get(_target, _property) {
3628
- var spec = specs[state.specKey];
3629
-
3630
- if (spec.valueProp) {
3631
- if (!spec.isRepeated) {
3632
- return props[spec.valueProp];
3633
- } else {
3634
- return _get(props[spec.valueProp], state.path.slice(1));
3635
- }
3636
- }
3637
-
3638
- var value = _get(stateValues, state.path);
3639
-
3640
- if (value === UNINITIALIZED) {
3641
- // This value has a init expression; need to be evaluated.
3642
- value = tracked(state);
3673
+ get: function get() {
3674
+ return _get($$state.stateValues, path);
3675
+ },
3676
+ set: function set$1(_t, _p, value) {
3677
+ set($$state.stateValues, path, mkUntrackedValue(value));
3643
3678
 
3644
- dset(stateValues, state.path, value);
3645
- } // Record that this field had just been accessed; for
3646
- // trackInit() to know what fields were used to compute
3647
- // the init value
3679
+ if (spec.onChangeProp) {
3680
+ var _$$state$props$spec$o5, _$$state$props5;
3648
3681
 
3682
+ (_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
3683
+ }
3649
3684
 
3650
- stateAccessStack[stateAccessStack.length - 1].add(JSON.stringify(state.path));
3651
- return value;
3652
- },
3653
- set: function set() {
3654
- throw new Error("Cannot update state values during initialization");
3685
+ return true;
3655
3686
  }
3656
3687
  };
3657
- }), {
3658
- registerInitFunc: function registerInitFunc() {}
3659
3688
  });
3660
3689
 
3661
- function tracked(state) {
3662
- stateAccessStack.push(new Set());
3663
- var res = specs[state.specKey].initFunc(props, $state);
3664
- var deps = stateAccessStack.pop();
3665
- initFuncDeps[JSON.stringify(state.path)] = [].concat(deps.values());
3666
- return res;
3667
- }
3668
-
3669
- for (var _i6 = 0, _Object$values3 = Object.values(states); _i6 < _Object$values3.length; _i6++) {
3670
- var path = _Object$values3[_i6].path;
3690
+ for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
3691
+ var spec = _step.value;
3692
+ var path = transformPathStringToObj(spec.path);
3693
+ var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
3671
3694
 
3672
- if (_get(stateValues, path) === UNINITIALIZED) {
3673
- _get($state, path);
3674
- }
3695
+ set($state, path, init);
3675
3696
  }
3676
3697
 
3677
- return initFuncDeps;
3698
+ return $state;
3678
3699
  }
3679
3700
 
3680
- export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, omit, pick, plasmicHeadMeta, renderPlasmicSlot, setPlumeStrictMode, useButton, useCheckbox, useVanillaDollarState as useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3701
+ export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, useButton, useCanvasDollarState, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3681
3702
  //# sourceMappingURL=react-web.esm.js.map