@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.69.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6b8b464: Added support for SHIFT + ENTER line breaks to FTE
8
+
3
9
  ## 1.68.1
4
10
 
5
11
  ### Patch Changes
@@ -6,6 +6,7 @@ export declare enum NodeName {
6
6
  CodeBlock = "codeBlock",
7
7
  AssetImage = "assetImage",
8
8
  Text = "text",
9
+ hardBreak = "hardBreak",
9
10
  Unsupported = "unsupportedNode"
10
11
  }
11
12
  export declare enum MarkName {
@@ -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(),
@@ -28,6 +28,7 @@ const getNodeType = (node) => {
28
28
  span: Extensions_1.NodeName.Text,
29
29
  strong: Extensions_1.NodeName.Text,
30
30
  code: Extensions_1.NodeName.CodeBlock,
31
+ br: Extensions_1.NodeName.hardBreak,
31
32
  };
32
33
  if (typeMap[node.type]) {
33
34
  return typeMap[node.type];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/formatted-text-editor",
3
- "version": "1.68.1",
3
+ "version": "1.69.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -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><br />' +
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 Break lines also, you got it, 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
  {
@@ -33,6 +33,7 @@ const getNodeType = (node: FormattedNodes): string => {
33
33
  span: NodeName.Text,
34
34
  strong: NodeName.Text,
35
35
  code: NodeName.CodeBlock,
36
+ br: NodeName.hardBreak,
36
37
  };
37
38
 
38
39
  if (typeMap[node.type]) {
@@ -26,6 +26,7 @@ describe('getNodeNamesByGroup', () => {
26
26
  'listItem',
27
27
  'orderedList',
28
28
  'horizontalRule',
29
+ 'hardBreak',
29
30
  ]);
30
31
  });
31
32
  });