@atlaskit/editor-plugin-card 1.14.5 → 1.15.1

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.
Files changed (36) hide show
  1. package/.eslintrc.js +12 -12
  2. package/CHANGELOG.md +693 -684
  3. package/LICENSE.md +6 -8
  4. package/dist/cjs/pm-plugins/doc.js +21 -1
  5. package/dist/cjs/toolbar.js +36 -6
  6. package/dist/cjs/ui/EditDatasourceButton.js +5 -26
  7. package/dist/cjs/ui/EditToolbarButton.js +139 -0
  8. package/dist/cjs/utils.js +4 -1
  9. package/dist/es2019/pm-plugins/doc.js +22 -2
  10. package/dist/es2019/toolbar.js +33 -7
  11. package/dist/es2019/ui/EditDatasourceButton.js +1 -22
  12. package/dist/es2019/ui/EditToolbarButton.js +123 -0
  13. package/dist/es2019/utils.js +3 -0
  14. package/dist/esm/pm-plugins/doc.js +22 -2
  15. package/dist/esm/toolbar.js +38 -8
  16. package/dist/esm/ui/EditDatasourceButton.js +1 -22
  17. package/dist/esm/ui/EditToolbarButton.js +131 -0
  18. package/dist/esm/utils.js +3 -0
  19. package/dist/types/pm-plugins/doc.d.ts +1 -0
  20. package/dist/types/ui/EditDatasourceButton.d.ts +0 -2
  21. package/dist/types/ui/EditToolbarButton.d.ts +15 -0
  22. package/dist/types/ui/EditorAnalyticsContext.d.ts +1 -1
  23. package/dist/types/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +1 -1
  24. package/dist/types/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +1 -1
  25. package/dist/types/ui/EditorSmartCardEvents.d.ts +1 -1
  26. package/dist/types/utils.d.ts +2 -0
  27. package/dist/types-ts4.5/pm-plugins/doc.d.ts +1 -0
  28. package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +0 -2
  29. package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +15 -0
  30. package/dist/types-ts4.5/ui/EditorAnalyticsContext.d.ts +1 -1
  31. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +1 -1
  32. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +1 -1
  33. package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +1 -1
  34. package/dist/types-ts4.5/utils.d.ts +2 -0
  35. package/package.json +8 -6
  36. package/report.api.md +94 -96
package/LICENSE.md CHANGED
@@ -1,13 +1,11 @@
1
1
  Copyright 2023 Atlassian Pty Ltd
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
4
+ compliance with the License. You may obtain a copy of the License at
6
5
 
7
6
  http://www.apache.org/licenses/LICENSE-2.0
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is
9
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10
+ implied. See the License for the specific language governing permissions and limitations under the
11
+ License.
@@ -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.updateCardViaDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.getAttrsForAppearance = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
7
+ exports.updateCardViaDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.getAttrsForAppearance = exports.editDatasource = 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"));
@@ -567,4 +567,24 @@ var updateDatasourceStash = function updateDatasourceStash(tr, selectedNode) {
567
567
  }
568
568
  }
569
569
  }
570
+ };
571
+ var editDatasource = exports.editDatasource = function editDatasource(datasourceId, _editorAnalyticsApi) {
572
+ return function (state, dispatch) {
573
+ var datasourceType = (0, _utils.getDatasourceType)(datasourceId);
574
+ if (dispatch && datasourceType) {
575
+ var tr = state.tr;
576
+ (0, _actions.showDatasourceModal)(datasourceType)(tr);
577
+ // editorAnalyticsApi?.attachAnalyticsEvent(
578
+ // buildEditLinkPayload(
579
+ // type as
580
+ // | ACTION_SUBJECT_ID.CARD_INLINE
581
+ // | ACTION_SUBJECT_ID.CARD_BLOCK
582
+ // | ACTION_SUBJECT_ID.EMBEDS,
583
+ // ),
584
+ // )(tr);
585
+ dispatch(tr);
586
+ return true;
587
+ }
588
+ return false;
589
+ };
570
590
  };
@@ -29,6 +29,7 @@ var _main = require("./pm-plugins/main");
29
29
  var _DatasourceAppearanceButton = require("./ui/DatasourceAppearanceButton");
30
30
  var _EditDatasourceButton = require("./ui/EditDatasourceButton");
31
31
  var _EditLinkToolbar = require("./ui/EditLinkToolbar");
32
+ var _EditToolbarButton = require("./ui/EditToolbarButton");
32
33
  var _LinkToolbarAppearance = require("./ui/LinkToolbarAppearance");
33
34
  var _ToolbarViewedEvent = require("./ui/ToolbarViewedEvent");
34
35
  var _utils3 = require("./utils");
@@ -225,7 +226,20 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
225
226
  return getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, node.attrs.datasource.id, state, cardOptions, currentAppearance, platform, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.card) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions);
226
227
  } else {
227
228
  var inlineCard = state.schema.nodes.inlineCard;
228
- var toolbarItems = [{
229
+ var toolbarItems = [(0, _utils3.isEditDropdownEnabled)(platform) && cardOptions.allowDatasource ? {
230
+ type: 'custom',
231
+ fallback: [],
232
+ render: function render(editorView) {
233
+ return /*#__PURE__*/_react.default.createElement(_EditToolbarButton.EditToolbarButton, {
234
+ key: "edit-toolbar-item",
235
+ url: url,
236
+ intl: intl,
237
+ editorAnalyticsApi: editorAnalyticsApi,
238
+ editorView: editorView,
239
+ onLinkEditClick: (0, _EditLinkToolbar.editLink)(editorAnalyticsApi)
240
+ });
241
+ }
242
+ } : {
229
243
  id: 'editor.link.edit',
230
244
  type: 'button',
231
245
  selected: false,
@@ -324,7 +338,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
324
338
  type: 'separator'
325
339
  }]));
326
340
  }
327
- var shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource;
341
+ var shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource && !(0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar');
328
342
  if (shouldShowDatasourceEditButton) {
329
343
  toolbarItems.unshift({
330
344
  type: 'custom',
@@ -384,7 +398,7 @@ var getSettingsButtonGroup = exports.getSettingsButtonGroup = function getSettin
384
398
  var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId, state, cardOptions, currentAppearance, platform, cardActions) {
385
399
  var _node$attrs3;
386
400
  var toolbarItems = [];
387
- if ((0, _utils3.isDatasourceConfigEditable)(datasourceId)) {
401
+ if ((0, _utils3.isDatasourceConfigEditable)(datasourceId) && !(0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar')) {
388
402
  toolbarItems.push({
389
403
  id: 'editor.edit.datasource',
390
404
  type: 'button',
@@ -392,12 +406,28 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
392
406
  metadata: metadata,
393
407
  className: 'datasource-edit',
394
408
  title: intl.formatMessage(_messages.linkToolbarMessages.editDatasource),
395
- onClick: (0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi),
409
+ onClick: (0, _doc.editDatasource)(datasourceId, editorAnalyticsApi),
396
410
  testId: 'datasource-edit-button'
397
411
  }, {
398
412
  type: 'separator'
399
413
  });
400
414
  }
415
+ var editDropdownWithSeparator = [{
416
+ type: 'custom',
417
+ fallback: [],
418
+ render: function render(editorView) {
419
+ return /*#__PURE__*/_react.default.createElement(_EditToolbarButton.EditToolbarButton, {
420
+ key: "edit-toolbar-item",
421
+ url: metadata.url,
422
+ intl: intl,
423
+ editorAnalyticsApi: editorAnalyticsApi,
424
+ editorView: editorView,
425
+ onLinkEditClick: (0, _EditLinkToolbar.editLink)(editorAnalyticsApi)
426
+ });
427
+ }
428
+ }, {
429
+ type: 'separator'
430
+ }];
401
431
  var canShowMainToolbar = function canShowMainToolbar() {
402
432
  // we do not show smart-link or the datasource icons when the node does not have a url to resolve
403
433
  if (!metadata.url) {
@@ -417,7 +447,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
417
447
  allowEmbeds = cardOptions.allowEmbeds,
418
448
  showUpgradeDiscoverability = cardOptions.showUpgradeDiscoverability;
419
449
  var url = metadata.url;
420
- toolbarItems.push({
450
+ toolbarItems.push.apply(toolbarItems, [{
421
451
  type: 'custom',
422
452
  fallback: [],
423
453
  render: function render(editorView) {
@@ -453,7 +483,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
453
483
  }
454
484
  }, {
455
485
  type: 'separator'
456
- });
486
+ }].concat((0, _toConsumableArray2.default)((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') ? [].concat(editDropdownWithSeparator) : [])));
457
487
  }
458
488
  if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
459
489
  toolbarItems.push({
@@ -3,14 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.editDatasource = exports.EditDatasourceButton = void 0;
6
+ exports.EditDatasourceButton = void 0;
7
7
  var _react = require("@emotion/react");
8
8
  var _messages = require("@atlaskit/editor-common/messages");
9
9
  var _ui = require("@atlaskit/editor-common/ui");
10
- var _utils = require("@atlaskit/editor-common/utils");
11
10
  var _primitives = require("@atlaskit/primitives");
12
- var _actions = require("../pm-plugins/actions");
13
- var _utils2 = require("../utils");
11
+ var _doc = require("../pm-plugins/doc");
12
+ var _utils = require("../utils");
14
13
  var _CardContextProvider = require("./CardContextProvider");
15
14
  var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
16
15
  /** @jsx jsx */
@@ -34,7 +33,7 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
34
33
  cardContext: cardContext
35
34
  }),
36
35
  datasourceId = _useFetchDatasourceIn.datasourceId;
37
- if (!datasourceId || !(0, _utils2.isDatasourceConfigEditable)(datasourceId)) {
36
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
38
37
  return null;
39
38
  }
40
39
  if (url) {
@@ -56,7 +55,7 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
56
55
  icon: (0, _react.jsx)(_ui.SmallerEditIcon, null),
57
56
  selected: false,
58
57
  onClick: function onClick() {
59
- return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
58
+ return dispatchCommand((0, _doc.editDatasource)(datasourceId, editorAnalyticsApi));
60
59
  },
61
60
  testId: 'card-edit-datasource-button'
62
61
  }), (0, _react.jsx)(_ui.FloatingToolbarSeparator, null));
@@ -78,24 +77,4 @@ var EditDatasourceButton = exports.EditDatasourceButton = function EditDatasourc
78
77
  cardContext: cardContext
79
78
  });
80
79
  });
81
- };
82
- var editDatasource = exports.editDatasource = function editDatasource(datasourceId, editorAnalyticsApi) {
83
- return function (state, dispatch) {
84
- var datasourceType = (0, _utils.getDatasourceType)(datasourceId);
85
- if (dispatch && datasourceType) {
86
- var tr = state.tr;
87
- (0, _actions.showDatasourceModal)(datasourceType)(tr);
88
- // editorAnalyticsApi?.attachAnalyticsEvent(
89
- // buildEditLinkPayload(
90
- // type as
91
- // | ACTION_SUBJECT_ID.CARD_INLINE
92
- // | ACTION_SUBJECT_ID.CARD_BLOCK
93
- // | ACTION_SUBJECT_ID.EMBEDS,
94
- // ),
95
- // )(tr);
96
- dispatch(tr);
97
- return true;
98
- }
99
- return false;
100
- };
101
80
  };
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.EditToolbarButton = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
+ var _reactIntlNext = require("react-intl-next");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _ui = require("@atlaskit/editor-common/ui");
14
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
15
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
16
+ var _menu = require("@atlaskit/menu");
17
+ var _primitives = require("@atlaskit/primitives");
18
+ var _doc = require("../pm-plugins/doc");
19
+ var _utils = require("../utils");
20
+ var _CardContextProvider = require("./CardContextProvider");
21
+ var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
22
+ /** @jsx jsx */
23
+
24
+ var dropdownExpandContainer = (0, _react2.css)({
25
+ margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
26
+ });
27
+ var EditButtonWithCardContext = function EditButtonWithCardContext(_ref) {
28
+ var cardContext = _ref.cardContext,
29
+ intl = _ref.intl,
30
+ editorAnalyticsApi = _ref.editorAnalyticsApi,
31
+ url = _ref.url,
32
+ editorView = _ref.editorView,
33
+ onLinkEditClick = _ref.onLinkEditClick;
34
+ var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
35
+ isRegularCardNode: true,
36
+ url: url,
37
+ cardContext: cardContext
38
+ }),
39
+ datasourceId = _useFetchDatasourceIn.datasourceId;
40
+ var _useState = (0, _react.useState)(false),
41
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
+ isOpen = _useState2[0],
43
+ setIsOpen = _useState2[1];
44
+ var containerRef = (0, _react.useRef)();
45
+ var toggleOpen = function toggleOpen() {
46
+ return setIsOpen(function (open) {
47
+ return !open;
48
+ });
49
+ };
50
+ var onClose = function onClose() {
51
+ return setIsOpen(false);
52
+ };
53
+ var dispatchCommand = (0, _react.useCallback)(function (fn) {
54
+ if (editorView) {
55
+ fn === null || fn === void 0 || fn(editorView.state, editorView.dispatch);
56
+ if (!editorView.hasFocus()) {
57
+ editorView.focus();
58
+ }
59
+ }
60
+ }, [editorView]);
61
+ var onEditLink = (0, _react.useCallback)(function () {
62
+ dispatchCommand(onLinkEditClick);
63
+ }, [dispatchCommand, onLinkEditClick]);
64
+ var shouldFallbackToEditButton = (0, _react.useMemo)(function () {
65
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
66
+ return true;
67
+ }
68
+ if (url) {
69
+ var _cardContext$store, _urlState$error;
70
+ var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
71
+ if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
72
+ return true;
73
+ }
74
+ }
75
+ return false;
76
+ }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
77
+ var onEditDatasource = (0, _react.useCallback)(function () {
78
+ if (datasourceId) {
79
+ dispatchCommand((0, _doc.editDatasource)(datasourceId, editorAnalyticsApi));
80
+ }
81
+ }, [dispatchCommand, datasourceId, editorAnalyticsApi]);
82
+ if (shouldFallbackToEditButton) {
83
+ return (0, _react2.jsx)(_ui.FloatingToolbarButton, {
84
+ testId: "edit-link",
85
+ onClick: onEditLink
86
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.linkToolbarMessages.editLink));
87
+ }
88
+ var trigger = (0, _react2.jsx)(_ui.FloatingToolbarButton, {
89
+ testId: "edit-dropdown-trigger",
90
+ iconAfter: (0, _react2.jsx)("span", {
91
+ css: dropdownExpandContainer
92
+ }, (0, _react2.jsx)(_chevronDown.default, {
93
+ label: intl.formatMessage(_messages.cardMessages.editDropdownTriggerTitle)
94
+ })),
95
+ onClick: toggleOpen,
96
+ selected: isOpen,
97
+ disabled: false,
98
+ ariaHasPopup: true
99
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownTriggerTitle));
100
+ return (0, _react2.jsx)(_primitives.Flex, {
101
+ ref: containerRef
102
+ }, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
103
+ mountTo: containerRef.current,
104
+ isOpen: isOpen,
105
+ handleClickOutside: onClose,
106
+ handleEscapeKeydown: onClose,
107
+ trigger: trigger,
108
+ scrollableElement: containerRef.current,
109
+ arrowKeyNavigationProviderOptions: {
110
+ type: _uiMenu.ArrowKeyNavigationType.MENU
111
+ }
112
+ }, (0, _react2.jsx)(_menu.ButtonItem, {
113
+ key: "edit.link",
114
+ onClick: onEditLink,
115
+ testId: "edit-dropdown-edit-link-item"
116
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditLinkTitle)), (0, _react2.jsx)(_menu.ButtonItem, {
117
+ key: "edit.datasource",
118
+ onClick: onEditDatasource,
119
+ testId: "edit-dropdown-edit-datasource-item"
120
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditDatasourceTitle))));
121
+ };
122
+ var EditToolbarButton = exports.EditToolbarButton = function EditToolbarButton(_ref2) {
123
+ var intl = _ref2.intl,
124
+ editorAnalyticsApi = _ref2.editorAnalyticsApi,
125
+ url = _ref2.url,
126
+ editorView = _ref2.editorView,
127
+ onLinkEditClick = _ref2.onLinkEditClick;
128
+ return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref3) {
129
+ var cardContext = _ref3.cardContext;
130
+ return (0, _react2.jsx)(EditButtonWithCardContext, {
131
+ url: url,
132
+ intl: intl,
133
+ editorAnalyticsApi: editorAnalyticsApi,
134
+ editorView: editorView,
135
+ cardContext: cardContext,
136
+ onLinkEditClick: onLinkEditClick
137
+ });
138
+ });
139
+ };
package/dist/cjs/utils.js CHANGED
@@ -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.titleUrlPairFromNode = exports.selectedCardAppearance = exports.mergeCardInfo = exports.isEmbedSupportedAtPosition = exports.isDatasourceNode = exports.isDatasourceConfigEditable = exports.isDatasourceAdfAttributes = exports.isBlockSupportedAtPosition = exports.getResolvedAttributesFromStore = exports.findCardInfo = exports.displayInfoForCard = exports.appearanceForNodeType = void 0;
7
+ exports.titleUrlPairFromNode = exports.selectedCardAppearance = exports.mergeCardInfo = exports.isEmbedSupportedAtPosition = exports.isEditDropdownEnabled = exports.isDatasourceNode = exports.isDatasourceConfigEditable = exports.isDatasourceAdfAttributes = exports.isBlockSupportedAtPosition = exports.getResolvedAttributesFromStore = exports.findCardInfo = exports.displayInfoForCard = exports.appearanceForNodeType = void 0;
8
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
9
  var _model = require("@atlaskit/editor-prosemirror/model");
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
@@ -87,6 +87,9 @@ var isDatasourceConfigEditable = exports.isDatasourceConfigEditable = function i
87
87
  }
88
88
  return datasourcesWithConfigModal.includes(datasourceId);
89
89
  };
90
+ var isEditDropdownEnabled = exports.isEditDropdownEnabled = function isEditDropdownEnabled(platform) {
91
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && platform !== 'mobile';
92
+ };
90
93
 
91
94
  /**
92
95
  * Typeguard that checks node attributes are datasource node attributes
@@ -2,12 +2,12 @@ import isEqual from 'lodash/isEqual';
2
2
  import { isSafeUrl } from '@atlaskit/adf-schema';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, SMART_LINK_TYPE, unlinkPayload } from '@atlaskit/editor-common/analytics';
4
4
  import { addLinkMetadata } from '@atlaskit/editor-common/card';
5
- import { getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
5
+ import { getDatasourceType, getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
6
6
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
7
7
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
9
  import { appearanceForNodeType, isDatasourceConfigEditable, isDatasourceNode, selectedCardAppearance } from '../utils';
10
- import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
10
+ import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash, showDatasourceModal } from './actions';
11
11
  import { pluginKey } from './plugin-key';
12
12
  import { shouldReplaceLink } from './shouldReplaceLink';
13
13
  /**
@@ -554,4 +554,24 @@ const updateDatasourceStash = (tr, selectedNode) => {
554
554
  }
555
555
  }
556
556
  }
557
+ };
558
+ export const editDatasource = (datasourceId, _editorAnalyticsApi) => (state, dispatch) => {
559
+ const datasourceType = getDatasourceType(datasourceId);
560
+ if (dispatch && datasourceType) {
561
+ const {
562
+ tr
563
+ } = state;
564
+ showDatasourceModal(datasourceType)(tr);
565
+ // editorAnalyticsApi?.attachAnalyticsEvent(
566
+ // buildEditLinkPayload(
567
+ // type as
568
+ // | ACTION_SUBJECT_ID.CARD_INLINE
569
+ // | ACTION_SUBJECT_ID.CARD_BLOCK
570
+ // | ACTION_SUBJECT_ID.EMBEDS,
571
+ // ),
572
+ // )(tr);
573
+ dispatch(tr);
574
+ return true;
575
+ }
576
+ return false;
557
577
  };
@@ -14,14 +14,15 @@ import CogIcon from '@atlaskit/icon/glyph/editor/settings';
14
14
  import UnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
15
15
  import OpenIcon from '@atlaskit/icon/glyph/shortcut';
16
16
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
- import { changeSelectedCardToText } from './pm-plugins/doc';
17
+ import { changeSelectedCardToText, editDatasource } from './pm-plugins/doc';
18
18
  import { pluginKey } from './pm-plugins/main';
19
19
  import { DatasourceAppearanceButton } from './ui/DatasourceAppearanceButton';
20
- import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
20
+ import { EditDatasourceButton } from './ui/EditDatasourceButton';
21
21
  import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
22
+ import { EditToolbarButton } from './ui/EditToolbarButton';
22
23
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
23
24
  import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
24
- import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, isDatasourceNode, titleUrlPairFromNode } from './utils';
25
+ import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, isDatasourceNode, isEditDropdownEnabled, titleUrlPairFromNode } from './utils';
25
26
  export const removeCard = editorAnalyticsApi => commandWithMetadata((state, dispatch) => {
26
27
  if (!(state.selection instanceof NodeSelection)) {
27
28
  return false;
@@ -219,7 +220,18 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
219
220
  const {
220
221
  inlineCard
221
222
  } = state.schema.nodes;
222
- const toolbarItems = [{
223
+ const toolbarItems = [isEditDropdownEnabled(platform) && cardOptions.allowDatasource ? {
224
+ type: 'custom',
225
+ fallback: [],
226
+ render: editorView => /*#__PURE__*/React.createElement(EditToolbarButton, {
227
+ key: "edit-toolbar-item",
228
+ url: url,
229
+ intl: intl,
230
+ editorAnalyticsApi: editorAnalyticsApi,
231
+ editorView: editorView,
232
+ onLinkEditClick: editLink(editorAnalyticsApi)
233
+ })
234
+ } : {
223
235
  id: 'editor.link.edit',
224
236
  type: 'button',
225
237
  selected: false,
@@ -318,7 +330,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
318
330
  type: 'separator'
319
331
  });
320
332
  }
321
- const shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource;
333
+ const shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource && !getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar');
322
334
  if (shouldShowDatasourceEditButton) {
323
335
  toolbarItems.unshift({
324
336
  type: 'custom',
@@ -375,7 +387,7 @@ export const getSettingsButtonGroup = (intl, editorAnalyticsApi, userPreferences
375
387
  const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId, state, cardOptions, currentAppearance, platform, cardActions) => {
376
388
  var _node$attrs3;
377
389
  const toolbarItems = [];
378
- if (isDatasourceConfigEditable(datasourceId)) {
390
+ if (isDatasourceConfigEditable(datasourceId) && !getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar')) {
379
391
  toolbarItems.push({
380
392
  id: 'editor.edit.datasource',
381
393
  type: 'button',
@@ -389,6 +401,20 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
389
401
  type: 'separator'
390
402
  });
391
403
  }
404
+ const editDropdownWithSeparator = [{
405
+ type: 'custom',
406
+ fallback: [],
407
+ render: editorView => /*#__PURE__*/React.createElement(EditToolbarButton, {
408
+ key: "edit-toolbar-item",
409
+ url: metadata.url,
410
+ intl: intl,
411
+ editorAnalyticsApi: editorAnalyticsApi,
412
+ editorView: editorView,
413
+ onLinkEditClick: editLink(editorAnalyticsApi)
414
+ })
415
+ }, {
416
+ type: 'separator'
417
+ }];
392
418
  const canShowMainToolbar = () => {
393
419
  // we do not show smart-link or the datasource icons when the node does not have a url to resolve
394
420
  if (!metadata.url) {
@@ -446,7 +472,7 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
446
472
  })
447
473
  }, {
448
474
  type: 'separator'
449
- });
475
+ }, ...(getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') ? [...editDropdownWithSeparator] : []));
450
476
  }
451
477
  if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
452
478
  toolbarItems.push({
@@ -2,9 +2,8 @@
2
2
  import { css, jsx } from '@emotion/react';
3
3
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
4
4
  import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator, SmallerEditIcon } from '@atlaskit/editor-common/ui';
5
- import { getDatasourceType } from '@atlaskit/editor-common/utils';
6
5
  import { Flex } from '@atlaskit/primitives';
7
- import { showDatasourceModal } from '../pm-plugins/actions';
6
+ import { editDatasource } from '../pm-plugins/doc';
8
7
  import { isDatasourceConfigEditable } from '../utils';
9
8
  import { CardContextProvider } from './CardContextProvider';
10
9
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
@@ -71,24 +70,4 @@ export const EditDatasourceButton = ({
71
70
  editorState: editorState,
72
71
  cardContext: cardContext
73
72
  }));
74
- };
75
- export const editDatasource = (datasourceId, editorAnalyticsApi) => (state, dispatch) => {
76
- const datasourceType = getDatasourceType(datasourceId);
77
- if (dispatch && datasourceType) {
78
- const {
79
- tr
80
- } = state;
81
- showDatasourceModal(datasourceType)(tr);
82
- // editorAnalyticsApi?.attachAnalyticsEvent(
83
- // buildEditLinkPayload(
84
- // type as
85
- // | ACTION_SUBJECT_ID.CARD_INLINE
86
- // | ACTION_SUBJECT_ID.CARD_BLOCK
87
- // | ACTION_SUBJECT_ID.EMBEDS,
88
- // ),
89
- // )(tr);
90
- dispatch(tr);
91
- return true;
92
- }
93
- return false;
94
73
  };
@@ -0,0 +1,123 @@
1
+ /** @jsx jsx */
2
+ import { useCallback, useMemo, useRef, useState } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { FormattedMessage } from 'react-intl-next';
5
+ import { linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
7
+ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlaskit/editor-common/ui-menu';
8
+ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
9
+ import { ButtonItem } from '@atlaskit/menu';
10
+ import { Flex } from '@atlaskit/primitives';
11
+ import { editDatasource } from '../pm-plugins/doc';
12
+ import { isDatasourceConfigEditable } from '../utils';
13
+ import { CardContextProvider } from './CardContextProvider';
14
+ import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
15
+ const dropdownExpandContainer = css({
16
+ margin: `0px ${"var(--ds-space-negative-050, -4px)"}`
17
+ });
18
+ const EditButtonWithCardContext = ({
19
+ cardContext,
20
+ intl,
21
+ editorAnalyticsApi,
22
+ url,
23
+ editorView,
24
+ onLinkEditClick
25
+ }) => {
26
+ const {
27
+ datasourceId
28
+ } = useFetchDatasourceInfo({
29
+ isRegularCardNode: true,
30
+ url,
31
+ cardContext
32
+ });
33
+ const [isOpen, setIsOpen] = useState(false);
34
+ const containerRef = useRef();
35
+ const toggleOpen = () => setIsOpen(open => !open);
36
+ const onClose = () => setIsOpen(false);
37
+ const dispatchCommand = useCallback(fn => {
38
+ if (editorView) {
39
+ fn === null || fn === void 0 ? void 0 : fn(editorView.state, editorView.dispatch);
40
+ if (!editorView.hasFocus()) {
41
+ editorView.focus();
42
+ }
43
+ }
44
+ }, [editorView]);
45
+ const onEditLink = useCallback(() => {
46
+ dispatchCommand(onLinkEditClick);
47
+ }, [dispatchCommand, onLinkEditClick]);
48
+ const shouldFallbackToEditButton = useMemo(() => {
49
+ if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
50
+ return true;
51
+ }
52
+ if (url) {
53
+ var _cardContext$store, _urlState$error;
54
+ const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
55
+ if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
56
+ return true;
57
+ }
58
+ }
59
+ return false;
60
+ }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
61
+ const onEditDatasource = useCallback(() => {
62
+ if (datasourceId) {
63
+ dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
64
+ }
65
+ }, [dispatchCommand, datasourceId, editorAnalyticsApi]);
66
+ if (shouldFallbackToEditButton) {
67
+ return jsx(Button, {
68
+ testId: "edit-link",
69
+ onClick: onEditLink
70
+ }, jsx(FormattedMessage, linkToolbarMessages.editLink));
71
+ }
72
+ const trigger = jsx(Button, {
73
+ testId: "edit-dropdown-trigger",
74
+ iconAfter: jsx("span", {
75
+ css: dropdownExpandContainer
76
+ }, jsx(ExpandIcon, {
77
+ label: intl.formatMessage(messages.editDropdownTriggerTitle)
78
+ })),
79
+ onClick: toggleOpen,
80
+ selected: isOpen,
81
+ disabled: false,
82
+ ariaHasPopup: true
83
+ }, jsx(FormattedMessage, messages.editDropdownTriggerTitle));
84
+ return jsx(Flex, {
85
+ ref: containerRef
86
+ }, jsx(UiDropdown, {
87
+ mountTo: containerRef.current,
88
+ isOpen: isOpen,
89
+ handleClickOutside: onClose,
90
+ handleEscapeKeydown: onClose,
91
+ trigger: trigger,
92
+ scrollableElement: containerRef.current,
93
+ arrowKeyNavigationProviderOptions: {
94
+ type: ArrowKeyNavigationType.MENU
95
+ }
96
+ }, jsx(ButtonItem, {
97
+ key: "edit.link",
98
+ onClick: onEditLink,
99
+ testId: "edit-dropdown-edit-link-item"
100
+ }, jsx(FormattedMessage, messages.editDropdownEditLinkTitle)), jsx(ButtonItem, {
101
+ key: "edit.datasource",
102
+ onClick: onEditDatasource,
103
+ testId: "edit-dropdown-edit-datasource-item"
104
+ }, jsx(FormattedMessage, messages.editDropdownEditDatasourceTitle))));
105
+ };
106
+ export const EditToolbarButton = ({
107
+ intl,
108
+ editorAnalyticsApi,
109
+ url,
110
+ editorView,
111
+ onLinkEditClick
112
+ }) => {
113
+ return jsx(CardContextProvider, null, ({
114
+ cardContext
115
+ }) => jsx(EditButtonWithCardContext, {
116
+ url: url,
117
+ intl: intl,
118
+ editorAnalyticsApi: editorAnalyticsApi,
119
+ editorView: editorView,
120
+ cardContext: cardContext,
121
+ onLinkEditClick: onLinkEditClick
122
+ }));
123
+ };
@@ -73,6 +73,9 @@ export const isDatasourceConfigEditable = datasourceId => {
73
73
  }
74
74
  return datasourcesWithConfigModal.includes(datasourceId);
75
75
  };
76
+ export const isEditDropdownEnabled = platform => {
77
+ return getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && platform !== 'mobile';
78
+ };
76
79
 
77
80
  /**
78
81
  * Typeguard that checks node attributes are datasource node attributes