@atlaskit/editor-plugin-card 2.6.1 → 2.6.3

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 (47) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/nodeviews/blockCard.js +37 -13
  3. package/dist/cjs/nodeviews/embedCard.js +35 -10
  4. package/dist/cjs/toolbar.js +1 -0
  5. package/dist/cjs/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js} +15 -65
  6. package/dist/cjs/ui/EditToolbarButton/index.js +286 -0
  7. package/dist/cjs/ui/EditToolbarButton/types.js +5 -0
  8. package/dist/cjs/ui/useFetchDatasourceDataInfo.js +75 -0
  9. package/dist/es2019/nodeviews/blockCard.js +21 -4
  10. package/dist/es2019/nodeviews/embedCard.js +20 -1
  11. package/dist/es2019/toolbar.js +1 -0
  12. package/dist/es2019/ui/{EditToolbarButton.js → EditToolbarButton/EditToolbarButtonPresentation.js} +14 -67
  13. package/dist/es2019/ui/EditToolbarButton/index.js +278 -0
  14. package/dist/es2019/ui/EditToolbarButton/types.js +1 -0
  15. package/dist/es2019/ui/useFetchDatasourceDataInfo.js +41 -0
  16. package/dist/esm/nodeviews/blockCard.js +38 -14
  17. package/dist/esm/nodeviews/embedCard.js +35 -10
  18. package/dist/esm/toolbar.js +1 -0
  19. package/dist/esm/ui/EditToolbarButton/EditToolbarButtonPresentation.js +116 -0
  20. package/dist/esm/ui/{EditToolbarButton.js → EditToolbarButton/index.js} +116 -4
  21. package/dist/esm/ui/EditToolbarButton/types.js +1 -0
  22. package/dist/esm/ui/useFetchDatasourceDataInfo.js +67 -0
  23. package/dist/types/nodeviews/blockCard.d.ts +3 -0
  24. package/dist/types/nodeviews/embedCard.d.ts +3 -0
  25. package/dist/types/ui/EditToolbarButton/EditToolbarButtonPresentation.d.ts +9 -0
  26. package/dist/types/ui/EditToolbarButton/index.d.ts +3 -0
  27. package/dist/types/ui/EditToolbarButton/types.d.ts +29 -0
  28. package/dist/types/ui/useFetchDatasourceDataInfo.d.ts +10 -0
  29. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +3 -0
  30. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +3 -0
  31. package/dist/types-ts4.5/ui/EditToolbarButton/EditToolbarButtonPresentation.d.ts +9 -0
  32. package/dist/types-ts4.5/ui/EditToolbarButton/index.d.ts +3 -0
  33. package/dist/types-ts4.5/ui/EditToolbarButton/types.d.ts +29 -0
  34. package/dist/types-ts4.5/ui/useFetchDatasourceDataInfo.d.ts +10 -0
  35. package/package.json +10 -7
  36. package/dist/cjs/ui/LeftIconOverlay/ConfigureLinkDropdown/index.js +0 -58
  37. package/dist/cjs/ui/LeftIconOverlay/index.js +0 -199
  38. package/dist/es2019/ui/LeftIconOverlay/ConfigureLinkDropdown/index.js +0 -47
  39. package/dist/es2019/ui/LeftIconOverlay/index.js +0 -177
  40. package/dist/esm/ui/LeftIconOverlay/ConfigureLinkDropdown/index.js +0 -48
  41. package/dist/esm/ui/LeftIconOverlay/index.js +0 -190
  42. package/dist/types/ui/EditToolbarButton.d.ts +0 -18
  43. package/dist/types/ui/LeftIconOverlay/ConfigureLinkDropdown/index.d.ts +0 -6
  44. package/dist/types/ui/LeftIconOverlay/index.d.ts +0 -10
  45. package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +0 -18
  46. package/dist/types-ts4.5/ui/LeftIconOverlay/ConfigureLinkDropdown/index.d.ts +0 -6
  47. package/dist/types-ts4.5/ui/LeftIconOverlay/index.d.ts +0 -10
@@ -14,7 +14,7 @@ import rafSchedule from 'raf-schd';
14
14
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
15
15
  import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
16
16
  import { browser } from '@atlaskit/editor-common/utils';
17
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
+ import { fg } from '@atlaskit/platform-feature-flags';
18
18
  import { Card as SmartCard } from '@atlaskit/smart-card';
19
19
  import { registerCard } from '../pm-plugins/actions';
20
20
  import { isDatasourceNode } from '../utils';
@@ -126,30 +126,48 @@ export var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
126
126
  _inherits(BlockCard, _ReactNodeView);
127
127
  var _super2 = _createSuper(BlockCard);
128
128
  function BlockCard() {
129
+ var _this2;
129
130
  _classCallCheck(this, BlockCard);
130
- return _super2.apply(this, arguments);
131
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
132
+ args[_key2] = arguments[_key2];
133
+ }
134
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
135
+ _defineProperty(_assertThisInitialized(_this2), "updateContentEditable", function (editorViewModeState, divElement) {
136
+ divElement.contentEditable = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? 'false' : 'true';
137
+ });
138
+ return _this2;
131
139
  }
132
140
  _createClass(BlockCard, [{
133
141
  key: "createDomRef",
134
142
  value: function createDomRef() {
143
+ var _this3 = this;
135
144
  var domRef = document.createElement('div');
136
145
  if (this.reactComponentProps.platform !== 'mobile') {
137
146
  // workaround Chrome bug in https://product-fabric.atlassian.net/browse/ED-5379
138
147
  // see also: https://github.com/ProseMirror/prosemirror/issues/884
139
- domRef.contentEditable = 'true';
148
+ if (fg('linking-platform-contenteditable-false-live-view')) {
149
+ var _this$reactComponentP, _this$reactComponentP2;
150
+ this.unsubscribe = (_this$reactComponentP = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP === void 0 || (_this$reactComponentP = _this$reactComponentP.editorViewMode) === null || _this$reactComponentP === void 0 ? void 0 : _this$reactComponentP.sharedState.onChange(function (_ref2) {
151
+ var nextSharedState = _ref2.nextSharedState;
152
+ return _this3.updateContentEditable(nextSharedState, domRef);
153
+ });
154
+ this.updateContentEditable((_this$reactComponentP2 = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP2 === void 0 || (_this$reactComponentP2 = _this$reactComponentP2.editorViewMode) === null || _this$reactComponentP2 === void 0 ? void 0 : _this$reactComponentP2.sharedState.currentState(), domRef);
155
+ } else {
156
+ domRef.contentEditable = 'true';
157
+ }
140
158
  domRef.setAttribute('spellcheck', 'false');
141
159
  }
142
160
  return domRef;
143
161
  }
144
-
162
+ }, {
163
+ key: "validUpdate",
164
+ value:
145
165
  // Need this function to check if the datasource attribute was added or not to a blockCard.
146
166
  // If so, we return false so we can get the node to re-render properly as a datasource node instead.
147
167
  // Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
148
- }, {
149
- key: "validUpdate",
150
- value: function validUpdate(currentNode, newNode) {
168
+ function validUpdate(currentNode, newNode) {
151
169
  var _currentNode$attrs, _newNode$attrs;
152
- if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
170
+ if (fg('platform.linking-platform.editor-datasource-typeguards')) {
153
171
  var _isCurrentNodeBlockCard = !isDatasourceNode(currentNode);
154
172
  var _isNewNodeDatasource = isDatasourceNode(newNode);
155
173
 
@@ -170,12 +188,12 @@ export var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
170
188
  }, {
171
189
  key: "render",
172
190
  value: function render() {
173
- var _this$reactComponentP = this.reactComponentProps,
174
- platform = _this$reactComponentP.platform,
175
- actionOptions = _this$reactComponentP.actionOptions,
176
- showServerActions = _this$reactComponentP.showServerActions,
177
- pluginInjectionApi = _this$reactComponentP.pluginInjectionApi,
178
- onClickCallback = _this$reactComponentP.onClickCallback;
191
+ var _this$reactComponentP3 = this.reactComponentProps,
192
+ platform = _this$reactComponentP3.platform,
193
+ actionOptions = _this$reactComponentP3.actionOptions,
194
+ showServerActions = _this$reactComponentP3.showServerActions,
195
+ pluginInjectionApi = _this$reactComponentP3.pluginInjectionApi,
196
+ onClickCallback = _this$reactComponentP3.onClickCallback;
179
197
  return /*#__PURE__*/React.createElement(WrappedBlockCard, {
180
198
  node: this.node,
181
199
  view: this.view,
@@ -187,6 +205,12 @@ export var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
187
205
  onClickCallback: onClickCallback
188
206
  });
189
207
  }
208
+ }, {
209
+ key: "destroy",
210
+ value: function destroy() {
211
+ var _this$unsubscribe;
212
+ (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
213
+ }
190
214
  }]);
191
215
  return BlockCard;
192
216
  }(ReactNodeView);
@@ -20,6 +20,7 @@ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
20
20
  import { findOverflowScrollParent, MediaSingle as RichMediaWrapper, UnsupportedBlock } from '@atlaskit/editor-common/ui';
21
21
  import { floatingLayouts, isRichMediaInsideOfBlockNode } from '@atlaskit/editor-common/utils';
22
22
  import { DEFAULT_EMBED_CARD_HEIGHT, DEFAULT_EMBED_CARD_WIDTH } from '@atlaskit/editor-shared-styles';
23
+ import { fg } from '@atlaskit/platform-feature-flags';
23
24
  import { EmbedResizeMessageListener, Card as SmartCard } from '@atlaskit/smart-card';
24
25
  import { registerCard } from '../pm-plugins/actions';
25
26
  import ResizableEmbedCard from '../ui/ResizableEmbedCard';
@@ -343,8 +344,16 @@ export var EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
343
344
  _inherits(EmbedCard, _ReactNodeView);
344
345
  var _super2 = _createSuper(EmbedCard);
345
346
  function EmbedCard() {
347
+ var _this2;
346
348
  _classCallCheck(this, EmbedCard);
347
- return _super2.apply(this, arguments);
349
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
350
+ args[_key2] = arguments[_key2];
351
+ }
352
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
353
+ _defineProperty(_assertThisInitialized(_this2), "updateContentEditable", function (editorViewModeState, divElement) {
354
+ divElement.contentEditable = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? 'false' : 'true';
355
+ });
356
+ return _this2;
348
357
  }
349
358
  _createClass(EmbedCard, [{
350
359
  key: "viewShouldUpdate",
@@ -357,10 +366,20 @@ export var EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
357
366
  }, {
358
367
  key: "createDomRef",
359
368
  value: function createDomRef() {
369
+ var _this3 = this;
360
370
  var domRef = document.createElement('div');
361
371
  if (this.reactComponentProps.platform !== 'mobile') {
362
372
  // It is a tradeoff for the bug mentioned that occurs in Chrome: https://product-fabric.atlassian.net/browse/ED-5379, https://github.com/ProseMirror/prosemirror/issues/884
363
- domRef.contentEditable = 'true';
373
+ if (fg('linking-platform-contenteditable-false-live-view')) {
374
+ var _this$reactComponentP, _this$reactComponentP2;
375
+ this.unsubscribe = (_this$reactComponentP = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP === void 0 || (_this$reactComponentP = _this$reactComponentP.editorViewMode) === null || _this$reactComponentP === void 0 ? void 0 : _this$reactComponentP.sharedState.onChange(function (_ref3) {
376
+ var nextSharedState = _ref3.nextSharedState;
377
+ return _this3.updateContentEditable(nextSharedState, domRef);
378
+ });
379
+ this.updateContentEditable((_this$reactComponentP2 = this.reactComponentProps.pluginInjectionApi) === null || _this$reactComponentP2 === void 0 || (_this$reactComponentP2 = _this$reactComponentP2.editorViewMode) === null || _this$reactComponentP2 === void 0 ? void 0 : _this$reactComponentP2.sharedState.currentState(), domRef);
380
+ } else {
381
+ domRef.contentEditable = 'true';
382
+ }
364
383
  domRef.setAttribute('spellcheck', 'false');
365
384
  }
366
385
  return domRef;
@@ -368,14 +387,14 @@ export var EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
368
387
  }, {
369
388
  key: "render",
370
389
  value: function render() {
371
- var _this$reactComponentP = this.reactComponentProps,
372
- eventDispatcher = _this$reactComponentP.eventDispatcher,
373
- allowResizing = _this$reactComponentP.allowResizing,
374
- platform = _this$reactComponentP.platform,
375
- fullWidthMode = _this$reactComponentP.fullWidthMode,
376
- dispatchAnalyticsEvent = _this$reactComponentP.dispatchAnalyticsEvent,
377
- pluginInjectionApi = _this$reactComponentP.pluginInjectionApi,
378
- onClickCallback = _this$reactComponentP.onClickCallback;
390
+ var _this$reactComponentP3 = this.reactComponentProps,
391
+ eventDispatcher = _this$reactComponentP3.eventDispatcher,
392
+ allowResizing = _this$reactComponentP3.allowResizing,
393
+ platform = _this$reactComponentP3.platform,
394
+ fullWidthMode = _this$reactComponentP3.fullWidthMode,
395
+ dispatchAnalyticsEvent = _this$reactComponentP3.dispatchAnalyticsEvent,
396
+ pluginInjectionApi = _this$reactComponentP3.pluginInjectionApi,
397
+ onClickCallback = _this$reactComponentP3.onClickCallback;
379
398
  return /*#__PURE__*/React.createElement(WrappedBlockCard, {
380
399
  node: this.node,
381
400
  view: this.view,
@@ -389,6 +408,12 @@ export var EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
389
408
  onClickCallback: onClickCallback
390
409
  });
391
410
  }
411
+ }, {
412
+ key: "destroy",
413
+ value: function destroy() {
414
+ var _this$unsubscribe;
415
+ (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
416
+ }
392
417
  }]);
393
418
  return EmbedCard;
394
419
  }(ReactNodeView);
@@ -466,6 +466,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
466
466
  render: function render(editorView) {
467
467
  return /*#__PURE__*/React.createElement(EditToolbarButton, {
468
468
  datasourceId: datasourceId,
469
+ node: node,
469
470
  key: "edit-toolbar-item",
470
471
  url: metadata.url,
471
472
  intl: intl,
@@ -0,0 +1,116 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /** @jsx jsx */
3
+ import { useCallback, useRef, useState } from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
+ import { css, jsx } from '@emotion/react';
7
+ import { FormattedMessage } from 'react-intl-next';
8
+ import { linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
9
+ import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
10
+ import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlaskit/editor-common/ui-menu';
11
+ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
12
+ import { ButtonItem } from '@atlaskit/menu';
13
+ import { Flex } from '@atlaskit/primitives';
14
+ import { focusEditorView } from '../../utils';
15
+ import { editDatasource } from '../EditDatasourceButton';
16
+ var dropdownExpandContainer = css({
17
+ margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
18
+ });
19
+ var EditToolbarButtonPresentation = function EditToolbarButtonPresentation(_ref) {
20
+ var datasourceId = _ref.datasourceId,
21
+ currentAppearance = _ref.currentAppearance,
22
+ editorAnalyticsApi = _ref.editorAnalyticsApi,
23
+ editVariant = _ref.editVariant,
24
+ editorView = _ref.editorView,
25
+ extensionKey = _ref.extensionKey,
26
+ onLinkEditClick = _ref.onLinkEditClick,
27
+ intl = _ref.intl;
28
+ var _useState = useState(false),
29
+ _useState2 = _slicedToArray(_useState, 2),
30
+ isOpen = _useState2[0],
31
+ setIsOpen = _useState2[1];
32
+ var containerRef = useRef();
33
+ var toggleOpen = function toggleOpen() {
34
+ return setIsOpen(function (open) {
35
+ return !open;
36
+ });
37
+ };
38
+ var onClose = function onClose() {
39
+ return setIsOpen(false);
40
+ };
41
+ var onEditLink = useCallback(function () {
42
+ if (editorView) {
43
+ onLinkEditClick(editorView.state, editorView.dispatch);
44
+ focusEditorView(editorView);
45
+ }
46
+ }, [editorView, onLinkEditClick]);
47
+ var onEditDatasource = useCallback(function () {
48
+ if (editorView && datasourceId) {
49
+ editDatasource(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
50
+ focusEditorView(editorView);
51
+ }
52
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
53
+ switch (editVariant) {
54
+ case 'edit-link':
55
+ {
56
+ return jsx(Flex, {
57
+ gap: "space.050"
58
+ }, jsx(Button, {
59
+ testId: "edit-link",
60
+ onClick: onEditLink
61
+ }, jsx(FormattedMessage, linkToolbarMessages.editLink)), jsx(Separator, null));
62
+ }
63
+ case 'edit-datasource':
64
+ {
65
+ return jsx(Flex, {
66
+ gap: "space.050"
67
+ }, jsx(Button, {
68
+ testId: "edit-datasource",
69
+ tooltipContent: intl.formatMessage(linkToolbarMessages.editDatasourceStandaloneTooltip),
70
+ onClick: onEditDatasource
71
+ }, jsx(FormattedMessage, linkToolbarMessages.editDatasourceStandalone)), jsx(Separator, null));
72
+ }
73
+ case 'edit-dropdown':
74
+ {
75
+ var trigger = jsx(Flex, {
76
+ gap: "space.050"
77
+ }, jsx(Button, {
78
+ testId: "edit-dropdown-trigger",
79
+ iconAfter: jsx("span", {
80
+ css: dropdownExpandContainer
81
+ }, jsx(ExpandIcon, {
82
+ label: intl.formatMessage(messages.editDropdownTriggerTitle)
83
+ })),
84
+ onClick: toggleOpen,
85
+ selected: isOpen,
86
+ disabled: false,
87
+ ariaHasPopup: true
88
+ }, jsx(FormattedMessage, messages.editDropdownTriggerTitle)), jsx(Separator, null));
89
+ return jsx(Flex, {
90
+ ref: containerRef
91
+ }, jsx(UiDropdown, {
92
+ mountTo: containerRef.current,
93
+ isOpen: isOpen,
94
+ handleClickOutside: onClose,
95
+ handleEscapeKeydown: onClose,
96
+ trigger: trigger,
97
+ scrollableElement: containerRef.current,
98
+ arrowKeyNavigationProviderOptions: {
99
+ type: ArrowKeyNavigationType.MENU
100
+ }
101
+ }, jsx(ButtonItem, {
102
+ key: "edit.link",
103
+ onClick: onEditLink,
104
+ testId: "edit-dropdown-edit-link-item"
105
+ }, jsx(FormattedMessage, messages.editDropdownEditLinkTitle)), jsx(ButtonItem, {
106
+ key: "edit.datasource",
107
+ onClick: onEditDatasource,
108
+ testId: "edit-dropdown-edit-datasource-item"
109
+ }, jsx(FormattedMessage, messages.editDropdownEditDatasourceTitle))));
110
+ }
111
+ case 'none':
112
+ default:
113
+ return null;
114
+ }
115
+ };
116
+ export default EditToolbarButtonPresentation;
@@ -12,11 +12,14 @@ import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator
12
12
  import { ArrowKeyNavigationType, DropdownContainer as UiDropdown } from '@atlaskit/editor-common/ui-menu';
13
13
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
14
14
  import { ButtonItem } from '@atlaskit/menu';
15
+ import { fg } from '@atlaskit/platform-feature-flags';
15
16
  import { Flex } from '@atlaskit/primitives';
16
- import { editDatasource } from '../ui/EditDatasourceButton';
17
- import { focusEditorView, isDatasourceConfigEditable } from '../utils';
18
- import { CardContextProvider } from './CardContextProvider';
19
- import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
17
+ import { editDatasource } from '../../ui/EditDatasourceButton';
18
+ import { focusEditorView, isDatasourceConfigEditable } from '../../utils';
19
+ import { CardContextProvider } from '../CardContextProvider';
20
+ import { useFetchDatasourceDataInfo } from '../useFetchDatasourceDataInfo';
21
+ import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
22
+ import EditToolbarButtonPresentation from './EditToolbarButtonPresentation';
20
23
  var dropdownExpandContainer = css({
21
24
  margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
22
25
  });
@@ -144,6 +147,91 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
144
147
  return null;
145
148
  }
146
149
  };
150
+ var EditToolbarButtonWithUrl = function EditToolbarButtonWithUrl(props) {
151
+ var cardContext = props.cardContext,
152
+ currentAppearance = props.currentAppearance,
153
+ editorAnalyticsApi = props.editorAnalyticsApi,
154
+ editorView = props.editorView,
155
+ intl = props.intl,
156
+ onLinkEditClick = props.onLinkEditClick,
157
+ url = props.url;
158
+ var _useFetchDatasourceIn2 = useFetchDatasourceInfo({
159
+ isRegularCardNode: true,
160
+ url: url,
161
+ cardContext: cardContext
162
+ }),
163
+ extensionKey = _useFetchDatasourceIn2.extensionKey,
164
+ datasourceId = _useFetchDatasourceIn2.datasourceId;
165
+ var editVariant = useMemo(function () {
166
+ var _cardContext$store2, _urlState$error2;
167
+ if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
168
+ return 'edit-link';
169
+ }
170
+ var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store2 = cardContext.store) === null || _cardContext$store2 === void 0 ? void 0 : _cardContext$store2.getState()[url];
171
+ if ((urlState === null || urlState === void 0 || (_urlState$error2 = urlState.error) === null || _urlState$error2 === void 0 ? void 0 : _urlState$error2.kind) === 'fatal') {
172
+ return 'edit-link';
173
+ }
174
+ return 'edit-dropdown';
175
+ }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
176
+ return jsx(EditToolbarButtonPresentation, {
177
+ datasourceId: datasourceId,
178
+ currentAppearance: currentAppearance,
179
+ editorAnalyticsApi: editorAnalyticsApi,
180
+ editVariant: editVariant,
181
+ editorView: editorView,
182
+ extensionKey: extensionKey,
183
+ onLinkEditClick: onLinkEditClick,
184
+ intl: intl
185
+ });
186
+ };
187
+ var EditToolbarButtonWithDatasourceId = function EditToolbarButtonWithDatasourceId(props) {
188
+ var currentAppearance = props.currentAppearance,
189
+ editorAnalyticsApi = props.editorAnalyticsApi,
190
+ editorView = props.editorView,
191
+ intl = props.intl,
192
+ onLinkEditClick = props.onLinkEditClick,
193
+ datasourceId = props.datasourceId,
194
+ node = props.node;
195
+ var fetchData = useMemo(function () {
196
+ try {
197
+ var _attrs$datasource$vie;
198
+ var attrs = node.attrs;
199
+ var parameters = attrs.datasource.parameters;
200
+ var visibleColumnKeys = (_attrs$datasource$vie = attrs.datasource.views[0]) === null || _attrs$datasource$vie === void 0 || (_attrs$datasource$vie = _attrs$datasource$vie.properties) === null || _attrs$datasource$vie === void 0 ? void 0 : _attrs$datasource$vie.columns.map(function (c) {
201
+ return c.key;
202
+ });
203
+ return {
204
+ parameters: parameters,
205
+ visibleColumnKeys: visibleColumnKeys
206
+ };
207
+ } catch (e) {
208
+ // eslint-disable-next-line no-console
209
+ console.error(e);
210
+ }
211
+ }, [node.attrs]);
212
+ var _useFetchDatasourceDa = useFetchDatasourceDataInfo({
213
+ datasourceId: datasourceId,
214
+ parameters: fetchData === null || fetchData === void 0 ? void 0 : fetchData.parameters,
215
+ visibleColumnKeys: fetchData === null || fetchData === void 0 ? void 0 : fetchData.visibleColumnKeys
216
+ }),
217
+ extensionKey = _useFetchDatasourceDa.extensionKey;
218
+ var editVariant = useMemo(function () {
219
+ if (!datasourceId || !isDatasourceConfigEditable(datasourceId)) {
220
+ return 'none';
221
+ }
222
+ return 'edit-datasource';
223
+ }, [datasourceId]);
224
+ return jsx(EditToolbarButtonPresentation, {
225
+ datasourceId: datasourceId,
226
+ currentAppearance: currentAppearance,
227
+ editorAnalyticsApi: editorAnalyticsApi,
228
+ editVariant: editVariant,
229
+ editorView: editorView,
230
+ extensionKey: extensionKey,
231
+ onLinkEditClick: onLinkEditClick,
232
+ intl: intl
233
+ });
234
+ };
147
235
  export var EditToolbarButton = function EditToolbarButton(props) {
148
236
  var currentAppearance = props.currentAppearance,
149
237
  datasourceId = props.datasourceId,
@@ -154,6 +242,30 @@ export var EditToolbarButton = function EditToolbarButton(props) {
154
242
  url = props.url;
155
243
  return jsx(CardContextProvider, null, function (_ref) {
156
244
  var cardContext = _ref.cardContext;
245
+ if (fg('enable_datasource_nourl_edit_dropdown_datafetch')) {
246
+ if (props.url) {
247
+ return jsx(EditToolbarButtonWithUrl, {
248
+ url: props.url,
249
+ intl: intl,
250
+ editorAnalyticsApi: editorAnalyticsApi,
251
+ editorView: editorView,
252
+ cardContext: cardContext,
253
+ onLinkEditClick: onLinkEditClick,
254
+ currentAppearance: currentAppearance
255
+ });
256
+ }
257
+ if (props.datasourceId && props.node) {
258
+ return jsx(EditToolbarButtonWithDatasourceId, {
259
+ datasourceId: props.datasourceId,
260
+ node: props.node,
261
+ intl: intl,
262
+ editorAnalyticsApi: editorAnalyticsApi,
263
+ editorView: editorView,
264
+ onLinkEditClick: onLinkEditClick,
265
+ currentAppearance: currentAppearance
266
+ });
267
+ }
268
+ }
157
269
  return jsx(EditToolbarButtonWithCardContext, {
158
270
  datasourceId: datasourceId,
159
271
  url: url,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,67 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ /** @jsx jsx */
5
+ import { useEffect, useState } from 'react';
6
+ import { DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE, useDatasourceClientExtension } from '@atlaskit/link-client-extension';
7
+ export var useFetchDatasourceDataInfo = function useFetchDatasourceDataInfo(_ref) {
8
+ var datasourceId = _ref.datasourceId,
9
+ parameters = _ref.parameters,
10
+ visibleColumnKeys = _ref.visibleColumnKeys;
11
+ var _useState = useState(undefined),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ extensionKey = _useState2[0],
14
+ setExtensionKey = _useState2[1];
15
+ var _useDatasourceClientE = useDatasourceClientExtension(),
16
+ getDatasourceData = _useDatasourceClientE.getDatasourceData;
17
+ useEffect(function () {
18
+ var fetchDatasource = /*#__PURE__*/function () {
19
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
20
+ var datasourceDataRequest, _yield$getDatasourceD, meta;
21
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
22
+ while (1) switch (_context.prev = _context.next) {
23
+ case 0:
24
+ _context.prev = 0;
25
+ if (!(!datasourceId || !parameters || !visibleColumnKeys)) {
26
+ _context.next = 3;
27
+ break;
28
+ }
29
+ return _context.abrupt("return");
30
+ case 3:
31
+ datasourceDataRequest = {
32
+ parameters: parameters,
33
+ pageSize: DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE,
34
+ pageCursor: undefined,
35
+ fields: visibleColumnKeys,
36
+ includeSchema: true
37
+ };
38
+ _context.next = 6;
39
+ return getDatasourceData(datasourceId, datasourceDataRequest, false);
40
+ case 6:
41
+ _yield$getDatasourceD = _context.sent;
42
+ meta = _yield$getDatasourceD.meta;
43
+ setExtensionKey(meta.extensionKey);
44
+ _context.next = 15;
45
+ break;
46
+ case 11:
47
+ _context.prev = 11;
48
+ _context.t0 = _context["catch"](0);
49
+ // eslint-disable-next-line no-console
50
+ console.error(_context.t0);
51
+ setExtensionKey(undefined);
52
+ case 15:
53
+ case "end":
54
+ return _context.stop();
55
+ }
56
+ }, _callee, null, [[0, 11]]);
57
+ }));
58
+ return function fetchDatasource() {
59
+ return _ref2.apply(this, arguments);
60
+ };
61
+ }();
62
+ void fetchDatasource();
63
+ }, [getDatasourceData, visibleColumnKeys, parameters, datasourceId]);
64
+ return {
65
+ extensionKey: extensionKey
66
+ };
67
+ };
@@ -22,8 +22,11 @@ export declare class BlockCardComponent extends React.PureComponent<SmartCardPro
22
22
  }
23
23
  export type BlockCardNodeViewProps = Pick<SmartCardProps, 'platform' | 'actionOptions' | 'showServerActions' | 'pluginInjectionApi' | 'onClickCallback'>;
24
24
  export declare class BlockCard extends ReactNodeView<BlockCardNodeViewProps> {
25
+ unsubscribe: (() => void) | undefined;
25
26
  createDomRef(): HTMLElement;
27
+ private updateContentEditable;
26
28
  validUpdate(currentNode: Node, newNode: Node): boolean;
27
29
  update(node: Node, decorations: ReadonlyArray<Decoration>, _innerDecorations?: DecorationSource): boolean;
28
30
  render(): JSX.Element;
31
+ destroy(): void;
29
32
  }
@@ -40,7 +40,10 @@ export declare class EmbedCardComponent extends React.PureComponent<SmartCardPro
40
40
  }
41
41
  export type EmbedCardNodeViewProps = Pick<SmartCardProps, 'eventDispatcher' | 'allowResizing' | 'platform' | 'fullWidthMode' | 'dispatchAnalyticsEvent' | 'pluginInjectionApi' | 'actionOptions' | 'showServerActions' | 'onClickCallback'>;
42
42
  export declare class EmbedCard extends ReactNodeView<EmbedCardNodeViewProps> {
43
+ unsubscribe: (() => void) | undefined;
43
44
  viewShouldUpdate(nextNode: PMNode): boolean;
44
45
  createDomRef(): HTMLElement;
46
+ private updateContentEditable;
45
47
  render(): JSX.Element;
48
+ destroy(): void;
46
49
  }
@@ -0,0 +1,9 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { EditDatasourceToolbarButtonWithCommonProps, EditVariant } from './types';
3
+ interface EditToolbarPresentationProps extends EditDatasourceToolbarButtonWithCommonProps {
4
+ extensionKey?: string;
5
+ datasourceId?: string;
6
+ editVariant: EditVariant;
7
+ }
8
+ declare const EditToolbarButtonPresentation: ({ datasourceId, currentAppearance, editorAnalyticsApi, editVariant, editorView, extensionKey, onLinkEditClick, intl, }: EditToolbarPresentationProps) => jsx.JSX.Element | null;
9
+ export default EditToolbarButtonPresentation;
@@ -0,0 +1,3 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { EditDatasourceToolbarButtonProps } from './types';
3
+ export declare const EditToolbarButton: (props: EditDatasourceToolbarButtonProps) => jsx.JSX.Element;
@@ -0,0 +1,29 @@
1
+ import { type IntlShape } from 'react-intl-next';
2
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
+ import type { Command } from '@atlaskit/editor-common/types';
4
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
5
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
+ import type { CardContext } from '@atlaskit/link-provider';
7
+ import { type CardType } from '../../types';
8
+ export type EditVariant = 'none' | 'edit-link' | 'edit-datasource' | 'edit-dropdown';
9
+ export interface EditDatasourceToolbarButtonWithCommonProps {
10
+ intl: IntlShape;
11
+ onLinkEditClick: Command;
12
+ editorAnalyticsApi?: EditorAnalyticsAPI;
13
+ editorView?: EditorView;
14
+ currentAppearance?: CardType;
15
+ }
16
+ export interface EditDatasourceToolbarButtonWithUrlProps extends EditDatasourceToolbarButtonWithCommonProps {
17
+ cardContext?: CardContext;
18
+ url: string;
19
+ }
20
+ export interface EditDatasourceToolbarButtonWithDatasourceIdProps extends EditDatasourceToolbarButtonWithCommonProps {
21
+ datasourceId: string;
22
+ node: Node;
23
+ }
24
+ export type EditDatasourceToolbarButtonProps = EditDatasourceToolbarButtonWithCommonProps & {
25
+ cardContext?: CardContext;
26
+ url?: string;
27
+ datasourceId?: string;
28
+ node?: Node;
29
+ };
@@ -0,0 +1,10 @@
1
+ import type { JiraIssueDatasourceParameters } from '@atlaskit/link-datasource';
2
+ import type { DatasourceParameters } from '@atlaskit/linking-types';
3
+ export interface useFetchDatasourceDataInfoProps {
4
+ datasourceId: string;
5
+ parameters?: DatasourceParameters | JiraIssueDatasourceParameters;
6
+ visibleColumnKeys?: string[];
7
+ }
8
+ export declare const useFetchDatasourceDataInfo: ({ datasourceId, parameters, visibleColumnKeys, }: useFetchDatasourceDataInfoProps) => {
9
+ extensionKey: string | undefined;
10
+ };
@@ -22,8 +22,11 @@ export declare class BlockCardComponent extends React.PureComponent<SmartCardPro
22
22
  }
23
23
  export type BlockCardNodeViewProps = Pick<SmartCardProps, 'platform' | 'actionOptions' | 'showServerActions' | 'pluginInjectionApi' | 'onClickCallback'>;
24
24
  export declare class BlockCard extends ReactNodeView<BlockCardNodeViewProps> {
25
+ unsubscribe: (() => void) | undefined;
25
26
  createDomRef(): HTMLElement;
27
+ private updateContentEditable;
26
28
  validUpdate(currentNode: Node, newNode: Node): boolean;
27
29
  update(node: Node, decorations: ReadonlyArray<Decoration>, _innerDecorations?: DecorationSource): boolean;
28
30
  render(): JSX.Element;
31
+ destroy(): void;
29
32
  }
@@ -40,7 +40,10 @@ export declare class EmbedCardComponent extends React.PureComponent<SmartCardPro
40
40
  }
41
41
  export type EmbedCardNodeViewProps = Pick<SmartCardProps, 'eventDispatcher' | 'allowResizing' | 'platform' | 'fullWidthMode' | 'dispatchAnalyticsEvent' | 'pluginInjectionApi' | 'actionOptions' | 'showServerActions' | 'onClickCallback'>;
42
42
  export declare class EmbedCard extends ReactNodeView<EmbedCardNodeViewProps> {
43
+ unsubscribe: (() => void) | undefined;
43
44
  viewShouldUpdate(nextNode: PMNode): boolean;
44
45
  createDomRef(): HTMLElement;
46
+ private updateContentEditable;
45
47
  render(): JSX.Element;
48
+ destroy(): void;
46
49
  }
@@ -0,0 +1,9 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { EditDatasourceToolbarButtonWithCommonProps, EditVariant } from './types';
3
+ interface EditToolbarPresentationProps extends EditDatasourceToolbarButtonWithCommonProps {
4
+ extensionKey?: string;
5
+ datasourceId?: string;
6
+ editVariant: EditVariant;
7
+ }
8
+ declare const EditToolbarButtonPresentation: ({ datasourceId, currentAppearance, editorAnalyticsApi, editVariant, editorView, extensionKey, onLinkEditClick, intl, }: EditToolbarPresentationProps) => jsx.JSX.Element | null;
9
+ export default EditToolbarButtonPresentation;
@@ -0,0 +1,3 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { EditDatasourceToolbarButtonProps } from './types';
3
+ export declare const EditToolbarButton: (props: EditDatasourceToolbarButtonProps) => jsx.JSX.Element;