@auth0/quantum-product 2.10.2 → 2.10.4
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/command-palette/command-palette-classes.d.ts +5 -0
- package/command-palette/command-palette-classes.js +34 -0
- package/command-palette/command-palette-context.d.ts +8 -0
- package/command-palette/command-palette-context.js +93 -0
- package/command-palette/command-palette-dialog.d.ts +3 -0
- package/command-palette/command-palette-dialog.js +112 -0
- package/command-palette/command-palette-empty.d.ts +3 -0
- package/command-palette/command-palette-empty.js +90 -0
- package/command-palette/command-palette-footer.d.ts +4 -0
- package/command-palette/command-palette-footer.js +111 -0
- package/command-palette/command-palette-group.d.ts +3 -0
- package/command-palette/command-palette-group.js +119 -0
- package/command-palette/command-palette-input.d.ts +3 -0
- package/command-palette/command-palette-input.js +144 -0
- package/command-palette/command-palette-item.d.ts +3 -0
- package/command-palette/command-palette-item.js +243 -0
- package/command-palette/command-palette-list.d.ts +3 -0
- package/command-palette/command-palette-list.js +101 -0
- package/command-palette/command-palette-loading.d.ts +3 -0
- package/command-palette/command-palette-loading.js +89 -0
- package/command-palette/command-palette-score.d.ts +1 -0
- package/command-palette/command-palette-score.js +47 -0
- package/command-palette/command-palette-separator.d.ts +3 -0
- package/command-palette/command-palette-separator.js +86 -0
- package/command-palette/command-palette-tabs.d.ts +4 -0
- package/command-palette/command-palette-tabs.js +146 -0
- package/command-palette/command-palette-types.d.ts +121 -0
- package/command-palette/command-palette-types.js +2 -0
- package/command-palette/command-palette.d.ts +5 -0
- package/command-palette/command-palette.js +477 -0
- package/command-palette/index.d.ts +27 -0
- package/command-palette/index.js +36 -0
- package/command-palette/use-command-palette-shortcut.d.ts +6 -0
- package/command-palette/use-command-palette-shortcut.js +65 -0
- package/esm/command-palette/command-palette-classes.js +30 -0
- package/esm/command-palette/command-palette-context.js +54 -0
- package/esm/command-palette/command-palette-dialog.js +73 -0
- package/esm/command-palette/command-palette-empty.js +51 -0
- package/esm/command-palette/command-palette-footer.js +72 -0
- package/esm/command-palette/command-palette-group.js +80 -0
- package/esm/command-palette/command-palette-input.js +105 -0
- package/esm/command-palette/command-palette-item.js +204 -0
- package/esm/command-palette/command-palette-list.js +62 -0
- package/esm/command-palette/command-palette-loading.js +50 -0
- package/esm/command-palette/command-palette-score.js +44 -0
- package/esm/command-palette/command-palette-separator.js +47 -0
- package/esm/command-palette/command-palette-tabs.js +107 -0
- package/esm/command-palette/command-palette-types.js +1 -0
- package/esm/command-palette/command-palette.js +438 -0
- package/esm/command-palette/index.js +14 -0
- package/esm/command-palette/use-command-palette-shortcut.js +29 -0
- package/esm/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
import * as React from 'react';
|
|
18
|
+
export var CommandPaletteContext = React.createContext(undefined);
|
|
19
|
+
export var CommandPaletteStoreContext = React.createContext(undefined);
|
|
20
|
+
export var CommandPaletteGroupContext = React.createContext(undefined);
|
|
21
|
+
export function useCommandPaletteContext() {
|
|
22
|
+
var context = React.useContext(CommandPaletteContext);
|
|
23
|
+
if (!context) {
|
|
24
|
+
throw new Error('useCommandPaletteContext must be used within a CommandPalette');
|
|
25
|
+
}
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
export function useCommandPaletteStore() {
|
|
29
|
+
var store = React.useContext(CommandPaletteStoreContext);
|
|
30
|
+
if (!store) {
|
|
31
|
+
throw new Error('useCommandPaletteStore must be used within a CommandPalette');
|
|
32
|
+
}
|
|
33
|
+
return store;
|
|
34
|
+
}
|
|
35
|
+
export function useCommandPaletteState(selector) {
|
|
36
|
+
var store = useCommandPaletteStore();
|
|
37
|
+
var selectorRef = React.useRef(selector);
|
|
38
|
+
var _a = __read(React.useState(function () { return selector(store.snapshot()); }), 2), state = _a[0], setState = _a[1];
|
|
39
|
+
React.useEffect(function () {
|
|
40
|
+
selectorRef.current = selector;
|
|
41
|
+
setState(selector(store.snapshot()));
|
|
42
|
+
}, [selector, store]);
|
|
43
|
+
React.useLayoutEffect(function () {
|
|
44
|
+
var unsubscribe = store.subscribe(function () {
|
|
45
|
+
setState(function (prevSelected) {
|
|
46
|
+
var nextSelected = selectorRef.current(store.snapshot());
|
|
47
|
+
return Object.is(prevSelected, nextSelected) ? prevSelected : nextSelected;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return unsubscribe;
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, [store]);
|
|
53
|
+
return state;
|
|
54
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
import MuiDialog from '@mui/material/Dialog';
|
|
25
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
26
|
+
import { styled } from '../styled';
|
|
27
|
+
import clsx from '../utils/clsx';
|
|
28
|
+
import { CommandPalette } from './command-palette';
|
|
29
|
+
import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
|
|
30
|
+
var StyledDialog = styled(MuiDialog, {
|
|
31
|
+
name: commandPaletteComponentName,
|
|
32
|
+
slot: 'Dialog',
|
|
33
|
+
})(function (_a) {
|
|
34
|
+
var theme = _a.theme;
|
|
35
|
+
return ({
|
|
36
|
+
'& .MuiDialog-container': {
|
|
37
|
+
alignItems: 'flex-start',
|
|
38
|
+
paddingTop: '15vh',
|
|
39
|
+
},
|
|
40
|
+
'& .MuiDialog-paper': {
|
|
41
|
+
margin: 0,
|
|
42
|
+
maxWidth: 640,
|
|
43
|
+
width: '100%',
|
|
44
|
+
borderRadius: theme.spacing(2),
|
|
45
|
+
overflow: 'hidden',
|
|
46
|
+
backgroundColor: theme.tokens.color_bg_layer_elevated,
|
|
47
|
+
border: "1px solid ".concat(theme.tokens.color_border_default),
|
|
48
|
+
boxShadow: "0px 33px 80px rgba(0, 0, 0, 0.12),\n 0px 13.7866px 33.4221px rgba(0, 0, 0, 0.086),\n 0px 7.37098px 17.869px rgba(0, 0, 0, 0.07),\n 0px 4.13211px 10.0172px rgba(0, 0, 0, 0.06),\n 0px 2.19453px 5.32008px rgba(0, 0, 0, 0.048),\n 0px 0.913195px 2.21381px rgba(0, 0, 0, 0.034)",
|
|
49
|
+
},
|
|
50
|
+
'& .MuiBackdrop-root': {
|
|
51
|
+
backgroundColor: 'rgba(0, 0, 0, 0.4)',
|
|
52
|
+
backdropFilter: 'blur(4px)',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
export var CommandPaletteDialog = React.forwardRef(function (props, ref) {
|
|
57
|
+
var _a = props.open, open = _a === void 0 ? false : _a, onOpenChange = props.onOpenChange, overlayProps = props.overlayProps, contentProps = props.contentProps, children = props.children, className = props.className, commandPaletteProps = __rest(props, ["open", "onOpenChange", "overlayProps", "contentProps", "children", "className"]);
|
|
58
|
+
var paletteRef = React.useRef(null);
|
|
59
|
+
var handleRef = useForkRef(ref, paletteRef);
|
|
60
|
+
var handleEntered = React.useCallback(function () {
|
|
61
|
+
requestAnimationFrame(function () {
|
|
62
|
+
var _a;
|
|
63
|
+
var input = (_a = paletteRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(commandPaletteClasses.input));
|
|
64
|
+
input === null || input === void 0 ? void 0 : input.focus();
|
|
65
|
+
});
|
|
66
|
+
}, []);
|
|
67
|
+
var handleClose = React.useCallback(function () {
|
|
68
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(false);
|
|
69
|
+
}, [onOpenChange]);
|
|
70
|
+
return (React.createElement(StyledDialog, { open: open, onClose: handleClose, TransitionProps: { onEntered: handleEntered }, className: clsx(commandPaletteClasses.dialog, className), maxWidth: false, BackdropProps: overlayProps, PaperProps: contentProps },
|
|
71
|
+
React.createElement(CommandPalette, __assign({ ref: handleRef }, commandPaletteProps), children)));
|
|
72
|
+
});
|
|
73
|
+
CommandPaletteDialog.displayName = 'CommandPaletteDialog';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
import { styled } from '../styled';
|
|
25
|
+
import clsx from '../utils/clsx';
|
|
26
|
+
import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
|
|
27
|
+
import { useCommandPaletteState } from './command-palette-context';
|
|
28
|
+
var Root = styled('div', {
|
|
29
|
+
name: commandPaletteComponentName,
|
|
30
|
+
slot: 'Empty',
|
|
31
|
+
})(function (_a) {
|
|
32
|
+
var theme = _a.theme;
|
|
33
|
+
return ({
|
|
34
|
+
display: 'flex',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
justifyContent: 'center',
|
|
37
|
+
padding: theme.spacing(6, 2),
|
|
38
|
+
color: theme.tokens.color_fg_disabled,
|
|
39
|
+
fontSize: theme.typography.body2.fontSize,
|
|
40
|
+
userSelect: 'none',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
export var CommandPaletteEmpty = React.forwardRef(function (props, ref) {
|
|
44
|
+
var _a = props.children, children = _a === void 0 ? 'No results found.' : _a, className = props.className, emptyProps = __rest(props, ["children", "className"]);
|
|
45
|
+
var filteredCount = useCommandPaletteState(function (state) { return state.filtered.count; });
|
|
46
|
+
var isSearching = useCommandPaletteState(function (state) { return state.search.length > 0; });
|
|
47
|
+
if (!isSearching || filteredCount > 0)
|
|
48
|
+
return null;
|
|
49
|
+
return (React.createElement(Root, __assign({ ref: ref, role: "presentation", className: clsx(commandPaletteClasses.empty, className) }, emptyProps), children));
|
|
50
|
+
});
|
|
51
|
+
CommandPaletteEmpty.displayName = 'CommandPaletteEmpty';
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
import { styled } from '../styled';
|
|
25
|
+
import clsx from '../utils/clsx';
|
|
26
|
+
import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
|
|
27
|
+
var Root = styled('div', {
|
|
28
|
+
name: commandPaletteComponentName,
|
|
29
|
+
slot: 'Footer',
|
|
30
|
+
})(function (_a) {
|
|
31
|
+
var theme = _a.theme;
|
|
32
|
+
return ({
|
|
33
|
+
display: 'flex',
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'flex-end',
|
|
36
|
+
gap: theme.spacing(2),
|
|
37
|
+
padding: "".concat(theme.spacing(1), " ").concat(theme.spacing(2)),
|
|
38
|
+
color: theme.tokens.color_fg_disabled,
|
|
39
|
+
fontSize: theme.typography.caption.fontSize,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
var Kbd = styled('kbd', {
|
|
43
|
+
name: commandPaletteComponentName,
|
|
44
|
+
slot: 'FooterKbd',
|
|
45
|
+
})(function (_a) {
|
|
46
|
+
var theme = _a.theme;
|
|
47
|
+
return ({
|
|
48
|
+
display: 'inline-flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
minWidth: theme.typography.pxToRem(20),
|
|
52
|
+
height: theme.typography.pxToRem(20),
|
|
53
|
+
padding: "0 ".concat(theme.spacing(0.5)),
|
|
54
|
+
borderRadius: theme.spacing(0.5),
|
|
55
|
+
backgroundColor: theme.tokens.color_bg_state_neutral_subtle,
|
|
56
|
+
border: "1px solid ".concat(theme.tokens.color_border_default),
|
|
57
|
+
color: theme.tokens.color_fg_disabled,
|
|
58
|
+
fontSize: theme.typography.caption.fontSize,
|
|
59
|
+
fontFamily: theme.typography.caption.fontFamily,
|
|
60
|
+
lineHeight: theme.typography.caption.lineHeight,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
export var CommandPaletteFooter = React.forwardRef(function (props, ref) {
|
|
64
|
+
var children = props.children, className = props.className, footerProps = __rest(props, ["children", "className"]);
|
|
65
|
+
return (React.createElement(Root, __assign({ ref: ref, className: clsx(commandPaletteClasses.footer, className) }, footerProps), children));
|
|
66
|
+
});
|
|
67
|
+
CommandPaletteFooter.displayName = 'CommandPaletteFooter';
|
|
68
|
+
export var CommandPaletteShortcutKey = React.forwardRef(function (props, ref) {
|
|
69
|
+
var children = props.children, className = props.className, kbdProps = __rest(props, ["children", "className"]);
|
|
70
|
+
return (React.createElement(Kbd, __assign({ ref: ref, className: clsx(commandPaletteClasses.kbd, className) }, kbdProps), children));
|
|
71
|
+
});
|
|
72
|
+
CommandPaletteShortcutKey.displayName = 'CommandPaletteShortcutKey';
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
import { styled } from '../styled';
|
|
25
|
+
import clsx from '../utils/clsx';
|
|
26
|
+
import { useId } from '../utils/use-id';
|
|
27
|
+
import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
|
|
28
|
+
import { CommandPaletteGroupContext, useCommandPaletteContext, useCommandPaletteState, } from './command-palette-context';
|
|
29
|
+
var Root = styled('div', {
|
|
30
|
+
name: commandPaletteComponentName,
|
|
31
|
+
slot: 'Group',
|
|
32
|
+
})(function (_a) {
|
|
33
|
+
var theme = _a.theme;
|
|
34
|
+
return ({
|
|
35
|
+
padding: theme.spacing(0.5, 1),
|
|
36
|
+
outline: 'none',
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var Heading = styled('div', {
|
|
40
|
+
name: commandPaletteComponentName,
|
|
41
|
+
slot: 'GroupHeading',
|
|
42
|
+
})(function (_a) {
|
|
43
|
+
var theme = _a.theme;
|
|
44
|
+
return ({
|
|
45
|
+
padding: "".concat(theme.spacing(1), " ").concat(theme.spacing(1.5)),
|
|
46
|
+
fontSize: theme.typography.overline.fontSize,
|
|
47
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
48
|
+
color: theme.tokens.color_fg_disabled,
|
|
49
|
+
textTransform: 'uppercase',
|
|
50
|
+
letterSpacing: '0.05em',
|
|
51
|
+
userSelect: 'none',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
var Items = styled('div', {
|
|
55
|
+
name: commandPaletteComponentName,
|
|
56
|
+
slot: 'GroupItems',
|
|
57
|
+
})(function () { return ({
|
|
58
|
+
outline: 'none',
|
|
59
|
+
}); });
|
|
60
|
+
export var CommandPaletteGroup = React.forwardRef(function (props, ref) {
|
|
61
|
+
var heading = props.heading, _a = props.forceMount, forceMount = _a === void 0 ? false : _a, children = props.children, className = props.className, groupProps = __rest(props, ["heading", "forceMount", "children", "className"]);
|
|
62
|
+
var id = useId() || '';
|
|
63
|
+
var headingId = "".concat(id, "-heading");
|
|
64
|
+
var context = useCommandPaletteContext();
|
|
65
|
+
React.useLayoutEffect(function () {
|
|
66
|
+
var cleanup = context.group(id);
|
|
67
|
+
return cleanup;
|
|
68
|
+
}, [context, id]);
|
|
69
|
+
var filteredState = useCommandPaletteState(function (state) { return state.filtered; });
|
|
70
|
+
var search = useCommandPaletteState(function (state) { return state.search; });
|
|
71
|
+
var groupCount = filteredState.groups.get(id);
|
|
72
|
+
var isVisible = forceMount || context.filter === false || !search || (groupCount !== undefined && groupCount > 0);
|
|
73
|
+
if (!isVisible)
|
|
74
|
+
return null;
|
|
75
|
+
return (React.createElement(Root, __assign({ ref: ref, className: clsx(commandPaletteClasses.group, className), role: "presentation" }, groupProps),
|
|
76
|
+
heading && (React.createElement(Heading, { id: headingId, className: commandPaletteClasses.groupHeading, "aria-hidden": true }, heading)),
|
|
77
|
+
React.createElement(CommandPaletteGroupContext.Provider, { value: id },
|
|
78
|
+
React.createElement(Items, { role: "group", className: commandPaletteClasses.groupItems, "aria-labelledby": heading ? headingId : undefined }, children))));
|
|
79
|
+
});
|
|
80
|
+
CommandPaletteGroup.displayName = 'CommandPaletteGroup';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
import { SearchIcon } from '../icon';
|
|
25
|
+
import { styled } from '../styled';
|
|
26
|
+
import clsx from '../utils/clsx';
|
|
27
|
+
import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
|
|
28
|
+
import { useCommandPaletteContext, useCommandPaletteState, useCommandPaletteStore } from './command-palette-context';
|
|
29
|
+
var Wrapper = styled('div', {
|
|
30
|
+
name: commandPaletteComponentName,
|
|
31
|
+
slot: 'InputWrapper',
|
|
32
|
+
})(function (_a) {
|
|
33
|
+
var theme = _a.theme;
|
|
34
|
+
return ({
|
|
35
|
+
display: 'flex',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
gap: theme.spacing(1.5),
|
|
38
|
+
padding: "".concat(theme.spacing(1.5), " ").concat(theme.spacing(2)),
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
var IconWrapper = styled('div', {
|
|
42
|
+
name: commandPaletteComponentName,
|
|
43
|
+
slot: 'InputIcon',
|
|
44
|
+
})(function (_a) {
|
|
45
|
+
var theme = _a.theme;
|
|
46
|
+
return ({
|
|
47
|
+
display: 'flex',
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
justifyContent: 'center',
|
|
50
|
+
flexShrink: 0,
|
|
51
|
+
color: theme.tokens.color_fg_disabled,
|
|
52
|
+
'& svg': {
|
|
53
|
+
width: theme.typography.pxToRem(20),
|
|
54
|
+
height: theme.typography.pxToRem(20),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
var InputElement = styled('input', {
|
|
59
|
+
name: commandPaletteComponentName,
|
|
60
|
+
slot: 'Input',
|
|
61
|
+
})(function (_a) {
|
|
62
|
+
var theme = _a.theme;
|
|
63
|
+
return ({
|
|
64
|
+
flex: 1,
|
|
65
|
+
border: 'none',
|
|
66
|
+
outline: 'none',
|
|
67
|
+
backgroundColor: 'transparent',
|
|
68
|
+
color: theme.tokens.color_fg_default,
|
|
69
|
+
fontSize: theme.typography.body1.fontSize,
|
|
70
|
+
lineHeight: theme.typography.body1.lineHeight,
|
|
71
|
+
fontFamily: theme.typography.fontFamily,
|
|
72
|
+
caretColor: theme.tokens.color_fg_brand_primary,
|
|
73
|
+
'&::placeholder': {
|
|
74
|
+
color: theme.tokens.color_fg_disabled,
|
|
75
|
+
},
|
|
76
|
+
width: '100%',
|
|
77
|
+
padding: 0,
|
|
78
|
+
margin: 0,
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
export var CommandPaletteInput = React.forwardRef(function (props, ref) {
|
|
82
|
+
var _a = props.icon, icon = _a === void 0 ? React.createElement(SearchIcon, { size: 20 }) : _a, _b = props.placeholder, placeholder = _b === void 0 ? 'Search for commands...' : _b, onValueChange = props.onValueChange, className = props.className, inputProps = __rest(props, ["icon", "placeholder", "onValueChange", "className"]);
|
|
83
|
+
var context = useCommandPaletteContext();
|
|
84
|
+
var store = useCommandPaletteStore();
|
|
85
|
+
var search = useCommandPaletteState(function (state) { return state.search; });
|
|
86
|
+
var isComposing = React.useRef(false);
|
|
87
|
+
var handleChange = React.useCallback(function (e) {
|
|
88
|
+
if (!isComposing.current) {
|
|
89
|
+
store.setState('search', e.target.value);
|
|
90
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(e.target.value);
|
|
91
|
+
}
|
|
92
|
+
}, [store, onValueChange]);
|
|
93
|
+
var handleCompositionStart = React.useCallback(function () {
|
|
94
|
+
isComposing.current = true;
|
|
95
|
+
}, []);
|
|
96
|
+
var handleCompositionEnd = React.useCallback(function (e) {
|
|
97
|
+
isComposing.current = false;
|
|
98
|
+
store.setState('search', e.target.value);
|
|
99
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(e.target.value);
|
|
100
|
+
}, [store, onValueChange]);
|
|
101
|
+
return (React.createElement(Wrapper, { className: clsx(commandPaletteClasses.inputWrapper, className) },
|
|
102
|
+
icon && React.createElement(IconWrapper, { className: commandPaletteClasses.inputIcon }, icon),
|
|
103
|
+
React.createElement(InputElement, __assign({ ref: ref, id: context.inputId, className: commandPaletteClasses.input, type: "text", role: "combobox", "aria-expanded": true, "aria-controls": context.listId, "aria-label": placeholder, "aria-autocomplete": "list", autoComplete: "off", autoCorrect: "off", spellCheck: false, placeholder: placeholder, value: search, onChange: handleChange, onCompositionStart: handleCompositionStart, onCompositionEnd: handleCompositionEnd }, inputProps))));
|
|
104
|
+
});
|
|
105
|
+
CommandPaletteInput.displayName = 'CommandPaletteInput';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
24
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
25
|
+
if (!m) return o;
|
|
26
|
+
var i = m.call(o), r, ar = [], e;
|
|
27
|
+
try {
|
|
28
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
29
|
+
}
|
|
30
|
+
catch (error) { e = { error: error }; }
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
34
|
+
}
|
|
35
|
+
finally { if (e) throw e.error; }
|
|
36
|
+
}
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
40
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
+
ar[i] = from[i];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
|
+
};
|
|
48
|
+
import * as React from 'react';
|
|
49
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
50
|
+
import { styled } from '../styled';
|
|
51
|
+
import clsx from '../utils/clsx';
|
|
52
|
+
import { useId } from '../utils/use-id';
|
|
53
|
+
import { VALUE_ATTR } from './command-palette';
|
|
54
|
+
import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
|
|
55
|
+
import { CommandPaletteGroupContext, useCommandPaletteContext, useCommandPaletteState, useCommandPaletteStore, } from './command-palette-context';
|
|
56
|
+
var Root = styled('div', {
|
|
57
|
+
name: commandPaletteComponentName,
|
|
58
|
+
slot: 'Item',
|
|
59
|
+
})(function (_a) {
|
|
60
|
+
var theme = _a.theme, ownerState = _a.ownerState;
|
|
61
|
+
return (__assign(__assign(__assign(__assign({ display: 'flex', alignItems: 'center', gap: theme.spacing(1.5), padding: "".concat(theme.spacing(1), " ").concat(theme.spacing(1.5)), borderRadius: theme.spacing(1), cursor: 'pointer', userSelect: 'none', fontSize: theme.typography.body2.fontSize, fontWeight: theme.typography.fontWeightMedium, lineHeight: theme.typography.body2.lineHeight, color: theme.tokens.color_fg_default, transition: theme.transitions.create(['background-color', 'color'], {
|
|
62
|
+
duration: theme.transitions.duration.shortest,
|
|
63
|
+
}) }, (ownerState.isSelected && {
|
|
64
|
+
backgroundColor: theme.tokens.color_bg_interactive_hover,
|
|
65
|
+
})), (ownerState.disabled && {
|
|
66
|
+
opacity: 0.5,
|
|
67
|
+
cursor: 'not-allowed',
|
|
68
|
+
})), (!ownerState.disabled &&
|
|
69
|
+
!ownerState.isSelected && {
|
|
70
|
+
'&:hover': {
|
|
71
|
+
backgroundColor: theme.tokens.color_bg_interactive_hover,
|
|
72
|
+
},
|
|
73
|
+
})), { '&[aria-disabled="true"]': {
|
|
74
|
+
opacity: 0.5,
|
|
75
|
+
cursor: 'not-allowed',
|
|
76
|
+
} }));
|
|
77
|
+
});
|
|
78
|
+
var ItemIcon = styled('div', {
|
|
79
|
+
name: commandPaletteComponentName,
|
|
80
|
+
slot: 'ItemIcon',
|
|
81
|
+
})(function (_a) {
|
|
82
|
+
var theme = _a.theme;
|
|
83
|
+
return ({
|
|
84
|
+
display: 'flex',
|
|
85
|
+
alignItems: 'center',
|
|
86
|
+
justifyContent: 'center',
|
|
87
|
+
flexShrink: 0,
|
|
88
|
+
color: theme.tokens.color_fg_disabled,
|
|
89
|
+
'& svg': {
|
|
90
|
+
width: theme.typography.pxToRem(18),
|
|
91
|
+
height: theme.typography.pxToRem(18),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
var ItemLabel = styled('span', {
|
|
96
|
+
name: commandPaletteComponentName,
|
|
97
|
+
slot: 'ItemLabel',
|
|
98
|
+
})(function () { return ({
|
|
99
|
+
flex: 1,
|
|
100
|
+
overflow: 'hidden',
|
|
101
|
+
textOverflow: 'ellipsis',
|
|
102
|
+
whiteSpace: 'nowrap',
|
|
103
|
+
}); });
|
|
104
|
+
var ItemShortcut = styled('span', {
|
|
105
|
+
name: commandPaletteComponentName,
|
|
106
|
+
slot: 'ItemShortcut',
|
|
107
|
+
})(function (_a) {
|
|
108
|
+
var theme = _a.theme;
|
|
109
|
+
return ({
|
|
110
|
+
display: 'flex',
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
gap: theme.spacing(0.5),
|
|
113
|
+
flexShrink: 0,
|
|
114
|
+
marginLeft: 'auto',
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
var Kbd = styled('kbd', {
|
|
118
|
+
name: commandPaletteComponentName,
|
|
119
|
+
slot: 'Kbd',
|
|
120
|
+
})(function (_a) {
|
|
121
|
+
var theme = _a.theme;
|
|
122
|
+
return ({
|
|
123
|
+
display: 'inline-flex',
|
|
124
|
+
alignItems: 'center',
|
|
125
|
+
justifyContent: 'center',
|
|
126
|
+
minWidth: theme.typography.pxToRem(22),
|
|
127
|
+
height: theme.typography.pxToRem(22),
|
|
128
|
+
padding: "0 ".concat(theme.spacing(0.5)),
|
|
129
|
+
borderRadius: theme.typography.pxToRem(4),
|
|
130
|
+
backgroundColor: theme.tokens.color_bg_state_neutral_subtle,
|
|
131
|
+
border: "1px solid ".concat(theme.tokens.color_border_default),
|
|
132
|
+
color: theme.tokens.color_fg_disabled,
|
|
133
|
+
fontSize: theme.typography.overline.fontSize,
|
|
134
|
+
fontFamily: theme.typography.fontFamily,
|
|
135
|
+
lineHeight: 1,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
function deriveValue(valueProp, children, el) {
|
|
139
|
+
var _a;
|
|
140
|
+
if (valueProp)
|
|
141
|
+
return valueProp;
|
|
142
|
+
if (typeof children === 'string')
|
|
143
|
+
return children.trim().toLowerCase();
|
|
144
|
+
if (typeof children === 'number')
|
|
145
|
+
return String(children);
|
|
146
|
+
return ((_a = el === null || el === void 0 ? void 0 : el.textContent) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase()) || '';
|
|
147
|
+
}
|
|
148
|
+
function useValue(id, ref, deps) {
|
|
149
|
+
var initialValue = deriveValue(deps[0], deps[2], null);
|
|
150
|
+
var valueRef = React.useRef(initialValue);
|
|
151
|
+
var context = useCommandPaletteContext();
|
|
152
|
+
React.useLayoutEffect(function () {
|
|
153
|
+
var value = deriveValue(deps[0], deps[2], ref.current);
|
|
154
|
+
valueRef.current = value;
|
|
155
|
+
context.value(id, value, deps[1]);
|
|
156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
157
|
+
}, __spreadArray([id], __read(deps), false));
|
|
158
|
+
return valueRef.current;
|
|
159
|
+
}
|
|
160
|
+
export var CommandPaletteItem = React.forwardRef(function (props, ref) {
|
|
161
|
+
var _a;
|
|
162
|
+
var _b, _c;
|
|
163
|
+
var valueProp = props.value, keywords = props.keywords, _d = props.disabled, disabled = _d === void 0 ? false : _d, onSelect = props.onSelect, _e = props.forceMount, forceMount = _e === void 0 ? false : _e, icon = props.icon, shortcut = props.shortcut, children = props.children, className = props.className, itemProps = __rest(props, ["value", "keywords", "disabled", "onSelect", "forceMount", "icon", "shortcut", "children", "className"]);
|
|
164
|
+
var generatedId = useId();
|
|
165
|
+
var idRef = React.useRef();
|
|
166
|
+
if (!idRef.current) {
|
|
167
|
+
idRef.current =
|
|
168
|
+
(_c = (_b = itemProps.id) !== null && _b !== void 0 ? _b : generatedId) !== null && _c !== void 0 ? _c : "command-palette-item-".concat(Math.random().toString(36).slice(2));
|
|
169
|
+
}
|
|
170
|
+
var id = idRef.current;
|
|
171
|
+
var itemRef = React.useRef(null);
|
|
172
|
+
var context = useCommandPaletteContext();
|
|
173
|
+
var store = useCommandPaletteStore();
|
|
174
|
+
var groupId = React.useContext(CommandPaletteGroupContext);
|
|
175
|
+
var itemValue = useValue(id, itemRef, [valueProp, keywords, children]);
|
|
176
|
+
var selectedValue = useCommandPaletteState(function (state) { return state.selectedValue; });
|
|
177
|
+
var isSelected = selectedValue === itemValue && itemValue !== '';
|
|
178
|
+
var filteredState = useCommandPaletteState(function (state) { return state.filtered; });
|
|
179
|
+
var score = filteredState.items.get(id);
|
|
180
|
+
var isVisible = forceMount || context.filter === false || score === undefined || score > 0;
|
|
181
|
+
React.useLayoutEffect(function () {
|
|
182
|
+
var cleanup = context.item(id, groupId);
|
|
183
|
+
return cleanup;
|
|
184
|
+
}, [context, id, groupId]);
|
|
185
|
+
var handlePointerMove = React.useCallback(function () {
|
|
186
|
+
if (!disabled && itemValue) {
|
|
187
|
+
store.setState('selectedValue', itemValue);
|
|
188
|
+
}
|
|
189
|
+
}, [disabled, itemValue, store]);
|
|
190
|
+
var handleClick = React.useCallback(function () {
|
|
191
|
+
if (!disabled) {
|
|
192
|
+
onSelect === null || onSelect === void 0 ? void 0 : onSelect(itemValue);
|
|
193
|
+
}
|
|
194
|
+
}, [disabled, onSelect, itemValue]);
|
|
195
|
+
var mergedRef = useForkRef(itemRef, ref);
|
|
196
|
+
var shortcutKeys = shortcut ? (Array.isArray(shortcut) ? shortcut : shortcut.split('+')) : null;
|
|
197
|
+
if (!isVisible)
|
|
198
|
+
return null;
|
|
199
|
+
return (React.createElement(Root, __assign((_a = { ref: mergedRef, ownerState: { isSelected: isSelected, disabled: disabled }, className: clsx(commandPaletteClasses.item, isSelected && commandPaletteClasses.itemSelected, className), role: "option", "aria-selected": isSelected, "aria-disabled": disabled, "data-disabled": disabled || undefined }, _a[VALUE_ATTR] = encodeURIComponent(itemValue), _a.onPointerMove = handlePointerMove, _a.onClick = handleClick, _a), itemProps),
|
|
200
|
+
icon && React.createElement(ItemIcon, { className: commandPaletteClasses.itemIcon }, icon),
|
|
201
|
+
React.createElement(ItemLabel, { className: commandPaletteClasses.itemLabel }, children),
|
|
202
|
+
shortcutKeys && (React.createElement(ItemShortcut, { className: commandPaletteClasses.itemShortcut }, shortcutKeys.map(function (key, i) { return (React.createElement(Kbd, { key: i, className: commandPaletteClasses.kbd }, key)); })))));
|
|
203
|
+
});
|
|
204
|
+
CommandPaletteItem.displayName = 'CommandPaletteItem';
|