@atlaskit/editor-plugin-quick-insert 1.5.1 → 1.6.1

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 (39) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/index.js +2 -2
  3. package/dist/cjs/pm-plugins/commands/index.js +47 -0
  4. package/dist/cjs/{plugin.js → quickInsertPlugin.js} +5 -6
  5. package/dist/cjs/quickInsertPluginType.js +5 -0
  6. package/dist/cjs/ui/ModalElementBrowser/index.js +7 -8
  7. package/dist/es2019/index.js +1 -1
  8. package/dist/es2019/{commands.js → pm-plugins/commands/index.js} +4 -2
  9. package/dist/es2019/{plugin.js → quickInsertPlugin.js} +5 -6
  10. package/dist/es2019/quickInsertPluginType.js +1 -0
  11. package/dist/es2019/ui/ModalElementBrowser/index.js +7 -8
  12. package/dist/esm/index.js +1 -1
  13. package/dist/esm/pm-plugins/commands/index.js +41 -0
  14. package/dist/esm/{plugin.js → quickInsertPlugin.js} +5 -6
  15. package/dist/esm/quickInsertPluginType.js +1 -0
  16. package/dist/esm/ui/ModalElementBrowser/index.js +7 -8
  17. package/dist/types/index.d.ts +2 -2
  18. package/dist/types/{commands.d.ts → pm-plugins/commands/index.d.ts} +1 -1
  19. package/dist/types/quickInsertPlugin.d.ts +4 -0
  20. package/dist/types/{plugin.d.ts → quickInsertPluginType.d.ts} +0 -3
  21. package/dist/types/ui/ModalElementBrowser/index.d.ts +1 -1
  22. package/dist/types-ts4.5/index.d.ts +2 -2
  23. package/dist/types-ts4.5/{commands.d.ts → pm-plugins/commands/index.d.ts} +1 -1
  24. package/dist/types-ts4.5/quickInsertPlugin.d.ts +4 -0
  25. package/dist/types-ts4.5/{plugin.d.ts → quickInsertPluginType.d.ts} +0 -3
  26. package/dist/types-ts4.5/ui/ModalElementBrowser/index.d.ts +1 -1
  27. package/package.json +6 -3
  28. package/dist/cjs/commands.js +0 -41
  29. package/dist/esm/commands.js +0 -35
  30. /package/dist/cjs/{plugin-key.js → pm-plugins/plugin-key.js} +0 -0
  31. /package/dist/cjs/{search.js → ui/search.js} +0 -0
  32. /package/dist/es2019/{plugin-key.js → pm-plugins/plugin-key.js} +0 -0
  33. /package/dist/es2019/{search.js → ui/search.js} +0 -0
  34. /package/dist/esm/{plugin-key.js → pm-plugins/plugin-key.js} +0 -0
  35. /package/dist/esm/{search.js → ui/search.js} +0 -0
  36. /package/dist/types/{plugin-key.d.ts → pm-plugins/plugin-key.d.ts} +0 -0
  37. /package/dist/types/{search.d.ts → ui/search.d.ts} +0 -0
  38. /package/dist/types-ts4.5/{plugin-key.d.ts → pm-plugins/plugin-key.d.ts} +0 -0
  39. /package/dist/types-ts4.5/{search.d.ts → ui/search.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-quick-insert
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#159777](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/159777)
8
+ [`e708d0a9e4b36`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e708d0a9e4b36) -
9
+ Refactoring plugins to meet folder standards.
10
+ - Updated dependencies
11
+
12
+ ## 1.6.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#157845](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157845)
17
+ [`036086b523133`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/036086b523133) -
18
+ Removed onInsert from quickInsert plugin actions, as the behavior is now encapsulated within
19
+ insertItem
20
+
3
21
  ## 1.5.1
4
22
 
5
23
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "quickInsertPlugin", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _plugin.quickInsertPlugin;
9
+ return _quickInsertPlugin.quickInsertPlugin;
10
10
  }
11
11
  });
12
- var _plugin = require("./plugin");
12
+ var _quickInsertPlugin = require("./quickInsertPlugin");
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.openElementBrowserModal = exports.createInsertItem = exports.closeElementBrowserModal = void 0;
7
+ var _insert = require("@atlaskit/editor-common/insert");
8
+ var _pluginKey = require("../plugin-key");
9
+ var openElementBrowserModal = exports.openElementBrowserModal = function openElementBrowserModal(_ref) {
10
+ var tr = _ref.tr;
11
+ return tr.setMeta(_pluginKey.pluginKey, {
12
+ isElementBrowserModalOpen: true
13
+ });
14
+ };
15
+ var closeElementBrowserModal = exports.closeElementBrowserModal = function closeElementBrowserModal() {
16
+ return function (state, dispatch) {
17
+ if (dispatch) {
18
+ dispatch(state.tr.setMeta(_pluginKey.pluginKey, {
19
+ isElementBrowserModalOpen: false
20
+ }));
21
+ }
22
+ return true;
23
+ };
24
+ };
25
+ var createInsertItem = exports.createInsertItem = function createInsertItem(onInsert) {
26
+ return insertItem(onInsert);
27
+ };
28
+
29
+ // this method was adapted from the typeahead plugin so we respect the API for quick insert items
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);
38
+
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
+ };
46
+ };
47
+ };
@@ -14,10 +14,10 @@ var _reactIntlNext = require("react-intl-next");
14
14
  var _quickInsert = require("@atlaskit/editor-common/quick-insert");
15
15
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
16
16
  var _typeAhead = require("@atlaskit/editor-common/type-ahead");
17
- var _commands = require("./commands");
18
- var _pluginKey = require("./plugin-key");
19
- var _search = require("./search");
17
+ var _commands = require("./pm-plugins/commands");
18
+ var _pluginKey = require("./pm-plugins/plugin-key");
20
19
  var _ModalElementBrowser = _interopRequireDefault(require("./ui/ModalElementBrowser"));
20
+ var _search = require("./ui/search");
21
21
  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; }
22
22
  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) { (0, _defineProperty2.default)(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; }
23
23
  var quickInsertPlugin = exports.quickInsertPlugin = function quickInsertPlugin(_ref) {
@@ -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,
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _hooks = require("@atlaskit/editor-common/hooks");
11
- var _commands = require("../../commands");
12
- var _search = require("../../search");
11
+ var _commands = require("../../pm-plugins/commands");
12
+ var _search = require("../search");
13
13
  var _ModalElementBrowser = _interopRequireDefault(require("./ModalElementBrowser"));
14
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
15
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -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
  };
@@ -1 +1 @@
1
- export { quickInsertPlugin } from './plugin';
1
+ export { quickInsertPlugin } from './quickInsertPlugin';
@@ -1,5 +1,5 @@
1
1
  import { insertSelectedItem } from '@atlaskit/editor-common/insert';
2
- import { pluginKey } from './plugin-key';
2
+ import { pluginKey } from '../plugin-key';
3
3
  export const openElementBrowserModal = ({
4
4
  tr
5
5
  }) => tr.setMeta(pluginKey, {
@@ -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,10 +3,10 @@ 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';
7
- import { pluginKey } from './plugin-key';
8
- import { getQuickInsertSuggestions } from './search';
6
+ import { createInsertItem, openElementBrowserModal } from './pm-plugins/commands';
7
+ import { pluginKey } from './pm-plugins/plugin-key';
9
8
  import ModalElementBrowser from './ui/ModalElementBrowser';
9
+ import { getQuickInsertSuggestions } from './ui/search';
10
10
  export const quickInsertPlugin = ({
11
11
  config: options,
12
12
  api
@@ -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,
@@ -0,0 +1 @@
1
+ export {};
@@ -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';
4
- import { getQuickInsertSuggestions } from '../../search';
3
+ import { closeElementBrowserModal } from '../../pm-plugins/commands';
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
  });
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export { quickInsertPlugin } from './plugin';
1
+ export { quickInsertPlugin } from './quickInsertPlugin';
@@ -0,0 +1,41 @@
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
+ export var createInsertItem = function createInsertItem(onInsert) {
20
+ return insertItem(onInsert);
21
+ };
22
+
23
+ // this method was adapted from the typeahead plugin so we respect the API for quick insert items
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);
32
+
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
+ };
40
+ };
41
+ };
@@ -9,10 +9,10 @@ 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';
13
- import { pluginKey } from './plugin-key';
14
- import { getQuickInsertSuggestions } from './search';
12
+ import { createInsertItem, openElementBrowserModal } from './pm-plugins/commands';
13
+ import { pluginKey } from './pm-plugins/plugin-key';
15
14
  import ModalElementBrowser from './ui/ModalElementBrowser';
15
+ import { getQuickInsertSuggestions } from './ui/search';
16
16
  export var quickInsertPlugin = function quickInsertPlugin(_ref) {
17
17
  var options = _ref.config,
18
18
  api = _ref.api;
@@ -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,
@@ -0,0 +1 @@
1
+ export {};
@@ -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';
4
- import { getQuickInsertSuggestions } from '../../search';
3
+ import { closeElementBrowserModal } from '../../pm-plugins/commands';
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
  });
@@ -1,2 +1,2 @@
1
- export { quickInsertPlugin } from './plugin';
2
- export type { QuickInsertPlugin, QuickInsertSharedState } from './plugin';
1
+ export { quickInsertPlugin } from './quickInsertPlugin';
2
+ export type { QuickInsertPlugin, QuickInsertSharedState } from './quickInsertPluginType';
@@ -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;
@@ -0,0 +1,4 @@
1
+ import type { QuickInsertPluginOptions } from '@atlaskit/editor-common/types';
2
+ import { type QuickInsertPlugin } from './quickInsertPluginType';
3
+ export type { QuickInsertPluginOptions };
4
+ export declare const quickInsertPlugin: QuickInsertPlugin;
@@ -2,7 +2,6 @@ import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
3
3
  import type { Command, QuickInsertSharedState as CommonQuickInsertSharedState, EditorCommand, NextEditorPlugin, QuickInsertHandler, QuickInsertPluginOptions, QuickInsertSearchOptions, TypeAheadHandler } from '@atlaskit/editor-common/types';
4
4
  import type { TypeAheadInputMethod, TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
5
- export type { QuickInsertPluginOptions };
6
5
  export type QuickInsertSharedState = CommonQuickInsertSharedState & {
7
6
  typeAheadHandler: TypeAheadHandler;
8
7
  };
@@ -14,11 +13,9 @@ export type QuickInsertPlugin = NextEditorPlugin<'quickInsert', {
14
13
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
15
14
  insertItem: (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
16
15
  getSuggestions: (searchOptions: QuickInsertSearchOptions) => QuickInsertItem[];
17
- onInsert: (item: QuickInsertItem) => void;
18
16
  };
19
17
  commands: {
20
18
  openElementBrowserModal: EditorCommand;
21
19
  addQuickInsertItem: (item: QuickInsertHandler) => EditorCommand;
22
20
  };
23
21
  }>;
24
- export declare const quickInsertPlugin: QuickInsertPlugin;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { QuickInsertPlugin } from '../../index';
4
+ import type { QuickInsertPlugin } from '../../quickInsertPluginType';
5
5
  type Props = {
6
6
  editorView: EditorView;
7
7
  helpUrl: string | undefined;
@@ -1,2 +1,2 @@
1
- export { quickInsertPlugin } from './plugin';
2
- export type { QuickInsertPlugin, QuickInsertSharedState } from './plugin';
1
+ export { quickInsertPlugin } from './quickInsertPlugin';
2
+ export type { QuickInsertPlugin, QuickInsertSharedState } from './quickInsertPluginType';
@@ -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;
@@ -0,0 +1,4 @@
1
+ import type { QuickInsertPluginOptions } from '@atlaskit/editor-common/types';
2
+ import { type QuickInsertPlugin } from './quickInsertPluginType';
3
+ export type { QuickInsertPluginOptions };
4
+ export declare const quickInsertPlugin: QuickInsertPlugin;
@@ -2,7 +2,6 @@ import type { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import type { QuickInsertItem } from '@atlaskit/editor-common/provider-factory';
3
3
  import type { Command, QuickInsertSharedState as CommonQuickInsertSharedState, EditorCommand, NextEditorPlugin, QuickInsertHandler, QuickInsertPluginOptions, QuickInsertSearchOptions, TypeAheadHandler } from '@atlaskit/editor-common/types';
4
4
  import type { TypeAheadInputMethod, TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
5
- export type { QuickInsertPluginOptions };
6
5
  export type QuickInsertSharedState = CommonQuickInsertSharedState & {
7
6
  typeAheadHandler: TypeAheadHandler;
8
7
  };
@@ -16,11 +15,9 @@ export type QuickInsertPlugin = NextEditorPlugin<'quickInsert', {
16
15
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
17
16
  insertItem: (item: QuickInsertItem, source?: INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.TOOLBAR) => Command;
18
17
  getSuggestions: (searchOptions: QuickInsertSearchOptions) => QuickInsertItem[];
19
- onInsert: (item: QuickInsertItem) => void;
20
18
  };
21
19
  commands: {
22
20
  openElementBrowserModal: EditorCommand;
23
21
  addQuickInsertItem: (item: QuickInsertHandler) => EditorCommand;
24
22
  };
25
23
  }>;
26
- export declare const quickInsertPlugin: QuickInsertPlugin;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
- import type { QuickInsertPlugin } from '../../index';
4
+ import type { QuickInsertPlugin } from '../../quickInsertPluginType';
5
5
  type Props = {
6
6
  editorView: EditorView;
7
7
  helpUrl: string | undefined;
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.1",
4
4
  "description": "Quick insert plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,13 +32,13 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/button": "^20.3.0",
35
- "@atlaskit/editor-common": "^94.2.0",
35
+ "@atlaskit/editor-common": "^94.12.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",
39
39
  "@atlaskit/modal-dialog": "^12.17.0",
40
40
  "@atlaskit/theme": "^14.0.0",
41
- "@atlaskit/tokens": "^2.0.0",
41
+ "@atlaskit/tokens": "^2.1.0",
42
42
  "@babel/runtime": "^7.0.0",
43
43
  "@emotion/react": "^11.7.1"
44
44
  },
@@ -57,6 +57,9 @@
57
57
  },
58
58
  "techstack": {
59
59
  "@atlassian/frontend": {
60
+ "code-structure": [
61
+ "editor-plugin"
62
+ ],
60
63
  "import-structure": [
61
64
  "atlassian-conventions"
62
65
  ],
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.openElementBrowserModal = exports.insertItem = exports.closeElementBrowserModal = void 0;
7
- var _insert = require("@atlaskit/editor-common/insert");
8
- var _pluginKey = require("./plugin-key");
9
- var openElementBrowserModal = exports.openElementBrowserModal = function openElementBrowserModal(_ref) {
10
- var tr = _ref.tr;
11
- return tr.setMeta(_pluginKey.pluginKey, {
12
- isElementBrowserModalOpen: true
13
- });
14
- };
15
- var closeElementBrowserModal = exports.closeElementBrowserModal = function closeElementBrowserModal() {
16
- return function (state, dispatch) {
17
- if (dispatch) {
18
- dispatch(state.tr.setMeta(_pluginKey.pluginKey, {
19
- isElementBrowserModalOpen: false
20
- }));
21
- }
22
- return true;
23
- };
24
- };
25
-
26
- // 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);
34
-
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;
40
- };
41
- };
@@ -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, 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);
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
- };
File without changes
File without changes
File without changes
File without changes