debian-mirror-gitlab/app/assets/javascripts/content_editor/extensions/details.js

36 lines
899 B
JavaScript
Raw Normal View History

2021-12-11 22:18:48 +05:30
import { Node, wrappingInputRule } from '@tiptap/core';
2021-11-18 22:05:49 +05:30
import { VueNodeViewRenderer } from '@tiptap/vue-2';
import DetailsWrapper from '../components/wrappers/details.vue';
export default Node.create({
name: 'details',
content: 'detailsContent+',
// eslint-disable-next-line @gitlab/require-i18n-strings
group: 'block list',
parseHTML() {
return [{ tag: 'details' }];
},
renderHTML({ HTMLAttributes }) {
return ['ul', HTMLAttributes, 0];
},
addNodeView() {
return VueNodeViewRenderer(DetailsWrapper);
},
addInputRules() {
2021-12-11 22:18:48 +05:30
const inputRegex = /^\s*(<details>)$/;
return [wrappingInputRule({ find: inputRegex, type: this.type })];
2021-11-18 22:05:49 +05:30
},
addCommands() {
return {
setDetails: () => ({ commands }) => commands.wrapInList('details'),
toggleDetails: () => ({ commands }) => commands.toggleList('details', 'detailsContent'),
};
},
});