mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
refactor: 富文本执行命令参数结构调整
This commit is contained in:
parent
9ed5a3e708
commit
54b122b77e
@ -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;
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 })
|
||||
}
|
||||
|
||||
// 设置富文本超链接
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user