@dotcms/react 0.0.1-beta.13 → 0.0.1-beta.15
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 +161 -79
- package/{es.regexp.to-string.esm.js → es.json.stringify.esm.js} +99 -156
- package/index.esm.js +69 -12
- package/next.esm.js +18 -232
- package/package.json +3 -3
- package/src/lib/next/__test__/mock.d.ts +1 -1
- package/src/lib/next/components/Column/Column.d.ts +1 -1
- package/src/lib/next/components/Container/Container.d.ts +1 -1
- package/src/lib/next/components/Container/ContainerFallbacks.d.ts +2 -2
- package/src/lib/next/components/Contentlet/Contentlet.d.ts +1 -1
- package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +1 -2
- package/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.d.ts +1 -4
- package/src/lib/next/components/FallbackComponent/FallbackComponent.d.ts +1 -1
- package/src/lib/next/components/Row/Row.d.ts +1 -1
- package/src/lib/next/contexts/DotCMSPageContext.d.ts +1 -2
- package/src/lib/next/hooks/useIsDevMode.d.ts +2 -5
- package/src/lib/next/types.d.ts +0 -421
- package/src/lib/next/utils/index.d.ts +0 -136
package/README.md
CHANGED
|
@@ -2,11 +2,54 @@
|
|
|
2
2
|
|
|
3
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.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> **Note:** This SDK is currently in **beta** (v0.0.1-beta.13 or newest).
|
|
6
|
+
>
|
|
7
|
+
> For comprehensive documentation, visit our [developer portal](https://dev.dotcms.com/docs/javascript-sdk-react-library).
|
|
8
|
+
|
|
9
|
+
> **⚠️ IMPORTANT:** Versions published under the `next` tag (`npm install @dotcms/react@next`) are experimental, in beta, and not code complete. For the current stable and functional version, please use `latest` (`npm install @dotcms/react@latest`). Once we release the stable version, we will provide a migration guide from the alpha to stable version. The current alpha version (under `latest`) will continue to work, allowing you to migrate progressively at your own pace.
|
|
10
|
+
|
|
11
|
+
## Table of Contents
|
|
12
|
+
|
|
13
|
+
- [What's New](#whats-new)
|
|
14
|
+
- [What's Being Deprecated](#whats-being-deprecated)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Dependencies](#dependencies)
|
|
17
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
18
|
+
- [Components](#components)
|
|
19
|
+
- [DotCMSLayoutBody](#dotcmslayoutbody)
|
|
20
|
+
- [DotCMSShow](#dotcmsshow)
|
|
21
|
+
- [BlockEditorRenderer](#blockeditorrenderer)
|
|
22
|
+
- [Hooks](#hooks)
|
|
23
|
+
- [useDotCMSShowWhen](#usedotcmsshowwhen)
|
|
24
|
+
- [usePageAsset](#usepageasset)
|
|
25
|
+
- [Making Your Page Editable](#making-your-page-editable)
|
|
26
|
+
- [Contributing](#contributing)
|
|
27
|
+
- [Licensing](#licensing)
|
|
28
|
+
- [Support](#support)
|
|
29
|
+
- [Documentation](#documentation)
|
|
30
|
+
|
|
31
|
+
## What's New?
|
|
32
|
+
|
|
33
|
+
- **Refactored Components (v0.0.1-beta.13):** Improved structure for better maintainability and performance.
|
|
34
|
+
- **New `DotCMSLayoutBody` Component (v0.0.1-beta.13):** Replaces `DotcmsLayout`, providing a more flexible approach to rendering page layouts.
|
|
35
|
+
- **Enhanced Block Editor Support (v0.0.1-beta.13):** The `BlockEditorRenderer` now supports advanced custom renderers.
|
|
36
|
+
- **Improved TypeScript Support (v0.0.1-beta.13):** Comprehensive typings for better developer experience.
|
|
37
|
+
|
|
38
|
+
Install the latest version with:
|
|
6
39
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
40
|
+
```bash
|
|
41
|
+
npm install @dotcms/react@0.0.1-beta.13
|
|
42
|
+
# or use the newest version
|
|
43
|
+
npm install @dotcms/react@latest
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## What's Being Deprecated?
|
|
47
|
+
|
|
48
|
+
- **`DotcmsLayout` Component:** Now replaced by `DotCMSLayoutBody`.
|
|
49
|
+
- **`useDotcmsPageContext` Hook:** No longer needed with the new component architecture.
|
|
50
|
+
- **`Context Providers`:** These are being phased out in favor of a more direct approach.
|
|
51
|
+
|
|
52
|
+
> **Note:** Deprecated items will continue to work and be supported, but won't receive new features or improvements. This approach allows users upgrading from alpha to beta or stable versions to update their codebase progressively without immediate breaking changes.
|
|
10
53
|
|
|
11
54
|
## Installation
|
|
12
55
|
|
|
@@ -22,26 +65,33 @@ Or using Yarn:
|
|
|
22
65
|
yarn add @dotcms/react
|
|
23
66
|
```
|
|
24
67
|
|
|
25
|
-
##
|
|
68
|
+
## Dependencies
|
|
26
69
|
|
|
27
|
-
|
|
70
|
+
This package has the following peer dependencies that you'll need to install in your project:
|
|
28
71
|
|
|
29
|
-
|
|
72
|
+
| Dependency | Version | Description |
|
|
73
|
+
|------------|---------|-------------|
|
|
74
|
+
| `@dotcms/uve` | * | Required for page editing functionality |
|
|
75
|
+
| `react` | >=16.8.0 | React library |
|
|
76
|
+
| `react-dom` | >=16.8.0 | React DOM library |
|
|
30
77
|
|
|
31
|
-
|
|
78
|
+
Install peer dependencies:
|
|
32
79
|
|
|
33
|
-
|
|
80
|
+
```bash
|
|
81
|
+
npm install @dotcms/uve react react-dom
|
|
82
|
+
```
|
|
34
83
|
|
|
35
|
-
|
|
84
|
+
## Browser Compatibility
|
|
36
85
|
|
|
37
|
-
|
|
38
|
-
// Deprecated:
|
|
39
|
-
import { DotcmsLayout } from '@dotcms/react';
|
|
86
|
+
The @dotcms/react package is compatible with the following browsers:
|
|
40
87
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
88
|
+
| Browser | Minimum Version | TLS Version |
|
|
89
|
+
|---------|----------------|-------------|
|
|
90
|
+
| Chrome | Latest 2 versions | TLS 1.2+ |
|
|
91
|
+
| Edge | Latest 2 versions | TLS 1.2+ |
|
|
92
|
+
| Firefox | Latest 2 versions | TLS 1.2+ |
|
|
93
|
+
|
|
94
|
+
## Components
|
|
45
95
|
|
|
46
96
|
### `DotCMSLayoutBody`
|
|
47
97
|
|
|
@@ -49,10 +99,11 @@ The `DotCMSLayoutBody` component renders the layout body for a DotCMS page.
|
|
|
49
99
|
|
|
50
100
|
#### Props
|
|
51
101
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
102
|
+
| Prop | Type | Required | Description |
|
|
103
|
+
|------|------|----------|-------------|
|
|
104
|
+
| `page` | Object | Yes | The DotCMS page asset containing the layout information |
|
|
105
|
+
| `components` | Object | Yes | A mapping of custom components for content rendering |
|
|
106
|
+
| `mode` | String | No | The renderer mode; defaults to `'production'` |
|
|
56
107
|
|
|
57
108
|
#### Usage
|
|
58
109
|
|
|
@@ -64,91 +115,133 @@ const MyPage = ({ page }) => {
|
|
|
64
115
|
};
|
|
65
116
|
```
|
|
66
117
|
|
|
118
|
+
### `DotCMSShow`
|
|
67
119
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
The `BlockEditorRenderer` component renders the content of a Block Editor Content Type from dotCMS.
|
|
71
|
-
[More information of Block Editor Content Type](https://dev.dotcms.com/docs/block-editor)
|
|
120
|
+
The `DotCMSShow` component conditionally renders content based on dotCMS conditions. It uses the UVE_MODE from `@dotcms/uve` which can be one of: `EDIT`, `PREVIEW`, or `LIVE`.
|
|
72
121
|
|
|
73
122
|
#### Props
|
|
74
123
|
|
|
124
|
+
| Prop | Type | Required | Description |
|
|
125
|
+
|------|------|----------|-------------|
|
|
126
|
+
| `when` | String | Yes | The condition that determines if the content should be shown (EDIT, PREVIEW, LIVE) |
|
|
127
|
+
| `children` | ReactNode | Yes | The content to be rendered when the condition is met |
|
|
128
|
+
|
|
129
|
+
#### Usage
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import { DotCMSShow } from '@dotcms/react';
|
|
133
|
+
import { UVE_MODE } from '@dotcms/uve';
|
|
134
|
+
|
|
135
|
+
const MyComponent = () => {
|
|
136
|
+
return (
|
|
137
|
+
<DotCMSShow when={UVE_MODE.EDIT}>
|
|
138
|
+
<div>This content is only visible in edit mode</div>
|
|
139
|
+
</DotCMSShow>
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### `BlockEditorRenderer`
|
|
145
|
+
|
|
146
|
+
The `BlockEditorRenderer` component renders content from a Block Editor Content Type in dotCMS.
|
|
75
147
|
|
|
76
|
-
|
|
77
|
-
|------|------|-------------|
|
|
78
|
-
| `blocks` | `Block` | The block editor content structure to render. |
|
|
79
|
-
| `customRenderers` | `CustomRenderer` | Optional custom renderers for specific block types. |
|
|
80
|
-
| `className` | `string` | Optional CSS class name to apply to the container. |
|
|
81
|
-
| `style` | `React.CSSProperties` | Optional inline styles to apply to the container. |
|
|
82
|
-
| `contentlet` | `DotCMSContentlet` | Contentlet object containing the field to be edited. Required when editable is true. |
|
|
83
|
-
| `fieldName` | `string` | Name of the field in the contentlet that contains the block editor content. Required when editable is true. |
|
|
148
|
+
#### Props
|
|
84
149
|
|
|
85
|
-
|
|
150
|
+
| Prop | Type | Required | Description |
|
|
151
|
+
|------|------|----------|-------------|
|
|
152
|
+
| `blocks` | Block | Yes | The block editor content structure to render |
|
|
153
|
+
| `customRenderers` | CustomRenderer | No | Optional custom renderers for specific block types |
|
|
154
|
+
| `className` | String | No | Optional CSS class name to apply to the container |
|
|
155
|
+
| `style` | React.CSSProperties | No | Optional inline styles to apply to the container |
|
|
156
|
+
| `contentlet` | DotCMSContentlet | Only when editable is true | Contentlet object containing the field to be edited |
|
|
157
|
+
| `fieldName` | String | Only when editable is true | Name of the field in the contentlet that contains the block editor content |
|
|
86
158
|
|
|
87
159
|
## Hooks
|
|
88
160
|
|
|
89
|
-
### `
|
|
161
|
+
### `useDotCMSShowWhen`
|
|
90
162
|
|
|
91
|
-
A custom
|
|
163
|
+
A custom hook that provides the same functionality as the `DotCMSShow` component in a hook form. It uses the UVE_MODE from `@dotcms/uve` which can be one of: `EDIT`, `PREVIEW`, or `LIVE`.
|
|
92
164
|
|
|
93
|
-
####
|
|
165
|
+
#### Parameters
|
|
94
166
|
|
|
95
|
-
|
|
167
|
+
| Parameter | Type | Required | Description |
|
|
168
|
+
|-----------|------|----------|-------------|
|
|
169
|
+
| `mode` | String | Yes | The UVE mode to check against (EDIT, PREVIEW, LIVE) |
|
|
96
170
|
|
|
97
171
|
#### Usage
|
|
98
172
|
|
|
99
173
|
```javascript
|
|
100
|
-
import {
|
|
174
|
+
import { useDotCMSShowWhen } from '@dotcms/react';
|
|
175
|
+
import { UVE_MODE } from '@dotcms/uve';
|
|
101
176
|
|
|
102
177
|
const MyComponent = () => {
|
|
103
|
-
const
|
|
104
|
-
|
|
178
|
+
const isVisible = useDotCMSShowWhen(UVE_MODE.EDIT);
|
|
179
|
+
|
|
180
|
+
return isVisible ? <div>Visible content</div> : null;
|
|
105
181
|
};
|
|
106
182
|
```
|
|
107
183
|
|
|
108
|
-
### `
|
|
109
|
-
|
|
110
|
-
A custom React hook that sets up the page editor for a dotCMS page.
|
|
111
|
-
|
|
112
|
-
#### Parameters
|
|
184
|
+
### `usePageAsset`
|
|
113
185
|
|
|
114
|
-
|
|
186
|
+
A custom hook that handles the communication with the Universal View Editor (UVE) and updates your page content in real-time when changes are made in the editor.
|
|
115
187
|
|
|
116
|
-
|
|
188
|
+
> **Note:** This hook will be built into the SDK in the stable version - the example below is a temporary workaround for the beta release.
|
|
189
|
+
>
|
|
190
|
+
> You need to save this hook in your project as a custom hook file.
|
|
117
191
|
|
|
118
|
-
|
|
192
|
+
#### Parameters
|
|
119
193
|
|
|
120
|
-
|
|
194
|
+
| Parameter | Type | Required | Description |
|
|
195
|
+
|-----------|------|----------|-------------|
|
|
196
|
+
| `currentPageAsset` | Object | Yes | The initial page asset from the server |
|
|
121
197
|
|
|
122
|
-
|
|
123
|
-
import { usePageEditor } from '@dotcms/react';
|
|
198
|
+
#### Implementation
|
|
124
199
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Use the rowsRef
|
|
128
|
-
};
|
|
129
|
-
```
|
|
200
|
+
```typescript
|
|
201
|
+
import { useEffect, useState } from 'react';
|
|
130
202
|
|
|
131
|
-
|
|
203
|
+
import { getUVEState, sendMessageToEditor, createUVESubscription} from '@dotcms/uve';
|
|
204
|
+
import { DotCMSUVEAction, UVEEventType} from '@dotcms/uve/types';
|
|
132
205
|
|
|
133
|
-
|
|
206
|
+
export const usePageAsset = (currentPageAsset) => {
|
|
207
|
+
const [pageAsset, setPageAsset] = useState(null);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (!getUVEState()) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
134
212
|
|
|
135
|
-
|
|
213
|
+
// Note: If using plain JavaScript instead of TypeScript, you can use the string literals directly
|
|
214
|
+
sendMessageToEditor({ action: DotCMSUVEAction.CLIENT_READY || "client-ready" });
|
|
215
|
+
const subscription = createUVESubscription(UVEEventType.CONTENT_CHANGES || "changes", (pageAsset) => setPageAsset(pageAsset));
|
|
136
216
|
|
|
137
|
-
|
|
217
|
+
return () => {
|
|
218
|
+
subscription.unsubscribe();
|
|
219
|
+
};
|
|
220
|
+
}, [currentPageAsset]);
|
|
138
221
|
|
|
139
|
-
|
|
140
|
-
|
|
222
|
+
return pageAsset ?? currentPageAsset;
|
|
223
|
+
};
|
|
224
|
+
```
|
|
141
225
|
|
|
142
226
|
#### Usage
|
|
143
227
|
|
|
144
|
-
```
|
|
145
|
-
|
|
228
|
+
```typescript
|
|
229
|
+
// Import the hook from where you saved it in your project
|
|
230
|
+
import { usePageAsset } from './hooks/usePageAsset';
|
|
146
231
|
|
|
147
|
-
const
|
|
148
|
-
|
|
232
|
+
const MyPage = ({ initialPageAsset }) => {
|
|
233
|
+
const pageAsset = usePageAsset(initialPageAsset);
|
|
234
|
+
|
|
235
|
+
return <DotCMSLayoutBody page={pageAsset} components={components} />;
|
|
149
236
|
};
|
|
150
237
|
```
|
|
151
238
|
|
|
239
|
+
## Making Your Page Editable
|
|
240
|
+
|
|
241
|
+
To make your page editable in dotCMS, you need to use the `usePageAsset` hook described above. This hook synchronizes your page with the Universal View Editor (UVE) and ensures that any changes made in the editor are reflected in your React application in real-time.
|
|
242
|
+
|
|
243
|
+
You need to save the hook implementation in your project (for example, in a file like `hooks/usePageAsset.js`) and import it where needed.
|
|
244
|
+
|
|
152
245
|
## Contributing
|
|
153
246
|
|
|
154
247
|
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).
|
|
@@ -163,15 +256,4 @@ If you need help or have any questions, please [open an issue](https://github.co
|
|
|
163
256
|
|
|
164
257
|
## Documentation
|
|
165
258
|
|
|
166
|
-
Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
|
|
167
|
-
|
|
168
|
-
## Getting Help
|
|
169
|
-
|
|
170
|
-
| Source | Location |
|
|
171
|
-
| --------------- | ------------------------------------------------------------------- |
|
|
172
|
-
| Installation | [Installation](https://dotcms.com/docs/latest/installation) |
|
|
173
|
-
| Documentation | [Documentation](https://dotcms.com/docs/latest/table-of-contents) |
|
|
174
|
-
| Videos | [Helpful Videos](http://dotcms.com/videos/) |
|
|
175
|
-
| Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
|
|
176
|
-
| Twitter | @dotCMS |
|
|
177
|
-
| Main Site | [dotCMS.com](https://dotcms.com/) |
|
|
259
|
+
Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references. For specific React library documentation, visit our [developer portal](https://dev.dotcms.com/docs/javascript-sdk-react-library).
|