@dotcms/react 0.0.1-beta.4 → 0.0.1-beta.41

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 (39) hide show
  1. package/README.md +539 -80
  2. package/index.esm.js +49 -2169
  3. package/next.esm.js +1037 -236
  4. package/package.json +10 -5
  5. package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Contentlet.d.ts +1 -1
  6. package/src/lib/deprecated/components/DotEditableText/DotEditableText.d.ts +1 -0
  7. package/src/lib/deprecated/components/DotcmsLayout/DotcmsLayout.d.ts +1 -0
  8. package/src/lib/deprecated/mocks/mockPageContext.d.ts +1 -0
  9. package/src/lib/next/__test__/mock.d.ts +2 -1
  10. package/src/lib/next/components/Column/Column.d.ts +1 -1
  11. package/src/lib/next/components/Container/Container.d.ts +1 -1
  12. package/src/lib/next/components/Container/{ContainerFallbakcs.d.ts → ContainerFallbacks.d.ts} +2 -2
  13. package/src/lib/next/components/Contentlet/Contentlet.d.ts +2 -2
  14. package/src/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.d.ts +27 -0
  15. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/BlockEditorBlock.d.ts +15 -0
  16. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Code.d.ts +24 -0
  17. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/DotContent.d.ts +14 -0
  18. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Image.d.ts +10 -0
  19. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Lists.d.ts +26 -0
  20. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/NoComponentProvided.d.ts +3 -0
  21. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Table.d.ts +16 -0
  22. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Texts.d.ts +81 -0
  23. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Video.d.ts +10 -0
  24. package/src/lib/next/components/DotCMSEditableText/DotCMSEditableText.d.ts +32 -0
  25. package/src/lib/next/components/DotCMSEditableText/utils.d.ts +36 -0
  26. package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +5 -4
  27. package/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.d.ts +1 -4
  28. package/src/lib/next/components/DotCMSShow/DotCMSShow.d.ts +49 -0
  29. package/src/lib/next/components/FallbackComponent/FallbackComponent.d.ts +6 -6
  30. package/src/lib/next/components/Row/Row.d.ts +1 -1
  31. package/src/lib/next/contexts/DotCMSPageContext.d.ts +2 -3
  32. package/src/lib/next/hooks/useDotCMSShowWhen.d.ts +31 -0
  33. package/src/lib/next/hooks/useEditableDotCMSPage.d.ts +90 -0
  34. package/src/lib/next/hooks/useIsDevMode.d.ts +2 -5
  35. package/src/next.d.ts +5 -0
  36. package/web.url-search-params.size.esm.js +4216 -0
  37. package/es.regexp.to-string.esm.js +0 -1878
  38. package/src/lib/next/types.d.ts +0 -421
  39. package/src/lib/next/utils/index.d.ts +0 -136
package/README.md CHANGED
@@ -1,156 +1,615 @@
1
- # @dotcms/react
1
+ # dotCMS React SDK
2
2
 
3
- `@dotcms/react` is the official set of React components and hooks designed to work seamlessly with dotCMS, making it easy to render dotCMS pages and use the page builder.
3
+ The `@dotcms/react` SDK is the DotCMS official React library. It empowers React developers to build powerful, editable websites and applications in no time.
4
4
 
5
- ## Features
5
+ ## Table of Contents
6
6
 
7
- - A collection of React components and hooks tailored to render dotCMS pages.
8
- - Streamlined integration with dotCMS page editor.
9
- - Improved development experience with comprehensive TypeScript typings.
7
+ - [Prerequisites & Setup](#prerequisites--setup)
8
+ - [Get a dotCMS Environment](#get-a-dotcms-environment)
9
+ - [Create a dotCMS API Key](#create-a-dotcms-api-key)
10
+ - [Configure The Universal Visual Editor App](#configure-the-universal-visual-editor-app)
11
+ - [Installation](#installation)
12
+ - [dotCMS Client Configuration](#dotcms-client-configuration)
13
+ - [Proxy Configuration for Static Assets](#proxy-configuration-for-static-assets)
14
+ - [Quickstart: Render a Page with dotCMS](#quickstart-render-a-page-with-dotcms)
15
+ - [Example Project](#example-project-)
16
+ - [SDK Reference](#sdk-reference)
17
+ - [DotCMSLayoutBody](#dotcmslayoutbody)
18
+ - [DotCMSShow](#dotcmsshow)
19
+ - [DotCMSBlockEditorRenderer](#dotcmsblockeditorrenderer)
20
+ - [DotCMSEditableText](#dotcmseditabletext)
21
+ - [useEditableDotCMSPage](#useeditabledotcmspage)
22
+ - [useDotCMSShowWhen](#usedotcmsshowwhen)
23
+ - [Troubleshooting](#troubleshooting)
24
+ - [Common Issues & Solutions](#common-issues--solutions)
25
+ - [Debugging Tips](#debugging-tips)
26
+ - [Version Compatibility](#version-compatibility)
27
+ - [Still Having Issues?](#still-having-issues)
28
+ - [dotCMS Support](#dotcms-support)
29
+ - [How To Contribute](#how-to-contribute)
30
+ - [Licensing Information](#licensing-information)
10
31
 
11
- ## Installation
32
+ ## Prerequisites & Setup
12
33
 
13
- Install the package via npm:
34
+ ### Get a dotCMS Environment
35
+
36
+ #### Version Compatibility
37
+
38
+ - **Recommended**: dotCMS Evergreen
39
+ - **Minimum**: dotCMS v25.05
40
+ - **Best Experience**: Latest Evergreen release
41
+
42
+ #### Environment Setup
43
+
44
+ **For Production Use:**
45
+
46
+ - ☁️ [Cloud hosting options](https://www.dotcms.com/pricing) - managed solutions with SLA
47
+ - 🛠️ [Self-hosted options](https://dev.dotcms.com/docs/current-releases) - deploy on your infrastructure
48
+
49
+ **For Testing & Development:**
50
+
51
+ - 🧑🏻‍💻 [dotCMS demo site](https://demo.dotcms.com/dotAdmin/#/public/login) - perfect for trying out the SDK
52
+ - 📘 [Learn how to use the demo site](https://dev.dotcms.com/docs/demo-site)
53
+ - 📝 Read-only access, ideal for building proof-of-concepts
54
+
55
+ **For Local Development:**
56
+
57
+ - 🐳 [Docker setup guide](https://github.com/dotCMS/core/tree/main/docker/docker-compose-examples/single-node-demo-site)
58
+ - 💻 [Local installation guide](https://dev.dotcms.com/docs/quick-start-guide)
59
+
60
+ ### Configure The Universal Visual Editor App
61
+
62
+ For a step-by-step guide on setting up the Universal Visual Editor, check out our [easy-to-follow instructions](https://dev.dotcms.com/docs/uve-headless-config) and get started in no time!
63
+
64
+ ### Create a dotCMS API Key
65
+
66
+ > [!TIP]
67
+ > Make sure your API Token has read-only permissions for Pages, Folders, Assets, and Content. Using a key with minimal permissions follows security best practices.
68
+
69
+ This integration requires an API Key with read-only permissions for security best practices:
70
+
71
+ 1. Go to the **dotCMS admin panel**.
72
+ 2. Click on **System** > **Users**.
73
+ 3. Select the user you want to create the API Key for.
74
+ 4. Go to **API Access Key** and generate a new key.
75
+
76
+ For detailed instructions, please refer to the [dotCMS API Documentation - Read-only token](https://dev.dotcms.com/docs/rest-api-authentication#ReadOnlyToken).
77
+
78
+ ### Install Dependencies
14
79
 
15
80
  ```bash
16
- npm install @dotcms/react
81
+ npm install @dotcms/react@next
17
82
  ```
18
83
 
19
- Or using Yarn:
84
+ This will automatically install the required dependencies:
85
+ - `@dotcms/uve`: Enables interaction with the [Universal Visual Editor](https://dev.dotcms.com/docs/uve-headless-config) for real-time content editing
86
+ - `@dotcms/client`: Provides the core client functionality for fetching and managing dotCMS data
20
87
 
21
- ```bash
22
- yarn add @dotcms/react
88
+ ### dotCMS Client Configuration
89
+
90
+ ```typescript
91
+ import { createDotCMSClient } from '@dotcms/client/next';
92
+
93
+ type DotCMSClient = ReturnType<typeof createDotCMSClient>;
94
+
95
+ export const dotCMSClient: DotCMSClient = createDotCMSClient({
96
+ dotcmsUrl: 'https://your-dotcms-instance.com',
97
+ authToken: 'your-auth-token', // Optional for public content
98
+ siteId: 'your-site-id' // Optional site identifier/name
99
+ });
100
+ ```
101
+
102
+ ### Proxy Configuration for Static Assets
103
+
104
+ Configure a proxy to leverage the powerful dotCMS image API, allowing you to resize and serve optimized images efficiently. This enhances application performance and improves user experience, making it a strategic enhancement for your project.
105
+
106
+ #### 1. Configure Vite
107
+
108
+ ```ts
109
+ // vite.config.ts
110
+ import { defineConfig } from 'vite';
111
+ import dns from 'node:dns';
112
+
113
+ dns.setDefaultResultOrder('verbatim');
114
+
115
+ export default defineConfig({
116
+ server: {
117
+ proxy: {
118
+ '/dA': {
119
+ target: 'your-dotcms-instance.com',
120
+ changeOrigin: true
121
+ }
122
+ }
123
+ }
124
+ });
125
+ ```
126
+
127
+ Learn more about Vite configuration [here](https://vitejs.dev/config/).
128
+
129
+ #### 2. Usage in Components
130
+
131
+ Once configured, image URLs in your components will automatically be proxied to your dotCMS instance:
132
+
133
+ >📚 Learn more about [Image Resizing and Processing in dotCMS with React](https://www.dotcms.com/blog/image-resizing-and-processing-in-dotcms-with-angular-and-nextjs).
134
+
135
+ ```typescript
136
+ // /components/my-dotcms-image.tsx
137
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
138
+
139
+ export const MyDotCMSImageComponent = ({ inode, title }: DotCMSBasicContentlet) => {
140
+ return <img src={`/dA/${inode}`} alt={title} />;
141
+ }
23
142
  ```
24
143
 
25
- ## Components
144
+ ## Quickstart: Render a Page with dotCMS
145
+
146
+ The following example demonstrates how to quickly set up a basic dotCMS page renderer in your React application. This example shows how to:
147
+
148
+ - Create a standalone component that renders a dotCMS page
149
+ - Set up dynamic component loading for different content types
150
+ - Handle both regular page viewing and editor mode
151
+ - Subscribe to real-time page updates when in the Universal Visual Editor
152
+
153
+ ```tsx
154
+ // /src/app/pages/dotcms-page.tsx
155
+ import { useState, useEffect } from 'react';
156
+ import { DotCMSLayoutBody, useEditableDotCMSPage } from '@dotcms/react/next';
157
+ import { DotCMSPageResponse } from '@dotcms/types';
158
+
159
+ import { dotCMSClient } from './dotCMSClient';
160
+ import { BlogComponent } from './BlogComponent';
161
+ import { ProductComponent } from './ProductComponent';
162
+
163
+ const COMPONENTS_MAP = {
164
+ Blog: BlogComponent,
165
+ Product: ProductComponent
166
+ };
167
+
168
+ const MyPage = () => {
169
+ const [response, setResponse] = useState<DotCMSPageResponse | null>(null);
170
+ const { pageAsset } = useEditableDotCMSPage(response);
171
+
172
+ useEffect(() => {
173
+ dotCMSClient.page.get('/').then((response) => {
174
+ setResponse(response);
175
+ });
176
+ }, []);
177
+
178
+ return <DotCMSLayoutBody page={pageAsset} components={COMPONENTS_MAP} mode="development" />;
179
+ };
180
+
181
+ export default MyPage;
182
+ ```
26
183
 
27
- ### Deprecated: DotcmsLayout
184
+ ### Example Project 🚀
28
185
 
29
- **Important:** The `DotcmsLayout` component is deprecated. Please use the new [`DotCMSLayoutBody`](#DotCMSLayoutBody) component instead.
186
+ Looking to get started quickly? We've got you covered! Our [Next.js starter project](https://github.com/dotCMS/core/tree/main/examples/nextjs) is the perfect launchpad for your dotCMS + Next.js journey. This production-ready template demonstrates everything you need:
30
187
 
31
- #### Props
188
+ 📦 Fetch and render dotCMS pages with best practices
189
+ 🧩 Register and manage components for different content types
190
+ 🔍 Listing pages with search functionality
191
+ 📝 Detail pages for blogs
192
+ 📈 Image and assets optimization for better performance
193
+ ✨ Enable seamless editing via the Universal Visual Editor (UVE)
194
+ ⚡️ Leverage React's hooks and state management for optimal performance
32
195
 
33
- - **entity**: The context for a dotCMS page.
196
+ > [!TIP]
197
+ > This starter project is more than just an example, it follows all our best practices. We highly recommend using it as the base for your next dotCMS + Next.js project!
198
+
199
+ ## SDK Reference
200
+
201
+ All components and hooks should be imported from `@dotcms/react/next`:
202
+
203
+ ### DotCMSLayoutBody
204
+
205
+ `DotCMSLayoutBody` is a component used to render the layout for a DotCMS page, supporting both production and development modes.
206
+
207
+ | Input | Type | Required | Default | Description |
208
+ | ------------ | ------------------------ | -------- | -------------- | ---------------------------------------------- |
209
+ | `page` | `DotCMSPageAsset` | ✅ | - | The page asset containing the layout to render |
210
+ | `components` | `DotCMSPageComponent` | ✅ | `{}` | [Map of content type → React component](#component-mapping) |
211
+ | `mode` | `DotCMSPageRendererMode` | ❌ | `'production'` | [Rendering mode ('production' or 'development')](#layout-body-modes) |
212
+
213
+ #### Client-Side Only Component
214
+
215
+ > ⚠️ **Important: This is a client-side React component.**
216
+ > `DotCMSLayoutBody` uses React features like `useContext`, `useEffect`, and `useState`.
217
+ > If you're using a framework that supports Server-Side Rendering (like **Next.js**, **Gatsby**, or **Astro**), you **must** mark the parent component with `"use client"` or follow your framework’s guidelines for using client-side components.
218
+ >
219
+ > 👉 [Learn more: Next.js – Client Components](https://nextjs.org/docs/getting-started/react-essentials#client-components)
34
220
 
35
221
  #### Usage
36
222
 
37
- ```javascript
38
- // Deprecated:
39
- import { DotcmsLayout } from '@dotcms/react';
223
+ ```tsx
224
+ import type { DotCMSPageAsset } from '@dotcms/types';
225
+ import { DotCMSLayoutBody } from '@dotcms/react/next';
226
+
227
+ import { MyBlogCard } from './MyBlogCard';
228
+ import { DotCMSProductComponent } from './DotCMSProductComponent';
40
229
 
41
- const MyPage = ({ entity }) => {
42
- return <DotcmsLayout entity={entity} />;
230
+ const COMPONENTS_MAP = {
231
+ Blog: MyBlogCard,
232
+ Product: DotCMSProductComponent
233
+ };
234
+
235
+ const MyPage = ({ pageAsset }: DotCMSPageResponse) => {
236
+ return <DotCMSLayoutBody page={pageAsset} components={COMPONENTS_MAP} />;
43
237
  };
44
238
  ```
45
239
 
46
- ### `DotCMSLayoutBody`
240
+ #### Layout Body Modes
241
+
242
+ - `production`: Performance-optimized mode that only renders content with explicitly mapped components, leaving unmapped content empty.
243
+ - `development`: Debug-friendly mode that renders default components for unmapped content types and provides visual indicators and console logs for empty containers and missing mappings.
244
+
245
+ #### Component Mapping
47
246
 
48
- The `DotCMSLayoutBody` component renders the layout body for a DotCMS page.
247
+ The `DotCMSLayoutBody` component uses a `components` prop to map content type variable names to React components. This allows you to render different components for different content types. Example:
248
+
249
+ ```typescript
250
+ const DYNAMIC_COMPONENTS = {
251
+ Blog: MyBlogCard,
252
+ Product: DotCMSProductComponent
253
+ };
254
+ ```
49
255
 
50
- #### Props
256
+ - Keys (e.g., `Blog`, `Product`): Match your [content type variable names](https://dev.dotcms.com/docs/content-types#VariableNames) in dotCMS
257
+ - Values: Dynamic imports of your React components that render each content type
258
+ - Supports lazy loading through dynamic imports
259
+ - Components must be standalone or declared in a module
51
260
 
52
- - **page**: The DotCMS page asset containing the layout information.
53
- - **components**: A mapping of custom components for content rendering.
54
- - **mode** (optional): The renderer mode; defaults to `'production'`.
261
+ > [!TIP]
262
+ > Always use the exact content type variable name from dotCMS as the key. You can find this in the Content Types section of your dotCMS admin panel.
263
+
264
+
265
+ ### DotCMSEditableText
266
+
267
+ `DotCMSEditableText` is a component for inline editing of text fields in dotCMS, supporting plain text, text area, and WYSIWYG fields.
268
+
269
+ | Input | Type | Required | Description |
270
+ | ------------ | ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
271
+ | `contentlet` | `T extends DotCMSBasicContentlet` | ✅ | The contentlet containing the editable field |
272
+ | `fieldName` | `keyof T` | ✅ | Name of the field to edit, which must be a valid key of the contentlet type `T` |
273
+ | `mode` | `'plain' \| 'full'` | ❌ | `plain` (default): Support text editing. Does not show style controls. <br/> `full`: Enables a bubble menu with style options. This mode only works with [`WYSIWYG` fields](https://dev.dotcms.com/docs/the-wysiwyg-field). |
274
+ | `format` | `'text' \| 'html'` | ❌ | `text` (default): Renders HTML tags as plain text <br/> `html`: Interprets and renders HTML markup |
275
+
276
+ #### Usage
277
+
278
+ ```tsx
279
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
280
+ import { DotCMSEditableText } from '@dotcms/react/next';
281
+
282
+ const MyBannerComponent = ({ contentlet }: { contentlet: DotCMSBasicContentlet }) => {
283
+ const { inode, title, link } = contentlet;
284
+
285
+ return (
286
+ <div className="flex overflow-hidden relative justify-center items-center w-full h-96 bg-gray-200">
287
+ <img className="object-cover w-full" src={`/dA/${inode}`} alt={title} />
288
+ <div className="flex absolute inset-0 flex-col justify-center items-center p-4 text-center text-white">
289
+ <h2 className="mb-2 text-6xl font-bold text-shadow">
290
+ <DotCMSEditableText fieldName="title" contentlet={contentlet} />
291
+ </h2>
292
+ <a
293
+ href={link}
294
+ className="p-4 text-xl bg-red-400 rounded-sm transition duration-300 hover:bg-red-500">
295
+ See more
296
+ </a>
297
+ </div>
298
+ </div>
299
+ );
300
+ };
301
+
302
+ export default MyBannerComponent;
303
+ ```
304
+
305
+ #### Editor Integration
306
+
307
+ - Detects UVE edit mode and enables inline TinyMCE editing
308
+ - Triggers a `Save` [workflow action](https://dev.dotcms.com/docs/workflows) on blur without needing full content dialog.
309
+
310
+ #### DotCMSBlockEditorRenderer
311
+
312
+ `DotCMSBlockEditorRenderer` is a component for rendering [Block Editor](https://dev.dotcms.com/docs/block-editor) content from dotCMS with support for custom block renderers.
313
+
314
+ | Input | Type | Required | Description |
315
+ | ----------------- | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
316
+ | `blocks` | `BlockEditorContent` | ✅ | The [Block Editor](https://dev.dotcms.com/docs/block-editor) content to render |
317
+ | `customRenderers` | `CustomRenderers` | ❌ | Custom rendering functions for specific [block types](https://dev.dotcms.com/docs/block-editor#BlockTypes) |
318
+ | `className` | `string` | ❌ | CSS class to apply to the container |
319
+ | `style` | `CSSProperties` | ❌ | Inline styles for the container |
55
320
 
56
321
  #### Usage
57
322
 
58
- ```javascript
59
- import { DotCMSLayoutBody } from '@dotcms/react';
323
+ ```tsx
324
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
325
+ import { DotCMSBlockEditorRenderer } from '@dotcms/react/next';
326
+
327
+ import { MyCustomBannerBlock } from './MyCustomBannerBlock';
328
+ import { MyCustomH1 } from './MyCustomH1';
60
329
 
61
- const MyPage = ({ page }) => {
62
- return <DotCMSLayoutBody page={page} components={components} />;
330
+ const CUSTOM_RENDERERS = {
331
+ customBannerBlock: MyCustomBannerBlock,
332
+ h1: MyCustomH1
333
+ };
334
+
335
+ const DetailPage = ({ contentlet }: { contentlet: DotCMSBasicContentlet }) => {
336
+ return (
337
+ <DotCMSBlockEditorRenderer
338
+ blocks={contentlet['YOUR_BLOCK_EDITOR_FIELD']}
339
+ customRenderers={CUSTOM_RENDERERS}
340
+ />
341
+ );
63
342
  };
64
343
  ```
65
344
 
66
- ## Hooks
345
+ #### Recommendations
67
346
 
68
- ### `useDotcmsPageContext`
347
+ - Should not be used with [`DotCMSEditableText`](#dotcmseditabletext)
348
+ - Take into account the CSS cascade can affect the look and feel of your blocks.
349
+ - `DotCMSBlockEditorRenderer` only works with [Block Editor fields](https://dev.dotcms.com/docs/block-editor). For other fields, use [`DotCMSEditableText`](#dotcmseditabletext).
69
350
 
70
- A custom React hook that provides access to the `PageProviderContext`.
351
+ 📘 For advanced examples, customization options, and best practices, refer to the [DotCMSBlockEditorRenderer README](https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/react/src/lib/components/DotCMSBlockEditorRenderer).
71
352
 
72
- #### Returns
353
+ #### DotCMSShow
73
354
 
74
- - `PageProviderContext | null`: The context value or `null` if it's not available.
355
+ `DotCMSShow` is a component for conditionally rendering content based on the current UVE mode. Useful for mode-based behaviors outside of render logic.
356
+
357
+ | Input | Type | Required | Description |
358
+ | ---------- | ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
359
+ | `children` | `ReactNode` | ✅ | Content to be conditionally rendered |
360
+ | `when` | `UVE_MODE` | ✅ | The `UVE` mode when content should be displayed: <br/> `UVE_MODE.EDIT`: Only visible in edit mode <br/> `UVE_MODE.PREVIEW`: Only visible in preview mode <br/> `UVE_MODE.PUBLISHED`: Only visible in published mode |
75
361
 
76
362
  #### Usage
77
363
 
78
- ```javascript
79
- import { useDotcmsPageContext } from '@dotcms/react';
364
+ ```tsx
365
+ import { UVE_MODE } from '@dotcms/types';
366
+ import { DotCMSShow } from '@dotcms/react/next';
80
367
 
81
368
  const MyComponent = () => {
82
- const context = useDotcmsPageContext();
83
- // Use the context
369
+ return (
370
+ <DotCMSShow when={UVE_MODE.EDIT}>
371
+ <div>This will only render in UVE EDIT mode</div>
372
+ </DotCMSShow>
373
+ );
84
374
  };
85
375
  ```
86
376
 
87
- ### `usePageEditor`
377
+ 📚 Learn more about the `UVE_MODE` enum in the [dotCMS UVE Package Documentation](https://dev.dotcms.com/docs/uve).
378
+
379
+ ### useEditableDotCMSPage
88
380
 
89
- A custom React hook that sets up the page editor for a dotCMS page.
381
+ `useEditableDotCMSPage` is a hook that enables real-time page updates when using the Universal Visual Editor.
90
382
 
91
- #### Parameters
383
+ | Param | Type | Required | Description |
384
+ | -------------- | -------------------- | -------- | --------------------------------------------- |
385
+ | `pageResponse` | `DotCMSPageResponse` | ✅ | The page data object from `client.page.get()` |
92
386
 
93
- - **props**: `PageEditorOptions` - The options for the page editor. Includes a `reloadFunction` and a `pathname`.
387
+ #### Service Lifecycle & Operations
94
388
 
95
- #### Returns
389
+ When you use the hook, it:
96
390
 
97
- - `React.RefObject<HTMLDivElement>[]`: A reference to the rows of the page.
391
+ 1. Initializes the UVE with your page data
392
+ 2. Sets up communication channels with the editor
393
+ 3. Tracks content changes in real-time
394
+ 4. Updates your page automatically when:
395
+ - Content is edited inline
396
+ - Blocks are added or removed
397
+ - Layout changes are made
398
+ - Components are moved
399
+ 5. Cleans up all listeners and connections on destroy
98
400
 
99
401
  #### Usage
100
402
 
101
- ```javascript
102
- import { usePageEditor } from '@dotcms/react';
403
+ ```tsx
404
+ 'use client';
103
405
 
104
- const MyEditor = () => {
105
- const rowsRef = usePageEditor({ pathname: '/my-page' });
106
- // Use the rowsRef
406
+ import { useEditableDotCMSPage, DotCMSLayoutBody } from '@dotcms/react/next';
407
+ import type { DotCMSPageResponse } from '@dotcms/types';
408
+
409
+ const COMPONENTS_MAP = {
410
+ Blog: BlogComponent,
411
+ Product: ProductComponent
107
412
  };
413
+
414
+ export function DotCMSPage({ pageResponse }: { pageResponse: DotCMSPageResponse }) {
415
+ const { pageAsset } = useEditableDotCMSPage(pageResponse);
416
+ return <DotCMSLayoutBody pageAsset={pageAsset} components={COMPONENTS_MAP} />;
417
+ }
108
418
  ```
109
419
 
110
- ## Context Providers
420
+ #### useDotCMSShowWhen
111
421
 
112
- ### `PageProvider`
422
+ `useDotCMSShowWhen` is a hook for conditionally showing content based on the current UVE mode. Useful for mode-based behaviors outside of render logic.
113
423
 
114
- A functional component that provides a context for a dotCMS page.
424
+ | Param | Type | Required | Description |
425
+ | ------ | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
426
+ | `when` | `UVE_MODE` | ✅ | The `UVE` mode when content should be displayed: <br/> `UVE_MODE.EDIT`: Only visible in edit mode <br/> `UVE_MODE.PREVIEW`: Only visible in preview mode <br/> `UVE_MODE.PUBLISHED`: Only visible in published mode |
115
427
 
116
- #### Props
428
+ #### Usage
117
429
 
118
- - **entity**: The entity representing the page's data.
119
- - **children**: The children components.
430
+ ```tsx
431
+ import { UVE_MODE } from '@dotcms/types';
432
+ import { useDotCMSShowWhen } from '@dotcms/react/next';
120
433
 
121
- #### Usage
434
+ const MyEditButton = () => {
435
+ const isEditMode = useDotCMSShowWhen(UVE_MODE.EDIT); // returns a boolean
122
436
 
123
- ```javascript
124
- import { PageProvider } from '@dotcms/react';
437
+ if (isEditMode) {
438
+ return <button>Edit</button>;
439
+ }
125
440
 
126
- const MyApp = ({ entity }) => {
127
- return <PageProvider entity={entity}>{/* children */}</PageProvider>;
441
+ return null;
128
442
  };
129
443
  ```
130
444
 
131
- ## Contributing
445
+ ## Troubleshooting
446
+
447
+ ### Common Issues & Solutions
448
+
449
+ #### Universal Visual Editor (UVE)
450
+
451
+ 1. **UVE Not Loading**: Page loads but UVE controls are not visible
452
+ - **Possible Causes**:
453
+ - Incorrect UVE configuration
454
+ - Missing API token permissions
455
+ - Missing the `DotCMSEditablePageService` call to enable UVE.
456
+ - **Solutions**:
457
+ - Verify UVE app configuration in dotCMS admin
458
+ - Check API token has edit permissions
459
+ - Ensure `dotcmsUrl` matches your instance URL exactly
460
+
461
+ #### Missing Content
462
+
463
+ 1. **Components Not Rendering**: Empty spaces where content should appear
464
+
465
+ - **Possible Causes**:
466
+ - Missing component mappings
467
+ - Incorrect content type variable names
468
+ - **Solutions**:
469
+ - Check component registration in `components` prop
470
+ - Verify content type variable names match exactly
471
+ - Enable `development` mode for detailed logging
472
+
473
+ 2. **Asset Loading Issues**: Images or files not loading
474
+ - **Possible Causes**:
475
+ - Proxy configuration issues
476
+ - CORS restrictions
477
+ - **Solutions**:
478
+ - Verify proxy settings in `vite.config.ts`
479
+ - Check network tab for CORS errors
480
+ - Ensure `/dA` path is properly configured
481
+
482
+ #### Development Setup
483
+
484
+ 1. **Build Errors**: `npm install` fails
485
+
486
+ - **Solutions**:
487
+ - Clear npm cache: `npm cache clean --force`
488
+ - Delete `node_modules` and reinstall
489
+ - Verify Node.js version compatibility
490
+
491
+ 2. **Runtime Errors**: Console errors about missing imports or components not rendering
492
+ - **Solutions**:
493
+ - Check all imports are from `@dotcms/react/next`
494
+ - Verify all peer dependencies are installed
495
+ - Update to latest compatible versions
496
+
497
+ #### Next.js App Router Integration
498
+
499
+ 1. **Server Component Errors**: Errors about React class components in Server Components
500
+
501
+ - **Possible Causes**:
502
+ - Using dotCMS components directly in Server Components
503
+ - Missing 'use client' directive
504
+ - Incorrect data fetching pattern
505
+ - **Solutions**:
506
+
507
+ 1. Split your code into Server and Client Components:
508
+
509
+ ```tsx
510
+ // app/page.tsx (Server Component)
511
+ import { DotCMSPage } from '@/components/DotCMSPage';
512
+ import { dotCMSClient } from '@/lib/dotCMSClient';
513
+
514
+ export default async function Page() {
515
+ const pageResponse = await dotCMSClient.page.get('/index');
516
+ return <DotCMSPage pageResponse={pageResponse} />;
517
+ }
518
+ ```
519
+
520
+ ```tsx
521
+ // components/DotCMSPage.tsx (Client Component)
522
+ 'use client';
523
+
524
+ import { useEditableDotCMSPage, DotCMSLayoutBody } from '@dotcms/react/next';
525
+ import type { DotCMSPageResponse } from '@dotcms/types';
526
+
527
+ const COMPONENTS_MAP = {
528
+ Blog: BlogComponent,
529
+ Product: ProductComponent
530
+ };
531
+
532
+ export function DotCMSPage({ pageResponse }: { pageResponse: DotCMSPageResponse }) {
533
+ const { pageAsset } = useEditableDotCMSPage(pageResponse);
534
+ return <DotCMSLayoutBody pageAsset={pageAsset} components={COMPONENTS_MAP} />;
535
+ }
536
+ ```
537
+
538
+ 2. Always fetch data in Server Components for better performance
539
+ 3. Use Client Components only for rendering dotCMS interactive components
540
+
541
+ ### Debugging Tips
542
+
543
+ 1. **Enable Development Mode**
544
+
545
+ ```typescript
546
+ <dotcms-layout-body
547
+ [page]="pageAsset()"
548
+ [components]="components()"
549
+ mode="development"
550
+ />
551
+ ```
552
+
553
+ This will:
554
+
555
+ - Show detailed error messages
556
+ - Highlight unmapped components
557
+ - Log component lifecycle events
558
+
559
+ 2. **Check Browser Console**
560
+
561
+ - Check for errors in the browser console
562
+ - Check for errors in the browser network tab
563
+
564
+ 3. **Network Monitoring**
565
+ - Use browser dev tools to monitor API calls
566
+ - Check for 401/403 errors (auth issues)
567
+ - Verify asset loading paths
568
+
569
+ ### Still Having Issues?
570
+
571
+ If you're still experiencing problems after trying these solutions:
572
+
573
+ 1. Search existing [GitHub issues](https://github.com/dotCMS/core/issues)
574
+ 2. Ask questions on the [community forum](https://community.dotcms.com/) to engage with other users.
575
+ 3. Create a new issue with:
576
+ - Detailed reproduction steps
577
+ - Environment information
578
+ - Error messages
579
+ - Code samples
580
+
581
+ ## dotCMS Support
582
+
583
+ We offer multiple channels to get help with the dotCMS React SDK:
584
+
585
+ - **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
586
+ - **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
587
+ - **Stack Overflow**: Use the tag `dotcms-react` when posting questions.
588
+ - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
589
+
590
+ When reporting issues, please include:
132
591
 
133
- GitHub pull requests are the preferred method to contribute code to dotCMS. Before any pull requests can be accepted, an automated tool will ask you to agree to the [dotCMS Contributor's Agreement](https://gist.github.com/wezell/85ef45298c48494b90d92755b583acb3).
592
+ - SDK version you're using
593
+ - React version
594
+ - Minimal reproduction steps
595
+ - Expected vs. actual behavior
134
596
 
135
- ## Licensing
597
+ ## How To Contribute
136
598
 
137
- dotCMS comes in multiple editions and as such is dual licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds a number of enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://dotcms.com/cms-platform/features).
599
+ GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS UVE SDK! If you'd like to contribute, please follow these steps:
138
600
 
139
- ## Support
601
+ 1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
602
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
603
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
604
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
605
+ 5. Open a Pull Request
140
606
 
141
- If you need help or have any questions, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
607
+ Please ensure your code follows the existing style and includes appropriate tests.
142
608
 
143
- ## Documentation
609
+ ## Licensing Information
144
610
 
145
- Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
611
+ dotCMS comes in multiple editions and as such is dual-licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization, and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds several enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://www.dotcms.com/cms-platform/features).
146
612
 
147
- ## Getting Help
613
+ This SDK is part of dotCMS's dual-licensed platform (GPL 3.0 for Community, commercial license for Enterprise).
148
614
 
149
- | Source | Location |
150
- | --------------- | ------------------------------------------------------------------- |
151
- | Installation | [Installation](https://dotcms.com/docs/latest/installation) |
152
- | Documentation | [Documentation](https://dotcms.com/docs/latest/table-of-contents) |
153
- | Videos | [Helpful Videos](http://dotcms.com/videos/) |
154
- | Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
155
- | Twitter | @dotCMS |
156
- | Main Site | [dotCMS.com](https://dotcms.com/) |
615
+ [Learn more ](https://www.dotcms.com)at [dotcms.com](https://www.dotcms.com).