mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 11:39:16 +01:00
feat: ✨ Add bubble menu to composer
Some checks failed
Some checks failed
This commit is contained in:
parent
5dd1752a25
commit
a0b01193d5
5 changed files with 194 additions and 1 deletions
97
components/editor/bubble-menu.vue
Normal file
97
components/editor/bubble-menu.vue
Normal 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>
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue