@atlaskit/editor-plugin-card 2.6.1 → 2.6.3
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 +20 -0
- package/dist/cjs/nodeviews/blockCard.js +37 -13
- package/dist/cjs/nodeviews/embedCard.js +35 -10
- 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/blockCard.js +21 -4
- package/dist/es2019/nodeviews/embedCard.js +20 -1
- 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/blockCard.js +38 -14
- package/dist/esm/nodeviews/embedCard.js +35 -10
- 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/blockCard.d.ts +3 -0
- package/dist/types/nodeviews/embedCard.d.ts +3 -0
- 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/blockCard.d.ts +3 -0
- package/dist/types-ts4.5/nodeviews/embedCard.d.ts +3 -0
- 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 +10 -7
- package/dist/cjs/ui/LeftIconOverlay/ConfigureLinkDropdown/index.js +0 -58
- package/dist/cjs/ui/LeftIconOverlay/index.js +0 -199
- package/dist/es2019/ui/LeftIconOverlay/ConfigureLinkDropdown/index.js +0 -47
- package/dist/es2019/ui/LeftIconOverlay/index.js +0 -177
- package/dist/esm/ui/LeftIconOverlay/ConfigureLinkDropdown/index.js +0 -48
- package/dist/esm/ui/LeftIconOverlay/index.js +0 -190
- package/dist/types/ui/EditToolbarButton.d.ts +0 -18
- package/dist/types/ui/LeftIconOverlay/ConfigureLinkDropdown/index.d.ts +0 -6
- package/dist/types/ui/LeftIconOverlay/index.d.ts +0 -10
- package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +0 -18
- package/dist/types-ts4.5/ui/LeftIconOverlay/ConfigureLinkDropdown/index.d.ts +0 -6
- package/dist/types-ts4.5/ui/LeftIconOverlay/index.d.ts +0 -10
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useFetchDatasourceDataInfo = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _linkClientExtension = require("@atlaskit/link-client-extension");
|
|
13
|
+
/** @jsx jsx */
|
|
14
|
+
|
|
15
|
+
var useFetchDatasourceDataInfo = exports.useFetchDatasourceDataInfo = function useFetchDatasourceDataInfo(_ref) {
|
|
16
|
+
var datasourceId = _ref.datasourceId,
|
|
17
|
+
parameters = _ref.parameters,
|
|
18
|
+
visibleColumnKeys = _ref.visibleColumnKeys;
|
|
19
|
+
var _useState = (0, _react.useState)(undefined),
|
|
20
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
21
|
+
extensionKey = _useState2[0],
|
|
22
|
+
setExtensionKey = _useState2[1];
|
|
23
|
+
var _useDatasourceClientE = (0, _linkClientExtension.useDatasourceClientExtension)(),
|
|
24
|
+
getDatasourceData = _useDatasourceClientE.getDatasourceData;
|
|
25
|
+
(0, _react.useEffect)(function () {
|
|
26
|
+
var fetchDatasource = /*#__PURE__*/function () {
|
|
27
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
28
|
+
var datasourceDataRequest, _yield$getDatasourceD, meta;
|
|
29
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
30
|
+
while (1) switch (_context.prev = _context.next) {
|
|
31
|
+
case 0:
|
|
32
|
+
_context.prev = 0;
|
|
33
|
+
if (!(!datasourceId || !parameters || !visibleColumnKeys)) {
|
|
34
|
+
_context.next = 3;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
return _context.abrupt("return");
|
|
38
|
+
case 3:
|
|
39
|
+
datasourceDataRequest = {
|
|
40
|
+
parameters: parameters,
|
|
41
|
+
pageSize: _linkClientExtension.DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE,
|
|
42
|
+
pageCursor: undefined,
|
|
43
|
+
fields: visibleColumnKeys,
|
|
44
|
+
includeSchema: true
|
|
45
|
+
};
|
|
46
|
+
_context.next = 6;
|
|
47
|
+
return getDatasourceData(datasourceId, datasourceDataRequest, false);
|
|
48
|
+
case 6:
|
|
49
|
+
_yield$getDatasourceD = _context.sent;
|
|
50
|
+
meta = _yield$getDatasourceD.meta;
|
|
51
|
+
setExtensionKey(meta.extensionKey);
|
|
52
|
+
_context.next = 15;
|
|
53
|
+
break;
|
|
54
|
+
case 11:
|
|
55
|
+
_context.prev = 11;
|
|
56
|
+
_context.t0 = _context["catch"](0);
|
|
57
|
+
// eslint-disable-next-line no-console
|
|
58
|
+
console.error(_context.t0);
|
|
59
|
+
setExtensionKey(undefined);
|
|
60
|
+
case 15:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee, null, [[0, 11]]);
|
|
65
|
+
}));
|
|
66
|
+
return function fetchDatasource() {
|
|
67
|
+
return _ref2.apply(this, arguments);
|
|
68
|
+
};
|
|
69
|
+
}();
|
|
70
|
+
void fetchDatasource();
|
|
71
|
+
}, [getDatasourceData, visibleColumnKeys, parameters, datasourceId]);
|
|
72
|
+
return {
|
|
73
|
+
extensionKey: extensionKey
|
|
74
|
+
};
|
|
75
|
+
};
|
|
@@ -5,7 +5,7 @@ import rafSchedule from 'raf-schd';
|
|
|
5
5
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
6
6
|
import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
|
|
7
7
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
8
|
-
import {
|
|
8
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
9
|
import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
10
10
|
import { registerCard } from '../pm-plugins/actions';
|
|
11
11
|
import { isDatasourceNode } from '../utils';
|
|
@@ -108,23 +108,36 @@ _defineProperty(BlockCardComponent, "contextTypes", {
|
|
|
108
108
|
});
|
|
109
109
|
const WrappedBlockCard = Card(BlockCardComponent, UnsupportedBlock);
|
|
110
110
|
export class BlockCard extends ReactNodeView {
|
|
111
|
+
constructor(...args) {
|
|
112
|
+
super(...args);
|
|
113
|
+
_defineProperty(this, "updateContentEditable", (editorViewModeState, divElement) => {
|
|
114
|
+
divElement.contentEditable = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? 'false' : 'true';
|
|
115
|
+
});
|
|
116
|
+
}
|
|
111
117
|
createDomRef() {
|
|
112
118
|
const domRef = document.createElement('div');
|
|
113
119
|
if (this.reactComponentProps.platform !== 'mobile') {
|
|
114
120
|
// workaround Chrome bug in https://product-fabric.atlassian.net/browse/ED-5379
|
|
115
121
|
// see also: https://github.com/ProseMirror/prosemirror/issues/884
|
|
116
|
-
|
|
122
|
+
if (fg('linking-platform-contenteditable-false-live-view')) {
|
|
123
|
+
var _this$reactComponentP, _this$reactComponentP2, _this$reactComponentP3, _this$reactComponentP4;
|
|
124
|
+
this.unsubscribe = (_this$reactComponentP = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP === void 0 ? void 0 : (_this$reactComponentP2 = _this$reactComponentP.editorViewMode) === null || _this$reactComponentP2 === void 0 ? void 0 : _this$reactComponentP2.sharedState.onChange(({
|
|
125
|
+
nextSharedState
|
|
126
|
+
}) => this.updateContentEditable(nextSharedState, domRef));
|
|
127
|
+
this.updateContentEditable((_this$reactComponentP3 = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP3 === void 0 ? void 0 : (_this$reactComponentP4 = _this$reactComponentP3.editorViewMode) === null || _this$reactComponentP4 === void 0 ? void 0 : _this$reactComponentP4.sharedState.currentState(), domRef);
|
|
128
|
+
} else {
|
|
129
|
+
domRef.contentEditable = 'true';
|
|
130
|
+
}
|
|
117
131
|
domRef.setAttribute('spellcheck', 'false');
|
|
118
132
|
}
|
|
119
133
|
return domRef;
|
|
120
134
|
}
|
|
121
|
-
|
|
122
135
|
// Need this function to check if the datasource attribute was added or not to a blockCard.
|
|
123
136
|
// If so, we return false so we can get the node to re-render properly as a datasource node instead.
|
|
124
137
|
// Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
|
|
125
138
|
validUpdate(currentNode, newNode) {
|
|
126
139
|
var _currentNode$attrs, _newNode$attrs;
|
|
127
|
-
if (
|
|
140
|
+
if (fg('platform.linking-platform.editor-datasource-typeguards')) {
|
|
128
141
|
const isCurrentNodeBlockCard = !isDatasourceNode(currentNode);
|
|
129
142
|
const isNewNodeDatasource = isDatasourceNode(newNode);
|
|
130
143
|
|
|
@@ -159,4 +172,8 @@ export class BlockCard extends ReactNodeView {
|
|
|
159
172
|
onClickCallback: onClickCallback
|
|
160
173
|
});
|
|
161
174
|
}
|
|
175
|
+
destroy() {
|
|
176
|
+
var _this$unsubscribe;
|
|
177
|
+
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
|
|
178
|
+
}
|
|
162
179
|
}
|
|
@@ -9,6 +9,7 @@ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
|
9
9
|
import { findOverflowScrollParent, MediaSingle as RichMediaWrapper, UnsupportedBlock } from '@atlaskit/editor-common/ui';
|
|
10
10
|
import { floatingLayouts, isRichMediaInsideOfBlockNode } from '@atlaskit/editor-common/utils';
|
|
11
11
|
import { DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
|
|
12
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
13
|
import { EmbedResizeMessageListener, Card as SmartCard } from '@atlaskit/smart-card';
|
|
13
14
|
import { registerCard } from '../pm-plugins/actions';
|
|
14
15
|
import ResizableEmbedCard from '../ui/ResizableEmbedCard';
|
|
@@ -334,6 +335,12 @@ _defineProperty(EmbedCardComponent, "contextTypes", {
|
|
|
334
335
|
});
|
|
335
336
|
const WrappedBlockCard = Card(EmbedCardComponent, UnsupportedBlock);
|
|
336
337
|
export class EmbedCard extends ReactNodeView {
|
|
338
|
+
constructor(...args) {
|
|
339
|
+
super(...args);
|
|
340
|
+
_defineProperty(this, "updateContentEditable", (editorViewModeState, divElement) => {
|
|
341
|
+
divElement.contentEditable = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? 'false' : 'true';
|
|
342
|
+
});
|
|
343
|
+
}
|
|
337
344
|
viewShouldUpdate(nextNode) {
|
|
338
345
|
if (this.node.attrs !== nextNode.attrs) {
|
|
339
346
|
return true;
|
|
@@ -344,7 +351,15 @@ export class EmbedCard extends ReactNodeView {
|
|
|
344
351
|
const domRef = document.createElement('div');
|
|
345
352
|
if (this.reactComponentProps.platform !== 'mobile') {
|
|
346
353
|
// It is a tradeoff for the bug mentioned that occurs in Chrome: https://product-fabric.atlassian.net/browse/ED-5379, https://github.com/ProseMirror/prosemirror/issues/884
|
|
347
|
-
|
|
354
|
+
if (fg('linking-platform-contenteditable-false-live-view')) {
|
|
355
|
+
var _this$reactComponentP, _this$reactComponentP2, _this$reactComponentP3, _this$reactComponentP4;
|
|
356
|
+
this.unsubscribe = (_this$reactComponentP = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP === void 0 ? void 0 : (_this$reactComponentP2 = _this$reactComponentP.editorViewMode) === null || _this$reactComponentP2 === void 0 ? void 0 : _this$reactComponentP2.sharedState.onChange(({
|
|
357
|
+
nextSharedState
|
|
358
|
+
}) => this.updateContentEditable(nextSharedState, domRef));
|
|
359
|
+
this.updateContentEditable((_this$reactComponentP3 = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP3 === void 0 ? void 0 : (_this$reactComponentP4 = _this$reactComponentP3.editorViewMode) === null || _this$reactComponentP4 === void 0 ? void 0 : _this$reactComponentP4.sharedState.currentState(), domRef);
|
|
360
|
+
} else {
|
|
361
|
+
domRef.contentEditable = 'true';
|
|
362
|
+
}
|
|
348
363
|
domRef.setAttribute('spellcheck', 'false');
|
|
349
364
|
}
|
|
350
365
|
return domRef;
|
|
@@ -372,4 +387,8 @@ export class EmbedCard extends ReactNodeView {
|
|
|
372
387
|
onClickCallback: onClickCallback
|
|
373
388
|
});
|
|
374
389
|
}
|
|
390
|
+
destroy() {
|
|
391
|
+
var _this$unsubscribe;
|
|
392
|
+
(_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
|
|
393
|
+
}
|
|
375
394
|
}
|
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
|
+
};
|