diff --git a/src/components/Milkdown/Slash.vue b/src/components/Milkdown/Slash.vue
index 9b890a1..b566ad5 100644
--- a/src/components/Milkdown/Slash.vue
+++ b/src/components/Milkdown/Slash.vue
@@ -3,7 +3,7 @@ import { SlashProvider } from '@milkdown/plugin-slash'
import { onMounted, onUnmounted, ref, watch } from 'vue'
import { usePluginViewContext } from '@prosemirror-adapter/vue'
import type { VNodeRef } from 'vue'
-import { addCodeBlock } from '../../utils/utils'
+import { useAddCodeBlock, useToggleBold } from '../../composables/quickCommands'
let tooltipProvider: SlashProvider
@@ -25,6 +25,9 @@ watch([view, prevState], () => {
onUnmounted(() => {
tooltipProvider.destroy()
})
+
+const { addCodeBlock } = useAddCodeBlock()
+const { toggleBold } = useToggleBold()
@@ -35,5 +38,11 @@ onUnmounted(() => {
>
Code Block
+
diff --git a/src/components/Milkdown/Tooltip.vue b/src/components/Milkdown/Tooltip.vue
index fbe0d17..4b5eae3 100644
--- a/src/components/Milkdown/Tooltip.vue
+++ b/src/components/Milkdown/Tooltip.vue
@@ -1,15 +1,17 @@
+
diff --git a/src/composables/quickCommands.ts b/src/composables/quickCommands.ts
new file mode 100644
index 0000000..f5d8afa
--- /dev/null
+++ b/src/composables/quickCommands.ts
@@ -0,0 +1,38 @@
+/* eslint-disable antfu/if-newline */
+import { useInstance } from '@milkdown/vue'
+import {
+ createCodeBlockCommand,
+ toggleStrongCommand,
+} from '@milkdown/preset-commonmark'
+import { callCommand } from '@milkdown/utils'
+import { editorViewCtx } from '@milkdown/core'
+
+export const useToggleBold = () => {
+ const [loading, get] = useInstance()
+
+ const toggleBold = (e: Event) => {
+ if (loading.value) return
+ e.preventDefault()
+ get()!.action(callCommand(toggleStrongCommand.key))
+ }
+
+ return { toggleBold }
+}
+
+export const useAddCodeBlock = () => {
+ const [loading, get] = useInstance()
+
+ const addCodeBlock = (e: Event) => {
+ if (loading.value) return
+ e.preventDefault()
+ get()!.action((ctx) => {
+ const view = ctx.get(editorViewCtx)
+ const { dispatch, state } = view
+ const { tr, selection } = state
+ const { from } = selection
+ dispatch(tr.deleteRange(from - 1, from))
+ return callCommand(createCodeBlockCommand.key)(ctx)
+ })
+ }
+ return { addCodeBlock }
+}
diff --git a/src/utils/types.ts b/src/utils/types.ts
deleted file mode 100644
index e69de29..0000000
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
deleted file mode 100644
index 0c806d7..0000000
--- a/src/utils/utils.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-/* eslint-disable antfu/if-newline */
-import { useInstance } from '@milkdown/vue'
-import { editorViewCtx } from '@milkdown/core'
-import { callCommand } from '@milkdown/utils'
-import {
- createCodeBlockCommand,
- toggleStrongCommand,
-} from '@milkdown/preset-commonmark'
-
-export const addCodeBlock = (e: Event) => {
- const [loading, get] = useInstance()
- if (loading.value) return
- e.preventDefault()
-
- get()!.action((ctx) => {
- const view = ctx.get(editorViewCtx)
- const { dispatch, state } = view
- const { tr, selection } = state
- const { from } = selection
- dispatch(tr.deleteRange(from - 1, from))
- return callCommand(createCodeBlockCommand.key)(ctx)
- })
-}
-
-export const toggleBold = (e: Event) => {
- const [loading, get] = useInstance()
- if (loading.value) return
- e.preventDefault()
-
- get()!.action(callCommand(toggleStrongCommand.key))
-}