@atlaskit/code 14.4.5 → 14.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/__perf__/code-block-100-lines.tsx +7 -0
  3. package/__perf__/code-block-1000-lines.tsx +7 -0
  4. package/__perf__/code-block-4458-lines.tsx +7 -0
  5. package/__perf__/code-block-500-lines.tsx +7 -0
  6. package/__perf__/{code-block-text.tsx → code-block-no-syntax-highlighting.tsx} +1 -1
  7. package/__perf__/{code-block-jsx.tsx → code-block-syntax-highlighting.tsx} +0 -0
  8. package/__perf__/{default.tsx → inline-code.tsx} +0 -0
  9. package/__perf__/source-code-examples/100-line-example.tsx +101 -0
  10. package/__perf__/source-code-examples/1000-line-example.tsx +1000 -0
  11. package/__perf__/source-code-examples/4458-line-example.tsx +4461 -0
  12. package/__perf__/source-code-examples/500-line-example.tsx +501 -0
  13. package/dist/cjs/bidi-warning/bidi-warning-decorator.js +6 -19
  14. package/dist/cjs/bidi-warning/index.js +0 -2
  15. package/dist/cjs/bidi-warning/ui/index.js +6 -17
  16. package/dist/cjs/bidi-warning/ui/styled.js +7 -12
  17. package/dist/cjs/code-block.js +25 -34
  18. package/dist/cjs/code.js +11 -33
  19. package/dist/cjs/constants.js +0 -2
  20. package/dist/cjs/entry-points/block.js +0 -2
  21. package/dist/cjs/entry-points/constants.js +0 -1
  22. package/dist/cjs/entry-points/inline.js +0 -4
  23. package/dist/cjs/extract-react-types/code-block.js +0 -1
  24. package/dist/cjs/extract-react-types/code.js +0 -1
  25. package/dist/cjs/index.js +0 -7
  26. package/dist/cjs/internal/hooks/use-highlight.js +10 -24
  27. package/dist/cjs/internal/theme/constants.js +2 -3
  28. package/dist/cjs/internal/theme/get-theme.js +0 -16
  29. package/dist/cjs/internal/theme/styles.js +4 -23
  30. package/dist/cjs/internal/utils/get-normalized-language.js +2 -8
  31. package/dist/cjs/react-syntax-highlighter-bidi-warning-renderer.js +17 -41
  32. package/dist/cjs/version.json +1 -1
  33. package/dist/es2019/bidi-warning/bidi-warning-decorator.js +5 -9
  34. package/dist/es2019/bidi-warning/ui/index.js +0 -1
  35. package/dist/es2019/bidi-warning/ui/styled.js +5 -6
  36. package/dist/es2019/code-block.js +5 -3
  37. package/dist/es2019/code.js +0 -7
  38. package/dist/es2019/internal/hooks/use-highlight.js +4 -8
  39. package/dist/es2019/internal/theme/constants.js +2 -1
  40. package/dist/es2019/internal/theme/get-theme.js +2 -3
  41. package/dist/es2019/internal/theme/styles.js +8 -9
  42. package/dist/es2019/internal/utils/get-normalized-language.js +2 -3
  43. package/dist/es2019/react-syntax-highlighter-bidi-warning-renderer.js +14 -21
  44. package/dist/es2019/version.json +1 -1
  45. package/dist/esm/bidi-warning/bidi-warning-decorator.js +6 -16
  46. package/dist/esm/bidi-warning/ui/index.js +6 -9
  47. package/dist/esm/bidi-warning/ui/styled.js +7 -8
  48. package/dist/esm/code-block.js +26 -26
  49. package/dist/esm/code.js +11 -21
  50. package/dist/esm/internal/hooks/use-highlight.js +10 -19
  51. package/dist/esm/internal/theme/constants.js +2 -1
  52. package/dist/esm/internal/theme/get-theme.js +0 -5
  53. package/dist/esm/internal/theme/styles.js +4 -10
  54. package/dist/esm/internal/utils/get-normalized-language.js +2 -3
  55. package/dist/esm/react-syntax-highlighter-bidi-warning-renderer.js +20 -33
  56. package/dist/esm/version.json +1 -1
  57. package/package.json +1 -1
  58. package/report.api.md +14 -1
@@ -1,26 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.normalizeLanguage = void 0;
9
-
10
8
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
11
-
12
9
  var _constants = require("../../constants");
13
-
14
10
  var normalizeLanguage = (0, _memoizeOne.default)(function (language) {
15
11
  if (!language) {
16
12
  return '';
17
13
  }
18
-
19
14
  var match = _constants.SUPPORTED_LANGUAGES.find(function (val) {
20
15
  return val.name === language || val.alias.includes(language);
21
- }); // Fallback to plain monospaced text if language passed but not supported
22
-
23
-
16
+ });
17
+ // Fallback to plain monospaced text if language passed but not supported
24
18
  return match ? match.value : 'text';
25
19
  });
26
20
  exports.normalizeLanguage = normalizeLanguage;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -9,26 +8,18 @@ exports.createBidiWarningRenderer = createBidiWarningRenderer;
9
8
  exports.createChildren = createChildren;
10
9
  exports.createClassNameString = createClassNameString;
11
10
  exports.createStyleObject = createStyleObject;
12
-
13
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
-
15
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
-
17
13
  var _react = _interopRequireDefault(require("react"));
18
-
19
14
  var _bidiWarning = _interopRequireDefault(require("./bidi-warning"));
20
-
21
15
  var _bidiWarningDecorator = _interopRequireDefault(require("./bidi-warning/bidi-warning-decorator"));
22
-
23
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
24
-
25
17
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
26
-
27
18
  function createBidiWarningRenderer(codeBidiWarningConfig) {
28
19
  return function bidiWarningRenderer(_ref) {
29
20
  var rows = _ref.rows,
30
- stylesheet = _ref.stylesheet,
31
- useInlineStyles = _ref.useInlineStyles;
21
+ stylesheet = _ref.stylesheet,
22
+ useInlineStyles = _ref.useInlineStyles;
32
23
  return rows.map(function (node, i) {
33
24
  return createElement({
34
25
  node: node,
@@ -39,51 +30,41 @@ function createBidiWarningRenderer(codeBidiWarningConfig) {
39
30
  });
40
31
  });
41
32
  };
42
- } // Get all possible permutations of all power sets
33
+ }
34
+
35
+ // Get all possible permutations of all power sets
43
36
  //
44
37
  // Super simple, non-algorithmic solution since the
45
38
  // number of class names will not be greater than 4
46
-
47
-
48
39
  function powerSetPermutations(arr) {
49
40
  var arrLength = arr.length;
50
-
51
41
  if (arrLength === 0 || arrLength === 1) {
52
42
  return arr;
53
43
  }
54
-
55
44
  if (arrLength === 2) {
56
45
  // prettier-ignore
57
46
  return [arr[0], arr[1], "".concat(arr[0], ".").concat(arr[1]), "".concat(arr[1], ".").concat(arr[0])];
58
47
  }
59
-
60
48
  if (arrLength === 3) {
61
49
  return [arr[0], arr[1], arr[2], "".concat(arr[0], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[0]), "".concat(arr[1], ".").concat(arr[2]), "".concat(arr[2], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[1], ".").concat(arr[2]), "".concat(arr[0], ".").concat(arr[2], ".").concat(arr[1]), "".concat(arr[1], ".").concat(arr[0], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[2], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[0], ".").concat(arr[1]), "".concat(arr[2], ".").concat(arr[1], ".").concat(arr[0])];
62
50
  }
63
-
64
51
  if (arrLength >= 4) {
65
52
  // Currently does not support more than 4 extra
66
53
  // class names (after `.token` has been removed)
67
54
  return [arr[0], arr[1], arr[2], arr[3], "".concat(arr[0], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[2]), "".concat(arr[0], ".").concat(arr[3]), "".concat(arr[1], ".").concat(arr[0]), "".concat(arr[1], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[3]), "".concat(arr[2], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[1]), "".concat(arr[2], ".").concat(arr[3]), "".concat(arr[3], ".").concat(arr[0]), "".concat(arr[3], ".").concat(arr[1]), "".concat(arr[3], ".").concat(arr[2]), "".concat(arr[0], ".").concat(arr[1], ".").concat(arr[2]), "".concat(arr[0], ".").concat(arr[1], ".").concat(arr[3]), "".concat(arr[0], ".").concat(arr[2], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[2], ".").concat(arr[3]), "".concat(arr[0], ".").concat(arr[3], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[3], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[0], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[0], ".").concat(arr[3]), "".concat(arr[1], ".").concat(arr[2], ".").concat(arr[0]), "".concat(arr[1], ".").concat(arr[2], ".").concat(arr[3]), "".concat(arr[1], ".").concat(arr[3], ".").concat(arr[0]), "".concat(arr[1], ".").concat(arr[3], ".").concat(arr[2]), "".concat(arr[2], ".").concat(arr[0], ".").concat(arr[1]), "".concat(arr[2], ".").concat(arr[0], ".").concat(arr[3]), "".concat(arr[2], ".").concat(arr[1], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[1], ".").concat(arr[3]), "".concat(arr[2], ".").concat(arr[3], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[3], ".").concat(arr[1]), "".concat(arr[3], ".").concat(arr[0], ".").concat(arr[1]), "".concat(arr[3], ".").concat(arr[0], ".").concat(arr[2]), "".concat(arr[3], ".").concat(arr[1], ".").concat(arr[0]), "".concat(arr[3], ".").concat(arr[1], ".").concat(arr[2]), "".concat(arr[3], ".").concat(arr[2], ".").concat(arr[0]), "".concat(arr[3], ".").concat(arr[2], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[1], ".").concat(arr[2], ".").concat(arr[3]), "".concat(arr[0], ".").concat(arr[1], ".").concat(arr[3], ".").concat(arr[2]), "".concat(arr[0], ".").concat(arr[2], ".").concat(arr[1], ".").concat(arr[3]), "".concat(arr[0], ".").concat(arr[2], ".").concat(arr[3], ".").concat(arr[1]), "".concat(arr[0], ".").concat(arr[3], ".").concat(arr[1], ".").concat(arr[2]), "".concat(arr[0], ".").concat(arr[3], ".").concat(arr[2], ".").concat(arr[1]), "".concat(arr[1], ".").concat(arr[0], ".").concat(arr[2], ".").concat(arr[3]), "".concat(arr[1], ".").concat(arr[0], ".").concat(arr[3], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[2], ".").concat(arr[0], ".").concat(arr[3]), "".concat(arr[1], ".").concat(arr[2], ".").concat(arr[3], ".").concat(arr[0]), "".concat(arr[1], ".").concat(arr[3], ".").concat(arr[0], ".").concat(arr[2]), "".concat(arr[1], ".").concat(arr[3], ".").concat(arr[2], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[0], ".").concat(arr[1], ".").concat(arr[3]), "".concat(arr[2], ".").concat(arr[0], ".").concat(arr[3], ".").concat(arr[1]), "".concat(arr[2], ".").concat(arr[1], ".").concat(arr[0], ".").concat(arr[3]), "".concat(arr[2], ".").concat(arr[1], ".").concat(arr[3], ".").concat(arr[0]), "".concat(arr[2], ".").concat(arr[3], ".").concat(arr[0], ".").concat(arr[1]), "".concat(arr[2], ".").concat(arr[3], ".").concat(arr[1], ".").concat(arr[0]), "".concat(arr[3], ".").concat(arr[0], ".").concat(arr[1], ".").concat(arr[2]), "".concat(arr[3], ".").concat(arr[0], ".").concat(arr[2], ".").concat(arr[1]), "".concat(arr[3], ".").concat(arr[1], ".").concat(arr[0], ".").concat(arr[2]), "".concat(arr[3], ".").concat(arr[1], ".").concat(arr[2], ".").concat(arr[0]), "".concat(arr[3], ".").concat(arr[2], ".").concat(arr[0], ".").concat(arr[1]), "".concat(arr[3], ".").concat(arr[2], ".").concat(arr[1], ".").concat(arr[0])];
68
55
  }
69
56
  }
70
-
71
57
  var classNameCombinations = {};
72
-
73
58
  function getClassNameCombinations(classNames) {
74
59
  if (classNames.length === 0 || classNames.length === 1) {
75
60
  return classNames;
76
61
  }
77
-
78
62
  var key = classNames.join('.');
79
-
80
63
  if (!classNameCombinations[key]) {
81
64
  classNameCombinations[key] = powerSetPermutations(classNames);
82
65
  }
83
-
84
66
  return classNameCombinations[key];
85
67
  }
86
-
87
68
  function createStyleObject(classNames) {
88
69
  var elementStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
89
70
  var stylesheet = arguments.length > 2 ? arguments[2] : undefined;
@@ -95,11 +76,9 @@ function createStyleObject(classNames) {
95
76
  return _objectSpread(_objectSpread({}, styleObject), stylesheet[className]);
96
77
  }, elementStyle);
97
78
  }
98
-
99
79
  function createClassNameString(classNames) {
100
80
  return classNames.join(' ');
101
81
  }
102
-
103
82
  function createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig) {
104
83
  var childrenCount = 0;
105
84
  return function (children) {
@@ -115,27 +94,25 @@ function createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig) {
115
94
  });
116
95
  };
117
96
  }
118
-
119
97
  function createElement(_ref2) {
120
98
  var node = _ref2.node,
121
- stylesheet = _ref2.stylesheet,
122
- _ref2$style = _ref2.style,
123
- style = _ref2$style === void 0 ? {} : _ref2$style,
124
- useInlineStyles = _ref2.useInlineStyles,
125
- codeBidiWarningConfig = _ref2.codeBidiWarningConfig,
126
- key = _ref2.key;
99
+ stylesheet = _ref2.stylesheet,
100
+ _ref2$style = _ref2.style,
101
+ style = _ref2$style === void 0 ? {} : _ref2$style,
102
+ useInlineStyles = _ref2.useInlineStyles,
103
+ codeBidiWarningConfig = _ref2.codeBidiWarningConfig,
104
+ key = _ref2.key;
127
105
  var properties = node.properties,
128
- type = node.type,
129
- TagName = node.tagName,
130
- value = node.value;
131
-
106
+ type = node.type,
107
+ TagName = node.tagName,
108
+ value = node.value;
132
109
  if (type === 'text') {
133
110
  // occasionally react-syntax-highlighter passes a numeric value when the
134
111
  // type is text
135
112
  var textValue = value + '';
136
113
  var decorated = (0, _bidiWarningDecorator.default)(textValue, function (_ref3) {
137
114
  var bidiCharacter = _ref3.bidiCharacter,
138
- index = _ref3.index;
115
+ index = _ref3.index;
139
116
  return /*#__PURE__*/_react.default.createElement(_bidiWarning.default, {
140
117
  bidiCharacter: bidiCharacter,
141
118
  key: index,
@@ -147,7 +124,6 @@ function createElement(_ref2) {
147
124
  } else if (TagName) {
148
125
  var childrenCreator = createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig);
149
126
  var props;
150
-
151
127
  if (!useInlineStyles) {
152
128
  props = _objectSpread(_objectSpread({}, properties), {}, {
153
129
  className: createClassNameString(properties.className)
@@ -160,8 +136,9 @@ function createElement(_ref2) {
160
136
  }
161
137
  });
162
138
  return classes;
163
- }, []); // For compatibility with older versions of react-syntax-highlighter
139
+ }, []);
164
140
 
141
+ // For compatibility with older versions of react-syntax-highlighter
165
142
  var startingClassName = properties.className && properties.className.includes('token') ? ['token'] : [];
166
143
  var className = properties.className && startingClassName.concat(properties.className.filter(function (className) {
167
144
  return !allStylesheetSelectors.includes(className);
@@ -171,7 +148,6 @@ function createElement(_ref2) {
171
148
  style: createStyleObject(properties.className, Object.assign({}, properties.style, style), stylesheet)
172
149
  });
173
150
  }
174
-
175
151
  var children = childrenCreator(node.children);
176
152
  return /*#__PURE__*/_react.default.createElement(TagName, (0, _extends2.default)({
177
153
  key: key
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/code",
3
- "version": "14.4.5",
3
+ "version": "14.4.7",
4
4
  "sideEffects": false
5
5
  }
@@ -1,15 +1,12 @@
1
1
  export const bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/g;
2
2
  export default function codeBidiWarningDecorator(originalText, decorate) {
3
3
  const matches = [...originalText.matchAll(bidiCharacterRegex)];
4
-
5
4
  if (matches.length === 0) {
6
5
  // No matches encountered, so we return the originalText value
7
6
  return originalText;
8
7
  }
9
-
10
8
  let children = [];
11
9
  let mappedTo = 0;
12
-
13
10
  for (const match of matches) {
14
11
  if (mappedTo !== match.index) {
15
12
  // There were unmatched characters prior to this match which haven't been
@@ -17,26 +14,25 @@ export default function codeBidiWarningDecorator(originalText, decorate) {
17
14
  // Add them as plain text.
18
15
  children.push(originalText.substring(mappedTo, match.index));
19
16
  }
20
-
21
17
  children.push(decorate({
22
18
  bidiCharacter: match[0],
23
19
  index: match.index
24
- })); // While index is guaranteed to be present, it needs to be asserted due
20
+ }));
21
+
22
+ // While index is guaranteed to be present, it needs to be asserted due
25
23
  // to a limitation of typescripts regex handling
26
24
  //
27
25
  // https://github.com/microsoft/TypeScript/issues/36788
28
26
  // Decorate bidi character
29
-
30
27
  mappedTo = match.index + match[0].length;
31
28
  }
32
-
33
29
  if (mappedTo !== originalText.length) {
34
30
  // There is text following the final match, which needs to be mapped
35
31
  // to the children.
36
32
  // Added as plain text.
37
33
  children.push(originalText.substring(mappedTo, originalText.length));
38
- } // return the mapped children with decorated bidi characters
39
-
34
+ }
40
35
 
36
+ // return the mapped children with decorated bidi characters
41
37
  return children;
42
38
  }
@@ -23,7 +23,6 @@ export default function BidiWarning({
23
23
  }, skipChildren ? null : bidiCharacter))
24
24
  );
25
25
  }
26
-
27
26
  return /*#__PURE__*/React.createElement(Decorator, {
28
27
  testId: testId,
29
28
  bidiCharacter: bidiCharacter
@@ -1,4 +1,5 @@
1
1
  /** @jsx jsx */
2
+
2
3
  import { css, jsx } from '@emotion/react';
3
4
  import { Y75 } from '@atlaskit/theme/colors';
4
5
  const decoration = css({
@@ -10,17 +11,16 @@ const decoration = css({
10
11
  position: 'relative',
11
12
  ':before': {
12
13
  display: 'inline-flex',
13
- padding: `${"var(--ds-scale-0, 0px)"} ${"var(--ds-scale-050, 4px)"}`,
14
+ padding: `${"var(--ds-space-0, 0px)"} ${"var(--ds-space-050, 4px)"}`,
14
15
  alignItems: 'center',
15
16
  justifyContent: 'center',
16
17
  flexDirection: 'row',
17
18
  background: `var(--ds-background-warning, ${Y75})`,
18
19
  color: "var(--ds-text-warning, #7F5F01)",
19
20
  content: '"<"attr(data-bidi-character-code)">"',
20
- fontSize: '14px',
21
+ fontSize: "var(--ds-font-size-100, 14px)",
21
22
  fontStyle: 'normal',
22
23
  lineHeight: '18px',
23
-
24
24
  /**
25
25
  * Ensures the decoration receives pointer events when it occurs with
26
26
  * an ancestor that disables them.
@@ -43,7 +43,8 @@ export function Decorator({
43
43
  }, jsx("span", {
44
44
  css: decoration,
45
45
  "data-testid": testId,
46
- "data-bidi-character-code": bidiCharacterCode // This is set to true so that the content is not read out by
46
+ "data-bidi-character-code": bidiCharacterCode
47
+ // This is set to true so that the content is not read out by
47
48
  // screen readers as the content includes angle brackets for
48
49
  // visual decoration purposes.
49
50
  // We use a span with the aria-label set to the bidi character code
@@ -52,10 +53,8 @@ export function Decorator({
52
53
  "aria-hidden": "true"
53
54
  }, children));
54
55
  }
55
-
56
56
  function getBidiCharacterCode(bidiCharacter) {
57
57
  var _bidiCharacter$codePo;
58
-
59
58
  const bidiCharacterCode = (_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toString(16);
60
59
  return `U+${bidiCharacterCode}`;
61
60
  }
@@ -7,6 +7,7 @@ import { useHighlightLines } from './internal/hooks/use-highlight';
7
7
  import { getCodeBlockStyles, getCodeBlockTheme } from './internal/theme/styles';
8
8
  import { normalizeLanguage } from './internal/utils/get-normalized-language';
9
9
  import { createBidiWarningRenderer } from './react-syntax-highlighter-bidi-warning-renderer';
10
+
10
11
  /**
11
12
  * __Code block__
12
13
  *
@@ -16,7 +17,6 @@ import { createBidiWarningRenderer } from './react-syntax-highlighter-bidi-warni
16
17
  * - [Code](https://atlassian.design/components/code/code-block/code)
17
18
  * - [Usage](https://atlassian.design/components/code/code-block/usage)
18
19
  */
19
-
20
20
  const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
21
21
  showLineNumbers = true,
22
22
  language: providedLanguage = 'text',
@@ -42,8 +42,9 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
42
42
  testId
43
43
  });
44
44
  const getLineProps = useCallback(line => getHighlightStyles(line, highlightedLines), [getHighlightStyles, highlightedLines]);
45
- const language = useMemo(() => normalizeLanguage(providedLanguage), [providedLanguage]); // https://product-fabric.atlassian.net/browse/DST-2472
45
+ const language = useMemo(() => normalizeLanguage(providedLanguage), [providedLanguage]);
46
46
 
47
+ // https://product-fabric.atlassian.net/browse/DST-2472
47
48
  const languageToUse = text ? language : 'text';
48
49
  const renderer = codeBidiWarnings ? createBidiWarningRenderer({
49
50
  codeBidiWarningLabel,
@@ -56,7 +57,8 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
56
57
  css: styles,
57
58
  language: languageToUse,
58
59
  PreTag: "span",
59
- showLineNumbers: showLineNumbers // Wrap lines is needed to set styles on the line when highlighting.
60
+ showLineNumbers: showLineNumbers
61
+ // Wrap lines is needed to set styles on the line when highlighting.
60
62
  ,
61
63
  wrapLines: highlight.length > 0 || !!testId,
62
64
  lineProps: getLineProps,
@@ -1,5 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
-
3
2
  /** @jsx jsx */
4
3
  import React, { forwardRef, memo, useMemo } from 'react';
5
4
  import { css, jsx } from '@emotion/react';
@@ -7,7 +6,6 @@ import { useGlobalTheme } from '@atlaskit/theme/components';
7
6
  import CodeBidiWarning from './bidi-warning';
8
7
  import codeBidiWarningDecorator from './bidi-warning/bidi-warning-decorator';
9
8
  import { getCodeStyles } from './internal/theme/styles';
10
-
11
9
  /**
12
10
  * __Code__
13
11
  *
@@ -40,7 +38,6 @@ const Code = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Code({
40
38
  css: styles
41
39
  }, otherProps), decoratedChildren);
42
40
  }));
43
-
44
41
  function RenderCodeChildrenWithBidiWarnings({
45
42
  children,
46
43
  codeBidiWarningLabel,
@@ -59,7 +56,6 @@ function RenderCodeChildrenWithBidiWarnings({
59
56
  }));
60
57
  return decorated;
61
58
  }
62
-
63
59
  if (isReactElement(childNode) && childNode.props.children) {
64
60
  // eslint-disable-next-line @repo/internal/react/no-clone-element
65
61
  const newChildNode = /*#__PURE__*/React.cloneElement(childNode, {
@@ -70,16 +66,13 @@ function RenderCodeChildrenWithBidiWarnings({
70
66
  });
71
67
  return newChildNode;
72
68
  }
73
-
74
69
  return childNode;
75
70
  });
76
71
  return jsx(React.Fragment, null, replacedChildren);
77
72
  }
78
-
79
73
  function isReactElement(child) {
80
74
  return !!child.type;
81
75
  }
82
-
83
76
  Code.displayName = 'Code';
84
77
  export { getCodeStyles };
85
78
  export default Code;
@@ -2,14 +2,12 @@ import { useCallback, useMemo } from 'react';
2
2
  const DEFAULT_LINE_EL_ATTR_OBJ = {
3
3
  'data-ds--code--row': ''
4
4
  };
5
-
6
5
  const getLineStyleObject = (lineNumber, testId) => {
7
6
  return testId ? {
8
7
  'data-testid': `${testId}-line-${lineNumber}`,
9
8
  ...DEFAULT_LINE_EL_ATTR_OBJ
10
9
  } : DEFAULT_LINE_EL_ATTR_OBJ;
11
10
  };
12
-
13
11
  export const useHighlightLines = ({
14
12
  highlight = '',
15
13
  testId
@@ -18,15 +16,14 @@ export const useHighlightLines = ({
18
16
  if (!highlight) {
19
17
  return [];
20
18
  }
21
-
22
19
  return highlight.split(',').map(num => {
23
20
  if (num.indexOf('-') > 0) {
24
21
  // We found a line group, e.g. 1-3
25
- const [from, to] = num.split('-').map(Number) // Sort by lowest value first, highest value last.
22
+ const [from, to] = num.split('-').map(Number)
23
+ // Sort by lowest value first, highest value last.
26
24
  .sort((a, b) => a - b);
27
25
  return Array(to + 1).fill(undefined).map((_, index) => index).slice(from, to + 1);
28
26
  }
29
-
30
27
  return Number(num);
31
28
  }).reduce((acc, val) => acc.concat(val), []) || [];
32
29
  }, [highlight]);
@@ -34,16 +31,15 @@ export const useHighlightLines = ({
34
31
  if (!highlight || highlightedLines.length === 0) {
35
32
  return getLineStyleObject(lineNumber, testId);
36
33
  }
37
-
38
34
  if (highlightedLines.includes(lineNumber)) {
39
35
  const highlightedDataAttrObj = {
40
36
  'data-ds--code--row--highlight': ''
41
37
  };
42
- return { ...highlightedDataAttrObj,
38
+ return {
39
+ ...highlightedDataAttrObj,
43
40
  ...getLineStyleObject(lineNumber, testId)
44
41
  };
45
42
  }
46
-
47
43
  return getLineStyleObject(lineNumber, testId);
48
44
  }, [highlight, testId]);
49
45
  return {
@@ -5,6 +5,7 @@ export const HIGHLIGHT_BORDER_WIDTH = '4px';
5
5
  export const SPACING = gridSize();
6
6
  export const LINE_NUMBER_GUTTER = SPACING * 2;
7
7
  export const VAR_CODE_LINE_NUMBER_BG_COLOR = '--ds--code--line-number-bg-color';
8
- export const VAR_CODE_BG_COLOR = '--ds--code--bg-color'; // selector for codeblock
8
+ export const VAR_CODE_BG_COLOR = '--ds--code--bg-color';
9
9
 
10
+ // selector for codeblock
10
11
  export const CODE_BLOCK_SELECTOR = `data-ds--code--code-block`;
@@ -221,9 +221,8 @@ export const getColorPalette = memoizeOne(theme => {
221
221
  })(akTheme)
222
222
  };
223
223
  });
224
-
225
- const getTheme = theme => ({ ...getBaseTheme(theme),
224
+ const getTheme = theme => ({
225
+ ...getBaseTheme(theme),
226
226
  ...getColorPalette(theme)
227
227
  });
228
-
229
228
  export default getTheme;
@@ -5,10 +5,8 @@ export const getLineNumWidth = numLines => {
5
5
  if (!numLines) {
6
6
  return '1ch';
7
7
  }
8
-
9
8
  return `${numLines.toFixed(0).length}ch`;
10
9
  };
11
-
12
10
  const lineNumberStyle = theme => ({
13
11
  // width of the line number gutter
14
12
  minWidth: `calc(${theme.lineNumberWidth} + ${LINE_NUMBER_GUTTER}px) !important`,
@@ -26,9 +24,9 @@ const lineNumberStyle = theme => ({
26
24
  userSelect: 'none',
27
25
  // this is to fix SSR spacing issue
28
26
  display: 'block'
29
- }); // order of these keys does matter as it will affect the css precedence
30
-
27
+ });
31
28
 
29
+ // order of these keys does matter as it will affect the css precedence
32
30
  const syntaxKeywordColors = theme => ({
33
31
  '.token': {
34
32
  // this specifically stops prism css cascading.
@@ -174,11 +172,10 @@ const syntaxKeywordColors = theme => ({
174
172
  }
175
173
  }
176
174
  });
175
+
177
176
  /**
178
177
  * Styles applied at the root element level, common across code/codeblock
179
178
  */
180
-
181
-
182
179
  export const getBaseCodeStyles = theme => ({
183
180
  fontSize: CODE_FONT_SIZE,
184
181
  fontFamily: theme.fontFamily,
@@ -188,13 +185,13 @@ export const getBaseCodeStyles = theme => ({
188
185
  borderStyle: 'none',
189
186
  borderRadius: `${borderRadius()}px`
190
187
  });
188
+
191
189
  /**
192
190
  * Takes an implemented CodeBlock theme, and returns styles required for
193
191
  * react-syntax-highlighter.
194
192
  *
195
193
  * @param theme
196
194
  */
197
-
198
195
  export const getCodeBlockStyles = theme => (highlightedStartText, highlightedEndText, hasLineNumbers) => ({
199
196
  // this is required to account for prismjs styles leaking into the codeblock
200
197
  'code[class*="language-"], pre[class*="language-"], code': {
@@ -281,7 +278,8 @@ export const getCodeStyles = globalTheme => {
281
278
  const akTheme = 'theme' in globalTheme ? globalTheme.theme : globalTheme;
282
279
  const theme = getBaseTheme(akTheme);
283
280
  const baseStyles = getBaseCodeStyles(theme);
284
- return { ...baseStyles,
281
+ return {
282
+ ...baseStyles,
285
283
  display: 'inline',
286
284
  padding: '2px 0.5ch',
287
285
  boxDecorationBreak: 'clone',
@@ -292,7 +290,8 @@ export const getCodeStyles = globalTheme => {
292
290
  };
293
291
  };
294
292
  export const getCodeBlockTheme = (globalTheme, maxLines) => {
295
- return { ...getBaseTheme(globalTheme),
293
+ return {
294
+ ...getBaseTheme(globalTheme),
296
295
  ...getColorPalette(globalTheme),
297
296
  lineNumberWidth: maxLines ? getLineNumWidth(maxLines) : undefined
298
297
  };
@@ -4,10 +4,9 @@ export const normalizeLanguage = memoizeOne(language => {
4
4
  if (!language) {
5
5
  return '';
6
6
  }
7
-
8
7
  const match = SUPPORTED_LANGUAGES.find(val => {
9
8
  return val.name === language || val.alias.includes(language);
10
- }); // Fallback to plain monospaced text if language passed but not supported
11
-
9
+ });
10
+ // Fallback to plain monospaced text if language passed but not supported
12
11
  return match ? match.value : 'text';
13
12
  });