@dotcms/react 0.0.1-alpha.50 → 0.0.1-alpha.51
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/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useEffect, createContext, useRef, useContext, createElement as createElement$1, forwardRef } from 'react';
|
|
3
|
-
import { isInsideEditor, initEditor, updateNavigation, destroyEditor, DotCmsClient, postMessageToEditor, CLIENT_ACTIONS, NOTIFY_CLIENT } from '@dotcms/client';
|
|
3
|
+
import { isInsideEditor, initEditor, updateNavigation, destroyEditor, DotCmsClient, postMessageToEditor, CLIENT_ACTIONS, NOTIFY_CLIENT, initInlineEditing } from '@dotcms/client';
|
|
4
4
|
import { Editor } from '@tinymce/tinymce-react';
|
|
5
5
|
|
|
6
6
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -5187,17 +5187,57 @@ const BlockEditorBlock = ({
|
|
|
5187
5187
|
* @param {CustomRenderer} [props.customRenderers] - Optional custom renderers for specific block types.
|
|
5188
5188
|
* @param {string} [props.className] - Optional CSS class name for the container div.
|
|
5189
5189
|
* @param {React.CSSProperties} [props.style] - Optional inline styles for the container div.
|
|
5190
|
+
* @param {boolean} props.editable - Flag to enable inline editing. When true, `contentlet` and `fieldName` are required. Note: Enterprise only feature.
|
|
5191
|
+
* @param {DotCMSContentlet} [props.contentlet] - Contentlet object for inline editing. Required when `editable` is true.
|
|
5192
|
+
* @param {string} [props.fieldName] - Field name for inline editing. Required when `editable` is true.
|
|
5190
5193
|
* @returns {JSX.Element} A div containing the rendered blocks of content.
|
|
5191
5194
|
*/
|
|
5192
5195
|
const BlockEditorRenderer = ({
|
|
5196
|
+
style,
|
|
5193
5197
|
blocks,
|
|
5194
|
-
|
|
5198
|
+
editable,
|
|
5199
|
+
fieldName,
|
|
5195
5200
|
className,
|
|
5196
|
-
|
|
5201
|
+
contentlet,
|
|
5202
|
+
customRenderers
|
|
5197
5203
|
}) => {
|
|
5204
|
+
const ref = useRef(null);
|
|
5205
|
+
useEffect(() => {
|
|
5206
|
+
if (!editable || !ref.current || !isInsideEditor()) {
|
|
5207
|
+
return;
|
|
5208
|
+
}
|
|
5209
|
+
// TypeScript will throw an error if contentlet or fieldName are not provided when editable is true,
|
|
5210
|
+
// but we need to check them again to avoid runtime errors in Pure JavaScript
|
|
5211
|
+
if (!contentlet || !fieldName) {
|
|
5212
|
+
console.error('contentlet and fieldName are required to enable inline editing');
|
|
5213
|
+
return;
|
|
5214
|
+
}
|
|
5215
|
+
const {
|
|
5216
|
+
inode,
|
|
5217
|
+
languageId: language,
|
|
5218
|
+
contentType
|
|
5219
|
+
} = contentlet;
|
|
5220
|
+
// `ContentNode` lives on `@dotcms/react` that's why we can use it in `@dotcms/client`
|
|
5221
|
+
// We need to move interfaces to external lib
|
|
5222
|
+
const content = blocks;
|
|
5223
|
+
const element = ref.current;
|
|
5224
|
+
const handleClickEvent = () => {
|
|
5225
|
+
initInlineEditing('BLOCK_EDITOR', {
|
|
5226
|
+
inode,
|
|
5227
|
+
content,
|
|
5228
|
+
language,
|
|
5229
|
+
fieldName,
|
|
5230
|
+
contentType
|
|
5231
|
+
});
|
|
5232
|
+
};
|
|
5233
|
+
element.addEventListener('click', handleClickEvent);
|
|
5234
|
+
return () => element.removeEventListener('click', handleClickEvent);
|
|
5235
|
+
}, [editable, contentlet, blocks, fieldName]);
|
|
5198
5236
|
return jsx("div", {
|
|
5199
5237
|
className: className,
|
|
5200
5238
|
style: style,
|
|
5239
|
+
ref: ref,
|
|
5240
|
+
"data-testid": "dot-block-editor-container",
|
|
5201
5241
|
children: jsx(BlockEditorBlock, {
|
|
5202
5242
|
content: blocks.content,
|
|
5203
5243
|
customRenderers: customRenderers
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/react",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.51",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=18",
|
|
6
6
|
"react-dom": ">=18",
|
|
7
|
-
"@dotcms/client": "0.0.1-alpha.
|
|
7
|
+
"@dotcms/client": "0.0.1-alpha.51",
|
|
8
8
|
"@tinymce/tinymce-react": "^5.1.1"
|
|
9
9
|
},
|
|
10
10
|
"description": "Official React Components library to render a dotCMS page.",
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { DotCMSContentlet } from '../../models';
|
|
2
3
|
import { Block } from '../../models/blocks.interface';
|
|
3
4
|
import { CustomRenderer } from '../../models/content-node.interface';
|
|
4
|
-
|
|
5
|
+
interface BaseProps {
|
|
5
6
|
blocks: Block;
|
|
6
7
|
customRenderers?: CustomRenderer;
|
|
7
8
|
className?: string;
|
|
8
9
|
style?: React.CSSProperties;
|
|
9
10
|
}
|
|
11
|
+
interface EditableProps extends BaseProps {
|
|
12
|
+
editable: true;
|
|
13
|
+
contentlet: DotCMSContentlet;
|
|
14
|
+
fieldName: string;
|
|
15
|
+
}
|
|
16
|
+
interface NonEditableProps extends BaseProps {
|
|
17
|
+
editable?: false;
|
|
18
|
+
contentlet?: never;
|
|
19
|
+
fieldName?: never;
|
|
20
|
+
}
|
|
21
|
+
type BlockEditorRendererProps = EditableProps | NonEditableProps;
|
|
10
22
|
/**
|
|
11
23
|
* BlockEditorRenderer component for rendering block editor field.
|
|
12
24
|
*
|
|
@@ -16,6 +28,10 @@ export interface BlockEditorRendererProps {
|
|
|
16
28
|
* @param {CustomRenderer} [props.customRenderers] - Optional custom renderers for specific block types.
|
|
17
29
|
* @param {string} [props.className] - Optional CSS class name for the container div.
|
|
18
30
|
* @param {React.CSSProperties} [props.style] - Optional inline styles for the container div.
|
|
31
|
+
* @param {boolean} props.editable - Flag to enable inline editing. When true, `contentlet` and `fieldName` are required. Note: Enterprise only feature.
|
|
32
|
+
* @param {DotCMSContentlet} [props.contentlet] - Contentlet object for inline editing. Required when `editable` is true.
|
|
33
|
+
* @param {string} [props.fieldName] - Field name for inline editing. Required when `editable` is true.
|
|
19
34
|
* @returns {JSX.Element} A div containing the rendered blocks of content.
|
|
20
35
|
*/
|
|
21
|
-
export declare const BlockEditorRenderer: ({ blocks,
|
|
36
|
+
export declare const BlockEditorRenderer: ({ style, blocks, editable, fieldName, className, contentlet, customRenderers }: BlockEditorRendererProps) => import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export {};
|