mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
perf: 文本框优化(创建文本自动聚焦、空文本自动删除)
This commit is contained in:
parent
d7a85ca83c
commit
138f09cdd2
@ -32,7 +32,7 @@ export default () => {
|
||||
const { addHistorySnapshot } = useHistorySnapshot()
|
||||
|
||||
// 创建(插入)一个元素并将其设置为被选中元素
|
||||
const createElement = (element: PPTElement) => {
|
||||
const createElement = (element: PPTElement, callback?: () => void) => {
|
||||
slidesStore.addElement(element)
|
||||
mainStore.setActiveElementIdList([element.id])
|
||||
|
||||
@ -42,6 +42,8 @@ export default () => {
|
||||
mainStore.setEditorareaFocus(true)
|
||||
}, 0)
|
||||
|
||||
if (callback) callback()
|
||||
|
||||
addHistorySnapshot()
|
||||
}
|
||||
|
||||
@ -170,11 +172,12 @@ export default () => {
|
||||
* @param position 位置大小信息
|
||||
* @param content 文本内容
|
||||
*/
|
||||
const createTextElement = (position: CommonElementPosition, content = '请输入内容') => {
|
||||
const createTextElement = (position: CommonElementPosition, content = '') => {
|
||||
const { left, top, width, height } = position
|
||||
const id = nanoid(10)
|
||||
createElement({
|
||||
type: 'text',
|
||||
id: nanoid(10),
|
||||
id,
|
||||
left,
|
||||
top,
|
||||
width,
|
||||
@ -183,6 +186,11 @@ export default () => {
|
||||
rotate: 0,
|
||||
defaultFontName: theme.value.fontName,
|
||||
defaultColor: theme.value.fontColor,
|
||||
}, () => {
|
||||
setTimeout(() => {
|
||||
const editorRef: HTMLElement | null = document.querySelector(`#editable-element-${id} .ProseMirror`)
|
||||
if (editorRef) editorRef.focus()
|
||||
}, 0)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,13 @@ export const useSlidesStore = defineStore('slides', {
|
||||
const newEls = [...currentSlideEls, ...elements]
|
||||
this.slides[this.slideIndex].elements = newEls
|
||||
},
|
||||
|
||||
deleteElement(elementId: string | string[]) {
|
||||
const elementIdList = Array.isArray(elementId) ? elementId : [elementId]
|
||||
const currentSlideEls = this.slides[this.slideIndex].elements
|
||||
const newEls = currentSlideEls.filter(item => !elementIdList.includes(item.id))
|
||||
this.slides[this.slideIndex].elements = newEls
|
||||
},
|
||||
|
||||
updateElement(data: UpdateElementData) {
|
||||
const { id, props } = data
|
||||
|
@ -145,7 +145,7 @@ export default (
|
||||
baseTop = oppositePoint.top
|
||||
}
|
||||
|
||||
// 未旋转的元素具有缩放时的对齐吸附功能,在这处收集对齐对齐吸附线
|
||||
// 未旋转的元素具有缩放时的对齐吸附功能,在此处收集对齐对齐吸附线
|
||||
// 包括页面内除目标元素外的其他元素在画布中的各个可吸附对齐位置:上下左右四边
|
||||
// 其中线条和被旋转过的元素不参与吸附对齐
|
||||
else {
|
||||
|
@ -11,7 +11,7 @@ import { debounce } from 'lodash'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useMainStore } from '@/store'
|
||||
import { EditorView } from 'prosemirror-view'
|
||||
import { toggleMark, wrapIn, selectAll } from 'prosemirror-commands'
|
||||
import { toggleMark, wrapIn } from 'prosemirror-commands'
|
||||
import { initProsemirrorEditor, createDocument } from '@/utils/prosemirror'
|
||||
import { findNodesWithSameMark, getTextAttrs, autoSelectAll, addMark, markActive, getFontsize } from '@/utils/prosemirror/utils'
|
||||
import emitter, { EmitterEvents, RichTextCommand } from '@/utils/emitter'
|
||||
@ -63,11 +63,6 @@ export default defineComponent({
|
||||
}, 300, { trailing: true })
|
||||
|
||||
const handleFocus = () => {
|
||||
if (props.value === '请输入内容') {
|
||||
setTimeout(() => {
|
||||
selectAll(editorView.state, editorView.dispatch)
|
||||
}, 100)
|
||||
}
|
||||
mainStore.setDisableHotkeysState(true)
|
||||
emit('focus')
|
||||
}
|
||||
|
@ -40,6 +40,7 @@
|
||||
:editable="!elementInfo.lock"
|
||||
:value="elementInfo.content"
|
||||
@update="value => updateContent(value)"
|
||||
@blur="checkEmptyText()"
|
||||
@mousedown="$event => handleSelectElement($event, false)"
|
||||
/>
|
||||
|
||||
@ -151,11 +152,17 @@ export default defineComponent({
|
||||
addHistorySnapshot()
|
||||
}
|
||||
|
||||
const checkEmptyText = () => {
|
||||
const pureText = props.elementInfo.content.replaceAll(/<[^>]+>/g, '')
|
||||
if (!pureText) slidesStore.deleteElement(props.elementInfo.id)
|
||||
}
|
||||
|
||||
return {
|
||||
elementRef,
|
||||
shadowStyle,
|
||||
updateContent,
|
||||
handleSelectElement,
|
||||
checkEmptyText,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user