@atlaskit/popup 1.17.2 → 1.18.0

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.
@@ -1,211 +1,178 @@
1
1
  import {
2
- type API,
3
- type ASTPath,
4
- type default as core,
5
- type FileInfo,
6
- type JSXElement,
7
- JSXExpressionContainer,
8
- type Literal,
9
- type Options,
2
+ type API,
3
+ type ASTPath,
4
+ type default as core,
5
+ type FileInfo,
6
+ type JSXElement,
7
+ JSXExpressionContainer,
8
+ type Literal,
9
+ type Options,
10
10
  } from 'jscodeshift';
11
11
  import { type Collection } from 'jscodeshift/src/Collection';
12
12
 
13
13
  import {
14
- addCommentToStartOfFile,
15
- getDefaultSpecifierName,
16
- getJSXAttributesByName,
17
- getSpecifierName,
18
- hasImportDeclaration,
19
- isUsingProp,
20
- updateRenderProps,
14
+ addCommentToStartOfFile,
15
+ getDefaultSpecifierName,
16
+ getJSXAttributesByName,
17
+ getSpecifierName,
18
+ hasImportDeclaration,
19
+ isUsingProp,
20
+ updateRenderProps,
21
21
  } from './utils/helpers';
22
22
 
23
- function updateBoundariesProps(
24
- j: core.JSCodeshift,
25
- source: Collection<any>,
26
- specifier: string,
27
- ) {
28
- source.findJSXElements(specifier).forEach((path: ASTPath<JSXElement>) => {
29
- if (
30
- isUsingProp({
31
- j,
32
- base: source,
33
- element: path,
34
- propName: 'boundariesElement',
35
- })
36
- ) {
37
- // Get value from prop
38
- getJSXAttributesByName({
39
- j,
40
- element: path,
41
- attributeName: 'boundariesElement',
42
- }).forEach((attribute) => {
43
- const expression = attribute.node.value;
44
- if (expression && expression.type === 'StringLiteral') {
45
- const value = expression && expression.value;
46
- if (value === 'window') {
47
- j(attribute).replaceWith(
48
- j.jsxAttribute(
49
- j.jsxIdentifier('rootBoundary'),
50
- j.stringLiteral('document'),
51
- ),
52
- );
53
- } else if (value === 'viewport') {
54
- j(attribute).replaceWith(
55
- j.jsxAttribute(
56
- j.jsxIdentifier('rootBoundary'),
57
- j.stringLiteral('viewport'),
58
- ),
59
- );
60
- } else if (value === 'scrollParents') {
61
- j(attribute).replaceWith(
62
- j.jsxAttribute(
63
- j.jsxIdentifier('boundary'),
64
- j.stringLiteral('clippingParents'),
65
- ),
66
- );
67
- }
68
- }
69
- });
70
- // Add relevant replacement props
23
+ function updateBoundariesProps(j: core.JSCodeshift, source: Collection<any>, specifier: string) {
24
+ source.findJSXElements(specifier).forEach((path: ASTPath<JSXElement>) => {
25
+ if (
26
+ isUsingProp({
27
+ j,
28
+ base: source,
29
+ element: path,
30
+ propName: 'boundariesElement',
31
+ })
32
+ ) {
33
+ // Get value from prop
34
+ getJSXAttributesByName({
35
+ j,
36
+ element: path,
37
+ attributeName: 'boundariesElement',
38
+ }).forEach((attribute) => {
39
+ const expression = attribute.node.value;
40
+ if (expression && expression.type === 'StringLiteral') {
41
+ const value = expression && expression.value;
42
+ if (value === 'window') {
43
+ j(attribute).replaceWith(
44
+ j.jsxAttribute(j.jsxIdentifier('rootBoundary'), j.stringLiteral('document')),
45
+ );
46
+ } else if (value === 'viewport') {
47
+ j(attribute).replaceWith(
48
+ j.jsxAttribute(j.jsxIdentifier('rootBoundary'), j.stringLiteral('viewport')),
49
+ );
50
+ } else if (value === 'scrollParents') {
51
+ j(attribute).replaceWith(
52
+ j.jsxAttribute(j.jsxIdentifier('boundary'), j.stringLiteral('clippingParents')),
53
+ );
54
+ }
55
+ }
56
+ });
57
+ // Add relevant replacement props
71
58
 
72
- // Remove old prop
73
- getJSXAttributesByName({
74
- j,
75
- element: path,
76
- attributeName: 'boundariesElement',
77
- }).remove();
78
- }
79
- });
59
+ // Remove old prop
60
+ getJSXAttributesByName({
61
+ j,
62
+ element: path,
63
+ attributeName: 'boundariesElement',
64
+ }).remove();
65
+ }
66
+ });
80
67
  }
81
68
 
82
- function updateOffset(
83
- j: core.JSCodeshift,
84
- source: Collection<any>,
85
- specifier: string,
86
- ) {
87
- source.findJSXElements(specifier).forEach((path: ASTPath<JSXElement>) => {
88
- getJSXAttributesByName({
89
- j,
90
- element: path,
91
- attributeName: 'offset',
92
- })
93
- .find(JSXExpressionContainer)
94
- .forEach((attribute) => {
95
- const expression = attribute.value.expression;
96
- if (expression.type === 'StringLiteral') {
97
- const value = expression.value;
98
- // Not testing for cases like '10 + 10%' because I assume if you're
99
- // adding or taking numbers it's with units that are not supported
100
- // and will be picked up by the first case
101
- if (
102
- value.includes('%') ||
103
- value.includes('vw') ||
104
- value.includes('vh')
105
- ) {
106
- addCommentToStartOfFile({
107
- j,
108
- base: source,
109
- message: `
69
+ function updateOffset(j: core.JSCodeshift, source: Collection<any>, specifier: string) {
70
+ source.findJSXElements(specifier).forEach((path: ASTPath<JSXElement>) => {
71
+ getJSXAttributesByName({
72
+ j,
73
+ element: path,
74
+ attributeName: 'offset',
75
+ })
76
+ .find(JSXExpressionContainer)
77
+ .forEach((attribute) => {
78
+ const expression = attribute.value.expression;
79
+ if (expression.type === 'StringLiteral') {
80
+ const value = expression.value;
81
+ // Not testing for cases like '10 + 10%' because I assume if you're
82
+ // adding or taking numbers it's with units that are not supported
83
+ // and will be picked up by the first case
84
+ if (value.includes('%') || value.includes('vw') || value.includes('vh')) {
85
+ addCommentToStartOfFile({
86
+ j,
87
+ base: source,
88
+ message: `
110
89
  Popper.js has been upgraded from 1.14.1 to 2.4.2,
111
90
  and as a result the offset prop has changed to be an array. e.g '0px 8px' -> [0, 8]
112
91
  Along with this change you cannot use vw, vh or % units or addition or multiplication
113
92
  Change the offset value to use pixel values
114
93
  Further details can be found in the popper docs https://popper.js.org/docs/v2/modifiers/offset/
115
94
  `,
116
- });
117
- } else if (value.includes(',')) {
118
- // Split by comma
119
- const offsetArray: Literal[] = expression.value
120
- .split(',')
121
- //@ts-ignore
122
- .map((elem) => j.literal(parseInt(elem.replace(/\D/g, ''))));
123
- if (offsetArray.length === 2) {
124
- j(attribute).replaceWith(
125
- j.jsxExpressionContainer(j.arrayExpression(offsetArray)),
126
- );
127
- }
128
- } else {
129
- // Split by space but check if it is a single number
130
- const offsetArray: Literal[] = expression.value
131
- .split(' ')
132
- .filter((elem) => elem.length)
133
- .map((elem) => j.literal(parseInt(elem.replace(/\D/g, ''))));
134
- if (offsetArray.length === 2) {
135
- j(attribute).replaceWith(
136
- j.jsxExpressionContainer(j.arrayExpression(offsetArray)),
137
- );
138
- } else if (offsetArray.length === 1) {
139
- j(attribute).replaceWith(
140
- j.jsxExpressionContainer(
141
- j.arrayExpression([offsetArray[0], j.literal(0)]),
142
- ),
143
- );
144
- }
145
- }
146
- } else if (expression.type === 'NumericLiteral') {
147
- // If it is a single number convert to [number, 0]
148
- j(attribute).replaceWith(
149
- j.jsxExpressionContainer(
150
- j.arrayExpression([expression, j.literal(0)]),
151
- ),
152
- );
153
- } else if (expression.type === 'Identifier') {
154
- // If there is a variable add this comment
155
- addCommentToStartOfFile({
156
- j,
157
- base: source,
158
- message: `
95
+ });
96
+ } else if (value.includes(',')) {
97
+ // Split by comma
98
+ const offsetArray: Literal[] = expression.value
99
+ .split(',')
100
+ //@ts-ignore
101
+ .map((elem) => j.literal(parseInt(elem.replace(/\D/g, ''))));
102
+ if (offsetArray.length === 2) {
103
+ j(attribute).replaceWith(j.jsxExpressionContainer(j.arrayExpression(offsetArray)));
104
+ }
105
+ } else {
106
+ // Split by space but check if it is a single number
107
+ const offsetArray: Literal[] = expression.value
108
+ .split(' ')
109
+ .filter((elem) => elem.length)
110
+ .map((elem) => j.literal(parseInt(elem.replace(/\D/g, ''))));
111
+ if (offsetArray.length === 2) {
112
+ j(attribute).replaceWith(j.jsxExpressionContainer(j.arrayExpression(offsetArray)));
113
+ } else if (offsetArray.length === 1) {
114
+ j(attribute).replaceWith(
115
+ j.jsxExpressionContainer(j.arrayExpression([offsetArray[0], j.literal(0)])),
116
+ );
117
+ }
118
+ }
119
+ } else if (expression.type === 'NumericLiteral') {
120
+ // If it is a single number convert to [number, 0]
121
+ j(attribute).replaceWith(
122
+ j.jsxExpressionContainer(j.arrayExpression([expression, j.literal(0)])),
123
+ );
124
+ } else if (expression.type === 'Identifier') {
125
+ // If there is a variable add this comment
126
+ addCommentToStartOfFile({
127
+ j,
128
+ base: source,
129
+ message: `
159
130
  Popper.js has been upgraded from 1.14.1 to 2.4.2, and as a result the offset
160
131
  prop has changed to be an array. e.g '0px 8px' -> [0, 8]
161
132
  As you are using a variable, you will have change the offset prop manually
162
133
  Further details can be found in the popper docs https://popper.js.org/docs/v2/modifiers/offset/
163
134
  `,
164
- });
165
- }
166
- });
167
- });
135
+ });
136
+ }
137
+ });
138
+ });
168
139
  }
169
140
 
170
- export default function transformer(
171
- file: FileInfo,
172
- { jscodeshift: j }: API,
173
- options: Options,
174
- ) {
175
- const source = j(file.source);
141
+ export default function transformer(file: FileInfo, { jscodeshift: j }: API, options: Options) {
142
+ const source = j(file.source);
176
143
 
177
- // Exit early if not relevant
178
- // We are doing this so we don't touch the formatting of unrelated files
179
- if (!hasImportDeclaration(j, file.source, '@atlaskit/popup')) {
180
- return file.source;
181
- }
144
+ // Exit early if not relevant
145
+ // We are doing this so we don't touch the formatting of unrelated files
146
+ if (!hasImportDeclaration(j, file.source, '@atlaskit/popup')) {
147
+ return file.source;
148
+ }
182
149
 
183
- // Get imported name for the component
184
- var specifier = getDefaultSpecifierName({
185
- j,
186
- base: source,
187
- packageName: '@atlaskit/popup',
188
- });
189
- if (!specifier) {
190
- specifier = getSpecifierName({
191
- j,
192
- base: source,
193
- packageName: '@atlaskit/popup',
194
- component: 'Popup',
195
- });
196
- }
197
- if (!specifier) {
198
- return file.source;
199
- }
150
+ // Get imported name for the component
151
+ var specifier = getDefaultSpecifierName({
152
+ j,
153
+ base: source,
154
+ packageName: '@atlaskit/popup',
155
+ });
156
+ if (!specifier) {
157
+ specifier = getSpecifierName({
158
+ j,
159
+ base: source,
160
+ packageName: '@atlaskit/popup',
161
+ component: 'Popup',
162
+ });
163
+ }
164
+ if (!specifier) {
165
+ return file.source;
166
+ }
200
167
 
201
- // Convert boundaries prop
202
- updateBoundariesProps(j, source, specifier);
168
+ // Convert boundaries prop
169
+ updateBoundariesProps(j, source, specifier);
203
170
 
204
- // Convert offset prop
205
- updateOffset(j, source, specifier);
171
+ // Convert offset prop
172
+ updateOffset(j, source, specifier);
206
173
 
207
- // Rename render props
208
- updateRenderProps(j, source, specifier, 'scheduleUpdate', 'update');
174
+ // Rename render props
175
+ updateRenderProps(j, source, specifier, 'scheduleUpdate', 'update');
209
176
 
210
- return source.toSource(options.printOptions || { quote: 'single' });
177
+ return source.toSource(options.printOptions || { quote: 'single' });
211
178
  }