@atlaskit/editor-plugin-card 2.3.2 → 2.3.4
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/CHANGELOG.md +16 -0
- package/dist/cjs/nodeviews/genericCard.js +1 -1
- package/dist/cjs/nodeviews/inlineCard.js +101 -16
- package/dist/cjs/nodeviews/inlineCardWithAwareness.js +40 -96
- package/dist/cjs/toolbar.js +14 -14
- package/dist/cjs/ui/AwarenessWrapper/index.js +2 -11
- package/dist/cjs/utils.js +15 -2
- package/dist/es2019/nodeviews/genericCard.js +2 -2
- package/dist/es2019/nodeviews/inlineCard.js +100 -17
- package/dist/es2019/nodeviews/inlineCardWithAwareness.js +39 -97
- package/dist/es2019/toolbar.js +15 -15
- package/dist/es2019/ui/AwarenessWrapper/index.js +2 -11
- package/dist/es2019/utils.js +15 -2
- package/dist/esm/nodeviews/genericCard.js +2 -2
- package/dist/esm/nodeviews/inlineCard.js +98 -17
- package/dist/esm/nodeviews/inlineCardWithAwareness.js +41 -97
- package/dist/esm/toolbar.js +15 -15
- package/dist/esm/ui/AwarenessWrapper/index.js +2 -11
- package/dist/esm/utils.js +15 -2
- package/dist/types/nodeviews/genericCard.d.ts +6 -4
- package/dist/types/nodeviews/inlineCard.d.ts +3 -7
- package/dist/types/nodeviews/inlineCardWithAwareness.d.ts +6 -1
- package/dist/types/ui/AwarenessWrapper/index.d.ts +4 -3
- package/dist/types/utils.d.ts +6 -0
- package/dist/types-ts4.5/nodeviews/genericCard.d.ts +6 -4
- package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +3 -7
- package/dist/types-ts4.5/nodeviews/inlineCardWithAwareness.d.ts +6 -1
- package/dist/types-ts4.5/ui/AwarenessWrapper/index.d.ts +4 -3
- package/dist/types-ts4.5/utils.d.ts +6 -0
- package/package.json +3 -3
|
@@ -1,11 +1,92 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import React, { memo, useCallback, useMemo } from 'react';
|
|
3
|
+
import rafSchedule from 'raf-schd';
|
|
4
|
+
import { findOverflowScrollParent, UnsupportedInline } from '@atlaskit/editor-common/ui';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
+
import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
7
|
+
import { registerCard } from '../pm-plugins/actions';
|
|
8
|
+
import OverlayWrapper from '../ui/ConfigureOverlay';
|
|
9
|
+
import { getAwarenessProps } from '../utils';
|
|
6
10
|
import { Card } from './genericCard';
|
|
7
11
|
import { InlineCardWithAwareness } from './inlineCardWithAwareness';
|
|
12
|
+
export const InlineCard = /*#__PURE__*/memo(({
|
|
13
|
+
node,
|
|
14
|
+
cardContext,
|
|
15
|
+
actionOptions,
|
|
16
|
+
showServerActions,
|
|
17
|
+
useAlternativePreloader,
|
|
18
|
+
view,
|
|
19
|
+
getPos,
|
|
20
|
+
onClick,
|
|
21
|
+
onResolve: onRes,
|
|
22
|
+
isHovered
|
|
23
|
+
}) => {
|
|
24
|
+
const {
|
|
25
|
+
url,
|
|
26
|
+
data
|
|
27
|
+
} = node.attrs;
|
|
28
|
+
const scrollContainer = useMemo(() => findOverflowScrollParent(view.dom) || undefined, [view.dom]);
|
|
29
|
+
const onResolve = useCallback(data => {
|
|
30
|
+
if (!getPos || typeof getPos === 'boolean') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const {
|
|
34
|
+
title,
|
|
35
|
+
url
|
|
36
|
+
} = data;
|
|
37
|
+
// don't dispatch immediately since we might be in the middle of
|
|
38
|
+
// rendering a nodeview
|
|
39
|
+
rafSchedule(() => {
|
|
40
|
+
// prosemirror-bump-fix
|
|
41
|
+
const pos = getPos();
|
|
42
|
+
if (typeof pos !== 'number') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const tr = view.state.tr;
|
|
46
|
+
registerCard({
|
|
47
|
+
title,
|
|
48
|
+
url,
|
|
49
|
+
pos
|
|
50
|
+
})(tr);
|
|
51
|
+
onRes === null || onRes === void 0 ? void 0 : onRes(tr, title);
|
|
52
|
+
view.dispatch(tr);
|
|
53
|
+
})();
|
|
54
|
+
}, [getPos, view, onRes]);
|
|
55
|
+
const onError = useCallback(data => {
|
|
56
|
+
const {
|
|
57
|
+
url,
|
|
58
|
+
err
|
|
59
|
+
} = data;
|
|
60
|
+
if (err) {
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
onResolve({
|
|
64
|
+
url
|
|
65
|
+
});
|
|
66
|
+
}, [onResolve]);
|
|
67
|
+
const card = useMemo(() => /*#__PURE__*/React.createElement(SmartCard, {
|
|
68
|
+
key: url,
|
|
69
|
+
url: url,
|
|
70
|
+
data: data,
|
|
71
|
+
appearance: "inline",
|
|
72
|
+
onClick: onClick,
|
|
73
|
+
container: scrollContainer,
|
|
74
|
+
onResolve: onResolve,
|
|
75
|
+
onError: onError,
|
|
76
|
+
inlinePreloaderStyle: useAlternativePreloader ? 'on-right-without-skeleton' : undefined,
|
|
77
|
+
actionOptions: actionOptions,
|
|
78
|
+
showServerActions: showServerActions,
|
|
79
|
+
isHovered: isHovered
|
|
80
|
+
}), [data, isHovered, onError, onResolve, scrollContainer, url, useAlternativePreloader, actionOptions, showServerActions, onClick]);
|
|
81
|
+
|
|
82
|
+
// [WS-2307]: we only render card wrapped into a Provider when the value is ready,
|
|
83
|
+
// otherwise if we got data, we can render the card directly since it doesn't need the Provider
|
|
84
|
+
return cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
|
|
85
|
+
value: cardContext.value
|
|
86
|
+
}, card) : data ? card : null;
|
|
87
|
+
});
|
|
8
88
|
const WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
|
|
89
|
+
const WrappedInlineCard = Card(InlineCard, UnsupportedInline);
|
|
9
90
|
export function InlineCardNodeView(props) {
|
|
10
91
|
const {
|
|
11
92
|
useAlternativePreloader,
|
|
@@ -20,6 +101,20 @@ export function InlineCardNodeView(props) {
|
|
|
20
101
|
pluginInjectionApi,
|
|
21
102
|
onClickCallback
|
|
22
103
|
} = props;
|
|
104
|
+
if (fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
105
|
+
return /*#__PURE__*/React.createElement(OverlayWrapper, {
|
|
106
|
+
targetElementPos: getPos(),
|
|
107
|
+
view: view
|
|
108
|
+
}, /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
109
|
+
node: node,
|
|
110
|
+
view: view,
|
|
111
|
+
getPos: getPos,
|
|
112
|
+
actionOptions: actionOptions,
|
|
113
|
+
showServerActions: showServerActions,
|
|
114
|
+
useAlternativePreloader: useAlternativePreloader,
|
|
115
|
+
onClickCallback: onClickCallback
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
23
118
|
return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
|
|
24
119
|
node: node,
|
|
25
120
|
view: view,
|
|
@@ -30,16 +125,4 @@ export function InlineCardNodeView(props) {
|
|
|
30
125
|
pluginInjectionApi: pluginInjectionApi,
|
|
31
126
|
onClickCallback: onClickCallback
|
|
32
127
|
}, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards)));
|
|
33
|
-
}
|
|
34
|
-
const getAwarenessProps = (editorState, getPos, allowEmbeds, allowBlockCards) => {
|
|
35
|
-
var _editorState$selectio, _editorState$selectio2, _editorState$selectio3;
|
|
36
|
-
const linkPosition = getPos && typeof getPos() === 'number' ? getPos() : undefined;
|
|
37
|
-
const canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? isEmbedSupportedAtPosition(linkPosition, editorState, 'inline') : false;
|
|
38
|
-
const canBeUpgradedToBlock = !!linkPosition && allowBlockCards ? isBlockSupportedAtPosition(linkPosition, editorState, 'inline') : false;
|
|
39
|
-
const isSelected = editorState.selection instanceof NodeSelection && ((_editorState$selectio = editorState.selection) === null || _editorState$selectio === void 0 ? void 0 : (_editorState$selectio2 = _editorState$selectio.node) === null || _editorState$selectio2 === void 0 ? void 0 : _editorState$selectio2.type) === editorState.schema.nodes.inlineCard && ((_editorState$selectio3 = editorState.selection) === null || _editorState$selectio3 === void 0 ? void 0 : _editorState$selectio3.from) === getPos();
|
|
40
|
-
return {
|
|
41
|
-
isPulseEnabled: canBeUpgradedToEmbed,
|
|
42
|
-
isOverlayEnabled: canBeUpgradedToEmbed || canBeUpgradedToBlock,
|
|
43
|
-
isSelected
|
|
44
|
-
};
|
|
45
|
-
};
|
|
128
|
+
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import React, { memo, useCallback, useMemo, useState } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
4
|
-
import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
5
|
-
import { registerCard, registerRemoveOverlay } from '../pm-plugins/actions';
|
|
2
|
+
import { registerRemoveOverlay } from '../pm-plugins/actions';
|
|
6
3
|
import { AwarenessWrapper } from '../ui/AwarenessWrapper';
|
|
7
|
-
|
|
4
|
+
import { InlineCard } from './inlineCard';
|
|
5
|
+
export const InlineCardWithAwareness = /*#__PURE__*/memo(({
|
|
8
6
|
node,
|
|
9
7
|
cardContext,
|
|
10
8
|
actionOptions,
|
|
@@ -12,63 +10,21 @@ const InlineCard = ({
|
|
|
12
10
|
useAlternativePreloader,
|
|
13
11
|
view,
|
|
14
12
|
getPos,
|
|
15
|
-
isOverlayEnabled,
|
|
16
|
-
isPulseEnabled,
|
|
17
13
|
pluginInjectionApi,
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
onClick,
|
|
15
|
+
isPulseEnabled,
|
|
16
|
+
isOverlayEnabled,
|
|
17
|
+
isSelected
|
|
20
18
|
}) => {
|
|
21
|
-
const {
|
|
22
|
-
url,
|
|
23
|
-
data
|
|
24
|
-
} = node.attrs;
|
|
25
19
|
const [isHovered, setIsHovered] = useState(false);
|
|
26
20
|
const [isInserted, setIsInserted] = useState(false);
|
|
27
21
|
const [isResolvedViewRendered, setIsResolvedViewRendered] = useState(false);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
if (!getPos || typeof getPos === 'boolean') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const {
|
|
34
|
-
title,
|
|
35
|
-
url
|
|
36
|
-
} = data;
|
|
37
|
-
// don't dispatch immediately since we might be in the middle of
|
|
38
|
-
// rendering a nodeview
|
|
39
|
-
rafSchedule(() => {
|
|
40
|
-
// prosemirror-bump-fix
|
|
41
|
-
const pos = getPos();
|
|
42
|
-
if (typeof pos !== 'number') {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const tr = view.state.tr;
|
|
46
|
-
registerCard({
|
|
47
|
-
title,
|
|
48
|
-
url,
|
|
49
|
-
pos
|
|
50
|
-
})(tr);
|
|
51
|
-
registerRemoveOverlay(() => setIsInserted(false))(tr);
|
|
52
|
-
view.dispatch(tr);
|
|
53
|
-
})();
|
|
22
|
+
const onResolve = useCallback((tr, title) => {
|
|
23
|
+
registerRemoveOverlay(() => setIsInserted(false))(tr);
|
|
54
24
|
if (title) {
|
|
55
25
|
setIsResolvedViewRendered(true);
|
|
56
26
|
}
|
|
57
|
-
}, [
|
|
58
|
-
const onError = useCallback(data => {
|
|
59
|
-
const {
|
|
60
|
-
url,
|
|
61
|
-
err
|
|
62
|
-
} = data;
|
|
63
|
-
if (err) {
|
|
64
|
-
throw err;
|
|
65
|
-
}
|
|
66
|
-
onResolve({
|
|
67
|
-
url
|
|
68
|
-
});
|
|
69
|
-
}, [onResolve]);
|
|
70
|
-
|
|
71
|
-
// Begin Upgrade Awareness related code
|
|
27
|
+
}, []);
|
|
72
28
|
const markMostRecentlyInsertedLink = useCallback(isLinkMostRecentlyInserted => {
|
|
73
29
|
if (isOverlayEnabled) {
|
|
74
30
|
setIsInserted(isLinkMostRecentlyInserted);
|
|
@@ -79,49 +35,35 @@ const InlineCard = ({
|
|
|
79
35
|
setIsHovered(isHovered);
|
|
80
36
|
}
|
|
81
37
|
}, [isOverlayEnabled]);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
data: data,
|
|
88
|
-
appearance: "inline",
|
|
89
|
-
onClick: onClick,
|
|
90
|
-
container: scrollContainer,
|
|
91
|
-
onResolve: onResolve,
|
|
92
|
-
onError: onError,
|
|
93
|
-
inlinePreloaderStyle: useAlternativePreloader ? 'on-right-without-skeleton' : undefined,
|
|
38
|
+
const innerCard = useMemo(() => /*#__PURE__*/React.createElement(InlineCard, {
|
|
39
|
+
node: node,
|
|
40
|
+
view: view,
|
|
41
|
+
getPos: getPos,
|
|
42
|
+
useAlternativePreloader: useAlternativePreloader,
|
|
94
43
|
actionOptions: actionOptions,
|
|
95
44
|
showServerActions: showServerActions,
|
|
45
|
+
onResolve: onResolve,
|
|
46
|
+
onClick: onClick,
|
|
47
|
+
cardContext: cardContext,
|
|
96
48
|
isHovered: isHovered
|
|
97
|
-
}), [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}, innerCard);
|
|
119
|
-
}, [cardContext, getPos, innerCard, isHovered, isInserted, isOverlayEnabled, isPulseEnabled, isResolvedViewRendered, isSelected, markMostRecentlyInsertedLink, pluginInjectionApi, setOverlayHoveredStyles, url, view]);
|
|
120
|
-
|
|
121
|
-
// [WS-2307]: we only render card wrapped into a Provider when the value is ready,
|
|
122
|
-
// otherwise if we got data, we can render the card directly since it doesn't need the Provider
|
|
123
|
-
return cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
|
|
124
|
-
value: cardContext.value
|
|
125
|
-
}, card) : data ? card : null;
|
|
126
|
-
};
|
|
127
|
-
export const InlineCardWithAwareness = /*#__PURE__*/memo(InlineCard);
|
|
49
|
+
}), [actionOptions, cardContext, getPos, isHovered, node, onClick, onResolve, showServerActions, useAlternativePreloader, view]);
|
|
50
|
+
return isOverlayEnabled || isPulseEnabled ? /*#__PURE__*/React.createElement(AwarenessWrapper, {
|
|
51
|
+
isOverlayEnabled: isOverlayEnabled,
|
|
52
|
+
isPulseEnabled: isPulseEnabled,
|
|
53
|
+
cardContext: cardContext,
|
|
54
|
+
getPos: getPos,
|
|
55
|
+
isHovered: isHovered,
|
|
56
|
+
isInserted: isInserted,
|
|
57
|
+
url: node.attrs.url,
|
|
58
|
+
isSelected: isSelected,
|
|
59
|
+
isResolvedViewRendered: isResolvedViewRendered,
|
|
60
|
+
markMostRecentlyInsertedLink: markMostRecentlyInsertedLink,
|
|
61
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
62
|
+
setOverlayHoveredStyles: setOverlayHoveredStyles
|
|
63
|
+
}, innerCard) :
|
|
64
|
+
/*#__PURE__*/
|
|
65
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
66
|
+
React.createElement("span", {
|
|
67
|
+
className: "card"
|
|
68
|
+
}, innerCard);
|
|
69
|
+
});
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -13,8 +13,8 @@ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
|
13
13
|
import CogIcon from '@atlaskit/icon/glyph/editor/settings';
|
|
14
14
|
import UnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
|
|
15
15
|
import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
16
|
-
import {
|
|
17
|
-
import { changeSelectedCardToText } from '
|
|
16
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
17
|
+
import { changeSelectedCardToText } from './pm-plugins/doc';
|
|
18
18
|
import { pluginKey } from './pm-plugins/main';
|
|
19
19
|
import { DatasourceAppearanceButton } from './ui/DatasourceAppearanceButton';
|
|
20
20
|
import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
|
|
@@ -200,7 +200,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
|
|
|
200
200
|
const {
|
|
201
201
|
hoverDecoration
|
|
202
202
|
} = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {};
|
|
203
|
-
const isDatasource =
|
|
203
|
+
const isDatasource = fg('platform.linking-platform.editor-datasource-typeguards') ? isDatasourceNode(node) : currentAppearance === 'block' && (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
|
|
204
204
|
const shouldRenderDatasourceToolbar = isDatasource &&
|
|
205
205
|
// not showing toolbar in mobile for now since not sure what our plans are for it
|
|
206
206
|
platform !== 'mobile' && cardOptions.allowDatasource && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : (_node$attrs2$datasour = _node$attrs2.datasource) === null || _node$attrs2$datasour === void 0 ? void 0 : _node$attrs2$datasour.id);
|
|
@@ -220,7 +220,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
|
|
|
220
220
|
const {
|
|
221
221
|
inlineCard
|
|
222
222
|
} = state.schema.nodes;
|
|
223
|
-
const isEditDropdownEnabled =
|
|
223
|
+
const isEditDropdownEnabled = platform !== 'mobile' && cardOptions.allowDatasource && fg('platform.linking-platform.enable-datasource-edit-dropdown-toolbar');
|
|
224
224
|
const editItems = isEditDropdownEnabled ? [{
|
|
225
225
|
type: 'custom',
|
|
226
226
|
fallback: [],
|
|
@@ -297,7 +297,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
|
|
|
297
297
|
// This code will be executed only for appearances such as "inline", "block" & "embed"
|
|
298
298
|
// For url appearance, please see HyperlinkToolbarAppearanceProps
|
|
299
299
|
if (currentAppearance) {
|
|
300
|
-
const showDatasourceAppearance =
|
|
300
|
+
const showDatasourceAppearance = allowDatasource && url && fg('platform.linking-platform.enable-datasource-appearance-toolbar');
|
|
301
301
|
toolbarItems.unshift(...getToolbarViewedItem(url, currentAppearance), {
|
|
302
302
|
type: 'custom',
|
|
303
303
|
fallback: [],
|
|
@@ -329,7 +329,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
|
|
|
329
329
|
type: 'separator'
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
|
-
const shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource && !
|
|
332
|
+
const shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource && !fg('platform.linking-platform.enable-datasource-edit-dropdown-toolbar');
|
|
333
333
|
if (shouldShowDatasourceEditButton) {
|
|
334
334
|
toolbarItems.unshift({
|
|
335
335
|
type: 'custom',
|
|
@@ -364,8 +364,8 @@ export const getHyperlinkToolbarSettingsButton = (intl, editorAnalyticsApi, user
|
|
|
364
364
|
type: 'button',
|
|
365
365
|
icon: CogIcon,
|
|
366
366
|
title: intl.formatMessage(linkToolbarMessages.settingsLink),
|
|
367
|
-
onClick:
|
|
368
|
-
href:
|
|
367
|
+
onClick: fg('platform.editor.card.inject-settings-button') ? openLinkSettings(editorAnalyticsApi, userPreferencesLink) : openLinkSettings(editorAnalyticsApi, undefined),
|
|
368
|
+
href: fg('platform.editor.card.inject-settings-button') ? userPreferencesLink || getLinkPreferencesURLFromENV() : getLinkPreferencesURLFromENV(),
|
|
369
369
|
target: '_blank'
|
|
370
370
|
};
|
|
371
371
|
};
|
|
@@ -375,7 +375,7 @@ export const getSettingsButton = (intl, editorAnalyticsApi, userPreferencesLink)
|
|
|
375
375
|
type: 'button',
|
|
376
376
|
icon: CogIcon,
|
|
377
377
|
title: intl.formatMessage(linkToolbarMessages.settingsLink),
|
|
378
|
-
onClick:
|
|
378
|
+
onClick: fg('platform.editor.card.inject-settings-button') ? openLinkSettings(editorAnalyticsApi, userPreferencesLink) : openLinkSettings(editorAnalyticsApi, undefined)
|
|
379
379
|
};
|
|
380
380
|
};
|
|
381
381
|
export const getSettingsButtonGroup = (intl, editorAnalyticsApi, userPreferencesLink) => {
|
|
@@ -386,7 +386,7 @@ export const getSettingsButtonGroup = (intl, editorAnalyticsApi, userPreferences
|
|
|
386
386
|
const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId, state, cardOptions, currentAppearance, platform) => {
|
|
387
387
|
var _node$attrs3;
|
|
388
388
|
const toolbarItems = [];
|
|
389
|
-
if (isDatasourceConfigEditable(datasourceId) && !
|
|
389
|
+
if (isDatasourceConfigEditable(datasourceId) && !fg('platform.linking-platform.enable-datasource-edit-dropdown-toolbar')) {
|
|
390
390
|
toolbarItems.push({
|
|
391
391
|
id: 'editor.edit.datasource',
|
|
392
392
|
type: 'button',
|
|
@@ -407,12 +407,12 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
|
|
|
407
407
|
}
|
|
408
408
|
if (
|
|
409
409
|
// FF that controls visibily of the additional toolbar buttons
|
|
410
|
-
!
|
|
410
|
+
!fg('platform.linking-platform.enable-datasource-appearance-toolbar')) {
|
|
411
411
|
return false;
|
|
412
412
|
}
|
|
413
413
|
|
|
414
414
|
// FF to enable additional toolbar buttons based on if the datasource is configurable or not
|
|
415
|
-
return
|
|
415
|
+
return fg('platform.linking-platform.datasource-enable-toolbar-buttons-for-all-datasources') ? true : !isDatasourceConfigEditable(datasourceId);
|
|
416
416
|
};
|
|
417
417
|
if (canShowAppearanceSwitch()) {
|
|
418
418
|
const {
|
|
@@ -458,7 +458,7 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
|
|
|
458
458
|
type: 'separator'
|
|
459
459
|
});
|
|
460
460
|
}
|
|
461
|
-
if (
|
|
461
|
+
if (fg('platform.linking-platform.enable-datasource-edit-dropdown-toolbar')) {
|
|
462
462
|
toolbarItems.push({
|
|
463
463
|
type: 'custom',
|
|
464
464
|
fallback: [],
|
|
@@ -517,7 +517,7 @@ export const shouldRenderToolbarPulse = (embedEnabled, appearance, status, isDis
|
|
|
517
517
|
};
|
|
518
518
|
export const getStartingToolbarItems = (options, api) => {
|
|
519
519
|
return (intl, link, providerFactory, onEditLink, metadata) => {
|
|
520
|
-
const isEditDropdownEnabled =
|
|
520
|
+
const isEditDropdownEnabled = options.platform !== 'mobile' && options.allowDatasource && fg('platform.linking-platform.enable-datasource-edit-dropdown-toolbar');
|
|
521
521
|
const editLinkItem = isEditDropdownEnabled ? [{
|
|
522
522
|
type: 'custom',
|
|
523
523
|
fallback: [],
|
|
@@ -580,7 +580,7 @@ export const getStartingToolbarItems = (options, api) => {
|
|
|
580
580
|
};
|
|
581
581
|
};
|
|
582
582
|
export const getEndingToolbarItems = (options, api) => (intl, link) => {
|
|
583
|
-
if (
|
|
583
|
+
if (fg('platform.editor.card.inject-settings-button')) {
|
|
584
584
|
/**
|
|
585
585
|
* Require either provider to be supplied (controls link preferences)
|
|
586
586
|
* Or explicit user preferences config in order to enable button
|
|
@@ -4,11 +4,9 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
|
4
4
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
5
5
|
import { css, jsx } from '@emotion/react';
|
|
6
6
|
import { AnalyticsContext } from '@atlaskit/analytics-next';
|
|
7
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
8
7
|
import useLinkUpgradeDiscoverability from '../../common/hooks/useLinkUpgradeDiscoverability';
|
|
9
8
|
import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR, markLocalStorageKeyDiscovered, ONE_DAY_IN_MILLISECONDS } from '../../common/local-storage';
|
|
10
9
|
import { getResolvedAttributesFromStore } from '../../utils';
|
|
11
|
-
import OverlayWrapper from '../ConfigureOverlay';
|
|
12
10
|
import InlineCardOverlay from '../InlineCardOverlay';
|
|
13
11
|
import { DiscoveryPulse } from '../Pulse';
|
|
14
12
|
// editor adds a standard line-height that is bigger than an inline smart link
|
|
@@ -31,8 +29,7 @@ export const AwarenessWrapper = ({
|
|
|
31
29
|
markMostRecentlyInsertedLink,
|
|
32
30
|
pluginInjectionApi,
|
|
33
31
|
setOverlayHoveredStyles,
|
|
34
|
-
url
|
|
35
|
-
view
|
|
32
|
+
url
|
|
36
33
|
}) => {
|
|
37
34
|
var _cardContext$value2;
|
|
38
35
|
const [isHovered, setIsHovered] = useState(false);
|
|
@@ -72,12 +69,6 @@ export const AwarenessWrapper = ({
|
|
|
72
69
|
setOverlayHoveredStyles(isHovered);
|
|
73
70
|
}, [setOverlayHoveredStyles]);
|
|
74
71
|
const cardWithOverlay = useMemo(() => {
|
|
75
|
-
if (getBooleanFF('platform.linking-platform.smart-links-in-live-pages')) {
|
|
76
|
-
return jsx(OverlayWrapper, {
|
|
77
|
-
targetElementPos: linkPosition,
|
|
78
|
-
view: view
|
|
79
|
-
}, children);
|
|
80
|
-
}
|
|
81
72
|
if (shouldShowLinkOverlay) {
|
|
82
73
|
return jsx(InlineCardOverlay, {
|
|
83
74
|
isSelected: isSelected,
|
|
@@ -88,7 +79,7 @@ export const AwarenessWrapper = ({
|
|
|
88
79
|
}, children);
|
|
89
80
|
}
|
|
90
81
|
return children;
|
|
91
|
-
}, [shouldShowLinkOverlay, children, isSelected, isResolvedViewRendered, isInserted, isHovered, url,
|
|
82
|
+
}, [shouldShowLinkOverlay, children, isSelected, isResolvedViewRendered, isInserted, isHovered, url, handleOverlayChange]);
|
|
92
83
|
return useMemo(() => {
|
|
93
84
|
var _cardContext$value;
|
|
94
85
|
return (
|
package/dist/es2019/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
|
2
2
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { getResolvedAttributes } from '@atlaskit/link-analytics/resolved-attributes';
|
|
4
4
|
import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, CONFLUENCE_SEARCH_DATASOURCE_ID, JIRA_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource';
|
|
5
|
-
import {
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
6
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
7
7
|
export const appearanceForNodeType = spec => {
|
|
8
8
|
if (spec.name === 'inlineCard') {
|
|
@@ -68,7 +68,7 @@ export const getResolvedAttributesFromStore = (url, display, store) => {
|
|
|
68
68
|
};
|
|
69
69
|
export const isDatasourceConfigEditable = datasourceId => {
|
|
70
70
|
const datasourcesWithConfigModal = [JIRA_LIST_OF_LINKS_DATASOURCE_ID, ASSETS_LIST_OF_LINKS_DATASOURCE_ID];
|
|
71
|
-
if (
|
|
71
|
+
if (fg('platform.linking-platform.datasource.enable-confluence-search-modal')) {
|
|
72
72
|
datasourcesWithConfigModal.push(CONFLUENCE_SEARCH_DATASOURCE_ID);
|
|
73
73
|
}
|
|
74
74
|
return datasourcesWithConfigModal.includes(datasourceId);
|
|
@@ -118,4 +118,17 @@ export const focusEditorView = editorView => {
|
|
|
118
118
|
if (!editorView.hasFocus()) {
|
|
119
119
|
editorView.focus();
|
|
120
120
|
}
|
|
121
|
+
};
|
|
122
|
+
export const getAwarenessProps = (editorState, getPos, allowEmbeds, allowBlockCards) => {
|
|
123
|
+
var _editorState$selectio, _editorState$selectio2, _editorState$selectio3;
|
|
124
|
+
const getPosFunction = typeof getPos !== 'boolean' ? getPos : undefined;
|
|
125
|
+
const linkPosition = getPosFunction === null || getPosFunction === void 0 ? void 0 : getPosFunction();
|
|
126
|
+
const canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? isEmbedSupportedAtPosition(linkPosition, editorState, 'inline') : false;
|
|
127
|
+
const canBeUpgradedToBlock = !!linkPosition && allowBlockCards ? isBlockSupportedAtPosition(linkPosition, editorState, 'inline') : false;
|
|
128
|
+
const isSelected = editorState.selection instanceof NodeSelection && ((_editorState$selectio = editorState.selection) === null || _editorState$selectio === void 0 ? void 0 : (_editorState$selectio2 = _editorState$selectio.node) === null || _editorState$selectio2 === void 0 ? void 0 : _editorState$selectio2.type) === editorState.schema.nodes.inlineCard && ((_editorState$selectio3 = editorState.selection) === null || _editorState$selectio3 === void 0 ? void 0 : _editorState$selectio3.from) === (getPosFunction === null || getPosFunction === void 0 ? void 0 : getPosFunction());
|
|
129
|
+
return {
|
|
130
|
+
isPulseEnabled: canBeUpgradedToEmbed,
|
|
131
|
+
isOverlayEnabled: canBeUpgradedToEmbed || canBeUpgradedToBlock,
|
|
132
|
+
isSelected
|
|
133
|
+
};
|
|
121
134
|
};
|
|
@@ -14,7 +14,7 @@ import { isSafeUrl } from '@atlaskit/adf-schema';
|
|
|
14
14
|
import { AnalyticsContext } from '@atlaskit/analytics-next';
|
|
15
15
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
16
16
|
import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
|
|
17
|
-
import {
|
|
17
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
18
18
|
import { changeSelectedCardToLinkFallback } from '../pm-plugins/doc';
|
|
19
19
|
import { getPluginState } from '../pm-plugins/util/state';
|
|
20
20
|
import { titleUrlPairFromNode } from '../utils';
|
|
@@ -97,7 +97,7 @@ export function Card(SmartCardComponent, UnsupportedComponent) {
|
|
|
97
97
|
// Below is added for the future implementation of Linking Platform namespaced analytics context
|
|
98
98
|
location: analyticsEditorAppearance
|
|
99
99
|
}
|
|
100
|
-
},
|
|
100
|
+
}, fg('platform.linking-platform.smart-card.on-click-callback') ? /*#__PURE__*/React.createElement(WithClickHandler, {
|
|
101
101
|
pluginInjectionApi: pluginInjectionApi,
|
|
102
102
|
onClickCallback: onClickCallback,
|
|
103
103
|
url: url
|
|
@@ -1,11 +1,90 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import React, { memo, useCallback, useMemo } from 'react';
|
|
3
|
+
import rafSchedule from 'raf-schd';
|
|
4
|
+
import { findOverflowScrollParent, UnsupportedInline } from '@atlaskit/editor-common/ui';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
+
import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
7
|
+
import { registerCard } from '../pm-plugins/actions';
|
|
8
|
+
import OverlayWrapper from '../ui/ConfigureOverlay';
|
|
9
|
+
import { getAwarenessProps } from '../utils';
|
|
6
10
|
import { Card } from './genericCard';
|
|
7
11
|
import { InlineCardWithAwareness } from './inlineCardWithAwareness';
|
|
12
|
+
export var InlineCard = /*#__PURE__*/memo(function (_ref) {
|
|
13
|
+
var node = _ref.node,
|
|
14
|
+
cardContext = _ref.cardContext,
|
|
15
|
+
actionOptions = _ref.actionOptions,
|
|
16
|
+
showServerActions = _ref.showServerActions,
|
|
17
|
+
useAlternativePreloader = _ref.useAlternativePreloader,
|
|
18
|
+
view = _ref.view,
|
|
19
|
+
getPos = _ref.getPos,
|
|
20
|
+
onClick = _ref.onClick,
|
|
21
|
+
onRes = _ref.onResolve,
|
|
22
|
+
isHovered = _ref.isHovered;
|
|
23
|
+
var _node$attrs = node.attrs,
|
|
24
|
+
url = _node$attrs.url,
|
|
25
|
+
data = _node$attrs.data;
|
|
26
|
+
var scrollContainer = useMemo(function () {
|
|
27
|
+
return findOverflowScrollParent(view.dom) || undefined;
|
|
28
|
+
}, [view.dom]);
|
|
29
|
+
var onResolve = useCallback(function (data) {
|
|
30
|
+
if (!getPos || typeof getPos === 'boolean') {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var title = data.title,
|
|
34
|
+
url = data.url;
|
|
35
|
+
// don't dispatch immediately since we might be in the middle of
|
|
36
|
+
// rendering a nodeview
|
|
37
|
+
rafSchedule(function () {
|
|
38
|
+
// prosemirror-bump-fix
|
|
39
|
+
var pos = getPos();
|
|
40
|
+
if (typeof pos !== 'number') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
var tr = view.state.tr;
|
|
44
|
+
registerCard({
|
|
45
|
+
title: title,
|
|
46
|
+
url: url,
|
|
47
|
+
pos: pos
|
|
48
|
+
})(tr);
|
|
49
|
+
onRes === null || onRes === void 0 || onRes(tr, title);
|
|
50
|
+
view.dispatch(tr);
|
|
51
|
+
})();
|
|
52
|
+
}, [getPos, view, onRes]);
|
|
53
|
+
var onError = useCallback(function (data) {
|
|
54
|
+
var url = data.url,
|
|
55
|
+
err = data.err;
|
|
56
|
+
if (err) {
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
onResolve({
|
|
60
|
+
url: url
|
|
61
|
+
});
|
|
62
|
+
}, [onResolve]);
|
|
63
|
+
var card = useMemo(function () {
|
|
64
|
+
return /*#__PURE__*/React.createElement(SmartCard, {
|
|
65
|
+
key: url,
|
|
66
|
+
url: url,
|
|
67
|
+
data: data,
|
|
68
|
+
appearance: "inline",
|
|
69
|
+
onClick: onClick,
|
|
70
|
+
container: scrollContainer,
|
|
71
|
+
onResolve: onResolve,
|
|
72
|
+
onError: onError,
|
|
73
|
+
inlinePreloaderStyle: useAlternativePreloader ? 'on-right-without-skeleton' : undefined,
|
|
74
|
+
actionOptions: actionOptions,
|
|
75
|
+
showServerActions: showServerActions,
|
|
76
|
+
isHovered: isHovered
|
|
77
|
+
});
|
|
78
|
+
}, [data, isHovered, onError, onResolve, scrollContainer, url, useAlternativePreloader, actionOptions, showServerActions, onClick]);
|
|
79
|
+
|
|
80
|
+
// [WS-2307]: we only render card wrapped into a Provider when the value is ready,
|
|
81
|
+
// otherwise if we got data, we can render the card directly since it doesn't need the Provider
|
|
82
|
+
return cardContext && cardContext.value ? /*#__PURE__*/React.createElement(cardContext.Provider, {
|
|
83
|
+
value: cardContext.value
|
|
84
|
+
}, card) : data ? card : null;
|
|
85
|
+
});
|
|
8
86
|
var WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
|
|
87
|
+
var WrappedInlineCard = Card(InlineCard, UnsupportedInline);
|
|
9
88
|
export function InlineCardNodeView(props) {
|
|
10
89
|
var useAlternativePreloader = props.useAlternativePreloader,
|
|
11
90
|
node = props.node,
|
|
@@ -18,6 +97,20 @@ export function InlineCardNodeView(props) {
|
|
|
18
97
|
enableInlineUpgradeFeatures = props.enableInlineUpgradeFeatures,
|
|
19
98
|
pluginInjectionApi = props.pluginInjectionApi,
|
|
20
99
|
onClickCallback = props.onClickCallback;
|
|
100
|
+
if (fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
101
|
+
return /*#__PURE__*/React.createElement(OverlayWrapper, {
|
|
102
|
+
targetElementPos: getPos(),
|
|
103
|
+
view: view
|
|
104
|
+
}, /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
105
|
+
node: node,
|
|
106
|
+
view: view,
|
|
107
|
+
getPos: getPos,
|
|
108
|
+
actionOptions: actionOptions,
|
|
109
|
+
showServerActions: showServerActions,
|
|
110
|
+
useAlternativePreloader: useAlternativePreloader,
|
|
111
|
+
onClickCallback: onClickCallback
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
21
114
|
return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
|
|
22
115
|
node: node,
|
|
23
116
|
view: view,
|
|
@@ -28,16 +121,4 @@ export function InlineCardNodeView(props) {
|
|
|
28
121
|
pluginInjectionApi: pluginInjectionApi,
|
|
29
122
|
onClickCallback: onClickCallback
|
|
30
123
|
}, enableInlineUpgradeFeatures && getAwarenessProps(view.state, getPos, allowEmbeds, allowBlockCards)));
|
|
31
|
-
}
|
|
32
|
-
var getAwarenessProps = function getAwarenessProps(editorState, getPos, allowEmbeds, allowBlockCards) {
|
|
33
|
-
var _editorState$selectio, _editorState$selectio2;
|
|
34
|
-
var linkPosition = getPos && typeof getPos() === 'number' ? getPos() : undefined;
|
|
35
|
-
var canBeUpgradedToEmbed = !!linkPosition && allowEmbeds ? isEmbedSupportedAtPosition(linkPosition, editorState, 'inline') : false;
|
|
36
|
-
var canBeUpgradedToBlock = !!linkPosition && allowBlockCards ? isBlockSupportedAtPosition(linkPosition, editorState, 'inline') : false;
|
|
37
|
-
var isSelected = editorState.selection instanceof NodeSelection && ((_editorState$selectio = editorState.selection) === null || _editorState$selectio === void 0 || (_editorState$selectio = _editorState$selectio.node) === null || _editorState$selectio === void 0 ? void 0 : _editorState$selectio.type) === editorState.schema.nodes.inlineCard && ((_editorState$selectio2 = editorState.selection) === null || _editorState$selectio2 === void 0 ? void 0 : _editorState$selectio2.from) === getPos();
|
|
38
|
-
return {
|
|
39
|
-
isPulseEnabled: canBeUpgradedToEmbed,
|
|
40
|
-
isOverlayEnabled: canBeUpgradedToEmbed || canBeUpgradedToBlock,
|
|
41
|
-
isSelected: isSelected
|
|
42
|
-
};
|
|
43
|
-
};
|
|
124
|
+
}
|