oficina / sheets Public

Clone
git clone https://amadan.net/oficina/sheets

Plain git — no account needed to clone.

Download

Download this file

1{{define "head"}}
2<link rel="stylesheet" href="{{asset "static/vendor/jsuites.css"}}">
3<link rel="stylesheet" href="{{asset "static/vendor/jspreadsheet.css"}}">
4{{/* Vendored, in dependency order, and deferred so neither blocks the
5 first paint. defer preserves document order, so each module below
6 is defined before the one that calls it: live.js registers
7 window.SheetsLive and paint.js window.SheetsPaint; grid.js calls
8 both once the window has loaded; menubar.js and commands.js wire
9 the chrome and read window.SheetsGrid, which grid.js publishes. */}}
10<script defer src="{{asset "static/vendor/jsuites.js"}}"></script>
11<script defer src="{{asset "static/vendor/jspreadsheet.js"}}"></script>
12<script defer src="{{asset "static/live.js"}}"></script>
13<script defer src="{{asset "static/paint.js"}}"></script>
14<script defer src="{{asset "static/sizes.js"}}"></script>
15<script defer src="{{asset "static/autofit.js"}}"></script>
16<script defer src="{{asset "static/grid.js"}}"></script>
17<script defer src="{{asset "static/typestart.js"}}"></script>
18<script defer src="{{asset "static/menubar.js"}}"></script>
19<script defer src="{{asset "static/formulabar.js"}}"></script>
20<script defer src="{{asset "static/formulapick.js"}}"></script>
21<script defer src="{{asset "static/note.js"}}"></script>
22<script defer src="{{asset "static/tsv.js"}}"></script>
23<script defer src="{{asset "static/cellqueue.js"}}"></script>
24<script defer src="{{asset "static/clipboard.js"}}"></script>
25<script defer src="{{asset "static/commands.js"}}"></script>
26{{end}}
27
28{{/* The open sheet's title, and for anyone who may edit it the rename,
29 are the bar's (estilo's editable title slot, chrome.TitleEdit, built
30 in handleSheetPage). It is still a real form posting to
31 /sheets/{id}/rename, so Enter renames with scripting off, and the
32 Rename button is visually hidden until the field has focus. Escape
33 restores the title and leaves the field (estilo chrome.js), which
34 fixes the sticky focus look the audit found. A reader sees the
35 title read-only. */}}
36
37{{define "main"}}
38{{/* The grid gets its own <main>, without rst-page's padding and max
39 width: a spreadsheet is the one screen in this app that should fill
40 the viewport. Everything else uses the layout's default. */}}
41<main data-sheet-surface id="main"
42 data-sheet-id="{{.Data.Sheet.ID}}"
43 data-tab-id="{{.Data.Sheet.TabID}}"
44 data-rows="{{.Data.Rows}}"
45 data-cols="{{.Data.Cols}}"
46 {{/* Set when the sheet reaches past the widest grid this build
47 can paint. grid.js reads it and says so in the status line
48 rather than the page shouting at somebody who may never
49 scroll that far — but it is said, which is the point: the
50 window used to be a constant 100 rows and a cell on row 151
51 was simply not on this screen, with nothing anywhere
52 admitting a window existed. */}}
53 {{if .Data.Truncated}}data-window-truncated="1"{{end}}
54 {{if .Data.MayWrite}}data-may-write="1"{{end}}
55 {{/* The chords clipboard.js names when a browser refuses a menu
56 copy, cut or paste ("Press ⌘C instead"), in this request's
57 platform's spelling, so its status line agrees with the menu. */}}
58 data-key-copy="{{.Frame.Keys.copy}}" data-key-cut="{{.Frame.Keys.cut}}" data-key-paste="{{.Frame.Keys.paste}}">
59{{template "content" .}}
60</main>
61{{end}}
62
63{{/* --- Glyphs -------------------------------------------------------
64
65 Written here rather than fetched with {{icon}}. rastrillo vendors
66 twelve Lucide slugs — alert-triangle, check, check-circle,
67 chevron-down, help-circle, info, kebab, menu, plus, search, x,
68 x-circle — and rastrillo.Icon returns an EMPTY STRING for a slug it
69 does not have, with no error. So {{icon "bold"}} is not a missing
70 icon, it is a button with no label and no complaint, which is the
71 same silent-failure shape as an invented CSS token.
72
73 Bold and italic are letters, because that is what they are on every
74 spreadsheet anybody has used. The three alignments are rules,
75 because "left" as a word is longer than the button. */}}
76
77{{define "glyph-align-left"}}<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M2 3.5h12M2 6.5h7M2 9.5h12M2 12.5h7"/></svg>{{end}}
78{{define "glyph-align-center"}}<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M2 3.5h12M4.5 6.5h7M2 9.5h12M4.5 12.5h7"/></svg>{{end}}
79{{define "glyph-align-right"}}<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M2 3.5h12M7 6.5h7M2 9.5h12M7 12.5h7"/></svg>{{end}}
80{{define "glyph-undo"}}<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M3 8h7a3 3 0 0 1 0 6H6M3 8l3-3M3 8l3 3"/></svg>{{end}}
81
82{{define "content"}}
83
84{{/* Row B — the menu bar and the toolbar share one row.
85 Six short words are about 300px; a row holding only them wastes
86 two-thirds of itself. They wrap onto separate rows below ~900px,
87 which is also what keeps the chrome inside the 320px reflow
88 budget. */}}
89<div data-chrome>
90
91<nav estilo-menubar data-menubar aria-label="Sheet menu">
92
93{{/* estilo's menu bar ([estilo-menubar], estilo menu.css): square titles
94 in the page flow, 9px floating panels with inset rows, a shortcut
95 column, and the platform's own labels (⌘Z on a Mac, Ctrl+Z
96 elsewhere) from estilo's menu.Shortcut, formatted server-side.
97
98 Every top-level menu is in the one group, name="estilo-menus", with
99 the bar's Menu, switcher and account: opening File closes the
100 account menu and the other way round, which is the behaviour this
101 app chose on purpose and TestTheMenusShareOneGroup pins. estilo's
102 chrome.js closes the group on Escape and an outside click.
103
104 There are no submenus. A <details> nested inside a grouped one
105 closes its parent when it opens (TestNoNestedExclusiveDetails), and
106 inline accordions made Format a panel that scrolled with its
107 swatches cut off. Format lost Number, Fill colour and Text colour,
108 which the toolbar beside it already carries; Insert's functions
109 are rows under a heading. Hidden items are hidden until
110 commands.js can run them: an item appears only if it works. */}}
111
112<details estilo-menubar-menu name="estilo-menus">
113<summary estilo-menubar-title>File</summary>
114<div estilo-menu>
115<form method="post" action="/sheets"><button estilo-menu-item type="submit"><span estilo-menu-label>New sheet</span></button></form>
116{{/* A page, not a file input in this menu. A hidden input behind a
117 menu-shaped label never submits itself, so the item would have
118 needed script to import anything at all — see handleImportPage. */}}
119<a estilo-menu-item href="/sheets/import"><span estilo-menu-label>Import a spreadsheet…</span></a>
120<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/export.xlsx"><span estilo-menu-label>Download as .xlsx</span></a>
121<hr>
122<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/table"><span estilo-menu-label>Open as table</span></a>
123<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/history"><span estilo-menu-label>Version history</span></a>
124{{if .Data.ImportReport}}<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/import-report"><span estilo-menu-label>Import report</span></a>{{end}}
125{{if .Data.MayShare}}<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/share"><span estilo-menu-label>Share…</span></a>{{end}}
126</div>
127</details>
128
129{{if .Data.MayWrite}}
130<details estilo-menubar-menu name="estilo-menus">
131<summary estilo-menubar-title>Edit</summary>
132<div estilo-menu>
133{{/* Undo is a form, not a button, so it works with scripting off —
134 it posts to the same route the keyboard shortcut fetches, so
135 there is one undo and not two that can disagree. */}}
136<form method="post" action="/sheets/{{.Data.Sheet.ID}}/undo"><button estilo-menu-item type="submit"><span estilo-menu-label>Undo</span><kbd estilo-menu-key>{{.Frame.Keys.undo}}</kbd></button></form>
137{{/* The separators around the script-only groups are script-only too:
138 with scripting off Undo stands alone, not above two empty rules. */}}
139<hr data-needs-js hidden>
140<button estilo-menu-item type="button" data-cmd="cut" hidden><span estilo-menu-label>Cut</span><kbd estilo-menu-key>{{.Frame.Keys.cut}}</kbd></button>
141<button estilo-menu-item type="button" data-cmd="copy" hidden><span estilo-menu-label>Copy</span><kbd estilo-menu-key>{{.Frame.Keys.copy}}</kbd></button>
142{{/* Paste is here despite the browser being allowed to refuse a menu
143 read of the clipboard. It is not a dead control: clipboard.js
144 asks, and on a refusal says so in the status line below the grid
145 — which is more than the app could do for a person who does not
146 know the keyboard is the only way. The keyboard path needs no
147 permission at all, because a paste EVENT carries its own data. */}}
148<button estilo-menu-item type="button" data-cmd="paste" hidden><span estilo-menu-label>Paste</span><kbd estilo-menu-key>{{.Frame.Keys.paste}}</kbd></button>
149<button estilo-menu-item type="button" data-cmd="clear" hidden><span estilo-menu-label>Clear contents</span><kbd estilo-menu-key>{{.Frame.Keys.delete}}</kbd></button>
150<hr data-needs-js hidden>
151{{/* Fill down and fill right are the menu equivalents of the grid's
152 drag handle — AGENTS.md requires one for every drag-only
153 affordance. Ctrl+R is reload in every browser, so fill right is
154 deliberately shortcut-free. */}}
155<button estilo-menu-item type="button" data-cmd="fill-down" hidden><span estilo-menu-label>Fill down</span><kbd estilo-menu-key>{{.Frame.Keys.filldown}}</kbd></button>
156<button estilo-menu-item type="button" data-cmd="fill-right" hidden><span estilo-menu-label>Fill right</span></button>
157<button estilo-menu-item type="button" data-cmd="select-all" hidden><span estilo-menu-label>Select all</span><kbd estilo-menu-key>{{.Frame.Keys.selectall}}</kbd></button>
158</div>
159</details>
160{{end}}
161
162{{if or .Data.MayWrite .Data.MayComment}}
163<details estilo-menubar-menu name="estilo-menus">
164<summary estilo-menubar-title>Insert</summary>
165<div estilo-menu>
166{{if .Data.MayWrite}}
167{{/* Exactly the aggregates the engine registers and that a one-click
168 insert can guess the arguments for. VLOOKUP, INDEX and MATCH are
169 registered too and are deliberately absent: nothing here can guess
170 their second and third arguments. Rows under a heading, not a
171 submenu, and hidden until commands.js can insert them. */}}
172<p estilo-menu-heading data-needs-js hidden>Function</p>
173<button estilo-menu-item type="button" data-cmd="fn" data-fn="SUM" hidden><span estilo-menu-label>SUM</span></button>
174<button estilo-menu-item type="button" data-cmd="fn" data-fn="AVERAGE" hidden><span estilo-menu-label>AVERAGE</span></button>
175<button estilo-menu-item type="button" data-cmd="fn" data-fn="COUNT" hidden><span estilo-menu-label>COUNT</span></button>
176<button estilo-menu-item type="button" data-cmd="fn" data-fn="MIN" hidden><span estilo-menu-label>MIN</span></button>
177<button estilo-menu-item type="button" data-cmd="fn" data-fn="MAX" hidden><span estilo-menu-label>MAX</span></button>
178{{if .Data.MayComment}}<hr data-needs-js hidden>{{end}}
179{{end}}
180{{if .Data.MayComment}}<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/comments"><span estilo-menu-label>Comment…</span></a>{{end}}
181</div>
182</details>
183{{end}}
184
185{{if .Data.MayWrite}}
186{{/* The Format menu is entirely script-driven, so the whole menu is
187 hidden until commands.js reveals it. A menu of items that do
188 nothing is worse than no menu. */}}
189<details estilo-menubar-menu name="estilo-menus" hidden data-needs-js>
190<summary estilo-menubar-title>Format</summary>
191<div estilo-menu>
192<button estilo-menu-item type="button" data-cmd="bold"><span estilo-menu-label>Bold</span><kbd estilo-menu-key>{{.Frame.Keys.bold}}</kbd></button>
193<button estilo-menu-item type="button" data-cmd="italic"><span estilo-menu-label>Italic</span><kbd estilo-menu-key>{{.Frame.Keys.italic}}</kbd></button>
194<hr>
195<button estilo-menu-item type="button" data-cmd="align" data-value="left"><span estilo-menu-label>Align left</span></button>
196<button estilo-menu-item type="button" data-cmd="align" data-value="center"><span estilo-menu-label>Align centre</span></button>
197<button estilo-menu-item type="button" data-cmd="align" data-value="right"><span estilo-menu-label>Align right</span></button>
198<hr>
199{{/* The menu equivalent of dragging a column edge (AGENTS.md: every
200 drag-only affordance has one). A number field rather than a set of
201 buttons, because the size a drag produces is the one thing here you
202 cannot pick from a list. Real forms rather than a prompt(); they
203 post through commands.js because the size route takes JSON. */}}
204<button estilo-menu-item type="button" data-cmd="autofit-columns"><span estilo-menu-label>Auto-fit columns</span></button>
205<form data-size-form data-axis="col">
206<label for="colw">Column width</label>
207<input rst-input id="colw" name="size" type="number" min="16" max="2000" step="1" placeholder="px">
208<button rst-btn="ghost" type="submit">Set</button>
209</form>
210<form data-size-form data-axis="row">
211<label for="rowh">Row height</label>
212<input rst-input id="rowh" name="size" type="number" min="16" max="2000" step="1" placeholder="px">
213<button rst-btn="ghost" type="submit">Set</button>
214</form>
215<hr>
216<button estilo-menu-item type="button" data-cmd="clear-format"><span estilo-menu-label>Clear formatting</span></button>
217</div>
218</details>
219{{end}}
220
221<details estilo-menubar-menu name="estilo-menus">
222<summary estilo-menubar-title>Data</summary>
223<div estilo-menu>
224{{/* Both items lead to the table view, and the labels say so. The
225 grid does not apply a saved sort or filter yet — snapshot never
226 reads the ViewSpec, only the table does — and a "Sort A→Z" here
227 that silently moved you to another page would be worse than a
228 link that admits where it goes. */}}
229<a estilo-menu-item href="/sheets/{{.Data.Sheet.ID}}/table"><span estilo-menu-label>Sort and filter, in the table view…</span></a>
230{{if .Data.MayWrite}}
231<form method="post" action="/sheets/{{.Data.Sheet.ID}}/view">
232<input type="hidden" name="sortCol" value="-1">
233<input type="hidden" name="filterCol" value="-1">
234<button estilo-menu-item type="submit"><span estilo-menu-label>Clear sort and filter</span></button>
235</form>
236{{end}}
237</div>
238</details>
239
240{{/* No Help menu here. The shortcut list moved into the account menu's
241 Help, as "Keyboard shortcuts…" opening a dialog, where every app's
242 help lives (spec §8.2). */}}
243
244</nav>
245
246{{if .Data.MayWrite}}
247{{/* The toolbar. Hidden until commands.js wires it: every control
248 posts, so an unwired one is a button that does nothing.
249
250 role="toolbar" with a roving tabindex, so the whole strip is one
251 tab stop rather than fourteen — the same shape the Docs app uses,
252 deliberately, so the two apps behave alike. */}}
253<div data-toolbar role="toolbar" aria-label="Formatting" aria-controls="main" hidden data-needs-js>
254
255<button type="button" data-tool rst-tip data-cmd="undo" aria-label="Undo" data-tip="Undo ({{.Frame.Keys.undo}})">{{template "glyph-undo"}}</button>
256
257<span data-tool-rule aria-hidden="true"></span>
258
259<details rst-dropdown name="rst-tools" data-tool-menu>
260<summary data-tool rst-tip aria-label="Number format" data-tip="Number format">123<span rst-caret aria-hidden="true">{{icon "chevron-down"}}</span></summary>
261<div rst-dropdown-menu>
262{{range .Data.NumberFormats}}
263<button type="button" data-cmd="numfmt" data-value="{{.Code}}">{{.Label}}</button>
264{{end}}
265</div>
266</details>
267
268<span data-tool-rule aria-hidden="true"></span>
269
270<button type="button" data-tool rst-tip data-cmd="bold" aria-pressed="false" aria-label="Bold" data-tip="Bold ({{.Frame.Keys.bold}})"><b>B</b></button>
271<button type="button" data-tool rst-tip data-cmd="italic" aria-pressed="false" aria-label="Italic" data-tip="Italic ({{.Frame.Keys.italic}})"><i>I</i></button>
272
273<span data-tool-rule aria-hidden="true"></span>
274
275<details rst-dropdown name="rst-tools" data-tool-menu>
276<summary data-tool rst-tip aria-label="Fill colour" data-tip="Fill colour"><span data-fill-chip aria-hidden="true"></span><span rst-caret aria-hidden="true">{{icon "chevron-down"}}</span></summary>
277<div rst-dropdown-menu data-swatches>
278<button type="button" data-cmd="fill" data-value="none">No fill</button>
279{{range .Data.FillSwatches}}
280<button type="button" data-cmd="fill" data-value="{{.Name}}" aria-label="Fill {{.Label}}"
281 data-swatch style="--sheet-h:{{.H}};--sheet-c:{{.C}}">{{.Label}}</button>
282{{end}}
283</div>
284</details>
285
286<details rst-dropdown name="rst-tools" data-tool-menu>
287<summary data-tool rst-tip aria-label="Text colour" data-tip="Text colour"><span data-ink-chip aria-hidden="true">A</span><span rst-caret aria-hidden="true">{{icon "chevron-down"}}</span></summary>
288<div rst-dropdown-menu data-swatches>
289<button type="button" data-cmd="ink" data-value="none">Default</button>
290{{range .Data.InkSwatches}}
291<button type="button" data-cmd="ink" data-value="{{.Name}}" aria-label="Text {{.Label}}"
292 data-swatch data-ink-swatch style="--sheet-kh:{{.H}};--sheet-kc:{{.C}}">{{.Label}}</button>
293{{end}}
294</div>
295</details>
296
297<span data-tool-rule aria-hidden="true"></span>
298
299<button type="button" data-tool rst-tip data-cmd="align" data-value="left" aria-pressed="false" aria-label="Align left" data-tip="Align left">{{template "glyph-align-left"}}</button>
300<button type="button" data-tool rst-tip data-cmd="align" data-value="center" aria-pressed="false" aria-label="Align centre" data-tip="Align centre">{{template "glyph-align-center"}}</button>
301<button type="button" data-tool rst-tip data-cmd="align" data-value="right" aria-pressed="false" aria-label="Align right" data-tip="Align right">{{template "glyph-align-right"}}</button>
302
303</div>
304{{end}}
305
306</div>
307
308{{/* Row C — the name box and the formula bar, full width.
309 The formula bar shows the selected cell's INPUT while the grid
310 shows its computed value, which is the difference between a
311 spreadsheet and a table of numbers. It is also the reliable way to
312 see a formula: the in-cell editor swap is best effort. */}}
313<div data-formula-row>
314<label class="rst-sr-only" for="namebox">Cell reference</label>
315<input rst-input id="namebox" class="rst-mono" data-name-box type="text"
316 autocomplete="off" spellcheck="false" value="A1">
317<label for="formula" data-fx aria-hidden="true"><i>fx</i></label>
318<span class="rst-sr-only" id="formula-label">Selected cell contents</span>
319<input rst-input id="formula" class="rst-mono" data-formula-input type="text"
320 aria-labelledby="formula-label" autocomplete="off" spellcheck="false"
321 placeholder="Select a cell"{{if not .Data.MayWrite}} readonly{{end}}>
322</div>
323
324<noscript>
325{{/* Spec §6 names the grid editor, drag-fill and live sync as the
326 script-required parts, and everything else as scriptless. A visitor
327 with scripting off should land somewhere useful rather than on an
328 empty div, so this is a link and not an apology. */}}
329<div rst-callout rst-tone="info">
330<span rst-callout-ic aria-hidden="true">{{icon "info"}}</span>
331<div rst-callout-body>
332<p>The grid needs JavaScript. Everything it does, the
333<a href="/sheets/{{.Data.Sheet.ID}}/table">table view</a> also does —
334read every cell, edit any of them, one page at a time.</p>
335</div>
336</div>
337</noscript>
338
339{{template "contrast-notice" .Data.Warned}}
340
341<div data-sheet-grid></div>
342
343{{/* Row D — the tabs along the bottom, and the status that used to sit
344 in the strip above the grid.
345
346 One tab today, rendered as a link to the page it is already on, so
347 the strip is real markup rather than a picture of tabs. There is
348 deliberately no "+": nothing in this build creates, names or
349 switches a tab, and spec §14 makes "a second tab is reachable in
350 the UI" the trigger for multi-worksheet import. A + that did
351 nothing would fake that trigger. */}}
352<div data-tabstrip>
353<nav data-sheet-tabs aria-label="Sheets in this document">
354<a href="/sheets/{{.Data.Sheet.ID}}" aria-current="page">{{.Data.Sheet.TabName}}</a>
355</nav>
356{{/* Deliberately NOT role="status". It changes on every arrow key, and
357 a live region announcing "3 cells" after each one talks over the
358 cell content a screen reader is trying to read. It is a glance,
359 and the selection itself is what announces. */}}
360<span data-selection-size></span>
361{{/* The one place this app can say something transient. role="status"
362 is right here and wrong on the selection size beside it: this
363 changes when you ask for something and it did not happen, which
364 is exactly what a person needs read out, where the selection
365 size changes on every arrow key and would talk over the cell. */}}
366<span data-sheet-note role="status"></span>
367<span data-sheet-live data-state="off" role="status">Connecting</span>
368</div>
369{{end}}
370