@efolusi/meridian 1.21.9 → 1.22.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/THIRD_PARTY_NOTICES.md +1 -1
- package/ai/Citation.js +44 -22
- package/ai/Confirmation.js +2 -2
- package/ai/PromptComposer.d.ts +4 -0
- package/ai/PromptComposer.js +7 -1
- package/ai/RichComposer.js +3 -0
- package/ai/SourceCard.js +12 -4
- package/ai/UsageMeter.d.ts +3 -1
- package/ai/UsageMeter.js +8 -2
- package/ai/WebPreview.js +12 -4
- package/code/CodeBlock.js +26 -7
- package/code/CopyField.js +24 -9
- package/components.css +141 -58
- package/data/BarChart.d.ts +4 -0
- package/data/BarChart.js +28 -4
- package/data/Chart.d.ts +1 -1
- package/data/Chart.js +5 -2
- package/data/DonutChart.d.ts +4 -0
- package/data/DonutChart.js +38 -8
- package/data/LineChart.d.ts +4 -0
- package/data/LineChart.js +29 -7
- package/data/Table.d.ts +1 -0
- package/data/Table.js +35 -19
- package/dates/Calendar.js +43 -15
- package/dates/TimePicker.js +18 -3
- package/display/Toolbar.js +1 -0
- package/display/TreeList.js +20 -13
- package/feedback/AlertDialog.js +12 -12
- package/feedback/Dialog.js +17 -12
- package/feedback/Toast.js +5 -2
- package/feedback/Tooltip.js +5 -1
- package/files/FileDrop.d.ts +5 -1
- package/files/FileDrop.js +28 -1
- package/forms/ButtonTile.js +2 -0
- package/forms/Combobox.js +21 -5
- package/forms/NumberInput.js +21 -4
- package/forms/Questionnaire.js +1 -1
- package/forms/Slider.js +2 -1
- package/forms/Switch.js +14 -3
- package/index.js +3 -3
- package/navigation/NavigationMenu.js +17 -5
- package/navigation/PageControl.js +1 -0
- package/navigation/SegmentedControl.js +1 -0
- package/navigation/SideNav.js +2 -0
- package/navigation/Sidebar.js +74 -11
- package/navigation/SkipLink.d.ts +2 -1
- package/navigation/SkipLink.js +16 -4
- package/overlay/Command.js +1 -0
- package/overlay/ContextMenu.js +32 -10
- package/overlay/Drawer.d.ts +1 -0
- package/overlay/Drawer.js +19 -2
- package/overlay/DropdownMenu.js +32 -10
- package/overlay/HoverCard.js +8 -13
- package/overlay/Popover.js +46 -10
- package/overlay/Portal.js +67 -2
- package/package.json +1 -1
- package/tailwind.preset.cjs +34 -13
- package/tokens/base.css +5 -0
- package/tokens/colors.css +7 -3
- package/tokens.json +427 -95
package/navigation/Sidebar.js
CHANGED
|
@@ -3,7 +3,12 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { Icon } from "../icons/Icon.js";
|
|
5
5
|
import { mergeRefs } from "../forms/Button.js";
|
|
6
|
+
import { useScrollLock, useEscapeLayer, escapeLayerContext } from "../overlay/Portal.js";
|
|
6
7
|
const SidebarContext = /*#__PURE__*/React.createContext(null);
|
|
8
|
+
// Cmd/Ctrl+B is "bold" in every text field and rich-text editor; the sidebar
|
|
9
|
+
// shortcut must not take it from them.
|
|
10
|
+
const EDITABLE = 'input,textarea,select,[contenteditable]:not([contenteditable="false"])';
|
|
11
|
+
const isEditable = target => !!(target && target.closest && target.closest(EDITABLE));
|
|
7
12
|
const join = (...parts) => parts.filter(Boolean).join(' ');
|
|
8
13
|
function compose(render, fallback, props, ref, children) {
|
|
9
14
|
if (/*#__PURE__*/React.isValidElement(render)) return /*#__PURE__*/React.cloneElement(render, {
|
|
@@ -52,18 +57,14 @@ export const SidebarProvider = /*#__PURE__*/React.forwardRef(function SidebarPro
|
|
|
52
57
|
}, []);
|
|
53
58
|
React.useEffect(() => {
|
|
54
59
|
const onKeyDown = event => {
|
|
55
|
-
if (event.key === '
|
|
56
|
-
event.preventDefault();
|
|
57
|
-
setOpenMobile(false);
|
|
58
|
-
}
|
|
59
|
-
if (event.key.toLowerCase() === 'b' && (event.metaKey || event.ctrlKey)) {
|
|
60
|
+
if (typeof event.key === 'string' && event.key.toLowerCase() === 'b' && (event.metaKey || event.ctrlKey) && !isEditable(event.target)) {
|
|
60
61
|
event.preventDefault();
|
|
61
62
|
toggleSidebar();
|
|
62
63
|
}
|
|
63
64
|
};
|
|
64
65
|
window.addEventListener('keydown', onKeyDown);
|
|
65
66
|
return () => window.removeEventListener('keydown', onKeyDown);
|
|
66
|
-
}, [
|
|
67
|
+
}, [toggleSidebar]);
|
|
67
68
|
const context = React.useMemo(() => ({
|
|
68
69
|
state: open ? 'expanded' : 'collapsed',
|
|
69
70
|
open,
|
|
@@ -110,17 +111,79 @@ export const Sidebar = /*#__PURE__*/React.forwardRef(function Sidebar({
|
|
|
110
111
|
}), /*#__PURE__*/React.createElement("div", {
|
|
111
112
|
"data-slot": "sidebar-container",
|
|
112
113
|
className: "ef-sidebar__panel"
|
|
113
|
-
}, children)), context.openMobile ? /*#__PURE__*/React.createElement(
|
|
114
|
+
}, children)), context.openMobile ? /*#__PURE__*/React.createElement(MobileSidebarPanel, {
|
|
115
|
+
common: common,
|
|
116
|
+
dir: dir,
|
|
117
|
+
label: props['aria-label'] || 'Sidebar',
|
|
118
|
+
onClose: () => context.setOpenMobile(false)
|
|
119
|
+
}, children) : null);
|
|
120
|
+
});
|
|
121
|
+
const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
|
122
|
+
|
|
123
|
+
// The off-canvas sidebar on a phone covers the page behind a backdrop, so it
|
|
124
|
+
// behaves as a modal dialog: focus moves in, Tab stays in, the page does not
|
|
125
|
+
// scroll, and closing returns focus to whatever opened it. Escape goes through
|
|
126
|
+
// the shared layer stack, so a menu, popover or dialog opened inside the panel
|
|
127
|
+
// closes first and the panel only on the next press.
|
|
128
|
+
function MobileSidebarPanel({
|
|
129
|
+
common,
|
|
130
|
+
dir,
|
|
131
|
+
label,
|
|
132
|
+
onClose,
|
|
133
|
+
children
|
|
134
|
+
}) {
|
|
135
|
+
const panelRef = React.useRef(null);
|
|
136
|
+
useScrollLock(true);
|
|
137
|
+
const layer = useEscapeLayer(true, event => {
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
onClose();
|
|
140
|
+
});
|
|
141
|
+
React.useEffect(() => {
|
|
142
|
+
const previous = document.activeElement;
|
|
143
|
+
const panel = panelRef.current;
|
|
144
|
+
(panel?.querySelector(FOCUSABLE) || panel)?.focus();
|
|
145
|
+
return () => {
|
|
146
|
+
if (previous && previous.isConnected && previous.focus) previous.focus();
|
|
147
|
+
};
|
|
148
|
+
}, []);
|
|
149
|
+
const keydown = event => {
|
|
150
|
+
if (event.key !== 'Tab' || event.defaultPrevented) return;
|
|
151
|
+
// focus inside a portaled child layer (a popover) is that layer's business
|
|
152
|
+
if (layer.children > 0 && !panelRef.current?.contains(document.activeElement)) return;
|
|
153
|
+
const items = Array.from(panelRef.current?.querySelectorAll(FOCUSABLE) || []);
|
|
154
|
+
if (!items.length) {
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const index = items.indexOf(document.activeElement);
|
|
159
|
+
if (event.shiftKey && index <= 0) {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
items[items.length - 1].focus();
|
|
162
|
+
} else if (!event.shiftKey && (index < 0 || index === items.length - 1)) {
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
items[0].focus();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
|
|
114
168
|
type: "button",
|
|
115
169
|
className: "ef-sidebar-mobile-backdrop",
|
|
116
170
|
"aria-label": "Close sidebar",
|
|
117
|
-
|
|
171
|
+
tabIndex: -1,
|
|
172
|
+
onClick: onClose
|
|
118
173
|
}), /*#__PURE__*/React.createElement("aside", _extends({}, common, {
|
|
174
|
+
ref: panelRef,
|
|
119
175
|
dir: dir,
|
|
120
176
|
"data-mobile": "true",
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
177
|
+
role: "dialog",
|
|
178
|
+
"aria-modal": "true",
|
|
179
|
+
"aria-label": label,
|
|
180
|
+
tabIndex: -1,
|
|
181
|
+
className: "ef-sidebar-mobile",
|
|
182
|
+
onKeyDown: keydown
|
|
183
|
+
}), /*#__PURE__*/React.createElement(escapeLayerContext.Provider, {
|
|
184
|
+
value: layer
|
|
185
|
+
}, children)));
|
|
186
|
+
}
|
|
124
187
|
export const SidebarTrigger = /*#__PURE__*/React.forwardRef(function SidebarTrigger({
|
|
125
188
|
render,
|
|
126
189
|
className,
|
package/navigation/SkipLink.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface SkipLinkProps {
|
|
2
|
-
/**
|
|
2
|
+
/** Fragment of the target landmark. The link focuses it directly (adding tabIndex=-1 if needed) without changing location.hash. @default '#main' */
|
|
3
3
|
href?: string;
|
|
4
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
4
5
|
children?: React.ReactNode;
|
|
5
6
|
style?: React.CSSProperties;
|
|
6
7
|
className?: string;
|
package/navigation/SkipLink.js
CHANGED
|
@@ -5,20 +5,32 @@ import React from 'react';
|
|
|
5
5
|
* First focusable element on the page: one Tab press moves a keyboard user past
|
|
6
6
|
* the whole header into the content.
|
|
7
7
|
*
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* The link moves focus to its target itself instead of following the hash:
|
|
9
|
+
* a plain jump changes location.hash, which a hash-based router reads as a
|
|
10
|
+
* route, and Safari and Firefox scroll without moving focus unless the target
|
|
11
|
+
* is focusable. The target gets `tabIndex=-1` when it has no tabindex, then
|
|
12
|
+
* receives focus. An onClick that calls preventDefault keeps full control.
|
|
12
13
|
*/
|
|
13
14
|
export function SkipLink({
|
|
14
15
|
href = '#main',
|
|
15
16
|
children = 'Skip to content',
|
|
16
17
|
style,
|
|
17
18
|
className,
|
|
19
|
+
onClick,
|
|
18
20
|
...rest
|
|
19
21
|
}) {
|
|
22
|
+
const jump = event => {
|
|
23
|
+
onClick?.(event);
|
|
24
|
+
if (event.defaultPrevented || typeof href !== 'string' || href.length < 2 || href[0] !== '#') return;
|
|
25
|
+
const target = document.getElementById(decodeURIComponent(href.slice(1)));
|
|
26
|
+
if (!target) return;
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
if (!target.hasAttribute('tabindex')) target.setAttribute('tabindex', '-1');
|
|
29
|
+
target.focus();
|
|
30
|
+
};
|
|
20
31
|
return /*#__PURE__*/React.createElement("a", _extends({}, rest, {
|
|
21
32
|
href: href,
|
|
33
|
+
onClick: jump,
|
|
22
34
|
className: `ef-skip${className ? ' ' + className : ''}`,
|
|
23
35
|
style: style
|
|
24
36
|
}), children);
|
package/overlay/Command.js
CHANGED
|
@@ -227,6 +227,7 @@ export const CommandItem = /*#__PURE__*/React.forwardRef(function CommandItem({
|
|
|
227
227
|
"data-disabled": disabled ? 'true' : 'false',
|
|
228
228
|
role: "option",
|
|
229
229
|
"aria-selected": selected,
|
|
230
|
+
tabIndex: -1,
|
|
230
231
|
disabled: disabled,
|
|
231
232
|
hidden: hidden,
|
|
232
233
|
className: join('ef-command__item', className),
|
package/overlay/ContextMenu.js
CHANGED
|
@@ -4,6 +4,7 @@ import React from 'react';
|
|
|
4
4
|
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
5
5
|
import { Icon } from "../icons/Icon.js";
|
|
6
6
|
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
7
|
+
import { useDirection } from "../display/Direction.js";
|
|
7
8
|
const RootCtx = /*#__PURE__*/React.createContext(null);
|
|
8
9
|
const SubCtx = /*#__PURE__*/React.createContext(null);
|
|
9
10
|
const RadioCtx = /*#__PURE__*/React.createContext(null);
|
|
@@ -15,6 +16,13 @@ const compose = (theirs, ours) => event => {
|
|
|
15
16
|
function menuItems(node) {
|
|
16
17
|
return node ? Array.from(node.querySelectorAll('[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]')).filter(item => !item.disabled && item.dataset.disabled !== 'true') : [];
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
// Submenus portal to their own host, so a pointerdown inside one is outside the
|
|
21
|
+
// root panel's DOM subtree. Every panel of one menu carries the same id.
|
|
22
|
+
function insideMenu(target, id) {
|
|
23
|
+
for (let node = target; node; node = node.parentNode) if (node.dataset && node.dataset.efMenu === id) return true;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
18
26
|
function focusRelative(node, direction, loop = true) {
|
|
19
27
|
const items = menuItems(node);
|
|
20
28
|
if (!items.length) return;
|
|
@@ -25,7 +33,8 @@ function focusRelative(node, direction, loop = true) {
|
|
|
25
33
|
}
|
|
26
34
|
function useMenuKeyboard(ref, close, {
|
|
27
35
|
sub = false,
|
|
28
|
-
loop = true
|
|
36
|
+
loop = true,
|
|
37
|
+
rtl = false
|
|
29
38
|
} = {}) {
|
|
30
39
|
return event => {
|
|
31
40
|
if (event.defaultPrevented) return;
|
|
@@ -35,7 +44,7 @@ function useMenuKeyboard(ref, close, {
|
|
|
35
44
|
} else if (event.key === 'Home' || event.key === 'End') {
|
|
36
45
|
event.preventDefault();
|
|
37
46
|
focusRelative(ref.current, event.key === 'Home' ? 'first' : 'last');
|
|
38
|
-
} else if (event.key === 'Escape' || sub && event.key === 'ArrowLeft') {
|
|
47
|
+
} else if (event.key === 'Escape' || sub && event.key === (rtl ? 'ArrowRight' : 'ArrowLeft')) {
|
|
39
48
|
event.preventDefault();
|
|
40
49
|
close?.();
|
|
41
50
|
} else if (event.key.length === 1 && /\S/.test(event.key) && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
@@ -68,6 +77,7 @@ export function ContextMenu({
|
|
|
68
77
|
const open = controlled !== undefined ? controlled : inner;
|
|
69
78
|
const triggerRef = React.useRef(null);
|
|
70
79
|
const contentRef = React.useRef(null);
|
|
80
|
+
const menuId = React.useId();
|
|
71
81
|
const setOpen = React.useCallback(next => {
|
|
72
82
|
if (controlled === undefined) setInner(next);
|
|
73
83
|
onOpenChange?.(next);
|
|
@@ -86,8 +96,9 @@ export function ContextMenu({
|
|
|
86
96
|
point,
|
|
87
97
|
triggerRef,
|
|
88
98
|
contentRef,
|
|
89
|
-
modal
|
|
90
|
-
|
|
99
|
+
modal,
|
|
100
|
+
menuId
|
|
101
|
+
}), [open, setOpen, openAt, point, modal, menuId]);
|
|
91
102
|
return /*#__PURE__*/React.createElement(RootCtx.Provider, {
|
|
92
103
|
value: value
|
|
93
104
|
}, children);
|
|
@@ -151,6 +162,7 @@ export const ContextMenuContent = /*#__PURE__*/React.forwardRef(function Context
|
|
|
151
162
|
...rest
|
|
152
163
|
}, forwardedRef) {
|
|
153
164
|
const root = React.useContext(RootCtx);
|
|
165
|
+
const rtl = useDirection() === 'rtl';
|
|
154
166
|
const localRef = React.useRef(null);
|
|
155
167
|
const ref = mergeRefs(forwardedRef, localRef, root?.contentRef);
|
|
156
168
|
const close = React.useCallback(() => {
|
|
@@ -181,7 +193,7 @@ export const ContextMenuContent = /*#__PURE__*/React.forwardRef(function Context
|
|
|
181
193
|
React.useEffect(() => {
|
|
182
194
|
if (!root?.open) return;
|
|
183
195
|
const away = event => {
|
|
184
|
-
if (!
|
|
196
|
+
if (!insideMenu(event.target, root.menuId) && !root.triggerRef.current?.contains(event.target)) close();
|
|
185
197
|
};
|
|
186
198
|
const blur = () => close();
|
|
187
199
|
document.addEventListener('pointerdown', away);
|
|
@@ -192,9 +204,12 @@ export const ContextMenuContent = /*#__PURE__*/React.forwardRef(function Context
|
|
|
192
204
|
};
|
|
193
205
|
}, [root?.open, close]);
|
|
194
206
|
if (!root?.open) return null;
|
|
195
|
-
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
207
|
+
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
208
|
+
dir: rtl ? 'rtl' : undefined
|
|
209
|
+
}, rest, {
|
|
196
210
|
ref: ref,
|
|
197
211
|
role: "menu",
|
|
212
|
+
"data-ef-menu": root.menuId,
|
|
198
213
|
"data-slot": "context-menu-content",
|
|
199
214
|
"data-state": "open",
|
|
200
215
|
className: join('ef-context-menu__content', className),
|
|
@@ -410,8 +425,9 @@ export const ContextMenuSubTrigger = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
410
425
|
...props
|
|
411
426
|
}, forwardedRef) {
|
|
412
427
|
const sub = React.useContext(SubCtx);
|
|
428
|
+
const rtl = useDirection() === 'rtl';
|
|
413
429
|
const keyboard = event => {
|
|
414
|
-
if (!disabled && event.key === 'ArrowRight') {
|
|
430
|
+
if (!disabled && event.key === (rtl ? 'ArrowLeft' : 'ArrowRight')) {
|
|
415
431
|
event.preventDefault();
|
|
416
432
|
sub?.setOpen(true);
|
|
417
433
|
requestAnimationFrame(() => menuItems(sub?.contentRef.current)[0]?.focus());
|
|
@@ -447,6 +463,8 @@ export const ContextMenuSubContent = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
447
463
|
...props
|
|
448
464
|
}, forwardedRef) {
|
|
449
465
|
const sub = React.useContext(SubCtx);
|
|
466
|
+
const root = React.useContext(RootCtx);
|
|
467
|
+
const rtl = useDirection() === 'rtl';
|
|
450
468
|
const localRef = React.useRef(null);
|
|
451
469
|
const fallbackTriggerRef = React.useRef(null);
|
|
452
470
|
const fallbackContentRef = React.useRef(null);
|
|
@@ -455,7 +473,7 @@ export const ContextMenuSubContent = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
455
473
|
side
|
|
456
474
|
} = useAnchoredStyle(sub?.triggerRef ?? fallbackTriggerRef, sub?.contentRef ?? fallbackContentRef, {
|
|
457
475
|
open: !!sub?.open,
|
|
458
|
-
placement: 'right',
|
|
476
|
+
placement: rtl ? 'left' : 'right',
|
|
459
477
|
align: 'start',
|
|
460
478
|
offset: sideOffset,
|
|
461
479
|
crossOffset: alignOffset
|
|
@@ -466,15 +484,19 @@ export const ContextMenuSubContent = /*#__PURE__*/React.forwardRef(function Cont
|
|
|
466
484
|
};
|
|
467
485
|
const keyboard = useMenuKeyboard(localRef, close, {
|
|
468
486
|
sub: true,
|
|
469
|
-
loop
|
|
487
|
+
loop,
|
|
488
|
+
rtl
|
|
470
489
|
});
|
|
471
490
|
useIsoLayoutEffect(() => {
|
|
472
491
|
if (sub?.open) menuItems(localRef.current)[0]?.focus();
|
|
473
492
|
}, [sub?.open]);
|
|
474
493
|
if (!sub?.open) return null;
|
|
475
|
-
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
494
|
+
return /*#__PURE__*/React.createElement(ContextMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
495
|
+
dir: rtl ? 'rtl' : undefined
|
|
496
|
+
}, props, {
|
|
476
497
|
ref: mergeRefs(forwardedRef, localRef, sub.contentRef),
|
|
477
498
|
role: "menu",
|
|
499
|
+
"data-ef-menu": root?.menuId,
|
|
478
500
|
"data-slot": "context-menu-sub-content",
|
|
479
501
|
"data-state": "open",
|
|
480
502
|
"data-side": side,
|
package/overlay/Drawer.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface DrawerProps {
|
|
|
7
7
|
onOpenChange?: (open: boolean) => void;
|
|
8
8
|
direction?: DrawerDirection;
|
|
9
9
|
dismissible?: boolean;
|
|
10
|
+
/** @deprecated Ignored: a Drawer is always modal. Passing `false` logs a development warning; the prop will be removed in the next major version. */
|
|
10
11
|
modal?: boolean;
|
|
11
12
|
handleOnly?: boolean;
|
|
12
13
|
children?: React.ReactNode;
|
package/overlay/Drawer.js
CHANGED
|
@@ -8,6 +8,21 @@ const compose = (first, second) => event => {
|
|
|
8
8
|
first?.(event);
|
|
9
9
|
if (!event.defaultPrevented) second?.(event);
|
|
10
10
|
};
|
|
11
|
+
|
|
12
|
+
// Deprecated props keep working until the next major, with one warning per
|
|
13
|
+
// page outside production builds.
|
|
14
|
+
let warnedModal = false;
|
|
15
|
+
function warnModalIgnored() {
|
|
16
|
+
if (warnedModal || typeof console === 'undefined') return;
|
|
17
|
+
// Bare `process.env.NODE_ENV` so bundlers (Vite, webpack, esbuild) fold it to a
|
|
18
|
+
// literal; `typeof process` is not replaced and would keep the warning in
|
|
19
|
+
// production. Where nothing defines it, the read throws and we warn.
|
|
20
|
+
try {
|
|
21
|
+
if (process.env.NODE_ENV === 'production') return;
|
|
22
|
+
} catch (e) {/* no build-time env */}
|
|
23
|
+
warnedModal = true;
|
|
24
|
+
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.');
|
|
25
|
+
}
|
|
11
26
|
export function Drawer({
|
|
12
27
|
open: controlled,
|
|
13
28
|
defaultOpen = false,
|
|
@@ -18,6 +33,9 @@ export function Drawer({
|
|
|
18
33
|
handleOnly = false,
|
|
19
34
|
children
|
|
20
35
|
}) {
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
if (modal === false) warnModalIgnored();
|
|
38
|
+
}, [modal]);
|
|
21
39
|
const [internal, setInternal] = React.useState(defaultOpen);
|
|
22
40
|
const open = controlled === undefined ? internal : controlled;
|
|
23
41
|
const setOpen = React.useCallback(next => {
|
|
@@ -35,8 +53,7 @@ export function Drawer({
|
|
|
35
53
|
value: context
|
|
36
54
|
}, /*#__PURE__*/React.createElement(Dialog, {
|
|
37
55
|
open: open,
|
|
38
|
-
onOpenChange: setOpen
|
|
39
|
-
modal: modal
|
|
56
|
+
onOpenChange: setOpen
|
|
40
57
|
}, children));
|
|
41
58
|
}
|
|
42
59
|
export const DrawerTrigger = /*#__PURE__*/React.forwardRef(function DrawerTrigger(props, ref) {
|
package/overlay/DropdownMenu.js
CHANGED
|
@@ -4,6 +4,7 @@ import React from 'react';
|
|
|
4
4
|
import { mergeRefs, useIsoLayoutEffect } from "../forms/Button.js";
|
|
5
5
|
import { Icon } from "../icons/Icon.js";
|
|
6
6
|
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
7
|
+
import { useDirection } from "../display/Direction.js";
|
|
7
8
|
const RootCtx = /*#__PURE__*/React.createContext(null);
|
|
8
9
|
const SubCtx = /*#__PURE__*/React.createContext(null);
|
|
9
10
|
const RadioCtx = /*#__PURE__*/React.createContext(null);
|
|
@@ -15,6 +16,13 @@ const compose = (theirs, ours) => event => {
|
|
|
15
16
|
function menuItems(node) {
|
|
16
17
|
return node ? Array.from(node.querySelectorAll('[role="menuitem"],[role="menuitemcheckbox"],[role="menuitemradio"]')).filter(item => !item.disabled && item.dataset.disabled !== 'true') : [];
|
|
17
18
|
}
|
|
19
|
+
|
|
20
|
+
// Submenus portal to their own host, so a pointerdown inside one is outside the
|
|
21
|
+
// root panel's DOM subtree. Every panel of one menu carries the same id.
|
|
22
|
+
function insideMenu(target, id) {
|
|
23
|
+
for (let node = target; node; node = node.parentNode) if (node.dataset && node.dataset.efMenu === id) return true;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
18
26
|
function focusRelative(node, direction, loop = true) {
|
|
19
27
|
const items = menuItems(node);
|
|
20
28
|
if (!items.length) return;
|
|
@@ -25,7 +33,8 @@ function focusRelative(node, direction, loop = true) {
|
|
|
25
33
|
}
|
|
26
34
|
function useMenuKeyboard(ref, close, {
|
|
27
35
|
sub = false,
|
|
28
|
-
loop = true
|
|
36
|
+
loop = true,
|
|
37
|
+
rtl = false
|
|
29
38
|
} = {}) {
|
|
30
39
|
return event => {
|
|
31
40
|
if (event.defaultPrevented) return;
|
|
@@ -35,7 +44,7 @@ function useMenuKeyboard(ref, close, {
|
|
|
35
44
|
} else if (event.key === 'Home' || event.key === 'End') {
|
|
36
45
|
event.preventDefault();
|
|
37
46
|
focusRelative(ref.current, event.key === 'Home' ? 'first' : 'last');
|
|
38
|
-
} else if (event.key === 'Escape' || sub && event.key === 'ArrowLeft') {
|
|
47
|
+
} else if (event.key === 'Escape' || sub && event.key === (rtl ? 'ArrowRight' : 'ArrowLeft')) {
|
|
39
48
|
event.preventDefault();
|
|
40
49
|
close?.();
|
|
41
50
|
} else if (event.key.length === 1 && /\S/.test(event.key) && !event.metaKey && !event.ctrlKey && !event.altKey) {
|
|
@@ -64,6 +73,7 @@ export function DropdownMenu({
|
|
|
64
73
|
const open = controlled !== undefined ? controlled : inner;
|
|
65
74
|
const triggerRef = React.useRef(null);
|
|
66
75
|
const contentRef = React.useRef(null);
|
|
76
|
+
const menuId = React.useId();
|
|
67
77
|
const setOpen = React.useCallback(next => {
|
|
68
78
|
if (controlled === undefined) setInner(next);
|
|
69
79
|
onOpenChange?.(next);
|
|
@@ -73,8 +83,9 @@ export function DropdownMenu({
|
|
|
73
83
|
setOpen,
|
|
74
84
|
triggerRef,
|
|
75
85
|
contentRef,
|
|
76
|
-
modal
|
|
77
|
-
|
|
86
|
+
modal,
|
|
87
|
+
menuId
|
|
88
|
+
}), [open, setOpen, modal, menuId]);
|
|
78
89
|
return /*#__PURE__*/React.createElement(RootCtx.Provider, {
|
|
79
90
|
value: value
|
|
80
91
|
}, children);
|
|
@@ -147,6 +158,7 @@ export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function Dropdo
|
|
|
147
158
|
...rest
|
|
148
159
|
}, forwardedRef) {
|
|
149
160
|
const root = React.useContext(RootCtx);
|
|
161
|
+
const rtl = useDirection() === 'rtl';
|
|
150
162
|
const localRef = React.useRef(null);
|
|
151
163
|
const ref = mergeRefs(forwardedRef, localRef, root?.contentRef);
|
|
152
164
|
const fallbackTriggerRef = React.useRef(null);
|
|
@@ -181,7 +193,7 @@ export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function Dropdo
|
|
|
181
193
|
React.useEffect(() => {
|
|
182
194
|
if (!root?.open) return;
|
|
183
195
|
const away = event => {
|
|
184
|
-
if (!
|
|
196
|
+
if (!insideMenu(event.target, root.menuId) && !root.triggerRef.current?.contains(event.target)) close();
|
|
185
197
|
};
|
|
186
198
|
const blur = () => close();
|
|
187
199
|
document.addEventListener('pointerdown', away);
|
|
@@ -192,9 +204,12 @@ export const DropdownMenuContent = /*#__PURE__*/React.forwardRef(function Dropdo
|
|
|
192
204
|
};
|
|
193
205
|
}, [root?.open, close]);
|
|
194
206
|
if (!root?.open) return null;
|
|
195
|
-
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
207
|
+
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
208
|
+
dir: rtl ? 'rtl' : undefined
|
|
209
|
+
}, rest, {
|
|
196
210
|
ref: ref,
|
|
197
211
|
role: "menu",
|
|
212
|
+
"data-ef-menu": root.menuId,
|
|
198
213
|
"data-slot": slot,
|
|
199
214
|
"data-state": "open",
|
|
200
215
|
"data-side": resolvedSide,
|
|
@@ -422,8 +437,9 @@ export const DropdownMenuSubTrigger = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
422
437
|
...props
|
|
423
438
|
}, forwardedRef) {
|
|
424
439
|
const sub = React.useContext(SubCtx);
|
|
440
|
+
const rtl = useDirection() === 'rtl';
|
|
425
441
|
const keyboard = event => {
|
|
426
|
-
if (!disabled && event.key === 'ArrowRight') {
|
|
442
|
+
if (!disabled && event.key === (rtl ? 'ArrowLeft' : 'ArrowRight')) {
|
|
427
443
|
event.preventDefault();
|
|
428
444
|
sub?.setOpen(true);
|
|
429
445
|
requestAnimationFrame(() => menuItems(sub?.contentRef.current)[0]?.focus());
|
|
@@ -460,6 +476,8 @@ export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
460
476
|
...props
|
|
461
477
|
}, forwardedRef) {
|
|
462
478
|
const sub = React.useContext(SubCtx);
|
|
479
|
+
const root = React.useContext(RootCtx);
|
|
480
|
+
const rtl = useDirection() === 'rtl';
|
|
463
481
|
const localRef = React.useRef(null);
|
|
464
482
|
const fallbackTriggerRef = React.useRef(null);
|
|
465
483
|
const fallbackContentRef = React.useRef(null);
|
|
@@ -468,7 +486,7 @@ export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
468
486
|
side
|
|
469
487
|
} = useAnchoredStyle(sub?.triggerRef ?? fallbackTriggerRef, sub?.contentRef ?? fallbackContentRef, {
|
|
470
488
|
open: !!sub?.open,
|
|
471
|
-
placement: 'right',
|
|
489
|
+
placement: rtl ? 'left' : 'right',
|
|
472
490
|
align: 'start',
|
|
473
491
|
offset: sideOffset,
|
|
474
492
|
crossOffset: alignOffset
|
|
@@ -479,15 +497,19 @@ export const DropdownMenuSubContent = /*#__PURE__*/React.forwardRef(function Dro
|
|
|
479
497
|
};
|
|
480
498
|
const keyboard = useMenuKeyboard(localRef, close, {
|
|
481
499
|
sub: true,
|
|
482
|
-
loop
|
|
500
|
+
loop,
|
|
501
|
+
rtl
|
|
483
502
|
});
|
|
484
503
|
useIsoLayoutEffect(() => {
|
|
485
504
|
if (sub?.open) menuItems(localRef.current)[0]?.focus();
|
|
486
505
|
}, [sub?.open]);
|
|
487
506
|
if (!sub?.open) return null;
|
|
488
|
-
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
507
|
+
return /*#__PURE__*/React.createElement(DropdownMenuPortal, null, /*#__PURE__*/React.createElement("div", _extends({
|
|
508
|
+
dir: rtl ? 'rtl' : undefined
|
|
509
|
+
}, props, {
|
|
489
510
|
ref: mergeRefs(forwardedRef, localRef, sub.contentRef),
|
|
490
511
|
role: "menu",
|
|
512
|
+
"data-ef-menu": root?.menuId,
|
|
491
513
|
"data-slot": slot,
|
|
492
514
|
"data-state": "open",
|
|
493
515
|
"data-side": side,
|
package/overlay/HoverCard.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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 { mergeRefs } from "../forms/Button.js";
|
|
5
|
-
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
5
|
+
import { Portal, useAnchoredStyle, useEscapeLayer, escapeLayerContext } from "./Portal.js";
|
|
6
6
|
const HoverCardCtx = /*#__PURE__*/React.createContext(null);
|
|
7
7
|
function compose(theirs, ours) {
|
|
8
8
|
return event => {
|
|
@@ -38,17 +38,10 @@ export function HoverCard({
|
|
|
38
38
|
timerRef.current = setTimeout(() => setOpen(false), closeDelay);
|
|
39
39
|
}, [clearTimer, closeDelay, setOpen]);
|
|
40
40
|
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]);
|
|
41
|
+
const layer = useEscapeLayer(open, () => {
|
|
42
|
+
clearTimer();
|
|
43
|
+
setOpen(false);
|
|
44
|
+
});
|
|
52
45
|
const value = React.useMemo(() => ({
|
|
53
46
|
open,
|
|
54
47
|
setOpen,
|
|
@@ -61,7 +54,9 @@ export function HoverCard({
|
|
|
61
54
|
}), [open, setOpen, openSoon, closeSoon, clearTimer, contentId]);
|
|
62
55
|
return /*#__PURE__*/React.createElement(HoverCardCtx.Provider, {
|
|
63
56
|
value: value
|
|
64
|
-
},
|
|
57
|
+
}, /*#__PURE__*/React.createElement(escapeLayerContext.Provider, {
|
|
58
|
+
value: layer
|
|
59
|
+
}, children));
|
|
65
60
|
}
|
|
66
61
|
export const HoverCardTrigger = /*#__PURE__*/React.forwardRef(function HoverCardTrigger({
|
|
67
62
|
asChild = false,
|
package/overlay/Popover.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
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 { mergeRefs } from "../forms/Button.js";
|
|
5
|
-
import { Portal, useAnchoredStyle } from "./Portal.js";
|
|
5
|
+
import { Portal, useAnchoredStyle, useEscapeLayer, escapeLayerContext } from "./Portal.js";
|
|
6
6
|
const PopoverCtx = /*#__PURE__*/React.createContext(null);
|
|
7
|
+
const TABBABLE = 'a[href],button,input,select,textarea,[tabindex]';
|
|
8
|
+
const tabbable = root => [...root.querySelectorAll(TABBABLE)].filter(node => !node.disabled && node.tabIndex >= 0 && !node.closest('[hidden]'));
|
|
7
9
|
function compose(theirs, ours) {
|
|
8
10
|
return event => {
|
|
9
11
|
theirs?.(event);
|
|
@@ -37,24 +39,58 @@ export function Popover({
|
|
|
37
39
|
const away = event => {
|
|
38
40
|
if (!triggerRef.current?.contains(event.target) && !contentRef.current?.contains(event.target)) setOpen(false);
|
|
39
41
|
};
|
|
40
|
-
const key = event => {
|
|
41
|
-
if (event.key === 'Escape') {
|
|
42
|
-
setOpen(false);
|
|
43
|
-
triggerRef.current?.focus();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
42
|
document.addEventListener('pointerdown', away);
|
|
47
43
|
document.addEventListener('mousedown', away);
|
|
48
|
-
document.addEventListener('keydown', key);
|
|
49
44
|
return () => {
|
|
50
45
|
document.removeEventListener('pointerdown', away);
|
|
51
46
|
document.removeEventListener('mousedown', away);
|
|
52
|
-
document.removeEventListener('keydown', key);
|
|
53
47
|
};
|
|
54
48
|
}, [open, setOpen]);
|
|
49
|
+
// The panel is portaled to the end of <body>, so the browser's Tab order
|
|
50
|
+
// runs from the trigger straight past it. Stitch it back in: Tab from the
|
|
51
|
+
// trigger enters the panel, Shift+Tab from its first stop returns to the
|
|
52
|
+
// trigger, and Tab past its last stop continues after the trigger.
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
if (!open) return;
|
|
55
|
+
const tab = event => {
|
|
56
|
+
if (event.key !== 'Tab' || event.defaultPrevented) return;
|
|
57
|
+
const trigger = triggerRef.current;
|
|
58
|
+
const panel = contentRef.current;
|
|
59
|
+
if (!trigger || !panel) return;
|
|
60
|
+
const inside = tabbable(panel);
|
|
61
|
+
const active = document.activeElement;
|
|
62
|
+
if (active === trigger && !event.shiftKey && inside.length) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
inside[0].focus();
|
|
65
|
+
} else if (event.shiftKey && inside.length && active === inside[0]) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
trigger.focus();
|
|
68
|
+
} else if (!event.shiftKey && (inside.length ? active === inside[inside.length - 1] : active === panel)) {
|
|
69
|
+
// inside a modal the order wraps within that modal, not the page
|
|
70
|
+
const modal = trigger.closest('[aria-modal="true"]');
|
|
71
|
+
const page = tabbable(modal || document.body).filter(node => !panel.contains(node));
|
|
72
|
+
const next = page[page.indexOf(trigger) + 1] || (modal ? page[0] : undefined);
|
|
73
|
+
if (next) {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
next.focus();
|
|
76
|
+
}
|
|
77
|
+
setOpen(false);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
// capture phase: a dialog's focus trap listening on document must see the
|
|
81
|
+
// key already handled, or it would wrap focus away from the panel
|
|
82
|
+
document.addEventListener('keydown', tab, true);
|
|
83
|
+
return () => document.removeEventListener('keydown', tab, true);
|
|
84
|
+
}, [open, setOpen]);
|
|
85
|
+
const layer = useEscapeLayer(open, () => {
|
|
86
|
+
setOpen(false);
|
|
87
|
+
triggerRef.current?.focus();
|
|
88
|
+
});
|
|
55
89
|
return /*#__PURE__*/React.createElement(PopoverCtx.Provider, {
|
|
56
90
|
value: value
|
|
57
|
-
},
|
|
91
|
+
}, /*#__PURE__*/React.createElement(escapeLayerContext.Provider, {
|
|
92
|
+
value: layer
|
|
93
|
+
}, children));
|
|
58
94
|
}
|
|
59
95
|
export const PopoverTrigger = /*#__PURE__*/React.forwardRef(function PopoverTrigger({
|
|
60
96
|
asChild = false,
|