@sitecore-content-sdk/react 0.1.0-beta.9 → 0.1.0-canary.0

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 (46) hide show
  1. package/README.md +5 -4
  2. package/dist/cjs/components/{ComponentLibraryLayout.js → DesignLibrary.js} +5 -5
  3. package/dist/cjs/components/EditingScripts.js +20 -7
  4. package/dist/cjs/components/Form.js +75 -0
  5. package/dist/cjs/components/Placeholder.js +4 -4
  6. package/dist/cjs/components/PlaceholderCommon.js +16 -9
  7. package/dist/cjs/components/SitecoreContext.js +11 -4
  8. package/dist/cjs/components/sharedTypes/components.js +7 -0
  9. package/dist/cjs/components/sharedTypes/index.js +18 -0
  10. package/dist/cjs/enhancers/{withComponentFactory.js → withComponentMap.js} +7 -7
  11. package/dist/cjs/enhancers/withPlaceholder.js +3 -3
  12. package/dist/cjs/enhancers/withSitecoreContext.js +2 -2
  13. package/dist/cjs/index.js +11 -9
  14. package/dist/esm/components/{ComponentLibraryLayout.js → DesignLibrary.js} +4 -4
  15. package/dist/esm/components/EditingScripts.js +21 -8
  16. package/dist/esm/components/Form.js +38 -0
  17. package/dist/esm/components/Placeholder.js +4 -4
  18. package/dist/esm/components/PlaceholderCommon.js +16 -9
  19. package/dist/esm/components/SitecoreContext.js +10 -3
  20. package/dist/esm/components/sharedTypes/components.js +4 -0
  21. package/dist/esm/components/sharedTypes/index.js +2 -0
  22. package/dist/esm/enhancers/withComponentMap.js +20 -0
  23. package/dist/esm/enhancers/withPlaceholder.js +3 -3
  24. package/dist/esm/enhancers/withSitecoreContext.js +3 -3
  25. package/dist/esm/index.js +5 -4
  26. package/package.json +9 -6
  27. package/types/components/DesignLibrary.d.ts +2 -0
  28. package/types/components/EditingScripts.d.ts +15 -2
  29. package/types/components/Form.d.ts +24 -0
  30. package/types/components/PlaceholderCommon.d.ts +6 -6
  31. package/types/components/SitecoreContext.d.ts +7 -4
  32. package/types/components/sharedTypes/components.d.ts +32 -0
  33. package/types/components/sharedTypes/index.d.ts +2 -0
  34. package/types/components/sharedTypes/props.d.ts +14 -0
  35. package/types/enhancers/withComponentMap.d.ts +12 -0
  36. package/types/enhancers/withSitecoreContext.d.ts +3 -6
  37. package/types/index.d.ts +6 -5
  38. package/dist/cjs/ComponentBuilder.js +0 -25
  39. package/dist/esm/ComponentBuilder.js +0 -21
  40. package/dist/esm/enhancers/withComponentFactory.js +0 -20
  41. package/types/ComponentBuilder.d.ts +0 -27
  42. package/types/components/ComponentLibraryLayout.d.ts +0 -2
  43. package/types/components/sharedTypes.d.ts +0 -28
  44. package/types/enhancers/withComponentFactory.d.ts +0 -12
  45. /package/dist/cjs/components/{sharedTypes.js → sharedTypes/props.js} +0 -0
  46. /package/dist/esm/components/{sharedTypes.js → sharedTypes/props.js} +0 -0
@@ -12,6 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import React from 'react';
13
13
  import PropTypes from 'prop-types';
14
14
  import { MissingComponent } from './MissingComponent';
15
+ import { DEFAULT_EXPORT_NAME } from './sharedTypes';
15
16
  import { isDynamicPlaceholder, getDynamicPlaceholderPattern, } from '@sitecore-content-sdk/core/layout';
16
17
  import { constants } from '@sitecore-content-sdk/core';
17
18
  import { HiddenRendering } from './HiddenRendering';
@@ -96,7 +97,7 @@ export class PlaceholderCommon extends React.Component {
96
97
  else {
97
98
  component = this.getComponentForRendering(componentRendering);
98
99
  }
99
- // Fallback/defaults for Sitecore Component renderings (in case not defined in component factory)
100
+ // Fallback/defaults for Sitecore Component renderings (in case not defined in component map)
100
101
  if (!component) {
101
102
  if (componentRendering.componentName === FEAAS_COMPONENT_RENDERING_NAME) {
102
103
  component = FEaaSComponent;
@@ -112,7 +113,7 @@ export class PlaceholderCommon extends React.Component {
112
113
  }
113
114
  }
114
115
  if (!component) {
115
- console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your componentFactory.js.`);
116
+ console.error(`Placeholder ${name} contains unknown component ${componentRendering.componentName}. Ensure that a React component exists for it, and that it is registered in your component-map file.`);
116
117
  component = missingComponentComponent !== null && missingComponentComponent !== void 0 ? missingComponentComponent : MissingComponent;
117
118
  isEmpty = true;
118
119
  }
@@ -145,16 +146,22 @@ export class PlaceholderCommon extends React.Component {
145
146
  }
146
147
  getComponentForRendering(renderingDefinition) {
147
148
  var _a;
148
- const componentFactory = this.props.componentFactory;
149
- if (!componentFactory || typeof componentFactory !== 'function') {
150
- console.warn(`No componentFactory was available to service request for component ${renderingDefinition}`);
149
+ const componentMap = this.props.componentMap;
150
+ if (!componentMap || componentMap.size === 0) {
151
+ console.warn(`No components were available in component map to service request for component ${renderingDefinition}`);
151
152
  return null;
152
153
  }
153
- // Render SXA Rendering Variant
154
- if ((_a = renderingDefinition.params) === null || _a === void 0 ? void 0 : _a.FieldNames) {
155
- return componentFactory(renderingDefinition.componentName, renderingDefinition.params.FieldNames);
154
+ // Render SXA Rendering Variant if available
155
+ const exportName = (_a = renderingDefinition.params) === null || _a === void 0 ? void 0 : _a.FieldNames;
156
+ const component = componentMap.get(renderingDefinition.componentName);
157
+ if (!component)
158
+ return null;
159
+ if (exportName && exportName !== DEFAULT_EXPORT_NAME) {
160
+ return component[exportName];
156
161
  }
157
- return componentFactory(renderingDefinition.componentName);
162
+ return (component.default ||
163
+ component.Default ||
164
+ component);
158
165
  }
159
166
  }
160
167
  PlaceholderCommon.propTypes = {
@@ -2,10 +2,12 @@
2
2
  import React from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import fastDeepEqual from 'fast-deep-equal/es6/react';
5
+ import { constants } from '@sitecore-content-sdk/core';
5
6
  export const SitecoreContextReactContext = React.createContext({});
6
- export const ComponentFactoryReactContext = React.createContext({});
7
+ export const ComponentMapReactContext = React.createContext(new Map());
7
8
  export class SitecoreContext extends React.Component {
8
9
  constructor(props) {
10
+ var _a, _b, _c, _d;
9
11
  super(props);
10
12
  /**
11
13
  * Update context state. Value can be @type {LayoutServiceData} which will be automatically transformed
@@ -20,9 +22,14 @@ export class SitecoreContext extends React.Component {
20
22
  });
21
23
  };
22
24
  const context = this.constructContext(props.layoutData);
25
+ let api = props.api;
26
+ if (((_b = (_a = props.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId) && !((_d = (_c = props.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)) {
27
+ api = Object.assign(Object.assign({}, props.api), { edge: Object.assign(Object.assign({}, props.api.edge), { edgeUrl: constants.SITECORE_EDGE_URL_DEFAULT }) });
28
+ }
23
29
  this.state = {
24
30
  context,
25
31
  setContext: this.setContext,
32
+ api,
26
33
  };
27
34
  }
28
35
  constructContext(layoutData) {
@@ -43,13 +50,13 @@ export class SitecoreContext extends React.Component {
43
50
  }
44
51
  }
45
52
  render() {
46
- return (React.createElement(ComponentFactoryReactContext.Provider, { value: this.props.componentFactory },
53
+ return (React.createElement(ComponentMapReactContext.Provider, { value: this.props.componentMap },
47
54
  React.createElement(SitecoreContextReactContext.Provider, { value: this.state }, this.props.children)));
48
55
  }
49
56
  }
50
57
  SitecoreContext.propTypes = {
51
58
  children: PropTypes.any.isRequired,
52
- componentFactory: PropTypes.func,
59
+ componentMap: PropTypes.instanceOf(Map),
53
60
  layoutData: PropTypes.shape({
54
61
  sitecore: PropTypes.shape({
55
62
  context: PropTypes.any,
@@ -0,0 +1,4 @@
1
+ /**
2
+ * SXA uses custom default export name
3
+ */
4
+ export const DEFAULT_EXPORT_NAME = 'Default';
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export * from './props';
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { ComponentMapReactContext } from '../components/SitecoreContext';
3
+ import { useContext } from 'react';
4
+ /**
5
+ * @param {React.ComponentClass<T> | React.FC<T>} Component
6
+ */
7
+ export function withComponentMap(Component) {
8
+ /**
9
+ * @param {T} props - props to pass to the wrapped component
10
+ * @returns {JSX.Element} - the rendered component
11
+ */
12
+ function WithComponentMap(props) {
13
+ const context = useContext(ComponentMapReactContext);
14
+ return React.createElement(Component, Object.assign({}, props, { componentMap: props.componentMap || context }));
15
+ }
16
+ WithComponentMap.displayName = `withComponentMap(${Component.displayName ||
17
+ Component.name ||
18
+ 'Anonymous'})`;
19
+ return WithComponentMap;
20
+ }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { PlaceholderCommon } from '../components/PlaceholderCommon';
3
- import { withComponentFactory } from './withComponentFactory';
3
+ import { withComponentMap } from './withComponentMap';
4
4
  import { withSitecoreContext } from './withSitecoreContext';
5
5
  /**
6
6
  * @param {WithPlaceholderSpec} placeholders
@@ -14,7 +14,7 @@ export function withPlaceholder(placeholders, options) {
14
14
  }
15
15
  render() {
16
16
  let childProps = Object.assign({}, this.props);
17
- delete childProps.componentFactory;
17
+ delete childProps.componentMap;
18
18
  if (options && options.propsTransformer) {
19
19
  childProps = options.propsTransformer(childProps);
20
20
  }
@@ -52,6 +52,6 @@ export function withPlaceholder(placeholders, options) {
52
52
  }
53
53
  }
54
54
  WithPlaceholder.propTypes = PlaceholderCommon.propTypes;
55
- return withSitecoreContext()(withComponentFactory(WithPlaceholder));
55
+ return withSitecoreContext()(withComponentMap(WithPlaceholder));
56
56
  };
57
57
  }
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
- import { SitecoreContextReactContext } from '../components/SitecoreContext';
2
+ import { SitecoreContextReactContext, } from '../components/SitecoreContext';
3
3
  /**
4
4
  * @param {WithSitecoreContextOptions} [options]
5
5
  */
6
6
  export function withSitecoreContext(options) {
7
7
  return function withSitecoreContextHoc(Component) {
8
8
  return function WithSitecoreContext(props) {
9
- return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, updateSitecoreContext: options && options.updatable && context.setContext })))));
9
+ return (React.createElement(SitecoreContextReactContext.Consumer, null, (context) => (React.createElement(Component, Object.assign({}, props, { sitecoreContext: context.context, api: context.api, updateSitecoreContext: options && options.updatable && context.setContext })))));
10
10
  };
11
11
  };
12
12
  }
@@ -16,7 +16,6 @@ export function withSitecoreContext(options) {
16
16
  * - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Sitecore Editor.
17
17
  * - pageState - Like pageEditing, but a string: normal, preview or edit.
18
18
  * - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
19
- * @see https://jss.sitecore.com/docs/techniques/extending-layout-service/layoutservice-extending-context
20
19
  * @param {WithSitecoreContextOptions} [options] hook options
21
20
  * @example
22
21
  * const EditMode = () => {
@@ -35,6 +34,7 @@ export function useSitecoreContext(options) {
35
34
  const reactContext = React.useContext(SitecoreContextReactContext);
36
35
  const updatable = options === null || options === void 0 ? void 0 : options.updatable;
37
36
  return {
37
+ api: reactContext.api,
38
38
  sitecoreContext: reactContext.context,
39
39
  updateSitecoreContext: updatable ? reactContext.setContext : undefined,
40
40
  };
package/dist/esm/index.js CHANGED
@@ -1,9 +1,10 @@
1
1
  export { constants, enableDebug, ClientError, MemoryCacheClient, NativeDataFetcher, } from '@sitecore-content-sdk/core';
2
2
  export { isEditorActive, resetEditorChromes } from '@sitecore-content-sdk/core/editing';
3
- export { getContentStylesheetLink, getComponentLibraryStylesheetLinks, LayoutServicePageState, GraphQLLayoutService, getChildPlaceholder, getFieldValue, EditMode, } from '@sitecore-content-sdk/core/layout';
3
+ export { getContentStylesheetLink, getDesignLibraryStylesheetLinks, LayoutServicePageState, GraphQLLayoutService, getChildPlaceholder, getFieldValue, EditMode, } from '@sitecore-content-sdk/core/layout';
4
4
  export { GraphQLDictionaryService, } from '@sitecore-content-sdk/core/i18n';
5
- export { DefaultRetryStrategy, GraphQLRequestClient, } from '@sitecore-content-sdk/core/graphql';
5
+ export { DefaultRetryStrategy, GraphQLRequestClient, } from '@sitecore-content-sdk/core/client';
6
6
  export { mediaApi } from '@sitecore-content-sdk/core/media';
7
+ export { Form } from './components/Form';
7
8
  export { Placeholder } from './components/Placeholder';
8
9
  export { Image, } from './components/Image';
9
10
  export { RichText, RichTextPropTypes } from './components/RichText';
@@ -11,7 +12,7 @@ export { Text } from './components/Text';
11
12
  export { DateField } from './components/Date';
12
13
  export { FEaaSComponent, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
13
14
  export { FEaaSWrapper } from './components/FEaaSWrapper';
14
- export { ComponentLibraryLayout } from './components/ComponentLibraryLayout';
15
+ export { DesignLibrary } from './components/DesignLibrary';
15
16
  export { BYOCComponent, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
16
17
  export { BYOCWrapper } from './components/BYOCWrapper';
17
18
  export { Link, LinkPropTypes } from './components/Link';
@@ -21,8 +22,8 @@ export { withSitecoreContext, useSitecoreContext, } from './enhancers/withSiteco
21
22
  export { withEditorChromes } from './enhancers/withEditorChromes';
22
23
  export { withPlaceholder } from './enhancers/withPlaceholder';
23
24
  export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
24
- export { ComponentBuilder } from './ComponentBuilder';
25
25
  export { withFieldMetadata } from './enhancers/withFieldMetadata';
26
26
  export { withEmptyFieldEditingComponent } from './enhancers/withEmptyFieldEditingComponent';
27
27
  export { EditingScripts } from './components/EditingScripts';
28
28
  export { DefaultEmptyFieldEditingComponentText, DefaultEmptyFieldEditingComponentImage, } from './components/DefaultEmptyFieldEditingComponents';
29
+ export { GraphQLSitePathService, } from '@sitecore-content-sdk/core/site';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "0.1.0-beta.9",
3
+ "version": "0.1.0-canary.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -22,12 +22,12 @@
22
22
  },
23
23
  "author": {
24
24
  "name": "Sitecore Corporation",
25
- "url": "https://jss.sitecore.com"
25
+ "url": "https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html"
26
26
  },
27
27
  "license": "Apache-2.0",
28
- "homepage": "https://jss.sitecore.com",
28
+ "homepage": "https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html",
29
29
  "bugs": {
30
- "url": "https://github.com/sitecore/jss/issues"
30
+ "url": "https://github.com/sitecore/content-sdk/issues"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@sitecore-feaas/clientside": "^0.5.19",
@@ -39,6 +39,7 @@
39
39
  "@types/mocha": "^10.0.10",
40
40
  "@types/node": "22.12.0",
41
41
  "@types/prop-types": "^15.7.14",
42
+ "@types/proxyquire": "^1.3.31",
42
43
  "@types/react": "^18.2.45",
43
44
  "@types/react-dom": "^18.0.10",
44
45
  "@types/sinon": "^17.0.3",
@@ -51,6 +52,7 @@
51
52
  "jsdom": "^26.0.0",
52
53
  "mocha": "^11.1.0",
53
54
  "nyc": "^17.1.0",
55
+ "proxyquire": "^2.1.3",
54
56
  "react": "^18.2.0",
55
57
  "react-dom": "^18.2.0",
56
58
  "sinon": "^19.0.2",
@@ -59,18 +61,19 @@
59
61
  "typescript": "~5.7.3"
60
62
  },
61
63
  "peerDependencies": {
64
+ "@sitecore-cloudsdk/events": "^0.5.0",
62
65
  "@sitecore-feaas/clientside": "^0.5.19",
63
66
  "react": "^18.2.0",
64
67
  "react-dom": "^18.2.0"
65
68
  },
66
69
  "dependencies": {
67
- "@sitecore-content-sdk/core": "0.1.0-beta.9",
70
+ "@sitecore-content-sdk/core": "0.1.0-canary.0",
68
71
  "fast-deep-equal": "^3.1.3",
69
72
  "prop-types": "^15.8.1"
70
73
  },
71
74
  "description": "",
72
75
  "types": "types/index.d.ts",
73
- "gitHead": "119f924ced30a80f183049cce1477365aeadb1c3",
76
+ "gitHead": "2352eb9d087aa563507d1a2092af21ddf1e31c35",
74
77
  "files": [
75
78
  "dist",
76
79
  "types"
@@ -0,0 +1,2 @@
1
+ import { LayoutServiceData } from '@sitecore-content-sdk/core/layout';
2
+ export declare const DesignLibrary: (layoutData: LayoutServiceData) => JSX.Element;
@@ -1,4 +1,17 @@
1
1
  /**
2
- * Renders client scripts and data for editing/preview mode in Pages.
2
+ * Props for the EditingScripts component.
3
3
  */
4
- export declare const EditingScripts: () => JSX.Element;
4
+ export type EditingScriptsProps = {
5
+ /**
6
+ * Sitecore Edge Platform URL.
7
+ */
8
+ sitecoreEdgeUrl?: string;
9
+ };
10
+ /**
11
+ * Renders client scripts and data for editing/preview mode for Pages.
12
+ * Renders script required for the Design Library (when RenderingType is `component`).
13
+ * @param {EditingScriptsProps} props - The props for the EditingScripts component.
14
+ * @param {string} props.sitecoreEdgeUrl - Sitecore Edge Platform URL.
15
+ * @returns A JSX element containing the editing scripts or an empty fragment if not in editing/preview mode.
16
+ */
17
+ export declare const EditingScripts: (props: EditingScriptsProps) => JSX.Element;
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { ComponentRendering } from '@sitecore-content-sdk/core/layout';
3
+ /**
4
+ * Shape of the Form component rendering data.
5
+ * FormId is the rendering parameter that specifies the ID of the Sitecore Form to render.
6
+ */
7
+ export type FormProps = {
8
+ rendering: ComponentRendering;
9
+ params: {
10
+ /**
11
+ * The ID of the Sitecore Form to render.
12
+ */
13
+ FormId: string;
14
+ /**
15
+ * The CSS class to apply to the form.
16
+ */
17
+ styles?: string;
18
+ /**
19
+ * The unique identifier of the rendering.
20
+ */
21
+ RenderingIdentifier?: string;
22
+ };
23
+ };
24
+ export declare const Form: ({ params, rendering }: FormProps) => React.JSX.Element;
@@ -1,6 +1,6 @@
1
1
  import React, { ComponentType } from 'react';
2
2
  import PropTypes, { Requireable } from 'prop-types';
3
- import { ComponentFactory } from './sharedTypes';
3
+ import { ComponentMap } from './sharedTypes';
4
4
  import { ComponentRendering, RouteData, Field, Item } from '@sitecore-content-sdk/core/layout';
5
5
  import { SitecoreContextValue } from './SitecoreContext';
6
6
  type ErrorComponentProps = {
@@ -18,10 +18,10 @@ export interface PlaceholderProps {
18
18
  /** Rendering data to be used when rendering the placeholder. */
19
19
  rendering: ComponentRendering | RouteData;
20
20
  /**
21
- * A factory function that will receive a componentName and return an instance of a React component.
22
- * When rendered within a <SitecoreContext> component, defaults to the context componentFactory.
21
+ * Component Map will be used to map Sitecore component names to app implementation
22
+ * When rendered within a <SitecoreContext> component, defaults to the context componentMap.
23
23
  */
24
- componentFactory?: ComponentFactory;
24
+ componentMap?: ComponentMap;
25
25
  /**
26
26
  * An object of field names/values that are aggregated and propagated through the component tree created by a placeholder.
27
27
  * Any component or placeholder rendered by a placeholder will have access to this data via `props.fields`.
@@ -45,7 +45,7 @@ export interface PlaceholderProps {
45
45
  modifyComponentProps?: (componentProps: ComponentProps) => ComponentProps;
46
46
  /**
47
47
  * A component that is rendered in place of any components that are in this placeholder,
48
- * but do not have a definition in the componentFactory (i.e. don't have a React implementation)
48
+ * but do not have a definition in the componentMap (i.e. don't have a React implementation)
49
49
  */
50
50
  missingComponentComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
51
51
  /**
@@ -68,7 +68,7 @@ export interface PlaceholderProps {
68
68
  }
69
69
  export declare class PlaceholderCommon<T extends PlaceholderProps> extends React.Component<T> {
70
70
  static propTypes: {
71
- rendering: PropTypes.Validator<NonNullable<NonNullable<ComponentRendering<import("@sitecore-content-sdk/core/layout").ComponentFields> | RouteData<Record<string, Field<import("@sitecore-content-sdk/core/layout").GenericFieldValue> | Item | Item[]>>>>>;
71
+ rendering: PropTypes.Validator<NonNullable<NonNullable<RouteData<Record<string, Field<import("@sitecore-content-sdk/core/layout").GenericFieldValue> | Item | Item[]>> | ComponentRendering<import("@sitecore-content-sdk/core/layout").ComponentFields>>>>;
72
72
  fields: PropTypes.Requireable<{
73
73
  [x: string]: NonNullable<NonNullable<Field<import("@sitecore-content-sdk/core/layout").GenericFieldValue> | Item[]>>;
74
74
  }>;
@@ -1,18 +1,21 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { ComponentFactory } from './sharedTypes';
3
+ import { SitecoreConfig } from '@sitecore-content-sdk/core/config';
4
4
  import { LayoutServiceContext, LayoutServiceData, RouteData } from '../index';
5
+ import { ComponentMap } from './sharedTypes';
5
6
  export interface SitecoreContextProps {
6
- componentFactory: ComponentFactory;
7
+ api: SitecoreConfig['api'];
8
+ componentMap: ComponentMap;
7
9
  layoutData?: LayoutServiceData;
8
10
  children: React.ReactNode;
9
11
  }
10
12
  export interface SitecoreContextState {
11
13
  setContext: (value: SitecoreContextValue | LayoutServiceData) => void;
12
14
  context: SitecoreContextValue;
15
+ api?: SitecoreContextProps['api'];
13
16
  }
14
17
  export declare const SitecoreContextReactContext: React.Context<SitecoreContextState>;
15
- export declare const ComponentFactoryReactContext: React.Context<ComponentFactory>;
18
+ export declare const ComponentMapReactContext: React.Context<ComponentMap>;
16
19
  export type SitecoreContextValue = LayoutServiceContext & {
17
20
  itemId?: string;
18
21
  route?: RouteData;
@@ -20,7 +23,7 @@ export type SitecoreContextValue = LayoutServiceContext & {
20
23
  export declare class SitecoreContext extends React.Component<SitecoreContextProps, SitecoreContextState> {
21
24
  static propTypes: {
22
25
  children: PropTypes.Validator<any>;
23
- componentFactory: PropTypes.Requireable<(...args: any[]) => any>;
26
+ componentMap: PropTypes.Requireable<Map<unknown, unknown>>;
24
27
  layoutData: PropTypes.Requireable<PropTypes.InferProps<{
25
28
  sitecore: PropTypes.Requireable<PropTypes.InferProps<{
26
29
  context: PropTypes.Requireable<any>;
@@ -0,0 +1,32 @@
1
+ import { ComponentType } from 'react';
2
+ /**
3
+ * SXA uses custom default export name
4
+ */
5
+ export declare const DEFAULT_EXPORT_NAME = "Default";
6
+ /**
7
+ * React component import with account for custom exports
8
+ */
9
+ export type ReactJssComponent = ComponentType | ReactModule;
10
+ export type ReactModule = {
11
+ /**
12
+ * Custom exports
13
+ */
14
+ [key: string]: unknown;
15
+ /**
16
+ * Default module export
17
+ */
18
+ Default?: ComponentType;
19
+ /**
20
+ * Default non-standard export
21
+ */
22
+ default?: ComponentType;
23
+ };
24
+ /**
25
+ * Component type returned from component builder / factory
26
+ */
27
+ export type LazyComponentType = ComponentType & {
28
+ render?: {
29
+ [key: string]: unknown;
30
+ };
31
+ };
32
+ export type ComponentMap<TComponent extends ReactJssComponent = ReactJssComponent> = Map<string, TComponent>;
@@ -0,0 +1,2 @@
1
+ export * from './components';
2
+ export * from './props';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Shared editing field props
3
+ */
4
+ export interface EditableFieldProps {
5
+ /**
6
+ * Can be used to explicitly disable inline editing.
7
+ * @default true
8
+ */
9
+ editable?: boolean;
10
+ /**
11
+ * Custom element to render in Pages in edit mode if field value is empty
12
+ */
13
+ emptyFieldEditingComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
14
+ }
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ComponentMap } from '../components/sharedTypes';
3
+ export interface WithComponentMapProps {
4
+ componentMap?: ComponentMap;
5
+ }
6
+ /**
7
+ * @param {React.ComponentClass<T> | React.FC<T>} Component
8
+ */
9
+ export declare function withComponentMap<T extends WithComponentMapProps>(Component: React.ComponentClass<T> | React.FC<T>): {
10
+ (props: T): JSX.Element;
11
+ displayName: string;
12
+ };
@@ -1,11 +1,12 @@
1
1
  import React from 'react';
2
2
  import { EnhancedOmit } from '@sitecore-content-sdk/core/utils';
3
- import { SitecoreContextValue } from '../components/SitecoreContext';
3
+ import { SitecoreContextState, SitecoreContextValue } from '../components/SitecoreContext';
4
4
  export interface WithSitecoreContextOptions {
5
5
  updatable?: boolean;
6
6
  }
7
7
  export interface WithSitecoreContextProps {
8
8
  sitecoreContext: SitecoreContextValue;
9
+ api?: SitecoreContextState['api'];
9
10
  updateSitecoreContext?: ((value: SitecoreContextValue) => void) | false;
10
11
  }
11
12
  export type WithSitecoreContextHocProps<ComponentProps> = EnhancedOmit<ComponentProps, keyof WithSitecoreContextProps>;
@@ -19,7 +20,6 @@ export declare function withSitecoreContext(options?: WithSitecoreContextOptions
19
20
  * - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Sitecore Editor.
20
21
  * - pageState - Like pageEditing, but a string: normal, preview or edit.
21
22
  * - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
22
- * @see https://jss.sitecore.com/docs/techniques/extending-layout-service/layoutservice-extending-context
23
23
  * @param {WithSitecoreContextOptions} [options] hook options
24
24
  * @example
25
25
  * const EditMode = () => {
@@ -34,7 +34,4 @@ export declare function withSitecoreContext(options?: WithSitecoreContextOptions
34
34
  * }
35
35
  * @returns {object} { sitecoreContext, updateSitecoreContext }
36
36
  */
37
- export declare function useSitecoreContext(options?: WithSitecoreContextOptions): {
38
- sitecoreContext: SitecoreContextValue;
39
- updateSitecoreContext: (value: SitecoreContextValue | import("@sitecore-content-sdk/core/layout").LayoutServiceData) => void;
40
- };
37
+ export declare function useSitecoreContext(options?: WithSitecoreContextOptions): WithSitecoreContextProps;
package/types/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  export { constants, enableDebug, ClientError, CacheClient, CacheOptions, MemoryCacheClient, NativeDataFetcher, NativeDataFetcherResponse, NativeDataFetcherConfig, } from '@sitecore-content-sdk/core';
2
2
  export { EnhancedOmit } from '@sitecore-content-sdk/core/utils';
3
3
  export { isEditorActive, resetEditorChromes } from '@sitecore-content-sdk/core/editing';
4
- export { getContentStylesheetLink, getComponentLibraryStylesheetLinks, LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, RouteData, Field, Item, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, EditMode, } from '@sitecore-content-sdk/core/layout';
4
+ export { getContentStylesheetLink, getDesignLibraryStylesheetLinks, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, RouteData, Field, Item, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, EditMode, } from '@sitecore-content-sdk/core/layout';
5
5
  export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, } from '@sitecore-content-sdk/core/i18n';
6
- export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClientFactoryConfig, GraphQLRequestClient, } from '@sitecore-content-sdk/core/graphql';
6
+ export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClientFactoryConfig, GraphQLRequestClient, } from '@sitecore-content-sdk/core/client';
7
7
  export { mediaApi } from '@sitecore-content-sdk/core/media';
8
- export { ComponentFactory, JssComponentType } from './components/sharedTypes';
8
+ export { Form } from './components/Form';
9
+ export { ReactJssComponent, ComponentMap, ReactModule } from './components/sharedTypes';
9
10
  export { Placeholder, PlaceholderComponentProps } from './components/Placeholder';
10
11
  export { Image, ImageProps, ImageField, ImageFieldValue, ImageSizeParameters, } from './components/Image';
11
12
  export { RichText, RichTextProps, RichTextPropTypes, RichTextField } from './components/RichText';
@@ -13,7 +14,7 @@ export { Text, TextField } from './components/Text';
13
14
  export { DateField, DateFieldProps } from './components/Date';
14
15
  export { FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
15
16
  export { FEaaSWrapper } from './components/FEaaSWrapper';
16
- export { ComponentLibraryLayout } from './components/ComponentLibraryLayout';
17
+ export { DesignLibrary } from './components/DesignLibrary';
17
18
  export { BYOCComponent, BYOCComponentParams, BYOCComponentProps, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
18
19
  export { BYOCWrapper } from './components/BYOCWrapper';
19
20
  export { Link, LinkField, LinkFieldValue, LinkProps, LinkPropTypes } from './components/Link';
@@ -23,8 +24,8 @@ export { withSitecoreContext, useSitecoreContext, WithSitecoreContextOptions, Wi
23
24
  export { withEditorChromes } from './enhancers/withEditorChromes';
24
25
  export { withPlaceholder } from './enhancers/withPlaceholder';
25
26
  export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
26
- export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
27
27
  export { withFieldMetadata } from './enhancers/withFieldMetadata';
28
28
  export { withEmptyFieldEditingComponent } from './enhancers/withEmptyFieldEditingComponent';
29
29
  export { EditingScripts } from './components/EditingScripts';
30
30
  export { DefaultEmptyFieldEditingComponentText, DefaultEmptyFieldEditingComponentImage, } from './components/DefaultEmptyFieldEditingComponents';
31
+ export { GraphQLSitePathService, GraphQLSitePathServiceConfig, } from '@sitecore-content-sdk/core/site';
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ComponentBuilder = void 0;
4
- /**
5
- * React implementation of component builder class for building components based on the configuration.
6
- */
7
- class ComponentBuilder {
8
- constructor(config) {
9
- this.config = config;
10
- this.components = new Map([...config.components]);
11
- }
12
- /**
13
- * Creates a new instance of component factory
14
- * @returns {ComponentFactory} Component factory implementation
15
- */
16
- getComponentFactory() {
17
- return (componentName) => {
18
- const component = this.components.get(componentName);
19
- if (!component)
20
- return null;
21
- return component;
22
- };
23
- }
24
- }
25
- exports.ComponentBuilder = ComponentBuilder;
@@ -1,21 +0,0 @@
1
- /**
2
- * React 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
- this.components = new Map([...config.components]);
8
- }
9
- /**
10
- * Creates a new instance of component factory
11
- * @returns {ComponentFactory} Component factory implementation
12
- */
13
- getComponentFactory() {
14
- return (componentName) => {
15
- const component = this.components.get(componentName);
16
- if (!component)
17
- return null;
18
- return component;
19
- };
20
- }
21
- }
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- import { ComponentFactoryReactContext } from '../components/SitecoreContext';
3
- import { useContext } from 'react';
4
- /**
5
- * @param {React.ComponentClass<T> | React.FC<T>} Component
6
- */
7
- export function withComponentFactory(Component) {
8
- /**
9
- * @param {T} props - props to pass to the wrapped component
10
- * @returns {JSX.Element} - the rendered component
11
- */
12
- function WithComponentFactory(props) {
13
- const context = useContext(ComponentFactoryReactContext);
14
- return React.createElement(Component, Object.assign({}, props, { componentFactory: props.componentFactory || context }));
15
- }
16
- WithComponentFactory.displayName = `withComponentFactory(${Component.displayName ||
17
- Component.name ||
18
- 'Anonymous'})`;
19
- return WithComponentFactory;
20
- }
@@ -1,27 +0,0 @@
1
- import { ComponentType } from 'react';
2
- import { ComponentFactory } from './components/sharedTypes';
3
- /**
4
- * Configuration for ComponentBuilder
5
- */
6
- export type ComponentBuilderConfig<ComponentType> = {
7
- /**
8
- * List of components to be stored
9
- */
10
- components: Map<string, ComponentType>;
11
- };
12
- /**
13
- * React implementation of component builder class for building components based on the configuration.
14
- */
15
- export declare class ComponentBuilder {
16
- protected config: ComponentBuilderConfig<ComponentType>;
17
- /**
18
- * List of components to be stored
19
- */
20
- protected components: Map<string, ComponentType>;
21
- constructor(config: ComponentBuilderConfig<ComponentType>);
22
- /**
23
- * Creates a new instance of component factory
24
- * @returns {ComponentFactory} Component factory implementation
25
- */
26
- getComponentFactory(): ComponentFactory;
27
- }