Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
Canvas hover-set switcher: edit reveal sets in place
nyblneta8497802de05
diff --git a/slides/src/editor/canvas.ts b/slides/src/editor/canvas.tsindex 523bba1e..ec65561e 100644--- a/slides/src/editor/canvas.ts+++ b/slides/src/editor/canvas.ts@@ -93,14 +93,16 @@ export class SlideCanvas {this.commitTextEdit()const slide = this.store.slideconst next = renderSlide(slide, this.store.doc)- // hover-reveal slides: preview one set at a time (panel picks which);- // hidden sets are display:none so they don't block selection- if (slide.elements.some((e) => e.showOnHover)) {- const active = this.store.hoverPreview ?? slide.hover?.default ?? null+ // hover-reveal slides: preview one set at a time; hidden sets are+ // display:none so they don't block selection+ const sets = [...new Set(slide.elements.map((e) => e.showOnHover).filter(Boolean))] as string[]+ if (sets.length) {+ const active = this.store.hoverPreview ?? slide.hover?.default ?? sets[0]for (const node of next.querySelectorAll<HTMLElement>('[data-show-on-hover]')) {if (node.dataset.showOnHover !== active) node.style.display = 'none'}}+ this.renderSetBar(sets)if (this.surface) this.surface.replaceWith(next)else this.scaleHost.appendChild(next)this.surface = next@@ -108,6 +110,39 @@ export class SlideCanvas {this.syncTargets()}+ /**+ * Canvas set-switcher: when a slide has hover-reveal sets, a chip bar sits+ * above the stage so each set is one click away while editing. Selection+ * survives the switch when the selected element is in the shown set.+ */+ private renderSetBar(sets: string[]) {+ this.wrap.querySelector('.ed-setbar')?.remove()+ if (!sets.length) return+ const slide = this.store.slide+ const active = this.store.hoverPreview ?? slide.hover?.default ?? sets[0]+ const bar = document.createElement('div')+ bar.className = 'ed-setbar'+ const label = document.createElement('span')+ label.className = 'ed-setbar-label'+ label.textContent = 'Hover set:'+ bar.appendChild(label)+ for (const set of sets) {+ const chip = document.createElement('button')+ chip.className = 'ed-setchip'+ chip.textContent = set + (slide.hover?.default === set ? ' ●' : '')+ chip.title = slide.hover?.default === set+ ? `"${set}" — shown when nothing is hovered (default set)`+ : `Preview and edit the "${set}" hover set`+ if (set === active) chip.classList.add('active')+ chip.addEventListener('click', () => {+ this.store.hoverPreview = set+ this.render()+ })+ bar.appendChild(chip)+ }+ this.wrap.appendChild(bar)+ }+private selectedNodes(): HTMLElement[] {if (!this.surface) return []return this.store.selection@@ -280,6 +315,13 @@ export class SlideCanvas {/** Insert an element, select it, and (for text) drop straight into editing. */insert(el: SlideElement, startEditing = false) {+ // inserting while previewing a non-default hover set joins that set —+ // "I'm editing the italy panel" means new content belongs to it+ const slide = this.store.slide+ const preview = this.store.hoverPreview+ if (preview && slide.hover?.type === 'reveal' && preview !== slide.hover.default) {+ el.showOnHover = preview+ }this.store.commit(() => this.store.slide.elements.push(el))this.store.select([el.id])if (startEditing && el.type === 'text') {diff --git a/slides/src/editor/editor.ts b/slides/src/editor/editor.tsindex ab074579..efce34f2 100644--- a/slides/src/editor/editor.ts+++ b/slides/src/editor/editor.ts@@ -298,7 +298,8 @@ export class Editor {if (this.presenting) returnconst mod = ev.metaKey || ev.ctrlKeyconst inField =- (ev.target as HTMLElement).closest('input, textarea, select, [contenteditable="true"]') != null+ ev.target instanceof Element &&+ ev.target.closest('input, textarea, select, [contenteditable="true"]') != nullif (mod && ev.key.toLowerCase() === 's') {ev.preventDefault()diff --git a/slides/src/editor/panels.ts b/slides/src/editor/panels.tsindex bf8571ba..3f124dc7 100644--- a/slides/src/editor/panels.ts+++ b/slides/src/editor/panels.ts@@ -220,11 +220,15 @@ export class PropsPanel {soh.placeholder = 'always visible'soh.value = el.showOnHover ?? ''soh.title = "Only visible while an element with this group is hovered (slide hover: 'reveal')"- soh.addEventListener('change', () =>+ soh.addEventListener('change', () => {this.mutate(el.id, (e) => {if (soh.value) e.showOnHover = soh.valueelse delete e.showOnHover- }, true))+ }, true)+ // follow the element into its new set so it stays visible/editable+ this.store.hoverPreview = soh.value || null+ this.store.emit('current')+ })this.row('Show on hover', soh)// group tag (hover focus & interaction targeting)diff --git a/slides/src/main.ts b/slides/src/main.tsindex cea75823..6001c4fe 100644--- a/slides/src/main.ts+++ b/slides/src/main.ts@@ -30,4 +30,6 @@ if (location.hash === '#present') {return store.doc},serialize: () => serializeFile(store.doc),+ undo: () => store.undo(),+ redo: () => store.redo(),}diff --git a/slides/src/styles.css b/slides/src/styles.cssindex 109e7a95..61a1dad8 100644--- a/slides/src/styles.css+++ b/slides/src/styles.css@@ -224,6 +224,47 @@ html, body {.ed-stage-scale { position: absolute; top: 0; left: 0; transform-origin: 0 0; }+/* hover-set switcher chips, floating above the canvas */+.ed-setbar {+ position: absolute;+ top: 12px;+ left: 50%;+ transform: translateX(-50%);+ display: flex;+ align-items: center;+ gap: 6px;+ background: #fff;+ border: 1px solid var(--line);+ border-radius: 999px;+ padding: 5px 10px;+ box-shadow: 0 4px 14px rgb(20 30 45 / 0.10);+ z-index: 10;+ max-width: calc(100% - 48px);+ overflow-x: auto;+}+.ed-setbar-label {+ font-size: 11px;+ font-weight: 700;+ color: var(--muted);+ white-space: nowrap;+}+.ed-setchip {+ font: inherit;+ font-size: 12px;+ color: var(--ink-2);+ background: var(--chrome);+ border: 1px solid transparent;+ border-radius: 999px;+ padding: 3px 11px;+ cursor: pointer;+ white-space: nowrap;+}+.ed-setchip:hover { background: var(--chrome-2); }+.ed-setchip.active {+ background: var(--ink);+ color: #fff;+}+/* ————— slide surface (shared by canvas, thumbs, present) ————— */.bento-slide { position: relative; overflow: hidden; }