2024-06-25 15:48:20 +02:00
|
|
|
<template>
|
|
|
|
|
<UButtonGroup
|
|
|
|
|
size="sm"
|
|
|
|
|
orientation="horizontal"
|
|
|
|
|
>
|
2024-07-02 15:15:59 +02:00
|
|
|
<UTooltip text="Undo" :shortcuts="undoShortcut" :popper="{ placement: 'left' }">
|
|
|
|
|
<UButton
|
|
|
|
|
:disabled="!canUndo"
|
|
|
|
|
color="white"
|
|
|
|
|
icon="i-material-symbols-undo"
|
|
|
|
|
class="disabled:text-gray-500"
|
|
|
|
|
@click="undo"
|
|
|
|
|
/>
|
|
|
|
|
</UTooltip>
|
|
|
|
|
<UTooltip text="Redo" :shortcuts="redoShortcut" :popper="{ placement: 'right' }">
|
|
|
|
|
<UButton
|
|
|
|
|
:disabled="!canRedo"
|
|
|
|
|
icon="i-material-symbols-redo"
|
|
|
|
|
color="white"
|
|
|
|
|
class="disabled:text-gray-500"
|
|
|
|
|
@click="redo"
|
|
|
|
|
/>
|
|
|
|
|
</UTooltip>
|
2024-06-25 15:48:20 +02:00
|
|
|
</UButtonGroup>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
const workingFormStore = useWorkingFormStore()
|
|
|
|
|
|
|
|
|
|
const { undo, redo, clearHistory } = workingFormStore
|
|
|
|
|
const { canUndo, canRedo } = storeToRefs(workingFormStore)
|
|
|
|
|
|
2024-07-02 15:15:59 +02:00
|
|
|
defineShortcuts({
|
|
|
|
|
meta_z: {
|
|
|
|
|
whenever: [canUndo],
|
|
|
|
|
handler: () => {
|
|
|
|
|
undo()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
meta_shift_z: {
|
|
|
|
|
whenever: [canRedo],
|
|
|
|
|
handler: () => {
|
|
|
|
|
redo()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const undoShortcut = computed(() => {
|
|
|
|
|
return getOS() == 'macOS' ? ['⌘', 'Z'] : ['Ctrl', 'Z']
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const redoShortcut = computed(() => {
|
|
|
|
|
return getOS() == 'macOS' ? ['⌘', 'Shift', 'Z'] : ['Ctrl', 'Shift', 'Z']
|
|
|
|
|
})
|
|
|
|
|
|
2024-06-25 15:48:20 +02:00
|
|
|
onMounted(() => {
|
|
|
|
|
setTimeout(() => { clearHistory() }, 500)
|
|
|
|
|
})
|
2024-07-02 15:15:59 +02:00
|
|
|
|
|
|
|
|
const getOS = ()=> {
|
|
|
|
|
if (navigator.userAgentData) {
|
|
|
|
|
// Modern method
|
|
|
|
|
return navigator.userAgentData.platform;
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback for older browsers
|
|
|
|
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
|
|
|
if (userAgent.indexOf("mac") > -1) return "macOS";
|
|
|
|
|
if (userAgent.indexOf("win") > -1) return "Windows";
|
|
|
|
|
if (userAgent.indexOf("linux") > -1) return "Linux";
|
|
|
|
|
return "Unknown";
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-25 15:48:20 +02:00
|
|
|
</script>
|