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

interoperability.js « utils « diffs « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a52e8fd25f596402a778bed1595cb3ddbb74cdd5 (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
const OLD = 'old';
const NEW = 'new';
const ATTR_PREFIX = 'data-interop-';

export const ATTR_TYPE = `${ATTR_PREFIX}type`;
export const ATTR_LINE = `${ATTR_PREFIX}line`;
export const ATTR_NEW_LINE = `${ATTR_PREFIX}new-line`;
export const ATTR_OLD_LINE = `${ATTR_PREFIX}old-line`;

export const getInteropInlineAttributes = (line) => {
  if (!line) {
    return null;
  }

  const interopType = line.type?.startsWith(OLD) ? OLD : NEW;

  const interopLine = interopType === OLD ? line.old_line : line.new_line;

  return {
    [ATTR_TYPE]: interopType,
    [ATTR_LINE]: interopLine,
    [ATTR_NEW_LINE]: line.new_line,
    [ATTR_OLD_LINE]: line.old_line,
  };
};

export const getInteropOldSideAttributes = (line) => {
  if (!line) {
    return null;
  }

  return {
    [ATTR_TYPE]: OLD,
    [ATTR_LINE]: line.old_line,
    [ATTR_OLD_LINE]: line.old_line,
  };
};

export const getInteropNewSideAttributes = (line) => {
  if (!line) {
    return null;
  }

  return {
    [ATTR_TYPE]: NEW,
    [ATTR_LINE]: line.new_line,
    [ATTR_NEW_LINE]: line.new_line,
  };
};