@vkontakte/vkui-codemods 1.1.0-beta.2 → 1.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.
- package/dist/autoDetectVKUIVersion.js +16 -24
- package/dist/cli.js +97 -160
- package/dist/codemod-helpers.js +41 -43
- package/dist/getAvailableCodemods.js +13 -14
- package/dist/helpers/logger.js +17 -17
- package/dist/index.js +76 -147
- package/dist/report.js +4 -4
- package/dist/testHelpers/testHelper.js +17 -88
- package/dist/transforms/v6/accordion.js +10 -10
- package/dist/transforms/v6/action-sheet-item.js +5 -5
- package/dist/transforms/v6/action-sheet.js +15 -15
- package/dist/transforms/v6/alert.js +14 -14
- package/dist/transforms/v6/appearance-provider.js +8 -10
- package/dist/transforms/v6/banner.js +10 -10
- package/dist/transforms/v6/calendar-range.js +6 -6
- package/dist/transforms/v6/calendar.js +6 -6
- package/dist/transforms/v6/card-scroll.js +5 -5
- package/dist/transforms/v6/chip.js +6 -6
- package/dist/transforms/v6/chips-input.js +6 -6
- package/dist/transforms/v6/config-provider.js +20 -20
- package/dist/transforms/v6/content-card.js +7 -7
- package/dist/transforms/v6/custom-scroll-view.js +11 -13
- package/dist/transforms/v6/date-input.js +6 -6
- package/dist/transforms/v6/date-range-input.js +6 -6
- package/dist/transforms/v6/fixed-layout.js +11 -11
- package/dist/transforms/v6/forbid-imports.js +8 -8
- package/dist/transforms/v6/form-item.js +9 -9
- package/dist/transforms/v6/form-layout.js +10 -10
- package/dist/transforms/v6/gallery.js +5 -5
- package/dist/transforms/v6/gradient-prop-change.js +12 -12
- package/dist/transforms/v6/horizontal-cell-show-more.js +7 -11
- package/dist/transforms/v6/image-base.js +7 -7
- package/dist/transforms/v6/modal-card.js +16 -18
- package/dist/transforms/v6/modal-page-header.js +11 -11
- package/dist/transforms/v6/pagination.js +12 -12
- package/dist/transforms/v6/panel-header-content.js +10 -10
- package/dist/transforms/v6/panel-header.js +11 -11
- package/dist/transforms/v6/placeholder.js +5 -5
- package/dist/transforms/v6/popout-wrapper.js +9 -9
- package/dist/transforms/v6/popover.js +45 -54
- package/dist/transforms/v6/popper.js +35 -44
- package/dist/transforms/v6/range-slider.js +14 -25
- package/dist/transforms/v6/rich-tooltip.js +10 -10
- package/dist/transforms/v6/search.js +6 -6
- package/dist/transforms/v6/select.js +7 -7
- package/dist/transforms/v6/simple-cell.js +13 -15
- package/dist/transforms/v6/split-col.js +9 -9
- package/dist/transforms/v6/tabbar.js +5 -5
- package/dist/transforms/v6/tappable.js +13 -15
- package/dist/transforms/v6/text-tooltip.js +47 -58
- package/dist/transforms/v6/tooltip-container.js +14 -14
- package/dist/transforms/v6/tooltip.js +63 -72
- package/dist/transforms/v6/typography.js +19 -21
- package/dist/transforms/v6/users-stack.js +13 -13
- package/dist/transforms/v6/visually-hidden-input.js +13 -24
- package/dist/transforms/v7/action-sheet.js +5 -5
- package/dist/transforms/v7/alert.js +5 -5
- package/dist/transforms/v7/appearance-provider.js +12 -12
- package/dist/transforms/v7/appearance.js +16 -16
- package/dist/transforms/v7/banner.js +13 -14
- package/dist/transforms/v7/calendar.js +5 -5
- package/dist/transforms/v7/card-grid.js +5 -5
- package/dist/transforms/v7/card-scroll.js +17 -18
- package/dist/transforms/v7/cell-button.js +13 -13
- package/dist/transforms/v7/cell.js +5 -5
- package/dist/transforms/v7/chips-select.js +8 -8
- package/dist/transforms/v7/common/moveFromChildrenToLabel.js +19 -21
- package/dist/transforms/v7/common/remapSizePropValue.js +14 -16
- package/dist/transforms/v7/common/removeChildrenFromComponent.js +6 -6
- package/dist/transforms/v7/common/swapGapPropElements.js +7 -7
- package/dist/transforms/v7/config-provider.js +32 -36
- package/dist/transforms/v7/content-card.js +5 -5
- package/dist/transforms/v7/counter.js +12 -12
- package/dist/transforms/v7/custom-scroll-view.js +8 -8
- package/dist/transforms/v7/custom-select.js +8 -8
- package/dist/transforms/v7/date-picker.js +8 -8
- package/dist/transforms/v7/flex.js +6 -6
- package/dist/transforms/v7/form-item.js +29 -35
- package/dist/transforms/v7/form-status.js +5 -5
- package/dist/transforms/v7/header.js +21 -21
- package/dist/transforms/v7/horizontal-cell-show-more.js +16 -19
- package/dist/transforms/v7/horizontal-cell.js +5 -5
- package/dist/transforms/v7/horizontal-scroll.js +12 -12
- package/dist/transforms/v7/image-overlay.js +30 -32
- package/dist/transforms/v7/mini-info-cell.js +5 -5
- package/dist/transforms/v7/modal-card.js +7 -7
- package/dist/transforms/v7/onboarding-tooltip.js +5 -5
- package/dist/transforms/v7/panel-header-back.js +6 -6
- package/dist/transforms/v7/panel-header-close.js +6 -6
- package/dist/transforms/v7/panel-header-content.js +5 -5
- package/dist/transforms/v7/panel-header-edit.js +6 -6
- package/dist/transforms/v7/panel-header-submit.js +6 -6
- package/dist/transforms/v7/panel-spinner.js +10 -10
- package/dist/transforms/v7/placeholder.js +5 -5
- package/dist/transforms/v7/rich-cell.js +5 -5
- package/dist/transforms/v7/screen-spinner.js +7 -7
- package/dist/transforms/v7/scroll-arrow.js +20 -23
- package/dist/transforms/v7/select.js +8 -8
- package/dist/transforms/v7/separator.js +6 -6
- package/dist/transforms/v7/simple-cell.js +5 -5
- package/dist/transforms/v7/simple-grid.js +6 -6
- package/dist/transforms/v7/spacing.js +9 -9
- package/dist/transforms/v7/spinner.js +9 -9
- package/dist/transforms/v7/subnavigation-bar.js +10 -10
- package/dist/transforms/v7/subnavigation-button.js +5 -5
- package/dist/transforms/v7/tabbar-item.js +5 -5
- package/dist/transforms/v7/tooltip.js +5 -5
- package/dist/transforms/v7/typography.js +16 -17
- package/dist/transforms/v7/users-stack.js +13 -13
- package/dist/transforms/v8/action-sheet.js +6 -6
- package/dist/transforms/v8/alert.js +5 -5
- package/dist/transforms/v8/checkbox.js +12 -12
- package/dist/transforms/v8/chips-input.js +7 -7
- package/dist/transforms/v8/chips-select.js +7 -7
- package/dist/transforms/v8/common/moveAllPropsIntoSlotProp.js +6 -16
- package/dist/transforms/v8/common/moveInputPropsIntoSlotProps.js +8 -8
- package/dist/transforms/v8/common/movePropIntoSlotProps.js +44 -63
- package/dist/transforms/v8/custom-select.js +7 -7
- package/dist/transforms/v8/file.js +7 -7
- package/dist/transforms/v8/input.js +8 -7
- package/dist/transforms/v8/native-select.js +7 -7
- package/dist/transforms/v8/popout-wrapper.js +12 -12
- package/dist/transforms/v8/radio.js +12 -12
- package/dist/transforms/v8/rich-cell.js +11 -11
- package/dist/transforms/v8/search.js +8 -7
- package/dist/transforms/v8/select.js +7 -7
- package/dist/transforms/v8/snackbar.js +6 -6
- package/dist/transforms/v8/split-layout.js +7 -7
- package/dist/transforms/v8/switch.js +7 -7
- package/dist/transforms/v8/text-area.js +7 -7
- package/dist/transforms/v8/write-bar.js +7 -7
- package/package.json +6 -5
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformUseAccentWeightAttribute;
|
|
5
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
7
|
function isJSXAttribute(attribute) {
|
|
8
|
-
return
|
|
8
|
+
return attribute?.type === 'JSXAttribute';
|
|
9
9
|
}
|
|
10
10
|
function removeAttribute(attributes, attribute) {
|
|
11
|
-
attributes
|
|
11
|
+
attributes?.splice(attributes?.indexOf(attribute), 1);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const componentsToTransform = [
|
|
14
14
|
'Typography',
|
|
15
15
|
'Caption',
|
|
16
16
|
'DisplayTitle',
|
|
@@ -22,32 +22,31 @@ var componentsToTransform = [
|
|
|
22
22
|
'Title',
|
|
23
23
|
];
|
|
24
24
|
function transformUseAccentWeightAttribute(file, api, options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
componentsToTransform.forEach(
|
|
29
|
-
|
|
25
|
+
const { alias } = options;
|
|
26
|
+
const j = api.jscodeshift;
|
|
27
|
+
const source = j(file.source);
|
|
28
|
+
componentsToTransform.forEach((componentName) => {
|
|
29
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, componentName, alias);
|
|
30
30
|
if (!localName) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
source
|
|
34
34
|
.find(j.JSXOpeningElement)
|
|
35
|
-
.filter(
|
|
35
|
+
.filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName)
|
|
36
36
|
// useAccentWeight по умолчанию теперь false, поэтому, чтобы
|
|
37
37
|
// пользователи продолжили использовать accent шрифты мы включим accent режим,
|
|
38
38
|
// добавив useAccentWeight, если его нету.
|
|
39
39
|
.forEach(function handleUseAccentWeightAttribute(path) {
|
|
40
|
-
|
|
41
|
-
var attributes = path.node.attributes;
|
|
40
|
+
const attributes = path.node.attributes;
|
|
42
41
|
if (!attributes) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const accentAttribute = attributes?.find((attr) => isJSXAttribute(attr) && attr.name.name === 'useAccentWeight');
|
|
45
|
+
const weightAttribute = attributes?.find((attr) => isJSXAttribute(attr) && attr.name.name === 'weight');
|
|
47
46
|
// weight задан и не равен `undefined`
|
|
48
|
-
|
|
47
|
+
const hasDefinedWeightAttribute = Boolean(weightAttribute &&
|
|
49
48
|
weightAttribute.type === 'JSXAttribute' &&
|
|
50
|
-
!(
|
|
49
|
+
!(weightAttribute.value?.type === 'JSXExpressionContainer' &&
|
|
51
50
|
weightAttribute.value.expression.type === 'Identifier' &&
|
|
52
51
|
weightAttribute.value.expression.name === 'undefined'));
|
|
53
52
|
// есть weight и нету useAccentWeight: нужно добавить
|
|
@@ -62,7 +61,7 @@ function transformUseAccentWeightAttribute(file, api, options) {
|
|
|
62
61
|
removeAttribute(attributes, accentAttribute);
|
|
63
62
|
return;
|
|
64
63
|
}
|
|
65
|
-
if (
|
|
64
|
+
if (accentAttribute.value?.type === 'JSXExpressionContainer' &&
|
|
66
65
|
accentAttribute.value.expression.type === 'BooleanLiteral') {
|
|
67
66
|
// useAccentWeight={true} => useAccentWeight
|
|
68
67
|
if (accentAttribute.value.expression.value === true) {
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const report_1 = require("../../report");
|
|
7
7
|
exports.parser = 'tsx';
|
|
8
8
|
function transformer(file, api, options) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const { alias } = options;
|
|
10
|
+
const j = api.jscodeshift;
|
|
11
|
+
const source = j(file.source);
|
|
12
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'UsersStack', alias);
|
|
13
13
|
if (!localName) {
|
|
14
14
|
return source.toSource();
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const attributeToReplace = 'direction';
|
|
17
|
+
const newAttributeName = 'avatarsPosition';
|
|
18
|
+
const directionToAvatarsPosition = {
|
|
19
19
|
'row': 'inline-start',
|
|
20
20
|
'row-reverse': 'inline-end',
|
|
21
21
|
'column': 'block-start',
|
|
@@ -23,12 +23,12 @@ function transformer(file, api, options) {
|
|
|
23
23
|
source
|
|
24
24
|
.find(j.JSXElement, { openingElement: { name: { name: localName } } })
|
|
25
25
|
.find(j.JSXAttribute, { name: { name: attributeToReplace } })
|
|
26
|
-
.forEach(
|
|
27
|
-
|
|
26
|
+
.forEach((path) => {
|
|
27
|
+
const avatar = path.node;
|
|
28
28
|
avatar.name.name = newAttributeName;
|
|
29
|
-
|
|
29
|
+
const value = (0, codemod_helpers_1.getStringValueFromAttribute)(avatar);
|
|
30
30
|
if (!value || !directionToAvatarsPosition[value]) {
|
|
31
|
-
(0, report_1.report)(api,
|
|
31
|
+
(0, report_1.report)(api, `: ${localName} has been changed. Manual changes required: need to change direction prop to avatarsPosition.`);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
avatar.value = j.stringLiteral(directionToAvatarsPosition[value]);
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
|
-
|
|
7
|
+
const RENAME_MAP = {
|
|
8
8
|
onClose: 'onClosed',
|
|
9
9
|
};
|
|
10
10
|
function transformer(file, api, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const { alias } = options;
|
|
12
|
+
const j = api.jscodeshift;
|
|
13
|
+
const source = j(file.source);
|
|
14
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'ActionSheet', alias);
|
|
15
15
|
if (localName) {
|
|
16
16
|
(0, codemod_helpers_1.renameProp)(j, source, localName, RENAME_MAP);
|
|
17
17
|
}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
6
|
exports.parser = 'tsx';
|
|
7
7
|
function transformer(file, api, options) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const { alias } = options;
|
|
9
|
+
const j = api.jscodeshift;
|
|
10
|
+
const source = j(file.source);
|
|
11
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Alert', alias);
|
|
12
12
|
if (!localName) {
|
|
13
13
|
return source.toSource();
|
|
14
14
|
}
|
|
@@ -2,37 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Checkbox', alias);
|
|
14
14
|
if (localName) {
|
|
15
|
-
[localName,
|
|
15
|
+
[localName, `${localName}.Input`].forEach((componentName) => {
|
|
16
16
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
17
17
|
root: source,
|
|
18
|
-
componentName
|
|
18
|
+
componentName,
|
|
19
19
|
propName: 'getRef',
|
|
20
20
|
slotName: 'input',
|
|
21
21
|
slotPropName: 'getRootRef',
|
|
22
22
|
});
|
|
23
23
|
(0, movePropIntoSlotProps_1.moveDataAttrsIntoSlotProps)(j, {
|
|
24
24
|
root: source,
|
|
25
|
-
componentName
|
|
25
|
+
componentName,
|
|
26
26
|
slotName: 'input',
|
|
27
27
|
});
|
|
28
28
|
(0, movePropIntoSlotProps_1.moveAriaAttrsIntoSlotProps)(j, {
|
|
29
29
|
root: source,
|
|
30
|
-
componentName
|
|
30
|
+
componentName,
|
|
31
31
|
slotName: 'input',
|
|
32
32
|
});
|
|
33
33
|
(0, moveInputPropsIntoSlotProps_1.moveInputPropsIntoSlotProps)(j, {
|
|
34
34
|
root: source,
|
|
35
|
-
componentName
|
|
35
|
+
componentName,
|
|
36
36
|
excludedProps: ['checked', 'disabled', 'readOnly', 'required', 'name', 'value', 'form'],
|
|
37
37
|
});
|
|
38
38
|
});
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'ChipsInput', alias);
|
|
14
14
|
if (localName) {
|
|
15
15
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
16
16
|
root: source,
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'ChipsSelect', alias);
|
|
14
14
|
if (localName) {
|
|
15
15
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
16
16
|
root: source,
|
|
@@ -1,23 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.moveAllPropsIntoSlotProp = moveAllPropsIntoSlotProp;
|
|
13
|
-
|
|
14
|
-
function moveAllPropsIntoSlotProp(j,
|
|
15
|
-
var root = _a.root, componentName = _a.componentName, slotName = _a.slotName, excludedProps = _a.excludedProps;
|
|
4
|
+
const movePropIntoSlotProps_1 = require("./movePropIntoSlotProps");
|
|
5
|
+
function moveAllPropsIntoSlotProp(j, { root, componentName, slotName, excludedProps }) {
|
|
16
6
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
17
|
-
root
|
|
18
|
-
componentName
|
|
19
|
-
slotName
|
|
7
|
+
root,
|
|
8
|
+
componentName,
|
|
9
|
+
slotName,
|
|
20
10
|
propName: /.+/,
|
|
21
|
-
excludedProps:
|
|
11
|
+
excludedProps: [...(excludedProps || []), 'slotProps'],
|
|
22
12
|
});
|
|
23
13
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.moveInputPropsIntoSlotProps = moveInputPropsIntoSlotProps;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const movePropIntoSlotProps_1 = require("./movePropIntoSlotProps");
|
|
5
|
+
const INPUT_SPECIFIC_PROPS = [
|
|
6
6
|
'accept',
|
|
7
7
|
'alt',
|
|
8
8
|
'autoComplete',
|
|
@@ -24,6 +24,7 @@ var INPUT_SPECIFIC_PROPS = [
|
|
|
24
24
|
'multiple',
|
|
25
25
|
'name',
|
|
26
26
|
'pattern',
|
|
27
|
+
'enterKeyHint',
|
|
27
28
|
'placeholder',
|
|
28
29
|
'readOnly',
|
|
29
30
|
'required',
|
|
@@ -44,13 +45,12 @@ var INPUT_SPECIFIC_PROPS = [
|
|
|
44
45
|
'onKeyUp',
|
|
45
46
|
'onKeyUpCapture',
|
|
46
47
|
];
|
|
47
|
-
function moveInputPropsIntoSlotProps(j,
|
|
48
|
-
var root = _a.root, componentName = _a.componentName, excludedProps = _a.excludedProps, _b = _a.slotName, slotName = _b === void 0 ? 'input' : _b;
|
|
48
|
+
function moveInputPropsIntoSlotProps(j, { root, componentName, excludedProps, slotName = 'input' }) {
|
|
49
49
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
50
|
-
root
|
|
51
|
-
componentName
|
|
50
|
+
root,
|
|
51
|
+
componentName,
|
|
52
52
|
propName: INPUT_SPECIFIC_PROPS,
|
|
53
|
-
excludedProps
|
|
54
|
-
slotName
|
|
53
|
+
excludedProps,
|
|
54
|
+
slotName,
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.movePropIntoSlotProps = movePropIntoSlotProps;
|
|
13
4
|
exports.moveDataAttrsIntoSlotProps = moveDataAttrsIntoSlotProps;
|
|
14
5
|
exports.moveAriaAttrsIntoSlotProps = moveAriaAttrsIntoSlotProps;
|
|
15
6
|
function assignObject(j, options) {
|
|
16
|
-
|
|
7
|
+
const { target, expression, key } = options;
|
|
17
8
|
if (target && target.type === 'JSXAttribute') {
|
|
18
|
-
|
|
9
|
+
const expContainer = target.value;
|
|
19
10
|
if (expContainer.expression.type === 'ObjectExpression') {
|
|
20
11
|
// case `<prop>={{ ... }}`
|
|
21
12
|
expContainer.expression.properties.push(j.objectProperty(j.identifier(key), expression));
|
|
@@ -30,12 +21,11 @@ function assignObject(j, options) {
|
|
|
30
21
|
}
|
|
31
22
|
}
|
|
32
23
|
function appendAttribute(j, options) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(_a = target.openingElement.attributes) === null || _a === void 0 ? void 0 : _a.push(j.jsxAttribute(j.jsxIdentifier(attributeName), j.jsxExpressionContainer(expression)));
|
|
24
|
+
const { target, attributeName, expression } = options;
|
|
25
|
+
target.openingElement.attributes?.push(j.jsxAttribute(j.jsxIdentifier(attributeName), j.jsxExpressionContainer(expression)));
|
|
36
26
|
}
|
|
37
27
|
function findComponentJSX(j, root, componentName, callback) {
|
|
38
|
-
|
|
28
|
+
const [component, subcomponent] = componentName.split('.');
|
|
39
29
|
if (subcomponent) {
|
|
40
30
|
root
|
|
41
31
|
.find(j.JSXElement, {
|
|
@@ -54,17 +44,17 @@ function findComponentJSX(j, root, componentName, callback) {
|
|
|
54
44
|
}
|
|
55
45
|
}
|
|
56
46
|
function moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName) {
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
const attributes = element.openingElement.attributes;
|
|
48
|
+
const propIndex = attributes?.findIndex((attr) => attr.type === 'JSXAttribute' && attr.name.name === propName);
|
|
59
49
|
if (!attributes || propIndex === -1 || propIndex === undefined) {
|
|
60
50
|
return;
|
|
61
51
|
}
|
|
62
|
-
|
|
63
|
-
if (
|
|
52
|
+
const removedAttr = attributes?.splice(propIndex, 1)[0];
|
|
53
|
+
if (removedAttr?.type !== 'JSXAttribute') {
|
|
64
54
|
return;
|
|
65
55
|
}
|
|
66
|
-
|
|
67
|
-
if (!
|
|
56
|
+
const removedValue = (() => {
|
|
57
|
+
if (!removedAttr?.value) {
|
|
68
58
|
return j.literal(true);
|
|
69
59
|
}
|
|
70
60
|
switch (removedAttr.value.type) {
|
|
@@ -79,27 +69,21 @@ function moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName)
|
|
|
79
69
|
if (removedValue === undefined) {
|
|
80
70
|
return;
|
|
81
71
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var hasSlotProps = false;
|
|
86
|
-
attributes.forEach(function (attr) {
|
|
87
|
-
var _a, _b, _c, _d;
|
|
72
|
+
const getSlotPropNameLiteral = (name) => name.includes('-') ? j.stringLiteral(name) : j.identifier(name);
|
|
73
|
+
let hasSlotProps = false;
|
|
74
|
+
attributes.forEach((attr) => {
|
|
88
75
|
if (attr.type === 'JSXAttribute' &&
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
attr.name?.name === 'slotProps' &&
|
|
77
|
+
attr.value?.type === 'JSXExpressionContainer' &&
|
|
78
|
+
attr.value?.expression.type === 'ObjectExpression') {
|
|
92
79
|
hasSlotProps = true;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
((_a = prop === null || prop === void 0 ? void 0 : prop.key) === null || _a === void 0 ? void 0 : _a.type) === 'Identifier' &&
|
|
98
|
-
((_b = prop === null || prop === void 0 ? void 0 : prop.key) === null || _b === void 0 ? void 0 : _b.name) === slotName;
|
|
99
|
-
});
|
|
80
|
+
const slots = attr.value?.expression;
|
|
81
|
+
const slotIndex = slots.properties.findIndex((prop) => prop.type === 'ObjectProperty' &&
|
|
82
|
+
prop?.key?.type === 'Identifier' &&
|
|
83
|
+
prop?.key?.name === slotName);
|
|
100
84
|
if (slotIndex === -1) {
|
|
101
85
|
// Создаем новый слот
|
|
102
|
-
|
|
86
|
+
const slotValue = slotPropName
|
|
103
87
|
? j.objectExpression([
|
|
104
88
|
j.objectProperty(getSlotPropNameLiteral(slotPropName), removedValue),
|
|
105
89
|
])
|
|
@@ -111,9 +95,9 @@ function moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName)
|
|
|
111
95
|
});
|
|
112
96
|
}
|
|
113
97
|
else if (slots.properties[slotIndex].type === 'ObjectProperty') {
|
|
114
|
-
|
|
98
|
+
const property = slots.properties[slotIndex];
|
|
115
99
|
// Добавляем свойство в существующий слот
|
|
116
|
-
|
|
100
|
+
const existingSlot = property.value;
|
|
117
101
|
if (slotPropName) {
|
|
118
102
|
if (existingSlot.type === 'ObjectExpression') {
|
|
119
103
|
existingSlot.properties.push(j.objectProperty(getSlotPropNameLiteral(slotPropName), removedValue));
|
|
@@ -135,7 +119,7 @@ function moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName)
|
|
|
135
119
|
});
|
|
136
120
|
if (!hasSlotProps) {
|
|
137
121
|
// Создаем slotsProps
|
|
138
|
-
|
|
122
|
+
const slotValue = slotPropName
|
|
139
123
|
? j.objectExpression([j.objectProperty(getSlotPropNameLiteral(slotPropName), removedValue)])
|
|
140
124
|
: removedValue;
|
|
141
125
|
appendAttribute(j, {
|
|
@@ -146,29 +130,28 @@ function moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName)
|
|
|
146
130
|
}
|
|
147
131
|
}
|
|
148
132
|
function moveMultipleJsxPropsIntoSlotProps(j, element, propName, slotName, excludedProps) {
|
|
149
|
-
|
|
133
|
+
const attributes = element.openingElement.attributes;
|
|
150
134
|
if (!attributes) {
|
|
151
135
|
return;
|
|
152
136
|
}
|
|
153
|
-
|
|
137
|
+
const checkMatch = (attrName) => {
|
|
154
138
|
return (((propName instanceof RegExp && propName.test(attrName)) ||
|
|
155
139
|
(propName instanceof Array && propName.includes(attrName))) &&
|
|
156
|
-
!
|
|
140
|
+
!excludedProps?.includes(attrName));
|
|
157
141
|
};
|
|
158
|
-
|
|
159
|
-
.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
142
|
+
[...attributes]
|
|
143
|
+
.reverse()
|
|
144
|
+
.forEach((attr) => attr.type === 'JSXAttribute' &&
|
|
145
|
+
typeof attr.name.name === 'string' &&
|
|
146
|
+
checkMatch(attr.name.name) &&
|
|
147
|
+
moveJsxPropIntoSlotProps(j, element, attr.name.name, slotName, attr.name.name));
|
|
165
148
|
}
|
|
166
149
|
function moveJsxPropIntoSlotPropsByName(j, element, propName, slotName, slotPropName) {
|
|
167
150
|
moveJsxPropIntoSlotProps(j, element, propName, slotName, slotPropName);
|
|
168
151
|
}
|
|
169
152
|
function movePropIntoSlotProps(j, options) {
|
|
170
|
-
|
|
171
|
-
findComponentJSX(j, root, componentName,
|
|
153
|
+
const { propName, slotName, slotPropName, root, componentName, excludedProps } = options;
|
|
154
|
+
findComponentJSX(j, root, componentName, (elementPath) => {
|
|
172
155
|
if (typeof propName === 'string') {
|
|
173
156
|
moveJsxPropIntoSlotPropsByName(j, elementPath.node, propName, slotName, slotPropName);
|
|
174
157
|
}
|
|
@@ -177,21 +160,19 @@ function movePropIntoSlotProps(j, options) {
|
|
|
177
160
|
}
|
|
178
161
|
});
|
|
179
162
|
}
|
|
180
|
-
function moveDataAttrsIntoSlotProps(j,
|
|
181
|
-
var root = _a.root, componentName = _a.componentName, slotName = _a.slotName;
|
|
163
|
+
function moveDataAttrsIntoSlotProps(j, { root, componentName, slotName }) {
|
|
182
164
|
movePropIntoSlotProps(j, {
|
|
183
|
-
root
|
|
184
|
-
componentName
|
|
165
|
+
root,
|
|
166
|
+
componentName,
|
|
185
167
|
propName: /data-.+/,
|
|
186
|
-
slotName
|
|
168
|
+
slotName,
|
|
187
169
|
});
|
|
188
170
|
}
|
|
189
|
-
function moveAriaAttrsIntoSlotProps(j,
|
|
190
|
-
var root = _a.root, componentName = _a.componentName, slotName = _a.slotName;
|
|
171
|
+
function moveAriaAttrsIntoSlotProps(j, { root, componentName, slotName }) {
|
|
191
172
|
movePropIntoSlotProps(j, {
|
|
192
|
-
root
|
|
193
|
-
componentName
|
|
173
|
+
root,
|
|
174
|
+
componentName,
|
|
194
175
|
propName: /aria-.+/,
|
|
195
|
-
slotName
|
|
176
|
+
slotName,
|
|
196
177
|
});
|
|
197
178
|
}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'CustomSelect', alias);
|
|
14
14
|
if (localName) {
|
|
15
15
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
16
16
|
root: source,
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'File', alias);
|
|
14
14
|
if (localName) {
|
|
15
15
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
16
16
|
root: source,
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'Input', alias);
|
|
14
14
|
if (localName) {
|
|
15
15
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
16
16
|
root: source,
|
|
@@ -43,6 +43,7 @@ function transformer(file, api, options) {
|
|
|
43
43
|
'multiple',
|
|
44
44
|
'name',
|
|
45
45
|
'pattern',
|
|
46
|
+
'enterKeyHint',
|
|
46
47
|
'placeholder',
|
|
47
48
|
'readOnly',
|
|
48
49
|
'required',
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parser = void 0;
|
|
4
4
|
exports.default = transformer;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const codemod_helpers_1 = require("../../codemod-helpers");
|
|
6
|
+
const moveInputPropsIntoSlotProps_1 = require("./common/moveInputPropsIntoSlotProps");
|
|
7
|
+
const movePropIntoSlotProps_1 = require("./common/movePropIntoSlotProps");
|
|
8
8
|
exports.parser = 'tsx';
|
|
9
9
|
function transformer(file, api, options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const { alias } = options;
|
|
11
|
+
const j = api.jscodeshift;
|
|
12
|
+
const source = j(file.source);
|
|
13
|
+
const { localName } = (0, codemod_helpers_1.getImportInfo)(j, file, 'NativeSelect', alias);
|
|
14
14
|
if (localName) {
|
|
15
15
|
(0, movePropIntoSlotProps_1.movePropIntoSlotProps)(j, {
|
|
16
16
|
root: source,
|