refactor: 富文本执行命令参数结构调整

This commit is contained in:
pipipi-pikachu 2022-05-02 21:10:32 +08:00
parent 9ed5a3e708
commit 54b122b77e
5 changed files with 19 additions and 13 deletions

View File

@ -6,13 +6,18 @@ export const enum EmitterEvents {
OPEN_LATEX_EDITOR = 'OPEN_LATEX_EDITOR',
}
export interface RichTextCommand {
export interface RichTextAction {
command: string;
value?: string;
}
export interface RichTextCommand {
target?: string;
action: RichTextAction | RichTextAction[];
}
type Events = {
[EmitterEvents.RICH_TEXT_COMMAND]: RichTextCommand | RichTextCommand[];
[EmitterEvents.RICH_TEXT_COMMAND]: RichTextCommand;
[EmitterEvents.OPEN_CHART_DATA_EDITOR]: void;
[EmitterEvents.OPEN_LATEX_EDITOR]: void;
}

View File

@ -289,7 +289,7 @@ export default defineComponent({
]
const emitRichTextCommand = (command: string, value?: string) => {
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { command, value })
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action: { command, value } })
}
return {

View File

@ -240,7 +240,7 @@ import { defineComponent, ref, watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore } from '@/store'
import { PPTTextElement } from '@/types/slides'
import emitter, { EmitterEvents, RichTextCommand } from '@/utils/emitter'
import emitter, { EmitterEvents, RichTextAction } from '@/utils/emitter'
import { WEB_FONTS } from '@/configs/font'
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
import { message } from 'ant-design-vue'
@ -379,12 +379,12 @@ export default defineComponent({
//
const emitRichTextCommand = (command: string, value?: string) => {
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { command, value })
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action: { command, value } })
}
//
const emitBatchRichTextCommand = (payload: RichTextCommand[]) => {
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, payload)
const emitBatchRichTextCommand = (action: RichTextAction[]) => {
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action })
}
//

View File

@ -33,8 +33,8 @@ export default defineComponent({
return selectedSymbol?.children || []
})
const selectSymbol = (item: string) => {
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { command: 'insert', value: item })
const selectSymbol = (value: string) => {
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action: { command: 'insert', value } })
}
return {

View File

@ -124,12 +124,13 @@ export default defineComponent({
//
//
const execCommand = (payload: RichTextCommand | RichTextCommand[]) => {
if (handleElementId.value !== props.elementId) return
const execCommand = ({ target, action }: RichTextCommand) => {
if (!target && handleElementId.value !== props.elementId) return
if (target && target !== props.elementId) return
const commands = ('command' in payload) ? [payload] : payload
const actions = ('command' in action) ? [action] : action
for (const item of commands) {
for (const item of actions) {
if (item.command === 'fontname' && item.value) {
const mark = editorView.state.schema.marks.fontname.create({ fontname: item.value })
autoSelectAll(editorView)