@atlaskit/code 14.1.5 → 14.3.2

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 (52) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/__perf__/default.tsx +1 -1
  3. package/bidi-warning/package.json +7 -0
  4. package/bidi-warning-decorator/package.json +7 -0
  5. package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.ts +10 -10
  6. package/codemods/__tests__/14.0.0-lite-mode/remove-language.ts +6 -6
  7. package/codemods/__tests__/14.0.0-lite-mode/text-to-child.ts +10 -10
  8. package/dist/cjs/bidi-warning/bidi-warning-decorator.js +73 -0
  9. package/dist/cjs/bidi-warning/index.js +15 -0
  10. package/dist/cjs/bidi-warning/ui/index.js +57 -0
  11. package/dist/cjs/bidi-warning/ui/styled.js +74 -0
  12. package/dist/cjs/bidi-warning/ui/types.js +5 -0
  13. package/dist/cjs/code-block.js +14 -2
  14. package/dist/cjs/code.js +70 -5
  15. package/dist/cjs/index.js +6 -6
  16. package/dist/cjs/internal/hooks/use-highlight.js +2 -2
  17. package/dist/cjs/internal/theme/constants.js +1 -1
  18. package/dist/cjs/internal/theme/get-theme.js +3 -3
  19. package/dist/cjs/internal/theme/styles.js +3 -3
  20. package/dist/cjs/react-syntax-highlighter-bidi-warning-renderer.js +180 -0
  21. package/dist/cjs/version.json +1 -1
  22. package/dist/es2019/bidi-warning/bidi-warning-decorator.js +42 -0
  23. package/dist/es2019/bidi-warning/index.js +1 -0
  24. package/dist/es2019/bidi-warning/ui/index.js +40 -0
  25. package/dist/es2019/bidi-warning/ui/styled.js +65 -0
  26. package/dist/es2019/bidi-warning/ui/types.js +1 -0
  27. package/dist/es2019/code-block.js +11 -2
  28. package/dist/es2019/code.js +54 -2
  29. package/dist/es2019/react-syntax-highlighter-bidi-warning-renderer.js +156 -0
  30. package/dist/es2019/version.json +1 -1
  31. package/dist/esm/bidi-warning/bidi-warning-decorator.js +61 -0
  32. package/dist/esm/bidi-warning/index.js +1 -0
  33. package/dist/esm/bidi-warning/ui/index.js +42 -0
  34. package/dist/esm/bidi-warning/ui/styled.js +64 -0
  35. package/dist/esm/bidi-warning/ui/types.js +1 -0
  36. package/dist/esm/code-block.js +13 -2
  37. package/dist/esm/code.js +59 -3
  38. package/dist/esm/internal/hooks/use-highlight.js +2 -2
  39. package/dist/esm/internal/theme/get-theme.js +2 -2
  40. package/dist/esm/internal/theme/styles.js +2 -2
  41. package/dist/esm/react-syntax-highlighter-bidi-warning-renderer.js +168 -0
  42. package/dist/esm/version.json +1 -1
  43. package/dist/types/bidi-warning/bidi-warning-decorator.d.ts +5 -0
  44. package/dist/types/bidi-warning/index.d.ts +1 -0
  45. package/dist/types/bidi-warning/ui/index.d.ts +3 -0
  46. package/dist/types/bidi-warning/ui/styled.d.ts +7 -0
  47. package/dist/types/bidi-warning/ui/types.d.ts +29 -0
  48. package/dist/types/code.d.ts +3 -2
  49. package/dist/types/internal/types.d.ts +19 -0
  50. package/dist/types/react-syntax-highlighter-bidi-warning-renderer.d.ts +9 -0
  51. package/dist/types/types.d.ts +19 -0
  52. package/package.json +10 -8
package/dist/cjs/index.js CHANGED
@@ -13,12 +13,6 @@ Object.defineProperty(exports, "Code", {
13
13
  return _code.default;
14
14
  }
15
15
  });
16
- Object.defineProperty(exports, "getCodeStyles", {
17
- enumerable: true,
18
- get: function get() {
19
- return _code.getCodeStyles;
20
- }
21
- });
22
16
  Object.defineProperty(exports, "CodeBlock", {
23
17
  enumerable: true,
24
18
  get: function get() {
@@ -31,6 +25,12 @@ Object.defineProperty(exports, "SUPPORTED_LANGUAGES", {
31
25
  return _constants.SUPPORTED_LANGUAGES;
32
26
  }
33
27
  });
28
+ Object.defineProperty(exports, "getCodeStyles", {
29
+ enumerable: true,
30
+ get: function get() {
31
+ return _code.getCodeStyles;
32
+ }
33
+ });
34
34
 
35
35
  var _code = _interopRequireWildcard(require("./code"));
36
36
 
@@ -13,9 +13,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
13
13
 
14
14
  var _react = require("react");
15
15
 
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
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; }
17
17
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+ 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; }
19
19
 
20
20
  var DEFAULT_LINE_EL_ATTR_OBJ = {
21
21
  'data-ds--code--row': ''
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CODE_BLOCK_SELECTOR = exports.VAR_CODE_BG_COLOR = exports.VAR_CODE_LINE_NUMBER_BG_COLOR = exports.LINE_NUMBER_GUTTER = exports.SPACING = exports.HIGHLIGHT_BORDER_WIDTH = exports.CODE_LINE_HEIGHT = exports.CODE_FONT_SIZE = void 0;
6
+ exports.VAR_CODE_LINE_NUMBER_BG_COLOR = exports.VAR_CODE_BG_COLOR = exports.SPACING = exports.LINE_NUMBER_GUTTER = exports.HIGHLIGHT_BORDER_WIDTH = exports.CODE_LINE_HEIGHT = exports.CODE_FONT_SIZE = exports.CODE_BLOCK_SELECTOR = void 0;
7
7
 
8
8
  var _constants = require("@atlaskit/theme/constants");
9
9
 
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.default = exports.getColorPalette = exports.defaultBaseTheme = exports.getBaseTheme = void 0;
10
+ exports.getColorPalette = exports.getBaseTheme = exports.defaultBaseTheme = exports.default = void 0;
11
11
 
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
 
@@ -23,9 +23,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
23
23
 
24
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
25
 
26
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
26
+ 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; }
27
27
 
28
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
28
+ 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; }
29
29
 
30
30
  // Hardcoded values have been used due to the current color palette not having any
31
31
  // accessible color options for Teal and Yellow and +20A
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getCodeBlockTheme = exports.getCodeStyles = exports.getCodeBlockStyles = exports.getBaseCodeStyles = exports.getLineNumWidth = void 0;
8
+ exports.getLineNumWidth = exports.getCodeStyles = exports.getCodeBlockTheme = exports.getCodeBlockStyles = exports.getBaseCodeStyles = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -15,9 +15,9 @@ var _constants2 = require("./constants");
15
15
 
16
16
  var _getTheme = require("./get-theme");
17
17
 
18
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
18
+ 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; }
19
19
 
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
20
+ 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; }
21
21
 
22
22
  var getLineNumWidth = function getLineNumWidth(numLines) {
23
23
  if (!numLines) {
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createBidiWarningRenderer = createBidiWarningRenderer;
9
+ exports.createChildren = createChildren;
10
+ exports.createClassNameString = createClassNameString;
11
+ exports.createStyleObject = createStyleObject;
12
+
13
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
14
+
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+
17
+ var _react = _interopRequireDefault(require("react"));
18
+
19
+ var _bidiWarning = _interopRequireDefault(require("./bidi-warning"));
20
+
21
+ var _bidiWarningDecorator = _interopRequireDefault(require("./bidi-warning/bidi-warning-decorator"));
22
+
23
+ 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
+ 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
+ function createBidiWarningRenderer(codeBidiWarningConfig) {
28
+ return function bidiWarningRenderer(_ref) {
29
+ var rows = _ref.rows,
30
+ stylesheet = _ref.stylesheet,
31
+ useInlineStyles = _ref.useInlineStyles;
32
+ return rows.map(function (node, i) {
33
+ return createElement({
34
+ node: node,
35
+ stylesheet: stylesheet,
36
+ useInlineStyles: useInlineStyles,
37
+ codeBidiWarningConfig: codeBidiWarningConfig,
38
+ key: "code-segement".concat(i)
39
+ });
40
+ });
41
+ };
42
+ } // Get all possible permutations of all power sets
43
+ //
44
+ // Super simple, non-algorithmic solution since the
45
+ // number of class names will not be greater than 4
46
+
47
+
48
+ function powerSetPermutations(arr) {
49
+ var arrLength = arr.length;
50
+
51
+ if (arrLength === 0 || arrLength === 1) {
52
+ return arr;
53
+ }
54
+
55
+ if (arrLength === 2) {
56
+ // prettier-ignore
57
+ return [arr[0], arr[1], "".concat(arr[0], ".").concat(arr[1]), "".concat(arr[1], ".").concat(arr[0])];
58
+ }
59
+
60
+ if (arrLength === 3) {
61
+ 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
+ }
63
+
64
+ if (arrLength >= 4) {
65
+ // Currently does not support more than 4 extra
66
+ // class names (after `.token` has been removed)
67
+ 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
+ }
69
+ }
70
+
71
+ var classNameCombinations = {};
72
+
73
+ function getClassNameCombinations(classNames) {
74
+ if (classNames.length === 0 || classNames.length === 1) {
75
+ return classNames;
76
+ }
77
+
78
+ var key = classNames.join('.');
79
+
80
+ if (!classNameCombinations[key]) {
81
+ classNameCombinations[key] = powerSetPermutations(classNames);
82
+ }
83
+
84
+ return classNameCombinations[key];
85
+ }
86
+
87
+ function createStyleObject(classNames) {
88
+ var elementStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
89
+ var stylesheet = arguments.length > 2 ? arguments[2] : undefined;
90
+ var nonTokenClassNames = classNames.filter(function (className) {
91
+ return className !== 'token';
92
+ });
93
+ var classNamesCombinations = getClassNameCombinations(nonTokenClassNames);
94
+ return classNamesCombinations.reduce(function (styleObject, className) {
95
+ return _objectSpread(_objectSpread({}, styleObject), stylesheet[className]);
96
+ }, elementStyle);
97
+ }
98
+
99
+ function createClassNameString(classNames) {
100
+ return classNames.join(' ');
101
+ }
102
+
103
+ function createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig) {
104
+ var childrenCount = 0;
105
+ return function (children) {
106
+ childrenCount += 1;
107
+ return children.map(function (child, i) {
108
+ return createElement({
109
+ node: child,
110
+ stylesheet: stylesheet,
111
+ useInlineStyles: useInlineStyles,
112
+ codeBidiWarningConfig: codeBidiWarningConfig,
113
+ key: "code-segment-".concat(childrenCount, "-").concat(i)
114
+ });
115
+ });
116
+ };
117
+ }
118
+
119
+ function createElement(_ref2) {
120
+ 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;
127
+ var properties = node.properties,
128
+ type = node.type,
129
+ TagName = node.tagName,
130
+ value = node.value;
131
+
132
+ if (type === 'text') {
133
+ // occasionally react-syntax-highlighter passes a numeric value when the
134
+ // type is text
135
+ var textValue = value + '';
136
+ var decorated = (0, _bidiWarningDecorator.default)(textValue, function (_ref3) {
137
+ var bidiCharacter = _ref3.bidiCharacter,
138
+ index = _ref3.index;
139
+ return /*#__PURE__*/_react.default.createElement(_bidiWarning.default, {
140
+ bidiCharacter: bidiCharacter,
141
+ key: index,
142
+ label: codeBidiWarningConfig.codeBidiWarningLabel,
143
+ tooltipEnabled: codeBidiWarningConfig.codeBidiWarningTooltipEnabled
144
+ });
145
+ });
146
+ return decorated;
147
+ } else if (TagName) {
148
+ var childrenCreator = createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig);
149
+ var props;
150
+
151
+ if (!useInlineStyles) {
152
+ props = _objectSpread(_objectSpread({}, properties), {}, {
153
+ className: createClassNameString(properties.className)
154
+ });
155
+ } else {
156
+ var allStylesheetSelectors = Object.keys(stylesheet).reduce(function (classes, selector) {
157
+ selector.split('.').forEach(function (className) {
158
+ if (!classes.includes(className)) {
159
+ classes.push(className);
160
+ }
161
+ });
162
+ return classes;
163
+ }, []); // For compatibility with older versions of react-syntax-highlighter
164
+
165
+ var startingClassName = properties.className && properties.className.includes('token') ? ['token'] : [];
166
+ var className = properties.className && startingClassName.concat(properties.className.filter(function (className) {
167
+ return !allStylesheetSelectors.includes(className);
168
+ }));
169
+ props = _objectSpread(_objectSpread({}, properties), {}, {
170
+ className: createClassNameString(className) || undefined,
171
+ style: createStyleObject(properties.className, Object.assign({}, properties.style, style), stylesheet)
172
+ });
173
+ }
174
+
175
+ var children = childrenCreator(node.children);
176
+ return /*#__PURE__*/_react.default.createElement(TagName, (0, _extends2.default)({
177
+ key: key
178
+ }, props), children);
179
+ }
180
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/code",
3
- "version": "14.1.5",
3
+ "version": "14.3.2",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,42 @@
1
+ export const bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/g;
2
+ export default function codeBidiWarningDecorator(originalText, decorate) {
3
+ const matches = [...originalText.matchAll(bidiCharacterRegex)];
4
+
5
+ if (matches.length === 0) {
6
+ // No matches encountered, so we return the originalText value
7
+ return originalText;
8
+ }
9
+
10
+ let children = [];
11
+ let mappedTo = 0;
12
+
13
+ for (const match of matches) {
14
+ if (mappedTo !== match.index) {
15
+ // There were unmatched characters prior to this match which haven't been
16
+ // mapped to the children.
17
+ // Add them as plain text.
18
+ children.push(originalText.substring(mappedTo, match.index));
19
+ }
20
+
21
+ children.push(decorate({
22
+ bidiCharacter: match[0],
23
+ index: match.index
24
+ })); // While index is guaranteed to be present, it needs to be asserted due
25
+ // to a limitation of typescripts regex handling
26
+ //
27
+ // https://github.com/microsoft/TypeScript/issues/36788
28
+ // Decorate bidi character
29
+
30
+ mappedTo = match.index + match[0].length;
31
+ }
32
+
33
+ if (mappedTo !== originalText.length) {
34
+ // There is text following the final match, which needs to be mapped
35
+ // to the children.
36
+ // Added as plain text.
37
+ children.push(originalText.substring(mappedTo, originalText.length));
38
+ } // return the mapped children with decorated bidi characters
39
+
40
+
41
+ return children;
42
+ }
@@ -0,0 +1 @@
1
+ export { default } from './ui';
@@ -0,0 +1,40 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React from 'react';
3
+ import Tooltip from '@atlaskit/tooltip';
4
+ import { Decorator } from './styled';
5
+ export default function BidiWarning({
6
+ testId,
7
+ bidiCharacter,
8
+ skipChildren,
9
+ tooltipEnabled,
10
+ label = 'Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.'
11
+ }) {
12
+ if (tooltipEnabled) {
13
+ return (
14
+ /*#__PURE__*/
15
+ // Following patches, this should be updated to use the render props signature which will provide aria attributes.
16
+ // Note: this should be tested, as initial testing did not see attributes work with current tooltip implementation.
17
+ React.createElement(Tooltip, {
18
+ content: label,
19
+ tag: CustomizedTagWithRef
20
+ }, /*#__PURE__*/React.createElement(Decorator, {
21
+ testId: testId,
22
+ bidiCharacter: bidiCharacter
23
+ }, skipChildren ? null : bidiCharacter))
24
+ );
25
+ }
26
+
27
+ return /*#__PURE__*/React.createElement(Decorator, {
28
+ testId: testId,
29
+ bidiCharacter: bidiCharacter
30
+ }, skipChildren ? null : bidiCharacter);
31
+ }
32
+ const CustomizedTagWithRef = /*#__PURE__*/React.forwardRef((props, ref) => {
33
+ const {
34
+ children,
35
+ ...rest
36
+ } = props;
37
+ return /*#__PURE__*/React.createElement("span", _extends({}, rest, {
38
+ ref: ref
39
+ }), children);
40
+ });
@@ -0,0 +1,65 @@
1
+ /** @jsx jsx */
2
+ import { css, jsx } from '@emotion/core';
3
+ import { Y75 } from '@atlaskit/theme/colors';
4
+ const decoration = css({
5
+ // Required as otherwise the following bidi characters cause the span
6
+ // to not receive hover events.
7
+ //
8
+ // U+2066 LEFT-TO-RIGHT ISOLATE (when using pseudo element before)
9
+ // U+202E RIGHT-TO-LEFT OVERRIDE' (when using pseudo element after)
10
+ position: 'relative',
11
+ ':before': {
12
+ /* layout */
13
+ display: 'inline-flex',
14
+ flexDirection: 'row',
15
+ justifyContent: 'center',
16
+ alignItems: 'center',
17
+ padding: '0 4px',
18
+ fontSize: '14px',
19
+ lineHeight: '18px',
20
+ background: Y75,
21
+
22
+ /**
23
+ * Ensures the decoration receives pointer events when it occurs with
24
+ * an ancestor that disables them.
25
+ */
26
+ pointerEvents: 'auto',
27
+
28
+ /* contents */
29
+ content: '"<"attr(data-bidi-character-code)">"',
30
+ // This color is Y800 which is not yet rolled out
31
+ // https://hello.atlassian.net/wiki/spaces/~tswan/pages/1366555782?focusedCommentId=1370387374#comment-1370387374
32
+ color: '#7F5F01',
33
+ fontStyle: 'normal'
34
+ },
35
+ ':hover:before': {
36
+ color: '#533F04'
37
+ }
38
+ });
39
+ export function Decorator({
40
+ bidiCharacter,
41
+ children,
42
+ testId
43
+ }) {
44
+ const bidiCharacterCode = getBidiCharacterCode(bidiCharacter);
45
+ return jsx("span", {
46
+ "aria-label": bidiCharacterCode
47
+ }, jsx("span", {
48
+ css: decoration,
49
+ "data-testid": testId,
50
+ "data-bidi-character-code": bidiCharacterCode // This is set to true so that the content is not read out by
51
+ // screen readers as the content includes angle brackets for
52
+ // visual decoration purposes.
53
+ // We use a span with the aria-label set to the bidi character code
54
+ // above this span for screen readers.
55
+ ,
56
+ "aria-hidden": "true"
57
+ }, children));
58
+ }
59
+
60
+ function getBidiCharacterCode(bidiCharacter) {
61
+ var _bidiCharacter$codePo;
62
+
63
+ const bidiCharacterCode = (_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toString(16);
64
+ return `U+${bidiCharacterCode}`;
65
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -6,6 +6,7 @@ import { useGlobalTheme } from '@atlaskit/theme/components';
6
6
  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
+ import { createBidiWarningRenderer } from './react-syntax-highlighter-bidi-warning-renderer';
9
10
  const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
10
11
  showLineNumbers = true,
11
12
  language: providedLanguage = 'text',
@@ -13,7 +14,10 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
13
14
  highlightedStartText = 'Highlight start',
14
15
  highlightedEndText = 'Highlight end',
15
16
  testId,
16
- text
17
+ text,
18
+ codeBidiWarnings = true,
19
+ codeBidiWarningLabel,
20
+ codeBidiWarningTooltipEnabled = true
17
21
  }) {
18
22
  const numLines = (text || '').split('\n').length;
19
23
  const globalTheme = useGlobalTheme();
@@ -31,6 +35,10 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
31
35
  const language = useMemo(() => normalizeLanguage(providedLanguage), [providedLanguage]); // https://product-fabric.atlassian.net/browse/DST-2472
32
36
 
33
37
  const languageToUse = text ? language : 'text';
38
+ const renderer = codeBidiWarnings ? createBidiWarningRenderer({
39
+ codeBidiWarningLabel,
40
+ codeBidiWarningTooltipEnabled
41
+ }) : undefined;
34
42
  return jsx(SyntaxHighlighter, {
35
43
  "data-testid": testId,
36
44
  "data-code-lang": language,
@@ -42,7 +50,8 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
42
50
  ,
43
51
  wrapLines: highlight.length > 0 || !!testId,
44
52
  lineProps: getLineProps,
45
- useInlineStyles: false
53
+ useInlineStyles: false,
54
+ renderer: renderer
46
55
  }, text);
47
56
  });
48
57
  CodeBlock.displayName = 'CodeBlock';
@@ -1,9 +1,11 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
 
3
3
  /** @jsx jsx */
4
- import { forwardRef, memo, useMemo } from 'react';
4
+ import React, { forwardRef, memo, useMemo } from 'react';
5
5
  import { jsx } from '@emotion/core';
6
6
  import { useGlobalTheme } from '@atlaskit/theme/components';
7
+ import CodeBidiWarning from './bidi-warning';
8
+ import codeBidiWarningDecorator from './bidi-warning/bidi-warning-decorator';
7
9
  import { getCodeStyles } from './internal/theme/styles';
8
10
  const Code = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Code({
9
11
  testId,
@@ -11,12 +13,62 @@ const Code = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Code({
11
13
  }, ref) {
12
14
  const theme = useGlobalTheme();
13
15
  const styles = useMemo(() => getCodeStyles(theme), [theme]);
16
+ const {
17
+ children,
18
+ codeBidiWarnings = true,
19
+ codeBidiWarningLabel,
20
+ codeBidiWarningTooltipEnabled = true,
21
+ ...otherProps
22
+ } = props;
23
+ const decoratedChildren = codeBidiWarnings ? jsx(RenderCodeChildrenWithBidiWarnings, {
24
+ codeBidiWarningLabel: codeBidiWarningLabel,
25
+ codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
26
+ }, children) : children;
14
27
  return jsx("code", _extends({
15
28
  ref: ref,
16
29
  "data-testid": testId,
17
30
  css: styles
18
- }, props));
31
+ }, otherProps), decoratedChildren);
19
32
  }));
33
+
34
+ function RenderCodeChildrenWithBidiWarnings({
35
+ children,
36
+ codeBidiWarningLabel,
37
+ codeBidiWarningTooltipEnabled
38
+ }) {
39
+ const replacedChildren = React.Children.map(children, childNode => {
40
+ if (typeof childNode === 'string') {
41
+ const decorated = codeBidiWarningDecorator(childNode, ({
42
+ bidiCharacter,
43
+ index
44
+ }) => jsx(CodeBidiWarning, {
45
+ bidiCharacter: bidiCharacter,
46
+ key: index,
47
+ label: codeBidiWarningLabel,
48
+ tooltipEnabled: codeBidiWarningTooltipEnabled
49
+ }));
50
+ return decorated;
51
+ }
52
+
53
+ if (isReactElement(childNode) && childNode.props.children) {
54
+ const newChildNode = /*#__PURE__*/React.cloneElement(childNode, {
55
+ children: jsx(RenderCodeChildrenWithBidiWarnings, {
56
+ codeBidiWarningLabel: codeBidiWarningLabel,
57
+ codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
58
+ }, childNode.props.children)
59
+ });
60
+ return newChildNode;
61
+ }
62
+
63
+ return childNode;
64
+ });
65
+ return jsx(React.Fragment, null, replacedChildren);
66
+ }
67
+
68
+ function isReactElement(child) {
69
+ return !!child.type;
70
+ }
71
+
20
72
  Code.displayName = 'Code';
21
73
  export { getCodeStyles };
22
74
  export default Code;