{
  "id": 138,
  "slug": "block-slash-composer",
  "name": "Block-Based Slash-Command Composer",
  "kind": "ui",
  "family": "Workspace & Editor",
  "sourceSite": {
    "name": "Slite",
    "url": "https://slite.com/",
    "verifiedStatus": 200
  },
  "tagline": "Structured document composer where typing / or tapping + inserts Headings, Callouts, Todos, Code, and Quotes as reorderable blocks.",
  "whyUnique": "Combines keyboard-fast slash-command insertion with tactile block handles, interactive checkboxes, and a touch-accessible '+' block picker bar so mobile authors never have to hunt for '/' on soft keyboards.",
  "theme": "light",
  "mobileStrength": "native-first",
  "tags": [
    "block-editor",
    "slash-commands",
    "composer",
    "rich-text",
    "document-workspace",
    "structured-content"
  ],
  "bestFor": [
    "Collaborative docs and team wikis",
    "Project briefs and meeting notes",
    "CMS article and newsletter composers",
    "Interactive runbooks and checklists"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#F7F6F3",
      "name": "Warm Linen"
    },
    {
      "role": "surface",
      "hex": "#FFFFFF",
      "name": "Document Card"
    },
    {
      "role": "ink",
      "hex": "#1E1D1B",
      "name": "Graphite Ink"
    },
    {
      "role": "accent",
      "hex": "#2563EB",
      "name": "Craft Azure"
    },
    {
      "role": "muted",
      "hex": "#716E67",
      "name": "Warm Slate"
    }
  ],
  "typography": {
    "display": "Inter",
    "body": "Inter",
    "mono": "JetBrains Mono",
    "googleFontsUrl": "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap",
    "scaleNotes": "28px document title, 20px section heading blocks, 15.5px/1.65 paragraph blocks, 13px mono code blocks."
  },
  "layoutNotes": "Centered 760px elevated document sheet with subtle per-block action rails on hover/focus and a floating slash-command popover menu.",
  "interactionNotes": "Type '/' inside any block or click '+ Add Block' to filter and insert Heading, Callout, Todo, Code, Quote, or Divider blocks; move blocks up/down, duplicate, or delete in one click.",
  "mobileNotes": "Keeps an always-reachable bottom/top '+ Insert Block' action bar and explicit Up/Down reorder buttons so touch users never depend on hover-only drag handles.",
  "agentGuardrails": {
    "do": [
      "Always pair keyboard '/' slash triggers with a visible '+ Add Block' button for touch devices.",
      "Support up/down keyboard arrow navigation inside the slash-command picker.",
      "Provide explicit Up/Down reorder buttons alongside drag handles for accessibility."
    ],
    "dont": [
      "Never hide block insertion or deletion strictly behind desktop hover states.",
      "Avoid breaking cursor focus when converting or inserting a new block."
    ]
  },
  "demoFile": "demos/block-slash-composer.html",
  "thumbDesktop": "thumbs/block-slash-composer-desktop.webp",
  "thumbMobile": "thumbs/block-slash-composer-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/block-slash-composer",
    "markdown": "https://templates.michaelpitts.net/t/block-slash-composer.md",
    "api": "https://templates.michaelpitts.net/api/templates/block-slash-composer",
    "demo": "https://templates.michaelpitts.net/demos/block-slash-composer.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/block-slash-composer-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/block-slash-composer-mobile.webp"
  },
  "agentPrompt": "Design & build using template #138 \"Block-Based Slash-Command Composer\" (ui / Workspace & Editor, light theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/block-slash-composer.md\nLive demo: https://templates.michaelpitts.net/demos/block-slash-composer.html\nReal-world inspiration: Slite (https://slite.com/)\n\nCore aesthetic: Combines keyboard-fast slash-command insertion with tactile block handles, interactive checkboxes, and a touch-accessible '+' block picker bar so mobile authors never have to hunt for '/' on soft keyboards.\nPalette: canvas: #F7F6F3 (Warm Linen), surface: #FFFFFF (Document Card), ink: #1E1D1B (Graphite Ink), accent: #2563EB (Craft Azure), muted: #716E67 (Warm Slate)\nTypography: Display=\"Inter\", Body=\"Inter\", Mono=\"JetBrains Mono\"\nLayout: Centered 760px elevated document sheet with subtle per-block action rails on hover/focus and a floating slash-command popover menu.\nInteractions: Type '/' inside any block or click '+ Add Block' to filter and insert Heading, Callout, Todo, Code, Quote, or Divider blocks; move blocks up/down, duplicate, or delete in one click.\nMobile: Keeps an always-reachable bottom/top '+ Insert Block' action bar and explicit Up/Down reorder buttons so touch users never depend on hover-only drag handles.\n\nGuardrails:\n- DO: Always pair keyboard '/' slash triggers with a visible '+ Add Block' button for touch devices.\n- DO: Support up/down keyboard arrow navigation inside the slash-command picker.\n- DO: Provide explicit Up/Down reorder buttons alongside drag handles for accessibility.\n- DON'T: Never hide block insertion or deletion strictly behind desktop hover states.\n- DON'T: Avoid breaking cursor focus when converting or inserting a new block.",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <title>CanvasDoc — Block Slash-Command Composer</title>\n  <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n  <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n  <link href=\"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap\" rel=\"stylesheet\">\n  <style>\n    :root {\n      --canvas: #f4f1ea;\n      --sheet: #ffffff;\n      --sheet-subtle: #faf8f4;\n      --border: #e6e0d4;\n      --border-strong: #d3cbbd;\n      --ink: #1e1d1a;\n      --ink-muted: #666158;\n      --ink-faint: #9a9387;\n      --accent: #3b5bdb;\n      --accent-soft: #edf2ff;\n      --callout-bg: #fff8e6;\n      --callout-border: #f59e0b;\n      --code-bg: #1e2430;\n      --code-ink: #e2e8f0;\n      --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;\n      --font-mono: 'JetBrains Mono', ui-monospace, monospace;\n    }\n\n    * { box-sizing: border-box; margin: 0; padding: 0; }\n\n    html, body {\n      min-height: 100%;\n      background: var(--canvas);\n      color: var(--ink);\n      font-family: var(--font-sans);\n      -webkit-font-smoothing: antialiased;\n      overflow-x: hidden;\n    }\n\n    .topbar {\n      position: sticky;\n      top: 0;\n      z-index: 30;\n      background: rgba(244, 241, 234, 0.92);\n      backdrop-filter: blur(10px);\n      border-bottom: 1px solid var(--border);\n      padding: 10px 20px;\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      gap: 12px;\n    }\n\n    .crumb {\n      display: flex;\n      align-items: center;\n      gap: 8px;\n      font-size: 13px;\n      color: var(--ink-muted);\n      min-width: 0;\n    }\n\n    .crumb-badge {\n      width: 26px;\n      height: 26px;\n      border-radius: 7px;\n      background: var(--ink);\n      color: #fff;\n      display: grid;\n      place-items: center;\n      font-size: 13px;\n      font-weight: 700;\n      flex-shrink: 0;\n    }\n\n    .crumb strong {\n      color: var(--ink);\n      white-space: nowrap;\n      overflow: hidden;\n      text-overflow: ellipsis;\n    }\n\n    .top-actions {\n      display: flex;\n      align-items: center;\n      gap: 8px;\n    }\n\n    .todo-pill {\n      font-size: 12px;\n      font-weight: 600;\n      color: var(--accent);\n      background: var(--accent-soft);\n      padding: 6px 11px;\n      border-radius: 99px;\n      white-space: nowrap;\n    }\n\n    .insert-btn {\n      appearance: none;\n      border: 1px solid var(--border-strong);\n      background: var(--sheet);\n      color: var(--ink);\n      font-family: var(--font-sans);\n      font-size: 13px;\n      font-weight: 600;\n      padding: 0 13px;\n      min-height: 38px;\n      border-radius: 9px;\n      cursor: pointer;\n      display: inline-flex;\n      align-items: center;\n      gap: 6px;\n      box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);\n      transition: background 0.15s, border-color 0.15s;\n    }\n    .insert-btn:hover {\n      background: var(--sheet-subtle);\n      border-color: var(--accent);\n      color: var(--accent);\n    }\n\n    /* Document Card Sheet */\n    .stage {\n      max-width: 820px;\n      margin: 28px auto 96px;\n      padding: 0 16px;\n    }\n\n    .doc-sheet {\n      background: var(--sheet);\n      border: 1px solid var(--border);\n      border-radius: 18px;\n      padding: 40px 44px 48px;\n      box-shadow: 0 10px 34px rgba(30, 29, 26, 0.06);\n    }\n\n    .doc-cover-meta {\n      display: flex;\n      align-items: center;\n      gap: 8px;\n      font-size: 12px;\n      font-weight: 600;\n      color: var(--ink-faint);\n      text-transform: uppercase;\n      letter-spacing: 0.06em;\n      margin-bottom: 10px;\n    }\n\n    .doc-title {\n      width: 100%;\n      border: none;\n      outline: none;\n      background: transparent;\n      font-family: var(--font-sans);\n      font-size: clamp(24px, 3.6vw, 34px);\n      font-weight: 700;\n      letter-spacing: -0.025em;\n      color: var(--ink);\n      margin-bottom: 8px;\n    }\n\n    .doc-hint {\n      font-size: 13px;\n      color: var(--ink-faint);\n      margin-bottom: 24px;\n      padding-bottom: 18px;\n      border-bottom: 1px solid var(--border);\n    }\n\n    .doc-hint kbd {\n      font-family: var(--font-mono);\n      font-size: 11.5px;\n      background: var(--sheet-subtle);\n      border: 1px solid var(--border-strong);\n      border-radius: 4px;\n      padding: 1px 5px;\n      color: var(--ink);\n    }\n\n    /* Blocks */\n    .blocks-list {\n      display: flex;\n      flex-direction: column;\n      gap: 10px;\n    }\n\n    .block-row {\n      display: grid;\n      grid-template-columns: 1fr auto;\n      align-items: start;\n      gap: 8px;\n      padding: 6px 8px;\n      margin: 0 -8px;\n      border-radius: 11px;\n      border: 1px solid transparent;\n      transition: background 0.15s, border-color 0.15s;\n    }\n\n    .block-row:hover,\n    .block-row:focus-within {\n      background: var(--sheet-subtle);\n      border-color: var(--border);\n    }\n\n    .block-content {\n      min-width: 0;\n    }\n\n    .block-actions {\n      display: flex;\n      align-items: center;\n      gap: 3px;\n      opacity: 0.25;\n      transition: opacity 0.15s;\n      flex-shrink: 0;\n    }\n\n    .block-row:hover .block-actions,\n    .block-row:focus-within .block-actions {\n      opacity: 1;\n    }\n\n    .act-btn {\n      appearance: none;\n      border: 1px solid transparent;\n      background: transparent;\n      color: var(--ink-muted);\n      width: 30px;\n      height: 30px;\n      border-radius: 6px;\n      cursor: pointer;\n      display: grid;\n      place-items: center;\n      font-size: 13px;\n    }\n    .act-btn:hover {\n      background: var(--sheet);\n      border-color: var(--border);\n      color: var(--ink);\n    }\n    .act-btn.del:hover { color: #dc2626; }\n\n    /* Editable Text Variants */\n    .editable {\n      outline: none;\n      width: 100%;\n      word-break: break-word;\n      white-space: pre-wrap;\n    }\n\n    .editable:empty::before {\n      content: attr(data-placeholder);\n      color: var(--ink-faint);\n      pointer-events: none;\n    }\n\n    .b-paragraph {\n      font-size: 15.5px;\n      line-height: 1.65;\n      color: var(--ink);\n      padding: 4px 2px;\n    }\n\n    .b-heading {\n      font-size: 21px;\n      font-weight: 700;\n      letter-spacing: -0.015em;\n      line-height: 1.3;\n      color: var(--ink);\n      padding: 8px 2px 2px;\n    }\n\n    .b-callout {\n      background: var(--callout-bg);\n      border: 1px solid rgba(245, 158, 11, 0.35);\n      border-left: 4px solid var(--callout-border);\n      border-radius: 10px;\n      padding: 12px 14px;\n      display: flex;\n      align-items: flex-start;\n      gap: 10px;\n      font-size: 14.5px;\n      line-height: 1.55;\n    }\n\n    .callout-icon {\n      font-size: 16px;\n      line-height: 1.4;\n      flex-shrink: 0;\n    }\n\n    .b-todo {\n      display: flex;\n      align-items: flex-start;\n      gap: 10px;\n      padding: 4px 2px;\n      font-size: 15.5px;\n      line-height: 1.55;\n    }\n\n    .b-todo input[type=\"checkbox\"] {\n      width: 18px;\n      height: 18px;\n      margin-top: 3px;\n      accent-color: var(--accent);\n      cursor: pointer;\n      flex-shrink: 0;\n    }\n\n    .b-todo.checked .editable {\n      text-decoration: line-through;\n      color: var(--ink-faint);\n    }\n\n    .b-quote {\n      border-left: 3px solid var(--accent);\n      padding: 6px 14px;\n      font-style: italic;\n      font-size: 16px;\n      line-height: 1.6;\n      color: var(--ink-muted);\n    }\n\n    .b-code {\n      background: var(--code-bg);\n      color: var(--code-ink);\n      border-radius: 10px;\n      padding: 13px 15px;\n      font-family: var(--font-mono);\n      font-size: 13px;\n      line-height: 1.6;\n      overflow-x: auto;\n    }\n\n    .b-divider {\n      padding: 12px 0;\n    }\n\n    .b-divider hr {\n      border: none;\n      border-top: 1px solid var(--border-strong);\n    }\n\n    .add-tail-btn {\n      margin-top: 18px;\n      width: 100%;\n      appearance: none;\n      border: 1px dashed var(--border-strong);\n      background: transparent;\n      color: var(--ink-muted);\n      font-family: var(--font-sans);\n      font-size: 13.5px;\n      font-weight: 500;\n      min-height: 44px;\n      border-radius: 10px;\n      cursor: pointer;\n      transition: background 0.15s, border-color 0.15s, color 0.15s;\n    }\n    .add-tail-btn:hover {\n      background: var(--sheet-subtle);\n      border-color: var(--accent);\n      color: var(--accent);\n    }\n\n    /* Slash Command Palette */\n    .slash-menu {\n      position: fixed;\n      z-index: 90;\n      width: 280px;\n      max-width: calc(100vw - 24px);\n      background: var(--sheet);\n      border: 1px solid var(--border-strong);\n      border-radius: 13px;\n      box-shadow: 0 18px 46px rgba(15, 23, 42, 0.18);\n      padding: 8px;\n      display: none;\n    }\n\n    .slash-menu.open { display: block; }\n\n    .slash-search {\n      width: 100%;\n      border: 1px solid var(--border);\n      background: var(--sheet-subtle);\n      border-radius: 8px;\n      padding: 8px 10px;\n      font-family: var(--font-sans);\n      font-size: 13px;\n      color: var(--ink);\n      outline: none;\n      margin-bottom: 6px;\n    }\n    .slash-search:focus { border-color: var(--accent); }\n\n    .slash-list {\n      display: flex;\n      flex-direction: column;\n      gap: 2px;\n      max-height: 280px;\n      overflow-y: auto;\n    }\n\n    .slash-item {\n      appearance: none;\n      border: none;\n      background: transparent;\n      width: 100%;\n      min-height: 44px;\n      padding: 7px 10px;\n      border-radius: 8px;\n      cursor: pointer;\n      display: flex;\n      align-items: center;\n      gap: 11px;\n      text-align: left;\n      color: var(--ink);\n    }\n\n    .slash-item:hover,\n    .slash-item.active {\n      background: var(--accent-soft);\n    }\n\n    .slash-badge {\n      width: 30px;\n      height: 30px;\n      border-radius: 7px;\n      background: var(--sheet-subtle);\n      border: 1px solid var(--border);\n      display: grid;\n      place-items: center;\n      font-family: var(--font-mono);\n      font-size: 12px;\n      font-weight: 600;\n      color: var(--ink-muted);\n      flex-shrink: 0;\n    }\n\n    .slash-item.active .slash-badge {\n      background: var(--accent);\n      border-color: var(--accent);\n      color: #fff;\n    }\n\n    .slash-meta strong {\n      display: block;\n      font-size: 13.5px;\n      font-weight: 600;\n    }\n    .slash-meta span {\n      font-size: 11.5px;\n      color: var(--ink-muted);\n    }\n\n    /* Mobile (390px) */\n    @media (max-width: 680px) {\n      .topbar { padding: 8px 12px; }\n      .insert-btn { min-height: 44px; }\n\n      .stage {\n        margin: 14px auto 64px;\n        padding: 0 10px;\n      }\n\n      .doc-sheet {\n        padding: 20px 16px 28px;\n        border-radius: 14px;\n      }\n\n      .block-row {\n        grid-template-columns: 1fr;\n        gap: 6px;\n        padding: 8px;\n        margin: 0;\n        border-color: var(--border);\n        background: var(--sheet-subtle);\n      }\n\n      .block-actions {\n        opacity: 1;\n        justify-content: flex-end;\n        border-top: 1px solid var(--border);\n        padding-top: 6px;\n      }\n\n      .act-btn {\n        width: 44px;\n        height: 44px;\n        background: var(--sheet);\n        border-color: var(--border);\n      }\n\n      .slash-menu {\n        left: 12px !important;\n        right: 12px !important;\n        bottom: 14px !important;\n        top: auto !important;\n        width: auto;\n      }\n    }\n  </style>\n</head>\n<body>\n  <header class=\"topbar\">\n    <div class=\"crumb\">\n      <div class=\"crumb-badge\" aria-hidden=\"true\">C</div>\n      <span>Workspace / <strong>Q3 Sync Brief</strong></span>\n    </div>\n    <div class=\"top-actions\">\n      <span id=\"todoPill\" class=\"todo-pill\">0/0 tasks</span>\n      <button id=\"topInsertBtn\" class=\"insert-btn\" type=\"button\">+ Insert Block</button>\n    </div>\n  </header>\n\n  <main class=\"stage\">\n    <article class=\"doc-sheet\">\n      <div class=\"doc-cover-meta\">Product Spec · Live Block Editor</div>\n      <input id=\"docTitle\" class=\"doc-title\" type=\"text\" value=\"Q3 Launch Brief — Offline Sync Engine\" aria-label=\"Document title\">\n      <p class=\"doc-hint\">Type <kbd>/</kbd> inside any block or tap <strong>+ Insert Block</strong> to open the slash-command menu.</p>\n\n      <div id=\"blocksList\" class=\"blocks-list\"></div>\n\n      <button id=\"tailAddBtn\" class=\"add-tail-btn\" type=\"button\">+ Add block or type /</button>\n    </article>\n  </main>\n\n  <div id=\"slashMenu\" class=\"slash-menu\" role=\"dialog\" aria-label=\"Insert block menu\">\n    <input id=\"slashSearch\" class=\"slash-search\" type=\"text\" placeholder=\"Filter blocks (heading, todo, code…)\" aria-label=\"Filter slash commands\">\n    <div id=\"slashList\" class=\"slash-list\"></div>\n  </div>\n\n  <script>\n    const COMMANDS = [\n      { type: 'heading', icon: 'H2', label: 'Heading', desc: 'Section heading' },\n      { type: 'paragraph', icon: '¶', label: 'Paragraph', desc: 'Plain body text' },\n      { type: 'callout', icon: '!', label: 'Callout', desc: 'Highlighted amber note' },\n      { type: 'todo', icon: '☑', label: 'Todo', desc: 'Interactive checklist item' },\n      { type: 'code', icon: '</>', label: 'Code', desc: 'Monospace snippet block' },\n      { type: 'quote', icon: '“', label: 'Quote', desc: 'Indented pull quote' },\n      { type: 'divider', icon: '—', label: 'Divider', desc: 'Horizontal section rule' }\n    ];\n\n    let nextId = 10;\n    const blocks = [\n      { id: 1, type: 'paragraph', text: 'Our Q3 release replaces polling with a local-first CRDT log so edits survive airplane mode and merge cleanly upon reconnect.' },\n      { id: 2, type: 'callout', text: 'Beta cohort opens July 14 for 250 workspace admins. Keep telemetry payload under 12 KB per sync batch.' },\n      { id: 3, type: 'heading', text: 'Launch Readiness Checklist' },\n      { id: 4, type: 'todo', checked: true, text: 'Finalize IndexedDB compaction benchmark on 50k blocks' },\n      { id: 5, type: 'todo', checked: false, text: 'Verify conflict toast when two devices edit the same heading' },\n      { id: 6, type: 'todo', checked: false, text: 'Publish migration guide and rollback flag documentation' },\n      { id: 7, type: 'quote', text: 'Local-first software should feel instantaneous on a slow train and invisible when the network returns.' },\n      { id: 8, type: 'code', text: 'const batch = await syncEngine.flush({ maxBytes: 12_288, retry: \"exponential\" });' },\n      { id: 9, type: 'divider', text: '' }\n    ];\n\n    const blocksList = document.getElementById('blocksList');\n    const todoPill = document.getElementById('todoPill');\n    const slashMenu = document.getElementById('slashMenu');\n    const slashSearch = document.getElementById('slashSearch');\n    const slashList = document.getElementById('slashList');\n\n    let menuContext = { afterIndex: blocks.length - 1, replaceIndex: null };\n    let filteredCmds = [...COMMANDS];\n    let activeCmdIdx = 0;\n\n    function updateTodoCount() {\n      const todos = blocks.filter(b => b.type === 'todo');\n      const done = todos.filter(b => b.checked).length;\n      todoPill.textContent = `${done}/${todos.length} tasks`;\n    }\n\n    function renderBlocks(focusId = null) {\n      blocksList.innerHTML = '';\n\n      blocks.forEach((block, idx) => {\n        const row = document.createElement('div');\n        row.className = 'block-row';\n        row.dataset.id = block.id;\n\n        const content = document.createElement('div');\n        content.className = 'block-content';\n\n        if (block.type === 'divider') {\n          content.innerHTML = `<div class=\"b-divider\"><hr></div>`;\n        } else if (block.type === 'todo') {\n          const wrap = document.createElement('div');\n          wrap.className = `b-todo ${block.checked ? 'checked' : ''}`;\n          const cb = document.createElement('input');\n          cb.type = 'checkbox';\n          cb.checked = !!block.checked;\n          cb.setAttribute('aria-label', 'Toggle task');\n          cb.addEventListener('change', () => {\n            block.checked = cb.checked;\n            wrap.classList.toggle('checked', block.checked);\n            updateTodoCount();\n          });\n          const ed = createEditable(block, idx, 'To-do item…');\n          wrap.append(cb, ed);\n          content.appendChild(wrap);\n        } else if (block.type === 'callout') {\n          const wrap = document.createElement('div');\n          wrap.className = 'b-callout';\n          const icon = document.createElement('span');\n          icon.className = 'callout-icon';\n          icon.textContent = '✦';\n          const ed = createEditable(block, idx, 'Callout note…');\n          wrap.append(icon, ed);\n          content.appendChild(wrap);\n        } else {\n          const placeholders = {\n            heading: 'Section heading…',\n            paragraph: 'Write text, or type / for commands…',\n            quote: 'Pull quote…',\n            code: '// Code snippet…'\n          };\n          const ed = createEditable(block, idx, placeholders[block.type] || 'Type / for commands…');\n          ed.classList.add(`b-${block.type}`);\n          content.appendChild(ed);\n        }\n\n        const actions = document.createElement('div');\n        actions.className = 'block-actions';\n        actions.innerHTML = `\n          <button class=\"act-btn\" type=\"button\" data-act=\"add\" title=\"Insert below\" aria-label=\"Insert block below\">+</button>\n          <button class=\"act-btn\" type=\"button\" data-act=\"up\" title=\"Move up\" aria-label=\"Move block up\" ${idx === 0 ? 'disabled' : ''}>↑</button>\n          <button class=\"act-btn\" type=\"button\" data-act=\"down\" title=\"Move down\" aria-label=\"Move block down\" ${idx === blocks.length - 1 ? 'disabled' : ''}>↓</button>\n          <button class=\"act-btn del\" type=\"button\" data-act=\"del\" title=\"Delete block\" aria-label=\"Delete block\">×</button>\n        `;\n\n        actions.addEventListener('click', (e) => {\n          const btn = e.target.closest('button[data-act]');\n          if (!btn) return;\n          const act = btn.dataset.act;\n          if (act === 'add') {\n            openSlashMenu(btn, { afterIndex: idx, replaceIndex: null });\n          } else if (act === 'up' && idx > 0) {\n            [blocks[idx - 1], blocks[idx]] = [blocks[idx], blocks[idx - 1]];\n            renderBlocks(block.id);\n          } else if (act === 'down' && idx < blocks.length - 1) {\n            [blocks[idx + 1], blocks[idx]] = [blocks[idx], blocks[idx + 1]];\n            renderBlocks(block.id);\n          } else if (act === 'del') {\n            blocks.splice(idx, 1);\n            if (!blocks.length) blocks.push({ id: nextId++, type: 'paragraph', text: '' });\n            renderBlocks();\n          }\n        });\n\n        row.append(content, actions);\n        blocksList.appendChild(row);\n      });\n\n      updateTodoCount();\n\n      if (focusId !== null) {\n        const target = blocksList.querySelector(`.block-row[data-id=\"${focusId}\"] .editable`);\n        if (target) {\n          target.focus();\n          placeCaretAtEnd(target);\n        }\n      }\n    }\n\n    function createEditable(block, idx, placeholder) {\n      const ed = document.createElement('div');\n      ed.className = 'editable';\n      ed.contentEditable = 'true';\n      ed.dataset.placeholder = placeholder;\n      ed.textContent = block.text;\n\n      ed.addEventListener('input', () => {\n        block.text = ed.textContent;\n        if (block.text === '/') {\n          openSlashMenu(ed, { afterIndex: idx, replaceIndex: idx });\n        }\n      });\n\n      ed.addEventListener('keydown', (e) => {\n        if (e.key === 'Enter' && !e.shiftKey && block.type !== 'code') {\n          e.preventDefault();\n          const newBlock = { id: nextId++, type: block.type === 'todo' ? 'todo' : 'paragraph', checked: false, text: '' };\n          blocks.splice(idx + 1, 0, newBlock);\n          renderBlocks(newBlock.id);\n        }\n      });\n\n      return ed;\n    }\n\n    function placeCaretAtEnd(el) {\n      const range = document.createRange();\n      const sel = window.getSelection();\n      range.selectNodeContents(el);\n      range.collapse(false);\n      sel.removeAllRanges();\n      sel.addRange(range);\n    }\n\n    function renderSlashList() {\n      const q = slashSearch.value.trim().toLowerCase();\n      filteredCmds = COMMANDS.filter(c =>\n        c.label.toLowerCase().includes(q) || c.desc.toLowerCase().includes(q)\n      );\n      activeCmdIdx = Math.min(activeCmdIdx, Math.max(0, filteredCmds.length - 1));\n\n      if (!filteredCmds.length) {\n        slashList.innerHTML = `<div style=\"padding:12px;font-size:12.5px;color:var(--ink-faint);text-align:center;\">No matching block</div>`;\n        return;\n      }\n\n      slashList.innerHTML = filteredCmds.map((cmd, i) => `\n        <button class=\"slash-item ${i === activeCmdIdx ? 'active' : ''}\" type=\"button\" data-cmd=\"${cmd.type}\">\n          <span class=\"slash-badge\">${cmd.icon}</span>\n          <span class=\"slash-meta\">\n            <strong>${cmd.label}</strong>\n            <span>${cmd.desc}</span>\n          </span>\n        </button>\n      `).join('');\n    }\n\n    function openSlashMenu(anchorEl, ctx) {\n      menuContext = ctx;\n      slashSearch.value = '';\n      activeCmdIdx = 0;\n      renderSlashList();\n\n      const rect = anchorEl.getBoundingClientRect();\n      const top = Math.min(window.innerHeight - 330, rect.bottom + 8);\n      const left = Math.min(window.innerWidth - 296, Math.max(12, rect.left));\n      slashMenu.style.top = `${Math.max(60, top)}px`;\n      slashMenu.style.left = `${left}px`;\n      slashMenu.classList.add('open');\n      slashSearch.focus();\n    }\n\n    function closeSlashMenu() {\n      slashMenu.classList.remove('open');\n    }\n\n    function executeCommand(type) {\n      closeSlashMenu();\n      const newBlock = { id: nextId++, type, checked: false, text: '' };\n      if (menuContext.replaceIndex !== null) {\n        blocks[menuContext.replaceIndex] = newBlock;\n      } else {\n        blocks.splice(menuContext.afterIndex + 1, 0, newBlock);\n      }\n      renderBlocks(type === 'divider' ? null : newBlock.id);\n    }\n\n    slashSearch.addEventListener('input', () => {\n      activeCmdIdx = 0;\n      renderSlashList();\n    });\n\n    slashSearch.addEventListener('keydown', (e) => {\n      if (e.key === 'ArrowDown') {\n        e.preventDefault();\n        activeCmdIdx = (activeCmdIdx + 1) % Math.max(1, filteredCmds.length);\n        renderSlashList();\n      } else if (e.key === 'ArrowUp') {\n        e.preventDefault();\n        activeCmdIdx = (activeCmdIdx - 1 + filteredCmds.length) % Math.max(1, filteredCmds.length);\n        renderSlashList();\n      } else if (e.key === 'Enter') {\n        e.preventDefault();\n        if (filteredCmds[activeCmdIdx]) executeCommand(filteredCmds[activeCmdIdx].type);\n      } else if (e.key === 'Escape') {\n        closeSlashMenu();\n      }\n    });\n\n    slashList.addEventListener('click', (e) => {\n      const item = e.target.closest('button[data-cmd]');\n      if (item) executeCommand(item.dataset.cmd);\n    });\n\n    document.getElementById('topInsertBtn').addEventListener('click', (e) => {\n      openSlashMenu(e.currentTarget, { afterIndex: blocks.length - 1, replaceIndex: null });\n    });\n\n    document.getElementById('tailAddBtn').addEventListener('click', (e) => {\n      openSlashMenu(e.currentTarget, { afterIndex: blocks.length - 1, replaceIndex: null });\n    });\n\n    document.addEventListener('click', (e) => {\n      if (!slashMenu.classList.contains('open')) return;\n      if (e.target.closest('#slashMenu') || e.target.closest('#topInsertBtn') || e.target.closest('#tailAddBtn') || e.target.closest('button[data-act=\"add\"]')) return;\n      closeSlashMenu();\n    });\n\n    renderBlocks();\n  </script>\n</body>\n</html>\n"
}
