@plasmicapp/react-web 0.2.170 → 0.2.172

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 (41) hide show
  1. package/dist/all.d.ts +6 -2
  2. package/dist/react-web.cjs.development.js +288 -269
  3. package/dist/react-web.cjs.development.js.map +1 -1
  4. package/dist/react-web.cjs.production.min.js +1 -1
  5. package/dist/react-web.cjs.production.min.js.map +1 -1
  6. package/dist/react-web.esm.js +288 -271
  7. package/dist/react-web.esm.js.map +1 -1
  8. package/dist/states/graph.d.ts +2 -20
  9. package/dist/states/helpers.d.ts +5 -1
  10. package/dist/states/index.d.ts +1 -1
  11. package/dist/states/types.d.ts +26 -1
  12. package/dist/states/valtio.d.ts +4 -1
  13. package/dist/stories/UseDollarState.stories.d.ts +1 -0
  14. package/package.json +4 -4
  15. package/skinny/dist/{collection-utils-3496fd68.js → collection-utils-719bb030.js} +4 -4
  16. package/skinny/dist/{collection-utils-3496fd68.js.map → collection-utils-719bb030.js.map} +1 -1
  17. package/skinny/dist/{common-c2744215.js → common-dd6b46fb.js} +11 -2
  18. package/skinny/dist/{common-c2744215.js.map → common-dd6b46fb.js.map} +1 -1
  19. package/skinny/dist/index.js +279 -254
  20. package/skinny/dist/index.js.map +1 -1
  21. package/skinny/dist/plume/button/index.js +2 -2
  22. package/skinny/dist/plume/checkbox/index.js +4 -4
  23. package/skinny/dist/plume/menu/index.js +5 -5
  24. package/skinny/dist/plume/menu-button/index.js +4 -4
  25. package/skinny/dist/plume/select/index.js +5 -5
  26. package/skinny/dist/plume/switch/index.js +4 -4
  27. package/skinny/dist/plume/text-input/index.js +2 -2
  28. package/skinny/dist/plume/triggered-overlay/index.js +4 -4
  29. package/skinny/dist/{plume-utils-653f4b8a.js → plume-utils-43df92e6.js} +2 -2
  30. package/skinny/dist/{plume-utils-653f4b8a.js.map → plume-utils-43df92e6.js.map} +1 -1
  31. package/skinny/dist/{props-utils-70c2d02a.js → props-utils-eaa18f66.js} +2 -2
  32. package/skinny/dist/{props-utils-70c2d02a.js.map → props-utils-eaa18f66.js.map} +1 -1
  33. package/skinny/dist/{react-utils-76d05959.js → react-utils-628465ba.js} +2 -2
  34. package/skinny/dist/{react-utils-76d05959.js.map → react-utils-628465ba.js.map} +1 -1
  35. package/skinny/dist/render/PlasmicImg/index.js +2 -2
  36. package/skinny/dist/states/graph.d.ts +2 -20
  37. package/skinny/dist/states/helpers.d.ts +5 -1
  38. package/skinny/dist/states/index.d.ts +1 -1
  39. package/skinny/dist/states/types.d.ts +26 -1
  40. package/skinny/dist/states/valtio.d.ts +4 -1
  41. package/skinny/dist/stories/UseDollarState.stories.d.ts +1 -0
@@ -10,7 +10,7 @@ import { SSRProvider, useIsSSR as useIsSSR$1 } from '@react-aria/ssr';
10
10
  import { useFocusRing, useFocusable, FocusScope } from '@react-aria/focus';
11
11
  import clone from 'clone';
12
12
  import deepEqual from 'fast-deep-equal';
13
- import { proxy, useSnapshot, ref } from 'valtio';
13
+ import { proxy, ref, useSnapshot } from 'valtio';
14
14
  import { useCheckbox as useCheckbox$1 } from '@react-aria/checkbox';
15
15
  import { VisuallyHidden } from '@react-aria/visually-hidden';
16
16
  import { useToggleState } from '@react-stately/toggle';
@@ -959,6 +959,14 @@ function chainSingleArgFuncs() {
959
959
  return res;
960
960
  };
961
961
  }
962
+ function ensure(x) {
963
+ if (x === null || x === undefined) {
964
+ debugger;
965
+ throw new Error("Value must not be undefined or null");
966
+ } else {
967
+ return x;
968
+ }
969
+ }
962
970
  function isString(x) {
963
971
  return typeof x === "string";
964
972
  }
@@ -2295,13 +2303,12 @@ function useTrigger(trigger, opts) {
2295
2303
 
2296
2304
  var ARRAY_SYMBOL = /*#__PURE__*/Symbol("[]");
2297
2305
  var PLASMIC_STATE_PROXY_SYMBOL = /*#__PURE__*/Symbol("plasmic.state.proxy");
2298
-
2299
2306
  var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
2307
+
2300
2308
  var StateSpecNode = /*#__PURE__*/function () {
2301
2309
  function StateSpecNode(specs) {
2302
2310
  this._specs = specs;
2303
2311
  this._edges = new Map();
2304
- this._state = {};
2305
2312
  }
2306
2313
  var _proto = StateSpecNode.prototype;
2307
2314
  _proto.setSpecs = function setSpecs(specs) {
@@ -2310,9 +2317,6 @@ var StateSpecNode = /*#__PURE__*/function () {
2310
2317
  _proto.edges = function edges() {
2311
2318
  return this._edges;
2312
2319
  };
2313
- _proto.state = function state() {
2314
- return this._state;
2315
- };
2316
2320
  _proto.hasEdge = function hasEdge(key) {
2317
2321
  return this._edges.has(key);
2318
2322
  };
@@ -2326,11 +2330,11 @@ var StateSpecNode = /*#__PURE__*/function () {
2326
2330
  return this._edges.values();
2327
2331
  };
2328
2332
  _proto.makeTransition = function makeTransition(key) {
2329
- key = isNum(key) ? ARRAY_SYMBOL : key;
2333
+ key = isNum$1(key) ? ARRAY_SYMBOL : key;
2330
2334
  return this._edges.get(key);
2331
2335
  };
2332
2336
  _proto.isLeaf = function isLeaf() {
2333
- return this._edges.size === 0;
2337
+ return this._edges.size === 0 && this.getAllSpecs().length > 0;
2334
2338
  };
2335
2339
  _proto.hasArrayTransition = function hasArrayTransition() {
2336
2340
  return this._edges.has(ARRAY_SYMBOL);
@@ -2341,52 +2345,6 @@ var StateSpecNode = /*#__PURE__*/function () {
2341
2345
  _proto.getAllSpecs = function getAllSpecs() {
2342
2346
  return this._specs;
2343
2347
  };
2344
- _proto.getState = function getState(path) {
2345
- return this._state[JSON.stringify(path)];
2346
- };
2347
- _proto.getInitFunc = function getInitFunc(stateCell) {
2348
- var _stateCell$registered;
2349
- return (_stateCell$registered = stateCell.registeredInitFunc) != null ? _stateCell$registered : this.getSpec().initFunc;
2350
- };
2351
- _proto.clearStates = function clearStates() {
2352
- this._state = {};
2353
- };
2354
- _proto.states = function states() {
2355
- return Object.values(this._state);
2356
- };
2357
- _proto.hasState = function hasState(path) {
2358
- var key = JSON.stringify(path);
2359
- return key in this._state;
2360
- };
2361
- _proto.createStateCell = function createStateCell(path) {
2362
- var key = JSON.stringify(path);
2363
- this._state[key] = {
2364
- listeners: [],
2365
- initialValue: UNINITIALIZED,
2366
- path: path
2367
- };
2368
- };
2369
- _proto.deleteStateCell = function deleteStateCell(prefixPath) {
2370
- var _this = this;
2371
- [].concat(Object.keys(this._state)).forEach(function (key) {
2372
- var path = JSON.parse(key);
2373
- if (shallowEqual(prefixPath, path.slice(0, prefixPath.length))) {
2374
- delete _this._state[key];
2375
- }
2376
- });
2377
- };
2378
- _proto.setInitialValue = function setInitialValue(path, value) {
2379
- var key = JSON.stringify(path);
2380
- this._state[key].initialValue = value;
2381
- };
2382
- _proto.getInitialValue = function getInitialValue(path) {
2383
- var key = JSON.stringify(path);
2384
- return this._state[key].initialValue;
2385
- };
2386
- _proto.addListener = function addListener(path, f) {
2387
- var key = JSON.stringify(path);
2388
- this._state[key].listeners.push(f);
2389
- };
2390
2348
  return StateSpecNode;
2391
2349
  }();
2392
2350
  var transformPathStringToObj = function transformPathStringToObj(str) {
@@ -2449,7 +2407,7 @@ function updateTree(root, specs) {
2449
2407
  };
2450
2408
  return rec(root, []);
2451
2409
  }
2452
- function getStateCells(root) {
2410
+ function getSpecTreeLeaves(root) {
2453
2411
  var leaves = [];
2454
2412
  var rec = function rec(node) {
2455
2413
  for (var _iterator = _createForOfIteratorHelperLoose(node.children()), _step; !(_step = _iterator()).done;) {
@@ -2489,156 +2447,63 @@ function findStateCell(root, pathStr, repetitionIndex) {
2489
2447
  };
2490
2448
  }
2491
2449
 
2492
- function generateStateOnChangeProp($state, path) {
2493
- return function (val) {
2494
- return set($state, path, val);
2495
- };
2496
- }
2497
- function generateStateValueProp($state, path) {
2498
- return _get($state, path);
2499
- }
2500
- var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
2501
- function isPlasmicStateProxy(obj) {
2502
- return obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL];
2503
- }
2504
- function getStateCellsInPlasmicProxy(obj) {
2505
- if (!isPlasmicStateProxy(obj)) {
2506
- return [];
2507
- }
2508
- var _obj$PLASMIC_STATE_PR = obj[PLASMIC_STATE_PROXY_SYMBOL],
2509
- rootNode = _obj$PLASMIC_STATE_PR.node,
2510
- rootPath = _obj$PLASMIC_STATE_PR.path,
2511
- isOutside = _obj$PLASMIC_STATE_PR.isOutside;
2512
- if (isOutside) {
2513
- return [];
2514
- }
2515
- return getStateCells(rootNode).flatMap(function (node) {
2516
- return node.states().map(function (stateCell) {
2517
- return {
2518
- path: node.getSpec().path,
2519
- realPath: stateCell.path.slice(rootPath.length)
2520
- };
2521
- });
2522
- });
2523
- }
2524
- function getStateSpecInPlasmicProxy(obj, path) {
2525
- obj = _get(obj, path.slice(0, path.length - 1));
2526
- if (!isPlasmicStateProxy(obj)) {
2527
- return undefined;
2528
- }
2529
- var _obj$PLASMIC_STATE_PR2 = obj[PLASMIC_STATE_PROXY_SYMBOL],
2530
- node = _obj$PLASMIC_STATE_PR2.node,
2531
- isOutside = _obj$PLASMIC_STATE_PR2.isOutside;
2532
- var nextNode = node.makeTransition(path[path.length - 1]);
2533
- if (isOutside || node.isLeaf() || !nextNode) {
2534
- return undefined;
2535
- }
2536
- return {
2537
- spec: nextNode.getSpec(),
2538
- isImplicitStateArray: nextNode.hasArrayTransition()
2539
- };
2540
- }
2541
- function shallowEqual(a1, a2) {
2542
- if (a1.length !== a2.length) {
2543
- return false;
2544
- }
2545
- for (var i = 0; i < a1.length; i++) {
2546
- if (a1[i] !== a2[i]) {
2547
- return false;
2548
- }
2549
- }
2550
- return true;
2551
- }
2552
- /**
2553
- * Shallow comparison of arrays.
2554
- */
2555
- function arrayEq(xs, ys) {
2556
- return xs.length === ys.length && xs.every(function (_, index) {
2557
- return xs[index] === ys[index];
2558
- });
2559
- }
2560
2450
  function isNum(value) {
2561
2451
  return typeof value === "symbol" ? false : !isNaN(+value);
2562
2452
  }
2563
- function assert(cond, msg) {
2564
- if (msg === void 0) {
2565
- msg = "Assertion failed";
2566
- }
2567
- if (!cond) {
2568
- // We always generate an non empty message so that it doesn't get swallowed
2569
- // by the async library.
2570
- msg = (typeof msg === "string" ? msg : msg()) || "Assertion failed";
2571
- debugger;
2572
- throw new Error(msg);
2573
- }
2453
+ function canProxy(value) {
2454
+ return typeof value === "object" && value != null;
2574
2455
  }
2575
- /**
2576
- * Forked from https://github.com/lukeed/dset
2577
- * Changes: fixed setting a deep value to a proxy object
2578
- */
2579
- function set(obj, keys, val) {
2580
- keys = keys.split ? keys.split(".") : keys;
2581
- var i = 0,
2582
- l = keys.length,
2583
- t = obj,
2584
- x,
2585
- k;
2586
- while (i < l) {
2587
- k = keys[i++];
2588
- if (k === "__proto__" || k === "constructor" || k === "prototype") break;
2589
- var newValue = i === l ? val : typeof (x = t[k]) === typeof keys ? x : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".") ? {} : [];
2590
- assignValue(t, k, newValue);
2591
- t = t[k];
2456
+ var proxyObjToStateCell = /*#__PURE__*/new WeakMap();
2457
+ function ensureStateCell(target, property, path, node) {
2458
+ if (!proxyObjToStateCell.has(target)) {
2459
+ proxyObjToStateCell.set(target, {});
2592
2460
  }
2593
- }
2594
- /**
2595
- * Forked from lodash
2596
- */
2597
- function baseAssignValue(object, key, value) {
2598
- if (key == "__proto__") {
2599
- Object.defineProperty(object, key, {
2600
- configurable: true,
2601
- enumerable: true,
2602
- value: value,
2603
- writable: true
2604
- });
2605
- } else {
2606
- object[key] = value;
2461
+ var stateCell = proxyObjToStateCell.get(target);
2462
+ if (!(property in stateCell)) {
2463
+ var _node$getSpec$initFun;
2464
+ stateCell[property] = {
2465
+ listeners: [],
2466
+ initialValue: UNINITIALIZED,
2467
+ path: path,
2468
+ node: node,
2469
+ initFunc: node.getSpec().initFunc,
2470
+ initFuncHash: (_node$getSpec$initFun = node.getSpec().initFuncHash) != null ? _node$getSpec$initFun : ""
2471
+ };
2607
2472
  }
2473
+ return stateCell[property];
2608
2474
  }
2609
- function eq(value, other) {
2610
- return value === other || value !== value && other !== other;
2475
+ function getStateCell(target, property) {
2476
+ var _proxyObjToStateCell$;
2477
+ return (_proxyObjToStateCell$ = proxyObjToStateCell.get(target)) == null ? void 0 : _proxyObjToStateCell$[property];
2611
2478
  }
2612
- function assignValue(object, key, value) {
2613
- var objValue = object[key];
2614
- if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) || value === undefined && !(key in object)) {
2615
- baseAssignValue(object, key, value);
2479
+ function tryGetStateCellFrom$StateRoot($state, path) {
2480
+ if (path.length === 0) {
2481
+ throw new Error("expected a path with length greater than 0");
2616
2482
  }
2483
+ var target = _get($state, path.slice(0, -1));
2484
+ _get(target, path.slice(-1)); // create state cell;
2485
+ return getStateCell(target, path.slice(-1)[0]);
2617
2486
  }
2618
-
2619
- function isNum$1(value) {
2620
- return typeof value === "symbol" ? false : !isNaN(+value);
2621
- }
2622
- function canProxy(value) {
2623
- return typeof value === "object" && value != null;
2487
+ function getStateCellFrom$StateRoot($state, path) {
2488
+ return ensure(tryGetStateCellFrom$StateRoot($state, path));
2624
2489
  }
2625
- function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyRoot) {
2490
+ function initializeStateValue($$state, initialStateCell, proxyRoot) {
2491
+ var _initialStateCell$ove2;
2626
2492
  var stateAccess = new Set();
2627
- var $state = create$StateProxy($$state, function (node, path) {
2493
+ var $state = create$StateProxy($$state, function (internalStateCell) {
2628
2494
  return {
2629
2495
  get: function get() {
2496
+ var stateCell = getStateCellFrom$StateRoot(proxyRoot, internalStateCell.path);
2630
2497
  stateAccess.add({
2631
- path: path,
2632
- node: node
2498
+ stateCell: stateCell
2633
2499
  });
2634
- var spec = node.getSpec();
2500
+ var spec = stateCell.node.getSpec();
2635
2501
  if (spec.valueProp) {
2636
2502
  return $$state.env.$props[spec.valueProp];
2637
- } else if (!node.hasState(path) && spec.initFunc) {
2638
- node.createStateCell(path);
2639
- return initializeStateValue($$state, node, path, proxyRoot);
2503
+ } else if (spec.initFunc && stateCell.initialValue === UNINITIALIZED) {
2504
+ return initializeStateValue($$state, stateCell, proxyRoot);
2640
2505
  }
2641
- return _get(proxyRoot, path);
2506
+ return _get(proxyRoot, stateCell.path);
2642
2507
  },
2643
2508
  set: function set() {
2644
2509
  throw new Error("Cannot update state values during initialization");
@@ -2646,23 +2511,22 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
2646
2511
  };
2647
2512
  });
2648
2513
  stateAccess.forEach(function (_ref) {
2649
- var node = _ref.node,
2650
- path = _ref.path;
2651
- node.addListener(path, function () {
2652
- var newValue = invokeInitFuncBackwardsCompatible(initialSpecNode.getSpec().initFunc, _extends({
2514
+ var stateCell = _ref.stateCell;
2515
+ stateCell.listeners.push(function () {
2516
+ var _initialStateCell$ove;
2517
+ var newValue = invokeInitFuncBackwardsCompatible(initialStateCell.node.getSpec().initFunc, _extends({
2653
2518
  $state: $state
2654
- }, $$state.env));
2655
- set(proxyRoot, initialStatePath, newValue);
2519
+ }, (_initialStateCell$ove = initialStateCell.overrideEnv) != null ? _initialStateCell$ove : $$state.env));
2520
+ set(proxyRoot, initialStateCell.path, newValue);
2656
2521
  });
2657
2522
  });
2658
- var initFunc = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath));
2659
- var initialValue = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2523
+ var initialValue = invokeInitFuncBackwardsCompatible(initialStateCell.initFunc, _extends({
2660
2524
  $state: $state
2661
- }, $$state.env));
2662
- initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
2663
- var initialSpec = initialSpecNode.getSpec();
2525
+ }, (_initialStateCell$ove2 = initialStateCell.overrideEnv) != null ? _initialStateCell$ove2 : $$state.env));
2526
+ initialStateCell.initialValue = clone(initialValue);
2527
+ var initialSpec = initialStateCell.node.getSpec();
2664
2528
  var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
2665
- set(proxyRoot, initialStatePath, value);
2529
+ set(proxyRoot, initialStateCell.path, value);
2666
2530
  //immediately fire onChange
2667
2531
  if (initialSpec.onChangeProp) {
2668
2532
  var _$$state$env$$props$i, _$$state$env$$props;
@@ -2674,12 +2538,12 @@ function create$StateProxy($$state, leafHandlers) {
2674
2538
  var proxyRoot;
2675
2539
  var rec = function rec(currPath, currNode, isOutside, initialObject) {
2676
2540
  var getNextPath = function getNextPath(property) {
2677
- return [].concat(currPath, [isNum$1(property) ? +property : property]);
2541
+ return [].concat(currPath, [isNum(property) ? +property : property]);
2678
2542
  };
2679
2543
  var spec = currNode.getSpec();
2680
2544
  var handlers = {
2681
2545
  deleteProperty: function deleteProperty(target, property) {
2682
- if (!isOutside && !currNode.isLeaf() && !currNode.hasArrayTransition() && !isNum$1(property)) {
2546
+ if (!isOutside && !currNode.isLeaf() && !currNode.hasArrayTransition() && !isNum(property)) {
2683
2547
  throw new Error("Can't delete a property in the middle of the state spec");
2684
2548
  }
2685
2549
  delete _get($$state.stateValues, currPath)[property];
@@ -2690,13 +2554,6 @@ function create$StateProxy($$state, leafHandlers) {
2690
2554
  // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
2691
2555
  (_$$state$env$$props$s = (_$$state$env$$props2 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s.call(_$$state$env$$props2, _get(proxyRoot, currPath.slice(spec.pathObj.length)));
2692
2556
  }
2693
- var nextPath = getNextPath(property);
2694
- var nextNode = currNode.makeTransition(property);
2695
- if (nextNode) {
2696
- getStateCells(nextNode).forEach(function (node) {
2697
- node.deleteStateCell(nextPath);
2698
- });
2699
- }
2700
2557
  return Reflect.deleteProperty(target, property);
2701
2558
  },
2702
2559
  get: function get(target, property, receiver) {
@@ -2714,7 +2571,7 @@ function create$StateProxy($$state, leafHandlers) {
2714
2571
  var nextNode = currNode.makeTransition(property);
2715
2572
  if (nextNode != null && nextNode.isLeaf()) {
2716
2573
  var _leafHandlers$get, _leafHandlers;
2717
- return (_leafHandlers$get = (_leafHandlers = leafHandlers(nextNode, nextPath)).get) == null ? void 0 : _leafHandlers$get.call(_leafHandlers, target, property, receiver);
2574
+ return (_leafHandlers$get = (_leafHandlers = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).get) == null ? void 0 : _leafHandlers$get.call(_leafHandlers, target, property, receiver);
2718
2575
  } else if (nextNode && !(property in target)) {
2719
2576
  target[property] = rec(nextPath, nextNode, false, undefined);
2720
2577
  }
@@ -2734,7 +2591,7 @@ function create$StateProxy($$state, leafHandlers) {
2734
2591
  }
2735
2592
  if ((_nextNode = nextNode) != null && _nextNode.isLeaf()) {
2736
2593
  var _leafHandlers$set, _leafHandlers2;
2737
- (_leafHandlers$set = (_leafHandlers2 = leafHandlers(nextNode, nextPath)).set) == null ? void 0 : _leafHandlers$set.call(_leafHandlers2, target, property, value, receiver);
2594
+ (_leafHandlers$set = (_leafHandlers2 = leafHandlers(ensureStateCell(receiver, property, nextPath, nextNode))).set) == null ? void 0 : _leafHandlers$set.call(_leafHandlers2, target, property, value, receiver);
2738
2595
  }
2739
2596
  if (!isOutside && !currNode.isLeaf() && !nextNode) {
2740
2597
  // can't set an unknown field in $state
@@ -2850,28 +2707,27 @@ function useDollarState(specs) {
2850
2707
  var rootSpecTree = buildTree(specs);
2851
2708
  return {
2852
2709
  rootSpecTree: rootSpecTree,
2853
- specTreeLeaves: getStateCells(rootSpecTree),
2710
+ specTreeLeaves: getSpecTreeLeaves(rootSpecTree),
2854
2711
  stateValues: proxy({}),
2855
2712
  env: envFieldsAreNonNill(env),
2856
2713
  specs: [],
2857
2714
  registrationsQueue: proxy([])
2858
2715
  };
2859
2716
  }()).current;
2860
- $$state.env = envFieldsAreNonNill(env), $$state.specs = specs;
2861
- var create$State = function create$State() {
2862
- var $state = Object.assign(create$StateProxy($$state, function (node, path) {
2863
- if (!node.hasState(path)) {
2864
- node.createStateCell(path);
2865
- var spec = node.getSpec();
2866
- if (spec.initFunc) {
2867
- initializeStateValue($$state, node, path, $state);
2868
- } else if (!spec.valueProp) {
2869
- set($state, path, spec.initVal);
2870
- }
2717
+ $$state.env = envFieldsAreNonNill(env);
2718
+ $$state.specs = specs;
2719
+ var create$State = React__default.useCallback(function () {
2720
+ var $state = Object.assign(create$StateProxy($$state, function (stateCell) {
2721
+ var spec = stateCell.node.getSpec();
2722
+ if (stateCell.initialValue === UNINITIALIZED && spec.initFunc) {
2723
+ initializeStateValue($$state, stateCell, $state);
2724
+ } else if (stateCell.initialValue === UNINITIALIZED && !spec.valueProp) {
2725
+ stateCell.initialValue = spec.initVal;
2726
+ set($state, stateCell.path, spec.initVal);
2871
2727
  }
2872
2728
  return {
2873
2729
  get: function get(target, property, receiver) {
2874
- var spec = node.getSpec();
2730
+ var spec = stateCell.node.getSpec();
2875
2731
  if (spec.valueProp) {
2876
2732
  return $$state.env.$props[spec.valueProp];
2877
2733
  } else {
@@ -2880,26 +2736,26 @@ function useDollarState(specs) {
2880
2736
  }
2881
2737
  };
2882
2738
  }), {
2883
- registerInitFunc: function registerInitFunc(pathStr, f, repetitionIndex) {
2739
+ registerInitFunc: function registerInitFunc(pathStr, f, repetitionIndex, overrideEnv) {
2884
2740
  var _findStateCell = findStateCell($$state.rootSpecTree, pathStr, repetitionIndex),
2885
2741
  node = _findStateCell.node,
2886
2742
  realPath = _findStateCell.realPath;
2887
- if (!node.hasState(realPath)) {
2888
- node.createStateCell(realPath);
2889
- }
2890
- if (!deepEqual(node.getState(realPath).initialValue, f(_extends({
2743
+ var stateCell = getStateCellFrom$StateRoot($state, realPath);
2744
+ var env = overrideEnv ? envFieldsAreNonNill(overrideEnv) : $$state.env;
2745
+ if (!deepEqual(stateCell.initialValue, f(_extends({
2891
2746
  $state: $state
2892
- }, $$state.env)))) {
2747
+ }, env)))) {
2893
2748
  $$state.registrationsQueue.push(mkUntrackedValue({
2894
2749
  node: node,
2895
2750
  path: realPath,
2896
- f: f
2751
+ f: f,
2752
+ overrideEnv: overrideEnv ? envFieldsAreNonNill(overrideEnv) : undefined
2897
2753
  }));
2898
2754
  }
2899
2755
  }
2900
2756
  });
2901
2757
  return $state;
2902
- };
2758
+ }, []);
2903
2759
  var ref = React__default.useRef(undefined);
2904
2760
  if (!ref.current) {
2905
2761
  ref.current = create$State();
@@ -2907,79 +2763,79 @@ function useDollarState(specs) {
2907
2763
  var $state = ref.current;
2908
2764
  if (opts != null && opts.inCanvas) {
2909
2765
  $$state.rootSpecTree = updateTree($$state.rootSpecTree, specs);
2910
- var newLeaves = getStateCells($$state.rootSpecTree);
2766
+ var newLeaves = getSpecTreeLeaves($$state.rootSpecTree);
2911
2767
  if (!arrayEq(newLeaves, $$state.specTreeLeaves)) {
2912
- var old$State = $state;
2768
+ var old$state = $state;
2913
2769
  $state = ref.current = create$State();
2914
2770
  $$state.specTreeLeaves = newLeaves;
2915
- $$state.specTreeLeaves.flatMap(function (node) {
2916
- return node.states();
2917
- }).forEach(function (_ref2) {
2771
+ getStateCells(newLeaves, $$state.rootSpecTree).forEach(function (_ref2) {
2918
2772
  var path = _ref2.path;
2919
- set($state, path, _get(old$State, path));
2773
+ var oldStateCell = tryGetStateCellFrom$StateRoot(old$state, path);
2774
+ if (oldStateCell) {
2775
+ set($state, path, _get(old$state, path));
2776
+ }
2920
2777
  });
2921
2778
  }
2922
2779
  // we need to eager initialize all states in canvas to populate the data picker
2923
2780
  $$state.specTreeLeaves.forEach(function (node) {
2781
+ var _newSpec$initFuncHash;
2924
2782
  var spec = node.getSpec();
2925
- if (spec.isRepeated || node.hasState(spec.pathObj)) {
2783
+ if (spec.isRepeated) {
2926
2784
  return;
2927
2785
  }
2928
- node.createStateCell(spec.pathObj);
2929
- var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
2786
+ var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
2787
+ var newSpec = specs.find(function (sp) {
2788
+ return sp.path === spec.path;
2789
+ });
2790
+ if (!newSpec || stateCell.initFuncHash === (newSpec == null ? void 0 : newSpec.initFuncHash)) {
2791
+ return;
2792
+ }
2793
+ stateCell.initFunc = newSpec.initFunc;
2794
+ stateCell.initFuncHash = (_newSpec$initFuncHash = newSpec.initFuncHash) != null ? _newSpec$initFuncHash : "";
2795
+ var init = spec.valueProp ? $$state.env.$props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, stateCell, $state) : spec.initVal;
2930
2796
  set($state, spec.pathObj, init);
2931
2797
  });
2932
2798
  }
2933
2799
  // For each spec with an initFunc, evaluate it and see if
2934
2800
  // the init value has changed. If so, reset its state.
2935
2801
  var resetSpecs = [];
2936
- $$state.specTreeLeaves.flatMap(function (node) {
2937
- return node.states().map(function (stateCell) {
2938
- return {
2939
- stateCell: stateCell,
2940
- node: node
2941
- };
2942
- });
2943
- }).forEach(function (_ref3) {
2944
- var node = _ref3.node,
2945
- stateCell = _ref3.stateCell;
2946
- var initFunc = node.getInitFunc(stateCell);
2947
- if (initFunc) {
2948
- var newInit = invokeInitFuncBackwardsCompatible(initFunc, _extends({
2802
+ getStateCells($state, $$state.rootSpecTree).forEach(function (stateCell) {
2803
+ if (stateCell.initFunc) {
2804
+ var _stateCell$overrideEn;
2805
+ var newInit = invokeInitFuncBackwardsCompatible(stateCell.initFunc, _extends({
2949
2806
  $state: $state
2950
- }, envFieldsAreNonNill(env)));
2807
+ }, (_stateCell$overrideEn = stateCell.overrideEnv) != null ? _stateCell$overrideEn : envFieldsAreNonNill(env)));
2951
2808
  if (!deepEqual(newInit, stateCell.initialValue)) {
2952
2809
  resetSpecs.push({
2953
- stateCell: stateCell,
2954
- node: node
2810
+ stateCell: stateCell
2955
2811
  });
2956
2812
  }
2957
2813
  }
2958
2814
  });
2959
- var reInitializeState = function reInitializeState(node, stateCell) {
2960
- var newInit = initializeStateValue($$state, node, stateCell.path, $state);
2961
- var spec = node.getSpec();
2815
+ var reInitializeState = function reInitializeState(stateCell) {
2816
+ var newInit = initializeStateValue($$state, stateCell, $state);
2817
+ var spec = stateCell.node.getSpec();
2962
2818
  if (spec.onChangeProp) {
2963
2819
  var _$$state$env$$props$s4, _$$state$env$$props5;
2964
2820
  (_$$state$env$$props$s4 = (_$$state$env$$props5 = $$state.env.$props)[spec.onChangeProp]) == null ? void 0 : _$$state$env$$props$s4.call(_$$state$env$$props5, newInit);
2965
2821
  }
2966
2822
  };
2967
2823
  useIsomorphicLayoutEffect$1(function () {
2968
- resetSpecs.forEach(function (_ref4) {
2969
- var stateCell = _ref4.stateCell,
2970
- node = _ref4.node;
2971
- reInitializeState(node, stateCell);
2824
+ resetSpecs.forEach(function (_ref3) {
2825
+ var stateCell = _ref3.stateCell;
2826
+ reInitializeState(stateCell);
2972
2827
  });
2973
2828
  }, [env.$props, resetSpecs]);
2974
2829
  useIsomorphicLayoutEffect$1(function () {
2975
2830
  while ($$state.registrationsQueue.length) {
2976
2831
  var _$$state$registration = $$state.registrationsQueue.shift(),
2977
- node = _$$state$registration.node,
2978
2832
  path = _$$state$registration.path,
2979
- f = _$$state$registration.f;
2980
- var stateCell = node.getState(path);
2981
- stateCell.registeredInitFunc = f;
2982
- reInitializeState(node, stateCell);
2833
+ f = _$$state$registration.f,
2834
+ overrideEnv = _$$state$registration.overrideEnv;
2835
+ var stateCell = getStateCellFrom$StateRoot($state, path);
2836
+ stateCell.initFunc = f;
2837
+ stateCell.overrideEnv = overrideEnv;
2838
+ reInitializeState(stateCell);
2983
2839
  }
2984
2840
  }, [$$state.registrationsQueue.length]);
2985
2841
  // immediately initialize exposed non-private states
@@ -2987,8 +2843,8 @@ function useDollarState(specs) {
2987
2843
  $$state.specTreeLeaves.forEach(function (node) {
2988
2844
  var spec = node.getSpec();
2989
2845
  if (!spec.isRepeated && spec.type !== "private" && spec.initFunc) {
2990
- node.createStateCell(spec.pathObj);
2991
- initializeStateValue($$state, node, spec.pathObj, $state);
2846
+ var stateCell = getStateCellFrom$StateRoot($state, spec.pathObj);
2847
+ initializeStateValue($$state, stateCell, $state);
2992
2848
  }
2993
2849
  });
2994
2850
  }, []);
@@ -2996,10 +2852,171 @@ function useDollarState(specs) {
2996
2852
  useSnapshot($$state.stateValues, {
2997
2853
  sync: true
2998
2854
  });
2999
- useSnapshot($$state.registrationsQueue);
2855
+ useSnapshot($$state.registrationsQueue, {
2856
+ sync: true
2857
+ });
3000
2858
  return $state;
3001
2859
  }
3002
2860
 
2861
+ function generateStateOnChangeProp($state, path) {
2862
+ return function (val) {
2863
+ return set($state, path, val);
2864
+ };
2865
+ }
2866
+ function generateStateValueProp($state, path) {
2867
+ return _get($state, path);
2868
+ }
2869
+ var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
2870
+ function isPlasmicStateProxy(obj) {
2871
+ return obj != null && typeof obj === "object" && !!obj[PLASMIC_STATE_PROXY_SYMBOL];
2872
+ }
2873
+ function getStateCells($state, root) {
2874
+ var _proxyObjToStateCell$;
2875
+ if ($state == null || typeof $state !== "object") {
2876
+ return [];
2877
+ }
2878
+ var stateCells = Object.values((_proxyObjToStateCell$ = proxyObjToStateCell.get($state)) != null ? _proxyObjToStateCell$ : {});
2879
+ if (root.isLeaf()) {
2880
+ return stateCells;
2881
+ }
2882
+ if (root.hasArrayTransition()) {
2883
+ return [].concat(stateCells, Object.keys($state).flatMap(function (key) {
2884
+ return getStateCells($state[key], ensure(root.makeTransition(ARRAY_SYMBOL)));
2885
+ }));
2886
+ } else {
2887
+ return [].concat(stateCells, [].concat(root.edges().entries()).flatMap(function (_ref) {
2888
+ var key = _ref[0],
2889
+ child = _ref[1];
2890
+ return typeof key === "string" && key in $state ? getStateCells($state[key], child) : [];
2891
+ }));
2892
+ }
2893
+ }
2894
+ function getStateCellsInPlasmicProxy(obj) {
2895
+ if (!isPlasmicStateProxy(obj)) {
2896
+ return [];
2897
+ }
2898
+ var _obj$PLASMIC_STATE_PR = obj[PLASMIC_STATE_PROXY_SYMBOL],
2899
+ rootNode = _obj$PLASMIC_STATE_PR.node,
2900
+ rootPath = _obj$PLASMIC_STATE_PR.path,
2901
+ isOutside = _obj$PLASMIC_STATE_PR.isOutside;
2902
+ if (isOutside) {
2903
+ return [];
2904
+ }
2905
+ return getStateCells(obj, rootNode).map(function (stateCell) {
2906
+ return {
2907
+ path: stateCell.node.getSpec().path,
2908
+ realPath: stateCell.path.slice(rootPath.length)
2909
+ };
2910
+ });
2911
+ }
2912
+ function getStateSpecInPlasmicProxy(obj, path) {
2913
+ obj = _get(obj, path.slice(0, path.length - 1));
2914
+ if (!isPlasmicStateProxy(obj)) {
2915
+ return undefined;
2916
+ }
2917
+ var _obj$PLASMIC_STATE_PR2 = obj[PLASMIC_STATE_PROXY_SYMBOL],
2918
+ node = _obj$PLASMIC_STATE_PR2.node,
2919
+ isOutside = _obj$PLASMIC_STATE_PR2.isOutside;
2920
+ var nextNode = node.makeTransition(path[path.length - 1]);
2921
+ if (isOutside || node.isLeaf() || !nextNode) {
2922
+ return undefined;
2923
+ }
2924
+ return {
2925
+ spec: nextNode.getSpec(),
2926
+ isImplicitStateArray: nextNode.hasArrayTransition()
2927
+ };
2928
+ }
2929
+ function getCurrentInitialValue(obj, path) {
2930
+ var _tryGetStateCellFrom$;
2931
+ if (!isPlasmicStateProxy(obj)) {
2932
+ return undefined;
2933
+ }
2934
+ return (_tryGetStateCellFrom$ = tryGetStateCellFrom$StateRoot(obj, path)) == null ? void 0 : _tryGetStateCellFrom$.initialValue;
2935
+ }
2936
+ function resetToInitialValue(obj, path) {
2937
+ var stateCell = tryGetStateCellFrom$StateRoot(obj, path);
2938
+ if (stateCell) {
2939
+ set(obj, path, stateCell.initialValue);
2940
+ }
2941
+ }
2942
+ function shallowEqual(a1, a2) {
2943
+ if (a1.length !== a2.length) {
2944
+ return false;
2945
+ }
2946
+ for (var i = 0; i < a1.length; i++) {
2947
+ if (a1[i] !== a2[i]) {
2948
+ return false;
2949
+ }
2950
+ }
2951
+ return true;
2952
+ }
2953
+ /**
2954
+ * Shallow comparison of arrays.
2955
+ */
2956
+ function arrayEq(xs, ys) {
2957
+ return xs.length === ys.length && xs.every(function (_, index) {
2958
+ return xs[index] === ys[index];
2959
+ });
2960
+ }
2961
+ function isNum$1(value) {
2962
+ return typeof value === "symbol" ? false : !isNaN(+value);
2963
+ }
2964
+ function assert(cond, msg) {
2965
+ if (msg === void 0) {
2966
+ msg = "Assertion failed";
2967
+ }
2968
+ if (!cond) {
2969
+ // We always generate an non empty message so that it doesn't get swallowed
2970
+ // by the async library.
2971
+ msg = (typeof msg === "string" ? msg : msg()) || "Assertion failed";
2972
+ debugger;
2973
+ throw new Error(msg);
2974
+ }
2975
+ }
2976
+ /**
2977
+ * Forked from https://github.com/lukeed/dset
2978
+ * Changes: fixed setting a deep value to a proxy object
2979
+ */
2980
+ function set(obj, keys, val) {
2981
+ keys = keys.split ? keys.split(".") : keys;
2982
+ var i = 0,
2983
+ l = keys.length,
2984
+ t = obj,
2985
+ x,
2986
+ k;
2987
+ while (i < l) {
2988
+ k = keys[i++];
2989
+ if (k === "__proto__" || k === "constructor" || k === "prototype") break;
2990
+ var newValue = i === l ? val : typeof (x = t[k]) === typeof keys ? x : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".") ? {} : [];
2991
+ assignValue(t, k, newValue);
2992
+ t = t[k];
2993
+ }
2994
+ }
2995
+ /**
2996
+ * Forked from lodash
2997
+ */
2998
+ function baseAssignValue(object, key, value) {
2999
+ if (key == "__proto__") {
3000
+ Object.defineProperty(object, key, {
3001
+ configurable: true,
3002
+ enumerable: true,
3003
+ value: value,
3004
+ writable: true
3005
+ });
3006
+ } else {
3007
+ object[key] = value;
3008
+ }
3009
+ }
3010
+ function eq(value, other) {
3011
+ return value === other || value !== value && other !== other;
3012
+ }
3013
+ function assignValue(object, key, value) {
3014
+ var objValue = object[key];
3015
+ if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) || value === undefined && !(key in object)) {
3016
+ baseAssignValue(object, key, value);
3017
+ }
3018
+ }
3019
+
3003
3020
  // Utilities used by generated code
3004
3021
  var classNames = classNames$1;
3005
3022
 
@@ -4477,5 +4494,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
4477
4494
  };
4478
4495
  }
4479
4496
 
4480
- export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
4497
+ export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getCurrentInitialValue, getDataProps, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, resetToInitialValue, set, setPlumeStrictMode, useButton, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
4481
4498
  //# sourceMappingURL=react-web.esm.js.map