@atlaskit/editor-plugin-paste-options-toolbar 8.3.0 → 8.4.1

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 (38) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/cjs/editor-commands/commands.js +5 -1
  3. package/dist/cjs/pasteOptionsToolbarPlugin.js +32 -32
  4. package/dist/cjs/pm-plugins/main.js +7 -5
  5. package/dist/cjs/pm-plugins/reducer.js +2 -0
  6. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +42 -14
  7. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
  8. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +5 -0
  9. package/dist/cjs/ui/on-paste-actions-menu/hasVisibleButton.js +31 -0
  10. package/dist/es2019/editor-commands/commands.js +4 -2
  11. package/dist/es2019/pasteOptionsToolbarPlugin.js +29 -25
  12. package/dist/es2019/pm-plugins/main.js +3 -1
  13. package/dist/es2019/pm-plugins/reducer.js +2 -0
  14. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +44 -15
  15. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
  16. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +5 -0
  17. package/dist/es2019/ui/on-paste-actions-menu/hasVisibleButton.js +19 -0
  18. package/dist/esm/editor-commands/commands.js +5 -1
  19. package/dist/esm/pasteOptionsToolbarPlugin.js +32 -31
  20. package/dist/esm/pm-plugins/main.js +3 -1
  21. package/dist/esm/pm-plugins/reducer.js +2 -0
  22. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +44 -16
  23. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -9
  24. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +5 -0
  25. package/dist/esm/ui/on-paste-actions-menu/hasVisibleButton.js +25 -0
  26. package/dist/types/editor-actions/actions.d.ts +2 -0
  27. package/dist/types/editor-commands/commands.d.ts +1 -1
  28. package/dist/types/pasteOptionsToolbarPluginType.d.ts +3 -0
  29. package/dist/types/types/types.d.ts +2 -0
  30. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +3 -5
  31. package/dist/types/ui/on-paste-actions-menu/hasVisibleButton.d.ts +6 -0
  32. package/dist/types-ts4.5/editor-actions/actions.d.ts +2 -0
  33. package/dist/types-ts4.5/editor-commands/commands.d.ts +1 -1
  34. package/dist/types-ts4.5/pasteOptionsToolbarPluginType.d.ts +3 -0
  35. package/dist/types-ts4.5/types/types.d.ts +2 -0
  36. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +3 -5
  37. package/dist/types-ts4.5/ui/on-paste-actions-menu/hasVisibleButton.d.ts +6 -0
  38. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 8.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1a9b3a0f8a1c1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1a9b3a0f8a1c1) -
8
+ [ux] EDITOR-5892 Refactor Paste actions menu to use a single ui controls registry entry and single
9
+ SurfaceRenderer. Tweaked visibility rules and increased test coverage.
10
+ - Updated dependencies
11
+
12
+ ## 8.4.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [`8cb8a3e42b2c2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8cb8a3e42b2c2) -
17
+ [ux] EDITOR-5668 Introducing configurable visibility rules to determine which AI actions should
18
+ display in on-paste menu
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+
3
24
  ## 8.3.0
4
25
 
5
26
  ### Minor 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");
@@ -17,8 +15,6 @@ var _PasteActionsMenu = require("./ui/on-paste-actions-menu/PasteActionsMenu");
17
15
  var _PasteMenuComponents = require("./ui/on-paste-actions-menu/PasteMenuComponents");
18
16
  var _toolbar = require("./ui/toolbar");
19
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); }
20
- 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; }
21
- 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; }
22
18
  var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref) {
23
19
  var _api$analytics;
24
20
  var api = _ref.api;
@@ -30,29 +26,7 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
30
26
  editorAnalyticsAPI: editorAnalyticsAPI
31
27
  }));
32
28
  }
33
- var getSharedState = function getSharedState(editorState) {
34
- var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
35
- if (!editorState) {
36
- return {
37
- isPlainText: false,
38
- pasteEndPos: 0,
39
- pasteStartPos: 0,
40
- plaintextLength: 0,
41
- selectedOption: _types.ToolbarDropdownOption.None,
42
- showToolbar: false
43
- };
44
- }
45
- var pluginState = _types.pasteOptionsPluginKey.getState(editorState);
46
- return {
47
- isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
48
- pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0,
49
- pasteStartPos: (_pluginState$pasteSta = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteStartPos) !== null && _pluginState$pasteSta !== void 0 ? _pluginState$pasteSta : 0,
50
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
51
- selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
52
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
53
- };
54
- };
55
- return _objectSpread(_objectSpread({
29
+ return {
56
30
  name: 'pasteOptionsToolbarPlugin',
57
31
  pmPlugins: function pmPlugins() {
58
32
  return [{
@@ -64,10 +38,33 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
64
38
  });
65
39
  }
66
40
  }];
67
- }
68
- }, (0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
69
- getSharedState: getSharedState
70
- } : {}), {}, {
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
+ },
71
68
  pluginsOptions: {
72
69
  floatingToolbar: function floatingToolbar(state, intl) {
73
70
  if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
@@ -106,6 +103,9 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
106
103
  }),
107
104
  lastContentPasted = _useSharedPluginState.lastContentPasted;
108
105
  (0, _react.useEffect)(function () {
106
+ if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
107
+ return;
108
+ }
109
109
  if (!lastContentPasted) {
110
110
  (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
111
111
  return;
@@ -124,5 +124,5 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
124
124
  (0, _commands.showToolbar)(lastContentPasted, selectedOption)(editorView.state, editorView.dispatch);
125
125
  }, [lastContentPasted, editorView]);
126
126
  }
127
- });
127
+ };
128
128
  };
@@ -6,7 +6,7 @@ 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");
@@ -16,18 +16,20 @@ function createPlugin(dispatch, options) {
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
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
  };
@@ -53,13 +55,13 @@ function createPlugin(dispatch, options) {
53
55
  var _ref = _types.pasteOptionsPluginKey.getState(state) || {},
54
56
  highlightContent = _ref.highlightContent,
55
57
  pasteStartPos = _ref.pasteStartPos;
56
- 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;
57
59
  if (!highlightContent) {
58
60
  return decorationSet;
59
61
  }
60
62
  var selection = state.tr.selection;
61
63
  var pasteEndPos = selection.$anchor.pos;
62
- var highlightDecoration = _view.Decoration.inline(pasteStartPos, pasteEndPos, {
64
+ var highlightDecoration = _view2.Decoration.inline(pasteStartPos, pasteEndPos, {
63
65
  class: _constants.TEXT_HIGHLIGHT_CLASS
64
66
  }, {
65
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,
@@ -14,6 +14,9 @@ var _utils = require("@atlaskit/editor-prosemirror/utils");
14
14
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
15
15
  var _editorToolbar = require("@atlaskit/editor-toolbar");
16
16
  var _commands = require("../../editor-commands/commands");
17
+ var _types = require("../../types/types");
18
+ var _toolbar2 = require("../toolbar");
19
+ var _hasVisibleButton = require("./hasVisibleButton");
17
20
  var _PasteActionsMenuContent = require("./PasteActionsMenuContent");
18
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); }
19
22
  var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
@@ -37,20 +40,48 @@ function getPopupOffset(dom) {
37
40
  return [-(window.innerWidth - rightEdge - 50), 20];
38
41
  }
39
42
  var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
40
- var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
43
+ var _api$uiControlRegistr, _api$uiControlRegistr2;
41
44
  var api = _ref.api,
42
45
  editorView = _ref.editorView,
43
46
  mountTo = _ref.mountTo,
44
47
  boundariesElement = _ref.boundariesElement,
45
48
  scrollableElement = _ref.scrollableElement;
46
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
49
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['paste'], function (states) {
50
+ var _states$pasteState;
51
+ return {
52
+ lastContentPasted: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.lastContentPasted
53
+ };
54
+ }),
55
+ lastContentPasted = _useSharedPluginState.lastContentPasted;
56
+ (0, _react.useEffect)(function () {
57
+ if (!lastContentPasted) {
58
+ (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
59
+ return;
60
+ }
61
+ var selectedOption = _types.ToolbarDropdownOption.None;
62
+ if (!lastContentPasted.isPlainText) {
63
+ selectedOption = _types.ToolbarDropdownOption.RichText;
64
+ } else if (lastContentPasted.isShiftPressed) {
65
+ selectedOption = _types.ToolbarDropdownOption.PlainText;
66
+ } else {
67
+ selectedOption = _types.ToolbarDropdownOption.Markdown;
68
+ }
69
+ var $pos = editorView.state.doc.resolve(lastContentPasted.pasteStartPos);
70
+ var pasteAncestorNodeNames = [];
71
+ for (var depth = $pos.depth; depth > 0; depth--) {
72
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
73
+ }
74
+ var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted);
75
+ (0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
76
+ }, [lastContentPasted, editorView]);
77
+ var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
47
78
  var _pluginState$showTool;
48
79
  var pluginState = states.pasteOptionsToolbarPluginState;
49
80
  return {
50
81
  showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
51
82
  };
52
83
  }),
53
- showToolbar = _useSharedPluginState.showToolbar;
84
+ isToolbarShown = _useSharedPluginState2.showToolbar;
54
85
  var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
55
86
  e.preventDefault();
56
87
  }, []);
@@ -74,19 +105,18 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
74
105
  handleDismiss();
75
106
  }
76
107
  }, [handleDismiss]);
77
- if (!showToolbar) {
108
+ var pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
109
+ var anyComponentVisible = (0, _hasVisibleButton.hasVisibleButton)(pasteMenuComponents);
110
+ if (!isToolbarShown) {
111
+ return null;
112
+ }
113
+ if (!anyComponentVisible) {
78
114
  return null;
79
115
  }
80
116
  var target = getTargetElement(editorView);
81
117
  if (!target) {
82
118
  return null;
83
119
  }
84
- var aiSurface = {
85
- type: 'menu',
86
- key: 'ai-paste-menu'
87
- };
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(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
89
- 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 : [];
90
120
  return /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
91
121
  target: target,
92
122
  mountTo: mountTo,
@@ -101,13 +131,11 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
101
131
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
102
132
  editorView: editorView
103
133
  }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenuProvider, {
104
- isOpen: showToolbar,
134
+ isOpen: isToolbarShown,
105
135
  setIsOpen: handleSetIsOpen
106
136
  }, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
107
137
  onMouseDown: preventEditorFocusLoss,
108
138
  onMouseEnter: handleMouseEnter,
109
- aiSurface: aiSurface,
110
- aiSurfaceComponents: aiSurfaceComponents,
111
- pasteSurfaceComponents: pasteSurfaceComponents
139
+ components: pasteMenuComponents
112
140
  }))));
113
141
  };
@@ -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
  };
@@ -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
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasVisibleButton = 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 true when at least one menu-item button in the list is visible.
20
+ * A button is visible when neither it nor any of its ancestors are hidden.
21
+ */
22
+ var hasVisibleButton = exports.hasVisibleButton = function hasVisibleButton(components) {
23
+ var componentsByKey = new Map(components.map(function (c) {
24
+ return [c.key, c];
25
+ }));
26
+ return components.filter(function (c) {
27
+ return c.type === 'menu-item';
28
+ }).some(function (c) {
29
+ return !_isComponentOrAncestorHidden(c, componentsByKey);
30
+ });
31
+ };
@@ -4,7 +4,7 @@ import { PastePluginActionTypes as ActionTypes } from '../editor-actions/actions
4
4
  import { createCommand } from '../pm-plugins/plugin-factory';
5
5
  import { formatMarkdown, formatPlainText, formatRichText } from '../pm-plugins/util/format-handlers';
6
6
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from '../types/types';
7
- export const showToolbar = (lastContentPasted, selectedOption) => {
7
+ export const showToolbar = (lastContentPasted, selectedOption, showLegacyOptions = true, pasteAncestorNodeNames = []) => {
8
8
  const commandAction = _editorState => {
9
9
  var _lastContentPasted$te;
10
10
  return {
@@ -15,7 +15,9 @@ export const showToolbar = (lastContentPasted, selectedOption) => {
15
15
  isPlainText: lastContentPasted.isPlainText,
16
16
  richTextSlice: lastContentPasted.pastedSlice,
17
17
  pasteStartPos: lastContentPasted.pasteStartPos,
18
- pasteEndPos: lastContentPasted.pasteEndPos
18
+ pasteEndPos: lastContentPasted.pasteEndPos,
19
+ showLegacyOptions,
20
+ pasteAncestorNodeNames
19
21
  }
20
22
  };
21
23
  };
@@ -19,28 +19,6 @@ export const pasteOptionsToolbarPlugin = ({
19
19
  editorAnalyticsAPI
20
20
  }));
21
21
  }
22
- const getSharedState = editorState => {
23
- var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
24
- if (!editorState) {
25
- return {
26
- isPlainText: false,
27
- pasteEndPos: 0,
28
- pasteStartPos: 0,
29
- plaintextLength: 0,
30
- selectedOption: ToolbarDropdownOption.None,
31
- showToolbar: false
32
- };
33
- }
34
- const pluginState = pasteOptionsPluginKey.getState(editorState);
35
- return {
36
- isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
37
- pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0,
38
- pasteStartPos: (_pluginState$pasteSta = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteStartPos) !== null && _pluginState$pasteSta !== void 0 ? _pluginState$pasteSta : 0,
39
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
40
- selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
41
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
42
- };
43
- };
44
22
  return {
45
23
  name: 'pasteOptionsToolbarPlugin',
46
24
  pmPlugins() {
@@ -53,9 +31,32 @@ export const pasteOptionsToolbarPlugin = ({
53
31
  })
54
32
  }];
55
33
  },
56
- ...(expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
57
- getSharedState
58
- } : {}),
34
+ getSharedState(editorState) {
35
+ var _pluginState$isPlainT, _pluginState$pasteAnc, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showLega, _pluginState$showTool;
36
+ if (!editorState) {
37
+ return {
38
+ isPlainText: false,
39
+ pasteAncestorNodeNames: [],
40
+ pasteEndPos: 0,
41
+ pasteStartPos: 0,
42
+ plaintextLength: 0,
43
+ selectedOption: ToolbarDropdownOption.None,
44
+ showLegacyOptions: false,
45
+ showToolbar: false
46
+ };
47
+ }
48
+ const pluginState = pasteOptionsPluginKey.getState(editorState);
49
+ return {
50
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
51
+ pasteAncestorNodeNames: (_pluginState$pasteAnc = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteAncestorNodeNames) !== null && _pluginState$pasteAnc !== void 0 ? _pluginState$pasteAnc : [],
52
+ pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0,
53
+ pasteStartPos: (_pluginState$pasteSta = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteStartPos) !== null && _pluginState$pasteSta !== void 0 ? _pluginState$pasteSta : 0,
54
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
55
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
56
+ showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false,
57
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
58
+ };
59
+ },
59
60
  pluginsOptions: {
60
61
  floatingToolbar(state, intl) {
61
62
  if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
@@ -97,6 +98,9 @@ export const pasteOptionsToolbarPlugin = ({
97
98
  };
98
99
  });
99
100
  useEffect(() => {
101
+ if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
102
+ return;
103
+ }
100
104
  if (!lastContentPasted) {
101
105
  hideToolbar()(editorView.state, editorView.dispatch);
102
106
  return;
@@ -10,6 +10,8 @@ export function createPlugin(dispatch, options) {
10
10
  key: pasteOptionsPluginKey,
11
11
  state: createPluginState(dispatch, {
12
12
  showToolbar: false,
13
+ showLegacyOptions: false,
14
+ pasteAncestorNodeNames: [],
13
15
  pasteStartPos: 0,
14
16
  pasteEndPos: 0,
15
17
  plaintext: '',
@@ -21,7 +23,7 @@ export function createPlugin(dispatch, options) {
21
23
  }),
22
24
  view(_editorView) {
23
25
  return {
24
- update(view, prevState) {
26
+ update(_view, prevState) {
25
27
  return prevState;
26
28
  }
27
29
  };
@@ -6,6 +6,8 @@ export const reducer = (state, action) => {
6
6
  return {
7
7
  ...state,
8
8
  showToolbar: true,
9
+ showLegacyOptions: action.data.showLegacyOptions,
10
+ pasteAncestorNodeNames: action.data.pasteAncestorNodeNames,
9
11
  highlightContent: false,
10
12
  isPlainText: action.data.isPlainText,
11
13
  plaintext: action.data.plaintext,
@@ -1,4 +1,4 @@
1
- import React, { useCallback } from 'react';
1
+ import React, { useCallback, useEffect } from 'react';
2
2
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
3
  import { EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
4
4
  import { Popup } from '@atlaskit/editor-common/ui';
@@ -6,7 +6,10 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
6
6
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
7
7
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
8
8
  import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
9
- import { hideToolbar, highlightContent } from '../../editor-commands/commands';
9
+ import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
10
+ import { ToolbarDropdownOption } from '../../types/types';
11
+ import { isToolbarVisible } from '../toolbar';
12
+ import { hasVisibleButton } from './hasVisibleButton';
10
13
  import { PasteActionsMenuContent } from './PasteActionsMenuContent';
11
14
  const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
12
15
  function getTargetElement(editorView) {
@@ -37,9 +40,38 @@ export const PasteActionsMenu = ({
37
40
  boundariesElement,
38
41
  scrollableElement
39
42
  }) => {
40
- var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
43
+ var _api$uiControlRegistr, _api$uiControlRegistr2;
41
44
  const {
42
- showToolbar
45
+ lastContentPasted
46
+ } = useSharedPluginStateWithSelector(api, ['paste'], states => {
47
+ var _states$pasteState;
48
+ return {
49
+ lastContentPasted: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.lastContentPasted
50
+ };
51
+ });
52
+ useEffect(() => {
53
+ if (!lastContentPasted) {
54
+ hideToolbar()(editorView.state, editorView.dispatch);
55
+ return;
56
+ }
57
+ let selectedOption = ToolbarDropdownOption.None;
58
+ if (!lastContentPasted.isPlainText) {
59
+ selectedOption = ToolbarDropdownOption.RichText;
60
+ } else if (lastContentPasted.isShiftPressed) {
61
+ selectedOption = ToolbarDropdownOption.PlainText;
62
+ } else {
63
+ selectedOption = ToolbarDropdownOption.Markdown;
64
+ }
65
+ const $pos = editorView.state.doc.resolve(lastContentPasted.pasteStartPos);
66
+ const pasteAncestorNodeNames = [];
67
+ for (let depth = $pos.depth; depth > 0; depth--) {
68
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
69
+ }
70
+ const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
71
+ showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
72
+ }, [lastContentPasted, editorView]);
73
+ const {
74
+ showToolbar: isToolbarShown
43
75
  } = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
44
76
  var _pluginState$showTool;
45
77
  const pluginState = states.pasteOptionsToolbarPluginState;
@@ -70,19 +102,18 @@ export const PasteActionsMenu = ({
70
102
  handleDismiss();
71
103
  }
72
104
  }, [handleDismiss]);
73
- if (!showToolbar) {
105
+ const pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
106
+ const anyComponentVisible = hasVisibleButton(pasteMenuComponents);
107
+ if (!isToolbarShown) {
108
+ return null;
109
+ }
110
+ if (!anyComponentVisible) {
74
111
  return null;
75
112
  }
76
113
  const target = getTargetElement(editorView);
77
114
  if (!target) {
78
115
  return null;
79
116
  }
80
- const aiSurface = {
81
- type: 'menu',
82
- key: 'ai-paste-menu'
83
- };
84
- 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 : [];
85
- 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 : [];
86
117
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
87
118
  target: target,
88
119
  mountTo: mountTo,
@@ -97,13 +128,11 @@ export const PasteActionsMenu = ({
97
128
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
98
129
  editorView: editorView
99
130
  }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, {
100
- isOpen: showToolbar,
131
+ isOpen: isToolbarShown,
101
132
  setIsOpen: handleSetIsOpen
102
133
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
103
134
  onMouseDown: preventEditorFocusLoss,
104
135
  onMouseEnter: handleMouseEnter,
105
- aiSurface: aiSurface,
106
- aiSurfaceComponents: aiSurfaceComponents,
107
- pasteSurfaceComponents: pasteSurfaceComponents
136
+ components: pasteMenuComponents
108
137
  }))));
109
138
  };