Add new commands

This commit is contained in:
Seviche CC 2023-03-25 15:46:06 +08:00
parent 45c32e307c
commit 83df80eefc
Signed by: SevicheCC
GPG key ID: C577000000000000
2 changed files with 39 additions and 2 deletions

View file

@ -7,7 +7,13 @@ import { onMounted, onUnmounted, ref, watch } from 'vue'
import type { VNodeRef } from 'vue' import type { VNodeRef } from 'vue'
import { useCommands } from '../../composables/commands' import { useCommands } from '../../composables/commands'
const { toggleBold, toggleInlineCode, toggleItalic } = useCommands() const {
toggleBold,
toggleInlineCode,
toggleItalic,
wrapInBlockQuote,
toggleStrikeThrough,
} = useCommands()
const { view, prevState } = usePluginViewContext() const { view, prevState } = usePluginViewContext()
const divRef = ref<VNodeRef>() const divRef = ref<VNodeRef>()
@ -51,5 +57,17 @@ onUnmounted(() => {
> >
Italic Italic
</button> </button>
<button
class="text-gray-600 bg-slate-200 px-2 py-1 rounded-lg hover:bg-slate-300 border hover:text-gray-900"
@click="wrapInBlockQuote"
>
Quote
</button>
<button
class="text-gray-600 bg-slate-200 px-2 py-1 rounded-lg hover:bg-slate-300 border hover:text-gray-900"
@click="toggleStrikeThrough"
>
StrikeThrough
</button>
</div> </div>
</template> </template>

View file

@ -5,7 +5,9 @@ import {
toggleEmphasisCommand, toggleEmphasisCommand,
toggleInlineCodeCommand, toggleInlineCodeCommand,
toggleStrongCommand, toggleStrongCommand,
wrapInBlockquoteCommand,
} from '@milkdown/preset-commonmark' } from '@milkdown/preset-commonmark'
import { toggleStrikethroughCommand } from '@milkdown/preset-gfm'
import { callCommand } from '@milkdown/utils' import { callCommand } from '@milkdown/utils'
import { editorViewCtx } from '@milkdown/core' import { editorViewCtx } from '@milkdown/core'
@ -29,7 +31,17 @@ export const useCommands = () => {
e.preventDefault() e.preventDefault()
get()!.action(callCommand(toggleEmphasisCommand.key)) get()!.action(callCommand(toggleEmphasisCommand.key))
} }
const toggleStrikeThrough = (e: Event) => {
if (loading.value) return
e.preventDefault()
get()!.action(callCommand(toggleStrikethroughCommand.key))
}
const wrapInBlockQuote = (e: Event) => {
if (loading.value) return
e.preventDefault()
get()!.action(callCommand(wrapInBlockquoteCommand.key))
}
const addCodeBlock = (e: Event) => { const addCodeBlock = (e: Event) => {
if (loading.value) return if (loading.value) return
e.preventDefault() e.preventDefault()
@ -43,5 +55,12 @@ export const useCommands = () => {
}) })
} }
return { toggleBold, addCodeBlock, toggleInlineCode, toggleItalic } return {
toggleBold,
toggleInlineCode,
toggleItalic,
toggleStrikeThrough,
wrapInBlockQuote,
addCodeBlock,
}
} }