Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Editor: make the topbar fit a phone

nyblnetfe623bfafa87
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1aedaad6..690dbb37 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,18 @@ pre-1.0.
## [Unreleased]
+- **The editor fits on a phone.** The toolbar used to need about 680px of a
+ 402px screen: it ran off the edge, took the Save button with it, and because
+ nothing clipped it, swiping the toolbar dragged the whole canvas sideways.
+ On a phone it now folds into two menus — + for inserting and ⋯ for
+ everything occasional — leaving slides, insert, undo, format, save and more,
+ at proper touch size. The side panels slide over the canvas instead of
+ squeezing it, so the slide you're editing is no longer the smallest thing on
+ screen. Nothing changes on a laptop.
+
+ Known gap: the save-as menu (copy, new deck, template, password) doesn't fit
+ on a phone yet and is unreachable there for now.
+
- **Maths, written the way you'd write it.** Type `$E=mc^2$` in a text box and
it renders as a formula — `$$…$$` for a display equation on its own line.
The document stores exactly what you typed, so a deck with maths still opens
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 426f09cf..0d523e34 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -291,8 +291,36 @@ export class Editor {
history.append(undoB, redoB)
const saveGroup = div('ed-split')
saveGroup.append(saveB, this.saveDropdown())
- actions.append(pdfB, this.avatarsBox, this.shareDropdown(), saveGroup, this.languageDropdown(), helpB)
- bar.append(logo, this.updatesB, title, history, insert, actions)
+ const shareD = this.shareDropdown()
+ const langD = this.languageDropdown()
+ actions.append(pdfB, this.avatarsBox, shareD, saveGroup, langD, helpB)
+
+ // Phone chrome: two menus that stay EMPTY on a wide screen. Nothing is
+ // duplicated — applyPhoneChrome moves the real buttons in and out, so every
+ // listener, tooltip and live reference (dirtyDot, updatesB, the comment
+ // button's armed state) keeps working wherever the button currently sits.
+ const insertMenu = div('ed-menu')
+ const insertD = div('ed-dropdown ed-phone-only')
+ insertD.append(
+ btn(ICONS.plus, t('Insert'), () => insertD.classList.toggle('open'), t('Insert — text, shapes, images, media, tables, charts')),
+ insertMenu)
+ const moreMenu = div('ed-menu')
+ const moreD = div('ed-dropdown ed-phone-only')
+ moreD.append(
+ btn('<b>⋯</b>', t('More'), () => moreD.classList.toggle('open'), t('More actions')),
+ moreMenu)
+ const slidesB = btn(ICONS.panelLeft, t('Slides'), () => this.togglePanel('left'), t('Slides — show or hide the slide list'))
+ slidesB.classList.add('ed-phone-only')
+ const formatB = btn(ICONS.panelRight, t('Format'), () => this.togglePanel('right'), t('Format — show or hide the properties panel'))
+ formatB.classList.add('ed-phone-only')
+
+ this.phoneChrome = {
+ insertD, insertMenu, moreD, moreMenu, slidesB, formatB, insert, actions, history,
+ // order matters: this is the order they appear in the ⋯ menu
+ demote: [redoB, commentB, pdfB, shareD, langD, helpB],
+ }
+
+ bar.append(logo, this.updatesB, title, slidesB, insertD, history, insert, actions, moreD)
// main area
const main = div('ed-main')
@@ -350,6 +378,22 @@ export class Editor {
this.props.classList.add('ed-collapsed')
}
+ actions.insertBefore(formatB, saveGroup)
+
+ // drive it now and whenever the query flips
+ // Held on `this` deliberately: a MediaQueryList that nothing references can
+ // be collected along with its listener, and the bar then never unfolds when
+ // the window grows — the CSS flips but the JS half silently stops.
+ this.phoneQuery = window.matchMedia('(max-width: 700px)')
+ this.applyPhoneChrome(this.phoneQuery.matches)
+ this.phoneQuery.addEventListener('change', (e) => this.applyPhoneChrome(e.matches))
+ // ...and on plain resize as well. matchMedia's change event is the correct
+ // signal but not a universally reliable one — it does not fire at all under
+ // CDP-driven viewport changes, and a phone ROTATING is exactly this path.
+ // applyPhoneChrome early-returns when the state is unchanged, so calling it
+ // on every resize costs a comparison.
+ window.addEventListener('resize', () => this.applyPhoneChrome(window.innerWidth <= 700))
+
this.restorePanelWidths()
this.canvas = new SlideCanvas(canvasWrap, this.store)
this.canvas.onCommentModeChange = (on) => commentB.classList.toggle('ed-btn-armed', on)
@@ -467,6 +511,58 @@ export class Editor {
}
/** Collapse/expand the slide list or the properties panel. */
+ private phoneChrome: {
+ insertD: HTMLElement; insertMenu: HTMLElement
+ moreD: HTMLElement; moreMenu: HTMLElement
+ slidesB: HTMLElement; formatB: HTMLElement
+ insert: HTMLElement; actions: HTMLElement; history: HTMLElement
+ demote: HTMLElement[]
+ } | null = null
+
+ /**
+ * Fold the topbar into menus on a phone, and unfold it again on a wide
+ * window. REPARENTS the existing buttons rather than building phone copies:
+ * a duplicate would need its own listeners and would desync from live state
+ * (the dirty dot lives ON the save button; the comment button carries an
+ * armed class). Moving a node keeps all of that by construction.
+ */
+ private applyPhoneChrome(on: boolean) {
+ const p = this.phoneChrome
+ if (!p || this.phoneChromeOn === on) return
+ this.phoneChromeOn = on
+ if (on) {
+ // the six insert tools + comment go under +
+ while (p.insert.firstChild) p.insertMenu.appendChild(p.insert.firstChild)
+ for (const b of p.demote) {
+ if (!b.parentElement) continue
+ // Undo/redo/PDF are icon-only BY DESIGN in the bar (no <span> at all),
+ // so the menu's label rule has nothing to reveal and they would sit in
+ // ⋯ as mystery glyphs. Borrow the tooltip, minus its shortcut: "Redo
+ // (⇧⌘Z)" -> "Redo". No new strings, and desktop is untouched.
+ if (!b.querySelector('span') && b.title) {
+ const lab = document.createElement('span')
+ lab.dataset.phoneLabel = '1'
+ lab.textContent = b.title.split('(')[0].trim()
+ b.appendChild(lab)
+ }
+ p.moreMenu.appendChild(b)
+ }
+ } else {
+ while (p.insertMenu.firstChild) p.insert.appendChild(p.insertMenu.firstChild)
+ for (const lab of p.moreMenu.querySelectorAll('[data-phone-label]')) lab.remove()
+ // back to their original homes, in their original order
+ for (const b of p.demote) {
+ if (b === p.demote[0]) p.history.appendChild(b)
+ else p.actions.insertBefore(b, p.formatB)
+ }
+ p.moreD.classList.remove('open')
+ p.insertD.classList.remove('open')
+ }
+ }
+
+ private phoneChromeOn: boolean | null = null
+ private phoneQuery: MediaQueryList | null = null
+
togglePanel(side: 'left' | 'right') {
const el = side === 'left' ? this.sidebar : this.props
el.classList.toggle('ed-collapsed')
diff --git a/slides/src/i18n/de.ts b/slides/src/i18n/de.ts
index d4091f47..f7bfe769 100644
--- a/slides/src/i18n/de.ts
+++ b/slides/src/i18n/de.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const de: Catalog = {
+ "More": "Mehr",
+ "Insert": "Einfügen",
+ "Slides": "Folien",
+ "Format": "Format",
"Backed up in this browser": "In diesem Browser gesichert",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "Nicht gespeicherte Änderungen — um {when} in diesem Browser gesichert und beim erneuten Öffnen angeboten. ⌘S lädt eine aktualisierte Kopie herunter.",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "Nicht gespeicherte Änderungen — ⌘S lädt eine aktualisierte Kopie herunter (dieser Browser kann die Datei nicht überschreiben)",
diff --git a/slides/src/i18n/es.ts b/slides/src/i18n/es.ts
index 7d435a86..1210d62d 100644
--- a/slides/src/i18n/es.ts
+++ b/slides/src/i18n/es.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const es: Catalog = {
+ "More": "Más",
+ "Insert": "Insertar",
+ "Slides": "Diapositivas",
+ "Format": "Formato",
"Backed up in this browser": "Copia guardada en este navegador",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "Cambios sin guardar — conservados en este navegador a las {when} y se te ofrecerán al reabrir. ⌘S descarga una copia actualizada.",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "Cambios sin guardar — ⌘S descarga una copia actualizada (este navegador no puede reescribir el archivo)",
diff --git a/slides/src/i18n/fr.ts b/slides/src/i18n/fr.ts
index 8e936409..a000012c 100644
--- a/slides/src/i18n/fr.ts
+++ b/slides/src/i18n/fr.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const fr: Catalog = {
+ "More": "Plus",
+ "Insert": "Insérer",
+ "Slides": "Diapositives",
+ "Format": "Format",
"Backed up in this browser": "Sauvegardé dans ce navigateur",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "Modifications non enregistrées — conservées dans ce navigateur à {when} et proposées à la réouverture. ⌘S télécharge une copie à jour.",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "Modifications non enregistrées — ⌘S télécharge une copie à jour (ce navigateur ne peut pas réécrire le fichier)",
diff --git a/slides/src/i18n/it.ts b/slides/src/i18n/it.ts
index 3d581bef..8d47bf83 100644
--- a/slides/src/i18n/it.ts
+++ b/slides/src/i18n/it.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const it: Catalog = {
+ "More": "Altro",
+ "Insert": "Inserisci",
+ "Slides": "Diapositive",
+ "Format": "Formato",
"Backed up in this browser": "Salvato in questo browser",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "Modifiche non salvate — conservate in questo browser alle {when} e riproposte alla riapertura. ⌘S scarica una copia aggiornata.",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "Modifiche non salvate — ⌘S scarica una copia aggiornata (questo browser non può riscrivere il file)",
diff --git a/slides/src/i18n/ja.ts b/slides/src/i18n/ja.ts
index 38359bcd..c8b598a5 100644
--- a/slides/src/i18n/ja.ts
+++ b/slides/src/i18n/ja.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const ja: Catalog = {
+ "More": "その他",
+ "Insert": "挿入",
+ "Slides": "スライド",
+ "Format": "書式",
"Backed up in this browser": "このブラウザに保存しました",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "未保存の変更 — {when} にこのブラウザへ保存済みで、再度開いたときに復元できます。⌘S は更新されたコピーをダウンロードします。",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "未保存の変更 — ⌘S は更新されたコピーをダウンロードします(このブラウザはファイルを上書きできません)",
diff --git a/slides/src/i18n/zh-Hans.ts b/slides/src/i18n/zh-Hans.ts
index 68776ba3..d747ece2 100644
--- a/slides/src/i18n/zh-Hans.ts
+++ b/slides/src/i18n/zh-Hans.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const zhHans: Catalog = {
+ "More": "更多",
+ "Insert": "插入",
+ "Slides": "幻灯片",
+ "Format": "格式",
"Backed up in this browser": "已备份到此浏览器",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "未保存的更改 — 已于 {when} 保存在此浏览器中,重新打开时可以恢复。⌘S 将下载更新后的副本。",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "未保存的更改 — ⌘S 将下载更新后的副本(此浏览器无法改写文件)",
diff --git a/slides/src/i18n/zh-Hant.ts b/slides/src/i18n/zh-Hant.ts
index d669909f..1c4f52fb 100644
--- a/slides/src/i18n/zh-Hant.ts
+++ b/slides/src/i18n/zh-Hant.ts
@@ -4,6 +4,10 @@
import type { Catalog } from '../i18n'
export const zhHant: Catalog = {
+ "More": "更多",
+ "Insert": "插入",
+ "Slides": "投影片",
+ "Format": "格式",
"Backed up in this browser": "已備份到此瀏覽器",
"Unsaved changes — kept in this browser at {when} and offered back if you reopen. ⌘S downloads an updated copy.": "未儲存的變更 — 已於 {when} 保存在此瀏覽器中,重新開啟時可以還原。⌘S 會下載更新後的副本。",
"Unsaved changes — ⌘S downloads an updated copy (this browser can’t rewrite the file)": "未儲存的變更 — ⌘S 會下載更新後的副本(此瀏覽器無法改寫檔案)",
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 1d8b1054..5edc6117 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -31,6 +31,10 @@ html, body {
display: flex;
flex-direction: column;
user-select: none;
+ /* Nothing in this column may leak sideways. Without this, a topbar wider than
+ the viewport turned into DOCUMENT scroll — on a phone the bar needed 681px
+ of a 402px screen, so swiping the toolbar dragged the whole canvas off. */
+ overflow: hidden;
}
/* iOS Safari (WebKit) renders a <select>'s chosen value as BLANK text when any
ancestor sets user-select:none — restore it on form fields app-wide. Inputs
@@ -1817,6 +1821,46 @@ body.ed-col-resizing { cursor: col-resize; user-select: none; }
.ed-logo > b { display: none; } /* mark only — the icon is the brand */
}
+/* --- phones: the bar cannot fit, so most of it moves into menus -----------
+ Hiding labels is not enough — 17 icon buttons at 36px plus gaps is an
+ irreducible ~684px floor. Under 700px (the same threshold the JS uses to
+ collapse both panels) applyPhoneChrome() REPARENTS the low-priority controls
+ into "+" and "⋯" dropdowns, leaving: logo · title · ☰ · + · undo · format ·
+ save · ⋯ . Labels come back inside menus via the 1200px rule above. */
+/* the phone-only controls exist in the DOM at every width; only the query shows
+ them, so applyPhoneChrome never has to create or destroy anything */
+.ed-phone-only { display: none; }
+@media (max-width: 700px) {
+ .ed-phone-only { display: inline-flex; }
+ /* HIG touch targets — a 36px icon is a mis-tap on glass */
+ .ed-topbar .ed-btn { min-width: 44px; min-height: 44px; justify-content: center; }
+ .ed-topbar .ed-menu .ed-btn { min-width: 0; } /* menu rows are text, not targets */
+ .ed-title { flex: 0 1 90px; }
+
+ /* Panels become OVERLAY DRAWERS. As flex siblings the 188px sidebar left a
+ 214px canvas on a 402px screen — the thing you are editing became the
+ smallest thing on screen. */
+ .ed-sidebar, .ed-props {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ z-index: 40;
+ box-shadow: 0 0 40px rgb(15 23 36 / 0.18);
+ background: var(--chrome, #fff);
+ }
+ .ed-sidebar { left: 0; }
+ .ed-props { right: 0; }
+ .ed-sidebar.ed-collapsed, .ed-props.ed-collapsed { box-shadow: none; }
+ .ed-main { position: relative; }
+ /* the 16px resizer chevrons are replaced by real buttons in the bar */
+ .ed-panel-toggle { display: none; }
+ /* Save stays one tap; its save-AS caret does not fit and is the least-used
+ half. KNOWN GAP: copy / new deck / template / password are unreachable on
+ a phone until they move into ⋯. */
+ .ed-topbar .ed-split-caret { display: none; }
+ .ed-title { min-width: 0; }
+}
+
/* panel collapse chevrons live ON the resizer strips, not in the topbar */
.ed-resizer { position: relative; }
.ed-panel-toggle {