Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/add-tempate-transfer
Browse files Browse the repository at this point in the history
40oleg authored Mar 18, 2024
2 parents bb7e865 + de7eda6 commit 0e7754f
Showing 23 changed files with 1,917 additions and 1,501 deletions.
3,317 changes: 1,862 additions & 1,455 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions projects/cdk/package.json
Original file line number Diff line number Diff line change
@@ -21,8 +21,7 @@
"@angular-devkit/core": "16.2.12",
"@angular-devkit/schematics": "16.2.12",
"@angular-devkit/schematics-cli": "16.2.12",
"@schematics/angular": "16.2.12",
"@types/parse5": "6.0.3"
"@schematics/angular": "16.2.12"
},
"peerDependencies": {
"@angular/animations": ">=16.0.0",
@@ -41,7 +40,7 @@
"@angular-devkit/schematics": ">=16.0.0",
"@schematics/angular": ">=16.0.0",
"ng-morph": "^4.0.6",
"parse5": "^6.0.1"
"parse5": "^7.1.2"
},
"ng-update": {
"migrations": "./schematics/migration.json",
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Element} from 'parse5';
import type {Element} from 'parse5/dist/tree-adapters/default';

export interface ReplacementAttributeToDirective {
readonly componentSelector: string[] | string;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Element} from 'parse5';
import type {Element} from 'parse5/dist/tree-adapters/default';

export interface ReplacementAttribute {
readonly from: {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Element} from 'parse5';
import type {Element} from 'parse5/dist/tree-adapters/default';

export interface ReplacementTag {
readonly addAttributes?: string[];
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {ElementLocation} from 'parse5';
import type {ElementLocation} from 'parse5/dist/common/token';

const START_TAG_OFFSET = 1;
const END_TAG_OFFSET = 2;

export function replaceTag(
recorder: UpdateRecorder,
sourceCodeLocation: ElementLocation | undefined,
sourceCodeLocation: ElementLocation | null | undefined,
from: string,
to: string,
templateOffset = 0,
addAttributes: string[] = [],
): void {
const startTagOffset = sourceCodeLocation?.startTag.startOffset;
const startTagOffset = sourceCodeLocation?.startTag?.startOffset ?? 0;
const endTagOffset = sourceCodeLocation?.endTag?.startOffset;

if (endTagOffset) {
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ function migrateExpand({
attr => attr.name === 'tuiexpandcontent',
);

const insertTo = templateElement?.sourceCodeLocation?.startTag.endOffset;
const insertTo = templateElement?.sourceCodeLocation?.startTag?.endOffset ?? 0;

if (!insertTo || tuiExpandAttr) {
return;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {DevkitFileSystem} from 'ng-morph/project/classes/devkit-file-system';
import type {Element} from 'parse5';
import type {Element} from 'parse5/dist/tree-adapters/default';

import {
findElementsByFn,
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {DevkitFileSystem} from 'ng-morph';
import {createProject, saveActiveProject, setActiveProject} from 'ng-morph';
import type {Element} from 'parse5';
import type {Element} from 'parse5/dist/tree-adapters/default';

import {ALL_FILES, ALL_TS_FILES} from '../../../constants';
import type {TuiSchema} from '../../../ng-add/schema';
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ function replaceBreadcrumbs({
elements.forEach(element => {
const itemsAttr = element.attrs.find(attr => attr.name === '[items]');
const itemsValue = itemsAttr?.value;
const insertTo = element?.sourceCodeLocation?.startTag.endOffset;
const insertTo = element?.sourceCodeLocation?.startTag?.endOffset ?? 0;

if (!itemsValue || !insertTo) {
return;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import {arrayFlat} from 'ng-morph';
import type {DevkitFileSystem} from 'ng-morph/project/classes/devkit-file-system';
import type {Attribute, Element} from 'parse5';
import type {Attribute} from 'parse5/dist/common/token';
import type {Element} from 'parse5/dist/tree-adapters/default';

import {
findElementsByFn,
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {DevkitFileSystem} from 'ng-morph';
import type {Attribute} from 'parse5';
import type {Attribute} from 'parse5/dist/common/token';

import {addImportToClosestModule} from '../../../../utils/add-import-to-closest-module';
import {findElementsByTagName} from '../../../../utils/templates/elements';
@@ -76,7 +76,8 @@ export function migrateAvatar({
fallbackAttr?.value &&
normalizeAttrValue(fallbackAttr.name, fallbackAttr.value);

const insertTo = sourceCodeLocation.startTag.startOffset + '<tui-avatar'.length;
const insertTo =
(sourceCodeLocation.startTag?.startOffset ?? 0) + '<tui-avatar'.length;

if (!insertTo) {
return;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {DevkitFileSystem} from 'ng-morph';
import type {Attribute, Element, ElementLocation} from 'parse5';
import type {Attribute, ElementLocation} from 'parse5/dist/common/token';
import type {Element} from 'parse5/dist/tree-adapters/default';

import {findElementsByTagName} from '../../../../utils/templates/elements';
import {
@@ -97,7 +98,7 @@ function migrateBadgeValue({
templateOffset: number;
}): void {
const attrValue = valueAttr?.value;
const insertTo = sourceCodeLocation?.startTag.endOffset;
const insertTo = sourceCodeLocation?.startTag?.endOffset ?? 0;
const selfClosing = !sourceCodeLocation?.endTag;

if (!attrValue || !insertTo) {
@@ -120,7 +121,7 @@ function migrateBadgeValue({
}

if (selfClosing) {
recorder.remove(sourceCodeLocation.startTag.endOffset - 2, 1);
recorder.remove((sourceCodeLocation.startTag?.endOffset ?? 2) - 2, 1);
}
}

@@ -130,7 +131,7 @@ function addTodo(
templateOffset: number,
): void {
recorder.insertRight(
templateOffset + (sourceCodeLocation?.startTag.startOffset || 0),
templateOffset + (sourceCodeLocation?.startTag?.startOffset ?? 0),
'<!-- Taiga migration TODO: use "<tui-icon>" with "tuiBadge" directive for icon-only badges instead -->\n',
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {DevkitFileSystem} from 'ng-morph';
import type {Attribute, ElementLocation} from 'parse5';
import type {Attribute, ElementLocation} from 'parse5/dist/common/token';

import {findElementsByTagName} from '../../../../utils/templates/elements';
import {findAttr} from '../../../../utils/templates/inputs';
@@ -80,7 +80,7 @@ export function migrateBadgedContent({
});

if (!rounded || rounded.value === 'true') {
const insertTo = sourceCodeLocation.startTag.endOffset;
const insertTo = sourceCodeLocation.startTag?.endOffset ?? 0;

recorder.insertRight(
insertTo + templateOffset - 1,
@@ -119,7 +119,7 @@ function migrateColor({
}

const value = attr.value;
const insertTo = sourceCodeLocation.startTag.endOffset || 0;
const insertTo = sourceCodeLocation.startTag?.endOffset ?? 0;

recorder.insertRight(
insertTo + templateOffset + 1,
@@ -154,7 +154,7 @@ function migrateContent({

const value = attr.value;
const colorAttrValue = colorAttr?.value;
const insertTo = sourceCodeLocation.startTag.endOffset || 0;
const insertTo = sourceCodeLocation.startTag?.endOffset ?? 0;

if (value.startsWith('tuiIcon')) {
recorder.insertRight(
@@ -170,7 +170,7 @@ function migrateContent({
);
} else if (Number.isNaN(Number(value))) {
recorder.insertRight(
templateOffset + (sourceCodeLocation?.startTag.startOffset || 0),
templateOffset + (sourceCodeLocation?.startTag?.startOffset ?? 0),
'<!-- Taiga migration TODO: contentTop and contentBottom inputs has been removed. Use ng-content, see taiga-ui.dev/components/badged-content -->\n',
);
} else {
Original file line number Diff line number Diff line change
@@ -35,21 +35,21 @@ export function migrateExpandable({

const expandableValue = expandableAttr?.value;
const expandableStart =
sourceCodeLocation?.attrs?.[expandableAttr.name].startOffset || 0;
sourceCodeLocation?.attrs?.[expandableAttr.name]?.startOffset ?? 0;
const expandableEnd =
sourceCodeLocation?.attrs?.[expandableAttr.name].endOffset || 0;
sourceCodeLocation?.attrs?.[expandableAttr.name]?.endOffset ?? 0;

if (expandableValue === 'false') {
const rowsAttr = attrs.find(attr => attr.name === '[rows]');

const insertTo = (sourceCodeLocation?.startTag.endOffset || 0) - 1;
const insertTo = (sourceCodeLocation?.startTag?.endOffset ?? 0) - 1;

recorder.insertRight(templateOffset + insertTo, rowsAttr ? '' : '[rows]="1"');
}

if (expandableValue !== 'false' && expandableValue !== 'true') {
recorder.insertRight(
templateOffset + (sourceCodeLocation?.startTag.startOffset || 0),
templateOffset + (sourceCodeLocation?.startTag?.startOffset ?? 0),
'<!-- Taiga migration TODO: "expandable" property has been removed. Use "rows" property instead -->\n',
);
}
Original file line number Diff line number Diff line change
@@ -57,16 +57,16 @@ export function migrateLabeled({
);

recorder.insertRight(
templateOffset + sourceCodeLocation.startTag.startOffset - 1,
templateOffset + (sourceCodeLocation.startTag?.startOffset ?? 1) - 1,
'<label tuiLabel>',
);
recorder.insertRight(
templateOffset + sourceCodeLocation.endTag.startOffset - 1,
templateOffset + (sourceCodeLocation.endTag?.startOffset ?? 1) - 1,
'\n</label>',
);

recorder.remove(
templateOffset + sourceCodeLocation.endTag.startOffset,
templateOffset + (sourceCodeLocation.endTag?.startOffset ?? 0),
tagName === 'tui-checkbox-labeled'
? '<tui-checkbox-labeled/>'.length
: '<tui-radio-labeled/>'.length,
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {DevkitFileSystem} from 'ng-morph';
import type {Attribute} from 'parse5';
import type {Attribute} from 'parse5/dist/common/token';

import {tuiCleanObject} from '../../../../../utils/miscellaneous/clean-object';
import type {TemplateResource} from '../../../../ng-update/interfaces';
@@ -42,7 +42,7 @@ export function migrateMoney({
return;
}

const insertTo = sourceCodeLocation?.endTag.startOffset;
const insertTo = sourceCodeLocation?.endTag?.startOffset ?? 0;
const value = isBinding(valueAttr) ? valueAttr.value : `'${valueAttr.value}'`;
const currency =
currencyAttr && isBinding(currencyAttr)
@@ -70,7 +70,7 @@ export function migrateMoney({

const formatPart = `[tuiNumberFormat]='${format}'`;

const insertTo = (sourceCodeLocation?.startTag.startOffset || 0) + 1;
const insertTo = (sourceCodeLocation?.startTag?.startOffset || 0) + 1;

recorder.insertRight(templateOffset + insertTo, formatPart);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {Attribute, ElementLocation} from 'parse5';
import type {Attribute, ElementLocation} from 'parse5/dist/common/token';

const sizeMap: Record<string, string> = {
l: 'm',
@@ -12,13 +12,16 @@ export function replaceOpenTag(
{tag, directive, type}: {tag: string; directive: string; type: string},
): void {
const {startTag} = sourceCodeLocation;
const {startOffset, startCol} = startTag;

const spaces = ' '.repeat(startCol + 3);
if (!startTag) {
return;
}

const spaces = ' '.repeat(startTag.startCol + 3);

recorder.remove(templateOffset + startOffset, `<${tag}`.length);
recorder.remove(templateOffset + startTag.startOffset, `<${tag}`.length);
recorder.insertRight(
templateOffset + startOffset,
templateOffset + startTag.startOffset,
`<input\n${spaces}${directive}\n${spaces}type="${type}"`,
);
}
@@ -73,5 +76,5 @@ export function closeStartTag(
return;
}

recorder.insertRight(templateOffset + startTag.endOffset - 1, '/');
recorder.insertRight(templateOffset + (startTag?.endOffset ?? 1) - 1, '/');
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {UpdateRecorder} from '@angular-devkit/schematics';
import type {Attribute, ElementLocation} from 'parse5';
import type {Attribute, ElementLocation} from 'parse5/dist/common/token';

export function removeAttrs(
attrs: Attribute[],
2 changes: 1 addition & 1 deletion projects/cdk/schematics/utils/templates/elements.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ChildNode, Element} from 'parse5';
import {parseFragment} from 'parse5';
import type {ChildNode, Element} from 'parse5/dist/tree-adapters/default';

export function findElementsByFn(
nodes: ChildNode[],
2 changes: 1 addition & 1 deletion projects/cdk/schematics/utils/templates/inputs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Attribute} from 'parse5';
import type {Attribute} from 'parse5/dist/common/token';

export function findAttr(attrs: Attribute[], name: string): Attribute | undefined {
return attrs.find(attr => attr.name === name || attr.name === `[${name}]`);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {DevkitFileSystem} from 'ng-morph/project/classes/devkit-file-system';
import type {Element} from 'parse5';
import type {Element} from 'parse5/dist/tree-adapters/default';

import type {TemplateResource} from '../../ng-update/interfaces/template-resource';
import {addImportToClosestModule} from '../add-import-to-closest-module';
6 changes: 5 additions & 1 deletion projects/core/directives/hint/hint-hover.directive.ts
Original file line number Diff line number Diff line change
@@ -44,7 +44,11 @@ export class TuiHintHoverDirective extends TuiDriver {
),
).pipe(
filter(() => this.enabled),
map(value => value && !tuiIsObscured(this.el)),
map(
value =>
value &&
(this.el.hasAttribute('tuiHintPointer') || !tuiIsObscured(this.el)),
),
tap(visible => {
this.visible = visible;
}),

0 comments on commit 0e7754f

Please sign in to comment.