|
@ -6,7 +6,7 @@ |
|
|
headingStyle: 'atx' |
|
|
headingStyle: 'atx' |
|
|
}); |
|
|
}); |
|
|
turndownService.escape = (string) => string; |
|
|
turndownService.escape = (string) => string; |
|
|
|
|
|
import TextStyle from '@tiptap/extension-text-style'; |
|
|
import { onMount, onDestroy } from 'svelte'; |
|
|
import { onMount, onDestroy } from 'svelte'; |
|
|
import { createEventDispatcher } from 'svelte'; |
|
|
import { createEventDispatcher } from 'svelte'; |
|
|
const eventDispatch = createEventDispatcher(); |
|
|
const eventDispatch = createEventDispatcher(); |
|
@ -24,7 +24,7 @@ |
|
|
import Typography from '@tiptap/extension-typography'; |
|
|
import Typography from '@tiptap/extension-typography'; |
|
|
import StarterKit from '@tiptap/starter-kit'; |
|
|
import StarterKit from '@tiptap/starter-kit'; |
|
|
import { all, createLowlight } from 'lowlight'; |
|
|
import { all, createLowlight } from 'lowlight'; |
|
|
|
|
|
import Color from '@tiptap/extension-color'; |
|
|
import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants'; |
|
|
import { PASTED_TEXT_CHARACTER_LIMIT } from '$lib/constants'; |
|
|
|
|
|
|
|
|
// create a lowlight instance with all languages loaded |
|
|
// create a lowlight instance with all languages loaded |
|
@ -42,10 +42,14 @@ |
|
|
export let messageInput = false; |
|
|
export let messageInput = false; |
|
|
export let shiftEnter = false; |
|
|
export let shiftEnter = false; |
|
|
export let largeTextAsFile = false; |
|
|
export let largeTextAsFile = false; |
|
|
|
|
|
export let autofill = ''; |
|
|
let element; |
|
|
let element; |
|
|
let editor; |
|
|
let editor; |
|
|
|
|
|
$: { |
|
|
|
|
|
if (editor && autofill !== editor.getHTML()) { |
|
|
|
|
|
setContent(autofill); // 更新编辑器内容 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
const options = { |
|
|
const options = { |
|
|
throwOnError: false |
|
|
throwOnError: false |
|
|
}; |
|
|
}; |
|
@ -105,6 +109,7 @@ |
|
|
|
|
|
|
|
|
export const setContent = (content) => { |
|
|
export const setContent = (content) => { |
|
|
editor.commands.setContent(content); |
|
|
editor.commands.setContent(content); |
|
|
|
|
|
editor.commands.focus(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const selectTemplate = () => { |
|
|
const selectTemplate = () => { |
|
@ -163,6 +168,8 @@ |
|
|
element: element, |
|
|
element: element, |
|
|
extensions: [ |
|
|
extensions: [ |
|
|
StarterKit, |
|
|
StarterKit, |
|
|
|
|
|
TextStyle, |
|
|
|
|
|
Color.configure({ types: ['textStyle'] }), |
|
|
CodeBlockLowlight.configure({ |
|
|
CodeBlockLowlight.configure({ |
|
|
lowlight |
|
|
lowlight |
|
|
}), |
|
|
}), |
|
@ -188,12 +195,11 @@ |
|
|
] |
|
|
] |
|
|
: []) |
|
|
: []) |
|
|
], |
|
|
], |
|
|
content: content,// |
|
|
content: content, // |
|
|
|
|
|
editable: true, |
|
|
autofocus: messageInput ? true : false, |
|
|
autofocus: messageInput ? true : false, |
|
|
onTransaction: () => { |
|
|
onTransaction: () => { |
|
|
// force re-render so `editor.isActive` works as expected |
|
|
// force re-render so `editor.isActive` works as expected |
|
|
editor = editor; |
|
|
|
|
|
|
|
|
|
|
|
if (!raw) { |
|
|
if (!raw) { |
|
|
let newValue = turndownService |
|
|
let newValue = turndownService |
|
|
.turndown( |
|
|
.turndown( |
|
@ -332,7 +338,6 @@ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (messageInput) { |
|
|
if (messageInput) { |
|
|
selectTemplate(); |
|
|
selectTemplate(); |
|
|
} |
|
|
} |
|
@ -375,4 +380,4 @@ |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<div bind:this={element} class="relative w-full min-w-full h-full min-h-fit {className}" /> |
|
|
<div bind:this={element} class="relative ccccc min-w-full h-full min-h-fit {className}" /> |
|
|