@dotcms/react 0.0.1-beta.2 → 0.0.1-beta.21

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,85 +99,149 @@ 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'`.
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
 
58
110
  ```javascript
59
- import { DotCMSLayoutBody } from '@dotcms/react';
111
+ import { DotCMSLayoutBody } from '@dotcms/react/next';
60
112
 
61
113
  const MyPage = ({ page }) => {
62
114
  return <DotCMSLayoutBody page={page} components={components} />;
63
115
  };
64
116
  ```
65
117
 
66
- ## Hooks
67
-
68
- ### `useDotcmsPageContext`
118
+ ### `DotCMSShow`
69
119
 
70
- A custom React hook that provides access to the `PageProviderContext`.
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
- #### Returns
122
+ #### Props
73
123
 
74
- - `PageProviderContext | null`: The context value or `null` if it's not available.
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 { useDotcmsPageContext } from '@dotcms/react';
132
+ import { DotCMSShow } from '@dotcms/react/next';
133
+ import { UVE_MODE } from '@dotcms/uve';
80
134
 
81
135
  const MyComponent = () => {
82
- const context = useDotcmsPageContext();
83
- // Use the context
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
- ### `usePageEditor`
144
+ ### `BlockEditorRenderer`
88
145
 
89
- A custom React hook that sets up the page editor for a dotCMS page.
146
+ The `BlockEditorRenderer` component renders content from a Block Editor Content Type in dotCMS.
90
147
 
91
- #### Parameters
148
+ #### Props
92
149
 
93
- - **props**: `PageEditorOptions` - The options for the page editor. Includes a `reloadFunction` and a `pathname`.
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 |
94
158
 
95
- #### Returns
159
+ ## Hooks
96
160
 
97
- - `React.RefObject<HTMLDivElement>[]`: A reference to the rows of the page.
161
+ ### `useDotCMSShowWhen`
162
+
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 { usePageEditor } from '@dotcms/react';
174
+ import { useDotCMSShowWhen } from '@dotcms/react/next';
175
+ import { UVE_MODE } from '@dotcms/uve';
176
+
177
+ const MyComponent = () => {
178
+ const isVisible = useDotCMSShowWhen(UVE_MODE.EDIT);
103
179
 
104
- const MyEditor = () => {
105
- const rowsRef = usePageEditor({ pathname: '/my-page' });
106
- // Use the rowsRef
180
+ return isVisible ? <div>Visible content</div> : null;
107
181
  };
108
182
  ```
109
183
 
110
- ## Context Providers
184
+ ### `usePageAsset`
111
185
 
112
- ### `PageProvider`
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
- A functional component that provides a context for a dotCMS page.
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
- #### Props
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
- - **entity**: The entity representing the page's data.
119
- - **children**: The children components.
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
- ```javascript
124
- 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';
231
+
232
+ const MyPage = ({ initialPageAsset }) => {
233
+ const pageAsset = usePageAsset(initialPageAsset);
125
234
 
126
- const MyApp = ({ entity }) => {
127
- return <PageProvider entity={entity}>{/* children */}</PageProvider>;
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).