@plasmicapp/react-web 0.2.139 → 0.2.141
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 +6 -9
- package/dist/react-web.cjs.development.js +151 -72
- 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 +151 -72
- package/dist/react-web.esm.js.map +1 -1
- package/dist/states/graph.d.ts +10 -4
- package/dist/states/helpers.d.ts +7 -9
- package/dist/states/valtio.d.ts +3 -1
- package/dist/stories/UseDollarState.stories.d.ts +7 -0
- package/package.json +6 -6
- package/skinny/dist/index.js +143 -68
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/states/graph.d.ts +10 -4
- package/skinny/dist/states/helpers.d.ts +7 -9
- package/skinny/dist/states/valtio.d.ts +3 -1
- package/skinny/dist/stories/UseDollarState.stories.d.ts +7 -0
package/dist/all.d.ts
CHANGED
|
@@ -52,6 +52,7 @@ declare type HTMLElementRefOf<T extends keyof JSX.IntrinsicElements> = Exclude<R
|
|
|
52
52
|
declare function dlv(object: object, key: string | Array<string | number>, defaultValue?: any): any;
|
|
53
53
|
|
|
54
54
|
declare type InitFunc<T> = ($props: Record<string, any>, $state: $State, $ctx: Record<string, any>, indexes?: number[]) => T;
|
|
55
|
+
declare type ObjectPath = (string | number)[];
|
|
55
56
|
interface $StateSpec<T> {
|
|
56
57
|
path: string;
|
|
57
58
|
initFunc?: InitFunc<T>;
|
|
@@ -66,14 +67,8 @@ interface $State {
|
|
|
66
67
|
registerInitFunc?: (path: string, f: InitFunc<any>, repetitonIndex?: number[]) => any;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
declare function generateStateOnChangeProp($state: $State,
|
|
70
|
-
|
|
71
|
-
* This function generate the state value prop for repeated states
|
|
72
|
-
* Example:
|
|
73
|
-
* - parent[][].counter[].count
|
|
74
|
-
* We need to pass `parent[index1][index2].counter to the child component
|
|
75
|
-
*/
|
|
76
|
-
declare function generateStateValueProp($state: $State, path: (string | number)[]): any;
|
|
70
|
+
declare function generateStateOnChangeProp($state: $State, path: ObjectPath): (val: any) => void;
|
|
71
|
+
declare function generateStateValueProp($state: $State, path: ObjectPath): any;
|
|
77
72
|
declare function isPlasmicStateProxy(obj: any): any;
|
|
78
73
|
/**
|
|
79
74
|
* Forked from https://github.com/lukeed/dset
|
|
@@ -81,7 +76,9 @@ declare function isPlasmicStateProxy(obj: any): any;
|
|
|
81
76
|
*/
|
|
82
77
|
declare function set(obj: any, keys: any, val: any): void;
|
|
83
78
|
|
|
84
|
-
declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any
|
|
79
|
+
declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>, opts?: {
|
|
80
|
+
inCanvas: boolean;
|
|
81
|
+
}): $State;
|
|
85
82
|
|
|
86
83
|
interface Variants {
|
|
87
84
|
[vg: string]: any;
|
|
@@ -1285,10 +1285,16 @@ function renderPlasmicSlot(opts) {
|
|
|
1285
1285
|
}
|
|
1286
1286
|
function maybeAsString(node) {
|
|
1287
1287
|
// Unwrap fragments
|
|
1288
|
-
if (React.isValidElement(node)
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1288
|
+
if (React.isValidElement(node)) {
|
|
1289
|
+
// Fragment doesn't render DOM elements
|
|
1290
|
+
if (node.type === React.Fragment) {
|
|
1291
|
+
return maybeAsString(node.props.children);
|
|
1292
|
+
} else if (node.type === Trans) {
|
|
1293
|
+
// Trans also doesn't render DOM elements. But we don't want to just render
|
|
1294
|
+
// its content string, because we want to keep the <Trans/> for the localization.
|
|
1295
|
+
// So we render the same node, to be wrapped into __wab_slot-string-wrapper.
|
|
1296
|
+
return node;
|
|
1297
|
+
}
|
|
1292
1298
|
}
|
|
1293
1299
|
if (typeof node === "string") {
|
|
1294
1300
|
return node;
|
|
@@ -1511,19 +1517,12 @@ function useTrigger(trigger, opts) {
|
|
|
1511
1517
|
var ARRAY_SYMBOL = /*#__PURE__*/Symbol("[]");
|
|
1512
1518
|
var PLASMIC_STATE_PROXY_SYMBOL = /*#__PURE__*/Symbol("plasmic.state.proxy");
|
|
1513
1519
|
|
|
1514
|
-
function generateStateOnChangeProp($state,
|
|
1515
|
-
return function (val
|
|
1516
|
-
return set($state,
|
|
1520
|
+
function generateStateOnChangeProp($state, path) {
|
|
1521
|
+
return function (val) {
|
|
1522
|
+
return set($state, path, val);
|
|
1517
1523
|
};
|
|
1518
1524
|
}
|
|
1519
|
-
|
|
1520
|
-
* This function generate the state value prop for repeated states
|
|
1521
|
-
* Example:
|
|
1522
|
-
* - parent[][].counter[].count
|
|
1523
|
-
* We need to pass `parent[index1][index2].counter to the child component
|
|
1524
|
-
*/
|
|
1525
|
-
function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
|
|
1526
|
-
) {
|
|
1525
|
+
function generateStateValueProp($state, path) {
|
|
1527
1526
|
return _get($state, path);
|
|
1528
1527
|
}
|
|
1529
1528
|
var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
|
|
@@ -1541,6 +1540,14 @@ function shallowEqual(a1, a2) {
|
|
|
1541
1540
|
}
|
|
1542
1541
|
return true;
|
|
1543
1542
|
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Shallow comparison of arrays.
|
|
1545
|
+
*/
|
|
1546
|
+
function arrayEq(xs, ys) {
|
|
1547
|
+
return xs.length === ys.length && xs.every(function (_, index) {
|
|
1548
|
+
return xs[index] === ys[index];
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1544
1551
|
function isNum(value) {
|
|
1545
1552
|
return typeof value === "symbol" ? false : !isNaN(+value);
|
|
1546
1553
|
}
|
|
@@ -1603,69 +1610,84 @@ function assignValue(object, key, value) {
|
|
|
1603
1610
|
var UNINITIALIZED = /*#__PURE__*/Symbol("plasmic.unitialized");
|
|
1604
1611
|
var StateSpecNode = /*#__PURE__*/function () {
|
|
1605
1612
|
function StateSpecNode(specs) {
|
|
1606
|
-
this.
|
|
1607
|
-
this.
|
|
1608
|
-
this.
|
|
1613
|
+
this._specs = specs;
|
|
1614
|
+
this._edges = new Map();
|
|
1615
|
+
this._state = {};
|
|
1609
1616
|
}
|
|
1610
1617
|
var _proto = StateSpecNode.prototype;
|
|
1618
|
+
_proto.setSpecs = function setSpecs(specs) {
|
|
1619
|
+
this._specs = specs;
|
|
1620
|
+
};
|
|
1621
|
+
_proto.edges = function edges() {
|
|
1622
|
+
return this._edges;
|
|
1623
|
+
};
|
|
1624
|
+
_proto.state = function state() {
|
|
1625
|
+
return this._state;
|
|
1626
|
+
};
|
|
1611
1627
|
_proto.hasEdge = function hasEdge(key) {
|
|
1612
|
-
return this.
|
|
1628
|
+
return this._edges.has(key);
|
|
1613
1629
|
};
|
|
1614
1630
|
_proto.addEdge = function addEdge(key, node) {
|
|
1615
|
-
this.
|
|
1631
|
+
this._edges.set(key, node);
|
|
1632
|
+
};
|
|
1633
|
+
_proto.clearEdges = function clearEdges() {
|
|
1634
|
+
this._edges = new Map();
|
|
1616
1635
|
};
|
|
1617
1636
|
_proto.children = function children() {
|
|
1618
|
-
return this.
|
|
1637
|
+
return this._edges.values();
|
|
1619
1638
|
};
|
|
1620
1639
|
_proto.makeTransition = function makeTransition(key) {
|
|
1621
1640
|
key = isNum(key) ? ARRAY_SYMBOL : key;
|
|
1622
|
-
return this.
|
|
1641
|
+
return this._edges.get(key);
|
|
1623
1642
|
};
|
|
1624
1643
|
_proto.isLeaf = function isLeaf() {
|
|
1625
|
-
return this.
|
|
1644
|
+
return this._edges.size === 0;
|
|
1626
1645
|
};
|
|
1627
1646
|
_proto.hasArrayTransition = function hasArrayTransition() {
|
|
1628
|
-
return this.
|
|
1647
|
+
return this._edges.has(ARRAY_SYMBOL);
|
|
1629
1648
|
};
|
|
1630
1649
|
_proto.getSpec = function getSpec() {
|
|
1631
|
-
return this.
|
|
1650
|
+
return this._specs[0];
|
|
1632
1651
|
};
|
|
1633
1652
|
_proto.getAllSpecs = function getAllSpecs() {
|
|
1634
|
-
return this.
|
|
1653
|
+
return this._specs;
|
|
1635
1654
|
};
|
|
1636
1655
|
_proto.getState = function getState(path) {
|
|
1637
|
-
return this.
|
|
1656
|
+
return this._state[JSON.stringify(path)];
|
|
1657
|
+
};
|
|
1658
|
+
_proto.getInitFunc = function getInitFunc(stateCell) {
|
|
1659
|
+
var _stateCell$registered;
|
|
1660
|
+
return (_stateCell$registered = stateCell.registeredInitFunc) != null ? _stateCell$registered : this.getSpec().initFunc;
|
|
1638
1661
|
};
|
|
1639
1662
|
_proto.clearStates = function clearStates() {
|
|
1640
|
-
this.
|
|
1663
|
+
this._state = {};
|
|
1641
1664
|
};
|
|
1642
1665
|
_proto.states = function states() {
|
|
1643
|
-
return Object.values(this.
|
|
1666
|
+
return Object.values(this._state);
|
|
1644
1667
|
};
|
|
1645
1668
|
_proto.hasState = function hasState(path) {
|
|
1646
1669
|
var key = JSON.stringify(path);
|
|
1647
|
-
return key in this.
|
|
1670
|
+
return key in this._state;
|
|
1648
1671
|
};
|
|
1649
1672
|
_proto.createStateCell = function createStateCell(path) {
|
|
1650
1673
|
var key = JSON.stringify(path);
|
|
1651
|
-
this.
|
|
1674
|
+
this._state[key] = {
|
|
1652
1675
|
listeners: [],
|
|
1653
1676
|
initialValue: UNINITIALIZED,
|
|
1654
|
-
registeredInitFunc: this.getSpec().initFunc,
|
|
1655
1677
|
path: path
|
|
1656
1678
|
};
|
|
1657
1679
|
};
|
|
1658
1680
|
_proto.setInitialValue = function setInitialValue(path, value) {
|
|
1659
1681
|
var key = JSON.stringify(path);
|
|
1660
|
-
this.
|
|
1682
|
+
this._state[key].initialValue = value;
|
|
1661
1683
|
};
|
|
1662
1684
|
_proto.getInitialValue = function getInitialValue(path) {
|
|
1663
1685
|
var key = JSON.stringify(path);
|
|
1664
|
-
return this.
|
|
1686
|
+
return this._state[key].initialValue;
|
|
1665
1687
|
};
|
|
1666
1688
|
_proto.addListener = function addListener(path, f) {
|
|
1667
1689
|
var key = JSON.stringify(path);
|
|
1668
|
-
this.
|
|
1690
|
+
this._state[key].listeners.push(f);
|
|
1669
1691
|
};
|
|
1670
1692
|
return StateSpecNode;
|
|
1671
1693
|
}();
|
|
@@ -1700,14 +1722,43 @@ function buildTree(specs) {
|
|
|
1700
1722
|
};
|
|
1701
1723
|
return rec([]);
|
|
1702
1724
|
}
|
|
1703
|
-
function
|
|
1725
|
+
function updateTree(root, specs) {
|
|
1726
|
+
var internalSpec = specs.map(function (spec) {
|
|
1727
|
+
return _extends({}, spec, {
|
|
1728
|
+
pathObj: transformPathStringToObj(spec.path),
|
|
1729
|
+
isRepeated: spec.path.split(".").some(function (part) {
|
|
1730
|
+
return part.endsWith("[]");
|
|
1731
|
+
})
|
|
1732
|
+
});
|
|
1733
|
+
});
|
|
1734
|
+
var rec = function rec(oldNode, currentPath) {
|
|
1735
|
+
var nodeSpecs = internalSpec.filter(function (spec) {
|
|
1736
|
+
return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
|
|
1737
|
+
});
|
|
1738
|
+
var node = oldNode != null ? oldNode : new StateSpecNode(nodeSpecs);
|
|
1739
|
+
node.setSpecs(nodeSpecs);
|
|
1740
|
+
var oldEdges = oldNode == null ? void 0 : oldNode.edges();
|
|
1741
|
+
node.clearEdges();
|
|
1742
|
+
node.getAllSpecs().forEach(function (spec) {
|
|
1743
|
+
if (spec.pathObj.length > currentPath.length) {
|
|
1744
|
+
var nextKey = spec.pathObj[currentPath.length];
|
|
1745
|
+
if (!node.hasEdge(nextKey)) {
|
|
1746
|
+
node.addEdge(nextKey, rec(oldEdges == null ? void 0 : oldEdges.get(nextKey), [].concat(currentPath, [nextKey])));
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
return node;
|
|
1751
|
+
};
|
|
1752
|
+
return rec(root, []);
|
|
1753
|
+
}
|
|
1754
|
+
function getStateCells(root) {
|
|
1704
1755
|
var leaves = [];
|
|
1705
1756
|
var rec = function rec(node) {
|
|
1706
1757
|
for (var _iterator = _createForOfIteratorHelperLoose(node.children()), _step; !(_step = _iterator()).done;) {
|
|
1707
1758
|
var child = _step.value;
|
|
1708
1759
|
rec(child);
|
|
1709
1760
|
}
|
|
1710
|
-
if (node.isLeaf()) {
|
|
1761
|
+
if (node.isLeaf() && node.getAllSpecs().length > 0) {
|
|
1711
1762
|
leaves.push(node);
|
|
1712
1763
|
}
|
|
1713
1764
|
};
|
|
@@ -1722,7 +1773,6 @@ function findStateCell(root, pathStr, repetitionIndex) {
|
|
|
1722
1773
|
var part = _step2.value;
|
|
1723
1774
|
if (typeof part === "symbol") {
|
|
1724
1775
|
if (!root.hasArrayTransition() || !repetitionIndex || currRepIndex > repetitionIndex.length) {
|
|
1725
|
-
console.log(root);
|
|
1726
1776
|
throw new Error("transition not found: pathStr " + pathStr + " part " + (typeof part === "symbol" ? "[]" : part));
|
|
1727
1777
|
}
|
|
1728
1778
|
realPath.push(repetitionIndex[currRepIndex++]);
|
|
@@ -1777,7 +1827,7 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1777
1827
|
set(proxyRoot, initialStatePath, newValue);
|
|
1778
1828
|
});
|
|
1779
1829
|
});
|
|
1780
|
-
var initialValue = initialSpecNode.getState(initialStatePath)
|
|
1830
|
+
var initialValue = initialSpecNode.getInitFunc(initialSpecNode.getState(initialStatePath))($$state.props, $state, $$state.ctx);
|
|
1781
1831
|
initialSpecNode.setInitialValue(initialStatePath, clone(initialValue));
|
|
1782
1832
|
var initialSpec = initialSpecNode.getSpec();
|
|
1783
1833
|
var value = initialSpec.isImmutable ? mkUntrackedValue(initialValue) : clone(initialValue);
|
|
@@ -1790,7 +1840,8 @@ function initializeStateValue($$state, initialSpecNode, initialStatePath, proxyR
|
|
|
1790
1840
|
return initialValue;
|
|
1791
1841
|
}
|
|
1792
1842
|
function create$StateProxy($$state, leafHandlers) {
|
|
1793
|
-
var
|
|
1843
|
+
var proxyRoot;
|
|
1844
|
+
var rec = function rec(currPath, currNode, isOutside, initialObject) {
|
|
1794
1845
|
var getNextPath = function getNextPath(property) {
|
|
1795
1846
|
return [].concat(currPath, [isNum$1(property) ? +property : property]);
|
|
1796
1847
|
};
|
|
@@ -1806,7 +1857,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1806
1857
|
//we are always in a leaf, since we only have two cases:
|
|
1807
1858
|
// 1 - delete properties outside the state tree
|
|
1808
1859
|
// 2 - delete indices in repeated implicit states, but these can't be exposed, so they don't have onChangeProp
|
|
1809
|
-
(_$$state$props$spec$o = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o.call(_$$state$props2, _get(
|
|
1860
|
+
(_$$state$props$spec$o = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o.call(_$$state$props2, _get(proxyRoot, currPath.slice(spec.pathObj.length)));
|
|
1810
1861
|
}
|
|
1811
1862
|
return Reflect.deleteProperty(target, property);
|
|
1812
1863
|
},
|
|
@@ -1814,7 +1865,6 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1814
1865
|
if (property === PLASMIC_STATE_PROXY_SYMBOL) {
|
|
1815
1866
|
return true;
|
|
1816
1867
|
}
|
|
1817
|
-
proxyRoot = proxyRoot == null ? receiver : proxyRoot;
|
|
1818
1868
|
var nextPath = getNextPath(property);
|
|
1819
1869
|
if (isOutside || currNode.isLeaf()) {
|
|
1820
1870
|
return Reflect.get(target, property, receiver);
|
|
@@ -1822,15 +1872,14 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1822
1872
|
var nextNode = currNode.makeTransition(property);
|
|
1823
1873
|
if (nextNode != null && nextNode.isLeaf()) {
|
|
1824
1874
|
var _leafHandlers$get, _leafHandlers;
|
|
1825
|
-
return (_leafHandlers$get = (_leafHandlers = leafHandlers(nextNode, nextPath
|
|
1875
|
+
return (_leafHandlers$get = (_leafHandlers = leafHandlers(nextNode, nextPath)).get) == null ? void 0 : _leafHandlers$get.call(_leafHandlers, target, property, receiver);
|
|
1826
1876
|
} else if (nextNode && !(property in target)) {
|
|
1827
|
-
target[property] = rec(nextPath, nextNode, false,
|
|
1877
|
+
target[property] = rec(nextPath, nextNode, false, undefined);
|
|
1828
1878
|
}
|
|
1829
1879
|
return Reflect.get(target, property, receiver);
|
|
1830
1880
|
},
|
|
1831
1881
|
set: function set$1(target, property, value, receiver) {
|
|
1832
1882
|
var _nextNode, _nextNode2;
|
|
1833
|
-
proxyRoot = proxyRoot == null ? receiver : proxyRoot;
|
|
1834
1883
|
var nextPath = getNextPath(property);
|
|
1835
1884
|
var nextNode = currNode.makeTransition(property);
|
|
1836
1885
|
if (property === "registerInitFunc" && currPath.length === 0) {
|
|
@@ -1843,7 +1892,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1843
1892
|
}
|
|
1844
1893
|
if ((_nextNode = nextNode) != null && _nextNode.isLeaf()) {
|
|
1845
1894
|
var _leafHandlers$set, _leafHandlers2;
|
|
1846
|
-
(_leafHandlers$set = (_leafHandlers2 = leafHandlers(nextNode, nextPath
|
|
1895
|
+
(_leafHandlers$set = (_leafHandlers2 = leafHandlers(nextNode, nextPath)).set) == null ? void 0 : _leafHandlers$set.call(_leafHandlers2, target, property, value, receiver);
|
|
1847
1896
|
}
|
|
1848
1897
|
if (!isOutside && !currNode.isLeaf() && !nextNode) {
|
|
1849
1898
|
// can't set an unknown field in $state
|
|
@@ -1855,7 +1904,7 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1855
1904
|
nextNode = currNode;
|
|
1856
1905
|
}
|
|
1857
1906
|
if (canProxy(value)) {
|
|
1858
|
-
target[property] = rec(nextPath, nextNode, isOutside || currNode.isLeaf(),
|
|
1907
|
+
target[property] = rec(nextPath, nextNode, isOutside || currNode.isLeaf(), value);
|
|
1859
1908
|
} else if (!isOutside && !currNode.isLeaf() && !((_nextNode2 = nextNode) != null && _nextNode2.isLeaf())) {
|
|
1860
1909
|
throw new Error("inserting a primitive value into a non-leaf");
|
|
1861
1910
|
} else {
|
|
@@ -1872,8 +1921,11 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1872
1921
|
return true;
|
|
1873
1922
|
}
|
|
1874
1923
|
};
|
|
1875
|
-
var baseObject = !isOutside && !currNode.isLeaf() ? currNode.hasArrayTransition() ? [] : {} : Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject));
|
|
1924
|
+
var baseObject = !isOutside && !currNode.isLeaf() ? currNode.hasArrayTransition() ? [] : {} : Array.isArray(initialObject) ? [] : Object.create(Object.getPrototypeOf(initialObject != null ? initialObject : {}));
|
|
1876
1925
|
var proxyObj = new Proxy(baseObject, handlers);
|
|
1926
|
+
if (currPath.length === 0) {
|
|
1927
|
+
proxyRoot = proxyObj;
|
|
1928
|
+
}
|
|
1877
1929
|
if (initialObject) {
|
|
1878
1930
|
Reflect.ownKeys(initialObject).forEach(function (key) {
|
|
1879
1931
|
var desc = Object.getOwnPropertyDescriptor(initialObject, key);
|
|
@@ -1886,34 +1938,36 @@ function create$StateProxy($$state, leafHandlers) {
|
|
|
1886
1938
|
}
|
|
1887
1939
|
return proxyObj;
|
|
1888
1940
|
};
|
|
1889
|
-
return rec([], $$state.rootSpecTree, false, undefined
|
|
1941
|
+
return rec([], $$state.rootSpecTree, false, undefined);
|
|
1890
1942
|
}
|
|
1891
1943
|
var mkUntrackedValue = function mkUntrackedValue(o) {
|
|
1892
1944
|
return o != null && typeof o === "object" ? valtio.ref(o) : o;
|
|
1893
1945
|
};
|
|
1894
|
-
function useDollarState(specs, props, $ctx) {
|
|
1946
|
+
function useDollarState(specs, props, $ctx, opts) {
|
|
1895
1947
|
var $$state = React__default.useRef(function () {
|
|
1896
1948
|
var rootSpecTree = buildTree(specs);
|
|
1897
1949
|
return {
|
|
1898
1950
|
rootSpecTree: rootSpecTree,
|
|
1899
|
-
specTreeLeaves:
|
|
1951
|
+
specTreeLeaves: getStateCells(rootSpecTree),
|
|
1900
1952
|
stateValues: valtio.proxy({}),
|
|
1901
1953
|
props: {},
|
|
1902
1954
|
ctx: {},
|
|
1903
|
-
|
|
1955
|
+
specs: [],
|
|
1956
|
+
registrationsQueue: valtio.proxy([])
|
|
1904
1957
|
};
|
|
1905
1958
|
}()).current;
|
|
1906
1959
|
$$state.props = props;
|
|
1907
1960
|
$$state.ctx = $ctx != null ? $ctx : {};
|
|
1908
|
-
|
|
1909
|
-
|
|
1961
|
+
$$state.specs = specs;
|
|
1962
|
+
var create$State = function create$State() {
|
|
1963
|
+
var $state = Object.assign(create$StateProxy($$state, function (node, path) {
|
|
1910
1964
|
if (!node.hasState(path)) {
|
|
1911
1965
|
node.createStateCell(path);
|
|
1912
1966
|
var spec = node.getSpec();
|
|
1913
1967
|
if (spec.initFunc) {
|
|
1914
|
-
initializeStateValue($$state, node, path,
|
|
1968
|
+
initializeStateValue($$state, node, path, $state);
|
|
1915
1969
|
} else if (!spec.valueProp) {
|
|
1916
|
-
set(
|
|
1970
|
+
set($state, path, spec.initVal);
|
|
1917
1971
|
}
|
|
1918
1972
|
}
|
|
1919
1973
|
return {
|
|
@@ -1934,17 +1988,40 @@ function useDollarState(specs, props, $ctx) {
|
|
|
1934
1988
|
if (!node.hasState(realPath)) {
|
|
1935
1989
|
node.createStateCell(realPath);
|
|
1936
1990
|
}
|
|
1937
|
-
if (!deepEqual(node.getState(realPath).initialValue, f($$state.props,
|
|
1938
|
-
$$state.registrationsQueue.push({
|
|
1991
|
+
if (!deepEqual(node.getState(realPath).initialValue, f($$state.props, $state, $$state.ctx))) {
|
|
1992
|
+
$$state.registrationsQueue.push(mkUntrackedValue({
|
|
1939
1993
|
node: node,
|
|
1940
1994
|
path: realPath,
|
|
1941
1995
|
f: f
|
|
1942
|
-
});
|
|
1996
|
+
}));
|
|
1943
1997
|
}
|
|
1944
1998
|
}
|
|
1945
1999
|
});
|
|
1946
|
-
return
|
|
1947
|
-
}
|
|
2000
|
+
return $state;
|
|
2001
|
+
};
|
|
2002
|
+
var ref = React__default.useRef(undefined);
|
|
2003
|
+
if (!ref.current) {
|
|
2004
|
+
ref.current = create$State();
|
|
2005
|
+
}
|
|
2006
|
+
var $state = ref.current;
|
|
2007
|
+
if (opts != null && opts.inCanvas) {
|
|
2008
|
+
$$state.rootSpecTree = updateTree($$state.rootSpecTree, specs);
|
|
2009
|
+
var newLeaves = getStateCells($$state.rootSpecTree);
|
|
2010
|
+
if (!arrayEq(newLeaves, $$state.specTreeLeaves)) {
|
|
2011
|
+
$state = ref.current = create$State();
|
|
2012
|
+
$$state.specTreeLeaves = newLeaves;
|
|
2013
|
+
}
|
|
2014
|
+
// we need to eager initialize all states in canvas to populate the data picker
|
|
2015
|
+
$$state.specTreeLeaves.forEach(function (node) {
|
|
2016
|
+
var spec = node.getSpec();
|
|
2017
|
+
if (spec.isRepeated || node.hasState(spec.pathObj)) {
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
2020
|
+
node.createStateCell(spec.pathObj);
|
|
2021
|
+
var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initFunc ? initializeStateValue($$state, node, spec.pathObj, $state) : spec.initVal;
|
|
2022
|
+
set($state, spec.pathObj, init);
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
1948
2025
|
// For each spec with an initFunc, evaluate it and see if
|
|
1949
2026
|
// the init value has changed. If so, reset its state.
|
|
1950
2027
|
var resetSpecs = [];
|
|
@@ -1956,10 +2033,11 @@ function useDollarState(specs, props, $ctx) {
|
|
|
1956
2033
|
};
|
|
1957
2034
|
});
|
|
1958
2035
|
}).forEach(function (_ref2) {
|
|
1959
|
-
var
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2036
|
+
var node = _ref2.node,
|
|
2037
|
+
stateCell = _ref2.stateCell;
|
|
2038
|
+
var initFunc = node.getInitFunc(stateCell);
|
|
2039
|
+
if (initFunc) {
|
|
2040
|
+
var newInit = initFunc(props, $state, $ctx != null ? $ctx : {});
|
|
1963
2041
|
if (!deepEqual(newInit, stateCell.initialValue)) {
|
|
1964
2042
|
resetSpecs.push({
|
|
1965
2043
|
stateCell: stateCell,
|
|
@@ -1984,16 +2062,16 @@ function useDollarState(specs, props, $ctx) {
|
|
|
1984
2062
|
});
|
|
1985
2063
|
}, [props, resetSpecs]);
|
|
1986
2064
|
useIsomorphicLayoutEffect$1(function () {
|
|
1987
|
-
$$state.registrationsQueue.
|
|
1988
|
-
var
|
|
1989
|
-
|
|
1990
|
-
|
|
2065
|
+
while ($$state.registrationsQueue.length) {
|
|
2066
|
+
var _$$state$registration = $$state.registrationsQueue.shift(),
|
|
2067
|
+
node = _$$state$registration.node,
|
|
2068
|
+
path = _$$state$registration.path,
|
|
2069
|
+
f = _$$state$registration.f;
|
|
1991
2070
|
var stateCell = node.getState(path);
|
|
1992
2071
|
stateCell.registeredInitFunc = f;
|
|
1993
2072
|
reInitializeState(node, stateCell);
|
|
1994
|
-
}
|
|
1995
|
-
|
|
1996
|
-
}, [$$state.registrationsQueue]);
|
|
2073
|
+
}
|
|
2074
|
+
}, [$$state.registrationsQueue.length]);
|
|
1997
2075
|
// immediately initialize exposed non-private states
|
|
1998
2076
|
useIsomorphicLayoutEffect$1(function () {
|
|
1999
2077
|
$$state.specTreeLeaves.forEach(function (node) {
|
|
@@ -2008,6 +2086,7 @@ function useDollarState(specs, props, $ctx) {
|
|
|
2008
2086
|
valtio.useSnapshot($$state.stateValues, {
|
|
2009
2087
|
sync: true
|
|
2010
2088
|
});
|
|
2089
|
+
valtio.useSnapshot($$state.registrationsQueue);
|
|
2011
2090
|
return $state;
|
|
2012
2091
|
}
|
|
2013
2092
|
|