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