@sdxc/ui 2026.11.11 → 2026.11.17
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 +114 -61
- package/dist/app/app-shell-toggle.d.ts +2 -0
- package/dist/app/app-shell-toggle.js +5 -2
- package/dist/app/app-shell.d.ts +25 -1
- package/dist/app/app-shell.js +73 -38
- package/dist/app/auto-refresh.d.ts +2 -0
- package/dist/app/auto-refresh.js +3 -3
- package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
- package/dist/app/behaviors/refresh-schedule.js +4 -3
- package/dist/app/board.d.ts +123 -0
- package/dist/app/board.js +224 -0
- package/dist/app/chart.d.ts +2 -2
- package/dist/app/chart.js +7 -3
- package/dist/app/check-runs.d.ts +116 -0
- package/dist/app/check-runs.js +201 -0
- package/dist/app/code-view.d.ts +172 -0
- package/dist/app/code-view.js +414 -0
- package/dist/app/command-palette.d.ts +38 -3
- package/dist/app/command-palette.js +53 -5
- package/dist/app/contribution-graph.d.ts +106 -0
- package/dist/app/contribution-graph.js +289 -0
- package/dist/app/detail-sheet.d.ts +7 -0
- package/dist/app/detail-sheet.js +7 -7
- package/dist/app/diff.d.ts +200 -0
- package/dist/app/diff.js +702 -0
- package/dist/app/filter-bar.d.ts +20 -0
- package/dist/app/filter-bar.js +35 -15
- package/dist/app/filter-menu.d.ts +144 -0
- package/dist/app/filter-menu.js +480 -0
- package/dist/app/gantt.d.ts +108 -0
- package/dist/app/gantt.js +420 -0
- package/dist/app/index.d.ts +20 -0
- package/dist/app/index.js +20 -0
- package/dist/app/log-viewer.d.ts +120 -0
- package/dist/app/log-viewer.js +384 -0
- package/dist/app/merge-box.d.ts +97 -0
- package/dist/app/merge-box.js +227 -0
- package/dist/app/mixins/app-shell-controls.d.ts +4 -1
- package/dist/app/mixins/app-shell-controls.js +64 -4
- package/dist/app/mixins/auto-refresh.d.ts +5 -2
- package/dist/app/mixins/auto-refresh.js +9 -3
- package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
- package/dist/app/mixins/close-popover-on-submit.js +32 -0
- package/dist/app/mixins/code-view-selection.d.ts +60 -0
- package/dist/app/mixins/code-view-selection.js +276 -0
- package/dist/app/mixins/command-palette.d.ts +15 -4
- package/dist/app/mixins/command-palette.js +94 -6
- package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
- package/dist/app/mixins/contribution-graph-keys.js +155 -0
- package/dist/app/mixins/diff-interactions.d.ts +72 -0
- package/dist/app/mixins/diff-interactions.js +269 -0
- package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
- package/dist/app/mixins/filter-menu-keys.js +91 -0
- package/dist/app/mixins/gantt-today.d.ts +17 -0
- package/dist/app/mixins/gantt-today.js +50 -0
- package/dist/app/mixins/log-viewer.d.ts +29 -0
- package/dist/app/mixins/log-viewer.js +347 -0
- package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
- package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
- package/dist/app/mixins/save-bar-sync.d.ts +7 -1
- package/dist/app/mixins/save-bar-sync.js +23 -4
- package/dist/app/mixins/save-status-sync.js +23 -1
- package/dist/app/mixins/split-view.js +1 -1
- package/dist/app/mixins/submit-on-close.d.ts +17 -0
- package/dist/app/mixins/submit-on-close.js +52 -0
- package/dist/app/mixins/tree-filter.d.ts +44 -0
- package/dist/app/mixins/tree-filter.js +111 -0
- package/dist/app/mixins/tree-navigation.d.ts +50 -0
- package/dist/app/mixins/tree-navigation.js +216 -0
- package/dist/app/optimistic-toggle.d.ts +8 -0
- package/dist/app/optimistic-toggle.js +3 -2
- package/dist/app/page-header.d.ts +18 -3
- package/dist/app/page-header.js +105 -50
- package/dist/app/profile-picker.d.ts +47 -0
- package/dist/app/profile-picker.js +104 -0
- package/dist/app/review-thread.d.ts +115 -0
- package/dist/app/review-thread.js +116 -0
- package/dist/app/save-bar.d.ts +5 -0
- package/dist/app/save-bar.js +1 -1
- package/dist/app/save-status.js +1 -1
- package/dist/app/settings-layout.d.ts +5 -0
- package/dist/app/settings-layout.js +5 -5
- package/dist/app/skeleton.d.ts +9 -0
- package/dist/app/skeleton.js +28 -0
- package/dist/app/split-view.d.ts +4 -0
- package/dist/app/split-view.js +3 -3
- package/dist/app/styles/code-tokens.d.ts +24 -0
- package/dist/app/styles/code-tokens.js +47 -0
- package/dist/app/tab-bar.d.ts +59 -0
- package/dist/app/tab-bar.js +111 -0
- package/dist/app/tree.d.ts +111 -14
- package/dist/app/tree.js +202 -15
- package/dist/app/utils/ansi.d.ts +55 -0
- package/dist/app/utils/ansi.js +157 -0
- package/dist/app/utils/diff-rows.d.ts +82 -0
- package/dist/app/utils/diff-rows.js +209 -0
- package/dist/app/utils/fuzzy-path.d.ts +58 -0
- package/dist/app/utils/fuzzy-path.js +202 -0
- package/dist/app/utils/line-range.d.ts +48 -0
- package/dist/app/utils/line-range.js +61 -0
- package/dist/app/utils/log-lines.d.ts +107 -0
- package/dist/app/utils/log-lines.js +170 -0
- package/dist/app/utils/tree-filter.d.ts +19 -0
- package/dist/app/utils/tree-filter.js +26 -0
- package/dist/app/view-options.d.ts +2 -0
- package/dist/app/view-options.js +2 -2
- package/dist/chat/activity.d.ts +72 -0
- package/dist/chat/activity.js +184 -0
- package/dist/chat/composer-submit.d.ts +38 -0
- package/dist/chat/composer-submit.js +44 -0
- package/dist/chat/composer.d.ts +47 -0
- package/dist/chat/composer.js +100 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mixins/composer-send.d.ts +32 -0
- package/dist/chat/mixins/composer-send.js +121 -0
- package/dist/chat/mixins/reveal-stream.d.ts +68 -0
- package/dist/chat/mixins/reveal-stream.js +184 -0
- package/dist/chat/mixins/stream-target.d.ts +18 -0
- package/dist/chat/mixins/stream-target.js +38 -0
- package/dist/components/button.js +7 -1
- package/dist/components/character-count.d.ts +44 -0
- package/dist/components/character-count.js +68 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/label-chip.d.ts +42 -0
- package/dist/components/label-chip.js +86 -0
- package/dist/components/property-list.d.ts +9 -2
- package/dist/components/property-list.js +37 -10
- package/dist/components/textarea.js +6 -1
- package/dist/components/timeline.d.ts +62 -5
- package/dist/components/timeline.js +124 -5
- package/dist/docs/code-block.js +8 -31
- package/dist/docs/file-tree.js +3 -48
- package/dist/landing/case-study.d.ts +79 -0
- package/dist/landing/case-study.js +162 -0
- package/dist/landing/contributor-wall.d.ts +72 -0
- package/dist/landing/contributor-wall.js +129 -0
- package/dist/landing/countdown.d.ts +88 -0
- package/dist/landing/countdown.js +91 -0
- package/dist/landing/episode-player.d.ts +87 -0
- package/dist/landing/episode-player.js +113 -0
- package/dist/landing/faq-band.d.ts +3 -2
- package/dist/landing/faq-band.js +4 -3
- package/dist/landing/index.d.ts +7 -0
- package/dist/landing/index.js +7 -0
- package/dist/landing/landing-header.js +15 -4
- package/dist/landing/mixins/countdown-tick.d.ts +29 -0
- package/dist/landing/mixins/countdown-tick.js +65 -0
- package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
- package/dist/landing/mixins/usage-estimate-live.js +120 -0
- package/dist/landing/phone-frame.d.ts +2 -1
- package/dist/landing/price-list.d.ts +68 -0
- package/dist/landing/price-list.js +125 -0
- package/dist/landing/scroll-scene.d.ts +59 -0
- package/dist/landing/scroll-scene.js +70 -0
- package/dist/landing/sponsor-wall.d.ts +30 -6
- package/dist/landing/sponsor-wall.js +70 -14
- package/dist/landing/typed-terminal.d.ts +24 -6
- package/dist/landing/typed-terminal.js +22 -14
- package/dist/landing/usage-estimate.d.ts +127 -0
- package/dist/landing/usage-estimate.js +164 -0
- package/dist/landing/utils/countdown.d.ts +33 -0
- package/dist/landing/utils/countdown.js +42 -0
- package/dist/landing/utils/pause-toggle.d.ts +2 -1
- package/dist/mixins/character-count.d.ts +62 -0
- package/dist/mixins/character-count.js +139 -0
- package/dist/mixins/index.d.ts +6 -2
- package/dist/mixins/index.js +6 -2
- package/dist/mixins/invoker-fields.d.ts +18 -0
- package/dist/mixins/invoker-fields.js +60 -0
- package/dist/mixins/media-sync.d.ts +58 -0
- package/dist/mixins/media-sync.js +102 -0
- package/dist/mixins/menu-keys.d.ts +11 -0
- package/dist/mixins/menu-keys.js +79 -70
- package/dist/mixins/sortable.d.ts +96 -0
- package/dist/mixins/sortable.js +433 -0
- package/dist/utils/code-lines.d.ts +26 -0
- package/dist/utils/code-lines.js +29 -0
- package/dist/utils/file-icon.d.ts +31 -0
- package/dist/utils/file-icon.js +60 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/write-cookie.d.ts +15 -15
- package/dist/utils/write-cookie.js +10 -16
- package/dist/video/episode-list.d.ts +48 -0
- package/dist/video/episode-list.js +161 -0
- package/dist/video/index.d.ts +15 -0
- package/dist/video/index.js +15 -0
- package/dist/video/mixins/video-player-sync.d.ts +27 -0
- package/dist/video/mixins/video-player-sync.js +413 -0
- package/dist/video/mixins/video-shelf-steps.d.ts +20 -0
- package/dist/video/mixins/video-shelf-steps.js +79 -0
- package/dist/video/title-hero.d.ts +51 -0
- package/dist/video/title-hero.js +170 -0
- package/dist/video/utils/timeline.d.ts +55 -0
- package/dist/video/utils/timeline.js +90 -0
- package/dist/video/video-card.d.ts +51 -0
- package/dist/video/video-card.js +135 -0
- package/dist/video/video-player.d.ts +261 -0
- package/dist/video/video-player.js +927 -0
- package/dist/video/video-shelf.d.ts +58 -0
- package/dist/video/video-shelf.js +155 -0
- package/package.json +6 -3
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line selection for a code view, from one listener on the view: a number click selects its
|
|
3
|
+
* line, a shift-click a range, the address becomes `#L3-L8` in place, the band and line menu
|
|
4
|
+
* follow, and the numbers are one Tab stop the arrow keys walk.
|
|
5
|
+
* Why JS: ranges, an address rewritten without a navigation, and the clipboard need script.
|
|
6
|
+
* No-JS baseline: every number links to `?L=n#Ln`, the server paints that line and
|
|
7
|
+
* `:target` paints the line an address names.
|
|
8
|
+
*
|
|
9
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
10
|
+
* @copyright Sergio Xalambrí 2026
|
|
11
|
+
*/
|
|
12
|
+
import { createElement, createMixin } from "remix/component";
|
|
13
|
+
import { ESCAPE_PRIORITY, shortcutRegistry } from "../behaviors/shortcuts.js";
|
|
14
|
+
import { lineRangeHash, lineRangeQuery, parseLineRange } from "../utils/line-range.js";
|
|
15
|
+
/** Selector for the element a code view renders as its root. */
|
|
16
|
+
export const CODE_VIEW_SELECTOR = '[data-slot="code-view"]';
|
|
17
|
+
/** Attribute a selected row carries, which the view's styles paint as the band. */
|
|
18
|
+
export const CODE_VIEW_SELECTED_ATTRIBUTE = "data-selected";
|
|
19
|
+
/**
|
|
20
|
+
* Attribute the view's root carries while this mixin owns the selection, which hands the
|
|
21
|
+
* band from `:target` (fixed at load) to the rows it marks.
|
|
22
|
+
*/
|
|
23
|
+
export const CODE_VIEW_LIVE_ATTRIBUTE = "data-selection-live";
|
|
24
|
+
/** Attribute the view's root carries while a selection shows its line menu. */
|
|
25
|
+
export const CODE_VIEW_MENU_ATTRIBUTE = "data-line-menu";
|
|
26
|
+
/** Selector for a line's number link, whose `data-line-number` names its line. */
|
|
27
|
+
const NUMBER_SELECTOR = "a[data-line-number]";
|
|
28
|
+
/**
|
|
29
|
+
* The line each key moves focus to from `line`, so the numbers are one Tab stop the arrows walk:
|
|
30
|
+
* a line up or down, a screen up or down, or the first or last line.
|
|
31
|
+
*/
|
|
32
|
+
const LINE_STEPS = {
|
|
33
|
+
ArrowUp: (line) => Math.max(1, line - 1),
|
|
34
|
+
ArrowDown: (line, view) => Math.min(lastLine(view), line + 1),
|
|
35
|
+
PageUp: (line) => Math.max(1, line - 20),
|
|
36
|
+
PageDown: (line, view) => Math.min(lastLine(view), line + 20),
|
|
37
|
+
Home: () => 1,
|
|
38
|
+
End: (_, view) => lastLine(view),
|
|
39
|
+
};
|
|
40
|
+
/** The view's last line number, read from its last number link. */
|
|
41
|
+
function lastLine(view) {
|
|
42
|
+
let numbers = view.querySelectorAll(NUMBER_SELECTOR);
|
|
43
|
+
return Number(numbers[numbers.length - 1]?.getAttribute("data-line-number") ?? 1);
|
|
44
|
+
}
|
|
45
|
+
/** Moves the numbers' one Tab stop from `from` to `to` and focuses `to`. */
|
|
46
|
+
function rove(from, to) {
|
|
47
|
+
if (from !== null && from !== to)
|
|
48
|
+
from.tabIndex = -1;
|
|
49
|
+
to.tabIndex = 0;
|
|
50
|
+
to.focus();
|
|
51
|
+
}
|
|
52
|
+
/** Search parameter a server reads to paint a range without script. */
|
|
53
|
+
const LINE_PARAM = "L";
|
|
54
|
+
/** How long a copy action reads as done to a screen reader before the status clears. */
|
|
55
|
+
const COPIED_MS = 2000;
|
|
56
|
+
/** The row of line `line` inside `root`, through its number's `id`. */
|
|
57
|
+
function rowOf(root, line) {
|
|
58
|
+
let number = root.ownerDocument.getElementById(`L${line}`);
|
|
59
|
+
if (number === null || !root.contains(number))
|
|
60
|
+
return null;
|
|
61
|
+
return number.closest("tr");
|
|
62
|
+
}
|
|
63
|
+
/** Marks the rows in `range` as selected and clears every row marked before. */
|
|
64
|
+
function paint(root, range) {
|
|
65
|
+
for (let row of root.querySelectorAll(`tr[${CODE_VIEW_SELECTED_ATTRIBUTE}]`)) {
|
|
66
|
+
row.removeAttribute(CODE_VIEW_SELECTED_ATTRIBUTE);
|
|
67
|
+
}
|
|
68
|
+
if (range === undefined)
|
|
69
|
+
return;
|
|
70
|
+
for (let line = range.start; line <= range.end; line += 1) {
|
|
71
|
+
rowOf(root, line)?.setAttribute(CODE_VIEW_SELECTED_ATTRIBUTE, "");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Moves the line menu beside the first selected line's number, through custom properties
|
|
76
|
+
* on the root the menu reads its offsets from.
|
|
77
|
+
*/
|
|
78
|
+
function placeMenu(root, range) {
|
|
79
|
+
let row = range === undefined ? null : rowOf(root, range.start);
|
|
80
|
+
let number = row?.querySelector(NUMBER_SELECTOR)?.parentElement;
|
|
81
|
+
if (number == null) {
|
|
82
|
+
root.removeAttribute(CODE_VIEW_MENU_ATTRIBUTE);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let box = root.getBoundingClientRect();
|
|
86
|
+
let cell = number.getBoundingClientRect();
|
|
87
|
+
root.style.setProperty("--code-view-menu-top", `${cell.top - box.top}px`);
|
|
88
|
+
root.style.setProperty("--code-view-menu-start", `${cell.left - box.left}px`);
|
|
89
|
+
root.setAttribute(CODE_VIEW_MENU_ATTRIBUTE, "");
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Rewrites the address for `range` without a navigation or a history entry, keeping the
|
|
93
|
+
* state the router stored there. A `?L=` already in the address follows the range, so a
|
|
94
|
+
* reload without script paints the same lines.
|
|
95
|
+
*/
|
|
96
|
+
function writeAddress(range) {
|
|
97
|
+
let url = new URL(location.href);
|
|
98
|
+
url.hash = range === undefined ? "" : lineRangeHash(range);
|
|
99
|
+
if (url.searchParams.has(LINE_PARAM)) {
|
|
100
|
+
if (range === undefined)
|
|
101
|
+
url.searchParams.delete(LINE_PARAM);
|
|
102
|
+
else
|
|
103
|
+
url.searchParams.set(LINE_PARAM, lineRangeQuery(range));
|
|
104
|
+
}
|
|
105
|
+
if (url.href !== location.href)
|
|
106
|
+
history.replaceState(history.state, "", url);
|
|
107
|
+
}
|
|
108
|
+
/** The text of the lines in `range`, one per line, as the source holds them. */
|
|
109
|
+
function linesText(root, range) {
|
|
110
|
+
let lines = [];
|
|
111
|
+
for (let line = range.start; line <= range.end; line += 1) {
|
|
112
|
+
lines.push(rowOf(root, line)?.lastElementChild?.textContent ?? "");
|
|
113
|
+
}
|
|
114
|
+
return lines.join("\n");
|
|
115
|
+
}
|
|
116
|
+
/** The permalink for `range`: the fixed-commit address, or this page's, with the range's fragment. */
|
|
117
|
+
function permalinkFor(permalink, range) {
|
|
118
|
+
let url = new URL(permalink ?? location.href, location.href);
|
|
119
|
+
url.searchParams.delete(LINE_PARAM);
|
|
120
|
+
url.hash = range === undefined ? "" : lineRangeHash(range);
|
|
121
|
+
return url.href;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Owns a code view's line selection from inside the view's island: it reads the range from
|
|
125
|
+
* the address (or the one the server painted), answers clicks on line numbers, `y` and
|
|
126
|
+
* Escape, and runs the line menu's actions, marked `data-action` on its items.
|
|
127
|
+
*
|
|
128
|
+
* @param options The permalink, the issue address and the copy.
|
|
129
|
+
* @example <div mix={[codeViewSelection({ permalink: "/blob/3f2a9c1/app.ts", labels: { copied: t("copied") } })]}>…menu…</div>
|
|
130
|
+
*/
|
|
131
|
+
export const codeViewSelection = createMixin((handle) => {
|
|
132
|
+
let options = { labels: { copied: "" } };
|
|
133
|
+
handle.addEventListener("insert", (event) => {
|
|
134
|
+
let island = event.node;
|
|
135
|
+
let root = island.closest(CODE_VIEW_SELECTOR);
|
|
136
|
+
if (root === null)
|
|
137
|
+
return;
|
|
138
|
+
let view = root;
|
|
139
|
+
let signal = handle.signal;
|
|
140
|
+
let state = { anchor: undefined, range: undefined };
|
|
141
|
+
let clearStatus;
|
|
142
|
+
signal.addEventListener("abort", () => clearTimeout(clearStatus));
|
|
143
|
+
/** Paints `range`, moves the menu to it and keeps it as the anchor for the next shift-click. */
|
|
144
|
+
let select = (range, anchor = range?.start) => {
|
|
145
|
+
state = { anchor, range };
|
|
146
|
+
paint(view, range);
|
|
147
|
+
placeMenu(view, range);
|
|
148
|
+
};
|
|
149
|
+
/** Says `copied` to a screen reader for a moment. */
|
|
150
|
+
let announce = () => {
|
|
151
|
+
let status = island.querySelector('[role="status"]');
|
|
152
|
+
if (status === null)
|
|
153
|
+
return;
|
|
154
|
+
status.textContent = options.labels.copied;
|
|
155
|
+
clearTimeout(clearStatus);
|
|
156
|
+
clearStatus = setTimeout(() => {
|
|
157
|
+
status.textContent = "";
|
|
158
|
+
}, COPIED_MS);
|
|
159
|
+
};
|
|
160
|
+
view.setAttribute(CODE_VIEW_LIVE_ATTRIBUTE, "");
|
|
161
|
+
signal.addEventListener("abort", () => view.removeAttribute(CODE_VIEW_LIVE_ATTRIBUTE));
|
|
162
|
+
let fromHash = parseLineRange(location.hash);
|
|
163
|
+
let initial = fromHash ?? parseLineRange(view.getAttribute("data-selection"));
|
|
164
|
+
select(initial);
|
|
165
|
+
if (fromHash !== undefined && fromHash.start !== fromHash.end) {
|
|
166
|
+
rowOf(view, fromHash.start)?.scrollIntoView({ block: "center" });
|
|
167
|
+
}
|
|
168
|
+
view.addEventListener("keydown", (press) => {
|
|
169
|
+
if (!(press.target instanceof HTMLAnchorElement) ||
|
|
170
|
+
!press.target.matches(NUMBER_SELECTOR)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let line = Number(press.target.getAttribute("data-line-number"));
|
|
174
|
+
let next = LINE_STEPS[press.key]?.(line, view);
|
|
175
|
+
if (next === undefined)
|
|
176
|
+
return;
|
|
177
|
+
let target = view.ownerDocument.getElementById(`L${next}`);
|
|
178
|
+
if (!(target instanceof HTMLAnchorElement) || !view.contains(target))
|
|
179
|
+
return;
|
|
180
|
+
press.preventDefault();
|
|
181
|
+
rove(press.target, target);
|
|
182
|
+
}, { signal });
|
|
183
|
+
view.addEventListener("click", (click) => {
|
|
184
|
+
if (!(click.target instanceof Element))
|
|
185
|
+
return;
|
|
186
|
+
let number = click.target.closest(NUMBER_SELECTOR);
|
|
187
|
+
if (number === null || !view.contains(number))
|
|
188
|
+
return;
|
|
189
|
+
click.preventDefault();
|
|
190
|
+
rove(view.querySelector(`${NUMBER_SELECTOR}[tabindex="0"]`), number);
|
|
191
|
+
let line = Number(number.getAttribute("data-line-number"));
|
|
192
|
+
let anchor = state.anchor;
|
|
193
|
+
if (click.shiftKey && anchor !== undefined) {
|
|
194
|
+
select({ start: Math.min(anchor, line), end: Math.max(anchor, line) }, anchor);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
select({ start: line, end: line });
|
|
198
|
+
}
|
|
199
|
+
writeAddress(state.range);
|
|
200
|
+
}, { signal });
|
|
201
|
+
island.addEventListener("click", async (click) => {
|
|
202
|
+
if (!(click.target instanceof Element))
|
|
203
|
+
return;
|
|
204
|
+
let item = click.target.closest("[data-action]");
|
|
205
|
+
let range = state.range;
|
|
206
|
+
if (item === null || range === undefined)
|
|
207
|
+
return;
|
|
208
|
+
let action = item.getAttribute("data-action");
|
|
209
|
+
if (action === "reference" && item instanceof HTMLAnchorElement && options.issueHref) {
|
|
210
|
+
let target = new URL(options.issueHref, location.href);
|
|
211
|
+
target.searchParams.set(options.issueParam ?? "body", permalinkFor(options.permalink, range));
|
|
212
|
+
item.href = target.href;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
let text = action === "copy-line" ? linesText(view, range) : permalinkFor(options.permalink, range);
|
|
216
|
+
item.closest("[popover]")?.hidePopover();
|
|
217
|
+
try {
|
|
218
|
+
await navigator.clipboard.writeText(text);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (!signal.aborted)
|
|
224
|
+
announce();
|
|
225
|
+
}, { signal });
|
|
226
|
+
window.addEventListener("hashchange", () => {
|
|
227
|
+
let range = parseLineRange(location.hash);
|
|
228
|
+
if (range !== undefined)
|
|
229
|
+
select(range);
|
|
230
|
+
}, { signal });
|
|
231
|
+
let resize = new ResizeObserver(() => placeMenu(view, state.range));
|
|
232
|
+
resize.observe(view);
|
|
233
|
+
signal.addEventListener("abort", () => resize.disconnect());
|
|
234
|
+
let registry = shortcutRegistry(view.ownerDocument);
|
|
235
|
+
registry.register({
|
|
236
|
+
keys: "y",
|
|
237
|
+
label: options.labels.permalinkKey,
|
|
238
|
+
group: options.labels.group,
|
|
239
|
+
scope: view,
|
|
240
|
+
run: () => {
|
|
241
|
+
if (options.permalink === undefined)
|
|
242
|
+
return false;
|
|
243
|
+
let url = new URL(options.permalink, location.href);
|
|
244
|
+
let current = new URL(location.href);
|
|
245
|
+
url.hash = current.hash;
|
|
246
|
+
let line = current.searchParams.get(LINE_PARAM);
|
|
247
|
+
if (line !== null)
|
|
248
|
+
url.searchParams.set(LINE_PARAM, line);
|
|
249
|
+
history.replaceState(history.state, "", url);
|
|
250
|
+
return true;
|
|
251
|
+
},
|
|
252
|
+
signal,
|
|
253
|
+
});
|
|
254
|
+
registry.register({
|
|
255
|
+
keys: "escape",
|
|
256
|
+
label: options.labels.clearSelection,
|
|
257
|
+
group: options.labels.group,
|
|
258
|
+
scope: view,
|
|
259
|
+
priority: ESCAPE_PRIORITY.selection,
|
|
260
|
+
run: (key) => {
|
|
261
|
+
if (state.range === undefined)
|
|
262
|
+
return false;
|
|
263
|
+
if (key.target instanceof Node && island.contains(key.target))
|
|
264
|
+
return false;
|
|
265
|
+
select(undefined);
|
|
266
|
+
writeAddress(undefined);
|
|
267
|
+
return true;
|
|
268
|
+
},
|
|
269
|
+
signal,
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
return (next) => {
|
|
273
|
+
options = next;
|
|
274
|
+
return createElement(handle.element, {});
|
|
275
|
+
};
|
|
276
|
+
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The browser half of the command palette: filters
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* page stacks need script. No-JS baseline: a trigger opens the dialog and
|
|
2
|
+
* The browser half of the command palette: filters commands by title and keywords, ranks a
|
|
3
|
+
* finder page's paths, moves the active row, opens pages, fills Recent, and binds the toggle
|
|
4
|
+
* key and every page's and command's own key. Why JS: filtering, active-descendant movement,
|
|
5
|
+
* page stacks and finder ranking need script. No-JS baseline: a trigger opens the dialog and
|
|
6
|
+
* every command works.
|
|
6
7
|
*
|
|
7
8
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
9
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -18,6 +19,16 @@ export declare const PALETTE_CONTROL_ATTRIBUTE = "data-palette-control";
|
|
|
18
19
|
export declare const PALETTE_GOTO_ATTRIBUTE = "data-palette-goto";
|
|
19
20
|
/** Marks a page of commands with its id. */
|
|
20
21
|
export declare const PALETTE_PAGE_ATTRIBUTE = "data-palette-page";
|
|
22
|
+
/** Marks a page's shortcut, the combo that opens the palette straight on that page. */
|
|
23
|
+
export declare const PALETTE_PAGE_SHORTCUT_ATTRIBUTE = "data-palette-page-shortcut";
|
|
24
|
+
/** Marks a finder and carries its paths, one per line. */
|
|
25
|
+
export declare const PALETTE_FINDER_ATTRIBUTE = "data-palette-finder";
|
|
26
|
+
/** Marks the `<template>` holding the row a finder clones per result. */
|
|
27
|
+
export declare const PALETTE_FINDER_ROW_ATTRIBUTE = "data-palette-finder-row";
|
|
28
|
+
/** Marks the container a finder lists its results in. */
|
|
29
|
+
export declare const PALETTE_FINDER_RESULTS_ATTRIBUTE = "data-palette-finder-results";
|
|
30
|
+
/** Marks the span in a finder row that holds the path and its bolded matches. */
|
|
31
|
+
export declare const PALETTE_FINDER_PATH_ATTRIBUTE = "data-palette-finder-path";
|
|
21
32
|
/** Marks a row the island copied into the Recent group. */
|
|
22
33
|
export declare const PALETTE_CLONE_ATTRIBUTE = "data-palette-clone";
|
|
23
34
|
/** Marks a shortcut hint with the combo it prints, so the island reprints it per platform. */
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The browser half of the command palette: filters
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* page stacks need script. No-JS baseline: a trigger opens the dialog and
|
|
2
|
+
* The browser half of the command palette: filters commands by title and keywords, ranks a
|
|
3
|
+
* finder page's paths, moves the active row, opens pages, fills Recent, and binds the toggle
|
|
4
|
+
* key and every page's and command's own key. Why JS: filtering, active-descendant movement,
|
|
5
|
+
* page stacks and finder ranking need script. No-JS baseline: a trigger opens the dialog and
|
|
6
|
+
* every command works.
|
|
6
7
|
*
|
|
7
8
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
9
|
* @copyright Sergio Xalambrí 2026
|
|
9
10
|
*/
|
|
10
11
|
import { createMixin } from "remix/component";
|
|
11
12
|
import { isApplePlatform, shortcutGlyphs, shortcutRegistry } from "../behaviors/shortcuts.js";
|
|
13
|
+
import { fuzzyFilter, fuzzySegments } from "../utils/fuzzy-path.js";
|
|
12
14
|
/** How many recent commands the palette offers before anything is typed. */
|
|
13
15
|
export const PALETTE_RECENT_LIMIT = 5;
|
|
14
16
|
/** Marks each row with its command's id, which `recent` and the remembered list name. */
|
|
@@ -19,6 +21,16 @@ export const PALETTE_CONTROL_ATTRIBUTE = "data-palette-control";
|
|
|
19
21
|
export const PALETTE_GOTO_ATTRIBUTE = "data-palette-goto";
|
|
20
22
|
/** Marks a page of commands with its id. */
|
|
21
23
|
export const PALETTE_PAGE_ATTRIBUTE = "data-palette-page";
|
|
24
|
+
/** Marks a page's shortcut, the combo that opens the palette straight on that page. */
|
|
25
|
+
export const PALETTE_PAGE_SHORTCUT_ATTRIBUTE = "data-palette-page-shortcut";
|
|
26
|
+
/** Marks a finder and carries its paths, one per line. */
|
|
27
|
+
export const PALETTE_FINDER_ATTRIBUTE = "data-palette-finder";
|
|
28
|
+
/** Marks the `<template>` holding the row a finder clones per result. */
|
|
29
|
+
export const PALETTE_FINDER_ROW_ATTRIBUTE = "data-palette-finder-row";
|
|
30
|
+
/** Marks the container a finder lists its results in. */
|
|
31
|
+
export const PALETTE_FINDER_RESULTS_ATTRIBUTE = "data-palette-finder-results";
|
|
32
|
+
/** Marks the span in a finder row that holds the path and its bolded matches. */
|
|
33
|
+
export const PALETTE_FINDER_PATH_ATTRIBUTE = "data-palette-finder-path";
|
|
22
34
|
/** Marks a row the island copied into the Recent group. */
|
|
23
35
|
export const PALETTE_CLONE_ATTRIBUTE = "data-palette-clone";
|
|
24
36
|
/** Marks a shortcut hint with the combo it prints, so the island reprints it per platform. */
|
|
@@ -40,6 +52,57 @@ export function foldSearchText(value) {
|
|
|
40
52
|
function pageOf(element) {
|
|
41
53
|
return (element.closest(`[${PALETTE_PAGE_ATTRIBUTE}]`)?.getAttribute(PALETTE_PAGE_ATTRIBUTE) ?? null);
|
|
42
54
|
}
|
|
55
|
+
/** Reads every finder in `list`; one missing its row template or results container is skipped. */
|
|
56
|
+
function readFinders(list) {
|
|
57
|
+
let finders = new Map();
|
|
58
|
+
for (let element of list.querySelectorAll(`[${PALETTE_FINDER_ATTRIBUTE}]`)) {
|
|
59
|
+
let page = pageOf(element);
|
|
60
|
+
let template = element.querySelector(`template[${PALETTE_FINDER_ROW_ATTRIBUTE}]`);
|
|
61
|
+
let row = template?.content.firstElementChild ?? template?.firstElementChild ?? null;
|
|
62
|
+
let results = element.querySelector(`[${PALETTE_FINDER_RESULTS_ATTRIBUTE}]`);
|
|
63
|
+
if (page === null || row === null || results === null)
|
|
64
|
+
continue;
|
|
65
|
+
finders.set(page, {
|
|
66
|
+
page,
|
|
67
|
+
paths: (element.getAttribute(PALETTE_FINDER_ATTRIBUTE) ?? "").split("\n").filter(Boolean),
|
|
68
|
+
href: element.getAttribute("data-palette-finder-href") ?? "{path}",
|
|
69
|
+
limit: Number(element.getAttribute("data-palette-finder-limit") ?? "50"),
|
|
70
|
+
row,
|
|
71
|
+
results,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return finders;
|
|
75
|
+
}
|
|
76
|
+
/** The finder's link for `path`: its `{path}` placeholder filled with the URI-encoded segments. */
|
|
77
|
+
function finderHref(template, path) {
|
|
78
|
+
return template.replace("{path}", path.split("/").map(encodeURIComponent).join("/"));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Lists the finder's best matches for `query`, cloning its row per result and marking the
|
|
82
|
+
* matched characters, so each keystroke builds at most `limit` rows whatever the path count.
|
|
83
|
+
*/
|
|
84
|
+
function renderFinder(finder, query) {
|
|
85
|
+
let document = finder.results.ownerDocument;
|
|
86
|
+
let rows = fuzzyFilter(query, finder.paths, finder.limit).map((match, index) => {
|
|
87
|
+
let row = finder.row.cloneNode(true);
|
|
88
|
+
let id = `${finder.page}-result-${index}`;
|
|
89
|
+
row.id = id;
|
|
90
|
+
row.hidden = false;
|
|
91
|
+
row.setAttribute(PALETTE_ITEM_ATTRIBUTE, id);
|
|
92
|
+
row.setAttribute("data-value", match.path);
|
|
93
|
+
row.setAttribute("aria-selected", "false");
|
|
94
|
+
row.querySelector("a")?.setAttribute("href", finderHref(finder.href, match.path));
|
|
95
|
+
row.querySelector(`[${PALETTE_FINDER_PATH_ATTRIBUTE}]`)?.replaceChildren(...fuzzySegments(match.path, match.positions).map((segment) => {
|
|
96
|
+
if (!segment.match)
|
|
97
|
+
return document.createTextNode(segment.text);
|
|
98
|
+
let mark = document.createElement("mark");
|
|
99
|
+
mark.textContent = segment.text;
|
|
100
|
+
return mark;
|
|
101
|
+
}));
|
|
102
|
+
return row;
|
|
103
|
+
});
|
|
104
|
+
finder.results.replaceChildren(...rows);
|
|
105
|
+
}
|
|
43
106
|
/** Reads the remembered command ids, newest first, empty when storage is unavailable. */
|
|
44
107
|
function readRemembered(key) {
|
|
45
108
|
if (key === undefined)
|
|
@@ -101,7 +164,8 @@ function attach(dialog, props, signal) {
|
|
|
101
164
|
let current = null;
|
|
102
165
|
let active = null;
|
|
103
166
|
let registry = shortcutRegistry(dialog.ownerDocument);
|
|
104
|
-
let
|
|
167
|
+
let finders = readFinders(list);
|
|
168
|
+
let items = () => [...list.querySelectorAll(`[${PALETTE_ITEM_ATTRIBUTE}]`)].filter((item) => item.closest("template") === null);
|
|
105
169
|
let visible = () => items().filter((item) => item.closest("[hidden]") === null);
|
|
106
170
|
let setActive = (item) => {
|
|
107
171
|
active = item;
|
|
@@ -112,6 +176,9 @@ function attach(dialog, props, signal) {
|
|
|
112
176
|
};
|
|
113
177
|
let apply = () => {
|
|
114
178
|
let tokens = foldSearchText(input.value).split(/\s+/).filter(Boolean);
|
|
179
|
+
let finder = current === null ? undefined : finders.get(current);
|
|
180
|
+
if (finder !== undefined)
|
|
181
|
+
renderFinder(finder, input.value);
|
|
115
182
|
for (let child of list.children) {
|
|
116
183
|
if (!(child instanceof HTMLElement) || child === recentGroup)
|
|
117
184
|
continue;
|
|
@@ -121,6 +188,8 @@ function attach(dialog, props, signal) {
|
|
|
121
188
|
for (let item of items()) {
|
|
122
189
|
if (item.hasAttribute(PALETTE_CLONE_ATTRIBUTE) || pageOf(item) !== current)
|
|
123
190
|
continue;
|
|
191
|
+
if (item.closest(`[${PALETTE_FINDER_ATTRIBUTE}]`) !== null)
|
|
192
|
+
continue;
|
|
124
193
|
let haystack = foldSearchText(`${item.getAttribute("data-value") ?? ""} ${item.getAttribute("data-keywords") ?? ""}`);
|
|
125
194
|
item.hidden = !tokens.every((token) => haystack.includes(token));
|
|
126
195
|
}
|
|
@@ -212,7 +281,8 @@ function attach(dialog, props, signal) {
|
|
|
212
281
|
return push(page);
|
|
213
282
|
}
|
|
214
283
|
let id = control.closest(`[${PALETTE_ITEM_ATTRIBUTE}]`)?.getAttribute(PALETTE_ITEM_ATTRIBUTE);
|
|
215
|
-
|
|
284
|
+
let isFinderRow = control.closest(`[${PALETTE_FINDER_ATTRIBUTE}]`) !== null;
|
|
285
|
+
if (id != null && !isFinderRow)
|
|
216
286
|
remember(props.remember, id);
|
|
217
287
|
dialog.close();
|
|
218
288
|
}, { signal });
|
|
@@ -258,6 +328,24 @@ function attach(dialog, props, signal) {
|
|
|
258
328
|
},
|
|
259
329
|
signal,
|
|
260
330
|
});
|
|
331
|
+
for (let page of list.querySelectorAll(`[${PALETTE_PAGE_SHORTCUT_ATTRIBUTE}]`)) {
|
|
332
|
+
let id = page.getAttribute(PALETTE_PAGE_ATTRIBUTE);
|
|
333
|
+
let keys = page.getAttribute(PALETTE_PAGE_SHORTCUT_ATTRIBUTE);
|
|
334
|
+
if (id === null || keys === null || keys === "")
|
|
335
|
+
continue;
|
|
336
|
+
registry.register({
|
|
337
|
+
keys,
|
|
338
|
+
label: page.getAttribute("data-palette-title") ?? undefined,
|
|
339
|
+
run: () => {
|
|
340
|
+
if (!dialog.open)
|
|
341
|
+
dialog.showModal();
|
|
342
|
+
stack = [{ page: null, query: "" }];
|
|
343
|
+
showPage(id, "");
|
|
344
|
+
return true;
|
|
345
|
+
},
|
|
346
|
+
signal,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
261
349
|
for (let item of items()) {
|
|
262
350
|
let keys = item.getAttribute("data-palette-shortcut");
|
|
263
351
|
if (keys === null || item.hasAttribute(PALETTE_CLONE_ATTRIBUTE))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: one shared tooltip that follows the hovered or focused day, and arrow keys that move
|
|
3
|
+
* one roving Tab stop through a contribution graph, both need listeners. No-JS baseline: each day
|
|
4
|
+
* carries a `title` with its count, and the newest day is the graph's one Tab stop.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { MixinFactory } from "remix/component";
|
|
10
|
+
/**
|
|
11
|
+
* Runs a contribution graph from the island inside it: the host is the graph's shared tooltip
|
|
12
|
+
* (a manual popover), which shows the hovered or focused day's label anchored to that day, and
|
|
13
|
+
* the arrows, Home and End walk the days with a roving Tab stop. Each day's `title` is removed
|
|
14
|
+
* once this runs, so the browser's own tooltip never doubles the shared one.
|
|
15
|
+
*
|
|
16
|
+
* @param anchor The CSS anchor name the tooltip positions against, unique to the graph.
|
|
17
|
+
* @example <div popover="manual" mix={[contributionGraphKeys("--ui-contribution-graph-r1")]} />
|
|
18
|
+
*/
|
|
19
|
+
export declare const contributionGraphKeys: MixinFactory<HTMLElement, [anchor: string]>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why JS: one shared tooltip that follows the hovered or focused day, and arrow keys that move
|
|
3
|
+
* one roving Tab stop through a contribution graph, both need listeners. No-JS baseline: each day
|
|
4
|
+
* carries a `title` with its count, and the newest day is the graph's one Tab stop.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { createMixin } from "remix/component";
|
|
10
|
+
import { focusItem, setRovingTabindex } from "../../utils/keyboard-nav.js";
|
|
11
|
+
/** The graph the mixin serves when its host sits inside one. */
|
|
12
|
+
const GRAPH_SELECTOR = '[data-slot="contribution-graph"]';
|
|
13
|
+
/** One focusable day: the cell itself, or the link filling it. */
|
|
14
|
+
const DAY_SELECTOR = '[data-slot="contribution-graph-day"]';
|
|
15
|
+
/**
|
|
16
|
+
* Picks the day a key moves focus to: ←/→ a week (mirrored right to left), ↑/↓ a weekday,
|
|
17
|
+
* Home and End the row's first and last day, Ctrl+Home and Ctrl+End the first and last day of
|
|
18
|
+
* the range. A move onto a cell outside the range goes nowhere.
|
|
19
|
+
*
|
|
20
|
+
* @param key The pressed key.
|
|
21
|
+
* @param ctrl Whether Ctrl or Meta is held.
|
|
22
|
+
* @param from The focused day's week (column) and weekday (row).
|
|
23
|
+
* @param at Looks up the day at a week and weekday, `undefined` outside the range.
|
|
24
|
+
* @param days Every day, in document order (weekday by weekday).
|
|
25
|
+
* @param rtl Whether the graph lays out right to left.
|
|
26
|
+
* @returns The day to focus, or `undefined` for a key the graph leaves alone.
|
|
27
|
+
*/
|
|
28
|
+
function targetDay(key, ctrl, from, at, days, rtl) {
|
|
29
|
+
let step = rtl ? -1 : 1;
|
|
30
|
+
switch (key) {
|
|
31
|
+
case "ArrowRight":
|
|
32
|
+
return at(from.week + step, from.row) ?? at(from.week, from.row);
|
|
33
|
+
case "ArrowLeft":
|
|
34
|
+
return at(from.week - step, from.row) ?? at(from.week, from.row);
|
|
35
|
+
case "ArrowDown":
|
|
36
|
+
return at(from.week, from.row + 1) ?? at(from.week, from.row);
|
|
37
|
+
case "ArrowUp":
|
|
38
|
+
return at(from.week, from.row - 1) ?? at(from.week, from.row);
|
|
39
|
+
case "Home":
|
|
40
|
+
if (ctrl)
|
|
41
|
+
return byDate(days)[0];
|
|
42
|
+
return days.find((day) => position(day).row === from.row);
|
|
43
|
+
case "End":
|
|
44
|
+
if (ctrl)
|
|
45
|
+
return byDate(days).at(-1);
|
|
46
|
+
return days.filter((day) => position(day).row === from.row).at(-1);
|
|
47
|
+
default:
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Orders days by date, since the table lists them weekday by weekday.
|
|
53
|
+
*
|
|
54
|
+
* @param days The days in document order.
|
|
55
|
+
* @returns A copy, earliest first.
|
|
56
|
+
*/
|
|
57
|
+
function byDate(days) {
|
|
58
|
+
return [...days].sort((a, b) => (a.dataset.date ?? "").localeCompare(b.dataset.date ?? ""));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reads a day's week and weekday from the attributes the server writes.
|
|
62
|
+
*
|
|
63
|
+
* @param day A focusable day.
|
|
64
|
+
* @returns Its column and row in the grid.
|
|
65
|
+
*/
|
|
66
|
+
function position(day) {
|
|
67
|
+
return { week: Number(day.dataset.week), row: Number(day.dataset.row) };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Runs a contribution graph from the island inside it: the host is the graph's shared tooltip
|
|
71
|
+
* (a manual popover), which shows the hovered or focused day's label anchored to that day, and
|
|
72
|
+
* the arrows, Home and End walk the days with a roving Tab stop. Each day's `title` is removed
|
|
73
|
+
* once this runs, so the browser's own tooltip never doubles the shared one.
|
|
74
|
+
*
|
|
75
|
+
* @param anchor The CSS anchor name the tooltip positions against, unique to the graph.
|
|
76
|
+
* @example <div popover="manual" mix={[contributionGraphKeys("--ui-contribution-graph-r1")]} />
|
|
77
|
+
*/
|
|
78
|
+
export const contributionGraphKeys = createMixin((handle) => {
|
|
79
|
+
let anchor = "";
|
|
80
|
+
let controller;
|
|
81
|
+
handle.addEventListener("insert", (event) => {
|
|
82
|
+
controller?.abort();
|
|
83
|
+
controller = new AbortController();
|
|
84
|
+
let signal = controller.signal;
|
|
85
|
+
let tooltip = event.node;
|
|
86
|
+
let graph = tooltip.closest(GRAPH_SELECTOR);
|
|
87
|
+
if (!graph)
|
|
88
|
+
return;
|
|
89
|
+
let days = () => [...graph.querySelectorAll(DAY_SELECTOR)];
|
|
90
|
+
let current;
|
|
91
|
+
for (let day of days())
|
|
92
|
+
day.removeAttribute("title");
|
|
93
|
+
tooltip.style.setProperty("position-anchor", anchor);
|
|
94
|
+
/** Shows the tooltip over `day`, moving the anchor name onto it. */
|
|
95
|
+
let show = (day) => {
|
|
96
|
+
if (current && current !== day)
|
|
97
|
+
current.style.removeProperty("anchor-name");
|
|
98
|
+
current = day;
|
|
99
|
+
day.style.setProperty("anchor-name", anchor);
|
|
100
|
+
tooltip.textContent = day.getAttribute("aria-label");
|
|
101
|
+
if (!tooltip.matches(":popover-open"))
|
|
102
|
+
tooltip.showPopover();
|
|
103
|
+
};
|
|
104
|
+
/** Hides the tooltip unless the day it names still holds focus. */
|
|
105
|
+
let hide = (force = false) => {
|
|
106
|
+
if (!force && current && current === document.activeElement)
|
|
107
|
+
return;
|
|
108
|
+
if (tooltip.matches(":popover-open"))
|
|
109
|
+
tooltip.hidePopover();
|
|
110
|
+
};
|
|
111
|
+
graph.addEventListener("pointerover", (pointer) => {
|
|
112
|
+
let day = pointer.target?.closest(DAY_SELECTOR);
|
|
113
|
+
if (day && graph.contains(day))
|
|
114
|
+
show(day);
|
|
115
|
+
}, { signal });
|
|
116
|
+
graph.addEventListener("pointerout", (pointer) => {
|
|
117
|
+
let to = pointer.relatedTarget?.closest(DAY_SELECTOR);
|
|
118
|
+
if (to && graph.contains(to))
|
|
119
|
+
return;
|
|
120
|
+
hide();
|
|
121
|
+
}, { signal });
|
|
122
|
+
graph.addEventListener("focusin", (focus) => {
|
|
123
|
+
if (!(focus.target instanceof HTMLElement) || !focus.target.matches(DAY_SELECTOR))
|
|
124
|
+
return;
|
|
125
|
+
setRovingTabindex(days(), focus.target);
|
|
126
|
+
show(focus.target);
|
|
127
|
+
}, { signal });
|
|
128
|
+
graph.addEventListener("focusout", () => hide(true), { signal });
|
|
129
|
+
graph.addEventListener("keydown", (key) => {
|
|
130
|
+
if (!(key.target instanceof HTMLElement) || !key.target.matches(DAY_SELECTOR))
|
|
131
|
+
return;
|
|
132
|
+
if (key.key === "Escape") {
|
|
133
|
+
hide(true);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (key.altKey || key.shiftKey)
|
|
137
|
+
return;
|
|
138
|
+
let all = days();
|
|
139
|
+
let grid = new Map(all.map((day) => [`${day.dataset.week}:${day.dataset.row}`, day]));
|
|
140
|
+
let rtl = getComputedStyle(graph).direction === "rtl";
|
|
141
|
+
let next = targetDay(key.key, key.ctrlKey || key.metaKey, position(key.target), (week, row) => grid.get(`${week}:${row}`), all, rtl);
|
|
142
|
+
if (next === undefined)
|
|
143
|
+
return;
|
|
144
|
+
key.preventDefault();
|
|
145
|
+
focusItem(all, next);
|
|
146
|
+
}, { signal });
|
|
147
|
+
});
|
|
148
|
+
handle.addEventListener("remove", () => {
|
|
149
|
+
controller?.abort();
|
|
150
|
+
controller = undefined;
|
|
151
|
+
});
|
|
152
|
+
return (name) => {
|
|
153
|
+
anchor = name;
|
|
154
|
+
};
|
|
155
|
+
});
|