Skip to content

Commit

Permalink
fix(cdk): schematics fix incorrectly processing setNativeFocused (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Apr 11, 2023
1 parent bd09ef1 commit cf04d14
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,6 @@ export const DEPRECATED_FUNCTIONS: readonly TypeToRename[] = [
to: `tuiMoveFocus`,
moduleSpecifier: [`@taiga-ui/cdk`],
},
{
from: `setNativeFocused`,
to: `tuiSetNativeFocused`,
moduleSpecifier: [`@taiga-ui/cdk`],
},
{
from: `setNativeMouseFocused`,
to: `tuiSetNativeMouseFocused`,
Expand Down
4 changes: 3 additions & 1 deletion projects/cdk/schematics/ng-update/v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ function main(options: TuiSchema): Rule {

function addTaigaStyles(options: TuiSchema): Rule {
return async (tree: Tree, context) => {
const taigaStyles = [TAIGA_THEME_FONTS];
const proprietary = getPackageJsonDependency(tree, `@taiga-ui/proprietary-core`);

const taigaStyles = proprietary ? [] : [TAIGA_THEME_FONTS];
const stylesToReplace = {
from: TAIGA_GLOBAL_OLD_STYLE,
to: [TAIGA_GLOBAL_NEW_STYLE],
Expand Down
25 changes: 25 additions & 0 deletions projects/cdk/schematics/ng-update/v3/steps/replace-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function replaceFunctions(options: TuiSchema): void {
replaceFallbackValue(getNamedImportReferences(`fallbackValue`, `@taiga-ui/cdk`));
replaceCustomEvent(getNamedImportReferences(`tuiCustomEvent`, `@taiga-ui/cdk`));
replaceClosestElement(getNamedImportReferences(`getClosestElement`, `@taiga-ui/cdk`));
replaceNativeFocused([
...getNamedImportReferences(`tuiSetNativeFocused`, `@taiga-ui/cdk`),
...getNamedImportReferences(`setNativeFocused`, `@taiga-ui/cdk`),
]);
replaceDeprecatedFunction();
modifyFormatNumberArgs();
modifyClosestFocusable();
Expand Down Expand Up @@ -67,6 +71,27 @@ function replacePadStart(references: Node[]): void {
});
}

function replaceNativeFocused(references: Node[]): void {
references.forEach(ref => {
const parent = ref.getParent();

if (Node.isImportSpecifier(parent)) {
removeImport(parent);
} else if (Node.isCallExpression(parent)) {
const [targetString, focusedArg, preventScroll] = parent.getArguments();

const setFocused = !focusedArg || focusedArg.getText() === `true`;

const focus = `${targetString.getText()}.focus(${
preventScroll?.getText() ? `{preventScroll: true}` : ``
})`;
const blur = `${targetString.getText()}.blur()`;

parent.replaceWithText(setFocused ? focus : blur);
}
});
}

function replaceClosestElement(references: Node[]): void {
references.forEach(ref => {
const parent = ref.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ import {
isNativeKeyboardFocusable,
isNativeMouseFocusable,
moveFocus,
setNativeFocused,
setNativeMouseFocused,
px,
clamp,
Expand Down Expand Up @@ -241,7 +240,6 @@ isNativeFocused(...args);
isNativeKeyboardFocusable(...args);
isNativeMouseFocusable(...args);
moveFocus(...args);
setNativeFocused(...args);
setNativeMouseFocused(...args);
px(...args);
clamp(...args);
Expand Down Expand Up @@ -384,7 +382,6 @@ class Component {
isNativeKeyboardFocusable();
isNativeMouseFocusable();
moveFocus();
setNativeFocused();
setNativeMouseFocused();
px();
clamp();
Expand Down Expand Up @@ -488,7 +485,7 @@ import {
tuiToGradient,
} from '@taiga-ui/addon-editor';
import {tuiDefaultSort} from '@taiga-ui/addon-table';
import { tuiMockCurrentDate, tuiRestoreRealDate, tuiMockDateInside, tuiPendingIfNotMoscowTimeZone, tuiDragAndDropFrom, tuiFocusVisibleObservable, tuiQueryListChanges, tuiMouseDragFinishFrom, tuiMustBePresent, tuiPressedObservable, tuiPreventDefault, tuiStopPropagation, tuiTypedFromEvent, tuiWatch, tuiIsEdgeOlderThan, tuiIsEdge, tuiIsFirefox, tuiIsIE, tuiIsSafari, tuiCanScroll, tuiContainsOrAfter, tuiGetActualTarget, tuiGetClipboardDataText, tuiGetDocumentOrShadowRoot, tuiGetElementObscures, tuiGetElementOffset, tuiGetScrollParent, tuiIsCurrentTarget, tuiIsInsideIframe, tuiIsNodeIn, tuiBlurNativeFocused, tuiGetNativeFocused, tuiIsNativeFocusedIn, tuiIsNativeFocused, tuiIsNativeKeyboardFocusable, tuiIsNativeMouseFocusable, tuiMoveFocus, tuiSetNativeFocused, tuiSetNativeMouseFocused, tuiPx, tuiClamp, tuiInRange, tuiNormalizeToIntNumber, tuiQuantize, tuiRound, tuiCeil, tuiFloor, tuiSum, tuiToInt, tuiToRadians, tuiDistanceBetweenTouches, tuiEaseInOutQuad, tuiFlatLength, tuiGetOriginalArrayFromQueryList, tuiGetSwipeDirection, tuiIsElementEditable, tuiIsNumber, tuiIsPresent, tuiMarkControlAsTouchedAndValidate, tuiNullableSame, tuiUniqBy, tuiIsApplePlatform, tuiIsApple, tuiIsIos, tuiSvgLinearGradientProcessor, tuiGetClosestFocusable, tuiHexToRgb, tuiHsvToRgb, tuiParseColor, tuiRgbToHex, tuiRgbToHsv } from '@taiga-ui/cdk';
import { tuiMockCurrentDate, tuiRestoreRealDate, tuiMockDateInside, tuiPendingIfNotMoscowTimeZone, tuiDragAndDropFrom, tuiFocusVisibleObservable, tuiQueryListChanges, tuiMouseDragFinishFrom, tuiMustBePresent, tuiPressedObservable, tuiPreventDefault, tuiStopPropagation, tuiTypedFromEvent, tuiWatch, tuiIsEdgeOlderThan, tuiIsEdge, tuiIsFirefox, tuiIsIE, tuiIsSafari, tuiCanScroll, tuiContainsOrAfter, tuiGetActualTarget, tuiGetClipboardDataText, tuiGetDocumentOrShadowRoot, tuiGetElementObscures, tuiGetElementOffset, tuiGetScrollParent, tuiIsCurrentTarget, tuiIsInsideIframe, tuiIsNodeIn, tuiBlurNativeFocused, tuiGetNativeFocused, tuiIsNativeFocusedIn, tuiIsNativeFocused, tuiIsNativeKeyboardFocusable, tuiIsNativeMouseFocusable, tuiMoveFocus, tuiSetNativeMouseFocused, tuiPx, tuiClamp, tuiInRange, tuiNormalizeToIntNumber, tuiQuantize, tuiRound, tuiCeil, tuiFloor, tuiSum, tuiToInt, tuiToRadians, tuiDistanceBetweenTouches, tuiEaseInOutQuad, tuiFlatLength, tuiGetOriginalArrayFromQueryList, tuiGetSwipeDirection, tuiIsElementEditable, tuiIsNumber, tuiIsPresent, tuiMarkControlAsTouchedAndValidate, tuiNullableSame, tuiUniqBy, tuiIsApplePlatform, tuiIsApple, tuiIsIos, tuiSvgLinearGradientProcessor, tuiGetClosestFocusable, tuiHexToRgb, tuiHsvToRgb, tuiParseColor, tuiRgbToHex, tuiRgbToHsv } from '@taiga-ui/cdk';
import {
tuiTextfieldWatchedControllerFactory,
tuiSmartSearch,
Expand Down Expand Up @@ -607,7 +604,6 @@ tuiIsNativeFocused(...args);
tuiIsNativeKeyboardFocusable(...args);
tuiIsNativeMouseFocusable(...args);
tuiMoveFocus(...args);
tuiSetNativeFocused(...args);
tuiSetNativeMouseFocused(...args);
tuiPx(...args);
tuiClamp(...args);
Expand Down Expand Up @@ -750,7 +746,6 @@ class Component {
tuiIsNativeKeyboardFocusable();
tuiIsNativeMouseFocusable();
tuiMoveFocus();
tuiSetNativeFocused();
tuiSetNativeMouseFocused();
tuiPx();
tuiClamp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import {
TuiNumberFormatSettings,
} from '@taiga-ui/core';
element.focus();
element.focus();
element.focus();
element.blur();
element.focus({preventScroll: true});
tuiFormatNumber(1000);
tuiFormatNumber(1.234, {decimalLimit: 2, decimalSeparator: ',', thousandSeparator: ' ', zeroPadding: true});
tuiFormatNumber(123.45, {decimalLimit: 3, decimalSeparator: '.', thousandSeparator: ' ', zeroPadding: true});
Expand Down Expand Up @@ -82,13 +88,19 @@ const event = new CustomEvent("hello", {
`;

const BEFORE = `import {Component} from '@angular/core';
import { fallbackValue, tuiCustomEvent, getClosestElement, padStart, tuiGetClosestFocusable } from '@taiga-ui/cdk';
import { fallbackValue, tuiCustomEvent, getClosestElement, padStart, tuiGetClosestFocusable, tuiSetNativeFocused, setNativeFocused } from '@taiga-ui/cdk';
import {
TUI_NUMBER_FORMAT,
tuiFormatNumber,
TuiNumberFormatSettings,
} from '@taiga-ui/core';
setNativeFocused(element);
tuiSetNativeFocused(element);
tuiSetNativeFocused(element, true);
tuiSetNativeFocused(element, false);
tuiSetNativeFocused(element, true, true);
tuiFormatNumber(1000);
tuiFormatNumber(1.234, 2);
tuiFormatNumber(123.45, 3, '.');
Expand Down

0 comments on commit cf04d14

Please sign in to comment.