@squiz/formatted-text-editor 1.66.0 → 1.66.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/CHANGELOG.md +12 -0
- package/lib/Editor/Editor.js +1 -1
- package/lib/hooks/useFocus.js +3 -1
- package/lib/utils/createToolbarPositioner.js +10 -1
- package/package.json +2 -2
- package/src/Editor/Editor.tsx +1 -1
- package/src/hooks/useFocus.ts +4 -1
- package/src/utils/createToolbarPositioner.ts +12 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.66.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 629a64f: Fixed FTE bubble menu from staying visible when unfocusing from editor
|
8
|
+
|
9
|
+
## 1.66.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- e01fd51: Fixed FTE floating toolbar overlap
|
14
|
+
|
3
15
|
## 1.66.0
|
4
16
|
|
5
17
|
### Minor Changes
|
package/lib/Editor/Editor.js
CHANGED
@@ -70,6 +70,6 @@ const Editor = ({ content, className, border = true, editable = true, onChange,
|
|
70
70
|
editable && react_1.default.createElement(EditorToolbar_1.Toolbar, { isVisible: isVisible }),
|
71
71
|
children && react_1.default.createElement("div", { className: "squiz-fte-scope__editor__children" }, children),
|
72
72
|
react_1.default.createElement(WrappedEditor, null),
|
73
|
-
editable && react_1.default.createElement(EditorToolbar_1.FloatingToolbar, null))));
|
73
|
+
editable && isVisible && react_1.default.createElement(EditorToolbar_1.FloatingToolbar, null))));
|
74
74
|
};
|
75
75
|
exports.default = Editor;
|
package/lib/hooks/useFocus.js
CHANGED
@@ -32,7 +32,9 @@ const useFocus = (initialState) => {
|
|
32
32
|
// (and therefore still in our React tree resulting in the element still effectively being focused).
|
33
33
|
const isBlurringEditor = wrapperRef.current?.contains(event.target);
|
34
34
|
const isFocusedInEditor = wrapperRef.current?.contains(event.relatedTarget);
|
35
|
-
if
|
35
|
+
// Detect if the blur event happens when the related/clicked target is the floating popover
|
36
|
+
const isClickingFloatingToolbar = !!event.relatedTarget?.closest('.squiz-fte-scope__floating-popover');
|
37
|
+
if (isBlurringEditor && !isFocusedInEditor && !isClickingFloatingToolbar) {
|
36
38
|
setIsVisible(false);
|
37
39
|
}
|
38
40
|
}, [wrapperRef]);
|
@@ -74,11 +74,20 @@ const createToolbarPositioner = ({ types }) => {
|
|
74
74
|
const leftmost = Math.min(from.left, to.left);
|
75
75
|
// The position nearest the top.
|
76
76
|
const topmost = Math.min(from.top, to.top);
|
77
|
+
const bottommost = Math.max(from.bottom, to.bottom);
|
77
78
|
const left = parent.scrollLeft + (spansMultipleLines ? to.left - parentRect.left : leftmost - parentRect.left);
|
78
79
|
const top = parent.scrollTop + topmost - parentRect.top;
|
79
80
|
const width = spansMultipleLines ? 1 : Math.abs(from.left - to.right);
|
80
81
|
const rect = new DOMRect(spansMultipleLines ? to.left : leftmost, topmost, width, height);
|
81
|
-
|
82
|
+
// Get header toolbar by class inside the current element/editor
|
83
|
+
const headerToolbar = element.parentElement?.getElementsByClassName('header-toolbar')?.[0];
|
84
|
+
const headerBarRects = headerToolbar?.getBoundingClientRect();
|
85
|
+
const headerBarHeight = headerBarRects?.height ?? 0;
|
86
|
+
const headerBarBottom = (headerBarRects?.top ?? 0) + headerBarHeight;
|
87
|
+
// If floating toolbar will overlap fixed toolbar, set position to under selection
|
88
|
+
const isOverlapping = headerBarBottom + headerBarHeight > topmost;
|
89
|
+
const y = isOverlapping ? bottommost + 62 : top; // FIXME: need to calculate rather than hard-code
|
90
|
+
return { rect, y, x: left, height, width, visible };
|
82
91
|
},
|
83
92
|
});
|
84
93
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/formatted-text-editor",
|
3
|
-
"version": "1.66.
|
3
|
+
"version": "1.66.2",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"private": false,
|
@@ -35,7 +35,7 @@
|
|
35
35
|
"@testing-library/jest-dom": "5.16.5",
|
36
36
|
"@testing-library/react": "14.0.0",
|
37
37
|
"@testing-library/user-event": "14.4.3",
|
38
|
-
"@types/node": "
|
38
|
+
"@types/node": "20.11.24",
|
39
39
|
"@types/react": "^18.2.45",
|
40
40
|
"@types/react-dom": "^18.2.18",
|
41
41
|
"@vitejs/plugin-react": "3.0.0",
|
package/src/Editor/Editor.tsx
CHANGED
@@ -93,7 +93,7 @@ const Editor = ({
|
|
93
93
|
{editable && <Toolbar isVisible={isVisible} />}
|
94
94
|
{children && <div className="squiz-fte-scope__editor__children">{children}</div>}
|
95
95
|
<WrappedEditor />
|
96
|
-
{editable && <FloatingToolbar />}
|
96
|
+
{editable && isVisible && <FloatingToolbar />}
|
97
97
|
</Remirror>
|
98
98
|
</div>
|
99
99
|
);
|
package/src/hooks/useFocus.ts
CHANGED
@@ -45,7 +45,10 @@ const useFocus = (
|
|
45
45
|
const isBlurringEditor = wrapperRef.current?.contains(event.target);
|
46
46
|
const isFocusedInEditor = wrapperRef.current?.contains(event.relatedTarget);
|
47
47
|
|
48
|
-
if
|
48
|
+
// Detect if the blur event happens when the related/clicked target is the floating popover
|
49
|
+
const isClickingFloatingToolbar = !!event.relatedTarget?.closest('.squiz-fte-scope__floating-popover');
|
50
|
+
|
51
|
+
if (isBlurringEditor && !isFocusedInEditor && !isClickingFloatingToolbar) {
|
49
52
|
setIsVisible(false);
|
50
53
|
}
|
51
54
|
},
|
@@ -103,13 +103,24 @@ export const createToolbarPositioner = ({ types }: ToolbarPositionerProps) => {
|
|
103
103
|
|
104
104
|
// The position nearest the top.
|
105
105
|
const topmost = Math.min(from.top, to.top);
|
106
|
+
const bottommost = Math.max(from.bottom, to.bottom);
|
106
107
|
|
107
108
|
const left = parent.scrollLeft + (spansMultipleLines ? to.left - parentRect.left : leftmost - parentRect.left);
|
108
109
|
const top = parent.scrollTop + topmost - parentRect.top;
|
109
110
|
const width = spansMultipleLines ? 1 : Math.abs(from.left - to.right);
|
110
111
|
const rect = new DOMRect(spansMultipleLines ? to.left : leftmost, topmost, width, height);
|
111
112
|
|
112
|
-
|
113
|
+
// Get header toolbar by class inside the current element/editor
|
114
|
+
const headerToolbar = element.parentElement?.getElementsByClassName('header-toolbar')?.[0];
|
115
|
+
const headerBarRects = headerToolbar?.getBoundingClientRect();
|
116
|
+
const headerBarHeight = headerBarRects?.height ?? 0;
|
117
|
+
const headerBarBottom = (headerBarRects?.top ?? 0) + headerBarHeight;
|
118
|
+
|
119
|
+
// If floating toolbar will overlap fixed toolbar, set position to under selection
|
120
|
+
const isOverlapping = headerBarBottom + headerBarHeight > topmost;
|
121
|
+
const y = isOverlapping ? bottommost + 62 : top; // FIXME: need to calculate rather than hard-code
|
122
|
+
|
123
|
+
return { rect, y, x: left, height, width, visible };
|
113
124
|
},
|
114
125
|
});
|
115
126
|
};
|