@squiz/formatted-text-editor 1.49.1-alpha.5 → 1.49.1-alpha.7

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.
@@ -1,6 +1,6 @@
1
- import { FocusEventHandler, RefObject } from 'react';
1
+ import { FocusEvent, FocusEventHandler, RefObject } from 'react';
2
2
  declare const useFocus: (initialState: boolean) => {
3
- handleFocus: () => void;
3
+ handleFocus: (event: FocusEvent) => void;
4
4
  handleBlur: FocusEventHandler<HTMLDivElement>;
5
5
  isVisible: boolean;
6
6
  wrapperRef: RefObject<HTMLDivElement>;
@@ -4,8 +4,13 @@ const react_1 = require("react");
4
4
  const useFocus = (initialState) => {
5
5
  const wrapperRef = (0, react_1.createRef)();
6
6
  const [isVisible, setIsVisible] = (0, react_1.useState)(initialState);
7
- const handleFocus = (0, react_1.useCallback)(() => {
8
- setIsVisible(true);
7
+ const handleFocus = (0, react_1.useCallback)((event) => {
8
+ // Ignore elements flagged to be ignored, this allows us to add extra, clickable, elements
9
+ // without triggering a focus, such as action menus.
10
+ if (!event.target?.classList?.contains('fte-ignore') &&
11
+ !event.target?.parentElement?.classList?.contains('fte-ignore')) {
12
+ setIsVisible(true);
13
+ }
9
14
  }, [wrapperRef]);
10
15
  const handleBlur = (0, react_1.useCallback)((event) => {
11
16
  // React event bubbling is interesting, it bubbles up the React tree rather than the DOM tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/formatted-text-editor",
3
- "version": "1.49.1-alpha.5",
3
+ "version": "1.49.1-alpha.7",
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.49.1-alpha.5",
24
- "@squiz/resource-browser": "1.49.1-alpha.5",
23
+ "@squiz/dx-json-schema-lib": "1.49.1-alpha.7",
24
+ "@squiz/resource-browser": "1.49.1-alpha.7",
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": "9814f923e3c7bdd1098e403a150d33c6a34db1b3"
78
+ "gitHead": "55080e70b7105892e90c002a21c0c283c240d5af"
79
79
  }
@@ -3,7 +3,7 @@ import { useState, useCallback, FocusEvent, FocusEventHandler, RefObject, create
3
3
  const useFocus = (
4
4
  initialState: boolean,
5
5
  ): {
6
- handleFocus: () => void;
6
+ handleFocus: (event: FocusEvent) => void;
7
7
  handleBlur: FocusEventHandler<HTMLDivElement>;
8
8
  isVisible: boolean;
9
9
  wrapperRef: RefObject<HTMLDivElement>;
@@ -11,9 +11,19 @@ const useFocus = (
11
11
  const wrapperRef = createRef<HTMLDivElement>();
12
12
  const [isVisible, setIsVisible] = useState(initialState);
13
13
 
14
- const handleFocus = useCallback(() => {
15
- setIsVisible(true);
16
- }, [wrapperRef]);
14
+ const handleFocus = useCallback(
15
+ (event: FocusEvent) => {
16
+ // Ignore elements flagged to be ignored, this allows us to add extra, clickable, elements
17
+ // without triggering a focus, such as action menus.
18
+ if (
19
+ !event.target?.classList?.contains('fte-ignore') &&
20
+ !event.target?.parentElement?.classList?.contains('fte-ignore')
21
+ ) {
22
+ setIsVisible(true);
23
+ }
24
+ },
25
+ [wrapperRef],
26
+ );
17
27
 
18
28
  const handleBlur = useCallback(
19
29
  (event: FocusEvent<HTMLDivElement>) => {