@atlaskit/editor-plugin-quick-insert 13.0.1 → 13.1.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 +11 -0
- package/dist/cjs/pm-plugins/commands/index.js +35 -3
- package/dist/cjs/quickInsertPlugin.js +56 -33
- package/dist/cjs/ui/ModalElementBrowser/ModalElementBrowser.js +2 -1
- package/dist/cjs/ui/ModalElementBrowser/index.js +24 -15
- package/dist/cjs/ui/QuickInsertMenuFooterItem.js +37 -0
- package/dist/cjs/ui/QuickInsertSectionOverflowMenuItem.js +38 -0
- package/dist/cjs/ui/getQuickInsertComponents.js +103 -11
- package/dist/es2019/pm-plugins/commands/index.js +27 -0
- package/dist/es2019/quickInsertPlugin.js +27 -5
- package/dist/es2019/ui/ModalElementBrowser/ModalElementBrowser.js +2 -1
- package/dist/es2019/ui/ModalElementBrowser/index.js +25 -16
- package/dist/es2019/ui/QuickInsertMenuFooterItem.js +31 -0
- package/dist/es2019/ui/QuickInsertSectionOverflowMenuItem.js +32 -0
- package/dist/es2019/ui/getQuickInsertComponents.js +100 -7
- package/dist/esm/pm-plugins/commands/index.js +34 -2
- package/dist/esm/quickInsertPlugin.js +57 -34
- package/dist/esm/ui/ModalElementBrowser/ModalElementBrowser.js +2 -1
- package/dist/esm/ui/ModalElementBrowser/index.js +25 -16
- package/dist/esm/ui/QuickInsertMenuFooterItem.js +28 -0
- package/dist/esm/ui/QuickInsertSectionOverflowMenuItem.js +29 -0
- package/dist/esm/ui/getQuickInsertComponents.js +105 -13
- package/dist/types/pm-plugins/commands/index.d.ts +11 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +5 -1
- package/dist/types/quickInsertPluginType.d.ts +5 -0
- package/dist/types/ui/ModalElementBrowser/ModalElementBrowser.d.ts +1 -0
- package/dist/types/ui/QuickInsertMenuFooterItem.d.ts +8 -0
- package/dist/types/ui/QuickInsertSectionOverflowMenuItem.d.ts +9 -0
- package/dist/types/ui/getQuickInsertComponents.d.ts +8 -1
- package/package.json +3 -3
|
@@ -9,7 +9,7 @@ import ShowMoreHorizontalIcon from '@atlaskit/icon/core/show-more-horizontal';
|
|
|
9
9
|
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
11
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
12
|
-
import { createInsertItem, openElementBrowserModal } from './pm-plugins/commands';
|
|
12
|
+
import { createInsertItem, openElementBrowser as openElementBrowserCommand, openElementBrowserModal } from './pm-plugins/commands';
|
|
13
13
|
import { getQuickInsertOpenExperiencePlugin } from './pm-plugins/experiences/quick-insert-open-experience';
|
|
14
14
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
15
15
|
import { getQuickInsertComponents } from './ui/getQuickInsertComponents';
|
|
@@ -86,8 +86,27 @@ export const quickInsertPlugin = ({
|
|
|
86
86
|
};
|
|
87
87
|
if (isExperimentEnabled('platform_editor_slash_command')) {
|
|
88
88
|
var _api$uiControlRegistr;
|
|
89
|
-
api === null || api === void 0 ? void 0 : (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 ? void 0 : _api$uiControlRegistr.actions.register(getQuickInsertComponents(
|
|
89
|
+
api === null || api === void 0 ? void 0 : (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 ? void 0 : _api$uiControlRegistr.actions.register(getQuickInsertComponents({
|
|
90
|
+
api,
|
|
91
|
+
includeElementBrowserItems: (options === null || options === void 0 ? void 0 : options.enableElementBrowser) === true
|
|
92
|
+
}));
|
|
90
93
|
}
|
|
94
|
+
const openElementBrowser = options => ({
|
|
95
|
+
tr
|
|
96
|
+
}) => {
|
|
97
|
+
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
98
|
+
var _api$metrics;
|
|
99
|
+
api === null || api === void 0 ? void 0 : (_api$metrics = api.metrics) === null || _api$metrics === void 0 ? void 0 : _api$metrics.commands.handleIntentToStartEdit({
|
|
100
|
+
shouldStartTimer: false,
|
|
101
|
+
shouldPersistActiveSession: true
|
|
102
|
+
})({
|
|
103
|
+
tr
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return openElementBrowserCommand(options)({
|
|
107
|
+
tr
|
|
108
|
+
});
|
|
109
|
+
};
|
|
91
110
|
let intl;
|
|
92
111
|
return {
|
|
93
112
|
name: 'quickInsert',
|
|
@@ -146,7 +165,8 @@ export const quickInsertPlugin = ({
|
|
|
146
165
|
lazyDefaultItems: quickInsertState.lazyDefaultItems,
|
|
147
166
|
emptyStateHandler: quickInsertState.emptyStateHandler,
|
|
148
167
|
providedItems: quickInsertState.providedItems,
|
|
149
|
-
isElementBrowserModalOpen: quickInsertState.isElementBrowserModalOpen
|
|
168
|
+
isElementBrowserModalOpen: quickInsertState.isElementBrowserModalOpen,
|
|
169
|
+
isElementBrowserOpen: quickInsertState.isElementBrowserOpen
|
|
150
170
|
};
|
|
151
171
|
},
|
|
152
172
|
actions: {
|
|
@@ -192,12 +212,13 @@ export const quickInsertPlugin = ({
|
|
|
192
212
|
}
|
|
193
213
|
},
|
|
194
214
|
commands: {
|
|
215
|
+
openElementBrowser,
|
|
195
216
|
openElementBrowserModal: ({
|
|
196
217
|
tr
|
|
197
218
|
}) => {
|
|
198
219
|
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
199
|
-
var _api$
|
|
200
|
-
api === null || api === void 0 ? void 0 : (_api$
|
|
220
|
+
var _api$metrics2;
|
|
221
|
+
api === null || api === void 0 ? void 0 : (_api$metrics2 = api.metrics) === null || _api$metrics2 === void 0 ? void 0 : _api$metrics2.commands.handleIntentToStartEdit({
|
|
201
222
|
shouldStartTimer: false,
|
|
202
223
|
shouldPersistActiveSession: true
|
|
203
224
|
})({
|
|
@@ -274,6 +295,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
274
295
|
init() {
|
|
275
296
|
return {
|
|
276
297
|
isElementBrowserModalOpen: false,
|
|
298
|
+
isElementBrowserOpen: false,
|
|
277
299
|
emptyStateHandler,
|
|
278
300
|
// lazy so it doesn't run on editor initialization
|
|
279
301
|
// memo here to avoid using a singleton cache, avoids editor
|
|
@@ -68,6 +68,7 @@ const ModalElementBrowser = props => {
|
|
|
68
68
|
css: wrapperStyles
|
|
69
69
|
}, jsx(ElementBrowser, {
|
|
70
70
|
categories: getCategories(props.intl),
|
|
71
|
+
defaultCategory: props.defaultCategory,
|
|
71
72
|
getItems: props.getItems,
|
|
72
73
|
showSearch: true,
|
|
73
74
|
showCategories: true,
|
|
@@ -76,7 +77,7 @@ const ModalElementBrowser = props => {
|
|
|
76
77
|
onInsertItem: onInsertItem,
|
|
77
78
|
emptyStateHandler: props.emptyStateHandler,
|
|
78
79
|
autoFocusSearch: false
|
|
79
|
-
})), [props.intl, props.getItems, onSelectItem, onInsertItem, props.emptyStateHandler]);
|
|
80
|
+
})), [props.intl, props.defaultCategory, props.getItems, onSelectItem, onInsertItem, props.emptyStateHandler]);
|
|
80
81
|
const label = intl.formatMessage(messages.browse);
|
|
81
82
|
return jsx("div", {
|
|
82
83
|
"data-editor-popup": true
|
|
@@ -2,8 +2,10 @@ import React, { useCallback } from 'react';
|
|
|
2
2
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
5
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
5
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
-
import { closeElementBrowserModal } from '../../pm-plugins/commands';
|
|
7
|
+
import { closeElementBrowser, closeElementBrowserModal } from '../../pm-plugins/commands';
|
|
8
|
+
import { pluginKey } from '../../pm-plugins/plugin-key';
|
|
7
9
|
import ModalElementBrowser from './ModalElementBrowser';
|
|
8
10
|
const Modal = ({
|
|
9
11
|
quickInsertState,
|
|
@@ -12,7 +14,8 @@ const Modal = ({
|
|
|
12
14
|
helpUrl,
|
|
13
15
|
insertItem,
|
|
14
16
|
getSuggestions,
|
|
15
|
-
api
|
|
17
|
+
api,
|
|
18
|
+
defaultCategory
|
|
16
19
|
}) => {
|
|
17
20
|
const getItems = useCallback((query, category) => {
|
|
18
21
|
var _getSuggestions$map, _getSuggestions;
|
|
@@ -39,22 +42,26 @@ const Modal = ({
|
|
|
39
42
|
// Instead of adding the item immediately on insert item
|
|
40
43
|
// We wait until modal close is complete, refocus the editor and then add the item
|
|
41
44
|
const insertableItem = React.useRef(null);
|
|
45
|
+
const closeBrowser = useCallback(() => {
|
|
46
|
+
const closeCommand = isExperimentEnabled('platform_editor_slash_command') ? closeElementBrowser : closeElementBrowserModal;
|
|
47
|
+
closeCommand()(editorView.state, editorView.dispatch);
|
|
48
|
+
}, [editorView]);
|
|
42
49
|
const onInsertItem = useCallback(item => {
|
|
43
|
-
|
|
50
|
+
closeBrowser();
|
|
44
51
|
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
45
52
|
var _api$metrics;
|
|
46
53
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$metrics = api.metrics) === null || _api$metrics === void 0 ? void 0 : _api$metrics.commands.startActiveSessionTimer());
|
|
47
54
|
}
|
|
48
55
|
insertableItem.current = item;
|
|
49
|
-
}, [
|
|
56
|
+
}, [closeBrowser, api]);
|
|
50
57
|
const onClose = useCallback(() => {
|
|
51
|
-
|
|
58
|
+
closeBrowser();
|
|
52
59
|
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
53
60
|
var _api$metrics2;
|
|
54
61
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$metrics2 = api.metrics) === null || _api$metrics2 === void 0 ? void 0 : _api$metrics2.commands.startActiveSessionTimer());
|
|
55
62
|
}
|
|
56
63
|
focusInEditor();
|
|
57
|
-
}, [
|
|
64
|
+
}, [closeBrowser, focusInEditor, api]);
|
|
58
65
|
const onCloseComplete = useCallback(() => {
|
|
59
66
|
if (!insertableItem.current) {
|
|
60
67
|
focusInEditor();
|
|
@@ -66,10 +73,11 @@ const Modal = ({
|
|
|
66
73
|
insertItem === null || insertItem === void 0 ? void 0 : insertItem(item, INPUT_METHOD.ELEMENT_BROWSER)(editorView.state, editorView.dispatch);
|
|
67
74
|
}, [editorView, focusInEditor, insertItem]);
|
|
68
75
|
return /*#__PURE__*/React.createElement(ModalElementBrowser, {
|
|
76
|
+
defaultCategory: defaultCategory,
|
|
69
77
|
getItems: getItems,
|
|
70
78
|
onInsertItem: onInsertItem,
|
|
71
79
|
helpUrl: helpUrl,
|
|
72
|
-
isOpen: quickInsertState.
|
|
80
|
+
isOpen: quickInsertState.isElementBrowserOpen || false,
|
|
73
81
|
emptyStateHandler: quickInsertState.emptyStateHandler,
|
|
74
82
|
onClose: onClose,
|
|
75
83
|
onCloseComplete: onCloseComplete,
|
|
@@ -81,30 +89,31 @@ export default (({
|
|
|
81
89
|
helpUrl,
|
|
82
90
|
pluginInjectionAPI
|
|
83
91
|
}) => {
|
|
84
|
-
var _pluginInjectionAPI$q, _pluginInjectionAPI$q2, _pluginInjectionAPI$q3, _pluginInjectionAPI$q4;
|
|
92
|
+
var _pluginKey$getState, _pluginInjectionAPI$q, _pluginInjectionAPI$q2, _pluginInjectionAPI$q3, _pluginInjectionAPI$q4;
|
|
85
93
|
const {
|
|
86
94
|
lazyDefaultItems,
|
|
87
95
|
providedItems,
|
|
88
|
-
|
|
96
|
+
isElementBrowserOpen,
|
|
89
97
|
emptyStateHandler,
|
|
90
98
|
mode
|
|
91
99
|
} = useSharedPluginStateWithSelector(pluginInjectionAPI, ['quickInsert', 'connectivity'], state => {
|
|
92
|
-
var _state$quickInsertSta, _state$quickInsertSta2, _state$quickInsertSta3, _state$quickInsertSta4, _state$connectivitySt;
|
|
100
|
+
var _state$quickInsertSta, _state$quickInsertSta2, _state$quickInsertSta3, _state$quickInsertSta4, _state$quickInsertSta5, _state$connectivitySt;
|
|
93
101
|
return {
|
|
94
102
|
lazyDefaultItems: (_state$quickInsertSta = state.quickInsertState) === null || _state$quickInsertSta === void 0 ? void 0 : _state$quickInsertSta.lazyDefaultItems,
|
|
95
103
|
providedItems: (_state$quickInsertSta2 = state.quickInsertState) === null || _state$quickInsertSta2 === void 0 ? void 0 : _state$quickInsertSta2.providedItems,
|
|
96
|
-
|
|
97
|
-
emptyStateHandler: (_state$
|
|
104
|
+
isElementBrowserOpen: isExperimentEnabled('platform_editor_slash_command') ? (_state$quickInsertSta3 = state.quickInsertState) === null || _state$quickInsertSta3 === void 0 ? void 0 : _state$quickInsertSta3.isElementBrowserOpen : (_state$quickInsertSta4 = state.quickInsertState) === null || _state$quickInsertSta4 === void 0 ? void 0 : _state$quickInsertSta4.isElementBrowserModalOpen,
|
|
105
|
+
emptyStateHandler: (_state$quickInsertSta5 = state.quickInsertState) === null || _state$quickInsertSta5 === void 0 ? void 0 : _state$quickInsertSta5.emptyStateHandler,
|
|
98
106
|
mode: (_state$connectivitySt = state.connectivityState) === null || _state$connectivitySt === void 0 ? void 0 : _state$connectivitySt.mode
|
|
99
107
|
};
|
|
100
108
|
});
|
|
101
|
-
return /*#__PURE__*/React.createElement(Modal
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
110
|
+
defaultCategory: (_pluginKey$getState = pluginKey.getState(editorView.state)) === null || _pluginKey$getState === void 0 ? void 0 : _pluginKey$getState.elementBrowserInitialCategory
|
|
111
|
+
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
112
|
+
,
|
|
104
113
|
quickInsertState: {
|
|
105
114
|
lazyDefaultItems,
|
|
106
115
|
providedItems,
|
|
107
|
-
|
|
116
|
+
isElementBrowserOpen,
|
|
108
117
|
emptyStateHandler
|
|
109
118
|
},
|
|
110
119
|
editorView: editorView,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
|
|
5
|
+
import ShowMoreHorizontalIcon from '@atlaskit/icon/core/show-more-horizontal';
|
|
6
|
+
export const QuickInsertMenuFooterItem = ({
|
|
7
|
+
api
|
|
8
|
+
}) => {
|
|
9
|
+
const {
|
|
10
|
+
formatMessage
|
|
11
|
+
} = useIntl();
|
|
12
|
+
const onSelect = useCallback(({
|
|
13
|
+
insert
|
|
14
|
+
}) => {
|
|
15
|
+
var _api$quickInsert$comm, _api$quickInsert;
|
|
16
|
+
const tr = insert(undefined);
|
|
17
|
+
return (_api$quickInsert$comm = api === null || api === void 0 ? void 0 : (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.commands.openElementBrowser()({
|
|
18
|
+
tr
|
|
19
|
+
})) !== null && _api$quickInsert$comm !== void 0 ? _api$quickInsert$comm : tr;
|
|
20
|
+
}, [api]);
|
|
21
|
+
return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
|
|
22
|
+
ariaLabel: formatMessage(toolbarInsertBlockMessages.viewMoreAriaLabel),
|
|
23
|
+
iconBefore: /*#__PURE__*/React.createElement(ShowMoreHorizontalIcon, {
|
|
24
|
+
label: ""
|
|
25
|
+
}),
|
|
26
|
+
isDisabled: !(api !== null && api !== void 0 && api.quickInsert),
|
|
27
|
+
onSelect: onSelect,
|
|
28
|
+
shouldWrapIcon: false,
|
|
29
|
+
title: formatMessage(toolbarInsertBlockMessages.viewMore)
|
|
30
|
+
});
|
|
31
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { toolbarInsertBlockMessages } from '@atlaskit/editor-common/messages';
|
|
4
|
+
import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
|
|
5
|
+
import AddIcon from '@atlaskit/icon/core/add';
|
|
6
|
+
export const QuickInsertSectionOverflowMenuItem = ({
|
|
7
|
+
api,
|
|
8
|
+
category
|
|
9
|
+
}) => {
|
|
10
|
+
const {
|
|
11
|
+
formatMessage
|
|
12
|
+
} = useIntl();
|
|
13
|
+
const onSelect = useCallback(({
|
|
14
|
+
insert
|
|
15
|
+
}) => {
|
|
16
|
+
var _api$quickInsert$comm, _api$quickInsert;
|
|
17
|
+
const tr = insert(undefined);
|
|
18
|
+
return (_api$quickInsert$comm = api === null || api === void 0 ? void 0 : (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.commands.openElementBrowser({
|
|
19
|
+
category
|
|
20
|
+
})({
|
|
21
|
+
tr
|
|
22
|
+
})) !== null && _api$quickInsert$comm !== void 0 ? _api$quickInsert$comm : tr;
|
|
23
|
+
}, [api, category]);
|
|
24
|
+
return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
|
|
25
|
+
iconBefore: /*#__PURE__*/React.createElement(AddIcon, {
|
|
26
|
+
label: ""
|
|
27
|
+
}),
|
|
28
|
+
isDisabled: !(api !== null && api !== void 0 && api.quickInsert),
|
|
29
|
+
onSelect: onSelect,
|
|
30
|
+
title: formatMessage(toolbarInsertBlockMessages.viewMore)
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -1,10 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { BLOCK_TEMPLATES_SECTION, DATA_AND_CHARTS_SECTION, EMBED_SECTION, MEDIA_SECTION, MENU, OTHER_SECTION, RECOMMENDED_SECTION, ROVO_SECTION, STRUCTURE_SECTION, TEXT_FORMATTING_SECTION, VIEW_ALL_ELEMENTS_MENU_ITEM } from '@atlaskit/editor-common/quick-insert/keys';
|
|
4
|
+
import { QuickInsertMenuRoot } from '@atlaskit/editor-common/quick-insert/menu-root';
|
|
5
|
+
import { QuickInsertMenuSection } from '@atlaskit/editor-common/quick-insert/menu-section';
|
|
6
|
+
import { messages } from '@atlaskit/editor-common/quick-insert/messages';
|
|
7
|
+
import { CATEGORY_VIEW_MORE_RANK, QUICK_INSERT_MENU_RANK } from '@atlaskit/editor-common/quick-insert/rank';
|
|
8
|
+
import { getMenuFooterSectionKey } from '@atlaskit/editor-common/type-ahead-get-menu-footer-section-key';
|
|
9
|
+
import { getSectionOverflowItemKey } from '@atlaskit/editor-common/type-ahead-get-section-overflow-item-key';
|
|
10
|
+
import { QuickInsertMenuFooterItem } from './QuickInsertMenuFooterItem';
|
|
11
|
+
import { QuickInsertSectionOverflowMenuItem } from './QuickInsertSectionOverflowMenuItem';
|
|
12
|
+
const categories = [{
|
|
13
|
+
message: messages.categoryRecommended,
|
|
14
|
+
section: RECOMMENDED_SECTION
|
|
15
|
+
}, {
|
|
16
|
+
message: messages.categoryStructure,
|
|
17
|
+
section: STRUCTURE_SECTION
|
|
18
|
+
}, {
|
|
19
|
+
message: messages.categoryMedia,
|
|
20
|
+
section: MEDIA_SECTION
|
|
21
|
+
}, {
|
|
22
|
+
message: messages.categoryEmbed,
|
|
23
|
+
section: EMBED_SECTION
|
|
24
|
+
}, {
|
|
25
|
+
message: messages.categoryTextFormatting,
|
|
26
|
+
section: TEXT_FORMATTING_SECTION
|
|
27
|
+
}, {
|
|
28
|
+
message: messages.categoryRovo,
|
|
29
|
+
section: ROVO_SECTION
|
|
30
|
+
}, {
|
|
31
|
+
message: messages.categoryDataAndCharts,
|
|
32
|
+
section: DATA_AND_CHARTS_SECTION
|
|
33
|
+
}, {
|
|
34
|
+
message: messages.categoryBlockTemplates,
|
|
35
|
+
section: BLOCK_TEMPLATES_SECTION
|
|
36
|
+
}, {
|
|
37
|
+
message: messages.categoryOther,
|
|
38
|
+
section: OTHER_SECTION
|
|
39
|
+
}];
|
|
40
|
+
const createSectionComponent = message => {
|
|
41
|
+
const SectionComponent = ({
|
|
42
|
+
children
|
|
43
|
+
}) => {
|
|
44
|
+
const {
|
|
45
|
+
formatMessage
|
|
46
|
+
} = useIntl();
|
|
47
|
+
return /*#__PURE__*/React.createElement(QuickInsertMenuSection, {
|
|
48
|
+
title: formatMessage(message)
|
|
49
|
+
}, children);
|
|
50
|
+
};
|
|
51
|
+
return SectionComponent;
|
|
52
|
+
};
|
|
53
|
+
export const getQuickInsertComponents = ({
|
|
54
|
+
api,
|
|
55
|
+
includeElementBrowserItems
|
|
56
|
+
}) => [{
|
|
57
|
+
key: MENU.key,
|
|
58
|
+
type: MENU.type,
|
|
59
|
+
component: QuickInsertMenuRoot
|
|
60
|
+
}, ...categories.flatMap(({
|
|
61
|
+
message,
|
|
62
|
+
section
|
|
63
|
+
}) => [{
|
|
64
|
+
key: section.key,
|
|
65
|
+
type: section.type,
|
|
6
66
|
parents: [{
|
|
7
|
-
|
|
67
|
+
key: MENU.key,
|
|
68
|
+
type: MENU.type,
|
|
8
69
|
rank: QUICK_INSERT_MENU_RANK[section.key]
|
|
70
|
+
}],
|
|
71
|
+
component: createSectionComponent(message)
|
|
72
|
+
}, ...(includeElementBrowserItems ? [{
|
|
73
|
+
key: getSectionOverflowItemKey(section.key),
|
|
74
|
+
type: 'menu-item',
|
|
75
|
+
parents: [{
|
|
76
|
+
key: section.key,
|
|
77
|
+
type: section.type,
|
|
78
|
+
rank: CATEGORY_VIEW_MORE_RANK
|
|
79
|
+
}],
|
|
80
|
+
component: () => /*#__PURE__*/React.createElement(QuickInsertSectionOverflowMenuItem, {
|
|
81
|
+
api,
|
|
82
|
+
category: section.key
|
|
83
|
+
})
|
|
84
|
+
}] : [])]), ...(includeElementBrowserItems ? [{
|
|
85
|
+
key: getMenuFooterSectionKey(MENU.key),
|
|
86
|
+
type: 'menu-section',
|
|
87
|
+
parents: [{
|
|
88
|
+
key: MENU.key,
|
|
89
|
+
type: MENU.type,
|
|
90
|
+
rank: Number.MAX_SAFE_INTEGER
|
|
9
91
|
}]
|
|
10
|
-
}
|
|
92
|
+
}, {
|
|
93
|
+
key: VIEW_ALL_ELEMENTS_MENU_ITEM.key,
|
|
94
|
+
type: VIEW_ALL_ELEMENTS_MENU_ITEM.type,
|
|
95
|
+
parents: [{
|
|
96
|
+
key: getMenuFooterSectionKey(MENU.key),
|
|
97
|
+
type: 'menu-section',
|
|
98
|
+
rank: 100
|
|
99
|
+
}],
|
|
100
|
+
component: () => /*#__PURE__*/React.createElement(QuickInsertMenuFooterItem, {
|
|
101
|
+
api
|
|
102
|
+
})
|
|
103
|
+
}] : [])];
|
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
import { insertSelectedItem } from '@atlaskit/editor-common/insert';
|
|
2
2
|
import { pluginKey } from '../plugin-key';
|
|
3
|
-
export var
|
|
4
|
-
var
|
|
3
|
+
export var openElementBrowser = function openElementBrowser() {
|
|
4
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
5
|
+
category = _ref.category;
|
|
6
|
+
return function (_ref2) {
|
|
7
|
+
var tr = _ref2.tr;
|
|
8
|
+
return tr.setMeta(pluginKey, {
|
|
9
|
+
elementBrowserInitialCategory: category,
|
|
10
|
+
isElementBrowserOpen: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export var closeElementBrowser = function closeElementBrowser() {
|
|
15
|
+
return function (state, dispatch) {
|
|
16
|
+
if (dispatch) {
|
|
17
|
+
dispatch(state.tr.setMeta(pluginKey, {
|
|
18
|
+
elementBrowserInitialCategory: undefined,
|
|
19
|
+
isElementBrowserOpen: false
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @private
|
|
28
|
+
* @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-62138 Internal documentation for deprecation (no external access)} Tracked by EDITOR-8422. Use `openElementBrowser` instead.
|
|
29
|
+
*/
|
|
30
|
+
export var openElementBrowserModal = function openElementBrowserModal(_ref3) {
|
|
31
|
+
var tr = _ref3.tr;
|
|
5
32
|
return tr.setMeta(pluginKey, {
|
|
6
33
|
isElementBrowserModalOpen: true
|
|
7
34
|
});
|
|
8
35
|
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @private
|
|
39
|
+
* @deprecated {@link https://hello.atlassian.net/browse/ENGHEALTH-62138 Internal documentation for deprecation (no external access)} Tracked by EDITOR-8422. Use `closeElementBrowser` instead.
|
|
40
|
+
*/
|
|
9
41
|
export var closeElementBrowserModal = function closeElementBrowserModal() {
|
|
10
42
|
return function (state, dispatch) {
|
|
11
43
|
if (dispatch) {
|
|
@@ -15,7 +15,7 @@ import ShowMoreHorizontalIcon from '@atlaskit/icon/core/show-more-horizontal';
|
|
|
15
15
|
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
16
16
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
17
17
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
18
|
-
import { createInsertItem, openElementBrowserModal as _openElementBrowserModal } from './pm-plugins/commands';
|
|
18
|
+
import { createInsertItem, openElementBrowser as openElementBrowserCommand, openElementBrowserModal as _openElementBrowserModal } from './pm-plugins/commands';
|
|
19
19
|
import { getQuickInsertOpenExperiencePlugin } from './pm-plugins/experiences/quick-insert-open-experience';
|
|
20
20
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
21
21
|
import { getQuickInsertComponents } from './ui/getQuickInsertComponents';
|
|
@@ -88,8 +88,28 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
88
88
|
};
|
|
89
89
|
if (isExperimentEnabled('platform_editor_slash_command')) {
|
|
90
90
|
var _api$uiControlRegistr;
|
|
91
|
-
api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register(getQuickInsertComponents(
|
|
91
|
+
api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register(getQuickInsertComponents({
|
|
92
|
+
api: api,
|
|
93
|
+
includeElementBrowserItems: (options === null || options === void 0 ? void 0 : options.enableElementBrowser) === true
|
|
94
|
+
}));
|
|
92
95
|
}
|
|
96
|
+
var openElementBrowser = function openElementBrowser(options) {
|
|
97
|
+
return function (_ref5) {
|
|
98
|
+
var tr = _ref5.tr;
|
|
99
|
+
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
100
|
+
var _api$metrics;
|
|
101
|
+
api === null || api === void 0 || (_api$metrics = api.metrics) === null || _api$metrics === void 0 || _api$metrics.commands.handleIntentToStartEdit({
|
|
102
|
+
shouldStartTimer: false,
|
|
103
|
+
shouldPersistActiveSession: true
|
|
104
|
+
})({
|
|
105
|
+
tr: tr
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return openElementBrowserCommand(options)({
|
|
109
|
+
tr: tr
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
};
|
|
93
113
|
var intl;
|
|
94
114
|
return {
|
|
95
115
|
name: 'quickInsert',
|
|
@@ -97,10 +117,10 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
97
117
|
return [{
|
|
98
118
|
name: 'quickInsert',
|
|
99
119
|
// It's important that this plugin is above TypeAheadPlugin
|
|
100
|
-
plugin: function plugin(
|
|
101
|
-
var providerFactory =
|
|
102
|
-
getIntl =
|
|
103
|
-
dispatch =
|
|
120
|
+
plugin: function plugin(_ref6) {
|
|
121
|
+
var providerFactory = _ref6.providerFactory,
|
|
122
|
+
getIntl = _ref6.getIntl,
|
|
123
|
+
dispatch = _ref6.dispatch;
|
|
104
124
|
return quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, options === null || options === void 0 ? void 0 : options.emptyStateHandler);
|
|
105
125
|
}
|
|
106
126
|
}, {
|
|
@@ -119,10 +139,10 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
119
139
|
pluginsOptions: {
|
|
120
140
|
typeAhead: typeAhead
|
|
121
141
|
},
|
|
122
|
-
contentComponent: function contentComponent(
|
|
123
|
-
var editorView =
|
|
124
|
-
popupsMountPoint =
|
|
125
|
-
wrapperElement =
|
|
142
|
+
contentComponent: function contentComponent(_ref7) {
|
|
143
|
+
var editorView = _ref7.editorView,
|
|
144
|
+
popupsMountPoint = _ref7.popupsMountPoint,
|
|
145
|
+
wrapperElement = _ref7.wrapperElement;
|
|
126
146
|
refs.popupsMountPoint = popupsMountPoint || undefined;
|
|
127
147
|
refs.wrapperElement = wrapperElement || undefined;
|
|
128
148
|
if (!editorView || isSSR()) {
|
|
@@ -150,7 +170,8 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
150
170
|
lazyDefaultItems: quickInsertState.lazyDefaultItems,
|
|
151
171
|
emptyStateHandler: quickInsertState.emptyStateHandler,
|
|
152
172
|
providedItems: quickInsertState.providedItems,
|
|
153
|
-
isElementBrowserModalOpen: quickInsertState.isElementBrowserModalOpen
|
|
173
|
+
isElementBrowserModalOpen: quickInsertState.isElementBrowserModalOpen,
|
|
174
|
+
isElementBrowserOpen: quickInsertState.isElementBrowserOpen
|
|
154
175
|
};
|
|
155
176
|
},
|
|
156
177
|
actions: {
|
|
@@ -165,9 +186,9 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
165
186
|
},
|
|
166
187
|
getSuggestions: function getSuggestions(searchOptions) {
|
|
167
188
|
var _api$quickInsert$shar, _api$quickInsert;
|
|
168
|
-
var
|
|
169
|
-
lazyDefaultItems =
|
|
170
|
-
providedItems =
|
|
189
|
+
var _ref8 = (_api$quickInsert$shar = api === null || api === void 0 || (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.sharedState.currentState()) !== null && _api$quickInsert$shar !== void 0 ? _api$quickInsert$shar : {},
|
|
190
|
+
lazyDefaultItems = _ref8.lazyDefaultItems,
|
|
191
|
+
providedItems = _ref8.providedItems;
|
|
171
192
|
if (expValEquals('platform_editor_layout_typeahead_reorder', 'isEnabled', true)) {
|
|
172
193
|
var _options$prioritySort;
|
|
173
194
|
searchOptions = _objectSpread(_objectSpread({}, searchOptions), {}, {
|
|
@@ -194,11 +215,12 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
194
215
|
}
|
|
195
216
|
},
|
|
196
217
|
commands: {
|
|
197
|
-
|
|
198
|
-
|
|
218
|
+
openElementBrowser: openElementBrowser,
|
|
219
|
+
openElementBrowserModal: function openElementBrowserModal(_ref9) {
|
|
220
|
+
var tr = _ref9.tr;
|
|
199
221
|
if (fg('platform_editor_ease_of_use_metrics')) {
|
|
200
|
-
var _api$
|
|
201
|
-
api === null || api === void 0 || (_api$
|
|
222
|
+
var _api$metrics2;
|
|
223
|
+
api === null || api === void 0 || (_api$metrics2 = api.metrics) === null || _api$metrics2 === void 0 || _api$metrics2.commands.handleIntentToStartEdit({
|
|
202
224
|
shouldStartTimer: false,
|
|
203
225
|
shouldPersistActiveSession: true
|
|
204
226
|
})({
|
|
@@ -210,11 +232,11 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
210
232
|
});
|
|
211
233
|
},
|
|
212
234
|
addQuickInsertItem: function addQuickInsertItem(item) {
|
|
213
|
-
return function (
|
|
235
|
+
return function (_ref0) {
|
|
214
236
|
var _api$quickInsert$shar2, _api$quickInsert2;
|
|
215
|
-
var tr =
|
|
216
|
-
var
|
|
217
|
-
lazyDefaultItems =
|
|
237
|
+
var tr = _ref0.tr;
|
|
238
|
+
var _ref1 = (_api$quickInsert$shar2 = api === null || api === void 0 || (_api$quickInsert2 = api.quickInsert) === null || _api$quickInsert2 === void 0 ? void 0 : _api$quickInsert2.sharedState.currentState()) !== null && _api$quickInsert$shar2 !== void 0 ? _api$quickInsert$shar2 : {},
|
|
239
|
+
lazyDefaultItems = _ref1.lazyDefaultItems;
|
|
218
240
|
var defaultItems = lazyDefaultItems ? lazyDefaultItems() : [];
|
|
219
241
|
var memoisedNewItems = memoProcessQuickInsertItems([item], intl);
|
|
220
242
|
return tr.setMeta(pluginKey, {
|
|
@@ -225,12 +247,12 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
225
247
|
};
|
|
226
248
|
},
|
|
227
249
|
updateQuickInsertItem: function updateQuickInsertItem(key, item) {
|
|
228
|
-
return function (
|
|
250
|
+
return function (_ref10) {
|
|
229
251
|
var _api$quickInsert$shar3, _api$quickInsert3;
|
|
230
|
-
var tr =
|
|
231
|
-
var
|
|
232
|
-
providedItems =
|
|
233
|
-
lazyDefaultItems =
|
|
252
|
+
var tr = _ref10.tr;
|
|
253
|
+
var _ref11 = (_api$quickInsert$shar3 = api === null || api === void 0 || (_api$quickInsert3 = api.quickInsert) === null || _api$quickInsert3 === void 0 ? void 0 : _api$quickInsert3.sharedState.currentState()) !== null && _api$quickInsert$shar3 !== void 0 ? _api$quickInsert$shar3 : {},
|
|
254
|
+
providedItems = _ref11.providedItems,
|
|
255
|
+
lazyDefaultItems = _ref11.lazyDefaultItems;
|
|
234
256
|
var defaultItems = lazyDefaultItems ? lazyDefaultItems() : [];
|
|
235
257
|
var newItem = memoProcessQuickInsertItems([item], intl);
|
|
236
258
|
var replaceByKey = function replaceByKey(items) {
|
|
@@ -255,12 +277,12 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
|
255
277
|
};
|
|
256
278
|
},
|
|
257
279
|
removeQuickInsertItem: function removeQuickInsertItem(key) {
|
|
258
|
-
return function (
|
|
280
|
+
return function (_ref12) {
|
|
259
281
|
var _api$quickInsert$shar4, _api$quickInsert4, _providedItems$filter;
|
|
260
|
-
var tr =
|
|
261
|
-
var
|
|
262
|
-
providedItems =
|
|
263
|
-
lazyDefaultItems =
|
|
282
|
+
var tr = _ref12.tr;
|
|
283
|
+
var _ref13 = (_api$quickInsert$shar4 = api === null || api === void 0 || (_api$quickInsert4 = api.quickInsert) === null || _api$quickInsert4 === void 0 ? void 0 : _api$quickInsert4.sharedState.currentState()) !== null && _api$quickInsert$shar4 !== void 0 ? _api$quickInsert$shar4 : {},
|
|
284
|
+
providedItems = _ref13.providedItems,
|
|
285
|
+
lazyDefaultItems = _ref13.lazyDefaultItems;
|
|
264
286
|
var defaultItems = lazyDefaultItems ? lazyDefaultItems() : [];
|
|
265
287
|
return tr.setMeta(pluginKey, {
|
|
266
288
|
providedItems: (_providedItems$filter = providedItems === null || providedItems === void 0 ? void 0 : providedItems.filter(function (item) {
|
|
@@ -295,6 +317,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
295
317
|
init: function init() {
|
|
296
318
|
return {
|
|
297
319
|
isElementBrowserModalOpen: false,
|
|
320
|
+
isElementBrowserOpen: false,
|
|
298
321
|
emptyStateHandler: emptyStateHandler,
|
|
299
322
|
// lazy so it doesn't run on editor initialization
|
|
300
323
|
// memo here to avoid using a singleton cache, avoids editor
|
|
@@ -322,7 +345,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
322
345
|
},
|
|
323
346
|
view: function view(editorView) {
|
|
324
347
|
var providerHandler = /*#__PURE__*/function () {
|
|
325
|
-
var
|
|
348
|
+
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_name, providerPromise) {
|
|
326
349
|
var provider, providedItems, _t;
|
|
327
350
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
328
351
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -358,7 +381,7 @@ function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispat
|
|
|
358
381
|
}, _callee, null, [[1, 4]]);
|
|
359
382
|
}));
|
|
360
383
|
return function providerHandler(_x, _x2) {
|
|
361
|
-
return
|
|
384
|
+
return _ref14.apply(this, arguments);
|
|
362
385
|
};
|
|
363
386
|
}();
|
|
364
387
|
providerFactory.subscribe('quickInsertProvider', providerHandler);
|
|
@@ -75,6 +75,7 @@ var ModalElementBrowser = function ModalElementBrowser(props) {
|
|
|
75
75
|
css: wrapperStyles
|
|
76
76
|
}, jsx(ElementBrowser, {
|
|
77
77
|
categories: getCategories(props.intl),
|
|
78
|
+
defaultCategory: props.defaultCategory,
|
|
78
79
|
getItems: props.getItems,
|
|
79
80
|
showSearch: true,
|
|
80
81
|
showCategories: true,
|
|
@@ -84,7 +85,7 @@ var ModalElementBrowser = function ModalElementBrowser(props) {
|
|
|
84
85
|
emptyStateHandler: props.emptyStateHandler,
|
|
85
86
|
autoFocusSearch: false
|
|
86
87
|
}));
|
|
87
|
-
}, [props.intl, props.getItems, onSelectItem, onInsertItem, props.emptyStateHandler]);
|
|
88
|
+
}, [props.intl, props.defaultCategory, props.getItems, onSelectItem, onInsertItem, props.emptyStateHandler]);
|
|
88
89
|
var label = intl.formatMessage(messages.browse);
|
|
89
90
|
return jsx("div", {
|
|
90
91
|
"data-editor-popup": true
|