create-sitecore-jss 22.10.0-canary.1 → 22.10.0-canary.10

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 (105) hide show
  1. package/LICENSE.MD +1 -1
  2. package/dist/templates/angular/angular.json +133 -133
  3. package/dist/templates/angular/package.json +118 -119
  4. package/dist/templates/angular/scripts/generate-component-factory/template.ts +1 -3
  5. package/dist/templates/angular/server.bundle.ts +3 -2
  6. package/dist/templates/angular/src/app/ViewBag.ts +4 -0
  7. package/dist/templates/angular/src/app/app.component.ts +10 -9
  8. package/dist/templates/angular/src/app/app.module.ts +3 -1
  9. package/dist/templates/angular/src/app/app.server.module.ts +2 -1
  10. package/dist/templates/angular/src/app/components/app-components.shared.module.ts +16 -3
  11. package/dist/templates/angular/src/app/components/content-block/content-block.component.ts +2 -1
  12. package/dist/templates/angular/src/app/i18n/jss-translation-client-loader.service.ts +3 -2
  13. package/dist/templates/angular/src/app/i18n/jss-translation-server-loader.service.ts +8 -4
  14. package/dist/templates/angular/src/app/injection-tokens.ts +13 -0
  15. package/dist/templates/angular/src/app/jss-context.server-side.service.ts +8 -10
  16. package/dist/templates/angular/src/app/jss-context.service.ts +6 -4
  17. package/dist/templates/angular/src/app/jss-graphql.module.ts +58 -48
  18. package/dist/templates/angular/src/app/jss-graphql.service.ts +6 -6
  19. package/dist/templates/angular/src/app/jss-meta.service.ts +3 -2
  20. package/dist/templates/angular/src/app/routing/layout/layout.component.ts +10 -4
  21. package/dist/templates/angular/src/app/routing/navigation/navigation.component.ts +3 -0
  22. package/dist/templates/angular/src/app/routing/not-found/not-found.component.ts +1 -1
  23. package/dist/templates/angular/src/app/routing/routing.module.ts +3 -4
  24. package/dist/templates/angular/src/app/routing/scripts/scripts.module.ts +1 -1
  25. package/dist/templates/angular-sxp/src/app/components/app-components.shared.module.ts +1 -3
  26. package/dist/templates/angular-sxp/src/app/components/graph-ql-connected-demo/graph-ql-connected-demo.component.html +41 -39
  27. package/dist/templates/angular-sxp/src/app/components/graph-ql-connected-demo/graph-ql-connected-demo.component.ts +5 -3
  28. package/dist/templates/angular-sxp/src/app/components/graph-ql-integrated-demo/graph-ql-integrated-demo.component.html +6 -4
  29. package/dist/templates/angular-sxp/src/app/components/graph-ql-integrated-demo/graph-ql-integrated-demo.component.ts +4 -4
  30. package/dist/templates/angular-sxp/src/app/components/graph-ql-layout/graph-ql-layout.component.html +3 -4
  31. package/dist/templates/angular-sxp/src/app/components/graph-ql-layout/graph-ql-layout.component.ts +4 -4
  32. package/dist/templates/angular-sxp/src/app/components/shared/styleguide-specimen/styleguide-specimen.component.ts +3 -4
  33. package/dist/templates/angular-sxp/src/app/components/styleguide-angular-lazy-loading/styleguide-angular-lazy-loading.component.ts +5 -5
  34. package/dist/templates/angular-sxp/src/app/components/styleguide-angular-lazy-loading/styleguide-angular-lazy-loading.module.ts +2 -5
  35. package/dist/templates/angular-sxp/src/app/components/styleguide-component-params/styleguide-component-params.component.html +8 -4
  36. package/dist/templates/angular-sxp/src/app/components/styleguide-component-params/styleguide-component-params.component.ts +2 -2
  37. package/dist/templates/angular-sxp/src/app/components/styleguide-custom-route-type/styleguide-custom-route-type.component.ts +5 -5
  38. package/dist/templates/angular-sxp/src/app/components/styleguide-edit-frame/styleguide-edit-frame.component.html +7 -3
  39. package/dist/templates/angular-sxp/src/app/components/styleguide-edit-frame/styleguide-edit-frame.component.ts +13 -4
  40. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-checkbox/styleguide-field-usage-checkbox.component.ts +2 -2
  41. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-content-list/styleguide-field-usage-content-list.component.html +20 -16
  42. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-content-list/styleguide-field-usage-content-list.component.ts +20 -3
  43. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-custom/styleguide-field-usage-custom.component.ts +2 -0
  44. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-date/styleguide-field-usage-date.component.ts +4 -1
  45. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-file/styleguide-field-usage-file.component.ts +3 -1
  46. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-image/styleguide-field-usage-image.component.ts +3 -1
  47. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-item-link/styleguide-field-usage-item-link.component.html +4 -4
  48. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-item-link/styleguide-field-usage-item-link.component.ts +4 -1
  49. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-link/styleguide-field-usage-link.component.ts +3 -1
  50. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-number/styleguide-field-usage-number.component.ts +2 -0
  51. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-rich-text/styleguide-field-usage-rich-text.component.ts +3 -1
  52. package/dist/templates/angular-sxp/src/app/components/styleguide-field-usage-text/styleguide-field-usage-text.component.ts +3 -1
  53. package/dist/templates/angular-sxp/src/app/components/styleguide-layout/styleguide-layout.component.html +12 -8
  54. package/dist/templates/angular-sxp/src/app/components/styleguide-layout/styleguide-layout.component.ts +2 -4
  55. package/dist/templates/angular-sxp/src/app/components/styleguide-layout-reuse/styleguide-layout-reuse.component.ts +3 -1
  56. package/dist/templates/angular-sxp/src/app/components/styleguide-layout-tabs/styleguide-layout-tabs.component.html +18 -15
  57. package/dist/templates/angular-sxp/src/app/components/styleguide-layout-tabs/styleguide-layout-tabs.component.ts +6 -4
  58. package/dist/templates/angular-sxp/src/app/components/styleguide-layout-tabs-tab/styleguide-layout-tabs-tab.component.html +2 -2
  59. package/dist/templates/angular-sxp/src/app/components/styleguide-layout-tabs-tab/styleguide-layout-tabs-tab.component.ts +4 -4
  60. package/dist/templates/angular-sxp/src/app/components/styleguide-multilingual/styleguide-multilingual.component.ts +7 -3
  61. package/dist/templates/angular-sxp/src/app/components/styleguide-route-fields/styleguide-route-fields.component.ts +5 -4
  62. package/dist/templates/angular-sxp/src/app/components/styleguide-section/styleguide-section.component.ts +2 -1
  63. package/dist/templates/angular-sxp/src/app/components/styleguide-sitecore-context/styleguide-sitecore-context.component.ts +7 -4
  64. package/dist/templates/angular-sxp/src/app/components/styleguide-tracking/styleguide-tracking.component.html +6 -2
  65. package/dist/templates/angular-sxp/src/app/components/styleguide-tracking/styleguide-tracking.component.ts +12 -12
  66. package/dist/templates/angular-sxp/src/app/jss-data-fetcher.service.ts +4 -2
  67. package/dist/templates/angular-sxp/src/app/routing/scripts/scripts.component.ts +10 -0
  68. package/dist/templates/angular-sxp/src/app/routing/scripts/scripts.module.ts +1 -1
  69. package/dist/templates/angular-sxp/src/app/routing/scripts/visitor-identification/visitor-identification.component.ts +6 -3
  70. package/dist/templates/angular-xmcloud/scripts/generate-component-factory/template.ts +1 -3
  71. package/dist/templates/angular-xmcloud/src/app/components/app-components.shared.module.ts +1 -2
  72. package/dist/templates/angular-xmcloud/src/app/components/column-splitter/column-splitter.component.html +6 -4
  73. package/dist/templates/angular-xmcloud/src/app/components/column-splitter/column-splitter.component.ts +4 -1
  74. package/dist/templates/angular-xmcloud/src/app/components/container/container.component.html +14 -5
  75. package/dist/templates/angular-xmcloud/src/app/components/container/container.component.ts +3 -0
  76. package/dist/templates/angular-xmcloud/src/app/components/image/image.component.html +21 -23
  77. package/dist/templates/angular-xmcloud/src/app/components/image/image.component.ts +5 -5
  78. package/dist/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html +11 -10
  79. package/dist/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts +3 -0
  80. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation-item.component.html +14 -17
  81. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation-item.component.ts +3 -3
  82. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation.component.html +3 -6
  83. package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation.component.ts +8 -5
  84. package/dist/templates/angular-xmcloud/src/app/components/page-content/page-content.component.ts +4 -4
  85. package/dist/templates/angular-xmcloud/src/app/components/partial-design-dynamic-placeholder/partial-design-dynamic-placeholder.component.ts +2 -0
  86. package/dist/templates/angular-xmcloud/src/app/components/promo/promo.component.html +4 -6
  87. package/dist/templates/angular-xmcloud/src/app/components/promo/promo.component.ts +3 -0
  88. package/dist/templates/angular-xmcloud/src/app/components/richtext/richtext.component.html +3 -4
  89. package/dist/templates/angular-xmcloud/src/app/components/richtext/richtext.component.ts +3 -0
  90. package/dist/templates/angular-xmcloud/src/app/components/row-splitter/row-splitter.component.html +10 -9
  91. package/dist/templates/angular-xmcloud/src/app/components/row-splitter/row-splitter.component.ts +3 -0
  92. package/dist/templates/angular-xmcloud/src/app/components/title/title.component.html +4 -5
  93. package/dist/templates/angular-xmcloud/src/app/components/title/title.component.ts +5 -5
  94. package/dist/templates/angular-xmcloud/src/app/jss-link.service.ts +2 -2
  95. package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.html +38 -36
  96. package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.ts +10 -6
  97. package/dist/templates/angular-xmcloud/src/app/routing/scripts/cdp-page-view.component.ts +2 -3
  98. package/dist/templates/angular-xmcloud/src/app/routing/scripts/cloud-sdk-init.component.ts +2 -2
  99. package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.component.ts +13 -0
  100. package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.module.ts +1 -2
  101. package/dist/templates/nextjs/src/lib/component-props/index.ts +40 -0
  102. package/dist/templates/nextjs/src/lib/page-props-factory/plugins/component-props.ts +4 -37
  103. package/dist/templates/nextjs-sxa/src/pages/404.tsx +30 -17
  104. package/dist/templates/nextjs-sxa/src/pages/500.tsx +30 -17
  105. package/package.json +2 -2
@@ -3,6 +3,7 @@ import { CommonModule } from '@angular/common';
3
3
  import { FormsModule } from '@angular/forms';
4
4
  import { TranslateModule } from '@ngx-translate/core';
5
5
  import { RouterModule } from '@angular/router';
6
+ import { StyleguideSpecimenComponent } from './shared/styleguide-specimen/styleguide-specimen.component';
6
7
  import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
7
8
 
8
9
  /*
@@ -13,8 +14,20 @@ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
13
14
  Don't want code generation? See ./.gitignore for instructions to turn it off.
14
15
  */
15
16
  @NgModule({
16
- imports: [CommonModule, TranslateModule, RouterModule, JssModule, FormsModule],
17
- exports: [CommonModule, TranslateModule, RouterModule, FormsModule],
18
- declarations: [],
17
+ imports: [
18
+ CommonModule,
19
+ TranslateModule,
20
+ RouterModule,
21
+ JssModule,
22
+ FormsModule,
23
+ StyleguideSpecimenComponent
24
+ ],
25
+ exports: [
26
+ CommonModule,
27
+ TranslateModule,
28
+ RouterModule,
29
+ FormsModule,
30
+ StyleguideSpecimenComponent
31
+ ],
19
32
  })
20
33
  export class AppComponentsSharedModule {}
@@ -1,9 +1,10 @@
1
1
  import { Component, Input } from '@angular/core';
2
- import { ComponentRendering } from '@sitecore-jss/sitecore-jss-angular';
2
+ import { ComponentRendering, JssModule } from '@sitecore-jss/sitecore-jss-angular';
3
3
 
4
4
  @Component({
5
5
  selector: 'app-content-block',
6
6
  templateUrl: './content-block.component.html',
7
+ imports: [JssModule]
7
8
  })
8
9
  export class ContentBlockComponent {
9
10
  @Input() rendering: ComponentRendering;
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @angular-eslint/prefer-inject */
1
2
  import { Injectable, TransferState } from '@angular/core';
2
3
  import { TranslateLoader } from '@ngx-translate/core';
3
4
  import { DictionaryPhrases } from '@sitecore-jss/sitecore-jss-angular';
@@ -8,8 +9,8 @@ import { dictionaryStateKey } from './jss-translation-server-loader.service';
8
9
  @Injectable()
9
10
  export class JssTranslationClientLoaderService implements TranslateLoader {
10
11
  constructor(
11
- private fallbackLoader: JssTranslationLoaderService,
12
- private transferState: TransferState
12
+ protected fallbackLoader: JssTranslationLoaderService,
13
+ protected transferState: TransferState
13
14
  ) {}
14
15
 
15
16
  getTranslation(lang: string): Observable<DictionaryPhrases> {
@@ -1,4 +1,5 @@
1
- import { Inject, Injectable, makeStateKey, StateKey, TransferState } from '@angular/core';
1
+ /* eslint-disable @angular-eslint/prefer-inject */
2
+ import { Injectable, makeStateKey, StateKey, TransferState } from '@angular/core';
2
3
  import { TranslateLoader } from '@ngx-translate/core';
3
4
  import { DictionaryPhrases } from '@sitecore-jss/sitecore-jss-angular';
4
5
  import { of as observableOf, EMPTY } from 'rxjs';
@@ -11,10 +12,13 @@ export const dictionaryStateKey: StateKey<DictionaryPhrases> = makeStateKey<Dict
11
12
  export class JssTranslationServerLoaderService implements TranslateLoader {
12
13
  constructor(
13
14
  // this initial state from sitecore is injected by server.bundle for "integrated" mode
14
- @Inject('JSS_SERVER_VIEWBAG')
15
- private serverViewBag: { [key: string]: unknown; dictionary: DictionaryPhrases },
16
- private transferState: TransferState
15
+ protected serverViewBag: {
16
+ [key: string]: unknown;
17
+ dictionary: { [key: string]: string };
18
+ },
19
+ protected transferState: TransferState
17
20
  ) {}
21
+
18
22
  getTranslation(_lang: string) {
19
23
  // read initial dictionary from data injected via server.bundle wrapper
20
24
  const dictionary = this.serverViewBag.dictionary;
@@ -0,0 +1,13 @@
1
+ import { InjectionToken } from '@angular/core';
2
+ import { InMemoryCache } from '@apollo/client/core';
3
+ import { JssState } from './JssState';
4
+ import { ViewBag } from './ViewBag';
5
+
6
+ /**
7
+ * Injection token for server-side layout data provided by server.bundle
8
+ */
9
+ export const JSS_SERVER_LAYOUT_DATA = new InjectionToken<JssState>('JSS_SERVER_LAYOUT_DATA');
10
+
11
+ export const JSS_SERVER_VIEWBAG = new InjectionToken<ViewBag>('JSS_SERVER_VIEWBAG');
12
+
13
+ export const APOLLO_CACHE = new InjectionToken<InMemoryCache>('APOLLO_CACHE');
@@ -1,9 +1,10 @@
1
- import { Injectable, Inject, TransferState } from '@angular/core';
1
+ import { Injectable, inject, TransferState } from '@angular/core';
2
2
  import { JssContextService, jssKey } from './jss-context.service';
3
3
  import { JssState } from './JssState';
4
4
  import { Observable, of as observableOf } from 'rxjs';
5
5
  import { JssLayoutService } from './layout/jss-layout.service';
6
6
  import { JssStateService } from '@sitecore-jss/sitecore-jss-angular';
7
+ import { JSS_SERVER_LAYOUT_DATA } from './injection-tokens';
7
8
 
8
9
  /**
9
10
  * Stores the JSS app's context (current route and Sitecore context data).
@@ -12,15 +13,12 @@ import { JssStateService } from '@sitecore-jss/sitecore-jss-angular';
12
13
  */
13
14
  @Injectable()
14
15
  export class JssContextServerSideService extends JssContextService {
15
- constructor(
16
- protected transferState: TransferState,
17
- protected layoutService: JssLayoutService,
18
- protected stateService: JssStateService<JssState>,
19
- // this initial state from sitecore is injected by server.bundle for "integrated" mode
20
- @Inject('JSS_SERVER_LAYOUT_DATA') private serverToSsrState: JssState
21
- ) {
22
- super(transferState, layoutService, stateService);
23
- }
16
+ protected transferState = inject(TransferState);
17
+ protected layoutService = inject(JssLayoutService);
18
+ // this initial state from sitecore is injected by server.bundle for "integrated" mode
19
+ protected stateService = inject(JssStateService<JssState>);
20
+ protected serverToSsrState = inject(JSS_SERVER_LAYOUT_DATA);
21
+
24
22
  changeRoute(_route: string, _language: string): Observable<JssState> {
25
23
  // console.log('Server route change to ' + route);
26
24
 
@@ -1,4 +1,4 @@
1
- import { Injectable, TransferState, makeStateKey } from '@angular/core';
1
+ import { Injectable, TransferState, makeStateKey, inject } from '@angular/core';
2
2
  import { LayoutServiceData, JssStateService } from '@sitecore-jss/sitecore-jss-angular';
3
3
  import { map, shareReplay, catchError } from 'rxjs/operators';
4
4
  import { Observable, of as observableOf } from 'rxjs';
@@ -22,8 +22,10 @@ export class JssContextService {
22
22
  get stateValue() {
23
23
  return this.stateService.stateValue;
24
24
  }
25
- constructor(protected transferState: TransferState, protected layoutService: JssLayoutService, protected stateService: JssStateService<JssState>) {
26
- }
25
+
26
+ protected transferState = inject(TransferState);
27
+ protected layoutService = inject(JssLayoutService);
28
+ protected stateService = inject(JssStateService<JssState>);
27
29
 
28
30
  changeLanguage(language: string) {
29
31
  this.stateService.setState({ ...this.stateService.stateValue, language });
@@ -63,7 +65,7 @@ export class JssContextService {
63
65
  );
64
66
 
65
67
  // subscribe to it ourselves so we can maintain current state
66
- jssState$.subscribe((jssState) => {
68
+ jssState$.subscribe((jssState: JssState) => {
67
69
  this.stateService.setState(jssState);
68
70
  });
69
71
 
@@ -1,7 +1,7 @@
1
- import { makeStateKey, TransferState, NgModule, PLATFORM_ID, Inject } from '@angular/core';
1
+ import { makeStateKey, TransferState, NgModule, PLATFORM_ID, inject } from '@angular/core';
2
2
  import { HttpClientModule, HttpHeaders } from '@angular/common/http';
3
3
  import { InMemoryCache, NormalizedCacheObject, PossibleTypesMap } from '@apollo/client/core';
4
- import { Apollo, ApolloModule } from 'apollo-angular';
4
+ import { Apollo, provideApollo } from 'apollo-angular';
5
5
  import { HttpBatchLink } from 'apollo-angular/http';
6
6
  import { isPlatformServer } from '@angular/common';
7
7
  import { environment } from '../environments/environment';
@@ -14,28 +14,73 @@ import { JssGraphQLService } from './jss-graphql.service';
14
14
  If this file does not exist, you may need to run the `jss graphql:update` script.
15
15
  */
16
16
  import introspectionQueryResultData from '../graphql-fragment-types';
17
+ import { APOLLO_CACHE } from './injection-tokens';
17
18
 
18
19
  // SSR transfer state key to serialize + rehydrate apollo cache on client side
19
20
  // See https://www.apollographql.com/docs/angular/recipes/server-side-rendering.html
20
21
  const STATE_KEY = makeStateKey<NormalizedCacheObject>('apollo.state');
21
22
 
23
+ const getGraphQLCache = () => {
24
+ const possibleTypes = {} as PossibleTypesMap;
25
+ introspectionQueryResultData.__schema.types.forEach((supertype) => {
26
+ possibleTypes[supertype.name] = supertype.possibleTypes.map((subtype) => subtype.name);
27
+ });
28
+ return new InMemoryCache({
29
+ possibleTypes,
30
+ });
31
+ };
32
+
33
+ const getApolloOptions = () => {
34
+ const httpLink = inject(HttpBatchLink);
35
+ const platformId = inject(PLATFORM_ID);
36
+ /*
37
+ QUERY LINK SELECTION
38
+ A link is transport which GraphQL queries are pushed across.
39
+ You have many choices.
40
+ See the apollo-link documentation for more details.
41
+ */
42
+
43
+ // set sc_apikey header which is required for any GraphQL calls
44
+ const sc_apikey = new HttpHeaders().set('sc_apikey', environment.sitecoreApiKey);
45
+
46
+ // choose between a basic HTTP link to run queries...
47
+ // import { createHttpLink } from 'apollo-angular-link-http';
48
+ // const link = createHttpLink({ uri: endpoint });
49
+
50
+ // ...or a batched link (multiple queries within 10ms all go in one HTTP request)
51
+ const batchHttp = httpLink.create({
52
+ uri: environment.graphQLEndpoint,
53
+ headers: sc_apikey,
54
+ });
55
+
56
+ const cache = inject(APOLLO_CACHE);
57
+
58
+ return {
59
+ link: batchHttp,
60
+ cache,
61
+ ssrMode: isPlatformServer(platformId),
62
+ ssrForceFetchDelay: 100,
63
+ };
64
+ }
65
+
22
66
  @NgModule({
23
67
  imports: [
24
- ApolloModule,
25
68
  HttpClientModule, // provides HttpClient for HttpLink
26
69
  ],
27
- providers: [JssGraphQLService],
70
+ providers: [
71
+ JssGraphQLService,
72
+ { provide: APOLLO_CACHE, useValue: getGraphQLCache() },
73
+ provideApollo(getApolloOptions),
74
+ ],
28
75
  })
29
76
  export class GraphQLModule {
30
- constructor(
31
- private readonly apollo: Apollo,
32
- private readonly httpLink: HttpBatchLink,
33
- private readonly transferState: TransferState,
34
- @Inject(PLATFORM_ID) private readonly platformId: string
35
- ) {
36
- this.createApolloClient();
77
+ constructor() {
78
+ this.addCacheEvents();
37
79
  }
38
80
 
81
+ private readonly transferState = inject(TransferState);
82
+ apolloClient = inject(Apollo);
83
+
39
84
  onServer(cache: InMemoryCache) {
40
85
  this.transferState.onSerialize(STATE_KEY, () => cache.extract());
41
86
  }
@@ -46,43 +91,8 @@ export class GraphQLModule {
46
91
  cache.restore(state);
47
92
  }
48
93
 
49
- private createApolloClient(): void {
50
- /*
51
- QUERY LINK SELECTION
52
- A link is transport which GraphQL queries are pushed across.
53
- You have many choices.
54
- See the apollo-link documentation for more details.
55
- */
56
-
57
- // set sc_apikey header which is required for any GraphQL calls
58
- const sc_apikey = new HttpHeaders().set('sc_apikey', environment.sitecoreApiKey);
59
-
60
- // choose between a basic HTTP link to run queries...
61
- // import { createHttpLink } from 'apollo-angular-link-http';
62
- // const link = createHttpLink({ uri: endpoint });
63
-
64
- // ...or a batched link (multiple queries within 10ms all go in one HTTP request)
65
- const batchHttp = this.httpLink.create({
66
- uri: environment.graphQLEndpoint,
67
- headers: sc_apikey,
68
- });
69
-
70
- const possibleTypes = {} as PossibleTypesMap;
71
-
72
- introspectionQueryResultData.__schema.types.forEach((supertype) => {
73
- possibleTypes[supertype.name] = supertype.possibleTypes.map((subtype) => subtype.name);
74
- });
75
-
76
- const cache = new InMemoryCache({
77
- possibleTypes,
78
- });
79
-
80
- this.apollo.create({
81
- link: batchHttp,
82
- cache,
83
- ssrMode: isPlatformServer(this.platformId),
84
- ssrForceFetchDelay: 100,
85
- });
94
+ private addCacheEvents(): void {
95
+ const cache = inject(APOLLO_CACHE);
86
96
 
87
97
  const isBrowser = this.transferState.hasKey(STATE_KEY);
88
98
 
@@ -1,4 +1,4 @@
1
- import { Injectable, PLATFORM_ID, Inject, } from '@angular/core';
1
+ import { Injectable, PLATFORM_ID, inject, } from '@angular/core';
2
2
  import { Apollo } from 'apollo-angular';
3
3
  import { ExtraSubscriptionOptions, EmptyObject, MutationResult } from 'apollo-angular/types';
4
4
  import {
@@ -36,16 +36,16 @@ export interface JssGraphQLOptions {
36
36
  export class JssGraphQLService {
37
37
  private isEditingOrPreviewingAndSsr: boolean;
38
38
 
39
- constructor(
40
- private readonly apollo: Apollo,
41
- private readonly sitecoreContext: JssContextService,
42
- @Inject(PLATFORM_ID) private readonly platformId: string,
43
- ) {
39
+ constructor() {
44
40
  this.isEditingOrPreviewingAndSsr =
45
41
  isPlatformServer(this.platformId) &&
46
42
  this.sitecoreContext.stateValue.sitecore.context.pageState !== 'normal';
47
43
  }
48
44
 
45
+ protected apollo = inject(Apollo);
46
+ protected sitecoreContext = inject(JssContextService);
47
+ protected platformId = inject(PLATFORM_ID);
48
+
49
49
  private static extractVariableNames(query: DocumentNode) {
50
50
  const variableNames: { [key: string]: boolean } = {};
51
51
  query.definitions
@@ -1,4 +1,4 @@
1
- import { Injectable } from '@angular/core';
1
+ import { Injectable, inject } from '@angular/core';
2
2
  import { Meta, Title } from '@angular/platform-browser';
3
3
 
4
4
  export interface MetaSettings {
@@ -7,7 +7,8 @@ export interface MetaSettings {
7
7
 
8
8
  @Injectable()
9
9
  export class JssMetaService {
10
- constructor(private titleService: Title, private meta: Meta) {}
10
+ protected titleService = inject(Title);
11
+ protected meta = inject(Meta);
11
12
 
12
13
  setTitle(title?: string) {
13
14
  this.titleService.setTitle(title);
@@ -1,10 +1,15 @@
1
1
  /* eslint-disable no-shadow, no-console */
2
- import { Component, OnInit, OnDestroy } from '@angular/core';
3
- import { RouteData, Field, LayoutServiceContextData } from '@sitecore-jss/sitecore-jss-angular';
2
+ import { Component, OnInit, OnDestroy, inject } from '@angular/core';
3
+ import { CommonModule } from '@angular/common';
4
+ import { RouteData, Field, LayoutServiceContextData, JssModule } from '@sitecore-jss/sitecore-jss-angular';
4
5
  import { ActivatedRoute } from '@angular/router';
5
6
  import { Subscription } from 'rxjs';
6
7
  import { JssState } from '../../JssState';
7
8
  import { JssMetaService } from '../../jss-meta.service';
9
+ import { NotFoundComponent } from '../not-found/not-found.component';
10
+ import { ServerErrorComponent } from '../server-error/server-error.component';
11
+ import { ScriptsComponent } from '../scripts/scripts.component';
12
+ import { NavigationComponent } from '../navigation/navigation.component';
8
13
 
9
14
  enum LayoutState {
10
15
  Layout,
@@ -20,6 +25,7 @@ interface RouteFields {
20
25
  @Component({
21
26
  selector: 'app-layout',
22
27
  templateUrl: './layout.component.html',
28
+ imports: [CommonModule, JssModule, NotFoundComponent, ServerErrorComponent, ScriptsComponent, NavigationComponent]
23
29
  })
24
30
  export class LayoutComponent implements OnInit, OnDestroy {
25
31
  route: RouteData<RouteFields>;
@@ -27,8 +33,8 @@ export class LayoutComponent implements OnInit, OnDestroy {
27
33
  LayoutState = LayoutState;
28
34
  subscription: Subscription;
29
35
  errorContextData: LayoutServiceContextData;
30
-
31
- constructor(private activatedRoute: ActivatedRoute, private readonly meta: JssMetaService) {}
36
+ private activatedRoute = inject(ActivatedRoute);
37
+ private readonly meta = inject(JssMetaService);
32
38
 
33
39
  ngOnInit() {
34
40
  // route data is populated by the JssRouteResolver
@@ -1,7 +1,10 @@
1
1
  import { Component } from '@angular/core';
2
+ import { RouterModule } from '@angular/router';
3
+ import { TranslateModule } from '@ngx-translate/core';
2
4
 
3
5
  @Component({
4
6
  selector: 'app-navigation',
5
7
  templateUrl: './navigation.component.html',
8
+ imports: [RouterModule, TranslateModule]
6
9
  })
7
10
  export class NavigationComponent {}
@@ -3,7 +3,7 @@ import { LayoutServiceContextData } from '@sitecore-jss/sitecore-jss-angular';
3
3
 
4
4
  @Component({
5
5
  selector: 'app-not-found',
6
- templateUrl: './not-found.component.html',
6
+ templateUrl: './not-found.component.html'
7
7
  })
8
8
  export class NotFoundComponent {
9
9
  @Input() errorContextData: LayoutServiceContextData;
@@ -7,9 +7,7 @@ import { jssRouteResolver } from './jss-route-resolver.service';
7
7
  import { JssRouteBuilderService } from './jss-route-builder.service';
8
8
  import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
9
9
  import { BrowserModule } from '@angular/platform-browser';
10
- import { NavigationComponent } from './navigation/navigation.component';
11
10
  import { TranslateModule } from '@ngx-translate/core';
12
- import { ScriptsModule } from './scripts/scripts.module';
13
11
 
14
12
  export function jssRouteMatcher(url: UrlSegment[]): UrlMatchResult {
15
13
  // use the route builder to parse out language / server route
@@ -54,10 +52,11 @@ const routes: Routes = [
54
52
  JssModule,
55
53
  TranslateModule,
56
54
  BrowserModule,
57
- ScriptsModule,
55
+ LayoutComponent,
56
+ NotFoundComponent,
57
+ ServerErrorComponent,
58
58
  ],
59
59
  exports: [RouterModule, TranslateModule],
60
- declarations: [NotFoundComponent, ServerErrorComponent, LayoutComponent, NavigationComponent],
61
60
  providers: [JssRouteBuilderService],
62
61
  })
63
62
  export class RoutingModule {}
@@ -3,6 +3,6 @@ import { ScriptsComponent } from './scripts.component';
3
3
 
4
4
  @NgModule({
5
5
  exports: [ScriptsComponent],
6
- declarations: [ScriptsComponent],
6
+ imports: [ScriptsComponent],
7
7
  })
8
8
  export class ScriptsModule {}
@@ -20,6 +20,7 @@ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
20
20
  RouterModule,
21
21
  JssModule,
22
22
  FormsModule,
23
+ StyleguideSpecimenComponent
23
24
  ],
24
25
  exports: [
25
26
  CommonModule,
@@ -28,8 +29,5 @@ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
28
29
  FormsModule,
29
30
  StyleguideSpecimenComponent
30
31
  ],
31
- declarations: [
32
- StyleguideSpecimenComponent
33
- ],
34
32
  })
35
33
  export class AppComponentsSharedModule { }
@@ -9,47 +9,49 @@
9
9
  the cache. Consult the Apollo documentation for details.
10
10
  </p>
11
11
 
12
- <div *ngIf="query$ | async as queryResult; else loading">
12
+ @if (query$ | async; as queryResult) {
13
13
  <div>
14
- <h4>Datasource Item (via Connected GraphQL)</h4>
15
- id: {{ queryResult.data.datasource.id }}
16
- <br />
17
- name: {{ queryResult.data.datasource.name }}
18
- <br />
19
- sample1: {{ queryResult.data.datasource.sample1.value }}
20
- <br />
21
- sample1 (editable): <span *scText="queryResult.data.datasource.sample1.jsonValue"></span>
22
- <br />
23
- sample2:<br />
24
- <ul>
25
- <li>text: {{ queryResult.data.datasource.sample2.text }}</li>
26
- <li>url: {{ queryResult.data.datasource.sample2.url }}</li>
27
- <li>target: {{ queryResult.data.datasource.sample2.target }}</li>
28
- <li>
29
- editable: <a *scLink="queryResult.data.datasource.sample2.jsonValue"></a>
30
- </li>
31
- <li>field type: {{ queryResult.data.datasource.sample2.definition.type }}</li>
32
- <li>field is shared?: {{ queryResult.data.datasource.sample2.definition.shared.toString() }}</li>
33
- </ul>
34
- </div>
14
+ <div>
15
+ <h4>Datasource Item (via Connected GraphQL)</h4>
16
+ id: {{ queryResult.data.datasource.id }}
17
+ <br />
18
+ name: {{ queryResult.data.datasource.name }}
19
+ <br />
20
+ sample1: {{ queryResult.data.datasource.sample1.value }}
21
+ <br />
22
+ sample1 (editable): <span *scText="queryResult.data.datasource.sample1.jsonValue"></span>
23
+ <br />
24
+ sample2:<br />
25
+ <ul>
26
+ <li>text: {{ queryResult.data.datasource.sample2.text }}</li>
27
+ <li>url: {{ queryResult.data.datasource.sample2.url }}</li>
28
+ <li>target: {{ queryResult.data.datasource.sample2.target }}</li>
29
+ <li>
30
+ editable: <a *scLink="queryResult.data.datasource.sample2.jsonValue"></a>
31
+ </li>
32
+ <li>field type: {{ queryResult.data.datasource.sample2.definition.type }}</li>
33
+ <li>field is shared?: {{ queryResult.data.datasource.sample2.definition.shared.toString() }}</li>
34
+ </ul>
35
+ </div>
35
36
 
36
- <div>
37
- <h4>Route Item (via Connected GraphQL)</h4>
38
- id: {{ queryResult.data.contextItem.id }}
39
- <br />
40
- page title: {{ queryResult.data.contextItem.pageTitle.value }}
41
- <br />
42
- children:
43
- <ul>
44
- <li *ngFor="let child of queryResult.data.contextItem.children.results">
45
- <a [routerLink]="child.url.path">{{ child.pageTitle.value }}</a>
46
- (editable title too! <span *scText="child.pageTitle.jsonValue"></span>)
47
- </li>
48
- </ul>
37
+ <div>
38
+ <h4>Route Item (via Connected GraphQL)</h4>
39
+ id: {{ queryResult.data.contextItem.id }}
40
+ <br />
41
+ page title: {{ queryResult.data.contextItem.pageTitle.value }}
42
+ <br />
43
+ children:
44
+ <ul>
45
+ @for (child of queryResult.data.contextItem.children.results; track child) {
46
+ <li>
47
+ <a [routerLink]="child.url.path">{{ child.pageTitle.value }}</a>
48
+ (editable title too! <span *scText="child.pageTitle.jsonValue"></span>)
49
+ </li>
50
+ }
51
+ </ul>
52
+ </div>
49
53
  </div>
50
- </div>
51
-
52
- <ng-template #loading>
54
+ } @else {
53
55
  <p class="alert alert-info">GraphQL query is loading...</p>
54
- </ng-template>
56
+ }
55
57
  </div>
@@ -1,5 +1,6 @@
1
- import { Component, Input, OnInit } from '@angular/core';
2
- import { ComponentRendering } from '@sitecore-jss/sitecore-jss-angular';
1
+ import { Component, Input, OnInit, inject } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { ComponentRendering, JssModule } from '@sitecore-jss/sitecore-jss-angular';
3
4
  import { DocumentNode } from 'graphql';
4
5
  import { JssGraphQLService } from '../../jss-graphql.service';
5
6
  import { ApolloQueryResult } from '@apollo/client/core';
@@ -14,6 +15,7 @@ const ComponentQuery: DocumentNode = require('graphql-tag/loader!./graph-ql-conn
14
15
  @Component({
15
16
  selector: 'app-graph-ql-connected-demo',
16
17
  templateUrl: './graph-ql-connected-demo.component.html',
18
+ imports: [CommonModule, JssModule]
17
19
  })
18
20
  export class GraphQLConnectedDemoComponent implements OnInit {
19
21
  @Input() rendering: ComponentRendering;
@@ -22,7 +24,7 @@ export class GraphQLConnectedDemoComponent implements OnInit {
22
24
  // inject the JssGraphQLService to make GraphQL queries
23
25
  // note that it's possible to use Apollo directly, but the JSS
24
26
  // service provides automatic GraphQL variables and SSR assistance.
25
- constructor(private graphQLService: JssGraphQLService) {}
27
+ private graphQLService = inject(JssGraphQLService);
26
28
 
27
29
  ngOnInit(): void {
28
30
  // the query result is an Rx Observable, so any observable patterns
@@ -38,10 +38,12 @@
38
38
  <br />
39
39
  children:
40
40
  <ul>
41
- <li *ngFor="let child of queryResult.data.contextItem.children.results">
42
- <a [routerLink]="child.url.path">{{ child.pageTitle.value }}</a>
43
- (editable title too! <span *scText="child.pageTitle.jsonValue"></span>)
44
- </li>
41
+ @for (child of queryResult.data.contextItem.children.results; track child) {
42
+ <li>
43
+ <a [routerLink]="child.url.path">{{ child.pageTitle.value }}</a>
44
+ (editable title too! <span *scText="child.pageTitle.jsonValue"></span>)
45
+ </li>
46
+ }
45
47
  </ul>
46
48
  </div>
47
49
  </div>
@@ -1,5 +1,6 @@
1
1
  import { Component, OnInit, Input } from '@angular/core';
2
- import { ComponentRendering } from '@sitecore-jss/sitecore-jss-angular';
2
+ import { CommonModule } from '@angular/common';
3
+ import { ComponentRendering, JssModule } from '@sitecore-jss/sitecore-jss-angular';
3
4
 
4
5
  interface QueryResult {
5
6
  data: {
@@ -63,13 +64,12 @@ interface ItemSearchResults {
63
64
  @Component({
64
65
  selector: 'app-graph-ql-integrated-demo',
65
66
  templateUrl: './graph-ql-integrated-demo.component.html',
67
+ imports: [CommonModule, JssModule]
66
68
  })
67
69
  export class GraphQLIntegratedDemoComponent implements OnInit {
68
70
  @Input() rendering: ComponentRendering;
69
71
  queryResult: QueryResult;
70
-
71
- constructor() {}
72
-
72
+
73
73
  ngOnInit() {
74
74
  this.queryResult = (this.rendering.fields as unknown) as QueryResult;
75
75
  }
@@ -1,5 +1,5 @@
1
1
  <div data-e2e-id="graphql-layout">
2
- <ng-container *ngIf="disconnectedMode">
2
+ @if (disconnectedMode) {
3
3
  <p>
4
4
  This app is running in disconnected mode. GraphQL requires connected mode, headless connected
5
5
  mode, or integrated mode to work.
@@ -12,11 +12,10 @@
12
12
  To view the GraphQL samples, restart the app using <code>jss start:connected</code>&nbsp; or
13
13
  deploy the app to Sitecore to run in integrated mode per the JSS documentation.
14
14
  </p>
15
- </ng-container>
16
- <ng-container *ngIf="!disconnectedMode">
15
+ } @else {
17
16
  <sc-placeholder
18
17
  name="<%- helper.getAppPrefix(appPrefix, appName) %>jss-graphql-layout"
19
18
  [rendering]="rendering"
20
19
  ></sc-placeholder>
21
- </ng-container>
20
+ }
22
21
  </div>