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