changed to TipTap
This commit is contained in:
@@ -1,96 +1,48 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="editor">
|
<div class="editor">
|
||||||
<MdEditor
|
<EditorContent
|
||||||
:preview="false"
|
:editor="editor" />
|
||||||
language="en-US"
|
|
||||||
v-model="markdown"
|
|
||||||
@change="handleChange" />
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from "vue";
|
import { computed, onBeforeUnmount, watch } from "vue";
|
||||||
import { api } from "../helpers/api";
|
import { useEditor, EditorContent } from "@tiptap/vue-3";
|
||||||
import { MediaCollection, MediaResponse } from "../helpers/api.types";
|
import StarterKit from "@tiptap/starter-kit";
|
||||||
import { routes } from "../router";
|
|
||||||
import { urlMatches } from "../helpers/url";
|
|
||||||
import { mediaGetVariantUrl } from "../helpers/media";
|
|
||||||
|
|
||||||
interface PageList {
|
|
||||||
title: string;
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
import { MdEditor } from "md-editor-v3";
|
|
||||||
import "md-editor-v3/lib/style.css";
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
}
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emits = defineEmits(["input", "update:modelValue", "blur", "focus"]);
|
const emits = defineEmits(["update:modelValue"]);
|
||||||
|
|
||||||
const markdown = ref(props.modelValue);
|
const editor = useEditor({
|
||||||
let timeout = null;
|
content: props.modelValue,
|
||||||
|
extensions: [
|
||||||
const handleChange = (newValue) => {
|
StarterKit,
|
||||||
if (timeout != null) {
|
],
|
||||||
clearTimeout(timeout);
|
onUpdate: () => {
|
||||||
|
emits("update:modelValue", editor.value.getHTML());
|
||||||
}
|
}
|
||||||
timeout = setTimeout(() => {
|
});
|
||||||
timeout = null;
|
|
||||||
emits("update:modelValue", newValue);
|
onBeforeUnmount(() => {
|
||||||
}, 50);
|
editor.value.destroy();
|
||||||
};
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.modelValue,
|
() => props.modelValue,
|
||||||
(newValue) => {
|
(newValue) => {
|
||||||
markdown.value = newValue;
|
const isSame = editor.value.getHTML() === newValue;
|
||||||
|
|
||||||
|
if (isSame) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor.value.commands.setContent(newValue, false);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.md-editor {
|
|
||||||
border-color: rgba(156, 163, 175);
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
|
|
||||||
.md-editor-toolbar-wrapper {
|
|
||||||
height: 2.5rem;
|
|
||||||
border-bottom-color: rgba(156, 163, 175);
|
|
||||||
|
|
||||||
.md-editor-toolbar-item {
|
|
||||||
height: 1.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-editor-icon {
|
|
||||||
height: 1.75rem;
|
|
||||||
width: 1.75rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.cm-editor {
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.md-editor-footer {
|
|
||||||
height: 2.5rem;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
border-top-color: rgba(156, 163, 175);
|
|
||||||
|
|
||||||
.md-editor-checkbox {
|
|
||||||
width: 1rem;
|
|
||||||
height: 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user