@plasmicapp/react-web 0.2.134 → 0.2.136

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.
@@ -1735,20 +1735,105 @@ function set(obj, keys, val) {
1735
1735
  }
1736
1736
  }
1737
1737
  var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
1738
+ function shallowEqual(a1, a2) {
1739
+ if (a1.length !== a2.length) {
1740
+ return false;
1741
+ }
1738
1742
 
1739
- var mkUntrackedValue = function mkUntrackedValue(o) {
1740
- return o != null && typeof o === "object" ? ref(o) : o;
1741
- };
1743
+ for (var i = 0; i < a1.length; i++) {
1744
+ if (a1[i] !== a2[i]) {
1745
+ return false;
1746
+ }
1747
+ }
1748
+
1749
+ return true;
1750
+ }
1751
+ function isNum(value) {
1752
+ return typeof value === "symbol" ? false : !isNaN(+value);
1753
+ }
1754
+
1755
+ var ARRAY_SYMBOL = /*#__PURE__*/Symbol("[]");
1756
+
1757
+ var StateSpecNode = /*#__PURE__*/function () {
1758
+ function StateSpecNode(specs) {
1759
+ this.specs = specs;
1760
+ this.edges = new Map();
1761
+ }
1742
1762
 
1763
+ var _proto = StateSpecNode.prototype;
1764
+
1765
+ _proto.hasEdge = function hasEdge(key) {
1766
+ return this.edges.has(key);
1767
+ };
1768
+
1769
+ _proto.addEdge = function addEdge(key, node) {
1770
+ this.edges.set(key, node);
1771
+ };
1772
+
1773
+ _proto.makeTransition = function makeTransition(key) {
1774
+ key = isNum(key) ? ARRAY_SYMBOL : key;
1775
+ return this.edges.get(key);
1776
+ };
1777
+
1778
+ _proto.isLeaf = function isLeaf() {
1779
+ return this.edges.size === 0;
1780
+ };
1781
+
1782
+ _proto.hasArrayTransition = function hasArrayTransition() {
1783
+ return this.edges.has(ARRAY_SYMBOL);
1784
+ };
1785
+
1786
+ _proto.getSpec = function getSpec() {
1787
+ return this.specs[0];
1788
+ };
1789
+
1790
+ _proto.getAllSpecs = function getAllSpecs() {
1791
+ return this.specs;
1792
+ };
1793
+
1794
+ return StateSpecNode;
1795
+ }();
1743
1796
  var transformPathStringToObj = function transformPathStringToObj(str) {
1744
1797
  var splitStatePathPart = function splitStatePathPart(state) {
1745
- return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
1798
+ return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), [ARRAY_SYMBOL]) : [state];
1746
1799
  };
1747
1800
 
1748
1801
  return str.split(".").flatMap(splitStatePathPart);
1749
1802
  };
1803
+ function buildGraph(specs) {
1804
+ var internalSpec = specs.map(function (spec) {
1805
+ return _extends({}, spec, {
1806
+ pathObj: transformPathStringToObj(spec.path),
1807
+ isRepeated: spec.path.split(".").some(function (part) {
1808
+ return part.endsWith("[]");
1809
+ })
1810
+ });
1811
+ });
1750
1812
 
1751
- function shallowEqual(a1, a2) {
1813
+ var rec = function rec(currentPath) {
1814
+ var node = new StateSpecNode(internalSpec.filter(function (spec) {
1815
+ return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
1816
+ }));
1817
+ node.getAllSpecs().forEach(function (spec) {
1818
+ if (spec.pathObj.length > currentPath.length) {
1819
+ var nextKey = spec.pathObj[currentPath.length];
1820
+
1821
+ if (!node.hasEdge(nextKey)) {
1822
+ node.addEdge(nextKey, rec([].concat(currentPath, [nextKey])));
1823
+ }
1824
+ }
1825
+ });
1826
+ return node;
1827
+ };
1828
+
1829
+ return rec([]);
1830
+ }
1831
+
1832
+ var mkUntrackedValue = function mkUntrackedValue(o) {
1833
+ return o != null && typeof o === "object" ? ref(o) : o;
1834
+ };
1835
+
1836
+ function shallowEqual$1(a1, a2) {
1752
1837
  if (a1.length !== a2.length) {
1753
1838
  return false;
1754
1839
  }
@@ -1762,7 +1847,7 @@ function shallowEqual(a1, a2) {
1762
1847
  return true;
1763
1848
  }
1764
1849
 
1765
- function isNum(value) {
1850
+ function isNum$1(value) {
1766
1851
  return typeof value === "symbol" ? false : !isNaN(+value);
1767
1852
  }
1768
1853
 
@@ -1784,37 +1869,12 @@ function saveNewState($$state, path, spec) {
1784
1869
  }
1785
1870
 
1786
1871
  function create$StateProxy($$state, handlers) {
1787
- var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
1788
- return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
1789
- return shallowEqual(currPath.map(function (p) {
1790
- return isNum(p) ? "[]" : p;
1791
- }), spec.pathObj.slice(0, currPath.length));
1792
- }).reduce(function (agg, spec) {
1793
- var nextKey = spec.pathObj[currPath.length];
1794
-
1795
- if (!(nextKey in agg)) {
1796
- agg[nextKey] = [];
1797
- }
1798
-
1799
- agg[nextKey].push(spec);
1800
- return agg;
1801
- }, {})));
1802
- };
1803
-
1804
- var rec = function rec(currPath) {
1805
- var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
1806
-
1807
- var getSpecForProperty = function getSpecForProperty(property) {
1808
- var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
1809
-
1810
- return nextKeyToSpecs.has("[]") && isNum(property) ? (_nextKeyToSpecs$get = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get[0] : typeof property === "string" && nextKeyToSpecs.has(property) ? (_nextKeyToSpecs$get2 = nextKeyToSpecs.get(property)) == null ? void 0 : _nextKeyToSpecs$get2[0] : undefined;
1811
- };
1812
-
1872
+ var rec = function rec(currPath, currNode) {
1813
1873
  var getNextPath = function getNextPath(property) {
1814
- return [].concat(currPath, [isNum(property) ? +property : property]);
1874
+ return [].concat(currPath, [isNum$1(property) ? +property : property]);
1815
1875
  };
1816
1876
 
1817
- return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
1877
+ return new Proxy(currNode.hasArrayTransition() ? [] : {}, {
1818
1878
  deleteProperty: function deleteProperty(target, property) {
1819
1879
  var prefixPath = getNextPath(property);
1820
1880
  var specKeysToUpdate = new Set();
@@ -1822,7 +1882,7 @@ function create$StateProxy($$state, handlers) {
1822
1882
  var path = _ref.path,
1823
1883
  specKey = _ref.specKey;
1824
1884
 
1825
- if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
1885
+ if (path.length >= prefixPath.length && shallowEqual$1(path.slice(0, prefixPath.length), prefixPath)) {
1826
1886
  deleteState($$state, path);
1827
1887
  specKeysToUpdate.add(specKey);
1828
1888
  }
@@ -1839,36 +1899,34 @@ function create$StateProxy($$state, handlers) {
1839
1899
  return Reflect.deleteProperty(target, property);
1840
1900
  },
1841
1901
  get: function get(target, property, receiver) {
1842
- var spec = getSpecForProperty(property);
1843
-
1844
- if (spec && typeof property !== "symbol") {
1845
- var nextPath = getNextPath(property);
1902
+ var nextPath = getNextPath(property);
1903
+ var nextNode = currNode.makeTransition(property);
1846
1904
 
1847
- if (spec.pathObj.length === currPath.length + 1) {
1905
+ if (nextNode) {
1906
+ if (nextNode.isLeaf()) {
1848
1907
  var _handlers$get, _handlers;
1849
1908
 
1850
- // reached the end of the spec
1851
- target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
1909
+ target[property] = (_handlers$get = (_handlers = handlers(nextPath, nextNode.getSpec())).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
1852
1910
  } else if (!(property in target)) {
1853
- target[property] = rec(nextPath);
1911
+ target[property] = rec(nextPath, nextNode);
1854
1912
  }
1855
1913
  }
1856
1914
 
1857
1915
  return Reflect.get(target, property, receiver);
1858
1916
  },
1859
1917
  set: function set$1(target, property, value, receiver) {
1860
- var spec = getSpecForProperty(property);
1861
1918
  var nextPath = getNextPath(property);
1919
+ var nextNode = currNode.makeTransition(property);
1862
1920
 
1863
- if (spec && typeof property !== "symbol") {
1864
- if (spec.pathObj.length === currPath.length + 1) {
1921
+ if (nextNode && typeof property !== "symbol") {
1922
+ if (nextNode.isLeaf()) {
1865
1923
  var _handlers$set, _handlers2;
1866
1924
 
1867
1925
  // reached the end of the spec
1868
- target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
1926
+ target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, nextNode.getSpec())).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
1869
1927
  return Reflect.set(target, property, value, receiver);
1870
1928
  } else if (typeof value === "object") {
1871
- target[property] = rec(nextPath);
1929
+ target[property] = rec(nextPath, nextNode);
1872
1930
 
1873
1931
  for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
1874
1932
  var key = _Object$keys[_i];
@@ -1883,13 +1941,13 @@ function create$StateProxy($$state, handlers) {
1883
1941
  return Reflect.set(target, property, value, receiver);
1884
1942
  }
1885
1943
 
1886
- if (nextKeyToSpecs.has("[]")) {
1887
- var _nextKeyToSpecs$get3;
1944
+ if (currNode.hasArrayTransition()) {
1945
+ var _currNode$makeTransit, _currNode$makeTransit2;
1888
1946
 
1889
1947
  set($$state.stateValues, nextPath, value);
1890
1948
 
1891
- (_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
1892
- if (spec != null && spec.onChangeProp) {
1949
+ (_currNode$makeTransit = currNode.makeTransition(ARRAY_SYMBOL)) == null ? void 0 : (_currNode$makeTransit2 = _currNode$makeTransit.getAllSpecs()) == null ? void 0 : _currNode$makeTransit2.forEach(function (spec) {
1950
+ if (spec.onChangeProp) {
1893
1951
  var _$$state$props$spec$o2, _$$state$props2;
1894
1952
 
1895
1953
  (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
@@ -1904,7 +1962,7 @@ function create$StateProxy($$state, handlers) {
1904
1962
  });
1905
1963
  };
1906
1964
 
1907
- return rec([]);
1965
+ return rec([], $$state.rootStateSpec);
1908
1966
  }
1909
1967
 
1910
1968
  var deleteState = function deleteState($$state, path) {
@@ -2023,7 +2081,8 @@ function useDollarState(specs, props, $ctx) {
2023
2081
  unsubscriptionsByState: {},
2024
2082
  props: {},
2025
2083
  ctx: {},
2026
- registrationsQueue: []
2084
+ registrationsQueue: [],
2085
+ rootStateSpec: buildGraph(specs)
2027
2086
  })).current;
2028
2087
  $$state.props = mkUntrackedValue(props);
2029
2088
  $$state.ctx = mkUntrackedValue($ctx != null ? $ctx : {});
@@ -2142,28 +2201,12 @@ function useCanvasDollarState(specs, props, $ctx) {
2142
2201
  unsubscriptionsByState: {},
2143
2202
  props: {},
2144
2203
  ctx: {},
2145
- registrationsQueue: []
2204
+ registrationsQueue: [],
2205
+ rootStateSpec: buildGraph(specs)
2146
2206
  });
2147
2207
  $$state.props = mkUntrackedValue(props);
2148
2208
  $$state.ctx = mkUntrackedValue($ctx);
2149
- var $state = create$StateProxy($$state, function (path, spec) {
2150
- return {
2151
- get: function get() {
2152
- return _get($$state.stateValues, path);
2153
- },
2154
- set: function set(_t, _p, value) {
2155
- saveValue($$state, path, spec, value);
2156
-
2157
- if (spec.onChangeProp) {
2158
- var _$$state$props$spec$o5, _$$state$props5;
2159
-
2160
- (_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
2161
- }
2162
-
2163
- return true;
2164
- }
2165
- };
2166
- });
2209
+ var $state = {};
2167
2210
 
2168
2211
  for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
2169
2212
  var spec = _step.value;
@@ -3728,5 +3771,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
3728
3771
  };
3729
3772
  }
3730
3773
 
3731
- export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, Stack, Trans, TriggeredOverlayContext, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, getDataProps, hasVariant, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, useButton, useCanvasDollarState, useCheckbox, useDollarState, useIsSSR, useIsomorphicLayoutEffect$1 as useIsomorphicLayoutEffect, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
3774
+ export { DropdownMenu, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, 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 };
3732
3775
  //# sourceMappingURL=react-web.esm.js.map