@taiga-ui/cdk 2.48.0 → 2.49.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/taiga-ui-cdk-classes.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-classes.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-components-alert-host.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-components-alert-host.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-constants.umd.js +29 -2
- package/bundles/taiga-ui-cdk-constants.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-constants.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-constants.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-for-async.umd.js +5 -4
- package/bundles/taiga-ui-cdk-directives-for-async.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-for-async.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-directives-for-async.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-let.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-let.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-observables.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-observables.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-tokens.umd.js +18 -0
- package/bundles/taiga-ui-cdk-tokens.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-tokens.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-tokens.umd.min.js.map +1 -1
- package/classes/validation-error.d.ts +1 -1
- package/components/alert-host/alert-host.component.d.ts +1 -1
- package/constants/stringify.d.ts +1 -1
- package/constants/taiga-ui-cdk-constants.metadata.json +1 -1
- package/constants/unicode-chars.d.ts +25 -1
- package/directives/let/let.directive.d.ts +1 -1
- package/esm2015/classes/validation-error.js +1 -1
- package/esm2015/components/alert-host/alert-host.component.js +1 -1
- package/esm2015/constants/stringify.js +1 -1
- package/esm2015/constants/unicode-chars.js +27 -3
- package/esm2015/directives/for-async/for-async.directive.js +5 -5
- package/esm2015/directives/let/let.directive.js +1 -1
- package/esm2015/observables/is-alive.js +1 -1
- package/esm2015/tokens/index.js +4 -1
- package/esm2015/tokens/is-chromium.js +6 -0
- package/esm2015/tokens/is-firefox.js +9 -0
- package/esm2015/tokens/is-webkit.js +6 -0
- package/esm5/classes/validation-error.js +1 -1
- package/esm5/components/alert-host/alert-host.component.js +1 -1
- package/esm5/constants/stringify.js +1 -1
- package/esm5/constants/unicode-chars.js +27 -3
- package/esm5/directives/for-async/for-async.directive.js +7 -6
- package/esm5/directives/let/let.directive.js +1 -1
- package/esm5/observables/is-alive.js +1 -1
- package/esm5/tokens/index.js +4 -1
- package/esm5/tokens/is-chromium.js +6 -0
- package/esm5/tokens/is-firefox.js +9 -0
- package/esm5/tokens/is-webkit.js +6 -0
- package/fesm2015/taiga-ui-cdk-classes.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-components-alert-host.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-constants.js +27 -3
- package/fesm2015/taiga-ui-cdk-constants.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-directives-for-async.js +4 -4
- package/fesm2015/taiga-ui-cdk-directives-for-async.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-directives-let.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-observables.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-tokens.js +16 -1
- package/fesm2015/taiga-ui-cdk-tokens.js.map +1 -1
- package/fesm5/taiga-ui-cdk-classes.js.map +1 -1
- package/fesm5/taiga-ui-cdk-components-alert-host.js.map +1 -1
- package/fesm5/taiga-ui-cdk-constants.js +27 -3
- package/fesm5/taiga-ui-cdk-constants.js.map +1 -1
- package/fesm5/taiga-ui-cdk-directives-for-async.js +6 -5
- package/fesm5/taiga-ui-cdk-directives-for-async.js.map +1 -1
- package/fesm5/taiga-ui-cdk-directives-let.js.map +1 -1
- package/fesm5/taiga-ui-cdk-observables.js.map +1 -1
- package/fesm5/taiga-ui-cdk-tokens.js +16 -1
- package/fesm5/taiga-ui-cdk-tokens.js.map +1 -1
- package/observables/is-alive.d.ts +1 -1
- package/package.json +3 -1
- package/schematics/ng-update/constants/consts.js +21 -0
- package/schematics/ng-update/constants/modules.d.ts +6 -0
- package/schematics/ng-update/constants/modules.js +5 -0
- package/schematics/ng-update/constants/services.js +1 -1
- package/schematics/ng-update/constants/templates.d.ts +27 -0
- package/schematics/ng-update/constants/templates.js +92 -0
- package/schematics/ng-update/constants/tui-interactive-selectors.d.ts +1 -0
- package/schematics/ng-update/constants/tui-interactive-selectors.js +54 -0
- package/schematics/ng-update/constants/types.js +5 -0
- package/schematics/ng-update/constants/warnings.js +50 -0
- package/schematics/ng-update/index.js +6 -0
- package/schematics/ng-update/interfaces/template-resourse.d.ts +8 -0
- package/schematics/ng-update/interfaces/template-resourse.js +2 -0
- package/schematics/ng-update/steps/migrate-sliders/index.d.ts +2 -0
- package/schematics/ng-update/steps/migrate-sliders/index.js +7 -0
- package/schematics/ng-update/steps/migrate-sliders/migrate-input-slider.d.ts +2 -0
- package/schematics/ng-update/steps/migrate-sliders/migrate-input-slider.js +69 -0
- package/schematics/ng-update/steps/migrate-templates.d.ts +2 -0
- package/schematics/ng-update/steps/migrate-templates.js +74 -0
- package/schematics/ng-update/steps/remove-module.d.ts +2 -0
- package/schematics/ng-update/steps/remove-module.js +24 -0
- package/schematics/ng-update/steps/replace-const.js +2 -2
- package/schematics/utils/add-unique-import.js +1 -1
- package/schematics/utils/angular/ng-component.d.ts +3 -0
- package/schematics/utils/angular/ng-component.js +7 -0
- package/schematics/utils/angular/ng-module.d.ts +7 -0
- package/schematics/utils/angular/ng-module.js +21 -0
- package/schematics/utils/templates/elements.d.ts +21 -0
- package/schematics/utils/templates/elements.js +79 -0
- package/schematics/utils/templates/get-component-templates.d.ts +4 -0
- package/schematics/utils/templates/get-component-templates.js +36 -0
- package/schematics/utils/templates/ng-component-input-manipulations.d.ts +76 -0
- package/schematics/utils/templates/ng-component-input-manipulations.js +142 -0
- package/schematics/utils/templates/template-resource.d.ts +5 -0
- package/schematics/utils/templates/template-resource.js +21 -0
- package/tokens/index.d.ts +3 -0
- package/tokens/is-chromium.d.ts +2 -0
- package/tokens/is-firefox.d.ts +2 -0
- package/tokens/is-webkit.d.ts +2 -0
- package/tokens/taiga-ui-cdk-tokens.metadata.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TUI_INTERACTIVE_SELECTORS = [
|
|
4
|
+
'tui-primitive-textfield',
|
|
5
|
+
'tui-primitive-spin-button',
|
|
6
|
+
'tui-action',
|
|
7
|
+
'tui-input-range',
|
|
8
|
+
'tui-pagination',
|
|
9
|
+
'tui-accordion-item',
|
|
10
|
+
'tui-button',
|
|
11
|
+
'tuiButton',
|
|
12
|
+
'tuiIconButton',
|
|
13
|
+
'tui-toggle',
|
|
14
|
+
'tuiSlider',
|
|
15
|
+
'tui-slider',
|
|
16
|
+
'tui-rating',
|
|
17
|
+
'tui-input-card',
|
|
18
|
+
'tui-input-cvc',
|
|
19
|
+
'tui-input-expire',
|
|
20
|
+
'tui-editor',
|
|
21
|
+
'tui-input-color',
|
|
22
|
+
'tui-input-copy',
|
|
23
|
+
'tui-input-count',
|
|
24
|
+
'tui-input-date-time',
|
|
25
|
+
'tui-input-inline',
|
|
26
|
+
'tui-input-password',
|
|
27
|
+
'tui-input-phone-international',
|
|
28
|
+
'tui-input-phone',
|
|
29
|
+
'tui-input-range',
|
|
30
|
+
'tui-input-slider',
|
|
31
|
+
'tui-input',
|
|
32
|
+
'tui-range',
|
|
33
|
+
'tui-text-area',
|
|
34
|
+
'tui-radio-block',
|
|
35
|
+
'tui-radio-labeled',
|
|
36
|
+
'tui-radio-list',
|
|
37
|
+
'tui-radio',
|
|
38
|
+
'tui-select',
|
|
39
|
+
'tui-input-card-grouped',
|
|
40
|
+
'tui-checkbox-block',
|
|
41
|
+
'tui-checkbox-labeled',
|
|
42
|
+
'tui-combo-box',
|
|
43
|
+
'tui-input-date-range',
|
|
44
|
+
'tui-input-file',
|
|
45
|
+
'tui-input-files',
|
|
46
|
+
'tui-input-month-range',
|
|
47
|
+
'tui-input-month',
|
|
48
|
+
'tui-input-number',
|
|
49
|
+
'tui-input-time',
|
|
50
|
+
'tui-input-time',
|
|
51
|
+
'tui-multiselect',
|
|
52
|
+
'tui-filter',
|
|
53
|
+
'tui-input-tag',
|
|
54
|
+
];
|
|
@@ -27,4 +27,54 @@ exports.MIGRATION_WARNINGS = [
|
|
|
27
27
|
moduleSpecifier: '@taiga-ui/kit',
|
|
28
28
|
message: 'Use DI-token TUI_COUNTRIES_MASKS to get phone mask by country iso code',
|
|
29
29
|
},
|
|
30
|
+
{
|
|
31
|
+
name: 'TuiTableModeModule',
|
|
32
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
33
|
+
message: 'TuiTableModeModule has been deleted in 3.0, please use @taiga-ui/addon-table',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'TuiColorModule',
|
|
37
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
38
|
+
message: 'TuiColorModule has been deleted in 3.0, please use CSS custom properties',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'TuiPluralizePipeModule',
|
|
42
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
43
|
+
message: 'TuiPluralizePipeModule has been deleted in 3.0, please use use Angular built-in pipe https://angular.io/api/common/I18nPluralPipe ',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'TUI_DEFAULT_COLOR_HANDLER',
|
|
47
|
+
moduleSpecifier: '@taiga-ui/addon-charts',
|
|
48
|
+
message: 'TUI_DEFAULT_COLOR_HANDLER has been deleted in 3.0, please use CSS variables',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'TuiColorHandler',
|
|
52
|
+
moduleSpecifier: '@taiga-ui/addon-charts',
|
|
53
|
+
message: 'TuiColorHandler has been deleted in 3.0, please use CSS custom properties',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'DEFAULT_COLORS',
|
|
57
|
+
moduleSpecifier: '@taiga-ui/addon-charts',
|
|
58
|
+
message: 'DEFAULT_COLORS has been deleted in 3.0, please use CSS variables',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'AbstractTuiInteractive',
|
|
62
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
63
|
+
message: 'pressedChange and hoveredChange outputs have been removed from AbstractTuiInteractive, please use tuiPressedChange and tuiHoveredChange directives instead',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'AbstractTuiControl',
|
|
67
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
68
|
+
message: 'pressedChange and hoveredChange outputs have been removed from AbstractTuiInteractive, please use tuiPressedChange and tuiHoveredChange directives instead',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'AbstractTuiMultipleControl',
|
|
72
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
73
|
+
message: 'pressedChange and hoveredChange outputs have been removed from AbstractTuiInteractive, please use tuiPressedChange and tuiHoveredChange directives instead',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'AbstractTuiNullableControl',
|
|
77
|
+
moduleSpecifier: '@taiga-ui/core',
|
|
78
|
+
message: 'pressedChange and hoveredChange outputs have been removed from AbstractTuiInteractive, please use tuiPressedChange and tuiHoveredChange directives instead',
|
|
79
|
+
},
|
|
30
80
|
];
|
|
@@ -9,6 +9,9 @@ const replace_const_1 = require("./steps/replace-const");
|
|
|
9
9
|
const replace_deep_import_1 = require("./steps/replace-deep-import");
|
|
10
10
|
const show_warnings_1 = require("./steps/show-warnings");
|
|
11
11
|
const replace_services_1 = require("./steps/replace-services");
|
|
12
|
+
const migrate_templates_1 = require("./steps/migrate-templates");
|
|
13
|
+
const migrate_sliders_1 = require("./steps/migrate-sliders");
|
|
14
|
+
const remove_module_1 = require("./steps/remove-module");
|
|
12
15
|
function updateToV3(_) {
|
|
13
16
|
return (tree, context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
17
|
context.logger.info(`taiga packages will be updated to ${versions_1.TAIGA_VERSION}`);
|
|
@@ -19,6 +22,9 @@ function updateToV3(_) {
|
|
|
19
22
|
replace_const_1.replaceConsts();
|
|
20
23
|
replace_services_1.replaceServices();
|
|
21
24
|
show_warnings_1.showWarnings(context);
|
|
25
|
+
migrate_templates_1.migrateTemplates(tree);
|
|
26
|
+
migrate_sliders_1.migrateSliders(tree);
|
|
27
|
+
remove_module_1.removeModules();
|
|
22
28
|
ng_morph_1.saveActiveProject();
|
|
23
29
|
});
|
|
24
30
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const migrate_input_slider_1 = require("./migrate-input-slider");
|
|
4
|
+
function migrateSliders(tree) {
|
|
5
|
+
migrate_input_slider_1.migrateInputSlider(tree);
|
|
6
|
+
}
|
|
7
|
+
exports.migrateSliders = migrateSliders;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ng_morph_1 = require("ng-morph");
|
|
4
|
+
const devkit_file_system_1 = require("ng-morph/project/classes/devkit-file-system");
|
|
5
|
+
const ng_component_input_manipulations_1 = require("../../../utils/templates/ng-component-input-manipulations");
|
|
6
|
+
const ng_component_1 = require("../../../utils/angular/ng-component");
|
|
7
|
+
const add_unique_import_1 = require("../../../utils/add-unique-import");
|
|
8
|
+
const get_component_templates_1 = require("../../../utils/templates/get-component-templates");
|
|
9
|
+
const elements_1 = require("../../../utils/templates/elements");
|
|
10
|
+
function migrateInputSlider(tree) {
|
|
11
|
+
const fileSystem = new devkit_file_system_1.DevkitFileSystem(tree);
|
|
12
|
+
const templateResources = get_component_templates_1.getComponentTemplates('**/**');
|
|
13
|
+
for (const templateResource of templateResources) {
|
|
14
|
+
replaceMinMaxLabels(templateResource, fileSystem);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.migrateInputSlider = migrateInputSlider;
|
|
18
|
+
function replaceMinMaxLabels(templateResource, fileSystem) {
|
|
19
|
+
const wasMaxLabelModified = ng_component_input_manipulations_1.replaceInputProperty({
|
|
20
|
+
templateResource,
|
|
21
|
+
fileSystem,
|
|
22
|
+
componentSelector: 'tui-input-slider',
|
|
23
|
+
from: 'maxLabel',
|
|
24
|
+
to: '[valueContent]',
|
|
25
|
+
newValue: 'tuiMigrationMinMaxLabel',
|
|
26
|
+
});
|
|
27
|
+
const wasMinLabelModified = ng_component_input_manipulations_1.replaceInputProperty({
|
|
28
|
+
templateResource,
|
|
29
|
+
fileSystem,
|
|
30
|
+
componentSelector: 'tui-input-slider',
|
|
31
|
+
from: 'minLabel',
|
|
32
|
+
to: '[valueContent]',
|
|
33
|
+
newValue: 'tuiMigrationMinMaxLabel',
|
|
34
|
+
filterFn: element => !elements_1.hasElementAttribute(element, 'maxLabel'),
|
|
35
|
+
});
|
|
36
|
+
ng_component_input_manipulations_1.removeInputProperty({
|
|
37
|
+
templateResource,
|
|
38
|
+
fileSystem,
|
|
39
|
+
componentSelector: 'tui-input-slider',
|
|
40
|
+
inputProperty: 'minLabel',
|
|
41
|
+
filterFn: element => elements_1.hasElementAttribute(element, 'maxLabel'),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* We should update virtual file tree
|
|
45
|
+
* otherwise all following ng-morph commands will overwrite all previous template manipulations
|
|
46
|
+
* */
|
|
47
|
+
fileSystem.commitEdits();
|
|
48
|
+
ng_morph_1.saveActiveProject();
|
|
49
|
+
ng_morph_1.setActiveProject(ng_morph_1.createProject(fileSystem.tree, '/', '**/**'));
|
|
50
|
+
const [ngComponent] = ng_component_1.getNgComponents(templateResource.componentPath);
|
|
51
|
+
if ((wasMaxLabelModified || wasMinLabelModified) && ngComponent) {
|
|
52
|
+
add_unique_import_1.addUniqueImport(templateResource.componentPath, 'TuiContextWithImplicit', '@taiga-ui/cdk');
|
|
53
|
+
ng_morph_1.addMethods(ngComponent, {
|
|
54
|
+
name: 'tuiMigrationMinMaxLabel',
|
|
55
|
+
returnType: 'string',
|
|
56
|
+
parameters: [{ name: 'context', type: 'TuiContextWithImplicit<number>' }],
|
|
57
|
+
statements: [
|
|
58
|
+
'const currentValue = context.$implicit;',
|
|
59
|
+
'const maxValue = 100; // TODO replace with the MAX value of the input',
|
|
60
|
+
'const maxLabelText = "Max"; // TODO replace with the required label',
|
|
61
|
+
'const minValue = 0; // TODO replace with the MIN value of the input',
|
|
62
|
+
'const minLabelText = "Min"; // TODO replace with the required label',
|
|
63
|
+
'if (currentValue === maxValue) return maxLabelText;',
|
|
64
|
+
'if (currentValue === minValue) return minLabelText;',
|
|
65
|
+
'return String(currentValue);',
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const get_component_templates_1 = require("../../utils/templates/get-component-templates");
|
|
4
|
+
const templates_1 = require("../constants/templates");
|
|
5
|
+
const elements_1 = require("../../utils/templates/elements");
|
|
6
|
+
const devkit_file_system_1 = require("ng-morph/project/classes/devkit-file-system");
|
|
7
|
+
const ng_component_input_manipulations_1 = require("../../utils/templates/ng-component-input-manipulations");
|
|
8
|
+
const template_resource_1 = require("../../utils/templates/template-resource");
|
|
9
|
+
const ng_morph_1 = require("ng-morph");
|
|
10
|
+
const START_TAG_OFFSET = 1;
|
|
11
|
+
const END_TAG_OFFSET = 2;
|
|
12
|
+
function migrateTemplates(tree) {
|
|
13
|
+
const templateResources = get_component_templates_1.getComponentTemplates('**/**');
|
|
14
|
+
const fileSystem = new devkit_file_system_1.DevkitFileSystem(tree);
|
|
15
|
+
templateResources.forEach((resource) => {
|
|
16
|
+
const path = fileSystem.resolve(template_resource_1.getPathFromTemplateResource(resource));
|
|
17
|
+
const template = template_resource_1.getTemplateFromTemplateResource(resource, fileSystem);
|
|
18
|
+
const recorder = fileSystem.edit(path);
|
|
19
|
+
const offset = template_resource_1.getTemplateOffset(resource);
|
|
20
|
+
replaceTags(template, recorder, offset);
|
|
21
|
+
replaceAttrs(template, recorder, offset);
|
|
22
|
+
replaceAttrsByDirective(fileSystem, resource);
|
|
23
|
+
/**
|
|
24
|
+
* We should update virtual file tree
|
|
25
|
+
* otherwise all following ng-morph commands will overwrite all previous template manipulations
|
|
26
|
+
* */
|
|
27
|
+
fileSystem.commitEdits();
|
|
28
|
+
ng_morph_1.saveActiveProject();
|
|
29
|
+
ng_morph_1.setActiveProject(ng_morph_1.createProject(fileSystem.tree, '/', '**/**'));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.migrateTemplates = migrateTemplates;
|
|
33
|
+
function replaceAttrsByDirective(fileSystem, templateResource) {
|
|
34
|
+
templates_1.ATTR_TO_DIRECTIVE.forEach(({ componentSelector, directiveModule, directive, inputProperty }) => {
|
|
35
|
+
ng_component_input_manipulations_1.replaceInputPropertyByDirective({
|
|
36
|
+
componentSelector,
|
|
37
|
+
directiveModule,
|
|
38
|
+
directive,
|
|
39
|
+
inputProperty,
|
|
40
|
+
fileSystem,
|
|
41
|
+
templateResource,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function replaceAttrs(template, recorder, templateOffset = 0) {
|
|
46
|
+
templates_1.ATTRS_TO_REPLACE.forEach(({ from, to }) => {
|
|
47
|
+
const offsets = [
|
|
48
|
+
...elements_1.findAttributeOnElementWithTag(template, from.attrName, from.withTagNames || []),
|
|
49
|
+
...elements_1.findAttributeOnElementWithAttrs(template, from.attrName, from.withAttrsNames || []),
|
|
50
|
+
];
|
|
51
|
+
offsets.forEach(offset => {
|
|
52
|
+
recorder.remove(offset + templateOffset, from.attrName.length + (to.attrName.length ? 0 : 1));
|
|
53
|
+
recorder.insertRight(offset + templateOffset, to.attrName);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function replaceTags(template, recorder, templateOffset = 0) {
|
|
58
|
+
templates_1.TAGS_TO_REPLACE.forEach(({ from, to, addAttributes }) => {
|
|
59
|
+
const elements = elements_1.findElementsByTagName(template, from);
|
|
60
|
+
elements.forEach(({ sourceCodeLocation }) => {
|
|
61
|
+
var _a;
|
|
62
|
+
if (sourceCodeLocation) {
|
|
63
|
+
const startTagOffset = sourceCodeLocation.startTag.startOffset;
|
|
64
|
+
const endTagOffset = (_a = sourceCodeLocation.endTag) === null || _a === void 0 ? void 0 : _a.startOffset;
|
|
65
|
+
if (endTagOffset) {
|
|
66
|
+
recorder.remove(endTagOffset + templateOffset + END_TAG_OFFSET, from.length);
|
|
67
|
+
recorder.insertRight(endTagOffset + templateOffset + END_TAG_OFFSET, to);
|
|
68
|
+
}
|
|
69
|
+
recorder.remove(startTagOffset + templateOffset + START_TAG_OFFSET, from.length);
|
|
70
|
+
recorder.insertRight(startTagOffset + templateOffset + START_TAG_OFFSET, `${to} ${addAttributes.join(' ')}`);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ng_morph_1 = require("ng-morph");
|
|
4
|
+
const get_named_import_references_1 = require("../../utils/get-named-import-references");
|
|
5
|
+
const import_manipulations_1 = require("../../utils/import-manipulations");
|
|
6
|
+
const modules_1 = require("../constants/modules");
|
|
7
|
+
function removeModules() {
|
|
8
|
+
modules_1.REMOVED_MODULES.forEach(({ name, moduleSpecifier }) => removeModule(name, moduleSpecifier));
|
|
9
|
+
}
|
|
10
|
+
exports.removeModules = removeModules;
|
|
11
|
+
function removeModule(name, moduleSpecifier) {
|
|
12
|
+
const references = get_named_import_references_1.getNamedImportReferences(name, moduleSpecifier);
|
|
13
|
+
references.forEach(ref => {
|
|
14
|
+
const parent = ref.getParent();
|
|
15
|
+
if (ng_morph_1.Node.isImportSpecifier(parent)) {
|
|
16
|
+
import_manipulations_1.removeImport(parent);
|
|
17
|
+
}
|
|
18
|
+
else if (ng_morph_1.Node.isArrayLiteralExpression(parent)) {
|
|
19
|
+
const index = parent.getElements().findIndex(el => el.getText() === name);
|
|
20
|
+
parent.removeElement(index);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.removeModule = removeModule;
|
|
@@ -11,7 +11,7 @@ function replaceConsts() {
|
|
|
11
11
|
exports.replaceConsts = replaceConsts;
|
|
12
12
|
function replaceConst({ from, to }) {
|
|
13
13
|
const references = get_named_import_references_1.getNamedImportReferences(from.name, from.moduleSpecifier);
|
|
14
|
-
|
|
14
|
+
references.forEach(ref => {
|
|
15
15
|
const parent = ref.getParent();
|
|
16
16
|
if (ng_morph_1.Node.isImportSpecifier(parent)) {
|
|
17
17
|
import_manipulations_1.removeImport(parent);
|
|
@@ -20,6 +20,6 @@ function replaceConst({ from, to }) {
|
|
|
20
20
|
else {
|
|
21
21
|
ref === null || ref === void 0 ? void 0 : ref.replaceWithText(to.name);
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
});
|
|
24
24
|
}
|
|
25
25
|
exports.replaceConst = replaceConst;
|
|
@@ -16,7 +16,7 @@ function addUniqueImport(filePath, namedImport, moduleSpecifier) {
|
|
|
16
16
|
const modules = existingDeclaration[0]
|
|
17
17
|
.getNamedImports()
|
|
18
18
|
.map(namedImport => namedImport.getText());
|
|
19
|
-
ng_morph_1.editImports(existingDeclaration, () => ({
|
|
19
|
+
ng_morph_1.editImports(existingDeclaration[0], () => ({
|
|
20
20
|
namedImports: [...modules, namedImport],
|
|
21
21
|
}));
|
|
22
22
|
return;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ng_morph_1 = require("ng-morph");
|
|
4
|
+
function getNgComponents(pattern, query) {
|
|
5
|
+
return ng_morph_1.getClasses(pattern, query).filter(declaration => !!declaration.getDecorator('Component'));
|
|
6
|
+
}
|
|
7
|
+
exports.getNgComponents = getNgComponents;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ClassDeclaration, Pattern, Query } from 'ng-morph';
|
|
2
|
+
import { StructureType } from 'ng-morph/utils/types/structure-type';
|
|
3
|
+
export declare function getNgModules(pattern: Pattern, query?: Query<Omit<StructureType<ClassDeclaration>, 'kind'>>): ClassDeclaration[];
|
|
4
|
+
/**
|
|
5
|
+
* Find NgModule where the component was declared.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findNgModule(ngComponent: ClassDeclaration): ClassDeclaration | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ng_morph_1 = require("ng-morph");
|
|
4
|
+
function getNgModules(pattern, query) {
|
|
5
|
+
return ng_morph_1.getClasses(pattern, query).filter(declaration => !!declaration.getDecorator('NgModule'));
|
|
6
|
+
}
|
|
7
|
+
exports.getNgModules = getNgModules;
|
|
8
|
+
/**
|
|
9
|
+
* Find NgModule where the component was declared.
|
|
10
|
+
*/
|
|
11
|
+
function findNgModule(ngComponent) {
|
|
12
|
+
const allNgModules = getNgModules('**/**');
|
|
13
|
+
return (allNgModules.find(module => {
|
|
14
|
+
const moduleFile = module.getSourceFile();
|
|
15
|
+
const imports = ng_morph_1.getImports(moduleFile.getFilePath(), {
|
|
16
|
+
namedImports: ngComponent.getName(),
|
|
17
|
+
});
|
|
18
|
+
return imports.some(i => i.getModuleSpecifierSourceFile() === ngComponent.getSourceFile());
|
|
19
|
+
}) || null);
|
|
20
|
+
}
|
|
21
|
+
exports.findNgModule = findNgModule;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Element } from 'parse5';
|
|
2
|
+
export declare function findElementsByTagName(html: string, tagName: string): Element[];
|
|
3
|
+
/**
|
|
4
|
+
* Parses a HTML fragment and traverses all AST nodes in order find elements that
|
|
5
|
+
* include the specified attribute.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findElementsWithAttribute(html: string, attributeName: string): Element[];
|
|
8
|
+
/**
|
|
9
|
+
* Finds elements with explicit tag names that also contain the specified attribute. Returns the
|
|
10
|
+
* attribute start offset based on the specified HTML.
|
|
11
|
+
*/
|
|
12
|
+
export declare function findAttributeOnElementWithTag(html: string, name: string, tagNames: string[], filterFn?: (element: Element) => boolean): number[];
|
|
13
|
+
/**
|
|
14
|
+
* Finds elements that contain the given attribute and contain at least one of the other
|
|
15
|
+
* specified attributes. Returns the primary attribute's start offset based on the specified HTML.
|
|
16
|
+
*/
|
|
17
|
+
export declare function findAttributeOnElementWithAttrs(html: string, name: string, attrs: string[], filterFn?: (element: Element) => boolean): number[];
|
|
18
|
+
/** Shorthand function that checks if the specified element contains the given attribute. */
|
|
19
|
+
export declare function hasElementAttribute(element: Element, attributeName: string): boolean;
|
|
20
|
+
/** Gets the start offset of the given attribute from a Parse5 element. */
|
|
21
|
+
export declare function getStartOffsetOfAttribute(element: Element, attributeName: string): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const parse5_1 = require("parse5");
|
|
4
|
+
const ALWAYS_TRUE_HANDLER = () => true;
|
|
5
|
+
function findElementsByTagName(html, tagName) {
|
|
6
|
+
const document = parse5_1.parseFragment(html, { sourceCodeLocationInfo: true });
|
|
7
|
+
const elements = [];
|
|
8
|
+
const visitNodes = (nodes) => {
|
|
9
|
+
nodes.forEach(n => {
|
|
10
|
+
const node = n;
|
|
11
|
+
if (node.childNodes) {
|
|
12
|
+
visitNodes(node.childNodes);
|
|
13
|
+
}
|
|
14
|
+
if (node.tagName === tagName) {
|
|
15
|
+
elements.push(node);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
visitNodes(document.childNodes);
|
|
20
|
+
return elements;
|
|
21
|
+
}
|
|
22
|
+
exports.findElementsByTagName = findElementsByTagName;
|
|
23
|
+
/**
|
|
24
|
+
* Parses a HTML fragment and traverses all AST nodes in order find elements that
|
|
25
|
+
* include the specified attribute.
|
|
26
|
+
*/
|
|
27
|
+
function findElementsWithAttribute(html, attributeName) {
|
|
28
|
+
const document = parse5_1.parseFragment(html, { sourceCodeLocationInfo: true });
|
|
29
|
+
const elements = [];
|
|
30
|
+
const visitNodes = (nodes) => {
|
|
31
|
+
nodes.forEach(n => {
|
|
32
|
+
var _a;
|
|
33
|
+
const node = n;
|
|
34
|
+
if (node.childNodes) {
|
|
35
|
+
visitNodes(node.childNodes);
|
|
36
|
+
}
|
|
37
|
+
if ((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.some(attr => attr.name === attributeName.toLowerCase())) {
|
|
38
|
+
elements.push(node);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
visitNodes(document.childNodes);
|
|
43
|
+
return elements;
|
|
44
|
+
}
|
|
45
|
+
exports.findElementsWithAttribute = findElementsWithAttribute;
|
|
46
|
+
/**
|
|
47
|
+
* Finds elements with explicit tag names that also contain the specified attribute. Returns the
|
|
48
|
+
* attribute start offset based on the specified HTML.
|
|
49
|
+
*/
|
|
50
|
+
function findAttributeOnElementWithTag(html, name, tagNames, filterFn = ALWAYS_TRUE_HANDLER) {
|
|
51
|
+
return findElementsWithAttribute(html, name)
|
|
52
|
+
.filter(element => tagNames.includes(element.tagName) && filterFn(element))
|
|
53
|
+
.map(element => getStartOffsetOfAttribute(element, name));
|
|
54
|
+
}
|
|
55
|
+
exports.findAttributeOnElementWithTag = findAttributeOnElementWithTag;
|
|
56
|
+
/**
|
|
57
|
+
* Finds elements that contain the given attribute and contain at least one of the other
|
|
58
|
+
* specified attributes. Returns the primary attribute's start offset based on the specified HTML.
|
|
59
|
+
*/
|
|
60
|
+
function findAttributeOnElementWithAttrs(html, name, attrs, filterFn = ALWAYS_TRUE_HANDLER) {
|
|
61
|
+
return findElementsWithAttribute(html, name)
|
|
62
|
+
.filter(element => attrs.some(attr => hasElementAttribute(element, attr)) &&
|
|
63
|
+
filterFn(element))
|
|
64
|
+
.map(element => getStartOffsetOfAttribute(element, name));
|
|
65
|
+
}
|
|
66
|
+
exports.findAttributeOnElementWithAttrs = findAttributeOnElementWithAttrs;
|
|
67
|
+
/** Shorthand function that checks if the specified element contains the given attribute. */
|
|
68
|
+
function hasElementAttribute(element, attributeName) {
|
|
69
|
+
return (element.attrs &&
|
|
70
|
+
element.attrs.some(attr => attr.name === attributeName.toLowerCase()));
|
|
71
|
+
}
|
|
72
|
+
exports.hasElementAttribute = hasElementAttribute;
|
|
73
|
+
/** Gets the start offset of the given attribute from a Parse5 element. */
|
|
74
|
+
function getStartOffsetOfAttribute(element, attributeName) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return ((((_a = element.sourceCodeLocation) === null || _a === void 0 ? void 0 : _a.attrs) && ((_b = element.sourceCodeLocation.attrs[attributeName.toLowerCase()]) === null || _b === void 0 ? void 0 : _b.startOffset)) ||
|
|
77
|
+
0);
|
|
78
|
+
}
|
|
79
|
+
exports.getStartOffsetOfAttribute = getStartOffsetOfAttribute;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ClassDeclaration, Pattern, Query } from 'ng-morph';
|
|
2
|
+
import { StructureType } from 'ng-morph/utils/types/structure-type';
|
|
3
|
+
import { TemplateResource } from '../../ng-update/interfaces/template-resourse';
|
|
4
|
+
export declare function getComponentTemplates(pattern: Pattern, query?: Query<Omit<StructureType<ClassDeclaration>, 'kind'>>): TemplateResource[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const ng_morph_1 = require("ng-morph");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
function getComponentTemplates(pattern, query) {
|
|
7
|
+
return ng_morph_1.getClasses(pattern, query)
|
|
8
|
+
.map(declaration => declaration.getDecorator('Component'))
|
|
9
|
+
.filter((decorator) => !!decorator)
|
|
10
|
+
.map(decoratorToTemplateResource);
|
|
11
|
+
}
|
|
12
|
+
exports.getComponentTemplates = getComponentTemplates;
|
|
13
|
+
function decoratorToTemplateResource(decorator) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
const [metadata] = decorator.getArguments();
|
|
16
|
+
const templateUrl = metadata.getProperty('templateUrl');
|
|
17
|
+
const template = metadata.getProperty('template');
|
|
18
|
+
const componentPath = decorator.getSourceFile().getFilePath();
|
|
19
|
+
if (templateUrl) {
|
|
20
|
+
const templatePath = path.parse(((_a = templateUrl === null || templateUrl === void 0 ? void 0 : templateUrl.getInitializer()) === null || _a === void 0 ? void 0 : _a.getText().replace(/['"]/g, '')) || '');
|
|
21
|
+
return {
|
|
22
|
+
componentPath,
|
|
23
|
+
templatePath: getFullTemplatePath(templatePath, path.parse(componentPath)),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return {
|
|
28
|
+
componentPath,
|
|
29
|
+
template: ((_b = template.getInitializer()) === null || _b === void 0 ? void 0 : _b.getText()) || '',
|
|
30
|
+
offset: ((_c = template.getInitializer()) === null || _c === void 0 ? void 0 : _c.getStart()) || 0,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getFullTemplatePath(templatePath, componentPath) {
|
|
35
|
+
return path.join(componentPath.dir, templatePath.dir, templatePath.name + templatePath.ext);
|
|
36
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DevkitFileSystem } from 'ng-morph/project/classes/devkit-file-system';
|
|
2
|
+
import { Element } from 'parse5';
|
|
3
|
+
import { TemplateResource } from '../../ng-update/interfaces/template-resourse';
|
|
4
|
+
/**
|
|
5
|
+
* Replace component input property by new value
|
|
6
|
+
* ___
|
|
7
|
+
* Example:
|
|
8
|
+
* 1. Before
|
|
9
|
+
* ```html
|
|
10
|
+
* <tui-input-slider secondary="123"></tui-input-slider>
|
|
11
|
+
* ```
|
|
12
|
+
* 2. Execute
|
|
13
|
+
* ```ts
|
|
14
|
+
* const wasModified = replaceInputProperty({
|
|
15
|
+
* templateResource,
|
|
16
|
+
* fileSystem,
|
|
17
|
+
* componentSelector: 'tui-input-slider',
|
|
18
|
+
* from: 'secondary',
|
|
19
|
+
* to: 'tuiTextfieldCustomContent',
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
* 3. After
|
|
23
|
+
* ```html
|
|
24
|
+
* <tui-input-slider tuiTextfieldCustomContent="123"></tui-input-slider>
|
|
25
|
+
* ```
|
|
26
|
+
* ___
|
|
27
|
+
* @return true if something was changed
|
|
28
|
+
*/
|
|
29
|
+
export declare function replaceInputProperty({ templateResource, fileSystem, componentSelector, from, to, newValue, filterFn, }: {
|
|
30
|
+
templateResource: TemplateResource;
|
|
31
|
+
fileSystem: DevkitFileSystem;
|
|
32
|
+
componentSelector: string | string[];
|
|
33
|
+
from: string;
|
|
34
|
+
to: string;
|
|
35
|
+
newValue?: string;
|
|
36
|
+
filterFn?: (element: Element) => boolean;
|
|
37
|
+
}): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* @example
|
|
40
|
+
* // 10 symbols before property `size` and string `size="s"` has 8-symbols length
|
|
41
|
+
* const template = '<tui-card size="s"></tui-card>';
|
|
42
|
+
*
|
|
43
|
+
* getInputPropertyOffsets(template, 'size', ['tui-card']) // [[10, 18]]
|
|
44
|
+
*/
|
|
45
|
+
export declare function getInputPropertyOffsets(html: string, attrName: string, tags: string[], filterFn?: (element: Element) => boolean): [number, number][];
|
|
46
|
+
/**
|
|
47
|
+
* @example
|
|
48
|
+
* // `<tui-card size="` has 16-symbols length
|
|
49
|
+
* const template = '<tui-card size="xl"></tui-card>';
|
|
50
|
+
*
|
|
51
|
+
* getInputPropertyValueOffsets(template, 'size', ['tui-card']) // [ [16, 18] ]
|
|
52
|
+
*/
|
|
53
|
+
export declare function getInputPropertyValueOffsets(template: string, attrName: string, tags: string[]): [number, number][];
|
|
54
|
+
export declare function replaceInputPropertyByDirective({ templateResource, fileSystem, componentSelector, inputProperty, directive, directiveModule, }: {
|
|
55
|
+
templateResource: TemplateResource;
|
|
56
|
+
fileSystem: DevkitFileSystem;
|
|
57
|
+
componentSelector: string | string[];
|
|
58
|
+
inputProperty: string;
|
|
59
|
+
directive: string;
|
|
60
|
+
directiveModule?: {
|
|
61
|
+
name: string;
|
|
62
|
+
moduleSpecifier: string;
|
|
63
|
+
};
|
|
64
|
+
}): void;
|
|
65
|
+
/**
|
|
66
|
+
* After removing property from the tag (which uses multi lines inside template) it can leave redundant space.
|
|
67
|
+
* It is not critical because html is valid even with this extra space.
|
|
68
|
+
* TODO: Find a way to fix it
|
|
69
|
+
*/
|
|
70
|
+
export declare function removeInputProperty({ templateResource, fileSystem, componentSelector, inputProperty, filterFn, }: {
|
|
71
|
+
templateResource: TemplateResource;
|
|
72
|
+
fileSystem: DevkitFileSystem;
|
|
73
|
+
componentSelector: string;
|
|
74
|
+
inputProperty: string;
|
|
75
|
+
filterFn?: (element: Element) => boolean;
|
|
76
|
+
}): void;
|