@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 +11 -2
- package/codemods/18.0.0-lite-mode.ts +221 -270
- package/codemods/19.0.0-render-props.ts +100 -132
- package/codemods/__tests__/18.0.0-lite-mode.ts +140 -140
- package/codemods/__tests__/19.0.0-render-props.ts +28 -28
- package/dist/cjs/Avatar.js +7 -7
- package/dist/cjs/AvatarImage.js +3 -1
- package/dist/cjs/AvatarItem.js +1 -1
- package/dist/cjs/IconWrapper.js +1 -0
- package/dist/cjs/Presence.js +2 -0
- package/dist/cjs/Skeleton.js +5 -1
- package/dist/cjs/Status.js +2 -0
- package/dist/es2019/Avatar.js +48 -45
- package/dist/es2019/AvatarImage.js +3 -1
- package/dist/es2019/AvatarItem.js +20 -20
- package/dist/es2019/IconWrapper.js +1 -0
- package/dist/es2019/Presence.js +2 -0
- package/dist/es2019/Skeleton.js +7 -1
- package/dist/es2019/Status.js +2 -0
- package/dist/esm/Avatar.js +7 -7
- package/dist/esm/AvatarImage.js +3 -1
- package/dist/esm/AvatarItem.js +1 -1
- package/dist/esm/IconWrapper.js +1 -0
- package/dist/esm/Presence.js +2 -0
- package/dist/esm/Skeleton.js +5 -1
- package/dist/esm/Status.js +2 -0
- package/dist/types/Avatar.d.ts +5 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types-ts4.5/Avatar.d.ts +5 -1
- package/dist/types-ts4.5/index.d.ts +2 -2
- package/package.json +3 -3
- package/report.api.md +83 -94
|
@@ -1,157 +1,125 @@
|
|
|
1
1
|
// eslint-disable-next-line @repo/internal/fs/filename-pattern-match
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
API,
|
|
4
|
+
ASTPath,
|
|
5
|
+
default as core,
|
|
6
|
+
FileInfo,
|
|
7
|
+
ImportDeclaration,
|
|
8
|
+
ImportSpecifier,
|
|
9
|
+
Options,
|
|
10
10
|
} from 'jscodeshift';
|
|
11
11
|
|
|
12
|
-
function getDefaultSpecifier(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
23
|
-
.find(j.ImportDefaultSpecifier);
|
|
24
|
-
|
|
25
|
-
if (!specifiers.length) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
12
|
+
function getDefaultSpecifier(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
|
|
13
|
+
const specifiers = source
|
|
14
|
+
.find(j.ImportDeclaration)
|
|
15
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
16
|
+
.find(j.ImportDefaultSpecifier);
|
|
17
|
+
|
|
18
|
+
if (!specifiers.length) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
function getImportSpecifier(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
j: core.JSCodeshift,
|
|
26
|
+
source: ReturnType<typeof j>,
|
|
27
|
+
specifier: string,
|
|
28
|
+
imported: string,
|
|
36
29
|
) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!specifiers.length) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
30
|
+
const specifiers = source
|
|
31
|
+
.find(j.ImportDeclaration)
|
|
32
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
33
|
+
.find(j.ImportSpecifier)
|
|
34
|
+
.filter((path: ASTPath<ImportSpecifier>) => path.value.imported.name === imported);
|
|
35
|
+
|
|
36
|
+
if (!specifiers.length) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
53
41
|
}
|
|
54
42
|
|
|
55
|
-
function getJSXAttributesByName(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.find(j.JSXIdentifier)
|
|
66
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
67
|
-
return Boolean(matches.length);
|
|
68
|
-
});
|
|
43
|
+
function getJSXAttributesByName(j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) {
|
|
44
|
+
return j(element)
|
|
45
|
+
.find(j.JSXOpeningElement)
|
|
46
|
+
.find(j.JSXAttribute)
|
|
47
|
+
.filter((attribute) => {
|
|
48
|
+
const matches = j(attribute)
|
|
49
|
+
.find(j.JSXIdentifier)
|
|
50
|
+
.filter((identifier) => identifier.value.name === attributeName);
|
|
51
|
+
return Boolean(matches.length);
|
|
52
|
+
});
|
|
69
53
|
}
|
|
70
54
|
|
|
71
|
-
function wrapChildrenProp(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
),
|
|
111
|
-
j.jsxClosingElement(element.value.openingElement.name),
|
|
112
|
-
[childrenExpression],
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
});
|
|
55
|
+
function wrapChildrenProp(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
|
|
56
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
57
|
+
const componentProp = getJSXAttributesByName(j, element, 'component').get();
|
|
58
|
+
const componentName = j(componentProp).find(j.JSXExpressionContainer).find(j.Expression).get()
|
|
59
|
+
.value.name;
|
|
60
|
+
|
|
61
|
+
const customComponent = j.jsxElement(
|
|
62
|
+
j.jsxOpeningElement(
|
|
63
|
+
j.jsxIdentifier(componentName),
|
|
64
|
+
[j.jsxSpreadAttribute(j.identifier('props'))],
|
|
65
|
+
true,
|
|
66
|
+
),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const childrenExpression = j.jsxExpressionContainer(
|
|
70
|
+
j.arrowFunctionExpression(
|
|
71
|
+
[
|
|
72
|
+
j.objectPattern([
|
|
73
|
+
j.objectProperty(j.identifier('ref'), j.identifier('_')),
|
|
74
|
+
j.restProperty(j.identifier('props')),
|
|
75
|
+
]),
|
|
76
|
+
],
|
|
77
|
+
customComponent,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
j(componentProp).remove();
|
|
82
|
+
j(element).replaceWith(
|
|
83
|
+
j.jsxElement(
|
|
84
|
+
j.jsxOpeningElement(
|
|
85
|
+
element.value.openingElement.name,
|
|
86
|
+
element.value.openingElement.attributes,
|
|
87
|
+
false,
|
|
88
|
+
),
|
|
89
|
+
j.jsxClosingElement(element.value.openingElement.name),
|
|
90
|
+
[childrenExpression],
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
});
|
|
116
94
|
}
|
|
117
95
|
|
|
118
96
|
function hasImportDeclaration(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
97
|
+
j: core.JSCodeshift,
|
|
98
|
+
source: ReturnType<typeof j>,
|
|
99
|
+
importPath: string,
|
|
122
100
|
) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
.filter((path) => path.node.source.value === importPath).length;
|
|
101
|
+
return !!source.find(j.ImportDeclaration).filter((path) => path.node.source.value === importPath)
|
|
102
|
+
.length;
|
|
126
103
|
}
|
|
127
104
|
|
|
128
|
-
export default function transformer(
|
|
129
|
-
|
|
130
|
-
{ jscodeshift: j }: API,
|
|
131
|
-
options: Options,
|
|
132
|
-
) {
|
|
133
|
-
const source = j(fileInfo.source);
|
|
105
|
+
export default function transformer(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) {
|
|
106
|
+
const source = j(fileInfo.source);
|
|
134
107
|
|
|
135
|
-
|
|
136
|
-
|
|
108
|
+
if (hasImportDeclaration(j, source, '@atlaskit/avatar')) {
|
|
109
|
+
const defaultSpecifier = getDefaultSpecifier(j, source, '@atlaskit/avatar');
|
|
137
110
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
111
|
+
if (defaultSpecifier != null) {
|
|
112
|
+
wrapChildrenProp(j, source, defaultSpecifier);
|
|
113
|
+
}
|
|
141
114
|
|
|
142
|
-
|
|
143
|
-
j,
|
|
144
|
-
source,
|
|
145
|
-
'@atlaskit/avatar',
|
|
146
|
-
'AvatarItem',
|
|
147
|
-
);
|
|
115
|
+
const importSpecifier = getImportSpecifier(j, source, '@atlaskit/avatar', 'AvatarItem');
|
|
148
116
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
117
|
+
if (importSpecifier != null) {
|
|
118
|
+
wrapChildrenProp(j, source, importSpecifier);
|
|
119
|
+
}
|
|
152
120
|
|
|
153
|
-
|
|
154
|
-
|
|
121
|
+
return source.toSource(options.printOptions || { quote: 'single' });
|
|
122
|
+
}
|
|
155
123
|
|
|
156
|
-
|
|
124
|
+
return fileInfo.source;
|
|
157
125
|
}
|