@efolusi/meridian 1.20.0 → 1.21.1
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/README.md +1 -1
- package/ai/Bubble.d.ts +16 -0
- package/ai/Bubble.js +71 -0
- package/ai/ChatMessage.js +2 -5
- package/ai/Confirmation.d.ts +0 -7
- package/ai/Confirmation.js +3 -6
- package/ai/GeneratedImage.d.ts +0 -2
- package/ai/GeneratedImage.js +2 -4
- package/ai/Marker.d.ts +26 -0
- package/ai/Marker.js +67 -0
- package/ai/Message.d.ts +13 -0
- package/ai/Message.js +68 -0
- package/ai/MessageScroller.d.ts +21 -0
- package/ai/MessageScroller.js +283 -0
- package/ai/ModelSelector.d.ts +2 -2
- package/ai/ModelSelector.js +1 -2
- package/ai/Player.js +1 -1
- package/ai/PromptSteps.js +4 -2
- package/ai/Sandbox.d.ts +0 -2
- package/ai/Sandbox.js +2 -4
- package/ai/Suggestions.d.ts +0 -2
- package/ai/Suggestions.js +1 -4
- package/ai/WebPreview.d.ts +0 -2
- package/ai/WebPreview.js +2 -4
- package/code/Console.js +1 -1
- package/code/EnvList.d.ts +0 -2
- package/code/EnvList.js +2 -3
- package/components.css +652 -418
- package/data/BarChart.d.ts +0 -2
- package/data/BarChart.js +1 -4
- package/data/Chart.d.ts +14 -0
- package/data/Chart.js +149 -0
- package/data/EmptyState.d.ts +8 -13
- package/data/EmptyState.js +62 -24
- package/data/LineChart.js +7 -4
- package/data/Skeleton.d.ts +2 -11
- package/data/Skeleton.js +8 -38
- package/data/Sparkline.js +4 -1
- package/data/StatusDot.d.ts +0 -4
- package/data/StatusDot.js +3 -6
- package/data/Table.d.ts +11 -4
- package/data/Table.js +39 -7
- package/dates/Calendar.d.ts +10 -27
- package/dates/Calendar.js +250 -184
- package/dates/TimePicker.js +2 -2
- package/display/Accordion.d.ts +47 -15
- package/display/Accordion.js +257 -27
- package/display/AspectRatio.d.ts +4 -6
- package/display/AspectRatio.js +7 -5
- package/display/Avatar.d.ts +17 -14
- package/display/Avatar.js +68 -43
- package/display/Badge.d.ts +9 -8
- package/display/Badge.js +32 -14
- package/display/Card.d.ts +11 -13
- package/display/Card.js +74 -29
- package/display/Carousel.d.ts +23 -15
- package/display/Carousel.js +217 -66
- package/display/Collapsible.d.ts +19 -9
- package/display/Collapsible.js +140 -28
- package/display/Direction.d.ts +10 -0
- package/display/Direction.js +24 -0
- package/display/Item.d.ts +19 -0
- package/display/Item.js +152 -0
- package/display/Kbd.d.ts +5 -7
- package/display/Kbd.js +22 -10
- package/display/Link.js +2 -4
- package/display/Resizable.d.ts +6 -16
- package/display/Resizable.js +141 -58
- package/display/ScrollArea.d.ts +3 -1
- package/display/ScrollArea.js +30 -5
- package/display/Separator.d.ts +9 -0
- package/display/Separator.js +18 -0
- package/display/Timeline.d.ts +24 -0
- package/display/Timeline.js +51 -0
- package/display/Toolbar.js +5 -4
- package/display/TreeList.d.ts +0 -2
- package/display/TreeList.js +2 -5
- package/feedback/Alert.d.ts +13 -13
- package/feedback/Alert.js +40 -36
- package/feedback/AlertDialog.d.ts +30 -0
- package/feedback/AlertDialog.js +249 -0
- package/feedback/Banner.d.ts +1 -3
- package/feedback/Banner.js +1 -5
- package/feedback/ConfirmDialog.d.ts +1 -1
- package/feedback/ConfirmDialog.js +18 -20
- package/feedback/Dialog.d.ts +13 -16
- package/feedback/Dialog.js +204 -62
- package/feedback/Progress.d.ts +8 -9
- package/feedback/Progress.js +42 -24
- package/feedback/Sonner.d.ts +8 -0
- package/feedback/Sonner.js +238 -0
- package/feedback/Spinner.d.ts +2 -9
- package/feedback/Spinner.js +19 -28
- package/feedback/Tooltip.d.ts +9 -10
- package/feedback/Tooltip.js +147 -96
- package/files/Attachment.d.ts +27 -0
- package/files/Attachment.js +111 -0
- package/files/FileDrop.js +3 -1
- package/finance/PaymentCard.js +3 -3
- package/forms/Button.d.ts +6 -5
- package/forms/Button.js +22 -8
- package/forms/ButtonGroup.d.ts +11 -3
- package/forms/ButtonGroup.js +57 -6
- package/forms/Checkbox.d.ts +14 -3
- package/forms/Checkbox.js +84 -16
- package/forms/Combobox.d.ts +24 -16
- package/forms/Combobox.js +466 -135
- package/forms/Field.d.ts +14 -0
- package/forms/Field.js +99 -0
- package/forms/IconButton.d.ts +1 -1
- package/forms/IconButton.js +4 -3
- package/forms/Input.d.ts +8 -8
- package/forms/Input.js +46 -33
- package/forms/InputGroup.d.ts +8 -15
- package/forms/InputGroup.js +74 -35
- package/forms/InputOTP.d.ts +13 -0
- package/forms/InputOTP.js +125 -0
- package/forms/Label.d.ts +2 -6
- package/forms/Label.js +6 -4
- package/forms/NativeSelect.d.ts +16 -0
- package/forms/NativeSelect.js +35 -0
- package/forms/NumberInput.js +2 -2
- package/forms/Radio.d.ts +12 -1
- package/forms/Radio.js +76 -6
- package/forms/Select.d.ts +12 -9
- package/forms/Select.js +254 -42
- package/forms/Slider.d.ts +10 -17
- package/forms/Slider.js +78 -39
- package/forms/Switch.d.ts +8 -2
- package/forms/Switch.js +46 -15
- package/forms/Textarea.d.ts +1 -1
- package/forms/Textarea.js +26 -18
- package/forms/Toggle.d.ts +18 -15
- package/forms/Toggle.js +96 -42
- package/icons/_svg.js +2 -0
- package/index.d.ts +20 -8
- package/index.js +50 -38
- package/navigation/Breadcrumbs.d.ts +18 -11
- package/navigation/Breadcrumbs.js +99 -26
- package/navigation/Menubar.d.ts +52 -10
- package/navigation/Menubar.js +191 -146
- package/navigation/NavigationMenu.d.ts +15 -0
- package/navigation/NavigationMenu.js +296 -0
- package/navigation/Pagination.d.ts +10 -9
- package/navigation/Pagination.js +94 -51
- package/navigation/SideNav.js +4 -3
- package/navigation/Sidebar.d.ts +29 -0
- package/navigation/Sidebar.js +311 -0
- package/navigation/Tabs.d.ts +9 -5
- package/navigation/Tabs.js +132 -44
- package/overlay/Command.d.ts +32 -0
- package/overlay/Command.js +257 -0
- package/overlay/ContextMenu.d.ts +40 -8
- package/overlay/ContextMenu.js +468 -107
- package/overlay/Drawer.d.ts +29 -14
- package/overlay/Drawer.js +178 -80
- package/overlay/DropdownMenu.d.ts +43 -0
- package/overlay/DropdownMenu.js +502 -0
- package/overlay/HoverCard.d.ts +21 -12
- package/overlay/HoverCard.js +129 -61
- package/overlay/Popover.d.ts +11 -13
- package/overlay/Popover.js +138 -65
- package/overlay/Portal.js +21 -7
- package/overlay/Sheet.d.ts +11 -0
- package/overlay/Sheet.js +62 -0
- package/package.json +4 -1
- package/tokens/base.css +1 -1
- package/dates/DatePicker.d.ts +0 -14
- package/dates/DatePicker.js +0 -111
- package/dates/DateRangePicker.d.ts +0 -23
- package/dates/DateRangePicker.js +0 -150
- package/display/ListItem.d.ts +0 -19
- package/display/ListItem.js +0 -50
- package/feedback/Toast.d.ts +0 -78
- package/feedback/Toast.js +0 -192
- package/forms/DigitEntry.d.ts +0 -15
- package/forms/DigitEntry.js +0 -79
- package/forms/FormField.d.ts +0 -82
- package/forms/FormField.js +0 -209
- package/overlay/CommandPalette.d.ts +0 -21
- package/overlay/CommandPalette.js +0 -148
- package/overlay/Menu.d.ts +0 -24
- package/overlay/Menu.js +0 -139
package/navigation/Tabs.js
CHANGED
|
@@ -2,65 +2,153 @@
|
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Icon } from "../icons/Icon.js";
|
|
5
|
-
import {
|
|
5
|
+
import { useDirection } from "../display/Direction.js";
|
|
6
|
+
const TabsContext = /*#__PURE__*/React.createContext(null);
|
|
6
7
|
export const Tabs = /*#__PURE__*/React.forwardRef(function Tabs({
|
|
7
8
|
items,
|
|
8
|
-
value,
|
|
9
|
+
value: valueProp,
|
|
10
|
+
defaultValue,
|
|
11
|
+
onValueChange,
|
|
9
12
|
onChange,
|
|
13
|
+
orientation = 'horizontal',
|
|
14
|
+
children,
|
|
10
15
|
style,
|
|
11
16
|
className,
|
|
12
17
|
...rest
|
|
13
18
|
}, fRef) {
|
|
14
|
-
const
|
|
15
|
-
const [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (el) setInk({
|
|
22
|
-
left: el.offsetLeft,
|
|
23
|
-
width: el.offsetWidth
|
|
24
|
-
});
|
|
25
|
-
}, [value, items]);
|
|
26
|
-
const onKey = e => {
|
|
27
|
-
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(e.key)) return;
|
|
28
|
-
e.preventDefault();
|
|
29
|
-
const ids = items.map(i => i.id);
|
|
30
|
-
const cur = ids.indexOf(value);
|
|
31
|
-
let next = cur;
|
|
32
|
-
if (e.key === 'ArrowLeft') next = (cur - 1 + ids.length) % ids.length;
|
|
33
|
-
if (e.key === 'ArrowRight') next = (cur + 1) % ids.length;
|
|
34
|
-
if (e.key === 'Home') next = 0;
|
|
35
|
-
if (e.key === 'End') next = ids.length - 1;
|
|
36
|
-
if (onChange) onChange(ids[next]);
|
|
37
|
-
const btns = ref.current ? ref.current.querySelectorAll('[role="tab"]') : [];
|
|
38
|
-
if (btns[next]) btns[next].focus();
|
|
19
|
+
const uid = React.useId();
|
|
20
|
+
const [inner, setInner] = React.useState(defaultValue != null ? defaultValue : items && items[0] ? items[0].id : undefined);
|
|
21
|
+
const value = valueProp !== undefined ? valueProp : inner;
|
|
22
|
+
const change = next => {
|
|
23
|
+
if (valueProp === undefined) setInner(next);
|
|
24
|
+
if (onValueChange) onValueChange(next);
|
|
25
|
+
if (onChange) onChange(next);
|
|
39
26
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
const forwardedRef = typeof fRef === 'function' || fRef && Object.prototype.hasOwnProperty.call(fRef, 'current') ? fRef : null;
|
|
28
|
+
if (items) return /*#__PURE__*/React.createElement(Tabs, _extends({
|
|
29
|
+
value: value,
|
|
30
|
+
onValueChange: change,
|
|
31
|
+
orientation: orientation,
|
|
32
|
+
className: className,
|
|
45
33
|
style: style
|
|
46
|
-
}
|
|
34
|
+
}, rest, {
|
|
35
|
+
ref: forwardedRef
|
|
36
|
+
}), /*#__PURE__*/React.createElement(TabsList, null, items.map(it => /*#__PURE__*/React.createElement(TabsTrigger, {
|
|
47
37
|
key: it.id,
|
|
48
|
-
|
|
49
|
-
"aria-selected": value === it.id,
|
|
50
|
-
tabIndex: value === it.id ? 0 : -1,
|
|
51
|
-
"data-active": value === it.id ? 'true' : 'false',
|
|
52
|
-
className: `ef-tabs__tab${value === it.id ? ' ef-tabs__tab--active' : ''}`,
|
|
53
|
-
onClick: () => onChange && onChange(it.id)
|
|
38
|
+
value: it.id
|
|
54
39
|
}, it.icon ? /*#__PURE__*/React.createElement(Icon, {
|
|
55
40
|
name: it.icon,
|
|
56
41
|
size: 16
|
|
57
42
|
}) : null, it.label, it.count != null ? /*#__PURE__*/React.createElement("span", {
|
|
58
43
|
className: "ef-tabs__count"
|
|
59
|
-
}, it.count) : null))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
}, it.count) : null))));
|
|
45
|
+
return /*#__PURE__*/React.createElement(TabsContext.Provider, {
|
|
46
|
+
value: {
|
|
47
|
+
value,
|
|
48
|
+
change,
|
|
49
|
+
orientation,
|
|
50
|
+
uid
|
|
51
|
+
}
|
|
52
|
+
}, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
53
|
+
ref: forwardedRef,
|
|
54
|
+
"data-slot": "tabs",
|
|
55
|
+
"data-orientation": orientation,
|
|
56
|
+
className: `ef-tabs${className ? ' ' + className : ''}`,
|
|
57
|
+
style: style
|
|
58
|
+
}), children));
|
|
59
|
+
});
|
|
60
|
+
export const TabsList = /*#__PURE__*/React.forwardRef(function TabsList({
|
|
61
|
+
className,
|
|
62
|
+
onKeyDown,
|
|
63
|
+
variant,
|
|
64
|
+
...props
|
|
65
|
+
}, ref) {
|
|
66
|
+
const ctx = React.useContext(TabsContext) || {
|
|
67
|
+
orientation: 'horizontal'
|
|
68
|
+
};
|
|
69
|
+
const direction = useDirection();
|
|
70
|
+
const keydown = e => {
|
|
71
|
+
if (onKeyDown) onKeyDown(e);
|
|
72
|
+
if (e.defaultPrevented || !['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End'].includes(e.key)) return;
|
|
73
|
+
const tabs = [...e.currentTarget.querySelectorAll('[role="tab"]')].filter(x => !x.disabled);
|
|
74
|
+
const focused = tabs.indexOf(document.activeElement);
|
|
75
|
+
const current = focused >= 0 ? focused : tabs.indexOf(e.target);
|
|
76
|
+
let next = current;
|
|
77
|
+
const previous = ctx.orientation === 'vertical' ? e.key === 'ArrowUp' : e.key === (direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft');
|
|
78
|
+
const following = ctx.orientation === 'vertical' ? e.key === 'ArrowDown' : e.key === (direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight');
|
|
79
|
+
if (previous) next = (current - 1 + tabs.length) % tabs.length;
|
|
80
|
+
if (following) next = (current + 1) % tabs.length;
|
|
81
|
+
if (e.key === 'Home') next = 0;
|
|
82
|
+
if (e.key === 'End') next = tabs.length - 1;
|
|
83
|
+
if (tabs[next]) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
tabs[next].focus();
|
|
86
|
+
tabs[next].click();
|
|
64
87
|
}
|
|
88
|
+
};
|
|
89
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
90
|
+
ref: ref,
|
|
91
|
+
role: "tablist",
|
|
92
|
+
"aria-orientation": ctx.orientation,
|
|
93
|
+
"data-slot": "tabs-list",
|
|
94
|
+
"data-orientation": ctx.orientation,
|
|
95
|
+
"data-variant": variant || 'default',
|
|
96
|
+
onKeyDown: keydown,
|
|
97
|
+
className: `ef-tabs__list${className ? ' ' + className : ''}`
|
|
98
|
+
}));
|
|
99
|
+
});
|
|
100
|
+
export const TabsTrigger = /*#__PURE__*/React.forwardRef(function TabsTrigger({
|
|
101
|
+
value,
|
|
102
|
+
className,
|
|
103
|
+
disabled,
|
|
104
|
+
...props
|
|
105
|
+
}, ref) {
|
|
106
|
+
const ctx = React.useContext(TabsContext) || {
|
|
107
|
+
value: undefined,
|
|
108
|
+
change: () => {},
|
|
109
|
+
uid: 'tabs'
|
|
110
|
+
};
|
|
111
|
+
const active = ctx.value === value;
|
|
112
|
+
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
113
|
+
ref: ref,
|
|
114
|
+
id: `${ctx.uid}-trigger-${value}`,
|
|
115
|
+
type: "button",
|
|
116
|
+
role: "tab",
|
|
117
|
+
disabled: disabled,
|
|
118
|
+
"aria-selected": active,
|
|
119
|
+
"aria-controls": `${ctx.uid}-content-${value}`,
|
|
120
|
+
tabIndex: active ? 0 : -1,
|
|
121
|
+
"data-slot": "tabs-trigger",
|
|
122
|
+
"data-state": active ? 'active' : 'inactive',
|
|
123
|
+
"data-active": active ? 'true' : 'false',
|
|
124
|
+
className: `ef-tabs__tab${active ? ' ef-tabs__tab--active' : ''}${className ? ' ' + className : ''}`,
|
|
125
|
+
onClick: e => {
|
|
126
|
+
if (props.onClick) props.onClick(e);
|
|
127
|
+
if (!e.defaultPrevented) ctx.change(value);
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
export const TabsContent = /*#__PURE__*/React.forwardRef(function TabsContent({
|
|
132
|
+
value,
|
|
133
|
+
className,
|
|
134
|
+
forceMount,
|
|
135
|
+
...props
|
|
136
|
+
}, ref) {
|
|
137
|
+
const ctx = React.useContext(TabsContext) || {
|
|
138
|
+
value: undefined,
|
|
139
|
+
uid: 'tabs'
|
|
140
|
+
};
|
|
141
|
+
const active = ctx.value === value;
|
|
142
|
+
if (!active && !forceMount) return null;
|
|
143
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, props, {
|
|
144
|
+
ref: ref,
|
|
145
|
+
id: `${ctx.uid}-content-${value}`,
|
|
146
|
+
role: "tabpanel",
|
|
147
|
+
"aria-labelledby": `${ctx.uid}-trigger-${value}`,
|
|
148
|
+
tabIndex: 0,
|
|
149
|
+
hidden: !active,
|
|
150
|
+
"data-slot": "tabs-content",
|
|
151
|
+
"data-state": active ? 'active' : 'inactive',
|
|
152
|
+
className: `ef-tabs__content${className ? ' ' + className : ''}`
|
|
65
153
|
}));
|
|
66
154
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface CommandProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
2
|
+
value?: string;
|
|
3
|
+
defaultValue?: string;
|
|
4
|
+
onValueChange?: (value: string) => void;
|
|
5
|
+
shouldFilter?: boolean;
|
|
6
|
+
filter?: (value: string, search: string, keywords?: string[]) => number;
|
|
7
|
+
loop?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface CommandDialogProps {
|
|
10
|
+
open?: boolean;
|
|
11
|
+
defaultOpen?: boolean;
|
|
12
|
+
onOpenChange?: (open: boolean) => void;
|
|
13
|
+
title?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
showCloseButton?: boolean;
|
|
16
|
+
className?: string;
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export interface CommandItemProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onSelect'> {
|
|
20
|
+
value?: string;
|
|
21
|
+
keywords?: string[];
|
|
22
|
+
onSelect?: (value: string) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare const Command: React.ForwardRefExoticComponent<CommandProps & React.RefAttributes<HTMLDivElement>>;
|
|
25
|
+
export declare function CommandDialog(props: CommandDialogProps): React.JSX.Element;
|
|
26
|
+
export declare const CommandInput: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & React.RefAttributes<HTMLInputElement>>;
|
|
27
|
+
export declare const CommandList: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
28
|
+
export declare const CommandEmpty: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
29
|
+
export declare const CommandGroup: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & { heading?: React.ReactNode } & React.RefAttributes<HTMLDivElement>>;
|
|
30
|
+
export declare const CommandItem: React.ForwardRefExoticComponent<CommandItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
31
|
+
export declare const CommandShortcut: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & React.RefAttributes<HTMLSpanElement>>;
|
|
32
|
+
export declare const CommandSeparator: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { Icon } from "../icons/Icon.js";
|
|
5
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "../feedback/Dialog.js";
|
|
6
|
+
const CommandContext = /*#__PURE__*/React.createContext(null);
|
|
7
|
+
const textOf = node => React.Children.toArray(node).map(child => typeof child === 'string' || typeof child === 'number' ? String(child) : /*#__PURE__*/React.isValidElement(child) ? textOf(child.props.children) : '').join(' ');
|
|
8
|
+
const join = (...values) => values.filter(Boolean).join(' ');
|
|
9
|
+
export const Command = /*#__PURE__*/React.forwardRef(function Command({
|
|
10
|
+
value,
|
|
11
|
+
defaultValue = '',
|
|
12
|
+
onValueChange,
|
|
13
|
+
shouldFilter = true,
|
|
14
|
+
filter,
|
|
15
|
+
loop = false,
|
|
16
|
+
className,
|
|
17
|
+
children,
|
|
18
|
+
onKeyDown,
|
|
19
|
+
...props
|
|
20
|
+
}, ref) {
|
|
21
|
+
const [search, setSearch] = React.useState('');
|
|
22
|
+
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
23
|
+
const [version, setVersion] = React.useState(0);
|
|
24
|
+
const listId = React.useId();
|
|
25
|
+
const items = React.useRef(new Map());
|
|
26
|
+
const selected = value === undefined ? internalValue : value;
|
|
27
|
+
const setSelected = React.useCallback(next => {
|
|
28
|
+
if (value === undefined) setInternalValue(next);
|
|
29
|
+
onValueChange?.(next);
|
|
30
|
+
}, [value, onValueChange]);
|
|
31
|
+
const register = React.useCallback((id, record) => {
|
|
32
|
+
items.current.set(id, record);
|
|
33
|
+
setVersion(v => v + 1);
|
|
34
|
+
return () => {
|
|
35
|
+
items.current.delete(id);
|
|
36
|
+
setVersion(v => v + 1);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
const score = React.useCallback(record => {
|
|
40
|
+
if (!shouldFilter || !search) return 1;
|
|
41
|
+
if (filter) return filter(record.value, search, record.keywords) || 0;
|
|
42
|
+
const haystack = `${record.value} ${record.label} ${(record.keywords || []).join(' ')}`.toLocaleLowerCase();
|
|
43
|
+
return haystack.includes(search.toLocaleLowerCase()) ? 1 : 0;
|
|
44
|
+
}, [filter, search, shouldFilter]);
|
|
45
|
+
const visible = React.useCallback(record => score(record) > 0, [score]);
|
|
46
|
+
const visibleItems = [...items.current.values()].filter(record => !record.disabled && visible(record));
|
|
47
|
+
const activeId = visibleItems.find(record => record.value === selected)?.id;
|
|
48
|
+
React.useEffect(() => {
|
|
49
|
+
if (!visibleItems.length) return setSelected('');
|
|
50
|
+
if (!visibleItems.some(record => record.value === selected)) setSelected(visibleItems[0].value);
|
|
51
|
+
}, [search, version]);
|
|
52
|
+
const keydown = event => {
|
|
53
|
+
onKeyDown?.(event);
|
|
54
|
+
if (event.defaultPrevented) return;
|
|
55
|
+
const current = [...items.current.values()].filter(record => !record.disabled && visible(record));
|
|
56
|
+
if (!current.length) return;
|
|
57
|
+
const index = Math.max(0, current.findIndex(record => record.value === selected));
|
|
58
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
const delta = event.key === 'ArrowDown' ? 1 : -1;
|
|
61
|
+
const next = loop ? (index + delta + current.length) % current.length : Math.max(0, Math.min(current.length - 1, index + delta));
|
|
62
|
+
setSelected(current[next].value);
|
|
63
|
+
current[next].ref.current?.scrollIntoView?.({
|
|
64
|
+
block: 'nearest'
|
|
65
|
+
});
|
|
66
|
+
} else if (event.key === 'Home' || event.key === 'End') {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
setSelected(current[event.key === 'Home' ? 0 : current.length - 1].value);
|
|
69
|
+
} else if (event.key === 'Enter') {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
current[index].ref.current?.click();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const context = React.useMemo(() => ({
|
|
75
|
+
register,
|
|
76
|
+
search,
|
|
77
|
+
setSearch,
|
|
78
|
+
selected,
|
|
79
|
+
setSelected,
|
|
80
|
+
visible,
|
|
81
|
+
visibleCount: visibleItems.length,
|
|
82
|
+
version,
|
|
83
|
+
listId,
|
|
84
|
+
activeId
|
|
85
|
+
}), [register, search, selected, setSelected, visible, visibleItems.length, version, listId, activeId]);
|
|
86
|
+
return /*#__PURE__*/React.createElement(CommandContext.Provider, {
|
|
87
|
+
value: context
|
|
88
|
+
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
89
|
+
ref: ref,
|
|
90
|
+
"data-slot": "command",
|
|
91
|
+
className: join('ef-command', className),
|
|
92
|
+
onKeyDown: keydown
|
|
93
|
+
}, props), children));
|
|
94
|
+
});
|
|
95
|
+
export function CommandDialog({
|
|
96
|
+
title = 'Command Palette',
|
|
97
|
+
description = 'Search for a command to run…',
|
|
98
|
+
children,
|
|
99
|
+
className,
|
|
100
|
+
showCloseButton = true,
|
|
101
|
+
...props
|
|
102
|
+
}) {
|
|
103
|
+
return /*#__PURE__*/React.createElement(Dialog, props, /*#__PURE__*/React.createElement(DialogContent, {
|
|
104
|
+
className: join('ef-command-dialog', className),
|
|
105
|
+
showCloseButton: showCloseButton,
|
|
106
|
+
width: 560
|
|
107
|
+
}, /*#__PURE__*/React.createElement(DialogHeader, {
|
|
108
|
+
className: "ef-command__sr"
|
|
109
|
+
}, /*#__PURE__*/React.createElement(DialogTitle, null, title), /*#__PURE__*/React.createElement(DialogDescription, null, description)), /*#__PURE__*/React.createElement(Command, null, children)));
|
|
110
|
+
}
|
|
111
|
+
export const CommandInput = /*#__PURE__*/React.forwardRef(function CommandInput({
|
|
112
|
+
className,
|
|
113
|
+
value,
|
|
114
|
+
onChange,
|
|
115
|
+
...props
|
|
116
|
+
}, ref) {
|
|
117
|
+
const context = React.useContext(CommandContext);
|
|
118
|
+
const current = value === undefined ? context?.search || '' : value;
|
|
119
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
120
|
+
"data-slot": "command-input-wrapper",
|
|
121
|
+
className: "ef-command__input-wrap"
|
|
122
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
123
|
+
name: "search",
|
|
124
|
+
size: 16
|
|
125
|
+
}), /*#__PURE__*/React.createElement("input", _extends({
|
|
126
|
+
ref: ref,
|
|
127
|
+
"data-slot": "command-input",
|
|
128
|
+
className: join('ef-command__input', className),
|
|
129
|
+
value: current,
|
|
130
|
+
onChange: event => {
|
|
131
|
+
if (value === undefined) context?.setSearch(event.target.value);
|
|
132
|
+
onChange?.(event);
|
|
133
|
+
},
|
|
134
|
+
role: "combobox",
|
|
135
|
+
"aria-expanded": "true",
|
|
136
|
+
"aria-autocomplete": "list",
|
|
137
|
+
"aria-controls": context?.listId,
|
|
138
|
+
"aria-activedescendant": context?.activeId,
|
|
139
|
+
"aria-label": props['aria-label'] || props.placeholder
|
|
140
|
+
}, props)));
|
|
141
|
+
});
|
|
142
|
+
export const CommandList = /*#__PURE__*/React.forwardRef(function CommandList({
|
|
143
|
+
className,
|
|
144
|
+
...props
|
|
145
|
+
}, ref) {
|
|
146
|
+
const context = React.useContext(CommandContext);
|
|
147
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
148
|
+
ref: ref,
|
|
149
|
+
id: props.id || context?.listId,
|
|
150
|
+
"data-slot": "command-list",
|
|
151
|
+
role: "listbox",
|
|
152
|
+
className: join('ef-command__list', className)
|
|
153
|
+
}, props));
|
|
154
|
+
});
|
|
155
|
+
export const CommandEmpty = /*#__PURE__*/React.forwardRef(function CommandEmpty({
|
|
156
|
+
className,
|
|
157
|
+
...props
|
|
158
|
+
}, ref) {
|
|
159
|
+
const context = React.useContext(CommandContext);
|
|
160
|
+
return context?.visibleCount === 0 ? /*#__PURE__*/React.createElement("div", _extends({
|
|
161
|
+
ref: ref,
|
|
162
|
+
"data-slot": "command-empty",
|
|
163
|
+
className: join('ef-command__empty', className)
|
|
164
|
+
}, props)) : null;
|
|
165
|
+
});
|
|
166
|
+
export const CommandGroup = /*#__PURE__*/React.forwardRef(function CommandGroup({
|
|
167
|
+
heading,
|
|
168
|
+
className,
|
|
169
|
+
children,
|
|
170
|
+
...props
|
|
171
|
+
}, ref) {
|
|
172
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
173
|
+
ref: ref,
|
|
174
|
+
"data-slot": "command-group",
|
|
175
|
+
role: "group",
|
|
176
|
+
"aria-label": typeof heading === 'string' ? heading : undefined,
|
|
177
|
+
className: join('ef-command__group', className)
|
|
178
|
+
}, props), heading ? /*#__PURE__*/React.createElement("div", {
|
|
179
|
+
"data-slot": "command-group-heading",
|
|
180
|
+
className: "ef-command__heading"
|
|
181
|
+
}, heading) : null, children);
|
|
182
|
+
});
|
|
183
|
+
export const CommandItem = /*#__PURE__*/React.forwardRef(function CommandItem({
|
|
184
|
+
value,
|
|
185
|
+
keywords = [],
|
|
186
|
+
disabled = false,
|
|
187
|
+
onSelect,
|
|
188
|
+
onClick,
|
|
189
|
+
className,
|
|
190
|
+
children,
|
|
191
|
+
...props
|
|
192
|
+
}, forwardedRef) {
|
|
193
|
+
const context = React.useContext(CommandContext);
|
|
194
|
+
const id = React.useId();
|
|
195
|
+
const localRef = React.useRef(null);
|
|
196
|
+
React.useImperativeHandle(forwardedRef, () => localRef.current);
|
|
197
|
+
const itemValue = value || textOf(children).trim();
|
|
198
|
+
React.useEffect(() => context?.register(id, {
|
|
199
|
+
id,
|
|
200
|
+
value: itemValue,
|
|
201
|
+
label: textOf(children),
|
|
202
|
+
keywords,
|
|
203
|
+
disabled,
|
|
204
|
+
ref: localRef
|
|
205
|
+
}), [context?.register, id, itemValue, keywords.join('\0'), disabled]);
|
|
206
|
+
const hidden = context ? !context.visible({
|
|
207
|
+
value: itemValue,
|
|
208
|
+
label: textOf(children),
|
|
209
|
+
keywords,
|
|
210
|
+
disabled
|
|
211
|
+
}) : false;
|
|
212
|
+
const selected = context?.selected === itemValue;
|
|
213
|
+
const activate = event => {
|
|
214
|
+
onClick?.(event);
|
|
215
|
+
if (!event.defaultPrevented && !disabled) {
|
|
216
|
+
context?.setSelected(itemValue);
|
|
217
|
+
onSelect?.(itemValue);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
return /*#__PURE__*/React.createElement("button", _extends({
|
|
221
|
+
ref: localRef,
|
|
222
|
+
type: "button",
|
|
223
|
+
id: id,
|
|
224
|
+
"data-slot": "command-item",
|
|
225
|
+
"data-value": itemValue,
|
|
226
|
+
"data-selected": selected ? 'true' : 'false',
|
|
227
|
+
"data-disabled": disabled ? 'true' : 'false',
|
|
228
|
+
role: "option",
|
|
229
|
+
"aria-selected": selected,
|
|
230
|
+
disabled: disabled,
|
|
231
|
+
hidden: hidden,
|
|
232
|
+
className: join('ef-command__item', className),
|
|
233
|
+
onMouseEnter: () => !disabled && context?.setSelected(itemValue),
|
|
234
|
+
onClick: activate
|
|
235
|
+
}, props), children);
|
|
236
|
+
});
|
|
237
|
+
export const CommandShortcut = /*#__PURE__*/React.forwardRef(function CommandShortcut({
|
|
238
|
+
className,
|
|
239
|
+
...props
|
|
240
|
+
}, ref) {
|
|
241
|
+
return /*#__PURE__*/React.createElement("span", _extends({
|
|
242
|
+
ref: ref,
|
|
243
|
+
"data-slot": "command-shortcut",
|
|
244
|
+
className: join('ef-command__shortcut', className)
|
|
245
|
+
}, props));
|
|
246
|
+
});
|
|
247
|
+
export const CommandSeparator = /*#__PURE__*/React.forwardRef(function CommandSeparator({
|
|
248
|
+
className,
|
|
249
|
+
...props
|
|
250
|
+
}, ref) {
|
|
251
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
252
|
+
ref: ref,
|
|
253
|
+
"data-slot": "command-separator",
|
|
254
|
+
role: "separator",
|
|
255
|
+
className: join('ef-command__separator', className)
|
|
256
|
+
}, props));
|
|
257
|
+
});
|
package/overlay/ContextMenu.d.ts
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
|
|
2
3
|
export interface ContextMenuProps {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
style?: React.CSSProperties;
|
|
9
|
-
className?: string;
|
|
4
|
+
open?: boolean;
|
|
5
|
+
defaultOpen?: boolean;
|
|
6
|
+
onOpenChange?: (open: boolean) => void;
|
|
7
|
+
modal?: boolean;
|
|
8
|
+
children?: React.ReactNode;
|
|
10
9
|
}
|
|
11
10
|
export declare function ContextMenu(props: ContextMenuProps): React.JSX.Element;
|
|
11
|
+
|
|
12
|
+
export interface ContextMenuTriggerProps extends React.HTMLAttributes<HTMLElement> { asChild?: boolean; disabled?: boolean; }
|
|
13
|
+
export declare const ContextMenuTrigger: React.ForwardRefExoticComponent<ContextMenuTriggerProps & React.RefAttributes<HTMLElement>>;
|
|
14
|
+
|
|
15
|
+
export interface ContextMenuPortalProps { children?: React.ReactNode; container?: HTMLElement | null; }
|
|
16
|
+
export declare function ContextMenuPortal(props: ContextMenuPortalProps): React.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export interface ContextMenuContentProps extends React.HTMLAttributes<HTMLDivElement> { loop?: boolean; onCloseAutoFocus?: (event: { defaultPrevented: boolean; preventDefault(): void }) => void; }
|
|
19
|
+
export declare const ContextMenuContent: React.ForwardRefExoticComponent<ContextMenuContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
20
|
+
|
|
21
|
+
export declare const ContextMenuGroup: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
22
|
+
export interface ContextMenuLabelProps extends React.HTMLAttributes<HTMLDivElement> { inset?: boolean; }
|
|
23
|
+
export declare const ContextMenuLabel: React.ForwardRefExoticComponent<ContextMenuLabelProps & React.RefAttributes<HTMLDivElement>>;
|
|
24
|
+
export declare const ContextMenuSeparator: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
|
|
25
|
+
export declare const ContextMenuShortcut: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & React.RefAttributes<HTMLSpanElement>>;
|
|
26
|
+
|
|
27
|
+
export interface ContextMenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { inset?: boolean; variant?: 'default' | 'destructive'; onSelect?: (event: React.SyntheticEvent) => void; }
|
|
28
|
+
export declare const ContextMenuItem: React.ForwardRefExoticComponent<ContextMenuItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
29
|
+
|
|
30
|
+
export interface ContextMenuCheckboxItemProps extends Omit<ContextMenuItemProps, 'onCheckedChange'> { checked?: boolean; defaultChecked?: boolean; onCheckedChange?: (checked: boolean) => void; }
|
|
31
|
+
export declare const ContextMenuCheckboxItem: React.ForwardRefExoticComponent<ContextMenuCheckboxItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
32
|
+
|
|
33
|
+
export interface ContextMenuRadioGroupProps extends React.HTMLAttributes<HTMLDivElement> { value?: string; defaultValue?: string; onValueChange?: (value: string) => void; }
|
|
34
|
+
export declare function ContextMenuRadioGroup(props: ContextMenuRadioGroupProps): React.JSX.Element;
|
|
35
|
+
export interface ContextMenuRadioItemProps extends ContextMenuItemProps { value: string; }
|
|
36
|
+
export declare const ContextMenuRadioItem: React.ForwardRefExoticComponent<ContextMenuRadioItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
37
|
+
|
|
38
|
+
export interface ContextMenuSubProps { open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; children?: React.ReactNode; }
|
|
39
|
+
export declare function ContextMenuSub(props: ContextMenuSubProps): React.JSX.Element;
|
|
40
|
+
export interface ContextMenuSubTriggerProps extends ContextMenuItemProps {}
|
|
41
|
+
export declare const ContextMenuSubTrigger: React.ForwardRefExoticComponent<ContextMenuSubTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
42
|
+
export interface ContextMenuSubContentProps extends React.HTMLAttributes<HTMLDivElement> { sideOffset?: number; alignOffset?: number; loop?: boolean; }
|
|
43
|
+
export declare const ContextMenuSubContent: React.ForwardRefExoticComponent<ContextMenuSubContentProps & React.RefAttributes<HTMLDivElement>>;
|