Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

One comment tool; collapsible panel sections

nyblnet54f6612fa37d
diff --git a/CLAUDE.md b/CLAUDE.md
index 66cbec19..16a67dcb 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -71,10 +71,12 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.
editor/comments.ts; never in present/print). Anchors: element id, POINT
(x/y slide coords β€” "πŸ“ Comment at a point" arms a one-shot crosshair
click, Esc cancels), or the slide. Author name in localStorage
- 'bento-author'; unresolved threads badge the sidebar thumb. Panel buttons
- dispatch 'bento:add-comment'. `window.bento.comments()` returns the flat
- typed-anchor list β€” the entry point for AI agents processing flagged
- issues in a deck.
+ 'bento-author'; unresolved threads badge the sidebar thumb. ONE entry
+ point: the topbar πŸ’¬ tool (C) β€” armed click on an element anchors there,
+ on empty canvas anchors the point; near-full-slide backdrops never
+ capture (a comment on scenery means the spot). `window.bento.comments()`
+ returns the flat typed-anchor list β€” the entry point for AI agents
+ processing flagged issues in a deck.
- **Hover content is in-slide, not states**: `showOnHover` sets + slide
`hover:'reveal'` (with a default set) swap content on pointer-over. Editor previews
one set at a time. Rule of thumb: click β†’ state slide; hover β†’ reveal set.
@@ -86,6 +88,11 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.
"Sync from parent" (id-lineage merge β€” generators must emit deterministic
element ids for it and for cross-state morphs); slide deletion cascades states
and clears inbound links after confirm; `[`/`]` collapse the side panels.
+- **Panel accordion**: every `.ed-section` header is retrofitted into a
+ collapsible group after each rebuild (panels.applyAccordion) β€” open state
+ persisted per title in localStorage; Presenting/Interactivity/Layout
+ default closed. Add new panel content under a section header and the
+ accordion picks it up automatically.
- `src/editor/` β€” vanilla-TS editor. Moveable + Selecto handle manipulation.
Alt/Option-click digs through overlapping elements (capture-phase, beats
Moveable's control box). Fill/stroke colors carry alpha (color input + % pair,
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.ts
index 87e39082..1e8c3a0e 100644
--- a/slides/src/editor/canvas.ts
+++ b/slides/src/editor/canvas.ts
@@ -89,10 +89,6 @@ export class SlideCanvas {
}) as EventListener)
this.comments = new CommentsUI(store, this.stage, () => this.scale)
- document.addEventListener('bento:add-comment', ((ev: CustomEvent) => {
- if (ev.detail?.point) this.armPointComment()
- else this.comments.openNew(ev.detail?.elementId)
- }) as EventListener)
// Alt/Option-click digs through overlapping elements: first click grabs
// the topmost, each further alt-click steps one element deeper (wrapping).
@@ -176,14 +172,32 @@ export class SlideCanvas {
this.wrap.appendChild(bar)
}
- /** One-shot mode: the next canvas click drops a point-anchored comment.
- * Capture phase so Selecto/Moveable never see the click; Esc cancels. */
- private armPointComment() {
+ /** notified when the comment tool arms/disarms (topbar button state) */
+ onCommentModeChange: ((on: boolean) => void) | null = null
+ private commentCleanup: (() => void) | null = null
+
+ get isCommentMode() {
+ return !!this.commentCleanup
+ }
+
+ /**
+ * The unified comment tool. Armed: the next canvas click anchors a new
+ * thread β€” on the ELEMENT under the cursor when there is one, else at
+ * that POINT of the slide. Capture phase (Selecto/Moveable never see the
+ * click); Esc or toggling again disarms.
+ */
+ toggleCommentMode() {
+ if (this.commentCleanup) {
+ this.commentCleanup()
+ return
+ }
this.stage.style.cursor = 'crosshair'
const cleanup = () => {
+ this.commentCleanup = null
this.stage.style.cursor = ''
document.removeEventListener('mousedown', onDown, true)
document.removeEventListener('keydown', onKey, true)
+ this.onCommentModeChange?.(false)
}
const onDown = (ev: MouseEvent) => {
cleanup()
@@ -191,16 +205,29 @@ export class SlideCanvas {
const x = Math.round((ev.clientX - r.left) / this.scale)
const y = Math.round((ev.clientY - r.top) / this.scale)
const { width, height } = this.store.doc.size
- if (x < 0 || y < 0 || x > width || y > height) return // clicked outside the slide
+ if (x < 0 || y < 0 || x > width || y > height) return // outside the slide
ev.preventDefault()
ev.stopPropagation()
- this.comments.openNew(undefined, { x, y })
+ // topmost element under the point wins; empty canvas β†’ point anchor.
+ // Near-full-slide elements (photos, scrims) don't capture β€” a comment
+ // "here" on scenery means the spot, not the backdrop object.
+ let hit: string | undefined
+ const slideArea = width * height
+ for (const el of this.store.slide.elements) {
+ if (x < el.x || x > el.x + el.w || y < el.y || y > el.y + el.h) continue
+ if (el.w * el.h >= slideArea * 0.8) continue
+ const node = this.scaleHost.querySelector<HTMLElement>(`[data-el-id="${CSS.escape(el.id)}"]`)
+ if (node && node.style.display !== 'none') hit = el.id
+ }
+ this.comments.openNew(hit, hit ? undefined : { x, y })
}
const onKey = (ev: KeyboardEvent) => {
if (ev.key === 'Escape') cleanup()
}
+ this.commentCleanup = cleanup
document.addEventListener('mousedown', onDown, true)
document.addEventListener('keydown', onKey, true)
+ this.onCommentModeChange?.(true)
}
/** Grow a selection to whole groups: any member pulls in its groupId kin.
diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.ts
index 9f654b20..3a42e6a3 100644
--- a/slides/src/editor/editor.ts
+++ b/slides/src/editor/editor.ts
@@ -90,6 +90,9 @@ export class Editor {
btn(ICONS.image, 'Image', () => this.pickImage()),
btn(ICONS.chart, 'Chart', () => this.canvas.insert(defaultChart(CHART_PRESETS.bar()))),
)
+ const commentB = btn(ICONS.comment, '', () => this.canvas.toggleCommentMode(),
+ 'Comment (C) β€” click an element or a spot on the slide')
+ insert.appendChild(commentB)
const actions = div('ed-group ed-group-right')
const undoB = btn(ICONS.undo, '', () => this.store.undo(), 'Undo (⌘Z)')
@@ -116,6 +119,7 @@ export class Editor {
this.restorePanelWidths()
this.canvas = new SlideCanvas(canvasWrap, this.store)
+ this.canvas.onCommentModeChange = (on) => commentB.classList.toggle('ed-btn-armed', on)
this.panel = new PropsPanel(this.props, this.store)
}
@@ -593,6 +597,11 @@ export class Editor {
}
if (inField) return
+ if (!mod && ev.key.toLowerCase() === 'c') {
+ ev.preventDefault()
+ this.canvas.toggleCommentMode()
+ return
+ }
if (mod && ev.key.toLowerCase() === 'g') {
ev.preventDefault()
const els = this.store.selectedElements
diff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.ts
index 2cf71638..3ec03842 100644
--- a/slides/src/editor/panels.ts
+++ b/slides/src/editor/panels.ts
@@ -54,6 +54,46 @@ export class PropsPanel {
if (els.length === 0) this.buildSlidePanel()
else if (els.length === 1) this.buildElementPanel(els[0])
else this.buildMultiPanel(els)
+ this.applyAccordion()
+ }
+
+ /** Collapsed by default until the user opens them (persisted per title). */
+ private static CLOSED_BY_DEFAULT = new Set(['Presenting', 'Interactivity', 'Layout'])
+
+ /**
+ * Retrofit the flat panel into an accordion: every .ed-section header
+ * gathers its following siblings into a collapsible body. Open state is
+ * remembered per section title β€” everything stays discoverable (headers
+ * always visible) while rarely-used sections stop costing space.
+ */
+ private applyAccordion() {
+ let openState: Record<string, boolean> = {}
+ try { openState = JSON.parse(localStorage.getItem('bento-panel-open') ?? '{}') } catch { /* defaults */ }
+ const headers = [...this.host.querySelectorAll<HTMLElement>('.ed-section')]
+ for (const h of headers) {
+ const key = h.textContent ?? ''
+ const body = document.createElement('div')
+ body.className = 'ed-section-body'
+ let n: ChildNode | null = h.nextSibling
+ while (n && !(n instanceof HTMLElement && n.classList.contains('ed-section'))) {
+ const next: ChildNode | null = n.nextSibling
+ body.appendChild(n)
+ n = next
+ }
+ h.after(body)
+ const isOpen = openState[key] ?? !PropsPanel.CLOSED_BY_DEFAULT.has(key)
+ h.classList.add('ed-sec-toggle')
+ if (!isOpen) {
+ h.classList.add('closed')
+ body.style.display = 'none'
+ }
+ h.addEventListener('click', () => {
+ const nowClosed = h.classList.toggle('closed')
+ body.style.display = nowClosed ? 'none' : ''
+ openState[key] = !nowClosed
+ localStorage.setItem('bento-panel-open', JSON.stringify(openState))
+ })
+ }
}
// --- builders ---------------------------------------------------------------
@@ -68,10 +108,12 @@ export class PropsPanel {
slide.transition,
(v) => this.edit(() => { this.store.slide.transition = v as TransitionKind }, true),
))
- const hint = document.createElement('p')
- hint.className = 'ed-hint'
- hint.innerHTML = '<b>Morph</b> animates elements that appear on both this slide and the previous one (copy a slide, then move things around).'
- this.host.appendChild(hint)
+ if (slide.transition === 'morph') {
+ const hint = document.createElement('p')
+ hint.className = 'ed-hint'
+ hint.innerHTML = '<b>Morph</b> animates elements that appear on both this slide and the previous one (copy a slide, then move things around).'
+ this.host.appendChild(hint)
+ }
// interactivity: naming, state-of, hover focus
this.section('Interactivity')
@@ -150,21 +192,7 @@ export class PropsPanel {
}
}
- const cmtS = document.createElement('button')
- cmtS.className = 'ed-btn ed-btn-block'
- cmtS.textContent = 'πŸ’¬ Comment on this slide'
- cmtS.addEventListener('click', () =>
- document.dispatchEvent(new CustomEvent('bento:add-comment', { detail: {} })))
- this.host.appendChild(cmtS)
-
- const cmtP = document.createElement('button')
- cmtP.className = 'ed-btn ed-btn-block'
- cmtP.textContent = 'πŸ“ Comment at a point…'
- cmtP.title = 'Click a spot on the slide to pin the comment there'
- cmtP.addEventListener('click', () =>
- document.dispatchEvent(new CustomEvent('bento:add-comment', { detail: { point: true } })))
- this.host.appendChild(cmtP)
-
+ this.section('Layout')
const applyLy = document.createElement('button')
applyLy.className = 'ed-btn ed-btn-block'
applyLy.textContent = '⧉ Apply layout…'
@@ -229,12 +257,6 @@ export class PropsPanel {
else e.role = v
}, true)))
- const cmt = document.createElement('button')
- cmt.className = 'ed-btn ed-btn-block'
- cmt.textContent = 'πŸ’¬ Comment on this element'
- cmt.addEventListener('click', () =>
- document.dispatchEvent(new CustomEvent('bento:add-comment', { detail: { elementId: el.id } })))
- this.host.appendChild(cmt)
if (el.type === 'text') this.buildTextProps(el)
if (el.type === 'shape') this.buildShapeProps(el)
diff --git a/slides/src/icons.ts b/slides/src/icons.ts
index a375413c..c1565e35 100644
--- a/slides/src/icons.ts
+++ b/slides/src/icons.ts
@@ -7,6 +7,7 @@ export const ICONS = {
text: svg('<polyline points="4 7 4 4 20 4 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="4" x2="12" y2="20"/>'),
shapes: svg('<rect x="3" y="3" width="10" height="10" rx="1.5"/><circle cx="16.5" cy="16.5" r="4.5"/>'),
image: svg('<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15-3.5-3.5L6 23"/>'),
+ comment: svg('<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>'),
chart: svg('<path d="M3 3v16a2 2 0 0 0 2 2h16"/><path d="M18 17V9"/><path d="M13 17V5"/><path d="M8 17v-3"/>'),
undo: svg('<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>'),
redo: svg('<path d="m15 14 5-5-5-5"/><path d="M20 9H9.5a5.5 5.5 0 0 0 0 11H13"/>'),
diff --git a/slides/src/styles.css b/slides/src/styles.css
index 0460ebc9..78d53b2f 100644
--- a/slides/src/styles.css
+++ b/slides/src/styles.css
@@ -498,6 +498,29 @@ html, body {
}
.ed-arrange-btn:disabled { opacity: 0.35; cursor: default; }
+/* armed topbar tool (comment mode) */
+.ed-btn-armed { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-ink); }
+.ed-btn-armed:hover { background: color-mix(in srgb, var(--accent) 30%, transparent); }
+
+/* collapsible panel sections */
+.ed-sec-toggle { cursor: pointer; user-select: none; position: relative; padding-left: 14px; }
+.ed-sec-toggle::before {
+ content: '';
+ position: absolute;
+ left: 1px;
+ top: 50%;
+ width: 0; height: 0;
+ border-left: 5px solid currentColor;
+ border-top: 4px solid transparent;
+ border-bottom: 4px solid transparent;
+ transform: translateY(-50%) rotate(90deg);
+ transition: transform 0.12s ease;
+ opacity: 0.55;
+}
+.ed-sec-toggle.closed::before { transform: translateY(-50%); }
+.ed-sec-toggle:hover { color: var(--ink); }
+.ed-section-body { display: flex; flex-direction: column; }
+
/* review comments: canvas markers, thread popover, thumb badge */
.ed-comment-layer { position: absolute; inset: 0; pointer-events: none; z-index: 12; }
.ed-comment-marker {