@atlaskit/code 14.4.7 → 14.5.0

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 (81) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/bidi-warning/bidi-warning-decorator.js +8 -0
  3. package/dist/cjs/bidi-warning/ui/index.js +8 -0
  4. package/dist/cjs/code-block.js +22 -20
  5. package/dist/cjs/internal/theme/styles.js +20 -9
  6. package/dist/cjs/syntax-highlighter/async.js +88 -0
  7. package/dist/cjs/syntax-highlighter/index.js +44 -0
  8. package/dist/cjs/syntax-highlighter/lib/highlight.js +91 -0
  9. package/dist/cjs/syntax-highlighter/lib/process/create-line-element.js +74 -0
  10. package/dist/cjs/syntax-highlighter/lib/process/create-line.js +32 -0
  11. package/dist/cjs/syntax-highlighter/lib/process/flatten-code-tree.js +29 -0
  12. package/dist/cjs/syntax-highlighter/lib/process/get-code-tree.js +22 -0
  13. package/dist/cjs/syntax-highlighter/lib/process/get-inline-line-number.js +23 -0
  14. package/dist/cjs/syntax-highlighter/lib/process/index.js +122 -0
  15. package/dist/cjs/syntax-highlighter/lib/react-renderer/create-children.js +21 -0
  16. package/dist/cjs/syntax-highlighter/lib/react-renderer/create-element.js +57 -0
  17. package/dist/cjs/syntax-highlighter/lib/react-renderer/index.js +30 -0
  18. package/dist/cjs/syntax-highlighter/types.js +31 -0
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/bidi-warning/bidi-warning-decorator.js +8 -0
  21. package/dist/es2019/bidi-warning/ui/index.js +8 -0
  22. package/dist/es2019/code-block.js +18 -18
  23. package/dist/es2019/internal/theme/styles.js +20 -9
  24. package/dist/es2019/syntax-highlighter/async.js +51 -0
  25. package/dist/es2019/syntax-highlighter/index.js +38 -0
  26. package/dist/es2019/syntax-highlighter/lib/highlight.js +73 -0
  27. package/dist/es2019/syntax-highlighter/lib/process/create-line-element.js +65 -0
  28. package/dist/es2019/syntax-highlighter/lib/process/create-line.js +23 -0
  29. package/dist/es2019/syntax-highlighter/lib/process/flatten-code-tree.js +18 -0
  30. package/dist/es2019/syntax-highlighter/lib/process/get-code-tree.js +16 -0
  31. package/dist/es2019/syntax-highlighter/lib/process/get-inline-line-number.js +17 -0
  32. package/dist/es2019/syntax-highlighter/lib/process/index.js +114 -0
  33. package/dist/es2019/syntax-highlighter/lib/react-renderer/create-children.js +12 -0
  34. package/dist/es2019/syntax-highlighter/lib/react-renderer/create-element.js +53 -0
  35. package/dist/es2019/syntax-highlighter/lib/react-renderer/index.js +23 -0
  36. package/dist/es2019/syntax-highlighter/types.js +9 -0
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/bidi-warning/bidi-warning-decorator.js +8 -0
  39. package/dist/esm/bidi-warning/ui/index.js +8 -0
  40. package/dist/esm/code-block.js +20 -19
  41. package/dist/esm/internal/theme/styles.js +20 -9
  42. package/dist/esm/syntax-highlighter/async.js +76 -0
  43. package/dist/esm/syntax-highlighter/index.js +38 -0
  44. package/dist/esm/syntax-highlighter/lib/highlight.js +84 -0
  45. package/dist/esm/syntax-highlighter/lib/process/create-line-element.js +67 -0
  46. package/dist/esm/syntax-highlighter/lib/process/create-line.js +24 -0
  47. package/dist/esm/syntax-highlighter/lib/process/flatten-code-tree.js +22 -0
  48. package/dist/esm/syntax-highlighter/lib/process/get-code-tree.js +16 -0
  49. package/dist/esm/syntax-highlighter/lib/process/get-inline-line-number.js +17 -0
  50. package/dist/esm/syntax-highlighter/lib/process/index.js +115 -0
  51. package/dist/esm/syntax-highlighter/lib/react-renderer/create-children.js +14 -0
  52. package/dist/esm/syntax-highlighter/lib/react-renderer/create-element.js +50 -0
  53. package/dist/esm/syntax-highlighter/lib/react-renderer/index.js +24 -0
  54. package/dist/esm/syntax-highlighter/types.js +24 -0
  55. package/dist/esm/version.json +1 -1
  56. package/dist/types/bidi-warning/bidi-warning-decorator.d.ts +7 -0
  57. package/dist/types/bidi-warning/ui/index.d.ts +8 -0
  58. package/dist/types/bidi-warning/ui/types.d.ts +11 -15
  59. package/dist/types/extract-react-types/code-block.d.ts +24 -14
  60. package/dist/types/internal/theme/styles.d.ts +1 -1
  61. package/dist/types/internal/types.d.ts +31 -18
  62. package/dist/types/syntax-highlighter/async.d.ts +3 -0
  63. package/dist/types/syntax-highlighter/index.d.ts +36 -0
  64. package/dist/types/syntax-highlighter/lib/highlight.d.ts +12 -0
  65. package/dist/types/syntax-highlighter/lib/process/create-line-element.d.ts +9 -0
  66. package/dist/types/syntax-highlighter/lib/process/create-line.d.ts +3 -0
  67. package/dist/types/syntax-highlighter/lib/process/flatten-code-tree.d.ts +2 -0
  68. package/dist/types/syntax-highlighter/lib/process/get-code-tree.d.ts +2 -0
  69. package/dist/types/syntax-highlighter/lib/process/get-inline-line-number.d.ts +2 -0
  70. package/dist/types/syntax-highlighter/lib/process/index.d.ts +17 -0
  71. package/dist/types/syntax-highlighter/lib/react-renderer/create-children.d.ts +3 -0
  72. package/dist/types/syntax-highlighter/lib/react-renderer/create-element.d.ts +7 -0
  73. package/dist/types/syntax-highlighter/lib/react-renderer/index.d.ts +15 -0
  74. package/dist/types/syntax-highlighter/types.d.ts +129 -0
  75. package/dist/types/types.d.ts +10 -11
  76. package/package.json +13 -9
  77. package/report.api.md +1 -0
  78. package/dist/cjs/react-syntax-highlighter-bidi-warning-renderer.js +0 -156
  79. package/dist/es2019/react-syntax-highlighter-bidi-warning-renderer.js +0 -149
  80. package/dist/esm/react-syntax-highlighter-bidi-warning-renderer.js +0 -155
  81. package/dist/types/react-syntax-highlighter-bidi-warning-renderer.d.ts +0 -9
@@ -20,7 +20,7 @@ export declare const getBaseCodeStyles: (theme: CodeTheme) => {
20
20
  *
21
21
  * @param theme
22
22
  */
23
- export declare const getCodeBlockStyles: (theme: CodeBlockTheme) => (highlightedStartText: string, highlightedEndText: string, hasLineNumbers?: boolean | undefined) => CSSObject;
23
+ export declare const getCodeBlockStyles: (theme: CodeBlockTheme) => (highlightedStartText: string, highlightedEndText: string, showLineNumbers: boolean, shouldWrapLongLines: boolean) => CSSObject;
24
24
  export declare const getCodeStyles: (globalTheme: Theme | {
25
25
  theme: Theme;
26
26
  }) => CSSObject;
@@ -1,24 +1,33 @@
1
1
  import type { SupportedLanguages } from '../constants';
2
2
  export interface CodeBlockProps {
3
3
  /**
4
- * The code to be formatted
4
+ * The code to be formatted.
5
5
  */
6
6
  text: string;
7
7
  /**
8
- * A unique string that appears as a data attribute `data-testid`
9
- * in the rendered code. Serves as a hook for automated tests.
8
+ * A unique string that appears as a data attribute `data-testid` in the
9
+ * rendered code. Serves as a hook for automated tests.
10
10
  */
11
11
  testId?: string;
12
12
  /**
13
- * Whether to showLineNumbers or not, defaults to true
13
+ * Sets whether to display code line numbers or not.
14
+ * @default true
14
15
  */
15
16
  showLineNumbers?: boolean;
16
17
  /**
17
- * The language in which the code is written
18
+ * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
19
+ * `design-system/code`. Run against language grammars from PrismJS (full list
20
+ * available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
21
+ *
22
+ * When set to "text" will not perform highlighting. If unsupported language
23
+ * provided - code will be treated as "text" with no highlighting.
24
+ *
25
+ * @default 'text'
18
26
  */
19
27
  language?: SupportedLanguages;
20
28
  /**
21
- * Lines to highlight comma delimited.
29
+ * Comma delimited lines to highlight.
30
+ *
22
31
  * Example uses:
23
32
  * - To highlight one line `highlight="3"`
24
33
  * - To highlight a group of lines `highlight="1-5"`
@@ -26,32 +35,36 @@ export interface CodeBlockProps {
26
35
  */
27
36
  highlight?: string;
28
37
  /**
29
- * Screen reader text for the start of a highlighted line
38
+ * Screen reader text for the start of a highlighted line.
30
39
  */
31
40
  highlightedStartText?: string;
32
41
  /**
33
- * Screen reader text for the end of a highlighted line
42
+ * Screen reader text for the end of a highlighted line.
34
43
  */
35
44
  highlightedEndText?: string;
36
45
  /**
37
- * When false, disables decorating code with bidi warnings
38
- *
39
- * defaults to true
46
+ * When set to `false`, disables code decorating with bidi warnings.
47
+ * @default true
40
48
  */
41
49
  codeBidiWarnings?: boolean;
42
50
  /**
43
- * Labels for the previous and next buttons used in pagination.
44
- * Defaults to `Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.`.
51
+ * Label for the bidi warning tooltip.
52
+ * @default 'Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.'
45
53
  */
46
54
  codeBidiWarningLabel?: string;
47
55
  /**
48
- * Defaults to enabled (true)
49
- *
50
- * Intended to be disabled when used in a mobile view, such as in the editor
51
- * via mobile bridge, where the tooltip could end up being cut off of otherwise
52
- * not work as expected.
56
+ * Sets whether to render tooltip with the warning or not.
57
+ * Intended to be disabled when used in a mobile view, such as in the editor via mobile bridge,
58
+ * where the tooltip could end up being cut off or otherwise not work as expected.
59
+ * @default true
53
60
  */
54
61
  codeBidiWarningTooltipEnabled?: boolean;
62
+ /**
63
+ * Sets whether long lines will create a horizontally scrolling container.
64
+ * When set to `true`, these lines will visually wrap instead.
65
+ * @default false
66
+ */
67
+ shouldWrapLongLines?: boolean;
55
68
  }
56
69
  export type { SupportedLanguages, LanguageAlias, Language } from '../constants';
57
70
  export type { CodeBlockTheme, CodeTheme } from './theme/types';
@@ -0,0 +1,3 @@
1
+ import { SyntaxHighlighter } from './types';
2
+ declare const _default: typeof SyntaxHighlighter;
3
+ export default _default;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Original library: https://github.com/react-syntax-highlighter/react-syntax-highlighter
3
+ * All modifications by Atlassian
4
+ */
5
+ /**
6
+ * MIT License
7
+ *
8
+ * Copyright (c) 2019 Conor Hastings
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ * of this software and associated documentation files (the "Software"), to deal
12
+ * in the Software without restriction, including without limitation the rights
13
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ * copies of the Software, and to permit persons to whom the Software is
15
+ * furnished to do so, subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ * SOFTWARE.
27
+ */
28
+ /**
29
+ * __Syntax Highlighter__
30
+ *
31
+ * A syntax highlighter based on top of [refractor](https://github.com/wooorm/refractor).
32
+ * @atlaskit/code uses this under-the-hood, but it is not intended for public consumption.
33
+ * You should be using @atlaskit/code directly.
34
+ */
35
+ import SyntaxHighlighter from './async';
36
+ export default SyntaxHighlighter;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { SyntaxHighlighterProps } from '../types';
3
+ /**
4
+ * Takes in a code string and (in the default behaviour):
5
+ * - Uses refractor to turn it into a tree structure with highlighting metadata
6
+ * - Collapses this tree into lines for a renderer
7
+ * - Passes these lines to a React renderer
8
+ *
9
+ * In future, the final step could have a custom renderer.
10
+ */
11
+ declare const Highlight: import("react").NamedExoticComponent<SyntaxHighlighterProps>;
12
+ export default Highlight;
@@ -0,0 +1,9 @@
1
+ import { AST, RefractorNode, SyntaxHighlighterLineProps } from '../../types';
2
+ export declare type CreateLineElementProps = {
3
+ children: RefractorNode[];
4
+ lineNumber: number;
5
+ showLineNumbers?: boolean;
6
+ lineProps?: SyntaxHighlighterLineProps;
7
+ className?: string[];
8
+ };
9
+ export default function createLineElement({ children, lineNumber, showLineNumbers, lineProps, className, }: CreateLineElementProps): AST.Element;
@@ -0,0 +1,3 @@
1
+ import { RefractorNode, SyntaxHighlighterLineProps } from '../../types';
2
+ declare function createLineGenerator(lineProps: SyntaxHighlighterLineProps, shouldCreateParentElementForLines: boolean, showLineNumbers: boolean): (children: RefractorNode[], lineNumber: number, className?: string[]) => RefractorNode | RefractorNode[];
3
+ export default createLineGenerator;
@@ -0,0 +1,2 @@
1
+ import { RefractorNode } from '../../types';
2
+ export default function flattenCodeTree(tree: RefractorNode[], offset?: number, className?: string[]): RefractorNode[];
@@ -0,0 +1,2 @@
1
+ import { AstGenerator, RefractorNode } from '../../types';
2
+ export default function getCodeTree(language: string, code: string, astGenerator?: AstGenerator): RefractorNode[];
@@ -0,0 +1,2 @@
1
+ import { RefractorNode } from '../../types';
2
+ export default function getInlineLineNumber(lineNumber: number): RefractorNode;
@@ -0,0 +1,17 @@
1
+ import { AstGenerator, RefractorNode, SyntaxHighlighterLineProps } from '../../types';
2
+ interface ProcessLines {
3
+ astGenerator: AstGenerator;
4
+ code: string;
5
+ language: string;
6
+ shouldCreateParentElementForLines: boolean;
7
+ lineProps: SyntaxHighlighterLineProps;
8
+ showLineNumbers: boolean;
9
+ }
10
+ /**
11
+ * __Line Processor__
12
+ *
13
+ * A line processor, that uses refractor to turn code into a tree structure
14
+ * with highlighting metadata and collapses this tree into lines for a renderer.
15
+ */
16
+ export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, }: ProcessLines): RefractorNode[];
17
+ export {};
@@ -0,0 +1,3 @@
1
+ import { ReactNode } from 'react';
2
+ import { CodeBidiWarningConfig, RefractorNode } from '../../types';
3
+ export default function createChildren(codeBidiWarningConfig: CodeBidiWarningConfig): (children: RefractorNode[]) => ReactNode[];
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+ import { CodeBidiWarningConfig, RefractorNode } from '../../types';
3
+ export default function createElement({ node, codeBidiWarningConfig, key, }: {
4
+ node: RefractorNode;
5
+ codeBidiWarningConfig: CodeBidiWarningConfig;
6
+ key: string;
7
+ }): ReactNode;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { CodeBidiWarningConfig, RefractorNode } from '../../types';
3
+ /**
4
+ * __React Renderer__
5
+ *
6
+ * A component that receives processed code lines and renders them into the code
7
+ * rows inside the wrapping span and nested code tag, applying passed props and
8
+ * code bidi warning config settings.
9
+ */
10
+ export default function ReactRenderer({ containerProps, codeTagProps, rows, codeBidiWarningConfig, }: {
11
+ containerProps: React.HTMLProps<HTMLElement>;
12
+ codeTagProps: React.HTMLProps<HTMLElement>;
13
+ rows: RefractorNode[];
14
+ codeBidiWarningConfig: CodeBidiWarningConfig;
15
+ }): JSX.Element;
@@ -0,0 +1,129 @@
1
+ import React from 'react';
2
+ import { SerializedStyles } from '@emotion/react';
3
+ import { AST, RefractorNode } from 'refractor';
4
+ export type { AST, RefractorNode } from 'refractor';
5
+ export declare class SyntaxHighlighter extends React.PureComponent<SyntaxHighlighterProps> {
6
+ }
7
+ /**
8
+ * Function that receives current line number as argument and returns a
9
+ * line props object to be applied to each `span` wrapping code line.
10
+ */
11
+ declare type lineTagPropsFunction = (lineNumber?: number) => AST.Properties;
12
+ /**
13
+ * Props to be passed to the `span` wrapping each code line. Can be an
14
+ * object or a function that receives current line number as argument and
15
+ * returns a props object.
16
+ */
17
+ export declare type SyntaxHighlighterLineProps = lineTagPropsFunction | AST.Properties;
18
+ export interface SyntaxHighlighterProps {
19
+ /**
20
+ * A unique string that appears as a data attribute `data-testid`
21
+ * in the rendered code. Serves as a hook for automated tests.
22
+ */
23
+ testId?: string;
24
+ /**
25
+ * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
26
+ * `design-system/code`. Run against language grammars from PrismJS (full list
27
+ * available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
28
+ *
29
+ * When set to "text" will not perform highlighting. If unsupported language
30
+ * provided - code will be treated as "text" with no highlighting.
31
+ * @default 'text'
32
+ */
33
+ language?: string;
34
+ /**
35
+ * Props to be passed to the `span` wrapping each line if
36
+ * `shouldCreateParentElementForLines` is `true`. Can be an object or a function
37
+ * that receives current line number as argument and returns a props object.
38
+ */
39
+ lineProps?: SyntaxHighlighterLineProps;
40
+ /**
41
+ * Props to be passed to the `code` element that is the parent of all lines of code.
42
+ */
43
+ codeTagProps?: React.HTMLProps<HTMLElement>;
44
+ /**
45
+ * Sets whether to display code line numbers or not. Defaults to `true`
46
+ */
47
+ showLineNumbers?: boolean;
48
+ /**
49
+ * Determines whether or not each line of code should be wrapped in a parent
50
+ * element.
51
+ *
52
+ * When set to false, can not take action on an element on the line level,
53
+ * meaning, for example, that props will not be passed down.
54
+ *
55
+ * @default false
56
+ */
57
+ shouldCreateParentElementForLines?: boolean;
58
+ /**
59
+ * Sets whether long lines will create a horizontally scrolling container.
60
+ * When set to `true`, these lines will visually wrap instead.
61
+ *
62
+ * @default false
63
+ */
64
+ shouldWrapLongLines?: boolean;
65
+ /**
66
+ * Serialized styles returned from Emotion's `css()` function.
67
+ */
68
+ styles?: SerializedStyles;
69
+ /**
70
+ * `codeBidiWarnings` is set via a prop on @atlaskit/code/CodeBlock.
71
+ *
72
+ * When set to `false`, disables code decorating with bidi warnings.
73
+ *
74
+ * @default true
75
+ */
76
+ codeBidiWarnings?: CodeBidiWarningConfig['codeBidiWarnings'];
77
+ /**
78
+ * `codeBidiWarningLabel` is set via a prop on @atlaskit/code/CodeBlock.
79
+ *
80
+ * Label for the bidi warning tooltip.
81
+ *
82
+ * @default 'Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.'
83
+ */
84
+ codeBidiWarningLabel?: CodeBidiWarningConfig['codeBidiWarningLabel'];
85
+ /**
86
+ * `codeBidiWarningTooltipEnabled` is set via a prop on @atlaskit/code/CodeBlock.
87
+ *
88
+ * Sets whether to render tooltip with the warning or not.
89
+ * Intended to be disabled when used in a mobile view, such as in the editor via mobile bridge,
90
+ * where the tooltip could end up being cut off or otherwise not work as expected.
91
+ * @default true
92
+ */
93
+ codeBidiWarningTooltipEnabled?: CodeBidiWarningConfig['codeBidiWarningTooltipEnabled'];
94
+ /**
95
+ * Code to render; equivalent of `text` prop on @atlaskit/code/CodeBlock.
96
+ */
97
+ text?: string;
98
+ [spread: string]: any;
99
+ }
100
+ export interface CodeBidiWarningConfig {
101
+ /**
102
+ * `codeBidiWarnings` is set via a prop on @atlaskit/code/CodeBlock.
103
+ *
104
+ * When set to `false`, disables code decorating with bidi warnings.
105
+ * @default true
106
+ */
107
+ codeBidiWarnings?: boolean;
108
+ /**
109
+ * `codeBidiWarningLabel` is set via a prop on @atlaskit/code/CodeBlock.
110
+ *
111
+ * Label for the bidi warning tooltip.
112
+ *
113
+ * @default 'Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.'
114
+ */
115
+ codeBidiWarningLabel?: string;
116
+ /**
117
+ * `codeBidiWarningTooltipEnabled` is set via a prop on @atlaskit/code/CodeBlock.
118
+ *
119
+ * Sets whether to render tooltip with the warning or not.
120
+ * Intended to be disabled when used in a mobile view, such as in the editor via mobile bridge,
121
+ * where the tooltip could end up being cut off or otherwise not work as expected.
122
+ * @default true
123
+ */
124
+ codeBidiWarningTooltipEnabled?: boolean;
125
+ }
126
+ interface IAstGenerator {
127
+ highlight: (code: string, language: string) => RefractorNode[];
128
+ }
129
+ export declare type AstGenerator = IAstGenerator | null;
@@ -7,26 +7,25 @@ export interface CodeProps extends HTMLProps<HTMLElement> {
7
7
  */
8
8
  testId?: string;
9
9
  /**
10
- * Content to be rendered in the inline code block
10
+ * Content to be rendered in the inline code block.
11
11
  */
12
12
  children?: ReactNode;
13
13
  /**
14
- * When false, disables decorating code with bidi warnings
15
- *
16
- * defaults to true
14
+ * When set to `false`, disables code decorating with bidi warnings. Defaults to `true`.
17
15
  */
18
16
  codeBidiWarnings?: boolean;
19
17
  /**
20
- * Labels for the previous and next buttons used in pagination.
21
- * Defaults to `Bidirectional characters change the order that text is rendered. This could be used to obscure malicious code.`.
18
+ Label for the bidi warning tooltip.
19
+
20
+ Defaults to `Bidirectional characters change the order that text is rendered.
21
+ This could be used to obscure malicious code.`
22
22
  */
23
23
  codeBidiWarningLabel?: string;
24
24
  /**
25
- * Defaults to enabled (true)
26
- *
27
- * Intended to be disabled when used in a mobile view, such as in the editor
28
- * via mobile bridge, where the tooltip could end up being cut off of otherwise
29
- * not work as expected.
25
+ * Sets whether to render tooltip with the warning or not. Intended to be
26
+ * disabled when used in a mobile view, such as in the editor via mobile
27
+ * bridge, where the tooltip could end up being cut off or otherwise not work
28
+ * as expected. Defaults to `true`.
30
29
  */
31
30
  codeBidiWarningTooltipEnabled?: boolean;
32
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/code",
3
- "version": "14.4.7",
3
+ "version": "14.5.0",
4
4
  "description": "Code highlights short strings of code snippets inline with body text.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -15,7 +15,6 @@
15
15
  "sideEffects": false,
16
16
  "atlaskit:src": "src/index.tsx",
17
17
  "atlassian": {
18
- "disableProductCI": true,
19
18
  "team": "Design System Team",
20
19
  "releaseModel": "scheduled",
21
20
  "website": {
@@ -29,12 +28,12 @@
29
28
  "dependencies": {
30
29
  "@atlaskit/codemod-utils": "^4.1.0",
31
30
  "@atlaskit/theme": "^12.2.0",
32
- "@atlaskit/tokens": "^0.13.0",
33
- "@atlaskit/tooltip": "^17.6.0",
31
+ "@atlaskit/tokens": "^1.2.0",
32
+ "@atlaskit/tooltip": "^17.7.0",
34
33
  "@babel/runtime": "^7.0.0",
35
34
  "@emotion/react": "^11.7.1",
36
35
  "memoize-one": "^6.0.0",
37
- "react-syntax-highlighter": "^15.4.3"
36
+ "refractor": "^3.6.0"
38
37
  },
39
38
  "peerDependencies": {
40
39
  "react": "^16.8.0"
@@ -42,15 +41,18 @@
42
41
  "devDependencies": {
43
42
  "@atlaskit/button": "^16.5.0",
44
43
  "@atlaskit/docs": "^9.0.0",
44
+ "@atlaskit/ds-explorations": "^2.0.1",
45
45
  "@atlaskit/ds-lib": "^2.1.0",
46
+ "@atlaskit/form": "^8.8.0",
46
47
  "@atlaskit/section-message": "^6.3.0",
47
48
  "@atlaskit/ssr": "*",
49
+ "@atlaskit/toggle": "^12.5.0",
48
50
  "@atlaskit/visual-regression": "*",
49
51
  "@atlaskit/webdriver-runner": "*",
50
52
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
51
53
  "@testing-library/react": "^12.1.5",
52
54
  "@types/jscodeshift": "^0.11.0",
53
- "@types/react-syntax-highlighter": "^13.5.0",
55
+ "@types/refractor": "^3.0.2",
54
56
  "color-contrast-checker": "^1.5.0",
55
57
  "jscodeshift": "^0.13.0",
56
58
  "prismjs": "^1.25.0",
@@ -77,7 +79,10 @@
77
79
  },
78
80
  "@repo/internal": {
79
81
  "design-system": "v1",
80
- "design-tokens": "spacing",
82
+ "design-tokens": [
83
+ "color",
84
+ "spacing"
85
+ ],
81
86
  "dom-events": "use-bind-event-listener",
82
87
  "ui-components": [
83
88
  "lite-mode"
@@ -86,8 +91,7 @@
86
91
  "analytics-next"
87
92
  ],
88
93
  "theming": [
89
- "react-context",
90
- "tokens"
94
+ "react-context"
91
95
  ],
92
96
  "deprecation": "no-deprecated-imports",
93
97
  "styling": [
package/report.api.md CHANGED
@@ -409,6 +409,7 @@ export interface CodeBlockProps {
409
409
  highlightedEndText?: string;
410
410
  highlightedStartText?: string;
411
411
  language?: SupportedLanguages;
412
+ shouldWrapLongLines?: boolean;
412
413
  showLineNumbers?: boolean;
413
414
  testId?: string;
414
415
  text: string;
@@ -1,156 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createBidiWarningRenderer = createBidiWarningRenderer;
8
- exports.createChildren = createChildren;
9
- exports.createClassNameString = createClassNameString;
10
- exports.createStyleObject = createStyleObject;
11
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
- var _react = _interopRequireDefault(require("react"));
14
- var _bidiWarning = _interopRequireDefault(require("./bidi-warning"));
15
- var _bidiWarningDecorator = _interopRequireDefault(require("./bidi-warning/bidi-warning-decorator"));
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
- 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; }
18
- function createBidiWarningRenderer(codeBidiWarningConfig) {
19
- return function bidiWarningRenderer(_ref) {
20
- var rows = _ref.rows,
21
- stylesheet = _ref.stylesheet,
22
- useInlineStyles = _ref.useInlineStyles;
23
- return rows.map(function (node, i) {
24
- return createElement({
25
- node: node,
26
- stylesheet: stylesheet,
27
- useInlineStyles: useInlineStyles,
28
- codeBidiWarningConfig: codeBidiWarningConfig,
29
- key: "code-segement".concat(i)
30
- });
31
- });
32
- };
33
- }
34
-
35
- // Get all possible permutations of all power sets
36
- //
37
- // Super simple, non-algorithmic solution since the
38
- // number of class names will not be greater than 4
39
- function powerSetPermutations(arr) {
40
- var arrLength = arr.length;
41
- if (arrLength === 0 || arrLength === 1) {
42
- return arr;
43
- }
44
- if (arrLength === 2) {
45
- // prettier-ignore
46
- return [arr[0], arr[1], "".concat(arr[0], ".").concat(arr[1]), "".concat(arr[1], ".").concat(arr[0])];
47
- }
48
- if (arrLength === 3) {
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])];
50
- }
51
- if (arrLength >= 4) {
52
- // Currently does not support more than 4 extra
53
- // class names (after `.token` has been removed)
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])];
55
- }
56
- }
57
- var classNameCombinations = {};
58
- function getClassNameCombinations(classNames) {
59
- if (classNames.length === 0 || classNames.length === 1) {
60
- return classNames;
61
- }
62
- var key = classNames.join('.');
63
- if (!classNameCombinations[key]) {
64
- classNameCombinations[key] = powerSetPermutations(classNames);
65
- }
66
- return classNameCombinations[key];
67
- }
68
- function createStyleObject(classNames) {
69
- var elementStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
70
- var stylesheet = arguments.length > 2 ? arguments[2] : undefined;
71
- var nonTokenClassNames = classNames.filter(function (className) {
72
- return className !== 'token';
73
- });
74
- var classNamesCombinations = getClassNameCombinations(nonTokenClassNames);
75
- return classNamesCombinations.reduce(function (styleObject, className) {
76
- return _objectSpread(_objectSpread({}, styleObject), stylesheet[className]);
77
- }, elementStyle);
78
- }
79
- function createClassNameString(classNames) {
80
- return classNames.join(' ');
81
- }
82
- function createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig) {
83
- var childrenCount = 0;
84
- return function (children) {
85
- childrenCount += 1;
86
- return children.map(function (child, i) {
87
- return createElement({
88
- node: child,
89
- stylesheet: stylesheet,
90
- useInlineStyles: useInlineStyles,
91
- codeBidiWarningConfig: codeBidiWarningConfig,
92
- key: "code-segment-".concat(childrenCount, "-").concat(i)
93
- });
94
- });
95
- };
96
- }
97
- function createElement(_ref2) {
98
- var node = _ref2.node,
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;
105
- var properties = node.properties,
106
- type = node.type,
107
- TagName = node.tagName,
108
- value = node.value;
109
- if (type === 'text') {
110
- // occasionally react-syntax-highlighter passes a numeric value when the
111
- // type is text
112
- var textValue = value + '';
113
- var decorated = (0, _bidiWarningDecorator.default)(textValue, function (_ref3) {
114
- var bidiCharacter = _ref3.bidiCharacter,
115
- index = _ref3.index;
116
- return /*#__PURE__*/_react.default.createElement(_bidiWarning.default, {
117
- bidiCharacter: bidiCharacter,
118
- key: index,
119
- label: codeBidiWarningConfig.codeBidiWarningLabel,
120
- tooltipEnabled: codeBidiWarningConfig.codeBidiWarningTooltipEnabled
121
- });
122
- });
123
- return decorated;
124
- } else if (TagName) {
125
- var childrenCreator = createChildren(stylesheet, useInlineStyles, codeBidiWarningConfig);
126
- var props;
127
- if (!useInlineStyles) {
128
- props = _objectSpread(_objectSpread({}, properties), {}, {
129
- className: createClassNameString(properties.className)
130
- });
131
- } else {
132
- var allStylesheetSelectors = Object.keys(stylesheet).reduce(function (classes, selector) {
133
- selector.split('.').forEach(function (className) {
134
- if (!classes.includes(className)) {
135
- classes.push(className);
136
- }
137
- });
138
- return classes;
139
- }, []);
140
-
141
- // For compatibility with older versions of react-syntax-highlighter
142
- var startingClassName = properties.className && properties.className.includes('token') ? ['token'] : [];
143
- var className = properties.className && startingClassName.concat(properties.className.filter(function (className) {
144
- return !allStylesheetSelectors.includes(className);
145
- }));
146
- props = _objectSpread(_objectSpread({}, properties), {}, {
147
- className: createClassNameString(className) || undefined,
148
- style: createStyleObject(properties.className, Object.assign({}, properties.style, style), stylesheet)
149
- });
150
- }
151
- var children = childrenCreator(node.children);
152
- return /*#__PURE__*/_react.default.createElement(TagName, (0, _extends2.default)({
153
- key: key
154
- }, props), children);
155
- }
156
- }