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