create-sitecore-jss 22.4.0-canary.1 → 22.4.0-canary.3
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/README.md +1 -1
- package/dist/templates/nextjs-xmcloud/src/Bootstrap.tsx +2 -1
- package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/preview-mode.ts +45 -0
- package/dist/templates/nextjs-xmcloud/src/pages/component-library/render.tsx +51 -0
- package/package.json +2 -2
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
@TODO: Verify the link for angular xmcloud when documentation is ready
|
|
11
11
|
-->
|
|
12
12
|
|
|
13
|
-
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/
|
|
13
|
+
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/jss/latest/jss-xmc/introducing-sitecore-javascript-rendering-sdk.html)
|
|
@@ -13,9 +13,10 @@ const Bootstrap = (props: SitecorePageProps): JSX.Element | null => {
|
|
|
13
13
|
// Browser ClientSDK init allows for page view events to be tracked
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
const pageState = props.layoutData?.sitecore?.context.pageState;
|
|
16
|
+
const renderingType = props.layoutData?.sitecore?.context.renderingType;
|
|
16
17
|
if (process.env.NODE_ENV === 'development')
|
|
17
18
|
console.debug('Browser Events SDK is not initialized in development environment');
|
|
18
|
-
else if (pageState !== LayoutServicePageState.Normal)
|
|
19
|
+
else if (pageState !== LayoutServicePageState.Normal || renderingType === 'component')
|
|
19
20
|
console.debug('Browser Events SDK is not initialized in edit and preview modes');
|
|
20
21
|
else {
|
|
21
22
|
CloudSDK({
|
|
@@ -6,11 +6,14 @@ import {
|
|
|
6
6
|
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
7
7
|
import {
|
|
8
8
|
editingDataService,
|
|
9
|
+
isComponentLibraryPreviewData,
|
|
9
10
|
isEditingMetadataPreviewData,
|
|
10
11
|
} from '@sitecore-jss/sitecore-jss-nextjs/editing';
|
|
11
12
|
import { SitecorePageProps } from 'lib/page-props';
|
|
12
13
|
import { graphQLEditingService } from 'lib/graphql-editing-service';
|
|
13
14
|
import { Plugin } from '..';
|
|
15
|
+
import { RestComponentLayoutService } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
16
|
+
import config from 'temp/config';
|
|
14
17
|
|
|
15
18
|
class PreviewModePlugin implements Plugin {
|
|
16
19
|
order = 1;
|
|
@@ -18,6 +21,48 @@ class PreviewModePlugin implements Plugin {
|
|
|
18
21
|
async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
|
|
19
22
|
if (!context.preview) return props;
|
|
20
23
|
|
|
24
|
+
if (isComponentLibraryPreviewData(context.previewData)) {
|
|
25
|
+
const { itemId, componentUid, site, language, renderingId, dataSourceId, version, variant } =
|
|
26
|
+
context.previewData;
|
|
27
|
+
|
|
28
|
+
const componentService = new RestComponentLayoutService({
|
|
29
|
+
apiHost: config.sitecoreApiHost,
|
|
30
|
+
apiKey: config.sitecoreApiKey,
|
|
31
|
+
siteName: site,
|
|
32
|
+
configurationName: config.layoutServiceConfigurationName,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const componentData = await componentService.fetchComponentData({
|
|
36
|
+
siteName: site,
|
|
37
|
+
itemId,
|
|
38
|
+
language,
|
|
39
|
+
componentUid,
|
|
40
|
+
renderingId,
|
|
41
|
+
dataSourceId,
|
|
42
|
+
variant,
|
|
43
|
+
version,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// we can reuse editing service, fortunately
|
|
47
|
+
const dictionaryData = await graphQLEditingService.fetchDictionaryData({
|
|
48
|
+
siteName: site,
|
|
49
|
+
language,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
if (!componentData) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Unable to fetch editing data for preview ${JSON.stringify(context.previewData)}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
props.locale = context.previewData.language;
|
|
59
|
+
props.layoutData = componentData;
|
|
60
|
+
props.headLinks = [];
|
|
61
|
+
props.dictionary = dictionaryData;
|
|
62
|
+
|
|
63
|
+
return props;
|
|
64
|
+
}
|
|
65
|
+
|
|
21
66
|
// If we're in Pages preview (editing) Metadata Edit Mode, prefetch the editing data
|
|
22
67
|
if (isEditingMetadataPreviewData(context.previewData)) {
|
|
23
68
|
const { site, itemId, language, version, variantIds, layoutKind } = context.previewData;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { GetServerSideProps } from 'next';
|
|
2
|
+
import Head from 'next/head';
|
|
3
|
+
import {
|
|
4
|
+
ComponentLibraryLayout,
|
|
5
|
+
ComponentPropsContext,
|
|
6
|
+
SitecoreContext,
|
|
7
|
+
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
8
|
+
import { SitecorePageProps } from 'lib/page-props';
|
|
9
|
+
import { sitecorePagePropsFactory } from 'lib/page-props-factory';
|
|
10
|
+
import NotFound from 'src/NotFound';
|
|
11
|
+
import { componentBuilder } from 'temp/componentBuilder';
|
|
12
|
+
import config from 'temp/config';
|
|
13
|
+
|
|
14
|
+
const FEAASRender = ({
|
|
15
|
+
notFound,
|
|
16
|
+
componentProps,
|
|
17
|
+
layoutData,
|
|
18
|
+
headLinks,
|
|
19
|
+
}: SitecorePageProps): JSX.Element => {
|
|
20
|
+
if (notFound) {
|
|
21
|
+
return <NotFound />;
|
|
22
|
+
}
|
|
23
|
+
return (
|
|
24
|
+
<ComponentPropsContext value={componentProps}>
|
|
25
|
+
<SitecoreContext
|
|
26
|
+
componentFactory={componentBuilder.getComponentFactory()}
|
|
27
|
+
layoutData={layoutData}
|
|
28
|
+
>
|
|
29
|
+
<Head>
|
|
30
|
+
<title>Sitecore Component Library</title>
|
|
31
|
+
<link rel="icon" href={`${config.publicUrl}/favicon.ico`} />
|
|
32
|
+
{headLinks.map((headLink) => (
|
|
33
|
+
<link rel={headLink.rel} key={headLink.href} href={headLink.href} />
|
|
34
|
+
))}
|
|
35
|
+
</Head>
|
|
36
|
+
<ComponentLibraryLayout {...layoutData} />
|
|
37
|
+
</SitecoreContext>
|
|
38
|
+
</ComponentPropsContext>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const getServerSideProps: GetServerSideProps = async (context) => {
|
|
43
|
+
const props = await sitecorePagePropsFactory.create(context);
|
|
44
|
+
return {
|
|
45
|
+
props,
|
|
46
|
+
// not found when page not requested through editing render api or notFound set in page-props
|
|
47
|
+
notFound: props.notFound || !context.preview,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default FEAASRender;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.4.0-canary.
|
|
3
|
+
"version": "22.4.0-canary.3",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"ts-node": "^10.9.1",
|
|
66
66
|
"typescript": "~5.6.3"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "9e192b19fd1c19e559a93469ce26392eed3621e0"
|
|
69
69
|
}
|