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
@@ -1,11 +1,15 @@
1
- import { Component, OnInit, OnDestroy } from '@angular/core';
1
+ import { Component, OnInit, OnDestroy, inject } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
4
  import { Subscription } from 'rxjs';
3
5
  import { SxaComponent } from '../sxa.component';
4
6
  import { JssContextService } from '../../jss-context.service';
7
+ import { NavigationItemComponent } from './navigation-item.component';
5
8
 
6
9
  @Component({
7
10
  selector: 'app-navigation',
8
11
  templateUrl: './navigation.component.html',
12
+ imports: [CommonModule, JssModule, NavigationItemComponent],
9
13
  host: {
10
14
  'class': 'component navigation',
11
15
  '[id]': 'id',
@@ -17,16 +21,15 @@ export class NavigationComponent extends SxaComponent implements OnInit, OnDestr
17
21
  private contextSubscription: Subscription;
18
22
  isOpenMenu = false;
19
23
  baseLevel = 1;
20
-
21
- constructor(private jssContext: JssContextService) {
22
- super();
23
- }
24
+ private jssContext = inject(JssContextService);
25
+ fieldKeys: string[];
24
26
 
25
27
  ngOnInit() {
26
28
  super.ngOnInit();
27
29
  this.contextSubscription = this.jssContext.state.subscribe((newState) => {
28
30
  this.isEditing = newState.sitecore && newState.sitecore.context.pageEditing;
29
31
  });
32
+ this.fieldKeys = Object.keys(this.rendering.fields || {});
30
33
  }
31
34
 
32
35
  ngOnDestroy() {
@@ -1,4 +1,5 @@
1
- import { Component, OnDestroy, OnInit } from '@angular/core';
1
+ import { Component, OnDestroy, OnInit, inject } from '@angular/core';
2
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
3
  import { RichTextField } from '@sitecore-jss/sitecore-jss-angular';
3
4
  import { JssContextService } from '../../jss-context.service';
4
5
  import { SxaComponent } from './../sxa.component';
@@ -7,6 +8,7 @@ import { Subscription } from 'rxjs';
7
8
  @Component({
8
9
  selector: 'app-page-content',
9
10
  templateUrl: './page-content.component.html',
11
+ imports: [JssModule],
10
12
  host: {
11
13
  'class': 'component content',
12
14
  '[class]': 'styles',
@@ -17,10 +19,8 @@ export class PageContentComponent extends SxaComponent implements OnInit, OnDest
17
19
  content?: RichTextField;
18
20
  contextContent?: RichTextField;
19
21
  private contextSubscription: Subscription;
22
+ private jssContext = inject(JssContextService);
20
23
 
21
- constructor(private jssContext: JssContextService) {
22
- super();
23
- }
24
24
  ngOnInit() {
25
25
  super.ngOnInit();
26
26
 
@@ -1,9 +1,11 @@
1
1
  import { Component, OnInit } from '@angular/core';
2
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
3
  import { SxaComponent } from '../sxa.component';
3
4
 
4
5
  @Component({
5
6
  selector: 'app-partial-design-dynamic-placeholder',
6
7
  templateUrl: './partial-design-dynamic-placeholder.component.html',
8
+ imports: [JssModule]
7
9
  })
8
10
  export class PartialDesignDynamicPlaceholderComponent extends SxaComponent implements OnInit {
9
11
  sig: string;
@@ -1,5 +1,5 @@
1
1
  <div class="component-content">
2
- <ng-container *ngIf="rendering.fields; else empty">
2
+ @if (rendering.fields) {
3
3
  <div class="field-promoicon">
4
4
  <img *scImage="rendering.fields.PromoIcon" />
5
5
  </div>
@@ -13,9 +13,7 @@
13
13
  <a *scGenericLink="rendering.fields.PromoLink"></a>
14
14
  </div>
15
15
  </div>
16
- </ng-container>
16
+ } @else {
17
+ <span className="is-empty-hint">Promo</span>
18
+ }
17
19
  </div>
18
-
19
- <ng-template #empty>
20
- <span className="is-empty-hint">Promo</span>
21
- </ng-template>
@@ -1,9 +1,12 @@
1
1
  import { Component } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
4
  import { SxaComponent } from '../sxa.component';
3
5
 
4
6
  @Component({
5
7
  selector: 'app-promo',
6
8
  templateUrl: './promo.component.html',
9
+ imports: [CommonModule, JssModule],
7
10
  host: {
8
11
  'class': 'component promo',
9
12
  '[class]': "styles",
@@ -1,8 +1,7 @@
1
1
  <div class="component-content">
2
- <ng-container *ngIf="text; else emptyHint">
2
+ @if (text) {
3
3
  <div *scRichText="text"></div>
4
- </ng-container>
5
- <ng-template #emptyHint>
4
+ } @else {
6
5
  <span class="is-empty-hint">Rich text</span>
7
- </ng-template>
6
+ }
8
7
  </div>
@@ -1,10 +1,13 @@
1
1
  import { Component, OnInit } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
4
  import { Field } from '@sitecore-jss/sitecore-jss-angular';
3
5
  import { SxaComponent } from '../sxa.component';
4
6
 
5
7
  @Component({
6
8
  selector: 'app-richtext',
7
9
  templateUrl: './richtext.component.html',
10
+ imports: [CommonModule, JssModule],
8
11
  host: {
9
12
  'class': 'component rich-text',
10
13
  '[class]': "styles",
@@ -1,11 +1,12 @@
1
- <div
2
- *ngFor="let ph of enabledPlaceholders"
3
- class="container-fluid"
4
- [ngClass]="getRowClass(+ph - 1)"
5
- >
6
- <div>
7
- <div class="row">
8
- <sc-placeholder [name]="getPlaceholderName(ph)" [rendering]="rendering"> </sc-placeholder>
1
+ @for (ph of enabledPlaceholders; track ph) {
2
+ <div
3
+ class="container-fluid"
4
+ [ngClass]="getRowClass(+ph - 1)"
5
+ >
6
+ <div>
7
+ <div class="row">
8
+ <sc-placeholder [name]="getPlaceholderName(ph)" [rendering]="rendering"> </sc-placeholder>
9
+ </div>
9
10
  </div>
10
11
  </div>
11
- </div>
12
+ }
@@ -1,9 +1,12 @@
1
1
  import { Component } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
4
  import { SxaComponent } from '../sxa.component';
3
5
 
4
6
  @Component({
5
7
  selector: 'app-row-splitter',
6
8
  templateUrl: './row-splitter.component.html',
9
+ imports: [CommonModule, JssModule],
7
10
  host: {
8
11
  "class": "component row-splitter",
9
12
  "[class]": "rowSplitterStyles",
@@ -1,10 +1,9 @@
1
1
  <div clas="component-content">
2
2
  <div class="field-title">
3
- <ng-container *ngIf="!pageEditing; else textOnly">
3
+ @if (!pageEditing) {
4
4
  <a *scGenericLink="link"></a>
5
- </ng-container>
5
+ } @else {
6
+ <span *scText="text"></span>
7
+ }
6
8
  </div>
7
9
  </div>
8
- <ng-template #textOnly>
9
- <span *scText="text"></span>
10
- </ng-template>
@@ -1,4 +1,6 @@
1
- import { Component, OnDestroy, OnInit } from '@angular/core';
1
+ import { Component, OnDestroy, OnInit, inject } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
2
4
  import { LinkField, SxaTitleFields, TextField } from '@sitecore-jss/sitecore-jss-angular';
3
5
  import { SxaComponent } from '../sxa.component';
4
6
  import { Subscription } from 'rxjs';
@@ -7,6 +9,7 @@ import { JssContextService } from '../../jss-context.service';
7
9
  @Component({
8
10
  selector: 'app-title',
9
11
  templateUrl: './title.component.html',
12
+ imports: [CommonModule, JssModule],
10
13
  host: {
11
14
  'class': 'component title',
12
15
  '[class]': 'styles',
@@ -19,10 +22,7 @@ export class TitleComponent extends SxaComponent<SxaTitleFields> implements OnIn
19
22
  pageEditing?: boolean;
20
23
 
21
24
  private contextSubscription: Subscription;
22
-
23
- constructor(private jssContext: JssContextService) {
24
- super();
25
- }
25
+ private jssContext = inject(JssContextService);
26
26
 
27
27
  ngOnInit() {
28
28
  super.ngOnInit();
@@ -1,4 +1,4 @@
1
- import { Inject, Injectable } from '@angular/core';
1
+ import { inject, Injectable } from '@angular/core';
2
2
  import { DOCUMENT } from '@angular/common';
3
3
  import { HTMLLink } from '@sitecore-jss/sitecore-jss-angular';
4
4
 
@@ -6,7 +6,7 @@ import { HTMLLink } from '@sitecore-jss/sitecore-jss-angular';
6
6
  providedIn: 'root',
7
7
  })
8
8
  export class JssLinkService {
9
- constructor(@Inject(DOCUMENT) private document: Document) {}
9
+ private document = inject(DOCUMENT);
10
10
 
11
11
  /**
12
12
  * Adds link element in the document head.
@@ -1,38 +1,40 @@
1
1
  <div class="{{ mainClassPageEditing }}">
2
- <ng-container *ngIf="state === LayoutState.Layout">
3
- <app-scripts></app-scripts>
4
- <header>
5
- <div id="header">
6
- <sc-placeholder
7
- name="headless-header"
8
- [rendering]="route"
9
- (loaded)="onPlaceholderLoaded($event)"
10
- ></sc-placeholder>
11
- </div>
12
- </header>
13
- <main>
14
- <div id="content">
15
- <sc-placeholder
16
- name="headless-main"
17
- [rendering]="route"
18
- (loaded)="onPlaceholderLoaded($event)"
19
- ></sc-placeholder>
20
- </div>
21
- </main>
22
- <footer>
23
- <div id="footer">
24
- <sc-placeholder
25
- name="headless-footer"
26
- [rendering]="route"
27
- (loaded)="onPlaceholderLoaded($event)"
28
- ></sc-placeholder>
29
- </div>
30
- </footer>
31
- </ng-container>
32
-
33
- <app-not-found
34
- *ngIf="state === LayoutState.NotFound"
35
- [errorContextData]="errorContextData"
36
- ></app-not-found>
37
- <app-server-error *ngIf="state === LayoutState.Error"></app-server-error>
2
+ @if (state === LayoutState.Layout) {
3
+ <ng-container>
4
+ <app-scripts></app-scripts>
5
+ <header>
6
+ <div id="header">
7
+ <sc-placeholder
8
+ name="headless-header"
9
+ [rendering]="route"
10
+ (loaded)="onPlaceholderLoaded($event)"
11
+ ></sc-placeholder>
12
+ </div>
13
+ </header>
14
+ <main>
15
+ <div id="content">
16
+ <sc-placeholder
17
+ name="headless-main"
18
+ [rendering]="route"
19
+ (loaded)="onPlaceholderLoaded($event)"
20
+ ></sc-placeholder>
21
+ </div>
22
+ </main>
23
+ <footer>
24
+ <div id="footer">
25
+ <sc-placeholder
26
+ name="headless-footer"
27
+ [rendering]="route"
28
+ (loaded)="onPlaceholderLoaded($event)"
29
+ ></sc-placeholder>
30
+ </div>
31
+ </footer>
32
+ </ng-container>
33
+ }
34
+ @if (state === LayoutState.NotFound) {
35
+ <app-not-found [errorContextData]="errorContextData"></app-not-found>
36
+ }
37
+ @if (state === LayoutState.Error) {
38
+ <app-server-error></app-server-error>
39
+ }
38
40
  </div>
@@ -1,17 +1,22 @@
1
1
  /* eslint-disable no-shadow, no-console */
2
- import { Component, OnInit, OnDestroy } from '@angular/core';
2
+ import { Component, OnInit, OnDestroy, inject } from '@angular/core';
3
3
  import {
4
4
  RouteData,
5
5
  Field,
6
6
  LayoutServiceContextData,
7
7
  getContentStylesheetLink,
8
+ JssModule,
8
9
  } from '@sitecore-jss/sitecore-jss-angular';
9
10
  import { ActivatedRoute } from '@angular/router';
10
11
  import { Subscription } from 'rxjs';
11
12
  import { JssState } from '../../JssState';
12
13
  import { JssMetaService } from '../../jss-meta.service';
13
14
  import { JssLinkService } from '../../jss-link.service';
15
+ import { NotFoundComponent } from '../not-found/not-found.component';
16
+ import { ServerErrorComponent } from '../server-error/server-error.component';
17
+ import { ScriptsComponent } from '../scripts/scripts.component';
14
18
  import { environment as env } from '../../../environments/environment';
19
+ import { CommonModule } from '@angular/common';
15
20
 
16
21
  enum LayoutState {
17
22
  Layout,
@@ -27,6 +32,7 @@ interface RouteFields {
27
32
  @Component({
28
33
  selector: 'app-layout',
29
34
  templateUrl: './layout.component.html',
35
+ imports: [CommonModule, JssModule, NotFoundComponent, ServerErrorComponent, ScriptsComponent],
30
36
  })
31
37
  export class LayoutComponent implements OnInit, OnDestroy {
32
38
  route: RouteData<RouteFields>;
@@ -36,11 +42,9 @@ export class LayoutComponent implements OnInit, OnDestroy {
36
42
  errorContextData: LayoutServiceContextData;
37
43
  mainClassPageEditing: string;
38
44
 
39
- constructor(
40
- private activatedRoute: ActivatedRoute,
41
- private readonly meta: JssMetaService,
42
- private linkService: JssLinkService
43
- ) {}
45
+ private activatedRoute = inject(ActivatedRoute);
46
+ private readonly meta = inject(JssMetaService);
47
+ private linkService = inject(JssLinkService);
44
48
 
45
49
  ngOnInit() {
46
50
  // route data is populated by the JssRouteResolver
@@ -1,4 +1,4 @@
1
- import { Component, OnInit, OnDestroy } from '@angular/core';
1
+ import { Component, OnInit, OnDestroy, inject } from '@angular/core';
2
2
  import { Subscription } from 'rxjs';
3
3
  import { isServer, CdpHelper, LayoutServicePageState } from '@sitecore-jss/sitecore-jss-angular';
4
4
  import { pageView, PageViewData } from '@sitecore-cloudsdk/events/browser';
@@ -18,8 +18,7 @@ import { environment } from '../../../environments/environment';
18
18
  })
19
19
  export class CdpPageViewComponent implements OnInit, OnDestroy {
20
20
  private contextSubscription: Subscription;
21
-
22
- constructor(private jssContext: JssContextService) {}
21
+ private jssContext = inject(JssContextService);
23
22
 
24
23
  ngOnInit(): void {
25
24
  if (!isServer()) {
@@ -1,4 +1,4 @@
1
- import { Component, OnInit } from '@angular/core';
1
+ import { Component, OnInit, inject } from '@angular/core';
2
2
  import { take } from 'rxjs/operators';
3
3
  import { CloudSDK } from '@sitecore-cloudsdk/core/browser';
4
4
  import '@sitecore-cloudsdk/events/browser';
@@ -15,7 +15,7 @@ import { JssState } from '../../JssState';
15
15
  template: '',
16
16
  })
17
17
  export class CloudSdkInitComponent implements OnInit {
18
- constructor(private jssContext: JssContextService) {}
18
+ private jssContext = inject(JssContextService);
19
19
 
20
20
  ngOnInit(): void {
21
21
  if (!isServer() && environment.production) {
@@ -0,0 +1,13 @@
1
+ import { Component } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { JssModule } from '@sitecore-jss/sitecore-jss-angular';
4
+ import { CloudSdkInitComponent } from './cloud-sdk-init.component';
5
+ import { CdpPageViewComponent } from './cdp-page-view.component';
6
+
7
+ @Component({
8
+ selector: 'app-scripts',
9
+ templateUrl: './scripts.component.html',
10
+ imports: [CommonModule, JssModule, CloudSdkInitComponent, CdpPageViewComponent]
11
+ })
12
+ export class ScriptsComponent {}
13
+
@@ -5,8 +5,7 @@ import { CloudSdkInitComponent } from './cloud-sdk-init.component';
5
5
  import { CdpPageViewComponent } from './cdp-page-view.component';
6
6
 
7
7
  @NgModule({
8
+ imports: [JssModule, ScriptsComponent, CloudSdkInitComponent, CdpPageViewComponent],
8
9
  exports: [ScriptsComponent],
9
- imports: [JssModule],
10
- declarations: [ScriptsComponent, CloudSdkInitComponent, CdpPageViewComponent],
11
10
  })
12
11
  export class ScriptsModule {}
@@ -2,7 +2,14 @@ import {
2
2
  ComponentParams,
3
3
  ComponentRendering,
4
4
  SitecoreContextValue,
5
+ LayoutServiceData,
6
+ ComponentPropsService,
7
+ ComponentPropsCollection,
8
+ ComponentPropsError,
5
9
  } from '@sitecore-jss/sitecore-jss-nextjs';
10
+ import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
11
+ import { isServerSidePropsContext } from 'lib/page-props-factory';
12
+ import { moduleFactory } from 'temp/componentBuilder';
6
13
 
7
14
  /**
8
15
  * Shared component props
@@ -21,3 +28,36 @@ export type ComponentProps = {
21
28
  export type ComponentWithContextProps = ComponentProps & {
22
29
  sitecoreContext: SitecoreContextValue;
23
30
  };
31
+
32
+ /**
33
+ * Fetch component props for a given layout data and context
34
+ * @param {LayoutServiceData} layoutData - The layout data to fetch component props for
35
+ * @param {GetServerSidePropsContext | GetStaticPropsContext} context - The context to fetch component props for
36
+ * @returns {ComponentPropsCollection} The component props
37
+ * @throws {Error} If there are errors during component props fetching
38
+ */
39
+ export async function fetchComponentProps(
40
+ layoutData: LayoutServiceData,
41
+ context: GetServerSidePropsContext | GetStaticPropsContext
42
+ ): Promise<ComponentPropsCollection> {
43
+ const service = new ComponentPropsService();
44
+
45
+ const componentProps = isServerSidePropsContext(context)
46
+ ? await service.fetchServerSideComponentProps({ layoutData, context, moduleFactory })
47
+ : await service.fetchStaticComponentProps({ layoutData, context, moduleFactory });
48
+
49
+ const errors = Object.keys(componentProps)
50
+ .map(id => {
51
+ const c = componentProps[id] as ComponentPropsError;
52
+ return c?.error
53
+ ? `\nUnable to get component props for ${c.componentName} (${id}): ${c.error}`
54
+ : '';
55
+ })
56
+ .join('');
57
+
58
+ if (errors.length) {
59
+ throw new Error(errors);
60
+ }
61
+
62
+ return componentProps;
63
+ }
@@ -1,50 +1,17 @@
1
- import { ComponentPropsService, ComponentPropsError } from '@sitecore-jss/sitecore-jss-nextjs';
2
- import { SitecorePageProps } from 'lib/page-props';
3
1
  import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
4
- import { moduleFactory } from 'temp/componentBuilder';
5
- import { Plugin, isServerSidePropsContext } from '..';
2
+ import { SitecorePageProps } from 'lib/page-props';
3
+ import { fetchComponentProps } from 'lib/component-props';
4
+ import { Plugin } from '..';
6
5
 
7
6
  class ComponentPropsPlugin implements Plugin {
8
- private componentPropsService: ComponentPropsService;
9
-
10
7
  // Make sure to run this plugin last to ensure that the updated layout data is used
11
8
  order = 10;
12
9
 
13
- constructor() {
14
- this.componentPropsService = new ComponentPropsService();
15
- }
16
-
17
10
  async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
18
11
  if (!props.layoutData.sitecore.route) return props;
19
12
 
20
13
  // Retrieve component props using side-effects defined on components level
21
- if (isServerSidePropsContext(context)) {
22
- props.componentProps = await this.componentPropsService.fetchServerSideComponentProps({
23
- layoutData: props.layoutData,
24
- context,
25
- moduleFactory,
26
- });
27
- } else {
28
- props.componentProps = await this.componentPropsService.fetchStaticComponentProps({
29
- layoutData: props.layoutData,
30
- context,
31
- moduleFactory,
32
- });
33
- }
34
-
35
- const errors = Object.keys(props.componentProps)
36
- .map(id => {
37
- const component = props.componentProps[id] as ComponentPropsError;
38
-
39
- return component.error
40
- ? `\nUnable to get component props for ${component.componentName} (${id}): ${component.error}`
41
- : '';
42
- })
43
- .join('');
44
-
45
- if (errors.length) {
46
- throw new Error(errors);
47
- }
14
+ props.componentProps = await fetchComponentProps(props.layoutData, context);
48
15
 
49
16
  return props;
50
17
  }
@@ -1,17 +1,19 @@
1
1
  import { JSX } from 'react';
2
- import config from 'temp/config';
2
+ import { GetStaticProps } from 'next';
3
3
  import {
4
4
  GraphQLErrorPagesService,
5
5
  SitecoreContext,
6
+ ComponentPropsContext,
6
7
  ErrorPages,
7
8
  } from '@sitecore-jss/sitecore-jss-nextjs';
8
9
  import { SitecorePageProps } from 'lib/page-props';
9
10
  import NotFound from 'src/NotFound';
10
11
  import { componentBuilder } from 'temp/componentBuilder';
11
12
  import Layout from 'src/Layout';
12
- import { GetStaticProps } from 'next';
13
13
  import { siteResolver } from 'lib/site-resolver';
14
+ import { fetchComponentProps } from 'lib/component-props';
14
15
  import clientFactory from 'lib/graphql-client-factory';
16
+ import config from 'temp/config';
15
17
 
16
18
  const Custom404 = (props: SitecorePageProps): JSX.Element => {
17
19
  if (!(props && props.layoutData)) {
@@ -19,20 +21,22 @@ const Custom404 = (props: SitecorePageProps): JSX.Element => {
19
21
  }
20
22
 
21
23
  return (
22
- <SitecoreContext
23
- componentFactory={componentBuilder.getComponentFactory()}
24
- layoutData={props.layoutData}
25
- <% if (templates.includes('nextjs-xmcloud')) { %>
26
- api={{
27
- edge: {
28
- contextId: config.sitecoreEdgeContextId,
29
- edgeUrl: config.sitecoreEdgeUrl,
30
- },
31
- }}
32
- <% } %>
33
- >
34
- <Layout layoutData={props.layoutData} headLinks={props.headLinks} />
35
- </SitecoreContext>
24
+ <ComponentPropsContext value={props.componentProps}>
25
+ <SitecoreContext
26
+ componentFactory={componentBuilder.getComponentFactory()}
27
+ layoutData={props.layoutData}
28
+ <% if (templates.includes('nextjs-xmcloud')) { %>
29
+ api={{
30
+ edge: {
31
+ contextId: config.sitecoreEdgeContextId,
32
+ edgeUrl: config.sitecoreEdgeUrl,
33
+ },
34
+ }}
35
+ <% } %>
36
+ >
37
+ <Layout layoutData={props.layoutData} headLinks={props.headLinks} />
38
+ </SitecoreContext>
39
+ </ComponentPropsContext>
36
40
  );
37
41
  };
38
42
 
@@ -58,10 +62,19 @@ export const getStaticProps: GetStaticProps = async (context) => {
58
62
  }
59
63
  }
60
64
 
65
+ const layoutData = resultErrorPages?.notFoundPage?.rendered || null;
66
+
67
+ let componentProps = {};
68
+
69
+ if (layoutData?.sitecore?.route) {
70
+ componentProps = await fetchComponentProps(layoutData, context);
71
+ }
72
+
61
73
  return {
62
74
  props: {
63
75
  headLinks: [],
64
- layoutData: resultErrorPages?.notFoundPage?.rendered || null,
76
+ layoutData,
77
+ componentProps,
65
78
  },
66
79
  };
67
80
  };