@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
@@ -11,6 +11,7 @@ export const useFetchDatasourceInfo = ({
11
11
  // Since fetchData() is async, using this ready check to see if we have the parameters before passing it to the modal.
12
12
  // Only non-datasource nodes will be not ready initially since we need to fetch data.
13
13
  const [ready, setReady] = useState(!isRegularCardNode);
14
+ const [extensionKey, setExtensionKey] = useState(undefined);
14
15
  useEffect(() => {
15
16
  const fetchDatasource = async () => {
16
17
  try {
@@ -22,12 +23,14 @@ export const useFetchDatasourceInfo = ({
22
23
  }
23
24
  const response = await (cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$connecti = cardContext.connections) === null || _cardContext$connecti === void 0 ? void 0 : (_cardContext$connecti2 = _cardContext$connecti.client) === null || _cardContext$connecti2 === void 0 ? void 0 : _cardContext$connecti2.fetchData(url));
24
25
  const datasources = response && response.datasources || [];
26
+ setExtensionKey(response === null || response === void 0 ? void 0 : response.meta.key);
25
27
  setDatasourceId((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id);
26
28
  setParameters((_datasources$2 = datasources[0]) === null || _datasources$2 === void 0 ? void 0 : _datasources$2.parameters);
27
29
  setReady(true);
28
30
  } catch (e) {
29
31
  setDatasourceId(undefined);
30
32
  setParameters(undefined);
33
+ setExtensionKey(undefined);
31
34
  // If fetch somehow errors, still set ready as true so we don't block the rendering of the modal.
32
35
  // It will just open with empty params.
33
36
  setReady(true);
@@ -40,6 +43,7 @@ export const useFetchDatasourceInfo = ({
40
43
  return {
41
44
  datasourceId,
42
45
  parameters,
43
- ready
46
+ ready,
47
+ extensionKey
44
48
  };
45
49
  };
@@ -108,4 +108,14 @@ export const isDatasourceNode = node => {
108
108
  return false;
109
109
  }
110
110
  return node.type.name === 'blockCard' && isDatasourceAdfAttributes(node.attrs);
111
+ };
112
+
113
+ /**
114
+ * Focuses the editorView if it's not already focused.
115
+ * @param editorView The editor view to focus.
116
+ */
117
+ export const focusEditorView = editorView => {
118
+ if (!editorView.hasFocus()) {
119
+ editorView.focus();
120
+ }
111
121
  };
@@ -13,6 +13,8 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
13
13
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
14
  /** @jsx jsx */
15
15
  import React from 'react';
16
+
17
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
16
18
  import { jsx } from '@emotion/react';
17
19
  import PropTypes from 'prop-types';
18
20
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
@@ -8,13 +8,13 @@ import { IconDatasourceAssetsObjects, IconDatasourceConfluenceSearch, IconDataso
8
8
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
9
9
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, CONFLUENCE_SEARCH_DATASOURCE_ID } from '@atlaskit/link-datasource';
10
10
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
+ import { queueCardsFromChangedTr } from '../src/pm-plugins/doc';
11
12
  import { createEventsQueue } from './analytics/create-events-queue';
12
13
  import { hideLinkToolbar, showDatasourceModal } from './pm-plugins/actions';
13
- import { getEndingToolbarItems, getStartingToolbarItems, queueCardsFromChangedTr } from './pm-plugins/doc';
14
14
  import { cardKeymap } from './pm-plugins/keymap';
15
15
  import { createPlugin } from './pm-plugins/main';
16
16
  import { pluginKey } from './pm-plugins/plugin-key';
17
- import { floatingToolbar } from './toolbar';
17
+ import { floatingToolbar, getEndingToolbarItems, getStartingToolbarItems } from './toolbar';
18
18
  import DatasourceModalWithState from './ui/DatasourceModal/ModalWithState';
19
19
  import { EditorLinkingPlatformAnalytics } from './ui/EditorLinkingPlatformAnalytics';
20
20
  import { EditorSmartCardEvents } from './ui/EditorSmartCardEvents';
@@ -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,6 +1,8 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useCallback, useEffect, useMemo, useState } from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
4
6
  import { css, jsx } from '@emotion/react';
5
7
  import { AnalyticsContext } from '@atlaskit/analytics-next';
6
8
  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
  var buttonStyles = css({
@@ -19,13 +24,20 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
19
24
  editorAnalyticsApi = _ref.editorAnalyticsApi,
20
25
  url = _ref.url,
21
26
  editorView = _ref.editorView,
22
- editorState = _ref.editorState;
27
+ currentAppearance = _ref.currentAppearance;
23
28
  var _useFetchDatasourceIn = useFetchDatasourceInfo({
24
29
  isRegularCardNode: true,
25
30
  url: url,
26
31
  cardContext: cardContext
27
32
  }),
28
- 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]);
29
41
  if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
30
42
  return null;
31
43
  }
@@ -36,20 +48,12 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
36
48
  return null;
37
49
  }
38
50
  }
39
- var dispatchCommand = function dispatchCommand(fn) {
40
- fn && fn(editorState, editorView && editorView.dispatch);
41
- if (editorView && !editorView.hasFocus()) {
42
- editorView.focus();
43
- }
44
- };
45
51
  return jsx(Flex, null, jsx(Button, {
46
52
  css: buttonStyles,
47
53
  title: intl.formatMessage(messages.datasourceTitle),
48
54
  icon: jsx(SmallerEditIcon, null),
49
55
  selected: false,
50
- onClick: function onClick() {
51
- return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
52
- },
56
+ onClick: onEditDatasource,
53
57
  testId: 'card-edit-datasource-button'
54
58
  }), jsx(Separator, null));
55
59
  };
@@ -58,7 +62,7 @@ export var EditDatasourceButton = function EditDatasourceButton(_ref2) {
58
62
  editorAnalyticsApi = _ref2.editorAnalyticsApi,
59
63
  url = _ref2.url,
60
64
  editorView = _ref2.editorView,
61
- editorState = _ref2.editorState;
65
+ currentAppearance = _ref2.currentAppearance;
62
66
  return jsx(CardContextProvider, null, function (_ref3) {
63
67
  var cardContext = _ref3.cardContext;
64
68
  return jsx(EditDatasourceButtonWithCardContext, {
@@ -66,8 +70,30 @@ export var EditDatasourceButton = function EditDatasourceButton(_ref2) {
66
70
  intl: intl,
67
71
  editorAnalyticsApi: editorAnalyticsApi,
68
72
  editorView: editorView,
69
- editorState: editorState,
70
- cardContext: cardContext
73
+ cardContext: cardContext,
74
+ currentAppearance: currentAppearance
71
75
  });
72
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
+ };
73
99
  };
@@ -1,6 +1,10 @@
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';
6
+
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
4
8
  import { css, jsx } from '@emotion/react';
5
9
  import { FormattedMessage } from 'react-intl-next';
6
10
  import { linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
@@ -9,8 +13,8 @@ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlask
9
13
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
10
14
  import { ButtonItem } from '@atlaskit/menu';
11
15
  import { Flex } from '@atlaskit/primitives';
12
- import { editDatasource } from '../pm-plugins/doc';
13
- import { isDatasourceConfigEditable } from '../utils';
16
+ import { editDatasource } from '../ui/EditDatasourceButton';
17
+ import { focusEditorView, isDatasourceConfigEditable } from '../utils';
14
18
  import { CardContextProvider } from './CardContextProvider';
15
19
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
16
20
  var dropdownExpandContainer = css({
@@ -18,17 +22,20 @@ var dropdownExpandContainer = css({
18
22
  });
19
23
  var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext(props) {
20
24
  var _response$datasourceI;
21
- var url = props.url,
22
- cardContext = props.cardContext,
23
- intl = props.intl,
25
+ var cardContext = props.cardContext,
26
+ currentAppearance = props.currentAppearance,
24
27
  editorAnalyticsApi = props.editorAnalyticsApi,
25
28
  editorView = props.editorView,
26
- onLinkEditClick = props.onLinkEditClick;
27
- var response = useFetchDatasourceInfo({
28
- isRegularCardNode: true,
29
- url: url,
30
- cardContext: cardContext
31
- });
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);
32
39
  var datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
33
40
  var _useState = useState(false),
34
41
  _useState2 = _slicedToArray(_useState, 2),
@@ -43,17 +50,12 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
43
50
  var onClose = function onClose() {
44
51
  return setIsOpen(false);
45
52
  };
46
- var dispatchCommand = useCallback(function (fn) {
53
+ var onEditLink = useCallback(function () {
47
54
  if (editorView) {
48
- fn === null || fn === void 0 || fn(editorView.state, editorView.dispatch);
49
- if (!editorView.hasFocus()) {
50
- editorView.focus();
51
- }
55
+ onLinkEditClick(editorView.state, editorView.dispatch);
56
+ focusEditorView(editorView);
52
57
  }
53
- }, [editorView]);
54
- var onEditLink = useCallback(function () {
55
- dispatchCommand(onLinkEditClick);
56
- }, [dispatchCommand, onLinkEditClick]);
58
+ }, [editorView, onLinkEditClick]);
57
59
  var editVariant = useMemo(function () {
58
60
  var hasUrl = url !== null && url !== undefined;
59
61
  if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
@@ -74,10 +76,11 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
74
76
  }
75
77
  }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
76
78
  var onEditDatasource = useCallback(function () {
77
- if (datasourceId) {
78
- dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
79
+ if (editorView && datasourceId) {
80
+ editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
81
+ focusEditorView(editorView);
79
82
  }
80
- }, [dispatchCommand, datasourceId, editorAnalyticsApi]);
83
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
81
84
  switch (editVariant) {
82
85
  case 'edit-link':
83
86
  {
@@ -142,12 +145,13 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
142
145
  }
143
146
  };
144
147
  export var EditToolbarButton = function EditToolbarButton(props) {
145
- var datasourceId = props.datasourceId,
146
- intl = props.intl,
148
+ var currentAppearance = props.currentAppearance,
149
+ datasourceId = props.datasourceId,
147
150
  editorAnalyticsApi = props.editorAnalyticsApi,
148
- url = props.url,
149
151
  editorView = props.editorView,
150
- onLinkEditClick = props.onLinkEditClick;
152
+ intl = props.intl,
153
+ onLinkEditClick = props.onLinkEditClick,
154
+ url = props.url;
151
155
  return jsx(CardContextProvider, null, function (_ref) {
152
156
  var cardContext = _ref.cardContext;
153
157
  return jsx(EditToolbarButtonWithCardContext, {
@@ -157,7 +161,8 @@ export var EditToolbarButton = function EditToolbarButton(props) {
157
161
  editorAnalyticsApi: editorAnalyticsApi,
158
162
  editorView: editorView,
159
163
  cardContext: cardContext,
160
- onLinkEditClick: onLinkEditClick
164
+ onLinkEditClick: onLinkEditClick,
165
+ currentAppearance: currentAppearance
161
166
  });
162
167
  });
163
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,
@@ -8,6 +8,8 @@ var _active;
8
8
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
9
9
  /** @jsx jsx */
10
10
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
11
+
12
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
11
13
  import { css, jsx } from '@emotion/react';
12
14
  import debounce from 'lodash/debounce';
13
15
  import { useIntl } from 'react-intl-next';
@@ -3,6 +3,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  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; }
4
4
  /** @jsx jsx */
5
5
  import { useCallback, useMemo } 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 { injectIntl } from 'react-intl-next';
8
10
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
@@ -6,6 +6,8 @@ var _excluded = ["children", "isSelected", "isVisible", "testId"];
6
6
  /* eslint-disable @atlaskit/design-system/prefer-primitives */
7
7
  /** @jsx jsx */
8
8
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
9
+
10
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
11
  import { css, jsx } from '@emotion/react';
10
12
  import debounce from 'lodash/debounce';
11
13
  import { useIntl } from 'react-intl-next';
@@ -12,6 +12,8 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
12
12
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
13
13
  /** @jsx jsx */
14
14
  import React from 'react';
15
+
16
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
15
17
  import { jsx } from '@emotion/react';
16
18
  import { calcColumnsFromPx, calcMediaPxWidth, calcPctFromPx, calcPxFromColumns, handleSides, imageAlignmentMap, Resizer, snapTo, wrappedLayouts, wrapperStyle } from '@atlaskit/editor-common/ui';
17
19
  import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';