// fixtures/slide-layouts.mjs — what "New slide" puts on a slide. // // A layout here is a starting point, not a kind of slide: one of the // seven flow templates plus the empty blocks a person fills in, all // written through the ordinary ops (add_slide, then add_block per // block). Nothing about a layout survives on the slide except the // template and the blocks it made, so a slide made from "Title and // list" is a title-body slide with a heading and a list on it, and the // inspector changes it like any other. // // The blocks start empty; the stage shows each one's placeholder // (render.Options.Placeholders, editor.css) so there is somewhere to // click. A layout that gave a slide no block to type into would open // on a blank rectangle — which is what "New slide" did before this. import { newID } from './ids.mjs' const heading = (region, level = 1) => ({ type: 'heading', region, props: { level } }) const text = (region, props) => ({ type: 'text', region, props }) /** Every layout the picker offers, in its order: name → {template, blocks}. */ export const LAYOUTS = { title: { template: 'title', blocks: [heading('heading'), text('body', { size: 'l' })] }, 'title-text': { template: 'title-body', blocks: [heading('heading'), text('body')] }, 'title-list': { template: 'title-body', blocks: [heading('heading'), { type: 'list', region: 'body', props: { style: 'bullet' } }] }, 'two-column': { template: 'two-column', blocks: [heading('heading'), text('body'), text('aside')] }, section: { template: 'section', blocks: [heading('heading')] }, picture: { template: 'image-full', blocks: [{ type: 'image', region: 'media', props: { fit: 'cover' } }, heading('heading', 2)] }, quote: { template: 'quote', blocks: [{ type: 'quote', region: 'body', props: {} }] }, blank: { template: 'blank', blocks: [] } } export const LAYOUT_NAMES = Object.keys(LAYOUTS) /** * The layout a plain "New slide" uses after a slide with this template: * the same again, except after an opening title (a deck's second slide * is almost never another title) or after a blank one. */ export function layoutAfter (template) { switch (template) { case 'two-column': return 'two-column' case 'section': return 'section' case 'image-full': return 'picture' case 'quote': return 'quote' default: return 'title-text' } } /** * The op batch that makes slide `id` from `layout`, after `after` when * it is given (null puts it first; undefined, last). Unknown layouts * are 'title-text', so a stale menu item still makes a slide. */ export function layoutOps (id, layout, after, mint = newID) { const l = LAYOUTS[layout] ?? LAYOUTS['title-text'] const add = { op: 'add_slide', id, layout: 'flow', template: l.template } if (after !== undefined) add.after = after const ops = [add] for (const b of l.blocks) { ops.push({ op: 'add_block', slide: id, id: mint(), type: b.type, region: b.region, props: { ...b.props }, markdown: '' }) } return ops }