CodeBlock.vue 869 B

1234567891011121314151617181920212223242526272829303132
  1. <script setup lang="ts">
  2. import VividMenuItem from "../../components/VividMenuItem.vue";
  3. import { PropType } from "vue";
  4. import { CodeBlockLowlightOptions } from "@tiptap/extension-code-block-lowlight";
  5. import { useCodeBlock } from "./code-block";
  6. import { useEditorInstance, injectExtension } from "../utils/common";
  7. const props = defineProps({
  8. options: {
  9. type: Object as PropType<Partial<CodeBlockLowlightOptions>>,
  10. required: false,
  11. },
  12. });
  13. const editorInstance = useEditorInstance();
  14. injectExtension(useCodeBlock(props.options));
  15. </script>
  16. <template>
  17. <div v-if="editorInstance">
  18. <slot>
  19. <vivid-menu-item
  20. icon="code-view"
  21. title="代码块"
  22. :action="() => editorInstance.chain().focus().toggleCodeBlock().run()"
  23. :is-active="() => editorInstance.isActive('hb-code')"
  24. />
  25. </slot>
  26. </div>
  27. </template>
  28. <style scoped></style>