@dotcms/react 0.0.1-beta.3 → 0.0.1-beta.5
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 +11 -8
- package/next.esm.js +87 -14
- package/package.json +3 -3
- package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +3 -13
- package/src/lib/next/components/DotCMSShow/DotCMSShow.d.ts +49 -0
- package/src/lib/next/hooks/useShowInUVE.d.ts +31 -0
- package/src/next.d.ts +2 -0
package/index.esm.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { s as styleInject, f as functionUncurryThis, t as toString$4, r as requireObjectCoercible$1, a as toIntegerOrInfinity$1, i as iteratorDefine, b as internalState, c as createIterResultObject$2, d as fails$2, w as wellKnownSymbol$4, e as descriptors, g as classofRaw$1, h as aCallable$2, j as functionBindNative, m as makeBuiltInExports, o as objectDefineProperty, k as objectIsPrototypeOf, l as functionCall, n as anObject$4, p as getMethod$2, q as iterators, u as getBuiltIn$1, v as isCallable$2, x as classof$3, y as inspectSource$1, z as createPropertyDescriptor$2, A as isNullOrUndefined$1, B as tryToString$1, C as toObject$1, D as lengthOfArrayLike$1, E as global$3, F as defineBuiltIn$5, G as arraySlice$2, _ as _export, H as setToStringTag$2, I as iteratorCreateConstructor, J as isObject$1, K as objectCreate, L as hasOwnProperty_1, M as objectAssign } from './es.regexp.to-string.esm.js';
|
|
3
3
|
import { useState, useEffect, createContext, useRef, useContext, createElement, forwardRef } from 'react';
|
|
4
|
-
import { isInsideEditor, initEditor, updateNavigation, destroyEditor,
|
|
4
|
+
import { isInsideEditor, initEditor, updateNavigation, destroyEditor, postMessageToEditor, CLIENT_ACTIONS, DotCmsClient, NOTIFY_CLIENT, initInlineEditing } from '@dotcms/client';
|
|
5
|
+
import { createUVESubscription } from '@dotcms/uve';
|
|
5
6
|
import { Editor } from '@tinymce/tinymce-react';
|
|
6
7
|
|
|
7
8
|
var isPure = false;
|
|
@@ -49,12 +50,13 @@ const useDotcmsEditor = ({
|
|
|
49
50
|
*/
|
|
50
51
|
useEffect(() => {
|
|
51
52
|
const insideEditor = isInsideEditor();
|
|
52
|
-
const client = DotCmsClient.instance;
|
|
53
53
|
if (!insideEditor || !onReload) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const {
|
|
57
|
+
unsubscribe
|
|
58
|
+
} = createUVESubscription('changes', () => onReload());
|
|
59
|
+
return () => unsubscribe();
|
|
58
60
|
}, [onReload]);
|
|
59
61
|
/**
|
|
60
62
|
* Sends a message to the editor when the client is ready.
|
|
@@ -69,20 +71,21 @@ const useDotcmsEditor = ({
|
|
|
69
71
|
});
|
|
70
72
|
}, [pathname, editor]);
|
|
71
73
|
/**
|
|
72
|
-
*
|
|
74
|
+
* Old
|
|
73
75
|
*/
|
|
74
76
|
useEffect(() => {
|
|
75
77
|
if (!isInsideEditor()) {
|
|
76
78
|
return;
|
|
77
79
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
+
const {
|
|
81
|
+
unsubscribe
|
|
82
|
+
} = createUVESubscription('changes', data => {
|
|
80
83
|
const pageAsset = data;
|
|
81
84
|
setState(state => Object.assign({}, state, {
|
|
82
85
|
pageAsset
|
|
83
86
|
}));
|
|
84
87
|
});
|
|
85
|
-
return () =>
|
|
88
|
+
return () => unsubscribe();
|
|
86
89
|
}, []);
|
|
87
90
|
return state;
|
|
88
91
|
};
|
package/next.esm.js
CHANGED
|
@@ -614,28 +614,18 @@ const Row = ({
|
|
|
614
614
|
/**
|
|
615
615
|
* DotCMSLayoutBody component renders the layout body for a DotCMS page.
|
|
616
616
|
*
|
|
617
|
-
* It utilizes the page asset's layout body to render
|
|
618
|
-
* If the layout body does not exist, it renders an error message
|
|
619
|
-
* It also provides context (DotCMSPageContext) with the page asset, optional user components,
|
|
620
|
-
* and the renderer mode to its children.
|
|
617
|
+
* It utilizes the dotCMS page asset's layout body to render the page body.
|
|
618
|
+
* If the layout body does not exist, it renders an error message in the mode is `development`.
|
|
621
619
|
*
|
|
622
620
|
* @public
|
|
623
621
|
* @component
|
|
624
622
|
* @param {Object} props - Component properties.
|
|
625
623
|
* @param {DotCMSPageAsset} props.page - The DotCMS page asset containing the layout information.
|
|
626
|
-
* @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] -
|
|
624
|
+
* @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] - mapping of custom components for content rendering.
|
|
627
625
|
* @param {DotCMSPageRendererMode} [props.mode='production'] - The renderer mode; defaults to 'production'. Alternate modes might trigger different behaviors.
|
|
628
626
|
*
|
|
629
627
|
* @returns {JSX.Element} The rendered DotCMS page body or an error message if the layout body is missing.
|
|
630
628
|
*
|
|
631
|
-
* -------------------------------------------------------------------
|
|
632
|
-
*
|
|
633
|
-
* El componente DotCMSLayoutBody renderiza el cuerpo del layout para una página de DotCMS.
|
|
634
|
-
*
|
|
635
|
-
* Utiliza el "body" del layout del asset de la página para renderizar las filas mediante el componente Row.
|
|
636
|
-
* Si el "body" del layout no está presente, renderiza un mensaje de error.
|
|
637
|
-
* También provee un contexto (DotCMSPageContext) con el asset de la página, componentes de usuario opcionales,
|
|
638
|
-
* y el modo del renderizado para sus componentes hijos.
|
|
639
629
|
*/
|
|
640
630
|
const DotCMSLayoutBody = ({
|
|
641
631
|
page,
|
|
@@ -662,4 +652,87 @@ const DotCMSLayoutBody = ({
|
|
|
662
652
|
});
|
|
663
653
|
};
|
|
664
654
|
|
|
665
|
-
|
|
655
|
+
/**
|
|
656
|
+
* Custom hook to determine if the current UVE (Universal Visual Editor) mode
|
|
657
|
+
* matches the specified mode. This hook is useful for conditionally rendering
|
|
658
|
+
* components based on the UVE mode.
|
|
659
|
+
*
|
|
660
|
+
* @param {UVE_MODE} when - The UVE mode to check against.
|
|
661
|
+
* @returns {boolean} True if the current UVE mode matches the specified mode, otherwise false.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* // Basic usage: Check if the UVE is in edit mode
|
|
665
|
+
* const showInEditMode = useShowInUVE(UVE_MODE.EDIT);
|
|
666
|
+
* if (showInEditMode) {
|
|
667
|
+
* // Render edit-specific components
|
|
668
|
+
* }
|
|
669
|
+
*
|
|
670
|
+
* @example
|
|
671
|
+
* // Check if the UVE is in preview mode
|
|
672
|
+
* const showInPreviewMode = useShowInUVE(UVE_MODE.PREVIEW);
|
|
673
|
+
* if (showInPreviewMode) {
|
|
674
|
+
* // Render preview-specific components
|
|
675
|
+
* }
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* // Check if the UVE is in live mode
|
|
679
|
+
* const showInLiveMode = useShowInUVE(UVE_MODE.LIVE);
|
|
680
|
+
* if (showInLiveMode) {
|
|
681
|
+
* // Render live-specific components
|
|
682
|
+
* }
|
|
683
|
+
*/
|
|
684
|
+
const useShowInUVE = when => {
|
|
685
|
+
const [show, setShow] = useState(false);
|
|
686
|
+
useEffect(() => {
|
|
687
|
+
var _getUVEState;
|
|
688
|
+
setShow(((_getUVEState = getUVEState()) == null ? void 0 : _getUVEState.mode) === when);
|
|
689
|
+
}, [when]);
|
|
690
|
+
return show;
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* DotCMSShow component is used to conditionally render its children
|
|
695
|
+
* based on the Universal Visual Editor (UVE) mode. It checks if the UVE
|
|
696
|
+
* is in a specified mode and only renders its children in that case.
|
|
697
|
+
*
|
|
698
|
+
* @param {Object} props - The component props.
|
|
699
|
+
* @param {React.ReactNode} props.children - The children to be rendered when the condition is met.
|
|
700
|
+
* @param {UVE_MODE} [props.when=UVE_MODE.EDIT] - The UVE mode in which the children should be rendered.
|
|
701
|
+
* @returns {React.ReactNode | null} The children if the current UVE mode matches the `when` prop, otherwise null.
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
* // Basic usage: Render content only in edit mode
|
|
705
|
+
* <DotCMSShow when={UVE_MODE.EDIT}>
|
|
706
|
+
* <div>Edit Mode Content</div>
|
|
707
|
+
* </DotCMSShow>
|
|
708
|
+
*
|
|
709
|
+
* // This will render <div>Edit Mode Content</div> only if the UVE is in edit mode.
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* // Render content in preview mode
|
|
713
|
+
* <DotCMSShow when={UVE_MODE.PREVIEW}>
|
|
714
|
+
* <MyCustomPreviewComponent />
|
|
715
|
+
* </DotCMSShow>
|
|
716
|
+
*
|
|
717
|
+
* // MyCustomPreviewComponent will only be rendered if the UVE is in preview mode.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* // Render content in live mode
|
|
721
|
+
* <DotCMSShow when={UVE_MODE.LIVE}>
|
|
722
|
+
* <LiveContentComponent />
|
|
723
|
+
* </DotCMSShow>
|
|
724
|
+
*
|
|
725
|
+
* // LiveContentComponent will only be rendered if the UVE is in live mode.
|
|
726
|
+
*/
|
|
727
|
+
const DotCMSShow = ({
|
|
728
|
+
children,
|
|
729
|
+
when: _when = UVE_MODE.EDIT
|
|
730
|
+
}) => {
|
|
731
|
+
const show = useShowInUVE(_when);
|
|
732
|
+
if (!show) {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
return children;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
export { DotCMSLayoutBody, DotCMSShow, useShowInUVE };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/react",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.5",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=18",
|
|
6
6
|
"react-dom": ">=18",
|
|
7
|
-
"@dotcms/client": "0.0.1-beta.
|
|
8
|
-
"@dotcms/uve": "0.0.1-beta.
|
|
7
|
+
"@dotcms/client": "0.0.1-beta.5",
|
|
8
|
+
"@dotcms/uve": "0.0.1-beta.5",
|
|
9
9
|
"@tinymce/tinymce-react": "^5.1.1"
|
|
10
10
|
},
|
|
11
11
|
"description": "Official React Components library to render a dotCMS page.",
|
|
@@ -9,28 +9,18 @@ interface DotCMSLayoutBodyProps {
|
|
|
9
9
|
/**
|
|
10
10
|
* DotCMSLayoutBody component renders the layout body for a DotCMS page.
|
|
11
11
|
*
|
|
12
|
-
* It utilizes the page asset's layout body to render
|
|
13
|
-
* If the layout body does not exist, it renders an error message
|
|
14
|
-
* It also provides context (DotCMSPageContext) with the page asset, optional user components,
|
|
15
|
-
* and the renderer mode to its children.
|
|
12
|
+
* It utilizes the dotCMS page asset's layout body to render the page body.
|
|
13
|
+
* If the layout body does not exist, it renders an error message in the mode is `development`.
|
|
16
14
|
*
|
|
17
15
|
* @public
|
|
18
16
|
* @component
|
|
19
17
|
* @param {Object} props - Component properties.
|
|
20
18
|
* @param {DotCMSPageAsset} props.page - The DotCMS page asset containing the layout information.
|
|
21
|
-
* @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] -
|
|
19
|
+
* @param {Record<string, React.ComponentType<DotCMSContentlet>>} [props.components] - mapping of custom components for content rendering.
|
|
22
20
|
* @param {DotCMSPageRendererMode} [props.mode='production'] - The renderer mode; defaults to 'production'. Alternate modes might trigger different behaviors.
|
|
23
21
|
*
|
|
24
22
|
* @returns {JSX.Element} The rendered DotCMS page body or an error message if the layout body is missing.
|
|
25
23
|
*
|
|
26
|
-
* -------------------------------------------------------------------
|
|
27
|
-
*
|
|
28
|
-
* El componente DotCMSLayoutBody renderiza el cuerpo del layout para una página de DotCMS.
|
|
29
|
-
*
|
|
30
|
-
* Utiliza el "body" del layout del asset de la página para renderizar las filas mediante el componente Row.
|
|
31
|
-
* Si el "body" del layout no está presente, renderiza un mensaje de error.
|
|
32
|
-
* También provee un contexto (DotCMSPageContext) con el asset de la página, componentes de usuario opcionales,
|
|
33
|
-
* y el modo del renderizado para sus componentes hijos.
|
|
34
24
|
*/
|
|
35
25
|
export declare const DotCMSLayoutBody: ({ page, components, mode }: DotCMSLayoutBodyProps) => import("react/jsx-runtime").JSX.Element;
|
|
36
26
|
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { UVE_MODE } from '@dotcms/uve/types';
|
|
3
|
+
/**
|
|
4
|
+
* Props for the DotCMSShow component.
|
|
5
|
+
*
|
|
6
|
+
* @typedef {Object} DotCMSShowProps
|
|
7
|
+
* @property {React.ReactNode} children - The children to be rendered when the condition is met.
|
|
8
|
+
* @property {UVE_MODE} [when=UVE_MODE.EDIT] - The UVE mode in which the children should be rendered.
|
|
9
|
+
*/
|
|
10
|
+
type DotCMSShowProps = {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
when?: UVE_MODE;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* DotCMSShow component is used to conditionally render its children
|
|
16
|
+
* based on the Universal Visual Editor (UVE) mode. It checks if the UVE
|
|
17
|
+
* is in a specified mode and only renders its children in that case.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} props - The component props.
|
|
20
|
+
* @param {React.ReactNode} props.children - The children to be rendered when the condition is met.
|
|
21
|
+
* @param {UVE_MODE} [props.when=UVE_MODE.EDIT] - The UVE mode in which the children should be rendered.
|
|
22
|
+
* @returns {React.ReactNode | null} The children if the current UVE mode matches the `when` prop, otherwise null.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Basic usage: Render content only in edit mode
|
|
26
|
+
* <DotCMSShow when={UVE_MODE.EDIT}>
|
|
27
|
+
* <div>Edit Mode Content</div>
|
|
28
|
+
* </DotCMSShow>
|
|
29
|
+
*
|
|
30
|
+
* // This will render <div>Edit Mode Content</div> only if the UVE is in edit mode.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Render content in preview mode
|
|
34
|
+
* <DotCMSShow when={UVE_MODE.PREVIEW}>
|
|
35
|
+
* <MyCustomPreviewComponent />
|
|
36
|
+
* </DotCMSShow>
|
|
37
|
+
*
|
|
38
|
+
* // MyCustomPreviewComponent will only be rendered if the UVE is in preview mode.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Render content in live mode
|
|
42
|
+
* <DotCMSShow when={UVE_MODE.LIVE}>
|
|
43
|
+
* <LiveContentComponent />
|
|
44
|
+
* </DotCMSShow>
|
|
45
|
+
*
|
|
46
|
+
* // LiveContentComponent will only be rendered if the UVE is in live mode.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DotCMSShow: ({ children, when }: DotCMSShowProps) => import("react").ReactNode;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UVE_MODE } from '@dotcms/uve/types';
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook to determine if the current UVE (Universal Visual Editor) mode
|
|
4
|
+
* matches the specified mode. This hook is useful for conditionally rendering
|
|
5
|
+
* components based on the UVE mode.
|
|
6
|
+
*
|
|
7
|
+
* @param {UVE_MODE} when - The UVE mode to check against.
|
|
8
|
+
* @returns {boolean} True if the current UVE mode matches the specified mode, otherwise false.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Basic usage: Check if the UVE is in edit mode
|
|
12
|
+
* const showInEditMode = useShowInUVE(UVE_MODE.EDIT);
|
|
13
|
+
* if (showInEditMode) {
|
|
14
|
+
* // Render edit-specific components
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Check if the UVE is in preview mode
|
|
19
|
+
* const showInPreviewMode = useShowInUVE(UVE_MODE.PREVIEW);
|
|
20
|
+
* if (showInPreviewMode) {
|
|
21
|
+
* // Render preview-specific components
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Check if the UVE is in live mode
|
|
26
|
+
* const showInLiveMode = useShowInUVE(UVE_MODE.LIVE);
|
|
27
|
+
* if (showInLiveMode) {
|
|
28
|
+
* // Render live-specific components
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
export declare const useShowInUVE: (when: UVE_MODE) => boolean;
|
package/src/next.d.ts
CHANGED