@atlaskit/editor-plugin-type-ahead 0.9.0 → 0.9.2
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.
- package/.eslintrc.js +13 -0
- package/CHANGELOG.md +13 -0
- package/dist/cjs/plugin.js +41 -125
- package/dist/cjs/ui/ContentComponent.js +27 -0
- package/dist/cjs/ui/InputQuery.js +5 -3
- package/dist/cjs/ui/TypeAheadMenu.js +95 -0
- package/dist/es2019/plugin.js +21 -104
- package/dist/es2019/ui/ContentComponent.js +22 -0
- package/dist/es2019/ui/InputQuery.js +5 -3
- package/dist/es2019/ui/TypeAheadMenu.js +86 -0
- package/dist/esm/plugin.js +41 -125
- package/dist/esm/ui/ContentComponent.js +20 -0
- package/dist/esm/ui/InputQuery.js +5 -3
- package/dist/esm/ui/TypeAheadMenu.js +88 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +12 -6
- package/dist/types/ui/ContentComponent.d.ts +13 -0
- package/dist/types/ui/InputQuery.d.ts +4 -2
- package/dist/types/ui/TypeAheadListItem.d.ts +2 -3
- package/dist/types/ui/TypeAheadMenu.d.ts +12 -0
- package/dist/types/ui/TypeAheadPopup.d.ts +2 -1
- package/dist/types/ui/WrapperTypeAhead.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +12 -6
- package/dist/types-ts4.5/ui/ContentComponent.d.ts +13 -0
- package/dist/types-ts4.5/ui/InputQuery.d.ts +4 -2
- package/dist/types-ts4.5/ui/TypeAheadListItem.d.ts +2 -3
- package/dist/types-ts4.5/ui/TypeAheadMenu.d.ts +12 -0
- package/dist/types-ts4.5/ui/TypeAheadPopup.d.ts +2 -1
- package/dist/types-ts4.5/ui/WrapperTypeAhead.d.ts +1 -1
- package/package.json +4 -5
package/.eslintrc.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
rules: {
|
|
3
3
|
'@typescript-eslint/no-duplicate-imports': 'error',
|
|
4
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
5
|
+
'@typescript-eslint/ban-types': [
|
|
6
|
+
'error',
|
|
7
|
+
{
|
|
8
|
+
types: {
|
|
9
|
+
'React.FC':
|
|
10
|
+
'Please use types directly on props instead, and explicitly define children if required',
|
|
11
|
+
'React.FunctionalComponent':
|
|
12
|
+
'Please use types directly on props instead, and explicitly define children if required',
|
|
13
|
+
},
|
|
14
|
+
extendDefaults: false,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
4
17
|
},
|
|
5
18
|
};
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-type-ahead
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#67189](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/67189) [`93cbf53ca0e0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/93cbf53ca0e0) - Removing instances of WithPluginState from mentions and type-ahead plugins.
|
|
8
|
+
|
|
9
|
+
## 0.9.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#65031](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65031) [`a00094111b5a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a00094111b5a) - ED-21609 Update adf-schema to 35.3.0
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 0.9.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -5,15 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.typeAheadPlugin = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
8
|
var _react = _interopRequireDefault(require("react"));
|
|
10
9
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
11
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
13
12
|
var _typeAhead = require("@atlaskit/editor-common/type-ahead");
|
|
14
|
-
var
|
|
13
|
+
var _view2 = require("@atlaskit/editor-prosemirror/view");
|
|
15
14
|
var _insertTypeAheadItem = require("./commands/insert-type-ahead-item");
|
|
16
|
-
var _updateSelectedIndex = require("./commands/update-selected-index");
|
|
17
15
|
var _inputRules = require("./pm-plugins/input-rules");
|
|
18
16
|
var _insertItemPlugin = require("./pm-plugins/insert-item-plugin");
|
|
19
17
|
var _key = require("./pm-plugins/key");
|
|
@@ -21,8 +19,7 @@ var _main = require("./pm-plugins/main");
|
|
|
21
19
|
var _statsModifier = require("./stats-modifier");
|
|
22
20
|
var _closeTypeAhead = require("./transforms/close-type-ahead");
|
|
23
21
|
var _openTypeaheadAtCursor = require("./transforms/open-typeahead-at-cursor");
|
|
24
|
-
var
|
|
25
|
-
var _TypeAheadPopup = require("./ui/TypeAheadPopup");
|
|
22
|
+
var _ContentComponent = require("./ui/ContentComponent");
|
|
26
23
|
var _utils = require("./utils");
|
|
27
24
|
/**
|
|
28
25
|
*
|
|
@@ -33,88 +30,6 @@ var _utils = require("./utils");
|
|
|
33
30
|
*
|
|
34
31
|
*/
|
|
35
32
|
|
|
36
|
-
var TypeAheadMenu = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
37
|
-
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
38
|
-
var editorView = _ref.editorView,
|
|
39
|
-
popupMountRef = _ref.popupMountRef,
|
|
40
|
-
typeAheadState = _ref.typeAheadState,
|
|
41
|
-
fireAnalyticsCallback = _ref.fireAnalyticsCallback;
|
|
42
|
-
var isOpen = typeAheadState.decorationSet.find().length > 0;
|
|
43
|
-
var triggerHandler = typeAheadState.triggerHandler,
|
|
44
|
-
items = typeAheadState.items,
|
|
45
|
-
selectedIndex = typeAheadState.selectedIndex,
|
|
46
|
-
decorationElement = typeAheadState.decorationElement,
|
|
47
|
-
decorationSet = typeAheadState.decorationSet,
|
|
48
|
-
query = typeAheadState.query;
|
|
49
|
-
var _useItemInsert = (0, _useItemInsert3.useItemInsert)(triggerHandler, editorView, items),
|
|
50
|
-
_useItemInsert2 = (0, _slicedToArray2.default)(_useItemInsert, 3),
|
|
51
|
-
onItemInsert = _useItemInsert2[0],
|
|
52
|
-
onTextInsert = _useItemInsert2[1],
|
|
53
|
-
onItemMatch = _useItemInsert2[2];
|
|
54
|
-
var setSelectedItem = _react.default.useCallback(function (_ref2) {
|
|
55
|
-
var nextIndex = _ref2.index;
|
|
56
|
-
queueMicrotask(function () {
|
|
57
|
-
(0, _updateSelectedIndex.updateSelectedIndex)(nextIndex)(editorView.state, editorView.dispatch);
|
|
58
|
-
});
|
|
59
|
-
}, [editorView]);
|
|
60
|
-
var insertItem = _react.default.useCallback(function () {
|
|
61
|
-
var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _typeAhead.SelectItemMode.SELECTED;
|
|
62
|
-
var index = arguments.length > 1 ? arguments[1] : undefined;
|
|
63
|
-
queueMicrotask(function () {
|
|
64
|
-
onItemInsert({
|
|
65
|
-
mode: mode,
|
|
66
|
-
index: index,
|
|
67
|
-
query: query
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}, [onItemInsert, query]);
|
|
71
|
-
var cancel = _react.default.useCallback(function (_ref3) {
|
|
72
|
-
var setSelectionAt = _ref3.setSelectionAt,
|
|
73
|
-
addPrefixTrigger = _ref3.addPrefixTrigger,
|
|
74
|
-
forceFocusOnEditor = _ref3.forceFocusOnEditor;
|
|
75
|
-
var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
|
|
76
|
-
onTextInsert({
|
|
77
|
-
forceFocusOnEditor: forceFocusOnEditor,
|
|
78
|
-
setSelectionAt: setSelectionAt,
|
|
79
|
-
text: fullQuery
|
|
80
|
-
});
|
|
81
|
-
}, [triggerHandler, onTextInsert, query]);
|
|
82
|
-
_react.default.useEffect(function () {
|
|
83
|
-
if (!isOpen || !query) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
var isLastCharSpace = query[query.length - 1] === ' ';
|
|
87
|
-
if (!isLastCharSpace) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
var result = onItemMatch({
|
|
91
|
-
mode: _typeAhead.SelectItemMode.SPACE,
|
|
92
|
-
query: query.trim()
|
|
93
|
-
});
|
|
94
|
-
if (!result) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
}, [isOpen, query, onItemMatch]);
|
|
98
|
-
if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
return /*#__PURE__*/_react.default.createElement(_TypeAheadPopup.TypeAheadPopup, {
|
|
102
|
-
editorView: editorView,
|
|
103
|
-
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
104
|
-
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
105
|
-
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
106
|
-
anchorElement: decorationElement,
|
|
107
|
-
triggerHandler: triggerHandler,
|
|
108
|
-
fireAnalyticsCallback: fireAnalyticsCallback,
|
|
109
|
-
items: items,
|
|
110
|
-
selectedIndex: selectedIndex,
|
|
111
|
-
setSelectedItem: setSelectedItem,
|
|
112
|
-
onItemInsert: insertItem,
|
|
113
|
-
decorationSet: decorationSet,
|
|
114
|
-
isEmptyQuery: !query,
|
|
115
|
-
cancel: cancel
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
33
|
var createOpenAtTransaction = function createOpenAtTransaction(editorAnalyticsAPI) {
|
|
119
34
|
return function (props) {
|
|
120
35
|
return function (tr) {
|
|
@@ -221,10 +136,10 @@ var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
|
|
|
221
136
|
*
|
|
222
137
|
*
|
|
223
138
|
*/
|
|
224
|
-
var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(
|
|
139
|
+
var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(_ref) {
|
|
225
140
|
var _api$analytics, _api$analytics2;
|
|
226
|
-
var options =
|
|
227
|
-
api =
|
|
141
|
+
var options = _ref.config,
|
|
142
|
+
api = _ref.api;
|
|
228
143
|
var fireAnalyticsCallback = (0, _analytics.fireAnalyticsEvent)(options === null || options === void 0 ? void 0 : options.createAnalyticsEvent);
|
|
229
144
|
var popupMountRef = {
|
|
230
145
|
current: null
|
|
@@ -246,9 +161,9 @@ var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(_ref4)
|
|
|
246
161
|
var typeAhead = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
247
162
|
return [{
|
|
248
163
|
name: 'typeAhead',
|
|
249
|
-
plugin: function plugin(
|
|
250
|
-
var dispatch =
|
|
251
|
-
getIntl =
|
|
164
|
+
plugin: function plugin(_ref2) {
|
|
165
|
+
var dispatch = _ref2.dispatch,
|
|
166
|
+
getIntl = _ref2.getIntl;
|
|
252
167
|
return (0, _main.createPlugin)({
|
|
253
168
|
getIntl: getIntl,
|
|
254
169
|
popupMountRef: popupMountRef,
|
|
@@ -276,28 +191,40 @@ var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(_ref4)
|
|
|
276
191
|
plugin: _insertItemPlugin.createPlugin
|
|
277
192
|
}, {
|
|
278
193
|
name: 'typeAheadInputRule',
|
|
279
|
-
plugin: function plugin(
|
|
280
|
-
var schema =
|
|
281
|
-
featureFlags =
|
|
194
|
+
plugin: function plugin(_ref3) {
|
|
195
|
+
var schema = _ref3.schema,
|
|
196
|
+
featureFlags = _ref3.featureFlags;
|
|
282
197
|
return (0, _inputRules.inputRulePlugin)(schema, typeAhead, featureFlags);
|
|
283
198
|
}
|
|
284
199
|
}];
|
|
285
200
|
},
|
|
286
201
|
getSharedState: function getSharedState(editorState) {
|
|
202
|
+
var _state$decorationSet, _state$decorationElem, _state$items, _state$selectedIndex;
|
|
287
203
|
if (!editorState) {
|
|
288
204
|
return {
|
|
289
205
|
query: '',
|
|
290
206
|
isOpen: false,
|
|
291
207
|
isAllowed: false,
|
|
292
|
-
currentHandler: undefined
|
|
208
|
+
currentHandler: undefined,
|
|
209
|
+
decorationSet: _view2.DecorationSet.empty,
|
|
210
|
+
decorationElement: null,
|
|
211
|
+
triggerHandler: undefined,
|
|
212
|
+
items: [],
|
|
213
|
+
selectedIndex: 0
|
|
293
214
|
};
|
|
294
215
|
}
|
|
295
216
|
var isOpen = (0, _utils.isTypeAheadOpen)(editorState);
|
|
217
|
+
var state = (0, _utils.getPluginState)(editorState);
|
|
296
218
|
return {
|
|
297
219
|
query: (0, _utils.getTypeAheadQuery)(editorState) || '',
|
|
298
220
|
currentHandler: (0, _utils.getTypeAheadHandler)(editorState),
|
|
299
221
|
isOpen: isOpen,
|
|
300
|
-
isAllowed: !isOpen
|
|
222
|
+
isAllowed: !isOpen,
|
|
223
|
+
decorationSet: (_state$decorationSet = state === null || state === void 0 ? void 0 : state.decorationSet) !== null && _state$decorationSet !== void 0 ? _state$decorationSet : _view2.DecorationSet.empty,
|
|
224
|
+
decorationElement: (_state$decorationElem = state === null || state === void 0 ? void 0 : state.decorationElement) !== null && _state$decorationElem !== void 0 ? _state$decorationElem : null,
|
|
225
|
+
triggerHandler: state === null || state === void 0 ? void 0 : state.triggerHandler,
|
|
226
|
+
items: (_state$items = state === null || state === void 0 ? void 0 : state.items) !== null && _state$items !== void 0 ? _state$items : [],
|
|
227
|
+
selectedIndex: (_state$selectedIndex = state === null || state === void 0 ? void 0 : state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0
|
|
301
228
|
};
|
|
302
229
|
},
|
|
303
230
|
actions: {
|
|
@@ -309,40 +236,29 @@ var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(_ref4)
|
|
|
309
236
|
insert: createInsertTypeAheadItem(editorViewRef),
|
|
310
237
|
close: createCloseTypeAhead(editorViewRef)
|
|
311
238
|
},
|
|
312
|
-
contentComponent: function contentComponent(
|
|
313
|
-
var editorView =
|
|
314
|
-
containerElement =
|
|
315
|
-
popupsMountPoint =
|
|
316
|
-
popupsBoundariesElement =
|
|
317
|
-
popupsScrollableElement =
|
|
318
|
-
wrapperElement =
|
|
239
|
+
contentComponent: function contentComponent(_ref4) {
|
|
240
|
+
var editorView = _ref4.editorView,
|
|
241
|
+
containerElement = _ref4.containerElement,
|
|
242
|
+
popupsMountPoint = _ref4.popupsMountPoint,
|
|
243
|
+
popupsBoundariesElement = _ref4.popupsBoundariesElement,
|
|
244
|
+
popupsScrollableElement = _ref4.popupsScrollableElement,
|
|
245
|
+
wrapperElement = _ref4.wrapperElement;
|
|
319
246
|
popupMountRef.current = {
|
|
320
247
|
popupsMountPoint: popupsMountPoint || wrapperElement || undefined,
|
|
321
248
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
322
249
|
popupsScrollableElement: popupsScrollableElement || containerElement || undefined
|
|
323
250
|
};
|
|
324
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
var typeAheadState = _ref8.typeAheadState;
|
|
330
|
-
if (!typeAheadState) {
|
|
331
|
-
return null;
|
|
332
|
-
}
|
|
333
|
-
return /*#__PURE__*/_react.default.createElement(TypeAheadMenu, {
|
|
334
|
-
editorView: editorView,
|
|
335
|
-
popupMountRef: popupMountRef,
|
|
336
|
-
typeAheadState: typeAheadState,
|
|
337
|
-
fireAnalyticsCallback: fireAnalyticsCallback
|
|
338
|
-
});
|
|
339
|
-
}
|
|
251
|
+
return /*#__PURE__*/_react.default.createElement(_ContentComponent.ContentComponent, {
|
|
252
|
+
editorView: editorView,
|
|
253
|
+
popupMountRef: popupMountRef,
|
|
254
|
+
api: api,
|
|
255
|
+
fireAnalyticsCallback: fireAnalyticsCallback
|
|
340
256
|
});
|
|
341
257
|
},
|
|
342
|
-
onEditorViewStateUpdated: function onEditorViewStateUpdated(
|
|
343
|
-
var originalTransaction =
|
|
344
|
-
oldEditorState =
|
|
345
|
-
newEditorState =
|
|
258
|
+
onEditorViewStateUpdated: function onEditorViewStateUpdated(_ref5) {
|
|
259
|
+
var originalTransaction = _ref5.originalTransaction,
|
|
260
|
+
oldEditorState = _ref5.oldEditorState,
|
|
261
|
+
newEditorState = _ref5.newEditorState;
|
|
346
262
|
var oldPluginState = (0, _utils.getPluginState)(oldEditorState);
|
|
347
263
|
var newPluginState = (0, _utils.getPluginState)(newEditorState);
|
|
348
264
|
if (!oldPluginState || !newPluginState) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.ContentComponent = ContentComponent;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
10
|
+
var _TypeAheadMenu = require("./TypeAheadMenu");
|
|
11
|
+
function ContentComponent(_ref) {
|
|
12
|
+
var api = _ref.api,
|
|
13
|
+
editorView = _ref.editorView,
|
|
14
|
+
popupMountRef = _ref.popupMountRef,
|
|
15
|
+
fireAnalyticsCallback = _ref.fireAnalyticsCallback;
|
|
16
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['typeAhead']),
|
|
17
|
+
typeAheadState = _useSharedPluginState.typeAheadState;
|
|
18
|
+
if (!typeAheadState) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return /*#__PURE__*/_react.default.createElement(_TypeAheadMenu.TypeAheadMenu, {
|
|
22
|
+
editorView: editorView,
|
|
23
|
+
popupMountRef: popupMountRef,
|
|
24
|
+
typeAheadState: typeAheadState,
|
|
25
|
+
fireAnalyticsCallback: fireAnalyticsCallback
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -255,7 +255,9 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
255
255
|
// our event listener). As this path is strictly for click or other typeahead
|
|
256
256
|
// dismissals that don't involve typeahead item selection, we carve out an
|
|
257
257
|
// exception for Chrome-specific events where an input device was not the initiator.
|
|
258
|
-
if (_utils.browser.chrome && !(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range') &&
|
|
258
|
+
if (_utils.browser.chrome && !(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range') &&
|
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
|
+
!('sourceCapabilities' in event && event.sourceCapabilities)) {
|
|
259
261
|
return;
|
|
260
262
|
}
|
|
261
263
|
cancel({
|
|
@@ -304,7 +306,7 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
};
|
|
307
|
-
var onInput =
|
|
309
|
+
var onInput = function onInput() {};
|
|
308
310
|
if (_utils.browser.safari) {
|
|
309
311
|
// On Safari, for reasons beyond my understanding,
|
|
310
312
|
// The undo behavior is totally different from other browsers
|
|
@@ -312,7 +314,7 @@ var InputQuery = exports.InputQuery = /*#__PURE__*/_react.default.memo(function
|
|
|
312
314
|
var _onInput = function _onInput(e) {
|
|
313
315
|
var _target$textContent2;
|
|
314
316
|
var target = e.target;
|
|
315
|
-
if (e.isComposing || !(target instanceof HTMLElement)) {
|
|
317
|
+
if (!(e instanceof InputEvent) || e.isComposing || !(target instanceof HTMLElement)) {
|
|
316
318
|
return;
|
|
317
319
|
}
|
|
318
320
|
if (e.inputType === 'historyUndo' && ((_target$textContent2 = target.textContent) === null || _target$textContent2 === void 0 ? void 0 : _target$textContent2.length) === 1) {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TypeAheadMenu = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _typeAhead = require("@atlaskit/editor-common/type-ahead");
|
|
11
|
+
var _updateSelectedIndex = require("../commands/update-selected-index");
|
|
12
|
+
var _useItemInsert3 = require("./hooks/use-item-insert");
|
|
13
|
+
var _TypeAheadPopup = require("./TypeAheadPopup");
|
|
14
|
+
var TypeAheadMenu = exports.TypeAheadMenu = /*#__PURE__*/_react.default.memo(function (_ref) {
|
|
15
|
+
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
16
|
+
var editorView = _ref.editorView,
|
|
17
|
+
popupMountRef = _ref.popupMountRef,
|
|
18
|
+
typeAheadState = _ref.typeAheadState,
|
|
19
|
+
fireAnalyticsCallback = _ref.fireAnalyticsCallback;
|
|
20
|
+
var isOpen = typeAheadState.decorationSet.find().length > 0;
|
|
21
|
+
var triggerHandler = typeAheadState.triggerHandler,
|
|
22
|
+
items = typeAheadState.items,
|
|
23
|
+
selectedIndex = typeAheadState.selectedIndex,
|
|
24
|
+
decorationElement = typeAheadState.decorationElement,
|
|
25
|
+
decorationSet = typeAheadState.decorationSet,
|
|
26
|
+
query = typeAheadState.query;
|
|
27
|
+
var _useItemInsert = (0, _useItemInsert3.useItemInsert)(triggerHandler, editorView, items),
|
|
28
|
+
_useItemInsert2 = (0, _slicedToArray2.default)(_useItemInsert, 3),
|
|
29
|
+
onItemInsert = _useItemInsert2[0],
|
|
30
|
+
onTextInsert = _useItemInsert2[1],
|
|
31
|
+
onItemMatch = _useItemInsert2[2];
|
|
32
|
+
var setSelectedItem = _react.default.useCallback(function (_ref2) {
|
|
33
|
+
var nextIndex = _ref2.index;
|
|
34
|
+
queueMicrotask(function () {
|
|
35
|
+
(0, _updateSelectedIndex.updateSelectedIndex)(nextIndex)(editorView.state, editorView.dispatch);
|
|
36
|
+
});
|
|
37
|
+
}, [editorView]);
|
|
38
|
+
var insertItem = _react.default.useCallback(function () {
|
|
39
|
+
var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _typeAhead.SelectItemMode.SELECTED;
|
|
40
|
+
var index = arguments.length > 1 ? arguments[1] : undefined;
|
|
41
|
+
queueMicrotask(function () {
|
|
42
|
+
onItemInsert({
|
|
43
|
+
mode: mode,
|
|
44
|
+
index: index,
|
|
45
|
+
query: query
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}, [onItemInsert, query]);
|
|
49
|
+
var cancel = _react.default.useCallback(function (_ref3) {
|
|
50
|
+
var setSelectionAt = _ref3.setSelectionAt,
|
|
51
|
+
addPrefixTrigger = _ref3.addPrefixTrigger,
|
|
52
|
+
forceFocusOnEditor = _ref3.forceFocusOnEditor;
|
|
53
|
+
var fullQuery = addPrefixTrigger ? "".concat(triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger).concat(query) : query;
|
|
54
|
+
onTextInsert({
|
|
55
|
+
forceFocusOnEditor: forceFocusOnEditor,
|
|
56
|
+
setSelectionAt: setSelectionAt,
|
|
57
|
+
text: fullQuery
|
|
58
|
+
});
|
|
59
|
+
}, [triggerHandler, onTextInsert, query]);
|
|
60
|
+
_react.default.useEffect(function () {
|
|
61
|
+
if (!isOpen || !query) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var isLastCharSpace = query[query.length - 1] === ' ';
|
|
65
|
+
if (!isLastCharSpace) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var result = onItemMatch({
|
|
69
|
+
mode: _typeAhead.SelectItemMode.SPACE,
|
|
70
|
+
query: query.trim()
|
|
71
|
+
});
|
|
72
|
+
if (!result) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}, [isOpen, query, onItemMatch]);
|
|
76
|
+
if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return /*#__PURE__*/_react.default.createElement(_TypeAheadPopup.TypeAheadPopup, {
|
|
80
|
+
editorView: editorView,
|
|
81
|
+
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
82
|
+
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
83
|
+
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
84
|
+
anchorElement: decorationElement,
|
|
85
|
+
triggerHandler: triggerHandler,
|
|
86
|
+
fireAnalyticsCallback: fireAnalyticsCallback,
|
|
87
|
+
items: items,
|
|
88
|
+
selectedIndex: selectedIndex,
|
|
89
|
+
setSelectedItem: setSelectedItem,
|
|
90
|
+
onItemInsert: insertItem,
|
|
91
|
+
decorationSet: decorationSet,
|
|
92
|
+
isEmptyQuery: !query,
|
|
93
|
+
cancel: cancel
|
|
94
|
+
});
|
|
95
|
+
});
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -11,9 +11,8 @@ import { typeAheadQuery } from '@atlaskit/adf-schema';
|
|
|
11
11
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, fireAnalyticsEvent, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
12
12
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
13
13
|
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
14
|
-
import {
|
|
14
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
15
15
|
import { insertTypeAheadItem } from './commands/insert-type-ahead-item';
|
|
16
|
-
import { updateSelectedIndex } from './commands/update-selected-index';
|
|
17
16
|
import { inputRulePlugin } from './pm-plugins/input-rules';
|
|
18
17
|
import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
|
|
19
18
|
import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
|
|
@@ -21,90 +20,8 @@ import { createPlugin } from './pm-plugins/main';
|
|
|
21
20
|
import { StatsModifier } from './stats-modifier';
|
|
22
21
|
import { closeTypeAhead } from './transforms/close-type-ahead';
|
|
23
22
|
import { openTypeAheadAtCursor } from './transforms/open-typeahead-at-cursor';
|
|
24
|
-
import {
|
|
25
|
-
import { TypeAheadPopup } from './ui/TypeAheadPopup';
|
|
23
|
+
import { ContentComponent } from './ui/ContentComponent';
|
|
26
24
|
import { findHandler, getPluginState, getTypeAheadHandler, getTypeAheadQuery, isTypeAheadAllowed, isTypeAheadOpen } from './utils';
|
|
27
|
-
const TypeAheadMenu = /*#__PURE__*/React.memo(({
|
|
28
|
-
editorView,
|
|
29
|
-
popupMountRef,
|
|
30
|
-
typeAheadState,
|
|
31
|
-
fireAnalyticsCallback
|
|
32
|
-
}) => {
|
|
33
|
-
var _popupMountRef$curren, _popupMountRef$curren2, _popupMountRef$curren3;
|
|
34
|
-
const isOpen = typeAheadState.decorationSet.find().length > 0;
|
|
35
|
-
const {
|
|
36
|
-
triggerHandler,
|
|
37
|
-
items,
|
|
38
|
-
selectedIndex,
|
|
39
|
-
decorationElement,
|
|
40
|
-
decorationSet,
|
|
41
|
-
query
|
|
42
|
-
} = typeAheadState;
|
|
43
|
-
const [onItemInsert, onTextInsert, onItemMatch] = useItemInsert(triggerHandler, editorView, items);
|
|
44
|
-
const setSelectedItem = React.useCallback(({
|
|
45
|
-
index: nextIndex
|
|
46
|
-
}) => {
|
|
47
|
-
queueMicrotask(() => {
|
|
48
|
-
updateSelectedIndex(nextIndex)(editorView.state, editorView.dispatch);
|
|
49
|
-
});
|
|
50
|
-
}, [editorView]);
|
|
51
|
-
const insertItem = React.useCallback((mode = SelectItemMode.SELECTED, index) => {
|
|
52
|
-
queueMicrotask(() => {
|
|
53
|
-
onItemInsert({
|
|
54
|
-
mode,
|
|
55
|
-
index,
|
|
56
|
-
query
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}, [onItemInsert, query]);
|
|
60
|
-
const cancel = React.useCallback(({
|
|
61
|
-
setSelectionAt,
|
|
62
|
-
addPrefixTrigger,
|
|
63
|
-
forceFocusOnEditor
|
|
64
|
-
}) => {
|
|
65
|
-
const fullQuery = addPrefixTrigger ? `${triggerHandler === null || triggerHandler === void 0 ? void 0 : triggerHandler.trigger}${query}` : query;
|
|
66
|
-
onTextInsert({
|
|
67
|
-
forceFocusOnEditor,
|
|
68
|
-
setSelectionAt,
|
|
69
|
-
text: fullQuery
|
|
70
|
-
});
|
|
71
|
-
}, [triggerHandler, onTextInsert, query]);
|
|
72
|
-
React.useEffect(() => {
|
|
73
|
-
if (!isOpen || !query) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const isLastCharSpace = query[query.length - 1] === ' ';
|
|
77
|
-
if (!isLastCharSpace) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const result = onItemMatch({
|
|
81
|
-
mode: SelectItemMode.SPACE,
|
|
82
|
-
query: query.trim()
|
|
83
|
-
});
|
|
84
|
-
if (!result) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
}, [isOpen, query, onItemMatch]);
|
|
88
|
-
if (!isOpen || !triggerHandler || !(decorationElement instanceof HTMLElement) || items.length === 0) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
return /*#__PURE__*/React.createElement(TypeAheadPopup, {
|
|
92
|
-
editorView: editorView,
|
|
93
|
-
popupsMountPoint: (_popupMountRef$curren = popupMountRef.current) === null || _popupMountRef$curren === void 0 ? void 0 : _popupMountRef$curren.popupsMountPoint,
|
|
94
|
-
popupsBoundariesElement: (_popupMountRef$curren2 = popupMountRef.current) === null || _popupMountRef$curren2 === void 0 ? void 0 : _popupMountRef$curren2.popupsBoundariesElement,
|
|
95
|
-
popupsScrollableElement: (_popupMountRef$curren3 = popupMountRef.current) === null || _popupMountRef$curren3 === void 0 ? void 0 : _popupMountRef$curren3.popupsScrollableElement,
|
|
96
|
-
anchorElement: decorationElement,
|
|
97
|
-
triggerHandler: triggerHandler,
|
|
98
|
-
fireAnalyticsCallback: fireAnalyticsCallback,
|
|
99
|
-
items: items,
|
|
100
|
-
selectedIndex: selectedIndex,
|
|
101
|
-
setSelectedItem: setSelectedItem,
|
|
102
|
-
onItemInsert: insertItem,
|
|
103
|
-
decorationSet: decorationSet,
|
|
104
|
-
isEmptyQuery: !query,
|
|
105
|
-
cancel: cancel
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
25
|
const createOpenAtTransaction = editorAnalyticsAPI => props => tr => {
|
|
109
26
|
const {
|
|
110
27
|
triggerHandler,
|
|
@@ -276,20 +193,32 @@ export const typeAheadPlugin = ({
|
|
|
276
193
|
}];
|
|
277
194
|
},
|
|
278
195
|
getSharedState(editorState) {
|
|
196
|
+
var _state$decorationSet, _state$decorationElem, _state$items, _state$selectedIndex;
|
|
279
197
|
if (!editorState) {
|
|
280
198
|
return {
|
|
281
199
|
query: '',
|
|
282
200
|
isOpen: false,
|
|
283
201
|
isAllowed: false,
|
|
284
|
-
currentHandler: undefined
|
|
202
|
+
currentHandler: undefined,
|
|
203
|
+
decorationSet: DecorationSet.empty,
|
|
204
|
+
decorationElement: null,
|
|
205
|
+
triggerHandler: undefined,
|
|
206
|
+
items: [],
|
|
207
|
+
selectedIndex: 0
|
|
285
208
|
};
|
|
286
209
|
}
|
|
287
210
|
const isOpen = isTypeAheadOpen(editorState);
|
|
211
|
+
const state = getPluginState(editorState);
|
|
288
212
|
return {
|
|
289
213
|
query: getTypeAheadQuery(editorState) || '',
|
|
290
214
|
currentHandler: getTypeAheadHandler(editorState),
|
|
291
215
|
isOpen,
|
|
292
|
-
isAllowed: !isOpen
|
|
216
|
+
isAllowed: !isOpen,
|
|
217
|
+
decorationSet: (_state$decorationSet = state === null || state === void 0 ? void 0 : state.decorationSet) !== null && _state$decorationSet !== void 0 ? _state$decorationSet : DecorationSet.empty,
|
|
218
|
+
decorationElement: (_state$decorationElem = state === null || state === void 0 ? void 0 : state.decorationElement) !== null && _state$decorationElem !== void 0 ? _state$decorationElem : null,
|
|
219
|
+
triggerHandler: state === null || state === void 0 ? void 0 : state.triggerHandler,
|
|
220
|
+
items: (_state$items = state === null || state === void 0 ? void 0 : state.items) !== null && _state$items !== void 0 ? _state$items : [],
|
|
221
|
+
selectedIndex: (_state$selectedIndex = state === null || state === void 0 ? void 0 : state.selectedIndex) !== null && _state$selectedIndex !== void 0 ? _state$selectedIndex : 0
|
|
293
222
|
};
|
|
294
223
|
},
|
|
295
224
|
actions: {
|
|
@@ -314,23 +243,11 @@ export const typeAheadPlugin = ({
|
|
|
314
243
|
popupsBoundariesElement,
|
|
315
244
|
popupsScrollableElement: popupsScrollableElement || containerElement || undefined
|
|
316
245
|
};
|
|
317
|
-
return /*#__PURE__*/React.createElement(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
typeAheadState
|
|
323
|
-
}) => {
|
|
324
|
-
if (!typeAheadState) {
|
|
325
|
-
return null;
|
|
326
|
-
}
|
|
327
|
-
return /*#__PURE__*/React.createElement(TypeAheadMenu, {
|
|
328
|
-
editorView: editorView,
|
|
329
|
-
popupMountRef: popupMountRef,
|
|
330
|
-
typeAheadState: typeAheadState,
|
|
331
|
-
fireAnalyticsCallback: fireAnalyticsCallback
|
|
332
|
-
});
|
|
333
|
-
}
|
|
246
|
+
return /*#__PURE__*/React.createElement(ContentComponent, {
|
|
247
|
+
editorView: editorView,
|
|
248
|
+
popupMountRef: popupMountRef,
|
|
249
|
+
api: api,
|
|
250
|
+
fireAnalyticsCallback: fireAnalyticsCallback
|
|
334
251
|
});
|
|
335
252
|
},
|
|
336
253
|
onEditorViewStateUpdated({
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
|
+
import { TypeAheadMenu } from './TypeAheadMenu';
|
|
4
|
+
export function ContentComponent({
|
|
5
|
+
api,
|
|
6
|
+
editorView,
|
|
7
|
+
popupMountRef,
|
|
8
|
+
fireAnalyticsCallback
|
|
9
|
+
}) {
|
|
10
|
+
const {
|
|
11
|
+
typeAheadState
|
|
12
|
+
} = useSharedPluginState(api, ['typeAhead']);
|
|
13
|
+
if (!typeAheadState) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return /*#__PURE__*/React.createElement(TypeAheadMenu, {
|
|
17
|
+
editorView: editorView,
|
|
18
|
+
popupMountRef: popupMountRef,
|
|
19
|
+
typeAheadState: typeAheadState,
|
|
20
|
+
fireAnalyticsCallback: fireAnalyticsCallback
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -243,7 +243,9 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
243
243
|
// our event listener). As this path is strictly for click or other typeahead
|
|
244
244
|
// dismissals that don't involve typeahead item selection, we carve out an
|
|
245
245
|
// exception for Chrome-specific events where an input device was not the initiator.
|
|
246
|
-
if (browser.chrome && !(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range') &&
|
|
246
|
+
if (browser.chrome && !(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range') &&
|
|
247
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
248
|
+
!('sourceCapabilities' in event && event.sourceCapabilities)) {
|
|
247
249
|
return;
|
|
248
250
|
}
|
|
249
251
|
cancel({
|
|
@@ -294,7 +296,7 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
298
|
};
|
|
297
|
-
let onInput =
|
|
299
|
+
let onInput = () => {};
|
|
298
300
|
if (browser.safari) {
|
|
299
301
|
// On Safari, for reasons beyond my understanding,
|
|
300
302
|
// The undo behavior is totally different from other browsers
|
|
@@ -304,7 +306,7 @@ export const InputQuery = /*#__PURE__*/React.memo(({
|
|
|
304
306
|
const {
|
|
305
307
|
target
|
|
306
308
|
} = e;
|
|
307
|
-
if (e.isComposing || !(target instanceof HTMLElement)) {
|
|
309
|
+
if (!(e instanceof InputEvent) || e.isComposing || !(target instanceof HTMLElement)) {
|
|
308
310
|
return;
|
|
309
311
|
}
|
|
310
312
|
if (e.inputType === 'historyUndo' && ((_target$textContent2 = target.textContent) === null || _target$textContent2 === void 0 ? void 0 : _target$textContent2.length) === 1) {
|