create-sitecore-jss 22.2.0-canary.48 → 22.2.0-canary.49
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.
- package/dist/templates/angular/src/app/JssState.ts +2 -6
- package/dist/templates/angular/src/app/app.module.ts +1 -1
- package/dist/templates/angular/src/app/jss-context.server-side.service.ts +4 -2
- package/dist/templates/angular/src/app/jss-context.service.ts +14 -11
- package/dist/templates/angular/src/app/jss-graphql.service.ts +7 -7
- package/dist/templates/angular/src/app/layout/jss-layout.service.ts +2 -2
- package/dist/templates/angular-sxp/src/app/components/graph-ql-layout/graph-ql-layout.component.ts +1 -1
- package/package.json +2 -2
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseJssState } from '@sitecore-jss/sitecore-jss-angular';
|
|
2
2
|
import { LayoutServiceError } from './layout/jss-layout.service';
|
|
3
3
|
|
|
4
|
-
export class JssState {
|
|
4
|
+
export class JssState extends BaseJssState {
|
|
5
5
|
language: string;
|
|
6
6
|
serverRoute: string;
|
|
7
7
|
routeFetchError?: LayoutServiceError;
|
|
8
|
-
sitecore?: LayoutServiceContextData & {
|
|
9
|
-
route: RouteData | null;
|
|
10
|
-
};
|
|
11
|
-
viewBag: { [key: string]: unknown };
|
|
12
8
|
}
|
|
@@ -3,7 +3,6 @@ import { APP_BASE_HREF } from '@angular/common';
|
|
|
3
3
|
import { HttpClientModule, HttpClient } from '@angular/common/http';
|
|
4
4
|
import { RoutingModule } from './routing/routing.module';
|
|
5
5
|
import { JssLayoutService } from './layout/jss-layout.service';
|
|
6
|
-
import { JssContextService } from './jss-context.service';
|
|
7
6
|
import { AppComponentsModule } from './components/app-components.module';
|
|
8
7
|
import { AppComponent } from './app.component';
|
|
9
8
|
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
|
@@ -11,6 +10,7 @@ import { JssTranslationClientLoaderService } from './i18n/jss-translation-client
|
|
|
11
10
|
import { JssTranslationLoaderService } from './i18n/jss-translation-loader.service';
|
|
12
11
|
import { GraphQLModule } from './jss-graphql.module';
|
|
13
12
|
import { JssMetaService } from './jss-meta.service';
|
|
13
|
+
import { JssContextService } from './jss-context.service';
|
|
14
14
|
|
|
15
15
|
@NgModule({
|
|
16
16
|
imports: [
|
|
@@ -3,6 +3,7 @@ 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
|
+
import { JssStateService } from '@sitecore-jss/sitecore-jss-angular';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Stores the JSS app's context (current route and Sitecore context data).
|
|
@@ -14,10 +15,11 @@ export class JssContextServerSideService extends JssContextService {
|
|
|
14
15
|
constructor(
|
|
15
16
|
protected transferState: TransferState,
|
|
16
17
|
protected layoutService: JssLayoutService,
|
|
18
|
+
protected stateService: JssStateService<JssState>,
|
|
17
19
|
// this initial state from sitecore is injected by server.bundle for "integrated" mode
|
|
18
20
|
@Inject('JSS_SERVER_LAYOUT_DATA') private serverToSsrState: JssState
|
|
19
21
|
) {
|
|
20
|
-
super(transferState, layoutService);
|
|
22
|
+
super(transferState, layoutService, stateService);
|
|
21
23
|
}
|
|
22
24
|
changeRoute(_route: string, _language: string): Observable<JssState> {
|
|
23
25
|
// console.log('Server route change to ' + route);
|
|
@@ -34,7 +36,7 @@ export class JssContextServerSideService extends JssContextService {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
// read initial state from data injected via server.bundle wrapper
|
|
37
|
-
this.
|
|
39
|
+
this.stateService.setState(this.serverToSsrState);
|
|
38
40
|
|
|
39
41
|
// place the initial state into TransferState for the client
|
|
40
42
|
this.transferState.set<JssState>(jssKey, this.serverToSsrState);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Injectable, TransferState, makeStateKey } from '@angular/core';
|
|
2
|
-
import { LayoutServiceData } from '@sitecore-jss/sitecore-jss-angular';
|
|
2
|
+
import { LayoutServiceData, JssStateService } from '@sitecore-jss/sitecore-jss-angular';
|
|
3
3
|
import { map, shareReplay, catchError } from 'rxjs/operators';
|
|
4
|
-
import { Observable, of as observableOf
|
|
5
|
-
import { JssState } from './JssState';
|
|
4
|
+
import { Observable, of as observableOf } from 'rxjs';
|
|
6
5
|
import { JssLayoutService, LayoutServiceError } from './layout/jss-layout.service';
|
|
6
|
+
import { JssState } from './JssState';
|
|
7
7
|
|
|
8
8
|
export const jssKey = makeStateKey<JssState>('jss');
|
|
9
9
|
|
|
@@ -16,14 +16,17 @@ export const jssKey = makeStateKey<JssState>('jss');
|
|
|
16
16
|
export class JssContextService {
|
|
17
17
|
// components can subscribe to this (or use getValue()) to get access to latest data from Layout Service,
|
|
18
18
|
// as well as current language and server route
|
|
19
|
-
state
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
get state() {
|
|
20
|
+
return this.stateService.state;
|
|
21
|
+
}
|
|
22
|
+
get stateValue() {
|
|
23
|
+
return this.stateService.stateValue;
|
|
24
|
+
}
|
|
25
|
+
constructor(protected transferState: TransferState, protected layoutService: JssLayoutService, protected stateService: JssStateService<JssState>) {
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
changeLanguage(language: string) {
|
|
26
|
-
this.
|
|
29
|
+
this.stateService.setState({ ...this.stateService.stateValue, language });
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
// primarily invoked by JssRouteResolver on URL/route change
|
|
@@ -33,11 +36,11 @@ export class JssContextService {
|
|
|
33
36
|
if (foundInitialState) {
|
|
34
37
|
const jssState = this.transferState.get<JssState>(jssKey, null);
|
|
35
38
|
this.transferState.remove(jssKey);
|
|
36
|
-
this.
|
|
39
|
+
this.stateService.setState(jssState);
|
|
37
40
|
return observableOf(jssState);
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
const appLanguage = this.
|
|
43
|
+
const appLanguage = this.stateService.stateValue.language || language;
|
|
41
44
|
|
|
42
45
|
const jssState$ = this.layoutService.getRouteData(route, appLanguage).pipe(
|
|
43
46
|
map((routeData) => {
|
|
@@ -61,7 +64,7 @@ export class JssContextService {
|
|
|
61
64
|
|
|
62
65
|
// subscribe to it ourselves so we can maintain current state
|
|
63
66
|
jssState$.subscribe((jssState) => {
|
|
64
|
-
this.
|
|
67
|
+
this.stateService.setState(jssState);
|
|
65
68
|
});
|
|
66
69
|
|
|
67
70
|
return jssState$;
|
|
@@ -43,7 +43,7 @@ export class JssGraphQLService {
|
|
|
43
43
|
) {
|
|
44
44
|
this.isEditingOrPreviewingAndSsr =
|
|
45
45
|
isPlatformServer(this.platformId) &&
|
|
46
|
-
this.sitecoreContext.
|
|
46
|
+
this.sitecoreContext.stateValue.sitecore.context.pageState !== 'normal';
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
private static extractVariableNames(query: DocumentNode) {
|
|
@@ -127,19 +127,19 @@ export class JssGraphQLService {
|
|
|
127
127
|
|
|
128
128
|
if (
|
|
129
129
|
usedVariables.contextItem &&
|
|
130
|
-
this.sitecoreContext.
|
|
131
|
-
this.sitecoreContext.
|
|
132
|
-
this.sitecoreContext.
|
|
130
|
+
this.sitecoreContext.stateValue.sitecore &&
|
|
131
|
+
this.sitecoreContext.stateValue.sitecore.route &&
|
|
132
|
+
this.sitecoreContext.stateValue.sitecore.route.itemId
|
|
133
133
|
) {
|
|
134
|
-
(variables as EmptyObject).contextItem = this.sitecoreContext.
|
|
134
|
+
(variables as EmptyObject).contextItem = this.sitecoreContext.stateValue.sitecore.route.itemId;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// pass language as a variable to the query, if language exists as a variable and in sitecoreContext
|
|
138
138
|
if (
|
|
139
139
|
usedVariables.language &&
|
|
140
|
-
this.sitecoreContext.
|
|
140
|
+
this.sitecoreContext.stateValue.language
|
|
141
141
|
) {
|
|
142
|
-
(variables as EmptyObject).language = this.sitecoreContext.
|
|
142
|
+
(variables as EmptyObject).language = this.sitecoreContext.stateValue.language;
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
return variables;
|
|
@@ -7,14 +7,14 @@ import { from as fromPromise, Observable, throwError as observableThrow } from '
|
|
|
7
7
|
import { catchError, map } from 'rxjs/operators';
|
|
8
8
|
import { layoutServiceFactory } from '../lib/layout-service-factory';
|
|
9
9
|
|
|
10
|
-
const layoutServiceInstance = layoutServiceFactory.create();
|
|
11
|
-
|
|
12
10
|
export class LayoutServiceError {
|
|
13
11
|
status: number;
|
|
14
12
|
statusText: string;
|
|
15
13
|
data?: { sitecore?: LayoutServiceContextData };
|
|
16
14
|
}
|
|
17
15
|
|
|
16
|
+
const layoutServiceInstance = layoutServiceFactory.create();
|
|
17
|
+
|
|
18
18
|
@Injectable()
|
|
19
19
|
export class JssLayoutService {
|
|
20
20
|
getRouteData(
|
package/dist/templates/angular-sxp/src/app/components/graph-ql-layout/graph-ql-layout.component.ts
CHANGED
|
@@ -13,6 +13,6 @@ export class GraphQLLayoutComponent implements OnInit {
|
|
|
13
13
|
constructor(private contextService: JssContextService) { }
|
|
14
14
|
|
|
15
15
|
ngOnInit() {
|
|
16
|
-
this.disconnectedMode = this.contextService.
|
|
16
|
+
this.disconnectedMode = this.contextService.stateValue.sitecore.route.itemId === 'available-in-connected-mode';
|
|
17
17
|
}
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.2.0-canary.
|
|
3
|
+
"version": "22.2.0-canary.49",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"ts-node": "^10.9.1",
|
|
64
64
|
"typescript": "~4.9.5"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "6bf25fd8b2273f0b036d6894ce89d2ff94b7aef6"
|
|
67
67
|
}
|