feat: Add bubble menu to composer
Some checks failed
CodeQL / Analyze (javascript) (push) Failing after 1s
Deploy to GitHub Pages / build (push) Failing after 1s
Deploy to GitHub Pages / deploy (push) Has been skipped
Docker / build (push) Failing after 1s
Mirror to Codeberg / Mirror (push) Failing after 1s

This commit is contained in:
Jesse Wierzbinski 2025-07-11 06:02:28 +02:00
parent 5dd1752a25
commit a0b01193d5
5 changed files with 194 additions and 1 deletions

View file

@ -0,0 +1,97 @@
<script setup lang="ts">
import { BubbleMenu, type Editor } from "@tiptap/vue-3";
import {
BoldIcon,
CurlyBracesIcon,
ItalicIcon,
StrikethroughIcon,
SubscriptIcon,
SuperscriptIcon,
UnderlineIcon,
} from "lucide-vue-next";
import { ToggleGroup, ToggleGroupItem } from "~/components/ui/toggle-group";
const { editor } = defineProps<{
editor: Editor;
}>();
const active = ref<string[]>(
[
editor.isActive("bold") ? "bold" : null,
editor.isActive("italic") ? "italic" : null,
editor.isActive("underline") ? "underline" : null,
editor.isActive("code") ? "code" : null,
editor.isActive("strike") ? "strike" : null,
editor.isActive("subscript") ? "subscript" : null,
editor.isActive("superscript") ? "superscript" : null,
].filter((s) => s !== null),
);
watch(active, (value) => {
if (value.includes("bold")) {
editor.chain().focus().toggleBold().run();
} else {
editor.chain().unsetBold().run();
}
if (value.includes("italic")) {
editor.chain().focus().toggleItalic().run();
} else {
editor.chain().unsetItalic().run();
}
if (value.includes("underline")) {
editor.chain().focus().toggleUnderline().run();
} else {
editor.chain().unsetUnderline().run();
}
if (value.includes("code")) {
editor.chain().focus().toggleCode().run();
} else {
editor.chain().unsetCode().run();
}
if (value.includes("strike")) {
editor.chain().focus().toggleStrike().run();
} else {
editor.chain().unsetStrike().run();
}
if (value.includes("subscript")) {
editor.chain().focus().toggleSubscript().run();
} else {
editor.chain().unsetSubscript().run();
}
if (value.includes("superscript")) {
editor.chain().focus().toggleSuperscript().run();
} else {
editor.chain().unsetSuperscript().run();
}
});
</script>
<template>
<BubbleMenu :editor="editor" class="bg-popover rounded-md">
<ToggleGroup type="multiple"
v-model="active"
>
<ToggleGroupItem value="bold">
<BoldIcon />
</ToggleGroupItem>
<ToggleGroupItem value="italic">
<ItalicIcon />
</ToggleGroupItem>
<ToggleGroupItem value="underline">
<UnderlineIcon />
</ToggleGroupItem>
<ToggleGroupItem value="code">
<CurlyBracesIcon />
</ToggleGroupItem>
<ToggleGroupItem value="strike">
<StrikethroughIcon />
</ToggleGroupItem>
<ToggleGroupItem value="subscript">
<SubscriptIcon />
</ToggleGroupItem>
<ToggleGroupItem value="superscript">
<SuperscriptIcon />
</ToggleGroupItem>
</ToggleGroup>
</BubbleMenu>
</template>

View file

@ -1,5 +1,7 @@
<template>
<BubbleMenu :editor="editor" />
<EditorContent :editor="editor"
v-bind="$attrs"
:class="[$style.content, 'prose prose-sm dark:prose-invert break-words prose-a:no-underline prose-a:hover:underline prose-p:first-of-type:mt-0']" />
</template>
@ -14,6 +16,7 @@ import Superscript from "@tiptap/extension-superscript";
import Underline from "@tiptap/extension-underline";
import StarterKit from "@tiptap/starter-kit";
import { Editor, EditorContent } from "@tiptap/vue-3";
import BubbleMenu from "./bubble-menu.vue";
import suggestion from "./suggestion.ts";
const content = defineModel<string>("content");
@ -113,7 +116,7 @@ onUnmounted(() => {
@apply font-bold rounded-sm text-primary-foreground bg-primary px-1 py-0.5;
}
.tiptap .emoji > img {
.tiptap .emoji>img {
@apply h-[1lh] align-middle inline hover:scale-110 transition-transform duration-75 ease-in-out;
}
</style>