@vkontakte/vkui-codemods 0.0.7 → 1.0.0-beta.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/README.md +10 -5
- package/dist/autoDetectVKUIVersion.js +77 -0
- package/dist/cli.js +14 -6
- package/dist/codemod-helpers.js +8 -4
- package/dist/getAvailableCodemods.js +31 -4
- package/dist/index.js +24 -19
- package/dist/report.js +1 -2
- package/dist/testHelpers/testHelper.js +3 -3
- package/dist/transforms/{accordion.js → v6/accordion.js} +3 -3
- package/dist/transforms/{action-sheet-item.js → v6/action-sheet-item.js} +2 -2
- package/dist/transforms/{action-sheet.js → v6/action-sheet.js} +3 -3
- package/dist/transforms/{alert.js → v6/alert.js} +2 -2
- package/dist/transforms/{appearance-provider.js → v6/appearance-provider.js} +2 -2
- package/dist/transforms/{banner.js → v6/banner.js} +3 -3
- package/dist/transforms/{calendar-range.js → v6/calendar-range.js} +2 -2
- package/dist/transforms/{calendar.js → v6/calendar.js} +2 -2
- package/dist/transforms/{card-scroll.js → v6/card-scroll.js} +2 -2
- package/dist/transforms/{chip.js → v6/chip.js} +2 -2
- package/dist/transforms/{chips-input.js → v6/chips-input.js} +2 -2
- package/dist/transforms/{config-provider.js → v6/config-provider.js} +2 -2
- package/dist/transforms/{content-card.js → v6/content-card.js} +2 -2
- package/dist/transforms/{custom-scroll-view.js → v6/custom-scroll-view.js} +3 -3
- package/dist/transforms/{date-input.js → v6/date-input.js} +2 -2
- package/dist/transforms/{date-range-input.js → v6/date-range-input.js} +2 -2
- package/dist/transforms/{fixed-layout.js → v6/fixed-layout.js} +2 -2
- package/dist/transforms/{forbid-imports.js → v6/forbid-imports.js} +2 -2
- package/dist/transforms/{form-item.js → v6/form-item.js} +2 -2
- package/dist/transforms/{form-layout.js → v6/form-layout.js} +3 -3
- package/dist/transforms/{gallery.js → v6/gallery.js} +2 -2
- package/dist/transforms/{gradient-prop-change.js → v6/gradient-prop-change.js} +3 -3
- package/dist/transforms/{image-base.js → v6/image-base.js} +2 -2
- package/dist/transforms/{modal-card.js → v6/modal-card.js} +3 -3
- package/dist/transforms/{modal-page-header.js → v6/modal-page-header.js} +2 -2
- package/dist/transforms/{pagination.js → v6/pagination.js} +3 -3
- package/dist/transforms/{panel-header-content.js → v6/panel-header-content.js} +3 -3
- package/dist/transforms/{panel-header.js → v6/panel-header.js} +3 -3
- package/dist/transforms/{placeholder.js → v6/placeholder.js} +2 -2
- package/dist/transforms/{popout-wrapper.js → v6/popout-wrapper.js} +3 -3
- package/dist/transforms/{popover.js → v6/popover.js} +2 -2
- package/dist/transforms/{popper.js → v6/popper.js} +2 -2
- package/dist/transforms/{rich-tooltip.js → v6/rich-tooltip.js} +3 -3
- package/dist/transforms/{search.js → v6/search.js} +2 -2
- package/dist/transforms/{select.js → v6/select.js} +2 -2
- package/dist/transforms/{simple-cell.js → v6/simple-cell.js} +3 -3
- package/dist/transforms/{split-col.js → v6/split-col.js} +2 -2
- package/dist/transforms/{tabbar.js → v6/tabbar.js} +2 -2
- package/dist/transforms/{tappable.js → v6/tappable.js} +3 -3
- package/dist/transforms/{text-tooltip.js → v6/text-tooltip.js} +2 -2
- package/dist/transforms/{tooltip-container.js → v6/tooltip-container.js} +2 -2
- package/dist/transforms/{tooltip.js → v6/tooltip.js} +2 -2
- package/dist/transforms/{typography.js → v6/typography.js} +3 -3
- package/dist/transforms/{users-stack.js → v6/users-stack.js} +3 -3
- package/dist/transforms/v7/cell-button.js +49 -0
- package/dist/transforms/v7/common/remapSizePropValue.js +38 -0
- package/dist/transforms/v7/common/swapGapPropElements.js +25 -0
- package/dist/transforms/v7/flex.js +18 -0
- package/dist/transforms/v7/form-item.js +128 -0
- package/dist/transforms/v7/header.js +27 -0
- package/dist/transforms/v7/horizontal-cell-show-more.js +38 -0
- package/dist/transforms/v7/horizontal-scroll.js +38 -0
- package/dist/transforms/v7/image-overlay.js +125 -0
- package/dist/transforms/v7/screen-spinner.js +38 -0
- package/dist/transforms/v7/separator.js +17 -0
- package/dist/transforms/v7/simple-grid.js +18 -0
- package/dist/transforms/v7/spacing.js +26 -0
- package/dist/transforms/v7/spinner.js +29 -0
- package/dist/transforms/v7/typography.js +79 -0
- package/dist/transforms/v7/users-stack.js +50 -0
- package/package.json +6 -6
- package/dist/transforms/{horizontal-cell-show-more.js → v6/horizontal-cell-show-more.js} +1 -1
- package/dist/transforms/{range-slider.js → v6/range-slider.js} +1 -1
- package/dist/transforms/{visually-hidden-input.js → v6/visually-hidden-input.js} +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var swapGapPropElements_1 = require("./common/swapGapPropElements");
|
|
6
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Flex', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, swapGapPropElements_1.swapGapPropElements)(j, source, localName);
|
|
17
|
+
return source.toSource();
|
|
18
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
exports.parser = 'tsx';
|
|
7
|
+
function transformer(file, api, options) {
|
|
8
|
+
var alias = options.alias;
|
|
9
|
+
var j = api.jscodeshift;
|
|
10
|
+
var source = j(file.source);
|
|
11
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'FormItem', alias).localName;
|
|
12
|
+
if (!localName) {
|
|
13
|
+
return source.toSource();
|
|
14
|
+
}
|
|
15
|
+
function processTopLabel(element) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
if (element.openingElement.name.type === 'JSXMemberExpression' &&
|
|
18
|
+
((_a = element.openingElement.name.property) === null || _a === void 0 ? void 0 : _a.name) === 'TopLabel') {
|
|
19
|
+
var multilineValue_1;
|
|
20
|
+
element.openingElement.attributes = (_b = element.openingElement.attributes) === null || _b === void 0 ? void 0 : _b.filter(function (attr) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (attr.type === 'JSXAttribute' && attr.name.name === 'multiline') {
|
|
23
|
+
if (!attr.value) {
|
|
24
|
+
multilineValue_1 = true;
|
|
25
|
+
}
|
|
26
|
+
else if (((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer') {
|
|
27
|
+
multilineValue_1 = attr.value;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
return multilineValue_1;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function findTopLabelRecursive(element) {
|
|
38
|
+
var result = processTopLabel(element);
|
|
39
|
+
if (result !== undefined) {
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
if (!element.children) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
for (var _i = 0, _a = element.children; _i < _a.length; _i++) {
|
|
46
|
+
var child = _a[_i];
|
|
47
|
+
if (child.type === 'JSXElement') {
|
|
48
|
+
result = findTopLabelRecursive(child);
|
|
49
|
+
if (result !== undefined) {
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
source.find(j.JSXElement, { openingElement: { name: { name: localName } } }).forEach(function (path) {
|
|
57
|
+
var formItem = path.node;
|
|
58
|
+
var topMultiline;
|
|
59
|
+
var topLabelMultiline;
|
|
60
|
+
var formItemAttributes = formItem.openingElement.attributes;
|
|
61
|
+
var prettifyTopMultilineAttribute = function () {
|
|
62
|
+
var _a;
|
|
63
|
+
// Избавляемся от лишнего:
|
|
64
|
+
// если topMultiline={false} можно убрать аттрибут
|
|
65
|
+
// если topMultiline={true} можно убрать {true}
|
|
66
|
+
if (topMultiline && (formItemAttributes === null || formItemAttributes === void 0 ? void 0 : formItemAttributes.includes(topMultiline))) {
|
|
67
|
+
if (((_a = topMultiline === null || topMultiline === void 0 ? void 0 : topMultiline.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer' &&
|
|
68
|
+
topMultiline.value.expression.type === 'BooleanLiteral') {
|
|
69
|
+
if (topMultiline.value.expression.value) {
|
|
70
|
+
topMultiline.value = null;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
formItemAttributes.splice(formItemAttributes.indexOf(topMultiline), 1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
// Проверяем существующий topMultiline проп
|
|
79
|
+
formItemAttributes === null || formItemAttributes === void 0 ? void 0 : formItemAttributes.forEach(function (attr) {
|
|
80
|
+
if (attr.type === 'JSXAttribute' && attr.name.name === 'topMultiline') {
|
|
81
|
+
topMultiline = attr;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// Ищем FormItem.TopLabel в пропе top и topNode
|
|
85
|
+
formItemAttributes === null || formItemAttributes === void 0 ? void 0 : formItemAttributes.forEach(function (attr) {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if (attr.type === 'JSXAttribute' &&
|
|
88
|
+
(attr.name.name === 'top' || attr.name.name === 'topNode')) {
|
|
89
|
+
if (((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXElement') {
|
|
90
|
+
topLabelMultiline = findTopLabelRecursive(attr.value);
|
|
91
|
+
}
|
|
92
|
+
else if (((_b = attr.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer' &&
|
|
93
|
+
attr.value.expression.type === 'JSXElement') {
|
|
94
|
+
topLabelMultiline = findTopLabelRecursive(attr.value.expression);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
// Ищем FormItem.TopLabel в children
|
|
99
|
+
if (topLabelMultiline === undefined && formItem.children) {
|
|
100
|
+
for (var _i = 0, _a = formItem.children; _i < _a.length; _i++) {
|
|
101
|
+
var child = _a[_i];
|
|
102
|
+
if (child.type === 'JSXElement') {
|
|
103
|
+
topLabelMultiline = findTopLabelRecursive(child);
|
|
104
|
+
if (topLabelMultiline !== undefined) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!topLabelMultiline) {
|
|
111
|
+
prettifyTopMultilineAttribute();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var newTopMultilineValue = topLabelMultiline === true ? null : topLabelMultiline;
|
|
115
|
+
// Обновляем или добавляем topMultiline проп
|
|
116
|
+
if (topMultiline) {
|
|
117
|
+
// Если у FormItem задан topMultiline -> переопределяем
|
|
118
|
+
topMultiline.value = newTopMultilineValue;
|
|
119
|
+
}
|
|
120
|
+
else if (topLabelMultiline) {
|
|
121
|
+
// Если у FormItem не задан topMultiline
|
|
122
|
+
// добавляем его в аргументы
|
|
123
|
+
formItemAttributes === null || formItemAttributes === void 0 ? void 0 : formItemAttributes.push(j.jsxAttribute(j.jsxIdentifier('topMultiline'), newTopMultilineValue));
|
|
124
|
+
}
|
|
125
|
+
prettifyTopMultilineAttribute();
|
|
126
|
+
});
|
|
127
|
+
return source.toSource();
|
|
128
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var remapSizePropValue_1 = require("./common/remapSizePropValue");
|
|
6
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Header', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, remapSizePropValue_1.remapSizePropValue)({
|
|
17
|
+
j: j,
|
|
18
|
+
api: api,
|
|
19
|
+
source: source,
|
|
20
|
+
componentName: localName,
|
|
21
|
+
sizesMap: {
|
|
22
|
+
large: 'l',
|
|
23
|
+
regular: 'm',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
return source.toSource();
|
|
27
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
var report_1 = require("../../report");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
var componentName = 'HorizontalCellShowMore';
|
|
9
|
+
function transformer(file, api, options) {
|
|
10
|
+
var alias = options.alias;
|
|
11
|
+
var j = api.jscodeshift;
|
|
12
|
+
var source = j(file.source);
|
|
13
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
|
|
14
|
+
if (!localName) {
|
|
15
|
+
return source.toSource();
|
|
16
|
+
}
|
|
17
|
+
source
|
|
18
|
+
.find(j.JSXOpeningElement)
|
|
19
|
+
.filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
|
|
20
|
+
.find(j.JSXAttribute)
|
|
21
|
+
.filter(function (attribute) { return attribute.node.name.name === 'compensateLastCellIndent'; })
|
|
22
|
+
.forEach(function (attribute) {
|
|
23
|
+
var node = attribute.node;
|
|
24
|
+
if (!node.value) {
|
|
25
|
+
j(attribute).remove();
|
|
26
|
+
}
|
|
27
|
+
else if (node.value.type === 'JSXExpressionContainer' &&
|
|
28
|
+
node.value.expression.type === 'BooleanLiteral') {
|
|
29
|
+
if (node.value.expression.value) {
|
|
30
|
+
j(attribute).remove();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
(0, report_1.report)(api, "Manual changes required for ".concat(componentName, "'s \"compensateLastCellIndent\" prop. You might not need it anymore."));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return source.toSource();
|
|
38
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
var report_1 = require("../../report");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
var componentName = 'HorizontalScroll';
|
|
9
|
+
function transformer(file, api, options) {
|
|
10
|
+
var alias = options.alias;
|
|
11
|
+
var j = api.jscodeshift;
|
|
12
|
+
var source = j(file.source);
|
|
13
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
|
|
14
|
+
if (!localName) {
|
|
15
|
+
return source.toSource();
|
|
16
|
+
}
|
|
17
|
+
source
|
|
18
|
+
.find(j.JSXOpeningElement)
|
|
19
|
+
.filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
|
|
20
|
+
.find(j.JSXAttribute)
|
|
21
|
+
.filter(function (attribute) { return attribute.node.name.name === 'inline'; })
|
|
22
|
+
.forEach(function (attribute) {
|
|
23
|
+
var node = attribute.node;
|
|
24
|
+
if (!node.value) {
|
|
25
|
+
j(attribute).remove();
|
|
26
|
+
}
|
|
27
|
+
else if (node.value.type === 'JSXExpressionContainer' &&
|
|
28
|
+
node.value.expression.type === 'BooleanLiteral') {
|
|
29
|
+
if (node.value.expression.value) {
|
|
30
|
+
j(attribute).remove();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
(0, report_1.report)(api, "Manual changes required for ".concat(componentName, "'s \"inline\" prop."));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return source.toSource();
|
|
38
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parser = void 0;
|
|
7
|
+
exports.default = transformer;
|
|
8
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
10
|
+
var report_1 = require("../../report");
|
|
11
|
+
exports.parser = 'tsx';
|
|
12
|
+
function transformer(file, api, options) {
|
|
13
|
+
var alias = options.alias;
|
|
14
|
+
var j = api.jscodeshift;
|
|
15
|
+
var source = j(file.source);
|
|
16
|
+
var ImageLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Image', alias).localName;
|
|
17
|
+
var ImageBaseLocalName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ImageBase', alias).localName;
|
|
18
|
+
if (!ImageLocalName && !ImageBaseLocalName) {
|
|
19
|
+
return source.toSource();
|
|
20
|
+
}
|
|
21
|
+
var findAttribute = function (attributes, attributeName) {
|
|
22
|
+
return ((attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) {
|
|
23
|
+
return attr.type === 'JSXAttribute' && attr.name.name === attributeName;
|
|
24
|
+
})) || null);
|
|
25
|
+
};
|
|
26
|
+
var showReport = function (localName, additionalMessage) {
|
|
27
|
+
(0, report_1.report)(api, ": ".concat(chalk_1.default.white.bgBlue("".concat(localName, ".Overlay")), " has been changed. Manual changes required: ").concat(additionalMessage));
|
|
28
|
+
};
|
|
29
|
+
var showDisableInteractivePropReport = function (localName) {
|
|
30
|
+
showReport(localName, "\"disableInteractive\" has been removed, please use \"onClick\" if you want to make ".concat(localName, ".Overlay interactive"));
|
|
31
|
+
};
|
|
32
|
+
var calcDisableInteractiveValue = function (disableInteractiveAttribute) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
if (((_a = disableInteractiveAttribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'BooleanLiteral') {
|
|
35
|
+
return disableInteractiveAttribute.value.value;
|
|
36
|
+
}
|
|
37
|
+
else if (disableInteractiveAttribute.value === null) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
else if (((_b = disableInteractiveAttribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
41
|
+
var expression = disableInteractiveAttribute.value.expression;
|
|
42
|
+
if (expression.type === 'BooleanLiteral') {
|
|
43
|
+
return expression.value;
|
|
44
|
+
}
|
|
45
|
+
if (expression.type === 'Identifier' && expression.name === 'undefined') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
var handleImageComponent = function (localName) {
|
|
52
|
+
source
|
|
53
|
+
.find(j.JSXElement, {
|
|
54
|
+
openingElement: {
|
|
55
|
+
name: {
|
|
56
|
+
type: 'JSXMemberExpression',
|
|
57
|
+
object: { name: localName },
|
|
58
|
+
property: { name: 'Overlay' },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
.forEach(function (path) {
|
|
63
|
+
var _a;
|
|
64
|
+
var overlay = path.node;
|
|
65
|
+
var overlayItemAttributes = overlay.openingElement.attributes;
|
|
66
|
+
var onClickAttribute = findAttribute(overlayItemAttributes, 'onClick');
|
|
67
|
+
var disableInteractiveAttribute = findAttribute(overlayItemAttributes, 'disableInteractive');
|
|
68
|
+
// Кейс, когда disableInteractive не был задан, значит overlay interactive.
|
|
69
|
+
// Сейчас у него обязательно должен быть onClick, чтобы не ломать обратную совместимость
|
|
70
|
+
if (!disableInteractiveAttribute) {
|
|
71
|
+
// Проверяем наличие onClick, и если его нет, то пользователь должен добавить onClick
|
|
72
|
+
if (!onClickAttribute) {
|
|
73
|
+
showReport(localName, "If you want to make ".concat(localName, ".Overlay interactive please add \"onClick\" prop"));
|
|
74
|
+
}
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Рассчитываем значение disableInteractive в boolean
|
|
78
|
+
var disableInteractiveValue = calcDisableInteractiveValue(disableInteractiveAttribute);
|
|
79
|
+
if (disableInteractiveValue === null) {
|
|
80
|
+
// Если у disableInteractive используется сложное выражение
|
|
81
|
+
// То пользователь сам должен удалить этот проп, как ему нужно
|
|
82
|
+
showDisableInteractivePropReport(localName);
|
|
83
|
+
}
|
|
84
|
+
// Удаляем аттрибут disableInteractive
|
|
85
|
+
(0, codemod_helpers_1.removeAttribute)(overlayItemAttributes, disableInteractiveAttribute);
|
|
86
|
+
if (disableInteractiveValue) {
|
|
87
|
+
// Если disableInteractive = true, то все, что нам нужно это удалить атрибут onClick
|
|
88
|
+
// Важно: мы можем его спокойно удалить, так как в этом кейсе он может быть только undefined
|
|
89
|
+
if (onClickAttribute) {
|
|
90
|
+
(0, codemod_helpers_1.removeAttribute)(overlayItemAttributes, onClickAttribute);
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!onClickAttribute) {
|
|
95
|
+
// Если disableInteractive = false и onClick пропа нет, то пользователь должен его добавить
|
|
96
|
+
showDisableInteractivePropReport(localName);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
// Если disableInteractive = false и onClick не пустой надо обработать следующие кейс:
|
|
100
|
+
// onClick=undefined: надо добавить колбэк
|
|
101
|
+
// onClick=identifier: все хорошо,оставляем как есть
|
|
102
|
+
// В остальных случаях, надо чтобы пользователь убедился, что onClick устанавливается корректно
|
|
103
|
+
if (((_a = onClickAttribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer') {
|
|
104
|
+
var expression = onClickAttribute.value.expression;
|
|
105
|
+
if (expression.type === 'Identifier') {
|
|
106
|
+
if (expression.name === 'undefined') {
|
|
107
|
+
showDisableInteractivePropReport(localName);
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (expression.type === 'ArrowFunctionExpression') {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
showReport(localName, "\"disableInteractive\" has been removed, please validate that \"onClick\" prop value not falsy");
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
if (ImageLocalName) {
|
|
119
|
+
handleImageComponent(ImageLocalName);
|
|
120
|
+
}
|
|
121
|
+
if (ImageBaseLocalName) {
|
|
122
|
+
handleImageComponent(ImageBaseLocalName);
|
|
123
|
+
}
|
|
124
|
+
return source.toSource();
|
|
125
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
exports.parser = 'tsx';
|
|
7
|
+
function transformer(file, api, options) {
|
|
8
|
+
var alias = options.alias;
|
|
9
|
+
var j = api.jscodeshift;
|
|
10
|
+
var source = j(file.source);
|
|
11
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ScreenSpinner', alias).localName;
|
|
12
|
+
if (!localName) {
|
|
13
|
+
return source.toSource();
|
|
14
|
+
}
|
|
15
|
+
function removeSizeProp(attribute) {
|
|
16
|
+
attribute.node.name.name === 'size' && j(attribute).remove();
|
|
17
|
+
}
|
|
18
|
+
// Обработка ScreenSpinner
|
|
19
|
+
source
|
|
20
|
+
.find(j.JSXOpeningElement)
|
|
21
|
+
.filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
|
|
22
|
+
.find(j.JSXAttribute)
|
|
23
|
+
.forEach(removeSizeProp);
|
|
24
|
+
// Обработка ScreenSpinner.Loader
|
|
25
|
+
source
|
|
26
|
+
.find(j.JSXElement, {
|
|
27
|
+
openingElement: {
|
|
28
|
+
name: {
|
|
29
|
+
type: 'JSXMemberExpression',
|
|
30
|
+
object: { name: localName },
|
|
31
|
+
property: { name: 'Loader' },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
.find(j.JSXAttribute)
|
|
36
|
+
.forEach(removeSizeProp);
|
|
37
|
+
return source.toSource();
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
exports.parser = 'tsx';
|
|
7
|
+
var componentName = 'Separator';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
|
|
13
|
+
if (localName) {
|
|
14
|
+
(0, codemod_helpers_1.renameProp)(j, source, localName, { mode: 'appearance' });
|
|
15
|
+
}
|
|
16
|
+
return source.toSource();
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var swapGapPropElements_1 = require("./common/swapGapPropElements");
|
|
6
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'SimpleGrid', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, swapGapPropElements_1.swapGapPropElements)(j, source, localName);
|
|
17
|
+
return source.toSource();
|
|
18
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var remapSizePropValue_1 = require("./common/remapSizePropValue");
|
|
6
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Spacing', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, remapSizePropValue_1.remapSizePropValue)({
|
|
17
|
+
j: j,
|
|
18
|
+
api: api,
|
|
19
|
+
source: source,
|
|
20
|
+
componentName: localName,
|
|
21
|
+
sizesMap: {
|
|
22
|
+
'3xs': '2xs',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return source.toSource();
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var remapSizePropValue_1 = require("./common/remapSizePropValue");
|
|
6
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Spinner', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
(0, remapSizePropValue_1.remapSizePropValue)({
|
|
17
|
+
j: j,
|
|
18
|
+
api: api,
|
|
19
|
+
source: source,
|
|
20
|
+
componentName: localName,
|
|
21
|
+
sizesMap: {
|
|
22
|
+
large: 'xl',
|
|
23
|
+
medium: 'l',
|
|
24
|
+
regular: 'm',
|
|
25
|
+
small: 's',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return source.toSource();
|
|
29
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformUseAccentWeightAttribute;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
exports.parser = 'tsx';
|
|
7
|
+
function isJSXAttribute(attribute) {
|
|
8
|
+
return (attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'JSXAttribute';
|
|
9
|
+
}
|
|
10
|
+
function removeAttribute(attributes, attribute) {
|
|
11
|
+
attributes === null || attributes === void 0 ? void 0 : attributes.splice(attributes === null || attributes === void 0 ? void 0 : attributes.indexOf(attribute), 1);
|
|
12
|
+
}
|
|
13
|
+
var componentsToTransform = [
|
|
14
|
+
'Typography',
|
|
15
|
+
'Caption',
|
|
16
|
+
'DisplayTitle',
|
|
17
|
+
'Footnote',
|
|
18
|
+
'Headline',
|
|
19
|
+
'Paragraph',
|
|
20
|
+
'Subhead',
|
|
21
|
+
'Text',
|
|
22
|
+
'Title',
|
|
23
|
+
];
|
|
24
|
+
function transformUseAccentWeightAttribute(file, api, options) {
|
|
25
|
+
var alias = options.alias;
|
|
26
|
+
var j = api.jscodeshift;
|
|
27
|
+
var source = j(file.source);
|
|
28
|
+
componentsToTransform.forEach(function (componentName) {
|
|
29
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias).localName;
|
|
30
|
+
if (!localName) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
source
|
|
34
|
+
.find(j.JSXOpeningElement)
|
|
35
|
+
.filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
|
|
36
|
+
// useAccentWeight по умолчанию теперь false, поэтому, чтобы
|
|
37
|
+
// пользователи продолжили использовать accent шрифты мы включим accent режим,
|
|
38
|
+
// добавив useAccentWeight, если его нету.
|
|
39
|
+
.forEach(function handleUseAccentWeightAttribute(path) {
|
|
40
|
+
var _a, _b;
|
|
41
|
+
var attributes = path.node.attributes;
|
|
42
|
+
if (!attributes) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var accentAttribute = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return isJSXAttribute(attr) && attr.name.name === 'useAccentWeight'; });
|
|
46
|
+
var weightAttribute = attributes === null || attributes === void 0 ? void 0 : attributes.find(function (attr) { return isJSXAttribute(attr) && attr.name.name === 'weight'; });
|
|
47
|
+
// weight задан и не равен `undefined`
|
|
48
|
+
var hasDefinedWeightAttribute = Boolean(weightAttribute &&
|
|
49
|
+
weightAttribute.type === 'JSXAttribute' &&
|
|
50
|
+
!(((_a = weightAttribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'JSXExpressionContainer' &&
|
|
51
|
+
weightAttribute.value.expression.type === 'Identifier' &&
|
|
52
|
+
weightAttribute.value.expression.name === 'undefined'));
|
|
53
|
+
// есть weight и нету useAccentWeight: нужно добавить
|
|
54
|
+
if (!accentAttribute && hasDefinedWeightAttribute) {
|
|
55
|
+
attributes.push(j.jsxAttribute(j.jsxIdentifier('useAccentWeight')));
|
|
56
|
+
}
|
|
57
|
+
if (!isJSXAttribute(accentAttribute)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// weight нету, убираем useAccentWeight
|
|
61
|
+
if (!hasDefinedWeightAttribute) {
|
|
62
|
+
removeAttribute(attributes, accentAttribute);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (((_b = accentAttribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer' &&
|
|
66
|
+
accentAttribute.value.expression.type === 'BooleanLiteral') {
|
|
67
|
+
// useAccentWeight={true} => useAccentWeight
|
|
68
|
+
if (accentAttribute.value.expression.value === true) {
|
|
69
|
+
accentAttribute.value = null;
|
|
70
|
+
// useAccentWeight={false} => совсем убираем
|
|
71
|
+
}
|
|
72
|
+
else if (accentAttribute.value.expression.value === false) {
|
|
73
|
+
removeAttribute(attributes, accentAttribute);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return source.toSource();
|
|
79
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parser = void 0;
|
|
4
|
+
exports.default = transformer;
|
|
5
|
+
var codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
var report_1 = require("../../report");
|
|
7
|
+
exports.parser = 'tsx';
|
|
8
|
+
function transformer(file, api, options) {
|
|
9
|
+
var alias = options.alias;
|
|
10
|
+
var j = api.jscodeshift;
|
|
11
|
+
var source = j(file.source);
|
|
12
|
+
var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'UsersStack', alias).localName;
|
|
13
|
+
if (!localName) {
|
|
14
|
+
return source.toSource();
|
|
15
|
+
}
|
|
16
|
+
var attributeToReplace = 'direction';
|
|
17
|
+
var newAttributeName = 'avatarsPosition';
|
|
18
|
+
var directionToAvatarsPosition = {
|
|
19
|
+
'row': 'inline-start',
|
|
20
|
+
'row-reverse': 'inline-end',
|
|
21
|
+
'column': 'block-start',
|
|
22
|
+
};
|
|
23
|
+
var getValueFromAttribute = function (attribute) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
26
|
+
return attribute.value.value;
|
|
27
|
+
}
|
|
28
|
+
if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
29
|
+
var expression = attribute.value.expression;
|
|
30
|
+
if (expression.type === 'StringLiteral') {
|
|
31
|
+
return expression.value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
source
|
|
37
|
+
.find(j.JSXElement, { openingElement: { name: { name: localName } } })
|
|
38
|
+
.find(j.JSXAttribute, { name: { name: attributeToReplace } })
|
|
39
|
+
.forEach(function (path) {
|
|
40
|
+
var avatar = path.node;
|
|
41
|
+
avatar.name.name = newAttributeName;
|
|
42
|
+
var value = getValueFromAttribute(avatar);
|
|
43
|
+
if (!value || !directionToAvatarsPosition[value]) {
|
|
44
|
+
(0, report_1.report)(api, ": ".concat(localName, " has been changed. Manual changes required: need to change direction prop to avatarsPosition"));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
avatar.value = j.stringLiteral(directionToAvatarsPosition[value]);
|
|
48
|
+
});
|
|
49
|
+
return source.toSource();
|
|
50
|
+
}
|