mirror of
https://codeberg.org/Sevichecc/Seigwai.git
synced 2025-04-30 07:49:30 +08:00
Refactor utils
This commit is contained in:
parent
3544b30b60
commit
c2a47f7159
3 changed files with 40 additions and 41 deletions
|
@ -1,20 +1,15 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { editorViewCtx } from '@milkdown/core'
|
|
||||||
import { SlashProvider } from '@milkdown/plugin-slash'
|
import { SlashProvider } from '@milkdown/plugin-slash'
|
||||||
import { createCodeBlockCommand } from '@milkdown/preset-commonmark'
|
|
||||||
import { callCommand } from '@milkdown/utils'
|
|
||||||
import { useInstance } from '@milkdown/vue'
|
|
||||||
import { usePluginViewContext } from '@prosemirror-adapter/vue'
|
|
||||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
|
import { usePluginViewContext } from '@prosemirror-adapter/vue'
|
||||||
import type { VNodeRef } from 'vue'
|
import type { VNodeRef } from 'vue'
|
||||||
const { view, prevState } = usePluginViewContext()
|
import { addCodeBlock } from '../../utils/utils'
|
||||||
const [loading, get] = useInstance()
|
|
||||||
|
|
||||||
const divRef = ref<VNodeRef>()
|
|
||||||
|
|
||||||
let tooltipProvider: SlashProvider
|
let tooltipProvider: SlashProvider
|
||||||
|
|
||||||
|
const { view, prevState } = usePluginViewContext()
|
||||||
|
const divRef = ref<VNodeRef>()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
tooltipProvider = new SlashProvider({
|
tooltipProvider = new SlashProvider({
|
||||||
content: divRef.value as any,
|
content: divRef.value as any,
|
||||||
|
@ -30,21 +25,6 @@ watch([view, prevState], () => {
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
tooltipProvider.destroy()
|
tooltipProvider.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { TooltipProvider } from '@milkdown/plugin-tooltip'
|
import { TooltipProvider } from '@milkdown/plugin-tooltip'
|
||||||
import { toggleStrongCommand } from '@milkdown/preset-commonmark'
|
|
||||||
import { callCommand } from '@milkdown/utils'
|
|
||||||
import { useInstance } from '@milkdown/vue'
|
|
||||||
import { usePluginViewContext } from '@prosemirror-adapter/vue'
|
|
||||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
|
import { usePluginViewContext } from '@prosemirror-adapter/vue'
|
||||||
import type { VNodeRef } from 'vue'
|
import type { VNodeRef } from 'vue'
|
||||||
|
import { toggleBold } from '../../utils/utils'
|
||||||
const { view, prevState } = usePluginViewContext()
|
|
||||||
const [loading, get] = useInstance()
|
|
||||||
|
|
||||||
const divRef = ref<VNodeRef>()
|
|
||||||
|
|
||||||
let tooltipProvider: TooltipProvider
|
let tooltipProvider: TooltipProvider
|
||||||
|
|
||||||
|
const { view, prevState } = usePluginViewContext()
|
||||||
|
const divRef = ref<VNodeRef>()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
tooltipProvider = new TooltipProvider({
|
tooltipProvider = new TooltipProvider({
|
||||||
content: divRef.value as any,
|
content: divRef.value as any,
|
||||||
|
@ -30,12 +25,6 @@ watch([view, prevState], () => {
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
tooltipProvider.destroy()
|
tooltipProvider.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
const toggleBold = (e: Event) => {
|
|
||||||
if (loading.value) return
|
|
||||||
e.preventDefault()
|
|
||||||
get()!.action(callCommand(toggleStrongCommand.key))
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* 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'
|
||||||
|
|
||||||
|
const [loading, get] = useInstance()
|
||||||
|
|
||||||
|
export 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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const toggleBold = (e: Event) => {
|
||||||
|
if (loading.value) return
|
||||||
|
e.preventDefault()
|
||||||
|
get()!.action(callCommand(toggleStrongCommand.key))
|
||||||
|
}
|
Loading…
Reference in a new issue