@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,105 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React, { ComponentType } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { ComponentFactory } from './sharedTypes';
|
|
5
|
+
import { ComponentRendering, RouteData, Field, Item, HtmlElementRendering } from '@sitecore-jss/sitecore-jss/layout';
|
|
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
|
+
export declare class PlaceholderCommon<T extends PlaceholderProps> extends React.Component<T> {
|
|
62
|
+
static propTypes: {
|
|
63
|
+
rendering: PropTypes.Validator<NonNullable<NonNullable<ComponentRendering | RouteData<Record<string, Field<import("@sitecore-jss/sitecore-jss/types/layout/models").GenericFieldValue> | Item | Item[]>>>>>;
|
|
64
|
+
fields: PropTypes.Requireable<{
|
|
65
|
+
[x: string]: NonNullable<NonNullable<Field<import("@sitecore-jss/sitecore-jss/types/layout/models").GenericFieldValue> | Item[]>>;
|
|
66
|
+
}>;
|
|
67
|
+
params: PropTypes.Requireable<{
|
|
68
|
+
[x: string]: string;
|
|
69
|
+
}>;
|
|
70
|
+
missingComponentComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
71
|
+
hiddenRenderingComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
72
|
+
errorComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
73
|
+
modifyComponentProps: PropTypes.Requireable<(...args: any[]) => any>;
|
|
74
|
+
};
|
|
75
|
+
nodeRefs: Element[];
|
|
76
|
+
state: Readonly<{
|
|
77
|
+
error?: Error;
|
|
78
|
+
}>;
|
|
79
|
+
constructor(props: T);
|
|
80
|
+
static getPlaceholderDataFromRenderingData(rendering: ComponentRendering | RouteData, name: string): (ComponentRendering | HtmlElementRendering)[];
|
|
81
|
+
componentDidMount(): void;
|
|
82
|
+
componentDidUpdate(): void;
|
|
83
|
+
componentDidCatch(error: Error): void;
|
|
84
|
+
getSXAParams(rendering: ComponentRendering): {
|
|
85
|
+
styles?: undefined;
|
|
86
|
+
} | {
|
|
87
|
+
styles: string;
|
|
88
|
+
};
|
|
89
|
+
getComponentsForRenderingData(placeholderData: (ComponentRendering | HtmlElementRendering)[]): React.ReactElement<{
|
|
90
|
+
[attr: string]: unknown;
|
|
91
|
+
}, string | React.JSXElementConstructor<any>>[];
|
|
92
|
+
getComponentForRendering(renderingDefinition: ComponentRendering): ComponentType | null;
|
|
93
|
+
addRef(nodeRef: Element): void;
|
|
94
|
+
createRawElement(elem: HtmlElementRendering, baseProps: {
|
|
95
|
+
key?: string;
|
|
96
|
+
}): React.ReactElement<{
|
|
97
|
+
[attr: string]: unknown;
|
|
98
|
+
key?: string;
|
|
99
|
+
dangerouslySetInnerHTML?: {
|
|
100
|
+
__html: string | null;
|
|
101
|
+
};
|
|
102
|
+
}, string | React.JSXElementConstructor<any>>;
|
|
103
|
+
updateKeyAttributes(): void;
|
|
104
|
+
}
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
export interface RichTextField {
|
|
5
|
+
value?: string;
|
|
6
|
+
editable?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface RichTextProps {
|
|
9
|
+
[htmlAttributes: string]: unknown;
|
|
10
|
+
/** The rich text field data. */
|
|
11
|
+
field?: RichTextField;
|
|
12
|
+
/**
|
|
13
|
+
* The HTML element that will wrap the contents of the field.
|
|
14
|
+
* @default <div />
|
|
15
|
+
*/
|
|
16
|
+
tag?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Can be used to explicitly disable inline editing.
|
|
19
|
+
* 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.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
editable?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const RichText: React.FC<RichTextProps>;
|
|
25
|
+
export declare const RichTextPropTypes: {
|
|
26
|
+
field: PropTypes.Requireable<PropTypes.InferProps<{
|
|
27
|
+
value: PropTypes.Requireable<string>;
|
|
28
|
+
editable: PropTypes.Requireable<string>;
|
|
29
|
+
}>>;
|
|
30
|
+
tag: PropTypes.Requireable<string>;
|
|
31
|
+
editable: PropTypes.Requireable<boolean>;
|
|
32
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { ComponentFactory } from './sharedTypes';
|
|
5
|
+
import { LayoutServiceContext, LayoutServiceData, RouteData } from '../index';
|
|
6
|
+
export interface SitecoreContextProps {
|
|
7
|
+
componentFactory: ComponentFactory;
|
|
8
|
+
layoutData?: LayoutServiceData;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export interface SitecoreContextState {
|
|
12
|
+
setContext: (value: SitecoreContextValue | LayoutServiceData) => void;
|
|
13
|
+
context: SitecoreContextValue;
|
|
14
|
+
}
|
|
15
|
+
export declare const SitecoreContextReactContext: React.Context<SitecoreContextState>;
|
|
16
|
+
export declare const ComponentFactoryReactContext: React.Context<ComponentFactory>;
|
|
17
|
+
export type SitecoreContextValue = LayoutServiceContext & {
|
|
18
|
+
itemId?: string;
|
|
19
|
+
route?: RouteData;
|
|
20
|
+
};
|
|
21
|
+
export declare class SitecoreContext extends React.Component<SitecoreContextProps, SitecoreContextState> {
|
|
22
|
+
static propTypes: {
|
|
23
|
+
children: PropTypes.Validator<any>;
|
|
24
|
+
componentFactory: PropTypes.Requireable<(...args: any[]) => any>;
|
|
25
|
+
layoutData: PropTypes.Requireable<PropTypes.InferProps<{
|
|
26
|
+
sitecore: PropTypes.Requireable<PropTypes.InferProps<{
|
|
27
|
+
context: PropTypes.Requireable<any>;
|
|
28
|
+
route: PropTypes.Requireable<any>;
|
|
29
|
+
}>>;
|
|
30
|
+
}>>;
|
|
31
|
+
};
|
|
32
|
+
static displayName: string;
|
|
33
|
+
constructor(props: SitecoreContextProps);
|
|
34
|
+
constructContext(layoutData?: LayoutServiceData): SitecoreContextValue;
|
|
35
|
+
componentDidUpdate(prevProps: SitecoreContextProps): void;
|
|
36
|
+
/**
|
|
37
|
+
* Update context state. Value can be @type {LayoutServiceData} which will be automatically transformed
|
|
38
|
+
* or you can provide exact @type {SitecoreContextValue}
|
|
39
|
+
* @param {SitecoreContextValue | LayoutServiceData} value New context value
|
|
40
|
+
*/
|
|
41
|
+
setContext: (value: SitecoreContextValue | LayoutServiceData) => void;
|
|
42
|
+
render(): React.JSX.Element;
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import { FunctionComponent } from 'react';
|
|
3
|
+
export interface TextField {
|
|
4
|
+
value?: string | number;
|
|
5
|
+
editable?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TextProps {
|
|
8
|
+
[htmlAttributes: string]: unknown;
|
|
9
|
+
/** The text field data. */
|
|
10
|
+
field?: TextField;
|
|
11
|
+
/**
|
|
12
|
+
* The HTML element that will wrap the contents of the field.
|
|
13
|
+
*/
|
|
14
|
+
tag?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Can be used to explicitly disable inline editing.
|
|
17
|
+
* 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.
|
|
18
|
+
* @default true
|
|
19
|
+
*/
|
|
20
|
+
editable?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If false, HTML-encoding of the field value is disabled and the value is rendered as-is.
|
|
23
|
+
*/
|
|
24
|
+
encode?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const Text: FunctionComponent<TextProps>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import { ComponentType } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} componentName component to be imported from the component factory
|
|
5
|
+
* @param {string?} exportName component to be imported in case you export multiple components from the same file
|
|
6
|
+
*/
|
|
7
|
+
export type ComponentFactory = (componentName: string, exportName?: string) => ComponentType | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ComponentFactory } from '../components/sharedTypes';
|
|
4
|
+
export interface ComponentFactoryProps {
|
|
5
|
+
componentFactory?: ComponentFactory;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @param {React.ComponentClass<T> | React.FC<T>} Component
|
|
9
|
+
*/
|
|
10
|
+
export declare function withComponentFactory<T extends ComponentFactoryProps>(Component: React.ComponentClass<T> | React.FC<T>): {
|
|
11
|
+
(props: T): JSX.Element;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ComponentRendering } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
+
export declare const DefaultEditingError: () => JSX.Element;
|
|
5
|
+
export interface WithDatasourceCheckProps {
|
|
6
|
+
rendering: ComponentRendering;
|
|
7
|
+
}
|
|
8
|
+
export interface WithDatasourceCheckOptions {
|
|
9
|
+
/**
|
|
10
|
+
* A component that is rendered when a datasource is missing during editing.
|
|
11
|
+
* If unspecified, a default component with message is displayed.
|
|
12
|
+
*/
|
|
13
|
+
editingErrorComponent?: React.ComponentClass<unknown> | React.FC<unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether a Sitecore datasource is present and renders appropriately depending on page mode (normal vs editing).
|
|
17
|
+
* @param {WithDatasourceCheckOptions} [options]
|
|
18
|
+
* @returns
|
|
19
|
+
* The wrapped component, if a datasource is present.
|
|
20
|
+
* A null component (in normal mode) or an error component (in editing mode), if a datasource is not present.
|
|
21
|
+
*/
|
|
22
|
+
export declare function withDatasourceCheck(options?: WithDatasourceCheckOptions): <ComponentProps extends WithDatasourceCheckProps>(Component: React.ComponentType<ComponentProps>) => (props: ComponentProps) => React.JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentRendering, RouteData } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
|
+
import { PlaceholderProps } from '../components/PlaceholderCommon';
|
|
4
|
+
export interface WithPlaceholderOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Function to map incoming placeholder props into rendering data to use for the placeholder data.
|
|
7
|
+
* Normally in a JSS component, props.rendering is passed the component data, and that is the default.
|
|
8
|
+
* However, if your component data is in a different prop, like say 'route' in a sample app,
|
|
9
|
+
* this lets you map that.
|
|
10
|
+
*/
|
|
11
|
+
resolvePlaceholderDataFromProps?: (props: unknown) => ComponentRendering | RouteData;
|
|
12
|
+
/**
|
|
13
|
+
* Function to alter the placeholder props from within the HOC. Enables the props to be
|
|
14
|
+
* transformed before being used by the placeholder/HOC, for example to customize the
|
|
15
|
+
* error or missing component display
|
|
16
|
+
*/
|
|
17
|
+
propsTransformer?: (props: PlaceholderProps) => PlaceholderProps;
|
|
18
|
+
}
|
|
19
|
+
export interface PlaceholderToPropMapping {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the placeholder this component will expose
|
|
22
|
+
*/
|
|
23
|
+
placeholder: string;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the prop on your wrapped component that you would like the placeholder data injected on
|
|
26
|
+
*/
|
|
27
|
+
prop: string;
|
|
28
|
+
}
|
|
29
|
+
export type WithPlaceholderSpec = (string | PlaceholderToPropMapping) | (string | PlaceholderToPropMapping)[];
|
|
30
|
+
/**
|
|
31
|
+
* @param {WithPlaceholderSpec} placeholders
|
|
32
|
+
* @param {WithPlaceholderOptions} [options]
|
|
33
|
+
*/
|
|
34
|
+
export declare function withPlaceholder(placeholders: WithPlaceholderSpec, options?: WithPlaceholderOptions): (WrappedComponent: React.ComponentClass<PlaceholderProps> | React.FunctionComponent<PlaceholderProps>) => {
|
|
35
|
+
(props: PlaceholderProps): JSX.Element;
|
|
36
|
+
displayName: string;
|
|
37
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React, { ReactNode } from 'react';
|
|
3
|
+
import { SitecoreContextValue } from '../components/SitecoreContext';
|
|
4
|
+
export interface WithSitecoreContextOptions {
|
|
5
|
+
updatable?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface WithSitecoreContextProps {
|
|
8
|
+
sitecoreContext: SitecoreContextValue;
|
|
9
|
+
updateSitecoreContext?: ((value: SitecoreContextValue) => void) | false;
|
|
10
|
+
}
|
|
11
|
+
export interface ComponentConsumerProps extends WithSitecoreContextProps {
|
|
12
|
+
children?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export type WithSitecoreContextHocProps<ComponentProps> = Pick<ComponentProps, Exclude<keyof ComponentProps, keyof WithSitecoreContextProps>>;
|
|
15
|
+
/**
|
|
16
|
+
* @param {WithSitecoreContextOptions} [options]
|
|
17
|
+
*/
|
|
18
|
+
export declare function withSitecoreContext(options?: WithSitecoreContextOptions): <ComponentProps extends ComponentConsumerProps>(Component: React.ComponentType<ComponentProps>) => (props: WithSitecoreContextHocProps<ComponentProps>) => React.JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* This hook grants acсess to the current Sitecore page context
|
|
21
|
+
* by default JSS includes the following properties in this context:
|
|
22
|
+
* - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Experience Editor.
|
|
23
|
+
* - pageState - Like pageEditing, but a string: normal, preview or edit.
|
|
24
|
+
* - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
|
|
25
|
+
*
|
|
26
|
+
* @see https://jss.sitecore.com/docs/techniques/extending-layout-service/layoutservice-extending-context
|
|
27
|
+
*
|
|
28
|
+
* @param {WithSitecoreContextOptions} [options] hook options
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const EditMode = () => {
|
|
32
|
+
* const { sitecoreContext } = useSitecoreContext();
|
|
33
|
+
* return <span>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const EditMode = () => {
|
|
38
|
+
* const { sitecoreContext, updateSitecoreContext } = useSitecoreContext({ updatable: true });
|
|
39
|
+
* const onClick = () => updateSitecoreContext({ pageEditing: true });
|
|
40
|
+
* return <span onClick={onClick}>Edit Mode is {sitecoreContext.pageEditing ? 'active' : 'inactive'}</span>
|
|
41
|
+
* }
|
|
42
|
+
* @returns {Object} { sitecoreContext, updateSitecoreContext }
|
|
43
|
+
*/
|
|
44
|
+
export declare function useSitecoreContext(options?: WithSitecoreContextOptions): {
|
|
45
|
+
sitecoreContext: SitecoreContextValue;
|
|
46
|
+
updateSitecoreContext: (value: import("@sitecore-jss/sitecore-jss/layout").LayoutServiceData | SitecoreContextValue) => void;
|
|
47
|
+
};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { constants, NativeDataFetcher, NativeDataFetcherResponse, NativeDataFetcherConfig, enableDebug, } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
export { isEditorActive, resetEditorChromes, DefaultEditFrameButton, DefaultEditFrameButtons, EditFrameDataSource, FieldEditButton, WebEditButton, EditButtonTypes, } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
|
+
export { getContentStylesheetLink, getComponentLibraryStylesheetLinks, LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
+
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
5
|
+
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
6
|
+
export { ComponentFactory } from './components/sharedTypes';
|
|
7
|
+
export { Placeholder, PlaceholderComponentProps } from './components/Placeholder';
|
|
8
|
+
export { Image, ImageProps, ImageField, getEEMarkup, ImageFieldValue, ImageSizeParameters, } from './components/Image';
|
|
9
|
+
export { RichText, RichTextProps, RichTextPropTypes, RichTextField } from './components/RichText';
|
|
10
|
+
export { Text, TextField } from './components/Text';
|
|
11
|
+
export { DateField, DateFieldProps } from './components/Date';
|
|
12
|
+
export { FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, } from './components/FEaaSComponent';
|
|
13
|
+
export { FEaaSWrapper } from './components/FEaaSWrapper';
|
|
14
|
+
export { BYOCComponent, BYOCComponentParams, BYOCComponentProps, fetchBYOCComponentServerProps, } from './components/BYOCComponent';
|
|
15
|
+
export { BYOCWrapper } from './components/BYOCWrapper';
|
|
16
|
+
export { Link, LinkField, LinkFieldValue, LinkProps, LinkPropTypes } from './components/Link';
|
|
17
|
+
export { File, FileField } from './components/File';
|
|
18
|
+
export { SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, } from './components/SitecoreContext';
|
|
19
|
+
export { withSitecoreContext, useSitecoreContext, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, } from './enhancers/withSitecoreContext';
|
|
20
|
+
export { withEditorChromes } from './enhancers/withEditorChromes';
|
|
21
|
+
export { withPlaceholder } from './enhancers/withPlaceholder';
|
|
22
|
+
export { withDatasourceCheck } from './enhancers/withDatasourceCheck';
|
|
23
|
+
export { EditFrameProps, EditFrame } from './components/EditFrame';
|
|
24
|
+
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ComponentFields } from '@sitecore-jss/sitecore-jss/layout';
|
|
2
|
+
export declare const convertKebabCasetoCamelCase: (str: string) => string;
|
|
3
|
+
/**
|
|
4
|
+
* https://facebook.github.io/react/docs/dom-elements.html
|
|
5
|
+
* We are only concerned with style at the moment, which needs to be converted from string to object to satisfy React.
|
|
6
|
+
* 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.
|
|
7
|
+
* 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.
|
|
8
|
+
* @param {string} [style] style
|
|
9
|
+
* @returns {Array} converted attributes
|
|
10
|
+
*/
|
|
11
|
+
export declare const convertStyleAttribute: (style?: string) => {};
|
|
12
|
+
export declare const convertAttributesToReactProps: (attributes: {
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
style?: string;
|
|
15
|
+
class?: string;
|
|
16
|
+
}) => [] | {
|
|
17
|
+
[attr: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
21
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
24
|
+
export declare const addClassName: (otherAttrs: {
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Converts the given tag attributes object to a string
|
|
29
|
+
* @param {Object.<string, unknown>} attributes the attributes object
|
|
30
|
+
* @returns {string} string representation of the attributes
|
|
31
|
+
*/
|
|
32
|
+
export declare const getAttributesString: (attributes: {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}) => string;
|
|
35
|
+
/**
|
|
36
|
+
* Used in FEAAS and BYOC implementations to convert datasource item field values into component props
|
|
37
|
+
* @param {ComponentFields} fields field collection from Sitecore
|
|
38
|
+
* @returns JSON object that can be used as props
|
|
39
|
+
*/
|
|
40
|
+
export declare const getDataFromFields: (fields: ComponentFields) => {
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
};
|