@workday/canvas-kit-codemod 15.0.0-alpha.1301-next.0 → 15.0.0-alpha.1326-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es6/v13.2/mapping/index.d.ts +59 -1
- package/dist/es6/v13.2/mapping/index.d.ts.map +1 -1
- package/dist/es6/v13.2/mapping/index.js +88 -1
- package/dist/es6/v13.2/migrateColorTokens.d.ts.map +1 -1
- package/dist/es6/v13.2/migrateColorTokens.js +64 -13
- package/dist/es6/v13.2/migrateDepthTokens.d.ts.map +1 -1
- package/dist/es6/v13.2/migrateDepthTokens.js +42 -26
- package/dist/es6/v13.2/migrateOtherTokens.d.ts.map +1 -1
- package/dist/es6/v13.2/migrateOtherTokens.js +37 -67
- package/dist/es6/v13.2/migrateTypeTokens.d.ts.map +1 -1
- package/dist/es6/v13.2/migrateTypeTokens.js +43 -19
- package/dist/es6/v13.2/utils/filterOutImports.d.ts +6 -1
- package/dist/es6/v13.2/utils/filterOutImports.d.ts.map +1 -1
- package/dist/es6/v13.2/utils/filterOutImports.js +22 -4
- package/dist/es6/v13.2/utils/getImports.d.ts +3 -0
- package/dist/es6/v13.2/utils/getImports.d.ts.map +1 -0
- package/dist/es6/v13.2/utils/getImports.js +12 -0
- package/dist/es6/v13.2/utils/index.d.ts +1 -0
- package/dist/es6/v13.2/utils/index.d.ts.map +1 -1
- package/dist/es6/v13.2/utils/index.js +1 -0
- package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts +1 -1
- package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts.map +1 -1
- package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.js +151 -33
- package/dist/es6/v13.2/utils/varToMemberExpression.d.ts.map +1 -1
- package/dist/es6/v13.2/utils/varToMemberExpression.js +1 -1
- package/dist/es6/v14-tokens/index.d.ts.map +1 -1
- package/dist/es6/v14-tokens/index.js +9 -2
- package/dist/es6/v14-tokens/migrateColorTokens.d.ts.map +1 -1
- package/dist/es6/v14-tokens/migrateColorTokens.js +10 -23
- package/dist/es6/v14-tokens/utils/transformObjectPropertyRecursively.d.ts.map +1 -1
- package/dist/es6/v14-tokens/utils/transformObjectPropertyRecursively.js +31 -28
- package/dist/es6/v15/index.d.ts +4 -0
- package/dist/es6/v15/index.d.ts.map +1 -0
- package/dist/es6/v15/index.js +6 -0
- package/dist/es6/v15/utils/getImportRenameMap.d.ts +7 -0
- package/dist/es6/v15/utils/getImportRenameMap.d.ts.map +1 -0
- package/dist/es6/v15/utils/getImportRenameMap.js +44 -0
- package/index.js +7 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addMissingImports, filterOutImports, varToMemberExpression } from './utils';
|
|
1
|
+
import { addMissingImports, filterOutImports, getImports, varToMemberExpression } from './utils';
|
|
2
2
|
import { typeProps } from './mapping/typeProps';
|
|
3
3
|
import { mapping } from './mapping';
|
|
4
4
|
const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
|
|
@@ -12,7 +12,7 @@ const transform = (file, api) => {
|
|
|
12
12
|
source: { value: (value) => canvasImportSources.includes(value) },
|
|
13
13
|
})
|
|
14
14
|
.forEach(nodePath => {
|
|
15
|
-
importDeclaration = { ...importDeclaration, ...
|
|
15
|
+
importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
|
|
16
16
|
});
|
|
17
17
|
if (!Object.values(importDeclaration).includes('type')) {
|
|
18
18
|
return root.toSource();
|
|
@@ -40,14 +40,26 @@ const transform = (file, api) => {
|
|
|
40
40
|
const object = argument.object;
|
|
41
41
|
const level = object.property.name;
|
|
42
42
|
const size = argument.property.name;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const mapKeys = mapping.type.keys.levels.values;
|
|
44
|
+
const levelKeys = mapKeys[level] || {};
|
|
45
|
+
const tokens = levelKeys[size];
|
|
46
|
+
if (tokens) {
|
|
47
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
48
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
49
|
+
const properties = typeProps
|
|
50
|
+
.filter(prop => tokens[prop])
|
|
51
|
+
.map((key) => {
|
|
52
|
+
const tokenValue = tokens[key];
|
|
53
|
+
if (!tokenValue) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return j.objectProperty(j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, tokenValue)]));
|
|
57
|
+
})
|
|
58
|
+
.filter((prop) => prop !== null);
|
|
59
|
+
// Replace the spread element with individual properties
|
|
60
|
+
return properties;
|
|
61
|
+
}
|
|
62
|
+
return nodePath.value;
|
|
51
63
|
});
|
|
52
64
|
root
|
|
53
65
|
.find(j.MemberExpression, (value) => {
|
|
@@ -80,7 +92,7 @@ const transform = (file, api) => {
|
|
|
80
92
|
return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]);
|
|
81
93
|
}
|
|
82
94
|
}
|
|
83
|
-
return nodePath;
|
|
95
|
+
return nodePath.value;
|
|
84
96
|
});
|
|
85
97
|
root
|
|
86
98
|
.find(j.MemberExpression, (value) => {
|
|
@@ -104,7 +116,10 @@ const transform = (file, api) => {
|
|
|
104
116
|
const lowestPropertyValue = lowestProperty.type === 'Identifier' ? lowestProperty.name : lowestProperty.value;
|
|
105
117
|
const innerKey = innerProperty.name;
|
|
106
118
|
if (mainProperty.name === 'properties') {
|
|
107
|
-
const { name, values } = mapping.type.keys[innerKey];
|
|
119
|
+
const { name, values } = mapping.type.keys[innerKey] || {};
|
|
120
|
+
if (!name || !values) {
|
|
121
|
+
return nodePath.value;
|
|
122
|
+
}
|
|
108
123
|
const newValue = values[lowestPropertyValue];
|
|
109
124
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
110
125
|
if (newValue.includes('.')) {
|
|
@@ -123,16 +138,25 @@ const transform = (file, api) => {
|
|
|
123
138
|
const { values } = mapping.type.keys.levels;
|
|
124
139
|
const levels = values[innerKey];
|
|
125
140
|
const lowestKey = lowestPropertyValue;
|
|
126
|
-
const tokens = levels[lowestKey];
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
const tokens = levels === null || levels === void 0 ? void 0 : levels[lowestKey];
|
|
142
|
+
if (tokens) {
|
|
143
|
+
const props = Object.entries(tokens).map(([key, value]) => {
|
|
144
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
145
|
+
return j.property('init', j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]));
|
|
146
|
+
});
|
|
147
|
+
return j.objectExpression(props);
|
|
148
|
+
}
|
|
132
149
|
}
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
|
-
return nodePath;
|
|
152
|
+
return nodePath.value;
|
|
153
|
+
});
|
|
154
|
+
root
|
|
155
|
+
.find(j.ImportDeclaration, {
|
|
156
|
+
source: { value: (value) => canvasImportSources.includes(value) },
|
|
157
|
+
})
|
|
158
|
+
.forEach(nodePath => {
|
|
159
|
+
filterOutImports({ root, j }, nodePath, 'type');
|
|
136
160
|
});
|
|
137
161
|
return root.toSource();
|
|
138
162
|
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { ASTPath, ImportDeclaration } from 'jscodeshift';
|
|
2
|
-
|
|
2
|
+
type ImportType = 'colors' | 'depth' | 'space' | 'type' | 'borderRadius';
|
|
3
|
+
export declare const filterOutImports: ({ root, j }: {
|
|
4
|
+
root: any;
|
|
5
|
+
j: any;
|
|
6
|
+
}, nodePath: ASTPath<ImportDeclaration>, type: ImportType | ImportType[]) => Record<string, string>;
|
|
7
|
+
export {};
|
|
3
8
|
//# sourceMappingURL=filterOutImports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,KAAK,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC;AASzE,eAAO,MAAM,gBAAgB;UACT,GAAG;OAAK,GAAG;aACnB,QAAQ,iBAAiB,CAAC,QAC9B,UAAU,GAAG,UAAU,EAAE,2BA0ChC,CAAC"}
|
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
const canvasImportSources = [
|
|
2
|
+
'@workday/canvas-kit-react/tokens',
|
|
3
|
+
'@workday/canvas-colors-web',
|
|
4
|
+
'@workday/canvas-space-web',
|
|
5
|
+
'@workday/canvas-depth-web',
|
|
6
|
+
];
|
|
7
|
+
export const filterOutImports = ({ root, j }, nodePath, type) => {
|
|
2
8
|
var _a, _b;
|
|
3
9
|
const importName = {};
|
|
4
10
|
nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(specifier => {
|
|
5
|
-
var _a;
|
|
6
11
|
if (specifier.type === 'ImportSpecifier' && specifier.local) {
|
|
12
|
+
let isInstanceExist = false;
|
|
7
13
|
const localName = specifier.local.name.toString();
|
|
8
14
|
const importedName = specifier.imported.name.toString();
|
|
9
15
|
importName[localName] = importedName;
|
|
10
|
-
|
|
11
|
-
(
|
|
16
|
+
root
|
|
17
|
+
.find(j.MemberExpression, {
|
|
18
|
+
object: {
|
|
19
|
+
name: importedName,
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
.forEach(() => {
|
|
23
|
+
isInstanceExist = true;
|
|
24
|
+
});
|
|
25
|
+
return (isInstanceExist ||
|
|
26
|
+
!(((typeof type === 'string' && importedName.toLowerCase().includes(type)) ||
|
|
27
|
+
type.includes(importedName)) &&
|
|
28
|
+
typeof nodePath.value.source.value === 'string' &&
|
|
29
|
+
canvasImportSources.includes(nodePath.value.source.value)));
|
|
12
30
|
}
|
|
13
31
|
return true;
|
|
14
32
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/getImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,UAAU,aAAc,QAAQ,iBAAiB,CAAC,2BAa9D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const getImports = (nodePath) => {
|
|
2
|
+
var _a;
|
|
3
|
+
const importName = {};
|
|
4
|
+
(_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(specifier => {
|
|
5
|
+
if (specifier.type === 'ImportSpecifier' && specifier.local) {
|
|
6
|
+
const localName = specifier.local.name.toString();
|
|
7
|
+
const importedName = specifier.imported.name.toString();
|
|
8
|
+
importName[localName] = importedName;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return importName;
|
|
12
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const transformObjectPropertyRecursively: ({ j, root }: any, property: any, importDeclaration: {
|
|
2
2
|
[key: string]: any;
|
|
3
|
-
}, isCanvasKitStyling?: boolean) => any;
|
|
3
|
+
}, isCanvasKitStyling?: boolean, tokenTypes?: string[]) => any;
|
|
4
4
|
//# sourceMappingURL=transformObjectPropertyRecursively.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,eACf,MAAM,EAAE,KACpB,GA2UF,CAAC"}
|
|
@@ -1,26 +1,60 @@
|
|
|
1
|
-
import { systemColors } from '../mapping';
|
|
1
|
+
import { mapping, paletteNames, systemColors } from '../mapping';
|
|
2
2
|
import { addMissingImports } from './addMissingImports';
|
|
3
3
|
import { varToMemberExpression } from './varToMemberExpression';
|
|
4
|
-
export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling) => {
|
|
4
|
+
export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling, tokenTypes) => {
|
|
5
5
|
var _a, _b, _c;
|
|
6
|
+
// Helper to create object property preserving computed flag
|
|
7
|
+
const createObjectProperty = (key, value) => {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
const prop = j.objectProperty(key, value);
|
|
10
|
+
// Preserve computed flag: if explicitly true, or if key is not a simple literal/identifier
|
|
11
|
+
if (property.computed === true ||
|
|
12
|
+
(((_a = property.key) === null || _a === void 0 ? void 0 : _a.type) !== 'Identifier' &&
|
|
13
|
+
((_b = property.key) === null || _b === void 0 ? void 0 : _b.type) !== 'StringLiteral' &&
|
|
14
|
+
((_c = property.key) === null || _c === void 0 ? void 0 : _c.type) !== 'NumericLiteral')) {
|
|
15
|
+
prop.computed = true;
|
|
16
|
+
}
|
|
17
|
+
return prop;
|
|
18
|
+
};
|
|
6
19
|
if (property.type === 'ObjectProperty' &&
|
|
7
20
|
property.key.type === 'Identifier' &&
|
|
8
21
|
property.value.type === 'MemberExpression' &&
|
|
9
22
|
property.value.object.type === 'Identifier' &&
|
|
10
|
-
property.value.property.type === 'Identifier'
|
|
11
|
-
importDeclaration[property.value.object.name]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
property.value.property.type === 'Identifier') {
|
|
24
|
+
const importedTokenName = importDeclaration[property.value.object.name];
|
|
25
|
+
// Handle colors tokens
|
|
26
|
+
if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
|
|
27
|
+
const key = property.key.name;
|
|
28
|
+
const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
|
|
29
|
+
const { property: value } = property.value;
|
|
30
|
+
const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
|
|
31
|
+
if (colorToken) {
|
|
32
|
+
if (!isCanvasKitStyling) {
|
|
33
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
34
|
+
}
|
|
35
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
36
|
+
return createObjectProperty(property.key, isCanvasKitStyling
|
|
37
|
+
? varToMemberExpression(j, colorToken)
|
|
38
|
+
: j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Handle space and borderRadius tokens
|
|
42
|
+
if (tokenTypes &&
|
|
43
|
+
tokenTypes.includes(importedTokenName) &&
|
|
44
|
+
['space', 'borderRadius'].includes(importedTokenName)) {
|
|
45
|
+
const map = mapping[importedTokenName];
|
|
46
|
+
const propertyName = property.value.property.name;
|
|
47
|
+
if ((map === null || map === void 0 ? void 0 : map.type) === 'system' && map.keys) {
|
|
48
|
+
const newValue = map.keys[propertyName];
|
|
49
|
+
if (newValue) {
|
|
50
|
+
if (!isCanvasKitStyling) {
|
|
51
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
52
|
+
}
|
|
53
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
54
|
+
const tokenPath = j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(newValue));
|
|
55
|
+
return createObjectProperty(property.key, isCanvasKitStyling ? tokenPath : j.callExpression(j.identifier('cssVar'), [tokenPath]));
|
|
56
|
+
}
|
|
19
57
|
}
|
|
20
|
-
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
21
|
-
return j.objectProperty(j.identifier(key), isCanvasKitStyling
|
|
22
|
-
? varToMemberExpression(j, colorToken)
|
|
23
|
-
: j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
|
|
24
58
|
}
|
|
25
59
|
}
|
|
26
60
|
if (property.type === 'ObjectProperty' && property.value.type === 'TemplateLiteral') {
|
|
@@ -28,21 +62,72 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
|
|
|
28
62
|
const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
|
|
29
63
|
const transformedExpressions = templateLiteral.expressions.map((expr) => {
|
|
30
64
|
var _a;
|
|
65
|
+
if (expr.type === 'CallExpression') {
|
|
66
|
+
expr.arguments = expr.arguments.map((arg) => {
|
|
67
|
+
var _a;
|
|
68
|
+
if (arg.type === 'MemberExpression' &&
|
|
69
|
+
arg.object.type === 'Identifier' &&
|
|
70
|
+
arg.object.name === 'colors' &&
|
|
71
|
+
arg.property.type === 'Identifier') {
|
|
72
|
+
const keyName = property.key.type === 'Identifier' ? property.key.name : null;
|
|
73
|
+
const tokens = keyName
|
|
74
|
+
? (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _a === void 0 ? void 0 : _a[1]
|
|
75
|
+
: {};
|
|
76
|
+
const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[arg.property.name];
|
|
77
|
+
if (colorToken) {
|
|
78
|
+
return isCanvasKitStyling
|
|
79
|
+
? varToMemberExpression(j, colorToken)
|
|
80
|
+
: j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return arg;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
31
86
|
if (expr.type === 'MemberExpression' &&
|
|
32
87
|
expr.object.type === 'Identifier' &&
|
|
33
|
-
expr.property.type === 'Identifier'
|
|
34
|
-
importDeclaration[expr.object.name]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
88
|
+
expr.property.type === 'Identifier') {
|
|
89
|
+
const importedTokenName = importDeclaration[expr.object.name];
|
|
90
|
+
// Handle colors tokens
|
|
91
|
+
if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
|
|
92
|
+
const keyName = property.key.type === 'Identifier' ? property.key.name : null;
|
|
93
|
+
const tokens = keyName
|
|
94
|
+
? (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _a === void 0 ? void 0 : _a[1]
|
|
95
|
+
: null;
|
|
96
|
+
const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
|
|
97
|
+
if (colorToken) {
|
|
98
|
+
if (!isCanvasKitStyling) {
|
|
99
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
100
|
+
}
|
|
101
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
102
|
+
return isCanvasKitStyling
|
|
103
|
+
? varToMemberExpression(j, colorToken)
|
|
104
|
+
: j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Handle space and borderRadius tokens
|
|
108
|
+
if (tokenTypes &&
|
|
109
|
+
tokenTypes.includes(importedTokenName) &&
|
|
110
|
+
['space', 'borderRadius'].includes(importedTokenName)) {
|
|
111
|
+
const map = mapping[importedTokenName];
|
|
112
|
+
const propertyName = expr.property.name;
|
|
113
|
+
if ((map === null || map === void 0 ? void 0 : map.type) === 'system' && map.keys) {
|
|
114
|
+
const newValue = map.keys[propertyName];
|
|
115
|
+
if (newValue) {
|
|
116
|
+
if (!isCanvasKitStyling) {
|
|
117
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
118
|
+
}
|
|
119
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
120
|
+
const tokenPath = j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(newValue));
|
|
121
|
+
return isCanvasKitStyling
|
|
122
|
+
? tokenPath
|
|
123
|
+
: j.callExpression(j.identifier('cssVar'), [tokenPath]);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
41
126
|
}
|
|
42
127
|
}
|
|
43
128
|
return expr;
|
|
44
129
|
});
|
|
45
|
-
return
|
|
130
|
+
return createObjectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
|
|
46
131
|
}
|
|
47
132
|
if (property.type === 'ObjectProperty' && property.value.type === 'ConditionalExpression') {
|
|
48
133
|
const { test, consequent, alternate } = property.value;
|
|
@@ -54,23 +139,56 @@ export const transformObjectPropertyRecursively = ({ j, root }, property, import
|
|
|
54
139
|
alternate.object.type === 'Identifier' &&
|
|
55
140
|
alternate.property.type === 'Identifier' &&
|
|
56
141
|
importDeclaration[alternate.object.name] === 'colors') {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
142
|
+
const keyName = property.key.type === 'Identifier' ? property.key.name : null;
|
|
143
|
+
const consequentTokens = keyName
|
|
144
|
+
? (_b = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _b === void 0 ? void 0 : _b[1]
|
|
145
|
+
: null;
|
|
146
|
+
const alternateTokens = keyName
|
|
147
|
+
? (_c = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === keyName))) === null || _c === void 0 ? void 0 : _c[1]
|
|
148
|
+
: null;
|
|
59
149
|
const consequentColorToken = consequentTokens === null || consequentTokens === void 0 ? void 0 : consequentTokens[consequent.property.name];
|
|
60
150
|
const alternateColorToken = alternateTokens === null || alternateTokens === void 0 ? void 0 : alternateTokens[alternate.property.name];
|
|
61
151
|
if (consequentColorToken && alternateColorToken) {
|
|
62
|
-
|
|
152
|
+
if (!isCanvasKitStyling) {
|
|
153
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
154
|
+
}
|
|
63
155
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
|
|
64
|
-
return
|
|
65
|
-
varToMemberExpression(j, consequentColorToken)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
156
|
+
return createObjectProperty(property.key, j.conditionalExpression(test, isCanvasKitStyling
|
|
157
|
+
? varToMemberExpression(j, consequentColorToken)
|
|
158
|
+
: j.callExpression(j.identifier('cssVar'), [
|
|
159
|
+
varToMemberExpression(j, consequentColorToken),
|
|
160
|
+
]), isCanvasKitStyling
|
|
161
|
+
? varToMemberExpression(j, alternateColorToken)
|
|
162
|
+
: j.callExpression(j.identifier('cssVar'), [
|
|
163
|
+
varToMemberExpression(j, alternateColorToken),
|
|
164
|
+
])));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (property.type === 'ObjectProperty' &&
|
|
169
|
+
property.key.type === 'Identifier' &&
|
|
170
|
+
property.value.type === 'MemberExpression' &&
|
|
171
|
+
property.value.object.type === 'Identifier' &&
|
|
172
|
+
property.value.property.type === 'Identifier') {
|
|
173
|
+
const importedTokenName = importDeclaration[property.value.object.name];
|
|
174
|
+
// Handle colors tokens
|
|
175
|
+
if (importedTokenName === 'colors' && (!tokenTypes || tokenTypes.includes('colors'))) {
|
|
176
|
+
const { property: value } = property.value;
|
|
177
|
+
if (paletteNames.some(name => value.name.includes(name))) {
|
|
178
|
+
if (!isCanvasKitStyling) {
|
|
179
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
|
|
180
|
+
}
|
|
181
|
+
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
|
|
182
|
+
return createObjectProperty(property.key, isCanvasKitStyling
|
|
183
|
+
? j.memberExpression(j.identifier('base'), j.identifier(value.name))
|
|
184
|
+
: j.callExpression(j.identifier('cssVar'), [
|
|
185
|
+
j.memberExpression(j.identifier('base'), j.identifier(value.name)),
|
|
186
|
+
]));
|
|
69
187
|
}
|
|
70
188
|
}
|
|
71
189
|
}
|
|
72
190
|
if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
|
|
73
|
-
return
|
|
191
|
+
return createObjectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling, tokenTypes))));
|
|
74
192
|
}
|
|
75
193
|
return property;
|
|
76
194
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,QAU1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAQtC,QAAA,MAAM,SAAS,EAAE,SAShB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import migrateNewColorTokens from './migrateColorTokens';
|
|
2
|
+
import migrateColorTokens from '../v13.2/migrateColorTokens';
|
|
2
3
|
import migrateDepthTokens from '../v13.2/migrateDepthTokens';
|
|
3
4
|
import migrateOtherTokens from '../v13.2/migrateOtherTokens';
|
|
4
5
|
import migrateTypeTokens from '../v13.2/migrateTypeTokens';
|
|
5
6
|
const transform = (file, api, options) => {
|
|
6
|
-
const fixes = [
|
|
7
|
+
const fixes = [
|
|
8
|
+
migrateColorTokens,
|
|
9
|
+
migrateNewColorTokens,
|
|
10
|
+
migrateDepthTokens,
|
|
11
|
+
migrateTypeTokens,
|
|
12
|
+
migrateOtherTokens,
|
|
13
|
+
];
|
|
7
14
|
return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
|
|
8
15
|
};
|
|
9
16
|
export default transform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v14-tokens/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AASlD,QAAA,MAAM,SAAS,EAAE,SA6GhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { addMissingImports,
|
|
1
|
+
import { addMissingImports, getImports } from '../v13.2/utils';
|
|
2
2
|
import { transformObjectPropertyRecursively } from './utils/transformObjectPropertyRecursively';
|
|
3
|
-
import { mapping } from '../v13.2/mapping';
|
|
4
3
|
import baseMapping from './baseMapping';
|
|
5
|
-
const canvasImportSources = [
|
|
6
|
-
'@workday/canvas-kit-styling',
|
|
7
|
-
'@workday/canvas-kit-react/tokens',
|
|
8
|
-
'@workday/canvas-tokens-web',
|
|
9
|
-
];
|
|
4
|
+
const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-tokens-web'];
|
|
10
5
|
const transform = (file, api) => {
|
|
11
6
|
const j = api.jscodeshift;
|
|
12
7
|
const root = j(file.source);
|
|
@@ -17,9 +12,9 @@ const transform = (file, api) => {
|
|
|
17
12
|
source: { value: (value) => canvasImportSources.includes(value) },
|
|
18
13
|
})
|
|
19
14
|
.forEach(nodePath => {
|
|
20
|
-
importDeclaration = { ...importDeclaration, ...
|
|
15
|
+
importDeclaration = { ...importDeclaration, ...getImports(nodePath) };
|
|
21
16
|
});
|
|
22
|
-
if (!Object.values(importDeclaration).some(importedValue => importedValue === '
|
|
17
|
+
if (!Object.values(importDeclaration).some(importedValue => importedValue === 'base')) {
|
|
23
18
|
return root.toSource();
|
|
24
19
|
}
|
|
25
20
|
root
|
|
@@ -43,7 +38,8 @@ const transform = (file, api) => {
|
|
|
43
38
|
.find(j.MemberExpression, (value) => {
|
|
44
39
|
return (value.type === 'MemberExpression' &&
|
|
45
40
|
checkImport(value.object.name) &&
|
|
46
|
-
Object.keys(baseMapping).includes(value.property.name)
|
|
41
|
+
Object.keys(baseMapping).includes(value.property.name) &&
|
|
42
|
+
importDeclaration[value.object.name] === 'base');
|
|
47
43
|
})
|
|
48
44
|
.replaceWith(nodePath => {
|
|
49
45
|
const mainWrapper = nodePath.value.object;
|
|
@@ -51,24 +47,15 @@ const transform = (file, api) => {
|
|
|
51
47
|
const mainObject = mainWrapper;
|
|
52
48
|
const mainName = mainObject.name;
|
|
53
49
|
const lowestProperty = nodePath.value.property;
|
|
54
|
-
|
|
55
|
-
const map = importedName === 'base' ? { type: 'base' } : mapping[importedName];
|
|
56
|
-
if (map.type === 'base' && lowestProperty.type === 'Identifier') {
|
|
50
|
+
if (lowestProperty.type === 'Identifier') {
|
|
57
51
|
const colorName = baseMapping[lowestProperty.name];
|
|
58
|
-
if (mainName === '
|
|
52
|
+
if (mainName === 'base' && colorName) {
|
|
59
53
|
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
|
|
60
|
-
|
|
61
|
-
return j.callExpression(j.identifier('cssVar'), [
|
|
62
|
-
j.memberExpression(j.identifier(map.type), j.identifier(colorName || lowestProperty.name)),
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
|
-
if (mainName === 'base') {
|
|
66
|
-
addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
|
|
67
|
-
return j.memberExpression(j.identifier(map.type), j.identifier(colorName));
|
|
54
|
+
return j.memberExpression(j.identifier('base'), j.identifier(colorName));
|
|
68
55
|
}
|
|
69
56
|
}
|
|
70
57
|
}
|
|
71
|
-
return nodePath;
|
|
58
|
+
return nodePath.value;
|
|
72
59
|
});
|
|
73
60
|
// Filter out base imports if no base tokens are used
|
|
74
61
|
root
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v14-tokens/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAiDA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,KAC3B,
|
|
1
|
+
{"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v14-tokens/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAiDA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,KAC3B,GA6MF,CAAC"}
|