@contentful/field-editor-rich-text 3.16.0 → 3.16.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.
@@ -9,6 +9,9 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ useFocused: function() {
13
+ return useFocused;
14
+ },
12
15
  usePlateEditorRef: function() {
13
16
  return usePlateEditorRef;
14
17
  },
@@ -75,3 +78,6 @@ const usePlateEditorState = (id)=>{
75
78
  const usePlateSelectors = (id)=>{
76
79
  return _platecommon.usePlateSelectors(id);
77
80
  };
81
+ const useFocused = ()=>{
82
+ return _slatereact.useFocused();
83
+ };
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "LinkPopover", {
11
11
  const _react = /*#__PURE__*/ _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");
14
15
  const _styles = require("./styles");
15
16
  function _getRequireWildcardCache(nodeInterop) {
16
17
  if (typeof WeakMap !== "function") return null;
@@ -53,16 +54,36 @@ function _interop_require_wildcard(obj, nodeInterop) {
53
54
  }
54
55
  return newObj;
55
56
  }
56
- const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink })=>// eslint-disable-next-line jsx-a11y/no-autofocus -- we don't want to autofocus the popover
57
+ const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink })=>{
58
+ const isEditorFocused = (0, _hooks.useFocused)();
59
+ const popoverContent = _react.useRef(null);
60
+ const [isPopoverContentClicked, setIsPopoverContentClicked] = _react.useState(false);
61
+ _react.useEffect(()=>{
62
+ const handleMouseDown = (event)=>{
63
+ if (popoverContent.current && popoverContent.current.contains(event.target)) {
64
+ setIsPopoverContentClicked(true);
65
+ } else {
66
+ setIsPopoverContentClicked(false);
67
+ }
68
+ };
69
+ document.addEventListener('mousedown', handleMouseDown);
70
+ return ()=>{
71
+ document.removeEventListener('mousedown', handleMouseDown);
72
+ };
73
+ }, []);
74
+ const isOpen = isLinkFocused && isEditorFocused || isPopoverContentClicked;
75
+ // Important to render this component in a portal
76
+ // Otherwise the content of the popover will get copied over when users copy text from the rich text editor
77
+ return(// eslint-disable-next-line jsx-a11y/no-autofocus -- we don't want to autofocus the popover
57
78
  /*#__PURE__*/ _react.createElement(_f36components.Popover, {
58
79
  renderOnlyWhenOpen: false,
59
- usePortal: false,
80
+ usePortal: true,
60
81
  autoFocus: false,
61
- isOpen: isLinkFocused
82
+ isOpen: isOpen
62
83
  }, /*#__PURE__*/ _react.createElement(_f36components.Popover.Trigger, null, children), /*#__PURE__*/ _react.createElement(_f36components.Popover.Content, {
63
84
  className: _styles.styles.popover
64
85
  }, /*#__PURE__*/ _react.createElement(_f36components.Flex, {
65
- contentEditable: "false",
86
+ ref: popoverContent,
66
87
  alignItems: "center",
67
88
  paddingTop: "spacing2Xs",
68
89
  paddingBottom: "spacing2Xs",
@@ -115,4 +136,5 @@ const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveL
115
136
  d: "M1.75 8C1.75 8.59674 1.98705 9.16903 2.40901 9.59099C2.83097 10.0129 3.40326 10.25 4 10.25H6.5C6.69891 10.25 6.88968 10.329 7.03033 10.4697C7.17098 10.6103 7.25 10.8011 7.25 11C7.25 11.1989 7.17098 11.3897 7.03033 11.5303C6.88968 11.671 6.69891 11.75 6.5 11.75H4C3.00544 11.75 2.05161 11.3549 1.34835 10.6517C0.645088 9.94839 0.25 8.99456 0.25 8C0.25 7.00544 0.645088 6.05161 1.34835 5.34835C2.05161 4.64509 3.00544 4.25 4 4.25H6.5C6.69891 4.25 6.88968 4.32902 7.03033 4.46967C7.17098 4.61032 7.25 4.80109 7.25 5C7.25 5.19891 7.17098 5.38968 7.03033 5.53033C6.88968 5.67098 6.69891 5.75 6.5 5.75H4C3.40326 5.75 2.83097 5.98705 2.40901 6.40901C1.98705 6.83097 1.75 7.40326 1.75 8ZM12 4.25H9.5C9.30109 4.25 9.11032 4.32902 8.96967 4.46967C8.82902 4.61032 8.75 4.80109 8.75 5C8.75 5.19891 8.82902 5.38968 8.96967 5.53033C9.11032 5.67098 9.30109 5.75 9.5 5.75H12C12.5967 5.75 13.169 5.98705 13.591 6.40901C14.0129 6.83097 14.25 7.40326 14.25 8C14.25 8.59674 14.0129 9.16903 13.591 9.59099C13.169 10.0129 12.5967 10.25 12 10.25H9.5C9.30109 10.25 9.11032 10.329 8.96967 10.4697C8.82902 10.6103 8.75 10.8011 8.75 11C8.75 11.1989 8.82902 11.3897 8.96967 11.5303C9.11032 11.671 9.30109 11.75 9.5 11.75H12C12.9946 11.75 13.9484 11.3549 14.6517 10.6517C15.3549 9.94839 15.75 8.99456 15.75 8C15.75 7.00544 15.3549 6.05161 14.6517 5.34835C13.9484 4.64509 12.9946 4.25 12 4.25Z",
116
137
  fill: "black"
117
138
  }))
118
- })))));
139
+ }))))));
140
+ };
@@ -76,10 +76,10 @@ function UrlHyperlink(props) {
76
76
  handleRemoveLink: ()=>(0, _linkHandlers.handleRemoveLink)(editor),
77
77
  handleCopyLink: ()=>(0, _linkHandlers.handleCopyLink)(uri),
78
78
  popoverText: popoverText
79
- }, /*#__PURE__*/ _react.createElement(_f36components.Text, {
79
+ }, /*#__PURE__*/ _react.createElement(_f36components.TextLink, {
80
80
  testId: "cf-ui-text-link",
81
- fontColor: "blue600",
82
- fontWeight: "fontWeightMedium",
81
+ href: uri,
82
+ onClick: (e)=>e.preventDefault(),
83
83
  className: _styles.styles.hyperlink
84
84
  }, props.children));
85
85
  }
@@ -36,13 +36,14 @@ const styles = {
36
36
  textOverflow: 'ellipsis'
37
37
  }),
38
38
  popover: (0, _emotion.css)({
39
- zIndex: _f36tokens.default.zIndexDefault
39
+ zIndex: _f36tokens.default.zIndexModal
40
40
  }),
41
41
  hyperlink: (0, _emotion.css)({
42
42
  fontSize: 'inherit !important',
43
43
  display: 'inline !important',
44
44
  '&:hover': {
45
- fill: _f36tokens.default.gray900
45
+ fill: _f36tokens.default.gray900,
46
+ textDecoration: 'none'
46
47
  },
47
48
  '&:focus': {
48
49
  fill: _f36tokens.default.gray900
@@ -10,3 +10,6 @@ export const usePlateEditorState = (id)=>{
10
10
  export const usePlateSelectors = (id)=>{
11
11
  return p.usePlateSelectors(id);
12
12
  };
13
+ export const useFocused = ()=>{
14
+ return sr.useFocused();
15
+ };
@@ -1,17 +1,38 @@
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';
4
5
  import { styles } from './styles';
5
- export const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink })=>// eslint-disable-next-line jsx-a11y/no-autofocus -- we don't want to autofocus the popover
6
+ export const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handleRemoveLink, children, handleCopyLink })=>{
7
+ const isEditorFocused = useFocused();
8
+ const popoverContent = React.useRef(null);
9
+ const [isPopoverContentClicked, setIsPopoverContentClicked] = React.useState(false);
10
+ React.useEffect(()=>{
11
+ const handleMouseDown = (event)=>{
12
+ if (popoverContent.current && popoverContent.current.contains(event.target)) {
13
+ setIsPopoverContentClicked(true);
14
+ } else {
15
+ setIsPopoverContentClicked(false);
16
+ }
17
+ };
18
+ document.addEventListener('mousedown', handleMouseDown);
19
+ return ()=>{
20
+ document.removeEventListener('mousedown', handleMouseDown);
21
+ };
22
+ }, []);
23
+ const isOpen = isLinkFocused && isEditorFocused || isPopoverContentClicked;
24
+ // Important to render this component in a portal
25
+ // Otherwise the content of the popover will get copied over when users copy text from the rich text editor
26
+ return(// eslint-disable-next-line jsx-a11y/no-autofocus -- we don't want to autofocus the popover
6
27
  /*#__PURE__*/ React.createElement(Popover, {
7
28
  renderOnlyWhenOpen: false,
8
- usePortal: false,
29
+ usePortal: true,
9
30
  autoFocus: false,
10
- isOpen: isLinkFocused
31
+ isOpen: isOpen
11
32
  }, /*#__PURE__*/ React.createElement(Popover.Trigger, null, children), /*#__PURE__*/ React.createElement(Popover.Content, {
12
33
  className: styles.popover
13
34
  }, /*#__PURE__*/ React.createElement(Flex, {
14
- contentEditable: "false",
35
+ ref: popoverContent,
15
36
  alignItems: "center",
16
37
  paddingTop: "spacing2Xs",
17
38
  paddingBottom: "spacing2Xs",
@@ -64,4 +85,5 @@ export const LinkPopover = ({ isLinkFocused, popoverText, handleEditLink, handle
64
85
  d: "M1.75 8C1.75 8.59674 1.98705 9.16903 2.40901 9.59099C2.83097 10.0129 3.40326 10.25 4 10.25H6.5C6.69891 10.25 6.88968 10.329 7.03033 10.4697C7.17098 10.6103 7.25 10.8011 7.25 11C7.25 11.1989 7.17098 11.3897 7.03033 11.5303C6.88968 11.671 6.69891 11.75 6.5 11.75H4C3.00544 11.75 2.05161 11.3549 1.34835 10.6517C0.645088 9.94839 0.25 8.99456 0.25 8C0.25 7.00544 0.645088 6.05161 1.34835 5.34835C2.05161 4.64509 3.00544 4.25 4 4.25H6.5C6.69891 4.25 6.88968 4.32902 7.03033 4.46967C7.17098 4.61032 7.25 4.80109 7.25 5C7.25 5.19891 7.17098 5.38968 7.03033 5.53033C6.88968 5.67098 6.69891 5.75 6.5 5.75H4C3.40326 5.75 2.83097 5.98705 2.40901 6.40901C1.98705 6.83097 1.75 7.40326 1.75 8ZM12 4.25H9.5C9.30109 4.25 9.11032 4.32902 8.96967 4.46967C8.82902 4.61032 8.75 4.80109 8.75 5C8.75 5.19891 8.82902 5.38968 8.96967 5.53033C9.11032 5.67098 9.30109 5.75 9.5 5.75H12C12.5967 5.75 13.169 5.98705 13.591 6.40901C14.0129 6.83097 14.25 7.40326 14.25 8C14.25 8.59674 14.0129 9.16903 13.591 9.59099C13.169 10.0129 12.5967 10.25 12 10.25H9.5C9.30109 10.25 9.11032 10.329 8.96967 10.4697C8.82902 10.6103 8.75 10.8011 8.75 11C8.75 11.1989 8.82902 11.3897 8.96967 11.5303C9.11032 11.671 9.30109 11.75 9.5 11.75H12C12.9946 11.75 13.9484 11.3549 14.6517 10.6517C15.3549 9.94839 15.75 8.99456 15.75 8C15.75 7.00544 15.3549 6.05161 14.6517 5.34835C13.9484 4.64509 12.9946 4.25 12 4.25Z",
65
86
  fill: "black"
66
87
  }))
67
- })))));
88
+ }))))));
89
+ };
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { TextLink, Text } from '@contentful/f36-components';
2
+ import { TextLink } from '@contentful/f36-components';
3
3
  import { useContentfulEditor } from '../../../ContentfulEditorProvider';
4
4
  import { findNodePath, isChildPath } from '../../../internal/queries';
5
5
  import { useSdkContext } from '../../../SdkProvider';
@@ -25,10 +25,10 @@ export function UrlHyperlink(props) {
25
25
  handleRemoveLink: ()=>handleRemoveLink(editor),
26
26
  handleCopyLink: ()=>handleCopyLink(uri),
27
27
  popoverText: popoverText
28
- }, /*#__PURE__*/ React.createElement(Text, {
28
+ }, /*#__PURE__*/ React.createElement(TextLink, {
29
29
  testId: "cf-ui-text-link",
30
- fontColor: "blue600",
31
- fontWeight: "fontWeightMedium",
30
+ href: uri,
31
+ onClick: (e)=>e.preventDefault(),
32
32
  className: styles.hyperlink
33
33
  }, props.children));
34
34
  }
@@ -21,13 +21,14 @@ export const styles = {
21
21
  textOverflow: 'ellipsis'
22
22
  }),
23
23
  popover: css({
24
- zIndex: tokens.zIndexDefault
24
+ zIndex: tokens.zIndexModal
25
25
  }),
26
26
  hyperlink: css({
27
27
  fontSize: 'inherit !important',
28
28
  display: 'inline !important',
29
29
  '&:hover': {
30
- fill: tokens.gray900
30
+ fill: tokens.gray900,
31
+ textDecoration: 'none'
31
32
  },
32
33
  '&:focus': {
33
34
  fill: tokens.gray900
@@ -4,3 +4,4 @@ export declare const useReadOnly: () => boolean;
4
4
  export declare const usePlateEditorRef: (id?: string) => PlateEditor;
5
5
  export declare const usePlateEditorState: (id?: string) => PlateEditor;
6
6
  export declare const usePlateSelectors: (id?: string) => p.GetRecord<p.PlateStoreState<Value, PlateEditor>>;
7
+ export declare const useFocused: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.16.0",
3
+ "version": "3.16.1",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -81,5 +81,5 @@
81
81
  "prism-react-renderer": "2.0.5",
82
82
  "react": ">=16.14.0"
83
83
  },
84
- "gitHead": "9d07b5cbfb32a72cab6ff4fc4732e236033412bd"
84
+ "gitHead": "70604b5cc83909d95641b7ce9babe7c2dac1e6e6"
85
85
  }