Skip to content

Commit

Permalink
chore: fix some migration issues (#8511)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Aug 13, 2024
2 parents 54c6a8d + 5af5846 commit 47ed442
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {hasElementAttribute} from '../../../../utils/templates/elements';
import type {ReplacementAttributeValue} from '../../../interfaces';

const hasPseudo = [
'button',
'a',
const hasPseudoInvalid = [
'tui-checkbox',
'tui-checkbox-block',
'tui-radio',
'tui-radio-block',
'tui-radio-labeled',
'tui-checkbox-labeled',
'tui-toggle',
];

const hasPseudo = [...hasPseudoInvalid, 'button', 'a'];

export const ATTR_WITH_VALUES_TO_REPLACE: ReplacementAttributeValue[] = [
{
attrNames: ['shape'],
Expand All @@ -36,6 +37,12 @@ export const ATTR_WITH_VALUES_TO_REPLACE: ReplacementAttributeValue[] = [
withTagNames: hasPseudo,
valueReplacer: (condition) => `${condition} ? 'active' : null`,
},
{
attrNames: ['[pseudoInvalid]'],
newAttrName: '[attr.data-mode]',
withTagNames: hasPseudoInvalid,
valueReplacer: (condition) => `${condition} ? 'invalid' : null`,
},
{
attrNames: ['[pseudoHover]'],
newAttrName: '[tuiAppearanceState]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export const IDENTIFIERS_TO_REPLACE: ReplacementIdentifierMulti[] = [
from: {name: 'TUI_DIALOGS', moduleSpecifier: '@taiga-ui/cdk'},
to: {name: 'TUI_DIALOGS', moduleSpecifier: '@taiga-ui/core'},
},
{
from: {
name: 'TuiStringifiableItem',
moduleSpecifier: '@taiga-ui/kit',
},
to: {
name: 'TuiStringifiableItem',
moduleSpecifier: '@taiga-ui/legacy',
},
},
{
from: {name: 'tuiSvgSrcInterceptors', moduleSpecifier: '@taiga-ui/core'},
to: {name: 'tuiSvgSrcInterceptors', moduleSpecifier: '@taiga-ui/legacy'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getTemplateOffset,
} from '../../../../utils/templates/template-resource';
import type {TemplateResource} from '../../../interfaces';
import {normalizeAttrValue} from '../utils/normalize-attr-value';
import {removeAttrs} from '../utils/remove-attrs';
import {replaceSizeAttr} from './toggles/common';

Expand Down Expand Up @@ -39,10 +40,6 @@ function getFallbackValue(
return textValue ? `(${textValue} | tuiInitials)` : fallbackValue || '';
}

function normalizeAttrValue(attrName: string, attrValue: string): string {
return attrName.startsWith('[') ? attrValue : `'${attrValue}'`;
}

export function migrateAvatar({
resource,
recorder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getTemplateFromTemplateResource,
getTemplateOffset,
} from '../../../../utils/templates/template-resource';
import {cleanObject} from '../utils/clean-object';
import {normalizeAttrValue} from '../utils/normalize-attr-value';

export function migrateNumberPrecision({
resource,
Expand Down Expand Up @@ -42,14 +42,9 @@ export function migrateNumberPrecision({
'@taiga-ui/core',
);

const format = JSON.stringify(
cleanObject({
decimalMode: decimalAttr?.value,
precision: precisionAttr?.value,
}),
);
const format = `{${decimalAttr ? `decimalMode: ${normalizeAttrValue(decimalAttr.name, decimalAttr.value)}` : ''}${decimalAttr ? ', ' : ''}${precisionAttr ? `precision: ${normalizeAttrValue(precisionAttr.name, precisionAttr.value)}` : ''}`;

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

const insertTo =
(sourceCodeLocation?.startTag?.startOffset || 0) +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function normalizeAttrValue(attrName: string, attrValue: string): string {
return attrName.startsWith('[') ? attrValue : `'${attrValue}'`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { TuiBlock, TuiCheckbox, TuiRadio } from "@taiga-ui/kit";
export class Test {}`;

const TEMPLATE_BEFORE = `
<tui-checkbox-block [(ngModel)]="value" [pseudoFocus]="pseudoFocus">Content</tui-checkbox-block>
<tui-checkbox-block [(ngModel)]="value" [pseudoInvalid]="invalid" [pseudoFocus]="pseudoFocus">Content</tui-checkbox-block>
<form [formGroup]="testForm">
<tui-radio-block
Expand Down Expand Up @@ -87,7 +87,7 @@ const TEMPLATE_BEFORE = `
`.trim();

const TEMPLATE_AFTER = `
<label tuiBlock><input tuiCheckbox type="checkbox" [(ngModel)]="value" [tuiAppearanceFocus]="pseudoFocus">Content</label>
<label tuiBlock><input tuiCheckbox type="checkbox" [(ngModel)]="value" [attr.data-mode]="invalid ? 'invalid' : null" [tuiAppearanceFocus]="pseudoFocus">Content</label>
<form [formGroup]="testForm">
<label tuiBlock> <input tuiRadio type="radio"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,26 @@ const TEMPLATE_BEFORE = `
<tui-input-number
[formControl]="control"
[precision]="2"
[decimal]="always"
decimal="always"
>
</tui-input-number>
<tui-input-number
[formControl]="control"
[precision]="2"
[decimal]="decimal()"
>
</tui-input-number>
`;

const TEMPLATE_AFTER = `
<tui-input-number
[tuiNumberFormat]='{"decimalMode":"always","precision":"2"}' [formControl]="control"
[tuiNumberFormat]="{decimalMode: 'always', precision: 2" [formControl]="control"
${''}
${''}
>
</tui-input-number>
<tui-input-number
[tuiNumberFormat]="{decimalMode: decimal(), precision: 2" [formControl]="control"
${''}
${''}
>
Expand Down

0 comments on commit 47ed442

Please sign in to comment.