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',
|
OPEN_LATEX_EDITOR = 'OPEN_LATEX_EDITOR',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RichTextCommand {
|
export interface RichTextAction {
|
||||||
command: string;
|
command: string;
|
||||||
value?: string;
|
value?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RichTextCommand {
|
||||||
|
target?: string;
|
||||||
|
action: RichTextAction | RichTextAction[];
|
||||||
|
}
|
||||||
|
|
||||||
type Events = {
|
type Events = {
|
||||||
[EmitterEvents.RICH_TEXT_COMMAND]: RichTextCommand | RichTextCommand[];
|
[EmitterEvents.RICH_TEXT_COMMAND]: RichTextCommand;
|
||||||
[EmitterEvents.OPEN_CHART_DATA_EDITOR]: void;
|
[EmitterEvents.OPEN_CHART_DATA_EDITOR]: void;
|
||||||
[EmitterEvents.OPEN_LATEX_EDITOR]: void;
|
[EmitterEvents.OPEN_LATEX_EDITOR]: void;
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ export default defineComponent({
|
|||||||
]
|
]
|
||||||
|
|
||||||
const emitRichTextCommand = (command: string, value?: string) => {
|
const emitRichTextCommand = (command: string, value?: string) => {
|
||||||
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { command, value })
|
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action: { command, value } })
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -240,7 +240,7 @@ import { defineComponent, ref, watch } from 'vue'
|
|||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
import { useMainStore, useSlidesStore } from '@/store'
|
import { useMainStore, useSlidesStore } from '@/store'
|
||||||
import { PPTTextElement } from '@/types/slides'
|
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 { WEB_FONTS } from '@/configs/font'
|
||||||
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
import useHistorySnapshot from '@/hooks/useHistorySnapshot'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
@ -379,12 +379,12 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 发射富文本设置命令
|
// 发射富文本设置命令
|
||||||
const emitRichTextCommand = (command: string, value?: string) => {
|
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[]) => {
|
const emitBatchRichTextCommand = (action: RichTextAction[]) => {
|
||||||
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, payload)
|
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置富文本超链接
|
// 设置富文本超链接
|
||||||
|
@ -33,8 +33,8 @@ export default defineComponent({
|
|||||||
return selectedSymbol?.children || []
|
return selectedSymbol?.children || []
|
||||||
})
|
})
|
||||||
|
|
||||||
const selectSymbol = (item: string) => {
|
const selectSymbol = (value: string) => {
|
||||||
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { command: 'insert', value: item })
|
emitter.emit(EmitterEvents.RICH_TEXT_COMMAND, { action: { command: 'insert', value } })
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -124,12 +124,13 @@ export default defineComponent({
|
|||||||
|
|
||||||
// 执行富文本命令(可以是一个或多个)
|
// 执行富文本命令(可以是一个或多个)
|
||||||
// 部分命令在执行前先判断当前选区是否为空,如果选区为空先进行全选操作
|
// 部分命令在执行前先判断当前选区是否为空,如果选区为空先进行全选操作
|
||||||
const execCommand = (payload: RichTextCommand | RichTextCommand[]) => {
|
const execCommand = ({ target, action }: RichTextCommand) => {
|
||||||
if (handleElementId.value !== props.elementId) return
|
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) {
|
if (item.command === 'fontname' && item.value) {
|
||||||
const mark = editorView.state.schema.marks.fontname.create({ fontname: item.value })
|
const mark = editorView.state.schema.marks.fontname.create({ fontname: item.value })
|
||||||
autoSelectAll(editorView)
|
autoSelectAll(editorView)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user