@atlaskit/code 15.2.0 → 15.2.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 +644 -645
- package/__perf__/source-code-examples/100-line-example.tsx +49 -40
- package/codemods/13.0.0-remove-unnecessary-code-props.tsx +61 -75
- package/codemods/13.0.0-rename-imports.tsx +214 -251
- package/codemods/14.0.0-lite-mode.tsx +5 -9
- package/codemods/__tests__/13.0.0-remove-unnecessary-code-props.tsx +43 -43
- package/codemods/__tests__/13.0.0-rename-imports.tsx +143 -143
- package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.tsx +35 -35
- package/codemods/__tests__/14.0.0-lite-mode/remove-language.tsx +21 -21
- package/codemods/__tests__/14.0.0-lite-mode/text-to-child.tsx +35 -35
- package/codemods/migrations/14.0.0-lite-mode/remove-language.tsx +1 -6
- package/codemods/migrations/14.0.0-lite-mode/text-to-child.tsx +53 -61
- package/codemods/utils/helpers.tsx +161 -201
- package/dist/cjs/internal/theme/styles.js +2 -1
- package/dist/es2019/internal/theme/styles.js +2 -1
- package/dist/esm/internal/theme/styles.js +2 -1
- package/dist/types/bidi-warning/ui/index.d.ts +1 -1
- package/dist/types/bidi-warning/ui/styled.d.ts +1 -1
- package/dist/types/extract-react-types/code-block.d.ts +16 -16
- package/dist/types/internal/hooks/use-highlight.d.ts +1 -1
- package/dist/types/internal/utils/get-normalized-language.d.ts +1 -1
- package/dist/types/syntax-highlighter/async.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/highlight.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/create-line.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/index.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
- package/dist/types/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
- package/dist/types/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
- package/dist/types/syntax-highlighter/types.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types-ts4.5/bidi-warning/ui/index.d.ts +1 -1
- package/dist/types-ts4.5/bidi-warning/ui/styled.d.ts +1 -1
- package/dist/types-ts4.5/extract-react-types/code-block.d.ts +16 -16
- package/dist/types-ts4.5/internal/hooks/use-highlight.d.ts +1 -1
- package/dist/types-ts4.5/internal/utils/get-normalized-language.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/async.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/highlight.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/index.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/types.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/package.json +5 -7
- package/report.api.md +807 -807
|
@@ -1,266 +1,226 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ASTPath,
|
|
3
|
+
CallExpression,
|
|
4
|
+
default as core,
|
|
5
|
+
Identifier,
|
|
6
|
+
ImportDeclaration,
|
|
7
|
+
ImportSpecifier,
|
|
8
|
+
JSCodeshift,
|
|
9
|
+
JSXAttribute,
|
|
10
|
+
JSXElement,
|
|
11
|
+
ObjectProperty,
|
|
11
12
|
} from 'jscodeshift';
|
|
12
|
-
import { Collection } from 'jscodeshift/src/Collection';
|
|
13
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
13
14
|
|
|
14
|
-
import {
|
|
15
|
-
addCommentToStartOfFile,
|
|
16
|
-
getNamedSpecifier,
|
|
17
|
-
} from '@atlaskit/codemod-utils';
|
|
15
|
+
import { addCommentToStartOfFile, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
18
16
|
|
|
19
17
|
export function hasImportDeclaration(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
j: JSCodeshift,
|
|
19
|
+
collection: Collection<any>,
|
|
20
|
+
importPath: string,
|
|
23
21
|
) {
|
|
24
|
-
|
|
22
|
+
return getImportDeclarationCollection(j, collection, importPath).length > 0;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export function getImportDeclarationCollection(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
j: JSCodeshift,
|
|
27
|
+
collection: Collection<any>,
|
|
28
|
+
importPath: string,
|
|
31
29
|
) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(importDeclarationPath) =>
|
|
36
|
-
importDeclarationPath.node.source.value === importPath,
|
|
37
|
-
);
|
|
30
|
+
return collection
|
|
31
|
+
.find(j.ImportDeclaration)
|
|
32
|
+
.filter((importDeclarationPath) => importDeclarationPath.node.source.value === importPath);
|
|
38
33
|
}
|
|
39
34
|
|
|
40
|
-
export function hasDynamicImport(
|
|
41
|
-
|
|
42
|
-
collection: Collection<any>,
|
|
43
|
-
importPath: string,
|
|
44
|
-
) {
|
|
45
|
-
return getDynamicImportCollection(j, collection, importPath).length > 0;
|
|
35
|
+
export function hasDynamicImport(j: JSCodeshift, collection: Collection<any>, importPath: string) {
|
|
36
|
+
return getDynamicImportCollection(j, collection, importPath).length > 0;
|
|
46
37
|
}
|
|
47
38
|
|
|
48
39
|
export function getDynamicImportCollection(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
j: JSCodeshift,
|
|
41
|
+
collection: Collection<any>,
|
|
42
|
+
importPath: string,
|
|
52
43
|
) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
callExpressionPath.node;
|
|
44
|
+
return collection.find(j.CallExpression).filter((callExpressionPath) => {
|
|
45
|
+
const { callee, arguments: callExpressionArguments } = callExpressionPath.node;
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
importPath,
|
|
64
|
-
)
|
|
65
|
-
);
|
|
66
|
-
});
|
|
47
|
+
return !!(
|
|
48
|
+
isCallExpressionCalleeImportType(callee) &&
|
|
49
|
+
isCallExpressionArgumentStringLiteralType(callExpressionArguments) &&
|
|
50
|
+
isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath)
|
|
51
|
+
);
|
|
52
|
+
});
|
|
67
53
|
}
|
|
68
54
|
function isCallExpressionCalleeImportType(callee: CallExpression['callee']) {
|
|
69
|
-
|
|
55
|
+
return callee && callee.type === 'Import';
|
|
70
56
|
}
|
|
71
57
|
function isCallExpressionArgumentStringLiteralType(
|
|
72
|
-
|
|
58
|
+
callExpressionArguments: CallExpression['arguments'],
|
|
73
59
|
) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
return (
|
|
61
|
+
callExpressionArguments &&
|
|
62
|
+
callExpressionArguments.length &&
|
|
63
|
+
callExpressionArguments[0].type === 'StringLiteral'
|
|
64
|
+
);
|
|
79
65
|
}
|
|
80
66
|
function isCallExpressionArgumentValueMatches(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
callExpressionArgument: CallExpression['arguments'][0],
|
|
68
|
+
j: JSCodeshift,
|
|
69
|
+
value: string,
|
|
84
70
|
) {
|
|
85
|
-
|
|
71
|
+
return j(callExpressionArgument).some((path) => path.node.value === value);
|
|
86
72
|
}
|
|
87
73
|
|
|
88
74
|
export function getImportSpecifierCollection(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
j: JSCodeshift,
|
|
76
|
+
importDeclarationCollection: Collection<ImportDeclaration>,
|
|
77
|
+
importName: string,
|
|
92
78
|
) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
(importSpecifierPath) =>
|
|
97
|
-
importSpecifierPath.node.imported.name === importName,
|
|
98
|
-
);
|
|
79
|
+
return importDeclarationCollection
|
|
80
|
+
.find(j.ImportSpecifier)
|
|
81
|
+
.filter((importSpecifierPath) => importSpecifierPath.node.imported.name === importName);
|
|
99
82
|
}
|
|
100
83
|
|
|
101
|
-
export function getImportSpecifierName(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
84
|
+
export function getImportSpecifierName(importSpecifierCollection: Collection<ImportSpecifier>) {
|
|
85
|
+
if (importSpecifierCollection.length === 0) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
107
88
|
|
|
108
|
-
|
|
89
|
+
return importSpecifierCollection.nodes()[0]!.local!.name;
|
|
109
90
|
}
|
|
110
91
|
|
|
111
92
|
export function isVariableDeclaratorIdentifierPresent(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
93
|
+
j: JSCodeshift,
|
|
94
|
+
collection: Collection<any>,
|
|
95
|
+
variableName: string,
|
|
115
96
|
) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
97
|
+
return collection
|
|
98
|
+
.find(j.VariableDeclaration)
|
|
99
|
+
.find(j.VariableDeclarator)
|
|
100
|
+
.some((variableDeclaratorPath) => {
|
|
101
|
+
const { id } = variableDeclaratorPath.node;
|
|
121
102
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
id.type === 'Identifier' &&
|
|
125
|
-
(id as Identifier).name === variableName
|
|
126
|
-
);
|
|
127
|
-
});
|
|
103
|
+
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
104
|
+
});
|
|
128
105
|
}
|
|
129
106
|
|
|
130
107
|
export function isFunctionDeclarationIdentifierPresent(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
108
|
+
j: JSCodeshift,
|
|
109
|
+
collection: Collection<any>,
|
|
110
|
+
variableName: string,
|
|
134
111
|
) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.some((functionDeclarationPath) => {
|
|
138
|
-
const { id } = functionDeclarationPath.node;
|
|
112
|
+
return collection.find(j.FunctionDeclaration).some((functionDeclarationPath) => {
|
|
113
|
+
const { id } = functionDeclarationPath.node;
|
|
139
114
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
id.type === 'Identifier' &&
|
|
143
|
-
(id as Identifier).name === variableName
|
|
144
|
-
);
|
|
145
|
-
});
|
|
115
|
+
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
116
|
+
});
|
|
146
117
|
}
|
|
147
118
|
|
|
148
119
|
export function isClassDeclarationIdentifierPresent(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
120
|
+
j: JSCodeshift,
|
|
121
|
+
collection: Collection<any>,
|
|
122
|
+
variableName: string,
|
|
152
123
|
) {
|
|
153
|
-
|
|
154
|
-
|
|
124
|
+
return collection.find(j.ClassDeclaration).some((classDeclarationPath) => {
|
|
125
|
+
const { id } = classDeclarationPath.node;
|
|
155
126
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
id.type === 'Identifier' &&
|
|
159
|
-
(id as Identifier).name === variableName
|
|
160
|
-
);
|
|
161
|
-
});
|
|
127
|
+
return !!(id && id.type === 'Identifier' && (id as Identifier).name === variableName);
|
|
128
|
+
});
|
|
162
129
|
}
|
|
163
130
|
|
|
164
131
|
export function isImportDeclarationIdentifierPresent(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
132
|
+
j: JSCodeshift,
|
|
133
|
+
collection: Collection<any>,
|
|
134
|
+
variableName: string,
|
|
168
135
|
) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
136
|
+
return collection
|
|
137
|
+
.find(j.ImportDeclaration)
|
|
138
|
+
.find(j.Identifier)
|
|
139
|
+
.some((identifierPath) => identifierPath.node.name === variableName);
|
|
173
140
|
}
|
|
174
141
|
|
|
175
142
|
export function getJSXAttributesByName(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
143
|
+
j: JSCodeshift,
|
|
144
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
145
|
+
attributeName: string,
|
|
179
146
|
): Collection<JSXAttribute> {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
),
|
|
189
|
-
);
|
|
147
|
+
return j(jsxElementPath)
|
|
148
|
+
.find(j.JSXOpeningElement)
|
|
149
|
+
.find(j.JSXAttribute)
|
|
150
|
+
.filter((jsxAttributePath) =>
|
|
151
|
+
j(jsxAttributePath)
|
|
152
|
+
.find(j.JSXIdentifier)
|
|
153
|
+
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === attributeName),
|
|
154
|
+
);
|
|
190
155
|
}
|
|
191
156
|
|
|
192
157
|
export function getJSXSpreadIdentifierAttributesByName(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
158
|
+
j: JSCodeshift,
|
|
159
|
+
collection: Collection<any>,
|
|
160
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
161
|
+
attributeName: string,
|
|
197
162
|
): Collection<ObjectProperty> | null {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
.filter((objectPropertyPath) =>
|
|
226
|
-
j(objectPropertyPath)
|
|
227
|
-
.find(j.Identifier)
|
|
228
|
-
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
229
|
-
);
|
|
163
|
+
const identifierCollection = j(jsxElementPath)
|
|
164
|
+
.find(j.JSXOpeningElement)
|
|
165
|
+
.find(j.JSXSpreadAttribute)
|
|
166
|
+
.filter((jsxSpreadAttributePath) => jsxSpreadAttributePath.node.argument.type === 'Identifier')
|
|
167
|
+
.find(j.Identifier);
|
|
168
|
+
|
|
169
|
+
if (identifierCollection.length === 0) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return collection
|
|
174
|
+
.find(j.VariableDeclarator)
|
|
175
|
+
.filter((variableDeclaratorPath) => {
|
|
176
|
+
const { id } = variableDeclaratorPath.node;
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
id.type === 'Identifier' &&
|
|
180
|
+
identifierCollection.some((identifierPath) => identifierPath.node.name === id.name)
|
|
181
|
+
);
|
|
182
|
+
})
|
|
183
|
+
.find(j.ObjectExpression)
|
|
184
|
+
.find(j.ObjectProperty)
|
|
185
|
+
.filter((objectPropertyPath) =>
|
|
186
|
+
j(objectPropertyPath)
|
|
187
|
+
.find(j.Identifier)
|
|
188
|
+
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
189
|
+
);
|
|
230
190
|
}
|
|
231
191
|
|
|
232
192
|
export function getJSXSpreadObjectExpressionAttributesByName(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
193
|
+
j: JSCodeshift,
|
|
194
|
+
jsxElementPath: ASTPath<JSXElement>,
|
|
195
|
+
attributeName: string,
|
|
236
196
|
) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
197
|
+
return j(jsxElementPath)
|
|
198
|
+
.find(j.JSXOpeningElement)
|
|
199
|
+
.find(j.JSXSpreadAttribute)
|
|
200
|
+
.find(j.ObjectExpression)
|
|
201
|
+
.find(j.ObjectProperty)
|
|
202
|
+
.filter((objectPropertyPath) =>
|
|
203
|
+
j(objectPropertyPath)
|
|
204
|
+
.find(j.Identifier)
|
|
205
|
+
.some((identifierPath) => identifierPath.node.name === attributeName),
|
|
206
|
+
);
|
|
247
207
|
}
|
|
248
208
|
|
|
249
209
|
export const createRemoveFuncFor =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
210
|
+
(component: string, importName: string, prop: string, comment?: string) =>
|
|
211
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
212
|
+
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
213
|
+
|
|
214
|
+
if (!specifier) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
219
|
+
getJSXAttributesByName(j, element, prop).forEach((attribute: any) => {
|
|
220
|
+
j(attribute).remove();
|
|
221
|
+
if (comment) {
|
|
222
|
+
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
};
|
|
@@ -219,7 +219,8 @@ var getCodeBlockStyles = exports.getCodeBlockStyles = function getCodeBlockStyle
|
|
|
219
219
|
// this is required to account for prismjs styles leaking into the codeblock
|
|
220
220
|
'code[class*="language-"], pre[class*="language-"], code': {
|
|
221
221
|
all: 'unset',
|
|
222
|
-
padding: showLineNumbers ? "".concat(_constants.SPACING, "px 0") : _constants.SPACING
|
|
222
|
+
padding: showLineNumbers ? "".concat(_constants.SPACING, "px 0") : _constants.SPACING,
|
|
223
|
+
tabSize: 4
|
|
223
224
|
},
|
|
224
225
|
display: 'flex',
|
|
225
226
|
lineHeight: _constants.CODE_LINE_HEIGHT,
|
|
@@ -201,7 +201,8 @@ export const getCodeBlockStyles = theme => (highlightedStartText, highlightedEnd
|
|
|
201
201
|
// this is required to account for prismjs styles leaking into the codeblock
|
|
202
202
|
'code[class*="language-"], pre[class*="language-"], code': {
|
|
203
203
|
all: 'unset',
|
|
204
|
-
padding: showLineNumbers ? `${SPACING}px 0` : SPACING
|
|
204
|
+
padding: showLineNumbers ? `${SPACING}px 0` : SPACING,
|
|
205
|
+
tabSize: 4
|
|
205
206
|
},
|
|
206
207
|
display: 'flex',
|
|
207
208
|
lineHeight: CODE_LINE_HEIGHT,
|
|
@@ -212,7 +212,8 @@ export var getCodeBlockStyles = function getCodeBlockStyles(theme) {
|
|
|
212
212
|
// this is required to account for prismjs styles leaking into the codeblock
|
|
213
213
|
'code[class*="language-"], pre[class*="language-"], code': {
|
|
214
214
|
all: 'unset',
|
|
215
|
-
padding: showLineNumbers ? "".concat(SPACING, "px 0") : SPACING
|
|
215
|
+
padding: showLineNumbers ? "".concat(SPACING, "px 0") : SPACING,
|
|
216
|
+
tabSize: 4
|
|
216
217
|
},
|
|
217
218
|
display: 'flex',
|
|
218
219
|
lineHeight: CODE_LINE_HEIGHT,
|
|
@@ -12,24 +12,24 @@ export default function CodeBlock(__: {
|
|
|
12
12
|
*/
|
|
13
13
|
showLineNumbers?: boolean;
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
24
|
language?: string;
|
|
25
25
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
33
|
highlight?: string;
|
|
34
34
|
/**
|
|
35
35
|
* Screen reader text for the start of a highlighted line.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTMLProps } from 'react';
|
|
1
|
+
import { type HTMLProps } from 'react';
|
|
2
2
|
import type { CodeBlockProps } from '../types';
|
|
3
3
|
export declare const useHighlightLines: ({ highlight, testId, }: Pick<CodeBlockProps, 'highlight' | 'testId'>) => {
|
|
4
4
|
getHighlightStyles: (lineNumber: number, highlightedLines: number[]) => HTMLProps<HTMLElement>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SupportedLanguages } from '../types';
|
|
1
|
+
import { type SupportedLanguages } from '../types';
|
|
2
2
|
export declare const normalizeLanguage: import("memoize-one").MemoizedFn<(language?: SupportedLanguages) => string>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { SyntaxHighlighterProps } from '../types';
|
|
2
|
+
import { type SyntaxHighlighterProps } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Takes in a code string and (in the default behaviour):
|
|
5
5
|
* - Uses refractor to turn it into a tree structure with highlighting metadata
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { RefractorNode, SyntaxHighlighterLineProps } from '../../types';
|
|
1
|
+
import { type RefractorNode, type SyntaxHighlighterLineProps } from '../../types';
|
|
2
2
|
declare function createLineGenerator(lineProps: SyntaxHighlighterLineProps, shouldCreateParentElementForLines: boolean, showLineNumbers: boolean): (children: RefractorNode[], lineNumber: number, className?: string[]) => RefractorNode | RefractorNode[];
|
|
3
3
|
export default createLineGenerator;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RefractorNode } from '../../types';
|
|
1
|
+
import { type RefractorNode } from '../../types';
|
|
2
2
|
export default function flattenCodeTree(tree: RefractorNode[], offset?: number, className?: string[]): RefractorNode[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AstGenerator, RefractorNode } from '../../types';
|
|
1
|
+
import { type AstGenerator, type RefractorNode } from '../../types';
|
|
2
2
|
export default function getCodeTree(language: string, code: string, astGenerator?: AstGenerator): RefractorNode[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RefractorNode } from '../../types';
|
|
1
|
+
import { type RefractorNode } from '../../types';
|
|
2
2
|
export default function getInlineLineNumber(lineNumber: number): RefractorNode;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { CodeBidiWarningConfig, RefractorNode } from '../../types';
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type CodeBidiWarningConfig, type RefractorNode } from '../../types';
|
|
3
3
|
export default function createChildren(codeBidiWarningConfig: CodeBidiWarningConfig): (children: RefractorNode[]) => ReactNode[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { CodeBidiWarningConfig, RefractorNode } from '../../types';
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type CodeBidiWarningConfig, type RefractorNode } from '../../types';
|
|
3
3
|
export default function createElement({ node, codeBidiWarningConfig, key, }: {
|
|
4
4
|
node: RefractorNode;
|
|
5
5
|
codeBidiWarningConfig: CodeBidiWarningConfig;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SerializedStyles } from '@emotion/react';
|
|
3
|
-
import { AST, RefractorNode } from 'refractor';
|
|
2
|
+
import { type SerializedStyles } from '@emotion/react';
|
|
3
|
+
import { type AST, type RefractorNode } from 'refractor';
|
|
4
4
|
export type { AST, RefractorNode } from 'refractor';
|
|
5
5
|
export declare class SyntaxHighlighter extends React.PureComponent<SyntaxHighlighterProps> {
|
|
6
6
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HTMLProps, ReactNode } from 'react';
|
|
2
|
-
export type { SupportedLanguages, Language, LanguageAlias, CodeBlockProps
|
|
2
|
+
export type { SupportedLanguages, Language, LanguageAlias, CodeBlockProps } from './internal/types';
|
|
3
3
|
export interface CodeProps extends HTMLProps<HTMLElement> {
|
|
4
4
|
/**
|
|
5
5
|
* A unique string that appears as a data attribute `data-testid`
|