@dotcms/react 0.0.1-alpha.17 → 0.0.1-alpha.19

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
@@ -1646,11 +1646,11 @@ const PageContext = /*#__PURE__*/createContext(null);
1646
1646
  */
1647
1647
  function PageProvider(props) {
1648
1648
  const {
1649
- entity,
1649
+ pageContext,
1650
1650
  children
1651
1651
  } = props;
1652
1652
  return jsx(PageContext.Provider, {
1653
- value: entity,
1653
+ value: pageContext,
1654
1654
  children: children
1655
1655
  });
1656
1656
  }
@@ -1752,7 +1752,7 @@ var css_248z = ".column-module_col-start-1__GK-q- {\n grid-column-start: 1;\n
1752
1752
  var styles = {"col-start-1":"column-module_col-start-1__GK-q-","col-start-2":"column-module_col-start-2__1DmkY","col-start-3":"column-module_col-start-3__HNEPh","col-start-4":"column-module_col-start-4__oCAwh","col-start-5":"column-module_col-start-5__re1rB","col-start-6":"column-module_col-start-6__dkB4w","col-start-7":"column-module_col-start-7__kEfJb","col-start-8":"column-module_col-start-8__Yx31z","col-start-9":"column-module_col-start-9__9YiVY","col-start-10":"column-module_col-start-10__6AFbk","col-start-11":"column-module_col-start-11__LP24D","col-start-12":"column-module_col-start-12__8p0QS","col-end-1":"column-module_col-end-1__G9axv","col-end-2":"column-module_col-end-2__pYjHG","col-end-3":"column-module_col-end-3__4woe6","col-end-4":"column-module_col-end-4__zlBaT","col-end-5":"column-module_col-end-5__aC-y8","col-end-6":"column-module_col-end-6__YljAP","col-end-7":"column-module_col-end-7__lpQrW","col-end-8":"column-module_col-end-8__F6UVd","col-end-9":"column-module_col-end-9__kvQ3T","col-end-10":"column-module_col-end-10__XJhrd","col-end-11":"column-module_col-end-11__nx-lF","col-end-12":"column-module_col-end-12__LIRnk","col-end-13":"column-module_col-end-13__0p7YI"};
1753
1753
  styleInject(css_248z);
1754
1754
 
1755
- function NoContent({
1755
+ function NoComponent({
1756
1756
  contentType
1757
1757
  }) {
1758
1758
  return jsxs("div", {
@@ -1760,6 +1760,9 @@ function NoContent({
1760
1760
  children: ["No Component for ", contentType]
1761
1761
  });
1762
1762
  }
1763
+ function EmptyContent() {
1764
+ return null;
1765
+ }
1763
1766
  function Container({
1764
1767
  containerRef
1765
1768
  }) {
@@ -1772,7 +1775,9 @@ function Container({
1772
1775
  } = containerRef;
1773
1776
  // Get the containers from the global context
1774
1777
  const {
1775
- containers,
1778
+ pageAsset: {
1779
+ containers
1780
+ },
1776
1781
  components
1777
1782
  } = useContext(PageContext);
1778
1783
  const {
@@ -1799,7 +1804,9 @@ function Container({
1799
1804
  height: '10rem'
1800
1805
  };
1801
1806
  const ContainerChildren = contentlets.map(contentlet => {
1802
- const Component = components[contentlet.contentType] || NoContent;
1807
+ const ContentTypeComponent = components[contentlet.contentType];
1808
+ const DefaultComponent = components['CustomNoComponent'] || NoComponent;
1809
+ const Component = isInsideEditor ? ContentTypeComponent || DefaultComponent : ContentTypeComponent || EmptyContent;
1803
1810
  return isInsideEditor ? jsx("div", {
1804
1811
  "data-testid": "dot-contentlet",
1805
1812
  "data-dot-object": "contentlet",
@@ -1891,15 +1898,15 @@ const Row = /*#__PURE__*/forwardRef((props, ref) => {
1891
1898
  * @returns {JSX.Element} - A JSX element that represents the layout for a DotCMS page.
1892
1899
  */
1893
1900
  function DotcmsLayout({
1894
- entity,
1901
+ pageContext,
1895
1902
  config
1896
1903
  }) {
1897
1904
  const isInsideEditor = useDotcmsEditor(config);
1898
1905
  return jsx(PageProvider, {
1899
- entity: Object.assign({}, entity, {
1906
+ pageContext: Object.assign({}, pageContext, {
1900
1907
  isInsideEditor
1901
1908
  }),
1902
- children: entity.layout.body.rows.map((row, index) => jsx(Row, {
1909
+ children: pageContext.pageAsset.layout.body.rows.map((row, index) => jsx(Row, {
1903
1910
  row: row
1904
1911
  }, index))
1905
1912
  });
@@ -1910,7 +1917,7 @@ function DotcmsLayout({
1910
1917
  * It takes no parameters and returns the context value or `null` if it's not available.
1911
1918
  *
1912
1919
  * @category Hooks
1913
- * @returns {PageProviderContext | null} - The context value or `null` if it's not available.
1920
+ * @returns {DotCMSPageContext | null} - The context value or `null` if it's not available.
1914
1921
  */
1915
1922
  function useDotcmsPageContext() {
1916
1923
  return useContext(PageContext);
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dotcms/react",
3
- "version": "0.0.1-alpha.17",
3
+ "version": "0.0.1-alpha.19",
4
4
  "peerDependencies": {
5
5
  "react": ">=18",
6
6
  "react-dom": ">=18",
7
- "@dotcms/client": "0.0.1-alpha.17"
7
+ "@dotcms/client": "0.0.1-alpha.19"
8
8
  },
9
9
  "description": "Official React Components library to render a dotCMS page.",
10
10
  "repository": {
@@ -1,5 +1,5 @@
1
- import { PageProviderContext } from '../PageProvider/PageProvider';
1
+ import { DotCMSPageContext } from '../../models';
2
2
  export interface ColumnProps {
3
- readonly column: PageProviderContext['layout']['body']['rows'][0]['columns'][0];
3
+ readonly column: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0];
4
4
  }
5
5
  export declare function Column({ column }: ColumnProps): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
- import { PageProviderContext } from '../PageProvider/PageProvider';
1
+ import { DotCMSPageContext } from '../../models';
2
2
  export interface ContainerProps {
3
- readonly containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0];
3
+ readonly containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0];
4
4
  }
5
5
  export declare function Container({ containerRef }: ContainerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,26 +1,26 @@
1
1
  /// <reference types="react" />
2
2
  import { DotCMSPageEditorConfig } from '@dotcms/client';
3
- import { PageProviderContext } from '../PageProvider/PageProvider';
3
+ import { DotCMSPageContext } from '../../models';
4
4
  /**
5
5
  * `DotcmsPageProps` is a type that defines the properties for the `DotcmsLayout` component.
6
6
  * It includes a readonly `entity` property that represents the context for a DotCMS page.
7
7
  *
8
8
  * @typedef {Object} DotcmsPageProps
9
9
  *
10
- * @property {PageProviderContext} entity - The context for a DotCMS page.
10
+ * @property {DotCMSPageContext} entity - The context for a DotCMS page.
11
11
  * @readonly
12
12
  */
13
13
  export type DotcmsPageProps = {
14
14
  /**
15
- * `entity` is a readonly property of the `DotcmsPageProps` type.
15
+ * `pageContext` is a readonly property of the `DotcmsPageProps` type.
16
16
  * It represents the context for a DotCMS page and is of type `PageProviderContext`.
17
17
  *
18
- * @property {PageProviderContext} entity
18
+ * @property {PageProviderContext} pageContext
19
19
  * @memberof DotcmsPageProps
20
- * @type {PageProviderContext}
20
+ * @type {DotCMSPageContext}
21
21
  * @readonly
22
22
  */
23
- readonly entity: PageProviderContext;
23
+ readonly pageContext: DotCMSPageContext;
24
24
  readonly config?: DotCMSPageEditorConfig;
25
25
  };
26
26
  /**
@@ -31,4 +31,4 @@ export type DotcmsPageProps = {
31
31
  * @param {DotcmsPageProps} props - The properties for the DotCMS page.
32
32
  * @returns {JSX.Element} - A JSX element that represents the layout for a DotCMS page.
33
33
  */
34
- export declare function DotcmsLayout({ entity, config }: DotcmsPageProps): JSX.Element;
34
+ export declare function DotcmsLayout({ pageContext, config }: DotcmsPageProps): JSX.Element;
@@ -1,81 +1,8 @@
1
1
  import { ReactNode } from 'react';
2
2
  export interface PageProviderProps {
3
- readonly entity: any;
3
+ readonly pageContext: any;
4
4
  readonly children: ReactNode;
5
5
  }
6
- export interface ContainerData {
7
- [key: string]: {
8
- container: {
9
- path: string;
10
- identifier: string;
11
- maxContentlets: number;
12
- parentPermissionable: Record<string, string>;
13
- };
14
- containerStructures: {
15
- contentTypeVar: string;
16
- }[];
17
- contentlets: {
18
- [key: string]: {
19
- contentType: string;
20
- identifier: string;
21
- title: string;
22
- inode: string;
23
- onNumberOfPages: number;
24
- baseType: string;
25
- widgetTitle?: string;
26
- }[];
27
- };
28
- };
29
- }
30
- export interface PageProviderContext {
31
- /**
32
- * `components` is a property of the `PageProviderProps` type.
33
- * It is an object that maps content type variables to their corresponding React components.
34
- *
35
- * It will be use to render the contentlets in the page.
36
- *
37
- * @property {Object} components
38
- * @memberof PageProviderProps
39
- * @type {Object.<string, React.ElementType>}
40
- */
41
- components: {
42
- [contentTypeVariable: string]: React.ElementType;
43
- };
44
- containers: ContainerData;
45
- layout: {
46
- header: boolean;
47
- footer: boolean;
48
- body: {
49
- rows: {
50
- styleClass: string;
51
- columns: {
52
- styleClass: string;
53
- width: number;
54
- leftOffset: number;
55
- containers: {
56
- identifier: string;
57
- uuid: string;
58
- }[];
59
- }[];
60
- }[];
61
- };
62
- };
63
- page: {
64
- title: string;
65
- identifier: string;
66
- };
67
- viewAs: {
68
- language: {
69
- id: string;
70
- };
71
- persona: {
72
- keyTag: string;
73
- };
74
- variantId: string;
75
- };
76
- isInsideEditor: boolean;
77
- runningExperimentId?: string;
78
- }
79
6
  /**
80
7
  * `PageProvider` is a functional component that provides a context for a DotCMS page.
81
8
  * It takes a `PageProviderProps` object as a parameter and returns a JSX element.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../PageProvider/PageProvider';
2
+ import { DotCMSPageContext } from '../../models';
3
3
  /**
4
4
  * Props for the row component
5
5
  *
@@ -10,10 +10,10 @@ export interface RowProps {
10
10
  /**
11
11
  * Row data
12
12
  *
13
- * @type {PageProviderContext['layout']['body']['rows'][0]}
13
+ * @type {DotCMSPageContext['layout']['body']['rows'][0]}
14
14
  * @memberof RowProps
15
15
  */
16
- row: PageProviderContext['layout']['body']['rows'][0];
16
+ row: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0];
17
17
  }
18
18
  /**
19
19
  * Renders a row
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../components/PageProvider/PageProvider';
3
- export declare const PageContext: import("react").Context<PageProviderContext | null>;
2
+ import { DotCMSPageContext } from '../models';
3
+ export declare const PageContext: import("react").Context<DotCMSPageContext | null>;
@@ -1,9 +1,9 @@
1
- import { PageProviderContext } from '../components/PageProvider/PageProvider';
1
+ import { DotCMSPageContext } from '../models';
2
2
  /**
3
3
  * `useDotcmsPageContext` is a custom React hook that provides access to the `PageProviderContext`.
4
4
  * It takes no parameters and returns the context value or `null` if it's not available.
5
5
  *
6
6
  * @category Hooks
7
- * @returns {PageProviderContext | null} - The context value or `null` if it's not available.
7
+ * @returns {DotCMSPageContext | null} - The context value or `null` if it's not available.
8
8
  */
9
- export declare function useDotcmsPageContext(): PageProviderContext | null;
9
+ export declare function useDotcmsPageContext(): DotCMSPageContext | null;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { PageProviderContext } from '../components/PageProvider/PageProvider';
3
- export declare const mockPageContext: PageProviderContext;
2
+ import { DotCMSPageContext } from '../models';
3
+ export declare const mockPageContext: DotCMSPageContext;
4
4
  export declare const MockContextRender: ({ children, mockContext }: {
5
5
  children: JSX.Element;
6
- mockContext: Partial<PageProviderContext>;
6
+ mockContext: Partial<DotCMSPageContext>;
7
7
  }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,75 @@
1
+ /// <reference types="react" />
2
+ export interface ContainerData {
3
+ [key: string]: {
4
+ container: {
5
+ path: string;
6
+ identifier: string;
7
+ maxContentlets: number;
8
+ parentPermissionable: Record<string, string>;
9
+ };
10
+ containerStructures: {
11
+ contentTypeVar: string;
12
+ }[];
13
+ contentlets: {
14
+ [key: string]: {
15
+ contentType: string;
16
+ identifier: string;
17
+ title: string;
18
+ inode: string;
19
+ onNumberOfPages: number;
20
+ widgetTitle?: string;
21
+ baseType: string;
22
+ }[];
23
+ };
24
+ };
25
+ }
26
+ export interface DotCMSPageContext {
27
+ /**
28
+ * `components` is a property of the `PageProviderProps` type.
29
+ * It is an object that maps content type variables to their corresponding React components.
30
+ *
31
+ * It will be use to render the contentlets in the page.
32
+ *
33
+ * @property {Object} components
34
+ * @memberof PageProviderProps
35
+ * @type {Object.<string, React.ElementType>}
36
+ */
37
+ components: {
38
+ [contentTypeVariable: string]: React.ElementType;
39
+ };
40
+ pageAsset: {
41
+ containers: ContainerData;
42
+ layout: {
43
+ header: boolean;
44
+ footer: boolean;
45
+ body: {
46
+ rows: {
47
+ styleClass: string;
48
+ columns: {
49
+ styleClass: string;
50
+ width: number;
51
+ leftOffset: number;
52
+ containers: {
53
+ identifier: string;
54
+ uuid: string;
55
+ }[];
56
+ }[];
57
+ }[];
58
+ };
59
+ };
60
+ page: {
61
+ title: string;
62
+ identifier: string;
63
+ };
64
+ viewAs: {
65
+ language: {
66
+ id: string;
67
+ };
68
+ persona: {
69
+ keyTag: string;
70
+ };
71
+ variantId: string;
72
+ };
73
+ };
74
+ isInsideEditor: boolean;
75
+ }
@@ -1,5 +1,5 @@
1
- import { ContainerData, PageProviderContext } from '../components/PageProvider/PageProvider';
2
- export declare const getContainersData: (containers: ContainerData, containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
1
+ import { ContainerData, DotCMSPageContext } from '../models';
2
+ export declare const getContainersData: (containers: ContainerData, containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]) => {
3
3
  acceptTypes: string;
4
4
  contentlets: {
5
5
  contentType: string;
@@ -7,8 +7,8 @@ export declare const getContainersData: (containers: ContainerData, containerRef
7
7
  title: string;
8
8
  inode: string;
9
9
  onNumberOfPages: number;
10
- baseType: string;
11
10
  widgetTitle?: string | undefined;
11
+ baseType: string;
12
12
  }[];
13
13
  variantId: string;
14
14
  path: string;