@dotcms/react 0.0.1-beta.3 → 0.0.1-beta.30

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 (37) hide show
  1. package/README.md +165 -62
  2. package/index.esm.js +49 -2169
  3. package/next.esm.js +943 -249
  4. package/package.json +7 -4
  5. package/src/lib/deprecated/components/DotEditableText/DotEditableText.d.ts +1 -0
  6. package/src/lib/deprecated/components/DotcmsLayout/DotcmsLayout.d.ts +1 -0
  7. package/src/lib/deprecated/mocks/mockPageContext.d.ts +1 -0
  8. package/src/lib/next/__test__/mock.d.ts +2 -1
  9. package/src/lib/next/components/Column/Column.d.ts +1 -1
  10. package/src/lib/next/components/Container/Container.d.ts +1 -1
  11. package/src/lib/next/components/Container/{ContainerFallbakcs.d.ts → ContainerFallbacks.d.ts} +2 -2
  12. package/src/lib/next/components/Contentlet/Contentlet.d.ts +2 -2
  13. package/src/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.d.ts +27 -0
  14. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.d.ts +15 -0
  15. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Code.d.ts +24 -0
  16. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Contentlet.d.ts +14 -0
  17. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Image.d.ts +10 -0
  18. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Lists.d.ts +26 -0
  19. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Table.d.ts +16 -0
  20. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Texts.d.ts +81 -0
  21. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Video.d.ts +10 -0
  22. package/src/lib/next/components/DotCMSEditableText/DotCMSEditableText.d.ts +31 -0
  23. package/src/lib/next/components/DotCMSEditableText/utils.d.ts +36 -0
  24. package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +8 -17
  25. package/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.d.ts +1 -4
  26. package/src/lib/next/components/DotCMSShow/DotCMSShow.d.ts +49 -0
  27. package/src/lib/next/components/FallbackComponent/FallbackComponent.d.ts +6 -6
  28. package/src/lib/next/components/Row/Row.d.ts +1 -1
  29. package/src/lib/next/contexts/DotCMSPageContext.d.ts +2 -3
  30. package/src/lib/next/hooks/useDotCMSShowWhen.d.ts +31 -0
  31. package/src/lib/next/hooks/useEditableDotCMSPage.d.ts +90 -0
  32. package/src/lib/next/hooks/useIsDevMode.d.ts +2 -5
  33. package/src/next.d.ts +5 -0
  34. package/web.url-search-params.size.esm.js +4216 -0
  35. package/es.regexp.to-string.esm.js +0 -1878
  36. package/src/lib/next/types.d.ts +0 -421
  37. package/src/lib/next/utils/index.d.ts +0 -136
package/next.esm.js CHANGED
@@ -1,8 +1,11 @@
1
+ import { s as styleInject } from './web.url-search-params.size.esm.js';
1
2
  import { jsxs, jsx } from 'react/jsx-runtime';
2
3
  import { createContext, useContext, useState, useEffect, useLayoutEffect, useRef, useMemo } from 'react';
3
- import { s as styleInject } from './es.regexp.to-string.esm.js';
4
- import { getUVEState } from '@dotcms/uve';
5
- import { UVE_MODE } from '@dotcms/uve/types';
4
+ import { UVE_MODE, UVEEventType, DotCMSUVEAction } from '@dotcms/types';
5
+ import { getUVEState, initUVE, updateNavigation, createUVESubscription, sendMessageToUVE } from '@dotcms/uve';
6
+ import { DEVELOPMENT_MODE, EMPTY_CONTAINER_STYLE_REACT, getDotContentletAttributes, CUSTOM_NO_COMPONENT, getContainersData, getContentletsInContainer, getDotContainerAttributes, getColumnPositionClasses, combineClasses, __DEFAULT_TINYMCE_CONFIG__, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__, __TINYMCE_PATH_ON_DOTCMS__, isValidBlocks } from '@dotcms/uve/internal';
7
+ import { Editor } from '@tinymce/tinymce-react';
8
+ import { __DOTCMS_UVE_EVENT__, BlockEditorDefaultBlocks } from '@dotcms/types/internal';
6
9
 
7
10
  /**
8
11
  * The `PageContext` is a React context that provides access to the DotCMS page context.
@@ -20,18 +23,15 @@ const DotCMSPageContext = /*#__PURE__*/createContext({
20
23
  * A React hook that determines if the current environment is in development mode.
21
24
  *
22
25
  * The hook returns `true` if either:
23
- * - The context mode (or the optional `renderMode` argument) is set to 'development', or
24
- * - The application is running inside the DotCMS editor (as determined by `isInsideEditor()`).
26
+ * - The application is running inside the DotCMS editor (as determined by `getUVEState()`).
25
27
  *
26
- * @param {DotCMSPageRendererMode} [renderMode] - Optional override for the render mode.
27
28
  * @returns {boolean} - `true` if in development mode or inside the editor; otherwise, `false`.
28
29
  */
29
- const useIsDevMode = renderMode => {
30
+ const useIsDevMode = () => {
30
31
  const {
31
32
  mode
32
33
  } = useContext(DotCMSPageContext);
33
- const effectiveMode = renderMode != null ? renderMode : mode;
34
- const [isDevMode, setIsDevMode] = useState(effectiveMode === 'development');
34
+ const [isDevMode, setIsDevMode] = useState(mode === 'development');
35
35
  useEffect(() => {
36
36
  var _getUVEState;
37
37
  // Inside UVE we rely on the UVE state to determine if we are in development mode
@@ -41,9 +41,8 @@ const useIsDevMode = renderMode => {
41
41
  setIsDevMode(isUVEInEditor);
42
42
  return;
43
43
  }
44
- const effectiveMode = renderMode != null ? renderMode : mode;
45
- setIsDevMode(effectiveMode === 'development');
46
- }, [renderMode, mode]);
44
+ setIsDevMode(mode === DEVELOPMENT_MODE);
45
+ }, [mode]);
47
46
  return isDevMode;
48
47
  };
49
48
 
@@ -52,17 +51,12 @@ const useIsDevMode = renderMode => {
52
51
  *
53
52
  * @return {JSX.Element} Error message component
54
53
  */
55
- const ErrorMessage = ({
56
- mode
57
- }) => {
54
+ const ErrorMessage = () => {
55
+ const isDevMode = useIsDevMode();
58
56
  useEffect(() => {
59
57
  console.warn('Missing required layout.body property in page');
60
58
  }, []);
61
- const isDevMode = useIsDevMode(mode);
62
- if (!isDevMode) {
63
- return null;
64
- }
65
- return jsxs("div", {
59
+ return isDevMode && jsxs("div", {
66
60
  "data-testid": "error-message",
67
61
  style: {
68
62
  padding: '1rem',
@@ -97,207 +91,6 @@ var css_248z = ".Column-module_col-start-1__xylw6 {\n grid-column-start: 1;\n
97
91
  var styles = {"col-start-1":"Column-module_col-start-1__xylw6","col-start-2":"Column-module_col-start-2__Mod81","col-start-3":"Column-module_col-start-3__HHbXB","col-start-4":"Column-module_col-start-4__Uk-Qj","col-start-5":"Column-module_col-start-5__jlV8e","col-start-6":"Column-module_col-start-6__oi8k0","col-start-7":"Column-module_col-start-7__EmPky","col-start-8":"Column-module_col-start-8__hLI1h","col-start-9":"Column-module_col-start-9__Kcv9X","col-start-10":"Column-module_col-start-10__-MOrt","col-start-11":"Column-module_col-start-11__gDEQM","col-start-12":"Column-module_col-start-12__omVX6","col-end-1":"Column-module_col-end-1__Ho2y9","col-end-2":"Column-module_col-end-2__KwFu9","col-end-3":"Column-module_col-end-3__vfbJk","col-end-4":"Column-module_col-end-4__d4pyL","col-end-5":"Column-module_col-end-5__6yPd4","col-end-6":"Column-module_col-end-6__xQpAX","col-end-7":"Column-module_col-end-7__CCF7e","col-end-8":"Column-module_col-end-8__fVWEi","col-end-9":"Column-module_col-end-9__tpIGv","col-end-10":"Column-module_col-end-10__SX75K","col-end-11":"Column-module_col-end-11__9K1zv","col-end-12":"Column-module_col-end-12__oqTiE","col-end-13":"Column-module_col-end-13__L-nK9"};
98
92
  styleInject(css_248z);
99
93
 
100
- const endClassMap = {
101
- 1: 'col-end-1',
102
- 2: 'col-end-2',
103
- 3: 'col-end-3',
104
- 4: 'col-end-4',
105
- 5: 'col-end-5',
106
- 6: 'col-end-6',
107
- 7: 'col-end-7',
108
- 8: 'col-end-8',
109
- 9: 'col-end-9',
110
- 10: 'col-end-10',
111
- 11: 'col-end-11',
112
- 12: 'col-end-12',
113
- 13: 'col-end-13'
114
- };
115
- const startClassMap = {
116
- 1: 'col-start-1',
117
- 2: 'col-start-2',
118
- 3: 'col-start-3',
119
- 4: 'col-start-4',
120
- 5: 'col-start-5',
121
- 6: 'col-start-6',
122
- 7: 'col-start-7',
123
- 8: 'col-start-8',
124
- 9: 'col-start-9',
125
- 10: 'col-start-10',
126
- 11: 'col-start-11',
127
- 12: 'col-start-12'
128
- };
129
- /**
130
- * @internal
131
- *
132
- * Combine classes into a single string.
133
- *
134
- * @param {string[]} classes
135
- * @returns {string} Combined classes
136
- */
137
- const combineClasses = classes => classes.filter(Boolean).join(' ');
138
- /**
139
- * @internal
140
- *
141
- * Calculates and returns the CSS Grid positioning classes for a column based on its configuration.
142
- * Uses a 12-column grid system where columns are positioned using grid-column-start and grid-column-end.
143
- *
144
- * @example
145
- * ```typescript
146
- * const classes = getColumnPositionClasses({
147
- * leftOffset: 1, // Starts at the first column
148
- * width: 6 // Spans 6 columns
149
- * });
150
- * // Returns: { startClass: 'col-start-1', endClass: 'col-end-7' }
151
- * ```
152
- *
153
- * @param {DotPageAssetLayoutColumn} column - Column configuration object
154
- * @param {number} column.leftOffset - Starting position (0-based) in the grid
155
- * @param {number} column.width - Number of columns to span
156
- * @returns {{ startClass: string, endClass: string }} Object containing CSS class names for grid positioning
157
- */
158
- const getColumnPositionClasses = column => {
159
- const {
160
- leftOffset,
161
- width
162
- } = column;
163
- const startClass = startClassMap[leftOffset];
164
- const endClass = endClassMap[leftOffset + width];
165
- return {
166
- startClass,
167
- endClass
168
- };
169
- };
170
- /**
171
- * @internal
172
- *
173
- * Helper function that returns an object containing the dotCMS data attributes.
174
- * @param {DotCMSContentlet} contentlet - The contentlet to get the attributes for
175
- * @param {string} container - The container to get the attributes for
176
- * @returns {DotContentletAttributes} The dotCMS data attributes
177
- */
178
- function getDotContentletAttributes(contentlet, container) {
179
- return {
180
- 'data-dot-identifier': contentlet == null ? void 0 : contentlet.identifier,
181
- 'data-dot-basetype': contentlet == null ? void 0 : contentlet.baseType,
182
- 'data-dot-title': (contentlet == null ? void 0 : contentlet.widgetTitle) || (contentlet == null ? void 0 : contentlet.title),
183
- 'data-dot-inode': contentlet == null ? void 0 : contentlet.inode,
184
- 'data-dot-type': contentlet == null ? void 0 : contentlet.contentType,
185
- 'data-dot-container': container,
186
- 'data-dot-on-number-of-pages': contentlet == null ? void 0 : contentlet.onNumberOfPages
187
- };
188
- }
189
- /**
190
- * @internal
191
- *
192
- * Retrieves container data from a DotCMS page asset using the container reference.
193
- * This function processes the container information and returns a standardized format
194
- * for container editing.
195
- *
196
- * @param {DotCMSPageAsset} dotCMSPageAsset - The page asset containing all containers data
197
- * @param {DotCMSColumnContainer} columContainer - The container reference from the layout
198
- * @throws {Error} When page asset is invalid or container is not found
199
- * @returns {EditableContainerData} Formatted container data for editing
200
- *
201
- * @example
202
- * const containerData = getContainersData(pageAsset, containerRef);
203
- * // Returns: { uuid: '123', identifier: 'cont1', acceptTypes: 'type1,type2', maxContentlets: 5 }
204
- */
205
- const getContainersData = (dotCMSPageAsset, columContainer) => {
206
- var _containerStructures$, _container$parentPerm, _container$maxContent;
207
- const {
208
- identifier,
209
- uuid
210
- } = columContainer;
211
- const dotContainer = dotCMSPageAsset.containers[identifier];
212
- if (!dotContainer) {
213
- return null;
214
- }
215
- const {
216
- containerStructures,
217
- container
218
- } = dotContainer;
219
- const acceptTypes = (_containerStructures$ = containerStructures == null ? void 0 : containerStructures.map(structure => structure.contentTypeVar).join(',')) != null ? _containerStructures$ : '';
220
- const variantId = container == null || (_container$parentPerm = container.parentPermissionable) == null ? void 0 : _container$parentPerm.variantId;
221
- const maxContentlets = (_container$maxContent = container == null ? void 0 : container.maxContentlets) != null ? _container$maxContent : 0;
222
- const path = container == null ? void 0 : container.path;
223
- return {
224
- uuid,
225
- variantId,
226
- acceptTypes,
227
- maxContentlets,
228
- identifier: path != null ? path : identifier
229
- };
230
- };
231
- /**
232
- * @internal
233
- *
234
- * Retrieves the contentlets (content items) associated with a specific container.
235
- * Handles different UUID formats and provides warning for missing contentlets.
236
- *
237
- * @param {DotCMSPageAsset} dotCMSPageAsset - The page asset containing all containers data
238
- * @param {DotCMSColumnContainer} columContainer - The container reference from the layout
239
- * @returns {DotCMSContentlet[]} Array of contentlets in the container
240
- *
241
- * @example
242
- * const contentlets = getContentletsInContainer(pageAsset, containerRef);
243
- * // Returns: [{ identifier: 'cont1', ... }, { identifier: 'cont2', ... }]
244
- */
245
- const getContentletsInContainer = (dotCMSPageAsset, columContainer) => {
246
- const {
247
- identifier,
248
- uuid
249
- } = columContainer;
250
- const {
251
- contentlets
252
- } = dotCMSPageAsset.containers[identifier];
253
- const contentletsInContainer = contentlets[`uuid-${uuid}`] || contentlets[`uuid-dotParser_${uuid}`] || [];
254
- if (!contentletsInContainer) {
255
- console.warn(`We couldn't find the contentlets for the container with the identifier ${identifier} and the uuid ${uuid} becareful by adding content to this container.\nWe recommend to change the container in the layout and add the content again.`);
256
- }
257
- return contentletsInContainer;
258
- };
259
- /**
260
- * @internal
261
- *
262
- * Generates the required DotCMS data attributes for a container element.
263
- * These attributes are used by DotCMS for container identification and functionality.
264
- *
265
- * @param {EditableContainerData} params - Container data including uuid, identifier, acceptTypes, and maxContentlets
266
- * @returns {DotContainerAttributes} Object containing all necessary data attributes
267
- *
268
- * @example
269
- * const attributes = getDotContainerAttributes({
270
- * uuid: '123',
271
- * identifier: 'cont1',
272
- * acceptTypes: 'type1,type2',
273
- * maxContentlets: 5
274
- * });
275
- * // Returns: { 'data-dot-object': 'container', 'data-dot-identifier': 'cont1', ... }
276
- */
277
- function getDotContainerAttributes({
278
- uuid,
279
- identifier,
280
- acceptTypes,
281
- maxContentlets
282
- }) {
283
- return {
284
- 'data-dot-object': 'container',
285
- 'data-dot-accept-types': acceptTypes,
286
- 'data-dot-identifier': identifier,
287
- 'data-max-contentlets': maxContentlets.toString(),
288
- 'data-dot-uuid': uuid
289
- };
290
- }
291
-
292
- const EMPTY_CONTAINER_STYLE = {
293
- width: '100%',
294
- backgroundColor: '#ECF0FD',
295
- display: 'flex',
296
- justifyContent: 'center',
297
- alignItems: 'center',
298
- color: '#030E32',
299
- height: '10rem'
300
- };
301
94
  /**
302
95
  * @internal
303
96
  *
@@ -309,7 +102,7 @@ const EMPTY_CONTAINER_STYLE = {
309
102
  * @param {string} props.identifier - Container identifier
310
103
  * @returns {JSX.Element | null} Message about missing container or null in production
311
104
  */
312
- const ContainerNoFound = ({
105
+ const ContainerNotFound = ({
313
106
  identifier
314
107
  }) => {
315
108
  const isDevMode = useIsDevMode();
@@ -324,7 +117,7 @@ const ContainerNoFound = ({
324
117
  }
325
118
  return jsxs("div", {
326
119
  "data-testid": "container-not-found",
327
- style: EMPTY_CONTAINER_STYLE,
120
+ style: EMPTY_CONTAINER_STYLE_REACT,
328
121
  children: ["This container with identifier ", identifier, " was not found."]
329
122
  });
330
123
  };
@@ -342,7 +135,7 @@ const EmptyContainer = dotAttributes => {
342
135
  return null;
343
136
  }
344
137
  return jsx("div", Object.assign({}, dotAttributes, {
345
- style: EMPTY_CONTAINER_STYLE,
138
+ style: EMPTY_CONTAINER_STYLE_REACT,
346
139
  children: jsx("span", {
347
140
  "data-testid": "empty-container-message",
348
141
  children: "This container is empty."
@@ -422,7 +215,7 @@ function FallbackComponent({
422
215
  *
423
216
  * Component to render when there is no component for the content type.
424
217
  *
425
- * @param {DotCMSContentlet} contentType - The content type that couldn't be rendered
218
+ * @param {DotCMSBasicContentlet} contentType - The content type that couldn't be rendered
426
219
  * @return {*}
427
220
  */
428
221
  function NoComponent({
@@ -493,7 +286,7 @@ function CustomComponent({
493
286
  if (UserComponent) {
494
287
  return jsx(UserComponent, Object.assign({}, contentlet));
495
288
  }
496
- const UserNoComponent = userComponents['CustomNoComponent'];
289
+ const UserNoComponent = userComponents[CUSTOM_NO_COMPONENT];
497
290
  return jsx(FallbackComponent, {
498
291
  UserNoComponent: UserNoComponent,
499
292
  contentlet: contentlet
@@ -528,7 +321,7 @@ function Container({
528
321
  const containerData = useMemo(() => getContainersData(pageAsset, container), [pageAsset, container]);
529
322
  const contentlets = useMemo(() => getContentletsInContainer(pageAsset, container), [pageAsset, container]);
530
323
  if (!containerData) {
531
- return jsx(ContainerNoFound, {
324
+ return jsx(ContainerNotFound, {
532
325
  identifier: container.identifier
533
326
  });
534
327
  }
@@ -598,7 +391,7 @@ function Column({
598
391
  const Row = ({
599
392
  row
600
393
  }) => {
601
- const customRowClass = `${row.styleClass || ''} ${styles$1.row}`;
394
+ const customRowClass = combineClasses([row.styleClass || '', styles$1.row]);
602
395
  return jsx("div", {
603
396
  className: "dot-row-container",
604
397
  children: jsx("div", {
@@ -614,28 +407,18 @@ const Row = ({
614
407
  /**
615
408
  * DotCMSLayoutBody component renders the layout body for a DotCMS page.
616
409
  *
617
- * It utilizes the page asset's layout body to render rows using the Row component.
618
- * If the layout body does not exist, it renders an error message.
619
- * It also provides context (DotCMSPageContext) with the page asset, optional user components,
620
- * and the renderer mode to its children.
410
+ * It utilizes the dotCMS page asset's layout body to render the page body.
411
+ * If the layout body does not exist, it renders an error message in the mode is `development`.
621
412
  *
622
413
  * @public
623
414
  * @component
624
415
  * @param {Object} props - Component properties.
625
416
  * @param {DotCMSPageAsset} props.page - The DotCMS page asset containing the layout information.
626
- * @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] - Optional mapping of custom components for content rendering.
417
+ * @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] - mapping of custom components for content rendering.
627
418
  * @param {DotCMSPageRendererMode} [props.mode='production'] - The renderer mode; defaults to 'production'. Alternate modes might trigger different behaviors.
628
419
  *
629
420
  * @returns {JSX.Element} The rendered DotCMS page body or an error message if the layout body is missing.
630
421
  *
631
- * -------------------------------------------------------------------
632
- *
633
- * El componente DotCMSLayoutBody renderiza el cuerpo del layout para una página de DotCMS.
634
- *
635
- * Utiliza el "body" del layout del asset de la página para renderizar las filas mediante el componente Row.
636
- * Si el "body" del layout no está presente, renderiza un mensaje de error.
637
- * También provee un contexto (DotCMSPageContext) con el asset de la página, componentes de usuario opcionales,
638
- * y el modo del renderizado para sus componentes hijos.
639
422
  */
640
423
  const DotCMSLayoutBody = ({
641
424
  page,
@@ -644,11 +427,6 @@ const DotCMSLayoutBody = ({
644
427
  }) => {
645
428
  var _page$layout;
646
429
  const dotCMSPageBody = page == null || (_page$layout = page.layout) == null ? void 0 : _page$layout.body;
647
- if (!dotCMSPageBody) {
648
- return jsx(ErrorMessage, {
649
- mode: _mode
650
- });
651
- }
652
430
  const contextValue = {
653
431
  pageAsset: page,
654
432
  userComponents: _components,
@@ -656,10 +434,926 @@ const DotCMSLayoutBody = ({
656
434
  };
657
435
  return jsx(DotCMSPageContext.Provider, {
658
436
  value: contextValue,
659
- children: dotCMSPageBody.rows.map((row, index) => jsx(Row, {
437
+ children: dotCMSPageBody ? dotCMSPageBody.rows.map((row, index) => jsx(Row, {
660
438
  row: row
661
- }, index))
439
+ }, index)) : jsx(ErrorMessage, {})
440
+ });
441
+ };
442
+
443
+ /**
444
+ * Custom hook to determine if the current UVE (Universal Visual Editor) mode
445
+ * matches the specified mode. This hook is useful for conditionally rendering
446
+ * components based on the UVE mode.
447
+ *
448
+ * @param {UVE_MODE} when - The UVE mode to check against.
449
+ * @returns {boolean} True if the current UVE mode matches the specified mode, otherwise false.
450
+ *
451
+ * @example
452
+ * // Basic usage: Check if the UVE is in edit mode
453
+ * const showInEditMode = useDotCMSShowWhen(UVE_MODE.EDIT);
454
+ * if (showInEditMode) {
455
+ * // Render edit-specific components
456
+ * }
457
+ *
458
+ * @example
459
+ * // Check if the UVE is in preview mode
460
+ * const showInPreviewMode = useDotCMSShowWhen(UVE_MODE.PREVIEW);
461
+ * if (showInPreviewMode) {
462
+ * // Render preview-specific components
463
+ * }
464
+ *
465
+ * @example
466
+ * // Check if the UVE is in live mode
467
+ * const showInLiveMode = useDotCMSShowWhen(UVE_MODE.LIVE);
468
+ * if (showInLiveMode) {
469
+ * // Render live-specific components
470
+ * }
471
+ */
472
+ const useDotCMSShowWhen = when => {
473
+ const [show, setShow] = useState(false);
474
+ useEffect(() => {
475
+ var _getUVEState;
476
+ setShow(((_getUVEState = getUVEState()) == null ? void 0 : _getUVEState.mode) === when);
477
+ }, [when]);
478
+ return show;
479
+ };
480
+
481
+ /**
482
+ * DotCMSShow component is used to conditionally render its children
483
+ * based on the Universal Visual Editor (UVE) mode. It checks if the UVE
484
+ * is in a specified mode and only renders its children in that case.
485
+ *
486
+ * @param {Object} props - The component props.
487
+ * @param {React.ReactNode} props.children - The children to be rendered when the condition is met.
488
+ * @param {UVE_MODE} [props.when=UVE_MODE.EDIT] - The UVE mode in which the children should be rendered.
489
+ * @returns {React.ReactNode | null} The children if the current UVE mode matches the `when` prop, otherwise null.
490
+ *
491
+ * @example
492
+ * // Basic usage: Render content only in edit mode
493
+ * <DotCMSShow when={UVE_MODE.EDIT}>
494
+ * <div>Edit Mode Content</div>
495
+ * </DotCMSShow>
496
+ *
497
+ * // This will render <div>Edit Mode Content</div> only if the UVE is in edit mode.
498
+ *
499
+ * @example
500
+ * // Render content in preview mode
501
+ * <DotCMSShow when={UVE_MODE.PREVIEW}>
502
+ * <MyCustomPreviewComponent />
503
+ * </DotCMSShow>
504
+ *
505
+ * // MyCustomPreviewComponent will only be rendered if the UVE is in preview mode.
506
+ *
507
+ * @example
508
+ * // Render content in live mode
509
+ * <DotCMSShow when={UVE_MODE.LIVE}>
510
+ * <LiveContentComponent />
511
+ * </DotCMSShow>
512
+ *
513
+ * // LiveContentComponent will only be rendered if the UVE is in live mode.
514
+ */
515
+ const DotCMSShow = ({
516
+ children,
517
+ when: _when = UVE_MODE.EDIT
518
+ }) => {
519
+ const show = useDotCMSShowWhen(_when);
520
+ if (!show) {
521
+ return null;
522
+ }
523
+ return children;
524
+ };
525
+
526
+ /**
527
+ * Custom hook to manage the editable state of a DotCMS page.
528
+ *
529
+ * This hook initializes the Universal Visual Editor (UVE) and subscribes to content changes.
530
+ * It updates the editable page state when content changes are detected in the UVE,
531
+ * ensuring your React components always display the latest content when editing in DotCMS.
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * // Import the hook and the client
536
+ * import { useEditableDotCMSPage } from '@dotcms/react';
537
+ * import { createDotCMSClient } from '@dotcms/client';
538
+ *
539
+ * // Create the client
540
+ * const client = createDotCMSClient({
541
+ * dotcmsURL: 'https://your-dotcms-instance.com',
542
+ * authToken: 'your-auth-token'
543
+ * });
544
+ *
545
+ * // Get the page
546
+ * const page = await client.page.get('/', {
547
+ * languageId: '1',
548
+ * });
549
+ *
550
+ * // Use the hook to get an editable version of the page
551
+ * const editablePage = useEditableDotCMSPage(page);
552
+ *
553
+ * // Then use the page data in your component
554
+ * return (
555
+ * <div>
556
+ * <h1>{editablePage.page.title}</h1>
557
+ * <div dangerouslySetInnerHTML={{ __html: editablePage.page.body }} />
558
+ * </div>
559
+ * );
560
+ * ```
561
+ *
562
+ * @example
563
+ * ```ts
564
+ * // Import the hook and the client
565
+ * import { useEditableDotCMSPage } from '@dotcms/react';
566
+ * import { createDotCMSClient } from '@dotcms/client';
567
+ *
568
+ * // Create the client
569
+ * const client = createDotCMSClient({
570
+ * dotcmsURL: 'https://your-dotcms-instance.com',
571
+ * authToken: 'your-auth-token'
572
+ * });
573
+ *
574
+ * // Get the page with GraphQL content
575
+ * const page = await client.page.get('/', {
576
+ * languageId: '1',
577
+ * graphql: {
578
+ * content: {
579
+ * products: `ProductCollection(query: "+title:snow", limit: 10, offset: 0, sortBy: "score") {
580
+ * title
581
+ * urlMap
582
+ * category {
583
+ * name
584
+ * inode
585
+ * }
586
+ * retailPrice
587
+ * image {
588
+ * versionPath
589
+ * }
590
+ * }`
591
+ * }
592
+ * }
593
+ * });
594
+ *
595
+ * // Use the hook to get an editable version of the page and its content
596
+ * const editablePage = useEditableDotCMSPage(page);
597
+ *
598
+ * // Access both page data and GraphQL content
599
+ * const { page: pageData, content } = editablePage;
600
+ *
601
+ * // Use the products from GraphQL content
602
+ * return (
603
+ * <div>
604
+ * <h1>{pageData.title}</h1>
605
+ * <ProductList products={content.products} />
606
+ * </div>
607
+ * );
608
+ * ```
609
+ * @param {DotCMSPageResponse} pageResponse - The initial editable page data from client.page.get().
610
+ *
611
+ * @returns {DotCMSPageResponse} The updated editable page state that reflects any changes made in the UVE.
612
+ * The structure includes page data and any GraphQL content that was requested.
613
+ */
614
+ const useEditableDotCMSPage = pageResponse => {
615
+ const [updatedPageResponse, setUpdatedPageResponse] = useState(pageResponse);
616
+ useEffect(() => {
617
+ var _pageResponse$pageAss;
618
+ if (!getUVEState()) {
619
+ return;
620
+ }
621
+ const pageURI = pageResponse == null || (_pageResponse$pageAss = pageResponse.pageAsset) == null || (_pageResponse$pageAss = _pageResponse$pageAss.page) == null ? void 0 : _pageResponse$pageAss.pageURI;
622
+ const {
623
+ destroyUVESubscriptions
624
+ } = initUVE(pageResponse);
625
+ // Update the navigation to the pageURI, when we have a pageURI
626
+ // Sometimes the page is null due to permissions, so we don't want to update the navigation
627
+ // And wait for the UVE to resolve the page
628
+ if (pageURI) {
629
+ updateNavigation(pageURI);
630
+ }
631
+ return () => {
632
+ destroyUVESubscriptions();
633
+ };
634
+ }, [pageResponse]);
635
+ useEffect(() => {
636
+ const {
637
+ unsubscribe
638
+ } = createUVESubscription(UVEEventType.CONTENT_CHANGES, payload => {
639
+ setUpdatedPageResponse(payload);
640
+ });
641
+ return () => {
642
+ unsubscribe();
643
+ };
644
+ }, []);
645
+ return updatedPageResponse;
646
+ };
647
+
648
+ const DEFAULT_TINYMCE_CONFIG = Object.assign({}, __DEFAULT_TINYMCE_CONFIG__, {
649
+ licenseKey: 'gpl' // Using self-hosted license key
650
+ });
651
+ const TINYMCE_CONFIG = {
652
+ full: Object.assign({}, DEFAULT_TINYMCE_CONFIG, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__.full),
653
+ plain: Object.assign({}, DEFAULT_TINYMCE_CONFIG, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__.plain),
654
+ minimal: Object.assign({}, DEFAULT_TINYMCE_CONFIG, __BASE_TINYMCE_CONFIG_WITH_NO_DEFAULT__.minimal)
655
+ };
656
+
657
+ /**
658
+ * Allows inline edit content pulled from dotCMS API using TinyMCE editor
659
+ *
660
+ * @export
661
+ * @component
662
+ * @param {Readonly<DotCMSEditableTextProps>} props {
663
+ * mode = 'plain',
664
+ * format = 'text',
665
+ * contentlet,
666
+ * fieldName = ''
667
+ * }
668
+ * @example
669
+ * ```javascript
670
+ * import { DotCMSEditableText } from '@dotcms/react';
671
+ *
672
+ * const MyContentletWithTitle = ({ contentlet }) => (
673
+ * <h2>
674
+ * <DotCMSEditableText
675
+ * contentlet={contentlet}
676
+ * fieldName="title"
677
+ * mode='full'
678
+ * format='text'/>
679
+ * </h2>
680
+ * );
681
+ * ```
682
+ * @returns {JSX.Element} A component to edit content inline
683
+ */
684
+ function DotCMSEditableText({
685
+ mode = 'plain',
686
+ format = 'text',
687
+ contentlet,
688
+ fieldName = ''
689
+ }) {
690
+ const editorRef = useRef(null);
691
+ const [scriptSrc, setScriptSrc] = useState('');
692
+ const [initEditor, setInitEditor] = useState(false);
693
+ const [content, setContent] = useState((contentlet == null ? void 0 : contentlet[fieldName]) || '');
694
+ useEffect(() => {
695
+ var _state$dotCMSHost, _editorRef$current;
696
+ const state = getUVEState();
697
+ setInitEditor((state == null ? void 0 : state.mode) === UVE_MODE.EDIT && !!(state != null && (_state$dotCMSHost = state.dotCMSHost) != null && _state$dotCMSHost.length));
698
+ if (!contentlet || !fieldName) {
699
+ console.error('DotCMSEditableText: contentlet or fieldName is missing', 'Ensure that all needed props are passed to view and edit the content');
700
+ return;
701
+ }
702
+ if (state && state.mode !== UVE_MODE.EDIT) {
703
+ console.warn('DotCMSEditableText: TinyMCE is not available in the current mode');
704
+ return;
705
+ }
706
+ if (!(state != null && state.dotCMSHost)) {
707
+ console.warn('The `dotCMSHost` parameter is not defined. Check that the UVE is sending the correct parameters.');
708
+ return;
709
+ }
710
+ const createURL = new URL(__TINYMCE_PATH_ON_DOTCMS__, state.dotCMSHost);
711
+ setScriptSrc(createURL.toString());
712
+ const content = (contentlet == null ? void 0 : contentlet[fieldName]) || '';
713
+ (_editorRef$current = editorRef.current) == null || _editorRef$current.setContent(content, {
714
+ format
715
+ });
716
+ setContent(content);
717
+ }, [format, fieldName, contentlet]);
718
+ useEffect(() => {
719
+ var _getUVEState;
720
+ if (((_getUVEState = getUVEState()) == null ? void 0 : _getUVEState.mode) !== UVE_MODE.EDIT) {
721
+ return;
722
+ }
723
+ const onMessage = ({
724
+ data
725
+ }) => {
726
+ const {
727
+ name,
728
+ payload
729
+ } = data;
730
+ if (name !== __DOTCMS_UVE_EVENT__.UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS) {
731
+ return;
732
+ }
733
+ const {
734
+ oldInode,
735
+ inode
736
+ } = payload;
737
+ const currentInode = contentlet.inode;
738
+ const shouldFocus = currentInode === oldInode || currentInode === inode;
739
+ if (shouldFocus) {
740
+ var _editorRef$current2;
741
+ (_editorRef$current2 = editorRef.current) == null || _editorRef$current2.focus();
742
+ }
743
+ };
744
+ window.addEventListener('message', onMessage);
745
+ return () => {
746
+ window.removeEventListener('message', onMessage);
747
+ };
748
+ }, [contentlet == null ? void 0 : contentlet.inode]);
749
+ const onMouseDown = event => {
750
+ var _editorRef$current3;
751
+ const {
752
+ onNumberOfPages = 1
753
+ } = contentlet;
754
+ const {
755
+ inode,
756
+ languageId: language
757
+ } = contentlet;
758
+ if (Number(onNumberOfPages) <= 1 || (_editorRef$current3 = editorRef.current) != null && _editorRef$current3.hasFocus()) {
759
+ return;
760
+ }
761
+ event.stopPropagation();
762
+ event.preventDefault();
763
+ sendMessageToUVE({
764
+ action: DotCMSUVEAction.COPY_CONTENTLET_INLINE_EDITING,
765
+ payload: {
766
+ dataset: {
767
+ inode,
768
+ language,
769
+ fieldName
770
+ }
771
+ }
772
+ });
773
+ };
774
+ const onFocusOut = () => {
775
+ var _editorRef$current4, _editorRef$current5;
776
+ const editedContent = ((_editorRef$current4 = editorRef.current) == null ? void 0 : _editorRef$current4.getContent({
777
+ format: format
778
+ })) || '';
779
+ const {
780
+ inode,
781
+ languageId: langId
782
+ } = contentlet;
783
+ if (!((_editorRef$current5 = editorRef.current) != null && _editorRef$current5.isDirty()) || !didContentChange(editedContent)) {
784
+ return;
785
+ }
786
+ sendMessageToUVE({
787
+ action: DotCMSUVEAction.UPDATE_CONTENTLET_INLINE_EDITING,
788
+ payload: {
789
+ content: editedContent,
790
+ dataset: {
791
+ inode,
792
+ langId,
793
+ fieldName
794
+ }
795
+ }
796
+ });
797
+ };
798
+ const didContentChange = editedContent => {
799
+ return content !== editedContent;
800
+ };
801
+ if (!initEditor) {
802
+ // We can let the user pass the Child Component and create a root to get the HTML for the editor
803
+ return jsx("span", {
804
+ dangerouslySetInnerHTML: {
805
+ __html: content
806
+ }
807
+ });
808
+ }
809
+ return jsx(Editor, {
810
+ tinymceScriptSrc: scriptSrc,
811
+ inline: true,
812
+ onInit: (_, editor) => editorRef.current = editor,
813
+ init: TINYMCE_CONFIG[mode],
814
+ initialValue: content,
815
+ onMouseDown: onMouseDown,
816
+ onFocusOut: onFocusOut
817
+ });
818
+ }
819
+
820
+ /**
821
+ * Renders a code block component.
822
+ *
823
+ * @param attrs - The attributes of the code block.
824
+ * @param children - The content of the code block.
825
+ * @returns The rendered code block component.
826
+ */
827
+ const CodeBlock = ({
828
+ node,
829
+ children
830
+ }) => {
831
+ var _node$attrs;
832
+ const language = (node == null || (_node$attrs = node.attrs) == null ? void 0 : _node$attrs.language) || '';
833
+ return jsx("pre", {
834
+ "data-language": language,
835
+ children: jsx("code", {
836
+ children: children
837
+ })
838
+ });
839
+ };
840
+ /**
841
+ * Renders a blockquote component.
842
+ *
843
+ * @param children - The content to be rendered inside the blockquote.
844
+ * @returns The rendered blockquote component.
845
+ */
846
+ const BlockQuote = ({
847
+ children
848
+ }) => {
849
+ return jsx("blockquote", {
850
+ children: children
851
+ });
852
+ };
853
+
854
+ /**
855
+ * Renders a DotContent component.
856
+ *
857
+ * @param {DotContentProps} props - The props for the DotContent component.
858
+ * @returns {JSX.Element} The rendered DotContent component.
859
+ */
860
+ const DotContent = ({
861
+ customRenderers,
862
+ node
863
+ }) => {
864
+ const isDevMode = useIsDevMode();
865
+ const attrs = (node == null ? void 0 : node.attrs) || {};
866
+ const data = attrs.data;
867
+ if (!data) {
868
+ console.error('DotContent: No data provided');
869
+ return null;
870
+ }
871
+ const contentType = data.contentType || 'Unknown Content Type';
872
+ const Component = customRenderers[contentType];
873
+ // In dev mode, show a helpful message for unknown content types
874
+ if (isDevMode && !Component) {
875
+ return jsxs("div", {
876
+ children: ["Unknown ContentType: ", contentType]
877
+ });
878
+ }
879
+ // In production, use default component if no matching component found
880
+ if (!Component) {
881
+ console.error('DotContent: No matching component found for content type', contentType);
882
+ return null;
883
+ }
884
+ return jsx(Component, Object.assign({}, node));
885
+ };
886
+
887
+ /**
888
+ * Renders an image component for dotCMS.
889
+ *
890
+ * @param node - The node for the DotCMSImage component.
891
+ * @returns The rendered image component.
892
+ */
893
+ const DotCMSImage = ({
894
+ node
895
+ }) => {
896
+ const {
897
+ src,
898
+ alt
899
+ } = node.attrs;
900
+ return jsx("img", {
901
+ alt: alt,
902
+ src: src
903
+ });
904
+ };
905
+
906
+ /**
907
+ * ListItem component represents a list item in a block editor.
908
+ *
909
+ * @param children - The content of the list item.
910
+ * @returns The rendered list item element.
911
+ */
912
+ const ListItem = ({
913
+ children
914
+ }) => {
915
+ return jsx("li", {
916
+ children: children
917
+ });
918
+ };
919
+ /**
920
+ * Renders an ordered list component.
921
+ *
922
+ * @param children - The content to be rendered inside the ordered list.
923
+ * @returns The ordered list component.
924
+ */
925
+ const OrderedList = ({
926
+ children
927
+ }) => {
928
+ return jsx("ol", {
929
+ children: children
930
+ });
931
+ };
932
+ /**
933
+ * Renders a bullet list component.
934
+ *
935
+ * @param children - The content of the bullet list.
936
+ * @returns The rendered bullet list component.
937
+ */
938
+ const BulletList = ({
939
+ children
940
+ }) => {
941
+ return jsx("ul", {
942
+ children: children
943
+ });
944
+ };
945
+
946
+ /**
947
+ * Renders a table component for the Block Editor.
948
+ *
949
+ * @param content - The content of the table.
950
+ * @param blockEditorItem - The Block Editor item component.
951
+ */
952
+ const TableRenderer = ({
953
+ content,
954
+ blockEditorItem
955
+ }) => {
956
+ const BlockEditorItemComponent = blockEditorItem;
957
+ const renderTableContent = node => {
958
+ var _node$content;
959
+ return jsx(BlockEditorItemComponent, {
960
+ content: (_node$content = node.content) != null ? _node$content : []
961
+ });
962
+ };
963
+ return jsxs("table", {
964
+ children: [jsx("thead", {
965
+ children: content.slice(0, 1).map((rowNode, rowIndex) => {
966
+ var _rowNode$content;
967
+ return jsx("tr", {
968
+ children: (_rowNode$content = rowNode.content) == null ? void 0 : _rowNode$content.map((cellNode, cellIndex) => {
969
+ var _cellNode$attrs, _cellNode$attrs2;
970
+ return jsx("th", {
971
+ colSpan: Number(((_cellNode$attrs = cellNode.attrs) == null ? void 0 : _cellNode$attrs.colspan) || 1),
972
+ rowSpan: Number(((_cellNode$attrs2 = cellNode.attrs) == null ? void 0 : _cellNode$attrs2.rowspan) || 1),
973
+ children: renderTableContent(cellNode)
974
+ }, `${cellNode.type}-${cellIndex}`);
975
+ })
976
+ }, `${rowNode.type}-${rowIndex}`);
977
+ })
978
+ }), jsx("tbody", {
979
+ children: content.slice(1).map((rowNode, rowIndex) => {
980
+ var _rowNode$content2;
981
+ return jsx("tr", {
982
+ children: (_rowNode$content2 = rowNode.content) == null ? void 0 : _rowNode$content2.map((cellNode, cellIndex) => {
983
+ var _cellNode$attrs3, _cellNode$attrs4;
984
+ return jsx("td", {
985
+ colSpan: Number(((_cellNode$attrs3 = cellNode.attrs) == null ? void 0 : _cellNode$attrs3.colspan) || 1),
986
+ rowSpan: Number(((_cellNode$attrs4 = cellNode.attrs) == null ? void 0 : _cellNode$attrs4.rowspan) || 1),
987
+ children: renderTableContent(cellNode)
988
+ }, `${cellNode.type}-${cellIndex}`);
989
+ })
990
+ }, `${rowNode.type}-${rowIndex}`);
991
+ })
992
+ })]
993
+ });
994
+ };
995
+
996
+ /**
997
+ * Renders the text in bold.
998
+ *
999
+ * @param children - The content to be rendered in bold.
1000
+ */
1001
+ const Bold = ({
1002
+ children
1003
+ }) => jsx("strong", {
1004
+ children: children
1005
+ });
1006
+ /**
1007
+ * Renders the text in italic format.
1008
+ *
1009
+ * @param children - The content to be rendered in italic.
1010
+ */
1011
+ const Italic = ({
1012
+ children
1013
+ }) => jsx("em", {
1014
+ children: children
1015
+ });
1016
+ /**
1017
+ * Renders a strike-through text.
1018
+ *
1019
+ * @param children - The content to be rendered within the strike-through element.
1020
+ */
1021
+ const Strike = ({
1022
+ children
1023
+ }) => jsx("s", {
1024
+ children: children
1025
+ });
1026
+ /**
1027
+ * Renders an underline element for the given children.
1028
+ *
1029
+ * @param children - The content to be underlined.
1030
+ */
1031
+ const Underline = ({
1032
+ children
1033
+ }) => jsx("u", {
1034
+ children: children
1035
+ });
1036
+ /**
1037
+ * Renders a paragraph element.
1038
+ *
1039
+ * @param children - The content of the paragraph.
1040
+ * @param attrs - The style attributes for the paragraph.
1041
+ * @returns The rendered paragraph element.
1042
+ */
1043
+ const Paragraph = ({
1044
+ children,
1045
+ node
1046
+ }) => {
1047
+ const attrs = (node == null ? void 0 : node.attrs) || {};
1048
+ return jsx("p", {
1049
+ style: attrs,
1050
+ children: children
1051
+ });
1052
+ };
1053
+ /**
1054
+ * Renders a link component.
1055
+ *
1056
+ * @param children - The content of the link.
1057
+ * @param attrs - The attributes to be applied to the link.
1058
+ * @returns The rendered link component.
1059
+ */
1060
+ const Link = ({
1061
+ children,
1062
+ attrs
1063
+ }) => {
1064
+ return jsx("a", Object.assign({}, attrs, {
1065
+ children: children
1066
+ }));
1067
+ };
1068
+ /**
1069
+ * Renders a heading element with the specified level.
1070
+ *
1071
+ * @param children - The content of the heading.
1072
+ * @param attrs - The attributes for the heading.
1073
+ * @returns The rendered heading element.
1074
+ */
1075
+ const Heading = ({
1076
+ children,
1077
+ node
1078
+ }) => {
1079
+ const attrs = (node == null ? void 0 : node.attrs) || {};
1080
+ const level = attrs.level || 1;
1081
+ const Tag = `h${level}`;
1082
+ return jsx(Tag, {
1083
+ children: children
1084
+ });
1085
+ };
1086
+ /**
1087
+ * Renders the superscript text.
1088
+ *
1089
+ * @param children - The content to be rendered as superscript.
1090
+ */
1091
+ const Superscript = ({
1092
+ children
1093
+ }) => jsx("sup", {
1094
+ children: children
1095
+ });
1096
+ /**
1097
+ * Renders a subscript element.
1098
+ *
1099
+ * @param children - The content to be rendered as subscript.
1100
+ */
1101
+ const Subscript = ({
1102
+ children
1103
+ }) => jsx("sub", {
1104
+ children: children
1105
+ });
1106
+ const nodeMarks = {
1107
+ bold: Bold,
1108
+ link: Link,
1109
+ italic: Italic,
1110
+ strike: Strike,
1111
+ subscript: Subscript,
1112
+ underline: Underline,
1113
+ superscript: Superscript
1114
+ };
1115
+ const defaultMark = {
1116
+ type: '',
1117
+ attrs: {}
1118
+ };
1119
+ /**
1120
+ * Renders a text block with optional marks.
1121
+ *
1122
+ * @param props - The props for the TextBlock component.
1123
+ * @returns The rendered text block.
1124
+ */
1125
+ const TextBlock = (props = {}) => {
1126
+ const {
1127
+ marks = [],
1128
+ text
1129
+ } = props;
1130
+ const mark = marks[0] || defaultMark;
1131
+ const textProps = Object.assign({}, props, {
1132
+ marks: marks.slice(1)
1133
+ });
1134
+ const Component = nodeMarks[mark == null ? void 0 : mark.type];
1135
+ // In React, class is not a valid attribute name, so we need to rename it to className
1136
+ if (mark.attrs) {
1137
+ mark.attrs.className = mark.attrs.class;
1138
+ delete mark.attrs.class;
1139
+ }
1140
+ if (!Component) {
1141
+ return text;
1142
+ }
1143
+ return jsx(Component, {
1144
+ type: mark.type,
1145
+ attrs: mark.attrs,
1146
+ children: jsx(TextBlock, Object.assign({}, textProps))
1147
+ });
1148
+ };
1149
+
1150
+ /**
1151
+ * Renders a video component for displaying videos.
1152
+ *
1153
+ * @param props - The properties for the video component.
1154
+ * @returns The rendered video component.
1155
+ */
1156
+ const DotCMSVideo = ({
1157
+ node
1158
+ }) => {
1159
+ const {
1160
+ data,
1161
+ src,
1162
+ mimeType,
1163
+ width,
1164
+ height
1165
+ } = node.attrs;
1166
+ const poster = data == null ? void 0 : data.thumbnail;
1167
+ const posterAttribute = poster ? {
1168
+ poster
1169
+ } : {};
1170
+ return jsxs("video", Object.assign({
1171
+ controls: true,
1172
+ preload: "metadata",
1173
+ width: width,
1174
+ height: height
1175
+ }, posterAttribute, {
1176
+ children: [jsx("track", {
1177
+ default: true,
1178
+ kind: "captions",
1179
+ srcLang: "en"
1180
+ }), jsx("source", {
1181
+ src: src,
1182
+ type: mimeType
1183
+ }), "Your browser does not support the ", jsx("code", {
1184
+ children: "video"
1185
+ }), " element."]
1186
+ }));
1187
+ };
1188
+
1189
+ /**
1190
+ * Renders a block editor item based on the provided content and custom renderers.
1191
+ *
1192
+ * @param content - The content nodes to render.
1193
+ * @param customRenderers - Optional custom renderers for specific node types.
1194
+ * @returns The rendered block editor item.
1195
+ */
1196
+ const BlockEditorBlock = ({
1197
+ content,
1198
+ customRenderers
1199
+ }) => {
1200
+ if (!content) {
1201
+ return null;
1202
+ }
1203
+ return content == null ? void 0 : content.map((node, index) => {
1204
+ var _node$content;
1205
+ const CustomRendererComponent = customRenderers == null ? void 0 : customRenderers[node.type];
1206
+ if (CustomRendererComponent) {
1207
+ return jsx(CustomRendererComponent, {
1208
+ content: node.content,
1209
+ children: jsx(BlockEditorBlock, {
1210
+ content: node.content,
1211
+ customRenderers: customRenderers
1212
+ })
1213
+ }, `${node.type}-${index}`);
1214
+ }
1215
+ switch (node.type) {
1216
+ case BlockEditorDefaultBlocks.PARAGRAPH:
1217
+ return jsx(Paragraph, {
1218
+ node: node,
1219
+ children: jsx(BlockEditorBlock, {
1220
+ content: node.content,
1221
+ customRenderers: customRenderers
1222
+ })
1223
+ }, `${node.type}-${index}`);
1224
+ case BlockEditorDefaultBlocks.HEADING:
1225
+ return jsx(Heading, {
1226
+ node: node,
1227
+ children: jsx(BlockEditorBlock, {
1228
+ content: node.content,
1229
+ customRenderers: customRenderers
1230
+ })
1231
+ }, `${node.type}-${index}`);
1232
+ case BlockEditorDefaultBlocks.TEXT:
1233
+ return jsx(TextBlock, Object.assign({}, node), `${node.type}-${index}`);
1234
+ case BlockEditorDefaultBlocks.BULLET_LIST:
1235
+ return jsx(BulletList, {
1236
+ children: jsx(BlockEditorBlock, {
1237
+ content: node.content,
1238
+ customRenderers: customRenderers
1239
+ })
1240
+ }, `${node.type}-${index}`);
1241
+ case BlockEditorDefaultBlocks.ORDERED_LIST:
1242
+ return jsx(OrderedList, {
1243
+ children: jsx(BlockEditorBlock, {
1244
+ content: node.content,
1245
+ customRenderers: customRenderers
1246
+ })
1247
+ }, `${node.type}-${index}`);
1248
+ case BlockEditorDefaultBlocks.LIST_ITEM:
1249
+ return jsx(ListItem, {
1250
+ children: jsx(BlockEditorBlock, {
1251
+ content: node.content,
1252
+ customRenderers: customRenderers
1253
+ })
1254
+ }, `${node.type}-${index}`);
1255
+ case BlockEditorDefaultBlocks.BLOCK_QUOTE:
1256
+ return jsx(BlockQuote, {
1257
+ children: jsx(BlockEditorBlock, {
1258
+ content: node.content,
1259
+ customRenderers: customRenderers
1260
+ })
1261
+ }, `${node.type}-${index}`);
1262
+ case BlockEditorDefaultBlocks.CODE_BLOCK:
1263
+ return jsx(CodeBlock, {
1264
+ node: node,
1265
+ children: jsx(BlockEditorBlock, {
1266
+ content: node.content,
1267
+ customRenderers: customRenderers
1268
+ })
1269
+ }, `${node.type}-${index}`);
1270
+ case BlockEditorDefaultBlocks.HARDBREAK:
1271
+ return jsx("br", {}, `${node.type}-${index}`);
1272
+ case BlockEditorDefaultBlocks.HORIZONTAL_RULE:
1273
+ return jsx("hr", {}, `${node.type}-${index}`);
1274
+ case BlockEditorDefaultBlocks.DOT_IMAGE:
1275
+ return jsx(DotCMSImage, {
1276
+ node: node
1277
+ }, `${node.type}-${index}`);
1278
+ case BlockEditorDefaultBlocks.DOT_VIDEO:
1279
+ return jsx(DotCMSVideo, {
1280
+ node: node
1281
+ }, `${node.type}-${index}`);
1282
+ case BlockEditorDefaultBlocks.TABLE:
1283
+ return jsx(TableRenderer, {
1284
+ content: (_node$content = node.content) != null ? _node$content : [],
1285
+ blockEditorItem: BlockEditorBlock
1286
+ }, `${node.type}-${index}`);
1287
+ case BlockEditorDefaultBlocks.DOT_CONTENT:
1288
+ return jsx(DotContent, {
1289
+ customRenderers: customRenderers,
1290
+ node: node
1291
+ }, `${node.type}-${index}`);
1292
+ default:
1293
+ return jsxs("div", {
1294
+ children: ["Unknown Block Type ", node.type]
1295
+ }, `${node.type}-${index}`);
1296
+ }
1297
+ });
1298
+ };
1299
+
1300
+ /**
1301
+ * BlockEditorRenderer component for rendering block editor field.
1302
+ *
1303
+ * @component
1304
+ * @param {Object} props - The component props.
1305
+ * @param {BlockEditorContent} props.blocks - The blocks of content to render.
1306
+ * @param {CustomRenderer} [props.customRenderers] - Optional custom renderers for specific block types.
1307
+ * @param {string} [props.className] - Optional CSS class name for the container div.
1308
+ * @param {React.CSSProperties} [props.style] - Optional inline styles for the container div.
1309
+ * @returns {JSX.Element} A div containing the rendered blocks of content.
1310
+ */
1311
+ const DotCMSBlockEditorRenderer = ({
1312
+ blocks,
1313
+ style,
1314
+ className,
1315
+ customRenderers
1316
+ }) => {
1317
+ const [blockEditorState, setBlockEditorState] = useState({
1318
+ error: null
1319
+ });
1320
+ const isDevMode = useIsDevMode();
1321
+ /**
1322
+ * Validates the blocks structure and updates the block editor state.
1323
+ *
1324
+ * This effect:
1325
+ * 1. Validates that blocks have the correct structure (doc type, content array, etc)
1326
+ * 2. Updates the block editor state with validation result
1327
+ * 3. Logs any validation errors to console
1328
+ *
1329
+ * @dependency {Block} blocks - The content blocks to validate
1330
+ */
1331
+ useEffect(() => {
1332
+ const validationResult = isValidBlocks(blocks);
1333
+ setBlockEditorState(validationResult);
1334
+ if (validationResult.error) {
1335
+ console.error(validationResult.error);
1336
+ }
1337
+ }, [blocks]);
1338
+ if (blockEditorState.error) {
1339
+ console.error(blockEditorState.error);
1340
+ if (isDevMode) {
1341
+ return jsx("div", {
1342
+ "data-testid": "invalid-blocks-message",
1343
+ children: blockEditorState.error
1344
+ });
1345
+ }
1346
+ return null;
1347
+ }
1348
+ return jsx("div", {
1349
+ className: className,
1350
+ style: style,
1351
+ "data-testid": "dot-block-editor-container",
1352
+ children: jsx(BlockEditorBlock, {
1353
+ content: blocks == null ? void 0 : blocks.content,
1354
+ customRenderers: customRenderers
1355
+ })
662
1356
  });
663
1357
  };
664
1358
 
665
- export { DotCMSLayoutBody };
1359
+ export { DotCMSBlockEditorRenderer, DotCMSEditableText, DotCMSLayoutBody, DotCMSShow, useDotCMSShowWhen, useEditableDotCMSPage };