@squiz/formatted-text-editor 1.12.0-alpha.39 → 1.12.0-alpha.40
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 +2 -0
- package/lib/Editor/Editor.js +2 -13
- package/lib/Extensions/Extensions.d.ts +3 -0
- package/lib/Extensions/Extensions.js +13 -0
- package/lib/{extensions → Extensions}/PreformattedExtension/PreformattedExtension.d.ts +0 -0
- package/lib/{extensions → Extensions}/PreformattedExtension/PreformattedExtension.js +0 -0
- package/package.json +2 -2
- package/src/Editor/Editor.mock.tsx +40 -0
- package/src/Editor/Editor.spec.tsx +28 -2
- package/src/Editor/Editor.tsx +3 -23
- package/src/EditorToolbar/Tools/TextType/Preformatted/PreformattedButton.tsx +1 -1
- package/src/EditorToolbar/Tools/TextType/TextTypeDropdown.tsx +1 -1
- package/src/Extensions/Extensions.tsx +24 -0
- package/src/{extensions → Extensions}/PreformattedExtension/PreformattedExtension.tsx +0 -0
- package/src/FormattedTextEditor.spec.tsx +10 -0
package/README.md
CHANGED
@@ -51,6 +51,8 @@ Or if you'd like to "watch" for changes:
|
|
51
51
|
npm run test:watch
|
52
52
|
```
|
53
53
|
|
54
|
+
When testing text input in the text editor, it is recommended to use the `<MockEditor />` component, which is a simple wrapper around the Remirror component that provides additional functionality for testing (supplying text into the editor).
|
55
|
+
|
54
56
|
### End to end testing
|
55
57
|
|
56
58
|
This package uses [Cypress](https://docs.cypress.io/) for end to end testing.
|
package/lib/Editor/Editor.js
CHANGED
@@ -1,21 +1,10 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { BoldExtension, HeadingExtension, ItalicExtension, NodeFormattingExtension, ParagraphExtension, UnderlineExtension, HistoryExtension, wysiwygPreset, } from 'remirror/extensions';
|
3
2
|
import { EditorComponent, Remirror, useRemirror } from '@remirror/react';
|
4
3
|
import { EditorToolbar } from '../EditorToolbar/EditorToolbar';
|
5
|
-
import {
|
4
|
+
import { Extensions } from '../Extensions/Extensions';
|
6
5
|
const Editor = ({ content }) => {
|
7
6
|
const { manager, state, setState } = useRemirror({
|
8
|
-
extensions:
|
9
|
-
...wysiwygPreset(),
|
10
|
-
new BoldExtension(),
|
11
|
-
new HeadingExtension(),
|
12
|
-
new ItalicExtension(),
|
13
|
-
new NodeFormattingExtension(),
|
14
|
-
new ParagraphExtension(),
|
15
|
-
new PreformattedExtension(),
|
16
|
-
new UnderlineExtension(),
|
17
|
-
new HistoryExtension(),
|
18
|
-
],
|
7
|
+
extensions: Extensions,
|
19
8
|
content,
|
20
9
|
selection: 'start',
|
21
10
|
stringHandler: 'html',
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { BoldExtension, HeadingExtension, NodeFormattingExtension, HistoryExtension } from 'remirror/extensions';
|
2
|
+
import { Extension } from '@remirror/core';
|
3
|
+
export declare const Extensions: () => (BoldExtension | HistoryExtension | HeadingExtension | NodeFormattingExtension | Extension<import("@remirror/core").EmptyShape>)[];
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { BoldExtension, HeadingExtension, ItalicExtension, NodeFormattingExtension, ParagraphExtension, UnderlineExtension, HistoryExtension, wysiwygPreset, } from 'remirror/extensions';
|
2
|
+
import { PreformattedExtension } from './PreformattedExtension/PreformattedExtension';
|
3
|
+
export const Extensions = () => [
|
4
|
+
...wysiwygPreset(),
|
5
|
+
new BoldExtension(),
|
6
|
+
new HeadingExtension(),
|
7
|
+
new ItalicExtension(),
|
8
|
+
new NodeFormattingExtension(),
|
9
|
+
new ParagraphExtension(),
|
10
|
+
new PreformattedExtension(),
|
11
|
+
new UnderlineExtension(),
|
12
|
+
new HistoryExtension(),
|
13
|
+
];
|
File without changes
|
File without changes
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/formatted-text-editor",
|
3
|
-
"version": "1.12.0-alpha.
|
3
|
+
"version": "1.12.0-alpha.40",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"scripts": {
|
@@ -61,5 +61,5 @@
|
|
61
61
|
"volta": {
|
62
62
|
"node": "16.19.0"
|
63
63
|
},
|
64
|
-
"gitHead": "
|
64
|
+
"gitHead": "8db852ade2813dc297b7d0fa4975e0c5a57ac83e"
|
65
65
|
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { Remirror, useRemirror, useRemirrorContext } from '@remirror/react';
|
2
|
+
import React from 'react';
|
3
|
+
import { EditorToolbar } from '../EditorToolbar/EditorToolbar';
|
4
|
+
import { Extensions } from '../Extensions/Extensions';
|
5
|
+
|
6
|
+
type MockEditorProps = {
|
7
|
+
setContent?: any;
|
8
|
+
};
|
9
|
+
|
10
|
+
export const MockEditor = ({ setContent }: MockEditorProps) => {
|
11
|
+
const { manager, state, setState } = useRemirror({
|
12
|
+
extensions: Extensions,
|
13
|
+
selection: 'start',
|
14
|
+
stringHandler: 'html',
|
15
|
+
});
|
16
|
+
|
17
|
+
const Component = () => {
|
18
|
+
setContent && setContent.mockImplementation(useRemirrorContext().setContent);
|
19
|
+
return null;
|
20
|
+
};
|
21
|
+
|
22
|
+
const handleChange = (parameter: { state: any }) => {
|
23
|
+
setState(parameter.state);
|
24
|
+
};
|
25
|
+
|
26
|
+
return (
|
27
|
+
<Remirror
|
28
|
+
manager={manager}
|
29
|
+
onChange={handleChange}
|
30
|
+
placeholder="Write something"
|
31
|
+
label="Text editor"
|
32
|
+
state={state}
|
33
|
+
autoRender="start"
|
34
|
+
>
|
35
|
+
<EditorToolbar manager={manager} />
|
36
|
+
<Component />
|
37
|
+
<EditorToolbar manager={manager} isPopover />
|
38
|
+
</Remirror>
|
39
|
+
);
|
40
|
+
};
|
@@ -1,7 +1,11 @@
|
|
1
|
+
import { jest } from '@jest/globals';
|
1
2
|
import React from 'react';
|
2
|
-
import '@testing-library/
|
3
|
+
import { act, fireEvent, render, screen } from '@testing-library/react';
|
4
|
+
import { MockEditor } from './Editor.mock';
|
3
5
|
import Editor from './Editor';
|
4
|
-
import
|
6
|
+
import '@testing-library/jest-dom';
|
7
|
+
|
8
|
+
const setContent: any = jest.fn();
|
5
9
|
|
6
10
|
describe('Formatted text editor', () => {
|
7
11
|
it('Renders the text editor', () => {
|
@@ -225,4 +229,26 @@ describe('Formatted text editor', () => {
|
|
225
229
|
|
226
230
|
expect(baseElement.querySelectorAll('div.remirror-editor p')).toHaveLength(2);
|
227
231
|
});
|
232
|
+
|
233
|
+
it('Should allow text input & undo input upon clicking undo button', () => {
|
234
|
+
const { baseElement, getByLabelText } = render(<MockEditor setContent={setContent} />);
|
235
|
+
|
236
|
+
const textContent = `This is a string with a random number: ${Math.random() * 9999}`;
|
237
|
+
|
238
|
+
// This sets the content of the text editor
|
239
|
+
act(() => {
|
240
|
+
setContent(`<p>${textContent}</p>`, { triggerChange: true });
|
241
|
+
});
|
242
|
+
|
243
|
+
const editorNode = getByLabelText(`Text editor`);
|
244
|
+
expect(editorNode).toBeTruthy();
|
245
|
+
expect(editorNode.textContent).toBe(textContent);
|
246
|
+
|
247
|
+
// Testing if clicking undo button removes text from editor
|
248
|
+
const undoButton = baseElement.querySelector('button[title="Undo (cmd+Z)"]') as HTMLButtonElement;
|
249
|
+
expect(undoButton).toBeTruthy();
|
250
|
+
fireEvent.click(undoButton);
|
251
|
+
|
252
|
+
expect(editorNode.textContent).toBe('');
|
253
|
+
});
|
228
254
|
});
|
package/src/Editor/Editor.tsx
CHANGED
@@ -1,18 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import {
|
3
|
-
BoldExtension,
|
4
|
-
HeadingExtension,
|
5
|
-
ItalicExtension,
|
6
|
-
NodeFormattingExtension,
|
7
|
-
ParagraphExtension,
|
8
|
-
UnderlineExtension,
|
9
|
-
HistoryExtension,
|
10
|
-
wysiwygPreset,
|
11
|
-
} from 'remirror/extensions';
|
12
2
|
import { EditorComponent, Remirror, useRemirror } from '@remirror/react';
|
13
|
-
import { RemirrorContentType
|
3
|
+
import { RemirrorContentType } from '@remirror/core';
|
14
4
|
import { EditorToolbar } from '../EditorToolbar/EditorToolbar';
|
15
|
-
import {
|
5
|
+
import { Extensions } from '../Extensions/Extensions';
|
16
6
|
|
17
7
|
type EditorProps = {
|
18
8
|
content?: RemirrorContentType;
|
@@ -20,17 +10,7 @@ type EditorProps = {
|
|
20
10
|
|
21
11
|
const Editor = ({ content }: EditorProps) => {
|
22
12
|
const { manager, state, setState } = useRemirror({
|
23
|
-
extensions:
|
24
|
-
...(wysiwygPreset() as Extension[]),
|
25
|
-
new BoldExtension(),
|
26
|
-
new HeadingExtension(),
|
27
|
-
new ItalicExtension(),
|
28
|
-
new NodeFormattingExtension(),
|
29
|
-
new ParagraphExtension(),
|
30
|
-
new PreformattedExtension(),
|
31
|
-
new UnderlineExtension(),
|
32
|
-
new HistoryExtension(),
|
33
|
-
],
|
13
|
+
extensions: Extensions,
|
34
14
|
content,
|
35
15
|
selection: 'start',
|
36
16
|
stringHandler: 'html',
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { useCommands, useActive } from '@remirror/react';
|
3
|
-
import { PreformattedExtension } from '../../../../
|
3
|
+
import { PreformattedExtension } from '../../../../Extensions/PreformattedExtension/PreformattedExtension';
|
4
4
|
import DropdownButton from '../../../../ui/DropdownButton/DropdownButton';
|
5
5
|
|
6
6
|
const PreformattedButton = () => {
|
@@ -4,7 +4,7 @@ import ParagraphButton from './Paragraph/ParagraphButton';
|
|
4
4
|
import PreformattedButton from './Preformatted/PreformattedButton';
|
5
5
|
import ToolbarDropdown from '../../../ui/ToolbarDropdown/ToolbarDropdown';
|
6
6
|
import { useActive, VerticalDivider } from '@remirror/react';
|
7
|
-
import { PreformattedExtension } from '../../../
|
7
|
+
import { PreformattedExtension } from '../../../Extensions/PreformattedExtension/PreformattedExtension';
|
8
8
|
|
9
9
|
const TextTypeDropdown = () => {
|
10
10
|
const active = useActive<PreformattedExtension>();
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import {
|
2
|
+
BoldExtension,
|
3
|
+
HeadingExtension,
|
4
|
+
ItalicExtension,
|
5
|
+
NodeFormattingExtension,
|
6
|
+
ParagraphExtension,
|
7
|
+
UnderlineExtension,
|
8
|
+
HistoryExtension,
|
9
|
+
wysiwygPreset,
|
10
|
+
} from 'remirror/extensions';
|
11
|
+
import { PreformattedExtension } from './PreformattedExtension/PreformattedExtension';
|
12
|
+
import { Extension } from '@remirror/core';
|
13
|
+
|
14
|
+
export const Extensions = () => [
|
15
|
+
...(wysiwygPreset() as Extension[]),
|
16
|
+
new BoldExtension(),
|
17
|
+
new HeadingExtension(),
|
18
|
+
new ItalicExtension(),
|
19
|
+
new NodeFormattingExtension(),
|
20
|
+
new ParagraphExtension(),
|
21
|
+
new PreformattedExtension(),
|
22
|
+
new UnderlineExtension(),
|
23
|
+
new HistoryExtension(),
|
24
|
+
];
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { render } from '@testing-library/react';
|
2
|
+
import { FormattedTextEditor } from './';
|
3
|
+
import React from 'react';
|
4
|
+
|
5
|
+
describe('<FormattedTextEditor />', () => {
|
6
|
+
it('should render "<FormattedTextEditor />" component', () => {
|
7
|
+
const { baseElement } = render(<FormattedTextEditor />);
|
8
|
+
expect(baseElement).toBeTruthy();
|
9
|
+
});
|
10
|
+
});
|