@atlaskit/editor-plugin-insert-block 8.4.4 → 8.5.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.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/insertBlockPlugin.js +17 -0
- package/dist/cjs/pm-plugins/experiences/toolbar-action-experiences.js +183 -0
- package/dist/cjs/pm-plugins/experiences/toolbar-experience-utils.js +409 -0
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +18 -5
- package/dist/cjs/ui/toolbar-components/EmojiButton.js +3 -1
- package/dist/cjs/ui/toolbar-components/ImageButton.js +2 -1
- package/dist/cjs/ui/toolbar-components/InsertButton.js +2 -1
- package/dist/cjs/ui/toolbar-components/LayoutButton.js +2 -1
- package/dist/cjs/ui/toolbar-components/MediaButton.js +3 -1
- package/dist/cjs/ui/toolbar-components/MentionButton.js +3 -1
- package/dist/cjs/ui/toolbar-components/TableButton.js +1 -1
- package/dist/cjs/ui/toolbar-components/TableSizePicker.js +3 -1
- package/dist/cjs/ui/toolbar-components/TaskListButton.js +2 -1
- package/dist/es2019/insertBlockPlugin.js +15 -0
- package/dist/es2019/pm-plugins/experiences/toolbar-action-experiences.js +173 -0
- package/dist/es2019/pm-plugins/experiences/toolbar-experience-utils.js +279 -0
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +15 -4
- package/dist/es2019/ui/toolbar-components/EmojiButton.js +3 -1
- package/dist/es2019/ui/toolbar-components/ImageButton.js +3 -2
- package/dist/es2019/ui/toolbar-components/InsertButton.js +3 -2
- package/dist/es2019/ui/toolbar-components/LayoutButton.js +3 -2
- package/dist/es2019/ui/toolbar-components/MediaButton.js +3 -1
- package/dist/es2019/ui/toolbar-components/MentionButton.js +3 -1
- package/dist/es2019/ui/toolbar-components/TableButton.js +2 -2
- package/dist/es2019/ui/toolbar-components/TableSizePicker.js +3 -1
- package/dist/es2019/ui/toolbar-components/TaskListButton.js +3 -2
- package/dist/esm/insertBlockPlugin.js +17 -0
- package/dist/esm/pm-plugins/experiences/toolbar-action-experiences.js +177 -0
- package/dist/esm/pm-plugins/experiences/toolbar-experience-utils.js +403 -0
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +17 -4
- package/dist/esm/ui/toolbar-components/EmojiButton.js +3 -1
- package/dist/esm/ui/toolbar-components/ImageButton.js +3 -2
- package/dist/esm/ui/toolbar-components/InsertButton.js +3 -2
- package/dist/esm/ui/toolbar-components/LayoutButton.js +3 -2
- package/dist/esm/ui/toolbar-components/MediaButton.js +3 -1
- package/dist/esm/ui/toolbar-components/MentionButton.js +3 -1
- package/dist/esm/ui/toolbar-components/TableButton.js +2 -2
- package/dist/esm/ui/toolbar-components/TableSizePicker.js +3 -1
- package/dist/esm/ui/toolbar-components/TaskListButton.js +3 -2
- package/dist/types/pm-plugins/experiences/toolbar-action-experiences.d.ts +10 -0
- package/dist/types/pm-plugins/experiences/toolbar-experience-utils.d.ts +57 -0
- package/dist/types/ui/ElementBrowser/InsertMenu.d.ts +5 -2
- package/dist/types-ts4.5/pm-plugins/experiences/toolbar-action-experiences.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/experiences/toolbar-experience-utils.d.ts +57 -0
- package/dist/types-ts4.5/ui/ElementBrowser/InsertMenu.d.ts +5 -2
- package/package.json +6 -2
|
@@ -17,15 +17,26 @@ import { messages, IconCode, IconDate, IconDecision, IconDivider, IconExpand, Ic
|
|
|
17
17
|
import { OutsideClickTargetRefContext, withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
18
18
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
19
19
|
import { N0, N30A, N60A } from '@atlaskit/theme/colors';
|
|
20
|
+
import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
20
21
|
export const DEFAULT_HEIGHT = 560;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
* Exported helper to allow testing of InsertMenu
|
|
24
|
+
* Exported helper to allow testing of InsertMenu pinning logic. NOTE: this is
|
|
24
25
|
*not* the ideal way to approach this, quickinsert plugin provides a `getSuggestions`
|
|
25
26
|
method that can be used to get suggestions -> once all experiments are cleaned up,
|
|
26
27
|
they should be unified through `pluginInjectionApi?.quickInsert?.actions.getSuggestions`
|
|
28
|
+
|
|
29
|
+
`cc_fd_db_top_editor_toolbar` experiment adds new logic to sort elements by `priority`
|
|
30
|
+
this newer implementation matches how the "quick insert menu" sorts elements
|
|
27
31
|
*/
|
|
28
|
-
export const
|
|
32
|
+
export const sortPrioritizedElements = (featuredItems, formatMessage) => {
|
|
33
|
+
if (['new-description', 'orig-description'].includes(expVal('cc_fd_db_top_editor_toolbar', 'cohort', 'control'))) {
|
|
34
|
+
// Sort by priority (lower first) on the concatenated list so items
|
|
35
|
+
// with "priority" are at the top (e.g. Whiteboard before Database)
|
|
36
|
+
return featuredItems.slice(0).sort((a, b) => (a.priority || Number.POSITIVE_INFINITY) - (b.priority || Number.POSITIVE_INFINITY));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// old logic sort whiteboards to top
|
|
29
40
|
const DIAGRAM_KEY = 'whiteboard-extension:create-diagram';
|
|
30
41
|
const isDiagram = item => item.key === DIAGRAM_KEY;
|
|
31
42
|
const featuredWhiteboardsPresent = featuredItems.some(isDiagram);
|
|
@@ -142,8 +153,8 @@ const InsertMenu = ({
|
|
|
142
153
|
isDisabled: true
|
|
143
154
|
} : item)) !== null && _pluginInjectionApi$q5 !== void 0 ? _pluginInjectionApi$q5 : [];
|
|
144
155
|
const unfilteredResult = quickInsertDropdownItems.concat(featuredQuickInsertSuggestions);
|
|
145
|
-
// need to
|
|
146
|
-
result =
|
|
156
|
+
// need to sort on the concatenated list so desired elements are at the top
|
|
157
|
+
result = sortPrioritizedElements(unfilteredResult, formatMessage);
|
|
147
158
|
}
|
|
148
159
|
setItemCount(result.length);
|
|
149
160
|
return result;
|
|
@@ -3,6 +3,7 @@ import { useIntl } from 'react-intl-next';
|
|
|
3
3
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { ToolTipContent, insertEmoji } from '@atlaskit/editor-common/keymaps';
|
|
5
5
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
6
7
|
import { ToolbarButton, ToolbarTooltip, EmojiIcon, useToolbarUI } from '@atlaskit/editor-toolbar';
|
|
7
8
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
8
9
|
import { useEmojiPickerPopup } from './hooks/useEmojiPickerPopup';
|
|
@@ -69,6 +70,7 @@ export const EmojiButton = ({
|
|
|
69
70
|
ref: emojiButtonRef,
|
|
70
71
|
onClick: () => emojiPickerPopup.toggle(),
|
|
71
72
|
isSelected: emojiPickerPopup.isOpen,
|
|
72
|
-
isDisabled: !isTypeAheadAllowed || !emojiProvider
|
|
73
|
+
isDisabled: !isTypeAheadAllowed || !emojiProvider,
|
|
74
|
+
testId: TOOLBAR_BUTTON_TEST_ID.EMOJI
|
|
73
75
|
})));
|
|
74
76
|
};
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useIntl } from 'react-intl-next';
|
|
3
3
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
|
-
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
5
|
+
import { useEditorToolbar, TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
6
6
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
7
7
|
import { ToolbarButton, ToolbarTooltip, ImageIcon } from '@atlaskit/editor-toolbar';
|
|
8
8
|
export const ImageButton = ({
|
|
@@ -43,6 +43,7 @@ export const ImageButton = ({
|
|
|
43
43
|
size: "small"
|
|
44
44
|
}),
|
|
45
45
|
onClick: onClick,
|
|
46
|
-
isDisabled: !imageUploadEnabled || isOffline
|
|
46
|
+
isDisabled: !imageUploadEnabled || isOffline,
|
|
47
|
+
testId: TOOLBAR_BUTTON_TEST_ID.IMAGE
|
|
47
48
|
}));
|
|
48
49
|
};
|
|
@@ -3,7 +3,7 @@ import { useIntl } from 'react-intl-next';
|
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { getAriaKeyshortcuts, insertElements, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
5
5
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
-
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
6
|
+
import { TOOLBAR_BUTTON_TEST_ID, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
7
7
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
8
8
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
9
9
|
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
@@ -242,6 +242,7 @@ export const InsertButton = ({
|
|
|
242
242
|
ref: insertButtonRef,
|
|
243
243
|
onClick: onClick,
|
|
244
244
|
isSelected: insertMenuOpen,
|
|
245
|
-
isDisabled: !isTypeAheadAllowed || isDisabled
|
|
245
|
+
isDisabled: !isTypeAheadAllowed || isDisabled,
|
|
246
|
+
testId: TOOLBAR_BUTTON_TEST_ID.INSERT
|
|
246
247
|
})));
|
|
247
248
|
};
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useIntl } from 'react-intl-next';
|
|
3
3
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
|
-
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
5
|
+
import { useEditorToolbar, TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
6
6
|
import { ToolbarButton, ToolbarTooltip, LayoutIcon } from '@atlaskit/editor-toolbar';
|
|
7
7
|
export const LayoutButton = ({
|
|
8
8
|
api
|
|
@@ -33,6 +33,7 @@ export const LayoutButton = ({
|
|
|
33
33
|
label: formatMessage(messages.columns),
|
|
34
34
|
size: "small"
|
|
35
35
|
}),
|
|
36
|
-
onClick: onClick
|
|
36
|
+
onClick: onClick,
|
|
37
|
+
testId: TOOLBAR_BUTTON_TEST_ID.LAYOUT
|
|
37
38
|
}));
|
|
38
39
|
};
|
|
@@ -3,6 +3,7 @@ import { useIntl } from 'react-intl-next';
|
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
5
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
+
import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
6
7
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
7
8
|
import { ToolbarButton, ToolbarTooltip, ImageIcon } from '@atlaskit/editor-toolbar';
|
|
8
9
|
export const MediaButton = ({
|
|
@@ -62,6 +63,7 @@ export const MediaButton = ({
|
|
|
62
63
|
}),
|
|
63
64
|
onClick: onClick,
|
|
64
65
|
ref: mediaButtonRef,
|
|
65
|
-
isDisabled: isOffline || !allowsUploads
|
|
66
|
+
isDisabled: isOffline || !allowsUploads,
|
|
67
|
+
testId: TOOLBAR_BUTTON_TEST_ID.MEDIA
|
|
66
68
|
}));
|
|
67
69
|
};
|
|
@@ -4,6 +4,7 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
|
4
4
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
5
5
|
import { ToolTipContent, insertMention } from '@atlaskit/editor-common/keymaps';
|
|
6
6
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
|
+
import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
7
8
|
import { ToolbarButton, ToolbarTooltip, MentionIcon } from '@atlaskit/editor-toolbar';
|
|
8
9
|
export const MentionButton = ({
|
|
9
10
|
api
|
|
@@ -42,6 +43,7 @@ export const MentionButton = ({
|
|
|
42
43
|
}),
|
|
43
44
|
onClick: onClick,
|
|
44
45
|
ariaKeyshortcuts: "Shift+2 Space",
|
|
45
|
-
isDisabled: !canInsertMention || !mentionProvider || !isTypeAheadAllowed
|
|
46
|
+
isDisabled: !canInsertMention || !mentionProvider || !isTypeAheadAllowed,
|
|
47
|
+
testId: TOOLBAR_BUTTON_TEST_ID.MENTION
|
|
46
48
|
}));
|
|
47
49
|
};
|
|
@@ -3,7 +3,7 @@ import { useIntl } from 'react-intl-next';
|
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { ToolTipContent, getAriaKeyshortcuts, toggleTable } from '@atlaskit/editor-common/keymaps';
|
|
5
5
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
-
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
6
|
+
import { useEditorToolbar, TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
7
7
|
import { ToolbarButton, ToolbarTooltip, TableIcon } from '@atlaskit/editor-toolbar';
|
|
8
8
|
export const TableButton = ({
|
|
9
9
|
api
|
|
@@ -50,6 +50,6 @@ export const TableButton = ({
|
|
|
50
50
|
}),
|
|
51
51
|
onClick: onClick,
|
|
52
52
|
ariaKeyshortcuts: getAriaKeyshortcuts(toggleTable),
|
|
53
|
-
testId:
|
|
53
|
+
testId: TOOLBAR_BUTTON_TEST_ID.TABLE
|
|
54
54
|
}));
|
|
55
55
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl-next';
|
|
3
3
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
4
5
|
import { MoreItemsIcon, ToolbarButton, ToolbarTooltip, useToolbarUI } from '@atlaskit/editor-toolbar';
|
|
5
6
|
import { useTableSelectorPopup } from './hooks/useTableSelectorPopup';
|
|
6
7
|
import { TableSelectorPopupWrapper } from './popups/TableSelectorPopupWrapper';
|
|
@@ -49,6 +50,7 @@ export const TableSizePicker = ({
|
|
|
49
50
|
}),
|
|
50
51
|
onClick: onClick,
|
|
51
52
|
isSelected: tableSelectorPopup.isOpen,
|
|
52
|
-
ref: tableSizePickerRef
|
|
53
|
+
ref: tableSizePickerRef,
|
|
54
|
+
testId: TOOLBAR_BUTTON_TEST_ID.TABLE_SELECTOR
|
|
53
55
|
})));
|
|
54
56
|
};
|
|
@@ -3,7 +3,7 @@ import { useIntl } from 'react-intl-next';
|
|
|
3
3
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { ToolTipContent, insertTaskList } from '@atlaskit/editor-common/keymaps';
|
|
5
5
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
|
-
import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
6
|
+
import { TOOLBAR_BUTTON_TEST_ID, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
|
|
7
7
|
import { ToolbarButton, ToolbarTooltip, TaskIcon } from '@atlaskit/editor-toolbar';
|
|
8
8
|
export const TaskListButton = ({
|
|
9
9
|
api
|
|
@@ -38,6 +38,7 @@ export const TaskListButton = ({
|
|
|
38
38
|
size: "small"
|
|
39
39
|
}),
|
|
40
40
|
onClick: onClick,
|
|
41
|
-
ariaKeyshortcuts: "[ ] Space"
|
|
41
|
+
ariaKeyshortcuts: "[ ] Space",
|
|
42
|
+
testId: TOOLBAR_BUTTON_TEST_ID.TASK_LIST
|
|
42
43
|
}));
|
|
43
44
|
};
|
|
@@ -9,6 +9,7 @@ import { BLOCK_QUOTE, CODE_BLOCK, PANEL } from '@atlaskit/editor-plugin-block-ty
|
|
|
9
9
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
11
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
12
|
+
import { getToolbarActionExperiencesPlugin } from './pm-plugins/experiences/toolbar-action-experiences';
|
|
12
13
|
import { toggleInsertBlockPmKey, toggleInsertBlockPmPlugin } from './pm-plugins/toggleInsertBlock';
|
|
13
14
|
import { getToolbarComponents } from './ui/toolbar-components';
|
|
14
15
|
// Ignored via go/ees005
|
|
@@ -98,6 +99,7 @@ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
|
|
|
98
99
|
options = _ref$config === void 0 ? {} : _ref$config,
|
|
99
100
|
api = _ref.api;
|
|
100
101
|
var isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
|
|
102
|
+
var refs = {};
|
|
101
103
|
var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
|
|
102
104
|
var editorView = _ref2.editorView,
|
|
103
105
|
editorActions = _ref2.editorActions,
|
|
@@ -110,6 +112,7 @@ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
|
|
|
110
112
|
disabled = _ref2.disabled,
|
|
111
113
|
isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
|
|
112
114
|
isLastItem = _ref2.isLastItem;
|
|
115
|
+
refs.popupsMountPoint = popupsMountPoint || undefined;
|
|
113
116
|
var renderNode = function renderNode(providers) {
|
|
114
117
|
if (!editorView) {
|
|
115
118
|
return null;
|
|
@@ -216,6 +219,20 @@ export var insertBlockPlugin = function insertBlockPlugin(_ref) {
|
|
|
216
219
|
return toggleInsertBlockPmPlugin();
|
|
217
220
|
}
|
|
218
221
|
});
|
|
222
|
+
if (fg('platform_editor_experience_tracking_toolbar_button')) {
|
|
223
|
+
plugins.push({
|
|
224
|
+
name: 'toolbarActionExperiences',
|
|
225
|
+
plugin: function plugin() {
|
|
226
|
+
return getToolbarActionExperiencesPlugin({
|
|
227
|
+
refs: refs,
|
|
228
|
+
dispatchAnalyticsEvent: function dispatchAnalyticsEvent(payload) {
|
|
229
|
+
var _api$analytics;
|
|
230
|
+
return api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 ? void 0 : _api$analytics.fireAnalyticsEvent(payload);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
219
236
|
return plugins;
|
|
220
237
|
},
|
|
221
238
|
pluginsOptions: {},
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { bind } from 'bind-event-listener';
|
|
2
|
+
import { getDocument } from '@atlaskit/browser-apis';
|
|
3
|
+
import { Experience, EXPERIENCE_ID, ExperienceCheckDomMutation, ExperienceCheckTimeout, getPopupContainerFromEditorView } from '@atlaskit/editor-common/experiences';
|
|
4
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
+
import { TOOLBAR_BUTTON_TEST_ID } from '@atlaskit/editor-common/toolbar';
|
|
6
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import { ExperienceCheckPopupMutation, getParentDOMAtSelection, handleEditorNodeInsertDomMutation, handleTypeAheadOpenDomMutation, isToolbarButtonClick } from './toolbar-experience-utils';
|
|
8
|
+
var pluginKey = new PluginKey('toolbarActionExperiences');
|
|
9
|
+
var TIMEOUT_DURATION = 1000;
|
|
10
|
+
var PRIMARY_TOOLBAR = 'primaryToolbar';
|
|
11
|
+
var ABORT_REASON = {
|
|
12
|
+
USER_CANCELED: 'userCanceled',
|
|
13
|
+
EDITOR_DESTROYED: 'editorDestroyed'
|
|
14
|
+
};
|
|
15
|
+
export var getToolbarActionExperiencesPlugin = function getToolbarActionExperiencesPlugin(_ref) {
|
|
16
|
+
var refs = _ref.refs,
|
|
17
|
+
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
|
|
18
|
+
var editorView;
|
|
19
|
+
var popupTargetEl;
|
|
20
|
+
var getPopupsTarget = function getPopupsTarget() {
|
|
21
|
+
if (!popupTargetEl) {
|
|
22
|
+
var _editorView;
|
|
23
|
+
popupTargetEl = refs.popupsMountPoint || getPopupContainerFromEditorView((_editorView = editorView) === null || _editorView === void 0 ? void 0 : _editorView.dom);
|
|
24
|
+
}
|
|
25
|
+
return popupTargetEl;
|
|
26
|
+
};
|
|
27
|
+
var getEditorDom = function getEditorDom() {
|
|
28
|
+
var _editorView2;
|
|
29
|
+
if (((_editorView2 = editorView) === null || _editorView2 === void 0 ? void 0 : _editorView2.dom) instanceof HTMLElement) {
|
|
30
|
+
return editorView.dom;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
var narrowParentObserveConfig = function narrowParentObserveConfig() {
|
|
35
|
+
var _getParentDOMAtSelect;
|
|
36
|
+
return {
|
|
37
|
+
target: (_getParentDOMAtSelect = getParentDOMAtSelection(editorView)) !== null && _getParentDOMAtSelect !== void 0 ? _getParentDOMAtSelect : getEditorDom(),
|
|
38
|
+
options: {
|
|
39
|
+
childList: true
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var rootObserveConfig = function rootObserveConfig() {
|
|
44
|
+
return {
|
|
45
|
+
target: getEditorDom(),
|
|
46
|
+
options: {
|
|
47
|
+
childList: true
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
var createNodeInsertExperience = function createNodeInsertExperience(action) {
|
|
52
|
+
return new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
53
|
+
action: action,
|
|
54
|
+
actionSubjectId: PRIMARY_TOOLBAR,
|
|
55
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
56
|
+
checks: [new ExperienceCheckTimeout({
|
|
57
|
+
durationMs: TIMEOUT_DURATION
|
|
58
|
+
}), new ExperienceCheckDomMutation({
|
|
59
|
+
onDomMutation: handleEditorNodeInsertDomMutation,
|
|
60
|
+
observeConfig: narrowParentObserveConfig
|
|
61
|
+
}), new ExperienceCheckDomMutation({
|
|
62
|
+
onDomMutation: handleEditorNodeInsertDomMutation,
|
|
63
|
+
observeConfig: rootObserveConfig
|
|
64
|
+
})]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
var createPopupExperience = function createPopupExperience(action, popupSelector) {
|
|
68
|
+
return new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
69
|
+
action: action,
|
|
70
|
+
actionSubjectId: PRIMARY_TOOLBAR,
|
|
71
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
72
|
+
checks: [new ExperienceCheckTimeout({
|
|
73
|
+
durationMs: TIMEOUT_DURATION
|
|
74
|
+
}), new ExperienceCheckPopupMutation(popupSelector, getPopupsTarget, getEditorDom)]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
var experienceButtonMappings = [{
|
|
78
|
+
experience: createPopupExperience('emoji', '[data-emoji-picker-container]'),
|
|
79
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.EMOJI
|
|
80
|
+
}, {
|
|
81
|
+
experience: createPopupExperience('media', '[id="local-media-upload-button"], [data-testid="media-picker-file-input"]'),
|
|
82
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.MEDIA
|
|
83
|
+
}, {
|
|
84
|
+
experience: new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
85
|
+
action: 'mention',
|
|
86
|
+
actionSubjectId: PRIMARY_TOOLBAR,
|
|
87
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
88
|
+
checks: [new ExperienceCheckTimeout({
|
|
89
|
+
durationMs: TIMEOUT_DURATION
|
|
90
|
+
}), new ExperienceCheckDomMutation({
|
|
91
|
+
onDomMutation: handleTypeAheadOpenDomMutation,
|
|
92
|
+
observeConfig: narrowParentObserveConfig
|
|
93
|
+
})]
|
|
94
|
+
}),
|
|
95
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.MENTION
|
|
96
|
+
}, {
|
|
97
|
+
experience: createNodeInsertExperience('table'),
|
|
98
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.TABLE
|
|
99
|
+
}, {
|
|
100
|
+
experience: createPopupExperience('tableSelector', '[aria-label*="table size"], [data-testid*="table-selector"]'),
|
|
101
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.TABLE_SELECTOR
|
|
102
|
+
}, {
|
|
103
|
+
experience: createNodeInsertExperience('layout'),
|
|
104
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.LAYOUT
|
|
105
|
+
}, {
|
|
106
|
+
experience: createPopupExperience('image', '[id="local-media-upload-button"], [data-testid="media-picker-file-input"]'),
|
|
107
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.IMAGE
|
|
108
|
+
}, {
|
|
109
|
+
experience: createNodeInsertExperience('action'),
|
|
110
|
+
buttonTestId: TOOLBAR_BUTTON_TEST_ID.TASK_LIST
|
|
111
|
+
}];
|
|
112
|
+
var handleToolbarButtonClick = function handleToolbarButtonClick(target) {
|
|
113
|
+
for (var _i = 0, _experienceButtonMapp = experienceButtonMappings; _i < _experienceButtonMapp.length; _i++) {
|
|
114
|
+
var _experienceButtonMapp2 = _experienceButtonMapp[_i],
|
|
115
|
+
experience = _experienceButtonMapp2.experience,
|
|
116
|
+
buttonTestId = _experienceButtonMapp2.buttonTestId;
|
|
117
|
+
if (isToolbarButtonClick(target, buttonTestId)) {
|
|
118
|
+
experience.start({
|
|
119
|
+
forceRestart: true
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var abortAllExperiences = function abortAllExperiences(reason) {
|
|
126
|
+
for (var _i2 = 0, _experienceButtonMapp3 = experienceButtonMappings; _i2 < _experienceButtonMapp3.length; _i2++) {
|
|
127
|
+
var experience = _experienceButtonMapp3[_i2].experience;
|
|
128
|
+
experience.abort({
|
|
129
|
+
reason: reason
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var doc = getDocument();
|
|
134
|
+
if (!doc) {
|
|
135
|
+
return new SafePlugin({
|
|
136
|
+
key: pluginKey
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
var unbindClickListener = bind(doc, {
|
|
140
|
+
type: 'click',
|
|
141
|
+
listener: function listener(event) {
|
|
142
|
+
var target = event.target;
|
|
143
|
+
if (target instanceof HTMLElement) {
|
|
144
|
+
handleToolbarButtonClick(target);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
options: {
|
|
148
|
+
capture: true
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
var unbindKeydownListener = bind(doc, {
|
|
152
|
+
type: 'keydown',
|
|
153
|
+
listener: function listener(event) {
|
|
154
|
+
if (event.key === 'Escape') {
|
|
155
|
+
abortAllExperiences(ABORT_REASON.USER_CANCELED);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
options: {
|
|
159
|
+
capture: true
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
return new SafePlugin({
|
|
163
|
+
key: pluginKey,
|
|
164
|
+
view: function view(_view) {
|
|
165
|
+
editorView = _view;
|
|
166
|
+
return {
|
|
167
|
+
destroy: function destroy() {
|
|
168
|
+
abortAllExperiences(ABORT_REASON.EDITOR_DESTROYED);
|
|
169
|
+
editorView = undefined;
|
|
170
|
+
popupTargetEl = undefined;
|
|
171
|
+
unbindClickListener();
|
|
172
|
+
unbindKeydownListener();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|