@squiz/formatted-text-editor 1.21.1-alpha.1 → 1.21.1-alpha.2
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/.eslintrc.json +7 -0
- package/lib/EditorToolbar/FloatingToolbar.js +1 -1
- package/lib/Extensions/LinkExtension/LinkExtension.js +6 -4
- package/lib/index.css +3 -3
- package/lib/ui/Modal/Modal.js +1 -1
- package/lib/ui/ToolbarDropdown/ToolbarDropdown.js +1 -1
- package/package.json +2 -2
- package/src/EditorToolbar/FloatingToolbar.tsx +1 -1
- package/src/EditorToolbar/_toolbar.scss +7 -7
- package/src/Extensions/LinkExtension/LinkExtension.ts +8 -5
- package/src/ui/Modal/Modal.tsx +1 -0
- package/src/ui/ToolbarDropdown/ToolbarDropdown.spec.tsx +4 -2
- package/src/ui/ToolbarDropdown/ToolbarDropdown.tsx +1 -1
package/.eslintrc.json
CHANGED
@@ -30,5 +30,12 @@
|
|
30
30
|
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
31
31
|
}
|
32
32
|
}
|
33
|
+
},
|
34
|
+
"rules": {
|
35
|
+
// The rules below are listed in the order they appear on the eslint-plugin-react rules page.
|
36
|
+
|
37
|
+
// React
|
38
|
+
// https://github.com/yannickcr/eslint-plugin-react#list-of-supported-rules
|
39
|
+
"react/button-has-type": "error"
|
33
40
|
}
|
34
41
|
}
|
@@ -54,7 +54,7 @@ const FloatingToolbar = () => {
|
|
54
54
|
}
|
55
55
|
else if (!data.marks?.link.isActive) {
|
56
56
|
// if none of the selected text is a link show the option to create a link.
|
57
|
-
buttons.push(react_1.default.createElement(react_components_1.VerticalDivider, { key: "link-divider", className: "
|
57
|
+
buttons.push(react_1.default.createElement(react_components_1.VerticalDivider, { key: "link-divider", className: "editor-divider" }), react_1.default.createElement(LinkButton_1.default, { key: "add-link", inPopover: true }));
|
58
58
|
}
|
59
59
|
return (react_1.default.createElement(react_2.FloatingToolbar, { className: "squiz-fte-scope squiz-fte-scope__floating-popover", positioner: positioner }, buttons));
|
60
60
|
};
|
@@ -75,18 +75,20 @@ class LinkExtension extends extensions_1.LinkExtension {
|
|
75
75
|
const selectedText = tr.doc.textBetween(range.from, range.to);
|
76
76
|
if (text !== selectedText) {
|
77
77
|
// update the text in the editor if it was updated, update the range to cover the length of the new text.
|
78
|
-
|
78
|
+
tr.insertText(text);
|
79
79
|
range.to = range.from + text.length;
|
80
80
|
}
|
81
81
|
// apply the link, or remove it if no URL was provided.
|
82
82
|
if (attrs.href.length > 0) {
|
83
|
-
(
|
83
|
+
tr.addMark(range.from, range.to, this.type.create(attrs));
|
84
84
|
}
|
85
85
|
else {
|
86
|
-
(
|
86
|
+
tr.removeMark(range.from, range.to, this.type);
|
87
87
|
}
|
88
88
|
// move the cursor to the end of the link and re-focus the editor.
|
89
|
-
|
89
|
+
tr.setSelection((0, core_1.getTextSelection)({ from: range.to, to: range.to }, tr.doc));
|
90
|
+
// apply the transaction.
|
91
|
+
dispatch?.(tr);
|
90
92
|
view?.focus();
|
91
93
|
return true;
|
92
94
|
};
|
package/lib/index.css
CHANGED
@@ -722,7 +722,7 @@
|
|
722
722
|
letter-spacing: -0.2px;
|
723
723
|
line-height: 1.25rem;
|
724
724
|
}
|
725
|
-
.squiz-fte-scope .
|
725
|
+
.squiz-fte-scope .editor-toolbar {
|
726
726
|
border-bottom-width: 2px;
|
727
727
|
border-style: solid;
|
728
728
|
--tw-border-opacity: 1;
|
@@ -733,10 +733,10 @@
|
|
733
733
|
display: flex;
|
734
734
|
justify-items: center;
|
735
735
|
}
|
736
|
-
.squiz-fte-scope .
|
736
|
+
.squiz-fte-scope .editor-toolbar > *:not(:first-child, .editor-divider) {
|
737
737
|
margin: 0 0 0 2px;
|
738
738
|
}
|
739
|
-
.squiz-fte-scope .
|
739
|
+
.squiz-fte-scope .editor-divider {
|
740
740
|
margin-top: -0.25rem;
|
741
741
|
margin-bottom: -0.25rem;
|
742
742
|
margin-left: 0.25rem;
|
package/lib/ui/Modal/Modal.js
CHANGED
@@ -65,7 +65,7 @@ const Modal = ({ children, title, onCancel, onSubmit, className }, ref) => {
|
|
65
65
|
react_1.default.createElement("div", { className: "squiz-fte-modal" },
|
66
66
|
react_1.default.createElement("div", { className: "squiz-fte-modal-header p-6 pb-2" },
|
67
67
|
react_1.default.createElement("h2", { className: "font-semibold text-gray-900 text-heading-2" }, title),
|
68
|
-
react_1.default.createElement("button", { className: "ml-auto -mr-3 -mt-3 bg-transparent border-0 text-gray-600 font-semibold outline-none focus:outline-none hover:text-color-gray-800", onClick: onCancel, "aria-label": "Close" },
|
68
|
+
react_1.default.createElement("button", { type: "button", className: "ml-auto -mr-3 -mt-3 bg-transparent border-0 text-gray-600 font-semibold outline-none focus:outline-none hover:text-color-gray-800", onClick: onCancel, "aria-label": "Close" },
|
69
69
|
react_1.default.createElement(CloseRounded_1.default, null))),
|
70
70
|
react_1.default.createElement("div", { className: "squiz-fte-modal-content" }, children),
|
71
71
|
react_1.default.createElement("div", { className: "squiz-fte-modal-footer p-6 pt-3" },
|
@@ -39,7 +39,7 @@ const ToolbarDropdown = ({ children, label }) => {
|
|
39
39
|
}
|
40
40
|
};
|
41
41
|
return (react_1.default.createElement("div", { className: "toolbar-dropdown", onBlur: handleBlur },
|
42
|
-
react_1.default.createElement("button", { id: "dropdownHoverButton", className: "toolbar-dropdown__button", onClick: handleDropDown },
|
42
|
+
react_1.default.createElement("button", { id: "dropdownHoverButton", className: "toolbar-dropdown__button", type: "button", onClick: handleDropDown },
|
43
43
|
react_1.default.createElement("span", { className: "toolbar-dropdown__label" }, label),
|
44
44
|
react_1.default.createElement(ExpandMore_1.default, { className: "toolbar-dropdown__icon", "aria-hidden": "true" })),
|
45
45
|
react_1.default.createElement("div", { id: "dropdown", className: `toolbar-dropdown__menu z-10 ${isOpen ? 'block' : 'hidden'} bg-white divide-y w-169` },
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/formatted-text-editor",
|
3
|
-
"version": "1.21.1-alpha.
|
3
|
+
"version": "1.21.1-alpha.2",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"scripts": {
|
@@ -67,5 +67,5 @@
|
|
67
67
|
"volta": {
|
68
68
|
"node": "16.19.0"
|
69
69
|
},
|
70
|
-
"gitHead": "
|
70
|
+
"gitHead": "094356f01a017174820505681d5dfc4a2ee9428b"
|
71
71
|
}
|
@@ -27,7 +27,7 @@ export const FloatingToolbar = () => {
|
|
27
27
|
} else if (!data.marks?.link.isActive) {
|
28
28
|
// if none of the selected text is a link show the option to create a link.
|
29
29
|
buttons.push(
|
30
|
-
<VerticalDivider key="link-divider" className="
|
30
|
+
<VerticalDivider key="link-divider" className="editor-divider" />,
|
31
31
|
<LinkButton key="add-link" inPopover={true} />,
|
32
32
|
);
|
33
33
|
}
|
@@ -1,16 +1,16 @@
|
|
1
|
-
.
|
1
|
+
.editor-toolbar {
|
2
2
|
@apply bg-white border-gray-200 border-b-2 border-solid p-1;
|
3
3
|
|
4
4
|
display: flex;
|
5
5
|
justify-items: center;
|
6
6
|
|
7
|
-
> *:not(:first-child) {
|
7
|
+
> *:not(:first-child, .editor-divider) {
|
8
8
|
margin: 0 0 0 2px;
|
9
9
|
}
|
10
|
+
}
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
}
|
12
|
+
.editor-divider {
|
13
|
+
@apply -my-1 mx-1 border;
|
14
|
+
margin-right: 2px;
|
15
|
+
height: auto;
|
16
16
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ApplySchemaAttributes, getMarkRanges, isElementDomNode, MarkExtensionSpec, MarkSpecOverride } from 'remirror';
|
2
|
-
import { getTextSelection, getMarkRange, KeyBindingProps
|
2
|
+
import { getTextSelection, getMarkRange, KeyBindingProps } from '@remirror/core';
|
3
3
|
import { CommandFunction } from '@remirror/pm';
|
4
4
|
import { LinkAttributes as RemirrorLinkAttributes, LinkExtension as RemirrorLinkExtension } from 'remirror/extensions';
|
5
5
|
|
@@ -95,19 +95,22 @@ export class LinkExtension extends RemirrorLinkExtension {
|
|
95
95
|
|
96
96
|
if (text !== selectedText) {
|
97
97
|
// update the text in the editor if it was updated, update the range to cover the length of the new text.
|
98
|
-
|
98
|
+
tr.insertText(text);
|
99
99
|
range.to = range.from + text.length;
|
100
100
|
}
|
101
101
|
|
102
102
|
// apply the link, or remove it if no URL was provided.
|
103
103
|
if (attrs.href.length > 0) {
|
104
|
-
|
104
|
+
tr.addMark(range.from, range.to, this.type.create(attrs));
|
105
105
|
} else {
|
106
|
-
removeMark(
|
106
|
+
tr.removeMark(range.from, range.to, this.type);
|
107
107
|
}
|
108
108
|
|
109
109
|
// move the cursor to the end of the link and re-focus the editor.
|
110
|
-
|
110
|
+
tr.setSelection(getTextSelection({ from: range.to, to: range.to }, tr.doc));
|
111
|
+
|
112
|
+
// apply the transaction.
|
113
|
+
dispatch?.(tr);
|
111
114
|
view?.focus();
|
112
115
|
|
113
116
|
return true;
|
package/src/ui/Modal/Modal.tsx
CHANGED
@@ -56,6 +56,7 @@ const Modal = (
|
|
56
56
|
<div className="squiz-fte-modal-header p-6 pb-2">
|
57
57
|
<h2 className="font-semibold text-gray-900 text-heading-2">{title}</h2>
|
58
58
|
<button
|
59
|
+
type="button"
|
59
60
|
className="ml-auto -mr-3 -mt-3 bg-transparent border-0 text-gray-600 font-semibold outline-none focus:outline-none hover:text-color-gray-800"
|
60
61
|
onClick={onCancel}
|
61
62
|
aria-label="Close"
|
@@ -2,13 +2,14 @@ import '@testing-library/jest-dom';
|
|
2
2
|
import { fireEvent, render, screen } from '@testing-library/react';
|
3
3
|
import React from 'react';
|
4
4
|
import ToolbarDropdown from './ToolbarDropdown';
|
5
|
+
import ToolbarDropdownButton from '../ToolbarDropdownButton/ToolbarDropdownButton';
|
5
6
|
|
6
7
|
describe('Toolbar dropdown', () => {
|
7
8
|
const ToolbarDropdownComponent = () => {
|
8
9
|
return (
|
9
10
|
<ToolbarDropdown label="Test dropdown">
|
10
|
-
<
|
11
|
-
<
|
11
|
+
<ToolbarDropdownButton label="Test button" isDisabled={false} isActive={false} handleOnClick={jest.fn()} />
|
12
|
+
<ToolbarDropdownButton label="Test button 2" isDisabled={false} isActive={false} handleOnClick={jest.fn()} />
|
12
13
|
</ToolbarDropdown>
|
13
14
|
);
|
14
15
|
};
|
@@ -17,6 +18,7 @@ describe('Toolbar dropdown', () => {
|
|
17
18
|
render(<ToolbarDropdownComponent />);
|
18
19
|
// Check that the supplied label renders
|
19
20
|
const dropdownButton = screen.getByRole('button', { name: 'Test dropdown' });
|
21
|
+
expect(dropdownButton).toHaveAttribute('type', 'button');
|
20
22
|
expect(dropdownButton).toBeInTheDocument();
|
21
23
|
});
|
22
24
|
|
@@ -21,7 +21,7 @@ const ToolbarDropdown = ({ children, label }: ToolbarDropdownProps) => {
|
|
21
21
|
|
22
22
|
return (
|
23
23
|
<div className="toolbar-dropdown" onBlur={handleBlur}>
|
24
|
-
<button id="dropdownHoverButton" className="toolbar-dropdown__button" onClick={handleDropDown}>
|
24
|
+
<button id="dropdownHoverButton" className="toolbar-dropdown__button" type="button" onClick={handleDropDown}>
|
25
25
|
<span className="toolbar-dropdown__label">{label}</span>
|
26
26
|
<ExpandMoreIcon className="toolbar-dropdown__icon" aria-hidden="true" />
|
27
27
|
</button>
|