@atlaskit/css 0.11.0 → 0.12.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,26 @@
|
|
|
1
1
|
# @atlaskit/css
|
|
2
2
|
|
|
3
|
+
## 0.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#193214](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/193214)
|
|
8
|
+
[`c661806a65543`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c661806a65543) -
|
|
9
|
+
Internal changes to how border radius and border width values are applied. No visual change.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 0.12.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#177956](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/177956)
|
|
17
|
+
[`124aac4a851f1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/124aac4a851f1) -
|
|
18
|
+
Added metric typography tokens which can be used via the CSS `font` shorthand.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies
|
|
23
|
+
|
|
3
24
|
## 0.11.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
|
@@ -96,7 +96,15 @@ function replaceXcssWithCssMap(
|
|
|
96
96
|
let firstUsagePath: ASTPath<core.Node> | null = null;
|
|
97
97
|
const styleVariables = new Set<string>();
|
|
98
98
|
const variableDependencies = new Map<string, Set<string>>();
|
|
99
|
-
|
|
99
|
+
const inlineXcssUsages: Array<{
|
|
100
|
+
path: ASTPath<core.CallExpression>;
|
|
101
|
+
keyName: string;
|
|
102
|
+
jsxAttribute: ASTPath<core.JSXAttribute>;
|
|
103
|
+
componentName: string;
|
|
104
|
+
variableName: string;
|
|
105
|
+
}> = [];
|
|
106
|
+
|
|
107
|
+
// First pass: collect all xcss variable declarations
|
|
100
108
|
source
|
|
101
109
|
.find(j.CallExpression, {
|
|
102
110
|
// get all xcss calls
|
|
@@ -137,11 +145,49 @@ function replaceXcssWithCssMap(
|
|
|
137
145
|
variableDependencies.set(variableName, dependencies);
|
|
138
146
|
}
|
|
139
147
|
}
|
|
148
|
+
} else {
|
|
149
|
+
// This is an inline xcss call - check if it's inside a JSX attribute
|
|
150
|
+
let current = path.parentPath;
|
|
151
|
+
let jsxElement: ASTPath<core.JSXElement> | null = null;
|
|
152
|
+
|
|
153
|
+
while (current) {
|
|
154
|
+
if (
|
|
155
|
+
current.node.type === 'JSXAttribute' &&
|
|
156
|
+
current.node.name.type === 'JSXIdentifier' &&
|
|
157
|
+
current.node.name.name === 'xcss'
|
|
158
|
+
) {
|
|
159
|
+
// Found inline xcss usage - now find the JSX element
|
|
160
|
+
let elementCurrent = current.parentPath;
|
|
161
|
+
while (elementCurrent) {
|
|
162
|
+
if (elementCurrent.node.type === 'JSXElement') {
|
|
163
|
+
jsxElement = elementCurrent as ASTPath<core.JSXElement>;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
elementCurrent = elementCurrent.parentPath;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (jsxElement && jsxElement.node.openingElement.name.type === 'JSXIdentifier') {
|
|
170
|
+
const componentName = jsxElement.node.openingElement.name.name;
|
|
171
|
+
const variableName = `${componentName.toLowerCase()}Styles`;
|
|
172
|
+
const keyName = 'root';
|
|
173
|
+
|
|
174
|
+
inlineXcssUsages.push({
|
|
175
|
+
path,
|
|
176
|
+
keyName,
|
|
177
|
+
jsxAttribute: current as ASTPath<core.JSXAttribute>,
|
|
178
|
+
componentName,
|
|
179
|
+
variableName,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
current = current.parentPath;
|
|
185
|
+
}
|
|
140
186
|
}
|
|
141
187
|
}
|
|
142
188
|
});
|
|
143
189
|
|
|
144
|
-
// find the first usage of any style variable
|
|
190
|
+
// find the first usage of any style variable or inline xcss
|
|
145
191
|
source.find(j.Identifier).forEach((path) => {
|
|
146
192
|
if (
|
|
147
193
|
styleVariables.has(path.node.name) &&
|
|
@@ -156,7 +202,15 @@ function replaceXcssWithCssMap(
|
|
|
156
202
|
}
|
|
157
203
|
});
|
|
158
204
|
|
|
159
|
-
//
|
|
205
|
+
// Check for inline xcss usage as well for first usage
|
|
206
|
+
if (
|
|
207
|
+
inlineXcssUsages.length > 0 &&
|
|
208
|
+
(!firstUsagePath || inlineXcssUsages[0].path.node.loc?.start)
|
|
209
|
+
) {
|
|
210
|
+
firstUsagePath = inlineXcssUsages[0].path;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Process variable xcss declarations
|
|
160
214
|
source
|
|
161
215
|
.find(j.CallExpression, {
|
|
162
216
|
callee: {
|
|
@@ -202,7 +256,40 @@ function replaceXcssWithCssMap(
|
|
|
202
256
|
}
|
|
203
257
|
});
|
|
204
258
|
|
|
205
|
-
//
|
|
259
|
+
// Process inline xcss usages - create separate cssMap for each
|
|
260
|
+
const cssMapDeclarations: core.VariableDeclaration[] = [];
|
|
261
|
+
|
|
262
|
+
inlineXcssUsages.forEach(({ path, keyName, jsxAttribute, componentName, variableName }) => {
|
|
263
|
+
const args = path.node.arguments;
|
|
264
|
+
if (args.length === 1 && args[0].type === 'ObjectExpression') {
|
|
265
|
+
// Create separate cssMap declaration for each inline xcss
|
|
266
|
+
const cssMapObject = j.objectProperty(
|
|
267
|
+
j.identifier(keyName),
|
|
268
|
+
ensureSelectorAmpersand(j, args[0]),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
const cssMapVariableDeclaration = j.variableDeclaration('const', [
|
|
272
|
+
j.variableDeclarator(
|
|
273
|
+
j.identifier(variableName),
|
|
274
|
+
j.callExpression(j.identifier('cssMap'), [j.objectExpression([cssMapObject])]),
|
|
275
|
+
),
|
|
276
|
+
]);
|
|
277
|
+
|
|
278
|
+
cssMapDeclarations.push(cssMapVariableDeclaration);
|
|
279
|
+
|
|
280
|
+
// Update the JSX attribute to use the cssMap reference
|
|
281
|
+
jsxAttribute.node.value = j.jsxExpressionContainer(
|
|
282
|
+
j.memberExpression(j.identifier(variableName), j.identifier(keyName)),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Track first xcss call if not already set
|
|
286
|
+
if (!firstXcssPath) {
|
|
287
|
+
firstXcssPath = path;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
// create new cssMap with the combined xcss object properties (for variable declarations)
|
|
206
293
|
if (cssMapProperties.length > 0) {
|
|
207
294
|
const cssMapObject = j.objectExpression(cssMapProperties);
|
|
208
295
|
const cssMapVariableDeclaration = j.variableDeclaration('const', [
|
|
@@ -212,44 +299,46 @@ function replaceXcssWithCssMap(
|
|
|
212
299
|
),
|
|
213
300
|
]);
|
|
214
301
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
302
|
+
cssMapDeclarations.unshift(cssMapVariableDeclaration);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Insert all cssMap declarations
|
|
306
|
+
if (cssMapDeclarations.length > 0 && firstUsagePath) {
|
|
307
|
+
const programBody = source.get().node.program.body;
|
|
308
|
+
let insertIndex = 0;
|
|
309
|
+
|
|
310
|
+
// find the last variable declaration that any style depends on
|
|
311
|
+
let lastDependencyIndex = -1;
|
|
312
|
+
for (let i = 0; i < programBody.length; i++) {
|
|
313
|
+
const node = programBody[i];
|
|
314
|
+
if (node.type === 'VariableDeclaration') {
|
|
315
|
+
const varName = node.declarations[0]?.id.name;
|
|
316
|
+
if (varName) {
|
|
317
|
+
// check if this variable is a dependency of any style
|
|
318
|
+
for (const [, deps] of variableDependencies.entries()) {
|
|
319
|
+
if (deps.has(varName)) {
|
|
320
|
+
lastDependencyIndex = i;
|
|
321
|
+
break;
|
|
233
322
|
}
|
|
234
323
|
}
|
|
235
324
|
}
|
|
236
325
|
}
|
|
326
|
+
}
|
|
237
327
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
programBody.splice(insertIndex, 0, cssMapVariableDeclaration);
|
|
328
|
+
// insert after the last dependency
|
|
329
|
+
if (lastDependencyIndex !== -1) {
|
|
330
|
+
insertIndex = lastDependencyIndex + 1;
|
|
331
|
+
} else {
|
|
332
|
+
// if no dependencies, find the first non-import/type declaration
|
|
333
|
+
insertIndex = programBody.findIndex(
|
|
334
|
+
(node: { type: string }) =>
|
|
335
|
+
node.type !== 'ImportDeclaration' &&
|
|
336
|
+
node.type !== 'TypeAlias' &&
|
|
337
|
+
node.type !== 'InterfaceDeclaration',
|
|
338
|
+
);
|
|
252
339
|
}
|
|
340
|
+
|
|
341
|
+
programBody.splice(insertIndex, 0, ...cssMapDeclarations);
|
|
253
342
|
}
|
|
254
343
|
|
|
255
344
|
// First handle backgroundColor transformation for Box components
|
|
@@ -387,19 +476,35 @@ function replaceXcssWithCssMap(
|
|
|
387
476
|
if (value && value.type === 'JSXExpressionContainer') {
|
|
388
477
|
const expression = value.expression;
|
|
389
478
|
if (expression.type === 'Identifier') {
|
|
390
|
-
|
|
391
|
-
|
|
479
|
+
if (styleVariables.has(expression.name)) {
|
|
480
|
+
// <Box xcss={buttonStyles} /> => <Box xcss={styles.button} />
|
|
481
|
+
path.node.value = j.jsxExpressionContainer(
|
|
482
|
+
j.memberExpression(
|
|
483
|
+
j.identifier('styles'),
|
|
484
|
+
j.identifier(getCssMapKey(expression.name)),
|
|
485
|
+
),
|
|
486
|
+
);
|
|
487
|
+
}
|
|
392
488
|
} else if (expression.type === 'ArrayExpression') {
|
|
393
|
-
// <Box xcss={[baseStyles, otherStyles]} />
|
|
489
|
+
// <Box xcss={[baseStyles, otherStyles]} /> => <Box xcss={[styles.base, styles.other]} />
|
|
394
490
|
expression.elements.forEach((element) => {
|
|
395
|
-
if (element?.type === 'Identifier') {
|
|
396
|
-
|
|
491
|
+
if (element?.type === 'Identifier' && styleVariables.has(element.name)) {
|
|
492
|
+
const memberExpression = j.memberExpression(
|
|
493
|
+
j.identifier('styles'),
|
|
494
|
+
j.identifier(getCssMapKey(element.name)),
|
|
495
|
+
);
|
|
496
|
+
// Replace the identifier with the member expression
|
|
497
|
+
Object.assign(element, memberExpression);
|
|
397
498
|
} else if (
|
|
398
|
-
// <Box xcss={condition && styles} />
|
|
499
|
+
// <Box xcss={condition && styles} /> => <Box xcss={condition && styles.root} />
|
|
399
500
|
element?.type === 'LogicalExpression' &&
|
|
400
|
-
element.right.type === 'Identifier'
|
|
501
|
+
element.right.type === 'Identifier' &&
|
|
502
|
+
styleVariables.has(element.right.name)
|
|
401
503
|
) {
|
|
402
|
-
element.right
|
|
504
|
+
element.right = j.memberExpression(
|
|
505
|
+
j.identifier('styles'),
|
|
506
|
+
j.identifier(getCssMapKey(element.right.name)),
|
|
507
|
+
);
|
|
403
508
|
}
|
|
404
509
|
});
|
|
405
510
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "Style components backed by Atlassian Design System design tokens powered by Compiled CSS-in-JS.",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
},
|
|
10
10
|
"atlassian": {
|
|
11
11
|
"team": "Design System Team",
|
|
12
|
-
"runReact18": true,
|
|
13
12
|
"website": {
|
|
14
13
|
"name": "CSS",
|
|
15
14
|
"category": "Libraries",
|
|
@@ -49,7 +48,7 @@
|
|
|
49
48
|
"./test-utils": "./src/test-utils/index.tsx"
|
|
50
49
|
},
|
|
51
50
|
"dependencies": {
|
|
52
|
-
"@atlaskit/tokens": "^5.
|
|
51
|
+
"@atlaskit/tokens": "^5.6.0",
|
|
53
52
|
"@babel/runtime": "^7.0.0",
|
|
54
53
|
"@compiled/react": "^0.18.3"
|
|
55
54
|
},
|
|
@@ -58,9 +57,9 @@
|
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
59
|
"@af/visual-regression": "workspace:^",
|
|
61
|
-
"@atlaskit/button": "^23.
|
|
62
|
-
"@atlaskit/ds-lib": "^
|
|
63
|
-
"@atlaskit/primitives": "^14.
|
|
60
|
+
"@atlaskit/button": "^23.3.0",
|
|
61
|
+
"@atlaskit/ds-lib": "^5.0.0",
|
|
62
|
+
"@atlaskit/primitives": "^14.11.0",
|
|
64
63
|
"@emotion/react": "^11.7.1",
|
|
65
64
|
"@testing-library/react": "^13.4.0",
|
|
66
65
|
"@types/jscodeshift": "^0.11.0",
|