@atlaskit/editor-plugin-paste-options-toolbar 8.2.4 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/editor-commands/commands.js +5 -1
  3. package/dist/cjs/pasteOptionsToolbarPlugin.js +44 -35
  4. package/dist/cjs/pm-plugins/main.js +16 -9
  5. package/dist/cjs/pm-plugins/reducer.js +2 -0
  6. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +81 -60
  7. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  8. package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenuContent.js +10 -13
  9. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  10. package/dist/cjs/ui/on-paste-actions-menu/PasteMenuComponents.js +205 -0
  11. package/dist/es2019/editor-commands/commands.js +4 -2
  12. package/dist/es2019/pasteOptionsToolbarPlugin.js +41 -28
  13. package/dist/es2019/pm-plugins/main.js +12 -5
  14. package/dist/es2019/pm-plugins/reducer.js +2 -0
  15. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +82 -62
  16. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  17. package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenuContent.js +11 -12
  18. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  19. package/dist/es2019/ui/on-paste-actions-menu/PasteMenuComponents.js +187 -0
  20. package/dist/esm/editor-commands/commands.js +5 -1
  21. package/dist/esm/pasteOptionsToolbarPlugin.js +44 -34
  22. package/dist/esm/pm-plugins/main.js +12 -5
  23. package/dist/esm/pm-plugins/reducer.js +2 -0
  24. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +84 -63
  25. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.compiled.css +2 -8
  26. package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenuContent.js +11 -14
  27. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.compiled.css +1 -0
  28. package/dist/esm/ui/on-paste-actions-menu/PasteMenuComponents.js +196 -0
  29. package/dist/types/editor-actions/actions.d.ts +2 -0
  30. package/dist/types/editor-commands/commands.d.ts +1 -1
  31. package/dist/types/pasteOptionsToolbarPluginType.d.ts +3 -0
  32. package/dist/types/pm-plugins/main.d.ts +3 -1
  33. package/dist/types/types/types.d.ts +3 -0
  34. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +1 -3
  35. package/dist/types/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -8
  36. package/dist/types/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +12 -0
  37. package/dist/types-ts4.5/editor-actions/actions.d.ts +2 -0
  38. package/dist/types-ts4.5/editor-commands/commands.d.ts +1 -1
  39. package/dist/types-ts4.5/pasteOptionsToolbarPluginType.d.ts +3 -0
  40. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -1
  41. package/dist/types-ts4.5/types/types.d.ts +3 -0
  42. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +1 -3
  43. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteActionsMenuContent.d.ts +2 -8
  44. package/dist/types-ts4.5/ui/on-paste-actions-menu/PasteMenuComponents.d.ts +12 -0
  45. package/package.json +6 -4
@@ -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
+ };
@@ -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
  };
@@ -5,34 +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;
14
- const getSharedState = editorState => {
15
- var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
16
- if (!editorState) {
17
- return {
18
- isPlainText: false,
19
- pasteEndPos: 0,
20
- pasteStartPos: 0,
21
- plaintextLength: 0,
22
- selectedOption: ToolbarDropdownOption.None,
23
- showToolbar: false
24
- };
25
- }
26
- const pluginState = pasteOptionsPluginKey.getState(editorState);
27
- return {
28
- isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
29
- pasteEndPos: (_pluginState$pasteEnd = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteEndPos) !== null && _pluginState$pasteEnd !== void 0 ? _pluginState$pasteEnd : 0,
30
- pasteStartPos: (_pluginState$pasteSta = pluginState === null || pluginState === void 0 ? void 0 : pluginState.pasteStartPos) !== null && _pluginState$pasteSta !== void 0 ? _pluginState$pasteSta : 0,
31
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintext.length) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
32
- selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
33
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
34
- };
35
- };
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
+ }
36
22
  return {
37
23
  name: 'pasteOptionsToolbarPlugin',
38
24
  pmPlugins() {
@@ -40,12 +26,37 @@ export const pasteOptionsToolbarPlugin = ({
40
26
  name: 'pasteOptionsToolbarPlugin',
41
27
  plugin: ({
42
28
  dispatch
43
- }) => createPlugin(dispatch)
29
+ }) => createPlugin(dispatch, {
30
+ useNewPasteMenu: expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)
31
+ })
44
32
  }];
45
33
  },
46
- ...(expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true) ? {
47
- getSharedState
48
- } : {}),
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
+ },
49
60
  pluginsOptions: {
50
61
  floatingToolbar(state, intl) {
51
62
  if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
@@ -72,8 +83,7 @@ export const pasteOptionsToolbarPlugin = ({
72
83
  editorView: editorView,
73
84
  mountTo: popupsMountPoint,
74
85
  boundariesElement: popupsBoundariesElement,
75
- scrollableElement: popupsScrollableElement,
76
- editorAnalyticsAPI: editorAnalyticsAPI
86
+ scrollableElement: popupsScrollableElement
77
87
  });
78
88
  },
79
89
  usePluginHook({
@@ -88,6 +98,9 @@ export const pasteOptionsToolbarPlugin = ({
88
98
  };
89
99
  });
90
100
  useEffect(() => {
101
+ if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
102
+ return;
103
+ }
91
104
  if (!lastContentPasted) {
92
105
  hideToolbar()(editorView.state, editorView.dispatch);
93
106
  return;
@@ -5,11 +5,13 @@ 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, {
12
12
  showToolbar: false,
13
+ showLegacyOptions: false,
14
+ pasteAncestorNodeNames: [],
13
15
  pasteStartPos: 0,
14
16
  pasteEndPos: 0,
15
17
  plaintext: '',
@@ -19,17 +21,22 @@ export function createPlugin(dispatch) {
19
21
  richTextSlice: Slice.empty,
20
22
  selectedOption: ToolbarDropdownOption.None
21
23
  }),
22
- view(editorView) {
24
+ view(_editorView) {
23
25
  return {
24
- update(view, prevState) {
26
+ update(_view, prevState) {
25
27
  return prevState;
26
28
  }
27
29
  };
28
30
  },
29
31
  props: {
30
32
  handleDOMEvents: {
31
- // Hide toolbar when clicked outside the editor
32
- blur: checkAndHideToolbar,
33
+ blur: view => {
34
+ if (options !== null && options !== void 0 && options.useNewPasteMenu) {
35
+ return false;
36
+ }
37
+ checkAndHideToolbar(view);
38
+ return false;
39
+ },
33
40
  // 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
41
  mousedown: checkAndHideToolbar
35
42
  },
@@ -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,14 +1,15 @@
1
- import React, { useCallback, useMemo } from 'react';
2
- import { useIntl } from 'react-intl-next';
1
+ import React, { useCallback, useEffect } from 'react';
3
2
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
- import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
5
- import { EditorToolbarProvider } from '@atlaskit/editor-common/toolbar';
3
+ import { EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
6
4
  import { Popup } from '@atlaskit/editor-common/ui';
7
5
  import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
8
6
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
7
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
10
- import { changeToMarkdownWithAnalytics, changeToPlainTextWithAnalytics, changeToRichTextWithAnalytics, hideToolbar, highlightContent } from '../../editor-commands/commands';
8
+ import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
9
+ import { buildChildrenMap, willComponentRender } from '@atlaskit/editor-ui-control-model';
10
+ import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
11
11
  import { ToolbarDropdownOption } from '../../types/types';
12
+ import { isToolbarVisible } from '../toolbar';
12
13
  import { PasteActionsMenuContent } from './PasteActionsMenuContent';
13
14
  const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
14
15
  function getTargetElement(editorView) {
@@ -32,29 +33,62 @@ function getPopupOffset(dom) {
32
33
  const rightEdge = dom.getBoundingClientRect().right;
33
34
  return [-(window.innerWidth - rightEdge - 50), 20];
34
35
  }
36
+
37
+ /**
38
+ * Returns true when at least one component in the given list would produce
39
+ * visible output (i.e. is not hidden and, for containers, has at least one
40
+ * visible descendant).
41
+ */
42
+ const hasVisibleComponent = components => {
43
+ const childrenMap = buildChildrenMap(components);
44
+ return components.some(c => willComponentRender(c, childrenMap));
45
+ };
35
46
  export const PasteActionsMenu = ({
36
47
  api,
37
48
  editorView,
38
49
  mountTo,
39
50
  boundariesElement,
40
- scrollableElement,
41
- editorAnalyticsAPI
51
+ scrollableElement
42
52
  }) => {
43
- var _api$uiControlRegistr, _api$uiControlRegistr2;
44
- const intl = useIntl();
53
+ var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
45
54
  const {
46
- showToolbar,
47
- isPlainText,
48
- selectedOption,
49
- plaintextLength
55
+ lastContentPasted
56
+ } = useSharedPluginStateWithSelector(api, ['paste'], states => {
57
+ var _states$pasteState;
58
+ return {
59
+ lastContentPasted: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.lastContentPasted
60
+ };
61
+ });
62
+ useEffect(() => {
63
+ if (!lastContentPasted) {
64
+ hideToolbar()(editorView.state, editorView.dispatch);
65
+ return;
66
+ }
67
+ let selectedOption = ToolbarDropdownOption.None;
68
+ if (!lastContentPasted.isPlainText) {
69
+ selectedOption = ToolbarDropdownOption.RichText;
70
+ } else if (lastContentPasted.isShiftPressed) {
71
+ selectedOption = ToolbarDropdownOption.PlainText;
72
+ } else {
73
+ selectedOption = ToolbarDropdownOption.Markdown;
74
+ }
75
+ const $pos = editorView.state.doc.resolve(lastContentPasted.pasteStartPos);
76
+ const pasteAncestorNodeNames = [];
77
+ for (let depth = $pos.depth; depth > 0; depth--) {
78
+ pasteAncestorNodeNames.push($pos.node(depth).type.name);
79
+ }
80
+ const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
81
+ showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
82
+ }, [lastContentPasted, editorView]);
83
+ const {
84
+ showToolbar: isToolbarShown,
85
+ showLegacyOptions
50
86
  } = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
51
- var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
87
+ var _pluginState$showTool, _pluginState$showLega;
52
88
  const pluginState = states.pasteOptionsToolbarPluginState;
53
89
  return {
54
90
  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 : ToolbarDropdownOption.None,
57
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0
91
+ showLegacyOptions: (_pluginState$showLega = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLegacyOptions) !== null && _pluginState$showLega !== void 0 ? _pluginState$showLega : false
58
92
  };
59
93
  });
60
94
  const preventEditorFocusLoss = useCallback(e => {
@@ -66,54 +100,37 @@ export const PasteActionsMenu = ({
66
100
  const handleMouseEnter = useCallback(() => {
67
101
  highlightContent()(editorView.state, editorView.dispatch);
68
102
  }, [editorView]);
69
- const handleRichText = useCallback(e => {
70
- e.preventDefault();
71
- changeToRichTextWithAnalytics(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
72
- }, [editorView, editorAnalyticsAPI]);
73
- const handleMarkdown = useCallback(e => {
74
- e.preventDefault();
75
- changeToMarkdownWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
76
- }, [editorView, editorAnalyticsAPI, plaintextLength]);
77
- const handlePlainText = useCallback(e => {
78
- e.preventDefault();
79
- changeToPlainTextWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
80
- }, [editorView, editorAnalyticsAPI, plaintextLength]);
81
- const options = useMemo(() => {
82
- const items = [];
83
- if (!isPlainText) {
84
- items.push({
85
- id: 'editor.paste.richText',
86
- label: intl.formatMessage(messages.richText),
87
- selected: selectedOption === ToolbarDropdownOption.RichText,
88
- onClick: handleRichText
89
- });
103
+ const handleClickOutside = useCallback(evt => {
104
+ if (evt.target instanceof Element) {
105
+ const isInsideNestedDropdown = evt.target.closest('[data-toolbar-nested-dropdown-menu]');
106
+ if (isInsideNestedDropdown) {
107
+ return;
108
+ }
109
+ }
110
+ handleDismiss();
111
+ }, [handleDismiss]);
112
+ const handleSetIsOpen = useCallback(isOpen => {
113
+ if (!isOpen) {
114
+ handleDismiss();
90
115
  }
91
- items.push({
92
- id: 'editor.paste.markdown',
93
- label: intl.formatMessage(messages.markdown),
94
- selected: selectedOption === ToolbarDropdownOption.Markdown,
95
- onClick: handleMarkdown
96
- });
97
- items.push({
98
- id: 'editor.paste.plainText',
99
- label: intl.formatMessage(messages.plainText),
100
- selected: selectedOption === ToolbarDropdownOption.PlainText,
101
- onClick: handlePlainText
102
- });
103
- return items;
104
- }, [isPlainText, selectedOption, intl, handleRichText, handleMarkdown, handlePlainText]);
105
- if (!showToolbar) {
116
+ }, [handleDismiss]);
117
+ const aiSurface = {
118
+ type: 'menu',
119
+ key: 'ai-paste-menu'
120
+ };
121
+ const aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
122
+ const pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
123
+ const anyAiComponentVisible = hasVisibleComponent(aiSurfaceComponents);
124
+ if (!isToolbarShown) {
125
+ return null;
126
+ }
127
+ if (!showLegacyOptions && !anyAiComponentVisible) {
106
128
  return null;
107
129
  }
108
130
  const target = getTargetElement(editorView);
109
131
  if (!target) {
110
132
  return null;
111
133
  }
112
- const aiSurface = {
113
- type: 'menu',
114
- key: 'ai-paste-menu'
115
- };
116
- 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 : [];
117
134
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
118
135
  target: target,
119
136
  mountTo: mountTo,
@@ -123,15 +140,18 @@ export const PasteActionsMenu = ({
123
140
  zIndex: akEditorFloatingPanelZIndex,
124
141
  alignX: "right",
125
142
  alignY: "bottom",
126
- handleClickOutside: handleDismiss,
143
+ handleClickOutside: handleClickOutside,
127
144
  handleEscapeKeydown: handleDismiss
128
145
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
129
146
  editorView: editorView
147
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, {
148
+ isOpen: isToolbarShown,
149
+ setIsOpen: handleSetIsOpen
130
150
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
131
- options: options,
132
151
  onMouseDown: preventEditorFocusLoss,
133
152
  onMouseEnter: handleMouseEnter,
134
153
  aiSurface: aiSurface,
135
- aiSurfaceComponents: aiSurfaceComponents
136
- })));
154
+ aiSurfaceComponents: aiSurfaceComponents,
155
+ pasteSurfaceComponents: showLegacyOptions ? pasteSurfaceComponents : []
156
+ }))));
137
157
  };
@@ -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)}
@@ -2,21 +2,18 @@
2
2
  import "./PasteActionsMenuContent.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React, { useContext } from 'react';
5
- import { cx } from '@atlaskit/css';
6
5
  import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
7
6
  import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model';
8
- import { Box, Pressable } from '@atlaskit/primitives/compiled';
7
+ import { Box } from '@atlaskit/primitives/compiled';
9
8
  const styles = {
10
- container: "_2rko12b0 _1rjc1b66 _bfhk1bhr _16qs130s",
11
- option: "_1rjcu2gc _18zrpxbi _syazi7uo _bfhksm61 _irr31dpa",
12
- selectedOption: "_k48pwu06"
9
+ container: "_2rko12b0 _1rjc1b66 _bfhk1bhr _16qs130s"
13
10
  };
14
11
  export const PasteActionsMenuContent = ({
15
- options,
16
12
  onMouseDown,
17
13
  onMouseEnter,
18
14
  aiSurface,
19
- aiSurfaceComponents
15
+ aiSurfaceComponents,
16
+ pasteSurfaceComponents
20
17
  }) => {
21
18
  const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
22
19
  return /*#__PURE__*/React.createElement(Box, {
@@ -27,9 +24,11 @@ export const PasteActionsMenuContent = ({
27
24
  }, aiSurface && aiSurfaceComponents && aiSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
28
25
  surface: aiSurface,
29
26
  components: aiSurfaceComponents
30
- }), options.map(option => /*#__PURE__*/React.createElement(Pressable, {
31
- key: option.id,
32
- xcss: cx(styles.option, option.selected && styles.selectedOption),
33
- onClick: option.onClick
34
- }, option.label)));
27
+ }), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
28
+ surface: {
29
+ type: 'menu',
30
+ key: 'paste-menu'
31
+ },
32
+ components: pasteSurfaceComponents
33
+ }));
35
34
  };
@@ -0,0 +1 @@
1
+ ._10gv1lit button{min-width:10pc}