@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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atlaskit/code
2
2
 
3
+ ## 14.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b5226ba2c15`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b5226ba2c15) - Replace `bolt` with `yarn` for rendered example changeset commands
8
+
9
+ ## 14.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`7a34eeea327`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7a34eeea327) - Bump prismjs due to vulnerability
14
+
15
+ ## 14.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [`db3477abb18`](https://bitbucket.org/atlassian/atlassian-frontend/commits/db3477abb18) - [ux] ED-13938 disabled code-bidi warning tooltip for mobile, reworked TextWrapper to fix bidi mitigation, and fixed issue where bidi warnings were not presented when renderer used with an annotation provider with draftMode set to true
20
+
21
+ ## 14.2.0
22
+
23
+ ### Minor Changes
24
+
25
+ - [`c80c71b537d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c80c71b537d) - [ux] ED-13860 add bidi warning decorations to code components
26
+
3
27
  ## 14.1.5
4
28
 
5
29
  ### Patch Changes
@@ -2,4 +2,4 @@ import React from 'react';
2
2
 
3
3
  import { Code } from '../src';
4
4
 
5
- export default () => <Code>bolt changeset</Code>;
5
+ export default () => <Code>yarn changeset</Code>;
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/code/bidi-warning",
3
+ "main": "../dist/cjs/bidi-warning/index.js",
4
+ "module": "../dist/esm/bidi-warning/index.js",
5
+ "module:es2019": "../dist/es2019/bidi-warning/index.js",
6
+ "types": "../dist/types/bidi-warning/index.d.ts"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@atlaskit/code/bidi-warning-decorator",
3
+ "main": "../dist/cjs/bidi-warning/bidi-warning-decorator.js",
4
+ "module": "../dist/esm/bidi-warning/bidi-warning-decorator.js",
5
+ "module:es2019": "../dist/es2019/bidi-warning/bidi-warning-decorator.js",
6
+ "types": "../dist/types/bidi-warning/bidi-warning-decorator.d.ts"
7
+ }
@@ -14,12 +14,12 @@ describe('all transforms should be applied', () => {
14
14
  import { Code } from '@atlaskit/code';
15
15
 
16
16
  export default function CodeDefaultExample() {
17
- const text = "bolt changeset";
17
+ const text = "yarn changeset";
18
18
 
19
19
  return (
20
20
  <p>
21
21
  To start creating a changeset, run{' '}
22
- <Code language="text" text="bolt changeset" />. Then you will be prompted
22
+ <Code language="text" text="yarn changeset" />. Then you will be prompted
23
23
  to select packages for release.
24
24
  </p>
25
25
  );
@@ -32,12 +32,12 @@ describe('all transforms should be applied', () => {
32
32
  import { Code } from '@atlaskit/code';
33
33
 
34
34
  export default function CodeDefaultExample() {
35
- const text = "bolt changeset";
35
+ const text = "yarn changeset";
36
36
 
37
37
  return (
38
38
  <p>
39
39
  To start creating a changeset, run{' '}
40
- <Code>bolt changeset</Code>. Then you will be prompted
40
+ <Code>yarn changeset</Code>. Then you will be prompted
41
41
  to select packages for release.
42
42
  </p>
43
43
  );
@@ -60,7 +60,7 @@ describe('all transforms should be applied', () => {
60
60
  return (
61
61
  <p>
62
62
  To start creating a changeset, run{' '}
63
- <AkCode language={language} text="bolt changeset" />. Then you will be prompted
63
+ <AkCode language={language} text="yarn changeset" />. Then you will be prompted
64
64
  to select packages for release.
65
65
  </p>
66
66
  );
@@ -78,7 +78,7 @@ describe('all transforms should be applied', () => {
78
78
  return (
79
79
  <p>
80
80
  To start creating a changeset, run{' '}
81
- <AkCode>bolt changeset</AkCode>. Then you will be prompted
81
+ <AkCode>yarn changeset</AkCode>. Then you will be prompted
82
82
  to select packages for release.
83
83
  </p>
84
84
  );
@@ -186,11 +186,11 @@ describe('all transforms should be applied', () => {
186
186
  import { Code } from '@atlaskit/code';
187
187
 
188
188
  export default function CodeDefaultExample() {
189
- const text = "bolt changeset";
189
+ const text = "yarn changeset";
190
190
 
191
191
  return (
192
192
  <p>
193
- To start creating a changeset, run <Code language="text" text="bolt changeset" />. All g mate.
193
+ To start creating a changeset, run <Code language="text" text="yarn changeset" />. All g mate.
194
194
  </p>
195
195
  );
196
196
  }
@@ -202,11 +202,11 @@ describe('all transforms should be applied', () => {
202
202
  import { Code } from '@atlaskit/code';
203
203
 
204
204
  export default function CodeDefaultExample() {
205
- const text = "bolt changeset";
205
+ const text = "yarn changeset";
206
206
 
207
207
  return (
208
208
  <p>
209
- To start creating a changeset, run <Code>bolt changeset</Code>. All g mate.
209
+ To start creating a changeset, run <Code>yarn changeset</Code>. All g mate.
210
210
  </p>
211
211
  );
212
212
  }
@@ -27,7 +27,7 @@ describe('remove language prop', () => {
27
27
  return (
28
28
  <p>
29
29
  To start creating a changeset, run{' '}
30
- <Code language="text" text="bolt changeset" />. Then you will be prompted
30
+ <Code language="text" text="yarn changeset" />. Then you will be prompted
31
31
  to select packages for release.
32
32
  </p>
33
33
  );
@@ -43,7 +43,7 @@ describe('remove language prop', () => {
43
43
  return (
44
44
  <p>
45
45
  To start creating a changeset, run{' '}
46
- <Code text="bolt changeset" />. Then you will be prompted
46
+ <Code text="yarn changeset" />. Then you will be prompted
47
47
  to select packages for release.
48
48
  </p>
49
49
  );
@@ -66,7 +66,7 @@ describe('remove language prop', () => {
66
66
  return (
67
67
  <p>
68
68
  To start creating a changeset, run{' '}
69
- <Code language={language} text="bolt changeset" />. Then you will be prompted
69
+ <Code language={language} text="yarn changeset" />. Then you will be prompted
70
70
  to select packages for release.
71
71
  </p>
72
72
  );
@@ -84,7 +84,7 @@ describe('remove language prop', () => {
84
84
  return (
85
85
  <p>
86
86
  To start creating a changeset, run{' '}
87
- <Code text="bolt changeset" />. Then you will be prompted
87
+ <Code text="yarn changeset" />. Then you will be prompted
88
88
  to select packages for release.
89
89
  </p>
90
90
  );
@@ -105,7 +105,7 @@ describe('remove language prop', () => {
105
105
  return (
106
106
  <p>
107
107
  To start creating a changeset, run{' '}
108
- <Code text="bolt changeset" />. Then you will be prompted
108
+ <Code text="yarn changeset" />. Then you will be prompted
109
109
  to select packages for release.
110
110
  </p>
111
111
  );
@@ -120,7 +120,7 @@ describe('remove language prop', () => {
120
120
  return (
121
121
  <p>
122
122
  To start creating a changeset, run{' '}
123
- <Code text="bolt changeset" />. Then you will be prompted
123
+ <Code text="yarn changeset" />. Then you will be prompted
124
124
  to select packages for release.
125
125
  </p>
126
126
  );
@@ -19,7 +19,7 @@ describe('make the test prop a child', () => {
19
19
  return (
20
20
  <p>
21
21
  To start creating a changeset, run{' '}
22
- <Code text="bolt changeset" />. Then you will be prompted
22
+ <Code text="yarn changeset" />. Then you will be prompted
23
23
  to select packages for release.
24
24
  </p>
25
25
  );
@@ -34,7 +34,7 @@ describe('make the test prop a child', () => {
34
34
  return (
35
35
  <p>
36
36
  To start creating a changeset, run{' '}
37
- <Code>bolt changeset</Code>. Then you will be prompted
37
+ <Code>yarn changeset</Code>. Then you will be prompted
38
38
  to select packages for release.
39
39
  </p>
40
40
  );
@@ -51,7 +51,7 @@ describe('make the test prop a child', () => {
51
51
 
52
52
  import { Code } from '@atlaskit/code';
53
53
 
54
- const text = "bolt changeset";
54
+ const text = "yarn changeset";
55
55
 
56
56
  export default function CodeDefaultExample() {
57
57
  return (
@@ -68,7 +68,7 @@ describe('make the test prop a child', () => {
68
68
 
69
69
  import { Code } from '@atlaskit/code';
70
70
 
71
- const text = "bolt changeset";
71
+ const text = "yarn changeset";
72
72
 
73
73
  export default function CodeDefaultExample() {
74
74
  return (
@@ -95,7 +95,7 @@ describe('make the test prop a child', () => {
95
95
  return (
96
96
  <p>
97
97
  To start creating a changeset, run{' '}
98
- <Code testId="hello!" text="bolt changeset" />. Then you will be prompted
98
+ <Code testId="hello!" text="yarn changeset" />. Then you will be prompted
99
99
  to select packages for release.
100
100
  </p>
101
101
  );
@@ -110,7 +110,7 @@ describe('make the test prop a child', () => {
110
110
  return (
111
111
  <p>
112
112
  To start creating a changeset, run{' '}
113
- <Code testId="hello!">bolt changeset</Code>. Then you will be prompted
113
+ <Code testId="hello!">yarn changeset</Code>. Then you will be prompted
114
114
  to select packages for release.
115
115
  </p>
116
116
  );
@@ -133,7 +133,7 @@ describe('make the test prop a child', () => {
133
133
  return (
134
134
  <p>
135
135
  To start creating a changeset, run{' '}
136
- <Code {...codeProps} text="bolt changeset" />. Then you will be prompted
136
+ <Code {...codeProps} text="yarn changeset" />. Then you will be prompted
137
137
  to select packages for release.
138
138
  </p>
139
139
  );
@@ -150,7 +150,7 @@ describe('make the test prop a child', () => {
150
150
  return (
151
151
  <p>
152
152
  To start creating a changeset, run{' '}
153
- <Code {...codeProps}>bolt changeset</Code>. Then you will be prompted
153
+ <Code {...codeProps}>yarn changeset</Code>. Then you will be prompted
154
154
  to select packages for release.
155
155
  </p>
156
156
  );
@@ -167,7 +167,7 @@ describe('make the test prop a child', () => {
167
167
 
168
168
  import { Code } from '@atlaskit/code';
169
169
 
170
- const text = "bolt changeset" ;
170
+ const text = "yarn changeset" ;
171
171
 
172
172
  export default function CodeDefaultExample() {
173
173
  return (
@@ -185,7 +185,7 @@ describe('make the test prop a child', () => {
185
185
 
186
186
  import { Code } from '@atlaskit/code';
187
187
 
188
- const text = "bolt changeset" ;
188
+ const text = "yarn changeset" ;
189
189
 
190
190
  export default function CodeDefaultExample() {
191
191
  return (
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.bidiCharacterRegex = void 0;
9
+ exports.default = codeBidiWarningDecorator;
10
+
11
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
+
13
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
14
+
15
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
16
+
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
18
+
19
+ var bidiCharacterRegex = /[\u202A-\u202E\u2066-\u2069]/g;
20
+ exports.bidiCharacterRegex = bidiCharacterRegex;
21
+
22
+ function codeBidiWarningDecorator(originalText, decorate) {
23
+ var matches = (0, _toConsumableArray2.default)(originalText.matchAll(bidiCharacterRegex));
24
+
25
+ if (matches.length === 0) {
26
+ // No matches encountered, so we return the originalText value
27
+ return originalText;
28
+ }
29
+
30
+ var children = [];
31
+ var mappedTo = 0;
32
+
33
+ var _iterator = _createForOfIteratorHelper(matches),
34
+ _step;
35
+
36
+ try {
37
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
38
+ var match = _step.value;
39
+
40
+ if (mappedTo !== match.index) {
41
+ // There were unmatched characters prior to this match which haven't been
42
+ // mapped to the children.
43
+ // Add them as plain text.
44
+ children.push(originalText.substring(mappedTo, match.index));
45
+ }
46
+
47
+ children.push(decorate({
48
+ bidiCharacter: match[0],
49
+ index: match.index
50
+ })); // While index is guaranteed to be present, it needs to be asserted due
51
+ // to a limitation of typescripts regex handling
52
+ //
53
+ // https://github.com/microsoft/TypeScript/issues/36788
54
+ // Decorate bidi character
55
+
56
+ mappedTo = match.index + match[0].length;
57
+ }
58
+ } catch (err) {
59
+ _iterator.e(err);
60
+ } finally {
61
+ _iterator.f();
62
+ }
63
+
64
+ if (mappedTo !== originalText.length) {
65
+ // There is text following the final match, which needs to be mapped
66
+ // to the children.
67
+ // Added as plain text.
68
+ children.push(originalText.substring(mappedTo, originalText.length));
69
+ } // return the mapped children with decorated bidi characters
70
+
71
+
72
+ return children;
73
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "default", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _ui.default;
12
+ }
13
+ });
14
+
15
+ var _ui = _interopRequireDefault(require("./ui"));
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = BidiWarning;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
17
+
18
+ var _styled = require("./styled");
19
+
20
+ var _excluded = ["children"];
21
+
22
+ function BidiWarning(_ref) {
23
+ var testId = _ref.testId,
24
+ bidiCharacter = _ref.bidiCharacter,
25
+ skipChildren = _ref.skipChildren,
26
+ tooltipEnabled = _ref.tooltipEnabled,
27
+ _ref$label = _ref.label,
28
+ label = _ref$label === void 0 ? 'Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.' : _ref$label;
29
+
30
+ if (tooltipEnabled) {
31
+ return (
32
+ /*#__PURE__*/
33
+ // Following patches, this should be updated to use the render props signature which will provide aria attributes.
34
+ // Note: this should be tested, as initial testing did not see attributes work with current tooltip implementation.
35
+ _react.default.createElement(_tooltip.default, {
36
+ content: label,
37
+ tag: CustomizedTagWithRef
38
+ }, /*#__PURE__*/_react.default.createElement(_styled.Decorator, {
39
+ testId: testId,
40
+ bidiCharacter: bidiCharacter
41
+ }, skipChildren ? null : bidiCharacter))
42
+ );
43
+ }
44
+
45
+ return /*#__PURE__*/_react.default.createElement(_styled.Decorator, {
46
+ testId: testId,
47
+ bidiCharacter: bidiCharacter
48
+ }, skipChildren ? null : bidiCharacter);
49
+ }
50
+
51
+ var CustomizedTagWithRef = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
52
+ var children = props.children,
53
+ rest = (0, _objectWithoutProperties2.default)(props, _excluded);
54
+ return /*#__PURE__*/_react.default.createElement("span", (0, _extends2.default)({}, rest, {
55
+ ref: ref
56
+ }), children);
57
+ });
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Decorator = Decorator;
7
+
8
+ var _core = require("@emotion/core");
9
+
10
+ var _colors = require("@atlaskit/theme/colors");
11
+
12
+ /** @jsx jsx */
13
+ var decoration = (0, _core.css)({
14
+ // Required as otherwise the following bidi characters cause the span
15
+ // to not receive hover events.
16
+ //
17
+ // U+2066 LEFT-TO-RIGHT ISOLATE (when using pseudo element before)
18
+ // U+202E RIGHT-TO-LEFT OVERRIDE' (when using pseudo element after)
19
+ position: 'relative',
20
+ ':before': {
21
+ /* layout */
22
+ display: 'inline-flex',
23
+ flexDirection: 'row',
24
+ justifyContent: 'center',
25
+ alignItems: 'center',
26
+ padding: '0 4px',
27
+ fontSize: '14px',
28
+ lineHeight: '18px',
29
+ background: _colors.Y75,
30
+
31
+ /**
32
+ * Ensures the decoration receives pointer events when it occurs with
33
+ * an ancestor that disables them.
34
+ */
35
+ pointerEvents: 'auto',
36
+
37
+ /* contents */
38
+ content: '"<"attr(data-bidi-character-code)">"',
39
+ // This color is Y800 which is not yet rolled out
40
+ // https://hello.atlassian.net/wiki/spaces/~tswan/pages/1366555782?focusedCommentId=1370387374#comment-1370387374
41
+ color: '#7F5F01',
42
+ fontStyle: 'normal'
43
+ },
44
+ ':hover:before': {
45
+ color: '#533F04'
46
+ }
47
+ });
48
+
49
+ function Decorator(_ref) {
50
+ var bidiCharacter = _ref.bidiCharacter,
51
+ children = _ref.children,
52
+ testId = _ref.testId;
53
+ var bidiCharacterCode = getBidiCharacterCode(bidiCharacter);
54
+ return (0, _core.jsx)("span", {
55
+ "aria-label": bidiCharacterCode
56
+ }, (0, _core.jsx)("span", {
57
+ css: decoration,
58
+ "data-testid": testId,
59
+ "data-bidi-character-code": bidiCharacterCode // This is set to true so that the content is not read out by
60
+ // screen readers as the content includes angle brackets for
61
+ // visual decoration purposes.
62
+ // We use a span with the aria-label set to the bidi character code
63
+ // above this span for screen readers.
64
+ ,
65
+ "aria-hidden": "true"
66
+ }, children));
67
+ }
68
+
69
+ function getBidiCharacterCode(bidiCharacter) {
70
+ var _bidiCharacter$codePo;
71
+
72
+ var bidiCharacterCode = (_bidiCharacter$codePo = bidiCharacter.codePointAt(0)) === null || _bidiCharacter$codePo === void 0 ? void 0 : _bidiCharacter$codePo.toString(16);
73
+ return "U+".concat(bidiCharacterCode);
74
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -19,6 +19,8 @@ var _styles = require("./internal/theme/styles");
19
19
 
20
20
  var _getNormalizedLanguage = require("./internal/utils/get-normalized-language");
21
21
 
22
+ var _reactSyntaxHighlighterBidiWarningRenderer = require("./react-syntax-highlighter-bidi-warning-renderer");
23
+
22
24
  /** @jsx jsx */
23
25
  var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
24
26
  var _ref$showLineNumbers = _ref.showLineNumbers,
@@ -32,7 +34,12 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
32
34
  _ref$highlightedEndTe = _ref.highlightedEndText,
33
35
  highlightedEndText = _ref$highlightedEndTe === void 0 ? 'Highlight end' : _ref$highlightedEndTe,
34
36
  testId = _ref.testId,
35
- text = _ref.text;
37
+ text = _ref.text,
38
+ _ref$codeBidiWarnings = _ref.codeBidiWarnings,
39
+ codeBidiWarnings = _ref$codeBidiWarnings === void 0 ? true : _ref$codeBidiWarnings,
40
+ codeBidiWarningLabel = _ref.codeBidiWarningLabel,
41
+ _ref$codeBidiWarningT = _ref.codeBidiWarningTooltipEnabled,
42
+ codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT;
36
43
  var numLines = (text || '').split('\n').length;
37
44
  var globalTheme = (0, _components.useGlobalTheme)();
38
45
  var theme = (0, _react.useMemo)(function () {
@@ -60,6 +67,10 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
60
67
  }, [providedLanguage]); // https://product-fabric.atlassian.net/browse/DST-2472
61
68
 
62
69
  var languageToUse = text ? language : 'text';
70
+ var renderer = codeBidiWarnings ? (0, _reactSyntaxHighlighterBidiWarningRenderer.createBidiWarningRenderer)({
71
+ codeBidiWarningLabel: codeBidiWarningLabel,
72
+ codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
73
+ }) : undefined;
63
74
  return (0, _core.jsx)(_reactSyntaxHighlighter.PrismAsync, {
64
75
  "data-testid": testId,
65
76
  "data-code-lang": language,
@@ -71,7 +82,8 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
71
82
  ,
72
83
  wrapLines: highlight.length > 0 || !!testId,
73
84
  lineProps: getLineProps,
74
- useInlineStyles: false
85
+ useInlineStyles: false,
86
+ renderer: renderer
75
87
  }, text);
76
88
  });
77
89
  CodeBlock.displayName = 'CodeBlock';
package/dist/cjs/code.js CHANGED
@@ -2,43 +2,108 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
5
7
  Object.defineProperty(exports, "__esModule", {
6
8
  value: true
7
9
  });
10
+ exports.default = void 0;
8
11
  Object.defineProperty(exports, "getCodeStyles", {
9
12
  enumerable: true,
10
13
  get: function get() {
11
14
  return _styles.getCodeStyles;
12
15
  }
13
16
  });
14
- exports.default = void 0;
15
17
 
16
18
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
17
19
 
18
20
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
19
21
 
20
- var _react = require("react");
22
+ var _react = _interopRequireWildcard(require("react"));
21
23
 
22
24
  var _core = require("@emotion/core");
23
25
 
24
26
  var _components = require("@atlaskit/theme/components");
25
27
 
28
+ var _bidiWarning = _interopRequireDefault(require("./bidi-warning"));
29
+
30
+ var _bidiWarningDecorator = _interopRequireDefault(require("./bidi-warning/bidi-warning-decorator"));
31
+
26
32
  var _styles = require("./internal/theme/styles");
27
33
 
28
- /** @jsx jsx */
34
+ var _excluded = ["testId"],
35
+ _excluded2 = ["children", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled"];
36
+
37
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
38
+
39
+ 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; }
40
+
29
41
  var Code = /*#__PURE__*/(0, _react.memo)( /*#__PURE__*/(0, _react.forwardRef)(function Code(_ref, ref) {
30
42
  var testId = _ref.testId,
31
- props = (0, _objectWithoutProperties2.default)(_ref, ["testId"]);
43
+ props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
32
44
  var theme = (0, _components.useGlobalTheme)();
33
45
  var styles = (0, _react.useMemo)(function () {
34
46
  return (0, _styles.getCodeStyles)(theme);
35
47
  }, [theme]);
48
+ var children = props.children,
49
+ _props$codeBidiWarnin = props.codeBidiWarnings,
50
+ codeBidiWarnings = _props$codeBidiWarnin === void 0 ? true : _props$codeBidiWarnin,
51
+ codeBidiWarningLabel = props.codeBidiWarningLabel,
52
+ _props$codeBidiWarnin2 = props.codeBidiWarningTooltipEnabled,
53
+ codeBidiWarningTooltipEnabled = _props$codeBidiWarnin2 === void 0 ? true : _props$codeBidiWarnin2,
54
+ otherProps = (0, _objectWithoutProperties2.default)(props, _excluded2);
55
+ var decoratedChildren = codeBidiWarnings ? (0, _core.jsx)(RenderCodeChildrenWithBidiWarnings, {
56
+ codeBidiWarningLabel: codeBidiWarningLabel,
57
+ codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
58
+ }, children) : children;
36
59
  return (0, _core.jsx)("code", (0, _extends2.default)({
37
60
  ref: ref,
38
61
  "data-testid": testId,
39
62
  css: styles
40
- }, props));
63
+ }, otherProps), decoratedChildren);
41
64
  }));
65
+
66
+ function RenderCodeChildrenWithBidiWarnings(_ref2) {
67
+ var children = _ref2.children,
68
+ codeBidiWarningLabel = _ref2.codeBidiWarningLabel,
69
+ codeBidiWarningTooltipEnabled = _ref2.codeBidiWarningTooltipEnabled;
70
+
71
+ var replacedChildren = _react.default.Children.map(children, function (childNode) {
72
+ if (typeof childNode === 'string') {
73
+ var decorated = (0, _bidiWarningDecorator.default)(childNode, function (_ref3) {
74
+ var bidiCharacter = _ref3.bidiCharacter,
75
+ index = _ref3.index;
76
+ return (0, _core.jsx)(_bidiWarning.default, {
77
+ bidiCharacter: bidiCharacter,
78
+ key: index,
79
+ label: codeBidiWarningLabel,
80
+ tooltipEnabled: codeBidiWarningTooltipEnabled
81
+ });
82
+ });
83
+ return decorated;
84
+ }
85
+
86
+ if (isReactElement(childNode) && childNode.props.children) {
87
+ var newChildNode = /*#__PURE__*/_react.default.cloneElement(childNode, {
88
+ children: (0, _core.jsx)(RenderCodeChildrenWithBidiWarnings, {
89
+ codeBidiWarningLabel: codeBidiWarningLabel,
90
+ codeBidiWarningTooltipEnabled: codeBidiWarningTooltipEnabled
91
+ }, childNode.props.children)
92
+ });
93
+
94
+ return newChildNode;
95
+ }
96
+
97
+ return childNode;
98
+ });
99
+
100
+ return (0, _core.jsx)(_react.default.Fragment, null, replacedChildren);
101
+ }
102
+
103
+ function isReactElement(child) {
104
+ return !!child.type;
105
+ }
106
+
42
107
  Code.displayName = 'Code';
43
108
  var _default = Code;
44
109
  exports.default = _default;