-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
198 additions
and
105 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
- 支持 TypeScript | ||
- 国际化支持(`en`, `zhHans`) | ||
- 支持自定义扩展 | ||
- Tailwind CSS | ||
|
||
## 安装 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Extension } from '@tiptap/core' | ||
|
||
import TextDropdown from './components/TextDropdown.vue' | ||
|
||
import type { GeneralOptions } from '@/type' | ||
|
||
export interface TextBubbleOptions extends GeneralOptions<TextBubbleOptions> {} | ||
|
||
export const TextBubble = Extension.create<TextBubbleOptions>({ | ||
name: 'text-bubble', | ||
addOptions() { | ||
return { | ||
...this.parent?.(), | ||
toolbar: false, | ||
button: () => ({ | ||
component: TextDropdown, | ||
componentProps: {}, | ||
}), | ||
} | ||
}, | ||
}) | ||
|
||
export default TextBubble |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
import { Button } from '@/components/ui/button' | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuCheckboxItem, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu' | ||
import { Editor } from '@tiptap/vue-3' | ||
import { Icon, icons } from '@/components/icons' | ||
import { useLocale } from '@/locales' | ||
interface ContentTypeMenu { | ||
name: string | ||
label: string | ||
iconName: keyof typeof icons | ||
action?: (value?: unknown) => void | ||
isActive: () => boolean | ||
} | ||
interface Props { | ||
editor: Editor | ||
disabled?: boolean | ||
color?: string | ||
maxHeight?: string | number | ||
icon?: any | ||
tooltip?: string | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
disabled: false, | ||
color: undefined, | ||
maxHeight: undefined, | ||
icon: undefined, | ||
tooltip: '', | ||
items: () => [], | ||
}) | ||
const { t } = useLocale() | ||
const menus: ContentTypeMenu[] = [ | ||
{ | ||
name: 'paragraph', | ||
label: t.value('editor.paragraph.tooltip'), | ||
iconName: 'Heading1', | ||
isActive: () => | ||
props.editor.isActive('paragraph') && | ||
!props.editor.isActive('orderedList') && | ||
!props.editor.isActive('bulletList') && | ||
!props.editor.isActive('taskList'), | ||
action: () => props.editor.chain().focus().clearNodes().run(), | ||
}, | ||
{ | ||
name: 'heading1', | ||
label: t.value('editor.heading.h1.tooltip'), | ||
isActive: () => props.editor.isActive('heading', { level: 1 }), | ||
iconName: 'Heading1', | ||
action: () => props.editor.chain().focus().clearNodes().toggleHeading({ level: 1 }).run(), | ||
}, | ||
{ | ||
name: 'heading2', | ||
label: t.value('editor.heading.h2.tooltip'), | ||
isActive: () => props.editor.isActive('heading', { level: 2 }), | ||
iconName: 'Heading2', | ||
action: () => props.editor.chain().focus().clearNodes().toggleHeading({ level: 2 }).run(), | ||
}, | ||
{ | ||
name: 'heading3', | ||
label: t.value('editor.heading.h3.tooltip'), | ||
isActive: () => props.editor.isActive('heading', { level: 3 }), | ||
iconName: 'Heading3', | ||
action: () => props.editor.chain().focus().clearNodes().toggleHeading({ level: 3 }).run(), | ||
}, | ||
{ | ||
name: 'bulletList', | ||
label: t.value('editor.bulletlist.tooltip'), | ||
isActive: () => props.editor.isActive('bulletList'), | ||
iconName: 'List', | ||
action: () => props.editor.chain().focus().clearNodes().toggleBulletList().run(), | ||
}, | ||
{ | ||
name: 'numberedList', | ||
label: t.value('editor.orderedlist.tooltip'), | ||
isActive: () => props.editor.isActive('orderedList'), | ||
iconName: 'ListOrdered', | ||
action: () => props.editor.chain().focus().clearNodes().toggleOrderedList().run(), | ||
}, | ||
{ | ||
name: 'taskList', | ||
label: t.value('editor.tasklist.tooltip'), | ||
isActive: () => props.editor.isActive('taskList'), | ||
iconName: 'ListTodo', | ||
action: () => props.editor.chain().focus().clearNodes().toggleTaskList().run(), | ||
}, | ||
{ | ||
name: 'blockquote', | ||
label: t.value('editor.blockquote.tooltip'), | ||
isActive: () => props.editor.isActive('blockquote'), | ||
iconName: 'TextQuote', | ||
action: () => props.editor.chain().focus().clearNodes().toggleBlockquote().run(), | ||
}, | ||
{ | ||
name: 'codeBlock', | ||
label: t.value('editor.codeblock.tooltip'), | ||
isActive: () => props.editor.isActive('codeBlock'), | ||
iconName: 'Code2', | ||
action: () => props.editor.chain().focus().clearNodes().toggleCodeBlock().run(), | ||
}, | ||
] | ||
const activeItem = computed(() => { | ||
return ( | ||
menus.filter(item => item.isActive()).pop() ?? { | ||
label: '修改', | ||
} | ||
) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger as-child> | ||
<Button variant="ghost" class="h-[32px] flex gap-1 px-1.5"> | ||
<span class="whitespace-nowrap text-sm font-normal"> {{ activeItem?.label }}</span> | ||
<Icon name="ChevronDown" class="w-4 h-4" /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent class="w-full p-1" align="start" :sideOffset="5"> | ||
<DropdownMenuCheckboxItem | ||
v-for="(item, index) in menus" | ||
:key="index" | ||
@click="item.action" | ||
class="cursor-pointer" | ||
:checked="item.isActive?.() || false" | ||
> | ||
<div class="flex items-center gap-2 px-2"> | ||
<Icon :name="item.iconName" class="h3 w-3" /> | ||
<span> {{ item.label }}</span> | ||
</div></DropdownMenuCheckboxItem | ||
> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './TextBubble' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters