@taiga-ui/cdk 2.47.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 (182) hide show
  1. package/abstract/controller.d.ts +6 -0
  2. package/abstract/taiga-ui-cdk-abstract.metadata.json +1 -1
  3. package/bundles/taiga-ui-cdk-abstract.umd.js +12 -0
  4. package/bundles/taiga-ui-cdk-abstract.umd.js.map +1 -1
  5. package/bundles/taiga-ui-cdk-abstract.umd.min.js +1 -1
  6. package/bundles/taiga-ui-cdk-abstract.umd.min.js.map +1 -1
  7. package/bundles/taiga-ui-cdk-classes.umd.js.map +1 -1
  8. package/bundles/taiga-ui-cdk-classes.umd.min.js.map +1 -1
  9. package/bundles/taiga-ui-cdk-components-alert-host.umd.js.map +1 -1
  10. package/bundles/taiga-ui-cdk-components-alert-host.umd.min.js.map +1 -1
  11. package/bundles/taiga-ui-cdk-constants.umd.js +29 -2
  12. package/bundles/taiga-ui-cdk-constants.umd.js.map +1 -1
  13. package/bundles/taiga-ui-cdk-constants.umd.min.js +1 -1
  14. package/bundles/taiga-ui-cdk-constants.umd.min.js.map +1 -1
  15. package/bundles/taiga-ui-cdk-directives-auto-focus.umd.js +96 -35
  16. package/bundles/taiga-ui-cdk-directives-auto-focus.umd.js.map +1 -1
  17. package/bundles/taiga-ui-cdk-directives-auto-focus.umd.min.js +1 -1
  18. package/bundles/taiga-ui-cdk-directives-auto-focus.umd.min.js.map +1 -1
  19. package/bundles/taiga-ui-cdk-directives-for-async.umd.js +5 -4
  20. package/bundles/taiga-ui-cdk-directives-for-async.umd.js.map +1 -1
  21. package/bundles/taiga-ui-cdk-directives-for-async.umd.min.js +1 -1
  22. package/bundles/taiga-ui-cdk-directives-for-async.umd.min.js.map +1 -1
  23. package/bundles/taiga-ui-cdk-directives-let.umd.js.map +1 -1
  24. package/bundles/taiga-ui-cdk-directives-let.umd.min.js.map +1 -1
  25. package/bundles/taiga-ui-cdk-enums.umd.js +12 -0
  26. package/bundles/taiga-ui-cdk-enums.umd.js.map +1 -1
  27. package/bundles/taiga-ui-cdk-enums.umd.min.js +1 -1
  28. package/bundles/taiga-ui-cdk-enums.umd.min.js.map +1 -1
  29. package/bundles/taiga-ui-cdk-observables.umd.js.map +1 -1
  30. package/bundles/taiga-ui-cdk-observables.umd.min.js.map +1 -1
  31. package/bundles/taiga-ui-cdk-tokens.umd.js +18 -0
  32. package/bundles/taiga-ui-cdk-tokens.umd.js.map +1 -1
  33. package/bundles/taiga-ui-cdk-tokens.umd.min.js +1 -1
  34. package/bundles/taiga-ui-cdk-tokens.umd.min.js.map +1 -1
  35. package/bundles/taiga-ui-cdk-utils-browser.umd.js +2 -2
  36. package/bundles/taiga-ui-cdk-utils-browser.umd.js.map +1 -1
  37. package/bundles/taiga-ui-cdk-utils-browser.umd.min.js +1 -1
  38. package/bundles/taiga-ui-cdk-utils-browser.umd.min.js.map +1 -1
  39. package/bundles/taiga-ui-cdk-utils-focus.umd.js +1 -1
  40. package/bundles/taiga-ui-cdk-utils-focus.umd.js.map +1 -1
  41. package/bundles/taiga-ui-cdk-utils-focus.umd.min.js +1 -1
  42. package/bundles/taiga-ui-cdk-utils-focus.umd.min.js.map +1 -1
  43. package/classes/validation-error.d.ts +1 -1
  44. package/components/alert-host/alert-host.component.d.ts +1 -1
  45. package/constants/stringify.d.ts +1 -1
  46. package/constants/taiga-ui-cdk-constants.metadata.json +1 -1
  47. package/constants/unicode-chars.d.ts +25 -1
  48. package/directives/auto-focus/autofocus.options.d.ts +1 -1
  49. package/directives/auto-focus/handlers/ios.handler.d.ts +26 -1
  50. package/directives/auto-focus/taiga-ui-cdk-directives-auto-focus.metadata.json +1 -1
  51. package/directives/let/let.directive.d.ts +1 -1
  52. package/enums/autocomplete.d.ts +10 -0
  53. package/enums/taiga-ui-cdk-enums.metadata.json +1 -1
  54. package/esm2015/abstract/controller.js +7 -1
  55. package/esm2015/classes/validation-error.js +1 -1
  56. package/esm2015/components/alert-host/alert-host.component.js +1 -1
  57. package/esm2015/constants/stringify.js +1 -1
  58. package/esm2015/constants/unicode-chars.js +27 -3
  59. package/esm2015/directives/auto-focus/autofocus.options.js +7 -6
  60. package/esm2015/directives/auto-focus/handlers/ios.handler.js +80 -29
  61. package/esm2015/directives/for-async/for-async.directive.js +5 -5
  62. package/esm2015/directives/let/let.directive.js +1 -1
  63. package/esm2015/enums/autocomplete.js +12 -1
  64. package/esm2015/observables/is-alive.js +1 -1
  65. package/esm2015/tokens/index.js +4 -1
  66. package/esm2015/tokens/is-chromium.js +6 -0
  67. package/esm2015/tokens/is-firefox.js +9 -0
  68. package/esm2015/tokens/is-webkit.js +6 -0
  69. package/esm2015/utils/browser/is-edge-older-than.js +2 -2
  70. package/esm2015/utils/browser/is-safari.js +2 -2
  71. package/esm2015/utils/focus/get-native-focused.js +2 -2
  72. package/esm5/abstract/controller.js +14 -1
  73. package/esm5/classes/validation-error.js +1 -1
  74. package/esm5/components/alert-host/alert-host.component.js +1 -1
  75. package/esm5/constants/stringify.js +1 -1
  76. package/esm5/constants/unicode-chars.js +27 -3
  77. package/esm5/directives/auto-focus/autofocus.options.js +7 -6
  78. package/esm5/directives/auto-focus/handlers/ios.handler.js +92 -30
  79. package/esm5/directives/for-async/for-async.directive.js +7 -6
  80. package/esm5/directives/let/let.directive.js +1 -1
  81. package/esm5/enums/autocomplete.js +12 -1
  82. package/esm5/observables/is-alive.js +1 -1
  83. package/esm5/tokens/index.js +4 -1
  84. package/esm5/tokens/is-chromium.js +6 -0
  85. package/esm5/tokens/is-firefox.js +9 -0
  86. package/esm5/tokens/is-webkit.js +6 -0
  87. package/esm5/utils/browser/is-edge-older-than.js +2 -2
  88. package/esm5/utils/browser/is-safari.js +2 -2
  89. package/esm5/utils/focus/get-native-focused.js +2 -2
  90. package/fesm2015/taiga-ui-cdk-abstract.js +7 -1
  91. package/fesm2015/taiga-ui-cdk-abstract.js.map +1 -1
  92. package/fesm2015/taiga-ui-cdk-classes.js.map +1 -1
  93. package/fesm2015/taiga-ui-cdk-components-alert-host.js.map +1 -1
  94. package/fesm2015/taiga-ui-cdk-constants.js +27 -3
  95. package/fesm2015/taiga-ui-cdk-constants.js.map +1 -1
  96. package/fesm2015/taiga-ui-cdk-directives-auto-focus.js +84 -33
  97. package/fesm2015/taiga-ui-cdk-directives-auto-focus.js.map +1 -1
  98. package/fesm2015/taiga-ui-cdk-directives-for-async.js +4 -4
  99. package/fesm2015/taiga-ui-cdk-directives-for-async.js.map +1 -1
  100. package/fesm2015/taiga-ui-cdk-directives-let.js.map +1 -1
  101. package/fesm2015/taiga-ui-cdk-enums.js +11 -0
  102. package/fesm2015/taiga-ui-cdk-enums.js.map +1 -1
  103. package/fesm2015/taiga-ui-cdk-observables.js.map +1 -1
  104. package/fesm2015/taiga-ui-cdk-tokens.js +16 -1
  105. package/fesm2015/taiga-ui-cdk-tokens.js.map +1 -1
  106. package/fesm2015/taiga-ui-cdk-utils-browser.js +2 -2
  107. package/fesm2015/taiga-ui-cdk-utils-browser.js.map +1 -1
  108. package/fesm2015/taiga-ui-cdk-utils-focus.js +1 -1
  109. package/fesm2015/taiga-ui-cdk-utils-focus.js.map +1 -1
  110. package/fesm5/taiga-ui-cdk-abstract.js +12 -1
  111. package/fesm5/taiga-ui-cdk-abstract.js.map +1 -1
  112. package/fesm5/taiga-ui-cdk-classes.js.map +1 -1
  113. package/fesm5/taiga-ui-cdk-components-alert-host.js.map +1 -1
  114. package/fesm5/taiga-ui-cdk-constants.js +27 -3
  115. package/fesm5/taiga-ui-cdk-constants.js.map +1 -1
  116. package/fesm5/taiga-ui-cdk-directives-auto-focus.js +96 -34
  117. package/fesm5/taiga-ui-cdk-directives-auto-focus.js.map +1 -1
  118. package/fesm5/taiga-ui-cdk-directives-for-async.js +6 -5
  119. package/fesm5/taiga-ui-cdk-directives-for-async.js.map +1 -1
  120. package/fesm5/taiga-ui-cdk-directives-let.js.map +1 -1
  121. package/fesm5/taiga-ui-cdk-enums.js +11 -0
  122. package/fesm5/taiga-ui-cdk-enums.js.map +1 -1
  123. package/fesm5/taiga-ui-cdk-observables.js.map +1 -1
  124. package/fesm5/taiga-ui-cdk-tokens.js +16 -1
  125. package/fesm5/taiga-ui-cdk-tokens.js.map +1 -1
  126. package/fesm5/taiga-ui-cdk-utils-browser.js +2 -2
  127. package/fesm5/taiga-ui-cdk-utils-browser.js.map +1 -1
  128. package/fesm5/taiga-ui-cdk-utils-focus.js +1 -1
  129. package/fesm5/taiga-ui-cdk-utils-focus.js.map +1 -1
  130. package/observables/is-alive.d.ts +1 -1
  131. package/package.json +1 -1
  132. package/schematics/ng-update/constants/consts.js +49 -0
  133. package/schematics/ng-update/constants/enums.js +22 -0
  134. package/schematics/ng-update/constants/modules.d.ts +6 -0
  135. package/schematics/ng-update/constants/modules.js +5 -0
  136. package/schematics/ng-update/constants/services.d.ts +8 -0
  137. package/schematics/ng-update/constants/services.js +43 -0
  138. package/schematics/ng-update/constants/templates.d.ts +27 -0
  139. package/schematics/ng-update/constants/templates.js +74 -0
  140. package/schematics/ng-update/constants/tui-interactive-selectors.d.ts +1 -0
  141. package/schematics/ng-update/constants/tui-interactive-selectors.js +54 -0
  142. package/schematics/ng-update/constants/types.d.ts +1 -0
  143. package/schematics/ng-update/constants/types.js +34 -0
  144. package/schematics/ng-update/constants/warnings.js +72 -0
  145. package/schematics/ng-update/index.js +8 -0
  146. package/schematics/ng-update/interfaces/template-resourse.d.ts +8 -0
  147. package/schematics/ng-update/interfaces/template-resourse.js +2 -0
  148. package/schematics/ng-update/steps/migrate-sliders/index.d.ts +2 -0
  149. package/schematics/ng-update/steps/migrate-sliders/index.js +7 -0
  150. package/schematics/ng-update/steps/migrate-sliders/migrate-input-slider.d.ts +2 -0
  151. package/schematics/ng-update/steps/migrate-sliders/migrate-input-slider.js +24 -0
  152. package/schematics/ng-update/steps/migrate-templates.d.ts +2 -0
  153. package/schematics/ng-update/steps/migrate-templates.js +67 -0
  154. package/schematics/ng-update/steps/remove-module.d.ts +2 -0
  155. package/schematics/ng-update/steps/remove-module.js +24 -0
  156. package/schematics/ng-update/steps/rename-types.js +26 -17
  157. package/schematics/ng-update/steps/replace-const.js +4 -4
  158. package/schematics/ng-update/steps/replace-enums.js +2 -2
  159. package/schematics/ng-update/steps/replace-services.d.ts +1 -0
  160. package/schematics/ng-update/steps/replace-services.js +51 -0
  161. package/schematics/ng-update/steps/show-warnings.js +26 -9
  162. package/schematics/utils/add-unique-import.js +1 -1
  163. package/schematics/utils/angular/ng-component.d.ts +3 -0
  164. package/schematics/utils/angular/ng-component.js +7 -0
  165. package/schematics/utils/angular/ng-module.d.ts +7 -0
  166. package/schematics/utils/angular/ng-module.js +21 -0
  167. package/schematics/utils/{remove-import.d.ts → import-manipulations.d.ts} +1 -0
  168. package/schematics/utils/import-manipulations.js +19 -0
  169. package/schematics/utils/templates/elements.d.ts +19 -0
  170. package/schematics/utils/templates/elements.js +76 -0
  171. package/schematics/utils/templates/get-component-templates.d.ts +4 -0
  172. package/schematics/utils/templates/get-component-templates.js +36 -0
  173. package/schematics/utils/templates/ng-component-input-manipulations.d.ts +45 -0
  174. package/schematics/utils/templates/ng-component-input-manipulations.js +83 -0
  175. package/schematics/utils/templates/template-resource.d.ts +5 -0
  176. package/schematics/utils/templates/template-resource.js +21 -0
  177. package/tokens/index.d.ts +3 -0
  178. package/tokens/is-chromium.d.ts +2 -0
  179. package/tokens/is-firefox.d.ts +2 -0
  180. package/tokens/is-webkit.d.ts +2 -0
  181. package/tokens/taiga-ui-cdk-tokens.metadata.json +1 -1
  182. package/schematics/utils/remove-import.js +0 -11
@@ -0,0 +1,67 @@
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 START_TAG_OFFSET = 1;
10
+ const END_TAG_OFFSET = 2;
11
+ function migrateTemplates(tree) {
12
+ const templateResources = get_component_templates_1.getComponentTemplates('**/**');
13
+ const fileSystem = new devkit_file_system_1.DevkitFileSystem(tree);
14
+ templateResources.forEach((resource) => {
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);
22
+ fileSystem.commitEdits();
23
+ });
24
+ }
25
+ exports.migrateTemplates = migrateTemplates;
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) {
39
+ templates_1.ATTRS_TO_REPLACE.forEach(({ from, to }) => {
40
+ const offsets = [
41
+ ...elements_1.findAttributeOnElementWithTag(template, from.attrName, from.withTagNames || []),
42
+ ...elements_1.findAttributeOnElementWithAttrs(template, from.attrName, from.withAttrsNames || []),
43
+ ];
44
+ offsets.forEach(offset => {
45
+ recorder.remove(offset + templateOffset, from.attrName.length + (to.attrName.length ? 0 : 1));
46
+ recorder.insertRight(offset + templateOffset, to.attrName);
47
+ });
48
+ });
49
+ }
50
+ function replaceTags(template, recorder, templateOffset = 0) {
51
+ templates_1.TAGS_TO_REPLACE.forEach(({ from, to, addAttributes }) => {
52
+ const elements = elements_1.findElementsByTagName(template, from);
53
+ elements.forEach(({ sourceCodeLocation }) => {
54
+ var _a;
55
+ if (sourceCodeLocation) {
56
+ const startTagOffset = sourceCodeLocation.startTag.startOffset;
57
+ const endTagOffset = (_a = sourceCodeLocation.endTag) === null || _a === void 0 ? void 0 : _a.startOffset;
58
+ if (endTagOffset) {
59
+ recorder.remove(endTagOffset + templateOffset + END_TAG_OFFSET, from.length);
60
+ recorder.insertRight(endTagOffset + templateOffset + END_TAG_OFFSET, to);
61
+ }
62
+ recorder.remove(startTagOffset + templateOffset + START_TAG_OFFSET, from.length);
63
+ recorder.insertRight(startTagOffset + templateOffset + START_TAG_OFFSET, `${to} ${addAttributes.join(' ')}`);
64
+ }
65
+ });
66
+ });
67
+ }
@@ -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;
@@ -1,34 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const get_named_import_references_1 = require("../../utils/get-named-import-references");
4
3
  const ng_morph_1 = require("ng-morph");
4
+ const get_named_import_references_1 = require("../../utils/get-named-import-references");
5
5
  const types_1 = require("../constants/types");
6
- const remove_import_1 = require("../../utils/remove-import");
6
+ const import_manipulations_1 = require("../../utils/import-manipulations");
7
7
  function renameTypes() {
8
- types_1.TYPES_TO_RENAME.forEach(({ from, to, moduleSpecifier }) => {
9
- renameType(from, to, moduleSpecifier);
8
+ types_1.TYPES_TO_RENAME.forEach(({ from, to, moduleSpecifier, preserveGenerics }) => {
9
+ renameType(from, to, moduleSpecifier, preserveGenerics);
10
10
  });
11
11
  }
12
12
  exports.renameTypes = renameTypes;
13
- function renameType(from, to, moduleSpecifier) {
13
+ function renameType(from, to, moduleSpecifier, preserveGenerics = false) {
14
14
  const references = get_named_import_references_1.getNamedImportReferences(from, moduleSpecifier);
15
15
  references.forEach(ref => {
16
16
  const parent = ref.getParent();
17
- if (ng_morph_1.Node.isImportSpecifier(parent) && to) {
18
- renameImport(parent, to, from);
19
- }
20
- else if (ng_morph_1.Node.isImportSpecifier(parent) && !to) {
21
- remove_import_1.removeImport(parent);
17
+ if (ng_morph_1.Node.isImportSpecifier(parent)) {
18
+ processImport(parent, from, to);
22
19
  }
23
20
  else if (ng_morph_1.Node.isTypeReferenceNode(parent)) {
24
- parent.replaceWithText(to || 'any');
21
+ const targetType = preserveGenerics && to ? addGeneric(to, parent.getTypeArguments()) : to;
22
+ parent.replaceWithText(targetType || 'any');
25
23
  }
26
24
  });
27
25
  }
28
- function renameImport(specifier, to, from) {
29
- const namedImport = specifier
30
- .getImportDeclaration()
31
- .getNamedImports()
32
- .find(specifier => specifier.getName() === from);
33
- namedImport === null || namedImport === void 0 ? void 0 : namedImport.replaceWithText(to);
26
+ function processImport(node, from, to) {
27
+ const filePath = node.getSourceFile().getFilePath();
28
+ const targetImportAlreadyExists = Boolean(ng_morph_1.getImports(filePath, { namedImports: to }).length);
29
+ if (to && !targetImportAlreadyExists) {
30
+ import_manipulations_1.renameImport(node, removeGeneric(to), removeGeneric(from));
31
+ }
32
+ else {
33
+ import_manipulations_1.removeImport(node);
34
+ }
35
+ }
36
+ function removeGeneric(type) {
37
+ return type.replace(/<.*>$/gi, '');
38
+ }
39
+ function addGeneric(typeName, generics) {
40
+ const typeArgs = generics.map(t => t.getType().getText());
41
+ const genericType = typeArgs.length ? `<${typeArgs.join(', ')}>` : '';
42
+ return typeName + genericType;
34
43
  }
@@ -2,7 +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 remove_import_1 = require("../../utils/remove-import");
5
+ const import_manipulations_1 = require("../../utils/import-manipulations");
6
6
  const add_unique_import_1 = require("../../utils/add-unique-import");
7
7
  const consts_1 = require("../constants/consts");
8
8
  function replaceConsts() {
@@ -11,15 +11,15 @@ 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
- remove_import_1.removeImport(parent);
17
+ import_manipulations_1.removeImport(parent);
18
18
  add_unique_import_1.addUniqueImport(parent.getSourceFile().getFilePath(), to.namedImport || to.name, to.moduleSpecifier);
19
19
  }
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;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ng_morph_1 = require("ng-morph");
4
4
  const get_named_import_references_1 = require("../../utils/get-named-import-references");
5
5
  const enums_1 = require("../constants/enums");
6
- const remove_import_1 = require("../../utils/remove-import");
6
+ const import_manipulations_1 = require("../../utils/import-manipulations");
7
7
  function replaceEnums() {
8
8
  enums_1.ENUMS_TO_REPLACE.forEach(({ name, replaceValues, keepAsType }) => {
9
9
  replaceEnumWithString(name, replaceValues, keepAsType);
@@ -15,7 +15,7 @@ function replaceEnumWithString(enumName, replaceValues, keepAsType = true) {
15
15
  for (let ref of references) {
16
16
  const parent = ref.getParent();
17
17
  if (ng_morph_1.Node.isImportSpecifier(parent) && !(keepAsType && containTypeRef(parent))) {
18
- remove_import_1.removeImport(parent);
18
+ import_manipulations_1.removeImport(parent);
19
19
  continue;
20
20
  }
21
21
  if (ng_morph_1.Node.isTypeReferenceNode(parent) && !keepAsType) {
@@ -0,0 +1 @@
1
+ export declare function replaceServices(): void;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const services_1 = require("../constants/services");
4
+ const get_named_import_references_1 = require("../../utils/get-named-import-references");
5
+ const ng_morph_1 = require("ng-morph");
6
+ const import_manipulations_1 = require("../../utils/import-manipulations");
7
+ const add_unique_import_1 = require("../../utils/add-unique-import");
8
+ function replaceServices() {
9
+ services_1.SERVICES_TO_REPLACE.forEach(service => replaceService(service));
10
+ }
11
+ exports.replaceServices = replaceServices;
12
+ function replaceService({ from, to, replaceMethods }) {
13
+ const references = get_named_import_references_1.getNamedImportReferences(from.name, from.moduleSpecifier);
14
+ references.forEach(ref => {
15
+ const parent = ref.getParent();
16
+ if (ng_morph_1.Node.isImportSpecifier(parent)) {
17
+ import_manipulations_1.removeImport(parent);
18
+ add_unique_import_1.addUniqueImport(parent.getSourceFile().getFilePath(), to.namedImport || to.name, to.moduleSpecifier);
19
+ return;
20
+ }
21
+ if (ng_morph_1.Node.isTypeReferenceNode(parent) && (replaceMethods === null || replaceMethods === void 0 ? void 0 : replaceMethods.length)) {
22
+ replaceProperties(parent, replaceMethods);
23
+ }
24
+ ref.replaceWithText(to.name);
25
+ });
26
+ }
27
+ function replaceProperties(parent, replaceProperties) {
28
+ const statement = parent.getParent();
29
+ const identifier = statement.getChildrenOfKind(ng_morph_1.SyntaxKind.Identifier)[0];
30
+ identifier.findReferencesAsNodes().forEach(ref => {
31
+ let parent = ref.getParent();
32
+ if ((ng_morph_1.Node.isPropertyAccessExpression(parent) &&
33
+ parent.getText().startsWith('this.')) ||
34
+ ng_morph_1.Node.isCallExpression(parent)) {
35
+ parent = parent.getParentIfKind(ng_morph_1.SyntaxKind.PropertyAccessExpression);
36
+ }
37
+ if (ng_morph_1.Node.isPropertyAccessExpression(parent)) {
38
+ replaceProperty(parent, replaceProperties);
39
+ return;
40
+ }
41
+ });
42
+ }
43
+ function replaceProperty(node, properties) {
44
+ const identifiers = node.getChildrenOfKind(ng_morph_1.SyntaxKind.Identifier);
45
+ identifiers.forEach(identifier => {
46
+ const property = properties === null || properties === void 0 ? void 0 : properties.find(property => property.from === identifier.getText());
47
+ if (property) {
48
+ identifier.replaceWithText(property.to);
49
+ }
50
+ });
51
+ }
@@ -1,18 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ng_morph_1 = require("ng-morph");
3
4
  const warnings_1 = require("../constants/warnings");
4
- const get_named_import_references_1 = require("../../utils/get-named-import-references");
5
5
  function showWarnings(context) {
6
6
  warnings_1.MIGRATION_WARNINGS.forEach(warning => showWarning(warning, context));
7
7
  }
8
8
  exports.showWarnings = showWarnings;
9
- function showWarning({ name, message, moduleSpecifier }, { logger }) {
10
- const references = get_named_import_references_1.getNamedImportReferences(name, moduleSpecifier);
11
- references.forEach(reference => {
12
- const file = reference.getSourceFile().getFilePath();
13
- const { line, column } = reference
14
- .getSourceFile()
15
- .getLineAndColumnAtPos(reference.getStart());
16
- logger.warn(`[WARNING]: in ${file} at line ${line}, col ${column}: ${message}`);
9
+ function showWarning({ name, message, moduleSpecifier = '**/**' }, { logger }) {
10
+ const references = ng_morph_1.getImports('**/**', {
11
+ moduleSpecifier,
12
+ namedImports: [name],
13
+ })
14
+ .map(i => { var _a; return (_a = i
15
+ .getNamedImports()
16
+ .find(namedImport => namedImport.getName() === name)) === null || _a === void 0 ? void 0 : _a.getNameNode(); })
17
+ .filter((namedImport) => Boolean(namedImport));
18
+ const referencesMeta = references.map(ref => {
19
+ const sourceFile = ref.getSourceFile();
20
+ return {
21
+ sourceFile,
22
+ filePath: sourceFile.getFilePath().toString(),
23
+ startLinePos: ref.getStartLinePos(),
24
+ };
25
+ });
26
+ /**
27
+ * We have to twice iterate array with refs because otherwise we get error:
28
+ * > Attempted to get information from a node that was removed or forgotten.
29
+ * See this {@link https://ts-morph.com/manipulation/#strongwarningstrong warning}
30
+ */
31
+ referencesMeta.forEach(({ sourceFile, filePath, startLinePos }) => {
32
+ logger.warn(`[WARNING] in ${filePath}: ${message}`);
33
+ sourceFile.insertText(startLinePos, `// TODO: ${message}\n`);
17
34
  });
18
35
  }
@@ -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,3 @@
1
+ import { ClassDeclaration, Pattern, Query } from 'ng-morph';
2
+ import { StructureType } from 'ng-morph/utils/types/structure-type';
3
+ export declare function getNgComponents(pattern: Pattern, query?: Query<Omit<StructureType<ClassDeclaration>, 'kind'>>): ClassDeclaration[];
@@ -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;
@@ -1,2 +1,3 @@
1
1
  import { ImportSpecifier } from 'ng-morph';
2
2
  export declare function removeImport(specifier: ImportSpecifier): void;
3
+ export declare function renameImport(specifier: ImportSpecifier, to: string, from: string): void;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function removeImport(specifier) {
4
+ if (specifier.getImportDeclaration().getNamedImports().length === 1) {
5
+ specifier.getImportDeclaration().remove();
6
+ }
7
+ else {
8
+ specifier.remove();
9
+ }
10
+ }
11
+ exports.removeImport = removeImport;
12
+ function renameImport(specifier, to, from) {
13
+ const namedImport = specifier
14
+ .getImportDeclaration()
15
+ .getNamedImports()
16
+ .find(specifier => specifier.getName() === from);
17
+ namedImport === null || namedImport === void 0 ? void 0 : namedImport.replaceWithText(to);
18
+ }
19
+ exports.renameImport = renameImport;
@@ -0,0 +1,19 @@
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[]): 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;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const parse5_1 = require("parse5");
4
+ function findElementsByTagName(html, tagName) {
5
+ const document = parse5_1.parseFragment(html, { sourceCodeLocationInfo: true });
6
+ const elements = [];
7
+ const visitNodes = (nodes) => {
8
+ nodes.forEach(n => {
9
+ const node = n;
10
+ if (node.childNodes) {
11
+ visitNodes(node.childNodes);
12
+ }
13
+ if (node.tagName === tagName) {
14
+ elements.push(node);
15
+ }
16
+ });
17
+ };
18
+ visitNodes(document.childNodes);
19
+ return elements;
20
+ }
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;
@@ -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,45 @@
1
+ import { DevkitFileSystem } from 'ng-morph/project/classes/devkit-file-system';
2
+ import { TemplateResource } from '../../ng-update/interfaces/template-resourse';
3
+ /**
4
+ * Replace component input property by new value
5
+ * ___
6
+ * Example:
7
+ * 1. Before
8
+ * ```html
9
+ * <tui-input-slider secondary="123"></tui-input-slider>
10
+ * ```
11
+ * 2. Execute
12
+ * ```ts
13
+ * const wasModified = replaceInputProperty({
14
+ * templateResource,
15
+ * fileSystem,
16
+ * componentSelector: 'tui-input-slider',
17
+ * from: 'secondary',
18
+ * to: 'tuiTextfieldCustomContent',
19
+ * });
20
+ * ```
21
+ * 3. After
22
+ * ```html
23
+ * <tui-input-slider tuiTextfieldCustomContent="123"></tui-input-slider>
24
+ * ```
25
+ * ___
26
+ * @return true if something was changed
27
+ */
28
+ export declare function replaceInputProperty({ templateResource, fileSystem, componentSelector, from, to, }: {
29
+ templateResource: TemplateResource;
30
+ fileSystem: DevkitFileSystem;
31
+ componentSelector: string | string[];
32
+ from: string;
33
+ to: string;
34
+ }): boolean;
35
+ export declare function replaceInputPropertyByDirective({ templateResource, fileSystem, componentSelector, inputProperty, directive, directiveModule, }: {
36
+ templateResource: TemplateResource;
37
+ fileSystem: DevkitFileSystem;
38
+ componentSelector: string | string[];
39
+ inputProperty: string;
40
+ directive: string;
41
+ directiveModule?: {
42
+ name: string;
43
+ moduleSpecifier: string;
44
+ };
45
+ }): void;