How to pass and use custom options, like Headings? #920
Answered
by
bgrand-ch
bgrand-ch
asked this question in
Questions & Help
-
I would like to pass some options via object, like Headings node extension. Test.vue: <template>
<div>
<!-- [...] -->
<editor-menu-bar
class="q-gutter-sm"
:editor="editor"
v-slot="{ commands, isActive }"
>
<q-btn
flat
dense
color="primary"
label="Section col"
:class="{ 'is-active': isActive.section({ flexDirection: 'row' }) }"
@click="commands.section({ flexDirection: 'row' })"
/>
</editor-menu-bar>
<!-- [...] -->
</div>
</template> import { Editor, EditorContent, EditorMenuBar, EditorMenuBubble } from 'tiptap'
import { Heading } from 'tiptap-extensions'
import Section from './extensions/blocks/section'
// [...]
export default {
// [...]
mounted () {
this.editor = new Editor({
autoFocus: true,
extensions: [
new Heading({ levels: [1, 2, 3] }),
new Section({ flexDirections: ['row', 'column'] })
]
})
console.log('mounted() -> this.editor', this.editor)
}
// [...]
} Section.js: import { Node } from 'tiptap'
import { toggleWrap } from 'tiptap-commands'
export default class SectionTag extends Node {
get name () {
return 'section'
}
get defaultOptions () {
return {
flexDirections: ['row', 'column']
}
}
get schema () {
return {
attrs: {
flexDirection: {
default: 'column'
}
},
content: 'block*',
group: 'block',
defining: true,
draggable: false,
parseDOM: [{ tag: 'section' }],
toDOM: node => ['section', {
style: `display: flex; flex-flow: ${node.attrs.flexDirection} wrap; justify-content: space-around;`
}, 0]
}
}
commands ({ type }) {
return () => toggleWrap(type)
}
} No error, but it doesn't work. |
Beta Was this translation helpful? Give feedback.
Answered by
bgrand-ch
Dec 24, 2020
Replies: 1 comment
-
https://gist.github.com/waaronking/0e1712e1c1aea1d73b0cc2cb4129edde |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bgrand-ch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/waaronking/0e1712e1c1aea1d73b0cc2cb4129edde