@contentful/field-editor-rich-text 3.18.0 → 3.19.0

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,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
  }
@@ -10,6 +10,3 @@ 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
- };
@@ -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
  }
@@ -31,4 +31,3 @@ export declare const usePlateSelectors: (id?: string) => {
31
31
  } & {
32
32
  atom: <V>(atom: import("jotai").Atom<V>, options?: string | import("jotai-x").UseAtomOptions | undefined) => V;
33
33
  };
34
- export declare const useFocused: () => boolean;
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { ResourceLink } from '@contentful/field-editor-reference';
3
3
  import { FieldAppSDK } from '@contentful/field-editor-shared';
4
4
  interface FetchingWrappedResourceInlineCardProps {
5
- link: ResourceLink['sys'];
5
+ link: ResourceLink<'Contentful:Entry'>['sys'];
6
6
  sdk: FieldAppSDK;
7
7
  isSelected: boolean;
8
8
  isDisabled: boolean;
@@ -3,7 +3,7 @@ import { Element, RenderElementProps } from '../../internal';
3
3
  export type LinkedResourceInlineProps = {
4
4
  element: Element & {
5
5
  data: {
6
- target: ResourceLink;
6
+ target: ResourceLink<'Contentful:Entry'>;
7
7
  };
8
8
  };
9
9
  attributes: Pick<RenderElementProps, 'attributes'>;
@@ -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 {};
@@ -4,4 +4,5 @@ export declare function useHyperlinkCommon(element: any): {
4
4
  sdk: FieldAppSDK;
5
5
  isLinkFocused: boolean | undefined;
6
6
  pathToElement: import("slate").Path | undefined;
7
+ isEditorFocused: boolean;
7
8
  };
@@ -4,7 +4,7 @@ import { RenderElementProps } from '../../internal';
4
4
  type LinkedBlockWrapperProps = React.PropsWithChildren<{
5
5
  attributes: Pick<RenderElementProps, 'attributes'>;
6
6
  card: JSX.Element;
7
- link: ResourceLink | EntityLink;
7
+ link: ResourceLink<'Contentful:Entry'> | EntityLink;
8
8
  }>;
9
9
  export declare function LinkedBlockWrapper({ attributes, card, children, link }: LinkedBlockWrapperProps): JSX.Element;
10
10
  export {};
@@ -4,7 +4,7 @@ import { RenderElementProps } from '../../internal/types';
4
4
  type LinkedInlineWrapperProps = React.PropsWithChildren<{
5
5
  attributes: Pick<RenderElementProps, 'attributes'>;
6
6
  card: JSX.Element;
7
- link: ResourceLink | EntryLink;
7
+ link: ResourceLink<'Contentful:Entry'> | EntryLink;
8
8
  }>;
9
9
  export declare function LinkedInlineWrapper({ attributes, card, children, link, }: LinkedInlineWrapperProps): JSX.Element;
10
10
  export {};
@@ -1,3 +1,3 @@
1
1
  import { EntityLink, ResourceLink } from '@contentful/field-editor-reference';
2
- export declare const getLinkEntityId: (link: EntityLink | ResourceLink) => string;
2
+ export declare const getLinkEntityId: (link: EntityLink | ResourceLink<'Contentful:Entry'>) => string;
3
3
  export declare function truncateTitle(str: string, length: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-rich-text",
3
- "version": "3.18.0",
3
+ "version": "3.19.0",
4
4
  "source": "./src/index.tsx",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -44,7 +44,7 @@
44
44
  "@contentful/f36-icons": "^4.1.1",
45
45
  "@contentful/f36-tokens": "^4.0.0",
46
46
  "@contentful/f36-utils": "^4.19.0",
47
- "@contentful/field-editor-reference": "^5.22.6",
47
+ "@contentful/field-editor-reference": "^5.23.0",
48
48
  "@contentful/field-editor-shared": "^1.4.6",
49
49
  "@contentful/rich-text-plain-text-renderer": "^16.0.4",
50
50
  "@contentful/rich-text-types": "16.3.0",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "registry": "https://npm.pkg.github.com/"
88
88
  },
89
- "gitHead": "07c583c9bd150caf992c18cdbccc536e8f3a6467"
89
+ "gitHead": "7018fb86df27fcb2e0d4bdb475549367fe6ee87d"
90
90
  }