@workday/canvas-kit-codemod 7.1.4 → 7.2.0-427-next.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/README.md +41 -5
- package/dist/es6/v5/compoundCard.js +19 -22
- package/dist/es6/v5/getImportRenameMap.js +11 -12
- package/dist/es6/v5/index.js +2 -13
- package/dist/es6/v5/mapTypeTokensToNewHierarchy.js +62 -62
- package/dist/es6/v5/maps.js +2 -2
- package/dist/es6/v5/moveInputProvider.js +6 -6
- package/dist/es6/v5/recategorizeButtons.js +34 -35
- package/dist/es6/v5/removeButtonEnums.js +26 -28
- package/dist/es6/v5/removeDefaultImports.js +7 -7
- package/dist/es6/v5/renameButtonRefs.js +8 -8
- package/dist/es6/v5/renameCoreImports.js +10 -10
- package/dist/es6/v5/renameInputRefs.js +17 -21
- package/dist/es6/v5/renamePreviewTokenImports.js +10 -10
- package/dist/es6/v5/renameSpacing.js +18 -18
- package/dist/es6/v5/slashImports.js +31 -33
- package/dist/es6/v6/deprecateCookieBanner.js +3 -3
- package/dist/es6/v6/deprecateHeader.js +4 -4
- package/dist/es6/v6/deprecatePageHeader.js +3 -3
- package/dist/es6/v6/index.js +3 -14
- package/dist/es6/v6/moveAndRenameSearchBar.js +23 -29
- package/dist/es6/v6/renameCanvasDepthValue.js +3 -3
- package/dist/es6/v6/utils/index.js +28 -31
- package/dist/es6/v7/compoundActionBar.js +27 -39
- package/dist/es6/v7/compoundBanner.js +40 -43
- package/dist/es6/v7/index.js +3 -14
- package/dist/es6/v7/recategorizeIconButtons.js +27 -31
- package/dist/es6/v7/removePropFromPopper.js +14 -18
- package/dist/es6/v7/renameIconPosition.js +13 -17
- package/dist/es6/v7/renameIconRef.js +17 -21
- package/dist/es6/v7/renameLayoutImports.js +14 -14
- package/dist/es6/v7/updateDisclosureShowHide.js +22 -22
- package/dist/es6/v7/updateModelSignatures.js +21 -21
- package/dist/es6/v7/updateSegmentedControl.js +8 -11
- package/dist/es6/v7/updateTabs.js +8 -8
- package/dist/es6/v7/utils/getImportRenameMap.js +11 -12
- package/dist/es6/v7/utils/hasImportSpecifiers.js +9 -11
- package/dist/es6/v8/index.d.ts +4 -0
- package/dist/es6/v8/index.d.ts.map +1 -0
- package/dist/es6/v8/index.js +25 -0
- package/dist/es6/v8/promoteBreadcrumbs.d.ts +4 -0
- package/dist/es6/v8/promoteBreadcrumbs.d.ts.map +1 -0
- package/dist/es6/v8/promoteBreadcrumbs.js +56 -0
- package/dist/es6/v8/promoteComponentsToTesting.d.ts +4 -0
- package/dist/es6/v8/promoteComponentsToTesting.d.ts.map +1 -0
- package/dist/es6/v8/promoteComponentsToTesting.js +76 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.d.ts +3 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.d.ts.map +1 -0
- package/dist/es6/v8/refactorActionBarOverflowButton.js +46 -0
- package/dist/es6/v8/removeDefaultImports.d.ts +3 -0
- package/dist/es6/v8/removeDefaultImports.d.ts.map +1 -0
- package/dist/es6/v8/removeDefaultImports.js +52 -0
- package/dist/es6/v8/renameLoadingAnimation.d.ts +3 -0
- package/dist/es6/v8/renameLoadingAnimation.d.ts.map +1 -0
- package/dist/es6/v8/renameLoadingAnimation.js +62 -0
- package/dist/es6/v8/restructureBreadcrumbs.d.ts +3 -0
- package/dist/es6/v8/restructureBreadcrumbs.d.ts.map +1 -0
- package/dist/es6/v8/restructureBreadcrumbs.js +55 -0
- package/dist/es6/v8/softDeprecateDrawer.d.ts +3 -0
- package/dist/es6/v8/softDeprecateDrawer.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecateDrawer.js +103 -0
- package/dist/es6/v8/softDeprecateLayout.d.ts +3 -0
- package/dist/es6/v8/softDeprecateLayout.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecateLayout.js +76 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.d.ts +3 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.d.ts.map +1 -0
- package/dist/es6/v8/softDeprecatePreviewMenu.js +79 -0
- package/dist/es6/v9/compoundToast.d.ts +3 -0
- package/dist/es6/v9/compoundToast.d.ts.map +1 -0
- package/dist/es6/v9/compoundToast.js +121 -0
- package/dist/es6/v9/deprecateStack.d.ts +3 -0
- package/dist/es6/v9/deprecateStack.d.ts.map +1 -0
- package/dist/es6/v9/deprecateStack.js +275 -0
- package/dist/es6/v9/index.d.ts +4 -0
- package/dist/es6/v9/index.d.ts.map +1 -0
- package/dist/es6/v9/index.js +16 -0
- package/dist/es6/v9/promoteToast.d.ts +4 -0
- package/dist/es6/v9/promoteToast.d.ts.map +1 -0
- package/dist/es6/v9/promoteToast.js +56 -0
- package/dist/es6/v9/promoteUseThemedRing.d.ts +4 -0
- package/dist/es6/v9/promoteUseThemedRing.d.ts.map +1 -0
- package/dist/es6/v9/promoteUseThemedRing.js +56 -0
- package/index.js +40 -5
- package/package.json +2 -2
|
@@ -1,38 +1,29 @@
|
|
|
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
1
|
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
9
2
|
import { hasImportSpecifiers } from '../v6/utils';
|
|
10
|
-
|
|
3
|
+
const actionBarPackage = '@workday/canvas-kit-react/action-bar';
|
|
11
4
|
export default function transformer(file, api, options) {
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const j = api.jscodeshift;
|
|
6
|
+
const root = j(file.source);
|
|
14
7
|
if (!hasImportSpecifiers(api, root, actionBarPackage, ['ActionBar'])) {
|
|
15
8
|
return file.source;
|
|
16
9
|
}
|
|
17
10
|
// Replace default import with named or renamed import
|
|
18
|
-
root.find(j.ImportDefaultSpecifier).forEach(
|
|
11
|
+
root.find(j.ImportDefaultSpecifier).forEach(nodePath => {
|
|
19
12
|
var _a;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
const parent = nodePath.parent;
|
|
14
|
+
const importSource = String(parent.node.source.value);
|
|
15
|
+
const localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
23
16
|
if (actionBarPackage === importSource && localName) {
|
|
24
17
|
nodePath.replace(j.importSpecifier(j.identifier('ActionBar'), j.identifier(localName)));
|
|
25
18
|
}
|
|
26
19
|
});
|
|
27
|
-
|
|
20
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/action-bar');
|
|
28
21
|
root
|
|
29
|
-
.find(j.JSXElement,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.forEach(function (nodePath) {
|
|
35
|
-
(nodePath.value.children || []).forEach(function (child, index) {
|
|
22
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
23
|
+
(value.openingElement.name.name === importMap.ActionBar ||
|
|
24
|
+
value.openingElement.name.name === styledMap.ActionBar))
|
|
25
|
+
.forEach(nodePath => {
|
|
26
|
+
(nodePath.value.children || []).forEach((child, index) => {
|
|
36
27
|
if (child.type === 'JSXElement') {
|
|
37
28
|
// bail early if we find a `ActionBar.List` as a child
|
|
38
29
|
if (child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
@@ -44,23 +35,24 @@ export default function transformer(file, api, options) {
|
|
|
44
35
|
}
|
|
45
36
|
// Transform Primary and Secondary button to ActionBar.Item
|
|
46
37
|
if (child.openingElement.name.type === 'JSXIdentifier') {
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
const buttonAttrs = child.openingElement.attributes || [];
|
|
39
|
+
const ActionItemJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('Item'));
|
|
49
40
|
if (nodePath.value.children &&
|
|
50
41
|
['PrimaryButton', 'SecondaryButton'].includes(child.openingElement.name.name)) {
|
|
51
42
|
// Add isPrimary attribute to primary Action Item
|
|
52
|
-
|
|
53
|
-
?
|
|
43
|
+
const elementAttrs = child.openingElement.name.name === 'PrimaryButton'
|
|
44
|
+
? [...buttonAttrs, j.jsxAttribute(j.jsxIdentifier('isPrimary'))]
|
|
45
|
+
: buttonAttrs;
|
|
54
46
|
nodePath.value.children[index] = j.jsxElement(j.jsxOpeningElement(ActionItemJSX, elementAttrs), j.jsxClosingElement(ActionItemJSX), child.children);
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
});
|
|
59
|
-
|
|
51
|
+
const children = nodePath.value.children || [];
|
|
60
52
|
// Remove all attributes from ActionBar to replace them to ActionBar.List
|
|
61
|
-
|
|
53
|
+
const attributes = nodePath.value.openingElement.attributes;
|
|
62
54
|
if (attributes) {
|
|
63
|
-
nodePath.value.openingElement.attributes = attributes.filter(
|
|
55
|
+
nodePath.value.openingElement.attributes = attributes.filter(item => !(item.type === 'JSXAttribute' && item.name.type === 'JSXIdentifier'));
|
|
64
56
|
}
|
|
65
57
|
// Create closing element for ActionBar without closing tag
|
|
66
58
|
if (nodePath.value.openingElement.selfClosing) {
|
|
@@ -68,20 +60,16 @@ export default function transformer(file, api, options) {
|
|
|
68
60
|
nodePath.value.closingElement = j.jsxClosingElement(nodePath.value.openingElement.name);
|
|
69
61
|
}
|
|
70
62
|
// Create ActionBar.List component
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
const ActionBarListJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.ActionBar), j.jsxIdentifier('List'));
|
|
64
|
+
const subComponentJSX = j.jsxElement(j.jsxOpeningElement(ActionBarListJSX,
|
|
73
65
|
// 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);
|
|
66
|
+
attributes === null || attributes === void 0 ? void 0 : attributes.filter(attr => !(attr.type === 'JSXAttribute' && attr.name.name === 'fixed'))), j.jsxClosingElement(ActionBarListJSX), children);
|
|
79
67
|
// Keep space for code structure
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
const textLiteralStart = children.find(child => child.type === 'JSXText');
|
|
69
|
+
const textLiteralEnd = children
|
|
82
70
|
.slice()
|
|
83
71
|
.reverse()
|
|
84
|
-
.find(
|
|
72
|
+
.find(child => child.type === 'JSXText');
|
|
85
73
|
nodePath.value.children =
|
|
86
74
|
textLiteralStart && textLiteralEnd
|
|
87
75
|
? [textLiteralStart, subComponentJSX, textLiteralEnd]
|
|
@@ -3,23 +3,20 @@ function filterDefined(input) {
|
|
|
3
3
|
return !!input;
|
|
4
4
|
}
|
|
5
5
|
export default function transformer(file, api, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const j = api.jscodeshift;
|
|
7
|
+
const root = j(file.source);
|
|
8
|
+
const { containsCanvasImports, importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/banner');
|
|
9
9
|
if (!containsCanvasImports) {
|
|
10
10
|
return file.source;
|
|
11
11
|
}
|
|
12
12
|
root
|
|
13
|
-
.find(j.JSXElement,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
18
|
-
.forEach(function (nodePath) {
|
|
13
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
14
|
+
(value.openingElement.name.name === importMap.Banner ||
|
|
15
|
+
value.openingElement.name.name === styledMap.Banner))
|
|
16
|
+
.forEach(nodePath => {
|
|
19
17
|
var _a, _b;
|
|
20
18
|
// bail early if we find a `Banner.Label` as a child
|
|
21
|
-
for (
|
|
22
|
-
var child = _c[_i];
|
|
19
|
+
for (const child of nodePath.value.children || []) {
|
|
23
20
|
if (child.type === 'JSXElement' &&
|
|
24
21
|
child.openingElement.name.type === 'JSXMemberExpression' &&
|
|
25
22
|
child.openingElement.name.object.type === 'JSXIdentifier' &&
|
|
@@ -29,64 +26,64 @@ export default function transformer(file, api, options) {
|
|
|
29
26
|
return;
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
|
|
29
|
+
const findAttribute = (name) => (item) => {
|
|
33
30
|
if (item.type === 'JSXAttribute' &&
|
|
34
31
|
item.name.type === 'JSXIdentifier' &&
|
|
35
32
|
item.name.name === name) {
|
|
36
33
|
return true;
|
|
37
34
|
}
|
|
38
35
|
return false;
|
|
39
|
-
};
|
|
40
|
-
|
|
36
|
+
};
|
|
37
|
+
const attributes = nodePath.value.openingElement.attributes;
|
|
41
38
|
if (attributes) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
const label = attributes.find(findAttribute('label'));
|
|
40
|
+
const actionText = attributes.find(findAttribute('actionText'));
|
|
41
|
+
const errorIndex = attributes.findIndex(findAttribute('error'));
|
|
42
|
+
const variantIndex = attributes.findIndex(findAttribute('variant'));
|
|
43
|
+
if (errorIndex >= 0 && ((_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a[errorIndex])) {
|
|
44
|
+
const errorExpression = nodePath.value.openingElement.attributes[errorIndex].value.expression;
|
|
45
|
+
const getNameToBoolean = (name) => {
|
|
49
46
|
return name === 'Error' ? j.booleanLiteral(true) : j.booleanLiteral(false);
|
|
50
47
|
};
|
|
51
|
-
|
|
48
|
+
const setHasError = (hasErrorValue) => {
|
|
52
49
|
if (nodePath.value.openingElement.attributes) {
|
|
53
|
-
nodePath.value.openingElement.attributes[
|
|
50
|
+
nodePath.value.openingElement.attributes[errorIndex] = j.jsxAttribute(j.jsxIdentifier('hasError'), j.jsxExpressionContainer(hasErrorValue));
|
|
54
51
|
}
|
|
55
52
|
};
|
|
56
53
|
if (errorExpression.property) {
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const previousExpression = errorExpression;
|
|
55
|
+
const newValue = getNameToBoolean(previousExpression.property.name);
|
|
59
56
|
setHasError(newValue);
|
|
60
57
|
}
|
|
61
58
|
if (errorExpression.test) {
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const previousExpression = errorExpression;
|
|
60
|
+
const newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
|
|
64
61
|
setHasError(newValue);
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (variantIndex >= 0 && ((_b = nodePath.value.openingElement.attributes) === null || _b === void 0 ? void 0 : _b[variantIndex])) {
|
|
65
|
+
const stickyExpression = nodePath.value.openingElement.attributes[variantIndex].value.expression;
|
|
66
|
+
const getNameToBoolean = (name) => {
|
|
70
67
|
return name === 'Sticky' ? j.booleanLiteral(true) : j.booleanLiteral(false);
|
|
71
68
|
};
|
|
72
|
-
|
|
69
|
+
const setIsSticky = (hasStickyValue) => {
|
|
73
70
|
if (nodePath.value.openingElement.attributes) {
|
|
74
|
-
nodePath.value.openingElement.attributes[
|
|
71
|
+
nodePath.value.openingElement.attributes[variantIndex] = j.jsxAttribute(j.jsxIdentifier('isSticky'), j.jsxExpressionContainer(hasStickyValue));
|
|
75
72
|
}
|
|
76
73
|
};
|
|
77
74
|
if (stickyExpression.property) {
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
const previousExpression = stickyExpression;
|
|
76
|
+
const newValue = getNameToBoolean(previousExpression.property.name);
|
|
80
77
|
setIsSticky(newValue);
|
|
81
78
|
}
|
|
82
79
|
if (stickyExpression.test) {
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
const previousExpression = stickyExpression;
|
|
81
|
+
const newValue = j.conditionalExpression(previousExpression.test, getNameToBoolean(previousExpression.consequent.property.name), getNameToBoolean(previousExpression.alternate.property.name));
|
|
85
82
|
setIsSticky(newValue);
|
|
86
83
|
}
|
|
87
84
|
}
|
|
88
85
|
// remove these attributes from the list - we'll add them as sub components
|
|
89
|
-
nodePath.value.openingElement.attributes = attributes.filter(
|
|
86
|
+
nodePath.value.openingElement.attributes = attributes.filter(item => {
|
|
90
87
|
if (item.type === 'JSXAttribute' &&
|
|
91
88
|
item.name.type === 'JSXIdentifier' &&
|
|
92
89
|
['label', 'actionText'].includes(item.name.name)) {
|
|
@@ -94,10 +91,10 @@ export default function transformer(file, api, options) {
|
|
|
94
91
|
}
|
|
95
92
|
return true;
|
|
96
93
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
const BannerIconJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Icon'));
|
|
95
|
+
const BannerLabelJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('Label'));
|
|
96
|
+
const BannerActionTextJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Banner), j.jsxIdentifier('ActionText'));
|
|
97
|
+
const convertAttributeToChildren = (input) => {
|
|
101
98
|
var _a;
|
|
102
99
|
switch ((_a = input.value) === null || _a === void 0 ? void 0 : _a.type) {
|
|
103
100
|
case 'JSXExpressionContainer':
|
|
@@ -110,8 +107,8 @@ export default function transformer(file, api, options) {
|
|
|
110
107
|
return [input.value];
|
|
111
108
|
}
|
|
112
109
|
};
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
const createSelfClosingTag = (Tag) => {
|
|
111
|
+
const OpeningTag = j.jsxOpeningElement(Tag);
|
|
115
112
|
OpeningTag.selfClosing = true;
|
|
116
113
|
return j.jsxElement(OpeningTag);
|
|
117
114
|
};
|
package/dist/es6/v7/index.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
import compoundActionBar from './compoundActionBar';
|
|
13
2
|
import compoundBanner from './compoundBanner';
|
|
14
3
|
import removePropFromPopper from './removePropFromPopper';
|
|
@@ -20,9 +9,9 @@ import recategorizeIconButtons from './recategorizeIconButtons';
|
|
|
20
9
|
import updateModelSignatures from './updateModelSignatures';
|
|
21
10
|
import updateTabs from './updateTabs';
|
|
22
11
|
import updateDisclosureShowHide from './updateDisclosureShowHide';
|
|
23
|
-
|
|
12
|
+
const transform = (file, api, options) => {
|
|
24
13
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
25
|
-
|
|
14
|
+
const fixes = [
|
|
26
15
|
compoundActionBar,
|
|
27
16
|
compoundBanner,
|
|
28
17
|
recategorizeIconButtons,
|
|
@@ -35,6 +24,6 @@ var transform = function (file, api, options) {
|
|
|
35
24
|
updateTabs,
|
|
36
25
|
updateDisclosureShowHide,
|
|
37
26
|
];
|
|
38
|
-
return fixes.reduce(
|
|
27
|
+
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
39
28
|
};
|
|
40
29
|
export default transform;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const updateJSXTag = (nodePath, newTag) => {
|
|
4
|
+
const { name: componentName } = nodePath.value.openingElement.name;
|
|
5
5
|
if (componentName === 'IconButton') {
|
|
6
6
|
nodePath.value.openingElement.name.name = newTag;
|
|
7
7
|
if (nodePath.value.closingElement) {
|
|
@@ -10,17 +10,17 @@ var updateJSXTag = function (nodePath, newTag) {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
export default function transformer(file, api, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
|
+
const requiredImportSpecifiers = [];
|
|
16
16
|
/**
|
|
17
17
|
* 1. Find button imports
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
const { containsCanvasImports, importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/button');
|
|
20
20
|
if (!containsCanvasImports) {
|
|
21
21
|
return file.source;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
let buttonType = 'TertiaryButton'; //default button if no variant is specified
|
|
24
24
|
// Button Mapping
|
|
25
25
|
// circle -> tertiary
|
|
26
26
|
// circle-filled -> secondary
|
|
@@ -38,23 +38,21 @@ export default function transformer(file, api, options) {
|
|
|
38
38
|
* - Swap it out for the appropriate mapping
|
|
39
39
|
*/
|
|
40
40
|
root
|
|
41
|
-
.find(j.JSXElement,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
46
|
-
.forEach(function (nodePath) {
|
|
41
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
42
|
+
(value.openingElement.name.name === importMap.IconButton ||
|
|
43
|
+
value.openingElement.name.name === styledMap.IconButton))
|
|
44
|
+
.forEach(nodePath => {
|
|
47
45
|
var _a;
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
const attrs = nodePath.value.openingElement.attributes;
|
|
47
|
+
const variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(attr => attr.type === 'JSXAttribute' && attr.name.name === 'variant');
|
|
50
48
|
// Default IconButton variant is `circle`
|
|
51
49
|
if (variantProp) {
|
|
52
|
-
|
|
50
|
+
const valueBody = variantProp.value;
|
|
53
51
|
if ((valueBody === null || valueBody === void 0 ? void 0 : valueBody.type) === 'JSXExpressionContainer' &&
|
|
54
52
|
valueBody.expression.type === 'StringLiteral') {
|
|
55
53
|
variantProp.value = valueBody.expression;
|
|
56
54
|
}
|
|
57
|
-
|
|
55
|
+
const variantPropValue = variantProp.value.value;
|
|
58
56
|
if (variantPropValue) {
|
|
59
57
|
variantProp.value.value = variantPropValue.replace('Filled', '');
|
|
60
58
|
buttonType = /filled/gi.test(variantPropValue) ? 'SecondaryButton' : 'TertiaryButton';
|
|
@@ -79,7 +77,7 @@ export default function transformer(file, api, options) {
|
|
|
79
77
|
// Find all instances of IconButton within a style function
|
|
80
78
|
// const StyledIconButton = styled(IconButton) gets renamed to
|
|
81
79
|
// const StyledIconButton = styled(CorrectButtonMapping)
|
|
82
|
-
root.find(j.VariableDeclarator).forEach(
|
|
80
|
+
root.find(j.VariableDeclarator).forEach(nodePath => {
|
|
83
81
|
var _a;
|
|
84
82
|
if (((_a = nodePath.value.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
|
|
85
83
|
nodePath.value.init.callee.type === 'CallExpression' &&
|
|
@@ -95,30 +93,28 @@ export default function transformer(file, api, options) {
|
|
|
95
93
|
* Remove old imports: `IconButton`
|
|
96
94
|
* Add new required imports
|
|
97
95
|
*/
|
|
98
|
-
|
|
96
|
+
const buttonImports = root.find(j.ImportDeclaration, {
|
|
99
97
|
source: {
|
|
100
|
-
value:
|
|
101
|
-
return value === '@workday/canvas-kit-react' || value === '@workday/canvas-kit-react/button';
|
|
102
|
-
},
|
|
98
|
+
value: (value) => value === '@workday/canvas-kit-react' || value === '@workday/canvas-kit-react/button',
|
|
103
99
|
},
|
|
104
100
|
});
|
|
105
101
|
if (!buttonImports.length) {
|
|
106
102
|
// Add new specifiers to a new import
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
const allImports = root.find(j.ImportDeclaration);
|
|
104
|
+
const lastImport = allImports.at(allImports.length);
|
|
109
105
|
if (lastImport) {
|
|
110
|
-
lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(
|
|
106
|
+
lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(specifier => j.importSpecifier(j.identifier(specifier))), j.stringLiteral('@workday/canvas-kit-react/button')));
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
109
|
else {
|
|
114
|
-
buttonImports.forEach(
|
|
110
|
+
buttonImports.forEach(nodePath => {
|
|
115
111
|
var _a, _b, _c;
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
const { node } = nodePath;
|
|
113
|
+
const specifiersToRemove = ['IconButton'];
|
|
118
114
|
// Remove old specifiers
|
|
119
115
|
if (typeof node.source.value === 'string' &&
|
|
120
116
|
node.source.value.includes('@workday/canvas-kit-react')) {
|
|
121
|
-
(_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
117
|
+
(_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
122
118
|
var _a, _b;
|
|
123
119
|
if (specifier.type === 'ImportSpecifier' &&
|
|
124
120
|
specifiersToRemove.includes(specifier.imported.name)) {
|
|
@@ -128,9 +124,9 @@ export default function transformer(file, api, options) {
|
|
|
128
124
|
});
|
|
129
125
|
}
|
|
130
126
|
// Add new specifiers to existing import
|
|
131
|
-
requiredImportSpecifiers.forEach(
|
|
127
|
+
requiredImportSpecifiers.forEach(specifier => {
|
|
132
128
|
var _a, _b;
|
|
133
|
-
if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(
|
|
129
|
+
if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(existing => existing.type === 'ImportSpecifier' && existing.imported.name === specifier))) {
|
|
134
130
|
// Only add a specifier if it has not already been declared
|
|
135
131
|
if (!importMap[buttonType]) {
|
|
136
132
|
(_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.push(j.importSpecifier(j.identifier(specifier)));
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
2
|
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
-
|
|
3
|
+
const popupBarPackage = '@workday/canvas-kit-react/popup';
|
|
4
4
|
export default function transformer(file, api, options) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const j = api.jscodeshift;
|
|
6
|
+
const root = j(file.source);
|
|
7
7
|
if (!hasImportSpecifiers(api, root, popupBarPackage, ['Popper'])) {
|
|
8
8
|
return file.source;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
const { importMap, styledMap } = getImportRenameMap(j, root, popupBarPackage);
|
|
11
11
|
root
|
|
12
|
-
.find(j.JSXElement,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.forEach(function (nodePath) {
|
|
18
|
-
var attributes = nodePath.value.openingElement.attributes;
|
|
12
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
13
|
+
(value.openingElement.name.name === importMap.Popper ||
|
|
14
|
+
value.openingElement.name.name === styledMap.Popper))
|
|
15
|
+
.forEach(nodePath => {
|
|
16
|
+
const attributes = nodePath.value.openingElement.attributes;
|
|
19
17
|
// Remove containerElement prop from Popper component
|
|
20
18
|
if (attributes) {
|
|
21
|
-
nodePath.value.openingElement.attributes = attributes.filter(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
: true;
|
|
27
|
-
});
|
|
19
|
+
nodePath.value.openingElement.attributes = attributes.filter(item => item.type === 'JSXAttribute' &&
|
|
20
|
+
item.name.type === 'JSXIdentifier' &&
|
|
21
|
+
['containerElement'].includes(item.name.name)
|
|
22
|
+
? false
|
|
23
|
+
: true);
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
26
|
return root.toSource();
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
2
|
export default function transformer(file, api, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const j = api.jscodeshift;
|
|
4
|
+
const root = j(file.source);
|
|
5
|
+
const { containsCanvasImports, importMap, styledMap } = getImportRenameMap(j, root, '@workday/canvas-kit-react/button');
|
|
6
6
|
if (!containsCanvasImports) {
|
|
7
7
|
return file.source;
|
|
8
8
|
}
|
|
9
9
|
root
|
|
10
|
-
.find(j.JSXElement,
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
.forEach(function (nodePath) {
|
|
10
|
+
.find(j.JSXElement, (value) => value.openingElement.name.type === 'JSXIdentifier' &&
|
|
11
|
+
(value.openingElement.name.name ===
|
|
12
|
+
(importMap.PrimaryButton || importMap.SecondaryButton) ||
|
|
13
|
+
value.openingElement.name.name === (styledMap.PrimaryButton || styledMap.SecondaryButton)))
|
|
14
|
+
.forEach(nodePath => {
|
|
17
15
|
var _a;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}; };
|
|
23
|
-
var attributes = nodePath.value.openingElement.attributes;
|
|
16
|
+
const findAttribute = (name) => (item) => item.type === 'JSXAttribute' &&
|
|
17
|
+
item.name.type === 'JSXIdentifier' &&
|
|
18
|
+
item.name.name === name;
|
|
19
|
+
const attributes = nodePath.value.openingElement.attributes;
|
|
24
20
|
if (attributes) {
|
|
25
|
-
|
|
21
|
+
const iconPosition = attributes.find(findAttribute('iconPosition'));
|
|
26
22
|
if (((_a = iconPosition === null || iconPosition === void 0 ? void 0 : iconPosition.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
27
23
|
if (iconPosition.value.value === 'left') {
|
|
28
24
|
iconPosition.value.value = 'start';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getImportRenameMap } from './utils/getImportRenameMap';
|
|
2
|
-
|
|
2
|
+
const inputsMap = {
|
|
3
3
|
'@workday/canvas-kit-react/icon': [
|
|
4
4
|
'AccentIcon',
|
|
5
5
|
'AppletIcon',
|
|
@@ -10,8 +10,8 @@ var inputsMap = {
|
|
|
10
10
|
],
|
|
11
11
|
};
|
|
12
12
|
export default function transformer(file, api, options) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const j = api.jscodeshift;
|
|
14
|
+
const root = j(file.source);
|
|
15
15
|
// defaultImports should be an array of local names that were imported using
|
|
16
16
|
// a default import from any of the modules listed in inputsMap. For example,
|
|
17
17
|
// given...
|
|
@@ -24,26 +24,26 @@ export default function transformer(file, api, options) {
|
|
|
24
24
|
// ```
|
|
25
25
|
//
|
|
26
26
|
// ... defaultImports should be set to `['Checkbox', 'CanvasTextArea']`
|
|
27
|
-
|
|
28
|
-
root.find(j.ImportDefaultSpecifier).forEach(
|
|
27
|
+
const defaultImports = [];
|
|
28
|
+
root.find(j.ImportDefaultSpecifier).forEach(nodePath => {
|
|
29
29
|
var _a;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const packageName = nodePath.parent.node.source.value;
|
|
31
|
+
const localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
|
|
32
32
|
if (packageName in inputsMap && localName) {
|
|
33
33
|
defaultImports.push(localName);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
let runningSource = file.source;
|
|
37
|
+
for (const inputPackageName of Object.keys(inputsMap)) {
|
|
38
|
+
const currentRoot = j(runningSource);
|
|
39
|
+
const { containsCanvasImports, importMap, styledMap } = getImportRenameMap(j, currentRoot, inputPackageName);
|
|
40
40
|
if (containsCanvasImports) {
|
|
41
|
-
|
|
41
|
+
const inputNames = inputsMap[inputPackageName];
|
|
42
42
|
currentRoot
|
|
43
|
-
.find(j.JSXIdentifier,
|
|
44
|
-
.replaceWith(
|
|
43
|
+
.find(j.JSXIdentifier, (value) => value.name === 'iconRef')
|
|
44
|
+
.replaceWith(nodePath => {
|
|
45
45
|
var _a, _b, _c, _d;
|
|
46
|
-
|
|
46
|
+
const elementName = (_d = (_c = (_b = (_a = nodePath.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.name;
|
|
47
47
|
// Rewrite inputRef to ref if any of the following are true:
|
|
48
48
|
// (a) elementName was the name used in a default import of the current
|
|
49
49
|
// input being processed (e.g., `import TextInput ...`)
|
|
@@ -53,18 +53,14 @@ export default function transformer(file, api, options) {
|
|
|
53
53
|
// (c) elementName was created by calling `styled` on the current input
|
|
54
54
|
// being processed (e.g., `const StyledTextInput = styled(TextInput)`)
|
|
55
55
|
if (defaultImports.includes(elementName) ||
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
inputNames.map(n => importMap[n]).includes(elementName) ||
|
|
57
|
+
inputNames.map(n => styledMap[n]).includes(elementName)) {
|
|
58
58
|
return j.jsxIdentifier('ref');
|
|
59
59
|
}
|
|
60
60
|
return nodePath.value;
|
|
61
61
|
});
|
|
62
62
|
runningSource = currentRoot.toSource();
|
|
63
63
|
}
|
|
64
|
-
};
|
|
65
|
-
for (var _i = 0, _a = Object.keys(inputsMap); _i < _a.length; _i++) {
|
|
66
|
-
var inputPackageName = _a[_i];
|
|
67
|
-
_loop_1(inputPackageName);
|
|
68
64
|
}
|
|
69
65
|
return runningSource;
|
|
70
66
|
}
|