@sitecore-jss/sitecore-jss-nextjs 21.2.0-canary.9 → 21.3.0-canary.2

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.
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ComponentBuilder = void 0;
4
+ /**
5
+ * Nextjs implementation of component builder class for building components based on the configuration.
6
+ */
7
+ class ComponentBuilder {
8
+ constructor(config) {
9
+ this.config = config;
10
+ /**
11
+ * SXA uses custom default export name
12
+ */
13
+ this.DEFAULT_EXPORT_NAME = 'Default';
14
+ this.components = new Map([...config.components]);
15
+ }
16
+ /**
17
+ * Creates a new instance of module factory
18
+ * Module factory provides a module (file) including all exports.
19
+ * Module can be imported dynamically or statically.
20
+ * @returns {ModuleFactory} Module factory implementation
21
+ */
22
+ getModuleFactory() {
23
+ return (componentName) => {
24
+ const component = this.components.get(componentName);
25
+ if (!component)
26
+ return null;
27
+ // check if module should be imported dynamically
28
+ if (component.module) {
29
+ return component.module();
30
+ }
31
+ return component;
32
+ };
33
+ }
34
+ /**
35
+ * Creates a new instance of component factory
36
+ * Component can be imported dynamically or statically.
37
+ * @param {Object} [config] Component factory configuration
38
+ * @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
39
+ * @returns {ComponentFactory} Component factory implementation
40
+ */
41
+ getComponentFactory({ isEditing } = {}) {
42
+ return (componentName, exportName) => {
43
+ const component = this.components.get(componentName);
44
+ if (!component)
45
+ return null;
46
+ // check if component should be imported dynamically
47
+ if (component.element) {
48
+ // Editing mode doesn't work well with dynamic components in nextjs: dynamic components are not displayed without refresh after a rendering is added.
49
+ // This happens beacuse Sitecore editors simply insert updated HTML generated on server side. This conflicts with nextjs dynamic logic as no HTML gets rendered for dynamic component
50
+ // So we use require() to obtain dynamic components in editing mode while preserving dynamic logic for non-editing scenarios
51
+ // As we need to be able to seamlessly work with dynamic components in both editing and normal modes, different componentFactory functions will be passed to app
52
+ return component.element(isEditing);
53
+ }
54
+ if (exportName && exportName !== this.DEFAULT_EXPORT_NAME) {
55
+ return component[exportName];
56
+ }
57
+ return component.Default || component.default || null;
58
+ };
59
+ }
60
+ }
61
+ exports.ComponentBuilder = ComponentBuilder;
@@ -44,7 +44,7 @@ const router_1 = require("next/router");
44
44
  const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
45
45
  const prefetched = {};
46
46
  const RichText = (props) => {
47
- const { internalLinksSelector = 'a[href^="/"]' } = props, rest = __rest(props, ["internalLinksSelector"]);
47
+ const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks"]);
48
48
  const hasText = props.field && props.field.value;
49
49
  const isEditing = props.editable && props.field && props.field.editable;
50
50
  const router = (0, router_1.useRouter)();
@@ -54,7 +54,7 @@ const RichText = (props) => {
54
54
  if (hasText && !isEditing) {
55
55
  initializeLinks();
56
56
  }
57
- }, []);
57
+ }, [hasText]);
58
58
  const routeHandler = (ev) => {
59
59
  if (!ev.target)
60
60
  return;
@@ -69,13 +69,13 @@ const RichText = (props) => {
69
69
  if (!internalLinks || !internalLinks.length)
70
70
  return;
71
71
  internalLinks.forEach((link) => {
72
- if (link.target !== '_blank') {
73
- if (!prefetched[link.pathname]) {
74
- router.prefetch(link.pathname, undefined, { locale: false });
75
- prefetched[link.pathname] = true;
76
- }
77
- link.addEventListener('click', routeHandler, false);
72
+ if (link.target === '_blank')
73
+ return;
74
+ if (prefetchLinks && !prefetched[link.pathname]) {
75
+ router.prefetch(link.pathname, undefined, { locale: false });
76
+ prefetched[link.pathname] = true;
78
77
  }
78
+ link.addEventListener('click', routeHandler, false);
79
79
  });
80
80
  };
81
81
  return react_1.default.createElement(sitecore_jss_react_1.RichText, Object.assign({ ref: richTextRef }, rest));
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Image = exports.NextImage = exports.EditingComponentPlaceholder = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.GraphQLRequestClient = exports.PosResolver = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.tryParseEnvValue = exports.resolveUrl = exports.resetEditorChromes = exports.isEditorActive = exports.getPublicUrl = exports.handleEditorFastRefresh = exports.enableDebug = exports.NativeDataFetcher = exports.AxiosDataFetcher = exports.constants = void 0;
4
- exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = void 0;
3
+ exports.ComponentBuilder = exports.NextImage = exports.EditingComponentPlaceholder = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.GraphQLRequestClient = exports.PosResolver = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.tryParseEnvValue = exports.resolveUrl = exports.resetEditorChromes = exports.isEditorActive = exports.getPublicUrl = exports.handleEditorFastRefresh = exports.enableDebug = exports.NativeDataFetcher = exports.AxiosDataFetcher = exports.constants = void 0;
4
+ exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = void 0;
5
5
  var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
6
6
  Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
7
7
  Object.defineProperty(exports, "AxiosDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.AxiosDataFetcher; } });
@@ -82,6 +82,8 @@ var EditingComponentPlaceholder_1 = require("./components/EditingComponentPlaceh
82
82
  Object.defineProperty(exports, "EditingComponentPlaceholder", { enumerable: true, get: function () { return EditingComponentPlaceholder_1.EditingComponentPlaceholder; } });
83
83
  var NextImage_1 = require("./components/NextImage");
84
84
  Object.defineProperty(exports, "NextImage", { enumerable: true, get: function () { return NextImage_1.NextImage; } });
85
+ var ComponentBuilder_1 = require("./ComponentBuilder");
86
+ Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
85
87
  var sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
86
88
  Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return sitecore_jss_react_1.Image; } });
87
89
  Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return sitecore_jss_react_1.Text; } });
@@ -23,9 +23,9 @@ class ComponentPropsService {
23
23
  */
24
24
  fetchServerSideComponentProps(params) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- const { componentModule, layoutData, context } = params;
26
+ const { moduleFactory, layoutData, context } = params;
27
27
  const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
28
- const module = yield componentModule(componentName);
28
+ const module = yield moduleFactory(componentName);
29
29
  return module === null || module === void 0 ? void 0 : module.getServerSideProps;
30
30
  });
31
31
  return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
@@ -39,9 +39,9 @@ class ComponentPropsService {
39
39
  */
40
40
  fetchStaticComponentProps(params) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
- const { componentModule, layoutData, context } = params;
42
+ const { moduleFactory, layoutData, context } = params;
43
43
  const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
44
- const module = yield componentModule(componentName);
44
+ const module = yield moduleFactory(componentName);
45
45
  return module === null || module === void 0 ? void 0 : module.getStaticProps;
46
46
  });
47
47
  return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Nextjs implementation of component builder class for building components based on the configuration.
3
+ */
4
+ export class ComponentBuilder {
5
+ constructor(config) {
6
+ this.config = config;
7
+ /**
8
+ * SXA uses custom default export name
9
+ */
10
+ this.DEFAULT_EXPORT_NAME = 'Default';
11
+ this.components = new Map([...config.components]);
12
+ }
13
+ /**
14
+ * Creates a new instance of module factory
15
+ * Module factory provides a module (file) including all exports.
16
+ * Module can be imported dynamically or statically.
17
+ * @returns {ModuleFactory} Module factory implementation
18
+ */
19
+ getModuleFactory() {
20
+ return (componentName) => {
21
+ const component = this.components.get(componentName);
22
+ if (!component)
23
+ return null;
24
+ // check if module should be imported dynamically
25
+ if (component.module) {
26
+ return component.module();
27
+ }
28
+ return component;
29
+ };
30
+ }
31
+ /**
32
+ * Creates a new instance of component factory
33
+ * Component can be imported dynamically or statically.
34
+ * @param {Object} [config] Component factory configuration
35
+ * @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
36
+ * @returns {ComponentFactory} Component factory implementation
37
+ */
38
+ getComponentFactory({ isEditing } = {}) {
39
+ return (componentName, exportName) => {
40
+ const component = this.components.get(componentName);
41
+ if (!component)
42
+ return null;
43
+ // check if component should be imported dynamically
44
+ if (component.element) {
45
+ // Editing mode doesn't work well with dynamic components in nextjs: dynamic components are not displayed without refresh after a rendering is added.
46
+ // This happens beacuse Sitecore editors simply insert updated HTML generated on server side. This conflicts with nextjs dynamic logic as no HTML gets rendered for dynamic component
47
+ // So we use require() to obtain dynamic components in editing mode while preserving dynamic logic for non-editing scenarios
48
+ // As we need to be able to seamlessly work with dynamic components in both editing and normal modes, different componentFactory functions will be passed to app
49
+ return component.element(isEditing);
50
+ }
51
+ if (exportName && exportName !== this.DEFAULT_EXPORT_NAME) {
52
+ return component[exportName];
53
+ }
54
+ return component.Default || component.default || null;
55
+ };
56
+ }
57
+ }
@@ -15,7 +15,7 @@ import { useRouter } from 'next/router';
15
15
  import { RichText as ReactRichText, RichTextPropTypes, } from '@sitecore-jss/sitecore-jss-react';
16
16
  const prefetched = {};
17
17
  export const RichText = (props) => {
18
- const { internalLinksSelector = 'a[href^="/"]' } = props, rest = __rest(props, ["internalLinksSelector"]);
18
+ const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks"]);
19
19
  const hasText = props.field && props.field.value;
20
20
  const isEditing = props.editable && props.field && props.field.editable;
21
21
  const router = useRouter();
@@ -25,7 +25,7 @@ export const RichText = (props) => {
25
25
  if (hasText && !isEditing) {
26
26
  initializeLinks();
27
27
  }
28
- }, []);
28
+ }, [hasText]);
29
29
  const routeHandler = (ev) => {
30
30
  if (!ev.target)
31
31
  return;
@@ -40,13 +40,13 @@ export const RichText = (props) => {
40
40
  if (!internalLinks || !internalLinks.length)
41
41
  return;
42
42
  internalLinks.forEach((link) => {
43
- if (link.target !== '_blank') {
44
- if (!prefetched[link.pathname]) {
45
- router.prefetch(link.pathname, undefined, { locale: false });
46
- prefetched[link.pathname] = true;
47
- }
48
- link.addEventListener('click', routeHandler, false);
43
+ if (link.target === '_blank')
44
+ return;
45
+ if (prefetchLinks && !prefetched[link.pathname]) {
46
+ router.prefetch(link.pathname, undefined, { locale: false });
47
+ prefetched[link.pathname] = true;
49
48
  }
49
+ link.addEventListener('click', routeHandler, false);
50
50
  });
51
51
  };
52
52
  return React.createElement(ReactRichText, Object.assign({ ref: richTextRef }, rest));
package/dist/esm/index.js CHANGED
@@ -31,4 +31,5 @@ export { RichText } from './components/RichText';
31
31
  export { Placeholder } from './components/Placeholder';
32
32
  export { EditingComponentPlaceholder } from './components/EditingComponentPlaceholder';
33
33
  export { NextImage } from './components/NextImage';
34
+ export { ComponentBuilder } from './ComponentBuilder';
34
35
  export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, File, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, } from '@sitecore-jss/sitecore-jss-react';
@@ -17,9 +17,9 @@ export class ComponentPropsService {
17
17
  */
18
18
  fetchServerSideComponentProps(params) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const { componentModule, layoutData, context } = params;
20
+ const { moduleFactory, layoutData, context } = params;
21
21
  const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
22
- const module = yield componentModule(componentName);
22
+ const module = yield moduleFactory(componentName);
23
23
  return module === null || module === void 0 ? void 0 : module.getServerSideProps;
24
24
  });
25
25
  return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
@@ -33,9 +33,9 @@ export class ComponentPropsService {
33
33
  */
34
34
  fetchStaticComponentProps(params) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- const { componentModule, layoutData, context } = params;
36
+ const { moduleFactory, layoutData, context } = params;
37
37
  const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
38
- const module = yield componentModule(componentName);
38
+ const module = yield moduleFactory(componentName);
39
39
  return module === null || module === void 0 ? void 0 : module.getStaticProps;
40
40
  });
41
41
  return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "21.2.0-canary.9",
3
+ "version": "21.3.0-canary.2",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -70,9 +70,9 @@
70
70
  "react-dom": "^18.2.0"
71
71
  },
72
72
  "dependencies": {
73
- "@sitecore-jss/sitecore-jss": "^21.2.0-canary.9",
74
- "@sitecore-jss/sitecore-jss-dev-tools": "^21.2.0-canary.9",
75
- "@sitecore-jss/sitecore-jss-react": "^21.2.0-canary.9",
73
+ "@sitecore-jss/sitecore-jss": "^21.3.0-canary.2",
74
+ "@sitecore-jss/sitecore-jss-dev-tools": "^21.3.0-canary.2",
75
+ "@sitecore-jss/sitecore-jss-react": "^21.3.0-canary.2",
76
76
  "node-html-parser": "^6.1.4",
77
77
  "prop-types": "^15.8.1",
78
78
  "regex-parser": "^2.2.11",
@@ -80,7 +80,7 @@
80
80
  },
81
81
  "description": "",
82
82
  "types": "types/index.d.ts",
83
- "gitHead": "d4ac1db367d5ce2060cd22d543c38019b1d230bb",
83
+ "gitHead": "a498d1b8b6bab066a58907a2a01a554b9d20bd42",
84
84
  "files": [
85
85
  "dist",
86
86
  "types",
@@ -0,0 +1,60 @@
1
+ import { ComponentFactory } from '@sitecore-jss/sitecore-jss-react';
2
+ import { Module, ModuleFactory } from './sharedTypes/module-factory';
3
+ import { ComponentType } from 'react';
4
+ /**
5
+ * Represents a component that can be imported dynamically
6
+ */
7
+ export type LazyModule = {
8
+ module: () => Promise<Module>;
9
+ element: (isEditing?: boolean) => ComponentType;
10
+ };
11
+ /**
12
+ * Component is a module or a lazy module
13
+ */
14
+ type Component = Module | LazyModule;
15
+ /**
16
+ * Configuration for ComponentBuilder
17
+ */
18
+ export type ComponentBuilderConfig<Component> = {
19
+ /**
20
+ * List of components to be stored
21
+ */
22
+ components: Map<string, Component>;
23
+ };
24
+ /**
25
+ * Configuration for ComponentFactory
26
+ */
27
+ type ComponentFactoryConfig = {
28
+ isEditing?: boolean;
29
+ };
30
+ /**
31
+ * Nextjs implementation of component builder class for building components based on the configuration.
32
+ */
33
+ export declare class ComponentBuilder {
34
+ protected config: ComponentBuilderConfig<Component>;
35
+ /**
36
+ * List of components to be stored
37
+ */
38
+ protected components: Map<string, Component>;
39
+ /**
40
+ * SXA uses custom default export name
41
+ */
42
+ protected DEFAULT_EXPORT_NAME: string;
43
+ constructor(config: ComponentBuilderConfig<Component>);
44
+ /**
45
+ * Creates a new instance of module factory
46
+ * Module factory provides a module (file) including all exports.
47
+ * Module can be imported dynamically or statically.
48
+ * @returns {ModuleFactory} Module factory implementation
49
+ */
50
+ getModuleFactory(): ModuleFactory;
51
+ /**
52
+ * Creates a new instance of component factory
53
+ * Component can be imported dynamically or statically.
54
+ * @param {Object} [config] Component factory configuration
55
+ * @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
56
+ * @returns {ComponentFactory} Component factory implementation
57
+ */
58
+ getComponentFactory({ isEditing }?: ComponentFactoryConfig): ComponentFactory;
59
+ }
60
+ export {};
@@ -6,6 +6,12 @@ export type RichTextProps = ReactRichTextProps & {
6
6
  * @default 'a[href^="/"]'
7
7
  */
8
8
  internalLinksSelector?: string;
9
+ /**
10
+ * Controls the prefetch of internal links. This can be beneficial if you have RichText fields
11
+ * with large numbers of internal links in them.
12
+ * @default true
13
+ */
14
+ prefetchLinks?: boolean;
9
15
  };
10
16
  export declare const RichText: {
11
17
  (props: RichTextProps): JSX.Element;
package/types/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQL
11
11
  export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, PosResolver, } from '@sitecore-jss/sitecore-jss/personalize';
12
12
  export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';
13
13
  export { ComponentPropsCollection, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
14
- export { ComponentModule } from './sharedTypes/component-module';
14
+ export { ModuleFactory, Module } from './sharedTypes/module-factory';
15
15
  export { ComponentPropsService } from './services/component-props-service';
16
16
  export { DisconnectedSitemapService } from './services/disconnected-sitemap-service';
17
17
  export { GraphQLSitemapService, GraphQLSitemapServiceConfig, } from './services/graphql-sitemap-service';
@@ -24,4 +24,5 @@ export { RichText, RichTextProps } from './components/RichText';
24
24
  export { Placeholder } from './components/Placeholder';
25
25
  export { EditingComponentPlaceholder } from './components/EditingComponentPlaceholder';
26
26
  export { NextImage } from './components/NextImage';
27
+ export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
27
28
  export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
@@ -1,11 +1,11 @@
1
1
  import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
2
2
  import { LayoutServiceData, ComponentRendering, PlaceholdersData } from '@sitecore-jss/sitecore-jss/layout';
3
3
  import { ComponentPropsCollection, ComponentPropsFetchFunction } from '../sharedTypes/component-props';
4
- import { ComponentModule } from '../sharedTypes/component-module';
4
+ import { ModuleFactory } from '../sharedTypes/module-factory';
5
5
  export type FetchComponentPropsArguments<NextContext> = {
6
6
  layoutData: LayoutServiceData;
7
7
  context: NextContext;
8
- componentModule: ComponentModule;
8
+ moduleFactory: ModuleFactory;
9
9
  };
10
10
  export type ComponentPropsRequest<NextContext> = {
11
11
  fetch: ComponentPropsFetchFunction<NextContext>;
@@ -0,0 +1,32 @@
1
+ import { ComponentType } from 'react';
2
+ import { GetServerSideComponentProps, GetStaticComponentProps } from './component-props';
3
+ /**
4
+ * Represents a module (file)
5
+ */
6
+ export type Module = {
7
+ /**
8
+ * Default SXA export
9
+ */
10
+ Default?: ComponentType;
11
+ /**
12
+ * Default Next.js export
13
+ */
14
+ default?: ComponentType;
15
+ /**
16
+ * function for component level data fetching in SSR mode
17
+ */
18
+ getServerSideProps?: GetServerSideComponentProps;
19
+ /**
20
+ * function for component level data fetching in SSG mode
21
+ */
22
+ getStaticProps?: GetStaticComponentProps;
23
+ } & {
24
+ /**
25
+ * Custom exports
26
+ */
27
+ [key: string]: ComponentType;
28
+ };
29
+ /**
30
+ * Represents a module factory
31
+ */
32
+ export type ModuleFactory = (componentName: string) => Module | Promise<Module> | null;
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { GetServerSideComponentProps, GetStaticComponentProps } from './component-props';
3
- export type Module = {
4
- default: React.Component;
5
- getServerSideProps?: GetServerSideComponentProps;
6
- getStaticProps?: GetStaticComponentProps;
7
- };
8
- /**
9
- * @returns `undefined` module not found
10
- * @returns `Module` regular module
11
- * @returns `Promise<Module>` when module should be lazy loaded
12
- */
13
- export type ComponentModule = (componentName: string) => Module | Promise<Module> | undefined;