@contentful/field-editor-rich-text 3.17.7 → 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/Toolbar/components/ButtonRedo.js +33 -0
- package/dist/cjs/Toolbar/components/ButtonUndo.js +33 -0
- package/dist/cjs/Toolbar/index.js +10 -4
- 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/Toolbar/components/ButtonRedo.js +18 -0
- package/dist/esm/Toolbar/components/ButtonUndo.js +18 -0
- package/dist/esm/Toolbar/index.js +10 -4
- 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/Toolbar/components/ButtonRedo.d.ts +1 -0
- package/dist/types/Toolbar/components/ButtonUndo.d.ts +1 -0
- 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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ButtonRedo", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ButtonRedo;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_default(require("react"));
|
|
12
|
+
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
14
|
+
const _ToolbarButton = require("../../plugins/shared/ToolbarButton");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const ButtonRedo = ()=>{
|
|
21
|
+
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
22
|
+
return _react.default.createElement(_ToolbarButton.ToolbarButton, {
|
|
23
|
+
title: "Redo",
|
|
24
|
+
testId: "redo-toolbar-button",
|
|
25
|
+
onClick: editor.redo,
|
|
26
|
+
isActive: false,
|
|
27
|
+
isDisabled: editor.history.redos.length === 0
|
|
28
|
+
}, _react.default.createElement(_f36components.Icon, {
|
|
29
|
+
variant: "secondary"
|
|
30
|
+
}, _react.default.createElement("path", {
|
|
31
|
+
d: "M18.4,10.6C16.55,9 14.15,8 11.5,8C6.85,8 2.92,11.03 1.54,15.22L3.9,16C4.95,12.81 7.95,10.5 11.5,10.5C13.45,10.5 15.23,11.22 16.62,12.38L13,16H22V7L18.4,10.6Z"
|
|
32
|
+
})));
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ButtonUndo", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ButtonUndo;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _react = _interop_require_default(require("react"));
|
|
12
|
+
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _ContentfulEditorProvider = require("../../ContentfulEditorProvider");
|
|
14
|
+
const _ToolbarButton = require("../../plugins/shared/ToolbarButton");
|
|
15
|
+
function _interop_require_default(obj) {
|
|
16
|
+
return obj && obj.__esModule ? obj : {
|
|
17
|
+
default: obj
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const ButtonUndo = ()=>{
|
|
21
|
+
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
22
|
+
return _react.default.createElement(_ToolbarButton.ToolbarButton, {
|
|
23
|
+
title: "Undo",
|
|
24
|
+
testId: "undo-toolbar-button",
|
|
25
|
+
onClick: editor.undo,
|
|
26
|
+
isActive: false,
|
|
27
|
+
isDisabled: editor.history.undos.length === 0
|
|
28
|
+
}, _react.default.createElement(_f36components.Icon, {
|
|
29
|
+
variant: "secondary"
|
|
30
|
+
}, _react.default.createElement("path", {
|
|
31
|
+
d: "M12.5,8C9.85,8 7.45,9 5.6,10.6L2,7V16H11L7.38,12.38C8.77,11.22 10.54,10.5 12.5,10.5C16.04,10.5 19.05,12.81 20.1,16L22.47,15.22C21.08,11.03 17.15,8 12.5,8Z"
|
|
32
|
+
})));
|
|
33
|
+
};
|
|
@@ -31,6 +31,8 @@ const _Underline = require("../plugins/Marks/Underline");
|
|
|
31
31
|
const _Quote = require("../plugins/Quote");
|
|
32
32
|
const _Table = require("../plugins/Table");
|
|
33
33
|
const _SdkProvider = require("../SdkProvider");
|
|
34
|
+
const _ButtonRedo = require("./components/ButtonRedo");
|
|
35
|
+
const _ButtonUndo = require("./components/ButtonUndo");
|
|
34
36
|
const _EmbedEntityWidget = require("./components/EmbedEntityWidget");
|
|
35
37
|
function _interop_require_default(obj) {
|
|
36
38
|
return obj && obj.__esModule ? obj : {
|
|
@@ -106,8 +108,7 @@ const styles = {
|
|
|
106
108
|
],
|
|
107
109
|
webkitAlignSelf: 'flex-start',
|
|
108
110
|
alignSelf: 'flex-start',
|
|
109
|
-
msFlexItemAlign: 'start'
|
|
110
|
-
marginLeft: 'auto'
|
|
111
|
+
msFlexItemAlign: 'start'
|
|
111
112
|
}),
|
|
112
113
|
formattingOptionsWrapper: (0, _emotion.css)({
|
|
113
114
|
display: [
|
|
@@ -156,14 +157,19 @@ const Toolbar = ({ isDisabled })=>{
|
|
|
156
157
|
const dropdownItemsAvailable = (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.SUPERSCRIPT) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.SUBSCRIPT) || (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.CODE);
|
|
157
158
|
const shouldShowDropdown = boldItalicUnderlineAvailable && dropdownItemsAvailable;
|
|
158
159
|
return _react.createElement(_f36components.Flex, {
|
|
160
|
+
gap: "spacingS",
|
|
161
|
+
flexWrap: "wrap",
|
|
162
|
+
flexDirection: "row",
|
|
159
163
|
testId: "toolbar",
|
|
160
164
|
className: styles.toolbar,
|
|
161
|
-
|
|
165
|
+
justifyContent: "space-between"
|
|
162
166
|
}, _react.createElement("div", {
|
|
163
167
|
className: styles.formattingOptionsWrapper
|
|
164
168
|
}, _react.createElement(_Heading.ToolbarHeadingButton, {
|
|
165
169
|
isDisabled: isDisabled || !canInsertBlocks
|
|
166
|
-
}),
|
|
170
|
+
}), _react.createElement("span", {
|
|
171
|
+
className: styles.divider
|
|
172
|
+
}), _react.createElement(_ButtonUndo.ButtonUndo, null), _react.createElement(_ButtonRedo.ButtonRedo, null), validationInfo.isAnyMarkEnabled && _react.createElement("span", {
|
|
167
173
|
className: styles.divider
|
|
168
174
|
}), (0, _validations.isMarkEnabled)(sdk.field, _richtexttypes.MARKS.BOLD) && _react.createElement(_Bold.ToolbarBoldButton, {
|
|
169
175
|
isDisabled: isDisabled
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Icon } from '@contentful/f36-components';
|
|
3
|
+
import { useContentfulEditor } from '../../ContentfulEditorProvider';
|
|
4
|
+
import { ToolbarButton } from '../../plugins/shared/ToolbarButton';
|
|
5
|
+
export const ButtonRedo = ()=>{
|
|
6
|
+
const editor = useContentfulEditor();
|
|
7
|
+
return React.createElement(ToolbarButton, {
|
|
8
|
+
title: "Redo",
|
|
9
|
+
testId: "redo-toolbar-button",
|
|
10
|
+
onClick: editor.redo,
|
|
11
|
+
isActive: false,
|
|
12
|
+
isDisabled: editor.history.redos.length === 0
|
|
13
|
+
}, React.createElement(Icon, {
|
|
14
|
+
variant: "secondary"
|
|
15
|
+
}, React.createElement("path", {
|
|
16
|
+
d: "M18.4,10.6C16.55,9 14.15,8 11.5,8C6.85,8 2.92,11.03 1.54,15.22L3.9,16C4.95,12.81 7.95,10.5 11.5,10.5C13.45,10.5 15.23,11.22 16.62,12.38L13,16H22V7L18.4,10.6Z"
|
|
17
|
+
})));
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Icon } from '@contentful/f36-components';
|
|
3
|
+
import { useContentfulEditor } from '../../ContentfulEditorProvider';
|
|
4
|
+
import { ToolbarButton } from '../../plugins/shared/ToolbarButton';
|
|
5
|
+
export const ButtonUndo = ()=>{
|
|
6
|
+
const editor = useContentfulEditor();
|
|
7
|
+
return React.createElement(ToolbarButton, {
|
|
8
|
+
title: "Undo",
|
|
9
|
+
testId: "undo-toolbar-button",
|
|
10
|
+
onClick: editor.undo,
|
|
11
|
+
isActive: false,
|
|
12
|
+
isDisabled: editor.history.undos.length === 0
|
|
13
|
+
}, React.createElement(Icon, {
|
|
14
|
+
variant: "secondary"
|
|
15
|
+
}, React.createElement("path", {
|
|
16
|
+
d: "M12.5,8C9.85,8 7.45,9 5.6,10.6L2,7V16H11L7.38,12.38C8.77,11.22 10.54,10.5 12.5,10.5C16.04,10.5 19.05,12.81 20.1,16L22.47,15.22C21.08,11.03 17.15,8 12.5,8Z"
|
|
17
|
+
})));
|
|
18
|
+
};
|
|
@@ -21,6 +21,8 @@ import { ToolbarUnderlineButton } from '../plugins/Marks/Underline';
|
|
|
21
21
|
import { ToolbarQuoteButton } from '../plugins/Quote';
|
|
22
22
|
import { ToolbarTableButton } from '../plugins/Table';
|
|
23
23
|
import { useSdkContext } from '../SdkProvider';
|
|
24
|
+
import { ButtonRedo } from './components/ButtonRedo';
|
|
25
|
+
import { ButtonUndo } from './components/ButtonUndo';
|
|
24
26
|
import { EmbedEntityWidget } from './components/EmbedEntityWidget';
|
|
25
27
|
const styles = {
|
|
26
28
|
toolbar: css({
|
|
@@ -50,8 +52,7 @@ const styles = {
|
|
|
50
52
|
],
|
|
51
53
|
webkitAlignSelf: 'flex-start',
|
|
52
54
|
alignSelf: 'flex-start',
|
|
53
|
-
msFlexItemAlign: 'start'
|
|
54
|
-
marginLeft: 'auto'
|
|
55
|
+
msFlexItemAlign: 'start'
|
|
55
56
|
}),
|
|
56
57
|
formattingOptionsWrapper: css({
|
|
57
58
|
display: [
|
|
@@ -100,14 +101,19 @@ const Toolbar = ({ isDisabled })=>{
|
|
|
100
101
|
const dropdownItemsAvailable = isMarkEnabled(sdk.field, MARKS.SUPERSCRIPT) || isMarkEnabled(sdk.field, MARKS.SUBSCRIPT) || isMarkEnabled(sdk.field, MARKS.CODE);
|
|
101
102
|
const shouldShowDropdown = boldItalicUnderlineAvailable && dropdownItemsAvailable;
|
|
102
103
|
return React.createElement(Flex, {
|
|
104
|
+
gap: "spacingS",
|
|
105
|
+
flexWrap: "wrap",
|
|
106
|
+
flexDirection: "row",
|
|
103
107
|
testId: "toolbar",
|
|
104
108
|
className: styles.toolbar,
|
|
105
|
-
|
|
109
|
+
justifyContent: "space-between"
|
|
106
110
|
}, React.createElement("div", {
|
|
107
111
|
className: styles.formattingOptionsWrapper
|
|
108
112
|
}, React.createElement(ToolbarHeadingButton, {
|
|
109
113
|
isDisabled: isDisabled || !canInsertBlocks
|
|
110
|
-
}),
|
|
114
|
+
}), React.createElement("span", {
|
|
115
|
+
className: styles.divider
|
|
116
|
+
}), React.createElement(ButtonUndo, null), React.createElement(ButtonRedo, null), validationInfo.isAnyMarkEnabled && React.createElement("span", {
|
|
111
117
|
className: styles.divider
|
|
112
118
|
}), isMarkEnabled(sdk.field, MARKS.BOLD) && React.createElement(ToolbarBoldButton, {
|
|
113
119
|
isDisabled: isDisabled
|
|
@@ -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
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ButtonRedo: () => JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ButtonUndo: () => JSX.Element;
|
|
@@ -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.
|
|
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
|
}
|