@dotcms/react 0.0.1-alpha.3 → 0.0.1-alpha.30

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dotcms/react",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.1-alpha.30",
4
4
  "peerDependencies": {
5
- "react": "^18",
6
- "react-dom": "^18",
7
- "@dotcms/client": "latest"
5
+ "react": ">=18",
6
+ "react-dom": ">=18",
7
+ "@dotcms/client": "0.0.1-alpha.30"
8
8
  },
9
9
  "description": "Official React Components library to render a dotCMS page.",
10
10
  "repository": {
@@ -28,5 +28,6 @@
28
28
  "homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/react/README.md",
29
29
  "module": "./index.esm.js",
30
30
  "type": "module",
31
- "main": "./index.esm.js"
32
- }
31
+ "main": "./index.esm.js",
32
+ "types": "./index.esm.d.ts"
33
+ }
package/src/index.d.ts CHANGED
@@ -2,4 +2,3 @@ export * from './lib/components/DotcmsLayout/DotcmsLayout';
2
2
  export * from './lib/components/PageProvider/PageProvider';
3
3
  export * from './lib/components/Row/Row';
4
4
  export * from './lib/hooks/useDotcmsPageContext';
5
- export * from './lib/hooks/usePageEditor';
@@ -1,5 +1,5 @@
1
- import { PageProviderContext } from '../PageProvider/PageProvider';
1
+ import { DotCMSPageContext } from '../../models';
2
2
  export interface ColumnProps {
3
- readonly column: PageProviderContext['layout']['body']['rows'][0]['columns'][0];
3
+ readonly column: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0];
4
4
  }
5
5
  export declare function Column({ column }: ColumnProps): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
- import { PageProviderContext } from '../PageProvider/PageProvider';
1
+ import { DotCMSPageContext } from '../../models';
2
2
  export interface ContainerProps {
3
- readonly containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0];
3
+ readonly containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0];
4
4
  }
5
5
  export declare function Container({ containerRef }: ContainerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,25 +1,27 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../PageProvider/PageProvider';
2
+ import { DotCMSPageEditorConfig } from '@dotcms/client';
3
+ import { DotCMSPageContext } from '../../models';
3
4
  /**
4
5
  * `DotcmsPageProps` is a type that defines the properties for the `DotcmsLayout` component.
5
6
  * It includes a readonly `entity` property that represents the context for a DotCMS page.
6
7
  *
7
8
  * @typedef {Object} DotcmsPageProps
8
9
  *
9
- * @property {PageProviderContext} entity - The context for a DotCMS page.
10
+ * @property {DotCMSPageContext} entity - The context for a DotCMS page.
10
11
  * @readonly
11
12
  */
12
13
  export type DotcmsPageProps = {
13
14
  /**
14
- * `entity` is a readonly property of the `DotcmsPageProps` type.
15
+ * `pageContext` is a readonly property of the `DotcmsPageProps` type.
15
16
  * It represents the context for a DotCMS page and is of type `PageProviderContext`.
16
17
  *
17
- * @property {PageProviderContext} entity
18
+ * @property {PageProviderContext} pageContext
18
19
  * @memberof DotcmsPageProps
19
- * @type {PageProviderContext}
20
+ * @type {DotCMSPageContext}
20
21
  * @readonly
21
22
  */
22
- readonly entity: PageProviderContext;
23
+ readonly pageContext: DotCMSPageContext;
24
+ readonly config: DotCMSPageEditorConfig;
23
25
  };
24
26
  /**
25
27
  * `DotcmsLayout` is a functional component that renders a layout for a DotCMS page.
@@ -29,4 +31,4 @@ export type DotcmsPageProps = {
29
31
  * @param {DotcmsPageProps} props - The properties for the DotCMS page.
30
32
  * @returns {JSX.Element} - A JSX element that represents the layout for a DotCMS page.
31
33
  */
32
- export declare function DotcmsLayout(props: DotcmsPageProps): JSX.Element;
34
+ export declare function DotcmsLayout(dotPageProps: DotcmsPageProps): JSX.Element;
@@ -1,76 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  export interface PageProviderProps {
3
- readonly entity: any;
3
+ readonly pageContext: any;
4
4
  readonly children: ReactNode;
5
5
  }
6
- export interface ContainerData {
7
- [key: string]: {
8
- container: {
9
- path: string;
10
- identifier: string;
11
- maxContentlets: number;
12
- };
13
- containerStructures: {
14
- contentTypeVar: string;
15
- }[];
16
- contentlets: {
17
- [key: string]: {
18
- contentType: string;
19
- identifier: string;
20
- title: string;
21
- inode: string;
22
- widgetTitle?: string;
23
- }[];
24
- };
25
- };
26
- }
27
- export interface PageProviderContext {
28
- /**
29
- * `components` is a property of the `PageProviderProps` type.
30
- * It is an object that maps content type variables to their corresponding React components.
31
- *
32
- * It will be use to render the contentlets in the page.
33
- *
34
- * @property {Object} components
35
- * @memberof PageProviderProps
36
- * @type {Object.<string, React.ElementType>}
37
- */
38
- components: {
39
- [contentTypeVariable: string]: React.ElementType;
40
- };
41
- containers: ContainerData;
42
- layout: {
43
- header: boolean;
44
- footer: boolean;
45
- body: {
46
- rows: {
47
- styleClass: string;
48
- columns: {
49
- styleClass: string;
50
- width: number;
51
- leftOffset: number;
52
- containers: {
53
- identifier: string;
54
- uuid: string;
55
- }[];
56
- }[];
57
- }[];
58
- };
59
- };
60
- page: {
61
- title: string;
62
- identifier: string;
63
- };
64
- viewAs: {
65
- language: {
66
- id: string;
67
- };
68
- persona: {
69
- keyTag: string;
70
- };
71
- };
72
- isInsideEditor: boolean;
73
- }
74
6
  /**
75
7
  * `PageProvider` is a functional component that provides a context for a DotCMS page.
76
8
  * It takes a `PageProviderProps` object as a parameter and returns a JSX element.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../PageProvider/PageProvider';
2
+ import { DotCMSPageContext } from '../../models';
3
3
  /**
4
4
  * Props for the row component
5
5
  *
@@ -10,10 +10,10 @@ export interface RowProps {
10
10
  /**
11
11
  * Row data
12
12
  *
13
- * @type {PageProviderContext['layout']['body']['rows'][0]}
13
+ * @type {DotCMSPageContext['layout']['body']['rows'][0]}
14
14
  * @memberof RowProps
15
15
  */
16
- row: PageProviderContext['layout']['body']['rows'][0];
16
+ row: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0];
17
17
  }
18
18
  /**
19
19
  * Renders a row
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../components/PageProvider/PageProvider';
3
- export declare const PageContext: import("react").Context<PageProviderContext | null>;
2
+ import { DotCMSPageContext } from '../models';
3
+ export declare const PageContext: import("react").Context<DotCMSPageContext | null>;
@@ -0,0 +1,3 @@
1
+ import { DotcmsPageProps } from '../components/DotcmsLayout/DotcmsLayout';
2
+ import { DotCMSPageContext } from '../models';
3
+ export declare const useDotcmsEditor: ({ pageContext, config }: DotcmsPageProps) => DotCMSPageContext;
@@ -1,9 +1,9 @@
1
- import { PageProviderContext } from '../components/PageProvider/PageProvider';
1
+ import { DotCMSPageContext } from '../models';
2
2
  /**
3
3
  * `useDotcmsPageContext` is a custom React hook that provides access to the `PageProviderContext`.
4
4
  * It takes no parameters and returns the context value or `null` if it's not available.
5
5
  *
6
6
  * @category Hooks
7
- * @returns {PageProviderContext | null} - The context value or `null` if it's not available.
7
+ * @returns {DotCMSPageContext | null} - The context value or `null` if it's not available.
8
8
  */
9
- export declare function useDotcmsPageContext(): PageProviderContext | null;
9
+ export declare function useDotcmsPageContext(): DotCMSPageContext | null;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../components/PageProvider/PageProvider';
3
- export declare const mockPageContext: PageProviderContext;
2
+ import { DotCMSPageContext } from '../models';
3
+ export declare const mockPageContext: DotCMSPageContext;
4
4
  export declare const MockContextRender: ({ children, mockContext }: {
5
5
  children: JSX.Element;
6
- mockContext: Partial<PageProviderContext>;
6
+ mockContext: Partial<DotCMSPageContext>;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,88 @@
1
+ /// <reference types="react" />
2
+ export interface ContainerData {
3
+ [key: string]: {
4
+ container: {
5
+ path: string;
6
+ identifier: string;
7
+ maxContentlets: number;
8
+ parentPermissionable: Record<string, string>;
9
+ };
10
+ containerStructures: {
11
+ contentTypeVar: string;
12
+ }[];
13
+ contentlets: {
14
+ [key: string]: {
15
+ contentType: string;
16
+ identifier: string;
17
+ title: string;
18
+ inode: string;
19
+ onNumberOfPages: number;
20
+ widgetTitle?: string;
21
+ baseType: string;
22
+ }[];
23
+ };
24
+ };
25
+ }
26
+ export interface DotCMSPageContext {
27
+ /**
28
+ * `components` is a property of the `PageProviderProps` type.
29
+ * It is an object that maps content type variables to their corresponding React components.
30
+ *
31
+ * It will be use to render the contentlets in the page.
32
+ *
33
+ * @property {Object} components
34
+ * @memberof PageProviderProps
35
+ * @type {Object.<string, React.ElementType>}
36
+ */
37
+ components: {
38
+ [contentTypeVariable: string]: React.ElementType;
39
+ };
40
+ pageAsset: {
41
+ containers: ContainerData;
42
+ layout: {
43
+ header: boolean;
44
+ footer: boolean;
45
+ body: {
46
+ rows: {
47
+ styleClass: string;
48
+ columns: {
49
+ styleClass: string;
50
+ width: number;
51
+ leftOffset: number;
52
+ containers: {
53
+ identifier: string;
54
+ uuid: string;
55
+ }[];
56
+ }[];
57
+ }[];
58
+ };
59
+ };
60
+ page: {
61
+ title: string;
62
+ identifier: string;
63
+ };
64
+ viewAs: {
65
+ language: {
66
+ id: string;
67
+ };
68
+ persona: {
69
+ keyTag: string;
70
+ };
71
+ variantId: string;
72
+ };
73
+ vanityUrl?: {
74
+ pattern: string;
75
+ vanityUrlId: string;
76
+ url: string;
77
+ siteId: string;
78
+ languageId: number;
79
+ forwardTo: string;
80
+ response: number;
81
+ order: number;
82
+ temporaryRedirect: boolean;
83
+ permanentRedirect: boolean;
84
+ forward: boolean;
85
+ };
86
+ };
87
+ isInsideEditor: boolean;
88
+ }
@@ -1,55 +1,23 @@
1
- import { ContainerData, PageProviderContext } from '../components/PageProvider/PageProvider';
2
- export declare function getPageElementBound(rowsNodes: HTMLDivElement[] | null): {
3
- x: number;
4
- y: number;
5
- width: number;
6
- height: number;
7
- columns: {
8
- x: number;
9
- y: number;
10
- width: number;
11
- height: number;
12
- containers: {
13
- x: number;
14
- y: number;
15
- width: number;
16
- height: number;
17
- payload: string | undefined;
18
- contentlets: {
19
- x: number;
20
- y: number;
21
- width: number;
22
- height: number;
23
- payload: string | undefined;
24
- }[];
25
- }[];
26
- }[];
27
- }[];
28
- export declare const getPageContainers: (containers: ContainerData) => {
29
- identifier: string;
30
- uuid: string;
31
- contentletsId: string[];
32
- }[];
33
- export declare const getContainersData: (containers: ContainerData, containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
1
+ import { ContainerData, DotCMSPageContext } from '../models';
2
+ export declare const getContainersData: (containers: ContainerData, containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
34
3
  acceptTypes: string;
35
4
  contentlets: {
36
5
  contentType: string;
37
6
  identifier: string;
38
7
  title: string;
39
8
  inode: string;
9
+ onNumberOfPages: number;
40
10
  widgetTitle?: string | undefined;
11
+ baseType: string;
41
12
  }[];
42
- pageContainers: {
43
- identifier: string;
44
- uuid: string;
45
- contentletsId: string[];
46
- }[];
13
+ variantId: string;
47
14
  path: string;
48
15
  identifier: string;
49
16
  maxContentlets: number;
17
+ parentPermissionable: Record<string, string>;
50
18
  };
51
19
  export declare const combineClasses: (classes: string[]) => string;
52
- export declare const getPositionStyleClasses: (width: number, leftOffset: number) => {
53
- widthClass: string;
20
+ export declare const getPositionStyleClasses: (start: number, end: number) => {
54
21
  startClass: string;
22
+ endClass: string;
55
23
  };
@@ -1,50 +0,0 @@
1
- /**
2
- * `PageEditorOptions` is an interface that defines the options for the `usePageEditor` hook.
3
- * It includes an optional `reloadFunction` that is called when the editor needs to reload the page to get changes,
4
- * and an optional `pathname` that represents the path of the page that the editor is editing.
5
- *
6
- * @interface PageEditorOptions
7
- *
8
- * @property {Function} reloadFunction - An optional function that is called when the editor needs to reload the page to get changes.
9
- * @property {string} pathname - An optional string that represents the path of the page that the editor is editing.
10
- */
11
- interface PageEditorOptions {
12
- /**
13
- * `reloadFunction` is an optional function that can be provided to the `PageEditorOptions` object.
14
- * It is called when the dotcms editor needs to reload the page to get changes.
15
- *
16
- * @property {Function} reloadFunction
17
- * @default window.location.reload
18
- * @memberof PageEditorOptions
19
- * @type {() => void}
20
- * @optional
21
- */
22
- reloadFunction?: () => void;
23
- /**
24
- * `pathname` is an optional string that can be provided to the `PageEditorOptions` object.
25
- * It represents the path of the page that the editor is editing.
26
- * When this path changes, the editor will update its own state and reload the page to get the changes.
27
- * @property {string} pathname
28
- * @memberof PageEditorOptions
29
- * @type {string}
30
- * @optional
31
- */
32
- pathname?: string;
33
- }
34
- /**
35
- * `usePageEditor` is a custom React hook that sets up the page editor for a DotCMS page.
36
- * It takes a `PageEditorOptions` object as a parameter and returns a reference to the rows of the page.
37
- *
38
- * This hook is the main brigde between your webapp and the dotcms page editor.
39
- *
40
- *
41
- * @category Hooks
42
- * @param {PageEditorOptions} props - The options for the page editor. Includes a `reloadFunction` and a `pathname`.
43
- * @returns {{rowsRef: React.RefObject<HTMLDivElement>[], isInsideEditor: boolean}} - Returns a reference to the rows of the page and a boolean that indicates if the page is inside the editor.
44
- * @throws {Error} - Throws an error if the `pathname` is not provided.
45
- */
46
- export declare const usePageEditor: (props: PageEditorOptions) => {
47
- rowsRef: React.MutableRefObject<HTMLDivElement[]>;
48
- isInsideEditor: boolean;
49
- };
50
- export {};