@alulore/kumiko 0.17.0 → 0.17.2
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/dist/media-viewer/video-controls.js +11 -1
- package/dist/shortcuts/bindings.d.ts +6 -0
- package/dist/shortcuts/capture.js +9 -4
- package/dist/shortcuts/help.d.ts +17 -3
- package/dist/shortcuts/help.js +16 -6
- package/dist/shortcuts/index.d.ts +2 -1
- package/dist/shortcuts/index.js +2 -1
- package/dist/shortcuts/list.js +9 -3
- package/dist/shortcuts/over-dialogs.d.ts +18 -0
- package/dist/shortcuts/over-dialogs.js +38 -0
- package/dist/shortcuts/provider.js +1 -1
- package/dist/shortcuts/registration.js +5 -0
- package/dist/shortcuts/shortcuts.css +59 -16
- package/dist/smooth-caret/caret-controller.js +21 -1
- package/dist/smooth-caret/caret-host.js +3 -0
- package/dist/smooth-caret/remote-carets.js +20 -1
- package/dist/smooth-caret/smooth-caret.css +19 -0
- package/dist/smooth-caret/top-layer.d.ts +13 -0
- package/dist/smooth-caret/top-layer.js +56 -0
- package/dist/undo/undo-provider.d.ts +5 -1
- package/dist/undo/undo-provider.js +1 -1
- package/package.json +1 -1
|
@@ -36,12 +36,22 @@ function clock(seconds) {
|
|
|
36
36
|
const whole = Math.max(0, Math.floor(seconds));
|
|
37
37
|
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
|
|
38
38
|
}
|
|
39
|
+
/*
|
|
40
|
+
* A play() that can't finish (the video left the page, or the browser needs a tap first) leaves
|
|
41
|
+
* the clip paused, which is what the controls already show. Nothing else needs to hear of it.
|
|
42
|
+
*/
|
|
43
|
+
function keepPaused(error) {
|
|
44
|
+
if (!(error instanceof DOMException) ||
|
|
45
|
+
!["AbortError", "NotAllowedError"].includes(error.name)) {
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
function togglePlay(video) {
|
|
40
50
|
if (!video) {
|
|
41
51
|
return;
|
|
42
52
|
}
|
|
43
53
|
if (video.paused) {
|
|
44
|
-
|
|
54
|
+
video.play().catch(keepPaused);
|
|
45
55
|
}
|
|
46
56
|
else {
|
|
47
57
|
video.pause();
|
|
@@ -14,6 +14,12 @@ export interface ShortcutAction {
|
|
|
14
14
|
when?: () => boolean;
|
|
15
15
|
/** Whether it also runs while focus is in a text field. Keys with Ctrl, Cmd or Alt always do. */
|
|
16
16
|
allowInInput?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether it keeps running while a modal (a dialog or a sheet) is open. For app-wide chords such as a
|
|
19
|
+
* finder or settings. Typing in a field, `when` and the pause during a drag or menu still apply.
|
|
20
|
+
* @defaultValue false
|
|
21
|
+
*/
|
|
22
|
+
overDialogs?: boolean;
|
|
17
23
|
}
|
|
18
24
|
/** The keys people changed, by action id. An action that is not in here uses its defaults. */
|
|
19
25
|
export type Overrides = Readonly<Record<string, readonly string[]>>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Button } from "../button";
|
|
4
|
+
import { Input } from "../input";
|
|
3
5
|
import { canonicalKeys, describeKeys, isValidKeys, keysFromEvent } from "./keys";
|
|
4
6
|
import { useShortcuts } from "./provider";
|
|
5
7
|
/** Keys offered when capturing by picking from a list. */
|
|
@@ -40,7 +42,7 @@ function PressCapture({ rebinder }) {
|
|
|
40
42
|
window.addEventListener("keydown", onKey, true);
|
|
41
43
|
return () => window.removeEventListener("keydown", onKey, true);
|
|
42
44
|
}, [submit, cancel, escapeCancels]);
|
|
43
|
-
return (_jsxs("p", { className: "kumiko-shortcuts-capture", "data-mode": "press", children: [escapeCancels ? "Press the new keys. Esc cancels." : "Press the new keys.", _jsx("
|
|
45
|
+
return (_jsxs("p", { className: "kumiko-shortcuts-capture", "data-mode": "press", children: [escapeCancels ? "Press the new keys. Esc cancels." : "Press the new keys.", _jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: cancel, children: "Cancel" })] }));
|
|
44
46
|
}
|
|
45
47
|
function TypeCapture({ rebinder }) {
|
|
46
48
|
const [text, setText] = useState("");
|
|
@@ -51,17 +53,20 @@ function TypeCapture({ rebinder }) {
|
|
|
51
53
|
if (isValidKeys(text)) {
|
|
52
54
|
rebinder.submit(text);
|
|
53
55
|
}
|
|
54
|
-
}, children: [_jsx(
|
|
56
|
+
}, children: [_jsx(Input, { "aria-label": "New keys, like mod+shift+k", placeholder: "mod+shift+k", ref: input, value: text, onChange: (event) => setText(event.target.value) }), _jsx(Button, { variant: "solid", size: "sm", type: "submit", disabled: !isValidKeys(text), children: "Use" }), _jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: rebinder.cancel, children: "Cancel" })] }));
|
|
55
57
|
}
|
|
56
58
|
function ListCapture({ rebinder }) {
|
|
57
59
|
const [choice, setChoice] = useState("");
|
|
58
|
-
return (_jsxs("div", { className: "kumiko-shortcuts-capture", "data-mode": "list", children: [_jsxs("select", { "aria-label": "New keys", value: choice, onChange: (event) => setChoice(event.target.value), children: [_jsx("option", { value: "", children: "Pick keys\u2026" }), suggestions.map((keys) => (_jsx("option", { value: keys, children: describeKeys(keys) }, keys)))] }), _jsx("
|
|
60
|
+
return (_jsxs("div", { className: "kumiko-shortcuts-capture", "data-mode": "list", children: [_jsxs("select", { "aria-label": "New keys", value: choice, onChange: (event) => setChoice(event.target.value), children: [_jsx("option", { value: "", children: "Pick keys\u2026" }), suggestions.map((keys) => (_jsx("option", { value: keys, children: describeKeys(keys) }, keys)))] }), _jsx(Button, { variant: "solid", size: "sm", type: "button", disabled: choice === "", onClick: () => rebinder.submit(choice), children: "Use" }), _jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: rebinder.cancel, children: "Cancel" })] }));
|
|
61
|
+
}
|
|
62
|
+
function Answers({ rebinder, kind }) {
|
|
63
|
+
return (_jsx(_Fragment, { children: kind === "taken" ? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "solid", size: "sm", type: "button", onClick: () => rebinder.resolve("swap"), children: "Swap" }), _jsx(Button, { variant: "outline", size: "sm", type: "button", onClick: () => rebinder.resolve("replace"), children: "Replace" })] })) : (_jsx(Button, { variant: "outline", size: "sm", type: "button", onClick: rebinder.useAnyway, children: "Use anyway" })) }));
|
|
59
64
|
}
|
|
60
65
|
function Question({ rebinder, pending }) {
|
|
61
66
|
const { actions } = useShortcuts();
|
|
62
67
|
const mine = actions.find((action) => action.id === rebinder.target?.id)?.description ?? "";
|
|
63
68
|
const keys = describeKeys(pending.keys);
|
|
64
|
-
return (_jsxs("div", { className: "kumiko-shortcuts-capture", "data-mode": pending.kind, role: "alert", children: [pending.kind === "taken" ? (_jsxs("p", { children: [keys, " already runs \u201C", pending.owner.description, "\u201D. Swap gives it the keys \u201C", mine, "\u201D had. Replace takes ", keys, " away from it."] })) : (_jsxs("p", { children: [keys, " is reserved. ", pending.reason] })),
|
|
69
|
+
return (_jsxs("div", { className: "kumiko-shortcuts-capture", "data-mode": pending.kind, role: "alert", children: [pending.kind === "taken" ? (_jsxs("p", { children: [keys, " already runs \u201C", pending.owner.description, "\u201D. Swap gives it the keys \u201C", mine, "\u201D had. Replace takes ", keys, " away from it."] })) : (_jsxs("p", { children: [keys, " is reserved. ", pending.reason] })), _jsx(Answers, { rebinder: rebinder, kind: pending.kind }), _jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: rebinder.cancel, children: "Cancel" })] }));
|
|
65
70
|
}
|
|
66
71
|
/** What shows under an action while its key is being changed: the capture, and the answer to a conflict. */
|
|
67
72
|
export function Capture({ rebinder, bare = false }) {
|
package/dist/shortcuts/help.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { DialogTrigger } from "../dialog";
|
|
1
2
|
export type HelpPresentation = "popover" | "dialog" | "panel";
|
|
2
|
-
|
|
3
|
+
/** The button attributes and `render` the sheet's trigger takes, as the other triggers do. */
|
|
4
|
+
type TriggerProps = Omit<React.ComponentProps<typeof DialogTrigger>, "children" | "className" | "controller">;
|
|
5
|
+
export type ShortcutsHelpProps = TriggerProps & {
|
|
3
6
|
/**
|
|
4
7
|
* Where the sheet appears: a dialog with search, a popover from its button, or a panel at the side.
|
|
5
8
|
* @defaultValue "dialog"
|
|
@@ -16,10 +19,21 @@ export interface ShortcutsHelpProps {
|
|
|
16
19
|
* @defaultValue "Shortcuts"
|
|
17
20
|
*/
|
|
18
21
|
label?: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* The heading of the sheet.
|
|
24
|
+
* @defaultValue "Shortcuts"
|
|
25
|
+
*/
|
|
26
|
+
title?: React.ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* A line under the heading. Without it the sheet shows none.
|
|
29
|
+
* @defaultValue undefined
|
|
30
|
+
*/
|
|
31
|
+
description?: React.ReactNode;
|
|
19
32
|
/** A class for the button. */
|
|
20
33
|
className?: string;
|
|
21
|
-
}
|
|
34
|
+
};
|
|
22
35
|
/** A button that opens the help sheet: what can run now, by section. Its keys (`helpKeys`) open it too. */
|
|
23
|
-
export declare function ShortcutsHelp({ presentation, editable, label, className }: ShortcutsHelpProps): React.JSX.Element;
|
|
36
|
+
export declare function ShortcutsHelp({ presentation, editable, label, title, description, className, ...trigger }: ShortcutsHelpProps): React.JSX.Element;
|
|
24
37
|
/** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
|
|
25
38
|
export declare function ShortcutsSettings(): React.JSX.Element;
|
|
39
|
+
export {};
|
package/dist/shortcuts/help.js
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
+
import { Button } from "../button";
|
|
3
4
|
import { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogDescription, DialogTitle, DialogTrigger } from "../dialog";
|
|
5
|
+
import { SearchInput } from "../input";
|
|
6
|
+
import { Kbd } from "../kbd";
|
|
4
7
|
import { Popover, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger } from "../popover";
|
|
5
8
|
import { ShortcutsList } from "./list";
|
|
6
9
|
import { useShortcuts } from "./provider";
|
|
7
|
-
|
|
10
|
+
/** How the keys that open the sheet read, as the person sees them elsewhere: Shift+? and Ctrl+/. */
|
|
11
|
+
function OpensWith({ keys }) {
|
|
12
|
+
if (keys.length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return (_jsxs("p", { className: "kumiko-shortcuts-foot", children: ["Opens with", " ", keys.map((key, index) => (_jsxs("span", { children: [index > 0 ? " or " : null, _jsx(Kbd, { keys: key, listen: false })] }, key)))] }));
|
|
16
|
+
}
|
|
17
|
+
function Body({ presentation, editable, closer }) {
|
|
8
18
|
const [editing, setEditing] = useState(false);
|
|
9
19
|
const [query, setQuery] = useState("");
|
|
10
20
|
const { options } = useShortcuts();
|
|
11
|
-
|
|
12
|
-
return (_jsxs("div", { className: "kumiko-shortcuts-sheet", "data-presentation": presentation, children: [presentation === "dialog" ? (_jsx("input", { type: "search", "aria-label": "Search shortcuts", placeholder: "Search shortcuts", value: query, onChange: (event) => setQuery(event.target.value) })) : null, _jsx(ShortcutsList, { editing: editing, all: editing, query: query }), help.length > 0 ? (_jsxs("p", { className: "kumiko-shortcuts-foot", children: ["This sheet opens with ", help.join(" or "), "."] })) : null, editable ? (_jsx("button", { type: "button", onClick: () => setEditing((now) => !now), children: editing ? "Done" : "Edit keys" })) : null] }));
|
|
21
|
+
return (_jsxs("div", { className: "kumiko-shortcuts-sheet", "data-presentation": presentation, children: [presentation === "dialog" ? (_jsx(SearchInput, { "aria-label": "Search shortcuts", placeholder: "Search shortcuts", value: query, onValueChange: (value) => setQuery(value) })) : null, _jsx("div", { className: "kumiko-shortcuts-scroll", children: _jsx(ShortcutsList, { editing: editing, all: editing, query: query }) }), _jsxs("div", { className: "kumiko-shortcuts-foot-row", children: [_jsx(OpensWith, { keys: options.helpKeys }), _jsxs("div", { className: "kumiko-shortcuts-actions", children: [editable ? (_jsx(Button, { variant: editing ? "solid" : "outline", size: "sm", onClick: () => setEditing((now) => !now), children: editing ? "Done" : "Edit keys" })) : null, closer] })] })] }));
|
|
13
22
|
}
|
|
14
23
|
/** A button that opens the help sheet: what can run now, by section. Its keys (`helpKeys`) open it too. */
|
|
15
|
-
export function ShortcutsHelp({ presentation = "dialog", editable = false, label = "Shortcuts", className }) {
|
|
24
|
+
export function ShortcutsHelp({ presentation = "dialog", editable = false, label = "Shortcuts", title = "Shortcuts", description, className, ...trigger }) {
|
|
16
25
|
const { helpOpen, openHelp, closeHelp } = useShortcuts();
|
|
17
26
|
const onOpenChange = (open) => (open ? openHelp() : closeHelp());
|
|
27
|
+
const render = trigger.render ?? _jsx(Button, { variant: "outline", size: "sm" });
|
|
18
28
|
if (presentation === "popover") {
|
|
19
|
-
return (_jsxs(Popover, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(PopoverTrigger, { className: className, children: label }), _jsxs(PopoverContent, { align: "end", sideOffset: 8, className: "kumiko-shortcuts-popover", children: [_jsx(PopoverTitle, { children:
|
|
29
|
+
return (_jsxs(Popover, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(PopoverTrigger, { ...trigger, render: render, className: className, children: label }), _jsxs(PopoverContent, { align: "end", sideOffset: 8, className: "kumiko-shortcuts-popover", children: [_jsx(PopoverTitle, { children: title }), description ? _jsx(PopoverDescription, { children: description }) : null, _jsx(Body, { presentation: presentation, editable: editable })] })] }));
|
|
20
30
|
}
|
|
21
|
-
return (_jsxs(Dialog, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(DialogTrigger, { className: className, children: label }), _jsx(DialogBackdrop, {}), _jsxs(DialogContent, { className: "kumiko-shortcuts-dialog", "data-kumiko-shortcuts": presentation, children: [_jsx(DialogTitle, { children:
|
|
31
|
+
return (_jsxs(Dialog, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(DialogTrigger, { ...trigger, render: render, className: className, children: label }), _jsx(DialogBackdrop, {}), _jsxs(DialogContent, { className: "kumiko-shortcuts-dialog", "data-kumiko-shortcuts": presentation, children: [_jsx(DialogTitle, { children: title }), description ? _jsx(DialogDescription, { children: description }) : null, _jsx(Body, { presentation: presentation, editable: editable, closer: _jsx(DialogClose, { render: _jsx(Button, { variant: "outline", size: "sm" }), children: "Close" }) })] })] }));
|
|
22
32
|
}
|
|
23
33
|
/** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
|
|
24
34
|
export function ShortcutsSettings() {
|
|
@@ -6,6 +6,7 @@ export { defaultReservedKeys } from "./keys";
|
|
|
6
6
|
export { type ShortcutNote } from "./notes";
|
|
7
7
|
export { ShortcutsList, type ShortcutsListProps } from "./list";
|
|
8
8
|
export { ShortcutsProvider, useShortcuts, type CaptureMode, type HintMode, type ReservedMode, type ShortcutsContextValue, type ShortcutsOptions, type ShortcutsProviderProps, type TakenKeys } from "./provider";
|
|
9
|
-
export {
|
|
9
|
+
export { ariaKeyshortcuts, formatShortcut, shortcuts, useShortcutHint, type ShortcutInfo } from "@ui-sdk/react/shortcuts";
|
|
10
|
+
export { useShortcut, type OverDialogsOptions } from "./over-dialogs";
|
|
10
11
|
export { Capture as ShortcutPrompt } from "./capture";
|
|
11
12
|
export { useRebinder, type Rebinder, type Target } from "./rebinder";
|
package/dist/shortcuts/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export { defaultReservedKeys } from "./keys";
|
|
|
6
6
|
export {} from "./notes";
|
|
7
7
|
export { ShortcutsList } from "./list";
|
|
8
8
|
export { ShortcutsProvider, useShortcuts } from "./provider";
|
|
9
|
-
export {
|
|
9
|
+
export { ariaKeyshortcuts, formatShortcut, shortcuts, useShortcutHint } from "@ui-sdk/react/shortcuts";
|
|
10
|
+
export { useShortcut } from "./over-dialogs";
|
|
10
11
|
export { Capture as ShortcutPrompt } from "./capture";
|
|
11
12
|
export { useRebinder } from "./rebinder";
|
package/dist/shortcuts/list.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatShortcut } from "@ui-sdk/react/shortcuts";
|
|
3
|
+
import { Button } from "../button";
|
|
2
4
|
import { Kbd } from "../kbd";
|
|
3
5
|
import { defaultKeys, maxKeysPerAction } from "./bindings";
|
|
4
6
|
import { Capture } from "./capture";
|
|
5
7
|
import { noteKeys, sectionRows } from "./notes";
|
|
6
8
|
import { useShortcuts } from "./provider";
|
|
7
9
|
import { useRebinder } from "./rebinder";
|
|
10
|
+
/** The key as a person sees it (Ctrl+K), without the marks that keep it left to right, for a screen reader. */
|
|
11
|
+
function spoken(key) {
|
|
12
|
+
return formatShortcut(key).replaceAll(/[]/gu, "");
|
|
13
|
+
}
|
|
8
14
|
function sameKeys(action, keys) {
|
|
9
15
|
const defaults = defaultKeys(action);
|
|
10
16
|
return keys.length === defaults.length && keys.every((key, index) => key === defaults[index]);
|
|
@@ -14,13 +20,13 @@ function KeyChip({ action, slot, removable, rebinder }) {
|
|
|
14
20
|
const key = keysFor(action.id)[slot] ?? "";
|
|
15
21
|
const { target } = rebinder;
|
|
16
22
|
const changing = target?.id === action.id && target.slot === slot;
|
|
17
|
-
return (_jsxs("span", { className: "kumiko-shortcuts-key", "data-changing": changing ? "" : undefined, children: [_jsx(Kbd, { keys: key, listen: false }), _jsx(
|
|
23
|
+
return (_jsxs("span", { className: "kumiko-shortcuts-key", "data-changing": changing ? "" : undefined, children: [_jsx(Kbd, { keys: key, listen: false }), _jsx(Button, { variant: "outline", size: "sm", "aria-label": `Change ${spoken(key)} for ${action.description}`, onClick: () => rebinder.begin({ id: action.id, slot }), children: "Change" }), removable ? (_jsx(Button, { variant: "destructive-ghost", size: "sm", type: "button", "aria-label": `Remove ${spoken(key)} from ${action.description}`, onClick: () => rebinder.remove(action.id, slot), children: "Remove" })) : null] }));
|
|
18
24
|
}
|
|
19
25
|
function KeyEditor({ action, rebinder }) {
|
|
20
26
|
const { keysFor, options } = useShortcuts();
|
|
21
27
|
const keys = keysFor(action.id);
|
|
22
28
|
const canAdd = options.multipleKeys ? keys.length < maxKeysPerAction : keys.length === 0;
|
|
23
|
-
return (_jsxs("div", { className: "kumiko-shortcuts-editor", children: [keys.map((key, slot) => (_jsx(KeyChip, { action: action, slot: slot, removable: keys.length > 1, rebinder: rebinder }, key))), keys.length === 0 ? _jsx("span", { className: "kumiko-shortcuts-none", children: "No keys" }) : null, canAdd ? (_jsx("
|
|
29
|
+
return (_jsxs("div", { className: "kumiko-shortcuts-editor", children: [keys.map((key, slot) => (_jsx(KeyChip, { action: action, slot: slot, removable: keys.length > 1, rebinder: rebinder }, key))), keys.length === 0 ? _jsx("span", { className: "kumiko-shortcuts-none", children: "No keys" }) : null, canAdd ? (_jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: () => rebinder.begin({ id: action.id, slot: -1 }), children: keys.length === 0 ? "Set keys" : "Add another" })) : null, options.resetEach && !sameKeys(action, keys) ? (_jsx(Button, { variant: "ghost", size: "sm", type: "button", onClick: () => rebinder.reset(action.id), children: "Reset" })) : null] }));
|
|
24
30
|
}
|
|
25
31
|
function Row({ action, editing, rebinder }) {
|
|
26
32
|
const { keysFor, available } = useShortcuts();
|
|
@@ -31,7 +37,7 @@ function NoteRow({ note }) {
|
|
|
31
37
|
}
|
|
32
38
|
function EditFooter() {
|
|
33
39
|
const { resetAll, overrides, options, saveFailed } = useShortcuts();
|
|
34
|
-
return (_jsxs(_Fragment, { children: [saveFailed ? (_jsx("p", { className: "kumiko-shortcuts-message", role: "alert", children: "Your changes could not be saved. They last until the page closes." })) : null, Object.keys(overrides).length > 0 ? (_jsx("p", { children: _jsx("
|
|
40
|
+
return (_jsxs(_Fragment, { children: [saveFailed ? (_jsx("p", { className: "kumiko-shortcuts-message", role: "alert", children: "Your changes could not be saved. They last until the page closes." })) : null, Object.keys(overrides).length > 0 ? (_jsx("p", { children: _jsx(Button, { variant: "outline", size: "sm", type: "button", onClick: resetAll, children: "Reset all" }) })) : null, options.multipleKeys ? null : (_jsx("p", { className: "kumiko-shortcuts-empty", children: "Each action has one key." }))] }));
|
|
35
41
|
}
|
|
36
42
|
/** The actions grouped by section, each with its keys. With `editing`, every key can be changed. */
|
|
37
43
|
export function ShortcutsList({ editing = false, all = editing, query = "" }) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ShortcutHandler, type UseShortcutOptions } from "@ui-sdk/react/shortcuts";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the one hidden element that makes a shortcut survive modals. It is created for the first holder,
|
|
4
|
+
* bound as a persistent layer, and removed when the last holder lets go.
|
|
5
|
+
*/
|
|
6
|
+
export declare function holdOverDialogs(): () => void;
|
|
7
|
+
/** The `layer` that keeps a shortcut running over modals. Nothing while no shortcut asked for it. */
|
|
8
|
+
export declare function overDialogsLayer(): Element | undefined;
|
|
9
|
+
export type OverDialogsOptions = UseShortcutOptions & {
|
|
10
|
+
/**
|
|
11
|
+
* Whether the shortcut keeps running while a modal (a dialog or a sheet) is open. Typing in a field and
|
|
12
|
+
* `when` still apply.
|
|
13
|
+
* @defaultValue false
|
|
14
|
+
*/
|
|
15
|
+
overDialogs?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** The ui-sdk `useShortcut`, with `overDialogs` for app-wide chords that must work over a modal. */
|
|
18
|
+
export declare function useShortcut(keys: string | null | undefined, handler: ShortcutHandler, { overDialogs, ...options }?: OverDialogsOptions): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { bindPersistentLayer } from "@ui-sdk/core";
|
|
2
|
+
import { useShortcut as useUiShortcut } from "@ui-sdk/react/shortcuts";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
let layer;
|
|
5
|
+
let unbind;
|
|
6
|
+
let holders = 0;
|
|
7
|
+
/**
|
|
8
|
+
* Keeps the one hidden element that makes a shortcut survive modals. It is created for the first holder,
|
|
9
|
+
* bound as a persistent layer, and removed when the last holder lets go.
|
|
10
|
+
*/
|
|
11
|
+
export function holdOverDialogs() {
|
|
12
|
+
holders += 1;
|
|
13
|
+
if (!layer) {
|
|
14
|
+
layer = document.createElement("div");
|
|
15
|
+
layer.hidden = true;
|
|
16
|
+
layer.dataset.kumikoShortcutsOverDialogs = "";
|
|
17
|
+
document.body.append(layer);
|
|
18
|
+
unbind = bindPersistentLayer(layer);
|
|
19
|
+
}
|
|
20
|
+
return () => {
|
|
21
|
+
holders -= 1;
|
|
22
|
+
if (holders === 0) {
|
|
23
|
+
unbind?.();
|
|
24
|
+
layer?.remove();
|
|
25
|
+
layer = undefined;
|
|
26
|
+
unbind = undefined;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** The `layer` that keeps a shortcut running over modals. Nothing while no shortcut asked for it. */
|
|
31
|
+
export function overDialogsLayer() {
|
|
32
|
+
return layer;
|
|
33
|
+
}
|
|
34
|
+
/** The ui-sdk `useShortcut`, with `overDialogs` for app-wide chords that must work over a modal. */
|
|
35
|
+
export function useShortcut(keys, handler, { overDialogs = false, ...options } = {}) {
|
|
36
|
+
useEffect(() => (overDialogs ? holdOverDialogs() : undefined), [overDialogs]);
|
|
37
|
+
useUiShortcut(keys, handler, overDialogs ? { ...options, layer: overDialogsLayer } : options);
|
|
38
|
+
}
|
|
@@ -90,7 +90,7 @@ export function ShortcutsProvider(props) {
|
|
|
90
90
|
};
|
|
91
91
|
});
|
|
92
92
|
const signature = [
|
|
93
|
-
...actions.map((action) => `${action.id}:${action.description}:${action.allowInInput}`),
|
|
93
|
+
...actions.map((action) => `${action.id}:${action.description}:${action.allowInInput}:${action.overDialogs}`),
|
|
94
94
|
...options.helpKeys
|
|
95
95
|
].join("|");
|
|
96
96
|
useRegistration(live, signature);
|
|
@@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
|
|
|
3
3
|
import { keysOf, maxKeysPerAction } from "./bindings";
|
|
4
4
|
import { isDragging, isMenuOpen } from "./guard";
|
|
5
5
|
import { canonicalKeys, onApple } from "./keys";
|
|
6
|
+
import { holdOverDialogs, overDialogsLayer } from "./over-dialogs";
|
|
6
7
|
/** Whether page shortcuts may run: not while a drag or a menu is open, unless the app turned that off. */
|
|
7
8
|
function calm(live) {
|
|
8
9
|
return !live.current.pauseWhileBusy || (!isDragging() && !isMenuOpen());
|
|
@@ -17,6 +18,7 @@ function registerSlot(live, action, slot) {
|
|
|
17
18
|
}, (event) => find()?.run(event), {
|
|
18
19
|
description: action.description,
|
|
19
20
|
allowInInput: action.allowInInput ?? false,
|
|
21
|
+
layer: action.overDialogs ? overDialogsLayer : undefined,
|
|
20
22
|
when: () => calm(live) && (find()?.when?.() ?? true)
|
|
21
23
|
});
|
|
22
24
|
}
|
|
@@ -27,6 +29,9 @@ function registerSlot(live, action, slot) {
|
|
|
27
29
|
export function useRegistration(live, signature) {
|
|
28
30
|
useEffect(() => {
|
|
29
31
|
const offs = [];
|
|
32
|
+
if (live.current.actions.some((action) => action.overDialogs)) {
|
|
33
|
+
offs.push(holdOverDialogs());
|
|
34
|
+
}
|
|
30
35
|
for (const action of live.current.actions) {
|
|
31
36
|
for (let slot = 0; slot < maxKeysPerAction; slot += 1) {
|
|
32
37
|
offs.push(registerSlot(live, action, slot));
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
@import "../motion/motion.css";
|
|
2
|
+
@import "../button/button.css";
|
|
3
|
+
@import "../dialog/dialog.css";
|
|
4
|
+
@import "../input/input.css";
|
|
5
|
+
@import "../kbd/kbd.css";
|
|
6
|
+
@import "../popover/popover.css";
|
|
2
7
|
|
|
3
8
|
@layer kumiko {
|
|
4
9
|
:where(:root) {
|
|
@@ -8,6 +13,7 @@
|
|
|
8
13
|
--kumiko-shortcuts-accent: Highlight;
|
|
9
14
|
--kumiko-shortcuts-danger: #b42318;
|
|
10
15
|
--kumiko-shortcuts-panel-width: 24rem;
|
|
16
|
+
--kumiko-shortcuts-sheet-height: 30rem;
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
.kumiko-shortcuts-sheet {
|
|
@@ -17,8 +23,53 @@
|
|
|
17
23
|
font-size: 0.875rem;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
/*
|
|
27
|
+
* The sheet keeps the height it opened with, so searching never makes it jump: the search and the footer stay
|
|
28
|
+
* put and only the list scrolls between them.
|
|
29
|
+
*/
|
|
30
|
+
.kumiko-shortcuts-dialog,
|
|
31
|
+
.kumiko-shortcuts-popover {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.kumiko-shortcuts-dialog {
|
|
38
|
+
block-size: min(var(--kumiko-shortcuts-sheet-height), var(--_dialog-room-block));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.kumiko-shortcuts-dialog > .kumiko-shortcuts-sheet,
|
|
42
|
+
.kumiko-shortcuts-popover > .kumiko-shortcuts-sheet {
|
|
43
|
+
flex: 1;
|
|
44
|
+
min-block-size: 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.kumiko-shortcuts-popover {
|
|
48
|
+
gap: 0.75rem;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.kumiko-shortcuts-actions {
|
|
52
|
+
display: flex;
|
|
53
|
+
gap: 0.5rem;
|
|
54
|
+
align-items: center;
|
|
55
|
+
margin-inline-start: auto;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.kumiko-shortcuts-scroll {
|
|
59
|
+
flex: 1;
|
|
60
|
+
min-block-size: 0;
|
|
61
|
+
overflow-y: auto;
|
|
62
|
+
overscroll-behavior: contain;
|
|
63
|
+
scrollbar-gutter: stable;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.kumiko-shortcuts-foot-row {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex: none;
|
|
69
|
+
flex-wrap: wrap;
|
|
70
|
+
gap: var(--kumiko-shortcuts-gap);
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: space-between;
|
|
22
73
|
}
|
|
23
74
|
|
|
24
75
|
.kumiko-shortcuts-list section + section {
|
|
@@ -74,20 +125,7 @@
|
|
|
74
125
|
outline: 2px solid var(--kumiko-shortcuts-accent);
|
|
75
126
|
}
|
|
76
127
|
|
|
77
|
-
.kumiko-shortcuts-sheet button {
|
|
78
|
-
padding: 0.2rem 0.55rem;
|
|
79
|
-
border: 1px solid var(--kumiko-shortcuts-row-border);
|
|
80
|
-
border-radius: 0.5rem;
|
|
81
|
-
background: transparent;
|
|
82
|
-
color: inherit;
|
|
83
|
-
font: inherit;
|
|
84
|
-
font-size: 0.8125rem;
|
|
85
|
-
cursor: var(--kumiko-press-cursor, pointer);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
128
|
@media (pointer: coarse) {
|
|
89
|
-
.kumiko-shortcuts-sheet button,
|
|
90
|
-
.kumiko-shortcuts-sheet input,
|
|
91
129
|
.kumiko-shortcuts-sheet select {
|
|
92
130
|
min-block-size: var(--kumiko-touch-target, 2.75rem);
|
|
93
131
|
}
|
|
@@ -118,6 +156,11 @@
|
|
|
118
156
|
color: var(--kumiko-shortcuts-danger);
|
|
119
157
|
}
|
|
120
158
|
|
|
159
|
+
.kumiko-shortcuts-scroll .kumiko-shortcuts-empty {
|
|
160
|
+
padding-block: 2rem;
|
|
161
|
+
text-align: center;
|
|
162
|
+
}
|
|
163
|
+
|
|
121
164
|
.kumiko-shortcuts-empty,
|
|
122
165
|
.kumiko-shortcuts-foot,
|
|
123
166
|
.kumiko-shortcuts-none {
|
|
@@ -127,7 +170,7 @@
|
|
|
127
170
|
|
|
128
171
|
:where([data-slot$="popover-content"].kumiko-shortcuts-popover) {
|
|
129
172
|
inline-size: min(26rem, 100dvw - 2rem);
|
|
130
|
-
|
|
173
|
+
block-size: min(var(--kumiko-shortcuts-sheet-height), 70dvh);
|
|
131
174
|
}
|
|
132
175
|
|
|
133
176
|
/* The panel sits against the inline-end edge and takes the page's full height. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { disposeMirror, findField, measureCaret } from "./caret-geometry";
|
|
2
2
|
import { createGlider, prefersReducedMotion } from "./caret-glide";
|
|
3
|
+
import { canJoinTopLayer, isRaised, raiseToTop, topLayerAncestor } from "./top-layer";
|
|
3
4
|
const GLIDE_LIMIT = 400;
|
|
4
5
|
const IDLE_MS = 500;
|
|
5
6
|
const STILL_FRAMES = 12;
|
|
@@ -52,6 +53,8 @@ class CaretController {
|
|
|
52
53
|
watchTimer = 0;
|
|
53
54
|
stillFrames = 0;
|
|
54
55
|
fieldBox = "";
|
|
56
|
+
raisedField = null;
|
|
57
|
+
raisedLayer = null;
|
|
55
58
|
resizeObserver = new ResizeObserver(() => this.schedule());
|
|
56
59
|
glider;
|
|
57
60
|
caret;
|
|
@@ -153,12 +156,25 @@ class CaretController {
|
|
|
153
156
|
this.visible = false;
|
|
154
157
|
delete this.caret.dataset.visible;
|
|
155
158
|
}
|
|
159
|
+
/* Paints the caret above the top-layer element that holds the field, once per field and per holder. */
|
|
160
|
+
raise(field) {
|
|
161
|
+
const layer = topLayerAncestor(field);
|
|
162
|
+
const settled = isRaised(this.caret) &&
|
|
163
|
+
layer === this.raisedLayer &&
|
|
164
|
+
(layer === null || field === this.raisedField);
|
|
165
|
+
if (!settled) {
|
|
166
|
+
raiseToTop(this.caret);
|
|
167
|
+
this.raisedField = field;
|
|
168
|
+
this.raisedLayer = layer;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
156
171
|
show(rect, follow, field) {
|
|
157
172
|
const snap = follow ||
|
|
158
173
|
!this.visible ||
|
|
159
174
|
!this.last ||
|
|
160
175
|
Math.hypot(rect.x - this.last.x, rect.y - this.last.y) > GLIDE_LIMIT;
|
|
161
176
|
const reduced = prefersReducedMotion(field);
|
|
177
|
+
this.raise(field);
|
|
162
178
|
this.caret.style.setProperty("--_caret-color", colourOf(field));
|
|
163
179
|
this.glider.to(rect.x, rect.y, rect.height, snap || reduced);
|
|
164
180
|
this.caret.dataset.visible = "true";
|
|
@@ -175,7 +191,11 @@ class CaretController {
|
|
|
175
191
|
render(follow) {
|
|
176
192
|
const usable = document.hasFocus() && !this.composing;
|
|
177
193
|
const candidate = usable ? findField(document.activeElement) : null;
|
|
178
|
-
const
|
|
194
|
+
const drawable = candidate !== null &&
|
|
195
|
+
candidate.isConnected &&
|
|
196
|
+
hasArea(candidate) &&
|
|
197
|
+
(canJoinTopLayer(this.caret) || topLayerAncestor(candidate) === null);
|
|
198
|
+
const field = drawable ? candidate : null;
|
|
179
199
|
this.setTracked(field);
|
|
180
200
|
this.fieldBox = field ? boxOf(field) : "";
|
|
181
201
|
const rect = field ? measureCaret(field) : null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { startSmoothCaret } from "./caret-controller";
|
|
2
|
+
import { makeTopLayerPopover } from "./top-layer";
|
|
2
3
|
let users = 0;
|
|
3
4
|
let stopHost = null;
|
|
4
5
|
/* Builds the one caret element and starts following the focused field. Returns what undoes both. */
|
|
@@ -6,6 +7,8 @@ function mountCaret() {
|
|
|
6
7
|
const caret = document.createElement("div");
|
|
7
8
|
caret.dataset.slot = "smooth-caret";
|
|
8
9
|
caret.setAttribute("aria-hidden", "true");
|
|
10
|
+
caret.setAttribute("inert", "");
|
|
11
|
+
makeTopLayerPopover(caret);
|
|
9
12
|
const bar = document.createElement("div");
|
|
10
13
|
bar.dataset.slot = "smooth-caret-bar";
|
|
11
14
|
caret.append(bar);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createGlider, prefersReducedMotion } from "./caret-glide";
|
|
2
|
+
import { makeTopLayerPopover, openModals, raiseToTop, sameElements } from "./top-layer";
|
|
2
3
|
/* A nudge under this many pixels is not a move. */
|
|
3
4
|
const MOVED_BY = 0.5;
|
|
4
5
|
/* A jump longer than this many pixels snaps instead of gliding. */
|
|
@@ -91,6 +92,17 @@ function placeOne(overlay, caret, snap) {
|
|
|
91
92
|
show(overlay, entry, caret.spot, snap);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
95
|
+
/* A dialog that opened since the layer was raised paints above it, so the layer is raised again. */
|
|
96
|
+
function raiseOverDialogs(overlay) {
|
|
97
|
+
if (overlay.raisedOver === null) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const modals = openModals();
|
|
101
|
+
if (!sameElements(modals, overlay.raisedOver)) {
|
|
102
|
+
raiseToTop(overlay.layer);
|
|
103
|
+
overlay.raisedOver = modals;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
94
106
|
/**
|
|
95
107
|
* The overlay for remote collaborators: one gliding caret bar and name tag per person, in a fixed layer over
|
|
96
108
|
* the page. Framework-free, so any editor can drive it from its own awareness data.
|
|
@@ -101,14 +113,21 @@ export function createRemoteCarets(options = {}) {
|
|
|
101
113
|
layer.dataset.slot = "remote-carets";
|
|
102
114
|
layer.setAttribute("aria-hidden", "true");
|
|
103
115
|
host.append(layer);
|
|
116
|
+
const inTopLayer = host === document.body;
|
|
117
|
+
if (inTopLayer) {
|
|
118
|
+
makeTopLayerPopover(layer);
|
|
119
|
+
raiseToTop(layer);
|
|
120
|
+
}
|
|
104
121
|
const overlay = {
|
|
105
122
|
host,
|
|
106
123
|
layer,
|
|
107
124
|
stillMs: options.stillMs ?? TAG_STILL_MS,
|
|
108
|
-
entries: new Map()
|
|
125
|
+
entries: new Map(),
|
|
126
|
+
raisedOver: inTopLayer ? openModals() : null
|
|
109
127
|
};
|
|
110
128
|
return {
|
|
111
129
|
place(carets, snap) {
|
|
130
|
+
raiseOverDialogs(overlay);
|
|
112
131
|
const present = new Set();
|
|
113
132
|
for (const caret of carets) {
|
|
114
133
|
present.add(caret.id);
|
|
@@ -14,10 +14,22 @@
|
|
|
14
14
|
caret-color: transparent !important;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/*
|
|
18
|
+
* Both are manual popovers, so they sit in the top layer and paint above dialogs and popovers. The
|
|
19
|
+
* resets undo the browser's popover look (centred, bordered, padded, filled).
|
|
20
|
+
*/
|
|
17
21
|
[data-slot="smooth-caret"] {
|
|
18
22
|
position: fixed;
|
|
19
23
|
inset-block-start: 0;
|
|
20
24
|
inset-inline-start: 0;
|
|
25
|
+
inset-block-end: auto;
|
|
26
|
+
inset-inline-end: auto;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
border: 0;
|
|
30
|
+
overflow: visible;
|
|
31
|
+
background: transparent;
|
|
32
|
+
color: inherit;
|
|
21
33
|
z-index: var(--kumiko-smooth-caret-z);
|
|
22
34
|
inline-size: var(--kumiko-smooth-caret-width);
|
|
23
35
|
block-size: 1rem;
|
|
@@ -64,6 +76,13 @@
|
|
|
64
76
|
position: fixed;
|
|
65
77
|
inset: 0;
|
|
66
78
|
z-index: calc(var(--kumiko-smooth-caret-z) - 1);
|
|
79
|
+
inline-size: auto;
|
|
80
|
+
block-size: auto;
|
|
81
|
+
margin: 0;
|
|
82
|
+
padding: 0;
|
|
83
|
+
border: 0;
|
|
84
|
+
background: transparent;
|
|
85
|
+
color: inherit;
|
|
67
86
|
overflow: hidden;
|
|
68
87
|
pointer-events: none;
|
|
69
88
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Whether this browser can put the element in the top layer as a popover. */
|
|
2
|
+
export declare function canJoinTopLayer(element: HTMLElement): boolean;
|
|
3
|
+
/** Makes the element a manual popover. A manual one is never closed by light dismiss or by another popover opening. */
|
|
4
|
+
export declare function makeTopLayerPopover(element: HTMLElement): void;
|
|
5
|
+
/** Puts the element on top of the top layer: showing it again moves it above everything opened so far. */
|
|
6
|
+
export declare function raiseToTop(element: HTMLElement): void;
|
|
7
|
+
/** Whether the element is shown in the top layer right now. */
|
|
8
|
+
export declare function isRaised(element: HTMLElement): boolean;
|
|
9
|
+
/** The modal dialog or open popover that holds this element, or `null` when it sits in the page. */
|
|
10
|
+
export declare function topLayerAncestor(element: Element): Element | null;
|
|
11
|
+
/** Every dialog open right now: a native modal one, or a Kumiko dialog, which is a popover. */
|
|
12
|
+
export declare function openModals(): Element[];
|
|
13
|
+
export declare function sameElements(a: readonly Element[], b: readonly Element[]): boolean;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modal dialogs and open popovers sit in the browser's top layer, which paints above everything on the page
|
|
3
|
+
* whatever its z-index. The caret and the remote carets are plain page elements, so they have to join the top
|
|
4
|
+
* layer themselves, as manual popovers, and be raised again whenever something opens above them.
|
|
5
|
+
*/
|
|
6
|
+
/** Whether this browser can put the element in the top layer as a popover. */
|
|
7
|
+
export function canJoinTopLayer(element) {
|
|
8
|
+
return typeof element.showPopover === "function" && typeof element.hidePopover === "function";
|
|
9
|
+
}
|
|
10
|
+
/** Makes the element a manual popover. A manual one is never closed by light dismiss or by another popover opening. */
|
|
11
|
+
export function makeTopLayerPopover(element) {
|
|
12
|
+
element.setAttribute("popover", "manual");
|
|
13
|
+
}
|
|
14
|
+
function isShown(element) {
|
|
15
|
+
try {
|
|
16
|
+
return element.matches(":popover-open");
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Puts the element on top of the top layer: showing it again moves it above everything opened so far. */
|
|
23
|
+
export function raiseToTop(element) {
|
|
24
|
+
if (!canJoinTopLayer(element) || !element.isConnected) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (isShown(element)) {
|
|
28
|
+
element.hidePopover();
|
|
29
|
+
}
|
|
30
|
+
element.showPopover();
|
|
31
|
+
}
|
|
32
|
+
/** Whether the element is shown in the top layer right now. */
|
|
33
|
+
export function isRaised(element) {
|
|
34
|
+
return isShown(element);
|
|
35
|
+
}
|
|
36
|
+
/** The modal dialog or open popover that holds this element, or `null` when it sits in the page. */
|
|
37
|
+
export function topLayerAncestor(element) {
|
|
38
|
+
try {
|
|
39
|
+
return element.closest(":modal, :popover-open");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Every dialog open right now: a native modal one, or a Kumiko dialog, which is a popover. */
|
|
46
|
+
export function openModals() {
|
|
47
|
+
try {
|
|
48
|
+
return [...document.querySelectorAll(':modal, [data-slot$="dialog-content"]:popover-open')];
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function sameElements(a, b) {
|
|
55
|
+
return a.length === b.length && a.every((element, index) => element === b[index]);
|
|
56
|
+
}
|
|
@@ -18,7 +18,11 @@ export interface UndoApi {
|
|
|
18
18
|
/** Whether undo and redo controls should ignore taps: a step runs and extra taps are dropped. */
|
|
19
19
|
locked: boolean;
|
|
20
20
|
place: string | undefined;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Stores a step and returns the stored entry. A step that doesn't name a `place` gets this
|
|
23
|
+
* provider's. A step that names one keeps it, and `place: undefined` on purpose stays
|
|
24
|
+
* placeless. `store.remember` never stamps.
|
|
25
|
+
*/
|
|
22
26
|
remember: (entry: NewUndoEntry) => UndoEntry;
|
|
23
27
|
undo: () => Promise<void>;
|
|
24
28
|
redo: () => Promise<void>;
|
|
@@ -17,7 +17,7 @@ function bind({ store, scope, place }, snapshot) {
|
|
|
17
17
|
busy: snapshot.busy,
|
|
18
18
|
locked: snapshot.busy && snapshot.busyMode === "ignore",
|
|
19
19
|
place,
|
|
20
|
-
remember: store.remember,
|
|
20
|
+
remember: (entry) => store.remember("place" in entry ? entry : { ...entry, place }),
|
|
21
21
|
undo: () => store.undo(scope),
|
|
22
22
|
redo: () => store.redo(scope),
|
|
23
23
|
undoEntry: (id) => store.undoEntry(id, scope),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alulore/kumiko",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"description": "Polished, cozy React components with gentle motion, built on ui-sdk. Every look and behaviour can be switched with props and CSS tokens.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|