@atlaskit/editor-plugin-quick-insert 0.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/.eslintrc.js +14 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +30 -0
- package/dist/cjs/commands.js +44 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/plugin-key.js +9 -0
- package/dist/cjs/plugin.js +188 -0
- package/dist/cjs/search.js +33 -0
- package/dist/cjs/ui/ModalElementBrowser/ModalElementBrowser.js +159 -0
- package/dist/cjs/ui/ModalElementBrowser/categories.js +100 -0
- package/dist/cjs/ui/ModalElementBrowser/index.js +61 -0
- package/dist/cjs/ui/ModalElementBrowser/messages.js +15 -0
- package/dist/es2019/commands.js +29 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/plugin-key.js +2 -0
- package/dist/es2019/plugin.js +150 -0
- package/dist/es2019/search.js +16 -0
- package/dist/es2019/ui/ModalElementBrowser/ModalElementBrowser.js +136 -0
- package/dist/es2019/ui/ModalElementBrowser/categories.js +94 -0
- package/dist/es2019/ui/ModalElementBrowser/index.js +51 -0
- package/dist/es2019/ui/ModalElementBrowser/messages.js +8 -0
- package/dist/esm/commands.js +35 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/plugin-key.js +2 -0
- package/dist/esm/plugin.js +180 -0
- package/dist/esm/search.js +25 -0
- package/dist/esm/ui/ModalElementBrowser/ModalElementBrowser.js +146 -0
- package/dist/esm/ui/ModalElementBrowser/categories.js +94 -0
- package/dist/esm/ui/ModalElementBrowser/index.js +50 -0
- package/dist/esm/ui/ModalElementBrowser/messages.js +8 -0
- package/dist/types/commands.d.ts +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugin-key.d.ts +3 -0
- package/dist/types/plugin.d.ts +15 -0
- package/dist/types/search.d.ts +5 -0
- package/dist/types/ui/ModalElementBrowser/ModalElementBrowser.d.ts +18 -0
- package/dist/types/ui/ModalElementBrowser/categories.d.ts +5 -0
- package/dist/types/ui/ModalElementBrowser/index.d.ts +11 -0
- package/dist/types/ui/ModalElementBrowser/messages.d.ts +7 -0
- package/dist/types-ts4.5/commands.d.ts +5 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/plugin.d.ts +15 -0
- package/dist/types-ts4.5/search.d.ts +5 -0
- package/dist/types-ts4.5/ui/ModalElementBrowser/ModalElementBrowser.d.ts +18 -0
- package/dist/types-ts4.5/ui/ModalElementBrowser/categories.d.ts +5 -0
- package/dist/types-ts4.5/ui/ModalElementBrowser/index.d.ts +11 -0
- package/dist/types-ts4.5/ui/ModalElementBrowser/messages.d.ts +7 -0
- package/package.json +99 -0
- package/report.api.md +63 -0
- package/tmp/api-report-tmp.d.ts +33 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { memoProcessQuickInsertItems } from '@atlaskit/editor-common/quick-insert';
|
|
8
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
9
|
+
import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
|
|
10
|
+
import { insertItem, openElementBrowserModal } from './commands';
|
|
11
|
+
import { pluginKey } from './plugin-key';
|
|
12
|
+
import { getQuickInsertSuggestions } from './search';
|
|
13
|
+
import ModalElementBrowser from './ui/ModalElementBrowser';
|
|
14
|
+
export var quickInsertPlugin = function quickInsertPlugin(_ref) {
|
|
15
|
+
var options = _ref.config,
|
|
16
|
+
api = _ref.api;
|
|
17
|
+
return {
|
|
18
|
+
name: 'quickInsert',
|
|
19
|
+
pmPlugins: function pmPlugins(defaultItems) {
|
|
20
|
+
return [{
|
|
21
|
+
name: 'quickInsert',
|
|
22
|
+
// It's important that this plugin is above TypeAheadPlugin
|
|
23
|
+
plugin: function plugin(_ref2) {
|
|
24
|
+
var providerFactory = _ref2.providerFactory,
|
|
25
|
+
getIntl = _ref2.getIntl,
|
|
26
|
+
dispatch = _ref2.dispatch;
|
|
27
|
+
return quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, options === null || options === void 0 ? void 0 : options.emptyStateHandler);
|
|
28
|
+
}
|
|
29
|
+
}];
|
|
30
|
+
},
|
|
31
|
+
pluginsOptions: {
|
|
32
|
+
typeAhead: {
|
|
33
|
+
id: TypeAheadAvailableNodes.QUICK_INSERT,
|
|
34
|
+
trigger: '/',
|
|
35
|
+
headless: options === null || options === void 0 ? void 0 : options.headless,
|
|
36
|
+
getItems: function getItems(_ref3) {
|
|
37
|
+
var query = _ref3.query,
|
|
38
|
+
editorState = _ref3.editorState;
|
|
39
|
+
var quickInsertState = pluginKey.getState(editorState);
|
|
40
|
+
return Promise.resolve(getQuickInsertSuggestions({
|
|
41
|
+
query: query,
|
|
42
|
+
disableDefaultItems: options === null || options === void 0 ? void 0 : options.disableDefaultItems
|
|
43
|
+
}, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.lazyDefaultItems, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.providedItems));
|
|
44
|
+
},
|
|
45
|
+
selectItem: function selectItem(state, item, insert) {
|
|
46
|
+
return item.action(insert, state);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
contentComponent: function contentComponent(_ref4) {
|
|
51
|
+
var editorView = _ref4.editorView;
|
|
52
|
+
if (options !== null && options !== void 0 && options.enableElementBrowser) {
|
|
53
|
+
return /*#__PURE__*/React.createElement(ModalElementBrowser, {
|
|
54
|
+
editorView: editorView,
|
|
55
|
+
helpUrl: options === null || options === void 0 ? void 0 : options.elementBrowserHelpUrl,
|
|
56
|
+
pluginInjectionAPI: api
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
61
|
+
getSharedState: function getSharedState(editorState) {
|
|
62
|
+
if (!editorState) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
var quickInsertState = pluginKey.getState(editorState);
|
|
66
|
+
if (!quickInsertState) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
lazyDefaultItems: quickInsertState.lazyDefaultItems,
|
|
71
|
+
emptyStateHandler: quickInsertState.emptyStateHandler,
|
|
72
|
+
providedItems: quickInsertState.providedItems,
|
|
73
|
+
isElementBrowserModalOpen: quickInsertState.isElementBrowserModalOpen
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
actions: {
|
|
77
|
+
insertItem: insertItem,
|
|
78
|
+
getSuggestions: function getSuggestions(searchOptions) {
|
|
79
|
+
var _api$quickInsert$shar;
|
|
80
|
+
var _ref5 = (_api$quickInsert$shar = api === null || api === void 0 ? void 0 : api.quickInsert.sharedState.currentState()) !== null && _api$quickInsert$shar !== void 0 ? _api$quickInsert$shar : {},
|
|
81
|
+
lazyDefaultItems = _ref5.lazyDefaultItems,
|
|
82
|
+
providedItems = _ref5.providedItems;
|
|
83
|
+
return getQuickInsertSuggestions(searchOptions, lazyDefaultItems, providedItems);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
commands: {
|
|
87
|
+
openElementBrowserModal: openElementBrowserModal
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var setProviderState = function setProviderState(providerState) {
|
|
92
|
+
return function (state, dispatch) {
|
|
93
|
+
if (dispatch) {
|
|
94
|
+
dispatch(state.tr.setMeta(pluginKey, providerState));
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, emptyStateHandler) {
|
|
100
|
+
return new SafePlugin({
|
|
101
|
+
key: pluginKey,
|
|
102
|
+
state: {
|
|
103
|
+
init: function init() {
|
|
104
|
+
return {
|
|
105
|
+
isElementBrowserModalOpen: false,
|
|
106
|
+
emptyStateHandler: emptyStateHandler,
|
|
107
|
+
// lazy so it doesn't run on editor initialization
|
|
108
|
+
// memo here to avoid using a singleton cache, avoids editor
|
|
109
|
+
// getting confused when two editors exist within the same page.
|
|
110
|
+
lazyDefaultItems: function lazyDefaultItems() {
|
|
111
|
+
return memoProcessQuickInsertItems(defaultItems || [], getIntl());
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
apply: function apply(tr, pluginState) {
|
|
116
|
+
var meta = tr.getMeta(pluginKey);
|
|
117
|
+
if (meta) {
|
|
118
|
+
var keys = Object.keys(meta);
|
|
119
|
+
var changed = keys.some(function (key) {
|
|
120
|
+
return pluginState[key] !== meta[key];
|
|
121
|
+
});
|
|
122
|
+
if (changed) {
|
|
123
|
+
var newState = _objectSpread(_objectSpread({}, pluginState), meta);
|
|
124
|
+
dispatch(pluginKey, newState);
|
|
125
|
+
return newState;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return pluginState;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
view: function view(editorView) {
|
|
132
|
+
var providerHandler = /*#__PURE__*/function () {
|
|
133
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_name, providerPromise) {
|
|
134
|
+
var provider, providedItems;
|
|
135
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
136
|
+
while (1) switch (_context.prev = _context.next) {
|
|
137
|
+
case 0:
|
|
138
|
+
if (!providerPromise) {
|
|
139
|
+
_context.next = 14;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
_context.prev = 1;
|
|
143
|
+
_context.next = 4;
|
|
144
|
+
return providerPromise;
|
|
145
|
+
case 4:
|
|
146
|
+
provider = _context.sent;
|
|
147
|
+
_context.next = 7;
|
|
148
|
+
return provider.getItems();
|
|
149
|
+
case 7:
|
|
150
|
+
providedItems = _context.sent;
|
|
151
|
+
setProviderState({
|
|
152
|
+
provider: provider,
|
|
153
|
+
providedItems: providedItems
|
|
154
|
+
})(editorView.state, editorView.dispatch);
|
|
155
|
+
_context.next = 14;
|
|
156
|
+
break;
|
|
157
|
+
case 11:
|
|
158
|
+
_context.prev = 11;
|
|
159
|
+
_context.t0 = _context["catch"](1);
|
|
160
|
+
// eslint-disable-next-line no-console
|
|
161
|
+
console.error('Error getting items from quick insert provider', _context.t0);
|
|
162
|
+
case 14:
|
|
163
|
+
case "end":
|
|
164
|
+
return _context.stop();
|
|
165
|
+
}
|
|
166
|
+
}, _callee, null, [[1, 11]]);
|
|
167
|
+
}));
|
|
168
|
+
return function providerHandler(_x, _x2) {
|
|
169
|
+
return _ref6.apply(this, arguments);
|
|
170
|
+
};
|
|
171
|
+
}();
|
|
172
|
+
providerFactory.subscribe('quickInsertProvider', providerHandler);
|
|
173
|
+
return {
|
|
174
|
+
destroy: function destroy() {
|
|
175
|
+
providerFactory.unsubscribe('quickInsertProvider', providerHandler);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { find } from '@atlaskit/editor-common/quick-insert';
|
|
3
|
+
import { dedupe } from '@atlaskit/editor-common/utils';
|
|
4
|
+
export var getQuickInsertSuggestions = function getQuickInsertSuggestions(searchOptions) {
|
|
5
|
+
var lazyDefaultItems = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
|
|
6
|
+
return [];
|
|
7
|
+
};
|
|
8
|
+
var providedItems = arguments.length > 2 ? arguments[2] : undefined;
|
|
9
|
+
var query = searchOptions.query,
|
|
10
|
+
category = searchOptions.category,
|
|
11
|
+
disableDefaultItems = searchOptions.disableDefaultItems,
|
|
12
|
+
featuredItems = searchOptions.featuredItems;
|
|
13
|
+
var defaultItems = disableDefaultItems ? [] : lazyDefaultItems();
|
|
14
|
+
var items = providedItems ? dedupe([].concat(_toConsumableArray(defaultItems), _toConsumableArray(providedItems)), function (item) {
|
|
15
|
+
return item.title;
|
|
16
|
+
}) : defaultItems;
|
|
17
|
+
if (featuredItems) {
|
|
18
|
+
return items.filter(function (item) {
|
|
19
|
+
return item.featured;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return find(query || '', category === 'all' || !category ? items : items.filter(function (item) {
|
|
23
|
+
return item.categories && item.categories.includes(category);
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import React, { useCallback, useState } from 'react';
|
|
4
|
+
import { css, jsx } from '@emotion/react';
|
|
5
|
+
import { injectIntl } from 'react-intl-next';
|
|
6
|
+
import Button from '@atlaskit/button/custom-theme-button';
|
|
7
|
+
import { ElementBrowser } from '@atlaskit/editor-common/element-browser';
|
|
8
|
+
import QuestionCircleIcon from '@atlaskit/icon/glyph/question-circle';
|
|
9
|
+
import Modal, { ModalTransition, useModal } from '@atlaskit/modal-dialog';
|
|
10
|
+
import { DN50, N0 } from '@atlaskit/theme/colors';
|
|
11
|
+
import { themed } from '@atlaskit/theme/components';
|
|
12
|
+
import { borderRadius } from '@atlaskit/theme/constants';
|
|
13
|
+
import { getCategories } from './categories';
|
|
14
|
+
import { messages } from './messages';
|
|
15
|
+
export var MODAL_WRAPPER_PADDING = 16;
|
|
16
|
+
var actionsStyles = css({
|
|
17
|
+
display: 'inline-flex',
|
|
18
|
+
margin: "0 ".concat("var(--ds-space-negative-050, -4px)")
|
|
19
|
+
});
|
|
20
|
+
var actionItemStyles = css({
|
|
21
|
+
flex: '1 0 auto',
|
|
22
|
+
margin: "0 ".concat("var(--ds-space-050, 4px)")
|
|
23
|
+
});
|
|
24
|
+
var wrapperStyles = css({
|
|
25
|
+
display: 'flex',
|
|
26
|
+
flex: '1 1 auto',
|
|
27
|
+
boxSizing: 'border-box',
|
|
28
|
+
padding: "var(--ds-space-200, 16px)".concat(" ", "var(--ds-space-200, 16px)", " 0 10px"),
|
|
29
|
+
overflow: 'hidden',
|
|
30
|
+
backgroundColor: "".concat(themed({
|
|
31
|
+
light: "var(--ds-surface-overlay, ".concat(N0, ")"),
|
|
32
|
+
dark: "var(--ds-surface-overlay, ".concat(DN50, ")")
|
|
33
|
+
})()),
|
|
34
|
+
borderRadius: "".concat(borderRadius(), "px")
|
|
35
|
+
});
|
|
36
|
+
var modalFooterStyles = css({
|
|
37
|
+
display: 'flex',
|
|
38
|
+
padding: "var(--ds-space-200, 16px)",
|
|
39
|
+
position: 'relative',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
justifyContent: 'space-between'
|
|
42
|
+
});
|
|
43
|
+
var ModalElementBrowser = function ModalElementBrowser(props) {
|
|
44
|
+
var _useState = useState(),
|
|
45
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
46
|
+
selectedItem = _useState2[0],
|
|
47
|
+
setSelectedItem = _useState2[1];
|
|
48
|
+
var helpUrl = props.helpUrl,
|
|
49
|
+
intl = props.intl,
|
|
50
|
+
onClose = props.onClose,
|
|
51
|
+
onInsertItemFn = props.onInsertItem;
|
|
52
|
+
var onSelectItem = useCallback(function (item) {
|
|
53
|
+
setSelectedItem(item);
|
|
54
|
+
}, [setSelectedItem]);
|
|
55
|
+
var onInsertItem = useCallback(function (item) {
|
|
56
|
+
onInsertItemFn(item);
|
|
57
|
+
}, [onInsertItemFn]);
|
|
58
|
+
var RenderFooter = useCallback(function () {
|
|
59
|
+
return jsx(Footer, {
|
|
60
|
+
onInsert: function onInsert() {
|
|
61
|
+
return onInsertItem(selectedItem);
|
|
62
|
+
},
|
|
63
|
+
beforeElement: helpUrl ? HelpLink(helpUrl, intl.formatMessage(messages.help)) : undefined
|
|
64
|
+
});
|
|
65
|
+
}, [onInsertItem, selectedItem, helpUrl, intl]);
|
|
66
|
+
|
|
67
|
+
// Since Modal uses stackIndex it's shouldCloseOnEscapePress prop doesn't work.
|
|
68
|
+
var onKeyDown = useCallback(function (e) {
|
|
69
|
+
if (e.key === 'Escape') {
|
|
70
|
+
onClose();
|
|
71
|
+
}
|
|
72
|
+
}, [onClose]);
|
|
73
|
+
var RenderBody = useCallback(function () {
|
|
74
|
+
return jsx("div", {
|
|
75
|
+
css: wrapperStyles
|
|
76
|
+
}, jsx(ElementBrowser, {
|
|
77
|
+
categories: getCategories(props.intl),
|
|
78
|
+
getItems: props.getItems,
|
|
79
|
+
showSearch: true,
|
|
80
|
+
showCategories: true,
|
|
81
|
+
mode: "full",
|
|
82
|
+
onSelectItem: onSelectItem,
|
|
83
|
+
onInsertItem: onInsertItem,
|
|
84
|
+
emptyStateHandler: props.emptyStateHandler
|
|
85
|
+
}));
|
|
86
|
+
}, [props.intl, props.getItems, onSelectItem, onInsertItem, props.emptyStateHandler]);
|
|
87
|
+
return jsx("div", {
|
|
88
|
+
"data-editor-popup": true,
|
|
89
|
+
onClick: onModalClick,
|
|
90
|
+
onKeyDown: onKeyDown
|
|
91
|
+
}, jsx(ModalTransition, null, props.isOpen && jsx(Modal, {
|
|
92
|
+
testId: "element-browser-modal-dialog",
|
|
93
|
+
stackIndex: 0,
|
|
94
|
+
key: "element-browser-modal",
|
|
95
|
+
onClose: props.onClose,
|
|
96
|
+
height: "664px",
|
|
97
|
+
width: "x-large",
|
|
98
|
+
autoFocus: false
|
|
99
|
+
// defaults to true and doesn't work along with stackIndex=1.
|
|
100
|
+
// packages/design-system/modal-dialog/src/components/Content.tsx Line 287
|
|
101
|
+
,
|
|
102
|
+
shouldCloseOnEscapePress: false
|
|
103
|
+
}, jsx(RenderBody, null), jsx(RenderFooter, null))));
|
|
104
|
+
};
|
|
105
|
+
ModalElementBrowser.displayName = 'ModalElementBrowser';
|
|
106
|
+
|
|
107
|
+
// Prevent ModalElementBrowser click propagation through to the editor.
|
|
108
|
+
var onModalClick = function onModalClick(e) {
|
|
109
|
+
return e.stopPropagation();
|
|
110
|
+
};
|
|
111
|
+
var Footer = function Footer(_ref) {
|
|
112
|
+
var onInsert = _ref.onInsert,
|
|
113
|
+
beforeElement = _ref.beforeElement;
|
|
114
|
+
var _useModal = useModal(),
|
|
115
|
+
onClose = _useModal.onClose;
|
|
116
|
+
return jsx("div", {
|
|
117
|
+
css: modalFooterStyles
|
|
118
|
+
}, beforeElement ? beforeElement : jsx("span", null), jsx("div", {
|
|
119
|
+
css: actionsStyles
|
|
120
|
+
}, jsx("div", {
|
|
121
|
+
css: actionItemStyles
|
|
122
|
+
}, jsx(Button, {
|
|
123
|
+
appearance: "primary",
|
|
124
|
+
onClick: onInsert,
|
|
125
|
+
testId: "ModalElementBrowser__insert-button"
|
|
126
|
+
}, "Insert")), jsx("div", {
|
|
127
|
+
css: actionItemStyles
|
|
128
|
+
}, jsx(Button, {
|
|
129
|
+
appearance: "subtle",
|
|
130
|
+
onClick: onClose,
|
|
131
|
+
testId: "ModalElementBrowser__close-button"
|
|
132
|
+
}, "Close"))));
|
|
133
|
+
};
|
|
134
|
+
var HelpLink = function HelpLink(url, helpText) {
|
|
135
|
+
return jsx(Button, {
|
|
136
|
+
iconBefore: jsx(QuestionCircleIcon, {
|
|
137
|
+
label: "",
|
|
138
|
+
size: "medium"
|
|
139
|
+
}),
|
|
140
|
+
appearance: "subtle-link",
|
|
141
|
+
href: url,
|
|
142
|
+
target: "_blank",
|
|
143
|
+
testId: "ModalElementBrowser__help-button"
|
|
144
|
+
}, helpText);
|
|
145
|
+
};
|
|
146
|
+
export default injectIntl(ModalElementBrowser);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export function getCategories(intl) {
|
|
3
|
+
return [{
|
|
4
|
+
title: intl.formatMessage(messages.all),
|
|
5
|
+
name: 'all'
|
|
6
|
+
}, {
|
|
7
|
+
title: intl.formatMessage(messages.formatting),
|
|
8
|
+
name: 'formatting'
|
|
9
|
+
}, {
|
|
10
|
+
title: intl.formatMessage(messages['confluence-content']),
|
|
11
|
+
name: 'confluence-content'
|
|
12
|
+
}, {
|
|
13
|
+
title: intl.formatMessage(messages.media),
|
|
14
|
+
name: 'media'
|
|
15
|
+
}, {
|
|
16
|
+
title: intl.formatMessage(messages.visuals),
|
|
17
|
+
name: 'visuals'
|
|
18
|
+
}, {
|
|
19
|
+
title: intl.formatMessage(messages.navigation),
|
|
20
|
+
name: 'navigation'
|
|
21
|
+
}, {
|
|
22
|
+
title: intl.formatMessage(messages['external-content']),
|
|
23
|
+
name: 'external-content'
|
|
24
|
+
}, {
|
|
25
|
+
title: intl.formatMessage(messages.communication),
|
|
26
|
+
name: 'communication'
|
|
27
|
+
}, {
|
|
28
|
+
title: intl.formatMessage(messages.reporting),
|
|
29
|
+
name: 'reporting'
|
|
30
|
+
}, {
|
|
31
|
+
title: intl.formatMessage(messages.admin),
|
|
32
|
+
name: 'admin'
|
|
33
|
+
}, {
|
|
34
|
+
title: intl.formatMessage(messages.development),
|
|
35
|
+
name: 'development'
|
|
36
|
+
}];
|
|
37
|
+
}
|
|
38
|
+
var messages = defineMessages({
|
|
39
|
+
all: {
|
|
40
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-all',
|
|
41
|
+
defaultMessage: 'All',
|
|
42
|
+
description: 'all'
|
|
43
|
+
},
|
|
44
|
+
formatting: {
|
|
45
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-formatting',
|
|
46
|
+
defaultMessage: 'Formatting',
|
|
47
|
+
description: 'formatting'
|
|
48
|
+
},
|
|
49
|
+
'confluence-content': {
|
|
50
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-confluence-content',
|
|
51
|
+
defaultMessage: 'Confluence content',
|
|
52
|
+
description: 'confluence-content'
|
|
53
|
+
},
|
|
54
|
+
media: {
|
|
55
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-media',
|
|
56
|
+
defaultMessage: 'Media',
|
|
57
|
+
description: 'media'
|
|
58
|
+
},
|
|
59
|
+
visuals: {
|
|
60
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-visuals',
|
|
61
|
+
defaultMessage: 'Visuals & images',
|
|
62
|
+
description: 'visuals'
|
|
63
|
+
},
|
|
64
|
+
navigation: {
|
|
65
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-navigation',
|
|
66
|
+
defaultMessage: 'Navigation',
|
|
67
|
+
description: 'navigation'
|
|
68
|
+
},
|
|
69
|
+
'external-content': {
|
|
70
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-external-content',
|
|
71
|
+
defaultMessage: 'External content',
|
|
72
|
+
description: 'external-content'
|
|
73
|
+
},
|
|
74
|
+
communication: {
|
|
75
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-communication',
|
|
76
|
+
defaultMessage: 'Communication',
|
|
77
|
+
description: 'communication'
|
|
78
|
+
},
|
|
79
|
+
reporting: {
|
|
80
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-reporting',
|
|
81
|
+
defaultMessage: 'Reporting',
|
|
82
|
+
description: 'reporting'
|
|
83
|
+
},
|
|
84
|
+
admin: {
|
|
85
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-admin',
|
|
86
|
+
defaultMessage: 'Administration',
|
|
87
|
+
description: 'admin'
|
|
88
|
+
},
|
|
89
|
+
development: {
|
|
90
|
+
id: 'fabric.editor.elementbrowser.categorylist.category-development',
|
|
91
|
+
defaultMessage: 'Development',
|
|
92
|
+
description: 'development'
|
|
93
|
+
}
|
|
94
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
|
+
import { closeElementBrowserModal, insertItem } from '../../commands';
|
|
4
|
+
import { getQuickInsertSuggestions } from '../../search';
|
|
5
|
+
import ModalElementBrowser from './ModalElementBrowser';
|
|
6
|
+
var Modal = function Modal(_ref) {
|
|
7
|
+
var quickInsertState = _ref.quickInsertState,
|
|
8
|
+
editorView = _ref.editorView,
|
|
9
|
+
helpUrl = _ref.helpUrl;
|
|
10
|
+
var getItems = useCallback(function (query, category) {
|
|
11
|
+
return getQuickInsertSuggestions({
|
|
12
|
+
query: query,
|
|
13
|
+
category: category
|
|
14
|
+
}, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.lazyDefaultItems, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.providedItems);
|
|
15
|
+
}, [quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.lazyDefaultItems, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.providedItems]);
|
|
16
|
+
var focusInEditor = useCallback(function () {
|
|
17
|
+
if (!editorView.hasFocus()) {
|
|
18
|
+
editorView.focus();
|
|
19
|
+
}
|
|
20
|
+
}, [editorView]);
|
|
21
|
+
var onInsertItem = useCallback(function (item) {
|
|
22
|
+
closeElementBrowserModal()(editorView.state, editorView.dispatch);
|
|
23
|
+
focusInEditor();
|
|
24
|
+
insertItem(item)(editorView.state, editorView.dispatch);
|
|
25
|
+
}, [editorView, focusInEditor]);
|
|
26
|
+
var onClose = useCallback(function () {
|
|
27
|
+
closeElementBrowserModal()(editorView.state, editorView.dispatch);
|
|
28
|
+
focusInEditor();
|
|
29
|
+
}, [editorView, focusInEditor]);
|
|
30
|
+
return /*#__PURE__*/React.createElement(ModalElementBrowser, {
|
|
31
|
+
getItems: getItems,
|
|
32
|
+
onInsertItem: onInsertItem,
|
|
33
|
+
helpUrl: helpUrl,
|
|
34
|
+
isOpen: (quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.isElementBrowserModalOpen) || false,
|
|
35
|
+
emptyStateHandler: quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.emptyStateHandler,
|
|
36
|
+
onClose: onClose
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export default (function (_ref2) {
|
|
40
|
+
var editorView = _ref2.editorView,
|
|
41
|
+
helpUrl = _ref2.helpUrl,
|
|
42
|
+
pluginInjectionAPI = _ref2.pluginInjectionAPI;
|
|
43
|
+
var _useSharedPluginState = useSharedPluginState(pluginInjectionAPI, ['quickInsert']),
|
|
44
|
+
quickInsertState = _useSharedPluginState.quickInsertState;
|
|
45
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
46
|
+
quickInsertState: quickInsertState !== null && quickInsertState !== void 0 ? quickInsertState : undefined,
|
|
47
|
+
editorView: editorView,
|
|
48
|
+
helpUrl: helpUrl
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
+
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
+
export declare const openElementBrowserModal: EditorCommand;
|
|
4
|
+
export declare const closeElementBrowserModal: () => Command;
|
|
5
|
+
export declare const insertItem: (item: QuickInsertItem) => Command;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
+
import type { Command, EditorCommand, NextEditorPlugin, QuickInsertPluginOptions, QuickInsertSearchOptions, QuickInsertSharedState } from '@atlaskit/editor-common/types';
|
|
3
|
+
export type { QuickInsertPluginOptions };
|
|
4
|
+
export type QuickInsertPlugin = NextEditorPlugin<'quickInsert', {
|
|
5
|
+
pluginConfiguration: QuickInsertPluginOptions | undefined;
|
|
6
|
+
sharedState: QuickInsertSharedState | null;
|
|
7
|
+
actions: {
|
|
8
|
+
insertItem: (item: QuickInsertItem) => Command;
|
|
9
|
+
getSuggestions: (searchOptions: QuickInsertSearchOptions) => QuickInsertItem[];
|
|
10
|
+
};
|
|
11
|
+
commands: {
|
|
12
|
+
openElementBrowserModal: EditorCommand;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export declare const quickInsertPlugin: QuickInsertPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
+
import type { QuickInsertSearchOptions } from '@atlaskit/editor-common/types';
|
|
3
|
+
type GetQuickInsertSuggestions = (searchOptions: QuickInsertSearchOptions, lazyDefaultItems?: () => QuickInsertItem[], providedItems?: QuickInsertItem[]) => QuickInsertItem[];
|
|
4
|
+
export declare const getQuickInsertSuggestions: GetQuickInsertSuggestions;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
5
|
+
import type { EmptyStateHandler } from '@atlaskit/editor-common/types';
|
|
6
|
+
export declare const MODAL_WRAPPER_PADDING = 16;
|
|
7
|
+
export interface Props {
|
|
8
|
+
getItems: (query?: string, category?: string) => QuickInsertItem[];
|
|
9
|
+
onInsertItem: (item: QuickInsertItem) => void;
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
helpUrl?: string | undefined;
|
|
13
|
+
emptyStateHandler?: EmptyStateHandler;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: React.FC<import("react-intl-next").WithIntlProps<Props & WrappedComponentProps<"intl">>> & {
|
|
16
|
+
WrappedComponent: React.ComponentType<Props & WrappedComponentProps<"intl">>;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { QuickInsertPlugin } from '../../index';
|
|
5
|
+
type Props = {
|
|
6
|
+
editorView: EditorView;
|
|
7
|
+
helpUrl: string | undefined;
|
|
8
|
+
pluginInjectionAPI: ExtractInjectionAPI<QuickInsertPlugin> | undefined;
|
|
9
|
+
};
|
|
10
|
+
declare const _default: ({ editorView, helpUrl, pluginInjectionAPI }: Props) => JSX.Element;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
+
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
+
export declare const openElementBrowserModal: EditorCommand;
|
|
4
|
+
export declare const closeElementBrowserModal: () => Command;
|
|
5
|
+
export declare const insertItem: (item: QuickInsertItem) => Command;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
+
import type { Command, EditorCommand, NextEditorPlugin, QuickInsertPluginOptions, QuickInsertSearchOptions, QuickInsertSharedState } from '@atlaskit/editor-common/types';
|
|
3
|
+
export type { QuickInsertPluginOptions };
|
|
4
|
+
export type QuickInsertPlugin = NextEditorPlugin<'quickInsert', {
|
|
5
|
+
pluginConfiguration: QuickInsertPluginOptions | undefined;
|
|
6
|
+
sharedState: QuickInsertSharedState | null;
|
|
7
|
+
actions: {
|
|
8
|
+
insertItem: (item: QuickInsertItem) => Command;
|
|
9
|
+
getSuggestions: (searchOptions: QuickInsertSearchOptions) => QuickInsertItem[];
|
|
10
|
+
};
|
|
11
|
+
commands: {
|
|
12
|
+
openElementBrowserModal: EditorCommand;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export declare const quickInsertPlugin: QuickInsertPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
2
|
+
import type { QuickInsertSearchOptions } from '@atlaskit/editor-common/types';
|
|
3
|
+
type GetQuickInsertSuggestions = (searchOptions: QuickInsertSearchOptions, lazyDefaultItems?: () => QuickInsertItem[], providedItems?: QuickInsertItem[]) => QuickInsertItem[];
|
|
4
|
+
export declare const getQuickInsertSuggestions: GetQuickInsertSuggestions;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
|
|
5
|
+
import type { EmptyStateHandler } from '@atlaskit/editor-common/types';
|
|
6
|
+
export declare const MODAL_WRAPPER_PADDING = 16;
|
|
7
|
+
export interface Props {
|
|
8
|
+
getItems: (query?: string, category?: string) => QuickInsertItem[];
|
|
9
|
+
onInsertItem: (item: QuickInsertItem) => void;
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
helpUrl?: string | undefined;
|
|
13
|
+
emptyStateHandler?: EmptyStateHandler;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: React.FC<import("react-intl-next").WithIntlProps<Props & WrappedComponentProps<"intl">>> & {
|
|
16
|
+
WrappedComponent: React.ComponentType<Props & WrappedComponentProps<"intl">>;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|