@atlaskit/editor-plugin-card 2.0.6 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/plugin.js +3 -3
  3. package/dist/cjs/pm-plugins/doc.js +1 -109
  4. package/dist/cjs/toolbar.js +92 -6
  5. package/dist/cjs/ui/EditDatasourceButton.js +50 -25
  6. package/dist/cjs/ui/EditToolbarButton.js +30 -29
  7. package/dist/cjs/ui/HyperlinkToolbarAppearance.js +2 -2
  8. package/dist/cjs/ui/useFetchDatasourceInfo.js +13 -6
  9. package/dist/cjs/utils.js +11 -1
  10. package/dist/es2019/plugin.js +2 -2
  11. package/dist/es2019/pm-plugins/doc.js +2 -106
  12. package/dist/es2019/toolbar.js +88 -6
  13. package/dist/es2019/ui/EditDatasourceButton.js +41 -14
  14. package/dist/es2019/ui/EditToolbarButton.js +24 -22
  15. package/dist/es2019/ui/HyperlinkToolbarAppearance.js +2 -2
  16. package/dist/es2019/ui/useFetchDatasourceInfo.js +5 -1
  17. package/dist/es2019/utils.js +10 -0
  18. package/dist/esm/plugin.js +2 -2
  19. package/dist/esm/pm-plugins/doc.js +2 -110
  20. package/dist/esm/toolbar.js +92 -6
  21. package/dist/esm/ui/EditDatasourceButton.js +41 -16
  22. package/dist/esm/ui/EditToolbarButton.js +31 -28
  23. package/dist/esm/ui/HyperlinkToolbarAppearance.js +2 -2
  24. package/dist/esm/ui/useFetchDatasourceInfo.js +13 -6
  25. package/dist/esm/utils.js +10 -0
  26. package/dist/types/pm-plugins/doc.d.ts +3 -11
  27. package/dist/types/toolbar.d.ts +7 -0
  28. package/dist/types/types.d.ts +1 -0
  29. package/dist/types/ui/EditDatasourceButton.d.ts +6 -5
  30. package/dist/types/ui/EditLinkToolbar.d.ts +1 -1
  31. package/dist/types/ui/EditToolbarButton.d.ts +3 -1
  32. package/dist/types/ui/useFetchDatasourceInfo.d.ts +1 -0
  33. package/dist/types/utils.d.ts +6 -0
  34. package/dist/types-ts4.5/pm-plugins/doc.d.ts +3 -11
  35. package/dist/types-ts4.5/toolbar.d.ts +7 -0
  36. package/dist/types-ts4.5/types.d.ts +1 -0
  37. package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +6 -5
  38. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +1 -1
  39. package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +3 -1
  40. package/dist/types-ts4.5/ui/useFetchDatasourceInfo.d.ts +1 -0
  41. package/dist/types-ts4.5/utils.d.ts +6 -0
  42. package/package.json +6 -6
@@ -2,22 +2,16 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  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; }
4
4
  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) { _defineProperty(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; }
5
- import React from 'react';
6
5
  import isEqual from 'lodash/isEqual';
7
6
  import { isSafeUrl } from '@atlaskit/adf-schema';
8
7
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, SMART_LINK_TYPE, unlinkPayload } from '@atlaskit/editor-common/analytics';
9
8
  import { addLinkMetadata } from '@atlaskit/editor-common/card';
10
- import { linkToolbarMessages } from '@atlaskit/editor-common/messages';
11
- import { getDatasourceType, getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
9
+ import { getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged, processRawValue } from '@atlaskit/editor-common/utils';
12
10
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
13
11
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
14
12
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
- import { getHyperlinkToolbarSettingsButton } from '../toolbar';
16
- import { EditToolbarButton } from '../ui/EditToolbarButton';
17
- import { HyperlinkToolbarAppearance } from '../ui/HyperlinkToolbarAppearance';
18
- import { ToolbarViewedEvent } from '../ui/ToolbarViewedEvent';
19
13
  import { appearanceForNodeType, isDatasourceConfigEditable, isDatasourceNode, selectedCardAppearance } from '../utils';
20
- import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash, showDatasourceModal } from './actions';
14
+ import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
21
15
  import { pluginKey } from './plugin-key';
22
16
  import { shouldReplaceLink } from './shouldReplaceLink';
23
17
 
@@ -567,106 +561,4 @@ var updateDatasourceStash = function updateDatasourceStash(tr, selectedNode) {
567
561
  }
568
562
  }
569
563
  }
570
- };
571
- export var editDatasource = function editDatasource(datasourceId, editorAnalyticsApi) {
572
- return function (state, dispatch) {
573
- var datasourceType = getDatasourceType(datasourceId);
574
- if (dispatch && datasourceType) {
575
- var tr = state.tr;
576
- 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
- };
590
- };
591
- export var getStartingToolbarItems = function getStartingToolbarItems(options, api) {
592
- return function (intl, link, providerFactory, onEditLink, metadata) {
593
- var isEditDropdownEnabled = getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && options.platform !== 'mobile' && options.allowDatasource;
594
- var editLinkItem = isEditDropdownEnabled ? [{
595
- type: 'custom',
596
- fallback: [],
597
- render: function render(editorView) {
598
- var _api$analytics;
599
- if (!editorView) {
600
- return null;
601
- }
602
- return /*#__PURE__*/React.createElement(EditToolbarButton, {
603
- key: "edit-toolbar-button",
604
- intl: intl,
605
- editorAnalyticsApi: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
606
- url: link,
607
- editorView: editorView,
608
- onLinkEditClick: onEditLink
609
- });
610
- }
611
- }] : [{
612
- id: 'editor.link.edit',
613
- testId: 'editor.link.edit',
614
- type: 'button',
615
- onClick: onEditLink,
616
- title: intl.formatMessage(linkToolbarMessages.editLink),
617
- showTitle: true,
618
- metadata: metadata
619
- }, {
620
- type: 'separator'
621
- }];
622
- return [{
623
- type: 'custom',
624
- fallback: [],
625
- render: function render(editorView) {
626
- return /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
627
- key: "edit.link.menu.viewed",
628
- url: link,
629
- display: "url",
630
- editorView: editorView
631
- });
632
- }
633
- }, {
634
- type: 'custom',
635
- fallback: [],
636
- render: function render(editorView) {
637
- var _api$analytics2;
638
- if (!editorView) {
639
- return null;
640
- }
641
- return /*#__PURE__*/React.createElement(HyperlinkToolbarAppearance, {
642
- key: "link-appearance",
643
- url: link,
644
- intl: intl,
645
- editorView: editorView,
646
- editorState: editorView.state,
647
- cardOptions: options,
648
- providerFactory: providerFactory,
649
- platform: options === null || options === void 0 ? void 0 : options.platform,
650
- editorAnalyticsApi: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
651
- });
652
- }
653
- }].concat(editLinkItem);
654
- };
655
- };
656
- export var getEndingToolbarItems = function getEndingToolbarItems(options, api) {
657
- return function (intl, link) {
658
- if (getBooleanFF('platform.editor.card.inject-settings-button')) {
659
- /**
660
- * Require either provider to be supplied (controls link preferences)
661
- * Or explicit user preferences config in order to enable button
662
- */
663
- if (options.provider || options.userPreferencesLink) {
664
- var _api$analytics3;
665
- return [{
666
- type: 'separator'
667
- }, getHyperlinkToolbarSettingsButton(intl, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.userPreferencesLink)];
668
- }
669
- }
670
- return [];
671
- };
672
564
  };
@@ -18,12 +18,13 @@ import CogIcon from '@atlaskit/icon/glyph/editor/settings';
18
18
  import UnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
19
19
  import OpenIcon from '@atlaskit/icon/glyph/shortcut';
20
20
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
21
- import { changeSelectedCardToText, editDatasource } from './pm-plugins/doc';
21
+ import { changeSelectedCardToText } from '../src/pm-plugins/doc';
22
22
  import { pluginKey } from './pm-plugins/main';
23
23
  import { DatasourceAppearanceButton } from './ui/DatasourceAppearanceButton';
24
- import { EditDatasourceButton } from './ui/EditDatasourceButton';
24
+ import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
25
25
  import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
26
26
  import { EditToolbarButton } from './ui/EditToolbarButton';
27
+ import { HyperlinkToolbarAppearance } from './ui/HyperlinkToolbarAppearance';
27
28
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
28
29
  import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
29
30
  import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, isDatasourceNode, titleUrlPairFromNode } from './utils';
@@ -226,7 +227,8 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
226
227
  intl: intl,
227
228
  editorAnalyticsApi: editorAnalyticsApi,
228
229
  editorView: editorView,
229
- onLinkEditClick: editLink(editorAnalyticsApi, true)
230
+ onLinkEditClick: editLink(editorAnalyticsApi, true),
231
+ currentAppearance: currentAppearance
230
232
  });
231
233
  }
232
234
  }] : [{
@@ -338,7 +340,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
338
340
  editorAnalyticsApi: editorAnalyticsApi,
339
341
  url: url,
340
342
  editorView: editorView,
341
- editorState: state
343
+ currentAppearance: currentAppearance
342
344
  });
343
345
  }
344
346
  });
@@ -395,7 +397,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
395
397
  metadata: metadata,
396
398
  className: 'datasource-edit',
397
399
  title: intl.formatMessage(linkToolbarMessages.editDatasource),
398
- onClick: editDatasource(datasourceId, editorAnalyticsApi),
400
+ onClick: editDatasource(datasourceId, editorAnalyticsApi, 'datasource'),
399
401
  testId: 'datasource-edit-button'
400
402
  }, {
401
403
  type: 'separator'
@@ -469,7 +471,8 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
469
471
  intl: intl,
470
472
  editorAnalyticsApi: editorAnalyticsApi,
471
473
  editorView: editorView,
472
- onLinkEditClick: editLink(editorAnalyticsApi, false)
474
+ onLinkEditClick: editLink(editorAnalyticsApi, false),
475
+ currentAppearance: "datasource"
473
476
  });
474
477
  }
475
478
  });
@@ -514,4 +517,87 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
514
517
  };
515
518
  export var shouldRenderToolbarPulse = function shouldRenderToolbarPulse(embedEnabled, appearance, status, isDiscoverabilityEnabled) {
516
519
  return embedEnabled && appearance === 'inline' && status === 'resolved' && isDiscoverabilityEnabled;
520
+ };
521
+ export var getStartingToolbarItems = function getStartingToolbarItems(options, api) {
522
+ return function (intl, link, providerFactory, onEditLink, metadata) {
523
+ var isEditDropdownEnabled = getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && options.platform !== 'mobile' && options.allowDatasource;
524
+ var editLinkItem = isEditDropdownEnabled ? [{
525
+ type: 'custom',
526
+ fallback: [],
527
+ render: function render(editorView) {
528
+ var _api$analytics;
529
+ if (!editorView) {
530
+ return null;
531
+ }
532
+ return /*#__PURE__*/React.createElement(EditToolbarButton, {
533
+ key: "edit-toolbar-button",
534
+ intl: intl,
535
+ editorAnalyticsApi: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions,
536
+ url: link,
537
+ editorView: editorView,
538
+ onLinkEditClick: onEditLink,
539
+ currentAppearance: "url"
540
+ });
541
+ }
542
+ }] : [{
543
+ id: 'editor.link.edit',
544
+ testId: 'editor.link.edit',
545
+ type: 'button',
546
+ onClick: onEditLink,
547
+ title: intl.formatMessage(linkToolbarMessages.editLink),
548
+ showTitle: true,
549
+ metadata: metadata
550
+ }, {
551
+ type: 'separator'
552
+ }];
553
+ return [{
554
+ type: 'custom',
555
+ fallback: [],
556
+ render: function render(editorView) {
557
+ return /*#__PURE__*/React.createElement(ToolbarViewedEvent, {
558
+ key: "edit.link.menu.viewed",
559
+ url: link,
560
+ display: "url",
561
+ editorView: editorView
562
+ });
563
+ }
564
+ }, {
565
+ type: 'custom',
566
+ fallback: [],
567
+ render: function render(editorView) {
568
+ var _api$analytics2;
569
+ if (!editorView) {
570
+ return null;
571
+ }
572
+ return /*#__PURE__*/React.createElement(HyperlinkToolbarAppearance, {
573
+ key: "link-appearance",
574
+ url: link,
575
+ intl: intl,
576
+ editorView: editorView,
577
+ editorState: editorView.state,
578
+ cardOptions: options,
579
+ providerFactory: providerFactory,
580
+ platform: options === null || options === void 0 ? void 0 : options.platform,
581
+ editorAnalyticsApi: api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
582
+ });
583
+ }
584
+ }].concat(editLinkItem);
585
+ };
586
+ };
587
+ export var getEndingToolbarItems = function getEndingToolbarItems(options, api) {
588
+ return function (intl, link) {
589
+ if (getBooleanFF('platform.editor.card.inject-settings-button')) {
590
+ /**
591
+ * Require either provider to be supplied (controls link preferences)
592
+ * Or explicit user preferences config in order to enable button
593
+ */
594
+ if (options.provider || options.userPreferencesLink) {
595
+ var _api$analytics3;
596
+ return [{
597
+ type: 'separator'
598
+ }, getHyperlinkToolbarSettingsButton(intl, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, options.userPreferencesLink)];
599
+ }
600
+ }
601
+ return [];
602
+ };
517
603
  };
@@ -1,11 +1,15 @@
1
1
  /** @jsx jsx */
2
+ import { useCallback } from 'react';
3
+
2
4
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { css, jsx } from '@emotion/react';
6
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
4
7
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
5
8
  import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator, SmallerEditIcon } from '@atlaskit/editor-common/ui';
9
+ import { getDatasourceType } from '@atlaskit/editor-common/utils';
6
10
  import { Flex } from '@atlaskit/primitives';
7
- import { editDatasource } from '../pm-plugins/doc';
8
- import { isDatasourceConfigEditable } from '../utils';
11
+ import { showDatasourceModal } from '../pm-plugins/actions';
12
+ import { focusEditorView, isDatasourceConfigEditable } from '../utils';
9
13
  import { CardContextProvider } from './CardContextProvider';
10
14
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
11
15
  var buttonStyles = css({
@@ -20,13 +24,20 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
20
24
  editorAnalyticsApi = _ref.editorAnalyticsApi,
21
25
  url = _ref.url,
22
26
  editorView = _ref.editorView,
23
- editorState = _ref.editorState;
27
+ currentAppearance = _ref.currentAppearance;
24
28
  var _useFetchDatasourceIn = useFetchDatasourceInfo({
25
29
  isRegularCardNode: true,
26
30
  url: url,
27
31
  cardContext: cardContext
28
32
  }),
29
- datasourceId = _useFetchDatasourceIn.datasourceId;
33
+ datasourceId = _useFetchDatasourceIn.datasourceId,
34
+ extensionKey = _useFetchDatasourceIn.extensionKey;
35
+ var onEditDatasource = useCallback(function () {
36
+ if (editorView && datasourceId) {
37
+ editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
38
+ focusEditorView(editorView);
39
+ }
40
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
30
41
  if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
31
42
  return null;
32
43
  }
@@ -37,20 +48,12 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
37
48
  return null;
38
49
  }
39
50
  }
40
- var dispatchCommand = function dispatchCommand(fn) {
41
- fn && fn(editorState, editorView && editorView.dispatch);
42
- if (editorView && !editorView.hasFocus()) {
43
- editorView.focus();
44
- }
45
- };
46
51
  return jsx(Flex, null, jsx(Button, {
47
52
  css: buttonStyles,
48
53
  title: intl.formatMessage(messages.datasourceTitle),
49
54
  icon: jsx(SmallerEditIcon, null),
50
55
  selected: false,
51
- onClick: function onClick() {
52
- return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
53
- },
56
+ onClick: onEditDatasource,
54
57
  testId: 'card-edit-datasource-button'
55
58
  }), jsx(Separator, null));
56
59
  };
@@ -59,7 +62,7 @@ export var EditDatasourceButton = function EditDatasourceButton(_ref2) {
59
62
  editorAnalyticsApi = _ref2.editorAnalyticsApi,
60
63
  url = _ref2.url,
61
64
  editorView = _ref2.editorView,
62
- editorState = _ref2.editorState;
65
+ currentAppearance = _ref2.currentAppearance;
63
66
  return jsx(CardContextProvider, null, function (_ref3) {
64
67
  var cardContext = _ref3.cardContext;
65
68
  return jsx(EditDatasourceButtonWithCardContext, {
@@ -67,8 +70,30 @@ export var EditDatasourceButton = function EditDatasourceButton(_ref2) {
67
70
  intl: intl,
68
71
  editorAnalyticsApi: editorAnalyticsApi,
69
72
  editorView: editorView,
70
- editorState: editorState,
71
- cardContext: cardContext
73
+ cardContext: cardContext,
74
+ currentAppearance: currentAppearance
72
75
  });
73
76
  });
77
+ };
78
+ export var editDatasource = function editDatasource(datasourceId, editorAnalyticsApi, appearance, extensionKey) {
79
+ return function (state, dispatch) {
80
+ var datasourceType = getDatasourceType(datasourceId);
81
+ if (dispatch && datasourceType) {
82
+ var tr = state.tr;
83
+ showDatasourceModal(datasourceType)(tr);
84
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
85
+ action: ACTION.CLICKED,
86
+ actionSubject: ACTION_SUBJECT.BUTTON,
87
+ actionSubjectId: ACTION_SUBJECT_ID.EDIT_DATASOURCE,
88
+ eventType: EVENT_TYPE.UI,
89
+ attributes: {
90
+ extensionKey: extensionKey,
91
+ appearance: appearance
92
+ }
93
+ })(tr);
94
+ dispatch(tr);
95
+ return true;
96
+ }
97
+ return false;
98
+ };
74
99
  };
@@ -1,4 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["extensionKey"];
2
4
  /** @jsx jsx */
3
5
  import { useCallback, useMemo, useRef, useState } from 'react';
4
6
 
@@ -11,8 +13,8 @@ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlask
11
13
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
12
14
  import { ButtonItem } from '@atlaskit/menu';
13
15
  import { Flex } from '@atlaskit/primitives';
14
- import { editDatasource } from '../pm-plugins/doc';
15
- import { isDatasourceConfigEditable } from '../utils';
16
+ import { editDatasource } from '../ui/EditDatasourceButton';
17
+ import { focusEditorView, isDatasourceConfigEditable } from '../utils';
16
18
  import { CardContextProvider } from './CardContextProvider';
17
19
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
18
20
  var dropdownExpandContainer = css({
@@ -20,17 +22,20 @@ var dropdownExpandContainer = css({
20
22
  });
21
23
  var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext(props) {
22
24
  var _response$datasourceI;
23
- var url = props.url,
24
- cardContext = props.cardContext,
25
- intl = props.intl,
25
+ var cardContext = props.cardContext,
26
+ currentAppearance = props.currentAppearance,
26
27
  editorAnalyticsApi = props.editorAnalyticsApi,
27
28
  editorView = props.editorView,
28
- onLinkEditClick = props.onLinkEditClick;
29
- var response = useFetchDatasourceInfo({
30
- isRegularCardNode: true,
31
- url: url,
32
- cardContext: cardContext
33
- });
29
+ intl = props.intl,
30
+ onLinkEditClick = props.onLinkEditClick,
31
+ url = props.url;
32
+ var _useFetchDatasourceIn = useFetchDatasourceInfo({
33
+ isRegularCardNode: true,
34
+ url: url,
35
+ cardContext: cardContext
36
+ }),
37
+ extensionKey = _useFetchDatasourceIn.extensionKey,
38
+ response = _objectWithoutProperties(_useFetchDatasourceIn, _excluded);
34
39
  var datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
35
40
  var _useState = useState(false),
36
41
  _useState2 = _slicedToArray(_useState, 2),
@@ -45,17 +50,12 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
45
50
  var onClose = function onClose() {
46
51
  return setIsOpen(false);
47
52
  };
48
- var dispatchCommand = useCallback(function (fn) {
53
+ var onEditLink = useCallback(function () {
49
54
  if (editorView) {
50
- fn === null || fn === void 0 || fn(editorView.state, editorView.dispatch);
51
- if (!editorView.hasFocus()) {
52
- editorView.focus();
53
- }
55
+ onLinkEditClick(editorView.state, editorView.dispatch);
56
+ focusEditorView(editorView);
54
57
  }
55
- }, [editorView]);
56
- var onEditLink = useCallback(function () {
57
- dispatchCommand(onLinkEditClick);
58
- }, [dispatchCommand, onLinkEditClick]);
58
+ }, [editorView, onLinkEditClick]);
59
59
  var editVariant = useMemo(function () {
60
60
  var hasUrl = url !== null && url !== undefined;
61
61
  if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
@@ -76,10 +76,11 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
76
76
  }
77
77
  }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
78
78
  var onEditDatasource = useCallback(function () {
79
- if (datasourceId) {
80
- dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
79
+ if (editorView && datasourceId) {
80
+ editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
81
+ focusEditorView(editorView);
81
82
  }
82
- }, [dispatchCommand, datasourceId, editorAnalyticsApi]);
83
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
83
84
  switch (editVariant) {
84
85
  case 'edit-link':
85
86
  {
@@ -144,12 +145,13 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
144
145
  }
145
146
  };
146
147
  export var EditToolbarButton = function EditToolbarButton(props) {
147
- var datasourceId = props.datasourceId,
148
- intl = props.intl,
148
+ var currentAppearance = props.currentAppearance,
149
+ datasourceId = props.datasourceId,
149
150
  editorAnalyticsApi = props.editorAnalyticsApi,
150
- url = props.url,
151
151
  editorView = props.editorView,
152
- onLinkEditClick = props.onLinkEditClick;
152
+ intl = props.intl,
153
+ onLinkEditClick = props.onLinkEditClick,
154
+ url = props.url;
153
155
  return jsx(CardContextProvider, null, function (_ref) {
154
156
  var cardContext = _ref.cardContext;
155
157
  return jsx(EditToolbarButtonWithCardContext, {
@@ -159,7 +161,8 @@ export var EditToolbarButton = function EditToolbarButton(props) {
159
161
  editorAnalyticsApi: editorAnalyticsApi,
160
162
  editorView: editorView,
161
163
  cardContext: cardContext,
162
- onLinkEditClick: onLinkEditClick
164
+ onLinkEditClick: onLinkEditClick,
165
+ currentAppearance: currentAppearance
163
166
  });
164
167
  });
165
168
  };
@@ -154,9 +154,9 @@ export var HyperlinkToolbarAppearance = /*#__PURE__*/function (_Component) {
154
154
  return /*#__PURE__*/React.createElement(Flex, null, !getBooleanFF('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') && /*#__PURE__*/React.createElement(EditDatasourceButton, {
155
155
  url: url,
156
156
  intl: intl,
157
- editorState: editorState,
158
157
  editorView: editorView,
159
- editorAnalyticsApi: editorAnalyticsApi
158
+ editorAnalyticsApi: editorAnalyticsApi,
159
+ currentAppearance: "url"
160
160
  }), /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
161
161
  key: "link-appearance",
162
162
  url: url,
@@ -22,6 +22,10 @@ export var useFetchDatasourceInfo = function useFetchDatasourceInfo(_ref) {
22
22
  _useState6 = _slicedToArray(_useState5, 2),
23
23
  ready = _useState6[0],
24
24
  setReady = _useState6[1];
25
+ var _useState7 = useState(undefined),
26
+ _useState8 = _slicedToArray(_useState7, 2),
27
+ extensionKey = _useState8[0],
28
+ setExtensionKey = _useState8[1];
25
29
  useEffect(function () {
26
30
  var fetchDatasource = /*#__PURE__*/function () {
27
31
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
@@ -43,24 +47,26 @@ export var useFetchDatasourceInfo = function useFetchDatasourceInfo(_ref) {
43
47
  case 6:
44
48
  response = _context.sent;
45
49
  datasources = response && response.datasources || [];
50
+ setExtensionKey(response === null || response === void 0 ? void 0 : response.meta.key);
46
51
  setDatasourceId((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id);
47
52
  setParameters((_datasources$2 = datasources[0]) === null || _datasources$2 === void 0 ? void 0 : _datasources$2.parameters);
48
53
  setReady(true);
49
- _context.next = 18;
54
+ _context.next = 20;
50
55
  break;
51
- case 13:
52
- _context.prev = 13;
56
+ case 14:
57
+ _context.prev = 14;
53
58
  _context.t0 = _context["catch"](0);
54
59
  setDatasourceId(undefined);
55
60
  setParameters(undefined);
61
+ setExtensionKey(undefined);
56
62
  // If fetch somehow errors, still set ready as true so we don't block the rendering of the modal.
57
63
  // It will just open with empty params.
58
64
  setReady(true);
59
- case 18:
65
+ case 20:
60
66
  case "end":
61
67
  return _context.stop();
62
68
  }
63
- }, _callee, null, [[0, 13]]);
69
+ }, _callee, null, [[0, 14]]);
64
70
  }));
65
71
  return function fetchDatasource() {
66
72
  return _ref2.apply(this, arguments);
@@ -73,6 +79,7 @@ export var useFetchDatasourceInfo = function useFetchDatasourceInfo(_ref) {
73
79
  return {
74
80
  datasourceId: datasourceId,
75
81
  parameters: parameters,
76
- ready: ready
82
+ ready: ready,
83
+ extensionKey: extensionKey
77
84
  };
78
85
  };
package/dist/esm/utils.js CHANGED
@@ -115,4 +115,14 @@ export var isDatasourceNode = function isDatasourceNode(node) {
115
115
  return false;
116
116
  }
117
117
  return node.type.name === 'blockCard' && isDatasourceAdfAttributes(node.attrs);
118
+ };
119
+
120
+ /**
121
+ * Focuses the editorView if it's not already focused.
122
+ * @param editorView The editor view to focus.
123
+ */
124
+ export var focusEditorView = function focusEditorView(editorView) {
125
+ if (!editorView.hasFocus()) {
126
+ editorView.focus();
127
+ }
118
128
  };
@@ -1,16 +1,14 @@
1
- import { type IntlShape } from 'react-intl-next';
2
1
  import type { CreateUIAnalyticsEvent, UIAnalyticsEvent } from '@atlaskit/analytics-next';
3
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
3
  import { ACTION } from '@atlaskit/editor-common/analytics';
5
4
  import type { CardReplacementInputMethod } from '@atlaskit/editor-common/card';
6
- import type { CardAdf, CardAppearance, DatasourceAdf, ProviderFactory } from '@atlaskit/editor-common/provider-factory';
7
- import type { Command, ExtractInjectionAPI, FloatingToolbarItem } from '@atlaskit/editor-common/types';
5
+ import type { CardAdf, CardAppearance, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
6
+ import type { Command } from '@atlaskit/editor-common/types';
8
7
  import type { Node, NodeType } from '@atlaskit/editor-prosemirror/model';
9
8
  import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
10
9
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
11
10
  import type { InlineCardAdf } from '@atlaskit/smart-card';
12
- import { type cardPlugin } from '../plugin';
13
- import type { CardPluginOptions, Request } from '../types';
11
+ import type { Request } from '../types';
14
12
  export declare const replaceQueuedUrlWithCard: (url: string, cardData: CardAdf | DatasourceAdf, analyticsAction?: ACTION, editorAnalyticsApi?: EditorAnalyticsAPI, createAnalyticsEvent?: CreateUIAnalyticsEvent) => Command;
15
13
  export declare const handleFallbackWithAnalytics: (request: Request, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
16
14
  export declare const queueCardsFromChangedTr: (state: EditorState, tr: Transaction, source: CardReplacementInputMethod, analyticsAction?: ACTION, normalizeLinkText?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Transaction;
@@ -40,10 +38,4 @@ export declare const insertDatasource: (state: EditorState, adf: DatasourceAdf |
40
38
  * Get attributes for new Card Appearance
41
39
  */
42
40
  export declare const getAttrsForAppearance: (appearance: CardAppearance, selectedNode: Node) => import("prosemirror-model").Attrs;
43
- export declare const editDatasource: (datasourceId: string, editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
44
- export declare const getStartingToolbarItems: (options: CardPluginOptions, api?: ExtractInjectionAPI<typeof cardPlugin> | undefined) => (intl: IntlShape, link: string, providerFactory: ProviderFactory, onEditLink: Command, metadata: {
45
- url: string;
46
- title: string;
47
- }) => FloatingToolbarItem<Command>[];
48
- export declare const getEndingToolbarItems: (options: CardPluginOptions, api?: ExtractInjectionAPI<typeof cardPlugin> | undefined) => (intl: IntlShape, link: string) => FloatingToolbarItem<Command>[];
49
41
  export {};
@@ -1,8 +1,10 @@
1
1
  import type { IntlShape } from 'react-intl-next';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
3
  import type { CardOptions } from '@atlaskit/editor-common/card';
4
+ import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
4
5
  import type { Command, ExtractInjectionAPI, FloatingToolbarHandler, FloatingToolbarItem, LinkPickerOptions } from '@atlaskit/editor-common/types';
5
6
  import type { CardPlatform } from '@atlaskit/smart-card';
7
+ import type { CardPluginOptions } from './types';
6
8
  import type { cardPlugin } from './index';
7
9
  export declare const removeCard: (editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
8
10
  export declare const visitCardLink: (editorAnalyticsApi: EditorAnalyticsAPI | undefined) => Command;
@@ -12,3 +14,8 @@ export declare const getHyperlinkToolbarSettingsButton: (intl: IntlShape, editor
12
14
  export declare const getSettingsButton: (intl: IntlShape, editorAnalyticsApi: EditorAnalyticsAPI | undefined, userPreferencesLink: string | undefined) => FloatingToolbarItem<Command>;
13
15
  export declare const getSettingsButtonGroup: (intl: IntlShape, editorAnalyticsApi: EditorAnalyticsAPI | undefined, userPreferencesLink: string | undefined) => FloatingToolbarItem<Command>[];
14
16
  export declare const shouldRenderToolbarPulse: (embedEnabled: boolean, appearance: string, status: string, isDiscoverabilityEnabled: boolean) => boolean;
17
+ export declare const getStartingToolbarItems: (options: CardPluginOptions, api?: ExtractInjectionAPI<typeof cardPlugin> | undefined) => (intl: IntlShape, link: string, providerFactory: ProviderFactory, onEditLink: Command, metadata: {
18
+ url: string;
19
+ title: string;
20
+ }) => FloatingToolbarItem<Command>[];
21
+ export declare const getEndingToolbarItems: (options: CardPluginOptions, api?: ExtractInjectionAPI<typeof cardPlugin> | undefined) => (intl: IntlShape, link: string) => FloatingToolbarItem<Command>[];
@@ -10,6 +10,7 @@ import type { SmartLinkEvents } from '@atlaskit/smart-card';
10
10
  import type { EditorCardPluginEvents } from './analytics/create-events-queue';
11
11
  import type { CardPluginEvent } from './analytics/types';
12
12
  import type { DatasourceTableLayout } from './ui/LayoutButton/types';
13
+ export type CardType = CardAppearance | 'url' | 'datasource';
13
14
  export type DatasourceNode = Omit<Node, 'attrs'> & {
14
15
  readonly attrs: DatasourceAdf['attrs'] & Partial<RichMediaAttributes>;
15
16
  };
@@ -1,16 +1,17 @@
1
- /** @jsx jsx */
2
1
  import { jsx } from '@emotion/react';
3
2
  import type { IntlShape } from 'react-intl-next';
4
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
5
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
+ import { type Command } from '@atlaskit/editor-common/types';
6
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
7
6
  import type { CardContext } from '@atlaskit/link-provider';
7
+ import { type CardType } from '../types';
8
8
  export interface EditDatasourceButtonProps {
9
9
  intl: IntlShape;
10
10
  editorAnalyticsApi?: EditorAnalyticsAPI;
11
11
  url?: string;
12
12
  editorView?: EditorView;
13
- editorState: EditorState;
14
13
  cardContext?: CardContext;
14
+ currentAppearance?: CardType;
15
15
  }
16
- export declare const EditDatasourceButton: ({ intl, editorAnalyticsApi, url, editorView, editorState, }: EditDatasourceButtonProps) => jsx.JSX.Element;
16
+ export declare const EditDatasourceButton: ({ intl, editorAnalyticsApi, url, editorView, currentAppearance, }: EditDatasourceButtonProps) => jsx.JSX.Element;
17
+ export declare const editDatasource: (datasourceId: string, editorAnalyticsApi?: EditorAnalyticsAPI, appearance?: CardType, extensionKey?: string) => Command;