Skip to content

armgit / bento

Public Imported from GitHub
0

Bento, the office suite that fits in a file

Point-anchored comments + window.bento.comments() for AI tooling

nyblnet3b573449f425
diff --git a/CLAUDE.md b/CLAUDE.md
index 35e5e05d..66cbec19 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -68,9 +68,13 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.
leftovers are dropped UNLESS they are text someone wrote; user extras stay.
- **Comments**: `Slide.comments` threads (author/at/text/replies/resolved) —
saved in the file, editor-only (canvas markers + thread popover via
- editor/comments.ts; never in present/print). Anchored to an element id or
- the slide; author name in localStorage 'bento-author'; unresolved threads
- badge the sidebar thumb. Panel buttons dispatch 'bento:add-comment'.
+ 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.
- **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.
diff --git a/docs/architecture.md b/docs/architecture.md
index 3c249520..428c47fd 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -175,7 +175,7 @@ BentoDoc
├─ name? · notes
├─ stateOf? ← marks a hidden interactive state of another slide
├─ hover? ← { type:'focus-group', dim } | { type:'reveal', default }
- ├─ comments? ← review threads (editor-only; never presented/printed)
+ ├─ comments? ← review threads, anchored to element/point/slide (editor-only; window.bento.comments() for tooling)
└─ elements: SlideElement[] ← array order = paint order (z)
├─ common: id · x y w h · rotation · opacity
│ fx? · link? · group? · groupId? · showOnHover? · role?
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.ts
index 0e5fc2ea..87e39082 100644
--- a/slides/src/editor/canvas.ts
+++ b/slides/src/editor/canvas.ts
@@ -90,7 +90,8 @@ export class SlideCanvas {
this.comments = new CommentsUI(store, this.stage, () => this.scale)
document.addEventListener('bento:add-comment', ((ev: CustomEvent) => {
- this.comments.openNew(ev.detail?.elementId)
+ 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
@@ -175,6 +176,33 @@ 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() {
+ this.stage.style.cursor = 'crosshair'
+ const cleanup = () => {
+ this.stage.style.cursor = ''
+ document.removeEventListener('mousedown', onDown, true)
+ document.removeEventListener('keydown', onKey, true)
+ }
+ const onDown = (ev: MouseEvent) => {
+ cleanup()
+ const r = this.scaleHost.getBoundingClientRect()
+ 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
+ ev.preventDefault()
+ ev.stopPropagation()
+ this.comments.openNew(undefined, { x, y })
+ }
+ const onKey = (ev: KeyboardEvent) => {
+ if (ev.key === 'Escape') cleanup()
+ }
+ document.addEventListener('mousedown', onDown, true)
+ document.addEventListener('keydown', onKey, true)
+ }
+
/** Grow a selection to whole groups: any member pulls in its groupId kin.
* (Alt-click deep select bypasses this — that's how you reach a member.) */
private expandGroups(ids: string[]): string[] {
diff --git a/slides/src/editor/comments.ts b/slides/src/editor/comments.ts
index 940ced64..d13cd477 100644
--- a/slides/src/editor/comments.ts
+++ b/slides/src/editor/comments.ts
@@ -55,6 +55,11 @@ export class CommentsUI {
if (el) {
marker.style.left = `${(el.x + el.w) * scale - 9}px`
marker.style.top = `${el.y * scale - 9}px`
+ } else if (typeof c.x === 'number' && typeof c.y === 'number') {
+ // point anchor: the teardrop's bottom-left tip sits ON the point
+ marker.classList.add('point')
+ marker.style.left = `${c.x * scale}px`
+ marker.style.top = `${c.y * scale - 19}px`
} else {
marker.style.left = '10px'
marker.style.top = `${10 + slideStack * 26}px`
@@ -68,14 +73,14 @@ export class CommentsUI {
})
}
- /** Start a new thread on an element (or the slide) and open its popover. */
- openNew(elementId?: string) {
+ /** Start a new thread on an element, at a point, or on the slide. */
+ openNew(elementId?: string, point?: { x: number; y: number }) {
const author = commentAuthor()
if (!author) return
const text = window.prompt('Comment:')?.trim()
if (!text) return
const comment: Comment = {
- id: uid('cmt'), elementId, author, text, at: new Date().toISOString(),
+ id: uid('cmt'), elementId, ...(point ?? {}), author, text, at: new Date().toISOString(),
}
this.store.commit(() => {
const s = this.store.slide
@@ -95,7 +100,9 @@ export class CommentsUI {
const head = document.createElement('div')
head.className = 'ed-comment-pop-head'
- head.textContent = c.elementId ? 'Comment · element' : 'Comment · slide'
+ head.textContent = c.elementId
+ ? 'Comment · element'
+ : typeof c.x === 'number' ? `Comment · point (${c.x}, ${c.y})` : 'Comment · slide'
pop.appendChild(head)
const entries = document.createElement('div')
diff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.ts
index 5c11d380..2cf71638 100644
--- a/slides/src/editor/panels.ts
+++ b/slides/src/editor/panels.ts
@@ -157,6 +157,14 @@ export class PropsPanel {
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)
+
const applyLy = document.createElement('button')
applyLy.className = 'ed-btn ed-btn-block'
applyLy.textContent = '⧉ Apply layout…'
diff --git a/slides/src/main.ts b/slides/src/main.ts
index dee90b2f..5ad1ad4f 100644
--- a/slides/src/main.ts
+++ b/slides/src/main.ts
@@ -58,4 +58,29 @@ if (location.hash === '#present') {
},
/** animation engine, exposed for scripting/diagnostics */
anim,
+ /**
+ * Flat list of every review comment thread — the entry point for tooling
+ * and AI agents processing the deck ("fix everything people flagged"):
+ * each item carries the slide, a typed anchor (element / point / slide),
+ * author, text, replies and resolved state.
+ */
+ comments() {
+ return store.doc.slides.flatMap((s, slideIndex) =>
+ (s.comments ?? []).map((c) => ({
+ slideId: s.id,
+ slideIndex,
+ id: c.id,
+ anchor: c.elementId
+ ? { type: 'element' as const, elementId: c.elementId }
+ : typeof c.x === 'number'
+ ? { type: 'point' as const, x: c.x, y: c.y }
+ : { type: 'slide' as const },
+ author: c.author,
+ at: c.at,
+ text: c.text,
+ replies: c.replies ?? [],
+ resolved: !!c.resolved,
+ })),
+ )
+ },
}
diff --git a/slides/src/model.ts b/slides/src/model.ts
index 9d33fc2c..02548968 100644
--- a/slides/src/model.ts
+++ b/slides/src/model.ts
@@ -165,6 +165,9 @@ export interface Comment {
id: string
/** element the thread is anchored to; absent (or dangling) = the slide */
elementId?: string
+ /** point anchor in slide coordinates — used when no elementId is set */
+ x?: number
+ y?: number
author: string
text: string
/** ISO datetime */