|
import { storeToRefs } from 'pinia' |
|
import { useMainStore } from '@/store' |
|
import { copyText, readClipboard } from '@/utils/clipboard' |
|
import { encrypt } from '@/utils/crypto' |
|
import message from '@/utils/message' |
|
import usePasteTextClipboardData from '@/hooks/usePasteTextClipboardData' |
|
import useDeleteElement from './useDeleteElement' |
|
|
|
export default () => { |
|
const mainStore = useMainStore() |
|
const { activeElementIdList, activeElementList } = storeToRefs(mainStore) |
|
|
|
const { pasteTextClipboardData } = usePasteTextClipboardData() |
|
const { deleteElement } = useDeleteElement() |
|
|
|
|
|
const copyElement = () => { |
|
if (!activeElementIdList.value.length) return |
|
|
|
const text = encrypt(JSON.stringify({ |
|
type: 'elements', |
|
data: activeElementList.value, |
|
})) |
|
|
|
copyText(text).then(() => { |
|
mainStore.setEditorareaFocus(true) |
|
}) |
|
} |
|
|
|
|
|
const cutElement = () => { |
|
copyElement() |
|
deleteElement() |
|
} |
|
|
|
|
|
const pasteElement = () => { |
|
readClipboard().then(text => { |
|
pasteTextClipboardData(text) |
|
}).catch(err => message.warning(err)) |
|
} |
|
|
|
|
|
const quickCopyElement = () => { |
|
copyElement() |
|
pasteElement() |
|
} |
|
|
|
return { |
|
copyElement, |
|
cutElement, |
|
pasteElement, |
|
quickCopyElement, |
|
} |
|
} |