Update TipTap to not use a beta version anymore

This commit is contained in:
Ramon Wenger 2023-12-05 15:57:54 +01:00
parent ac88edf67d
commit 93bb7f4473
3 changed files with 1247 additions and 544 deletions

1653
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -51,13 +51,13 @@
"@rollup/plugin-graphql": "^1.1.0",
"@sentry/vite-plugin": "^2.5.0",
"@sentry/vue": "^7.60.1",
"@tiptap/core": "^2.0.0-beta.174",
"@tiptap/extension-bullet-list": "^2.0.0-beta.26",
"@tiptap/extension-document": "^2.0.0-beta.15",
"@tiptap/extension-list-item": "^2.0.0-beta.20",
"@tiptap/extension-paragraph": "^2.0.0-beta.23",
"@tiptap/extension-text": "^2.0.0-beta.15",
"@tiptap/vue-3": "^2.0.0-beta.90",
"@tiptap/core": "^2.1.11",
"@tiptap/extension-bullet-list": "^2.1.11",
"@tiptap/extension-document": "^2.1.11",
"@tiptap/extension-list-item": "^2.1.11",
"@tiptap/extension-paragraph": "^2.1.11",
"@tiptap/extension-text": "^2.1.11",
"@tiptap/vue-3": "^2.1.11",
"@typescript-eslint/eslint-plugin": "^5.10.0",
"@typescript-eslint/parser": "^5.10.0",
"@vitejs/plugin-vue": "^3.0.3",

View File

@ -14,94 +14,58 @@
</div>
</template>
<script lang="ts">
import { PropType, defineComponent } from 'vue';
import { Editor, EditorContent } from '@tiptap/vue-3';
<script lang="ts" setup>
import Document from '@tiptap/extension-document';
import Paragraph from '@tiptap/extension-paragraph';
import Text from '@tiptap/extension-text';
import BulletList from '@tiptap/extension-bullet-list';
import ListItem from '@tiptap/extension-list-item';
import { EditorContent, useEditor } from '@tiptap/vue-3';
import Toggle from '@/components/ui/Toggle.vue';
interface Data {
editor: Editor | undefined;
}
import { computed, watch } from 'vue';
import log from 'loglevel';
interface Value {
text: string;
}
interface Props {
value: Value;
}
export default defineComponent({
props: {
value: {
type: Object as PropType<Value>,
validator: (value: Value) => {
return Object.prototype.hasOwnProperty.call(value, 'text');
},
},
},
const props = defineProps<Props>();
const emits = defineEmits(['input', 'change-text']);
const text = computed(() => props.value.text || '');
components: {
Toggle,
EditorContent,
},
data(): Data {
return {
editor: undefined,
};
},
computed: {
isList(): boolean {
return this.editor?.isActive('bulletList') || false;
},
text(): string {
return this.value?.text || '';
},
},
watch: {
value({ text }: Value) {
const editor = this.editor as Editor; // editor is always initialized on mount, cast it
const isSame = editor.getHTML() === text;
if (isSame) {
return;
}
editor.commands.setContent(text, false);
},
},
mounted() {
this.editor = new Editor({
const editor = useEditor({
editorProps: {
attributes: {
class: 'tip-tap__editor',
},
},
content: this.text,
content: text.value,
extensions: [Document, Paragraph, Text, BulletList, ListItem],
onUpdate: () => {
const text = (this.editor as Editor).getHTML();
this.$emit('input', text);
this.$emit('change-text', text);
},
});
},
beforeUnmount() {
this.editor?.destroy();
},
methods: {
toggleList() {
const editor = this.editor as Editor;
editor.chain().selectAll().toggleBulletList().run();
},
onUpdate: ({ editor }) => {
log.debug('editor:onUpdate');
const text = editor.getHTML();
// emits('input', text);
emits('change-text', text);
},
});
watch(text, (newText: string, _oldText: string) => {
const isSame = editor.value?.getHTML() === newText;
if (isSame) {
return;
}
editor.value?.commands.setContent(newText, false);
});
const isList = computed(() => editor.value?.isActive('bulletList') || false);
const toggleList = () => {
console.log('toggleList');
editor.value?.chain().selectAll().toggleBulletList().run();
};
</script>
<style scoped lang="scss">