feat: editor module BlotFormatter

This commit is contained in:
KUN1007 2023-09-08 15:53:30 +08:00
parent 71cbf01456
commit 84aa83b841
5 changed files with 55 additions and 3 deletions

View file

@ -24,6 +24,7 @@
"dompurify": "^3.0.5", "dompurify": "^3.0.5",
"pinia": "^2.1.6", "pinia": "^2.1.6",
"pinia-plugin-persistedstate": "^3.2.0", "pinia-plugin-persistedstate": "^3.2.0",
"quill-blot-formatter": "^1.0.5",
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-i18n": "^9.2.2", "vue-i18n": "^9.2.2",
"vue-router": "^4.2.4" "vue-router": "^4.2.4"

View file

@ -23,6 +23,9 @@ dependencies:
pinia-plugin-persistedstate: pinia-plugin-persistedstate:
specifier: ^3.2.0 specifier: ^3.2.0
version: 3.2.0(pinia@2.1.6) version: 3.2.0(pinia@2.1.6)
quill-blot-formatter:
specifier: ^1.0.5
version: 1.0.5(quill@1.3.7)
vue: vue:
specifier: ^3.3.4 specifier: ^3.3.4
version: 3.3.4 version: 3.3.4
@ -1118,6 +1121,11 @@ packages:
regexp.prototype.flags: 1.5.0 regexp.prototype.flags: 1.5.0
dev: false dev: false
/deepmerge@2.2.1:
resolution: {integrity: sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==}
engines: {node: '>=0.10.0'}
dev: false
/define-lazy-prop@2.0.0: /define-lazy-prop@2.0.0:
resolution: {integrity: sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==} resolution: {integrity: sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==}
engines: {node: '>=8'} engines: {node: '>=8'}
@ -1613,6 +1621,15 @@ packages:
resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==}
dev: true dev: true
/quill-blot-formatter@1.0.5(quill@1.3.7):
resolution: {integrity: sha512-iVmuEdmMIpvERBnnDfosWul6VAVN6tqQRruUzAEwA9ZbQ/Ef7DTHGZDUR4KklXpxM+z50opFp6m1NhNdN6HJhw==}
peerDependencies:
quill: ^1.3.4
dependencies:
deepmerge: 2.2.1
quill: 1.3.7
dev: false
/quill-delta@3.6.3: /quill-delta@3.6.3:
resolution: {integrity: sha512-wdIGBlcX13tCHOXGMVnnTVFtGRLoP0imqxM696fIPwIf5ODIYUHIvHbZcyvGlZFiFhK5XzDC2lpjbxRhnM05Tg==} resolution: {integrity: sha512-wdIGBlcX13tCHOXGMVnnTVFtGRLoP0imqxM696fIPwIf5ODIYUHIvHbZcyvGlZFiFhK5XzDC2lpjbxRhnM05Tg==}
engines: {node: '>=0.10'} engines: {node: '>=0.10'}

View file

@ -1,7 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
//
import { Icon } from '@iconify/vue'
// css // css
import 'animate.css' import 'animate.css'

View file

@ -1,6 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { defineAsyncComponent, computed, ref, onBeforeMount } from 'vue' import { defineAsyncComponent, computed, ref, onBeforeMount } from 'vue'
//
import { QuillEditor } from '@vueup/vue-quill' import { QuillEditor } from '@vueup/vue-quill'
// quill module: for resizing and realigning images and iframe video
import BlotFormatter from 'quill-blot-formatter'
// quill // quill
import '@/styles/editor/editor.snow.scss' import '@/styles/editor/editor.snow.scss'
@ -35,6 +39,7 @@ const { editorHeight, mode, theme, isSave, content } = storeToRefs(
* @param {boolean} isShowTitle - 是否显示标题 * @param {boolean} isShowTitle - 是否显示标题
* @param {boolean} isShowSettings - 是否显示编辑器设置 * @param {boolean} isShowSettings - 是否显示编辑器设置
*/ */
const props = defineProps<{ const props = defineProps<{
height?: number height?: number
isShowToolbar: boolean isShowToolbar: boolean
@ -46,6 +51,20 @@ const props = defineProps<{
// //
const editorRef = ref<typeof QuillEditor>() const editorRef = ref<typeof QuillEditor>()
// modules
const modules = {
name: 'blotFormatter',
module: BlotFormatter,
// see: https://github.com/Fandom-OSS/quill-blot-formatter/blob/master/src/Options.js
options: {
overlay: {
style: {
border: '2px solid var(--kungalgame-blue-3)',
},
},
},
}
// //
const editorHeightStyle = computed( const editorHeightStyle = computed(
() => `height: ${props.height ? props.height : editorHeight.value}px` () => `height: ${props.height ? props.height : editorHeight.value}px`
@ -106,6 +125,7 @@ const handleTextChange = async () => {
:content="valueHtml" :content="valueHtml"
:style="editorHeightStyle" :style="editorHeightStyle"
:theme="theme" :theme="theme"
:modules="modules"
:toolbar="mode" :toolbar="mode"
:options="editorOptions" :options="editorOptions"
@textChange="handleTextChange" @textChange="handleTextChange"
@ -192,5 +212,21 @@ const handleTextChange = async () => {
font-style: oblique; font-style: oblique;
} }
} }
/* BlotFormatter 插件的样式 */
.blot-formatter__toolbar-button {
margin: 0 5px;
border: none !important;
background: var(--kungalgame-trans-white-9) !important;
svg {
border: 1px solid var(--kungalgame-blue-4) !important;
background: var(--kungalgame-trans-white-2) !important;
}
}
.is-selected {
svg {
background: var(--kungalgame-trans-blue-1) !important;
}
}
} }
</style> </style>

View file

@ -7,7 +7,7 @@
padding: 0; padding: 0;
text-decoration: none; text-decoration: none;
list-style: none; list-style: none;
font-family: serif, system-ui; font-family: system-ui;
box-sizing: border-box; box-sizing: border-box;
} }