@atlaskit/editor-plugin-paste-options-toolbar 8.2.4 → 8.4.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 (45) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/editor-commands/commands.js +5 -1
  3. package/dist/cjs/pasteOptionsToolbarPlugin.js +44 -35
  4. package/dist/cjs/pm-plugins/main.js +16 -9
  5. package/dist/cjs/pm-plugins/reducer.js +2 -0
  6. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +81 -60
  7. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  8. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -13
  9. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  10. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +205 -0
  11. package/dist/es2019/editor-commands/commands.js +4 -2
  12. package/dist/es2019/pasteOptionsToolbarPlugin.js +41 -28
  13. package/dist/es2019/pm-plugins/main.js +12 -5
  14. package/dist/es2019/pm-plugins/reducer.js +2 -0
  15. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +82 -62
  16. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  17. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +11 -12
  18. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  19. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +187 -0
  20. package/dist/esm/editor-commands/commands.js +5 -1
  21. package/dist/esm/pasteOptionsToolbarPlugin.js +44 -34
  22. package/dist/esm/pm-plugins/main.js +12 -5
  23. package/dist/esm/pm-plugins/reducer.js +2 -0
  24. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +84 -63
  25. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  26. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +11 -14
  27. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  28. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +196 -0
  29. package/dist/types/editor-actions/actions.d.ts +2 -0
  30. package/dist/types/editor-commands/commands.d.ts +1 -1
  31. package/dist/types/pasteOptionsToolbarPluginType.d.ts +3 -0
  32. package/dist/types/pm-plugins/main.d.ts +3 -1
  33. package/dist/types/types/types.d.ts +3 -0
  34. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +1 -3
  35. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -8
  36. package/dist/types/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +12 -0
  37. package/dist/types-ts4.5/editor-actions/actions.d.ts +2 -0
  38. package/dist/types-ts4.5/editor-commands/commands.d.ts +1 -1
  39. package/dist/types-ts4.5/pasteOptionsToolbarPluginType.d.ts +3 -0
  40. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
  41. package/dist/types-ts4.5/types/types.d.ts +3 -0
  42. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +1 -3
  43. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -8
  44. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +12 -0
  45. package/package.json +6 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 8.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`8cb8a3e42b2c2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8cb8a3e42b2c2) -
8
+ [ux] EDITOR-5668 Introducing configurable visibility rules to determine which AI actions should
9
+ display in on-paste menu
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 8.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [`d7675f084fe05`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d7675f084fe05) -
20
+ [ux] [EDITOR-5669] refactored existing paste actions menu to use control registry and platform
21
+ toolbars
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies
26
+
3
27
  ## 8.2.4
4
28
 
5
29
  ### Patch Changes
@@ -11,6 +11,8 @@ var _pluginFactory = require("../pm-plugins/plugin-factory");
11
11
  var _formatHandlers = require("../pm-plugins/util/format-handlers");
12
12
  var _types = require("../types/types");
13
13
  var showToolbar = exports.showToolbar = function showToolbar(lastContentPasted, selectedOption) {
14
+ var showLegacyOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
15
+ var pasteAncestorNodeNames = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
14
16
  var commandAction = function commandAction(_editorState) {
15
17
  var _lastContentPasted$te;
16
18
  return {
@@ -21,7 +23,9 @@ var showToolbar = exports.showToolbar = function showToolbar(lastContentPasted,
21
23
  isPlainText: lastContentPasted.isPlainText,
22
24
  richTextSlice: lastContentPasted.pastedSlice,
23
25
  pasteStartPos: lastContentPasted.pasteStartPos,
24
- pasteEndPos: lastContentPasted.pasteEndPos
26
+ pasteEndPos: lastContentPasted.pasteEndPos,
27
+ showLegacyOptions: showLegacyOptions,
28
+ pasteAncestorNodeNames: pasteAncestorNodeNames
25
29
  }
26
30
  };
27
31
  };
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.pasteOptionsToolbarPlugin = void 0;
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
8
  var _react = _interopRequireWildcard(require("react"));
11
9
  var _hooks = require("@atlaskit/editor-common/hooks");
12
10
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
@@ -14,50 +12,59 @@ var _commands = require("./editor-commands/commands");
14
12
  var _main = require("./pm-plugins/main");
15
13
  var _types = require("./types/types");
16
14
  var _PasteActionsMenu = require("./ui/on-paste-actions-menu/PasteActionsMenu");
15
+ var _PasteMenuComponents = require("./ui/on-paste-actions-menu/PasteMenuComponents");
17
16
  var _toolbar = require("./ui/toolbar");
18
17
  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
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
18
  var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref) {
22
19
  var _api$analytics;
23
20
  var api = _ref.api;
24
21
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
25
- var getSharedState = function getSharedState(editorState) {
26
- var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
27
- if (!editorState) {
28
- return {
29
- isPlainText: false,
30
- pasteEndPos: 0,
31
- pasteStartPos: 0,
32
- plaintextLength: 0,
33
- selectedOption: _types.ToolbarDropdownOption.None,
34
- showToolbar: false
35
- };
36
- }
37
- var pluginState = _types.pasteOptionsPluginKey.getState(editorState);
38
- return {
39
- isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
40
- pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0,
41
- pasteStartPos: (_pluginState$pasteSta = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteStartPos) !== null && _pluginState$pasteSta !== void 0 ? _pluginState$pasteSta : 0,
42
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
43
- selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
44
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
45
- };
46
- };
47
- return _objectSpread(_objectSpread({
22
+ if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
23
+ var _api$uiControlRegistr;
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
27
+ }));
28
+ }
29
+ return {
48
30
  name: 'pasteOptionsToolbarPlugin',
49
31
  pmPlugins: function pmPlugins() {
50
32
  return [{
51
33
  name: 'pasteOptionsToolbarPlugin',
52
34
  plugin: function plugin(_ref2) {
53
35
  var dispatch = _ref2.dispatch;
54
- return (0, _main.createPlugin)(dispatch);
36
+ return (0, _main.createPlugin)(dispatch, {
37
+ useNewPasteMenu: (0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)
38
+ });
55
39
  }
56
40
  }];
57
- }
58
- }, (0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
59
- getSharedState: getSharedState
60
- } : {}), {}, {
41
+ },
42
+ getSharedState: function getSharedState(editorState) {
43
+ var _pluginState$isPlainT, _pluginState$pasteAnc, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showLega, _pluginState$showTool;
44
+ if (!editorState) {
45
+ return {
46
+ isPlainText: false,
47
+ pasteAncestorNodeNames: [],
48
+ pasteEndPos: 0,
49
+ pasteStartPos: 0,
50
+ plaintextLength: 0,
51
+ selectedOption: _types.ToolbarDropdownOption.None,
52
+ showLegacyOptions: false,
53
+ showToolbar: false
54
+ };
55
+ }
56
+ var pluginState = _types.pasteOptionsPluginKey.getState(editorState);
57
+ return {
58
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
59
+ pasteAncestorNodeNames: (_pluginState$pasteAnc = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteAncestorNodeNames) !== null && _pluginState$pasteAnc !== void 0 ? _pluginState$pasteAnc : [],
60
+ pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0,
61
+ pasteStartPos: (_pluginState$pasteSta = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteStartPos) !== null && _pluginState$pasteSta !== void 0 ? _pluginState$pasteSta : 0,
62
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
63
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
64
+ showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false,
65
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
66
+ };
67
+ },
61
68
  pluginsOptions: {
62
69
  floatingToolbar: function floatingToolbar(state, intl) {
63
70
  if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
@@ -83,8 +90,7 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
83
90
  editorView: editorView,
84
91
  mountTo: popupsMountPoint,
85
92
  boundariesElement: popupsBoundariesElement,
86
- scrollableElement: popupsScrollableElement,
87
- editorAnalyticsAPI: editorAnalyticsAPI
93
+ scrollableElement: popupsScrollableElement
88
94
  });
89
95
  },
90
96
  usePluginHook: function usePluginHook(_ref4) {
@@ -97,6 +103,9 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
97
103
  }),
98
104
  lastContentPasted = _useSharedPluginState.lastContentPasted;
99
105
  (0, _react.useEffect)(function () {
106
+ if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
107
+ return;
108
+ }
100
109
  if (!lastContentPasted) {
101
110
  (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
102
111
  return;
@@ -115,5 +124,5 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
115
124
  (0, _commands.showToolbar)(lastContentPasted, selectedOption)(editorView.state, editorView.dispatch);
116
125
  }, [lastContentPasted, editorView]);
117
126
  }
118
- });
127
+ };
119
128
  };
@@ -6,36 +6,43 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createPlugin = createPlugin;
7
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _model = require("@atlaskit/editor-prosemirror/model");
9
- var _view = require("@atlaskit/editor-prosemirror/view");
9
+ var _view2 = require("@atlaskit/editor-prosemirror/view");
10
10
  var _commands = require("../editor-commands/commands");
11
11
  var _types = require("../types/types");
12
12
  var _constants = require("./constants");
13
13
  var _pluginFactory = require("./plugin-factory");
14
- function createPlugin(dispatch) {
14
+ function createPlugin(dispatch, options) {
15
15
  return new _safePlugin.SafePlugin({
16
16
  key: _types.pasteOptionsPluginKey,
17
17
  state: (0, _pluginFactory.createPluginState)(dispatch, {
18
18
  showToolbar: false,
19
+ showLegacyOptions: false,
20
+ pasteAncestorNodeNames: [],
19
21
  pasteStartPos: 0,
20
22
  pasteEndPos: 0,
21
23
  plaintext: '',
22
24
  isPlainText: false,
23
25
  highlightContent: false,
24
- highlightDecorationSet: _view.DecorationSet.empty,
26
+ highlightDecorationSet: _view2.DecorationSet.empty,
25
27
  richTextSlice: _model.Slice.empty,
26
28
  selectedOption: _types.ToolbarDropdownOption.None
27
29
  }),
28
- view: function view(editorView) {
30
+ view: function view(_editorView) {
29
31
  return {
30
- update: function update(view, prevState) {
32
+ update: function update(_view, prevState) {
31
33
  return prevState;
32
34
  }
33
35
  };
34
36
  },
35
37
  props: {
36
38
  handleDOMEvents: {
37
- // Hide toolbar when clicked outside the editor
38
- blur: _commands.checkAndHideToolbar,
39
+ blur: function blur(view) {
40
+ if (options !== null && options !== void 0 && options.useNewPasteMenu) {
41
+ return false;
42
+ }
43
+ (0, _commands.checkAndHideToolbar)(view);
44
+ return false;
45
+ },
39
46
  // Hide toolbar when clicked anywhere within the editor, tr.getMeta('pointer') does not work if clicked on the same line after pasting so relying on mousedown event
40
47
  mousedown: _commands.checkAndHideToolbar
41
48
  },
@@ -48,13 +55,13 @@ function createPlugin(dispatch) {
48
55
  var _ref = _types.pasteOptionsPluginKey.getState(state) || {},
49
56
  highlightContent = _ref.highlightContent,
50
57
  pasteStartPos = _ref.pasteStartPos;
51
- var decorationSet = (_pasteOptionsPluginKe = (_pasteOptionsPluginKe2 = _types.pasteOptionsPluginKey.getState(state)) === null || _pasteOptionsPluginKe2 === void 0 ? void 0 : _pasteOptionsPluginKe2.highlightDecorationSet) !== null && _pasteOptionsPluginKe !== void 0 ? _pasteOptionsPluginKe : _view.DecorationSet.empty;
58
+ var decorationSet = (_pasteOptionsPluginKe = (_pasteOptionsPluginKe2 = _types.pasteOptionsPluginKey.getState(state)) === null || _pasteOptionsPluginKe2 === void 0 ? void 0 : _pasteOptionsPluginKe2.highlightDecorationSet) !== null && _pasteOptionsPluginKe !== void 0 ? _pasteOptionsPluginKe : _view2.DecorationSet.empty;
52
59
  if (!highlightContent) {
53
60
  return decorationSet;
54
61
  }
55
62
  var selection = state.tr.selection;
56
63
  var pasteEndPos = selection.$anchor.pos;
57
- var highlightDecoration = _view.Decoration.inline(pasteStartPos, pasteEndPos, {
64
+ var highlightDecoration = _view2.Decoration.inline(pasteStartPos, pasteEndPos, {
58
65
  class: _constants.TEXT_HIGHLIGHT_CLASS
59
66
  }, {
60
67
  key: _constants.PASTE_HIGHLIGHT_DECORATION_KEY
@@ -15,6 +15,8 @@ var reducer = exports.reducer = function reducer(state, action) {
15
15
  {
16
16
  return _objectSpread(_objectSpread({}, state), {}, {
17
17
  showToolbar: true,
18
+ showLegacyOptions: action.data.showLegacyOptions,
19
+ pasteAncestorNodeNames: action.data.pasteAncestorNodeNames,
18
20
  highlightContent: false,
19
21
  isPlainText: action.data.isPlainText,
20
22
  plaintext: action.data.plaintext,
@@ -6,16 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.PasteActionsMenu = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactIntlNext = require("react-intl-next");
10
9
  var _hooks = require("@atlaskit/editor-common/hooks");
11
- var _messages = require("@atlaskit/editor-common/messages");
12
10
  var _toolbar = require("@atlaskit/editor-common/toolbar");
13
11
  var _ui = require("@atlaskit/editor-common/ui");
14
12
  var _uiReact = require("@atlaskit/editor-common/ui-react");
15
13
  var _utils = require("@atlaskit/editor-prosemirror/utils");
16
14
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
15
+ 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
+ var _toolbar2 = require("../toolbar");
19
20
  var _PasteActionsMenuContent = require("./PasteActionsMenuContent");
20
21
  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); }
21
22
  var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
@@ -38,29 +39,63 @@ function getPopupOffset(dom) {
38
39
  var rightEdge = dom.getBoundingClientRect().right;
39
40
  return [-(window.innerWidth - rightEdge - 50), 20];
40
41
  }
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
+ };
41
54
  var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
42
- var _api$uiControlRegistr, _api$uiControlRegistr2;
55
+ var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
43
56
  var api = _ref.api,
44
57
  editorView = _ref.editorView,
45
58
  mountTo = _ref.mountTo,
46
59
  boundariesElement = _ref.boundariesElement,
47
- scrollableElement = _ref.scrollableElement,
48
- editorAnalyticsAPI = _ref.editorAnalyticsAPI;
49
- var intl = (0, _reactIntlNext.useIntl)();
50
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
51
- var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
60
+ scrollableElement = _ref.scrollableElement;
61
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['paste'], function (states) {
62
+ var _states$pasteState;
63
+ return {
64
+ lastContentPasted: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.lastContentPasted
65
+ };
66
+ }),
67
+ lastContentPasted = _useSharedPluginState.lastContentPasted;
68
+ (0, _react.useEffect)(function () {
69
+ if (!lastContentPasted) {
70
+ (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
71
+ return;
72
+ }
73
+ var selectedOption = _types.ToolbarDropdownOption.None;
74
+ if (!lastContentPasted.isPlainText) {
75
+ selectedOption = _types.ToolbarDropdownOption.RichText;
76
+ } else if (lastContentPasted.isShiftPressed) {
77
+ selectedOption = _types.ToolbarDropdownOption.PlainText;
78
+ } else {
79
+ selectedOption = _types.ToolbarDropdownOption.Markdown;
80
+ }
81
+ var $pos = editorView.state.doc.resolve(lastContentPasted.pasteStartPos);
82
+ var pasteAncestorNodeNames = [];
83
+ for (var depth = $pos.depth; depth > 0; depth--) {
84
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
85
+ }
86
+ var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted);
87
+ (0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
88
+ }, [lastContentPasted, editorView]);
89
+ var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
90
+ var _pluginState$showTool, _pluginState$showLega;
52
91
  var pluginState = states.pasteOptionsToolbarPluginState;
53
92
  return {
54
93
  showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
55
- isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
56
- selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
57
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0
94
+ showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
58
95
  };
59
96
  }),
60
- showToolbar = _useSharedPluginState.showToolbar,
61
- isPlainText = _useSharedPluginState.isPlainText,
62
- selectedOption = _useSharedPluginState.selectedOption,
63
- plaintextLength = _useSharedPluginState.plaintextLength;
97
+ isToolbarShown = _useSharedPluginState2.showToolbar,
98
+ showLegacyOptions = _useSharedPluginState2.showLegacyOptions;
64
99
  var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
65
100
  e.preventDefault();
66
101
  }, []);
@@ -70,54 +105,37 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
70
105
  var handleMouseEnter = (0, _react.useCallback)(function () {
71
106
  (0, _commands.highlightContent)()(editorView.state, editorView.dispatch);
72
107
  }, [editorView]);
73
- var handleRichText = (0, _react.useCallback)(function (e) {
74
- e.preventDefault();
75
- (0, _commands.changeToRichTextWithAnalytics)(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
76
- }, [editorView, editorAnalyticsAPI]);
77
- var handleMarkdown = (0, _react.useCallback)(function (e) {
78
- e.preventDefault();
79
- (0, _commands.changeToMarkdownWithAnalytics)(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
80
- }, [editorView, editorAnalyticsAPI, plaintextLength]);
81
- var handlePlainText = (0, _react.useCallback)(function (e) {
82
- e.preventDefault();
83
- (0, _commands.changeToPlainTextWithAnalytics)(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
84
- }, [editorView, editorAnalyticsAPI, plaintextLength]);
85
- var options = (0, _react.useMemo)(function () {
86
- var items = [];
87
- if (!isPlainText) {
88
- items.push({
89
- id: 'editor.paste.richText',
90
- label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.richText),
91
- selected: selectedOption === _types.ToolbarDropdownOption.RichText,
92
- onClick: handleRichText
93
- });
108
+ var handleClickOutside = (0, _react.useCallback)(function (evt) {
109
+ if (evt.target instanceof Element) {
110
+ var isInsideNestedDropdown = evt.target.closest('[data-toolbar-nested-dropdown-menu]');
111
+ if (isInsideNestedDropdown) {
112
+ return;
113
+ }
114
+ }
115
+ handleDismiss();
116
+ }, [handleDismiss]);
117
+ var handleSetIsOpen = (0, _react.useCallback)(function (isOpen) {
118
+ if (!isOpen) {
119
+ handleDismiss();
94
120
  }
95
- items.push({
96
- id: 'editor.paste.markdown',
97
- label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.markdown),
98
- selected: selectedOption === _types.ToolbarDropdownOption.Markdown,
99
- onClick: handleMarkdown
100
- });
101
- items.push({
102
- id: 'editor.paste.plainText',
103
- label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.plainText),
104
- selected: selectedOption === _types.ToolbarDropdownOption.PlainText,
105
- onClick: handlePlainText
106
- });
107
- return items;
108
- }, [isPlainText, selectedOption, intl, handleRichText, handleMarkdown, handlePlainText]);
109
- if (!showToolbar) {
121
+ }, [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);
129
+ if (!isToolbarShown) {
130
+ return null;
131
+ }
132
+ if (!showLegacyOptions && !anyAiComponentVisible) {
110
133
  return null;
111
134
  }
112
135
  var target = getTargetElement(editorView);
113
136
  if (!target) {
114
137
  return null;
115
138
  }
116
- var aiSurface = {
117
- type: 'menu',
118
- key: 'ai-paste-menu'
119
- };
120
- 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 : [];
121
139
  return /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
122
140
  target: target,
123
141
  mountTo: mountTo,
@@ -127,15 +145,18 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
127
145
  zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex,
128
146
  alignX: "right",
129
147
  alignY: "bottom",
130
- handleClickOutside: handleDismiss,
148
+ handleClickOutside: handleClickOutside,
131
149
  handleEscapeKeydown: handleDismiss
132
150
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
133
151
  editorView: editorView
152
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenuProvider, {
153
+ isOpen: isToolbarShown,
154
+ setIsOpen: handleSetIsOpen
134
155
  }, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
135
- options: options,
136
156
  onMouseDown: preventEditorFocusLoss,
137
157
  onMouseEnter: handleMouseEnter,
138
158
  aiSurface: aiSurface,
139
- aiSurfaceComponents: aiSurfaceComponents
140
- })));
159
+ aiSurfaceComponents: aiSurfaceComponents,
160
+ pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
161
+ }))));
141
162
  };
@@ -1,10 +1,4 @@
1
1
 
2
2
  ._2rko12b0{border-radius:var(--ds-radius-small,4px)}
3
- ._18zrpxbi{padding-inline:var(--ds-space-200,1pc)}
4
- ._1rjc1b66{padding-block:var(--ds-space-050,4px)}
5
- ._1rjcu2gc{padding-block:var(--ds-space-100,8px)}._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
6
- ._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
7
- ._bfhksm61{background-color:var(--ds-background-neutral-subtle,#00000000)}
8
- ._k48pwu06{font-weight:var(--ds-font-weight-bold,653)}
9
- ._syazi7uo{color:var(--ds-text,#292a2e)}
10
- ._irr31dpa:hover{background-color:var(--ds-background-neutral-subtle-hovered,#0515240f)}
3
+ ._1rjc1b66{padding-block:var(--ds-space-050,4px)}._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
4
+ ._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
@@ -9,22 +9,19 @@ 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 _css = require("@atlaskit/css");
13
12
  var _uiReact = require("@atlaskit/editor-common/ui-react");
14
13
  var _editorUiControlModel = require("@atlaskit/editor-ui-control-model");
15
14
  var _compiled = require("@atlaskit/primitives/compiled");
16
15
  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); }
17
16
  var styles = {
18
- container: "_2rko12b0 _1rjc1b66 _bfhk1bhr _16qs130s",
19
- option: "_1rjcu2gc _18zrpxbi _syazi7uo _bfhksm61 _irr31dpa",
20
- selectedOption: "_k48pwu06"
17
+ container: "_2rko12b0 _1rjc1b66 _bfhk1bhr _16qs130s"
21
18
  };
22
19
  var PasteActionsMenuContent = exports.PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
23
- var options = _ref.options,
24
- onMouseDown = _ref.onMouseDown,
20
+ var onMouseDown = _ref.onMouseDown,
25
21
  onMouseEnter = _ref.onMouseEnter,
26
22
  aiSurface = _ref.aiSurface,
27
- aiSurfaceComponents = _ref.aiSurfaceComponents;
23
+ aiSurfaceComponents = _ref.aiSurfaceComponents,
24
+ pasteSurfaceComponents = _ref.pasteSurfaceComponents;
28
25
  var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
29
26
  return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
30
27
  ref: setOutsideClickTargetRef,
@@ -34,11 +31,11 @@ var PasteActionsMenuContent = exports.PasteActionsMenuContent = function PasteAc
34
31
  }, aiSurface && aiSurfaceComponents && aiSurfaceComponents.length > 0 && /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
35
32
  surface: aiSurface,
36
33
  components: aiSurfaceComponents
37
- }), options.map(function (option) {
38
- return /*#__PURE__*/_react.default.createElement(_compiled.Pressable, {
39
- key: option.id,
40
- xcss: (0, _css.cx)(styles.option, option.selected && styles.selectedOption),
41
- onClick: option.onClick
42
- }, option.label);
34
+ }), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/_react.default.createElement(_editorUiControlModel.SurfaceRenderer, {
35
+ surface: {
36
+ type: 'menu',
37
+ key: 'paste-menu'
38
+ },
39
+ components: pasteSurfaceComponents
43
40
  }));
44
41
  };
@@ -0,0 +1 @@
1
+ ._10gv1lit button{min-width:10pc}