@atlaskit/editor-core 187.43.8 → 187.43.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/labs/next/presets/default.js +2 -2
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/plugins/tasks-and-decisions/nodeviews/taskItem.js +3 -1
  5. package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/helpers.js +111 -2
  6. package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/main.js +108 -7
  7. package/dist/cjs/plugins/tasks-and-decisions/pm-plugins/types.js +12 -0
  8. package/dist/cjs/version-wrapper.js +1 -1
  9. package/dist/es2019/labs/next/presets/default.js +1 -1
  10. package/dist/es2019/plugins/index.js +0 -1
  11. package/dist/es2019/plugins/tasks-and-decisions/nodeviews/taskItem.js +4 -1
  12. package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/helpers.js +121 -1
  13. package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/main.js +113 -5
  14. package/dist/es2019/plugins/tasks-and-decisions/pm-plugins/types.js +5 -0
  15. package/dist/es2019/version-wrapper.js +1 -1
  16. package/dist/esm/labs/next/presets/default.js +1 -1
  17. package/dist/esm/plugins/index.js +0 -1
  18. package/dist/esm/plugins/tasks-and-decisions/nodeviews/taskItem.js +3 -1
  19. package/dist/esm/plugins/tasks-and-decisions/pm-plugins/helpers.js +102 -1
  20. package/dist/esm/plugins/tasks-and-decisions/pm-plugins/main.js +106 -5
  21. package/dist/esm/plugins/tasks-and-decisions/pm-plugins/types.js +5 -0
  22. package/dist/esm/version-wrapper.js +1 -1
  23. package/dist/types/plugins/help-dialog/index.d.ts +4 -4
  24. package/dist/types/plugins/index.d.ts +0 -1
  25. package/dist/types/plugins/insert-block/types.d.ts +2 -2
  26. package/dist/types/plugins/tasks-and-decisions/pm-plugins/helpers.d.ts +23 -1
  27. package/dist/types/plugins/tasks-and-decisions/pm-plugins/types.d.ts +8 -0
  28. package/dist/types/plugins/tasks-and-decisions/ui/Task/index.d.ts +1 -0
  29. package/dist/types/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.d.ts +1 -0
  30. package/dist/types-ts4.5/plugins/help-dialog/index.d.ts +4 -4
  31. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  32. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -2
  33. package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/helpers.d.ts +23 -1
  34. package/dist/types-ts4.5/plugins/tasks-and-decisions/pm-plugins/types.d.ts +8 -0
  35. package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/Task/index.d.ts +1 -0
  36. package/dist/types-ts4.5/plugins/tasks-and-decisions/ui/Task/task-item-with-providers.d.ts +1 -0
  37. package/package.json +7 -6
  38. package/dist/cjs/plugins/quick-insert/commands.js +0 -44
  39. package/dist/cjs/plugins/quick-insert/index.js +0 -189
  40. package/dist/cjs/plugins/quick-insert/plugin-key.js +0 -9
  41. package/dist/cjs/plugins/quick-insert/search.js +0 -33
  42. package/dist/cjs/plugins/quick-insert/ui/ModalElementBrowser/ModalElementBrowser.js +0 -140
  43. package/dist/cjs/plugins/quick-insert/ui/ModalElementBrowser/categories.js +0 -100
  44. package/dist/cjs/plugins/quick-insert/ui/ModalElementBrowser/index.js +0 -61
  45. package/dist/cjs/plugins/quick-insert/ui/ModalElementBrowser/messages.js +0 -15
  46. package/dist/es2019/plugins/quick-insert/commands.js +0 -29
  47. package/dist/es2019/plugins/quick-insert/index.js +0 -151
  48. package/dist/es2019/plugins/quick-insert/plugin-key.js +0 -2
  49. package/dist/es2019/plugins/quick-insert/search.js +0 -16
  50. package/dist/es2019/plugins/quick-insert/ui/ModalElementBrowser/ModalElementBrowser.js +0 -137
  51. package/dist/es2019/plugins/quick-insert/ui/ModalElementBrowser/categories.js +0 -94
  52. package/dist/es2019/plugins/quick-insert/ui/ModalElementBrowser/index.js +0 -51
  53. package/dist/es2019/plugins/quick-insert/ui/ModalElementBrowser/messages.js +0 -8
  54. package/dist/esm/plugins/quick-insert/commands.js +0 -35
  55. package/dist/esm/plugins/quick-insert/index.js +0 -181
  56. package/dist/esm/plugins/quick-insert/plugin-key.js +0 -2
  57. package/dist/esm/plugins/quick-insert/search.js +0 -25
  58. package/dist/esm/plugins/quick-insert/ui/ModalElementBrowser/ModalElementBrowser.js +0 -128
  59. package/dist/esm/plugins/quick-insert/ui/ModalElementBrowser/categories.js +0 -94
  60. package/dist/esm/plugins/quick-insert/ui/ModalElementBrowser/index.js +0 -50
  61. package/dist/esm/plugins/quick-insert/ui/ModalElementBrowser/messages.js +0 -8
  62. package/dist/types/plugins/quick-insert/commands.d.ts +0 -5
  63. package/dist/types/plugins/quick-insert/index.d.ts +0 -16
  64. package/dist/types/plugins/quick-insert/plugin-key.d.ts +0 -3
  65. package/dist/types/plugins/quick-insert/search.d.ts +0 -5
  66. package/dist/types/plugins/quick-insert/ui/ModalElementBrowser/ModalElementBrowser.d.ts +0 -18
  67. package/dist/types/plugins/quick-insert/ui/ModalElementBrowser/categories.d.ts +0 -5
  68. package/dist/types/plugins/quick-insert/ui/ModalElementBrowser/index.d.ts +0 -11
  69. package/dist/types/plugins/quick-insert/ui/ModalElementBrowser/messages.d.ts +0 -7
  70. package/dist/types-ts4.5/plugins/quick-insert/commands.d.ts +0 -5
  71. package/dist/types-ts4.5/plugins/quick-insert/index.d.ts +0 -16
  72. package/dist/types-ts4.5/plugins/quick-insert/plugin-key.d.ts +0 -3
  73. package/dist/types-ts4.5/plugins/quick-insert/search.d.ts +0 -5
  74. package/dist/types-ts4.5/plugins/quick-insert/ui/ModalElementBrowser/ModalElementBrowser.d.ts +0 -18
  75. package/dist/types-ts4.5/plugins/quick-insert/ui/ModalElementBrowser/categories.d.ts +0 -5
  76. package/dist/types-ts4.5/plugins/quick-insert/ui/ModalElementBrowser/index.d.ts +0 -11
  77. package/dist/types-ts4.5/plugins/quick-insert/ui/ModalElementBrowser/messages.d.ts +0 -7
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.messages = void 0;
7
- var _reactIntlNext = require("react-intl-next");
8
- var messages = (0, _reactIntlNext.defineMessages)({
9
- help: {
10
- id: 'fabric.editor.elementBrowser.help',
11
- defaultMessage: 'Help',
12
- description: 'Element browser help button label'
13
- }
14
- });
15
- exports.messages = messages;
@@ -1,29 +0,0 @@
1
- import { insertSelectedItem } from '@atlaskit/editor-common/insert';
2
- import { pluginKey } from './plugin-key';
3
- export const openElementBrowserModal = ({
4
- tr
5
- }) => tr.setMeta(pluginKey, {
6
- isElementBrowserModalOpen: true
7
- });
8
- export const closeElementBrowserModal = () => (state, dispatch) => {
9
- if (dispatch) {
10
- dispatch(state.tr.setMeta(pluginKey, {
11
- isElementBrowserModalOpen: false
12
- }));
13
- }
14
- return true;
15
- };
16
-
17
- // this method was adapted from the typeahead plugin so we respect the API for quick insert items
18
- export const insertItem = item => (state, dispatch) => {
19
- const insert = (maybeNode, opts = {}) => {
20
- return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
21
- };
22
- const tr = item.action(insert, state);
23
-
24
- /** @note There is no transaction when called without a search currently (different insert) */
25
- if (tr && dispatch) {
26
- dispatch(tr);
27
- }
28
- return true;
29
- };
@@ -1,151 +0,0 @@
1
- import React from 'react';
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
4
- import { pluginKey } from './plugin-key';
5
- import ModalElementBrowser from './ui/ModalElementBrowser';
6
- import { openElementBrowserModal, insertItem } from './commands';
7
- import { memoProcessQuickInsertItems } from '@atlaskit/editor-common/quick-insert';
8
- import { getQuickInsertSuggestions } from './search';
9
- const quickInsertPlugin = ({
10
- config: options,
11
- api
12
- }) => ({
13
- name: 'quickInsert',
14
- pmPlugins(defaultItems) {
15
- return [{
16
- name: 'quickInsert',
17
- // It's important that this plugin is above TypeAheadPlugin
18
- plugin: ({
19
- providerFactory,
20
- getIntl,
21
- dispatch
22
- }) => quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, options === null || options === void 0 ? void 0 : options.emptyStateHandler)
23
- }];
24
- },
25
- pluginsOptions: {
26
- typeAhead: {
27
- id: TypeAheadAvailableNodes.QUICK_INSERT,
28
- trigger: '/',
29
- headless: options === null || options === void 0 ? void 0 : options.headless,
30
- getItems({
31
- query,
32
- editorState
33
- }) {
34
- const quickInsertState = pluginKey.getState(editorState);
35
- return Promise.resolve(getQuickInsertSuggestions({
36
- query,
37
- disableDefaultItems: options === null || options === void 0 ? void 0 : options.disableDefaultItems
38
- }, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.lazyDefaultItems, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.providedItems));
39
- },
40
- selectItem: (state, item, insert) => {
41
- return item.action(insert, state);
42
- }
43
- }
44
- },
45
- contentComponent({
46
- editorView
47
- }) {
48
- if (options !== null && options !== void 0 && options.enableElementBrowser) {
49
- return /*#__PURE__*/React.createElement(ModalElementBrowser, {
50
- editorView: editorView,
51
- helpUrl: options === null || options === void 0 ? void 0 : options.elementBrowserHelpUrl,
52
- pluginInjectionAPI: api
53
- });
54
- }
55
- return null;
56
- },
57
- getSharedState(editorState) {
58
- if (!editorState) {
59
- return null;
60
- }
61
- const quickInsertState = pluginKey.getState(editorState);
62
- if (!quickInsertState) {
63
- return null;
64
- }
65
- return {
66
- lazyDefaultItems: quickInsertState.lazyDefaultItems,
67
- emptyStateHandler: quickInsertState.emptyStateHandler,
68
- providedItems: quickInsertState.providedItems,
69
- isElementBrowserModalOpen: quickInsertState.isElementBrowserModalOpen
70
- };
71
- },
72
- actions: {
73
- insertItem,
74
- getSuggestions: searchOptions => {
75
- var _api$quickInsert$shar;
76
- const {
77
- lazyDefaultItems,
78
- providedItems
79
- } = (_api$quickInsert$shar = api === null || api === void 0 ? void 0 : api.quickInsert.sharedState.currentState()) !== null && _api$quickInsert$shar !== void 0 ? _api$quickInsert$shar : {};
80
- return getQuickInsertSuggestions(searchOptions, lazyDefaultItems, providedItems);
81
- }
82
- },
83
- commands: {
84
- openElementBrowserModal
85
- }
86
- });
87
- export default quickInsertPlugin;
88
- const setProviderState = providerState => (state, dispatch) => {
89
- if (dispatch) {
90
- dispatch(state.tr.setMeta(pluginKey, providerState));
91
- }
92
- return true;
93
- };
94
- function quickInsertPluginFactory(defaultItems, providerFactory, getIntl, dispatch, emptyStateHandler) {
95
- return new SafePlugin({
96
- key: pluginKey,
97
- state: {
98
- init() {
99
- return {
100
- isElementBrowserModalOpen: false,
101
- emptyStateHandler,
102
- // lazy so it doesn't run on editor initialization
103
- // memo here to avoid using a singleton cache, avoids editor
104
- // getting confused when two editors exist within the same page.
105
- lazyDefaultItems: () => memoProcessQuickInsertItems(defaultItems || [], getIntl())
106
- };
107
- },
108
- apply(tr, pluginState) {
109
- const meta = tr.getMeta(pluginKey);
110
- if (meta) {
111
- const keys = Object.keys(meta);
112
- const changed = keys.some(key => {
113
- return pluginState[key] !== meta[key];
114
- });
115
- if (changed) {
116
- const newState = {
117
- ...pluginState,
118
- ...meta
119
- };
120
- dispatch(pluginKey, newState);
121
- return newState;
122
- }
123
- }
124
- return pluginState;
125
- }
126
- },
127
- view(editorView) {
128
- const providerHandler = async (_name, providerPromise) => {
129
- if (providerPromise) {
130
- try {
131
- const provider = await providerPromise;
132
- const providedItems = await provider.getItems();
133
- setProviderState({
134
- provider,
135
- providedItems
136
- })(editorView.state, editorView.dispatch);
137
- } catch (e) {
138
- // eslint-disable-next-line no-console
139
- console.error('Error getting items from quick insert provider', e);
140
- }
141
- }
142
- };
143
- providerFactory.subscribe('quickInsertProvider', providerHandler);
144
- return {
145
- destroy() {
146
- providerFactory.unsubscribe('quickInsertProvider', providerHandler);
147
- }
148
- };
149
- }
150
- });
151
- }
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export const pluginKey = new PluginKey('quickInsertPluginKey');
@@ -1,16 +0,0 @@
1
- import { dedupe } from '@atlaskit/editor-common/utils';
2
- import { find } from '@atlaskit/editor-common/quick-insert';
3
- export const getQuickInsertSuggestions = (searchOptions, lazyDefaultItems = () => [], providedItems) => {
4
- const {
5
- query,
6
- category,
7
- disableDefaultItems,
8
- featuredItems
9
- } = searchOptions;
10
- const defaultItems = disableDefaultItems ? [] : lazyDefaultItems();
11
- const items = providedItems ? dedupe([...defaultItems, ...providedItems], item => item.title) : defaultItems;
12
- if (featuredItems) {
13
- return items.filter(item => item.featured);
14
- }
15
- return find(query || '', category === 'all' || !category ? items : items.filter(item => item.categories && item.categories.includes(category)));
16
- };
@@ -1,137 +0,0 @@
1
- /** @jsx jsx */
2
- import React, { useState, useCallback } from 'react';
3
- import { css, jsx } from '@emotion/react';
4
- import { injectIntl } from 'react-intl-next';
5
- import { DN50, N0 } from '@atlaskit/theme/colors';
6
- import { themed } from '@atlaskit/theme/components';
7
- import { borderRadius } from '@atlaskit/theme/constants';
8
- import Button from '@atlaskit/button/custom-theme-button';
9
- import Modal, { ModalTransition, useModal } from '@atlaskit/modal-dialog';
10
- import QuestionCircleIcon from '@atlaskit/icon/glyph/question-circle';
11
- import { ElementBrowser } from '@atlaskit/editor-common/element-browser';
12
- import { getCategories } from './categories';
13
- import { messages } from './messages';
14
- export const MODAL_WRAPPER_PADDING = 16;
15
- const actions = css`
16
- display: inline-flex;
17
- margin: 0 -4px;
18
- `;
19
- const actionItem = css`
20
- flex: 1 0 auto;
21
- margin: 0 ${"var(--ds-space-050, 4px)"};
22
- `;
23
- const wrapper = css`
24
- display: flex;
25
- flex: 1 1 auto;
26
- box-sizing: border-box;
27
- padding: ${"var(--ds-space-200, 16px)"} ${"var(--ds-space-200, 16px)"} 0 10px;
28
- overflow: hidden;
29
- background-color: ${themed({
30
- light: `var(--ds-surface-overlay, ${N0})`,
31
- dark: `var(--ds-surface-overlay, ${DN50})`
32
- })()};
33
- border-radius: ${borderRadius()}px;
34
- `;
35
- const modalFooter = css`
36
- display: flex;
37
- padding: ${"var(--ds-space-200, 16px)"};
38
-
39
- position: relative;
40
- align-items: center;
41
- justify-content: space-between;
42
- `;
43
- const ModalElementBrowser = props => {
44
- const [selectedItem, setSelectedItem] = useState();
45
- const {
46
- helpUrl,
47
- intl,
48
- onClose,
49
- onInsertItem: onInsertItemFn
50
- } = props;
51
- const onSelectItem = useCallback(item => {
52
- setSelectedItem(item);
53
- }, [setSelectedItem]);
54
- const onInsertItem = useCallback(item => {
55
- onInsertItemFn(item);
56
- }, [onInsertItemFn]);
57
- const RenderFooter = useCallback(() => jsx(Footer, {
58
- onInsert: () => onInsertItem(selectedItem),
59
- beforeElement: helpUrl ? HelpLink(helpUrl, intl.formatMessage(messages.help)) : undefined
60
- }), [onInsertItem, selectedItem, helpUrl, intl]);
61
-
62
- // Since Modal uses stackIndex it's shouldCloseOnEscapePress prop doesn't work.
63
- const onKeyDown = useCallback(e => {
64
- if (e.key === 'Escape') {
65
- onClose();
66
- }
67
- }, [onClose]);
68
- const RenderBody = useCallback(() => jsx("div", {
69
- css: wrapper
70
- }, jsx(ElementBrowser, {
71
- categories: getCategories(props.intl),
72
- getItems: props.getItems,
73
- showSearch: true,
74
- showCategories: true,
75
- mode: "full",
76
- onSelectItem: onSelectItem,
77
- onInsertItem: onInsertItem,
78
- emptyStateHandler: props.emptyStateHandler
79
- })), [props.intl, props.getItems, onSelectItem, onInsertItem, props.emptyStateHandler]);
80
- return jsx("div", {
81
- "data-editor-popup": true,
82
- onClick: onModalClick,
83
- onKeyDown: onKeyDown
84
- }, jsx(ModalTransition, null, props.isOpen && jsx(Modal, {
85
- testId: "element-browser-modal-dialog",
86
- stackIndex: 0,
87
- key: "element-browser-modal",
88
- onClose: props.onClose,
89
- height: "664px",
90
- width: "x-large",
91
- autoFocus: false
92
- // defaults to true and doesn't work along with stackIndex=1.
93
- // packages/design-system/modal-dialog/src/components/Content.tsx Line 287
94
- ,
95
- shouldCloseOnEscapePress: false
96
- }, jsx(RenderBody, null), jsx(RenderFooter, null))));
97
- };
98
- ModalElementBrowser.displayName = 'ModalElementBrowser';
99
-
100
- // Prevent ModalElementBrowser click propagation through to the editor.
101
- const onModalClick = e => e.stopPropagation();
102
- const Footer = ({
103
- onInsert,
104
- beforeElement
105
- }) => {
106
- const {
107
- onClose
108
- } = useModal();
109
- return jsx("div", {
110
- css: modalFooter
111
- }, beforeElement ? beforeElement : jsx("span", null), jsx("div", {
112
- css: actions
113
- }, jsx("div", {
114
- css: actionItem
115
- }, jsx(Button, {
116
- appearance: "primary",
117
- onClick: onInsert,
118
- testId: "ModalElementBrowser__insert-button"
119
- }, "Insert")), jsx("div", {
120
- css: actionItem
121
- }, jsx(Button, {
122
- appearance: "subtle",
123
- onClick: onClose,
124
- testId: "ModalElementBrowser__close-button"
125
- }, "Close"))));
126
- };
127
- const HelpLink = (url, helpText) => jsx(Button, {
128
- iconBefore: jsx(QuestionCircleIcon, {
129
- label: "",
130
- size: "medium"
131
- }),
132
- appearance: "subtle-link",
133
- href: url,
134
- target: "_blank",
135
- testId: "ModalElementBrowser__help-button"
136
- }, helpText);
137
- export default injectIntl(ModalElementBrowser);
@@ -1,94 +0,0 @@
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
- const 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
- });
@@ -1,51 +0,0 @@
1
- import React, { useCallback } from 'react';
2
- import ModalElementBrowser from './ModalElementBrowser';
3
- import { closeElementBrowserModal, insertItem } from '../../commands';
4
- import { getQuickInsertSuggestions } from '../../search';
5
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
- const Modal = ({
7
- quickInsertState,
8
- editorView,
9
- helpUrl
10
- }) => {
11
- const getItems = useCallback((query, category) => getQuickInsertSuggestions({
12
- query,
13
- category
14
- }, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.lazyDefaultItems, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.providedItems), [quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.lazyDefaultItems, quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.providedItems]);
15
- const focusInEditor = useCallback(() => {
16
- if (!editorView.hasFocus()) {
17
- editorView.focus();
18
- }
19
- }, [editorView]);
20
- const onInsertItem = useCallback(item => {
21
- closeElementBrowserModal()(editorView.state, editorView.dispatch);
22
- focusInEditor();
23
- insertItem(item)(editorView.state, editorView.dispatch);
24
- }, [editorView, focusInEditor]);
25
- const onClose = useCallback(() => {
26
- closeElementBrowserModal()(editorView.state, editorView.dispatch);
27
- focusInEditor();
28
- }, [editorView, focusInEditor]);
29
- return /*#__PURE__*/React.createElement(ModalElementBrowser, {
30
- getItems: getItems,
31
- onInsertItem: onInsertItem,
32
- helpUrl: helpUrl,
33
- isOpen: (quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.isElementBrowserModalOpen) || false,
34
- emptyStateHandler: quickInsertState === null || quickInsertState === void 0 ? void 0 : quickInsertState.emptyStateHandler,
35
- onClose: onClose
36
- });
37
- };
38
- export default (({
39
- editorView,
40
- helpUrl,
41
- pluginInjectionAPI
42
- }) => {
43
- const {
44
- quickInsertState
45
- } = useSharedPluginState(pluginInjectionAPI, ['quickInsert']);
46
- return /*#__PURE__*/React.createElement(Modal, {
47
- quickInsertState: quickInsertState !== null && quickInsertState !== void 0 ? quickInsertState : undefined,
48
- editorView: editorView,
49
- helpUrl: helpUrl
50
- });
51
- });
@@ -1,8 +0,0 @@
1
- import { defineMessages } from 'react-intl-next';
2
- export const messages = defineMessages({
3
- help: {
4
- id: 'fabric.editor.elementBrowser.help',
5
- defaultMessage: 'Help',
6
- description: 'Element browser help button label'
7
- }
8
- });
@@ -1,35 +0,0 @@
1
- import { insertSelectedItem } from '@atlaskit/editor-common/insert';
2
- import { pluginKey } from './plugin-key';
3
- export var openElementBrowserModal = function openElementBrowserModal(_ref) {
4
- var tr = _ref.tr;
5
- return tr.setMeta(pluginKey, {
6
- isElementBrowserModalOpen: true
7
- });
8
- };
9
- export var closeElementBrowserModal = function closeElementBrowserModal() {
10
- return function (state, dispatch) {
11
- if (dispatch) {
12
- dispatch(state.tr.setMeta(pluginKey, {
13
- isElementBrowserModalOpen: false
14
- }));
15
- }
16
- return true;
17
- };
18
- };
19
-
20
- // this method was adapted from the typeahead plugin so we respect the API for quick insert items
21
- export var insertItem = function insertItem(item) {
22
- return function (state, dispatch) {
23
- var insert = function insert(maybeNode) {
24
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25
- return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
26
- };
27
- var tr = item.action(insert, state);
28
-
29
- /** @note There is no transaction when called without a search currently (different insert) */
30
- if (tr && dispatch) {
31
- dispatch(tr);
32
- }
33
- return true;
34
- };
35
- };