@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 188.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#41459](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41459) [`9874d0f70b0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9874d0f70b0) - [ED-20003] TypeAhead extraction: Replace the mobile view-subscription with proper API
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 188.7.6
4
14
 
5
15
  ### Patch Changes
@@ -1,382 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
- Object.defineProperty(exports, "typeAheadPluginKey", {
7
+ Object.defineProperty(exports, "typeAheadPlugin", {
9
8
  enumerable: true,
10
9
  get: function get() {
11
- return _key.pluginKey;
10
+ return _plugin.typeAheadPlugin;
12
11
  }
13
12
  });
14
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
- var _react = _interopRequireDefault(require("react"));
16
- var _typeAhead = require("@atlaskit/editor-common/type-ahead");
17
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
18
- var _main = require("./pm-plugins/main");
19
- var _insertItemPlugin = require("./pm-plugins/insert-item-plugin");
20
- var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
21
- var _adfSchema = require("@atlaskit/adf-schema");
22
- var _key = require("./pm-plugins/key");
23
- var _inputRules = require("./pm-plugins/input-rules");
24
- var _TypeAheadPopup = require("./ui/TypeAheadPopup");
25
- var _utils = require("./utils");
26
- var _useItemInsert3 = require("./ui/hooks/use-item-insert");
27
- var _updateSelectedIndex = require("./commands/update-selected-index");
28
- var _statsModifier = require("./stats-modifier");
29
- var _analytics = require("@atlaskit/editor-common/analytics");
30
- var _openTypeaheadAtCursor = require("./transforms/open-typeahead-at-cursor");
31
- var _closeTypeAhead = require("./transforms/close-type-ahead");
32
- var _insertTypeAheadItem = require("./commands/insert-type-ahead-item");
33
- /**
34
- *
35
- * Revamped typeahead using decorations instead of the `typeAheadQuery` mark
36
- *
37
- * https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
38
- *
39
- *
40
- */
41
-
42
- var TypeAheadMenu = /*#__PURE__*/_react.default.memo(function (_ref) {
43
- var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
44
- var editorView = _ref.editorView,
45
- popupMountRef = _ref.popupMountRef,
46
- typeAheadState = _ref.typeAheadState,
47
- fireAnalyticsCallback = _ref.fireAnalyticsCallback;
48
- var isOpen = typeAheadState.decorationSet.find().length > 0;
49
- var triggerHandler = typeAheadState.triggerHandler,
50
- items = typeAheadState.items,
51
- selectedIndex = typeAheadState.selectedIndex,
52
- decorationElement = typeAheadState.decorationElement,
53
- decorationSet = typeAheadState.decorationSet,
54
- query = typeAheadState.query;
55
- var _useItemInsert = (0, _useItemInsert3.useItemInsert)(triggerHandler, editorView, items),
56
- _useItemInsert2 = (0, _slicedToArray2.default)(_useItemInsert, 3),
57
- onItemInsert = _useItemInsert2[0],
58
- onTextInsert = _useItemInsert2[1],
59
- onItemMatch = _useItemInsert2[2];
60
- var setSelectedItem = _react.default.useCallback(function (_ref2) {
61
- var nextIndex = _ref2.index;
62
- queueMicrotask(function () {
63
- (0, _updateSelectedIndex.updateSelectedIndex)(nextIndex)(editorView.state, editorView.dispatch);
64
- });
65
- }, [editorView]);
66
- var insertItem = _react.default.useCallback(function () {
67
- var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _typeAhead.SelectItemMode.SELECTED;
68
- var index = arguments.length > 1 ? arguments[1] : undefined;
69
- queueMicrotask(function () {
70
- onItemInsert({
71
- mode: mode,
72
- index: index,
73
- query: query
74
- });
75
- });
76
- }, [onItemInsert, query]);
77
- var cancel = _react.default.useCallback(function (_ref3) {
78
- var setSelectionAt = _ref3.setSelectionAt,
79
- addPrefixTrigger = _ref3.addPrefixTrigger,
80
- forceFocusOnEditor = _ref3.forceFocusOnEditor;
81
- var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
82
- onTextInsert({
83
- forceFocusOnEditor: forceFocusOnEditor,
84
- setSelectionAt: setSelectionAt,
85
- text: fullQuery
86
- });
87
- }, [triggerHandler, onTextInsert, query]);
88
- _react.default.useEffect(function () {
89
- if (!isOpen || !query) {
90
- return;
91
- }
92
- var isLastCharSpace = query[query.length - 1] === ' ';
93
- if (!isLastCharSpace) {
94
- return;
95
- }
96
- var result = onItemMatch({
97
- mode: _typeAhead.SelectItemMode.SPACE,
98
- query: query.trim()
99
- });
100
- if (!result) {
101
- return;
102
- }
103
- }, [isOpen, query, onItemMatch]);
104
- if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
105
- return null;
106
- }
107
- return /*#__PURE__*/_react.default.createElement(_TypeAheadPopup.TypeAheadPopup, {
108
- editorView: editorView,
109
- popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
110
- popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
111
- popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
112
- anchorElement: decorationElement,
113
- triggerHandler: triggerHandler,
114
- fireAnalyticsCallback: fireAnalyticsCallback,
115
- items: items,
116
- selectedIndex: selectedIndex,
117
- setSelectedItem: setSelectedItem,
118
- onItemInsert: insertItem,
119
- decorationSet: decorationSet,
120
- isEmptyQuery: !query,
121
- cancel: cancel
122
- });
123
- });
124
- var createOpenAtTransaction = function createOpenAtTransaction(editorAnalyticsAPI) {
125
- return function (props) {
126
- return function (tr) {
127
- var triggerHandler = props.triggerHandler,
128
- inputMethod = props.inputMethod;
129
- (0, _openTypeaheadAtCursor.openTypeAheadAtCursor)({
130
- triggerHandler: triggerHandler,
131
- inputMethod: inputMethod
132
- })({
133
- tr: tr
134
- });
135
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
136
- action: _analytics.ACTION.INVOKED,
137
- actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
138
- actionSubjectId: triggerHandler.id,
139
- attributes: {
140
- inputMethod: inputMethod
141
- },
142
- eventType: _analytics.EVENT_TYPE.UI
143
- })(tr);
144
- return true;
145
- };
146
- };
147
- };
148
- var createOpenTypeAhead = function createOpenTypeAhead(editorViewRef, editorAnalyticsAPI) {
149
- return function (props) {
150
- if (!editorViewRef.current) {
151
- return false;
152
- }
153
- var view = editorViewRef.current;
154
- var tr = view.state.tr;
155
- createOpenAtTransaction(editorAnalyticsAPI)(props)(tr);
156
- view.dispatch(tr);
157
- return true;
158
- };
159
- };
160
- var createInsertTypeAheadItem = function createInsertTypeAheadItem(editorViewRef) {
161
- return function (props) {
162
- if (!editorViewRef.current) {
163
- return false;
164
- }
165
- var view = editorViewRef.current;
166
- var triggerHandler = props.triggerHandler,
167
- contentItem = props.contentItem,
168
- query = props.query,
169
- sourceListItem = props.sourceListItem,
170
- mode = props.mode;
171
- (0, _insertTypeAheadItem.insertTypeAheadItem)(view)({
172
- handler: triggerHandler,
173
- item: contentItem,
174
- mode: mode || _typeAhead.SelectItemMode.SELECTED,
175
- query: query,
176
- sourceListItem: sourceListItem
177
- });
178
- return true;
179
- };
180
- };
181
- var createFindHandlerByTrigger = function createFindHandlerByTrigger(editorViewRef) {
182
- return function (trigger) {
183
- if (!editorViewRef.current) {
184
- return null;
185
- }
186
- var view = editorViewRef.current;
187
- return (0, _utils.findHandler)(trigger, view.state);
188
- };
189
- };
190
- var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
191
- return function (options) {
192
- if (!editorViewRef.current) {
193
- return false;
194
- }
195
- var view = editorViewRef.current;
196
- var currentQuery = (0, _utils.getTypeAheadQuery)(view.state) || '';
197
- var state = view.state;
198
- var tr = state.tr;
199
- if (options.attachCommand) {
200
- var fakeDispatch = function fakeDispatch(customTr) {
201
- tr = customTr;
202
- };
203
- options.attachCommand(state, fakeDispatch);
204
- }
205
- (0, _closeTypeAhead.closeTypeAhead)(tr);
206
- if (options.insertCurrentQueryAsRawText && currentQuery && currentQuery.length > 0) {
207
- var handler = (0, _utils.getTypeAheadHandler)(state);
208
- if (!handler) {
209
- return false;
210
- }
211
- var text = handler.trigger.concat(currentQuery);
212
- tr.replaceSelectionWith(state.schema.text(text));
213
- }
214
- view.dispatch(tr);
215
- if (!view.hasFocus()) {
216
- view.focus();
217
- }
218
- return true;
219
- };
220
- };
221
-
222
- /**
223
- *
224
- * Revamped typeahead using decorations instead of the `typeAheadQuery` mark
225
- *
226
- * https://product-fabric.atlassian.net/wiki/spaces/E/pages/2992177582/Technical+TypeAhead+Data+Flow
227
- *
228
- *
229
- */
230
- var typeAheadPlugin = function typeAheadPlugin(_ref4) {
231
- var _api$analytics, _api$analytics2;
232
- var options = _ref4.config,
233
- api = _ref4.api;
234
- var fireAnalyticsCallback = (0, _analytics.fireAnalyticsEvent)(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
235
- var popupMountRef = {
236
- current: null
237
- };
238
- var editorViewRef = {
239
- current: null
240
- };
241
- return {
242
- name: 'typeAhead',
243
- marks: function marks() {
244
- // We need to keep this to make sure
245
- // All documents with typeahead marks will be loaded normally
246
- return [{
247
- name: 'typeAheadQuery',
248
- mark: _adfSchema.typeAheadQuery
249
- }];
250
- },
251
- pmPlugins: function pmPlugins() {
252
- var typeAhead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
253
- return [{
254
- name: 'typeAhead',
255
- plugin: function plugin(_ref5) {
256
- var dispatch = _ref5.dispatch,
257
- getIntl = _ref5.getIntl;
258
- return (0, _main.createPlugin)({
259
- getIntl: getIntl,
260
- popupMountRef: popupMountRef,
261
- reactDispatch: dispatch,
262
- typeAheadHandlers: typeAhead,
263
- createAnalyticsEvent: options === null || options === void 0 ? void 0 : options.createAnalyticsEvent
264
- });
265
- }
266
- }, {
267
- name: 'typeAheadEditorViewRef',
268
- plugin: function plugin() {
269
- return new _safePlugin.SafePlugin({
270
- view: function view(_view) {
271
- editorViewRef.current = _view;
272
- return {
273
- destroy: function destroy() {
274
- editorViewRef.current = null;
275
- }
276
- };
277
- }
278
- });
279
- }
280
- }, {
281
- name: 'typeAheadInsertItem',
282
- plugin: _insertItemPlugin.createPlugin
283
- }, {
284
- name: 'typeAheadInputRule',
285
- plugin: function plugin(_ref6) {
286
- var schema = _ref6.schema,
287
- featureFlags = _ref6.featureFlags;
288
- return (0, _inputRules.inputRulePlugin)(schema, typeAhead, featureFlags);
289
- }
290
- }];
291
- },
292
- getSharedState: function getSharedState(editorState) {
293
- if (!editorState) {
294
- return {
295
- query: ''
296
- };
297
- }
298
- return {
299
- query: (0, _utils.getTypeAheadQuery)(editorState) || ''
300
- };
301
- },
302
- actions: {
303
- isOpen: _utils.isTypeAheadOpen,
304
- isAllowed: _utils.isTypeAheadAllowed,
305
- open: createOpenTypeAhead(editorViewRef, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
306
- openAtTransaction: createOpenAtTransaction(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
307
- findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
308
- insert: createInsertTypeAheadItem(editorViewRef),
309
- close: createCloseTypeAhead(editorViewRef)
310
- },
311
- contentComponent: function contentComponent(_ref7) {
312
- var editorView = _ref7.editorView,
313
- containerElement = _ref7.containerElement,
314
- popupsMountPoint = _ref7.popupsMountPoint,
315
- popupsBoundariesElement = _ref7.popupsBoundariesElement,
316
- popupsScrollableElement = _ref7.popupsScrollableElement,
317
- wrapperElement = _ref7.wrapperElement;
318
- popupMountRef.current = {
319
- popupsMountPoint: popupsMountPoint || wrapperElement || undefined,
320
- popupsBoundariesElement: popupsBoundariesElement,
321
- popupsScrollableElement: popupsScrollableElement || containerElement || undefined
322
- };
323
- return /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
324
- plugins: {
325
- typeAheadState: _key.pluginKey
326
- },
327
- render: function render(_ref8) {
328
- var typeAheadState = _ref8.typeAheadState;
329
- if (!typeAheadState) {
330
- return null;
331
- }
332
- return /*#__PURE__*/_react.default.createElement(TypeAheadMenu, {
333
- editorView: editorView,
334
- popupMountRef: popupMountRef,
335
- typeAheadState: typeAheadState,
336
- fireAnalyticsCallback: fireAnalyticsCallback
337
- });
338
- }
339
- });
340
- },
341
- onEditorViewStateUpdated: function onEditorViewStateUpdated(_ref9) {
342
- var originalTransaction = _ref9.originalTransaction,
343
- oldEditorState = _ref9.oldEditorState,
344
- newEditorState = _ref9.newEditorState;
345
- var oldPluginState = (0, _utils.getPluginState)(oldEditorState);
346
- var newPluginState = (0, _utils.getPluginState)(newEditorState);
347
- if (!oldPluginState || !newPluginState) {
348
- return;
349
- }
350
- var oldTriggerHandler = oldPluginState.triggerHandler;
351
- var newTriggerHandler = newPluginState.triggerHandler;
352
- var isANewHandler = oldTriggerHandler !== newTriggerHandler;
353
- if (oldTriggerHandler !== null && oldTriggerHandler !== void 0 && oldTriggerHandler.dismiss && isANewHandler) {
354
- var typeAheadMessage = originalTransaction.getMeta(_key.pluginKey);
355
- var wasItemInserted = typeAheadMessage && typeAheadMessage.action === 'INSERT_RAW_QUERY';
356
- oldTriggerHandler.dismiss({
357
- editorState: newEditorState,
358
- query: oldPluginState.query,
359
- stats: (oldPluginState.stats || new _statsModifier.StatsModifier()).serialize(),
360
- wasItemInserted: wasItemInserted
361
- });
362
- }
363
- if (newTriggerHandler !== null && newTriggerHandler !== void 0 && newTriggerHandler.onOpen && isANewHandler) {
364
- newTriggerHandler.onOpen(newEditorState);
365
- }
366
- if (newTriggerHandler && isANewHandler && options !== null && options !== void 0 && options.createAnalyticsEvent) {
367
- fireAnalyticsCallback({
368
- payload: {
369
- action: _analytics.ACTION.INVOKED,
370
- actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
371
- actionSubjectId: newTriggerHandler.id || 'not_set',
372
- attributes: {
373
- inputMethod: newPluginState.inputMethod || _analytics.INPUT_METHOD.KEYBOARD
374
- },
375
- eventType: _analytics.EVENT_TYPE.UI
376
- }
377
- });
378
- }
379
- }
380
- };
381
- };
382
- var _default = exports.default = typeAheadPlugin;
13
+ var _plugin = require("./plugin");
14
+ var _default = exports.default = _plugin.typeAheadPlugin;