diff --git a/packages/devextreme-cli/src/applications/application.angular.js b/packages/devextreme-cli/src/applications/application.angular.js index c67bd6022..6863bc1e2 100644 --- a/packages/devextreme-cli/src/applications/application.angular.js +++ b/packages/devextreme-cli/src/applications/application.angular.js @@ -13,7 +13,6 @@ const modifyJson = require('../utility/modify-json-file'); const schematicsVersion = latestVersions['devextreme-schematics'] || 'latest'; const minNgCliVersion = new semver('21.0.0'); -const ngCliWithZoneless = new semver('21.0.0'); async function runSchematicCommand(schematicCommand, options, evaluatingOptions) { const collectionName = 'devextreme-schematics'; @@ -100,7 +99,6 @@ const bumpAngular = (appPath, versionTag) => { const create = async(appName, options) => { const layout = await getLayoutInfo(options.layout); - const currentNgVersion = ngVersion.getNgCliVersion().version; const depsVersionTag = extractDepsVersionTag(options); const commandArguments = [ @@ -115,10 +113,6 @@ const create = async(appName, options) => { '--ai-config=none' ]; - if(ngCliWithZoneless.compare(currentNgVersion) <= 0) { - commandArguments.push('--zoneless=false'); - } - await runNgCommand(commandArguments, options); const appPath = path.join(process.cwd(), appName); @@ -140,8 +134,7 @@ const create = async(appName, options) => { const addTemplate = async(appName, options, evaluatingOptions) => { const schematicOptions = { ...(appName && { project: appName }), - ...options, - globalNgCliVersion: ngVersion.getNgCliVersion().version + ...options }; runSchematicCommand('add-app-template', schematicOptions, evaluatingOptions); }; diff --git a/packages/devextreme-cli/src/utility/ng-version.js b/packages/devextreme-cli/src/utility/ng-version.js index e9330e919..f323a07c9 100644 --- a/packages/devextreme-cli/src/utility/ng-version.js +++ b/packages/devextreme-cli/src/utility/ng-version.js @@ -14,22 +14,6 @@ const getLocalNgVersion = () => { } }; -const getPublicNgVersion = () => { - const version = execSync('npm view @angular/cli@v21-lts version').toString(); - return new semver(version); -}; - -const getNgCliVersion = () => { - let ngCliVersion = getLocalNgVersion(); - if(!ngCliVersion) { - ngCliVersion = getPublicNgVersion(); - } - - return ngCliVersion; -}; - module.exports = { - getLocalNgVersion, - getPublicNgVersion, - getNgCliVersion + getLocalNgVersion }; diff --git a/packages/devextreme-cli/testing/verifying.js b/packages/devextreme-cli/testing/verifying.js index 28bdad1c3..b81cf893c 100644 --- a/packages/devextreme-cli/testing/verifying.js +++ b/packages/devextreme-cli/testing/verifying.js @@ -36,9 +36,39 @@ const verifyThemesAreBuilt = (env) => { return missing.map(outputFile => `${env.engine}: '${outputFile}' was not generated on the application creation`); }; +const verifyZoneless = (env) => { + if(env.engine !== 'angular') { + return []; + } + + const problems = []; + const { dependencies = {}, devDependencies = {} } = readJson(path.join(env.appPath, 'package.json')); + + if('zone.js' in dependencies || 'zone.js' in devDependencies) { + problems.push(`${env.engine}: package.json has the 'zone.js' dependency`); + } + + const { projects } = readJson(path.join(env.appPath, 'angular.json')); + Object.keys(projects).forEach(projectName => { + const polyfills = projects[projectName].architect.build.options.polyfills || []; + + if([].concat(polyfills).includes('zone.js')) { + problems.push(`${env.engine}: angular.json has the 'zone.js' polyfill in the '${projectName}' project`); + } + }); + + const appConfig = fs.readFileSync(path.join(env.appPath, 'src/app/app.config.ts'), 'utf8'); + if(appConfig.includes('provideZoneChangeDetection')) { + problems.push(`${env.engine}: app.config.ts uses provideZoneChangeDetection`); + } + + return problems; +}; + const verify = (env) => [ ...verifyNoInstallScripts(env), - ...verifyThemesAreBuilt(env) + ...verifyThemesAreBuilt(env), + ...verifyZoneless(env) ]; (function verifyProcess() { @@ -56,5 +86,5 @@ const verify = (env) => [ process.exit(1); } - console.log('The generated applications need no install scripts.'); + console.log('The generated applications passed verification.'); })(); diff --git a/packages/devextreme-schematics/src/add-app-template/index.ts b/packages/devextreme-schematics/src/add-app-template/index.ts index 3b17c5486..1d3cb7f22 100644 --- a/packages/devextreme-schematics/src/add-app-template/index.ts +++ b/packages/devextreme-schematics/src/add-app-template/index.ts @@ -15,8 +15,7 @@ export default function(options: any): Rule { resolveConflicts: options.resolveConflicts, project: options.project, skipInstall: true, - updateBudgets: options.updateBudgets, - globalNgCliVersion: options.globalNgCliVersion + updateBudgets: options.updateBudgets }) ]; diff --git a/packages/devextreme-schematics/src/add-app-template/schema.json b/packages/devextreme-schematics/src/add-app-template/schema.json index f72ea8510..144dcb559 100644 --- a/packages/devextreme-schematics/src/add-app-template/schema.json +++ b/packages/devextreme-schematics/src/add-app-template/schema.json @@ -41,10 +41,6 @@ "description": "The DevExtreme version", "default": "26.1.6" }, - "globalNgCliVersion": { - "type":"string", - "default": "^17.2.0" - }, "empty": { "type": "boolean", "description": "Specifies whether to skip sample views generation", diff --git a/packages/devextreme-schematics/src/add-layout/README.md b/packages/devextreme-schematics/src/add-layout/README.md index 0e91a5812..fa76c4b38 100644 --- a/packages/devextreme-schematics/src/add-layout/README.md +++ b/packages/devextreme-schematics/src/add-layout/README.md @@ -15,4 +15,3 @@ A schematic that adds a DevExtreme layout to a DevExtreme Angular application. - skip-install (boolean) Specifies whether to skip the dependency package installation - diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/app.config.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/app.config.ts index 9e771f76a..5ba816eba 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/app.config.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/app.config.ts @@ -1,20 +1,10 @@ -import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; +import { ApplicationConfig<% if (!zoneless) { %>, provideZoneChangeDetection<% } %> } from '@angular/core'; import { provideRouter, withHashLocation } from '@angular/router'; import { routes } from './app.routes'; -import { - AppInfoService, - AuthGuardService, - AuthService, - ScreenService, -} from './shared/services'; export const appConfig: ApplicationConfig = { - providers: [ - provideZoneChangeDetection({ eventCoalescing: true }), + providers: [<% if (!zoneless) { %> + provideZoneChangeDetection({ eventCoalescing: true }),<% } %> provideRouter(routes, withHashLocation()), - AuthGuardService, - AuthService, - ScreenService, - AppInfoService, ] }; diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.html b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.html index f09ae4664..60f03c304 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.html +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.html @@ -1,22 +1,22 @@ - @if (minMenuSize !== 0) { + @if (minMenuSize() !== 0) { + [menuToggleEnabled]="minMenuSize() === 0" + (menuToggle)="menuOpened.set(!menuOpened())"> diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.ts index defb82861..5908449ad 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-inner-toolbar/side-nav-inner-toolbar.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, ViewChild } from '@angular/core'; +import { Component, OnInit, Input, ViewChild, signal } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; import { CommonModule } from '@angular/common'; @@ -27,32 +27,32 @@ import { ThemeService } from '../../shared/services/theme.service'; }) export class SideNavInnerToolbarComponent implements OnInit { @ViewChild(DxScrollViewComponent, { static: true }) scrollView!: DxScrollViewComponent; - selectedRoute = ''; + selectedRoute = signal(''); - menuOpened!: boolean; - temporaryMenuOpened = false; + menuOpened = signal(false); + temporaryMenuOpened = signal(false); @Input() title!: string; - menuMode: DxDrawerTypes.OpenedStateMode = 'shrink'; - menuRevealMode: DxDrawerTypes.RevealMode = 'expand'; - minMenuSize = 0; - shaderEnabled = false; - swatchClassName = 'dx-swatch-additional'; + menuMode = signal('shrink'); + menuRevealMode = signal('expand'); + minMenuSize = signal(0); + shaderEnabled = signal(false); + swatchClassName = signal('dx-swatch-additional'); constructor(protected themeService: ThemeService, private screen: ScreenService, private router: Router) { themeService.isDark.subscribe((isDark) => { - this.swatchClassName = 'dx-swatch-additional' + (isDark ? '-dark' : ''); + this.swatchClassName.set('dx-swatch-additional' + (isDark ? '-dark' : '')); }) } ngOnInit() { - this.menuOpened = this.screen.sizes['screen-large']; + this.menuOpened.set(this.screen.sizes['screen-large']); this.router.events.subscribe(val => { if (val instanceof NavigationEnd) { - this.selectedRoute = val.urlAfterRedirects.split('?')[0]; + this.selectedRoute.set(val.urlAfterRedirects.split('?')[0]); } }); @@ -65,30 +65,30 @@ export class SideNavInnerToolbarComponent implements OnInit { const isXSmall = this.screen.sizes['screen-x-small']; const isLarge = this.screen.sizes['screen-large']; - this.menuMode = isLarge ? 'shrink' : 'overlap'; - this.menuRevealMode = isXSmall ? 'slide' : 'expand'; - this.minMenuSize = isXSmall ? 0 : 60; - this.shaderEnabled = !isLarge; + this.menuMode.set(isLarge ? 'shrink' : 'overlap'); + this.menuRevealMode.set(isXSmall ? 'slide' : 'expand'); + this.minMenuSize.set(isXSmall ? 0 : 60); + this.shaderEnabled.set(!isLarge); } toggleMenu = (e: DxToolbarTypes.ItemClickEvent) => { - this.menuOpened = !this.menuOpened; + this.menuOpened.update((opened) => !opened); e.event?.stopPropagation(); } get hideMenuAfterNavigation() { - return this.menuMode === 'overlap' || this.temporaryMenuOpened; + return this.menuMode() === 'overlap' || this.temporaryMenuOpened(); } get showMenuAfterClick() { - return !this.menuOpened; + return !this.menuOpened(); } navigationChanged(event: DxTreeViewTypes.ItemClickEvent) { const path = (event.itemData as any).path; const pointerEvent = event.event; - if (path && this.menuOpened) { + if (path && this.menuOpened()) { if (event.node?.selected) { pointerEvent?.preventDefault(); } else { @@ -97,8 +97,8 @@ export class SideNavInnerToolbarComponent implements OnInit { } if (this.hideMenuAfterNavigation) { - this.temporaryMenuOpened = false; - this.menuOpened = false; + this.temporaryMenuOpened.set(false); + this.menuOpened.set(false); pointerEvent?.stopPropagation(); } } else { @@ -108,8 +108,8 @@ export class SideNavInnerToolbarComponent implements OnInit { navigationClick() { if (this.showMenuAfterClick) { - this.temporaryMenuOpened = true; - this.menuOpened = true; + this.temporaryMenuOpened.set(true); + this.menuOpened.set(true); } } } diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.html b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.html index 095d540bc..8b9f40732 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.html +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.html @@ -1,24 +1,24 @@ diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.ts index 75f70eca9..b3199ade7 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/layouts/side-nav-outer-toolbar/side-nav-outer-toolbar.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, ViewChild } from '@angular/core'; +import { Component, OnInit, Input, ViewChild, signal } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Router, NavigationEnd } from '@angular/router'; @@ -19,32 +19,32 @@ import { ScreenService, ThemeService } from '../../shared/services'; }) export class SideNavOuterToolbarComponent implements OnInit { @ViewChild(DxScrollViewComponent, { static: true }) scrollView!: DxScrollViewComponent; - selectedRoute = ''; + selectedRoute = signal(''); - menuOpened!: boolean; - temporaryMenuOpened = false; + menuOpened = signal(false); + temporaryMenuOpened = signal(false); @Input() title!: string; - menuMode: DxDrawerTypes.OpenedStateMode = 'shrink'; - menuRevealMode: DxDrawerTypes.RevealMode = 'expand'; - minMenuSize = 0; - shaderEnabled = false; - swatchClassName = 'dx-swatch-additional'; + menuMode = signal('shrink'); + menuRevealMode = signal('expand'); + minMenuSize = signal(0); + shaderEnabled = signal(false); + swatchClassName = signal('dx-swatch-additional'); constructor(protected themeService: ThemeService, private screen: ScreenService, private router: Router) { themeService.isDark.subscribe((isDark) => { - this.swatchClassName = 'dx-swatch-additional' + (isDark ? '-dark' : ''); + this.swatchClassName.set('dx-swatch-additional' + (isDark ? '-dark' : '')); }) } ngOnInit() { - this.menuOpened = this.screen.sizes['screen-large']; + this.menuOpened.set(this.screen.sizes['screen-large']); this.router.events.subscribe(val => { if (val instanceof NavigationEnd) { - this.selectedRoute = val.urlAfterRedirects.split('?')[0]; + this.selectedRoute.set(val.urlAfterRedirects.split('?')[0]); } }); @@ -57,25 +57,25 @@ export class SideNavOuterToolbarComponent implements OnInit { const isXSmall = this.screen.sizes['screen-x-small']; const isLarge = this.screen.sizes['screen-large']; - this.menuMode = isLarge ? 'shrink' : 'overlap'; - this.menuRevealMode = isXSmall ? 'slide' : 'expand'; - this.minMenuSize = isXSmall ? 0 : 60; - this.shaderEnabled = !isLarge; + this.menuMode.set(isLarge ? 'shrink' : 'overlap'); + this.menuRevealMode.set(isXSmall ? 'slide' : 'expand'); + this.minMenuSize.set(isXSmall ? 0 : 60); + this.shaderEnabled.set(!isLarge); } get hideMenuAfterNavigation() { - return this.menuMode === 'overlap' || this.temporaryMenuOpened; + return this.menuMode() === 'overlap' || this.temporaryMenuOpened(); } get showMenuAfterClick() { - return !this.menuOpened; + return !this.menuOpened(); } navigationChanged(event: DxTreeViewTypes.ItemClickEvent) { const path = (event.itemData as any).path; const pointerEvent = event.event; - if (path && this.menuOpened) { + if (path && this.menuOpened()) { if (event.node?.selected) { pointerEvent?.preventDefault(); } else { @@ -84,8 +84,8 @@ export class SideNavOuterToolbarComponent implements OnInit { } if (this.hideMenuAfterNavigation) { - this.temporaryMenuOpened = false; - this.menuOpened = false; + this.temporaryMenuOpened.set(false); + this.menuOpened.set(false); pointerEvent?.stopPropagation(); } } else { @@ -95,8 +95,8 @@ export class SideNavOuterToolbarComponent implements OnInit { navigationClick() { if (this.showMenuAfterClick) { - this.temporaryMenuOpened = true; - this.menuOpened = true; + this.temporaryMenuOpened.set(true); + this.menuOpened.set(true); } } } diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.html b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.html index 4b1c42e7d..be7e10fb2 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.html +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.html @@ -1,5 +1,5 @@
- + @@ -23,7 +23,7 @@
- @if (loading) { + @if (loading()) { } @else {
Continue
diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.ts index b262481f9..df97a11d6 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/change-password-form/change-password-form.component.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, signal } from '@angular/core'; import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { ValidationCallbackData } from 'devextreme-angular/common'; import { DxFormModule } from 'devextreme-angular/ui/form'; @@ -20,7 +20,7 @@ import { AuthService } from '../../services'; ] }) export class ChangePasswordFormComponent implements OnInit { - loading = false; + loading = signal(false); formData: any = {}; recoveryCode: string = ''; @@ -35,10 +35,10 @@ export class ChangePasswordFormComponent implements OnInit { async onSubmit(e: Event) { e.preventDefault(); const { password } = this.formData; - this.loading = true; + this.loading.set(true); const result = await this.authService.changePassword(password, this.recoveryCode); - this.loading = false; + this.loading.set(false); if (result.isOk) { this.router.navigate(['/login-form']); diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.html b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.html index 5e7ae555f..e1ad51fc3 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.html +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.html @@ -1,5 +1,5 @@ - + @@ -37,7 +37,7 @@
- @if (loading) { + @if (loading()) { } @else {
Create a new account
diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.ts index f2e49fbde..54179a724 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/create-account-form/create-account-form.component.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { Component } from '@angular/core'; +import { Component, signal } from '@angular/core'; import { Router, RouterModule } from '@angular/router'; import { ValidationCallbackData } from 'devextreme-angular/common'; import { DxFormModule } from 'devextreme-angular/ui/form'; @@ -21,7 +21,7 @@ import { AuthService } from '../../services'; ] }) export class CreateAccountFormComponent { - loading = false; + loading = signal(false); formData: any = {}; constructor(private authService: AuthService, private router: Router) { } @@ -29,10 +29,10 @@ export class CreateAccountFormComponent { async onSubmit(e: Event) { e.preventDefault(); const { email, password } = this.formData; - this.loading = true; + this.loading.set(true); const result = await this.authService.createAccount(email, password); - this.loading = false; + this.loading.set(false); if (result.isOk) { this.router.navigate(['/login-form']); diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/header/header.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/header/header.component.ts index 6f88303e5..510774d57 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/header/header.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/header/header.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core'; +import { Component, Input, Output, EventEmitter, OnInit, signal } from '@angular/core'; import { Router } from '@angular/router'; import { CommonModule } from '@angular/common'; import { DxButtonModule } from 'devextreme-angular/ui/button'; @@ -32,7 +32,7 @@ export class HeaderComponent implements OnInit { @Input() title!: string; - user: IUser | null = { email: '' }; + user = signal({ email: '' }); userMenuItems = [{ text: 'Profile', @@ -52,7 +52,7 @@ export class HeaderComponent implements OnInit { constructor(private authService: AuthService, private router: Router) { } ngOnInit() { - this.authService.getUser().then((e) => this.user = e.data); + this.authService.getUser().then((e) => this.user.set(e.data)); } toggleMenu = () => { diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.html b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.html index 7f5e1269a..91f2f1fcf 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.html +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.html @@ -1,5 +1,5 @@ - + @@ -27,7 +27,7 @@
- @if (loading) { + @if (loading()) { } @else {
Sign In
diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.ts index 142a7e92b..30d983cd2 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/login-form/login-form.component.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { Component } from '@angular/core'; +import { Component, signal } from '@angular/core'; import { Router, RouterModule } from '@angular/router'; import { DxFormModule } from 'devextreme-angular/ui/form'; import { DxButtonModule } from 'devextreme-angular/ui/button'; @@ -22,7 +22,7 @@ import { AuthService } from '../../services'; ] }) export class LoginFormComponent { - loading = false; + loading = signal(false); formData: any = {}; constructor(private authService: AuthService, private router: Router) { } @@ -30,11 +30,11 @@ export class LoginFormComponent { async onSubmit(e: Event) { e.preventDefault(); const { email, password } = this.formData; - this.loading = true; + this.loading.set(true); const result = await this.authService.logIn(email, password); if (!result.isOk) { - this.loading = false; + this.loading.set(false); notify(result.message, 'error', 2000); } } diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.html b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.html index 59dc77f04..faa442468 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.html +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.html @@ -1,5 +1,5 @@ - + @@ -17,7 +17,7 @@
- @if (loading) { + @if (loading()) { } @else {
Reset my password
diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.ts index 61765c29b..525824694 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/components/reset-password-form/reset-password-form.component.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { Component } from '@angular/core'; +import { Component, signal } from '@angular/core'; import { Router, RouterModule } from '@angular/router'; import { DxFormModule } from 'devextreme-angular/ui/form'; import { DxLoadIndicatorModule } from 'devextreme-angular/ui/load-indicator'; @@ -21,7 +21,7 @@ const notificationText = 'We\'ve sent a link to reset your password. Check your ] }) export class ResetPasswordFormComponent { - loading = false; + loading = signal(false); formData: any = {}; constructor(private authService: AuthService, private router: Router) { } @@ -29,10 +29,10 @@ export class ResetPasswordFormComponent { async onSubmit(e: Event) { e.preventDefault(); const { email } = this.formData; - this.loading = true; + this.loading.set(true); const result = await this.authService.resetPassword(email); - this.loading = false; + this.loading.set(false); if (result.isOk) { this.router.navigate(['/login-form']); diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/app-info.service.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/app-info.service.ts index bf39e60a6..bd7390b38 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/app-info.service.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/app-info.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; -@Injectable() +@Injectable({ providedIn: 'root' }) export class AppInfoService { constructor() {} diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/auth.service.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/auth.service.ts index 162c00558..b04249b86 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/auth.service.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/auth.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, signal } from '@angular/core'; import { CanActivate, Router, ActivatedRouteSnapshot } from '@angular/router'; export interface IUser { @@ -12,11 +12,11 @@ const defaultUser = { avatarUrl: 'https://js.devexpress.com/Demos/WidgetsGallery/JSDemos/images/employees/06.png' }; -@Injectable() +@Injectable({ providedIn: 'root' }) export class AuthService { - private _user: IUser | null = defaultUser; + private _user = signal(defaultUser); get loggedIn(): boolean { - return !!this._user; + return !!this._user(); } private _lastAuthenticatedPath: string = defaultPath; @@ -30,12 +30,12 @@ export class AuthService { try { // Send request - this._user = { ...defaultUser, email }; + this._user.set({ ...defaultUser, email }); this.router.navigate([this._lastAuthenticatedPath]); return { isOk: true, - data: this._user + data: this._user() }; } catch { @@ -52,7 +52,7 @@ export class AuthService { return { isOk: true, - data: this._user + data: this._user() }; } catch { @@ -113,12 +113,12 @@ export class AuthService { } async logOut() { - this._user = null; + this._user.set(null); this.router.navigate(['/login-form']); } } -@Injectable() +@Injectable({ providedIn: 'root' }) export class AuthGuardService implements CanActivate { constructor(private router: Router, private authService: AuthService) { } diff --git a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/screen.service.ts b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/screen.service.ts index 16de9f2ce..def101b36 100644 --- a/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/screen.service.ts +++ b/packages/devextreme-schematics/src/add-layout/files/src/app/shared/services/screen.service.ts @@ -1,14 +1,21 @@ -import { Output, Injectable, EventEmitter } from '@angular/core'; +import { Output, Injectable, EventEmitter, WritableSignal, signal } from '@angular/core'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; -@Injectable() +@Injectable({ providedIn: 'root' }) export class ScreenService { @Output() changed = new EventEmitter(); + private readonly _sizes: WritableSignal>; + constructor(private breakpointObserver: BreakpointObserver) { + this._sizes = signal(this.calculateSizes()); + this.breakpointObserver .observe([Breakpoints.XSmall, Breakpoints.Small, Breakpoints.Medium, Breakpoints.Large]) - .subscribe(() => this.changed.next(true)); + .subscribe(() => { + this._sizes.set(this.calculateSizes()); + this.changed.next(true); + }); } private isLargeScreen() { @@ -18,7 +25,7 @@ export class ScreenService { return isLarge || isXLarge; } - public get sizes(): Record { + private calculateSizes(): Record { return { 'screen-x-small': this.breakpointObserver.isMatched(Breakpoints.XSmall), 'screen-small': this.breakpointObserver.isMatched(Breakpoints.Small), @@ -26,4 +33,8 @@ export class ScreenService { 'screen-large': this.isLargeScreen(), }; } + + public get sizes(): Record { + return this._sizes(); + } } diff --git a/packages/devextreme-schematics/src/add-layout/index.ts b/packages/devextreme-schematics/src/add-layout/index.ts index 6b7fccc81..012e6442b 100644 --- a/packages/devextreme-schematics/src/add-layout/index.ts +++ b/packages/devextreme-schematics/src/add-layout/index.ts @@ -22,7 +22,7 @@ import { strings } from '@angular-devkit/core'; import { join, basename } from 'path'; -import { SemVer } from 'semver'; +import { coerce } from 'semver'; import { getApplicationPath, @@ -67,6 +67,7 @@ import { getWorkspace } from '@schematics/angular/utility/workspace'; import { Change } from '@schematics/angular/utility/change'; import { isAngularVersionHigherThan } from '../utility/angular-version'; +import { isZonelessApp } from '../utility/zone'; import { NodePackageInstallTask, RunSchematicTask } from '@angular-devkit/schematics/tasks'; const routes = [ @@ -181,6 +182,8 @@ async function addPolyfills(host: Tree, project: string, polyfills: string[]) { if (!buildOptions.polyfills) { buildOptions.polyfills = []; + } else if (!Array.isArray(buildOptions.polyfills)) { + buildOptions.polyfills = [buildOptions.polyfills]; } polyfills.forEach((polyfill) => { @@ -270,24 +273,31 @@ function hasRouting(host: Tree, sourcePath: string) { return host.exists(sourcePath + 'app.routes.ts'); } -function addPackagesToDependency(globalNgCliVersion: string) { - const version = new SemVer(globalNgCliVersion.replace(/\^|\~/g, '')); +function getCdkVersion(angularCoreVersion: string = '') { + if (angularCoreVersion.includes('next')) { + return 'next'; + } + + const version = coerce(angularCoreVersion); + return version ? `^${version.major}.0.0` : 'latest'; +} +function addPackagesToDependency(zoneless: boolean) { return (host: Tree) => { const zonejs = getPackageJsonDependency(host, 'zone.js'); + const angularCore = getPackageJsonDependency(host, '@angular/core'); addPackageJsonDependency(host, { type: NodeDependencyType.Default, name: '@angular/cdk', - version: version.raw.includes('next') || version.raw.includes('-rc') - ? 'next' : `^${version.major}.0.0` + version: getCdkVersion(angularCore?.version) }); - if (!zonejs) { + if (!zoneless && !zonejs) { addPackageJsonDependency(host, { type: NodeDependencyType.Default, name: 'zone.js', - version: version.major > 18 ? '~0.16.0' : '~0.14.0' + version: '~0.16.0' }); } @@ -397,6 +407,7 @@ export default function(options: any): Rule { const override = options.resolveConflicts === 'override'; const componentName = override ? 'app' : getComponentName(host, appPath); const pathToCss = sourcePath?.replace(/\/?(\w)+\/?/g, '../'); + const zoneless = await isZonelessApp(host, project, appPath); const templateOptions = { name: setPostfix(host, componentName), @@ -404,7 +415,8 @@ export default function(options: any): Rule { title, strings, path: pathToCss, - prefix + prefix, + zoneless }; const modifyContent = (templateContent: string, currentContent: string, filePath: string) => { @@ -427,10 +439,13 @@ export default function(options: any): Rule { addBuildThemeScript(), () => addCustomThemeStyles(host, options, sourcePath) as any, addViewportToBody(sourcePath), - addPackagesToDependency(options.globalNgCliVersion), - () => addPolyfills(host, options.project, ['zone.js']) + addPackagesToDependency(zoneless), ]; + if (!zoneless) { + rules.push(() => addPolyfills(host, options.project, ['zone.js']) as any); + } + if (options.updateBudgets) { rules.push(() => updateBudgets(host, options) as any); } diff --git a/packages/devextreme-schematics/src/add-layout/index_spec.ts b/packages/devextreme-schematics/src/add-layout/index_spec.ts index 04c3009ca..88f09bab7 100644 --- a/packages/devextreme-schematics/src/add-layout/index_spec.ts +++ b/packages/devextreme-schematics/src/add-layout/index_spec.ts @@ -32,8 +32,7 @@ describe('layout', () => { const options: any = { layout: 'side-nav-outer-toolbar', - resolveConflicts: 'override', - globalNgCliVersion: '^17.2.0' + resolveConflicts: 'override' }; const angularSchematicsCollection = require.resolve('../../node_modules/@schematics/angular/collection.json'); @@ -175,12 +174,25 @@ describe('layout', () => { expect(packageConfig.dependencies['@angular/cdk']).toBeDefined(); }); - it('should choose angular/cdk version such as angular/cli', async () => { - const runner = new SchematicTestRunner('schematics', collectionPath); - const tree = await runner.runSchematic('add-layout', options, appTree); - const packageConfig = JSON.parse(tree.readContent('package.json')); - - expect(packageConfig.dependencies['@angular/cdk']).toBe('^17.0.0'); + [ + { angularCore: '~21.2.0', cdk: '^21.0.0' }, + { angularCore: '^22.0.0', cdk: '^22.0.0' }, + { angularCore: '^22.0.0-next.3', cdk: 'next' }, + ].forEach(({ angularCore, cdk }) => { + it(`should choose angular/cdk ${cdk} for angular/core ${angularCore}`, async () => { + removePackageJsonDependency(appTree, '@angular/core'); + addPackageJsonDependency(appTree, { + type: NodeDependencyType.Default, + name: '@angular/core', + version: angularCore + }); + + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner.runSchematic('add-layout', options, appTree); + const packageConfig = JSON.parse(tree.readContent('package.json')); + + expect(packageConfig.dependencies['@angular/cdk']).toBe(cdk); + }); }); it('should update budgets if updateBudgets option is true', async () => { @@ -321,4 +333,83 @@ describe('layout', () => { expect(content).toContain('"inputFile": "src/themes/metadata.base.json",'); expect(content).toContain('"inputFile": "projects/testApp2/src/themes/metadata.base.json",'); }); + + describe('change detection', () => { + const zoneOptions = { ...options, resolveConflicts: 'override' }; + + const setPolyfills = (polyfills: string | string[]) => { + modifyJSONFile(appTree, './angular.json', config => { + config.projects.testApp.architect.build.options.polyfills = polyfills; + return config; + }); + }; + + const expectZoneApp = (tree: UnitTestTree) => { + const packageConfig = JSON.parse(tree.readContent('package.json')); + const appConfig = tree.readContent('/src/app/app.config.ts'); + + expect(packageConfig.dependencies['zone.js']).toBeDefined(); + expect(appConfig).toMatch(/import { ApplicationConfig, provideZoneChangeDetection } from '@angular\/core';/); + expect(appConfig).toMatch(/providers: \[\s+provideZoneChangeDetection\({ eventCoalescing: true }\),/); + }; + + it('should not add zone.js to a zoneless app', async () => { + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner.runSchematic('add-layout', zoneOptions, appTree); + + const packageConfig = JSON.parse(tree.readContent('package.json')); + const angularContent = JSON.parse(tree.readContent('/angular.json')); + const polyfills = angularContent.projects.testApp.architect.build.options.polyfills || []; + + expect(packageConfig.dependencies['zone.js']).toBeUndefined(); + expect(polyfills).not.toContain('zone.js'); + expect(tree.readContent('/src/app/app.config.ts')).not.toContain('provideZoneChangeDetection'); + }); + + it('should keep zone change detection if zone.js is in polyfills', async () => { + setPolyfills(['zone.js']); + + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner.runSchematic('add-layout', zoneOptions, appTree); + + expectZoneApp(tree); + }); + + it('should keep zone change detection if zone.js is imported in a polyfills file', async () => { + setPolyfills('src/polyfills.ts'); + appTree.create('/src/polyfills.ts', `import 'zone.js';`); + + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner.runSchematic('add-layout', zoneOptions, appTree); + + expectZoneApp(tree); + const angularContent = JSON.parse(tree.readContent('/angular.json')); + expect(angularContent.projects.testApp.architect.build.options.polyfills) + .toEqual(['src/polyfills.ts', 'zone.js']); + }); + + it('should keep zone change detection if zone.js is imported in main file', async () => { + const mainPath = '/src/main.ts'; + appTree.overwrite(mainPath, `import 'zone.js';\n${appTree.readContent(mainPath)}`); + + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner.runSchematic('add-layout', zoneOptions, appTree); + + expectZoneApp(tree); + }); + + it('should keep zone change detection if app config provides it', async () => { + appTree.create('/src/app/app.config.ts', [ + `import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';`, + `export const appConfig: ApplicationConfig = {`, + ` providers: [provideZoneChangeDetection()]`, + `};` + ].join('\n')); + + const runner = new SchematicTestRunner('schematics', collectionPath); + const tree = await runner.runSchematic('add-layout', zoneOptions, appTree); + + expectZoneApp(tree); + }); + }); }); diff --git a/packages/devextreme-schematics/src/add-layout/schema.json b/packages/devextreme-schematics/src/add-layout/schema.json index bfc3f8e0c..2d13f4a18 100644 --- a/packages/devextreme-schematics/src/add-layout/schema.json +++ b/packages/devextreme-schematics/src/add-layout/schema.json @@ -46,10 +46,6 @@ }, "updateBudgets": { "type": "boolean" - }, - "globalNgCliVersion": { - "type":"string", - "default": "17.2.0" } } } diff --git a/packages/devextreme-schematics/src/utility/angular-version.ts b/packages/devextreme-schematics/src/utility/angular-version.ts index 2c79b91eb..9f793157d 100644 --- a/packages/devextreme-schematics/src/utility/angular-version.ts +++ b/packages/devextreme-schematics/src/utility/angular-version.ts @@ -1,12 +1,12 @@ import { Tree } from '@angular-devkit/schematics'; -import { SemVer } from 'semver'; +import { coerce } from 'semver'; export function getAngularVersion(host: Tree): number { const packageJson = JSON.parse(host.read('package.json')?.toString() || '{}'); const angularCore = packageJson.dependencies?.['@angular/core']; - if (angularCore) { - const version = new SemVer(angularCore.replace(/\^|\~/g, '')); + const version = coerce(angularCore); + if (version) { return version.major; } diff --git a/packages/devextreme-schematics/src/utility/zone.ts b/packages/devextreme-schematics/src/utility/zone.ts new file mode 100644 index 000000000..b6d63f8f9 --- /dev/null +++ b/packages/devextreme-schematics/src/utility/zone.ts @@ -0,0 +1,30 @@ +import { Tree } from '@angular-devkit/schematics'; +import { getWorkspace } from '@schematics/angular/utility/workspace'; +import { join } from 'path'; + +function readFile(host: Tree, path?: string) { + return path && host.exists(path) ? host.read(path)!.toString() : ''; +} + +export async function isZonelessApp(host: Tree, projectName: string, appPath: string) { + const workspace = await getWorkspace(host); + const buildOptions = workspace.projects.get(projectName)?.targets.get('build')?.options || {}; + const mainPath = (buildOptions.browser || buildOptions.main) as string | undefined; + const bootstrapSource = readFile(host, join(appPath, 'app.config.ts')) + readFile(host, mainPath); + + if (/provideZoneChangeDetection\s*\(/.test(bootstrapSource)) { + return false; + } + + if (/provideZonelessChangeDetection\s*\(/.test(bootstrapSource)) { + return true; + } + + const hasZoneImport = (path?: string) => /['"]zone\.js['"]/.test(readFile(host, path)); + const polyfills = buildOptions.polyfills; + const polyfillList = (Array.isArray(polyfills) ? polyfills : [polyfills]).filter(Boolean) as string[]; + + return !hasZoneImport(mainPath) && !polyfillList.some((polyfill) => + polyfill === 'zone.js' || hasZoneImport(polyfill) + ); +}