feat: Add Editor component and add editor demo
parent
17e8e7cda9
commit
3fb3e8da39
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
import Editor from './src/Editor.vue'
|
||||
import { IDomEditor } from '@wangeditor/editor'
|
||||
|
||||
export interface EditorExpose {
|
||||
getEditorRef: () => Promise<IDomEditor>
|
||||
}
|
||||
|
||||
export { Editor }
|
||||
@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import { ContentWrap } from '@/components/ContentWrap'
|
||||
import { Editor, EditorExpose } from '@/components/Editor'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { IDomEditor } from '@wangeditor/editor'
|
||||
import { ref, onMounted, unref } from 'vue'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const change = (editor: IDomEditor) => {
|
||||
console.log(editor.getHtml())
|
||||
}
|
||||
|
||||
const editorRef = ref<typeof Editor & EditorExpose>()
|
||||
|
||||
const defaultHtml = ref('')
|
||||
|
||||
onMounted(async () => {
|
||||
const editor = await unref(editorRef)?.getEditorRef()
|
||||
console.log(editor)
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
defaultHtml.value = '<p>hello <strong>world</strong></p>'
|
||||
}, 3000)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ContentWrap :title="t('richText.richText')" :message="t('richText.richTextDes')">
|
||||
<Editor ref="editorRef" @change="change" :defaultHtml="defaultHtml" />
|
||||
</ContentWrap>
|
||||
</template>
|
||||
@ -0,0 +1,27 @@
|
||||
import { SlateDescendant } from '@wangeditor/editor'
|
||||
|
||||
declare module 'slate' {
|
||||
interface CustomTypes {
|
||||
// 扩展 text
|
||||
Text: {
|
||||
text: string
|
||||
bold?: boolean
|
||||
italic?: boolean
|
||||
code?: boolean
|
||||
through?: boolean
|
||||
underline?: boolean
|
||||
sup?: boolean
|
||||
sub?: boolean
|
||||
color?: string
|
||||
bgColor?: string
|
||||
fontSize?: string
|
||||
fontFamily?: string
|
||||
}
|
||||
|
||||
// 扩展 Element 的 type 属性
|
||||
Element: {
|
||||
type: string
|
||||
children: SlateDescendant[]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue