update svelte example
This commit is contained in:
@@ -21,32 +21,35 @@ App.svelte
|
|||||||
Editor.svelte
|
Editor.svelte
|
||||||
```html
|
```html
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { onMount } from 'svelte'
|
import { onMount, onDestroy } from 'svelte'
|
||||||
import { Editor } from '@tiptap/core'
|
import { Editor } from '@tiptap/core'
|
||||||
import { defaultExtensions } from '@tiptap/starter-kit'
|
import { defaultExtensions } from '@tiptap/starter-kit'
|
||||||
|
|
||||||
let element
|
let element
|
||||||
let editor
|
let editor
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
editor = new Editor({
|
editor = new Editor({
|
||||||
element: element,
|
element: element,
|
||||||
extensions: defaultExtensions(),
|
extensions: defaultExtensions(),
|
||||||
|
onTransaction: () => {
|
||||||
|
// force re-render so `editor.isActive` works as expected
|
||||||
|
editor = editor
|
||||||
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
onDestroy(() => {
|
||||||
|
editor.destroy()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if editor}
|
{#if editor}
|
||||||
<button on:click={editor.chain().focus().toggleBold().run()} class:error={editor.isActive('bold')}>
|
<button on:click={() => editor.chain().focus().toggleBold().run()} class:active={editor.isActive('bold')}>
|
||||||
bold
|
Bold
|
||||||
</button>
|
</button>
|
||||||
<button on:click={editor.chain().focus().toggleItalic().run()} class:error={editor.isActive('italic')}>
|
<button on:click={() => editor.chain().focus().toggleItalic().run()} class:active={editor.isActive('italic')}>
|
||||||
italic
|
Italic
|
||||||
</button>
|
</button>
|
||||||
<button on:click={editor.chain().focus().toggleStrike().run()} class:error={editor.isActive('strike')}>
|
<button on:click={() => editor.chain().focus().toggleStrike().run()} class:active={editor.isActive('strike')}>
|
||||||
strike
|
Strike
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div bind:this={element} />
|
<div bind:this={element} />
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user