@sitecore-content-sdk/react 0.1.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.
- package/LICENSE.txt +202 -0
- package/README.md +10 -0
- package/dist/cjs/ComponentBuilder.js +25 -0
- package/dist/cjs/components/BYOCComponent.js +132 -0
- package/dist/cjs/components/BYOCWrapper.js +21 -0
- package/dist/cjs/components/ComponentLibraryLayout.js +80 -0
- package/dist/cjs/components/Date.js +57 -0
- package/dist/cjs/components/DefaultEmptyFieldEditingComponents.js +22 -0
- package/dist/cjs/components/EditingScripts.js +27 -0
- package/dist/cjs/components/ErrorBoundary.js +95 -0
- package/dist/cjs/components/FEaaSComponent.js +161 -0
- package/dist/cjs/components/FEaaSWrapper.js +18 -0
- package/dist/cjs/components/FieldMetadata.js +34 -0
- package/dist/cjs/components/File.js +51 -0
- package/dist/cjs/components/HiddenRendering.js +18 -0
- package/dist/cjs/components/Image.js +83 -0
- package/dist/cjs/components/Link.js +106 -0
- package/dist/cjs/components/MissingComponent.js +34 -0
- package/dist/cjs/components/Placeholder.js +72 -0
- package/dist/cjs/components/PlaceholderCommon.js +191 -0
- package/dist/cjs/components/PlaceholderMetadata.js +63 -0
- package/dist/cjs/components/RichText.js +82 -0
- package/dist/cjs/components/SitecoreContext.js +67 -0
- package/dist/cjs/components/Text.js +78 -0
- package/dist/cjs/components/sharedTypes.js +2 -0
- package/dist/cjs/enhancers/withComponentFactory.js +26 -0
- package/dist/cjs/enhancers/withDatasourceCheck.js +28 -0
- package/dist/cjs/enhancers/withEditorChromes.js +24 -0
- package/dist/cjs/enhancers/withEmptyFieldEditingComponent.js +65 -0
- package/dist/cjs/enhancers/withFieldMetadata.js +69 -0
- package/dist/cjs/enhancers/withPlaceholder.js +63 -0
- package/dist/cjs/enhancers/withSitecoreContext.js +48 -0
- package/dist/cjs/index.js +78 -0
- package/dist/cjs/utils.js +38 -0
- package/dist/esm/ComponentBuilder.js +21 -0
- package/dist/esm/components/BYOCComponent.js +91 -0
- package/dist/esm/components/BYOCWrapper.js +14 -0
- package/dist/esm/components/ComponentLibraryLayout.js +43 -0
- package/dist/esm/components/Date.js +51 -0
- package/dist/esm/components/DefaultEmptyFieldEditingComponents.js +14 -0
- package/dist/esm/components/EditingScripts.js +20 -0
- package/dist/esm/components/ErrorBoundary.js +60 -0
- package/dist/esm/components/FEaaSComponent.js +119 -0
- package/dist/esm/components/FEaaSWrapper.js +11 -0
- package/dist/esm/components/FieldMetadata.js +27 -0
- package/dist/esm/components/File.js +44 -0
- package/dist/esm/components/HiddenRendering.js +11 -0
- package/dist/esm/components/Image.js +77 -0
- package/dist/esm/components/Link.js +67 -0
- package/dist/esm/components/MissingComponent.js +27 -0
- package/dist/esm/components/Placeholder.js +66 -0
- package/dist/esm/components/PlaceholderCommon.js +184 -0
- package/dist/esm/components/PlaceholderMetadata.js +56 -0
- package/dist/esm/components/RichText.js +43 -0
- package/dist/esm/components/SitecoreContext.js +60 -0
- package/dist/esm/components/Text.js +72 -0
- package/dist/esm/components/sharedTypes.js +1 -0
- package/dist/esm/enhancers/withComponentFactory.js +20 -0
- package/dist/esm/enhancers/withDatasourceCheck.js +20 -0
- package/dist/esm/enhancers/withEditorChromes.js +17 -0
- package/dist/esm/enhancers/withEmptyFieldEditingComponent.js +29 -0
- package/dist/esm/enhancers/withFieldMetadata.js +33 -0
- package/dist/esm/enhancers/withPlaceholder.js +57 -0
- package/dist/esm/enhancers/withSitecoreContext.js +41 -0
- package/dist/esm/index.js +28 -0
- package/dist/esm/utils.js +33 -0
- package/package.json +78 -0
- package/types/ComponentBuilder.d.ts +27 -0
- package/types/components/BYOCComponent.d.ts +93 -0
- package/types/components/BYOCWrapper.d.ts +6 -0
- package/types/components/ComponentLibraryLayout.d.ts +2 -0
- package/types/components/Date.d.ts +16 -0
- package/types/components/DefaultEmptyFieldEditingComponents.d.ts +3 -0
- package/types/components/EditingScripts.d.ts +4 -0
- package/types/components/ErrorBoundary.d.ts +17 -0
- package/types/components/FEaaSComponent.d.ts +71 -0
- package/types/components/FEaaSWrapper.d.ts +3 -0
- package/types/components/FieldMetadata.d.ts +22 -0
- package/types/components/File.d.ts +18 -0
- package/types/components/HiddenRendering.d.ts +2 -0
- package/types/components/Image.d.ts +48 -0
- package/types/components/Link.d.ts +38 -0
- package/types/components/MissingComponent.d.ts +8 -0
- package/types/components/Placeholder.d.ts +20 -0
- package/types/components/PlaceholderCommon.d.ts +98 -0
- package/types/components/PlaceholderMetadata.d.ts +28 -0
- package/types/components/RichText.d.ts +29 -0
- package/types/components/SitecoreContext.d.ts +42 -0
- package/types/components/Text.d.ts +20 -0
- package/types/components/sharedTypes.d.ts +28 -0
- package/types/enhancers/withComponentFactory.d.ts +12 -0
- package/types/enhancers/withDatasourceCheck.d.ts +21 -0
- package/types/enhancers/withEditorChromes.d.ts +2 -0
- package/types/enhancers/withEmptyFieldEditingComponent.d.ts +27 -0
- package/types/enhancers/withFieldMetadata.d.ts +16 -0
- package/types/enhancers/withPlaceholder.d.ts +34 -0
- package/types/enhancers/withSitecoreContext.d.ts +40 -0
- package/types/index.d.ts +30 -0
- package/types/utils.d.ts +17 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { constants, enableDebug, ClientError, MemoryCacheClient, NativeDataFetcher, } from '@sitecore-content-sdk/core';
|
|
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';
|
|
4
|
+
export { GraphQLDictionaryService, } from '@sitecore-content-sdk/core/i18n';
|
|
5
|
+
export { DefaultRetryStrategy, GraphQLRequestClient, } from '@sitecore-content-sdk/core/graphql';
|
|
6
|
+
export { mediaApi } from '@sitecore-content-sdk/core/media';
|
|
7
|
+
export { Placeholder } from './components/Placeholder';
|
|
8
|
+
export { Image, } from './components/Image';
|
|
9
|
+
export { RichText, RichTextPropTypes } from './components/RichText';
|
|
10
|
+
export { Text } from './components/Text';
|
|
11
|
+
export { DateField } from './components/Date';
|
|
12
|
+
export { FEaaSComponent, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
|
|
13
|
+
export { FEaaSWrapper } from './components/FEaaSWrapper';
|
|
14
|
+
export { ComponentLibraryLayout } from './components/ComponentLibraryLayout';
|
|
15
|
+
export { BYOCComponent, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
|
|
16
|
+
export { BYOCWrapper } from './components/BYOCWrapper';
|
|
17
|
+
export { Link, LinkPropTypes } from './components/Link';
|
|
18
|
+
export { File } from './components/File';
|
|
19
|
+
export { SitecoreContext, SitecoreContextReactContext, } from './components/SitecoreContext';
|
|
20
|
+
export { withSitecoreContext, useSitecoreContext, } from './enhancers/withSitecoreContext';
|
|
21
|
+
export { withEditorChromes } from './enhancers/withEditorChromes';
|
|
22
|
+
export { withPlaceholder } from './enhancers/withPlaceholder';
|
|
23
|
+
export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
|
|
24
|
+
export { ComponentBuilder } from './ComponentBuilder';
|
|
25
|
+
export { withFieldMetadata } from './enhancers/withFieldMetadata';
|
|
26
|
+
export { withEmptyFieldEditingComponent } from './enhancers/withEmptyFieldEditingComponent';
|
|
27
|
+
export { EditingScripts } from './components/EditingScripts';
|
|
28
|
+
export { DefaultEmptyFieldEditingComponentText, DefaultEmptyFieldEditingComponentImage, } from './components/DefaultEmptyFieldEditingComponents';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getFieldValue } from '@sitecore-content-sdk/core/layout';
|
|
2
|
+
/**
|
|
3
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
4
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
5
|
+
* @returns {void}
|
|
6
|
+
*/
|
|
7
|
+
export const addClassName = (otherAttrs) => {
|
|
8
|
+
if (otherAttrs.class) {
|
|
9
|
+
// if any classes are defined properly already
|
|
10
|
+
if (otherAttrs.className) {
|
|
11
|
+
let className = otherAttrs.className;
|
|
12
|
+
className += ` ${otherAttrs.class}`;
|
|
13
|
+
otherAttrs.className = className;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
otherAttrs.className = otherAttrs.class;
|
|
17
|
+
}
|
|
18
|
+
delete otherAttrs.class;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Used in FEAAS and BYOC implementations to convert datasource item field values into component props
|
|
23
|
+
* @param {ComponentFields} fields field collection from Sitecore
|
|
24
|
+
* @returns JSON object that can be used as props
|
|
25
|
+
*/
|
|
26
|
+
export const getDataFromFields = (fields) => {
|
|
27
|
+
let data = {};
|
|
28
|
+
data = Object.entries(fields).reduce((acc, [key]) => {
|
|
29
|
+
acc[key] = getFieldValue(fields, key);
|
|
30
|
+
return acc;
|
|
31
|
+
}, data);
|
|
32
|
+
return data;
|
|
33
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sitecore-content-sdk/react",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
13
|
+
"clean": "del-cli dist types",
|
|
14
|
+
"lint": "eslint \"./src/**/*.tsx\" \"./src/**/*.ts\"",
|
|
15
|
+
"test": "mocha --require ts-node/register/transpile-only --require ./src/tests/jsdom-setup.ts \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"coverage": "nyc npm test",
|
|
18
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/react src/index.ts --githubPages false"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Sitecore Corporation",
|
|
25
|
+
"url": "https://jss.sitecore.com"
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"homepage": "https://jss.sitecore.com",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/sitecore/jss/issues"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@sitecore-feaas/clientside": "^0.5.19",
|
|
34
|
+
"@testing-library/dom": "^10.4.0",
|
|
35
|
+
"@testing-library/react": "^16.1.0",
|
|
36
|
+
"@testing-library/user-event": "^14.6.0",
|
|
37
|
+
"@types/chai": "^5.0.1",
|
|
38
|
+
"@types/chai-string": "^1.4.5",
|
|
39
|
+
"@types/mocha": "^10.0.10",
|
|
40
|
+
"@types/node": "22.12.0",
|
|
41
|
+
"@types/prop-types": "^15.7.14",
|
|
42
|
+
"@types/react": "^18.2.45",
|
|
43
|
+
"@types/react-dom": "^18.0.10",
|
|
44
|
+
"@types/sinon": "^17.0.3",
|
|
45
|
+
"@types/sinon-chai": "^4.0.0",
|
|
46
|
+
"chai": "^4.3.7",
|
|
47
|
+
"chai-string": "^1.5.0",
|
|
48
|
+
"del-cli": "^6.0.0",
|
|
49
|
+
"eslint": "^8.56.0",
|
|
50
|
+
"eslint-plugin-react": "^7.31.11",
|
|
51
|
+
"jsdom": "^26.0.0",
|
|
52
|
+
"mocha": "^11.1.0",
|
|
53
|
+
"nyc": "^17.1.0",
|
|
54
|
+
"react": "^18.2.0",
|
|
55
|
+
"react-dom": "^18.2.0",
|
|
56
|
+
"sinon": "^19.0.2",
|
|
57
|
+
"sinon-chai": "^3.7.0",
|
|
58
|
+
"ts-node": "^10.9.1",
|
|
59
|
+
"typescript": "~5.7.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@sitecore-feaas/clientside": "^0.5.19",
|
|
63
|
+
"react": "^18.2.0",
|
|
64
|
+
"react-dom": "^18.2.0"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@sitecore-content-sdk/core": "^0.1.0-beta.1",
|
|
68
|
+
"fast-deep-equal": "^3.1.3",
|
|
69
|
+
"prop-types": "^15.8.1"
|
|
70
|
+
},
|
|
71
|
+
"description": "",
|
|
72
|
+
"types": "types/index.d.ts",
|
|
73
|
+
"gitHead": "11e6c0ce4b6bcaf8a5ddffa39a921c8dd145e603",
|
|
74
|
+
"files": [
|
|
75
|
+
"dist",
|
|
76
|
+
"types"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentFields, ComponentRendering } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
import { MissingComponentProps } from './MissingComponent';
|
|
4
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
5
|
+
export declare const BYOC_COMPONENT_RENDERING_NAME = "BYOCComponent";
|
|
6
|
+
/**
|
|
7
|
+
* TODO: remove when framework agnostic forms implemented
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* FEaaS props for server rendering.
|
|
11
|
+
*/
|
|
12
|
+
type BYOCServerProps = {
|
|
13
|
+
/**
|
|
14
|
+
* Fetched data from server component props for server rendering, based on rendering params.
|
|
15
|
+
*/
|
|
16
|
+
fetchedData?: FEAAS.DataScopes;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Data from rendering params on Sitecore's BYOC rendering
|
|
20
|
+
*/
|
|
21
|
+
export type BYOCComponentParams = {
|
|
22
|
+
/**
|
|
23
|
+
* Name of the component to render
|
|
24
|
+
*/
|
|
25
|
+
ComponentName?: string;
|
|
26
|
+
/**
|
|
27
|
+
* JSON props to pass into rendered component
|
|
28
|
+
*/
|
|
29
|
+
ComponentProps?: string;
|
|
30
|
+
/**
|
|
31
|
+
* A JSON object with data sources to be fetched and passed to the component
|
|
32
|
+
*/
|
|
33
|
+
ComponentDataOverride?: string;
|
|
34
|
+
/**
|
|
35
|
+
* A string with classes that can be used to apply themes, via SXA functionality
|
|
36
|
+
*/
|
|
37
|
+
styles?: string;
|
|
38
|
+
RenderingIdentifier?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Props for BYOCComponent. Includes components list to load external components from.
|
|
42
|
+
*/
|
|
43
|
+
export type BYOCComponentClientProps = {
|
|
44
|
+
/**
|
|
45
|
+
* rendering data
|
|
46
|
+
*/
|
|
47
|
+
rendering: ComponentRendering;
|
|
48
|
+
/**
|
|
49
|
+
* rendering params
|
|
50
|
+
*/
|
|
51
|
+
params?: BYOCComponentParams;
|
|
52
|
+
/**
|
|
53
|
+
* fields from datasource items to be passed as rendered child component props
|
|
54
|
+
*/
|
|
55
|
+
fields?: ComponentFields;
|
|
56
|
+
/**
|
|
57
|
+
* Error component override. To be shown when Renderer or underlying component throws
|
|
58
|
+
*/
|
|
59
|
+
errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
|
|
60
|
+
/**
|
|
61
|
+
* Override to indicate missing component situations. Would be shown when BYOC component is not registered
|
|
62
|
+
* or ComponentName is missing
|
|
63
|
+
*/
|
|
64
|
+
missingComponentComponent?: React.ComponentClass<MissingComponentProps> | React.FC<MissingComponentProps>;
|
|
65
|
+
};
|
|
66
|
+
export type BYOCComponentProps = BYOCComponentClientProps & BYOCServerProps;
|
|
67
|
+
type ErrorComponentProps = {
|
|
68
|
+
[prop: string]: unknown;
|
|
69
|
+
error?: Error;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* BYOCComponent facilitate the rendering of external components. It manages potential errors,
|
|
73
|
+
* missing components, and customization of error messages or alternative rendering components.
|
|
74
|
+
* @param {ByocComponentProps} props component props
|
|
75
|
+
* @returns dynamicly rendered component or Missing Component error frame
|
|
76
|
+
*/
|
|
77
|
+
export declare class BYOCComponent extends React.Component<BYOCComponentProps> {
|
|
78
|
+
state: Readonly<{
|
|
79
|
+
error?: Error;
|
|
80
|
+
}>;
|
|
81
|
+
constructor(props: BYOCComponentProps);
|
|
82
|
+
static getDerivedStateFromError(error: Error): {
|
|
83
|
+
error: Error;
|
|
84
|
+
};
|
|
85
|
+
componentDidCatch(error: Error): void;
|
|
86
|
+
render(): React.JSX.Element;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Fetches server component props required for server rendering, based on rendering params.
|
|
90
|
+
* @param {BYOCComponentParams} params component params
|
|
91
|
+
*/
|
|
92
|
+
export declare function fetchBYOCComponentServerProps(params: BYOCComponentParams): Promise<BYOCServerProps>;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BYOCComponentProps } from './BYOCComponent';
|
|
2
|
+
export declare const BYOC_WRAPPER_RENDERING_NAME = "BYOCWrapper";
|
|
3
|
+
/**
|
|
4
|
+
* TODO: remove when framework agnostic forms implemented
|
|
5
|
+
*/
|
|
6
|
+
export declare const BYOCWrapper: (props: BYOCComponentProps) => JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EditableFieldProps } from './sharedTypes';
|
|
3
|
+
import { FieldMetadata } from '@sitecore-content-sdk/core/layout';
|
|
4
|
+
export interface DateFieldProps extends EditableFieldProps {
|
|
5
|
+
/** The date field data. */
|
|
6
|
+
[htmlAttributes: string]: unknown;
|
|
7
|
+
field: FieldMetadata & {
|
|
8
|
+
value?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The HTML element that will wrap the contents of the field.
|
|
12
|
+
*/
|
|
13
|
+
tag?: string;
|
|
14
|
+
render?: (date: Date | null) => React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare const DateField: React.FC<DateFieldProps>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ComponentRendering } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
import { SitecoreContextValue } from './SitecoreContext';
|
|
4
|
+
type ErrorComponentProps = {
|
|
5
|
+
[prop: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
export type ErrorBoundaryProps = {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
sitecoreContext: SitecoreContextValue;
|
|
10
|
+
type: string;
|
|
11
|
+
isDynamic?: boolean;
|
|
12
|
+
errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
|
|
13
|
+
rendering?: ComponentRendering;
|
|
14
|
+
componentLoadingMessage?: string;
|
|
15
|
+
};
|
|
16
|
+
declare const _default: (props: import("@sitecore-content-sdk/core/utils").EnhancedOmit<ErrorBoundaryProps, keyof import("../enhancers/withSitecoreContext").WithSitecoreContextProps>) => React.JSX.Element;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
2
|
+
import { ComponentFields, LayoutServicePageState } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
export declare const FEAAS_COMPONENT_RENDERING_NAME = "FEaaSComponent";
|
|
4
|
+
/**
|
|
5
|
+
* Params from a Sitecore FEaaS rendering
|
|
6
|
+
*/
|
|
7
|
+
export type FEaaSComponentParams = {
|
|
8
|
+
LibraryId?: string;
|
|
9
|
+
ComponentId?: string;
|
|
10
|
+
ComponentVersion?: string;
|
|
11
|
+
ComponentRevision?: RevisionType;
|
|
12
|
+
ComponentHostName?: string;
|
|
13
|
+
ComponentInstanceId?: string;
|
|
14
|
+
ComponentDataOverride?: string;
|
|
15
|
+
ComponentHTMLOverride?: string;
|
|
16
|
+
styles?: string;
|
|
17
|
+
RenderingIdentifier?: string;
|
|
18
|
+
};
|
|
19
|
+
type RevisionType = number | 'staged' | 'published' | 'saved';
|
|
20
|
+
/**
|
|
21
|
+
* FEaaS props for server rendering.
|
|
22
|
+
*/
|
|
23
|
+
type FEaaSComponentServerProps = {
|
|
24
|
+
/**
|
|
25
|
+
* HTML template for presentation rendered inside the component
|
|
26
|
+
*/
|
|
27
|
+
template?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Default revision to be fetched. Should be 'staged' for editing/preview. Can be overriden by params.ComponentRevision
|
|
30
|
+
*/
|
|
31
|
+
revisionFallback?: RevisionType;
|
|
32
|
+
/**
|
|
33
|
+
* Fetched data from server component props for server rendering, based on rendering params.
|
|
34
|
+
*/
|
|
35
|
+
fetchedData?: FEAAS.DataScopes;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* FEaaS props for client side component. Should be used as fallback when server props are not provided.
|
|
39
|
+
* Would also be passed on server to avoid hydration issues
|
|
40
|
+
*/
|
|
41
|
+
type FEaaSComponentClientProps = {
|
|
42
|
+
/**
|
|
43
|
+
* parameters from Sitecore's FEAAS component
|
|
44
|
+
*/
|
|
45
|
+
params?: FEaaSComponentParams;
|
|
46
|
+
/**
|
|
47
|
+
* field data from component's datasource
|
|
48
|
+
*/
|
|
49
|
+
fields?: ComponentFields;
|
|
50
|
+
};
|
|
51
|
+
export type FEaaSComponentProps = FEaaSComponentServerProps & FEaaSComponentClientProps;
|
|
52
|
+
/**
|
|
53
|
+
* @param {FEaaSComponentProps} props component props
|
|
54
|
+
*/
|
|
55
|
+
export declare const FEaaSComponent: (props: FEaaSComponentProps) => JSX.Element;
|
|
56
|
+
/**
|
|
57
|
+
* Fetches server component props required for server rendering, based on rendering params.
|
|
58
|
+
* Component endpoint will either be retrieved from params or from endpointOverride
|
|
59
|
+
* @param {FEaaSComponentParams} params component params
|
|
60
|
+
* @param {LayoutServicePageState} [pageState] page state to determine which component variant to use
|
|
61
|
+
* @param {string} [endpointOverride] optional override for component endpoint
|
|
62
|
+
*/
|
|
63
|
+
export declare function fetchFEaaSComponentServerProps(params: FEaaSComponentParams, pageState?: LayoutServicePageState, endpointOverride?: string): Promise<FEaaSComponentProps>;
|
|
64
|
+
/**
|
|
65
|
+
* Build component endpoint URL from component's params
|
|
66
|
+
* @param {FEaaSComponentParams} params rendering parameters for FEAAS component
|
|
67
|
+
* @param {RevisionType} revisionFallback fallback revision to fetch if revision is absent in params
|
|
68
|
+
* @returns component endpoint URL
|
|
69
|
+
*/
|
|
70
|
+
export declare const composeComponentEndpoint: (params: FEaaSComponentParams, revisionFallback: RevisionType) => string;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
interface FieldMetadataProps {
|
|
4
|
+
metadata: {
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
};
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The component which renders field metadata markup
|
|
11
|
+
* @param {FieldMetadataProps} props the props of the component
|
|
12
|
+
* @returns metadata markup wrapped around children
|
|
13
|
+
*/
|
|
14
|
+
export declare const FieldMetadata: {
|
|
15
|
+
(props: FieldMetadataProps): JSX.Element;
|
|
16
|
+
displayName: string;
|
|
17
|
+
propTypes: {
|
|
18
|
+
metadata: PropTypes.Validator<object>;
|
|
19
|
+
children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface FileFieldValue {
|
|
3
|
+
[propName: string]: unknown;
|
|
4
|
+
src?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface FileField {
|
|
9
|
+
value: FileFieldValue;
|
|
10
|
+
}
|
|
11
|
+
export interface FileProps {
|
|
12
|
+
[attributeName: string]: unknown;
|
|
13
|
+
/** The file field data. */
|
|
14
|
+
field: FileFieldValue | FileField;
|
|
15
|
+
/** HTML attributes that will be appended to the rendered <a /> tag. */
|
|
16
|
+
children?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
export declare const File: React.FC<FileProps>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EditableFieldProps } from './sharedTypes';
|
|
3
|
+
import { FieldMetadata } from '@sitecore-content-sdk/core/layout';
|
|
4
|
+
export interface ImageFieldValue {
|
|
5
|
+
[attributeName: string]: unknown;
|
|
6
|
+
src?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ImageField {
|
|
9
|
+
value?: ImageFieldValue;
|
|
10
|
+
}
|
|
11
|
+
export interface ImageSizeParameters {
|
|
12
|
+
[attr: string]: string | number | undefined;
|
|
13
|
+
/** Fixed width of the image */
|
|
14
|
+
w?: number;
|
|
15
|
+
/** Fixed height of the image */
|
|
16
|
+
h?: number;
|
|
17
|
+
/** Max width of the image */
|
|
18
|
+
mw?: number;
|
|
19
|
+
/** Max height of the image */
|
|
20
|
+
mh?: number;
|
|
21
|
+
/** Ignore aspect ratio */
|
|
22
|
+
iar?: 1 | 0;
|
|
23
|
+
/** Allow stretch */
|
|
24
|
+
as?: 1 | 0;
|
|
25
|
+
/** Image scale. Defaults to 1.0 */
|
|
26
|
+
sc?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface ImageProps extends EditableFieldProps {
|
|
29
|
+
[attributeName: string]: unknown;
|
|
30
|
+
/** Image field data (consistent with other field types) */
|
|
31
|
+
field?: (ImageField | ImageFieldValue) & FieldMetadata;
|
|
32
|
+
/**
|
|
33
|
+
* Parameters that will be attached to Sitecore media URLs
|
|
34
|
+
*/
|
|
35
|
+
imageParams?: {
|
|
36
|
+
[paramName: string]: string | number;
|
|
37
|
+
};
|
|
38
|
+
srcSet?: ImageSizeParameters[];
|
|
39
|
+
/**
|
|
40
|
+
* Custom regexp that finds media URL prefix that will be replaced by `/-/jssmedia` or `/~/jssmedia`.
|
|
41
|
+
* @example
|
|
42
|
+
* /\/([-~]{1})assets\//i
|
|
43
|
+
* /-assets/website -> /-/jssmedia/website
|
|
44
|
+
* /~assets/website -> /~/jssmedia/website
|
|
45
|
+
*/
|
|
46
|
+
mediaUrlPrefix?: RegExp;
|
|
47
|
+
}
|
|
48
|
+
export declare const Image: React.FC<ImageProps>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { RefAttributes } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { FieldMetadata } from '@sitecore-content-sdk/core/layout';
|
|
4
|
+
import { EditableFieldProps } from './sharedTypes';
|
|
5
|
+
export interface LinkFieldValue {
|
|
6
|
+
[attributeName: string]: unknown;
|
|
7
|
+
href?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
class?: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
target?: string;
|
|
12
|
+
text?: string;
|
|
13
|
+
anchor?: string;
|
|
14
|
+
querystring?: string;
|
|
15
|
+
linktype?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface LinkField {
|
|
18
|
+
value: LinkFieldValue;
|
|
19
|
+
}
|
|
20
|
+
export type LinkProps = EditableFieldProps & React.AnchorHTMLAttributes<HTMLAnchorElement> & RefAttributes<HTMLAnchorElement> & {
|
|
21
|
+
/** The link field data. */
|
|
22
|
+
field: (LinkField | LinkFieldValue) & FieldMetadata;
|
|
23
|
+
/**
|
|
24
|
+
* Displays a link text ('description' in Sitecore) even when children exist
|
|
25
|
+
*/
|
|
26
|
+
showLinkTextWithChildrenPresent?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare const Link: React.FC<LinkProps>;
|
|
29
|
+
export declare const LinkPropTypes: {
|
|
30
|
+
field: PropTypes.Validator<NonNullable<NonNullable<PropTypes.InferProps<{
|
|
31
|
+
href: PropTypes.Requireable<any>;
|
|
32
|
+
}> | PropTypes.InferProps<{
|
|
33
|
+
value: PropTypes.Requireable<object>;
|
|
34
|
+
}>>>>;
|
|
35
|
+
editable: PropTypes.Requireable<boolean>;
|
|
36
|
+
showLinkTextWithChildrenPresent: PropTypes.Requireable<boolean>;
|
|
37
|
+
emptyFieldEditingComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
38
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PlaceholderProps } from './PlaceholderCommon';
|
|
3
|
+
import { ComponentRendering } from '@sitecore-content-sdk/core/layout';
|
|
4
|
+
export interface PlaceholderComponentProps extends PlaceholderProps {
|
|
5
|
+
/**
|
|
6
|
+
* Render props function that is called when the placeholder contains no content components.
|
|
7
|
+
*/
|
|
8
|
+
renderEmpty?: (components: React.ReactNode[]) => React.ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* Render props function that enables control over the rendering of the components in the placeholder.
|
|
11
|
+
* Useful for techniques like wrapping each child in a wrapper component.
|
|
12
|
+
*/
|
|
13
|
+
render?: (components: React.ReactNode[], data: ComponentRendering[], props: PlaceholderProps) => React.ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Render props function that is called for each non-system component added to the placeholder.
|
|
16
|
+
* Mutually exclusive with `render`.
|
|
17
|
+
*/
|
|
18
|
+
renderEach?: (component: React.ReactNode, index: number) => React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
export declare const Placeholder: (props: import("@sitecore-content-sdk/core/utils").EnhancedOmit<PlaceholderComponentProps, keyof import("../enhancers/withSitecoreContext").WithSitecoreContextProps>) => React.JSX.Element;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { ComponentType } from 'react';
|
|
2
|
+
import PropTypes, { Requireable } from 'prop-types';
|
|
3
|
+
import { ComponentFactory } from './sharedTypes';
|
|
4
|
+
import { ComponentRendering, RouteData, Field, Item } from '@sitecore-content-sdk/core/layout';
|
|
5
|
+
import { SitecoreContextValue } from './SitecoreContext';
|
|
6
|
+
type ErrorComponentProps = {
|
|
7
|
+
[prop: string]: unknown;
|
|
8
|
+
};
|
|
9
|
+
/** Provided for the component which represents rendering data */
|
|
10
|
+
export type ComponentProps = {
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
rendering: ComponentRendering;
|
|
13
|
+
};
|
|
14
|
+
export interface PlaceholderProps {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
/** Name of the placeholder to render. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Rendering data to be used when rendering the placeholder. */
|
|
19
|
+
rendering: ComponentRendering | RouteData;
|
|
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.
|
|
23
|
+
*/
|
|
24
|
+
componentFactory?: ComponentFactory;
|
|
25
|
+
/**
|
|
26
|
+
* An object of field names/values that are aggregated and propagated through the component tree created by a placeholder.
|
|
27
|
+
* Any component or placeholder rendered by a placeholder will have access to this data via `props.fields`.
|
|
28
|
+
*/
|
|
29
|
+
fields?: {
|
|
30
|
+
[name: string]: Field | Item[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* An object of rendering parameter names/values that are aggregated and propagated through the component tree created by a placeholder.
|
|
34
|
+
* Any component or placeholder rendered by a placeholder will have access to this data via `props.params`.
|
|
35
|
+
*/
|
|
36
|
+
params?: {
|
|
37
|
+
[name: string]: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Modify final props of component (before render) provided by rendering data.
|
|
41
|
+
* Can be used in case when you need to insert additional data into the component.
|
|
42
|
+
* @param {ComponentProps} componentProps component props to be modified
|
|
43
|
+
* @returns {ComponentProps} modified or initial props
|
|
44
|
+
*/
|
|
45
|
+
modifyComponentProps?: (componentProps: ComponentProps) => ComponentProps;
|
|
46
|
+
/**
|
|
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)
|
|
49
|
+
*/
|
|
50
|
+
missingComponentComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* A component that is rendered in place of any components that are hidden
|
|
53
|
+
*/
|
|
54
|
+
hiddenRenderingComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
|
|
55
|
+
/**
|
|
56
|
+
* A component that is rendered in place of the placeholder when an error occurs rendering
|
|
57
|
+
* the placeholder
|
|
58
|
+
*/
|
|
59
|
+
errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
|
|
60
|
+
/**
|
|
61
|
+
* Context data from the Sitecore Layout Service
|
|
62
|
+
*/
|
|
63
|
+
sitecoreContext: SitecoreContextValue;
|
|
64
|
+
/**
|
|
65
|
+
* The message that gets displayed while component is loading
|
|
66
|
+
*/
|
|
67
|
+
componentLoadingMessage?: string;
|
|
68
|
+
}
|
|
69
|
+
export declare class PlaceholderCommon<T extends PlaceholderProps> extends React.Component<T> {
|
|
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[]>>>>>;
|
|
72
|
+
fields: PropTypes.Requireable<{
|
|
73
|
+
[x: string]: NonNullable<NonNullable<Field<import("@sitecore-content-sdk/core/layout").GenericFieldValue> | Item[]>>;
|
|
74
|
+
}>;
|
|
75
|
+
params: PropTypes.Requireable<{
|
|
76
|
+
[x: string]: string;
|
|
77
|
+
}>;
|
|
78
|
+
missingComponentComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
79
|
+
hiddenRenderingComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
80
|
+
errorComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
81
|
+
modifyComponentProps: PropTypes.Requireable<(...args: any[]) => any>;
|
|
82
|
+
sitecoreContext: Requireable<SitecoreContextValue>;
|
|
83
|
+
};
|
|
84
|
+
state: Readonly<{
|
|
85
|
+
error?: Error;
|
|
86
|
+
}>;
|
|
87
|
+
constructor(props: T);
|
|
88
|
+
static getPlaceholderDataFromRenderingData(rendering: ComponentRendering | RouteData, name: string, isEditing: boolean): ComponentRendering<import("@sitecore-content-sdk/core/layout").ComponentFields>[];
|
|
89
|
+
componentDidCatch(error: Error): void;
|
|
90
|
+
getSXAParams(rendering: ComponentRendering): {
|
|
91
|
+
styles?: undefined;
|
|
92
|
+
} | {
|
|
93
|
+
styles: string;
|
|
94
|
+
};
|
|
95
|
+
getComponentsForRenderingData(placeholderData: ComponentRendering[]): React.JSX.Element[];
|
|
96
|
+
getComponentForRendering(renderingDefinition: ComponentRendering): ComponentType | null;
|
|
97
|
+
}
|
|
98
|
+
export {};
|