@atlaskit/editor-core 188.7.6 → 188.8.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 (27) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/plugins/type-ahead/index.js +4 -372
  3. package/dist/cjs/plugins/type-ahead/plugin.js +382 -0
  4. package/dist/cjs/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +17 -8
  5. package/dist/cjs/version-wrapper.js +1 -1
  6. package/dist/es2019/plugins/type-ahead/index.js +2 -375
  7. package/dist/es2019/plugins/type-ahead/plugin.js +381 -0
  8. package/dist/es2019/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +17 -8
  9. package/dist/es2019/version-wrapper.js +1 -1
  10. package/dist/esm/plugins/type-ahead/index.js +2 -368
  11. package/dist/esm/plugins/type-ahead/plugin.js +374 -0
  12. package/dist/esm/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +17 -8
  13. package/dist/esm/version-wrapper.js +1 -1
  14. package/dist/types/labs/next/presets/default.d.ts +30 -12
  15. package/dist/types/plugins/type-ahead/index.d.ts +3 -14
  16. package/dist/types/plugins/type-ahead/plugin.d.ts +10 -0
  17. package/dist/types/plugins/type-ahead/types.d.ts +51 -6
  18. package/dist/types-ts4.5/labs/next/presets/default.d.ts +30 -12
  19. package/dist/types-ts4.5/plugins/type-ahead/index.d.ts +3 -14
  20. package/dist/types-ts4.5/plugins/type-ahead/plugin.d.ts +10 -0
  21. package/dist/types-ts4.5/plugins/type-ahead/types.d.ts +53 -6
  22. package/package.json +2 -2
  23. package/dist/cjs/plugins/view-update-subscription/subscribe/type-ahead-updates.js +0 -33
  24. package/dist/es2019/plugins/view-update-subscription/subscribe/type-ahead-updates.js +0 -28
  25. package/dist/esm/plugins/view-update-subscription/subscribe/type-ahead-updates.js +0 -27
  26. package/dist/types/plugins/view-update-subscription/subscribe/type-ahead-updates.d.ts +0 -9
  27. package/dist/types-ts4.5/plugins/view-update-subscription/subscribe/type-ahead-updates.d.ts +0 -9
@@ -1,369 +1,3 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- /**
3
- *
4
- * Revamped typeahead using decorations instead of the `typeAheadQuery` mark
5
- *
6
- * https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
7
- *
8
- *
9
- */
10
- import React from 'react';
11
- import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
12
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
13
- import { createPlugin } from './pm-plugins/main';
14
- import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
15
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
16
- import { typeAheadQuery } from '@atlaskit/adf-schema';
17
- import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
18
- import { inputRulePlugin } from './pm-plugins/input-rules';
19
- import { TypeAheadPopup } from './ui/TypeAheadPopup';
20
- import { findHandler, getPluginState, isTypeAheadOpen, isTypeAheadAllowed, getTypeAheadQuery, getTypeAheadHandler } from './utils';
21
- import { useItemInsert } from './ui/hooks/use-item-insert';
22
- import { updateSelectedIndex } from './commands/update-selected-index';
23
- import { StatsModifier } from './stats-modifier';
24
- import { ACTION, ACTION_SUBJECT, INPUT_METHOD, EVENT_TYPE, fireAnalyticsEvent } from '@atlaskit/editor-common/analytics';
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';
28
- var TypeAheadMenu = /*#__PURE__*/React.memo(function (_ref) {
29
- var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
30
- var editorView = _ref.editorView,
31
- popupMountRef = _ref.popupMountRef,
32
- typeAheadState = _ref.typeAheadState,
33
- fireAnalyticsCallback = _ref.fireAnalyticsCallback;
34
- var isOpen = typeAheadState.decorationSet.find().length > 0;
35
- var triggerHandler = typeAheadState.triggerHandler,
36
- items = typeAheadState.items,
37
- selectedIndex = typeAheadState.selectedIndex,
38
- decorationElement = typeAheadState.decorationElement,
39
- decorationSet = typeAheadState.decorationSet,
40
- query = typeAheadState.query;
41
- var _useItemInsert = useItemInsert(triggerHandler, editorView, items),
42
- _useItemInsert2 = _slicedToArray(_useItemInsert, 3),
43
- onItemInsert = _useItemInsert2[0],
44
- onTextInsert = _useItemInsert2[1],
45
- onItemMatch = _useItemInsert2[2];
46
- var setSelectedItem = React.useCallback(function (_ref2) {
47
- var nextIndex = _ref2.index;
48
- queueMicrotask(function () {
49
- updateSelectedIndex(nextIndex)(editorView.state, editorView.dispatch);
50
- });
51
- }, [editorView]);
52
- var insertItem = React.useCallback(function () {
53
- var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SelectItemMode.SELECTED;
54
- var index = arguments.length > 1 ? arguments[1] : undefined;
55
- queueMicrotask(function () {
56
- onItemInsert({
57
- mode: mode,
58
- index: index,
59
- query: query
60
- });
61
- });
62
- }, [onItemInsert, query]);
63
- var cancel = React.useCallback(function (_ref3) {
64
- var setSelectionAt = _ref3.setSelectionAt,
65
- addPrefixTrigger = _ref3.addPrefixTrigger,
66
- forceFocusOnEditor = _ref3.forceFocusOnEditor;
67
- var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
68
- onTextInsert({
69
- forceFocusOnEditor: forceFocusOnEditor,
70
- setSelectionAt: setSelectionAt,
71
- text: fullQuery
72
- });
73
- }, [triggerHandler, onTextInsert, query]);
74
- React.useEffect(function () {
75
- if (!isOpen || !query) {
76
- return;
77
- }
78
- var isLastCharSpace = query[query.length - 1] === ' ';
79
- if (!isLastCharSpace) {
80
- return;
81
- }
82
- var result = onItemMatch({
83
- mode: SelectItemMode.SPACE,
84
- query: query.trim()
85
- });
86
- if (!result) {
87
- return;
88
- }
89
- }, [isOpen, query, onItemMatch]);
90
- if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
91
- return null;
92
- }
93
- return /*#__PURE__*/React.createElement(TypeAheadPopup, {
94
- editorView: editorView,
95
- popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
96
- popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
97
- popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
98
- anchorElement: decorationElement,
99
- triggerHandler: triggerHandler,
100
- fireAnalyticsCallback: fireAnalyticsCallback,
101
- items: items,
102
- selectedIndex: selectedIndex,
103
- setSelectedItem: setSelectedItem,
104
- onItemInsert: insertItem,
105
- decorationSet: decorationSet,
106
- isEmptyQuery: !query,
107
- cancel: cancel
108
- });
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
- };
207
-
208
- /**
209
- *
210
- * Revamped typeahead using decorations instead of the `typeAheadQuery` mark
211
- *
212
- * https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
213
- *
214
- *
215
- */
216
- var typeAheadPlugin = function typeAheadPlugin(_ref4) {
217
- var _api$analytics, _api$analytics2;
218
- var options = _ref4.config,
219
- api = _ref4.api;
220
- var fireAnalyticsCallback = fireAnalyticsEvent(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
221
- var popupMountRef = {
222
- current: null
223
- };
224
- var editorViewRef = {
225
- current: null
226
- };
227
- return {
228
- name: 'typeAhead',
229
- marks: function marks() {
230
- // We need to keep this to make sure
231
- // All documents with typeahead marks will be loaded normally
232
- return [{
233
- name: 'typeAheadQuery',
234
- mark: typeAheadQuery
235
- }];
236
- },
237
- pmPlugins: function pmPlugins() {
238
- var typeAhead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
239
- return [{
240
- name: 'typeAhead',
241
- plugin: function plugin(_ref5) {
242
- var dispatch = _ref5.dispatch,
243
- getIntl = _ref5.getIntl;
244
- return createPlugin({
245
- getIntl: getIntl,
246
- popupMountRef: popupMountRef,
247
- reactDispatch: dispatch,
248
- typeAheadHandlers: typeAhead,
249
- createAnalyticsEvent: options === null || options === void 0 ? void 0 : options.createAnalyticsEvent
250
- });
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
- }
266
- }, {
267
- name: 'typeAheadInsertItem',
268
- plugin: createInsertItemPlugin
269
- }, {
270
- name: 'typeAheadInputRule',
271
- plugin: function plugin(_ref6) {
272
- var schema = _ref6.schema,
273
- featureFlags = _ref6.featureFlags;
274
- return inputRulePlugin(schema, typeAhead, featureFlags);
275
- }
276
- }];
277
- },
278
- getSharedState: function getSharedState(editorState) {
279
- if (!editorState) {
280
- return {
281
- query: ''
282
- };
283
- }
284
- return {
285
- query: getTypeAheadQuery(editorState) || ''
286
- };
287
- },
288
- actions: {
289
- isOpen: isTypeAheadOpen,
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)
296
- },
297
- contentComponent: function contentComponent(_ref7) {
298
- var editorView = _ref7.editorView,
299
- containerElement = _ref7.containerElement,
300
- popupsMountPoint = _ref7.popupsMountPoint,
301
- popupsBoundariesElement = _ref7.popupsBoundariesElement,
302
- popupsScrollableElement = _ref7.popupsScrollableElement,
303
- wrapperElement = _ref7.wrapperElement;
304
- popupMountRef.current = {
305
- popupsMountPoint: popupsMountPoint || wrapperElement || undefined,
306
- popupsBoundariesElement: popupsBoundariesElement,
307
- popupsScrollableElement: popupsScrollableElement || containerElement || undefined
308
- };
309
- return /*#__PURE__*/React.createElement(WithPluginState, {
310
- plugins: {
311
- typeAheadState: typeAheadPluginKey
312
- },
313
- render: function render(_ref8) {
314
- var typeAheadState = _ref8.typeAheadState;
315
- if (!typeAheadState) {
316
- return null;
317
- }
318
- return /*#__PURE__*/React.createElement(TypeAheadMenu, {
319
- editorView: editorView,
320
- popupMountRef: popupMountRef,
321
- typeAheadState: typeAheadState,
322
- fireAnalyticsCallback: fireAnalyticsCallback
323
- });
324
- }
325
- });
326
- },
327
- onEditorViewStateUpdated: function onEditorViewStateUpdated(_ref9) {
328
- var originalTransaction = _ref9.originalTransaction,
329
- oldEditorState = _ref9.oldEditorState,
330
- newEditorState = _ref9.newEditorState;
331
- var oldPluginState = getPluginState(oldEditorState);
332
- var newPluginState = getPluginState(newEditorState);
333
- if (!oldPluginState || !newPluginState) {
334
- return;
335
- }
336
- var oldTriggerHandler = oldPluginState.triggerHandler;
337
- var newTriggerHandler = newPluginState.triggerHandler;
338
- var isANewHandler = oldTriggerHandler !== newTriggerHandler;
339
- if (oldTriggerHandler !== null && oldTriggerHandler !== void 0 && oldTriggerHandler.dismiss && isANewHandler) {
340
- var typeAheadMessage = originalTransaction.getMeta(typeAheadPluginKey);
341
- var wasItemInserted = typeAheadMessage && typeAheadMessage.action === 'INSERT_RAW_QUERY';
342
- oldTriggerHandler.dismiss({
343
- editorState: newEditorState,
344
- query: oldPluginState.query,
345
- stats: (oldPluginState.stats || new StatsModifier()).serialize(),
346
- wasItemInserted: wasItemInserted
347
- });
348
- }
349
- if (newTriggerHandler !== null && newTriggerHandler !== void 0 && newTriggerHandler.onOpen && isANewHandler) {
350
- newTriggerHandler.onOpen(newEditorState);
351
- }
352
- if (newTriggerHandler && isANewHandler && options !== null && options !== void 0 && options.createAnalyticsEvent) {
353
- fireAnalyticsCallback({
354
- payload: {
355
- action: ACTION.INVOKED,
356
- actionSubject: ACTION_SUBJECT.TYPEAHEAD,
357
- actionSubjectId: newTriggerHandler.id || 'not_set',
358
- attributes: {
359
- inputMethod: newPluginState.inputMethod || INPUT_METHOD.KEYBOARD
360
- },
361
- eventType: EVENT_TYPE.UI
362
- }
363
- });
364
- }
365
- }
366
- };
367
- };
1
+ import { typeAheadPlugin } from './plugin';
368
2
  export default typeAheadPlugin;
369
- export { typeAheadPluginKey };
3
+ export { typeAheadPlugin };