@dotcms/react 0.0.1-alpha.9 → 0.0.1-beta.2
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 +24 -4
- package/es.regexp.to-string.esm.js +1878 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +3461 -0
- package/next.esm.d.ts +1 -0
- package/next.esm.js +665 -0
- package/package.json +34 -28
- package/src/index.d.ts +1 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/BlockEditorRenderer.d.ts +37 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Code.d.ts +17 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Contentlet.d.ts +41 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Image.d.ts +8 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Lists.d.ts +22 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Table.d.ts +16 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Texts.d.ts +71 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Video.d.ts +8 -0
- package/src/lib/deprecated/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +12 -0
- package/src/lib/deprecated/components/Column/Column.d.ts +19 -0
- package/src/lib/deprecated/components/Container/Container.d.ts +19 -0
- package/src/lib/deprecated/components/DotEditableText/DotEditableText.d.ts +30 -0
- package/src/lib/deprecated/components/DotEditableText/utils.d.ts +36 -0
- package/src/lib/{components/DotcmsLayout/DotcmsLayout.tsx → deprecated/components/DotcmsLayout/DotcmsLayout.d.ts} +9 -23
- package/src/lib/deprecated/components/PageProvider/PageProvider.d.ts +14 -0
- package/src/lib/deprecated/components/Row/Row.d.ts +26 -0
- package/src/lib/deprecated/contexts/PageContext.d.ts +8 -0
- package/src/lib/deprecated/deprecated_api.d.ts +7 -0
- package/src/lib/deprecated/hooks/useCheckHaveContent.d.ts +5 -0
- package/src/lib/deprecated/hooks/useDotcmsEditor.d.ts +13 -0
- package/src/lib/deprecated/hooks/useDotcmsPageContext.d.ts +9 -0
- package/src/lib/deprecated/mocks/mockPageContext.d.ts +7 -0
- package/src/lib/deprecated/models/blocks.interface.d.ts +89 -0
- package/src/lib/deprecated/models/content-node.interface.d.ts +82 -0
- package/src/lib/deprecated/models/index.d.ts +127 -0
- package/src/lib/deprecated/utils/utils.d.ts +58 -0
- package/src/lib/next/__test__/mock.d.ts +11 -0
- package/src/lib/next/components/Column/Column.d.ts +37 -0
- package/src/lib/next/components/Container/Container.d.ts +32 -0
- package/src/lib/next/components/Container/ContainerFallbakcs.d.ts +24 -0
- package/src/lib/next/components/Contentlet/Contentlet.d.ts +32 -0
- package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +36 -0
- package/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.d.ts +9 -0
- package/src/lib/next/components/FallbackComponent/FallbackComponent.d.ts +41 -0
- package/src/lib/next/components/Row/Row.d.ts +21 -0
- package/src/lib/next/contexts/DotCMSPageContext.d.ts +23 -0
- package/src/lib/next/hooks/useCheckVisibleContent.d.ts +24 -0
- package/src/lib/next/hooks/useIsDevMode.d.ts +13 -0
- package/src/lib/next/types.d.ts +421 -0
- package/src/lib/next/utils/index.d.ts +136 -0
- package/src/next.d.ts +1 -0
- package/.babelrc +0 -12
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -11
- package/project.json +0 -51
- package/src/index.ts +0 -4
- package/src/lib/components/Column/Column.module.css +0 -99
- package/src/lib/components/Column/Column.spec.tsx +0 -78
- package/src/lib/components/Column/Column.tsx +0 -45
- package/src/lib/components/Container/Container.module.css +0 -7
- package/src/lib/components/Container/Container.spec.tsx +0 -82
- package/src/lib/components/Container/Container.tsx +0 -105
- package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +0 -7
- package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +0 -41
- package/src/lib/components/PageProvider/PageProvider.module.css +0 -7
- package/src/lib/components/PageProvider/PageProvider.spec.tsx +0 -54
- package/src/lib/components/PageProvider/PageProvider.tsx +0 -95
- package/src/lib/components/Row/Row.module.css +0 -5
- package/src/lib/components/Row/Row.spec.tsx +0 -92
- package/src/lib/components/Row/Row.tsx +0 -51
- package/src/lib/contexts/PageContext.tsx +0 -5
- package/src/lib/hooks/useDotcmsEditor.spec.ts +0 -56
- package/src/lib/hooks/useDotcmsEditor.ts +0 -29
- package/src/lib/hooks/useDotcmsPageContext.spec.tsx +0 -43
- package/src/lib/hooks/useDotcmsPageContext.tsx +0 -15
- package/src/lib/mocks/mockPageContext.tsx +0 -84
- package/src/lib/utils/utils.ts +0 -69
- package/tsconfig.json +0 -20
- package/tsconfig.lib.json +0 -23
- package/tsconfig.spec.json +0 -20
- /package/src/lib/{mocks/index.ts → deprecated/mocks/index.d.ts} +0 -0
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
.col-start-1 {
|
|
2
|
-
grid-column-start: 1;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.col-start-2 {
|
|
6
|
-
grid-column-start: 2;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.col-start-3 {
|
|
10
|
-
grid-column-start: 3;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.col-start-4 {
|
|
14
|
-
grid-column-start: 4;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.col-start-5 {
|
|
18
|
-
grid-column-start: 5;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.col-start-6 {
|
|
22
|
-
grid-column-start: 6;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.col-start-7 {
|
|
26
|
-
grid-column-start: 7;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.col-start-8 {
|
|
30
|
-
grid-column-start: 8;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.col-start-9 {
|
|
34
|
-
grid-column-start: 9;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.col-start-10 {
|
|
38
|
-
grid-column-start: 10;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.col-start-11 {
|
|
42
|
-
grid-column-start: 11;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.col-start-12 {
|
|
46
|
-
grid-column-start: 12;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.col-end-1 {
|
|
50
|
-
grid-column-end: 1;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.col-end-2 {
|
|
54
|
-
grid-column-end: 2;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.col-end-3 {
|
|
58
|
-
grid-column-end: 3;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.col-end-4 {
|
|
62
|
-
grid-column-end: 4;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.col-end-5 {
|
|
66
|
-
grid-column-end: 5;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.col-end-6 {
|
|
70
|
-
grid-column-end: 6;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.col-end-7 {
|
|
74
|
-
grid-column-end: 7;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.col-end-8 {
|
|
78
|
-
grid-column-end: 8;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
.col-end-9 {
|
|
82
|
-
grid-column-end: 9;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.col-end-10 {
|
|
86
|
-
grid-column-end: 10;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
.col-end-11 {
|
|
90
|
-
grid-column-end: 11;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.col-end-12 {
|
|
94
|
-
grid-column-end: 12;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.col-end-13 {
|
|
98
|
-
grid-column-end: 13;
|
|
99
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
-
import '@testing-library/jest-dom';
|
|
3
|
-
|
|
4
|
-
import * as dotcmsClient from '@dotcms/client';
|
|
5
|
-
|
|
6
|
-
import { Column } from './Column';
|
|
7
|
-
|
|
8
|
-
import { MockContextRender } from '../../mocks/mockPageContext';
|
|
9
|
-
import { ContainerProps } from '../Container/Container';
|
|
10
|
-
|
|
11
|
-
jest.mock('../Container/Container', () => {
|
|
12
|
-
return {
|
|
13
|
-
Container: ({ containerRef }: Partial<ContainerProps>) => (
|
|
14
|
-
<div data-testid="mockContainer">{containerRef?.identifier}</div>
|
|
15
|
-
)
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('Column', () => {
|
|
20
|
-
const mockColumnData = {
|
|
21
|
-
width: 6, // Adjust as needed
|
|
22
|
-
leftOffset: 3, // Adjust as needed
|
|
23
|
-
containers: [
|
|
24
|
-
{ identifier: 'Container1', uuid: 'unique-id-1' },
|
|
25
|
-
{ identifier: 'Container2', uuid: 'unique-id-2' }
|
|
26
|
-
// Add more containers as needed for your test
|
|
27
|
-
],
|
|
28
|
-
styleClass: ''
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
describe('Column is inside editor', () => {
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(true);
|
|
34
|
-
render(
|
|
35
|
-
<MockContextRender mockContext={{ isInsideEditor: true }}>
|
|
36
|
-
<Column column={mockColumnData} />
|
|
37
|
-
</MockContextRender>
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('applies the correct width and start classes based on props', () => {
|
|
42
|
-
const columnElement = screen.getByTestId('column');
|
|
43
|
-
expect(columnElement).toHaveClass('col-end-9');
|
|
44
|
-
expect(columnElement).toHaveClass('col-start-3');
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('applies the correct data attr', () => {
|
|
48
|
-
expect(screen.getByTestId('column')).toHaveAttribute('data-dot', 'column');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('renders the correct number of containers', () => {
|
|
52
|
-
const containers = screen.getAllByTestId('mockContainer');
|
|
53
|
-
expect(containers.length).toBe(mockColumnData.containers.length);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('passes the correct props to each Container', () => {
|
|
57
|
-
mockColumnData.containers.forEach((container) => {
|
|
58
|
-
expect(screen.getByText(container.identifier)).toBeInTheDocument();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('Column is not inside editor', () => {
|
|
64
|
-
beforeEach(() => {
|
|
65
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(false);
|
|
66
|
-
render(
|
|
67
|
-
<MockContextRender mockContext={{ isInsideEditor: false }}>
|
|
68
|
-
<Column column={mockColumnData} />
|
|
69
|
-
</MockContextRender>
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should not have dot attrs', () => {
|
|
74
|
-
const columnElement = screen.queryByTestId('column');
|
|
75
|
-
expect(columnElement).toBeNull();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import styles from './column.module.css';
|
|
4
|
-
|
|
5
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
6
|
-
import { combineClasses, getPositionStyleClasses } from '../../utils/utils';
|
|
7
|
-
import { Container } from '../Container/Container';
|
|
8
|
-
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
9
|
-
|
|
10
|
-
export interface ColumnProps {
|
|
11
|
-
readonly column: PageProviderContext['layout']['body']['rows'][0]['columns'][0];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function Column({ column }: ColumnProps) {
|
|
15
|
-
const { isInsideEditor } = useContext(PageContext) as PageProviderContext;
|
|
16
|
-
|
|
17
|
-
const { startClass, endClass } = getPositionStyleClasses(
|
|
18
|
-
column.leftOffset,
|
|
19
|
-
column.width + column.leftOffset
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
const combinedClasses = combineClasses([
|
|
23
|
-
styles[endClass],
|
|
24
|
-
styles[startClass],
|
|
25
|
-
column.styleClass
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
const columnProps = isInsideEditor
|
|
29
|
-
? {
|
|
30
|
-
'data-dot': 'column',
|
|
31
|
-
'data-testid': 'column'
|
|
32
|
-
}
|
|
33
|
-
: {};
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<div {...columnProps} className={combinedClasses}>
|
|
37
|
-
{column.containers.map((container) => (
|
|
38
|
-
<Container
|
|
39
|
-
key={`${container.identifier}-${container.uuid}`}
|
|
40
|
-
containerRef={container}
|
|
41
|
-
/>
|
|
42
|
-
))}
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
|
|
5
|
-
import * as dotcmsClient from '@dotcms/client';
|
|
6
|
-
|
|
7
|
-
import { Container } from './Container';
|
|
8
|
-
|
|
9
|
-
import { MockContextRender, mockPageContext } from '../../mocks/mockPageContext';
|
|
10
|
-
|
|
11
|
-
describe('Container', () => {
|
|
12
|
-
// Mock data for your context and container
|
|
13
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(true);
|
|
14
|
-
|
|
15
|
-
describe('with contentlets', () => {
|
|
16
|
-
const mockContainerRef = {
|
|
17
|
-
identifier: 'container-1',
|
|
18
|
-
uuid: '1',
|
|
19
|
-
containers: []
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
it('renders NoContent component for unsupported content types', () => {
|
|
23
|
-
const updatedContext = {
|
|
24
|
-
...mockPageContext,
|
|
25
|
-
components: {}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
render(
|
|
29
|
-
<MockContextRender mockContext={updatedContext}>
|
|
30
|
-
<Container containerRef={mockContainerRef} />
|
|
31
|
-
</MockContextRender>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
expect(screen.getByTestId('no-component')).toHaveTextContent(
|
|
35
|
-
'No Component for content-type-1'
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('without contentlets', () => {
|
|
40
|
-
const mockContainerRef = {
|
|
41
|
-
identifier: 'container-2',
|
|
42
|
-
uuid: '2',
|
|
43
|
-
containers: []
|
|
44
|
-
};
|
|
45
|
-
it('renders EmptyContainer component in editor mode', () => {
|
|
46
|
-
const updatedContext = {
|
|
47
|
-
...mockPageContext,
|
|
48
|
-
components: {},
|
|
49
|
-
isInsideEditor: true
|
|
50
|
-
};
|
|
51
|
-
render(
|
|
52
|
-
<MockContextRender mockContext={updatedContext}>
|
|
53
|
-
<Container containerRef={mockContainerRef} />
|
|
54
|
-
</MockContextRender>
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(screen.getByTestId('empty-container')).toHaveTextContent(
|
|
58
|
-
'This container is empty.'
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('dont render EmptyContainer component outside editor mode', () => {
|
|
63
|
-
jest.spyOn(dotcmsClient, 'isInsideEditor').mockReturnValue(false);
|
|
64
|
-
|
|
65
|
-
const updatedContext = {
|
|
66
|
-
...mockPageContext,
|
|
67
|
-
components: {},
|
|
68
|
-
isInsideEditor: false
|
|
69
|
-
};
|
|
70
|
-
render(
|
|
71
|
-
<MockContextRender mockContext={updatedContext}>
|
|
72
|
-
<Container containerRef={mockContainerRef} />
|
|
73
|
-
</MockContextRender>
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect(screen.queryByTestId('empty-container')).toBeNull();
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Add tests for pointer events, dynamic component rendering, and other scenarios...
|
|
82
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
4
|
-
import { getContainersData } from '../../utils/utils';
|
|
5
|
-
import { PageProviderContext } from '../PageProvider/PageProvider';
|
|
6
|
-
|
|
7
|
-
const FAKE_CONTENLET = {
|
|
8
|
-
identifier: 'TEMP_EMPTY_CONTENTLET',
|
|
9
|
-
title: 'TEMP_EMPTY_CONTENTLET',
|
|
10
|
-
contentType: 'TEMP_EMPTY_CONTENTLET_TYPE',
|
|
11
|
-
inode: 'TEMPY_EMPTY_CONTENTLET_INODE',
|
|
12
|
-
widgetTitle: 'TEMP_EMPTY_CONTENTLET',
|
|
13
|
-
onNumberOfPages: 1
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function EmptyContainer() {
|
|
17
|
-
return (
|
|
18
|
-
<div
|
|
19
|
-
data-testid="empty-container"
|
|
20
|
-
style={{
|
|
21
|
-
width: '100%',
|
|
22
|
-
backgroundColor: '#ECF0FD',
|
|
23
|
-
display: 'flex',
|
|
24
|
-
justifyContent: 'center',
|
|
25
|
-
alignItems: 'center',
|
|
26
|
-
color: '#030E32',
|
|
27
|
-
height: '10rem'
|
|
28
|
-
}}>
|
|
29
|
-
This container is empty.
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function NoContent({ contentType }: { readonly contentType: string }) {
|
|
35
|
-
return <div data-testid="no-component">No Component for {contentType}</div>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ContainerProps {
|
|
39
|
-
readonly containerRef: PageProviderContext['layout']['body']['rows'][0]['columns'][0]['containers'][0];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function Container({ containerRef }: ContainerProps) {
|
|
43
|
-
const { isInsideEditor } = useContext(PageContext) as PageProviderContext;
|
|
44
|
-
|
|
45
|
-
const { identifier, uuid } = containerRef;
|
|
46
|
-
|
|
47
|
-
// Get the containers from the global context
|
|
48
|
-
const { containers, components } = useContext<PageProviderContext | null>(
|
|
49
|
-
PageContext
|
|
50
|
-
) as PageProviderContext;
|
|
51
|
-
|
|
52
|
-
const { acceptTypes, contentlets, maxContentlets, variantId, path } = getContainersData(
|
|
53
|
-
containers,
|
|
54
|
-
containerRef
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const updatedContentlets =
|
|
58
|
-
contentlets.length === 0 && isInsideEditor ? [FAKE_CONTENLET] : contentlets;
|
|
59
|
-
|
|
60
|
-
const container = {
|
|
61
|
-
acceptTypes,
|
|
62
|
-
identifier: path ?? identifier,
|
|
63
|
-
maxContentlets,
|
|
64
|
-
variantId,
|
|
65
|
-
uuid
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const renderContentlets = updatedContentlets.map((contentlet) => {
|
|
69
|
-
const ContentTypeComponent = components[contentlet.contentType] || NoContent;
|
|
70
|
-
|
|
71
|
-
const Component =
|
|
72
|
-
contentlet.identifier === 'TEMP_EMPTY_CONTENTLET'
|
|
73
|
-
? EmptyContainer
|
|
74
|
-
: ContentTypeComponent;
|
|
75
|
-
|
|
76
|
-
return isInsideEditor ? (
|
|
77
|
-
<div
|
|
78
|
-
data-dot-object="contentlet"
|
|
79
|
-
data-dot-identifier={contentlet.identifier}
|
|
80
|
-
data-dot-title={contentlet.widgetTitle || contentlet.title}
|
|
81
|
-
data-dot-inode={contentlet.inode}
|
|
82
|
-
data-dot-type={contentlet.contentType}
|
|
83
|
-
data-dot-container={JSON.stringify(container)}
|
|
84
|
-
key={contentlet.identifier}>
|
|
85
|
-
<Component {...contentlet} />
|
|
86
|
-
</div>
|
|
87
|
-
) : (
|
|
88
|
-
<Component {...contentlet} key={contentlet.identifier} />
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return isInsideEditor ? (
|
|
93
|
-
<div
|
|
94
|
-
data-dot-object="container"
|
|
95
|
-
data-dot-accept-types={acceptTypes}
|
|
96
|
-
data-dot-identifier={path ?? identifier}
|
|
97
|
-
data-max-contentlets={maxContentlets}
|
|
98
|
-
data-uuid={uuid}>
|
|
99
|
-
{renderContentlets}
|
|
100
|
-
</div>
|
|
101
|
-
) : (
|
|
102
|
-
// eslint-disable-next-line react/jsx-no-useless-fragment
|
|
103
|
-
<>{renderContentlets}</>
|
|
104
|
-
);
|
|
105
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import '@testing-library/jest-dom';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import { ElementRef, ForwardRefExoticComponent } from 'react';
|
|
4
|
-
|
|
5
|
-
import { DotcmsLayout } from './DotcmsLayout';
|
|
6
|
-
|
|
7
|
-
import { mockPageContext } from '../../mocks/mockPageContext';
|
|
8
|
-
|
|
9
|
-
jest.mock('../Row/Row', () => {
|
|
10
|
-
const { forwardRef } = jest.requireActual('react');
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
Row: forwardRef(
|
|
14
|
-
(
|
|
15
|
-
{ children }: { children: JSX.Element },
|
|
16
|
-
ref: ElementRef<ForwardRefExoticComponent<unknown>>
|
|
17
|
-
) => (
|
|
18
|
-
<div data-testid="mockRow" ref={ref}>
|
|
19
|
-
{children}
|
|
20
|
-
</div>
|
|
21
|
-
)
|
|
22
|
-
)
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
jest.mock('../PageProvider/PageProvider', () => {
|
|
27
|
-
return {
|
|
28
|
-
PageProvider: ({ children }: { children: JSX.Element }) => (
|
|
29
|
-
<div data-testid="mockPageProvider">{children}</div>
|
|
30
|
-
)
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('DotcmsLayout', () => {
|
|
35
|
-
it('renders correctly with PageProvider and rows', () => {
|
|
36
|
-
render(<DotcmsLayout entity={{ ...mockPageContext, isInsideEditor: true }} />);
|
|
37
|
-
expect(screen.getAllByTestId('mockRow').length).toBe(
|
|
38
|
-
mockPageContext.layout.body.rows.length
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
|
|
4
|
-
import '@testing-library/jest-dom';
|
|
5
|
-
import { PageProvider } from './PageProvider';
|
|
6
|
-
|
|
7
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
8
|
-
|
|
9
|
-
const MockChildComponent = () => {
|
|
10
|
-
const context = React.useContext(PageContext);
|
|
11
|
-
|
|
12
|
-
return <div data-testid="mockChild">{JSON.stringify(context?.page.title)}</div>;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe('PageProvider', () => {
|
|
16
|
-
const mockEntity = {
|
|
17
|
-
page: {
|
|
18
|
-
title: 'Test Page',
|
|
19
|
-
identifier: 'test-page-1'
|
|
20
|
-
}
|
|
21
|
-
// ... add other context properties as needed
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
it('provides the context to its children', () => {
|
|
25
|
-
render(
|
|
26
|
-
<PageProvider entity={mockEntity}>
|
|
27
|
-
<MockChildComponent />
|
|
28
|
-
</PageProvider>
|
|
29
|
-
);
|
|
30
|
-
expect(screen.getByTestId('mockChild')).toHaveTextContent(mockEntity.page.title);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('updates context when entity changes', () => {
|
|
34
|
-
const { rerender } = render(
|
|
35
|
-
<PageProvider entity={mockEntity}>
|
|
36
|
-
<MockChildComponent />
|
|
37
|
-
</PageProvider>
|
|
38
|
-
);
|
|
39
|
-
// Change the context
|
|
40
|
-
const newEntity = {
|
|
41
|
-
...mockEntity,
|
|
42
|
-
page: {
|
|
43
|
-
...mockEntity.page,
|
|
44
|
-
title: 'Updated Test Page'
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
rerender(
|
|
48
|
-
<PageProvider entity={newEntity}>
|
|
49
|
-
<MockChildComponent />
|
|
50
|
-
</PageProvider>
|
|
51
|
-
);
|
|
52
|
-
expect(screen.getByTestId('mockChild')).toHaveTextContent(newEntity.page.title);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
4
|
-
|
|
5
|
-
export interface PageProviderProps {
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
readonly entity: any;
|
|
8
|
-
readonly children: ReactNode;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface ContainerData {
|
|
12
|
-
[key: string]: {
|
|
13
|
-
container: {
|
|
14
|
-
path: string;
|
|
15
|
-
identifier: string;
|
|
16
|
-
maxContentlets: number;
|
|
17
|
-
parentPermissionable: Record<string, string>;
|
|
18
|
-
};
|
|
19
|
-
containerStructures: {
|
|
20
|
-
contentTypeVar: string;
|
|
21
|
-
}[];
|
|
22
|
-
contentlets: {
|
|
23
|
-
[key: string]: {
|
|
24
|
-
contentType: string;
|
|
25
|
-
identifier: string;
|
|
26
|
-
title: string;
|
|
27
|
-
inode: string;
|
|
28
|
-
onNumberOfPages: number;
|
|
29
|
-
widgetTitle?: string;
|
|
30
|
-
}[];
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface PageProviderContext {
|
|
36
|
-
/**
|
|
37
|
-
* `components` is a property of the `PageProviderProps` type.
|
|
38
|
-
* It is an object that maps content type variables to their corresponding React components.
|
|
39
|
-
*
|
|
40
|
-
* It will be use to render the contentlets in the page.
|
|
41
|
-
*
|
|
42
|
-
* @property {Object} components
|
|
43
|
-
* @memberof PageProviderProps
|
|
44
|
-
* @type {Object.<string, React.ElementType>}
|
|
45
|
-
*/
|
|
46
|
-
components: {
|
|
47
|
-
[contentTypeVariable: string]: React.ElementType;
|
|
48
|
-
};
|
|
49
|
-
containers: ContainerData;
|
|
50
|
-
layout: {
|
|
51
|
-
header: boolean;
|
|
52
|
-
footer: boolean;
|
|
53
|
-
body: {
|
|
54
|
-
rows: {
|
|
55
|
-
styleClass: string;
|
|
56
|
-
columns: {
|
|
57
|
-
styleClass: string;
|
|
58
|
-
width: number;
|
|
59
|
-
leftOffset: number;
|
|
60
|
-
containers: {
|
|
61
|
-
identifier: string;
|
|
62
|
-
uuid: string;
|
|
63
|
-
}[];
|
|
64
|
-
}[];
|
|
65
|
-
}[];
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
page: {
|
|
69
|
-
title: string;
|
|
70
|
-
identifier: string;
|
|
71
|
-
};
|
|
72
|
-
viewAs: {
|
|
73
|
-
language: {
|
|
74
|
-
id: string;
|
|
75
|
-
};
|
|
76
|
-
persona: {
|
|
77
|
-
keyTag: string;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
isInsideEditor: boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* `PageProvider` is a functional component that provides a context for a DotCMS page.
|
|
85
|
-
* It takes a `PageProviderProps` object as a parameter and returns a JSX element.
|
|
86
|
-
*
|
|
87
|
-
* @category Components
|
|
88
|
-
* @param {PageProviderProps} props - The properties for the PageProvider. Includes an `entity` and `children`.
|
|
89
|
-
* @returns {JSX.Element} - A JSX element that provides a context for a DotCMS page.
|
|
90
|
-
*/
|
|
91
|
-
export function PageProvider(props: PageProviderProps): JSX.Element {
|
|
92
|
-
const { entity, children } = props;
|
|
93
|
-
|
|
94
|
-
return <PageContext.Provider value={entity}>{children}</PageContext.Provider>;
|
|
95
|
-
}
|