@sitecore-content-sdk/react 1.0.0-canary.8 → 1.0.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 (32) hide show
  1. package/LICENSE.txt +202 -202
  2. package/README.md +11 -11
  3. package/dist/cjs/components/DesignLibrary.js +65 -7
  4. package/dist/cjs/components/EditingScripts.js +7 -10
  5. package/dist/cjs/components/ErrorBoundary.js +1 -5
  6. package/dist/cjs/components/Form.js +1 -1
  7. package/dist/cjs/components/Placeholder.js +2 -3
  8. package/dist/cjs/components/PlaceholderCommon.js +4 -5
  9. package/dist/cjs/components/SitecoreProvider.js +9 -21
  10. package/dist/cjs/enhancers/withDatasourceCheck.js +3 -4
  11. package/dist/cjs/enhancers/withPlaceholder.js +2 -2
  12. package/dist/cjs/enhancers/withSitecore.js +10 -14
  13. package/dist/cjs/index.js +2 -1
  14. package/dist/esm/components/DesignLibrary.js +59 -3
  15. package/dist/esm/components/EditingScripts.js +7 -10
  16. package/dist/esm/components/ErrorBoundary.js +1 -5
  17. package/dist/esm/components/Form.js +1 -1
  18. package/dist/esm/components/Placeholder.js +2 -3
  19. package/dist/esm/components/PlaceholderCommon.js +4 -5
  20. package/dist/esm/components/SitecoreProvider.js +9 -21
  21. package/dist/esm/enhancers/withDatasourceCheck.js +3 -4
  22. package/dist/esm/enhancers/withPlaceholder.js +2 -2
  23. package/dist/esm/enhancers/withSitecore.js +10 -14
  24. package/dist/esm/index.js +1 -1
  25. package/package.json +3 -3
  26. package/types/components/DesignLibrary.d.ts +7 -2
  27. package/types/components/EditingScripts.d.ts +1 -1
  28. package/types/components/ErrorBoundary.d.ts +2 -2
  29. package/types/components/PlaceholderCommon.d.ts +3 -3
  30. package/types/components/SitecoreProvider.d.ts +11 -20
  31. package/types/enhancers/withSitecore.d.ts +13 -16
  32. package/types/index.d.ts +2 -2
@@ -1,7 +1,7 @@
1
1
  import React, { ComponentType } from 'react';
2
2
  import { ComponentMap } from './sharedTypes';
3
3
  import { ComponentRendering, RouteData, Field, Item } from '@sitecore-content-sdk/core/layout';
4
- import { SitecoreProviderPageContext } from './SitecoreProvider';
4
+ import { Page } from '@sitecore-content-sdk/core/client';
5
5
  type ErrorComponentProps = {
6
6
  [prop: string]: unknown;
7
7
  };
@@ -57,10 +57,10 @@ export interface PlaceholderProps {
57
57
  */
58
58
  errorComponent?: React.ComponentClass<ErrorComponentProps> | React.FC<ErrorComponentProps>;
59
59
  /**
60
- * Page context data.
60
+ * Page data.
61
61
  * This data is passed by the SitecoreProvider.
62
62
  */
63
- pageContext: SitecoreProviderPageContext;
63
+ page: Page;
64
64
  /**
65
65
  * The message that gets displayed while component is loading
66
66
  */
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
+ import { Page } from '@sitecore-content-sdk/core/client';
2
3
  import { SitecoreConfig } from '@sitecore-content-sdk/core/config';
3
- import { LayoutServiceContext, LayoutServiceData, RouteData } from '../index';
4
4
  import { ComponentMap } from './sharedTypes';
5
5
  export interface SitecoreProviderProps {
6
6
  /**
@@ -12,22 +12,22 @@ export interface SitecoreProviderProps {
12
12
  */
13
13
  componentMap: ComponentMap;
14
14
  /**
15
- * The Sitecore Layout data.
15
+ * The page data.
16
16
  */
17
- layoutData?: LayoutServiceData;
17
+ page: Page;
18
18
  children: React.ReactNode;
19
19
  }
20
20
  export interface SitecoreProviderState {
21
21
  /**
22
- * Method to set the page context.
23
- * @param {SitecoreProviderPageContext | LayoutServiceData} value New page context value.
22
+ * Method to set the page.
23
+ * @param {Page} value New page value.
24
24
  * @returns {void}
25
25
  */
26
- setContext: (value: SitecoreProviderPageContext | LayoutServiceData) => void;
26
+ setPage: (value: Page) => void;
27
27
  /**
28
- * The current page context.
28
+ * The current page.
29
29
  */
30
- pageContext: SitecoreProviderPageContext;
30
+ page: Page;
31
31
  /**
32
32
  * The API configuration defined in the `SitecoreConfig`.
33
33
  */
@@ -35,23 +35,14 @@ export interface SitecoreProviderState {
35
35
  }
36
36
  export declare const SitecoreProviderReactContext: React.Context<SitecoreProviderState>;
37
37
  export declare const ComponentMapReactContext: React.Context<ComponentMap>;
38
- /**
39
- * The page context provided by the SitecoreProvider.
40
- */
41
- export type SitecoreProviderPageContext = LayoutServiceContext & {
42
- itemId?: string;
43
- route?: RouteData;
44
- };
45
38
  export declare class SitecoreProvider extends React.Component<SitecoreProviderProps, SitecoreProviderState> {
46
39
  static displayName: string;
47
40
  constructor(props: SitecoreProviderProps);
48
- constructContext(layoutData?: LayoutServiceData): SitecoreProviderPageContext;
49
41
  componentDidUpdate(prevProps: SitecoreProviderProps): void;
50
42
  /**
51
- * Update context state. Value can be @type {LayoutServiceData} which will be automatically transformed
52
- * or you can provide exact @type {SitecoreProviderPageContext}
53
- * @param {SitecoreProviderPageContext | LayoutServiceData} value New context value
43
+ * Update page state.
44
+ * @param {Page} value New page value
54
45
  */
55
- setContext: (value: SitecoreProviderPageContext | LayoutServiceData) => void;
46
+ setPage: (value: Page) => void;
56
47
  render(): React.JSX.Element;
57
48
  }
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { EnhancedOmit } from '@sitecore-content-sdk/core/utils';
3
- import { SitecoreProviderState, SitecoreProviderPageContext } from '../components/SitecoreProvider';
3
+ import { SitecoreProviderState } from '../components/SitecoreProvider';
4
+ import { Page } from '@sitecore-content-sdk/core/client';
4
5
  export interface WithSitecoreOptions {
5
6
  /**
6
7
  * If set to true, the `updateContext` method will be injected into the component props.
@@ -11,17 +12,17 @@ export interface WithSitecoreProps {
11
12
  /**
12
13
  * The current page context.
13
14
  */
14
- pageContext: SitecoreProviderPageContext;
15
+ page: Page;
15
16
  /**
16
17
  * The API configuration defined in the `SitecoreConfig`.
17
18
  */
18
19
  api?: SitecoreProviderState['api'];
19
20
  /**
20
- * Method to update the page context. This is only available if `updatable` is set to true.
21
- * @param {SitecoreProviderPageContext} value New page context value.
21
+ * Method to update the page. This is only available if `updatable` is set to true.
22
+ * @param {Page} value New page value.
22
23
  * @returns {void}
23
24
  */
24
- updateContext?: ((value: SitecoreProviderPageContext) => void) | false;
25
+ updatePage?: ((value: Page) => void) | false;
25
26
  }
26
27
  export type WithSitecoreHocProps<ComponentProps> = EnhancedOmit<ComponentProps, keyof WithSitecoreProps>;
27
28
  /**
@@ -29,23 +30,19 @@ export type WithSitecoreHocProps<ComponentProps> = EnhancedOmit<ComponentProps,
29
30
  */
30
31
  export declare function withSitecore(options?: WithSitecoreOptions): <ComponentProps extends WithSitecoreProps>(Component: React.ComponentType<ComponentProps>) => (props: WithSitecoreHocProps<ComponentProps>) => React.JSX.Element;
31
32
  /**
32
- * This hook grants acсess to the current Sitecore page context and api.
33
- * by default Content SDK includes the following properties in this context:
34
- * - pageEditing - Provided by Layout Service, a boolean indicating whether the route is being accessed via the Sitecore Editor.
35
- * - pageState - Like pageEditing, but a string: normal, preview or edit.
36
- * - site - Provided by Layout Service, an object containing the name of the current Sitecore site context.
33
+ * This hook grants acсess to the current Sitecore page and api.
37
34
  * @param {WithSitecoreOptions} [options] hook options
38
35
  * @example
39
36
  * const EditMode = () => {
40
- * const { pageContext } = useSitecore();
41
- * return <span>Edit Mode is {pageContext.pageEditing ? 'active' : 'inactive'}</span>
37
+ * const { page } = useSitecore();
38
+ * return <span>Edit Mode is {page.mode.isEditing ? 'active' : 'inactive'}</span>
42
39
  * }
43
40
  * @example
44
41
  * const EditMode = () => {
45
- * const { pageContext, updateContext } = useSitecore({ updatable: true });
46
- * const onClick = () => updateContext({ pageEditing: true });
47
- * return <span onClick={onClick}>Edit Mode is {pageContext.pageEditing ? 'active' : 'inactive'}</span>
42
+ * const { page, updatePage } = useSitecore({ updatable: true });
43
+ * const onClick = () => updatePage({ itemId: '123' });
44
+ * return <span onClick={onClick}>Item id is {page.itemId}</span>
48
45
  * }
49
- * @returns {object} { api, pageContext, updateContext }
46
+ * @returns {object} { api, page, updatePage }
50
47
  */
51
48
  export declare function useSitecore(options?: WithSitecoreOptions): WithSitecoreProps;
package/types/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { EnhancedOmit } from '@sitecore-content-sdk/core/utils';
3
3
  export { isEditorActive, resetEditorChromes } from '@sitecore-content-sdk/core/editing';
4
4
  export { getContentStylesheetLink, getDesignLibraryStylesheetLinks, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, LayoutService, RouteData, Field, Item, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, EditMode, } from '@sitecore-content-sdk/core/layout';
5
5
  export { DictionaryPhrases, DictionaryService } from '@sitecore-content-sdk/core/i18n';
6
- export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClientFactoryConfig, GraphQLRequestClient, } from '@sitecore-content-sdk/core/client';
6
+ export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClientFactoryConfig, GraphQLRequestClient, PageMode, ErrorPage, Page, } from '@sitecore-content-sdk/core/client';
7
7
  export { mediaApi } from '@sitecore-content-sdk/core/media';
8
8
  export { Form } from './components/Form';
9
9
  export { ReactContentSdkComponent, ComponentMap, ReactModule } from './components/sharedTypes';
@@ -19,7 +19,7 @@ export { BYOCComponent, BYOCComponentParams, BYOCComponentProps, fetchBYOCCompon
19
19
  export { BYOCWrapper } from './components/BYOCWrapper';
20
20
  export { Link, LinkField, LinkFieldValue, LinkProps } from './components/Link';
21
21
  export { File, FileField } from './components/File';
22
- export { SitecoreProvider, SitecoreProviderState, SitecoreProviderPageContext, SitecoreProviderReactContext, } from './components/SitecoreProvider';
22
+ export { SitecoreProvider, SitecoreProviderState, SitecoreProviderReactContext, } from './components/SitecoreProvider';
23
23
  export { withSitecore, useSitecore, WithSitecoreOptions, WithSitecoreProps, WithSitecoreHocProps, } from './enhancers/withSitecore';
24
24
  export { withEditorChromes } from './enhancers/withEditorChromes';
25
25
  export { withPlaceholder } from './enhancers/withPlaceholder';