@workday/canvas-kit-codemod 9.0.0-alpha.359-next.4 → 9.0.0-alpha.362-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/dist/es6/v9/compoundToast.d.ts +3 -0
- package/dist/es6/v9/compoundToast.d.ts.map +1 -0
- package/dist/es6/v9/compoundToast.js +127 -0
- package/dist/es6/v9/index.d.ts.map +1 -1
- package/dist/es6/v9/index.js +4 -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/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compoundToast.d.ts","sourceRoot":"","sources":["../../../lib/v9/compoundToast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAc,OAAO,EAAC,MAAM,aAAa,CAAC;AAM/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA8M7E"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { getImportRenameMap } from '../v7/utils/getImportRenameMap';
|
|
2
|
+
import { hasImportSpecifiers } from '../v6/utils';
|
|
3
|
+
var toastPackage = '@workday/canvas-kit-react/toast';
|
|
4
|
+
export default function transformer(file, api, options) {
|
|
5
|
+
var j = api.jscodeshift;
|
|
6
|
+
var root = j(file.source);
|
|
7
|
+
if (!hasImportSpecifiers(api, root, toastPackage, ['Toast'])) {
|
|
8
|
+
return file.source;
|
|
9
|
+
}
|
|
10
|
+
var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/toast'), importMap = _a.importMap, styledMap = _a.styledMap;
|
|
11
|
+
root
|
|
12
|
+
.find(j.JSXElement, function (value) {
|
|
13
|
+
return value.openingElement.name.type === 'JSXIdentifier' &&
|
|
14
|
+
(value.openingElement.name.name === importMap.Toast ||
|
|
15
|
+
value.openingElement.name.name === styledMap.Toast);
|
|
16
|
+
})
|
|
17
|
+
.forEach(function (nodePath) {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
// Toast Body JSX
|
|
20
|
+
var ToastBodyJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Toast), j.jsxIdentifier('Body'));
|
|
21
|
+
// Toast CloseIcon JSX
|
|
22
|
+
var ToastCloseJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Toast), j.jsxIdentifier('Close'));
|
|
23
|
+
// Toast Message JSX
|
|
24
|
+
var ToastMessageJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Toast), j.jsxIdentifier('Message'));
|
|
25
|
+
// Toast Icon JSX
|
|
26
|
+
var ToastIconJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Toast), j.jsxIdentifier('Icon'));
|
|
27
|
+
// Toast Link JSX
|
|
28
|
+
var ToastLinkJSX = j.jsxMemberExpression(j.jsxIdentifier(importMap.Toast), j.jsxIdentifier('Link'));
|
|
29
|
+
// Attributes
|
|
30
|
+
var attributes = nodePath.value.openingElement.attributes;
|
|
31
|
+
var defaultIconAttributes = [
|
|
32
|
+
j.jsxAttribute(j.jsxIdentifier('color'), j.stringLiteral('greenApple400')),
|
|
33
|
+
j.jsxAttribute(j.jsxIdentifier('icon'), j.jsxExpressionContainer(j.jsxIdentifier('checkIcon'))),
|
|
34
|
+
];
|
|
35
|
+
var unchangedIconAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attr) {
|
|
36
|
+
return attr.type === 'JSXAttribute' &&
|
|
37
|
+
typeof attr.name.name === 'string' &&
|
|
38
|
+
/icon|iconColor/g.test(attr.name.name);
|
|
39
|
+
});
|
|
40
|
+
var updatedIconAttrs = unchangedIconAttributes === null || unchangedIconAttributes === void 0 ? void 0 : unchangedIconAttributes.map(function (specifier) {
|
|
41
|
+
if (specifier.type === 'JSXAttribute' && specifier.name.name === 'iconColor') {
|
|
42
|
+
specifier.name.name = 'color';
|
|
43
|
+
}
|
|
44
|
+
return specifier;
|
|
45
|
+
});
|
|
46
|
+
var chooseIconAttrs = unchangedIconAttributes && unchangedIconAttributes.length
|
|
47
|
+
? updatedIconAttrs
|
|
48
|
+
: defaultIconAttributes;
|
|
49
|
+
var closeAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'onClose'; });
|
|
50
|
+
var linkAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attr) {
|
|
51
|
+
return attr.type === 'JSXAttribute' &&
|
|
52
|
+
(attr.name.name === 'actionText' || attr.name.name === 'onActionClick');
|
|
53
|
+
});
|
|
54
|
+
// Elements
|
|
55
|
+
var OpeningIconJSX = j.jsxOpeningElement(ToastIconJSX, chooseIconAttrs, true);
|
|
56
|
+
var IconElement = j.jsxElement(OpeningIconJSX);
|
|
57
|
+
// Add `import {checkIcon} from '@workday/canvas-system-icons-web'`
|
|
58
|
+
// when there's a default toast
|
|
59
|
+
var lastImport = root.find(j.ImportDeclaration).at(-1);
|
|
60
|
+
if (lastImport && !(unchangedIconAttributes === null || unchangedIconAttributes === void 0 ? void 0 : unchangedIconAttributes.length)) {
|
|
61
|
+
lastImport.insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('checkIcon'))], j.stringLiteral('@workday/canvas-system-icons-web')));
|
|
62
|
+
}
|
|
63
|
+
var lineBreakStart = j.jsxText('\n ');
|
|
64
|
+
var lineBreakEnd = j.jsxText('\n');
|
|
65
|
+
// Filter out all old props
|
|
66
|
+
var filteredAttrNames = [
|
|
67
|
+
'actionText',
|
|
68
|
+
'icon',
|
|
69
|
+
'iconColor',
|
|
70
|
+
'onActionClick',
|
|
71
|
+
'onClose',
|
|
72
|
+
'color',
|
|
73
|
+
];
|
|
74
|
+
var filterAttr = (_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.filter(function (attr) {
|
|
75
|
+
return !(attr.type === 'JSXAttribute' &&
|
|
76
|
+
typeof attr.name.name === 'string' &&
|
|
77
|
+
filteredAttrNames.includes(attr.name.name));
|
|
78
|
+
});
|
|
79
|
+
nodePath.value.openingElement.attributes = filterAttr;
|
|
80
|
+
var OpeningCloseElement = j.jsxOpeningElement(ToastCloseJSX, closeAttributes, true);
|
|
81
|
+
var CloseElement = j.jsxElement(OpeningCloseElement);
|
|
82
|
+
// grab the onActionClick attr
|
|
83
|
+
var onActionClickAttr = linkAttributes === null || linkAttributes === void 0 ? void 0 : linkAttributes.filter(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'onActionClick'; });
|
|
84
|
+
// rename onActionClick to onClick for the Toast.Link component
|
|
85
|
+
var renameOnActionClick = onActionClickAttr === null || onActionClickAttr === void 0 ? void 0 : onActionClickAttr.map(function (attr) {
|
|
86
|
+
if (attr.type === 'JSXAttribute') {
|
|
87
|
+
attr.name.name = 'onClick';
|
|
88
|
+
}
|
|
89
|
+
return attr;
|
|
90
|
+
});
|
|
91
|
+
// grab the actionText prop
|
|
92
|
+
var actionTextAttr = linkAttributes === null || linkAttributes === void 0 ? void 0 : linkAttributes.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'actionText'; });
|
|
93
|
+
var actionText = actionTextAttr &&
|
|
94
|
+
actionTextAttr.type === 'JSXAttribute' &&
|
|
95
|
+
((_b = actionTextAttr.value) === null || _b === void 0 ? void 0 : _b.type) === 'StringLiteral'
|
|
96
|
+
? [actionTextAttr.value]
|
|
97
|
+
: [];
|
|
98
|
+
var LinkElement = j.jsxElement(j.jsxOpeningElement(ToastLinkJSX, renameOnActionClick), j.jsxClosingElement(ToastLinkJSX), actionText);
|
|
99
|
+
// Toast Message JSX inclduing children which should be the string
|
|
100
|
+
var MessageElement = j.jsxElement(j.jsxOpeningElement(ToastMessageJSX), j.jsxClosingElement(ToastMessageJSX), nodePath.value.children);
|
|
101
|
+
if (linkAttributes && (linkAttributes === null || linkAttributes === void 0 ? void 0 : linkAttributes.length)) {
|
|
102
|
+
// If there's a link, add mode="dialog" to the main Toast component for accessibility
|
|
103
|
+
nodePath.value.openingElement.attributes = [
|
|
104
|
+
j.jsxAttribute(j.jsxIdentifier('mode'), j.stringLiteral('dialog')),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
// Body element including Message and its children
|
|
108
|
+
var BodyElement = j.jsxElement(j.jsxOpeningElement(ToastBodyJSX), j.jsxClosingElement(ToastBodyJSX), [lineBreakStart, MessageElement, lineBreakEnd]);
|
|
109
|
+
// If there's an actionText or onActionClick, add the Toast.Link with its attributes inside Toast.Body
|
|
110
|
+
if (linkAttributes && linkAttributes.length) {
|
|
111
|
+
(_c = BodyElement.children) === null || _c === void 0 ? void 0 : _c.push(LinkElement, lineBreakEnd);
|
|
112
|
+
}
|
|
113
|
+
// Default Toast with no Close or Link
|
|
114
|
+
nodePath.value.children = [
|
|
115
|
+
lineBreakStart,
|
|
116
|
+
IconElement,
|
|
117
|
+
lineBreakEnd,
|
|
118
|
+
BodyElement,
|
|
119
|
+
lineBreakEnd,
|
|
120
|
+
];
|
|
121
|
+
// If there's an onClose, add the Toast.Close with its attributes
|
|
122
|
+
if (closeAttributes && (closeAttributes === null || closeAttributes === void 0 ? void 0 : closeAttributes.length)) {
|
|
123
|
+
nodePath.value.children.push(CloseElement, lineBreakEnd);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return root.toSource();
|
|
127
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v9/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v9/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAMtC,QAAA,MAAM,SAAS,EAAE,SAShB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
package/dist/es6/v9/index.js
CHANGED
|
@@ -10,11 +10,15 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import softDeprecateStack from './deprecateStack';
|
|
13
|
+
import promoteToast from './promoteToast';
|
|
14
|
+
import compoundToast from './compoundToast';
|
|
13
15
|
var transform = function (file, api, options) {
|
|
14
16
|
// These will run in order. If your transform depends on others, place yours after dependent transforms
|
|
15
17
|
var fixes = [
|
|
16
18
|
// add codemods here
|
|
17
19
|
softDeprecateStack,
|
|
20
|
+
promoteToast,
|
|
21
|
+
compoundToast,
|
|
18
22
|
];
|
|
19
23
|
return fixes.reduce(function (source, fix) { return fix(__assign(__assign({}, file), { source: source }), api, options); }, file.source);
|
|
20
24
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promoteToast.d.ts","sourceRoot":"","sources":["../../../lib/v9/promoteToast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAIlE,QAAA,MAAM,SAAS,EAAE,SAyEhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
var transform = function (file, api) {
|
|
2
|
+
var j = api.jscodeshift;
|
|
3
|
+
var root = j(file.source);
|
|
4
|
+
var toastSpecifiers = [];
|
|
5
|
+
var foundImport = [];
|
|
6
|
+
root
|
|
7
|
+
.find(j.ImportDeclaration, {
|
|
8
|
+
source: { value: function (value) { return value.includes('@workday/canvas-kit-labs-react'); } },
|
|
9
|
+
})
|
|
10
|
+
.forEach(function (nodePath) {
|
|
11
|
+
var _a;
|
|
12
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
|
|
13
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
14
|
+
specifier.local &&
|
|
15
|
+
specifier.imported.name === 'Toast') {
|
|
16
|
+
toastSpecifiers.push({
|
|
17
|
+
importedName: specifier.imported.name,
|
|
18
|
+
name: specifier.local.name,
|
|
19
|
+
});
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
24
|
+
if (toastSpecifiers.length) {
|
|
25
|
+
foundImport.push(nodePath);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
var existingToastImports = root.find(j.ImportDeclaration, {
|
|
29
|
+
source: { value: '@workday/canvas-kit-react/toast' },
|
|
30
|
+
});
|
|
31
|
+
var mapToSpecifiers = function (specifier) {
|
|
32
|
+
return j.importSpecifier(j.identifier(specifier.importedName), specifier.name ? j.identifier(specifier.name) : undefined);
|
|
33
|
+
};
|
|
34
|
+
// add to existing import
|
|
35
|
+
if (existingToastImports.length) {
|
|
36
|
+
existingToastImports.forEach(function (nodePath) {
|
|
37
|
+
var _a;
|
|
38
|
+
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(toastSpecifiers.map(mapToSpecifiers));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// create new import
|
|
43
|
+
if (foundImport.length) {
|
|
44
|
+
foundImport[0].insertBefore(j.importDeclaration(toastSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/toast')));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
foundImport.forEach(function (importPath) {
|
|
48
|
+
var _a;
|
|
49
|
+
if (!((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) ||
|
|
50
|
+
importPath.value.source.value === '@workday/canvas-kit-labs-react/toast') {
|
|
51
|
+
importPath.prune();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return root.toSource();
|
|
55
|
+
};
|
|
56
|
+
export default transform;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@workday/canvas-kit-codemod",
|
|
3
3
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "9.0.0-alpha.
|
|
5
|
+
"version": "9.0.0-alpha.362-next.2+ea2fe722",
|
|
6
6
|
"description": "A collection of codemods for use on Workday Canvas Kit packages.",
|
|
7
7
|
"main": "dist/es6/index.js",
|
|
8
8
|
"sideEffects": false,
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"test": "TZ=UTC jest -c ../../jest.config.js",
|
|
44
44
|
"typecheck:src": "tsc -p . --noEmit --incremental false"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "ea2fe722d1176835120f765c4b9b88dcd5234fe5"
|
|
47
47
|
}
|