@dotcms/react 0.0.1-alpha.40 → 0.0.1-alpha.42

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 (64) hide show
  1. package/index.esm.d.ts +1 -0
  2. package/index.esm.js +5164 -0
  3. package/package.json +8 -4
  4. package/src/lib/components/BlockEditorRenderer/{BlockEditorRenderer.tsx → BlockEditorRenderer.d.ts} +2 -16
  5. package/src/lib/components/BlockEditorRenderer/blocks/{Code.tsx → Code.d.ts} +2 -14
  6. package/src/lib/components/BlockEditorRenderer/blocks/{Contentlet.tsx → Contentlet.d.ts} +1 -21
  7. package/src/lib/components/BlockEditorRenderer/blocks/Image.d.ts +8 -0
  8. package/src/lib/components/BlockEditorRenderer/blocks/{Lists.tsx → Lists.d.ts} +3 -12
  9. package/src/lib/components/BlockEditorRenderer/blocks/Table.d.ts +16 -0
  10. package/src/lib/components/BlockEditorRenderer/blocks/Texts.d.ts +71 -0
  11. package/src/lib/components/BlockEditorRenderer/blocks/Video.d.ts +8 -0
  12. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +12 -0
  13. package/src/lib/components/Column/Column.d.ts +19 -0
  14. package/src/lib/components/Container/Container.d.ts +19 -0
  15. package/src/lib/components/DotEditableText/DotEditableText.d.ts +31 -0
  16. package/src/lib/components/DotEditableText/utils.d.ts +36 -0
  17. package/src/lib/components/DotcmsLayout/{DotcmsLayout.tsx → DotcmsLayout.d.ts} +2 -18
  18. package/src/lib/components/PageProvider/{PageProvider.tsx → PageProvider.d.ts} +1 -10
  19. package/src/lib/components/Row/Row.d.ts +26 -0
  20. package/src/lib/contexts/{PageContext.tsx → PageContext.d.ts} +2 -4
  21. package/src/lib/hooks/useDotcmsEditor.d.ts +13 -0
  22. package/src/lib/hooks/{useDotcmsPageContext.tsx → useDotcmsPageContext.d.ts} +1 -7
  23. package/src/lib/mocks/mockPageContext.d.ts +8 -0
  24. package/src/lib/models/{blocks.interface.ts → blocks.interface.d.ts} +16 -19
  25. package/src/lib/models/{content-node.interface.ts → content-node.interface.d.ts} +4 -12
  26. package/src/lib/models/{index.ts → index.d.ts} +2 -5
  27. package/src/lib/utils/utils.d.ts +43 -0
  28. package/.babelrc +0 -12
  29. package/.eslintrc.json +0 -18
  30. package/jest.config.ts +0 -11
  31. package/project.json +0 -56
  32. package/src/lib/components/BlockEditorRenderer/BlockEditorRenderer.spec.tsx +0 -51
  33. package/src/lib/components/BlockEditorRenderer/blocks/Image.tsx +0 -18
  34. package/src/lib/components/BlockEditorRenderer/blocks/Table.tsx +0 -60
  35. package/src/lib/components/BlockEditorRenderer/blocks/Texts.tsx +0 -126
  36. package/src/lib/components/BlockEditorRenderer/blocks/Video.tsx +0 -26
  37. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.spec.tsx +0 -634
  38. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.tsx +0 -146
  39. package/src/lib/components/Column/Column.module.css +0 -99
  40. package/src/lib/components/Column/Column.spec.tsx +0 -78
  41. package/src/lib/components/Column/Column.tsx +0 -59
  42. package/src/lib/components/Container/Container.module.css +0 -7
  43. package/src/lib/components/Container/Container.spec.tsx +0 -155
  44. package/src/lib/components/Container/Container.tsx +0 -122
  45. package/src/lib/components/DotEditableText/DotEditableText.spec.tsx +0 -232
  46. package/src/lib/components/DotEditableText/DotEditableText.tsx +0 -168
  47. package/src/lib/components/DotEditableText/utils.ts +0 -82
  48. package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +0 -7
  49. package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +0 -46
  50. package/src/lib/components/PageProvider/PageProvider.module.css +0 -7
  51. package/src/lib/components/PageProvider/PageProvider.spec.tsx +0 -59
  52. package/src/lib/components/Row/Row.module.css +0 -5
  53. package/src/lib/components/Row/Row.spec.tsx +0 -92
  54. package/src/lib/components/Row/Row.tsx +0 -52
  55. package/src/lib/hooks/useDotcmsEditor.spec.ts +0 -176
  56. package/src/lib/hooks/useDotcmsEditor.ts +0 -94
  57. package/src/lib/hooks/useDotcmsPageContext.spec.tsx +0 -47
  58. package/src/lib/mocks/mockPageContext.tsx +0 -113
  59. package/src/lib/utils/utils.ts +0 -89
  60. package/tsconfig.json +0 -20
  61. package/tsconfig.lib.json +0 -23
  62. package/tsconfig.spec.json +0 -20
  63. /package/src/{index.ts → index.d.ts} +0 -0
  64. /package/src/lib/mocks/{index.ts → index.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
+ /// <reference types="react" />
1
2
  import { BlockProps } from './blocks.interface';
2
-
3
3
  /**
4
4
  * Represents a Mark used by text content in the Block Editor
5
5
  *
@@ -10,7 +10,6 @@ export interface Mark {
10
10
  type: string;
11
11
  attrs: Record<string, string>;
12
12
  }
13
-
14
13
  /**
15
14
  * Represents a Content Node used by the Block Editor
16
15
  *
@@ -24,44 +23,39 @@ export interface ContentNode {
24
23
  marks?: Mark[];
25
24
  text?: string;
26
25
  }
27
-
28
26
  /**
29
27
  * Represents a Custom Renderer used by the Block Editor Component
30
28
  *
31
29
  * @export
32
30
  * @interface CustomRenderer
33
31
  */
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
32
  export type CustomRenderer<T = any> = Record<string, React.FC<T>>;
36
-
37
33
  /**
38
34
  * Represents a CodeBlock used by the Block Editor Component
39
35
  * @export
40
36
  * @interface CodeBlockProps
41
37
  */
42
38
  export type CodeBlockProps = BlockProps & ContentNode;
43
-
44
39
  /**
45
40
  * Represents a Heading used by the Block Editor Component
46
41
  * @export
47
42
  * @interface HeadingProps
48
43
  */
49
44
  export type HeadingProps = BlockProps & ContentNode;
50
-
51
45
  /**
52
46
  * Represents a Link used by the Block Editor Component
53
47
  * @export
54
48
  * @interface LinkProps
55
49
  */
56
- export type LinkProps = BlockProps & { attrs?: Mark['attrs'] };
57
-
50
+ export type LinkProps = BlockProps & {
51
+ attrs?: Mark['attrs'];
52
+ };
58
53
  /**
59
54
  * Represents a Paragraph used by the Block Editor Component
60
55
  * @export
61
56
  * @interface ParagraphProps
62
57
  */
63
58
  export type ParagraphProps = BlockProps & ContentNode;
64
-
65
59
  /**
66
60
  * Represents a DotCMSVideo used by the Block Editor Component
67
61
  * @export
@@ -70,7 +64,6 @@ export type ParagraphProps = BlockProps & ContentNode;
70
64
  export type DotCMSVideoProps = ContentNode['attrs'] & {
71
65
  data?: Record<string, string>;
72
66
  };
73
-
74
67
  /**
75
68
  * Represents a DotCMSImage used by the Block Editor Component
76
69
  * @export
@@ -79,7 +72,6 @@ export type DotCMSVideoProps = ContentNode['attrs'] & {
79
72
  export type DotCMSImageProps = ContentNode['attrs'] & {
80
73
  data?: Record<string, unknown>;
81
74
  };
82
-
83
75
  /**
84
76
  * Represents a DotContent used by the Block Editor Component
85
77
  * @export
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  export interface ContainerData {
2
3
  [key: string]: {
3
4
  container: {
@@ -22,7 +23,6 @@ export interface ContainerData {
22
23
  };
23
24
  };
24
25
  }
25
-
26
26
  export interface DotCMSPageContext {
27
27
  /**
28
28
  * `components` is a property of the `PageProviderProps` type.
@@ -68,7 +68,6 @@ export interface DotCMSPageContext {
68
68
  persona: {
69
69
  keyTag: string;
70
70
  };
71
- // variant requested
72
71
  variantId: string;
73
72
  };
74
73
  vanityUrl?: {
@@ -87,7 +86,6 @@ export interface DotCMSPageContext {
87
86
  };
88
87
  isInsideEditor: boolean;
89
88
  }
90
-
91
89
  export interface DotCMSContentlet {
92
90
  archived: boolean;
93
91
  binaryContentAsset?: string;
@@ -125,6 +123,5 @@ export interface DotCMSContentlet {
125
123
  body?: string;
126
124
  variant?: string;
127
125
  __icon__?: string;
128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- [key: string]: any; // This is a catch-all for any other custom properties that might be on the contentlet.
126
+ [key: string]: any;
130
127
  }
@@ -0,0 +1,43 @@
1
+ import { ContainerData, DotCMSPageContext } from '../models';
2
+ /**
3
+ * Get the container data from the containers object using the current container reference obtained from the layout.
4
+ *
5
+ * @param {ContainerData} containers
6
+ * @param {DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]} containerRef
7
+ * @returns {Object} Container with all the data it has.
8
+ */
9
+ export declare const getContainersData: (containers: ContainerData, containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
10
+ acceptTypes: string;
11
+ contentlets: {
12
+ contentType: string;
13
+ identifier: string;
14
+ title: string;
15
+ inode: string;
16
+ onNumberOfPages: number;
17
+ widgetTitle?: string | undefined;
18
+ baseType: string;
19
+ }[];
20
+ variantId: string;
21
+ path: string;
22
+ identifier: string;
23
+ maxContentlets: number;
24
+ parentPermissionable: Record<string, string>;
25
+ };
26
+ /**
27
+ * Combine classes into a single string.
28
+ *
29
+ * @param {string[]} classes
30
+ * @returns {string} Combined classes
31
+ */
32
+ export declare const combineClasses: (classes: string[]) => string;
33
+ /**
34
+ * Get the start and end classes for the column based on the left offset and width.
35
+ *
36
+ * @param {number} start
37
+ * @param {number} end
38
+ * @returns {Object} Start and end classes
39
+ */
40
+ export declare const getPositionStyleClasses: (start: number, end: number) => {
41
+ startClass: string;
42
+ endClass: string;
43
+ };
package/.babelrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@nrwl/react/babel",
5
- {
6
- "runtime": "automatic",
7
- "useBuiltIns": "usage"
8
- }
9
- ]
10
- ],
11
- "plugins": []
12
- }
package/.eslintrc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": ["plugin:@nrwl/nx/react", "../../../.eslintrc.base.json"],
3
- "ignorePatterns": ["!**/*"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {}
8
- },
9
- {
10
- "files": ["*.ts", "*.tsx"],
11
- "rules": {}
12
- },
13
- {
14
- "files": ["*.js", "*.jsx"],
15
- "rules": {}
16
- }
17
- ]
18
- }
package/jest.config.ts DELETED
@@ -1,11 +0,0 @@
1
- /* eslint-disable */
2
- export default {
3
- displayName: 'sdk-react',
4
- preset: '../../../jest.preset.js',
5
- transform: {
6
- '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
7
- '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/react/babel'] }]
8
- },
9
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
10
- coverageDirectory: '../../../coverage/libs/sdk/react'
11
- };
package/project.json DELETED
@@ -1,56 +0,0 @@
1
- {
2
- "name": "sdk-react",
3
- "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/sdk/react/src",
5
- "projectType": "library",
6
- "tags": [],
7
- "targets": {
8
- "lint": {
9
- "executor": "@nx/eslint:lint",
10
- "outputs": ["{options.outputFile}"],
11
- "options": {
12
- "lintFilePatterns": ["libs/sdk/react/**/*.{ts,tsx,js,jsx}"]
13
- }
14
- },
15
- "build": {
16
- "executor": "@nrwl/rollup:rollup",
17
- "outputs": ["{options.outputPath}"],
18
- "options": {
19
- "outputPath": "dist/libs/sdk/react",
20
- "tsConfig": "libs/sdk/react/tsconfig.lib.json",
21
- "project": "libs/sdk/react/package.json",
22
- "entryFile": "libs/sdk/react/src/index.ts",
23
- "external": ["react/jsx-runtime"],
24
- "rollupConfig": "@nrwl/react/plugins/bundle-rollup",
25
- "compiler": "babel",
26
- "extractCss": false,
27
- "assets": [
28
- {
29
- "glob": "libs/sdk/react/README.md",
30
- "input": ".",
31
- "output": "."
32
- }
33
- ]
34
- }
35
- },
36
- "test": {
37
- "executor": "@nrwl/jest:jest",
38
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
39
- "options": {
40
- "jestConfig": "libs/sdk/react/jest.config.ts",
41
- "passWithNoTests": true
42
- },
43
- "configurations": {
44
- "ci": {
45
- "ci": true,
46
- "codeCoverage": true
47
- }
48
- }
49
- },
50
- "nx-release-publish": {
51
- "options": {
52
- "packageRoot": "dist/libs/sdk/react"
53
- }
54
- }
55
- }
56
- }
@@ -1,51 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- import { render } from '@testing-library/react';
3
-
4
- import { BlockEditorRenderer } from './BlockEditorRenderer';
5
-
6
- import { Block } from '../../models/blocks.interface';
7
-
8
- describe('BlockEditorRenderer', () => {
9
- const blocks = {
10
- content: [
11
- {
12
- type: 'paragraph',
13
- attrs: {},
14
- content: [
15
- {
16
- type: 'text',
17
- text: 'Hello, World!'
18
- }
19
- ]
20
- }
21
- ]
22
- } as Block;
23
-
24
- it('should render the BlockEditorItem component', () => {
25
- const { getByText } = render(<BlockEditorRenderer blocks={blocks} />);
26
- expect(getByText('Hello, World!')).toBeInTheDocument();
27
- });
28
-
29
- it('should render the custom renderer component', () => {
30
- const customRenderers = {
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- paragraph: ({ content }: { content: any }) => {
33
- const [{ text }] = content;
34
-
35
- return <p data-testid="custom-paragraph">{text}</p>;
36
- }
37
- };
38
- const { getByTestId } = render(
39
- <BlockEditorRenderer blocks={blocks} customRenderers={customRenderers} />
40
- );
41
- expect(getByTestId('custom-paragraph')).toBeInTheDocument();
42
- });
43
-
44
- it('should render the property className and style props', () => {
45
- const { container } = render(
46
- <BlockEditorRenderer blocks={blocks} className="test-class" style={{ color: 'red' }} />
47
- );
48
- expect(container.firstChild).toHaveClass('test-class');
49
- expect(container.firstChild).toHaveStyle('color: red');
50
- });
51
- });
@@ -1,18 +0,0 @@
1
- import { DotCmsClient } from '@dotcms/client';
2
-
3
- import { ContentNode, DotCMSImageProps } from '../../../models/content-node.interface';
4
-
5
- /**
6
- * Renders an image component for dotCMS.
7
- *
8
- * @param props - The props for the DotCMSImage component.
9
- * @returns The rendered image component.
10
- */
11
- export const DotCMSImage = (props: ContentNode) => {
12
- const { data, src, alt } = props.attrs as DotCMSImageProps;
13
- const client = DotCmsClient.instance;
14
-
15
- const srcUrl = data?.identifier ? `${client.dotcmsUrl}${src}` : src;
16
-
17
- return <img alt={alt} src={srcUrl} />;
18
- };
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
-
3
- import { ContentNode } from '../../../models/content-node.interface';
4
-
5
- interface TableRendererProps {
6
- content: ContentNode[];
7
- blockEditorItem: React.FC<{
8
- content: ContentNode[];
9
- }>;
10
- }
11
-
12
- /**
13
- * Renders a table component for the Block Editor.
14
- *
15
- * @param content - The content of the table.
16
- * @param blockEditorItem - The Block Editor item component.
17
- */
18
- export const TableRenderer: React.FC<TableRendererProps> = ({
19
- content,
20
- blockEditorItem
21
- }: TableRendererProps) => {
22
- const BlockEditorItemComponent = blockEditorItem;
23
-
24
- const renderTableContent = (node: ContentNode) => {
25
- return <BlockEditorItemComponent content={node.content} />;
26
- };
27
-
28
- return (
29
- <table>
30
- <thead>
31
- {content.slice(0, 1).map((rowNode, rowIndex) => (
32
- <tr key={`${rowNode.type}-${rowIndex}`}>
33
- {rowNode.content?.map((cellNode, cellIndex) => (
34
- <th
35
- key={`${cellNode.type}-${cellIndex}`}
36
- colSpan={Number(cellNode.attrs?.colspan || 1)}
37
- rowSpan={Number(cellNode.attrs?.rowspan || 1)}>
38
- {renderTableContent(cellNode)}
39
- </th>
40
- ))}
41
- </tr>
42
- ))}
43
- </thead>
44
- <tbody>
45
- {content.slice(1).map((rowNode, rowIndex) => (
46
- <tr key={`${rowNode.type}-${rowIndex}`}>
47
- {rowNode.content?.map((cellNode, cellIndex) => (
48
- <td
49
- key={`${cellNode.type}-${cellIndex}`}
50
- colSpan={Number(cellNode.attrs?.colspan || 1)}
51
- rowSpan={Number(cellNode.attrs?.rowspan || 1)}>
52
- {renderTableContent(cellNode)}
53
- </td>
54
- ))}
55
- </tr>
56
- ))}
57
- </tbody>
58
- </table>
59
- );
60
- };
@@ -1,126 +0,0 @@
1
- import { BlockProps } from '../../../models/blocks.interface';
2
- import {
3
- ContentNode,
4
- HeadingProps,
5
- LinkProps,
6
- ParagraphProps
7
- } from '../../../models/content-node.interface';
8
-
9
- /**
10
- * Renders the text in bold.
11
- *
12
- * @param children - The content to be rendered in bold.
13
- */
14
- export const Bold = ({ children }: BlockProps) => <strong>{children}</strong>;
15
-
16
- /**
17
- * Renders the text in italic format.
18
- *
19
- * @param children - The content to be rendered in italic.
20
- */
21
- export const Italic = ({ children }: BlockProps) => <em>{children}</em>;
22
-
23
- /**
24
- * Renders a strike-through text.
25
- *
26
- * @param children - The content to be rendered within the strike-through element.
27
- */
28
- export const Strike = ({ children }: BlockProps) => <s>{children}</s>;
29
-
30
- /**
31
- * Renders an underline element for the given children.
32
- *
33
- * @param children - The content to be underlined.
34
- */
35
- export const Underline = ({ children }: BlockProps) => <u>{children}</u>;
36
-
37
- /**
38
- * Renders a paragraph element.
39
- *
40
- * @param children - The content of the paragraph.
41
- * @param attrs - The style attributes for the paragraph.
42
- * @returns The rendered paragraph element.
43
- */
44
- export const Paragraph = ({ children, attrs }: ParagraphProps) => {
45
- return <p style={attrs}>{children}</p>;
46
- };
47
-
48
- /**
49
- * Renders a link component.
50
- *
51
- * @param children - The content of the link.
52
- * @param attrs - The attributes to be applied to the link.
53
- * @returns The rendered link component.
54
- */
55
- export const Link = ({ children, attrs }: LinkProps) => {
56
- return <a {...attrs}>{children}</a>;
57
- };
58
-
59
- /**
60
- * Renders a heading element with the specified level.
61
- *
62
- * @param children - The content of the heading.
63
- * @param attrs - The attributes for the heading.
64
- * @returns The rendered heading element.
65
- */
66
- export const Heading = ({ children, attrs }: HeadingProps) => {
67
- const level = attrs?.level || 1;
68
- const Tag = `h${level}` as keyof JSX.IntrinsicElements;
69
-
70
- return <Tag>{children}</Tag>;
71
- };
72
-
73
- /**
74
- * Renders the superscript text.
75
- *
76
- * @param children - The content to be rendered as superscript.
77
- */
78
- export const Superscript = ({ children }: BlockProps) => <sup>{children}</sup>;
79
-
80
- /**
81
- * Renders a subscript element.
82
- *
83
- * @param children - The content to be rendered as subscript.
84
- */
85
- export const Subscript = ({ children }: BlockProps) => <sub>{children}</sub>;
86
-
87
- const nodeMarks: Record<string, React.FC<BlockProps | LinkProps | HeadingProps>> = {
88
- link: Link,
89
- bold: Bold,
90
- underline: Underline,
91
- italic: Italic,
92
- strike: Strike,
93
- superscript: Superscript,
94
- subscript: Subscript
95
- };
96
-
97
- type TextBlockProps = Omit<ContentNode, 'content' | 'attrs'>;
98
-
99
- /**
100
- * Renders a text block with optional marks.
101
- *
102
- * @param props - The props for the TextBlock component.
103
- * @returns The rendered text block.
104
- */
105
- export const TextBlock = (props: TextBlockProps) => {
106
- const { marks = [], text } = props;
107
- const mark = marks[0] || { type: '', attrs: {} };
108
- const newProps = { ...props, marks: marks.slice(1) };
109
- const Component = nodeMarks[mark?.type];
110
-
111
- // To avoid the warning: "Warning: Invalid DOM property `class`. Did you mean `className`?"
112
- if (mark.attrs) {
113
- mark.attrs.className = mark.attrs.class;
114
- delete mark.attrs.class;
115
- }
116
-
117
- if (!Component) {
118
- return text;
119
- }
120
-
121
- return (
122
- <Component attrs={mark.attrs}>
123
- <TextBlock {...newProps} />
124
- </Component>
125
- );
126
- };
@@ -1,26 +0,0 @@
1
- import { DotCmsClient } from '@dotcms/client';
2
-
3
- import { ContentNode, DotCMSVideoProps } from '../../../models/content-node.interface';
4
-
5
- /**
6
- * Renders a video component for displaying videos.
7
- *
8
- * @param props - The properties for the video component.
9
- * @returns The rendered video component.
10
- */
11
- export const DotCMSVideo = (props: ContentNode) => {
12
- const { data, src, mimeType, width, height } = props.attrs as DotCMSVideoProps;
13
- const client = DotCmsClient.instance;
14
-
15
- const srcUrl = data?.identifier ? `${client.dotcmsUrl}${src}` : src;
16
-
17
- const poster = data?.thumbnail ? `${client.dotcmsUrl}${data?.thumbnail}` : 'poster-image.jpg';
18
-
19
- return (
20
- <video controls preload="metadata" poster={poster} width={width} height={height}>
21
- <track default kind="captions" srcLang="en" />
22
- <source src={srcUrl} type={mimeType} />
23
- Your browser does not support the <code>video</code> element.
24
- </video>
25
- );
26
- };