@atlaskit/editor-plugin-card 1.14.4 → 1.15.0

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 (61) hide show
  1. package/.eslintrc.js +12 -12
  2. package/CHANGELOG.md +692 -681
  3. package/LICENSE.md +6 -8
  4. package/dist/cjs/nodeviews/datasource.js +1 -0
  5. package/dist/cjs/nodeviews/inlineCardWithAwareness.js +4 -1
  6. package/dist/cjs/pm-plugins/doc.js +21 -1
  7. package/dist/cjs/toolbar.js +36 -6
  8. package/dist/cjs/ui/AwarenessWrapper/index.js +20 -18
  9. package/dist/cjs/ui/DatasourceModal/index.js +4 -5
  10. package/dist/cjs/ui/EditDatasourceButton.js +5 -26
  11. package/dist/cjs/ui/EditToolbarButton.js +139 -0
  12. package/dist/cjs/ui/InlineCardOverlay/index.js +9 -3
  13. package/dist/cjs/ui/{NewInlineCardOverlay → LeftIconOverlay}/index.js +60 -101
  14. package/dist/cjs/ui/ResizableEmbedCard.js +3 -0
  15. package/dist/cjs/utils.js +4 -1
  16. package/dist/es2019/nodeviews/datasource.js +1 -0
  17. package/dist/es2019/nodeviews/inlineCardWithAwareness.js +4 -1
  18. package/dist/es2019/pm-plugins/doc.js +22 -2
  19. package/dist/es2019/toolbar.js +33 -7
  20. package/dist/es2019/ui/AwarenessWrapper/index.js +20 -18
  21. package/dist/es2019/ui/DatasourceModal/index.js +4 -5
  22. package/dist/es2019/ui/EditDatasourceButton.js +1 -22
  23. package/dist/es2019/ui/EditToolbarButton.js +123 -0
  24. package/dist/es2019/ui/InlineCardOverlay/index.js +9 -3
  25. package/dist/es2019/ui/{NewInlineCardOverlay → LeftIconOverlay}/index.js +51 -94
  26. package/dist/es2019/ui/ResizableEmbedCard.js +4 -0
  27. package/dist/es2019/utils.js +3 -0
  28. package/dist/esm/nodeviews/datasource.js +1 -0
  29. package/dist/esm/nodeviews/inlineCardWithAwareness.js +4 -1
  30. package/dist/esm/pm-plugins/doc.js +22 -2
  31. package/dist/esm/toolbar.js +38 -8
  32. package/dist/esm/ui/AwarenessWrapper/index.js +20 -18
  33. package/dist/esm/ui/DatasourceModal/index.js +4 -5
  34. package/dist/esm/ui/EditDatasourceButton.js +1 -22
  35. package/dist/esm/ui/EditToolbarButton.js +131 -0
  36. package/dist/esm/ui/InlineCardOverlay/index.js +9 -3
  37. package/dist/esm/ui/{NewInlineCardOverlay → LeftIconOverlay}/index.js +62 -103
  38. package/dist/esm/ui/ResizableEmbedCard.js +3 -0
  39. package/dist/esm/utils.js +3 -0
  40. package/dist/types/pm-plugins/doc.d.ts +1 -0
  41. package/dist/types/ui/EditDatasourceButton.d.ts +0 -2
  42. package/dist/types/ui/EditToolbarButton.d.ts +15 -0
  43. package/dist/types/ui/EditorAnalyticsContext.d.ts +1 -1
  44. package/dist/types/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +1 -1
  45. package/dist/types/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +1 -1
  46. package/dist/types/ui/EditorSmartCardEvents.d.ts +1 -1
  47. package/dist/types/ui/LeftIconOverlay/index.d.ts +10 -0
  48. package/dist/types/utils.d.ts +2 -0
  49. package/dist/types-ts4.5/pm-plugins/doc.d.ts +1 -0
  50. package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +0 -2
  51. package/dist/types-ts4.5/ui/EditToolbarButton.d.ts +15 -0
  52. package/dist/types-ts4.5/ui/EditorAnalyticsContext.d.ts +1 -1
  53. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +1 -1
  54. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +1 -1
  55. package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +1 -1
  56. package/dist/types-ts4.5/ui/LeftIconOverlay/index.d.ts +10 -0
  57. package/dist/types-ts4.5/utils.d.ts +2 -0
  58. package/package.json +9 -6
  59. package/report.api.md +94 -96
  60. package/dist/types/ui/NewInlineCardOverlay/index.d.ts +0 -6
  61. package/dist/types-ts4.5/ui/NewInlineCardOverlay/index.d.ts +0 -6
package/LICENSE.md CHANGED
@@ -1,13 +1,11 @@
1
1
  Copyright 2023 Atlassian Pty Ltd
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
4
+ compliance with the License. You may obtain a copy of the License at
6
5
 
7
6
  http://www.apache.org/licenses/LICENSE-2.0
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is
9
+ distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10
+ implied. See the License for the specific language governing permissions and limitations under the
11
+ License.
@@ -281,6 +281,7 @@ var Datasource = exports.Datasource = /*#__PURE__*/function (_ReactNodeView) {
281
281
  url: attrs.url,
282
282
  datasourceId: attrs === null || attrs === void 0 || (_attrs$datasource = attrs.datasource) === null || _attrs$datasource === void 0 ? void 0 : _attrs$datasource.id
283
283
  }, (0, _react2.jsx)("div", {
284
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
284
285
  className: _styles.DATASOURCE_INNER_CONTAINER_CLASSNAME,
285
286
  style: {
286
287
  minWidth: this.isNodeNested ? '100%' : (0, _utils.calcBreakoutWidth)(attrs.layout || _linkingCommon.DATASOURCE_DEFAULT_LAYOUT, this.tableWidth)
@@ -130,7 +130,10 @@ var InlineCard = function InlineCard(_ref) {
130
130
  markMostRecentlyInsertedLink: markMostRecentlyInsertedLink,
131
131
  pluginInjectionApi: pluginInjectionApi,
132
132
  setOverlayHoveredStyles: setOverlayHoveredStyles
133
- }, innerCard) : /*#__PURE__*/_react.default.createElement("span", {
133
+ }, innerCard) :
134
+ /*#__PURE__*/
135
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
136
+ _react.default.createElement("span", {
134
137
  className: "card"
135
138
  }, innerCard);
136
139
  }, [cardContext, getPos, innerCard, isHovered, isInserted, isOverlayEnabled, isPulseEnabled, isResolvedViewRendered, isSelected, markMostRecentlyInsertedLink, pluginInjectionApi, setOverlayHoveredStyles, url]);
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.updateCardViaDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.getAttrsForAppearance = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
7
+ exports.updateCardViaDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.getAttrsForAppearance = exports.editDatasource = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
@@ -567,4 +567,24 @@ var updateDatasourceStash = function updateDatasourceStash(tr, selectedNode) {
567
567
  }
568
568
  }
569
569
  }
570
+ };
571
+ var editDatasource = exports.editDatasource = function editDatasource(datasourceId, _editorAnalyticsApi) {
572
+ return function (state, dispatch) {
573
+ var datasourceType = (0, _utils.getDatasourceType)(datasourceId);
574
+ if (dispatch && datasourceType) {
575
+ var tr = state.tr;
576
+ (0, _actions.showDatasourceModal)(datasourceType)(tr);
577
+ // editorAnalyticsApi?.attachAnalyticsEvent(
578
+ // buildEditLinkPayload(
579
+ // type as
580
+ // | ACTION_SUBJECT_ID.CARD_INLINE
581
+ // | ACTION_SUBJECT_ID.CARD_BLOCK
582
+ // | ACTION_SUBJECT_ID.EMBEDS,
583
+ // ),
584
+ // )(tr);
585
+ dispatch(tr);
586
+ return true;
587
+ }
588
+ return false;
589
+ };
570
590
  };
@@ -29,6 +29,7 @@ var _main = require("./pm-plugins/main");
29
29
  var _DatasourceAppearanceButton = require("./ui/DatasourceAppearanceButton");
30
30
  var _EditDatasourceButton = require("./ui/EditDatasourceButton");
31
31
  var _EditLinkToolbar = require("./ui/EditLinkToolbar");
32
+ var _EditToolbarButton = require("./ui/EditToolbarButton");
32
33
  var _LinkToolbarAppearance = require("./ui/LinkToolbarAppearance");
33
34
  var _ToolbarViewedEvent = require("./ui/ToolbarViewedEvent");
34
35
  var _utils3 = require("./utils");
@@ -225,7 +226,20 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
225
226
  return getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, node.attrs.datasource.id, state, cardOptions, currentAppearance, platform, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.card) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions);
226
227
  } else {
227
228
  var inlineCard = state.schema.nodes.inlineCard;
228
- var toolbarItems = [{
229
+ var toolbarItems = [(0, _utils3.isEditDropdownEnabled)(platform) && cardOptions.allowDatasource ? {
230
+ type: 'custom',
231
+ fallback: [],
232
+ render: function render(editorView) {
233
+ return /*#__PURE__*/_react.default.createElement(_EditToolbarButton.EditToolbarButton, {
234
+ key: "edit-toolbar-item",
235
+ url: url,
236
+ intl: intl,
237
+ editorAnalyticsApi: editorAnalyticsApi,
238
+ editorView: editorView,
239
+ onLinkEditClick: (0, _EditLinkToolbar.editLink)(editorAnalyticsApi)
240
+ });
241
+ }
242
+ } : {
229
243
  id: 'editor.link.edit',
230
244
  type: 'button',
231
245
  selected: false,
@@ -324,7 +338,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
324
338
  type: 'separator'
325
339
  }]));
326
340
  }
327
- var shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource;
341
+ var shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource && !(0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar');
328
342
  if (shouldShowDatasourceEditButton) {
329
343
  toolbarItems.unshift({
330
344
  type: 'custom',
@@ -384,7 +398,7 @@ var getSettingsButtonGroup = exports.getSettingsButtonGroup = function getSettin
384
398
  var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId, state, cardOptions, currentAppearance, platform, cardActions) {
385
399
  var _node$attrs3;
386
400
  var toolbarItems = [];
387
- if ((0, _utils3.isDatasourceConfigEditable)(datasourceId)) {
401
+ if ((0, _utils3.isDatasourceConfigEditable)(datasourceId) && !(0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar')) {
388
402
  toolbarItems.push({
389
403
  id: 'editor.edit.datasource',
390
404
  type: 'button',
@@ -392,12 +406,28 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
392
406
  metadata: metadata,
393
407
  className: 'datasource-edit',
394
408
  title: intl.formatMessage(_messages.linkToolbarMessages.editDatasource),
395
- onClick: (0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi),
409
+ onClick: (0, _doc.editDatasource)(datasourceId, editorAnalyticsApi),
396
410
  testId: 'datasource-edit-button'
397
411
  }, {
398
412
  type: 'separator'
399
413
  });
400
414
  }
415
+ var editDropdownWithSeparator = [{
416
+ type: 'custom',
417
+ fallback: [],
418
+ render: function render(editorView) {
419
+ return /*#__PURE__*/_react.default.createElement(_EditToolbarButton.EditToolbarButton, {
420
+ key: "edit-toolbar-item",
421
+ url: metadata.url,
422
+ intl: intl,
423
+ editorAnalyticsApi: editorAnalyticsApi,
424
+ editorView: editorView,
425
+ onLinkEditClick: (0, _EditLinkToolbar.editLink)(editorAnalyticsApi)
426
+ });
427
+ }
428
+ }, {
429
+ type: 'separator'
430
+ }];
401
431
  var canShowMainToolbar = function canShowMainToolbar() {
402
432
  // we do not show smart-link or the datasource icons when the node does not have a url to resolve
403
433
  if (!metadata.url) {
@@ -417,7 +447,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
417
447
  allowEmbeds = cardOptions.allowEmbeds,
418
448
  showUpgradeDiscoverability = cardOptions.showUpgradeDiscoverability;
419
449
  var url = metadata.url;
420
- toolbarItems.push({
450
+ toolbarItems.push.apply(toolbarItems, [{
421
451
  type: 'custom',
422
452
  fallback: [],
423
453
  render: function render(editorView) {
@@ -453,7 +483,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
453
483
  }
454
484
  }, {
455
485
  type: 'separator'
456
- });
486
+ }].concat((0, _toConsumableArray2.default)((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-edit-dropdown-toolbar') ? [].concat(editDropdownWithSeparator) : [])));
457
487
  }
458
488
  if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
459
489
  toolbarItems.push({
@@ -14,7 +14,7 @@ var _useLinkUpgradeDiscoverability = _interopRequireDefault(require("../../commo
14
14
  var _localStorage = require("../../common/local-storage");
15
15
  var _utils = require("../../utils");
16
16
  var _InlineCardOverlay = _interopRequireDefault(require("../InlineCardOverlay"));
17
- var _NewInlineCardOverlay = _interopRequireDefault(require("../NewInlineCardOverlay"));
17
+ var _LeftIconOverlay = _interopRequireDefault(require("../LeftIconOverlay"));
18
18
  var _Pulse = require("../Pulse");
19
19
  /** @jsx jsx */
20
20
 
@@ -81,7 +81,7 @@ var AwarenessWrapper = exports.AwarenessWrapper = function AwarenessWrapper(_ref
81
81
  var cardWithOverlay = (0, _react.useMemo)(function () {
82
82
  if (shouldShowLinkOverlay) {
83
83
  if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-links-in-live-pages')) {
84
- return (0, _react2.jsx)(_NewInlineCardOverlay.default, {
84
+ return (0, _react2.jsx)(_LeftIconOverlay.default, {
85
85
  isSelected: isSelected,
86
86
  isVisible: isResolvedViewRendered && (isInserted || isHovered || isSelected),
87
87
  onMouseEnter: function onMouseEnter() {
@@ -89,8 +89,7 @@ var AwarenessWrapper = exports.AwarenessWrapper = function AwarenessWrapper(_ref
89
89
  },
90
90
  onMouseLeave: function onMouseLeave() {
91
91
  return handleOverlayChange(false);
92
- },
93
- url: url
92
+ }
94
93
  }, children);
95
94
  }
96
95
  return (0, _react2.jsx)(_InlineCardOverlay.default, {
@@ -109,19 +108,22 @@ var AwarenessWrapper = exports.AwarenessWrapper = function AwarenessWrapper(_ref
109
108
  }, [shouldShowLinkOverlay, isSelected, isResolvedViewRendered, isInserted, isHovered, url, children, handleOverlayChange]);
110
109
  return (0, _react.useMemo)(function () {
111
110
  var _cardContext$value;
112
- return (0, _react2.jsx)("span", {
113
- css: shouldShowLinkPulse && loaderWrapperStyles,
114
- className: "card"
115
- }, (0, _react2.jsx)(_analyticsNext.AnalyticsContext, {
116
- data: {
117
- attributes: (0, _utils.getResolvedAttributesFromStore)(url, 'inline', cardContext === null || cardContext === void 0 || (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store)
118
- }
119
- }, (0, _react2.jsx)(_Pulse.DiscoveryPulse, {
120
- localStorageKey: _localStorage.LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
121
- localStorageKeyExpirationInMs: _localStorage.ONE_DAY_IN_MILLISECONDS,
122
- discoveryMode: "start",
123
- shouldShowPulse: isResolvedViewRendered && shouldShowLinkPulse,
124
- testId: "link-discovery-pulse"
125
- }, cardWithOverlay)));
111
+ return (
112
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
113
+ (0, _react2.jsx)("span", {
114
+ css: shouldShowLinkPulse && loaderWrapperStyles,
115
+ className: "card"
116
+ }, (0, _react2.jsx)(_analyticsNext.AnalyticsContext, {
117
+ data: {
118
+ attributes: (0, _utils.getResolvedAttributesFromStore)(url, 'inline', cardContext === null || cardContext === void 0 || (_cardContext$value = cardContext.value) === null || _cardContext$value === void 0 ? void 0 : _cardContext$value.store)
119
+ }
120
+ }, (0, _react2.jsx)(_Pulse.DiscoveryPulse, {
121
+ localStorageKey: _localStorage.LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK,
122
+ localStorageKeyExpirationInMs: _localStorage.ONE_DAY_IN_MILLISECONDS,
123
+ discoveryMode: "start",
124
+ shouldShowPulse: isResolvedViewRendered && shouldShowLinkPulse,
125
+ testId: "link-discovery-pulse"
126
+ }, cardWithOverlay)))
127
+ );
126
128
  }, [shouldShowLinkPulse, url, cardContext === null || cardContext === void 0 || (_cardContext$value2 = cardContext.value) === null || _cardContext$value2 === void 0 ? void 0 : _cardContext$value2.store, isResolvedViewRendered, cardWithOverlay]);
127
129
  };
@@ -34,7 +34,7 @@ var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
34
34
  var onClose = (0, _react.useCallback)(function () {
35
35
  dispatch((0, _actions.hideDatasourceModal)(transaction));
36
36
  }, [dispatch, transaction]);
37
- var onInsert = useOnInsert(view, existingNode);
37
+ var updateAdf = useUpdateAdf(view, existingNode);
38
38
  var isRegularCardNode = !!(existingNode && !(existingNode !== null && existingNode !== void 0 && (_existingNode$attrs = existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
39
39
  var _ref2 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.datasource) || {},
40
40
  _ref2$id = _ref2.id,
@@ -67,10 +67,10 @@ var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
67
67
  columnCustomSizes: columnCustomSizes,
68
68
  wrappedColumnKeys: wrappedColumnKeys,
69
69
  onCancel: onClose,
70
- onInsert: onInsert
70
+ onInsert: updateAdf
71
71
  });
72
72
  };
73
- var useOnInsert = function useOnInsert(view, existingNode) {
73
+ var useUpdateAdf = function useUpdateAdf(view, existingNode) {
74
74
  return (0, _react.useCallback)(function (newAdf, analyticEvent) {
75
75
  if (analyticEvent) {
76
76
  analyticEvent.update(function (payload) {
@@ -121,10 +121,9 @@ var resolveColumnsConfig = function resolveColumnsConfig(views) {
121
121
  tableView = _views[0];
122
122
  var visibleColumnKeys = [];
123
123
  var wrappedColumnKeys = [];
124
- var columnCustomSizes;
124
+ var columnCustomSizes = {};
125
125
  var columns = tableView === null || tableView === void 0 || (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns;
126
126
  if (columns) {
127
- columnCustomSizes = {};
128
127
  var _iterator = _createForOfIteratorHelper(columns),
129
128
  _step;
130
129
  try {
@@ -3,14 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.editDatasource = exports.EditDatasourceButton = void 0;
6
+ exports.EditDatasourceButton = void 0;
7
7
  var _react = require("@emotion/react");
8
8
  var _messages = require("@atlaskit/editor-common/messages");
9
9
  var _ui = require("@atlaskit/editor-common/ui");
10
- var _utils = require("@atlaskit/editor-common/utils");
11
10
  var _primitives = require("@atlaskit/primitives");
12
- var _actions = require("../pm-plugins/actions");
13
- var _utils2 = require("../utils");
11
+ var _doc = require("../pm-plugins/doc");
12
+ var _utils = require("../utils");
14
13
  var _CardContextProvider = require("./CardContextProvider");
15
14
  var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
16
15
  /** @jsx jsx */
@@ -34,7 +33,7 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
34
33
  cardContext: cardContext
35
34
  }),
36
35
  datasourceId = _useFetchDatasourceIn.datasourceId;
37
- if (!datasourceId || !(0, _utils2.isDatasourceConfigEditable)(datasourceId)) {
36
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
38
37
  return null;
39
38
  }
40
39
  if (url) {
@@ -56,7 +55,7 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
56
55
  icon: (0, _react.jsx)(_ui.SmallerEditIcon, null),
57
56
  selected: false,
58
57
  onClick: function onClick() {
59
- return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
58
+ return dispatchCommand((0, _doc.editDatasource)(datasourceId, editorAnalyticsApi));
60
59
  },
61
60
  testId: 'card-edit-datasource-button'
62
61
  }), (0, _react.jsx)(_ui.FloatingToolbarSeparator, null));
@@ -78,24 +77,4 @@ var EditDatasourceButton = exports.EditDatasourceButton = function EditDatasourc
78
77
  cardContext: cardContext
79
78
  });
80
79
  });
81
- };
82
- var editDatasource = exports.editDatasource = function editDatasource(datasourceId, editorAnalyticsApi) {
83
- return function (state, dispatch) {
84
- var datasourceType = (0, _utils.getDatasourceType)(datasourceId);
85
- if (dispatch && datasourceType) {
86
- var tr = state.tr;
87
- (0, _actions.showDatasourceModal)(datasourceType)(tr);
88
- // editorAnalyticsApi?.attachAnalyticsEvent(
89
- // buildEditLinkPayload(
90
- // type as
91
- // | ACTION_SUBJECT_ID.CARD_INLINE
92
- // | ACTION_SUBJECT_ID.CARD_BLOCK
93
- // | ACTION_SUBJECT_ID.EMBEDS,
94
- // ),
95
- // )(tr);
96
- dispatch(tr);
97
- return true;
98
- }
99
- return false;
100
- };
101
80
  };
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.EditToolbarButton = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
+ var _reactIntlNext = require("react-intl-next");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
+ var _ui = require("@atlaskit/editor-common/ui");
14
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
15
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
16
+ var _menu = require("@atlaskit/menu");
17
+ var _primitives = require("@atlaskit/primitives");
18
+ var _doc = require("../pm-plugins/doc");
19
+ var _utils = require("../utils");
20
+ var _CardContextProvider = require("./CardContextProvider");
21
+ var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
22
+ /** @jsx jsx */
23
+
24
+ var dropdownExpandContainer = (0, _react2.css)({
25
+ margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
26
+ });
27
+ var EditButtonWithCardContext = function EditButtonWithCardContext(_ref) {
28
+ var cardContext = _ref.cardContext,
29
+ intl = _ref.intl,
30
+ editorAnalyticsApi = _ref.editorAnalyticsApi,
31
+ url = _ref.url,
32
+ editorView = _ref.editorView,
33
+ onLinkEditClick = _ref.onLinkEditClick;
34
+ var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
35
+ isRegularCardNode: true,
36
+ url: url,
37
+ cardContext: cardContext
38
+ }),
39
+ datasourceId = _useFetchDatasourceIn.datasourceId;
40
+ var _useState = (0, _react.useState)(false),
41
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
+ isOpen = _useState2[0],
43
+ setIsOpen = _useState2[1];
44
+ var containerRef = (0, _react.useRef)();
45
+ var toggleOpen = function toggleOpen() {
46
+ return setIsOpen(function (open) {
47
+ return !open;
48
+ });
49
+ };
50
+ var onClose = function onClose() {
51
+ return setIsOpen(false);
52
+ };
53
+ var dispatchCommand = (0, _react.useCallback)(function (fn) {
54
+ if (editorView) {
55
+ fn === null || fn === void 0 || fn(editorView.state, editorView.dispatch);
56
+ if (!editorView.hasFocus()) {
57
+ editorView.focus();
58
+ }
59
+ }
60
+ }, [editorView]);
61
+ var onEditLink = (0, _react.useCallback)(function () {
62
+ dispatchCommand(onLinkEditClick);
63
+ }, [dispatchCommand, onLinkEditClick]);
64
+ var shouldFallbackToEditButton = (0, _react.useMemo)(function () {
65
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
66
+ return true;
67
+ }
68
+ if (url) {
69
+ var _cardContext$store, _urlState$error;
70
+ var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
71
+ if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
72
+ return true;
73
+ }
74
+ }
75
+ return false;
76
+ }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
77
+ var onEditDatasource = (0, _react.useCallback)(function () {
78
+ if (datasourceId) {
79
+ dispatchCommand((0, _doc.editDatasource)(datasourceId, editorAnalyticsApi));
80
+ }
81
+ }, [dispatchCommand, datasourceId, editorAnalyticsApi]);
82
+ if (shouldFallbackToEditButton) {
83
+ return (0, _react2.jsx)(_ui.FloatingToolbarButton, {
84
+ testId: "edit-link",
85
+ onClick: onEditLink
86
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.linkToolbarMessages.editLink));
87
+ }
88
+ var trigger = (0, _react2.jsx)(_ui.FloatingToolbarButton, {
89
+ testId: "edit-dropdown-trigger",
90
+ iconAfter: (0, _react2.jsx)("span", {
91
+ css: dropdownExpandContainer
92
+ }, (0, _react2.jsx)(_chevronDown.default, {
93
+ label: intl.formatMessage(_messages.cardMessages.editDropdownTriggerTitle)
94
+ })),
95
+ onClick: toggleOpen,
96
+ selected: isOpen,
97
+ disabled: false,
98
+ ariaHasPopup: true
99
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownTriggerTitle));
100
+ return (0, _react2.jsx)(_primitives.Flex, {
101
+ ref: containerRef
102
+ }, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
103
+ mountTo: containerRef.current,
104
+ isOpen: isOpen,
105
+ handleClickOutside: onClose,
106
+ handleEscapeKeydown: onClose,
107
+ trigger: trigger,
108
+ scrollableElement: containerRef.current,
109
+ arrowKeyNavigationProviderOptions: {
110
+ type: _uiMenu.ArrowKeyNavigationType.MENU
111
+ }
112
+ }, (0, _react2.jsx)(_menu.ButtonItem, {
113
+ key: "edit.link",
114
+ onClick: onEditLink,
115
+ testId: "edit-dropdown-edit-link-item"
116
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditLinkTitle)), (0, _react2.jsx)(_menu.ButtonItem, {
117
+ key: "edit.datasource",
118
+ onClick: onEditDatasource,
119
+ testId: "edit-dropdown-edit-datasource-item"
120
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditDatasourceTitle))));
121
+ };
122
+ var EditToolbarButton = exports.EditToolbarButton = function EditToolbarButton(_ref2) {
123
+ var intl = _ref2.intl,
124
+ editorAnalyticsApi = _ref2.editorAnalyticsApi,
125
+ url = _ref2.url,
126
+ editorView = _ref2.editorView,
127
+ onLinkEditClick = _ref2.onLinkEditClick;
128
+ return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref3) {
129
+ var cardContext = _ref3.cardContext;
130
+ return (0, _react2.jsx)(EditButtonWithCardContext, {
131
+ url: url,
132
+ intl: intl,
133
+ editorAnalyticsApi: editorAnalyticsApi,
134
+ editorView: editorView,
135
+ cardContext: cardContext,
136
+ onLinkEditClick: onLinkEditClick
137
+ });
138
+ });
139
+ };
@@ -241,7 +241,9 @@ var InlineCardOverlay = function InlineCardOverlay(_ref) {
241
241
  }, (0, _react2.jsx)("span", {
242
242
  css: overflowingContainerStyles
243
243
  }, (0, _react2.jsx)("span", {
244
- css: iconAndLabelStyles,
244
+ css: iconAndLabelStyles
245
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
246
+ ,
245
247
  className: ICON_AND_LABEL_CLASSNAME
246
248
  }, (0, _react2.jsx)("span", {
247
249
  css: iconStyles
@@ -250,11 +252,15 @@ var InlineCardOverlay = function InlineCardOverlay(_ref) {
250
252
  size: iconSize.current,
251
253
  testId: "".concat(testId, "-icon")
252
254
  })), showLabel && (0, _react2.jsx)("span", {
253
- css: labelStyles,
255
+ css: labelStyles
256
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
257
+ ,
254
258
  className: OVERLAY_LABEL_CLASSNAME,
255
259
  "data-testid": "".concat(testId, "-label")
256
260
  }, label)), (0, _react2.jsx)("span", {
257
- css: gradientStyles,
261
+ css: gradientStyles
262
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
263
+ ,
258
264
  className: OVERLAY_GRADIENT_CLASSNAME,
259
265
  "data-testid": "".concat(testId, "-gradient")
260
266
  })))));