@alulore/kumiko 0.17.1 → 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.
@@ -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("button", { type: "button", onClick: cancel, children: "Cancel" })] }));
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("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", { type: "submit", disabled: !isValidKeys(text), children: "Use" }), _jsx("button", { type: "button", onClick: rebinder.cancel, children: "Cancel" })] }));
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("button", { type: "button", disabled: choice === "", onClick: () => rebinder.submit(choice), children: "Use" }), _jsx("button", { type: "button", onClick: rebinder.cancel, children: "Cancel" })] }));
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] })), pending.kind === "taken" ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: () => rebinder.resolve("swap"), children: "Swap" }), _jsx("button", { type: "button", onClick: () => rebinder.resolve("replace"), children: "Replace" })] })) : (_jsx("button", { type: "button", onClick: rebinder.useAnyway, children: "Use anyway" })), _jsx("button", { type: "button", onClick: rebinder.cancel, children: "Cancel" })] }));
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 }) {
@@ -19,11 +19,21 @@ export type ShortcutsHelpProps = TriggerProps & {
19
19
  * @defaultValue "Shortcuts"
20
20
  */
21
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;
22
32
  /** A class for the button. */
23
33
  className?: string;
24
34
  };
25
35
  /** A button that opens the help sheet: what can run now, by section. Its keys (`helpKeys`) open it too. */
26
- export declare function ShortcutsHelp({ presentation, editable, label, className, ...trigger }: ShortcutsHelpProps): React.JSX.Element;
36
+ export declare function ShortcutsHelp({ presentation, editable, label, title, description, className, ...trigger }: ShortcutsHelpProps): React.JSX.Element;
27
37
  /** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
28
38
  export declare function ShortcutsSettings(): React.JSX.Element;
29
39
  export {};
@@ -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
- function Body({ presentation, editable }) {
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
- const help = options.helpKeys;
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, ...trigger }) {
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, { ...trigger, className: className, children: label }), _jsxs(PopoverContent, { align: "end", sideOffset: 8, className: "kumiko-shortcuts-popover", children: [_jsx(PopoverTitle, { children: "Keyboard shortcuts" }), _jsx(PopoverDescription, { children: "What works right now." }), _jsx(Body, { presentation: presentation, editable: editable })] })] }));
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, { ...trigger, className: className, children: label }), _jsx(DialogBackdrop, {}), _jsxs(DialogContent, { className: "kumiko-shortcuts-dialog", "data-kumiko-shortcuts": presentation, children: [_jsx(DialogTitle, { children: "Keyboard shortcuts" }), _jsx(DialogDescription, { children: "What works right now." }), _jsx(Body, { presentation: presentation, editable: editable }), _jsx(DialogClose, { className: className, children: "Close" })] })] }));
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() {
@@ -1,5 +1,6 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { formatShortcut } from "@ui-sdk/react/shortcuts";
3
+ import { Button } from "../button";
3
4
  import { Kbd } from "../kbd";
4
5
  import { defaultKeys, maxKeysPerAction } from "./bindings";
5
6
  import { Capture } from "./capture";
@@ -19,13 +20,13 @@ function KeyChip({ action, slot, removable, rebinder }) {
19
20
  const key = keysFor(action.id)[slot] ?? "";
20
21
  const { target } = rebinder;
21
22
  const changing = target?.id === action.id && target.slot === slot;
22
- return (_jsxs("span", { className: "kumiko-shortcuts-key", "data-changing": changing ? "" : undefined, children: [_jsx(Kbd, { keys: key, listen: false }), _jsx("button", { type: "button", "aria-label": `Change ${spoken(key)} for ${action.description}`, onClick: () => rebinder.begin({ id: action.id, slot }), children: "Change" }), removable ? (_jsx("button", { type: "button", "aria-label": `Remove ${spoken(key)} from ${action.description}`, onClick: () => rebinder.remove(action.id, slot), children: "Remove" })) : null] }));
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] }));
23
24
  }
24
25
  function KeyEditor({ action, rebinder }) {
25
26
  const { keysFor, options } = useShortcuts();
26
27
  const keys = keysFor(action.id);
27
28
  const canAdd = options.multipleKeys ? keys.length < maxKeysPerAction : keys.length === 0;
28
- 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", { 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", { type: "button", onClick: () => rebinder.reset(action.id), children: "Reset" })) : null] }));
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] }));
29
30
  }
30
31
  function Row({ action, editing, rebinder }) {
31
32
  const { keysFor, available } = useShortcuts();
@@ -36,7 +37,7 @@ function NoteRow({ note }) {
36
37
  }
37
38
  function EditFooter() {
38
39
  const { resetAll, overrides, options, saveFailed } = useShortcuts();
39
- 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", { type: "button", onClick: resetAll, children: "Reset all" }) })) : null, options.multipleKeys ? null : (_jsx("p", { className: "kumiko-shortcuts-empty", children: "Each action has one key." }))] }));
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." }))] }));
40
41
  }
41
42
  /** The actions grouped by section, each with its keys. With `editing`, every key can be changed. */
42
43
  export function ShortcutsList({ editing = false, all = editing, query = "" }) {
@@ -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
- .kumiko-shortcuts-sheet input[type="search"] {
21
- padding: 0.4rem 0.6rem;
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
- max-block-size: 70dvh;
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 field = candidate?.isConnected && hasArea(candidate) ? candidate : null;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alulore/kumiko",
3
- "version": "0.17.1",
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": {