@react-spectrum/codemods 0.1.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.
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.default = transformer;
30
+ /* eslint-disable max-depth */
31
+ const utils_1 = require("./utils");
32
+ const changes_1 = require("./changes");
33
+ const transforms_1 = require("./transforms");
34
+ const getComponents_1 = require("../getComponents");
35
+ const t = __importStar(require("@babel/types"));
36
+ const styleProps_1 = require("./styleProps");
37
+ const traverse_1 = __importDefault(require("@babel/traverse"));
38
+ // Determine list of available components in S2 from index.ts
39
+ let availableComponents = (0, getComponents_1.getComponents)();
40
+ // These components in v3 were replaced by divs
41
+ availableComponents.add('View');
42
+ availableComponents.add('Flex');
43
+ availableComponents.add('Grid');
44
+ // Replaced by collection component-specific items
45
+ availableComponents.add('Item');
46
+ availableComponents.add('Section');
47
+ // Don't update v3 Provider
48
+ availableComponents.delete('Provider');
49
+ function transformer(file, api, options) {
50
+ let j = api.jscodeshift;
51
+ let root = j(file.source);
52
+ let componentsToTransform = options.components ? new Set(options.components.split(',').filter(s => availableComponents.has(s))) : availableComponents;
53
+ let bindings = [];
54
+ let importedComponents = new Map();
55
+ let elements = [];
56
+ let lastImportPath = null;
57
+ const leadingComments = root.find(j.Program).get('body', 0).node.leadingComments;
58
+ (0, traverse_1.default)(root.paths()[0].node, {
59
+ ImportDeclaration(path) {
60
+ if (path.node.source.value === '@adobe/react-spectrum' || path.node.source.value.startsWith('@react-spectrum/')) {
61
+ lastImportPath = path;
62
+ for (let specifier of path.node.specifiers) {
63
+ if (specifier.type === 'ImportNamespaceSpecifier') {
64
+ // e.g. import * as RSP from '@adobe/react-spectrum';
65
+ let binding = path.scope.getBinding(specifier.local.name);
66
+ let clonedSpecifier = t.cloneNode(specifier);
67
+ if (binding) {
68
+ let isUsed = false;
69
+ for (let path of binding.referencePaths) {
70
+ if (path.parentPath?.isJSXMemberExpression() && componentsToTransform.has(path.parentPath.node.property.name) && path.parentPath.parentPath.parentPath?.isJSXElement()) {
71
+ importedComponents.set(path.parentPath.node.property.name, clonedSpecifier);
72
+ elements.push([path.parentPath.node.property.name, path.parentPath.parentPath.parentPath]);
73
+ }
74
+ else {
75
+ isUsed = true;
76
+ }
77
+ }
78
+ if (!isUsed) {
79
+ bindings.push(binding);
80
+ }
81
+ else {
82
+ let name;
83
+ let i = 0;
84
+ do {
85
+ name = `${specifier.local.name}${++i}`;
86
+ } while (path.scope.hasBinding(name));
87
+ clonedSpecifier.local = t.identifier(name);
88
+ }
89
+ }
90
+ }
91
+ else if (specifier.type === 'ImportSpecifier' &&
92
+ typeof specifier.local.name === 'string' &&
93
+ specifier.imported.type === 'Identifier' &&
94
+ typeof specifier.imported.name === 'string' &&
95
+ componentsToTransform.has(specifier.imported.name)) {
96
+ // e.g. import {Button} from '@adobe/react-spectrum';
97
+ let binding = path.scope.getBinding(specifier.local.name);
98
+ if (binding) {
99
+ importedComponents.set(specifier.imported.name, specifier);
100
+ bindings.push(binding);
101
+ for (let path of binding.referencePaths) {
102
+ if (path.parentPath?.isJSXOpeningElement() && path.parentPath.parentPath.isJSXElement()) {
103
+ elements.push([specifier.imported.name, path.parentPath.parentPath]);
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ },
111
+ Import(path) {
112
+ let call = path.parentPath;
113
+ if (!call?.isCallExpression()) {
114
+ return;
115
+ }
116
+ let arg = call.node.arguments[0];
117
+ if (arg.type !== 'StringLiteral') {
118
+ return;
119
+ }
120
+ if (arg.value !== '@adobe/react-spectrum' && !arg.value.startsWith('@react-spectrum/')) {
121
+ return;
122
+ }
123
+ // TODO: implement this. could be a bit challenging. punting for now.
124
+ (0, utils_1.addComment)(call.node, ' TODO(S2-upgrade): check this dynamic import');
125
+ }
126
+ });
127
+ let hasMacros = false;
128
+ let usedLightDark = false;
129
+ elements.forEach(([elementName, path]) => {
130
+ if (!path.node) {
131
+ return;
132
+ }
133
+ try {
134
+ let res = (0, styleProps_1.transformStyleProps)(path, elementName);
135
+ if (res) {
136
+ hasMacros || (hasMacros = res.hasMacros);
137
+ usedLightDark || (usedLightDark = res.usedLightDark);
138
+ }
139
+ }
140
+ catch (error) {
141
+ (0, utils_1.addComment)(path.node, ' TODO(S2-upgrade): Could not transform style prop automatically: ' + error);
142
+ }
143
+ const componentInfo = changes_1.changes[elementName];
144
+ if (!componentInfo) {
145
+ return;
146
+ }
147
+ const { changes } = componentInfo;
148
+ changes.forEach((change) => {
149
+ const { function: functionInfo } = change;
150
+ let { name: functionName, args: functionArgs } = functionInfo;
151
+ // Call the respective transformation function
152
+ if (transforms_1.functionMap[functionName]) {
153
+ transforms_1.functionMap[functionName](path, functionArgs);
154
+ }
155
+ });
156
+ });
157
+ if (hasMacros) {
158
+ let specifiers = [t.importSpecifier(t.identifier('style'), t.identifier('style'))];
159
+ if (usedLightDark) {
160
+ specifiers.push(t.importSpecifier(t.identifier('lightDark'), t.identifier('lightDark')));
161
+ }
162
+ let macroImport = t.importDeclaration(specifiers, t.stringLiteral('@react-spectrum/s2/style'));
163
+ macroImport.assertions = [t.importAttribute(t.identifier('type'), t.stringLiteral('macro'))];
164
+ lastImportPath.insertAfter(macroImport);
165
+ }
166
+ if (importedComponents.size) {
167
+ // Add imports to existing @react-spectrum/s2 import if it exists, otherwise add a new one.
168
+ let importSpecifiers = new Set([...importedComponents]
169
+ .filter(([c]) => c !== 'Flex' && c !== 'Grid' && c !== 'View' && c !== 'Item' && c !== 'Section')
170
+ .map(([, specifier]) => specifier));
171
+ let existingImport = root.find(j.ImportDeclaration, {
172
+ source: { value: '@react-spectrum/s2' }
173
+ });
174
+ if (existingImport.length) {
175
+ let importDecl = existingImport.get();
176
+ for (let specifier of importDecl.node.specifiers) {
177
+ if (specifier.type === 'ImportSpecifier'
178
+ && importedComponents.has(specifier.imported.name)) {
179
+ importSpecifiers.add(specifier);
180
+ }
181
+ }
182
+ // add importSpecifiers to existing import
183
+ importDecl.value.specifiers = [...importDecl.value.specifiers, ...[...importSpecifiers].filter(specifier => {
184
+ // @ts-ignore
185
+ return specifier.imported.name !== 'Item' && ![...importDecl.value.specifiers].find(s => s.imported.name === specifier.imported.name);
186
+ })];
187
+ }
188
+ else {
189
+ if (importSpecifiers.size > 0) {
190
+ let importDecl = t.importDeclaration([...importSpecifiers], t.stringLiteral('@react-spectrum/s2'));
191
+ lastImportPath.insertAfter(importDecl);
192
+ }
193
+ }
194
+ // Remove the original imports from v3.
195
+ bindings.forEach(b => {
196
+ if (t.isImportSpecifier(b.path.node) &&
197
+ t.isIdentifier(b.path.node.imported) &&
198
+ (b.path.node.imported.name === 'Item' || b.path.node.imported.name === 'Section')) {
199
+ // Keep Item and Section imports
200
+ // TODO: remove if they are unused
201
+ return;
202
+ }
203
+ b.path.remove();
204
+ // If the import statement is now empty, remove it entirely.
205
+ let decl = b.path.find(p => p.isImportDeclaration());
206
+ if (decl?.isImportDeclaration() && decl.node.specifiers.length === 0) {
207
+ decl.remove();
208
+ }
209
+ });
210
+ }
211
+ root.find(j.Program).get('body', 0).node.comments = leadingComments;
212
+ return root.toSource();
213
+ }
214
+ transformer.parser = 'tsx';
@@ -0,0 +1,309 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2024 Adobe. All rights reserved.
4
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License. You may obtain a copy
6
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
7
+ *
8
+ * Unless required by applicable law or agreed to in writing, software distributed under
9
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
+ * OF ANY KIND, either express or implied. See the License for the specific language
11
+ * governing permissions and limitations under the License.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.convertColor = convertColor;
15
+ exports.convertUnsafeStyleColor = convertUnsafeStyleColor;
16
+ // Mapping of v5 static colors to latest s2 colors. This was generated by finding the closest
17
+ // color perceptually using deltaE in the oklab color space. Since the static colors are not
18
+ // supposed to change between light and dark color schemes, we find the closest value for each
19
+ // and map them both. See scripts/mapStaticColors.mjs for more details.
20
+ const staticColors = {
21
+ 'static-blue': { default: 'blue-1100', dark: 'blue-500' },
22
+ 'static-gray-50': { default: 'gray-25', dark: 'gray-1000' },
23
+ 'static-gray-75': { default: 'gray-25', dark: 'gray-1000' },
24
+ 'static-gray-100': { default: 'gray-25', dark: 'gray-1000' },
25
+ 'static-gray-200': { default: 'gray-100', dark: 'silver-1400' },
26
+ 'static-gray-300': { default: 'gray-300', dark: 'gray-800' },
27
+ 'static-gray-400': { default: 'silver-500', dark: 'gray-700' },
28
+ 'static-gray-500': { default: 'gray-500', dark: 'silver-1000' },
29
+ 'static-gray-600': { default: 'gray-600', dark: 'gray-500' },
30
+ 'static-gray-700': { default: 'silver-1200', dark: 'gray-400' },
31
+ 'static-gray-800': { default: 'silver-1400', dark: 'gray-75' },
32
+ 'static-gray-900': { default: 'gray-1000', dark: 'gray-25' },
33
+ 'static-blue-200': { default: 'blue-500', dark: 'cyan-1200' },
34
+ 'static-blue-300': { default: 'cyan-600', dark: 'cyan-1100' },
35
+ 'static-blue-400': { default: 'cyan-700', dark: 'cyan-1000' },
36
+ 'static-blue-500': { default: 'blue-800', dark: 'blue-900' },
37
+ 'static-blue-600': { default: 'blue-900', dark: 'blue-700' },
38
+ 'static-blue-700': { default: 'blue-1100', dark: 'blue-500' },
39
+ 'static-blue-800': { default: 'blue-1200', dark: 'blue-400' },
40
+ 'static-red-400': { default: 'red-800', dark: 'red-800' },
41
+ 'static-red-500': { default: 'red-900', dark: 'red-700' },
42
+ 'static-red-600': { default: 'red-1000', dark: 'red-600' },
43
+ 'static-red-700': { default: 'red-1100', dark: 'red-500' },
44
+ 'static-orange-400': { default: 'orange-600', dark: 'orange-1100' },
45
+ 'static-orange-500': { default: 'orange-700', dark: 'orange-1000' },
46
+ 'static-orange-600': { default: 'orange-800', dark: 'orange-800' },
47
+ 'static-orange-700': { default: 'orange-900', dark: 'orange-700' },
48
+ 'static-green-400': { default: 'green-700', dark: 'green-1000' },
49
+ 'static-green-500': { default: 'green-800', dark: 'green-800' },
50
+ 'static-green-600': { default: 'green-900', dark: 'green-700' },
51
+ 'static-green-700': { default: 'green-1000', dark: 'green-600' },
52
+ 'static-celery-200': { default: 'celery-400', dark: 'celery-1300' },
53
+ 'static-celery-300': { default: 'celery-500', dark: 'celery-1200' },
54
+ 'static-celery-400': { default: 'celery-600', dark: 'celery-1100' },
55
+ 'static-celery-500': { default: 'celery-700', dark: 'celery-1000' },
56
+ 'static-celery-600': { default: 'celery-800', dark: 'celery-900' },
57
+ 'static-celery-700': { default: 'celery-900', dark: 'celery-700' },
58
+ 'static-chartreuse-300': { default: 'chartreuse-400', dark: 'chartreuse-1300' },
59
+ 'static-chartreuse-400': { default: 'chartreuse-500', dark: 'chartreuse-1200' },
60
+ 'static-chartreuse-500': { default: 'chartreuse-600', dark: 'chartreuse-1100' },
61
+ 'static-chartreuse-600': { default: 'chartreuse-700', dark: 'chartreuse-1000' },
62
+ 'static-chartreuse-700': { default: 'chartreuse-800', dark: 'chartreuse-800' },
63
+ 'static-yellow-200': { default: 'yellow-200', dark: 'yellow-1400' },
64
+ 'static-yellow-300': { default: 'yellow-300', dark: 'yellow-1400' },
65
+ 'static-yellow-400': { default: 'yellow-400', dark: 'yellow-1300' },
66
+ 'static-yellow-500': { default: 'yellow-500', dark: 'yellow-1200' },
67
+ 'static-yellow-600': { default: 'yellow-600', dark: 'yellow-1100' },
68
+ 'static-yellow-700': { default: 'yellow-700', dark: 'yellow-1000' },
69
+ 'static-magenta-200': { default: 'magenta-600', dark: 'magenta-1100' },
70
+ 'static-magenta-300': { default: 'magenta-600', dark: 'magenta-1000' },
71
+ 'static-magenta-400': { default: 'magenta-800', dark: 'magenta-800' },
72
+ 'static-magenta-500': { default: 'magenta-900', dark: 'magenta-700' },
73
+ 'static-magenta-600': { default: 'magenta-1000', dark: 'magenta-600' },
74
+ 'static-magenta-700': { default: 'magenta-1100', dark: 'magenta-500' },
75
+ 'static-fuchsia-400': { default: 'fuchsia-700', dark: 'fuchsia-1000' },
76
+ 'static-fuchsia-500': { default: 'fuchsia-800', dark: 'fuchsia-900' },
77
+ 'static-fuchsia-600': { default: 'fuchsia-900', dark: 'fuchsia-700' },
78
+ 'static-fuchsia-700': { default: 'fuchsia-1000', dark: 'fuchsia-600' },
79
+ 'static-purple-400': { default: 'purple-700', dark: 'purple-1000' },
80
+ 'static-purple-500': { default: 'purple-800', dark: 'purple-800' },
81
+ 'static-purple-600': { default: 'purple-900', dark: 'purple-700' },
82
+ 'static-purple-700': { default: 'purple-1000', dark: 'purple-600' },
83
+ 'static-purple-800': { default: 'purple-1200', dark: 'purple-500' },
84
+ 'static-indigo-200': { default: 'indigo-500', dark: 'indigo-1200' },
85
+ 'static-indigo-300': { default: 'indigo-600', dark: 'indigo-1100' },
86
+ 'static-indigo-400': { default: 'indigo-700', dark: 'indigo-1000' },
87
+ 'static-indigo-500': { default: 'indigo-800', dark: 'indigo-900' },
88
+ 'static-indigo-600': { default: 'blue-900', dark: 'blue-700' },
89
+ 'static-indigo-700': { default: 'blue-1000', dark: 'blue-600' },
90
+ 'static-seafoam-200': { default: 'turquoise-500', dark: 'turquoise-1200' },
91
+ 'static-seafoam-300': { default: 'turquoise-600', dark: 'turquoise-1100' },
92
+ 'static-seafoam-400': { default: 'turquoise-700', dark: 'turquoise-1000' },
93
+ 'static-seafoam-500': { default: 'turquoise-800', dark: 'seafoam-800' },
94
+ 'static-seafoam-600': { default: 'seafoam-900', dark: 'seafoam-700' },
95
+ 'static-seafoam-700': { default: 'seafoam-1000', dark: 'seafoam-600' }
96
+ };
97
+ // Mapping from v5 colors to v6 colors. These are in the light color scheme.
98
+ const v5ColorsToV6Colors = {
99
+ 'celery-400': 'celery-600',
100
+ 'celery-500': 'celery-700',
101
+ 'celery-600': 'celery-800',
102
+ 'celery-700': 'celery-900',
103
+ 'chartreuse-400': 'chartreuse-500',
104
+ 'chartreuse-500': 'chartreuse-600',
105
+ 'chartreuse-600': 'chartreuse-700',
106
+ 'chartreuse-700': 'chartreuse-800',
107
+ 'yellow-400': 'yellow-400',
108
+ 'yellow-500': 'yellow-500',
109
+ 'yellow-600': 'yellow-600',
110
+ 'yellow-700': 'yellow-700',
111
+ 'magenta-400': 'magenta-800',
112
+ 'magenta-500': 'magenta-900',
113
+ 'magenta-600': 'magenta-1000',
114
+ 'magenta-700': 'magenta-1100',
115
+ 'fuchsia-400': 'fuchsia-800',
116
+ 'fuchsia-500': 'fuchsia-900',
117
+ 'fuchsia-600': 'fuchsia-1000',
118
+ 'fuchsia-700': 'fuchsia-1100',
119
+ 'purple-400': 'purple-800',
120
+ 'purple-500': 'purple-900',
121
+ 'purple-600': 'purple-1000',
122
+ 'purple-700': 'purple-1100',
123
+ 'indigo-400': 'indigo-800',
124
+ 'indigo-500': 'indigo-900',
125
+ 'indigo-600': 'indigo-1000',
126
+ 'indigo-700': 'indigo-1100',
127
+ 'seafoam-400': 'seafoam-700',
128
+ 'seafoam-500': 'seafoam-800',
129
+ 'seafoam-600': 'seafoam-900',
130
+ 'seafoam-700': 'seafoam-1000',
131
+ 'red-400': 'red-800',
132
+ 'red-500': 'red-900',
133
+ 'red-600': 'red-1000',
134
+ 'red-700': 'red-1100',
135
+ 'orange-400': 'orange-600',
136
+ 'orange-500': 'orange-700',
137
+ 'orange-600': 'orange-800',
138
+ 'orange-700': 'orange-900',
139
+ 'green-400': 'green-800',
140
+ 'green-500': 'green-900',
141
+ 'green-600': 'green-1000',
142
+ 'green-700': 'green-1100',
143
+ 'blue-400': 'blue-800',
144
+ 'blue-500': 'blue-900',
145
+ 'blue-600': 'blue-1000',
146
+ 'blue-700': 'blue-1100',
147
+ 'gray-50': 'gray-50',
148
+ 'gray-75': 'gray-75',
149
+ 'gray-100': 'gray-100',
150
+ 'gray-200': 'gray-200',
151
+ 'gray-300': 'gray-300',
152
+ 'gray-400': 'gray-400',
153
+ 'gray-500': 'gray-500',
154
+ 'gray-600': 'gray-600',
155
+ 'gray-700': 'gray-700',
156
+ 'gray-800': 'gray-800',
157
+ 'gray-900': 'gray-900'
158
+ };
159
+ const darkV5ColorsToV6Colors = {
160
+ 'celery-400': 'celery-800',
161
+ 'celery-500': 'celery-900',
162
+ 'celery-600': 'celery-1000',
163
+ 'celery-700': 'celery-1100',
164
+ 'chartreuse-400': 'chartreuse-900',
165
+ 'chartreuse-500': 'chartreuse-1000',
166
+ 'chartreuse-600': 'chartreuse-1100',
167
+ 'chartreuse-700': 'chartreuse-1200',
168
+ 'yellow-400': 'yellow-1000',
169
+ 'yellow-500': 'yellow-1100',
170
+ 'yellow-600': 'yellow-1200',
171
+ 'yellow-700': 'yellow-1300',
172
+ 'magenta-400': 'magenta-600',
173
+ 'magenta-500': 'magenta-700',
174
+ 'magenta-600': 'magenta-800',
175
+ 'magenta-700': 'magenta-900',
176
+ 'fuchsia-400': 'fuchsia-600',
177
+ 'fuchsia-500': 'fuchsia-700',
178
+ 'fuchsia-600': 'fuchsia-800',
179
+ 'fuchsia-700': 'fuchsia-900',
180
+ 'purple-400': 'purple-600',
181
+ 'purple-500': 'purple-700',
182
+ 'purple-600': 'purple-800',
183
+ 'purple-700': 'purple-900',
184
+ 'indigo-400': 'indigo-600',
185
+ 'indigo-500': 'indigo-700',
186
+ 'indigo-600': 'indigo-800',
187
+ 'indigo-700': 'indigo-900',
188
+ 'red-400': 'red-600',
189
+ 'red-500': 'red-700',
190
+ 'red-600': 'red-800',
191
+ 'red-700': 'red-900',
192
+ 'orange-400': 'orange-800',
193
+ 'orange-500': 'orange-900',
194
+ 'orange-600': 'orange-1000',
195
+ 'orange-700': 'orange-1100',
196
+ 'green-400': 'green-700',
197
+ 'green-500': 'green-800',
198
+ 'green-600': 'green-900',
199
+ 'green-700': 'green-1000',
200
+ 'blue-400': 'blue-700',
201
+ 'blue-500': 'blue-800',
202
+ 'blue-600': 'blue-900',
203
+ 'blue-700': 'blue-1000'
204
+ };
205
+ // https://s2.spectrum.corp.adobe.com/page/grays/#migration-guide
206
+ const v6ColorsToS2 = {
207
+ 'gray-50': 'gray-25',
208
+ 'gray-75': 'gray-50',
209
+ 'gray-100': 'gray-75',
210
+ 'gray-200': 'gray-100',
211
+ 'gray-300': 'gray-200' // ???????
212
+ };
213
+ const backgroundColors = {
214
+ default: 'base',
215
+ disabled: 'disabled',
216
+ transparent: 'transparent',
217
+ 'label-gray': null // ???
218
+ };
219
+ const borderColors = {
220
+ default: 'gray-500', // ???
221
+ hover: 'gray-600',
222
+ down: 'gray-600',
223
+ focus: 'blue-800',
224
+ 'mouse-focus': 'blue-900',
225
+ disabled: 'disabled',
226
+ extralight: v6ColorsToS2['gray-100'],
227
+ light: v6ColorsToS2['gray-200'],
228
+ mid: v6ColorsToS2['gray-300'],
229
+ dark: 'gray-400',
230
+ transparent: 'transparent',
231
+ 'translucent-dark': 'transparent-black-75',
232
+ 'translucent-darker': 'transparent-black-100',
233
+ negative: 'negative',
234
+ notice: 'notice-600',
235
+ positive: 'positive-800',
236
+ informative: 'informative-800'
237
+ };
238
+ function convertColor(property, value, colorVersion) {
239
+ switch (property) {
240
+ case 'background':
241
+ case 'backgroundColor': {
242
+ let color = backgroundColors[value];
243
+ if (color !== undefined) {
244
+ return color;
245
+ }
246
+ break;
247
+ }
248
+ case 'borderColor':
249
+ case 'borderStartColor':
250
+ case 'borderEndColor':
251
+ case 'borderTopColor':
252
+ case 'borderBottomColor':
253
+ case 'borderXColor':
254
+ case 'borderYColor': {
255
+ let color = borderColors[value];
256
+ if (color !== undefined) {
257
+ return color;
258
+ }
259
+ break;
260
+ }
261
+ case 'color':
262
+ case 'outlineColor':
263
+ case 'fill':
264
+ case 'stroke':
265
+ break;
266
+ default:
267
+ return null;
268
+ }
269
+ if (colorVersion === 5) {
270
+ if (value in staticColors) {
271
+ return staticColors[value];
272
+ }
273
+ // Get both a light and a dark mapping. This gets the closest color in each theme
274
+ // to what was available in v5.
275
+ // TODO: should we still do this or just map to one color for S2?
276
+ let light = v5ColorsToV6Colors[value] || value;
277
+ let dark = darkV5ColorsToV6Colors[value];
278
+ if (dark) {
279
+ return {
280
+ default: v6ColorsToS2[light] || light,
281
+ dark: v6ColorsToS2[dark] || dark
282
+ };
283
+ }
284
+ return v6ColorsToS2[light] || light;
285
+ }
286
+ if (colorVersion === 6) {
287
+ return v6ColorsToS2[value] || value;
288
+ }
289
+ return null;
290
+ }
291
+ function convertUnsafeStyleColor(property, value) {
292
+ let m = value.match(/^var\(--spectrum-global-color-(.+)\)$/);
293
+ if (m) {
294
+ return convertColor(property, m[1], 5);
295
+ }
296
+ m = value.match(/^var\(--spectrum-semantic-(.+)-color-(.+)\)$/);
297
+ if (m) {
298
+ return convertColor(property, m[1], 5);
299
+ }
300
+ m = value.match(/^var\(--spectrum-alias-(.+)-color(?:-(.+))?\)$/);
301
+ if (m) {
302
+ return convertColor(property, m[2] || 'default', 5);
303
+ }
304
+ m = value.match(/^var\(--spectrum-(.+)\)$/);
305
+ if (m) {
306
+ return convertColor(property, m[1], 6);
307
+ }
308
+ return null;
309
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.transformDialog = transformDialog;
27
+ exports.transformDialogTrigger = transformDialogTrigger;
28
+ const utils_1 = require("./utils");
29
+ const t = __importStar(require("@babel/types"));
30
+ function transformDialog(path) {
31
+ path.get('children').forEach(path => {
32
+ // S2 dialogs don't have a divider anymore.
33
+ if (path.isJSXElement()) {
34
+ let name = path.get('openingElement').get('name');
35
+ if (name.referencesImport('@adobe/react-spectrum', 'Divider') || name.referencesImport('@react-spectrum/divider', 'Divider')) {
36
+ path.remove();
37
+ }
38
+ }
39
+ });
40
+ }
41
+ function transformDialogTrigger(path) {
42
+ path.get('children').forEach(path => {
43
+ // Move close function inside dialog.
44
+ // TODO: handle other types of functions too?
45
+ if (!path.isJSXExpressionContainer()) {
46
+ return;
47
+ }
48
+ let expression = path.get('expression');
49
+ if (!expression.isArrowFunctionExpression()) {
50
+ return;
51
+ }
52
+ let body = expression.get('body');
53
+ if (body.isJSXElement()) {
54
+ let name = body.get('openingElement').get('name');
55
+ if ((name.referencesImport('@adobe/react-spectrum', 'Dialog') || name.referencesImport('@react-spectrum/dialog', 'Dialog'))) {
56
+ body.node.children = [t.jsxExpressionContainer(t.arrowFunctionExpression(expression.node.params, t.jsxFragment(t.jsxOpeningFragment(), t.jsxClosingFragment(), body.node.children)))];
57
+ path.replaceWith(body.node);
58
+ return;
59
+ }
60
+ }
61
+ (0, utils_1.addComment)(body.node, ' TODO(S2-upgrade): update this dialog to move the close function inside');
62
+ });
63
+ }