extensions.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import type { Extensions } from '@tiptap/vue-3';
  2. import type { VbenTiptapExtensionOptions } from './types';
  3. import { $t } from '@vben/locales';
  4. import Document from '@tiptap/extension-document';
  5. import Highlight from '@tiptap/extension-highlight';
  6. import Image from '@tiptap/extension-image';
  7. import Link from '@tiptap/extension-link';
  8. import Placeholder from '@tiptap/extension-placeholder';
  9. import TextAlign from '@tiptap/extension-text-align';
  10. import { Color, TextStyle } from '@tiptap/extension-text-style';
  11. import Underline from '@tiptap/extension-underline';
  12. import StarterKit from '@tiptap/starter-kit';
  13. export function createDefaultTiptapExtensions(
  14. options: VbenTiptapExtensionOptions = {},
  15. ): Extensions {
  16. return [
  17. Document,
  18. StarterKit.configure({
  19. heading: {
  20. levels: [1, 2, 3, 4],
  21. },
  22. }),
  23. Underline,
  24. TextAlign.configure({
  25. types: ['heading', 'paragraph'],
  26. }),
  27. TextStyle,
  28. Color.configure({
  29. types: ['textStyle'],
  30. }),
  31. Highlight.configure({
  32. multicolor: true,
  33. }),
  34. Link.configure({
  35. autolink: true,
  36. defaultProtocol: 'https',
  37. enableClickSelection: true,
  38. openOnClick: false,
  39. protocols: ['mailto', { optionalSlashes: true, scheme: 'tel' }],
  40. }),
  41. Image.configure({
  42. allowBase64: true,
  43. HTMLAttributes: {
  44. class: 'vben-tiptap__image',
  45. },
  46. }),
  47. Placeholder.configure({
  48. placeholder: options.placeholder ?? $t('ui.tiptap.placeholder'),
  49. }),
  50. ];
  51. }