@workday/canvas-kit-codemod 6.9.0-next.0 → 6.9.0-next.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/dist/es6/v5/recategorizeButtons.js +1 -1
- package/dist/es6/v6/moveAndRenameSearchBar.d.ts.map +1 -1
- package/dist/es6/v6/moveAndRenameSearchBar.js +24 -5
- package/dist/es6/v6/utils/index.d.ts +1 -12
- package/dist/es6/v6/utils/index.d.ts.map +1 -1
- package/dist/es6/v6/utils/index.js +23 -22
- package/dist/es6/v7/compoundActionBar.d.ts +3 -0
- package/dist/es6/v7/compoundActionBar.d.ts.map +1 -0
- package/dist/es6/v7/compoundActionBar.js +91 -0
- package/dist/es6/v7/compoundBanner.d.ts +3 -0
- package/dist/es6/v7/compoundBanner.d.ts.map +1 -0
- package/dist/es6/v7/compoundBanner.js +133 -0
- package/dist/es6/v7/index.d.ts +4 -0
- package/dist/es6/v7/index.d.ts.map +1 -0
- package/dist/es6/v7/index.js +40 -0
- package/dist/es6/v7/recategorizeIconButtons.d.ts +3 -0
- package/dist/es6/v7/recategorizeIconButtons.d.ts.map +1 -0
- package/dist/es6/v7/recategorizeIconButtons.js +148 -0
- package/dist/es6/v7/removePropFromPopper.d.ts +3 -0
- package/dist/es6/v7/removePropFromPopper.d.ts.map +1 -0
- package/dist/es6/v7/removePropFromPopper.js +31 -0
- package/dist/es6/v7/renameIconPosition.d.ts +3 -0
- package/dist/es6/v7/renameIconPosition.d.ts.map +1 -0
- package/dist/es6/v7/renameIconPosition.js +37 -0
- package/dist/es6/v7/renameIconRef.d.ts +3 -0
- package/dist/es6/v7/renameIconRef.d.ts.map +1 -0
- package/dist/es6/v7/renameIconRef.js +70 -0
- package/dist/es6/v7/renameLayoutImports.d.ts +4 -0
- package/dist/es6/v7/renameLayoutImports.d.ts.map +1 -0
- package/dist/es6/v7/renameLayoutImports.js +105 -0
- package/dist/es6/v7/updateDisclosureShowHide.d.ts +3 -0
- package/dist/es6/v7/updateDisclosureShowHide.d.ts.map +1 -0
- package/dist/es6/v7/updateDisclosureShowHide.js +96 -0
- package/dist/es6/v7/updateModelSignatures.d.ts +3 -0
- package/dist/es6/v7/updateModelSignatures.d.ts.map +1 -0
- package/dist/es6/v7/updateModelSignatures.js +90 -0
- package/dist/es6/v7/updateSegmentedControl.d.ts +3 -0
- package/dist/es6/v7/updateSegmentedControl.d.ts.map +1 -0
- package/dist/es6/v7/updateSegmentedControl.js +24 -0
- package/dist/es6/v7/updateTabs.d.ts +3 -0
- package/dist/es6/v7/updateTabs.d.ts.map +1 -0
- package/dist/es6/v7/updateTabs.js +48 -0
- package/dist/es6/v7/utils/getImportRenameMap.d.ts +7 -0
- package/dist/es6/v7/utils/getImportRenameMap.d.ts.map +1 -0
- package/dist/es6/v7/utils/getImportRenameMap.js +52 -0
- package/dist/es6/v7/utils/hasImportSpecifiers.d.ts +20 -0
- package/dist/es6/v7/utils/hasImportSpecifiers.d.ts.map +1 -0
- package/dist/es6/v7/utils/hasImportSpecifiers.js +46 -0
- package/index.js +7 -0
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAqC,MAAM,aAAa,CAAC;AAyBnF,QAAA,MAAM,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"moveAndRenameSearchBar.d.ts","sourceRoot":"","sources":["../../../lib/v6/moveAndRenameSearchBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAqC,MAAM,aAAa,CAAC;AAyBnF,QAAA,MAAM,SAAS,EAAE,SAyGhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -5,7 +5,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
5
5
|
r[k] = a[j];
|
|
6
6
|
return r;
|
|
7
7
|
};
|
|
8
|
-
import { filterImportSpecifiers,
|
|
8
|
+
import { filterImportSpecifiers, renameImports, hasImportSpecifiers, } from './utils';
|
|
9
9
|
var mainPackage = '@workday/canvas-kit-labs-react';
|
|
10
10
|
var headerPackage = '@workday/canvas-kit-labs-react/header';
|
|
11
11
|
var searchBarRenameImports = ['SearchBar', 'SearchBarProps', 'SearchBarState'];
|
|
@@ -27,6 +27,7 @@ var transform = function (file, api) {
|
|
|
27
27
|
function insertImportDeclarationBefore(nodePath, specifiers, sourcePath) {
|
|
28
28
|
nodePath.insertBefore(j.importDeclaration(specifiers, j.stringLiteral(sourcePath)));
|
|
29
29
|
}
|
|
30
|
+
var discoveredImportSpecifiers = {};
|
|
30
31
|
// Rename search-bar named imports from @workday/canvas-kit-labs-react
|
|
31
32
|
// e.g. import { SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react';
|
|
32
33
|
// becomes import { SearchForm, SearchFormProps } from '@workday/canvas-kit-labs-react';
|
|
@@ -35,7 +36,16 @@ var transform = function (file, api) {
|
|
|
35
36
|
// Filter search bar imports
|
|
36
37
|
var searchBarImports = filterImportSpecifiers(importSpecifiers);
|
|
37
38
|
// Rename search bar imports
|
|
38
|
-
|
|
39
|
+
searchBarImports.forEach(function (specifier) {
|
|
40
|
+
var specifierName = specifier.imported.name;
|
|
41
|
+
if (specifierName in renameMap) {
|
|
42
|
+
// if it hasn't been aliased, track it for updating JSX
|
|
43
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
44
|
+
discoveredImportSpecifiers[specifier.imported.name] = true;
|
|
45
|
+
}
|
|
46
|
+
specifier.imported.name = renameMap[specifierName];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
39
49
|
});
|
|
40
50
|
// Handle imports from @workday/canvas-kit-react/header
|
|
41
51
|
// e.g import { Header, SearchBar, SearchBarProps } from '@workday/canvas-kit-labs-react/header';
|
|
@@ -62,8 +72,17 @@ var transform = function (file, api) {
|
|
|
62
72
|
root.find(j.ImportDeclaration, { source: { value: headerPackage } }).remove();
|
|
63
73
|
// If SearchBar import specifiers were found, insert a new import declaration above the original import declaration
|
|
64
74
|
if (searchBarSpecifiers.length) {
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
searchBarSpecifiers.forEach(function (specifier) {
|
|
76
|
+
var specifierName = specifier.imported.name;
|
|
77
|
+
if (specifierName in renameMap) {
|
|
78
|
+
// if it hasn't been aliased, track it for updating JSX
|
|
79
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
80
|
+
discoveredImportSpecifiers[specifier.imported.name] = true;
|
|
81
|
+
}
|
|
82
|
+
specifier.imported.name = renameMap[specifierName];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
insertImportDeclarationBefore(nodePath, searchBarSpecifiers, '@workday/canvas-kit-labs-react/search-form');
|
|
67
86
|
}
|
|
68
87
|
// If other header import specifiers were found, insert a new import declaration above the original import declaration
|
|
69
88
|
// This will replace the import declaration that was removed above
|
|
@@ -71,6 +90,6 @@ var transform = function (file, api) {
|
|
|
71
90
|
insertImportDeclarationBefore(nodePath, headerSpecifiers, headerPackage);
|
|
72
91
|
}
|
|
73
92
|
});
|
|
74
|
-
return renameImports(api, root, '@workday/canvas-kit-labs-react/
|
|
93
|
+
return renameImports(api, root, '@workday/canvas-kit-labs-react/search-form', renameMap, discoveredImportSpecifiers).toSource();
|
|
75
94
|
};
|
|
76
95
|
export default transform;
|
|
@@ -16,17 +16,6 @@ export declare function filterImportSpecifiers(importSpecifiers: ImportSpecifier
|
|
|
16
16
|
export declare type RenameMap = {
|
|
17
17
|
[key: string]: string;
|
|
18
18
|
};
|
|
19
|
-
/**
|
|
20
|
-
* Renames import specifiers for a given rename map
|
|
21
|
-
* @example
|
|
22
|
-
* const renameMap = {
|
|
23
|
-
* 'PageHeader': 'DeprecatedPageHeader',
|
|
24
|
-
* 'PageHeaderProps': 'DeprecatedPageHeaderProps',
|
|
25
|
-
* };
|
|
26
|
-
* const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
|
|
27
|
-
* renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
|
|
28
|
-
*/
|
|
29
|
-
export declare function renameImportSpecifiers(importSpecifiers: ImportSpecifier[], renameMap: RenameMap): ImportSpecifier[];
|
|
30
19
|
/**
|
|
31
20
|
* Returns a filtered array of ImportDefaultSpecifiers
|
|
32
21
|
* You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
|
|
@@ -66,5 +55,5 @@ export declare function renameImportDefaultSpecifiers(importSpecifiers: ImportDe
|
|
|
66
55
|
* }
|
|
67
56
|
*/
|
|
68
57
|
export declare function hasImportSpecifiers(api: API, root: Collection<any>, packageName: string | string[], specifiers: string[]): boolean;
|
|
69
|
-
export declare function renameImports(api: API, root: Collection<any>, packageName: string, specifierMap: Record<string, string>): Collection<any>;
|
|
58
|
+
export declare function renameImports(api: API, root: Collection<any>, packageName: string, specifierMap: Record<string, string>, discoveredImportSpecifiers?: Record<string, boolean>): Collection<any>;
|
|
70
59
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v6/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,EACJ,MAAM,aAAa,CAAC;AAErB,oBAAY,oBAAoB,GAAG,CAC/B,eAAe,GACf,wBAAwB,GACxB,sBAAsB,CACzB,EAAE,CAAC;AAEJ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,qBAevB;AAED,oBAAY,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v6/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,GAAG,EACJ,MAAM,aAAa,CAAC;AAErB,oBAAY,oBAAoB,GAAG,CAC/B,eAAe,GACf,wBAAwB,GACxB,sBAAsB,CACzB,EAAE,CAAC;AAEJ;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,qBAevB;AAED,oBAAY,SAAS,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,oBAAoB,EACtC,WAAW,CAAC,EAAE,MAAM,EAAE,4BAevB;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,gBAAgB,EAAE,sBAAsB,EAAE,EAC1C,SAAS,EAAE,SAAS,4BASrB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,WAkCrB;AAED,wBAAgB,aAAa,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EACrB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,0BAA0B,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACvD,UAAU,CAAC,GAAG,CAAC,CA+GjB"}
|
|
@@ -24,25 +24,6 @@ export function filterImportSpecifiers(importSpecifiers, importNames) {
|
|
|
24
24
|
});
|
|
25
25
|
return filteredSpecifiers;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Renames import specifiers for a given rename map
|
|
29
|
-
* @example
|
|
30
|
-
* const renameMap = {
|
|
31
|
-
* 'PageHeader': 'DeprecatedPageHeader',
|
|
32
|
-
* 'PageHeaderProps': 'DeprecatedPageHeaderProps',
|
|
33
|
-
* };
|
|
34
|
-
* const pageHeaderImports = filterImportSpecifiers(importSpecifiers, importNames);
|
|
35
|
-
* renameImportSpecifiers(pageHeaderSpecifiers, renameMap);
|
|
36
|
-
*/
|
|
37
|
-
export function renameImportSpecifiers(importSpecifiers, renameMap) {
|
|
38
|
-
importSpecifiers.forEach(function (specifier) {
|
|
39
|
-
var specifierName = specifier.imported.name;
|
|
40
|
-
if (specifierName in renameMap) {
|
|
41
|
-
specifier.imported.name = renameMap[specifierName];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return importSpecifiers;
|
|
45
|
-
}
|
|
46
27
|
/**
|
|
47
28
|
* Returns a filtered array of ImportDefaultSpecifiers
|
|
48
29
|
* You can filter all ImportDefaultSpecifiers or additionally filter by providing an array of import names.
|
|
@@ -134,7 +115,8 @@ export function hasImportSpecifiers(api, root, packageName, specifiers) {
|
|
|
134
115
|
return false;
|
|
135
116
|
});
|
|
136
117
|
}
|
|
137
|
-
export function renameImports(api, root, packageName, specifierMap) {
|
|
118
|
+
export function renameImports(api, root, packageName, specifierMap, discoveredImportSpecifiers) {
|
|
119
|
+
if (discoveredImportSpecifiers === void 0) { discoveredImportSpecifiers = {}; }
|
|
138
120
|
var j = api.jscodeshift;
|
|
139
121
|
if (!hasImportSpecifiers(api, root, packageName, Object.keys(specifierMap))) {
|
|
140
122
|
return root;
|
|
@@ -146,27 +128,41 @@ export function renameImports(api, root, packageName, specifierMap) {
|
|
|
146
128
|
// Transform import statements
|
|
147
129
|
// e.g. import { CookieBanner, CookieBannerProps } from '@workday/canvas-kit-react';
|
|
148
130
|
// becomes import { DeprecatedCookieBanner, DeprecatedCookieBannerProps } from '@workday/canvas-kit-react';
|
|
131
|
+
// Find imports from main packages
|
|
132
|
+
// ex. '@workday/canvas-kit-labs-react'
|
|
149
133
|
root.find(j.ImportDeclaration, { source: { value: mainPackage } }).forEach(function (nodePath) {
|
|
150
134
|
var _a;
|
|
151
135
|
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
152
136
|
if (specifier.type === 'ImportSpecifier') {
|
|
153
137
|
if (Object.keys(specifierMap).includes(specifier.imported.name)) {
|
|
138
|
+
// if it hasn't been aliased, track it for updating JSX
|
|
139
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
140
|
+
discoveredImportSpecifiers[specifier.imported.name] = true;
|
|
141
|
+
}
|
|
154
142
|
specifier.imported.name = specifierMap[specifier.imported.name];
|
|
155
143
|
}
|
|
156
144
|
}
|
|
157
145
|
});
|
|
158
146
|
});
|
|
159
|
-
//
|
|
147
|
+
// Find imports from component specific packages
|
|
148
|
+
// ex. '@workday/canvas-kit-labs-react/header'
|
|
160
149
|
root.find(j.ImportDeclaration, { source: { value: packageName } }).forEach(function (nodePath) {
|
|
161
150
|
var _a;
|
|
162
151
|
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
|
|
152
|
+
// Transforms default imports
|
|
163
153
|
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
164
154
|
if (specifier.local && Object.keys(specifierMap).includes(specifier.local.name)) {
|
|
155
|
+
discoveredImportSpecifiers[specifier.local.name] = true;
|
|
165
156
|
specifier.local.name = specifierMap[specifier.local.name];
|
|
166
157
|
}
|
|
167
158
|
}
|
|
159
|
+
// Transform named exports
|
|
168
160
|
if (specifier.type === 'ImportSpecifier') {
|
|
169
161
|
if (Object.keys(specifierMap).includes(specifier.imported.name)) {
|
|
162
|
+
// if it hasn't been aliased, track it for updating JSX
|
|
163
|
+
if (!specifier.local || specifier.local.name === specifier.imported.name) {
|
|
164
|
+
discoveredImportSpecifiers[specifier.imported.name] = true;
|
|
165
|
+
}
|
|
170
166
|
specifier.imported.name = specifierMap[specifier.imported.name];
|
|
171
167
|
}
|
|
172
168
|
}
|
|
@@ -195,7 +191,10 @@ export function renameImports(api, root, packageName, specifierMap) {
|
|
|
195
191
|
// Transform JSXElements
|
|
196
192
|
// e.g. `<CookieBanner>` becomes `<DeprecatedCookieBanner>`
|
|
197
193
|
root.find(j.JSXIdentifier).forEach(function (nodePath) {
|
|
198
|
-
if (
|
|
194
|
+
if (
|
|
195
|
+
// Check to see if it was imported from Canvas Kit
|
|
196
|
+
discoveredImportSpecifiers[nodePath.value.name] &&
|
|
197
|
+
Object.keys(specifierMap).includes(nodePath.value.name)) {
|
|
199
198
|
nodePath.node.name = specifierMap[nodePath.value.name];
|
|
200
199
|
}
|
|
201
200
|
});
|
|
@@ -203,6 +202,8 @@ export function renameImports(api, root, packageName, specifierMap) {
|
|
|
203
202
|
// e.g. `CookieBanner.DefaultNotice` becomes `DeprecatedCookieBanner.DefaultNotice`
|
|
204
203
|
root.find(j.MemberExpression, { object: { type: 'Identifier' } }).forEach(function (nodePath) {
|
|
205
204
|
if (nodePath.value.object.type === 'Identifier' &&
|
|
205
|
+
// Check to see if it was imported from Canvas Kit
|
|
206
|
+
discoveredImportSpecifiers[nodePath.value.object.name] &&
|
|
206
207
|
Object.keys(specifierMap).includes(nodePath.value.object.name)) {
|
|
207
208
|
nodePath.value.object.name = specifierMap[nodePath.value.object.name];
|
|
208
209
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compoundActionBar.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundActionBar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAyC,MAAM,aAAa,CAAC;AAM3F,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0H7E"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
2
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
3
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
4
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
5
|
+
r[k] = a[j];
|
|
6
|
+
return r;
|
|
7
|
+
};
|
|
8
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
9
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
10
|
+
var actionBarPackage = '@workday/canvas-kit-react/action-bar';
|
|
11
|
+
export default function transformer(file, api, options) {
|
|
12
|
+
var j = api.jscodeshift;
|
|
13
|
+
var root = j(file.source);
|
|
14
|
+
if (!hasImportSpecifiers(api, root, actionBarPackage, ['ActionBar'])) {
|
|
15
|
+
return file.source;
|
|
16
|
+
}
|
|
17
|
+
// Replace default import with named or renamed import
|
|
18
|
+
root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
|
|
19
|
+
var _a;
|
|
20
|
+
var parent = nodePath.parent;
|
|
21
|
+
var importSource = String(parent.node.source.value);
|
|
22
|
+
var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
23
|
+
if (actionBarPackage === importSource && localName) {
|
|
24
|
+
nodePath.replace(j.importSpecifier(j.identifier('ActionBar'), j.identifier(localName)));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/action-bar'), importMap = _a.importMap, styledMap = _a.styledMap;
|
|
28
|
+
root
|
|
29
|
+
.find(j.JSXElement, function (value) {
|
|
30
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
31
|
+
(value.openingElement.name.name === importMap.ActionBar ||
|
|
32
|
+
value.openingElement.name.name === styledMap.ActionBar);
|
|
33
|
+
})
|
|
34
|
+
.forEach(function (nodePath) {
|
|
35
|
+
(nodePath.value.children || []).forEach(function (child, index) {
|
|
36
|
+
if (child.type === 'JSXElement') {
|
|
37
|
+
// bail early if we find a `ActionBar.List` as a child
|
|
38
|
+
if (child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
39
|
+
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
40
|
+
child.openingElement.name.object.name === 'ActionBar' &&
|
|
41
|
+
child.openingElement.name.property.type === 'JSXIdentifier' &&
|
|
42
|
+
child.openingElement.name.property.name === 'List') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Transform Primary and Secondary button to ActionBar.Item
|
|
46
|
+
if (child.openingElement.name.type === 'JSXIdentifier') {
|
|
47
|
+
var buttonAttrs = child.openingElement.attributes || [];
|
|
48
|
+
var ActionItemJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('Item'));
|
|
49
|
+
if (nodePath.value.children &&
|
|
50
|
+
['PrimaryButton', 'SecondaryButton'].includes(child.openingElement.name.name)) {
|
|
51
|
+
// Add isPrimary attribute to primary Action Item
|
|
52
|
+
var elementAttrs = child.openingElement.name.name === 'PrimaryButton'
|
|
53
|
+
? __spreadArrays(buttonAttrs, [j.jsxAttribute(j.jsxIdentifier('isPrimary'))]) : buttonAttrs;
|
|
54
|
+
nodePath.value.children[index] = j.jsxElement(j.jsxOpeningElement(ActionItemJSX, elementAttrs), j.jsxClosingElement(ActionItemJSX), child.children);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var children = nodePath.value.children || [];
|
|
60
|
+
// Remove all attributes from ActionBar to replace them to ActionBar.List
|
|
61
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
62
|
+
if (attributes) {
|
|
63
|
+
nodePath.value.openingElement.attributes = attributes.filter(function (item) { return !(item.type === 'JSXAttribute' && item.name.type === 'JSXIdentifier'); });
|
|
64
|
+
}
|
|
65
|
+
// Create closing element for ActionBar without closing tag
|
|
66
|
+
if (nodePath.value.openingElement.selfClosing) {
|
|
67
|
+
nodePath.value.openingElement.selfClosing = false;
|
|
68
|
+
nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
|
|
69
|
+
}
|
|
70
|
+
// Create ActionBar.List component
|
|
71
|
+
var ActionBarListJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('List'));
|
|
72
|
+
var subComponentJSX = j.jsxElement(j.jsxOpeningElement(ActionBarListJSX,
|
|
73
|
+
// All attributes except fixed should be passed
|
|
74
|
+
attributes === null ||
|
|
75
|
+
// All attributes except fixed should be passed
|
|
76
|
+
attributes === void 0 ? void 0 :
|
|
77
|
+
// All attributes except fixed should be passed
|
|
78
|
+
attributes.filter(function (attr) { return !(attr.type === 'JSXAttribute' && attr.name.name === 'fixed'); })), j.jsxClosingElement(ActionBarListJSX), children);
|
|
79
|
+
// Keep space for code structure
|
|
80
|
+
var textLiteralStart = children.find(function (child) { return child.type === 'JSXText'; });
|
|
81
|
+
var textLiteralEnd = children
|
|
82
|
+
.slice()
|
|
83
|
+
.reverse()
|
|
84
|
+
.find(function (child) { return child.type === 'JSXText'; });
|
|
85
|
+
nodePath.value.children =
|
|
86
|
+
textLiteralStart && textLiteralEnd
|
|
87
|
+
? [textLiteralStart, subComponentJSX, textLiteralEnd]
|
|
88
|
+
: [subComponentJSX];
|
|
89
|
+
});
|
|
90
|
+
return root.toSource();
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compoundBanner.d.ts","sourceRoot":"","sources":["../../../lib/v7/compoundBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAUR,MAAM,aAAa,CAAC;AAQrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAuM7E"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
+
function filterDefined(input) {
|
|
3
|
+
return !!input;
|
|
4
|
+
}
|
|
5
|
+
export default function transformer(file, api, options) {
|
|
6
|
+
var j = api.jscodeshift;
|
|
7
|
+
var root = j(file.source);
|
|
8
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/banner'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
|
|
9
|
+
if (!containsCanvasImports) {
|
|
10
|
+
return file.source;
|
|
11
|
+
}
|
|
12
|
+
root
|
|
13
|
+
.find(j.JSXElement, function (value) {
|
|
14
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
15
|
+
(value.openingElement.name.name === importMap.Banner ||
|
|
16
|
+
value.openingElement.name.name === styledMap.Banner);
|
|
17
|
+
})
|
|
18
|
+
.forEach(function (nodePath) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
// bail early if we find a `Banner.Label` as a child
|
|
21
|
+
for (var _i = 0, _c = nodePath.value.children || []; _i < _c.length; _i++) {
|
|
22
|
+
var child = _c[_i];
|
|
23
|
+
if (child.type === 'JSXElement' &&
|
|
24
|
+
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
25
|
+
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
26
|
+
child.openingElement.name.object.name === 'Banner' &&
|
|
27
|
+
child.openingElement.name.property.type === 'JSXIdentifier' &&
|
|
28
|
+
child.openingElement.name.property.name === 'Label') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
var findAttribute = function (name) { return function (item) {
|
|
33
|
+
if (item.type === 'JSXAttribute' &&
|
|
34
|
+
item.name.type === 'JSXIdentifier' &&
|
|
35
|
+
item.name.name === name) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}; };
|
|
40
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
41
|
+
if (attributes) {
|
|
42
|
+
var label = attributes.find(findAttribute('label'));
|
|
43
|
+
var actionText = attributes.find(findAttribute('actionText'));
|
|
44
|
+
var errorIndex_1 = attributes.findIndex(findAttribute('error'));
|
|
45
|
+
var variantIndex_1 = attributes.findIndex(findAttribute('variant'));
|
|
46
|
+
if (errorIndex_1 >= 0 && ((_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a[errorIndex_1])) {
|
|
47
|
+
var errorExpression = nodePath.value.openingElement.attributes[errorIndex_1].value.expression;
|
|
48
|
+
var getNameToBoolean = function (name) {
|
|
49
|
+
return name === 'Error' ? j.booleanLiteral(true) : j.booleanLiteral(false);
|
|
50
|
+
};
|
|
51
|
+
var setHasError = function (hasErrorValue) {
|
|
52
|
+
if (nodePath.value.openingElement.attributes) {
|
|
53
|
+
nodePath.value.openingElement.attributes[errorIndex_1] = j.jsxAttribute(j.jsxIdentifier('hasError'), j.jsxExpressionContainer(hasErrorValue));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
if (errorExpression.property) {
|
|
57
|
+
var previousExpression = errorExpression;
|
|
58
|
+
var newValue = getNameToBoolean(previousExpression.property.name);
|
|
59
|
+
setHasError(newValue);
|
|
60
|
+
}
|
|
61
|
+
if (errorExpression.test) {
|
|
62
|
+
var previousExpression = errorExpression;
|
|
63
|
+
var newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
|
|
64
|
+
setHasError(newValue);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (variantIndex_1 >= 0 && ((_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b[variantIndex_1])) {
|
|
68
|
+
var stickyExpression = nodePath.value.openingElement.attributes[variantIndex_1].value.expression;
|
|
69
|
+
var getNameToBoolean = function (name) {
|
|
70
|
+
return name === 'Sticky' ? j.booleanLiteral(true) : j.booleanLiteral(false);
|
|
71
|
+
};
|
|
72
|
+
var setIsSticky = function (hasStickyValue) {
|
|
73
|
+
if (nodePath.value.openingElement.attributes) {
|
|
74
|
+
nodePath.value.openingElement.attributes[variantIndex_1] = j.jsxAttribute(j.jsxIdentifier('isSticky'), j.jsxExpressionContainer(hasStickyValue));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (stickyExpression.property) {
|
|
78
|
+
var previousExpression = stickyExpression;
|
|
79
|
+
var newValue = getNameToBoolean(previousExpression.property.name);
|
|
80
|
+
setIsSticky(newValue);
|
|
81
|
+
}
|
|
82
|
+
if (stickyExpression.test) {
|
|
83
|
+
var previousExpression = stickyExpression;
|
|
84
|
+
var newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
|
|
85
|
+
setIsSticky(newValue);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// remove these attributes from the list - we'll add them as sub components
|
|
89
|
+
nodePath.value.openingElement.attributes = attributes.filter(function (item) {
|
|
90
|
+
if (item.type === 'JSXAttribute' &&
|
|
91
|
+
item.name.type === 'JSXIdentifier' &&
|
|
92
|
+
['label', 'actionText'].includes(item.name.name)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
var BannerIconJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Icon'));
|
|
98
|
+
var BannerLabelJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Label'));
|
|
99
|
+
var BannerActionTextJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('ActionText'));
|
|
100
|
+
var convertAttributeToChildren = function (input) {
|
|
101
|
+
var _a;
|
|
102
|
+
switch ((_a = input.value) === null || _a === void 0 ? void 0 : _a.type) {
|
|
103
|
+
case 'JSXExpressionContainer':
|
|
104
|
+
// unwrap JSXElements
|
|
105
|
+
if (input.value.expression.type === 'JSXElement') {
|
|
106
|
+
return [input.value.expression];
|
|
107
|
+
}
|
|
108
|
+
return [input.value];
|
|
109
|
+
default:
|
|
110
|
+
return [input.value];
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var createSelfClosingTag = function (Tag) {
|
|
114
|
+
var OpeningTag = j.jsxOpeningElement(Tag);
|
|
115
|
+
OpeningTag.selfClosing = true;
|
|
116
|
+
return j.jsxElement(OpeningTag);
|
|
117
|
+
};
|
|
118
|
+
nodePath.value.openingElement.selfClosing = false;
|
|
119
|
+
// Add subcomponents back as children
|
|
120
|
+
nodePath.value.children = [
|
|
121
|
+
createSelfClosingTag(BannerIconJSX),
|
|
122
|
+
!!label
|
|
123
|
+
? j.jsxElement(j.jsxOpeningElement(BannerLabelJSX), j.jsxClosingElement(BannerLabelJSX), convertAttributeToChildren(label))
|
|
124
|
+
: createSelfClosingTag(BannerLabelJSX),
|
|
125
|
+
!!actionText
|
|
126
|
+
? j.jsxElement(j.jsxOpeningElement(BannerActionTextJSX), j.jsxClosingElement(BannerActionTextJSX), convertAttributeToChildren(actionText))
|
|
127
|
+
: createSelfClosingTag(BannerActionTextJSX),
|
|
128
|
+
].filter(filterDefined);
|
|
129
|
+
nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return root.toSource();
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v7/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AActC,QAAA,MAAM,SAAS,EAAE,SAiBhB,CAAC;AACF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import compoundActionBar from './compoundActionBar';
|
|
13
|
+
import compoundBanner from './compoundBanner';
|
|
14
|
+
import removePropFromPopper from './removePropFromPopper';
|
|
15
|
+
import renameIconRef from './renameIconRef';
|
|
16
|
+
import renameLayoutImports from './renameLayoutImports';
|
|
17
|
+
import updateSegmentedControl from './updateSegmentedControl';
|
|
18
|
+
import renameIconPosition from './renameIconPosition';
|
|
19
|
+
import recategorizeIconButtons from './recategorizeIconButtons';
|
|
20
|
+
import updateModelSignatures from './updateModelSignatures';
|
|
21
|
+
import updateTabs from './updateTabs';
|
|
22
|
+
import updateDisclosureShowHide from './updateDisclosureShowHide';
|
|
23
|
+
var transform = function (file, api, options) {
|
|
24
|
+
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
25
|
+
var fixes = [
|
|
26
|
+
compoundActionBar,
|
|
27
|
+
compoundBanner,
|
|
28
|
+
recategorizeIconButtons,
|
|
29
|
+
renameIconRef,
|
|
30
|
+
removePropFromPopper,
|
|
31
|
+
renameIconPosition,
|
|
32
|
+
renameLayoutImports,
|
|
33
|
+
updateSegmentedControl,
|
|
34
|
+
updateModelSignatures,
|
|
35
|
+
updateTabs,
|
|
36
|
+
updateDisclosureShowHide,
|
|
37
|
+
];
|
|
38
|
+
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
|
|
39
|
+
};
|
|
40
|
+
export default transform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recategorizeIconButtons.d.ts","sourceRoot":"","sources":["../../../lib/v7/recategorizeIconButtons.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,OAAO,EAMR,MAAM,aAAa,CAAC;AAcrB,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA8K7E"}
|