@auth0/quantum-product 2.10.1 → 2.10.3

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.
Files changed (58) hide show
  1. package/command-palette/command-palette-classes.d.ts +5 -0
  2. package/command-palette/command-palette-classes.js +34 -0
  3. package/command-palette/command-palette-context.d.ts +8 -0
  4. package/command-palette/command-palette-context.js +61 -0
  5. package/command-palette/command-palette-dialog.d.ts +3 -0
  6. package/command-palette/command-palette-dialog.js +112 -0
  7. package/command-palette/command-palette-empty.d.ts +3 -0
  8. package/command-palette/command-palette-empty.js +90 -0
  9. package/command-palette/command-palette-footer.d.ts +4 -0
  10. package/command-palette/command-palette-footer.js +111 -0
  11. package/command-palette/command-palette-group.d.ts +3 -0
  12. package/command-palette/command-palette-group.js +118 -0
  13. package/command-palette/command-palette-input.d.ts +3 -0
  14. package/command-palette/command-palette-input.js +144 -0
  15. package/command-palette/command-palette-item.d.ts +3 -0
  16. package/command-palette/command-palette-item.js +235 -0
  17. package/command-palette/command-palette-list.d.ts +3 -0
  18. package/command-palette/command-palette-list.js +101 -0
  19. package/command-palette/command-palette-loading.d.ts +3 -0
  20. package/command-palette/command-palette-loading.js +89 -0
  21. package/command-palette/command-palette-score.d.ts +1 -0
  22. package/command-palette/command-palette-score.js +47 -0
  23. package/command-palette/command-palette-separator.d.ts +3 -0
  24. package/command-palette/command-palette-separator.js +86 -0
  25. package/command-palette/command-palette-tabs.d.ts +4 -0
  26. package/command-palette/command-palette-tabs.js +146 -0
  27. package/command-palette/command-palette-types.d.ts +121 -0
  28. package/command-palette/command-palette-types.js +2 -0
  29. package/command-palette/command-palette.d.ts +5 -0
  30. package/command-palette/command-palette.js +474 -0
  31. package/command-palette/index.d.ts +27 -0
  32. package/command-palette/index.js +36 -0
  33. package/command-palette/use-command-palette-shortcut.d.ts +6 -0
  34. package/command-palette/use-command-palette-shortcut.js +65 -0
  35. package/esm/command-palette/command-palette-classes.js +30 -0
  36. package/esm/command-palette/command-palette-context.js +22 -0
  37. package/esm/command-palette/command-palette-dialog.js +73 -0
  38. package/esm/command-palette/command-palette-empty.js +51 -0
  39. package/esm/command-palette/command-palette-footer.js +72 -0
  40. package/esm/command-palette/command-palette-group.js +79 -0
  41. package/esm/command-palette/command-palette-input.js +105 -0
  42. package/esm/command-palette/command-palette-item.js +196 -0
  43. package/esm/command-palette/command-palette-list.js +62 -0
  44. package/esm/command-palette/command-palette-loading.js +50 -0
  45. package/esm/command-palette/command-palette-score.js +44 -0
  46. package/esm/command-palette/command-palette-separator.js +47 -0
  47. package/esm/command-palette/command-palette-tabs.js +107 -0
  48. package/esm/command-palette/command-palette-types.js +1 -0
  49. package/esm/command-palette/command-palette.js +435 -0
  50. package/esm/command-palette/index.js +14 -0
  51. package/esm/command-palette/use-command-palette-shortcut.js +29 -0
  52. package/esm/icon/index.js +2 -1
  53. package/esm/index.js +1 -0
  54. package/icon/index.d.ts +1 -0
  55. package/icon/index.js +8 -7
  56. package/index.d.ts +1 -0
  57. package/index.js +1 -0
  58. package/package.json +2 -2
@@ -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,79 @@
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 { CommandPaletteGroupContext, useCommandPaletteContext, useCommandPaletteState, } from './command-palette-context';
28
+ var Root = styled('div', {
29
+ name: commandPaletteComponentName,
30
+ slot: 'Group',
31
+ })(function (_a) {
32
+ var theme = _a.theme;
33
+ return ({
34
+ padding: theme.spacing(0.5, 1),
35
+ outline: 'none',
36
+ });
37
+ });
38
+ var Heading = styled('div', {
39
+ name: commandPaletteComponentName,
40
+ slot: 'GroupHeading',
41
+ })(function (_a) {
42
+ var theme = _a.theme;
43
+ return ({
44
+ padding: "".concat(theme.spacing(1), " ").concat(theme.spacing(1.5)),
45
+ fontSize: theme.typography.overline.fontSize,
46
+ fontWeight: theme.typography.fontWeightMedium,
47
+ color: theme.tokens.color_fg_disabled,
48
+ textTransform: 'uppercase',
49
+ letterSpacing: '0.05em',
50
+ userSelect: 'none',
51
+ });
52
+ });
53
+ var Items = styled('div', {
54
+ name: commandPaletteComponentName,
55
+ slot: 'GroupItems',
56
+ })(function () { return ({
57
+ outline: 'none',
58
+ }); });
59
+ export var CommandPaletteGroup = React.forwardRef(function (props, ref) {
60
+ 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"]);
61
+ var id = React.useId();
62
+ var headingId = "".concat(id, "-heading");
63
+ var context = useCommandPaletteContext();
64
+ React.useLayoutEffect(function () {
65
+ var cleanup = context.group(id);
66
+ return cleanup;
67
+ }, [context, id]);
68
+ var filteredState = useCommandPaletteState(function (state) { return state.filtered; });
69
+ var search = useCommandPaletteState(function (state) { return state.search; });
70
+ var groupCount = filteredState.groups.get(id);
71
+ var isVisible = forceMount || context.filter === false || !search || (groupCount !== undefined && groupCount > 0);
72
+ if (!isVisible)
73
+ return null;
74
+ return (React.createElement(Root, __assign({ ref: ref, className: clsx(commandPaletteClasses.group, className), role: "presentation" }, groupProps),
75
+ heading && (React.createElement(Heading, { id: headingId, className: commandPaletteClasses.groupHeading, "aria-hidden": true }, heading)),
76
+ React.createElement(CommandPaletteGroupContext.Provider, { value: id },
77
+ React.createElement(Items, { role: "group", className: commandPaletteClasses.groupItems, "aria-labelledby": heading ? headingId : undefined }, children))));
78
+ });
79
+ 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,196 @@
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 { VALUE_ATTR } from './command-palette';
53
+ import { commandPaletteClasses, commandPaletteComponentName } from './command-palette-classes';
54
+ import { CommandPaletteGroupContext, useCommandPaletteContext, useCommandPaletteState, useCommandPaletteStore, } from './command-palette-context';
55
+ var Root = styled('div', {
56
+ name: commandPaletteComponentName,
57
+ slot: 'Item',
58
+ })(function (_a) {
59
+ var theme = _a.theme, ownerState = _a.ownerState;
60
+ 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'], {
61
+ duration: theme.transitions.duration.shortest,
62
+ }) }, (ownerState.isSelected && {
63
+ backgroundColor: theme.tokens.color_bg_interactive_hover,
64
+ })), (ownerState.disabled && {
65
+ opacity: 0.5,
66
+ cursor: 'not-allowed',
67
+ })), (!ownerState.disabled &&
68
+ !ownerState.isSelected && {
69
+ '&:hover': {
70
+ backgroundColor: theme.tokens.color_bg_interactive_hover,
71
+ },
72
+ })), { '&[aria-disabled="true"]': {
73
+ opacity: 0.5,
74
+ cursor: 'not-allowed',
75
+ } }));
76
+ });
77
+ var ItemIcon = styled('div', {
78
+ name: commandPaletteComponentName,
79
+ slot: 'ItemIcon',
80
+ })(function (_a) {
81
+ var theme = _a.theme;
82
+ return ({
83
+ display: 'flex',
84
+ alignItems: 'center',
85
+ justifyContent: 'center',
86
+ flexShrink: 0,
87
+ color: theme.tokens.color_fg_disabled,
88
+ '& svg': {
89
+ width: theme.typography.pxToRem(18),
90
+ height: theme.typography.pxToRem(18),
91
+ },
92
+ });
93
+ });
94
+ var ItemLabel = styled('span', {
95
+ name: commandPaletteComponentName,
96
+ slot: 'ItemLabel',
97
+ })(function () { return ({
98
+ flex: 1,
99
+ overflow: 'hidden',
100
+ textOverflow: 'ellipsis',
101
+ whiteSpace: 'nowrap',
102
+ }); });
103
+ var ItemShortcut = styled('span', {
104
+ name: commandPaletteComponentName,
105
+ slot: 'ItemShortcut',
106
+ })(function (_a) {
107
+ var theme = _a.theme;
108
+ return ({
109
+ display: 'flex',
110
+ alignItems: 'center',
111
+ gap: theme.spacing(0.5),
112
+ flexShrink: 0,
113
+ marginLeft: 'auto',
114
+ });
115
+ });
116
+ var Kbd = styled('kbd', {
117
+ name: commandPaletteComponentName,
118
+ slot: 'Kbd',
119
+ })(function (_a) {
120
+ var theme = _a.theme;
121
+ return ({
122
+ display: 'inline-flex',
123
+ alignItems: 'center',
124
+ justifyContent: 'center',
125
+ minWidth: theme.typography.pxToRem(22),
126
+ height: theme.typography.pxToRem(22),
127
+ padding: "0 ".concat(theme.spacing(0.5)),
128
+ borderRadius: theme.typography.pxToRem(4),
129
+ backgroundColor: theme.tokens.color_bg_state_neutral_subtle,
130
+ border: "1px solid ".concat(theme.tokens.color_border_default),
131
+ color: theme.tokens.color_fg_disabled,
132
+ fontSize: theme.typography.overline.fontSize,
133
+ fontFamily: theme.typography.fontFamily,
134
+ lineHeight: 1,
135
+ });
136
+ });
137
+ function deriveValue(valueProp, children, el) {
138
+ var _a;
139
+ if (valueProp)
140
+ return valueProp;
141
+ if (typeof children === 'string')
142
+ return children.trim().toLowerCase();
143
+ if (typeof children === 'number')
144
+ return String(children);
145
+ return ((_a = el === null || el === void 0 ? void 0 : el.textContent) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase()) || '';
146
+ }
147
+ function useValue(id, ref, deps) {
148
+ var initialValue = deriveValue(deps[0], deps[2], null);
149
+ var valueRef = React.useRef(initialValue);
150
+ var context = useCommandPaletteContext();
151
+ React.useLayoutEffect(function () {
152
+ var value = deriveValue(deps[0], deps[2], ref.current);
153
+ valueRef.current = value;
154
+ context.value(id, value, deps[1]);
155
+ // eslint-disable-next-line react-hooks/exhaustive-deps
156
+ }, __spreadArray([id], __read(deps), false));
157
+ return valueRef.current;
158
+ }
159
+ export var CommandPaletteItem = React.forwardRef(function (props, ref) {
160
+ var _a;
161
+ var valueProp = props.value, keywords = props.keywords, _b = props.disabled, disabled = _b === void 0 ? false : _b, onSelect = props.onSelect, _c = props.forceMount, forceMount = _c === void 0 ? false : _c, icon = props.icon, shortcut = props.shortcut, children = props.children, className = props.className, itemProps = __rest(props, ["value", "keywords", "disabled", "onSelect", "forceMount", "icon", "shortcut", "children", "className"]);
162
+ var id = React.useId();
163
+ var itemRef = React.useRef(null);
164
+ var context = useCommandPaletteContext();
165
+ var store = useCommandPaletteStore();
166
+ var groupId = React.useContext(CommandPaletteGroupContext);
167
+ var itemValue = useValue(id, itemRef, [valueProp, keywords, children]);
168
+ var selectedValue = useCommandPaletteState(function (state) { return state.selectedValue; });
169
+ var isSelected = selectedValue === itemValue && itemValue !== '';
170
+ var filteredState = useCommandPaletteState(function (state) { return state.filtered; });
171
+ var score = filteredState.items.get(id);
172
+ var isVisible = forceMount || context.filter === false || score === undefined || score > 0;
173
+ React.useLayoutEffect(function () {
174
+ var cleanup = context.item(id, groupId);
175
+ return cleanup;
176
+ }, [context, id, groupId]);
177
+ var handlePointerMove = React.useCallback(function () {
178
+ if (!disabled && itemValue) {
179
+ store.setState('selectedValue', itemValue);
180
+ }
181
+ }, [disabled, itemValue, store]);
182
+ var handleClick = React.useCallback(function () {
183
+ if (!disabled) {
184
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect(itemValue);
185
+ }
186
+ }, [disabled, onSelect, itemValue]);
187
+ var mergedRef = useForkRef(itemRef, ref);
188
+ var shortcutKeys = shortcut ? (Array.isArray(shortcut) ? shortcut : shortcut.split('+')) : null;
189
+ if (!isVisible)
190
+ return null;
191
+ 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),
192
+ icon && React.createElement(ItemIcon, { className: commandPaletteClasses.itemIcon }, icon),
193
+ React.createElement(ItemLabel, { className: commandPaletteClasses.itemLabel }, children),
194
+ shortcutKeys && (React.createElement(ItemShortcut, { className: commandPaletteClasses.itemShortcut }, shortcutKeys.map(function (key, i) { return (React.createElement(Kbd, { key: i, className: commandPaletteClasses.kbd }, key)); })))));
195
+ });
196
+ CommandPaletteItem.displayName = 'CommandPaletteItem';
@@ -0,0 +1,62 @@
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 { useCommandPaletteContext } from './command-palette-context';
28
+ var Root = styled('div', {
29
+ name: commandPaletteComponentName,
30
+ slot: 'List',
31
+ })(function (_a) {
32
+ var theme = _a.theme;
33
+ return ({
34
+ height: theme.typography.pxToRem(300),
35
+ overflow: 'auto',
36
+ outline: 'none',
37
+ overscrollBehavior: 'contain',
38
+ scrollbarWidth: 'thin',
39
+ scrollbarColor: "".concat(theme.tokens.color_border_default, " transparent"),
40
+ '&::-webkit-scrollbar': {
41
+ width: 6,
42
+ },
43
+ '&::-webkit-scrollbar-track': {
44
+ background: 'transparent',
45
+ },
46
+ '&::-webkit-scrollbar-thumb': {
47
+ backgroundColor: theme.tokens.color_border_default,
48
+ borderRadius: 3,
49
+ },
50
+ });
51
+ });
52
+ var Inner = styled('div', {
53
+ name: commandPaletteComponentName,
54
+ slot: 'ListInner',
55
+ })(function () { return ({}); });
56
+ export var CommandPaletteList = React.forwardRef(function (props, ref) {
57
+ var children = props.children, className = props.className, style = props.style, listProps = __rest(props, ["children", "className", "style"]);
58
+ var context = useCommandPaletteContext();
59
+ return (React.createElement(Root, __assign({ ref: ref, id: context.listId, role: "listbox", "aria-label": "Suggestions", className: clsx(commandPaletteClasses.list, className), style: style }, listProps),
60
+ React.createElement(Inner, { ref: context.listInnerRef }, children)));
61
+ });
62
+ CommandPaletteList.displayName = 'CommandPaletteList';