@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 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
- ## Features
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
- - 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.
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
- ## Components
68
+ ## Dependencies
26
69
 
27
- ### Deprecated: DotcmsLayout
70
+ This package has the following peer dependencies that you'll need to install in your project:
28
71
 
29
- **Important:** The `DotcmsLayout` component is deprecated. Please use the new [`DotCMSLayoutBody`](#DotCMSLayoutBody) component instead.
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
- #### Props
78
+ Install peer dependencies:
32
79
 
33
- - **entity**: The context for a dotCMS page.
80
+ ```bash
81
+ npm install @dotcms/uve react react-dom
82
+ ```
34
83
 
35
- #### Usage
84
+ ## Browser Compatibility
36
85
 
37
- ```javascript
38
- // Deprecated:
39
- import { DotcmsLayout } from '@dotcms/react';
86
+ The @dotcms/react package is compatible with the following browsers:
40
87
 
41
- const MyPage = ({ entity }) => {
42
- return <DotcmsLayout entity={entity} />;
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
- - **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'`.
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
- ### `BlockEditorRenderer`
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
- | Prop | Type | Description |
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
- For a more in-depth explanation of BlockEditorRenderer, visit the [documentation](./src/lib/deprecated/components/BlockEditorRenderer/BlockEditorRenderer.md).
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
- ### `useDotcmsPageContext`
161
+ ### `useDotCMSShowWhen`
90
162
 
91
- A custom React hook that provides access to the `PageProviderContext`.
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
- #### Returns
165
+ #### Parameters
94
166
 
95
- - `PageProviderContext | null`: The context value or `null` if it's not available.
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 { useDotcmsPageContext } from '@dotcms/react';
174
+ import { useDotCMSShowWhen } from '@dotcms/react';
175
+ import { UVE_MODE } from '@dotcms/uve';
101
176
 
102
177
  const MyComponent = () => {
103
- const context = useDotcmsPageContext();
104
- // Use the context
178
+ const isVisible = useDotCMSShowWhen(UVE_MODE.EDIT);
179
+
180
+ return isVisible ? <div>Visible content</div> : null;
105
181
  };
106
182
  ```
107
183
 
108
- ### `usePageEditor`
109
-
110
- A custom React hook that sets up the page editor for a dotCMS page.
111
-
112
- #### Parameters
184
+ ### `usePageAsset`
113
185
 
114
- - **props**: `PageEditorOptions` - The options for the page editor. Includes a `reloadFunction` and a `pathname`.
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
- #### Returns
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
- - `React.RefObject<HTMLDivElement>[]`: A reference to the rows of the page.
192
+ #### Parameters
119
193
 
120
- #### Usage
194
+ | Parameter | Type | Required | Description |
195
+ |-----------|------|----------|-------------|
196
+ | `currentPageAsset` | Object | Yes | The initial page asset from the server |
121
197
 
122
- ```javascript
123
- import { usePageEditor } from '@dotcms/react';
198
+ #### Implementation
124
199
 
125
- const MyEditor = () => {
126
- const rowsRef = usePageEditor({ pathname: '/my-page' });
127
- // Use the rowsRef
128
- };
129
- ```
200
+ ```typescript
201
+ import { useEffect, useState } from 'react';
130
202
 
131
- ## Context Providers
203
+ import { getUVEState, sendMessageToEditor, createUVESubscription} from '@dotcms/uve';
204
+ import { DotCMSUVEAction, UVEEventType} from '@dotcms/uve/types';
132
205
 
133
- ### `PageProvider`
206
+ export const usePageAsset = (currentPageAsset) => {
207
+ const [pageAsset, setPageAsset] = useState(null);
208
+ useEffect(() => {
209
+ if (!getUVEState()) {
210
+ return;
211
+ }
134
212
 
135
- A functional component that provides a context for a dotCMS page.
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
- #### Props
217
+ return () => {
218
+ subscription.unsubscribe();
219
+ };
220
+ }, [currentPageAsset]);
138
221
 
139
- - **entity**: The entity representing the page's data.
140
- - **children**: The children components.
222
+ return pageAsset ?? currentPageAsset;
223
+ };
224
+ ```
141
225
 
142
226
  #### Usage
143
227
 
144
- ```javascript
145
- import { PageProvider } from '@dotcms/react';
228
+ ```typescript
229
+ // Import the hook from where you saved it in your project
230
+ import { usePageAsset } from './hooks/usePageAsset';
146
231
 
147
- const MyApp = ({ entity }) => {
148
- return <PageProvider entity={entity}>{/* children */}</PageProvider>;
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).