|
1 | 1 | <script setup lang="ts"> |
| 2 | +import type { EmojiMartData } from '@emoji-mart/data' |
2 | 3 | import type FluentEditor from '@opentiny/fluent-editor' |
| 4 | +
|
3 | 5 | import type { I18N } from '@opentiny/fluent-editor' |
| 6 | +// 这里实际导入的是一个 json 文件,包含了 emoji-mart 所需的所有表情数据,类型是 EmojiMartData |
| 7 | +import data from '@emoji-mart/data' |
| 8 | +// computePosition 函数用于计算 emoji picker显示的位置 |
| 9 | +import { computePosition } from '@floating-ui/dom' |
4 | 10 |
|
5 | 11 | import QuillToolbarTip from 'quill-toolbar-tip' |
6 | 12 | import { onMounted, ref } from 'vue' |
| 13 | +
|
7 | 14 | import 'quill-toolbar-tip/dist/index.css' |
| 15 | +import 'quill-table-up/index.css' |
| 16 | +import 'quill-table-up/table-creator.css' |
8 | 17 |
|
9 | 18 | let editor: FluentEditor |
10 | 19 | const editorRef = ref<HTMLElement>() |
11 | 20 | const lang = ref('zh-CN') |
12 | 21 |
|
13 | | -onMounted(() => { |
| 22 | +const TOOLBAR_CONFIG = [ |
| 23 | + ['undo', 'redo', 'clean', 'format-painter'], |
| 24 | + [ |
| 25 | + // 请保留默认值为 false |
| 26 | + { header: [1, 2, 3, 4, 5, 6, false] }, |
| 27 | + { font: [false, '宋体', '微软雅黑', '楷体', '黑体', '隶书', 'andale mono', 'arial', 'arial black', 'comic sans ms', 'impact', 'times new roman'] }, |
| 28 | + { size: [false, '12px', '14px', '16px', '18px', '20px', '24px', '32px', '36px', '48px', '72px'] }, |
| 29 | + { 'line-height': [false, '1.2', '1.5', '1.75', '2', '3', '4', '5'] }, |
| 30 | + ], |
| 31 | + ['bold', 'italic', 'strike', 'underline', 'divider'], |
| 32 | + [{ color: [] }, { background: [] }], |
| 33 | + [{ align: '' }, { align: 'center' }, { align: 'right' }, { align: 'justify' }], |
| 34 | + [{ list: 'ordered' }, { list: 'bullet' }, { list: 'check' }], |
| 35 | + [{ script: 'sub' }, { script: 'super' }], |
| 36 | + [{ indent: '-1' }, { indent: '+1' }], |
| 37 | + [{ direction: 'rtl' }], |
| 38 | + ['link', 'blockquote', 'code', 'code-block'], |
| 39 | + ['image', 'file'], |
| 40 | + ['emoji', 'video', 'formula', 'screenshot', 'fullscreen'], |
| 41 | + [{ 'table-up': [] }], |
| 42 | +] |
| 43 | +
|
| 44 | +onMounted(async () => { |
14 | 45 | // ssr compat, reference: https://vitepress.dev/guide/ssr-compat#importing-in-mounted-hook |
15 | | - import('@opentiny/fluent-editor').then(({ default: FluentEditor, I18N, generateToolbarTip }) => { |
16 | | - if (!editorRef.value) return |
17 | | - FluentEditor.register({ 'modules/toolbar-tip': generateToolbarTip(QuillToolbarTip) }, true) |
18 | | - I18N.register( |
19 | | - { |
20 | | - 'zh-CN': { |
21 | | - 'replace bold': '替换粗体文本', |
22 | | - 'replace italic': '替换斜体文本', |
| 46 | + const [ |
| 47 | + { default: FluentEditor, I18N, generateToolbarTip, generateTableUp }, |
| 48 | + { defaultCustomSelect, TableMenuContextmenu, TableSelection, TableUp }, |
| 49 | + emojiMart, |
| 50 | + ] = await Promise.all([ |
| 51 | + import('@opentiny/fluent-editor'), |
| 52 | + import('quill-table-up'), |
| 53 | + import('emoji-mart'), |
| 54 | + ]) |
| 55 | +
|
| 56 | + if (!editorRef.value) return |
| 57 | + FluentEditor.register({ 'modules/toolbar-tip': generateToolbarTip(QuillToolbarTip) }, true) |
| 58 | + FluentEditor.register({ 'modules/table-up': generateTableUp(TableUp) }, true) |
| 59 | + I18N.register( |
| 60 | + { |
| 61 | + 'zh-CN': { |
| 62 | + 'replace bold': '替换粗体文本', |
| 63 | + 'replace italic': '替换斜体文本', |
| 64 | + }, |
| 65 | + 'en-US': { |
| 66 | + 'replace bold': 'Replace bold text', |
| 67 | + 'replace italic': 'Replace italic text', |
| 68 | + }, |
| 69 | + }, |
| 70 | + // set false to add text to the existing language |
| 71 | + false, |
| 72 | + ) |
| 73 | + editor = new FluentEditor(editorRef.value, { |
| 74 | + theme: 'snow', |
| 75 | + modules: { |
| 76 | + 'toolbar': TOOLBAR_CONFIG, |
| 77 | + 'counter': true, |
| 78 | + 'emoji': { |
| 79 | + emojiData: data as EmojiMartData, |
| 80 | + EmojiPicker: emojiMart.Picker, |
| 81 | + emojiPickerPosition: computePosition, |
| 82 | + }, |
| 83 | + 'i18n': { |
| 84 | + lang: lang.value, |
| 85 | + }, |
| 86 | + 'toolbar-tip': { |
| 87 | + tipTextMap: { |
| 88 | + bold: '_i18n"replace bold"', |
| 89 | + italic: '_i18n"replace italic"', |
23 | 90 | }, |
24 | | - 'en-US': { |
25 | | - 'replace bold': 'Replace bold text', |
26 | | - 'replace italic': 'Replace italic text', |
| 91 | + defaultTooltipOptions: { |
| 92 | + tipHoverable: false, |
27 | 93 | }, |
28 | 94 | }, |
29 | | - // set false to add text to the existing language |
30 | | - false, |
31 | | - ) |
32 | | - editor = new FluentEditor(editorRef.value, { |
33 | | - theme: 'snow', |
34 | | - modules: { |
35 | | - 'toolbar': [ |
36 | | - ['bold', 'italic', 'strike', 'underline'], |
37 | | - ['link', 'image'], |
38 | | - [{ color: [] }, { background: [] }], |
| 95 | + 'table-up': { |
| 96 | + customSelect: defaultCustomSelect, |
| 97 | + modules: [ |
| 98 | + { module: TableSelection }, |
| 99 | + { module: TableMenuContextmenu }, |
39 | 100 | ], |
40 | | - 'counter': true, |
41 | | - 'i18n': { |
42 | | - lang: lang.value, |
43 | | - }, |
44 | | - 'toolbar-tip': { |
45 | | - tipTextMap: { |
46 | | - bold: '_i18n"replace bold"', |
47 | | - italic: '_i18n"replace italic"', |
48 | | - }, |
49 | | - defaultTooltipOptions: { |
50 | | - tipHoverable: false, |
51 | | - }, |
52 | | - }, |
53 | 101 | }, |
54 | | - }) |
| 102 | + }, |
55 | 103 | }) |
56 | 104 | }) |
57 | 105 | function switchLanguage() { |
|
0 commit comments