@dotcms/react 0.0.1-alpha.38 → 0.0.1-alpha.39
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/.babelrc +12 -0
- package/.eslintrc.json +18 -0
- package/jest.config.ts +11 -0
- package/package.json +4 -8
- package/project.json +56 -0
- package/src/lib/components/BlockEditorRenderer/BlockEditorRenderer.spec.tsx +51 -0
- package/src/lib/components/BlockEditorRenderer/{BlockEditorRenderer.d.ts → BlockEditorRenderer.tsx} +16 -2
- package/src/lib/components/BlockEditorRenderer/blocks/{Code.d.ts → Code.tsx} +14 -2
- package/src/lib/components/BlockEditorRenderer/blocks/{Contentlet.d.ts → Contentlet.tsx} +21 -1
- package/src/lib/components/BlockEditorRenderer/blocks/Image.tsx +18 -0
- package/src/lib/components/BlockEditorRenderer/blocks/{Lists.d.ts → Lists.tsx} +12 -3
- package/src/lib/components/BlockEditorRenderer/blocks/Table.tsx +60 -0
- package/src/lib/components/BlockEditorRenderer/blocks/Texts.tsx +126 -0
- package/src/lib/components/BlockEditorRenderer/blocks/Video.tsx +26 -0
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.spec.tsx +634 -0
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.tsx +146 -0
- package/src/lib/components/Column/Column.module.css +99 -0
- package/src/lib/components/Column/Column.spec.tsx +78 -0
- package/src/lib/components/Column/Column.tsx +59 -0
- package/src/lib/components/Container/Container.module.css +7 -0
- package/src/lib/components/Container/Container.spec.tsx +155 -0
- package/src/lib/components/Container/Container.tsx +122 -0
- package/src/lib/components/DotEditableText/DotEditableText.spec.tsx +232 -0
- package/src/lib/components/DotEditableText/DotEditableText.tsx +168 -0
- package/src/lib/components/DotEditableText/utils.ts +82 -0
- package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +7 -0
- package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +46 -0
- package/src/lib/components/DotcmsLayout/{DotcmsLayout.d.ts → DotcmsLayout.tsx} +18 -2
- package/src/lib/components/PageProvider/PageProvider.module.css +7 -0
- package/src/lib/components/PageProvider/PageProvider.spec.tsx +59 -0
- package/src/lib/components/PageProvider/{PageProvider.d.ts → PageProvider.tsx} +10 -1
- package/src/lib/components/Row/Row.module.css +5 -0
- package/src/lib/components/Row/Row.spec.tsx +92 -0
- package/src/lib/components/Row/Row.tsx +52 -0
- package/src/lib/contexts/{PageContext.d.ts → PageContext.tsx} +4 -2
- package/src/lib/hooks/useDotcmsEditor.spec.ts +176 -0
- package/src/lib/hooks/useDotcmsEditor.ts +94 -0
- package/src/lib/hooks/useDotcmsPageContext.spec.tsx +47 -0
- package/src/lib/hooks/{useDotcmsPageContext.d.ts → useDotcmsPageContext.tsx} +7 -1
- package/src/lib/mocks/mockPageContext.tsx +113 -0
- package/src/lib/models/{blocks.interface.d.ts → blocks.interface.ts} +19 -16
- package/src/lib/models/{content-node.interface.d.ts → content-node.interface.ts} +12 -4
- package/src/lib/models/{index.d.ts → index.ts} +5 -2
- package/src/lib/utils/utils.ts +89 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +23 -0
- package/tsconfig.spec.json +20 -0
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -5172
- package/src/lib/components/BlockEditorRenderer/blocks/Image.d.ts +0 -8
- package/src/lib/components/BlockEditorRenderer/blocks/Table.d.ts +0 -16
- package/src/lib/components/BlockEditorRenderer/blocks/Texts.d.ts +0 -71
- package/src/lib/components/BlockEditorRenderer/blocks/Video.d.ts +0 -8
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +0 -12
- package/src/lib/components/Column/Column.d.ts +0 -19
- package/src/lib/components/Container/Container.d.ts +0 -19
- package/src/lib/components/DotEditableText/DotEditableText.d.ts +0 -31
- package/src/lib/components/DotEditableText/utils.d.ts +0 -36
- package/src/lib/components/Row/Row.d.ts +0 -26
- package/src/lib/hooks/useDotcmsEditor.d.ts +0 -13
- package/src/lib/mocks/mockPageContext.d.ts +0 -8
- package/src/lib/utils/utils.d.ts +0 -43
- /package/src/{index.d.ts → index.ts} +0 -0
- /package/src/lib/mocks/{index.d.ts → index.ts} +0 -0
package/.babelrc
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/react",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.39",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=18",
|
|
6
6
|
"react-dom": ">=18",
|
|
7
|
-
"@dotcms/client": "0.0.1-alpha.
|
|
7
|
+
"@dotcms/client": "0.0.1-alpha.39",
|
|
8
8
|
"@tinymce/tinymce-react": "^5.1.1"
|
|
9
9
|
},
|
|
10
10
|
"description": "Official React Components library to render a dotCMS page.",
|
|
@@ -26,9 +26,5 @@
|
|
|
26
26
|
"bugs": {
|
|
27
27
|
"url": "https://github.com/dotCMS/core/issues"
|
|
28
28
|
},
|
|
29
|
-
"homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/react/README.md"
|
|
30
|
-
|
|
31
|
-
"type": "module",
|
|
32
|
-
"main": "./index.esm.js",
|
|
33
|
-
"types": "./index.esm.d.ts"
|
|
34
|
-
}
|
|
29
|
+
"homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/react/README.md"
|
|
30
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
});
|
package/src/lib/components/BlockEditorRenderer/{BlockEditorRenderer.d.ts → BlockEditorRenderer.tsx}
RENAMED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { BlockEditorBlock } from './item/BlockEditorBlock';
|
|
2
|
+
|
|
2
3
|
import { Block } from '../../models/blocks.interface';
|
|
3
4
|
import { CustomRenderer } from '../../models/content-node.interface';
|
|
5
|
+
|
|
4
6
|
export interface BlockEditorRendererProps {
|
|
5
7
|
blocks: Block;
|
|
6
8
|
customRenderers?: CustomRenderer;
|
|
7
9
|
className?: string;
|
|
8
10
|
style?: React.CSSProperties;
|
|
9
11
|
}
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* BlockEditorRenderer component for rendering block editor field.
|
|
12
15
|
*
|
|
@@ -18,4 +21,15 @@ export interface BlockEditorRendererProps {
|
|
|
18
21
|
* @param {React.CSSProperties} [props.style] - Optional inline styles for the container div.
|
|
19
22
|
* @returns {JSX.Element} A div containing the rendered blocks of content.
|
|
20
23
|
*/
|
|
21
|
-
export
|
|
24
|
+
export const BlockEditorRenderer = ({
|
|
25
|
+
blocks,
|
|
26
|
+
customRenderers,
|
|
27
|
+
className,
|
|
28
|
+
style
|
|
29
|
+
}: BlockEditorRendererProps) => {
|
|
30
|
+
return (
|
|
31
|
+
<div className={className} style={style}>
|
|
32
|
+
<BlockEditorBlock content={blocks.content} customRenderers={customRenderers} />
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BlockProps } from '../../../models/blocks.interface';
|
|
2
2
|
import { CodeBlockProps } from '../../../models/content-node.interface';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Renders a code block component.
|
|
5
6
|
*
|
|
@@ -7,11 +8,22 @@ import { CodeBlockProps } from '../../../models/content-node.interface';
|
|
|
7
8
|
* @param children - The content of the code block.
|
|
8
9
|
* @returns The rendered code block component.
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export const CodeBlock = ({ attrs, children }: CodeBlockProps) => {
|
|
12
|
+
const language = attrs?.language || '';
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<pre data-language={language}>
|
|
16
|
+
<code>{children}</code>
|
|
17
|
+
</pre>
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
11
21
|
/**
|
|
12
22
|
* Renders a blockquote component.
|
|
13
23
|
*
|
|
14
24
|
* @param children - The content to be rendered inside the blockquote.
|
|
15
25
|
* @returns The rendered blockquote component.
|
|
16
26
|
*/
|
|
17
|
-
export
|
|
27
|
+
export const BlockQuote = ({ children }: BlockProps) => {
|
|
28
|
+
return <blockquote>{children}</blockquote>;
|
|
29
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DotContentProps } from '../../../models/content-node.interface';
|
|
2
|
+
|
|
3
|
+
// Replace this when we have a types lib
|
|
2
4
|
export interface Contentlet {
|
|
3
5
|
hostName: string;
|
|
4
6
|
modDate: string;
|
|
@@ -32,10 +34,28 @@ export interface Contentlet {
|
|
|
32
34
|
contentTypeIcon: string;
|
|
33
35
|
variant: string;
|
|
34
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Renders the default content for an unknown content type.
|
|
40
|
+
*/
|
|
41
|
+
const DefaultContent = () => <div>Unknown Content Type</div>;
|
|
42
|
+
|
|
35
43
|
/**
|
|
36
44
|
* Renders a DotContent component.
|
|
37
45
|
*
|
|
38
46
|
* @param {DotContentProps} props - The props for the DotContent component.
|
|
39
47
|
* @returns {JSX.Element} The rendered DotContent component.
|
|
40
48
|
*/
|
|
41
|
-
export
|
|
49
|
+
export const DotContent = ({ customRenderers, ...props }: DotContentProps) => {
|
|
50
|
+
const { attrs } = props;
|
|
51
|
+
|
|
52
|
+
const data = attrs?.data as unknown as Contentlet;
|
|
53
|
+
|
|
54
|
+
const Component = customRenderers?.[data?.contentType] ?? DefaultContent;
|
|
55
|
+
|
|
56
|
+
if (!data) {
|
|
57
|
+
console.error('DotContent: No data provided');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return <Component {...props} />;
|
|
61
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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,22 +1,31 @@
|
|
|
1
1
|
import { BlockProps } from '../../../models/blocks.interface';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* ListItem component represents a list item in a block editor.
|
|
4
5
|
*
|
|
5
6
|
* @param children - The content of the list item.
|
|
6
7
|
* @returns The rendered list item element.
|
|
7
8
|
*/
|
|
8
|
-
export
|
|
9
|
+
export const ListItem = ({ children }: BlockProps) => {
|
|
10
|
+
return <li>{children}</li>;
|
|
11
|
+
};
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Renders an ordered list component.
|
|
11
15
|
*
|
|
12
16
|
* @param children - The content to be rendered inside the ordered list.
|
|
13
17
|
* @returns The ordered list component.
|
|
14
18
|
*/
|
|
15
|
-
export
|
|
19
|
+
export const OrderedList = ({ children }: BlockProps) => {
|
|
20
|
+
return <ol>{children}</ol>;
|
|
21
|
+
};
|
|
22
|
+
|
|
16
23
|
/**
|
|
17
24
|
* Renders a bullet list component.
|
|
18
25
|
*
|
|
19
26
|
* @param children - The content of the bullet list.
|
|
20
27
|
* @returns The rendered bullet list component.
|
|
21
28
|
*/
|
|
22
|
-
export
|
|
29
|
+
export const BulletList = ({ children }: BlockProps) => {
|
|
30
|
+
return <ul>{children}</ul>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
};
|