mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
feat: 粘贴超链接、图片链接
This commit is contained in:
parent
237f2442e8
commit
4d9471e582
@ -1,6 +1,9 @@
|
|||||||
|
import { storeToRefs } from 'pinia'
|
||||||
|
import { useKeyboardStore } from '@/store'
|
||||||
import { pasteCustomClipboardString } from '@/utils/clipboard'
|
import { pasteCustomClipboardString } from '@/utils/clipboard'
|
||||||
import { parseText2Paragraphs } from '@/utils/textParser'
|
import { parseText2Paragraphs } from '@/utils/textParser'
|
||||||
import { getImageDataURL, isSVGString, svg2File } from '@/utils/image'
|
import { getImageDataURL, isSVGString, svg2File } from '@/utils/image'
|
||||||
|
import { isValidImgURL, isValidURL } from '@/utils/common'
|
||||||
import useCreateElement from '@/hooks/useCreateElement'
|
import useCreateElement from '@/hooks/useCreateElement'
|
||||||
import useAddSlidesOrElements from '@/hooks/useAddSlidesOrElements'
|
import useAddSlidesOrElements from '@/hooks/useAddSlidesOrElements'
|
||||||
|
|
||||||
@ -10,6 +13,8 @@ interface PasteTextClipboardDataOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
const { shiftKeyState } = storeToRefs(useKeyboardStore())
|
||||||
|
|
||||||
const { createTextElement, createImageElement } = useCreateElement()
|
const { createTextElement, createImageElement } = useCreateElement()
|
||||||
const { addElementsFromData, addSlidesFromData } = useAddSlidesOrElements()
|
const { addElementsFromData, addSlidesFromData } = useAddSlidesOrElements()
|
||||||
|
|
||||||
@ -47,9 +52,22 @@ export default () => {
|
|||||||
|
|
||||||
// 普通文本
|
// 普通文本
|
||||||
else if (!onlyElements && !onlySlide) {
|
else if (!onlyElements && !onlySlide) {
|
||||||
|
// 普通文字
|
||||||
|
if (shiftKeyState.value) {
|
||||||
|
const string = parseText2Paragraphs(clipboardData)
|
||||||
|
createTextElementFromClipboard(string)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 尝试检查是否为图片地址链接
|
||||||
|
if (isValidImgURL(clipboardData)) {
|
||||||
|
createImageElement(clipboardData)
|
||||||
|
}
|
||||||
|
// 尝试检查是否为超链接
|
||||||
|
else if (isValidURL(clipboardData)) {
|
||||||
|
createTextElementFromClipboard(`<a href="${clipboardData}" title="${clipboardData}" target="_blank">${clipboardData}</a>`)
|
||||||
|
}
|
||||||
// 尝试检查是否为SVG代码
|
// 尝试检查是否为SVG代码
|
||||||
const isSVG = isSVGString(clipboardData)
|
else if (isSVGString(clipboardData)) {
|
||||||
if (isSVG) {
|
|
||||||
const file = svg2File(clipboardData)
|
const file = svg2File(clipboardData)
|
||||||
getImageDataURL(file).then(dataURL => createImageElement(dataURL))
|
getImageDataURL(file).then(dataURL => createImageElement(dataURL))
|
||||||
}
|
}
|
||||||
@ -60,6 +78,7 @@ export default () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pasteTextClipboardData,
|
pasteTextClipboardData,
|
||||||
|
@ -15,3 +15,17 @@ export const fillDigit = (digit: number, len: number) => {
|
|||||||
export const isPC = () => {
|
export const isPC = () => {
|
||||||
return !navigator.userAgent.match(/(iPhone|iPod|iPad|Android|Mobile|BlackBerry|Symbian|Windows Phone)/i)
|
return !navigator.userAgent.match(/(iPhone|iPod|iPad|Android|Mobile|BlackBerry|Symbian|Windows Phone)/i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断URL字符串
|
||||||
|
*/
|
||||||
|
export const isValidURL = (url: string) => {
|
||||||
|
return /^(https?:\/\/)([\w-]+\.)+[\w-]{2,}(\/[\w-./?%&=]*)?$/i.test(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断图片URL字符串
|
||||||
|
*/
|
||||||
|
export const isValidImgURL = (url: string) => {
|
||||||
|
return /^(https?:\/\/)([\w-]+\.)+[\w-]{2,}(\/[\w-./?%&=]*)?\.(jpg|jpeg|png|svg|webp)(\?.*)?$/i.test(url)
|
||||||
|
}
|
@ -255,7 +255,7 @@ const toggleNotesPanel = () => {
|
|||||||
|
|
||||||
&.group-btn {
|
&.group-btn {
|
||||||
width: auto;
|
width: auto;
|
||||||
margin-right: 4px;
|
margin-right: 5px;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: #f3f3f3;
|
background-color: #f3f3f3;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user