mirror of
https://codeberg.org/Sevichecc/Seigwai.git
synced 2025-06-18 01:09:14 +08:00
Compare commits
No commits in common. "45c32e307cd906119eff3ac96a32a8600704e6ba" and "3544b30b60977280f4ecec39479c251ce7876f86" have entirely different histories.
45c32e307c
...
3544b30b60
8 changed files with 47 additions and 94 deletions
10
src/App.vue
10
src/App.vue
|
@ -1,7 +1,13 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import EditorWrapper from './components/Milkdown/EditroWrapper.vue'
|
import { MilkdownProvider } from '@milkdown/vue'
|
||||||
|
import { ProsemirrorAdapterProvider } from '@prosemirror-adapter/vue'
|
||||||
|
import Milkdown from './components/Milkdown/Editor.vue'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<EditorWrapper />
|
<MilkdownProvider>
|
||||||
|
<ProsemirrorAdapterProvider>
|
||||||
|
<Milkdown />
|
||||||
|
</ProsemirrorAdapterProvider>
|
||||||
|
</MilkdownProvider>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -14,7 +14,6 @@ let tooltipProvider: BlockProvider | undefined
|
||||||
|
|
||||||
watch([loading], () => {
|
watch([loading], () => {
|
||||||
const editor = get()
|
const editor = get()
|
||||||
// eslint-disable-next-line antfu/if-newline
|
|
||||||
if (loading.value || !editor || tooltipProvider) return
|
if (loading.value || !editor || tooltipProvider) return
|
||||||
|
|
||||||
editor.action((ctx) => {
|
editor.action((ctx) => {
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
<script setup lang="ts">
|
|
||||||
import { MilkdownProvider } from '@milkdown/vue'
|
|
||||||
import { ProsemirrorAdapterProvider } from '@prosemirror-adapter/vue'
|
|
||||||
import Editor from './Editor.vue'
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<MilkdownProvider>
|
|
||||||
<ProsemirrorAdapterProvider>
|
|
||||||
<Editor />
|
|
||||||
</ProsemirrorAdapterProvider>
|
|
||||||
</MilkdownProvider>
|
|
||||||
</template>
|
|
|
@ -1,16 +1,20 @@
|
||||||
<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 { onMounted, onUnmounted, ref, watch } from 'vue'
|
import { createCodeBlockCommand } from '@milkdown/preset-commonmark'
|
||||||
|
import { callCommand } from '@milkdown/utils'
|
||||||
|
import { useInstance } from '@milkdown/vue'
|
||||||
import { usePluginViewContext } from '@prosemirror-adapter/vue'
|
import { usePluginViewContext } from '@prosemirror-adapter/vue'
|
||||||
|
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
import type { VNodeRef } from 'vue'
|
import type { VNodeRef } from 'vue'
|
||||||
import { useCommands } from '../../composables/commands'
|
|
||||||
|
|
||||||
const { addCodeBlock, toggleBold } = useCommands()
|
|
||||||
let tooltipProvider: SlashProvider
|
|
||||||
|
|
||||||
const { view, prevState } = usePluginViewContext()
|
const { view, prevState } = usePluginViewContext()
|
||||||
|
const [loading, get] = useInstance()
|
||||||
|
|
||||||
const divRef = ref<VNodeRef>()
|
const divRef = ref<VNodeRef>()
|
||||||
|
|
||||||
|
let tooltipProvider: SlashProvider
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
tooltipProvider = new SlashProvider({
|
tooltipProvider = new SlashProvider({
|
||||||
content: divRef.value as any,
|
content: divRef.value as any,
|
||||||
|
@ -26,21 +30,30 @@ 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>
|
||||||
<div ref="divRef">
|
<div ref="divRef">
|
||||||
<button
|
<button
|
||||||
class="text-gray-600 bg-slate-200 px-2 py-1 rounded-lg hover:bg-slate-300 border hover:text-gray-900"
|
className="text-gray-600 bg-slate-200 px-2 py-1 rounded-lg hover:bg-slate-300 border hover:text-gray-900"
|
||||||
@click="addCodeBlock"
|
@mousedown="addCodeBlock"
|
||||||
>
|
>
|
||||||
Code Block
|
Code Block
|
||||||
</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="toggleBold"
|
|
||||||
>
|
|
||||||
Bold
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,14 +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 { usePluginViewContext } from '@prosemirror-adapter/vue'
|
||||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
import type { VNodeRef } from 'vue'
|
import type { VNodeRef } from 'vue'
|
||||||
import { useCommands } from '../../composables/commands'
|
|
||||||
|
|
||||||
const { toggleBold, toggleInlineCode, toggleItalic } = useCommands()
|
|
||||||
const { view, prevState } = usePluginViewContext()
|
const { view, prevState } = usePluginViewContext()
|
||||||
|
const [loading, get] = useInstance()
|
||||||
|
|
||||||
const divRef = ref<VNodeRef>()
|
const divRef = ref<VNodeRef>()
|
||||||
|
|
||||||
|
@ -29,27 +30,21 @@ 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>
|
||||||
<div ref="divRef">
|
<div ref="divRef">
|
||||||
<button
|
<button
|
||||||
class="text-gray-600 bg-slate-200 px-2 py-1 rounded-lg hover:bg-slate-300 border hover:text-gray-900"
|
className="text-gray-600 bg-slate-200 px-2 py-1 rounded-lg hover:bg-slate-300 border hover:text-gray-900"
|
||||||
@click="toggleBold"
|
@mousedown="toggleBold"
|
||||||
>
|
>
|
||||||
Bold
|
Bold
|
||||||
</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="toggleInlineCode"
|
|
||||||
>
|
|
||||||
Code
|
|
||||||
</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="toggleItalic"
|
|
||||||
>
|
|
||||||
Italic
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
/* eslint-disable antfu/if-newline */
|
|
||||||
import { useInstance } from '@milkdown/vue'
|
|
||||||
import {
|
|
||||||
createCodeBlockCommand,
|
|
||||||
toggleEmphasisCommand,
|
|
||||||
toggleInlineCodeCommand,
|
|
||||||
toggleStrongCommand,
|
|
||||||
} from '@milkdown/preset-commonmark'
|
|
||||||
import { callCommand } from '@milkdown/utils'
|
|
||||||
import { editorViewCtx } from '@milkdown/core'
|
|
||||||
|
|
||||||
export const useCommands = () => {
|
|
||||||
const [loading, get] = useInstance()
|
|
||||||
|
|
||||||
const toggleBold = (e: Event) => {
|
|
||||||
if (loading.value) return
|
|
||||||
e.preventDefault()
|
|
||||||
get()!.action(callCommand(toggleStrongCommand.key))
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleInlineCode = (e: Event) => {
|
|
||||||
if (loading.value) return
|
|
||||||
e.preventDefault()
|
|
||||||
get()!.action(callCommand(toggleInlineCodeCommand.key))
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleItalic = (e: Event) => {
|
|
||||||
if (loading.value) return
|
|
||||||
e.preventDefault()
|
|
||||||
get()!.action(callCommand(toggleEmphasisCommand.key))
|
|
||||||
}
|
|
||||||
|
|
||||||
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 { toggleBold, addCodeBlock, toggleInlineCode, toggleItalic }
|
|
||||||
}
|
|
0
src/utils/types.ts
Normal file
0
src/utils/types.ts
Normal file
0
src/utils/utils.ts
Normal file
0
src/utils/utils.ts
Normal file
Loading…
Reference in a new issue