1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import (
6 "strconv"
7 "strings"
8)
9
10// OverlayHelp is the keyboard map panel; the keys of the merge request page
11// show on that page only.
12templ OverlayHelp(mr bool) {
13 <dialog id="panel-help" class="panel modal" aria-label="Keyboard shortcuts" hx-on:keydown="event.key === 'Escape' && (event.preventDefault(), this.close())" hx-on:click="event.target === this && this.close()">
14 <div class="panel-head"><h2>Keyboard shortcuts</h2><button type="button" class="panel-x" aria-label="Close" hx-on:click="closest('dialog').close()"><kbd>esc</kbd> close</button></div>
15 <div class="keys-pref">
16 <label><input type="checkbox" id="keys-off" aria-describedby="keys-note" hx-on:change="ermite.setKeysOff(this.checked)"/> Turn off single-key shortcuts</label>
17 <p id="keys-note" class="dim">Single-key shortcuts are on. ctrl k and esc work whatever this says.</p>
18 </div>
19 <dl class="keys">
20 <div><dt><kbd>ctrl k</kbd> <kbd>:</kbd></dt><dd>go to a section, branch, tag, file or repository</dd></div>
21 <div><dt><kbd>?</kbd></dt><dd>this list</dd></div>
22 <div><dt><kbd>j</kbd> <kbd>k</kbd></dt><dd>move the row cursor down / up</dd></div>
23 <div><dt><kbd>enter</kbd></dt><dd>open the row under the cursor; on Files, a directory opens or closes in place</dd></div>
24 <div><dt><kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> <kbd>→</kbd> <kbd>home</kbd> <kbd>end</kbd></dt><dd>in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file</dd></div>
25 <div><dt><kbd>l</kbd> <kbd>h</kbd></dt><dd>on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls</dd></div>
26 <div><dt><kbd>g g</kbd> <kbd>G</kbd></dt><dd>first / last row</dd></div>
27 <div><dt><kbd>/</kbd></dt><dd>filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)</dd></div>
28 <div><dt><kbd>b</kbd></dt><dd>{ "switch" } branch or tag</dd></div>
29 <div><dt><kbd>s</kbd> <kbd>t</kbd> <kbd>c</kbd> <kbd>r</kbd> <kbd>m</kbd></dt><dd>tabs: summary, files, commits, branches & tags, merge requests</dd></div>
30 <div><dt><kbd>g h</kbd></dt><dd>home</dd></div>
31 <div><dt><kbd>y</kbd></dt><dd>copy a permalink pinned to the commit</dd></div>
32 <div><dt><kbd>d</kbd> <kbd>u</kbd> <kbd>x</kbd></dt><dd>diff: split / unified / collapse or expand all</dd></div>
33 <div><dt><kbd>e</kbd> <kbd>E</kbd></dt><dd>diff: the whole file in view / every file, with the lines the hunks hide</dd></div>
34 <div><dt><kbd>n</kbd></dt><dd>merge request: next note in the diff</dd></div>
35 if mr {
36 <div><dt><kbd>g f</kbd></dt><dd>merge request: the list of files (j k move, enter opens, esc back)</dd></div>
37 <div><dt><kbd>M</kbd></dt><dd>merge request: the merge menu; there 1–3 pick the mode, D deletes the branch, enter merges</dd></div>
38 <div><dt><kbd>R</kbd></dt><dd>merge request: mark the head read</dd></div>
39 }
40 <div><dt><kbd>esc</kbd></dt><dd>close a dialog, leave a field</dd></div>
41 </dl>
42 </dialog>
43}
44
45// OverlayRefs is the ref switcher. It exists only inside a repository.
46templ OverlayRefs(l Layout) {
47 if l.Ref != "" {
48 <dialog id="panel-refs" class="panel modal" aria-label="Switch ref" hx-on:keydown="event.key === 'Escape' && (event.preventDefault(), this.close())" hx-on:click="event.target === this && this.close()">
49 <div class="panel-head">
50 <label for="refs-filter" class="sr">filter branches and tags</label>
51 <input
52 id="refs-filter"
53 type="search"
54 placeholder="Switch branch or tag…"
55 autocomplete="off"
56 data-pick="#panel-refs li"
57 hx-on:input="ermite.filter(this)"
58 />
59 <button type="button" class="panel-x" aria-label="Close" hx-on:click="closest('dialog').close()"><kbd>esc</kbd></button>
60 </div>
61 <div class="panel-cols" data-picklist>
62 <section aria-label="Branches">
63 <h2>Branches <span class="count">{ itoa(len(l.Heads)) }</span></h2>
64 <ul>
65 for _, r := range l.Heads {
66 @refItem(r)
67 }
68 </ul>
69 </section>
70 <section aria-label="Tags">
71 <h2>Tags <span class="count">{ itoa(len(l.Tags)) }</span></h2>
72 <ul>
73 for _, r := range l.Tags {
74 @refItem(r)
75 }
76 </ul>
77 </section>
78 </div>
79 </dialog>
80 }
81}
82
83templ refItem(r RefItem) {
84 <li>
85 <a
86 href={ templ.SafeURL(r.Href) }
87 if r.Current {
88 aria-current="true"
89 }
90 >
91 <span class="mark" aria-hidden="true">
92 if r.Current {
93 ●
94 } else {
95
96 }
97 </span>{ r.Name }
98 </a>
99 </li>
100}
101
102// OverlayCmd is the ":" command line: one filterable list mixing sections,
103// refs and repos.
104templ OverlayCmd(items []CmdItem) {
105 <dialog id="panel-cmd" class="panel modal" aria-label="Go to" hx-on:close="ermiteFinder.paletteClose()" hx-on:keydown="event.key === 'Escape' && (event.preventDefault(), this.close())" hx-on:click="event.target === this && this.close()">
106 <div class="panel-head">
107 <label for="cmd-q" class="sr">go to</label>
108 <input
109 id="cmd-q"
110 type="search"
111 placeholder="Go to a section, branch, tag, file or repository…"
112 autocomplete="off"
113 spellcheck="false"
114 role="combobox"
115 aria-autocomplete="list"
116 aria-expanded="true"
117 aria-controls="cmd-list"
118 aria-activedescendant="cmd-o0"
119 hx-on:input="ermite.cmdFilter(this); ermiteFinder.palette(this)"
120 hx-on:keydown="ermite.cmdKey(event)"
121 />
122 <button type="button" class="panel-x" aria-label="Close" hx-on:click="closest('dialog').close()"><kbd>esc</kbd></button>
123 </div>
124 <ul id="cmd-list" class="cmd-list" role="listbox" aria-label="Targets">
125 for i, c := range items {
126 <li id={ "cmd-o" + itoa(i) } role="option" aria-selected={ strconv.FormatBool(i == 0) } data-k={ strings.ToLower(c.Kind + " " + c.Label) } data-cursor?={ i == 0 }><a href={ templ.SafeURL(c.Href) } tabindex="-1"><span class="lbl">{ c.Label }</span><span class="k">{ c.Kind }</span></a></li>
127 }
128 <li id={ "cmd-o" + itoa(len(items)) } role="option" aria-selected="false" data-k="action turn single-key shortcuts on off keyboard"><a href="#" data-fire="keys" tabindex="-1"><span class="lbl">turn single-key shortcuts off</span><span class="k">action</span></a></li>
129 </ul>
130 <p class="panel-foot"><span><kbd>↑</kbd><kbd>↓</kbd> move</span><span><kbd>enter</kbd> open</span><span><kbd>esc</kbd> close</span></p>
131 </dialog>
132}