@workday/canvas-kit-codemod 6.9.0-next.0 → 6.9.0-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.
Files changed (50) hide show
  1. package/dist/es6/v5/recategorizeButtons.js +1 -1
  2. package/dist/es6/v6/moveAndRenameSearchBar.d.ts.map +1 -1
  3. package/dist/es6/v6/moveAndRenameSearchBar.js +24 -5
  4. package/dist/es6/v6/utils/index.d.ts +1 -12
  5. package/dist/es6/v6/utils/index.d.ts.map +1 -1
  6. package/dist/es6/v6/utils/index.js +23 -22
  7. package/dist/es6/v7/compoundActionBar.d.ts +3 -0
  8. package/dist/es6/v7/compoundActionBar.d.ts.map +1 -0
  9. package/dist/es6/v7/compoundActionBar.js +91 -0
  10. package/dist/es6/v7/compoundBanner.d.ts +3 -0
  11. package/dist/es6/v7/compoundBanner.d.ts.map +1 -0
  12. package/dist/es6/v7/compoundBanner.js +133 -0
  13. package/dist/es6/v7/index.d.ts +4 -0
  14. package/dist/es6/v7/index.d.ts.map +1 -0
  15. package/dist/es6/v7/index.js +40 -0
  16. package/dist/es6/v7/recategorizeIconButtons.d.ts +3 -0
  17. package/dist/es6/v7/recategorizeIconButtons.d.ts.map +1 -0
  18. package/dist/es6/v7/recategorizeIconButtons.js +148 -0
  19. package/dist/es6/v7/removePropFromPopper.d.ts +3 -0
  20. package/dist/es6/v7/removePropFromPopper.d.ts.map +1 -0
  21. package/dist/es6/v7/removePropFromPopper.js +31 -0
  22. package/dist/es6/v7/renameIconPosition.d.ts +3 -0
  23. package/dist/es6/v7/renameIconPosition.d.ts.map +1 -0
  24. package/dist/es6/v7/renameIconPosition.js +37 -0
  25. package/dist/es6/v7/renameIconRef.d.ts +3 -0
  26. package/dist/es6/v7/renameIconRef.d.ts.map +1 -0
  27. package/dist/es6/v7/renameIconRef.js +70 -0
  28. package/dist/es6/v7/renameLayoutImports.d.ts +4 -0
  29. package/dist/es6/v7/renameLayoutImports.d.ts.map +1 -0
  30. package/dist/es6/v7/renameLayoutImports.js +105 -0
  31. package/dist/es6/v7/updateDisclosureShowHide.d.ts +3 -0
  32. package/dist/es6/v7/updateDisclosureShowHide.d.ts.map +1 -0
  33. package/dist/es6/v7/updateDisclosureShowHide.js +96 -0
  34. package/dist/es6/v7/updateModelSignatures.d.ts +3 -0
  35. package/dist/es6/v7/updateModelSignatures.d.ts.map +1 -0
  36. package/dist/es6/v7/updateModelSignatures.js +90 -0
  37. package/dist/es6/v7/updateSegmentedControl.d.ts +3 -0
  38. package/dist/es6/v7/updateSegmentedControl.d.ts.map +1 -0
  39. package/dist/es6/v7/updateSegmentedControl.js +24 -0
  40. package/dist/es6/v7/updateTabs.d.ts +3 -0
  41. package/dist/es6/v7/updateTabs.d.ts.map +1 -0
  42. package/dist/es6/v7/updateTabs.js +48 -0
  43. package/dist/es6/v7/utils/getImportRenameMap.d.ts +7 -0
  44. package/dist/es6/v7/utils/getImportRenameMap.d.ts.map +1 -0
  45. package/dist/es6/v7/utils/getImportRenameMap.js +52 -0
  46. package/dist/es6/v7/utils/hasImportSpecifiers.d.ts +20 -0
  47. package/dist/es6/v7/utils/hasImportSpecifiers.d.ts.map +1 -0
  48. package/dist/es6/v7/utils/hasImportSpecifiers.js +46 -0
  49. package/index.js +7 -0
  50. package/package.json +4 -3
@@ -0,0 +1,148 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ import chalk from 'chalk';
3
+ var updateJSXTag = function (nodePath, newTag) {
4
+ var componentName = nodePath.value.openingElement.name.name;
5
+ if (componentName === 'IconButton') {
6
+ nodePath.value.openingElement.name.name = newTag;
7
+ if (nodePath.value.closingElement) {
8
+ nodePath.value.closingElement.name.name = newTag;
9
+ }
10
+ }
11
+ };
12
+ export default function transformer(file, api, options) {
13
+ var j = api.jscodeshift;
14
+ var root = j(file.source);
15
+ var requiredImportSpecifiers = [];
16
+ /**
17
+ * 1. Find button imports
18
+ */
19
+ var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
20
+ if (!containsCanvasImports) {
21
+ return file.source;
22
+ }
23
+ var buttonType = 'TertiaryButton'; //default button if no variant is specified
24
+ // Button Mapping
25
+ // circle -> tertiary
26
+ // circle-filled -> secondary
27
+ // inverse -> tertiary inverse
28
+ // inverse-filled -> secondary inverse
29
+ // plain/square -> not supported
30
+ // square-filled -> not supported
31
+ /**
32
+ * 2. Find `IconButton`
33
+ * - If it has no variant, it means it's "circle" which is the default
34
+ * - Swap to `TertiaryButton`
35
+ * - Add `TertiaryButton` import if it doesn't exist.
36
+ * - If not
37
+ * - check the variant of the IconButton
38
+ * - Swap it out for the appropriate mapping
39
+ */
40
+ root
41
+ .find(j.JSXElement, function (value) {
42
+ return value.openingElement.name.type === 'JSXIdentifier' &&
43
+ (value.openingElement.name.name === importMap.IconButton ||
44
+ value.openingElement.name.name === styledMap.IconButton);
45
+ })
46
+ .forEach(function (nodePath) {
47
+ var _a;
48
+ var attrs = nodePath.value.openingElement.attributes;
49
+ var variantProp = attrs === null || attrs === void 0 ? void 0 : attrs.find(function (attr) { return attr.type === 'JSXAttribute' && attr.name.name === 'variant'; });
50
+ // Default IconButton variant is `circle`
51
+ if (variantProp) {
52
+ var valueBody = variantProp.value;
53
+ if ((valueBody === null || valueBody === void 0 ? void 0 : valueBody.type) === 'JSXExpressionContainer' &&
54
+ valueBody.expression.type === 'StringLiteral') {
55
+ variantProp.value = valueBody.expression;
56
+ }
57
+ var variantPropValue = variantProp.value.value;
58
+ if (variantPropValue) {
59
+ variantProp.value.value = variantPropValue.replace('Filled', '');
60
+ buttonType = /filled/gi.test(variantPropValue) ? 'SecondaryButton' : 'TertiaryButton';
61
+ if (!variantPropValue.includes('inverse')) {
62
+ (_a = nodePath.value.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.splice(attrs === null || attrs === void 0 ? void 0 : attrs.indexOf(variantProp), 1);
63
+ }
64
+ }
65
+ else {
66
+ console.warn(chalk.bold.red('** CANNOT UPDATE EXPRESSION FOR ICON BUTTON VARIANT. **') +
67
+ '\nYou will need to manually update this file to fix this warning.' +
68
+ '\nFile Name: ' +
69
+ chalk.blue(file.path) +
70
+ '\nConsult Upgrade Guide Section for v7: "Removal of Icon Button"');
71
+ }
72
+ }
73
+ updateJSXTag(nodePath, buttonType);
74
+ requiredImportSpecifiers.push(buttonType);
75
+ });
76
+ if (requiredImportSpecifiers.length === 0) {
77
+ return file.source;
78
+ }
79
+ // Find all instances of IconButton within a style function
80
+ // const StyledIconButton = styled(IconButton) gets renamed to
81
+ // const StyledIconButton = styled(CorrectButtonMapping)
82
+ root.find(j.VariableDeclarator).forEach(function (nodePath) {
83
+ var _a;
84
+ if (((_a = nodePath.value.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
85
+ nodePath.value.init.callee.type === 'CallExpression' &&
86
+ nodePath.value.init.callee.callee.type === 'Identifier' &&
87
+ nodePath.value.init.callee.callee.name === 'styled' &&
88
+ nodePath.value.init.callee.arguments[0].type === 'Identifier' &&
89
+ nodePath.value.init.callee.arguments[0].name === importMap.IconButton) {
90
+ nodePath.value.init.callee.arguments[0].name = buttonType;
91
+ requiredImportSpecifiers.push(buttonType);
92
+ }
93
+ });
94
+ /**
95
+ * Remove old imports: `IconButton`
96
+ * Add new required imports
97
+ */
98
+ var buttonImports = root.find(j.ImportDeclaration, {
99
+ source: {
100
+ value: function (value) {
101
+ return value === '@workday/canvas-kit-react' || value === '@workday/canvas-kit-react/button';
102
+ },
103
+ },
104
+ });
105
+ if (!buttonImports.length) {
106
+ // Add new specifiers to a new import
107
+ var allImports = root.find(j.ImportDeclaration);
108
+ var lastImport = allImports.at(allImports.length);
109
+ if (lastImport) {
110
+ lastImport.insertAfter(j.importDeclaration(requiredImportSpecifiers.map(function (specifier) { return j.importSpecifier(j.identifier(specifier)); }), j.stringLiteral('@workday/canvas-kit-react/button')));
111
+ }
112
+ }
113
+ else {
114
+ buttonImports.forEach(function (nodePath) {
115
+ var _a, _b, _c;
116
+ var node = nodePath.node;
117
+ var specifiersToRemove = ['IconButton'];
118
+ // Remove old specifiers
119
+ if (typeof node.source.value === 'string' &&
120
+ node.source.value.includes('@workday/canvas-kit-react')) {
121
+ (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.forEach(function (specifier) {
122
+ var _a, _b;
123
+ if (specifier.type === 'ImportSpecifier' &&
124
+ specifiersToRemove.includes(specifier.imported.name)) {
125
+ // delete specifier
126
+ (_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.splice((_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.indexOf(specifier), 1);
127
+ }
128
+ });
129
+ }
130
+ // Add new specifiers to existing import
131
+ requiredImportSpecifiers.forEach(function (specifier) {
132
+ var _a, _b;
133
+ if (!((_a = node.specifiers) === null || _a === void 0 ? void 0 : _a.find(function (existing) { return existing.type === 'ImportSpecifier' && existing.imported.name === specifier; }))) {
134
+ // Only add a specifier if it has not already been declared
135
+ if (!importMap[buttonType]) {
136
+ (_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.push(j.importSpecifier(j.identifier(specifier)));
137
+ }
138
+ }
139
+ });
140
+ console.log((_b = node.specifiers) === null || _b === void 0 ? void 0 : _b.length);
141
+ // if we removed all specifiers, remove the import
142
+ if (!((_c = node.specifiers) === null || _c === void 0 ? void 0 : _c.length)) {
143
+ nodePath.prune();
144
+ }
145
+ });
146
+ }
147
+ return root.toSource();
148
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=removePropFromPopper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removePropFromPopper.d.ts","sourceRoot":"","sources":["../../../lib/v7/removePropFromPopper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAa,MAAM,aAAa,CAAC;AAM/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAkC7E"}
@@ -0,0 +1,31 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ import { hasImportSpecifiers } from '../v6/utils';
3
+ var popupBarPackage = '@workday/canvas-kit-react/popup';
4
+ export default function transformer(file, api, options) {
5
+ var j = api.jscodeshift;
6
+ var root = j(file.source);
7
+ if (!hasImportSpecifiers(api, root, popupBarPackage, ['Popper'])) {
8
+ return file.source;
9
+ }
10
+ var _a = getImportRenameMap(j, root, popupBarPackage), 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.Popper ||
15
+ value.openingElement.name.name === styledMap.Popper);
16
+ })
17
+ .forEach(function (nodePath) {
18
+ var attributes = nodePath.value.openingElement.attributes;
19
+ // Remove containerElement prop from Popper component
20
+ if (attributes) {
21
+ nodePath.value.openingElement.attributes = attributes.filter(function (item) {
22
+ return item.type === 'JSXAttribute' &&
23
+ item.name.type === 'JSXIdentifier' &&
24
+ ['containerElement'].includes(item.name.name)
25
+ ? false
26
+ : true;
27
+ });
28
+ }
29
+ });
30
+ return root.toSource();
31
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=renameIconPosition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renameIconPosition.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameIconPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAA+C,MAAM,aAAa,CAAC;AAIjG,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA+C7E"}
@@ -0,0 +1,37 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ export default function transformer(file, api, options) {
3
+ var j = api.jscodeshift;
4
+ var root = j(file.source);
5
+ var _a = getImportRenameMap(j, root, '@workday/canvas-kit-react/button'), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
6
+ if (!containsCanvasImports) {
7
+ return file.source;
8
+ }
9
+ root
10
+ .find(j.JSXElement, function (value) {
11
+ return value.openingElement.name.type === 'JSXIdentifier' &&
12
+ (value.openingElement.name.name ===
13
+ (importMap.PrimaryButton || importMap.SecondaryButton) ||
14
+ value.openingElement.name.name === (styledMap.PrimaryButton || styledMap.SecondaryButton));
15
+ })
16
+ .forEach(function (nodePath) {
17
+ var _a;
18
+ var findAttribute = function (name) { return function (item) {
19
+ return item.type === 'JSXAttribute' &&
20
+ item.name.type === 'JSXIdentifier' &&
21
+ item.name.name === name;
22
+ }; };
23
+ var attributes = nodePath.value.openingElement.attributes;
24
+ if (attributes) {
25
+ var iconPosition = attributes.find(findAttribute('iconPosition'));
26
+ if (((_a = iconPosition === null || iconPosition === void 0 ? void 0 : iconPosition.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
27
+ if (iconPosition.value.value === 'left') {
28
+ iconPosition.value.value = 'start';
29
+ }
30
+ else {
31
+ iconPosition.value.value = 'end';
32
+ }
33
+ }
34
+ }
35
+ });
36
+ return root.toSource();
37
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=renameIconRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renameIconRef.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameIconRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAC;AAgBlE,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiE7E"}
@@ -0,0 +1,70 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ var inputsMap = {
3
+ '@workday/canvas-kit-react/icon': [
4
+ 'AccentIcon',
5
+ 'AppletIcon',
6
+ 'SystemIcon',
7
+ 'SystemIconCircle',
8
+ 'Graphic',
9
+ 'Svg',
10
+ ],
11
+ };
12
+ export default function transformer(file, api, options) {
13
+ var j = api.jscodeshift;
14
+ var root = j(file.source);
15
+ // defaultImports should be an array of local names that were imported using
16
+ // a default import from any of the modules listed in inputsMap. For example,
17
+ // given...
18
+ //
19
+ // ```
20
+ // import Checkbox from '@workday/canvas-kit-react/checkbox';
21
+ // import CanvasTextArea from '@workday/canvas-kit-react/text-area';
22
+ // import {TextInput} from '@workday/canvas-kit-react/text-input';
23
+ // import StatusIndicator from '@workday/canvas-kit-react/status-indicator';
24
+ // ```
25
+ //
26
+ // ... defaultImports should be set to `['Checkbox', 'CanvasTextArea']`
27
+ var defaultImports = [];
28
+ root.find(j.ImportDefaultSpecifier).forEach(function (nodePath) {
29
+ var _a;
30
+ var packageName = nodePath.parent.node.source.value;
31
+ var localName = (_a = nodePath.value.local) === null || _a === void 0 ? void 0 : _a.name;
32
+ if (packageName in inputsMap && localName) {
33
+ defaultImports.push(localName);
34
+ }
35
+ });
36
+ var runningSource = file.source;
37
+ var _loop_1 = function (inputPackageName) {
38
+ var currentRoot = j(runningSource);
39
+ var _a = getImportRenameMap(j, currentRoot, inputPackageName), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap, styledMap = _a.styledMap;
40
+ if (containsCanvasImports) {
41
+ var inputNames_1 = inputsMap[inputPackageName];
42
+ currentRoot
43
+ .find(j.JSXIdentifier, function (value) { return value.name === 'iconRef'; })
44
+ .replaceWith(function (nodePath) {
45
+ var _a, _b, _c, _d;
46
+ var 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
+ // Rewrite inputRef to ref if any of the following are true:
48
+ // (a) elementName was the name used in a default import of the current
49
+ // input being processed (e.g., `import TextInput ...`)
50
+ // (b) elementName was the name used in a named import of the current
51
+ // input being processed (e.g., `import {TextInput} ...` or
52
+ // `import {TextInput as CanvasTextInput} ...`)
53
+ // (c) elementName was created by calling `styled` on the current input
54
+ // being processed (e.g., `const StyledTextInput = styled(TextInput)`)
55
+ if (defaultImports.includes(elementName) ||
56
+ inputNames_1.map(function (n) { return importMap[n]; }).includes(elementName) ||
57
+ inputNames_1.map(function (n) { return styledMap[n]; }).includes(elementName)) {
58
+ return j.jsxIdentifier('ref');
59
+ }
60
+ return nodePath.value;
61
+ });
62
+ runningSource = currentRoot.toSource();
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
+ }
69
+ return runningSource;
70
+ }
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=renameLayoutImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renameLayoutImports.d.ts","sourceRoot":"","sources":["../../../lib/v7/renameLayoutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAA6B,MAAM,aAAa,CAAC;AAoDlE,QAAA,MAAM,SAAS,EAAE,SAyEhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,105 @@
1
+ // used to filter our imports we want to keep in @workday/canvas-kit-labs-react/common
2
+ var commonSpecifiers = [
3
+ 'useTheme',
4
+ 'ComponentStatesTable',
5
+ 'permutateProps',
6
+ 'useThemeRTL',
7
+ 'useThemedRing',
8
+ ];
9
+ var layoutSpecifiers = [
10
+ 'Flex',
11
+ 'Stack',
12
+ 'StackProps',
13
+ 'HStackProps',
14
+ 'VStack',
15
+ 'VStackProps',
16
+ 'HStack',
17
+ 'Box',
18
+ 'BoxProps',
19
+ 'FlexProps',
20
+ 'ColorStyleProps',
21
+ 'StackSpacing',
22
+ 'StackDirection',
23
+ 'StackStyleProps',
24
+ 'FlexStyleProps',
25
+ 'SpaceStyleProps',
26
+ 'DepthStyleProps',
27
+ 'BorderShorthandStyleProps',
28
+ 'BorderColorStyleProps',
29
+ 'BorderRadiusStyleProps',
30
+ 'BorderLineStyleProps',
31
+ 'BorderWidthStyleProps',
32
+ 'BorderLogicalStyleProps',
33
+ 'BorderStyleProps',
34
+ 'border',
35
+ 'ColorTokens',
36
+ 'ColorStyleProps',
37
+ 'color',
38
+ 'FlexItemStyleProps',
39
+ 'flexItem',
40
+ 'PositionStandardProps',
41
+ 'PositionLogicalProps',
42
+ 'PositionStyleProps',
43
+ 'position',
44
+ ];
45
+ // 1. Gather all import specifiers from @workday/canvas-kit-labs-react/layout
46
+ // 2. Filter through all imports from @workday/canvas-kit-labs-react/common and gather specifiers we care about
47
+ // 3. If there's an existing @workday/canvas-kit-react/layout add gathered specifiers to that import
48
+ // 4. If no existing import, create new import with specifiers and insert before closest canvas kit import
49
+ var transform = function (file, api) {
50
+ var j = api.jscodeshift;
51
+ var root = j(file.source);
52
+ var reactLayoutSpecifiers = [];
53
+ var foundImport = [];
54
+ root
55
+ .find(j.ImportDeclaration, {
56
+ source: { value: function (value) { return value.includes('@workday/canvas-kit-labs-react'); } },
57
+ })
58
+ .forEach(function (nodePath) {
59
+ var _a;
60
+ nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(function (specifier) {
61
+ var _a, _b, _c, _d;
62
+ if (specifier.type === 'ImportSpecifier' &&
63
+ !commonSpecifiers.includes(specifier.imported.name)) {
64
+ if (((_a = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _a === void 0 ? void 0 : _a.name) !== undefined &&
65
+ layoutSpecifiers.includes((_b = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _b === void 0 ? void 0 : _b.name)) {
66
+ reactLayoutSpecifiers.push({
67
+ importedName: (_c = specifier === null || specifier === void 0 ? void 0 : specifier.local) === null || _c === void 0 ? void 0 : _c.name,
68
+ name: (_d = specifier === null || specifier === void 0 ? void 0 : specifier.imported) === null || _d === void 0 ? void 0 : _d.name,
69
+ });
70
+ return false;
71
+ }
72
+ }
73
+ return true;
74
+ });
75
+ foundImport.push(nodePath);
76
+ });
77
+ var existingLayoutImports = root.find(j.ImportDeclaration, {
78
+ source: { value: '@workday/canvas-kit-react/layout' },
79
+ });
80
+ var mapToSpecifiers = function (specifier) {
81
+ return j.importSpecifier(j.identifier(specifier.name), specifier.importedName ? j.identifier(specifier.importedName) : undefined);
82
+ };
83
+ // add to existing import
84
+ if (existingLayoutImports.length) {
85
+ existingLayoutImports.forEach(function (nodePath) {
86
+ var _a;
87
+ nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.concat(reactLayoutSpecifiers.map(mapToSpecifiers));
88
+ });
89
+ }
90
+ else {
91
+ // create new import
92
+ if (foundImport.length) {
93
+ foundImport[0].insertBefore(j.importDeclaration(reactLayoutSpecifiers.map(mapToSpecifiers), j.stringLiteral('@workday/canvas-kit-react/layout')));
94
+ }
95
+ }
96
+ foundImport.forEach(function (importPath) {
97
+ var _a;
98
+ if (((_a = importPath.value.specifiers) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
99
+ importPath.value.source.value === '@workday/canvas-kit-labs-react/layout') {
100
+ importPath.prune();
101
+ }
102
+ });
103
+ return root.toSource();
104
+ };
105
+ export default transform;
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=updateDisclosureShowHide.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateDisclosureShowHide.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateDisclosureShowHide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAK9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAiH7E"}
@@ -0,0 +1,96 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ var keys = function (input) { return Object.keys(input); };
3
+ export default function transformer(file, api, options) {
4
+ var j = api.jscodeshift;
5
+ var root = j(file.source);
6
+ var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
7
+ if (!containsCanvasImports) {
8
+ return file.source;
9
+ }
10
+ var disclosureModels = [
11
+ 'useDisclosureModel',
12
+ 'usePopupModel',
13
+ 'useModalModel',
14
+ 'useDialogModel',
15
+ ];
16
+ // inverse the import map. It is more useful this way for this function
17
+ var imports = Object.keys(importMap).reduce(function (result, key) {
18
+ result[importMap[key]] = key;
19
+ return result;
20
+ }, {});
21
+ root.find(j.CallExpression).forEach(function (nodePath) {
22
+ var value = nodePath.value;
23
+ // check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
24
+ if (value.callee.type === 'Identifier' &&
25
+ disclosureModels.includes(imports[value.callee.name])) {
26
+ // loop over all the arguments of the `use{*}Model` hook
27
+ value.arguments.forEach(function (argument) {
28
+ // look for object expressions: `use{*}Model({ /* here */ })`
29
+ if (argument.type === 'ObjectExpression') {
30
+ // loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
31
+ // the value is a function matching `on{*}` or `should{*}` naming convention
32
+ argument.properties.forEach(function (property) {
33
+ // If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
34
+ // {
35
+ // onShow() {}, // ObjectMethod
36
+ // onHide: () => {}, ObjectProperty with arrow function expression
37
+ // }
38
+ if ((property.type === 'ObjectMethod' ||
39
+ (property.type === 'ObjectProperty' &&
40
+ property.value.type === 'ArrowFunctionExpression')) &&
41
+ property.key.type === 'Identifier') {
42
+ var propertyName_1 = property.key.name;
43
+ // Both types have a `params`, but are at different places in the AST
44
+ var params_1 = property.type === 'ObjectMethod'
45
+ ? property.params
46
+ : property.value.type === 'ArrowFunctionExpression'
47
+ ? property.value.params
48
+ : [];
49
+ // create a mapping for param names of callbacks and guards. This makes the logic more
50
+ // difficult to follow, but decreases duplication
51
+ var paramMapping_1 = {
52
+ on: ['event'],
53
+ should: ['event'],
54
+ };
55
+ // We will be overriding the params with this variable later
56
+ var finalParams_1 = [];
57
+ // loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
58
+ keys(paramMapping_1).forEach(function (key) {
59
+ // matches `onShow` and `shouldShow`
60
+ if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
61
+ params_1.forEach(function (param) {
62
+ if (param.type === 'ObjectPattern') {
63
+ param.properties.forEach(function (property) {
64
+ if (property.type === 'ObjectProperty' &&
65
+ property.key.type === 'Identifier') {
66
+ if (property.value.type === 'Identifier' ||
67
+ property.value.type === 'ObjectPattern') {
68
+ var index = paramMapping_1[key].indexOf(property.key.name);
69
+ // use `property.value` instead of `property.key.name` in case they
70
+ // renamed it example `shouldShow({ data: myData })`. The key name is
71
+ // `data` while the value is `myData`
72
+ finalParams_1[index] = property.value;
73
+ }
74
+ }
75
+ });
76
+ }
77
+ });
78
+ // `ObjectMethod` and `ObjectProperty` have params in a different place in the
79
+ // AST, so apply `finalParams` where appropriate
80
+ if (property.type === 'ObjectMethod') {
81
+ property.params = finalParams_1;
82
+ }
83
+ else if (property.type === 'ObjectProperty' &&
84
+ property.value.type === 'ArrowFunctionExpression') {
85
+ property.value.params = finalParams_1;
86
+ }
87
+ }
88
+ });
89
+ }
90
+ });
91
+ }
92
+ });
93
+ }
94
+ });
95
+ return root.toSource();
96
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=updateModelSignatures.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateModelSignatures.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateModelSignatures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAA6B,OAAO,EAAC,MAAM,aAAa,CAAC;AAK9E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UA0G7E"}
@@ -0,0 +1,90 @@
1
+ import { getImportRenameMap } from './utils/getImportRenameMap';
2
+ var keys = function (input) { return Object.keys(input); };
3
+ export default function transformer(file, api, options) {
4
+ var j = api.jscodeshift;
5
+ var root = j(file.source);
6
+ var _a = getImportRenameMap(j, root), containsCanvasImports = _a.containsCanvasImports, importMap = _a.importMap;
7
+ if (!containsCanvasImports) {
8
+ return file.source;
9
+ }
10
+ // inverse the import map. It is more useful this way for this function
11
+ var imports = Object.keys(importMap).reduce(function (result, key) {
12
+ result[importMap[key]] = key;
13
+ return result;
14
+ }, {});
15
+ root.find(j.CallExpression).forEach(function (nodePath) {
16
+ var value = nodePath.value;
17
+ // check if the identifier was imported from CK AND follows the `use{*}Model` naming convention
18
+ if (value.callee.type === 'Identifier' &&
19
+ /use[a-zA-Z]+Model/.test(imports[value.callee.name])) {
20
+ // loop over all the arguments of the `use{*}Model` hook
21
+ value.arguments.forEach(function (argument) {
22
+ // look for object expressions: `use{*}Model({ /* here */ })`
23
+ if (argument.type === 'ObjectExpression') {
24
+ // loop over all the properties looking for `ObjectMethod` and `ObjectProperties` where
25
+ // the value is a function matching `on{*}` or `should{*}` naming convention
26
+ argument.properties.forEach(function (property) {
27
+ // If it is an `ObjectMethod` or an `ObjectProperty` with an arrow function expression:
28
+ // {
29
+ // onShow() {}, // ObjectMethod
30
+ // onHide: () => {}, ObjectProperty with arrow function expression
31
+ // }
32
+ if ((property.type === 'ObjectMethod' ||
33
+ (property.type === 'ObjectProperty' &&
34
+ property.value.type === 'ArrowFunctionExpression')) &&
35
+ property.key.type === 'Identifier') {
36
+ var propertyName_1 = property.key.name;
37
+ // Both types have a `params`, but are at different places in the AST
38
+ var params_1 = property.type === 'ObjectMethod'
39
+ ? property.params
40
+ : property.value.type === 'ArrowFunctionExpression'
41
+ ? property.value.params
42
+ : [];
43
+ // create a mapping for param names of callbacks and guards. This makes the logic more
44
+ // difficult to follow, but decreases duplication
45
+ var paramMapping_1 = {
46
+ on: ['data', 'state'],
47
+ should: ['data', 'prevState'],
48
+ };
49
+ // We will be overriding the params with this variable later
50
+ var finalParams_1 = [];
51
+ // loop over each `paramMapping` type. `on*` and `should*` functions have different signatures
52
+ keys(paramMapping_1).forEach(function (key) {
53
+ // matches `onShow` and `shouldShow`
54
+ if (new RegExp(key + "[A-Za-z]+").test(propertyName_1)) {
55
+ params_1.forEach(function (param) {
56
+ if (param.type === 'ObjectPattern') {
57
+ param.properties.forEach(function (property) {
58
+ if (property.type === 'ObjectProperty' &&
59
+ property.key.type === 'Identifier') {
60
+ if (property.value.type === 'Identifier' ||
61
+ property.value.type === 'ObjectPattern') {
62
+ var index = paramMapping_1[key].indexOf(property.key.name);
63
+ // use `property.value` instead of `property.key.name` in case they
64
+ // renamed it example `shouldShow({ data: myData })`. The key name is
65
+ // `data` while the value is `myData`
66
+ finalParams_1[index] = property.value;
67
+ }
68
+ }
69
+ });
70
+ }
71
+ });
72
+ // `ObjectMethod` and `ObjectProperty` have params in a different place in the
73
+ // AST, so apply `finalParams` where appropriate
74
+ if (property.type === 'ObjectMethod') {
75
+ property.params = finalParams_1;
76
+ }
77
+ else if (property.type === 'ObjectProperty' &&
78
+ property.value.type === 'ArrowFunctionExpression') {
79
+ property.value.params = finalParams_1;
80
+ }
81
+ }
82
+ });
83
+ }
84
+ });
85
+ }
86
+ });
87
+ }
88
+ });
89
+ return root.toSource();
90
+ }
@@ -0,0 +1,3 @@
1
+ import { API, FileInfo, Options } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API, options: Options): string;
3
+ //# sourceMappingURL=updateSegmentedControl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateSegmentedControl.d.ts","sourceRoot":"","sources":["../../../lib/v7/updateSegmentedControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAa,MAAM,aAAa,CAAC;AAI/D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,UAgC7E"}