jvs-ppt-ui 0.0.21 → 0.0.23
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 +18671 -18433
- package/dist/lib/jvs-ppt-ui.umd.js +86 -86
- package/dist/lib/style.css +1 -1
- package/package.json +2 -2
- package/src/components/CanvasArea.vue +25 -1
- package/src/components/PptEditor.vue +10 -2
- package/src/components/SidebarRight.vue +63 -11
- package/src/components/TemplateGallery.vue +23 -21
- package/src/components/material/CreateMaterialPanel.vue +7 -8
- package/src/components/material/MyAssetsPanel.vue +64 -24
- package/src/components/material/VideoCoverThumb.vue +411 -0
- package/src/composables/sidebar/useSidebarMultiSelect.ts +15 -1
- package/src/composables/useSlides.ts +19 -3
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
videoUrl?: string
|
|
6
|
+
coverUrl?: string
|
|
7
|
+
alt?: string
|
|
8
|
+
}>()
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<{
|
|
11
|
+
(e: 'loaded'): void
|
|
12
|
+
}>()
|
|
13
|
+
|
|
14
|
+
// 全局内存级视频首帧快照缓存(同一会话切换 Tab 时 0ms 瞬时渲染,无需重复请求视频流)
|
|
15
|
+
const videoFrameCache = new Map<string, string>()
|
|
16
|
+
|
|
17
|
+
// 全局并发控制器:限制同时解码首帧的 <video> 数量(避免多视频并发占满浏览器同源连接池)
|
|
18
|
+
const MAX_CONCURRENT_EXTRACTIONS = 3
|
|
19
|
+
let activeExtractions = 0
|
|
20
|
+
const waitQueue: Array<() => void> = []
|
|
21
|
+
|
|
22
|
+
function acquireSlot(): Promise<() => void> {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const tryStart = () => {
|
|
25
|
+
activeExtractions++
|
|
26
|
+
let released = false
|
|
27
|
+
const release = () => {
|
|
28
|
+
if (released) return
|
|
29
|
+
released = true
|
|
30
|
+
activeExtractions = Math.max(0, activeExtractions - 1)
|
|
31
|
+
const next = waitQueue.shift()
|
|
32
|
+
if (next) next()
|
|
33
|
+
}
|
|
34
|
+
resolve(release)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (activeExtractions < MAX_CONCURRENT_EXTRACTIONS) {
|
|
38
|
+
tryStart()
|
|
39
|
+
} else {
|
|
40
|
+
waitQueue.push(tryStart)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isVideoFileUrl(url?: string): boolean {
|
|
46
|
+
if (!url) return false
|
|
47
|
+
const clean = url.split('?')[0].split('#')[0].toLowerCase()
|
|
48
|
+
return (
|
|
49
|
+
clean.endsWith('.mp4') ||
|
|
50
|
+
clean.endsWith('.webm') ||
|
|
51
|
+
clean.endsWith('.mov') ||
|
|
52
|
+
clean.endsWith('.m4v') ||
|
|
53
|
+
clean.endsWith('.ogg') ||
|
|
54
|
+
clean.endsWith('.avi') ||
|
|
55
|
+
clean.endsWith('.mkv')
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function buildFirstFrameVideoSrc(url?: string): string {
|
|
60
|
+
if (!url) return ''
|
|
61
|
+
const base = url.split('#')[0]
|
|
62
|
+
return `${base}#t=0.05`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const rootRef = ref<HTMLElement | null>(null)
|
|
66
|
+
const videoElRef = ref<HTMLVideoElement | null>(null)
|
|
67
|
+
|
|
68
|
+
const staticCoverFailed = ref(false)
|
|
69
|
+
const capturedDataUrl = ref<string>('')
|
|
70
|
+
const shouldMountVideo = ref(false)
|
|
71
|
+
const isVideoFrameReady = ref(false)
|
|
72
|
+
const isVideoFailed = ref(false)
|
|
73
|
+
|
|
74
|
+
let observer: IntersectionObserver | null = null
|
|
75
|
+
let releaseCurrentSlot: (() => void) | null = null
|
|
76
|
+
let slotTimeoutTimer: ReturnType<typeof setTimeout> | null = null
|
|
77
|
+
|
|
78
|
+
// 优先使用非视频格式的静态封面图(若有且未加载失败)
|
|
79
|
+
const effectiveStaticCover = computed(() => {
|
|
80
|
+
if (staticCoverFailed.value) return ''
|
|
81
|
+
const c = (props.coverUrl || '').trim()
|
|
82
|
+
if (c && !isVideoFileUrl(c)) return c
|
|
83
|
+
return ''
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// 规范化后的原始视频地址
|
|
87
|
+
const rawVideoUrl = computed(() => {
|
|
88
|
+
const v = (props.videoUrl || '').trim()
|
|
89
|
+
if (v) return v.split('#')[0]
|
|
90
|
+
const c = (props.coverUrl || '').trim()
|
|
91
|
+
if (c && isVideoFileUrl(c)) return c.split('#')[0]
|
|
92
|
+
return ''
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
// 最终可直接用 <img> 极速展示的封面地址(静态封面图 或 已缓存的首帧 Base64)
|
|
96
|
+
const directImgSrc = computed(() => {
|
|
97
|
+
if (effectiveStaticCover.value) return effectiveStaticCover.value
|
|
98
|
+
if (capturedDataUrl.value) return capturedDataUrl.value
|
|
99
|
+
if (rawVideoUrl.value && videoFrameCache.has(rawVideoUrl.value)) {
|
|
100
|
+
return videoFrameCache.get(rawVideoUrl.value) || ''
|
|
101
|
+
}
|
|
102
|
+
return ''
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const videoFirstFrameSrc = computed(() => {
|
|
106
|
+
return buildFirstFrameVideoSrc(rawVideoUrl.value)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
function cleanupSlotAndTimers() {
|
|
110
|
+
if (slotTimeoutTimer) {
|
|
111
|
+
clearTimeout(slotTimeoutTimer)
|
|
112
|
+
slotTimeoutTimer = null
|
|
113
|
+
}
|
|
114
|
+
if (releaseCurrentSlot) {
|
|
115
|
+
releaseCurrentSlot()
|
|
116
|
+
releaseCurrentSlot = null
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function stopAndReleaseVideoElement(video: HTMLVideoElement | null) {
|
|
121
|
+
if (!video) return
|
|
122
|
+
try {
|
|
123
|
+
video.pause()
|
|
124
|
+
video.removeAttribute('src')
|
|
125
|
+
video.load()
|
|
126
|
+
} catch {}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function startFirstFrameExtraction() {
|
|
130
|
+
const targetUrl = rawVideoUrl.value
|
|
131
|
+
if (!targetUrl) {
|
|
132
|
+
isVideoFailed.value = true
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 命中内存缓存则直接渲染 <img>
|
|
137
|
+
const cached = videoFrameCache.get(targetUrl)
|
|
138
|
+
if (cached) {
|
|
139
|
+
capturedDataUrl.value = cached
|
|
140
|
+
emit('loaded')
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (shouldMountVideo.value || isVideoFrameReady.value) return
|
|
145
|
+
|
|
146
|
+
const release = await acquireSlot()
|
|
147
|
+
releaseCurrentSlot = release
|
|
148
|
+
|
|
149
|
+
// 排队期间如果已经被缓存或组件已销毁,直接释放槽位
|
|
150
|
+
if (videoFrameCache.has(targetUrl)) {
|
|
151
|
+
capturedDataUrl.value = videoFrameCache.get(targetUrl) || ''
|
|
152
|
+
cleanupSlotAndTimers()
|
|
153
|
+
emit('loaded')
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
shouldMountVideo.value = true
|
|
158
|
+
|
|
159
|
+
// 单个视频首帧提取最多等待 6 秒,超时立即释放队列槽位避免阻塞后续卡片
|
|
160
|
+
slotTimeoutTimer = setTimeout(() => {
|
|
161
|
+
cleanupSlotAndTimers()
|
|
162
|
+
if (!isVideoFrameReady.value && !capturedDataUrl.value) {
|
|
163
|
+
isVideoFailed.value = true
|
|
164
|
+
}
|
|
165
|
+
}, 6000)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function handleStaticImgLoad() {
|
|
169
|
+
emit('loaded')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function handleStaticImgError() {
|
|
173
|
+
staticCoverFailed.value = true
|
|
174
|
+
// 静态封面失败时自动降级为提取视频第一帧
|
|
175
|
+
if (rawVideoUrl.value) {
|
|
176
|
+
startFirstFrameExtraction()
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function handleVideoLoadedMetadata(e: Event) {
|
|
181
|
+
const video = e.target as HTMLVideoElement | null
|
|
182
|
+
if (!video) return
|
|
183
|
+
try {
|
|
184
|
+
video.pause()
|
|
185
|
+
if (video.currentTime === 0) {
|
|
186
|
+
video.currentTime = 0.05
|
|
187
|
+
}
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function tryCaptureCanvasFrame(video: HTMLVideoElement) {
|
|
192
|
+
if (!video || video.videoWidth <= 0 || video.videoHeight <= 0) return false
|
|
193
|
+
try {
|
|
194
|
+
const maxW = 360
|
|
195
|
+
const scale = Math.min(1, maxW / video.videoWidth)
|
|
196
|
+
const w = Math.max(1, Math.round(video.videoWidth * scale))
|
|
197
|
+
const h = Math.max(1, Math.round(video.videoHeight * scale))
|
|
198
|
+
const canvas = document.createElement('canvas')
|
|
199
|
+
canvas.width = w
|
|
200
|
+
canvas.height = h
|
|
201
|
+
const ctx = canvas.getContext('2d')
|
|
202
|
+
if (!ctx) return false
|
|
203
|
+
ctx.drawImage(video, 0, 0, w, h)
|
|
204
|
+
const dataUrl = canvas.toDataURL('image/jpeg', 0.78)
|
|
205
|
+
if (dataUrl && dataUrl.startsWith('data:image/') && dataUrl.length > 256) {
|
|
206
|
+
if (rawVideoUrl.value) {
|
|
207
|
+
videoFrameCache.set(rawVideoUrl.value, dataUrl)
|
|
208
|
+
}
|
|
209
|
+
capturedDataUrl.value = dataUrl
|
|
210
|
+
// 转为静态 <img> 后立即中止 <video> 网络流与硬件解码器,不再加载后续视频内容
|
|
211
|
+
stopAndReleaseVideoElement(video)
|
|
212
|
+
shouldMountVideo.value = false
|
|
213
|
+
return true
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
// 跨域视频无 CORS 头时 canvas.toDataURL 会抛 SecurityError,此时保留已暂停在 0.05s 首帧的 <video>
|
|
217
|
+
}
|
|
218
|
+
return false
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function finalizeVideoFirstFrame(e: Event) {
|
|
222
|
+
const video = e.target as HTMLVideoElement | null
|
|
223
|
+
if (!video) return
|
|
224
|
+
try {
|
|
225
|
+
video.pause()
|
|
226
|
+
} catch {}
|
|
227
|
+
|
|
228
|
+
const captured = tryCaptureCanvasFrame(video)
|
|
229
|
+
if (!captured) {
|
|
230
|
+
isVideoFrameReady.value = true
|
|
231
|
+
}
|
|
232
|
+
cleanupSlotAndTimers()
|
|
233
|
+
emit('loaded')
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function handleVideoError() {
|
|
237
|
+
isVideoFailed.value = true
|
|
238
|
+
cleanupSlotAndTimers()
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function setupIntersectionObserver() {
|
|
242
|
+
if (observer) {
|
|
243
|
+
observer.disconnect()
|
|
244
|
+
observer = null
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 如果已有可直接渲染的图片封面,无需观察视频流
|
|
248
|
+
if (directImgSrc.value) return
|
|
249
|
+
|
|
250
|
+
if (typeof IntersectionObserver === 'undefined') {
|
|
251
|
+
startFirstFrameExtraction()
|
|
252
|
+
return
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
observer = new IntersectionObserver(
|
|
256
|
+
(entries) => {
|
|
257
|
+
const entry = entries[0]
|
|
258
|
+
if (entry && entry.isIntersecting) {
|
|
259
|
+
if (observer) {
|
|
260
|
+
observer.disconnect()
|
|
261
|
+
observer = null
|
|
262
|
+
}
|
|
263
|
+
startFirstFrameExtraction()
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
rootMargin: '180px 0px'
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
if (rootRef.value) {
|
|
272
|
+
observer.observe(rootRef.value)
|
|
273
|
+
} else {
|
|
274
|
+
startFirstFrameExtraction()
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
watch(
|
|
279
|
+
[() => props.videoUrl, () => props.coverUrl],
|
|
280
|
+
() => {
|
|
281
|
+
staticCoverFailed.value = false
|
|
282
|
+
isVideoFailed.value = false
|
|
283
|
+
isVideoFrameReady.value = false
|
|
284
|
+
shouldMountVideo.value = false
|
|
285
|
+
cleanupSlotAndTimers()
|
|
286
|
+
|
|
287
|
+
const cached = rawVideoUrl.value ? videoFrameCache.get(rawVideoUrl.value) : ''
|
|
288
|
+
capturedDataUrl.value = cached || ''
|
|
289
|
+
|
|
290
|
+
if (!directImgSrc.value && rawVideoUrl.value) {
|
|
291
|
+
setupIntersectionObserver()
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
onMounted(() => {
|
|
297
|
+
if (!directImgSrc.value && rawVideoUrl.value) {
|
|
298
|
+
setupIntersectionObserver()
|
|
299
|
+
}
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
onUnmounted(() => {
|
|
303
|
+
if (observer) {
|
|
304
|
+
observer.disconnect()
|
|
305
|
+
observer = null
|
|
306
|
+
}
|
|
307
|
+
cleanupSlotAndTimers()
|
|
308
|
+
stopAndReleaseVideoElement(videoElRef.value)
|
|
309
|
+
})
|
|
310
|
+
</script>
|
|
311
|
+
|
|
312
|
+
<template>
|
|
313
|
+
<div ref="rootRef" class="video-cover-thumb">
|
|
314
|
+
<!-- 1. 优先展示静态封面图或已截取的首帧快照 <img>(极速渲染,0 视频流开销) -->
|
|
315
|
+
<img
|
|
316
|
+
v-if="directImgSrc"
|
|
317
|
+
:src="directImgSrc"
|
|
318
|
+
:alt="alt || '视频封面'"
|
|
319
|
+
loading="lazy"
|
|
320
|
+
class="video-cover-img"
|
|
321
|
+
@load="handleStaticImgLoad"
|
|
322
|
+
@error="handleStaticImgError"
|
|
323
|
+
/>
|
|
324
|
+
|
|
325
|
+
<!-- 2. 无静态封面时:按需拉取视频 #t=0.05 第一帧并立即暂停截帧 -->
|
|
326
|
+
<template v-else>
|
|
327
|
+
<video
|
|
328
|
+
v-if="shouldMountVideo && videoFirstFrameSrc && !isVideoFailed"
|
|
329
|
+
ref="videoElRef"
|
|
330
|
+
:src="videoFirstFrameSrc"
|
|
331
|
+
muted
|
|
332
|
+
playsinline
|
|
333
|
+
preload="metadata"
|
|
334
|
+
class="video-cover-el"
|
|
335
|
+
:class="{ 'is-ready': isVideoFrameReady }"
|
|
336
|
+
@loadedmetadata="handleVideoLoadedMetadata"
|
|
337
|
+
@loadeddata="finalizeVideoFirstFrame"
|
|
338
|
+
@seeked="finalizeVideoFirstFrame"
|
|
339
|
+
@error="handleVideoError"
|
|
340
|
+
/>
|
|
341
|
+
|
|
342
|
+
<!-- 首帧解码中或兜底占位骨架(保证卡片高度稳定、不出现空白) -->
|
|
343
|
+
<div
|
|
344
|
+
v-if="!isVideoFrameReady"
|
|
345
|
+
class="video-cover-placeholder"
|
|
346
|
+
:class="{ 'is-loading': !isVideoFailed }"
|
|
347
|
+
>
|
|
348
|
+
<svg viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="1.6">
|
|
349
|
+
<rect x="2" y="4" width="20" height="16" rx="3" />
|
|
350
|
+
<polygon points="10 9 15 12 10 15 10 9" fill="currentColor" stroke="none" />
|
|
351
|
+
</svg>
|
|
352
|
+
</div>
|
|
353
|
+
</template>
|
|
354
|
+
</div>
|
|
355
|
+
</template>
|
|
356
|
+
|
|
357
|
+
<style scoped lang="scss">
|
|
358
|
+
.video-cover-thumb {
|
|
359
|
+
position: relative;
|
|
360
|
+
width: 100%;
|
|
361
|
+
height: 100%;
|
|
362
|
+
min-height: 96px;
|
|
363
|
+
background: #1e293b;
|
|
364
|
+
overflow: hidden;
|
|
365
|
+
display: block;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.video-cover-img,
|
|
369
|
+
.video-cover-el {
|
|
370
|
+
width: 100%;
|
|
371
|
+
height: 100%;
|
|
372
|
+
display: block;
|
|
373
|
+
object-fit: cover;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
.video-cover-el {
|
|
377
|
+
opacity: 0;
|
|
378
|
+
transition: opacity 0.18s ease;
|
|
379
|
+
pointer-events: none;
|
|
380
|
+
|
|
381
|
+
&.is-ready {
|
|
382
|
+
opacity: 1;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
.video-cover-placeholder {
|
|
387
|
+
width: 100%;
|
|
388
|
+
min-height: 104px;
|
|
389
|
+
height: 100%;
|
|
390
|
+
display: flex;
|
|
391
|
+
align-items: center;
|
|
392
|
+
justify-content: center;
|
|
393
|
+
color: rgba(255, 255, 255, 0.45);
|
|
394
|
+
background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
|
|
395
|
+
|
|
396
|
+
&.is-loading {
|
|
397
|
+
background: linear-gradient(110deg, #1e293b 25%, #334155 50%, #1e293b 75%);
|
|
398
|
+
background-size: 200% 100%;
|
|
399
|
+
animation: coverShimmer 1.4s infinite linear;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
@keyframes coverShimmer {
|
|
404
|
+
0% {
|
|
405
|
+
background-position: 200% 0;
|
|
406
|
+
}
|
|
407
|
+
100% {
|
|
408
|
+
background-position: -200% 0;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
</style>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computed, type Ref, type ComputedRef } from 'vue'
|
|
2
|
+
import { updateTextAlignInHtml } from '../../utils/canvas/elementStyles'
|
|
2
3
|
|
|
3
4
|
export function toggleTextDecorationValue(current: string | undefined, decorator: 'underline' | 'line-through'): string {
|
|
4
5
|
if (!current || current === 'none') {
|
|
@@ -319,10 +320,23 @@ export function useSidebarMultiSelect(
|
|
|
319
320
|
function setMultiAlignment(align: string) {
|
|
320
321
|
if (!activeSlide.value) return
|
|
321
322
|
activeSlide.value.elements.forEach((el: any) => {
|
|
322
|
-
if (selectedElementIds.value.includes(el.id) && el.type === 'text') {
|
|
323
|
+
if (selectedElementIds.value.includes(el.id) && (el.type === 'text' || el.type === 'shape')) {
|
|
323
324
|
if (el.style) {
|
|
324
325
|
el.style.textAlign = align
|
|
325
326
|
}
|
|
327
|
+
if (el.type === 'text' && el.content) {
|
|
328
|
+
el.content = updateTextAlignInHtml(el.content, align)
|
|
329
|
+
}
|
|
330
|
+
if (el.text && el.text.content) {
|
|
331
|
+
el.text.content = updateTextAlignInHtml(el.text.content, align)
|
|
332
|
+
} else if (typeof el.text === 'string' && el.text) {
|
|
333
|
+
el.text = updateTextAlignInHtml(el.text, align)
|
|
334
|
+
}
|
|
335
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
336
|
+
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
337
|
+
container.style.textAlign = align
|
|
338
|
+
container.innerHTML = updateTextAlignInHtml(container.innerHTML, align)
|
|
339
|
+
}
|
|
326
340
|
}
|
|
327
341
|
})
|
|
328
342
|
addHistorySnapshot()
|
|
@@ -2562,7 +2562,11 @@ watch(selectedElementId, (newId) => {
|
|
|
2562
2562
|
setPlaceholderMaterialTargetId(null)
|
|
2563
2563
|
return
|
|
2564
2564
|
}
|
|
2565
|
-
|
|
2565
|
+
const isMaterialPanelOpen =
|
|
2566
|
+
activeTab.value === 'material' ||
|
|
2567
|
+
(activeTab.value as any) === 'library' ||
|
|
2568
|
+
Boolean(materialPopoverVisible.value)
|
|
2569
|
+
if (!newId && !isMaterialPanelOpen && activeSlide.value) {
|
|
2566
2570
|
const el = findPlaceholderElementRecursive(activeSlide.value.elements, targetId)
|
|
2567
2571
|
if (el && (el.isPlaceholderReplaced || el.replaced)) {
|
|
2568
2572
|
setPlaceholderMaterialTargetId(null)
|
|
@@ -2603,6 +2607,12 @@ function isElementUnreplacedImagePlaceholder(el: any): boolean {
|
|
|
2603
2607
|
return false
|
|
2604
2608
|
}
|
|
2605
2609
|
|
|
2610
|
+
function isElementReplacableImagePlaceholder(el: any): boolean {
|
|
2611
|
+
if (!el) return false
|
|
2612
|
+
if (el.isPlaceholderReplaced || el.replaced || el.fromImagePlaceholder) return true
|
|
2613
|
+
return isElementUnreplacedImagePlaceholder(el)
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2606
2616
|
function resolveActivePlaceholderTargetId(): string | null {
|
|
2607
2617
|
const explicitTargetId = getPlaceholderMaterialTargetId()
|
|
2608
2618
|
const curSelectedId = selectedElementId.value
|
|
@@ -2613,7 +2623,7 @@ function resolveActivePlaceholderTargetId(): string | null {
|
|
|
2613
2623
|
if (explicitTargetId && (!curSelectedId || curSelectedId === explicitTargetId)) {
|
|
2614
2624
|
return explicitTargetId
|
|
2615
2625
|
}
|
|
2616
|
-
if (curSelectedEl &&
|
|
2626
|
+
if (curSelectedEl && isElementReplacableImagePlaceholder(curSelectedEl)) {
|
|
2617
2627
|
return curSelectedEl.id
|
|
2618
2628
|
}
|
|
2619
2629
|
return null
|
|
@@ -2648,6 +2658,7 @@ function replacePlaceholderElement(
|
|
|
2648
2658
|
;(el as any).src = url
|
|
2649
2659
|
el.isPlaceholderReplaced = true
|
|
2650
2660
|
;(el as any).replaced = true
|
|
2661
|
+
;(el as any).fromImagePlaceholder = true
|
|
2651
2662
|
delete el.isPlaceholder
|
|
2652
2663
|
delete el.placeholder
|
|
2653
2664
|
delete el.placeholderType
|
|
@@ -3044,7 +3055,12 @@ function syncActiveEditingTextToElement() {
|
|
|
3044
3055
|
curSlide.elements.forEach((el: any) => {
|
|
3045
3056
|
if (el && (el.type === 'text' || el.type === 'shape')) {
|
|
3046
3057
|
const container = document.getElementById(`editable-${el.id}`)
|
|
3047
|
-
|
|
3058
|
+
const isEditingContainer = Boolean(
|
|
3059
|
+
container &&
|
|
3060
|
+
(container.getAttribute('contenteditable') === 'true' ||
|
|
3061
|
+
(document.activeElement && container.contains(document.activeElement)))
|
|
3062
|
+
)
|
|
3063
|
+
if (container && isEditingContainer && (!el.content || !el.content.includes('<table'))) {
|
|
3048
3064
|
const htmlVal = container.innerHTML
|
|
3049
3065
|
if (el.type === 'shape') {
|
|
3050
3066
|
// 空 DOM 抓到 '' 时不能给无文本 shape 制造 text:"" 新键:
|