@atlaskit/editor-plugin-paste-options-toolbar 8.0.4 → 8.1.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 (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/editor-commands/commands.js +6 -6
  3. package/dist/cjs/pasteOptionsToolbarPlugin.js +56 -8
  4. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +130 -0
  5. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +10 -0
  6. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +39 -0
  7. package/dist/cjs/ui/toolbar.js +1 -1
  8. package/dist/es2019/editor-commands/commands.js +6 -6
  9. package/dist/es2019/pasteOptionsToolbarPlugin.js +45 -2
  10. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +126 -0
  11. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +10 -0
  12. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +30 -0
  13. package/dist/es2019/ui/toolbar.js +1 -1
  14. package/dist/esm/editor-commands/commands.js +6 -6
  15. package/dist/esm/pasteOptionsToolbarPlugin.js +53 -8
  16. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +122 -0
  17. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +10 -0
  18. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +31 -0
  19. package/dist/esm/ui/toolbar.js +1 -1
  20. package/dist/types/index.d.ts +1 -1
  21. package/dist/types/pasteOptionsToolbarPluginType.d.ts +7 -0
  22. package/dist/types/pm-plugins/main.d.ts +1 -1
  23. package/dist/types/pm-plugins/plugin-factory.d.ts +2 -2
  24. package/dist/types/pm-plugins/reducer.d.ts +1 -1
  25. package/dist/types/pm-plugins/util/format-handlers.d.ts +4 -4
  26. package/dist/types/types/types.d.ts +1 -1
  27. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +15 -0
  28. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +14 -0
  29. package/dist/types/ui/toolbar.d.ts +2 -2
  30. package/dist/types-ts4.5/index.d.ts +1 -1
  31. package/dist/types-ts4.5/pasteOptionsToolbarPluginType.d.ts +7 -0
  32. package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
  33. package/dist/types-ts4.5/pm-plugins/plugin-factory.d.ts +2 -2
  34. package/dist/types-ts4.5/pm-plugins/reducer.d.ts +1 -1
  35. package/dist/types-ts4.5/pm-plugins/util/format-handlers.d.ts +4 -4
  36. package/dist/types-ts4.5/types/types.d.ts +1 -1
  37. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +15 -0
  38. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +14 -0
  39. package/dist/types-ts4.5/ui/toolbar.d.ts +2 -2
  40. package/package.json +5 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 8.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 8.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`a0aa8f73bbd02`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a0aa8f73bbd02) -
14
+ [ux] EDITOR-5466 Introduce new popup menu for paste actions which includes existing functionality
15
+ used by the existing floatingToolbar implementation
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 8.0.4
4
22
 
5
23
  ### Patch Changes
@@ -11,7 +11,7 @@ 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 commandAction = function commandAction(editorState) {
14
+ var commandAction = function commandAction(_editorState) {
15
15
  var _lastContentPasted$te;
16
16
  return {
17
17
  type: _actions.PastePluginActionTypes.SHOW_PASTE_OPTIONS,
@@ -35,7 +35,7 @@ var changeToPlainText = exports.changeToPlainText = function changeToPlainText()
35
35
  }
36
36
  return (0, _formatHandlers.formatPlainText)(tr, pluginState);
37
37
  };
38
- var commandAction = function commandAction(editorState) {
38
+ var commandAction = function commandAction(_editorState) {
39
39
  return {
40
40
  type: _actions.PastePluginActionTypes.CHANGE_FORMAT,
41
41
  data: {
@@ -71,7 +71,7 @@ var changeToRichText = exports.changeToRichText = function changeToRichText() {
71
71
  }
72
72
  return (0, _formatHandlers.formatRichText)(tr, pluginState);
73
73
  };
74
- var commandAction = function commandAction(editorState) {
74
+ var commandAction = function commandAction(_editorState) {
75
75
  return {
76
76
  type: _actions.PastePluginActionTypes.CHANGE_FORMAT,
77
77
  data: {
@@ -109,7 +109,7 @@ var changeToMarkDown = exports.changeToMarkDown = function changeToMarkDown() {
109
109
  }
110
110
  return (0, _formatHandlers.formatMarkdown)(tr, pluginState);
111
111
  };
112
- var commandAction = function commandAction(editorState) {
112
+ var commandAction = function commandAction(_editorState) {
113
113
  return {
114
114
  type: _actions.PastePluginActionTypes.CHANGE_FORMAT,
115
115
  data: {
@@ -135,7 +135,7 @@ var changeToMarkdownWithAnalytics = exports.changeToMarkdownWithAnalytics = func
135
135
  };
136
136
  };
137
137
  var highlightContent = exports.highlightContent = function highlightContent() {
138
- var commandAction = function commandAction(editorState) {
138
+ var commandAction = function commandAction(_editorState) {
139
139
  return {
140
140
  type: _actions.PastePluginActionTypes.HIGHLIGHT_CONTENT
141
141
  };
@@ -143,7 +143,7 @@ var highlightContent = exports.highlightContent = function highlightContent() {
143
143
  return (0, _pluginFactory.createCommand)(commandAction);
144
144
  };
145
145
  var hideToolbar = exports.hideToolbar = function hideToolbar() {
146
- var commandAction = function commandAction(editorState) {
146
+ var commandAction = function commandAction(_editorState) {
147
147
  return {
148
148
  type: _actions.PastePluginActionTypes.HIDE_PASTE_OPTIONS
149
149
  };
@@ -1,21 +1,46 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports.pasteOptionsToolbarPlugin = void 0;
7
- var _react = require("react");
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireWildcard(require("react"));
8
11
  var _hooks = require("@atlaskit/editor-common/hooks");
12
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
9
13
  var _commands = require("./editor-commands/commands");
10
14
  var _main = require("./pm-plugins/main");
11
15
  var _types = require("./types/types");
16
+ var _PasteActionsMenu = require("./ui/on-paste-actions-menu/PasteActionsMenu");
12
17
  var _toolbar = require("./ui/toolbar");
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
+ 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; }
13
21
  var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref) {
14
22
  var _api$analytics;
15
- var config = _ref.config,
16
- api = _ref.api;
23
+ var api = _ref.api;
17
24
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
18
- return {
25
+ var getSharedState = function getSharedState(editorState) {
26
+ var _pluginState$isPlainT, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
27
+ if (!editorState) {
28
+ return {
29
+ isPlainText: false,
30
+ plaintextLength: 0,
31
+ selectedOption: _types.ToolbarDropdownOption.None,
32
+ showToolbar: false
33
+ };
34
+ }
35
+ var pluginState = _types.pasteOptionsPluginKey.getState(editorState);
36
+ return {
37
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
38
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
39
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
40
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
41
+ };
42
+ };
43
+ return _objectSpread(_objectSpread({
19
44
  name: 'pasteOptionsToolbarPlugin',
20
45
  pmPlugins: function pmPlugins() {
21
46
  return [{
@@ -25,9 +50,15 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
25
50
  return (0, _main.createPlugin)(dispatch);
26
51
  }
27
52
  }];
28
- },
53
+ }
54
+ }, (0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
55
+ getSharedState: getSharedState
56
+ } : {}), {}, {
29
57
  pluginsOptions: {
30
58
  floatingToolbar: function floatingToolbar(state, intl) {
59
+ if ((0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true)) {
60
+ return;
61
+ }
31
62
  var pastePluginState = _types.pasteOptionsPluginKey.getState(state);
32
63
  if (pastePluginState.showToolbar) {
33
64
  return (0, _toolbar.buildToolbar)(state, intl, editorAnalyticsAPI);
@@ -35,8 +66,25 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
35
66
  return;
36
67
  }
37
68
  },
38
- usePluginHook: function usePluginHook(_ref3) {
39
- var editorView = _ref3.editorView;
69
+ contentComponent: function contentComponent(_ref3) {
70
+ var editorView = _ref3.editorView,
71
+ popupsMountPoint = _ref3.popupsMountPoint,
72
+ popupsBoundariesElement = _ref3.popupsBoundariesElement,
73
+ popupsScrollableElement = _ref3.popupsScrollableElement;
74
+ if (!(0, _expValEquals.expValEquals)('platform_editor_paste_actions_menu', 'isEnabled', true) || !editorView) {
75
+ return null;
76
+ }
77
+ return /*#__PURE__*/_react.default.createElement(_PasteActionsMenu.PasteActionsMenu, {
78
+ api: api,
79
+ editorView: editorView,
80
+ mountTo: popupsMountPoint,
81
+ boundariesElement: popupsBoundariesElement,
82
+ scrollableElement: popupsScrollableElement,
83
+ editorAnalyticsAPI: editorAnalyticsAPI
84
+ });
85
+ },
86
+ usePluginHook: function usePluginHook(_ref4) {
87
+ var editorView = _ref4.editorView;
40
88
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['paste'], function (states) {
41
89
  var _states$pasteState;
42
90
  return {
@@ -63,5 +111,5 @@ var pasteOptionsToolbarPlugin = exports.pasteOptionsToolbarPlugin = function pas
63
111
  (0, _commands.showToolbar)(lastContentPasted, selectedOption)(editorView.state, editorView.dispatch);
64
112
  }, [lastContentPasted, editorView]);
65
113
  }
66
- };
114
+ });
67
115
  };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PasteActionsMenu = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _ui = require("@atlaskit/editor-common/ui");
13
+ var _uiReact = require("@atlaskit/editor-common/ui-react");
14
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
15
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
+ var _commands = require("../../editor-commands/commands");
17
+ var _types = require("../../types/types");
18
+ var _PasteActionsMenuContent = require("./PasteActionsMenuContent");
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); }
20
+ var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
21
+ function getTargetElement(editorView) {
22
+ var from = editorView.state.selection.from;
23
+ try {
24
+ var domRef = (0, _utils.findDomRefAtPos)(from, editorView.domAtPos.bind(editorView));
25
+ if (domRef instanceof HTMLElement) {
26
+ return domRef;
27
+ }
28
+ return null;
29
+ } catch (_unused) {
30
+ return null;
31
+ }
32
+ }
33
+ function getPopupOffset(dom) {
34
+ if (!dom) {
35
+ return [0, 20];
36
+ }
37
+ var rightEdge = dom.getBoundingClientRect().right;
38
+ return [-(window.innerWidth - rightEdge - 50), 20];
39
+ }
40
+ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref) {
41
+ var api = _ref.api,
42
+ editorView = _ref.editorView,
43
+ mountTo = _ref.mountTo,
44
+ boundariesElement = _ref.boundariesElement,
45
+ scrollableElement = _ref.scrollableElement,
46
+ editorAnalyticsAPI = _ref.editorAnalyticsAPI;
47
+ var intl = (0, _reactIntlNext.useIntl)();
48
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
49
+ var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
50
+ var pluginState = states.pasteOptionsToolbarPluginState;
51
+ return {
52
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
53
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
54
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : _types.ToolbarDropdownOption.None,
55
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0
56
+ };
57
+ }),
58
+ showToolbar = _useSharedPluginState.showToolbar,
59
+ isPlainText = _useSharedPluginState.isPlainText,
60
+ selectedOption = _useSharedPluginState.selectedOption,
61
+ plaintextLength = _useSharedPluginState.plaintextLength;
62
+ var preventEditorFocusLoss = (0, _react.useCallback)(function (e) {
63
+ e.preventDefault();
64
+ }, []);
65
+ var handleDismiss = (0, _react.useCallback)(function () {
66
+ (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
67
+ }, [editorView]);
68
+ var handleMouseEnter = (0, _react.useCallback)(function () {
69
+ (0, _commands.highlightContent)()(editorView.state, editorView.dispatch);
70
+ }, [editorView]);
71
+ var handleRichText = (0, _react.useCallback)(function (e) {
72
+ e.preventDefault();
73
+ (0, _commands.changeToRichTextWithAnalytics)(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
74
+ }, [editorView, editorAnalyticsAPI]);
75
+ var handleMarkdown = (0, _react.useCallback)(function (e) {
76
+ e.preventDefault();
77
+ (0, _commands.changeToMarkdownWithAnalytics)(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
78
+ }, [editorView, editorAnalyticsAPI, plaintextLength]);
79
+ var handlePlainText = (0, _react.useCallback)(function (e) {
80
+ e.preventDefault();
81
+ (0, _commands.changeToPlainTextWithAnalytics)(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
82
+ }, [editorView, editorAnalyticsAPI, plaintextLength]);
83
+ var options = (0, _react.useMemo)(function () {
84
+ var items = [];
85
+ if (!isPlainText) {
86
+ items.push({
87
+ id: 'editor.paste.richText',
88
+ label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.richText),
89
+ selected: selectedOption === _types.ToolbarDropdownOption.RichText,
90
+ onClick: handleRichText
91
+ });
92
+ }
93
+ items.push({
94
+ id: 'editor.paste.markdown',
95
+ label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.markdown),
96
+ selected: selectedOption === _types.ToolbarDropdownOption.Markdown,
97
+ onClick: handleMarkdown
98
+ });
99
+ items.push({
100
+ id: 'editor.paste.plainText',
101
+ label: intl.formatMessage(_messages.pasteOptionsToolbarMessages.plainText),
102
+ selected: selectedOption === _types.ToolbarDropdownOption.PlainText,
103
+ onClick: handlePlainText
104
+ });
105
+ return items;
106
+ }, [isPlainText, selectedOption, intl, handleRichText, handleMarkdown, handlePlainText]);
107
+ if (!showToolbar) {
108
+ return null;
109
+ }
110
+ var target = getTargetElement(editorView);
111
+ if (!target) {
112
+ return null;
113
+ }
114
+ return /*#__PURE__*/_react.default.createElement(PopupWithListeners, {
115
+ target: target,
116
+ mountTo: mountTo,
117
+ boundariesElement: boundariesElement,
118
+ scrollableElement: scrollableElement,
119
+ offset: getPopupOffset(target),
120
+ zIndex: _editorSharedStyles.akEditorFloatingPanelZIndex,
121
+ alignX: "right",
122
+ alignY: "bottom",
123
+ handleClickOutside: handleDismiss,
124
+ handleEscapeKeydown: handleDismiss
125
+ }, /*#__PURE__*/_react.default.createElement(_PasteActionsMenuContent.PasteActionsMenuContent, {
126
+ options: options,
127
+ onMouseDown: preventEditorFocusLoss,
128
+ onMouseEnter: handleMouseEnter
129
+ }));
130
+ };
@@ -0,0 +1,10 @@
1
+
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)}
@@ -0,0 +1,39 @@
1
+ /* PasteActionsMenuContent.tsx generated by @compiled/babel-plugin v0.38.1 */
2
+ "use strict";
3
+
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.PasteActionsMenuContent = void 0;
9
+ require("./PasteActionsMenuContent.compiled.css");
10
+ var _runtime = require("@compiled/react/runtime");
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _css = require("@atlaskit/css");
13
+ var _uiReact = require("@atlaskit/editor-common/ui-react");
14
+ var _compiled = require("@atlaskit/primitives/compiled");
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); }
16
+ var styles = {
17
+ container: "_2rko12b0 _1rjc1b66 _bfhk1bhr _16qs130s",
18
+ option: "_1rjcu2gc _18zrpxbi _syazi7uo _bfhksm61 _irr31dpa",
19
+ selectedOption: "_k48pwu06"
20
+ };
21
+ var PasteActionsMenuContent = exports.PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
22
+ var options = _ref.options,
23
+ onMouseDown = _ref.onMouseDown,
24
+ onMouseEnter = _ref.onMouseEnter;
25
+ var setOutsideClickTargetRef = (0, _react.useContext)(_uiReact.OutsideClickTargetRefContext);
26
+ return /*#__PURE__*/_react.default.createElement(_compiled.Box, {
27
+ ref: setOutsideClickTargetRef,
28
+ xcss: styles.container
29
+ }, options.map(function (option) {
30
+ return /*#__PURE__*/_react.default.createElement(_compiled.Pressable, {
31
+ key: option.id,
32
+ xcss: (0, _css.cx)(styles.option, option.selected && styles.selectedOption),
33
+ onMouseDown: onMouseDown,
34
+ onMouseEnter: onMouseEnter,
35
+ onFocus: onMouseEnter,
36
+ onClick: option.onClick
37
+ }, option.label);
38
+ }));
39
+ };
@@ -78,7 +78,7 @@ var buildToolbar = exports.buildToolbar = function buildToolbar(state, intl, edi
78
78
  onPositionCalculated: onPositionCalculated
79
79
  };
80
80
  };
81
- var onPositionCalculated = function onPositionCalculated(editorView, nextPos) {
81
+ var onPositionCalculated = function onPositionCalculated(editorView, _nextPos) {
82
82
  var from = editorView.state.selection.from;
83
83
  var fromCoords = editorView.coordsAtPos(from);
84
84
 
@@ -5,7 +5,7 @@ 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
7
  export const showToolbar = (lastContentPasted, selectedOption) => {
8
- const commandAction = editorState => {
8
+ const commandAction = _editorState => {
9
9
  var _lastContentPasted$te;
10
10
  return {
11
11
  type: ActionTypes.SHOW_PASTE_OPTIONS,
@@ -29,7 +29,7 @@ export const changeToPlainText = () => {
29
29
  }
30
30
  return formatPlainText(tr, pluginState);
31
31
  };
32
- const commandAction = editorState => {
32
+ const commandAction = _editorState => {
33
33
  return {
34
34
  type: ActionTypes.CHANGE_FORMAT,
35
35
  data: {
@@ -63,7 +63,7 @@ export const changeToRichText = () => {
63
63
  }
64
64
  return formatRichText(tr, pluginState);
65
65
  };
66
- const commandAction = editorState => {
66
+ const commandAction = _editorState => {
67
67
  return {
68
68
  type: ActionTypes.CHANGE_FORMAT,
69
69
  data: {
@@ -99,7 +99,7 @@ export const changeToMarkDown = () => {
99
99
  }
100
100
  return formatMarkdown(tr, pluginState);
101
101
  };
102
- const commandAction = editorState => {
102
+ const commandAction = _editorState => {
103
103
  return {
104
104
  type: ActionTypes.CHANGE_FORMAT,
105
105
  data: {
@@ -123,7 +123,7 @@ export const changeToMarkdownWithAnalytics = (editorAnalyticsAPI, sliceSize) =>
123
123
  })(changeToMarkDown());
124
124
  };
125
125
  export const highlightContent = () => {
126
- const commandAction = editorState => {
126
+ const commandAction = _editorState => {
127
127
  return {
128
128
  type: ActionTypes.HIGHLIGHT_CONTENT
129
129
  };
@@ -131,7 +131,7 @@ export const highlightContent = () => {
131
131
  return createCommand(commandAction);
132
132
  };
133
133
  export const hideToolbar = () => {
134
- const commandAction = editorState => {
134
+ const commandAction = _editorState => {
135
135
  return {
136
136
  type: ActionTypes.HIDE_PASTE_OPTIONS
137
137
  };
@@ -1,15 +1,34 @@
1
- import { useEffect } from 'react';
1
+ import React, { useEffect } from 'react';
2
2
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
3
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
3
4
  import { hideToolbar, showToolbar } from './editor-commands/commands';
4
5
  import { createPlugin } from './pm-plugins/main';
5
6
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from './types/types';
7
+ import { PasteActionsMenu } from './ui/on-paste-actions-menu/PasteActionsMenu';
6
8
  import { buildToolbar, isToolbarVisible } from './ui/toolbar';
7
9
  export const pasteOptionsToolbarPlugin = ({
8
- config,
9
10
  api
10
11
  }) => {
11
12
  var _api$analytics;
12
13
  const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
14
+ const getSharedState = editorState => {
15
+ var _pluginState$isPlainT, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
16
+ if (!editorState) {
17
+ return {
18
+ isPlainText: false,
19
+ plaintextLength: 0,
20
+ selectedOption: ToolbarDropdownOption.None,
21
+ showToolbar: false
22
+ };
23
+ }
24
+ const pluginState = pasteOptionsPluginKey.getState(editorState);
25
+ return {
26
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
27
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
28
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
29
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
30
+ };
31
+ };
13
32
  return {
14
33
  name: 'pasteOptionsToolbarPlugin',
15
34
  pmPlugins() {
@@ -20,8 +39,14 @@ export const pasteOptionsToolbarPlugin = ({
20
39
  }) => createPlugin(dispatch)
21
40
  }];
22
41
  },
42
+ ...(expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
43
+ getSharedState
44
+ } : {}),
23
45
  pluginsOptions: {
24
46
  floatingToolbar(state, intl) {
47
+ if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
48
+ return;
49
+ }
25
50
  const pastePluginState = pasteOptionsPluginKey.getState(state);
26
51
  if (pastePluginState.showToolbar) {
27
52
  return buildToolbar(state, intl, editorAnalyticsAPI);
@@ -29,6 +54,24 @@ export const pasteOptionsToolbarPlugin = ({
29
54
  return;
30
55
  }
31
56
  },
57
+ contentComponent({
58
+ editorView,
59
+ popupsMountPoint,
60
+ popupsBoundariesElement,
61
+ popupsScrollableElement
62
+ }) {
63
+ if (!expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true) || !editorView) {
64
+ return null;
65
+ }
66
+ return /*#__PURE__*/React.createElement(PasteActionsMenu, {
67
+ api: api,
68
+ editorView: editorView,
69
+ mountTo: popupsMountPoint,
70
+ boundariesElement: popupsBoundariesElement,
71
+ scrollableElement: popupsScrollableElement,
72
+ editorAnalyticsAPI: editorAnalyticsAPI
73
+ });
74
+ },
32
75
  usePluginHook({
33
76
  editorView
34
77
  }) {
@@ -0,0 +1,126 @@
1
+ import React, { useCallback, useMemo } from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { Popup } from '@atlaskit/editor-common/ui';
6
+ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
7
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
8
+ import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
9
+ import { changeToMarkdownWithAnalytics, changeToPlainTextWithAnalytics, changeToRichTextWithAnalytics, hideToolbar, highlightContent } from '../../editor-commands/commands';
10
+ import { ToolbarDropdownOption } from '../../types/types';
11
+ import { PasteActionsMenuContent } from './PasteActionsMenuContent';
12
+ const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
13
+ function getTargetElement(editorView) {
14
+ const {
15
+ from
16
+ } = editorView.state.selection;
17
+ try {
18
+ const domRef = findDomRefAtPos(from, editorView.domAtPos.bind(editorView));
19
+ if (domRef instanceof HTMLElement) {
20
+ return domRef;
21
+ }
22
+ return null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+ function getPopupOffset(dom) {
28
+ if (!dom) {
29
+ return [0, 20];
30
+ }
31
+ const rightEdge = dom.getBoundingClientRect().right;
32
+ return [-(window.innerWidth - rightEdge - 50), 20];
33
+ }
34
+ export const PasteActionsMenu = ({
35
+ api,
36
+ editorView,
37
+ mountTo,
38
+ boundariesElement,
39
+ scrollableElement,
40
+ editorAnalyticsAPI
41
+ }) => {
42
+ const intl = useIntl();
43
+ const {
44
+ showToolbar,
45
+ isPlainText,
46
+ selectedOption,
47
+ plaintextLength
48
+ } = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
49
+ var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
50
+ const pluginState = states.pasteOptionsToolbarPluginState;
51
+ return {
52
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
53
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
54
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
55
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0
56
+ };
57
+ });
58
+ const preventEditorFocusLoss = useCallback(e => {
59
+ e.preventDefault();
60
+ }, []);
61
+ const handleDismiss = useCallback(() => {
62
+ hideToolbar()(editorView.state, editorView.dispatch);
63
+ }, [editorView]);
64
+ const handleMouseEnter = useCallback(() => {
65
+ highlightContent()(editorView.state, editorView.dispatch);
66
+ }, [editorView]);
67
+ const handleRichText = useCallback(e => {
68
+ e.preventDefault();
69
+ changeToRichTextWithAnalytics(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
70
+ }, [editorView, editorAnalyticsAPI]);
71
+ const handleMarkdown = useCallback(e => {
72
+ e.preventDefault();
73
+ changeToMarkdownWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
74
+ }, [editorView, editorAnalyticsAPI, plaintextLength]);
75
+ const handlePlainText = useCallback(e => {
76
+ e.preventDefault();
77
+ changeToPlainTextWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
78
+ }, [editorView, editorAnalyticsAPI, plaintextLength]);
79
+ const options = useMemo(() => {
80
+ const items = [];
81
+ if (!isPlainText) {
82
+ items.push({
83
+ id: 'editor.paste.richText',
84
+ label: intl.formatMessage(messages.richText),
85
+ selected: selectedOption === ToolbarDropdownOption.RichText,
86
+ onClick: handleRichText
87
+ });
88
+ }
89
+ items.push({
90
+ id: 'editor.paste.markdown',
91
+ label: intl.formatMessage(messages.markdown),
92
+ selected: selectedOption === ToolbarDropdownOption.Markdown,
93
+ onClick: handleMarkdown
94
+ });
95
+ items.push({
96
+ id: 'editor.paste.plainText',
97
+ label: intl.formatMessage(messages.plainText),
98
+ selected: selectedOption === ToolbarDropdownOption.PlainText,
99
+ onClick: handlePlainText
100
+ });
101
+ return items;
102
+ }, [isPlainText, selectedOption, intl, handleRichText, handleMarkdown, handlePlainText]);
103
+ if (!showToolbar) {
104
+ return null;
105
+ }
106
+ const target = getTargetElement(editorView);
107
+ if (!target) {
108
+ return null;
109
+ }
110
+ return /*#__PURE__*/React.createElement(PopupWithListeners, {
111
+ target: target,
112
+ mountTo: mountTo,
113
+ boundariesElement: boundariesElement,
114
+ scrollableElement: scrollableElement,
115
+ offset: getPopupOffset(target),
116
+ zIndex: akEditorFloatingPanelZIndex,
117
+ alignX: "right",
118
+ alignY: "bottom",
119
+ handleClickOutside: handleDismiss,
120
+ handleEscapeKeydown: handleDismiss
121
+ }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
122
+ options: options,
123
+ onMouseDown: preventEditorFocusLoss,
124
+ onMouseEnter: handleMouseEnter
125
+ }));
126
+ };
@@ -0,0 +1,10 @@
1
+
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)}