@atlaskit/editor-plugin-quick-insert 1.5.1 → 1.6.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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-quick-insert
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#157845](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157845)
8
+ [`036086b523133`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/036086b523133) -
9
+ Removed onInsert from quickInsert plugin actions, as the behavior is now encapsulated within
10
+ insertItem
11
+
3
12
  ## 1.5.1
4
13
 
5
14
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.openElementBrowserModal = exports.insertItem = exports.closeElementBrowserModal = void 0;
6
+ exports.openElementBrowserModal = exports.createInsertItem = exports.closeElementBrowserModal = void 0;
7
7
  var _insert = require("@atlaskit/editor-common/insert");
8
8
  var _pluginKey = require("./plugin-key");
9
9
  var openElementBrowserModal = exports.openElementBrowserModal = function openElementBrowserModal(_ref) {
@@ -22,20 +22,26 @@ var closeElementBrowserModal = exports.closeElementBrowserModal = function close
22
22
  return true;
23
23
  };
24
24
  };
25
+ var createInsertItem = exports.createInsertItem = function createInsertItem(onInsert) {
26
+ return insertItem(onInsert);
27
+ };
25
28
 
26
29
  // this method was adapted from the typeahead plugin so we respect the API for quick insert items
27
- var insertItem = exports.insertItem = function insertItem(item, source) {
28
- return function (state, dispatch) {
29
- var insert = function insert(maybeNode) {
30
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
31
- return (0, _insert.insertSelectedItem)(maybeNode, opts)(state, state.tr, state.selection.head);
32
- };
33
- var tr = item.action(insert, state, source);
30
+ var insertItem = function insertItem(onInsert) {
31
+ return function (item, source) {
32
+ return function (state, dispatch) {
33
+ var insert = function insert(maybeNode) {
34
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
35
+ return (0, _insert.insertSelectedItem)(maybeNode, opts)(state, state.tr, state.selection.head);
36
+ };
37
+ var tr = item.action(insert, state, source);
34
38
 
35
- /** @note There is no transaction when called without a search currently (different insert) */
36
- if (tr && dispatch) {
37
- dispatch(tr);
38
- }
39
- return true;
39
+ /** @note There is no transaction when called without a search currently (different insert) */
40
+ if (tr && dispatch) {
41
+ dispatch(tr);
42
+ }
43
+ onInsert === null || onInsert === void 0 || onInsert(item);
44
+ return true;
45
+ };
40
46
  };
41
47
  };
@@ -96,7 +96,7 @@ var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_
96
96
  };
97
97
  },
98
98
  actions: {
99
- insertItem: _commands.insertItem,
99
+ insertItem: (0, _commands.createInsertItem)(onInsert),
100
100
  openTypeAhead: function openTypeAhead(inputMethod) {
101
101
  var _api$typeAhead;
102
102
  return Boolean(api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.open({
@@ -115,8 +115,7 @@ var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_
115
115
  });
116
116
  }
117
117
  return (0, _search.getQuickInsertSuggestions)(searchOptions, lazyDefaultItems, providedItems);
118
- },
119
- onInsert: onInsert
118
+ }
120
119
  },
121
120
  commands: {
122
121
  openElementBrowserModal: _commands.openElementBrowserModal,
@@ -17,7 +17,7 @@ var Modal = function Modal(_ref) {
17
17
  var quickInsertState = _ref.quickInsertState,
18
18
  editorView = _ref.editorView,
19
19
  helpUrl = _ref.helpUrl,
20
- onInsert = _ref.onInsert;
20
+ insertItem = _ref.insertItem;
21
21
  var getItems = (0, _react.useCallback)(function (query, category) {
22
22
  return (0, _search.getQuickInsertSuggestions)({
23
23
  query: query,
@@ -35,10 +35,9 @@ var Modal = function Modal(_ref) {
35
35
  // We wait until modal close is complete, refocus the editor and then add the item
36
36
  var insertableItem = _react.default.useRef(null);
37
37
  var onInsertItem = (0, _react.useCallback)(function (item) {
38
- onInsert === null || onInsert === void 0 || onInsert(item);
39
38
  (0, _commands.closeElementBrowserModal)()(editorView.state, editorView.dispatch);
40
39
  insertableItem.current = item;
41
- }, [editorView, onInsert]);
40
+ }, [editorView]);
42
41
  var onClose = (0, _react.useCallback)(function () {
43
42
  (0, _commands.closeElementBrowserModal)()(editorView.state, editorView.dispatch);
44
43
  focusInEditor();
@@ -51,8 +50,8 @@ var Modal = function Modal(_ref) {
51
50
  var item = insertableItem.current;
52
51
  insertableItem.current = null;
53
52
  focusInEditor();
54
- (0, _commands.insertItem)(item)(editorView.state, editorView.dispatch);
55
- }, [editorView, focusInEditor]);
53
+ insertItem === null || insertItem === void 0 || insertItem(item)(editorView.state, editorView.dispatch);
54
+ }, [editorView, focusInEditor, insertItem]);
56
55
  return /*#__PURE__*/_react.default.createElement(_ModalElementBrowser.default, {
57
56
  getItems: getItems,
58
57
  onInsertItem: onInsertItem,
@@ -75,6 +74,6 @@ var _default = exports.default = function _default(_ref2) {
75
74
  quickInsertState: quickInsertState !== null && quickInsertState !== void 0 ? quickInsertState : undefined,
76
75
  editorView: editorView,
77
76
  helpUrl: helpUrl,
78
- onInsert: pluginInjectionAPI === null || pluginInjectionAPI === void 0 || (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 || (_pluginInjectionAPI$q = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q === void 0 ? void 0 : _pluginInjectionAPI$q.onInsert
77
+ insertItem: pluginInjectionAPI === null || pluginInjectionAPI === void 0 || (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 || (_pluginInjectionAPI$q = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q === void 0 ? void 0 : _pluginInjectionAPI$q.insertItem
79
78
  });
80
79
  };
@@ -13,9 +13,10 @@ export const closeElementBrowserModal = () => (state, dispatch) => {
13
13
  }
14
14
  return true;
15
15
  };
16
+ export const createInsertItem = onInsert => insertItem(onInsert);
16
17
 
17
18
  // this method was adapted from the typeahead plugin so we respect the API for quick insert items
18
- export const insertItem = (item, source) => (state, dispatch) => {
19
+ const insertItem = onInsert => (item, source) => (state, dispatch) => {
19
20
  const insert = (maybeNode, opts = {}) => {
20
21
  return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
21
22
  };
@@ -25,5 +26,6 @@ export const insertItem = (item, source) => (state, dispatch) => {
25
26
  if (tr && dispatch) {
26
27
  dispatch(tr);
27
28
  }
29
+ onInsert === null || onInsert === void 0 ? void 0 : onInsert(item);
28
30
  return true;
29
31
  };
@@ -3,7 +3,7 @@ import { useIntl } from 'react-intl-next';
3
3
  import { memoProcessQuickInsertItems } from '@atlaskit/editor-common/quick-insert';
4
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
5
  import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
6
- import { insertItem, openElementBrowserModal } from './commands';
6
+ import { createInsertItem, openElementBrowserModal } from './commands';
7
7
  import { pluginKey } from './plugin-key';
8
8
  import { getQuickInsertSuggestions } from './search';
9
9
  import ModalElementBrowser from './ui/ModalElementBrowser';
@@ -85,7 +85,7 @@ export const quickInsertPlugin = ({
85
85
  };
86
86
  },
87
87
  actions: {
88
- insertItem,
88
+ insertItem: createInsertItem(onInsert),
89
89
  openTypeAhead(inputMethod) {
90
90
  var _api$typeAhead;
91
91
  return Boolean(api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.open({
@@ -106,8 +106,7 @@ export const quickInsertPlugin = ({
106
106
  };
107
107
  }
108
108
  return getQuickInsertSuggestions(searchOptions, lazyDefaultItems, providedItems);
109
- },
110
- onInsert
109
+ }
111
110
  },
112
111
  commands: {
113
112
  openElementBrowserModal,
@@ -1,13 +1,13 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
- import { closeElementBrowserModal, insertItem } from '../../commands';
3
+ import { closeElementBrowserModal } from '../../commands';
4
4
  import { getQuickInsertSuggestions } from '../../search';
5
5
  import ModalElementBrowser from './ModalElementBrowser';
6
6
  const Modal = ({
7
7
  quickInsertState,
8
8
  editorView,
9
9
  helpUrl,
10
- onInsert
10
+ insertItem
11
11
  }) => {
12
12
  const getItems = useCallback((query, category) => getQuickInsertSuggestions({
13
13
  query,
@@ -24,10 +24,9 @@ const Modal = ({
24
24
  // We wait until modal close is complete, refocus the editor and then add the item
25
25
  const insertableItem = React.useRef(null);
26
26
  const onInsertItem = useCallback(item => {
27
- onInsert === null || onInsert === void 0 ? void 0 : onInsert(item);
28
27
  closeElementBrowserModal()(editorView.state, editorView.dispatch);
29
28
  insertableItem.current = item;
30
- }, [editorView, onInsert]);
29
+ }, [editorView]);
31
30
  const onClose = useCallback(() => {
32
31
  closeElementBrowserModal()(editorView.state, editorView.dispatch);
33
32
  focusInEditor();
@@ -40,8 +39,8 @@ const Modal = ({
40
39
  const item = insertableItem.current;
41
40
  insertableItem.current = null;
42
41
  focusInEditor();
43
- insertItem(item)(editorView.state, editorView.dispatch);
44
- }, [editorView, focusInEditor]);
42
+ insertItem === null || insertItem === void 0 ? void 0 : insertItem(item)(editorView.state, editorView.dispatch);
43
+ }, [editorView, focusInEditor, insertItem]);
45
44
  return /*#__PURE__*/React.createElement(ModalElementBrowser, {
46
45
  getItems: getItems,
47
46
  onInsertItem: onInsertItem,
@@ -66,6 +65,6 @@ export default (({
66
65
  quickInsertState: quickInsertState !== null && quickInsertState !== void 0 ? quickInsertState : undefined,
67
66
  editorView: editorView,
68
67
  helpUrl: helpUrl,
69
- onInsert: pluginInjectionAPI === null || pluginInjectionAPI === void 0 ? void 0 : (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 ? void 0 : (_pluginInjectionAPI$q2 = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q2 === void 0 ? void 0 : _pluginInjectionAPI$q2.onInsert
68
+ insertItem: pluginInjectionAPI === null || pluginInjectionAPI === void 0 ? void 0 : (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 ? void 0 : (_pluginInjectionAPI$q2 = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q2 === void 0 ? void 0 : _pluginInjectionAPI$q2.insertItem
70
69
  });
71
70
  });
@@ -16,20 +16,26 @@ export var closeElementBrowserModal = function closeElementBrowserModal() {
16
16
  return true;
17
17
  };
18
18
  };
19
+ export var createInsertItem = function createInsertItem(onInsert) {
20
+ return insertItem(onInsert);
21
+ };
19
22
 
20
23
  // this method was adapted from the typeahead plugin so we respect the API for quick insert items
21
- export var insertItem = function insertItem(item, source) {
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, source);
24
+ var insertItem = function insertItem(onInsert) {
25
+ return function (item, source) {
26
+ return function (state, dispatch) {
27
+ var insert = function insert(maybeNode) {
28
+ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29
+ return insertSelectedItem(maybeNode, opts)(state, state.tr, state.selection.head);
30
+ };
31
+ var tr = item.action(insert, state, source);
28
32
 
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;
33
+ /** @note There is no transaction when called without a search currently (different insert) */
34
+ if (tr && dispatch) {
35
+ dispatch(tr);
36
+ }
37
+ onInsert === null || onInsert === void 0 || onInsert(item);
38
+ return true;
39
+ };
34
40
  };
35
41
  };
@@ -9,7 +9,7 @@ import { useIntl } from 'react-intl-next';
9
9
  import { memoProcessQuickInsertItems } from '@atlaskit/editor-common/quick-insert';
10
10
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
11
  import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
12
- import { insertItem, openElementBrowserModal } from './commands';
12
+ import { createInsertItem, openElementBrowserModal } from './commands';
13
13
  import { pluginKey } from './plugin-key';
14
14
  import { getQuickInsertSuggestions } from './search';
15
15
  import ModalElementBrowser from './ui/ModalElementBrowser';
@@ -89,7 +89,7 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
89
89
  };
90
90
  },
91
91
  actions: {
92
- insertItem: insertItem,
92
+ insertItem: createInsertItem(onInsert),
93
93
  openTypeAhead: function openTypeAhead(inputMethod) {
94
94
  var _api$typeAhead;
95
95
  return Boolean(api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.actions.open({
@@ -108,8 +108,7 @@ export var quickInsertPlugin = function quickInsertPlugin(_ref) {
108
108
  });
109
109
  }
110
110
  return getQuickInsertSuggestions(searchOptions, lazyDefaultItems, providedItems);
111
- },
112
- onInsert: onInsert
111
+ }
113
112
  },
114
113
  commands: {
115
114
  openElementBrowserModal: openElementBrowserModal,
@@ -1,13 +1,13 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
- import { closeElementBrowserModal, insertItem } from '../../commands';
3
+ import { closeElementBrowserModal } from '../../commands';
4
4
  import { getQuickInsertSuggestions } from '../../search';
5
5
  import ModalElementBrowser from './ModalElementBrowser';
6
6
  var Modal = function Modal(_ref) {
7
7
  var quickInsertState = _ref.quickInsertState,
8
8
  editorView = _ref.editorView,
9
9
  helpUrl = _ref.helpUrl,
10
- onInsert = _ref.onInsert;
10
+ insertItem = _ref.insertItem;
11
11
  var getItems = useCallback(function (query, category) {
12
12
  return getQuickInsertSuggestions({
13
13
  query: query,
@@ -25,10 +25,9 @@ var Modal = function Modal(_ref) {
25
25
  // We wait until modal close is complete, refocus the editor and then add the item
26
26
  var insertableItem = React.useRef(null);
27
27
  var onInsertItem = useCallback(function (item) {
28
- onInsert === null || onInsert === void 0 || onInsert(item);
29
28
  closeElementBrowserModal()(editorView.state, editorView.dispatch);
30
29
  insertableItem.current = item;
31
- }, [editorView, onInsert]);
30
+ }, [editorView]);
32
31
  var onClose = useCallback(function () {
33
32
  closeElementBrowserModal()(editorView.state, editorView.dispatch);
34
33
  focusInEditor();
@@ -41,8 +40,8 @@ var Modal = function Modal(_ref) {
41
40
  var item = insertableItem.current;
42
41
  insertableItem.current = null;
43
42
  focusInEditor();
44
- insertItem(item)(editorView.state, editorView.dispatch);
45
- }, [editorView, focusInEditor]);
43
+ insertItem === null || insertItem === void 0 || insertItem(item)(editorView.state, editorView.dispatch);
44
+ }, [editorView, focusInEditor, insertItem]);
46
45
  return /*#__PURE__*/React.createElement(ModalElementBrowser, {
47
46
  getItems: getItems,
48
47
  onInsertItem: onInsertItem,
@@ -65,6 +64,6 @@ export default (function (_ref2) {
65
64
  quickInsertState: quickInsertState !== null && quickInsertState !== void 0 ? quickInsertState : undefined,
66
65
  editorView: editorView,
67
66
  helpUrl: helpUrl,
68
- onInsert: pluginInjectionAPI === null || pluginInjectionAPI === void 0 || (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 || (_pluginInjectionAPI$q = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q === void 0 ? void 0 : _pluginInjectionAPI$q.onInsert
67
+ insertItem: pluginInjectionAPI === null || pluginInjectionAPI === void 0 || (_pluginInjectionAPI$q = pluginInjectionAPI.quickInsert) === null || _pluginInjectionAPI$q === void 0 || (_pluginInjectionAPI$q = _pluginInjectionAPI$q.actions) === null || _pluginInjectionAPI$q === void 0 ? void 0 : _pluginInjectionAPI$q.insertItem
69
68
  });
70
69
  });
@@ -3,4 +3,4 @@ import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
3
3
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
4
4
  export declare const openElementBrowserModal: EditorCommand;
5
5
  export declare const closeElementBrowserModal: () => Command;
6
- export declare const insertItem: (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
6
+ export declare const createInsertItem: (onInsert?: ((item: QuickInsertItem) => void) | undefined) => (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
@@ -14,7 +14,6 @@ export type QuickInsertPlugin = NextEditorPlugin<'quickInsert', {
14
14
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
15
15
  insertItem: (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
16
16
  getSuggestions: (searchOptions: QuickInsertSearchOptions) => QuickInsertItem[];
17
- onInsert: (item: QuickInsertItem) => void;
18
17
  };
19
18
  commands: {
20
19
  openElementBrowserModal: EditorCommand;
@@ -3,4 +3,4 @@ import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
3
3
  import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
4
4
  export declare const openElementBrowserModal: EditorCommand;
5
5
  export declare const closeElementBrowserModal: () => Command;
6
- export declare const insertItem: (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
6
+ export declare const createInsertItem: (onInsert?: ((item: QuickInsertItem) => void) | undefined) => (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
@@ -16,7 +16,6 @@ export type QuickInsertPlugin = NextEditorPlugin<'quickInsert', {
16
16
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
17
17
  insertItem: (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
18
18
  getSuggestions: (searchOptions: QuickInsertSearchOptions) => QuickInsertItem[];
19
- onInsert: (item: QuickInsertItem) => void;
20
19
  };
21
20
  commands: {
22
21
  openElementBrowserModal: EditorCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-quick-insert",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Quick insert plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/button": "^20.3.0",
35
- "@atlaskit/editor-common": "^94.2.0",
35
+ "@atlaskit/editor-common": "^94.8.0",
36
36
  "@atlaskit/editor-plugin-type-ahead": "^1.10.0",
37
37
  "@atlaskit/editor-prosemirror": "6.0.0",
38
38
  "@atlaskit/icon": "^22.24.0",