project_note
Clone
https://git.tahinli.com/Tahinli/project_note.git
0 watching0 forksJavaScript3.6 MiBe100df4Tahinli1 month ago1 commit
| 1 | //! The app shell pieces shared by every page: the head scripts and styles, the sidebar, |
| 2 | //! the toast region, the note rows, and the "New note" form. |
| 3 | |
| 4 | use ; |
| 5 | |
| 6 | use |
| 7 | |
| 8 | |
| 9 | ; |
| 10 | |
| 11 | use crate; |
| 12 | use crate |
| 13 | |
| 14 | |
| 15 | |
| 16 | ; |
| 17 | use crate; |
| 18 | use crateinput; |
| 19 | use crate; |
| 20 | use crate; |
| 21 | use crate; |
| 22 | use crate; |
| 23 | use crateNotebook; |
| 24 | |
| 25 | /// Runs before first paint. It applies the theme (light, dark, or system, stored in |
| 26 | /// localStorage as "theme") and the sidebar state ("sidebar"). The sidebar theme buttons |
| 27 | /// (`data-theme-set`) set the theme on click and keep `aria-pressed` in step with it. |
| 28 | /// `window.cycleTheme` steps through light, dark, and system for the command palette. |
| 29 | /// `html.no-anim` turns transitions off until the first frame, so a restored sidebar |
| 30 | /// state does not animate on load. |
| 31 | pub const THEME_SCRIPT: &str = r#" |
| 32 | (function () { |
| 33 | var root = document.documentElement; |
| 34 | var order = ['light', 'dark', 'system']; |
| 35 | var mq = window.matchMedia('(prefers-color-scheme: dark)'); |
| 36 | root.classList.add('no-anim'); |
| 37 | function read(key, valid, fallback) { |
| 38 | try { |
| 39 | var v = localStorage.getItem(key); |
| 40 | return valid.indexOf(v) >= 0 ? v : fallback; |
| 41 | } catch (e) { |
| 42 | return fallback; |
| 43 | } |
| 44 | } |
| 45 | function syncThemeButtons() { |
| 46 | var pref = root.dataset.theme; |
| 47 | document.querySelectorAll('[data-theme-set]').forEach(function (btn) { |
| 48 | btn.setAttribute('aria-pressed', btn.dataset.themeSet === pref ? 'true' : 'false'); |
| 49 | }); |
| 50 | } |
| 51 | function applyTheme(pref) { |
| 52 | root.dataset.theme = pref; |
| 53 | root.classList.toggle('dark', pref === 'dark' || (pref === 'system' && mq.matches)); |
| 54 | syncThemeButtons(); |
| 55 | } |
| 56 | function setTheme(pref) { |
| 57 | try { localStorage.setItem('theme', pref); } catch (e) {} |
| 58 | applyTheme(pref); |
| 59 | } |
| 60 | applyTheme(read('theme', order, 'system')); |
| 61 | mq.addEventListener('change', function () { |
| 62 | if (read('theme', order, 'system') === 'system') applyTheme('system'); |
| 63 | }); |
| 64 | window.cycleTheme = function () { |
| 65 | setTheme(order[(order.indexOf(read('theme', order, 'system')) + 1) % order.length]); |
| 66 | }; |
| 67 | window.syncThemeButtons = syncThemeButtons; |
| 68 | document.addEventListener('click', function (e) { |
| 69 | var btn = e.target.closest && e.target.closest('[data-theme-set]'); |
| 70 | if (btn) setTheme(btn.dataset.themeSet); |
| 71 | }); |
| 72 | root.dataset.sidebar = read('sidebar', ['collapsed', 'expanded'], 'expanded'); |
| 73 | requestAnimationFrame(function () { |
| 74 | requestAnimationFrame(function () { root.classList.remove('no-anim'); }); |
| 75 | }); |
| 76 | })(); |
| 77 | "#; |
| 78 | |
| 79 | /// Shell styles that depend on the viewport or on `data-*` state. Below 1024px the sidebar |
| 80 | /// is an off-canvas drawer that slides in and out with a fading backdrop; it stays |
| 81 | /// `visibility: hidden` (and `inert`, set by the script) until the slide-out ends. At |
| 82 | /// 1024px and up the sidebar collapses by animating its width to 0, with its fixed-width |
| 83 | /// body fading. `html.no-anim` suppresses transitions on the first frame. Reduced motion |
| 84 | /// disables all of it. Also: touch target sizes and cross-document view transitions. |
| 85 | pub const SHELL_STYLE: &str = r#" |
| 86 | @view-transition { navigation: auto; } |
| 87 | #sidebar { |
| 88 | position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; |
| 89 | width: 240px; max-width: 85vw; height: 100dvh; |
| 90 | transform: translateX(-100%); visibility: hidden; |
| 91 | transition: transform 220ms cubic-bezier(.2,.8,.2,1), visibility 0s linear 220ms; |
| 92 | } |
| 93 | #sidebar[data-open="true"] { |
| 94 | transform: none; visibility: visible; |
| 95 | transition: transform 220ms cubic-bezier(.2,.8,.2,1), visibility 0s; |
| 96 | } |
| 97 | #drawer-backdrop { |
| 98 | position: fixed; inset: 0; z-index: 30; |
| 99 | background: color-mix(in srgb, var(--foreground) 30%, transparent); |
| 100 | opacity: 0; visibility: hidden; |
| 101 | transition: opacity 220ms ease, visibility 0s linear 220ms; |
| 102 | } |
| 103 | #drawer-backdrop[data-open="true"] { |
| 104 | opacity: 1; visibility: visible; |
| 105 | transition: opacity 220ms ease, visibility 0s; |
| 106 | } |
| 107 | #sidebar-expand { display: none; } |
| 108 | html.no-anim, html.no-anim *, html.no-anim *::before, html.no-anim *::after { |
| 109 | transition: none !important; |
| 110 | } |
| 111 | @media (min-width: 1024px) { |
| 112 | #sidebar { |
| 113 | position: static; z-index: auto; max-width: none; height: auto; flex-shrink: 0; |
| 114 | width: 240px; transform: none; visibility: visible; |
| 115 | transition: |
| 116 | width 200ms cubic-bezier(.2,.8,.2,1), |
| 117 | border-right-width 200ms cubic-bezier(.2,.8,.2,1), |
| 118 | visibility 200ms linear; |
| 119 | } |
| 120 | #sidebar > .sidebar-body { transition: opacity 150ms ease; } |
| 121 | html[data-sidebar="collapsed"] #sidebar { width: 0; border-right-width: 0; visibility: hidden; } |
| 122 | html[data-sidebar="collapsed"] #sidebar > .sidebar-body { opacity: 0; } |
| 123 | html[data-sidebar="collapsed"] #sidebar-expand { display: inline-flex; } |
| 124 | /* The list pane header reserves room for the floating expand button (12px inset, 32px wide, 8px gap). */ |
| 125 | .sidebar-lead { transition: padding-left 200ms cubic-bezier(.2,.8,.2,1); } |
| 126 | html[data-sidebar="collapsed"] .sidebar-lead { padding-left: 3.25rem; } |
| 127 | #drawer-backdrop { display: none; } |
| 128 | } |
| 129 | @media (max-width: 1023px) { |
| 130 | #sidebar a, #sidebar button, #sidebar input, #sidebar-expand, #drawer-open, [data-close-drawer] { min-height: 40px; } |
| 131 | input, select, textarea { font-size: 16px; } |
| 132 | } |
| 133 | @media (prefers-reduced-motion: reduce) { |
| 134 | #sidebar, #sidebar[data-open="true"], #sidebar > .sidebar-body, .sidebar-lead, #drawer-backdrop, #drawer-backdrop[data-open="true"] { |
| 135 | transition: none !important; |
| 136 | } |
| 137 | } |
| 138 | "#; |
| 139 | |
| 140 | /// Global keyboard shortcuts and the small interactions of the shell: the mobile drawer |
| 141 | /// (opened from the top bar, closed by Esc, the backdrop, or its close button), sidebar |
| 142 | /// collapse, and toasts that hide after six seconds. |
| 143 | /// |
| 144 | /// Shortcuts: Ctrl/Cmd+K opens the command palette (`window.openPalette`, Ctrl/Cmd+Shift+K |
| 145 | /// inside the editor), otherwise focuses the search box. "/" focuses search and "n" submits the New note form, both only when no |
| 146 | /// field is being typed in. |
| 147 | pub const SHELL_SCRIPT: &str = r#" |
| 148 | (function () { |
| 149 | var root = document.documentElement; |
| 150 | // Server renders times in UTC; show them in the viewer's own time zone. |
| 151 | var fmt = new Intl.DateTimeFormat(root.lang || undefined, { dateStyle: 'medium', timeStyle: 'short' }); |
| 152 | document.querySelectorAll('time[data-ms]').forEach(function (el) { |
| 153 | el.textContent = fmt.format(new Date(Number(el.dataset.ms))); |
| 154 | }); |
| 155 | var sidebar = document.getElementById('sidebar'); |
| 156 | var backdrop = document.getElementById('drawer-backdrop'); |
| 157 | var openBtn = document.getElementById('drawer-open'); |
| 158 | var collapseBtn = document.getElementById('sidebar-collapse'); |
| 159 | var expandBtn = document.getElementById('sidebar-expand'); |
| 160 | var desktop = window.matchMedia('(min-width: 1024px)'); |
| 161 | var opener = null; |
| 162 | |
| 163 | function isOpen() { return sidebar.dataset.open === 'true'; } |
| 164 | function syncInert() { sidebar.inert = !desktop.matches && !isOpen(); } |
| 165 | function setDrawer(open) { |
| 166 | if (open === isOpen()) return; |
| 167 | if (open) opener = document.activeElement; |
| 168 | sidebar.dataset.open = open ? 'true' : 'false'; |
| 169 | backdrop.dataset.open = open ? 'true' : 'false'; |
| 170 | openBtn.setAttribute('aria-expanded', open ? 'true' : 'false'); |
| 171 | syncInert(); |
| 172 | // The drawer is still sliding in when focus moves, so keep the page from scrolling. |
| 173 | if (open) { |
| 174 | var first = sidebar.querySelector('[data-close-drawer]'); |
| 175 | if (first) first.focus({ preventScroll: true }); |
| 176 | } else if (opener && !desktop.matches) { |
| 177 | opener.focus({ preventScroll: true }); |
| 178 | } |
| 179 | } |
| 180 | function isCollapsed() { return root.dataset.sidebar === 'collapsed'; } |
| 181 | function setCollapsed(collapsed) { |
| 182 | root.dataset.sidebar = collapsed ? 'collapsed' : 'expanded'; |
| 183 | try { localStorage.setItem('sidebar', root.dataset.sidebar); } catch (e) {} |
| 184 | } |
| 185 | function focusSearch() { |
| 186 | if (desktop.matches && isCollapsed()) setCollapsed(false); |
| 187 | if (!desktop.matches && !isOpen()) setDrawer(true); |
| 188 | var input = document.getElementById('search-input'); |
| 189 | if (input) { input.focus(); input.select(); } |
| 190 | } |
| 191 | |
| 192 | // Live search: results replace the page content as you type, without a reload. An |
| 193 | // empty box shows every note again. Enter still submits the form as a fallback. |
| 194 | var searchBox = document.getElementById('search-input'); |
| 195 | if (searchBox && window.fetch && window.DOMParser) { |
| 196 | var searchTimer = 0; |
| 197 | var searchCtl = null; |
| 198 | var searchSeq = 0; |
| 199 | // Search filters (match case, whole word, exact phrase, regex). The results page's |
| 200 | // URL says which are on; elsewhere the last choice is remembered. |
| 201 | var OPTS = ['case', 'word', 'exact', 're']; |
| 202 | var opts = {}; |
| 203 | var params = new URLSearchParams(location.search); |
| 204 | var saved = {}; |
| 205 | try { saved = JSON.parse(localStorage.getItem('search-opts') || '{}'); } catch (e) {} |
| 206 | OPTS.forEach(function (k) { |
| 207 | opts[k] = location.pathname === '/search' ? params.get(k) === '1' : !!saved[k]; |
| 208 | }); |
| 209 | // The filter menu's checkboxes and the dot on its button follow `opts`. |
| 210 | var syncOpts = function () { |
| 211 | var any = false; |
| 212 | document.querySelectorAll('[data-search-opt]').forEach(function (el) { |
| 213 | el.setAttribute('aria-checked', opts[el.dataset.searchOpt] ? 'true' : 'false'); |
| 214 | }); |
| 215 | OPTS.forEach(function (k) { if (opts[k]) any = true; }); |
| 216 | var btn = document.getElementById('search-filter-button'); |
| 217 | if (btn) btn.toggleAttribute('data-active', any); |
| 218 | }; |
| 219 | syncOpts(); |
| 220 | var runSearch = function () { |
| 221 | var q = searchBox.value.trim(); |
| 222 | var url = '/'; |
| 223 | if (q) { |
| 224 | url = '/search?q=' + encodeURIComponent(q); |
| 225 | OPTS.forEach(function (k) { if (opts[k]) url += '&' + k + '=1'; }); |
| 226 | } |
| 227 | if (searchCtl) searchCtl.abort(); |
| 228 | searchCtl = new AbortController(); |
| 229 | var seq = ++searchSeq; |
| 230 | fetch(url, { signal: searchCtl.signal, headers: { accept: 'text/html' } }) |
| 231 | .then(function (res) { return res.text(); }) |
| 232 | .then(function (html) { |
| 233 | if (seq !== searchSeq) return; |
| 234 | var doc = new DOMParser().parseFromString(html, 'text/html'); |
| 235 | var next = doc.getElementById('main'); |
| 236 | var main = document.getElementById('main'); |
| 237 | if (!next || !main) return; |
| 238 | window.dispatchEvent(new Event('note:detach')); |
| 239 | main.innerHTML = next.innerHTML; |
| 240 | document.title = doc.title; |
| 241 | main.querySelectorAll('time[data-ms]').forEach(function (el) { |
| 242 | el.textContent = fmt.format(new Date(Number(el.dataset.ms))); |
| 243 | }); |
| 244 | // Keep the sidebar's current section in step with the page. |
| 245 | // Links pair up by position; the sidebar has the same links on every page. |
| 246 | var twins = doc.querySelectorAll('#sidebar a[href]'); |
| 247 | document.querySelectorAll('#sidebar a[href]').forEach(function (a, i) { |
| 248 | var twin = twins[i]; |
| 249 | if (!twin || twin.getAttribute('href') !== a.getAttribute('href')) return; |
| 250 | a.className = twin.className; |
| 251 | if (twin.hasAttribute('aria-current')) a.setAttribute('aria-current', twin.getAttribute('aria-current')); |
| 252 | else a.removeAttribute('aria-current'); |
| 253 | }); |
| 254 | // The first keystroke from another page adds a history entry; later ones |
| 255 | // replace it, so Back leaves search in one step. |
| 256 | var onResults = location.pathname === '/search' || history.state === 'live-search'; |
| 257 | history[onResults ? 'replaceState' : 'pushState']('live-search', '', url); |
| 258 | }) |
| 259 | .catch(function () {}); |
| 260 | }; |
| 261 | searchBox.addEventListener('input', function () { |
| 262 | clearTimeout(searchTimer); |
| 263 | searchTimer = setTimeout(runSearch, 150); |
| 264 | }); |
| 265 | var flip = function (key) { |
| 266 | opts[key] = !opts[key]; |
| 267 | try { localStorage.setItem('search-opts', JSON.stringify(opts)); } catch (e) {} |
| 268 | syncOpts(); |
| 269 | clearTimeout(searchTimer); |
| 270 | if (searchBox.value.trim()) runSearch(); |
| 271 | }; |
| 272 | document.addEventListener('click', function (e) { |
| 273 | var btn = e.target.closest && e.target.closest('[data-search-opt]'); |
| 274 | if (!btn) return; |
| 275 | e.preventDefault(); |
| 276 | flip(btn.dataset.searchOpt); |
| 277 | }); |
| 278 | // Alt+C / W / E / R toggle the filters from the search box, as in code editors. |
| 279 | searchBox.addEventListener('keydown', function (e) { |
| 280 | if (!e.altKey || e.ctrlKey || e.metaKey) return; |
| 281 | var key = { KeyC: 'case', KeyW: 'word', KeyE: 'exact', KeyR: 're' }[e.code]; |
| 282 | if (!key) return; |
| 283 | e.preventDefault(); |
| 284 | flip(key); |
| 285 | }); |
| 286 | window.addEventListener('popstate', function () { location.reload(); }); |
| 287 | } |
| 288 | |
| 289 | openBtn.addEventListener('click', function () { setDrawer(!isOpen()); }); |
| 290 | backdrop.addEventListener('click', function () { setDrawer(false); }); |
| 291 | document.querySelectorAll('[data-close-drawer]').forEach(function (btn) { |
| 292 | btn.addEventListener('click', function () { setDrawer(false); }); |
| 293 | }); |
| 294 | if (collapseBtn) { |
| 295 | collapseBtn.addEventListener('click', function () { |
| 296 | setCollapsed(true); |
| 297 | if (expandBtn) expandBtn.focus(); |
| 298 | }); |
| 299 | } |
| 300 | if (expandBtn) { |
| 301 | expandBtn.addEventListener('click', function () { |
| 302 | setCollapsed(false); |
| 303 | if (collapseBtn) collapseBtn.focus(); |
| 304 | }); |
| 305 | } |
| 306 | desktop.addEventListener('change', function () { |
| 307 | if (desktop.matches) { |
| 308 | sidebar.dataset.open = 'false'; |
| 309 | backdrop.dataset.open = 'false'; |
| 310 | openBtn.setAttribute('aria-expanded', 'false'); |
| 311 | } |
| 312 | syncInert(); |
| 313 | }); |
| 314 | syncInert(); |
| 315 | if (typeof window.syncThemeButtons === 'function') window.syncThemeButtons(); |
| 316 | |
| 317 | document.addEventListener('keydown', function (e) { |
| 318 | if (e.key === 'Escape' && isOpen()) { |
| 319 | e.preventDefault(); |
| 320 | setDrawer(false); |
| 321 | return; |
| 322 | } |
| 323 | var el = document.activeElement; |
| 324 | var typing = !!el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName)); |
| 325 | var mod = e.ctrlKey || e.metaKey; |
| 326 | if (mod && !e.altKey && e.key.toLowerCase() === 'k') { |
| 327 | // In the editor, Mod-K is the link shortcut; the palette takes Mod-Shift-K there. |
| 328 | if (el && el.closest && el.closest('.ProseMirror') && !e.shiftKey) return; |
| 329 | e.preventDefault(); |
| 330 | if (typeof window.openPalette === 'function') { |
| 331 | window.openPalette(); |
| 332 | } else { |
| 333 | var palette = document.getElementById('palette'); |
| 334 | if (palette) { |
| 335 | if (typeof palette.showModal === 'function') palette.showModal(); |
| 336 | else palette.hidden = false; |
| 337 | } else { |
| 338 | focusSearch(); |
| 339 | } |
| 340 | } |
| 341 | return; |
| 342 | } |
| 343 | if (typing || mod || e.altKey) return; |
| 344 | if (e.key === '/') { |
| 345 | e.preventDefault(); |
| 346 | focusSearch(); |
| 347 | } else if (e.key === 'n' || e.key === 'N') { |
| 348 | var form = document.getElementById('new-note-form'); |
| 349 | if (form) { |
| 350 | e.preventDefault(); |
| 351 | form.requestSubmit(); |
| 352 | } |
| 353 | } |
| 354 | }); |
| 355 | |
| 356 | // Color scheme. The server puts data-scheme on <html> from the cookie. Choosing a scheme |
| 357 | // (picker or palette) applies it at once and saves it with a POST to /scheme. Hovering or |
| 358 | // focusing a picker row previews that scheme; closing the menu without a choice restores |
| 359 | // the saved one. `window.setScheme` is shared with the command palette. |
| 360 | var committed = root.dataset.scheme; |
| 361 | var schemeMenu = document.getElementById('scheme-menu'); |
| 362 | function syncScheme() { |
| 363 | var id = root.dataset.scheme; |
| 364 | document.querySelectorAll('[data-scheme-current]').forEach(function (el) { |
| 365 | el.hidden = el.dataset.schemeCurrent !== id; |
| 366 | }); |
| 367 | document.querySelectorAll('[data-scheme-choice]').forEach(function (el) { |
| 368 | el.setAttribute('aria-checked', el.dataset.schemeChoice === committed ? 'true' : 'false'); |
| 369 | }); |
| 370 | } |
| 371 | function preview(id) { |
| 372 | root.dataset.scheme = id; |
| 373 | syncScheme(); |
| 374 | } |
| 375 | window.setScheme = function (id) { |
| 376 | committed = id; |
| 377 | preview(id); |
| 378 | fetch('/scheme', { |
| 379 | method: 'POST', |
| 380 | credentials: 'same-origin', |
| 381 | redirect: 'manual', |
| 382 | body: new URLSearchParams({ scheme: id, back: location.pathname + location.search }) |
| 383 | }).catch(function () {}); |
| 384 | }; |
| 385 | function rowScheme(e) { |
| 386 | var item = e.target.closest && e.target.closest('[data-scheme-choice]'); |
| 387 | if (item) preview(item.dataset.schemeChoice); |
| 388 | } |
| 389 | if (schemeMenu) { |
| 390 | schemeMenu.addEventListener('pointerover', rowScheme); |
| 391 | schemeMenu.addEventListener('focusin', rowScheme); |
| 392 | schemeMenu.addEventListener('toggle', function (e) { |
| 393 | if (e.newState === 'closed') preview(committed); |
| 394 | }); |
| 395 | } |
| 396 | document.addEventListener('submit', function (e) { |
| 397 | var form = e.target; |
| 398 | var field = form.matches && form.matches('[data-scheme-form]') && form.querySelector('input[name="scheme"]'); |
| 399 | if (!field) return; |
| 400 | e.preventDefault(); |
| 401 | window.setScheme(field.value); |
| 402 | if (schemeMenu && schemeMenu.matches(':popover-open')) schemeMenu.hidePopover(); |
| 403 | }); |
| 404 | syncScheme(); |
| 405 | |
| 406 | document.querySelectorAll('#toasts [data-toast]').forEach(function (toast) { |
| 407 | var timer = setTimeout(function () { toast.remove(); }, 6000); |
| 408 | var dismiss = toast.querySelector('[data-dismiss]'); |
| 409 | if (dismiss) { |
| 410 | dismiss.addEventListener('click', function () { |
| 411 | clearTimeout(timer); |
| 412 | toast.remove(); |
| 413 | }); |
| 414 | } |
| 415 | }); |
| 416 | })(); |
| 417 | "#; |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | /// The note title, or "Untitled" in `lang` when it is blank. |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | /// The name of the notebook with `id`, if it exists. |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | /// Where the user is, as far as the sidebar is concerned. |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | /// A notebook entry in the sidebar. |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | /// Everything the sidebar shows. Counts exclude trashed notes, except `trash`. |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | const NAV_ITEM: &str = "flex h-9 min-w-0 items-center gap-2 rounded-control px-2 text-sm transition-colors"; |
| 477 | const NAV_IDLE: &str = "text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"; |
| 478 | const NAV_ACTIVE: &str = "marker font-medium"; |
| 479 | const NAV_COUNT: &str = "ml-auto font-mono text-xs tabular-nums text-muted-foreground"; |
| 480 | |
| 481 | /// One sidebar row: a link with an optional count. The active row gets the marker swipe |
| 482 | /// and `aria-current="page"`. |
| 483 | |
| 484 | async |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | /// Three dots showing a scheme's sidebar, accent, and active row colors. The light and |
| 500 | /// dark colors go in as custom properties; `.dark` picks the dark one (see `styles.css`). |
| 501 | |
| 502 | async |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | /// The picker's button label: the scheme's name and dots. Every scheme has a label, and |
| 518 | /// the script shows the one for the current (or previewed) scheme. |
| 519 | |
| 520 | async |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | /// Every scheme's label in the picker button. Only the current one is shown; the script |
| 537 | /// moves the `hidden` attribute when the scheme changes or is previewed. |
| 538 | |
| 539 | async |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | /// One row per scheme in the picker's menu. Each row is a form that posts the choice to |
| 548 | /// `/scheme`; the script intercepts it and applies the scheme without a reload. |
| 549 | |
| 550 | async |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | /// The round initials badge of the profile button. |
| 580 | const AVATAR: &str = "inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-[var(--active-row)] text-xs font-semibold text-[var(--active-row-foreground)]"; |
| 581 | /// A link row in a menu, with an icon, matching `dropdown_menu_item`. |
| 582 | const MENU_ROW: &str = "flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm whitespace-nowrap hover:bg-foreground/5 focus-visible:bg-foreground/5 active:bg-foreground/10"; |
| 583 | |
| 584 | /// The sidebar: app name, search, New note, the notes and trash list, notebooks with |
| 585 | /// a new-notebook form, and the theme and language controls. It is a `<nav>` landmark. |
| 586 | /// Below 1024px it is an off-canvas drawer; above, it can be collapsed. |
| 587 | |
| 588 | pub async |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 |