create-sitecore-jss 22.4.1-canary.2 → 22.5.0-beta.1

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.
@@ -183,10 +183,8 @@ const diffAndWriteFiles = (_a) => __awaiter(void 0, [_a], void 0, function* ({ r
183
183
  exports.diffAndWriteFiles = diffAndWriteFiles;
184
184
  const populateEjsData = (answers, destination) => {
185
185
  // pass in helper to answers object
186
- // Don't expose canary build number in the generated app
187
- const jssVersion = version.includes('canary')
188
- ? version.replace(/(-canary\.\d+)$/, '-canary')
189
- : version;
186
+ // Don't expose prerelease build number in the generated app
187
+ const jssVersion = version.replace(/(\.\d+)$/, '');
190
188
  const ejsData = Object.assign(Object.assign({}, answers), { version: jssVersion, helper: {
191
189
  isDev: (0, helpers_1.isDevEnvironment)(destination || answers.destination),
192
190
  getPascalCaseName: helpers_1.getPascalCaseName,
@@ -1,5 +1,5 @@
1
1
  import type { NextApiRequest, NextApiResponse } from 'next';
2
- import { NativeDataFetcher, GraphQLSitemapXmlService } from '@sitecore-jss/sitecore-jss-nextjs'
2
+ import { NativeDataFetcher, GraphQLSitemapXmlService } from '@sitecore-jss/sitecore-jss-nextjs';
3
3
  import { siteResolver } from 'lib/site-resolver';
4
4
  import config from 'temp/config';
5
5
  import clientFactory from 'lib/graphql-client-factory';
@@ -24,10 +24,11 @@ const sitemapApi = async (
24
24
  siteName: site.name,
25
25
  });
26
26
 
27
- // if url has sitemap-{n}.xml type. The id - can be null if it's sitemap.xml request
27
+ // The id is present if url has sitemap-{n}.xml type.
28
+ // The id can be null if it's index sitemap.xml request
28
29
  const sitemapPath = await sitemapXmlService.getSitemap(id as string);
29
30
 
30
- // if sitemap is match otherwise redirect to 404 page
31
+ // regular sitemap
31
32
  if (sitemapPath) {
32
33
  const isAbsoluteUrl = sitemapPath.match(ABSOLUTE_URL_REGEXP);
33
34
  const sitemapUrl = isAbsoluteUrl ? sitemapPath : `${config.sitecoreApiHost}${sitemapPath}`;
@@ -43,10 +44,7 @@ const sitemapApi = async (
43
44
  }
44
45
  }
45
46
 
46
-
47
-
48
-
49
- // this approache if user go to /sitemap.xml - under it generate xml page with list of sitemaps
47
+ // index /sitemap.xml that includes links to all sitemaps
50
48
  const sitemaps = await sitemapXmlService.fetchSitemaps();
51
49
 
52
50
  if (!sitemaps.length) {
@@ -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,47 @@ 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 } =
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
+ version,
43
+ });
44
+
45
+ // we can reuse editing service, fortunately
46
+ const dictionaryData = await graphQLEditingService.fetchDictionaryData({
47
+ siteName: site,
48
+ language,
49
+ });
50
+
51
+ if (!componentData) {
52
+ throw new Error(
53
+ `Unable to fetch editing data for preview ${JSON.stringify(context.previewData)}`
54
+ );
55
+ }
56
+
57
+ props.locale = context.previewData.language;
58
+ props.layoutData = componentData;
59
+ props.headLinks = [];
60
+ props.dictionary = dictionaryData;
61
+
62
+ return props;
63
+ }
64
+
21
65
  // If we're in Pages preview (editing) Metadata Edit Mode, prefetch the editing data
22
66
  if (isEditingMetadataPreviewData(context.previewData)) {
23
67
  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.1-canary.2",
3
+ "version": "22.5.0-beta.1",
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": "7cec13189f26fb9287541720fd1491bfcc9c24b8"
68
+ "gitHead": "e080916b354c36e63f29f01fbcb87688d7f2b4cd"
69
69
  }