@atlaskit/editor-plugin-card 0.16.7 → 0.16.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/pm-plugins/doc.js +3 -3
- package/dist/cjs/toolbar.js +15 -1
- package/dist/cjs/ui/DatasourceAppearanceButton.js +94 -0
- package/dist/cjs/ui/DatasourceModal/index.js +1 -1
- package/dist/es2019/pm-plugins/doc.js +2 -2
- package/dist/es2019/toolbar.js +13 -1
- package/dist/es2019/ui/DatasourceAppearanceButton.js +90 -0
- package/dist/es2019/ui/DatasourceModal/index.js +2 -2
- package/dist/esm/pm-plugins/doc.js +2 -2
- package/dist/esm/toolbar.js +15 -1
- package/dist/esm/ui/DatasourceAppearanceButton.js +86 -0
- package/dist/esm/ui/DatasourceModal/index.js +2 -2
- package/dist/types/pm-plugins/doc.d.ts +1 -1
- package/dist/types/pm-plugins/util/resolve.d.ts +1 -1
- package/dist/types/ui/DatasourceAppearanceButton.d.ts +15 -0
- package/dist/types-ts4.5/pm-plugins/doc.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +1 -1
- package/dist/types-ts4.5/ui/DatasourceAppearanceButton.d.ts +15 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-card
|
|
2
2
|
|
|
3
|
+
## 0.16.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#70612](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70612) [`87457cd97d6b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/87457cd97d6b) - Added a "datasource appearance" button to the toolbar and renamed an internal export.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
3
10
|
## 0.16.7
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.updateCardViaDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
@@ -420,8 +420,8 @@ var getLinkNodeType = exports.getLinkNodeType = function getLinkNodeType(appeara
|
|
|
420
420
|
}
|
|
421
421
|
};
|
|
422
422
|
|
|
423
|
-
// Apply an update made from
|
|
424
|
-
var
|
|
423
|
+
// Apply an update made from a datasource ui interaction
|
|
424
|
+
var updateCardViaDatasource = exports.updateCardViaDatasource = function updateCardViaDatasource(state, node, newAdf, view, sourceEvent) {
|
|
425
425
|
var tr = state.tr,
|
|
426
426
|
from = state.selection.from,
|
|
427
427
|
schemaNodes = state.schema.nodes;
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -25,6 +25,7 @@ var _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"))
|
|
|
25
25
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
26
26
|
var _doc = require("./pm-plugins/doc");
|
|
27
27
|
var _main = require("./pm-plugins/main");
|
|
28
|
+
var _DatasourceAppearanceButton = require("./ui/DatasourceAppearanceButton");
|
|
28
29
|
var _EditDatasourceButton = require("./ui/EditDatasourceButton");
|
|
29
30
|
var _EditLinkToolbar = require("./ui/EditLinkToolbar");
|
|
30
31
|
var _LinkToolbarAppearance = require("./ui/LinkToolbarAppearance");
|
|
@@ -279,6 +280,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
|
|
|
279
280
|
// This code will be executed only for appearances such as "inline", "block" & "embed"
|
|
280
281
|
// For url appearance, please see HyperlinkToolbarAppearanceProps
|
|
281
282
|
if (currentAppearance) {
|
|
283
|
+
var showDatasourceAppearance = (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-appearance-toolbar') && allowDatasource && url;
|
|
282
284
|
toolbarItems.unshift.apply(toolbarItems, (0, _toConsumableArray2.default)(getToolbarViewedItem(url, currentAppearance)).concat([{
|
|
283
285
|
type: 'custom',
|
|
284
286
|
fallback: [],
|
|
@@ -299,7 +301,19 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
|
|
|
299
301
|
showUpgradeDiscoverability: showUpgradeDiscoverability
|
|
300
302
|
});
|
|
301
303
|
}
|
|
302
|
-
}, {
|
|
304
|
+
}], (0, _toConsumableArray2.default)(showDatasourceAppearance ? [{
|
|
305
|
+
type: 'custom',
|
|
306
|
+
fallback: [],
|
|
307
|
+
render: function render(editorView) {
|
|
308
|
+
return /*#__PURE__*/_react.default.createElement(_DatasourceAppearanceButton.DatasourceAppearanceButton, {
|
|
309
|
+
intl: intl,
|
|
310
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
311
|
+
url: url,
|
|
312
|
+
editorView: editorView,
|
|
313
|
+
editorState: state
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}] : []), [{
|
|
303
317
|
type: 'separator'
|
|
304
318
|
}]));
|
|
305
319
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.DatasourceAppearanceButton = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _react2 = require("@emotion/react");
|
|
10
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
11
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
12
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
14
|
+
var _table = _interopRequireDefault(require("@atlaskit/icon/glyph/table"));
|
|
15
|
+
var _linkDatasource = require("@atlaskit/link-datasource");
|
|
16
|
+
var _primitives = require("@atlaskit/primitives");
|
|
17
|
+
var _doc = require("../pm-plugins/doc");
|
|
18
|
+
var _CardContextProvider = require("./CardContextProvider");
|
|
19
|
+
var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
|
|
20
|
+
/** @jsx jsx */
|
|
21
|
+
|
|
22
|
+
var buttonStyles = (0, _react2.css)({
|
|
23
|
+
pointerEvents: 'auto'
|
|
24
|
+
});
|
|
25
|
+
var DatasourceAppearanceButtonWithCardContext = function DatasourceAppearanceButtonWithCardContext(_ref) {
|
|
26
|
+
var cardContext = _ref.cardContext,
|
|
27
|
+
intl = _ref.intl,
|
|
28
|
+
url = _ref.url,
|
|
29
|
+
editorView = _ref.editorView,
|
|
30
|
+
editorState = _ref.editorState;
|
|
31
|
+
var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
|
|
32
|
+
isRegularCardNode: true,
|
|
33
|
+
url: url,
|
|
34
|
+
cardContext: cardContext
|
|
35
|
+
}),
|
|
36
|
+
datasourceId = _useFetchDatasourceIn.datasourceId,
|
|
37
|
+
parameters = _useFetchDatasourceIn.parameters;
|
|
38
|
+
var onChangeAppearance = (0, _react.useCallback)(function () {
|
|
39
|
+
if (!editorView || !datasourceId || !parameters) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
var newAdf = (0, _linkDatasource.buildDatasourceAdf)({
|
|
43
|
+
id: datasourceId,
|
|
44
|
+
parameters: parameters,
|
|
45
|
+
views: [{
|
|
46
|
+
type: 'table'
|
|
47
|
+
}]
|
|
48
|
+
}, url);
|
|
49
|
+
var selection = editorState.selection;
|
|
50
|
+
var existingNode = selection instanceof _state.NodeSelection ? selection.node : undefined;
|
|
51
|
+
if (existingNode) {
|
|
52
|
+
(0, _doc.updateCardViaDatasource)(editorState, existingNode, newAdf, editorView, undefined);
|
|
53
|
+
}
|
|
54
|
+
}, [parameters, datasourceId, editorState, editorView, url]);
|
|
55
|
+
if (!parameters || !datasourceId || !(0, _utils.canRenderDatasource)(datasourceId)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (url) {
|
|
59
|
+
var _cardContext$store, _urlState$error;
|
|
60
|
+
var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
61
|
+
if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
var buttonLabel = intl.formatMessage(_messages.cardMessages.datasourceAppearanceTitle);
|
|
66
|
+
return (0, _react2.jsx)(_primitives.Flex, null, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
|
|
67
|
+
css: buttonStyles,
|
|
68
|
+
title: buttonLabel,
|
|
69
|
+
icon: (0, _react2.jsx)(_table.default, {
|
|
70
|
+
label: buttonLabel
|
|
71
|
+
}),
|
|
72
|
+
selected: false,
|
|
73
|
+
onClick: onChangeAppearance,
|
|
74
|
+
testId: 'card-datasource-appearance-button'
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
var DatasourceAppearanceButton = exports.DatasourceAppearanceButton = function DatasourceAppearanceButton(_ref2) {
|
|
78
|
+
var intl = _ref2.intl,
|
|
79
|
+
editorAnalyticsApi = _ref2.editorAnalyticsApi,
|
|
80
|
+
url = _ref2.url,
|
|
81
|
+
editorView = _ref2.editorView,
|
|
82
|
+
editorState = _ref2.editorState;
|
|
83
|
+
return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref3) {
|
|
84
|
+
var cardContext = _ref3.cardContext;
|
|
85
|
+
return (0, _react2.jsx)(DatasourceAppearanceButtonWithCardContext, {
|
|
86
|
+
url: url,
|
|
87
|
+
intl: intl,
|
|
88
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
89
|
+
editorView: editorView,
|
|
90
|
+
editorState: editorState,
|
|
91
|
+
cardContext: cardContext
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
@@ -50,7 +50,7 @@ var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
if (existingNode) {
|
|
53
|
-
(0, _doc.
|
|
53
|
+
(0, _doc.updateCardViaDatasource)(view.state, existingNode, newAdf, view, analyticEvent);
|
|
54
54
|
} else {
|
|
55
55
|
(0, _doc.insertDatasource)(view.state, newAdf, view, analyticEvent);
|
|
56
56
|
}
|
|
@@ -394,8 +394,8 @@ export const getLinkNodeType = (appearance, linkNodes) => {
|
|
|
394
394
|
}
|
|
395
395
|
};
|
|
396
396
|
|
|
397
|
-
// Apply an update made from
|
|
398
|
-
export const
|
|
397
|
+
// Apply an update made from a datasource ui interaction
|
|
398
|
+
export const updateCardViaDatasource = (state, node, newAdf, view, sourceEvent) => {
|
|
399
399
|
const {
|
|
400
400
|
tr,
|
|
401
401
|
selection: {
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -15,6 +15,7 @@ import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
|
15
15
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
16
16
|
import { changeSelectedCardToText } from './pm-plugins/doc';
|
|
17
17
|
import { pluginKey } from './pm-plugins/main';
|
|
18
|
+
import { DatasourceAppearanceButton } from './ui/DatasourceAppearanceButton';
|
|
18
19
|
import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
|
|
19
20
|
import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
|
|
20
21
|
import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
|
|
@@ -275,6 +276,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
|
|
|
275
276
|
// This code will be executed only for appearances such as "inline", "block" & "embed"
|
|
276
277
|
// For url appearance, please see HyperlinkToolbarAppearanceProps
|
|
277
278
|
if (currentAppearance) {
|
|
279
|
+
const showDatasourceAppearance = getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && allowDatasource && url;
|
|
278
280
|
toolbarItems.unshift(...getToolbarViewedItem(url, currentAppearance), {
|
|
279
281
|
type: 'custom',
|
|
280
282
|
fallback: [],
|
|
@@ -295,7 +297,17 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
|
|
|
295
297
|
showUpgradeDiscoverability: showUpgradeDiscoverability
|
|
296
298
|
});
|
|
297
299
|
}
|
|
298
|
-
}, {
|
|
300
|
+
}, ...(showDatasourceAppearance ? [{
|
|
301
|
+
type: 'custom',
|
|
302
|
+
fallback: [],
|
|
303
|
+
render: editorView => /*#__PURE__*/React.createElement(DatasourceAppearanceButton, {
|
|
304
|
+
intl: intl,
|
|
305
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
306
|
+
url: url,
|
|
307
|
+
editorView: editorView,
|
|
308
|
+
editorState: state
|
|
309
|
+
})
|
|
310
|
+
}] : []), {
|
|
299
311
|
type: 'separator'
|
|
300
312
|
});
|
|
301
313
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
|
+
import { cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
6
|
+
import { canRenderDatasource } from '@atlaskit/editor-common/utils';
|
|
7
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import TableIcon from '@atlaskit/icon/glyph/table';
|
|
9
|
+
import { buildDatasourceAdf } from '@atlaskit/link-datasource';
|
|
10
|
+
import { Flex } from '@atlaskit/primitives';
|
|
11
|
+
import { updateCardViaDatasource } from '../pm-plugins/doc';
|
|
12
|
+
import { CardContextProvider } from './CardContextProvider';
|
|
13
|
+
import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
|
|
14
|
+
const buttonStyles = css({
|
|
15
|
+
pointerEvents: 'auto'
|
|
16
|
+
});
|
|
17
|
+
const DatasourceAppearanceButtonWithCardContext = ({
|
|
18
|
+
cardContext,
|
|
19
|
+
intl,
|
|
20
|
+
url,
|
|
21
|
+
editorView,
|
|
22
|
+
editorState
|
|
23
|
+
}) => {
|
|
24
|
+
const {
|
|
25
|
+
datasourceId,
|
|
26
|
+
parameters
|
|
27
|
+
} = useFetchDatasourceInfo({
|
|
28
|
+
isRegularCardNode: true,
|
|
29
|
+
url,
|
|
30
|
+
cardContext
|
|
31
|
+
});
|
|
32
|
+
const onChangeAppearance = useCallback(() => {
|
|
33
|
+
if (!editorView || !datasourceId || !parameters) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const newAdf = buildDatasourceAdf({
|
|
37
|
+
id: datasourceId,
|
|
38
|
+
parameters,
|
|
39
|
+
views: [{
|
|
40
|
+
type: 'table'
|
|
41
|
+
}]
|
|
42
|
+
}, url);
|
|
43
|
+
const {
|
|
44
|
+
selection
|
|
45
|
+
} = editorState;
|
|
46
|
+
const existingNode = selection instanceof NodeSelection ? selection.node : undefined;
|
|
47
|
+
if (existingNode) {
|
|
48
|
+
updateCardViaDatasource(editorState, existingNode, newAdf, editorView, undefined);
|
|
49
|
+
}
|
|
50
|
+
}, [parameters, datasourceId, editorState, editorView, url]);
|
|
51
|
+
if (!parameters || !datasourceId || !canRenderDatasource(datasourceId)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (url) {
|
|
55
|
+
var _cardContext$store, _urlState$error;
|
|
56
|
+
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
57
|
+
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const buttonLabel = intl.formatMessage(messages.datasourceAppearanceTitle);
|
|
62
|
+
return jsx(Flex, null, jsx(Button, {
|
|
63
|
+
css: buttonStyles,
|
|
64
|
+
title: buttonLabel,
|
|
65
|
+
icon: jsx(TableIcon, {
|
|
66
|
+
label: buttonLabel
|
|
67
|
+
}),
|
|
68
|
+
selected: false,
|
|
69
|
+
onClick: onChangeAppearance,
|
|
70
|
+
testId: 'card-datasource-appearance-button'
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
export const DatasourceAppearanceButton = ({
|
|
74
|
+
intl,
|
|
75
|
+
editorAnalyticsApi,
|
|
76
|
+
url,
|
|
77
|
+
editorView,
|
|
78
|
+
editorState
|
|
79
|
+
}) => {
|
|
80
|
+
return jsx(CardContextProvider, null, ({
|
|
81
|
+
cardContext
|
|
82
|
+
}) => jsx(DatasourceAppearanceButtonWithCardContext, {
|
|
83
|
+
url: url,
|
|
84
|
+
intl: intl,
|
|
85
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
86
|
+
editorView: editorView,
|
|
87
|
+
editorState: editorState,
|
|
88
|
+
cardContext: cardContext
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
@@ -2,7 +2,7 @@ import React, { useCallback } from 'react';
|
|
|
2
2
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
|
|
4
4
|
import { hideDatasourceModal } from '../../pm-plugins/actions';
|
|
5
|
-
import { insertDatasource,
|
|
5
|
+
import { insertDatasource, updateCardViaDatasource } from '../../pm-plugins/doc';
|
|
6
6
|
import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
|
|
7
7
|
export const DatasourceModal = ({
|
|
8
8
|
view,
|
|
@@ -42,7 +42,7 @@ export const DatasourceModal = ({
|
|
|
42
42
|
}));
|
|
43
43
|
}
|
|
44
44
|
if (existingNode) {
|
|
45
|
-
|
|
45
|
+
updateCardViaDatasource(view.state, existingNode, newAdf, view, analyticEvent);
|
|
46
46
|
} else {
|
|
47
47
|
insertDatasource(view.state, newAdf, view, analyticEvent);
|
|
48
48
|
}
|
|
@@ -413,8 +413,8 @@ export var getLinkNodeType = function getLinkNodeType(appearance, linkNodes) {
|
|
|
413
413
|
}
|
|
414
414
|
};
|
|
415
415
|
|
|
416
|
-
// Apply an update made from
|
|
417
|
-
export var
|
|
416
|
+
// Apply an update made from a datasource ui interaction
|
|
417
|
+
export var updateCardViaDatasource = function updateCardViaDatasource(state, node, newAdf, view, sourceEvent) {
|
|
418
418
|
var tr = state.tr,
|
|
419
419
|
from = state.selection.from,
|
|
420
420
|
schemaNodes = state.schema.nodes;
|
package/dist/esm/toolbar.js
CHANGED
|
@@ -19,6 +19,7 @@ import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
|
19
19
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
20
20
|
import { changeSelectedCardToText } from './pm-plugins/doc';
|
|
21
21
|
import { pluginKey } from './pm-plugins/main';
|
|
22
|
+
import { DatasourceAppearanceButton } from './ui/DatasourceAppearanceButton';
|
|
22
23
|
import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
|
|
23
24
|
import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
|
|
24
25
|
import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
|
|
@@ -269,6 +270,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
|
|
|
269
270
|
// This code will be executed only for appearances such as "inline", "block" & "embed"
|
|
270
271
|
// For url appearance, please see HyperlinkToolbarAppearanceProps
|
|
271
272
|
if (currentAppearance) {
|
|
273
|
+
var showDatasourceAppearance = getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && allowDatasource && url;
|
|
272
274
|
toolbarItems.unshift.apply(toolbarItems, _toConsumableArray(getToolbarViewedItem(url, currentAppearance)).concat([{
|
|
273
275
|
type: 'custom',
|
|
274
276
|
fallback: [],
|
|
@@ -289,7 +291,19 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
|
|
|
289
291
|
showUpgradeDiscoverability: showUpgradeDiscoverability
|
|
290
292
|
});
|
|
291
293
|
}
|
|
292
|
-
}, {
|
|
294
|
+
}], _toConsumableArray(showDatasourceAppearance ? [{
|
|
295
|
+
type: 'custom',
|
|
296
|
+
fallback: [],
|
|
297
|
+
render: function render(editorView) {
|
|
298
|
+
return /*#__PURE__*/React.createElement(DatasourceAppearanceButton, {
|
|
299
|
+
intl: intl,
|
|
300
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
301
|
+
url: url,
|
|
302
|
+
editorView: editorView,
|
|
303
|
+
editorState: state
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}] : []), [{
|
|
293
307
|
type: 'separator'
|
|
294
308
|
}]));
|
|
295
309
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
|
+
import { cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
|
+
import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
|
|
6
|
+
import { canRenderDatasource } from '@atlaskit/editor-common/utils';
|
|
7
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
8
|
+
import TableIcon from '@atlaskit/icon/glyph/table';
|
|
9
|
+
import { buildDatasourceAdf } from '@atlaskit/link-datasource';
|
|
10
|
+
import { Flex } from '@atlaskit/primitives';
|
|
11
|
+
import { updateCardViaDatasource } from '../pm-plugins/doc';
|
|
12
|
+
import { CardContextProvider } from './CardContextProvider';
|
|
13
|
+
import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
|
|
14
|
+
var buttonStyles = css({
|
|
15
|
+
pointerEvents: 'auto'
|
|
16
|
+
});
|
|
17
|
+
var DatasourceAppearanceButtonWithCardContext = function DatasourceAppearanceButtonWithCardContext(_ref) {
|
|
18
|
+
var cardContext = _ref.cardContext,
|
|
19
|
+
intl = _ref.intl,
|
|
20
|
+
url = _ref.url,
|
|
21
|
+
editorView = _ref.editorView,
|
|
22
|
+
editorState = _ref.editorState;
|
|
23
|
+
var _useFetchDatasourceIn = useFetchDatasourceInfo({
|
|
24
|
+
isRegularCardNode: true,
|
|
25
|
+
url: url,
|
|
26
|
+
cardContext: cardContext
|
|
27
|
+
}),
|
|
28
|
+
datasourceId = _useFetchDatasourceIn.datasourceId,
|
|
29
|
+
parameters = _useFetchDatasourceIn.parameters;
|
|
30
|
+
var onChangeAppearance = useCallback(function () {
|
|
31
|
+
if (!editorView || !datasourceId || !parameters) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
var newAdf = buildDatasourceAdf({
|
|
35
|
+
id: datasourceId,
|
|
36
|
+
parameters: parameters,
|
|
37
|
+
views: [{
|
|
38
|
+
type: 'table'
|
|
39
|
+
}]
|
|
40
|
+
}, url);
|
|
41
|
+
var selection = editorState.selection;
|
|
42
|
+
var existingNode = selection instanceof NodeSelection ? selection.node : undefined;
|
|
43
|
+
if (existingNode) {
|
|
44
|
+
updateCardViaDatasource(editorState, existingNode, newAdf, editorView, undefined);
|
|
45
|
+
}
|
|
46
|
+
}, [parameters, datasourceId, editorState, editorView, url]);
|
|
47
|
+
if (!parameters || !datasourceId || !canRenderDatasource(datasourceId)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
if (url) {
|
|
51
|
+
var _cardContext$store, _urlState$error;
|
|
52
|
+
var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
53
|
+
if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
var buttonLabel = intl.formatMessage(messages.datasourceAppearanceTitle);
|
|
58
|
+
return jsx(Flex, null, jsx(Button, {
|
|
59
|
+
css: buttonStyles,
|
|
60
|
+
title: buttonLabel,
|
|
61
|
+
icon: jsx(TableIcon, {
|
|
62
|
+
label: buttonLabel
|
|
63
|
+
}),
|
|
64
|
+
selected: false,
|
|
65
|
+
onClick: onChangeAppearance,
|
|
66
|
+
testId: 'card-datasource-appearance-button'
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
export var DatasourceAppearanceButton = function DatasourceAppearanceButton(_ref2) {
|
|
70
|
+
var intl = _ref2.intl,
|
|
71
|
+
editorAnalyticsApi = _ref2.editorAnalyticsApi,
|
|
72
|
+
url = _ref2.url,
|
|
73
|
+
editorView = _ref2.editorView,
|
|
74
|
+
editorState = _ref2.editorState;
|
|
75
|
+
return jsx(CardContextProvider, null, function (_ref3) {
|
|
76
|
+
var cardContext = _ref3.cardContext;
|
|
77
|
+
return jsx(DatasourceAppearanceButtonWithCardContext, {
|
|
78
|
+
url: url,
|
|
79
|
+
intl: intl,
|
|
80
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
81
|
+
editorView: editorView,
|
|
82
|
+
editorState: editorState,
|
|
83
|
+
cardContext: cardContext
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
@@ -6,7 +6,7 @@ import React, { useCallback } from 'react';
|
|
|
6
6
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
|
|
8
8
|
import { hideDatasourceModal } from '../../pm-plugins/actions';
|
|
9
|
-
import { insertDatasource,
|
|
9
|
+
import { insertDatasource, updateCardViaDatasource } from '../../pm-plugins/doc';
|
|
10
10
|
import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
|
|
11
11
|
export var DatasourceModal = function DatasourceModal(_ref) {
|
|
12
12
|
var _existingNode$attrs, _existingNode$attrs2;
|
|
@@ -40,7 +40,7 @@ export var DatasourceModal = function DatasourceModal(_ref) {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
if (existingNode) {
|
|
43
|
-
|
|
43
|
+
updateCardViaDatasource(view.state, existingNode, newAdf, view, analyticEvent);
|
|
44
44
|
} else {
|
|
45
45
|
insertDatasource(view.state, newAdf, view, analyticEvent);
|
|
46
46
|
}
|
|
@@ -23,5 +23,5 @@ export type LinkNodes = {
|
|
|
23
23
|
[key in 'inlineCard' | 'blockCard' | 'embedCard']: NodeType;
|
|
24
24
|
};
|
|
25
25
|
export declare const getLinkNodeType: (appearance: CardAppearance, linkNodes: LinkNodes) => NodeType;
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const updateCardViaDatasource: (state: EditorState, node: Node, newAdf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
|
|
27
27
|
export declare const insertDatasource: (state: EditorState, adf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
|
|
@@ -4,5 +4,5 @@ import type { CardOptions } from '@atlaskit/editor-common/card';
|
|
|
4
4
|
import type { CardProvider, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
|
|
5
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import type { Request } from '../../types';
|
|
7
|
-
export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf
|
|
7
|
+
export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf<Record<string, unknown>>>;
|
|
8
8
|
export declare const handleProvider: (_: 'cardProvider', provider: Promise<CardProvider> | undefined, view: EditorView) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from '@emotion/react';
|
|
2
|
+
import type { IntlShape } from 'react-intl-next';
|
|
3
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { CardContext } from '@atlaskit/link-provider';
|
|
7
|
+
export interface DatasourceAppearanceButtonProps {
|
|
8
|
+
intl: IntlShape;
|
|
9
|
+
editorAnalyticsApi?: EditorAnalyticsAPI;
|
|
10
|
+
url: string;
|
|
11
|
+
editorView?: EditorView;
|
|
12
|
+
editorState: EditorState;
|
|
13
|
+
cardContext?: CardContext;
|
|
14
|
+
}
|
|
15
|
+
export declare const DatasourceAppearanceButton: ({ intl, editorAnalyticsApi, url, editorView, editorState, }: DatasourceAppearanceButtonProps) => jsx.JSX.Element;
|
|
@@ -23,5 +23,5 @@ export type LinkNodes = {
|
|
|
23
23
|
[key in 'inlineCard' | 'blockCard' | 'embedCard']: NodeType;
|
|
24
24
|
};
|
|
25
25
|
export declare const getLinkNodeType: (appearance: CardAppearance, linkNodes: LinkNodes) => NodeType;
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const updateCardViaDatasource: (state: EditorState, node: Node, newAdf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
|
|
27
27
|
export declare const insertDatasource: (state: EditorState, adf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
|
|
@@ -4,5 +4,5 @@ import type { CardOptions } from '@atlaskit/editor-common/card';
|
|
|
4
4
|
import type { CardProvider, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
|
|
5
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
6
|
import type { Request } from '../../types';
|
|
7
|
-
export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf
|
|
7
|
+
export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf<Record<string, unknown>>>;
|
|
8
8
|
export declare const handleProvider: (_: 'cardProvider', provider: Promise<CardProvider> | undefined, view: EditorView) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from '@emotion/react';
|
|
2
|
+
import type { IntlShape } from 'react-intl-next';
|
|
3
|
+
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
4
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import type { CardContext } from '@atlaskit/link-provider';
|
|
7
|
+
export interface DatasourceAppearanceButtonProps {
|
|
8
|
+
intl: IntlShape;
|
|
9
|
+
editorAnalyticsApi?: EditorAnalyticsAPI;
|
|
10
|
+
url: string;
|
|
11
|
+
editorView?: EditorView;
|
|
12
|
+
editorState: EditorState;
|
|
13
|
+
cardContext?: CardContext;
|
|
14
|
+
}
|
|
15
|
+
export declare const DatasourceAppearanceButton: ({ intl, editorAnalyticsApi, url, editorView, editorState, }: DatasourceAppearanceButtonProps) => jsx.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-card",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.8",
|
|
4
4
|
"description": "Card plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@atlaskit/adf-schema": "^35.3.0",
|
|
36
36
|
"@atlaskit/analytics-next": "^9.1.0",
|
|
37
37
|
"@atlaskit/custom-steps": "^0.0.11",
|
|
38
|
-
"@atlaskit/editor-common": "^77.
|
|
38
|
+
"@atlaskit/editor-common": "^77.2.0",
|
|
39
39
|
"@atlaskit/editor-plugin-analytics": "^0.4.0",
|
|
40
40
|
"@atlaskit/editor-plugin-decorations": "^0.2.0",
|
|
41
41
|
"@atlaskit/editor-plugin-feature-flags": "^1.0.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@atlaskit/icon": "^22.0.0",
|
|
50
50
|
"@atlaskit/link-analytics": "^8.3.0",
|
|
51
51
|
"@atlaskit/link-client-extension": "^1.8.0",
|
|
52
|
-
"@atlaskit/link-datasource": "^1.
|
|
52
|
+
"@atlaskit/link-datasource": "^1.22.0",
|
|
53
53
|
"@atlaskit/linking-common": "^5.3.0",
|
|
54
54
|
"@atlaskit/linking-types": "^8.6.0",
|
|
55
55
|
"@atlaskit/platform-feature-flags": "^0.2.0",
|
|
@@ -115,6 +115,9 @@
|
|
|
115
115
|
},
|
|
116
116
|
"platform.editor.show-embed-card-frame-renderer": {
|
|
117
117
|
"type": "boolean"
|
|
118
|
+
},
|
|
119
|
+
"platform.linking-platform.enable-datasource-appearance-toolbar": {
|
|
120
|
+
"type": "boolean"
|
|
118
121
|
}
|
|
119
122
|
},
|
|
120
123
|
"stricter": {
|