@contentful/field-editor-rich-text 3.16.6 → 3.16.8
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/plugins/Hyperlink/components/EntityHyperlink.js +3 -9
- package/dist/cjs/plugins/Hyperlink/components/ResourceHyperlink.js +3 -9
- package/dist/cjs/plugins/Hyperlink/components/UrlHyperlink.js +2 -8
- package/dist/cjs/plugins/Hyperlink/components/useHyperlinkCommon.js +26 -0
- package/dist/cjs/plugins/Table/onKeyDownTable.js +3 -2
- package/dist/esm/plugins/Hyperlink/components/EntityHyperlink.js +3 -9
- package/dist/esm/plugins/Hyperlink/components/ResourceHyperlink.js +3 -9
- package/dist/esm/plugins/Hyperlink/components/UrlHyperlink.js +2 -8
- package/dist/esm/plugins/Hyperlink/components/useHyperlinkCommon.js +16 -0
- package/dist/esm/plugins/Table/onKeyDownTable.js +3 -2
- package/dist/types/plugins/Hyperlink/components/UrlHyperlink.d.ts +2 -2
- package/dist/types/plugins/Hyperlink/components/useHyperlinkCommon.d.ts +7 -0
- package/package.json +2 -2
|
@@ -10,14 +10,12 @@ Object.defineProperty(exports, "EntityHyperlink", {
|
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
|
-
const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
|
|
14
|
-
const _queries = require("../../../internal/queries");
|
|
15
|
-
const _SdkProvider = require("../../../SdkProvider");
|
|
16
13
|
const _linkstracking = require("../../links-tracking");
|
|
17
14
|
const _useEntityInfo = require("../useEntityInfo");
|
|
18
15
|
const _linkHandlers = require("./linkHandlers");
|
|
19
16
|
const _LinkPopover = require("./LinkPopover");
|
|
20
17
|
const _styles = require("./styles");
|
|
18
|
+
const _useHyperlinkCommon = require("./useHyperlinkCommon");
|
|
21
19
|
function _getRequireWildcardCache(nodeInterop) {
|
|
22
20
|
if (typeof WeakMap !== "function") return null;
|
|
23
21
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -60,13 +58,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
60
58
|
return newObj;
|
|
61
59
|
}
|
|
62
60
|
function EntityHyperlink(props) {
|
|
63
|
-
const editor = (0,
|
|
64
|
-
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
65
|
-
const focus = editor.selection?.focus;
|
|
66
|
-
const { target } = props.element.data;
|
|
61
|
+
const { editor, sdk, isLinkFocused, pathToElement } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
67
62
|
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
68
|
-
const
|
|
69
|
-
const isLinkFocused = pathToElement && focus && (0, _queries.isChildPath)(focus.path, pathToElement);
|
|
63
|
+
const { target } = props.element.data;
|
|
70
64
|
const tooltipContent = (0, _useEntityInfo.useEntityInfo)({
|
|
71
65
|
target,
|
|
72
66
|
sdk,
|
|
@@ -10,14 +10,12 @@ Object.defineProperty(exports, "ResourceHyperlink", {
|
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
|
-
const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
|
|
14
|
-
const _queries = require("../../../internal/queries");
|
|
15
|
-
const _SdkProvider = require("../../../SdkProvider");
|
|
16
13
|
const _linkstracking = require("../../links-tracking");
|
|
17
14
|
const _useResourceEntityInfo = require("../useResourceEntityInfo");
|
|
18
15
|
const _linkHandlers = require("./linkHandlers");
|
|
19
16
|
const _LinkPopover = require("./LinkPopover");
|
|
20
17
|
const _styles = require("./styles");
|
|
18
|
+
const _useHyperlinkCommon = require("./useHyperlinkCommon");
|
|
21
19
|
function _getRequireWildcardCache(nodeInterop) {
|
|
22
20
|
if (typeof WeakMap !== "function") return null;
|
|
23
21
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -60,13 +58,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
60
58
|
return newObj;
|
|
61
59
|
}
|
|
62
60
|
function ResourceHyperlink(props) {
|
|
63
|
-
const editor = (0,
|
|
64
|
-
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
65
|
-
const focus = editor.selection?.focus;
|
|
66
|
-
const { target } = props.element.data;
|
|
61
|
+
const { editor, sdk, isLinkFocused, pathToElement } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
67
62
|
const { onEntityFetchComplete } = (0, _linkstracking.useLinkTracking)();
|
|
68
|
-
const
|
|
69
|
-
const isLinkFocused = pathToElement && focus && (0, _queries.isChildPath)(focus.path, pathToElement);
|
|
63
|
+
const { target } = props.element.data;
|
|
70
64
|
const tooltipContent = (0, _useResourceEntityInfo.useResourceEntityInfo)({
|
|
71
65
|
target,
|
|
72
66
|
onEntityFetchComplete
|
|
@@ -10,12 +10,10 @@ Object.defineProperty(exports, "UrlHyperlink", {
|
|
|
10
10
|
});
|
|
11
11
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
|
-
const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
|
|
14
|
-
const _queries = require("../../../internal/queries");
|
|
15
|
-
const _SdkProvider = require("../../../SdkProvider");
|
|
16
13
|
const _linkHandlers = require("./linkHandlers");
|
|
17
14
|
const _LinkPopover = require("./LinkPopover");
|
|
18
15
|
const _styles = require("./styles");
|
|
16
|
+
const _useHyperlinkCommon = require("./useHyperlinkCommon");
|
|
19
17
|
function _getRequireWildcardCache(nodeInterop) {
|
|
20
18
|
if (typeof WeakMap !== "function") return null;
|
|
21
19
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -58,12 +56,8 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
58
56
|
return newObj;
|
|
59
57
|
}
|
|
60
58
|
function UrlHyperlink(props) {
|
|
61
|
-
const editor = (0,
|
|
62
|
-
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
63
|
-
const focus = editor.selection?.focus;
|
|
59
|
+
const { editor, sdk, isLinkFocused, pathToElement } = (0, _useHyperlinkCommon.useHyperlinkCommon)(props.element);
|
|
64
60
|
const uri = props.element.data?.uri;
|
|
65
|
-
const pathToElement = (0, _queries.findNodePath)(editor, props.element);
|
|
66
|
-
const isLinkFocused = pathToElement && focus && (0, _queries.isChildPath)(focus.path, pathToElement);
|
|
67
61
|
const popoverText = /*#__PURE__*/ _react.createElement(_f36components.TextLink, {
|
|
68
62
|
className: _styles.styles.openLink,
|
|
69
63
|
href: uri,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useHyperlinkCommon", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useHyperlinkCommon;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ContentfulEditorProvider = require("../../../ContentfulEditorProvider");
|
|
12
|
+
const _queries = require("../../../internal/queries");
|
|
13
|
+
const _SdkProvider = require("../../../SdkProvider");
|
|
14
|
+
function useHyperlinkCommon(element) {
|
|
15
|
+
const editor = (0, _ContentfulEditorProvider.useContentfulEditor)();
|
|
16
|
+
const sdk = (0, _SdkProvider.useSdkContext)();
|
|
17
|
+
const focus = editor.selection?.focus;
|
|
18
|
+
const pathToElement = (0, _queries.findNodePath)(editor, element);
|
|
19
|
+
const isLinkFocused = pathToElement && focus && (0, _queries.isChildPath)(focus.path, pathToElement);
|
|
20
|
+
return {
|
|
21
|
+
editor,
|
|
22
|
+
sdk,
|
|
23
|
+
isLinkFocused,
|
|
24
|
+
pathToElement
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -20,9 +20,10 @@ const onKeyDownTable = (editor, plugin)=>{
|
|
|
20
20
|
// This fixes `Cannot resolve a Slate point from DOM point:
|
|
21
21
|
// [object HTMLDivElement]` when typing while the cursor is before table
|
|
22
22
|
const windowSelection = window.getSelection();
|
|
23
|
-
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
// this attribute comes from `plugins/Table/components/Table.tsx`
|
|
25
|
+
if (windowSelection?.anchorNode?.attributes) {
|
|
24
26
|
// @ts-expect-error
|
|
25
|
-
// this attribute comes from `plugins/Table/components/Table.tsx`
|
|
26
27
|
const blockType = windowSelection.anchorNode.attributes?.['data-block-type']?.value;
|
|
27
28
|
const isBeforeTable = blockType === _richtexttypes.BLOCKS.TABLE;
|
|
28
29
|
if (isBeforeTable) {
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Text } from '@contentful/f36-components';
|
|
3
|
-
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
-
import { findNodePath, isChildPath } from '../../../internal/queries';
|
|
5
|
-
import { useSdkContext } from '../../../SdkProvider';
|
|
6
3
|
import { useLinkTracking } from '../../links-tracking';
|
|
7
4
|
import { useEntityInfo } from '../useEntityInfo';
|
|
8
5
|
import { handleEditLink, handleRemoveLink } from './linkHandlers';
|
|
9
6
|
import { LinkPopover } from './LinkPopover';
|
|
10
7
|
import { styles } from './styles';
|
|
8
|
+
import { useHyperlinkCommon } from './useHyperlinkCommon';
|
|
11
9
|
export function EntityHyperlink(props) {
|
|
12
|
-
const editor =
|
|
13
|
-
const sdk = useSdkContext();
|
|
14
|
-
const focus = editor.selection?.focus;
|
|
15
|
-
const { target } = props.element.data;
|
|
10
|
+
const { editor, sdk, isLinkFocused, pathToElement } = useHyperlinkCommon(props.element);
|
|
16
11
|
const { onEntityFetchComplete } = useLinkTracking();
|
|
17
|
-
const
|
|
18
|
-
const isLinkFocused = pathToElement && focus && isChildPath(focus.path, pathToElement);
|
|
12
|
+
const { target } = props.element.data;
|
|
19
13
|
const tooltipContent = useEntityInfo({
|
|
20
14
|
target,
|
|
21
15
|
sdk,
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Text } from '@contentful/f36-components';
|
|
3
|
-
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
-
import { findNodePath, isChildPath } from '../../../internal/queries';
|
|
5
|
-
import { useSdkContext } from '../../../SdkProvider';
|
|
6
3
|
import { useLinkTracking } from '../../links-tracking';
|
|
7
4
|
import { useResourceEntityInfo } from '../useResourceEntityInfo';
|
|
8
5
|
import { handleEditLink, handleRemoveLink } from './linkHandlers';
|
|
9
6
|
import { LinkPopover } from './LinkPopover';
|
|
10
7
|
import { styles } from './styles';
|
|
8
|
+
import { useHyperlinkCommon } from './useHyperlinkCommon';
|
|
11
9
|
export function ResourceHyperlink(props) {
|
|
12
|
-
const editor =
|
|
13
|
-
const sdk = useSdkContext();
|
|
14
|
-
const focus = editor.selection?.focus;
|
|
15
|
-
const { target } = props.element.data;
|
|
10
|
+
const { editor, sdk, isLinkFocused, pathToElement } = useHyperlinkCommon(props.element);
|
|
16
11
|
const { onEntityFetchComplete } = useLinkTracking();
|
|
17
|
-
const
|
|
18
|
-
const isLinkFocused = pathToElement && focus && isChildPath(focus.path, pathToElement);
|
|
12
|
+
const { target } = props.element.data;
|
|
19
13
|
const tooltipContent = useResourceEntityInfo({
|
|
20
14
|
target,
|
|
21
15
|
onEntityFetchComplete
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { TextLink } from '@contentful/f36-components';
|
|
3
|
-
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
4
|
-
import { findNodePath, isChildPath } from '../../../internal/queries';
|
|
5
|
-
import { useSdkContext } from '../../../SdkProvider';
|
|
6
3
|
import { handleCopyLink, handleEditLink, handleRemoveLink } from './linkHandlers';
|
|
7
4
|
import { LinkPopover } from './LinkPopover';
|
|
8
5
|
import { styles } from './styles';
|
|
6
|
+
import { useHyperlinkCommon } from './useHyperlinkCommon';
|
|
9
7
|
export function UrlHyperlink(props) {
|
|
10
|
-
const editor =
|
|
11
|
-
const sdk = useSdkContext();
|
|
12
|
-
const focus = editor.selection?.focus;
|
|
8
|
+
const { editor, sdk, isLinkFocused, pathToElement } = useHyperlinkCommon(props.element);
|
|
13
9
|
const uri = props.element.data?.uri;
|
|
14
|
-
const pathToElement = findNodePath(editor, props.element);
|
|
15
|
-
const isLinkFocused = pathToElement && focus && isChildPath(focus.path, pathToElement);
|
|
16
10
|
const popoverText = /*#__PURE__*/ React.createElement(TextLink, {
|
|
17
11
|
className: styles.openLink,
|
|
18
12
|
href: uri,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useContentfulEditor } from '../../../ContentfulEditorProvider';
|
|
2
|
+
import { findNodePath, isChildPath } from '../../../internal/queries';
|
|
3
|
+
import { useSdkContext } from '../../../SdkProvider';
|
|
4
|
+
export function useHyperlinkCommon(element) {
|
|
5
|
+
const editor = useContentfulEditor();
|
|
6
|
+
const sdk = useSdkContext();
|
|
7
|
+
const focus = editor.selection?.focus;
|
|
8
|
+
const pathToElement = findNodePath(editor, element);
|
|
9
|
+
const isLinkFocused = pathToElement && focus && isChildPath(focus.path, pathToElement);
|
|
10
|
+
return {
|
|
11
|
+
editor,
|
|
12
|
+
sdk,
|
|
13
|
+
isLinkFocused,
|
|
14
|
+
pathToElement
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -10,9 +10,10 @@ export const onKeyDownTable = (editor, plugin)=>{
|
|
|
10
10
|
// This fixes `Cannot resolve a Slate point from DOM point:
|
|
11
11
|
// [object HTMLDivElement]` when typing while the cursor is before table
|
|
12
12
|
const windowSelection = window.getSelection();
|
|
13
|
-
|
|
13
|
+
// @ts-expect-error
|
|
14
|
+
// this attribute comes from `plugins/Table/components/Table.tsx`
|
|
15
|
+
if (windowSelection?.anchorNode?.attributes) {
|
|
14
16
|
// @ts-expect-error
|
|
15
|
-
// this attribute comes from `plugins/Table/components/Table.tsx`
|
|
16
17
|
const blockType = windowSelection.anchorNode.attributes?.['data-block-type']?.value;
|
|
17
18
|
const isBeforeTable = blockType === BLOCKS.TABLE;
|
|
18
19
|
if (isBeforeTable) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Link } from '@contentful/app-sdk';
|
|
3
3
|
import { Element, RenderElementProps } from '../../../internal/types';
|
|
4
|
-
type
|
|
4
|
+
type UrlHyperlinkProps = {
|
|
5
5
|
element: Element & {
|
|
6
6
|
data: {
|
|
7
7
|
uri?: string;
|
|
@@ -18,5 +18,5 @@ type HyperlinkElementProps = {
|
|
|
18
18
|
onEntityFetchComplete?: VoidFunction;
|
|
19
19
|
children: Pick<RenderElementProps, 'children'>;
|
|
20
20
|
};
|
|
21
|
-
export declare function UrlHyperlink(props:
|
|
21
|
+
export declare function UrlHyperlink(props: UrlHyperlinkProps): React.JSX.Element;
|
|
22
22
|
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FieldAppSDK } from '@contentful/app-sdk';
|
|
2
|
+
export declare function useHyperlinkCommon(element: any): {
|
|
3
|
+
editor: import("../../../internal").PlateEditor;
|
|
4
|
+
sdk: FieldAppSDK;
|
|
5
|
+
isLinkFocused: boolean | undefined;
|
|
6
|
+
pathToElement: import("slate").Path | undefined;
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-rich-text",
|
|
3
|
-
"version": "3.16.
|
|
3
|
+
"version": "3.16.8",
|
|
4
4
|
"source": "./src/index.tsx",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"prism-react-renderer": "2.0.5",
|
|
84
84
|
"react": ">=16.14.0"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "d29915303ea8b42cde8c60b8e1df50686d4768ae"
|
|
87
87
|
}
|