Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Review comments on slides and elements
nyblnetfa589d50fb93
diff --git a/CLAUDE.md b/CLAUDE.mdindex d3a0a3b5..35e5e05d 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -66,6 +66,11 @@ One HTML file = the document + viewer + editor. See `README.md` for the vision.then by `role` (title/subtitle/body/kicker — Role select in the elementpanel); layout supplies frame+typography, content rides along; layout-ownedleftovers 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'.- **Hover content is in-slide, not states**: `showOnHover` sets + slide`hover:'reveal'` (with a default set) swap content on pointer-over. Editor previewsone set at a time. Rule of thumb: click → state slide; hover → reveal set.diff --git a/docs/architecture.md b/docs/architecture.mdindex 64cf38b3..3c249520 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -175,6 +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)└─ 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.tsindex 884f1c93..0e5fc2ea 100644--- a/slides/src/editor/canvas.ts+++ b/slides/src/editor/canvas.ts@@ -9,6 +9,7 @@ import type { SlideElement } from '../model'import { renderSlide, sanitizeHtml } from '../render'import { autoformatAtCaret, clearAutoformat, markdownToHtml, undoAutoformat } from './markdown'import { PathEditor } from './patheditor'+import { CommentsUI } from './comments'export class SlideCanvas {private stage: HTMLElement@@ -24,6 +25,7 @@ export class SlideCanvas {private zoomLabel: HTMLElement | null = nullprivate editing: HTMLElement | null = nullprivate pathEditor!: PathEditor+ private comments!: CommentsUIconstructor(private wrap: HTMLElement,@@ -86,6 +88,11 @@ export class SlideCanvas {this.startPathEdit(ev.detail.id)}) as EventListener)+ this.comments = new CommentsUI(store, this.stage, () => this.scale)+ document.addEventListener('bento:add-comment', ((ev: CustomEvent) => {+ 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).// Capture phase so it wins over Selecto AND Moveable's control-box area,@@ -129,6 +136,7 @@ export class SlideCanvas {this.moveable.zoom = 1 / this.scalethis.moveable.updateRect()if (this.zoomLabel) this.zoomLabel.textContent = `${Math.round(this.scale * 100)}%`+ this.comments?.refresh()}// --- zoom ------------------------------------------------------------------diff --git a/slides/src/editor/comments.ts b/slides/src/editor/comments.tsnew file mode 100644index 00000000..940ced64--- /dev/null+++ b/slides/src/editor/comments.ts@@ -0,0 +1,177 @@+// Review comments. Threads live in Slide.comments (saved with the file,+// never rendered in present/print). The editor shows them as small numbered+// markers on the canvas — at the anchored element's top-right corner, or+// stacked in the slide's top-left for slide-level (and orphaned) threads.+// Clicking a marker opens the thread popover: entries, reply, resolve, delete.++import type { Store } from '../store'+import { uid, type Comment } from '../model'++/** The commenter's name, remembered per browser; asked for on first use. */+export function commentAuthor(): string | null {+ let name = localStorage.getItem('bento-author')+ if (!name) {+ name = window.prompt('Your name (shown on comments):')?.trim() || ''+ if (!name) return null+ localStorage.setItem('bento-author', name)+ }+ return name+}++function relTime(iso: string): string {+ const s = (Date.now() - new Date(iso).getTime()) / 1000+ if (!Number.isFinite(s) || s < 45) return 'just now'+ if (s < 3600) return `${Math.round(s / 60)}m ago`+ if (s < 86400) return `${Math.round(s / 3600)}h ago`+ if (s < 86400 * 30) return `${Math.round(s / 86400)}d ago`+ return new Date(iso).toLocaleDateString()+}++export class CommentsUI {+ private layer: HTMLElement++ constructor(+ private store: Store,+ stageParent: HTMLElement,+ private scaleOf: () => number,+ ) {+ this.layer = document.createElement('div')+ this.layer.className = 'ed-comment-layer'+ stageParent.appendChild(this.layer)+ }++ /** Rebuild the markers for the current slide (call after render/relayout). */+ refresh() {+ this.layer.innerHTML = ''+ const slide = this.store.slide+ const scale = this.scaleOf()+ let slideStack = 0+ ;(slide.comments ?? []).forEach((c) => {+ const el = c.elementId ? slide.elements.find((e) => e.id === c.elementId) : undefined+ const marker = document.createElement('button')+ marker.className = 'ed-comment-marker' + (c.resolved ? ' resolved' : '')+ marker.textContent = String(1 + (c.replies?.length ?? 0))+ marker.title = `${c.author}: ${c.text.slice(0, 80)}`+ if (el) {+ marker.style.left = `${(el.x + el.w) * scale - 9}px`+ marker.style.top = `${el.y * scale - 9}px`+ } else {+ marker.style.left = '10px'+ marker.style.top = `${10 + slideStack * 26}px`+ slideStack+++ }+ marker.addEventListener('click', (ev) => {+ ev.stopPropagation()+ this.openThread(c.id, marker)+ })+ this.layer.appendChild(marker)+ })+ }++ /** Start a new thread on an element (or the slide) and open its popover. */+ openNew(elementId?: string) {+ 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(),+ }+ this.store.commit(() => {+ const s = this.store.slide+ s.comments = [...(s.comments ?? []), comment]+ })+ this.refresh()+ }++ private openThread(commentId: string, anchor: HTMLElement) {+ document.querySelector('.ed-comment-pop')?.remove()+ const slide = this.store.slide+ const c = slide.comments?.find((x) => x.id === commentId)+ if (!c) return++ const pop = document.createElement('div')+ pop.className = 'ed-comment-pop'++ const head = document.createElement('div')+ head.className = 'ed-comment-pop-head'+ head.textContent = c.elementId ? 'Comment · element' : 'Comment · slide'+ pop.appendChild(head)++ const entries = document.createElement('div')+ entries.className = 'ed-comment-entries'+ const entry = (author: string, at: string, text: string) => {+ const e = document.createElement('div')+ e.className = 'ed-comment-entry'+ e.innerHTML = `<b></b> <span class="ed-comment-time"></span><p></p>`+ e.querySelector('b')!.textContent = author+ e.querySelector('span')!.textContent = relTime(at)+ e.querySelector('p')!.textContent = text+ entries.appendChild(e)+ }+ entry(c.author, c.at, c.text)+ for (const r of c.replies ?? []) entry(r.author, r.at, r.text)+ pop.appendChild(entries)++ const reply = document.createElement('textarea')+ reply.className = 'ed-comment-reply'+ reply.rows = 2+ reply.placeholder = 'Reply…'+ pop.appendChild(reply)++ const foot = document.createElement('div')+ foot.className = 'ed-comment-pop-foot'+ const mkBtn = (label: string, onClick: () => void, cls = 'ed-btn') => {+ const b = document.createElement('button')+ b.className = cls+ b.textContent = label+ b.addEventListener('click', onClick)+ return b+ }+ foot.append(+ mkBtn('Reply', () => {+ const text = reply.value.trim()+ const author = commentAuthor()+ if (!text || !author) return+ this.store.commit(() => {+ const live = this.store.slide.comments?.find((x) => x.id === commentId)+ if (live) live.replies = [...(live.replies ?? []), { id: uid('cmt'), author, text, at: new Date().toISOString() }]+ })+ pop.remove()+ this.refresh()+ }),+ mkBtn(c.resolved ? 'Reopen' : 'Resolve', () => {+ this.store.commit(() => {+ const live = this.store.slide.comments?.find((x) => x.id === commentId)+ if (live) live.resolved = !live.resolved+ })+ pop.remove()+ this.refresh()+ }),+ mkBtn('Delete', () => {+ this.store.commit(() => {+ const s = this.store.slide+ s.comments = (s.comments ?? []).filter((x) => x.id !== commentId)+ if (!s.comments.length) delete s.comments+ })+ pop.remove()+ this.refresh()+ }),+ )+ pop.appendChild(foot)++ const r = anchor.getBoundingClientRect()+ pop.style.left = `${Math.max(8, Math.min(r.right + 8, window.innerWidth - 320))}px`+ pop.style.top = `${Math.max(8, Math.min(r.top - 10, window.innerHeight - 300))}px`+ document.body.appendChild(pop)+ reply.focus()++ const close = (ev: PointerEvent) => {+ if (!pop.contains(ev.target as Node)) {+ pop.remove()+ document.removeEventListener('pointerdown', close, true)+ }+ }+ setTimeout(() => document.addEventListener('pointerdown', close, true))+ }+}diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.tsindex d5afad2b..9f654b20 100644--- a/slides/src/editor/editor.ts+++ b/slides/src/editor/editor.ts@@ -223,6 +223,11 @@ export class Editor {// thumb width tracks the (resizable) sidebar; states render smallerconst base = Math.max(96, this.panelW.left - 40)const surface = renderThumbnail(slide, this.store.doc, isState ? Math.round(base * 0.84) : base)+ if (slide.comments?.some((c) => !c.resolved)) {+ const badge = div('ed-thumb-cmt')+ badge.title = `${slide.comments.filter((c) => !c.resolved).length} open comment(s)`+ item.appendChild(badge)+ }const tools = div('ed-thumb-tools')tools.append(btn(ICONS.copy, '', (ev) => { ev.stopPropagation(); this.duplicateSlide(i) }, 'Duplicate slide'),@@ -408,6 +413,16 @@ export class Editor {if (!slide) returnconst w = slide.stateOf ? Math.round(base * 0.84) : baseitem.querySelector('.bento-thumb-surface')?.replaceWith(renderThumbnail(slide, this.store.doc, w))+ // comment badge tracks doc-level changes too (comments emit 'doc')+ const open = slide.comments?.some((c) => !c.resolved)+ const badge = item.querySelector('.ed-thumb-cmt')+ if (open && !badge) {+ const b = div('ed-thumb-cmt')+ b.title = 'Open comment(s)'+ item.appendChild(b)+ } else if (!open && badge) {+ badge.remove()+ }})}, 150)}diff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.tsindex 9d30ee7e..5c11d380 100644--- a/slides/src/editor/panels.ts+++ b/slides/src/editor/panels.ts@@ -150,6 +150,13 @@ 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 applyLy = document.createElement('button')applyLy.className = 'ed-btn ed-btn-block'applyLy.textContent = '⧉ Apply layout…'@@ -214,6 +221,13 @@ 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)if (el.type === 'image') this.buildImageProps(el)diff --git a/slides/src/model.ts b/slides/src/model.tsindex 705168aa..9d33fc2c 100644--- a/slides/src/model.ts+++ b/slides/src/model.ts@@ -156,6 +156,23 @@ export interface ChartElement extends ElementBase {export type SlideElement = TextElement | ShapeElement | ImageElement | SvgElement | ChartElement+/**+ * A review comment thread. Editor-only metadata: never rendered while+ * presenting or printing, but saved in the file so it travels with the+ * document when people pass it around.+ */+export interface Comment {+ id: string+ /** element the thread is anchored to; absent (or dangling) = the slide */+ elementId?: string+ author: string+ text: string+ /** ISO datetime */+ at: string+ resolved?: boolean+ replies?: Array<{ id: string; author: string; text: string; at: string }>+}+export interface Slide {id: stringbackground: string@@ -179,6 +196,8 @@ export interface Slide {* (`default` names the set visible when nothing is hovered)*/hover?: { type: 'focus-group' | 'reveal'; dim?: number; default?: string }+ /** review comment threads (editor-only; see Comment) */+ comments?: Comment[]}export interface BentoDoc {diff --git a/slides/src/styles.css b/slides/src/styles.cssindex 5f6ebf28..0460ebc9 100644--- a/slides/src/styles.css+++ b/slides/src/styles.css@@ -498,6 +498,74 @@ html, body {}.ed-arrange-btn:disabled { opacity: 0.35; cursor: default; }+/* review comments: canvas markers, thread popover, thumb badge */+.ed-comment-layer { position: absolute; inset: 0; pointer-events: none; z-index: 12; }+.ed-comment-marker {+ position: absolute;+ pointer-events: auto;+ width: 19px;+ height: 19px;+ border: none;+ border-radius: 50% 50% 50% 3px;+ background: var(--accent);+ color: #3a2800;+ font: 700 10px/19px inherit;+ font-family: inherit;+ text-align: center;+ padding: 0;+ cursor: pointer;+ box-shadow: 0 2px 6px rgb(20 30 45 / 0.25);+}+.ed-comment-marker.resolved { opacity: 0.35; }+.ed-comment-marker:hover { transform: scale(1.15); }++.ed-comment-pop {+ position: fixed;+ z-index: 210;+ width: 300px;+ background: #fff;+ border: 1px solid var(--line);+ border-radius: 12px;+ box-shadow: 0 12px 32px rgb(15 23 36 / 0.18);+ padding: 12px 14px;+}+.ed-comment-pop-head {+ font-size: 10.5px;+ font-weight: 700;+ text-transform: uppercase;+ letter-spacing: 0.07em;+ color: var(--muted);+ margin-bottom: 8px;+}+.ed-comment-entries { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }+.ed-comment-entry b { font-size: 12.5px; }+.ed-comment-entry .ed-comment-time { font-size: 11px; color: var(--muted); margin-left: 5px; }+.ed-comment-entry p { margin: 2px 0 0; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }+.ed-comment-reply {+ width: 100%;+ margin-top: 10px;+ font: inherit;+ font-size: 12.5px;+ border: 1px solid var(--line);+ border-radius: 8px;+ padding: 7px 9px;+ resize: vertical;+}+.ed-comment-pop-foot { display: flex; gap: 6px; margin-top: 8px; }+.ed-comment-pop-foot .ed-btn { border: 1px solid var(--line); flex: 1; justify-content: center; padding: 5px 6px; font-size: 12px; }++.ed-thumb-cmt {+ position: absolute;+ bottom: 5px;+ right: 5px;+ z-index: 2;+ width: 9px;+ height: 9px;+ border-radius: 50% 50% 50% 2px;+ background: var(--accent);+ box-shadow: 0 0 0 2px #fff;+}+/* layout picker — popover over the New-slide button */.ed-layoutpick {position: fixed;