Welcome to mirror list, hosted at ThFree Co, Russian Federation.

playable.js « nodes « markdown « behaviors « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7559c2a6a8a505fcbead59b8a8cf713754cce90a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { defaultMarkdownSerializer } from '~/lib/prosemirror_markdown_serializer';

/**
 * Abstract base class for playable media, like video and audio.
 * Must not be instantiated directly. Subclasses must set
 * the `mediaType` property in their constructors.
 * @abstract
 */
export default ({ mediaType, extraElementAttrs = {} }) => {
  const attrs = {
    src: {},
    alt: {
      default: null,
    },
  };
  const parseDOM = [
    {
      // eslint-disable-next-line @gitlab/require-i18n-strings
      tag: `.${mediaType}-container`,
      getAttrs: (el) => ({
        src: el.querySelector(mediaType).src,
        alt: el.querySelector(mediaType).dataset.title,
      }),
    },
  ];
  const toDOM = (node) => [
    'span',
    { class: `media-container ${mediaType}-container` },
    [
      mediaType,
      {
        src: node.attrs.src,
        controls: true,
        'data-setup': '{}',
        'data-title': node.attrs.alt,
        ...extraElementAttrs,
      },
    ],
    ['a', { href: node.attrs.src }, node.attrs.alt],
  ];

  return {
    name: mediaType,
    schema: {
      attrs,
      group: 'inline',
      inline: true,
      draggable: true,
      parseDOM,
      toDOM,
    },
    toMarkdown(state, node) {
      defaultMarkdownSerializer.nodes.image(state, node);
    },
  };
};