@atlaskit/editor-plugin-paste-options-toolbar 8.4.0 → 9.0.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 (28) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/editor-commands/commands.js +9 -6
  3. package/dist/cjs/pasteOptionsToolbarPlugin.js +1 -2
  4. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +28 -30
  5. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
  6. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +8 -6
  7. package/dist/cjs/ui/on-paste-actions-menu/hasVisibleButton.js +42 -0
  8. package/dist/es2019/editor-commands/commands.js +9 -6
  9. package/dist/es2019/pasteOptionsToolbarPlugin.js +1 -2
  10. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +29 -29
  11. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
  12. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +8 -6
  13. package/dist/es2019/ui/on-paste-actions-menu/hasVisibleButton.js +27 -0
  14. package/dist/esm/editor-commands/commands.js +9 -6
  15. package/dist/esm/pasteOptionsToolbarPlugin.js +1 -2
  16. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +29 -31
  17. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
  18. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +8 -6
  19. package/dist/esm/ui/on-paste-actions-menu/hasVisibleButton.js +36 -0
  20. package/dist/types/editor-commands/commands.d.ts +3 -3
  21. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +3 -5
  22. package/dist/types/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +1 -3
  23. package/dist/types/ui/on-paste-actions-menu/hasVisibleButton.d.ts +11 -0
  24. package/dist/types-ts4.5/editor-commands/commands.d.ts +3 -3
  25. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +3 -5
  26. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +1 -3
  27. package/dist/types-ts4.5/ui/on-paste-actions-menu/hasVisibleButton.d.ts +11 -0
  28. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 9.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [`7091cae4a7f26`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7091cae4a7f26) -
8
+ EDITOR-5607 Add analytics for new editor paste menu
9
+ - Updated dependencies
10
+
11
+ ## 8.4.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [`1a9b3a0f8a1c1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1a9b3a0f8a1c1) -
16
+ [ux] EDITOR-5892 Refactor Paste actions menu to use a single ui controls registry entry and single
17
+ SurfaceRenderer. Tweaked visibility rules and increased test coverage.
18
+ - Updated dependencies
19
+
3
20
  ## 8.4.0
4
21
 
5
22
  ### Minor Changes
@@ -49,7 +49,7 @@ var changeToPlainText = exports.changeToPlainText = function changeToPlainText()
49
49
  };
50
50
  return (0, _pluginFactory.createCommand)(commandAction, plaintextTransformer);
51
51
  };
52
- var changeToPlainTextWithAnalytics = exports.changeToPlainTextWithAnalytics = function changeToPlainTextWithAnalytics(editorAnalyticsAPI, sliceSize) {
52
+ var changeToPlainTextWithAnalytics = exports.changeToPlainTextWithAnalytics = function changeToPlainTextWithAnalytics(editorAnalyticsAPI, sliceSize, invokedFrom) {
53
53
  return function () {
54
54
  return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
55
55
  action: _analytics.ACTION.PASTED,
@@ -59,7 +59,8 @@ var changeToPlainTextWithAnalytics = exports.changeToPlainTextWithAnalytics = fu
59
59
  inputMethod: _analytics.INPUT_METHOD.TOOLBAR,
60
60
  type: _analytics.PasteTypes.plain,
61
61
  content: _analytics.PasteContents.text,
62
- pasteSize: sliceSize
62
+ pasteSize: sliceSize,
63
+ invokedFrom: invokedFrom
63
64
  }
64
65
  })(changeToPlainText());
65
66
  };
@@ -85,7 +86,7 @@ var changeToRichText = exports.changeToRichText = function changeToRichText() {
85
86
  };
86
87
  return (0, _pluginFactory.createCommand)(commandAction, transformer);
87
88
  };
88
- var changeToRichTextWithAnalytics = exports.changeToRichTextWithAnalytics = function changeToRichTextWithAnalytics(editorAnalyticsAPI) {
89
+ var changeToRichTextWithAnalytics = exports.changeToRichTextWithAnalytics = function changeToRichTextWithAnalytics(editorAnalyticsAPI, invokedFrom) {
89
90
  return function () {
90
91
  var payloadCallback = function payloadCallback(state) {
91
92
  var _pastePluginState$ric;
@@ -98,7 +99,8 @@ var changeToRichTextWithAnalytics = exports.changeToRichTextWithAnalytics = func
98
99
  inputMethod: _analytics.INPUT_METHOD.TOOLBAR,
99
100
  type: _analytics.PasteTypes.richText,
100
101
  content: _analytics.PasteContents.text,
101
- pasteSize: ((_pastePluginState$ric = pastePluginState.richTextSlice) === null || _pastePluginState$ric === void 0 ? void 0 : _pastePluginState$ric.size) || 0
102
+ pasteSize: ((_pastePluginState$ric = pastePluginState.richTextSlice) === null || _pastePluginState$ric === void 0 ? void 0 : _pastePluginState$ric.size) || 0,
103
+ invokedFrom: invokedFrom
102
104
  }
103
105
  };
104
106
  };
@@ -123,7 +125,7 @@ var changeToMarkDown = exports.changeToMarkDown = function changeToMarkDown() {
123
125
  };
124
126
  return (0, _pluginFactory.createCommand)(commandAction, markdownTransformer);
125
127
  };
126
- var changeToMarkdownWithAnalytics = exports.changeToMarkdownWithAnalytics = function changeToMarkdownWithAnalytics(editorAnalyticsAPI, sliceSize) {
128
+ var changeToMarkdownWithAnalytics = exports.changeToMarkdownWithAnalytics = function changeToMarkdownWithAnalytics(editorAnalyticsAPI, sliceSize, invokedFrom) {
127
129
  return function () {
128
130
  return (0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
129
131
  action: _analytics.ACTION.PASTED,
@@ -133,7 +135,8 @@ var changeToMarkdownWithAnalytics = exports.changeToMarkdownWithAnalytics = func
133
135
  inputMethod: _analytics.INPUT_METHOD.TOOLBAR,
134
136
  type: _analytics.PasteTypes.markdown,
135
137
  content: _analytics.PasteContents.text,
136
- pasteSize: sliceSize
138
+ pasteSize: sliceSize,
139
+ invokedFrom: invokedFrom
137
140
  }
138
141
  })(changeToMarkDown());
139
142
  };
@@ -22,8 +22,7 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
22
22
  if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
23
23
  var _api$uiControlRegistr;
24
24
  api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register((0, _PasteMenuComponents.getPasteMenuComponents)({
25
- api: api,
26
- editorAnalyticsAPI: editorAnalyticsAPI
25
+ api: api
27
26
  }));
28
27
  }
29
28
  return {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.PasteActionsMenu = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
+ var _analytics = require("@atlaskit/editor-common/analytics");
9
10
  var _hooks = require("@atlaskit/editor-common/hooks");
10
11
  var _toolbar = require("@atlaskit/editor-common/toolbar");
11
12
  var _ui = require("@atlaskit/editor-common/ui");
@@ -13,10 +14,10 @@ var _uiReact = require("@atlaskit/editor-common/ui-react");
13
14
  var _utils = require("@atlaskit/editor-prosemirror/utils");
14
15
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
15
16
  var _editorToolbar = require("@atlaskit/editor-toolbar");
16
- var _editorUiControlModel = require("@atlaskit/editor-ui-control-model");
17
17
  var _commands = require("../../editor-commands/commands");
18
18
  var _types = require("../../types/types");
19
19
  var _toolbar2 = require("../toolbar");
20
+ var _hasVisibleButton = require("./hasVisibleButton");
20
21
  var _PasteActionsMenuContent = require("./PasteActionsMenuContent");
21
22
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
22
23
  var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
@@ -39,25 +40,14 @@ function getPopupOffset(dom) {
39
40
  var rightEdge = dom.getBoundingClientRect().right;
40
41
  return [-(window.innerWidth - rightEdge - 50), 20];
41
42
  }
42
-
43
- /**
44
- * Returns true when at least one component in the given list would produce
45
- * visible output (i.e. is not hidden and, for containers, has at least one
46
- * visible descendant).
47
- */
48
- var hasVisibleComponent = function hasVisibleComponent(components) {
49
- var childrenMap = (0, _editorUiControlModel.buildChildrenMap)(components);
50
- return components.some(function (c) {
51
- return (0, _editorUiControlModel.willComponentRender)(c, childrenMap);
52
- });
53
- };
54
43
  var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
55
- var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
44
+ var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
56
45
  var api = _ref.api,
57
46
  editorView = _ref.editorView,
58
47
  mountTo = _ref.mountTo,
59
48
  boundariesElement = _ref.boundariesElement,
60
49
  scrollableElement = _ref.scrollableElement;
50
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
61
51
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['paste'], function (states) {
62
52
  var _states$pasteState;
63
53
  return {
@@ -65,6 +55,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
65
55
  };
66
56
  }),
67
57
  lastContentPasted = _useSharedPluginState.lastContentPasted;
58
+ var prevShowToolbarRef = (0, _react.useRef)(false);
68
59
  (0, _react.useEffect)(function () {
69
60
  if (!lastContentPasted) {
70
61
  (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
@@ -87,15 +78,29 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
87
78
  (0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
88
79
  }, [lastContentPasted, editorView]);
89
80
  var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
90
- var _pluginState$showTool, _pluginState$showLega;
81
+ var _pluginState$showTool;
91
82
  var pluginState = states.pasteOptionsToolbarPluginState;
92
83
  return {
93
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
94
- showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
84
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
95
85
  };
96
86
  }),
97
- isToolbarShown = _useSharedPluginState2.showToolbar,
98
- showLegacyOptions = _useSharedPluginState2.showLegacyOptions;
87
+ isToolbarShown = _useSharedPluginState2.showToolbar;
88
+ var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents('ai-paste-menu')) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
89
+ var visibleAiActionKeys = (0, _hasVisibleButton.getVisibleKeys)(aiSurfaceComponents, ['button', 'menu-item']);
90
+ (0, _react.useEffect)(function () {
91
+ if (!prevShowToolbarRef.current && isToolbarShown) {
92
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
93
+ action: _analytics.ACTION.OPENED,
94
+ actionSubject: _analytics.ACTION_SUBJECT.PASTE_ACTIONS_MENU,
95
+ eventType: _analytics.EVENT_TYPE.UI,
96
+ attributes: {
97
+ visibleAiActions: visibleAiActionKeys
98
+ }
99
+ });
100
+ }
101
+ prevShowToolbarRef.current = isToolbarShown;
102
+ // eslint-disable-next-line react-hooks/exhaustive-deps
103
+ }, [isToolbarShown, editorAnalyticsAPI]);
99
104
  var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
100
105
  e.preventDefault();
101
106
  }, []);
@@ -119,17 +124,12 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
119
124
  handleDismiss();
120
125
  }
121
126
  }, [handleDismiss]);
122
- var aiSurface = {
123
- type: 'menu',
124
- key: 'ai-paste-menu'
125
- };
126
- var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
127
- var pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
128
- var anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
127
+ var pasteMenuComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
128
+ var anyComponentVisible = (0, _hasVisibleButton.hasVisibleButton)(pasteMenuComponents);
129
129
  if (!isToolbarShown) {
130
130
  return null;
131
131
  }
132
- if (!showLegacyOptions && !anyAiComponentVisible) {
132
+ if (!anyComponentVisible) {
133
133
  return null;
134
134
  }
135
135
  var target = getTargetElement(editorView);
@@ -155,8 +155,6 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
155
155
  }, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
156
156
  onMouseDown: preventEditorFocusLoss,
157
157
  onMouseEnter: handleMouseEnter,
158
- aiSurface: aiSurface,
159
- aiSurfaceComponents: aiSurfaceComponents,
160
- pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
158
+ components: pasteMenuComponents
161
159
  }))));
162
160
  };
@@ -9,7 +9,10 @@ exports.PasteActionsMenuContent = void 0;
9
9
  require("./PasteActionsMenuContent.compiled.css");
10
10
  var _runtime = require("@compiled/react/runtime");
11
11
  var _react = _interopRequireWildcard(require("react"));
12
+ var _reactIntlNext = require("react-intl-next");
13
+ var _messages = require("@atlaskit/editor-common/messages");
12
14
  var _uiReact = require("@atlaskit/editor-common/ui-react");
15
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
13
16
  var _editorUiControlModel = require("@atlaskit/editor-ui-control-model");
14
17
  var _compiled = require("@atlaskit/primitives/compiled");
15
18
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
@@ -19,23 +22,21 @@ var styles = {
19
22
  var PasteActionsMenuContent = exports.PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
20
23
  var onMouseDown = _ref.onMouseDown,
21
24
  onMouseEnter = _ref.onMouseEnter,
22
- aiSurface = _ref.aiSurface,
23
- aiSurfaceComponents = _ref.aiSurfaceComponents,
24
- pasteSurfaceComponents = _ref.pasteSurfaceComponents;
25
+ components = _ref.components;
25
26
  var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
27
+ var intl = (0, _reactIntlNext.useIntl)();
26
28
  return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
27
29
  ref: setOutsideClickTargetRef,
28
30
  xcss: styles.container,
29
31
  onMouseDown: onMouseDown,
30
32
  onMouseEnter: onMouseEnter
31
- }, aiSurface && aiSurfaceComponents && aiSurfaceComponents.length > 0 && /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
32
- surface: aiSurface,
33
- components: aiSurfaceComponents
34
- }), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
33
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
34
+ title: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteMenuActionsTitle)
35
+ }, /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
35
36
  surface: {
36
37
  type: 'menu',
37
38
  key: 'paste-menu'
38
39
  },
39
- components: pasteSurfaceComponents
40
- }));
40
+ components: components
41
+ })));
41
42
  };
@@ -38,12 +38,13 @@ var isPasteOptionSelected = exports.isPasteOptionSelected = function isPasteOpti
38
38
  }
39
39
  };
40
40
  var PasteMenuItem = function PasteMenuItem(_ref) {
41
+ var _api$analytics;
41
42
  var api = _ref.api,
42
- editorAnalyticsAPI = _ref.editorAnalyticsAPI,
43
43
  pasteType = _ref.pasteType;
44
44
  var intl = (0, _reactIntlNext.useIntl)();
45
45
  var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
46
46
  editorView = _useEditorToolbar.editorView;
47
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
47
48
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
48
49
  var _pluginState$selected, _pluginState$plaintex, _pluginState$isPlainT;
49
50
  var pluginState = states.pasteOptionsToolbarPluginState;
@@ -114,8 +115,7 @@ var PasteOptionsNestedMenu = function PasteOptionsNestedMenu(_ref2) {
114
115
  }, children);
115
116
  };
116
117
  var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
117
- var api = _ref3.api,
118
- editorAnalyticsAPI = _ref3.editorAnalyticsAPI;
118
+ var api = _ref3.api;
119
119
  return [{
120
120
  type: _toolbar.PASTE_MENU.type,
121
121
  key: _toolbar.PASTE_MENU.key
@@ -127,6 +127,11 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
127
127
  key: _toolbar.PASTE_MENU.key,
128
128
  rank: _toolbar.PASTE_MENU_RANK[_toolbar.PASTE_MENU_SECTION.key]
129
129
  }],
130
+ isHidden: function isHidden() {
131
+ var _api$pasteOptionsTool, _pluginState$showLega;
132
+ var pluginState = api === null || api === void 0 || (_api$pasteOptionsTool = api.pasteOptionsToolbarPlugin) === null || _api$pasteOptionsTool === void 0 ? void 0 : _api$pasteOptionsTool.sharedState.currentState();
133
+ return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
134
+ },
130
135
  component: function component(props) {
131
136
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
132
137
  hasSeparator: true
@@ -162,7 +167,6 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
162
167
  component: function component() {
163
168
  return /*#__PURE__*/_react.default.createElement(PasteMenuItem, {
164
169
  api: api,
165
- editorAnalyticsAPI: editorAnalyticsAPI,
166
170
  pasteType: "rich-text"
167
171
  });
168
172
  },
@@ -177,7 +181,6 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
177
181
  component: function component() {
178
182
  return /*#__PURE__*/_react.default.createElement(PasteMenuItem, {
179
183
  api: api,
180
- editorAnalyticsAPI: editorAnalyticsAPI,
181
184
  pasteType: "markdown"
182
185
  });
183
186
  },
@@ -192,7 +195,6 @@ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteM
192
195
  component: function component() {
193
196
  return /*#__PURE__*/_react.default.createElement(PasteMenuItem, {
194
197
  api: api,
195
- editorAnalyticsAPI: editorAnalyticsAPI,
196
198
  pasteType: "plain-text"
197
199
  });
198
200
  },
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasVisibleButton = exports.getVisibleKeys = void 0;
7
+ var _isComponentOrAncestorHidden = function isComponentOrAncestorHidden(component, componentsByKey) {
8
+ var _component$isHidden, _component$parents;
9
+ if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) {
10
+ return true;
11
+ }
12
+ return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(function (parent) {
13
+ var parentComponent = componentsByKey.get(parent.key);
14
+ return parentComponent ? _isComponentOrAncestorHidden(parentComponent, componentsByKey) : false;
15
+ });
16
+ };
17
+
18
+ /**
19
+ * Returns the keys of visible button/menu-item components in the list.
20
+ * A component is visible when neither it nor any of its ancestors are hidden.
21
+ */
22
+ var getVisibleKeys = exports.getVisibleKeys = function getVisibleKeys(components) {
23
+ var types = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['menu-item'];
24
+ var componentsByKey = new Map(components.map(function (c) {
25
+ return [c.key, c];
26
+ }));
27
+ return components.filter(function (c) {
28
+ return types.includes(c.type);
29
+ }).filter(function (c) {
30
+ return !_isComponentOrAncestorHidden(c, componentsByKey);
31
+ }).map(function (c) {
32
+ return c.key;
33
+ });
34
+ };
35
+
36
+ /**
37
+ * Returns true when at least one menu-item button in the list is visible.
38
+ * A button is visible when neither it nor any of its ancestors are hidden.
39
+ */
40
+ var hasVisibleButton = exports.hasVisibleButton = function hasVisibleButton(components) {
41
+ return getVisibleKeys(components).length > 0;
42
+ };
@@ -41,7 +41,7 @@ export const changeToPlainText = () => {
41
41
  };
42
42
  return createCommand(commandAction, plaintextTransformer);
43
43
  };
44
- export const changeToPlainTextWithAnalytics = (editorAnalyticsAPI, sliceSize) => () => {
44
+ export const changeToPlainTextWithAnalytics = (editorAnalyticsAPI, sliceSize, invokedFrom) => () => {
45
45
  return withAnalytics(editorAnalyticsAPI, {
46
46
  action: ACTION.PASTED,
47
47
  actionSubject: ACTION_SUBJECT.DOCUMENT,
@@ -50,7 +50,8 @@ export const changeToPlainTextWithAnalytics = (editorAnalyticsAPI, sliceSize) =>
50
50
  inputMethod: INPUT_METHOD.TOOLBAR,
51
51
  type: PasteTypes.plain,
52
52
  content: PasteContents.text,
53
- pasteSize: sliceSize
53
+ pasteSize: sliceSize,
54
+ invokedFrom
54
55
  }
55
56
  })(changeToPlainText());
56
57
  };
@@ -75,7 +76,7 @@ export const changeToRichText = () => {
75
76
  };
76
77
  return createCommand(commandAction, transformer);
77
78
  };
78
- export const changeToRichTextWithAnalytics = editorAnalyticsAPI => () => {
79
+ export const changeToRichTextWithAnalytics = (editorAnalyticsAPI, invokedFrom) => () => {
79
80
  const payloadCallback = state => {
80
81
  var _pastePluginState$ric;
81
82
  const pastePluginState = pasteOptionsPluginKey.getState(state);
@@ -87,7 +88,8 @@ export const changeToRichTextWithAnalytics = editorAnalyticsAPI => () => {
87
88
  inputMethod: INPUT_METHOD.TOOLBAR,
88
89
  type: PasteTypes.richText,
89
90
  content: PasteContents.text,
90
- pasteSize: ((_pastePluginState$ric = pastePluginState.richTextSlice) === null || _pastePluginState$ric === void 0 ? void 0 : _pastePluginState$ric.size) || 0
91
+ pasteSize: ((_pastePluginState$ric = pastePluginState.richTextSlice) === null || _pastePluginState$ric === void 0 ? void 0 : _pastePluginState$ric.size) || 0,
92
+ invokedFrom
91
93
  }
92
94
  };
93
95
  };
@@ -111,7 +113,7 @@ export const changeToMarkDown = () => {
111
113
  };
112
114
  return createCommand(commandAction, markdownTransformer);
113
115
  };
114
- export const changeToMarkdownWithAnalytics = (editorAnalyticsAPI, sliceSize) => () => {
116
+ export const changeToMarkdownWithAnalytics = (editorAnalyticsAPI, sliceSize, invokedFrom) => () => {
115
117
  return withAnalytics(editorAnalyticsAPI, {
116
118
  action: ACTION.PASTED,
117
119
  actionSubject: ACTION_SUBJECT.DOCUMENT,
@@ -120,7 +122,8 @@ export const changeToMarkdownWithAnalytics = (editorAnalyticsAPI, sliceSize) =>
120
122
  inputMethod: INPUT_METHOD.TOOLBAR,
121
123
  type: PasteTypes.markdown,
122
124
  content: PasteContents.text,
123
- pasteSize: sliceSize
125
+ pasteSize: sliceSize,
126
+ invokedFrom
124
127
  }
125
128
  })(changeToMarkDown());
126
129
  };
@@ -15,8 +15,7 @@ export const pasteOptionsToolbarPlugin = ({
15
15
  if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
16
16
  var _api$uiControlRegistr;
17
17
  api === null || api === void 0 ? void 0 : (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 ? void 0 : _api$uiControlRegistr.actions.register(getPasteMenuComponents({
18
- api,
19
- editorAnalyticsAPI
18
+ api
20
19
  }));
21
20
  }
22
21
  return {
@@ -1,4 +1,5 @@
1
- import React, { useCallback, useEffect } from 'react';
1
+ import React, { useCallback, useEffect, useRef } from 'react';
2
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
4
  import { EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
4
5
  import { Popup } from '@atlaskit/editor-common/ui';
@@ -6,10 +7,10 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
6
7
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
7
8
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
8
9
  import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
9
- import { buildChildrenMap, willComponentRender } from '@atlaskit/editor-ui-control-model';
10
10
  import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
11
11
  import { ToolbarDropdownOption } from '../../types/types';
12
12
  import { isToolbarVisible } from '../toolbar';
13
+ import { getVisibleKeys, hasVisibleButton } from './hasVisibleButton';
13
14
  import { PasteActionsMenuContent } from './PasteActionsMenuContent';
14
15
  const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
15
16
  function getTargetElement(editorView) {
@@ -33,16 +34,6 @@ function getPopupOffset(dom) {
33
34
  const rightEdge = dom.getBoundingClientRect().right;
34
35
  return [-(window.innerWidth - rightEdge - 50), 20];
35
36
  }
36
-
37
- /**
38
- * Returns true when at least one component in the given list would produce
39
- * visible output (i.e. is not hidden and, for containers, has at least one
40
- * visible descendant).
41
- */
42
- const hasVisibleComponent = components => {
43
- const childrenMap = buildChildrenMap(components);
44
- return components.some(c => willComponentRender(c, childrenMap));
45
- };
46
37
  export const PasteActionsMenu = ({
47
38
  api,
48
39
  editorView,
@@ -50,7 +41,8 @@ export const PasteActionsMenu = ({
50
41
  boundariesElement,
51
42
  scrollableElement
52
43
  }) => {
53
- var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
44
+ var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
45
+ const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
54
46
  const {
55
47
  lastContentPasted
56
48
  } = useSharedPluginStateWithSelector(api, ['paste'], states => {
@@ -59,6 +51,7 @@ export const PasteActionsMenu = ({
59
51
  lastContentPasted: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.lastContentPasted
60
52
  };
61
53
  });
54
+ const prevShowToolbarRef = useRef(false);
62
55
  useEffect(() => {
63
56
  if (!lastContentPasted) {
64
57
  hideToolbar()(editorView.state, editorView.dispatch);
@@ -81,16 +74,30 @@ export const PasteActionsMenu = ({
81
74
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
82
75
  }, [lastContentPasted, editorView]);
83
76
  const {
84
- showToolbar: isToolbarShown,
85
- showLegacyOptions
77
+ showToolbar: isToolbarShown
86
78
  } = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
87
- var _pluginState$showTool, _pluginState$showLega;
79
+ var _pluginState$showTool;
88
80
  const pluginState = states.pasteOptionsToolbarPluginState;
89
81
  return {
90
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
91
- showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
82
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
92
83
  };
93
84
  });
85
+ const aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents('ai-paste-menu')) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
86
+ const visibleAiActionKeys = getVisibleKeys(aiSurfaceComponents, ['button', 'menu-item']);
87
+ useEffect(() => {
88
+ if (!prevShowToolbarRef.current && isToolbarShown) {
89
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
90
+ action: ACTION.OPENED,
91
+ actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
92
+ eventType: EVENT_TYPE.UI,
93
+ attributes: {
94
+ visibleAiActions: visibleAiActionKeys
95
+ }
96
+ });
97
+ }
98
+ prevShowToolbarRef.current = isToolbarShown;
99
+ // eslint-disable-next-line react-hooks/exhaustive-deps
100
+ }, [isToolbarShown, editorAnalyticsAPI]);
94
101
  const preventEditorFocusLoss = useCallback(e => {
95
102
  e.preventDefault();
96
103
  }, []);
@@ -114,17 +121,12 @@ export const PasteActionsMenu = ({
114
121
  handleDismiss();
115
122
  }
116
123
  }, [handleDismiss]);
117
- const aiSurface = {
118
- type: 'menu',
119
- key: 'ai-paste-menu'
120
- };
121
- const aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
122
- const pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
123
- const anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
124
+ const pasteMenuComponents = (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
125
+ const anyComponentVisible = hasVisibleButton(pasteMenuComponents);
124
126
  if (!isToolbarShown) {
125
127
  return null;
126
128
  }
127
- if (!showLegacyOptions && !anyAiComponentVisible) {
129
+ if (!anyComponentVisible) {
128
130
  return null;
129
131
  }
130
132
  const target = getTargetElement(editorView);
@@ -150,8 +152,6 @@ export const PasteActionsMenu = ({
150
152
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
151
153
  onMouseDown: preventEditorFocusLoss,
152
154
  onMouseEnter: handleMouseEnter,
153
- aiSurface: aiSurface,
154
- aiSurfaceComponents: aiSurfaceComponents,
155
- pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
155
+ components: pasteMenuComponents
156
156
  }))));
157
157
  };
@@ -2,7 +2,10 @@
2
2
  import "./PasteActionsMenuContent.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useContext } from 'react';
5
+ import { useIntl } from 'react-intl-next';
6
+ import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
5
7
  import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
8
+ import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
6
9
  import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
7
10
  import { Box } from '@atlaskit/primitives/compiled';
8
11
  const styles = {
@@ -11,24 +14,22 @@ const styles = {
11
14
  export const PasteActionsMenuContent = ({
12
15
  onMouseDown,
13
16
  onMouseEnter,
14
- aiSurface,
15
- aiSurfaceComponents,
16
- pasteSurfaceComponents
17
+ components
17
18
  }) => {
18
19
  const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
20
+ const intl = useIntl();
19
21
  return /*#__PURE__*/React.createElement(Box, {
20
22
  ref: setOutsideClickTargetRef,
21
23
  xcss: styles.container,
22
24
  onMouseDown: onMouseDown,
23
25
  onMouseEnter: onMouseEnter
24
- }, aiSurface && aiSurfaceComponents && aiSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
25
- surface: aiSurface,
26
- components: aiSurfaceComponents
27
- }), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
26
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
27
+ title: intl.formatMessage(messages.pasteMenuActionsTitle)
28
+ }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
28
29
  surface: {
29
30
  type: 'menu',
30
31
  key: 'paste-menu'
31
32
  },
32
- components: pasteSurfaceComponents
33
- }));
33
+ components: components
34
+ })));
34
35
  };
@@ -30,13 +30,14 @@ export const isPasteOptionSelected = (pasteType, selectedOption) => {
30
30
  };
31
31
  const PasteMenuItem = ({
32
32
  api,
33
- editorAnalyticsAPI,
34
33
  pasteType
35
34
  }) => {
35
+ var _api$analytics;
36
36
  const intl = useIntl();
37
37
  const {
38
38
  editorView
39
39
  } = useEditorToolbar();
40
+ const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
40
41
  const {
41
42
  selectedOption,
42
43
  plaintextLength,
@@ -109,8 +110,7 @@ const PasteOptionsNestedMenu = ({
109
110
  }, children);
110
111
  };
111
112
  export const getPasteMenuComponents = ({
112
- api,
113
- editorAnalyticsAPI
113
+ api
114
114
  }) => [{
115
115
  type: PASTE_MENU.type,
116
116
  key: PASTE_MENU.key
@@ -122,6 +122,11 @@ export const getPasteMenuComponents = ({
122
122
  key: PASTE_MENU.key,
123
123
  rank: PASTE_MENU_RANK[PASTE_MENU_SECTION.key]
124
124
  }],
125
+ isHidden: () => {
126
+ var _api$pasteOptionsTool, _pluginState$showLega;
127
+ const pluginState = api === null || api === void 0 ? void 0 : (_api$pasteOptionsTool = api.pasteOptionsToolbarPlugin) === null || _api$pasteOptionsTool === void 0 ? void 0 : _api$pasteOptionsTool.sharedState.currentState();
128
+ return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
129
+ },
125
130
  component: props => /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
126
131
  hasSeparator: true
127
132
  }, props.children)
@@ -150,7 +155,6 @@ export const getPasteMenuComponents = ({
150
155
  type: PASTE_RICH_TEXT_MENU_ITEM.type,
151
156
  component: () => /*#__PURE__*/React.createElement(PasteMenuItem, {
152
157
  api: api,
153
- editorAnalyticsAPI: editorAnalyticsAPI,
154
158
  pasteType: "rich-text"
155
159
  }),
156
160
  parents: [{
@@ -163,7 +167,6 @@ export const getPasteMenuComponents = ({
163
167
  type: PASTE_MARKDOWN_MENU_ITEM.type,
164
168
  component: () => /*#__PURE__*/React.createElement(PasteMenuItem, {
165
169
  api: api,
166
- editorAnalyticsAPI: editorAnalyticsAPI,
167
170
  pasteType: "markdown"
168
171
  }),
169
172
  parents: [{
@@ -176,7 +179,6 @@ export const getPasteMenuComponents = ({
176
179
  type: PASTE_PLAIN_TEXT_MENU_ITEM.type,
177
180
  component: () => /*#__PURE__*/React.createElement(PasteMenuItem, {
178
181
  api: api,
179
- editorAnalyticsAPI: editorAnalyticsAPI,
180
182
  pasteType: "plain-text"
181
183
  }),
182
184
  parents: [{
@@ -0,0 +1,27 @@
1
+ const isComponentOrAncestorHidden = (component, componentsByKey) => {
2
+ var _component$isHidden, _component$parents;
3
+ if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) {
4
+ return true;
5
+ }
6
+ return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(parent => {
7
+ const parentComponent = componentsByKey.get(parent.key);
8
+ return parentComponent ? isComponentOrAncestorHidden(parentComponent, componentsByKey) : false;
9
+ });
10
+ };
11
+
12
+ /**
13
+ * Returns the keys of visible button/menu-item components in the list.
14
+ * A component is visible when neither it nor any of its ancestors are hidden.
15
+ */
16
+ export const getVisibleKeys = (components, types = ['menu-item']) => {
17
+ const componentsByKey = new Map(components.map(c => [c.key, c]));
18
+ return components.filter(c => types.includes(c.type)).filter(c => !isComponentOrAncestorHidden(c, componentsByKey)).map(c => c.key);
19
+ };
20
+
21
+ /**
22
+ * Returns true when at least one menu-item button in the list is visible.
23
+ * A button is visible when neither it nor any of its ancestors are hidden.
24
+ */
25
+ export const hasVisibleButton = components => {
26
+ return getVisibleKeys(components).length > 0;
27
+ };
@@ -43,7 +43,7 @@ export var changeToPlainText = function changeToPlainText() {
43
43
  };
44
44
  return createCommand(commandAction, plaintextTransformer);
45
45
  };
46
- export var changeToPlainTextWithAnalytics = function changeToPlainTextWithAnalytics(editorAnalyticsAPI, sliceSize) {
46
+ export var changeToPlainTextWithAnalytics = function changeToPlainTextWithAnalytics(editorAnalyticsAPI, sliceSize, invokedFrom) {
47
47
  return function () {
48
48
  return withAnalytics(editorAnalyticsAPI, {
49
49
  action: ACTION.PASTED,
@@ -53,7 +53,8 @@ export var changeToPlainTextWithAnalytics = function changeToPlainTextWithAnalyt
53
53
  inputMethod: INPUT_METHOD.TOOLBAR,
54
54
  type: PasteTypes.plain,
55
55
  content: PasteContents.text,
56
- pasteSize: sliceSize
56
+ pasteSize: sliceSize,
57
+ invokedFrom: invokedFrom
57
58
  }
58
59
  })(changeToPlainText());
59
60
  };
@@ -79,7 +80,7 @@ export var changeToRichText = function changeToRichText() {
79
80
  };
80
81
  return createCommand(commandAction, transformer);
81
82
  };
82
- export var changeToRichTextWithAnalytics = function changeToRichTextWithAnalytics(editorAnalyticsAPI) {
83
+ export var changeToRichTextWithAnalytics = function changeToRichTextWithAnalytics(editorAnalyticsAPI, invokedFrom) {
83
84
  return function () {
84
85
  var payloadCallback = function payloadCallback(state) {
85
86
  var _pastePluginState$ric;
@@ -92,7 +93,8 @@ export var changeToRichTextWithAnalytics = function changeToRichTextWithAnalytic
92
93
  inputMethod: INPUT_METHOD.TOOLBAR,
93
94
  type: PasteTypes.richText,
94
95
  content: PasteContents.text,
95
- pasteSize: ((_pastePluginState$ric = pastePluginState.richTextSlice) === null || _pastePluginState$ric === void 0 ? void 0 : _pastePluginState$ric.size) || 0
96
+ pasteSize: ((_pastePluginState$ric = pastePluginState.richTextSlice) === null || _pastePluginState$ric === void 0 ? void 0 : _pastePluginState$ric.size) || 0,
97
+ invokedFrom: invokedFrom
96
98
  }
97
99
  };
98
100
  };
@@ -117,7 +119,7 @@ export var changeToMarkDown = function changeToMarkDown() {
117
119
  };
118
120
  return createCommand(commandAction, markdownTransformer);
119
121
  };
120
- export var changeToMarkdownWithAnalytics = function changeToMarkdownWithAnalytics(editorAnalyticsAPI, sliceSize) {
122
+ export var changeToMarkdownWithAnalytics = function changeToMarkdownWithAnalytics(editorAnalyticsAPI, sliceSize, invokedFrom) {
121
123
  return function () {
122
124
  return withAnalytics(editorAnalyticsAPI, {
123
125
  action: ACTION.PASTED,
@@ -127,7 +129,8 @@ export var changeToMarkdownWithAnalytics = function changeToMarkdownWithAnalytic
127
129
  inputMethod: INPUT_METHOD.TOOLBAR,
128
130
  type: PasteTypes.markdown,
129
131
  content: PasteContents.text,
130
- pasteSize: sliceSize
132
+ pasteSize: sliceSize,
133
+ invokedFrom: invokedFrom
131
134
  }
132
135
  })(changeToMarkDown());
133
136
  };
@@ -14,8 +14,7 @@ export var pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref)
14
14
  if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
15
15
  var _api$uiControlRegistr;
16
16
  api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register(getPasteMenuComponents({
17
- api: api,
18
- editorAnalyticsAPI: editorAnalyticsAPI
17
+ api: api
19
18
  }));
20
19
  }
21
20
  return {
@@ -1,4 +1,5 @@
1
- import React, { useCallback, useEffect } from 'react';
1
+ import React, { useCallback, useEffect, useRef } from 'react';
2
+ import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
3
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
4
  import { EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
4
5
  import { Popup } from '@atlaskit/editor-common/ui';
@@ -6,10 +7,10 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
6
7
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
7
8
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
8
9
  import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
9
- import { buildChildrenMap, willComponentRender } from '@atlaskit/editor-ui-control-model';
10
10
  import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
11
11
  import { ToolbarDropdownOption } from '../../types/types';
12
12
  import { isToolbarVisible } from '../toolbar';
13
+ import { getVisibleKeys, hasVisibleButton } from './hasVisibleButton';
13
14
  import { PasteActionsMenuContent } from './PasteActionsMenuContent';
14
15
  var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
15
16
  function getTargetElement(editorView) {
@@ -31,25 +32,14 @@ function getPopupOffset(dom) {
31
32
  var rightEdge = dom.getBoundingClientRect().right;
32
33
  return [-(window.innerWidth - rightEdge - 50), 20];
33
34
  }
34
-
35
- /**
36
- * Returns true when at least one component in the given list would produce
37
- * visible output (i.e. is not hidden and, for containers, has at least one
38
- * visible descendant).
39
- */
40
- var hasVisibleComponent = function hasVisibleComponent(components) {
41
- var childrenMap = buildChildrenMap(components);
42
- return components.some(function (c) {
43
- return willComponentRender(c, childrenMap);
44
- });
45
- };
46
35
  export var PasteActionsMenu = function PasteActionsMenu(_ref) {
47
- var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
36
+ var _api$analytics, _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
48
37
  var api = _ref.api,
49
38
  editorView = _ref.editorView,
50
39
  mountTo = _ref.mountTo,
51
40
  boundariesElement = _ref.boundariesElement,
52
41
  scrollableElement = _ref.scrollableElement;
42
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
53
43
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['paste'], function (states) {
54
44
  var _states$pasteState;
55
45
  return {
@@ -57,6 +47,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
57
47
  };
58
48
  }),
59
49
  lastContentPasted = _useSharedPluginState.lastContentPasted;
50
+ var prevShowToolbarRef = useRef(false);
60
51
  useEffect(function () {
61
52
  if (!lastContentPasted) {
62
53
  hideToolbar()(editorView.state, editorView.dispatch);
@@ -79,15 +70,29 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
79
70
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
80
71
  }, [lastContentPasted, editorView]);
81
72
  var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
82
- var _pluginState$showTool, _pluginState$showLega;
73
+ var _pluginState$showTool;
83
74
  var pluginState = states.pasteOptionsToolbarPluginState;
84
75
  return {
85
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
86
- showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
76
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
87
77
  };
88
78
  }),
89
- isToolbarShown = _useSharedPluginState2.showToolbar,
90
- showLegacyOptions = _useSharedPluginState2.showLegacyOptions;
79
+ isToolbarShown = _useSharedPluginState2.showToolbar;
80
+ var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents('ai-paste-menu')) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
81
+ var visibleAiActionKeys = getVisibleKeys(aiSurfaceComponents, ['button', 'menu-item']);
82
+ useEffect(function () {
83
+ if (!prevShowToolbarRef.current && isToolbarShown) {
84
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
85
+ action: ACTION.OPENED,
86
+ actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
87
+ eventType: EVENT_TYPE.UI,
88
+ attributes: {
89
+ visibleAiActions: visibleAiActionKeys
90
+ }
91
+ });
92
+ }
93
+ prevShowToolbarRef.current = isToolbarShown;
94
+ // eslint-disable-next-line react-hooks/exhaustive-deps
95
+ }, [isToolbarShown, editorAnalyticsAPI]);
91
96
  var preventEditorFocusLoss = useCallback(function (e) {
92
97
  e.preventDefault();
93
98
  }, []);
@@ -111,17 +116,12 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
111
116
  handleDismiss();
112
117
  }
113
118
  }, [handleDismiss]);
114
- var aiSurface = {
115
- type: 'menu',
116
- key: 'ai-paste-menu'
117
- };
118
- var aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
119
- var pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
120
- var anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
119
+ var pasteMenuComponents = (_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
120
+ var anyComponentVisible = hasVisibleButton(pasteMenuComponents);
121
121
  if (!isToolbarShown) {
122
122
  return null;
123
123
  }
124
- if (!showLegacyOptions && !anyAiComponentVisible) {
124
+ if (!anyComponentVisible) {
125
125
  return null;
126
126
  }
127
127
  var target = getTargetElement(editorView);
@@ -147,8 +147,6 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
147
147
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
148
148
  onMouseDown: preventEditorFocusLoss,
149
149
  onMouseEnter: handleMouseEnter,
150
- aiSurface: aiSurface,
151
- aiSurfaceComponents: aiSurfaceComponents,
152
- pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
150
+ components: pasteMenuComponents
153
151
  }))));
154
152
  };
@@ -2,7 +2,10 @@
2
2
  import "./PasteActionsMenuContent.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useContext } from 'react';
5
+ import { useIntl } from 'react-intl-next';
6
+ import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
5
7
  import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
8
+ import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
6
9
  import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
7
10
  import { Box } from '@atlaskit/primitives/compiled';
8
11
  var styles = {
@@ -11,23 +14,21 @@ var styles = {
11
14
  export var PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
12
15
  var onMouseDown = _ref.onMouseDown,
13
16
  onMouseEnter = _ref.onMouseEnter,
14
- aiSurface = _ref.aiSurface,
15
- aiSurfaceComponents = _ref.aiSurfaceComponents,
16
- pasteSurfaceComponents = _ref.pasteSurfaceComponents;
17
+ components = _ref.components;
17
18
  var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
19
+ var intl = useIntl();
18
20
  return /*#__PURE__*/React.createElement(Box, {
19
21
  ref: setOutsideClickTargetRef,
20
22
  xcss: styles.container,
21
23
  onMouseDown: onMouseDown,
22
24
  onMouseEnter: onMouseEnter
23
- }, aiSurface && aiSurfaceComponents && aiSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
24
- surface: aiSurface,
25
- components: aiSurfaceComponents
26
- }), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
25
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
26
+ title: intl.formatMessage(messages.pasteMenuActionsTitle)
27
+ }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
27
28
  surface: {
28
29
  type: 'menu',
29
30
  key: 'paste-menu'
30
31
  },
31
- components: pasteSurfaceComponents
32
- }));
32
+ components: components
33
+ })));
33
34
  };
@@ -29,12 +29,13 @@ export var isPasteOptionSelected = function isPasteOptionSelected(pasteType, sel
29
29
  }
30
30
  };
31
31
  var PasteMenuItem = function PasteMenuItem(_ref) {
32
+ var _api$analytics;
32
33
  var api = _ref.api,
33
- editorAnalyticsAPI = _ref.editorAnalyticsAPI,
34
34
  pasteType = _ref.pasteType;
35
35
  var intl = useIntl();
36
36
  var _useEditorToolbar = useEditorToolbar(),
37
37
  editorView = _useEditorToolbar.editorView;
38
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
38
39
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
39
40
  var _pluginState$selected, _pluginState$plaintex, _pluginState$isPlainT;
40
41
  var pluginState = states.pasteOptionsToolbarPluginState;
@@ -105,8 +106,7 @@ var PasteOptionsNestedMenu = function PasteOptionsNestedMenu(_ref2) {
105
106
  }, children);
106
107
  };
107
108
  export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
108
- var api = _ref3.api,
109
- editorAnalyticsAPI = _ref3.editorAnalyticsAPI;
109
+ var api = _ref3.api;
110
110
  return [{
111
111
  type: PASTE_MENU.type,
112
112
  key: PASTE_MENU.key
@@ -118,6 +118,11 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
118
118
  key: PASTE_MENU.key,
119
119
  rank: PASTE_MENU_RANK[PASTE_MENU_SECTION.key]
120
120
  }],
121
+ isHidden: function isHidden() {
122
+ var _api$pasteOptionsTool, _pluginState$showLega;
123
+ var pluginState = api === null || api === void 0 || (_api$pasteOptionsTool = api.pasteOptionsToolbarPlugin) === null || _api$pasteOptionsTool === void 0 ? void 0 : _api$pasteOptionsTool.sharedState.currentState();
124
+ return !((_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false);
125
+ },
121
126
  component: function component(props) {
122
127
  return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
123
128
  hasSeparator: true
@@ -153,7 +158,6 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
153
158
  component: function component() {
154
159
  return /*#__PURE__*/React.createElement(PasteMenuItem, {
155
160
  api: api,
156
- editorAnalyticsAPI: editorAnalyticsAPI,
157
161
  pasteType: "rich-text"
158
162
  });
159
163
  },
@@ -168,7 +172,6 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
168
172
  component: function component() {
169
173
  return /*#__PURE__*/React.createElement(PasteMenuItem, {
170
174
  api: api,
171
- editorAnalyticsAPI: editorAnalyticsAPI,
172
175
  pasteType: "markdown"
173
176
  });
174
177
  },
@@ -183,7 +186,6 @@ export var getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
183
186
  component: function component() {
184
187
  return /*#__PURE__*/React.createElement(PasteMenuItem, {
185
188
  api: api,
186
- editorAnalyticsAPI: editorAnalyticsAPI,
187
189
  pasteType: "plain-text"
188
190
  });
189
191
  },
@@ -0,0 +1,36 @@
1
+ var _isComponentOrAncestorHidden = function isComponentOrAncestorHidden(component, componentsByKey) {
2
+ var _component$isHidden, _component$parents;
3
+ if ((_component$isHidden = component.isHidden) !== null && _component$isHidden !== void 0 && _component$isHidden.call(component)) {
4
+ return true;
5
+ }
6
+ return ((_component$parents = component.parents) !== null && _component$parents !== void 0 ? _component$parents : []).some(function (parent) {
7
+ var parentComponent = componentsByKey.get(parent.key);
8
+ return parentComponent ? _isComponentOrAncestorHidden(parentComponent, componentsByKey) : false;
9
+ });
10
+ };
11
+
12
+ /**
13
+ * Returns the keys of visible button/menu-item components in the list.
14
+ * A component is visible when neither it nor any of its ancestors are hidden.
15
+ */
16
+ export var getVisibleKeys = function getVisibleKeys(components) {
17
+ var types = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['menu-item'];
18
+ var componentsByKey = new Map(components.map(function (c) {
19
+ return [c.key, c];
20
+ }));
21
+ return components.filter(function (c) {
22
+ return types.includes(c.type);
23
+ }).filter(function (c) {
24
+ return !_isComponentOrAncestorHidden(c, componentsByKey);
25
+ }).map(function (c) {
26
+ return c.key;
27
+ });
28
+ };
29
+
30
+ /**
31
+ * Returns true when at least one menu-item button in the list is visible.
32
+ * A button is visible when neither it nor any of its ancestors are hidden.
33
+ */
34
+ export var hasVisibleButton = function hasVisibleButton(components) {
35
+ return getVisibleKeys(components).length > 0;
36
+ };
@@ -5,12 +5,12 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import { ToolbarDropdownOption } from '../types/types';
6
6
  export declare const showToolbar: (lastContentPasted: LastContentPasted, selectedOption: ToolbarDropdownOption, showLegacyOptions?: boolean, pasteAncestorNodeNames?: string[]) => Command;
7
7
  export declare const changeToPlainText: () => Command;
8
- export declare const changeToPlainTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => () => Command;
8
+ export declare const changeToPlainTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number, invokedFrom?: string) => () => Command;
9
9
  export declare const dropdownClickHandler: () => Command;
10
10
  export declare const changeToRichText: () => Command;
11
- export declare const changeToRichTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => () => Command;
11
+ export declare const changeToRichTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, invokedFrom?: string) => () => Command;
12
12
  export declare const changeToMarkDown: () => Command;
13
- export declare const changeToMarkdownWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => () => Command;
13
+ export declare const changeToMarkdownWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number, invokedFrom?: string) => () => Command;
14
14
  export declare const highlightContent: () => Command;
15
15
  export declare const hideToolbar: () => Command;
16
16
  export declare const checkAndHideToolbar: (view: EditorView) => void;
@@ -1,11 +1,9 @@
1
1
  import React from 'react';
2
- import type { RegisterComponent, SurfaceIdentifier } from '@atlaskit/editor-ui-control-model';
2
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
3
3
  interface PasteActionsMenuContentProps {
4
- aiSurface?: SurfaceIdentifier;
5
- aiSurfaceComponents?: RegisterComponent[];
4
+ components: RegisterComponent[];
6
5
  onMouseDown: (e: React.MouseEvent) => void;
7
6
  onMouseEnter: () => void;
8
- pasteSurfaceComponents?: RegisterComponent[];
9
7
  }
10
- export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, aiSurface, aiSurfaceComponents, pasteSurfaceComponents, }: PasteActionsMenuContentProps) => React.JSX.Element;
8
+ export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, components, }: PasteActionsMenuContentProps) => React.JSX.Element;
11
9
  export {};
@@ -1,4 +1,3 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
2
  import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
4
3
  import type { PasteOptionsToolbarPlugin } from '../../pasteOptionsToolbarPluginType';
@@ -6,7 +5,6 @@ import { ToolbarDropdownOption, type PasteType } from '../../types/types';
6
5
  export declare const isPasteOptionSelected: (pasteType: PasteType, selectedOption: ToolbarDropdownOption) => boolean;
7
6
  interface PasteMenuComponentsConfig {
8
7
  api: ExtractInjectionAPI<PasteOptionsToolbarPlugin> | undefined;
9
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
10
8
  }
11
- export declare const getPasteMenuComponents: ({ api, editorAnalyticsAPI, }: PasteMenuComponentsConfig) => RegisterComponent[];
9
+ export declare const getPasteMenuComponents: ({ api, }: PasteMenuComponentsConfig) => RegisterComponent[];
12
10
  export {};
@@ -0,0 +1,11 @@
1
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
2
+ /**
3
+ * Returns the keys of visible button/menu-item components in the list.
4
+ * A component is visible when neither it nor any of its ancestors are hidden.
5
+ */
6
+ export declare const getVisibleKeys: (components: RegisterComponent[], types?: RegisterComponent["type"][]) => string[];
7
+ /**
8
+ * Returns true when at least one menu-item button in the list is visible.
9
+ * A button is visible when neither it nor any of its ancestors are hidden.
10
+ */
11
+ export declare const hasVisibleButton: (components: RegisterComponent[]) => boolean;
@@ -5,12 +5,12 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
5
  import { ToolbarDropdownOption } from '../types/types';
6
6
  export declare const showToolbar: (lastContentPasted: LastContentPasted, selectedOption: ToolbarDropdownOption, showLegacyOptions?: boolean, pasteAncestorNodeNames?: string[]) => Command;
7
7
  export declare const changeToPlainText: () => Command;
8
- export declare const changeToPlainTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => () => Command;
8
+ export declare const changeToPlainTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number, invokedFrom?: string) => () => Command;
9
9
  export declare const dropdownClickHandler: () => Command;
10
10
  export declare const changeToRichText: () => Command;
11
- export declare const changeToRichTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => () => Command;
11
+ export declare const changeToRichTextWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, invokedFrom?: string) => () => Command;
12
12
  export declare const changeToMarkDown: () => Command;
13
- export declare const changeToMarkdownWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number) => () => Command;
13
+ export declare const changeToMarkdownWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, sliceSize: number, invokedFrom?: string) => () => Command;
14
14
  export declare const highlightContent: () => Command;
15
15
  export declare const hideToolbar: () => Command;
16
16
  export declare const checkAndHideToolbar: (view: EditorView) => void;
@@ -1,11 +1,9 @@
1
1
  import React from 'react';
2
- import type { RegisterComponent, SurfaceIdentifier } from '@atlaskit/editor-ui-control-model';
2
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
3
3
  interface PasteActionsMenuContentProps {
4
- aiSurface?: SurfaceIdentifier;
5
- aiSurfaceComponents?: RegisterComponent[];
4
+ components: RegisterComponent[];
6
5
  onMouseDown: (e: React.MouseEvent) => void;
7
6
  onMouseEnter: () => void;
8
- pasteSurfaceComponents?: RegisterComponent[];
9
7
  }
10
- export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, aiSurface, aiSurfaceComponents, pasteSurfaceComponents, }: PasteActionsMenuContentProps) => React.JSX.Element;
8
+ export declare const PasteActionsMenuContent: ({ onMouseDown, onMouseEnter, components, }: PasteActionsMenuContentProps) => React.JSX.Element;
11
9
  export {};
@@ -1,4 +1,3 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
2
  import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
4
3
  import type { PasteOptionsToolbarPlugin } from '../../pasteOptionsToolbarPluginType';
@@ -6,7 +5,6 @@ import { ToolbarDropdownOption, type PasteType } from '../../types/types';
6
5
  export declare const isPasteOptionSelected: (pasteType: PasteType, selectedOption: ToolbarDropdownOption) => boolean;
7
6
  interface PasteMenuComponentsConfig {
8
7
  api: ExtractInjectionAPI<PasteOptionsToolbarPlugin> | undefined;
9
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
10
8
  }
11
- export declare const getPasteMenuComponents: ({ api, editorAnalyticsAPI, }: PasteMenuComponentsConfig) => RegisterComponent[];
9
+ export declare const getPasteMenuComponents: ({ api, }: PasteMenuComponentsConfig) => RegisterComponent[];
12
10
  export {};
@@ -0,0 +1,11 @@
1
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
2
+ /**
3
+ * Returns the keys of visible button/menu-item components in the list.
4
+ * A component is visible when neither it nor any of its ancestors are hidden.
5
+ */
6
+ export declare const getVisibleKeys: (components: RegisterComponent[], types?: RegisterComponent["type"][]) => string[];
7
+ /**
8
+ * Returns true when at least one menu-item button in the list is visible.
9
+ * A button is visible when neither it nor any of its ancestors are hidden.
10
+ */
11
+ export declare const hasVisibleButton: (components: RegisterComponent[]) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste-options-toolbar",
3
- "version": "8.4.0",
3
+ "version": "9.0.0",
4
4
  "description": "Paste options toolbar for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@atlaskit/css": "^0.19.0",
33
33
  "@atlaskit/editor-markdown-transformer": "^5.20.0",
34
- "@atlaskit/editor-plugin-analytics": "^7.0.0",
35
- "@atlaskit/editor-plugin-paste": "^8.6.0",
36
- "@atlaskit/editor-plugin-ui-control-registry": "^1.1.0",
34
+ "@atlaskit/editor-plugin-analytics": "^8.0.0",
35
+ "@atlaskit/editor-plugin-paste": "^9.0.0",
36
+ "@atlaskit/editor-plugin-ui-control-registry": "^2.0.0",
37
37
  "@atlaskit/editor-prosemirror": "^7.3.0",
38
38
  "@atlaskit/editor-shared-styles": "^3.10.0",
39
39
  "@atlaskit/editor-toolbar": "^0.19.0",
@@ -41,15 +41,15 @@
41
41
  "@atlaskit/icon": "^32.0.0",
42
42
  "@atlaskit/platform-feature-flags": "^1.1.0",
43
43
  "@atlaskit/primitives": "^18.0.0",
44
- "@atlaskit/tmp-editor-statsig": "^35.4.0",
45
- "@atlaskit/tokens": "^11.0.0",
44
+ "@atlaskit/tmp-editor-statsig": "^35.10.0",
45
+ "@atlaskit/tokens": "^11.1.0",
46
46
  "@babel/runtime": "^7.0.0",
47
47
  "@compiled/react": "^0.20.0",
48
48
  "@emotion/react": "^11.7.1",
49
49
  "react-intl-next": "npm:react-intl@^5.18.1"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atlaskit/editor-common": "^111.31.0",
52
+ "@atlaskit/editor-common": "^112.0.0",
53
53
  "react": "^18.2.0",
54
54
  "react-dom": "^18.2.0"
55
55
  },