@mdbase-dev/ui 0.1.0-beta.155 → 0.1.0-beta.156
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 +32 -33
- package/css/feedback.css +6 -6
- package/css/motion.css +50 -26
- package/css/palette.css +22 -54
- package/css/toast.css +10 -5
- package/css/tokens.css +11 -25
- package/dist/AppSwitcher.js +18 -30
- package/dist/CommandPalette.d.ts +5 -2
- package/dist/CommandPalette.js +157 -152
- package/dist/ConfirmDialog.d.ts +14 -0
- package/dist/ConfirmDialog.js +65 -0
- package/dist/Dialog.d.ts +5 -7
- package/dist/Dialog.js +46 -24
- package/dist/Feedback.js +24 -56
- package/dist/FeedbackMarkup.d.ts +2 -1
- package/dist/FeedbackMarkup.js +8 -2
- package/dist/Menu.d.ts +10 -0
- package/dist/Menu.js +33 -0
- package/dist/Select.js +6 -2
- package/dist/SelectList.js +2 -1
- package/dist/Toaster.js +72 -44
- package/dist/brand.js +5 -3
- package/dist/collections/CollectionSwitcher.d.ts +2 -3
- package/dist/collections/CollectionSwitcher.js +14 -173
- package/dist/collections/dialogs.d.ts +9 -4
- package/dist/collections/dialogs.js +83 -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 +2 -1
- package/dist/popover.js +6 -13
- package/package.json +14 -2
package/dist/Dialog.js
CHANGED
|
@@ -1,50 +1,72 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
|
-
import { useLocaleRevision } from "./i18n.js";
|
|
4
3
|
import { useLayoutEffect, useRef } from "react";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { useLocaleRevision } from "./i18n.js";
|
|
6
|
+
import { useOverlay } from "./overlay.js";
|
|
9
7
|
export function Dialog({
|
|
10
8
|
open,
|
|
11
9
|
onClose,
|
|
12
10
|
title,
|
|
11
|
+
descriptionId,
|
|
13
12
|
className,
|
|
14
13
|
closeDisabled = false,
|
|
14
|
+
returnFocusRef,
|
|
15
15
|
children
|
|
16
16
|
}) {
|
|
17
17
|
useLocaleRevision();
|
|
18
|
-
const
|
|
18
|
+
const {
|
|
19
|
+
ref,
|
|
20
|
+
present
|
|
21
|
+
} = useOverlay(open);
|
|
22
|
+
const invoker = useRef(null);
|
|
19
23
|
useLayoutEffect(() => {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const dialog = ref.current;
|
|
25
|
+
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
|
+
invoker.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
34
|
+
dialog.showModal();
|
|
35
|
+
dialog.querySelector("[data-autofocus]")?.focus();
|
|
36
|
+
}, [open, ref]);
|
|
27
37
|
useLayoutEffect(() => {
|
|
28
38
|
const dialog = ref.current;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
return () => {
|
|
40
|
+
const wasOpen = dialog?.open;
|
|
41
|
+
dialog?.close();
|
|
42
|
+
if (wasOpen && !document.querySelector("dialog[open]")) (returnFocusRef?.current ?? invoker.current)?.focus({
|
|
43
|
+
preventScroll: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}, [present, ref, returnFocusRef]);
|
|
47
|
+
if (!present) return null;
|
|
48
|
+
return createPortal(_jsx("dialog", {
|
|
33
49
|
ref: ref,
|
|
34
|
-
className: ["mdbase-dialog", className].filter(Boolean).join(" "),
|
|
50
|
+
className: ["mdbase-dialog mdbase-overlay", className].filter(Boolean).join(" "),
|
|
51
|
+
"data-open": open,
|
|
52
|
+
role: "dialog",
|
|
35
53
|
"aria-label": title,
|
|
36
|
-
|
|
54
|
+
"aria-describedby": descriptionId,
|
|
55
|
+
onKeyDown: event => {
|
|
56
|
+
event.stopPropagation();
|
|
57
|
+
if (event.key === "Escape") {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
if (!closeDisabled) onClose();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
37
62
|
onCancel: event => {
|
|
38
63
|
event.preventDefault();
|
|
39
64
|
if (!closeDisabled) onClose();
|
|
40
65
|
},
|
|
41
|
-
onClose: () => {
|
|
42
|
-
if (!closeDisabled) onClose();
|
|
43
|
-
},
|
|
44
66
|
onMouseDown: event => {
|
|
45
67
|
if (!closeDisabled && event.target === event.currentTarget) onClose();
|
|
46
68
|
},
|
|
47
|
-
children:
|
|
69
|
+
children: _jsxs("div", {
|
|
48
70
|
className: "mdbase-dialog-body",
|
|
49
71
|
children: [_jsxs("header", {
|
|
50
72
|
className: "mdbase-dialog-header",
|
|
@@ -75,5 +97,5 @@ export function Dialog({
|
|
|
75
97
|
})]
|
|
76
98
|
}), children]
|
|
77
99
|
})
|
|
78
|
-
});
|
|
100
|
+
}), document.body);
|
|
79
101
|
}
|
package/dist/Feedback.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { flushSync } from "react-dom";
|
|
2
3
|
import { i18n as _i18n } from "@lingui/core";
|
|
3
4
|
import { useLocaleRevision } from "./i18n.js";
|
|
4
5
|
import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import { Dialog } from "./Dialog.js";
|
|
5
7
|
import { FeedbackMarkup } from "./FeedbackMarkup.js";
|
|
6
8
|
import { FeedbackVerification } from "./FeedbackVerification.js";
|
|
7
9
|
import { FEEDBACK_ERROR_CODES, FEEDBACK_MAX_MESSAGE_LENGTH, captureFeedbackScreenshot, feedbackDiagnostics, feedbackEvents, feedbackTopics, readFeedbackScreenshot, resolveFeedbackEndpoint, screenshotUrl, sendFeedback } from "./feedback-data.js";
|
|
@@ -96,12 +98,10 @@ export function FeedbackProvider({
|
|
|
96
98
|
}) {
|
|
97
99
|
useLocaleRevision();
|
|
98
100
|
const endpoint = resolveFeedbackEndpoint(configuredEndpoint ?? undefined);
|
|
99
|
-
const dialog = useRef(null);
|
|
100
101
|
const content = useRef(null);
|
|
101
|
-
const messageField = useRef(null);
|
|
102
102
|
const successHeading = useRef(null);
|
|
103
|
+
const messageField = useRef(null);
|
|
103
104
|
const body = useRef(null);
|
|
104
|
-
const trigger = useRef(null);
|
|
105
105
|
const events = useRef([]);
|
|
106
106
|
const lastWiggle = useRef(-Infinity);
|
|
107
107
|
const imageOperation = useRef(null);
|
|
@@ -125,6 +125,9 @@ export function FeedbackProvider({
|
|
|
125
125
|
const [submitError, setSubmitError] = useState("");
|
|
126
126
|
const [submitting, setSubmitting] = useState(false);
|
|
127
127
|
const [submitted, setSubmitted] = useState(null);
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
if (submitted) successHeading.current?.focus();
|
|
130
|
+
}, [submitted]);
|
|
128
131
|
const [turnstileToken, setTurnstileToken] = useState("");
|
|
129
132
|
const [verificationAttempt, setVerificationAttempt] = useState(0);
|
|
130
133
|
const [wiggle, setWiggle] = useState(0);
|
|
@@ -148,7 +151,6 @@ export function FeedbackProvider({
|
|
|
148
151
|
}, [wiggle]);
|
|
149
152
|
const openFeedback = useCallback(next => {
|
|
150
153
|
if (!endpoint) return;
|
|
151
|
-
trigger.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
152
154
|
if (next) setTopic(next);
|
|
153
155
|
setDiagnostics(feedbackDiagnostics(events.current));
|
|
154
156
|
setOpen(true);
|
|
@@ -175,17 +177,6 @@ export function FeedbackProvider({
|
|
|
175
177
|
reportError,
|
|
176
178
|
wiggle
|
|
177
179
|
}), [endpoint, openFeedback, reportError, wiggle]);
|
|
178
|
-
useLayoutEffect(() => {
|
|
179
|
-
if (!dialog.current) return;
|
|
180
|
-
if (open && !capturing) {
|
|
181
|
-
if (!dialog.current.open) dialog.current.showModal();
|
|
182
|
-
if (submitted) successHeading.current?.focus({
|
|
183
|
-
preventScroll: true
|
|
184
|
-
});else messageField.current?.focus({
|
|
185
|
-
preventScroll: true
|
|
186
|
-
});
|
|
187
|
-
} else if (dialog.current.open) dialog.current.close();
|
|
188
|
-
}, [open, capturing, submitted]);
|
|
189
180
|
function resetDraft() {
|
|
190
181
|
setTopic("problem");
|
|
191
182
|
setMessage("");
|
|
@@ -211,10 +202,6 @@ export function FeedbackProvider({
|
|
|
211
202
|
setTurnstileToken("");
|
|
212
203
|
setVerificationAttempt(value => value + 1);
|
|
213
204
|
if (submitted) resetDraft();
|
|
214
|
-
dialog.current?.close();
|
|
215
|
-
trigger.current?.focus({
|
|
216
|
-
preventScroll: true
|
|
217
|
-
});
|
|
218
205
|
}
|
|
219
206
|
async function capture() {
|
|
220
207
|
if (imageOperation.current || submitting) return;
|
|
@@ -222,11 +209,9 @@ export function FeedbackProvider({
|
|
|
222
209
|
imageOperation.current = controller;
|
|
223
210
|
const scroll = body.current?.scrollTop ?? 0;
|
|
224
211
|
setImageBusy(true);
|
|
225
|
-
setCapturing(true);
|
|
212
|
+
flushSync(() => setCapturing(true));
|
|
226
213
|
setScreenshotError("");
|
|
227
214
|
setCaptureStatus("");
|
|
228
|
-
// Close synchronously, before either the picker or capture stream sees this native modal.
|
|
229
|
-
dialog.current?.close();
|
|
230
215
|
if (content.current) content.current.inert = true;
|
|
231
216
|
try {
|
|
232
217
|
const next = await captureFeedbackScreenshot(controller.signal);
|
|
@@ -260,7 +245,6 @@ export function FeedbackProvider({
|
|
|
260
245
|
if (!controller.signal.aborted && live.current) {
|
|
261
246
|
setCapturing(false);
|
|
262
247
|
setImageBusy(false);
|
|
263
|
-
if (dialog.current && !dialog.current.open) dialog.current.showModal();
|
|
264
248
|
if (body.current) body.current.scrollTop = scroll;
|
|
265
249
|
}
|
|
266
250
|
}
|
|
@@ -373,38 +357,20 @@ export function FeedbackProvider({
|
|
|
373
357
|
id: "7qrUoz",
|
|
374
358
|
message: "A problem occurred. You can use Send feedback to report it."
|
|
375
359
|
}) : ""
|
|
376
|
-
}), endpoint &&
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
360
|
+
}), endpoint && _jsx(Dialog, {
|
|
361
|
+
open: open && !capturing && !markup,
|
|
362
|
+
title: _i18n._(
|
|
363
|
+
/** i18n */
|
|
364
|
+
{
|
|
365
|
+
id: "RoafuO",
|
|
366
|
+
message: "Send feedback"
|
|
367
|
+
}),
|
|
368
|
+
onClose: () => {
|
|
369
|
+
if (!markup) close();
|
|
384
370
|
},
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
id: `${id}-title`,
|
|
389
|
-
children: _i18n._(
|
|
390
|
-
/** i18n */
|
|
391
|
-
{
|
|
392
|
-
id: "RoafuO",
|
|
393
|
-
message: "Send feedback"
|
|
394
|
-
})
|
|
395
|
-
}), _jsx("button", {
|
|
396
|
-
type: "button",
|
|
397
|
-
disabled: submitting,
|
|
398
|
-
onClick: close,
|
|
399
|
-
"aria-label": _i18n._(
|
|
400
|
-
/** i18n */
|
|
401
|
-
{
|
|
402
|
-
id: "lnj9gP",
|
|
403
|
-
message: "Close feedback"
|
|
404
|
-
}),
|
|
405
|
-
children: "\u00D7"
|
|
406
|
-
})]
|
|
407
|
-
}), submitted ? _jsxs("section", {
|
|
371
|
+
closeDisabled: submitting,
|
|
372
|
+
className: `mdbase-feedback-dialog${capturing ? " is-capturing" : ""}`,
|
|
373
|
+
children: submitted ? _jsxs("section", {
|
|
408
374
|
className: "mdbase-feedback-success",
|
|
409
375
|
children: [_jsx("h3", {
|
|
410
376
|
ref: successHeading,
|
|
@@ -460,6 +426,7 @@ export function FeedbackProvider({
|
|
|
460
426
|
children: [_jsx("span", {
|
|
461
427
|
children: config.prompt
|
|
462
428
|
}), _jsx("textarea", {
|
|
429
|
+
"data-autofocus": true,
|
|
463
430
|
ref: messageField,
|
|
464
431
|
required: true,
|
|
465
432
|
maxLength: FEEDBACK_MAX_MESSAGE_LENGTH,
|
|
@@ -750,8 +717,9 @@ export function FeedbackProvider({
|
|
|
750
717
|
})
|
|
751
718
|
})]
|
|
752
719
|
})]
|
|
753
|
-
})
|
|
754
|
-
}),
|
|
720
|
+
})
|
|
721
|
+
}), screenshot && _jsx(FeedbackMarkup, {
|
|
722
|
+
open: markup,
|
|
755
723
|
screenshot: screenshot,
|
|
756
724
|
onClose: () => {
|
|
757
725
|
setMarkup(false);
|
package/dist/FeedbackMarkup.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export interface FeedbackMark {
|
|
|
10
10
|
}
|
|
11
11
|
/** Redactions render last and replace whole pixels. Export is a flattened raster, never layers. */
|
|
12
12
|
export declare function paintFeedbackMarks(context: CanvasRenderingContext2D, image: CanvasImageSource, marks: readonly FeedbackMark[]): void;
|
|
13
|
-
export declare function FeedbackMarkup({ screenshot, onApply, onClose }: {
|
|
13
|
+
export declare function FeedbackMarkup({ open, screenshot, onApply, onClose }: {
|
|
14
|
+
open: boolean;
|
|
14
15
|
screenshot: FeedbackScreenshot;
|
|
15
16
|
onApply(screenshot: FeedbackScreenshot, count: number): void;
|
|
16
17
|
onClose(): void;
|
package/dist/FeedbackMarkup.js
CHANGED
|
@@ -36,6 +36,7 @@ export function paintFeedbackMarks(context, image, marks) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export function FeedbackMarkup({
|
|
39
|
+
open,
|
|
39
40
|
screenshot,
|
|
40
41
|
onApply,
|
|
41
42
|
onClose
|
|
@@ -65,6 +66,11 @@ export function FeedbackMarkup({
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
useEffect(() => {
|
|
69
|
+
if (!open) return;
|
|
70
|
+
setReady(false);
|
|
71
|
+
setTool("draw");
|
|
72
|
+
setCount(0);
|
|
73
|
+
setError("");
|
|
68
74
|
let live = true;
|
|
69
75
|
const decoded = new Image();
|
|
70
76
|
decoded.src = screenshotUrl(screenshot);
|
|
@@ -89,7 +95,7 @@ export function FeedbackMarkup({
|
|
|
89
95
|
marks.current = [];
|
|
90
96
|
current.current = null;
|
|
91
97
|
};
|
|
92
|
-
}, [screenshot]);
|
|
98
|
+
}, [open, screenshot]);
|
|
93
99
|
function finish() {
|
|
94
100
|
if (current.current && current.current.points.length > 1 && marks.current.length < 100) marks.current.push(current.current);
|
|
95
101
|
current.current = null;
|
|
@@ -105,7 +111,7 @@ export function FeedbackMarkup({
|
|
|
105
111
|
};
|
|
106
112
|
}
|
|
107
113
|
return _jsxs(Dialog, {
|
|
108
|
-
open:
|
|
114
|
+
open: open,
|
|
109
115
|
onClose: onClose,
|
|
110
116
|
closeDisabled: busy,
|
|
111
117
|
title: _i18n._(
|
package/dist/Menu.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode, RefObject } from "react";
|
|
2
|
+
export declare function Menu({ open, triggerRef, onClose, id, label, className, children }: {
|
|
3
|
+
readonly open: boolean;
|
|
4
|
+
readonly triggerRef: RefObject<HTMLElement | null>;
|
|
5
|
+
readonly onClose: (refocus: boolean) => void;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly label?: string;
|
|
8
|
+
readonly className?: string;
|
|
9
|
+
readonly children: ReactNode;
|
|
10
|
+
}): import("react").JSX.Element | null;
|
package/dist/Menu.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { moveMenuFocus, useMenuPopover } from "./popover.js";
|
|
3
|
+
import { useOverlay } from "./overlay.js";
|
|
4
|
+
export function Menu({
|
|
5
|
+
open,
|
|
6
|
+
triggerRef,
|
|
7
|
+
onClose,
|
|
8
|
+
id,
|
|
9
|
+
label,
|
|
10
|
+
className = "mdbase-menu",
|
|
11
|
+
children
|
|
12
|
+
}) {
|
|
13
|
+
const {
|
|
14
|
+
ref,
|
|
15
|
+
present
|
|
16
|
+
} = useOverlay(open);
|
|
17
|
+
useMenuPopover(ref, triggerRef, onClose, {
|
|
18
|
+
align: "end",
|
|
19
|
+
open
|
|
20
|
+
});
|
|
21
|
+
return present ? _jsx("div", {
|
|
22
|
+
ref: ref,
|
|
23
|
+
id: id,
|
|
24
|
+
className: `${className} mdbase-overlay`,
|
|
25
|
+
"data-open": open,
|
|
26
|
+
popover: "manual",
|
|
27
|
+
role: "menu",
|
|
28
|
+
"aria-label": label,
|
|
29
|
+
tabIndex: -1,
|
|
30
|
+
onKeyDown: event => moveMenuFocus(event, ref.current),
|
|
31
|
+
children: children
|
|
32
|
+
}) : null;
|
|
33
|
+
}
|
package/dist/Select.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
3
|
import { edgeOption, extendTypeahead, flattenOptions, stepOption, typeaheadOption } from "./select-model.js";
|
|
4
|
+
import { useOverlay } from "./overlay.js";
|
|
4
5
|
import { SelectList } from "./SelectList.js";
|
|
5
6
|
import { useSelectPopover } from "./popover.js";
|
|
6
7
|
/**
|
|
@@ -27,10 +28,13 @@ export function Select({
|
|
|
27
28
|
"aria-labelledby": ariaLabelledBy
|
|
28
29
|
} = trigger;
|
|
29
30
|
const triggerRef = useRef(null);
|
|
30
|
-
const listRef = useRef(null);
|
|
31
31
|
const options = flattenOptions(items);
|
|
32
32
|
const selected = options.findIndex(option => option.value === value);
|
|
33
33
|
const state = useSelectState(options, selected, value, onChange, disabled, triggerRef);
|
|
34
|
+
const {
|
|
35
|
+
ref: listRef,
|
|
36
|
+
present
|
|
37
|
+
} = useOverlay(state.open);
|
|
34
38
|
useSelectPopover(state.open, triggerRef, listRef, () => state.close(false));
|
|
35
39
|
useLayoutEffect(() => {
|
|
36
40
|
if (state.open && listRef.current) {
|
|
@@ -76,7 +80,7 @@ export function Select({
|
|
|
76
80
|
d: "m7 10 5 5 5-5"
|
|
77
81
|
})
|
|
78
82
|
})]
|
|
79
|
-
}), _jsx(SelectList, {
|
|
83
|
+
}), present && _jsx(SelectList, {
|
|
80
84
|
id: id,
|
|
81
85
|
listRef: listRef,
|
|
82
86
|
items: items,
|
package/dist/SelectList.js
CHANGED
|
@@ -37,7 +37,8 @@ export function SelectList({
|
|
|
37
37
|
return _jsx("div", {
|
|
38
38
|
ref: listRef,
|
|
39
39
|
id: `${id}-list`,
|
|
40
|
-
className: "mdbase-select-list",
|
|
40
|
+
className: "mdbase-select-list mdbase-overlay",
|
|
41
|
+
"data-open": open,
|
|
41
42
|
popover: "manual",
|
|
42
43
|
role: "listbox",
|
|
43
44
|
tabIndex: -1,
|
package/dist/Toaster.js
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useOverlay } from "./overlay.js";
|
|
3
4
|
import { i18n, useLocaleRevision } from "./i18n.js";
|
|
4
|
-
|
|
5
|
+
let queue = [];
|
|
5
6
|
let nextId = 0;
|
|
6
7
|
const listeners = new Set();
|
|
7
8
|
const notify = () => listeners.forEach(listener => listener());
|
|
8
9
|
export function toast(message, undo) {
|
|
9
|
-
|
|
10
|
+
const active = queue.filter(item => item.open);
|
|
11
|
+
if (active.length >= 4) active[1].open = false;
|
|
10
12
|
queue.push({
|
|
11
13
|
id: ++nextId,
|
|
12
14
|
message,
|
|
13
|
-
undo
|
|
15
|
+
undo,
|
|
16
|
+
open: true
|
|
14
17
|
});
|
|
15
18
|
notify();
|
|
16
19
|
}
|
|
17
20
|
export function Toaster() {
|
|
18
21
|
useLocaleRevision();
|
|
19
|
-
const [
|
|
20
|
-
const [hovered, setHovered] = useState(false);
|
|
21
|
-
const [focused, setFocused] = useState(false);
|
|
22
|
-
const remaining = useRef(0);
|
|
22
|
+
const [items, setItems] = useState(() => [...queue]);
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
}, [current]);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
const update = () => setCurrent(queue[0]);
|
|
24
|
+
const update = () => setItems([...queue]);
|
|
28
25
|
listeners.add(update);
|
|
29
26
|
update();
|
|
30
27
|
return () => {
|
|
@@ -34,55 +31,86 @@ export function Toaster() {
|
|
|
34
31
|
});
|
|
35
32
|
};
|
|
36
33
|
}, []);
|
|
34
|
+
return _jsx("div", {
|
|
35
|
+
className: "mdbase-toaster",
|
|
36
|
+
role: "status",
|
|
37
|
+
"aria-live": "polite",
|
|
38
|
+
"aria-relevant": "additions text",
|
|
39
|
+
children: items.map(item => _jsx(ToastItem, {
|
|
40
|
+
item: item
|
|
41
|
+
}, item.id))
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function ToastItem({
|
|
45
|
+
item
|
|
46
|
+
}) {
|
|
47
|
+
const {
|
|
48
|
+
ref,
|
|
49
|
+
present
|
|
50
|
+
} = useOverlay(item.open);
|
|
51
|
+
const [hovered, setHovered] = useState(false);
|
|
52
|
+
const [focused, setFocused] = useState(false);
|
|
53
|
+
const remaining = useRef(item.undo ? 8_000 : 5_000);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!present) {
|
|
56
|
+
queue = queue.filter(current => current !== item);
|
|
57
|
+
notify();
|
|
58
|
+
}
|
|
59
|
+
}, [present, item]);
|
|
37
60
|
const dismiss = () => {
|
|
38
|
-
|
|
39
|
-
queue.shift();
|
|
61
|
+
item.open = false;
|
|
40
62
|
notify();
|
|
41
63
|
};
|
|
42
64
|
useEffect(() => {
|
|
43
|
-
if (!
|
|
65
|
+
if (!item.open || hovered || focused) return;
|
|
44
66
|
const started = Date.now();
|
|
45
67
|
const timeout = setTimeout(dismiss, remaining.current);
|
|
46
68
|
return () => {
|
|
47
69
|
clearTimeout(timeout);
|
|
48
70
|
remaining.current -= Date.now() - started;
|
|
49
71
|
};
|
|
50
|
-
}, [
|
|
72
|
+
}, [item.open, hovered, focused]);
|
|
73
|
+
if (!present) return null;
|
|
51
74
|
return _jsx("div", {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
ref: ref,
|
|
76
|
+
"data-open": item.open,
|
|
77
|
+
className: "mdbase-toast-slot",
|
|
78
|
+
inert: !item.open,
|
|
56
79
|
onMouseEnter: () => setHovered(true),
|
|
57
80
|
onMouseLeave: () => setHovered(false),
|
|
58
81
|
onFocus: () => setFocused(true),
|
|
59
82
|
onBlur: event => {
|
|
60
83
|
if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
|
|
61
84
|
},
|
|
62
|
-
children:
|
|
63
|
-
className: "mdbase-toast",
|
|
64
|
-
children:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
children: _jsx("div", {
|
|
86
|
+
className: "mdbase-toast-clip",
|
|
87
|
+
children: _jsxs("div", {
|
|
88
|
+
className: "mdbase-toast",
|
|
89
|
+
children: [_jsx("span", {
|
|
90
|
+
children: item.message
|
|
91
|
+
}), item.undo && _jsx("button", {
|
|
92
|
+
className: "mdbase-button is-secondary",
|
|
93
|
+
onClick: () => {
|
|
94
|
+
dismiss();
|
|
95
|
+
item.undo?.();
|
|
96
|
+
},
|
|
97
|
+
children: i18n._(
|
|
98
|
+
/** i18n */
|
|
99
|
+
{
|
|
100
|
+
id: "9uI_rE",
|
|
101
|
+
message: "Undo"
|
|
102
|
+
})
|
|
103
|
+
}), _jsx("button", {
|
|
104
|
+
className: "mdbase-button is-tertiary",
|
|
105
|
+
onClick: dismiss,
|
|
106
|
+
children: i18n._(
|
|
107
|
+
/** i18n */
|
|
108
|
+
{
|
|
109
|
+
id: "1QfxQT",
|
|
110
|
+
message: "Dismiss"
|
|
111
|
+
})
|
|
112
|
+
})]
|
|
113
|
+
})
|
|
114
|
+
})
|
|
87
115
|
});
|
|
88
116
|
}
|
package/dist/brand.js
CHANGED
|
@@ -7,6 +7,7 @@ export const mdbaseMarkEntrances = ["keys-first", "drop", "assemble"];
|
|
|
7
7
|
export const mdbaseMarkMotions = [...mdbaseMarkLoops, ...mdbaseMarkEntrances];
|
|
8
8
|
/** Long enough for each entrance in `motion.css` to finish. */
|
|
9
9
|
const ENTRANCE_MS = 1300;
|
|
10
|
+
let buildOwner;
|
|
10
11
|
export function mdbaseMarkMotionClass(motion) {
|
|
11
12
|
return motion ? ` mdbase-motion-${motion}` : "";
|
|
12
13
|
}
|
|
@@ -148,17 +149,18 @@ export function MdbaseMark({
|
|
|
148
149
|
const uid = useId().replaceAll(":", "");
|
|
149
150
|
// An entrance plays once per mark. Dropping its class afterwards stops it replaying when a signal
|
|
150
151
|
// remounts the lines, and remembering it stops a replay when a loop or progress hands back to it.
|
|
151
|
-
const [entering, setEntering] = useState(isEntrance(motion));
|
|
152
|
+
const [entering, setEntering] = useState(isEntrance(motion) && (motion !== "keys-first" || !buildOwner));
|
|
152
153
|
const played = useRef(undefined);
|
|
153
154
|
useEffect(() => {
|
|
154
|
-
if (!isEntrance(motion) || played.current === motion) return setEntering(false);
|
|
155
|
+
if (!isEntrance(motion) || played.current === motion || motion === "keys-first" && buildOwner !== undefined && buildOwner !== uid) return setEntering(false);
|
|
156
|
+
if (motion === "keys-first") buildOwner = uid;
|
|
155
157
|
setEntering(true);
|
|
156
158
|
const timer = setTimeout(() => {
|
|
157
159
|
played.current = motion;
|
|
158
160
|
setEntering(false);
|
|
159
161
|
}, ENTRANCE_MS);
|
|
160
162
|
return () => clearTimeout(timer);
|
|
161
|
-
}, [motion]);
|
|
163
|
+
}, [motion, uid]);
|
|
162
164
|
const showsProgress = typeof progress === "number" && Number.isFinite(progress);
|
|
163
165
|
const active = signal ? undefined : showsProgress ? undefined : isEntrance(motion) ? entering ? motion : undefined : motion;
|
|
164
166
|
const lines = _jsx(Lines, {
|
|
@@ -27,15 +27,14 @@ export type CollectionSwitcherProps = CollectionUiOptions & {
|
|
|
27
27
|
readonly variant: "none";
|
|
28
28
|
/**
|
|
29
29
|
* The app's element the switcher belongs to, such as the button of the menu
|
|
30
|
-
* that offered it.
|
|
31
|
-
* returns to it on close. It must stay mounted while the switcher is open.
|
|
30
|
+
* that offered it. Focus returns to it on close. It must stay mounted while the switcher is open.
|
|
32
31
|
*/
|
|
33
32
|
readonly anchorRef: RefObject<HTMLElement | null>;
|
|
34
33
|
});
|
|
35
34
|
/**
|
|
36
35
|
* The in-app collection switcher: a trigger that opens the approved collections
|
|
37
36
|
* (one click switches, no Connect window), "Add a collection…", "Manage access"
|
|
38
|
-
* and the account
|
|
37
|
+
* and the account in a modal collection chooser.
|
|
39
38
|
*
|
|
40
39
|
* Pass `open` and `onOpenChange` to control it. With `variant="none"` it has no
|
|
41
40
|
* trigger, so an app can open it from its own control and pass that control's
|