@mdbase-dev/ui 0.1.0-beta.155 → 0.1.0-beta.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/css/collections.css +5 -100
- package/css/controls.css +35 -36
- package/css/feedback.css +6 -6
- package/css/motion.css +50 -26
- package/css/palette.css +32 -55
- package/css/toast.css +11 -6
- package/css/tokens.css +14 -25
- package/dist/AppSwitcher.js +18 -30
- package/dist/CommandPalette.d.ts +9 -2
- package/dist/CommandPalette.js +203 -167
- package/dist/ConfirmDialog.d.ts +18 -0
- package/dist/ConfirmDialog.js +74 -0
- package/dist/Dialog.d.ts +8 -8
- package/dist/Dialog.js +90 -25
- package/dist/Feedback.js +24 -56
- package/dist/FeedbackMarkup.d.ts +2 -1
- package/dist/FeedbackMarkup.js +9 -2
- package/dist/Menu.d.ts +28 -0
- package/dist/Menu.js +64 -0
- package/dist/Select.js +6 -2
- package/dist/SelectList.js +2 -1
- package/dist/Toaster.d.ts +18 -1
- package/dist/Toaster.js +132 -50
- package/dist/brand.js +5 -3
- package/dist/collections/CollectionSwitcher.d.ts +2 -3
- package/dist/collections/CollectionSwitcher.js +14 -173
- package/dist/collections/copy.js +4 -4
- package/dist/collections/dialogs.d.ts +9 -4
- package/dist/collections/dialogs.js +84 -87
- package/dist/collections/parts.d.ts +0 -9
- package/dist/collections/parts.js +5 -77
- 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/overlay.d.ts +4 -0
- package/dist/overlay.js +23 -0
- package/dist/popover.d.ts +6 -1
- package/dist/popover.js +22 -16
- package/package.json +14 -2
package/dist/AppSwitcher.js
CHANGED
|
@@ -5,9 +5,7 @@ import { useId, useRef, useState } from "react";
|
|
|
5
5
|
import { mdbaseAppHref, withAppUrls } from "./apps.js";
|
|
6
6
|
import { MdbaseAppMark, Wordmark } from "./brand.js";
|
|
7
7
|
import { useMdbaseMarkActivity } from "./mark-activity.js";
|
|
8
|
-
import {
|
|
9
|
-
/** The switcher plays its entrance once per page, not every time it remounts. */
|
|
10
|
-
let entrancePlayed = false;
|
|
8
|
+
import { Menu } from "./Menu.js";
|
|
11
9
|
/**
|
|
12
10
|
* The product wordmark as a menu for opening the current collection in the other mdbase apps.
|
|
13
11
|
* Each opens in a new tab so the current app stays where it is.
|
|
@@ -24,11 +22,6 @@ export function AppSwitcher({
|
|
|
24
22
|
const menuId = useId();
|
|
25
23
|
const triggerRef = useRef(null);
|
|
26
24
|
const [open, setOpen] = useState(false);
|
|
27
|
-
const [entrance] = useState(() => {
|
|
28
|
-
if (motion || entrancePlayed || typeof window === "undefined") return undefined;
|
|
29
|
-
entrancePlayed = true;
|
|
30
|
-
return "keys-first";
|
|
31
|
-
});
|
|
32
25
|
const activity = useMdbaseMarkActivity();
|
|
33
26
|
const close = refocus => {
|
|
34
27
|
setOpen(false);
|
|
@@ -66,7 +59,7 @@ export function AppSwitcher({
|
|
|
66
59
|
},
|
|
67
60
|
children: [_jsx(Wordmark, {
|
|
68
61
|
app: current,
|
|
69
|
-
motion: activity.busy ?? motion ??
|
|
62
|
+
motion: activity.busy ?? motion ?? "keys-first",
|
|
70
63
|
signal: activity.signal,
|
|
71
64
|
progress: activity.progress
|
|
72
65
|
}), _jsx("svg", {
|
|
@@ -77,28 +70,31 @@ export function AppSwitcher({
|
|
|
77
70
|
d: "m7 10 5 5 5-5"
|
|
78
71
|
})
|
|
79
72
|
})]
|
|
80
|
-
}),
|
|
73
|
+
}), _jsx(Menu, {
|
|
74
|
+
open: open,
|
|
81
75
|
id: menuId,
|
|
82
|
-
apps: withAppUrls(urls),
|
|
83
|
-
current: current,
|
|
84
76
|
triggerRef: triggerRef,
|
|
85
|
-
onClose: close
|
|
86
|
-
|
|
77
|
+
onClose: close,
|
|
78
|
+
label: _i18n._(
|
|
79
|
+
/** i18n */
|
|
80
|
+
{
|
|
81
|
+
id: "vDwCOr",
|
|
82
|
+
message: "mdbase apps"
|
|
83
|
+
}),
|
|
84
|
+
children: _jsx(AppMenu, {
|
|
85
|
+
apps: withAppUrls(urls),
|
|
86
|
+
current: current,
|
|
87
|
+
onClose: close
|
|
88
|
+
})
|
|
89
|
+
})]
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
92
|
function AppMenu({
|
|
90
|
-
id,
|
|
91
93
|
apps,
|
|
92
94
|
current,
|
|
93
|
-
triggerRef,
|
|
94
95
|
onClose
|
|
95
96
|
}) {
|
|
96
97
|
useLocaleRevision();
|
|
97
|
-
const menuRef = useRef(null);
|
|
98
|
-
useMenuPopover(menuRef, triggerRef, onClose, {
|
|
99
|
-
width: 320,
|
|
100
|
-
focus: 'a[role="menuitem"]'
|
|
101
|
-
});
|
|
102
98
|
const heading = new URL(location.href).searchParams.has("collection") ? _i18n._(
|
|
103
99
|
/** i18n */
|
|
104
100
|
{
|
|
@@ -110,15 +106,7 @@ function AppMenu({
|
|
|
110
106
|
id: "vDwCOr",
|
|
111
107
|
message: "mdbase apps"
|
|
112
108
|
});
|
|
113
|
-
return _jsxs(
|
|
114
|
-
ref: menuRef,
|
|
115
|
-
id: id,
|
|
116
|
-
className: "mdbase-menu",
|
|
117
|
-
popover: "manual",
|
|
118
|
-
role: "menu",
|
|
119
|
-
"aria-label": heading,
|
|
120
|
-
tabIndex: -1,
|
|
121
|
-
onKeyDown: event => moveMenuFocus(event, menuRef.current),
|
|
109
|
+
return _jsxs(_Fragment, {
|
|
122
110
|
children: [_jsx("div", {
|
|
123
111
|
className: "mdbase-menu-heading",
|
|
124
112
|
role: "presentation",
|
package/dist/CommandPalette.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { type JSX } from "react";
|
|
1
|
+
import { type JSX, type RefObject, type ReactNode } from "react";
|
|
2
2
|
export interface Command {
|
|
3
3
|
readonly id: string;
|
|
4
4
|
readonly label: string;
|
|
5
|
+
readonly content?: ReactNode;
|
|
5
6
|
readonly detail?: string | undefined;
|
|
7
|
+
readonly icon?: ReactNode;
|
|
6
8
|
/** Stable group ID; headings follow first appearance and may be presented by groupLabel. */
|
|
7
9
|
readonly group: string;
|
|
8
10
|
readonly keywords?: string | undefined;
|
|
@@ -27,7 +29,7 @@ export declare function matchingCommands(commands: readonly Command[], query: st
|
|
|
27
29
|
* Find or run anything: every mdbase app opens it with Mod+K. Typing filters commands; the
|
|
28
30
|
* arrows move, Enter runs, Shift+Enter runs a command's alternate, Escape closes.
|
|
29
31
|
*/
|
|
30
|
-
export declare function CommandPalette({ open, commands, onClose, label, placeholder, showAll, groupLabel }: {
|
|
32
|
+
export declare function CommandPalette({ open, commands, onClose, label, placeholder, showAll, groupLabel, returnFocusRef, emptyState, initialQuery, getResults, inputLabel }: {
|
|
31
33
|
readonly open: boolean;
|
|
32
34
|
readonly commands: readonly Command[];
|
|
33
35
|
readonly onClose: () => void;
|
|
@@ -36,4 +38,9 @@ export declare function CommandPalette({ open, commands, onClose, label, placeho
|
|
|
36
38
|
readonly showAll?: readonly string[] | undefined;
|
|
37
39
|
/** Presentation only: translate headings without changing group or showAll IDs. */
|
|
38
40
|
readonly groupLabel?: ((group: string) => string) | undefined;
|
|
41
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
42
|
+
readonly emptyState?: ReactNode;
|
|
43
|
+
readonly initialQuery?: string;
|
|
44
|
+
readonly getResults?: (query: string) => readonly Command[];
|
|
45
|
+
readonly inputLabel?: string;
|
|
39
46
|
}): JSX.Element | null;
|
package/dist/CommandPalette.js
CHANGED
|
@@ -1,21 +1,40 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
3
|
import { useLocaleRevision } from "./i18n.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Dialog } from "./Dialog.js";
|
|
5
|
+
import { Fragment, useEffect, useLayoutEffect, useId, useMemo, useRef, useState } from "react";
|
|
5
6
|
export function isApplePlatform() {
|
|
6
7
|
return typeof navigator !== "undefined" && /Mac|iPhone|iPad/u.test(navigator.platform || navigator.userAgent);
|
|
7
8
|
}
|
|
8
9
|
/** "mod+shift+f" as the platform writes it: ⌘⇧F on Apple systems, Ctrl+Shift+F elsewhere. */
|
|
9
10
|
export function shortcutLabel(shortcut) {
|
|
11
|
+
if (/^[a-z] [a-z]$/iu.test(shortcut)) return shortcut.toUpperCase();
|
|
10
12
|
const apple = isApplePlatform();
|
|
11
13
|
return shortcut.split("+").map(part => {
|
|
12
14
|
switch (part.toLowerCase()) {
|
|
13
15
|
case "mod":
|
|
14
16
|
return apple ? "⌘" : "Ctrl";
|
|
17
|
+
case "ctrl":
|
|
18
|
+
return apple ? "⌃" : "Ctrl";
|
|
15
19
|
case "shift":
|
|
16
20
|
return apple ? "⇧" : "Shift";
|
|
17
21
|
case "alt":
|
|
18
22
|
return apple ? "⌥" : "Alt";
|
|
23
|
+
case "arrowdown":
|
|
24
|
+
return "↓";
|
|
25
|
+
case "arrowup":
|
|
26
|
+
return "↑";
|
|
27
|
+
case "arrowleft":
|
|
28
|
+
return "←";
|
|
29
|
+
case "arrowright":
|
|
30
|
+
return "→";
|
|
31
|
+
case "contextmenu":
|
|
32
|
+
return _i18n._(
|
|
33
|
+
/** i18n */
|
|
34
|
+
{
|
|
35
|
+
id: "zucql-",
|
|
36
|
+
message: "Menu"
|
|
37
|
+
});
|
|
19
38
|
default:
|
|
20
39
|
return part.length === 1 ? part.toUpperCase() : part;
|
|
21
40
|
}
|
|
@@ -41,10 +60,12 @@ export function matchingCommands(commands, query, showAll = []) {
|
|
|
41
60
|
const content = `${command.label} ${command.detail ?? ""} ${command.group} ${command.keywords ?? ""}`.toLocaleLowerCase();
|
|
42
61
|
return terms.every(term => content.includes(term));
|
|
43
62
|
});
|
|
44
|
-
const
|
|
63
|
+
const names = matches.filter(command => terms.every(term => command.label.toLocaleLowerCase().includes(term)));
|
|
64
|
+
const selected = [...names, ...matches.filter(command => !names.includes(command))].slice(0, searchLimit);
|
|
65
|
+
const groups = [...new Set(selected.map(({
|
|
45
66
|
group
|
|
46
67
|
}) => group))];
|
|
47
|
-
return groups.flatMap(group =>
|
|
68
|
+
return groups.flatMap(group => selected.filter(command => command.group === group));
|
|
48
69
|
}
|
|
49
70
|
/**
|
|
50
71
|
* Find or run anything: every mdbase app opens it with Mod+K. Typing filters commands; the
|
|
@@ -67,215 +88,227 @@ export function CommandPalette({
|
|
|
67
88
|
message: "Search commands"
|
|
68
89
|
}),
|
|
69
90
|
showAll,
|
|
70
|
-
groupLabel
|
|
91
|
+
groupLabel,
|
|
92
|
+
returnFocusRef,
|
|
93
|
+
emptyState,
|
|
94
|
+
initialQuery = "",
|
|
95
|
+
getResults,
|
|
96
|
+
inputLabel = placeholder
|
|
71
97
|
}) {
|
|
72
98
|
useLocaleRevision();
|
|
73
|
-
return
|
|
74
|
-
|
|
99
|
+
return _jsx(Dialog, {
|
|
100
|
+
open: open,
|
|
101
|
+
title: label,
|
|
75
102
|
onClose: onClose,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
103
|
+
returnFocusRef: returnFocusRef,
|
|
104
|
+
className: "mdbase-command-palette",
|
|
105
|
+
children: _jsx(OpenCommandPalette, {
|
|
106
|
+
open: open,
|
|
107
|
+
commands: commands,
|
|
108
|
+
onClose: onClose,
|
|
109
|
+
label: label,
|
|
110
|
+
placeholder: placeholder,
|
|
111
|
+
showAll: showAll,
|
|
112
|
+
groupLabel: groupLabel,
|
|
113
|
+
returnFocusRef: returnFocusRef,
|
|
114
|
+
emptyState: emptyState,
|
|
115
|
+
initialQuery: initialQuery,
|
|
116
|
+
getResults: getResults,
|
|
117
|
+
inputLabel: inputLabel
|
|
118
|
+
})
|
|
119
|
+
});
|
|
81
120
|
}
|
|
82
121
|
function OpenCommandPalette({
|
|
122
|
+
open,
|
|
83
123
|
commands,
|
|
84
124
|
onClose,
|
|
85
125
|
label,
|
|
86
126
|
placeholder,
|
|
87
127
|
showAll,
|
|
88
|
-
groupLabel
|
|
128
|
+
groupLabel,
|
|
129
|
+
returnFocusRef,
|
|
130
|
+
emptyState,
|
|
131
|
+
initialQuery,
|
|
132
|
+
getResults,
|
|
133
|
+
inputLabel
|
|
89
134
|
}) {
|
|
90
135
|
useLocaleRevision();
|
|
91
|
-
const [query, setQuery] = useState(
|
|
136
|
+
const [query, setQuery] = useState(initialQuery);
|
|
92
137
|
const [active, setActive] = useState(0);
|
|
93
138
|
const inputRef = useRef(null);
|
|
94
|
-
const
|
|
95
|
-
const matches = useMemo(() => matchingCommands(commands, query, showAll), [commands, query, showAll]);
|
|
139
|
+
const resultsRef = useRef(null);
|
|
140
|
+
const matches = useMemo(() => getResults ? getResults(query) : matchingCommands(commands, query, showAll), [commands, query, showAll, getResults]);
|
|
141
|
+
useLayoutEffect(() => {
|
|
142
|
+
resultsRef.current.querySelector('[aria-selected="true"]')?.scrollIntoView({
|
|
143
|
+
block: "nearest"
|
|
144
|
+
});
|
|
145
|
+
}, [active, matches]);
|
|
96
146
|
useEffect(() => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
147
|
+
if (open) {
|
|
148
|
+
setQuery(initialQuery);
|
|
149
|
+
setActive(0);
|
|
150
|
+
}
|
|
151
|
+
}, [open, initialQuery]);
|
|
101
152
|
const run = (command, alternate = false) => {
|
|
153
|
+
inputRef.current?.closest("dialog")?.close();
|
|
154
|
+
returnFocusRef?.current?.focus({
|
|
155
|
+
preventScroll: true
|
|
156
|
+
});
|
|
102
157
|
onClose();
|
|
103
158
|
(alternate && command.alternate ? command.alternate.run : command.run)();
|
|
104
159
|
};
|
|
105
160
|
const hintId = useId();
|
|
106
|
-
return _jsxs(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
161
|
+
return _jsxs(_Fragment, {
|
|
162
|
+
children: [_jsxs("label", {
|
|
163
|
+
className: "mdbase-command-search",
|
|
164
|
+
children: [_jsxs("svg", {
|
|
165
|
+
viewBox: "0 0 24 24",
|
|
166
|
+
"aria-hidden": "true",
|
|
167
|
+
fill: "none",
|
|
168
|
+
stroke: "currentColor",
|
|
169
|
+
strokeWidth: "1.6",
|
|
170
|
+
children: [_jsx("circle", {
|
|
171
|
+
cx: "11",
|
|
172
|
+
cy: "11",
|
|
173
|
+
r: "6.5"
|
|
174
|
+
}), _jsx("path", {
|
|
175
|
+
d: "m16 16 4 4"
|
|
176
|
+
})]
|
|
177
|
+
}), _jsx("span", {
|
|
178
|
+
className: "mdbase-visually-hidden",
|
|
179
|
+
children: inputLabel
|
|
180
|
+
}), _jsx("input", {
|
|
181
|
+
ref: inputRef,
|
|
182
|
+
"data-autofocus": true,
|
|
183
|
+
value: query,
|
|
184
|
+
placeholder: placeholder,
|
|
185
|
+
onChange: event => {
|
|
186
|
+
setQuery(event.target.value);
|
|
187
|
+
setActive(0);
|
|
188
|
+
},
|
|
189
|
+
role: "combobox",
|
|
190
|
+
"aria-autocomplete": "list",
|
|
191
|
+
"aria-expanded": "true",
|
|
192
|
+
"aria-controls": `${hintId}-results`,
|
|
193
|
+
"aria-activedescendant": matches[active] ? `${hintId}-${matches[active].id}` : undefined,
|
|
194
|
+
onKeyDown: event => {
|
|
195
|
+
if (!event.nativeEvent.isComposing) handleKeys(event, matches, active, setActive, run, onClose);
|
|
196
|
+
}
|
|
197
|
+
})]
|
|
198
|
+
}), _jsx("div", {
|
|
199
|
+
ref: resultsRef,
|
|
200
|
+
id: `${hintId}-results`,
|
|
201
|
+
className: "mdbase-command-results",
|
|
202
|
+
role: "listbox",
|
|
112
203
|
"aria-label": _i18n._(
|
|
113
204
|
/** i18n */
|
|
114
205
|
{
|
|
115
|
-
id: "
|
|
116
|
-
message: "
|
|
117
|
-
values: {
|
|
118
|
-
label: label
|
|
119
|
-
}
|
|
206
|
+
id: "kx0s-n",
|
|
207
|
+
message: "Results"
|
|
120
208
|
}),
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
placeholder: placeholder,
|
|
158
|
-
onChange: event => {
|
|
159
|
-
setQuery(event.target.value);
|
|
160
|
-
setActive(0);
|
|
161
|
-
},
|
|
162
|
-
onKeyDown: event => handleKeys(event, matches, active, setActive, run, onClose)
|
|
209
|
+
"aria-describedby": hintId,
|
|
210
|
+
children: matches.length > 0 ? matches.map((command, index) => _jsxs(Fragment, {
|
|
211
|
+
children: [command.group !== matches[index - 1]?.group ? _jsx("div", {
|
|
212
|
+
className: "mdbase-command-group",
|
|
213
|
+
role: "presentation",
|
|
214
|
+
children: groupLabel ? groupLabel(command.group) : command.group
|
|
215
|
+
}) : null, _jsx(CommandRow, {
|
|
216
|
+
id: `${hintId}-${command.id}`,
|
|
217
|
+
command: command,
|
|
218
|
+
query: query,
|
|
219
|
+
active: index === active,
|
|
220
|
+
onRun: run
|
|
221
|
+
})]
|
|
222
|
+
}, command.id)) : _jsx("div", {
|
|
223
|
+
className: "mdbase-command-empty",
|
|
224
|
+
role: "status",
|
|
225
|
+
children: emptyState ?? _i18n._(
|
|
226
|
+
/** i18n */
|
|
227
|
+
{
|
|
228
|
+
id: "DViXWV",
|
|
229
|
+
message: "Nothing matches"
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
}), _jsxs("footer", {
|
|
233
|
+
className: "mdbase-command-footer",
|
|
234
|
+
id: hintId,
|
|
235
|
+
children: [_jsxs("span", {
|
|
236
|
+
children: [_jsx("kbd", {
|
|
237
|
+
children: "\u2191"
|
|
238
|
+
}), _jsx("kbd", {
|
|
239
|
+
children: "\u2193"
|
|
240
|
+
}), " ", _i18n._(
|
|
241
|
+
/** i18n */
|
|
242
|
+
{
|
|
243
|
+
id: "2UA-qq",
|
|
244
|
+
message: "to move"
|
|
163
245
|
})]
|
|
164
|
-
}),
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
"
|
|
246
|
+
}), _jsxs("span", {
|
|
247
|
+
children: [_jsx("kbd", {
|
|
248
|
+
children: "\u21B5"
|
|
249
|
+
}), " ", _i18n._(
|
|
168
250
|
/** i18n */
|
|
169
251
|
{
|
|
170
|
-
id: "
|
|
171
|
-
message: "
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
children:
|
|
175
|
-
children:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
active: index === active,
|
|
182
|
-
onRun: run
|
|
183
|
-
})]
|
|
184
|
-
}, command.id)) : _jsx("div", {
|
|
185
|
-
className: "mdbase-command-empty",
|
|
252
|
+
id: "2cqK5k",
|
|
253
|
+
message: "to open"
|
|
254
|
+
})]
|
|
255
|
+
}), matches[active]?.alternate ? _jsxs("span", {
|
|
256
|
+
children: [_jsx("kbd", {
|
|
257
|
+
children: shortcutLabel("shift")
|
|
258
|
+
}), _jsx("kbd", {
|
|
259
|
+
children: "\u21B5"
|
|
260
|
+
}), " ", matches[active].alternate.label.toLocaleLowerCase()]
|
|
261
|
+
}) : null, _jsxs("span", {
|
|
262
|
+
children: [_jsx("kbd", {
|
|
186
263
|
children: _i18n._(
|
|
187
264
|
/** i18n */
|
|
188
265
|
{
|
|
189
|
-
id: "
|
|
190
|
-
message: "
|
|
266
|
+
id: "zO1gmR",
|
|
267
|
+
message: "Esc"
|
|
191
268
|
})
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
children: [_jsx("kbd", {
|
|
198
|
-
children: "\u2191"
|
|
199
|
-
}), _jsx("kbd", {
|
|
200
|
-
children: "\u2193"
|
|
201
|
-
}), " ", _i18n._(
|
|
202
|
-
/** i18n */
|
|
203
|
-
{
|
|
204
|
-
id: "2UA-qq",
|
|
205
|
-
message: "to move"
|
|
206
|
-
})]
|
|
207
|
-
}), _jsxs("span", {
|
|
208
|
-
children: [_jsx("kbd", {
|
|
209
|
-
children: "\u21B5"
|
|
210
|
-
}), " ", _i18n._(
|
|
211
|
-
/** i18n */
|
|
212
|
-
{
|
|
213
|
-
id: "2cqK5k",
|
|
214
|
-
message: "to open"
|
|
215
|
-
})]
|
|
216
|
-
}), matches[active]?.alternate ? _jsxs("span", {
|
|
217
|
-
children: [_jsx("kbd", {
|
|
218
|
-
children: shortcutLabel("shift")
|
|
219
|
-
}), _jsx("kbd", {
|
|
220
|
-
children: "\u21B5"
|
|
221
|
-
}), " ", matches[active].alternate.label.toLocaleLowerCase()]
|
|
222
|
-
}) : null, _jsxs("span", {
|
|
223
|
-
children: [_jsx("kbd", {
|
|
224
|
-
children: _i18n._(
|
|
225
|
-
/** i18n */
|
|
226
|
-
{
|
|
227
|
-
id: "zO1gmR",
|
|
228
|
-
message: "Esc"
|
|
229
|
-
})
|
|
230
|
-
}), " ", _i18n._(
|
|
231
|
-
/** i18n */
|
|
232
|
-
{
|
|
233
|
-
id: "UbVgIu",
|
|
234
|
-
message: "to close"
|
|
235
|
-
})]
|
|
269
|
+
}), " ", _i18n._(
|
|
270
|
+
/** i18n */
|
|
271
|
+
{
|
|
272
|
+
id: "UbVgIu",
|
|
273
|
+
message: "to close"
|
|
236
274
|
})]
|
|
237
275
|
})]
|
|
238
276
|
})]
|
|
239
277
|
});
|
|
240
278
|
}
|
|
241
|
-
function trapFocus(event, container) {
|
|
242
|
-
if (!container) return;
|
|
243
|
-
const items = [...container.querySelectorAll("input, button, [tabindex]:not([tabindex='-1'])")];
|
|
244
|
-
const first = items[0];
|
|
245
|
-
const last = items.at(-1);
|
|
246
|
-
if (!first || !last) return;
|
|
247
|
-
if (event.shiftKey && document.activeElement === first) {
|
|
248
|
-
event.preventDefault();
|
|
249
|
-
last.focus();
|
|
250
|
-
} else if (!event.shiftKey && document.activeElement === last) {
|
|
251
|
-
event.preventDefault();
|
|
252
|
-
first.focus();
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
279
|
function CommandRow({
|
|
280
|
+
id,
|
|
256
281
|
command,
|
|
282
|
+
query,
|
|
257
283
|
active,
|
|
258
284
|
onRun
|
|
259
285
|
}) {
|
|
260
286
|
useLocaleRevision();
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
});
|
|
266
|
-
}, [active]);
|
|
287
|
+
const pattern = query.trim().split(/\s+/u).filter(Boolean).map(term => term.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")).join("|");
|
|
288
|
+
const label = pattern ? command.label.split(new RegExp(`(${pattern})`, "giu")).map((part, index) => index % 2 ? _jsx("mark", {
|
|
289
|
+
children: part
|
|
290
|
+
}, index) : part) : command.label;
|
|
267
291
|
return _jsxs("button", {
|
|
268
|
-
|
|
292
|
+
id: id,
|
|
293
|
+
tabIndex: -1,
|
|
269
294
|
type: "button",
|
|
270
295
|
role: "option",
|
|
271
296
|
"aria-selected": active,
|
|
272
|
-
onMouseDown: event =>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
297
|
+
onMouseDown: event => event.preventDefault(),
|
|
298
|
+
onClick: event => onRun(command, event.shiftKey),
|
|
299
|
+
children: [command.icon && _jsx("span", {
|
|
300
|
+
className: "mdbase-command-icon",
|
|
301
|
+
"aria-hidden": "true",
|
|
302
|
+
children: command.icon
|
|
303
|
+
}), _jsx("span", {
|
|
304
|
+
className: "mdbase-command-copy",
|
|
305
|
+
children: command.content ?? _jsxs(_Fragment, {
|
|
306
|
+
children: [_jsx("strong", {
|
|
307
|
+
children: label
|
|
308
|
+
}), command.detail ? _jsx("small", {
|
|
309
|
+
children: command.detail
|
|
310
|
+
}) : null]
|
|
311
|
+
})
|
|
279
312
|
}), command.alternate && active ? _jsxs("span", {
|
|
280
313
|
className: "mdbase-command-alternate",
|
|
281
314
|
children: [shortcutLabel("shift"), "\u21B5 ", command.alternate.label]
|
|
@@ -292,6 +325,9 @@ function handleKeys(event, matches, active, setActive, run, close) {
|
|
|
292
325
|
event.preventDefault();
|
|
293
326
|
const direction = event.key === "ArrowDown" ? 1 : -1;
|
|
294
327
|
setActive((active + direction + matches.length) % Math.max(1, matches.length));
|
|
328
|
+
} else if (event.key === "Home" || event.key === "End") {
|
|
329
|
+
event.preventDefault();
|
|
330
|
+
setActive(event.key === "Home" ? 0 : Math.max(0, matches.length - 1));
|
|
295
331
|
} else if (event.key === "Enter") {
|
|
296
332
|
const command = matches[active];
|
|
297
333
|
if (command) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from "react";
|
|
2
|
+
export declare function ConfirmDialog({ open, title, consequence, confirmLabel, pendingLabel, busy, disabled, onConfirm, onClose, returnFocusRef, children, cancelLabel, tone, initialFocus, role }: {
|
|
3
|
+
readonly open: boolean;
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly consequence?: string;
|
|
6
|
+
readonly confirmLabel: string;
|
|
7
|
+
readonly pendingLabel: string;
|
|
8
|
+
readonly busy?: boolean;
|
|
9
|
+
readonly disabled?: boolean;
|
|
10
|
+
readonly onConfirm: () => void | Promise<unknown>;
|
|
11
|
+
readonly onClose: () => void;
|
|
12
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
13
|
+
readonly children?: ReactNode;
|
|
14
|
+
readonly cancelLabel?: string | undefined;
|
|
15
|
+
readonly tone?: "default" | "danger" | undefined;
|
|
16
|
+
readonly initialFocus?: "confirm" | "cancel" | undefined;
|
|
17
|
+
readonly role?: "dialog" | "alertdialog";
|
|
18
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { i18n as _i18n } from "@lingui/core";
|
|
3
|
+
import { useId, useState } from "react";
|
|
4
|
+
import { Dialog } from "./Dialog.js";
|
|
5
|
+
import { useLocaleRevision } from "./i18n.js";
|
|
6
|
+
export function ConfirmDialog({
|
|
7
|
+
open,
|
|
8
|
+
title,
|
|
9
|
+
consequence,
|
|
10
|
+
confirmLabel,
|
|
11
|
+
pendingLabel,
|
|
12
|
+
busy = false,
|
|
13
|
+
disabled = false,
|
|
14
|
+
onConfirm,
|
|
15
|
+
onClose,
|
|
16
|
+
returnFocusRef,
|
|
17
|
+
children,
|
|
18
|
+
cancelLabel = _i18n._(
|
|
19
|
+
/** i18n */
|
|
20
|
+
{
|
|
21
|
+
id: "dEgA5A",
|
|
22
|
+
message: "Cancel"
|
|
23
|
+
}),
|
|
24
|
+
tone = "danger",
|
|
25
|
+
initialFocus = "cancel",
|
|
26
|
+
role = "dialog"
|
|
27
|
+
}) {
|
|
28
|
+
useLocaleRevision();
|
|
29
|
+
const [pending, setPending] = useState(false);
|
|
30
|
+
const descriptionId = useId();
|
|
31
|
+
const working = busy || pending;
|
|
32
|
+
return _jsxs(Dialog, {
|
|
33
|
+
open: open,
|
|
34
|
+
role: role,
|
|
35
|
+
title: title,
|
|
36
|
+
descriptionId: consequence ? descriptionId : undefined,
|
|
37
|
+
onClose: onClose,
|
|
38
|
+
closeDisabled: working,
|
|
39
|
+
returnFocusRef: returnFocusRef,
|
|
40
|
+
className: "mdbase-confirm-dialog",
|
|
41
|
+
children: [consequence && _jsx("p", {
|
|
42
|
+
id: descriptionId,
|
|
43
|
+
children: consequence
|
|
44
|
+
}), children, _jsxs("footer", {
|
|
45
|
+
className: "mdbase-dialog-actions",
|
|
46
|
+
children: [_jsx("button", {
|
|
47
|
+
type: "button",
|
|
48
|
+
className: "mdbase-button is-tertiary",
|
|
49
|
+
"data-autofocus": initialFocus === "cancel" || undefined,
|
|
50
|
+
disabled: working,
|
|
51
|
+
onClick: onClose,
|
|
52
|
+
children: cancelLabel
|
|
53
|
+
}), _jsx("button", {
|
|
54
|
+
type: "button",
|
|
55
|
+
className: `mdbase-button ${tone === "danger" ? "is-danger" : "is-primary"}`,
|
|
56
|
+
"data-autofocus": initialFocus === "confirm" || undefined,
|
|
57
|
+
"aria-busy": working || undefined,
|
|
58
|
+
disabled: working || disabled,
|
|
59
|
+
onClick: async event => {
|
|
60
|
+
event.currentTarget.closest("dialog")?.focus({
|
|
61
|
+
preventScroll: true
|
|
62
|
+
});
|
|
63
|
+
setPending(true);
|
|
64
|
+
try {
|
|
65
|
+
await onConfirm();
|
|
66
|
+
} finally {
|
|
67
|
+
setPending(false);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
children: working ? pendingLabel : confirmLabel
|
|
71
|
+
})]
|
|
72
|
+
})]
|
|
73
|
+
});
|
|
74
|
+
}
|