@taiga-ui/cdk 2.51.1 → 2.52.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/package.json +1 -1
- package/schematics/ng-update/index.js +4 -0
- package/schematics/ng-update/steps/migrate-date-time.d.ts +1 -0
- package/schematics/ng-update/steps/migrate-date-time.js +152 -0
- package/schematics/ng-update/steps/migrate-templates.js +21 -0
- package/schematics/ng-update/steps/miscellaneous.js +2 -6
- package/schematics/ng-update/steps/replace-services.js +2 -1
- package/schematics/utils/insert-todo.d.ts +2 -0
- package/schematics/utils/insert-todo.js +8 -0
- package/schematics/utils/templates/elements.d.ts +1 -0
- package/schematics/utils/templates/elements.js +7 -18
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ const miscellaneous_1 = require("./steps/miscellaneous");
|
|
|
16
16
|
const replace_functions_1 = require("./steps/replace-functions");
|
|
17
17
|
const migrate_progress_1 = require("./steps/migrate-progress");
|
|
18
18
|
const colored_log_1 = require("../utils/colored-log");
|
|
19
|
+
const migrate_date_time_1 = require("./steps/migrate-date-time");
|
|
19
20
|
function updateToV3(_) {
|
|
20
21
|
return (tree, context) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
22
|
console.info('\x1b[35m', `taiga packages will be updated to ${versions_1.TAIGA_VERSION}`);
|
|
@@ -51,6 +52,9 @@ function updateToV3(_) {
|
|
|
51
52
|
colored_log_1.infoLog('removing modules...');
|
|
52
53
|
remove_module_1.removeModules();
|
|
53
54
|
colored_log_1.successLog('modules removed');
|
|
55
|
+
colored_log_1.infoLog('migrating taiga date/time ...');
|
|
56
|
+
migrate_date_time_1.dateTimeMigrations();
|
|
57
|
+
colored_log_1.successLog('date/time migrated');
|
|
54
58
|
colored_log_1.infoLog('miscellaneous migrating...');
|
|
55
59
|
replace_functions_1.replaceFunctions();
|
|
56
60
|
miscellaneous_1.miscellaneousMigrations();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dateTimeMigrations(): void;
|
|
@@ -0,0 +1,152 @@
|
|
|
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 insert_todo_1 = require("../../utils/insert-todo");
|
|
6
|
+
function dateTimeMigrations() {
|
|
7
|
+
migrateProperty({
|
|
8
|
+
namedImport: 'TuiDay',
|
|
9
|
+
moduleSpecifier: '@taiga-ui/cdk',
|
|
10
|
+
from: 'formattedDay',
|
|
11
|
+
callback: node => node.replaceWithText(node.getText().replace('formattedDay', 'getFormattedDay("DMY", ".")')),
|
|
12
|
+
});
|
|
13
|
+
migrateProperty({
|
|
14
|
+
namedImport: 'TuiDayRange',
|
|
15
|
+
moduleSpecifier: '@taiga-ui/cdk',
|
|
16
|
+
from: 'formattedDayRange',
|
|
17
|
+
callback: node => node.replaceWithText(node
|
|
18
|
+
.getText()
|
|
19
|
+
.replace('formattedDayRange', 'getFormattedDayRange("DMY", ".")')),
|
|
20
|
+
});
|
|
21
|
+
migrateProperty({
|
|
22
|
+
namedImport: 'TuiDayRange',
|
|
23
|
+
moduleSpecifier: '@taiga-ui/cdk',
|
|
24
|
+
from: 'normalizeParse',
|
|
25
|
+
callback: node => {
|
|
26
|
+
const parent = node.getParent();
|
|
27
|
+
if (ng_morph_1.Node.isCallExpression(parent)) {
|
|
28
|
+
changeNormalizeArgs(parent);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
[
|
|
33
|
+
{
|
|
34
|
+
namedImport: 'TuiMonthRange',
|
|
35
|
+
field: 'formattedMonthRange',
|
|
36
|
+
message: 'formattedMonthRange has been removed in 3.0. Please use TUI_MONTH_FORMATTER from @taiga-ui/kit',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
namedImport: 'TuiMonth',
|
|
40
|
+
field: 'formattedMonth',
|
|
41
|
+
message: 'formattedMonth has been removed in 3.0. Please use TUI_MONTH_FORMATTER from @taiga-ui/kit',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
namedImport: 'TuiDay',
|
|
45
|
+
field: 'getDayFromMonthRowCol',
|
|
46
|
+
message: 'getDayFromMonthRowCol has been removed in 3.0. If you need this utils check out this pipe https://github.com/Tinkoff/taiga-ui/tree/main/projects/core/pipes/calendar-sheet',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
namedImport: 'TuiMonth',
|
|
50
|
+
field: 'monthStartDaysOffset',
|
|
51
|
+
message: 'monthStartDaysOffset has been removed in 3.0. If you need this utils check out this pipe https://github.com/Tinkoff/taiga-ui/tree/main/projects/core/pipes/calendar-sheet',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
namedImport: 'TuiMonth',
|
|
55
|
+
field: 'weeksRowsCount',
|
|
56
|
+
message: 'weeksRowsCount has been removed in 3.0. If you need this utils check out this pipe https://github.com/Tinkoff/taiga-ui/tree/main/projects/core/pipes/calendar-sheet',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
namedImport: 'TuiYear',
|
|
60
|
+
field: 'getYearStartDaysOffset',
|
|
61
|
+
message: 'getYearStartDaysOffset has been removed in 3.0. If you need this utils check out this pipe https://github.com/Tinkoff/taiga-ui/tree/main/projects/core/pipes/calendar-sheet',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
namedImport: 'TuiYear',
|
|
65
|
+
field: 'weeksRowsCount',
|
|
66
|
+
message: 'weeksRowsCount has been removed in 3.0. If you need this utils check out this pipe https://github.com/Tinkoff/taiga-ui/tree/main/projects/core/pipes/calendar-sheet',
|
|
67
|
+
},
|
|
68
|
+
].forEach(({ namedImport, field, message }) => {
|
|
69
|
+
migrateProperty({
|
|
70
|
+
namedImport,
|
|
71
|
+
moduleSpecifier: '@taiga-ui/cdk',
|
|
72
|
+
from: field,
|
|
73
|
+
callback: node => insertTodoBeforeNode(node, message),
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.dateTimeMigrations = dateTimeMigrations;
|
|
78
|
+
function migrateProperty({ namedImport, moduleSpecifier, from, callback, }) {
|
|
79
|
+
const references = get_named_import_references_1.getNamedImportReferences(namedImport, moduleSpecifier);
|
|
80
|
+
references.forEach(ref => {
|
|
81
|
+
if (ref.wasForgotten()) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const parent = ref.getParent();
|
|
85
|
+
if (!parent) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (ng_morph_1.Node.isNewExpression(parent)) {
|
|
89
|
+
const accessExpression = parent.getFirstAncestorByKind(ng_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
90
|
+
const searched = accessExpression === null || accessExpression === void 0 ? void 0 : accessExpression.getChildrenOfKind(ng_morph_1.SyntaxKind.Identifier).find(identifier => identifier.getText() === from);
|
|
91
|
+
if (searched && accessExpression) {
|
|
92
|
+
callback(accessExpression);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (ng_morph_1.Node.isPropertyAccessExpression(parent)) {
|
|
97
|
+
const searched = parent
|
|
98
|
+
.getChildrenOfKind(ng_morph_1.SyntaxKind.Identifier)
|
|
99
|
+
.find(identifier => identifier.getText() === from);
|
|
100
|
+
if (searched && !parent.wasForgotten()) {
|
|
101
|
+
callback(parent);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
replaceIdentifier(parent, from, callback);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function replaceIdentifier(node, from, callback) {
|
|
109
|
+
const declaration = node.getFirstAncestorByKind(ng_morph_1.SyntaxKind.VariableDeclaration) ||
|
|
110
|
+
node.getFirstAncestorByKind(ng_morph_1.SyntaxKind.PropertyDeclaration);
|
|
111
|
+
const identifier = declaration === null || declaration === void 0 ? void 0 : declaration.getFirstDescendantByKind(ng_morph_1.SyntaxKind.Identifier);
|
|
112
|
+
if (identifier) {
|
|
113
|
+
replaceIdentifierReferences(identifier, from, callback);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function replaceIdentifierReferences(identifier, from, callback) {
|
|
117
|
+
identifier.findReferencesAsNodes().forEach(ref => {
|
|
118
|
+
let parent = ref.getParent();
|
|
119
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.getText()) === `this.${identifier.getText()}` ||
|
|
120
|
+
(parent === null || parent === void 0 ? void 0 : parent.getText()) === identifier.getText()) {
|
|
121
|
+
replaceIdentifier(parent, from, callback);
|
|
122
|
+
}
|
|
123
|
+
if (parent === null || parent === void 0 ? void 0 : parent.getText().startsWith('this')) {
|
|
124
|
+
parent = parent === null || parent === void 0 ? void 0 : parent.getParent();
|
|
125
|
+
}
|
|
126
|
+
if (ng_morph_1.Node.isPropertyAccessExpression(parent)) {
|
|
127
|
+
const searched = parent
|
|
128
|
+
.getChildrenOfKind(ng_morph_1.SyntaxKind.Identifier)
|
|
129
|
+
.find(identifier => identifier.getText() === from);
|
|
130
|
+
if (searched) {
|
|
131
|
+
callback(parent);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function changeNormalizeArgs(node) {
|
|
137
|
+
const args = node.getArguments();
|
|
138
|
+
if (args.length > 2) {
|
|
139
|
+
node.removeArgument(2);
|
|
140
|
+
node.removeArgument(1);
|
|
141
|
+
node.addArgument('"DMY"');
|
|
142
|
+
}
|
|
143
|
+
else if (args.length === 1) {
|
|
144
|
+
node.addArgument('"DMY"');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function insertTodoBeforeNode(node, message) {
|
|
148
|
+
const identifier = node.getFirstDescendantByKind(ng_morph_1.SyntaxKind.Identifier);
|
|
149
|
+
if (identifier) {
|
|
150
|
+
insert_todo_1.insertTodo(identifier, message);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -20,6 +20,7 @@ function migrateTemplates(fileSystem) {
|
|
|
20
20
|
replaceFieldError,
|
|
21
21
|
addHTMLCommentTags,
|
|
22
22
|
addEditorProviders,
|
|
23
|
+
migrateTuiHideSelectedPipe,
|
|
23
24
|
];
|
|
24
25
|
componentWithTemplatesPaths.forEach(resource => {
|
|
25
26
|
const path = fileSystem.resolve(template_resource_1.getPathFromTemplateResource(resource));
|
|
@@ -150,3 +151,23 @@ function addEditorProviders({ resource, fileSystem, }) {
|
|
|
150
151
|
add_unique_import_1.addUniqueImport(componentPath, 'defaultEditorExtensions', '@taiga-ui/addon-editor');
|
|
151
152
|
}
|
|
152
153
|
}
|
|
154
|
+
const HIDE_SELECTED_PIPE_WITH_ARGS_REG = /\|\s*tuiHideSelected(\s*:\s*[^|'"]*)?/gi;
|
|
155
|
+
function migrateTuiHideSelectedPipe({ resource, fileSystem, recorder, }) {
|
|
156
|
+
const template = template_resource_1.getTemplateFromTemplateResource(resource, fileSystem);
|
|
157
|
+
const templateOffset = template_resource_1.getTemplateOffset(resource);
|
|
158
|
+
const elementsWithPipe = elements_1.findElementByFn(template, el => { var _a; return (_a = el.attrs) === null || _a === void 0 ? void 0 : _a.some(attr => attr.value.match(HIDE_SELECTED_PIPE_WITH_ARGS_REG)); });
|
|
159
|
+
elementsWithPipe.forEach(el => {
|
|
160
|
+
var _a;
|
|
161
|
+
const { name, value: oldValue } = el.attrs.find(attr => attr.value.match(HIDE_SELECTED_PIPE_WITH_ARGS_REG)) ||
|
|
162
|
+
{};
|
|
163
|
+
const attrLocations = (_a = el.sourceCodeLocation) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
164
|
+
if (!name || !oldValue || !attrLocations) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const newValue = oldValue.replace(HIDE_SELECTED_PIPE_WITH_ARGS_REG, '| tuiHideSelected');
|
|
168
|
+
const { startOffset } = attrLocations[name];
|
|
169
|
+
const valueOffset = templateOffset + startOffset + name.length + '="'.length;
|
|
170
|
+
recorder.remove(valueOffset, oldValue.length);
|
|
171
|
+
recorder.insertRight(valueOffset, newValue);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const get_named_import_references_1 = require("../../utils/get-named-import-references");
|
|
4
4
|
const ng_morph_1 = require("ng-morph");
|
|
5
|
+
const insert_todo_1 = require("../../utils/insert-todo");
|
|
5
6
|
function miscellaneousMigrations() {
|
|
6
7
|
replaceEnumProperty({
|
|
7
8
|
enumName: 'TuiCurrency',
|
|
@@ -52,14 +53,9 @@ function checkMethod(node, method, message) {
|
|
|
52
53
|
if (ng_morph_1.Node.isPropertyAccessExpression(parent)) {
|
|
53
54
|
parent.getChildrenOfKind(ng_morph_1.SyntaxKind.Identifier).forEach(identifier => {
|
|
54
55
|
if (identifier.getText() === method) {
|
|
55
|
-
insertTodo(identifier, message);
|
|
56
|
+
insert_todo_1.insertTodo(identifier, message);
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
function insertTodo(identifier, message) {
|
|
62
|
-
const startLinePos = identifier.getStartLinePos();
|
|
63
|
-
const sourceFile = identifier.getSourceFile();
|
|
64
|
-
sourceFile.insertText(startLinePos, `// TODO: ${message}\n`);
|
|
65
|
-
}
|
|
@@ -5,9 +5,10 @@ const get_named_import_references_1 = require("../../utils/get-named-import-refe
|
|
|
5
5
|
const ng_morph_1 = require("ng-morph");
|
|
6
6
|
const import_manipulations_1 = require("../../utils/import-manipulations");
|
|
7
7
|
const add_unique_import_1 = require("../../utils/add-unique-import");
|
|
8
|
+
const colored_log_1 = require("../../utils/colored-log");
|
|
8
9
|
function replaceServices() {
|
|
9
10
|
services_1.SERVICES_TO_REPLACE.forEach(service => {
|
|
10
|
-
|
|
11
|
+
colored_log_1.infoLog(`replacing ${service.from.name}`);
|
|
11
12
|
replaceService(service);
|
|
12
13
|
});
|
|
13
14
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function insertTodo(identifier, message) {
|
|
4
|
+
const startLinePos = identifier.getStartLinePos();
|
|
5
|
+
const sourceFile = identifier.getSourceFile();
|
|
6
|
+
sourceFile.insertText(startLinePos, `// TODO: (Taiga UI migration) ${message}\n`);
|
|
7
|
+
}
|
|
8
|
+
exports.insertTodo = insertTodo;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Element } from 'parse5';
|
|
2
|
+
export declare function findElementByFn(html: string, predicateFn: (el: Element) => boolean): Element[];
|
|
2
3
|
export declare function findElementsByTagName(html: string, tagName: string): Element[];
|
|
3
4
|
/**
|
|
4
5
|
* Parses a HTML fragment and traverses all AST nodes in order find elements that
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const parse5_1 = require("parse5");
|
|
4
4
|
const ALWAYS_TRUE_HANDLER = () => true;
|
|
5
|
-
function
|
|
5
|
+
function findElementByFn(html, predicateFn) {
|
|
6
6
|
const document = parse5_1.parseFragment(html, { sourceCodeLocationInfo: true });
|
|
7
7
|
const elements = [];
|
|
8
8
|
const visitNodes = (nodes) => {
|
|
@@ -11,7 +11,7 @@ function findElementsByTagName(html, tagName) {
|
|
|
11
11
|
if (node.childNodes) {
|
|
12
12
|
visitNodes(node.childNodes);
|
|
13
13
|
}
|
|
14
|
-
if (node
|
|
14
|
+
if (predicateFn(node)) {
|
|
15
15
|
elements.push(node);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
@@ -19,28 +19,17 @@ function findElementsByTagName(html, tagName) {
|
|
|
19
19
|
visitNodes(document.childNodes);
|
|
20
20
|
return elements;
|
|
21
21
|
}
|
|
22
|
+
exports.findElementByFn = findElementByFn;
|
|
23
|
+
function findElementsByTagName(html, tagName) {
|
|
24
|
+
return findElementByFn(html, el => el.tagName === tagName);
|
|
25
|
+
}
|
|
22
26
|
exports.findElementsByTagName = findElementsByTagName;
|
|
23
27
|
/**
|
|
24
28
|
* Parses a HTML fragment and traverses all AST nodes in order find elements that
|
|
25
29
|
* include the specified attribute.
|
|
26
30
|
*/
|
|
27
31
|
function findElementsWithAttribute(html, attributeName) {
|
|
28
|
-
|
|
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;
|
|
32
|
+
return findElementByFn(html, el => { var _a; return (_a = el.attrs) === null || _a === void 0 ? void 0 : _a.some(attr => attr.name === attributeName.toLowerCase()); });
|
|
44
33
|
}
|
|
45
34
|
exports.findElementsWithAttribute = findElementsWithAttribute;
|
|
46
35
|
/**
|