@atlaskit/code 15.2.0 → 15.3.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 (69) hide show
  1. package/CHANGELOG.md +653 -645
  2. package/__perf__/code-block-syntax-highlighting.tsx +4 -1
  3. package/__perf__/source-code-examples/100-line-example.tsx +52 -40
  4. package/codemods/13.0.0-remove-unnecessary-code-props.tsx +61 -75
  5. package/codemods/13.0.0-rename-imports.tsx +214 -251
  6. package/codemods/14.0.0-lite-mode.tsx +5 -9
  7. package/codemods/__tests__/13.0.0-remove-unnecessary-code-props.tsx +43 -43
  8. package/codemods/__tests__/13.0.0-rename-imports.tsx +143 -143
  9. package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.tsx +35 -35
  10. package/codemods/__tests__/14.0.0-lite-mode/remove-language.tsx +21 -21
  11. package/codemods/__tests__/14.0.0-lite-mode/text-to-child.tsx +35 -35
  12. package/codemods/migrations/14.0.0-lite-mode/remove-language.tsx +1 -6
  13. package/codemods/migrations/14.0.0-lite-mode/text-to-child.tsx +53 -61
  14. package/codemods/utils/helpers.tsx +161 -201
  15. package/dist/cjs/bidi-warning/ui/styled.js +7 -0
  16. package/dist/cjs/code-block.js +8 -1
  17. package/dist/cjs/code.js +5 -0
  18. package/dist/cjs/internal/theme/styles.js +3 -2
  19. package/dist/cjs/syntax-highlighter/types.js +1 -0
  20. package/dist/es2019/bidi-warning/ui/styled.js +7 -0
  21. package/dist/es2019/code-block.js +8 -1
  22. package/dist/es2019/code.js +6 -0
  23. package/dist/es2019/internal/theme/styles.js +4 -1
  24. package/dist/es2019/syntax-highlighter/types.js +3 -0
  25. package/dist/esm/bidi-warning/ui/styled.js +7 -0
  26. package/dist/esm/code-block.js +8 -1
  27. package/dist/esm/code.js +6 -0
  28. package/dist/esm/internal/theme/styles.js +4 -1
  29. package/dist/esm/syntax-highlighter/types.js +3 -0
  30. package/dist/types/bidi-warning/ui/index.d.ts +1 -1
  31. package/dist/types/bidi-warning/ui/styled.d.ts +4 -1
  32. package/dist/types/code.d.ts +3 -0
  33. package/dist/types/extract-react-types/code-block.d.ts +16 -16
  34. package/dist/types/internal/hooks/use-highlight.d.ts +1 -1
  35. package/dist/types/internal/utils/get-normalized-language.d.ts +1 -1
  36. package/dist/types/syntax-highlighter/async.d.ts +1 -1
  37. package/dist/types/syntax-highlighter/lib/highlight.d.ts +1 -1
  38. package/dist/types/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
  39. package/dist/types/syntax-highlighter/lib/process/create-line.d.ts +1 -1
  40. package/dist/types/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
  41. package/dist/types/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
  42. package/dist/types/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
  43. package/dist/types/syntax-highlighter/lib/process/index.d.ts +1 -1
  44. package/dist/types/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
  45. package/dist/types/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
  46. package/dist/types/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
  47. package/dist/types/syntax-highlighter/types.d.ts +2 -2
  48. package/dist/types/types.d.ts +1 -1
  49. package/dist/types-ts4.5/bidi-warning/ui/index.d.ts +1 -1
  50. package/dist/types-ts4.5/bidi-warning/ui/styled.d.ts +4 -1
  51. package/dist/types-ts4.5/code.d.ts +3 -0
  52. package/dist/types-ts4.5/extract-react-types/code-block.d.ts +16 -16
  53. package/dist/types-ts4.5/internal/hooks/use-highlight.d.ts +1 -1
  54. package/dist/types-ts4.5/internal/utils/get-normalized-language.d.ts +1 -1
  55. package/dist/types-ts4.5/syntax-highlighter/async.d.ts +1 -1
  56. package/dist/types-ts4.5/syntax-highlighter/lib/highlight.d.ts +1 -1
  57. package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
  58. package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line.d.ts +1 -1
  59. package/dist/types-ts4.5/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
  60. package/dist/types-ts4.5/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
  61. package/dist/types-ts4.5/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
  62. package/dist/types-ts4.5/syntax-highlighter/lib/process/index.d.ts +1 -1
  63. package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
  64. package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
  65. package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
  66. package/dist/types-ts4.5/syntax-highlighter/types.d.ts +2 -2
  67. package/dist/types-ts4.5/types.d.ts +1 -1
  68. package/package.json +108 -110
  69. package/report.api.md +807 -807
@@ -2,7 +2,10 @@ import React from 'react';
2
2
 
3
3
  import { CodeBlock } from '../src';
4
4
 
5
- export const text = `/** @jsx jsx */
5
+ export const text = `/**
6
+ * @jsxRuntime classic
7
+ */
8
+ /** @jsx jsx */
6
9
  import React from 'react';
7
10
  import ReactDOM from 'react-dom';
8
11
  import styled from '@emotion/styled';
@@ -1,16 +1,26 @@
1
1
  // eslint-disable-file
2
2
  export const hundredLineExample = `/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
3
+ /**
4
+ * @jsxRuntime classic
5
+ */
3
6
  /** @jsx jsx */
4
- import React, { forwardRef, useMemo } from 'react';
7
+ import React, { CSSProperties, forwardRef } from 'react';
5
8
 
6
9
  import { css, jsx } from '@emotion/react';
7
10
 
8
- import { UNSAFE_Box as Box, UNSAFE_BoxProps as BoxProps, UNSAFE_Inline as Inline, UNSAFE_Text as Text, UNSAFE_TextProps as TextProps, } from '@atlaskit/ds-explorations';
11
+ import { BackgroundColor, Box, Inline, xcss } from '@atlaskit/primitives';
9
12
  import { N0, N500, N700, R400, Y300 } from '@atlaskit/theme/colors';
10
13
  import { token } from '@atlaskit/tokens';
11
14
 
12
- // Applies styles to nested links within banner messages.
13
- const nestedLinkStyles = css({
15
+ const CSS_VAR_TEXT_COLOR = '--banner-text-color';
16
+
17
+ const textStyles = css({
18
+ color: \`var(\${CSS_VAR_TEXT_COLOR})\`,
19
+ fontWeight: token('font.weight.medium', '500'),
20
+ lineHeight: token('font.lineHeight.300', '24px'),
21
+ overflow: 'hidden',
22
+ textOverflow: 'ellipsis',
23
+ whiteSpace: 'nowrap',
14
24
  // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
15
25
  'a, a:visited, a:hover, a:focus, a:active': {
16
26
  color: 'currentColor',
@@ -18,10 +28,10 @@ const nestedLinkStyles = css({
18
28
  },
19
29
  });
20
30
 
21
- const backgroundColors: Record<Appearance, BoxProps['backgroundColor']> = {
22
- warning: 'warning.bold',
23
- error: 'danger.bold',
24
- announcement: 'neutral.bold',
31
+ const backgroundColors: Record<Appearance, BackgroundColor> = {
32
+ warning: 'color.background.warning.bold',
33
+ error: 'color.background.danger.bold',
34
+ announcement: 'color.background.neutral.bold',
25
35
  };
26
36
 
27
37
  const tokenBackgroundColors: Record<Appearance, string> = {
@@ -30,12 +40,6 @@ const tokenBackgroundColors: Record<Appearance, string> = {
30
40
  announcement: token('color.background.neutral.bold', N500),
31
41
  };
32
42
 
33
- const textColors: Record<Appearance, TextProps['color']> = {
34
- warning: 'warning.inverse',
35
- error: 'inverse',
36
- announcement: 'inverse',
37
- };
38
-
39
43
  const tokenTextColors: Record<Appearance, string> = {
40
44
  warning: token('color.text.warning.inverse', N700),
41
45
  error: token('color.text.inverse', N0),
@@ -44,7 +48,19 @@ const tokenTextColors: Record<Appearance, string> = {
44
48
 
45
49
  type Appearance = 'warning' | 'error' | 'announcement';
46
50
 
47
- interface BannerProps {
51
+ const containerStyles = xcss({
52
+ overflow: 'hidden',
53
+ maxHeight: 'size.500',
54
+ });
55
+
56
+ const iconWrapperStyles = xcss({
57
+ display: 'block',
58
+ width: 'size.200',
59
+ height: 'size.200', // This matches Icon's "medium" size, without this the (line-)height is greater than that of the Icon
60
+ flexShrink: '0',
61
+ });
62
+
63
+ export interface BannerProps {
48
64
  appearance?: Appearance;
49
65
  children?: React.ReactNode;
50
66
  icon?: React.ReactElement;
@@ -56,42 +72,38 @@ const Banner = forwardRef<HTMLDivElement, BannerProps>(
56
72
  const appearanceType =
57
73
  appearance in backgroundColors ? appearance : 'warning';
58
74
 
59
- const accessibilityProps = useMemo(() => {
60
- const baseProps = {
61
- role: 'alert',
62
- };
63
-
64
- if (appearance === 'announcement') {
65
- return {
66
- ...baseProps,
67
- 'aria-label': 'announcement',
68
- tabIndex: 0,
69
- role: 'region',
70
- };
71
- }
72
-
73
- return baseProps;
74
- }, [appearance]);
75
-
76
75
  return (
77
- <Box display="block" backgroundColor={backgroundColors[appearanceType]} paddingInline="space.150" overflow="hidden" testId={testId} ref={ref} {...accessibilityProps} UNSAFE_style={{ paddingBlock: '14px', maxHeight: '52px', }} css={nestedLinkStyles} >
78
- <Inline gap="space.050" alignItems="center" justifyContent="start">
76
+ <Box
77
+ xcss={containerStyles}
78
+ backgroundColor={backgroundColors[appearanceType]}
79
+ padding="space.150"
80
+ testId={testId}
81
+ ref={ref}
82
+ role="alert"
83
+ >
84
+ <Inline space="space.050" alignBlock="center" alignInline="start">
79
85
  {icon ? (
80
86
  <Box
81
87
  as="span"
82
- display="inline"
83
- width="size.300"
84
- height="size.300" // This matches Icon's "medium" size, without this the (line-)height is greater than that of the Icon
85
- UNSAFE_style={{
88
+ xcss={iconWrapperStyles}
89
+ style={{
86
90
  fill: tokenBackgroundColors[appearanceType],
87
91
  color: tokenTextColors[appearanceType],
88
- flexShrink: 0,
89
92
  }}
90
93
  >
91
94
  {icon}
92
95
  </Box>
93
96
  ) : null}
94
- <Text fontWeight="medium" lineHeight="lineHeight.300" color={textColors[appearanceType]} shouldTruncate> {children} </Text>
97
+ <span
98
+ style={
99
+ {
100
+ [CSS_VAR_TEXT_COLOR]: tokenTextColors[appearanceType],
101
+ } as CSSProperties
102
+ }
103
+ css={textStyles}
104
+ >
105
+ {children}
106
+ </span>
95
107
  </Inline>
96
108
  </Box>
97
109
  );
@@ -1,98 +1,84 @@
1
- import { API, FileInfo, JSCodeshift, Options } from 'jscodeshift';
2
- import { Collection } from 'jscodeshift/src/Collection';
1
+ import { type API, type FileInfo, type JSCodeshift, type Options } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
3
 
4
4
  import {
5
- getImportDeclarationCollection,
6
- getImportSpecifierCollection,
7
- getImportSpecifierName,
8
- getJSXAttributesByName,
9
- getJSXSpreadIdentifierAttributesByName,
10
- getJSXSpreadObjectExpressionAttributesByName,
11
- hasImportDeclaration,
5
+ getImportDeclarationCollection,
6
+ getImportSpecifierCollection,
7
+ getImportSpecifierName,
8
+ getJSXAttributesByName,
9
+ getJSXSpreadIdentifierAttributesByName,
10
+ getJSXSpreadObjectExpressionAttributesByName,
11
+ hasImportDeclaration,
12
12
  } from './utils/helpers';
13
13
 
14
14
  const importPath = '@atlaskit/code';
15
15
  const importName = 'Code';
16
- const propsToBeRemoved = [
17
- 'lineNumberContainerStyle',
18
- 'showLineNumbers',
19
- 'highlight',
20
- ];
16
+ const propsToBeRemoved = ['lineNumberContainerStyle', 'showLineNumbers', 'highlight'];
21
17
 
22
18
  function removeProps(
23
- j: JSCodeshift,
24
- collection: Collection<any>,
25
- elementName: string,
26
- propName: string,
19
+ j: JSCodeshift,
20
+ collection: Collection<any>,
21
+ elementName: string,
22
+ propName: string,
27
23
  ) {
28
- collection.findJSXElements(elementName).forEach((jsxElementPath) => {
29
- const jsxAttributeCollection = getJSXAttributesByName(
30
- j,
31
- jsxElementPath,
32
- propName,
33
- );
34
- if (jsxAttributeCollection) {
35
- jsxAttributeCollection.remove();
36
- }
24
+ collection.findJSXElements(elementName).forEach((jsxElementPath) => {
25
+ const jsxAttributeCollection = getJSXAttributesByName(j, jsxElementPath, propName);
26
+ if (jsxAttributeCollection) {
27
+ jsxAttributeCollection.remove();
28
+ }
37
29
 
38
- const jsxSpreadIdentifierPropertyCollection =
39
- getJSXSpreadIdentifierAttributesByName(
40
- j,
41
- collection,
42
- jsxElementPath,
43
- propName,
44
- );
45
- if (jsxSpreadIdentifierPropertyCollection) {
46
- jsxSpreadIdentifierPropertyCollection.remove();
47
- }
30
+ const jsxSpreadIdentifierPropertyCollection = getJSXSpreadIdentifierAttributesByName(
31
+ j,
32
+ collection,
33
+ jsxElementPath,
34
+ propName,
35
+ );
36
+ if (jsxSpreadIdentifierPropertyCollection) {
37
+ jsxSpreadIdentifierPropertyCollection.remove();
38
+ }
48
39
 
49
- const jsxSpreadExpressionPropertyCollection =
50
- getJSXSpreadObjectExpressionAttributesByName(j, jsxElementPath, propName);
51
- if (jsxSpreadExpressionPropertyCollection) {
52
- jsxSpreadExpressionPropertyCollection.remove();
53
- }
54
- });
40
+ const jsxSpreadExpressionPropertyCollection = getJSXSpreadObjectExpressionAttributesByName(
41
+ j,
42
+ jsxElementPath,
43
+ propName,
44
+ );
45
+ if (jsxSpreadExpressionPropertyCollection) {
46
+ jsxSpreadExpressionPropertyCollection.remove();
47
+ }
48
+ });
55
49
  }
56
50
 
57
51
  function removePropsForImportSpecifiers(
58
- j: JSCodeshift,
59
- collection: Collection<any>,
60
- propName: string,
52
+ j: JSCodeshift,
53
+ collection: Collection<any>,
54
+ propName: string,
61
55
  ) {
62
- const importDeclarationCollection = getImportDeclarationCollection(
63
- j,
64
- collection,
65
- importPath,
66
- );
67
- const importSpecifierCollection = getImportSpecifierCollection(
68
- j,
69
- importDeclarationCollection,
70
- importName,
71
- );
72
- const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
56
+ const importDeclarationCollection = getImportDeclarationCollection(j, collection, importPath);
57
+ const importSpecifierCollection = getImportSpecifierCollection(
58
+ j,
59
+ importDeclarationCollection,
60
+ importName,
61
+ );
62
+ const importSpecifierName = getImportSpecifierName(importSpecifierCollection);
73
63
 
74
- if (importSpecifierName === null) {
75
- return;
76
- }
64
+ if (importSpecifierName === null) {
65
+ return;
66
+ }
77
67
 
78
- removeProps(j, collection, importSpecifierName, propName);
68
+ removeProps(j, collection, importSpecifierName, propName);
79
69
  }
80
70
 
81
- export default function transformer(
82
- fileInfo: FileInfo,
83
- { jscodeshift: j }: API,
84
- options: Options,
85
- ) {
86
- const { source } = fileInfo;
87
- const collection = j(source);
71
+ export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
72
+ const { source } = fileInfo;
73
+ const collection = j(source);
88
74
 
89
- if (!hasImportDeclaration(j, collection, importPath)) {
90
- return source;
91
- }
75
+ if (!hasImportDeclaration(j, collection, importPath)) {
76
+ return source;
77
+ }
92
78
 
93
- propsToBeRemoved.forEach((propToRemove) => {
94
- removePropsForImportSpecifiers(j, collection, propToRemove);
95
- });
79
+ propsToBeRemoved.forEach((propToRemove) => {
80
+ removePropsForImportSpecifiers(j, collection, propToRemove);
81
+ });
96
82
 
97
- return collection.toSource(options.printOptions || { quote: 'single' });
83
+ return collection.toSource(options.printOptions || { quote: 'single' });
98
84
  }