@atlaskit/modal-dialog 12.0.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 +2111 -0
- package/LICENSE +13 -0
- package/README.md +13 -0
- package/__perf__/default.tsx +42 -0
- package/__perf__/interactions.tsx +136 -0
- package/__perf__/scroll.tsx +98 -0
- package/codemods/12.0.0-lite-mode.ts +51 -0
- package/codemods/__tests__/12.0.0-lite-mode.test.ts +493 -0
- package/codemods/__tests__/handle-prop-spread.tsx +276 -0
- package/codemods/__tests__/inline-WidthNames-declaration.test.ts +260 -0
- package/codemods/__tests__/map-actions-prop.tsx +436 -0
- package/codemods/__tests__/map-body-from-props.test.ts +645 -0
- package/codemods/__tests__/map-container-from-props.test.ts +323 -0
- package/codemods/__tests__/map-footer-from-props.test.ts +544 -0
- package/codemods/__tests__/map-header-from-props.test.ts +559 -0
- package/codemods/__tests__/map-heading-prop.tsx +438 -0
- package/codemods/__tests__/remove-appearance-prop.test.ts +79 -0
- package/codemods/__tests__/remove-component-override-props.test.ts +153 -0
- package/codemods/__tests__/remove-is-chromeless.tsx +182 -0
- package/codemods/__tests__/rename-appearance-type.test.ts +52 -0
- package/codemods/__tests__/rename-inner-component-prop-types.test.ts +82 -0
- package/codemods/__tests__/rename-scrollBehavior-to-shouldScrollInViewport.test.ts +237 -0
- package/codemods/internal/constants.tsx +41 -0
- package/codemods/internal/utils.tsx +223 -0
- package/codemods/migrations/handle-prop-spread.tsx +51 -0
- package/codemods/migrations/inline-WidthNames-declaration.ts +92 -0
- package/codemods/migrations/map-actions-prop.tsx +430 -0
- package/codemods/migrations/map-body-from-props.ts +147 -0
- package/codemods/migrations/map-container-from-props.ts +72 -0
- package/codemods/migrations/map-footer-from-props.ts +107 -0
- package/codemods/migrations/map-header-from-props.ts +101 -0
- package/codemods/migrations/map-heading-prop.tsx +193 -0
- package/codemods/migrations/remove-appearance-prop.ts +27 -0
- package/codemods/migrations/remove-component-override-props.ts +84 -0
- package/codemods/migrations/remove-is-chromeless.tsx +42 -0
- package/codemods/migrations/rename-appearance-type.ts +9 -0
- package/codemods/migrations/rename-inner-component-prop-types.ts +28 -0
- package/codemods/migrations/rename-scrollBehavior-to-shouldScrollInViewport.ts +82 -0
- package/dist/cjs/hooks.js +22 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/internal/components/modal-dialog.js +155 -0
- package/dist/cjs/internal/components/positioner.js +89 -0
- package/dist/cjs/internal/components/scroll-container.js +138 -0
- package/dist/cjs/internal/constants.js +48 -0
- package/dist/cjs/internal/context.js +13 -0
- package/dist/cjs/internal/hooks/use-modal-stack.js +110 -0
- package/dist/cjs/internal/hooks/use-on-motion-finish.js +24 -0
- package/dist/cjs/internal/hooks/use-prevent-programmatic-scroll.js +55 -0
- package/dist/cjs/internal/hooks/use-scroll.js +20 -0
- package/dist/cjs/internal/utils.js +35 -0
- package/dist/cjs/modal-body.js +66 -0
- package/dist/cjs/modal-footer.js +40 -0
- package/dist/cjs/modal-header.js +43 -0
- package/dist/cjs/modal-title.js +108 -0
- package/dist/cjs/modal-transition.js +21 -0
- package/dist/cjs/modal-wrapper.js +126 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/hooks.js +11 -0
- package/dist/es2019/index.js +7 -0
- package/dist/es2019/internal/components/modal-dialog.js +120 -0
- package/dist/es2019/internal/components/positioner.js +78 -0
- package/dist/es2019/internal/components/scroll-container.js +97 -0
- package/dist/es2019/internal/constants.js +27 -0
- package/dist/es2019/internal/context.js +3 -0
- package/dist/es2019/internal/hooks/use-modal-stack.js +85 -0
- package/dist/es2019/internal/hooks/use-on-motion-finish.js +17 -0
- package/dist/es2019/internal/hooks/use-prevent-programmatic-scroll.js +39 -0
- package/dist/es2019/internal/hooks/use-scroll.js +11 -0
- package/dist/es2019/internal/utils.js +22 -0
- package/dist/es2019/modal-body.js +50 -0
- package/dist/es2019/modal-footer.js +30 -0
- package/dist/es2019/modal-header.js +30 -0
- package/dist/es2019/modal-title.js +94 -0
- package/dist/es2019/modal-transition.js +10 -0
- package/dist/es2019/modal-wrapper.js +88 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/hooks.js +11 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/internal/components/modal-dialog.js +131 -0
- package/dist/esm/internal/components/positioner.js +76 -0
- package/dist/esm/internal/components/scroll-container.js +114 -0
- package/dist/esm/internal/constants.js +27 -0
- package/dist/esm/internal/context.js +3 -0
- package/dist/esm/internal/hooks/use-modal-stack.js +96 -0
- package/dist/esm/internal/hooks/use-on-motion-finish.js +16 -0
- package/dist/esm/internal/hooks/use-prevent-programmatic-scroll.js +44 -0
- package/dist/esm/internal/hooks/use-scroll.js +11 -0
- package/dist/esm/internal/utils.js +22 -0
- package/dist/esm/modal-body.js +49 -0
- package/dist/esm/modal-footer.js +29 -0
- package/dist/esm/modal-header.js +29 -0
- package/dist/esm/modal-title.js +93 -0
- package/dist/esm/modal-transition.js +10 -0
- package/dist/esm/modal-wrapper.js +96 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/hooks.d.ts +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/internal/components/modal-dialog.d.ts +3 -0
- package/dist/types/internal/components/positioner.d.ts +10 -0
- package/dist/types/internal/components/scroll-container.d.ts +20 -0
- package/dist/types/internal/constants.d.ts +25 -0
- package/dist/types/internal/context.d.ts +20 -0
- package/dist/types/internal/hooks/use-modal-stack.d.ts +13 -0
- package/dist/types/internal/hooks/use-on-motion-finish.d.ts +4 -0
- package/dist/types/internal/hooks/use-prevent-programmatic-scroll.d.ts +7 -0
- package/dist/types/internal/hooks/use-scroll.d.ts +1 -0
- package/dist/types/internal/utils.d.ts +3 -0
- package/dist/types/modal-body.d.ts +16 -0
- package/dist/types/modal-footer.d.ts +16 -0
- package/dist/types/modal-header.d.ts +16 -0
- package/dist/types/modal-title.d.ts +26 -0
- package/dist/types/modal-transition.d.ts +3 -0
- package/dist/types/modal-wrapper.d.ts +5 -0
- package/dist/types/types.d.ts +90 -0
- package/extract-react-types/modal-attributes.tsx +5 -0
- package/hooks/package.json +7 -0
- package/modal-body/package.json +7 -0
- package/modal-dialog/package.json +7 -0
- package/modal-footer/package.json +7 -0
- package/modal-header/package.json +7 -0
- package/modal-title/package.json +7 -0
- package/modal-transition/package.json +7 -0
- package/package.json +113 -0
- package/types/package.json +7 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createTransformer } from '@atlaskit/codemod-utils';
|
|
2
|
+
|
|
3
|
+
import { renameScrollBehaviorToShouldScrollInViewport } from '../migrations/rename-scrollBehavior-to-shouldScrollInViewport';
|
|
4
|
+
|
|
5
|
+
const transformer = createTransformer([
|
|
6
|
+
renameScrollBehaviorToShouldScrollInViewport,
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
10
|
+
|
|
11
|
+
describe('rename scrollBehavior prop', () => {
|
|
12
|
+
['tsx', 'babylon'].forEach((parser) => {
|
|
13
|
+
describe(`parser: ${parser}`, () => {
|
|
14
|
+
defineInlineTest(
|
|
15
|
+
{ default: transformer, parser },
|
|
16
|
+
{},
|
|
17
|
+
`
|
|
18
|
+
import React from 'react';
|
|
19
|
+
|
|
20
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
21
|
+
|
|
22
|
+
export default function modalDialog() {
|
|
23
|
+
return (
|
|
24
|
+
<ModalDialog
|
|
25
|
+
testId="modal-dialog"
|
|
26
|
+
scrollBehavior="outside"
|
|
27
|
+
appearance="warning"
|
|
28
|
+
>
|
|
29
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
30
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
31
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
32
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
33
|
+
</ModalDialog>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
`,
|
|
37
|
+
`
|
|
38
|
+
import React from 'react';
|
|
39
|
+
|
|
40
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
41
|
+
|
|
42
|
+
export default function modalDialog() {
|
|
43
|
+
return (
|
|
44
|
+
<ModalDialog
|
|
45
|
+
testId="modal-dialog"
|
|
46
|
+
shouldScrollInViewport
|
|
47
|
+
appearance="warning"
|
|
48
|
+
>
|
|
49
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
50
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
51
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
52
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
53
|
+
</ModalDialog>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
`,
|
|
57
|
+
'should change scrollBehavior="outside" to shouldScrollInViewport',
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
defineInlineTest(
|
|
61
|
+
{ default: transformer, parser },
|
|
62
|
+
{},
|
|
63
|
+
`
|
|
64
|
+
import React from 'react';
|
|
65
|
+
|
|
66
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
67
|
+
|
|
68
|
+
export default function modalDialog() {
|
|
69
|
+
return (
|
|
70
|
+
<ModalDialog
|
|
71
|
+
testId="modal-dialog"
|
|
72
|
+
scrollBehavior="inside"
|
|
73
|
+
appearance="warning"
|
|
74
|
+
>
|
|
75
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
76
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
77
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
78
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
79
|
+
</ModalDialog>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
`
|
|
84
|
+
import React from 'react';
|
|
85
|
+
|
|
86
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
87
|
+
|
|
88
|
+
export default function modalDialog() {
|
|
89
|
+
return (
|
|
90
|
+
<ModalDialog testId="modal-dialog" appearance="warning">
|
|
91
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
92
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
93
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
94
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
95
|
+
</ModalDialog>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
`,
|
|
99
|
+
'should remove scrollBehavior="inside" as it is default behaviour',
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
defineInlineTest(
|
|
103
|
+
{ default: transformer, parser },
|
|
104
|
+
{},
|
|
105
|
+
`
|
|
106
|
+
import React from 'react';
|
|
107
|
+
|
|
108
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
109
|
+
|
|
110
|
+
export default function modalDialog() {
|
|
111
|
+
return (
|
|
112
|
+
<ModalDialog
|
|
113
|
+
testId="modal-dialog"
|
|
114
|
+
scrollBehavior="inside-wide"
|
|
115
|
+
appearance="warning"
|
|
116
|
+
>
|
|
117
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
118
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
119
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
120
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
121
|
+
</ModalDialog>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
`,
|
|
125
|
+
`
|
|
126
|
+
import React from 'react';
|
|
127
|
+
|
|
128
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
129
|
+
|
|
130
|
+
export default function modalDialog() {
|
|
131
|
+
return (
|
|
132
|
+
<ModalDialog testId="modal-dialog" appearance="warning">
|
|
133
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
134
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
135
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
136
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
137
|
+
</ModalDialog>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
`,
|
|
141
|
+
'should remove scrollBehavior="inside-wide" as it is now default behaviour',
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
defineInlineTest(
|
|
145
|
+
{ default: transformer, parser },
|
|
146
|
+
{},
|
|
147
|
+
`
|
|
148
|
+
import React from 'react';
|
|
149
|
+
|
|
150
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
151
|
+
|
|
152
|
+
export default function modalDialog() {
|
|
153
|
+
return (
|
|
154
|
+
<ModalDialog
|
|
155
|
+
testId="modal-dialog"
|
|
156
|
+
scrollBehavior={scrollBehavior}
|
|
157
|
+
appearance="warning"
|
|
158
|
+
>
|
|
159
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
160
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
161
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
162
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
163
|
+
</ModalDialog>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
`,
|
|
167
|
+
`
|
|
168
|
+
import React from 'react';
|
|
169
|
+
|
|
170
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
171
|
+
|
|
172
|
+
export default function modalDialog() {
|
|
173
|
+
return (
|
|
174
|
+
<ModalDialog
|
|
175
|
+
testId="modal-dialog"
|
|
176
|
+
shouldScrollInViewport={scrollBehavior === "outside"}
|
|
177
|
+
appearance="warning"
|
|
178
|
+
>
|
|
179
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
180
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
181
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
182
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
183
|
+
</ModalDialog>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
`,
|
|
187
|
+
'should assert scrollBehavior variable to convert to shouldScrollInViewport',
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
defineInlineTest(
|
|
191
|
+
{ default: transformer, parser },
|
|
192
|
+
{},
|
|
193
|
+
`
|
|
194
|
+
import React from 'react';
|
|
195
|
+
|
|
196
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
197
|
+
|
|
198
|
+
export default function modalDialog() {
|
|
199
|
+
return (
|
|
200
|
+
<ModalDialog
|
|
201
|
+
testId="modal-dialog"
|
|
202
|
+
scrollBehavior={"outside"}
|
|
203
|
+
appearance="warning"
|
|
204
|
+
>
|
|
205
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
206
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
207
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
208
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
209
|
+
</ModalDialog>
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
`,
|
|
213
|
+
`
|
|
214
|
+
import React from 'react';
|
|
215
|
+
|
|
216
|
+
import ModalDialog from '@atlaskit/modal-dialog';
|
|
217
|
+
|
|
218
|
+
export default function modalDialog() {
|
|
219
|
+
return (
|
|
220
|
+
<ModalDialog
|
|
221
|
+
testId="modal-dialog"
|
|
222
|
+
shouldScrollInViewport
|
|
223
|
+
appearance="warning"
|
|
224
|
+
>
|
|
225
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
|
|
226
|
+
Proin aliquet faucibus velit id ornare. Nam urna ante, consequat
|
|
227
|
+
vitae viverra non, hendrerit in lorem. Sed fringilla dolor
|
|
228
|
+
eget nisi eleifend lacinia ut a ligula.
|
|
229
|
+
</ModalDialog>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
`,
|
|
233
|
+
'should change scrollBehavior value passed in an expression container to shouldScrollInViewport',
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const PACKAGE_NAME = '@atlaskit/modal-dialog';
|
|
2
|
+
|
|
3
|
+
export const ACTIONS_PROP_NAME = 'actions';
|
|
4
|
+
export const HEADING_PROP_NAME = 'heading';
|
|
5
|
+
export const HEADER_PROP_NAME = 'header';
|
|
6
|
+
export const BODY_PROP_NAME = 'body';
|
|
7
|
+
export const FOOTER_PROP_NAME = 'footer';
|
|
8
|
+
export const APPEARANCE_PROP_NAME = 'appearance';
|
|
9
|
+
export const AUTOFOCUS_PROP_NAME = 'autoFocus';
|
|
10
|
+
export const COMPONENTS_PROP_NAME = 'components';
|
|
11
|
+
export const IS_HEADING_MULTILINE_PROP_NAME = 'isHeadingMultiline';
|
|
12
|
+
export const IS_MULTILINE_PROP_NAME = 'isMultiline';
|
|
13
|
+
export const IS_CHROMELESS_PROP_NAME = 'isChromeless';
|
|
14
|
+
|
|
15
|
+
export const SHARED_VARIABLES_ENDPOINT = `${PACKAGE_NAME}/shared-variables`;
|
|
16
|
+
export const WIDTH_NAMES_TYPE_NAME = 'WidthNames';
|
|
17
|
+
|
|
18
|
+
export const MODAL_HEADER_COMPONENT_NAME = 'ModalHeader';
|
|
19
|
+
export const MODAL_HEADER_COMPONENT_FALLBACK_NAME = 'AKModalHeader';
|
|
20
|
+
export const MODAL_HEADER_TYPE_NAME = `${MODAL_HEADER_COMPONENT_NAME}Props`;
|
|
21
|
+
export const MODAL_HEADER_ENDPOINT = `${PACKAGE_NAME}/modal-header`;
|
|
22
|
+
|
|
23
|
+
export const MODAL_TITLE_COMPONENT_NAME = 'ModalTitle';
|
|
24
|
+
export const MODAL_TITLE_COMPONENT_FALLBACK_NAME = 'AKModalTitle';
|
|
25
|
+
export const MODAL_TITLE_TYPE_NAME = `${MODAL_TITLE_COMPONENT_NAME}Props`;
|
|
26
|
+
export const MODAL_TITLE_ENDPOINT = `${PACKAGE_NAME}/modal-title`;
|
|
27
|
+
|
|
28
|
+
export const MODAL_BODY_COMPONENT_NAME = 'ModalBody';
|
|
29
|
+
export const MODAL_BODY_COMPONENT_FALLBACK_NAME = 'AKModalBody';
|
|
30
|
+
export const MODAL_BODY_TYPE_NAME = `${MODAL_BODY_COMPONENT_NAME}Props`;
|
|
31
|
+
export const MODAL_BODY_ENDPOINT = `${PACKAGE_NAME}/modal-body`;
|
|
32
|
+
|
|
33
|
+
export const MODAL_FOOTER_COMPONENT_NAME = 'ModalFooter';
|
|
34
|
+
export const MODAL_FOOTER_COMPONENT_FALLBACK_NAME = 'AKModalFooter';
|
|
35
|
+
export const MODAL_FOOTER_TYPE_NAME = `${MODAL_FOOTER_COMPONENT_NAME}Props`;
|
|
36
|
+
export const MODAL_FOOTER_ENDPOINT = `${PACKAGE_NAME}/modal-footer`;
|
|
37
|
+
|
|
38
|
+
export const BUTTON_PACKAGE_NAME = '@atlaskit/button';
|
|
39
|
+
export const BUTTON_COMPONENT_NAME = 'Button';
|
|
40
|
+
export const BUTTON_COMPONENT_FALLBACK_NAME = 'AKButton';
|
|
41
|
+
export const BUTTON_ENDPOINT = `${BUTTON_PACKAGE_NAME}/standard-button`;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import core, {
|
|
2
|
+
ASTPath,
|
|
3
|
+
ImportDeclaration,
|
|
4
|
+
ImportDefaultSpecifier,
|
|
5
|
+
ImportNamespaceSpecifier,
|
|
6
|
+
ImportSpecifier,
|
|
7
|
+
JSXAttribute,
|
|
8
|
+
JSXElement,
|
|
9
|
+
JSXExpressionContainer,
|
|
10
|
+
JSXFragment,
|
|
11
|
+
JSXSpreadChild,
|
|
12
|
+
ObjectExpression,
|
|
13
|
+
ObjectProperty,
|
|
14
|
+
StringLiteral,
|
|
15
|
+
VariableDeclaration,
|
|
16
|
+
VariableDeclarator,
|
|
17
|
+
} from 'jscodeshift';
|
|
18
|
+
import { Collection } from 'jscodeshift/src/Collection';
|
|
19
|
+
|
|
20
|
+
import { getJSXAttributesByName } from '@atlaskit/codemod-utils';
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
APPEARANCE_PROP_NAME,
|
|
24
|
+
IS_HEADING_MULTILINE_PROP_NAME,
|
|
25
|
+
PACKAGE_NAME,
|
|
26
|
+
} from './constants';
|
|
27
|
+
|
|
28
|
+
export const getOverrideFromIndividualProp = (
|
|
29
|
+
j: core.JSCodeshift,
|
|
30
|
+
element: ASTPath<JSXElement>,
|
|
31
|
+
attributeName: string,
|
|
32
|
+
) => {
|
|
33
|
+
let override;
|
|
34
|
+
getJSXAttributesByName(j, element, attributeName).forEach(
|
|
35
|
+
(attribute: ASTPath<JSXAttribute>) => {
|
|
36
|
+
const { value } = attribute.node;
|
|
37
|
+
|
|
38
|
+
if (value && value.type === 'JSXExpressionContainer') {
|
|
39
|
+
override = (value as JSXExpressionContainer).expression;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return override;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const getOverrideFromComponentsProp = (
|
|
48
|
+
j: core.JSCodeshift,
|
|
49
|
+
element: ASTPath<JSXElement>,
|
|
50
|
+
attributeName: string,
|
|
51
|
+
keyName: string,
|
|
52
|
+
) => {
|
|
53
|
+
let override;
|
|
54
|
+
getJSXAttributesByName(j, element, attributeName).forEach(
|
|
55
|
+
(attribute: ASTPath<JSXAttribute>) => {
|
|
56
|
+
const { value } = attribute.node;
|
|
57
|
+
|
|
58
|
+
if (value && value.type === 'JSXExpressionContainer') {
|
|
59
|
+
if (
|
|
60
|
+
(value as JSXExpressionContainer).expression.type ===
|
|
61
|
+
'ObjectExpression'
|
|
62
|
+
) {
|
|
63
|
+
const valueExpression = value.expression as ObjectExpression;
|
|
64
|
+
const overrideFromComponentsProp = valueExpression.properties
|
|
65
|
+
.filter((property) => property.type === 'ObjectProperty')
|
|
66
|
+
.map((property) => property as ObjectProperty)
|
|
67
|
+
.find(
|
|
68
|
+
(property: ObjectProperty) =>
|
|
69
|
+
property.key.type === 'Identifier' &&
|
|
70
|
+
property.key.name === keyName,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (overrideFromComponentsProp) {
|
|
74
|
+
override = overrideFromComponentsProp.value;
|
|
75
|
+
valueExpression.properties = valueExpression.properties.filter(
|
|
76
|
+
(property: any) => property !== overrideFromComponentsProp,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return override;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const getAppearanceFromProp = (
|
|
88
|
+
j: core.JSCodeshift,
|
|
89
|
+
element: ASTPath<JSXElement>,
|
|
90
|
+
) => {
|
|
91
|
+
let appearance;
|
|
92
|
+
getJSXAttributesByName(j, element, APPEARANCE_PROP_NAME).forEach(
|
|
93
|
+
(attribute: ASTPath<JSXAttribute>) => {
|
|
94
|
+
const { value } = attribute.node;
|
|
95
|
+
|
|
96
|
+
if (value && value.type === 'StringLiteral') {
|
|
97
|
+
// <ModalDialog appearance="warning" />
|
|
98
|
+
appearance = j.stringLiteral((value as StringLiteral).value);
|
|
99
|
+
} else if (value && value.type === 'JSXExpressionContainer') {
|
|
100
|
+
// <ModalDialog appearance={appearance} />
|
|
101
|
+
appearance = (value as JSXExpressionContainer).expression;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return appearance;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export const getIsMultilineFromProp = (
|
|
110
|
+
j: core.JSCodeshift,
|
|
111
|
+
element: ASTPath<JSXElement>,
|
|
112
|
+
) => {
|
|
113
|
+
let isMultiline;
|
|
114
|
+
getJSXAttributesByName(j, element, IS_HEADING_MULTILINE_PROP_NAME).forEach(
|
|
115
|
+
(attribute: ASTPath<JSXAttribute>) => {
|
|
116
|
+
const { value } = attribute.node;
|
|
117
|
+
if (value === null) {
|
|
118
|
+
// <ModalDialog isHeadingMultiline />
|
|
119
|
+
isMultiline = value;
|
|
120
|
+
j(attribute).remove();
|
|
121
|
+
} else if (value && value.type === 'JSXExpressionContainer') {
|
|
122
|
+
// <ModalDialog isHeadingMultiline={true} />
|
|
123
|
+
isMultiline = (value as JSXExpressionContainer).expression;
|
|
124
|
+
j(attribute).remove();
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return isMultiline;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
export const replaceChildren = (
|
|
133
|
+
j: core.JSCodeshift,
|
|
134
|
+
element: ASTPath<JSXElement>,
|
|
135
|
+
specifier: string,
|
|
136
|
+
children: JSXElement | JSXExpressionContainer | JSXFragment | JSXSpreadChild,
|
|
137
|
+
) => {
|
|
138
|
+
j(element)
|
|
139
|
+
.find(j.JSXOpeningElement)
|
|
140
|
+
.forEach((openingElement) => {
|
|
141
|
+
const openingElementName = openingElement.value.name;
|
|
142
|
+
if (
|
|
143
|
+
openingElementName.type === 'JSXIdentifier' &&
|
|
144
|
+
openingElementName.name === specifier
|
|
145
|
+
) {
|
|
146
|
+
j(element).replaceWith(
|
|
147
|
+
j.jsxElement(
|
|
148
|
+
j.jsxOpeningElement(
|
|
149
|
+
j.jsxIdentifier(specifier),
|
|
150
|
+
openingElement.value.attributes,
|
|
151
|
+
),
|
|
152
|
+
j.jsxClosingElement(j.jsxIdentifier(specifier)),
|
|
153
|
+
[j.jsxText('\n'), children, j.jsxText('\n')],
|
|
154
|
+
),
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export const getComponentImportName = (
|
|
161
|
+
j: core.JSCodeshift,
|
|
162
|
+
componentDefaultName: string,
|
|
163
|
+
componentAliasName: string,
|
|
164
|
+
) => {
|
|
165
|
+
return isAliasImport(componentDefaultName, componentAliasName)
|
|
166
|
+
? j.importSpecifier(
|
|
167
|
+
j.identifier(componentAliasName),
|
|
168
|
+
j.identifier(componentDefaultName),
|
|
169
|
+
)
|
|
170
|
+
: j.importSpecifier(j.identifier(componentDefaultName));
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const isAliasImport = (
|
|
174
|
+
componentDefaultName: string,
|
|
175
|
+
componentAliasName: string,
|
|
176
|
+
) => componentDefaultName !== componentAliasName;
|
|
177
|
+
|
|
178
|
+
export const addToImport = (
|
|
179
|
+
j: core.JSCodeshift,
|
|
180
|
+
source: Collection<Node>,
|
|
181
|
+
specifiers: (
|
|
182
|
+
| ImportSpecifier
|
|
183
|
+
| ImportDefaultSpecifier
|
|
184
|
+
| ImportNamespaceSpecifier
|
|
185
|
+
)[],
|
|
186
|
+
packageEndpoint?: string,
|
|
187
|
+
) => {
|
|
188
|
+
const endpoint = packageEndpoint ?? PACKAGE_NAME;
|
|
189
|
+
|
|
190
|
+
source
|
|
191
|
+
.find(j.ImportDeclaration)
|
|
192
|
+
.filter(
|
|
193
|
+
(path: ASTPath<ImportDeclaration>) => path.node.source.value === endpoint,
|
|
194
|
+
)
|
|
195
|
+
.forEach((path: ASTPath<ImportDeclaration>) => {
|
|
196
|
+
j(path).replaceWith(
|
|
197
|
+
j.importDeclaration(
|
|
198
|
+
[...(path.value.specifiers || []), ...specifiers],
|
|
199
|
+
j.literal(endpoint),
|
|
200
|
+
),
|
|
201
|
+
);
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export const getVariableDeclarationPathByName = (
|
|
206
|
+
j: core.JSCodeshift,
|
|
207
|
+
source: Collection<Node>,
|
|
208
|
+
variableName: string,
|
|
209
|
+
) => {
|
|
210
|
+
return source
|
|
211
|
+
.find(j.VariableDeclaration)
|
|
212
|
+
.filter((variableDeclarationPath: ASTPath<VariableDeclaration>) => {
|
|
213
|
+
return (
|
|
214
|
+
j(variableDeclarationPath)
|
|
215
|
+
.find(j.VariableDeclarator)
|
|
216
|
+
.filter(
|
|
217
|
+
(variableDeclaratorPath: ASTPath<VariableDeclarator>) =>
|
|
218
|
+
variableDeclaratorPath.node.id.type === 'Identifier' &&
|
|
219
|
+
variableDeclaratorPath.node.id.name === variableName,
|
|
220
|
+
).length > 0
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
};
|