@dotcms/react 1.5.5-next.2176 → 1.5.5-next.2245
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@ The `@dotcms/react` SDK is the DotCMS official React library. It empowers React
|
|
|
6
6
|
|
|
7
7
|
- [Prerequisites & Setup](#prerequisites--setup)
|
|
8
8
|
- [Get a dotCMS Environment](#get-a-dotcms-environment)
|
|
9
|
-
- [Create a dotCMS API Key](#create-a-dotcms-api-key)
|
|
10
9
|
- [Configure The Universal Visual Editor App](#configure-the-universal-visual-editor-app)
|
|
10
|
+
- [Create a dotCMS API Key](#create-a-dotcms-api-key)
|
|
11
11
|
- [Installation](#installation)
|
|
12
12
|
- [dotCMS Client Configuration](#dotcms-client-configuration)
|
|
13
13
|
- [Proxy Configuration for Static Assets](#proxy-configuration-for-static-assets)
|
|
@@ -15,16 +15,15 @@ The `@dotcms/react` SDK is the DotCMS official React library. It empowers React
|
|
|
15
15
|
- [Example Project](#example-project-)
|
|
16
16
|
- [SDK Reference](#sdk-reference)
|
|
17
17
|
- [DotCMSLayoutBody](#dotcmslayoutbody)
|
|
18
|
-
- [DotCMSShow](#dotcmsshow)
|
|
19
|
-
- [DotCMSBlockEditorRenderer](#dotcmsblockeditorrenderer)
|
|
20
18
|
- [DotCMSEditableText](#dotcmseditabletext)
|
|
19
|
+
- [DotCMSBlockEditorRenderer](#dotcmsblockeditorrenderer)
|
|
20
|
+
- [DotCMSShow](#dotcmsshow)
|
|
21
21
|
- [useEditableDotCMSPage](#useeditabledotcmspage)
|
|
22
22
|
- [useDotCMSShowWhen](#usedotcmsshowwhen)
|
|
23
23
|
- [useAISearch](#useaisearch)
|
|
24
24
|
- [Troubleshooting](#troubleshooting)
|
|
25
25
|
- [Common Issues & Solutions](#common-issues--solutions)
|
|
26
26
|
- [Debugging Tips](#debugging-tips)
|
|
27
|
-
- [Version Compatibility](#version-compatibility)
|
|
28
27
|
- [Still Having Issues?](#still-having-issues)
|
|
29
28
|
- [Migration from Alpha to 1.0.X](./MIGRATION.md)
|
|
30
29
|
- [Support](#support)
|
|
@@ -77,7 +76,7 @@ This integration requires an API Key with read-only permissions for security bes
|
|
|
77
76
|
|
|
78
77
|
For detailed instructions, please refer to the [dotCMS API Documentation - Read-only token](https://dev.dotcms.com/docs/rest-api-authentication#ReadOnlyToken).
|
|
79
78
|
|
|
80
|
-
###
|
|
79
|
+
### Installation
|
|
81
80
|
|
|
82
81
|
```bash
|
|
83
82
|
npm install @dotcms/react@latest
|
|
@@ -132,7 +131,7 @@ Learn more about Vite configuration [here](https://vitejs.dev/config/).
|
|
|
132
131
|
|
|
133
132
|
Once configured, image URLs in your components will automatically be proxied to your dotCMS instance:
|
|
134
133
|
|
|
135
|
-
>📚 Learn more about [Image Resizing and Processing in dotCMS with
|
|
134
|
+
>📚 Learn more about [Image Resizing and Processing in dotCMS with Angular and Next.js](https://www.dotcms.com/blog/image-resizing-and-processing-in-dotcms-with-angular-and-nextjs).
|
|
136
135
|
|
|
137
136
|
```typescript
|
|
138
137
|
// /components/my-dotcms-image.tsx
|
|
@@ -210,7 +209,7 @@ All components and hooks should be imported from `@dotcms/react`:
|
|
|
210
209
|
| ------------ | ------------------------ | -------- | -------------- | ---------------------------------------------- |
|
|
211
210
|
| `page` | `DotCMSPageAsset` | ✅ | - | The page asset containing the layout to render |
|
|
212
211
|
| `components` | `DotCMSPageComponent` | ✅ | `{}` | [Map of content type → React component](#component-mapping) |
|
|
213
|
-
| `mode` | `DotCMSPageRendererMode` | ❌ |
|
|
212
|
+
| `mode` | `DotCMSPageRendererMode` | ❌ | `'production'` | [Rendering mode ('production' or 'development')](#layout-body-modes) |
|
|
214
213
|
| `slots` | `Record<string, ReactNode>` | ❌ | `{}` | Pre-rendered server component nodes keyed by contentlet identifier. See [`buildSlots`](#buildslots). |
|
|
215
214
|
|
|
216
215
|
#### Next.js App Router
|
|
@@ -227,7 +226,7 @@ export default async function Page() {
|
|
|
227
226
|
|
|
228
227
|
```tsx
|
|
229
228
|
// PageView.tsx — "use client", owns components and renders layout
|
|
230
|
-
|
|
229
|
+
'use client';
|
|
231
230
|
|
|
232
231
|
export function PageView({ pageContent }) {
|
|
233
232
|
const { pageAsset } = useEditableDotCMSPage(pageContent);
|
|
@@ -238,11 +237,11 @@ export function PageView({ pageContent }) {
|
|
|
238
237
|
#### Usage
|
|
239
238
|
|
|
240
239
|
```tsx
|
|
241
|
-
import type {
|
|
242
|
-
import { DotCMSLayoutBody } from
|
|
240
|
+
import type { DotCMSPageResponse } from '@dotcms/types';
|
|
241
|
+
import { DotCMSLayoutBody } from '@dotcms/react';
|
|
243
242
|
|
|
244
|
-
import { MyBlogCard } from
|
|
245
|
-
import { DotCMSProductComponent } from
|
|
243
|
+
import { MyBlogCard } from './MyBlogCard';
|
|
244
|
+
import { DotCMSProductComponent } from './DotCMSProductComponent';
|
|
246
245
|
|
|
247
246
|
const COMPONENTS_MAP = {
|
|
248
247
|
Blog: MyBlogCard,
|
|
@@ -256,10 +255,10 @@ const MyPage = ({ pageAsset }: DotCMSPageResponse) => {
|
|
|
256
255
|
|
|
257
256
|
#### buildSlots
|
|
258
257
|
|
|
259
|
-
Use `buildSlots` when you have Next.js async server components that need to fetch their own data. Since async server components can
|
|
258
|
+
Use `buildSlots` when you have Next.js async server components that need to fetch their own data. Since async server components can't be called from inside a client component tree, pre-render them on the server and pass the result into the layout via `slots`:
|
|
260
259
|
|
|
261
260
|
```tsx
|
|
262
|
-
import { buildSlots, DotCMSLayoutBody } from
|
|
261
|
+
import { buildSlots, DotCMSLayoutBody } from '@dotcms/react';
|
|
263
262
|
|
|
264
263
|
// BlogListContainer is an async server component that fetches its own data
|
|
265
264
|
const slots = buildSlots(pageContent.pageAsset.containers, {
|
|
@@ -304,7 +303,7 @@ const DYNAMIC_COMPONENTS = {
|
|
|
304
303
|
| ------------ | ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
305
304
|
| `contentlet` | `T extends DotCMSBasicContentlet` | ✅ | The contentlet containing the editable field |
|
|
306
305
|
| `fieldName` | `keyof T` | ✅ | Name of the field to edit, which must be a valid key of the contentlet type `T` |
|
|
307
|
-
| `mode` | `'plain' \| 'full'` | ❌ | `plain` (default):
|
|
306
|
+
| `mode` | `'plain' \| 'full'` | ❌ | `plain` (default): Supports 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). |
|
|
308
307
|
| `format` | `'text' \| 'html'` | ❌ | `text` (default): Renders HTML tags as plain text <br/> `html`: Interprets and renders HTML markup |
|
|
309
308
|
|
|
310
309
|
#### Usage
|
|
@@ -341,7 +340,7 @@ export default MyBannerComponent;
|
|
|
341
340
|
- Detects UVE edit mode and enables inline TinyMCE editing
|
|
342
341
|
- Triggers a `Save` [workflow action](https://dev.dotcms.com/docs/workflows) on blur without needing full content dialog.
|
|
343
342
|
|
|
344
|
-
|
|
343
|
+
### DotCMSBlockEditorRenderer
|
|
345
344
|
|
|
346
345
|
`DotCMSBlockEditorRenderer` is a component for rendering [Block Editor](https://dev.dotcms.com/docs/block-editor) content from dotCMS with support for custom block renderers.
|
|
347
346
|
|
|
@@ -404,9 +403,9 @@ export default async function ArticlePage() {
|
|
|
404
403
|
- Take into account the CSS cascade can affect the look and feel of your blocks.
|
|
405
404
|
- `DotCMSBlockEditorRenderer` only works with [Block Editor fields](https://dev.dotcms.com/docs/block-editor). For other fields, use [`DotCMSEditableText`](#dotcmseditabletext).
|
|
406
405
|
|
|
407
|
-
📘 For advanced examples, customization options, and best practices, refer to the [DotCMSBlockEditorRenderer README](https://github.com/dotCMS/core/tree/
|
|
406
|
+
📘 For advanced examples, customization options, and best practices, refer to the [DotCMSBlockEditorRenderer README](https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/react/src/lib/next/components/DotCMSBlockEditorRenderer).
|
|
408
407
|
|
|
409
|
-
|
|
408
|
+
### DotCMSShow
|
|
410
409
|
|
|
411
410
|
`DotCMSShow` is a component for conditionally rendering content based on the current UVE mode. Useful for mode-based behaviors outside of render logic.
|
|
412
411
|
|
|
@@ -430,7 +429,7 @@ const MyComponent = () => {
|
|
|
430
429
|
};
|
|
431
430
|
```
|
|
432
431
|
|
|
433
|
-
📚 Learn more about the `UVE_MODE` enum in the [dotCMS UVE Package Documentation](https://dev.dotcms.com/docs/
|
|
432
|
+
📚 Learn more about the `UVE_MODE` enum in the [dotCMS UVE Package Documentation](https://dev.dotcms.com/docs/universal-visual-editor).
|
|
434
433
|
|
|
435
434
|
### useEditableDotCMSPage
|
|
436
435
|
|
|
@@ -469,11 +468,11 @@ const COMPONENTS_MAP = {
|
|
|
469
468
|
|
|
470
469
|
export function DotCMSPage({ pageResponse }: { pageResponse: DotCMSPageResponse }) {
|
|
471
470
|
const { pageAsset } = useEditableDotCMSPage(pageResponse);
|
|
472
|
-
return <DotCMSLayoutBody
|
|
471
|
+
return <DotCMSLayoutBody page={pageAsset} components={COMPONENTS_MAP} />;
|
|
473
472
|
}
|
|
474
473
|
```
|
|
475
474
|
|
|
476
|
-
|
|
475
|
+
### useDotCMSShowWhen
|
|
477
476
|
|
|
478
477
|
`useDotCMSShowWhen` is a hook for conditionally showing content based on the current UVE mode. Useful for mode-based behaviors outside of render logic.
|
|
479
478
|
|
|
@@ -643,7 +642,7 @@ export default AISearchComponent;
|
|
|
643
642
|
- **Possible Causes**:
|
|
644
643
|
- Incorrect UVE configuration
|
|
645
644
|
- Missing API token permissions
|
|
646
|
-
- Missing the `
|
|
645
|
+
- Missing the `useEditableDotCMSPage` hook to enable UVE.
|
|
647
646
|
- **Solutions**:
|
|
648
647
|
- Verify UVE app configuration in dotCMS admin
|
|
649
648
|
- Check API token has edit permissions
|
|
@@ -722,7 +721,7 @@ export default AISearchComponent;
|
|
|
722
721
|
|
|
723
722
|
export function DotCMSPage({ pageResponse }: { pageResponse: DotCMSPageResponse }) {
|
|
724
723
|
const { pageAsset } = useEditableDotCMSPage(pageResponse);
|
|
725
|
-
return <DotCMSLayoutBody
|
|
724
|
+
return <DotCMSLayoutBody page={pageAsset} components={COMPONENTS_MAP} />;
|
|
726
725
|
}
|
|
727
726
|
```
|
|
728
727
|
|
|
@@ -733,10 +732,10 @@ export default AISearchComponent;
|
|
|
733
732
|
|
|
734
733
|
1. **Enable Development Mode**
|
|
735
734
|
|
|
736
|
-
```
|
|
737
|
-
<
|
|
738
|
-
|
|
739
|
-
|
|
735
|
+
```tsx
|
|
736
|
+
<DotCMSLayoutBody
|
|
737
|
+
page={pageAsset}
|
|
738
|
+
components={COMPONENTS_MAP}
|
|
740
739
|
mode="development"
|
|
741
740
|
/>
|
|
742
741
|
```
|
|
@@ -776,7 +775,7 @@ We offer multiple channels to get help with the dotCMS React SDK:
|
|
|
776
775
|
- **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
|
|
777
776
|
- **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
|
|
778
777
|
- **Stack Overflow**: Use the tag `dotcms-react` when posting questions.
|
|
779
|
-
- **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://
|
|
778
|
+
- **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://www.dotcms.com/support).
|
|
780
779
|
|
|
781
780
|
When reporting issues, please include:
|
|
782
781
|
|
|
@@ -87,10 +87,15 @@ function DotCMSEditableText({
|
|
|
87
87
|
}
|
|
88
88
|
const {
|
|
89
89
|
oldInode,
|
|
90
|
-
inode
|
|
90
|
+
inode,
|
|
91
|
+
fieldName: focusedFieldName
|
|
91
92
|
} = payload;
|
|
92
93
|
const currentInode = contentlet.inode;
|
|
93
|
-
const
|
|
94
|
+
const matchesInode = currentInode === oldInode || currentInode === inode;
|
|
95
|
+
// Match the field too: a contentlet's fields all share one inode, so an
|
|
96
|
+
// inode-only check focuses every editable field on the contentlet (the
|
|
97
|
+
// last one wins) instead of the one the user clicked.
|
|
98
|
+
const shouldFocus = matchesInode && focusedFieldName === fieldName;
|
|
94
99
|
if (shouldFocus) {
|
|
95
100
|
var _editorRef$current2;
|
|
96
101
|
(_editorRef$current2 = editorRef.current) == null || _editorRef$current2.focus();
|
|
@@ -100,7 +105,7 @@ function DotCMSEditableText({
|
|
|
100
105
|
return () => {
|
|
101
106
|
window.removeEventListener('message', onMessage);
|
|
102
107
|
};
|
|
103
|
-
}, [contentlet == null ? void 0 : contentlet.inode]);
|
|
108
|
+
}, [contentlet == null ? void 0 : contentlet.inode, fieldName]);
|
|
104
109
|
const onMouseDown = event => {
|
|
105
110
|
var _editorRef$current3;
|
|
106
111
|
const {
|