@atlaskit/editor-plugin-card 5.3.0 → 5.3.2
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 +15 -0
- package/dist/cjs/ui/DatasourceDropdownOption.js +101 -0
- package/dist/cjs/ui/HyperlinkToolbarAppearanceDropdown.js +12 -5
- package/dist/cjs/ui/LinkToolbarAppearanceDropdown.js +12 -1
- package/dist/cjs/ui/toolbar.js +66 -71
- package/dist/es2019/ui/DatasourceDropdownOption.js +94 -0
- package/dist/es2019/ui/HyperlinkToolbarAppearanceDropdown.js +12 -5
- package/dist/es2019/ui/LinkToolbarAppearanceDropdown.js +12 -1
- package/dist/es2019/ui/toolbar.js +59 -64
- package/dist/esm/ui/DatasourceDropdownOption.js +94 -0
- package/dist/esm/ui/HyperlinkToolbarAppearanceDropdown.js +12 -5
- package/dist/esm/ui/LinkToolbarAppearanceDropdown.js +12 -1
- package/dist/esm/ui/toolbar.js +66 -71
- package/dist/types/ui/DatasourceDropdownOption.d.ts +28 -0
- package/dist/types/ui/HyperlinkToolbarAppearanceDropdown.d.ts +3 -1
- package/dist/types/ui/LinkToolbarAppearanceDropdown.d.ts +7 -3
- package/dist/types-ts4.5/ui/DatasourceDropdownOption.d.ts +28 -0
- package/dist/types-ts4.5/ui/HyperlinkToolbarAppearanceDropdown.d.ts +3 -1
- package/dist/types-ts4.5/ui/LinkToolbarAppearanceDropdown.d.ts +7 -3
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-card
|
|
2
2
|
|
|
3
|
+
## 5.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#127208](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/127208)
|
|
8
|
+
[`c2951b65d3aac`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c2951b65d3aac) -
|
|
9
|
+
[ux] ED-26896 Move list option to link dropdown
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 5.3.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 5.3.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.datasourceDisplayInformation = exports.DatasourceDropdownOption = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
10
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
+
var _smartLinkList = _interopRequireDefault(require("@atlaskit/icon/core/smart-link-list"));
|
|
12
|
+
var _linkDatasource = require("@atlaskit/link-datasource");
|
|
13
|
+
var _linkProvider = require("@atlaskit/link-provider");
|
|
14
|
+
var _menu = require("@atlaskit/menu");
|
|
15
|
+
var _doc = require("../pm-plugins/doc");
|
|
16
|
+
var _pluginKey = require("../pm-plugins/plugin-key");
|
|
17
|
+
var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
|
|
18
|
+
var datasourceDisplayInformation = exports.datasourceDisplayInformation = {
|
|
19
|
+
title: _messages.cardMessages.datasourceAppearanceTitle,
|
|
20
|
+
icon: _smartLinkList.default,
|
|
21
|
+
// eslint-disable-next-line @atlaskit/editor/no-re-export
|
|
22
|
+
iconFallback: _smartLinkList.default
|
|
23
|
+
};
|
|
24
|
+
var DatasourceDropdownOption = exports.DatasourceDropdownOption = function DatasourceDropdownOption(_ref) {
|
|
25
|
+
var allowDatasource = _ref.allowDatasource,
|
|
26
|
+
intl = _ref.intl,
|
|
27
|
+
url = _ref.url,
|
|
28
|
+
selected = _ref.selected,
|
|
29
|
+
inputMethod = _ref.inputMethod,
|
|
30
|
+
dispatchCommand = _ref.dispatchCommand;
|
|
31
|
+
var cardContext = (0, _linkProvider.useSmartLinkContext)();
|
|
32
|
+
var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
|
|
33
|
+
isRegularCardNode: true,
|
|
34
|
+
url: url,
|
|
35
|
+
cardContext: cardContext
|
|
36
|
+
}),
|
|
37
|
+
datasourceId = _useFetchDatasourceIn.datasourceId,
|
|
38
|
+
parameters = _useFetchDatasourceIn.parameters;
|
|
39
|
+
if (!allowDatasource || !datasourceId || !parameters) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
var onChangeAppearance = function onChangeAppearance(editorState, _dispatch, view) {
|
|
43
|
+
var _state$datasourceStas, _state$datasourceStas2;
|
|
44
|
+
if (!view || !datasourceId || !parameters) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
var state = _pluginKey.pluginKey.getState(editorState);
|
|
48
|
+
var newAdf = (0, _linkDatasource.buildDatasourceAdf)({
|
|
49
|
+
id: datasourceId,
|
|
50
|
+
parameters: parameters,
|
|
51
|
+
views: (_state$datasourceStas = state === null || state === void 0 || (_state$datasourceStas2 = state.datasourceStash[url]) === null || _state$datasourceStas2 === void 0 ? void 0 : _state$datasourceStas2.views) !== null && _state$datasourceStas !== void 0 ? _state$datasourceStas : [{
|
|
52
|
+
type: 'table'
|
|
53
|
+
}]
|
|
54
|
+
}, url);
|
|
55
|
+
var selection = editorState.selection;
|
|
56
|
+
var existingNode;
|
|
57
|
+
// Check if the selection contains a link mark
|
|
58
|
+
var $pos = editorState.doc.resolve(selection.from);
|
|
59
|
+
var isLinkMark = $pos.marks().some(function (mark) {
|
|
60
|
+
return mark.type === editorState.schema.marks.link;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// When selection is a TextNode and a link Mark is present return that node
|
|
64
|
+
if (selection instanceof _state.NodeSelection) {
|
|
65
|
+
existingNode = selection.node;
|
|
66
|
+
} else if (isLinkMark) {
|
|
67
|
+
var _editorState$doc$node;
|
|
68
|
+
existingNode = (_editorState$doc$node = editorState.doc.nodeAt(selection.from)) !== null && _editorState$doc$node !== void 0 ? _editorState$doc$node : undefined;
|
|
69
|
+
}
|
|
70
|
+
if (existingNode) {
|
|
71
|
+
(0, _doc.updateCardViaDatasource)({
|
|
72
|
+
state: editorState,
|
|
73
|
+
node: existingNode,
|
|
74
|
+
newAdf: newAdf,
|
|
75
|
+
view: view,
|
|
76
|
+
sourceEvent: undefined,
|
|
77
|
+
isDeletingConfig: true,
|
|
78
|
+
inputMethod: inputMethod
|
|
79
|
+
});
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
};
|
|
84
|
+
if (url) {
|
|
85
|
+
var _cardContext$store, _urlState$error;
|
|
86
|
+
var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
87
|
+
if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return /*#__PURE__*/_react.default.createElement(_menu.ButtonItem, {
|
|
92
|
+
key: intl.formatMessage(_messages.cardMessages.datasourceAppearanceTitle),
|
|
93
|
+
iconBefore: (0, _smartLinkList.default)({
|
|
94
|
+
label: intl.formatMessage(_messages.cardMessages.datasourceAppearanceTitle)
|
|
95
|
+
}),
|
|
96
|
+
onClick: function onClick() {
|
|
97
|
+
return dispatchCommand(onChangeAppearance);
|
|
98
|
+
},
|
|
99
|
+
isSelected: selected
|
|
100
|
+
}, intl.formatMessage(_messages.cardMessages.datasourceAppearanceTitle));
|
|
101
|
+
};
|
|
@@ -25,8 +25,9 @@ var HyperlinkDropdown = function HyperlinkDropdown(props) {
|
|
|
25
25
|
intl = props.intl,
|
|
26
26
|
editorState = props.editorState,
|
|
27
27
|
cardOptions = props.cardOptions,
|
|
28
|
-
editorAnalyticsApi = props.editorAnalyticsApi
|
|
29
|
-
|
|
28
|
+
editorAnalyticsApi = props.editorAnalyticsApi,
|
|
29
|
+
allowDatasource = props.allowDatasource,
|
|
30
|
+
isDatasourceView = props.isDatasourceView;
|
|
30
31
|
// Ignored via go/ees005
|
|
31
32
|
// eslint-disable-next-line require-await
|
|
32
33
|
var getProvider = /*#__PURE__*/function () {
|
|
@@ -139,9 +140,11 @@ var HyperlinkDropdown = function HyperlinkDropdown(props) {
|
|
|
139
140
|
editorState: editorState,
|
|
140
141
|
allowEmbeds: cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowEmbeds,
|
|
141
142
|
allowBlockCards: cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowBlockCards,
|
|
143
|
+
allowDatasource: allowDatasource,
|
|
142
144
|
editorAnalyticsApi: editorAnalyticsApi,
|
|
143
145
|
dispatchCommand: props.dispatchCommand,
|
|
144
|
-
settingsConfig: props.settingsConfig
|
|
146
|
+
settingsConfig: props.settingsConfig,
|
|
147
|
+
isDatasourceView: isDatasourceView
|
|
145
148
|
});
|
|
146
149
|
};
|
|
147
150
|
var getHyperlinkAppearanceDropdown = exports.getHyperlinkAppearanceDropdown = function getHyperlinkAppearanceDropdown(_ref3) {
|
|
@@ -151,7 +154,9 @@ var getHyperlinkAppearanceDropdown = exports.getHyperlinkAppearanceDropdown = fu
|
|
|
151
154
|
editorAnalyticsApi = _ref3.editorAnalyticsApi,
|
|
152
155
|
editorPluginApi = _ref3.editorPluginApi,
|
|
153
156
|
settingsConfig = _ref3.settingsConfig,
|
|
154
|
-
cardOptions = _ref3.cardOptions
|
|
157
|
+
cardOptions = _ref3.cardOptions,
|
|
158
|
+
allowDatasource = _ref3.allowDatasource,
|
|
159
|
+
isDatasourceView = _ref3.isDatasourceView;
|
|
155
160
|
var alignmentItemOptions = {
|
|
156
161
|
render: function render(props) {
|
|
157
162
|
if (!editorState) {
|
|
@@ -165,7 +170,9 @@ var getHyperlinkAppearanceDropdown = exports.getHyperlinkAppearanceDropdown = fu
|
|
|
165
170
|
editorPluginApi: editorPluginApi,
|
|
166
171
|
dispatchCommand: props.dispatchCommand,
|
|
167
172
|
settingsConfig: settingsConfig,
|
|
168
|
-
cardOptions: cardOptions
|
|
173
|
+
cardOptions: cardOptions,
|
|
174
|
+
allowDatasource: allowDatasource,
|
|
175
|
+
isDatasourceView: isDatasourceView
|
|
169
176
|
});
|
|
170
177
|
},
|
|
171
178
|
width: 200,
|
|
@@ -15,6 +15,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
|
|
|
15
15
|
var _linkProvider = require("@atlaskit/link-provider");
|
|
16
16
|
var _menu = require("@atlaskit/menu");
|
|
17
17
|
var _doc = require("../pm-plugins/doc");
|
|
18
|
+
var _DatasourceDropdownOption = require("./DatasourceDropdownOption");
|
|
18
19
|
var _LinkToolbarAppearance = require("./LinkToolbarAppearance");
|
|
19
20
|
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; }
|
|
20
21
|
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) { (0, _defineProperty2.default)(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; }
|
|
@@ -27,6 +28,7 @@ var LinkAppearanceMenu = exports.LinkAppearanceMenu = function LinkAppearanceMen
|
|
|
27
28
|
allowEmbeds = _ref.allowEmbeds,
|
|
28
29
|
_ref$allowBlockCards = _ref.allowBlockCards,
|
|
29
30
|
allowBlockCards = _ref$allowBlockCards === void 0 ? true : _ref$allowBlockCards,
|
|
31
|
+
allowDatasource = _ref.allowDatasource,
|
|
30
32
|
editorAnalyticsApi = _ref.editorAnalyticsApi,
|
|
31
33
|
_ref$showUpgradeDisco = _ref.showUpgradeDiscoverability,
|
|
32
34
|
showUpgradeDiscoverability = _ref$showUpgradeDisco === void 0 ? true : _ref$showUpgradeDisco,
|
|
@@ -109,6 +111,13 @@ var LinkAppearanceMenu = exports.LinkAppearanceMenu = function LinkAppearanceMen
|
|
|
109
111
|
},
|
|
110
112
|
isSelected: option.selected
|
|
111
113
|
}, option.title);
|
|
114
|
+
}), /*#__PURE__*/_react.default.createElement(_DatasourceDropdownOption.DatasourceDropdownOption, {
|
|
115
|
+
allowDatasource: allowDatasource,
|
|
116
|
+
intl: intl,
|
|
117
|
+
url: url !== null && url !== void 0 ? url : '',
|
|
118
|
+
selected: Boolean(isDatasourceView),
|
|
119
|
+
inputMethod: _analytics.INPUT_METHOD.FLOATING_TB,
|
|
120
|
+
dispatchCommand: dispatchCommand
|
|
112
121
|
})), /*#__PURE__*/_react.default.createElement(_menu.Section, {
|
|
113
122
|
hasSeparator: true
|
|
114
123
|
}, /*#__PURE__*/_react.default.createElement(_menu.LinkItem, {
|
|
@@ -127,6 +136,7 @@ var getLinkAppearanceDropdown = exports.getLinkAppearanceDropdown = function get
|
|
|
127
136
|
allowEmbeds = _ref2.allowEmbeds,
|
|
128
137
|
_ref2$allowBlockCards = _ref2.allowBlockCards,
|
|
129
138
|
allowBlockCards = _ref2$allowBlockCards === void 0 ? true : _ref2$allowBlockCards,
|
|
139
|
+
allowDatasource = _ref2.allowDatasource,
|
|
130
140
|
editorAnalyticsApi = _ref2.editorAnalyticsApi,
|
|
131
141
|
_ref2$showUpgradeDisc = _ref2.showUpgradeDiscoverability,
|
|
132
142
|
showUpgradeDiscoverability = _ref2$showUpgradeDisc === void 0 ? true : _ref2$showUpgradeDisc,
|
|
@@ -144,6 +154,7 @@ var getLinkAppearanceDropdown = exports.getLinkAppearanceDropdown = function get
|
|
|
144
154
|
editorAnalyticsApi: editorAnalyticsApi,
|
|
145
155
|
showUpgradeDiscoverability: showUpgradeDiscoverability,
|
|
146
156
|
isDatasourceView: isDatasourceView,
|
|
157
|
+
allowDatasource: allowDatasource,
|
|
147
158
|
dispatchCommand: props.dispatchCommand,
|
|
148
159
|
settingsConfig: settingsConfig
|
|
149
160
|
});
|
|
@@ -151,7 +162,7 @@ var getLinkAppearanceDropdown = exports.getLinkAppearanceDropdown = function get
|
|
|
151
162
|
width: 200,
|
|
152
163
|
height: 400
|
|
153
164
|
};
|
|
154
|
-
var currentAppearanceDisplayInformation = _card.appearancePropsMap[currentAppearance !== null && currentAppearance !== void 0 ? currentAppearance : 'url'];
|
|
165
|
+
var currentAppearanceDisplayInformation = isDatasourceView ? _DatasourceDropdownOption.datasourceDisplayInformation : _card.appearancePropsMap[currentAppearance !== null && currentAppearance !== void 0 ? currentAppearance : 'url'];
|
|
155
166
|
var alignmentToolbarItem = {
|
|
156
167
|
id: 'card-appearance',
|
|
157
168
|
testId: 'card-appearance-dropdown',
|
package/dist/cjs/ui/toolbar.js
CHANGED
|
@@ -401,9 +401,11 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
|
|
|
401
401
|
allowEmbeds: allowEmbeds,
|
|
402
402
|
allowBlockCards: allowBlockCards,
|
|
403
403
|
editorAnalyticsApi: editorAnalyticsApi,
|
|
404
|
+
allowDatasource: cardOptions.allowDatasource,
|
|
404
405
|
showUpgradeDiscoverability: showUpgradeDiscoverability,
|
|
405
|
-
settingsConfig: getSettingsButton(intl, editorAnalyticsApi, cardOptions.userPreferencesLink)
|
|
406
|
-
|
|
406
|
+
settingsConfig: getSettingsButton(intl, editorAnalyticsApi, cardOptions.userPreferencesLink),
|
|
407
|
+
isDatasourceView: isDatasource
|
|
408
|
+
})], (0, _toConsumableArray2.default)(showDatasourceAppearance && (0, _experiments.editorExperiment)('platform_editor_controls', 'control') ? [{
|
|
407
409
|
type: 'custom',
|
|
408
410
|
fallback: [],
|
|
409
411
|
render: function render(editorView) {
|
|
@@ -491,51 +493,59 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
|
|
|
491
493
|
allowEmbeds = cardOptions.allowEmbeds,
|
|
492
494
|
showUpgradeDiscoverability = cardOptions.showUpgradeDiscoverability;
|
|
493
495
|
var url = metadata.url;
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
496
|
+
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'control')) {
|
|
497
|
+
toolbarItems.push({
|
|
498
|
+
type: 'custom',
|
|
499
|
+
fallback: [],
|
|
500
|
+
render: function render(editorView) {
|
|
501
|
+
return /*#__PURE__*/_react.default.createElement(_LinkToolbarAppearance.LinkToolbarAppearance, {
|
|
502
|
+
key: "link-appearance",
|
|
503
|
+
url: url,
|
|
504
|
+
intl: intl,
|
|
505
|
+
currentAppearance: currentAppearance,
|
|
506
|
+
editorView: editorView,
|
|
507
|
+
editorState: state,
|
|
508
|
+
allowEmbeds: allowEmbeds,
|
|
509
|
+
allowBlockCards: allowBlockCards,
|
|
510
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
511
|
+
showUpgradeDiscoverability: showUpgradeDiscoverability,
|
|
512
|
+
isDatasourceView: true
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
}, {
|
|
516
|
+
type: 'custom',
|
|
517
|
+
fallback: [],
|
|
518
|
+
render: function render(editorView) {
|
|
519
|
+
return /*#__PURE__*/_react.default.createElement(_DatasourceAppearanceButton.DatasourceAppearanceButton, {
|
|
520
|
+
intl: intl,
|
|
521
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
522
|
+
url: url,
|
|
523
|
+
editorView: editorView,
|
|
524
|
+
editorState: state,
|
|
525
|
+
selected: true,
|
|
526
|
+
inputMethod: _analytics.INPUT_METHOD.FLOATING_TB
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
}, {
|
|
530
|
+
type: 'separator'
|
|
531
|
+
});
|
|
532
|
+
} else {
|
|
533
|
+
toolbarItems.push((0, _LinkToolbarAppearanceDropdown.getLinkAppearanceDropdown)({
|
|
534
|
+
url: url,
|
|
535
|
+
intl: intl,
|
|
536
|
+
currentAppearance: currentAppearance,
|
|
537
|
+
editorState: state,
|
|
538
|
+
allowEmbeds: allowEmbeds,
|
|
539
|
+
allowBlockCards: allowBlockCards,
|
|
540
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
541
|
+
allowDatasource: cardOptions.allowDatasource,
|
|
542
|
+
showUpgradeDiscoverability: showUpgradeDiscoverability,
|
|
543
|
+
settingsConfig: getSettingsButton(intl, editorAnalyticsApi, cardOptions.userPreferencesLink),
|
|
544
|
+
isDatasourceView: true
|
|
545
|
+
}), {
|
|
546
|
+
type: 'separator'
|
|
547
|
+
});
|
|
548
|
+
}
|
|
539
549
|
}
|
|
540
550
|
toolbarItems.push({
|
|
541
551
|
type: 'custom',
|
|
@@ -648,29 +658,14 @@ var getStartingToolbarItems = exports.getStartingToolbarItems = function getStar
|
|
|
648
658
|
intl: intl,
|
|
649
659
|
editorState: state,
|
|
650
660
|
editorAnalyticsApi: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions,
|
|
661
|
+
allowDatasource: options.allowDatasource,
|
|
651
662
|
editorPluginApi: api,
|
|
652
663
|
cardOptions: options,
|
|
653
|
-
settingsConfig: getSettingsButton(intl, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.userPreferencesLink)
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
fallback: [],
|
|
657
|
-
render: function render(editorView) {
|
|
658
|
-
var _api$analytics4;
|
|
659
|
-
if (!editorView) {
|
|
660
|
-
return null;
|
|
661
|
-
}
|
|
662
|
-
return /*#__PURE__*/_react.default.createElement(_DatasourceAppearanceButton.DatasourceAppearanceButton, {
|
|
663
|
-
intl: intl,
|
|
664
|
-
editorAnalyticsApi: api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions,
|
|
665
|
-
url: link,
|
|
666
|
-
editorView: editorView,
|
|
667
|
-
editorState: editorView.state,
|
|
668
|
-
inputMethod: _analytics.INPUT_METHOD.FLOATING_TB
|
|
669
|
-
});
|
|
670
|
-
}
|
|
671
|
-
}] : []), [{
|
|
664
|
+
settingsConfig: getSettingsButton(intl, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.userPreferencesLink),
|
|
665
|
+
isDatasourceView: false
|
|
666
|
+
}), {
|
|
672
667
|
type: 'separator'
|
|
673
|
-
}]
|
|
668
|
+
}].concat(editLinkItem);
|
|
674
669
|
}
|
|
675
670
|
return [{
|
|
676
671
|
type: 'custom',
|
|
@@ -687,7 +682,7 @@ var getStartingToolbarItems = exports.getStartingToolbarItems = function getStar
|
|
|
687
682
|
type: 'custom',
|
|
688
683
|
fallback: [],
|
|
689
684
|
render: function render(editorView) {
|
|
690
|
-
var _api$
|
|
685
|
+
var _api$analytics4;
|
|
691
686
|
if (!editorView) {
|
|
692
687
|
return null;
|
|
693
688
|
}
|
|
@@ -698,7 +693,7 @@ var getStartingToolbarItems = exports.getStartingToolbarItems = function getStar
|
|
|
698
693
|
editorView: editorView,
|
|
699
694
|
editorState: editorView.state,
|
|
700
695
|
cardOptions: options,
|
|
701
|
-
editorAnalyticsApi: api === null || api === void 0 || (_api$
|
|
696
|
+
editorAnalyticsApi: api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions,
|
|
702
697
|
editorPluginApi: api
|
|
703
698
|
});
|
|
704
699
|
}
|
|
@@ -712,10 +707,10 @@ var getEndingToolbarItems = exports.getEndingToolbarItems = function getEndingTo
|
|
|
712
707
|
* Or explicit user preferences config in order to enable button
|
|
713
708
|
*/
|
|
714
709
|
if ((options.provider || options.userPreferencesLink) && (0, _experiments.editorExperiment)('platform_editor_controls', 'control')) {
|
|
715
|
-
var _api$
|
|
710
|
+
var _api$analytics5;
|
|
716
711
|
return [{
|
|
717
712
|
type: 'separator'
|
|
718
|
-
}, getSettingsButton(intl, api === null || api === void 0 || (_api$
|
|
713
|
+
}, getSettingsButton(intl, api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions, options.userPreferencesLink)];
|
|
719
714
|
}
|
|
720
715
|
return [];
|
|
721
716
|
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
3
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import SmartLinkListIcon from '@atlaskit/icon/core/smart-link-list';
|
|
5
|
+
import { buildDatasourceAdf } from '@atlaskit/link-datasource';
|
|
6
|
+
import { useSmartLinkContext } from '@atlaskit/link-provider';
|
|
7
|
+
import { ButtonItem } from '@atlaskit/menu';
|
|
8
|
+
import { updateCardViaDatasource } from '../pm-plugins/doc';
|
|
9
|
+
import { pluginKey } from '../pm-plugins/plugin-key';
|
|
10
|
+
import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
|
|
11
|
+
export const datasourceDisplayInformation = {
|
|
12
|
+
title: messages.datasourceAppearanceTitle,
|
|
13
|
+
icon: SmartLinkListIcon,
|
|
14
|
+
// eslint-disable-next-line @atlaskit/editor/no-re-export
|
|
15
|
+
iconFallback: SmartLinkListIcon
|
|
16
|
+
};
|
|
17
|
+
export const DatasourceDropdownOption = ({
|
|
18
|
+
allowDatasource,
|
|
19
|
+
intl,
|
|
20
|
+
url,
|
|
21
|
+
selected,
|
|
22
|
+
inputMethod,
|
|
23
|
+
dispatchCommand
|
|
24
|
+
}) => {
|
|
25
|
+
const cardContext = useSmartLinkContext();
|
|
26
|
+
const {
|
|
27
|
+
datasourceId,
|
|
28
|
+
parameters
|
|
29
|
+
} = useFetchDatasourceInfo({
|
|
30
|
+
isRegularCardNode: true,
|
|
31
|
+
url,
|
|
32
|
+
cardContext
|
|
33
|
+
});
|
|
34
|
+
if (!allowDatasource || !datasourceId || !parameters) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const onChangeAppearance = (editorState, _dispatch, view) => {
|
|
38
|
+
var _state$datasourceStas, _state$datasourceStas2;
|
|
39
|
+
if (!view || !datasourceId || !parameters) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const state = pluginKey.getState(editorState);
|
|
43
|
+
const newAdf = buildDatasourceAdf({
|
|
44
|
+
id: datasourceId,
|
|
45
|
+
parameters,
|
|
46
|
+
views: (_state$datasourceStas = state === null || state === void 0 ? void 0 : (_state$datasourceStas2 = state.datasourceStash[url]) === null || _state$datasourceStas2 === void 0 ? void 0 : _state$datasourceStas2.views) !== null && _state$datasourceStas !== void 0 ? _state$datasourceStas : [{
|
|
47
|
+
type: 'table'
|
|
48
|
+
}]
|
|
49
|
+
}, url);
|
|
50
|
+
const {
|
|
51
|
+
selection
|
|
52
|
+
} = editorState;
|
|
53
|
+
let existingNode;
|
|
54
|
+
// Check if the selection contains a link mark
|
|
55
|
+
const $pos = editorState.doc.resolve(selection.from);
|
|
56
|
+
const isLinkMark = $pos.marks().some(mark => mark.type === editorState.schema.marks.link);
|
|
57
|
+
|
|
58
|
+
// When selection is a TextNode and a link Mark is present return that node
|
|
59
|
+
if (selection instanceof NodeSelection) {
|
|
60
|
+
existingNode = selection.node;
|
|
61
|
+
} else if (isLinkMark) {
|
|
62
|
+
var _editorState$doc$node;
|
|
63
|
+
existingNode = (_editorState$doc$node = editorState.doc.nodeAt(selection.from)) !== null && _editorState$doc$node !== void 0 ? _editorState$doc$node : undefined;
|
|
64
|
+
}
|
|
65
|
+
if (existingNode) {
|
|
66
|
+
updateCardViaDatasource({
|
|
67
|
+
state: editorState,
|
|
68
|
+
node: existingNode,
|
|
69
|
+
newAdf,
|
|
70
|
+
view,
|
|
71
|
+
sourceEvent: undefined,
|
|
72
|
+
isDeletingConfig: true,
|
|
73
|
+
inputMethod
|
|
74
|
+
});
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
if (url) {
|
|
80
|
+
var _cardContext$store, _urlState$error;
|
|
81
|
+
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
82
|
+
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return /*#__PURE__*/React.createElement(ButtonItem, {
|
|
87
|
+
key: intl.formatMessage(messages.datasourceAppearanceTitle),
|
|
88
|
+
iconBefore: SmartLinkListIcon({
|
|
89
|
+
label: intl.formatMessage(messages.datasourceAppearanceTitle)
|
|
90
|
+
}),
|
|
91
|
+
onClick: () => dispatchCommand(onChangeAppearance),
|
|
92
|
+
isSelected: selected
|
|
93
|
+
}, intl.formatMessage(messages.datasourceAppearanceTitle));
|
|
94
|
+
};
|
|
@@ -10,9 +10,10 @@ const HyperlinkDropdown = props => {
|
|
|
10
10
|
intl,
|
|
11
11
|
editorState,
|
|
12
12
|
cardOptions,
|
|
13
|
-
editorAnalyticsApi
|
|
13
|
+
editorAnalyticsApi,
|
|
14
|
+
allowDatasource,
|
|
15
|
+
isDatasourceView
|
|
14
16
|
} = props;
|
|
15
|
-
|
|
16
17
|
// Ignored via go/ees005
|
|
17
18
|
// eslint-disable-next-line require-await
|
|
18
19
|
const getProvider = async () => {
|
|
@@ -62,9 +63,11 @@ const HyperlinkDropdown = props => {
|
|
|
62
63
|
editorState: editorState,
|
|
63
64
|
allowEmbeds: cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowEmbeds,
|
|
64
65
|
allowBlockCards: cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowBlockCards,
|
|
66
|
+
allowDatasource: allowDatasource,
|
|
65
67
|
editorAnalyticsApi: editorAnalyticsApi,
|
|
66
68
|
dispatchCommand: props.dispatchCommand,
|
|
67
|
-
settingsConfig: props.settingsConfig
|
|
69
|
+
settingsConfig: props.settingsConfig,
|
|
70
|
+
isDatasourceView: isDatasourceView
|
|
68
71
|
});
|
|
69
72
|
};
|
|
70
73
|
export const getHyperlinkAppearanceDropdown = ({
|
|
@@ -74,7 +77,9 @@ export const getHyperlinkAppearanceDropdown = ({
|
|
|
74
77
|
editorAnalyticsApi,
|
|
75
78
|
editorPluginApi,
|
|
76
79
|
settingsConfig,
|
|
77
|
-
cardOptions
|
|
80
|
+
cardOptions,
|
|
81
|
+
allowDatasource,
|
|
82
|
+
isDatasourceView
|
|
78
83
|
}) => {
|
|
79
84
|
const alignmentItemOptions = {
|
|
80
85
|
render: props => {
|
|
@@ -89,7 +94,9 @@ export const getHyperlinkAppearanceDropdown = ({
|
|
|
89
94
|
editorPluginApi: editorPluginApi,
|
|
90
95
|
dispatchCommand: props.dispatchCommand,
|
|
91
96
|
settingsConfig: settingsConfig,
|
|
92
|
-
cardOptions: cardOptions
|
|
97
|
+
cardOptions: cardOptions,
|
|
98
|
+
allowDatasource: allowDatasource,
|
|
99
|
+
isDatasourceView: isDatasourceView
|
|
93
100
|
});
|
|
94
101
|
},
|
|
95
102
|
width: 200,
|
|
@@ -7,6 +7,7 @@ import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
|
7
7
|
import { useSmartCardContext } from '@atlaskit/link-provider';
|
|
8
8
|
import { ButtonItem, LinkItem, MenuGroup, Section } from '@atlaskit/menu';
|
|
9
9
|
import { changeSelectedCardToLink, setSelectedCardAppearance } from '../pm-plugins/doc';
|
|
10
|
+
import { DatasourceDropdownOption, datasourceDisplayInformation } from './DatasourceDropdownOption';
|
|
10
11
|
import { getUnavailableMessage } from './LinkToolbarAppearance';
|
|
11
12
|
export const LinkAppearanceMenu = ({
|
|
12
13
|
url,
|
|
@@ -15,6 +16,7 @@ export const LinkAppearanceMenu = ({
|
|
|
15
16
|
editorState,
|
|
16
17
|
allowEmbeds,
|
|
17
18
|
allowBlockCards = true,
|
|
19
|
+
allowDatasource,
|
|
18
20
|
editorAnalyticsApi,
|
|
19
21
|
showUpgradeDiscoverability = true,
|
|
20
22
|
isDatasourceView,
|
|
@@ -93,6 +95,13 @@ export const LinkAppearanceMenu = ({
|
|
|
93
95
|
onClick: () => option.onClick(),
|
|
94
96
|
isSelected: option.selected
|
|
95
97
|
}, option.title);
|
|
98
|
+
}), /*#__PURE__*/React.createElement(DatasourceDropdownOption, {
|
|
99
|
+
allowDatasource: allowDatasource,
|
|
100
|
+
intl: intl,
|
|
101
|
+
url: url !== null && url !== void 0 ? url : '',
|
|
102
|
+
selected: Boolean(isDatasourceView),
|
|
103
|
+
inputMethod: INPUT_METHOD.FLOATING_TB,
|
|
104
|
+
dispatchCommand: dispatchCommand
|
|
96
105
|
})), /*#__PURE__*/React.createElement(Section, {
|
|
97
106
|
hasSeparator: true
|
|
98
107
|
}, /*#__PURE__*/React.createElement(LinkItem, {
|
|
@@ -110,6 +119,7 @@ export const getLinkAppearanceDropdown = ({
|
|
|
110
119
|
editorState,
|
|
111
120
|
allowEmbeds,
|
|
112
121
|
allowBlockCards = true,
|
|
122
|
+
allowDatasource,
|
|
113
123
|
editorAnalyticsApi,
|
|
114
124
|
showUpgradeDiscoverability = true,
|
|
115
125
|
isDatasourceView,
|
|
@@ -127,6 +137,7 @@ export const getLinkAppearanceDropdown = ({
|
|
|
127
137
|
editorAnalyticsApi: editorAnalyticsApi,
|
|
128
138
|
showUpgradeDiscoverability: showUpgradeDiscoverability,
|
|
129
139
|
isDatasourceView: isDatasourceView,
|
|
140
|
+
allowDatasource: allowDatasource,
|
|
130
141
|
dispatchCommand: props.dispatchCommand,
|
|
131
142
|
settingsConfig: settingsConfig
|
|
132
143
|
});
|
|
@@ -134,7 +145,7 @@ export const getLinkAppearanceDropdown = ({
|
|
|
134
145
|
width: 200,
|
|
135
146
|
height: 400
|
|
136
147
|
};
|
|
137
|
-
const currentAppearanceDisplayInformation = appearancePropsMap[currentAppearance !== null && currentAppearance !== void 0 ? currentAppearance : 'url'];
|
|
148
|
+
const currentAppearanceDisplayInformation = isDatasourceView ? datasourceDisplayInformation : appearancePropsMap[currentAppearance !== null && currentAppearance !== void 0 ? currentAppearance : 'url'];
|
|
138
149
|
const alignmentToolbarItem = {
|
|
139
150
|
id: 'card-appearance',
|
|
140
151
|
testId: 'card-appearance-dropdown',
|