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 | function initCopyButtons(root = document) { | 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 | if (pre.dataset.copyWired) continue; | 53 | if (pre.dataset.copyWired) continue; |
| 54 | pre.dataset.copyWired = '1'; | 54 | pre.dataset.copyWired = '1'; |
| 55 | const code = pre.querySelector('code') || pre; | 55 | const code = pre.querySelector('code') || pre; |
| @@ -61,7 +61,7 @@ | |||
| 61 | btn.type = 'button'; | 61 | btn.type = 'button'; |
| 62 | btn.className = 'copybtn'; | 62 | btn.className = 'copybtn'; |
| 63 | btn.textContent = 'Copy'; | 63 | btn.textContent = 'Copy'; |
| 64 | btn.setAttribute('aria-label', 'Copy command'); | 64 | btn.setAttribute('aria-label', 'Copy code'); |
| 65 | btn.addEventListener('click', async () => { | 65 | btn.addEventListener('click', async () => { |
| 66 | try { | 66 | try { |
| 67 | await navigator.clipboard.writeText(code.textContent.trim()); | 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 | document.addEventListener('submit', async (e) => { | 80 | document.addEventListener('submit', async (e) => { |
| 81 | const form = e.target; | 81 | const form = e.target; |
| 82 | if (!(form instanceof HTMLFormElement) || form.method.toLowerCase() !== 'post') return; | 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 | let swapSel = null; | 114 | let swapSel = null; |
| 84 | if (form.classList.contains('reactions')) { | 115 | if (form.classList.contains('reactions')) { |
| 85 | swapSel = 'main#content'; | 116 | swapSel = 'main#content'; |
| @@ -306,6 +337,13 @@ | |||
| 306 | if (inline) inline.remove(); | 337 | if (inline) inline.remove(); |
| 307 | return; | 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 | if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { | 347 | if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') { |
| 310 | e.preventDefault(); | 348 | e.preventDefault(); |
| 311 | openPalette(); | 349 | openPalette(); |
internal/web/static/style.css +20
| @@ -2447,3 +2447,23 @@ article.release.setcard { | |||
| 2447 | border-top: 1px solid var(--faint); | 2447 | border-top: 1px solid var(--faint); |
| 2448 | padding: var(--sp-5); | 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 | {{define "width"}}wide{{end}} | 1 | {{define "width"}}wide{{end}} |
| 2 | {{define "title"}}edit {{.Path}} · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} | 2 | {{define "title"}}edit {{.Path}} · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} |
| 3 | {{define "content"}} | 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 | <div class="blobgrid"> | 9 | <div class="blobgrid"> |
| 6 | {{template "filenav" .Nav}} | 10 | {{template "filenav" .Nav}} |
| 7 | <div class="blobmain"> | 11 | <div class="blobmain"> |
| 8 | {{if .Error}}<p class="error" role="alert">{{.Error}}</p>{{end}} | 12 | {{if .Error}}<p class="error" role="alert">{{.Error}}</p>{{end}} |
| 9 | {{if .Blocked}}<p class="empty-note">{{.Blocked}}</p>{{else}} | 13 | {{if .Blocked}}<p class="empty-note">{{.Blocked}}</p>{{else}} |
| 14 | <section class="setcard"> | ||
| 10 | {{if .Creating}}<p class="meta"><code>{{.Path}}</code> does not exist on {{.Ref}}; committing creates it.</p>{{end}} | 15 | {{if .Creating}}<p class="meta"><code>{{.Path}}</code> does not exist on {{.Ref}}; committing creates it.</p>{{end}} |
| 11 | {{if .Draft.Is "content"}}{{template "previewblock" .Draft.HTML}}{{end}} | 16 | {{if .Draft.Is "content"}}{{template "previewblock" .Draft.HTML}}{{end}} |
| 12 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/edit/{{.Ref}}/{{.Path}}" class="editform"> | 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> | 18 | <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" ""}}"> | 19 | <div class="commitbar"> |
| 15 | <button type="submit">Commit to {{.Ref}}</button>{{if .Markup}} {{template "previewbtn"}}{{end}}</p> | 20 | <input name="message" aria-label="Commit message" placeholder="Commit message" value="{{.Draft.Or "content" "message" ""}}"> |
| 16 | <p class="crumbs">this commit will be unsigned and authored as {{.Viewer}}</p> | 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 | </form> | 25 | </form> |
| 26 | </section> | ||
| 18 | {{end}} | 27 | {{end}} |
| 19 | </div> | 28 | </div> |
| 20 | </div> | 29 | </div> |
internal/web/templates/issuenew.html +19 −11
| @@ -1,20 +1,28 @@ | |||
| 1 | {{define "width"}}bounded{{end}} | 1 | {{define "width"}}bounded{{end}} |
| 2 | {{define "title"}}new issue · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} | 2 | {{define "title"}}new issue · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} |
| 3 | {{define "content"}} | 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 | {{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}} | 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 | {{range .Templates}}{{if eq .Name $.Template}}<strong>{{.Name}}</strong>{{else}}<a href="?template={{.Name}}">{{.Name}}</a>{{end}} {{end}}</p>{{end}} | 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 | {{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}} | 13 | {{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}} |
| 9 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/issues/new" class="commentform"> | 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> | 15 | <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> | 16 | <p><textarea name="body" aria-label="Description" rows="12" placeholder="Describe the issue…">{{.Body}}</textarea></p> |
| 12 | {{template "formatpicker" .Format}} | 17 | {{template "formatpicker" .Format}} |
| 13 | {{if .CanWrite}} | 18 | {{if .CanWrite}} |
| 14 | <p><input type="text" name="labels" aria-label="Labels" placeholder="labels, space-separated (optional)" value="{{.Labels}}"></p> | 19 | <div class="meta-fields"> |
| 15 | <p><input type="text" name="milestone" aria-label="Milestone" placeholder="milestone (optional)" value="{{.Milestone}}"></p> | 20 | <input type="text" name="labels" aria-label="Labels" placeholder="labels, space-separated (optional)" value="{{.Labels}}"> |
| 16 | <p><input type="text" name="assignee" aria-label="Assignee" placeholder="assignees, space-separated (optional)" value="{{.Assignee}}"></p> | 21 | <input type="text" name="milestone" aria-label="Milestone" placeholder="milestone (optional)" value="{{.Milestone}}"> |
| 17 | {{end}} | 22 | <input type="text" name="assignee" aria-label="Assignee" placeholder="assignees, space-separated (optional)" value="{{.Assignee}}"> |
| 18 | <p><button type="submit">Open issue</button> {{template "previewbtn"}}</p> | 23 | </div> |
| 24 | {{end}} | ||
| 25 | <p class="btngroup"><button type="submit">Open issue</button> {{template "previewbtn"}} <span class="meta">⌘↵ to submit</span></p> | ||
| 19 | </form> | 26 | </form> |
| 27 | </section> | ||
| 20 | {{end}} | 28 | {{end}} |
internal/web/templates/mrnew.html +22 −16
| @@ -1,26 +1,32 @@ | |||
| 1 | {{define "width"}}bounded{{end}} | 1 | {{define "width"}}bounded{{end}} |
| 2 | {{define "title"}}new merge request · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} | 2 | {{define "title"}}new merge request · {{.Repo.OwnerName}}/{{.Repo.Name}}{{end}} |
| 3 | {{define "content"}} | 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 | {{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}} | 9 | {{if .Notice}}<p class="error" role="alert">{{.Notice}}</p>{{end}} |
| 10 | <section class="setcard"> | ||
| 6 | {{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}} | 11 | {{if .Draft.Is "body"}}{{template "previewblock" .Draft.HTML}}{{end}} |
| 7 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/mrs/new" class="commentform"> | 12 | <form method="post" action="/{{.Repo.OwnerName}}/{{.Repo.Name}}/mrs/new" class="commentform"> |
| 8 | <p class="branchpick"> | 13 | <p class="branchpick"> |
| 9 | <label for="source">Merge</label> | 14 | <label for="source">Merge</label> |
| 10 | <select id="source" name="source" required> | 15 | <select id="source" name="source" required> |
| 11 | <option value="">Choose a branch…</option> | 16 | <option value="">Choose a branch…</option> |
| 12 | {{range .Sources}}<option value="{{.}}"{{if eq . $.Source}} selected{{end}}>{{.}}</option>{{end}} | 17 | {{range .Sources}}<option value="{{.}}"{{if eq . $.Source}} selected{{end}}>{{.}}</option>{{end}} |
| 13 | </select> | 18 | </select> |
| 14 | <label for="target">into</label> | 19 | <label for="target">into</label> |
| 15 | <select id="target" name="target"> | 20 | <select id="target" name="target"> |
| 16 | {{range .Branches}}<option value="{{.Name}}"{{if eq .Name $.Target}} selected{{end}}>{{.Name}}</option>{{end}} | 21 | {{range .Branches}}<option value="{{.Name}}"{{if eq .Name $.Target}} selected{{end}}>{{.Name}}</option>{{end}} |
| 17 | </select> | 22 | </select> |
| 18 | </p> | 23 | </p> |
| 19 | <p><input type="text" name="title" aria-label="Title" placeholder="title" value="{{.Title}}" required></p> | 24 | <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> | 25 | <p><textarea name="body" aria-label="Description" rows="10" placeholder="what changes, and why">{{.Body}}</textarea></p> |
| 21 | {{template "formatpicker" .Format}} | 26 | {{template "formatpicker" .Format}} |
| 22 | <p><button type="submit">Open merge request</button> {{template "previewbtn"}}</p> | 27 | <p class="btngroup"><button type="submit">Open merge request</button> {{template "previewbtn"}} <span class="meta">⌘↵ to submit</span></p> |
| 23 | </form> | 28 | </form> |
| 29 | </section> | ||
| 24 | <p class="meta">Branches of a fork you can push to are offered as | 30 | <p class="meta">Branches of a fork you can push to are offered as |
| 25 | <code>owner/name:branch</code>. Fork this repository to propose a change | 31 | <code>owner/name:branch</code>. Fork this repository to propose a change |
| 26 | without write access here: <code>gitbay repo fork {{.Repo.OwnerName}}/{{.Repo.Name}}</code></p> | 32 | without write access here: <code>gitbay repo fork {{.Repo.OwnerName}}/{{.Repo.Name}}</code></p> |