@atlaskit/editor-plugin-card 2.6.2 → 2.6.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 +5 -3
- package/dist/cjs/nodeviews/inlineCard.js +15 -10
- package/dist/cjs/pm-plugins/main.js +9 -6
- package/dist/cjs/toolbar.js +1 -0
- package/dist/cjs/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js} +15 -65
- package/dist/cjs/ui/EditToolbarButton/index.js +286 -0
- package/dist/cjs/ui/EditToolbarButton/types.js +5 -0
- package/dist/cjs/ui/useFetchDatasourceDataInfo.js +75 -0
- package/dist/es2019/nodeviews/genericCard.js +5 -3
- package/dist/es2019/nodeviews/inlineCard.js +16 -10
- package/dist/es2019/pm-plugins/main.js +10 -5
- package/dist/es2019/toolbar.js +1 -0
- package/dist/es2019/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js} +14 -67
- package/dist/es2019/ui/EditToolbarButton/index.js +278 -0
- package/dist/es2019/ui/EditToolbarButton/types.js +1 -0
- package/dist/es2019/ui/useFetchDatasourceDataInfo.js +41 -0
- package/dist/esm/nodeviews/genericCard.js +5 -3
- package/dist/esm/nodeviews/inlineCard.js +15 -10
- package/dist/esm/pm-plugins/main.js +9 -6
- package/dist/esm/toolbar.js +1 -0
- package/dist/esm/ui/EditToolbarButton/EditToolbarButtonPresentation.js +116 -0
- package/dist/esm/ui/{EditToolbarButton.js → EditToolbarButton/index.js} +116 -4
- package/dist/esm/ui/EditToolbarButton/types.js +1 -0
- package/dist/esm/ui/useFetchDatasourceDataInfo.js +67 -0
- package/dist/types/nodeviews/genericCard.d.ts +1 -0
- package/dist/types/nodeviews/inlineCard.d.ts +1 -1
- package/dist/types/ui/EditToolbarButton/EditToolbarButtonPresentation.d.ts +9 -0
- package/dist/types/ui/EditToolbarButton/index.d.ts +3 -0
- package/dist/types/ui/EditToolbarButton/types.d.ts +29 -0
- package/dist/types/ui/useFetchDatasourceDataInfo.d.ts +10 -0
- package/dist/types-ts4.5/nodeviews/genericCard.d.ts +1 -0
- package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +1 -1
- package/dist/types-ts4.5/ui/EditToolbarButton/EditToolbarButtonPresentation.d.ts +9 -0
- package/dist/types-ts4.5/ui/EditToolbarButton/index.d.ts +3 -0
- package/dist/types-ts4.5/ui/EditToolbarButton/types.d.ts +29 -0
- package/dist/types-ts4.5/ui/useFetchDatasourceDataInfo.d.ts +10 -0
- package/package.json +5 -2
- package/dist/types/ui/EditToolbarButton.d.ts +0 -18
- package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +0 -18
|
@@ -93,7 +93,7 @@ export const InlineCard = /*#__PURE__*/memo(({
|
|
|
93
93
|
const WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
|
|
94
94
|
const WrappedInlineCard = Card(InlineCard, UnsupportedInline);
|
|
95
95
|
export function InlineCardNodeView(props) {
|
|
96
|
-
var
|
|
96
|
+
var _floatingToolbarState;
|
|
97
97
|
const {
|
|
98
98
|
useAlternativePreloader,
|
|
99
99
|
node,
|
|
@@ -105,18 +105,19 @@ export function InlineCardNodeView(props) {
|
|
|
105
105
|
allowBlockCards,
|
|
106
106
|
enableInlineUpgradeFeatures,
|
|
107
107
|
pluginInjectionApi,
|
|
108
|
-
onClickCallback
|
|
108
|
+
onClickCallback,
|
|
109
|
+
__livePage
|
|
109
110
|
} = props;
|
|
110
111
|
const [isOverlayHovered, setIsOverlayHovered] = useState(false);
|
|
111
|
-
const
|
|
112
|
-
|
|
112
|
+
const {
|
|
113
|
+
editorViewModeState,
|
|
114
|
+
floatingToolbarState
|
|
115
|
+
} = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorViewMode']);
|
|
116
|
+
const floatingToolbarNode = floatingToolbarState === null || floatingToolbarState === void 0 ? void 0 : (_floatingToolbarState = floatingToolbarState.configWithNodeInfo) === null || _floatingToolbarState === void 0 ? void 0 : _floatingToolbarState.node;
|
|
117
|
+
if (__livePage && fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
113
118
|
const showHoverPreview = floatingToolbarNode !== node;
|
|
114
119
|
const livePagesHoverCardFadeInDelay = 800;
|
|
115
|
-
|
|
116
|
-
targetElementPos: getPos(),
|
|
117
|
-
view: view,
|
|
118
|
-
isHoveredCallback: setIsOverlayHovered
|
|
119
|
-
}, /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
120
|
+
const inlineCard = /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
120
121
|
isHovered: isOverlayHovered,
|
|
121
122
|
node: node,
|
|
122
123
|
view: view,
|
|
@@ -129,7 +130,12 @@ export function InlineCardNodeView(props) {
|
|
|
129
130
|
hoverPreviewOptions: {
|
|
130
131
|
fadeInDelay: livePagesHoverCardFadeInDelay
|
|
131
132
|
}
|
|
132
|
-
})
|
|
133
|
+
});
|
|
134
|
+
return (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? inlineCard : /*#__PURE__*/React.createElement(OverlayWrapper, {
|
|
135
|
+
targetElementPos: getPos(),
|
|
136
|
+
view: view,
|
|
137
|
+
isHoveredCallback: setIsOverlayHovered
|
|
138
|
+
}, inlineCard);
|
|
133
139
|
}
|
|
134
140
|
return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
|
|
135
141
|
node: node,
|
|
@@ -59,7 +59,9 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
|
|
|
59
59
|
showUpgradeDiscoverability,
|
|
60
60
|
allowEmbeds,
|
|
61
61
|
allowBlockCards,
|
|
62
|
-
onClickCallback
|
|
62
|
+
onClickCallback,
|
|
63
|
+
// @ts-ignore Temporary solution to check for Live Page editor.
|
|
64
|
+
__livePage
|
|
63
65
|
} = options;
|
|
64
66
|
const enableInlineUpgradeFeatures = !!showUpgradeDiscoverability && platform !== 'mobile';
|
|
65
67
|
const inlineCardViewProducer = getInlineNodeViewProducer({
|
|
@@ -73,11 +75,14 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
|
|
|
73
75
|
allowEmbeds,
|
|
74
76
|
allowBlockCards,
|
|
75
77
|
pluginInjectionApi,
|
|
76
|
-
onClickCallback
|
|
78
|
+
onClickCallback,
|
|
79
|
+
__livePage
|
|
77
80
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
...(__livePage && fg('platform.linking-platform.smart-links-in-live-pages') && {
|
|
82
|
+
extraNodeViewProps: {
|
|
83
|
+
stopEvent
|
|
84
|
+
}
|
|
85
|
+
})
|
|
81
86
|
});
|
|
82
87
|
return new SafePlugin({
|
|
83
88
|
state: {
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -464,6 +464,7 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
|
|
|
464
464
|
fallback: [],
|
|
465
465
|
render: editorView => /*#__PURE__*/React.createElement(EditToolbarButton, {
|
|
466
466
|
datasourceId: datasourceId,
|
|
467
|
+
node: node,
|
|
467
468
|
key: "edit-toolbar-item",
|
|
468
469
|
url: metadata.url,
|
|
469
470
|
intl: intl,
|
package/dist/es2019/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
3
|
|
|
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';
|
|
@@ -10,33 +10,21 @@ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlask
|
|
|
10
10
|
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
11
11
|
import { ButtonItem } from '@atlaskit/menu';
|
|
12
12
|
import { Flex } from '@atlaskit/primitives';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { CardContextProvider } from './CardContextProvider';
|
|
16
|
-
import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
|
|
13
|
+
import { focusEditorView } from '../../utils';
|
|
14
|
+
import { editDatasource } from '../EditDatasourceButton';
|
|
17
15
|
const dropdownExpandContainer = css({
|
|
18
16
|
margin: `0px ${"var(--ds-space-negative-050, -4px)"}`
|
|
19
17
|
});
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = props;
|
|
31
|
-
const {
|
|
32
|
-
extensionKey,
|
|
33
|
-
...response
|
|
34
|
-
} = useFetchDatasourceInfo({
|
|
35
|
-
isRegularCardNode: true,
|
|
36
|
-
url,
|
|
37
|
-
cardContext
|
|
38
|
-
});
|
|
39
|
-
const datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
|
|
18
|
+
const EditToolbarButtonPresentation = ({
|
|
19
|
+
datasourceId,
|
|
20
|
+
currentAppearance,
|
|
21
|
+
editorAnalyticsApi,
|
|
22
|
+
editVariant,
|
|
23
|
+
editorView,
|
|
24
|
+
extensionKey,
|
|
25
|
+
onLinkEditClick,
|
|
26
|
+
intl
|
|
27
|
+
}) => {
|
|
40
28
|
const [isOpen, setIsOpen] = useState(false);
|
|
41
29
|
const containerRef = useRef();
|
|
42
30
|
const toggleOpen = () => setIsOpen(open => !open);
|
|
@@ -47,25 +35,6 @@ const EditToolbarButtonWithCardContext = props => {
|
|
|
47
35
|
focusEditorView(editorView);
|
|
48
36
|
}
|
|
49
37
|
}, [editorView, onLinkEditClick]);
|
|
50
|
-
const editVariant = useMemo(() => {
|
|
51
|
-
const hasUrl = url !== null && url !== undefined;
|
|
52
|
-
if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
|
|
53
|
-
if (hasUrl) {
|
|
54
|
-
return 'edit-link';
|
|
55
|
-
}
|
|
56
|
-
return 'none';
|
|
57
|
-
}
|
|
58
|
-
if (hasUrl) {
|
|
59
|
-
var _cardContext$store, _urlState$error;
|
|
60
|
-
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
61
|
-
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
62
|
-
return 'edit-link';
|
|
63
|
-
}
|
|
64
|
-
return 'edit-dropdown';
|
|
65
|
-
} else {
|
|
66
|
-
return 'edit-datasource';
|
|
67
|
-
}
|
|
68
|
-
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
69
38
|
const onEditDatasource = useCallback(() => {
|
|
70
39
|
if (editorView && datasourceId) {
|
|
71
40
|
editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
|
|
@@ -135,26 +104,4 @@ const EditToolbarButtonWithCardContext = props => {
|
|
|
135
104
|
return null;
|
|
136
105
|
}
|
|
137
106
|
};
|
|
138
|
-
export
|
|
139
|
-
const {
|
|
140
|
-
currentAppearance,
|
|
141
|
-
datasourceId,
|
|
142
|
-
editorAnalyticsApi,
|
|
143
|
-
editorView,
|
|
144
|
-
intl,
|
|
145
|
-
onLinkEditClick,
|
|
146
|
-
url
|
|
147
|
-
} = props;
|
|
148
|
-
return jsx(CardContextProvider, null, ({
|
|
149
|
-
cardContext
|
|
150
|
-
}) => jsx(EditToolbarButtonWithCardContext, {
|
|
151
|
-
datasourceId: datasourceId,
|
|
152
|
-
url: url,
|
|
153
|
-
intl: intl,
|
|
154
|
-
editorAnalyticsApi: editorAnalyticsApi,
|
|
155
|
-
editorView: editorView,
|
|
156
|
-
cardContext: cardContext,
|
|
157
|
-
onLinkEditClick: onLinkEditClick,
|
|
158
|
-
currentAppearance: currentAppearance
|
|
159
|
-
}));
|
|
160
|
-
};
|
|
107
|
+
export default EditToolbarButtonPresentation;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useCallback, useMemo, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
5
|
+
import { css, jsx } from '@emotion/react';
|
|
6
|
+
import { FormattedMessage } from 'react-intl-next';
|
|
7
|
+
import { linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
8
|
+
import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
|
|
9
|
+
import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlaskit/editor-common/ui-menu';
|
|
10
|
+
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
11
|
+
import { ButtonItem } from '@atlaskit/menu';
|
|
12
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
13
|
+
import { Flex } from '@atlaskit/primitives';
|
|
14
|
+
import { editDatasource } from '../../ui/EditDatasourceButton';
|
|
15
|
+
import { focusEditorView, isDatasourceConfigEditable } from '../../utils';
|
|
16
|
+
import { CardContextProvider } from '../CardContextProvider';
|
|
17
|
+
import { useFetchDatasourceDataInfo } from '../useFetchDatasourceDataInfo';
|
|
18
|
+
import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
|
|
19
|
+
import EditToolbarButtonPresentation from './EditToolbarButtonPresentation';
|
|
20
|
+
const dropdownExpandContainer = css({
|
|
21
|
+
margin: `0px ${"var(--ds-space-negative-050, -4px)"}`
|
|
22
|
+
});
|
|
23
|
+
const EditToolbarButtonWithCardContext = props => {
|
|
24
|
+
var _response$datasourceI;
|
|
25
|
+
const {
|
|
26
|
+
cardContext,
|
|
27
|
+
currentAppearance,
|
|
28
|
+
editorAnalyticsApi,
|
|
29
|
+
editorView,
|
|
30
|
+
intl,
|
|
31
|
+
onLinkEditClick,
|
|
32
|
+
url
|
|
33
|
+
} = props;
|
|
34
|
+
const {
|
|
35
|
+
extensionKey,
|
|
36
|
+
...response
|
|
37
|
+
} = useFetchDatasourceInfo({
|
|
38
|
+
isRegularCardNode: true,
|
|
39
|
+
url,
|
|
40
|
+
cardContext
|
|
41
|
+
});
|
|
42
|
+
const datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
|
|
43
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
44
|
+
const containerRef = useRef();
|
|
45
|
+
const toggleOpen = () => setIsOpen(open => !open);
|
|
46
|
+
const onClose = () => setIsOpen(false);
|
|
47
|
+
const onEditLink = useCallback(() => {
|
|
48
|
+
if (editorView) {
|
|
49
|
+
onLinkEditClick(editorView.state, editorView.dispatch);
|
|
50
|
+
focusEditorView(editorView);
|
|
51
|
+
}
|
|
52
|
+
}, [editorView, onLinkEditClick]);
|
|
53
|
+
const editVariant = useMemo(() => {
|
|
54
|
+
const hasUrl = url !== null && url !== undefined;
|
|
55
|
+
if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
|
|
56
|
+
if (hasUrl) {
|
|
57
|
+
return 'edit-link';
|
|
58
|
+
}
|
|
59
|
+
return 'none';
|
|
60
|
+
}
|
|
61
|
+
if (hasUrl) {
|
|
62
|
+
var _cardContext$store, _urlState$error;
|
|
63
|
+
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
64
|
+
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
65
|
+
return 'edit-link';
|
|
66
|
+
}
|
|
67
|
+
return 'edit-dropdown';
|
|
68
|
+
} else {
|
|
69
|
+
return 'edit-datasource';
|
|
70
|
+
}
|
|
71
|
+
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
72
|
+
const onEditDatasource = useCallback(() => {
|
|
73
|
+
if (editorView && datasourceId) {
|
|
74
|
+
editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
|
|
75
|
+
focusEditorView(editorView);
|
|
76
|
+
}
|
|
77
|
+
}, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
|
|
78
|
+
switch (editVariant) {
|
|
79
|
+
case 'edit-link':
|
|
80
|
+
{
|
|
81
|
+
return jsx(Flex, {
|
|
82
|
+
gap: "space.050"
|
|
83
|
+
}, jsx(Button, {
|
|
84
|
+
testId: "edit-link",
|
|
85
|
+
onClick: onEditLink
|
|
86
|
+
}, jsx(FormattedMessage, linkToolbarMessages.editLink)), jsx(Separator, null));
|
|
87
|
+
}
|
|
88
|
+
case 'edit-datasource':
|
|
89
|
+
{
|
|
90
|
+
return jsx(Flex, {
|
|
91
|
+
gap: "space.050"
|
|
92
|
+
}, jsx(Button, {
|
|
93
|
+
testId: "edit-datasource",
|
|
94
|
+
tooltipContent: intl.formatMessage(linkToolbarMessages.editDatasourceStandaloneTooltip),
|
|
95
|
+
onClick: onEditDatasource
|
|
96
|
+
}, jsx(FormattedMessage, linkToolbarMessages.editDatasourceStandalone)), jsx(Separator, null));
|
|
97
|
+
}
|
|
98
|
+
case 'edit-dropdown':
|
|
99
|
+
{
|
|
100
|
+
const trigger = jsx(Flex, {
|
|
101
|
+
gap: "space.050"
|
|
102
|
+
}, jsx(Button, {
|
|
103
|
+
testId: "edit-dropdown-trigger",
|
|
104
|
+
iconAfter: jsx("span", {
|
|
105
|
+
css: dropdownExpandContainer
|
|
106
|
+
}, jsx(ExpandIcon, {
|
|
107
|
+
label: intl.formatMessage(messages.editDropdownTriggerTitle)
|
|
108
|
+
})),
|
|
109
|
+
onClick: toggleOpen,
|
|
110
|
+
selected: isOpen,
|
|
111
|
+
disabled: false,
|
|
112
|
+
ariaHasPopup: true
|
|
113
|
+
}, jsx(FormattedMessage, messages.editDropdownTriggerTitle)), jsx(Separator, null));
|
|
114
|
+
return jsx(Flex, {
|
|
115
|
+
ref: containerRef
|
|
116
|
+
}, jsx(UiDropdown, {
|
|
117
|
+
mountTo: containerRef.current,
|
|
118
|
+
isOpen: isOpen,
|
|
119
|
+
handleClickOutside: onClose,
|
|
120
|
+
handleEscapeKeydown: onClose,
|
|
121
|
+
trigger: trigger,
|
|
122
|
+
scrollableElement: containerRef.current,
|
|
123
|
+
arrowKeyNavigationProviderOptions: {
|
|
124
|
+
type: ArrowKeyNavigationType.MENU
|
|
125
|
+
}
|
|
126
|
+
}, jsx(ButtonItem, {
|
|
127
|
+
key: "edit.link",
|
|
128
|
+
onClick: onEditLink,
|
|
129
|
+
testId: "edit-dropdown-edit-link-item"
|
|
130
|
+
}, jsx(FormattedMessage, messages.editDropdownEditLinkTitle)), jsx(ButtonItem, {
|
|
131
|
+
key: "edit.datasource",
|
|
132
|
+
onClick: onEditDatasource,
|
|
133
|
+
testId: "edit-dropdown-edit-datasource-item"
|
|
134
|
+
}, jsx(FormattedMessage, messages.editDropdownEditDatasourceTitle))));
|
|
135
|
+
}
|
|
136
|
+
case 'none':
|
|
137
|
+
default:
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const EditToolbarButtonWithUrl = props => {
|
|
142
|
+
const {
|
|
143
|
+
cardContext,
|
|
144
|
+
currentAppearance,
|
|
145
|
+
editorAnalyticsApi,
|
|
146
|
+
editorView,
|
|
147
|
+
intl,
|
|
148
|
+
onLinkEditClick,
|
|
149
|
+
url
|
|
150
|
+
} = props;
|
|
151
|
+
const {
|
|
152
|
+
extensionKey,
|
|
153
|
+
datasourceId
|
|
154
|
+
} = useFetchDatasourceInfo({
|
|
155
|
+
isRegularCardNode: true,
|
|
156
|
+
url,
|
|
157
|
+
cardContext
|
|
158
|
+
});
|
|
159
|
+
const editVariant = useMemo(() => {
|
|
160
|
+
var _cardContext$store2, _urlState$error2;
|
|
161
|
+
if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
|
|
162
|
+
return 'edit-link';
|
|
163
|
+
}
|
|
164
|
+
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store2 = cardContext.store) === null || _cardContext$store2 === void 0 ? void 0 : _cardContext$store2.getState()[url];
|
|
165
|
+
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error2 = urlState.error) === null || _urlState$error2 === void 0 ? void 0 : _urlState$error2.kind) === 'fatal') {
|
|
166
|
+
return 'edit-link';
|
|
167
|
+
}
|
|
168
|
+
return 'edit-dropdown';
|
|
169
|
+
}, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
|
|
170
|
+
return jsx(EditToolbarButtonPresentation, {
|
|
171
|
+
datasourceId: datasourceId,
|
|
172
|
+
currentAppearance: currentAppearance,
|
|
173
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
174
|
+
editVariant: editVariant,
|
|
175
|
+
editorView: editorView,
|
|
176
|
+
extensionKey: extensionKey,
|
|
177
|
+
onLinkEditClick: onLinkEditClick,
|
|
178
|
+
intl: intl
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
const EditToolbarButtonWithDatasourceId = props => {
|
|
182
|
+
const {
|
|
183
|
+
currentAppearance,
|
|
184
|
+
editorAnalyticsApi,
|
|
185
|
+
editorView,
|
|
186
|
+
intl,
|
|
187
|
+
onLinkEditClick,
|
|
188
|
+
datasourceId,
|
|
189
|
+
node
|
|
190
|
+
} = props;
|
|
191
|
+
const fetchData = useMemo(() => {
|
|
192
|
+
try {
|
|
193
|
+
var _attrs$datasource$vie, _attrs$datasource$vie2;
|
|
194
|
+
const attrs = node.attrs;
|
|
195
|
+
const parameters = attrs.datasource.parameters;
|
|
196
|
+
const visibleColumnKeys = (_attrs$datasource$vie = attrs.datasource.views[0]) === null || _attrs$datasource$vie === void 0 ? void 0 : (_attrs$datasource$vie2 = _attrs$datasource$vie.properties) === null || _attrs$datasource$vie2 === void 0 ? void 0 : _attrs$datasource$vie2.columns.map(c => c.key);
|
|
197
|
+
return {
|
|
198
|
+
parameters,
|
|
199
|
+
visibleColumnKeys
|
|
200
|
+
};
|
|
201
|
+
} catch (e) {
|
|
202
|
+
// eslint-disable-next-line no-console
|
|
203
|
+
console.error(e);
|
|
204
|
+
}
|
|
205
|
+
}, [node.attrs]);
|
|
206
|
+
const {
|
|
207
|
+
extensionKey
|
|
208
|
+
} = useFetchDatasourceDataInfo({
|
|
209
|
+
datasourceId,
|
|
210
|
+
parameters: fetchData === null || fetchData === void 0 ? void 0 : fetchData.parameters,
|
|
211
|
+
visibleColumnKeys: fetchData === null || fetchData === void 0 ? void 0 : fetchData.visibleColumnKeys
|
|
212
|
+
});
|
|
213
|
+
const editVariant = useMemo(() => {
|
|
214
|
+
if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
|
|
215
|
+
return 'none';
|
|
216
|
+
}
|
|
217
|
+
return 'edit-datasource';
|
|
218
|
+
}, [datasourceId]);
|
|
219
|
+
return jsx(EditToolbarButtonPresentation, {
|
|
220
|
+
datasourceId: datasourceId,
|
|
221
|
+
currentAppearance: currentAppearance,
|
|
222
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
223
|
+
editVariant: editVariant,
|
|
224
|
+
editorView: editorView,
|
|
225
|
+
extensionKey: extensionKey,
|
|
226
|
+
onLinkEditClick: onLinkEditClick,
|
|
227
|
+
intl: intl
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
export const EditToolbarButton = props => {
|
|
231
|
+
const {
|
|
232
|
+
currentAppearance,
|
|
233
|
+
datasourceId,
|
|
234
|
+
editorAnalyticsApi,
|
|
235
|
+
editorView,
|
|
236
|
+
intl,
|
|
237
|
+
onLinkEditClick,
|
|
238
|
+
url
|
|
239
|
+
} = props;
|
|
240
|
+
return jsx(CardContextProvider, null, ({
|
|
241
|
+
cardContext
|
|
242
|
+
}) => {
|
|
243
|
+
if (fg('enable_datasource_nourl_edit_dropdown_datafetch')) {
|
|
244
|
+
if (props.url) {
|
|
245
|
+
return jsx(EditToolbarButtonWithUrl, {
|
|
246
|
+
url: props.url,
|
|
247
|
+
intl: intl,
|
|
248
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
249
|
+
editorView: editorView,
|
|
250
|
+
cardContext: cardContext,
|
|
251
|
+
onLinkEditClick: onLinkEditClick,
|
|
252
|
+
currentAppearance: currentAppearance
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
if (props.datasourceId && props.node) {
|
|
256
|
+
return jsx(EditToolbarButtonWithDatasourceId, {
|
|
257
|
+
datasourceId: props.datasourceId,
|
|
258
|
+
node: props.node,
|
|
259
|
+
intl: intl,
|
|
260
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
261
|
+
editorView: editorView,
|
|
262
|
+
onLinkEditClick: onLinkEditClick,
|
|
263
|
+
currentAppearance: currentAppearance
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return jsx(EditToolbarButtonWithCardContext, {
|
|
268
|
+
datasourceId: datasourceId,
|
|
269
|
+
url: url,
|
|
270
|
+
intl: intl,
|
|
271
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
272
|
+
editorView: editorView,
|
|
273
|
+
cardContext: cardContext,
|
|
274
|
+
onLinkEditClick: onLinkEditClick,
|
|
275
|
+
currentAppearance: currentAppearance
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE, useDatasourceClientExtension } from '@atlaskit/link-client-extension';
|
|
4
|
+
export const useFetchDatasourceDataInfo = ({
|
|
5
|
+
datasourceId,
|
|
6
|
+
parameters,
|
|
7
|
+
visibleColumnKeys
|
|
8
|
+
}) => {
|
|
9
|
+
const [extensionKey, setExtensionKey] = useState(undefined);
|
|
10
|
+
const {
|
|
11
|
+
getDatasourceData
|
|
12
|
+
} = useDatasourceClientExtension();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const fetchDatasource = async () => {
|
|
15
|
+
try {
|
|
16
|
+
if (!datasourceId || !parameters || !visibleColumnKeys) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const datasourceDataRequest = {
|
|
20
|
+
parameters,
|
|
21
|
+
pageSize: DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE,
|
|
22
|
+
pageCursor: undefined,
|
|
23
|
+
fields: visibleColumnKeys,
|
|
24
|
+
includeSchema: true
|
|
25
|
+
};
|
|
26
|
+
const {
|
|
27
|
+
meta
|
|
28
|
+
} = await getDatasourceData(datasourceId, datasourceDataRequest, false);
|
|
29
|
+
setExtensionKey(meta.extensionKey);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.error(e);
|
|
33
|
+
setExtensionKey(undefined);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
void fetchDatasource();
|
|
37
|
+
}, [getDatasourceData, visibleColumnKeys, parameters, datasourceId]);
|
|
38
|
+
return {
|
|
39
|
+
extensionKey
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -22,7 +22,8 @@ var WithClickHandler = function WithClickHandler(_ref) {
|
|
|
22
22
|
var pluginInjectionApi = _ref.pluginInjectionApi,
|
|
23
23
|
url = _ref.url,
|
|
24
24
|
onClickCallback = _ref.onClickCallback,
|
|
25
|
-
children = _ref.children
|
|
25
|
+
children = _ref.children,
|
|
26
|
+
__livePage = _ref.__livePage;
|
|
26
27
|
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorViewMode']),
|
|
27
28
|
editorViewModeState = _useSharedPluginState.editorViewModeState;
|
|
28
29
|
var onClick = useCallback(function (event) {
|
|
@@ -43,7 +44,7 @@ var WithClickHandler = function WithClickHandler(_ref) {
|
|
|
43
44
|
*
|
|
44
45
|
* const allowNavigation = isLivePage && !onClickCallback;
|
|
45
46
|
*/
|
|
46
|
-
var _allowNavigation = !onClickCallback;
|
|
47
|
+
var _allowNavigation = __livePage && !onClickCallback;
|
|
47
48
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children({
|
|
48
49
|
onClick: _allowNavigation ? undefined : onClick
|
|
49
50
|
}));
|
|
@@ -112,7 +113,8 @@ export function Card(SmartCardComponent, UnsupportedComponent) {
|
|
|
112
113
|
}, /*#__PURE__*/React.createElement(WithClickHandler, {
|
|
113
114
|
pluginInjectionApi: pluginInjectionApi,
|
|
114
115
|
onClickCallback: onClickCallback,
|
|
115
|
-
url: url
|
|
116
|
+
url: url,
|
|
117
|
+
__livePage: this.props.__livePage
|
|
116
118
|
}, function (_ref2) {
|
|
117
119
|
var onClick = _ref2.onClick;
|
|
118
120
|
return /*#__PURE__*/React.createElement(SmartCardComponent, _extends({
|
|
@@ -92,7 +92,7 @@ export var InlineCard = /*#__PURE__*/memo(function (_ref) {
|
|
|
92
92
|
var WrappedInlineCardWithAwareness = Card(InlineCardWithAwareness, UnsupportedInline);
|
|
93
93
|
var WrappedInlineCard = Card(InlineCard, UnsupportedInline);
|
|
94
94
|
export function InlineCardNodeView(props) {
|
|
95
|
-
var
|
|
95
|
+
var _floatingToolbarState;
|
|
96
96
|
var useAlternativePreloader = props.useAlternativePreloader,
|
|
97
97
|
node = props.node,
|
|
98
98
|
view = props.view,
|
|
@@ -103,20 +103,20 @@ export function InlineCardNodeView(props) {
|
|
|
103
103
|
allowBlockCards = props.allowBlockCards,
|
|
104
104
|
enableInlineUpgradeFeatures = props.enableInlineUpgradeFeatures,
|
|
105
105
|
pluginInjectionApi = props.pluginInjectionApi,
|
|
106
|
-
onClickCallback = props.onClickCallback
|
|
106
|
+
onClickCallback = props.onClickCallback,
|
|
107
|
+
__livePage = props.__livePage;
|
|
107
108
|
var _useState = useState(false),
|
|
108
109
|
_useState2 = _slicedToArray(_useState, 2),
|
|
109
110
|
isOverlayHovered = _useState2[0],
|
|
110
111
|
setIsOverlayHovered = _useState2[1];
|
|
111
|
-
var
|
|
112
|
-
|
|
112
|
+
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['floatingToolbar', 'editorViewMode']),
|
|
113
|
+
editorViewModeState = _useSharedPluginState.editorViewModeState,
|
|
114
|
+
floatingToolbarState = _useSharedPluginState.floatingToolbarState;
|
|
115
|
+
var floatingToolbarNode = floatingToolbarState === null || floatingToolbarState === void 0 || (_floatingToolbarState = floatingToolbarState.configWithNodeInfo) === null || _floatingToolbarState === void 0 ? void 0 : _floatingToolbarState.node;
|
|
116
|
+
if (__livePage && fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
113
117
|
var showHoverPreview = floatingToolbarNode !== node;
|
|
114
118
|
var livePagesHoverCardFadeInDelay = 800;
|
|
115
|
-
|
|
116
|
-
targetElementPos: getPos(),
|
|
117
|
-
view: view,
|
|
118
|
-
isHoveredCallback: setIsOverlayHovered
|
|
119
|
-
}, /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
119
|
+
var inlineCard = /*#__PURE__*/React.createElement(WrappedInlineCard, {
|
|
120
120
|
isHovered: isOverlayHovered,
|
|
121
121
|
node: node,
|
|
122
122
|
view: view,
|
|
@@ -129,7 +129,12 @@ export function InlineCardNodeView(props) {
|
|
|
129
129
|
hoverPreviewOptions: {
|
|
130
130
|
fadeInDelay: livePagesHoverCardFadeInDelay
|
|
131
131
|
}
|
|
132
|
-
})
|
|
132
|
+
});
|
|
133
|
+
return (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? inlineCard : /*#__PURE__*/React.createElement(OverlayWrapper, {
|
|
134
|
+
targetElementPos: getPos(),
|
|
135
|
+
view: view,
|
|
136
|
+
isHoveredCallback: setIsOverlayHovered
|
|
137
|
+
}, inlineCard);
|
|
133
138
|
}
|
|
134
139
|
return /*#__PURE__*/React.createElement(WrappedInlineCardWithAwareness, _extends({
|
|
135
140
|
node: node,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
5
|
import rafSchedule from 'raf-schd';
|
|
@@ -63,9 +63,10 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
|
63
63
|
showUpgradeDiscoverability = options.showUpgradeDiscoverability,
|
|
64
64
|
allowEmbeds = options.allowEmbeds,
|
|
65
65
|
allowBlockCards = options.allowBlockCards,
|
|
66
|
-
onClickCallback = options.onClickCallback
|
|
66
|
+
onClickCallback = options.onClickCallback,
|
|
67
|
+
__livePage = options.__livePage;
|
|
67
68
|
var enableInlineUpgradeFeatures = !!showUpgradeDiscoverability && platform !== 'mobile';
|
|
68
|
-
var inlineCardViewProducer = getInlineNodeViewProducer({
|
|
69
|
+
var inlineCardViewProducer = getInlineNodeViewProducer(_objectSpread({
|
|
69
70
|
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
70
71
|
Component: InlineCardNodeView,
|
|
71
72
|
extraComponentProps: {
|
|
@@ -76,12 +77,14 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
|
76
77
|
allowEmbeds: allowEmbeds,
|
|
77
78
|
allowBlockCards: allowBlockCards,
|
|
78
79
|
pluginInjectionApi: pluginInjectionApi,
|
|
79
|
-
onClickCallback: onClickCallback
|
|
80
|
-
|
|
80
|
+
onClickCallback: onClickCallback,
|
|
81
|
+
__livePage: __livePage
|
|
82
|
+
}
|
|
83
|
+
}, __livePage && fg('platform.linking-platform.smart-links-in-live-pages') && {
|
|
81
84
|
extraNodeViewProps: {
|
|
82
85
|
stopEvent: stopEvent
|
|
83
86
|
}
|
|
84
|
-
});
|
|
87
|
+
}));
|
|
85
88
|
return new SafePlugin({
|
|
86
89
|
state: {
|
|
87
90
|
init: function init() {
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -466,6 +466,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
|
|
|
466
466
|
render: function render(editorView) {
|
|
467
467
|
return /*#__PURE__*/React.createElement(EditToolbarButton, {
|
|
468
468
|
datasourceId: datasourceId,
|
|
469
|
+
node: node,
|
|
469
470
|
key: "edit-toolbar-item",
|
|
470
471
|
url: metadata.url,
|
|
471
472
|
intl: intl,
|