Commit d5cd988ef5
Verified · cmc ci/build: success ci/quality: success ci/test: success
Layout: unified · split
Changed files (5)
internal/web/static/app.js +42 −4
| @@ -47,9 +47,9 @@ | ||
| 47 | 47 | } |
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | // ---- 2. Copy buttons on clone & copyable blocks ---- | |
| 50 | // ---- 2. Copy buttons on clone, copyable & rendered code blocks ---- | |
| 51 | 51 | function initCopyButtons(root = document) { |
| 52 | for (const pre of root.querySelectorAll('.clone pre, pre.copyable')) { | |
| 52 | for (const pre of root.querySelectorAll('.clone pre, pre.copyable, .rendered pre')) { | |
| 53 | 53 | if (pre.dataset.copyWired) continue; |
| 54 | 54 | pre.dataset.copyWired = '1'; |
| 55 | 55 | const code = pre.querySelector('code') || pre; |
| @@ -61,7 +61,7 @@ | ||
| 61 | 61 | btn.type = 'button'; |
| 62 | 62 | btn.className = 'copybtn'; |
| 63 | 63 | btn.textContent = 'Copy'; |
| 64 | btn.setAttribute('aria-label', 'Copy command'); | |
| 64 | btn.setAttribute('aria-label', 'Copy code'); | |
| 65 | 65 | btn.addEventListener('click', async () => { |
| 66 | 66 | try { |
| 67 | 67 | await navigator.clipboard.writeText(code.textContent.trim()); |
| @@ -76,10 +76,41 @@ | ||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | // ---- 3. In-place fragment swaps (reactions, header toggles, sidebar pickers) ---- | |
| 79 | // ---- 3. In-place fragment swaps (previews, reactions, header toggles, sidebar pickers) ---- | |
| 80 | 80 | document.addEventListener('submit', async (e) => { |
| 81 | 81 | const form = e.target; |
| 82 | 82 | if (!(form instanceof HTMLFormElement) || form.method.toLowerCase() !== 'post') return; |
| 83 | ||
| 84 | // No-reload markup preview on any form with a Preview button | |
| 85 | if (e.submitter && e.submitter.name === 'preview') { | |
| 86 | e.preventDefault(); | |
| 87 | const btn = e.submitter; | |
| 88 | const data = new FormData(form); | |
| 89 | data.append('preview', btn.value || '1'); | |
| 90 | btn.disabled = true; | |
| 91 | try { | |
| 92 | const res = await fetch(form.action, { | |
| 93 | method: 'POST', | |
| 94 | body: new URLSearchParams(data), | |
| 95 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | |
| 96 | credentials: 'same-origin', | |
| 97 | }); | |
| 98 | if (!res.ok) { form.submit(); return; } | |
| 99 | const doc = new DOMParser().parseFromString(await res.text(), 'text/html'); | |
| 100 | const nextPrev = doc.querySelector('.preview'); | |
| 101 | if (!nextPrev) { showToast('Nothing to preview'); return; } | |
| 102 | const prev = form.previousElementSibling; | |
| 103 | if (prev && prev.classList.contains('preview')) prev.replaceWith(nextPrev); | |
| 104 | else form.insertAdjacentElement('beforebegin', nextPrev); | |
| 105 | initCopyButtons(nextPrev); | |
| 106 | } catch { | |
| 107 | form.submit(); | |
| 108 | } finally { | |
| 109 | btn.disabled = false; | |
| 110 | } | |
| 111 | return; | |
| 112 | } | |
| 113 | ||
| 83 | 114 | let swapSel = null; |
| 84 | 115 | if (form.classList.contains('reactions')) { |
| 85 | 116 | swapSel = 'main#content'; |
| @@ -306,6 +337,13 @@ | ||
| 306 | 337 | if (inline) inline.remove(); |
| 307 | 338 | return; |
| 308 | 339 | } |
| 340 | if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && e.target instanceof HTMLTextAreaElement && e.target.form) { | |
| 341 | e.preventDefault(); | |
| 342 | const btn = e.target.form.querySelector('button[type="submit"]:not([name="preview"]), button:not([type]):not([name="preview"])'); | |
| 343 | if (btn) e.target.form.requestSubmit(btn); | |
| 344 | else e.target.form.requestSubmit(); | |
| 345 | return; | |
| 346 | } | |
| 309 | 347 | if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { |
| 310 | 348 | e.preventDefault(); |
| 311 | 349 | openPalette(); |
internal/web/static/style.css +20
| @@ -2447,3 +2447,23 @@ article.release.setcard { | ||
| 2447 | 2447 | border-top: 1px solid var(--faint); |
| 2448 | 2448 | padding: var(--sp-5); |
| 2449 | 2449 | } |
| 2450 | ||
| 2451 | /* ---- authoring forms polish ---- */ | |
| 2452 | .meta-fields { | |
| 2453 | display: grid; | |
| 2454 | grid-template-columns: repeat(3, minmax(0, 1fr)); | |
| 2455 | gap: var(--sp-3); | |
| 2456 | margin: var(--sp-3) 0; | |
| 2457 | } | |
| 2458 | @media (max-width: 44rem) { | |
| 2459 | .meta-fields { grid-template-columns: 1fr; } | |
| 2460 | } | |
| 2461 | .commitbar { | |
| 2462 | display: flex; | |
| 2463 | align-items: center; | |
| 2464 | gap: var(--sp-2); | |
| 2465 | flex-wrap: wrap; | |
| 2466 | margin: var(--sp-3) 0 var(--sp-2); | |
| 2467 | } | |
| 2468 | .commitbar input { flex: 1 1 16rem; min-width: 0; } | |
| 2469 | .rendered .copywrap .copybtn { top: var(--sp-2); transform: none; } | |
internal/web/templates/edit.html +14 −5
| @@ -1,20 +1,29 @@ | ||
| 1 | 1 | {{define "width"}}wide{{end}} |
| 2 | 2 | {{define "title"}}edit {{.Path}} · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} |
| 3 | 3 | {{define "content"}} |
| 4 | <h1>edit {{.Repo.OwnerName}}/{{.Repo.Name}} : {{.Path}} @ {{.Ref}}</h1> | |
| 4 | <div class="pagehead"> | |
| 5 | <h1>Edit <code>{{.Path}}</code> <span class="refchip">{{.Ref}}</span></h1> | |
| 6 | <span class="grow"></span> | |
| 7 | <a class="button btn" href="/{{.Repo.OwnerName}}/{{.Repo.Name}}/blob/{{.Ref}}/{{.Path}}">Cancel</a> | |
| 8 | </div> | |
| 5 | 9 | <div class="blobgrid"> |
| 6 | 10 | {{template "filenav" .Nav}} |
| 7 | 11 | <div class="blobmain"> |
| 8 | 12 | {{if .Error}}<p class="error" role="alert">{{.Error}}</p>{{end}} |
| 9 | 13 | {{if .Blocked}}<p class="empty-note">{{.Blocked}}</p>{{else}} |
| 14 | <section class="setcard"> | |
| 10 | 15 | {{if .Creating}}<p class="meta"><code>{{.Path}}</code> does not exist on {{.Ref}}; committing creates it.</p>{{end}} |
| 11 | 16 | {{if .Draft.Is "content"}}{{template "previewblock" .Draft.HTML}}{{end}} |
| 12 | 17 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/edit/{{.Ref}}/{{.Path}}" class="editform"> |
| 13 | <p><textarea name="content" aria-label="File contents" rows="24" spellcheck="false">{{.Content}}</textarea></p> | |
| 14 | <p><input name="message" aria-label="Commit message" placeholder="commit message" value="{{.Draft.Or "content" "message" ""}}"> | |
| 15 | <button type="submit">Commit to {{.Ref}}</button>{{if .Markup}} {{template "previewbtn"}}{{end}}</p> | |
| 16 | <p class="crumbs">this commit will be unsigned and authored as {{.Viewer}}</p> | |
| 18 | <p><textarea name="content" aria-label="File contents" rows="24" spellcheck="false">{{.Content}}</textarea></p> | |
| 19 | <div class="commitbar"> | |
| 20 | <input name="message" aria-label="Commit message" placeholder="Commit message" value="{{.Draft.Or "content" "message" ""}}"> | |
| 21 | <button type="submit">Commit to {{.Ref}}</button> | |
| 22 | {{if .Markup}}{{template "previewbtn"}}{{end}} | |
| 23 | </div> | |
| 24 | <p class="crumbs">this commit will be unsigned and authored as {{.Viewer}} · ⌘↵ to commit</p> | |
| 17 | 25 | </form> |
| 26 | </section> | |
| 18 | 27 | {{end}} |
| 19 | 28 | </div> |
| 20 | 29 | </div> |
internal/web/templates/issuenew.html +19 −11
| @@ -1,20 +1,28 @@ | ||
| 1 | 1 | {{define "width"}}bounded{{end}} |
| 2 | 2 | {{define "title"}}new issue · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} |
| 3 | 3 | {{define "content"}} |
| 4 | <h1>New issue</h1> | |
| 4 | <div class="pagehead"> | |
| 5 | <h1>New issue</h1> | |
| 6 | <span class="grow"></span> | |
| 7 | <a class="button btn" href="/{{.Repo.OwnerName}}/{{.Repo.Name}}/issues">Back to issues</a> | |
| 8 | </div> | |
| 5 | 9 | {{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}} |
| 6 | {{if gt (len .Templates) 1}}<p class="meta">template: | |
| 10 | {{if gt (len .Templates) 1}}<p class="meta">Template: | |
| 7 | 11 | {{range .Templates}}{{if eq .Name $.Template}}<strong>{{.Name}}</strong>{{else}}<a href="?template={{.Name}}">{{.Name}}</a>{{end}} {{end}}</p>{{end}} |
| 12 | <section class="setcard"> | |
| 8 | 13 | {{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}} |
| 9 | 14 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/issues/new" class="commentform"> |
| 10 | <p><input type="text" name="title" aria-label="Title" placeholder="title" value="{{.Title}}" required></p> | |
| 11 | <p><textarea name="body" aria-label="Description" rows="12">{{.Body}}</textarea></p> | |
| 12 | {{template "formatpicker" .Format}} | |
| 13 | {{if .CanWrite}} | |
| 14 | <p><input type="text" name="labels" aria-label="Labels" placeholder="labels, space-separated (optional)" value="{{.Labels}}"></p> | |
| 15 | <p><input type="text" name="milestone" aria-label="Milestone" placeholder="milestone (optional)" value="{{.Milestone}}"></p> | |
| 16 | <p><input type="text" name="assignee" aria-label="Assignee" placeholder="assignees, space-separated (optional)" value="{{.Assignee}}"></p> | |
| 17 | {{end}} | |
| 18 | <p><button type="submit">Open issue</button> {{template "previewbtn"}}</p> | |
| 15 | <p><input type="text" name="title" aria-label="Title" placeholder="Title" value="{{.Title}}" required></p> | |
| 16 | <p><textarea name="body" aria-label="Description" rows="12" placeholder="Describe the issue…">{{.Body}}</textarea></p> | |
| 17 | {{template "formatpicker" .Format}} | |
| 18 | {{if .CanWrite}} | |
| 19 | <div class="meta-fields"> | |
| 20 | <input type="text" name="labels" aria-label="Labels" placeholder="labels, space-separated (optional)" value="{{.Labels}}"> | |
| 21 | <input type="text" name="milestone" aria-label="Milestone" placeholder="milestone (optional)" value="{{.Milestone}}"> | |
| 22 | <input type="text" name="assignee" aria-label="Assignee" placeholder="assignees, space-separated (optional)" value="{{.Assignee}}"> | |
| 23 | </div> | |
| 24 | {{end}} | |
| 25 | <p class="btngroup"><button type="submit">Open issue</button> {{template "previewbtn"}} <span class="meta">⌘↵ to submit</span></p> | |
| 19 | 26 | </form> |
| 27 | </section> | |
| 20 | 28 | {{end}} |
internal/web/templates/mrnew.html +22 −16
| @@ -1,26 +1,32 @@ | ||
| 1 | 1 | {{define "width"}}bounded{{end}} |
| 2 | 2 | {{define "title"}}new merge request · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} |
| 3 | 3 | {{define "content"}} |
| 4 | <h1>New merge request</h1> | |
| 4 | <div class="pagehead"> | |
| 5 | <h1>New merge request</h1> | |
| 6 | <span class="grow"></span> | |
| 7 | <a class="button btn" href="/{{.Repo.OwnerName}}/{{.Repo.Name}}/mrs">Back to merge requests</a> | |
| 8 | </div> | |
| 5 | 9 | {{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}} |
| 10 | <section class="setcard"> | |
| 6 | 11 | {{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}} |
| 7 | 12 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/mrs/new" class="commentform"> |
| 8 | <p class="branchpick"> | |
| 9 | <label for="source">Merge</label> | |
| 10 | <select id="source" name="source" required> | |
| 11 | <option value="">Choose a branch…</option> | |
| 12 | {{range .Sources}}<option value="{{.}}"{{if eq . $.Source}} selected{{end}}>{{.}}</option>{{end}} | |
| 13 | </select> | |
| 14 | <label for="target">into</label> | |
| 15 | <select id="target" name="target"> | |
| 16 | {{range .Branches}}<option value="{{.Name}}"{{if eq .Name $.Target}} selected{{end}}>{{.Name}}</option>{{end}} | |
| 17 | </select> | |
| 18 | </p> | |
| 19 | <p><input type="text" name="title" aria-label="Title" placeholder="title" value="{{.Title}}" required></p> | |
| 20 | <p><textarea name="body" aria-label="Description" rows="10" placeholder="what changes, and why">{{.Body}}</textarea></p> | |
| 21 | {{template "formatpicker" .Format}} | |
| 22 | <p><button type="submit">Open merge request</button> {{template "previewbtn"}}</p> | |
| 13 | <p class="branchpick"> | |
| 14 | <label for="source">Merge</label> | |
| 15 | <select id="source" name="source" required> | |
| 16 | <option value="">Choose a branch…</option> | |
| 17 | {{range .Sources}}<option value="{{.}}"{{if eq . $.Source}} selected{{end}}>{{.}}</option>{{end}} | |
| 18 | </select> | |
| 19 | <label for="target">into</label> | |
| 20 | <select id="target" name="target"> | |
| 21 | {{range .Branches}}<option value="{{.Name}}"{{if eq .Name $.Target}} selected{{end}}>{{.Name}}</option>{{end}} | |
| 22 | </select> | |
| 23 | </p> | |
| 24 | <p><input type="text" name="title" aria-label="Title" placeholder="Title" value="{{.Title}}" required></p> | |
| 25 | <p><textarea name="body" aria-label="Description" rows="10" placeholder="what changes, and why">{{.Body}}</textarea></p> | |
| 26 | {{template "formatpicker" .Format}} | |
| 27 | <p class="btngroup"><button type="submit">Open merge request</button> {{template "previewbtn"}} <span class="meta">⌘↵ to submit</span></p> | |
| 23 | 28 | </form> |
| 29 | </section> | |
| 24 | 30 | <p class="meta">Branches of a fork you can push to are offered as |
| 25 | 31 | <code>owner/name:branch</code>. Fork this repository to propose a change |
| 26 | 32 | without write access here: <code>gitbay repo fork {{.Repo.OwnerName}}/{{.Repo.Name}}</code></p> |