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