@contentful/field-editor-rich-text 3.18.0 → 3.18.1
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/dist/cjs/internal/hooks.js +0 -6
- package/dist/cjs/plugins/Hyperlink/components/EntityHyperlink.js +3 -2
- package/dist/cjs/plugins/Hyperlink/components/LinkPopover.js +1 -3
- package/dist/cjs/plugins/Hyperlink/components/ResourceHyperlink.js +3 -2
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +3 -2
- package/dist/cjs/plugins/Hyperlink/components/useHyperlinkCommon.js +22 -1
- package/dist/esm/internal/hooks.js +0 -3
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +3 -2
- package/dist/esm/plugins/Hyperlink/components/LinkPopover.js +1 -3
- package/dist/esm/plugins/Hyperlink/components/ResourceHyperlink.js +3 -2
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +3 -2
- package/dist/esm/plugins/Hyperlink/components/useHyperlinkCommon.js +22 -1
- package/dist/types/internal/hooks.d.ts +0 -1
- package/dist/types/plugins/Hyperlink/components/LinkPopover.d.ts +2 -1
- package/dist/types/plugins/Hyperlink/components/useHyperlinkCommon.d.ts +1 -0
- package/package.json +2 -2
|
@@ -9,9 +9,6 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
useFocused: function() {
|
|
13
|
-
return useFocused;
|
|
14
|
-
},
|
|
15
12
|
usePlateEditorRef: function() {
|
|
16
13
|
return usePlateEditorRef;
|
|
17
14
|
},
|
|
@@ -78,6 +75,3 @@ const usePlateEditorState = (id)=>{
|
|
|
78
75
|
const usePlateSelectors = (id)=>{
|
|
79
76
|
return _platecommon.usePlateSelectors(id);
|
|
80
77
|
};
|
|
81
|
-
const useFocused = ()=>{
|
|
82
|
-
return _slatereact.useFocused();
|
|
83
|
-
};
|
|
@@ -58,7 +58,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
58
58
|
return newObj;
|
|
59
59
|
}
|
|
60
60
|
function EntityHyperlink(props) {
|
|
61
|
-
const { editor, sdk, isLinkFocused, pathToElement } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
61
|
+
const { editor, sdk, isLinkFocused, pathToElement, isEditorFocused } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
62
62
|
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
63
63
|
const { target } = props.element.data;
|
|
64
64
|
const tooltipContent = (0, _useEntityInfo.useEntityInfo)({
|
|
@@ -78,7 +78,8 @@ function EntityHyperlink(props) {
|
|
|
78
78
|
isLinkFocused: isLinkFocused,
|
|
79
79
|
handleEditLink: ()=>(0, _linkHandlers.handleEditLink)(editor, sdk, pathToElement),
|
|
80
80
|
handleRemoveLink: ()=>(0, _linkHandlers.handleRemoveLink)(editor),
|
|
81
|
-
popoverText: popoverText
|
|
81
|
+
popoverText: popoverText,
|
|
82
|
+
isEditorFocused: isEditorFocused
|
|
82
83
|
}, _react.createElement(_f36components.Text, {
|
|
83
84
|
testId: "cf-ui-text-link",
|
|
84
85
|
fontColor: "blue600",
|
|
@@ -11,7 +11,6 @@ Object.defineProperty(exports, "LinkPopover", {
|
|
|
11
11
|
const _react = _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
13
|
const _f36icons = require("@contentful/f36-icons");
|
|
14
|
-
const _hooks = require("../../../internal/hooks");
|
|
15
14
|
const _styles = require("./styles");
|
|
16
15
|
function _getRequireWildcardCache(nodeInterop) {
|
|
17
16
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -54,8 +53,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
54
53
|
}
|
|
55
54
|
return newObj;
|
|
56
55
|
}
|
|
57
|
-
const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink })=>{
|
|
58
|
-
const isEditorFocused = (0, _hooks.useFocused)();
|
|
56
|
+
const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink, isEditorFocused })=>{
|
|
59
57
|
const popoverContent = _react.useRef(null);
|
|
60
58
|
const [isPopoverContentClicked, setIsPopoverContentClicked] = _react.useState(false);
|
|
61
59
|
_react.useEffect(()=>{
|
|
@@ -58,7 +58,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
58
58
|
return newObj;
|
|
59
59
|
}
|
|
60
60
|
function ResourceHyperlink(props) {
|
|
61
|
-
const { editor, sdk, isLinkFocused, pathToElement } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
61
|
+
const { editor, sdk, isLinkFocused, pathToElement, isEditorFocused } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
62
62
|
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
63
63
|
const { target } = props.element.data;
|
|
64
64
|
const tooltipContent = (0, _useResourceEntityInfo.useResourceEntityInfo)({
|
|
@@ -77,7 +77,8 @@ function ResourceHyperlink(props) {
|
|
|
77
77
|
isLinkFocused: isLinkFocused,
|
|
78
78
|
handleEditLink: ()=>(0, _linkHandlers.handleEditLink)(editor, sdk, pathToElement),
|
|
79
79
|
handleRemoveLink: ()=>(0, _linkHandlers.handleRemoveLink)(editor),
|
|
80
|
-
popoverText: popoverText
|
|
80
|
+
popoverText: popoverText,
|
|
81
|
+
isEditorFocused: isEditorFocused
|
|
81
82
|
}, _react.createElement(_f36components.Text, {
|
|
82
83
|
testId: "cf-ui-text-link",
|
|
83
84
|
fontColor: "blue600",
|
|
@@ -56,7 +56,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
56
56
|
return newObj;
|
|
57
57
|
}
|
|
58
58
|
function UrlHyperlink(props) {
|
|
59
|
-
const { editor, sdk, isLinkFocused, pathToElement } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
59
|
+
const { editor, sdk, isLinkFocused, pathToElement, isEditorFocused } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
60
60
|
const uri = props.element.data?.uri;
|
|
61
61
|
const popoverText = _react.createElement(_f36components.TextLink, {
|
|
62
62
|
className: _styles.styles.openLink,
|
|
@@ -69,7 +69,8 @@ function UrlHyperlink(props) {
|
|
|
69
69
|
handleEditLink: ()=>(0, _linkHandlers.handleEditLink)(editor, sdk, pathToElement),
|
|
70
70
|
handleRemoveLink: ()=>(0, _linkHandlers.handleRemoveLink)(editor),
|
|
71
71
|
handleCopyLink: ()=>(0, _linkHandlers.handleCopyLink)(uri),
|
|
72
|
-
popoverText: popoverText
|
|
72
|
+
popoverText: popoverText,
|
|
73
|
+
isEditorFocused: isEditorFocused
|
|
73
74
|
}, _react.createElement(_f36components.TextLink, {
|
|
74
75
|
testId: "cf-ui-text-link",
|
|
75
76
|
href: uri,
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "useHyperlinkCommon", {
|
|
|
8
8
|
return useHyperlinkCommon;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _react = require("react");
|
|
11
12
|
const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
|
|
12
13
|
const _queries = require("../../../internal/queries");
|
|
13
14
|
const _SdkProvider = require("../../../SdkProvider");
|
|
@@ -17,10 +18,30 @@ function useHyperlinkCommon(element) {
|
|
|
17
18
|
const focus = editor.selection?.focus;
|
|
18
19
|
const pathToElement = (0, _queries.findNodePath)(editor, element);
|
|
19
20
|
const isLinkFocused = pathToElement && focus && (0, _queries.isChildPath)(focus.path, pathToElement);
|
|
21
|
+
const [isEditorFocused, setIsEditorFocused] = (0, _react.useState)(false);
|
|
22
|
+
(0, _react.useEffect)(()=>{
|
|
23
|
+
const handleFocus = ()=>setIsEditorFocused(true);
|
|
24
|
+
const handleBlur = ()=>setIsEditorFocused(false);
|
|
25
|
+
const editorElement = document.getElementById(editor.id);
|
|
26
|
+
if (editorElement) {
|
|
27
|
+
setIsEditorFocused(document.activeElement === editorElement);
|
|
28
|
+
editorElement.addEventListener('focus', handleFocus);
|
|
29
|
+
editorElement.addEventListener('blur', handleBlur);
|
|
30
|
+
}
|
|
31
|
+
return ()=>{
|
|
32
|
+
if (editorElement) {
|
|
33
|
+
editorElement.removeEventListener('focus', handleFocus);
|
|
34
|
+
editorElement.removeEventListener('blur', handleBlur);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}, [
|
|
38
|
+
editor
|
|
39
|
+
]);
|
|
20
40
|
return {
|
|
21
41
|
editor,
|
|
22
42
|
sdk,
|
|
23
43
|
isLinkFocused,
|
|
24
|
-
pathToElement
|
|
44
|
+
pathToElement,
|
|
45
|
+
isEditorFocused
|
|
25
46
|
};
|
|
26
47
|
}
|
|
@@ -7,7 +7,7 @@ import { LinkPopover } from './LinkPopover';
|
|
|
7
7
|
import { styles } from './styles';
|
|
8
8
|
import { useHyperlinkCommon } from './useHyperlinkCommon';
|
|
9
9
|
export function EntityHyperlink(props) {
|
|
10
|
-
const { editor, sdk, isLinkFocused, pathToElement } = useHyperlinkCommon(props.element);
|
|
10
|
+
const { editor, sdk, isLinkFocused, pathToElement, isEditorFocused } = useHyperlinkCommon(props.element);
|
|
11
11
|
const { onEntityFetchComplete } = useLinkTracking();
|
|
12
12
|
const { target } = props.element.data;
|
|
13
13
|
const tooltipContent = useEntityInfo({
|
|
@@ -27,7 +27,8 @@ export function EntityHyperlink(props) {
|
|
|
27
27
|
isLinkFocused: isLinkFocused,
|
|
28
28
|
handleEditLink: ()=>handleEditLink(editor, sdk, pathToElement),
|
|
29
29
|
handleRemoveLink: ()=>handleRemoveLink(editor),
|
|
30
|
-
popoverText: popoverText
|
|
30
|
+
popoverText: popoverText,
|
|
31
|
+
isEditorFocused: isEditorFocused
|
|
31
32
|
}, React.createElement(Text, {
|
|
32
33
|
testId: "cf-ui-text-link",
|
|
33
34
|
fontColor: "blue600",
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Popover, IconButton, Tooltip, Flex } from '@contentful/f36-components';
|
|
3
3
|
import { EditIcon, CopyIcon } from '@contentful/f36-icons';
|
|
4
|
-
import { useFocused } from '../../../internal/hooks';
|
|
5
4
|
import { styles } from './styles';
|
|
6
|
-
export const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink })=>{
|
|
7
|
-
const isEditorFocused = useFocused();
|
|
5
|
+
export const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink, isEditorFocused })=>{
|
|
8
6
|
const popoverContent = React.useRef(null);
|
|
9
7
|
const [isPopoverContentClicked, setIsPopoverContentClicked] = React.useState(false);
|
|
10
8
|
React.useEffect(()=>{
|
|
@@ -7,7 +7,7 @@ import { LinkPopover } from './LinkPopover';
|
|
|
7
7
|
import { styles } from './styles';
|
|
8
8
|
import { useHyperlinkCommon } from './useHyperlinkCommon';
|
|
9
9
|
export function ResourceHyperlink(props) {
|
|
10
|
-
const { editor, sdk, isLinkFocused, pathToElement } = useHyperlinkCommon(props.element);
|
|
10
|
+
const { editor, sdk, isLinkFocused, pathToElement, isEditorFocused } = useHyperlinkCommon(props.element);
|
|
11
11
|
const { onEntityFetchComplete } = useLinkTracking();
|
|
12
12
|
const { target } = props.element.data;
|
|
13
13
|
const tooltipContent = useResourceEntityInfo({
|
|
@@ -26,7 +26,8 @@ export function ResourceHyperlink(props) {
|
|
|
26
26
|
isLinkFocused: isLinkFocused,
|
|
27
27
|
handleEditLink: ()=>handleEditLink(editor, sdk, pathToElement),
|
|
28
28
|
handleRemoveLink: ()=>handleRemoveLink(editor),
|
|
29
|
-
popoverText: popoverText
|
|
29
|
+
popoverText: popoverText,
|
|
30
|
+
isEditorFocused: isEditorFocused
|
|
30
31
|
}, React.createElement(Text, {
|
|
31
32
|
testId: "cf-ui-text-link",
|
|
32
33
|
fontColor: "blue600",
|
|
@@ -5,7 +5,7 @@ import { LinkPopover } from './LinkPopover';
|
|
|
5
5
|
import { styles } from './styles';
|
|
6
6
|
import { useHyperlinkCommon } from './useHyperlinkCommon';
|
|
7
7
|
export function UrlHyperlink(props) {
|
|
8
|
-
const { editor, sdk, isLinkFocused, pathToElement } = useHyperlinkCommon(props.element);
|
|
8
|
+
const { editor, sdk, isLinkFocused, pathToElement, isEditorFocused } = useHyperlinkCommon(props.element);
|
|
9
9
|
const uri = props.element.data?.uri;
|
|
10
10
|
const popoverText = React.createElement(TextLink, {
|
|
11
11
|
className: styles.openLink,
|
|
@@ -18,7 +18,8 @@ export function UrlHyperlink(props) {
|
|
|
18
18
|
handleEditLink: ()=>handleEditLink(editor, sdk, pathToElement),
|
|
19
19
|
handleRemoveLink: ()=>handleRemoveLink(editor),
|
|
20
20
|
handleCopyLink: ()=>handleCopyLink(uri),
|
|
21
|
-
popoverText: popoverText
|
|
21
|
+
popoverText: popoverText,
|
|
22
|
+
isEditorFocused: isEditorFocused
|
|
22
23
|
}, React.createElement(TextLink, {
|
|
23
24
|
testId: "cf-ui-text-link",
|
|
24
25
|
href: uri,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
1
2
|
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
2
3
|
import { findNodePath, isChildPath } from '../../../internal/queries';
|
|
3
4
|
import { useSdkContext } from '../../../SdkProvider';
|
|
@@ -7,10 +8,30 @@ export function useHyperlinkCommon(element) {
|
|
|
7
8
|
const focus = editor.selection?.focus;
|
|
8
9
|
const pathToElement = findNodePath(editor, element);
|
|
9
10
|
const isLinkFocused = pathToElement && focus && isChildPath(focus.path, pathToElement);
|
|
11
|
+
const [isEditorFocused, setIsEditorFocused] = useState(false);
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
const handleFocus = ()=>setIsEditorFocused(true);
|
|
14
|
+
const handleBlur = ()=>setIsEditorFocused(false);
|
|
15
|
+
const editorElement = document.getElementById(editor.id);
|
|
16
|
+
if (editorElement) {
|
|
17
|
+
setIsEditorFocused(document.activeElement === editorElement);
|
|
18
|
+
editorElement.addEventListener('focus', handleFocus);
|
|
19
|
+
editorElement.addEventListener('blur', handleBlur);
|
|
20
|
+
}
|
|
21
|
+
return ()=>{
|
|
22
|
+
if (editorElement) {
|
|
23
|
+
editorElement.removeEventListener('focus', handleFocus);
|
|
24
|
+
editorElement.removeEventListener('blur', handleBlur);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}, [
|
|
28
|
+
editor
|
|
29
|
+
]);
|
|
10
30
|
return {
|
|
11
31
|
editor,
|
|
12
32
|
sdk,
|
|
13
33
|
isLinkFocused,
|
|
14
|
-
pathToElement
|
|
34
|
+
pathToElement,
|
|
35
|
+
isEditorFocused
|
|
15
36
|
};
|
|
16
37
|
}
|
|
@@ -6,6 +6,7 @@ type LinkPopoverProps = {
|
|
|
6
6
|
handleRemoveLink: () => void;
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
handleCopyLink?: () => void;
|
|
9
|
+
isEditorFocused: boolean;
|
|
9
10
|
};
|
|
10
|
-
export declare const LinkPopover: ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink, }: LinkPopoverProps) => JSX.Element;
|
|
11
|
+
export declare const LinkPopover: ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink, isEditorFocused, }: LinkPopoverProps) => JSX.Element;
|
|
11
12
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "3.18.
|
|
3
|
+
"version": "3.18.1",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"registry": "https://npm.pkg.github.com/"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "e9f015ed3812c349512b39f2fd2554dddd7ed8d4"
|
|
90
90
|
}
|