@plasmicapp/react-web 0.2.133 → 0.2.135

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.
@@ -8,6 +8,7 @@ import { PlasmicDataSourceContextProvider } from '@plasmicapp/data-sources-conte
8
8
  export { PlasmicDataSourceContextProvider, useCurrentUser } from '@plasmicapp/data-sources-context';
9
9
  import { SSRProvider, useIsSSR as useIsSSR$1 } from '@react-aria/ssr';
10
10
  import { useFocusRing, useFocusable, FocusScope } from '@react-aria/focus';
11
+ import clone from 'clone';
11
12
  import deepEqual from 'fast-deep-equal';
12
13
  import { proxy, ref, useSnapshot } from 'valtio';
13
14
  import { subscribeKey } from 'valtio/utils';
@@ -1734,20 +1735,105 @@ function set(obj, keys, val) {
1734
1735
  }
1735
1736
  }
1736
1737
  var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? useLayoutEffect : useEffect;
1738
+ function shallowEqual(a1, a2) {
1739
+ if (a1.length !== a2.length) {
1740
+ return false;
1741
+ }
1737
1742
 
1738
- var mkUntrackedValue = function mkUntrackedValue(o) {
1739
- return o != null && typeof o === "object" ? ref(o) : o;
1740
- };
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
+ }
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
+ };
1741
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
+ }();
1742
1796
  var transformPathStringToObj = function transformPathStringToObj(str) {
1743
1797
  var splitStatePathPart = function splitStatePathPart(state) {
1744
- return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
1798
+ return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), [ARRAY_SYMBOL]) : [state];
1745
1799
  };
1746
1800
 
1747
1801
  return str.split(".").flatMap(splitStatePathPart);
1748
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
+ });
1749
1812
 
1750
- 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) {
1751
1837
  if (a1.length !== a2.length) {
1752
1838
  return false;
1753
1839
  }
@@ -1761,7 +1847,7 @@ function shallowEqual(a1, a2) {
1761
1847
  return true;
1762
1848
  }
1763
1849
 
1764
- function isNum(value) {
1850
+ function isNum$1(value) {
1765
1851
  return typeof value === "symbol" ? false : !isNaN(+value);
1766
1852
  }
1767
1853
 
@@ -1783,37 +1869,12 @@ function saveNewState($$state, path, spec) {
1783
1869
  }
1784
1870
 
1785
1871
  function create$StateProxy($$state, handlers) {
1786
- var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
1787
- return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
1788
- return shallowEqual(currPath.map(function (p) {
1789
- return isNum(p) ? "[]" : p;
1790
- }), spec.pathObj.slice(0, currPath.length));
1791
- }).reduce(function (agg, spec) {
1792
- var nextKey = spec.pathObj[currPath.length];
1793
-
1794
- if (!(nextKey in agg)) {
1795
- agg[nextKey] = [];
1796
- }
1797
-
1798
- agg[nextKey].push(spec);
1799
- return agg;
1800
- }, {})));
1801
- };
1802
-
1803
- var rec = function rec(currPath) {
1804
- var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
1805
-
1806
- var getSpecForProperty = function getSpecForProperty(property) {
1807
- var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
1808
-
1809
- 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;
1810
- };
1811
-
1872
+ var rec = function rec(currPath, currNode) {
1812
1873
  var getNextPath = function getNextPath(property) {
1813
- return [].concat(currPath, [isNum(property) ? +property : property]);
1874
+ return [].concat(currPath, [isNum$1(property) ? +property : property]);
1814
1875
  };
1815
1876
 
1816
- return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
1877
+ return new Proxy(currNode.hasArrayTransition() ? [] : {}, {
1817
1878
  deleteProperty: function deleteProperty(target, property) {
1818
1879
  var prefixPath = getNextPath(property);
1819
1880
  var specKeysToUpdate = new Set();
@@ -1821,7 +1882,7 @@ function create$StateProxy($$state, handlers) {
1821
1882
  var path = _ref.path,
1822
1883
  specKey = _ref.specKey;
1823
1884
 
1824
- 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)) {
1825
1886
  deleteState($$state, path);
1826
1887
  specKeysToUpdate.add(specKey);
1827
1888
  }
@@ -1838,36 +1899,34 @@ function create$StateProxy($$state, handlers) {
1838
1899
  return Reflect.deleteProperty(target, property);
1839
1900
  },
1840
1901
  get: function get(target, property, receiver) {
1841
- var spec = getSpecForProperty(property);
1842
-
1843
- if (spec && typeof property !== "symbol") {
1844
- var nextPath = getNextPath(property);
1902
+ var nextPath = getNextPath(property);
1903
+ var nextNode = currNode.makeTransition(property);
1845
1904
 
1846
- if (spec.pathObj.length === currPath.length + 1) {
1905
+ if (nextNode) {
1906
+ if (nextNode.isLeaf()) {
1847
1907
  var _handlers$get, _handlers;
1848
1908
 
1849
- // reached the end of the spec
1850
- 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);
1851
1910
  } else if (!(property in target)) {
1852
- target[property] = rec(nextPath);
1911
+ target[property] = rec(nextPath, nextNode);
1853
1912
  }
1854
1913
  }
1855
1914
 
1856
1915
  return Reflect.get(target, property, receiver);
1857
1916
  },
1858
1917
  set: function set$1(target, property, value, receiver) {
1859
- var spec = getSpecForProperty(property);
1860
1918
  var nextPath = getNextPath(property);
1919
+ var nextNode = currNode.makeTransition(property);
1861
1920
 
1862
- if (spec && typeof property !== "symbol") {
1863
- if (spec.pathObj.length === currPath.length + 1) {
1921
+ if (nextNode && typeof property !== "symbol") {
1922
+ if (nextNode.isLeaf()) {
1864
1923
  var _handlers$set, _handlers2;
1865
1924
 
1866
1925
  // reached the end of the spec
1867
- 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);
1868
1927
  return Reflect.set(target, property, value, receiver);
1869
1928
  } else if (typeof value === "object") {
1870
- target[property] = rec(nextPath);
1929
+ target[property] = rec(nextPath, nextNode);
1871
1930
 
1872
1931
  for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
1873
1932
  var key = _Object$keys[_i];
@@ -1882,13 +1941,13 @@ function create$StateProxy($$state, handlers) {
1882
1941
  return Reflect.set(target, property, value, receiver);
1883
1942
  }
1884
1943
 
1885
- if (nextKeyToSpecs.has("[]")) {
1886
- var _nextKeyToSpecs$get3;
1944
+ if (currNode.hasArrayTransition()) {
1945
+ var _currNode$makeTransit, _currNode$makeTransit2;
1887
1946
 
1888
1947
  set($$state.stateValues, nextPath, value);
1889
1948
 
1890
- (_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
1891
- 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) {
1892
1951
  var _$$state$props$spec$o2, _$$state$props2;
1893
1952
 
1894
1953
  (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
@@ -1903,7 +1962,7 @@ function create$StateProxy($$state, handlers) {
1903
1962
  });
1904
1963
  };
1905
1964
 
1906
- return rec([]);
1965
+ return rec([], $$state.rootStateSpec);
1907
1966
  }
1908
1967
 
1909
1968
  var deleteState = function deleteState($$state, path) {
@@ -1974,7 +2033,7 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
1974
2033
  var path = _ref2.path,
1975
2034
  spec = _ref2.spec;
1976
2035
  var unsubscribe = subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
1977
- return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(path, spec))));
2036
+ return saveValue($$state, initialStatePath, initialSpec, initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(path, spec)));
1978
2037
  });
1979
2038
  $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
1980
2039
  });
@@ -1983,27 +2042,25 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
1983
2042
  return initialValue;
1984
2043
  }
1985
2044
 
1986
- function saveStateInitialValue($$state, path, spec, initialValue) {
1987
- // array states are a special case.Wwe listen for changes in the array and in the array cells.
1988
- // for example: $state.people.push(...), $state.people.splice(...), $state.people[0] = ...
1989
- // that's why we need to track the array object
1990
- if (spec.isArray && Array.isArray(initialValue)) {
1991
- var array = initialValue.map(function (val) {
1992
- return mkUntrackedValue(val);
1993
- });
1994
-
1995
- set($$state.stateValues, path, array); // we need to make the array untracked for initStateValues
1996
- // so we can distinguish between stateValue and initStateValue.
1997
- // otherwise they would reference the same array.
1998
-
1999
-
2000
- set($$state.initStateValues, path, mkUntrackedValue(array));
2045
+ function saveValue($$state, path, spec, value) {
2046
+ if (spec.isImmutable) {
2047
+ set($$state.stateValues, path, mkUntrackedValue(value));
2001
2048
  } else {
2049
+ set($$state.stateValues, path, value);
2050
+ }
2051
+ }
2052
+
2053
+ function saveStateInitialValue($$state, path, spec, initialValue) {
2054
+ if (spec.isImmutable) {
2002
2055
  var untrackedValue = mkUntrackedValue(initialValue);
2003
2056
 
2004
2057
  set($$state.stateValues, path, untrackedValue);
2005
2058
 
2006
- set($$state.initStateValues, path, untrackedValue);
2059
+ set($$state.initStateValues, path, clone(untrackedValue));
2060
+ } else {
2061
+ set($$state.stateValues, path, clone(initialValue));
2062
+
2063
+ set($$state.initStateValues, path, clone(initialValue));
2007
2064
  }
2008
2065
  }
2009
2066
 
@@ -2024,7 +2081,8 @@ function useDollarState(specs, props, $ctx) {
2024
2081
  unsubscriptionsByState: {},
2025
2082
  props: {},
2026
2083
  ctx: {},
2027
- registrationsQueue: []
2084
+ registrationsQueue: [],
2085
+ rootStateSpec: buildGraph(specs)
2028
2086
  })).current;
2029
2087
  $$state.props = mkUntrackedValue(props);
2030
2088
  $$state.ctx = mkUntrackedValue($ctx != null ? $ctx : {});
@@ -2048,8 +2106,8 @@ function useDollarState(specs, props, $ctx) {
2048
2106
  return _get($$state.stateValues, path);
2049
2107
  }
2050
2108
  },
2051
- set: function set$1(_t, _p, value) {
2052
- set($$state.stateValues, path, mkUntrackedValue(value));
2109
+ set: function set(_t, _p, value) {
2110
+ saveValue($$state, path, spec, value);
2053
2111
 
2054
2112
  if (spec.onChangeProp) {
2055
2113
  var _$$state$props$spec$o3, _$$state$props3;
@@ -2143,28 +2201,12 @@ function useCanvasDollarState(specs, props, $ctx) {
2143
2201
  unsubscriptionsByState: {},
2144
2202
  props: {},
2145
2203
  ctx: {},
2146
- registrationsQueue: []
2204
+ registrationsQueue: [],
2205
+ rootStateSpec: buildGraph(specs)
2147
2206
  });
2148
2207
  $$state.props = mkUntrackedValue(props);
2149
2208
  $$state.ctx = mkUntrackedValue($ctx);
2150
- var $state = create$StateProxy($$state, function (path, spec) {
2151
- return {
2152
- get: function get() {
2153
- return _get($$state.stateValues, path);
2154
- },
2155
- set: function set$1(_t, _p, value) {
2156
- set($$state.stateValues, path, mkUntrackedValue(value));
2157
-
2158
- if (spec.onChangeProp) {
2159
- var _$$state$props$spec$o5, _$$state$props5;
2160
-
2161
- (_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
2162
- }
2163
-
2164
- return true;
2165
- }
2166
- };
2167
- });
2209
+ var $state = {};
2168
2210
 
2169
2211
  for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
2170
2212
  var spec = _step.value;
@@ -3729,5 +3771,5 @@ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissabl
3729
3771
  };
3730
3772
  }
3731
3773
 
3732
- 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 };
3733
3775
  //# sourceMappingURL=react-web.esm.js.map