@atlaskit/editor-plugin-paste-options-toolbar 8.2.3 → 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 +18 -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 +6 -4
@@ -1,14 +1,12 @@
1
- import React, { useCallback, useMemo } from 'react';
2
- import { useIntl } from 'react-intl-next';
1
+ import React, { useCallback } 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';
11
- import { ToolbarDropdownOption } from '../../types/types';
8
+ import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
9
+ import { hideToolbar, highlightContent } from '../../editor-commands/commands';
12
10
  import { PasteActionsMenuContent } from './PasteActionsMenuContent';
13
11
  const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
14
12
  function getTargetElement(editorView) {
@@ -37,24 +35,16 @@ export const PasteActionsMenu = ({
37
35
  editorView,
38
36
  mountTo,
39
37
  boundariesElement,
40
- scrollableElement,
41
- editorAnalyticsAPI
38
+ scrollableElement
42
39
  }) => {
43
- var _api$uiControlRegistr, _api$uiControlRegistr2;
44
- const intl = useIntl();
40
+ var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
45
41
  const {
46
- showToolbar,
47
- isPlainText,
48
- selectedOption,
49
- plaintextLength
42
+ showToolbar
50
43
  } = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
51
- var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
44
+ var _pluginState$showTool;
52
45
  const pluginState = states.pasteOptionsToolbarPluginState;
53
46
  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 : ToolbarDropdownOption.None,
57
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0
47
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
58
48
  };
59
49
  });
60
50
  const preventEditorFocusLoss = useCallback(e => {
@@ -66,42 +56,20 @@ export const PasteActionsMenu = ({
66
56
  const handleMouseEnter = useCallback(() => {
67
57
  highlightContent()(editorView.state, editorView.dispatch);
68
58
  }, [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
- });
59
+ const handleClickOutside = useCallback(evt => {
60
+ if (evt.target instanceof Element) {
61
+ const isInsideNestedDropdown = evt.target.closest('[data-toolbar-nested-dropdown-menu]');
62
+ if (isInsideNestedDropdown) {
63
+ return;
64
+ }
65
+ }
66
+ handleDismiss();
67
+ }, [handleDismiss]);
68
+ const handleSetIsOpen = useCallback(isOpen => {
69
+ if (!isOpen) {
70
+ handleDismiss();
90
71
  }
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]);
72
+ }, [handleDismiss]);
105
73
  if (!showToolbar) {
106
74
  return null;
107
75
  }
@@ -114,6 +82,7 @@ export const PasteActionsMenu = ({
114
82
  key: 'ai-paste-menu'
115
83
  };
116
84
  const aiSurfaceComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(aiSurface.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
85
+ const pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [];
117
86
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
118
87
  target: target,
119
88
  mountTo: mountTo,
@@ -123,15 +92,18 @@ export const PasteActionsMenu = ({
123
92
  zIndex: akEditorFloatingPanelZIndex,
124
93
  alignX: "right",
125
94
  alignY: "bottom",
126
- handleClickOutside: handleDismiss,
95
+ handleClickOutside: handleClickOutside,
127
96
  handleEscapeKeydown: handleDismiss
128
97
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
129
98
  editorView: editorView
99
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, {
100
+ isOpen: showToolbar,
101
+ setIsOpen: handleSetIsOpen
130
102
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
131
- options: options,
132
103
  onMouseDown: preventEditorFocusLoss,
133
104
  onMouseEnter: handleMouseEnter,
134
105
  aiSurface: aiSurface,
135
- aiSurfaceComponents: aiSurfaceComponents
136
- })));
106
+ aiSurfaceComponents: aiSurfaceComponents,
107
+ pasteSurfaceComponents: pasteSurfaceComponents
108
+ }))));
137
109
  };
@@ -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}
@@ -0,0 +1,187 @@
1
+ /* PasteMenuComponents.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./PasteMenuComponents.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React, { useCallback } from 'react';
5
+ import { cx } from '@compiled/react';
6
+ import { useIntl } from 'react-intl-next';
7
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
8
+ import { pasteOptionsToolbarMessages as messages } from '@atlaskit/editor-common/messages';
9
+ import { useEditorToolbar, PASTE_MENU, PASTE_MENU_SECTION, PASTE_NESTED_MENU, PASTE_MENU_NESTED_SECTION, PASTE_RICH_TEXT_MENU_ITEM, PASTE_MARKDOWN_MENU_ITEM, PASTE_PLAIN_TEXT_MENU_ITEM, PASTE_MENU_RANK, PASTE_MENU_SECTION_RANK, PASTE_NESTED_MENU_RANK, PASTE_MENU_NESTED_SECTION_RANK } from '@atlaskit/editor-common/toolbar';
10
+ import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownMenu } from '@atlaskit/editor-toolbar';
11
+ import ChevronRightIcon from '@atlaskit/icon/core/chevron-right';
12
+ import ClipboardIcon from '@atlaskit/icon/core/clipboard';
13
+ import { Box } from '@atlaskit/primitives/compiled';
14
+ import { changeToMarkdownWithAnalytics, changeToPlainTextWithAnalytics, changeToRichTextWithAnalytics } from '../../editor-commands/commands';
15
+ import { ToolbarDropdownOption } from '../../types/types';
16
+ const nestedMenuStyles = {
17
+ narrowSection: "_10gv1lit"
18
+ };
19
+ export const isPasteOptionSelected = (pasteType, selectedOption) => {
20
+ switch (pasteType) {
21
+ case 'rich-text':
22
+ return selectedOption === ToolbarDropdownOption.RichText;
23
+ case 'markdown':
24
+ return selectedOption === ToolbarDropdownOption.Markdown;
25
+ case 'plain-text':
26
+ return selectedOption === ToolbarDropdownOption.PlainText;
27
+ default:
28
+ return false;
29
+ }
30
+ };
31
+ const PasteMenuItem = ({
32
+ api,
33
+ editorAnalyticsAPI,
34
+ pasteType
35
+ }) => {
36
+ const intl = useIntl();
37
+ const {
38
+ editorView
39
+ } = useEditorToolbar();
40
+ const {
41
+ selectedOption,
42
+ plaintextLength,
43
+ isPlainText
44
+ } = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], states => {
45
+ var _pluginState$selected, _pluginState$plaintex, _pluginState$isPlainT;
46
+ const pluginState = states.pasteOptionsToolbarPluginState;
47
+ return {
48
+ selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
49
+ plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0,
50
+ isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false
51
+ };
52
+ });
53
+ const getDefaultLabel = useCallback(type => {
54
+ switch (type) {
55
+ case 'rich-text':
56
+ return intl.formatMessage(messages.richTextAction);
57
+ case 'markdown':
58
+ return intl.formatMessage(messages.markdownAction);
59
+ case 'plain-text':
60
+ return intl.formatMessage(messages.plainTextAction);
61
+ default:
62
+ return type;
63
+ }
64
+ }, [intl]);
65
+ const handleClick = useCallback(e => {
66
+ e.preventDefault();
67
+ if (!editorView) {
68
+ return;
69
+ }
70
+ switch (pasteType) {
71
+ case 'rich-text':
72
+ changeToRichTextWithAnalytics(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
73
+ break;
74
+ case 'markdown':
75
+ changeToMarkdownWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
76
+ break;
77
+ case 'plain-text':
78
+ changeToPlainTextWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
79
+ break;
80
+ }
81
+ }, [editorView, editorAnalyticsAPI, plaintextLength, pasteType]);
82
+ if (pasteType === 'rich-text' && isPlainText) {
83
+ return null;
84
+ }
85
+ const displayLabel = getDefaultLabel(pasteType);
86
+ const isSelected = isPasteOptionSelected(pasteType, selectedOption);
87
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
88
+ onClick: handleClick,
89
+ isSelected: isSelected,
90
+ testId: `paste-${pasteType}-menu-item`,
91
+ hasNestedDropdownMenu: true
92
+ }, displayLabel);
93
+ };
94
+ const PasteOptionsNestedMenu = ({
95
+ children
96
+ }) => {
97
+ const intl = useIntl();
98
+ return /*#__PURE__*/React.createElement(ToolbarNestedDropdownMenu, {
99
+ elemBefore: /*#__PURE__*/React.createElement(ClipboardIcon, {
100
+ size: "small",
101
+ label: intl.formatMessage(messages.pasteOptions)
102
+ }),
103
+ elemAfter: /*#__PURE__*/React.createElement(ChevronRightIcon, {
104
+ size: "small",
105
+ label: intl.formatMessage(messages.pasteOptions)
106
+ }),
107
+ testId: "paste-options-nested-menu",
108
+ text: intl.formatMessage(messages.pasteOptions)
109
+ }, children);
110
+ };
111
+ export const getPasteMenuComponents = ({
112
+ api,
113
+ editorAnalyticsAPI
114
+ }) => [{
115
+ type: PASTE_MENU.type,
116
+ key: PASTE_MENU.key
117
+ }, {
118
+ type: PASTE_MENU_SECTION.type,
119
+ key: PASTE_MENU_SECTION.key,
120
+ parents: [{
121
+ type: PASTE_MENU.type,
122
+ key: PASTE_MENU.key,
123
+ rank: PASTE_MENU_RANK[PASTE_MENU_SECTION.key]
124
+ }],
125
+ component: props => /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
126
+ hasSeparator: true
127
+ }, props.children)
128
+ }, {
129
+ type: PASTE_NESTED_MENU.type,
130
+ key: PASTE_NESTED_MENU.key,
131
+ parents: [{
132
+ type: PASTE_MENU_SECTION.type,
133
+ key: PASTE_MENU_SECTION.key,
134
+ rank: PASTE_MENU_SECTION_RANK[PASTE_NESTED_MENU.key]
135
+ }],
136
+ component: props => /*#__PURE__*/React.createElement(PasteOptionsNestedMenu, null, props.children)
137
+ }, {
138
+ type: PASTE_MENU_NESTED_SECTION.type,
139
+ key: PASTE_MENU_NESTED_SECTION.key,
140
+ parents: [{
141
+ type: PASTE_NESTED_MENU.type,
142
+ key: PASTE_NESTED_MENU.key,
143
+ rank: PASTE_NESTED_MENU_RANK[PASTE_MENU_NESTED_SECTION.key]
144
+ }],
145
+ component: props => /*#__PURE__*/React.createElement(Box, {
146
+ xcss: cx(nestedMenuStyles.narrowSection)
147
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, null, props.children))
148
+ }, {
149
+ key: PASTE_RICH_TEXT_MENU_ITEM.key,
150
+ type: PASTE_RICH_TEXT_MENU_ITEM.type,
151
+ component: () => /*#__PURE__*/React.createElement(PasteMenuItem, {
152
+ api: api,
153
+ editorAnalyticsAPI: editorAnalyticsAPI,
154
+ pasteType: "rich-text"
155
+ }),
156
+ parents: [{
157
+ key: PASTE_MENU_NESTED_SECTION.key,
158
+ type: PASTE_MENU_NESTED_SECTION.type,
159
+ rank: PASTE_MENU_NESTED_SECTION_RANK[PASTE_RICH_TEXT_MENU_ITEM.key]
160
+ }]
161
+ }, {
162
+ key: PASTE_MARKDOWN_MENU_ITEM.key,
163
+ type: PASTE_MARKDOWN_MENU_ITEM.type,
164
+ component: () => /*#__PURE__*/React.createElement(PasteMenuItem, {
165
+ api: api,
166
+ editorAnalyticsAPI: editorAnalyticsAPI,
167
+ pasteType: "markdown"
168
+ }),
169
+ parents: [{
170
+ key: PASTE_MENU_NESTED_SECTION.key,
171
+ type: PASTE_MENU_NESTED_SECTION.type,
172
+ rank: PASTE_MENU_NESTED_SECTION_RANK[PASTE_MARKDOWN_MENU_ITEM.key]
173
+ }]
174
+ }, {
175
+ key: PASTE_PLAIN_TEXT_MENU_ITEM.key,
176
+ type: PASTE_PLAIN_TEXT_MENU_ITEM.type,
177
+ component: () => /*#__PURE__*/React.createElement(PasteMenuItem, {
178
+ api: api,
179
+ editorAnalyticsAPI: editorAnalyticsAPI,
180
+ pasteType: "plain-text"
181
+ }),
182
+ parents: [{
183
+ key: PASTE_MENU_NESTED_SECTION.key,
184
+ type: PASTE_MENU_NESTED_SECTION.type,
185
+ rank: PASTE_MENU_NESTED_SECTION_RANK[PASTE_PLAIN_TEXT_MENU_ITEM.key]
186
+ }]
187
+ }];
@@ -8,11 +8,19 @@ import { hideToolbar, showToolbar } from './editor-commands/commands';
8
8
  import { createPlugin } from './pm-plugins/main';
9
9
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from './types/types';
10
10
  import { PasteActionsMenu } from './ui/on-paste-actions-menu/PasteActionsMenu';
11
+ import { getPasteMenuComponents } from './ui/on-paste-actions-menu/PasteMenuComponents';
11
12
  import { buildToolbar, isToolbarVisible } from './ui/toolbar';
12
13
  export var pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref) {
13
14
  var _api$analytics;
14
15
  var api = _ref.api;
15
16
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
17
+ if (expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)) {
18
+ var _api$uiControlRegistr;
19
+ api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register(getPasteMenuComponents({
20
+ api: api,
21
+ editorAnalyticsAPI: editorAnalyticsAPI
22
+ }));
23
+ }
16
24
  var getSharedState = function getSharedState(editorState) {
17
25
  var _pluginState$isPlainT, _pluginState$pasteEnd, _pluginState$pasteSta, _pluginState$plaintex, _pluginState$selected, _pluginState$showTool;
18
26
  if (!editorState) {
@@ -42,7 +50,9 @@ export var pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref)
42
50
  name: 'pasteOptionsToolbarPlugin',
43
51
  plugin: function plugin(_ref2) {
44
52
  var dispatch = _ref2.dispatch;
45
- return createPlugin(dispatch);
53
+ return createPlugin(dispatch, {
54
+ useNewPasteMenu: expValEquals('platform_editor_paste_actions_menu', 'isEnabled', true)
55
+ });
46
56
  }
47
57
  }];
48
58
  }
@@ -74,8 +84,7 @@ export var pasteOptionsToolbarPlugin = function pasteOptionsToolbarPlugin(_ref)
74
84
  editorView: editorView,
75
85
  mountTo: popupsMountPoint,
76
86
  boundariesElement: popupsBoundariesElement,
77
- scrollableElement: popupsScrollableElement,
78
- editorAnalyticsAPI: editorAnalyticsAPI
87
+ scrollableElement: popupsScrollableElement
79
88
  });
80
89
  },
81
90
  usePluginHook: function usePluginHook(_ref4) {
@@ -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: function view(editorView) {
22
+ view: function view(_editorView) {
23
23
  return {
24
24
  update: function 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: function 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
  },
@@ -1,14 +1,12 @@
1
- import React, { useCallback, useMemo } from 'react';
2
- import { useIntl } from 'react-intl-next';
1
+ import React, { useCallback } 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';
11
- import { ToolbarDropdownOption } from '../../types/types';
8
+ import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
9
+ import { hideToolbar, highlightContent } from '../../editor-commands/commands';
12
10
  import { PasteActionsMenuContent } from './PasteActionsMenuContent';
13
11
  var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
14
12
  function getTargetElement(editorView) {
@@ -31,28 +29,20 @@ function getPopupOffset(dom) {
31
29
  return [-(window.innerWidth - rightEdge - 50), 20];
32
30
  }
33
31
  export var PasteActionsMenu = function PasteActionsMenu(_ref) {
34
- var _api$uiControlRegistr, _api$uiControlRegistr2;
32
+ var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
35
33
  var api = _ref.api,
36
34
  editorView = _ref.editorView,
37
35
  mountTo = _ref.mountTo,
38
36
  boundariesElement = _ref.boundariesElement,
39
- scrollableElement = _ref.scrollableElement,
40
- editorAnalyticsAPI = _ref.editorAnalyticsAPI;
41
- var intl = useIntl();
37
+ scrollableElement = _ref.scrollableElement;
42
38
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
43
- var _pluginState$showTool, _pluginState$isPlainT, _pluginState$selected, _pluginState$plaintex;
39
+ var _pluginState$showTool;
44
40
  var pluginState = states.pasteOptionsToolbarPluginState;
45
41
  return {
46
- showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false,
47
- isPlainText: (_pluginState$isPlainT = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPlainText) !== null && _pluginState$isPlainT !== void 0 ? _pluginState$isPlainT : false,
48
- selectedOption: (_pluginState$selected = pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectedOption) !== null && _pluginState$selected !== void 0 ? _pluginState$selected : ToolbarDropdownOption.None,
49
- plaintextLength: (_pluginState$plaintex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.plaintextLength) !== null && _pluginState$plaintex !== void 0 ? _pluginState$plaintex : 0
42
+ showToolbar: (_pluginState$showTool = pluginState === null || pluginState === void 0 ? void 0 : pluginState.showToolbar) !== null && _pluginState$showTool !== void 0 ? _pluginState$showTool : false
50
43
  };
51
44
  }),
52
- showToolbar = _useSharedPluginState.showToolbar,
53
- isPlainText = _useSharedPluginState.isPlainText,
54
- selectedOption = _useSharedPluginState.selectedOption,
55
- plaintextLength = _useSharedPluginState.plaintextLength;
45
+ showToolbar = _useSharedPluginState.showToolbar;
56
46
  var preventEditorFocusLoss = useCallback(function (e) {
57
47
  e.preventDefault();
58
48
  }, []);
@@ -62,42 +52,20 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
62
52
  var handleMouseEnter = useCallback(function () {
63
53
  highlightContent()(editorView.state, editorView.dispatch);
64
54
  }, [editorView]);
65
- var handleRichText = useCallback(function (e) {
66
- e.preventDefault();
67
- changeToRichTextWithAnalytics(editorAnalyticsAPI)()(editorView.state, editorView.dispatch);
68
- }, [editorView, editorAnalyticsAPI]);
69
- var handleMarkdown = useCallback(function (e) {
70
- e.preventDefault();
71
- changeToMarkdownWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
72
- }, [editorView, editorAnalyticsAPI, plaintextLength]);
73
- var handlePlainText = useCallback(function (e) {
74
- e.preventDefault();
75
- changeToPlainTextWithAnalytics(editorAnalyticsAPI, plaintextLength)()(editorView.state, editorView.dispatch);
76
- }, [editorView, editorAnalyticsAPI, plaintextLength]);
77
- var options = useMemo(function () {
78
- var items = [];
79
- if (!isPlainText) {
80
- items.push({
81
- id: 'editor.paste.richText',
82
- label: intl.formatMessage(messages.richText),
83
- selected: selectedOption === ToolbarDropdownOption.RichText,
84
- onClick: handleRichText
85
- });
55
+ var handleClickOutside = useCallback(function (evt) {
56
+ if (evt.target instanceof Element) {
57
+ var isInsideNestedDropdown = evt.target.closest('[data-toolbar-nested-dropdown-menu]');
58
+ if (isInsideNestedDropdown) {
59
+ return;
60
+ }
61
+ }
62
+ handleDismiss();
63
+ }, [handleDismiss]);
64
+ var handleSetIsOpen = useCallback(function (isOpen) {
65
+ if (!isOpen) {
66
+ handleDismiss();
86
67
  }
87
- items.push({
88
- id: 'editor.paste.markdown',
89
- label: intl.formatMessage(messages.markdown),
90
- selected: selectedOption === ToolbarDropdownOption.Markdown,
91
- onClick: handleMarkdown
92
- });
93
- items.push({
94
- id: 'editor.paste.plainText',
95
- label: intl.formatMessage(messages.plainText),
96
- selected: selectedOption === ToolbarDropdownOption.PlainText,
97
- onClick: handlePlainText
98
- });
99
- return items;
100
- }, [isPlainText, selectedOption, intl, handleRichText, handleMarkdown, handlePlainText]);
68
+ }, [handleDismiss]);
101
69
  if (!showToolbar) {
102
70
  return null;
103
71
  }
@@ -110,6 +78,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
110
78
  key: 'ai-paste-menu'
111
79
  };
112
80
  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 : [];
81
+ var pasteSurfaceComponents = (_api$uiControlRegistr3 = api === null || api === 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 : [];
113
82
  return /*#__PURE__*/React.createElement(PopupWithListeners, {
114
83
  target: target,
115
84
  mountTo: mountTo,
@@ -119,15 +88,18 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
119
88
  zIndex: akEditorFloatingPanelZIndex,
120
89
  alignX: "right",
121
90
  alignY: "bottom",
122
- handleClickOutside: handleDismiss,
91
+ handleClickOutside: handleClickOutside,
123
92
  handleEscapeKeydown: handleDismiss
124
93
  }, /*#__PURE__*/React.createElement(EditorToolbarProvider, {
125
94
  editorView: editorView
95
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, {
96
+ isOpen: showToolbar,
97
+ setIsOpen: handleSetIsOpen
126
98
  }, /*#__PURE__*/React.createElement(PasteActionsMenuContent, {
127
- options: options,
128
99
  onMouseDown: preventEditorFocusLoss,
129
100
  onMouseEnter: handleMouseEnter,
130
101
  aiSurface: aiSurface,
131
- aiSurfaceComponents: aiSurfaceComponents
132
- })));
102
+ aiSurfaceComponents: aiSurfaceComponents,
103
+ pasteSurfaceComponents: pasteSurfaceComponents
104
+ }))));
133
105
  };
@@ -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
  var 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 var PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
15
- var options = _ref.options,
16
- onMouseDown = _ref.onMouseDown,
12
+ var onMouseDown = _ref.onMouseDown,
17
13
  onMouseEnter = _ref.onMouseEnter,
18
14
  aiSurface = _ref.aiSurface,
19
- aiSurfaceComponents = _ref.aiSurfaceComponents;
15
+ aiSurfaceComponents = _ref.aiSurfaceComponents,
16
+ pasteSurfaceComponents = _ref.pasteSurfaceComponents;
20
17
  var setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
21
18
  return /*#__PURE__*/React.createElement(Box, {
22
19
  ref: setOutsideClickTargetRef,
@@ -26,11 +23,11 @@ export var PasteActionsMenuContent = function PasteActionsMenuContent(_ref) {
26
23
  }, aiSurface && aiSurfaceComponents && aiSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
27
24
  surface: aiSurface,
28
25
  components: aiSurfaceComponents
29
- }), options.map(function (option) {
30
- return /*#__PURE__*/React.createElement(Pressable, {
31
- key: option.id,
32
- xcss: cx(styles.option, option.selected && styles.selectedOption),
33
- onClick: option.onClick
34
- }, option.label);
26
+ }), pasteSurfaceComponents && pasteSurfaceComponents.length > 0 && /*#__PURE__*/React.createElement(SurfaceRenderer, {
27
+ surface: {
28
+ type: 'menu',
29
+ key: 'paste-menu'
30
+ },
31
+ components: pasteSurfaceComponents
35
32
  }));
36
33
  };