@atlaskit/editor-core 188.3.1 → 188.4.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/labs/next/presets/universal.js +2 -1
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +2 -4
  5. package/dist/cjs/plugins/mentions/index.js +31 -21
  6. package/dist/cjs/plugins/mentions/ui/ToolbarMention/index.js +1 -3
  7. package/dist/cjs/plugins/placeholder-text/index.js +9 -9
  8. package/dist/cjs/plugins/type-ahead/api.js +8 -26
  9. package/dist/cjs/plugins/type-ahead/index.js +135 -4
  10. package/dist/cjs/plugins/undo-redo/index.js +10 -8
  11. package/dist/cjs/plugins/undo-redo/types.js +5 -0
  12. package/dist/cjs/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +10 -9
  13. package/dist/cjs/test-utils.js +0 -7
  14. package/dist/cjs/version-wrapper.js +1 -1
  15. package/dist/es2019/labs/next/presets/universal.js +2 -1
  16. package/dist/es2019/plugins/index.js +1 -2
  17. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +2 -4
  18. package/dist/es2019/plugins/mentions/index.js +30 -22
  19. package/dist/es2019/plugins/mentions/ui/ToolbarMention/index.js +2 -5
  20. package/dist/es2019/plugins/placeholder-text/index.js +8 -8
  21. package/dist/es2019/plugins/type-ahead/api.js +9 -28
  22. package/dist/es2019/plugins/type-ahead/index.js +140 -5
  23. package/dist/es2019/plugins/undo-redo/index.js +5 -2
  24. package/dist/es2019/plugins/undo-redo/types.js +1 -0
  25. package/dist/es2019/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +10 -9
  26. package/dist/es2019/test-utils.js +0 -1
  27. package/dist/es2019/version-wrapper.js +1 -1
  28. package/dist/esm/labs/next/presets/universal.js +2 -1
  29. package/dist/esm/plugins/index.js +1 -2
  30. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +2 -4
  31. package/dist/esm/plugins/mentions/index.js +32 -22
  32. package/dist/esm/plugins/mentions/ui/ToolbarMention/index.js +2 -5
  33. package/dist/esm/plugins/placeholder-text/index.js +9 -9
  34. package/dist/esm/plugins/type-ahead/api.js +9 -27
  35. package/dist/esm/plugins/type-ahead/index.js +136 -5
  36. package/dist/esm/plugins/undo-redo/index.js +10 -8
  37. package/dist/esm/plugins/undo-redo/types.js +1 -0
  38. package/dist/esm/plugins/undo-redo/ui/ToolbarUndoRedo/index.js +10 -9
  39. package/dist/esm/test-utils.js +0 -1
  40. package/dist/esm/version-wrapper.js +1 -1
  41. package/dist/types/labs/next/presets/default.d.ts +228 -18
  42. package/dist/types/plugins/index.d.ts +0 -1
  43. package/dist/types/plugins/insert-block/types.d.ts +3 -1
  44. package/dist/types/plugins/mentions/index.d.ts +11 -4
  45. package/dist/types/plugins/mentions/ui/ToolbarMention/index.d.ts +1 -0
  46. package/dist/types/plugins/placeholder-text/index.d.ts +8 -3
  47. package/dist/types/plugins/type-ahead/api.d.ts +7 -9
  48. package/dist/types/plugins/type-ahead/utils.d.ts +1 -2
  49. package/dist/types/plugins/undo-redo/index.d.ts +2 -2
  50. package/dist/types/plugins/undo-redo/types.d.ts +5 -0
  51. package/dist/types/plugins/undo-redo/ui/ToolbarUndoRedo/index.d.ts +3 -0
  52. package/dist/types/test-utils.d.ts +0 -1
  53. package/dist/types-ts4.5/labs/next/presets/default.d.ts +256 -18
  54. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  55. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +3 -1
  56. package/dist/types-ts4.5/plugins/mentions/index.d.ts +11 -4
  57. package/dist/types-ts4.5/plugins/mentions/ui/ToolbarMention/index.d.ts +1 -0
  58. package/dist/types-ts4.5/plugins/placeholder-text/index.d.ts +12 -3
  59. package/dist/types-ts4.5/plugins/type-ahead/api.d.ts +7 -9
  60. package/dist/types-ts4.5/plugins/type-ahead/utils.d.ts +1 -2
  61. package/dist/types-ts4.5/plugins/undo-redo/index.d.ts +2 -2
  62. package/dist/types-ts4.5/plugins/undo-redo/types.d.ts +7 -0
  63. package/dist/types-ts4.5/plugins/undo-redo/ui/ToolbarUndoRedo/index.d.ts +3 -0
  64. package/dist/types-ts4.5/test-utils.d.ts +0 -1
  65. package/package.json +6 -5
  66. package/dist/cjs/plugins/border/index.js +0 -19
  67. package/dist/es2019/plugins/border/index.js +0 -11
  68. package/dist/esm/plugins/border/index.js +0 -13
  69. package/dist/types/plugins/border/index.d.ts +0 -3
  70. package/dist/types-ts4.5/plugins/border/index.d.ts +0 -3
@@ -1,22 +1,19 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
1
4
  import React from 'react';
2
5
  import uuid from 'uuid';
3
6
  import { ELEMENTS_CHANNEL } from '@atlaskit/mention/resource';
4
7
  import { mention } from '@atlaskit/adf-schema';
5
8
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
6
9
  import ToolbarMention from './ui/ToolbarMention';
7
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
10
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
8
11
  import { IconMention } from '@atlaskit/editor-common/quick-insert';
9
12
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
10
13
  import { createTypeAheadConfig } from './type-ahead';
11
14
  import { mentionPluginKey } from './pm-plugins/key';
12
15
  import { createMentionPlugin } from './pm-plugins/main';
13
16
  export { mentionPluginKey };
14
- var getSharedState = function getSharedState(editorState) {
15
- if (!editorState) {
16
- return undefined;
17
- }
18
- return mentionPluginKey.getState(editorState);
19
- };
20
17
  var mentionsPlugin = function mentionsPlugin(_ref) {
21
18
  var options = _ref.config,
22
19
  api = _ref.api;
@@ -58,6 +55,13 @@ var mentionsPlugin = function mentionsPlugin(_ref) {
58
55
  secondaryToolbarComponent: function secondaryToolbarComponent(_ref3) {
59
56
  var editorView = _ref3.editorView,
60
57
  disabled = _ref3.disabled;
58
+ var openMentionTypeAhead = function openMentionTypeAhead() {
59
+ var _api$typeAhead;
60
+ api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 || (_api$typeAhead = _api$typeAhead.actions) === null || _api$typeAhead === void 0 || _api$typeAhead.open({
61
+ triggerHandler: typeAhead,
62
+ inputMethod: INPUT_METHOD.INSERT_MENU
63
+ });
64
+ };
61
65
  return /*#__PURE__*/React.createElement(WithPluginState, {
62
66
  editorView: editorView,
63
67
  plugins: {
@@ -68,12 +72,30 @@ var mentionsPlugin = function mentionsPlugin(_ref) {
68
72
  mentionState = _ref4$mentionState === void 0 ? {} : _ref4$mentionState;
69
73
  return !mentionState.mentionProvider ? null : /*#__PURE__*/React.createElement(ToolbarMention, {
70
74
  editorView: editorView,
75
+ onInsertMention: openMentionTypeAhead,
71
76
  isDisabled: disabled || (api === null || api === void 0 ? void 0 : api.typeAhead.actions.isAllowed(editorView.state))
72
77
  });
73
78
  }
74
79
  });
75
80
  },
76
- getSharedState: getSharedState,
81
+ actions: {
82
+ openTypeAhead: function openTypeAhead(inputMethod) {
83
+ var _api$typeAhead2;
84
+ return Boolean(api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.open({
85
+ triggerHandler: typeAhead,
86
+ inputMethod: inputMethod
87
+ }));
88
+ }
89
+ },
90
+ getSharedState: function getSharedState(editorState) {
91
+ if (!editorState) {
92
+ return undefined;
93
+ }
94
+ var mentionPluginState = mentionPluginKey.getState(editorState);
95
+ return _objectSpread(_objectSpread({}, mentionPluginState), {}, {
96
+ typeAheadHandler: typeAhead
97
+ });
98
+ },
77
99
  pluginsOptions: {
78
100
  quickInsert: function quickInsert(_ref5) {
79
101
  var formatMessage = _ref5.formatMessage;
@@ -88,26 +110,14 @@ var mentionsPlugin = function mentionsPlugin(_ref) {
88
110
  return /*#__PURE__*/React.createElement(IconMention, null);
89
111
  },
90
112
  action: function action(insert, state) {
91
- var _api$analytics2;
92
113
  var tr = insert(undefined);
93
- var pluginState = getSharedState(state);
114
+ var pluginState = mentionPluginKey.getState(state);
94
115
  if (pluginState && pluginState.canInsertMention === false) {
95
116
  return false;
96
117
  }
97
- api === null || api === void 0 || api.typeAhead.commands.openTypeAheadAtCursor({
118
+ api === null || api === void 0 || api.typeAhead.actions.openAtTransaction({
98
119
  triggerHandler: typeAhead,
99
120
  inputMethod: INPUT_METHOD.QUICK_INSERT
100
- })({
101
- tr: tr
102
- });
103
- api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
104
- action: ACTION.INVOKED,
105
- actionSubject: ACTION_SUBJECT.TYPEAHEAD,
106
- actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_MENTION,
107
- attributes: {
108
- inputMethod: INPUT_METHOD.QUICK_INSERT
109
- },
110
- eventType: EVENT_TYPE.UI
111
121
  })(tr);
112
122
  return tr;
113
123
  }
@@ -7,12 +7,9 @@ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
8
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
9
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
- import React from 'react';
11
- import { PureComponent } from 'react';
10
+ import React, { PureComponent } from 'react';
12
11
  import MentionIcon from '@atlaskit/icon/glyph/editor/mention';
13
12
  import { ToolbarButton, TOOLBAR_BUTTON } from '@atlaskit/editor-common/ui-menu';
14
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
15
- import { createTypeAheadTools } from '../../../type-ahead/api';
16
13
  import { injectIntl } from 'react-intl-next';
17
14
  import { messages } from '../../messages';
18
15
  var ToolbarMention = /*#__PURE__*/function (_PureComponent) {
@@ -29,7 +26,7 @@ var ToolbarMention = /*#__PURE__*/function (_PureComponent) {
29
26
  if (!_this.props.editorView) {
30
27
  return false;
31
28
  }
32
- createTypeAheadTools(_this.props.editorView).openMention(INPUT_METHOD.INSERT_MENU);
29
+ _this.props.onInsertMention();
33
30
  return true;
34
31
  });
35
32
  return _this;
@@ -13,19 +13,18 @@ import { pluginKey } from './plugin-key';
13
13
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
14
14
  import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
15
15
  import { isSelectionAtPlaceholder } from './selection-utils';
16
- import { createInternalTypeAheadTools } from '../type-ahead/api';
17
- var getOpenTypeAhead = function getOpenTypeAhead(view, content) {
18
- var typeAheadAPI = createInternalTypeAheadTools(view);
19
- var typeAheadHandler = typeAheadAPI.findTypeAheadHandler(content);
16
+ var getOpenTypeAhead = function getOpenTypeAhead(trigger, api) {
17
+ var _api$typeAhead, _api$typeAhead2;
18
+ var typeAheadHandler = api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 || (_api$typeAhead = _api$typeAhead.actions) === null || _api$typeAhead === void 0 ? void 0 : _api$typeAhead.findHandlerByTrigger(trigger);
20
19
  if (!typeAheadHandler || !typeAheadHandler.id) {
21
20
  return null;
22
21
  }
23
- return typeAheadAPI.openTypeAheadHandler({
22
+ return api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.openAtTransaction({
24
23
  triggerHandler: typeAheadHandler,
25
24
  inputMethod: INPUT_METHOD.KEYBOARD
26
25
  });
27
26
  };
28
- export function createPlugin(dispatch, options) {
27
+ export function createPlugin(dispatch, options, api) {
29
28
  var allowInserting = !!options.allowInserting;
30
29
  return new SafePlugin({
31
30
  key: pluginKey,
@@ -103,7 +102,7 @@ export function createPlugin(dispatch, options) {
103
102
  var content = event.data || '';
104
103
  var tr = view.state.tr;
105
104
  tr.delete(startNodePosition, startNodePosition + 1);
106
- var openTypeAhead = getOpenTypeAhead(view, content);
105
+ var openTypeAhead = getOpenTypeAhead(content, api);
107
106
  if (openTypeAhead) {
108
107
  openTypeAhead(tr);
109
108
  } else {
@@ -124,7 +123,8 @@ export function createPlugin(dispatch, options) {
124
123
  });
125
124
  }
126
125
  var basePlaceholderTextPlugin = function basePlaceholderTextPlugin(_ref) {
127
- var options = _ref.config;
126
+ var api = _ref.api,
127
+ options = _ref.config;
128
128
  return {
129
129
  name: 'placeholderText',
130
130
  nodes: function nodes() {
@@ -138,7 +138,7 @@ var basePlaceholderTextPlugin = function basePlaceholderTextPlugin(_ref) {
138
138
  name: 'placeholderText',
139
139
  plugin: function plugin(_ref2) {
140
140
  var dispatch = _ref2.dispatch;
141
- return createPlugin(dispatch, options);
141
+ return createPlugin(dispatch, options, api);
142
142
  }
143
143
  }];
144
144
  },
@@ -1,7 +1,7 @@
1
1
  import { TypeAheadAvailableNodes, SelectItemMode } from '@atlaskit/editor-common/type-ahead';
2
- import { findHandler, findHandlerByTrigger, isTypeAheadOpen, getTypeAheadHandler, getTypeAheadQuery } from './utils';
2
+ import { findHandler, isTypeAheadOpen, getTypeAheadHandler, getTypeAheadQuery } from './utils';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
- import { openTypeAheadAtCursor, openTypeAhead } from './transforms/open-typeahead-at-cursor';
4
+ import { openTypeAheadAtCursor } from './transforms/open-typeahead-at-cursor';
5
5
  import { closeTypeAhead } from './transforms/close-type-ahead';
6
6
  import { updateQuery } from './commands/update-query';
7
7
  import { insertTypeAheadItem } from './commands/insert-type-ahead-item';
@@ -180,32 +180,14 @@ var currentQuery = function currentQuery(_ref8) {
180
180
  return getTypeAheadQuery(editorView.state);
181
181
  };
182
182
  };
183
- var find = function find(_ref9) {
184
- var editorView = _ref9.editorView;
185
- return function (trigger) {
186
- var editorState = editorView.state;
187
- var handler = findHandlerByTrigger({
188
- trigger: trigger,
189
- editorState: editorState
190
- });
191
- if (!handler) {
192
- return null;
193
- }
194
- return handler;
195
- };
196
- };
197
183
 
198
- // This is an internal tool to be used inside of others Editor Plugins
199
- // We shouldn't public export this method.
200
- export var createInternalTypeAheadTools = function createInternalTypeAheadTools(editorView) {
201
- var props = {
202
- editorView: editorView
203
- };
204
- return {
205
- findTypeAheadHandler: find(props),
206
- openTypeAheadHandler: openTypeAhead
207
- };
208
- };
184
+ /**
185
+ * Please do not use it. Ping #help-editor and talk to the Lego team before use it.
186
+ *
187
+ * @private
188
+ * @deprecated
189
+ *
190
+ */
209
191
  export var createTypeAheadTools = function createTypeAheadTools(editorView) {
210
192
  var props = {
211
193
  editorView: editorView
@@ -9,6 +9,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
9
9
  */
10
10
  import React from 'react';
11
11
  import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
12
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
12
13
  import { createPlugin } from './pm-plugins/main';
13
14
  import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
14
15
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
@@ -16,12 +17,14 @@ import { typeAheadQuery } from '@atlaskit/adf-schema';
16
17
  import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
17
18
  import { inputRulePlugin } from './pm-plugins/input-rules';
18
19
  import { TypeAheadPopup } from './ui/TypeAheadPopup';
19
- import { getPluginState, isTypeAheadOpen, isTypeAheadAllowed } from './utils';
20
+ import { findHandler, getPluginState, isTypeAheadOpen, isTypeAheadAllowed, getTypeAheadQuery, getTypeAheadHandler } from './utils';
20
21
  import { useItemInsert } from './ui/hooks/use-item-insert';
21
22
  import { updateSelectedIndex } from './commands/update-selected-index';
22
23
  import { StatsModifier } from './stats-modifier';
23
24
  import { ACTION, ACTION_SUBJECT, INPUT_METHOD, EVENT_TYPE, fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
24
25
  import { openTypeAheadAtCursor } from './transforms/open-typeahead-at-cursor';
26
+ import { closeTypeAhead } from './transforms/close-type-ahead';
27
+ import { insertTypeAheadItem } from './commands/insert-type-ahead-item';
25
28
  var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
26
29
  var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
27
30
  var editorView = _ref.editorView,
@@ -104,6 +107,103 @@ var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
104
107
  cancel: cancel
105
108
  });
106
109
  });
110
+ var createOpenAtTransaction = function createOpenAtTransaction(editorAnalyticsAPI) {
111
+ return function (props) {
112
+ return function (tr) {
113
+ var triggerHandler = props.triggerHandler,
114
+ inputMethod = props.inputMethod;
115
+ openTypeAheadAtCursor({
116
+ triggerHandler: triggerHandler,
117
+ inputMethod: inputMethod
118
+ })({
119
+ tr: tr
120
+ });
121
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
122
+ action: ACTION.INVOKED,
123
+ actionSubject: ACTION_SUBJECT.TYPEAHEAD,
124
+ actionSubjectId: triggerHandler.id,
125
+ attributes: {
126
+ inputMethod: inputMethod
127
+ },
128
+ eventType: EVENT_TYPE.UI
129
+ })(tr);
130
+ return true;
131
+ };
132
+ };
133
+ };
134
+ var createOpenTypeAhead = function createOpenTypeAhead(editorViewRef, editorAnalyticsAPI) {
135
+ return function (props) {
136
+ if (!editorViewRef.current) {
137
+ return false;
138
+ }
139
+ var view = editorViewRef.current;
140
+ var tr = view.state.tr;
141
+ createOpenAtTransaction(editorAnalyticsAPI)(props)(tr);
142
+ view.dispatch(tr);
143
+ return true;
144
+ };
145
+ };
146
+ var createInsertTypeAheadItem = function createInsertTypeAheadItem(editorViewRef) {
147
+ return function (props) {
148
+ if (!editorViewRef.current) {
149
+ return false;
150
+ }
151
+ var view = editorViewRef.current;
152
+ var triggerHandler = props.triggerHandler,
153
+ contentItem = props.contentItem,
154
+ query = props.query,
155
+ sourceListItem = props.sourceListItem,
156
+ mode = props.mode;
157
+ insertTypeAheadItem(view)({
158
+ handler: triggerHandler,
159
+ item: contentItem,
160
+ mode: mode || SelectItemMode.SELECTED,
161
+ query: query,
162
+ sourceListItem: sourceListItem
163
+ });
164
+ return true;
165
+ };
166
+ };
167
+ var createFindHandlerByTrigger = function createFindHandlerByTrigger(editorViewRef) {
168
+ return function (trigger) {
169
+ if (!editorViewRef.current) {
170
+ return null;
171
+ }
172
+ var view = editorViewRef.current;
173
+ return findHandler(trigger, view.state);
174
+ };
175
+ };
176
+ var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
177
+ return function (options) {
178
+ if (!editorViewRef.current) {
179
+ return false;
180
+ }
181
+ var view = editorViewRef.current;
182
+ var currentQuery = getTypeAheadQuery(view.state) || '';
183
+ var state = view.state;
184
+ var tr = state.tr;
185
+ if (options.attachCommand) {
186
+ var fakeDispatch = function fakeDispatch(customTr) {
187
+ tr = customTr;
188
+ };
189
+ options.attachCommand(state, fakeDispatch);
190
+ }
191
+ closeTypeAhead(tr);
192
+ if (options.insertCurrentQueryAsRawText && currentQuery && currentQuery.length > 0) {
193
+ var handler = getTypeAheadHandler(state);
194
+ if (!handler) {
195
+ return false;
196
+ }
197
+ var text = handler.trigger.concat(currentQuery);
198
+ tr.replaceSelectionWith(state.schema.text(text));
199
+ }
200
+ view.dispatch(tr);
201
+ if (!view.hasFocus()) {
202
+ view.focus();
203
+ }
204
+ return true;
205
+ };
206
+ };
107
207
 
108
208
  /**
109
209
  *
@@ -114,11 +214,16 @@ var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
114
214
  *
115
215
  */
116
216
  var typeAheadPlugin = function typeAheadPlugin(_ref4) {
117
- var options = _ref4.config;
217
+ var _api$analytics, _api$analytics2;
218
+ var options = _ref4.config,
219
+ api = _ref4.api;
118
220
  var fireAnalyticsCallback = fireAnalyticsEvent(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
119
221
  var popupMountRef = {
120
222
  current: null
121
223
  };
224
+ var editorViewRef = {
225
+ current: null
226
+ };
122
227
  return {
123
228
  name: 'typeAhead',
124
229
  marks: function marks() {
@@ -144,6 +249,20 @@ var typeAheadPlugin = function typeAheadPlugin(_ref4) {
144
249
  createAnalyticsEvent: options === null || options === void 0 ? void 0 : options.createAnalyticsEvent
145
250
  });
146
251
  }
252
+ }, {
253
+ name: 'typeAheadEditorViewRef',
254
+ plugin: function plugin() {
255
+ return new SafePlugin({
256
+ view: function view(_view) {
257
+ editorViewRef.current = _view;
258
+ return {
259
+ destroy: function destroy() {
260
+ editorViewRef.current = null;
261
+ }
262
+ };
263
+ }
264
+ });
265
+ }
147
266
  }, {
148
267
  name: 'typeAheadInsertItem',
149
268
  plugin: createInsertItemPlugin
@@ -156,12 +275,24 @@ var typeAheadPlugin = function typeAheadPlugin(_ref4) {
156
275
  }
157
276
  }];
158
277
  },
159
- commands: {
160
- openTypeAheadAtCursor: openTypeAheadAtCursor
278
+ getSharedState: function getSharedState(editorState) {
279
+ if (!editorState) {
280
+ return {
281
+ query: ''
282
+ };
283
+ }
284
+ return {
285
+ query: getTypeAheadQuery(editorState) || ''
286
+ };
161
287
  },
162
288
  actions: {
163
289
  isOpen: isTypeAheadOpen,
164
- isAllowed: isTypeAheadAllowed
290
+ isAllowed: isTypeAheadAllowed,
291
+ open: createOpenTypeAhead(editorViewRef, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
292
+ openAtTransaction: createOpenAtTransaction(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
293
+ findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
294
+ insert: createInsertTypeAheadItem(editorViewRef),
295
+ close: createCloseTypeAhead(editorViewRef)
165
296
  },
166
297
  contentComponent: function contentComponent(_ref7) {
167
298
  var editorView = _ref7.editorView,
@@ -4,7 +4,8 @@ import { createPlugin } from './pm-plugins/main';
4
4
  import { historyPluginKey } from '../history';
5
5
  import ToolbarUndoRedo from './ui/ToolbarUndoRedo';
6
6
  import WithPluginState from '../../ui/WithPluginState';
7
- var undoRedoPlugin = function undoRedoPlugin() {
7
+ var undoRedoPlugin = function undoRedoPlugin(_ref) {
8
+ var api = _ref.api;
8
9
  return {
9
10
  name: 'undoRedoPlugin',
10
11
  pmPlugins: function pmPlugins() {
@@ -20,21 +21,22 @@ var undoRedoPlugin = function undoRedoPlugin() {
20
21
  }
21
22
  }];
22
23
  },
23
- primaryToolbarComponent: function primaryToolbarComponent(_ref) {
24
- var editorView = _ref.editorView,
25
- disabled = _ref.disabled,
26
- isToolbarReducedSpacing = _ref.isToolbarReducedSpacing;
24
+ primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
25
+ var editorView = _ref2.editorView,
26
+ disabled = _ref2.disabled,
27
+ isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing;
27
28
  return /*#__PURE__*/React.createElement(WithPluginState, {
28
29
  plugins: {
29
30
  historyState: historyPluginKey
30
31
  },
31
- render: function render(_ref2) {
32
- var historyState = _ref2.historyState;
32
+ render: function render(_ref3) {
33
+ var historyState = _ref3.historyState;
33
34
  return /*#__PURE__*/React.createElement(ToolbarUndoRedo, {
34
35
  isReducedSpacing: isToolbarReducedSpacing,
35
36
  disabled: disabled,
36
37
  historyState: historyState,
37
- editorView: editorView
38
+ editorView: editorView,
39
+ api: api
38
40
  });
39
41
  }
40
42
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -15,17 +15,17 @@ import { undo as undoKeymap, redo as redoKeymap, ToolTipContent, tooltip } from
15
15
  import { separatorStyles, buttonGroupStyle } from '@atlaskit/editor-common/styles';
16
16
  import ToolbarButton, { TOOLBAR_BUTTON } from '../../../../ui/ToolbarButton';
17
17
  import { undoRedoMessages } from '@atlaskit/editor-common/messages';
18
- import { createTypeAheadTools } from '../../../type-ahead/api';
19
18
  import { undoFromToolbar, redoFromToolbar } from '../../commands';
20
19
  import { getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
21
- var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView) {
20
+ var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorView, api) {
22
21
  return function (command) {
22
+ var _api$typeAhead;
23
23
  if (!editorView) {
24
24
  return;
25
25
  }
26
- var tool = createTypeAheadTools(editorView);
27
- if (tool.isOpen()) {
28
- tool.close({
26
+ if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead = _api$typeAhead.actions) !== null && _api$typeAhead !== void 0 && _api$typeAhead.isOpen(editorView.state)) {
27
+ var _api$typeAhead2;
28
+ api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 || _api$typeAhead2.close({
29
29
  attachCommand: command,
30
30
  insertCurrentQueryAsRawText: false
31
31
  });
@@ -34,9 +34,9 @@ var closeTypeAheadAndRunCommand = function closeTypeAheadAndRunCommand(editorVie
34
34
  }
35
35
  };
36
36
  };
37
- var forceFocus = function forceFocus(editorView) {
37
+ var forceFocus = function forceFocus(editorView, api) {
38
38
  return function (command) {
39
- closeTypeAheadAndRunCommand(editorView)(command);
39
+ closeTypeAheadAndRunCommand(editorView, api)(command);
40
40
  if (!editorView.hasFocus()) {
41
41
  editorView.focus();
42
42
  }
@@ -57,12 +57,13 @@ export var ToolbarUndoRedo = /*#__PURE__*/function (_PureComponent) {
57
57
  isReducedSpacing = _this$props.isReducedSpacing,
58
58
  historyState = _this$props.historyState,
59
59
  editorView = _this$props.editorView,
60
+ api = _this$props.api,
60
61
  formatMessage = _this$props.intl.formatMessage;
61
62
  var handleUndo = function handleUndo() {
62
- forceFocus(editorView)(undoFromToolbar);
63
+ forceFocus(editorView, api)(undoFromToolbar);
63
64
  };
64
65
  var handleRedo = function handleRedo() {
65
- forceFocus(editorView)(redoFromToolbar);
66
+ forceFocus(editorView, api)(redoFromToolbar);
66
67
  };
67
68
  var labelUndo = formatMessage(undoRedoMessages.undo);
68
69
  var labelRedo = formatMessage(undoRedoMessages.redo);
@@ -8,7 +8,6 @@ import { createSchema } from './create-editor/create-schema';
8
8
  import { sortByOrder } from './create-editor/sort-by-order';
9
9
  import { analyticsPluginKey } from './plugins/analytics/plugin-key';
10
10
  import { basePlugin } from '@atlaskit/editor-plugin-base';
11
- export { createTypeAheadTools } from './plugins/type-ahead/api';
12
11
  export function getFireAnalytics(editorView) {
13
12
  var _analyticsPluginKey$g;
14
13
  return analyticsPluginKey === null || analyticsPluginKey === void 0 || (_analyticsPluginKey$g = analyticsPluginKey.getState(editorView.state)) === null || _analyticsPluginKey$g === void 0 ? void 0 : _analyticsPluginKey$g.fireAnalytics;
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "188.3.1";
2
+ export var version = "188.4.0";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };