@dotcms/react 0.0.1-alpha.8 → 0.0.1-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.
Files changed (30) hide show
  1. package/README.md +0 -1
  2. package/index.esm.js +4420 -1887
  3. package/package.json +8 -6
  4. package/src/index.d.ts +3 -1
  5. package/src/lib/components/BlockEditorRenderer/BlockEditorRenderer.d.ts +37 -0
  6. package/src/lib/components/BlockEditorRenderer/blocks/Code.d.ts +17 -0
  7. package/src/lib/components/BlockEditorRenderer/blocks/Contentlet.d.ts +41 -0
  8. package/src/lib/components/BlockEditorRenderer/blocks/Image.d.ts +8 -0
  9. package/src/lib/components/BlockEditorRenderer/blocks/Lists.d.ts +22 -0
  10. package/src/lib/components/BlockEditorRenderer/blocks/Table.d.ts +16 -0
  11. package/src/lib/components/BlockEditorRenderer/blocks/Texts.d.ts +71 -0
  12. package/src/lib/components/BlockEditorRenderer/blocks/Video.d.ts +8 -0
  13. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +12 -0
  14. package/src/lib/components/Column/Column.d.ts +16 -2
  15. package/src/lib/components/Container/Container.d.ts +16 -2
  16. package/src/lib/components/DotEditableText/DotEditableText.d.ts +30 -0
  17. package/src/lib/components/DotEditableText/utils.d.ts +36 -0
  18. package/src/lib/components/DotcmsLayout/DotcmsLayout.d.ts +9 -8
  19. package/src/lib/components/PageProvider/PageProvider.d.ts +1 -71
  20. package/src/lib/components/Row/Row.d.ts +6 -5
  21. package/src/lib/contexts/PageContext.d.ts +7 -2
  22. package/src/lib/hooks/useCheckHaveContent.d.ts +5 -0
  23. package/src/lib/hooks/useDotcmsEditor.d.ts +13 -0
  24. package/src/lib/hooks/useDotcmsPageContext.d.ts +3 -3
  25. package/src/lib/mocks/mockPageContext.d.ts +4 -4
  26. package/src/lib/models/blocks.interface.d.ts +89 -0
  27. package/src/lib/models/content-node.interface.d.ts +82 -0
  28. package/src/lib/models/index.d.ts +127 -0
  29. package/src/lib/utils/utils.d.ts +38 -28
  30. package/src/lib/hooks/usePageEditor.d.ts +0 -50
@@ -0,0 +1,89 @@
1
+ /// <reference types="react" />
2
+ import { ContentNode } from './content-node.interface';
3
+ /**
4
+ * Represents a Block of content provided by the Block Editor
5
+ *
6
+ * @export
7
+ * @interface Block
8
+ */
9
+ export interface Block {
10
+ content: ContentNode[];
11
+ type: string;
12
+ }
13
+ /**
14
+ * Props for a contentlet inside the Block Editor
15
+ *
16
+ * @export
17
+ * @interface DotContentletProps
18
+ */
19
+ export interface DotContentletProps {
20
+ title: string;
21
+ baseType: string;
22
+ inode: string;
23
+ archived: boolean;
24
+ working: boolean;
25
+ locked: boolean;
26
+ contentType: string;
27
+ live: boolean;
28
+ identifier: string;
29
+ image: string;
30
+ imageContentAsset: string;
31
+ urlTitle: string;
32
+ url: string;
33
+ titleImage: string;
34
+ urlMap: string;
35
+ hasLiveVersion: boolean;
36
+ hasTitleImage: boolean;
37
+ sortOrder: number;
38
+ modUser: string;
39
+ __icon__: string;
40
+ contentTypeIcon: string;
41
+ language: string;
42
+ description: string;
43
+ shortDescription: string;
44
+ salePrice: string;
45
+ retailPrice: string;
46
+ mimeType: string;
47
+ thumbnail?: string;
48
+ }
49
+ /**
50
+ * Props for a block inside the Block Editor Component
51
+ *
52
+ * @export
53
+ * @interface BlockProps
54
+ */
55
+ export interface BlockProps {
56
+ children: React.ReactNode;
57
+ }
58
+ /**
59
+ * Represents the different types of Blocks that can be used in the Block Editor
60
+ *
61
+ * @export
62
+ * @enum {number}
63
+ */
64
+ export declare enum Blocks {
65
+ PARAGRAPH = "paragraph",
66
+ HEADING = "heading",
67
+ TEXT = "text",
68
+ BULLET_LIST = "bulletList",
69
+ ORDERED_LIST = "orderedList",
70
+ LIST_ITEM = "listItem",
71
+ BLOCK_QUOTE = "blockquote",
72
+ CODE_BLOCK = "codeBlock",
73
+ HARDBREAK = "hardBreak",
74
+ HORIZONTAL_RULE = "horizontalRule",
75
+ DOT_IMAGE = "dotImage",
76
+ DOT_VIDEO = "dotVideo",
77
+ TABLE = "table",
78
+ DOT_CONTENT = "dotContent"
79
+ }
80
+ /**
81
+ * Represents the validation state of a Block Editor instance
82
+ *
83
+ * @interface BlockEditorState
84
+ * @property {boolean} isValid - Whether the blocks structure is valid
85
+ * @property {string | null} error - Error message if blocks are invalid, null otherwise
86
+ */
87
+ export interface BlockEditorState {
88
+ error: string | null;
89
+ }
@@ -0,0 +1,82 @@
1
+ /// <reference types="react" />
2
+ import { BlockProps } from './blocks.interface';
3
+ /**
4
+ * Represents a Mark used by text content in the Block Editor
5
+ *
6
+ * @export
7
+ * @interface Mark
8
+ */
9
+ export interface Mark {
10
+ type: string;
11
+ attrs: Record<string, string>;
12
+ }
13
+ /**
14
+ * Represents a Content Node used by the Block Editor
15
+ *
16
+ * @export
17
+ * @interface ContentNode
18
+ */
19
+ export interface ContentNode {
20
+ type: string;
21
+ content: ContentNode[];
22
+ attrs?: Record<string, string>;
23
+ marks?: Mark[];
24
+ text?: string;
25
+ }
26
+ /**
27
+ * Represents a Custom Renderer used by the Block Editor Component
28
+ *
29
+ * @export
30
+ * @interface CustomRenderer
31
+ */
32
+ export type CustomRenderer<T = any> = Record<string, React.FC<T>>;
33
+ /**
34
+ * Represents a CodeBlock used by the Block Editor Component
35
+ * @export
36
+ * @interface CodeBlockProps
37
+ */
38
+ export type CodeBlockProps = BlockProps & ContentNode;
39
+ /**
40
+ * Represents a Heading used by the Block Editor Component
41
+ * @export
42
+ * @interface HeadingProps
43
+ */
44
+ export type HeadingProps = BlockProps & ContentNode;
45
+ /**
46
+ * Represents a Link used by the Block Editor Component
47
+ * @export
48
+ * @interface LinkProps
49
+ */
50
+ export type LinkProps = BlockProps & {
51
+ attrs?: Mark['attrs'];
52
+ };
53
+ /**
54
+ * Represents a Paragraph used by the Block Editor Component
55
+ * @export
56
+ * @interface ParagraphProps
57
+ */
58
+ export type ParagraphProps = BlockProps & ContentNode;
59
+ /**
60
+ * Represents a DotCMSVideo used by the Block Editor Component
61
+ * @export
62
+ * @interface DotCMSVideoProps
63
+ */
64
+ export type DotCMSVideoProps = ContentNode['attrs'] & {
65
+ data?: Record<string, string>;
66
+ };
67
+ /**
68
+ * Represents a DotCMSImage used by the Block Editor Component
69
+ * @export
70
+ * @interface DotCMSImageProps
71
+ */
72
+ export type DotCMSImageProps = ContentNode['attrs'] & {
73
+ data?: Record<string, unknown>;
74
+ };
75
+ /**
76
+ * Represents a DotContent used by the Block Editor Component
77
+ * @export
78
+ * @interface DotContentProps
79
+ */
80
+ export type DotContentProps = ContentNode & {
81
+ customRenderers?: CustomRenderer;
82
+ };
@@ -0,0 +1,127 @@
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
+ }
89
+ export interface DotCMSContentlet {
90
+ archived: boolean;
91
+ binaryContentAsset?: string;
92
+ deleted?: boolean;
93
+ baseType: string;
94
+ binary?: string;
95
+ binaryVersion?: string;
96
+ file?: string;
97
+ contentType: string;
98
+ hasLiveVersion?: boolean;
99
+ folder: string;
100
+ hasTitleImage: boolean;
101
+ hostName: string;
102
+ host: string;
103
+ inode: string;
104
+ identifier: string;
105
+ languageId: number;
106
+ image?: string;
107
+ locked: boolean;
108
+ language?: string;
109
+ mimeType?: string;
110
+ modUser: string;
111
+ modDate: string;
112
+ live: boolean;
113
+ sortOrder: number;
114
+ owner: string;
115
+ title: string;
116
+ stInode: string;
117
+ titleImage: string;
118
+ modUserName: string;
119
+ text?: string;
120
+ working: boolean;
121
+ url: string;
122
+ contentTypeIcon?: string;
123
+ body?: string;
124
+ variant?: string;
125
+ __icon__?: string;
126
+ [key: string]: any;
127
+ }
@@ -1,31 +1,13 @@
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 getContainersData: (containers: ContainerData, containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
1
+ import { ContainerData, DotCMSPageContext } from '../models';
2
+ import { Block, BlockEditorState } from '../models/blocks.interface';
3
+ /**
4
+ * Get the container data from the containers object using the current container reference obtained from the layout.
5
+ *
6
+ * @param {ContainerData} containers
7
+ * @param {DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]} containerRef
8
+ * @returns {Object} Container with all the data it has.
9
+ */
10
+ export declare const getContainersData: (containers: ContainerData, containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
29
11
  acceptTypes: string;
30
12
  contentlets: {
31
13
  contentType: string;
@@ -34,6 +16,7 @@ export declare const getContainersData: (containers: ContainerData, containerRef
34
16
  inode: string;
35
17
  onNumberOfPages: number;
36
18
  widgetTitle?: string | undefined;
19
+ baseType: string;
37
20
  }[];
38
21
  variantId: string;
39
22
  path: string;
@@ -41,8 +24,35 @@ export declare const getContainersData: (containers: ContainerData, containerRef
41
24
  maxContentlets: number;
42
25
  parentPermissionable: Record<string, string>;
43
26
  };
27
+ /**
28
+ * Combine classes into a single string.
29
+ *
30
+ * @param {string[]} classes
31
+ * @returns {string} Combined classes
32
+ */
44
33
  export declare const combineClasses: (classes: string[]) => string;
34
+ /**
35
+ * Get the start and end classes for the column based on the left offset and width.
36
+ *
37
+ * @param {number} start
38
+ * @param {number} end
39
+ * @returns {Object} Start and end classes
40
+ */
45
41
  export declare const getPositionStyleClasses: (start: number, end: number) => {
46
42
  startClass: string;
47
43
  endClass: string;
48
44
  };
45
+ /**
46
+ * Validates the structure of a Block Editor block.
47
+ *
48
+ * This function checks that:
49
+ * 1. The blocks parameter is a valid object
50
+ * 2. The block has a 'doc' type
51
+ * 3. The block has a valid content array that is not empty
52
+ *
53
+ * @param {Block} blocks - The blocks structure to validate
54
+ * @returns {BlockEditorState} Object containing validation state and any error message
55
+ * @property {boolean} BlockEditorState.isValid - Whether the blocks structure is valid
56
+ * @property {string | null} BlockEditorState.error - Error message if invalid, null if valid
57
+ */
58
+ export declare const isValidBlocks: (blocks: Block) => BlockEditorState;
@@ -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 {};