@atlaskit/modal-dialog 14.10.3 → 14.10.4
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 +6 -0
- package/codemods/__tests__/not-yet-boolean-autofocus-removal.tsx +155 -0
- package/codemods/migrations/remove-props.tsx +6 -0
- package/codemods/not-yet-boolean-autofocus-removal.tsx +9 -0
- package/codemods/utils.tsx +457 -0
- package/dist/types/hooks.d.ts +2 -1
- package/dist/types/internal/context.d.ts +3 -2
- package/dist/types-ts4.5/hooks.d.ts +2 -1
- package/dist/types-ts4.5/internal/context.d.ts +3 -2
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
jest.autoMockOff();
|
|
2
|
+
|
|
3
|
+
import transformer from '../not-yet-boolean-autofocus-removal';
|
|
4
|
+
|
|
5
|
+
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
6
|
+
|
|
7
|
+
describe('Remove autoFocus prop', () => {
|
|
8
|
+
defineInlineTest(
|
|
9
|
+
{ default: transformer, parser: 'tsx' },
|
|
10
|
+
{},
|
|
11
|
+
`
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
14
|
+
|
|
15
|
+
const SimpleModalDialog = () => {
|
|
16
|
+
return <ModalDialog autoFocus />;
|
|
17
|
+
}
|
|
18
|
+
`,
|
|
19
|
+
`
|
|
20
|
+
import React from 'react';
|
|
21
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
22
|
+
|
|
23
|
+
const SimpleModalDialog = () => {
|
|
24
|
+
return <ModalDialog />;
|
|
25
|
+
}
|
|
26
|
+
`,
|
|
27
|
+
'should remove "true" boolean autoFocus prop from default import',
|
|
28
|
+
);
|
|
29
|
+
defineInlineTest(
|
|
30
|
+
{ default: transformer, parser: 'tsx' },
|
|
31
|
+
{},
|
|
32
|
+
`
|
|
33
|
+
import React from 'react';
|
|
34
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
35
|
+
|
|
36
|
+
const SimpleModalDialog = () => {
|
|
37
|
+
return <ModalDialog autoFocus={true} />;
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
`
|
|
41
|
+
import React from 'react';
|
|
42
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
43
|
+
|
|
44
|
+
const SimpleModalDialog = () => {
|
|
45
|
+
return <ModalDialog />;
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
'should remove boolean true autoFocus prop from default import',
|
|
49
|
+
);
|
|
50
|
+
defineInlineTest(
|
|
51
|
+
{ default: transformer, parser: 'tsx' },
|
|
52
|
+
{},
|
|
53
|
+
`
|
|
54
|
+
import React from 'react';
|
|
55
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
56
|
+
|
|
57
|
+
const SimpleModalDialog = () => {
|
|
58
|
+
return <ModalDialog autoFocus={false} />;
|
|
59
|
+
}
|
|
60
|
+
`,
|
|
61
|
+
`
|
|
62
|
+
import React from 'react';
|
|
63
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
64
|
+
|
|
65
|
+
const SimpleModalDialog = () => {
|
|
66
|
+
return <ModalDialog />;
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
'should remove boolean false autoFocus prop from default import',
|
|
70
|
+
);
|
|
71
|
+
defineInlineTest(
|
|
72
|
+
{ default: transformer, parser: 'tsx' },
|
|
73
|
+
{},
|
|
74
|
+
`
|
|
75
|
+
import React from 'react';
|
|
76
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
77
|
+
|
|
78
|
+
const SimpleModalDialog = () => {
|
|
79
|
+
return <ModalDialog autoFocus={ref} />;
|
|
80
|
+
}
|
|
81
|
+
`,
|
|
82
|
+
`
|
|
83
|
+
import React from 'react';
|
|
84
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
85
|
+
|
|
86
|
+
const SimpleModalDialog = () => {
|
|
87
|
+
return <ModalDialog autoFocus={ref} />;
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
90
|
+
'should not remove non-boolean autoFocus prop from default import',
|
|
91
|
+
);
|
|
92
|
+
defineInlineTest(
|
|
93
|
+
{ default: transformer, parser: 'tsx' },
|
|
94
|
+
{},
|
|
95
|
+
`
|
|
96
|
+
import React from 'react';
|
|
97
|
+
import { ModalDialog } from '@atlaskit/modal-dialog';
|
|
98
|
+
|
|
99
|
+
const SimpleModalDialog = () => {
|
|
100
|
+
return <ModalDialog autoFocus={false} />;
|
|
101
|
+
}
|
|
102
|
+
`,
|
|
103
|
+
`
|
|
104
|
+
import React from 'react';
|
|
105
|
+
import { ModalDialog } from '@atlaskit/modal-dialog';
|
|
106
|
+
|
|
107
|
+
const SimpleModalDialog = () => {
|
|
108
|
+
return <ModalDialog />;
|
|
109
|
+
}
|
|
110
|
+
`,
|
|
111
|
+
'should remove autoFocus prop from named import',
|
|
112
|
+
);
|
|
113
|
+
defineInlineTest(
|
|
114
|
+
{ default: transformer, parser: 'tsx' },
|
|
115
|
+
{},
|
|
116
|
+
`
|
|
117
|
+
import React from 'react';
|
|
118
|
+
import { ModalDialog } from '@foo/bar';
|
|
119
|
+
|
|
120
|
+
const SimpleModalDialog = () => {
|
|
121
|
+
return <ModalDialog autoFocus={false} />;
|
|
122
|
+
}
|
|
123
|
+
`,
|
|
124
|
+
`
|
|
125
|
+
import React from 'react';
|
|
126
|
+
import { ModalDialog } from '@foo/bar';
|
|
127
|
+
|
|
128
|
+
const SimpleModalDialog = () => {
|
|
129
|
+
return <ModalDialog autoFocus={false} />;
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
'should do nothing if not correct import',
|
|
133
|
+
);
|
|
134
|
+
defineInlineTest(
|
|
135
|
+
{ default: transformer, parser: 'tsx' },
|
|
136
|
+
{},
|
|
137
|
+
`
|
|
138
|
+
import React from 'react';
|
|
139
|
+
import { ModalDialog as AkModalDialog } from '@atlaskit/modal-dialog';
|
|
140
|
+
|
|
141
|
+
const SimpleModalDialog = () => {
|
|
142
|
+
return <AkModalDialog autoFocus={false} />;
|
|
143
|
+
}
|
|
144
|
+
`,
|
|
145
|
+
`
|
|
146
|
+
import React from 'react';
|
|
147
|
+
import { ModalDialog as AkModalDialog } from '@atlaskit/modal-dialog';
|
|
148
|
+
|
|
149
|
+
const SimpleModalDialog = () => {
|
|
150
|
+
return <AkModalDialog />;
|
|
151
|
+
}
|
|
152
|
+
`,
|
|
153
|
+
'should remove autoFocus prop with aliased import',
|
|
154
|
+
);
|
|
155
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createRemoveFuncIfBooleanFor } from '../utils';
|
|
2
|
+
|
|
3
|
+
export const removeAutoFocus: (
|
|
4
|
+
j: import('jscodeshift/src/core').JSCodeshift,
|
|
5
|
+
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
6
|
+
) => void = createRemoveFuncIfBooleanFor('@atlaskit/modal-dialog', 'ModalDialog', 'autoFocus');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { API, FileInfo, Options } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
import { removeAutoFocus } from './migrations/remove-props';
|
|
4
|
+
import { createTransformer } from './utils';
|
|
5
|
+
|
|
6
|
+
const transformer: (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string =
|
|
7
|
+
createTransformer('@atlaskit/modal-dialog', [removeAutoFocus]);
|
|
8
|
+
|
|
9
|
+
export default transformer;
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
API,
|
|
3
|
+
ASTPath,
|
|
4
|
+
default as core,
|
|
5
|
+
FileInfo,
|
|
6
|
+
ImportDeclaration,
|
|
7
|
+
ImportDefaultSpecifier,
|
|
8
|
+
ImportSpecifier,
|
|
9
|
+
JSXAttribute,
|
|
10
|
+
Options,
|
|
11
|
+
Program,
|
|
12
|
+
VariableDeclaration,
|
|
13
|
+
} from 'jscodeshift';
|
|
14
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
15
|
+
|
|
16
|
+
export type Nullable<T> = T | null;
|
|
17
|
+
|
|
18
|
+
export function getNamedSpecifier(
|
|
19
|
+
j: core.JSCodeshift,
|
|
20
|
+
source: any,
|
|
21
|
+
specifier: string,
|
|
22
|
+
importName: string,
|
|
23
|
+
): any {
|
|
24
|
+
const specifiers = source
|
|
25
|
+
.find(j.ImportDeclaration)
|
|
26
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
27
|
+
.find(j.ImportSpecifier)
|
|
28
|
+
.filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
|
|
29
|
+
|
|
30
|
+
if (!specifiers.length) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getDefaultSpecifier(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
|
|
37
|
+
const specifiers = source
|
|
38
|
+
.find(j.ImportDeclaration)
|
|
39
|
+
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
40
|
+
.find(j.ImportDefaultSpecifier);
|
|
41
|
+
|
|
42
|
+
if (!specifiers.length) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return specifiers.nodes()[0]!.local!.name;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getJSXAttributesByName(
|
|
49
|
+
j: core.JSCodeshift,
|
|
50
|
+
element: ASTPath<any>,
|
|
51
|
+
attributeName: string,
|
|
52
|
+
): Collection<JSXAttribute> {
|
|
53
|
+
return j(element)
|
|
54
|
+
.find(j.JSXOpeningElement)
|
|
55
|
+
.find(j.JSXAttribute)
|
|
56
|
+
.filter((attribute) => {
|
|
57
|
+
const matches = j(attribute)
|
|
58
|
+
.find(j.JSXIdentifier)
|
|
59
|
+
.filter((identifier) => identifier.value.name === attributeName);
|
|
60
|
+
return Boolean(matches.length);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function hasImportDeclaration(j: core.JSCodeshift, source: any, importPath: string): boolean {
|
|
65
|
+
const imports = source
|
|
66
|
+
.find(j.ImportDeclaration)
|
|
67
|
+
.filter(
|
|
68
|
+
(path: ASTPath<ImportDeclaration>) =>
|
|
69
|
+
typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return Boolean(imports.length);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function findIdentifierAndReplaceAttribute(
|
|
76
|
+
j: core.JSCodeshift,
|
|
77
|
+
source: ReturnType<typeof j>,
|
|
78
|
+
identifierName: string,
|
|
79
|
+
searchAttr: string,
|
|
80
|
+
replaceWithAttr: string,
|
|
81
|
+
): void {
|
|
82
|
+
source
|
|
83
|
+
.find(j.JSXElement)
|
|
84
|
+
.find(j.JSXOpeningElement)
|
|
85
|
+
.filter((path) => {
|
|
86
|
+
return !!j(path.node)
|
|
87
|
+
.find(j.JSXIdentifier)
|
|
88
|
+
.filter((identifier) => identifier.value.name === identifierName);
|
|
89
|
+
})
|
|
90
|
+
.forEach((element) => {
|
|
91
|
+
j(element)
|
|
92
|
+
.find(j.JSXAttribute)
|
|
93
|
+
.find(j.JSXIdentifier)
|
|
94
|
+
.filter((attr) => attr.node.name === searchAttr)
|
|
95
|
+
.forEach((attribute) => {
|
|
96
|
+
j(attribute).replaceWith(j.jsxIdentifier(replaceWithAttr));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function hasVariableAssignment(
|
|
102
|
+
j: core.JSCodeshift,
|
|
103
|
+
source: ReturnType<typeof j>,
|
|
104
|
+
identifierName: string,
|
|
105
|
+
): Collection<VariableDeclaration> | boolean {
|
|
106
|
+
const occurance = source.find(j.VariableDeclaration).filter((path) => {
|
|
107
|
+
return !!j(path.node)
|
|
108
|
+
.find(j.VariableDeclarator)
|
|
109
|
+
.find(j.Identifier)
|
|
110
|
+
.filter((identifier) => {
|
|
111
|
+
return identifier.node.name === identifierName;
|
|
112
|
+
}).length;
|
|
113
|
+
});
|
|
114
|
+
return !!occurance.length ? occurance : false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// not replacing newlines (which \s does)
|
|
118
|
+
const spacesAndTabs: RegExp = /[ \t]{2,}/g;
|
|
119
|
+
const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
|
|
120
|
+
|
|
121
|
+
function clean(value: string): string {
|
|
122
|
+
return (
|
|
123
|
+
value
|
|
124
|
+
.replace(spacesAndTabs, ' ')
|
|
125
|
+
.replace(lineStartWithSpaces, '')
|
|
126
|
+
// using .trim() to clear the any newlines before the first text and after last text
|
|
127
|
+
.trim()
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function addCommentToStartOfFile({
|
|
132
|
+
j,
|
|
133
|
+
base,
|
|
134
|
+
message,
|
|
135
|
+
}: {
|
|
136
|
+
j: core.JSCodeshift;
|
|
137
|
+
base: Collection<Node>;
|
|
138
|
+
message: string;
|
|
139
|
+
}): void {
|
|
140
|
+
addCommentBefore({
|
|
141
|
+
j,
|
|
142
|
+
target: base.find(j.Program),
|
|
143
|
+
message,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function addCommentBefore({
|
|
148
|
+
j,
|
|
149
|
+
target,
|
|
150
|
+
message,
|
|
151
|
+
}: {
|
|
152
|
+
j: core.JSCodeshift;
|
|
153
|
+
target: Collection<Program> | Collection<ImportDeclaration>;
|
|
154
|
+
message: string;
|
|
155
|
+
}): void {
|
|
156
|
+
const content: string = ` TODO: (from codemod) ${clean(message)} `;
|
|
157
|
+
target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
|
|
158
|
+
path.value.comments = path.value.comments || [];
|
|
159
|
+
|
|
160
|
+
const exists = path.value.comments.find((comment) => comment.value === content);
|
|
161
|
+
|
|
162
|
+
// avoiding duplicates of the same comment
|
|
163
|
+
if (exists) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
path.value.comments.push(j.commentBlock(content));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function tryCreateImport({
|
|
172
|
+
j,
|
|
173
|
+
base,
|
|
174
|
+
relativeToPackage,
|
|
175
|
+
packageName,
|
|
176
|
+
}: {
|
|
177
|
+
j: core.JSCodeshift;
|
|
178
|
+
base: Collection<any>;
|
|
179
|
+
relativeToPackage: string;
|
|
180
|
+
packageName: string;
|
|
181
|
+
}): void {
|
|
182
|
+
const exists: boolean =
|
|
183
|
+
base.find(j.ImportDeclaration).filter((path) => path.value.source.value === packageName)
|
|
184
|
+
.length > 0;
|
|
185
|
+
|
|
186
|
+
if (exists) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
base
|
|
191
|
+
.find(j.ImportDeclaration)
|
|
192
|
+
.filter((path) => path.value.source.value === relativeToPackage)
|
|
193
|
+
.insertBefore(j.importDeclaration([], j.literal(packageName)));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function addToImport({
|
|
197
|
+
j,
|
|
198
|
+
base,
|
|
199
|
+
importSpecifier,
|
|
200
|
+
packageName,
|
|
201
|
+
}: {
|
|
202
|
+
j: core.JSCodeshift;
|
|
203
|
+
base: Collection<any>;
|
|
204
|
+
importSpecifier: ImportSpecifier | ImportDefaultSpecifier;
|
|
205
|
+
packageName: string;
|
|
206
|
+
}): void {
|
|
207
|
+
base
|
|
208
|
+
.find(j.ImportDeclaration)
|
|
209
|
+
.filter((path) => path.value.source.value === packageName)
|
|
210
|
+
.replaceWith((declaration) => {
|
|
211
|
+
return j.importDeclaration(
|
|
212
|
+
[
|
|
213
|
+
// we are appending to the existing specifiers
|
|
214
|
+
// We are doing a filter hear because sometimes specifiers can be removed
|
|
215
|
+
// but they hand around in the declaration
|
|
216
|
+
...(declaration.value.specifiers || []).filter(
|
|
217
|
+
(item) => item.type === 'ImportSpecifier' && item.imported != null,
|
|
218
|
+
),
|
|
219
|
+
importSpecifier,
|
|
220
|
+
],
|
|
221
|
+
j.literal(packageName),
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export const createRenameFuncFor: (component: string, importName: string, from: string, to: string) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
227
|
+
(component: string, importName: string, from: string, to: string) =>
|
|
228
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
229
|
+
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
230
|
+
|
|
231
|
+
if (!specifier) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
236
|
+
getJSXAttributesByName(j, element, from).forEach((attribute) => {
|
|
237
|
+
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
let variable = hasVariableAssignment(j, source, specifier);
|
|
242
|
+
if (variable) {
|
|
243
|
+
(variable as Collection<VariableDeclaration>)
|
|
244
|
+
.find(j.VariableDeclarator)
|
|
245
|
+
.forEach((declarator) => {
|
|
246
|
+
j(declarator)
|
|
247
|
+
.find(j.Identifier)
|
|
248
|
+
.filter((identifier) => identifier.name === 'id')
|
|
249
|
+
.forEach((ids) => {
|
|
250
|
+
findIdentifierAndReplaceAttribute(j, source, ids.node.name, from, to);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export const createRemoveFuncIfBooleanFor: (component: string, importName: string, prop: string, comment?: string) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
257
|
+
(component: string, importName: string, prop: string, comment?: string) =>
|
|
258
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
259
|
+
const specifier =
|
|
260
|
+
getNamedSpecifier(j, source, component, importName) ||
|
|
261
|
+
getDefaultSpecifier(j, source, component);
|
|
262
|
+
|
|
263
|
+
if (!specifier) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
source.findJSXElements(specifier).forEach((element) => {
|
|
268
|
+
getJSXAttributesByName(j, element, prop).forEach((attribute) => {
|
|
269
|
+
if (
|
|
270
|
+
attribute.value.value === null ||
|
|
271
|
+
(attribute.value.value?.type === 'JSXExpressionContainer' &&
|
|
272
|
+
attribute.value.value.expression.type === 'BooleanLiteral')
|
|
273
|
+
) {
|
|
274
|
+
j(attribute).remove();
|
|
275
|
+
if (comment) {
|
|
276
|
+
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
export const createRenameImportFor: ({ componentName, newComponentName, oldPackagePath, newPackagePath, }: {
|
|
284
|
+
componentName: string;
|
|
285
|
+
newComponentName?: string;
|
|
286
|
+
oldPackagePath: string;
|
|
287
|
+
newPackagePath: string;
|
|
288
|
+
}) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
289
|
+
({
|
|
290
|
+
componentName,
|
|
291
|
+
newComponentName,
|
|
292
|
+
oldPackagePath,
|
|
293
|
+
newPackagePath,
|
|
294
|
+
}: {
|
|
295
|
+
componentName: string;
|
|
296
|
+
newComponentName?: string;
|
|
297
|
+
oldPackagePath: string;
|
|
298
|
+
newPackagePath: string;
|
|
299
|
+
}) =>
|
|
300
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
301
|
+
const isUsingName: boolean =
|
|
302
|
+
source
|
|
303
|
+
.find(j.ImportDeclaration)
|
|
304
|
+
.filter((path) => path.node.source.value === oldPackagePath)
|
|
305
|
+
.find(j.ImportSpecifier)
|
|
306
|
+
.nodes()
|
|
307
|
+
.filter((specifier) => specifier.imported && specifier.imported.name === componentName)
|
|
308
|
+
.length > 0;
|
|
309
|
+
if (!isUsingName) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const existingAlias: Nullable<string> =
|
|
314
|
+
source
|
|
315
|
+
.find(j.ImportDeclaration)
|
|
316
|
+
.filter((path) => path.node.source.value === oldPackagePath)
|
|
317
|
+
.find(j.ImportSpecifier)
|
|
318
|
+
.nodes()
|
|
319
|
+
.map((specifier): Nullable<string> => {
|
|
320
|
+
if (specifier.imported && specifier.imported.name !== componentName) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
// If aliased: return the alias
|
|
324
|
+
if (specifier.local && specifier.local.name !== componentName) {
|
|
325
|
+
return specifier.local.name;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return null;
|
|
329
|
+
})
|
|
330
|
+
.filter(Boolean)[0] || null;
|
|
331
|
+
|
|
332
|
+
// Check to see if need to create new package path
|
|
333
|
+
// Try create an import declaration just before the old import
|
|
334
|
+
tryCreateImport({
|
|
335
|
+
j,
|
|
336
|
+
base: source,
|
|
337
|
+
relativeToPackage: oldPackagePath,
|
|
338
|
+
packageName: newPackagePath,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const newSpecifier: ImportSpecifier | ImportDefaultSpecifier = (() => {
|
|
342
|
+
// If there's a new name use that
|
|
343
|
+
if (newComponentName) {
|
|
344
|
+
return j.importSpecifier(j.identifier(newComponentName), j.identifier(newComponentName));
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (existingAlias) {
|
|
348
|
+
return j.importSpecifier(j.identifier(componentName), j.identifier(existingAlias));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Add specifier
|
|
352
|
+
return j.importSpecifier(j.identifier(componentName), j.identifier(componentName));
|
|
353
|
+
})();
|
|
354
|
+
|
|
355
|
+
addToImport({
|
|
356
|
+
j,
|
|
357
|
+
base: source,
|
|
358
|
+
importSpecifier: newSpecifier,
|
|
359
|
+
packageName: newPackagePath,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// Remove old path
|
|
363
|
+
source
|
|
364
|
+
.find(j.ImportDeclaration)
|
|
365
|
+
.filter((path) => path.node.source.value === oldPackagePath)
|
|
366
|
+
.remove();
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
export const createRemoveImportsFor: ({ importsToRemove, packagePath, comment, }: {
|
|
370
|
+
importsToRemove: string[];
|
|
371
|
+
packagePath: string;
|
|
372
|
+
comment: string;
|
|
373
|
+
}) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
374
|
+
({
|
|
375
|
+
importsToRemove,
|
|
376
|
+
packagePath,
|
|
377
|
+
comment,
|
|
378
|
+
}: {
|
|
379
|
+
importsToRemove: string[];
|
|
380
|
+
packagePath: string;
|
|
381
|
+
comment: string;
|
|
382
|
+
}) =>
|
|
383
|
+
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
384
|
+
const isUsingName: boolean =
|
|
385
|
+
source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
|
|
386
|
+
.length > 0;
|
|
387
|
+
if (!isUsingName) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const existingAlias: Nullable<string> =
|
|
392
|
+
source
|
|
393
|
+
.find(j.ImportDeclaration)
|
|
394
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
395
|
+
.find(j.ImportSpecifier)
|
|
396
|
+
.nodes()
|
|
397
|
+
.map((specifier): Nullable<string> => {
|
|
398
|
+
if (!importsToRemove.includes(specifier.imported.name)) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
// If aliased: return the alias
|
|
402
|
+
if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
|
|
403
|
+
return specifier.local.name;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return null;
|
|
407
|
+
})
|
|
408
|
+
.filter(Boolean)[0] || null;
|
|
409
|
+
|
|
410
|
+
// Remove imports
|
|
411
|
+
source
|
|
412
|
+
.find(j.ImportDeclaration)
|
|
413
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
414
|
+
.find(j.ImportSpecifier)
|
|
415
|
+
.find(j.Identifier)
|
|
416
|
+
.filter((identifier) => {
|
|
417
|
+
if (
|
|
418
|
+
importsToRemove.includes(identifier.value.name) ||
|
|
419
|
+
identifier.value.name === existingAlias
|
|
420
|
+
) {
|
|
421
|
+
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
return false;
|
|
425
|
+
})
|
|
426
|
+
.remove();
|
|
427
|
+
|
|
428
|
+
// Remove entire import if it is empty
|
|
429
|
+
const isEmptyImport =
|
|
430
|
+
source
|
|
431
|
+
.find(j.ImportDeclaration)
|
|
432
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
433
|
+
.find(j.ImportSpecifier)
|
|
434
|
+
.find(j.Identifier).length === 0;
|
|
435
|
+
if (isEmptyImport) {
|
|
436
|
+
source
|
|
437
|
+
.find(j.ImportDeclaration)
|
|
438
|
+
.filter((path) => path.node.source.value === packagePath)
|
|
439
|
+
.remove();
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
export const createTransformer: (component: string, migrates: {
|
|
444
|
+
(j: core.JSCodeshift, source: Collection<Node>): void;
|
|
445
|
+
}[]) => (fileInfo: FileInfo, api: API, options: Options) => string =
|
|
446
|
+
(component: string, migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[]) =>
|
|
447
|
+
(fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
|
|
448
|
+
const source: Collection<Node> = j(fileInfo.source);
|
|
449
|
+
|
|
450
|
+
if (!hasImportDeclaration(j, source, component)) {
|
|
451
|
+
return fileInfo.source;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
migrates.forEach((tf) => tf(j, source));
|
|
455
|
+
|
|
456
|
+
return source.toSource(options.printOptions || { quote: 'single' });
|
|
457
|
+
};
|
package/dist/types/hooks.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ModalAttributes } from './internal/context';
|
|
2
|
+
export declare const useModal: () => ModalAttributes;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Context } from 'react';
|
|
1
2
|
import { type ModalDialogProps, type OnCloseHandler } from '../types';
|
|
2
3
|
export type ModalAttributes = {
|
|
3
4
|
/**
|
|
@@ -25,5 +26,5 @@ export type ModalAttributes = {
|
|
|
25
26
|
*/
|
|
26
27
|
isFullScreen: boolean;
|
|
27
28
|
};
|
|
28
|
-
export declare const ModalContext:
|
|
29
|
-
export declare const ScrollContext:
|
|
29
|
+
export declare const ModalContext: Context<ModalAttributes | null>;
|
|
30
|
+
export declare const ScrollContext: Context<boolean | null>;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ModalAttributes } from './internal/context';
|
|
2
|
+
export declare const useModal: () => ModalAttributes;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Context } from 'react';
|
|
1
2
|
import { type ModalDialogProps, type OnCloseHandler } from '../types';
|
|
2
3
|
export type ModalAttributes = {
|
|
3
4
|
/**
|
|
@@ -25,5 +26,5 @@ export type ModalAttributes = {
|
|
|
25
26
|
*/
|
|
26
27
|
isFullScreen: boolean;
|
|
27
28
|
};
|
|
28
|
-
export declare const ModalContext:
|
|
29
|
-
export declare const ScrollContext:
|
|
29
|
+
export declare const ModalContext: Context<ModalAttributes | null>;
|
|
30
|
+
export declare const ScrollContext: Context<boolean | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/modal-dialog",
|
|
3
|
-
"version": "14.10.
|
|
3
|
+
"version": "14.10.4",
|
|
4
4
|
"description": "A modal dialog displays content that requires user interaction, in a layer above the page.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@atlaskit/button": "^23.9.0",
|
|
33
33
|
"@atlaskit/css": "^0.19.0",
|
|
34
34
|
"@atlaskit/ds-lib": "^5.3.0",
|
|
35
|
-
"@atlaskit/icon": "^
|
|
35
|
+
"@atlaskit/icon": "^31.0.0",
|
|
36
36
|
"@atlaskit/layering": "^3.6.0",
|
|
37
37
|
"@atlaskit/motion": "^5.3.0",
|
|
38
38
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
@@ -61,12 +61,12 @@
|
|
|
61
61
|
"@atlaskit/breadcrumbs": "^15.3.0",
|
|
62
62
|
"@atlaskit/checkbox": "^17.3.0",
|
|
63
63
|
"@atlaskit/code": "^17.4.0",
|
|
64
|
-
"@atlaskit/datetime-picker": "^17.
|
|
64
|
+
"@atlaskit/datetime-picker": "^17.5.0",
|
|
65
65
|
"@atlaskit/docs": "^11.3.0",
|
|
66
66
|
"@atlaskit/dropdown-menu": "^16.4.0",
|
|
67
67
|
"@atlaskit/flag": "^17.8.0",
|
|
68
68
|
"@atlaskit/form": "^15.3.0",
|
|
69
|
-
"@atlaskit/heading": "^5.
|
|
69
|
+
"@atlaskit/heading": "^5.3.0",
|
|
70
70
|
"@atlaskit/link": "^3.3.0",
|
|
71
71
|
"@atlaskit/popup": "^4.13.0",
|
|
72
72
|
"@atlaskit/radio": "^8.4.0",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"@testing-library/react": "^16.3.0",
|
|
81
81
|
"@testing-library/user-event": "^14.4.3",
|
|
82
82
|
"@types/raf-schd": "^4.0.1",
|
|
83
|
+
"jscodeshift": "^17.0.0",
|
|
83
84
|
"react-dom": "^18.2.0",
|
|
84
85
|
"react-lorem-component": "^0.13.0",
|
|
85
86
|
"react-sweet-state": "^2.6.5",
|