// fixtures/inspect.mjs — what the card shows (spec §4.1), decided by // this person's selection and nothing else: a box's options ('box'), // the notes' marks ('notes'), or the slide's options then the deck's // ('slide'). It says so as one attribute on the editor's root, // data-inspect, and editor.css does the showing; nothing here touches // a form. // // The selection feeds it (selection.mjs's onChange, a deleted block's // included: reapply() hears an empty selection when the selected block // has gone, and that is 'slide', never an empty box). The format bar // says where the caret went: into the notes is 'notes'; back onto the // stage leaves the kind to the selection again. A click on the desk or // on a slide in the strip, Escape in the notes, and no slide left at // all reset it. A peer's selection never reaches it: presence is // drawn, not fed here. // // mountInspect({root, onChange}) → {selection(ids), caret(where), // reset(), slideShown(id), current()}. onChange(kind) is heard only // when the kind changes. Tested in inspect.test.mjs. const KINDS = ['box', 'notes', 'slide'] export function mountInspect ({ root, onChange = () => {} }) { let kind = KINDS.includes(root.dataset.inspect) ? root.dataset.inspect : 'slide' // The last selection, so the caret coming back to the stage from the // notes knows whether a box is still selected. let selected = false function set (next) { if (root.dataset.inspect !== next) root.dataset.inspect = next if (next === kind) return kind = next onChange(kind) } return { selection (ids) { selected = Array.isArray(ids) && ids.length > 0 if (selected) set('box') else if (kind !== 'notes') set('slide') }, caret (where) { if (where === 'notes') set('notes') else set(selected ? 'box' : 'slide') }, reset () { selected = false set('slide') }, // The stage now shows slide id. None (the last slide removed, by // this person or a colleague) is the deck's options alone: there are // no notes and no box left to show, whatever the card was on. slideShown (id) { if (!id) this.reset() }, current: () => kind } }