@dotcms/react 0.0.1-alpha.37 → 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.
Files changed (66) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintrc.json +18 -0
  3. package/jest.config.ts +11 -0
  4. package/package.json +4 -8
  5. package/project.json +56 -0
  6. package/src/lib/components/BlockEditorRenderer/BlockEditorRenderer.spec.tsx +51 -0
  7. package/src/lib/components/BlockEditorRenderer/{BlockEditorRenderer.d.ts → BlockEditorRenderer.tsx} +16 -2
  8. package/src/lib/components/BlockEditorRenderer/blocks/{Code.d.ts → Code.tsx} +14 -2
  9. package/src/lib/components/BlockEditorRenderer/blocks/{Contentlet.d.ts → Contentlet.tsx} +21 -1
  10. package/src/lib/components/BlockEditorRenderer/blocks/Image.tsx +18 -0
  11. package/src/lib/components/BlockEditorRenderer/blocks/{Lists.d.ts → Lists.tsx} +12 -3
  12. package/src/lib/components/BlockEditorRenderer/blocks/Table.tsx +60 -0
  13. package/src/lib/components/BlockEditorRenderer/blocks/Texts.tsx +126 -0
  14. package/src/lib/components/BlockEditorRenderer/blocks/Video.tsx +26 -0
  15. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.spec.tsx +634 -0
  16. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.tsx +146 -0
  17. package/src/lib/components/Column/Column.module.css +99 -0
  18. package/src/lib/components/Column/Column.spec.tsx +78 -0
  19. package/src/lib/components/Column/Column.tsx +59 -0
  20. package/src/lib/components/Container/Container.module.css +7 -0
  21. package/src/lib/components/Container/Container.spec.tsx +155 -0
  22. package/src/lib/components/Container/Container.tsx +122 -0
  23. package/src/lib/components/DotEditableText/DotEditableText.spec.tsx +232 -0
  24. package/src/lib/components/DotEditableText/DotEditableText.tsx +168 -0
  25. package/src/lib/components/DotEditableText/utils.ts +82 -0
  26. package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +7 -0
  27. package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +46 -0
  28. package/src/lib/components/DotcmsLayout/{DotcmsLayout.d.ts → DotcmsLayout.tsx} +18 -2
  29. package/src/lib/components/PageProvider/PageProvider.module.css +7 -0
  30. package/src/lib/components/PageProvider/PageProvider.spec.tsx +59 -0
  31. package/src/lib/components/PageProvider/{PageProvider.d.ts → PageProvider.tsx} +10 -1
  32. package/src/lib/components/Row/Row.module.css +5 -0
  33. package/src/lib/components/Row/Row.spec.tsx +92 -0
  34. package/src/lib/components/Row/Row.tsx +52 -0
  35. package/src/lib/contexts/PageContext.tsx +10 -0
  36. package/src/lib/hooks/useDotcmsEditor.spec.ts +176 -0
  37. package/src/lib/hooks/useDotcmsEditor.ts +94 -0
  38. package/src/lib/hooks/useDotcmsPageContext.spec.tsx +47 -0
  39. package/src/lib/hooks/{useDotcmsPageContext.d.ts → useDotcmsPageContext.tsx} +7 -1
  40. package/src/lib/mocks/mockPageContext.tsx +113 -0
  41. package/src/lib/models/{blocks.interface.d.ts → blocks.interface.ts} +43 -16
  42. package/src/lib/models/content-node.interface.ts +90 -0
  43. package/src/lib/models/{index.d.ts → index.ts} +5 -2
  44. package/src/lib/utils/utils.ts +89 -0
  45. package/tsconfig.json +20 -0
  46. package/tsconfig.lib.json +23 -0
  47. package/tsconfig.spec.json +20 -0
  48. package/index.esm.d.ts +0 -1
  49. package/index.esm.js +0 -5070
  50. package/src/lib/components/BlockEditorRenderer/blocks/Image.d.ts +0 -8
  51. package/src/lib/components/BlockEditorRenderer/blocks/Table.d.ts +0 -16
  52. package/src/lib/components/BlockEditorRenderer/blocks/Texts.d.ts +0 -71
  53. package/src/lib/components/BlockEditorRenderer/blocks/Video.d.ts +0 -8
  54. package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +0 -12
  55. package/src/lib/components/Column/Column.d.ts +0 -5
  56. package/src/lib/components/Container/Container.d.ts +0 -5
  57. package/src/lib/components/DotEditableText/DotEditableText.d.ts +0 -3
  58. package/src/lib/components/DotEditableText/utils.d.ts +0 -36
  59. package/src/lib/components/Row/Row.d.ts +0 -25
  60. package/src/lib/contexts/PageContext.d.ts +0 -3
  61. package/src/lib/hooks/useDotcmsEditor.d.ts +0 -3
  62. package/src/lib/mocks/mockPageContext.d.ts +0 -8
  63. package/src/lib/models/content-node.interface.d.ts +0 -29
  64. package/src/lib/utils/utils.d.ts +0 -23
  65. /package/src/{index.d.ts → index.ts} +0 -0
  66. /package/src/lib/mocks/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,90 @@
1
+ import { BlockProps } from './blocks.interface';
2
+
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
+ /**
15
+ * Represents a Content Node used by the Block Editor
16
+ *
17
+ * @export
18
+ * @interface ContentNode
19
+ */
20
+ export interface ContentNode {
21
+ type: string;
22
+ content: ContentNode[];
23
+ attrs?: Record<string, string>;
24
+ marks?: Mark[];
25
+ text?: string;
26
+ }
27
+
28
+ /**
29
+ * Represents a Custom Renderer used by the Block Editor Component
30
+ *
31
+ * @export
32
+ * @interface CustomRenderer
33
+ */
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ export type CustomRenderer<T = any> = Record<string, React.FC<T>>;
36
+
37
+ /**
38
+ * Represents a CodeBlock used by the Block Editor Component
39
+ * @export
40
+ * @interface CodeBlockProps
41
+ */
42
+ export type CodeBlockProps = BlockProps & ContentNode;
43
+
44
+ /**
45
+ * Represents a Heading used by the Block Editor Component
46
+ * @export
47
+ * @interface HeadingProps
48
+ */
49
+ export type HeadingProps = BlockProps & ContentNode;
50
+
51
+ /**
52
+ * Represents a Link used by the Block Editor Component
53
+ * @export
54
+ * @interface LinkProps
55
+ */
56
+ export type LinkProps = BlockProps & { attrs?: Mark['attrs'] };
57
+
58
+ /**
59
+ * Represents a Paragraph used by the Block Editor Component
60
+ * @export
61
+ * @interface ParagraphProps
62
+ */
63
+ export type ParagraphProps = BlockProps & ContentNode;
64
+
65
+ /**
66
+ * Represents a DotCMSVideo used by the Block Editor Component
67
+ * @export
68
+ * @interface DotCMSVideoProps
69
+ */
70
+ export type DotCMSVideoProps = ContentNode['attrs'] & {
71
+ data?: Record<string, string>;
72
+ };
73
+
74
+ /**
75
+ * Represents a DotCMSImage used by the Block Editor Component
76
+ * @export
77
+ * @interface DotCMSImageProps
78
+ */
79
+ export type DotCMSImageProps = ContentNode['attrs'] & {
80
+ data?: Record<string, unknown>;
81
+ };
82
+
83
+ /**
84
+ * Represents a DotContent used by the Block Editor Component
85
+ * @export
86
+ * @interface DotContentProps
87
+ */
88
+ export type DotContentProps = ContentNode & {
89
+ customRenderers?: CustomRenderer;
90
+ };
@@ -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
- [key: string]: any;
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";