@atlaskit/textfield 5.1.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +673 -0
  2. package/LICENSE +13 -0
  3. package/README.md +13 -0
  4. package/__perf__/default.tsx +5 -0
  5. package/__perf__/examples.tsx +58 -0
  6. package/codemods/5.0.0-lite-mode.tsx +16 -0
  7. package/codemods/__tests__/5.0.0-lite-mode.tsx +87 -0
  8. package/codemods/__tests__/remove-imports.tsx +64 -0
  9. package/codemods/__tests__/remove-prop.tsx +142 -0
  10. package/codemods/__tests__/rename-imports.tsx +85 -0
  11. package/codemods/migrations/remove-imports.tsx +8 -0
  12. package/codemods/migrations/remove-props.tsx +10 -0
  13. package/codemods/migrations/rename-imports.tsx +15 -0
  14. package/codemods/migrations/utils.tsx +375 -0
  15. package/dist/cjs/component-tokens.js +66 -0
  16. package/dist/cjs/index.js +23 -0
  17. package/dist/cjs/styles.js +231 -0
  18. package/dist/cjs/text-field.js +169 -0
  19. package/dist/cjs/types.js +5 -0
  20. package/dist/cjs/version.json +5 -0
  21. package/dist/es2019/component-tokens.js +46 -0
  22. package/dist/es2019/index.js +2 -0
  23. package/dist/es2019/styles.js +192 -0
  24. package/dist/es2019/text-field.js +129 -0
  25. package/dist/es2019/types.js +1 -0
  26. package/dist/es2019/version.json +5 -0
  27. package/dist/esm/component-tokens.js +46 -0
  28. package/dist/esm/index.js +2 -0
  29. package/dist/esm/styles.js +206 -0
  30. package/dist/esm/text-field.js +145 -0
  31. package/dist/esm/types.js +1 -0
  32. package/dist/esm/version.json +5 -0
  33. package/dist/types/component-tokens.d.ts +44 -0
  34. package/dist/types/index.d.ts +3 -0
  35. package/dist/types/styles.d.ts +208 -0
  36. package/dist/types/text-field.d.ts +14 -0
  37. package/dist/types/types.d.ts +71 -0
  38. package/package.json +79 -0
@@ -0,0 +1,8 @@
1
+ import { createRemoveImportsFor } from './utils';
2
+
3
+ export const removeThemeImports = createRemoveImportsFor({
4
+ importsToRemove: ['ThemeProps', 'ThemeTokens', 'Theme'],
5
+ packagePath: '@atlaskit/textfield',
6
+ comment: `This file uses exports used to help theme @atlaskit/textfield which
7
+ has now been removed due to its poor performance characteristics.`,
8
+ });
@@ -0,0 +1,10 @@
1
+ import { createRemoveFuncFor } from './utils';
2
+
3
+ const component = '@atlaskit/textfield';
4
+ const prop = 'theme';
5
+ const comment = `This file uses the @atlaskit/textfield \`theme\` prop which
6
+ has now been removed due to its poor performance characteristics. We have not replaced
7
+ theme with an equivalent API due to minimal usage of the \`theme\` prop.
8
+ The appearance of TextField will have likely changed.`;
9
+
10
+ export const removeThemeProp = createRemoveFuncFor(component, prop, comment);
@@ -0,0 +1,15 @@
1
+ import { createRenameJSXFunc } from './utils';
2
+
3
+ export const renamethemeTokensImport = createRenameJSXFunc(
4
+ '@atlaskit/textfield',
5
+ 'themeTokens',
6
+ 'TextFieldColors',
7
+ 'DSTextFieldColors',
8
+ );
9
+
10
+ export const renameThemeAppearanceImport = createRenameJSXFunc(
11
+ '@atlaskit/textfield',
12
+ 'ThemeAppearance',
13
+ 'Appearance',
14
+ 'DSTextFieldAppearance',
15
+ );
@@ -0,0 +1,375 @@
1
+ import core, {
2
+ API,
3
+ ASTPath,
4
+ FileInfo,
5
+ Identifier,
6
+ ImportDeclaration,
7
+ ImportSpecifier,
8
+ Options,
9
+ Program,
10
+ } from 'jscodeshift';
11
+ import { Collection } from 'jscodeshift/src/Collection';
12
+
13
+ export type Nullable<T> = T | null;
14
+
15
+ export function getDefaultSpecifier(
16
+ j: core.JSCodeshift,
17
+ source: any,
18
+ specifier: string,
19
+ ) {
20
+ const specifiers = source
21
+ .find(j.ImportDeclaration)
22
+ .filter(
23
+ (path: ASTPath<ImportDeclaration>) =>
24
+ path.node.source.value === specifier,
25
+ )
26
+ .find(j.ImportDefaultSpecifier);
27
+
28
+ if (!specifiers.length) {
29
+ return null;
30
+ }
31
+ return specifiers.nodes()[0]!.local!.name;
32
+ }
33
+ export function getNamedSpecifier(
34
+ j: core.JSCodeshift,
35
+ source: any,
36
+ specifier: string,
37
+ importName: string,
38
+ ) {
39
+ const specifiers = source
40
+ .find(j.ImportDeclaration)
41
+ .filter(
42
+ (path: ASTPath<ImportDeclaration>) =>
43
+ path.node.source.value === specifier,
44
+ )
45
+ .find(j.ImportSpecifier)
46
+ .filter(
47
+ (path: ASTPath<ImportSpecifier>) =>
48
+ path.node.imported.name === importName,
49
+ );
50
+
51
+ if (!specifiers.length) {
52
+ return null;
53
+ }
54
+ return specifiers.nodes()[0]!.local!.name;
55
+ }
56
+
57
+ export function getJSXAttributesByName(
58
+ j: core.JSCodeshift,
59
+ element: ASTPath<any>,
60
+ attributeName: string,
61
+ ) {
62
+ return j(element)
63
+ .find(j.JSXOpeningElement)
64
+ .find(j.JSXAttribute)
65
+ .filter((attribute) => {
66
+ const matches = j(attribute)
67
+ .find(j.JSXIdentifier)
68
+ .filter((identifier) => identifier.value.name === attributeName);
69
+ return Boolean(matches.length);
70
+ });
71
+ }
72
+
73
+ export function hasImportDeclaration(
74
+ j: core.JSCodeshift,
75
+ source: any,
76
+ importPath: string,
77
+ ) {
78
+ const imports = source
79
+ .find(j.ImportDeclaration)
80
+ .filter(
81
+ (path: ASTPath<ImportDeclaration>) =>
82
+ typeof path.node.source.value === 'string' &&
83
+ path.node.source.value.startsWith(importPath),
84
+ );
85
+
86
+ return Boolean(imports.length);
87
+ }
88
+ // not replacing newlines (which \s does)
89
+ const spacesAndTabs: RegExp = /[ \t]{2,}/g;
90
+ const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
91
+
92
+ function clean(value: string): string {
93
+ return (
94
+ value
95
+ .replace(spacesAndTabs, ' ')
96
+ .replace(lineStartWithSpaces, '')
97
+ // using .trim() to clear the any newlines before the first text and after last text
98
+ .trim()
99
+ );
100
+ }
101
+
102
+ export function addCommentToStartOfFile({
103
+ j,
104
+ base,
105
+ message,
106
+ }: {
107
+ j: core.JSCodeshift;
108
+ base: Collection<Node>;
109
+ message: string;
110
+ }) {
111
+ addCommentBefore({
112
+ j,
113
+ target: base.find(j.Program),
114
+ message,
115
+ });
116
+ }
117
+
118
+ export function addCommentBefore({
119
+ j,
120
+ target,
121
+ message,
122
+ }: {
123
+ j: core.JSCodeshift;
124
+ target: Collection<Program> | Collection<ImportDeclaration>;
125
+ message: string;
126
+ }) {
127
+ const content: string = ` TODO: (from codemod) ${clean(message)} `;
128
+ target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
129
+ path.value.comments = path.value.comments || [];
130
+
131
+ const exists = path.value.comments.find(
132
+ (comment) => comment.value === content,
133
+ );
134
+
135
+ // avoiding duplicates of the same comment
136
+ if (exists) {
137
+ return;
138
+ }
139
+
140
+ path.value.comments.push(j.commentBlock(content));
141
+ });
142
+ }
143
+
144
+ export function doesIdentifierExist({
145
+ j,
146
+ base,
147
+ name,
148
+ }: {
149
+ j: core.JSCodeshift;
150
+ base: Collection<any>;
151
+ name: string;
152
+ }): boolean {
153
+ return (
154
+ base
155
+ .find(j.Identifier)
156
+ .filter((identifer: ASTPath<Identifier>) => identifer.value.name === name)
157
+ .length > 0
158
+ );
159
+ }
160
+
161
+ export function getSafeImportName({
162
+ j,
163
+ base,
164
+ currentDefaultSpecifierName,
165
+ desiredName,
166
+ fallbackName,
167
+ }: {
168
+ j: core.JSCodeshift;
169
+ base: Collection<any>;
170
+ currentDefaultSpecifierName: string;
171
+ desiredName: string;
172
+ fallbackName: string;
173
+ }) {
174
+ if (currentDefaultSpecifierName === desiredName) {
175
+ return desiredName;
176
+ }
177
+
178
+ const isUsed: boolean = doesIdentifierExist({ j, base, name: desiredName });
179
+
180
+ return isUsed ? fallbackName : desiredName;
181
+ }
182
+
183
+ export const createRemoveFuncFor = (
184
+ component: string,
185
+ prop: string,
186
+ comment?: string,
187
+ ) => (j: core.JSCodeshift, source: Collection<Node>) => {
188
+ const defaultSpecifier = getDefaultSpecifier(j, source, component);
189
+
190
+ if (!defaultSpecifier) {
191
+ return;
192
+ }
193
+
194
+ source.findJSXElements(defaultSpecifier).forEach((element) => {
195
+ getJSXAttributesByName(j, element, prop).forEach((attribute) => {
196
+ j(attribute).remove();
197
+ if (comment) {
198
+ addCommentToStartOfFile({ j, base: source, message: comment });
199
+ }
200
+ });
201
+ });
202
+ };
203
+
204
+ export const createRemoveImportsFor = ({
205
+ importsToRemove,
206
+ packagePath,
207
+ comment,
208
+ }: {
209
+ importsToRemove: string[];
210
+ packagePath: string;
211
+ comment: string;
212
+ }) => (j: core.JSCodeshift, source: Collection<Node>) => {
213
+ const isUsingName: boolean =
214
+ source
215
+ .find(j.ImportDeclaration)
216
+ .filter((path) => path.node.source.value === packagePath).length > 0;
217
+ if (!isUsingName) {
218
+ return;
219
+ }
220
+
221
+ const existingAliases: Nullable<string>[] =
222
+ source
223
+ .find(j.ImportDeclaration)
224
+ .filter((path) => path.node.source.value === packagePath)
225
+ .find(j.ImportSpecifier)
226
+ .nodes()
227
+ .map(
228
+ (specifier): Nullable<string> => {
229
+ if (!importsToRemove.includes(specifier.imported.name)) {
230
+ return null;
231
+ }
232
+ // If aliased: return the alias
233
+ if (
234
+ specifier.local &&
235
+ !importsToRemove.includes(specifier.local.name)
236
+ ) {
237
+ return specifier.local.name;
238
+ }
239
+
240
+ return null;
241
+ },
242
+ )
243
+ .filter(Boolean) || null;
244
+
245
+ // Add comments
246
+ source
247
+ .find(j.ImportDeclaration)
248
+ .filter((path) => path.node.source.value === packagePath)
249
+ .find(j.ImportSpecifier)
250
+ .filter((importSpecifier) => {
251
+ const identifier = j(importSpecifier).find(j.Identifier).get();
252
+ if (
253
+ importsToRemove.includes(identifier.value.name) ||
254
+ existingAliases.includes(identifier.value.name)
255
+ ) {
256
+ addCommentToStartOfFile({ j, base: source, message: comment });
257
+ return true;
258
+ }
259
+ return false;
260
+ })
261
+ .remove();
262
+
263
+ // Remove entire import if it is empty
264
+ const isEmptyNamedImport =
265
+ source
266
+ .find(j.ImportDeclaration)
267
+ .filter((path) => path.node.source.value === packagePath)
268
+ .find(j.ImportSpecifier)
269
+ .find(j.Identifier).length === 0;
270
+
271
+ if (isEmptyNamedImport) {
272
+ const isEmptyDefaultImport =
273
+ source
274
+ .find(j.ImportDeclaration)
275
+ .filter((path) => path.node.source.value === packagePath)
276
+ .find(j.ImportDefaultSpecifier)
277
+ .find(j.Identifier).length === 0;
278
+
279
+ isEmptyDefaultImport
280
+ ? source
281
+ .find(j.ImportDeclaration)
282
+ .filter((path) => path.node.source.value === packagePath)
283
+ .remove()
284
+ : source
285
+ .find(j.ImportDeclaration)
286
+ .filter((path) => path.node.source.value === packagePath)
287
+ .find(j.ImportSpecifier)
288
+ .remove();
289
+ }
290
+ };
291
+
292
+ export const createRenameJSXFunc = (
293
+ packagePath: string,
294
+ from: string,
295
+ to: string,
296
+ fallback: string | undefined = undefined,
297
+ ) => (j: core.JSCodeshift, source: any) => {
298
+ const namedSpecifier = getNamedSpecifier(j, source, packagePath, from);
299
+
300
+ const toName = fallback
301
+ ? getSafeImportName({
302
+ j,
303
+ base: source,
304
+ currentDefaultSpecifierName: namedSpecifier,
305
+ desiredName: to,
306
+ fallbackName: fallback,
307
+ })
308
+ : to;
309
+
310
+ const existingAlias: Nullable<string> =
311
+ source
312
+ .find(j.ImportDeclaration)
313
+ .filter(
314
+ (path: ASTPath<ImportDeclaration>) =>
315
+ path.node.source.value === packagePath,
316
+ )
317
+ .find(j.ImportSpecifier)
318
+ .nodes()
319
+ .map(
320
+ (specifier: ImportSpecifier): Nullable<string> => {
321
+ if (from !== specifier.imported.name) {
322
+ return null;
323
+ }
324
+ // If aliased: return the alias
325
+ if (specifier.local && from !== specifier.local.name) {
326
+ return specifier.local.name;
327
+ }
328
+
329
+ return null;
330
+ },
331
+ )
332
+ .filter(Boolean)[0] || null;
333
+
334
+ source
335
+ .find(j.ImportDeclaration)
336
+ .filter(
337
+ (path: ASTPath<ImportDeclaration>) =>
338
+ path.node.source.value === packagePath,
339
+ )
340
+ .find(j.ImportSpecifier)
341
+ .filter((importSpecifier: ImportSpecifier) => {
342
+ const identifier = j(importSpecifier).find(j.Identifier).get();
343
+ if (
344
+ from === identifier.value.name ||
345
+ existingAlias === identifier.value.name
346
+ ) {
347
+ return true;
348
+ }
349
+ return false;
350
+ })
351
+ .replaceWith(
352
+ [
353
+ j.importSpecifier(
354
+ j.identifier(toName),
355
+ existingAlias ? j.identifier(existingAlias) : null,
356
+ ),
357
+ ],
358
+ j.literal(packagePath),
359
+ );
360
+ };
361
+
362
+ export const createTransformer = (
363
+ component: string,
364
+ migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[],
365
+ ) => (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options) => {
366
+ const source: Collection<Node> = j(fileInfo.source);
367
+
368
+ if (!hasImportDeclaration(j, source, component)) {
369
+ return fileInfo.source;
370
+ }
371
+
372
+ migrates.forEach((tf) => tf(j, source));
373
+
374
+ return source.toSource(options.printOptions || { quote: 'single' });
375
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.placeholderTextColor = exports.disabledTextColor = exports.textColor = exports.transparent = exports.defaultBorderColorFocus = exports.defaultBorderColor = exports.subtleBackgroundColorHover = exports.defaultBackgroundColorHover = exports.defaultBackgroundColorFocus = exports.defaultBackgroundColor = exports.disabledBackgroundColor = void 0;
7
+
8
+ var _colors = require("@atlaskit/theme/colors");
9
+
10
+ var _tokens = require("@atlaskit/tokens");
11
+
12
+ var disabledBackgroundColor = {
13
+ light: (0, _tokens.token)('color.background.disabled', _colors.N10),
14
+ dark: (0, _tokens.token)('color.background.disabled', _colors.DN10)
15
+ };
16
+ exports.disabledBackgroundColor = disabledBackgroundColor;
17
+ var defaultBackgroundColor = {
18
+ light: (0, _tokens.token)('color.background.subtleBorderedNeutral.resting', _colors.N10),
19
+ dark: (0, _tokens.token)('color.background.subtleBorderedNeutral.resting', _colors.DN10)
20
+ };
21
+ exports.defaultBackgroundColor = defaultBackgroundColor;
22
+ var defaultBackgroundColorFocus = {
23
+ light: (0, _tokens.token)('color.background.default', _colors.N0),
24
+ dark: (0, _tokens.token)('color.background.default', _colors.DN10)
25
+ };
26
+ exports.defaultBackgroundColorFocus = defaultBackgroundColorFocus;
27
+ var defaultBackgroundColorHover = {
28
+ light: (0, _tokens.token)('color.background.default', _colors.N30),
29
+ dark: (0, _tokens.token)('color.background.default', _colors.DN30)
30
+ };
31
+ exports.defaultBackgroundColorHover = defaultBackgroundColorHover;
32
+ var subtleBackgroundColorHover = {
33
+ light: (0, _tokens.token)('color.background.transparentNeutral.hover', _colors.N30),
34
+ dark: (0, _tokens.token)('color.background.transparentNeutral.hover', _colors.DN30)
35
+ };
36
+ exports.subtleBackgroundColorHover = subtleBackgroundColorHover;
37
+ var defaultBorderColor = {
38
+ light: (0, _tokens.token)('color.border.neutral', _colors.N40),
39
+ dark: (0, _tokens.token)('color.border.neutral', _colors.DN40)
40
+ };
41
+ exports.defaultBorderColor = defaultBorderColor;
42
+ var defaultBorderColorFocus = {
43
+ light: (0, _tokens.token)('color.border.focus', _colors.B100),
44
+ dark: (0, _tokens.token)('color.border.focus', _colors.B75)
45
+ };
46
+ exports.defaultBorderColorFocus = defaultBorderColorFocus;
47
+ var transparent = {
48
+ light: 'transparent',
49
+ dark: 'transparent'
50
+ };
51
+ exports.transparent = transparent;
52
+ var textColor = {
53
+ light: (0, _tokens.token)('color.text.highEmphasis', _colors.N900),
54
+ dark: (0, _tokens.token)('color.text.highEmphasis', _colors.DN600)
55
+ };
56
+ exports.textColor = textColor;
57
+ var disabledTextColor = {
58
+ light: (0, _tokens.token)('color.text.disabled', _colors.N70),
59
+ dark: (0, _tokens.token)('color.text.disabled', _colors.DN90)
60
+ };
61
+ exports.disabledTextColor = disabledTextColor;
62
+ var placeholderTextColor = {
63
+ light: (0, _tokens.token)('color.text.lowEmphasis', _colors.N100),
64
+ dark: (0, _tokens.token)('color.text.lowEmphasis', _colors.DN90)
65
+ };
66
+ exports.placeholderTextColor = placeholderTextColor;