@mdbase-dev/ui 0.1.0-beta.156 → 0.1.0-beta.158
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 +17 -1
- package/css/collections.css +3 -5
- package/css/controls.css +30 -3
- package/css/motion.css +3 -3
- package/css/palette.css +23 -5
- package/css/toast.css +2 -2
- package/css/tokens.css +7 -0
- package/dist/CommandPalette.d.ts +7 -4
- package/dist/CommandPalette.js +62 -54
- package/dist/ConfirmDialog.d.ts +5 -1
- package/dist/ConfirmDialog.js +19 -10
- package/dist/Dialog.d.ts +4 -2
- package/dist/Dialog.js +76 -29
- package/dist/FeedbackMarkup.js +1 -0
- package/dist/Menu.d.ts +20 -2
- package/dist/Menu.js +33 -2
- package/dist/Toaster.d.ts +18 -1
- package/dist/Toaster.js +86 -32
- package/dist/Tooltip.d.ts +6 -0
- package/dist/Tooltip.js +143 -0
- package/dist/codemirror.js +20 -5
- package/dist/collections/copy.js +4 -4
- package/dist/collections/dialogs.js +1 -0
- package/dist/collections/use-collection-ui.js +4 -1
- package/dist/locales/de/messages.json +1 -1
- package/dist/locales/en/messages.json +1 -1
- package/dist/locales/es/messages.json +1 -1
- package/dist/locales/fr/messages.json +1 -1
- package/dist/locales/it/messages.json +1 -1
- package/dist/locales/ja/messages.json +1 -1
- package/dist/locales/ko/messages.json +1 -1
- package/dist/locales/pt/messages.json +1 -1
- package/dist/locales/ru/messages.json +1 -1
- package/dist/locales/zh/messages.json +1 -1
- package/dist/popover.d.ts +5 -1
- package/dist/popover.js +18 -5
- package/dist/shortcuts.d.ts +2 -0
- package/dist/shortcuts.js +37 -0
- package/package.json +6 -2
package/dist/Dialog.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
|
-
import { useLayoutEffect, useRef } from "react";
|
|
3
|
+
import { useEffect, useId, useLayoutEffect, useRef } from "react";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
5
|
import { useLocaleRevision } from "./i18n.js";
|
|
6
6
|
import { useOverlay } from "./overlay.js";
|
|
7
|
+
import { Tooltip } from "./Tooltip.js";
|
|
7
8
|
export function Dialog({
|
|
8
9
|
open,
|
|
9
10
|
onClose,
|
|
@@ -12,6 +13,8 @@ export function Dialog({
|
|
|
12
13
|
className,
|
|
13
14
|
closeDisabled = false,
|
|
14
15
|
returnFocusRef,
|
|
16
|
+
initialFocusRef,
|
|
17
|
+
role = "dialog",
|
|
15
18
|
children
|
|
16
19
|
}) {
|
|
17
20
|
useLocaleRevision();
|
|
@@ -20,26 +23,55 @@ export function Dialog({
|
|
|
20
23
|
present
|
|
21
24
|
} = useOverlay(open);
|
|
22
25
|
const invoker = useRef(null);
|
|
26
|
+
const titleId = useId();
|
|
23
27
|
useLayoutEffect(() => {
|
|
24
28
|
const dialog = ref.current;
|
|
25
29
|
if (!dialog || !open || dialog.open) return;
|
|
26
|
-
const previous = document.querySelector("dialog[open]");
|
|
27
|
-
if (previous && previous !== dialog) {
|
|
28
|
-
previous.dispatchEvent(new Event("cancel", {
|
|
29
|
-
cancelable: true
|
|
30
|
-
}));
|
|
31
|
-
previous.close();
|
|
32
|
-
}
|
|
33
30
|
invoker.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
34
31
|
dialog.showModal();
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const focus = () => {
|
|
33
|
+
const scope = initialFocusRef?.current ?? dialog;
|
|
34
|
+
return scope.querySelector(initialFocusRef ? 'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex="0"]' : "[data-autofocus]");
|
|
35
|
+
};
|
|
36
|
+
const first = focus();
|
|
37
|
+
if (first) first.focus({
|
|
38
|
+
preventScroll: true
|
|
39
|
+
});else if (initialFocusRef) dialog.focus({
|
|
40
|
+
preventScroll: true
|
|
41
|
+
});
|
|
42
|
+
if (!initialFocusRef || first) return;
|
|
43
|
+
const observer = new MutationObserver(() => {
|
|
44
|
+
if (document.activeElement !== dialog) return;
|
|
45
|
+
const control = focus();
|
|
46
|
+
if (control) {
|
|
47
|
+
control.focus({
|
|
48
|
+
preventScroll: true
|
|
49
|
+
});
|
|
50
|
+
observer.disconnect();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
observer.observe(dialog, {
|
|
54
|
+
childList: true,
|
|
55
|
+
subtree: true
|
|
56
|
+
});
|
|
57
|
+
return () => observer.disconnect();
|
|
58
|
+
}, [open, ref, initialFocusRef]);
|
|
37
59
|
useLayoutEffect(() => {
|
|
60
|
+
const dialog = ref.current;
|
|
61
|
+
if (!dialog || !open) return;
|
|
62
|
+
if (closeDisabled && (!dialog.contains(document.activeElement) || document.activeElement?.matches(":disabled"))) dialog.focus({
|
|
63
|
+
preventScroll: true
|
|
64
|
+
});
|
|
65
|
+
if (!closeDisabled && document.activeElement === dialog) dialog.querySelector("[data-autofocus]:not(:disabled)")?.focus({
|
|
66
|
+
preventScroll: true
|
|
67
|
+
});
|
|
68
|
+
}, [closeDisabled, open, ref]);
|
|
69
|
+
useEffect(() => {
|
|
38
70
|
const dialog = ref.current;
|
|
39
71
|
return () => {
|
|
40
72
|
const wasOpen = dialog?.open;
|
|
41
73
|
dialog?.close();
|
|
42
|
-
if (wasOpen
|
|
74
|
+
if (wasOpen) (returnFocusRef?.current ?? invoker.current)?.focus({
|
|
43
75
|
preventScroll: true
|
|
44
76
|
});
|
|
45
77
|
};
|
|
@@ -49,21 +81,32 @@ export function Dialog({
|
|
|
49
81
|
ref: ref,
|
|
50
82
|
className: ["mdbase-dialog mdbase-overlay", className].filter(Boolean).join(" "),
|
|
51
83
|
"data-open": open,
|
|
52
|
-
role:
|
|
53
|
-
"aria-
|
|
84
|
+
role: role,
|
|
85
|
+
"aria-modal": "true",
|
|
86
|
+
"aria-labelledby": titleId,
|
|
54
87
|
"aria-describedby": descriptionId,
|
|
88
|
+
tabIndex: -1,
|
|
55
89
|
onKeyDown: event => {
|
|
56
90
|
event.stopPropagation();
|
|
57
91
|
if (event.key === "Escape") {
|
|
58
92
|
event.preventDefault();
|
|
59
93
|
if (!closeDisabled) onClose();
|
|
60
94
|
}
|
|
95
|
+
if (event.key === "Tab" && closeDisabled) {
|
|
96
|
+
const controls = [...event.currentTarget.querySelectorAll('button:not(:disabled), a[href], input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex="0"]')].filter(control => control.getClientRects().length > 0);
|
|
97
|
+
const current = controls.indexOf(document.activeElement);
|
|
98
|
+
const next = current < 0 ? event.shiftKey ? controls.length - 1 : 0 : (current + (event.shiftKey ? -1 : 1) + controls.length) % controls.length;
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
(controls.length ? controls[next] : event.currentTarget)?.focus({
|
|
101
|
+
preventScroll: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
61
104
|
},
|
|
62
105
|
onCancel: event => {
|
|
63
106
|
event.preventDefault();
|
|
64
107
|
if (!closeDisabled) onClose();
|
|
65
108
|
},
|
|
66
|
-
|
|
109
|
+
onClick: event => {
|
|
67
110
|
if (!closeDisabled && event.target === event.currentTarget) onClose();
|
|
68
111
|
},
|
|
69
112
|
children: _jsxs("div", {
|
|
@@ -71,27 +114,31 @@ export function Dialog({
|
|
|
71
114
|
children: [_jsxs("header", {
|
|
72
115
|
className: "mdbase-dialog-header",
|
|
73
116
|
children: [_jsx("h2", {
|
|
117
|
+
id: titleId,
|
|
74
118
|
children: title
|
|
75
|
-
}), _jsx(
|
|
76
|
-
|
|
77
|
-
className: "mdbase-icon-button",
|
|
78
|
-
disabled: closeDisabled,
|
|
79
|
-
onClick: onClose,
|
|
80
|
-
"aria-label": _i18n._(
|
|
119
|
+
}), _jsx(Tooltip, {
|
|
120
|
+
label: _i18n._(
|
|
81
121
|
/** i18n */
|
|
82
122
|
{
|
|
83
123
|
id: "yz7wBu",
|
|
84
124
|
message: "Close"
|
|
85
125
|
}),
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
126
|
+
shortcut: "Escape",
|
|
127
|
+
children: _jsx("button", {
|
|
128
|
+
type: "button",
|
|
129
|
+
className: "mdbase-icon-button",
|
|
130
|
+
disabled: closeDisabled,
|
|
131
|
+
onClick: onClose,
|
|
132
|
+
children: _jsx("svg", {
|
|
133
|
+
viewBox: "0 0 24 24",
|
|
134
|
+
"aria-hidden": "true",
|
|
135
|
+
fill: "none",
|
|
136
|
+
stroke: "currentColor",
|
|
137
|
+
strokeWidth: "1.6",
|
|
138
|
+
strokeLinecap: "round",
|
|
139
|
+
children: _jsx("path", {
|
|
140
|
+
d: "m6 6 12 12M18 6 6 18"
|
|
141
|
+
})
|
|
95
142
|
})
|
|
96
143
|
})
|
|
97
144
|
})]
|
package/dist/FeedbackMarkup.js
CHANGED
package/dist/Menu.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function Menu({ open, triggerRef, onClose, id, label, className, children }: {
|
|
1
|
+
import { type KeyboardEvent, type ReactNode, type RefObject } from "react";
|
|
2
|
+
export declare function Menu({ open, triggerRef, onClose, id, label, className, children, point }: {
|
|
3
3
|
readonly open: boolean;
|
|
4
4
|
readonly triggerRef: RefObject<HTMLElement | null>;
|
|
5
5
|
readonly onClose: (refocus: boolean) => void;
|
|
@@ -7,4 +7,22 @@ export declare function Menu({ open, triggerRef, onClose, id, label, className,
|
|
|
7
7
|
readonly label?: string;
|
|
8
8
|
readonly className?: string;
|
|
9
9
|
readonly children: ReactNode;
|
|
10
|
+
readonly point?: {
|
|
11
|
+
readonly left: number;
|
|
12
|
+
readonly top: number;
|
|
13
|
+
} | undefined;
|
|
10
14
|
}): import("react").JSX.Element | null;
|
|
15
|
+
export declare function useMenuTrigger(): {
|
|
16
|
+
id: string;
|
|
17
|
+
open: boolean;
|
|
18
|
+
close: (refocus: boolean) => void;
|
|
19
|
+
trigger: RefObject<HTMLButtonElement | null>;
|
|
20
|
+
triggerProps: {
|
|
21
|
+
ref: RefObject<HTMLButtonElement | null>;
|
|
22
|
+
"aria-haspopup": "menu";
|
|
23
|
+
"aria-expanded": boolean;
|
|
24
|
+
"aria-controls": string | undefined;
|
|
25
|
+
onClick: () => void;
|
|
26
|
+
onKeyDown: (event: KeyboardEvent) => void;
|
|
27
|
+
};
|
|
28
|
+
};
|
package/dist/Menu.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId, useRef, useState } from "react";
|
|
2
3
|
import { moveMenuFocus, useMenuPopover } from "./popover.js";
|
|
3
4
|
import { useOverlay } from "./overlay.js";
|
|
4
5
|
export function Menu({
|
|
@@ -8,7 +9,8 @@ export function Menu({
|
|
|
8
9
|
id,
|
|
9
10
|
label,
|
|
10
11
|
className = "mdbase-menu",
|
|
11
|
-
children
|
|
12
|
+
children,
|
|
13
|
+
point
|
|
12
14
|
}) {
|
|
13
15
|
const {
|
|
14
16
|
ref,
|
|
@@ -16,7 +18,8 @@ export function Menu({
|
|
|
16
18
|
} = useOverlay(open);
|
|
17
19
|
useMenuPopover(ref, triggerRef, onClose, {
|
|
18
20
|
align: "end",
|
|
19
|
-
open
|
|
21
|
+
open,
|
|
22
|
+
point
|
|
20
23
|
});
|
|
21
24
|
return present ? _jsx("div", {
|
|
22
25
|
ref: ref,
|
|
@@ -31,3 +34,31 @@ export function Menu({
|
|
|
31
34
|
children: children
|
|
32
35
|
}) : null;
|
|
33
36
|
}
|
|
37
|
+
export function useMenuTrigger() {
|
|
38
|
+
const id = useId();
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
const trigger = useRef(null);
|
|
41
|
+
const close = refocus => {
|
|
42
|
+
setOpen(false);
|
|
43
|
+
if (refocus) trigger.current?.focus();
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
open,
|
|
48
|
+
close,
|
|
49
|
+
trigger,
|
|
50
|
+
triggerProps: {
|
|
51
|
+
ref: trigger,
|
|
52
|
+
"aria-haspopup": "menu",
|
|
53
|
+
"aria-expanded": open,
|
|
54
|
+
"aria-controls": open ? id : undefined,
|
|
55
|
+
onClick: () => setOpen(value => !value),
|
|
56
|
+
onKeyDown: event => {
|
|
57
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
setOpen(true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/Toaster.d.ts
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
+
export interface ToastItem {
|
|
2
|
+
id: string;
|
|
3
|
+
message: string;
|
|
4
|
+
tone?: "info" | "success" | "error";
|
|
5
|
+
action?: {
|
|
6
|
+
label: string;
|
|
7
|
+
onAction: () => void;
|
|
8
|
+
busy?: boolean;
|
|
9
|
+
dismiss?: boolean;
|
|
10
|
+
};
|
|
11
|
+
sticky?: boolean;
|
|
12
|
+
dismissible?: boolean;
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
}
|
|
1
15
|
export declare function toast(message: string, undo?: () => void): void;
|
|
2
|
-
export declare function Toaster(
|
|
16
|
+
export declare function Toaster({ items, onDismiss }: {
|
|
17
|
+
items?: readonly ToastItem[];
|
|
18
|
+
onDismiss?: (id: string) => void;
|
|
19
|
+
}): import("react").JSX.Element;
|
package/dist/Toaster.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
|
3
3
|
import { useOverlay } from "./overlay.js";
|
|
4
4
|
import { i18n, useLocaleRevision } from "./i18n.js";
|
|
5
5
|
let queue = [];
|
|
@@ -10,18 +10,47 @@ export function toast(message, undo) {
|
|
|
10
10
|
const active = queue.filter(item => item.open);
|
|
11
11
|
if (active.length >= 4) active[1].open = false;
|
|
12
12
|
queue.push({
|
|
13
|
-
id: ++nextId
|
|
13
|
+
id: `toast-${++nextId}`,
|
|
14
14
|
message,
|
|
15
|
-
undo
|
|
15
|
+
action: undo ? {
|
|
16
|
+
label: i18n._(
|
|
17
|
+
/** i18n */
|
|
18
|
+
{
|
|
19
|
+
id: "9uI_rE",
|
|
20
|
+
message: "Undo"
|
|
21
|
+
}),
|
|
22
|
+
onAction: undo,
|
|
23
|
+
dismiss: true
|
|
24
|
+
} : undefined,
|
|
25
|
+
durationMs: undo ? 8_000 : 5_000,
|
|
16
26
|
open: true
|
|
17
27
|
});
|
|
18
28
|
notify();
|
|
19
29
|
}
|
|
20
|
-
export function Toaster(
|
|
30
|
+
export function Toaster({
|
|
31
|
+
items,
|
|
32
|
+
onDismiss
|
|
33
|
+
}) {
|
|
21
34
|
useLocaleRevision();
|
|
22
|
-
const [
|
|
35
|
+
const [queued, setQueued] = useState(() => [...queue]);
|
|
36
|
+
const source = items ?? queued;
|
|
37
|
+
const [previous, setPrevious] = useState(source);
|
|
38
|
+
const [visible, setVisible] = useState(() => source.map(item => ({
|
|
39
|
+
...item,
|
|
40
|
+
open: true
|
|
41
|
+
})));
|
|
42
|
+
if (source !== previous) {
|
|
43
|
+
setPrevious(source);
|
|
44
|
+
setVisible([...source.map(item => ({
|
|
45
|
+
...item,
|
|
46
|
+
open: "open" in item ? Boolean(item.open) : true
|
|
47
|
+
})), ...visible.filter(item => !source.some(current => current.id === item.id)).map(item => ({
|
|
48
|
+
...item,
|
|
49
|
+
open: false
|
|
50
|
+
}))]);
|
|
51
|
+
}
|
|
23
52
|
useEffect(() => {
|
|
24
|
-
const update = () =>
|
|
53
|
+
const update = () => setQueued([...queue]);
|
|
25
54
|
listeners.add(update);
|
|
26
55
|
update();
|
|
27
56
|
return () => {
|
|
@@ -31,18 +60,46 @@ export function Toaster() {
|
|
|
31
60
|
});
|
|
32
61
|
};
|
|
33
62
|
}, []);
|
|
63
|
+
const dismiss = useEffectEvent(id => {
|
|
64
|
+
if (items) onDismiss?.(id);else {
|
|
65
|
+
queue = queue.map(item => item.id === id ? {
|
|
66
|
+
...item,
|
|
67
|
+
open: false
|
|
68
|
+
} : item);
|
|
69
|
+
notify();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const escape = event => {
|
|
74
|
+
if (event.key !== "Escape" || event.defaultPrevented || document.querySelector('dialog[open], [role="dialog"], [role="alertdialog"], [role="menu"]')) return;
|
|
75
|
+
const item = [...visible].reverse().find(item => item.open && item.dismissible !== false && !item.action?.busy);
|
|
76
|
+
if (item) {
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
dismiss(item.id);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
window.addEventListener("keydown", escape);
|
|
82
|
+
return () => window.removeEventListener("keydown", escape);
|
|
83
|
+
}, [visible]);
|
|
34
84
|
return _jsx("div", {
|
|
35
85
|
className: "mdbase-toaster",
|
|
36
86
|
role: "status",
|
|
37
87
|
"aria-live": "polite",
|
|
38
88
|
"aria-relevant": "additions text",
|
|
39
|
-
children:
|
|
40
|
-
item: item
|
|
89
|
+
children: visible.map(item => _jsx(Toast, {
|
|
90
|
+
item: item,
|
|
91
|
+
onDismiss: () => dismiss(item.id),
|
|
92
|
+
onRemoved: () => {
|
|
93
|
+
setVisible(current => current.filter(entry => entry.id !== item.id));
|
|
94
|
+
queue = queue.filter(entry => entry.id !== item.id);
|
|
95
|
+
}
|
|
41
96
|
}, item.id))
|
|
42
97
|
});
|
|
43
98
|
}
|
|
44
|
-
function
|
|
45
|
-
item
|
|
99
|
+
function Toast({
|
|
100
|
+
item,
|
|
101
|
+
onDismiss,
|
|
102
|
+
onRemoved
|
|
46
103
|
}) {
|
|
47
104
|
const {
|
|
48
105
|
ref,
|
|
@@ -50,26 +107,24 @@ function ToastItem({
|
|
|
50
107
|
} = useOverlay(item.open);
|
|
51
108
|
const [hovered, setHovered] = useState(false);
|
|
52
109
|
const [focused, setFocused] = useState(false);
|
|
53
|
-
const remaining = useRef(item.
|
|
110
|
+
const remaining = useRef(item.durationMs ?? 6_000);
|
|
111
|
+
const dismiss = useEffectEvent(onDismiss);
|
|
112
|
+
const remove = useEffectEvent(onRemoved);
|
|
54
113
|
useEffect(() => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
notify();
|
|
58
|
-
}
|
|
59
|
-
}, [present, item]);
|
|
60
|
-
const dismiss = () => {
|
|
61
|
-
item.open = false;
|
|
62
|
-
notify();
|
|
63
|
-
};
|
|
114
|
+
remaining.current = item.durationMs ?? 6_000;
|
|
115
|
+
}, [item.message, item.durationMs]);
|
|
64
116
|
useEffect(() => {
|
|
65
|
-
if (!
|
|
117
|
+
if (!present) remove();
|
|
118
|
+
}, [present]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!item.open || item.sticky || item.action?.busy || hovered || focused) return;
|
|
66
121
|
const started = Date.now();
|
|
67
122
|
const timeout = setTimeout(dismiss, remaining.current);
|
|
68
123
|
return () => {
|
|
69
124
|
clearTimeout(timeout);
|
|
70
125
|
remaining.current -= Date.now() - started;
|
|
71
126
|
};
|
|
72
|
-
}, [item.open, hovered, focused]);
|
|
127
|
+
}, [item.open, item.sticky, item.message, item.durationMs, item.action?.busy, hovered, focused]);
|
|
73
128
|
if (!present) return null;
|
|
74
129
|
return _jsx("div", {
|
|
75
130
|
ref: ref,
|
|
@@ -86,22 +141,21 @@ function ToastItem({
|
|
|
86
141
|
className: "mdbase-toast-clip",
|
|
87
142
|
children: _jsxs("div", {
|
|
88
143
|
className: "mdbase-toast",
|
|
144
|
+
"data-tone": item.tone,
|
|
89
145
|
children: [_jsx("span", {
|
|
90
146
|
children: item.message
|
|
91
|
-
}), item.
|
|
147
|
+
}), item.action && _jsx("button", {
|
|
92
148
|
className: "mdbase-button is-secondary",
|
|
149
|
+
disabled: item.action.busy,
|
|
150
|
+
"aria-busy": item.action.busy || undefined,
|
|
93
151
|
onClick: () => {
|
|
94
|
-
dismiss();
|
|
95
|
-
item.
|
|
152
|
+
if (item.action?.dismiss) dismiss();
|
|
153
|
+
item.action?.onAction();
|
|
96
154
|
},
|
|
97
|
-
children:
|
|
98
|
-
|
|
99
|
-
{
|
|
100
|
-
id: "9uI_rE",
|
|
101
|
-
message: "Undo"
|
|
102
|
-
})
|
|
103
|
-
}), _jsx("button", {
|
|
155
|
+
children: item.action.label
|
|
156
|
+
}), item.dismissible !== false && _jsx("button", {
|
|
104
157
|
className: "mdbase-button is-tertiary",
|
|
158
|
+
disabled: item.action?.busy,
|
|
105
159
|
onClick: dismiss,
|
|
106
160
|
children: i18n._(
|
|
107
161
|
/** i18n */
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactElement } from "react";
|
|
2
|
+
export declare function Tooltip({ label, shortcut, children }: {
|
|
3
|
+
readonly label: string;
|
|
4
|
+
readonly shortcut?: string;
|
|
5
|
+
readonly children: ReactElement<ButtonHTMLAttributes<HTMLButtonElement>>;
|
|
6
|
+
}): import("react").JSX.Element;
|
package/dist/Tooltip.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cloneElement, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { useLocaleRevision } from "./i18n.js";
|
|
4
|
+
import { isApplePlatform, shortcutLabel } from "./shortcuts.js";
|
|
5
|
+
let activeTooltip;
|
|
6
|
+
let warmUntil = 0;
|
|
7
|
+
export function Tooltip({
|
|
8
|
+
label,
|
|
9
|
+
shortcut,
|
|
10
|
+
children
|
|
11
|
+
}) {
|
|
12
|
+
useLocaleRevision();
|
|
13
|
+
const id = useId();
|
|
14
|
+
const trigger = useRef(null);
|
|
15
|
+
const tooltip = useRef(null);
|
|
16
|
+
const timer = useRef(undefined);
|
|
17
|
+
const dispose = useRef(undefined);
|
|
18
|
+
const touch = useRef(false);
|
|
19
|
+
const [open, setOpen] = useState(false);
|
|
20
|
+
const close = useCallback(() => {
|
|
21
|
+
clearTimeout(timer.current);
|
|
22
|
+
dispose.current?.();
|
|
23
|
+
if (tooltip.current) warmUntil = performance.now() + 800;
|
|
24
|
+
if (activeTooltip === close) activeTooltip = undefined;
|
|
25
|
+
setOpen(false);
|
|
26
|
+
}, []);
|
|
27
|
+
useEffect(() => close, [close]);
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
if (!open) return;
|
|
30
|
+
const bubble = tooltip.current;
|
|
31
|
+
bubble.showPopover();
|
|
32
|
+
const button = trigger.current.getBoundingClientRect();
|
|
33
|
+
const bounds = bubble.getBoundingClientRect();
|
|
34
|
+
bubble.style.left = `${Math.max(8, Math.min(button.left + (button.width - bounds.width) / 2, innerWidth - bounds.width - 8))}px`;
|
|
35
|
+
bubble.style.top = `${Math.max(8, Math.min(button.bottom + 6 + bounds.height <= innerHeight - 8 ? button.bottom + 6 : button.top - bounds.height - 6, innerHeight - bounds.height - 8))}px`;
|
|
36
|
+
}, [open, label, shortcut]);
|
|
37
|
+
const show = (button, delay) => {
|
|
38
|
+
const available = () => button.isConnected && !button.matches(":disabled, [aria-disabled=true]") && !button.closest("[hidden], [inert], [aria-hidden=true]") && button.checkVisibility({
|
|
39
|
+
checkVisibilityCSS: true,
|
|
40
|
+
checkOpacity: true
|
|
41
|
+
});
|
|
42
|
+
if (!available()) return;
|
|
43
|
+
activeTooltip?.();
|
|
44
|
+
activeTooltip = close;
|
|
45
|
+
trigger.current = button;
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const observer = new MutationObserver(() => {
|
|
48
|
+
if (!available()) close();
|
|
49
|
+
});
|
|
50
|
+
observer.observe(document.documentElement, {
|
|
51
|
+
subtree: true,
|
|
52
|
+
childList: true,
|
|
53
|
+
attributes: true,
|
|
54
|
+
attributeFilter: ["disabled", "aria-disabled", "hidden", "aria-hidden", "inert", "style", "class", "open"]
|
|
55
|
+
});
|
|
56
|
+
dispose.current = () => {
|
|
57
|
+
controller.abort();
|
|
58
|
+
observer.disconnect();
|
|
59
|
+
};
|
|
60
|
+
document.addEventListener("keydown", event => {
|
|
61
|
+
if (event.key !== "Escape") return;
|
|
62
|
+
if (tooltip.current) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
event.stopImmediatePropagation();
|
|
65
|
+
}
|
|
66
|
+
close();
|
|
67
|
+
}, {
|
|
68
|
+
capture: true,
|
|
69
|
+
signal: controller.signal
|
|
70
|
+
});
|
|
71
|
+
document.addEventListener("pointerdown", close, {
|
|
72
|
+
capture: true,
|
|
73
|
+
signal: controller.signal
|
|
74
|
+
});
|
|
75
|
+
document.addEventListener("scroll", close, {
|
|
76
|
+
capture: true,
|
|
77
|
+
signal: controller.signal
|
|
78
|
+
});
|
|
79
|
+
window.addEventListener("resize", close, {
|
|
80
|
+
signal: controller.signal
|
|
81
|
+
});
|
|
82
|
+
window.addEventListener("blur", close, {
|
|
83
|
+
signal: controller.signal
|
|
84
|
+
});
|
|
85
|
+
if (delay && performance.now() >= warmUntil) timer.current = setTimeout(() => {
|
|
86
|
+
if (available()) setOpen(true);else close();
|
|
87
|
+
}, 400);else setOpen(true);
|
|
88
|
+
};
|
|
89
|
+
const leave = () => {
|
|
90
|
+
clearTimeout(timer.current);
|
|
91
|
+
if (tooltip.current) timer.current = setTimeout(close, 120);else close();
|
|
92
|
+
};
|
|
93
|
+
return _jsxs(_Fragment, {
|
|
94
|
+
children: [cloneElement(children, {
|
|
95
|
+
"aria-label": children.props["aria-label"] ?? label,
|
|
96
|
+
"aria-keyshortcuts": shortcut ? shortcut.replace(/\bmod\b/giu, isApplePlatform() ? "Meta" : "Control").replace(/\bctrl\b/giu, "Control") : children.props["aria-keyshortcuts"],
|
|
97
|
+
"aria-describedby": [children.props["aria-describedby"], open && shortcut ? id : ""].filter(Boolean).join(" ") || undefined,
|
|
98
|
+
title: undefined,
|
|
99
|
+
onPointerEnter: event => {
|
|
100
|
+
if (event.pointerType !== "touch" && matchMedia("(hover: hover)").matches) show(event.currentTarget, true);
|
|
101
|
+
children.props.onPointerEnter?.(event);
|
|
102
|
+
},
|
|
103
|
+
onPointerLeave: event => {
|
|
104
|
+
leave();
|
|
105
|
+
children.props.onPointerLeave?.(event);
|
|
106
|
+
},
|
|
107
|
+
onPointerDown: event => {
|
|
108
|
+
touch.current = event.pointerType === "touch";
|
|
109
|
+
close();
|
|
110
|
+
children.props.onPointerDown?.(event);
|
|
111
|
+
},
|
|
112
|
+
onFocus: event => {
|
|
113
|
+
if (!touch.current && event.currentTarget.matches(":focus-visible")) show(event.currentTarget, false);
|
|
114
|
+
children.props.onFocus?.(event);
|
|
115
|
+
},
|
|
116
|
+
onBlur: event => {
|
|
117
|
+
touch.current = false;
|
|
118
|
+
close();
|
|
119
|
+
children.props.onBlur?.(event);
|
|
120
|
+
},
|
|
121
|
+
onKeyDown: event => {
|
|
122
|
+
touch.current = false;
|
|
123
|
+
if (event.key === "Enter" || event.key === " ") close();
|
|
124
|
+
children.props.onKeyDown?.(event);
|
|
125
|
+
},
|
|
126
|
+
onClick: event => {
|
|
127
|
+
close();
|
|
128
|
+
children.props.onClick?.(event);
|
|
129
|
+
}
|
|
130
|
+
}), open && _jsxs("span", {
|
|
131
|
+
ref: tooltip,
|
|
132
|
+
role: "tooltip",
|
|
133
|
+
popover: "manual",
|
|
134
|
+
className: "mdbase-tooltip",
|
|
135
|
+
onPointerEnter: () => clearTimeout(timer.current),
|
|
136
|
+
onPointerLeave: leave,
|
|
137
|
+
children: [label, shortcut && _jsx("kbd", {
|
|
138
|
+
id: id,
|
|
139
|
+
children: shortcutLabel(shortcut)
|
|
140
|
+
})]
|
|
141
|
+
})]
|
|
142
|
+
});
|
|
143
|
+
}
|
package/dist/codemirror.js
CHANGED
|
@@ -37,8 +37,11 @@ export const mdbasePopupTheme = EditorView.theme({
|
|
|
37
37
|
lineHeight: "1.35"
|
|
38
38
|
},
|
|
39
39
|
".cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]": {
|
|
40
|
-
color: "var(--color-
|
|
41
|
-
background: "var(--color-
|
|
40
|
+
color: "var(--color-on-current)",
|
|
41
|
+
background: "var(--color-current)"
|
|
42
|
+
},
|
|
43
|
+
".cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected] :is(.cm-completionLabel, .cm-completionDetail, .cm-completionMatchedText, .cm-completionIcon), .cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected] .cm-completionIcon::after": {
|
|
44
|
+
color: "inherit"
|
|
42
45
|
},
|
|
43
46
|
".cm-tooltip.cm-tooltip-autocomplete > ul > li > *": {
|
|
44
47
|
minWidth: "0",
|
|
@@ -112,16 +115,28 @@ export const mdbasePopupTheme = EditorView.theme({
|
|
|
112
115
|
},
|
|
113
116
|
".cm-diagnostic": {
|
|
114
117
|
padding: "4px 8px",
|
|
118
|
+
border: "0",
|
|
115
119
|
borderRadius: "var(--control-radius, 2px)",
|
|
116
120
|
fontFamily: "var(--sans)"
|
|
117
121
|
},
|
|
118
122
|
".cm-diagnostic-error": {
|
|
119
|
-
|
|
123
|
+
backgroundColor: "var(--color-danger-soft)"
|
|
120
124
|
},
|
|
121
125
|
".cm-diagnostic-warning": {
|
|
122
|
-
|
|
126
|
+
backgroundColor: "var(--color-warning-surface)"
|
|
123
127
|
},
|
|
124
128
|
".cm-diagnostic-info, .cm-diagnostic-hint": {
|
|
125
|
-
|
|
129
|
+
backgroundColor: "var(--color-accent-soft)"
|
|
130
|
+
},
|
|
131
|
+
".cm-panel.cm-panel-lint": {
|
|
132
|
+
color: "var(--color-text)",
|
|
133
|
+
backgroundColor: "var(--color-surface)"
|
|
134
|
+
},
|
|
135
|
+
".cm-panel.cm-panel-lint ul [aria-selected], .cm-panel.cm-panel-lint ul:focus [aria-selected]": {
|
|
136
|
+
color: "var(--color-on-current)",
|
|
137
|
+
backgroundColor: "var(--color-current)"
|
|
138
|
+
},
|
|
139
|
+
".cm-panel.cm-panel-lint [aria-selected] .cm-diagnosticSource": {
|
|
140
|
+
opacity: "1"
|
|
126
141
|
}
|
|
127
142
|
});
|
package/dist/collections/copy.js
CHANGED
|
@@ -316,8 +316,8 @@ export const defaultCollectionCopy = {
|
|
|
316
316
|
return i18n._(
|
|
317
317
|
/** i18n */
|
|
318
318
|
{
|
|
319
|
-
id: "
|
|
320
|
-
message: "
|
|
319
|
+
id: "0xhU47",
|
|
320
|
+
message: "Preparing your offline copy\u2026",
|
|
321
321
|
context: "Collection access interface"
|
|
322
322
|
});
|
|
323
323
|
},
|
|
@@ -361,8 +361,8 @@ export const defaultCollectionCopy = {
|
|
|
361
361
|
return i18n._(
|
|
362
362
|
/** i18n */
|
|
363
363
|
{
|
|
364
|
-
id: "
|
|
365
|
-
message: "
|
|
364
|
+
id: "V5UB0c",
|
|
365
|
+
message: "Preparing secure access\u2026",
|
|
366
366
|
context: "Collection access interface"
|
|
367
367
|
});
|
|
368
368
|
},
|