@plasmicapp/react-web 0.2.114 → 0.2.116

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,9 @@ 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 deepEqual from 'fast-deep-equal';
12
+ import { proxy, ref, useSnapshot } from 'valtio';
13
+ import { subscribeKey } from 'valtio/utils';
11
14
  import { useCheckbox as useCheckbox$1 } from '@react-aria/checkbox';
12
15
  import { VisuallyHidden } from '@react-aria/visually-hidden';
13
16
  import { useToggleState } from '@react-stately/toggle';
@@ -22,9 +25,6 @@ import { useListBox, useOption, useListBoxSection } from '@react-aria/listbox';
22
25
  import { useSelectState } from '@react-stately/select';
23
26
  import { useSwitch as useSwitch$1 } from '@react-aria/switch';
24
27
  import { useOverlay, useOverlayPosition, DismissButton } from '@react-aria/overlays';
25
- import deepEqual from 'fast-deep-equal';
26
- import { proxy, ref, useSnapshot } from 'valtio';
27
- import { subscribeKey } from 'valtio/utils';
28
28
 
29
29
  function _extends() {
30
30
  _extends = Object.assign || function (target) {
@@ -1277,7 +1277,9 @@ var PlasmicLink = /*#__PURE__*/React__default.forwardRef(function PlasmicLink(pr
1277
1277
  // then we just render the default anchor element
1278
1278
  if (props.platform === "nextjs" && props.href) {
1279
1279
  var nextjsProps = ["href", "replace", "scroll", "shallow", "passHref", "prefetch", "locale"];
1280
- return React__default.createElement(props.component, pick.apply(void 0, [props].concat(nextjsProps)), React__default.createElement("a", Object.assign({}, omit.apply(void 0, [props, "component", "platform"].concat(nextjsProps)), {
1280
+ return React__default.createElement(props.component, _extends({}, pick.apply(void 0, [props].concat(nextjsProps)), {
1281
+ legacyBehavior: true
1282
+ }), React__default.createElement("a", Object.assign({}, omit.apply(void 0, [props, "component", "platform"].concat(nextjsProps)), {
1281
1283
  ref: ref
1282
1284
  })));
1283
1285
  }
@@ -1682,649 +1684,556 @@ function useTrigger(trigger, opts) {
1682
1684
  return TRIGGER_TO_HOOK[trigger](opts);
1683
1685
  }
1684
1686
 
1685
- // Utilities used by generated code
1686
- var classNames = classNames$1;
1687
-
1688
- var PLUME_STRICT_MODE = true;
1689
- function setPlumeStrictMode(mode) {
1690
- PLUME_STRICT_MODE = mode;
1691
- }
1692
- function mergeVariantToggles() {
1693
- for (var _len = arguments.length, toggles = new Array(_len), _key = 0; _key < _len; _key++) {
1694
- toggles[_key] = arguments[_key];
1695
- }
1696
-
1697
- var definedToggles = toggles.filter(function (x) {
1698
- return !!x.def;
1699
- });
1700
- var grouped = groupBy(definedToggles, function (_ref) {
1701
- var def = _ref.def;
1702
- return def.group;
1703
- });
1704
- return mapValues(grouped, function (subToggles) {
1705
- return Object.fromEntries(subToggles.map(function (_ref2) {
1706
- var def = _ref2.def,
1707
- active = _ref2.active;
1708
- return [def.variant, !!active];
1709
- }));
1710
- });
1711
- }
1712
- function noOutline() {
1713
- return {
1714
- outline: "none"
1687
+ function generateStateOnChangeProp($state, stateName, dataReps) {
1688
+ return function (val, path) {
1689
+ return set($state, [stateName].concat(dataReps, path), val);
1715
1690
  };
1716
1691
  }
1717
- function getPlumeType(child) {
1718
- if (!isValidElement(child)) {
1719
- return undefined;
1720
- }
1692
+ /**
1693
+ * This function generate the state value prop for repeated states
1694
+ * Example:
1695
+ * - parent[][].counter[].count
1696
+ * We need to pass `parent[index1][index2].counter to the child component
1697
+ */
1721
1698
 
1722
- var childType = child.type;
1723
- return childType.__plumeType || (childType.getPlumeType == null ? void 0 : childType.getPlumeType(child.props));
1699
+ function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
1700
+ ) {
1701
+ return _get($state, path);
1724
1702
  }
1703
+ /**
1704
+ * Forked from https://github.com/lukeed/dset
1705
+ * Changes: fixed setting a deep value to a proxy object
1706
+ */
1725
1707
 
1726
- var _excluded$4 = ["link", "isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "children"];
1727
- function useButton(plasmicClass, props, config, ref) {
1728
- var _ref, _ref2, _extends2, _overrides;
1708
+ function set(obj, keys, val) {
1709
+ keys = keys.split ? keys.split(".") : keys;
1710
+ var i = 0,
1711
+ l = keys.length,
1712
+ t = obj,
1713
+ x,
1714
+ k;
1729
1715
 
1730
- if (ref === void 0) {
1731
- ref = null;
1716
+ while (i < l) {
1717
+ k = keys[i++];
1718
+ if (k === "__proto__" || k === "constructor" || k === "prototype") break;
1719
+
1720
+ if (i === l) {
1721
+ t[k] = val;
1722
+ t = t[k];
1723
+ } else {
1724
+ if (typeof (x = t[k]) === typeof keys) {
1725
+ t = t[k] = x;
1726
+ } else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
1727
+ t[k] = {};
1728
+ t = t[k];
1729
+ } else {
1730
+ t[k] = [];
1731
+ t = t[k];
1732
+ }
1733
+ }
1732
1734
  }
1735
+ }
1733
1736
 
1734
- var link = props.link,
1735
- isDisabled = props.isDisabled,
1736
- startIcon = props.startIcon,
1737
- endIcon = props.endIcon,
1738
- showStartIcon = props.showStartIcon,
1739
- showEndIcon = props.showEndIcon,
1740
- children = props.children,
1741
- rest = _objectWithoutPropertiesLoose(props, _excluded$4);
1737
+ var mkUntrackedValue = function mkUntrackedValue(o) {
1738
+ return typeof o === "object" ? ref(o) : o;
1739
+ };
1742
1740
 
1743
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
1744
- def: config.showStartIconVariant,
1745
- active: showStartIcon
1746
- }, {
1747
- def: config.showEndIconVariant,
1748
- active: showEndIcon
1749
- }, {
1750
- def: config.isDisabledVariant,
1751
- active: isDisabled
1752
- }));
1741
+ var transformPathStringToObj = function transformPathStringToObj(str) {
1742
+ var splitStatePathPart = function splitStatePathPart(state) {
1743
+ return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
1744
+ };
1753
1745
 
1754
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.startIconSlot && (_ref = {}, _ref[config.startIconSlot] = startIcon, _ref), config.endIconSlot && (_ref2 = {}, _ref2[config.endIconSlot] = endIcon, _ref2), (_extends2 = {}, _extends2[config.contentSlot] = children, _extends2));
1746
+ return str.split(".").flatMap(splitStatePathPart);
1747
+ };
1755
1748
 
1756
- var overrides = (_overrides = {}, _overrides[config.root] = {
1757
- as: !!link ? "a" : "button",
1758
- props: _extends({}, omit.apply(void 0, [rest].concat(plasmicClass.internalArgProps, plasmicClass.internalVariantProps)), {
1759
- ref: ref,
1760
- disabled: isDisabled
1761
- }, !!link && {
1762
- href: link
1763
- })
1764
- }, _overrides);
1765
- return {
1766
- plasmicProps: {
1767
- variants: variants,
1768
- args: args,
1769
- overrides: overrides
1770
- }
1771
- };
1772
- }
1749
+ function shallowEqual(a1, a2) {
1750
+ if (a1.length !== a2.length) {
1751
+ return false;
1752
+ }
1773
1753
 
1774
- function getStyleProps(props) {
1775
- return pick(props, "className", "style");
1776
- }
1777
- function getDefaultPlasmicProps(plasmicClass, props) {
1778
- return {
1779
- plasmicProps: {
1780
- variants: pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)),
1781
- args: pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)),
1782
- overrides: {}
1754
+ for (var i = 0; i < a1.length; i++) {
1755
+ if (a1[i] !== a2[i]) {
1756
+ return false;
1783
1757
  }
1784
- };
1758
+ }
1759
+
1760
+ return true;
1785
1761
  }
1786
- var RE_DATA_PROP = /^(data-.*)$/;
1787
- function getDataProps(props) {
1788
- return pickBy(props, function (k) {
1789
- return RE_DATA_PROP.test(k);
1790
- });
1762
+
1763
+ function isNum(value) {
1764
+ return typeof value === "symbol" ? false : !isNaN(+value);
1791
1765
  }
1792
1766
 
1793
- function asAriaCheckboxProps(props) {
1794
- var ariaProps = _extends({}, props, {
1795
- isSelected: props.isChecked,
1796
- defaultSelected: props.defaultChecked
1767
+ function saveNewState($$state, path, spec) {
1768
+ var key = JSON.stringify(path);
1769
+ $$state.existingStates.set(key, {
1770
+ path: path,
1771
+ specKey: spec.path
1797
1772
  });
1798
1773
 
1799
- delete ariaProps["isChecked"];
1800
- delete ariaProps["defaultChecked"];
1801
- return ariaProps;
1802
- }
1774
+ if (!$$state.statesInstanceBySpec.has(spec.path)) {
1775
+ $$state.statesInstanceBySpec.set(spec.path, []);
1776
+ }
1803
1777
 
1804
- function useCheckbox(plasmicClass, props, config, ref) {
1805
- var _overrides, _ref;
1778
+ $$state.statesInstanceBySpec.get(spec.path).push({
1779
+ path: path,
1780
+ specKey: spec.path
1781
+ });
1782
+ }
1806
1783
 
1807
- if (ref === void 0) {
1808
- ref = null;
1809
- }
1784
+ function create$StateProxy($$state, handlers) {
1785
+ var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
1786
+ return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
1787
+ return shallowEqual(currPath.map(function (p) {
1788
+ return isNum(p) ? "[]" : p;
1789
+ }), spec.pathObj.slice(0, currPath.length));
1790
+ }).reduce(function (agg, spec) {
1791
+ var nextKey = spec.pathObj[currPath.length];
1810
1792
 
1811
- var children = props.children,
1812
- isDisabled = props.isDisabled,
1813
- isIndeterminate = props.isIndeterminate;
1814
- useEnsureSSRProvider();
1815
- var inputRef = useRef(null);
1816
- var rootRef = useRef(null);
1817
- var ariaProps = asAriaCheckboxProps(props);
1818
- var state = useToggleState(ariaProps);
1793
+ if (!(nextKey in agg)) {
1794
+ agg[nextKey] = [];
1795
+ }
1819
1796
 
1820
- var _useAriaCheckbox = useCheckbox$1(ariaProps, state, inputRef),
1821
- inputProps = _useAriaCheckbox.inputProps;
1797
+ agg[nextKey].push(spec);
1798
+ return agg;
1799
+ }, {})));
1800
+ };
1822
1801
 
1823
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
1824
- def: config.isDisabledVariant,
1825
- active: isDisabled
1826
- }, {
1827
- def: config.isCheckedVariant,
1828
- active: state.isSelected
1829
- }, {
1830
- def: config.isIndeterminateVariant,
1831
- active: isIndeterminate
1832
- }, {
1833
- def: config.noLabelVariant,
1834
- active: !children
1835
- }));
1802
+ var rec = function rec(currPath) {
1803
+ var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
1836
1804
 
1837
- var overrides = (_overrides = {}, _overrides[config.root] = {
1838
- as: "label",
1839
- props: mergeProps(getStyleProps(props), {
1840
- ref: rootRef
1841
- }),
1842
- wrapChildren: function wrapChildren(children) {
1843
- return createElement(Fragment, null, createElement(VisuallyHidden, {
1844
- isFocusable: true
1845
- }, createElement("input", Object.assign({}, inputProps, {
1846
- ref: inputRef
1847
- }))), children);
1848
- }
1849
- }, _overrides);
1805
+ var getSpecForProperty = function getSpecForProperty(property) {
1806
+ var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
1850
1807
 
1851
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.labelSlot ? (_ref = {}, _ref[config.labelSlot] = children, _ref) : {});
1808
+ 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;
1809
+ };
1852
1810
 
1853
- var plumeState = useMemo(function () {
1854
- return {
1855
- setChecked: function setChecked(checked) {
1856
- return state.setSelected(checked);
1857
- }
1811
+ var getNextPath = function getNextPath(property) {
1812
+ return [].concat(currPath, [isNum(property) ? +property : property]);
1858
1813
  };
1859
- }, [state]);
1860
- useImperativeHandle(ref, function () {
1861
- return {
1862
- getRoot: function getRoot() {
1863
- return rootRef.current;
1864
- },
1865
- focus: function focus() {
1866
- var _inputRef$current;
1867
1814
 
1868
- return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
1869
- },
1870
- blur: function blur() {
1871
- var _inputRef$current2;
1815
+ return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
1816
+ deleteProperty: function deleteProperty(target, property) {
1817
+ var prefixPath = getNextPath(property);
1818
+ var specKeysToUpdate = new Set();
1819
+ $$state.existingStates.forEach(function (_ref) {
1820
+ var path = _ref.path,
1821
+ specKey = _ref.specKey;
1872
1822
 
1873
- return (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
1874
- },
1875
- setChecked: function setChecked(checked) {
1876
- return plumeState.setChecked(checked);
1877
- }
1878
- };
1879
- }, [rootRef, inputRef, plumeState]);
1880
- return {
1881
- plasmicProps: {
1882
- variants: variants,
1883
- overrides: overrides,
1884
- args: args
1885
- },
1886
- state: plumeState
1887
- };
1888
- }
1823
+ if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
1824
+ deleteState($$state, path);
1825
+ specKeysToUpdate.add(specKey);
1826
+ }
1827
+ });
1828
+ specKeysToUpdate.forEach(function (specKey) {
1829
+ var spec = $$state.specsByKey[specKey];
1889
1830
 
1890
- /**
1891
- * Given children of a component like Select or Menu, derive the items
1892
- * that we will pass into the Collections API. These will be
1893
- * ReactElement<ItemLikeProps|SectionLikeProps>[].
1894
- *
1895
- * Will also assign keys to items by their index in the collection,
1896
- * and collect the keys of disabled items.
1897
- */
1831
+ if (spec.onChangeProp) {
1832
+ var _$$state$props$spec$o, _$$state$props;
1898
1833
 
1899
- function deriveItemsFromChildren(children, opts) {
1900
- if (!children) {
1901
- return {
1902
- items: [],
1903
- disabledKeys: []
1904
- };
1905
- }
1834
+ (_$$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);
1835
+ }
1836
+ });
1837
+ return Reflect.deleteProperty(target, property);
1838
+ },
1839
+ get: function get(target, property, receiver) {
1840
+ var spec = getSpecForProperty(property);
1906
1841
 
1907
- var itemPlumeType = opts.itemPlumeType,
1908
- sectionPlumeType = opts.sectionPlumeType,
1909
- invalidChildError = opts.invalidChildError; // For Plume items without an explicit key, we assign a key as the index
1910
- // of the collection.
1842
+ if (spec && typeof property !== "symbol") {
1843
+ var nextPath = getNextPath(property);
1911
1844
 
1912
- var itemCount = 0;
1913
- var sectionCount = 0;
1845
+ if (spec.pathObj.length === currPath.length + 1) {
1846
+ var _handlers$get, _handlers;
1914
1847
 
1915
- var ensureValue = function ensureValue(element) {
1916
- if (!propInChild(element, "value")) {
1917
- if (opts.requireItemValue && PLUME_STRICT_MODE) {
1918
- throw new Error("Must specify a \"value\" prop for " + getElementTypeName(element));
1919
- } else {
1920
- return cloneChild(element, {
1921
- value: "" + itemCount++
1922
- });
1923
- }
1924
- } else {
1925
- // Still increment count even if key is present, so that the
1926
- // auto-assigned key really reflects the index
1927
- itemCount++;
1928
- return element;
1929
- }
1930
- };
1848
+ // reached the end of the spec
1849
+ target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
1850
+ } else if (!(property in target)) {
1851
+ target[property] = rec(nextPath);
1852
+ }
1853
+ }
1931
1854
 
1932
- var disabledKeys = [];
1855
+ return Reflect.get(target, property, receiver);
1856
+ },
1857
+ set: function set$1(target, property, value, receiver) {
1858
+ var spec = getSpecForProperty(property);
1859
+ var nextPath = getNextPath(property);
1933
1860
 
1934
- var flattenedChildren = function flattenedChildren(children) {
1935
- return toChildArray(children).flatMap(function (child) {
1936
- if (React__default.isValidElement(child)) {
1937
- if (child.type === React__default.Fragment) {
1938
- return flattenedChildren(child.props.children);
1939
- }
1861
+ if (spec && typeof property !== "symbol") {
1862
+ if (spec.pathObj.length === currPath.length + 1) {
1863
+ var _handlers$set, _handlers2;
1940
1864
 
1941
- var type = getPlumeType(child);
1865
+ // reached the end of the spec
1866
+ target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
1867
+ return Reflect.set(target, property, value, receiver);
1868
+ } else if (typeof value === "object") {
1869
+ target[property] = rec(nextPath);
1942
1870
 
1943
- if (type === itemPlumeType) {
1944
- child = ensureValue(child);
1945
- var childKey = getItemLikeKey(child);
1871
+ for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
1872
+ var key = _Object$keys[_i];
1873
+ target[property][key] = value[key];
1874
+ }
1946
1875
 
1947
- if (getChildProp(child, "isDisabled") && !!childKey) {
1948
- disabledKeys.push(childKey);
1876
+ return true;
1949
1877
  }
1878
+ }
1950
1879
 
1951
- return [child];
1880
+ if (property === "registerInitFunc" && currPath.length === 0) {
1881
+ return Reflect.set(target, property, value, receiver);
1952
1882
  }
1953
1883
 
1954
- if (type === sectionPlumeType) {
1955
- var _child$key;
1884
+ if (nextKeyToSpecs.has("[]")) {
1885
+ var _nextKeyToSpecs$get3;
1956
1886
 
1957
- return [cloneChild(child, {
1958
- // key of section doesn't actually matter, just needs
1959
- // to be unique
1960
- key: (_child$key = child.key) != null ? _child$key : "section-" + sectionCount++,
1961
- children: flattenedChildren(getChildProp(child, "children"))
1962
- })];
1963
- }
1964
- }
1887
+ set($$state.stateValues, nextPath, value);
1965
1888
 
1966
- if (PLUME_STRICT_MODE) {
1967
- throw new Error(invalidChildError != null ? invalidChildError : "Unexpected child");
1968
- } else {
1969
- return [];
1889
+ (_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
1890
+ if (spec != null && spec.onChangeProp) {
1891
+ var _$$state$props$spec$o2, _$$state$props2;
1892
+
1893
+ (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
1894
+ }
1895
+ });
1896
+ return Reflect.set(target, property, value, receiver);
1897
+ } // invalid setting a value that doesn't make part of the spec
1898
+
1899
+
1900
+ return false;
1970
1901
  }
1971
1902
  });
1972
1903
  };
1973
1904
 
1974
- return {
1975
- items: flattenedChildren(children),
1976
- disabledKeys: disabledKeys
1977
- };
1978
- }
1979
- function useDerivedItemsFromChildren(children, opts) {
1980
- var itemPlumeType = opts.itemPlumeType,
1981
- sectionPlumeType = opts.sectionPlumeType,
1982
- invalidChildError = opts.invalidChildError,
1983
- requireItemValue = opts.requireItemValue;
1984
- return React__default.useMemo(function () {
1985
- return deriveItemsFromChildren(children, {
1986
- itemPlumeType: itemPlumeType,
1987
- sectionPlumeType: sectionPlumeType,
1988
- invalidChildError: invalidChildError,
1989
- requireItemValue: requireItemValue
1990
- });
1991
- }, [children, itemPlumeType, sectionPlumeType, invalidChildError, requireItemValue]);
1992
- }
1993
- /**
1994
- * Given a Collection node, create the React element that we should use
1995
- * to render it.
1996
- */
1997
-
1998
- function renderCollectionNode(node) {
1999
- // node.rendered should already have our item-like or section-like Plume
2000
- // component elements, so we just need to clone them with a secret
2001
- // _node prop that we use to render.
2002
- return cloneChild(node.rendered, {
2003
- _node: node,
2004
- key: node.key
2005
- });
1905
+ return rec([]);
2006
1906
  }
2007
- /**
2008
- * Renders a item-like or section-like Plume component element into an
2009
- * Item or a Section element.
2010
- */
2011
1907
 
2012
- function renderAsCollectionChild(child, opts) {
2013
- var plumeType = getPlumeType(child);
1908
+ var deleteState = function deleteState($$state, path) {
1909
+ var _$$state$unsubscripti;
2014
1910
 
2015
- if (plumeType === opts.itemPlumeType) {
2016
- var _getChildProp;
1911
+ var key = JSON.stringify(path);
1912
+ (_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
1913
+ return f();
1914
+ });
1915
+ delete $$state.unsubscriptionsByState[key];
1916
+ $$state.existingStates["delete"](key); // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
1917
+ // delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
1918
+ };
2017
1919
 
2018
- var option = child; // We look at the children passed to the item-like element, and derive key
2019
- // or textValue from it if it is a string
1920
+ var getIndexes = function getIndexes(path, spec) {
1921
+ var indexes = [];
2020
1922
 
2021
- var content = getChildProp(option, "children"); // The children render prop needs to return an <Item/>
1923
+ if (path.length !== spec.pathObj.length) {
1924
+ throw new Error("Unexpected error: state path and spec path have different lengths");
1925
+ }
2022
1926
 
2023
- return React__default.createElement(Item // We use ItemLike.value if the user explicitly specified a value,
2024
- // and we fallback to key. If the user specified neither, then
2025
- // the Collections API will generate a unique key for this item.
2026
- , {
2027
- // We use ItemLike.value if the user explicitly specified a value,
2028
- // and we fallback to key. If the user specified neither, then
2029
- // the Collections API will generate a unique key for this item.
2030
- key: getItemLikeKey(option),
2031
- // textValue is either explicitly specified by the user, or we
2032
- // try to derive it if `content` is a string.
2033
- textValue: (_getChildProp = getChildProp(option, "textValue")) != null ? _getChildProp : isString(content) ? content : propInChild(option, "value") ? getChildProp(option, "value") : option.key,
2034
- "aria-label": getChildProp(option, "aria-label")
2035
- }, option);
2036
- } else {
2037
- var group = child;
2038
- return React__default.createElement(Section // Note that we are using the whole section-like element as the title
2039
- // here, and not group.props.title; we want the entire section-like
2040
- // Plume element to end up as Node.rendered.
2041
- , {
2042
- // Note that we are using the whole section-like element as the title
2043
- // here, and not group.props.title; we want the entire section-like
2044
- // Plume element to end up as Node.rendered.
2045
- title: group,
2046
- "aria-label": getChildProp(group, "aria-label"),
2047
- // We are flattening and deriving the descendant Options as items here.
2048
- // group.props.children should've already been cleaned up by
2049
- // deriveItemsFromChildren()
2050
- items: getChildProp(group, "children")
2051
- }, function (c) {
2052
- return renderAsCollectionChild(c, opts);
2053
- });
1927
+ for (var i = 0; i < spec.pathObj.length; i++) {
1928
+ if (spec.pathObj[i] === "[]") {
1929
+ indexes.push(path[i]);
1930
+ }
2054
1931
  }
2055
- }
2056
-
2057
- function getItemLikeKey(element) {
2058
- var _getChildProp2;
2059
-
2060
- return (_getChildProp2 = getChildProp(element, "value")) != null ? _getChildProp2 : element.key;
2061
- } // PlasmicLoader-aware function to get prop from child.
2062
-
2063
-
2064
- function getChildProp(child, prop) {
2065
- return "componentProps" in child.props ? child.props.componentProps[prop] : child.props[prop];
2066
- } // PlasmicLoader-aware function to check `if (prop in element.props)`.
2067
-
2068
- function propInChild(child, prop) {
2069
- return "componentProps" in child.props ? prop in child.props.componentProps : prop in child.props;
2070
- } // PlasmicLoader-aware function to clone React element.
2071
1932
 
1933
+ return indexes;
1934
+ };
2072
1935
 
2073
- function cloneChild(child, props) {
2074
- if (child.type.getPlumeType) {
2075
- // If React element has getPlumeType(), assume that it is PlasmicLoader,
2076
- // so add nodeProps to componentProps instead of element props.
2077
- return React__default.cloneElement(child, _extends({
2078
- componentProps: _extends({}, child.props.componentProps, props)
2079
- }, props.key ? {
2080
- key: props.key
2081
- } : {}));
2082
- }
1936
+ function initializeStateValue($$state, initialStatePath, initialSpec) {
1937
+ var _$$state$unsubscripti2;
2083
1938
 
2084
- return React__default.cloneElement(child, props);
2085
- }
1939
+ var initialStateKey = JSON.stringify(initialStatePath);
1940
+ var stateAccess = new Set();
1941
+ var $state = create$StateProxy($$state, function (path, spec) {
1942
+ return {
1943
+ get: function get() {
1944
+ var key = JSON.stringify(path);
1945
+ stateAccess.add({
1946
+ path: path,
1947
+ spec: spec
1948
+ });
2086
1949
 
2087
- var TriggeredOverlayContext = /*#__PURE__*/createContext(undefined);
1950
+ if (spec.valueProp) {
1951
+ return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
1952
+ }
2088
1953
 
2089
- var MenuContext = /*#__PURE__*/createContext(undefined);
1954
+ if ($$state.existingStates.has(key)) {
1955
+ // is already initialized
1956
+ return _get($$state.stateValues, path);
1957
+ } else if (spec.initFunc) {
1958
+ initializeStateValue($$state, path, spec);
1959
+ }
2090
1960
 
2091
- var _excluded$5 = ["children"];
2092
- var COLLECTION_OPTS = {
2093
- itemPlumeType: "menu-item",
2094
- sectionPlumeType: "menu-group"
2095
- };
2096
- /**
2097
- * Converts props from BaseMenuProps to react-aria's useMenu() props.
2098
- */
1961
+ return _get($$state.stateValues, path);
1962
+ },
1963
+ set: function set() {
1964
+ throw new Error("Cannot update state values during initialization");
1965
+ }
1966
+ };
1967
+ });
1968
+ (_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
1969
+ return f();
1970
+ });
1971
+ $$state.unsubscriptionsByState[initialStateKey] = [];
1972
+ stateAccess.forEach(function (_ref2) {
1973
+ var path = _ref2.path,
1974
+ spec = _ref2.spec;
1975
+ var unsubscribe = subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
1976
+ return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
1977
+ });
1978
+ $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
1979
+ });
1980
+ var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
2099
1981
 
2100
- function asAriaMenuProps(props) {
2101
- var children = props.children,
2102
- rest = _objectWithoutPropertiesLoose(props, _excluded$5);
1982
+ set($$state.initStateValues, initialStatePath, untrackedInitialValue);
2103
1983
 
2104
- var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS, {
2105
- invalidChildError: "Can only use Menu.Item and Menu.Group as children to Menu",
2106
- requireItemValue: false
2107
- })),
2108
- items = _useDerivedItemsFromC.items,
2109
- disabledKeys = _useDerivedItemsFromC.disabledKeys;
1984
+ set($$state.stateValues, initialStatePath, untrackedInitialValue);
2110
1985
 
2111
- var collectionChildRenderer = useCallback(function (child) {
2112
- return renderAsCollectionChild(child, COLLECTION_OPTS);
2113
- }, []);
2114
- return {
2115
- ariaProps: _extends({}, rest, {
2116
- children: collectionChildRenderer,
2117
- items: items,
2118
- disabledKeys: disabledKeys
2119
- })
2120
- };
1986
+ return untrackedInitialValue;
2121
1987
  }
2122
1988
 
2123
- function useMenu(plasmicClass, props, config, ref) {
2124
- var _overrides, _extends2;
2125
-
2126
- if (ref === void 0) {
2127
- ref = null;
2128
- }
1989
+ function useDollarState(specs, props) {
1990
+ var $$state = React__default.useRef(proxy({
1991
+ stateValues: {},
1992
+ initStateValues: {},
1993
+ specsByKey: Object.fromEntries(specs.map(function (spec) {
1994
+ return [spec.path, _extends({}, spec, {
1995
+ pathObj: transformPathStringToObj(spec.path),
1996
+ isRepeated: spec.path.split(".").some(function (part) {
1997
+ return part.endsWith("[]");
1998
+ })
1999
+ })];
2000
+ })),
2001
+ statesInstanceBySpec: new Map(),
2002
+ existingStates: new Map(),
2003
+ unsubscriptionsByState: {},
2004
+ props: undefined,
2005
+ registrationsQueue: []
2006
+ })).current;
2007
+ $$state.props = mkUntrackedValue(props);
2008
+ var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
2009
+ var key = JSON.stringify(path);
2129
2010
 
2130
- useEnsureSSRProvider();
2011
+ if (!$$state.existingStates.has(key)) {
2012
+ var _spec$initVal;
2131
2013
 
2132
- var _asAriaMenuProps = asAriaMenuProps(props),
2133
- ariaProps = _asAriaMenuProps.ariaProps;
2014
+ saveNewState($$state, path, spec);
2015
+ var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
2134
2016
 
2135
- var triggerContext = useContext(TriggeredOverlayContext);
2136
- var rootRef = useRef(null);
2137
- var state = useTreeState(ariaProps);
2138
- var menuListRef = useRef(null);
2017
+ set($$state.stateValues, path, untrackedValue);
2139
2018
 
2140
- var _useAriaMenu = useMenu$1(_extends({}, ariaProps, {
2141
- autoFocus: triggerContext == null ? void 0 : triggerContext.autoFocus
2142
- }), state, menuListRef),
2143
- menuProps = _useAriaMenu.menuProps;
2019
+ set($$state.initStateValues, path, untrackedValue);
2020
+ }
2144
2021
 
2145
- var contextValue = useMemo(function () {
2146
2022
  return {
2147
- state: state,
2148
- menuProps: props
2149
- };
2150
- }, [state, props]);
2151
-
2152
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)));
2023
+ get: function get() {
2024
+ if (spec.valueProp) {
2025
+ var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
2026
+ return value;
2027
+ } else {
2028
+ return _get($$state.stateValues, path);
2029
+ }
2030
+ },
2031
+ set: function set$1(_t, _p, value) {
2032
+ set($$state.stateValues, path, mkUntrackedValue(value));
2153
2033
 
2154
- var overrides = (_overrides = {}, _overrides[config.root] = {
2155
- props: mergeProps(getStyleProps(props), {
2156
- ref: rootRef
2157
- })
2158
- }, _overrides[config.itemsContainer] = {
2159
- as: "ul",
2160
- props: mergeProps(menuProps, {
2161
- ref: menuListRef,
2162
- style: _extends({}, noOutline())
2163
- })
2164
- }, _overrides);
2034
+ if (spec.onChangeProp) {
2035
+ var _$$state$props$spec$o3, _$$state$props3;
2165
2036
 
2166
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.itemsSlot] = createElement(MenuContext.Provider, {
2167
- value: contextValue
2168
- }, Array.from(state.collection).map(function (node) {
2169
- return renderCollectionNode(node);
2170
- })), _extends2));
2037
+ (_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
2038
+ }
2171
2039
 
2172
- var plumeState = useMemo(function () {
2173
- return {
2174
- getFocusedValue: function getFocusedValue() {
2175
- return state.selectionManager.focusedKey;
2176
- },
2177
- setFocusedValue: function setFocusedValue(value) {
2178
- return state.selectionManager.setFocusedKey(value);
2040
+ return true;
2179
2041
  }
2180
2042
  };
2181
- }, [state]);
2182
- useImperativeHandle(ref, function () {
2183
- return {
2184
- getRoot: function getRoot() {
2185
- return rootRef.current;
2186
- },
2187
- getFocusedValue: function getFocusedValue() {
2188
- return plumeState.getFocusedValue();
2189
- },
2190
- setFocusedValue: function setFocusedValue(key) {
2191
- return plumeState.setFocusedValue(key);
2043
+ }), {
2044
+ registerInitFunc: function registerInitFunc(pathStr, f) {
2045
+ var _$$state$statesInstan;
2046
+
2047
+ if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
2048
+ var path = _ref3.path,
2049
+ specKey = _ref3.specKey;
2050
+ return !deepEqual(_get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
2051
+ })) {
2052
+ $$state.registrationsQueue.push({
2053
+ pathStr: pathStr,
2054
+ f: f
2055
+ });
2192
2056
  }
2193
- };
2194
- }, [rootRef, plumeState]);
2195
- return {
2196
- plasmicProps: {
2197
- variants: variants,
2198
- args: args,
2199
- overrides: overrides
2200
- },
2201
- state: plumeState
2202
- };
2203
- }
2057
+ }
2058
+ })).current; // For each spec with an initFunc, evaluate it and see if
2059
+ // the init value has changed. If so, reset its state.
2204
2060
 
2205
- function useMenuGroup(plasmicClass, props, config) {
2206
- var _extends2, _overrides;
2061
+ var resetSpecs = [];
2062
+ $$state.existingStates.forEach(function (_ref4) {
2063
+ var path = _ref4.path,
2064
+ specKey = _ref4.specKey;
2065
+ var spec = $$state.specsByKey[specKey];
2207
2066
 
2208
- var context = useContext(MenuContext);
2209
- var node = props._node;
2067
+ if (spec.initFunc) {
2068
+ var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
2210
2069
 
2211
- if (!context || !node) {
2212
- if (PLUME_STRICT_MODE) {
2213
- throw new Error("You can only use a Menu.Group within a Menu component.");
2070
+ if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
2071
+ resetSpecs.push({
2072
+ path: path,
2073
+ spec: spec
2074
+ });
2075
+ }
2214
2076
  }
2077
+ });
2078
+ React__default.useLayoutEffect(function () {
2079
+ resetSpecs.forEach(function (_ref5) {
2080
+ var path = _ref5.path,
2081
+ spec = _ref5.spec;
2082
+ var newInit = initializeStateValue($$state, path, spec);
2215
2083
 
2216
- return getDefaultPlasmicProps(plasmicClass, props);
2217
- }
2084
+ if (spec.onChangeProp) {
2085
+ var _$$state$props$spec$o4, _$$state$props4;
2218
2086
 
2219
- var _useMenuSection = useMenuSection({
2220
- heading: props.title,
2221
- "aria-label": props["aria-label"]
2222
- }),
2223
- headingProps = _useMenuSection.headingProps,
2224
- groupProps = _useMenuSection.groupProps;
2087
+ (_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
2088
+ }
2089
+ });
2090
+ }, [props, resetSpecs]);
2091
+ React__default.useLayoutEffect(function () {
2092
+ $$state.registrationsQueue.forEach(function (_ref6) {
2093
+ var f = _ref6.f,
2094
+ pathStr = _ref6.pathStr;
2095
+ $$state.specsByKey[pathStr].initFunc = f;
2096
+ });
2097
+ $$state.registrationsQueue = [];
2098
+ }, [$$state.registrationsQueue]); // Re-render if any value changed in one of these objects
2225
2099
 
2226
- var _useSeparator = useSeparator({
2227
- elementType: "li"
2228
- }),
2229
- separatorProps = _useSeparator.separatorProps;
2100
+ useSnapshot($$state.stateValues, {
2101
+ sync: true
2102
+ });
2103
+ useSnapshot($$state.specsByKey, {
2104
+ sync: true
2105
+ });
2106
+ return $state;
2107
+ }
2230
2108
 
2231
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2232
- def: config.noTitleVariant,
2233
- active: !props.title
2234
- }, {
2235
- def: config.isFirstVariant,
2236
- active: context.state.collection.getFirstKey() === node.key
2237
- }));
2109
+ function useCanvasDollarState(specs, props) {
2110
+ var $$state = proxy({
2111
+ stateValues: {},
2112
+ initStateValues: {},
2113
+ specsByKey: Object.fromEntries(specs.map(function (spec) {
2114
+ return [spec.path, _extends({}, spec, {
2115
+ pathObj: transformPathStringToObj(spec.path),
2116
+ isRepeated: spec.path.split(".").some(function (part) {
2117
+ return part.endsWith("[]");
2118
+ })
2119
+ })];
2120
+ })),
2121
+ statesInstanceBySpec: new Map(),
2122
+ existingStates: new Map(),
2123
+ unsubscriptionsByState: {},
2124
+ props: undefined,
2125
+ registrationsQueue: []
2126
+ });
2127
+ $$state.props = mkUntrackedValue(props);
2128
+ var $state = create$StateProxy($$state, function (path, spec) {
2129
+ return {
2130
+ get: function get() {
2131
+ return _get($$state.stateValues, path);
2132
+ },
2133
+ set: function set$1(_t, _p, value) {
2134
+ set($$state.stateValues, path, mkUntrackedValue(value));
2238
2135
 
2239
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.titleSlot] = props.title, _extends2[config.itemsSlot] = Array.from(node.childNodes).map(function (childNode) {
2240
- return renderCollectionNode(childNode);
2241
- }), _extends2));
2136
+ if (spec.onChangeProp) {
2137
+ var _$$state$props$spec$o5, _$$state$props5;
2242
2138
 
2243
- var overrides = (_overrides = {}, _overrides[config.root] = {
2244
- props: getStyleProps(props)
2245
- }, _overrides[config.separator] = {
2246
- props: _extends({}, separatorProps),
2247
- as: "li"
2248
- }, _overrides[config.titleContainer] = _extends({
2249
- props: _extends({
2250
- role: "presentation"
2251
- }, headingProps)
2252
- }, !props.title && {
2253
- render: function render() {
2254
- return null;
2255
- }
2256
- }), _overrides[config.itemsContainer] = {
2257
- props: _extends({}, groupProps),
2258
- as: "ul"
2259
- }, _overrides);
2139
+ (_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
2140
+ }
2141
+
2142
+ return true;
2143
+ }
2144
+ };
2145
+ });
2146
+
2147
+ for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
2148
+ var spec = _step.value;
2149
+ var path = transformPathStringToObj(spec.path);
2150
+ var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
2151
+
2152
+ set($state, path, init);
2153
+ }
2154
+
2155
+ return $state;
2156
+ }
2157
+
2158
+ // Utilities used by generated code
2159
+ var classNames = classNames$1;
2160
+
2161
+ var PLUME_STRICT_MODE = true;
2162
+ function setPlumeStrictMode(mode) {
2163
+ PLUME_STRICT_MODE = mode;
2164
+ }
2165
+ function mergeVariantToggles() {
2166
+ for (var _len = arguments.length, toggles = new Array(_len), _key = 0; _key < _len; _key++) {
2167
+ toggles[_key] = arguments[_key];
2168
+ }
2169
+
2170
+ var definedToggles = toggles.filter(function (x) {
2171
+ return !!x.def;
2172
+ });
2173
+ var grouped = groupBy(definedToggles, function (_ref) {
2174
+ var def = _ref.def;
2175
+ return def.group;
2176
+ });
2177
+ return mapValues(grouped, function (subToggles) {
2178
+ return Object.fromEntries(subToggles.map(function (_ref2) {
2179
+ var def = _ref2.def,
2180
+ active = _ref2.active;
2181
+ return [def.variant, !!active];
2182
+ }));
2183
+ });
2184
+ }
2185
+ function noOutline() {
2260
2186
  return {
2261
- plasmicProps: {
2262
- variants: variants,
2263
- args: args,
2264
- overrides: overrides
2265
- }
2187
+ outline: "none"
2266
2188
  };
2267
2189
  }
2190
+ function getPlumeType(child) {
2191
+ if (!isValidElement(child)) {
2192
+ return undefined;
2193
+ }
2268
2194
 
2269
- function useMenuItem(plasmicClass, props, config) {
2270
- var _extends2, _overrides;
2271
-
2272
- var menuContext = useContext(MenuContext);
2273
- var triggerContext = useContext(TriggeredOverlayContext);
2195
+ var childType = child.type;
2196
+ return childType.__plumeType || (childType.getPlumeType == null ? void 0 : childType.getPlumeType(child.props));
2197
+ }
2274
2198
 
2275
- if (!menuContext) {
2276
- if (PLUME_STRICT_MODE) {
2277
- throw new Error("You can only use a Menu.Item within a Menu component.");
2278
- }
2199
+ var _excluded$4 = ["link", "isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "children"];
2200
+ function useButton(plasmicClass, props, config, ref) {
2201
+ var _ref, _ref2, _extends2, _overrides;
2279
2202
 
2280
- return getDefaultPlasmicProps(plasmicClass, props);
2203
+ if (ref === void 0) {
2204
+ ref = null;
2281
2205
  }
2282
2206
 
2283
- var children = props.children,
2284
- onAction = props.onAction;
2285
- var state = menuContext.state,
2286
- menuProps = menuContext.menuProps; // We pass in the Node secretly as an undocumented prop from <Select />
2287
-
2288
- var node = props._node;
2289
- var isDisabled = state.disabledKeys.has(node.key);
2290
- var isHighlighted = state.selectionManager.isFocused && state.selectionManager.focusedKey === node.key;
2291
- var ref = useRef(null);
2207
+ var link = props.link,
2208
+ isDisabled = props.isDisabled,
2209
+ startIcon = props.startIcon,
2210
+ endIcon = props.endIcon,
2211
+ showStartIcon = props.showStartIcon,
2212
+ showEndIcon = props.showEndIcon,
2213
+ children = props.children,
2214
+ rest = _objectWithoutPropertiesLoose(props, _excluded$4);
2292
2215
 
2293
- var _useAriaMenuItem = useMenuItem$1(mergeProps({
2294
- // We need to merge both the onAction on MenuItem and the onAction
2295
- // on Menu
2296
- onAction: onAction
2216
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2217
+ def: config.showStartIconVariant,
2218
+ active: showStartIcon
2297
2219
  }, {
2298
- onAction: menuProps.onAction,
2299
- onClose: triggerContext == null ? void 0 : triggerContext.state.close
2220
+ def: config.showEndIconVariant,
2221
+ active: showEndIcon
2300
2222
  }, {
2301
- isDisabled: isDisabled,
2302
- "aria-label": node && node["aria-label"],
2303
- key: node.key,
2304
- isVirtualized: false,
2305
- closeOnSelect: true
2306
- }), state, ref),
2307
- menuItemProps = _useAriaMenuItem.menuItemProps,
2308
- labelProps = _useAriaMenuItem.labelProps;
2309
-
2310
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2311
2223
  def: config.isDisabledVariant,
2312
2224
  active: isDisabled
2313
- }, {
2314
- def: config.isHighlightedVariant,
2315
- active: isHighlighted
2316
2225
  }));
2317
2226
 
2318
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.labelSlot] = children, _extends2));
2227
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.startIconSlot && (_ref = {}, _ref[config.startIconSlot] = startIcon, _ref), config.endIconSlot && (_ref2 = {}, _ref2[config.endIconSlot] = endIcon, _ref2), (_extends2 = {}, _extends2[config.contentSlot] = children, _extends2));
2319
2228
 
2320
2229
  var overrides = (_overrides = {}, _overrides[config.root] = {
2321
- as: "li",
2322
- props: mergeProps(menuItemProps, {
2230
+ as: !!link ? "a" : "button",
2231
+ props: _extends({}, omit.apply(void 0, [rest].concat(plasmicClass.internalArgProps, plasmicClass.internalVariantProps)), {
2323
2232
  ref: ref,
2324
- style: noOutline()
2233
+ disabled: isDisabled
2234
+ }, !!link && {
2235
+ href: link
2325
2236
  })
2326
- }, _overrides[config.labelContainer] = {
2327
- props: _extends({}, labelProps)
2328
2237
  }, _overrides);
2329
2238
  return {
2330
2239
  plasmicProps: {
@@ -2335,294 +2244,356 @@ function useMenuItem(plasmicClass, props, config) {
2335
2244
  };
2336
2245
  }
2337
2246
 
2338
- /**
2339
- * A menu trigger hook that combines react-aria's useMenuTrigger, useAriaMenuTrigger,
2340
- * useOverlayPosition, useOverlay, and usePress
2341
- */
2342
-
2343
- function useMenuTrigger(opts, state) {
2344
- var triggerRef = opts.triggerRef,
2345
- isDisabled = opts.isDisabled,
2346
- placement = opts.placement,
2347
- menuMatchTriggerWidth = opts.menuMatchTriggerWidth,
2348
- menuWidth = opts.menuWidth,
2349
- menu = opts.menu;
2247
+ function getStyleProps(props) {
2248
+ return pick(props, "className", "style");
2249
+ }
2250
+ function getDefaultPlasmicProps(plasmicClass, props) {
2251
+ return {
2252
+ plasmicProps: {
2253
+ variants: pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)),
2254
+ args: pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)),
2255
+ overrides: {}
2256
+ }
2257
+ };
2258
+ }
2259
+ var RE_DATA_PROP = /^(data-.*)$/;
2260
+ function getDataProps(props) {
2261
+ return pickBy(props, function (k) {
2262
+ return RE_DATA_PROP.test(k);
2263
+ });
2264
+ }
2350
2265
 
2351
- var _useAriaMenuTrigger = useMenuTrigger$1({
2352
- type: "menu",
2353
- isDisabled: isDisabled
2354
- }, state, triggerRef),
2355
- triggerPressProps = _useAriaMenuTrigger.menuTriggerProps,
2356
- menuProps = _useAriaMenuTrigger.menuProps;
2266
+ function asAriaCheckboxProps(props) {
2267
+ var ariaProps = _extends({}, props, {
2268
+ isSelected: props.isChecked,
2269
+ defaultSelected: props.defaultChecked
2270
+ });
2357
2271
 
2358
- var _usePress = usePress(_extends({}, triggerPressProps, {
2359
- isDisabled: isDisabled
2360
- })),
2361
- triggerProps = _usePress.pressProps;
2362
-
2363
- var makeMenu = function makeMenu() {
2364
- var realMenu = typeof menu === "function" ? menu() : menu;
2365
-
2366
- if (!realMenu) {
2367
- return null;
2368
- }
2369
-
2370
- if (getPlumeType(realMenu) !== "menu") {
2371
- if (PLUME_STRICT_MODE) {
2372
- throw new Error("Must use an instance of the Menu component.");
2373
- }
2374
-
2375
- return null;
2376
- }
2377
-
2378
- return cloneElement(realMenu, mergeProps(realMenu.props, menuProps));
2379
- };
2380
-
2381
- var triggerContext = useMemo(function () {
2382
- var _state$focusStrategy;
2383
-
2384
- return {
2385
- triggerRef: triggerRef,
2386
- state: state,
2387
- autoFocus: (_state$focusStrategy = state.focusStrategy) != null ? _state$focusStrategy : true,
2388
- placement: placement,
2389
- overlayMatchTriggerWidth: menuMatchTriggerWidth,
2390
- overlayMinTriggerWidth: true,
2391
- overlayWidth: menuWidth
2392
- };
2393
- }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
2394
- return {
2395
- triggerProps: triggerProps,
2396
- makeMenu: makeMenu,
2397
- triggerContext: triggerContext
2398
- };
2399
- }
2400
-
2401
- function DropdownMenu(props) {
2402
- var isOpen = props.isOpen,
2403
- defaultOpen = props.defaultOpen,
2404
- onOpenChange = props.onOpenChange,
2405
- children = props.children,
2406
- placement = props.placement,
2407
- menu = props.menu;
2408
- var triggerRef = useRef(null);
2409
- var state = useMenuTriggerState({
2410
- isOpen: isOpen,
2411
- defaultOpen: defaultOpen,
2412
- onOpenChange: onOpenChange,
2413
- shouldFlip: true
2414
- });
2415
-
2416
- var _useMenuTrigger = useMenuTrigger({
2417
- triggerRef: triggerRef,
2418
- placement: placement,
2419
- menu: menu
2420
- }, state),
2421
- triggerProps = _useMenuTrigger.triggerProps,
2422
- makeMenu = _useMenuTrigger.makeMenu,
2423
- triggerContext = _useMenuTrigger.triggerContext;
2424
-
2425
- return createElement(TriggeredOverlayContext.Provider, {
2426
- value: triggerContext
2427
- }, cloneElement(children, mergeProps(children.props, triggerProps, {
2428
- ref: triggerRef
2429
- })), state.isOpen && makeMenu());
2272
+ delete ariaProps["isChecked"];
2273
+ delete ariaProps["defaultChecked"];
2274
+ return ariaProps;
2430
2275
  }
2431
2276
 
2432
- function useMenuButton(plasmicClass, props, config, outerRef) {
2433
- var _extends2, _overrides;
2277
+ function useCheckbox(plasmicClass, props, config, ref) {
2278
+ var _overrides, _ref;
2434
2279
 
2435
- if (outerRef === void 0) {
2436
- outerRef = null;
2280
+ if (ref === void 0) {
2281
+ ref = null;
2437
2282
  }
2438
2283
 
2439
- var placement = props.placement,
2440
- isOpen = props.isOpen,
2441
- defaultOpen = props.defaultOpen,
2442
- onOpenChange = props.onOpenChange,
2284
+ var children = props.children,
2443
2285
  isDisabled = props.isDisabled,
2444
- menu = props.menu,
2445
- autoFocus = props.autoFocus,
2446
- menuMatchTriggerWidth = props.menuMatchTriggerWidth,
2447
- menuWidth = props.menuWidth;
2286
+ isIndeterminate = props.isIndeterminate;
2448
2287
  useEnsureSSRProvider();
2288
+ var inputRef = useRef(null);
2449
2289
  var rootRef = useRef(null);
2450
- var triggerRef = useRef(null);
2451
- var state = useMenuTriggerState({
2452
- isOpen: isOpen,
2453
- defaultOpen: defaultOpen,
2454
- onOpenChange: onOpenChange,
2455
- shouldFlip: true
2456
- });
2457
-
2458
- var _useMenuTrigger = useMenuTrigger({
2459
- isDisabled: isDisabled,
2460
- triggerRef: triggerRef,
2461
- placement: placement,
2462
- menuMatchTriggerWidth: menuMatchTriggerWidth,
2463
- menuWidth: menuWidth,
2464
- menu: menu
2465
- }, state),
2466
- triggerProps = _useMenuTrigger.triggerProps,
2467
- makeMenu = _useMenuTrigger.makeMenu,
2468
- triggerContext = _useMenuTrigger.triggerContext;
2290
+ var ariaProps = asAriaCheckboxProps(props);
2291
+ var state = useToggleState(ariaProps);
2469
2292
 
2470
- var _useFocusable = useFocusable(props, triggerRef),
2471
- triggerFocusProps = _useFocusable.focusableProps;
2293
+ var _useAriaCheckbox = useCheckbox$1(ariaProps, state, inputRef),
2294
+ inputProps = _useAriaCheckbox.inputProps;
2472
2295
 
2473
2296
  var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2474
- def: config.isOpenVariant,
2475
- active: state.isOpen
2476
- }, {
2477
2297
  def: config.isDisabledVariant,
2478
2298
  active: isDisabled
2299
+ }, {
2300
+ def: config.isCheckedVariant,
2301
+ active: state.isSelected
2302
+ }, {
2303
+ def: config.isIndeterminateVariant,
2304
+ active: isIndeterminate
2305
+ }, {
2306
+ def: config.noLabelVariant,
2307
+ active: !children
2479
2308
  }));
2480
2309
 
2481
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.menuSlot] = state.isOpen ? makeMenu() : undefined, _extends2));
2482
-
2483
2310
  var overrides = (_overrides = {}, _overrides[config.root] = {
2484
- wrapChildren: function wrapChildren(children) {
2485
- return createElement(TriggeredOverlayContext.Provider, {
2486
- value: triggerContext
2487
- }, children);
2488
- },
2489
- props: {
2311
+ as: "label",
2312
+ props: mergeProps(getStyleProps(props), {
2490
2313
  ref: rootRef
2314
+ }),
2315
+ wrapChildren: function wrapChildren(children) {
2316
+ return createElement(Fragment, null, createElement(VisuallyHidden, {
2317
+ isFocusable: true
2318
+ }, createElement("input", Object.assign({}, inputProps, {
2319
+ ref: inputRef
2320
+ }))), children);
2491
2321
  }
2492
- }, _overrides[config.trigger] = {
2493
- props: mergeProps(triggerProps, triggerFocusProps, getStyleProps(props), pick(props, "title"), {
2494
- ref: triggerRef,
2495
- autoFocus: autoFocus,
2496
- disabled: !!isDisabled,
2497
- // Make sure this button is not interpreted as submit
2498
- type: "button"
2499
- })
2500
2322
  }, _overrides);
2323
+
2324
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.labelSlot ? (_ref = {}, _ref[config.labelSlot] = children, _ref) : {});
2325
+
2501
2326
  var plumeState = useMemo(function () {
2502
2327
  return {
2503
- open: function open() {
2504
- return state.open();
2505
- },
2506
- close: function close() {
2507
- return state.close();
2508
- },
2509
- isOpen: function isOpen() {
2510
- return state.isOpen;
2328
+ setChecked: function setChecked(checked) {
2329
+ return state.setSelected(checked);
2511
2330
  }
2512
2331
  };
2513
2332
  }, [state]);
2514
- useImperativeHandle(outerRef, function () {
2333
+ useImperativeHandle(ref, function () {
2515
2334
  return {
2516
2335
  getRoot: function getRoot() {
2517
2336
  return rootRef.current;
2518
2337
  },
2519
- getTrigger: function getTrigger() {
2520
- return triggerRef.current;
2521
- },
2522
2338
  focus: function focus() {
2523
- return triggerRef.current && triggerRef.current.focus();
2339
+ var _inputRef$current;
2340
+
2341
+ return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
2524
2342
  },
2525
2343
  blur: function blur() {
2526
- return triggerRef.current && triggerRef.current.blur();
2344
+ var _inputRef$current2;
2345
+
2346
+ return (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
2527
2347
  },
2528
- open: plumeState.open,
2529
- close: plumeState.close,
2530
- isOpen: plumeState.isOpen
2348
+ setChecked: function setChecked(checked) {
2349
+ return plumeState.setChecked(checked);
2350
+ }
2531
2351
  };
2532
- }, [rootRef, triggerRef, plumeState]);
2352
+ }, [rootRef, inputRef, plumeState]);
2533
2353
  return {
2534
2354
  plasmicProps: {
2535
2355
  variants: variants,
2536
- args: args,
2537
- overrides: overrides
2356
+ overrides: overrides,
2357
+ args: args
2538
2358
  },
2539
2359
  state: plumeState
2540
2360
  };
2541
2361
  }
2542
2362
 
2543
- var SelectContext = /*#__PURE__*/createContext(undefined);
2544
-
2545
- var _excluded$6 = ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"];
2546
- var COLLECTION_OPTS$1 = {
2547
- itemPlumeType: "select-option",
2548
- sectionPlumeType: "select-option-group"
2549
- };
2550
2363
  /**
2551
- * Converts props in our BaseSelectProps into props that react-aria's
2552
- * useSelect() understands.
2553
- *
2554
- * Because we're not exposing the Collections API (see ./index.tsx),
2555
- * we are converting our own API into props for useSelect.
2556
- *
2557
- * Specifically, in Plume's API,
2558
- * - `children` flattens to a list of ReactElements of type Select.Option
2559
- * or Select.OptionGroup
2560
- *
2561
- * and we map it this way to the Collections API:
2562
- * - `items` is a list of those flattened ReactElements from `children`!
2563
- * - `children`, as a render prop, is supposed to take one of the `items`
2564
- * and return a `Section` or `Item` element. We take an Option/OptionGroup
2565
- * element, and use its props to render the appropriate `Section` or
2566
- * `Item`. The "trick" here is that we then stuff the Option element as
2567
- * `Item.children`, and the OptionGroup element as `Section.title`.
2568
- *
2569
- * When the Collections API does its work deriving `Node`s, the corresponding
2570
- * Option/OptionGroup ReactElements will end up as `Node.rendered`.
2571
- *
2572
- * Then, when we are actually rendering the content of the dropdown, we
2573
- * iterate through each collected `Node`, and renders
2574
- * React.cloneElement(Node.rendered, {_node: node}). This "secretly" passes
2575
- * the derived collection `Node` as a prop to Option and OptionGroup, and they
2576
- * can make use of the derived `Node.key` etc in their rendering functions.
2364
+ * Given children of a component like Select or Menu, derive the items
2365
+ * that we will pass into the Collections API. These will be
2366
+ * ReactElement<ItemLikeProps|SectionLikeProps>[].
2577
2367
  *
2578
- * One thing to note here is that we never "rendered" the Option/OptionGroup
2579
- * React elements that the user constructed; instead, we just looked at the
2580
- * props used on those elements, and passed those onto the Collections API.
2581
- * What gets rendered to the screen is the cloned version of these elements
2582
- * with the secret derived `_node` prop. That means Option and OptionGroup
2583
- * render functions can assume that _node is passed in.
2368
+ * Will also assign keys to items by their index in the collection,
2369
+ * and collect the keys of disabled items.
2584
2370
  */
2585
2371
 
2586
- function useAriaSelectProps(props) {
2587
- var value = props.value,
2588
- defaultValue = props.defaultValue,
2589
- children = props.children,
2590
- onChange = props.onChange,
2591
- rest = _objectWithoutPropertiesLoose(props, _excluded$6);
2372
+ function deriveItemsFromChildren(children, opts) {
2373
+ if (!children) {
2374
+ return {
2375
+ items: [],
2376
+ disabledKeys: []
2377
+ };
2378
+ }
2592
2379
 
2593
- var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS$1, {
2594
- invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select",
2595
- requireItemValue: true
2596
- })),
2597
- items = _useDerivedItemsFromC.items,
2380
+ var itemPlumeType = opts.itemPlumeType,
2381
+ sectionPlumeType = opts.sectionPlumeType,
2382
+ invalidChildError = opts.invalidChildError; // For Plume items without an explicit key, we assign a key as the index
2383
+ // of the collection.
2384
+
2385
+ var itemCount = 0;
2386
+ var sectionCount = 0;
2387
+
2388
+ var ensureValue = function ensureValue(element) {
2389
+ if (!propInChild(element, "value")) {
2390
+ if (opts.requireItemValue && PLUME_STRICT_MODE) {
2391
+ throw new Error("Must specify a \"value\" prop for " + getElementTypeName(element));
2392
+ } else {
2393
+ return cloneChild(element, {
2394
+ value: "" + itemCount++
2395
+ });
2396
+ }
2397
+ } else {
2398
+ // Still increment count even if key is present, so that the
2399
+ // auto-assigned key really reflects the index
2400
+ itemCount++;
2401
+ return element;
2402
+ }
2403
+ };
2404
+
2405
+ var disabledKeys = [];
2406
+
2407
+ var flattenedChildren = function flattenedChildren(children) {
2408
+ return toChildArray(children).flatMap(function (child) {
2409
+ if (React__default.isValidElement(child)) {
2410
+ if (child.type === React__default.Fragment) {
2411
+ return flattenedChildren(child.props.children);
2412
+ }
2413
+
2414
+ var type = getPlumeType(child);
2415
+
2416
+ if (type === itemPlumeType) {
2417
+ child = ensureValue(child);
2418
+ var childKey = getItemLikeKey(child);
2419
+
2420
+ if (getChildProp(child, "isDisabled") && !!childKey) {
2421
+ disabledKeys.push(childKey);
2422
+ }
2423
+
2424
+ return [child];
2425
+ }
2426
+
2427
+ if (type === sectionPlumeType) {
2428
+ var _child$key;
2429
+
2430
+ return [cloneChild(child, {
2431
+ // key of section doesn't actually matter, just needs
2432
+ // to be unique
2433
+ key: (_child$key = child.key) != null ? _child$key : "section-" + sectionCount++,
2434
+ children: flattenedChildren(getChildProp(child, "children"))
2435
+ })];
2436
+ }
2437
+ }
2438
+
2439
+ if (PLUME_STRICT_MODE) {
2440
+ throw new Error(invalidChildError != null ? invalidChildError : "Unexpected child");
2441
+ } else {
2442
+ return [];
2443
+ }
2444
+ });
2445
+ };
2446
+
2447
+ return {
2448
+ items: flattenedChildren(children),
2449
+ disabledKeys: disabledKeys
2450
+ };
2451
+ }
2452
+ function useDerivedItemsFromChildren(children, opts) {
2453
+ var itemPlumeType = opts.itemPlumeType,
2454
+ sectionPlumeType = opts.sectionPlumeType,
2455
+ invalidChildError = opts.invalidChildError,
2456
+ requireItemValue = opts.requireItemValue;
2457
+ return React__default.useMemo(function () {
2458
+ return deriveItemsFromChildren(children, {
2459
+ itemPlumeType: itemPlumeType,
2460
+ sectionPlumeType: sectionPlumeType,
2461
+ invalidChildError: invalidChildError,
2462
+ requireItemValue: requireItemValue
2463
+ });
2464
+ }, [children, itemPlumeType, sectionPlumeType, invalidChildError, requireItemValue]);
2465
+ }
2466
+ /**
2467
+ * Given a Collection node, create the React element that we should use
2468
+ * to render it.
2469
+ */
2470
+
2471
+ function renderCollectionNode(node) {
2472
+ // node.rendered should already have our item-like or section-like Plume
2473
+ // component elements, so we just need to clone them with a secret
2474
+ // _node prop that we use to render.
2475
+ return cloneChild(node.rendered, {
2476
+ _node: node,
2477
+ key: node.key
2478
+ });
2479
+ }
2480
+ /**
2481
+ * Renders a item-like or section-like Plume component element into an
2482
+ * Item or a Section element.
2483
+ */
2484
+
2485
+ function renderAsCollectionChild(child, opts) {
2486
+ var plumeType = getPlumeType(child);
2487
+
2488
+ if (plumeType === opts.itemPlumeType) {
2489
+ var _getChildProp;
2490
+
2491
+ var option = child; // We look at the children passed to the item-like element, and derive key
2492
+ // or textValue from it if it is a string
2493
+
2494
+ var content = getChildProp(option, "children"); // The children render prop needs to return an <Item/>
2495
+
2496
+ return React__default.createElement(Item // We use ItemLike.value if the user explicitly specified a value,
2497
+ // and we fallback to key. If the user specified neither, then
2498
+ // the Collections API will generate a unique key for this item.
2499
+ , {
2500
+ // We use ItemLike.value if the user explicitly specified a value,
2501
+ // and we fallback to key. If the user specified neither, then
2502
+ // the Collections API will generate a unique key for this item.
2503
+ key: getItemLikeKey(option),
2504
+ // textValue is either explicitly specified by the user, or we
2505
+ // try to derive it if `content` is a string.
2506
+ textValue: (_getChildProp = getChildProp(option, "textValue")) != null ? _getChildProp : isString(content) ? content : propInChild(option, "value") ? getChildProp(option, "value") : option.key,
2507
+ "aria-label": getChildProp(option, "aria-label")
2508
+ }, option);
2509
+ } else {
2510
+ var group = child;
2511
+ return React__default.createElement(Section // Note that we are using the whole section-like element as the title
2512
+ // here, and not group.props.title; we want the entire section-like
2513
+ // Plume element to end up as Node.rendered.
2514
+ , {
2515
+ // Note that we are using the whole section-like element as the title
2516
+ // here, and not group.props.title; we want the entire section-like
2517
+ // Plume element to end up as Node.rendered.
2518
+ title: group,
2519
+ "aria-label": getChildProp(group, "aria-label"),
2520
+ // We are flattening and deriving the descendant Options as items here.
2521
+ // group.props.children should've already been cleaned up by
2522
+ // deriveItemsFromChildren()
2523
+ items: getChildProp(group, "children")
2524
+ }, function (c) {
2525
+ return renderAsCollectionChild(c, opts);
2526
+ });
2527
+ }
2528
+ }
2529
+
2530
+ function getItemLikeKey(element) {
2531
+ var _getChildProp2;
2532
+
2533
+ return (_getChildProp2 = getChildProp(element, "value")) != null ? _getChildProp2 : element.key;
2534
+ } // PlasmicLoader-aware function to get prop from child.
2535
+
2536
+
2537
+ function getChildProp(child, prop) {
2538
+ return "componentProps" in child.props ? child.props.componentProps[prop] : child.props[prop];
2539
+ } // PlasmicLoader-aware function to check `if (prop in element.props)`.
2540
+
2541
+ function propInChild(child, prop) {
2542
+ return "componentProps" in child.props ? prop in child.props.componentProps : prop in child.props;
2543
+ } // PlasmicLoader-aware function to clone React element.
2544
+
2545
+
2546
+ function cloneChild(child, props) {
2547
+ if (child.type.getPlumeType) {
2548
+ // If React element has getPlumeType(), assume that it is PlasmicLoader,
2549
+ // so add nodeProps to componentProps instead of element props.
2550
+ return React__default.cloneElement(child, _extends({
2551
+ componentProps: _extends({}, child.props.componentProps, props)
2552
+ }, props.key ? {
2553
+ key: props.key
2554
+ } : {}));
2555
+ }
2556
+
2557
+ return React__default.cloneElement(child, props);
2558
+ }
2559
+
2560
+ var TriggeredOverlayContext = /*#__PURE__*/createContext(undefined);
2561
+
2562
+ var MenuContext = /*#__PURE__*/createContext(undefined);
2563
+
2564
+ var _excluded$5 = ["children"];
2565
+ var COLLECTION_OPTS = {
2566
+ itemPlumeType: "menu-item",
2567
+ sectionPlumeType: "menu-group"
2568
+ };
2569
+ /**
2570
+ * Converts props from BaseMenuProps to react-aria's useMenu() props.
2571
+ */
2572
+
2573
+ function asAriaMenuProps(props) {
2574
+ var children = props.children,
2575
+ rest = _objectWithoutPropertiesLoose(props, _excluded$5);
2576
+
2577
+ var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS, {
2578
+ invalidChildError: "Can only use Menu.Item and Menu.Group as children to Menu",
2579
+ requireItemValue: false
2580
+ })),
2581
+ items = _useDerivedItemsFromC.items,
2598
2582
  disabledKeys = _useDerivedItemsFromC.disabledKeys;
2599
2583
 
2600
2584
  var collectionChildRenderer = useCallback(function (child) {
2601
- return renderAsCollectionChild(child, COLLECTION_OPTS$1);
2585
+ return renderAsCollectionChild(child, COLLECTION_OPTS);
2602
2586
  }, []);
2603
- var onSelectionChange = useMemo(function () {
2604
- if (onChange) {
2605
- return function (val) {
2606
- return onChange(val == null || val === "null" ? null : val);
2607
- };
2608
- } else {
2609
- return undefined;
2610
- }
2611
- }, [onChange]);
2612
2587
  return {
2613
2588
  ariaProps: _extends({}, rest, {
2614
2589
  children: collectionChildRenderer,
2615
- onSelectionChange: onSelectionChange,
2616
2590
  items: items,
2617
- disabledKeys: disabledKeys,
2618
- defaultSelectedKey: defaultValue
2619
- }, "value" in props && {
2620
- selectedKey: value != null ? value : null
2591
+ disabledKeys: disabledKeys
2621
2592
  })
2622
2593
  };
2623
2594
  }
2624
2595
 
2625
- function useSelect(plasmicClass, props, config, ref) {
2596
+ function useMenu(plasmicClass, props, config, ref) {
2626
2597
  var _overrides, _extends2;
2627
2598
 
2628
2599
  if (ref === void 0) {
@@ -2631,110 +2602,53 @@ function useSelect(plasmicClass, props, config, ref) {
2631
2602
 
2632
2603
  useEnsureSSRProvider();
2633
2604
 
2634
- var _useAriaSelectProps = useAriaSelectProps(props),
2635
- ariaProps = _useAriaSelectProps.ariaProps;
2605
+ var _asAriaMenuProps = asAriaMenuProps(props),
2606
+ ariaProps = _asAriaMenuProps.ariaProps;
2636
2607
 
2637
- var placement = props.placement;
2638
- var state = useSelectState(ariaProps);
2639
- var triggerRef = useRef(null);
2608
+ var triggerContext = useContext(TriggeredOverlayContext);
2640
2609
  var rootRef = useRef(null);
2641
- var isDisabled = props.isDisabled,
2642
- name = props.name,
2643
- menuWidth = props.menuWidth,
2644
- menuMatchTriggerWidth = props.menuMatchTriggerWidth,
2645
- autoFocus = props.autoFocus,
2646
- placeholder = props.placeholder,
2647
- selectedContent = props.selectedContent;
2610
+ var state = useTreeState(ariaProps);
2611
+ var menuListRef = useRef(null);
2648
2612
 
2649
- var _useAriaSelect = useSelect$1(ariaProps, state, triggerRef),
2650
- triggerPressProps = _useAriaSelect.triggerProps,
2651
- menuProps = _useAriaSelect.menuProps;
2613
+ var _useAriaMenu = useMenu$1(_extends({}, ariaProps, {
2614
+ autoFocus: triggerContext == null ? void 0 : triggerContext.autoFocus
2615
+ }), state, menuListRef),
2616
+ menuProps = _useAriaMenu.menuProps;
2652
2617
 
2653
- var _usePress = usePress(_extends({}, triggerPressProps, {
2654
- isDisabled: isDisabled
2655
- })),
2656
- triggerProps = _usePress.pressProps;
2618
+ var contextValue = useMemo(function () {
2619
+ return {
2620
+ state: state,
2621
+ menuProps: props
2622
+ };
2623
+ }, [state, props]);
2657
2624
 
2658
- var triggerContent = state.selectedItem ? selectedContent != null ? selectedContent : getChildProp(state.selectedItem.value, "children") : null;
2659
-
2660
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2661
- def: config.isOpenVariant,
2662
- active: state.isOpen
2663
- }, {
2664
- def: config.placeholderVariant,
2665
- active: !state.selectedItem
2666
- }, {
2667
- def: config.isDisabledVariant,
2668
- active: isDisabled
2669
- }));
2625
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)));
2670
2626
 
2671
- var triggerContext = useMemo(function () {
2672
- return {
2673
- triggerRef: triggerRef,
2674
- state: state,
2675
- placement: placement,
2676
- overlayMatchTriggerWidth: menuMatchTriggerWidth,
2677
- overlayMinTriggerWidth: true,
2678
- overlayWidth: menuWidth
2679
- };
2680
- }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
2681
2627
  var overrides = (_overrides = {}, _overrides[config.root] = {
2682
2628
  props: mergeProps(getStyleProps(props), {
2683
2629
  ref: rootRef
2684
- }),
2685
- wrapChildren: function wrapChildren(children) {
2686
- return createElement(Fragment, null, createElement(HiddenSelect, {
2687
- state: state,
2688
- triggerRef: triggerRef,
2689
- name: name,
2690
- isDisabled: isDisabled
2691
- }), children);
2692
- }
2693
- }, _overrides[config.trigger] = {
2694
- props: mergeProps(triggerProps, {
2695
- ref: triggerRef,
2696
- autoFocus: autoFocus,
2697
- disabled: !!isDisabled,
2698
- // Don't trigger form submission!
2699
- type: "button"
2700
2630
  })
2701
- }, _overrides[config.overlay] = {
2702
- wrap: function wrap(content) {
2703
- return createElement(TriggeredOverlayContext.Provider, {
2704
- value: triggerContext
2705
- }, content);
2706
- }
2707
- }, _overrides[config.optionsContainer] = {
2708
- wrap: function wrap(content) {
2709
- return createElement(ListBoxWrapper, {
2710
- state: state,
2711
- menuProps: menuProps
2712
- }, content);
2713
- }
2631
+ }, _overrides[config.itemsContainer] = {
2632
+ as: "ul",
2633
+ props: mergeProps(menuProps, {
2634
+ ref: menuListRef,
2635
+ style: _extends({}, noOutline())
2636
+ })
2714
2637
  }, _overrides);
2715
2638
 
2716
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.triggerContentSlot] = triggerContent, _extends2[config.placeholderSlot] = placeholder, _extends2[config.optionsSlot] = createElement(SelectContext.Provider, {
2717
- value: state
2639
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.itemsSlot] = createElement(MenuContext.Provider, {
2640
+ value: contextValue
2718
2641
  }, Array.from(state.collection).map(function (node) {
2719
2642
  return renderCollectionNode(node);
2720
2643
  })), _extends2));
2721
2644
 
2722
2645
  var plumeState = useMemo(function () {
2723
2646
  return {
2724
- open: function open() {
2725
- return state.open();
2726
- },
2727
- close: function close() {
2728
- return state.close();
2729
- },
2730
- isOpen: function isOpen() {
2731
- return state.isOpen;
2732
- },
2733
- getSelectedValue: function getSelectedValue() {
2734
- return state.selectedKey ? "" + state.selectedKey : null;
2647
+ getFocusedValue: function getFocusedValue() {
2648
+ return state.selectionManager.focusedKey;
2735
2649
  },
2736
- setSelectedValue: function setSelectedValue(key) {
2737
- return state.setSelectedKey(key);
2650
+ setFocusedValue: function setFocusedValue(value) {
2651
+ return state.selectionManager.setFocusedKey(value);
2738
2652
  }
2739
2653
  };
2740
2654
  }, [state]);
@@ -2743,36 +2657,14 @@ function useSelect(plasmicClass, props, config, ref) {
2743
2657
  getRoot: function getRoot() {
2744
2658
  return rootRef.current;
2745
2659
  },
2746
- getTrigger: function getTrigger() {
2747
- return triggerRef.current;
2748
- },
2749
- focus: function focus() {
2750
- var _triggerRef$current;
2751
-
2752
- return (_triggerRef$current = triggerRef.current) == null ? void 0 : _triggerRef$current.focus();
2753
- },
2754
- blur: function blur() {
2755
- var _triggerRef$current2;
2756
-
2757
- return (_triggerRef$current2 = triggerRef.current) == null ? void 0 : _triggerRef$current2.blur();
2758
- },
2759
- open: function open() {
2760
- return plumeState.open();
2761
- },
2762
- close: function close() {
2763
- return plumeState.close();
2764
- },
2765
- isOpen: function isOpen() {
2766
- return plumeState.isOpen();
2767
- },
2768
- getSelectedValue: function getSelectedValue() {
2769
- return plumeState.getSelectedValue();
2660
+ getFocusedValue: function getFocusedValue() {
2661
+ return plumeState.getFocusedValue();
2770
2662
  },
2771
- setSelectedValue: function setSelectedValue(key) {
2772
- return plumeState.setSelectedValue(key);
2663
+ setFocusedValue: function setFocusedValue(key) {
2664
+ return plumeState.setFocusedValue(key);
2773
2665
  }
2774
2666
  };
2775
- }, [rootRef, triggerRef, plumeState]);
2667
+ }, [rootRef, plumeState]);
2776
2668
  return {
2777
2669
  plasmicProps: {
2778
2670
  variants: variants,
@@ -2783,118 +2675,26 @@ function useSelect(plasmicClass, props, config, ref) {
2783
2675
  };
2784
2676
  }
2785
2677
 
2786
- function ListBoxWrapper(props) {
2787
- var state = props.state,
2788
- menuProps = props.menuProps,
2789
- children = props.children;
2790
- var ref = useRef(null);
2791
-
2792
- var _useListBox = useListBox(_extends({}, menuProps, {
2793
- isVirtualized: false,
2794
- autoFocus: state.focusStrategy || true,
2795
- disallowEmptySelection: true
2796
- }), state, ref),
2797
- listBoxProps = _useListBox.listBoxProps;
2798
-
2799
- return cloneElement(children, mergeProps(children.props, listBoxProps, {
2800
- style: noOutline(),
2801
- ref: ref
2802
- }));
2803
- }
2804
-
2805
- function useSelectOption(plasmicClass, props, config, outerRef) {
2806
- var _extends2, _overrides;
2807
-
2808
- if (outerRef === void 0) {
2809
- outerRef = null;
2810
- }
2811
-
2812
- var state = useContext(SelectContext);
2813
-
2814
- if (!state) {
2815
- // If no context, then we are being incorrectly used. Complain or just don't
2816
- // bother installing any hooks. It's okay to violate rules of hooks here
2817
- // because this instance won't suddenly be used correctly in another render.
2818
- if (PLUME_STRICT_MODE) {
2819
- throw new Error("You can only use a Select.Option within a Select component.");
2820
- }
2821
-
2822
- return getDefaultPlasmicProps(plasmicClass, props);
2823
- }
2824
-
2825
- var children = props.children;
2826
- var rootRef = useRef(null);
2827
- var onRef = mergeRefs(rootRef, outerRef); // We pass in the Node secretly as an undocumented prop from <Select />
2828
-
2829
- var node = props._node;
2830
- var isSelected = state.selectionManager.isSelected(node.key);
2831
- var isDisabled = state.disabledKeys.has(node.key);
2832
- var isHighlighted = state.selectionManager.isFocused && state.selectionManager.focusedKey === node.key;
2833
-
2834
- var _useAriaOption = useOption({
2835
- isSelected: isSelected,
2836
- isDisabled: isDisabled,
2837
- "aria-label": node && node["aria-label"],
2838
- key: node.key,
2839
- shouldSelectOnPressUp: true,
2840
- shouldFocusOnHover: true,
2841
- isVirtualized: false
2842
- }, state, rootRef),
2843
- optionProps = _useAriaOption.optionProps,
2844
- labelProps = _useAriaOption.labelProps;
2845
-
2846
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2847
- def: config.isSelectedVariant,
2848
- active: isSelected
2849
- }, {
2850
- def: config.isDisabledVariant,
2851
- active: isDisabled
2852
- }, {
2853
- def: config.isHighlightedVariant,
2854
- active: isHighlighted
2855
- }));
2856
-
2857
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.labelSlot] = children, _extends2));
2858
-
2859
- var overrides = (_overrides = {}, _overrides[config.root] = {
2860
- props: mergeProps(optionProps, getStyleProps(props), {
2861
- ref: onRef,
2862
- style: noOutline()
2863
- })
2864
- }, _overrides[config.labelContainer] = {
2865
- props: labelProps
2866
- }, _overrides);
2867
- return {
2868
- plasmicProps: {
2869
- variants: variants,
2870
- args: args,
2871
- overrides: overrides
2872
- }
2873
- };
2874
- }
2875
-
2876
- function useSelectOptionGroup(plasmicClass, props, config) {
2678
+ function useMenuGroup(plasmicClass, props, config) {
2877
2679
  var _extends2, _overrides;
2878
2680
 
2879
- var state = useContext(SelectContext); // `node` should exist if the OptionGroup was instantiated properly
2880
- // within a Select
2881
-
2681
+ var context = useContext(MenuContext);
2882
2682
  var node = props._node;
2883
2683
 
2884
- if (!state || !node) {
2684
+ if (!context || !node) {
2885
2685
  if (PLUME_STRICT_MODE) {
2886
- throw new Error("You can only use a Select.OptionGroup within a Select component.");
2686
+ throw new Error("You can only use a Menu.Group within a Menu component.");
2887
2687
  }
2888
2688
 
2889
2689
  return getDefaultPlasmicProps(plasmicClass, props);
2890
2690
  }
2891
2691
 
2892
- var _useListBoxSection = useListBoxSection({
2692
+ var _useMenuSection = useMenuSection({
2893
2693
  heading: props.title,
2894
2694
  "aria-label": props["aria-label"]
2895
2695
  }),
2896
- headingProps = _useListBoxSection.headingProps,
2897
- groupProps = _useListBoxSection.groupProps;
2696
+ headingProps = _useMenuSection.headingProps,
2697
+ groupProps = _useMenuSection.groupProps;
2898
2698
 
2899
2699
  var _useSeparator = useSeparator({
2900
2700
  elementType: "li"
@@ -2906,17 +2706,18 @@ function useSelectOptionGroup(plasmicClass, props, config) {
2906
2706
  active: !props.title
2907
2707
  }, {
2908
2708
  def: config.isFirstVariant,
2909
- active: state.collection.getFirstKey() === node.key
2709
+ active: context.state.collection.getFirstKey() === node.key
2910
2710
  }));
2911
2711
 
2912
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.titleSlot] = props.title, _extends2[config.optionsSlot] = Array.from(node.childNodes).map(function (childNode) {
2712
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.titleSlot] = props.title, _extends2[config.itemsSlot] = Array.from(node.childNodes).map(function (childNode) {
2913
2713
  return renderCollectionNode(childNode);
2914
2714
  }), _extends2));
2915
2715
 
2916
2716
  var overrides = (_overrides = {}, _overrides[config.root] = {
2917
2717
  props: getStyleProps(props)
2918
2718
  }, _overrides[config.separator] = {
2919
- props: _extends({}, separatorProps)
2719
+ props: _extends({}, separatorProps),
2720
+ as: "li"
2920
2721
  }, _overrides[config.titleContainer] = _extends({
2921
2722
  props: _extends({
2922
2723
  role: "presentation"
@@ -2925,8 +2726,9 @@ function useSelectOptionGroup(plasmicClass, props, config) {
2925
2726
  render: function render() {
2926
2727
  return null;
2927
2728
  }
2928
- }), _overrides[config.optionsContainer] = {
2929
- props: _extends({}, groupProps)
2729
+ }), _overrides[config.itemsContainer] = {
2730
+ props: _extends({}, groupProps),
2731
+ as: "ul"
2930
2732
  }, _overrides);
2931
2733
  return {
2932
2734
  plasmicProps: {
@@ -2937,776 +2739,976 @@ function useSelectOptionGroup(plasmicClass, props, config) {
2937
2739
  };
2938
2740
  }
2939
2741
 
2940
- function asAriaSwitchProps(props) {
2941
- var ariaProps = _extends({}, props, {
2942
- isSelected: props.isChecked,
2943
- defaultSelected: props.defaultChecked
2944
- });
2742
+ function useMenuItem(plasmicClass, props, config) {
2743
+ var _extends2, _overrides;
2945
2744
 
2946
- delete ariaProps["isChecked"];
2947
- delete ariaProps["defaultChecked"];
2948
- return ariaProps;
2949
- }
2745
+ var menuContext = useContext(MenuContext);
2746
+ var triggerContext = useContext(TriggeredOverlayContext);
2950
2747
 
2951
- function useSwitch(plasmicClass, props, config, ref) {
2952
- var _overrides, _ref;
2748
+ if (!menuContext) {
2749
+ if (PLUME_STRICT_MODE) {
2750
+ throw new Error("You can only use a Menu.Item within a Menu component.");
2751
+ }
2953
2752
 
2954
- if (ref === void 0) {
2955
- ref = null;
2753
+ return getDefaultPlasmicProps(plasmicClass, props);
2956
2754
  }
2957
2755
 
2958
2756
  var children = props.children,
2959
- isDisabled = props.isDisabled;
2960
- useEnsureSSRProvider();
2961
- var inputRef = useRef(null);
2962
- var rootRef = useRef(null);
2963
- var ariaProps = asAriaSwitchProps(props);
2964
- var state = useToggleState(ariaProps);
2757
+ onAction = props.onAction;
2758
+ var state = menuContext.state,
2759
+ menuProps = menuContext.menuProps; // We pass in the Node secretly as an undocumented prop from <Select />
2965
2760
 
2966
- var _useAriaSwitch = useSwitch$1(ariaProps, state, inputRef),
2967
- inputProps = _useAriaSwitch.inputProps;
2761
+ var node = props._node;
2762
+ var isDisabled = state.disabledKeys.has(node.key);
2763
+ var isHighlighted = state.selectionManager.isFocused && state.selectionManager.focusedKey === node.key;
2764
+ var ref = useRef(null);
2765
+
2766
+ var _useAriaMenuItem = useMenuItem$1(mergeProps({
2767
+ // We need to merge both the onAction on MenuItem and the onAction
2768
+ // on Menu
2769
+ onAction: onAction
2770
+ }, {
2771
+ onAction: menuProps.onAction,
2772
+ onClose: triggerContext == null ? void 0 : triggerContext.state.close
2773
+ }, {
2774
+ isDisabled: isDisabled,
2775
+ "aria-label": node && node["aria-label"],
2776
+ key: node.key,
2777
+ isVirtualized: false,
2778
+ closeOnSelect: true
2779
+ }), state, ref),
2780
+ menuItemProps = _useAriaMenuItem.menuItemProps,
2781
+ labelProps = _useAriaMenuItem.labelProps;
2968
2782
 
2969
2783
  var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
2970
2784
  def: config.isDisabledVariant,
2971
2785
  active: isDisabled
2972
2786
  }, {
2973
- def: config.isCheckedVariant,
2974
- active: state.isSelected
2975
- }, {
2976
- def: config.noLabelVariant,
2977
- active: !children
2787
+ def: config.isHighlightedVariant,
2788
+ active: isHighlighted
2978
2789
  }));
2979
2790
 
2791
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.labelSlot] = children, _extends2));
2792
+
2980
2793
  var overrides = (_overrides = {}, _overrides[config.root] = {
2981
- as: "label",
2982
- props: mergeProps(getStyleProps(props), {
2983
- ref: rootRef
2984
- }),
2985
- wrapChildren: function wrapChildren(children) {
2986
- return createElement(Fragment, null, createElement(VisuallyHidden, {
2987
- isFocusable: true
2988
- }, createElement("input", Object.assign({}, inputProps, {
2989
- ref: inputRef
2990
- }))), children);
2991
- }
2794
+ as: "li",
2795
+ props: mergeProps(menuItemProps, {
2796
+ ref: ref,
2797
+ style: noOutline()
2798
+ })
2799
+ }, _overrides[config.labelContainer] = {
2800
+ props: _extends({}, labelProps)
2992
2801
  }, _overrides);
2993
-
2994
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.labelSlot ? (_ref = {}, _ref[config.labelSlot] = children, _ref) : {});
2995
-
2996
- var plumeState = useMemo(function () {
2997
- return {
2998
- setChecked: function setChecked(checked) {
2999
- return state.setSelected(checked);
3000
- }
3001
- };
3002
- }, [state]);
3003
- useImperativeHandle(ref, function () {
3004
- return {
3005
- getRoot: function getRoot() {
3006
- return rootRef.current;
3007
- },
3008
- focus: function focus() {
3009
- var _inputRef$current;
3010
-
3011
- return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3012
- },
3013
- blur: function blur() {
3014
- var _inputRef$current2;
3015
-
3016
- return (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
3017
- },
3018
- setChecked: function setChecked(checked) {
3019
- return plumeState.setChecked(checked);
3020
- }
3021
- };
3022
- }, [rootRef, inputRef, plumeState]);
3023
2802
  return {
3024
2803
  plasmicProps: {
3025
2804
  variants: variants,
3026
- overrides: overrides,
3027
- args: args
3028
- },
3029
- state: plumeState
2805
+ args: args,
2806
+ overrides: overrides
2807
+ }
3030
2808
  };
3031
2809
  }
3032
2810
 
3033
- var _excluded$7 = ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"];
3034
- function useTextInput(plasmicClass, props, config, ref) {
3035
- var _ref, _ref2, _overrides;
2811
+ /**
2812
+ * A menu trigger hook that combines react-aria's useMenuTrigger, useAriaMenuTrigger,
2813
+ * useOverlayPosition, useOverlay, and usePress
2814
+ */
3036
2815
 
3037
- if (ref === void 0) {
3038
- ref = null;
3039
- }
2816
+ function useMenuTrigger(opts, state) {
2817
+ var triggerRef = opts.triggerRef,
2818
+ isDisabled = opts.isDisabled,
2819
+ placement = opts.placement,
2820
+ menuMatchTriggerWidth = opts.menuMatchTriggerWidth,
2821
+ menuWidth = opts.menuWidth,
2822
+ menu = opts.menu;
3040
2823
 
3041
- var isDisabled = props.isDisabled,
3042
- startIcon = props.startIcon,
3043
- endIcon = props.endIcon,
3044
- showStartIcon = props.showStartIcon,
3045
- showEndIcon = props.showEndIcon,
3046
- className = props.className,
3047
- style = props.style,
3048
- inputClassName = props.inputClassName,
3049
- inputStyle = props.inputStyle,
3050
- rest = _objectWithoutPropertiesLoose(props, _excluded$7);
2824
+ var _useAriaMenuTrigger = useMenuTrigger$1({
2825
+ type: "menu",
2826
+ isDisabled: isDisabled
2827
+ }, state, triggerRef),
2828
+ triggerPressProps = _useAriaMenuTrigger.menuTriggerProps,
2829
+ menuProps = _useAriaMenuTrigger.menuProps;
3051
2830
 
3052
- var rootRef = useRef(null);
3053
- var inputRef = useRef(null);
3054
- useImperativeHandle(ref, function () {
3055
- return {
3056
- focus: function focus() {
3057
- var _inputRef$current;
2831
+ var _usePress = usePress(_extends({}, triggerPressProps, {
2832
+ isDisabled: isDisabled
2833
+ })),
2834
+ triggerProps = _usePress.pressProps;
3058
2835
 
3059
- (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3060
- },
3061
- blur: function blur() {
3062
- var _inputRef$current2;
2836
+ var makeMenu = function makeMenu() {
2837
+ var realMenu = typeof menu === "function" ? menu() : menu;
3063
2838
 
3064
- (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
3065
- },
3066
- getRoot: function getRoot() {
3067
- return rootRef.current;
3068
- },
3069
- getInput: function getInput() {
3070
- return inputRef.current;
2839
+ if (!realMenu) {
2840
+ return null;
2841
+ }
2842
+
2843
+ if (getPlumeType(realMenu) !== "menu") {
2844
+ if (PLUME_STRICT_MODE) {
2845
+ throw new Error("Must use an instance of the Menu component.");
3071
2846
  }
3072
- };
3073
- }, [rootRef, inputRef]);
3074
2847
 
3075
- var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3076
- def: config.showStartIconVariant,
3077
- active: showStartIcon
3078
- }, {
3079
- def: config.showEndIconVariant,
3080
- active: showEndIcon
3081
- }, {
3082
- def: config.isDisabledVariant,
3083
- active: isDisabled
3084
- }));
2848
+ return null;
2849
+ }
3085
2850
 
3086
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.startIconSlot && (_ref = {}, _ref[config.startIconSlot] = startIcon, _ref), config.endIconSlot && (_ref2 = {}, _ref2[config.endIconSlot] = endIcon, _ref2));
2851
+ return cloneElement(realMenu, mergeProps(realMenu.props, menuProps));
2852
+ };
3087
2853
 
3088
- var overrides = (_overrides = {}, _overrides[config.root] = {
3089
- props: {
3090
- ref: rootRef,
3091
- className: className,
3092
- style: style
3093
- }
3094
- }, _overrides[config.input] = {
3095
- props: _extends({}, omit.apply(void 0, [rest].concat(plasmicClass.internalArgProps.filter(function (prop) {
3096
- return prop !== "required";
3097
- }), plasmicClass.internalVariantProps)), {
3098
- disabled: isDisabled,
3099
- ref: inputRef,
3100
- className: inputClassName,
3101
- style: inputStyle
3102
- })
3103
- }, _overrides);
2854
+ var triggerContext = useMemo(function () {
2855
+ var _state$focusStrategy;
2856
+
2857
+ return {
2858
+ triggerRef: triggerRef,
2859
+ state: state,
2860
+ autoFocus: (_state$focusStrategy = state.focusStrategy) != null ? _state$focusStrategy : true,
2861
+ placement: placement,
2862
+ overlayMatchTriggerWidth: menuMatchTriggerWidth,
2863
+ overlayMinTriggerWidth: true,
2864
+ overlayWidth: menuWidth
2865
+ };
2866
+ }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
3104
2867
  return {
3105
- plasmicProps: {
3106
- variants: variants,
3107
- args: args,
3108
- overrides: overrides
3109
- }
2868
+ triggerProps: triggerProps,
2869
+ makeMenu: makeMenu,
2870
+ triggerContext: triggerContext
3110
2871
  };
3111
2872
  }
3112
2873
 
3113
- function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissable) {
2874
+ function DropdownMenu(props) {
2875
+ var isOpen = props.isOpen,
2876
+ defaultOpen = props.defaultOpen,
2877
+ onOpenChange = props.onOpenChange,
2878
+ children = props.children,
2879
+ placement = props.placement,
2880
+ menu = props.menu;
2881
+ var triggerRef = useRef(null);
2882
+ var state = useMenuTriggerState({
2883
+ isOpen: isOpen,
2884
+ defaultOpen: defaultOpen,
2885
+ onOpenChange: onOpenChange,
2886
+ shouldFlip: true
2887
+ });
2888
+
2889
+ var _useMenuTrigger = useMenuTrigger({
2890
+ triggerRef: triggerRef,
2891
+ placement: placement,
2892
+ menu: menu
2893
+ }, state),
2894
+ triggerProps = _useMenuTrigger.triggerProps,
2895
+ makeMenu = _useMenuTrigger.makeMenu,
2896
+ triggerContext = _useMenuTrigger.triggerContext;
2897
+
2898
+ return createElement(TriggeredOverlayContext.Provider, {
2899
+ value: triggerContext
2900
+ }, cloneElement(children, mergeProps(children.props, triggerProps, {
2901
+ ref: triggerRef
2902
+ })), state.isOpen && makeMenu());
2903
+ }
2904
+
2905
+ function useMenuButton(plasmicClass, props, config, outerRef) {
3114
2906
  var _extends2, _overrides;
3115
2907
 
3116
2908
  if (outerRef === void 0) {
3117
2909
  outerRef = null;
3118
2910
  }
3119
2911
 
3120
- if (isDismissable === void 0) {
3121
- isDismissable = true;
3122
- }
3123
-
3124
- var overlayRef = useRef(null);
3125
- var onOverlayRef = mergeRefs(overlayRef, outerRef);
3126
- var context = useContext(TriggeredOverlayContext);
3127
-
3128
- if (!context) {
3129
- // If no context, then we are not being correctly used. Either complain, or
3130
- // exit early. It's okay to exit early and break the rules of React hooks
3131
- // because we won't suddenly have the appropriate context anyway for this instance.
3132
- if (PLUME_STRICT_MODE) {
3133
- throw new Error("You can only use a triggered overlay with a TriggeredOverlayContext");
3134
- }
3135
-
3136
- return getDefaultPlasmicProps(plasmicClass, props);
3137
- }
3138
-
3139
- var children = props.children;
3140
- var triggerRef = context.triggerRef,
3141
- placement = context.placement,
3142
- overlayMatchTriggerWidth = context.overlayMatchTriggerWidth,
3143
- overlayMinTriggerWidth = context.overlayMinTriggerWidth,
3144
- overlayWidth = context.overlayWidth,
3145
- state = context.state; // Measure the width of the trigger to inform the width of the menu (below).
3146
-
3147
- var _React$useState = useState(false),
3148
- isRendered = _React$useState[0],
3149
- setRendered = _React$useState[1];
3150
-
3151
- var triggerWidth = triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth) ? triggerRef.current.offsetWidth : undefined;
3152
- useIsomorphicLayoutEffect(function () {
3153
- if (!isRendered && triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)) {
3154
- setRendered(true);
3155
- }
3156
- }, [triggerRef, isRendered, overlayMatchTriggerWidth, overlayMinTriggerWidth]);
3157
-
3158
- var _useOverlay = useOverlay({
3159
- isOpen: state.isOpen,
3160
- onClose: state.close,
3161
- isDismissable: isDismissable,
3162
- shouldCloseOnBlur: true
3163
- }, overlayRef),
3164
- overlayAriaProps = _useOverlay.overlayProps;
2912
+ var placement = props.placement,
2913
+ isOpen = props.isOpen,
2914
+ defaultOpen = props.defaultOpen,
2915
+ onOpenChange = props.onOpenChange,
2916
+ isDisabled = props.isDisabled,
2917
+ menu = props.menu,
2918
+ autoFocus = props.autoFocus,
2919
+ menuMatchTriggerWidth = props.menuMatchTriggerWidth,
2920
+ menuWidth = props.menuWidth;
2921
+ useEnsureSSRProvider();
2922
+ var rootRef = useRef(null);
2923
+ var triggerRef = useRef(null);
2924
+ var state = useMenuTriggerState({
2925
+ isOpen: isOpen,
2926
+ defaultOpen: defaultOpen,
2927
+ onOpenChange: onOpenChange,
2928
+ shouldFlip: true
2929
+ });
3165
2930
 
3166
- var _useOverlayPosition = useOverlayPosition({
3167
- targetRef: triggerRef,
3168
- overlayRef: overlayRef,
3169
- placement: placement != null ? placement : "bottom left",
3170
- shouldFlip: true,
3171
- isOpen: state.isOpen,
3172
- onClose: state.close,
3173
- containerPadding: 0
3174
- }),
3175
- overlayPositionProps = _useOverlayPosition.overlayProps,
3176
- updatePosition = _useOverlayPosition.updatePosition,
3177
- placementAxis = _useOverlayPosition.placement;
2931
+ var _useMenuTrigger = useMenuTrigger({
2932
+ isDisabled: isDisabled,
2933
+ triggerRef: triggerRef,
2934
+ placement: placement,
2935
+ menuMatchTriggerWidth: menuMatchTriggerWidth,
2936
+ menuWidth: menuWidth,
2937
+ menu: menu
2938
+ }, state),
2939
+ triggerProps = _useMenuTrigger.triggerProps,
2940
+ makeMenu = _useMenuTrigger.makeMenu,
2941
+ triggerContext = _useMenuTrigger.triggerContext;
3178
2942
 
3179
- useIsomorphicLayoutEffect(function () {
3180
- if (state.isOpen) {
3181
- requestAnimationFrame(function () {
3182
- updatePosition();
3183
- });
3184
- }
3185
- }, [state.isOpen, updatePosition]);
3186
- var overlayProps = mergeProps({
3187
- style: {
3188
- left: "auto",
3189
- right: "auto",
3190
- top: "auto",
3191
- bottom: "auto",
3192
- position: "absolute",
3193
- width: overlayWidth != null ? overlayWidth : overlayMatchTriggerWidth ? triggerWidth : "auto",
3194
- minWidth: overlayMinTriggerWidth ? triggerWidth : "auto"
3195
- }
3196
- }, overlayAriaProps, overlayPositionProps);
2943
+ var _useFocusable = useFocusable(props, triggerRef),
2944
+ triggerFocusProps = _useFocusable.focusableProps;
3197
2945
 
3198
2946
  var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3199
- def: config.isPlacedTopVariant,
3200
- active: placementAxis === "top"
3201
- }, {
3202
- def: config.isPlacedBottomVariant,
3203
- active: placementAxis === "bottom"
3204
- }, {
3205
- def: config.isPlacedLeftVariant,
3206
- active: placementAxis === "left"
2947
+ def: config.isOpenVariant,
2948
+ active: state.isOpen
3207
2949
  }, {
3208
- def: config.isPlacedRightVariant,
3209
- active: placementAxis === "right"
2950
+ def: config.isDisabledVariant,
2951
+ active: isDisabled
3210
2952
  }));
3211
2953
 
3212
- var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.contentSlot] = createElement(FocusScope, {
3213
- restoreFocus: true
3214
- }, createElement(DismissButton, {
3215
- onDismiss: state.close
3216
- }), children), _extends2));
2954
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.menuSlot] = state.isOpen ? makeMenu() : undefined, _extends2));
3217
2955
 
3218
2956
  var overrides = (_overrides = {}, _overrides[config.root] = {
3219
- props: mergeProps(overlayProps, getStyleProps(props), {
3220
- ref: onOverlayRef
3221
- }),
3222
- wrap: function wrap(root) {
3223
- if (typeof document !== "undefined") {
3224
- return createPortal(root, document.body);
3225
- } else {
3226
- // Possibly being invoked on the server during SSR; no need to
3227
- // bother with a portal in that case.
3228
- return root;
3229
- }
2957
+ wrapChildren: function wrapChildren(children) {
2958
+ return createElement(TriggeredOverlayContext.Provider, {
2959
+ value: triggerContext
2960
+ }, children);
2961
+ },
2962
+ props: {
2963
+ ref: rootRef
3230
2964
  }
2965
+ }, _overrides[config.trigger] = {
2966
+ props: mergeProps(triggerProps, triggerFocusProps, getStyleProps(props), pick(props, "title"), {
2967
+ ref: triggerRef,
2968
+ autoFocus: autoFocus,
2969
+ disabled: !!isDisabled,
2970
+ // Make sure this button is not interpreted as submit
2971
+ type: "button"
2972
+ })
3231
2973
  }, _overrides);
2974
+ var plumeState = useMemo(function () {
2975
+ return {
2976
+ open: function open() {
2977
+ return state.open();
2978
+ },
2979
+ close: function close() {
2980
+ return state.close();
2981
+ },
2982
+ isOpen: function isOpen() {
2983
+ return state.isOpen;
2984
+ }
2985
+ };
2986
+ }, [state]);
2987
+ useImperativeHandle(outerRef, function () {
2988
+ return {
2989
+ getRoot: function getRoot() {
2990
+ return rootRef.current;
2991
+ },
2992
+ getTrigger: function getTrigger() {
2993
+ return triggerRef.current;
2994
+ },
2995
+ focus: function focus() {
2996
+ return triggerRef.current && triggerRef.current.focus();
2997
+ },
2998
+ blur: function blur() {
2999
+ return triggerRef.current && triggerRef.current.blur();
3000
+ },
3001
+ open: plumeState.open,
3002
+ close: plumeState.close,
3003
+ isOpen: plumeState.isOpen
3004
+ };
3005
+ }, [rootRef, triggerRef, plumeState]);
3232
3006
  return {
3233
3007
  plasmicProps: {
3234
3008
  variants: variants,
3235
3009
  args: args,
3236
3010
  overrides: overrides
3237
- }
3011
+ },
3012
+ state: plumeState
3238
3013
  };
3239
3014
  }
3240
3015
 
3241
- function generateStateOnChangeProp($state, stateName, dataReps) {
3242
- return function (val, path) {
3243
- return set($state, [stateName].concat(dataReps, path), val);
3244
- };
3245
- }
3246
- /**
3247
- * This function generate the state value prop for repeated states
3248
- * Example:
3249
- * - parent[][].counter[].count
3250
- * We need to pass `parent[index1][index2].counter to the child component
3251
- */
3016
+ var SelectContext = /*#__PURE__*/createContext(undefined);
3252
3017
 
3253
- function generateStateValueProp($state, path // ["parent", 0, 1, "counter"]
3254
- ) {
3255
- return _get($state, path);
3256
- }
3018
+ var _excluded$6 = ["value", "defaultValue", "children", "onChange", "placement", "menuMatchTriggerWidth", "menuWidth"];
3019
+ var COLLECTION_OPTS$1 = {
3020
+ itemPlumeType: "select-option",
3021
+ sectionPlumeType: "select-option-group"
3022
+ };
3257
3023
  /**
3258
- * Forked from https://github.com/lukeed/dset
3259
- * Changes: fixed setting a deep value to a proxy object
3024
+ * Converts props in our BaseSelectProps into props that react-aria's
3025
+ * useSelect() understands.
3026
+ *
3027
+ * Because we're not exposing the Collections API (see ./index.tsx),
3028
+ * we are converting our own API into props for useSelect.
3029
+ *
3030
+ * Specifically, in Plume's API,
3031
+ * - `children` flattens to a list of ReactElements of type Select.Option
3032
+ * or Select.OptionGroup
3033
+ *
3034
+ * and we map it this way to the Collections API:
3035
+ * - `items` is a list of those flattened ReactElements from `children`!
3036
+ * - `children`, as a render prop, is supposed to take one of the `items`
3037
+ * and return a `Section` or `Item` element. We take an Option/OptionGroup
3038
+ * element, and use its props to render the appropriate `Section` or
3039
+ * `Item`. The "trick" here is that we then stuff the Option element as
3040
+ * `Item.children`, and the OptionGroup element as `Section.title`.
3041
+ *
3042
+ * When the Collections API does its work deriving `Node`s, the corresponding
3043
+ * Option/OptionGroup ReactElements will end up as `Node.rendered`.
3044
+ *
3045
+ * Then, when we are actually rendering the content of the dropdown, we
3046
+ * iterate through each collected `Node`, and renders
3047
+ * React.cloneElement(Node.rendered, {_node: node}). This "secretly" passes
3048
+ * the derived collection `Node` as a prop to Option and OptionGroup, and they
3049
+ * can make use of the derived `Node.key` etc in their rendering functions.
3050
+ *
3051
+ * One thing to note here is that we never "rendered" the Option/OptionGroup
3052
+ * React elements that the user constructed; instead, we just looked at the
3053
+ * props used on those elements, and passed those onto the Collections API.
3054
+ * What gets rendered to the screen is the cloned version of these elements
3055
+ * with the secret derived `_node` prop. That means Option and OptionGroup
3056
+ * render functions can assume that _node is passed in.
3260
3057
  */
3261
3058
 
3262
- function set(obj, keys, val) {
3263
- keys = keys.split ? keys.split(".") : keys;
3264
- var i = 0,
3265
- l = keys.length,
3266
- t = obj,
3267
- x,
3268
- k;
3059
+ function useAriaSelectProps(props) {
3060
+ var value = props.value,
3061
+ defaultValue = props.defaultValue,
3062
+ children = props.children,
3063
+ onChange = props.onChange,
3064
+ rest = _objectWithoutPropertiesLoose(props, _excluded$6);
3269
3065
 
3270
- while (i < l) {
3271
- k = keys[i++];
3272
- if (k === "__proto__" || k === "constructor" || k === "prototype") break;
3066
+ var _useDerivedItemsFromC = useDerivedItemsFromChildren(children, _extends({}, COLLECTION_OPTS$1, {
3067
+ invalidChildError: "Can only use Select.Option and Select.OptionGroup as children to Select",
3068
+ requireItemValue: true
3069
+ })),
3070
+ items = _useDerivedItemsFromC.items,
3071
+ disabledKeys = _useDerivedItemsFromC.disabledKeys;
3273
3072
 
3274
- if (i === l) {
3275
- t[k] = val;
3276
- t = t[k];
3277
- } else {
3278
- if (typeof (x = t[k]) === typeof keys) {
3279
- t = t[k] = x;
3280
- } else if (keys[i] * 0 !== 0 || !!~("" + keys[i]).indexOf(".")) {
3281
- t[k] = {};
3282
- t = t[k];
3283
- } else {
3284
- t[k] = [];
3285
- t = t[k];
3286
- }
3073
+ var collectionChildRenderer = useCallback(function (child) {
3074
+ return renderAsCollectionChild(child, COLLECTION_OPTS$1);
3075
+ }, []);
3076
+ var onSelectionChange = useMemo(function () {
3077
+ if (onChange) {
3078
+ return function (val) {
3079
+ return onChange(val == null || val === "null" ? null : val);
3080
+ };
3081
+ } else {
3082
+ return undefined;
3287
3083
  }
3288
- }
3084
+ }, [onChange]);
3085
+ return {
3086
+ ariaProps: _extends({}, rest, {
3087
+ children: collectionChildRenderer,
3088
+ onSelectionChange: onSelectionChange,
3089
+ items: items,
3090
+ disabledKeys: disabledKeys,
3091
+ defaultSelectedKey: defaultValue
3092
+ }, "value" in props && {
3093
+ selectedKey: value != null ? value : null
3094
+ })
3095
+ };
3289
3096
  }
3290
3097
 
3291
- var mkUntrackedValue = function mkUntrackedValue(o) {
3292
- return typeof o === "object" ? ref(o) : o;
3293
- };
3098
+ function useSelect(plasmicClass, props, config, ref) {
3099
+ var _overrides, _extends2;
3294
3100
 
3295
- var transformPathStringToObj = function transformPathStringToObj(str) {
3296
- var splitStatePathPart = function splitStatePathPart(state) {
3297
- return state.endsWith("[]") ? [].concat(splitStatePathPart(state.slice(0, -2)), ["[]"]) : [state];
3298
- };
3101
+ if (ref === void 0) {
3102
+ ref = null;
3103
+ }
3299
3104
 
3300
- return str.split(".").flatMap(splitStatePathPart);
3301
- };
3105
+ useEnsureSSRProvider();
3302
3106
 
3303
- function shallowEqual(a1, a2) {
3304
- if (a1.length !== a2.length) {
3305
- return false;
3306
- }
3107
+ var _useAriaSelectProps = useAriaSelectProps(props),
3108
+ ariaProps = _useAriaSelectProps.ariaProps;
3307
3109
 
3308
- for (var i = 0; i < a1.length; i++) {
3309
- if (a1[i] !== a2[i]) {
3310
- return false;
3311
- }
3312
- }
3110
+ var placement = props.placement;
3111
+ var state = useSelectState(ariaProps);
3112
+ var triggerRef = useRef(null);
3113
+ var rootRef = useRef(null);
3114
+ var isDisabled = props.isDisabled,
3115
+ name = props.name,
3116
+ menuWidth = props.menuWidth,
3117
+ menuMatchTriggerWidth = props.menuMatchTriggerWidth,
3118
+ autoFocus = props.autoFocus,
3119
+ placeholder = props.placeholder,
3120
+ selectedContent = props.selectedContent;
3313
3121
 
3314
- return true;
3315
- }
3122
+ var _useAriaSelect = useSelect$1(ariaProps, state, triggerRef),
3123
+ triggerPressProps = _useAriaSelect.triggerProps,
3124
+ menuProps = _useAriaSelect.menuProps;
3316
3125
 
3317
- function isNum(value) {
3318
- return typeof value === "symbol" ? false : !isNaN(+value);
3319
- }
3126
+ var _usePress = usePress(_extends({}, triggerPressProps, {
3127
+ isDisabled: isDisabled
3128
+ })),
3129
+ triggerProps = _usePress.pressProps;
3320
3130
 
3321
- function saveNewState($$state, path, spec) {
3322
- var key = JSON.stringify(path);
3323
- $$state.existingStates.set(key, {
3324
- path: path,
3325
- specKey: spec.path
3326
- });
3131
+ var triggerContent = state.selectedItem ? selectedContent != null ? selectedContent : getChildProp(state.selectedItem.value, "children") : null;
3327
3132
 
3328
- if (!$$state.statesInstanceBySpec.has(spec.path)) {
3329
- $$state.statesInstanceBySpec.set(spec.path, []);
3330
- }
3133
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3134
+ def: config.isOpenVariant,
3135
+ active: state.isOpen
3136
+ }, {
3137
+ def: config.placeholderVariant,
3138
+ active: !state.selectedItem
3139
+ }, {
3140
+ def: config.isDisabledVariant,
3141
+ active: isDisabled
3142
+ }));
3331
3143
 
3332
- $$state.statesInstanceBySpec.get(spec.path).push({
3333
- path: path,
3334
- specKey: spec.path
3335
- });
3336
- }
3144
+ var triggerContext = useMemo(function () {
3145
+ return {
3146
+ triggerRef: triggerRef,
3147
+ state: state,
3148
+ placement: placement,
3149
+ overlayMatchTriggerWidth: menuMatchTriggerWidth,
3150
+ overlayMinTriggerWidth: true,
3151
+ overlayWidth: menuWidth
3152
+ };
3153
+ }, [triggerRef, state, placement, menuMatchTriggerWidth, menuWidth]);
3154
+ var overrides = (_overrides = {}, _overrides[config.root] = {
3155
+ props: mergeProps(getStyleProps(props), {
3156
+ ref: rootRef
3157
+ }),
3158
+ wrapChildren: function wrapChildren(children) {
3159
+ return createElement(Fragment, null, createElement(HiddenSelect, {
3160
+ state: state,
3161
+ triggerRef: triggerRef,
3162
+ name: name,
3163
+ isDisabled: isDisabled
3164
+ }), children);
3165
+ }
3166
+ }, _overrides[config.trigger] = {
3167
+ props: mergeProps(triggerProps, {
3168
+ ref: triggerRef,
3169
+ autoFocus: autoFocus,
3170
+ disabled: !!isDisabled,
3171
+ // Don't trigger form submission!
3172
+ type: "button"
3173
+ })
3174
+ }, _overrides[config.overlay] = {
3175
+ wrap: function wrap(content) {
3176
+ return createElement(TriggeredOverlayContext.Provider, {
3177
+ value: triggerContext
3178
+ }, content);
3179
+ }
3180
+ }, _overrides[config.optionsContainer] = {
3181
+ wrap: function wrap(content) {
3182
+ return createElement(ListBoxWrapper, {
3183
+ state: state,
3184
+ menuProps: menuProps
3185
+ }, content);
3186
+ }
3187
+ }, _overrides);
3337
3188
 
3338
- function create$StateProxy($$state, handlers) {
3339
- var getNextKeyToSpecMap = function getNextKeyToSpecMap(currPath) {
3340
- return new Map(Object.entries(Object.values($$state.specsByKey).filter(function (spec) {
3341
- return shallowEqual(currPath.map(function (p) {
3342
- return isNum(p) ? "[]" : p;
3343
- }), spec.pathObj.slice(0, currPath.length));
3344
- }).reduce(function (agg, spec) {
3345
- var nextKey = spec.pathObj[currPath.length];
3189
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.triggerContentSlot] = triggerContent, _extends2[config.placeholderSlot] = placeholder, _extends2[config.optionsSlot] = createElement(SelectContext.Provider, {
3190
+ value: state
3191
+ }, Array.from(state.collection).map(function (node) {
3192
+ return renderCollectionNode(node);
3193
+ })), _extends2));
3346
3194
 
3347
- if (!(nextKey in agg)) {
3348
- agg[nextKey] = [];
3195
+ var plumeState = useMemo(function () {
3196
+ return {
3197
+ open: function open() {
3198
+ return state.open();
3199
+ },
3200
+ close: function close() {
3201
+ return state.close();
3202
+ },
3203
+ isOpen: function isOpen() {
3204
+ return state.isOpen;
3205
+ },
3206
+ getSelectedValue: function getSelectedValue() {
3207
+ return state.selectedKey ? "" + state.selectedKey : null;
3208
+ },
3209
+ setSelectedValue: function setSelectedValue(key) {
3210
+ return state.setSelectedKey(key);
3349
3211
  }
3212
+ };
3213
+ }, [state]);
3214
+ useImperativeHandle(ref, function () {
3215
+ return {
3216
+ getRoot: function getRoot() {
3217
+ return rootRef.current;
3218
+ },
3219
+ getTrigger: function getTrigger() {
3220
+ return triggerRef.current;
3221
+ },
3222
+ focus: function focus() {
3223
+ var _triggerRef$current;
3350
3224
 
3351
- agg[nextKey].push(spec);
3352
- return agg;
3353
- }, {})));
3225
+ return (_triggerRef$current = triggerRef.current) == null ? void 0 : _triggerRef$current.focus();
3226
+ },
3227
+ blur: function blur() {
3228
+ var _triggerRef$current2;
3229
+
3230
+ return (_triggerRef$current2 = triggerRef.current) == null ? void 0 : _triggerRef$current2.blur();
3231
+ },
3232
+ open: function open() {
3233
+ return plumeState.open();
3234
+ },
3235
+ close: function close() {
3236
+ return plumeState.close();
3237
+ },
3238
+ isOpen: function isOpen() {
3239
+ return plumeState.isOpen();
3240
+ },
3241
+ getSelectedValue: function getSelectedValue() {
3242
+ return plumeState.getSelectedValue();
3243
+ },
3244
+ setSelectedValue: function setSelectedValue(key) {
3245
+ return plumeState.setSelectedValue(key);
3246
+ }
3247
+ };
3248
+ }, [rootRef, triggerRef, plumeState]);
3249
+ return {
3250
+ plasmicProps: {
3251
+ variants: variants,
3252
+ args: args,
3253
+ overrides: overrides
3254
+ },
3255
+ state: plumeState
3354
3256
  };
3257
+ }
3355
3258
 
3356
- var rec = function rec(currPath) {
3357
- var nextKeyToSpecs = getNextKeyToSpecMap(currPath);
3259
+ function ListBoxWrapper(props) {
3260
+ var state = props.state,
3261
+ menuProps = props.menuProps,
3262
+ children = props.children;
3263
+ var ref = useRef(null);
3358
3264
 
3359
- var getSpecForProperty = function getSpecForProperty(property) {
3360
- var _nextKeyToSpecs$get, _nextKeyToSpecs$get2;
3265
+ var _useListBox = useListBox(_extends({}, menuProps, {
3266
+ isVirtualized: false,
3267
+ autoFocus: state.focusStrategy || true,
3268
+ disallowEmptySelection: true
3269
+ }), state, ref),
3270
+ listBoxProps = _useListBox.listBoxProps;
3361
3271
 
3362
- 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;
3363
- };
3272
+ return cloneElement(children, mergeProps(children.props, listBoxProps, {
3273
+ style: noOutline(),
3274
+ ref: ref
3275
+ }));
3276
+ }
3364
3277
 
3365
- var getNextPath = function getNextPath(property) {
3366
- return [].concat(currPath, [isNum(property) ? +property : property]);
3367
- };
3278
+ function useSelectOption(plasmicClass, props, config, outerRef) {
3279
+ var _extends2, _overrides;
3368
3280
 
3369
- return new Proxy(nextKeyToSpecs.has("[]") ? [] : {}, {
3370
- deleteProperty: function deleteProperty(target, property) {
3371
- var prefixPath = getNextPath(property);
3372
- var specKeysToUpdate = new Set();
3373
- $$state.existingStates.forEach(function (_ref) {
3374
- var path = _ref.path,
3375
- specKey = _ref.specKey;
3281
+ if (outerRef === void 0) {
3282
+ outerRef = null;
3283
+ }
3376
3284
 
3377
- if (path.length >= prefixPath.length && shallowEqual(path.slice(0, prefixPath.length), prefixPath)) {
3378
- deleteState($$state, path);
3379
- specKeysToUpdate.add(specKey);
3380
- }
3381
- });
3382
- specKeysToUpdate.forEach(function (specKey) {
3383
- var spec = $$state.specsByKey[specKey];
3285
+ var state = useContext(SelectContext);
3384
3286
 
3385
- if (spec.onChangeProp) {
3386
- var _$$state$props$spec$o, _$$state$props;
3287
+ if (!state) {
3288
+ // If no context, then we are being incorrectly used. Complain or just don't
3289
+ // bother installing any hooks. It's okay to violate rules of hooks here
3290
+ // because this instance won't suddenly be used correctly in another render.
3291
+ if (PLUME_STRICT_MODE) {
3292
+ throw new Error("You can only use a Select.Option within a Select component.");
3293
+ }
3387
3294
 
3388
- (_$$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);
3389
- }
3390
- });
3391
- return Reflect.deleteProperty(target, property);
3392
- },
3393
- get: function get(target, property, receiver) {
3394
- var spec = getSpecForProperty(property);
3295
+ return getDefaultPlasmicProps(plasmicClass, props);
3296
+ }
3395
3297
 
3396
- if (spec && typeof property !== "symbol") {
3397
- var nextPath = getNextPath(property);
3298
+ var children = props.children;
3299
+ var rootRef = useRef(null);
3300
+ var onRef = mergeRefs(rootRef, outerRef); // We pass in the Node secretly as an undocumented prop from <Select />
3398
3301
 
3399
- if (spec.pathObj.length === currPath.length + 1) {
3400
- var _handlers$get, _handlers;
3302
+ var node = props._node;
3303
+ var isSelected = state.selectionManager.isSelected(node.key);
3304
+ var isDisabled = state.disabledKeys.has(node.key);
3305
+ var isHighlighted = state.selectionManager.isFocused && state.selectionManager.focusedKey === node.key;
3401
3306
 
3402
- // reached the end of the spec
3403
- target[property] = (_handlers$get = (_handlers = handlers(nextPath, spec)).get) == null ? void 0 : _handlers$get.call(_handlers, target, property, receiver);
3404
- } else if (!(property in target)) {
3405
- target[property] = rec(nextPath);
3406
- }
3407
- }
3307
+ var _useAriaOption = useOption({
3308
+ isSelected: isSelected,
3309
+ isDisabled: isDisabled,
3310
+ "aria-label": node && node["aria-label"],
3311
+ key: node.key,
3312
+ shouldSelectOnPressUp: true,
3313
+ shouldFocusOnHover: true,
3314
+ isVirtualized: false
3315
+ }, state, rootRef),
3316
+ optionProps = _useAriaOption.optionProps,
3317
+ labelProps = _useAriaOption.labelProps;
3408
3318
 
3409
- return Reflect.get(target, property, receiver);
3410
- },
3411
- set: function set$1(target, property, value, receiver) {
3412
- var spec = getSpecForProperty(property);
3413
- var nextPath = getNextPath(property);
3319
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3320
+ def: config.isSelectedVariant,
3321
+ active: isSelected
3322
+ }, {
3323
+ def: config.isDisabledVariant,
3324
+ active: isDisabled
3325
+ }, {
3326
+ def: config.isHighlightedVariant,
3327
+ active: isHighlighted
3328
+ }));
3414
3329
 
3415
- if (spec && typeof property !== "symbol") {
3416
- if (spec.pathObj.length === currPath.length + 1) {
3417
- var _handlers$set, _handlers2;
3330
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.labelSlot] = children, _extends2));
3418
3331
 
3419
- // reached the end of the spec
3420
- target[property] = (_handlers$set = (_handlers2 = handlers(nextPath, spec)).set) == null ? void 0 : _handlers$set.call(_handlers2, target, property, value, receiver);
3421
- return Reflect.set(target, property, value, receiver);
3422
- } else if (typeof value === "object") {
3423
- target[property] = rec(nextPath);
3332
+ var overrides = (_overrides = {}, _overrides[config.root] = {
3333
+ props: mergeProps(optionProps, getStyleProps(props), {
3334
+ ref: onRef,
3335
+ style: noOutline()
3336
+ })
3337
+ }, _overrides[config.labelContainer] = {
3338
+ props: labelProps
3339
+ }, _overrides);
3340
+ return {
3341
+ plasmicProps: {
3342
+ variants: variants,
3343
+ args: args,
3344
+ overrides: overrides
3345
+ }
3346
+ };
3347
+ }
3424
3348
 
3425
- for (var _i = 0, _Object$keys = Object.keys(value); _i < _Object$keys.length; _i++) {
3426
- var key = _Object$keys[_i];
3427
- target[property][key] = value[key];
3428
- }
3349
+ function useSelectOptionGroup(plasmicClass, props, config) {
3350
+ var _extends2, _overrides;
3429
3351
 
3430
- return true;
3431
- }
3432
- }
3352
+ var state = useContext(SelectContext); // `node` should exist if the OptionGroup was instantiated properly
3353
+ // within a Select
3433
3354
 
3434
- if (property === "registerInitFunc" && currPath.length === 0) {
3435
- return Reflect.set(target, property, value, receiver);
3436
- }
3355
+ var node = props._node;
3437
3356
 
3438
- if (nextKeyToSpecs.has("[]")) {
3439
- var _nextKeyToSpecs$get3;
3357
+ if (!state || !node) {
3358
+ if (PLUME_STRICT_MODE) {
3359
+ throw new Error("You can only use a Select.OptionGroup within a Select component.");
3360
+ }
3440
3361
 
3441
- set($$state.stateValues, nextPath, value);
3362
+ return getDefaultPlasmicProps(plasmicClass, props);
3363
+ }
3442
3364
 
3443
- (_nextKeyToSpecs$get3 = nextKeyToSpecs.get("[]")) == null ? void 0 : _nextKeyToSpecs$get3.forEach(function (spec) {
3444
- if (spec != null && spec.onChangeProp) {
3445
- var _$$state$props$spec$o2, _$$state$props2;
3365
+ var _useListBoxSection = useListBoxSection({
3366
+ heading: props.title,
3367
+ "aria-label": props["aria-label"]
3368
+ }),
3369
+ headingProps = _useListBoxSection.headingProps,
3370
+ groupProps = _useListBoxSection.groupProps;
3446
3371
 
3447
- (_$$state$props$spec$o2 = (_$$state$props2 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o2.call(_$$state$props2, value, nextPath);
3448
- }
3449
- });
3450
- return Reflect.set(target, property, value, receiver);
3451
- } // invalid setting a value that doesn't make part of the spec
3372
+ var _useSeparator = useSeparator({
3373
+ elementType: "li"
3374
+ }),
3375
+ separatorProps = _useSeparator.separatorProps;
3452
3376
 
3377
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3378
+ def: config.noTitleVariant,
3379
+ active: !props.title
3380
+ }, {
3381
+ def: config.isFirstVariant,
3382
+ active: state.collection.getFirstKey() === node.key
3383
+ }));
3453
3384
 
3454
- return false;
3455
- }
3456
- });
3457
- };
3385
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.titleSlot] = props.title, _extends2[config.optionsSlot] = Array.from(node.childNodes).map(function (childNode) {
3386
+ return renderCollectionNode(childNode);
3387
+ }), _extends2));
3458
3388
 
3459
- return rec([]);
3389
+ var overrides = (_overrides = {}, _overrides[config.root] = {
3390
+ props: getStyleProps(props)
3391
+ }, _overrides[config.separator] = {
3392
+ props: _extends({}, separatorProps)
3393
+ }, _overrides[config.titleContainer] = _extends({
3394
+ props: _extends({
3395
+ role: "presentation"
3396
+ }, headingProps)
3397
+ }, !props.title && {
3398
+ render: function render() {
3399
+ return null;
3400
+ }
3401
+ }), _overrides[config.optionsContainer] = {
3402
+ props: _extends({}, groupProps)
3403
+ }, _overrides);
3404
+ return {
3405
+ plasmicProps: {
3406
+ variants: variants,
3407
+ args: args,
3408
+ overrides: overrides
3409
+ }
3410
+ };
3460
3411
  }
3461
3412
 
3462
- var deleteState = function deleteState($$state, path) {
3463
- var _$$state$unsubscripti;
3464
-
3465
- var key = JSON.stringify(path);
3466
- (_$$state$unsubscripti = $$state.unsubscriptionsByState[key]) == null ? void 0 : _$$state$unsubscripti.forEach(function (f) {
3467
- return f();
3413
+ function asAriaSwitchProps(props) {
3414
+ var ariaProps = _extends({}, props, {
3415
+ isSelected: props.isChecked,
3416
+ defaultSelected: props.defaultChecked
3468
3417
  });
3469
- delete $$state.unsubscriptionsByState[key];
3470
- $$state.existingStates["delete"](key); // delete get($$state.stateValues, path.slice(-1))[path.slice(-1)[0]];
3471
- // delete get($$state.initStateValues, path.slice(-1))[path.slice(-1)[0]];
3472
- };
3473
3418
 
3474
- var getIndexes = function getIndexes(path, spec) {
3475
- var indexes = [];
3419
+ delete ariaProps["isChecked"];
3420
+ delete ariaProps["defaultChecked"];
3421
+ return ariaProps;
3422
+ }
3476
3423
 
3477
- if (path.length !== spec.pathObj.length) {
3478
- throw new Error("Unexpected error: state path and spec path have different lengths");
3479
- }
3424
+ function useSwitch(plasmicClass, props, config, ref) {
3425
+ var _overrides, _ref;
3480
3426
 
3481
- for (var i = 0; i < spec.pathObj.length; i++) {
3482
- if (spec.pathObj[i] === "[]") {
3483
- indexes.push(path[i]);
3484
- }
3427
+ if (ref === void 0) {
3428
+ ref = null;
3485
3429
  }
3486
3430
 
3487
- return indexes;
3488
- };
3489
-
3490
- function initializeStateValue($$state, initialStatePath, initialSpec) {
3491
- var _$$state$unsubscripti2;
3492
-
3493
- var initialStateKey = JSON.stringify(initialStatePath);
3494
- var stateAccess = new Set();
3495
- var $state = create$StateProxy($$state, function (path, spec) {
3496
- return {
3497
- get: function get() {
3498
- var key = JSON.stringify(path);
3499
- stateAccess.add({
3500
- path: path,
3501
- spec: spec
3502
- });
3431
+ var children = props.children,
3432
+ isDisabled = props.isDisabled;
3433
+ useEnsureSSRProvider();
3434
+ var inputRef = useRef(null);
3435
+ var rootRef = useRef(null);
3436
+ var ariaProps = asAriaSwitchProps(props);
3437
+ var state = useToggleState(ariaProps);
3503
3438
 
3504
- if (spec.valueProp) {
3505
- return !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
3506
- }
3439
+ var _useAriaSwitch = useSwitch$1(ariaProps, state, inputRef),
3440
+ inputProps = _useAriaSwitch.inputProps;
3507
3441
 
3508
- if ($$state.existingStates.has(key)) {
3509
- // is already initialized
3510
- return _get($$state.stateValues, path);
3511
- } else if (spec.initFunc) {
3512
- initializeStateValue($$state, path, spec);
3513
- }
3442
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3443
+ def: config.isDisabledVariant,
3444
+ active: isDisabled
3445
+ }, {
3446
+ def: config.isCheckedVariant,
3447
+ active: state.isSelected
3448
+ }, {
3449
+ def: config.noLabelVariant,
3450
+ active: !children
3451
+ }));
3514
3452
 
3515
- return _get($$state.stateValues, path);
3516
- },
3517
- set: function set() {
3518
- throw new Error("Cannot update state values during initialization");
3453
+ var overrides = (_overrides = {}, _overrides[config.root] = {
3454
+ as: "label",
3455
+ props: mergeProps(getStyleProps(props), {
3456
+ ref: rootRef
3457
+ }),
3458
+ wrapChildren: function wrapChildren(children) {
3459
+ return createElement(Fragment, null, createElement(VisuallyHidden, {
3460
+ isFocusable: true
3461
+ }, createElement("input", Object.assign({}, inputProps, {
3462
+ ref: inputRef
3463
+ }))), children);
3464
+ }
3465
+ }, _overrides);
3466
+
3467
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.labelSlot ? (_ref = {}, _ref[config.labelSlot] = children, _ref) : {});
3468
+
3469
+ var plumeState = useMemo(function () {
3470
+ return {
3471
+ setChecked: function setChecked(checked) {
3472
+ return state.setSelected(checked);
3519
3473
  }
3520
3474
  };
3521
- });
3522
- (_$$state$unsubscripti2 = $$state.unsubscriptionsByState[initialStateKey]) == null ? void 0 : _$$state$unsubscripti2.forEach(function (f) {
3523
- return f();
3524
- });
3525
- $$state.unsubscriptionsByState[initialStateKey] = [];
3526
- stateAccess.forEach(function (_ref2) {
3527
- var path = _ref2.path,
3528
- spec = _ref2.spec;
3529
- var unsubscribe = subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
3530
- return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(path, spec))));
3531
- });
3532
- $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
3533
- });
3534
- var untrackedInitialValue = mkUntrackedValue(initialSpec.initFunc($$state.props, $state, getIndexes(initialStatePath, initialSpec)));
3535
-
3536
- set($$state.initStateValues, initialStatePath, untrackedInitialValue);
3475
+ }, [state]);
3476
+ useImperativeHandle(ref, function () {
3477
+ return {
3478
+ getRoot: function getRoot() {
3479
+ return rootRef.current;
3480
+ },
3481
+ focus: function focus() {
3482
+ var _inputRef$current;
3537
3483
 
3538
- set($$state.stateValues, initialStatePath, untrackedInitialValue);
3484
+ return (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3485
+ },
3486
+ blur: function blur() {
3487
+ var _inputRef$current2;
3539
3488
 
3540
- return untrackedInitialValue;
3489
+ return (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
3490
+ },
3491
+ setChecked: function setChecked(checked) {
3492
+ return plumeState.setChecked(checked);
3493
+ }
3494
+ };
3495
+ }, [rootRef, inputRef, plumeState]);
3496
+ return {
3497
+ plasmicProps: {
3498
+ variants: variants,
3499
+ overrides: overrides,
3500
+ args: args
3501
+ },
3502
+ state: plumeState
3503
+ };
3541
3504
  }
3542
3505
 
3543
- function useDollarState(specs, props) {
3544
- var $$state = React__default.useRef(proxy({
3545
- stateValues: {},
3546
- initStateValues: {},
3547
- specsByKey: Object.fromEntries(specs.map(function (spec) {
3548
- return [spec.path, _extends({}, spec, {
3549
- pathObj: transformPathStringToObj(spec.path),
3550
- isRepeated: spec.path.split(".").some(function (part) {
3551
- return part.endsWith("[]");
3552
- })
3553
- })];
3554
- })),
3555
- statesInstanceBySpec: new Map(),
3556
- existingStates: new Map(),
3557
- unsubscriptionsByState: {},
3558
- props: undefined,
3559
- registrationsQueue: []
3560
- })).current;
3561
- $$state.props = mkUntrackedValue(props);
3562
- var $state = React__default.useRef(Object.assign(create$StateProxy($$state, function (path, spec) {
3563
- var key = JSON.stringify(path);
3564
-
3565
- if (!$$state.existingStates.has(key)) {
3566
- var _spec$initVal;
3567
-
3568
- saveNewState($$state, path, spec);
3569
- var untrackedValue = !spec.initFunc ? mkUntrackedValue((_spec$initVal = spec.initVal) != null ? _spec$initVal : undefined) : initializeStateValue($$state, path, spec);
3506
+ var _excluded$7 = ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"];
3507
+ function useTextInput(plasmicClass, props, config, ref) {
3508
+ var _ref, _ref2, _overrides;
3570
3509
 
3571
- set($$state.stateValues, path, untrackedValue);
3510
+ if (ref === void 0) {
3511
+ ref = null;
3512
+ }
3572
3513
 
3573
- set($$state.initStateValues, path, untrackedValue);
3574
- }
3514
+ var isDisabled = props.isDisabled,
3515
+ startIcon = props.startIcon,
3516
+ endIcon = props.endIcon,
3517
+ showStartIcon = props.showStartIcon,
3518
+ showEndIcon = props.showEndIcon,
3519
+ className = props.className,
3520
+ style = props.style,
3521
+ inputClassName = props.inputClassName,
3522
+ inputStyle = props.inputStyle,
3523
+ rest = _objectWithoutPropertiesLoose(props, _excluded$7);
3575
3524
 
3525
+ var rootRef = useRef(null);
3526
+ var inputRef = useRef(null);
3527
+ useImperativeHandle(ref, function () {
3576
3528
  return {
3577
- get: function get() {
3578
- if (spec.valueProp) {
3579
- var value = !spec.isRepeated ? $$state.props[spec.valueProp] : _get($$state.props[spec.valueProp], path.slice(1));
3580
- return value;
3581
- } else {
3582
- return _get($$state.stateValues, path);
3583
- }
3584
- },
3585
- set: function set$1(_t, _p, value) {
3586
- set($$state.stateValues, path, mkUntrackedValue(value));
3587
-
3588
- if (spec.onChangeProp) {
3589
- var _$$state$props$spec$o3, _$$state$props3;
3529
+ focus: function focus() {
3530
+ var _inputRef$current;
3590
3531
 
3591
- (_$$state$props$spec$o3 = (_$$state$props3 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o3.call(_$$state$props3, value, path);
3592
- }
3532
+ (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3533
+ },
3534
+ blur: function blur() {
3535
+ var _inputRef$current2;
3593
3536
 
3594
- return true;
3537
+ (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.blur();
3538
+ },
3539
+ getRoot: function getRoot() {
3540
+ return rootRef.current;
3541
+ },
3542
+ getInput: function getInput() {
3543
+ return inputRef.current;
3595
3544
  }
3596
3545
  };
3597
- }), {
3598
- registerInitFunc: function registerInitFunc(pathStr, f) {
3599
- var _$$state$statesInstan;
3546
+ }, [rootRef, inputRef]);
3600
3547
 
3601
- if ((_$$state$statesInstan = $$state.statesInstanceBySpec.get(pathStr)) != null && _$$state$statesInstan.some(function (_ref3) {
3602
- var path = _ref3.path,
3603
- specKey = _ref3.specKey;
3604
- return !deepEqual(_get($$state.initStateValues, path), f(props, $state, getIndexes(path, $$state.specsByKey[specKey])));
3605
- })) {
3606
- $$state.registrationsQueue.push({
3607
- pathStr: pathStr,
3608
- f: f
3609
- });
3610
- }
3548
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3549
+ def: config.showStartIconVariant,
3550
+ active: showStartIcon
3551
+ }, {
3552
+ def: config.showEndIconVariant,
3553
+ active: showEndIcon
3554
+ }, {
3555
+ def: config.isDisabledVariant,
3556
+ active: isDisabled
3557
+ }));
3558
+
3559
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), config.startIconSlot && (_ref = {}, _ref[config.startIconSlot] = startIcon, _ref), config.endIconSlot && (_ref2 = {}, _ref2[config.endIconSlot] = endIcon, _ref2));
3560
+
3561
+ var overrides = (_overrides = {}, _overrides[config.root] = {
3562
+ props: {
3563
+ ref: rootRef,
3564
+ className: className,
3565
+ style: style
3611
3566
  }
3612
- })).current; // For each spec with an initFunc, evaluate it and see if
3613
- // the init value has changed. If so, reset its state.
3567
+ }, _overrides[config.input] = {
3568
+ props: _extends({}, omit.apply(void 0, [rest].concat(plasmicClass.internalArgProps.filter(function (prop) {
3569
+ return prop !== "required";
3570
+ }), plasmicClass.internalVariantProps)), {
3571
+ disabled: isDisabled,
3572
+ ref: inputRef,
3573
+ className: inputClassName,
3574
+ style: inputStyle
3575
+ })
3576
+ }, _overrides);
3577
+ return {
3578
+ plasmicProps: {
3579
+ variants: variants,
3580
+ args: args,
3581
+ overrides: overrides
3582
+ }
3583
+ };
3584
+ }
3614
3585
 
3615
- var resetSpecs = [];
3616
- $$state.existingStates.forEach(function (_ref4) {
3617
- var path = _ref4.path,
3618
- specKey = _ref4.specKey;
3619
- var spec = $$state.specsByKey[specKey];
3586
+ function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissable) {
3587
+ var _extends2, _overrides;
3620
3588
 
3621
- if (spec.initFunc) {
3622
- var newInit = spec.initFunc(props, $state, getIndexes(path, spec));
3589
+ if (outerRef === void 0) {
3590
+ outerRef = null;
3591
+ }
3623
3592
 
3624
- if (!deepEqual(newInit, _get($$state.initStateValues, path))) {
3625
- resetSpecs.push({
3626
- path: path,
3627
- spec: spec
3628
- });
3629
- }
3593
+ if (isDismissable === void 0) {
3594
+ isDismissable = true;
3595
+ }
3596
+
3597
+ var overlayRef = useRef(null);
3598
+ var onOverlayRef = mergeRefs(overlayRef, outerRef);
3599
+ var context = useContext(TriggeredOverlayContext);
3600
+
3601
+ if (!context) {
3602
+ // If no context, then we are not being correctly used. Either complain, or
3603
+ // exit early. It's okay to exit early and break the rules of React hooks
3604
+ // because we won't suddenly have the appropriate context anyway for this instance.
3605
+ if (PLUME_STRICT_MODE) {
3606
+ throw new Error("You can only use a triggered overlay with a TriggeredOverlayContext");
3630
3607
  }
3631
- });
3632
- React__default.useLayoutEffect(function () {
3633
- resetSpecs.forEach(function (_ref5) {
3634
- var path = _ref5.path,
3635
- spec = _ref5.spec;
3636
- var newInit = initializeStateValue($$state, path, spec);
3637
3608
 
3638
- if (spec.onChangeProp) {
3639
- var _$$state$props$spec$o4, _$$state$props4;
3609
+ return getDefaultPlasmicProps(plasmicClass, props);
3610
+ }
3640
3611
 
3641
- (_$$state$props$spec$o4 = (_$$state$props4 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o4.call(_$$state$props4, newInit, path);
3642
- }
3643
- });
3644
- }, [props, resetSpecs]);
3645
- React__default.useLayoutEffect(function () {
3646
- $$state.registrationsQueue.forEach(function (_ref6) {
3647
- var f = _ref6.f,
3648
- pathStr = _ref6.pathStr;
3649
- $$state.specsByKey[pathStr].initFunc = f;
3650
- });
3651
- $$state.registrationsQueue = [];
3652
- }, [$$state.registrationsQueue]); // Re-render if any value changed in one of these objects
3612
+ var children = props.children;
3613
+ var triggerRef = context.triggerRef,
3614
+ placement = context.placement,
3615
+ overlayMatchTriggerWidth = context.overlayMatchTriggerWidth,
3616
+ overlayMinTriggerWidth = context.overlayMinTriggerWidth,
3617
+ overlayWidth = context.overlayWidth,
3618
+ state = context.state; // Measure the width of the trigger to inform the width of the menu (below).
3653
3619
 
3654
- useSnapshot($$state.stateValues, {
3655
- sync: true
3656
- });
3657
- useSnapshot($$state.specsByKey, {
3658
- sync: true
3659
- });
3660
- return $state;
3661
- }
3620
+ var _React$useState = useState(false),
3621
+ isRendered = _React$useState[0],
3622
+ setRendered = _React$useState[1];
3662
3623
 
3663
- function useCanvasDollarState(specs, props) {
3664
- var $$state = proxy({
3665
- stateValues: {},
3666
- initStateValues: {},
3667
- specsByKey: Object.fromEntries(specs.map(function (spec) {
3668
- return [spec.path, _extends({}, spec, {
3669
- pathObj: transformPathStringToObj(spec.path),
3670
- isRepeated: spec.path.split(".").some(function (part) {
3671
- return part.endsWith("[]");
3672
- })
3673
- })];
3674
- })),
3675
- statesInstanceBySpec: new Map(),
3676
- existingStates: new Map(),
3677
- unsubscriptionsByState: {},
3678
- props: undefined,
3679
- registrationsQueue: []
3680
- });
3681
- $$state.props = mkUntrackedValue(props);
3682
- var $state = create$StateProxy($$state, function (path, spec) {
3683
- return {
3684
- get: function get() {
3685
- return _get($$state.stateValues, path);
3686
- },
3687
- set: function set$1(_t, _p, value) {
3688
- set($$state.stateValues, path, mkUntrackedValue(value));
3624
+ var triggerWidth = triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth) ? triggerRef.current.offsetWidth : undefined;
3625
+ useIsomorphicLayoutEffect(function () {
3626
+ if (!isRendered && triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)) {
3627
+ setRendered(true);
3628
+ }
3629
+ }, [triggerRef, isRendered, overlayMatchTriggerWidth, overlayMinTriggerWidth]);
3689
3630
 
3690
- if (spec.onChangeProp) {
3691
- var _$$state$props$spec$o5, _$$state$props5;
3631
+ var _useOverlay = useOverlay({
3632
+ isOpen: state.isOpen,
3633
+ onClose: state.close,
3634
+ isDismissable: isDismissable,
3635
+ shouldCloseOnBlur: true
3636
+ }, overlayRef),
3637
+ overlayAriaProps = _useOverlay.overlayProps;
3692
3638
 
3693
- (_$$state$props$spec$o5 = (_$$state$props5 = $$state.props)[spec.onChangeProp]) == null ? void 0 : _$$state$props$spec$o5.call(_$$state$props5, value, path);
3694
- }
3639
+ var _useOverlayPosition = useOverlayPosition({
3640
+ targetRef: triggerRef,
3641
+ overlayRef: overlayRef,
3642
+ placement: placement != null ? placement : "bottom left",
3643
+ shouldFlip: true,
3644
+ isOpen: state.isOpen,
3645
+ onClose: state.close,
3646
+ containerPadding: 0
3647
+ }),
3648
+ overlayPositionProps = _useOverlayPosition.overlayProps,
3649
+ updatePosition = _useOverlayPosition.updatePosition,
3650
+ placementAxis = _useOverlayPosition.placement;
3695
3651
 
3696
- return true;
3697
- }
3698
- };
3699
- });
3652
+ useIsomorphicLayoutEffect(function () {
3653
+ if (state.isOpen) {
3654
+ requestAnimationFrame(function () {
3655
+ updatePosition();
3656
+ });
3657
+ }
3658
+ }, [state.isOpen, updatePosition]);
3659
+ var overlayProps = mergeProps({
3660
+ style: {
3661
+ left: "auto",
3662
+ right: "auto",
3663
+ top: "auto",
3664
+ bottom: "auto",
3665
+ position: "absolute",
3666
+ width: overlayWidth != null ? overlayWidth : overlayMatchTriggerWidth ? triggerWidth : "auto",
3667
+ minWidth: overlayMinTriggerWidth ? triggerWidth : "auto"
3668
+ }
3669
+ }, overlayAriaProps, overlayPositionProps);
3700
3670
 
3701
- for (var _iterator = _createForOfIteratorHelperLoose(specs), _step; !(_step = _iterator()).done;) {
3702
- var spec = _step.value;
3703
- var path = transformPathStringToObj(spec.path);
3704
- var init = spec.valueProp ? $$state.props[spec.valueProp] : spec.initVal ? spec.initVal : spec.initFunc ? initializeStateValue($$state, path, $$state.specsByKey[spec.path]) : undefined;
3671
+ var variants = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalVariantProps)), mergeVariantToggles({
3672
+ def: config.isPlacedTopVariant,
3673
+ active: placementAxis === "top"
3674
+ }, {
3675
+ def: config.isPlacedBottomVariant,
3676
+ active: placementAxis === "bottom"
3677
+ }, {
3678
+ def: config.isPlacedLeftVariant,
3679
+ active: placementAxis === "left"
3680
+ }, {
3681
+ def: config.isPlacedRightVariant,
3682
+ active: placementAxis === "right"
3683
+ }));
3705
3684
 
3706
- set($state, path, init);
3707
- }
3685
+ var args = _extends({}, pick.apply(void 0, [props].concat(plasmicClass.internalArgProps)), (_extends2 = {}, _extends2[config.contentSlot] = createElement(FocusScope, {
3686
+ restoreFocus: true
3687
+ }, createElement(DismissButton, {
3688
+ onDismiss: state.close
3689
+ }), children), _extends2));
3708
3690
 
3709
- return $state;
3691
+ var overrides = (_overrides = {}, _overrides[config.root] = {
3692
+ props: mergeProps(overlayProps, getStyleProps(props), {
3693
+ ref: onOverlayRef
3694
+ }),
3695
+ wrap: function wrap(root) {
3696
+ if (typeof document !== "undefined") {
3697
+ return createPortal(root, document.body);
3698
+ } else {
3699
+ // Possibly being invoked on the server during SSR; no need to
3700
+ // bother with a portal in that case.
3701
+ return root;
3702
+ }
3703
+ }
3704
+ }, _overrides);
3705
+ return {
3706
+ plasmicProps: {
3707
+ variants: variants,
3708
+ args: args,
3709
+ overrides: overrides
3710
+ }
3711
+ };
3710
3712
  }
3711
3713
 
3712
3714
  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, useMenu, useMenuButton, useMenuGroup, useMenuItem, useSelect, useSelectOption, useSelectOptionGroup, useSwitch, useTextInput, useTrigger, useTriggeredOverlay, wrapWithClassName };