@dotcms/react 0.0.1-alpha.40 → 0.0.1-alpha.41
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.d.ts +1 -0
- package/index.esm.js +5204 -0
- package/package.json +9 -5
- package/src/lib/components/BlockEditorRenderer/{BlockEditorRenderer.tsx → BlockEditorRenderer.d.ts} +2 -16
- package/src/lib/components/BlockEditorRenderer/blocks/{Code.tsx → Code.d.ts} +2 -14
- package/src/lib/components/BlockEditorRenderer/blocks/{Contentlet.tsx → Contentlet.d.ts} +1 -21
- package/src/lib/components/BlockEditorRenderer/blocks/Image.d.ts +8 -0
- package/src/lib/components/BlockEditorRenderer/blocks/{Lists.tsx → Lists.d.ts} +3 -12
- package/src/lib/components/BlockEditorRenderer/blocks/Table.d.ts +16 -0
- package/src/lib/components/BlockEditorRenderer/blocks/Texts.d.ts +71 -0
- package/src/lib/components/BlockEditorRenderer/blocks/Video.d.ts +8 -0
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.d.ts +12 -0
- package/src/lib/components/Column/Column.d.ts +19 -0
- package/src/lib/components/Container/Container.d.ts +19 -0
- package/src/lib/components/DotEditableText/DotEditableText.d.ts +31 -0
- package/src/lib/components/DotEditableText/utils.d.ts +36 -0
- package/src/lib/components/DotcmsLayout/{DotcmsLayout.tsx → DotcmsLayout.d.ts} +2 -18
- package/src/lib/components/PageProvider/{PageProvider.tsx → PageProvider.d.ts} +1 -10
- package/src/lib/components/Row/Row.d.ts +26 -0
- package/src/lib/contexts/{PageContext.tsx → PageContext.d.ts} +2 -4
- package/src/lib/hooks/useCheckHaveContent.d.ts +5 -0
- package/src/lib/hooks/useDotcmsEditor.d.ts +13 -0
- package/src/lib/hooks/{useDotcmsPageContext.tsx → useDotcmsPageContext.d.ts} +1 -7
- package/src/lib/mocks/mockPageContext.d.ts +8 -0
- package/src/lib/models/{blocks.interface.ts → blocks.interface.d.ts} +16 -19
- package/src/lib/models/{content-node.interface.ts → content-node.interface.d.ts} +4 -12
- package/src/lib/models/{index.ts → index.d.ts} +2 -5
- package/src/lib/utils/utils.d.ts +43 -0
- package/.babelrc +0 -12
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -11
- package/project.json +0 -56
- package/src/lib/components/BlockEditorRenderer/BlockEditorRenderer.spec.tsx +0 -51
- package/src/lib/components/BlockEditorRenderer/blocks/Image.tsx +0 -18
- package/src/lib/components/BlockEditorRenderer/blocks/Table.tsx +0 -60
- package/src/lib/components/BlockEditorRenderer/blocks/Texts.tsx +0 -126
- package/src/lib/components/BlockEditorRenderer/blocks/Video.tsx +0 -26
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.spec.tsx +0 -634
- package/src/lib/components/BlockEditorRenderer/item/BlockEditorBlock.tsx +0 -146
- 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 -59
- package/src/lib/components/Container/Container.module.css +0 -7
- package/src/lib/components/Container/Container.spec.tsx +0 -155
- package/src/lib/components/Container/Container.tsx +0 -122
- package/src/lib/components/DotEditableText/DotEditableText.spec.tsx +0 -232
- package/src/lib/components/DotEditableText/DotEditableText.tsx +0 -168
- package/src/lib/components/DotEditableText/utils.ts +0 -82
- package/src/lib/components/DotcmsLayout/DotcmsLayout.module.css +0 -7
- package/src/lib/components/DotcmsLayout/DotcmsLayout.spec.tsx +0 -46
- package/src/lib/components/PageProvider/PageProvider.module.css +0 -7
- package/src/lib/components/PageProvider/PageProvider.spec.tsx +0 -59
- 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 -52
- package/src/lib/hooks/useDotcmsEditor.spec.ts +0 -176
- package/src/lib/hooks/useDotcmsEditor.ts +0 -94
- package/src/lib/hooks/useDotcmsPageContext.spec.tsx +0 -47
- package/src/lib/mocks/mockPageContext.tsx +0 -113
- package/src/lib/utils/utils.ts +0 -89
- package/tsconfig.json +0 -20
- package/tsconfig.lib.json +0 -23
- package/tsconfig.spec.json +0 -20
- /package/src/{index.ts → index.d.ts} +0 -0
- /package/src/lib/mocks/{index.ts → index.d.ts} +0 -0
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
2
|
-
|
|
3
|
-
import { Row } from './Row';
|
|
4
|
-
|
|
5
|
-
import { MockContextRender } from '../../mocks/mockPageContext';
|
|
6
|
-
import { ColumnProps } from '../Column/Column';
|
|
7
|
-
import { DotCMSPageContext } from '../PageProvider/PageProvider';
|
|
8
|
-
|
|
9
|
-
import '@testing-library/jest-dom';
|
|
10
|
-
|
|
11
|
-
jest.mock('../Column/Column', () => {
|
|
12
|
-
return {
|
|
13
|
-
Column: ({ column }: ColumnProps) => (
|
|
14
|
-
<div data-testid="mockColumn">{JSON.stringify(column)}</div>
|
|
15
|
-
)
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('Row', () => {
|
|
20
|
-
const mockRowData: DotCMSPageContext['layout']['body']['rows'][0] = {
|
|
21
|
-
columns: [
|
|
22
|
-
{
|
|
23
|
-
width: 60,
|
|
24
|
-
leftOffset: 2,
|
|
25
|
-
containers: [
|
|
26
|
-
{
|
|
27
|
-
identifier: '123',
|
|
28
|
-
uuid: '1'
|
|
29
|
-
}
|
|
30
|
-
],
|
|
31
|
-
styleClass: ''
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
width: 20,
|
|
35
|
-
leftOffset: 0,
|
|
36
|
-
containers: [
|
|
37
|
-
{
|
|
38
|
-
identifier: '456',
|
|
39
|
-
uuid: '2'
|
|
40
|
-
}
|
|
41
|
-
],
|
|
42
|
-
styleClass: ''
|
|
43
|
-
}
|
|
44
|
-
],
|
|
45
|
-
styleClass: ''
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
describe('row is inside editor', () => {
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
render(
|
|
51
|
-
<MockContextRender mockContext={{ isInsideEditor: true }}>
|
|
52
|
-
<Row row={mockRowData} />
|
|
53
|
-
</MockContextRender>
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should set the data-dot attribute', () => {
|
|
58
|
-
expect(screen.getByTestId('row')).toHaveAttribute('data-dot', 'row');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('renders the correct number of mock columns', () => {
|
|
62
|
-
const mockColumns = screen.getAllByTestId('mockColumn');
|
|
63
|
-
expect(mockColumns.length).toBe(mockRowData.columns.length);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('passes the correct props to each mock Column', () => {
|
|
67
|
-
mockRowData.columns.forEach((column, index) => {
|
|
68
|
-
expect(screen.getAllByTestId('mockColumn')[index].innerHTML).toBe(
|
|
69
|
-
JSON.stringify(column)
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('renders the correct number of columns', () => {
|
|
75
|
-
const columns = screen.getAllByTestId('mockColumn');
|
|
76
|
-
expect(columns.length).toBe(mockRowData.columns.length);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe('row is not inside editor', () => {
|
|
80
|
-
beforeEach(() => {
|
|
81
|
-
render(
|
|
82
|
-
<MockContextRender mockContext={{ isInsideEditor: false }}>
|
|
83
|
-
<Row row={mockRowData} />
|
|
84
|
-
</MockContextRender>
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should not have dot attr', () => {
|
|
89
|
-
expect(screen.queryByTestId('row')).toBeNull();
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
import styles from './row.module.css';
|
|
4
|
-
|
|
5
|
-
import { PageContext } from '../../contexts/PageContext';
|
|
6
|
-
import { DotCMSPageContext } from '../../models';
|
|
7
|
-
import { combineClasses } from '../../utils/utils';
|
|
8
|
-
import { Column } from '../Column/Column';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Props for the row component
|
|
12
|
-
*
|
|
13
|
-
* @interface RowProps
|
|
14
|
-
*
|
|
15
|
-
*/
|
|
16
|
-
export interface RowProps {
|
|
17
|
-
/**
|
|
18
|
-
* Row data
|
|
19
|
-
*
|
|
20
|
-
* @type {DotCMSPageContext['layout']['body']['rows'][0]}
|
|
21
|
-
* @memberof RowProps
|
|
22
|
-
*/
|
|
23
|
-
row: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* This component renders a row with all it's content using the layout provided by dotCMS Page API.
|
|
28
|
-
*
|
|
29
|
-
* @see {@link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas}
|
|
30
|
-
* @category Components
|
|
31
|
-
* @param {React.ForwardedRef<HTMLDivElement, RowProps>} ref
|
|
32
|
-
* @return {JSX.Element} Rendered rows with columns
|
|
33
|
-
*/
|
|
34
|
-
export const Row = forwardRef<HTMLDivElement, RowProps>((props: RowProps, ref) => {
|
|
35
|
-
const { isInsideEditor } = useContext<DotCMSPageContext | null>(
|
|
36
|
-
PageContext
|
|
37
|
-
) as DotCMSPageContext;
|
|
38
|
-
|
|
39
|
-
const { row } = props;
|
|
40
|
-
|
|
41
|
-
const combinedClasses = combineClasses([styles.row, row.styleClass]);
|
|
42
|
-
|
|
43
|
-
const rowProps = isInsideEditor ? { 'data-dot': 'row', 'data-testid': 'row', ref } : {};
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div {...rowProps} className={combinedClasses}>
|
|
47
|
-
{row.columns.map((column, index) => (
|
|
48
|
-
<Column key={index} column={column} />
|
|
49
|
-
))}
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
});
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
-
|
|
3
|
-
import * as sdkClient from '@dotcms/client';
|
|
4
|
-
|
|
5
|
-
import { useDotcmsEditor } from './useDotcmsEditor';
|
|
6
|
-
|
|
7
|
-
import { DotcmsPageProps } from '../components/DotcmsLayout/DotcmsLayout';
|
|
8
|
-
import { mockPageContext } from '../mocks/mockPageContext';
|
|
9
|
-
|
|
10
|
-
jest.mock('@dotcms/client', () => ({
|
|
11
|
-
...jest.requireActual('@dotcms/client'),
|
|
12
|
-
isInsideEditor: () => true,
|
|
13
|
-
postMessageToEditor: jest.fn(),
|
|
14
|
-
DotCmsClient: {
|
|
15
|
-
instance: {
|
|
16
|
-
editor: {
|
|
17
|
-
on: jest.fn(),
|
|
18
|
-
off: jest.fn(),
|
|
19
|
-
callbacks: {}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const { DotCmsClient } = sdkClient as jest.Mocked<typeof sdkClient>;
|
|
26
|
-
|
|
27
|
-
describe('useDotcmsEditor', () => {
|
|
28
|
-
let isInsideEditorSpy: jest.SpyInstance<boolean>;
|
|
29
|
-
let initEditorSpy: jest.SpyInstance<void>;
|
|
30
|
-
let destroyEditorSpy: jest.SpyInstance<void>;
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
isInsideEditorSpy = jest.spyOn(sdkClient, 'isInsideEditor');
|
|
34
|
-
initEditorSpy = jest.spyOn(sdkClient, 'initEditor');
|
|
35
|
-
destroyEditorSpy = jest.spyOn(sdkClient, 'destroyEditor');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
jest.clearAllMocks();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('when outside editor', () => {
|
|
43
|
-
it('should not call initEditor or destroyEditor when outside editor', () => {
|
|
44
|
-
isInsideEditorSpy.mockReturnValueOnce(false);
|
|
45
|
-
|
|
46
|
-
renderHook(() =>
|
|
47
|
-
useDotcmsEditor({
|
|
48
|
-
pageContext: mockPageContext,
|
|
49
|
-
config: { pathname: '' }
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
expect(initEditorSpy).not.toHaveBeenCalled();
|
|
54
|
-
expect(destroyEditorSpy).not.toHaveBeenCalled();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('when inside editor', () => {
|
|
59
|
-
it('should call initEditor when inside editor', () => {
|
|
60
|
-
isInsideEditorSpy.mockReturnValueOnce(true);
|
|
61
|
-
|
|
62
|
-
renderHook(() =>
|
|
63
|
-
useDotcmsEditor({
|
|
64
|
-
pageContext: mockPageContext,
|
|
65
|
-
config: { pathname: '' }
|
|
66
|
-
})
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(initEditorSpy).toHaveBeenCalled();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should call destroyEditor on unmount when inside editor', () => {
|
|
73
|
-
isInsideEditorSpy.mockReturnValueOnce(true);
|
|
74
|
-
|
|
75
|
-
const { unmount } = renderHook(() =>
|
|
76
|
-
useDotcmsEditor({
|
|
77
|
-
pageContext: mockPageContext,
|
|
78
|
-
config: { pathname: '' }
|
|
79
|
-
})
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
unmount();
|
|
83
|
-
|
|
84
|
-
expect(destroyEditorSpy).toHaveBeenCalled();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('onReload', () => {
|
|
88
|
-
const dotCMSPagePropsMock = {
|
|
89
|
-
pageContext: mockPageContext,
|
|
90
|
-
config: {
|
|
91
|
-
pathname: '',
|
|
92
|
-
onReload: () => {
|
|
93
|
-
/* do nothing */
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
beforeEach(() => {
|
|
99
|
-
isInsideEditorSpy.mockReturnValueOnce(true);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should subscribe to the `CHANGE` event', () => {
|
|
103
|
-
const client = DotCmsClient.instance;
|
|
104
|
-
|
|
105
|
-
renderHook(() => useDotcmsEditor(dotCMSPagePropsMock));
|
|
106
|
-
|
|
107
|
-
expect(client.editor.on).toHaveBeenCalledWith('changes', expect.any(Function));
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should remove listener on unmount', () => {
|
|
111
|
-
const client = DotCmsClient.instance;
|
|
112
|
-
|
|
113
|
-
const { unmount } = renderHook(() => useDotcmsEditor(dotCMSPagePropsMock));
|
|
114
|
-
|
|
115
|
-
unmount();
|
|
116
|
-
|
|
117
|
-
expect(client.editor.off).toHaveBeenCalledWith('changes');
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('Client is ready', () => {
|
|
122
|
-
const dotCMSPagePropsMock = {
|
|
123
|
-
pageContext: mockPageContext,
|
|
124
|
-
config: {
|
|
125
|
-
pathname: '',
|
|
126
|
-
onReload: () => {
|
|
127
|
-
/* do nothing */
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
it('should send a message to the editor when the client is ready', () => {
|
|
133
|
-
const editor: sdkClient.EditorConfig = {
|
|
134
|
-
params: {
|
|
135
|
-
depth: '0'
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
renderHook(() =>
|
|
140
|
-
useDotcmsEditor({
|
|
141
|
-
...dotCMSPagePropsMock,
|
|
142
|
-
config: {
|
|
143
|
-
pathname: '',
|
|
144
|
-
editor
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
expect(sdkClient.postMessageToEditor).toHaveBeenCalledWith({
|
|
150
|
-
action: sdkClient.CUSTOMER_ACTIONS.CLIENT_READY,
|
|
151
|
-
payload: editor
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('onChange', () => {
|
|
157
|
-
const dotCMSPagePropsMock = {
|
|
158
|
-
pageContext: mockPageContext,
|
|
159
|
-
config: {
|
|
160
|
-
pathname: '',
|
|
161
|
-
editor: {
|
|
162
|
-
query: '{query { asset { identifier } }}'
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
it('should update the page asset when changes are made in the editor', () => {
|
|
168
|
-
const client = DotCmsClient.instance;
|
|
169
|
-
|
|
170
|
-
renderHook(() => useDotcmsEditor(dotCMSPagePropsMock as DotcmsPageProps));
|
|
171
|
-
|
|
172
|
-
expect(client.editor.on).toHaveBeenCalledWith('changes', expect.any(Function));
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
CUSTOMER_ACTIONS,
|
|
5
|
-
DotCmsClient,
|
|
6
|
-
destroyEditor,
|
|
7
|
-
initEditor,
|
|
8
|
-
isInsideEditor as isInsideEditorFn,
|
|
9
|
-
postMessageToEditor,
|
|
10
|
-
updateNavigation
|
|
11
|
-
} from '@dotcms/client';
|
|
12
|
-
|
|
13
|
-
import { DotcmsPageProps } from '../components/DotcmsLayout/DotcmsLayout';
|
|
14
|
-
import { DotCMSPageContext } from '../models';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Custom Hook to handle the DotCMS editor interaction with the page.
|
|
18
|
-
*
|
|
19
|
-
* @category Hooks
|
|
20
|
-
* @param {DotcmsPageProps} props {
|
|
21
|
-
* pageContext,
|
|
22
|
-
* config,
|
|
23
|
-
* }
|
|
24
|
-
* @returns {DotCMSPageContext} The context for a DotCMS page provided by the editor.
|
|
25
|
-
*/
|
|
26
|
-
export const useDotcmsEditor = ({ pageContext, config }: DotcmsPageProps) => {
|
|
27
|
-
const { pathname, onReload, editor } = config;
|
|
28
|
-
const [state, setState] = useState<DotCMSPageContext>({
|
|
29
|
-
...pageContext,
|
|
30
|
-
isInsideEditor: false
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Initializes the DotCMS editor.
|
|
35
|
-
*/
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (!isInsideEditorFn()) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
initEditor({ pathname });
|
|
42
|
-
updateNavigation(pathname || '/');
|
|
43
|
-
setState((prevState) => ({ ...prevState, isInsideEditor: true }));
|
|
44
|
-
|
|
45
|
-
return () => destroyEditor();
|
|
46
|
-
}, [pathname]);
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Reloads the page when changes are made in the editor.
|
|
50
|
-
*/
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
const insideEditor = isInsideEditorFn();
|
|
53
|
-
const client = DotCmsClient.instance;
|
|
54
|
-
|
|
55
|
-
if (!insideEditor || !onReload) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
client.editor.on('changes', () => onReload?.());
|
|
60
|
-
|
|
61
|
-
return () => client.editor.off('changes');
|
|
62
|
-
}, [onReload]);
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Sends a message to the editor when the client is ready.
|
|
66
|
-
*/
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (!isInsideEditorFn()) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
postMessageToEditor({ action: CUSTOMER_ACTIONS.CLIENT_READY, payload: editor });
|
|
73
|
-
}, [pathname, editor]);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Updates the page asset when changes are made in the editor.
|
|
77
|
-
*/
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (!isInsideEditorFn()) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const client = DotCmsClient.instance;
|
|
84
|
-
|
|
85
|
-
client.editor.on('changes', (data) => {
|
|
86
|
-
const pageAsset = data as DotCMSPageContext['pageAsset'];
|
|
87
|
-
setState((state) => ({ ...state, pageAsset }));
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
return () => client.editor.off('changes');
|
|
91
|
-
}, []);
|
|
92
|
-
|
|
93
|
-
return state;
|
|
94
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
import { useDotcmsPageContext } from './useDotcmsPageContext'; // Adjust the import path based on your file structure.
|
|
5
|
-
|
|
6
|
-
import { PageContext } from '../contexts/PageContext';
|
|
7
|
-
import { DotCMSPageContext } from '../models';
|
|
8
|
-
|
|
9
|
-
const mockContextValue: DotCMSPageContext = {
|
|
10
|
-
components: {},
|
|
11
|
-
isInsideEditor: false,
|
|
12
|
-
pageAsset: {
|
|
13
|
-
containers: {},
|
|
14
|
-
layout: {
|
|
15
|
-
header: false,
|
|
16
|
-
footer: false,
|
|
17
|
-
body: {
|
|
18
|
-
rows: []
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
page: {
|
|
22
|
-
title: 'Test Page',
|
|
23
|
-
identifier: 'test-page'
|
|
24
|
-
},
|
|
25
|
-
viewAs: {
|
|
26
|
-
language: {
|
|
27
|
-
id: 'en'
|
|
28
|
-
},
|
|
29
|
-
persona: {
|
|
30
|
-
keyTag: 'persona'
|
|
31
|
-
},
|
|
32
|
-
variantId: 'variant'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
describe('useDotcmsPageContext', () => {
|
|
38
|
-
it('returns the context value', () => {
|
|
39
|
-
const { result } = renderHook(() => useDotcmsPageContext(), {
|
|
40
|
-
wrapper: ({ children }: { children: ReactNode }) => (
|
|
41
|
-
<PageContext.Provider value={mockContextValue}>{children}</PageContext.Provider>
|
|
42
|
-
)
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(result.current).toEqual(mockContextValue);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { PageProvider } from '../components/PageProvider/PageProvider';
|
|
2
|
-
import { DotCMSPageContext, DotCMSContentlet } from '../models';
|
|
3
|
-
|
|
4
|
-
export const dotcmsContentletMock: DotCMSContentlet = {
|
|
5
|
-
archived: false,
|
|
6
|
-
baseType: '',
|
|
7
|
-
contentType: '',
|
|
8
|
-
folder: '',
|
|
9
|
-
hasTitleImage: false,
|
|
10
|
-
host: '',
|
|
11
|
-
hostName: '',
|
|
12
|
-
identifier: '',
|
|
13
|
-
inode: '',
|
|
14
|
-
languageId: 1,
|
|
15
|
-
live: false,
|
|
16
|
-
locked: false,
|
|
17
|
-
modDate: '',
|
|
18
|
-
modUser: '',
|
|
19
|
-
modUserName: '',
|
|
20
|
-
owner: '',
|
|
21
|
-
sortOrder: 1,
|
|
22
|
-
stInode: '',
|
|
23
|
-
title: 'This is my editable title',
|
|
24
|
-
titleImage: '',
|
|
25
|
-
url: '',
|
|
26
|
-
working: false
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const mockPageContext: DotCMSPageContext = {
|
|
30
|
-
pageAsset: {
|
|
31
|
-
layout: {
|
|
32
|
-
header: true,
|
|
33
|
-
footer: true,
|
|
34
|
-
body: {
|
|
35
|
-
rows: [
|
|
36
|
-
{
|
|
37
|
-
styleClass: 'row',
|
|
38
|
-
columns: [
|
|
39
|
-
{
|
|
40
|
-
styleClass: 'col-md-12',
|
|
41
|
-
width: 6,
|
|
42
|
-
leftOffset: 3,
|
|
43
|
-
containers: [
|
|
44
|
-
{
|
|
45
|
-
identifier: 'container-1',
|
|
46
|
-
uuid: 'uuid-1'
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
containers: {
|
|
56
|
-
'container-1': {
|
|
57
|
-
container: {
|
|
58
|
-
path: 'path/to/container',
|
|
59
|
-
identifier: 'container-1',
|
|
60
|
-
maxContentlets: 100,
|
|
61
|
-
parentPermissionable: {}
|
|
62
|
-
},
|
|
63
|
-
containerStructures: [
|
|
64
|
-
{
|
|
65
|
-
contentTypeVar: 'content-type-1'
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
|
-
contentlets: {
|
|
69
|
-
'uuid-1': [
|
|
70
|
-
{
|
|
71
|
-
contentType: 'content-type-1',
|
|
72
|
-
identifier: 'contentlet-1',
|
|
73
|
-
title: 'Contentlet 1',
|
|
74
|
-
inode: 'inode-1',
|
|
75
|
-
onNumberOfPages: 1,
|
|
76
|
-
baseType: 'base-type-1'
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
'container-2': {
|
|
82
|
-
container: {
|
|
83
|
-
path: 'path/to/container',
|
|
84
|
-
identifier: 'container-2',
|
|
85
|
-
maxContentlets: 100,
|
|
86
|
-
parentPermissionable: {}
|
|
87
|
-
},
|
|
88
|
-
containerStructures: [
|
|
89
|
-
{
|
|
90
|
-
contentTypeVar: 'content-type-2'
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
contentlets: {
|
|
94
|
-
'uuid-2': []
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
page: { identifier: 'page-1', title: 'Hello Page' },
|
|
99
|
-
viewAs: { language: { id: 'en' }, persona: { keyTag: 'persona-1' }, variantId: 'variant-1' }
|
|
100
|
-
},
|
|
101
|
-
components: {},
|
|
102
|
-
isInsideEditor: false
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const MockContextRender = ({
|
|
106
|
-
children,
|
|
107
|
-
mockContext
|
|
108
|
-
}: {
|
|
109
|
-
children: JSX.Element;
|
|
110
|
-
mockContext: Partial<DotCMSPageContext>;
|
|
111
|
-
}) => {
|
|
112
|
-
return <PageProvider pageContext={mockContext}>{children}</PageProvider>;
|
|
113
|
-
};
|
package/src/lib/utils/utils.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ContainerData, DotCMSPageContext } from '../models';
|
|
2
|
-
|
|
3
|
-
const endClassMap: Record<number, string> = {
|
|
4
|
-
1: 'col-end-1',
|
|
5
|
-
2: 'col-end-2',
|
|
6
|
-
3: 'col-end-3',
|
|
7
|
-
4: 'col-end-4',
|
|
8
|
-
5: 'col-end-5',
|
|
9
|
-
6: 'col-end-6',
|
|
10
|
-
7: 'col-end-7',
|
|
11
|
-
8: 'col-end-8',
|
|
12
|
-
9: 'col-end-9',
|
|
13
|
-
10: 'col-end-10',
|
|
14
|
-
11: 'col-end-11',
|
|
15
|
-
12: 'col-end-12',
|
|
16
|
-
13: 'col-end-13'
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const startClassMap: Record<number, string> = {
|
|
20
|
-
1: 'col-start-1',
|
|
21
|
-
2: 'col-start-2',
|
|
22
|
-
3: 'col-start-3',
|
|
23
|
-
4: 'col-start-4',
|
|
24
|
-
5: 'col-start-5',
|
|
25
|
-
6: 'col-start-6',
|
|
26
|
-
7: 'col-start-7',
|
|
27
|
-
8: 'col-start-8',
|
|
28
|
-
9: 'col-start-9',
|
|
29
|
-
10: 'col-start-10',
|
|
30
|
-
11: 'col-start-11',
|
|
31
|
-
12: 'col-start-12'
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get the container data from the containers object using the current container reference obtained from the layout.
|
|
36
|
-
*
|
|
37
|
-
* @param {ContainerData} containers
|
|
38
|
-
* @param {DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]} containerRef
|
|
39
|
-
* @returns {Object} Container with all the data it has.
|
|
40
|
-
*/
|
|
41
|
-
export const getContainersData = (
|
|
42
|
-
containers: ContainerData,
|
|
43
|
-
containerRef: DotCMSPageContext['pageAsset']['layout']['body']['rows'][0]['columns'][0]['containers'][0]
|
|
44
|
-
) => {
|
|
45
|
-
const { identifier, uuid } = containerRef;
|
|
46
|
-
|
|
47
|
-
const { containerStructures, container } = containers[identifier];
|
|
48
|
-
|
|
49
|
-
// Get the variant id
|
|
50
|
-
const { variantId } = container?.parentPermissionable || {};
|
|
51
|
-
|
|
52
|
-
// Get accepts types of content types for this container
|
|
53
|
-
const acceptTypes = containerStructures.map((structure) => structure.contentTypeVar).join(',');
|
|
54
|
-
|
|
55
|
-
// Get the contentlets for "this" container
|
|
56
|
-
const contentlets = containers[identifier].contentlets[`uuid-${uuid}`];
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
...containers[identifier].container,
|
|
60
|
-
acceptTypes,
|
|
61
|
-
contentlets,
|
|
62
|
-
variantId
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Combine classes into a single string.
|
|
68
|
-
*
|
|
69
|
-
* @param {string[]} classes
|
|
70
|
-
* @returns {string} Combined classes
|
|
71
|
-
*/
|
|
72
|
-
export const combineClasses = (classes: string[]) => classes.filter(Boolean).join(' ');
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Get the start and end classes for the column based on the left offset and width.
|
|
76
|
-
*
|
|
77
|
-
* @param {number} start
|
|
78
|
-
* @param {number} end
|
|
79
|
-
* @returns {Object} Start and end classes
|
|
80
|
-
*/
|
|
81
|
-
export const getPositionStyleClasses = (start: number, end: number) => {
|
|
82
|
-
const startClass = startClassMap[start];
|
|
83
|
-
const endClass = endClassMap[end];
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
startClass,
|
|
87
|
-
endClass
|
|
88
|
-
};
|
|
89
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"jsx": "react-jsx",
|
|
4
|
-
"allowJs": false,
|
|
5
|
-
"esModuleInterop": false,
|
|
6
|
-
"allowSyntheticDefaultImports": true,
|
|
7
|
-
"strict": true
|
|
8
|
-
},
|
|
9
|
-
"files": [],
|
|
10
|
-
"include": [],
|
|
11
|
-
"references": [
|
|
12
|
-
{
|
|
13
|
-
"path": "./tsconfig.lib.json"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.spec.json"
|
|
17
|
-
}
|
|
18
|
-
],
|
|
19
|
-
"extends": "../../../tsconfig.base.json"
|
|
20
|
-
}
|