@atlaskit/code 14.6.9 → 15.1.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.
@@ -1,228 +1,69 @@
1
1
  import memoizeOne from 'memoize-one';
2
2
  import * as colors from '@atlaskit/theme/colors';
3
- import { themed } from '@atlaskit/theme/components';
4
3
  import { codeFontFamily } from '@atlaskit/theme/constants';
5
4
  // Hardcoded values have been used due to the current color palette not having any
6
5
  // accessible color options for Teal and Yellow and +20A
7
6
  const T800 = '#067384';
8
7
  const Y1100 = '#7A5D1A';
9
- const PLUS20 = '#3A434E';
10
- export const getBaseTheme = theme => ({
8
+ export const getBaseTheme = () => ({
11
9
  fontFamily: codeFontFamily(),
12
10
  fontFamilyItalic: `SFMono-MediumItalic, ${codeFontFamily()}`,
13
- backgroundColor: themed({
14
- light: `var(--ds-background-neutral, ${colors.N20})`,
15
- dark: `var(--ds-background-neutral, ${colors.DN50})`
16
- })({
17
- theme
18
- }),
19
- textColor: themed({
20
- light: `var(--ds-text, ${colors.N800})`,
21
- dark: `var(--ds-text, ${colors.DN800})`
22
- })({
23
- theme
24
- }),
25
- lineNumberColor: themed({
26
- light: `var(--ds-text-subtlest, ${colors.N400})`,
27
- dark: `var(--ds-text-subtlest, ${colors.DN400})`
28
- })({
29
- theme
30
- }),
31
- lineNumberBgColor: themed({
32
- light: `var(--ds-background-neutral, ${colors.N30})`,
33
- dark: `var(--ds-background-neutral, ${colors.DN20})`
34
- })({
35
- theme
36
- })
11
+ backgroundColor: `var(--ds-background-neutral, ${colors.N20})`,
12
+ textColor: `var(--ds-text, ${colors.N800})`,
13
+ lineNumberColor: `var(--ds-text-subtlest, ${colors.N400})`,
14
+ lineNumberBgColor: `var(--ds-background-neutral, ${colors.N30})`
37
15
  });
38
- export const defaultBaseTheme = getBaseTheme({
39
- mode: 'light'
40
- });
41
- export const getColorPalette = memoizeOne(theme => {
42
- const akTheme = {
43
- theme
44
- };
16
+ export const defaultBaseTheme = getBaseTheme();
17
+ export const getColorPalette = memoizeOne(() => {
45
18
  return {
46
- highlightedLineBgColor: themed({
47
- light: `var(--ds-background-neutral, ${colors.N30})`,
48
- dark: `var(--ds-background-neutral, ${PLUS20})`
49
- })(akTheme),
50
- highlightedLineBorderColor: themed({
51
- light: `var(--ds-border-focused, ${colors.B200})`,
52
- dark: `var(--ds-border-focused, ${colors.B100})`
53
- })(akTheme),
54
- substringColor: themed({
55
- light: `var(--ds-text-subtlest, ${colors.N400})`,
56
- dark: `var(--ds-text-subtlest, ${colors.DN400})`
57
- })(akTheme),
58
- keywordColor: themed({
59
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
60
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
61
- })(akTheme),
62
- attributeColor: themed({
63
- light: `var(--ds-text-accent-teal, ${T800})`,
64
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
65
- })(akTheme),
66
- selectorTagColor: themed({
67
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
68
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
69
- })(akTheme),
70
- docTagColor: themed({
71
- light: `var(--ds-text-accent-yellow, ${Y1100})`,
72
- dark: `var(--ds-text-accent-yellow, ${colors.Y300})`
73
- })(akTheme),
74
- nameColor: themed({
75
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
76
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
77
- })(akTheme),
78
- builtInColor: themed({
79
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
80
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
81
- })(akTheme),
82
- literalColor: themed({
83
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
84
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
85
- })(akTheme),
86
- bulletColor: themed({
87
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
88
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
89
- })(akTheme),
90
- codeColor: themed({
91
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
92
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
93
- })(akTheme),
94
- regexpColor: themed({
95
- light: `var(--ds-text-accent-teal, ${T800})`,
96
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
97
- })(akTheme),
98
- symbolColor: themed({
99
- light: `var(--ds-text-accent-teal, ${T800})`,
100
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
101
- })(akTheme),
102
- variableColor: themed({
103
- light: `var(--ds-text-accent-teal, ${T800})`,
104
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
105
- })(akTheme),
106
- templateVariableColor: themed({
107
- light: `var(--ds-text-accent-teal, ${T800})`,
108
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
109
- })(akTheme),
110
- linkColor: themed({
111
- light: `var(--ds-text-accent-purple, ${colors.P300})`,
112
- dark: `var(--ds-text-accent-purple, ${colors.P75})`
113
- })(akTheme),
114
- selectorAttributeColor: themed({
115
- light: `var(--ds-text-accent-teal, ${T800})`,
116
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
117
- })(akTheme),
118
- selectorPseudoColor: themed({
119
- light: `var(--ds-text-accent-teal, ${T800})`,
120
- dark: `var(--ds-text-accent-teal, ${colors.T200})`
121
- })(akTheme),
122
- typeColor: themed({
123
- light: `var(--ds-text-accent-teal, ${T800})`,
124
- dark: `var(--ds-text-accent-teal, ${colors.T100})`
125
- })(akTheme),
126
- stringColor: themed({
127
- light: `var(--ds-text-accent-green, ${colors.G500})`,
128
- dark: `var(--ds-text-accent-green, ${colors.G200})`
129
- })(akTheme),
130
- selectorIdColor: themed({
131
- light: `var(--ds-text-accent-teal, ${T800})`,
132
- dark: `var(--ds-text-accent-teal, ${colors.T100})`
133
- })(akTheme),
134
- selectorClassColor: themed({
135
- light: `var(--ds-text-accent-teal, ${T800})`,
136
- dark: `var(--ds-text-accent-teal, ${colors.T100})`
137
- })(akTheme),
138
- quoteColor: themed({
139
- light: `var(--ds-text-accent-teal, ${T800})`,
140
- dark: `var(--ds-text-accent-teal, ${colors.T100})`
141
- })(akTheme),
142
- templateTagColor: themed({
143
- light: `var(--ds-text-accent-teal, ${T800})`,
144
- dark: `var(--ds-text-accent-teal, ${colors.T100})`
145
- })(akTheme),
146
- titleColor: themed({
147
- light: `var(--ds-text-accent-purple, ${colors.P300})`,
148
- dark: `var(--ds-text-accent-purple, ${colors.P75})`
149
- })(akTheme),
150
- sectionColor: themed({
151
- light: `var(--ds-text-accent-purple, ${colors.P300})`,
152
- dark: `var(--ds-text-accent-purple, ${colors.P75})`
153
- })(akTheme),
154
- commentColor: themed({
155
- light: `var(--ds-text-subtlest, ${colors.N400})`,
156
- dark: `var(--ds-text-subtlest, ${colors.DN400})`
157
- })(akTheme),
158
- metaKeywordColor: themed({
159
- light: `var(--ds-text-accent-green, ${colors.G500})`,
160
- dark: `var(--ds-text-accent-green, ${colors.G200})`
161
- })(akTheme),
162
- metaColor: themed({
163
- light: `var(--ds-text-subtlest, ${colors.N400})`,
164
- dark: `var(--ds-text-subtlest, ${colors.DN400})`
165
- })(akTheme),
166
- functionColor: themed({
167
- light: `var(--ds-text, ${colors.N800})`,
168
- dark: `var(--ds-text, ${colors.DN800})`
169
- })(akTheme),
170
- numberColor: themed({
171
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
172
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
173
- })(akTheme),
174
- prologColor: themed({
175
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
176
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
177
- })(akTheme),
178
- cdataColor: themed({
179
- light: `var(--ds-text-subtlest, ${colors.N400})`,
180
- dark: `var(--ds-text-subtlest, ${colors.B75})`
181
- })(akTheme),
182
- punctuationColor: themed({
183
- light: `var(--ds-text, ${colors.N800})`,
184
- dark: `var(--ds-text, ${colors.DN800})`
185
- })(akTheme),
186
- propertyColor: themed({
187
- light: `var(--ds-text-accent-purple, ${colors.P300})`,
188
- dark: `var(--ds-text-accent-purple, ${colors.P75})`
189
- })(akTheme),
190
- constantColor: themed({
191
- light: `var(--ds-text-accent-teal, ${T800})`,
192
- dark: `var(--ds-text-accent-teal, ${colors.T100})`
193
- })(akTheme),
194
- booleanColor: themed({
195
- light: `var(--ds-text-accent-blue, ${colors.B400})`,
196
- dark: `var(--ds-text-accent-blue, ${colors.B75})`
197
- })(akTheme),
198
- charColor: themed({
199
- light: `var(--ds-text, ${colors.N800})`,
200
- dark: `var(--ds-text, ${colors.DN800})`
201
- })(akTheme),
202
- insertedColor: themed({
203
- light: `var(--ds-text-accent-green, ${colors.G500})`,
204
- dark: `var(--ds-text-accent-green, ${colors.B75})`
205
- })(akTheme),
206
- deletedColor: themed({
207
- light: `var(--ds-text-accent-red, ${colors.R500})`,
208
- dark: `var(--ds-text-accent-red, ${colors.B75})`
209
- })(akTheme),
210
- operatorColor: themed({
211
- light: `var(--ds-text, ${colors.N800})`,
212
- dark: `var(--ds-text, ${colors.B75})`
213
- })(akTheme),
214
- atruleColor: themed({
215
- light: `var(--ds-text-accent-green, ${colors.G500})`,
216
- dark: `var(--ds-text-accent-green, ${colors.G200})`
217
- })(akTheme),
218
- importantColor: themed({
219
- light: `var(--ds-text-accent-yellow, ${Y1100})`,
220
- dark: `var(--ds-text-accent-yellow, ${colors.Y300})`
221
- })(akTheme)
19
+ highlightedLineBgColor: `var(--ds-background-neutral, ${colors.N30})`,
20
+ highlightedLineBorderColor: `var(--ds-border-focused, ${colors.B200})`,
21
+ substringColor: `var(--ds-text-subtlest, ${colors.N400})`,
22
+ keywordColor: `var(--ds-text-accent-blue, ${colors.B400})`,
23
+ attributeColor: `var(--ds-text-accent-teal, ${T800})`,
24
+ selectorTagColor: `var(--ds-text-accent-blue, ${colors.B400})`,
25
+ docTagColor: `var(--ds-text-accent-yellow, ${Y1100})`,
26
+ nameColor: `var(--ds-text-accent-blue, ${colors.B400})`,
27
+ builtInColor: `var(--ds-text-accent-blue, ${colors.B400})`,
28
+ literalColor: `var(--ds-text-accent-blue, ${colors.B400})`,
29
+ bulletColor: `var(--ds-text-accent-blue, ${colors.B400})`,
30
+ codeColor: `var(--ds-text-accent-blue, ${colors.B400})`,
31
+ regexpColor: `var(--ds-text-accent-teal, ${T800})`,
32
+ symbolColor: `var(--ds-text-accent-teal, ${T800})`,
33
+ variableColor: `var(--ds-text-accent-teal, ${T800})`,
34
+ templateVariableColor: `var(--ds-text-accent-teal, ${T800})`,
35
+ linkColor: `var(--ds-text-accent-purple, ${colors.P300})`,
36
+ selectorAttributeColor: `var(--ds-text-accent-teal, ${T800})`,
37
+ selectorPseudoColor: `var(--ds-text-accent-teal, ${T800})`,
38
+ typeColor: `var(--ds-text-accent-teal, ${T800})`,
39
+ stringColor: `var(--ds-text-accent-green, ${colors.G500})`,
40
+ selectorIdColor: `var(--ds-text-accent-teal, ${T800})`,
41
+ selectorClassColor: `var(--ds-text-accent-teal, ${T800})`,
42
+ quoteColor: `var(--ds-text-accent-teal, ${T800})`,
43
+ templateTagColor: `var(--ds-text-accent-teal, ${T800})`,
44
+ titleColor: `var(--ds-text-accent-purple, ${colors.P300})`,
45
+ sectionColor: `var(--ds-text-accent-purple, ${colors.P300})`,
46
+ commentColor: `var(--ds-text-subtlest, ${colors.N400})`,
47
+ metaKeywordColor: `var(--ds-text-accent-green, ${colors.G500})`,
48
+ metaColor: `var(--ds-text-subtlest, ${colors.N400})`,
49
+ functionColor: `var(--ds-text, ${colors.N800})`,
50
+ numberColor: `var(--ds-text-accent-blue, ${colors.B400})`,
51
+ prologColor: `var(--ds-text-accent-blue, ${colors.B400})`,
52
+ cdataColor: `var(--ds-text-subtlest, ${colors.N400})`,
53
+ punctuationColor: `var(--ds-text, ${colors.N800})`,
54
+ propertyColor: `var(--ds-text-accent-purple, ${colors.P300})`,
55
+ constantColor: `var(--ds-text-accent-teal, ${T800})`,
56
+ booleanColor: `var(--ds-text-accent-blue, ${colors.B400})`,
57
+ charColor: `var(--ds-text, ${colors.N800})`,
58
+ insertedColor: `var(--ds-text-accent-green, ${colors.G500})`,
59
+ deletedColor: `var(--ds-text-accent-red, ${colors.R500})`,
60
+ operatorColor: `var(--ds-text, ${colors.N800})`,
61
+ atruleColor: `var(--ds-text-accent-green, ${colors.G500})`,
62
+ importantColor: `var(--ds-text-accent-yellow, ${Y1100})`
222
63
  };
223
64
  });
224
- const getTheme = theme => ({
225
- ...getBaseTheme(theme),
226
- ...getColorPalette(theme)
65
+ const getTheme = () => ({
66
+ ...getBaseTheme(),
67
+ ...getColorPalette()
227
68
  });
228
69
  export default getTheme;
@@ -1,4 +1,3 @@
1
- import { borderRadius } from '@atlaskit/theme/constants';
2
1
  import { CODE_FONT_SIZE, CODE_LINE_HEIGHT, HIGHLIGHT_BORDER_WIDTH, LINE_NUMBER_GUTTER, SPACING, VAR_CODE_BG_COLOR, VAR_CODE_LINE_NUMBER_BG_COLOR } from './constants';
3
2
  import { getBaseTheme, getColorPalette } from './get-theme';
4
3
  export const getLineNumWidth = numLines => {
@@ -189,7 +188,7 @@ export const getBaseCodeStyles = theme => ({
189
188
  backgroundColor: `var(${VAR_CODE_BG_COLOR},${theme.backgroundColor})`,
190
189
  color: theme.textColor,
191
190
  borderStyle: 'none',
192
- borderRadius: `${borderRadius()}px`
191
+ borderRadius: "var(--ds-border-radius, 3px)"
193
192
  });
194
193
 
195
194
  /**
@@ -284,10 +283,8 @@ export const getCodeBlockStyles = theme => (highlightedStartText, highlightedEnd
284
283
  content: '" "'
285
284
  }
286
285
  });
287
- export const getCodeStyles = globalTheme => {
288
- // Required to have proper compatibility with styled components interpolations
289
- const akTheme = 'theme' in globalTheme ? globalTheme.theme : globalTheme;
290
- const theme = getBaseTheme(akTheme);
286
+ export const getCodeStyles = () => {
287
+ const theme = getBaseTheme();
291
288
  const baseStyles = getBaseCodeStyles(theme);
292
289
  return {
293
290
  ...baseStyles,
@@ -300,10 +297,10 @@ export const getCodeStyles = globalTheme => {
300
297
  whiteSpace: 'pre-wrap'
301
298
  };
302
299
  };
303
- export const getCodeBlockTheme = (globalTheme, maxLines) => {
300
+ export const getCodeBlockTheme = maxLines => {
304
301
  return {
305
- ...getBaseTheme(globalTheme),
306
- ...getColorPalette(globalTheme),
302
+ ...getBaseTheme(),
303
+ ...getColorPalette(),
307
304
  lineNumberWidth: maxLines ? getLineNumWidth(maxLines) : undefined
308
305
  };
309
306
  };
@@ -1,7 +1,6 @@
1
1
  /** @jsx jsx */
2
2
  import { memo, useCallback, useMemo } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
- import { useGlobalTheme } from '@atlaskit/theme/components';
5
4
  import { useHighlightLines } from './internal/hooks/use-highlight';
6
5
  import { getCodeBlockStyles, getCodeBlockTheme } from './internal/theme/styles';
7
6
  import { normalizeLanguage } from './internal/utils/get-normalized-language';
@@ -37,10 +36,9 @@ var CodeBlock = /*#__PURE__*/memo(function CodeBlock(_ref) {
37
36
  _ref$shouldWrapLongLi = _ref.shouldWrapLongLines,
38
37
  shouldWrapLongLines = _ref$shouldWrapLongLi === void 0 ? false : _ref$shouldWrapLongLi;
39
38
  var numLines = (text || '').split('\n').length;
40
- var globalTheme = useGlobalTheme();
41
39
  var theme = useMemo(function () {
42
- return getCodeBlockTheme(globalTheme, numLines);
43
- }, [globalTheme, numLines]);
40
+ return getCodeBlockTheme(numLines);
41
+ }, [numLines]);
44
42
  var getStyles = useMemo(function () {
45
43
  return getCodeBlockStyles(theme);
46
44
  }, [theme]);
package/dist/esm/code.js CHANGED
@@ -3,9 +3,8 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["testId"],
4
4
  _excluded2 = ["children", "codeBidiWarnings", "codeBidiWarningLabel", "codeBidiWarningTooltipEnabled"];
5
5
  /** @jsx jsx */
6
- import React, { forwardRef, memo, useMemo } from 'react';
6
+ import React, { forwardRef, memo } from 'react';
7
7
  import { css, jsx } from '@emotion/react';
8
- import { useGlobalTheme } from '@atlaskit/theme/components';
9
8
  import CodeBidiWarning from './bidi-warning';
10
9
  import codeBidiWarningDecorator from './bidi-warning/bidi-warning-decorator';
11
10
  import { getCodeStyles } from './internal/theme/styles';
@@ -21,10 +20,7 @@ import { getCodeStyles } from './internal/theme/styles';
21
20
  var Code = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Code(_ref, ref) {
22
21
  var testId = _ref.testId,
23
22
  props = _objectWithoutProperties(_ref, _excluded);
24
- var theme = useGlobalTheme();
25
- var styles = useMemo(function () {
26
- return css(getCodeStyles(theme));
27
- }, [theme]);
23
+ var styles = css(getCodeStyles());
28
24
  var children = props.children,
29
25
  _props$codeBidiWarnin = props.codeBidiWarnings,
30
26
  codeBidiWarnings = _props$codeBidiWarnin === void 0 ? true : _props$codeBidiWarnin,
@@ -1,3 +1,5 @@
1
+ // The full list of languages that can potentially be supported is found in
2
+ // https://prismjs.com/#supported-languages
1
3
  export var SUPPORTED_LANGUAGES = [{
2
4
  name: 'PHP',
3
5
  alias: ['php', 'php3', 'php4', 'php5'],
@@ -306,5 +308,21 @@ export var SUPPORTED_LANGUAGES = [{
306
308
  name: 'SplunkSPL',
307
309
  alias: ['splunk-spl'],
308
310
  value: 'splunk-spl'
311
+ }, {
312
+ name: 'Dockerfile',
313
+ alias: ['docker', 'dockerfile'],
314
+ value: 'dockerfile'
315
+ }, {
316
+ name: 'HCL',
317
+ alias: ['hcl', 'terraform'],
318
+ value: 'hcl'
319
+ }, {
320
+ name: 'NGINX',
321
+ alias: ['nginx'],
322
+ value: 'nginx'
323
+ }, {
324
+ name: 'Protocol Buffers',
325
+ alias: ['protobuf', 'proto'],
326
+ value: 'protobuf'
309
327
  }];
310
328
  export { CODE_BLOCK_SELECTOR } from './internal/theme/constants';