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