jvs-ppt-ui 0.0.37 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/jvs-ppt-ui.es.js +22348 -21892
- package/dist/lib/jvs-ppt-ui.umd.js +111 -111
- package/dist/lib/style.css +1 -1
- package/package.json +1 -1
- package/src/App.vue +7 -5
- package/src/components/CanvasArea.vue +316 -59
- package/src/components/Header.vue +2 -4
- package/src/components/PptEditor.vue +97 -5
- package/src/components/SidebarLeft.vue +30 -6
- package/src/components/canvas/elements/CanvasGroupElement.vue +3 -0
- package/src/components/canvas/elements/CanvasTextElement.vue +1 -1
- package/src/components/sidebar/common/SidebarPositionGroup.vue +199 -33
- package/src/components/sidebar/panels/SidebarImageFormatPanel.vue +37 -33
- package/src/composables/canvas/useCanvasCrop.ts +25 -2
- package/src/composables/canvas/useCanvasText.ts +27 -8
- package/src/composables/sidebar/useSidebarElementTransform.ts +13 -7
- package/src/composables/useSlides.ts +6 -4
- package/src/index.ts +8 -1
- package/src/style.css +1 -1
- package/src/types/index.ts +14 -0
- package/src/utils/canvas/formatPainter.ts +91 -32
- package/src/utils/localDraftStorage.ts +340 -0
|
@@ -30,6 +30,7 @@ if (currentApp) {
|
|
|
30
30
|
|
|
31
31
|
import { useSlides } from '../composables/useSlides'
|
|
32
32
|
import { builtinSlideTemplates, setCustomTemplates, addCustomTemplate } from '../configs/slideTemplates'
|
|
33
|
+
import { saveDraftToIndexedDB, loadDraftFromIndexedDB, clearDraftFromIndexedDB } from '../utils/localDraftStorage'
|
|
33
34
|
import type { Slide, SlideMaster, DeckData, PptEditorProps, PptEditorApi, SaveOptions, LoadSourceOptions, LoadSourceResult } from '../types'
|
|
34
35
|
|
|
35
36
|
const props = withDefaults(defineProps<PptEditorProps>(), {
|
|
@@ -57,6 +58,8 @@ const props = withDefaults(defineProps<PptEditorProps>(), {
|
|
|
57
58
|
templates: undefined,
|
|
58
59
|
templateBaseUrl: '',
|
|
59
60
|
replaceBuiltinTemplates: undefined,
|
|
61
|
+
localStorageCache: undefined,
|
|
62
|
+
localStorageKey: '',
|
|
60
63
|
config: () => ({})
|
|
61
64
|
})
|
|
62
65
|
|
|
@@ -78,6 +81,12 @@ const {
|
|
|
78
81
|
activeSlide,
|
|
79
82
|
presentationTitle,
|
|
80
83
|
slideMasters,
|
|
84
|
+
activeMasterId,
|
|
85
|
+
globalFontFamily,
|
|
86
|
+
globalFontColor,
|
|
87
|
+
globalBgColor,
|
|
88
|
+
globalThemeColor,
|
|
89
|
+
themeSchemeFillMap,
|
|
81
90
|
themeClrScheme,
|
|
82
91
|
slideRatio,
|
|
83
92
|
slideHeight,
|
|
@@ -265,13 +274,26 @@ if (props.config?.title) {
|
|
|
265
274
|
|
|
266
275
|
// 获取当前完整 Deck 工程数据
|
|
267
276
|
function getDeck(): DeckData {
|
|
277
|
+
const serializedMasters = JSON.parse(JSON.stringify(toRaw(slideMasters.value) || []))
|
|
268
278
|
return {
|
|
269
279
|
title: presentationTitle.value || '未命名演示文稿',
|
|
280
|
+
width: logicalWidth.value,
|
|
281
|
+
height: logicalHeight.value,
|
|
282
|
+
ratio: slideRatio.value,
|
|
283
|
+
theme: {
|
|
284
|
+
fontFamily: globalFontFamily.value,
|
|
285
|
+
fontColor: globalFontColor.value,
|
|
286
|
+
themeColor: toRaw(globalThemeColor.value),
|
|
287
|
+
backgroundColor: globalBgColor.value
|
|
288
|
+
},
|
|
289
|
+
activeMasterId: activeMasterId.value,
|
|
270
290
|
// toRaw 序列化:避免 stringify 遍历响应式代理时把调用方的 active effect 订阅到整册
|
|
271
291
|
// (曾在 computed 里调用 getDeck 导致拖拽每步都整册深拷贝,页数越多越卡)
|
|
272
292
|
slides: JSON.parse(JSON.stringify(toRaw(slides.value) || [])),
|
|
273
|
-
|
|
274
|
-
|
|
293
|
+
masters: serializedMasters,
|
|
294
|
+
slideMasters: serializedMasters,
|
|
295
|
+
schemeFillMap: toRaw(themeSchemeFillMap.value),
|
|
296
|
+
themeClrScheme: toRaw(themeClrScheme.value),
|
|
275
297
|
slideRatio: slideRatio.value,
|
|
276
298
|
slideHeight: slideHeight.value,
|
|
277
299
|
logicalWidth: logicalWidth.value,
|
|
@@ -295,11 +317,11 @@ function setSlides(newSlides: Slide[]) {
|
|
|
295
317
|
}
|
|
296
318
|
|
|
297
319
|
// 加载完整 Deck 工程数据
|
|
298
|
-
function loadDeck(deck: DeckData | Slide[]) {
|
|
320
|
+
function loadDeck(deck: DeckData | Slide[], options?: { silent?: boolean }) {
|
|
299
321
|
if (!deck) return
|
|
300
322
|
isInternalUpdating = true
|
|
301
323
|
if (Array.isArray(deck)) {
|
|
302
|
-
importSlides(deck)
|
|
324
|
+
importSlides(deck, options)
|
|
303
325
|
} else {
|
|
304
326
|
if (deck.title) {
|
|
305
327
|
presentationTitle.value = deck.title
|
|
@@ -308,7 +330,7 @@ function loadDeck(deck: DeckData | Slide[]) {
|
|
|
308
330
|
slideMasters.value = deck.slideMasters
|
|
309
331
|
}
|
|
310
332
|
if (deck.slides && Array.isArray(deck.slides)) {
|
|
311
|
-
importSlides(deck
|
|
333
|
+
importSlides(deck, options)
|
|
312
334
|
}
|
|
313
335
|
}
|
|
314
336
|
nextTick(() => {
|
|
@@ -790,6 +812,48 @@ watch(
|
|
|
790
812
|
{ immediate: true, deep: true }
|
|
791
813
|
)
|
|
792
814
|
|
|
815
|
+
// 是否开启浏览器本地 IndexedDB 自动缓存
|
|
816
|
+
const isLocalCacheEnabled = computed(() => {
|
|
817
|
+
if (props.localStorageCache !== undefined) return Boolean(props.localStorageCache)
|
|
818
|
+
if (props.config?.localStorageCache !== undefined) return Boolean(props.config.localStorageCache)
|
|
819
|
+
return false
|
|
820
|
+
})
|
|
821
|
+
|
|
822
|
+
const resolvedLocalStorageKey = computed(() => {
|
|
823
|
+
return props.localStorageKey || props.config?.localStorageKey || 'default_workspace_draft'
|
|
824
|
+
})
|
|
825
|
+
|
|
826
|
+
let isRestoringLocalDraft = false
|
|
827
|
+
|
|
828
|
+
async function saveLocalDraft(): Promise<boolean> {
|
|
829
|
+
if (isRestoringLocalDraft) return false
|
|
830
|
+
const currentDeck = getDeck()
|
|
831
|
+
return await saveDraftToIndexedDB(currentDeck, activeIndex.value, resolvedLocalStorageKey.value)
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
async function restoreLocalDraft(): Promise<boolean> {
|
|
835
|
+
try {
|
|
836
|
+
isRestoringLocalDraft = true
|
|
837
|
+
const record = await loadDraftFromIndexedDB(resolvedLocalStorageKey.value)
|
|
838
|
+
if (!record || !record.deck || !Array.isArray(record.deck.slides) || record.deck.slides.length === 0) {
|
|
839
|
+
return false
|
|
840
|
+
}
|
|
841
|
+
loadDeck(record.deck, { silent: true })
|
|
842
|
+
if (typeof record.activeIndex === 'number' && record.activeIndex >= 0 && record.activeIndex < record.deck.slides.length) {
|
|
843
|
+
selectSlide(record.activeIndex)
|
|
844
|
+
}
|
|
845
|
+
return true
|
|
846
|
+
} finally {
|
|
847
|
+
nextTick(() => {
|
|
848
|
+
isRestoringLocalDraft = false
|
|
849
|
+
})
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
async function clearLocalDraft(): Promise<boolean> {
|
|
854
|
+
return await clearDraftFromIndexedDB(resolvedLocalStorageKey.value)
|
|
855
|
+
}
|
|
856
|
+
|
|
793
857
|
// 对外 deck 同步防抖:打字/连续微编辑不再每次都整册 getDeck 深拷贝+emit,
|
|
794
858
|
// 300ms 静默后统一发一次;拖拽落沿/翻页/卸载时立即冲刷,宿主侧最终一致
|
|
795
859
|
let emitDeckTimer: ReturnType<typeof setTimeout> | null = null
|
|
@@ -812,6 +876,9 @@ function emitDeckNow() {
|
|
|
812
876
|
activeIndex: activeIndex.value,
|
|
813
877
|
title: presentationTitle.value
|
|
814
878
|
})
|
|
879
|
+
if (isLocalCacheEnabled.value && !isRestoringLocalDraft) {
|
|
880
|
+
saveDraftToIndexedDB(currentDeck, activeIndex.value, resolvedLocalStorageKey.value)
|
|
881
|
+
}
|
|
815
882
|
nextTick(() => {
|
|
816
883
|
isInternalUpdating = false
|
|
817
884
|
})
|
|
@@ -849,7 +916,11 @@ watch([() => isCanvasDragging?.value, () => pauseHistory?.value], ([isDragging,
|
|
|
849
916
|
watch(
|
|
850
917
|
() => activeIndex.value,
|
|
851
918
|
(idx) => {
|
|
919
|
+
const hadPending = emitDeckPending
|
|
852
920
|
emitDeckNow()
|
|
921
|
+
if (!hadPending && isLocalCacheEnabled.value && !isRestoringLocalDraft && !isInternalUpdating) {
|
|
922
|
+
saveDraftToIndexedDB(getDeck(), idx, resolvedLocalStorageKey.value)
|
|
923
|
+
}
|
|
853
924
|
emit('slideChange', {
|
|
854
925
|
index: idx,
|
|
855
926
|
slide: activeSlide.value || null
|
|
@@ -857,6 +928,17 @@ watch(
|
|
|
857
928
|
}
|
|
858
929
|
)
|
|
859
930
|
|
|
931
|
+
// 监听标题修改同步到本地 IndexedDB
|
|
932
|
+
watch(
|
|
933
|
+
() => presentationTitle.value,
|
|
934
|
+
() => {
|
|
935
|
+
if (isInternalUpdating || isRestoringLocalDraft) return
|
|
936
|
+
if (isLocalCacheEnabled.value) {
|
|
937
|
+
scheduleEmitDeck()
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
)
|
|
941
|
+
|
|
860
942
|
// 公式编辑确认
|
|
861
943
|
function handleFormulaConfirm(latex: string) {
|
|
862
944
|
if (currentEditingFormulaEl.value) {
|
|
@@ -929,6 +1011,9 @@ const editorApi: PptEditorApi = {
|
|
|
929
1011
|
addTemplate: (template) => addCustomTemplate(template),
|
|
930
1012
|
getTemplates: () => [...builtinSlideTemplates],
|
|
931
1013
|
isTemplateEnabled,
|
|
1014
|
+
saveLocalDraft,
|
|
1015
|
+
restoreLocalDraft,
|
|
1016
|
+
clearLocalDraft,
|
|
932
1017
|
slidesComposable: slidesState
|
|
933
1018
|
}
|
|
934
1019
|
|
|
@@ -1039,6 +1124,7 @@ onMounted(async () => {
|
|
|
1039
1124
|
emit('ready', editorApi)
|
|
1040
1125
|
|
|
1041
1126
|
// 若启用 MCP 自动拉取
|
|
1127
|
+
let loadedFromMcp = false
|
|
1042
1128
|
if (props.enableMcp) {
|
|
1043
1129
|
const params = new URLSearchParams(window.location.search)
|
|
1044
1130
|
const deckId = params.get('deckId')
|
|
@@ -1054,12 +1140,18 @@ onMounted(async () => {
|
|
|
1054
1140
|
}
|
|
1055
1141
|
const deck = await response.json()
|
|
1056
1142
|
loadDeck(deck)
|
|
1143
|
+
loadedFromMcp = true
|
|
1057
1144
|
notify('已从 MCP 打开可编辑稿')
|
|
1058
1145
|
} catch (error: any) {
|
|
1059
1146
|
notify(`打开 MCP 稿件失败:${error?.message || error}`)
|
|
1060
1147
|
}
|
|
1061
1148
|
}
|
|
1062
1149
|
}
|
|
1150
|
+
|
|
1151
|
+
// 若启用了浏览器本地 IndexedDB 自动缓存,且未通过外部 modelValue 或 MCP 载入初始数据,则自动从 IndexedDB 恢复上次编辑内容
|
|
1152
|
+
if (isLocalCacheEnabled.value && !loadedFromMcp && !props.modelValue) {
|
|
1153
|
+
await restoreLocalDraft()
|
|
1154
|
+
}
|
|
1063
1155
|
})
|
|
1064
1156
|
|
|
1065
1157
|
onBeforeUnmount(() => {
|
|
@@ -642,6 +642,16 @@ function ensureTemplateMasterForSlide(tpl: SlideTemplateItem, slide: any): strin
|
|
|
642
642
|
return newMasterId
|
|
643
643
|
}
|
|
644
644
|
|
|
645
|
+
function isSlideBlankOrUnedited(slide: any): boolean {
|
|
646
|
+
if (!slide) return false
|
|
647
|
+
const els = Array.isArray(slide.elements) ? slide.elements.filter(Boolean) : []
|
|
648
|
+
if (els.length === 0) return true
|
|
649
|
+
return els.every((el: any) => {
|
|
650
|
+
if (el.isPlaceholderReplaced || el.replaced) return false
|
|
651
|
+
return isPlaceholderElement(el)
|
|
652
|
+
})
|
|
653
|
+
}
|
|
654
|
+
|
|
645
655
|
function insertSingleTemplateSlide(tpl: SlideTemplateItem, slide: any, slideIdx: number) {
|
|
646
656
|
if (!slide) return
|
|
647
657
|
addHistorySnapshot()
|
|
@@ -652,9 +662,16 @@ function insertSingleTemplateSlide(tpl: SlideTemplateItem, slide: any, slideIdx:
|
|
|
652
662
|
if (!cloned.title) {
|
|
653
663
|
cloned.title = `${tpl.name} - 幻灯片 ${slideIdx + 1}`
|
|
654
664
|
}
|
|
655
|
-
const
|
|
656
|
-
slides.value
|
|
657
|
-
|
|
665
|
+
const currentIdx = Math.max(0, Math.min(slides.value.length - 1, activeIndex.value))
|
|
666
|
+
const curSlide = slides.value[currentIdx]
|
|
667
|
+
if (curSlide && isSlideBlankOrUnedited(curSlide)) {
|
|
668
|
+
slides.value.splice(currentIdx, 1, cloned)
|
|
669
|
+
activeIndex.value = currentIdx
|
|
670
|
+
} else {
|
|
671
|
+
const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
|
|
672
|
+
slides.value.splice(insertPos, 0, cloned)
|
|
673
|
+
activeIndex.value = insertPos
|
|
674
|
+
}
|
|
658
675
|
activeSlideVersion.value++
|
|
659
676
|
displaySlides.value = [...slides.value]
|
|
660
677
|
addHistorySnapshot()
|
|
@@ -675,9 +692,16 @@ function insertAllTemplateSlides(tpl: SlideTemplateItem) {
|
|
|
675
692
|
}
|
|
676
693
|
return cloned
|
|
677
694
|
})
|
|
678
|
-
const
|
|
679
|
-
slides.value
|
|
680
|
-
|
|
695
|
+
const currentIdx = Math.max(0, Math.min(slides.value.length - 1, activeIndex.value))
|
|
696
|
+
const curSlide = slides.value[currentIdx]
|
|
697
|
+
if (curSlide && isSlideBlankOrUnedited(curSlide)) {
|
|
698
|
+
slides.value.splice(currentIdx, 1, ...clonedList)
|
|
699
|
+
activeIndex.value = currentIdx
|
|
700
|
+
} else {
|
|
701
|
+
const insertPos = Math.min(slides.value.length, Math.max(0, activeIndex.value + 1))
|
|
702
|
+
slides.value.splice(insertPos, 0, ...clonedList)
|
|
703
|
+
activeIndex.value = insertPos
|
|
704
|
+
}
|
|
681
705
|
activeSlideVersion.value++
|
|
682
706
|
displaySlides.value = [...slides.value]
|
|
683
707
|
addHistorySnapshot()
|
|
@@ -156,6 +156,9 @@ function sortGroupElements(elements: any[]) {
|
|
|
156
156
|
@text-blur="emit('textBlur', $event, child)"
|
|
157
157
|
@text-input="emit('textInput', $event, child)"
|
|
158
158
|
@text-key-down="emit('textKeyDown', $event, child)"
|
|
159
|
+
@mousemove="emit('textMouseMove', $event, child)"
|
|
160
|
+
@mouseleave="emit('textMouseLeave', $event, child)"
|
|
161
|
+
@dblclick="emit('startEditing', child.id, $event)"
|
|
159
162
|
@start-editing="(ev) => emit('startEditing', child.id, ev)"
|
|
160
163
|
/>
|
|
161
164
|
</template>
|
|
@@ -30,7 +30,7 @@ function syncContentToDom(force = false) {
|
|
|
30
30
|
if (!editableRef.value) return
|
|
31
31
|
// 编辑中(焦点在元素自身或其内部——表格编辑时焦点在动态设 contenteditable 的 td 上)
|
|
32
32
|
// 绝不强制用 HTML 冲刷 DOM,防止光标/选中丢失;结构操作经 commitTableContent 强制同步
|
|
33
|
-
if (!force && document.activeElement && editableRef.value.contains(document.activeElement)) {
|
|
33
|
+
if (!force && props.isEditingText && document.activeElement && editableRef.value.contains(document.activeElement)) {
|
|
34
34
|
return
|
|
35
35
|
}
|
|
36
36
|
const newHtml = targetHtml.value || ''
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, computed } from 'vue'
|
|
2
|
+
import { ref, computed, nextTick } from 'vue'
|
|
3
3
|
import { useSlides } from '../../../composables/useSlides'
|
|
4
4
|
|
|
5
5
|
const props = withDefaults(defineProps<{
|
|
@@ -36,7 +36,7 @@ const emit = defineEmits<{
|
|
|
36
36
|
(e: 'adjustZIndex', command: any): void
|
|
37
37
|
}>()
|
|
38
38
|
|
|
39
|
-
const { activeSlide, selectedElementId, selectedElementIds } = useSlides()
|
|
39
|
+
const { activeSlide, selectedElementId, selectedElementIds, undo, redo } = useSlides()
|
|
40
40
|
|
|
41
41
|
const selectedIds = computed(() => {
|
|
42
42
|
if (selectedElementIds.value && selectedElementIds.value.length > 0) {
|
|
@@ -74,36 +74,184 @@ const canMoveDown = computed(() => {
|
|
|
74
74
|
const canMoveTop = computed(() => canMoveUp.value)
|
|
75
75
|
const canMoveBottom = computed(() => canMoveDown.value)
|
|
76
76
|
|
|
77
|
+
type FieldKey = 'X' | 'Y' | 'W' | 'H' | 'ROTATE'
|
|
78
|
+
const MIN_ELEMENT_DIMENSION = 10
|
|
79
|
+
|
|
80
|
+
const focusedField = ref<FieldKey | null>(null)
|
|
81
|
+
const draftText = ref<string>('')
|
|
82
|
+
const focusInitialVal = ref<number>(0)
|
|
83
|
+
const fieldUndoStack = ref<string[]>([])
|
|
84
|
+
const fieldRedoStack = ref<string[]>([])
|
|
85
|
+
|
|
77
86
|
const rotateInputRef = ref<HTMLInputElement | null>(null)
|
|
78
|
-
const rotateDisplayLen = computed(() =>
|
|
87
|
+
const rotateDisplayLen = computed(() => {
|
|
88
|
+
const text = focusedField.value === 'ROTATE' ? draftText.value : String(props.elementRotate ?? 0)
|
|
89
|
+
return Math.max(1, text.length)
|
|
90
|
+
})
|
|
79
91
|
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
function getPropVal(field: FieldKey): number {
|
|
93
|
+
switch (field) {
|
|
94
|
+
case 'X': return props.elementX ?? 0
|
|
95
|
+
case 'Y': return props.elementY ?? 0
|
|
96
|
+
case 'W': return props.elementW ?? MIN_ELEMENT_DIMENSION
|
|
97
|
+
case 'H': return props.elementH ?? MIN_ELEMENT_DIMENSION
|
|
98
|
+
case 'ROTATE': return props.elementRotate ?? 0
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
102
|
+
function emitFieldVal(field: FieldKey, val: number) {
|
|
103
|
+
switch (field) {
|
|
104
|
+
case 'X': emit('update:elementX', val); break
|
|
105
|
+
case 'Y': emit('update:elementY', val); break
|
|
106
|
+
case 'W': emit('update:elementW', val); break
|
|
107
|
+
case 'H': emit('update:elementH', val); break
|
|
108
|
+
case 'ROTATE': emit('update:elementRotate', val); break
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function normalizeRotateVal(val: number): number {
|
|
93
113
|
let deg = Math.round(val) % 360
|
|
94
114
|
if (deg < 0) deg += 360
|
|
95
|
-
|
|
115
|
+
return deg
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function onFieldFocus(field: FieldKey) {
|
|
119
|
+
const curVal = getPropVal(field)
|
|
120
|
+
focusedField.value = field
|
|
121
|
+
draftText.value = String(curVal)
|
|
122
|
+
focusInitialVal.value = curVal
|
|
123
|
+
fieldUndoStack.value = [draftText.value]
|
|
124
|
+
fieldRedoStack.value = []
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function recordDraftChange(text: string) {
|
|
128
|
+
draftText.value = text
|
|
129
|
+
const stack = fieldUndoStack.value
|
|
130
|
+
if (stack.length === 0 || stack[stack.length - 1] !== text) {
|
|
131
|
+
stack.push(text)
|
|
132
|
+
if (stack.length > 50) stack.shift()
|
|
133
|
+
}
|
|
134
|
+
fieldRedoStack.value = []
|
|
96
135
|
}
|
|
97
136
|
|
|
98
|
-
function
|
|
137
|
+
function applyDraftIfValid(field: FieldKey, rawText: string) {
|
|
138
|
+
const raw = rawText.trim()
|
|
139
|
+
if (raw === '' || raw === '-') return
|
|
140
|
+
const num = Number(raw)
|
|
141
|
+
if (isNaN(num)) return
|
|
142
|
+
if (field === 'W' || field === 'H') {
|
|
143
|
+
if (num < MIN_ELEMENT_DIMENSION) return
|
|
144
|
+
emitFieldVal(field, num)
|
|
145
|
+
} else if (field === 'ROTATE') {
|
|
146
|
+
emitFieldVal(field, normalizeRotateVal(num))
|
|
147
|
+
} else {
|
|
148
|
+
emitFieldVal(field, num)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function onFieldInput(field: FieldKey, e: Event) {
|
|
153
|
+
const target = e.target as HTMLInputElement
|
|
154
|
+
recordDraftChange(target.value)
|
|
155
|
+
applyDraftIfValid(field, target.value)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function onFieldBlur(field: FieldKey, e: Event) {
|
|
99
159
|
const target = e.target as HTMLInputElement
|
|
100
|
-
|
|
101
|
-
|
|
160
|
+
const raw = target.value.trim()
|
|
161
|
+
let finalVal: number
|
|
162
|
+
|
|
163
|
+
if (field === 'W' || field === 'H') {
|
|
164
|
+
const fallback = Math.max(MIN_ELEMENT_DIMENSION, focusInitialVal.value || getPropVal(field))
|
|
165
|
+
if (raw === '' || raw === '-' || isNaN(Number(raw))) {
|
|
166
|
+
finalVal = fallback
|
|
167
|
+
} else {
|
|
168
|
+
finalVal = Math.max(MIN_ELEMENT_DIMENSION, Number(raw))
|
|
169
|
+
}
|
|
170
|
+
} else if (field === 'ROTATE') {
|
|
171
|
+
const fallback = normalizeRotateVal(focusInitialVal.value || getPropVal(field))
|
|
172
|
+
if (raw === '' || raw === '-' || isNaN(Number(raw))) {
|
|
173
|
+
finalVal = fallback
|
|
174
|
+
} else {
|
|
175
|
+
finalVal = normalizeRotateVal(Number(raw))
|
|
176
|
+
}
|
|
102
177
|
} else {
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
178
|
+
const fallback = focusInitialVal.value ?? getPropVal(field)
|
|
179
|
+
if (raw === '' || raw === '-' || isNaN(Number(raw))) {
|
|
180
|
+
finalVal = fallback
|
|
181
|
+
} else {
|
|
182
|
+
finalVal = Number(raw)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
focusedField.value = null
|
|
187
|
+
draftText.value = String(finalVal)
|
|
188
|
+
fieldUndoStack.value = []
|
|
189
|
+
fieldRedoStack.value = []
|
|
190
|
+
target.value = String(finalVal)
|
|
191
|
+
emitFieldVal(field, finalVal)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function onFieldKeyDown(field: FieldKey, e: KeyboardEvent) {
|
|
195
|
+
if (e.key === 'Enter') {
|
|
196
|
+
;(e.target as HTMLElement)?.blur()
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
const isMod = e.ctrlKey || e.metaKey
|
|
200
|
+
if (!isMod) return
|
|
201
|
+
const key = e.key.toLowerCase()
|
|
202
|
+
const isUndo = key === 'z' && !e.shiftKey
|
|
203
|
+
const isRedo = key === 'y' || (key === 'z' && e.shiftKey)
|
|
204
|
+
if (!isUndo && !isRedo) return
|
|
205
|
+
|
|
206
|
+
// 彻底阻止浏览器原生 input 撤销栈将已回填的值重复拼接(如 92 变 9292)
|
|
207
|
+
e.preventDefault()
|
|
208
|
+
e.stopPropagation()
|
|
209
|
+
const target = e.target as HTMLInputElement
|
|
210
|
+
|
|
211
|
+
if (isUndo) {
|
|
212
|
+
if (fieldUndoStack.value.length > 1) {
|
|
213
|
+
const current = fieldUndoStack.value.pop()!
|
|
214
|
+
fieldRedoStack.value.push(current)
|
|
215
|
+
const prev = fieldUndoStack.value[fieldUndoStack.value.length - 1]
|
|
216
|
+
draftText.value = prev
|
|
217
|
+
target.value = prev
|
|
218
|
+
applyDraftIfValid(field, prev)
|
|
219
|
+
} else {
|
|
220
|
+
if (undo) undo()
|
|
221
|
+
nextTick(() => {
|
|
222
|
+
const nextVal = String(getPropVal(field))
|
|
223
|
+
draftText.value = nextVal
|
|
224
|
+
focusInitialVal.value = Number(nextVal) || 0
|
|
225
|
+
fieldUndoStack.value = [nextVal]
|
|
226
|
+
fieldRedoStack.value = []
|
|
227
|
+
target.value = nextVal
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
} else if (isRedo) {
|
|
231
|
+
if (fieldRedoStack.value.length > 0) {
|
|
232
|
+
const next = fieldRedoStack.value.pop()!
|
|
233
|
+
fieldUndoStack.value.push(next)
|
|
234
|
+
draftText.value = next
|
|
235
|
+
target.value = next
|
|
236
|
+
applyDraftIfValid(field, next)
|
|
237
|
+
} else {
|
|
238
|
+
if (redo) redo()
|
|
239
|
+
nextTick(() => {
|
|
240
|
+
const nextVal = String(getPropVal(field))
|
|
241
|
+
draftText.value = nextVal
|
|
242
|
+
focusInitialVal.value = Number(nextVal) || 0
|
|
243
|
+
fieldUndoStack.value = [nextVal]
|
|
244
|
+
fieldRedoStack.value = []
|
|
245
|
+
target.value = nextVal
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function focusRotateInput(e: MouseEvent) {
|
|
252
|
+
if (e.target !== rotateInputRef.value) {
|
|
253
|
+
rotateInputRef.value?.focus()
|
|
254
|
+
rotateInputRef.value?.select()
|
|
107
255
|
}
|
|
108
256
|
}
|
|
109
257
|
</script>
|
|
@@ -115,14 +263,22 @@ function onRotateBlur(e: Event) {
|
|
|
115
263
|
<div class="pos-main-cols">
|
|
116
264
|
<div class="custom-num-input">
|
|
117
265
|
<span class="custom-num-prefix">X</span>
|
|
118
|
-
<input type="number" step="any"
|
|
119
|
-
|
|
266
|
+
<input type="number" step="any"
|
|
267
|
+
:value="focusedField === 'X' ? draftText : elementX"
|
|
268
|
+
@focus="onFieldFocus('X')"
|
|
269
|
+
@input="onFieldInput('X', $event)"
|
|
270
|
+
@blur="onFieldBlur('X', $event)"
|
|
271
|
+
@keydown="onFieldKeyDown('X', $event)"
|
|
120
272
|
class="custom-num-field" />
|
|
121
273
|
</div>
|
|
122
274
|
<div class="custom-num-input">
|
|
123
275
|
<span class="custom-num-prefix">Y</span>
|
|
124
|
-
<input type="number" step="any"
|
|
125
|
-
|
|
276
|
+
<input type="number" step="any"
|
|
277
|
+
:value="focusedField === 'Y' ? draftText : elementY"
|
|
278
|
+
@focus="onFieldFocus('Y')"
|
|
279
|
+
@input="onFieldInput('Y', $event)"
|
|
280
|
+
@blur="onFieldBlur('Y', $event)"
|
|
281
|
+
@keydown="onFieldKeyDown('Y', $event)"
|
|
126
282
|
class="custom-num-field" />
|
|
127
283
|
</div>
|
|
128
284
|
</div>
|
|
@@ -134,14 +290,23 @@ function onRotateBlur(e: Event) {
|
|
|
134
290
|
<div class="pos-main-cols">
|
|
135
291
|
<div class="custom-num-input">
|
|
136
292
|
<span class="custom-num-prefix">W</span>
|
|
137
|
-
<input type="number" step="any" :
|
|
138
|
-
|
|
293
|
+
<input type="number" step="any" :min="MIN_ELEMENT_DIMENSION"
|
|
294
|
+
:value="focusedField === 'W' ? draftText : elementW"
|
|
295
|
+
@focus="onFieldFocus('W')"
|
|
296
|
+
@input="onFieldInput('W', $event)"
|
|
297
|
+
@blur="onFieldBlur('W', $event)"
|
|
298
|
+
@keydown="onFieldKeyDown('W', $event)"
|
|
139
299
|
class="custom-num-field" />
|
|
140
300
|
</div>
|
|
141
301
|
<div class="custom-num-input" :class="{ 'is-disabled': disableHeight }">
|
|
142
302
|
<span class="custom-num-prefix">H</span>
|
|
143
|
-
<input type="number" step="any" :
|
|
144
|
-
|
|
303
|
+
<input type="number" step="any" :min="MIN_ELEMENT_DIMENSION"
|
|
304
|
+
:value="focusedField === 'H' ? draftText : elementH"
|
|
305
|
+
:disabled="disableHeight" :readonly="disableHeight"
|
|
306
|
+
@focus="!disableHeight && onFieldFocus('H')"
|
|
307
|
+
@input="!disableHeight && onFieldInput('H', $event)"
|
|
308
|
+
@blur="!disableHeight && onFieldBlur('H', $event)"
|
|
309
|
+
@keydown="!disableHeight && onFieldKeyDown('H', $event)"
|
|
145
310
|
class="custom-num-field" />
|
|
146
311
|
</div>
|
|
147
312
|
</div>
|
|
@@ -169,10 +334,11 @@ function onRotateBlur(e: Event) {
|
|
|
169
334
|
ref="rotateInputRef"
|
|
170
335
|
type="text"
|
|
171
336
|
inputmode="numeric"
|
|
172
|
-
:value="elementRotate ?? 0"
|
|
173
|
-
@
|
|
174
|
-
@
|
|
175
|
-
@
|
|
337
|
+
:value="focusedField === 'ROTATE' ? draftText : (elementRotate ?? 0)"
|
|
338
|
+
@focus="onFieldFocus('ROTATE')"
|
|
339
|
+
@input="onFieldInput('ROTATE', $event)"
|
|
340
|
+
@blur="onFieldBlur('ROTATE', $event)"
|
|
341
|
+
@keydown="onFieldKeyDown('ROTATE', $event)"
|
|
176
342
|
class="custom-num-field rotate-num-field"
|
|
177
343
|
:style="{ width: `calc(${rotateDisplayLen}ch + 6px)` }"
|
|
178
344
|
/>
|