oficina / docs Public

I2: Share as a popover under its button

The editor's Share opens a panel instead of leaving for the share page.
The panel is the server's: GET /d/{sqid}/share?panel=1 from a script
(Sec-Fetch-Dest not "document") renders "docs-share-panel"; a typed or
reloaded URL still gets the page. Each control is a real form with
panel=1, whose 303 returns to the panel, so the one-time link is in the
panel the publisher sees (spec P1.1). brand/share-pop.js sends forms
with fetch and draws the answer; one request at a time, a spinner past
500ms, a switch put back on failure. Wide: a manual popover under Share
that Share does not toggle; narrow: a modal sheet. Esc returns focus to
Share or the Menu trigger.

Tests: panel only for a script's request, owner-only, redirects, the
one-time link once with no-store, the empty-address 400; engines check
in Chromium and WebKit, desk and phone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev d67f4c0a0bfb02d2e2fdb713bd9f795e3781c9e1 parent 61c24eb
12 files changed, +1,096 −5
  • fixtures/engines/share-pop.mjs +123 −0
  • internal/docs/brand/share-pop.css +315 −0
  • internal/docs/brand/share-pop.js +240 −0
  • internal/docs/fonts_engines_browser_test.go +4 −0
  • internal/docs/publish.go +1 −1
  • internal/docs/render.go +28 −1
  • internal/docs/share.go +20 −3
  • internal/docs/share_panel.go +132 −0
  • internal/docs/share_panel_test.go +158 −0
  • internal/docs/share_pop_browser_test.go +16 −0
  • internal/docs/views/share.html +55 −0
  • internal/docs/views/show.html +4 −0

CI cancelled — superseded by a newer push — run details

diff --git a/fixtures/engines/share-pop.mjs b/fixtures/engines/share-pop.mjs
new file mode 100644
index 0000000..b5318ed
--- /dev/null
+++ b/fixtures/engines/share-pop.mjs
@@ -0,0 +1,123 @@
+// fixtures/engines/share-pop.mjs — the editor's Share popover
+// (brand/share-pop.js), in Chromium and WebKit, through the real server.
+//
+// Run by internal/docs/share_pop_browser_test.go with the same
+// DOCS_ENGINES_CONFIG as first-reveal.mjs: "simple" documents owned by
+// the signed-in person, two per engine (desk and phone).
+//
+// Desk (1280px): Share opens a panel under the button without leaving
+// the page, focus in the email field; Share again changes nothing (no
+// flash: the same panel element stays); an invite lands and the person
+// is listed; the team switch and the link switch each move their rung,
+// the link's panel carrying the one-time URL; removing the person drops
+// them; a pointerdown outside closes it; Esc closes it and gives focus
+// back to Share. Phone (390px): Share is in estilo's Menu sheet, opens a
+// modal sheet, and Esc gives focus to the Menu trigger.
+
+const { chromium, webkit } = await import('playwright')
+const config = JSON.parse(process.env.DOCS_ENGINES_CONFIG)
+const pause = (ms) => new Promise((r) => setTimeout(r, ms))
+
+const failures = []
+for (const engine of [chromium, webkit]) {
+ const name = engine.name()
+ const fail = (msg) => failures.push(`${name}: ${msg}`)
+ const browser = await engine.launch({ headless: true })
+ const until = async (fn, ms = 4000) => {
+ const end = Date.now() + ms
+ while (Date.now() < end) { if (await fn()) return true; await pause(50) }
+ return fn()
+ }
+
+ // Desk.
+ {
+ const context = await browser.newContext({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 1 })
+ await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' })))
+ const page = await context.newPage()
+ const doc = config.docs.simple.shift()
+ const url = config.origin + '/d/' + doc
+ await page.goto(url)
+ await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 })
+ const share = page.locator('[estilo-bar-actions] a[href$="/share"]')
+ const panel = () => page.locator('[docs-share-pop] [docs-share-panel]')
+ const open = () => page.evaluate(() => document.querySelector('[docs-share-pop]')?.matches(':popover-open') ?? false)
+ const people = () => page.locator('[docs-share-people] li').allTextContents()
+
+ await share.click()
+ if (!(await until(async () => (await panel().count()) === 1))) fail('Share did not open the panel')
+ if (page.url() !== url) fail(`Share navigated to ${page.url()}`)
+ if (!(await until(() => page.evaluate(() => document.activeElement?.matches('[docs-share-invite] input[type=email]'))))) fail('focus is not in the email field')
+ const box = await page.locator('[docs-share-pop]').boundingBox()
+ const sbox = await share.boundingBox()
+ if (!box || box.y < sbox.y + sbox.height || Math.abs(box.x + box.width - (sbox.x + sbox.width)) > 2) fail(`the panel is not under Share, end-aligned: panel ${JSON.stringify(box)}, Share ${JSON.stringify(sbox)}`)
+
+ // Share while open: nothing (the same panel element stays).
+ await page.evaluate(() => { window.__panel = document.querySelector('[docs-share-panel]') })
+ await share.click()
+ await pause(300)
+ if (!(await open())) fail('Share while open closed the panel')
+ if (!(await page.evaluate(() => document.querySelector('[docs-share-panel]') === window.__panel))) fail('Share while open redrew the panel (a flash)')
+
+ // Invite.
+ await page.fill('[docs-share-invite] input[type=email]', 'pat@example.com')
+ await page.selectOption('[docs-share-invite] select', 'writer')
+ await page.click('[docs-share-submit]')
+ if (!(await until(async () => (await people()).some((t) => t.includes('pat@example.com'))))) fail('the invited person is not listed')
+ if (page.url() !== url) fail('the invite navigated')
+
+ // The two switches.
+ for (const [i, what] of [[0, 'team'], [1, 'link']]) {
+ const sw = page.locator('[docs-share-rung]').nth(i).locator('input[type=checkbox]')
+ const before = await sw.isChecked()
+ await page.locator('[docs-share-rung]').nth(i).locator('[rst-switch]').click()
+ const moved = await until(async () => (await page.locator('[docs-share-rung]').nth(i).locator('input[type=checkbox]').isChecked()) !== before
+ && !(await page.locator('[docs-share-pop] [aria-busy="true"]').count()))
+ if (!moved) fail(`the ${what} switch did not stay moved`)
+ }
+ // The link was just turned on (new documents are unpublished): the
+ // panel carries the URL once.
+ const link = await page.locator('[docs-share-link] input').inputValue().catch(() => '')
+ if (!/\/p\/[A-Za-z0-9_-]{16,}/.test(link)) fail(`publishing from the panel did not show the link: ${JSON.stringify(link)}`)
+
+ // Remove.
+ await page.locator('[docs-share-people] li', { hasText: 'pat@example.com' }).locator('[docs-share-remove]').click()
+ if (!(await until(async () => !(await people()).some((t) => t.includes('pat@example.com'))))) fail('removing the person did not drop them')
+
+ // Outside closes; Esc closes and returns focus to Share.
+ await page.mouse.click(640, 700)
+ if (!(await until(async () => !(await open())))) fail('a click outside did not close the panel')
+ await share.click()
+ await until(async () => (await panel().count()) === 1)
+ await page.keyboard.press('Escape')
+ if (!(await until(async () => !(await open())))) fail('Esc did not close the panel')
+ if (!(await page.evaluate(() => document.activeElement?.matches('[estilo-bar-actions] a[href$="/share"]')))) fail('Esc did not return focus to Share')
+ await context.close()
+ }
+
+ // Phone: Share is a row in estilo's Menu sheet; a modal sheet.
+ {
+ const context = await browser.newContext({ viewport: { width: 390, height: 844 }, deviceScaleFactor: 1, hasTouch: true })
+ await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' })))
+ const page = await context.newPage()
+ await page.goto(config.origin + '/d/' + config.docs.simple.shift())
+ await page.waitForSelector('[docs-text][contenteditable="true"]', { timeout: 30000 })
+ await page.click('[estilo-bar-more] > summary')
+ await page.click('[estilo-bar-more] a[href$="/share"]')
+ const modal = await until(() => page.evaluate(() => { const d = document.querySelector('[docs-share-pop]'); return !!d && d.open && !d.hasAttribute('popover') && !!d.querySelector('[docs-share-panel]') }))
+ if (!modal) fail('on a phone, Share in the Menu sheet did not open the modal sheet')
+ if (await page.evaluate(() => document.querySelector('[estilo-bar-more]').open)) fail('the Menu sheet stayed open under the share sheet')
+ const [w, vw] = await page.evaluate(() => [document.querySelector('[docs-share-pop]').getBoundingClientRect().width, innerWidth])
+ if (Math.abs(w - vw) > 1) fail(`the phone sheet is ${w}px wide, want the full ${vw}`)
+ await page.keyboard.press('Escape')
+ if (!(await until(() => page.evaluate(() => !document.querySelector('[docs-share-pop]').open)))) fail('Esc did not close the phone sheet')
+ if (!(await page.evaluate(() => document.activeElement?.matches('[estilo-bar-more] > summary')))) fail('Esc did not return focus to the Menu trigger')
+ await context.close()
+ }
+ await browser.close()
+}
+
+if (failures.length) {
+ for (const f of failures) console.log('FAIL ' + f)
+ process.exit(1)
+}
+console.log('ok: the Share popover opens, invites, switches, removes and closes, desk and phone, in both engines')
diff --git a/internal/docs/brand/share-pop.css b/internal/docs/brand/share-pop.css
new file mode 100644
index 0000000..c86b31d
--- /dev/null
+++ b/internal/docs/brand/share-pop.css
@@ -0,0 +1,315 @@
+/* share-pop.css: the editor's Share popover (brand/share-pop.js) and the
+ panel the server renders into it ("docs-share-panel", views/share.html).
+ From 36rem a panel under the Share button, 420px wide; below that a
+ full-width sheet from the top, opened as a modal dialog. Values from
+ the I2 mock-up (design/editor-looks, looks.css). */
+[docs-share-pop] {
+ position: fixed;
+ inset: auto;
+ margin: 0;
+ box-sizing: border-box;
+ inline-size: min(420px, calc(100vw - 16px));
+ max-block-size: calc(100dvh - var(--estilo-bar-block-size, 52px) - 24px);
+ overflow: auto;
+ padding: 14px 16px 16px;
+ border: 1px solid var(--rst-line);
+ border-radius: 14px;
+ background: var(--rst-surface);
+ color: var(--rst-text);
+ box-shadow: 0 2px 4px rgb(23 32 60 / 0.06), 0 24px 48px -16px rgb(23 32 60 / 0.35);
+ font-size: 13px;
+}
+[docs-share-pop][aria-busy="true"] {
+ min-block-size: 120px;
+}
+@media (prefers-reduced-motion: no-preference) {
+ [docs-share-pop]:popover-open,
+ [docs-share-pop][open] {
+ animation: docs-share-in 140ms cubic-bezier(.2, .7, .3, 1);
+ }
+}
+@keyframes docs-share-in {
+ from { opacity: 0; translate: 0 -4px; }
+}
+/* The phone sheet: a modal dialog across the top. */
+@media (max-width: 35.99rem) {
+ [docs-share-pop] {
+ inset-block-start: 0;
+ inset-inline: 0;
+ /* 100vw, not 100%: Chromium resolves a modal dialog's 100% against
+ the body's box, a classic scrollbar narrower than the screen. */
+ inline-size: 100vw;
+ max-inline-size: 100vw;
+ max-block-size: 100dvh;
+ border-radius: 0 0 14px 14px;
+ border-block-start: 0;
+ }
+ [docs-share-pop]::backdrop {
+ background: rgb(15 18 25 / 0.35);
+ }
+}
+@media print {
+ [docs-share-pop] { display: none !important; }
+}
+
+[docs-share-head] {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ margin-block-end: 12px;
+}
+[docs-share-head] h2 {
+ margin: 0;
+ font-size: 15px;
+ font-weight: 650;
+ letter-spacing: -0.01em;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+[docs-share-close],
+[docs-share-remove] {
+ display: grid;
+ place-items: center;
+ flex: none;
+ inline-size: 28px;
+ block-size: 28px;
+ padding: 0;
+ border: 0;
+ border-radius: 999px;
+ background: none;
+ color: var(--rst-text-muted);
+ cursor: pointer;
+}
+[docs-share-close]:hover,
+[docs-share-remove]:hover {
+ background: var(--rst-surface-2);
+ color: var(--rst-text);
+}
+[docs-share-error] {
+ margin: 0 0 10px;
+ padding: 8px 10px;
+ border-radius: 8px;
+ background: var(--rst-tone-negative-bg);
+ color: var(--rst-tone-negative-fg);
+ font-size: 12.5px;
+}
+[docs-share-invite] {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ margin: 0;
+ padding-block: 3px;
+ padding-inline: 10px 3px;
+ border: 1px solid var(--rst-line-strong);
+ border-radius: 10px;
+ background: var(--rst-surface);
+}
+[docs-share-invite]:focus-within {
+ border-color: var(--rst-accent);
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--rst-accent) 20%, transparent);
+}
+[docs-share-invite] input {
+ flex: 1 1 auto;
+ min-inline-size: 0;
+ block-size: 30px;
+ padding: 0;
+ border: 0;
+ outline: 0;
+ background: none;
+ font: 13px var(--rst-font, system-ui), sans-serif;
+ color: var(--rst-text);
+}
+[docs-share-invite] select {
+ flex: none;
+ block-size: 28px;
+ padding-block: 0;
+ padding-inline: 8px 22px;
+ border: 0;
+ border-radius: 7px;
+ background-color: var(--rst-surface-2);
+ font: 500 12.5px var(--rst-font, system-ui), sans-serif;
+ color: var(--rst-text);
+ cursor: pointer;
+ appearance: none;
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5 5 6.5 8 3.5' fill='none' stroke='%23565c69' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
+ background-repeat: no-repeat;
+ background-position: right 7px center;
+ background-size: 10px;
+}
+[dir="rtl"] [docs-share-invite] select {
+ background-position: left 7px center;
+}
+[docs-share-submit],
+[docs-share-copy] {
+ flex: none;
+ block-size: 28px;
+ padding: 0 14px;
+ border: 0;
+ border-radius: 7px;
+ background: var(--rst-accent);
+ color: var(--rst-on-accent);
+ font: 600 13px var(--rst-font, system-ui), sans-serif;
+ cursor: pointer;
+}
+[docs-share-submit]:hover,
+[docs-share-copy]:hover {
+ background: var(--rst-accent-strong);
+}
+/* iOS zooms into any field under 16px (tokens.css's touch rule, at this
+ selector's weight; TestNoZoomOnTap). */
+@media (pointer: coarse) {
+ [docs-share-invite] input,
+ [docs-share-invite] select,
+ [docs-share-link] input {
+ font-size: max(1rem, 1em);
+ }
+ [docs-share-close],
+ [docs-share-remove] {
+ inline-size: 32px;
+ block-size: 32px;
+ }
+}
+[docs-share-panel] h3 {
+ margin: 16px 0 6px;
+ font-size: 11px;
+ font-weight: 650;
+ color: var(--rst-text-muted);
+ letter-spacing: 0.01em;
+}
+[docs-share-people] {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+[docs-share-people] li {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ min-block-size: 36px;
+}
+[docs-share-people] form {
+ display: contents;
+}
+[docs-share-avatar] {
+ display: grid;
+ place-items: center;
+ flex: none;
+ inline-size: 26px;
+ block-size: 26px;
+ border-radius: 999px;
+ background: var(--rst-surface-2);
+ color: var(--rst-text-muted);
+ font-size: 12px;
+ font-weight: 650;
+}
+[docs-share-avatar][data-me] {
+ background: var(--rst-accent-soft);
+ color: var(--rst-accent);
+}
+[docs-share-name] {
+ flex: 1 1 auto;
+ min-inline-size: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+[docs-share-name] em {
+ font-style: normal;
+ color: var(--rst-text-muted);
+}
+[docs-share-access] {
+ flex: none;
+ font-size: 12.5px;
+ color: var(--rst-text-muted);
+}
+[docs-share-general] {
+ display: grid;
+ gap: 4px;
+}
+[docs-share-rung] {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ min-block-size: 44px;
+ margin: 0;
+}
+[docs-share-icon] {
+ display: grid;
+ place-items: center;
+ flex: none;
+ inline-size: 26px;
+ block-size: 26px;
+ border-radius: 8px;
+ background: var(--rst-surface-2);
+ color: var(--rst-text-muted);
+}
+[docs-share-icon] svg {
+ inline-size: 16px;
+ block-size: 16px;
+}
+[docs-share-rung-text] {
+ flex: 1 1 auto;
+ min-inline-size: 0;
+ display: grid;
+ gap: 1px;
+}
+[docs-share-rung-text] strong {
+ font-size: 13px;
+ font-weight: 600;
+}
+[docs-share-rung-text] small {
+ font-size: 12px;
+ color: var(--rst-text-muted);
+}
+[docs-share-switch] {
+ flex: none;
+ margin: 0;
+}
+/* A request past 500ms: the control it came from says so. */
+[docs-share-pop] [aria-busy="true"] {
+ opacity: 0.6;
+ cursor: progress;
+}
+[docs-sr] {
+ position: absolute;
+ inline-size: 1px;
+ block-size: 1px;
+ overflow: hidden;
+ clip-path: inset(50%);
+ white-space: nowrap;
+}
+[docs-share-link] {
+ display: flex;
+ gap: 6px;
+ margin-block-start: 6px;
+}
+[docs-share-link] input {
+ flex: 1 1 auto;
+ min-inline-size: 0;
+ block-size: 30px;
+ padding: 0 10px;
+ border: 1px solid var(--rst-line);
+ border-radius: 8px;
+ background: var(--rst-surface-2);
+ font: 12.5px var(--rst-font, system-ui), sans-serif;
+ color: var(--rst-text);
+}
+[docs-share-link] [docs-share-copy] {
+ block-size: 32px;
+}
+[docs-share-once] {
+ margin: 6px 0 0;
+ font-size: 12px;
+ color: var(--rst-text-muted);
+}
+[docs-share-once] button {
+ padding: 0;
+ border: 0;
+ background: none;
+ color: var(--rst-accent);
+ font: inherit;
+ cursor: pointer;
+ text-decoration: underline;
+}
diff --git a/internal/docs/brand/share-pop.js b/internal/docs/brand/share-pop.js
new file mode 100644
index 0000000..7298964
--- /dev/null
+++ b/internal/docs/brand/share-pop.js
@@ -0,0 +1,240 @@
+/* share-pop.js: the editor's Share as a popover under its button rather
+ than a page of its own (spec 2026-11-11-editor-i2-design.md, "Share as
+ a popover", and its revision 2).
+
+ The panel is the server's: GET /d/{sqid}/share?panel=1 from a script
+ answers "docs-share-panel" (share_panel.go), every control in it a
+ real form with panel=1. A submit is sent with fetch, and the answer,
+ which the 303 brings back to the panel, replaces the panel. Nothing is
+ composed here, so the server stays the one authority and the share
+ page stays the way in with no script.
+
+ Wide (36rem and up): a manual popover under the button. A pointerdown
+ outside closes it, except on Share, which does nothing while it is
+ open (Paul: "should do nothing. It's causing a flash"). Narrow: a
+ modal dialog across the top, which keeps focus inside it. Esc closes
+ either and returns focus to Share, or to the Menu trigger when Share
+ was a row in estilo's Menu sheet.
+
+ Busy: one request at a time; a second submit while one is out is
+ refused, and a switch flipped then goes back. A request past 500ms
+ marks its control aria-busy (the GET rule's shape; Paul ruled the busy
+ hold is for POSTs a page makes, and these redraw a panel). A failure
+ puts the switch back and says so in the panel. */
+(function () {
+ "use strict";
+ var bar = document.querySelector("[estilo-bar]");
+ if (!bar || !window.fetch || !window.DOMParser) return;
+ var links = bar.querySelectorAll('a[href$="/share"]');
+ if (!links.length) return;
+ var href = links[0].getAttribute("href");
+
+ var pop = document.createElement("dialog");
+ pop.setAttribute("docs-share-pop", "");
+ pop.setAttribute("aria-labelledby", "docs-share-heading");
+ document.body.appendChild(pop);
+
+ var narrow = window.matchMedia("(max-width: 35.99rem)");
+ var canPopover = typeof pop.showPopover === "function";
+ var opener = null;
+ var busy = false;
+ var drawn = false;
+
+ var isOpen = function () {
+ return pop.open || (canPopover && pop.hasAttribute("popover") && pop.matches(":popover-open"));
+ };
+
+ // Under the bar, its inline end on the button's. Placed, then measured
+ // and corrected: what an inset is measured from (the viewport with or
+ // without a classic scrollbar, in the top layer) differs by engine, so
+ // the panel's own box is the one reading that is right everywhere.
+ var place = function () {
+ var b = bar.getBoundingClientRect();
+ var r = opener.getBoundingClientRect();
+ var rtl = getComputedStyle(document.documentElement).direction === "rtl";
+ pop.style.insetBlockStart = Math.round(b.bottom + 6) + "px";
+ var end = rtl ? r.left : document.documentElement.clientWidth - r.right;
+ pop.style.insetInlineEnd = Math.max(8, Math.round(end)) + "px";
+ if (!isOpen()) return;
+ var p = pop.getBoundingClientRect();
+ var off = rtl ? p.left - r.left : r.right - p.right;
+ if (Math.abs(off) >= 1) pop.style.insetInlineEnd = Math.max(8, Math.round(end - off)) + "px";
+ };
+
+ var show = function () {
+ if (!narrow.matches && canPopover) {
+ pop.setAttribute("popover", "manual");
+ place();
+ pop.showPopover();
+ place();
+ } else {
+ pop.removeAttribute("popover");
+ pop.style.insetBlockStart = "";
+ pop.style.insetInlineEnd = "";
+ pop.showModal();
+ }
+ };
+
+ var close = function (restore) {
+ if (!isOpen()) return;
+ if (pop.hasAttribute("popover")) pop.hidePopover();
+ else pop.close();
+ if (restore && opener && opener.isConnected) opener.focus({ preventScroll: true });
+ };
+
+ var failed = function () {
+ var panel = pop.querySelector("[docs-share-panel]");
+ var text = panel ? panel.getAttribute("data-failed") : "";
+ var old = pop.querySelector("[docs-share-error]");
+ if (old) old.remove();
+ var p = document.createElement("p");
+ p.setAttribute("docs-share-error", "");
+ p.setAttribute("role", "alert");
+ p.textContent = text;
+ var head = pop.querySelector("[docs-share-head]");
+ if (head) head.after(p);
+ else pop.replaceChildren(p);
+ };
+
+ // The panel from an answer; anything else (a 404, a sign-in page, a
+ // proxy's error) is a failure, not something to draw.
+ var load = function (url, init) {
+ return fetch(url, Object.assign({ credentials: "same-origin", headers: { Accept: "text/html" } }, init || {}))
+ .then(function (r) {
+ return r.text();
+ })
+ .then(function (text) {
+ var doc = new DOMParser().parseFromString(text, "text/html");
+ var panel = doc.querySelector("[docs-share-panel]");
+ if (!panel) throw new Error("no panel");
+ pop.replaceChildren(document.importNode(panel, true));
+ pop.removeAttribute("aria-busy");
+ });
+ };
+
+ // Which control to give focus back to after a redraw: the same form's,
+ // found again by its action and address.
+ var keyOf = function (form) {
+ var a = form.querySelector('input[name="address"][type="hidden"]');
+ return form.getAttribute("action") + "|" + (a ? a.value : "") + "|" + (form.hasAttribute("docs-share-invite") ? "invite" : "");
+ };
+ var focusKey = function (key) {
+ var forms = pop.querySelectorAll("form");
+ for (var i = 0; i < forms.length; i++) {
+ if (keyOf(forms[i]) === key) {
+ var c = forms[i].hasAttribute("docs-share-invite") ? forms[i].querySelector('input[type="email"]') : forms[i].querySelector("input[type=checkbox], button");
+ if (c) { c.focus({ preventScroll: true }); return; }
+ }
+ }
+ var email = pop.querySelector('[docs-share-invite] input[type="email"]');
+ if (email) email.focus({ preventScroll: true });
+ };
+
+ var open = function (from) {
+ if (isOpen()) return;
+ opener = from;
+ var more = from.closest("details[estilo-bar-more]");
+ if (more) {
+ more.open = false;
+ opener = more.querySelector("summary") || from;
+ }
+ drawn = false;
+ pop.replaceChildren();
+ pop.setAttribute("aria-busy", "true");
+ show();
+ load(href + "?panel=1")
+ .then(function () {
+ drawn = true;
+ var email = pop.querySelector('[docs-share-invite] input[type="email"]');
+ if (email) email.focus({ preventScroll: true });
+ })
+ .catch(failed);
+ };
+
+ Array.prototype.forEach.call(links, function (a) {
+ a.addEventListener("click", function (e) {
+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
+ e.preventDefault();
+ open(a);
+ });
+ });
+
+ pop.addEventListener("submit", function (e) {
+ var form = e.target;
+ e.preventDefault();
+ if (busy || !drawn) return;
+ busy = true;
+ var control = e.submitter || form.querySelector("input[type=checkbox]");
+ var timer = setTimeout(function () {
+ if (control) control.setAttribute("aria-busy", "true");
+ }, 500);
+ var key = keyOf(form);
+ var body = new URLSearchParams(new FormData(form));
+ load(form.getAttribute("action"), { method: "POST", body: body })
+ .then(function () {
+ focusKey(key);
+ })
+ .catch(function () {
+ var sw = form.querySelector("[docs-share-switch] input");
+ if (sw) sw.checked = !sw.checked;
+ if (control) control.removeAttribute("aria-busy");
+ failed();
+ })
+ .finally(function () {
+ clearTimeout(timer);
+ busy = false;
+ });
+ });
+
+ // A switch submits its rung's form; the direction is the form's own.
+ pop.addEventListener("change", function (e) {
+ var input = e.target;
+ if (!input.closest || !input.closest("[docs-share-switch]")) return;
+ if (busy) {
+ input.checked = !input.checked;
+ return;
+ }
+ if (input.form) input.form.requestSubmit();
+ });
+
+ pop.addEventListener("click", function (e) {
+ var t = e.target.closest ? e.target.closest("button") : null;
+ if (t && t.hasAttribute("docs-share-close")) {
+ close(true);
+ } else if (t && t.hasAttribute("docs-share-copy")) {
+ var input = pop.querySelector("[docs-share-link] input");
+ if (input && navigator.clipboard) {
+ navigator.clipboard.writeText(input.value).then(function () {
+ t.textContent = t.getAttribute("data-copied") || t.textContent;
+ });
+ }
+ } else if (!t && e.target === pop && pop.open && !pop.hasAttribute("popover")) {
+ // The phone sheet's backdrop: a click outside the dialog's box.
+ var r = pop.getBoundingClientRect();
+ if (e.clientY > r.bottom || e.clientY < r.top || e.clientX < r.left || e.clientX > r.right) close(true);
+ }
+ });
+
+ // The modal's own Esc: closed here so focus goes back where it came from.
+ pop.addEventListener("cancel", function (e) {
+ e.preventDefault();
+ close(true);
+ });
+
+ document.addEventListener("pointerdown", function (e) {
+ if (!isOpen() || !pop.hasAttribute("popover") || pop.contains(e.target)) return;
+ for (var i = 0; i < links.length; i++) if (links[i].contains(e.target)) return;
+ close(false);
+ });
+
+ document.addEventListener("keydown", function (e) {
+ if (e.key === "Escape" && !e.defaultPrevented && isOpen() && pop.hasAttribute("popover")) {
+ e.preventDefault();
+ close(true);
+ }
+ });
+
+ window.addEventListener("resize", function () {
+ if (isOpen() && pop.hasAttribute("popover")) place();
+ });
+})();
diff --git a/internal/docs/fonts_engines_browser_test.go b/internal/docs/fonts_engines_browser_test.go
index 56648b6..844994f 100644
--- a/internal/docs/fonts_engines_browser_test.go
+++ b/internal/docs/fonts_engines_browser_test.go
@@ -107,6 +107,10 @@ func runEnginesApp(t *testing.T, script string) (string, *docs.App, error) {
}
// The richer-UI checks (richer.mjs): one simple document and one empty
// one per engine, and the list's search.
+ if script == "share-pop.mjs" {
+ names = []string{"simple"}
+ perName["simple"] = 2 * 2
+ }
if script == "richer.mjs" {
names = []string{"simple", "empty"}
perName["simple"] = 2
diff --git a/internal/docs/publish.go b/internal/docs/publish.go
index af0f792..f5d1513 100644
--- a/internal/docs/publish.go
+++ b/internal/docs/publish.go
@@ -130,7 +130,7 @@ func (h *handlers) shareLink(w http.ResponseWriter, r *http.Request) {
nativeJSON(w, r, 200, map[string]any{"published": on, "public_url": h.oneShots.take(oneShotKey(owner, sqid))})
return
}
- http.Redirect(w, r, "/d/"+sqid+"/share", http.StatusSeeOther)
+ http.Redirect(w, r, shareBack(r, sqid), http.StatusSeeOther)
case errors.Is(err, gorm.ErrRecordNotFound):
h.fail(w, r, http.StatusNotFound, failDocument)
default:
diff --git a/internal/docs/render.go b/internal/docs/render.go
index af21658..06cb83e 100644
--- a/internal/docs/render.go
+++ b/internal/docs/render.go
@@ -134,6 +134,33 @@ var Catalog = rastrillo.Catalog{
"docs.share.public.copy": "Copy link",
"docs.share.public.copied": "Link copied.",
+ // docs.share.panel.* — the editor's Share popover (share_panel.go),
+ // the share page's state in a panel under the button. Shorter than
+ // the page's words, which stay for the page itself (no script).
+ "docs.share.panel.heading": "Share “{title}”",
+ "docs.share.panel.close": "Close",
+ "docs.share.panel.failed": "That did not work. Check your connection and try again.",
+ "docs.share.panel.invite_placeholder": "Add people by email",
+ "docs.share.panel.invite": "Invite",
+ "docs.share.panel.access": "Access",
+ "docs.share.panel.can_read": "Can read",
+ "docs.share.panel.can_edit": "Can edit",
+ "docs.share.panel.people": "People with access",
+ "docs.share.panel.general": "General access",
+ "docs.share.panel.owner": "Owner",
+ "docs.share.panel.you": "(you)",
+ "docs.share.panel.remove": "Stop sharing with {address}",
+ "docs.share.panel.team_on": "Everyone on your team can read it.",
+ "docs.share.panel.team_off": "Only you and the people above.",
+ "docs.share.panel.team_switch": "Share with your team",
+ "docs.share.panel.link_heading": "Anyone with the link",
+ "docs.share.panel.link_on": "Published. Anyone with the link can read it, without signing in.",
+ "docs.share.panel.link_off": "Off. Turn on to make a read-only link.",
+ "docs.share.panel.link_switch": "Anyone with the link can read it",
+ "docs.share.panel.once": "Copy it now: the link is shown only this once.",
+ "docs.share.panel.shown": "The link was shown when it was made.",
+ "docs.share.panel.new_link": "Make a new link",
+
// docs.public.readonly is the standing notice on the published page
// itself (views/public.html). It is there because a person arriving
// from a pasted link has no other way to know they are looking at a
@@ -794,7 +821,7 @@ func vendoredStaticFS() (fs.FS, error) {
// import page (import.go).
"static/estilo/" + googleimport.JSName(): {Data: googleimport.JS()},
}
- for _, name := range []string{"icon-32.png", "apple-touch-icon.png", "brand.css", "LICENSE.lucide", "light.css", "pointer.js", "list.js"} {
+ for _, name := range []string{"icon-32.png", "apple-touch-icon.png", "brand.css", "LICENSE.lucide", "light.css", "pointer.js", "list.js", "share-pop.js", "share-pop.css"} {
body, err := brandFS.ReadFile("brand/" + name)
if err != nil {
return nil, err
diff --git a/internal/docs/share.go b/internal/docs/share.go
index 7e6ff63..1823d64 100644
--- a/internal/docs/share.go
+++ b/internal/docs/share.go
@@ -68,6 +68,13 @@ type sharePage struct {
TeamBody string
TeamButton string
TeamDestination Visibility
+
+ // The popover's panel (share_panel.go): who is signed in, for the
+ // owner's row, its own labels, and the grants as the panel draws them.
+ Me string
+ MeInitial string
+ Panel sharePanelLabels
+ PanelGrants []sharePanelGrant
}
// roleChoice is one option card: rastrillo's choice-field reads Value,
@@ -225,6 +232,16 @@ func (h *handlers) renderShare(w http.ResponseWriter, r *http.Request, doc *Docu
if page.PublicURL != "" {
w.Header().Set("Cache-Control", "no-store")
}
+ // The same URL answers a page or the popover's panel, by who asks.
+ w.Header().Add("Vary", "Sec-Fetch-Dest")
+ if sharePanelRequest(r) {
+ h.panelData(r, &page, grants)
+ if err := h.render.fragmentStatus(w, r, "share", "docs-share-panel", page, status); err != nil {
+ h.logger.Error("docs: render share panel", "sqid", doc.Sqid, "err", err)
+ h.fail(w, r, h.internalFailureStatus(), failStatus)
+ }
+ return
+ }
if err := h.render.pageStatus(w, r, "share", page, status); err != nil {
h.logger.Error("docs: render share", "sqid", doc.Sqid, "err", err)
h.fail(w, r, h.internalFailureStatus(), failStatus)
@@ -269,7 +286,7 @@ func (h *handlers) sharePost(w http.ResponseWriter, r *http.Request) {
nativeJSON(w, r, 200, map[string]bool{"ok": true})
return
}
- http.Redirect(w, r, "/d/"+sqid+"/share", http.StatusSeeOther)
+ http.Redirect(w, r, shareBack(r, sqid), http.StatusSeeOther)
case errors.Is(err, errEmptyAddress):
// Re-render with the message rather than redirecting, so the person
// sees what was wrong beside the field they typed it into.
@@ -316,7 +333,7 @@ func (h *handlers) shareRevoke(w http.ResponseWriter, r *http.Request) {
nativeJSON(w, r, 200, map[string]bool{"ok": true})
return
}
- http.Redirect(w, r, "/d/"+sqid+"/share", http.StatusSeeOther)
+ http.Redirect(w, r, shareBack(r, sqid), http.StatusSeeOther)
}
func (h *handlers) ownerLookupFailure(w http.ResponseWriter, r *http.Request, err error) {
@@ -350,7 +367,7 @@ func (h *handlers) shareTeam(w http.ResponseWriter, r *http.Request) {
nativeJSON(w, r, 200, map[string]bool{"ok": true})
return
}
- http.Redirect(w, r, "/d/"+sqid+"/share", http.StatusSeeOther)
+ http.Redirect(w, r, shareBack(r, sqid), http.StatusSeeOther)
case errors.Is(err, errUnknownVisibility):
h.fail(w, r, http.StatusBadRequest, failStatus)
default:
diff --git a/internal/docs/share_panel.go b/internal/docs/share_panel.go
new file mode 100644
index 0000000..37c5835
--- /dev/null
+++ b/internal/docs/share_panel.go
@@ -0,0 +1,132 @@
+package docs
+
+import (
+ "bytes"
+ "fmt"
+ "net/http"
+
+ "amadan.net/oficina/estilo.git/chrome"
+ "amadan.net/rastrillo/rastrillo"
+)
+
+// The share popover (spec 2026-11-11-editor-i2-design.md, "Share as a
+// popover" and revision 2's P1.1). The editor's Share opens a panel
+// under its button instead of a page of its own. The panel is the
+// share page's state rendered as a fragment, "docs-share-panel" in
+// views/share.html, and every control in it is a real form posting to
+// the share routes as the page's do. brand/share-pop.js sends each with
+// fetch and draws the answer, which is the fragment again: the handlers
+// redirect a panel form back to ?panel=1 and the redirected GET, a fetch,
+// gets the panel. The server stays the one authority, and the script
+// composes nothing.
+//
+// The one-time public link (oneshot.go) is taken by whichever render
+// follows the publish. With the panel's redirect, that render is the
+// fragment the popover shows, so the person who published sees it.
+
+// sharePanelRequest reports whether r asks for the panel rather than
+// the page: panel=1, in the query or a POST body, and a request a
+// script made. A navigation (Sec-Fetch-Dest: document), or a client
+// that sends no Sec-Fetch-Dest at all, gets the whole page, so a typed,
+// reloaded or bookmarked ?panel=1 is never a bare fragment.
+func sharePanelRequest(r *http.Request) bool {
+ if r.FormValue("panel") != "1" {
+ return false
+ }
+ dest := r.Header.Get("Sec-Fetch-Dest")
+ return dest != "" && dest != "document"
+}
+
+// shareBack is where a share mutation's 303 goes: the panel when the
+// form came from it, otherwise the page.
+func shareBack(r *http.Request, sqid string) string {
+ if r.PostFormValue("panel") == "1" {
+ return "/d/" + sqid + "/share?panel=1"
+ }
+ return "/d/" + sqid + "/share"
+}
+
+// sharePanelLabels are the panel's own words, beside the page's.
+type sharePanelLabels struct {
+ Heading, Close, Failed string
+ InvitePlaceholder, Invite, Access string
+ CanRead, CanEdit string
+ People, General, Owner, You string
+ TeamOn, TeamOff, TeamSwitch string
+ LinkHeading, LinkOn, LinkOff string
+ LinkSwitch, Once, Shown, NewLink string
+}
+
+// sharePanelGrant is one person in the panel's list.
+type sharePanelGrant struct {
+ Address, Initial, Access, Remove string
+}
+
+// initialOf is the avatar letter for an address, estilo's rule, and a
+// question mark when it has none.
+func initialOf(address string) string {
+ if i := chrome.Initials("", address); i != "" {
+ return i
+ }
+ return "?"
+}
+
+// panelData fills page's panel fields for r.
+func (h *handlers) panelData(r *http.Request, page *sharePage, grants []*Grant) {
+ me, _ := h.viewer(r)
+ page.Me = me
+ page.MeInitial = initialOf(me)
+ page.Panel = sharePanelLabels{
+ Heading: rastrillo.Tf(r, "docs.share.panel.heading", "title", page.DocTitle),
+ Close: rastrillo.T(r, "docs.share.panel.close"),
+ Failed: rastrillo.T(r, "docs.share.panel.failed"),
+ InvitePlaceholder: rastrillo.T(r, "docs.share.panel.invite_placeholder"),
+ Invite: rastrillo.T(r, "docs.share.panel.invite"),
+ Access: rastrillo.T(r, "docs.share.panel.access"),
+ CanRead: rastrillo.T(r, "docs.share.panel.can_read"),
+ CanEdit: rastrillo.T(r, "docs.share.panel.can_edit"),
+ People: rastrillo.T(r, "docs.share.panel.people"),
+ General: rastrillo.T(r, "docs.share.panel.general"),
+ Owner: rastrillo.T(r, "docs.share.panel.owner"),
+ You: rastrillo.T(r, "docs.share.panel.you"),
+ TeamOn: rastrillo.T(r, "docs.share.panel.team_on"),
+ TeamOff: rastrillo.T(r, "docs.share.panel.team_off"),
+ TeamSwitch: rastrillo.T(r, "docs.share.panel.team_switch"),
+ LinkHeading: rastrillo.T(r, "docs.share.panel.link_heading"),
+ LinkOn: rastrillo.T(r, "docs.share.panel.link_on"),
+ LinkOff: rastrillo.T(r, "docs.share.panel.link_off"),
+ LinkSwitch: rastrillo.T(r, "docs.share.panel.link_switch"),
+ Once: rastrillo.T(r, "docs.share.panel.once"),
+ Shown: rastrillo.T(r, "docs.share.panel.shown"),
+ NewLink: rastrillo.T(r, "docs.share.panel.new_link"),
+ }
+ page.PanelGrants = make([]sharePanelGrant, 0, len(grants))
+ for _, g := range grants {
+ access := page.Panel.CanRead
+ if g.Role == RoleWriter {
+ access = page.Panel.CanEdit
+ }
+ page.PanelGrants = append(page.PanelGrants, sharePanelGrant{
+ Address: g.Subject,
+ Initial: initialOf(g.Subject),
+ Access: access,
+ Remove: rastrillo.Tf(r, "docs.share.panel.remove", "address", g.Subject),
+ })
+ }
+}
+
+// fragmentStatus renders one named template of a page, with no layout,
+// into w: the share panel. Buffered for the same reason pageStatus is.
+func (rd *renderer) fragmentStatus(w http.ResponseWriter, r *http.Request, page, name string, data any, status int) error {
+ tmpl, ok := rd.pages[page]
+ if !ok {
+ return fmt.Errorf("docs: unknown page %q", page)
+ }
+ var buf bytes.Buffer
+ if err := tmpl.ExecuteTemplate(&buf, name, data); err != nil {
+ return fmt.Errorf("docs: render %q of %q: %w", name, page, err)
+ }
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ pageHeaders(w)
+ return writeGuardedBody(w, r, status, buf.Bytes())
+}
diff --git a/internal/docs/share_panel_test.go b/internal/docs/share_panel_test.go
new file mode 100644
index 0000000..71e9863
--- /dev/null
+++ b/internal/docs/share_panel_test.go
@@ -0,0 +1,158 @@
+package docs_test
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "regexp"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/docs/internal/docs"
+)
+
+// fetchAs sends what the share popover's script sends: a fetch, so
+// Sec-Fetch-Dest is "empty", with the person's cookies. method POST
+// carries body as a form.
+func fetchAs(t *testing.T, app *docs.App, cookies []*http.Cookie, method, path, body, dest string) *httptest.ResponseRecorder {
+ t.Helper()
+ var req *http.Request
+ if method == http.MethodPost {
+ req = httptest.NewRequest(method, path, strings.NewReader(body))
+ req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Set("Origin", docs.DefaultOrigin)
+ req.Header.Set("Sec-Fetch-Site", "same-origin")
+ } else {
+ req = httptest.NewRequest(method, path, nil)
+ }
+ if dest != "" {
+ req.Header.Set("Sec-Fetch-Dest", dest)
+ }
+ for _, c := range cookies {
+ req.AddCookie(c)
+ }
+ rec := httptest.NewRecorder()
+ app.Handler().ServeHTTP(rec, req)
+ return rec
+}
+
+func isPanel(body string) bool {
+ return strings.Contains(body, "docs-share-panel") && !strings.Contains(body, "<html")
+}
+
+// ?panel=1 is the popover's panel only for a request a script made. A
+// navigation, or a client that sends no Sec-Fetch-Dest, gets the whole
+// page, so a reloaded or typed URL is never a bare fragment (spec P1.1).
+func TestSharePanelOnlyForAScriptsRequest(t *testing.T) {
+ app, _ := docs.NewForTest(t)
+ alice := signInCookies(t, app, "alice@example.com")
+ sqid := createDoc(t, app, alice, "Minutes")
+ for _, tc := range []struct {
+ dest string
+ panel bool
+ }{{"empty", true}, {"document", false}, {"", false}} {
+ rec := fetchAs(t, app, alice, http.MethodGet, "/d/"+sqid+"/share?panel=1", "", tc.dest)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("dest %q: status %d", tc.dest, rec.Code)
+ }
+ if got := isPanel(rec.Body.String()); got != tc.panel {
+ t.Errorf("Sec-Fetch-Dest %q: panel = %v, want %v", tc.dest, got, tc.panel)
+ }
+ if !strings.Contains(rec.Header().Get("Vary"), "Sec-Fetch-Dest") {
+ t.Errorf("dest %q: no Vary: Sec-Fetch-Dest on a URL that answers two ways", tc.dest)
+ }
+ }
+ // Without panel=1, a fetch still gets the page.
+ if rec := fetchAs(t, app, alice, http.MethodGet, "/d/"+sqid+"/share", "", "empty"); isPanel(rec.Body.String()) {
+ t.Error("a fetch of the share page without panel=1 got the panel")
+ }
+}
+
+// The panel is the owner's, as the page is: a writer and a stranger get
+// the 404 a document they cannot share answers.
+func TestSharePanelIsOwnerOnly(t *testing.T) {
+ app, _ := docs.NewForTest(t)
+ alice := signInCookies(t, app, "alice@example.com")
+ sqid := createPrivateDoc(t, app, alice, "Minutes")
+ if rec := post(t, app, alice, "/d/"+sqid+"/share", "address=bob@example.com&role=writer"); rec.Code != http.StatusSeeOther {
+ t.Fatalf("share: %d", rec.Code)
+ }
+ for _, who := range []string{"bob@example.com", "carol@example.com"} {
+ c := signInCookies(t, app, who)
+ rec := fetchAs(t, app, c, http.MethodGet, "/d/"+sqid+"/share?panel=1", "", "empty")
+ if rec.Code != http.StatusNotFound || isPanel(rec.Body.String()) {
+ t.Errorf("%s: status %d (panel %v), want 404", who, rec.Code, isPanel(rec.Body.String()))
+ }
+ }
+}
+
+// Each panel form's 303 comes back to the panel, and a page form's to the
+// page; the invite lands and the panel names the person.
+func TestSharePanelFormsRedirectToThePanel(t *testing.T) {
+ app, _ := docs.NewForTest(t)
+ alice := signInCookies(t, app, "alice@example.com")
+ sqid := createDoc(t, app, alice, "Minutes")
+ base := "/d/" + sqid + "/share"
+ for _, tc := range []struct{ path, body string }{
+ {base, "panel=1&address=bob@example.com&role=writer"},
+ {base + "/team", "panel=1&visibility=private"},
+ {base + "/link", "panel=1&on=1"},
+ {base + "/link", "panel=1&on=0"},
+ {base + "/revoke", "panel=1&address=bob@example.com"},
+ } {
+ rec := fetchAs(t, app, alice, http.MethodPost, tc.path, tc.body, "empty")
+ if rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != base+"?panel=1" {
+ t.Errorf("POST %s %s: %d to %q, want 303 to the panel", tc.path, tc.body, rec.Code, rec.Header().Get("Location"))
+ }
+ page := strings.Replace(tc.body, "panel=1&", "", 1)
+ if rec := post(t, app, alice, tc.path, page); rec.Header().Get("Location") != base {
+ t.Errorf("POST %s without panel: to %q, want the page", tc.path, rec.Header().Get("Location"))
+ }
+ }
+ if rec := fetchAs(t, app, alice, http.MethodPost, base, "panel=1&address=dana@example.com&role=reader", "empty"); rec.Code != http.StatusSeeOther {
+ t.Fatalf("invite: %d", rec.Code)
+ }
+ body := fetchAs(t, app, alice, http.MethodGet, base+"?panel=1", "", "empty").Body.String()
+ if !strings.Contains(body, "dana@example.com") || !strings.Contains(body, "alice@example.com") {
+ t.Error("the panel does not list the owner and the person just invited")
+ }
+}
+
+// The one-time link reaches the person who published it from the popover:
+// it is in the panel that follows, with no-store, and in no later answer,
+// page or panel (spec P1.1).
+func TestSharePanelShowsTheOneTimeLinkOnce(t *testing.T) {
+ app, _ := docs.NewForTest(t)
+ alice := signInCookies(t, app, "alice@example.com")
+ sqid := createDoc(t, app, alice, "Minutes")
+ base := "/d/" + sqid + "/share"
+ link := regexp.MustCompile(`/p/[A-Za-z0-9_-]{16,}`)
+
+ if rec := fetchAs(t, app, alice, http.MethodPost, base+"/link", "panel=1&on=1", "empty"); rec.Code != http.StatusSeeOther {
+ t.Fatalf("publish: %d", rec.Code)
+ }
+ first := fetchAs(t, app, alice, http.MethodGet, base+"?panel=1", "", "empty")
+ if !isPanel(first.Body.String()) || !link.MatchString(first.Body.String()) {
+ t.Fatal("the panel after a publish does not carry the link")
+ }
+ if cc := first.Header().Get("Cache-Control"); !strings.Contains(cc, "no-store") {
+ t.Errorf("the panel carrying the link is cacheable: Cache-Control %q", cc)
+ }
+ for _, path := range []string{base + "?panel=1", base} {
+ if rec := fetchAs(t, app, alice, http.MethodGet, path, "", "empty"); link.MatchString(rec.Body.String()) {
+ t.Errorf("GET %s after the panel showed it: the link is shown again", path)
+ }
+ }
+}
+
+// An invite with no address is answered with the panel and its message,
+// 400, when it came from the panel, as the page answers the page's.
+func TestSharePanelEmptyAddressAnswersThePanel(t *testing.T) {
+ app, _ := docs.NewForTest(t)
+ alice := signInCookies(t, app, "alice@example.com")
+ sqid := createDoc(t, app, alice, "Minutes")
+ rec := fetchAs(t, app, alice, http.MethodPost, "/d/"+sqid+"/share", "panel=1&address=&role=reader", "empty")
+ if rec.Code != http.StatusBadRequest || !isPanel(rec.Body.String()) || !strings.Contains(rec.Body.String(), "docs-share-error") {
+ t.Errorf("empty address from the panel: status %d, panel %v, error shown %v; want 400 with the panel and its error",
+ rec.Code, isPanel(rec.Body.String()), strings.Contains(rec.Body.String(), "docs-share-error"))
+ }
+}
diff --git a/internal/docs/share_pop_browser_test.go b/internal/docs/share_pop_browser_test.go
new file mode 100644
index 0000000..29814c1
--- /dev/null
+++ b/internal/docs/share_pop_browser_test.go
@@ -0,0 +1,16 @@
+//go:build browser
+
+package docs_test
+
+import "testing"
+
+// The editor's Share popover in Chromium and WebKit
+// (fixtures/engines/share-pop.mjs): opens under Share without leaving the
+// page; Share while open does nothing; invite, both switches and remove
+// redraw it from the server; outside and Esc close it; on a phone it is a
+// modal sheet opened from the Menu sheet.
+func TestEnginesSharePopover(t *testing.T) {
+ if out, err := runEngines(t, "share-pop.mjs"); err != nil {
+ t.Fatalf("the Share popover failed in an engine: %v\n%s", err, out)
+ }
+}
diff --git a/internal/docs/views/share.html b/internal/docs/views/share.html
index 153cf23..a4c3456 100644
--- a/internal/docs/views/share.html
+++ b/internal/docs/views/share.html
@@ -205,3 +205,58 @@
</article>
<script type="module" defer src="{{.ShareScript}}"></script>
{{end}}
+
+{{/* docs-share-panel: the editor's Share popover (share_panel.go). The
+ page's state as a panel, every control a real form posting to the
+ share routes with panel=1, so their 303 comes back here; the script
+ (brand/share-pop.js) sends each with fetch and draws the answer. No
+ <style>: the panel's look is brand/share-pop.css, on the editor page.
+
+ The switches are rastrillo's: a checkbox in a label with its track,
+ so they click, drag (rastrillo.js) and take Space. Each sits in the
+ form that moves its rung, the direction in a hidden field as on the
+ page, and the script submits that form when it changes. */}}
+{{define "docs-share-panel"}}<div docs-share-panel data-failed="{{.Panel.Failed}}">
+ <header docs-share-head>
+ <h2 id="docs-share-heading" dir="auto">{{.Panel.Heading}}</h2>
+ <button type="button" docs-share-close aria-label="{{.Panel.Close}}"><svg viewBox="0 0 20 20" width="18" height="18" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><path d="M5 5l10 10M15 5 5 15"/></svg></button>
+ </header>
+ {{if .Error}}<p docs-share-error role="alert">{{.Error}}</p>{{end}}
+ <form docs-share-invite method="post" data-busy="false" action="/d/{{.Sqid}}/share">
+ <input type="hidden" name="panel" value="1">
+ <input type="email" name="address" required autocomplete="email" placeholder="{{.Panel.InvitePlaceholder}}" aria-label="{{.AddressLabel}}">
+ <select name="role" aria-label="{{.Panel.Access}}"><option value="reader">{{.Panel.CanRead}}</option><option value="writer">{{.Panel.CanEdit}}</option></select>
+ <button type="submit" docs-share-submit>{{.Panel.Invite}}</button>
+ </form>
+ <h3>{{.Panel.People}}</h3>
+ <ul docs-share-people>
+ <li><span docs-share-avatar data-me aria-hidden="true">{{.MeInitial}}</span><span docs-share-name dir="auto">{{.Me}} <em>{{.Panel.You}}</em></span><span docs-share-access>{{.Panel.Owner}}</span></li>
+ {{- range .PanelGrants}}
+ <li><span docs-share-avatar aria-hidden="true">{{.Initial}}</span><span docs-share-name dir="auto">{{.Address}}</span><span docs-share-access>{{.Access}}</span>
+ <form method="post" action="/d/{{$.Sqid}}/share/revoke" data-busy="false"><input type="hidden" name="panel" value="1"><input type="hidden" name="address" value="{{.Address}}"><button type="submit" docs-share-remove aria-label="{{.Remove}}" title="{{.Remove}}"><svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><path d="M6.5 6.5l7 7M13.5 6.5l-7 7"/></svg></button></form></li>
+ {{- end}}
+ </ul>
+ <h3>{{.Panel.General}}</h3>
+ <div docs-share-general>
+ <form docs-share-rung method="post" data-busy="false" action="/d/{{.Sqid}}/share/team">
+ <input type="hidden" name="panel" value="1">
+ <input type="hidden" name="visibility" value="{{.TeamDestination}}">
+ <span docs-share-icon aria-hidden="true"><svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="7.5" cy="7" r="2.6"/><path d="M2.8 16c.6-2.6 2.4-4 4.7-4s4.1 1.4 4.7 4"/><circle cx="14" cy="7.6" r="2"/><path d="M13.6 11.6c1.9 0 3.2 1.1 3.7 3.4"/></svg></span>
+ <span docs-share-rung-text><strong>{{.TeamHeading}}</strong><small>{{if .Team}}{{.Panel.TeamOn}}{{else}}{{.Panel.TeamOff}}{{end}}</small></span>
+ <label rst-switch docs-share-switch><input type="checkbox" name="on"{{if .Team}} checked{{end}}><span rst-switch-track aria-hidden="true"></span><span docs-sr>{{.Panel.TeamSwitch}}</span></label>
+ </form>
+ <form docs-share-rung method="post" data-busy="false" action="/d/{{.Sqid}}/share/link">
+ <input type="hidden" name="panel" value="1">
+ <input type="hidden" name="on" value="{{if .Published}}0{{else}}1{{end}}">
+ <span docs-share-icon aria-hidden="true"><svg viewBox="0 0 20 20" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M8.6 11.4a3 3 0 0 0 4.3 0l2.4-2.4a3 3 0 0 0-4.3-4.3l-.9.9"/><path d="M11.4 8.6a3 3 0 0 0-4.3 0L4.7 11a3 3 0 0 0 4.3 4.3l.9-.9"/></svg></span>
+ <span docs-share-rung-text><strong>{{.Panel.LinkHeading}}</strong><small>{{if .Published}}{{.Panel.LinkOn}}{{else}}{{.Panel.LinkOff}}{{end}}</small></span>
+ <label rst-switch docs-share-switch><input type="checkbox" name="state"{{if .Published}} checked{{end}}><span rst-switch-track aria-hidden="true"></span><span docs-sr>{{.Panel.LinkSwitch}}</span></label>
+ </form>
+ {{if .PublicURL}}
+ <div docs-share-link><input readonly value="{{.PublicURL}}" aria-label="{{.URLLabel}}"><button type="button" docs-share-copy data-copied="{{.CopiedLabel}}">{{.CopyButton}}</button></div>
+ <p docs-share-once role="status">{{.Panel.Once}}</p>
+ {{else if .Published}}
+ <form docs-share-once method="post" data-busy="false" action="/d/{{.Sqid}}/share/link"><input type="hidden" name="panel" value="1"><input type="hidden" name="on" value="1">{{.Panel.Shown}} <button type="submit" docs-share-replace>{{.Panel.NewLink}}</button></form>
+ {{end}}
+ </div>
+</div>{{end}}
diff --git a/internal/docs/views/show.html b/internal/docs/views/show.html
index b9b6380..197af8a 100644
--- a/internal/docs/views/show.html
+++ b/internal/docs/views/show.html
@@ -1690,5 +1690,9 @@
registers with it (fixtures/fonts-gate.mjs). */}}
<script type="module" src="{{.Fonts.Script}}"></script>
{{if .CanWrite}}<script type="module" defer src="{{.EditorScript}}"></script>{{end}}
+{{/* The Share popover (brand/share-pop.js), for the owner, who alone
+ has a Share in the bar. */}}
+{{if .CanShare}}<link rel="stylesheet" href="{{asset "static/brand/share-pop.css"}}">
+<script defer src="{{asset "static/brand/share-pop.js"}}"></script>{{end}}
{{template "docs-jumpto" .}}
{{end}}