@squiz/formatted-text-editor 1.41.1-alpha.1 → 1.41.1-alpha.13

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.
@@ -19,6 +19,7 @@ const ImageButton_1 = __importDefault(require("./Tools/Image/ImageButton"));
19
19
  const RemoveLinkButton_1 = __importDefault(require("./Tools/Link/RemoveLinkButton"));
20
20
  const ClearFormattingButton_1 = __importDefault(require("./Tools/ClearFormatting/ClearFormattingButton"));
21
21
  const ListButtons_1 = __importDefault(require("./Tools/Lists/ListButtons"));
22
+ const HorizontalLineButton_1 = __importDefault(require("./Tools/HorizontalLine/HorizontalLineButton"));
22
23
  const hooks_1 = require("../hooks");
23
24
  const Toolbar = ({ isVisible }) => {
24
25
  const extensionNames = (0, hooks_1.useExtensionNames)();
@@ -33,6 +34,7 @@ const Toolbar = ({ isVisible }) => {
33
34
  extensionNames.underline && react_1.default.createElement(UnderlineButton_1.default, null),
34
35
  extensionNames.nodeFormatting && react_1.default.createElement(TextAlignButtons_1.default, null),
35
36
  extensionNames.listItem && react_1.default.createElement(ListButtons_1.default, null),
37
+ extensionNames.horizontalRule && react_1.default.createElement(HorizontalLineButton_1.default, null),
36
38
  extensionNames.link && (react_1.default.createElement(react_1.default.Fragment, null,
37
39
  react_1.default.createElement(LinkButton_1.default, null),
38
40
  react_1.default.createElement(RemoveLinkButton_1.default, null))),
@@ -0,0 +1,2 @@
1
+ declare const HorizontalLineButton: () => JSX.Element;
2
+ export default HorizontalLineButton;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const react_2 = require("@remirror/react");
8
+ const react_components_1 = require("@remirror/react-components");
9
+ const Button_1 = __importDefault(require("../../../ui/Button/Button"));
10
+ const HorizontalRuleRounded_1 = __importDefault(require("@mui/icons-material/HorizontalRuleRounded"));
11
+ const HorizontalLineButton = () => {
12
+ const { insertHorizontalRule } = (0, react_2.useCommands)();
13
+ const chain = (0, react_2.useChainedCommands)();
14
+ const active = (0, react_2.useActive)();
15
+ const enabled = insertHorizontalRule.enabled();
16
+ const handleSelect = () => {
17
+ if (insertHorizontalRule.enabled()) {
18
+ chain.insertHorizontalRule().focus().run();
19
+ }
20
+ };
21
+ return (react_1.default.createElement(react_1.default.Fragment, null,
22
+ react_1.default.createElement(Button_1.default, { handleOnClick: handleSelect, isDisabled: !enabled, isActive: active.italic(), icon: react_1.default.createElement(HorizontalRuleRounded_1.default, null), label: "Horizontal line" }),
23
+ react_1.default.createElement(react_components_1.VerticalDivider, null)));
24
+ };
25
+ exports.default = HorizontalLineButton;
@@ -52,6 +52,7 @@ const createExtensions = (context, browserContext) => {
52
52
  new extensions_1.BulletListExtension(),
53
53
  new extensions_1.ListItemExtension(),
54
54
  new extensions_1.OrderedListExtension(),
55
+ new extensions_1.HorizontalRuleExtension(),
55
56
  new extensions_1.PlaceholderExtension(),
56
57
  new FetchUrlExtension_1.FetchUrlExtension({
57
58
  fetchUrl: browserContext.onRequestResource,
package/lib/index.css CHANGED
@@ -722,6 +722,12 @@
722
722
  .squiz-fte-scope .remirror-editor ol {
723
723
  list-style-type: decimal;
724
724
  }
725
+ .squiz-fte-scope .remirror-editor hr {
726
+ -webkit-margin-before: 0.6rem;
727
+ margin-block-start: 0.6rem;
728
+ -webkit-margin-after: 0.6rem;
729
+ margin-block-end: 0.6rem;
730
+ }
725
731
  .squiz-fte-scope .squiz-fte-form-group {
726
732
  display: flex;
727
733
  flex-direction: column;
@@ -22,6 +22,7 @@ const getNodeType = (node) => {
22
22
  ol: 'orderedList',
23
23
  li: 'listItem',
24
24
  ul: 'bulletList',
25
+ hr: 'horizontalRule',
25
26
  a: Extensions_1.NodeName.Text,
26
27
  span: Extensions_1.NodeName.Text,
27
28
  code: Extensions_1.NodeName.CodeBlock,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/formatted-text-editor",
3
- "version": "1.41.1-alpha.1",
3
+ "version": "1.41.1-alpha.13",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -20,8 +20,8 @@
20
20
  "@headlessui/react": "1.7.11",
21
21
  "@mui/icons-material": "5.11.16",
22
22
  "@remirror/react": "2.0.25",
23
- "@squiz/dx-json-schema-lib": "1.41.1-alpha.1",
24
- "@squiz/resource-browser": "1.41.1-alpha.1",
23
+ "@squiz/dx-json-schema-lib": "1.41.1-alpha.13",
24
+ "@squiz/resource-browser": "1.41.1-alpha.13",
25
25
  "clsx": "1.2.1",
26
26
  "react-hook-form": "7.43.2",
27
27
  "react-image-size": "2.0.0",
@@ -75,5 +75,5 @@
75
75
  "volta": {
76
76
  "node": "18.15.0"
77
77
  },
78
- "gitHead": "9846df51097ed1fa4be5e5ac69f9e1904b4fe63c"
78
+ "gitHead": "9e572a4de6b25e7fa91e016c3706e1b257b05b4b"
79
79
  }
@@ -13,6 +13,7 @@ import ImageButton from './Tools/Image/ImageButton';
13
13
  import RemoveLinkButton from './Tools/Link/RemoveLinkButton';
14
14
  import ClearFormattingButton from './Tools/ClearFormatting/ClearFormattingButton';
15
15
  import ListButtons from './Tools/Lists/ListButtons';
16
+ import HorizontalLineButton from './Tools/HorizontalLine/HorizontalLineButton';
16
17
  import { useExtensionNames } from '../hooks';
17
18
 
18
19
  type ToolbarProps = {
@@ -40,6 +41,7 @@ export const Toolbar = ({ isVisible }: ToolbarProps) => {
40
41
  {extensionNames.underline && <UnderlineButton />}
41
42
  {extensionNames.nodeFormatting && <TextAlignButtons />}
42
43
  {extensionNames.listItem && <ListButtons />}
44
+ {extensionNames.horizontalRule && <HorizontalLineButton />}
43
45
  {extensionNames.link && (
44
46
  <>
45
47
  <LinkButton />
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import '@testing-library/jest-dom';
3
+ import { screen, fireEvent } from '@testing-library/react';
4
+ import { renderWithEditor } from '../../../../tests';
5
+ import HorizontalLineButton from './HorizontalLineButton';
6
+
7
+ describe('Horizontal line button', () => {
8
+ it('Renders the horizontal line button', async () => {
9
+ await renderWithEditor(<HorizontalLineButton />, { content: 'Some nonsense content here' });
10
+ expect(screen.getByRole('button', { name: 'Horizontal line' })).toBeInTheDocument();
11
+ });
12
+
13
+ it('Inserts a horizontal line into the editor content after clicking button', async () => {
14
+ const { getHtmlContent } = await renderWithEditor(<HorizontalLineButton />, {
15
+ content: '<p>Hello Mr Bean</p>',
16
+ });
17
+
18
+ const horizontalLine = screen.getByRole('button', { name: 'Horizontal line' });
19
+ fireEvent.click(horizontalLine);
20
+
21
+ expect(getHtmlContent()).toBe('<hr><p style="">Hello Mr Bean</p>');
22
+ });
23
+ });
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { useCommands, useActive, useChainedCommands } from '@remirror/react';
3
+ import { VerticalDivider } from '@remirror/react-components';
4
+ import { HorizontalRuleExtension } from '@remirror/extension-horizontal-rule';
5
+ import Button from '../../../ui/Button/Button';
6
+ import HorizontalRuleRounded from '@mui/icons-material/HorizontalRuleRounded';
7
+
8
+ const HorizontalLineButton = () => {
9
+ const { insertHorizontalRule } = useCommands();
10
+ const chain = useChainedCommands();
11
+
12
+ const active = useActive<HorizontalRuleExtension>();
13
+ const enabled = insertHorizontalRule.enabled();
14
+ const handleSelect = () => {
15
+ if (insertHorizontalRule.enabled()) {
16
+ chain.insertHorizontalRule().focus().run();
17
+ }
18
+ };
19
+
20
+ return (
21
+ <>
22
+ <Button
23
+ handleOnClick={handleSelect}
24
+ isDisabled={!enabled}
25
+ isActive={active.italic()}
26
+ icon={<HorizontalRuleRounded />}
27
+ label="Horizontal line"
28
+ />
29
+ <VerticalDivider />
30
+ </>
31
+ );
32
+ };
33
+
34
+ export default HorizontalLineButton;
@@ -10,6 +10,7 @@ import {
10
10
  BulletListExtension,
11
11
  ListItemExtension,
12
12
  PlaceholderExtension,
13
+ HorizontalRuleExtension,
13
14
  } from 'remirror/extensions';
14
15
  import { Extension } from '@remirror/core';
15
16
  import { PreformattedExtension } from './PreformattedExtension/PreformattedExtension';
@@ -64,6 +65,7 @@ export const createExtensions = (context: EditorContextOptions, browserContext:
64
65
  new BulletListExtension(),
65
66
  new ListItemExtension(),
66
67
  new OrderedListExtension(),
68
+ new HorizontalRuleExtension(),
67
69
  new PlaceholderExtension(),
68
70
  new FetchUrlExtension({
69
71
  fetchUrl: browserContext.onRequestResource,
@@ -87,4 +87,9 @@
87
87
  ol {
88
88
  list-style-type: decimal;
89
89
  }
90
+
91
+ hr {
92
+ margin-block-start: 0.6rem;
93
+ margin-block-end: 0.6rem;
94
+ }
90
95
  }
@@ -170,6 +170,36 @@ describe('remirrorNodeToSquizNode', () => {
170
170
  expect(result).toEqual(expected);
171
171
  });
172
172
 
173
+ it('should handle horizontal lines', async () => {
174
+ const content: RemirrorJSON = {
175
+ type: 'doc',
176
+ content: [
177
+ {
178
+ type: 'horizontalRule',
179
+ attrs: {
180
+ nodeIndent: null,
181
+ nodeTextAlignment: null,
182
+ nodeLineHeight: null,
183
+ style: '',
184
+ },
185
+ },
186
+ ],
187
+ };
188
+
189
+ const { editor } = await renderWithEditor(null, { content });
190
+
191
+ const expected: FormattedText = [
192
+ {
193
+ type: 'tag',
194
+ tag: 'hr',
195
+ children: [],
196
+ },
197
+ ];
198
+
199
+ const result = remirrorNodeToSquizNode(editor.doc);
200
+ expect(result).toEqual(expected);
201
+ });
202
+
173
203
  it.each([1, 2, 3, 4, 5, 6])('should handle heading %s formatting', async (level) => {
174
204
  const content: RemirrorJSON = {
175
205
  type: 'doc',
@@ -616,4 +616,30 @@ describe('squizNodeToRemirrorNode', () => {
616
616
  const result = squizNodeToRemirrorNode(squizComponentJSON);
617
617
  expect(result).toEqual(expected);
618
618
  });
619
+
620
+ it('should handle horizontal lines', () => {
621
+ const squizComponentJSON: FormattedText = [
622
+ {
623
+ type: 'tag',
624
+ tag: 'hr',
625
+ children: [],
626
+ },
627
+ ];
628
+
629
+ const expected: RemirrorJSON = {
630
+ content: [
631
+ {
632
+ attrs: { level: NaN, nodeIndent: null, nodeLineHeight: null, nodeTextAlignment: null, style: '' },
633
+ type: 'horizontalRule',
634
+ marks: undefined,
635
+ text: undefined,
636
+ content: undefined,
637
+ },
638
+ ],
639
+ type: 'doc',
640
+ };
641
+
642
+ const result = squizNodeToRemirrorNode(squizComponentJSON);
643
+ expect(result).toEqual(expected);
644
+ });
619
645
  });
@@ -27,6 +27,7 @@ const getNodeType = (node: FormattedNodes): string => {
27
27
  ol: 'orderedList',
28
28
  li: 'listItem',
29
29
  ul: 'bulletList',
30
+ hr: 'horizontalRule',
30
31
  a: NodeName.Text,
31
32
  span: NodeName.Text,
32
33
  code: NodeName.CodeBlock,
@@ -25,6 +25,7 @@ describe('getNodeNamesByGroup', () => {
25
25
  'bulletList',
26
26
  'listItem',
27
27
  'orderedList',
28
+ 'horizontalRule',
28
29
  ]);
29
30
  });
30
31
  });