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