@dotcms/react 1.2.5 → 1.2.6-next.2

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 (49) hide show
  1. package/README.md +71 -17
  2. package/_virtual/_style-inject.esm.js +30 -0
  3. package/index.esm.js +9 -7097
  4. package/index.server.d.ts +1 -0
  5. package/index.server.esm.js +8 -0
  6. package/lib/next/components/Column/Column.esm.js +48 -0
  7. package/lib/next/components/Column/Column.module.css.esm.js +8 -0
  8. package/lib/next/components/Container/Container.esm.js +54 -0
  9. package/lib/next/components/Container/ContainerFallbacks.esm.js +60 -0
  10. package/lib/next/components/Contentlet/Contentlet.esm.js +87 -0
  11. package/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.esm.js +46 -0
  12. package/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.esm.js +179 -0
  13. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Code.esm.js +37 -0
  14. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/DotContent.esm.js +47 -0
  15. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/GridBlock.esm.js +44 -0
  16. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Image.esm.js +22 -0
  17. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Lists.esm.js +43 -0
  18. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/NoComponentProvided.esm.js +40 -0
  19. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Table.esm.js +53 -0
  20. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Texts.esm.js +157 -0
  21. package/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Video.esm.js +42 -0
  22. package/lib/next/components/DotCMSEditableText/DotCMSEditableText.esm.js +181 -0
  23. package/lib/next/components/DotCMSEditableText/utils.esm.js +12 -0
  24. package/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.esm.js +42 -0
  25. package/lib/next/components/DotCMSLayoutBody/DotCMSPageProvider.esm.js +30 -0
  26. package/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.esm.js +43 -0
  27. package/lib/next/components/DotCMSShow/DotCMSShow.esm.js +49 -0
  28. package/lib/next/components/FallbackComponent/FallbackComponent.esm.js +54 -0
  29. package/lib/next/components/Row/Row.esm.js +30 -0
  30. package/lib/next/components/Row/Row.module.css.esm.js +8 -0
  31. package/lib/next/contexts/DotCMSPageContext.esm.js +16 -0
  32. package/lib/next/hooks/useAISearch.esm.js +119 -0
  33. package/lib/next/hooks/useCheckVisibleContent.esm.js +40 -0
  34. package/lib/next/hooks/useDotCMSShowWhen.esm.js +42 -0
  35. package/lib/next/hooks/useEditableDotCMSPage.esm.js +131 -0
  36. package/lib/next/hooks/useIsDevMode.esm.js +35 -0
  37. package/lib/next/hooks/useStyleEditorSchemas.esm.js +15 -0
  38. package/lib/next/utils/buildSlots.esm.js +43 -0
  39. package/package.json +3 -2
  40. package/src/index.d.ts +1 -0
  41. package/src/index.server.d.ts +11 -0
  42. package/src/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.d.ts +2 -1
  43. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.d.ts +2 -1
  44. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/DotContent.d.ts +2 -1
  45. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/GridBlock.d.ts +19 -0
  46. package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +20 -1
  47. package/src/lib/next/components/DotCMSLayoutBody/DotCMSPageProvider.d.ts +18 -0
  48. package/src/lib/next/contexts/DotCMSPageContext.d.ts +3 -0
  49. package/src/lib/next/utils/buildSlots.d.ts +24 -0
@@ -0,0 +1,43 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * ListItem component represents a list item in a block editor.
5
+ *
6
+ * @param children - The content of the list item.
7
+ * @returns The rendered list item element.
8
+ */
9
+ const ListItem = ({
10
+ children
11
+ }) => {
12
+ return jsx("li", {
13
+ children: children
14
+ });
15
+ };
16
+ /**
17
+ * Renders an ordered list component.
18
+ *
19
+ * @param children - The content to be rendered inside the ordered list.
20
+ * @returns The ordered list component.
21
+ */
22
+ const OrderedList = ({
23
+ children
24
+ }) => {
25
+ return jsx("ol", {
26
+ children: children
27
+ });
28
+ };
29
+ /**
30
+ * Renders a bullet list component.
31
+ *
32
+ * @param children - The content of the bullet list.
33
+ * @returns The rendered bullet list component.
34
+ */
35
+ const BulletList = ({
36
+ children
37
+ }) => {
38
+ return jsx("ul", {
39
+ children: children
40
+ });
41
+ };
42
+
43
+ export { BulletList, ListItem, OrderedList };
@@ -0,0 +1,40 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ const NoComponentProvided = ({
4
+ contentType
5
+ }) => {
6
+ const style = {
7
+ backgroundColor: '#fffaf0',
8
+ color: '#333',
9
+ padding: '1rem',
10
+ borderRadius: '0.5rem',
11
+ marginBottom: '1rem',
12
+ marginTop: '1rem',
13
+ border: '1px solid #ed8936'
14
+ };
15
+ return jsxs("div", {
16
+ "data-testid": "no-component-provided",
17
+ style: style,
18
+ children: [jsx("strong", {
19
+ style: {
20
+ color: '#c05621'
21
+ },
22
+ children: "Dev Warning"
23
+ }), ": No component or custom renderer provided for content type", jsx("strong", {
24
+ style: {
25
+ color: '#c05621'
26
+ },
27
+ children: contentType || 'Unknown'
28
+ }), ".", jsx("br", {}), "Please refer to the", jsx("a", {
29
+ href: "https://dev.dotcms.com/docs/block-editor",
30
+ target: "_blank",
31
+ rel: "noopener noreferrer",
32
+ style: {
33
+ color: '#c05621'
34
+ },
35
+ children: "Block Editor Custom Renderers Documentation"
36
+ }), ' ', "for guidance."]
37
+ });
38
+ };
39
+
40
+ export { NoComponentProvided };
@@ -0,0 +1,53 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Renders a table component for the Block Editor.
5
+ *
6
+ * @param content - The content of the table.
7
+ * @param blockEditorItem - The Block Editor item component.
8
+ */
9
+ const TableRenderer = ({
10
+ content,
11
+ blockEditorItem
12
+ }) => {
13
+ const BlockEditorItemComponent = blockEditorItem;
14
+ const renderTableContent = node => {
15
+ var _node$content;
16
+ return jsx(BlockEditorItemComponent, {
17
+ content: (_node$content = node.content) != null ? _node$content : []
18
+ });
19
+ };
20
+ return jsxs("table", {
21
+ children: [jsx("thead", {
22
+ children: content.slice(0, 1).map((rowNode, rowIndex) => {
23
+ var _rowNode$content;
24
+ return jsx("tr", {
25
+ children: (_rowNode$content = rowNode.content) == null ? void 0 : _rowNode$content.map((cellNode, cellIndex) => {
26
+ var _cellNode$attrs, _cellNode$attrs2;
27
+ return jsx("th", {
28
+ colSpan: Number(((_cellNode$attrs = cellNode.attrs) == null ? void 0 : _cellNode$attrs.colspan) || 1),
29
+ rowSpan: Number(((_cellNode$attrs2 = cellNode.attrs) == null ? void 0 : _cellNode$attrs2.rowspan) || 1),
30
+ children: renderTableContent(cellNode)
31
+ }, `${cellNode.type}-${cellIndex}`);
32
+ })
33
+ }, `${rowNode.type}-${rowIndex}`);
34
+ })
35
+ }), jsx("tbody", {
36
+ children: content.slice(1).map((rowNode, rowIndex) => {
37
+ var _rowNode$content2;
38
+ return jsx("tr", {
39
+ children: (_rowNode$content2 = rowNode.content) == null ? void 0 : _rowNode$content2.map((cellNode, cellIndex) => {
40
+ var _cellNode$attrs3, _cellNode$attrs4;
41
+ return jsx("td", {
42
+ colSpan: Number(((_cellNode$attrs3 = cellNode.attrs) == null ? void 0 : _cellNode$attrs3.colspan) || 1),
43
+ rowSpan: Number(((_cellNode$attrs4 = cellNode.attrs) == null ? void 0 : _cellNode$attrs4.rowspan) || 1),
44
+ children: renderTableContent(cellNode)
45
+ }, `${cellNode.type}-${cellIndex}`);
46
+ })
47
+ }, `${rowNode.type}-${rowIndex}`);
48
+ })
49
+ })]
50
+ });
51
+ };
52
+
53
+ export { TableRenderer };
@@ -0,0 +1,157 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Renders the text in bold.
5
+ *
6
+ * @param children - The content to be rendered in bold.
7
+ */
8
+ const Bold = ({
9
+ children
10
+ }) => jsx("strong", {
11
+ children: children
12
+ });
13
+ /**
14
+ * Renders the text in italic format.
15
+ *
16
+ * @param children - The content to be rendered in italic.
17
+ */
18
+ const Italic = ({
19
+ children
20
+ }) => jsx("em", {
21
+ children: children
22
+ });
23
+ /**
24
+ * Renders a strike-through text.
25
+ *
26
+ * @param children - The content to be rendered within the strike-through element.
27
+ */
28
+ const Strike = ({
29
+ children
30
+ }) => jsx("s", {
31
+ children: children
32
+ });
33
+ /**
34
+ * Renders an underline element for the given children.
35
+ *
36
+ * @param children - The content to be underlined.
37
+ */
38
+ const Underline = ({
39
+ children
40
+ }) => jsx("u", {
41
+ children: children
42
+ });
43
+ /**
44
+ * Renders a paragraph element.
45
+ *
46
+ * @param children - The content of the paragraph.
47
+ * @param attrs - The style attributes for the paragraph.
48
+ * @returns The rendered paragraph element.
49
+ */
50
+ const Paragraph = ({
51
+ children,
52
+ node
53
+ }) => {
54
+ const attrs = (node == null ? void 0 : node.attrs) || {};
55
+ return jsx("p", {
56
+ style: attrs,
57
+ children: children
58
+ });
59
+ };
60
+ /**
61
+ * Renders a link component.
62
+ *
63
+ * @param children - The content of the link.
64
+ * @param attrs - The attributes to be applied to the link.
65
+ * @returns The rendered link component.
66
+ */
67
+ const Link = ({
68
+ children,
69
+ attrs
70
+ }) => {
71
+ return jsx("a", Object.assign({}, attrs, {
72
+ children: children
73
+ }));
74
+ };
75
+ /**
76
+ * Renders a heading element with the specified level.
77
+ *
78
+ * @param children - The content of the heading.
79
+ * @param attrs - The attributes for the heading.
80
+ * @returns The rendered heading element.
81
+ */
82
+ const Heading = ({
83
+ children,
84
+ node
85
+ }) => {
86
+ const attrs = (node == null ? void 0 : node.attrs) || {};
87
+ const level = attrs.level || 1;
88
+ const Tag = `h${level}`;
89
+ return jsx(Tag, {
90
+ children: children
91
+ });
92
+ };
93
+ /**
94
+ * Renders the superscript text.
95
+ *
96
+ * @param children - The content to be rendered as superscript.
97
+ */
98
+ const Superscript = ({
99
+ children
100
+ }) => jsx("sup", {
101
+ children: children
102
+ });
103
+ /**
104
+ * Renders a subscript element.
105
+ *
106
+ * @param children - The content to be rendered as subscript.
107
+ */
108
+ const Subscript = ({
109
+ children
110
+ }) => jsx("sub", {
111
+ children: children
112
+ });
113
+ const nodeMarks = {
114
+ bold: Bold,
115
+ link: Link,
116
+ italic: Italic,
117
+ strike: Strike,
118
+ subscript: Subscript,
119
+ underline: Underline,
120
+ superscript: Superscript
121
+ };
122
+ const defaultMark = {
123
+ type: '',
124
+ attrs: {}
125
+ };
126
+ /**
127
+ * Renders a text block with optional marks.
128
+ *
129
+ * @param props - The props for the TextBlock component.
130
+ * @returns The rendered text block.
131
+ */
132
+ const TextBlock = (props = {}) => {
133
+ const {
134
+ marks = [],
135
+ text
136
+ } = props;
137
+ const mark = marks[0] || defaultMark;
138
+ const textProps = Object.assign({}, props, {
139
+ marks: marks.slice(1)
140
+ });
141
+ const Component = nodeMarks[mark == null ? void 0 : mark.type];
142
+ // In React, class is not a valid attribute name, so we need to rename it to className
143
+ if (mark.attrs) {
144
+ mark.attrs.className = mark.attrs.class;
145
+ delete mark.attrs.class;
146
+ }
147
+ if (!Component) {
148
+ return text;
149
+ }
150
+ return jsx(Component, {
151
+ type: mark.type,
152
+ attrs: mark.attrs,
153
+ children: jsx(TextBlock, Object.assign({}, textProps))
154
+ });
155
+ };
156
+
157
+ export { Bold, Heading, Italic, Link, Paragraph, Strike, Subscript, Superscript, TextBlock, Underline };
@@ -0,0 +1,42 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ /**
4
+ * Renders a video component for displaying videos.
5
+ *
6
+ * @param props - The properties for the video component.
7
+ * @returns The rendered video component.
8
+ */
9
+ const DotCMSVideo = ({
10
+ node
11
+ }) => {
12
+ const {
13
+ data,
14
+ src,
15
+ mimeType,
16
+ width,
17
+ height
18
+ } = node.attrs;
19
+ const poster = data == null ? void 0 : data.thumbnail;
20
+ const posterAttribute = poster ? {
21
+ poster
22
+ } : {};
23
+ return jsxs("video", Object.assign({
24
+ controls: true,
25
+ preload: "metadata",
26
+ width: width,
27
+ height: height
28
+ }, posterAttribute, {
29
+ children: [jsx("track", {
30
+ default: true,
31
+ kind: "captions",
32
+ srcLang: "en"
33
+ }), jsx("source", {
34
+ src: src,
35
+ type: mimeType
36
+ }), "Your browser does not support the ", jsx("code", {
37
+ children: "video"
38
+ }), " element."]
39
+ }));
40
+ };
41
+
42
+ export { DotCMSVideo };
@@ -0,0 +1,181 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { Editor } from '@tinymce/tinymce-react';
3
+ import { useRef, useState, useEffect } from 'react';
4
+ import { UVE_MODE, DotCMSUVEAction } from '@dotcms/types';
5
+ import { __DOTCMS_UVE_EVENT__ } from '@dotcms/types/internal';
6
+ import { getUVEState, sendMessageToUVE } from '@dotcms/uve';
7
+ import { __TINYMCE_PATH_ON_DOTCMS__ } from '@dotcms/uve/internal';
8
+ import { TINYMCE_CONFIG } from './utils.esm.js';
9
+
10
+ /**
11
+ * Allows inline edit content pulled from dotCMS API using TinyMCE editor
12
+ *
13
+ * @export
14
+ * @component
15
+ * @param {Readonly<DotCMSEditableTextProps>} props {
16
+ * mode = 'plain',
17
+ * format = 'text',
18
+ * contentlet,
19
+ * fieldName = ''
20
+ * }
21
+ * @example
22
+ * ```javascript
23
+ * import { DotCMSEditableText } from '@dotcms/react';
24
+ *
25
+ * const MyContentletWithTitle = ({ contentlet }) => (
26
+ * <h2>
27
+ * <DotCMSEditableText
28
+ * contentlet={contentlet}
29
+ * fieldName="title"
30
+ * mode='full'
31
+ * format='text'/>
32
+ * </h2>
33
+ * );
34
+ * ```
35
+ * @returns {JSX.Element} A component to edit content inline
36
+ */
37
+ function DotCMSEditableText({
38
+ mode = 'plain',
39
+ format = 'text',
40
+ contentlet,
41
+ fieldName
42
+ }) {
43
+ const editorRef = useRef(null);
44
+ const [scriptSrc, setScriptSrc] = useState('');
45
+ const [initEditor, setInitEditor] = useState(false);
46
+ const [content, setContent] = useState((contentlet == null ? void 0 : contentlet[fieldName]) || '');
47
+ useEffect(() => {
48
+ setContent((contentlet == null ? void 0 : contentlet[fieldName]) || '');
49
+ }, [fieldName, contentlet]);
50
+ useEffect(() => {
51
+ var _state$dotCMSHost, _editorRef$current;
52
+ const state = getUVEState();
53
+ setInitEditor((state == null ? void 0 : state.mode) === UVE_MODE.EDIT && !!(state != null && (_state$dotCMSHost = state.dotCMSHost) != null && _state$dotCMSHost.length));
54
+ if (!contentlet || !fieldName) {
55
+ console.error('[DotCMSEditableText]: contentlet or fieldName is missing', 'Ensure that all needed props are passed to view and edit the content');
56
+ return;
57
+ }
58
+ if (state && state.mode !== UVE_MODE.EDIT) {
59
+ console.warn('[DotCMSEditableText]: TinyMCE is not available in the current mode');
60
+ return;
61
+ }
62
+ if (!(state != null && state.dotCMSHost)) {
63
+ console.warn('[DotCMSEditableText]: The `dotCMSHost` parameter is not defined. Check that the UVE is sending the correct parameters.');
64
+ return;
65
+ }
66
+ const createURL = new URL(__TINYMCE_PATH_ON_DOTCMS__, state.dotCMSHost);
67
+ setScriptSrc(createURL.toString());
68
+ const content = (contentlet == null ? void 0 : contentlet[fieldName]) || '';
69
+ (_editorRef$current = editorRef.current) == null || _editorRef$current.setContent(content, {
70
+ format
71
+ });
72
+ }, [format, fieldName, contentlet, content]);
73
+ useEffect(() => {
74
+ var _getUVEState;
75
+ if (((_getUVEState = getUVEState()) == null ? void 0 : _getUVEState.mode) !== UVE_MODE.EDIT) {
76
+ return;
77
+ }
78
+ const onMessage = ({
79
+ data
80
+ }) => {
81
+ const {
82
+ name,
83
+ payload
84
+ } = data;
85
+ if (name !== __DOTCMS_UVE_EVENT__.UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS) {
86
+ return;
87
+ }
88
+ const {
89
+ oldInode,
90
+ inode
91
+ } = payload;
92
+ const currentInode = contentlet.inode;
93
+ const shouldFocus = currentInode === oldInode || currentInode === inode;
94
+ if (shouldFocus) {
95
+ var _editorRef$current2;
96
+ (_editorRef$current2 = editorRef.current) == null || _editorRef$current2.focus();
97
+ }
98
+ };
99
+ window.addEventListener('message', onMessage);
100
+ return () => {
101
+ window.removeEventListener('message', onMessage);
102
+ };
103
+ }, [contentlet == null ? void 0 : contentlet.inode]);
104
+ const onMouseDown = event => {
105
+ var _editorRef$current3;
106
+ const {
107
+ onNumberOfPages = 1
108
+ } = contentlet;
109
+ const {
110
+ inode,
111
+ languageId: language
112
+ } = contentlet;
113
+ if (Number(onNumberOfPages) <= 1 || (_editorRef$current3 = editorRef.current) != null && _editorRef$current3.hasFocus()) {
114
+ return;
115
+ }
116
+ event.stopPropagation();
117
+ event.preventDefault();
118
+ sendMessageToUVE({
119
+ action: DotCMSUVEAction.COPY_CONTENTLET_INLINE_EDITING,
120
+ payload: {
121
+ dataset: {
122
+ inode,
123
+ language,
124
+ fieldName
125
+ }
126
+ }
127
+ });
128
+ };
129
+ const onFocusOut = () => {
130
+ var _editorRef$current4, _editorRef$current5;
131
+ const editedContent = ((_editorRef$current4 = editorRef.current) == null ? void 0 : _editorRef$current4.getContent({
132
+ format: format
133
+ })) || '';
134
+ const {
135
+ inode,
136
+ languageId: langId
137
+ } = contentlet;
138
+ if (!((_editorRef$current5 = editorRef.current) != null && _editorRef$current5.isDirty()) || !didContentChange(editedContent)) {
139
+ return;
140
+ }
141
+ sendMessageToUVE({
142
+ action: DotCMSUVEAction.UPDATE_CONTENTLET_INLINE_EDITING,
143
+ payload: {
144
+ content: editedContent,
145
+ dataset: {
146
+ inode,
147
+ langId,
148
+ fieldName
149
+ }
150
+ }
151
+ });
152
+ };
153
+ const didContentChange = editedContent => {
154
+ return content !== editedContent;
155
+ };
156
+ if (!initEditor) {
157
+ // We can let the user pass the Child Component and create a root to get the HTML for the editor
158
+ return jsx("span", {
159
+ dangerouslySetInnerHTML: {
160
+ __html: content
161
+ }
162
+ });
163
+ }
164
+ return jsx("div", {
165
+ style: {
166
+ outline: '2px solid #006ce7',
167
+ borderRadius: '4px'
168
+ },
169
+ children: jsx(Editor, {
170
+ tinymceScriptSrc: scriptSrc,
171
+ inline: true,
172
+ onInit: (_, editor) => editorRef.current = editor,
173
+ init: TINYMCE_CONFIG[mode],
174
+ initialValue: content,
175
+ onMouseDown: onMouseDown,
176
+ onFocusOut: onFocusOut
177
+ })
178
+ });
179
+ }
180
+
181
+ export { DotCMSEditableText };
@@ -0,0 +1,12 @@
1
+ import { __DEFAULT_TINYMCE_CONFIG__, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__ } from '@dotcms/uve/internal';
2
+
3
+ const DEFAULT_TINYMCE_CONFIG = Object.assign({}, __DEFAULT_TINYMCE_CONFIG__, {
4
+ licenseKey: 'gpl' // Using self-hosted license key
5
+ });
6
+ const TINYMCE_CONFIG = {
7
+ full: Object.assign({}, DEFAULT_TINYMCE_CONFIG, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__.full),
8
+ plain: Object.assign({}, DEFAULT_TINYMCE_CONFIG, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__.plain),
9
+ minimal: Object.assign({}, DEFAULT_TINYMCE_CONFIG, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__.minimal)
10
+ };
11
+
12
+ export { TINYMCE_CONFIG };
@@ -0,0 +1,42 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { ErrorMessage } from './components/ErrorMessage.esm.js';
3
+ import { DotCMSPageProvider } from './DotCMSPageProvider.esm.js';
4
+ import { Row } from '../Row/Row.esm.js';
5
+
6
+ /**
7
+ * DotCMSLayoutBody component renders the layout body for a DotCMS page.
8
+ *
9
+ * It utilizes the dotCMS page asset's layout body to render the page body.
10
+ * If the layout body does not exist, it renders an error message in the mode is `development`.
11
+ *
12
+ * @public
13
+ * @component
14
+ * @param {Object} props - Component properties.
15
+ * @param {DotCMSPageAsset} props.page - The DotCMS page asset containing the layout information.
16
+ * @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] - mapping of custom components for content rendering.
17
+ * @param {DotCMSPageRendererMode} [props.mode='production'] - The renderer mode; defaults to 'production'. Alternate modes might trigger different behaviors.
18
+ * @param {Record<string, ReactNode>} [props.slots] - Pre-rendered server component nodes keyed by contentlet identifier.
19
+ *
20
+ * @returns {JSX.Element} The rendered DotCMS page body or an error message if the layout body is missing.
21
+ *
22
+ */
23
+ const DotCMSLayoutBody = ({
24
+ page,
25
+ components: _components = {},
26
+ mode: _mode = 'production',
27
+ slots: _slots = {}
28
+ }) => {
29
+ var _page$layout;
30
+ const dotCMSPageBody = page == null || (_page$layout = page.layout) == null ? void 0 : _page$layout.body;
31
+ return jsx(DotCMSPageProvider, {
32
+ page: page,
33
+ components: _components,
34
+ mode: _mode,
35
+ slots: _slots,
36
+ children: dotCMSPageBody ? dotCMSPageBody.rows.map((row, index) => jsx(Row, {
37
+ row: row
38
+ }, index)) : jsx(ErrorMessage, {})
39
+ });
40
+ };
41
+
42
+ export { DotCMSLayoutBody };
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { DotCMSPageContext } from '../../contexts/DotCMSPageContext.esm.js';
4
+
5
+ /**
6
+ * @internal
7
+ *
8
+ * Client boundary that provides the DotCMS page context to the layout tree.
9
+ * Keeping this separate from DotCMSLayoutBody allows the layout to remain
10
+ * a server component while only the context provider runs on the client.
11
+ */
12
+ function DotCMSPageProvider({
13
+ page,
14
+ components,
15
+ mode,
16
+ slots,
17
+ children
18
+ }) {
19
+ return jsx(DotCMSPageContext.Provider, {
20
+ value: {
21
+ pageAsset: page,
22
+ userComponents: components,
23
+ mode,
24
+ slots
25
+ },
26
+ children: children
27
+ });
28
+ }
29
+
30
+ export { DotCMSPageProvider };
@@ -0,0 +1,43 @@
1
+ "use client";
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { useEffect } from 'react';
4
+ import { useIsDevMode } from '../../../hooks/useIsDevMode.esm.js';
5
+
6
+ /**
7
+ * Error message component for when the page body is missing
8
+ *
9
+ * @return {JSX.Element} Error message component
10
+ */
11
+ const ErrorMessage = () => {
12
+ const isDevMode = useIsDevMode();
13
+ useEffect(() => {
14
+ console.warn('Missing required layout.body property in page');
15
+ }, []);
16
+ return isDevMode && jsxs("div", {
17
+ "data-testid": "error-message",
18
+ style: {
19
+ padding: '1rem',
20
+ border: '1px solid #e0e0e0',
21
+ borderRadius: '4px'
22
+ },
23
+ children: [jsxs("p", {
24
+ style: {
25
+ margin: '0 0 0.5rem',
26
+ color: '#666'
27
+ },
28
+ children: ["The ", jsx("code", {
29
+ children: "page"
30
+ }), " is missing the required ", jsx("code", {
31
+ children: "layout.body"
32
+ }), " property."]
33
+ }), jsx("p", {
34
+ style: {
35
+ margin: 0,
36
+ color: '#666'
37
+ },
38
+ children: "Make sure the page asset is properly loaded and includes a layout configuration."
39
+ })]
40
+ });
41
+ };
42
+
43
+ export { ErrorMessage };
@@ -0,0 +1,49 @@
1
+ import { UVE_MODE } from '@dotcms/types';
2
+ import { useDotCMSShowWhen } from '../../hooks/useDotCMSShowWhen.esm.js';
3
+
4
+ /**
5
+ * DotCMSShow component is used to conditionally render its children
6
+ * based on the Universal Visual Editor (UVE) mode. It checks if the UVE
7
+ * is in a specified mode and only renders its children in that case.
8
+ *
9
+ * @param {Object} props - The component props.
10
+ * @param {React.ReactNode} props.children - The children to be rendered when the condition is met.
11
+ * @param {UVE_MODE} [props.when=UVE_MODE.EDIT] - The UVE mode in which the children should be rendered.
12
+ * @returns {React.ReactNode | null} The children if the current UVE mode matches the `when` prop, otherwise null.
13
+ *
14
+ * @example
15
+ * // Basic usage: Render content only in edit mode
16
+ * <DotCMSShow when={UVE_MODE.EDIT}>
17
+ * <div>Edit Mode Content</div>
18
+ * </DotCMSShow>
19
+ *
20
+ * // This will render <div>Edit Mode Content</div> only if the UVE is in edit mode.
21
+ *
22
+ * @example
23
+ * // Render content in preview mode
24
+ * <DotCMSShow when={UVE_MODE.PREVIEW}>
25
+ * <MyCustomPreviewComponent />
26
+ * </DotCMSShow>
27
+ *
28
+ * // MyCustomPreviewComponent will only be rendered if the UVE is in preview mode.
29
+ *
30
+ * @example
31
+ * // Render content in live mode
32
+ * <DotCMSShow when={UVE_MODE.LIVE}>
33
+ * <LiveContentComponent />
34
+ * </DotCMSShow>
35
+ *
36
+ * // LiveContentComponent will only be rendered if the UVE is in live mode.
37
+ */
38
+ const DotCMSShow = ({
39
+ children,
40
+ when: _when = UVE_MODE.EDIT
41
+ }) => {
42
+ const show = useDotCMSShowWhen(_when);
43
+ if (!show) {
44
+ return null;
45
+ }
46
+ return children;
47
+ };
48
+
49
+ export { DotCMSShow };