@atlaskit/avatar 21.9.1 → 21.9.2

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,14 @@
1
1
  # @atlaskit/avatar
2
2
 
3
+ ## 21.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#110310](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/110310)
8
+ [`ea4751db471b1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ea4751db471b1) -
9
+ Allow maker-provided prop to override the context value for the AvatarContext's `size` property.
10
+ - Updated dependencies
11
+
3
12
  ## 21.9.1
4
13
 
5
14
  ### Patch Changes
@@ -20,7 +29,7 @@
20
29
 
21
30
  - [#98168](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98168)
22
31
  [`bc3ef8133b6c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bc3ef8133b6c) -
23
- Add support for React 18.
32
+ Add support for React 18 in non-strict mode.
24
33
 
25
34
  ## 21.7.0
26
35
 
@@ -28,7 +37,7 @@
28
37
 
29
38
  - [#96490](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/96490)
30
39
  [`e7e14229e1ca`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e7e14229e1ca) -
31
- Add support for React 18.
40
+ Add support for React 18 in non-strict mode.
32
41
 
33
42
  ## 21.6.1
34
43
 
@@ -1,301 +1,252 @@
1
1
  // eslint-disable-next-line @repo/internal/fs/filename-pattern-match
2
2
  import type {
3
- API,
4
- ASTPath,
5
- default as core,
6
- FileInfo,
7
- ImportDeclaration,
8
- ImportSpecifier,
9
- MemberExpression,
10
- Options,
3
+ API,
4
+ ASTPath,
5
+ default as core,
6
+ FileInfo,
7
+ ImportDeclaration,
8
+ ImportSpecifier,
9
+ MemberExpression,
10
+ Options,
11
11
  } from 'jscodeshift';
12
12
 
13
13
  function getImportDeclaration(
14
- j: core.JSCodeshift,
15
- source: ReturnType<typeof j>,
16
- specifier: string,
14
+ j: core.JSCodeshift,
15
+ source: ReturnType<typeof j>,
16
+ specifier: string,
17
17
  ) {
18
- return source
19
- .find(j.ImportDeclaration)
20
- .filter(
21
- (path: ASTPath<ImportDeclaration>) =>
22
- path.node.source.value === specifier,
23
- );
18
+ return source
19
+ .find(j.ImportDeclaration)
20
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier);
24
21
  }
25
22
 
26
- function getDefaultSpecifier(
27
- j: core.JSCodeshift,
28
- source: ReturnType<typeof j>,
29
- specifier: string,
30
- ) {
31
- const specifiers = source
32
- .find(j.ImportDeclaration)
33
- .filter(
34
- (path: ASTPath<ImportDeclaration>) =>
35
- path.node.source.value === specifier,
36
- )
37
- .find(j.ImportDefaultSpecifier);
38
-
39
- if (!specifiers.length) {
40
- return null;
41
- }
42
- return specifiers.nodes()[0]!.local!.name;
23
+ function getDefaultSpecifier(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
24
+ const specifiers = source
25
+ .find(j.ImportDeclaration)
26
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
27
+ .find(j.ImportDefaultSpecifier);
28
+
29
+ if (!specifiers.length) {
30
+ return null;
31
+ }
32
+ return specifiers.nodes()[0]!.local!.name;
43
33
  }
44
34
 
45
35
  function getImportSpecifier(
46
- j: core.JSCodeshift,
47
- source: ReturnType<typeof j>,
48
- specifier: string,
49
- imported: string,
36
+ j: core.JSCodeshift,
37
+ source: ReturnType<typeof j>,
38
+ specifier: string,
39
+ imported: string,
50
40
  ) {
51
- const specifiers = source
52
- .find(j.ImportDeclaration)
53
- .filter(
54
- (path: ASTPath<ImportDeclaration>) =>
55
- path.node.source.value === specifier,
56
- )
57
- .find(j.ImportSpecifier)
58
- .filter(
59
- (path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported,
60
- );
61
-
62
- if (!specifiers.length) {
63
- return null;
64
- }
65
-
66
- return specifiers.nodes()[0]!.local!.name;
41
+ const specifiers = source
42
+ .find(j.ImportDeclaration)
43
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
44
+ .find(j.ImportSpecifier)
45
+ .filter((path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported);
46
+
47
+ if (!specifiers.length) {
48
+ return null;
49
+ }
50
+
51
+ return specifiers.nodes()[0]!.local!.name;
67
52
  }
68
53
 
69
- function getJSXAttributesByName(
70
- j: core.JSCodeshift,
71
- element: ASTPath<any>,
72
- attributeName: string,
73
- ) {
74
- return j(element)
75
- .find(j.JSXOpeningElement)
76
- .find(j.JSXAttribute)
77
- .filter((attribute) => {
78
- const matches = j(attribute)
79
- .find(j.JSXIdentifier)
80
- .filter((identifier) => identifier.value.name === attributeName);
81
- return Boolean(matches.length);
82
- });
54
+ function getJSXAttributesByName(j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) {
55
+ return j(element)
56
+ .find(j.JSXOpeningElement)
57
+ .find(j.JSXAttribute)
58
+ .filter((attribute) => {
59
+ const matches = j(attribute)
60
+ .find(j.JSXIdentifier)
61
+ .filter((identifier) => identifier.value.name === attributeName);
62
+ return Boolean(matches.length);
63
+ });
83
64
  }
84
65
 
85
66
  function updateAvatarProps(j: core.JSCodeshift, source: ReturnType<typeof j>) {
86
- const defaultSpecifier = getDefaultSpecifier(j, source, '@atlaskit/avatar');
87
-
88
- if (!defaultSpecifier) {
89
- return;
90
- }
91
-
92
- source.findJSXElements(defaultSpecifier).forEach((element) => {
93
- getJSXAttributesByName(j, element, 'isHover').remove();
94
- getJSXAttributesByName(j, element, 'isActive').remove();
95
- getJSXAttributesByName(j, element, 'isFocus').remove();
96
- getJSXAttributesByName(j, element, 'isSelected').remove();
97
- getJSXAttributesByName(j, element, 'theme').remove();
98
-
99
- const nameAttributes = getJSXAttributesByName(j, element, 'name');
100
- const name = nameAttributes.length && nameAttributes.get();
101
- const enableTooltipAttributes = getJSXAttributesByName(
102
- j,
103
- element,
104
- 'enableTooltip',
105
- );
106
- const enableTooltipValue =
107
- enableTooltipAttributes.length && enableTooltipAttributes;
108
-
109
- const hasDefaultTrue = !!enableTooltipAttributes.filter(
110
- (attr) => attr.node.value == null,
111
- ).length;
112
-
113
- const hasTruthy = !!enableTooltipAttributes
114
- .find(j.JSXExpressionContainer)
115
- .find(j.BooleanLiteral)
116
- .filter((literal) => literal.node.value).length;
117
-
118
- const hasFalsy = !!enableTooltipAttributes
119
- .find(j.JSXExpressionContainer)
120
- .find(j.BooleanLiteral)
121
- .filter((literal) => literal.node.value === false).length;
122
-
123
- const hasExpression = !!enableTooltipAttributes
124
- .find(j.JSXExpressionContainer)
125
- .filter((container) => {
126
- return j(container).find(j.BooleanLiteral).length === 0;
127
- }).length;
128
-
129
- const shouldWrapAvatar =
130
- !hasFalsy || hasDefaultTrue || hasTruthy || hasExpression;
131
-
132
- if (shouldWrapAvatar && name) {
133
- getImportDeclaration(j, source, '@atlaskit/avatar').forEach(
134
- (importDeclaration) => {
135
- j(importDeclaration).replaceWith([
136
- j.importDeclaration(
137
- [j.importDefaultSpecifier(j.identifier('Tooltip'))],
138
- j.literal('@atlaskit/tooltip'),
139
- ),
140
- importDeclaration.value,
141
- ]);
142
- },
143
- );
144
-
145
- const wrappedAvatar = j.jsxElement(
146
- j.jsxOpeningElement(j.jsxIdentifier('Tooltip'), [
147
- j.jsxAttribute(j.jsxIdentifier('content'), name.value.value),
148
- ]),
149
- j.jsxClosingElement(j.jsxIdentifier('Tooltip')),
150
- [
151
- j.jsxElement(
152
- element.value.openingElement,
153
- element.value.closingElement,
154
- element.value.children,
155
- ),
156
- ],
157
- );
158
-
159
- if (hasExpression && enableTooltipValue) {
160
- j(element).replaceWith([
161
- j.conditionalExpression(
162
- enableTooltipValue.find(j.JSXExpressionContainer).get().value
163
- .expression,
164
- wrappedAvatar,
165
- element.value,
166
- ),
167
- ]);
168
- } else {
169
- j(element).replaceWith([wrappedAvatar]);
170
- }
171
- }
172
-
173
- enableTooltipValue && enableTooltipValue.remove();
174
- });
67
+ const defaultSpecifier = getDefaultSpecifier(j, source, '@atlaskit/avatar');
68
+
69
+ if (!defaultSpecifier) {
70
+ return;
71
+ }
72
+
73
+ source.findJSXElements(defaultSpecifier).forEach((element) => {
74
+ getJSXAttributesByName(j, element, 'isHover').remove();
75
+ getJSXAttributesByName(j, element, 'isActive').remove();
76
+ getJSXAttributesByName(j, element, 'isFocus').remove();
77
+ getJSXAttributesByName(j, element, 'isSelected').remove();
78
+ getJSXAttributesByName(j, element, 'theme').remove();
79
+
80
+ const nameAttributes = getJSXAttributesByName(j, element, 'name');
81
+ const name = nameAttributes.length && nameAttributes.get();
82
+ const enableTooltipAttributes = getJSXAttributesByName(j, element, 'enableTooltip');
83
+ const enableTooltipValue = enableTooltipAttributes.length && enableTooltipAttributes;
84
+
85
+ const hasDefaultTrue = !!enableTooltipAttributes.filter((attr) => attr.node.value == null)
86
+ .length;
87
+
88
+ const hasTruthy = !!enableTooltipAttributes
89
+ .find(j.JSXExpressionContainer)
90
+ .find(j.BooleanLiteral)
91
+ .filter((literal) => literal.node.value).length;
92
+
93
+ const hasFalsy = !!enableTooltipAttributes
94
+ .find(j.JSXExpressionContainer)
95
+ .find(j.BooleanLiteral)
96
+ .filter((literal) => literal.node.value === false).length;
97
+
98
+ const hasExpression = !!enableTooltipAttributes
99
+ .find(j.JSXExpressionContainer)
100
+ .filter((container) => {
101
+ return j(container).find(j.BooleanLiteral).length === 0;
102
+ }).length;
103
+
104
+ const shouldWrapAvatar = !hasFalsy || hasDefaultTrue || hasTruthy || hasExpression;
105
+
106
+ if (shouldWrapAvatar && name) {
107
+ getImportDeclaration(j, source, '@atlaskit/avatar').forEach((importDeclaration) => {
108
+ j(importDeclaration).replaceWith([
109
+ j.importDeclaration(
110
+ [j.importDefaultSpecifier(j.identifier('Tooltip'))],
111
+ j.literal('@atlaskit/tooltip'),
112
+ ),
113
+ importDeclaration.value,
114
+ ]);
115
+ });
116
+
117
+ const wrappedAvatar = j.jsxElement(
118
+ j.jsxOpeningElement(j.jsxIdentifier('Tooltip'), [
119
+ j.jsxAttribute(j.jsxIdentifier('content'), name.value.value),
120
+ ]),
121
+ j.jsxClosingElement(j.jsxIdentifier('Tooltip')),
122
+ [
123
+ j.jsxElement(
124
+ element.value.openingElement,
125
+ element.value.closingElement,
126
+ element.value.children,
127
+ ),
128
+ ],
129
+ );
130
+
131
+ if (hasExpression && enableTooltipValue) {
132
+ j(element).replaceWith([
133
+ j.conditionalExpression(
134
+ enableTooltipValue.find(j.JSXExpressionContainer).get().value.expression,
135
+ wrappedAvatar,
136
+ element.value,
137
+ ),
138
+ ]);
139
+ } else {
140
+ j(element).replaceWith([wrappedAvatar]);
141
+ }
142
+ }
143
+
144
+ enableTooltipValue && enableTooltipValue.remove();
145
+ });
175
146
  }
176
147
 
177
- function updateAvatarItemProps(
178
- j: core.JSCodeshift,
179
- source: ReturnType<typeof j>,
180
- ) {
181
- const importSpecifier = getImportSpecifier(
182
- j,
183
- source,
184
- '@atlaskit/avatar',
185
- 'AvatarItem',
186
- );
187
-
188
- if (!importSpecifier) {
189
- return;
190
- }
191
-
192
- source.findJSXElements(importSpecifier).forEach((element) => {
193
- getJSXAttributesByName(j, element, 'isHover').remove();
194
- getJSXAttributesByName(j, element, 'isActive').remove();
195
- getJSXAttributesByName(j, element, 'isFocus').remove();
196
- getJSXAttributesByName(j, element, 'isSelected').remove();
197
- getJSXAttributesByName(j, element, 'theme').remove();
198
- getJSXAttributesByName(j, element, 'enableTextTruncate').forEach(
199
- (attribute) => {
200
- // Change the prop name to isTruncationDisabled
201
- j(attribute)
202
- .find(j.JSXIdentifier)
203
- .replaceWith(j.jsxIdentifier('isTruncationDisabled'));
204
-
205
- // Remove if enableTextTruncate was true or given no value (ie true)
206
- j(attribute)
207
- .filter((attr) => attr.node.value == null)
208
- .remove();
209
-
210
- j(attribute)
211
- .filter((attr) => {
212
- return !!j(attr)
213
- .find(j.JSXExpressionContainer)
214
- .find(j.BooleanLiteral)
215
- .filter((literal) => literal.node.value).length;
216
- })
217
- .remove();
218
-
219
- // if `enableTextTruncate` value is negative we can change it to 'true'
220
- j(attribute)
221
- .filter(
222
- (attr) =>
223
- !!j(attr)
224
- .find(j.JSXExpressionContainer)
225
- .filter(
226
- (expression) =>
227
- j(expression)
228
- .find(j.BooleanLiteral)
229
- .filter((literal) => !literal.node.value).length > 0,
230
- ).length,
231
- )
232
- .replaceWith(j.jsxAttribute(j.jsxIdentifier('isTruncationDisabled')));
233
-
234
- // if `enableTextTruncate` was an expression, negate it
235
- j(attribute)
236
- .find(j.JSXExpressionContainer)
237
- .filter((container) => {
238
- return j(container).find(j.BooleanLiteral).length === 0;
239
- })
240
- .forEach((container) => {
241
- j(container).replaceWith(
242
- j.jsxExpressionContainer(
243
- // Type 'JSXEmptyExpression' is not assignable to type 'ExpressionKind'.
244
- // @ts-ignore TS2345
245
- j.unaryExpression('!', container.node.expression),
246
- ),
247
- );
248
- });
249
- },
250
- );
251
- });
148
+ function updateAvatarItemProps(j: core.JSCodeshift, source: ReturnType<typeof j>) {
149
+ const importSpecifier = getImportSpecifier(j, source, '@atlaskit/avatar', 'AvatarItem');
150
+
151
+ if (!importSpecifier) {
152
+ return;
153
+ }
154
+
155
+ source.findJSXElements(importSpecifier).forEach((element) => {
156
+ getJSXAttributesByName(j, element, 'isHover').remove();
157
+ getJSXAttributesByName(j, element, 'isActive').remove();
158
+ getJSXAttributesByName(j, element, 'isFocus').remove();
159
+ getJSXAttributesByName(j, element, 'isSelected').remove();
160
+ getJSXAttributesByName(j, element, 'theme').remove();
161
+ getJSXAttributesByName(j, element, 'enableTextTruncate').forEach((attribute) => {
162
+ // Change the prop name to isTruncationDisabled
163
+ j(attribute).find(j.JSXIdentifier).replaceWith(j.jsxIdentifier('isTruncationDisabled'));
164
+
165
+ // Remove if enableTextTruncate was true or given no value (ie true)
166
+ j(attribute)
167
+ .filter((attr) => attr.node.value == null)
168
+ .remove();
169
+
170
+ j(attribute)
171
+ .filter((attr) => {
172
+ return !!j(attr)
173
+ .find(j.JSXExpressionContainer)
174
+ .find(j.BooleanLiteral)
175
+ .filter((literal) => literal.node.value).length;
176
+ })
177
+ .remove();
178
+
179
+ // if `enableTextTruncate` value is negative we can change it to 'true'
180
+ j(attribute)
181
+ .filter(
182
+ (attr) =>
183
+ !!j(attr)
184
+ .find(j.JSXExpressionContainer)
185
+ .filter(
186
+ (expression) =>
187
+ j(expression)
188
+ .find(j.BooleanLiteral)
189
+ .filter((literal) => !literal.node.value).length > 0,
190
+ ).length,
191
+ )
192
+ .replaceWith(j.jsxAttribute(j.jsxIdentifier('isTruncationDisabled')));
193
+
194
+ // if `enableTextTruncate` was an expression, negate it
195
+ j(attribute)
196
+ .find(j.JSXExpressionContainer)
197
+ .filter((container) => {
198
+ return j(container).find(j.BooleanLiteral).length === 0;
199
+ })
200
+ .forEach((container) => {
201
+ j(container).replaceWith(
202
+ j.jsxExpressionContainer(
203
+ // Type 'JSXEmptyExpression' is not assignable to type 'ExpressionKind'.
204
+ // @ts-ignore TS2345
205
+ j.unaryExpression('!', container.node.expression),
206
+ ),
207
+ );
208
+ });
209
+ });
210
+ });
252
211
  }
253
212
 
254
- function updateBorderWidthUsage(
255
- j: core.JSCodeshift,
256
- source: ReturnType<typeof j>,
257
- ) {
258
- source
259
- .find(j.MemberExpression)
260
- .filter(
261
- (memberExpression: ASTPath<MemberExpression>) =>
262
- // @ts-ignore
263
- memberExpression.value.object.name === 'BORDER_WIDTH',
264
- )
265
- .forEach((memberExpression: ASTPath<MemberExpression>) => {
266
- if (memberExpression.value.property) {
267
- j(memberExpression).replaceWith(
268
- // @ts-ignore
269
- j.identifier(memberExpression.value.object.name),
270
- );
271
- }
272
- });
213
+ function updateBorderWidthUsage(j: core.JSCodeshift, source: ReturnType<typeof j>) {
214
+ source
215
+ .find(j.MemberExpression)
216
+ .filter(
217
+ (memberExpression: ASTPath<MemberExpression>) =>
218
+ // @ts-ignore
219
+ memberExpression.value.object.name === 'BORDER_WIDTH',
220
+ )
221
+ .forEach((memberExpression: ASTPath<MemberExpression>) => {
222
+ if (memberExpression.value.property) {
223
+ j(memberExpression).replaceWith(
224
+ // @ts-ignore
225
+ j.identifier(memberExpression.value.object.name),
226
+ );
227
+ }
228
+ });
273
229
  }
274
230
 
275
231
  function hasImportDeclaration(
276
- j: core.JSCodeshift,
277
- source: ReturnType<typeof j>,
278
- importPath: string,
232
+ j: core.JSCodeshift,
233
+ source: ReturnType<typeof j>,
234
+ importPath: string,
279
235
  ) {
280
- return !!source
281
- .find(j.ImportDeclaration)
282
- .filter((path) => path.node.source.value === importPath).length;
236
+ return !!source.find(j.ImportDeclaration).filter((path) => path.node.source.value === importPath)
237
+ .length;
283
238
  }
284
239
 
285
- export default function transformer(
286
- fileInfo: FileInfo,
287
- { jscodeshift: j }: API,
288
- options: Options,
289
- ) {
290
- const source = j(fileInfo.source);
240
+ export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
241
+ const source = j(fileInfo.source);
291
242
 
292
- if (hasImportDeclaration(j, source, '@atlaskit/avatar')) {
293
- updateBorderWidthUsage(j, source);
294
- updateAvatarProps(j, source);
295
- updateAvatarItemProps(j, source);
243
+ if (hasImportDeclaration(j, source, '@atlaskit/avatar')) {
244
+ updateBorderWidthUsage(j, source);
245
+ updateAvatarProps(j, source);
246
+ updateAvatarItemProps(j, source);
296
247
 
297
- return source.toSource(options.printOptions || { quote: 'single' });
298
- }
248
+ return source.toSource(options.printOptions || { quote: 'single' });
249
+ }
299
250
 
300
- return fileInfo.source;
251
+ return fileInfo.source;
301
252
  }