@taiga-ui/cdk 4.45.0 → 4.46.0-canary.3415f27

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.
Files changed (29) hide show
  1. package/constants/empty.d.ts +1 -0
  2. package/constants/version.d.ts +1 -1
  3. package/constants/version.js +1 -1
  4. package/esm2022/constants/empty.mjs +2 -1
  5. package/esm2022/constants/version.mjs +2 -2
  6. package/esm2022/date-time/day.mjs +4 -2
  7. package/esm2022/date-time/month.mjs +5 -2
  8. package/esm2022/observables/close-watcher.mjs +2 -1
  9. package/esm2022/utils/dom/retarget-boundary-crossing.mjs +1 -1
  10. package/fesm2022/taiga-ui-cdk-constants.mjs +2 -1
  11. package/fesm2022/taiga-ui-cdk-constants.mjs.map +1 -1
  12. package/fesm2022/taiga-ui-cdk-date-time.mjs +7 -2
  13. package/fesm2022/taiga-ui-cdk-date-time.mjs.map +1 -1
  14. package/fesm2022/taiga-ui-cdk-observables.mjs +1 -0
  15. package/fesm2022/taiga-ui-cdk-observables.mjs.map +1 -1
  16. package/fesm2022/taiga-ui-cdk-utils-dom.mjs.map +1 -1
  17. package/package.json +2 -2
  18. package/schematics/collection.json +6 -0
  19. package/schematics/migration.json +5 -0
  20. package/schematics/ng-update/v5/index.d.ts +3 -0
  21. package/schematics/ng-update/v5/index.js +32 -0
  22. package/schematics/ng-update/v5/schema.json +7 -0
  23. package/schematics/ng-update/v5/steps/migrate-tokens/migrate-tokens.d.ts +13 -0
  24. package/schematics/ng-update/v5/steps/migrate-tokens/migrate-tokens.js +154 -0
  25. package/schematics/ng-update/v5/steps/migrate-tokens/update-tsconfig.d.ts +11 -0
  26. package/schematics/ng-update/v5/steps/migrate-tokens/update-tsconfig.js +75 -0
  27. package/schematics/ng-update/v5/tests/migrate-tokens/utils.d.ts +1 -0
  28. package/schematics/ng-update/v5/tests/migrate-tokens/utils.js +22 -0
  29. package/utils/dom/retarget-boundary-crossing.d.ts +1 -1
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateToV5 = void 0;
4
+ const node_perf_hooks_1 = require("node:perf_hooks");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
7
+ const ng_morph_1 = require("ng-morph");
8
+ const versions_1 = require("../../ng-add/constants/versions");
9
+ const get_execution_time_1 = require("../../utils/get-execution-time");
10
+ const migrate_tokens_1 = require("./steps/migrate-tokens/migrate-tokens");
11
+ const update_tsconfig_1 = require("./steps/migrate-tokens/update-tsconfig");
12
+ function main(options) {
13
+ return (tree, context) => {
14
+ (0, migrate_tokens_1.migrateTokens)(tree, options);
15
+ (0, update_tsconfig_1.updateTsConfig)(tree, options);
16
+ context.addTask(new tasks_1.NodePackageInstallTask());
17
+ };
18
+ }
19
+ function updateToV5(options) {
20
+ const t0 = node_perf_hooks_1.performance.now();
21
+ !options['skip-logs'] &&
22
+ (0, ng_morph_1.titleLog)(`\n\n${ng_morph_1.START_SYMBOL} Your packages will be updated to @taiga-ui/*@${versions_1.TAIGA_VERSION}\n`);
23
+ return (0, schematics_1.chain)([
24
+ main(options),
25
+ () => {
26
+ const executionTime = (0, get_execution_time_1.getExecutionTime)(t0, node_perf_hooks_1.performance.now());
27
+ !options['skip-logs'] &&
28
+ (0, ng_morph_1.titleLog)(`${ng_morph_1.FINISH_SYMBOL} We migrated packages to @taiga-ui/*@${versions_1.TAIGA_VERSION} in ${executionTime}. \n`);
29
+ },
30
+ ]);
31
+ }
32
+ exports.updateToV5 = updateToV5;
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "taiga-ui-ng-update-v5",
4
+ "title": "Taiga UI ng-update v5",
5
+ "type": "object",
6
+ "properties": {}
7
+ }
@@ -0,0 +1,13 @@
1
+ import type { Tree } from '@angular-devkit/schematics';
2
+ import type { TuiSchema } from '../../../../ng-add/schema';
3
+ /**
4
+ * Migrates Taiga UI token functions to Angular's InjectionToken
5
+ *
6
+ * This schematic:
7
+ * 1. Finds all references to `tuiCreateToken` and `tuiCreateTokenFromFactory`
8
+ * 2. Replaces them with equivalent `InjectionToken` implementations
9
+ * 3. Handles proper import management for `InjectionToken`
10
+ * 4. Preserves type parameters and factory functions
11
+ * 5. Adds descriptive error handling and logging
12
+ */
13
+ export declare function migrateTokens(tree: Tree, options: TuiSchema): void;
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrateTokens = void 0;
4
+ const ng_morph_1 = require("ng-morph");
5
+ const constants_1 = require("../../../../constants");
6
+ const get_named_import_references_1 = require("../../../../utils/get-named-import-references");
7
+ const import_manipulations_1 = require("../../../../utils/import-manipulations");
8
+ const insert_todo_1 = require("../../../../utils/insert-todo");
9
+ const TOKEN_FUNCTIONS = ['tuiCreateToken', 'tuiCreateTokenFromFactory'];
10
+ const ANGULAR_CORE = '@angular/core';
11
+ const INJECTION_TOKEN = 'InjectionToken';
12
+ /**
13
+ * Migrates Taiga UI token functions to Angular's InjectionToken
14
+ *
15
+ * This schematic:
16
+ * 1. Finds all references to `tuiCreateToken` and `tuiCreateTokenFromFactory`
17
+ * 2. Replaces them with equivalent `InjectionToken` implementations
18
+ * 3. Handles proper import management for `InjectionToken`
19
+ * 4. Preserves type parameters and factory functions
20
+ * 5. Adds descriptive error handling and logging
21
+ */
22
+ function migrateTokens(tree, options) {
23
+ if (!options['skip-logs']) {
24
+ (0, ng_morph_1.infoLog)('Starting token migration to InjectionToken...');
25
+ }
26
+ const project = (0, ng_morph_1.createProject)(tree, '/', constants_1.ALL_TS_FILES);
27
+ (0, ng_morph_1.setActiveProject)(project);
28
+ const allFiles = (0, ng_morph_1.getSourceFiles)();
29
+ if (!options['skip-logs']) {
30
+ (0, ng_morph_1.infoLog)(`Found ${allFiles.length} source files`);
31
+ }
32
+ TOKEN_FUNCTIONS.forEach((tokenFunction) => {
33
+ const references = (0, get_named_import_references_1.getNamedImportReferences)(tokenFunction, '@taiga-ui/cdk');
34
+ if (!options['skip-logs']) {
35
+ (0, ng_morph_1.infoLog)(`Found ${references.length} references for ${tokenFunction}`);
36
+ }
37
+ references.forEach((ref) => {
38
+ if (ref.wasForgotten()) {
39
+ return;
40
+ }
41
+ try {
42
+ const parent = ref.getParent();
43
+ const sourceFile = ref.getSourceFile();
44
+ if (ng_morph_1.Node.isImportSpecifier(parent)) {
45
+ (0, import_manipulations_1.removeImport)(parent);
46
+ return;
47
+ }
48
+ if (ng_morph_1.Node.isCallExpression(parent)) {
49
+ const declaration = parent.getFirstAncestorByKind(ng_morph_1.SyntaxKind.VariableDeclaration);
50
+ if (!declaration) {
51
+ if (!ref.wasForgotten()) {
52
+ (0, insert_todo_1.insertTodo)(ref, 'Could not find variable declaration');
53
+ }
54
+ return;
55
+ }
56
+ const constName = declaration.getName();
57
+ if (!constName) {
58
+ if (!ref.wasForgotten()) {
59
+ (0, insert_todo_1.insertTodo)(ref, 'Variable declaration has no name');
60
+ }
61
+ return;
62
+ }
63
+ const newExpression = createInjectionTokenExpression(parent, constName, tokenFunction);
64
+ parent.replaceWithText(newExpression);
65
+ // handle InjectionToken imports
66
+ let hasValueImport = false;
67
+ const coreImports = [];
68
+ sourceFile.getImportDeclarations().forEach((decl) => {
69
+ if (decl.getModuleSpecifierValue() !== ANGULAR_CORE) {
70
+ return;
71
+ }
72
+ coreImports.push(decl);
73
+ const namedImports = decl.getNamedImports();
74
+ const tokenImport = namedImports.find((i) => i.getName() === INJECTION_TOKEN);
75
+ if (!tokenImport) {
76
+ return;
77
+ }
78
+ // remove InjectionToken from type-only imports
79
+ if (tokenImport.isTypeOnly() || decl.isTypeOnly()) {
80
+ tokenImport.remove();
81
+ // remove the import declaration if it becomes empty
82
+ if (decl.getNamedImports().length === 0) {
83
+ decl.remove();
84
+ }
85
+ }
86
+ else {
87
+ hasValueImport = true;
88
+ }
89
+ });
90
+ // add InjectionToken as regular import if needed
91
+ if (!hasValueImport) {
92
+ sourceFile.addImportDeclaration({
93
+ moduleSpecifier: ANGULAR_CORE,
94
+ namedImports: [INJECTION_TOKEN],
95
+ isTypeOnly: false,
96
+ });
97
+ }
98
+ }
99
+ }
100
+ catch (error) {
101
+ const message = error instanceof Error ? error.message : String(error);
102
+ if (!options['skip-logs']) {
103
+ (0, ng_morph_1.infoLog)(`Error migrating token: ${message}`);
104
+ }
105
+ if (!ref.wasForgotten()) {
106
+ (0, insert_todo_1.insertTodo)(ref, `Migration failed: ${message}`);
107
+ }
108
+ }
109
+ });
110
+ });
111
+ (0, ng_morph_1.saveActiveProject)();
112
+ if (!options['skip-logs']) {
113
+ (0, ng_morph_1.titleLog)('Token migration completed!');
114
+ }
115
+ }
116
+ exports.migrateTokens = migrateTokens;
117
+ /**
118
+ * Creates InjectionToken expression to replace token functions
119
+ *
120
+ * This function:
121
+ * - Preserves type parameters (<T> syntax)
122
+ * - Converts token values to factory functions when needed
123
+ * - Adds ngDevMode checks for token descriptions
124
+ * - Handles different cases for tuiCreateToken vs tuiCreateTokenFromFactory
125
+ *
126
+ * Example conversions:
127
+ * tuiCreateToken('default') → new InjectionToken(..., { factory: () => 'default' })
128
+ * tuiCreateTokenFromFactory(() => value) → new InjectionToken(..., { factory: () => value })
129
+ */
130
+ function createInjectionTokenExpression(callExpression, constName, tokenFunction) {
131
+ const typeArgs = callExpression.getTypeArguments();
132
+ const typeArgsText = typeArgs.length
133
+ ? `<${typeArgs.map((t) => t.getText()).join(', ')}>`
134
+ : '';
135
+ const args = callExpression.getArguments();
136
+ const isFactory = tokenFunction === 'tuiCreateTokenFromFactory';
137
+ const tokenDescription = `ngDevMode ? '${constName}' : ''`;
138
+ if (args.length > 0 && args[0]) {
139
+ const argText = args[0].getText();
140
+ const isObjectOrArray = argText.startsWith('{') || argText.startsWith('[');
141
+ if (isFactory) {
142
+ return `new ${INJECTION_TOKEN}${typeArgsText}(${tokenDescription}, {
143
+ factory: ${argText}
144
+ })`;
145
+ }
146
+ const factoryContent = isObjectOrArray
147
+ ? `() => (${argText})`
148
+ : `() => ${argText}`;
149
+ return `new ${INJECTION_TOKEN}${typeArgsText}(${tokenDescription}, {
150
+ factory: ${factoryContent}
151
+ })`;
152
+ }
153
+ return `new ${INJECTION_TOKEN}${typeArgsText}(${tokenDescription})`;
154
+ }
@@ -0,0 +1,11 @@
1
+ import type { Tree } from '@angular-devkit/schematics';
2
+ import type { TuiSchema } from '../../../../ng-add/schema';
3
+ /**
4
+ * Updates tsconfig.json to include necessary type definitions
5
+ * - Adds `@taiga-ui/tsconfig` to typeRoots
6
+ * - Adds `node` and `ng-dev-mode` to types array
7
+ *
8
+ * This ensures proper type checking and IntelliSense for Taiga UI components
9
+ * and prevents common TypeScript errors related to custom types and ngDevMode.
10
+ */
11
+ export declare function updateTsConfig(tree: Tree, options: TuiSchema): void;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTsConfig = void 0;
4
+ const ng_morph_1 = require("ng-morph");
5
+ const TAIGA_TS_CONFIG_PATH = 'node_modules/@taiga-ui/tsconfig';
6
+ /**
7
+ * Updates tsconfig.json to include necessary type definitions
8
+ * - Adds `@taiga-ui/tsconfig` to typeRoots
9
+ * - Adds `node` and `ng-dev-mode` to types array
10
+ *
11
+ * This ensures proper type checking and IntelliSense for Taiga UI components
12
+ * and prevents common TypeScript errors related to custom types and ngDevMode.
13
+ */
14
+ function updateTsConfig(tree, options) {
15
+ const tsConfigPath = 'tsconfig.json';
16
+ if (!tree.exists(tsConfigPath)) {
17
+ if (!options['skip-logs']) {
18
+ (0, ng_morph_1.infoLog)(`Could not find ${tsConfigPath}, skipping tsconfig update.`);
19
+ }
20
+ return;
21
+ }
22
+ const content = tree.readText(tsConfigPath);
23
+ let tsConfig;
24
+ try {
25
+ tsConfig = JSON.parse(content);
26
+ }
27
+ catch (e) {
28
+ if (!options['skip-logs']) {
29
+ (0, ng_morph_1.infoLog)(`Error parsing ${tsConfigPath}: ${e instanceof Error ? e.message : e}. Skipping tsconfig update.`);
30
+ }
31
+ return;
32
+ }
33
+ if (!tsConfig.compilerOptions) {
34
+ tsConfig.compilerOptions = {};
35
+ }
36
+ // Track changes for logging
37
+ let changesMade = false;
38
+ const addedTypeRoots = [];
39
+ const addedTypes = [];
40
+ const typeRoots = tsConfig.compilerOptions.typeRoots || ['node_modules/@types'];
41
+ if (!typeRoots.includes(TAIGA_TS_CONFIG_PATH)) {
42
+ typeRoots.push(TAIGA_TS_CONFIG_PATH);
43
+ tsConfig.compilerOptions.typeRoots = typeRoots;
44
+ addedTypeRoots.push(TAIGA_TS_CONFIG_PATH);
45
+ changesMade = true;
46
+ }
47
+ const types = tsConfig.compilerOptions.types || [];
48
+ const requiredTypes = ['node', 'ng-dev-mode'];
49
+ const missingTypes = requiredTypes.filter((type) => !types.includes(type));
50
+ if (missingTypes.length > 0) {
51
+ missingTypes.forEach((type) => {
52
+ types.push(type);
53
+ addedTypes.push(type);
54
+ });
55
+ tsConfig.compilerOptions.types = types;
56
+ changesMade = true;
57
+ }
58
+ // Save changes if any modifications were made
59
+ if (changesMade) {
60
+ tree.overwrite(tsConfigPath, `${JSON.stringify(tsConfig, null, 2)}\n`);
61
+ if (!options['skip-logs']) {
62
+ if (addedTypeRoots.length > 0) {
63
+ (0, ng_morph_1.infoLog)(`Added to typeRoots: ${addedTypeRoots.join(', ')}`);
64
+ }
65
+ if (addedTypes.length > 0) {
66
+ (0, ng_morph_1.infoLog)(`Added to types: ${addedTypes.join(', ')}`);
67
+ }
68
+ (0, ng_morph_1.infoLog)(`Updated ${tsConfigPath} successfully`);
69
+ }
70
+ }
71
+ else if (!options['skip-logs']) {
72
+ (0, ng_morph_1.infoLog)(`No changes needed in ${tsConfigPath}, configuration already complete`);
73
+ }
74
+ }
75
+ exports.updateTsConfig = updateTsConfig;
@@ -0,0 +1 @@
1
+ export declare function runMigration(before: string): Promise<string>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runMigration = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_path_1 = require("node:path");
6
+ const schematics_1 = require("@angular-devkit/schematics");
7
+ const testing_1 = require("@angular-devkit/schematics/testing");
8
+ const ng_morph_1 = require("ng-morph");
9
+ const collectionPath = (0, node_path_1.join)(__dirname, '../../../../migration.json');
10
+ function runMigration(before) {
11
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
+ const host = new testing_1.UnitTestTree(new schematics_1.HostTree());
13
+ const runner = new testing_1.SchematicTestRunner('schematics', collectionPath);
14
+ (0, ng_morph_1.setActiveProject)((0, ng_morph_1.createProject)(host));
15
+ (0, ng_morph_1.createSourceFile)('test/app/tokens.ts', before);
16
+ (0, ng_morph_1.createSourceFile)('package.json', '{}');
17
+ (0, ng_morph_1.saveActiveProject)();
18
+ const tree = yield runner.runSchematic('updateToV5', { 'skip-logs': process.env['TUI_CI'] === 'true' }, host);
19
+ return tree.readContent('test/app/tokens.ts');
20
+ });
21
+ }
22
+ exports.runMigration = runMigration;
@@ -1 +1 @@
1
- export declare function tuiRetargetedBoundaryCrossing(event: any): boolean;
1
+ export declare function tuiRetargetedBoundaryCrossing(event: Event): boolean;