@dotcms/react 0.0.1-beta.2 → 0.0.1-beta.20
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 +164 -61
- package/{es.regexp.to-string.esm.js → es.json.stringify.esm.js} +99 -156
- package/index.esm.js +81 -20
- package/next.esm.js +105 -246
- package/package.json +24 -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/{ContainerFallbakcs.d.ts → 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 +4 -15
- package/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.d.ts +1 -4
- package/src/lib/next/components/DotCMSShow/DotCMSShow.d.ts +49 -0
- 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/useDotCMSShowWhen.d.ts +31 -0
- package/src/lib/next/hooks/useIsDevMode.d.ts +2 -5
- package/src/next.d.ts +2 -0
- 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,9 +99,11 @@ The `DotCMSLayoutBody` component renders the layout body for a DotCMS page.
|
|
|
49
99
|
|
|
50
100
|
#### Props
|
|
51
101
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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'` |
|
|
55
107
|
|
|
56
108
|
#### Usage
|
|
57
109
|
|
|
@@ -63,71 +115,133 @@ const MyPage = ({ page }) => {
|
|
|
63
115
|
};
|
|
64
116
|
```
|
|
65
117
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### `useDotcmsPageContext`
|
|
118
|
+
### `DotCMSShow`
|
|
69
119
|
|
|
70
|
-
|
|
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`.
|
|
71
121
|
|
|
72
|
-
####
|
|
122
|
+
#### Props
|
|
73
123
|
|
|
74
|
-
|
|
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 |
|
|
75
128
|
|
|
76
129
|
#### Usage
|
|
77
130
|
|
|
78
131
|
```javascript
|
|
79
|
-
import {
|
|
132
|
+
import { DotCMSShow } from '@dotcms/react';
|
|
133
|
+
import { UVE_MODE } from '@dotcms/uve';
|
|
80
134
|
|
|
81
135
|
const MyComponent = () => {
|
|
82
|
-
|
|
83
|
-
|
|
136
|
+
return (
|
|
137
|
+
<DotCMSShow when={UVE_MODE.EDIT}>
|
|
138
|
+
<div>This content is only visible in edit mode</div>
|
|
139
|
+
</DotCMSShow>
|
|
140
|
+
);
|
|
84
141
|
};
|
|
85
142
|
```
|
|
86
143
|
|
|
87
|
-
### `
|
|
144
|
+
### `BlockEditorRenderer`
|
|
88
145
|
|
|
89
|
-
|
|
146
|
+
The `BlockEditorRenderer` component renders content from a Block Editor Content Type in dotCMS.
|
|
90
147
|
|
|
91
|
-
####
|
|
148
|
+
#### Props
|
|
92
149
|
|
|
93
|
-
|
|
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 |
|
|
158
|
+
|
|
159
|
+
## Hooks
|
|
94
160
|
|
|
95
|
-
|
|
161
|
+
### `useDotCMSShowWhen`
|
|
96
162
|
|
|
97
|
-
|
|
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`.
|
|
164
|
+
|
|
165
|
+
#### Parameters
|
|
166
|
+
|
|
167
|
+
| Parameter | Type | Required | Description |
|
|
168
|
+
|-----------|------|----------|-------------|
|
|
169
|
+
| `mode` | String | Yes | The UVE mode to check against (EDIT, PREVIEW, LIVE) |
|
|
98
170
|
|
|
99
171
|
#### Usage
|
|
100
172
|
|
|
101
173
|
```javascript
|
|
102
|
-
import {
|
|
174
|
+
import { useDotCMSShowWhen } from '@dotcms/react';
|
|
175
|
+
import { UVE_MODE } from '@dotcms/uve';
|
|
103
176
|
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
|
|
177
|
+
const MyComponent = () => {
|
|
178
|
+
const isVisible = useDotCMSShowWhen(UVE_MODE.EDIT);
|
|
179
|
+
|
|
180
|
+
return isVisible ? <div>Visible content</div> : null;
|
|
107
181
|
};
|
|
108
182
|
```
|
|
109
183
|
|
|
110
|
-
|
|
184
|
+
### `usePageAsset`
|
|
111
185
|
|
|
112
|
-
|
|
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.
|
|
113
187
|
|
|
114
|
-
|
|
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.
|
|
115
191
|
|
|
116
|
-
####
|
|
192
|
+
#### Parameters
|
|
193
|
+
|
|
194
|
+
| Parameter | Type | Required | Description |
|
|
195
|
+
|-----------|------|----------|-------------|
|
|
196
|
+
| `currentPageAsset` | Object | Yes | The initial page asset from the server |
|
|
197
|
+
|
|
198
|
+
#### Implementation
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import { useEffect, useState } from 'react';
|
|
202
|
+
|
|
203
|
+
import { getUVEState, sendMessageToEditor, createUVESubscription} from '@dotcms/uve';
|
|
204
|
+
import { DotCMSUVEAction, UVEEventType} from '@dotcms/uve/types';
|
|
205
|
+
|
|
206
|
+
export const usePageAsset = (currentPageAsset) => {
|
|
207
|
+
const [pageAsset, setPageAsset] = useState(null);
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (!getUVEState()) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
117
212
|
|
|
118
|
-
|
|
119
|
-
-
|
|
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));
|
|
216
|
+
|
|
217
|
+
return () => {
|
|
218
|
+
subscription.unsubscribe();
|
|
219
|
+
};
|
|
220
|
+
}, [currentPageAsset]);
|
|
221
|
+
|
|
222
|
+
return pageAsset ?? currentPageAsset;
|
|
223
|
+
};
|
|
224
|
+
```
|
|
120
225
|
|
|
121
226
|
#### Usage
|
|
122
227
|
|
|
123
|
-
```
|
|
124
|
-
|
|
228
|
+
```typescript
|
|
229
|
+
// Import the hook from where you saved it in your project
|
|
230
|
+
import { usePageAsset } from './hooks/usePageAsset';
|
|
125
231
|
|
|
126
|
-
const
|
|
127
|
-
|
|
232
|
+
const MyPage = ({ initialPageAsset }) => {
|
|
233
|
+
const pageAsset = usePageAsset(initialPageAsset);
|
|
234
|
+
|
|
235
|
+
return <DotCMSLayoutBody page={pageAsset} components={components} />;
|
|
128
236
|
};
|
|
129
237
|
```
|
|
130
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
|
+
|
|
131
245
|
## Contributing
|
|
132
246
|
|
|
133
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).
|
|
@@ -142,15 +256,4 @@ If you need help or have any questions, please [open an issue](https://github.co
|
|
|
142
256
|
|
|
143
257
|
## Documentation
|
|
144
258
|
|
|
145
|
-
Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
|
|
146
|
-
|
|
147
|
-
## Getting Help
|
|
148
|
-
|
|
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/) |
|
|
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).
|