@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
@@ -14,7 +14,6 @@ import { showPlaceholderFloatingToolbar } from '../../../placeholder-text/action
14
14
  import { insertLayoutColumnsWithAnalytics } from '../../../layout/actions';
15
15
  import { insertTaskDecisionCommand } from '../../../tasks-and-decisions/commands';
16
16
  import { insertExpand } from '../../../expand/commands';
17
- import { createTypeAheadTools } from '../../../type-ahead/api';
18
17
  import { updateStatusWithAnalytics } from '../../../status/actions';
19
18
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
20
19
  import { messages } from './messages';
@@ -157,7 +156,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
157
156
  return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$h = pluginInjectionApi.hyperlink) === null || _pluginInjectionApi$h === void 0 ? void 0 : _pluginInjectionApi$h.commands.showLinkToolbar(inputMethod))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
158
157
  });
159
158
  _defineProperty(this, "insertMention", inputMethod => {
160
- var _pluginInjectionApi$m;
159
+ var _pluginInjectionApi$m, _pluginInjectionApi$m2, _pluginInjectionApi$m3;
161
160
  const {
162
161
  editorView,
163
162
  pluginInjectionApi
@@ -169,8 +168,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
169
168
  if (pluginState && pluginState.canInsertMention === false) {
170
169
  return false;
171
170
  }
172
- createTypeAheadTools(editorView).openMention(inputMethod);
173
- return true;
171
+ return Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$m2 = pluginInjectionApi.mention) === null || _pluginInjectionApi$m2 === void 0 ? void 0 : (_pluginInjectionApi$m3 = _pluginInjectionApi$m2.actions) === null || _pluginInjectionApi$m3 === void 0 ? void 0 : _pluginInjectionApi$m3.openTypeAhead(inputMethod));
174
172
  });
175
173
  _defineProperty(this, "insertTable", inputMethod => {
176
174
  var _pluginInjectionApi$t, _pluginInjectionApi$t2, _pluginInjectionApi$t3, _pluginInjectionApi$t4;
@@ -4,19 +4,13 @@ import { ELEMENTS_CHANNEL } from '@atlaskit/mention/resource';
4
4
  import { mention } from '@atlaskit/adf-schema';
5
5
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
6
6
  import ToolbarMention from './ui/ToolbarMention';
7
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
8
8
  import { IconMention } from '@atlaskit/editor-common/quick-insert';
9
9
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
10
10
  import { createTypeAheadConfig } from './type-ahead';
11
11
  import { mentionPluginKey } from './pm-plugins/key';
12
12
  import { createMentionPlugin } from './pm-plugins/main';
13
13
  export { mentionPluginKey };
14
- const getSharedState = editorState => {
15
- if (!editorState) {
16
- return undefined;
17
- }
18
- return mentionPluginKey.getState(editorState);
19
- };
20
14
  const mentionsPlugin = ({
21
15
  config: options,
22
16
  api
@@ -59,6 +53,13 @@ const mentionsPlugin = ({
59
53
  editorView,
60
54
  disabled
61
55
  }) {
56
+ const openMentionTypeAhead = () => {
57
+ var _api$typeAhead, _api$typeAhead$action;
58
+ api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : (_api$typeAhead$action = _api$typeAhead.actions) === null || _api$typeAhead$action === void 0 ? void 0 : _api$typeAhead$action.open({
59
+ triggerHandler: typeAhead,
60
+ inputMethod: INPUT_METHOD.INSERT_MENU
61
+ });
62
+ };
62
63
  return /*#__PURE__*/React.createElement(WithPluginState, {
63
64
  editorView: editorView,
64
65
  plugins: {
@@ -68,11 +69,30 @@ const mentionsPlugin = ({
68
69
  mentionState = {}
69
70
  }) => !mentionState.mentionProvider ? null : /*#__PURE__*/React.createElement(ToolbarMention, {
70
71
  editorView: editorView,
72
+ onInsertMention: openMentionTypeAhead,
71
73
  isDisabled: disabled || (api === null || api === void 0 ? void 0 : api.typeAhead.actions.isAllowed(editorView.state))
72
74
  })
73
75
  });
74
76
  },
75
- getSharedState,
77
+ actions: {
78
+ openTypeAhead(inputMethod) {
79
+ var _api$typeAhead2, _api$typeAhead2$actio;
80
+ return Boolean(api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.open({
81
+ triggerHandler: typeAhead,
82
+ inputMethod
83
+ }));
84
+ }
85
+ },
86
+ getSharedState(editorState) {
87
+ if (!editorState) {
88
+ return undefined;
89
+ }
90
+ const mentionPluginState = mentionPluginKey.getState(editorState);
91
+ return {
92
+ ...mentionPluginState,
93
+ typeAheadHandler: typeAhead
94
+ };
95
+ },
76
96
  pluginsOptions: {
77
97
  quickInsert: ({
78
98
  formatMessage
@@ -85,26 +105,14 @@ const mentionsPlugin = ({
85
105
  keyshortcut: '@',
86
106
  icon: () => /*#__PURE__*/React.createElement(IconMention, null),
87
107
  action(insert, state) {
88
- var _api$analytics2;
89
108
  const tr = insert(undefined);
90
- const pluginState = getSharedState(state);
109
+ const pluginState = mentionPluginKey.getState(state);
91
110
  if (pluginState && pluginState.canInsertMention === false) {
92
111
  return false;
93
112
  }
94
- api === null || api === void 0 ? void 0 : api.typeAhead.commands.openTypeAheadAtCursor({
113
+ api === null || api === void 0 ? void 0 : api.typeAhead.actions.openAtTransaction({
95
114
  triggerHandler: typeAhead,
96
115
  inputMethod: INPUT_METHOD.QUICK_INSERT
97
- })({
98
- tr
99
- });
100
- api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.attachAnalyticsEvent({
101
- action: ACTION.INVOKED,
102
- actionSubject: ACTION_SUBJECT.TYPEAHEAD,
103
- actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_MENTION,
104
- attributes: {
105
- inputMethod: INPUT_METHOD.QUICK_INSERT
106
- },
107
- eventType: EVENT_TYPE.UI
108
116
  })(tr);
109
117
  return tr;
110
118
  }
@@ -1,10 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React from 'react';
3
- import { PureComponent } from 'react';
2
+ import React, { PureComponent } from 'react';
4
3
  import MentionIcon from '@atlaskit/icon/glyph/editor/mention';
5
4
  import { ToolbarButton, TOOLBAR_BUTTON } from '@atlaskit/editor-common/ui-menu';
6
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
- import { createTypeAheadTools } from '../../../type-ahead/api';
8
5
  import { injectIntl } from 'react-intl-next';
9
6
  import { messages } from '../../messages';
10
7
  class ToolbarMention extends PureComponent {
@@ -14,7 +11,7 @@ class ToolbarMention extends PureComponent {
14
11
  if (!this.props.editorView) {
15
12
  return false;
16
13
  }
17
- createTypeAheadTools(this.props.editorView).openMention(INPUT_METHOD.INSERT_MENU);
14
+ this.props.onInsertMention();
18
15
  return true;
19
16
  });
20
17
  }
@@ -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
- const getOpenTypeAhead = (view, content) => {
18
- const typeAheadAPI = createInternalTypeAheadTools(view);
19
- const typeAheadHandler = typeAheadAPI.findTypeAheadHandler(content);
16
+ const getOpenTypeAhead = (trigger, api) => {
17
+ var _api$typeAhead, _api$typeAhead$action, _api$typeAhead2, _api$typeAhead2$actio;
18
+ const typeAheadHandler = api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : (_api$typeAhead$action = _api$typeAhead.actions) === null || _api$typeAhead$action === void 0 ? void 0 : _api$typeAhead$action.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 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.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
  const allowInserting = !!options.allowInserting;
30
29
  return new SafePlugin({
31
30
  key: pluginKey,
@@ -106,7 +105,7 @@ export function createPlugin(dispatch, options) {
106
105
  const content = event.data || '';
107
106
  const tr = view.state.tr;
108
107
  tr.delete(startNodePosition, startNodePosition + 1);
109
- const openTypeAhead = getOpenTypeAhead(view, content);
108
+ const openTypeAhead = getOpenTypeAhead(content, api);
110
109
  if (openTypeAhead) {
111
110
  openTypeAhead(tr);
112
111
  } else {
@@ -125,6 +124,7 @@ export function createPlugin(dispatch, options) {
125
124
  });
126
125
  }
127
126
  const basePlaceholderTextPlugin = ({
127
+ api,
128
128
  config: options
129
129
  }) => ({
130
130
  name: 'placeholderText',
@@ -139,7 +139,7 @@ const basePlaceholderTextPlugin = ({
139
139
  name: 'placeholderText',
140
140
  plugin: ({
141
141
  dispatch
142
- }) => createPlugin(dispatch, options)
142
+ }) => createPlugin(dispatch, options, api)
143
143
  }];
144
144
  },
145
145
  contentComponent({
@@ -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';
@@ -176,33 +176,14 @@ const currentQuery = ({
176
176
  }) => () => {
177
177
  return getTypeAheadQuery(editorView.state);
178
178
  };
179
- const find = ({
180
- editorView
181
- }) => trigger => {
182
- const {
183
- state: editorState
184
- } = editorView;
185
- const handler = findHandlerByTrigger({
186
- trigger,
187
- editorState
188
- });
189
- if (!handler) {
190
- return null;
191
- }
192
- return handler;
193
- };
194
179
 
195
- // This is an internal tool to be used inside of others Editor Plugins
196
- // We shouldn't public export this method.
197
- export const createInternalTypeAheadTools = editorView => {
198
- const props = {
199
- editorView
200
- };
201
- return {
202
- findTypeAheadHandler: find(props),
203
- openTypeAheadHandler: openTypeAhead
204
- };
205
- };
180
+ /**
181
+ * Please do not use it. Ping #help-editor and talk to the Lego team before use it.
182
+ *
183
+ * @private
184
+ * @deprecated
185
+ *
186
+ */
206
187
  export const createTypeAheadTools = editorView => {
207
188
  const props = {
208
189
  editorView
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import React from 'react';
10
10
  import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
11
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
12
  import { createPlugin } from './pm-plugins/main';
12
13
  import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
13
14
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
@@ -15,12 +16,14 @@ import { typeAheadQuery } from '@atlaskit/adf-schema';
15
16
  import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
16
17
  import { inputRulePlugin } from './pm-plugins/input-rules';
17
18
  import { TypeAheadPopup } from './ui/TypeAheadPopup';
18
- import { getPluginState, isTypeAheadOpen, isTypeAheadAllowed } from './utils';
19
+ import { findHandler, getPluginState, isTypeAheadOpen, isTypeAheadAllowed, getTypeAheadQuery, getTypeAheadHandler } from './utils';
19
20
  import { useItemInsert } from './ui/hooks/use-item-insert';
20
21
  import { updateSelectedIndex } from './commands/update-selected-index';
21
22
  import { StatsModifier } from './stats-modifier';
22
23
  import { ACTION, ACTION_SUBJECT, INPUT_METHOD, EVENT_TYPE, fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
23
24
  import { openTypeAheadAtCursor } from './transforms/open-typeahead-at-cursor';
25
+ import { closeTypeAhead } from './transforms/close-type-ahead';
26
+ import { insertTypeAheadItem } from './commands/insert-type-ahead-item';
24
27
  const TypeAheadMenu = /*#__PURE__*/React.memo(({
25
28
  editorView,
26
29
  popupMountRef,
@@ -102,6 +105,107 @@ const TypeAheadMenu = /*#__PURE__*/React.memo(({
102
105
  cancel: cancel
103
106
  });
104
107
  });
108
+ const createOpenAtTransaction = editorAnalyticsAPI => props => tr => {
109
+ const {
110
+ triggerHandler,
111
+ inputMethod
112
+ } = props;
113
+ openTypeAheadAtCursor({
114
+ triggerHandler,
115
+ inputMethod
116
+ })({
117
+ tr
118
+ });
119
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
120
+ action: ACTION.INVOKED,
121
+ actionSubject: ACTION_SUBJECT.TYPEAHEAD,
122
+ actionSubjectId: triggerHandler.id,
123
+ attributes: {
124
+ inputMethod
125
+ },
126
+ eventType: EVENT_TYPE.UI
127
+ })(tr);
128
+ return true;
129
+ };
130
+ const createOpenTypeAhead = (editorViewRef, editorAnalyticsAPI) => props => {
131
+ if (!editorViewRef.current) {
132
+ return false;
133
+ }
134
+ const {
135
+ current: view
136
+ } = editorViewRef;
137
+ const {
138
+ tr
139
+ } = view.state;
140
+ createOpenAtTransaction(editorAnalyticsAPI)(props)(tr);
141
+ view.dispatch(tr);
142
+ return true;
143
+ };
144
+ const createInsertTypeAheadItem = editorViewRef => props => {
145
+ if (!editorViewRef.current) {
146
+ return false;
147
+ }
148
+ const {
149
+ current: view
150
+ } = editorViewRef;
151
+ const {
152
+ triggerHandler,
153
+ contentItem,
154
+ query,
155
+ sourceListItem,
156
+ mode
157
+ } = props;
158
+ insertTypeAheadItem(view)({
159
+ handler: triggerHandler,
160
+ item: contentItem,
161
+ mode: mode || SelectItemMode.SELECTED,
162
+ query,
163
+ sourceListItem
164
+ });
165
+ return true;
166
+ };
167
+ const createFindHandlerByTrigger = editorViewRef => trigger => {
168
+ if (!editorViewRef.current) {
169
+ return null;
170
+ }
171
+ const {
172
+ current: view
173
+ } = editorViewRef;
174
+ return findHandler(trigger, view.state);
175
+ };
176
+ const createCloseTypeAhead = editorViewRef => options => {
177
+ if (!editorViewRef.current) {
178
+ return false;
179
+ }
180
+ const {
181
+ current: view
182
+ } = editorViewRef;
183
+ const currentQuery = getTypeAheadQuery(view.state) || '';
184
+ const {
185
+ state
186
+ } = view;
187
+ let tr = state.tr;
188
+ if (options.attachCommand) {
189
+ const fakeDispatch = customTr => {
190
+ tr = customTr;
191
+ };
192
+ options.attachCommand(state, fakeDispatch);
193
+ }
194
+ closeTypeAhead(tr);
195
+ if (options.insertCurrentQueryAsRawText && currentQuery && currentQuery.length > 0) {
196
+ const handler = getTypeAheadHandler(state);
197
+ if (!handler) {
198
+ return false;
199
+ }
200
+ const text = handler.trigger.concat(currentQuery);
201
+ tr.replaceSelectionWith(state.schema.text(text));
202
+ }
203
+ view.dispatch(tr);
204
+ if (!view.hasFocus()) {
205
+ view.focus();
206
+ }
207
+ return true;
208
+ };
105
209
 
106
210
  /**
107
211
  *
@@ -112,12 +216,17 @@ const TypeAheadMenu = /*#__PURE__*/React.memo(({
112
216
  *
113
217
  */
114
218
  const typeAheadPlugin = ({
115
- config: options
219
+ config: options,
220
+ api
116
221
  }) => {
222
+ var _api$analytics, _api$analytics2;
117
223
  const fireAnalyticsCallback = fireAnalyticsEvent(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
118
224
  const popupMountRef = {
119
225
  current: null
120
226
  };
227
+ const editorViewRef = {
228
+ current: null
229
+ };
121
230
  return {
122
231
  name: 'typeAhead',
123
232
  marks() {
@@ -141,6 +250,20 @@ const typeAheadPlugin = ({
141
250
  typeAheadHandlers: typeAhead,
142
251
  createAnalyticsEvent: options === null || options === void 0 ? void 0 : options.createAnalyticsEvent
143
252
  })
253
+ }, {
254
+ name: 'typeAheadEditorViewRef',
255
+ plugin: () => {
256
+ return new SafePlugin({
257
+ view(view) {
258
+ editorViewRef.current = view;
259
+ return {
260
+ destroy() {
261
+ editorViewRef.current = null;
262
+ }
263
+ };
264
+ }
265
+ });
266
+ }
144
267
  }, {
145
268
  name: 'typeAheadInsertItem',
146
269
  plugin: createInsertItemPlugin
@@ -152,12 +275,24 @@ const typeAheadPlugin = ({
152
275
  }) => inputRulePlugin(schema, typeAhead, featureFlags)
153
276
  }];
154
277
  },
155
- commands: {
156
- openTypeAheadAtCursor
278
+ getSharedState(editorState) {
279
+ if (!editorState) {
280
+ return {
281
+ query: ''
282
+ };
283
+ }
284
+ return {
285
+ query: getTypeAheadQuery(editorState) || ''
286
+ };
157
287
  },
158
288
  actions: {
159
289
  isOpen: isTypeAheadOpen,
160
- isAllowed: isTypeAheadAllowed
290
+ isAllowed: isTypeAheadAllowed,
291
+ open: createOpenTypeAhead(editorViewRef, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
292
+ openAtTransaction: createOpenAtTransaction(api === null || api === void 0 ? 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)
161
296
  },
162
297
  contentComponent({
163
298
  editorView,
@@ -4,7 +4,9 @@ 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
- const undoRedoPlugin = () => ({
7
+ const undoRedoPlugin = ({
8
+ api
9
+ }) => ({
8
10
  name: 'undoRedoPlugin',
9
11
  pmPlugins() {
10
12
  return [{
@@ -31,7 +33,8 @@ const undoRedoPlugin = () => ({
31
33
  isReducedSpacing: isToolbarReducedSpacing,
32
34
  disabled: disabled,
33
35
  historyState: historyState,
34
- editorView: editorView
36
+ editorView: editorView,
37
+ api: api
35
38
  });
36
39
  }
37
40
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -8,16 +8,16 @@ import { undo as undoKeymap, redo as redoKeymap, ToolTipContent, tooltip } from
8
8
  import { separatorStyles, buttonGroupStyle } from '@atlaskit/editor-common/styles';
9
9
  import ToolbarButton, { TOOLBAR_BUTTON } from '../../../../ui/ToolbarButton';
10
10
  import { undoRedoMessages } from '@atlaskit/editor-common/messages';
11
- import { createTypeAheadTools } from '../../../type-ahead/api';
12
11
  import { undoFromToolbar, redoFromToolbar } from '../../commands';
13
12
  import { getAriaKeyshortcuts } from '@atlaskit/editor-common/keymaps';
14
- const closeTypeAheadAndRunCommand = editorView => command => {
13
+ const closeTypeAheadAndRunCommand = (editorView, api) => command => {
14
+ var _api$typeAhead, _api$typeAhead$action;
15
15
  if (!editorView) {
16
16
  return;
17
17
  }
18
- const tool = createTypeAheadTools(editorView);
19
- if (tool.isOpen()) {
20
- tool.close({
18
+ if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead$action = _api$typeAhead.actions) !== null && _api$typeAhead$action !== void 0 && _api$typeAhead$action.isOpen(editorView.state)) {
19
+ var _api$typeAhead2, _api$typeAhead2$actio;
20
+ api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.close({
21
21
  attachCommand: command,
22
22
  insertCurrentQueryAsRawText: false
23
23
  });
@@ -25,8 +25,8 @@ const closeTypeAheadAndRunCommand = editorView => command => {
25
25
  command(editorView.state, editorView.dispatch);
26
26
  }
27
27
  };
28
- const forceFocus = editorView => command => {
29
- closeTypeAheadAndRunCommand(editorView)(command);
28
+ const forceFocus = (editorView, api) => command => {
29
+ closeTypeAheadAndRunCommand(editorView, api)(command);
30
30
  if (!editorView.hasFocus()) {
31
31
  editorView.focus();
32
32
  }
@@ -38,15 +38,16 @@ export class ToolbarUndoRedo extends PureComponent {
38
38
  isReducedSpacing,
39
39
  historyState,
40
40
  editorView,
41
+ api,
41
42
  intl: {
42
43
  formatMessage
43
44
  }
44
45
  } = this.props;
45
46
  const handleUndo = () => {
46
- forceFocus(editorView)(undoFromToolbar);
47
+ forceFocus(editorView, api)(undoFromToolbar);
47
48
  };
48
49
  const handleRedo = () => {
49
- forceFocus(editorView)(redoFromToolbar);
50
+ forceFocus(editorView, api)(redoFromToolbar);
50
51
  };
51
52
  const labelUndo = formatMessage(undoRedoMessages.undo);
52
53
  const labelRedo = formatMessage(undoRedoMessages.redo);
@@ -4,7 +4,6 @@ import { createSchema } from './create-editor/create-schema';
4
4
  import { sortByOrder } from './create-editor/sort-by-order';
5
5
  import { analyticsPluginKey } from './plugins/analytics/plugin-key';
6
6
  import { basePlugin } from '@atlaskit/editor-plugin-base';
7
- export { createTypeAheadTools } from './plugins/type-ahead/api';
8
7
  export function getFireAnalytics(editorView) {
9
8
  var _analyticsPluginKey$g;
10
9
  return analyticsPluginKey === null || analyticsPluginKey === void 0 ? 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 const name = "@atlaskit/editor-core";
2
- export const version = "188.3.1";
2
+ export const version = "188.4.0";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -3,8 +3,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  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; }
4
4
  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; }
5
5
  import { createEditorSelectionAPI } from '../../../selection-api/api';
6
- import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, extensionPlugin, fragmentMarkPlugin, insertBlockPlugin, jiraIssuePlugin, layoutPlugin, toolbarListsIndentationPlugin, macroPlugin, maxContentSizePlugin, mentionsPlugin, panelPlugin, placeholderTextPlugin, saveOnEnterPlugin, tasksAndDecisionsPlugin, textColorPlugin, statusPlugin, alignmentPlugin, indentationPlugin, customAutoformatPlugin, feedbackDialogPlugin, historyPlugin, expandPlugin, isExpandInsertionEnabled, scrollIntoViewPlugin, mobileDimensionsPlugin, findReplacePlugin, mobileSelectionPlugin, annotationPlugin, avatarGroupPlugin, viewUpdateSubscriptionPlugin, beforePrimaryToolbarPlugin, codeBidiWarningPlugin, borderPlugin } from '../../../plugins';
6
+ import { breakoutPlugin, collabEditPlugin, dataConsumerMarkPlugin, datePlugin, extensionPlugin, fragmentMarkPlugin, insertBlockPlugin, jiraIssuePlugin, layoutPlugin, toolbarListsIndentationPlugin, macroPlugin, maxContentSizePlugin, mentionsPlugin, panelPlugin, placeholderTextPlugin, saveOnEnterPlugin, tasksAndDecisionsPlugin, textColorPlugin, statusPlugin, alignmentPlugin, indentationPlugin, customAutoformatPlugin, feedbackDialogPlugin, historyPlugin, expandPlugin, isExpandInsertionEnabled, scrollIntoViewPlugin, mobileDimensionsPlugin, findReplacePlugin, mobileSelectionPlugin, annotationPlugin, avatarGroupPlugin, viewUpdateSubscriptionPlugin, beforePrimaryToolbarPlugin, codeBidiWarningPlugin } from '../../../plugins';
7
7
  import { captionPlugin } from '@atlaskit/editor-plugin-caption';
8
+ import { borderPlugin } from '@atlaskit/editor-plugin-border';
8
9
  import { helpDialogPlugin } from '@atlaskit/editor-plugin-help-dialog';
9
10
  import { mediaPlugin } from '@atlaskit/editor-plugin-media';
10
11
  import { rulePlugin } from '@atlaskit/editor-plugin-rule';
@@ -41,5 +41,4 @@ export { default as undoRedoPlugin } from './undo-redo';
41
41
  export { default as avatarGroupPlugin } from './avatar-group';
42
42
  export { default as viewUpdateSubscriptionPlugin } from './view-update-subscription';
43
43
  export { default as beforePrimaryToolbarPlugin } from './before-primaryToolbar';
44
- export { default as codeBidiWarningPlugin } from './code-bidi-warning';
45
- export { default as borderPlugin } from './border';
44
+ export { default as codeBidiWarningPlugin } from './code-bidi-warning';
@@ -25,7 +25,6 @@ import { showPlaceholderFloatingToolbar } from '../../../placeholder-text/action
25
25
  import { insertLayoutColumnsWithAnalytics } from '../../../layout/actions';
26
26
  import { insertTaskDecisionCommand } from '../../../tasks-and-decisions/commands';
27
27
  import { insertExpand } from '../../../expand/commands';
28
- import { createTypeAheadTools } from '../../../type-ahead/api';
29
28
  import { updateStatusWithAnalytics } from '../../../status/actions';
30
29
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
31
30
  import { messages } from './messages';
@@ -169,7 +168,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
169
168
  return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$h = pluginInjectionApi.hyperlink) === null || _pluginInjectionApi$h === void 0 ? void 0 : _pluginInjectionApi$h.commands.showLinkToolbar(inputMethod))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
170
169
  });
171
170
  _defineProperty(_assertThisInitialized(_this), "insertMention", function (inputMethod) {
172
- var _pluginInjectionApi$m;
171
+ var _pluginInjectionApi$m, _pluginInjectionApi$m2;
173
172
  var _this$props = _this.props,
174
173
  editorView = _this$props.editorView,
175
174
  pluginInjectionApi = _this$props.pluginInjectionApi;
@@ -180,8 +179,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
180
179
  if (pluginState && pluginState.canInsertMention === false) {
181
180
  return false;
182
181
  }
183
- createTypeAheadTools(editorView).openMention(inputMethod);
184
- return true;
182
+ return Boolean(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$m2 = pluginInjectionApi.mention) === null || _pluginInjectionApi$m2 === void 0 || (_pluginInjectionApi$m2 = _pluginInjectionApi$m2.actions) === null || _pluginInjectionApi$m2 === void 0 ? void 0 : _pluginInjectionApi$m2.openTypeAhead(inputMethod));
185
183
  });
186
184
  _defineProperty(_assertThisInitialized(_this), "insertTable", function (inputMethod) {
187
185
  var _pluginInjectionApi$t, _pluginInjectionApi$t2, _pluginInjectionApi$t3, _pluginInjectionApi$t4;