feat: Add extension storage (#2069)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { Extension } from '@tiptap/core'
|
||||
|
||||
type CustomStorage = {
|
||||
foo: number,
|
||||
}
|
||||
|
||||
export const CustomExtension = Extension.create<{}, CustomStorage>({
|
||||
name: 'custom',
|
||||
|
||||
addStorage() {
|
||||
return {
|
||||
foo: 123,
|
||||
}
|
||||
},
|
||||
|
||||
onUpdate() {
|
||||
this.storage.foo += 1
|
||||
},
|
||||
})
|
||||
15
demos/src/Experiments/ExtensionStorage/Vue/index.html
Normal file
15
demos/src/Experiments/ExtensionStorage/Vue/index.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module">
|
||||
import setup from '../../../../setup/vue.ts'
|
||||
import source from '@source'
|
||||
setup('Experiments/ExtensionStorage', source)
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
56
demos/src/Experiments/ExtensionStorage/Vue/index.vue
Normal file
56
demos/src/Experiments/ExtensionStorage/Vue/index.vue
Normal file
@@ -0,0 +1,56 @@
|
||||
<template>
|
||||
reactive storage: {{ editor?.storage.custom.foo }}
|
||||
<editor-content :editor="editor" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent } from '@tiptap/vue-3'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import { CustomExtension } from './CustomExtension'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
Document,
|
||||
Paragraph,
|
||||
Text,
|
||||
CustomExtension,
|
||||
],
|
||||
content: `
|
||||
<p>
|
||||
This is a radically reduced version of tiptap. It has support for a document, with paragraphs and text. That’s it. It’s probably too much for real minimalists though.
|
||||
</p>
|
||||
<p>
|
||||
The paragraph extension is not really required, but you need at least one node. Sure, that node can be something different.
|
||||
</p>
|
||||
`,
|
||||
})
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.editor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
/* Basic editor styles */
|
||||
.ProseMirror {
|
||||
> * + * {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user