@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/Toaster.js
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
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
|
+
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
|
-
id: ++nextId
|
|
13
|
+
id: `toast-${++nextId}`,
|
|
12
14
|
message,
|
|
13
|
-
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,
|
|
26
|
+
open: true
|
|
14
27
|
});
|
|
15
28
|
notify();
|
|
16
29
|
}
|
|
17
|
-
export function Toaster(
|
|
30
|
+
export function Toaster({
|
|
31
|
+
items,
|
|
32
|
+
onDismiss
|
|
33
|
+
}) {
|
|
18
34
|
useLocaleRevision();
|
|
19
|
-
const [
|
|
20
|
-
const
|
|
21
|
-
const [
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
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
|
+
}
|
|
26
52
|
useEffect(() => {
|
|
27
|
-
const update = () =>
|
|
53
|
+
const update = () => setQueued([...queue]);
|
|
28
54
|
listeners.add(update);
|
|
29
55
|
update();
|
|
30
56
|
return () => {
|
|
@@ -34,55 +60,111 @@ export function Toaster() {
|
|
|
34
60
|
});
|
|
35
61
|
};
|
|
36
62
|
}, []);
|
|
37
|
-
const dismiss = (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
});
|
|
42
72
|
useEffect(() => {
|
|
43
|
-
|
|
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]);
|
|
84
|
+
return _jsx("div", {
|
|
85
|
+
className: "mdbase-toaster",
|
|
86
|
+
role: "status",
|
|
87
|
+
"aria-live": "polite",
|
|
88
|
+
"aria-relevant": "additions text",
|
|
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
|
+
}
|
|
96
|
+
}, item.id))
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function Toast({
|
|
100
|
+
item,
|
|
101
|
+
onDismiss,
|
|
102
|
+
onRemoved
|
|
103
|
+
}) {
|
|
104
|
+
const {
|
|
105
|
+
ref,
|
|
106
|
+
present
|
|
107
|
+
} = useOverlay(item.open);
|
|
108
|
+
const [hovered, setHovered] = useState(false);
|
|
109
|
+
const [focused, setFocused] = useState(false);
|
|
110
|
+
const remaining = useRef(item.durationMs ?? 6_000);
|
|
111
|
+
const dismiss = useEffectEvent(onDismiss);
|
|
112
|
+
const remove = useEffectEvent(onRemoved);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
remaining.current = item.durationMs ?? 6_000;
|
|
115
|
+
}, [item.message, item.durationMs]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!present) remove();
|
|
118
|
+
}, [present]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!item.open || item.sticky || item.action?.busy || hovered || focused) return;
|
|
44
121
|
const started = Date.now();
|
|
45
122
|
const timeout = setTimeout(dismiss, remaining.current);
|
|
46
123
|
return () => {
|
|
47
124
|
clearTimeout(timeout);
|
|
48
125
|
remaining.current -= Date.now() - started;
|
|
49
126
|
};
|
|
50
|
-
}, [
|
|
127
|
+
}, [item.open, item.sticky, item.message, item.durationMs, item.action?.busy, hovered, focused]);
|
|
128
|
+
if (!present) return null;
|
|
51
129
|
return _jsx("div", {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
130
|
+
ref: ref,
|
|
131
|
+
"data-open": item.open,
|
|
132
|
+
className: "mdbase-toast-slot",
|
|
133
|
+
inert: !item.open,
|
|
56
134
|
onMouseEnter: () => setHovered(true),
|
|
57
135
|
onMouseLeave: () => setHovered(false),
|
|
58
136
|
onFocus: () => setFocused(true),
|
|
59
137
|
onBlur: event => {
|
|
60
138
|
if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);
|
|
61
139
|
},
|
|
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
|
-
|
|
140
|
+
children: _jsx("div", {
|
|
141
|
+
className: "mdbase-toast-clip",
|
|
142
|
+
children: _jsxs("div", {
|
|
143
|
+
className: "mdbase-toast",
|
|
144
|
+
"data-tone": item.tone,
|
|
145
|
+
children: [_jsx("span", {
|
|
146
|
+
children: item.message
|
|
147
|
+
}), item.action && _jsx("button", {
|
|
148
|
+
className: "mdbase-button is-secondary",
|
|
149
|
+
disabled: item.action.busy,
|
|
150
|
+
"aria-busy": item.action.busy || undefined,
|
|
151
|
+
onClick: () => {
|
|
152
|
+
if (item.action?.dismiss) dismiss();
|
|
153
|
+
item.action?.onAction();
|
|
154
|
+
},
|
|
155
|
+
children: item.action.label
|
|
156
|
+
}), item.dismissible !== false && _jsx("button", {
|
|
157
|
+
className: "mdbase-button is-tertiary",
|
|
158
|
+
disabled: item.action?.busy,
|
|
159
|
+
onClick: dismiss,
|
|
160
|
+
children: i18n._(
|
|
161
|
+
/** i18n */
|
|
162
|
+
{
|
|
163
|
+
id: "1QfxQT",
|
|
164
|
+
message: "Dismiss"
|
|
165
|
+
})
|
|
166
|
+
})]
|
|
167
|
+
})
|
|
168
|
+
})
|
|
87
169
|
});
|
|
88
170
|
}
|
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
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useId,
|
|
3
|
-
import {
|
|
2
|
+
import { useId, useRef, useState } from "react";
|
|
3
|
+
import { Dialog } from "../Dialog.js";
|
|
4
4
|
import { RowDialogs, SignOutDialog } from "./dialogs.js";
|
|
5
5
|
import { AccountLine, ActionButton, CollectionMark, ItemCopy, ItemMore, NoticeBlock, PrivateMark, RowCopy, RowMore } from "./parts.js";
|
|
6
6
|
import { useCollectionUi } from "./use-collection-ui.js";
|
|
7
7
|
/** Collections worth a filter box; fewer fit at a glance. */
|
|
8
8
|
const FILTER_THRESHOLD = 7;
|
|
9
|
-
const NARROW = "(max-width: 639.98px)";
|
|
10
9
|
/**
|
|
11
10
|
* The in-app collection switcher: a trigger that opens the approved collections
|
|
12
11
|
* (one click switches, no Connect window), "Add a collection…", "Manage access"
|
|
13
|
-
* and the account
|
|
12
|
+
* and the account in a modal collection chooser.
|
|
14
13
|
*
|
|
15
14
|
* Pass `open` and `onOpenChange` to control it. With `variant="none"` it has no
|
|
16
15
|
* trigger, so an app can open it from its own control and pass that control's
|
|
@@ -35,10 +34,8 @@ export function CollectionSwitcher({
|
|
|
35
34
|
};
|
|
36
35
|
const [dialog, setDialog] = useState(null);
|
|
37
36
|
const trigger = useRef(null);
|
|
38
|
-
// The element the panel is placed against and hands focus back to.
|
|
39
37
|
const anchor = anchorRef ?? trigger;
|
|
40
38
|
const panelId = useId();
|
|
41
|
-
const narrow = useNarrow();
|
|
42
39
|
const {
|
|
43
40
|
view,
|
|
44
41
|
copy,
|
|
@@ -61,14 +58,6 @@ export function CollectionSwitcher({
|
|
|
61
58
|
setOpen(false);
|
|
62
59
|
setDialog(next);
|
|
63
60
|
};
|
|
64
|
-
// The popover that held the row is gone: a closed row dialog hands focus to the anchor.
|
|
65
|
-
const returnFocus = useRef(false);
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
if (dialog || !returnFocus.current) return;
|
|
68
|
-
returnFocus.current = false;
|
|
69
|
-
const active = document.activeElement;
|
|
70
|
-
if (!active || active === document.body) anchor.current?.focus();
|
|
71
|
-
}, [dialog, anchor]);
|
|
72
61
|
const content = _jsx(SwitcherContent, {
|
|
73
62
|
ui: ui,
|
|
74
63
|
onDone: () => close(false),
|
|
@@ -110,24 +99,18 @@ export function CollectionSwitcher({
|
|
|
110
99
|
d: "m4 6 4 4 4-4"
|
|
111
100
|
})
|
|
112
101
|
})]
|
|
113
|
-
}),
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
id: panelId,
|
|
120
|
-
ui: ui,
|
|
121
|
-
anchorRef: anchor,
|
|
122
|
-
onClose: close,
|
|
102
|
+
}), _jsx(Dialog, {
|
|
103
|
+
open: open,
|
|
104
|
+
returnFocusRef: anchor,
|
|
105
|
+
title: copy.collectionsLabel,
|
|
106
|
+
onClose: () => close(true),
|
|
107
|
+
className: "mdbase-collections mdbase-collections-switcher-dialog",
|
|
123
108
|
children: content
|
|
124
|
-
})
|
|
109
|
+
}), _jsx(RowDialogs, {
|
|
125
110
|
ui: ui,
|
|
126
111
|
dialog: dialog,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
setDialog(null);
|
|
130
|
-
}
|
|
112
|
+
returnFocusRef: anchor,
|
|
113
|
+
onClose: () => setDialog(null)
|
|
131
114
|
}), _jsx(SignOutDialog, {
|
|
132
115
|
ui: ui
|
|
133
116
|
})]
|
|
@@ -266,6 +249,7 @@ export function SwitcherContent({
|
|
|
266
249
|
type: "button",
|
|
267
250
|
role: "radio",
|
|
268
251
|
"aria-checked": checked,
|
|
252
|
+
"data-autofocus": sdkKey(row) === rovingId || undefined,
|
|
269
253
|
"aria-disabled": !row.available || undefined,
|
|
270
254
|
"aria-describedby": detailId,
|
|
271
255
|
tabIndex: sdkKey(row) === rovingId ? 0 : -1,
|
|
@@ -380,6 +364,7 @@ function SwitcherSection({
|
|
|
380
364
|
type: "button",
|
|
381
365
|
role: "radio",
|
|
382
366
|
"aria-checked": item.current === true,
|
|
367
|
+
"data-autofocus": key(item.id) === roving || undefined,
|
|
383
368
|
"aria-disabled": item.disabled || undefined,
|
|
384
369
|
tabIndex: key(item.id) === roving ? 0 : -1,
|
|
385
370
|
className: "mdbase-collections-row",
|
|
@@ -432,9 +417,6 @@ function moveAmongRadios(event) {
|
|
|
432
417
|
radios[next]?.focus();
|
|
433
418
|
}
|
|
434
419
|
/** Where focus starts in the list: the open collection, else the first group's row. */
|
|
435
|
-
function firstRadio(root) {
|
|
436
|
-
return root.querySelector('[role="radio"][aria-checked="true"]') ?? root.querySelector('[role="radio"][tabindex="0"]');
|
|
437
|
-
}
|
|
438
420
|
function CheckGlyph() {
|
|
439
421
|
return _jsx("svg", {
|
|
440
422
|
className: "mdbase-collections-check",
|
|
@@ -445,139 +427,6 @@ function CheckGlyph() {
|
|
|
445
427
|
})
|
|
446
428
|
});
|
|
447
429
|
}
|
|
448
|
-
/**
|
|
449
|
-
* Wide screens: a non-modal dialog anchored to the trigger (or the app's
|
|
450
|
-
* anchor), in the top layer where supported. Pointer presses and focus on the
|
|
451
|
-
* anchor count as inside, so the trigger can toggle it.
|
|
452
|
-
*/
|
|
453
|
-
function SwitcherPopover({
|
|
454
|
-
id,
|
|
455
|
-
ui,
|
|
456
|
-
anchorRef,
|
|
457
|
-
onClose,
|
|
458
|
-
children
|
|
459
|
-
}) {
|
|
460
|
-
const ref = useRef(null);
|
|
461
|
-
const closeRef = useRef(onClose);
|
|
462
|
-
closeRef.current = onClose;
|
|
463
|
-
useLayoutEffect(() => {
|
|
464
|
-
const panel = ref.current;
|
|
465
|
-
const anchor = anchorRef.current;
|
|
466
|
-
if (!panel || !anchor) return undefined;
|
|
467
|
-
if (typeof panel.showPopover === "function") panel.showPopover();
|
|
468
|
-
const box = anchor.getBoundingClientRect();
|
|
469
|
-
const width = Math.min(340, window.innerWidth - 16);
|
|
470
|
-
panel.style.width = `${width}px`;
|
|
471
|
-
const place = anchoredPlacement(box, {
|
|
472
|
-
width,
|
|
473
|
-
height: panel.scrollHeight
|
|
474
|
-
}, {
|
|
475
|
-
width: window.innerWidth,
|
|
476
|
-
height: window.innerHeight
|
|
477
|
-
}, {
|
|
478
|
-
gap: 6
|
|
479
|
-
});
|
|
480
|
-
panel.style.top = `${place.top}px`;
|
|
481
|
-
panel.style.left = `${place.left}px`;
|
|
482
|
-
panel.style.maxHeight = `${place.maxHeight}px`;
|
|
483
|
-
(firstRadio(panel) ?? panel.querySelector("button") ?? panel).focus({
|
|
484
|
-
preventScroll: true
|
|
485
|
-
});
|
|
486
|
-
return () => {
|
|
487
|
-
if (typeof panel.hidePopover === "function" && panel.matches(":popover-open")) panel.hidePopover();
|
|
488
|
-
};
|
|
489
|
-
}, [anchorRef]);
|
|
490
|
-
useEffect(() => {
|
|
491
|
-
const outside = event => {
|
|
492
|
-
const target = event.target;
|
|
493
|
-
if (target && !ref.current?.contains(target) && !anchorRef.current?.contains(target)) closeRef.current(false);
|
|
494
|
-
};
|
|
495
|
-
const resize = () => closeRef.current(false);
|
|
496
|
-
document.addEventListener("pointerdown", outside, true);
|
|
497
|
-
window.addEventListener("resize", resize);
|
|
498
|
-
return () => {
|
|
499
|
-
document.removeEventListener("pointerdown", outside, true);
|
|
500
|
-
window.removeEventListener("resize", resize);
|
|
501
|
-
};
|
|
502
|
-
}, [anchorRef]);
|
|
503
|
-
return _jsx("div", {
|
|
504
|
-
ref: ref,
|
|
505
|
-
id: id,
|
|
506
|
-
className: "mdbase-collections-popover",
|
|
507
|
-
popover: "manual",
|
|
508
|
-
role: "dialog",
|
|
509
|
-
"aria-label": ui.copy.collectionsLabel,
|
|
510
|
-
tabIndex: -1,
|
|
511
|
-
onKeyDown: event => {
|
|
512
|
-
if (event.key !== "Escape") return;
|
|
513
|
-
event.preventDefault();
|
|
514
|
-
event.stopPropagation();
|
|
515
|
-
onClose(true);
|
|
516
|
-
},
|
|
517
|
-
onBlur: event => {
|
|
518
|
-
const next = event.relatedTarget;
|
|
519
|
-
if (next && !ref.current?.contains(next) && !anchorRef.current?.contains(next)) onClose(false);
|
|
520
|
-
},
|
|
521
|
-
children: children
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
/** Narrow screens: a modal bottom sheet on the native <dialog>. */
|
|
525
|
-
function SwitcherSheet({
|
|
526
|
-
id,
|
|
527
|
-
ui,
|
|
528
|
-
onClose,
|
|
529
|
-
children
|
|
530
|
-
}) {
|
|
531
|
-
const ref = useRef(null);
|
|
532
|
-
useLayoutEffect(() => {
|
|
533
|
-
const sheet = ref.current;
|
|
534
|
-
if (!sheet) return undefined;
|
|
535
|
-
if (!sheet.open) {
|
|
536
|
-
if (typeof sheet.showModal === "function") sheet.showModal();else sheet.setAttribute("open", "");
|
|
537
|
-
}
|
|
538
|
-
firstRadio(sheet)?.focus({
|
|
539
|
-
preventScroll: true
|
|
540
|
-
});
|
|
541
|
-
return () => {
|
|
542
|
-
if (sheet.open && typeof sheet.close === "function") sheet.close();
|
|
543
|
-
};
|
|
544
|
-
}, []);
|
|
545
|
-
return _jsx("dialog", {
|
|
546
|
-
ref: ref,
|
|
547
|
-
id: id,
|
|
548
|
-
className: "mdbase-collections mdbase-collections-sheet",
|
|
549
|
-
"aria-label": ui.copy.collectionsLabel,
|
|
550
|
-
onCancel: event => {
|
|
551
|
-
event.preventDefault();
|
|
552
|
-
onClose(true);
|
|
553
|
-
},
|
|
554
|
-
onClick: event => {
|
|
555
|
-
if (event.target === event.currentTarget) onClose(true);
|
|
556
|
-
},
|
|
557
|
-
children: _jsxs("div", {
|
|
558
|
-
className: "mdbase-collections-sheet-body",
|
|
559
|
-
children: [_jsxs("div", {
|
|
560
|
-
className: "mdbase-collections-sheet-header",
|
|
561
|
-
children: [_jsx("span", {
|
|
562
|
-
className: "mdbase-collections-sheet-title",
|
|
563
|
-
children: ui.copy.collectionsLabel
|
|
564
|
-
}), _jsx("button", {
|
|
565
|
-
type: "button",
|
|
566
|
-
className: "mdbase-collections-more",
|
|
567
|
-
"aria-label": ui.copy.close,
|
|
568
|
-
onClick: () => onClose(true),
|
|
569
|
-
children: _jsx("svg", {
|
|
570
|
-
viewBox: "0 0 16 16",
|
|
571
|
-
"aria-hidden": "true",
|
|
572
|
-
children: _jsx("path", {
|
|
573
|
-
d: "m4 4 8 8M12 4l-8 8"
|
|
574
|
-
})
|
|
575
|
-
})
|
|
576
|
-
})]
|
|
577
|
-
}), children]
|
|
578
|
-
})
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
430
|
function CollectionsGlyph() {
|
|
582
431
|
return _jsx("svg", {
|
|
583
432
|
className: "mdbase-collections-glyph",
|
|
@@ -588,11 +437,3 @@ function CollectionsGlyph() {
|
|
|
588
437
|
})
|
|
589
438
|
});
|
|
590
439
|
}
|
|
591
|
-
function subscribeNarrow(listener) {
|
|
592
|
-
const query = typeof window.matchMedia === "function" ? window.matchMedia(NARROW) : null;
|
|
593
|
-
query?.addEventListener("change", listener);
|
|
594
|
-
return () => query?.removeEventListener("change", listener);
|
|
595
|
-
}
|
|
596
|
-
function useNarrow() {
|
|
597
|
-
return useSyncExternalStore(subscribeNarrow, () => typeof window.matchMedia === "function" && window.matchMedia(NARROW).matches, () => false);
|
|
598
|
-
}
|
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
|
},
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { type JSX } from "react";
|
|
1
|
+
import { type JSX, type RefObject } from "react";
|
|
2
2
|
import type { CollectionRow } from "./model.js";
|
|
3
3
|
import { type RowDialog } from "./parts.js";
|
|
4
4
|
import type { CollectionUi, DeleteCollectionOutcome } from "./use-collection-ui.js";
|
|
5
5
|
type Target = Pick<CollectionRow, "id" | "name">;
|
|
6
6
|
/** Hide a collection on this device. Nothing is deleted and access stays. */
|
|
7
|
-
export declare function ForgetCollectionDialog({ ui, collection, onClose }: {
|
|
7
|
+
export declare function ForgetCollectionDialog({ open, ui, collection, onClose, returnFocusRef }: {
|
|
8
|
+
readonly open?: boolean;
|
|
9
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
8
10
|
readonly ui: CollectionUi;
|
|
9
11
|
readonly collection: Target;
|
|
10
12
|
readonly onClose: () => void;
|
|
11
13
|
}): JSX.Element;
|
|
12
14
|
/** Owner only: type the name to delete a collection for everyone. The SDK and server check both again. */
|
|
13
|
-
export declare function DeleteCollectionDialog({ ui, collection, onClose }: {
|
|
15
|
+
export declare function DeleteCollectionDialog({ open, ui, collection, onClose, returnFocusRef }: {
|
|
16
|
+
readonly open?: boolean;
|
|
17
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null> | undefined;
|
|
14
18
|
readonly ui: CollectionUi;
|
|
15
19
|
readonly collection: Target;
|
|
16
20
|
readonly onClose: (outcome: DeleteCollectionOutcome) => void;
|
|
@@ -19,9 +23,10 @@ export declare function DeleteCollectionDialog({ ui, collection, onClose }: {
|
|
|
19
23
|
export declare function SignOutDialog({ ui }: {
|
|
20
24
|
readonly ui: CollectionUi;
|
|
21
25
|
}): JSX.Element | null;
|
|
22
|
-
export declare function RowDialogs({ ui, dialog, onClose }: {
|
|
26
|
+
export declare function RowDialogs({ ui, dialog, onClose, returnFocusRef }: {
|
|
23
27
|
readonly ui: CollectionUi;
|
|
24
28
|
readonly dialog: RowDialog;
|
|
25
29
|
readonly onClose: () => void;
|
|
30
|
+
readonly returnFocusRef?: RefObject<HTMLElement | null>;
|
|
26
31
|
}): JSX.Element | null;
|
|
27
32
|
export {};
|