@taiga-ui/cdk 2.49.0 → 2.49.1

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 (60) hide show
  1. package/bundles/taiga-ui-cdk-classes.umd.js.map +1 -1
  2. package/bundles/taiga-ui-cdk-classes.umd.min.js.map +1 -1
  3. package/bundles/taiga-ui-cdk-components-alert-host.umd.js.map +1 -1
  4. package/bundles/taiga-ui-cdk-components-alert-host.umd.min.js.map +1 -1
  5. package/bundles/taiga-ui-cdk-constants.umd.js +1 -1
  6. package/bundles/taiga-ui-cdk-constants.umd.js.map +1 -1
  7. package/bundles/taiga-ui-cdk-constants.umd.min.js.map +1 -1
  8. package/bundles/taiga-ui-cdk-directives-let.umd.js.map +1 -1
  9. package/bundles/taiga-ui-cdk-directives-let.umd.min.js.map +1 -1
  10. package/bundles/taiga-ui-cdk-observables.umd.js.map +1 -1
  11. package/bundles/taiga-ui-cdk-observables.umd.min.js.map +1 -1
  12. package/classes/validation-error.d.ts +1 -1
  13. package/components/alert-host/alert-host.component.d.ts +1 -1
  14. package/constants/stringify.d.ts +1 -1
  15. package/constants/taiga-ui-cdk-constants.metadata.json +1 -1
  16. package/directives/let/let.directive.d.ts +1 -1
  17. package/esm2015/classes/validation-error.js +1 -1
  18. package/esm2015/components/alert-host/alert-host.component.js +1 -1
  19. package/esm2015/constants/stringify.js +1 -1
  20. package/esm2015/constants/unicode-chars.js +2 -2
  21. package/esm2015/directives/let/let.directive.js +1 -1
  22. package/esm2015/observables/is-alive.js +1 -1
  23. package/esm5/classes/validation-error.js +1 -1
  24. package/esm5/components/alert-host/alert-host.component.js +1 -1
  25. package/esm5/constants/stringify.js +1 -1
  26. package/esm5/constants/unicode-chars.js +2 -2
  27. package/esm5/directives/let/let.directive.js +1 -1
  28. package/esm5/observables/is-alive.js +1 -1
  29. package/fesm2015/taiga-ui-cdk-classes.js.map +1 -1
  30. package/fesm2015/taiga-ui-cdk-components-alert-host.js.map +1 -1
  31. package/fesm2015/taiga-ui-cdk-constants.js +1 -1
  32. package/fesm2015/taiga-ui-cdk-constants.js.map +1 -1
  33. package/fesm2015/taiga-ui-cdk-directives-let.js.map +1 -1
  34. package/fesm2015/taiga-ui-cdk-observables.js.map +1 -1
  35. package/fesm5/taiga-ui-cdk-classes.js.map +1 -1
  36. package/fesm5/taiga-ui-cdk-components-alert-host.js.map +1 -1
  37. package/fesm5/taiga-ui-cdk-constants.js +1 -1
  38. package/fesm5/taiga-ui-cdk-constants.js.map +1 -1
  39. package/fesm5/taiga-ui-cdk-directives-let.js.map +1 -1
  40. package/fesm5/taiga-ui-cdk-observables.js.map +1 -1
  41. package/observables/is-alive.d.ts +1 -1
  42. package/package.json +1 -4
  43. package/schematics/ng-update/constants/consts.js +11 -0
  44. package/schematics/ng-update/constants/modules.d.ts +6 -0
  45. package/schematics/ng-update/constants/modules.js +5 -0
  46. package/schematics/ng-update/constants/templates.d.ts +10 -0
  47. package/schematics/ng-update/constants/templates.js +30 -0
  48. package/schematics/ng-update/constants/tui-interactive-selectors.d.ts +1 -0
  49. package/schematics/ng-update/constants/tui-interactive-selectors.js +54 -0
  50. package/schematics/ng-update/constants/warnings.js +35 -0
  51. package/schematics/ng-update/index.js +2 -0
  52. package/schematics/ng-update/steps/migrate-templates.js +26 -16
  53. package/schematics/ng-update/steps/remove-module.d.ts +2 -0
  54. package/schematics/ng-update/steps/remove-module.js +24 -0
  55. package/schematics/ng-update/steps/replace-const.js +2 -2
  56. package/schematics/utils/add-unique-import.js +1 -1
  57. package/schematics/utils/templates/elements.d.ts +17 -0
  58. package/schematics/utils/templates/elements.js +55 -0
  59. package/schematics/utils/templates/ng-component-input-manipulations.d.ts +2 -2
  60. package/schematics/utils/templates/ng-component-input-manipulations.js +12 -7
@@ -2,42 +2,52 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const get_component_templates_1 = require("../../utils/templates/get-component-templates");
4
4
  const templates_1 = require("../constants/templates");
5
- const schematics_1 = require("@angular/cdk/schematics");
6
5
  const elements_1 = require("../../utils/templates/elements");
7
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");
8
9
  const START_TAG_OFFSET = 1;
9
10
  const END_TAG_OFFSET = 2;
10
11
  function migrateTemplates(tree) {
11
12
  const templateResources = get_component_templates_1.getComponentTemplates('**/**');
12
13
  const fileSystem = new devkit_file_system_1.DevkitFileSystem(tree);
13
14
  templateResources.forEach((resource) => {
14
- if ('template' in resource) {
15
- const template = resource.template;
16
- const path = fileSystem.resolve(resource.componentPath);
17
- const recorder = fileSystem.edit(path);
18
- processTemplateUrl(template, recorder, resource.offset);
19
- }
20
- else {
21
- const path = fileSystem.resolve(resource.templatePath);
22
- const template = fileSystem.read(path);
23
- const recorder = fileSystem.edit(path);
24
- processTemplateUrl(template, recorder);
25
- }
15
+ const path = fileSystem.resolve(template_resource_1.getPathFromTemplateResource(resource));
16
+ const template = template_resource_1.getTemplateFromTemplateResource(resource, fileSystem);
17
+ const recorder = fileSystem.edit(path);
18
+ const offset = template_resource_1.getTemplateOffset(resource);
19
+ replaceTags(template, recorder, offset);
20
+ replaceAttrs(template, recorder, offset);
21
+ replaceAttrsByDirective(fileSystem, resource);
26
22
  fileSystem.commitEdits();
27
23
  });
28
24
  }
29
25
  exports.migrateTemplates = migrateTemplates;
30
- function processTemplateUrl(template, recorder, templateOffset = 0) {
26
+ function replaceAttrsByDirective(fileSystem, templateResource) {
27
+ templates_1.ATTR_TO_DIRECTIVE.forEach(({ componentSelector, directiveModule, directive, inputProperty }) => {
28
+ ng_component_input_manipulations_1.replaceInputPropertyByDirective({
29
+ componentSelector,
30
+ directiveModule,
31
+ directive,
32
+ inputProperty,
33
+ fileSystem,
34
+ templateResource,
35
+ });
36
+ });
37
+ }
38
+ function replaceAttrs(template, recorder, templateOffset = 0) {
31
39
  templates_1.ATTRS_TO_REPLACE.forEach(({ from, to }) => {
32
40
  const offsets = [
33
- ...schematics_1.findAttributeOnElementWithTag(template, from.attrName, from.withTagNames || []),
34
- ...schematics_1.findAttributeOnElementWithAttrs(template, from.attrName, from.withAttrsNames || []),
41
+ ...elements_1.findAttributeOnElementWithTag(template, from.attrName, from.withTagNames || []),
42
+ ...elements_1.findAttributeOnElementWithAttrs(template, from.attrName, from.withAttrsNames || []),
35
43
  ];
36
44
  offsets.forEach(offset => {
37
45
  recorder.remove(offset + templateOffset, from.attrName.length + (to.attrName.length ? 0 : 1));
38
46
  recorder.insertRight(offset + templateOffset, to.attrName);
39
47
  });
40
48
  });
49
+ }
50
+ function replaceTags(template, recorder, templateOffset = 0) {
41
51
  templates_1.TAGS_TO_REPLACE.forEach(({ from, to, addAttributes }) => {
42
52
  const elements = elements_1.findElementsByTagName(template, from);
43
53
  elements.forEach(({ sourceCodeLocation }) => {
@@ -0,0 +1,2 @@
1
+ export declare function removeModules(): void;
2
+ export declare function removeModule(name: string, moduleSpecifier: string): void;
@@ -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
- for (let ref of references) {
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;
@@ -1,2 +1,19 @@
1
1
  import { Element } from 'parse5';
2
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[]): 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[]): number[];
18
+ /** Gets the start offset of the given attribute from a Parse5 element. */
19
+ export declare function getStartOffsetOfAttribute(element: Element, attributeName: string): number;
@@ -19,3 +19,58 @@ function findElementsByTagName(html, tagName) {
19
19
  return elements;
20
20
  }
21
21
  exports.findElementsByTagName = findElementsByTagName;
22
+ /**
23
+ * Parses a HTML fragment and traverses all AST nodes in order find elements that
24
+ * include the specified attribute.
25
+ */
26
+ function findElementsWithAttribute(html, attributeName) {
27
+ const document = parse5_1.parseFragment(html, { sourceCodeLocationInfo: true });
28
+ const elements = [];
29
+ const visitNodes = (nodes) => {
30
+ nodes.forEach(n => {
31
+ var _a;
32
+ const node = n;
33
+ if (node.childNodes) {
34
+ visitNodes(node.childNodes);
35
+ }
36
+ if ((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.some(attr => attr.name === attributeName.toLowerCase())) {
37
+ elements.push(node);
38
+ }
39
+ });
40
+ };
41
+ visitNodes(document.childNodes);
42
+ return elements;
43
+ }
44
+ exports.findElementsWithAttribute = findElementsWithAttribute;
45
+ /**
46
+ * Finds elements with explicit tag names that also contain the specified attribute. Returns the
47
+ * attribute start offset based on the specified HTML.
48
+ */
49
+ function findAttributeOnElementWithTag(html, name, tagNames) {
50
+ return findElementsWithAttribute(html, name)
51
+ .filter(element => tagNames.includes(element.tagName))
52
+ .map(element => getStartOffsetOfAttribute(element, name));
53
+ }
54
+ exports.findAttributeOnElementWithTag = findAttributeOnElementWithTag;
55
+ /**
56
+ * Finds elements that contain the given attribute and contain at least one of the other
57
+ * specified attributes. Returns the primary attribute's start offset based on the specified HTML.
58
+ */
59
+ function findAttributeOnElementWithAttrs(html, name, attrs) {
60
+ return findElementsWithAttribute(html, name)
61
+ .filter(element => attrs.some(attr => hasElementAttribute(element, attr)))
62
+ .map(element => getStartOffsetOfAttribute(element, name));
63
+ }
64
+ exports.findAttributeOnElementWithAttrs = findAttributeOnElementWithAttrs;
65
+ /** Shorthand function that checks if the specified element contains the given attribute. */
66
+ function hasElementAttribute(element, attributeName) {
67
+ return (element.attrs &&
68
+ element.attrs.some(attr => attr.name === attributeName.toLowerCase()));
69
+ }
70
+ /** Gets the start offset of the given attribute from a Parse5 element. */
71
+ function getStartOffsetOfAttribute(element, attributeName) {
72
+ var _a, _b;
73
+ 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)) ||
74
+ 0);
75
+ }
76
+ exports.getStartOffsetOfAttribute = getStartOffsetOfAttribute;
@@ -28,14 +28,14 @@ import { TemplateResource } from '../../ng-update/interfaces/template-resourse';
28
28
  export declare function replaceInputProperty({ templateResource, fileSystem, componentSelector, from, to, }: {
29
29
  templateResource: TemplateResource;
30
30
  fileSystem: DevkitFileSystem;
31
- componentSelector: string;
31
+ componentSelector: string | string[];
32
32
  from: string;
33
33
  to: string;
34
34
  }): boolean;
35
35
  export declare function replaceInputPropertyByDirective({ templateResource, fileSystem, componentSelector, inputProperty, directive, directiveModule, }: {
36
36
  templateResource: TemplateResource;
37
37
  fileSystem: DevkitFileSystem;
38
- componentSelector: string;
38
+ componentSelector: string | string[];
39
39
  inputProperty: string;
40
40
  directive: string;
41
41
  directiveModule?: {
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const schematics_1 = require("@angular/cdk/schematics");
4
3
  const template_resource_1 = require("./template-resource");
5
4
  const ng_component_1 = require("../angular/ng-component");
6
5
  const ng_module_1 = require("../angular/ng-module");
7
6
  const ng_morph_1 = require("ng-morph");
8
7
  const add_unique_import_1 = require("../add-unique-import");
8
+ const elements_1 = require("./elements");
9
9
  /**
10
10
  * Replace component input property by new value
11
11
  * ___
@@ -36,12 +36,17 @@ function replaceInputProperty({ templateResource, fileSystem, componentSelector,
36
36
  const path = fileSystem.resolve(template_resource_1.getPathFromTemplateResource(templateResource));
37
37
  const recorder = fileSystem.edit(path);
38
38
  const templateOffset = template_resource_1.getTemplateOffset(templateResource);
39
- const stringProperties = schematics_1.findAttributeOnElementWithTag(template, from, [
40
- componentSelector,
41
- ]);
42
- const propertyBindings = schematics_1.findAttributeOnElementWithTag(template, `[${from}]`, [
43
- componentSelector,
44
- ]);
39
+ const selector = Array.isArray(componentSelector)
40
+ ? componentSelector
41
+ : [componentSelector];
42
+ const stringProperties = [
43
+ ...elements_1.findAttributeOnElementWithTag(template, from, selector),
44
+ ...elements_1.findAttributeOnElementWithAttrs(template, from, selector),
45
+ ];
46
+ const propertyBindings = [
47
+ ...elements_1.findAttributeOnElementWithTag(template, `[${from}]`, selector),
48
+ ...elements_1.findAttributeOnElementWithAttrs(template, `[${from}]`, selector),
49
+ ];
45
50
  if (!stringProperties.length && !propertyBindings.length) {
46
51
  return false;
47
52
  }