@squiz/formatted-text-editor 1.40.1-alpha.10 → 1.40.1-alpha.12
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/lib/EditorToolbar/Toolbar.js +2 -3
- package/lib/EditorToolbar/Tools/Lists/ListButtons.d.ts +2 -0
- package/lib/EditorToolbar/Tools/Lists/ListButtons.js +14 -0
- package/lib/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.d.ts +2 -0
- package/lib/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.js +22 -0
- package/lib/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedListButton.js +1 -1
- package/lib/Extensions/Extensions.js +1 -0
- package/lib/index.css +8 -0
- package/lib/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.js +2 -1
- package/package.json +4 -4
- package/src/EditorToolbar/Toolbar.tsx +2 -3
- package/src/EditorToolbar/Tools/Lists/ListButtons.tsx +14 -0
- package/src/EditorToolbar/Tools/Lists/OrderedList/OrderListButton.spec.tsx +39 -0
- package/src/EditorToolbar/Tools/Lists/OrderedList/OrderedListButton.tsx +30 -0
- package/src/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedList.spec.tsx +1 -1
- package/src/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedListButton.tsx +1 -1
- package/src/Extensions/Extensions.ts +2 -0
- package/src/ui/_typography.scss +9 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.spec.ts +73 -0
- package/src/utils/converters/squizNodeToRemirrorNode/squizNodeToRemirrorNode.ts +2 -1
- package/src/utils/getNodeNamesByGroup.spec.ts +1 -0
- /package/lib/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedListButton.d.ts +0 -0
@@ -9,7 +9,6 @@ const react_components_1 = require("@remirror/react-components");
|
|
9
9
|
const clsx_1 = __importDefault(require("clsx"));
|
10
10
|
const ItalicButton_1 = __importDefault(require("./Tools/Italic/ItalicButton"));
|
11
11
|
const UnderlineButton_1 = __importDefault(require("./Tools/Underline/UnderlineButton"));
|
12
|
-
const UnorderedListButton_1 = __importDefault(require("./Tools/UnorderedList/UnorderedListButton"));
|
13
12
|
const BoldButton_1 = __importDefault(require("./Tools/Bold/BoldButton"));
|
14
13
|
const TextAlignButtons_1 = __importDefault(require("./Tools/TextAlign/TextAlignButtons"));
|
15
14
|
const UndoButton_1 = __importDefault(require("./Tools/Undo/UndoButton"));
|
@@ -19,6 +18,7 @@ const LinkButton_1 = __importDefault(require("./Tools/Link/LinkButton"));
|
|
19
18
|
const ImageButton_1 = __importDefault(require("./Tools/Image/ImageButton"));
|
20
19
|
const RemoveLinkButton_1 = __importDefault(require("./Tools/Link/RemoveLinkButton"));
|
21
20
|
const ClearFormattingButton_1 = __importDefault(require("./Tools/ClearFormatting/ClearFormattingButton"));
|
21
|
+
const ListButtons_1 = __importDefault(require("./Tools/Lists/ListButtons"));
|
22
22
|
const hooks_1 = require("../hooks");
|
23
23
|
const Toolbar = ({ isVisible }) => {
|
24
24
|
const extensionNames = (0, hooks_1.useExtensionNames)();
|
@@ -32,9 +32,8 @@ const Toolbar = ({ isVisible }) => {
|
|
32
32
|
extensionNames.italic && react_1.default.createElement(ItalicButton_1.default, null),
|
33
33
|
extensionNames.underline && react_1.default.createElement(UnderlineButton_1.default, null),
|
34
34
|
extensionNames.nodeFormatting && react_1.default.createElement(TextAlignButtons_1.default, null),
|
35
|
-
extensionNames.
|
35
|
+
extensionNames.listItem && react_1.default.createElement(ListButtons_1.default, null),
|
36
36
|
extensionNames.link && (react_1.default.createElement(react_1.default.Fragment, null,
|
37
|
-
react_1.default.createElement(react_components_1.VerticalDivider, null),
|
38
37
|
react_1.default.createElement(LinkButton_1.default, null),
|
39
38
|
react_1.default.createElement(RemoveLinkButton_1.default, null))),
|
40
39
|
extensionNames.image && react_1.default.createElement(ImageButton_1.default, null),
|
@@ -0,0 +1,14 @@
|
|
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 OrderedListButton_1 = __importDefault(require("./OrderedList/OrderedListButton"));
|
8
|
+
const UnorderedListButton_1 = __importDefault(require("./UnorderedList/UnorderedListButton"));
|
9
|
+
const react_components_1 = require("@remirror/react-components");
|
10
|
+
const ListButtons = () => (react_1.default.createElement(react_1.default.Fragment, null,
|
11
|
+
react_1.default.createElement(UnorderedListButton_1.default, null),
|
12
|
+
react_1.default.createElement(OrderedListButton_1.default, null),
|
13
|
+
react_1.default.createElement(react_components_1.VerticalDivider, null)));
|
14
|
+
exports.default = ListButtons;
|
@@ -0,0 +1,22 @@
|
|
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 Button_1 = __importDefault(require("../../../../ui/Button/Button"));
|
9
|
+
const FormatListNumbered_1 = __importDefault(require("@mui/icons-material/FormatListNumbered"));
|
10
|
+
const OrderedListButton = () => {
|
11
|
+
const { toggleOrderedList } = (0, react_2.useCommands)();
|
12
|
+
const chain = (0, react_2.useChainedCommands)();
|
13
|
+
const active = (0, react_2.useActive)();
|
14
|
+
const enabled = toggleOrderedList.enabled();
|
15
|
+
const handleSelect = () => {
|
16
|
+
if (toggleOrderedList.enabled()) {
|
17
|
+
chain.toggleOrderedList().focus().run();
|
18
|
+
}
|
19
|
+
};
|
20
|
+
return (react_1.default.createElement(Button_1.default, { handleOnClick: handleSelect, isDisabled: !enabled, isActive: active.orderedList(), icon: react_1.default.createElement(FormatListNumbered_1.default, null), label: "Ordered list" }));
|
21
|
+
};
|
22
|
+
exports.default = OrderedListButton;
|
package/lib/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedListButton.js
RENAMED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const react_1 = __importDefault(require("react"));
|
7
7
|
const react_2 = require("@remirror/react");
|
8
|
-
const Button_1 = __importDefault(require("
|
8
|
+
const Button_1 = __importDefault(require("../../../../ui/Button/Button"));
|
9
9
|
const FormatListBulletedRounded_1 = __importDefault(require("@mui/icons-material/FormatListBulletedRounded"));
|
10
10
|
const UnorderedListButton = () => {
|
11
11
|
const { toggleBulletList } = (0, react_2.useCommands)();
|
package/lib/index.css
CHANGED
@@ -643,6 +643,10 @@
|
|
643
643
|
color: rgb(7 116 210 / var(--tw-text-opacity));
|
644
644
|
text-decoration: underline;
|
645
645
|
}
|
646
|
+
.squiz-fte-scope .remirror-editor p {
|
647
|
+
-webkit-margin-after: 0.8rem;
|
648
|
+
margin-block-end: 0.8rem;
|
649
|
+
}
|
646
650
|
.squiz-fte-scope .remirror-editor h1 {
|
647
651
|
font-size: 1.625rem;
|
648
652
|
font-weight: 600;
|
@@ -714,6 +718,10 @@
|
|
714
718
|
padding: 0 0 0 2.5rem;
|
715
719
|
margin: 1rem 0;
|
716
720
|
}
|
721
|
+
.squiz-fte-scope .remirror-editor ol {
|
722
|
+
list-style-type: decimal;
|
723
|
+
padding: 0 0 0 1rem;
|
724
|
+
}
|
717
725
|
.squiz-fte-scope .squiz-fte-form-group {
|
718
726
|
display: flex;
|
719
727
|
flex-direction: column;
|
@@ -19,8 +19,9 @@ const getNodeType = (node) => {
|
|
19
19
|
img: 'image',
|
20
20
|
pre: 'preformatted',
|
21
21
|
p: 'paragraph',
|
22
|
-
|
22
|
+
ol: 'orderedList',
|
23
23
|
li: 'listItem',
|
24
|
+
ul: 'bulletList',
|
24
25
|
a: Extensions_1.NodeName.Text,
|
25
26
|
span: Extensions_1.NodeName.Text,
|
26
27
|
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.40.1-alpha.
|
3
|
+
"version": "1.40.1-alpha.12",
|
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.40.1-alpha.
|
24
|
-
"@squiz/resource-browser": "1.40.1-alpha.
|
23
|
+
"@squiz/dx-json-schema-lib": "1.40.1-alpha.12",
|
24
|
+
"@squiz/resource-browser": "1.40.1-alpha.12",
|
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": "
|
78
|
+
"gitHead": "f1b879c8a9a73e15ee53819c41d2fd3c6ccf2b3e"
|
79
79
|
}
|
@@ -3,7 +3,6 @@ import { Toolbar as RemirrorToolbar, VerticalDivider } from '@remirror/react-com
|
|
3
3
|
import clsx from 'clsx';
|
4
4
|
import ItalicButton from './Tools/Italic/ItalicButton';
|
5
5
|
import UnderlineButton from './Tools/Underline/UnderlineButton';
|
6
|
-
import UnorderedListButton from './Tools/UnorderedList/UnorderedListButton';
|
7
6
|
import BoldButton from './Tools/Bold/BoldButton';
|
8
7
|
import TextAlignButtons from './Tools/TextAlign/TextAlignButtons';
|
9
8
|
import UndoButton from './Tools/Undo/UndoButton';
|
@@ -13,6 +12,7 @@ import LinkButton from './Tools/Link/LinkButton';
|
|
13
12
|
import ImageButton from './Tools/Image/ImageButton';
|
14
13
|
import RemoveLinkButton from './Tools/Link/RemoveLinkButton';
|
15
14
|
import ClearFormattingButton from './Tools/ClearFormatting/ClearFormattingButton';
|
15
|
+
import ListButtons from './Tools/Lists/ListButtons';
|
16
16
|
import { useExtensionNames } from '../hooks';
|
17
17
|
|
18
18
|
type ToolbarProps = {
|
@@ -39,10 +39,9 @@ export const Toolbar = ({ isVisible }: ToolbarProps) => {
|
|
39
39
|
{extensionNames.italic && <ItalicButton />}
|
40
40
|
{extensionNames.underline && <UnderlineButton />}
|
41
41
|
{extensionNames.nodeFormatting && <TextAlignButtons />}
|
42
|
-
{extensionNames.
|
42
|
+
{extensionNames.listItem && <ListButtons />}
|
43
43
|
{extensionNames.link && (
|
44
44
|
<>
|
45
|
-
<VerticalDivider />
|
46
45
|
<LinkButton />
|
47
46
|
<RemoveLinkButton />
|
48
47
|
</>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import OrderedListButton from './OrderedList/OrderedListButton';
|
3
|
+
import UnorderedListButton from './UnorderedList/UnorderedListButton';
|
4
|
+
import { VerticalDivider } from '@remirror/react-components';
|
5
|
+
|
6
|
+
const ListButtons = () => (
|
7
|
+
<>
|
8
|
+
<UnorderedListButton />
|
9
|
+
<OrderedListButton />
|
10
|
+
<VerticalDivider />
|
11
|
+
</>
|
12
|
+
);
|
13
|
+
|
14
|
+
export default ListButtons;
|
@@ -0,0 +1,39 @@
|
|
1
|
+
import '@testing-library/jest-dom';
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
3
|
+
import Editor from '../../../../Editor/Editor';
|
4
|
+
import React from 'react';
|
5
|
+
|
6
|
+
describe('Ordered list button', () => {
|
7
|
+
it('Renders the ordered list button', () => {
|
8
|
+
const { baseElement, getByRole } = render(<Editor />);
|
9
|
+
expect(baseElement).toBeTruthy();
|
10
|
+
expect(getByRole('button', { name: 'Ordered list' })).toBeTruthy();
|
11
|
+
});
|
12
|
+
|
13
|
+
it('Applies ordered list after selecting ordered list button', () => {
|
14
|
+
const { baseElement, getByRole } = render(<Editor />);
|
15
|
+
expect(baseElement).toBeTruthy();
|
16
|
+
|
17
|
+
const OrderedListButton = getByRole('button', { name: 'Ordered list' });
|
18
|
+
expect(OrderedListButton).toBeTruthy();
|
19
|
+
expect(OrderedListButton.classList.contains('is-active')).toBeFalsy();
|
20
|
+
|
21
|
+
fireEvent.click(OrderedListButton);
|
22
|
+
|
23
|
+
setTimeout(() => {
|
24
|
+
expect(OrderedListButton.classList.contains('is-active')).toBeTruthy();
|
25
|
+
}, 50);
|
26
|
+
});
|
27
|
+
|
28
|
+
it('Should apply order list to editor after clicking button', () => {
|
29
|
+
const { baseElement, getByRole } = render(<Editor />);
|
30
|
+
expect(baseElement).toBeTruthy();
|
31
|
+
expect(baseElement.querySelector('ol')).toBeFalsy();
|
32
|
+
|
33
|
+
const OrderedListButton = getByRole('button', { name: 'Ordered list' });
|
34
|
+
expect(OrderedListButton).toBeTruthy();
|
35
|
+
fireEvent.click(OrderedListButton);
|
36
|
+
|
37
|
+
expect(baseElement.querySelector('ol')).toBeTruthy();
|
38
|
+
});
|
39
|
+
});
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { useCommands, useActive, useChainedCommands } from '@remirror/react';
|
3
|
+
import { OrderedListExtension } from '@remirror/extension-list';
|
4
|
+
import Button from '../../../../ui/Button/Button';
|
5
|
+
import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered';
|
6
|
+
|
7
|
+
const OrderedListButton = () => {
|
8
|
+
const { toggleOrderedList } = useCommands();
|
9
|
+
const chain = useChainedCommands();
|
10
|
+
|
11
|
+
const active = useActive<OrderedListExtension>();
|
12
|
+
const enabled = toggleOrderedList.enabled();
|
13
|
+
const handleSelect = () => {
|
14
|
+
if (toggleOrderedList.enabled()) {
|
15
|
+
chain.toggleOrderedList().focus().run();
|
16
|
+
}
|
17
|
+
};
|
18
|
+
|
19
|
+
return (
|
20
|
+
<Button
|
21
|
+
handleOnClick={handleSelect}
|
22
|
+
isDisabled={!enabled}
|
23
|
+
isActive={active.orderedList()}
|
24
|
+
icon={<FormatListNumberedIcon />}
|
25
|
+
label="Ordered list"
|
26
|
+
/>
|
27
|
+
);
|
28
|
+
};
|
29
|
+
|
30
|
+
export default OrderedListButton;
|
package/src/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedList.spec.tsx
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import '@testing-library/jest-dom';
|
3
3
|
import { render, screen, fireEvent } from '@testing-library/react';
|
4
|
-
import Editor from '
|
4
|
+
import Editor from '../../../../Editor/Editor';
|
5
5
|
|
6
6
|
describe('Unordered list button', () => {
|
7
7
|
it('Renders the unordered list button', () => {
|
package/src/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedListButton.tsx
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { useCommands, useActive, useChainedCommands } from '@remirror/react';
|
3
3
|
import { BulletListExtension } from 'remirror/extensions';
|
4
|
-
import Button from '
|
4
|
+
import Button from '../../../../ui/Button/Button';
|
5
5
|
import FormatListBulletedRoundedIcon from '@mui/icons-material/FormatListBulletedRounded';
|
6
6
|
|
7
7
|
const UnorderedListButton = () => {
|
@@ -6,6 +6,7 @@ import {
|
|
6
6
|
ParagraphExtension,
|
7
7
|
UnderlineExtension,
|
8
8
|
HistoryExtension,
|
9
|
+
OrderedListExtension,
|
9
10
|
BulletListExtension,
|
10
11
|
ListItemExtension,
|
11
12
|
} from 'remirror/extensions';
|
@@ -60,6 +61,7 @@ export const createExtensions = (context: EditorContextOptions) => {
|
|
60
61
|
new ClearFormattingExtension(),
|
61
62
|
new BulletListExtension(),
|
62
63
|
new ListItemExtension(),
|
64
|
+
new OrderedListExtension(),
|
63
65
|
];
|
64
66
|
};
|
65
67
|
};
|
package/src/ui/_typography.scss
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
text-decoration: underline;
|
6
6
|
}
|
7
7
|
|
8
|
+
p {
|
9
|
+
margin-block-end: 0.8rem;
|
10
|
+
}
|
11
|
+
|
8
12
|
h1 {
|
9
13
|
font-size: 1.625rem;
|
10
14
|
font-weight: 600;
|
@@ -78,4 +82,9 @@
|
|
78
82
|
padding: 0 0 0 2.5rem;
|
79
83
|
margin: 1rem 0;
|
80
84
|
}
|
85
|
+
|
86
|
+
ol {
|
87
|
+
list-style-type: decimal;
|
88
|
+
padding: 0 0 0 1rem;
|
89
|
+
}
|
81
90
|
}
|
@@ -426,6 +426,79 @@ describe('squizNodeToRemirrorNode', () => {
|
|
426
426
|
},
|
427
427
|
);
|
428
428
|
|
429
|
+
it('should handle ordered lists', () => {
|
430
|
+
const squizComponentJSON: FormattedText = [
|
431
|
+
{
|
432
|
+
type: 'tag',
|
433
|
+
tag: 'ol',
|
434
|
+
children: [
|
435
|
+
{
|
436
|
+
type: 'tag',
|
437
|
+
tag: 'li',
|
438
|
+
children: [
|
439
|
+
{
|
440
|
+
type: 'tag',
|
441
|
+
tag: 'p',
|
442
|
+
children: [
|
443
|
+
{
|
444
|
+
type: 'text',
|
445
|
+
value: 'ddd',
|
446
|
+
},
|
447
|
+
],
|
448
|
+
},
|
449
|
+
],
|
450
|
+
},
|
451
|
+
],
|
452
|
+
},
|
453
|
+
];
|
454
|
+
|
455
|
+
const expected: RemirrorJSON = {
|
456
|
+
content: [
|
457
|
+
{
|
458
|
+
attrs: { level: undefined, nodeIndent: null, nodeLineHeight: null, nodeTextAlignment: null, style: '' },
|
459
|
+
type: 'orderedList',
|
460
|
+
marks: undefined,
|
461
|
+
text: undefined,
|
462
|
+
content: [
|
463
|
+
{
|
464
|
+
attrs: { level: undefined, nodeIndent: null, nodeLineHeight: null, nodeTextAlignment: null, style: '' },
|
465
|
+
type: 'listItem',
|
466
|
+
marks: undefined,
|
467
|
+
text: undefined,
|
468
|
+
content: [
|
469
|
+
{
|
470
|
+
attrs: {
|
471
|
+
level: undefined,
|
472
|
+
nodeIndent: null,
|
473
|
+
nodeLineHeight: null,
|
474
|
+
nodeTextAlignment: null,
|
475
|
+
style: '',
|
476
|
+
},
|
477
|
+
marks: undefined,
|
478
|
+
text: undefined,
|
479
|
+
type: 'paragraph',
|
480
|
+
content: [
|
481
|
+
{
|
482
|
+
attrs: undefined,
|
483
|
+
content: undefined,
|
484
|
+
marks: undefined,
|
485
|
+
text: 'ddd',
|
486
|
+
type: 'text',
|
487
|
+
},
|
488
|
+
],
|
489
|
+
},
|
490
|
+
],
|
491
|
+
},
|
492
|
+
],
|
493
|
+
},
|
494
|
+
],
|
495
|
+
type: 'doc',
|
496
|
+
};
|
497
|
+
|
498
|
+
const result = squizNodeToRemirrorNode(squizComponentJSON);
|
499
|
+
expect(result).toEqual(expected);
|
500
|
+
});
|
501
|
+
|
429
502
|
it('should handle unordered lists', () => {
|
430
503
|
const squizComponentJSON: FormattedText = [
|
431
504
|
{
|
@@ -24,8 +24,9 @@ const getNodeType = (node: FormattedNodes): string => {
|
|
24
24
|
img: 'image',
|
25
25
|
pre: 'preformatted',
|
26
26
|
p: 'paragraph',
|
27
|
-
|
27
|
+
ol: 'orderedList',
|
28
28
|
li: 'listItem',
|
29
|
+
ul: 'bulletList',
|
29
30
|
a: NodeName.Text,
|
30
31
|
span: NodeName.Text,
|
31
32
|
code: NodeName.CodeBlock,
|
/package/lib/EditorToolbar/Tools/{UnorderedList → Lists/UnorderedList}/UnorderedListButton.d.ts
RENAMED
File without changes
|