@taiga-ui/cdk 4.1.0 → 4.3.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.
Files changed (65) hide show
  1. package/classes/control.d.ts +2 -1
  2. package/constants/version.d.ts +1 -1
  3. package/constants/version.js +1 -1
  4. package/directives/platform/platform.directive.d.ts +1 -1
  5. package/esm2022/classes/control.mjs +9 -11
  6. package/esm2022/constants/version.mjs +2 -2
  7. package/esm2022/directives/copy-processor/copy-processor.directive.mjs +5 -5
  8. package/esm2022/directives/focus-trap/focus-trap.directive.mjs +4 -6
  9. package/esm2022/directives/media/media.directive.mjs +14 -28
  10. package/esm2022/directives/native-validator/native-validator.directive.mjs +5 -5
  11. package/esm2022/directives/platform/platform.directive.mjs +7 -9
  12. package/esm2022/directives/resizer/resizer.directive.mjs +10 -16
  13. package/esm2022/observables/control-value.mjs +2 -13
  14. package/esm2022/tokens/fallback-value.mjs +3 -3
  15. package/esm2022/utils/miscellaneous/count-filled-controls.mjs +13 -0
  16. package/esm2022/utils/miscellaneous/index.mjs +3 -1
  17. package/esm2022/utils/miscellaneous/is-control-empty.mjs +4 -0
  18. package/fesm2022/taiga-ui-cdk-classes.mjs +9 -11
  19. package/fesm2022/taiga-ui-cdk-classes.mjs.map +1 -1
  20. package/fesm2022/taiga-ui-cdk-constants.mjs +1 -1
  21. package/fesm2022/taiga-ui-cdk-constants.mjs.map +1 -1
  22. package/fesm2022/taiga-ui-cdk-directives-copy-processor.mjs +4 -4
  23. package/fesm2022/taiga-ui-cdk-directives-copy-processor.mjs.map +1 -1
  24. package/fesm2022/taiga-ui-cdk-directives-focus-trap.mjs +3 -5
  25. package/fesm2022/taiga-ui-cdk-directives-focus-trap.mjs.map +1 -1
  26. package/fesm2022/taiga-ui-cdk-directives-media.mjs +13 -27
  27. package/fesm2022/taiga-ui-cdk-directives-media.mjs.map +1 -1
  28. package/fesm2022/taiga-ui-cdk-directives-native-validator.mjs +4 -4
  29. package/fesm2022/taiga-ui-cdk-directives-native-validator.mjs.map +1 -1
  30. package/fesm2022/taiga-ui-cdk-directives-platform.mjs +6 -8
  31. package/fesm2022/taiga-ui-cdk-directives-platform.mjs.map +1 -1
  32. package/fesm2022/taiga-ui-cdk-directives-resizer.mjs +9 -15
  33. package/fesm2022/taiga-ui-cdk-directives-resizer.mjs.map +1 -1
  34. package/fesm2022/taiga-ui-cdk-observables.mjs +2 -13
  35. package/fesm2022/taiga-ui-cdk-observables.mjs.map +1 -1
  36. package/fesm2022/taiga-ui-cdk-tokens.mjs +3 -2
  37. package/fesm2022/taiga-ui-cdk-tokens.mjs.map +1 -1
  38. package/fesm2022/taiga-ui-cdk-utils-miscellaneous.mjs +17 -2
  39. package/fesm2022/taiga-ui-cdk-utils-miscellaneous.mjs.map +1 -1
  40. package/observables/control-value.d.ts +0 -3
  41. package/package.json +2 -2
  42. package/schematics/ng-add/steps/add-taiga-modules.js +3 -1
  43. package/schematics/ng-add/steps/wrap-with-tui-root.js +11 -7
  44. package/schematics/ng-update/v4/index.js +1 -0
  45. package/schematics/ng-update/v4/steps/constants/html-comments.js +5 -0
  46. package/schematics/ng-update/v4/steps/constants/identifiers-to-replace.js +5 -1
  47. package/schematics/ng-update/v4/steps/index.d.ts +1 -0
  48. package/schematics/ng-update/v4/steps/index.js +1 -0
  49. package/schematics/ng-update/v4/steps/migrate-alert-service.js +7 -9
  50. package/schematics/ng-update/v4/steps/migrate-destroy-service.js +5 -3
  51. package/schematics/ng-update/v4/steps/migrate-templates.js +3 -0
  52. package/schematics/ng-update/v4/steps/remove-duplicates.d.ts +2 -0
  53. package/schematics/ng-update/v4/steps/remove-duplicates.js +41 -0
  54. package/schematics/ng-update/v4/steps/templates/migrate-blocked.js +10 -9
  55. package/schematics/ng-update/v4/steps/templates/migrate-labeled.js +5 -3
  56. package/schematics/ng-update/v4/steps/templates/migrate-money.js +8 -3
  57. package/schematics/ng-update/v4/steps/update-packages.js +1 -1
  58. package/schematics/utils/add-import-to-closest-module.d.ts +1 -0
  59. package/schematics/utils/add-import-to-closest-module.js +24 -17
  60. package/schematics/utils/create-angular-json.d.ts +0 -1
  61. package/schematics/utils/create-angular-json.js +1 -27
  62. package/tokens/fallback-value.d.ts +1 -2
  63. package/utils/miscellaneous/count-filled-controls.d.ts +2 -0
  64. package/utils/miscellaneous/index.d.ts +2 -0
  65. package/utils/miscellaneous/is-control-empty.d.ts +2 -0
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeDuplicates = void 0;
4
+ const ng_morph_1 = require("ng-morph");
5
+ const constants_1 = require("../../../constants");
6
+ const colored_log_1 = require("../../../utils/colored-log");
7
+ function removeDuplicates(options) {
8
+ !options['skip-logs'] &&
9
+ (0, colored_log_1.infoLog)(`${colored_log_1.SMALL_TAB_SYMBOL}${colored_log_1.REPLACE_SYMBOL} removing duplicates...`);
10
+ const classes = (0, ng_morph_1.getClasses)(constants_1.ALL_TS_FILES);
11
+ const modules = (0, ng_morph_1.getDecorators)(classes, { name: 'NgModule' });
12
+ const components = (0, ng_morph_1.getDecorators)(classes, { name: 'Component' });
13
+ [...modules, ...components].forEach((decorator) => {
14
+ const [metadata] = decorator.getArguments();
15
+ if (!metadata || !ng_morph_1.Node.isObjectLiteralExpression(metadata)) {
16
+ return;
17
+ }
18
+ const property = metadata.getProperty('imports');
19
+ if (!ng_morph_1.Node.isPropertyAssignment(property)) {
20
+ return;
21
+ }
22
+ const importsInitializer = property.getInitializer();
23
+ if (!importsInitializer || !ng_morph_1.Node.isArrayLiteralExpression(importsInitializer)) {
24
+ return;
25
+ }
26
+ const indexToRemove = [];
27
+ const existingImports = new Set();
28
+ importsInitializer.getElements().forEach((el, index) => {
29
+ if (existingImports.has(el.getText())) {
30
+ indexToRemove.push(index);
31
+ }
32
+ else {
33
+ existingImports.add(el.getText());
34
+ }
35
+ });
36
+ indexToRemove.forEach((index) => importsInitializer.removeElement(index));
37
+ });
38
+ !options['skip-logs'] &&
39
+ (0, colored_log_1.successLog)(`${colored_log_1.SMALL_TAB_SYMBOL}${colored_log_1.SUCCESS_SYMBOL} duplicates removed \n`);
40
+ }
41
+ exports.removeDuplicates = removeDuplicates;
@@ -20,21 +20,22 @@ function migrateBlocked({ resource, recorder, fileSystem, }) {
20
20
  name.includes('hideRadio'.toLowerCase())) || [];
21
21
  const [, sizeAttrLocation] = Object.entries(sourceCodeLocation.attrs || {}).find(([name]) => name.includes('size')) || [];
22
22
  const [, ngForAttrLocation] = Object.entries(sourceCodeLocation.attrs || {}).find(([name]) => name.includes('*ngfor')) || [];
23
+ const [, contentAlignAttrLocation] = Object.entries(sourceCodeLocation.attrs || {}).find(([name]) => name.includes('contentalign')) || [];
23
24
  const sizeAttr = (0, inputs_1.findAttr)(attrs, 'size');
24
25
  const ngForAttr = (0, inputs_1.findAttr)(attrs, '*ngFor');
25
26
  const newBlockAttr = `tuiBlock${sizeAttr ? `="${sizeAttr.value === 'xs' ? 's' : sizeAttr.value}"` : ''}`;
26
27
  recorder.insertRight(templateOffset + (((_a = sourceCodeLocation.startTag) === null || _a === void 0 ? void 0 : _a.startOffset) || 1) - 1, `<label${ngForAttr ? ` *ngFor="${ngForAttr.value}"` : ''} ${newBlockAttr}${hideIconAttrLocation ? ' appearance=""' : ''}>`);
27
28
  recorder.remove(templateOffset + ((_c = (_b = sourceCodeLocation.endTag) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : 0), `<${tagName}/>`.length);
28
29
  recorder.insertRight(templateOffset + (((_d = sourceCodeLocation.endTag) === null || _d === void 0 ? void 0 : _d.startOffset) || 1), '</label>');
29
- if (hideIconAttrLocation) {
30
- recorder.remove(templateOffset + hideIconAttrLocation.startOffset, hideIconAttrLocation.endOffset - hideIconAttrLocation.startOffset);
31
- }
32
- if (sizeAttrLocation) {
33
- recorder.remove(templateOffset + sizeAttrLocation.startOffset, sizeAttrLocation.endOffset - sizeAttrLocation.startOffset);
34
- }
35
- if (ngForAttrLocation) {
36
- recorder.remove(templateOffset + ngForAttrLocation.startOffset, ngForAttrLocation.endOffset - ngForAttrLocation.startOffset);
37
- }
30
+ const attrsToRemove = [
31
+ hideIconAttrLocation,
32
+ sizeAttrLocation,
33
+ ngForAttrLocation,
34
+ contentAlignAttrLocation,
35
+ ].filter((location) => Boolean(location));
36
+ attrsToRemove.forEach((location) => {
37
+ recorder.remove(templateOffset + location.startOffset, location.endOffset - location.startOffset);
38
+ });
38
39
  });
39
40
  }
40
41
  exports.migrateBlocked = migrateBlocked;
@@ -34,14 +34,16 @@ function migrateLabeled({ resource, recorder, fileSystem, }) {
34
34
  return;
35
35
  }
36
36
  const [, ngForAttrLocation] = Object.entries(sourceCodeLocation.attrs || {}).find(([name]) => name.includes('*ngfor')) || [];
37
+ const [, contentAlignAttrLocation] = Object.entries(sourceCodeLocation.attrs || {}).find(([name]) => name.includes('contentalign')) || [];
37
38
  const ngForAttr = (0, inputs_1.findAttr)(attrs, '*ngFor');
38
39
  (0, add_import_to_closest_module_1.addImportToClosestModule)(resource.componentPath, tagName === 'tui-checkbox-labeled' ? 'TuiCheckbox' : 'TuiRadio', '@taiga-ui/kit');
39
40
  recorder.insertRight(templateOffset + (((_a = sourceCodeLocation.startTag) === null || _a === void 0 ? void 0 : _a.startOffset) || 1) - 1, `<label${ngForAttr ? ` *ngFor="${ngForAttr.value}"` : ''} tuiLabel>`);
40
41
  recorder.remove(templateOffset + ((_c = (_b = sourceCodeLocation.endTag) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : 0), `<${tagName}/>`.length);
41
42
  recorder.insertRight(templateOffset + (((_d = sourceCodeLocation.endTag) === null || _d === void 0 ? void 0 : _d.startOffset) || 1), '</label>');
42
- if (ngForAttrLocation) {
43
- recorder.remove(templateOffset + ngForAttrLocation.startOffset, ngForAttrLocation.endOffset - ngForAttrLocation.startOffset);
44
- }
43
+ const attrsToRemove = [ngForAttrLocation, contentAlignAttrLocation].filter((location) => Boolean(location));
44
+ attrsToRemove.forEach((location) => {
45
+ recorder.remove(templateOffset + location.startOffset, location.endOffset - location.startOffset);
46
+ });
45
47
  });
46
48
  }
47
49
  exports.migrateLabeled = migrateLabeled;
@@ -12,7 +12,7 @@ function migrateMoney({ resource, recorder, fileSystem, }) {
12
12
  const templateOffset = (0, template_resource_1.getTemplateOffset)(resource);
13
13
  const elements = (0, elements_1.findElementsByTagName)(template, 'tui-money');
14
14
  elements.forEach(({ attrs, sourceCodeLocation }) => {
15
- var _a, _b, _c;
15
+ var _a, _b, _c, _d, _e;
16
16
  if (!sourceCodeLocation) {
17
17
  return;
18
18
  }
@@ -21,15 +21,16 @@ function migrateMoney({ resource, recorder, fileSystem, }) {
21
21
  const decimalAttr = (0, inputs_1.findAttr)(attrs, 'decimal');
22
22
  const precisionAttr = (0, inputs_1.findAttr)(attrs, 'precision');
23
23
  const signAttr = (0, inputs_1.findAttr)(attrs, 'sign');
24
+ const selfClosing = !(sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.endTag);
24
25
  if (!valueAttr) {
25
26
  return;
26
27
  }
27
- const insertTo = (_b = (_a = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.endTag) === null || _a === void 0 ? void 0 : _a.startOffset) !== null && _b !== void 0 ? _b : 0;
28
+ const insertTo = (_b = (_a = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag) === null || _a === void 0 ? void 0 : _a.endOffset) !== null && _b !== void 0 ? _b : 0;
28
29
  const value = (0, inputs_1.isBinding)(valueAttr) ? valueAttr.value : `'${valueAttr.value}'`;
29
30
  const currency = currencyAttr && (0, inputs_1.isBinding)(currencyAttr)
30
31
  ? currencyAttr === null || currencyAttr === void 0 ? void 0 : currencyAttr.value
31
32
  : `'${currencyAttr === null || currencyAttr === void 0 ? void 0 : currencyAttr.value}'`;
32
- recorder.insertRight(templateOffset + insertTo, `{{ ${value} | tuiAmount ${currencyAttr ? `: ${currency}` : ': "RUB"'} | async }}`);
33
+ recorder.insertRight(templateOffset + insertTo, `{{ ${value} | tuiAmount ${currencyAttr ? `: ${currency}` : ': "RUB"'} | async }}${selfClosing ? '</span>' : ''}`);
33
34
  if (decimalAttr || precisionAttr) {
34
35
  (0, add_import_to_closest_module_1.addImportToClosestModule)(resource.componentPath, 'TuiNumberFormat', '@taiga-ui/core');
35
36
  const format = JSON.stringify((0, clean_object_1.cleanObject)({
@@ -48,6 +49,10 @@ function migrateMoney({ resource, recorder, fileSystem, }) {
48
49
  signAttr,
49
50
  ].filter((attr) => attr !== undefined);
50
51
  (0, remove_attrs_1.removeAttrs)(attrsToRemove, sourceCodeLocation, recorder, templateOffset);
52
+ if (selfClosing) {
53
+ recorder.remove(templateOffset + ((_e = (_d = sourceCodeLocation.startTag) === null || _d === void 0 ? void 0 : _d.endOffset) !== null && _e !== void 0 ? _e : 2) - 2, 1);
54
+ }
55
+ (0, add_import_to_closest_module_1.addImportToClosestModule)(resource.componentPath, 'AsyncPipe', '@angular/common');
51
56
  });
52
57
  }
53
58
  exports.migrateMoney = migrateMoney;
@@ -24,7 +24,7 @@ function updatePackages({ tree }, _) {
24
24
  }, tree);
25
25
  (0, steps_1.replacePackageName)('@tinkoff/tui-editor', {
26
26
  name: '@taiga-ui/editor',
27
- version: '^2.0.0',
27
+ version: '^2.5.0',
28
28
  }, tree);
29
29
  if (!(0, ng_morph_1.getPackageJsonDependency)(tree, '@taiga-ui/event-plugins')) {
30
30
  (0, ng_morph_1.addPackageJsonDependency)(tree, {
@@ -1 +1,2 @@
1
1
  export declare function addImportToClosestModule(componentPath: string, moduleName: string, moduleSpecifier: string): void;
2
+ export declare function saveAddedImports(): void;
@@ -1,25 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addImportToClosestModule = void 0;
3
+ exports.saveAddedImports = exports.addImportToClosestModule = void 0;
4
4
  const ng_morph_1 = require("ng-morph");
5
5
  const file_globs_1 = require("../constants/file-globs");
6
6
  const add_unique_import_1 = require("./add-unique-import");
7
+ const importsToAdd = [];
7
8
  function addImportToClosestModule(componentPath, moduleName, moduleSpecifier) {
8
- const [ngComponent] = (0, ng_morph_1.getNgComponents)(componentPath);
9
- if (!ngComponent) {
10
- return;
11
- }
12
- if ((0, ng_morph_1.isStandaloneComponent)(ngComponent)) {
13
- (0, ng_morph_1.addImportToComponent)(ngComponent, moduleName, { unique: true });
14
- (0, add_unique_import_1.addUniqueImport)(ngComponent.getSourceFile().getFilePath(), moduleName, moduleSpecifier);
15
- return;
16
- }
17
- const ngModule = (0, ng_morph_1.findNgModule)(ngComponent, file_globs_1.ALL_TS_FILES);
18
- if (ngModule) {
19
- (0, ng_morph_1.addImportToNgModule)(ngModule, moduleName, {
20
- unique: true,
21
- });
22
- (0, add_unique_import_1.addUniqueImport)(ngModule.getSourceFile().getFilePath(), moduleName, moduleSpecifier);
23
- }
9
+ importsToAdd.push({ componentPath, moduleName, moduleSpecifier });
24
10
  }
25
11
  exports.addImportToClosestModule = addImportToClosestModule;
12
+ function saveAddedImports() {
13
+ importsToAdd.forEach(({ componentPath, moduleName, moduleSpecifier }) => {
14
+ const [ngComponent] = (0, ng_morph_1.getNgComponents)(componentPath);
15
+ if (!ngComponent) {
16
+ return;
17
+ }
18
+ if ((0, ng_morph_1.isStandaloneComponent)(ngComponent)) {
19
+ (0, ng_morph_1.addImportToComponent)(ngComponent, moduleName, { unique: true });
20
+ (0, add_unique_import_1.addUniqueImport)(ngComponent.getSourceFile().getFilePath(), moduleName, moduleSpecifier);
21
+ return;
22
+ }
23
+ const ngModule = (0, ng_morph_1.findNgModule)(ngComponent, file_globs_1.ALL_TS_FILES);
24
+ if (ngModule) {
25
+ (0, ng_morph_1.addImportToNgModule)(ngModule, moduleName, {
26
+ unique: true,
27
+ });
28
+ (0, add_unique_import_1.addUniqueImport)(ngModule.getSourceFile().getFilePath(), moduleName, moduleSpecifier);
29
+ }
30
+ });
31
+ }
32
+ exports.saveAddedImports = saveAddedImports;
@@ -1,4 +1,3 @@
1
1
  export declare function createAngularJson({ stylesExist }?: {
2
2
  stylesExist: boolean;
3
3
  }): void;
4
- export declare function createAngularJsonWithAssets(): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAngularJsonWithAssets = exports.createAngularJson = void 0;
3
+ exports.createAngularJson = void 0;
4
4
  const ng_morph_1 = require("ng-morph");
5
5
  function createAngularJson({ stylesExist } = { stylesExist: false }) {
6
6
  (0, ng_morph_1.createSourceFile)('angular.json', `
@@ -27,29 +27,3 @@ function createAngularJson({ stylesExist } = { stylesExist: false }) {
27
27
  }`, { overwrite: true });
28
28
  }
29
29
  exports.createAngularJson = createAngularJson;
30
- function createAngularJsonWithAssets() {
31
- (0, ng_morph_1.createSourceFile)('angular.json', `
32
- {
33
- "version": 1,
34
- "projects": {
35
- "demo": {
36
- "root": "",
37
- "architect": {
38
- "build": {
39
- "options": {
40
- "main": "test/main.ts",
41
- "assets": [
42
- {
43
- "glob": "**/*",
44
- "input": "node_modules/@taiga-ui/icons/src",
45
- "output": "assets/taiga-ui/icons"
46
- }
47
- ]
48
- }
49
- }
50
- }
51
- }
52
- }
53
- }`, { overwrite: true });
54
- }
55
- exports.createAngularJsonWithAssets = createAngularJsonWithAssets;
@@ -1,4 +1,3 @@
1
1
  import type { ValueProvider } from '@angular/core';
2
- import { InjectionToken } from '@angular/core';
3
- export declare const TUI_FALLBACK_VALUE: InjectionToken<unknown>;
2
+ export declare const TUI_FALLBACK_VALUE: import("@angular/core").InjectionToken<any>;
4
3
  export declare function tuiFallbackValueProvider<T>(useValue: T): ValueProvider;
@@ -0,0 +1,2 @@
1
+ import type { AbstractControl } from '@angular/forms';
2
+ export declare function tuiCountFilledControls(control: AbstractControl): number;
@@ -2,6 +2,7 @@ export * from './array-remove';
2
2
  export * from './array-shallow-equals';
3
3
  export * from './array-toggle';
4
4
  export * from './change-date-separator';
5
+ export * from './count-filled-controls';
5
6
  export * from './create-token';
6
7
  export * from './default-sort';
7
8
  export * from './directive-binding';
@@ -10,6 +11,7 @@ export * from './distance-between-touches';
10
11
  export * from './ease-in-out-quad';
11
12
  export * from './flat-length';
12
13
  export * from './get-original-array-from-query-list';
14
+ export * from './is-control-empty';
13
15
  export * from './is-falsy';
14
16
  export * from './is-number';
15
17
  export * from './is-object';
@@ -0,0 +1,2 @@
1
+ import type { AbstractControl } from '@angular/forms';
2
+ export declare function tuiIsControlEmpty({ value }: AbstractControl): boolean;