@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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { BlockProps } from './blocks.interface';
|
|
2
|
+
|
|
3
3
|
/**
|
|
4
4
|
* Represents a Mark used by text content in the Block Editor
|
|
5
5
|
*
|
|
@@ -10,6 +10,7 @@ export interface Mark {
|
|
|
10
10
|
type: string;
|
|
11
11
|
attrs: Record<string, string>;
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Represents a Content Node used by the Block Editor
|
|
15
16
|
*
|
|
@@ -23,39 +24,44 @@ export interface ContentNode {
|
|
|
23
24
|
marks?: Mark[];
|
|
24
25
|
text?: string;
|
|
25
26
|
}
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* Represents a Custom Renderer used by the Block Editor Component
|
|
28
30
|
*
|
|
29
31
|
* @export
|
|
30
32
|
* @interface CustomRenderer
|
|
31
33
|
*/
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
35
|
export type CustomRenderer<T = any> = Record<string, React.FC<T>>;
|
|
36
|
+
|
|
33
37
|
/**
|
|
34
38
|
* Represents a CodeBlock used by the Block Editor Component
|
|
35
39
|
* @export
|
|
36
40
|
* @interface CodeBlockProps
|
|
37
41
|
*/
|
|
38
42
|
export type CodeBlockProps = BlockProps & ContentNode;
|
|
43
|
+
|
|
39
44
|
/**
|
|
40
45
|
* Represents a Heading used by the Block Editor Component
|
|
41
46
|
* @export
|
|
42
47
|
* @interface HeadingProps
|
|
43
48
|
*/
|
|
44
49
|
export type HeadingProps = BlockProps & ContentNode;
|
|
50
|
+
|
|
45
51
|
/**
|
|
46
52
|
* Represents a Link used by the Block Editor Component
|
|
47
53
|
* @export
|
|
48
54
|
* @interface LinkProps
|
|
49
55
|
*/
|
|
50
|
-
export type LinkProps = BlockProps & {
|
|
51
|
-
|
|
52
|
-
};
|
|
56
|
+
export type LinkProps = BlockProps & { attrs?: Mark['attrs'] };
|
|
57
|
+
|
|
53
58
|
/**
|
|
54
59
|
* Represents a Paragraph used by the Block Editor Component
|
|
55
60
|
* @export
|
|
56
61
|
* @interface ParagraphProps
|
|
57
62
|
*/
|
|
58
63
|
export type ParagraphProps = BlockProps & ContentNode;
|
|
64
|
+
|
|
59
65
|
/**
|
|
60
66
|
* Represents a DotCMSVideo used by the Block Editor Component
|
|
61
67
|
* @export
|
|
@@ -64,6 +70,7 @@ export type ParagraphProps = BlockProps & ContentNode;
|
|
|
64
70
|
export type DotCMSVideoProps = ContentNode['attrs'] & {
|
|
65
71
|
data?: Record<string, string>;
|
|
66
72
|
};
|
|
73
|
+
|
|
67
74
|
/**
|
|
68
75
|
* Represents a DotCMSImage used by the Block Editor Component
|
|
69
76
|
* @export
|
|
@@ -72,6 +79,7 @@ export type DotCMSVideoProps = ContentNode['attrs'] & {
|
|
|
72
79
|
export type DotCMSImageProps = ContentNode['attrs'] & {
|
|
73
80
|
data?: Record<string, unknown>;
|
|
74
81
|
};
|
|
82
|
+
|
|
75
83
|
/**
|
|
76
84
|
* Represents a DotContent used by the Block Editor Component
|
|
77
85
|
* @export
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export interface ContainerData {
|
|
3
2
|
[key: string]: {
|
|
4
3
|
container: {
|
|
@@ -23,6 +22,7 @@ export interface ContainerData {
|
|
|
23
22
|
};
|
|
24
23
|
};
|
|
25
24
|
}
|
|
25
|
+
|
|
26
26
|
export interface DotCMSPageContext {
|
|
27
27
|
/**
|
|
28
28
|
* `components` is a property of the `PageProviderProps` type.
|
|
@@ -68,6 +68,7 @@ export interface DotCMSPageContext {
|
|
|
68
68
|
persona: {
|
|
69
69
|
keyTag: string;
|
|
70
70
|
};
|
|
71
|
+
// variant requested
|
|
71
72
|
variantId: string;
|
|
72
73
|
};
|
|
73
74
|
vanityUrl?: {
|
|
@@ -86,6 +87,7 @@ export interface DotCMSPageContext {
|
|
|
86
87
|
};
|
|
87
88
|
isInsideEditor: boolean;
|
|
88
89
|
}
|
|
90
|
+
|
|
89
91
|
export interface DotCMSContentlet {
|
|
90
92
|
archived: boolean;
|
|
91
93
|
binaryContentAsset?: string;
|
|
@@ -123,5 +125,6 @@ export interface DotCMSContentlet {
|
|
|
123
125
|
body?: string;
|
|
124
126
|
variant?: string;
|
|
125
127
|
__icon__?: string;
|
|
126
|
-
|
|
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.
|
|
127
130
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ContainerData, DotCMSPageContext } from '../models';
|
|
2
|
+
|
|
3
|
+
const endClassMap: Record<number, string> = {
|
|
4
|
+
1: 'col-end-1',
|
|
5
|
+
2: 'col-end-2',
|
|
6
|
+
3: 'col-end-3',
|
|
7
|
+
4: 'col-end-4',
|
|
8
|
+
5: 'col-end-5',
|
|
9
|
+
6: 'col-end-6',
|
|
10
|
+
7: 'col-end-7',
|
|
11
|
+
8: 'col-end-8',
|
|
12
|
+
9: 'col-end-9',
|
|
13
|
+
10: 'col-end-10',
|
|
14
|
+
11: 'col-end-11',
|
|
15
|
+
12: 'col-end-12',
|
|
16
|
+
13: 'col-end-13'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const startClassMap: Record<number, string> = {
|
|
20
|
+
1: 'col-start-1',
|
|
21
|
+
2: 'col-start-2',
|
|
22
|
+
3: 'col-start-3',
|
|
23
|
+
4: 'col-start-4',
|
|
24
|
+
5: 'col-start-5',
|
|
25
|
+
6: 'col-start-6',
|
|
26
|
+
7: 'col-start-7',
|
|
27
|
+
8: 'col-start-8',
|
|
28
|
+
9: 'col-start-9',
|
|
29
|
+
10: 'col-start-10',
|
|
30
|
+
11: 'col-start-11',
|
|
31
|
+
12: 'col-start-12'
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the container data from the containers object using the current container reference obtained from the layout.
|
|
36
|
+
*
|
|
37
|
+
* @param {ContainerData} containers
|
|
38
|
+
* @param {DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]} containerRef
|
|
39
|
+
* @returns {Object} Container with all the data it has.
|
|
40
|
+
*/
|
|
41
|
+
export const getContainersData = (
|
|
42
|
+
containers: ContainerData,
|
|
43
|
+
containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]
|
|
44
|
+
) => {
|
|
45
|
+
const { identifier, uuid } = containerRef;
|
|
46
|
+
|
|
47
|
+
const { containerStructures, container } = containers[identifier];
|
|
48
|
+
|
|
49
|
+
// Get the variant id
|
|
50
|
+
const { variantId } = container?.parentPermissionable || {};
|
|
51
|
+
|
|
52
|
+
// Get accepts types of content types for this container
|
|
53
|
+
const acceptTypes = containerStructures.map((structure) => structure.contentTypeVar).join(',');
|
|
54
|
+
|
|
55
|
+
// Get the contentlets for "this" container
|
|
56
|
+
const contentlets = containers[identifier].contentlets[`uuid-${uuid}`];
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
...containers[identifier].container,
|
|
60
|
+
acceptTypes,
|
|
61
|
+
contentlets,
|
|
62
|
+
variantId
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Combine classes into a single string.
|
|
68
|
+
*
|
|
69
|
+
* @param {string[]} classes
|
|
70
|
+
* @returns {string} Combined classes
|
|
71
|
+
*/
|
|
72
|
+
export const combineClasses = (classes: string[]) => classes.filter(Boolean).join(' ');
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the start and end classes for the column based on the left offset and width.
|
|
76
|
+
*
|
|
77
|
+
* @param {number} start
|
|
78
|
+
* @param {number} end
|
|
79
|
+
* @returns {Object} Start and end classes
|
|
80
|
+
*/
|
|
81
|
+
export const getPositionStyleClasses = (start: number, end: number) => {
|
|
82
|
+
const startClass = startClassMap[start];
|
|
83
|
+
const endClass = endClassMap[end];
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
startClass,
|
|
87
|
+
endClass
|
|
88
|
+
};
|
|
89
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react-jsx",
|
|
4
|
+
"allowJs": false,
|
|
5
|
+
"esModuleInterop": false,
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"strict": true
|
|
8
|
+
},
|
|
9
|
+
"files": [],
|
|
10
|
+
"include": [],
|
|
11
|
+
"references": [
|
|
12
|
+
{
|
|
13
|
+
"path": "./tsconfig.lib.json"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"path": "./tsconfig.spec.json"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"extends": "../../../tsconfig.base.json"
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"types": ["node"]
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"../../../node_modules/@nrwl/react/typings/cssmodule.d.ts",
|
|
9
|
+
"../../../node_modules/@nrwl/react/typings/image.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"jest.config.ts",
|
|
13
|
+
"src/**/*.spec.ts",
|
|
14
|
+
"src/**/*.test.ts",
|
|
15
|
+
"src/**/*.spec.tsx",
|
|
16
|
+
"src/**/*.test.tsx",
|
|
17
|
+
"src/**/*.spec.js",
|
|
18
|
+
"src/**/*.test.js",
|
|
19
|
+
"src/**/*.spec.jsx",
|
|
20
|
+
"src/**/*.test.jsx"
|
|
21
|
+
],
|
|
22
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node"]
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"jest.config.ts",
|
|
10
|
+
"src/**/*.test.ts",
|
|
11
|
+
"src/**/*.spec.ts",
|
|
12
|
+
"src/**/*.test.tsx",
|
|
13
|
+
"src/**/*.spec.tsx",
|
|
14
|
+
"src/**/*.test.js",
|
|
15
|
+
"src/**/*.spec.js",
|
|
16
|
+
"src/**/*.test.jsx",
|
|
17
|
+
"src/**/*.spec.jsx",
|
|
18
|
+
"src/**/*.d.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|