@atlaskit/editor-plugin-paste-options-toolbar 8.2.4 → 8.3.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 (33) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/pasteOptionsToolbarPlugin.js +12 -3
  3. package/dist/cjs/pm-plugins/main.js +9 -4
  4. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +27 -55
  5. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  6. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -13
  7. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  8. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +205 -0
  9. package/dist/es2019/pasteOptionsToolbarPlugin.js +12 -3
  10. package/dist/es2019/pm-plugins/main.js +9 -4
  11. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +30 -58
  12. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  13. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +11 -12
  14. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  15. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +187 -0
  16. package/dist/esm/pasteOptionsToolbarPlugin.js +12 -3
  17. package/dist/esm/pm-plugins/main.js +9 -4
  18. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +30 -58
  19. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  20. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +11 -14
  21. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  22. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +196 -0
  23. package/dist/types/pm-plugins/main.d.ts +3 -1
  24. package/dist/types/types/types.d.ts +1 -0
  25. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +1 -3
  26. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -8
  27. package/dist/types/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +12 -0
  28. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
  29. package/dist/types-ts4.5/types/types.d.ts +1 -0
  30. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +1 -3
  31. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -8
  32. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +12 -0
  33. package/package.json +5 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 8.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d7675f084fe05`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d7675f084fe05) -
8
+ [ux] [EDITOR-5669] refactored existing paste actions menu to use control registry and platform
9
+ toolbars
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 8.2.4
4
16
 
5
17
  ### Patch Changes
@@ -14,6 +14,7 @@ var _commands = require("./editor-commands/commands");
14
14
  var _main = require("./pm-plugins/main");
15
15
  var _types = require("./types/types");
16
16
  var _PasteActionsMenu = require("./ui/on-paste-actions-menu/PasteActionsMenu");
17
+ var _PasteMenuComponents = require("./ui/on-paste-actions-menu/PasteMenuComponents");
17
18
  var _toolbar = require("./ui/toolbar");
18
19
  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
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; }
@@ -22,6 +23,13 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
22
23
  var _api$analytics;
23
24
  var api = _ref.api;
24
25
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
26
+ if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
27
+ var _api$uiControlRegistr;
28
+ api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register((0, _PasteMenuComponents.getPasteMenuComponents)({
29
+ api: api,
30
+ editorAnalyticsAPI: editorAnalyticsAPI
31
+ }));
32
+ }
25
33
  var getSharedState = function getSharedState(editorState) {
26
34
  var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
27
35
  if (!editorState) {
@@ -51,7 +59,9 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
51
59
  name: 'pasteOptionsToolbarPlugin',
52
60
  plugin: function plugin(_ref2) {
53
61
  var dispatch = _ref2.dispatch;
54
- return (0, _main.createPlugin)(dispatch);
62
+ return (0, _main.createPlugin)(dispatch, {
63
+ useNewPasteMenu: (0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)
64
+ });
55
65
  }
56
66
  }];
57
67
  }
@@ -83,8 +93,7 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
83
93
  editorView: editorView,
84
94
  mountTo: popupsMountPoint,
85
95
  boundariesElement: popupsBoundariesElement,
86
- scrollableElement: popupsScrollableElement,
87
- editorAnalyticsAPI: editorAnalyticsAPI
96
+ scrollableElement: popupsScrollableElement
88
97
  });
89
98
  },
90
99
  usePluginHook: function usePluginHook(_ref4) {
@@ -11,7 +11,7 @@ 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, {
@@ -25,7 +25,7 @@ function createPlugin(dispatch) {
25
25
  richTextSlice: _model.Slice.empty,
26
26
  selectedOption: _types.ToolbarDropdownOption.None
27
27
  }),
28
- view: function view(editorView) {
28
+ view: function view(_editorView) {
29
29
  return {
30
30
  update: function update(view, prevState) {
31
31
  return prevState;
@@ -34,8 +34,13 @@ function createPlugin(dispatch) {
34
34
  },
35
35
  props: {
36
36
  handleDOMEvents: {
37
- // Hide toolbar when clicked outside the editor
38
- blur: _commands.checkAndHideToolbar,
37
+ blur: function blur(view) {
38
+ if (options !== null && options !== void 0 && options.useNewPasteMenu) {
39
+ return false;
40
+ }
41
+ (0, _commands.checkAndHideToolbar)(view);
42
+ return false;
43
+ },
39
44
  // 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
45
  mousedown: _commands.checkAndHideToolbar
41
46
  },
@@ -6,16 +6,14 @@ 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");
17
16
  var _commands = require("../../editor-commands/commands");
18
- var _types = require("../../types/types");
19
17
  var _PasteActionsMenuContent = require("./PasteActionsMenuContent");
20
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); }
21
19
  var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
@@ -39,28 +37,20 @@ function getPopupOffset(dom) {
39
37
  return [-(window.innerWidth - rightEdge - 50), 20];
40
38
  }
41
39
  var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
42
- var _api$uiControlRegistr, _api$uiControlRegistr2;
40
+ var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
43
41
  var api = _ref.api,
44
42
  editorView = _ref.editorView,
45
43
  mountTo = _ref.mountTo,
46
44
  boundariesElement = _ref.boundariesElement,
47
- scrollableElement = _ref.scrollableElement,
48
- editorAnalyticsAPI = _ref.editorAnalyticsAPI;
49
- var intl = (0, _reactIntlNext.useIntl)();
45
+ scrollableElement = _ref.scrollableElement;
50
46
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
51
- var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
47
+ var _pluginState$showTool;
52
48
  var pluginState = states.pasteOptionsToolbarPluginState;
53
49
  return {
54
- 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
50
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
58
51
  };
59
52
  }),
60
- showToolbar = _useSharedPluginState.showToolbar,
61
- isPlainText = _useSharedPluginState.isPlainText,
62
- selectedOption = _useSharedPluginState.selectedOption,
63
- plaintextLength = _useSharedPluginState.plaintextLength;
53
+ showToolbar = _useSharedPluginState.showToolbar;
64
54
  var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
65
55
  e.preventDefault();
66
56
  }, []);
@@ -70,42 +60,20 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
70
60
  var handleMouseEnter = (0, _react.useCallback)(function () {
71
61
  (0, _commands.highlightContent)()(editorView.state, editorView.dispatch);
72
62
  }, [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
- });
63
+ var handleClickOutside = (0, _react.useCallback)(function (evt) {
64
+ if (evt.target instanceof Element) {
65
+ var isInsideNestedDropdown = evt.target.closest('[data-toolbar-nested-dropdown-menu]');
66
+ if (isInsideNestedDropdown) {
67
+ return;
68
+ }
69
+ }
70
+ handleDismiss();
71
+ }, [handleDismiss]);
72
+ var handleSetIsOpen = (0, _react.useCallback)(function (isOpen) {
73
+ if (!isOpen) {
74
+ handleDismiss();
94
75
  }
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]);
76
+ }, [handleDismiss]);
109
77
  if (!showToolbar) {
110
78
  return null;
111
79
  }
@@ -118,6 +86,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
118
86
  key: 'ai-paste-menu'
119
87
  };
120
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 : [];
121
90
  return /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
122
91
  target: target,
123
92
  mountTo: mountTo,
@@ -127,15 +96,18 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
127
96
  zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex,
128
97
  alignX: "right",
129
98
  alignY: "bottom",
130
- handleClickOutside: handleDismiss,
99
+ handleClickOutside: handleClickOutside,
131
100
  handleEscapeKeydown: handleDismiss
132
101
  }, /*#__PURE__*/_react.default.createElement(_toolbar.EditorToolbarProvider, {
133
102
  editorView: editorView
103
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenuProvider, {
104
+ isOpen: showToolbar,
105
+ setIsOpen: handleSetIsOpen
134
106
  }, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
135
- options: options,
136
107
  onMouseDown: preventEditorFocusLoss,
137
108
  onMouseEnter: handleMouseEnter,
138
109
  aiSurface: aiSurface,
139
- aiSurfaceComponents: aiSurfaceComponents
140
- })));
110
+ aiSurfaceComponents: aiSurfaceComponents,
111
+ pasteSurfaceComponents: pasteSurfaceComponents
112
+ }))));
141
113
  };
@@ -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}
@@ -0,0 +1,205 @@
1
+ /* PasteMenuComponents.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.isPasteOptionSelected = exports.getPasteMenuComponents = void 0;
10
+ require("./PasteMenuComponents.compiled.css");
11
+ var _runtime = require("@compiled/react/runtime");
12
+ var _react = _interopRequireWildcard(require("react"));
13
+ var _react2 = require("@compiled/react");
14
+ var _reactIntlNext = require("react-intl-next");
15
+ var _hooks = require("@atlaskit/editor-common/hooks");
16
+ var _messages = require("@atlaskit/editor-common/messages");
17
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
18
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
19
+ var _chevronRight = _interopRequireDefault(require("@atlaskit/icon/core/chevron-right"));
20
+ var _clipboard = _interopRequireDefault(require("@atlaskit/icon/core/clipboard"));
21
+ var _compiled = require("@atlaskit/primitives/compiled");
22
+ var _commands = require("../../editor-commands/commands");
23
+ var _types = require("../../types/types");
24
+ 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); }
25
+ var nestedMenuStyles = {
26
+ narrowSection: "_10gv1lit"
27
+ };
28
+ var isPasteOptionSelected = exports.isPasteOptionSelected = function isPasteOptionSelected(pasteType, selectedOption) {
29
+ switch (pasteType) {
30
+ case 'rich-text':
31
+ return selectedOption === _types.ToolbarDropdownOption.RichText;
32
+ case 'markdown':
33
+ return selectedOption === _types.ToolbarDropdownOption.Markdown;
34
+ case 'plain-text':
35
+ return selectedOption === _types.ToolbarDropdownOption.PlainText;
36
+ default:
37
+ return false;
38
+ }
39
+ };
40
+ var PasteMenuItem = function PasteMenuItem(_ref) {
41
+ var api = _ref.api,
42
+ editorAnalyticsAPI = _ref.editorAnalyticsAPI,
43
+ pasteType = _ref.pasteType;
44
+ var intl = (0, _reactIntlNext.useIntl)();
45
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
46
+ editorView = _useEditorToolbar.editorView;
47
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
48
+ var _pluginState$selected, _pluginState$plaintex, _pluginState$isPlainT;
49
+ var pluginState = states.pasteOptionsToolbarPluginState;
50
+ return {
51
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
52
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
53
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false
54
+ };
55
+ }),
56
+ selectedOption = _useSharedPluginState.selectedOption,
57
+ plaintextLength = _useSharedPluginState.plaintextLength,
58
+ isPlainText = _useSharedPluginState.isPlainText;
59
+ var getDefaultLabel = (0, _react.useCallback)(function (type) {
60
+ switch (type) {
61
+ case 'rich-text':
62
+ return intl.formatMessage(_messages.pasteOptionsToolbarMessages.richTextAction);
63
+ case 'markdown':
64
+ return intl.formatMessage(_messages.pasteOptionsToolbarMessages.markdownAction);
65
+ case 'plain-text':
66
+ return intl.formatMessage(_messages.pasteOptionsToolbarMessages.plainTextAction);
67
+ default:
68
+ return type;
69
+ }
70
+ }, [intl]);
71
+ var handleClick = (0, _react.useCallback)(function (e) {
72
+ e.preventDefault();
73
+ if (!editorView) {
74
+ return;
75
+ }
76
+ switch (pasteType) {
77
+ case 'rich-text':
78
+ (0, _commands.changeToRichTextWithAnalytics)(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
79
+ break;
80
+ case 'markdown':
81
+ (0, _commands.changeToMarkdownWithAnalytics)(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
82
+ break;
83
+ case 'plain-text':
84
+ (0, _commands.changeToPlainTextWithAnalytics)(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
85
+ break;
86
+ }
87
+ }, [editorView, editorAnalyticsAPI, plaintextLength, pasteType]);
88
+ if (pasteType === 'rich-text' && isPlainText) {
89
+ return null;
90
+ }
91
+ var displayLabel = getDefaultLabel(pasteType);
92
+ var isSelected = isPasteOptionSelected(pasteType, selectedOption);
93
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
94
+ onClick: handleClick,
95
+ isSelected: isSelected,
96
+ testId: "paste-".concat(pasteType, "-menu-item"),
97
+ hasNestedDropdownMenu: true
98
+ }, displayLabel);
99
+ };
100
+ var PasteOptionsNestedMenu = function PasteOptionsNestedMenu(_ref2) {
101
+ var children = _ref2.children;
102
+ var intl = (0, _reactIntlNext.useIntl)();
103
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarNestedDropdownMenu, {
104
+ elemBefore: /*#__PURE__*/_react.default.createElement(_clipboard.default, {
105
+ size: "small",
106
+ label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteOptions)
107
+ }),
108
+ elemAfter: /*#__PURE__*/_react.default.createElement(_chevronRight.default, {
109
+ size: "small",
110
+ label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteOptions)
111
+ }),
112
+ testId: "paste-options-nested-menu",
113
+ text: intl.formatMessage(_messages.pasteOptionsToolbarMessages.pasteOptions)
114
+ }, children);
115
+ };
116
+ var getPasteMenuComponents = exports.getPasteMenuComponents = function getPasteMenuComponents(_ref3) {
117
+ var api = _ref3.api,
118
+ editorAnalyticsAPI = _ref3.editorAnalyticsAPI;
119
+ return [{
120
+ type: _toolbar.PASTE_MENU.type,
121
+ key: _toolbar.PASTE_MENU.key
122
+ }, {
123
+ type: _toolbar.PASTE_MENU_SECTION.type,
124
+ key: _toolbar.PASTE_MENU_SECTION.key,
125
+ parents: [{
126
+ type: _toolbar.PASTE_MENU.type,
127
+ key: _toolbar.PASTE_MENU.key,
128
+ rank: _toolbar.PASTE_MENU_RANK[_toolbar.PASTE_MENU_SECTION.key]
129
+ }],
130
+ component: function component(props) {
131
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, {
132
+ hasSeparator: true
133
+ }, props.children);
134
+ }
135
+ }, {
136
+ type: _toolbar.PASTE_NESTED_MENU.type,
137
+ key: _toolbar.PASTE_NESTED_MENU.key,
138
+ parents: [{
139
+ type: _toolbar.PASTE_MENU_SECTION.type,
140
+ key: _toolbar.PASTE_MENU_SECTION.key,
141
+ rank: _toolbar.PASTE_MENU_SECTION_RANK[_toolbar.PASTE_NESTED_MENU.key]
142
+ }],
143
+ component: function component(props) {
144
+ return /*#__PURE__*/_react.default.createElement(PasteOptionsNestedMenu, null, props.children);
145
+ }
146
+ }, {
147
+ type: _toolbar.PASTE_MENU_NESTED_SECTION.type,
148
+ key: _toolbar.PASTE_MENU_NESTED_SECTION.key,
149
+ parents: [{
150
+ type: _toolbar.PASTE_NESTED_MENU.type,
151
+ key: _toolbar.PASTE_NESTED_MENU.key,
152
+ rank: _toolbar.PASTE_NESTED_MENU_RANK[_toolbar.PASTE_MENU_NESTED_SECTION.key]
153
+ }],
154
+ component: function component(props) {
155
+ return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
156
+ xcss: (0, _react2.cx)(nestedMenuStyles.narrowSection)
157
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItemSection, null, props.children));
158
+ }
159
+ }, {
160
+ key: _toolbar.PASTE_RICH_TEXT_MENU_ITEM.key,
161
+ type: _toolbar.PASTE_RICH_TEXT_MENU_ITEM.type,
162
+ component: function component() {
163
+ return /*#__PURE__*/_react.default.createElement(PasteMenuItem, {
164
+ api: api,
165
+ editorAnalyticsAPI: editorAnalyticsAPI,
166
+ pasteType: "rich-text"
167
+ });
168
+ },
169
+ parents: [{
170
+ key: _toolbar.PASTE_MENU_NESTED_SECTION.key,
171
+ type: _toolbar.PASTE_MENU_NESTED_SECTION.type,
172
+ rank: _toolbar.PASTE_MENU_NESTED_SECTION_RANK[_toolbar.PASTE_RICH_TEXT_MENU_ITEM.key]
173
+ }]
174
+ }, {
175
+ key: _toolbar.PASTE_MARKDOWN_MENU_ITEM.key,
176
+ type: _toolbar.PASTE_MARKDOWN_MENU_ITEM.type,
177
+ component: function component() {
178
+ return /*#__PURE__*/_react.default.createElement(PasteMenuItem, {
179
+ api: api,
180
+ editorAnalyticsAPI: editorAnalyticsAPI,
181
+ pasteType: "markdown"
182
+ });
183
+ },
184
+ parents: [{
185
+ key: _toolbar.PASTE_MENU_NESTED_SECTION.key,
186
+ type: _toolbar.PASTE_MENU_NESTED_SECTION.type,
187
+ rank: _toolbar.PASTE_MENU_NESTED_SECTION_RANK[_toolbar.PASTE_MARKDOWN_MENU_ITEM.key]
188
+ }]
189
+ }, {
190
+ key: _toolbar.PASTE_PLAIN_TEXT_MENU_ITEM.key,
191
+ type: _toolbar.PASTE_PLAIN_TEXT_MENU_ITEM.type,
192
+ component: function component() {
193
+ return /*#__PURE__*/_react.default.createElement(PasteMenuItem, {
194
+ api: api,
195
+ editorAnalyticsAPI: editorAnalyticsAPI,
196
+ pasteType: "plain-text"
197
+ });
198
+ },
199
+ parents: [{
200
+ key: _toolbar.PASTE_MENU_NESTED_SECTION.key,
201
+ type: _toolbar.PASTE_MENU_NESTED_SECTION.type,
202
+ rank: _toolbar.PASTE_MENU_NESTED_SECTION_RANK[_toolbar.PASTE_PLAIN_TEXT_MENU_ITEM.key]
203
+ }]
204
+ }];
205
+ };
@@ -5,12 +5,20 @@ import { hideToolbar, showToolbar } from './editor-commands/commands';
5
5
  import { createPlugin } from './pm-plugins/main';
6
6
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from './types/types';
7
7
  import { PasteActionsMenu } from './ui/on-paste-actions-menu/PasteActionsMenu';
8
+ import { getPasteMenuComponents } from './ui/on-paste-actions-menu/PasteMenuComponents';
8
9
  import { buildToolbar, isToolbarVisible } from './ui/toolbar';
9
10
  export const pasteOptionsToolbarPlugin = ({
10
11
  api
11
12
  }) => {
12
13
  var _api$analytics;
13
14
  const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
15
+ if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
16
+ var _api$uiControlRegistr;
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
20
+ }));
21
+ }
14
22
  const getSharedState = editorState => {
15
23
  var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
16
24
  if (!editorState) {
@@ -40,7 +48,9 @@ export const pasteOptionsToolbarPlugin = ({
40
48
  name: 'pasteOptionsToolbarPlugin',
41
49
  plugin: ({
42
50
  dispatch
43
- }) => createPlugin(dispatch)
51
+ }) => createPlugin(dispatch, {
52
+ useNewPasteMenu: expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)
53
+ })
44
54
  }];
45
55
  },
46
56
  ...(expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
@@ -72,8 +82,7 @@ export const pasteOptionsToolbarPlugin = ({
72
82
  editorView: editorView,
73
83
  mountTo: popupsMountPoint,
74
84
  boundariesElement: popupsBoundariesElement,
75
- scrollableElement: popupsScrollableElement,
76
- editorAnalyticsAPI: editorAnalyticsAPI
85
+ scrollableElement: popupsScrollableElement
77
86
  });
78
87
  },
79
88
  usePluginHook({
@@ -5,7 +5,7 @@ import { checkAndHideToolbar } from '../editor-commands/commands';
5
5
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from '../types/types';
6
6
  import { PASTE_HIGHLIGHT_DECORATION_KEY, TEXT_HIGHLIGHT_CLASS } from './constants';
7
7
  import { createPluginState } from './plugin-factory';
8
- export function createPlugin(dispatch) {
8
+ export function createPlugin(dispatch, options) {
9
9
  return new SafePlugin({
10
10
  key: pasteOptionsPluginKey,
11
11
  state: createPluginState(dispatch, {
@@ -19,7 +19,7 @@ export function createPlugin(dispatch) {
19
19
  richTextSlice: Slice.empty,
20
20
  selectedOption: ToolbarDropdownOption.None
21
21
  }),
22
- view(editorView) {
22
+ view(_editorView) {
23
23
  return {
24
24
  update(view, prevState) {
25
25
  return prevState;
@@ -28,8 +28,13 @@ export function createPlugin(dispatch) {
28
28
  },
29
29
  props: {
30
30
  handleDOMEvents: {
31
- // Hide toolbar when clicked outside the editor
32
- blur: checkAndHideToolbar,
31
+ blur: view => {
32
+ if (options !== null && options !== void 0 && options.useNewPasteMenu) {
33
+ return false;
34
+ }
35
+ checkAndHideToolbar(view);
36
+ return false;
37
+ },
33
38
  // 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
34
39
  mousedown: checkAndHideToolbar
35
40
  },