Skip to content

The open alternative to Salesforce, designed for AI.

1.3 KB
Raw Blame
/* oxlint-disable twenty/no-hardcoded-colors --
   default styles are literal inline CSS shipped inside emails, where theme
   variables do not exist */
import { mergeAttributes, Node } from '@tiptap/core';
import { readBlockStyleAttribute } from '@/advanced-text-editor/extensions/blocks/readBlockStyleAttribute';
import { inlineStyleToCss } from '@/advanced-text-editor/utils/inlineStyleToCss';
import { TIPTAP_NODE_TYPES } from 'twenty-shared/utils';

export const DividerNode = Node.create({
  name: TIPTAP_NODE_TYPES.DIVIDER,
  group: 'block',
  atom: true,

  addAttributes() {
    return {
      style: {
        default: {
          borderTopWidth: '1px',
          borderTopStyle: 'solid',
          borderTopColor: '#ebebeb',
          marginTop: '16px',
          marginRight: '8px',
          marginBottom: '16px',
          marginLeft: '8px',
        },
        parseHTML: readBlockStyleAttribute,
        renderHTML: (attributes) => ({
          style: inlineStyleToCss(attributes.style),
          'data-style': JSON.stringify(attributes.style ?? {}),
        }),
      },
    };
  },

  parseHTML() {
    return [{ tag: 'hr[data-block-divider]' }];
  },

  renderHTML({ HTMLAttributes }) {
    return [
      'hr',
      mergeAttributes(HTMLAttributes, {
        'data-block-divider': 'true',
        class: 'block-divider',
      }),
    ];
  },
});