@atlaskit/code 15.3.1 → 15.4.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/code
2
2
 
3
+ ## 15.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#118430](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/118430)
8
+ [`d5fe97a9a6bc1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d5fe97a9a6bc1) -
9
+ Remove remnants of `extract-react-types`.
10
+
11
+ ## 15.4.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#116950](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/116950)
16
+ [`c3908db22d486`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c3908db22d486) -
17
+ CodeBlock supports a new `firstLineNumber` prop, which allows the starting line number to be set
18
+ (defaulting to 1).
19
+
3
20
  ## 15.3.1
4
21
 
5
22
  ### Patch Changes
@@ -30,6 +30,8 @@ var _syntaxHighlighter = _interopRequireDefault(require("./syntax-highlighter"))
30
30
  var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
31
31
  var _ref$showLineNumbers = _ref.showLineNumbers,
32
32
  showLineNumbers = _ref$showLineNumbers === void 0 ? true : _ref$showLineNumbers,
33
+ _ref$firstLineNumber = _ref.firstLineNumber,
34
+ firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
33
35
  _ref$language = _ref.language,
34
36
  providedLanguage = _ref$language === void 0 ? 'text' : _ref$language,
35
37
  _ref$highlight = _ref.highlight,
@@ -47,7 +49,7 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
47
49
  codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT,
48
50
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
49
51
  shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
50
- var numLines = (text || '').split('\n').length;
52
+ var numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
51
53
  var theme = (0, _react.useMemo)(function () {
52
54
  return (0, _styles.getCodeBlockTheme)(numLines);
53
55
  }, [numLines]);
@@ -81,6 +83,7 @@ var CodeBlock = /*#__PURE__*/(0, _react.memo)(function CodeBlock(_ref) {
81
83
  language: languageToUse,
82
84
  css: styles,
83
85
  showLineNumbers: showLineNumbers,
86
+ firstLineNumber: firstLineNumber,
84
87
  lineProps: getLineProps
85
88
  // shouldCreateParentElementForLines is needed to pass down props to each line.
86
89
  // This is necessary for both line highlighting and testId's, as each of
@@ -10,7 +10,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
10
10
  var _react = require("react");
11
11
  var _process = _interopRequireDefault(require("./process"));
12
12
  var _reactRenderer = _interopRequireDefault(require("./react-renderer"));
13
- var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
13
+ var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "firstLineNumber", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
14
14
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
15
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
16
  /**
@@ -33,6 +33,8 @@ var Highlight = /*#__PURE__*/(0, _react.memo)(function Highlight(_ref) {
33
33
  } : _ref$codeTagProps,
34
34
  _ref$showLineNumbers = _ref.showLineNumbers,
35
35
  showLineNumbers = _ref$showLineNumbers === void 0 ? false : _ref$showLineNumbers,
36
+ _ref$firstLineNumber = _ref.firstLineNumber,
37
+ firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
36
38
  _ref$shouldCreatePare = _ref.shouldCreateParentElementForLines,
37
39
  shouldCreateParentElementForLines = _ref$shouldCreatePare === void 0 ? false : _ref$shouldCreatePare,
38
40
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
@@ -76,7 +78,8 @@ var Highlight = /*#__PURE__*/(0, _react.memo)(function Highlight(_ref) {
76
78
  language: language,
77
79
  shouldCreateParentElementForLines: shouldCreateParentElementForLines || !!shouldWrapLongLines,
78
80
  lineProps: lineProps,
79
- showLineNumbers: showLineNumbers
81
+ showLineNumbers: showLineNumbers,
82
+ firstLineNumber: firstLineNumber
80
83
  });
81
84
 
82
85
  // Rows + logic into a renderer
@@ -25,9 +25,11 @@ function processLines(_ref) {
25
25
  language = _ref.language,
26
26
  shouldCreateParentElementForLines = _ref.shouldCreateParentElementForLines,
27
27
  lineProps = _ref.lineProps,
28
- showLineNumbers = _ref.showLineNumbers;
28
+ showLineNumbers = _ref.showLineNumbers,
29
+ _ref$firstLineNumber = _ref.firstLineNumber,
30
+ firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber;
29
31
  var codeTree = (0, _getCodeTree.default)(language, code, astGenerator);
30
- var startingLineNumber = 1;
32
+ var startingLineNumber = firstLineNumber > 0 ? firstLineNumber : 1;
31
33
  var createLine = (0, _createLine.default)(lineProps, shouldCreateParentElementForLines, showLineNumbers);
32
34
  var newTree = [];
33
35
  var lastLineBreakIndex = -1;
@@ -22,6 +22,7 @@ import SyntaxHighlighter from './syntax-highlighter';
22
22
  */
23
23
  const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
24
24
  showLineNumbers = true,
25
+ firstLineNumber = 1,
25
26
  language: providedLanguage = 'text',
26
27
  highlight = '',
27
28
  highlightedStartText = 'Highlight start',
@@ -33,7 +34,7 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
33
34
  codeBidiWarningTooltipEnabled = true,
34
35
  shouldWrapLongLines = false
35
36
  }) {
36
- const numLines = (text || '').split('\n').length;
37
+ const numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
37
38
  const theme = useMemo(() => getCodeBlockTheme(numLines), [numLines]);
38
39
  const getStyles = useMemo(() => getCodeBlockStyles(theme), [theme]);
39
40
  const styles = useMemo(() => css(
@@ -58,6 +59,7 @@ const CodeBlock = /*#__PURE__*/memo(function CodeBlock({
58
59
  language: languageToUse,
59
60
  css: styles,
60
61
  showLineNumbers: showLineNumbers,
62
+ firstLineNumber: firstLineNumber,
61
63
  lineProps: getLineProps
62
64
  // shouldCreateParentElementForLines is needed to pass down props to each line.
63
65
  // This is necessary for both line highlighting and testId's, as each of
@@ -18,6 +18,7 @@ const Highlight = /*#__PURE__*/memo(function Highlight({
18
18
  className: `language-${language}`
19
19
  },
20
20
  showLineNumbers = false,
21
+ firstLineNumber = 1,
21
22
  shouldCreateParentElementForLines = false,
22
23
  shouldWrapLongLines = false,
23
24
  lineProps = {},
@@ -59,7 +60,8 @@ const Highlight = /*#__PURE__*/memo(function Highlight({
59
60
  language,
60
61
  shouldCreateParentElementForLines: shouldCreateParentElementForLines || !!shouldWrapLongLines,
61
62
  lineProps,
62
- showLineNumbers
63
+ showLineNumbers,
64
+ firstLineNumber
63
65
  });
64
66
 
65
67
  // Rows + logic into a renderer
@@ -18,10 +18,11 @@ export default function processLines({
18
18
  language,
19
19
  shouldCreateParentElementForLines,
20
20
  lineProps,
21
- showLineNumbers
21
+ showLineNumbers,
22
+ firstLineNumber = 1
22
23
  }) {
23
24
  const codeTree = getCodeTree(language, code, astGenerator);
24
- const startingLineNumber = 1;
25
+ const startingLineNumber = firstLineNumber > 0 ? firstLineNumber : 1;
25
26
  const createLine = createLineGenerator(lineProps, shouldCreateParentElementForLines, showLineNumbers);
26
27
  const newTree = [];
27
28
  let lastLineBreakIndex = -1;
@@ -23,6 +23,8 @@ import SyntaxHighlighter from './syntax-highlighter';
23
23
  var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
24
24
  var _ref$showLineNumbers = _ref.showLineNumbers,
25
25
  showLineNumbers = _ref$showLineNumbers === void 0 ? true : _ref$showLineNumbers,
26
+ _ref$firstLineNumber = _ref.firstLineNumber,
27
+ firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
26
28
  _ref$language = _ref.language,
27
29
  providedLanguage = _ref$language === void 0 ? 'text' : _ref$language,
28
30
  _ref$highlight = _ref.highlight,
@@ -40,7 +42,7 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
40
42
  codeBidiWarningTooltipEnabled = _ref$codeBidiWarningT === void 0 ? true : _ref$codeBidiWarningT,
41
43
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
42
44
  shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
43
- var numLines = (text || '').split('\n').length;
45
+ var numLines = (text || '').split('\n').length + (firstLineNumber > 0 ? firstLineNumber : 1) - 1;
44
46
  var theme = useMemo(function () {
45
47
  return getCodeBlockTheme(numLines);
46
48
  }, [numLines]);
@@ -74,6 +76,7 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
74
76
  language: languageToUse,
75
77
  css: styles,
76
78
  showLineNumbers: showLineNumbers,
79
+ firstLineNumber: firstLineNumber,
77
80
  lineProps: getLineProps
78
81
  // shouldCreateParentElementForLines is needed to pass down props to each line.
79
82
  // This is necessary for both line highlighting and testId's, as each of
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
3
+ var _excluded = ["language", "testId", "text", "codeTagProps", "showLineNumbers", "firstLineNumber", "shouldCreateParentElementForLines", "shouldWrapLongLines", "lineProps", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled", "astGenerator"];
4
4
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
5
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
6
  import { memo } from 'react';
@@ -27,6 +27,8 @@ var Highlight = /*#__PURE__*/memo(function Highlight(_ref) {
27
27
  } : _ref$codeTagProps,
28
28
  _ref$showLineNumbers = _ref.showLineNumbers,
29
29
  showLineNumbers = _ref$showLineNumbers === void 0 ? false : _ref$showLineNumbers,
30
+ _ref$firstLineNumber = _ref.firstLineNumber,
31
+ firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber,
30
32
  _ref$shouldCreatePare = _ref.shouldCreateParentElementForLines,
31
33
  shouldCreateParentElementForLines = _ref$shouldCreatePare === void 0 ? false : _ref$shouldCreatePare,
32
34
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
@@ -70,7 +72,8 @@ var Highlight = /*#__PURE__*/memo(function Highlight(_ref) {
70
72
  language: language,
71
73
  shouldCreateParentElementForLines: shouldCreateParentElementForLines || !!shouldWrapLongLines,
72
74
  lineProps: lineProps,
73
- showLineNumbers: showLineNumbers
75
+ showLineNumbers: showLineNumbers,
76
+ firstLineNumber: firstLineNumber
74
77
  });
75
78
 
76
79
  // Rows + logic into a renderer
@@ -18,9 +18,11 @@ export default function processLines(_ref) {
18
18
  language = _ref.language,
19
19
  shouldCreateParentElementForLines = _ref.shouldCreateParentElementForLines,
20
20
  lineProps = _ref.lineProps,
21
- showLineNumbers = _ref.showLineNumbers;
21
+ showLineNumbers = _ref.showLineNumbers,
22
+ _ref$firstLineNumber = _ref.firstLineNumber,
23
+ firstLineNumber = _ref$firstLineNumber === void 0 ? 1 : _ref$firstLineNumber;
22
24
  var codeTree = getCodeTree(language, code, astGenerator);
23
- var startingLineNumber = 1;
25
+ var startingLineNumber = firstLineNumber > 0 ? firstLineNumber : 1;
24
26
  var createLine = createLineGenerator(lineProps, shouldCreateParentElementForLines, showLineNumbers);
25
27
  var newTree = [];
26
28
  var lastLineBreakIndex = -1;
@@ -14,6 +14,11 @@ export interface CodeBlockProps {
14
14
  * @default true
15
15
  */
16
16
  showLineNumbers?: boolean;
17
+ /**
18
+ * Sets the number of the first line, if showLineNumbers is set to true.
19
+ * @default 1
20
+ */
21
+ firstLineNumber?: number;
17
22
  /**
18
23
  * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
19
24
  * `design-system/code`. Run against language grammars from PrismJS (full list
@@ -6,6 +6,7 @@ interface ProcessLines {
6
6
  shouldCreateParentElementForLines: boolean;
7
7
  lineProps: SyntaxHighlighterLineProps;
8
8
  showLineNumbers: boolean;
9
+ firstLineNumber?: number;
9
10
  }
10
11
  /**
11
12
  * __Line Processor__
@@ -13,5 +14,5 @@ interface ProcessLines {
13
14
  * A line processor, that uses refractor to turn code into a tree structure
14
15
  * with highlighting metadata and collapses this tree into lines for a renderer.
15
16
  */
16
- export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, }: ProcessLines): RefractorNode[];
17
+ export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, firstLineNumber, }: ProcessLines): RefractorNode[];
17
18
  export {};
@@ -45,6 +45,11 @@ export interface SyntaxHighlighterProps {
45
45
  * Sets whether to display code line numbers or not. Defaults to `true`
46
46
  */
47
47
  showLineNumbers?: boolean;
48
+ /**
49
+ * Sets the number of the first line, if showLineNumbers is set to true.
50
+ * @default 1
51
+ */
52
+ firstLineNumber?: number;
48
53
  /**
49
54
  * Determines whether or not each line of code should be wrapped in a parent
50
55
  * element.
@@ -14,6 +14,11 @@ export interface CodeBlockProps {
14
14
  * @default true
15
15
  */
16
16
  showLineNumbers?: boolean;
17
+ /**
18
+ * Sets the number of the first line, if showLineNumbers is set to true.
19
+ * @default 1
20
+ */
21
+ firstLineNumber?: number;
17
22
  /**
18
23
  * Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
19
24
  * `design-system/code`. Run against language grammars from PrismJS (full list
@@ -6,6 +6,7 @@ interface ProcessLines {
6
6
  shouldCreateParentElementForLines: boolean;
7
7
  lineProps: SyntaxHighlighterLineProps;
8
8
  showLineNumbers: boolean;
9
+ firstLineNumber?: number;
9
10
  }
10
11
  /**
11
12
  * __Line Processor__
@@ -13,5 +14,5 @@ interface ProcessLines {
13
14
  * A line processor, that uses refractor to turn code into a tree structure
14
15
  * with highlighting metadata and collapses this tree into lines for a renderer.
15
16
  */
16
- export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, }: ProcessLines): RefractorNode[];
17
+ export default function processLines({ astGenerator, code, language, shouldCreateParentElementForLines, lineProps, showLineNumbers, firstLineNumber, }: ProcessLines): RefractorNode[];
17
18
  export {};
@@ -45,6 +45,11 @@ export interface SyntaxHighlighterProps {
45
45
  * Sets whether to display code line numbers or not. Defaults to `true`
46
46
  */
47
47
  showLineNumbers?: boolean;
48
+ /**
49
+ * Sets the number of the first line, if showLineNumbers is set to true.
50
+ * @default 1
51
+ */
52
+ firstLineNumber?: number;
48
53
  /**
49
54
  * Determines whether or not each line of code should be wrapped in a parent
50
55
  * element.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/code",
3
- "version": "15.3.1",
3
+ "version": "15.4.1",
4
4
  "description": "Code highlights short strings of code snippets inline with body text.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = CodeBlock;
7
- // below type is redeclared from ../types to appease ERT
8
- function CodeBlock(__) {
9
- return null;
10
- }
@@ -1,4 +0,0 @@
1
- // below type is redeclared from ../types to appease ERT
2
- export default function CodeBlock(__) {
3
- return null;
4
- }
@@ -1,4 +0,0 @@
1
- // below type is redeclared from ../types to appease ERT
2
- export default function CodeBlock(__) {
3
- return null;
4
- }
@@ -1,47 +0,0 @@
1
- export default function CodeBlock(__: {
2
- /**
3
- * The code to be formatted.
4
- */
5
- text: string;
6
- /**
7
- * A unique string that appears as a data attribute `data-testid` in the rendered code. Serves as a hook for automated tests.
8
- */
9
- testId?: string;
10
- /**
11
- * Sets whether to display code line numbers or not. Defaults to `true`.
12
- */
13
- showLineNumbers?: boolean;
14
- /**
15
- Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
16
- `design-system/code`. Run against language grammars from PrismJS (full list
17
- available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
18
-
19
- When set to `text` will not perform highlighting. If unsupported language
20
- provided - code will be treated as "text" with no highlighting.
21
-
22
- Defaults to `text`.
23
- */
24
- language?: string;
25
- /**
26
- Comma delimited lines to highlight.
27
-
28
- Example uses:
29
- - To highlight one line `highlight="3"`
30
- - To highlight a group of lines `highlight="1-5"`
31
- - To highlight multiple groups `highlight="1-5,7,10,15-20"`
32
- */
33
- highlight?: string;
34
- /**
35
- * Screen reader text for the start of a highlighted line.
36
- */
37
- highlightedStartText?: string;
38
- /**
39
- * Screen reader text for the end of a highlighted line.
40
- */
41
- highlightedEndText?: string;
42
- /**
43
- * Sets whether long lines will create a horizontally scrolling container.
44
- * When set to `true`, these lines will visually wrap instead. Defaults to `false`.
45
- */
46
- shouldWrapLongLines?: boolean;
47
- }): null;
@@ -1,47 +0,0 @@
1
- export default function CodeBlock(__: {
2
- /**
3
- * The code to be formatted.
4
- */
5
- text: string;
6
- /**
7
- * A unique string that appears as a data attribute `data-testid` in the rendered code. Serves as a hook for automated tests.
8
- */
9
- testId?: string;
10
- /**
11
- * Sets whether to display code line numbers or not. Defaults to `true`.
12
- */
13
- showLineNumbers?: boolean;
14
- /**
15
- Language reference designed to be populated from `SUPPORTED_LANGUAGES` in
16
- `design-system/code`. Run against language grammars from PrismJS (full list
17
- available at [PrismJS documentation](https://prismjs.com/#supported-languages)).
18
-
19
- When set to `text` will not perform highlighting. If unsupported language
20
- provided - code will be treated as "text" with no highlighting.
21
-
22
- Defaults to `text`.
23
- */
24
- language?: string;
25
- /**
26
- Comma delimited lines to highlight.
27
-
28
- Example uses:
29
- - To highlight one line `highlight="3"`
30
- - To highlight a group of lines `highlight="1-5"`
31
- - To highlight multiple groups `highlight="1-5,7,10,15-20"`
32
- */
33
- highlight?: string;
34
- /**
35
- * Screen reader text for the start of a highlighted line.
36
- */
37
- highlightedStartText?: string;
38
- /**
39
- * Screen reader text for the end of a highlighted line.
40
- */
41
- highlightedEndText?: string;
42
- /**
43
- * Sets whether long lines will create a horizontally scrolling container.
44
- * When set to `true`, these lines will visually wrap instead. Defaults to `false`.
45
- */
46
- shouldWrapLongLines?: boolean;
47
- }): null;