| 1 | // fixtures/inspect.mjs — what the card shows (spec §4.1), decided by |
| 2 | // this person's selection and nothing else: a box's options ('box'), |
| 3 | // the notes' marks ('notes'), or the slide's options then the deck's |
| 4 | // ('slide'). It says so as one attribute on the editor's root, |
| 5 | // data-inspect, and editor.css does the showing; nothing here touches |
| 6 | // a form. |
| 7 | // |
| 8 | // The selection feeds it (selection.mjs's onChange, a deleted block's |
| 9 | // included: reapply() hears an empty selection when the selected block |
| 10 | // has gone, and that is 'slide', never an empty box). The format bar |
| 11 | // says where the caret went: into the notes is 'notes'; back onto the |
| 12 | // stage leaves the kind to the selection again. A click on the desk or |
| 13 | // on a slide in the strip, Escape in the notes, and no slide left at |
| 14 | // all reset it. A peer's selection never reaches it: presence is |
| 15 | // drawn, not fed here. |
| 16 | // |
| 17 | // mountInspect({root, onChange}) → {selection(ids), caret(where), |
| 18 | // reset(), slideShown(id), current()}. onChange(kind) is heard only |
| 19 | // when the kind changes. Tested in inspect.test.mjs. |
| 20 | |
| 21 | const KINDS = ['box', 'notes', 'slide'] |
| 22 | |
| 23 | export function mountInspect ({ root, onChange = () => {} }) { |
| 24 | let kind = KINDS.includes(root.dataset.inspect) ? root.dataset.inspect : 'slide' |
| 25 | // The last selection, so the caret coming back to the stage from the |
| 26 | // notes knows whether a box is still selected. |
| 27 | let selected = false |
| 28 | |
| 29 | function set (next) { |
| 30 | if (root.dataset.inspect !== next) root.dataset.inspect = next |
| 31 | if (next === kind) return |
| 32 | kind = next |
| 33 | onChange(kind) |
| 34 | } |
| 35 | |
| 36 | return { |
| 37 | selection (ids) { |
| 38 | selected = Array.isArray(ids) && ids.length > 0 |
| 39 | if (selected) set('box') |
| 40 | else if (kind !== 'notes') set('slide') |
| 41 | }, |
| 42 | caret (where) { |
| 43 | if (where === 'notes') set('notes') |
| 44 | else set(selected ? 'box' : 'slide') |
| 45 | }, |
| 46 | reset () { |
| 47 | selected = false |
| 48 | set('slide') |
| 49 | }, |
| 50 | // The stage now shows slide id. None (the last slide removed, by |
| 51 | // this person or a colleague) is the deck's options alone: there are |
| 52 | // no notes and no box left to show, whatever the card was on. |
| 53 | slideShown (id) { |
| 54 | if (!id) this.reset() |
| 55 | }, |
| 56 | current: () => kind |
| 57 | } |
| 58 | } |
| 59 | |