@atlaskit/editor-plugin-card 2.0.5 → 2.0.7

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 (63) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/nodeviews/datasource.js +1 -1
  3. package/dist/cjs/plugin.js +3 -3
  4. package/dist/cjs/pm-plugins/doc.js +1 -109
  5. package/dist/cjs/toolbar.js +92 -6
  6. package/dist/cjs/ui/AwarenessWrapper/index.js +2 -0
  7. package/dist/cjs/ui/DatasourceAppearanceButton.js +2 -0
  8. package/dist/cjs/ui/EditDatasourceButton.js +51 -25
  9. package/dist/cjs/ui/EditToolbarButton.js +31 -28
  10. package/dist/cjs/ui/HyperlinkToolbarAppearance.js +2 -2
  11. package/dist/cjs/ui/InlineCardOverlay/index.js +1 -0
  12. package/dist/cjs/ui/LayoutButton/index.js +1 -1
  13. package/dist/cjs/ui/LeftIconOverlay/index.js +1 -0
  14. package/dist/cjs/ui/ResizableEmbedCard.js +1 -1
  15. package/dist/cjs/ui/useFetchDatasourceInfo.js +13 -6
  16. package/dist/cjs/utils.js +11 -1
  17. package/dist/es2019/nodeviews/datasource.js +2 -0
  18. package/dist/es2019/plugin.js +2 -2
  19. package/dist/es2019/pm-plugins/doc.js +2 -106
  20. package/dist/es2019/toolbar.js +88 -6
  21. package/dist/es2019/ui/AwarenessWrapper/index.js +2 -0
  22. package/dist/es2019/ui/DatasourceAppearanceButton.js +2 -0
  23. package/dist/es2019/ui/EditDatasourceButton.js +42 -14
  24. package/dist/es2019/ui/EditToolbarButton.js +26 -22
  25. package/dist/es2019/ui/HyperlinkToolbarAppearance.js +2 -2
  26. package/dist/es2019/ui/InlineCardOverlay/index.js +2 -0
  27. package/dist/es2019/ui/LayoutButton/index.js +2 -0
  28. package/dist/es2019/ui/LeftIconOverlay/index.js +2 -0
  29. package/dist/es2019/ui/ResizableEmbedCard.js +2 -0
  30. package/dist/es2019/ui/useFetchDatasourceInfo.js +5 -1
  31. package/dist/es2019/utils.js +10 -0
  32. package/dist/esm/nodeviews/datasource.js +2 -0
  33. package/dist/esm/plugin.js +2 -2
  34. package/dist/esm/pm-plugins/doc.js +2 -110
  35. package/dist/esm/toolbar.js +92 -6
  36. package/dist/esm/ui/AwarenessWrapper/index.js +2 -0
  37. package/dist/esm/ui/DatasourceAppearanceButton.js +2 -0
  38. package/dist/esm/ui/EditDatasourceButton.js +42 -16
  39. package/dist/esm/ui/EditToolbarButton.js +33 -28
  40. package/dist/esm/ui/HyperlinkToolbarAppearance.js +2 -2
  41. package/dist/esm/ui/InlineCardOverlay/index.js +2 -0
  42. package/dist/esm/ui/LayoutButton/index.js +2 -0
  43. package/dist/esm/ui/LeftIconOverlay/index.js +2 -0
  44. package/dist/esm/ui/ResizableEmbedCard.js +2 -0
  45. package/dist/esm/ui/useFetchDatasourceInfo.js +13 -6
  46. package/dist/esm/utils.js +10 -0
  47. package/dist/types/pm-plugins/doc.d.ts +3 -11
  48. package/dist/types/toolbar.d.ts +7 -0
  49. package/dist/types/types.d.ts +1 -0
  50. package/dist/types/ui/EditDatasourceButton.d.ts +6 -5
  51. package/dist/types/ui/EditLinkToolbar.d.ts +1 -1
  52. package/dist/types/ui/EditToolbarButton.d.ts +3 -1
  53. package/dist/types/ui/useFetchDatasourceInfo.d.ts +1 -0
  54. package/dist/types/utils.d.ts +6 -0
  55. package/dist/types-ts4.5/pm-plugins/doc.d.ts +3 -11
  56. package/dist/types-ts4.5/toolbar.d.ts +7 -0
  57. package/dist/types-ts4.5/types.d.ts +1 -0
  58. package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +6 -5
  59. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +1 -1
  60. package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +3 -1
  61. package/dist/types-ts4.5/ui/useFetchDatasourceInfo.d.ts +1 -0
  62. package/dist/types-ts4.5/utils.d.ts +6 -0
  63. package/package.json +37 -19
@@ -22,7 +22,7 @@ var _smartCard = require("@atlaskit/smart-card");
22
22
  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; }
23
23
  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; }
24
24
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /** @jsx jsx */
25
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /** @jsx jsx */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
26
26
  // eslint-disable-next-line @repo/internal/react/no-class-components
27
27
  var ResizableEmbedCard = exports.default = /*#__PURE__*/function (_React$Component) {
28
28
  (0, _inherits2.default)(ResizableEmbedCard, _React$Component);
@@ -30,6 +30,10 @@ var useFetchDatasourceInfo = exports.useFetchDatasourceInfo = function useFetchD
30
30
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
31
31
  ready = _useState6[0],
32
32
  setReady = _useState6[1];
33
+ var _useState7 = (0, _react.useState)(undefined),
34
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
35
+ extensionKey = _useState8[0],
36
+ setExtensionKey = _useState8[1];
33
37
  (0, _react.useEffect)(function () {
34
38
  var fetchDatasource = /*#__PURE__*/function () {
35
39
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
@@ -51,24 +55,26 @@ var useFetchDatasourceInfo = exports.useFetchDatasourceInfo = function useFetchD
51
55
  case 6:
52
56
  response = _context.sent;
53
57
  datasources = response && response.datasources || [];
58
+ setExtensionKey(response === null || response === void 0 ? void 0 : response.meta.key);
54
59
  setDatasourceId((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id);
55
60
  setParameters((_datasources$2 = datasources[0]) === null || _datasources$2 === void 0 ? void 0 : _datasources$2.parameters);
56
61
  setReady(true);
57
- _context.next = 18;
62
+ _context.next = 20;
58
63
  break;
59
- case 13:
60
- _context.prev = 13;
64
+ case 14:
65
+ _context.prev = 14;
61
66
  _context.t0 = _context["catch"](0);
62
67
  setDatasourceId(undefined);
63
68
  setParameters(undefined);
69
+ setExtensionKey(undefined);
64
70
  // If fetch somehow errors, still set ready as true so we don't block the rendering of the modal.
65
71
  // It will just open with empty params.
66
72
  setReady(true);
67
- case 18:
73
+ case 20:
68
74
  case "end":
69
75
  return _context.stop();
70
76
  }
71
- }, _callee, null, [[0, 13]]);
77
+ }, _callee, null, [[0, 14]]);
72
78
  }));
73
79
  return function fetchDatasource() {
74
80
  return _ref2.apply(this, arguments);
@@ -81,6 +87,7 @@ var useFetchDatasourceInfo = exports.useFetchDatasourceInfo = function useFetchD
81
87
  return {
82
88
  datasourceId: datasourceId,
83
89
  parameters: parameters,
84
- ready: ready
90
+ ready: ready,
91
+ extensionKey: extensionKey
85
92
  };
86
93
  };
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.isDatasourceNode = exports.isDatasourceConfigEditable = exports.isDatasourceAdfAttributes = exports.isBlockSupportedAtPosition = exports.getResolvedAttributesFromStore = exports.focusEditorView = 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");
@@ -122,4 +122,14 @@ var isDatasourceNode = exports.isDatasourceNode = function isDatasourceNode(node
122
122
  return false;
123
123
  }
124
124
  return node.type.name === 'blockCard' && isDatasourceAdfAttributes(node.attrs);
125
+ };
126
+
127
+ /**
128
+ * Focuses the editorView if it's not already focused.
129
+ * @param editorView The editor view to focus.
130
+ */
131
+ var focusEditorView = exports.focusEditorView = function focusEditorView(editorView) {
132
+ if (!editorView.hasFocus()) {
133
+ editorView.focus();
134
+ }
125
135
  };
@@ -1,6 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  /** @jsx jsx */
3
3
  import React from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
4
6
  import { jsx } from '@emotion/react';
5
7
  import PropTypes from 'prop-types';
6
8
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
@@ -5,13 +5,13 @@ import { IconDatasourceAssetsObjects, IconDatasourceConfluenceSearch, IconDataso
5
5
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
6
6
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, CONFLUENCE_SEARCH_DATASOURCE_ID } from '@atlaskit/link-datasource';
7
7
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
+ import { queueCardsFromChangedTr } from '../src/pm-plugins/doc';
8
9
  import { createEventsQueue } from './analytics/create-events-queue';
9
10
  import { hideLinkToolbar, showDatasourceModal } from './pm-plugins/actions';
10
- import { getEndingToolbarItems, getStartingToolbarItems, queueCardsFromChangedTr } from './pm-plugins/doc';
11
11
  import { cardKeymap } from './pm-plugins/keymap';
12
12
  import { createPlugin } from './pm-plugins/main';
13
13
  import { pluginKey } from './pm-plugins/plugin-key';
14
- import { floatingToolbar } from './toolbar';
14
+ import { floatingToolbar, getEndingToolbarItems, getStartingToolbarItems } from './toolbar';
15
15
  import DatasourceModalWithState from './ui/DatasourceModal/ModalWithState';
16
16
  import { EditorLinkingPlatformAnalytics } from './ui/EditorLinkingPlatformAnalytics';
17
17
  import { EditorSmartCardEvents } from './ui/EditorSmartCardEvents';
@@ -1,19 +1,13 @@
1
- import React from 'react';
2
1
  import isEqual from 'lodash/isEqual';
3
2
  import { isSafeUrl } from '@atlaskit/adf-schema';
4
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, SMART_LINK_TYPE, unlinkPayload } from '@atlaskit/editor-common/analytics';
5
4
  import { addLinkMetadata } from '@atlaskit/editor-common/card';
6
- import { linkToolbarMessages } from '@atlaskit/editor-common/messages';
7
- import { getDatasourceType, getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
5
+ import { getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
8
6
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
9
7
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
10
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
- import { getHyperlinkToolbarSettingsButton } from '../toolbar';
12
- import { EditToolbarButton } from '../ui/EditToolbarButton';
13
- import { HyperlinkToolbarAppearance } from '../ui/HyperlinkToolbarAppearance';
14
- import { ToolbarViewedEvent } from '../ui/ToolbarViewedEvent';
15
9
  import { appearanceForNodeType, isDatasourceConfigEditable, isDatasourceNode, selectedCardAppearance } from '../utils';
16
- import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash, showDatasourceModal } from './actions';
10
+ import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
17
11
  import { pluginKey } from './plugin-key';
18
12
  import { shouldReplaceLink } from './shouldReplaceLink';
19
13
 
@@ -561,102 +555,4 @@ const updateDatasourceStash = (tr, selectedNode) => {
561
555
  }
562
556
  }
563
557
  }
564
- };
565
- export const editDatasource = (datasourceId, editorAnalyticsApi) => (state, dispatch) => {
566
- const datasourceType = getDatasourceType(datasourceId);
567
- if (dispatch && datasourceType) {
568
- const {
569
- tr
570
- } = state;
571
- showDatasourceModal(datasourceType)(tr);
572
- // editorAnalyticsApi?.attachAnalyticsEvent(
573
- // buildEditLinkPayload(
574
- // type as
575
- // | ACTION_SUBJECT_ID.CARD_INLINE
576
- // | ACTION_SUBJECT_ID.CARD_BLOCK
577
- // | ACTION_SUBJECT_ID.EMBEDS,
578
- // ),
579
- // )(tr);
580
- dispatch(tr);
581
- return true;
582
- }
583
- return false;
584
- };
585
- export const getStartingToolbarItems = (options, api) => {
586
- return (intl, link, providerFactory, onEditLink, metadata) => {
587
- const isEditDropdownEnabled = getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && options.platform !== 'mobile' && options.allowDatasource;
588
- const editLinkItem = isEditDropdownEnabled ? [{
589
- type: 'custom',
590
- fallback: [],
591
- render: editorView => {
592
- var _api$analytics;
593
- if (!editorView) {
594
- return null;
595
- }
596
- return /*#__PURE__*/React.createElement(EditToolbarButton, {
597
- key: "edit-toolbar-button",
598
- intl: intl,
599
- editorAnalyticsApi: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
600
- url: link,
601
- editorView: editorView,
602
- onLinkEditClick: onEditLink
603
- });
604
- }
605
- }] : [{
606
- id: 'editor.link.edit',
607
- testId: 'editor.link.edit',
608
- type: 'button',
609
- onClick: onEditLink,
610
- title: intl.formatMessage(linkToolbarMessages.editLink),
611
- showTitle: true,
612
- metadata: metadata
613
- }, {
614
- type: 'separator'
615
- }];
616
- return [{
617
- type: 'custom',
618
- fallback: [],
619
- render: editorView => /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
620
- key: "edit.link.menu.viewed",
621
- url: link,
622
- display: "url",
623
- editorView: editorView
624
- })
625
- }, {
626
- type: 'custom',
627
- fallback: [],
628
- render: editorView => {
629
- var _api$analytics2;
630
- if (!editorView) {
631
- return null;
632
- }
633
- return /*#__PURE__*/React.createElement(HyperlinkToolbarAppearance, {
634
- key: "link-appearance",
635
- url: link,
636
- intl: intl,
637
- editorView: editorView,
638
- editorState: editorView.state,
639
- cardOptions: options,
640
- providerFactory: providerFactory,
641
- platform: options === null || options === void 0 ? void 0 : options.platform,
642
- editorAnalyticsApi: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
643
- });
644
- }
645
- }, ...editLinkItem];
646
- };
647
- };
648
- export const getEndingToolbarItems = (options, api) => (intl, link) => {
649
- if (getBooleanFF('platform.editor.card.inject-settings-button')) {
650
- /**
651
- * Require either provider to be supplied (controls link preferences)
652
- * Or explicit user preferences config in order to enable button
653
- */
654
- if (options.provider || options.userPreferencesLink) {
655
- var _api$analytics3;
656
- return [{
657
- type: 'separator'
658
- }, getHyperlinkToolbarSettingsButton(intl, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.userPreferencesLink)];
659
- }
660
- }
661
- return [];
662
558
  };
@@ -14,12 +14,13 @@ 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, editDatasource } from './pm-plugins/doc';
17
+ import { changeSelectedCardToText } from '../src/pm-plugins/doc';
18
18
  import { pluginKey } from './pm-plugins/main';
19
19
  import { DatasourceAppearanceButton } from './ui/DatasourceAppearanceButton';
20
- import { EditDatasourceButton } from './ui/EditDatasourceButton';
20
+ import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
21
21
  import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
22
22
  import { EditToolbarButton } from './ui/EditToolbarButton';
23
+ import { HyperlinkToolbarAppearance } from './ui/HyperlinkToolbarAppearance';
23
24
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
24
25
  import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
25
26
  import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, isDatasourceNode, titleUrlPairFromNode } from './utils';
@@ -229,7 +230,8 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
229
230
  intl: intl,
230
231
  editorAnalyticsApi: editorAnalyticsApi,
231
232
  editorView: editorView,
232
- onLinkEditClick: editLink(editorAnalyticsApi, true)
233
+ onLinkEditClick: editLink(editorAnalyticsApi, true),
234
+ currentAppearance: currentAppearance
233
235
  })
234
236
  }] : [{
235
237
  id: 'editor.link.edit',
@@ -337,7 +339,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
337
339
  editorAnalyticsApi: editorAnalyticsApi,
338
340
  url: url,
339
341
  editorView: editorView,
340
- editorState: state
342
+ currentAppearance: currentAppearance
341
343
  })
342
344
  });
343
345
  }
@@ -392,7 +394,7 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
392
394
  metadata: metadata,
393
395
  className: 'datasource-edit',
394
396
  title: intl.formatMessage(linkToolbarMessages.editDatasource),
395
- onClick: editDatasource(datasourceId, editorAnalyticsApi),
397
+ onClick: editDatasource(datasourceId, editorAnalyticsApi, 'datasource'),
396
398
  testId: 'datasource-edit-button'
397
399
  }, {
398
400
  type: 'separator'
@@ -467,7 +469,8 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
467
469
  intl: intl,
468
470
  editorAnalyticsApi: editorAnalyticsApi,
469
471
  editorView: editorView,
470
- onLinkEditClick: editLink(editorAnalyticsApi, false)
472
+ onLinkEditClick: editLink(editorAnalyticsApi, false),
473
+ currentAppearance: "datasource"
471
474
  })
472
475
  });
473
476
  }
@@ -511,4 +514,83 @@ const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hove
511
514
  };
512
515
  export const shouldRenderToolbarPulse = (embedEnabled, appearance, status, isDiscoverabilityEnabled) => {
513
516
  return embedEnabled && appearance === 'inline' && status === 'resolved' && isDiscoverabilityEnabled;
517
+ };
518
+ export const getStartingToolbarItems = (options, api) => {
519
+ return (intl, link, providerFactory, onEditLink, metadata) => {
520
+ const isEditDropdownEnabled = getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && options.platform !== 'mobile' && options.allowDatasource;
521
+ const editLinkItem = isEditDropdownEnabled ? [{
522
+ type: 'custom',
523
+ fallback: [],
524
+ render: editorView => {
525
+ var _api$analytics;
526
+ if (!editorView) {
527
+ return null;
528
+ }
529
+ return /*#__PURE__*/React.createElement(EditToolbarButton, {
530
+ key: "edit-toolbar-button",
531
+ intl: intl,
532
+ editorAnalyticsApi: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
533
+ url: link,
534
+ editorView: editorView,
535
+ onLinkEditClick: onEditLink,
536
+ currentAppearance: "url"
537
+ });
538
+ }
539
+ }] : [{
540
+ id: 'editor.link.edit',
541
+ testId: 'editor.link.edit',
542
+ type: 'button',
543
+ onClick: onEditLink,
544
+ title: intl.formatMessage(linkToolbarMessages.editLink),
545
+ showTitle: true,
546
+ metadata: metadata
547
+ }, {
548
+ type: 'separator'
549
+ }];
550
+ return [{
551
+ type: 'custom',
552
+ fallback: [],
553
+ render: editorView => /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
554
+ key: "edit.link.menu.viewed",
555
+ url: link,
556
+ display: "url",
557
+ editorView: editorView
558
+ })
559
+ }, {
560
+ type: 'custom',
561
+ fallback: [],
562
+ render: editorView => {
563
+ var _api$analytics2;
564
+ if (!editorView) {
565
+ return null;
566
+ }
567
+ return /*#__PURE__*/React.createElement(HyperlinkToolbarAppearance, {
568
+ key: "link-appearance",
569
+ url: link,
570
+ intl: intl,
571
+ editorView: editorView,
572
+ editorState: editorView.state,
573
+ cardOptions: options,
574
+ providerFactory: providerFactory,
575
+ platform: options === null || options === void 0 ? void 0 : options.platform,
576
+ editorAnalyticsApi: api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
577
+ });
578
+ }
579
+ }, ...editLinkItem];
580
+ };
581
+ };
582
+ export const getEndingToolbarItems = (options, api) => (intl, link) => {
583
+ if (getBooleanFF('platform.editor.card.inject-settings-button')) {
584
+ /**
585
+ * Require either provider to be supplied (controls link preferences)
586
+ * Or explicit user preferences config in order to enable button
587
+ */
588
+ if (options.provider || options.userPreferencesLink) {
589
+ var _api$analytics3;
590
+ return [{
591
+ type: 'separator'
592
+ }, getHyperlinkToolbarSettingsButton(intl, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.userPreferencesLink)];
593
+ }
594
+ }
595
+ return [];
514
596
  };
@@ -1,5 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback, useEffect, useMemo, useState } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
4
6
  import { AnalyticsContext } from '@atlaskit/analytics-next';
5
7
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
@@ -1,5 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
4
6
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
5
7
  import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
@@ -1,10 +1,15 @@
1
1
  /** @jsx jsx */
2
+ import { useCallback } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
2
5
  import { css, jsx } from '@emotion/react';
6
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
3
7
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
4
8
  import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator, SmallerEditIcon } from '@atlaskit/editor-common/ui';
9
+ import { getDatasourceType } from '@atlaskit/editor-common/utils';
5
10
  import { Flex } from '@atlaskit/primitives';
6
- import { editDatasource } from '../pm-plugins/doc';
7
- import { isDatasourceConfigEditable } from '../utils';
11
+ import { showDatasourceModal } from '../pm-plugins/actions';
12
+ import { focusEditorView, isDatasourceConfigEditable } from '../utils';
8
13
  import { CardContextProvider } from './CardContextProvider';
9
14
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
10
15
  const buttonStyles = css({
@@ -19,15 +24,22 @@ const EditDatasourceButtonWithCardContext = ({
19
24
  editorAnalyticsApi,
20
25
  url,
21
26
  editorView,
22
- editorState
27
+ currentAppearance
23
28
  }) => {
24
29
  const {
25
- datasourceId
30
+ datasourceId,
31
+ extensionKey
26
32
  } = useFetchDatasourceInfo({
27
33
  isRegularCardNode: true,
28
34
  url,
29
35
  cardContext
30
36
  });
37
+ const onEditDatasource = useCallback(() => {
38
+ if (editorView && datasourceId) {
39
+ editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
40
+ focusEditorView(editorView);
41
+ }
42
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
31
43
  if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
32
44
  return null;
33
45
  }
@@ -38,18 +50,12 @@ const EditDatasourceButtonWithCardContext = ({
38
50
  return null;
39
51
  }
40
52
  }
41
- const dispatchCommand = fn => {
42
- fn && fn(editorState, editorView && editorView.dispatch);
43
- if (editorView && !editorView.hasFocus()) {
44
- editorView.focus();
45
- }
46
- };
47
53
  return jsx(Flex, null, jsx(Button, {
48
54
  css: buttonStyles,
49
55
  title: intl.formatMessage(messages.datasourceTitle),
50
56
  icon: jsx(SmallerEditIcon, null),
51
57
  selected: false,
52
- onClick: () => dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi)),
58
+ onClick: onEditDatasource,
53
59
  testId: 'card-edit-datasource-button'
54
60
  }), jsx(Separator, null));
55
61
  };
@@ -58,7 +64,7 @@ export const EditDatasourceButton = ({
58
64
  editorAnalyticsApi,
59
65
  url,
60
66
  editorView,
61
- editorState
67
+ currentAppearance
62
68
  }) => {
63
69
  return jsx(CardContextProvider, null, ({
64
70
  cardContext
@@ -67,7 +73,29 @@ export const EditDatasourceButton = ({
67
73
  intl: intl,
68
74
  editorAnalyticsApi: editorAnalyticsApi,
69
75
  editorView: editorView,
70
- editorState: editorState,
71
- cardContext: cardContext
76
+ cardContext: cardContext,
77
+ currentAppearance: currentAppearance
72
78
  }));
79
+ };
80
+ export const editDatasource = (datasourceId, editorAnalyticsApi, appearance, extensionKey) => (state, dispatch) => {
81
+ const datasourceType = getDatasourceType(datasourceId);
82
+ if (dispatch && datasourceType) {
83
+ const {
84
+ tr
85
+ } = state;
86
+ showDatasourceModal(datasourceType)(tr);
87
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
88
+ action: ACTION.CLICKED,
89
+ actionSubject: ACTION_SUBJECT.BUTTON,
90
+ actionSubjectId: ACTION_SUBJECT_ID.EDIT_DATASOURCE,
91
+ eventType: EVENT_TYPE.UI,
92
+ attributes: {
93
+ extensionKey,
94
+ appearance
95
+ }
96
+ })(tr);
97
+ dispatch(tr);
98
+ return true;
99
+ }
100
+ return false;
73
101
  };
@@ -1,5 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback, useMemo, useRef, useState } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
4
6
  import { FormattedMessage } from 'react-intl-next';
5
7
  import { linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
@@ -8,8 +10,8 @@ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlask
8
10
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
9
11
  import { ButtonItem } from '@atlaskit/menu';
10
12
  import { Flex } from '@atlaskit/primitives';
11
- import { editDatasource } from '../pm-plugins/doc';
12
- import { isDatasourceConfigEditable } from '../utils';
13
+ import { editDatasource } from '../ui/EditDatasourceButton';
14
+ import { focusEditorView, isDatasourceConfigEditable } from '../utils';
13
15
  import { CardContextProvider } from './CardContextProvider';
14
16
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
15
17
  const dropdownExpandContainer = css({
@@ -18,14 +20,18 @@ const dropdownExpandContainer = css({
18
20
  const EditToolbarButtonWithCardContext = props => {
19
21
  var _response$datasourceI;
20
22
  const {
21
- url,
22
23
  cardContext,
23
- intl,
24
+ currentAppearance,
24
25
  editorAnalyticsApi,
25
26
  editorView,
26
- onLinkEditClick
27
+ intl,
28
+ onLinkEditClick,
29
+ url
27
30
  } = props;
28
- const response = useFetchDatasourceInfo({
31
+ const {
32
+ extensionKey,
33
+ ...response
34
+ } = useFetchDatasourceInfo({
29
35
  isRegularCardNode: true,
30
36
  url,
31
37
  cardContext
@@ -35,17 +41,12 @@ const EditToolbarButtonWithCardContext = props => {
35
41
  const containerRef = useRef();
36
42
  const toggleOpen = () => setIsOpen(open => !open);
37
43
  const onClose = () => setIsOpen(false);
38
- const dispatchCommand = useCallback(fn => {
44
+ const onEditLink = useCallback(() => {
39
45
  if (editorView) {
40
- fn === null || fn === void 0 ? void 0 : fn(editorView.state, editorView.dispatch);
41
- if (!editorView.hasFocus()) {
42
- editorView.focus();
43
- }
46
+ onLinkEditClick(editorView.state, editorView.dispatch);
47
+ focusEditorView(editorView);
44
48
  }
45
- }, [editorView]);
46
- const onEditLink = useCallback(() => {
47
- dispatchCommand(onLinkEditClick);
48
- }, [dispatchCommand, onLinkEditClick]);
49
+ }, [editorView, onLinkEditClick]);
49
50
  const editVariant = useMemo(() => {
50
51
  const hasUrl = url !== null && url !== undefined;
51
52
  if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
@@ -66,10 +67,11 @@ const EditToolbarButtonWithCardContext = props => {
66
67
  }
67
68
  }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
68
69
  const onEditDatasource = useCallback(() => {
69
- if (datasourceId) {
70
- dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
70
+ if (editorView && datasourceId) {
71
+ editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
72
+ focusEditorView(editorView);
71
73
  }
72
- }, [dispatchCommand, datasourceId, editorAnalyticsApi]);
74
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
73
75
  switch (editVariant) {
74
76
  case 'edit-link':
75
77
  {
@@ -135,12 +137,13 @@ const EditToolbarButtonWithCardContext = props => {
135
137
  };
136
138
  export const EditToolbarButton = props => {
137
139
  const {
140
+ currentAppearance,
138
141
  datasourceId,
139
- intl,
140
142
  editorAnalyticsApi,
141
- url,
142
143
  editorView,
143
- onLinkEditClick
144
+ intl,
145
+ onLinkEditClick,
146
+ url
144
147
  } = props;
145
148
  return jsx(CardContextProvider, null, ({
146
149
  cardContext
@@ -151,6 +154,7 @@ export const EditToolbarButton = props => {
151
154
  editorAnalyticsApi: editorAnalyticsApi,
152
155
  editorView: editorView,
153
156
  cardContext: cardContext,
154
- onLinkEditClick: onLinkEditClick
157
+ onLinkEditClick: onLinkEditClick,
158
+ currentAppearance: currentAppearance
155
159
  }));
156
160
  };
@@ -79,9 +79,9 @@ export class HyperlinkToolbarAppearance extends Component {
79
79
  return /*#__PURE__*/React.createElement(Flex, null, !getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && /*#__PURE__*/React.createElement(EditDatasourceButton, {
80
80
  url: url,
81
81
  intl: intl,
82
- editorState: editorState,
83
82
  editorView: editorView,
84
- editorAnalyticsApi: editorAnalyticsApi
83
+ editorAnalyticsApi: editorAnalyticsApi,
84
+ currentAppearance: "url"
85
85
  }), /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
86
86
  key: "link-appearance",
87
87
  url: url,
@@ -3,6 +3,8 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
4
4
  /** @jsx jsx */
5
5
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
8
  import { css, jsx } from '@emotion/react';
7
9
  import debounce from 'lodash/debounce';
8
10
  import { useIntl } from 'react-intl-next';
@@ -1,5 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback, useMemo } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
4
6
  import { injectIntl } from 'react-intl-next';
5
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
@@ -3,6 +3,8 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
4
4
  /** @jsx jsx */
5
5
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
8
  import { css, jsx } from '@emotion/react';
7
9
  import debounce from 'lodash/debounce';
8
10
  import { useIntl } from 'react-intl-next';
@@ -2,6 +2,8 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  /** @jsx jsx */
4
4
  import React from 'react';
5
+
6
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
5
7
  import { jsx } from '@emotion/react';
6
8
  import { calcColumnsFromPx, calcMediaPxWidth, calcPctFromPx, calcPxFromColumns, handleSides, imageAlignmentMap, Resizer, snapTo, wrappedLayouts, wrapperStyle } from '@atlaskit/editor-common/ui';
7
9
  import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';