@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 2.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#121784](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121784)
8
+ [`a6117088af0ad`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a6117088af0ad) -
9
+ The edit toolbar button is retrieving metadata from /data endpoint for analytics metadata.
10
+
11
+ ## 2.6.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#120605](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/120605)
16
+ [`b2b0cfe2fb0c4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b2b0cfe2fb0c4) -
17
+ Removed unused code in leftIconOverlay
18
+ - [#121395](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121395)
19
+ [`caceefb824256`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/caceefb824256) -
20
+ Removing contenteditable and CCFE workaround for smart links in live pages
21
+ - Updated dependencies
22
+
3
23
  ## 2.6.1
4
24
 
5
25
  ### Patch Changes
@@ -132,30 +132,48 @@ var BlockCard = exports.BlockCard = /*#__PURE__*/function (_ReactNodeView) {
132
132
  (0, _inherits2.default)(BlockCard, _ReactNodeView);
133
133
  var _super2 = _createSuper(BlockCard);
134
134
  function BlockCard() {
135
+ var _this2;
135
136
  (0, _classCallCheck2.default)(this, BlockCard);
136
- return _super2.apply(this, arguments);
137
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
138
+ args[_key2] = arguments[_key2];
139
+ }
140
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
141
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "updateContentEditable", function (editorViewModeState, divElement) {
142
+ divElement.contentEditable = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? 'false' : 'true';
143
+ });
144
+ return _this2;
137
145
  }
138
146
  (0, _createClass2.default)(BlockCard, [{
139
147
  key: "createDomRef",
140
148
  value: function createDomRef() {
149
+ var _this3 = this;
141
150
  var domRef = document.createElement('div');
142
151
  if (this.reactComponentProps.platform !== 'mobile') {
143
152
  // workaround Chrome bug in https://product-fabric.atlassian.net/browse/ED-5379
144
153
  // see also: https://github.com/ProseMirror/prosemirror/issues/884
145
- domRef.contentEditable = 'true';
154
+ if ((0, _platformFeatureFlags.fg)('linking-platform-contenteditable-false-live-view')) {
155
+ var _this$reactComponentP, _this$reactComponentP2;
156
+ 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) {
157
+ var nextSharedState = _ref2.nextSharedState;
158
+ return _this3.updateContentEditable(nextSharedState, domRef);
159
+ });
160
+ 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);
161
+ } else {
162
+ domRef.contentEditable = 'true';
163
+ }
146
164
  domRef.setAttribute('spellcheck', 'false');
147
165
  }
148
166
  return domRef;
149
167
  }
150
-
168
+ }, {
169
+ key: "validUpdate",
170
+ value:
151
171
  // Need this function to check if the datasource attribute was added or not to a blockCard.
152
172
  // If so, we return false so we can get the node to re-render properly as a datasource node instead.
153
173
  // Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
154
- }, {
155
- key: "validUpdate",
156
- value: function validUpdate(currentNode, newNode) {
174
+ function validUpdate(currentNode, newNode) {
157
175
  var _currentNode$attrs, _newNode$attrs;
158
- if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards')) {
176
+ if ((0, _platformFeatureFlags.fg)('platform.linking-platform.editor-datasource-typeguards')) {
159
177
  var _isCurrentNodeBlockCard = !(0, _utils2.isDatasourceNode)(currentNode);
160
178
  var _isNewNodeDatasource = (0, _utils2.isDatasourceNode)(newNode);
161
179
 
@@ -176,12 +194,12 @@ var BlockCard = exports.BlockCard = /*#__PURE__*/function (_ReactNodeView) {
176
194
  }, {
177
195
  key: "render",
178
196
  value: function render() {
179
- var _this$reactComponentP = this.reactComponentProps,
180
- platform = _this$reactComponentP.platform,
181
- actionOptions = _this$reactComponentP.actionOptions,
182
- showServerActions = _this$reactComponentP.showServerActions,
183
- pluginInjectionApi = _this$reactComponentP.pluginInjectionApi,
184
- onClickCallback = _this$reactComponentP.onClickCallback;
197
+ var _this$reactComponentP3 = this.reactComponentProps,
198
+ platform = _this$reactComponentP3.platform,
199
+ actionOptions = _this$reactComponentP3.actionOptions,
200
+ showServerActions = _this$reactComponentP3.showServerActions,
201
+ pluginInjectionApi = _this$reactComponentP3.pluginInjectionApi,
202
+ onClickCallback = _this$reactComponentP3.onClickCallback;
185
203
  return /*#__PURE__*/_react.default.createElement(WrappedBlockCard, {
186
204
  node: this.node,
187
205
  view: this.view,
@@ -193,6 +211,12 @@ var BlockCard = exports.BlockCard = /*#__PURE__*/function (_ReactNodeView) {
193
211
  onClickCallback: onClickCallback
194
212
  });
195
213
  }
214
+ }, {
215
+ key: "destroy",
216
+ value: function destroy() {
217
+ var _this$unsubscribe;
218
+ (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
219
+ }
196
220
  }]);
197
221
  return BlockCard;
198
222
  }(_reactNodeView.default);
@@ -23,6 +23,7 @@ var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/rea
23
23
  var _ui = require("@atlaskit/editor-common/ui");
24
24
  var _utils = require("@atlaskit/editor-common/utils");
25
25
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
26
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
26
27
  var _smartCard = require("@atlaskit/smart-card");
27
28
  var _actions = require("../pm-plugins/actions");
28
29
  var _ResizableEmbedCard = _interopRequireDefault(require("../ui/ResizableEmbedCard"));
@@ -350,8 +351,16 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
350
351
  (0, _inherits2.default)(EmbedCard, _ReactNodeView);
351
352
  var _super2 = _createSuper(EmbedCard);
352
353
  function EmbedCard() {
354
+ var _this2;
353
355
  (0, _classCallCheck2.default)(this, EmbedCard);
354
- return _super2.apply(this, arguments);
356
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
357
+ args[_key2] = arguments[_key2];
358
+ }
359
+ _this2 = _super2.call.apply(_super2, [this].concat(args));
360
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "updateContentEditable", function (editorViewModeState, divElement) {
361
+ divElement.contentEditable = (editorViewModeState === null || editorViewModeState === void 0 ? void 0 : editorViewModeState.mode) === 'view' ? 'false' : 'true';
362
+ });
363
+ return _this2;
355
364
  }
356
365
  (0, _createClass2.default)(EmbedCard, [{
357
366
  key: "viewShouldUpdate",
@@ -364,10 +373,20 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
364
373
  }, {
365
374
  key: "createDomRef",
366
375
  value: function createDomRef() {
376
+ var _this3 = this;
367
377
  var domRef = document.createElement('div');
368
378
  if (this.reactComponentProps.platform !== 'mobile') {
369
379
  // 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
370
- domRef.contentEditable = 'true';
380
+ if ((0, _platformFeatureFlags.fg)('linking-platform-contenteditable-false-live-view')) {
381
+ var _this$reactComponentP, _this$reactComponentP2;
382
+ 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) {
383
+ var nextSharedState = _ref3.nextSharedState;
384
+ return _this3.updateContentEditable(nextSharedState, domRef);
385
+ });
386
+ 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);
387
+ } else {
388
+ domRef.contentEditable = 'true';
389
+ }
371
390
  domRef.setAttribute('spellcheck', 'false');
372
391
  }
373
392
  return domRef;
@@ -375,14 +394,14 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
375
394
  }, {
376
395
  key: "render",
377
396
  value: function render() {
378
- var _this$reactComponentP = this.reactComponentProps,
379
- eventDispatcher = _this$reactComponentP.eventDispatcher,
380
- allowResizing = _this$reactComponentP.allowResizing,
381
- platform = _this$reactComponentP.platform,
382
- fullWidthMode = _this$reactComponentP.fullWidthMode,
383
- dispatchAnalyticsEvent = _this$reactComponentP.dispatchAnalyticsEvent,
384
- pluginInjectionApi = _this$reactComponentP.pluginInjectionApi,
385
- onClickCallback = _this$reactComponentP.onClickCallback;
397
+ var _this$reactComponentP3 = this.reactComponentProps,
398
+ eventDispatcher = _this$reactComponentP3.eventDispatcher,
399
+ allowResizing = _this$reactComponentP3.allowResizing,
400
+ platform = _this$reactComponentP3.platform,
401
+ fullWidthMode = _this$reactComponentP3.fullWidthMode,
402
+ dispatchAnalyticsEvent = _this$reactComponentP3.dispatchAnalyticsEvent,
403
+ pluginInjectionApi = _this$reactComponentP3.pluginInjectionApi,
404
+ onClickCallback = _this$reactComponentP3.onClickCallback;
386
405
  return /*#__PURE__*/_react.default.createElement(WrappedBlockCard, {
387
406
  node: this.node,
388
407
  view: this.view,
@@ -396,6 +415,12 @@ var EmbedCard = exports.EmbedCard = /*#__PURE__*/function (_ReactNodeView) {
396
415
  onClickCallback: onClickCallback
397
416
  });
398
417
  }
418
+ }, {
419
+ key: "destroy",
420
+ value: function destroy() {
421
+ var _this$unsubscribe;
422
+ (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 || _this$unsubscribe.call(this);
423
+ }
399
424
  }]);
400
425
  return EmbedCard;
401
426
  }(_reactNodeView.default);
@@ -476,6 +476,7 @@ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl,
476
476
  render: function render(editorView) {
477
477
  return /*#__PURE__*/_react.default.createElement(_EditToolbarButton.EditToolbarButton, {
478
478
  datasourceId: datasourceId,
479
+ node: node,
479
480
  key: "edit-toolbar-item",
480
481
  url: metadata.url,
481
482
  intl: intl,
@@ -4,9 +4,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.EditToolbarButton = void 0;
7
+ exports.default = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
9
  var _react = require("react");
11
10
  var _react2 = require("@emotion/react");
12
11
  var _reactIntlNext = require("react-intl-next");
@@ -16,33 +15,24 @@ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
16
15
  var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
17
16
  var _menu = require("@atlaskit/menu");
18
17
  var _primitives = require("@atlaskit/primitives");
19
- var _EditDatasourceButton = require("../ui/EditDatasourceButton");
20
- var _utils = require("../utils");
21
- var _CardContextProvider = require("./CardContextProvider");
22
- var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
23
- var _excluded = ["extensionKey"];
18
+ var _utils = require("../../utils");
19
+ var _EditDatasourceButton = require("../EditDatasourceButton");
24
20
  /** @jsx jsx */
21
+
25
22
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
23
+
26
24
  var dropdownExpandContainer = (0, _react2.css)({
27
25
  margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
28
26
  });
29
- var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext(props) {
30
- var _response$datasourceI;
31
- var cardContext = props.cardContext,
32
- currentAppearance = props.currentAppearance,
33
- editorAnalyticsApi = props.editorAnalyticsApi,
34
- editorView = props.editorView,
35
- intl = props.intl,
36
- onLinkEditClick = props.onLinkEditClick,
37
- url = props.url;
38
- var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
39
- isRegularCardNode: true,
40
- url: url,
41
- cardContext: cardContext
42
- }),
43
- extensionKey = _useFetchDatasourceIn.extensionKey,
44
- response = (0, _objectWithoutProperties2.default)(_useFetchDatasourceIn, _excluded);
45
- var datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
27
+ var EditToolbarButtonPresentation = function EditToolbarButtonPresentation(_ref) {
28
+ var datasourceId = _ref.datasourceId,
29
+ currentAppearance = _ref.currentAppearance,
30
+ editorAnalyticsApi = _ref.editorAnalyticsApi,
31
+ editVariant = _ref.editVariant,
32
+ editorView = _ref.editorView,
33
+ extensionKey = _ref.extensionKey,
34
+ onLinkEditClick = _ref.onLinkEditClick,
35
+ intl = _ref.intl;
46
36
  var _useState = (0, _react.useState)(false),
47
37
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
48
38
  isOpen = _useState2[0],
@@ -62,25 +52,6 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
62
52
  (0, _utils.focusEditorView)(editorView);
63
53
  }
64
54
  }, [editorView, onLinkEditClick]);
65
- var editVariant = (0, _react.useMemo)(function () {
66
- var hasUrl = url !== null && url !== undefined;
67
- if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
68
- if (hasUrl) {
69
- return 'edit-link';
70
- }
71
- return 'none';
72
- }
73
- if (hasUrl) {
74
- var _cardContext$store, _urlState$error;
75
- var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
76
- if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
77
- return 'edit-link';
78
- }
79
- return 'edit-dropdown';
80
- } else {
81
- return 'edit-datasource';
82
- }
83
- }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
84
55
  var onEditDatasource = (0, _react.useCallback)(function () {
85
56
  if (editorView && datasourceId) {
86
57
  (0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
@@ -150,25 +121,4 @@ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext
150
121
  return null;
151
122
  }
152
123
  };
153
- var EditToolbarButton = exports.EditToolbarButton = function EditToolbarButton(props) {
154
- var currentAppearance = props.currentAppearance,
155
- datasourceId = props.datasourceId,
156
- editorAnalyticsApi = props.editorAnalyticsApi,
157
- editorView = props.editorView,
158
- intl = props.intl,
159
- onLinkEditClick = props.onLinkEditClick,
160
- url = props.url;
161
- return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref) {
162
- var cardContext = _ref.cardContext;
163
- return (0, _react2.jsx)(EditToolbarButtonWithCardContext, {
164
- datasourceId: datasourceId,
165
- url: url,
166
- intl: intl,
167
- editorAnalyticsApi: editorAnalyticsApi,
168
- editorView: editorView,
169
- cardContext: cardContext,
170
- onLinkEditClick: onLinkEditClick,
171
- currentAppearance: currentAppearance
172
- });
173
- });
174
- };
124
+ var _default = exports.default = EditToolbarButtonPresentation;
@@ -0,0 +1,286 @@
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 _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _react = require("react");
11
+ var _react2 = require("@emotion/react");
12
+ var _reactIntlNext = require("react-intl-next");
13
+ var _messages = require("@atlaskit/editor-common/messages");
14
+ var _ui = require("@atlaskit/editor-common/ui");
15
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
16
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
17
+ var _menu = require("@atlaskit/menu");
18
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
+ var _primitives = require("@atlaskit/primitives");
20
+ var _EditDatasourceButton = require("../../ui/EditDatasourceButton");
21
+ var _utils = require("../../utils");
22
+ var _CardContextProvider = require("../CardContextProvider");
23
+ var _useFetchDatasourceDataInfo = require("../useFetchDatasourceDataInfo");
24
+ var _useFetchDatasourceInfo = require("../useFetchDatasourceInfo");
25
+ var _EditToolbarButtonPresentation = _interopRequireDefault(require("./EditToolbarButtonPresentation"));
26
+ var _excluded = ["extensionKey"];
27
+ /** @jsx jsx */
28
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
29
+ var dropdownExpandContainer = (0, _react2.css)({
30
+ margin: "0px ".concat("var(--ds-space-negative-050, -4px)")
31
+ });
32
+ var EditToolbarButtonWithCardContext = function EditToolbarButtonWithCardContext(props) {
33
+ var _response$datasourceI;
34
+ var cardContext = props.cardContext,
35
+ currentAppearance = props.currentAppearance,
36
+ editorAnalyticsApi = props.editorAnalyticsApi,
37
+ editorView = props.editorView,
38
+ intl = props.intl,
39
+ onLinkEditClick = props.onLinkEditClick,
40
+ url = props.url;
41
+ var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
42
+ isRegularCardNode: true,
43
+ url: url,
44
+ cardContext: cardContext
45
+ }),
46
+ extensionKey = _useFetchDatasourceIn.extensionKey,
47
+ response = (0, _objectWithoutProperties2.default)(_useFetchDatasourceIn, _excluded);
48
+ var datasourceId = (_response$datasourceI = response.datasourceId) !== null && _response$datasourceI !== void 0 ? _response$datasourceI : props.datasourceId;
49
+ var _useState = (0, _react.useState)(false),
50
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
51
+ isOpen = _useState2[0],
52
+ setIsOpen = _useState2[1];
53
+ var containerRef = (0, _react.useRef)();
54
+ var toggleOpen = function toggleOpen() {
55
+ return setIsOpen(function (open) {
56
+ return !open;
57
+ });
58
+ };
59
+ var onClose = function onClose() {
60
+ return setIsOpen(false);
61
+ };
62
+ var onEditLink = (0, _react.useCallback)(function () {
63
+ if (editorView) {
64
+ onLinkEditClick(editorView.state, editorView.dispatch);
65
+ (0, _utils.focusEditorView)(editorView);
66
+ }
67
+ }, [editorView, onLinkEditClick]);
68
+ var editVariant = (0, _react.useMemo)(function () {
69
+ var hasUrl = url !== null && url !== undefined;
70
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
71
+ if (hasUrl) {
72
+ return 'edit-link';
73
+ }
74
+ return 'none';
75
+ }
76
+ if (hasUrl) {
77
+ var _cardContext$store, _urlState$error;
78
+ var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
79
+ if ((urlState === null || urlState === void 0 || (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
80
+ return 'edit-link';
81
+ }
82
+ return 'edit-dropdown';
83
+ } else {
84
+ return 'edit-datasource';
85
+ }
86
+ }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
87
+ var onEditDatasource = (0, _react.useCallback)(function () {
88
+ if (editorView && datasourceId) {
89
+ (0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi, currentAppearance, extensionKey)(editorView.state, editorView.dispatch);
90
+ (0, _utils.focusEditorView)(editorView);
91
+ }
92
+ }, [currentAppearance, datasourceId, editorAnalyticsApi, editorView, extensionKey]);
93
+ switch (editVariant) {
94
+ case 'edit-link':
95
+ {
96
+ return (0, _react2.jsx)(_primitives.Flex, {
97
+ gap: "space.050"
98
+ }, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
99
+ testId: "edit-link",
100
+ onClick: onEditLink
101
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.linkToolbarMessages.editLink)), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
102
+ }
103
+ case 'edit-datasource':
104
+ {
105
+ return (0, _react2.jsx)(_primitives.Flex, {
106
+ gap: "space.050"
107
+ }, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
108
+ testId: "edit-datasource",
109
+ tooltipContent: intl.formatMessage(_messages.linkToolbarMessages.editDatasourceStandaloneTooltip),
110
+ onClick: onEditDatasource
111
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.linkToolbarMessages.editDatasourceStandalone)), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
112
+ }
113
+ case 'edit-dropdown':
114
+ {
115
+ var trigger = (0, _react2.jsx)(_primitives.Flex, {
116
+ gap: "space.050"
117
+ }, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
118
+ testId: "edit-dropdown-trigger",
119
+ iconAfter: (0, _react2.jsx)("span", {
120
+ css: dropdownExpandContainer
121
+ }, (0, _react2.jsx)(_chevronDown.default, {
122
+ label: intl.formatMessage(_messages.cardMessages.editDropdownTriggerTitle)
123
+ })),
124
+ onClick: toggleOpen,
125
+ selected: isOpen,
126
+ disabled: false,
127
+ ariaHasPopup: true
128
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownTriggerTitle)), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
129
+ return (0, _react2.jsx)(_primitives.Flex, {
130
+ ref: containerRef
131
+ }, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
132
+ mountTo: containerRef.current,
133
+ isOpen: isOpen,
134
+ handleClickOutside: onClose,
135
+ handleEscapeKeydown: onClose,
136
+ trigger: trigger,
137
+ scrollableElement: containerRef.current,
138
+ arrowKeyNavigationProviderOptions: {
139
+ type: _uiMenu.ArrowKeyNavigationType.MENU
140
+ }
141
+ }, (0, _react2.jsx)(_menu.ButtonItem, {
142
+ key: "edit.link",
143
+ onClick: onEditLink,
144
+ testId: "edit-dropdown-edit-link-item"
145
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditLinkTitle)), (0, _react2.jsx)(_menu.ButtonItem, {
146
+ key: "edit.datasource",
147
+ onClick: onEditDatasource,
148
+ testId: "edit-dropdown-edit-datasource-item"
149
+ }, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.cardMessages.editDropdownEditDatasourceTitle))));
150
+ }
151
+ case 'none':
152
+ default:
153
+ return null;
154
+ }
155
+ };
156
+ var EditToolbarButtonWithUrl = function EditToolbarButtonWithUrl(props) {
157
+ var cardContext = props.cardContext,
158
+ currentAppearance = props.currentAppearance,
159
+ editorAnalyticsApi = props.editorAnalyticsApi,
160
+ editorView = props.editorView,
161
+ intl = props.intl,
162
+ onLinkEditClick = props.onLinkEditClick,
163
+ url = props.url;
164
+ var _useFetchDatasourceIn2 = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
165
+ isRegularCardNode: true,
166
+ url: url,
167
+ cardContext: cardContext
168
+ }),
169
+ extensionKey = _useFetchDatasourceIn2.extensionKey,
170
+ datasourceId = _useFetchDatasourceIn2.datasourceId;
171
+ var editVariant = (0, _react.useMemo)(function () {
172
+ var _cardContext$store2, _urlState$error2;
173
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
174
+ return 'edit-link';
175
+ }
176
+ var urlState = cardContext === null || cardContext === void 0 || (_cardContext$store2 = cardContext.store) === null || _cardContext$store2 === void 0 ? void 0 : _cardContext$store2.getState()[url];
177
+ if ((urlState === null || urlState === void 0 || (_urlState$error2 = urlState.error) === null || _urlState$error2 === void 0 ? void 0 : _urlState$error2.kind) === 'fatal') {
178
+ return 'edit-link';
179
+ }
180
+ return 'edit-dropdown';
181
+ }, [cardContext === null || cardContext === void 0 ? void 0 : cardContext.store, datasourceId, url]);
182
+ return (0, _react2.jsx)(_EditToolbarButtonPresentation.default, {
183
+ datasourceId: datasourceId,
184
+ currentAppearance: currentAppearance,
185
+ editorAnalyticsApi: editorAnalyticsApi,
186
+ editVariant: editVariant,
187
+ editorView: editorView,
188
+ extensionKey: extensionKey,
189
+ onLinkEditClick: onLinkEditClick,
190
+ intl: intl
191
+ });
192
+ };
193
+ var EditToolbarButtonWithDatasourceId = function EditToolbarButtonWithDatasourceId(props) {
194
+ var currentAppearance = props.currentAppearance,
195
+ editorAnalyticsApi = props.editorAnalyticsApi,
196
+ editorView = props.editorView,
197
+ intl = props.intl,
198
+ onLinkEditClick = props.onLinkEditClick,
199
+ datasourceId = props.datasourceId,
200
+ node = props.node;
201
+ var fetchData = (0, _react.useMemo)(function () {
202
+ try {
203
+ var _attrs$datasource$vie;
204
+ var attrs = node.attrs;
205
+ var parameters = attrs.datasource.parameters;
206
+ 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) {
207
+ return c.key;
208
+ });
209
+ return {
210
+ parameters: parameters,
211
+ visibleColumnKeys: visibleColumnKeys
212
+ };
213
+ } catch (e) {
214
+ // eslint-disable-next-line no-console
215
+ console.error(e);
216
+ }
217
+ }, [node.attrs]);
218
+ var _useFetchDatasourceDa = (0, _useFetchDatasourceDataInfo.useFetchDatasourceDataInfo)({
219
+ datasourceId: datasourceId,
220
+ parameters: fetchData === null || fetchData === void 0 ? void 0 : fetchData.parameters,
221
+ visibleColumnKeys: fetchData === null || fetchData === void 0 ? void 0 : fetchData.visibleColumnKeys
222
+ }),
223
+ extensionKey = _useFetchDatasourceDa.extensionKey;
224
+ var editVariant = (0, _react.useMemo)(function () {
225
+ if (!datasourceId || !(0, _utils.isDatasourceConfigEditable)(datasourceId)) {
226
+ return 'none';
227
+ }
228
+ return 'edit-datasource';
229
+ }, [datasourceId]);
230
+ return (0, _react2.jsx)(_EditToolbarButtonPresentation.default, {
231
+ datasourceId: datasourceId,
232
+ currentAppearance: currentAppearance,
233
+ editorAnalyticsApi: editorAnalyticsApi,
234
+ editVariant: editVariant,
235
+ editorView: editorView,
236
+ extensionKey: extensionKey,
237
+ onLinkEditClick: onLinkEditClick,
238
+ intl: intl
239
+ });
240
+ };
241
+ var EditToolbarButton = exports.EditToolbarButton = function EditToolbarButton(props) {
242
+ var currentAppearance = props.currentAppearance,
243
+ datasourceId = props.datasourceId,
244
+ editorAnalyticsApi = props.editorAnalyticsApi,
245
+ editorView = props.editorView,
246
+ intl = props.intl,
247
+ onLinkEditClick = props.onLinkEditClick,
248
+ url = props.url;
249
+ return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref) {
250
+ var cardContext = _ref.cardContext;
251
+ if ((0, _platformFeatureFlags.fg)('enable_datasource_nourl_edit_dropdown_datafetch')) {
252
+ if (props.url) {
253
+ return (0, _react2.jsx)(EditToolbarButtonWithUrl, {
254
+ url: props.url,
255
+ intl: intl,
256
+ editorAnalyticsApi: editorAnalyticsApi,
257
+ editorView: editorView,
258
+ cardContext: cardContext,
259
+ onLinkEditClick: onLinkEditClick,
260
+ currentAppearance: currentAppearance
261
+ });
262
+ }
263
+ if (props.datasourceId && props.node) {
264
+ return (0, _react2.jsx)(EditToolbarButtonWithDatasourceId, {
265
+ datasourceId: props.datasourceId,
266
+ node: props.node,
267
+ intl: intl,
268
+ editorAnalyticsApi: editorAnalyticsApi,
269
+ editorView: editorView,
270
+ onLinkEditClick: onLinkEditClick,
271
+ currentAppearance: currentAppearance
272
+ });
273
+ }
274
+ }
275
+ return (0, _react2.jsx)(EditToolbarButtonWithCardContext, {
276
+ datasourceId: datasourceId,
277
+ url: url,
278
+ intl: intl,
279
+ editorAnalyticsApi: editorAnalyticsApi,
280
+ editorView: editorView,
281
+ cardContext: cardContext,
282
+ onLinkEditClick: onLinkEditClick,
283
+ currentAppearance: currentAppearance
284
+ });
285
+ });
286
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });