@squiz/formatted-text-editor 1.68.1 → 1.69.0
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/CHANGELOG.md +6 -0
- package/lib/Extensions/Extensions.d.ts +1 -0
- package/lib/Extensions/Extensions.js +2 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +1 -0
- package/package.json +1 -1
- package/src/Editor/Editor.spec.tsx +23 -0
- package/src/Extensions/Extensions.ts +3 -0
- package/src/utils/converters/htmlToSquizNode/htmlToSquizNode.spec.ts +2 -3
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.spec.ts +24 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +23 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +1 -0
- package/src/utils/getNodeNamesByGroup.spec.ts +1 -0
package/CHANGELOG.md
CHANGED
@@ -18,6 +18,7 @@ var NodeName;
|
|
18
18
|
NodeName["CodeBlock"] = "codeBlock";
|
19
19
|
NodeName["AssetImage"] = "assetImage";
|
20
20
|
NodeName["Text"] = "text";
|
21
|
+
NodeName["hardBreak"] = "hardBreak";
|
21
22
|
NodeName["Unsupported"] = "unsupportedNode";
|
22
23
|
})(NodeName = exports.NodeName || (exports.NodeName = {}));
|
23
24
|
var MarkName;
|
@@ -35,6 +36,7 @@ const createExtensions = (context, browserContext) => {
|
|
35
36
|
new extensions_1.ItalicExtension(),
|
36
37
|
new extensions_1.NodeFormattingExtension({ indents: [] }),
|
37
38
|
new extensions_1.ParagraphExtension(),
|
39
|
+
new extensions_1.HardBreakExtension(),
|
38
40
|
new PreformattedExtension_1.PreformattedExtension(),
|
39
41
|
new CodeBlockExtension_1.ExtendedCodeBlockExtension({ defaultWrap: true }),
|
40
42
|
new extensions_1.UnderlineExtension(),
|
package/package.json
CHANGED
@@ -233,6 +233,29 @@ describe('Formatted text editor', () => {
|
|
233
233
|
expect(baseElement.querySelectorAll('div.remirror-editor p')).toHaveLength(1);
|
234
234
|
});
|
235
235
|
|
236
|
+
it('Applies line break within text content when SHIFT+ENTER is used', async () => {
|
237
|
+
const { editor, getJsonContent } = await renderWithEditor(null, {
|
238
|
+
content: 'Some nonsense content here',
|
239
|
+
});
|
240
|
+
|
241
|
+
await act(() => editor.jumpTo('end'));
|
242
|
+
await act(() => editor.press('Shift-Enter'));
|
243
|
+
|
244
|
+
expect(getJsonContent()).toEqual({
|
245
|
+
type: 'paragraph',
|
246
|
+
attrs: expect.any(Object),
|
247
|
+
content: [
|
248
|
+
{
|
249
|
+
type: 'text',
|
250
|
+
text: 'Some nonsense content here',
|
251
|
+
},
|
252
|
+
{
|
253
|
+
type: 'hardBreak',
|
254
|
+
},
|
255
|
+
],
|
256
|
+
});
|
257
|
+
});
|
258
|
+
|
236
259
|
it('should allow text to be pasted into the editor', async () => {
|
237
260
|
const { editor, getJsonContent } = await renderWithEditor(<ImageButton />, {
|
238
261
|
content: 'Some nonsense content here',
|
@@ -13,6 +13,7 @@ import {
|
|
13
13
|
PlaceholderExtension,
|
14
14
|
HorizontalRuleExtension,
|
15
15
|
TextExtension,
|
16
|
+
HardBreakExtension,
|
16
17
|
} from 'remirror/extensions';
|
17
18
|
import { Extension } from '@remirror/core';
|
18
19
|
import { PreformattedExtension } from './PreformattedExtension/PreformattedExtension';
|
@@ -32,6 +33,7 @@ export enum NodeName {
|
|
32
33
|
CodeBlock = 'codeBlock',
|
33
34
|
AssetImage = 'assetImage',
|
34
35
|
Text = 'text',
|
36
|
+
hardBreak = 'hardBreak',
|
35
37
|
Unsupported = 'unsupportedNode',
|
36
38
|
}
|
37
39
|
|
@@ -50,6 +52,7 @@ export const createExtensions = (context: EditorContextOptions, browserContext:
|
|
50
52
|
new ItalicExtension(),
|
51
53
|
new NodeFormattingExtension({ indents: [] }),
|
52
54
|
new ParagraphExtension(),
|
55
|
+
new HardBreakExtension(),
|
53
56
|
new PreformattedExtension(),
|
54
57
|
new ExtendedCodeBlockExtension({ defaultWrap: true }),
|
55
58
|
new UnderlineExtension(),
|
@@ -131,8 +131,7 @@ describe('htmlToSquizNode', () => {
|
|
131
131
|
[
|
132
132
|
'nested block level tags are un-nested/normalised to a supported structure',
|
133
133
|
"<div><p>Div tags are not support, <p>Nested block element also aren't</p></p>" +
|
134
|
-
'<span>Span tags are not supported</span
|
135
|
-
'Break lines also, you got it, not supported.',
|
134
|
+
'<span>Span tags are not supported</span>',
|
136
135
|
[
|
137
136
|
{
|
138
137
|
children: [
|
@@ -163,7 +162,7 @@ describe('htmlToSquizNode', () => {
|
|
163
162
|
children: [
|
164
163
|
{
|
165
164
|
type: 'text',
|
166
|
-
value: 'Span tags are not supported
|
165
|
+
value: 'Span tags are not supported',
|
167
166
|
},
|
168
167
|
],
|
169
168
|
tag: 'p',
|
@@ -112,6 +112,30 @@ describe('remirrorNodeToSquizNode', () => {
|
|
112
112
|
expect(result).toEqual(expected);
|
113
113
|
});
|
114
114
|
|
115
|
+
it('should handle line break formatting', async () => {
|
116
|
+
const content: RemirrorJSON = {
|
117
|
+
type: 'doc',
|
118
|
+
content: [
|
119
|
+
{
|
120
|
+
type: 'hardBreak',
|
121
|
+
},
|
122
|
+
],
|
123
|
+
};
|
124
|
+
|
125
|
+
const { editor } = await renderWithEditor(null, { content });
|
126
|
+
|
127
|
+
const expected: FormattedText = [
|
128
|
+
{
|
129
|
+
type: 'tag',
|
130
|
+
tag: 'br',
|
131
|
+
children: [],
|
132
|
+
},
|
133
|
+
];
|
134
|
+
|
135
|
+
const result = remirrorNodeToSquizNode(editor.doc);
|
136
|
+
expect(result).toEqual(expected);
|
137
|
+
});
|
138
|
+
|
115
139
|
it('should handle images', async () => {
|
116
140
|
const content: RemirrorJSON = {
|
117
141
|
type: 'doc',
|
@@ -213,6 +213,29 @@ describe('squizNodeToRemirrorNode', () => {
|
|
213
213
|
expect(result).toEqual(expected);
|
214
214
|
});
|
215
215
|
|
216
|
+
it('should handle line breaks', () => {
|
217
|
+
const squizComponentJSON: FormattedText = [
|
218
|
+
{
|
219
|
+
children: [],
|
220
|
+
type: 'tag',
|
221
|
+
tag: 'br',
|
222
|
+
},
|
223
|
+
];
|
224
|
+
|
225
|
+
const expected: RemirrorJSON = {
|
226
|
+
content: [
|
227
|
+
{
|
228
|
+
attrs: expect.any(Object),
|
229
|
+
type: 'hardBreak',
|
230
|
+
},
|
231
|
+
],
|
232
|
+
type: 'doc',
|
233
|
+
};
|
234
|
+
|
235
|
+
const result = squizNodeToRemirrorNode(squizComponentJSON);
|
236
|
+
expect(result).toEqual(expected);
|
237
|
+
});
|
238
|
+
|
216
239
|
it('should handle pre formatted text', () => {
|
217
240
|
const squizComponentJSON: FormattedText = [
|
218
241
|
{
|