@efolusi/meridian 1.21.10 → 1.23.0
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/LICENSE +201 -21
- package/THIRD_PARTY_NOTICES.md +3 -3
- package/ai/AgentRun.js +1 -0
- package/ai/Bubble.js +1 -0
- package/ai/ChatMessage.js +1 -0
- package/ai/Citation.js +45 -22
- package/ai/Confirmation.js +3 -2
- package/ai/Conversation.js +1 -0
- package/ai/DocumentCard.js +1 -0
- package/ai/FeedbackBar.js +1 -0
- package/ai/GeneratedImage.js +1 -0
- package/ai/Marker.js +1 -0
- package/ai/Message.js +1 -0
- package/ai/MessageScroller.js +1 -0
- package/ai/ModelSelector.js +1 -0
- package/ai/Player.js +1 -0
- package/ai/PromptComposer.d.ts +4 -0
- package/ai/PromptComposer.js +8 -1
- package/ai/PromptSteps.js +1 -0
- package/ai/Reasoning.js +1 -0
- package/ai/RichComposer.js +4 -0
- package/ai/Sandbox.js +1 -0
- package/ai/SelectionQuote.js +1 -0
- package/ai/SourceCard.js +13 -4
- package/ai/Suggestions.js +1 -0
- package/ai/Task.js +1 -0
- package/ai/Todo.js +1 -0
- package/ai/ToolCall.js +1 -0
- package/ai/Transcript.js +1 -0
- package/ai/UsageMeter.d.ts +3 -1
- package/ai/UsageMeter.js +9 -2
- package/ai/WebPreview.js +13 -4
- package/code/CodeBlock.js +27 -7
- package/code/Console.js +1 -0
- package/code/CopyField.js +25 -9
- package/code/Diff.js +1 -0
- package/code/EnvList.js +1 -0
- package/code/Exception.js +1 -0
- package/code/Terminal.js +1 -0
- package/components.css +139 -56
- package/data/BarChart.d.ts +4 -0
- package/data/BarChart.js +29 -4
- package/data/Chart.d.ts +1 -1
- package/data/Chart.js +10 -4
- package/data/DonutChart.d.ts +4 -0
- package/data/DonutChart.js +38 -8
- package/data/EmptyState.js +1 -0
- package/data/KeyValueList.js +1 -0
- package/data/LineChart.d.ts +4 -0
- package/data/LineChart.js +30 -7
- package/data/Skeleton.js +1 -0
- package/data/Sparkline.js +1 -0
- package/data/Stat.js +1 -0
- package/data/StatusDot.js +1 -0
- package/data/Table.d.ts +1 -0
- package/data/Table.js +36 -19
- package/dates/Calendar.js +44 -15
- package/dates/TimePicker.js +19 -3
- package/display/Accordion.js +1 -0
- package/display/AspectRatio.js +1 -0
- package/display/Avatar.js +1 -0
- package/display/Badge.js +1 -0
- package/display/Card.js +1 -0
- package/display/Carousel.js +24 -6
- package/display/Collapsible.js +1 -0
- package/display/Direction.js +1 -0
- package/display/Divider.js +1 -0
- package/display/Item.js +1 -0
- package/display/Kbd.js +1 -0
- package/display/Link.js +1 -0
- package/display/Resizable.js +5 -4
- package/display/ScrollArea.js +4 -2
- package/display/Separator.js +1 -0
- package/display/Tag.js +1 -0
- package/display/Timeline.js +1 -0
- package/display/Toolbar.js +2 -0
- package/display/TreeList.js +21 -13
- package/feedback/Alert.js +1 -0
- package/feedback/AlertDialog.js +31 -18
- package/feedback/Banner.js +1 -0
- package/feedback/ConfirmDialog.js +1 -0
- package/feedback/Dialog.js +37 -18
- package/feedback/Loader.js +1 -0
- package/feedback/Progress.js +1 -0
- package/feedback/Spinner.js +1 -0
- package/feedback/Toast.js +10 -3
- package/feedback/Tooltip.js +25 -6
- package/files/Attachment.js +1 -0
- package/files/FileDrop.d.ts +5 -1
- package/files/FileDrop.js +29 -1
- package/files/FileTile.js +1 -0
- package/files/FileTypeIcon.js +1 -0
- package/finance/PaymentCard.js +1 -0
- package/forms/Button.js +55 -0
- package/forms/ButtonGroup.js +1 -0
- package/forms/ButtonTile.js +3 -0
- package/forms/Checkbox.js +1 -0
- package/forms/Combobox.js +31 -9
- package/forms/Field.js +1 -0
- package/forms/IconButton.js +1 -0
- package/forms/Input.js +1 -0
- package/forms/InputGroup.js +1 -0
- package/forms/InputOTP.js +1 -0
- package/forms/Label.js +1 -0
- package/forms/NativeSelect.js +1 -0
- package/forms/NumberInput.js +22 -4
- package/forms/Questionnaire.js +2 -1
- package/forms/Radio.js +1 -0
- package/forms/Select.js +7 -4
- package/forms/Slider.js +26 -3
- package/forms/Switch.js +15 -3
- package/forms/Textarea.js +1 -0
- package/forms/Toggle.js +1 -0
- package/icons/Icon.js +6 -0
- package/icons/_svg.js +1 -1
- package/index.js +3 -3
- package/navigation/Breadcrumbs.js +1 -0
- package/navigation/Menubar.js +1 -0
- package/navigation/NavigationMenu.js +18 -5
- package/navigation/PageControl.js +2 -0
- package/navigation/Pagination.js +1 -0
- package/navigation/SegmentedControl.js +2 -0
- package/navigation/SideNav.js +3 -0
- package/navigation/Sidebar.js +75 -11
- package/navigation/SkipLink.d.ts +2 -1
- package/navigation/SkipLink.js +17 -4
- package/navigation/Steps.js +1 -0
- package/navigation/Tabs.js +1 -0
- package/navigation/TopNav.js +1 -0
- package/overlay/Command.js +2 -0
- package/overlay/ContextMenu.js +40 -13
- package/overlay/Drawer.d.ts +4 -0
- package/overlay/Drawer.js +24 -3
- package/overlay/DropdownMenu.js +40 -13
- package/overlay/HoverCard.js +29 -19
- package/overlay/Popover.js +67 -16
- package/overlay/Portal.js +97 -2
- package/overlay/Sheet.js +1 -0
- package/package.json +2 -2
- package/tailwind.preset.cjs +60 -28
- package/tokens/base.css +19 -3
- package/tokens/colors.css +248 -46
- package/tokens/effects.css +33 -20
- package/tokens/fonts.css +7 -0
- package/tokens/spacing.css +42 -17
- package/tokens/typography.css +29 -8
- package/tokens.json +689 -115
package/overlay/ContextMenu.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
|
|
2
3
|
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
4
|
import React from 'react';
|
|
4
5
|
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
5
6
|
import { Icon } from "../icons/Icon.js";
|
|
6
|
-
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
7
|
+
import { Portal, useAnchoredStyle, useHydrated } from "./Portal.js";
|
|
8
|
+
import { useDirection } from "../display/Direction.js";
|
|
7
9
|
const RootCtx = /*#__PURE__*/React.createContext(null);
|
|
8
10
|
const SubCtx = /*#__PURE__*/React.createContext(null);
|
|
9
11
|
const RadioCtx = /*#__PURE__*/React.createContext(null);
|
|
@@ -15,6 +17,13 @@ const compose = (theirs, ours) => event => {
|
|
|
15
17
|
function menuItems(node) {
|
|
16
18
|
return node ? Array.from(node.querySelectorAll('[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]')).filter(item => !item.disabled && item.dataset.disabled !== 'true') : [];
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
// Submenus portal to their own host, so a pointerdown inside one is outside the
|
|
22
|
+
// root panel's DOM subtree. Every panel of one menu carries the same id.
|
|
23
|
+
function insideMenu(target, id) {
|
|
24
|
+
for (let node = target; node; node = node.parentNode) if (node.dataset && node.dataset.efMenu === id) return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
18
27
|
function focusRelative(node, direction, loop = true) {
|
|
19
28
|
const items = menuItems(node);
|
|
20
29
|
if (!items.length) return;
|
|
@@ -25,7 +34,8 @@ function focusRelative(node, direction, loop = true) {
|
|
|
25
34
|
}
|
|
26
35
|
function useMenuKeyboard(ref, close, {
|
|
27
36
|
sub = false,
|
|
28
|
-
loop = true
|
|
37
|
+
loop = true,
|
|
38
|
+
rtl = false
|
|
29
39
|
} = {}) {
|
|
30
40
|
return event => {
|
|
31
41
|
if (event.defaultPrevented) return;
|
|
@@ -35,7 +45,7 @@ function useMenuKeyboard(ref, close, {
|
|
|
35
45
|
} else if (event.key === 'Home' || event.key === 'End') {
|
|
36
46
|
event.preventDefault();
|
|
37
47
|
focusRelative(ref.current, event.key === 'Home' ? 'first' : 'last');
|
|
38
|
-
} else if (event.key === 'Escape' || sub && event.key === 'ArrowLeft') {
|
|
48
|
+
} else if (event.key === 'Escape' || sub && event.key === (rtl ? 'ArrowRight' : 'ArrowLeft')) {
|
|
39
49
|
event.preventDefault();
|
|
40
50
|
close?.();
|
|
41
51
|
} else if (event.key.length === 1 && /\S/.test(event.key) && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
@@ -65,9 +75,12 @@ export function ContextMenu({
|
|
|
65
75
|
x: 0,
|
|
66
76
|
y: 0
|
|
67
77
|
});
|
|
68
|
-
|
|
78
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
79
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
80
|
+
const open = useHydrated() && (controlled !== undefined ? controlled : inner);
|
|
69
81
|
const triggerRef = React.useRef(null);
|
|
70
82
|
const contentRef = React.useRef(null);
|
|
83
|
+
const menuId = React.useId();
|
|
71
84
|
const setOpen = React.useCallback(next => {
|
|
72
85
|
if (controlled === undefined) setInner(next);
|
|
73
86
|
onOpenChange?.(next);
|
|
@@ -86,8 +99,9 @@ export function ContextMenu({
|
|
|
86
99
|
point,
|
|
87
100
|
triggerRef,
|
|
88
101
|
contentRef,
|
|
89
|
-
modal
|
|
90
|
-
|
|
102
|
+
modal,
|
|
103
|
+
menuId
|
|
104
|
+
}), [open, setOpen, openAt, point, modal, menuId]);
|
|
91
105
|
return /*#__PURE__*/React.createElement(RootCtx.Provider, {
|
|
92
106
|
value: value
|
|
93
107
|
}, children);
|
|
@@ -151,6 +165,7 @@ export const ContextMenuContent = /*#__PURE__*/React.forwardRef(function Context
|
|
|
151
165
|
...rest
|
|
152
166
|
}, forwardedRef) {
|
|
153
167
|
const root = React.useContext(RootCtx);
|
|
168
|
+
const rtl = useDirection() === 'rtl';
|
|
154
169
|
const localRef = React.useRef(null);
|
|
155
170
|
const ref = mergeRefs(forwardedRef, localRef, root?.contentRef);
|
|
156
171
|
const close = React.useCallback(() => {
|
|
@@ -181,7 +196,7 @@ export const ContextMenuContent = /*#__PURE__*/React.forwardRef(function Context
|
|
|
181
196
|
React.useEffect(() => {
|
|
182
197
|
if (!root?.open) return;
|
|
183
198
|
const away = event => {
|
|
184
|
-
if (!
|
|
199
|
+
if (!insideMenu(event.target, root.menuId) && !root.triggerRef.current?.contains(event.target)) close();
|
|
185
200
|
};
|
|
186
201
|
const blur = () => close();
|
|
187
202
|
document.addEventListener('pointerdown', away);
|
|
@@ -192,9 +207,12 @@ export const ContextMenuContent = /*#__PURE__*/React.forwardRef(function Context
|
|
|
192
207
|
};
|
|
193
208
|
}, [root?.open, close]);
|
|
194
209
|
if (!root?.open) return null;
|
|
195
|
-
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
210
|
+
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
211
|
+
dir: rtl ? 'rtl' : undefined
|
|
212
|
+
}, rest, {
|
|
196
213
|
ref: ref,
|
|
197
214
|
role: "menu",
|
|
215
|
+
"data-ef-menu": root.menuId,
|
|
198
216
|
"data-slot": "context-menu-content",
|
|
199
217
|
"data-state": "open",
|
|
200
218
|
className: join('ef-context-menu__content', className),
|
|
@@ -385,7 +403,9 @@ export function ContextMenuSub({
|
|
|
385
403
|
children
|
|
386
404
|
}) {
|
|
387
405
|
const [inner, setInner] = React.useState(defaultOpen);
|
|
388
|
-
|
|
406
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
407
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
408
|
+
const open = useHydrated() && (controlled !== undefined ? controlled : inner);
|
|
389
409
|
const triggerRef = React.useRef(null);
|
|
390
410
|
const contentRef = React.useRef(null);
|
|
391
411
|
const setOpen = next => {
|
|
@@ -410,8 +430,9 @@ export const ContextMenuSubTrigger = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
410
430
|
...props
|
|
411
431
|
}, forwardedRef) {
|
|
412
432
|
const sub = React.useContext(SubCtx);
|
|
433
|
+
const rtl = useDirection() === 'rtl';
|
|
413
434
|
const keyboard = event => {
|
|
414
|
-
if (!disabled && event.key === 'ArrowRight') {
|
|
435
|
+
if (!disabled && event.key === (rtl ? 'ArrowLeft' : 'ArrowRight')) {
|
|
415
436
|
event.preventDefault();
|
|
416
437
|
sub?.setOpen(true);
|
|
417
438
|
requestAnimationFrame(() => menuItems(sub?.contentRef.current)[0]?.focus());
|
|
@@ -447,6 +468,8 @@ export const ContextMenuSubContent = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
447
468
|
...props
|
|
448
469
|
}, forwardedRef) {
|
|
449
470
|
const sub = React.useContext(SubCtx);
|
|
471
|
+
const root = React.useContext(RootCtx);
|
|
472
|
+
const rtl = useDirection() === 'rtl';
|
|
450
473
|
const localRef = React.useRef(null);
|
|
451
474
|
const fallbackTriggerRef = React.useRef(null);
|
|
452
475
|
const fallbackContentRef = React.useRef(null);
|
|
@@ -455,7 +478,7 @@ export const ContextMenuSubContent = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
455
478
|
side
|
|
456
479
|
} = useAnchoredStyle(sub?.triggerRef ?? fallbackTriggerRef, sub?.contentRef ?? fallbackContentRef, {
|
|
457
480
|
open: !!sub?.open,
|
|
458
|
-
placement: 'right',
|
|
481
|
+
placement: rtl ? 'left' : 'right',
|
|
459
482
|
align: 'start',
|
|
460
483
|
offset: sideOffset,
|
|
461
484
|
crossOffset: alignOffset
|
|
@@ -466,15 +489,19 @@ export const ContextMenuSubContent = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
466
489
|
};
|
|
467
490
|
const keyboard = useMenuKeyboard(localRef, close, {
|
|
468
491
|
sub: true,
|
|
469
|
-
loop
|
|
492
|
+
loop,
|
|
493
|
+
rtl
|
|
470
494
|
});
|
|
471
495
|
useIsoLayoutEffect(() => {
|
|
472
496
|
if (sub?.open) menuItems(localRef.current)[0]?.focus();
|
|
473
497
|
}, [sub?.open]);
|
|
474
498
|
if (!sub?.open) return null;
|
|
475
|
-
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
499
|
+
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
500
|
+
dir: rtl ? 'rtl' : undefined
|
|
501
|
+
}, props, {
|
|
476
502
|
ref: mergeRefs(forwardedRef, localRef, sub.contentRef),
|
|
477
503
|
role: "menu",
|
|
504
|
+
"data-ef-menu": root?.menuId,
|
|
478
505
|
"data-slot": "context-menu-sub-content",
|
|
479
506
|
"data-state": "open",
|
|
480
507
|
"data-side": side,
|
package/overlay/Drawer.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export interface DrawerProps {
|
|
|
7
7
|
onOpenChange?: (open: boolean) => void;
|
|
8
8
|
direction?: DrawerDirection;
|
|
9
9
|
dismissible?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Ignored: a Drawer is always modal. Passing `false` logs a development warning; the prop will be removed in the next major version. Migration: https://meridian.efolusi.com/guidelines/migration.md
|
|
12
|
+
* @codemod remove
|
|
13
|
+
*/
|
|
10
14
|
modal?: boolean;
|
|
11
15
|
handleOnly?: boolean;
|
|
12
16
|
children?: React.ReactNode;
|
package/overlay/Drawer.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
|
|
2
3
|
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
4
|
import React from 'react';
|
|
5
|
+
import { useHydrated } from "./Portal.js";
|
|
4
6
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger } from "../feedback/Dialog.js";
|
|
5
7
|
const DrawerContext = /*#__PURE__*/React.createContext(null);
|
|
6
8
|
const join = (...values) => values.filter(Boolean).join(' ');
|
|
@@ -8,6 +10,21 @@ const compose = (first, second) => event => {
|
|
|
8
10
|
first?.(event);
|
|
9
11
|
if (!event.defaultPrevented) second?.(event);
|
|
10
12
|
};
|
|
13
|
+
|
|
14
|
+
// Deprecated props keep working until the next major, with one warning per
|
|
15
|
+
// page outside production builds.
|
|
16
|
+
let warnedModal = false;
|
|
17
|
+
function warnModalIgnored() {
|
|
18
|
+
if (warnedModal || typeof console === 'undefined') return;
|
|
19
|
+
// Bare `process.env.NODE_ENV` so bundlers (Vite, webpack, esbuild) fold it to a
|
|
20
|
+
// literal; `typeof process` is not replaced and would keep the warning in
|
|
21
|
+
// production. Where nothing defines it, the read throws and we warn.
|
|
22
|
+
try {
|
|
23
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
24
|
+
} catch (e) {/* no build-time env */}
|
|
25
|
+
warnedModal = true;
|
|
26
|
+
console.warn('[meridian] <Drawer modal={false}> is deprecated and ignored: a Drawer is always modal. The prop will be removed in the next major version. Migration: https://meridian.efolusi.com/guidelines/migration.md');
|
|
27
|
+
}
|
|
11
28
|
export function Drawer({
|
|
12
29
|
open: controlled,
|
|
13
30
|
defaultOpen = false,
|
|
@@ -18,8 +35,13 @@ export function Drawer({
|
|
|
18
35
|
handleOnly = false,
|
|
19
36
|
children
|
|
20
37
|
}) {
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
if (modal === false) warnModalIgnored();
|
|
40
|
+
}, [modal]);
|
|
21
41
|
const [internal, setInternal] = React.useState(defaultOpen);
|
|
22
|
-
|
|
42
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
43
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
44
|
+
const open = useHydrated() && (controlled === undefined ? internal : controlled);
|
|
23
45
|
const setOpen = React.useCallback(next => {
|
|
24
46
|
if (controlled === undefined) setInternal(next);
|
|
25
47
|
onOpenChange?.(next);
|
|
@@ -35,8 +57,7 @@ export function Drawer({
|
|
|
35
57
|
value: context
|
|
36
58
|
}, /*#__PURE__*/React.createElement(Dialog, {
|
|
37
59
|
open: open,
|
|
38
|
-
onOpenChange: setOpen
|
|
39
|
-
modal: modal
|
|
60
|
+
onOpenChange: setOpen
|
|
40
61
|
}, children));
|
|
41
62
|
}
|
|
42
63
|
export const DrawerTrigger = /*#__PURE__*/React.forwardRef(function DrawerTrigger(props, ref) {
|
package/overlay/DropdownMenu.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
|
|
2
3
|
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
4
|
import React from 'react';
|
|
4
5
|
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
5
6
|
import { Icon } from "../icons/Icon.js";
|
|
6
|
-
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
7
|
+
import { Portal, useAnchoredStyle, useHydrated } from "./Portal.js";
|
|
8
|
+
import { useDirection } from "../display/Direction.js";
|
|
7
9
|
const RootCtx = /*#__PURE__*/React.createContext(null);
|
|
8
10
|
const SubCtx = /*#__PURE__*/React.createContext(null);
|
|
9
11
|
const RadioCtx = /*#__PURE__*/React.createContext(null);
|
|
@@ -15,6 +17,13 @@ const compose = (theirs, ours) => event => {
|
|
|
15
17
|
function menuItems(node) {
|
|
16
18
|
return node ? Array.from(node.querySelectorAll('[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]')).filter(item => !item.disabled && item.dataset.disabled !== 'true') : [];
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
// Submenus portal to their own host, so a pointerdown inside one is outside the
|
|
22
|
+
// root panel's DOM subtree. Every panel of one menu carries the same id.
|
|
23
|
+
function insideMenu(target, id) {
|
|
24
|
+
for (let node = target; node; node = node.parentNode) if (node.dataset && node.dataset.efMenu === id) return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
18
27
|
function focusRelative(node, direction, loop = true) {
|
|
19
28
|
const items = menuItems(node);
|
|
20
29
|
if (!items.length) return;
|
|
@@ -25,7 +34,8 @@ function focusRelative(node, direction, loop = true) {
|
|
|
25
34
|
}
|
|
26
35
|
function useMenuKeyboard(ref, close, {
|
|
27
36
|
sub = false,
|
|
28
|
-
loop = true
|
|
37
|
+
loop = true,
|
|
38
|
+
rtl = false
|
|
29
39
|
} = {}) {
|
|
30
40
|
return event => {
|
|
31
41
|
if (event.defaultPrevented) return;
|
|
@@ -35,7 +45,7 @@ function useMenuKeyboard(ref, close, {
|
|
|
35
45
|
} else if (event.key === 'Home' || event.key === 'End') {
|
|
36
46
|
event.preventDefault();
|
|
37
47
|
focusRelative(ref.current, event.key === 'Home' ? 'first' : 'last');
|
|
38
|
-
} else if (event.key === 'Escape' || sub && event.key === 'ArrowLeft') {
|
|
48
|
+
} else if (event.key === 'Escape' || sub && event.key === (rtl ? 'ArrowRight' : 'ArrowLeft')) {
|
|
39
49
|
event.preventDefault();
|
|
40
50
|
close?.();
|
|
41
51
|
} else if (event.key.length === 1 && /\S/.test(event.key) && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
@@ -61,9 +71,12 @@ export function DropdownMenu({
|
|
|
61
71
|
children
|
|
62
72
|
}) {
|
|
63
73
|
const [inner, setInner] = React.useState(defaultOpen);
|
|
64
|
-
|
|
74
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
75
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
76
|
+
const open = useHydrated() && (controlled !== undefined ? controlled : inner);
|
|
65
77
|
const triggerRef = React.useRef(null);
|
|
66
78
|
const contentRef = React.useRef(null);
|
|
79
|
+
const menuId = React.useId();
|
|
67
80
|
const setOpen = React.useCallback(next => {
|
|
68
81
|
if (controlled === undefined) setInner(next);
|
|
69
82
|
onOpenChange?.(next);
|
|
@@ -73,8 +86,9 @@ export function DropdownMenu({
|
|
|
73
86
|
setOpen,
|
|
74
87
|
triggerRef,
|
|
75
88
|
contentRef,
|
|
76
|
-
modal
|
|
77
|
-
|
|
89
|
+
modal,
|
|
90
|
+
menuId
|
|
91
|
+
}), [open, setOpen, modal, menuId]);
|
|
78
92
|
return /*#__PURE__*/React.createElement(RootCtx.Provider, {
|
|
79
93
|
value: value
|
|
80
94
|
}, children);
|
|
@@ -147,6 +161,7 @@ export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function Dropdo
|
|
|
147
161
|
...rest
|
|
148
162
|
}, forwardedRef) {
|
|
149
163
|
const root = React.useContext(RootCtx);
|
|
164
|
+
const rtl = useDirection() === 'rtl';
|
|
150
165
|
const localRef = React.useRef(null);
|
|
151
166
|
const ref = mergeRefs(forwardedRef, localRef, root?.contentRef);
|
|
152
167
|
const fallbackTriggerRef = React.useRef(null);
|
|
@@ -181,7 +196,7 @@ export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function Dropdo
|
|
|
181
196
|
React.useEffect(() => {
|
|
182
197
|
if (!root?.open) return;
|
|
183
198
|
const away = event => {
|
|
184
|
-
if (!
|
|
199
|
+
if (!insideMenu(event.target, root.menuId) && !root.triggerRef.current?.contains(event.target)) close();
|
|
185
200
|
};
|
|
186
201
|
const blur = () => close();
|
|
187
202
|
document.addEventListener('pointerdown', away);
|
|
@@ -192,9 +207,12 @@ export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function Dropdo
|
|
|
192
207
|
};
|
|
193
208
|
}, [root?.open, close]);
|
|
194
209
|
if (!root?.open) return null;
|
|
195
|
-
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
210
|
+
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
211
|
+
dir: rtl ? 'rtl' : undefined
|
|
212
|
+
}, rest, {
|
|
196
213
|
ref: ref,
|
|
197
214
|
role: "menu",
|
|
215
|
+
"data-ef-menu": root.menuId,
|
|
198
216
|
"data-slot": slot,
|
|
199
217
|
"data-state": "open",
|
|
200
218
|
"data-side": resolvedSide,
|
|
@@ -396,7 +414,9 @@ export function DropdownMenuSub({
|
|
|
396
414
|
children
|
|
397
415
|
}) {
|
|
398
416
|
const [inner, setInner] = React.useState(defaultOpen);
|
|
399
|
-
|
|
417
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
418
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
419
|
+
const open = useHydrated() && (controlled !== undefined ? controlled : inner);
|
|
400
420
|
const triggerRef = React.useRef(null);
|
|
401
421
|
const contentRef = React.useRef(null);
|
|
402
422
|
const setOpen = next => {
|
|
@@ -422,8 +442,9 @@ export const DropdownMenuSubTrigger = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
422
442
|
...props
|
|
423
443
|
}, forwardedRef) {
|
|
424
444
|
const sub = React.useContext(SubCtx);
|
|
445
|
+
const rtl = useDirection() === 'rtl';
|
|
425
446
|
const keyboard = event => {
|
|
426
|
-
if (!disabled && event.key === 'ArrowRight') {
|
|
447
|
+
if (!disabled && event.key === (rtl ? 'ArrowLeft' : 'ArrowRight')) {
|
|
427
448
|
event.preventDefault();
|
|
428
449
|
sub?.setOpen(true);
|
|
429
450
|
requestAnimationFrame(() => menuItems(sub?.contentRef.current)[0]?.focus());
|
|
@@ -460,6 +481,8 @@ export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
460
481
|
...props
|
|
461
482
|
}, forwardedRef) {
|
|
462
483
|
const sub = React.useContext(SubCtx);
|
|
484
|
+
const root = React.useContext(RootCtx);
|
|
485
|
+
const rtl = useDirection() === 'rtl';
|
|
463
486
|
const localRef = React.useRef(null);
|
|
464
487
|
const fallbackTriggerRef = React.useRef(null);
|
|
465
488
|
const fallbackContentRef = React.useRef(null);
|
|
@@ -468,7 +491,7 @@ export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
468
491
|
side
|
|
469
492
|
} = useAnchoredStyle(sub?.triggerRef ?? fallbackTriggerRef, sub?.contentRef ?? fallbackContentRef, {
|
|
470
493
|
open: !!sub?.open,
|
|
471
|
-
placement: 'right',
|
|
494
|
+
placement: rtl ? 'left' : 'right',
|
|
472
495
|
align: 'start',
|
|
473
496
|
offset: sideOffset,
|
|
474
497
|
crossOffset: alignOffset
|
|
@@ -479,15 +502,19 @@ export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
479
502
|
};
|
|
480
503
|
const keyboard = useMenuKeyboard(localRef, close, {
|
|
481
504
|
sub: true,
|
|
482
|
-
loop
|
|
505
|
+
loop,
|
|
506
|
+
rtl
|
|
483
507
|
});
|
|
484
508
|
useIsoLayoutEffect(() => {
|
|
485
509
|
if (sub?.open) menuItems(localRef.current)[0]?.focus();
|
|
486
510
|
}, [sub?.open]);
|
|
487
511
|
if (!sub?.open) return null;
|
|
488
|
-
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
512
|
+
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
513
|
+
dir: rtl ? 'rtl' : undefined
|
|
514
|
+
}, props, {
|
|
489
515
|
ref: mergeRefs(forwardedRef, localRef, sub.contentRef),
|
|
490
516
|
role: "menu",
|
|
517
|
+
"data-ef-menu": root?.menuId,
|
|
491
518
|
"data-slot": slot,
|
|
492
519
|
"data-state": "open",
|
|
493
520
|
"data-side": side,
|
package/overlay/HoverCard.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
|
|
2
3
|
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
4
|
import React from 'react';
|
|
4
|
-
import { mergeRefs } from "../forms/Button.js";
|
|
5
|
-
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
5
|
+
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
6
|
+
import { Portal, useAnchoredStyle, useEscapeLayer, escapeLayerContext, useHydrated } from "./Portal.js";
|
|
6
7
|
const HoverCardCtx = /*#__PURE__*/React.createContext(null);
|
|
7
8
|
function compose(theirs, ours) {
|
|
8
9
|
return event => {
|
|
@@ -19,11 +20,17 @@ export function HoverCard({
|
|
|
19
20
|
children
|
|
20
21
|
}) {
|
|
21
22
|
const [inner, setInner] = React.useState(defaultOpen);
|
|
22
|
-
|
|
23
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
24
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
25
|
+
const open = useHydrated() && (controlled !== undefined ? controlled : inner);
|
|
23
26
|
const triggerRef = React.useRef(null);
|
|
24
27
|
const contentRef = React.useRef(null);
|
|
25
28
|
const timerRef = React.useRef(null);
|
|
26
|
-
|
|
29
|
+
// The content's own `id` wins over the generated one, and the trigger's
|
|
30
|
+
// aria attribute follows whichever is rendered.
|
|
31
|
+
const baseId = React.useId();
|
|
32
|
+
const [customId, setContentId] = React.useState();
|
|
33
|
+
const contentId = customId || baseId;
|
|
27
34
|
const setOpen = React.useCallback(next => {
|
|
28
35
|
if (controlled === undefined) setInner(next);
|
|
29
36
|
onOpenChange?.(next);
|
|
@@ -38,17 +45,10 @@ export function HoverCard({
|
|
|
38
45
|
timerRef.current = setTimeout(() => setOpen(false), closeDelay);
|
|
39
46
|
}, [clearTimer, closeDelay, setOpen]);
|
|
40
47
|
React.useEffect(() => clearTimer, [clearTimer]);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
clearTimer();
|
|
46
|
-
setOpen(false);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
document.addEventListener('keydown', key);
|
|
50
|
-
return () => document.removeEventListener('keydown', key);
|
|
51
|
-
}, [clearTimer, open, setOpen]);
|
|
48
|
+
const layer = useEscapeLayer(open, () => {
|
|
49
|
+
clearTimer();
|
|
50
|
+
setOpen(false);
|
|
51
|
+
});
|
|
52
52
|
const value = React.useMemo(() => ({
|
|
53
53
|
open,
|
|
54
54
|
setOpen,
|
|
@@ -57,11 +57,14 @@ export function HoverCard({
|
|
|
57
57
|
clearTimer,
|
|
58
58
|
triggerRef,
|
|
59
59
|
contentRef,
|
|
60
|
-
contentId
|
|
61
|
-
|
|
60
|
+
contentId,
|
|
61
|
+
setContentId
|
|
62
|
+
}), [open, setOpen, openSoon, closeSoon, clearTimer, contentId, setContentId]);
|
|
62
63
|
return /*#__PURE__*/React.createElement(HoverCardCtx.Provider, {
|
|
63
64
|
value: value
|
|
64
|
-
},
|
|
65
|
+
}, /*#__PURE__*/React.createElement(escapeLayerContext.Provider, {
|
|
66
|
+
value: layer
|
|
67
|
+
}, children));
|
|
65
68
|
}
|
|
66
69
|
export const HoverCardTrigger = /*#__PURE__*/React.forwardRef(function HoverCardTrigger({
|
|
67
70
|
asChild = false,
|
|
@@ -111,9 +114,16 @@ export const HoverCardContent = /*#__PURE__*/React.forwardRef(function HoverCard
|
|
|
111
114
|
className,
|
|
112
115
|
style,
|
|
113
116
|
children,
|
|
117
|
+
id,
|
|
114
118
|
...rest
|
|
115
119
|
}, forwardedRef) {
|
|
116
120
|
const ctx = React.useContext(HoverCardCtx);
|
|
121
|
+
const registerId = ctx?.setContentId;
|
|
122
|
+
useIsoLayoutEffect(() => {
|
|
123
|
+
if (!registerId) return;
|
|
124
|
+
registerId(id);
|
|
125
|
+
return () => registerId(undefined);
|
|
126
|
+
}, [registerId, id]);
|
|
117
127
|
const fallbackTriggerRef = React.useRef(null);
|
|
118
128
|
const fallbackContentRef = React.useRef(null);
|
|
119
129
|
const {
|
|
@@ -129,7 +139,7 @@ export const HoverCardContent = /*#__PURE__*/React.forwardRef(function HoverCard
|
|
|
129
139
|
if (!ctx?.open) return null;
|
|
130
140
|
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
131
141
|
ref: mergeRefs(forwardedRef, ctx.contentRef),
|
|
132
|
-
id: ctx.contentId,
|
|
142
|
+
id: id || ctx.contentId,
|
|
133
143
|
"data-slot": "hover-card-content",
|
|
134
144
|
"data-state": "open",
|
|
135
145
|
"data-side": resolvedSide,
|
package/overlay/Popover.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
|
|
2
3
|
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
4
|
import React from 'react';
|
|
4
|
-
import { mergeRefs } from "../forms/Button.js";
|
|
5
|
-
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
5
|
+
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
6
|
+
import { Portal, useAnchoredStyle, useEscapeLayer, escapeLayerContext, useHydrated } from "./Portal.js";
|
|
6
7
|
const PopoverCtx = /*#__PURE__*/React.createContext(null);
|
|
8
|
+
const TABBABLE = 'a[href],button,input,select,textarea,[tabindex]';
|
|
9
|
+
const tabbable = root => [...root.querySelectorAll(TABBABLE)].filter(node => !node.disabled && node.tabIndex >= 0 && !node.closest('[hidden]'));
|
|
7
10
|
function compose(theirs, ours) {
|
|
8
11
|
return event => {
|
|
9
12
|
theirs?.(event);
|
|
@@ -17,10 +20,16 @@ export function Popover({
|
|
|
17
20
|
onOpenChange
|
|
18
21
|
}) {
|
|
19
22
|
const [inner, setInner] = React.useState(defaultOpen);
|
|
20
|
-
|
|
23
|
+
// Closed while React hydrates server HTML (the server rendered no portal),
|
|
24
|
+
// open right after, so effects keyed on it run with the panel present.
|
|
25
|
+
const open = useHydrated() && (controlled !== undefined ? controlled : inner);
|
|
21
26
|
const triggerRef = React.useRef(null);
|
|
22
27
|
const contentRef = React.useRef(null);
|
|
23
|
-
|
|
28
|
+
// The content's own `id` wins over the generated one, and the trigger's
|
|
29
|
+
// aria attribute follows whichever is rendered.
|
|
30
|
+
const baseId = React.useId();
|
|
31
|
+
const [customId, setContentId] = React.useState();
|
|
32
|
+
const contentId = customId || baseId;
|
|
24
33
|
const setOpen = React.useCallback(next => {
|
|
25
34
|
if (controlled === undefined) setInner(next);
|
|
26
35
|
onOpenChange?.(next);
|
|
@@ -30,31 +39,66 @@ export function Popover({
|
|
|
30
39
|
setOpen,
|
|
31
40
|
triggerRef,
|
|
32
41
|
contentRef,
|
|
33
|
-
contentId
|
|
34
|
-
|
|
42
|
+
contentId,
|
|
43
|
+
setContentId
|
|
44
|
+
}), [open, setOpen, contentId, setContentId]);
|
|
35
45
|
React.useEffect(() => {
|
|
36
46
|
if (!open) return;
|
|
37
47
|
const away = event => {
|
|
38
48
|
if (!triggerRef.current?.contains(event.target) && !contentRef.current?.contains(event.target)) setOpen(false);
|
|
39
49
|
};
|
|
40
|
-
const key = event => {
|
|
41
|
-
if (event.key === 'Escape') {
|
|
42
|
-
setOpen(false);
|
|
43
|
-
triggerRef.current?.focus();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
50
|
document.addEventListener('pointerdown', away);
|
|
47
51
|
document.addEventListener('mousedown', away);
|
|
48
|
-
document.addEventListener('keydown', key);
|
|
49
52
|
return () => {
|
|
50
53
|
document.removeEventListener('pointerdown', away);
|
|
51
54
|
document.removeEventListener('mousedown', away);
|
|
52
|
-
document.removeEventListener('keydown', key);
|
|
53
55
|
};
|
|
54
56
|
}, [open, setOpen]);
|
|
57
|
+
// The panel is portaled to the end of <body>, so the browser's Tab order
|
|
58
|
+
// runs from the trigger straight past it. Stitch it back in: Tab from the
|
|
59
|
+
// trigger enters the panel, Shift+Tab from its first stop returns to the
|
|
60
|
+
// trigger, and Tab past its last stop continues after the trigger.
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
if (!open) return;
|
|
63
|
+
const tab = event => {
|
|
64
|
+
if (event.key !== 'Tab' || event.defaultPrevented) return;
|
|
65
|
+
const trigger = triggerRef.current;
|
|
66
|
+
const panel = contentRef.current;
|
|
67
|
+
if (!trigger || !panel) return;
|
|
68
|
+
const inside = tabbable(panel);
|
|
69
|
+
const active = document.activeElement;
|
|
70
|
+
if (active === trigger && !event.shiftKey && inside.length) {
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
inside[0].focus();
|
|
73
|
+
} else if (event.shiftKey && inside.length && active === inside[0]) {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
trigger.focus();
|
|
76
|
+
} else if (!event.shiftKey && (inside.length ? active === inside[inside.length - 1] : active === panel)) {
|
|
77
|
+
// inside a modal the order wraps within that modal, not the page
|
|
78
|
+
const modal = trigger.closest('[aria-modal="true"]');
|
|
79
|
+
const page = tabbable(modal || document.body).filter(node => !panel.contains(node));
|
|
80
|
+
const next = page[page.indexOf(trigger) + 1] || (modal ? page[0] : undefined);
|
|
81
|
+
if (next) {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
next.focus();
|
|
84
|
+
}
|
|
85
|
+
setOpen(false);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// capture phase: a dialog's focus trap listening on document must see the
|
|
89
|
+
// key already handled, or it would wrap focus away from the panel
|
|
90
|
+
document.addEventListener('keydown', tab, true);
|
|
91
|
+
return () => document.removeEventListener('keydown', tab, true);
|
|
92
|
+
}, [open, setOpen]);
|
|
93
|
+
const layer = useEscapeLayer(open, () => {
|
|
94
|
+
setOpen(false);
|
|
95
|
+
triggerRef.current?.focus();
|
|
96
|
+
});
|
|
55
97
|
return /*#__PURE__*/React.createElement(PopoverCtx.Provider, {
|
|
56
98
|
value: value
|
|
57
|
-
},
|
|
99
|
+
}, /*#__PURE__*/React.createElement(escapeLayerContext.Provider, {
|
|
100
|
+
value: layer
|
|
101
|
+
}, children));
|
|
58
102
|
}
|
|
59
103
|
export const PopoverTrigger = /*#__PURE__*/React.forwardRef(function PopoverTrigger({
|
|
60
104
|
asChild = false,
|
|
@@ -101,9 +145,16 @@ export const PopoverContent = /*#__PURE__*/React.forwardRef(function PopoverCont
|
|
|
101
145
|
className,
|
|
102
146
|
style,
|
|
103
147
|
children,
|
|
148
|
+
id,
|
|
104
149
|
...rest
|
|
105
150
|
}, forwardedRef) {
|
|
106
151
|
const ctx = React.useContext(PopoverCtx);
|
|
152
|
+
const registerId = ctx?.setContentId;
|
|
153
|
+
useIsoLayoutEffect(() => {
|
|
154
|
+
if (!registerId) return;
|
|
155
|
+
registerId(id);
|
|
156
|
+
return () => registerId(undefined);
|
|
157
|
+
}, [registerId, id]);
|
|
107
158
|
const fallbackTriggerRef = React.useRef(null);
|
|
108
159
|
const fallbackContentRef = React.useRef(null);
|
|
109
160
|
const placement = side === 'top' ? 'top' : 'bottom';
|
|
@@ -118,7 +169,7 @@ export const PopoverContent = /*#__PURE__*/React.forwardRef(function PopoverCont
|
|
|
118
169
|
if (!ctx?.open) return null;
|
|
119
170
|
return /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
120
171
|
ref: mergeRefs(forwardedRef, ctx.contentRef),
|
|
121
|
-
id: ctx.contentId,
|
|
172
|
+
id: id || ctx.contentId,
|
|
122
173
|
role: role,
|
|
123
174
|
"data-slot": "popover-content",
|
|
124
175
|
"data-state": "open",
|