@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.
package/dist/all.d.ts CHANGED
@@ -23,24 +23,20 @@ declare function omit<T extends {}>(obj: T, ...keys: (keyof T)[]): Partial<T>;
23
23
  declare type StrictProps<T, TExpected> = Exclude<keyof T, keyof TExpected> extends never ? {} : Partial<"Unexpected extraneous props">;
24
24
  declare type HTMLElementRefOf<T extends keyof JSX.IntrinsicElements> = Exclude<React__default.ComponentProps<T>["ref"], string>;
25
25
 
26
- declare type InitFunc$1<T> = ($props: Record<string, any>, $state: $State$1, $ctx: Record<string, any>, indexes: number[]) => T;
27
- interface $State$1 {
28
- [key: string]: any;
29
- registerInitFunc?: (path: string, f: InitFunc$1<any>) => any;
30
- }
26
+ declare type InitFunc<T> = ($props: Record<string, any>, $state: $State, $ctx: Record<string, any>, indexes?: number[]) => T;
31
27
  interface $StateSpec<T> {
32
28
  path: string;
33
- initFunc?: InitFunc$1<T>;
29
+ initFunc?: InitFunc<T>;
34
30
  initVal?: T;
35
31
  type: "private" | "readonly" | "writable";
36
32
  valueProp?: string;
37
33
  onChangeProp?: string;
38
- isArray?: boolean;
39
34
  isImmutable?: boolean;
40
35
  }
41
- declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): any;
42
-
43
- declare function useCanvasDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): any;
36
+ interface $State {
37
+ [key: string]: any;
38
+ registerInitFunc?: (path: string, f: InitFunc<any>) => any;
39
+ }
44
40
 
45
41
  interface Variants {
46
42
  [vg: string]: any;
@@ -90,7 +86,7 @@ declare function wrapWithClassName(element: React.ReactNode, className: string):
90
86
  display: "grid";
91
87
  };
92
88
  }, HTMLElement>;
93
- declare function mergeVariantsWithStates(variants: Variants, $state: $State$1, linkedStates: {
89
+ declare function mergeVariantsWithStates(variants: Variants, $state: $State, linkedStates: {
94
90
  variantGroup: string;
95
91
  statePath: (string | number)[];
96
92
  }[]): Variants;
@@ -566,9 +562,7 @@ interface Node<T> {
566
562
  // Event bubbling can be problematic in real-world applications, so the default for React Spectrum components
567
563
  // is not to propagate. This can be overridden by calling continuePropagation() on the event.
568
564
  type BaseEvent<T extends SyntheticEvent> = T & {
569
- /**
570
- * Use continuePropagation.
571
- * @deprecated */
565
+ /** @deprecated Use continuePropagation. */
572
566
  stopPropagation(): void,
573
567
  continuePropagation(): void
574
568
  }
@@ -662,12 +656,6 @@ declare function useTrigger(trigger: TriggerType, opts: TriggerOpts): [boolean,
662
656
 
663
657
  declare function dlv(object: object, key: string | Array<string | number>, defaultValue?: any): any;
664
658
 
665
- declare type InitFunc<T> = ($props: Record<string, any>, $state: $State) => T;
666
- interface $State {
667
- [key: string]: any;
668
- registerInitFunc?: (path: string, f: InitFunc<any>) => any;
669
- }
670
-
671
659
  declare function generateStateOnChangeProp($state: $State, stateName: string, dataReps: number[]): (val: any, path: (string | number)[]) => void;
672
660
  /**
673
661
  * This function generate the state value prop for repeated states
@@ -681,7 +669,13 @@ declare function generateStateValueProp($state: $State, path: (string | number)[
681
669
  * Changes: fixed setting a deep value to a proxy object
682
670
  */
683
671
  declare function set(obj: any, keys: any, val: any): void;
684
- declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
672
+ declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
673
+ declare function shallowEqual<T>(a1: T[], a2: T[]): boolean;
674
+ declare function isNum(value: string | number | symbol): value is number;
675
+
676
+ declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): any;
677
+
678
+ declare function useCanvasDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): {};
685
679
 
686
680
  declare const classNames: typeof classNames$1;
687
681
 
@@ -1641,4 +1635,4 @@ interface TriggeredOverlayContextValue {
1641
1635
  }
1642
1636
  declare const TriggeredOverlayContext: React.Context<TriggeredOverlayContextValue | undefined>;
1643
1637
 
1644
- export { $State$1 as $State, BaseButtonProps, BaseMenuButtonProps, BaseMenuGroupProps, BaseMenuItemProps, BaseMenuProps, BaseSelectOptionGroupProps, BaseSelectOptionProps, BaseSelectProps, BaseTextInputProps, BaseTriggeredOverlayProps, ButtonRef, CheckboxProps, CheckboxRef, CheckboxRefValue, DropdownMenu, Flex, HTMLElementRefOf, HtmlAnchorOnlyProps, HtmlButtonOnlyProps, MenuButtonRef, MenuButtonRefValue, MenuRef, MenuRefValue, MultiChoiceArg, PlasmicDataSourceContextProvider, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, SelectOptionRef, SelectRef, SelectRefValue, SingleBooleanChoiceArg, SingleChoiceArg, Stack, StrictProps, SwitchProps, SwitchRef, SwitchRefValue, TextInputRef, TextInputRefValue, Trans, TriggeredOverlayConfig, TriggeredOverlayContext, TriggeredOverlayRef, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, dlv as get, getDataProps, hasVariant, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, useButton, useCanvasDollarState, useCheckbox, useCurrentUser, useDollarState, useIsSSR, useIsomorphicLayoutEffect, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
1638
+ export { $State, BaseButtonProps, BaseMenuButtonProps, BaseMenuGroupProps, BaseMenuItemProps, BaseMenuProps, BaseSelectOptionGroupProps, BaseSelectOptionProps, BaseSelectProps, BaseTextInputProps, BaseTriggeredOverlayProps, ButtonRef, CheckboxProps, CheckboxRef, CheckboxRefValue, DropdownMenu, Flex, HTMLElementRefOf, HtmlAnchorOnlyProps, HtmlButtonOnlyProps, MenuButtonRef, MenuButtonRefValue, MenuRef, MenuRefValue, MultiChoiceArg, PlasmicDataSourceContextProvider, PlasmicHead, PlasmicIcon, PlasmicImg, PlasmicLink, PlasmicRootProvider, PlasmicSlot, SelectContext, SelectOptionRef, SelectRef, SelectRefValue, SingleBooleanChoiceArg, SingleChoiceArg, Stack, StrictProps, SwitchProps, SwitchRef, SwitchRefValue, TextInputRef, TextInputRefValue, Trans, TriggeredOverlayConfig, TriggeredOverlayContext, TriggeredOverlayRef, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, genTranslatableString, generateStateOnChangeProp, generateStateValueProp, dlv as get, getDataProps, hasVariant, isNum, makeFragment, mergeVariantsWithStates, omit, pick, plasmicHeadMeta, renderPlasmicSlot, set, setPlumeStrictMode, shallowEqual, useButton, useCanvasDollarState, useCheckbox, useCurrentUser, useDollarState, useIsSSR, useIsomorphicLayoutEffect, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };
@@ -13,6 +13,7 @@ export { PlasmicDataSourceContextProvider, PlasmicRootProvider, useCurrentUser,
13
13
  export { Stack } from "./render/Stack";
14
14
  export { genTranslatableString, Trans } from "./render/translation";
15
15
  export { useTrigger } from "./render/triggers";
16
+ export { $State } from "./states";
16
17
  export * from "./states/helpers";
17
- export { $State, default as useDollarState, useCanvasDollarState, } from "./states/valtio";
18
+ export { default as useDollarState, useCanvasDollarState, } from "./states/valtio";
18
19
  export declare const classNames: typeof _classNames;
@@ -1740,20 +1740,105 @@ function set(obj, keys, val) {
1740
1740
  }
1741
1741
  }
1742
1742
  var useIsomorphicLayoutEffect$1 = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
1743
+ function shallowEqual(a1, a2) {
1744
+ if (a1.length !== a2.length) {
1745
+ return false;
1746
+ }
1743
1747
 
1744
- var mkUntrackedValue = function mkUntrackedValue(o) {
1745
- return o != null && typeof o === "object" ? valtio.ref(o) : o;
1746
- };
1748
+ for (var i = 0; i < a1.length; i++) {
1749
+ if (a1[i] !== a2[i]) {
1750
+ return false;
1751
+ }
1752
+ }
1753
+
1754
+ return true;
1755
+ }
1756
+ function isNum(value) {
1757
+ return typeof value === "symbol" ? false : !isNaN(+value);
1758
+ }
1759
+
1760
+ var ARRAY_SYMBOL = /*#__PURE__*/Symbol("[]");
1761
+
1762
+ var StateSpecNode = /*#__PURE__*/function () {
1763
+ function StateSpecNode(specs) {
1764
+ this.specs = specs;
1765
+ this.edges = new Map();
1766
+ }
1747
1767
 
1768
+ var _proto = StateSpecNode.prototype;
1769
+
1770
+ _proto.hasEdge = function hasEdge(key) {
1771
+ return this.edges.has(key);
1772
+ };
1773
+
1774
+ _proto.addEdge = function addEdge(key, node) {
1775
+ this.edges.set(key, node);
1776
+ };
1777
+
1778
+ _proto.makeTransition = function makeTransition(key) {
1779
+ key = isNum(key) ? ARRAY_SYMBOL : key;
1780
+ return this.edges.get(key);
1781
+ };
1782
+
1783
+ _proto.isLeaf = function isLeaf() {
1784
+ return this.edges.size === 0;
1785
+ };
1786
+
1787
+ _proto.hasArrayTransition = function hasArrayTransition() {
1788
+ return this.edges.has(ARRAY_SYMBOL);
1789
+ };
1790
+
1791
+ _proto.getSpec = function getSpec() {
1792
+ return this.specs[0];
1793
+ };
1794
+
1795
+ _proto.getAllSpecs = function getAllSpecs() {
1796
+ return this.specs;
1797
+ };
1798
+
1799
+ return StateSpecNode;
1800
+ }();
1748
1801
  var transformPathStringToObj = function transformPathStringToObj(str) {
1749
1802
  var splitStatePathPart = function splitStatePathPart(state) {
1750
- return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
1803
+ return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), [ARRAY_SYMBOL]) : [state];
1751
1804
  };
1752
1805
 
1753
1806
  return str.split(".").flatMap(splitStatePathPart);
1754
1807
  };
1808
+ function buildGraph(specs) {
1809
+ var internalSpec = specs.map(function (spec) {
1810
+ return _extends({}, spec, {
1811
+ pathObj: transformPathStringToObj(spec.path),
1812
+ isRepeated: spec.path.split(".").some(function (part) {
1813
+ return part.endsWith("[]");
1814
+ })
1815
+ });
1816
+ });
1755
1817
 
1756
- function shallowEqual(a1, a2) {
1818
+ var rec = function rec(currentPath) {
1819
+ var node = new StateSpecNode(internalSpec.filter(function (spec) {
1820
+ return shallowEqual(currentPath, spec.pathObj.slice(0, currentPath.length));
1821
+ }));
1822
+ node.getAllSpecs().forEach(function (spec) {
1823
+ if (spec.pathObj.length > currentPath.length) {
1824
+ var nextKey = spec.pathObj[currentPath.length];
1825
+
1826
+ if (!node.hasEdge(nextKey)) {
1827
+ node.addEdge(nextKey, rec([].concat(currentPath, [nextKey])));
1828
+ }
1829
+ }
1830
+ });
1831
+ return node;
1832
+ };
1833
+
1834
+ return rec([]);
1835
+ }
1836
+
1837
+ var mkUntrackedValue = function mkUntrackedValue(o) {
1838
+ return o != null && typeof o === "object" ? valtio.ref(o) : o;
1839
+ };
1840
+
1841
+ function shallowEqual$1(a1, a2) {
1757
1842
  if (a1.length !== a2.length) {
1758
1843
  return false;
1759
1844
  }
@@ -1767,7 +1852,7 @@ function shallowEqual(a1, a2) {
1767
1852
  return true;
1768
1853
  }
1769
1854
 
1770
- function isNum(value) {
1855
+ function isNum$1(value) {
1771
1856
  return typeof value === "symbol" ? false : !isNaN(+value);
1772
1857
  }
1773
1858
 
@@ -1789,37 +1874,12 @@ function saveNewState($$state, path, spec) {
1789
1874
  }
1790
1875
 
1791
1876
  function create$StateProxy($$state, handlers) {
1792
- var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
1793
- return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
1794
- return shallowEqual(currPath.map(function (p) {
1795
- return isNum(p) ? "[]" : p;
1796
- }), spec.pathObj.slice(0, currPath.length));
1797
- }).reduce(function (agg, spec) {
1798
- var nextKey = spec.pathObj[currPath.length];
1799
-
1800
- if (!(nextKey in agg)) {
1801
- agg[nextKey] = [];
1802
- }
1803
-
1804
- agg[nextKey].push(spec);
1805
- return agg;
1806
- }, {})));
1807
- };
1808
-
1809
- var rec = function rec(currPath) {
1810
- var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
1811
-
1812
- var getSpecForProperty = function getSpecForProperty(property) {
1813
- var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
1814
-
1815
- 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;
1816
- };
1817
-
1877
+ var rec = function rec(currPath, currNode) {
1818
1878
  var getNextPath = function getNextPath(property) {
1819
- return [].concat(currPath, [isNum(property) ? +property : property]);
1879
+ return [].concat(currPath, [isNum$1(property) ? +property : property]);
1820
1880
  };
1821
1881
 
1822
- return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
1882
+ return new Proxy(currNode.hasArrayTransition() ? [] : {}, {
1823
1883
  deleteProperty: function deleteProperty(target, property) {
1824
1884
  var prefixPath = getNextPath(property);
1825
1885
  var specKeysToUpdate = new Set();
@@ -1827,7 +1887,7 @@ function create$StateProxy($$state, handlers) {
1827
1887
  var path = _ref.path,
1828
1888
  specKey = _ref.specKey;
1829
1889
 
1830
- if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
1890
+ if (path.length >= prefixPath.length && shallowEqual$1(path.slice(0, prefixPath.length), prefixPath)) {
1831
1891
  deleteState($$state, path);
1832
1892
  specKeysToUpdate.add(specKey);
1833
1893
  }
@@ -1844,36 +1904,34 @@ function create$StateProxy($$state, handlers) {
1844
1904
  return Reflect.deleteProperty(target, property);
1845
1905
  },
1846
1906
  get: function get(target, property, receiver) {
1847
- var spec = getSpecForProperty(property);
1848
-
1849
- if (spec && typeof property !== "symbol") {
1850
- var nextPath = getNextPath(property);
1907
+ var nextPath = getNextPath(property);
1908
+ var nextNode = currNode.makeTransition(property);
1851
1909
 
1852
- if (spec.pathObj.length === currPath.length + 1) {
1910
+ if (nextNode) {
1911
+ if (nextNode.isLeaf()) {
1853
1912
  var _handlers$get, _handlers;
1854
1913
 
1855
- // reached the end of the spec
1856
- target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
1914
+ target[property] = (_handlers$get = (_handlers = handlers(nextPath, nextNode.getSpec())).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
1857
1915
  } else if (!(property in target)) {
1858
- target[property] = rec(nextPath);
1916
+ target[property] = rec(nextPath, nextNode);
1859
1917
  }
1860
1918
  }
1861
1919
 
1862
1920
  return Reflect.get(target, property, receiver);
1863
1921
  },
1864
1922
  set: function set$1(target, property, value, receiver) {
1865
- var spec = getSpecForProperty(property);
1866
1923
  var nextPath = getNextPath(property);
1924
+ var nextNode = currNode.makeTransition(property);
1867
1925
 
1868
- if (spec && typeof property !== "symbol") {
1869
- if (spec.pathObj.length === currPath.length + 1) {
1926
+ if (nextNode && typeof property !== "symbol") {
1927
+ if (nextNode.isLeaf()) {
1870
1928
  var _handlers$set, _handlers2;
1871
1929
 
1872
1930
  // reached the end of the spec
1873
- target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
1931
+ target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, nextNode.getSpec())).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
1874
1932
  return Reflect.set(target, property, value, receiver);
1875
1933
  } else if (typeof value === "object") {
1876
- target[property] = rec(nextPath);
1934
+ target[property] = rec(nextPath, nextNode);
1877
1935
 
1878
1936
  for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
1879
1937
  var key = _Object$keys[_i];
@@ -1888,13 +1946,13 @@ function create$StateProxy($$state, handlers) {
1888
1946
  return Reflect.set(target, property, value, receiver);
1889
1947
  }
1890
1948
 
1891
- if (nextKeyToSpecs.has("[]")) {
1892
- var _nextKeyToSpecs$get3;
1949
+ if (currNode.hasArrayTransition()) {
1950
+ var _currNode$makeTransit, _currNode$makeTransit2;
1893
1951
 
1894
1952
  set($$state.stateValues, nextPath, value);
1895
1953
 
1896
- (_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
1897
- if (spec != null && spec.onChangeProp) {
1954
+ (_currNode$makeTransit = currNode.makeTransition(ARRAY_SYMBOL)) == null ? void 0 : (_currNode$makeTransit2 = _currNode$makeTransit.getAllSpecs()) == null ? void 0 : _currNode$makeTransit2.forEach(function (spec) {
1955
+ if (spec.onChangeProp) {
1898
1956
  var _$$state$props$spec$o2, _$$state$props2;
1899
1957
 
1900
1958
  (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
@@ -1909,7 +1967,7 @@ function create$StateProxy($$state, handlers) {
1909
1967
  });
1910
1968
  };
1911
1969
 
1912
- return rec([]);
1970
+ return rec([], $$state.rootStateSpec);
1913
1971
  }
1914
1972
 
1915
1973
  var deleteState = function deleteState($$state, path) {
@@ -2028,7 +2086,8 @@ function useDollarState(specs, props, $ctx) {
2028
2086
  unsubscriptionsByState: {},
2029
2087
  props: {},
2030
2088
  ctx: {},
2031
- registrationsQueue: []
2089
+ registrationsQueue: [],
2090
+ rootStateSpec: buildGraph(specs)
2032
2091
  })).current;
2033
2092
  $$state.props = mkUntrackedValue(props);
2034
2093
  $$state.ctx = mkUntrackedValue($ctx != null ? $ctx : {});
@@ -2147,28 +2206,12 @@ function useCanvasDollarState(specs, props, $ctx) {
2147
2206
  unsubscriptionsByState: {},
2148
2207
  props: {},
2149
2208
  ctx: {},
2150
- registrationsQueue: []
2209
+ registrationsQueue: [],
2210
+ rootStateSpec: buildGraph(specs)
2151
2211
  });
2152
2212
  $$state.props = mkUntrackedValue(props);
2153
2213
  $$state.ctx = mkUntrackedValue($ctx);
2154
- var $state = create$StateProxy($$state, function (path, spec) {
2155
- return {
2156
- get: function get() {
2157
- return _get($$state.stateValues, path);
2158
- },
2159
- set: function set(_t, _p, value) {
2160
- saveValue($$state, path, spec, value);
2161
-
2162
- if (spec.onChangeProp) {
2163
- var _$$state$props$spec$o5, _$$state$props5;
2164
-
2165
- (_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
2166
- }
2167
-
2168
- return true;
2169
- }
2170
- };
2171
- });
2214
+ var $state = {};
2172
2215
 
2173
2216
  for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
2174
2217
  var spec = _step.value;
@@ -3767,6 +3810,7 @@ exports.generateStateOnChangeProp = generateStateOnChangeProp;
3767
3810
  exports.generateStateValueProp = generateStateValueProp;
3768
3811
  exports.getDataProps = getDataProps;
3769
3812
  exports.hasVariant = hasVariant;
3813
+ exports.isNum = isNum;
3770
3814
  exports.makeFragment = makeFragment;
3771
3815
  exports.mergeVariantsWithStates = mergeVariantsWithStates;
3772
3816
  exports.omit = omit;
@@ -3775,6 +3819,7 @@ exports.plasmicHeadMeta = plasmicHeadMeta;
3775
3819
  exports.renderPlasmicSlot = renderPlasmicSlot;
3776
3820
  exports.set = set;
3777
3821
  exports.setPlumeStrictMode = setPlumeStrictMode;
3822
+ exports.shallowEqual = shallowEqual;
3778
3823
  exports.useButton = useButton;
3779
3824
  exports.useCanvasDollarState = useCanvasDollarState;
3780
3825
  exports.useCheckbox = useCheckbox;