@plasmicapp/react-web 0.2.137 → 0.2.138

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.
@@ -10,8 +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, ref, useSnapshot } from 'valtio';
14
- import { subscribeKey } from 'valtio/utils';
13
+ import { proxy, useSnapshot, ref } from 'valtio';
15
14
  import { useCheckbox as useCheckbox$1 } from '@react-aria/checkbox';
16
15
  import { VisuallyHidden } from '@react-aria/visually-hidden';
17
16
  import { useToggleState } from '@react-stately/toggle';
@@ -1519,6 +1518,33 @@ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
1519
1518
  ) {
1520
1519
  return _get($state, path);
1521
1520
  }
1521
+ var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
1522
+ function shallowEqual(a1, a2) {
1523
+ if (a1.length !== a2.length) {
1524
+ return false;
1525
+ }
1526
+ for (var i = 0; i < a1.length; i++) {
1527
+ if (a1[i] !== a2[i]) {
1528
+ return false;
1529
+ }
1530
+ }
1531
+ return true;
1532
+ }
1533
+ function isNum(value) {
1534
+ return typeof value === "symbol" ? false : !isNaN(+value);
1535
+ }
1536
+ function assert(cond, msg) {
1537
+ if (msg === void 0) {
1538
+ msg = "Assertion failed";
1539
+ }
1540
+ if (!cond) {
1541
+ // We always generate an non empty message so that it doesn't get swallowed
1542
+ // by the async library.
1543
+ msg = (typeof msg === "string" ? msg : msg()) || "Assertion failed";
1544
+ debugger;
1545
+ throw new Error(msg);
1546
+ }
1547
+ }
1522
1548
  /**
1523
1549
  * Forked from https://github.com/lukeed/dset
1524
1550
  * Changes: fixed setting a deep value to a proxy object
@@ -1533,44 +1559,44 @@ function set(obj, keys, val) {
1533
1559
  while (i < l) {
1534
1560
  k = keys[i++];
1535
1561
  if (k === "__proto__" || k === "constructor" || k === "prototype") break;
1536
- if (i === l) {
1537
- t[k] = val;
1538
- t = t[k];
1539
- } else {
1540
- if (typeof (x = t[k]) === typeof keys) {
1541
- t = t[k] = x;
1542
- } else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
1543
- t[k] = {};
1544
- t = t[k];
1545
- } else {
1546
- t[k] = [];
1547
- t = t[k];
1548
- }
1549
- }
1562
+ var newValue = i === l ? val : typeof (x = t[k]) === typeof keys ? x : keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".") ? {} : [];
1563
+ assignValue(t, k, newValue);
1564
+ t = t[k];
1550
1565
  }
1551
1566
  }
1552
- var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
1553
- function shallowEqual(a1, a2) {
1554
- if (a1.length !== a2.length) {
1555
- return false;
1556
- }
1557
- for (var i = 0; i < a1.length; i++) {
1558
- if (a1[i] !== a2[i]) {
1559
- return false;
1560
- }
1567
+ /**
1568
+ * Forked from lodash
1569
+ */
1570
+ function baseAssignValue(object, key, value) {
1571
+ if (key == "__proto__") {
1572
+ Object.defineProperty(object, key, {
1573
+ configurable: true,
1574
+ enumerable: true,
1575
+ value: value,
1576
+ writable: true
1577
+ });
1578
+ } else {
1579
+ object[key] = value;
1561
1580
  }
1562
- return true;
1563
1581
  }
1564
- function isNum(value) {
1565
- return typeof value === "symbol" ? false : !isNaN(+value);
1582
+ function eq(value, other) {
1583
+ return value === other || value !== value && other !== other;
1584
+ }
1585
+ function assignValue(object, key, value) {
1586
+ var objValue = object[key];
1587
+ if (!(Object.prototype.hasOwnProperty.call(object, key) && eq(objValue, value)) || value === undefined && !(key in object)) {
1588
+ baseAssignValue(object, key, value);
1589
+ }
1566
1590
  }
1567
1591
 
1568
1592
  var ARRAY_SYMBOL = /*#__PURE__*/Symbol("[]");
1569
1593
 
1594
+ var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
1570
1595
  var StateSpecNode = /*#__PURE__*/function () {
1571
1596
  function StateSpecNode(specs) {
1572
1597
  this.specs = specs;
1573
1598
  this.edges = new Map();
1599
+ this.state = {};
1574
1600
  }
1575
1601
  var _proto = StateSpecNode.prototype;
1576
1602
  _proto.hasEdge = function hasEdge(key) {
@@ -1579,6 +1605,9 @@ var StateSpecNode = /*#__PURE__*/function () {
1579
1605
  _proto.addEdge = function addEdge(key, node) {
1580
1606
  this.edges.set(key, node);
1581
1607
  };
1608
+ _proto.children = function children() {
1609
+ return this.edges.values();
1610
+ };
1582
1611
  _proto.makeTransition = function makeTransition(key) {
1583
1612
  key = isNum(key) ? ARRAY_SYMBOL : key;
1584
1613
  return this.edges.get(key);
@@ -1595,6 +1624,40 @@ var StateSpecNode = /*#__PURE__*/function () {
1595
1624
  _proto.getAllSpecs = function getAllSpecs() {
1596
1625
  return this.specs;
1597
1626
  };
1627
+ _proto.getState = function getState(path) {
1628
+ return this.state[JSON.stringify(path)];
1629
+ };
1630
+ _proto.clearStates = function clearStates() {
1631
+ this.state = {};
1632
+ };
1633
+ _proto.states = function states() {
1634
+ return Object.values(this.state);
1635
+ };
1636
+ _proto.hasState = function hasState(path) {
1637
+ var key = JSON.stringify(path);
1638
+ return key in this.state;
1639
+ };
1640
+ _proto.createStateCell = function createStateCell(path) {
1641
+ var key = JSON.stringify(path);
1642
+ this.state[key] = {
1643
+ listeners: [],
1644
+ initialValue: UNINITIALIZED,
1645
+ registeredInitFunc: this.getSpec().initFunc,
1646
+ path: path
1647
+ };
1648
+ };
1649
+ _proto.setInitialValue = function setInitialValue(path, value) {
1650
+ var key = JSON.stringify(path);
1651
+ this.state[key].initialValue = value;
1652
+ };
1653
+ _proto.getInitialValue = function getInitialValue(path) {
1654
+ var key = JSON.stringify(path);
1655
+ return this.state[key].initialValue;
1656
+ };
1657
+ _proto.addListener = function addListener(path, f) {
1658
+ var key = JSON.stringify(path);
1659
+ this.state[key].listeners.push(f);
1660
+ };
1598
1661
  return StateSpecNode;
1599
1662
  }();
1600
1663
  var transformPathStringToObj = function transformPathStringToObj(str) {
@@ -1603,7 +1666,7 @@ var transformPathStringToObj = function transformPathStringToObj(str) {
1603
1666
  };
1604
1667
  return str.split(".").flatMap(splitStatePathPart);
1605
1668
  };
1606
- function buildGraph(specs) {
1669
+ function buildTree(specs) {
1607
1670
  var internalSpec = specs.map(function (spec) {
1608
1671
  return _extends({}, spec, {
1609
1672
  pathObj: transformPathStringToObj(spec.path),
@@ -1628,339 +1691,311 @@ function buildGraph(specs) {
1628
1691
  };
1629
1692
  return rec([]);
1630
1693
  }
1631
-
1632
- var mkUntrackedValue = function mkUntrackedValue(o) {
1633
- return o != null && typeof o === "object" ? ref(o) : o;
1634
- };
1635
- function shallowEqual$1(a1, a2) {
1636
- if (a1.length !== a2.length) {
1637
- return false;
1638
- }
1639
- for (var i = 0; i < a1.length; i++) {
1640
- if (a1[i] !== a2[i]) {
1641
- return false;
1694
+ function getLeaves(root) {
1695
+ var leaves = [];
1696
+ var rec = function rec(node) {
1697
+ for (var _iterator = _createForOfIteratorHelperLoose(node.children()), _step; !(_step = _iterator()).done;) {
1698
+ var child = _step.value;
1699
+ rec(child);
1700
+ }
1701
+ if (node.isLeaf()) {
1702
+ leaves.push(node);
1703
+ }
1704
+ };
1705
+ rec(root);
1706
+ return leaves;
1707
+ }
1708
+ function findStateCell(root, pathStr, repetitionIndex) {
1709
+ var realPath = [];
1710
+ var pathObj = transformPathStringToObj(pathStr);
1711
+ var currRepIndex = 0;
1712
+ for (var _iterator2 = _createForOfIteratorHelperLoose(pathObj), _step2; !(_step2 = _iterator2()).done;) {
1713
+ var part = _step2.value;
1714
+ if (typeof part === "symbol") {
1715
+ if (!root.hasArrayTransition() || !repetitionIndex || currRepIndex > repetitionIndex.length) {
1716
+ console.log(root);
1717
+ throw new Error("transition not found: pathStr " + pathStr + " part " + (typeof part === "symbol" ? "[]" : part));
1718
+ }
1719
+ realPath.push(repetitionIndex[currRepIndex++]);
1720
+ root = root.makeTransition(ARRAY_SYMBOL);
1721
+ } else {
1722
+ if (!root.hasEdge(part)) {
1723
+ throw new Error("transition not found: pathStr " + pathStr + " part " + (typeof part === "symbol" ? "[]" : part));
1724
+ }
1725
+ realPath.push(part);
1726
+ root = root.makeTransition(part);
1642
1727
  }
1643
1728
  }
1644
- return true;
1729
+ return {
1730
+ node: root,
1731
+ realPath: realPath
1732
+ };
1645
1733
  }
1734
+
1646
1735
  function isNum$1(value) {
1647
1736
  return typeof value === "symbol" ? false : !isNaN(+value);
1648
1737
  }
1649
- function saveNewState($$state, path, spec) {
1650
- var key = JSON.stringify(path);
1651
- $$state.existingStates.set(key, {
1652
- path: path,
1653
- specKey: spec.path
1738
+ function canProxy(value) {
1739
+ return typeof value === "object" && value != null;
1740
+ }
1741
+ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyRoot) {
1742
+ var stateAccess = new Set();
1743
+ var $state = create$StateProxy($$state, function (node, path) {
1744
+ return {
1745
+ get: function get() {
1746
+ stateAccess.add({
1747
+ path: path,
1748
+ node: node
1749
+ });
1750
+ var spec = node.getSpec();
1751
+ if (spec.valueProp) {
1752
+ return $$state.props[spec.valueProp];
1753
+ } else if (!node.hasState(path) && spec.initFunc) {
1754
+ return initializeStateValue($$state, node, path, proxyRoot);
1755
+ }
1756
+ return _get(proxyRoot, path);
1757
+ },
1758
+ set: function set() {
1759
+ throw new Error("Cannot update state values during initialization");
1760
+ }
1761
+ };
1654
1762
  });
1655
- if (!$$state.statesInstanceBySpec.has(spec.path)) {
1656
- $$state.statesInstanceBySpec.set(spec.path, []);
1657
- }
1658
- $$state.statesInstanceBySpec.get(spec.path).push({
1659
- path: path,
1660
- specKey: spec.path
1763
+ stateAccess.forEach(function (_ref) {
1764
+ var node = _ref.node,
1765
+ path = _ref.path;
1766
+ node.addListener(path, function () {
1767
+ var newValue = initialSpecNode.getSpec().initFunc($$state.props, $state, $$state.ctx);
1768
+ set(proxyRoot, initialStatePath, newValue);
1769
+ });
1661
1770
  });
1771
+ var initialValue = initialSpecNode.getState(initialStatePath).registeredInitFunc($$state.props, $state, $$state.ctx);
1772
+ initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
1773
+ var initialSpec = initialSpecNode.getSpec();
1774
+ var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
1775
+ set(proxyRoot, initialStatePath, value);
1776
+ //immediately fire onChange
1777
+ if (initialSpec.onChangeProp) {
1778
+ var _$$state$props$initia, _$$state$props;
1779
+ (_$$state$props$initia = (_$$state$props = $$state.props)[initialSpec.onChangeProp]) == null ? void 0 : _$$state$props$initia.call(_$$state$props, initialValue);
1780
+ }
1781
+ return initialValue;
1662
1782
  }
1663
- function create$StateProxy($$state, handlers) {
1664
- var rec = function rec(currPath, currNode) {
1783
+ function create$StateProxy($$state, leafHandlers) {
1784
+ var rec = function rec(currPath, currNode, isOutside, proxyRoot, initialObject) {
1665
1785
  var getNextPath = function getNextPath(property) {
1666
1786
  return [].concat(currPath, [isNum$1(property) ? +property : property]);
1667
1787
  };
1668
- return new Proxy(currNode.hasArrayTransition() ? [] : {}, {
1788
+ var spec = currNode.getSpec();
1789
+ var handlers = {
1669
1790
  deleteProperty: function deleteProperty(target, property) {
1670
- var prefixPath = getNextPath(property);
1671
- var specKeysToUpdate = new Set();
1672
- $$state.existingStates.forEach(function (_ref) {
1673
- var path = _ref.path,
1674
- specKey = _ref.specKey;
1675
- if (path.length >= prefixPath.length && shallowEqual$1(path.slice(0, prefixPath.length), prefixPath)) {
1676
- deleteState($$state, path);
1677
- specKeysToUpdate.add(specKey);
1678
- }
1679
- });
1680
- specKeysToUpdate.forEach(function (specKey) {
1681
- var spec = $$state.specsByKey[specKey];
1682
- if (spec.onChangeProp) {
1683
- var _$$state$props$spec$o, _$$state$props;
1684
- (_$$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);
1685
- }
1686
- });
1791
+ if (!isOutside && !currNode.isLeaf() && !currNode.hasArrayTransition() && !isNum$1(property)) {
1792
+ throw new Error("Can't delete a property in the middle of the state spec");
1793
+ }
1794
+ delete _get($$state.stateValues, currPath)[property];
1795
+ if (spec.onChangeProp) {
1796
+ var _$$state$props$spec$o, _$$state$props2;
1797
+ //we are always in a leaf, since we only have two cases:
1798
+ // 1 - delete properties outside the state tree
1799
+ // 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
1800
+ (_$$state$props$spec$o = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o.call(_$$state$props2, _get($$state.stateValues, currPath.slice(spec.pathObj.length)));
1801
+ }
1687
1802
  return Reflect.deleteProperty(target, property);
1688
1803
  },
1689
1804
  get: function get(target, property, receiver) {
1805
+ proxyRoot = proxyRoot == null ? receiver : proxyRoot;
1690
1806
  var nextPath = getNextPath(property);
1807
+ if (isOutside || currNode.isLeaf()) {
1808
+ return Reflect.get(target, property, receiver);
1809
+ }
1691
1810
  var nextNode = currNode.makeTransition(property);
1692
- if (nextNode) {
1693
- if (nextNode.isLeaf()) {
1694
- var _handlers$get, _handlers;
1695
- target[property] = (_handlers$get = (_handlers = handlers(nextPath, nextNode.getSpec())).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
1696
- } else if (!(property in target)) {
1697
- target[property] = rec(nextPath, nextNode);
1698
- }
1811
+ if (nextNode != null && nextNode.isLeaf()) {
1812
+ var _leafHandlers$get, _leafHandlers;
1813
+ return (_leafHandlers$get = (_leafHandlers = leafHandlers(nextNode, nextPath, proxyRoot)).get) == null ? void 0 : _leafHandlers$get.call(_leafHandlers, target, property, receiver);
1814
+ } else if (nextNode && !(property in target)) {
1815
+ target[property] = rec(nextPath, nextNode, false, proxyRoot, undefined);
1699
1816
  }
1700
1817
  return Reflect.get(target, property, receiver);
1701
1818
  },
1702
1819
  set: function set$1(target, property, value, receiver) {
1820
+ var _nextNode, _nextNode2;
1821
+ proxyRoot = proxyRoot == null ? receiver : proxyRoot;
1703
1822
  var nextPath = getNextPath(property);
1704
1823
  var nextNode = currNode.makeTransition(property);
1705
- if (nextNode && typeof property !== "symbol") {
1706
- if (nextNode.isLeaf()) {
1707
- var _handlers$set, _handlers2;
1708
- // reached the end of the spec
1709
- target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, nextNode.getSpec())).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
1710
- return Reflect.set(target, property, value, receiver);
1711
- } else if (typeof value === "object") {
1712
- target[property] = rec(nextPath, nextNode);
1713
- for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
1714
- var key = _Object$keys[_i];
1715
- target[property][key] = value[key];
1716
- }
1717
- return true;
1718
- }
1719
- }
1720
1824
  if (property === "registerInitFunc" && currPath.length === 0) {
1721
1825
  return Reflect.set(target, property, value, receiver);
1722
1826
  }
1723
- if (currNode.hasArrayTransition()) {
1724
- var _currNode$makeTransit, _currNode$makeTransit2;
1827
+ if (!nextNode && currNode.hasArrayTransition()) {
1725
1828
  set($$state.stateValues, nextPath, value);
1726
- (_currNode$makeTransit = currNode.makeTransition(ARRAY_SYMBOL)) == null ? void 0 : (_currNode$makeTransit2 = _currNode$makeTransit.getAllSpecs()) == null ? void 0 : _currNode$makeTransit2.forEach(function (spec) {
1727
- if (spec.onChangeProp) {
1728
- var _$$state$props$spec$o2, _$$state$props2;
1729
- (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
1730
- }
1731
- });
1829
+ //array can set his own properties such as length, map, ...
1732
1830
  return Reflect.set(target, property, value, receiver);
1733
1831
  }
1734
- // invalid setting a value that doesn't make part of the spec
1735
- return false;
1736
- }
1737
- });
1738
- };
1739
- return rec([], $$state.rootStateSpec);
1740
- }
1741
- var deleteState = function deleteState($$state, path) {
1742
- var _$$state$unsubscripti;
1743
- var key = JSON.stringify(path);
1744
- (_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
1745
- return f();
1746
- });
1747
- delete $$state.unsubscriptionsByState[key];
1748
- $$state.existingStates["delete"](key);
1749
- // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
1750
- // delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
1751
- };
1752
-
1753
- var getIndexes = function getIndexes(path, spec) {
1754
- var indexes = [];
1755
- if (path.length !== spec.pathObj.length) {
1756
- throw new Error("Unexpected error: state path and spec path have different lengths");
1757
- }
1758
- for (var i = 0; i < spec.pathObj.length; i++) {
1759
- if (spec.pathObj[i] === "[]") {
1760
- indexes.push(path[i]);
1761
- }
1762
- }
1763
- return indexes;
1764
- };
1765
- function initializeStateValue($$state, initialStatePath, initialSpec) {
1766
- var _$$state$unsubscripti2;
1767
- var initialStateKey = JSON.stringify(initialStatePath);
1768
- var stateAccess = new Set();
1769
- var $state = create$StateProxy($$state, function (path, spec) {
1770
- return {
1771
- get: function get() {
1772
- var key = JSON.stringify(path);
1773
- stateAccess.add({
1774
- path: path,
1775
- spec: spec
1776
- });
1777
- if (spec.valueProp) {
1778
- return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
1832
+ if ((_nextNode = nextNode) != null && _nextNode.isLeaf()) {
1833
+ var _leafHandlers$set, _leafHandlers2;
1834
+ (_leafHandlers$set = (_leafHandlers2 = leafHandlers(nextNode, nextPath, proxyRoot)).set) == null ? void 0 : _leafHandlers$set.call(_leafHandlers2, target, property, value, receiver);
1779
1835
  }
1780
- if ($$state.existingStates.has(key)) {
1781
- // is already initialized
1782
- return _get($$state.stateValues, path);
1783
- } else if (spec.initFunc) {
1784
- initializeStateValue($$state, path, spec);
1836
+ if (!isOutside && !currNode.isLeaf() && !nextNode) {
1837
+ // can't set an unknown field in $state
1838
+ return false;
1785
1839
  }
1786
- return _get($$state.stateValues, path);
1787
- },
1788
- set: function set() {
1789
- throw new Error("Cannot update state values during initialization");
1840
+ // we keep pointing to the leaf
1841
+ if (!nextNode) {
1842
+ assert(isOutside || currNode.isLeaf, "unexpected update in nextNode");
1843
+ nextNode = currNode;
1844
+ }
1845
+ if (canProxy(value)) {
1846
+ target[property] = rec(nextPath, nextNode, isOutside || currNode.isLeaf(), proxyRoot, value);
1847
+ } else if (!isOutside && !currNode.isLeaf() && !((_nextNode2 = nextNode) != null && _nextNode2.isLeaf())) {
1848
+ throw new Error("inserting a primitive value into a non-leaf");
1849
+ } else {
1850
+ Reflect.set(target, property, value, receiver);
1851
+ }
1852
+ nextNode.getAllSpecs().forEach(function (spec) {
1853
+ if (spec.onChangeProp) {
1854
+ var _$$state$props$spec$o2, _$$state$props3;
1855
+ (_$$state$props$spec$o2 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props3, value);
1856
+ }
1857
+ });
1858
+ var newValue = (isOutside || currNode.isLeaf()) && currNode.getSpec().isImmutable ? mkUntrackedValue(value) : value;
1859
+ set($$state.stateValues, nextPath, newValue);
1860
+ return true;
1790
1861
  }
1791
1862
  };
1792
- });
1793
- (_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
1794
- return f();
1795
- });
1796
- $$state.unsubscriptionsByState[initialStateKey] = [];
1797
- stateAccess.forEach(function (_ref2) {
1798
- var path = _ref2.path,
1799
- spec = _ref2.spec;
1800
- var unsubscribe = subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
1801
- return saveValue($$state, initialStatePath, initialSpec, initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(path, spec)));
1802
- });
1803
- $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
1804
- });
1805
- var initialValue = initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(initialStatePath, initialSpec));
1806
- saveStateInitialValue($$state, initialStatePath, initialSpec, initialValue);
1807
- return initialValue;
1808
- }
1809
- function saveValue($$state, path, spec, value) {
1810
- if (spec.isImmutable) {
1811
- set($$state.stateValues, path, mkUntrackedValue(value));
1812
- } else {
1813
- set($$state.stateValues, path, value);
1814
- }
1815
- }
1816
- function saveStateInitialValue($$state, path, spec, initialValue) {
1817
- if (spec.isImmutable) {
1818
- var untrackedValue = mkUntrackedValue(initialValue);
1819
- set($$state.stateValues, path, untrackedValue);
1820
- set($$state.initStateValues, path, clone(untrackedValue));
1821
- } else {
1822
- set($$state.stateValues, path, clone(initialValue));
1823
- set($$state.initStateValues, path, clone(initialValue));
1824
- }
1863
+ var baseObject = !isOutside && !currNode.isLeaf() ? currNode.hasArrayTransition() ? [] : {} : Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject));
1864
+ var proxyObj = new Proxy(baseObject, handlers);
1865
+ if (initialObject) {
1866
+ Reflect.ownKeys(initialObject).forEach(function (key) {
1867
+ var desc = Object.getOwnPropertyDescriptor(initialObject, key);
1868
+ if (desc.get || desc.set) {
1869
+ Object.defineProperty(baseObject, key, desc);
1870
+ } else {
1871
+ proxyObj[key] = initialObject[key];
1872
+ }
1873
+ });
1874
+ }
1875
+ return proxyObj;
1876
+ };
1877
+ return rec([], $$state.rootSpecTree, false, undefined, undefined);
1825
1878
  }
1879
+ var mkUntrackedValue = function mkUntrackedValue(o) {
1880
+ return o != null && typeof o === "object" ? ref(o) : o;
1881
+ };
1826
1882
  function useDollarState(specs, props, $ctx) {
1827
- var $$state = React__default.useRef(proxy({
1828
- stateValues: {},
1829
- initStateValues: {},
1830
- specsByKey: Object.fromEntries(specs.map(function (spec) {
1831
- return [spec.path, _extends({}, spec, {
1832
- pathObj: transformPathStringToObj(spec.path),
1833
- isRepeated: spec.path.split(".").some(function (part) {
1834
- return part.endsWith("[]");
1835
- })
1836
- })];
1837
- })),
1838
- statesInstanceBySpec: new Map(),
1839
- existingStates: new Map(),
1840
- unsubscriptionsByState: {},
1841
- props: {},
1842
- ctx: {},
1843
- registrationsQueue: [],
1844
- rootStateSpec: buildGraph(specs)
1845
- })).current;
1846
- $$state.props = mkUntrackedValue(props);
1847
- $$state.ctx = mkUntrackedValue($ctx != null ? $ctx : {});
1848
- var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
1849
- var key = JSON.stringify(path);
1850
- if (!$$state.existingStates.has(key)) {
1851
- var _spec$initVal;
1852
- saveNewState($$state, path, spec);
1853
- var initialValue = !spec.initFunc ? (_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined : initializeStateValue($$state, path, spec);
1854
- saveStateInitialValue($$state, path, spec, initialValue);
1855
- }
1883
+ var $$state = React__default.useRef(function () {
1884
+ var rootSpecTree = buildTree(specs);
1856
1885
  return {
1857
- get: function get() {
1858
- if (spec.valueProp) {
1859
- var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
1860
- return value;
1861
- } else {
1862
- return _get($$state.stateValues, path);
1863
- }
1864
- },
1865
- set: function set(_t, _p, value) {
1866
- saveValue($$state, path, spec, value);
1867
- if (spec.onChangeProp) {
1868
- var _$$state$props$spec$o3, _$$state$props3;
1869
- (_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
1886
+ rootSpecTree: rootSpecTree,
1887
+ specTreeLeaves: getLeaves(rootSpecTree),
1888
+ stateValues: proxy({}),
1889
+ props: {},
1890
+ ctx: {},
1891
+ registrationsQueue: []
1892
+ };
1893
+ }()).current;
1894
+ $$state.props = props;
1895
+ $$state.ctx = $ctx != null ? $ctx : {};
1896
+ var $state = React__default.useRef(function () {
1897
+ var useRef$state = Object.assign(create$StateProxy($$state, function (node, path, proxyRoot) {
1898
+ if (!node.hasState(path)) {
1899
+ node.createStateCell(path);
1900
+ var spec = node.getSpec();
1901
+ if (spec.initFunc) {
1902
+ initializeStateValue($$state, node, path, proxyRoot);
1903
+ } else if (!spec.valueProp) {
1904
+ set(proxyRoot, path, spec.initVal);
1870
1905
  }
1871
- return true;
1872
1906
  }
1873
- };
1874
- }), {
1875
- registerInitFunc: function registerInitFunc(pathStr, f) {
1876
- var _$$state$statesInstan;
1877
- if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
1878
- var path = _ref3.path,
1879
- specKey = _ref3.specKey;
1880
- return !deepEqual(_get($$state.initStateValues, path), f(props, $state, $ctx != null ? $ctx : {}, getIndexes(path, $$state.specsByKey[specKey])));
1881
- })) {
1882
- $$state.registrationsQueue.push({
1883
- pathStr: pathStr,
1884
- f: f
1885
- });
1907
+ return {
1908
+ get: function get(target, property, receiver) {
1909
+ var spec = node.getSpec();
1910
+ if (spec.valueProp) {
1911
+ return $$state.props[spec.valueProp];
1912
+ } else {
1913
+ return Reflect.get(target, property, receiver);
1914
+ }
1915
+ }
1916
+ };
1917
+ }), {
1918
+ registerInitFunc: function registerInitFunc(pathStr, f, repetitionIndex) {
1919
+ var _findStateCell = findStateCell($$state.rootSpecTree, pathStr, repetitionIndex),
1920
+ node = _findStateCell.node,
1921
+ realPath = _findStateCell.realPath;
1922
+ if (!node.hasState(realPath)) {
1923
+ node.createStateCell(realPath);
1924
+ }
1925
+ if (!deepEqual(node.getState(realPath).initialValue, f($$state.props, useRef$state, $$state.ctx))) {
1926
+ $$state.registrationsQueue.push({
1927
+ node: node,
1928
+ path: realPath,
1929
+ f: f
1930
+ });
1931
+ }
1886
1932
  }
1887
- }
1888
- })).current;
1933
+ });
1934
+ return useRef$state;
1935
+ }()).current;
1889
1936
  // For each spec with an initFunc, evaluate it and see if
1890
1937
  // the init value has changed. If so, reset its state.
1891
1938
  var resetSpecs = [];
1892
- $$state.existingStates.forEach(function (_ref4) {
1893
- var path = _ref4.path,
1894
- specKey = _ref4.specKey;
1895
- var spec = $$state.specsByKey[specKey];
1896
- if (spec.initFunc) {
1897
- var newInit = spec.initFunc(props, $state, $ctx != null ? $ctx : {}, getIndexes(path, spec));
1898
- if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
1939
+ $$state.specTreeLeaves.flatMap(function (node) {
1940
+ return node.states().map(function (stateCell) {
1941
+ return {
1942
+ stateCell: stateCell,
1943
+ node: node
1944
+ };
1945
+ });
1946
+ }).forEach(function (_ref2) {
1947
+ var stateCell = _ref2.stateCell,
1948
+ node = _ref2.node;
1949
+ if (stateCell.registeredInitFunc) {
1950
+ var newInit = stateCell.registeredInitFunc(props, $state, $ctx != null ? $ctx : {});
1951
+ if (!deepEqual(newInit, stateCell.initialValue)) {
1899
1952
  resetSpecs.push({
1900
- path: path,
1901
- spec: spec
1953
+ stateCell: stateCell,
1954
+ node: node
1902
1955
  });
1903
1956
  }
1904
1957
  }
1905
1958
  });
1959
+ var reInitializeState = function reInitializeState(node, stateCell) {
1960
+ var newInit = initializeStateValue($$state, node, stateCell.path, $state);
1961
+ var spec = node.getSpec();
1962
+ if (spec.onChangeProp) {
1963
+ var _$$state$props$spec$o3, _$$state$props4;
1964
+ (_$$state$props$spec$o3 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props4, newInit);
1965
+ }
1966
+ };
1906
1967
  useIsomorphicLayoutEffect$1(function () {
1907
- resetSpecs.forEach(function (_ref5) {
1908
- var path = _ref5.path,
1909
- spec = _ref5.spec;
1910
- var newInit = initializeStateValue($$state, path, spec);
1911
- if (spec.onChangeProp) {
1912
- var _$$state$props$spec$o4, _$$state$props4;
1913
- (_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
1914
- }
1968
+ resetSpecs.forEach(function (_ref3) {
1969
+ var stateCell = _ref3.stateCell,
1970
+ node = _ref3.node;
1971
+ reInitializeState(node, stateCell);
1915
1972
  });
1916
1973
  }, [props, resetSpecs]);
1917
1974
  useIsomorphicLayoutEffect$1(function () {
1918
- $$state.registrationsQueue.forEach(function (_ref6) {
1919
- var f = _ref6.f,
1920
- pathStr = _ref6.pathStr;
1921
- $$state.specsByKey[pathStr].initFunc = f;
1975
+ $$state.registrationsQueue.forEach(function (_ref4) {
1976
+ var node = _ref4.node,
1977
+ path = _ref4.path,
1978
+ f = _ref4.f;
1979
+ var stateCell = node.getState(path);
1980
+ stateCell.registeredInitFunc = f;
1981
+ reInitializeState(node, stateCell);
1922
1982
  });
1923
1983
  $$state.registrationsQueue = [];
1924
1984
  }, [$$state.registrationsQueue]);
1985
+ // immediately initialize exposed non-private states
1986
+ useIsomorphicLayoutEffect$1(function () {
1987
+ $$state.specTreeLeaves.forEach(function (node) {
1988
+ var spec = node.getSpec();
1989
+ if (!spec.isRepeated && spec.type !== "private" && spec.initFunc) {
1990
+ node.createStateCell(spec.pathObj);
1991
+ initializeStateValue($$state, node, spec.pathObj, $state);
1992
+ }
1993
+ });
1994
+ }, []);
1925
1995
  // Re-render if any value changed in one of these objects
1926
1996
  useSnapshot($$state.stateValues, {
1927
1997
  sync: true
1928
1998
  });
1929
- useSnapshot($$state.specsByKey, {
1930
- sync: true
1931
- });
1932
- return $state;
1933
- }
1934
- // Simple version of $state useDollarState for read-only
1935
- function useCanvasDollarState(specs, props, $ctx) {
1936
- var $$state = proxy({
1937
- stateValues: {},
1938
- initStateValues: {},
1939
- specsByKey: Object.fromEntries(specs.map(function (spec) {
1940
- return [spec.path, _extends({}, spec, {
1941
- pathObj: transformPathStringToObj(spec.path),
1942
- isRepeated: spec.path.split(".").some(function (part) {
1943
- return part.endsWith("[]");
1944
- })
1945
- })];
1946
- })),
1947
- statesInstanceBySpec: new Map(),
1948
- existingStates: new Map(),
1949
- unsubscriptionsByState: {},
1950
- props: {},
1951
- ctx: {},
1952
- registrationsQueue: [],
1953
- rootStateSpec: buildGraph(specs)
1954
- });
1955
- $$state.props = mkUntrackedValue(props);
1956
- $$state.ctx = mkUntrackedValue($ctx);
1957
- var $state = {};
1958
- for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
1959
- var spec = _step.value;
1960
- var path = transformPathStringToObj(spec.path);
1961
- var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
1962
- set($state, path, init);
1963
- }
1964
1999
  return $state;
1965
2000
  }
1966
2001
 
@@ -3360,5 +3395,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
3360
3395
  };
3361
3396
  }
3362
3397
 
3363
- export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, isNum, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, shallowEqual, useButton, useCanvasDollarState, useCheckbox, useDollarState, useIsSSR, useIsomorphicLayoutEffect$1 as useIsomorphicLayoutEffect, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3398
+ export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicPageGuard, 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, useCheckbox, useDollarState, useIsSSR, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3364
3399
  //# sourceMappingURL=react-web.esm.js.map