import { Editor, BubbleMenu } from '@tiptap/vue-3'; import { computed, defineComponent, onBeforeUpdate, ref } from 'vue'; import { DefaultComponentProps } from '../_default'; import { BCMSIcon } from '../index'; import { useTranslation } from '../../translations'; const component = defineComponent({ props: { ...DefaultComponentProps, editor: Editor, }, setup(props) { const headings: [1, 2, 3, 4, 5, 6] = [1, 2, 3, 4, 5, 6]; const isTextDropdownActive = ref(false); const inList = ref(false); let mounted = false; const translations = computed(() => { return useTranslation(); }); const filteredHeadings = computed(() => { return headings.filter((e) => { return !props.editor?.isActive('heading', { level: e, }); }); }); onBeforeUpdate(() => { if (props.editor && !mounted) { mounted = true; const editor = props.editor; props.editor.on('selectionUpdate', () => { const olAttrs = editor.getAttributes('orderedList'); const ulAttrs = editor.getAttributes('bulletList'); const liAttrs = editor.getAttributes('listItem'); if ( typeof olAttrs.start !== 'undefined' || typeof ulAttrs.list !== 'undefined' || typeof liAttrs.list !== 'undefined' ) { inList.value = true; } else { inList.value = false; } }); } }); return () => ( <> {props.editor ? ( { if (data.from === data.to) { return false; } const widgetAttrs = props.editor?.getAttributes('widget'); if (widgetAttrs?.widget) { return false; } else { return true; } }} > {!inList.value ? ( ) : ( '' )} {!inList.value ? ( <> ) : ( '' )} {isTextDropdownActive.value && (
(isTextDropdownActive.value = false)} >
{translations.value.page.entry.convertTo}
{!props.editor?.isActive('paragraph') && ( )} {filteredHeadings.value.map((headingLvl) => { return ( ); })}
)}
) : ( '' )} ); }, }); export default component;