@sitecore-jss/sitecore-jss-react 0.1.0-beta.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.
- package/LICENSE.txt +202 -0
- package/README.md +8 -0
- package/dist/cjs/ComponentBuilder.js +25 -0
- package/dist/cjs/components/BYOCComponent.js +122 -0
- package/dist/cjs/components/BYOCWrapper.js +18 -0
- package/dist/cjs/components/Date.js +58 -0
- package/dist/cjs/components/EditFrame.js +39 -0
- package/dist/cjs/components/FEaaSComponent.js +152 -0
- package/dist/cjs/components/FEaaSWrapper.js +18 -0
- package/dist/cjs/components/File.js +53 -0
- package/dist/cjs/components/HiddenRendering.js +15 -0
- package/dist/cjs/components/Image.js +120 -0
- package/dist/cjs/components/Link.js +115 -0
- package/dist/cjs/components/MissingComponent.js +34 -0
- package/dist/cjs/components/Placeholder.js +80 -0
- package/dist/cjs/components/PlaceholderCommon.js +212 -0
- package/dist/cjs/components/RichText.js +66 -0
- package/dist/cjs/components/SitecoreContext.js +67 -0
- package/dist/cjs/components/Text.js +83 -0
- package/dist/cjs/components/sharedTypes.js +2 -0
- package/dist/cjs/enhancers/withComponentFactory.js +27 -0
- package/dist/cjs/enhancers/withDatasourceCheck.js +28 -0
- package/dist/cjs/enhancers/withEditorChromes.js +24 -0
- package/dist/cjs/enhancers/withPlaceholder.js +63 -0
- package/dist/cjs/enhancers/withSitecoreContext.js +53 -0
- package/dist/cjs/index.js +66 -0
- package/dist/cjs/utils.js +118 -0
- package/dist/esm/ComponentBuilder.js +21 -0
- package/dist/esm/components/BYOCComponent.js +91 -0
- package/dist/esm/components/BYOCWrapper.js +11 -0
- package/dist/esm/components/Date.js +51 -0
- package/dist/esm/components/EditFrame.js +32 -0
- package/dist/esm/components/FEaaSComponent.js +120 -0
- package/dist/esm/components/FEaaSWrapper.js +11 -0
- package/dist/esm/components/File.js +46 -0
- package/dist/esm/components/HiddenRendering.js +8 -0
- package/dist/esm/components/Image.js +112 -0
- package/dist/esm/components/Link.js +86 -0
- package/dist/esm/components/MissingComponent.js +27 -0
- package/dist/esm/components/Placeholder.js +74 -0
- package/dist/esm/components/PlaceholderCommon.js +205 -0
- package/dist/esm/components/RichText.js +37 -0
- package/dist/esm/components/SitecoreContext.js +60 -0
- package/dist/esm/components/Text.js +76 -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/withPlaceholder.js +56 -0
- package/dist/esm/enhancers/withSitecoreContext.js +45 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/utils.js +109 -0
- package/package.json +76 -0
- package/types/ComponentBuilder.d.ts +28 -0
- package/types/components/BYOCComponent.d.ts +87 -0
- package/types/components/BYOCWrapper.d.ts +3 -0
- package/types/components/Date.d.ts +22 -0
- package/types/components/EditFrame.d.ts +12 -0
- package/types/components/FEaaSComponent.d.ts +71 -0
- package/types/components/FEaaSWrapper.d.ts +3 -0
- package/types/components/File.d.ts +19 -0
- package/types/components/HiddenRendering.d.ts +4 -0
- package/types/components/Image.d.ts +62 -0
- package/types/components/Link.d.ts +47 -0
- package/types/components/MissingComponent.d.ts +9 -0
- package/types/components/Placeholder.d.ts +25 -0
- package/types/components/PlaceholderCommon.d.ts +105 -0
- package/types/components/RichText.d.ts +32 -0
- package/types/components/SitecoreContext.d.ts +43 -0
- package/types/components/Text.d.ts +26 -0
- package/types/components/sharedTypes.d.ts +7 -0
- package/types/enhancers/withComponentFactory.d.ts +13 -0
- package/types/enhancers/withDatasourceCheck.d.ts +22 -0
- package/types/enhancers/withEditorChromes.d.ts +3 -0
- package/types/enhancers/withPlaceholder.d.ts +37 -0
- package/types/enhancers/withSitecoreContext.d.ts +47 -0
- package/types/index.d.ts +24 -0
- package/types/utils.d.ts +42 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { getFieldValue } from '@sitecore-jss/sitecore-jss/layout';
|
|
13
|
+
import { parse as styleParse } from 'style-attr';
|
|
14
|
+
// https://stackoverflow.com/a/10426674/9324
|
|
15
|
+
export const convertKebabCasetoCamelCase = (str) => str.replace(/^.|-./g, (letter, index) => index === 0 ? letter.toLowerCase() : letter.substr(1).toUpperCase());
|
|
16
|
+
/**
|
|
17
|
+
* https://facebook.github.io/react/docs/dom-elements.html
|
|
18
|
+
* We are only concerned with style at the moment, which needs to be converted from string to object to satisfy React.
|
|
19
|
+
* We don't need to convert any other attributes (that we know of), because the placeholder renders them "as-is" by using the special "is" React prop.
|
|
20
|
+
* For whatever reason though, the "style" prop is still validated as needing to be an object when using the "is" prop, which is why we need to convert from string to object.
|
|
21
|
+
* @param {string} [style] style
|
|
22
|
+
* @returns {Array} converted attributes
|
|
23
|
+
*/
|
|
24
|
+
export const convertStyleAttribute = (style = '') => {
|
|
25
|
+
// styleParse converts a style attribute string into an object format
|
|
26
|
+
const parsedStyle = styleParse(style, { preserveNumbers: true });
|
|
27
|
+
return Object.keys(parsedStyle).reduce((initialResult, styleKey) => {
|
|
28
|
+
const result = initialResult;
|
|
29
|
+
const convertedKey = convertKebabCasetoCamelCase(styleKey);
|
|
30
|
+
result[convertedKey] = parsedStyle[styleKey];
|
|
31
|
+
return result;
|
|
32
|
+
}, {});
|
|
33
|
+
};
|
|
34
|
+
export const convertAttributesToReactProps = (attributes) => {
|
|
35
|
+
if (!attributes) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
return Object.keys(attributes).reduce((initialResult, attrName) => {
|
|
39
|
+
const result = initialResult;
|
|
40
|
+
switch (attrName) {
|
|
41
|
+
case 'class': {
|
|
42
|
+
result.className = attributes.class;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'style': {
|
|
46
|
+
result.style = convertStyleAttribute(attributes.style);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
result[attrName] = attributes[attrName];
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}, {});
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
59
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/
|
|
62
|
+
export const addClassName = (otherAttrs) => {
|
|
63
|
+
if (otherAttrs.class) {
|
|
64
|
+
// if any classes are defined properly already
|
|
65
|
+
if (otherAttrs.className) {
|
|
66
|
+
let className = otherAttrs.className;
|
|
67
|
+
className += ` ${otherAttrs.class}`;
|
|
68
|
+
otherAttrs.className = className;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
otherAttrs.className = otherAttrs.class;
|
|
72
|
+
}
|
|
73
|
+
delete otherAttrs.class;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Converts the given tag attributes object to a string
|
|
78
|
+
* @param {Object.<string, unknown>} attributes the attributes object
|
|
79
|
+
* @returns {string} string representation of the attributes
|
|
80
|
+
*/
|
|
81
|
+
export const getAttributesString = (attributes) => {
|
|
82
|
+
const { className } = attributes, restAttributes = __rest(attributes, ["className"]);
|
|
83
|
+
const attributesEntries = Object.entries(restAttributes).map(([key, value]) => {
|
|
84
|
+
if (typeof value === 'object') {
|
|
85
|
+
const valueString = JSON.stringify(value)
|
|
86
|
+
.replace(/"|{|}/g, '')
|
|
87
|
+
.replace(/,/g, ';');
|
|
88
|
+
return `${key}="${valueString}"`;
|
|
89
|
+
}
|
|
90
|
+
return `${key}="${value}"`;
|
|
91
|
+
});
|
|
92
|
+
if (className) {
|
|
93
|
+
attributesEntries.push(`class="${className}"`);
|
|
94
|
+
}
|
|
95
|
+
return attributesEntries.join(' ');
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Used in FEAAS and BYOC implementations to convert datasource item field values into component props
|
|
99
|
+
* @param {ComponentFields} fields field collection from Sitecore
|
|
100
|
+
* @returns JSON object that can be used as props
|
|
101
|
+
*/
|
|
102
|
+
export const getDataFromFields = (fields) => {
|
|
103
|
+
let data = {};
|
|
104
|
+
data = Object.entries(fields).reduce((acc, [key]) => {
|
|
105
|
+
acc[key] = getFieldValue(fields, key);
|
|
106
|
+
return acc;
|
|
107
|
+
}, data);
|
|
108
|
+
return data;
|
|
109
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sitecore-jss/sitecore-jss-react",
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
9
|
+
"clean": "del-cli dist types",
|
|
10
|
+
"lint": "eslint \"./src/**/*.tsx\" \"./src/**/*.ts\"",
|
|
11
|
+
"test": "mocha --require ts-node/register/transpile-only --require ./src/tests/shim.ts ./src/tests/jsdom-setup.ts ./src/tests/enzyme-setup.ts \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"coverage": "nyc npm test",
|
|
14
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-react src/index.ts --githubPages false"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Sitecore Corporation",
|
|
21
|
+
"url": "https://jss.sitecore.com"
|
|
22
|
+
},
|
|
23
|
+
"license": "Apache-2.0",
|
|
24
|
+
"homepage": "https://jss.sitecore.com",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/sitecore/jss/issues"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@sitecore-feaas/clientside": "^0.5.6",
|
|
30
|
+
"@types/chai": "^4.3.4",
|
|
31
|
+
"@types/chai-string": "^1.4.2",
|
|
32
|
+
"@types/enzyme": "^3.10.12",
|
|
33
|
+
"@types/mocha": "^10.0.1",
|
|
34
|
+
"@types/node": "18.11.10",
|
|
35
|
+
"@types/prop-types": "^15.7.5",
|
|
36
|
+
"@types/react": "^18.2.22",
|
|
37
|
+
"@types/react-dom": "^18.0.10",
|
|
38
|
+
"@types/sinon": "^10.0.13",
|
|
39
|
+
"@types/sinon-chai": "^3.2.9",
|
|
40
|
+
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
|
|
41
|
+
"chai": "^4.3.7",
|
|
42
|
+
"chai-string": "^1.5.0",
|
|
43
|
+
"cheerio": "1.0.0-rc.12",
|
|
44
|
+
"del-cli": "^5.0.0",
|
|
45
|
+
"enzyme": "^3.11.0",
|
|
46
|
+
"eslint": "^8.28.0",
|
|
47
|
+
"eslint-plugin-react": "^7.31.11",
|
|
48
|
+
"jsdom": "^20.0.3",
|
|
49
|
+
"mocha": "^10.2.0",
|
|
50
|
+
"nyc": "^15.1.0",
|
|
51
|
+
"react": "^18.2.0",
|
|
52
|
+
"react-dom": "^18.2.0",
|
|
53
|
+
"sinon": "^15.0.0",
|
|
54
|
+
"sinon-chai": "^3.7.0",
|
|
55
|
+
"ts-node": "^10.9.1",
|
|
56
|
+
"typescript": "~4.9.3"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@sitecore-feaas/clientside": "^0.5.6",
|
|
60
|
+
"react": "^18.2.0",
|
|
61
|
+
"react-dom": "^18.2.0"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@sitecore-jss/sitecore-jss": "^0.1.0-beta.2",
|
|
65
|
+
"fast-deep-equal": "^3.1.3",
|
|
66
|
+
"prop-types": "^15.8.1",
|
|
67
|
+
"style-attr": "^1.3.0"
|
|
68
|
+
},
|
|
69
|
+
"description": "",
|
|
70
|
+
"types": "types/index.d.ts",
|
|
71
|
+
"gitHead": "db3098b97fd0fe5616636da848ab9aefb664a3f3",
|
|
72
|
+
"files": [
|
|
73
|
+
"dist",
|
|
74
|
+
"types"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
import { ComponentFactory } from './components/sharedTypes';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for ComponentBuilder
|
|
6
|
+
*/
|
|
7
|
+
export type ComponentBuilderConfig<ComponentType> = {
|
|
8
|
+
/**
|
|
9
|
+
* List of components to be stored
|
|
10
|
+
*/
|
|
11
|
+
components: Map<string, ComponentType>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* React implementation of component builder class for building components based on the configuration.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ComponentBuilder {
|
|
17
|
+
protected config: ComponentBuilderConfig<ComponentType>;
|
|
18
|
+
/**
|
|
19
|
+
* List of components to be stored
|
|
20
|
+
*/
|
|
21
|
+
protected components: Map<string, ComponentType>;
|
|
22
|
+
constructor(config: ComponentBuilderConfig<ComponentType>);
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new instance of component factory
|
|
25
|
+
* @returns {ComponentFactory} Component factory implementation
|
|
26
|
+
*/
|
|
27
|
+
getComponentFactory(): ComponentFactory;
|
|
28
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ComponentFields } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
+
import { MissingComponentProps } from './MissingComponent';
|
|
5
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
6
|
+
export declare const BYOC_COMPONENT_RENDERING_NAME = "BYOCComponent";
|
|
7
|
+
/**
|
|
8
|
+
* FEaaS props for server rendering.
|
|
9
|
+
*/
|
|
10
|
+
type BYOCServerProps = {
|
|
11
|
+
/**
|
|
12
|
+
* Fetched data from server component props for server rendering, based on rendering params.
|
|
13
|
+
*/
|
|
14
|
+
fetchedData?: FEAAS.DataScopes;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Data from rendering params on Sitecore's BYOC rendering
|
|
18
|
+
*/
|
|
19
|
+
export type BYOCComponentParams = {
|
|
20
|
+
/**
|
|
21
|
+
* Name of the component to render
|
|
22
|
+
*/
|
|
23
|
+
ComponentName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* JSON props to pass into rendered component
|
|
26
|
+
*/
|
|
27
|
+
ComponentProps?: string;
|
|
28
|
+
/**
|
|
29
|
+
* A JSON object with data sources to be fetched and passed to the component
|
|
30
|
+
*/
|
|
31
|
+
ComponentDataOverride?: string;
|
|
32
|
+
/**
|
|
33
|
+
* A string with classes that can be used to apply themes, via SXA functionality
|
|
34
|
+
*/
|
|
35
|
+
styles?: string;
|
|
36
|
+
RenderingIdentifier?: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Props for BYOCComponent. Includes components list to load external components from.
|
|
40
|
+
*/
|
|
41
|
+
export type BYOCComponentClientProps = {
|
|
42
|
+
/**
|
|
43
|
+
* rendering params
|
|
44
|
+
*/
|
|
45
|
+
params?: BYOCComponentParams;
|
|
46
|
+
/**
|
|
47
|
+
* fields from datasource items to be passed as rendered child component props
|
|
48
|
+
*/
|
|
49
|
+
fields?: ComponentFields;
|
|
50
|
+
/**
|
|
51
|
+
* Error component override. To be shown when Renderer or underlying component throws
|
|
52
|
+
*/
|
|
53
|
+
errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
|
|
54
|
+
/**
|
|
55
|
+
* Override to indicate missing component situations. Would be shown when BYOC component is not registered
|
|
56
|
+
* or ComponentName is missing
|
|
57
|
+
*/
|
|
58
|
+
missingComponentComponent?: React.ComponentClass<MissingComponentProps> | React.FC<MissingComponentProps>;
|
|
59
|
+
};
|
|
60
|
+
export type BYOCComponentProps = BYOCComponentClientProps & BYOCServerProps;
|
|
61
|
+
type ErrorComponentProps = {
|
|
62
|
+
[prop: string]: unknown;
|
|
63
|
+
error?: Error;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* BYOCComponent facilitate the rendering of external components. It manages potential errors,
|
|
67
|
+
* missing components, and customization of error messages or alternative rendering components.
|
|
68
|
+
* @param {ByocComponentProps} props component props
|
|
69
|
+
* @returns dynamicly rendered component or Missing Component error frame
|
|
70
|
+
*/
|
|
71
|
+
export declare class BYOCComponent extends React.Component<BYOCComponentProps> {
|
|
72
|
+
state: Readonly<{
|
|
73
|
+
error?: Error;
|
|
74
|
+
}>;
|
|
75
|
+
constructor(props: BYOCComponentProps);
|
|
76
|
+
static getDerivedStateFromError(error: Error): {
|
|
77
|
+
error: Error;
|
|
78
|
+
};
|
|
79
|
+
componentDidCatch(error: Error): void;
|
|
80
|
+
render(): React.JSX.Element;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fetches server component props required for server rendering, based on rendering params.
|
|
84
|
+
* @param {BYOCComponentParams} params component params
|
|
85
|
+
*/
|
|
86
|
+
export declare function fetchBYOCComponentServerProps(params: BYOCComponentParams): Promise<BYOCComponentProps>;
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface DateFieldProps {
|
|
4
|
+
/** The date field data. */
|
|
5
|
+
[htmlAttributes: string]: unknown;
|
|
6
|
+
field: {
|
|
7
|
+
value?: string;
|
|
8
|
+
editable?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The HTML element that will wrap the contents of the field.
|
|
12
|
+
*/
|
|
13
|
+
tag?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Can be used to explicitly disable inline editing.
|
|
16
|
+
* If true and `field.editable` has a value, then `field.editable` will be processed and rendered as component output. If false, `field.editable` value will be ignored and not rendered.
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
editable?: boolean;
|
|
20
|
+
render?: (date: Date | null) => React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export declare const DateField: React.FC<DateFieldProps>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React, { PropsWithChildren } from 'react';
|
|
3
|
+
import { EditFrameDataSource, EditButtonTypes } from '@sitecore-jss/sitecore-jss/utils';
|
|
4
|
+
export interface EditFrameProps {
|
|
5
|
+
dataSource?: EditFrameDataSource;
|
|
6
|
+
buttons?: EditButtonTypes[];
|
|
7
|
+
title?: string;
|
|
8
|
+
tooltip?: string;
|
|
9
|
+
cssClass?: string;
|
|
10
|
+
parameters?: Record<string, string | number | boolean | undefined | null>;
|
|
11
|
+
}
|
|
12
|
+
export declare const EditFrame: React.FC<PropsWithChildren<EditFrameProps>>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
2
|
+
import { ComponentFields, LayoutServicePageState } from '@sitecore-jss/sitecore-jss/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,19 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface FileFieldValue {
|
|
4
|
+
[propName: string]: unknown;
|
|
5
|
+
src?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
displayName?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FileField {
|
|
10
|
+
value: FileFieldValue;
|
|
11
|
+
}
|
|
12
|
+
export interface FileProps {
|
|
13
|
+
[attributeName: string]: unknown;
|
|
14
|
+
/** The file field data. */
|
|
15
|
+
field: FileFieldValue | FileField;
|
|
16
|
+
/** HTML attributes that will be appended to the rendered <a /> tag. */
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
export declare const File: React.FC<FileProps>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface ImageFieldValue {
|
|
4
|
+
[attributeName: string]: unknown;
|
|
5
|
+
src?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ImageField {
|
|
8
|
+
value?: ImageFieldValue;
|
|
9
|
+
editable?: string;
|
|
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 {
|
|
29
|
+
[attributeName: string]: unknown;
|
|
30
|
+
/** Image field data (consistent with other field types) */
|
|
31
|
+
field?: ImageField | ImageFieldValue;
|
|
32
|
+
/**
|
|
33
|
+
* Can be used to explicitly disable inline editing.
|
|
34
|
+
* If true and `media.editable` has a value, then `media.editable` will be processed
|
|
35
|
+
* and rendered as component output. If false, `media.editable` value will be ignored and not rendered.
|
|
36
|
+
*/
|
|
37
|
+
editable?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Parameters that will be attached to Sitecore media URLs
|
|
40
|
+
*/
|
|
41
|
+
imageParams?: {
|
|
42
|
+
[paramName: string]: string | number;
|
|
43
|
+
};
|
|
44
|
+
srcSet?: ImageSizeParameters[];
|
|
45
|
+
/**
|
|
46
|
+
* Custom regexp that finds media URL prefix that will be replaced by `/-/jssmedia` or `/~/jssmedia`.
|
|
47
|
+
* @example
|
|
48
|
+
* /\/([-~]{1})assets\//i
|
|
49
|
+
* /-assets/website -> /-/jssmedia/website
|
|
50
|
+
* /~assets/website -> /~/jssmedia/website
|
|
51
|
+
*/
|
|
52
|
+
mediaUrlPrefix?: RegExp;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {ImageField} imageField {ImageField} provides the dynamicMedia which is used to render the image
|
|
56
|
+
* @param {ImageProps.imageParams} imageParams {ImageProp['imageParams']}} provides the image parameters that will be attached to the image URL
|
|
57
|
+
* @param {RegExp} mediaUrlPrefix {RegExp} the url prefix regex used in the mediaApi
|
|
58
|
+
* @param {ImageProps} otherProps {ImageProps} all other props included on the image component
|
|
59
|
+
* @returns Experience Editor Markup
|
|
60
|
+
*/
|
|
61
|
+
export declare const getEEMarkup: (imageField: ImageField, imageParams?: ImageProps['imageParams'], mediaUrlPrefix?: RegExp, otherProps?: ImageProps) => React.JSX.Element;
|
|
62
|
+
export declare const Image: React.FC<ImageProps>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
export interface LinkFieldValue {
|
|
5
|
+
[attributeName: string]: unknown;
|
|
6
|
+
href?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
class?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
target?: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
anchor?: string;
|
|
13
|
+
querystring?: string;
|
|
14
|
+
linktype?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface LinkField {
|
|
17
|
+
value: LinkFieldValue;
|
|
18
|
+
editableFirstPart?: string;
|
|
19
|
+
editableLastPart?: string;
|
|
20
|
+
}
|
|
21
|
+
export type LinkProps = React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement> & {
|
|
22
|
+
/** The link field data. */
|
|
23
|
+
field: LinkField | LinkFieldValue;
|
|
24
|
+
/**
|
|
25
|
+
* Can be used to explicitly disable inline editing.
|
|
26
|
+
* If true and `field.editable` has a value, then `field.editable` will be processed and rendered as component output. If false, `field.editable` value will be ignored and not rendered.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
editable?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Displays a link text ('description' in Sitecore) even when children exist
|
|
32
|
+
* NOTE: when in Sitecore Experience Editor, this setting is ignored due to technical limitations, and the description is always rendered.
|
|
33
|
+
*/
|
|
34
|
+
showLinkTextWithChildrenPresent?: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
37
|
+
export declare const LinkPropTypes: {
|
|
38
|
+
field: PropTypes.Validator<NonNullable<NonNullable<PropTypes.InferProps<{
|
|
39
|
+
href: PropTypes.Requireable<any>;
|
|
40
|
+
}> | PropTypes.InferProps<{
|
|
41
|
+
value: PropTypes.Requireable<object>;
|
|
42
|
+
editableFirstPart: PropTypes.Requireable<string>;
|
|
43
|
+
editableLastPart: PropTypes.Requireable<string>;
|
|
44
|
+
}>>>>;
|
|
45
|
+
editable: PropTypes.Requireable<boolean>;
|
|
46
|
+
showLinkTextWithChildrenPresent: PropTypes.Requireable<boolean>;
|
|
47
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { PlaceholderProps } from './PlaceholderCommon';
|
|
4
|
+
import { ComponentRendering, HtmlElementRendering } from '@sitecore-jss/sitecore-jss/layout';
|
|
5
|
+
export interface PlaceholderComponentProps extends PlaceholderProps {
|
|
6
|
+
/**
|
|
7
|
+
* Render props function that is called when the placeholder contains no content components.
|
|
8
|
+
* Can be used to wrap the Sitecore EE empty placeholder markup in something that's visually correct
|
|
9
|
+
*/
|
|
10
|
+
renderEmpty?: (components: React.ReactNode[]) => React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* Render props function that enables control over the rendering of the components in the placeholder.
|
|
13
|
+
* Useful for techniques like wrapping each child in a wrapper component.
|
|
14
|
+
*/
|
|
15
|
+
render?: (components: React.ReactNode[], data: (ComponentRendering | HtmlElementRendering)[], props: PlaceholderProps) => React.ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* Render props function that is called for each non-system component added to the placeholder.
|
|
18
|
+
* Mutually exclusive with `render`. System components added during Experience Editor are automatically rendered as-is.
|
|
19
|
+
*/
|
|
20
|
+
renderEach?: (component: React.ReactNode, index: number) => React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export declare const Placeholder: {
|
|
23
|
+
(props: PlaceholderComponentProps): JSX.Element;
|
|
24
|
+
displayName: string;
|
|
25
|
+
};
|