toolbar.vue 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script setup lang="ts">
  2. import { Editor, EditorToolbar } from "@enesis/editor"
  3. import { ref } from "vue"
  4. const content =
  5. ref(`* **Bold**, *italic*, \`code\`, ~~strikethrough~~, ^^highlight^^, and $math$ work inline
  6. * ## Heading 2
  7. * TODO This task can be toggled from the toolbar
  8. * [[Page refs]] and #tags are supported inline
  9. * | Feature | Shortcut |
  10. |---|---|
  11. | Bold | **⌘B** |
  12. | Italic | *⌘I* |`)
  13. </script>
  14. <template>
  15. <UPage>
  16. <UPageHeader
  17. title="Toolbar"
  18. description="Formatting toolbar with active state tracking."
  19. />
  20. <UPageBody>
  21. <div class="space-y-8">
  22. <section class="space-y-4">
  23. <h2 class="text-lg font-semibold text-highlighted">Editor with Toolbar</h2>
  24. <p class="text-sm text-muted leading-relaxed">
  25. Toolbar and editor are wired automatically via the <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">#toolbar</code> slot — no manual event handling needed.
  26. The Editor provides <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">handlers</code> and <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">selectionVersion</code> to the slot scope.
  27. </p>
  28. <div class="flex flex-col gap-3 rounded-lg border border-default bg-elevated p-4">
  29. <Editor v-model:content="content" :focused="true" marker-mode="always-visible">
  30. <template #toolbar="{ handlers, selectionVersion }">
  31. <EditorToolbar :handlers="handlers" :selection-version="selectionVersion" />
  32. </template>
  33. </Editor>
  34. </div>
  35. </section>
  36. <section class="space-y-4">
  37. <h2 class="text-lg font-semibold text-highlighted">Integration Pattern</h2>
  38. <div class="rounded-lg border border-default overflow-hidden">
  39. <table class="w-full text-sm">
  40. <thead>
  41. <tr class="border-b border-default bg-elevated">
  42. <th class="text-left px-4 py-2 font-medium text-muted text-xs uppercase tracking-wider">Step</th>
  43. <th class="text-left px-4 py-2 font-medium text-muted text-xs uppercase tracking-wider">Description</th>
  44. </tr>
  45. </thead>
  46. <tbody>
  47. <tr class="border-b border-default">
  48. <td class="px-4 py-2 font-mono text-xs">1</td>
  49. <td class="px-4 py-2 text-xs text-muted">Editor detects <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">#toolbar</code> slot and renders it above the block list</td>
  50. </tr>
  51. <tr class="border-b border-default">
  52. <td class="px-4 py-2 font-mono text-xs">2</td>
  53. <td class="px-4 py-2 text-xs text-muted">Editor passes <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">handlers</code> and <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">selectionVersion</code> from the focused Block into the slot</td>
  54. </tr>
  55. <tr class="border-b border-default">
  56. <td class="px-4 py-2 font-mono text-xs">3</td>
  57. <td class="px-4 py-2 text-xs text-muted">Toolbar's <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">computed</code>s re-run, calling <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">handlers.isActive(format)</code> for each button</td>
  58. </tr>
  59. </tbody>
  60. </table>
  61. </div>
  62. </section>
  63. <section class="space-y-4">
  64. <h2 class="text-lg font-semibold text-highlighted">Known Limitations</h2>
  65. <ul class="text-sm text-muted leading-relaxed space-y-2 list-disc list-inside">
  66. <li>Reference insertion (Page Ref, Block Ref, Tag) uses <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">window.prompt()</code> — will be replaced with the pattern plugin's suggestion menu in a future phase.</li>
  67. <li>Undo/redo (<kbd class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">⌘Z</kbd> / <kbd class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">⌘⇧Z</kbd>) are wired via global keyboard shortcuts. <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">canUndo</code>, <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">canRedo</code>, <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">undo</code>, and <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">redo</code> are provided via the <code class="text-xs font-mono px-1 py-0.5 rounded bg-elevated border border-default">#toolbar</code> slot scope.</li>
  68. </ul>
  69. </section>
  70. </div>
  71. </UPageBody>
  72. </UPage>
  73. </template>