@atlaskit/editor-plugin-type-ahead 0.5.0 → 0.7.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.
- package/.eslintrc.js +11 -0
- package/CHANGELOG.md +12 -0
- package/dist/cjs/api.js +215 -0
- package/dist/cjs/commands/insert-type-ahead-item.js +205 -0
- package/dist/cjs/commands/update-list-items.js +23 -0
- package/dist/cjs/commands/update-query.js +27 -0
- package/dist/cjs/commands/update-selected-index.js +27 -0
- package/dist/cjs/constants.js +15 -0
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/insert-utils.js +107 -0
- package/dist/cjs/messages.js +79 -0
- package/dist/cjs/plugin.js +382 -0
- package/dist/cjs/pm-plugins/actions.js +16 -0
- package/dist/cjs/pm-plugins/decorations.js +148 -0
- package/dist/cjs/pm-plugins/input-rules.js +36 -0
- package/dist/cjs/pm-plugins/insert-item-plugin.js +22 -0
- package/dist/cjs/pm-plugins/key.js +8 -0
- package/dist/cjs/pm-plugins/main.js +110 -0
- package/dist/cjs/pm-plugins/reducer.js +158 -0
- package/dist/cjs/pm-plugins/utils.js +18 -0
- package/dist/cjs/stats-modifier.js +42 -0
- package/dist/cjs/transforms/close-type-ahead.js +13 -0
- package/dist/cjs/transforms/open-typeahead-at-cursor.js +75 -0
- package/dist/cjs/transforms/set-selection-before-query.js +18 -0
- package/dist/cjs/ui/AssistiveText.js +120 -0
- package/dist/cjs/ui/InputQuery.js +400 -0
- package/dist/cjs/ui/TypeAheadList.js +285 -0
- package/dist/cjs/ui/TypeAheadListItem.js +181 -0
- package/dist/cjs/ui/TypeAheadPopup.js +230 -0
- package/dist/cjs/ui/WrapperTypeAhead.js +127 -0
- package/dist/cjs/ui/hooks/use-item-insert.js +109 -0
- package/dist/cjs/ui/hooks/use-load-items.js +50 -0
- package/dist/cjs/ui/hooks/use-on-force-select.js +41 -0
- package/dist/cjs/utils.js +130 -0
- package/dist/es2019/api.js +205 -0
- package/dist/es2019/commands/insert-type-ahead-item.js +204 -0
- package/dist/es2019/commands/update-list-items.js +17 -0
- package/dist/es2019/commands/update-query.js +21 -0
- package/dist/es2019/commands/update-selected-index.js +21 -0
- package/dist/es2019/constants.js +9 -0
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/insert-utils.js +106 -0
- package/dist/es2019/messages.js +73 -0
- package/dist/es2019/plugin.js +381 -0
- package/dist/es2019/pm-plugins/actions.js +10 -0
- package/dist/es2019/pm-plugins/decorations.js +148 -0
- package/dist/es2019/pm-plugins/input-rules.js +29 -0
- package/dist/es2019/pm-plugins/insert-item-plugin.js +16 -0
- package/dist/es2019/pm-plugins/key.js +2 -0
- package/dist/es2019/pm-plugins/main.js +106 -0
- package/dist/es2019/pm-plugins/reducer.js +160 -0
- package/dist/es2019/pm-plugins/utils.js +12 -0
- package/dist/es2019/stats-modifier.js +33 -0
- package/dist/es2019/transforms/close-type-ahead.js +7 -0
- package/dist/es2019/transforms/open-typeahead-at-cursor.js +71 -0
- package/dist/es2019/transforms/set-selection-before-query.js +10 -0
- package/dist/es2019/ui/AssistiveText.js +88 -0
- package/dist/es2019/ui/InputQuery.js +393 -0
- package/dist/es2019/ui/TypeAheadList.js +273 -0
- package/dist/es2019/ui/TypeAheadListItem.js +216 -0
- package/dist/es2019/ui/TypeAheadPopup.js +233 -0
- package/dist/es2019/ui/WrapperTypeAhead.js +109 -0
- package/dist/es2019/ui/hooks/use-item-insert.js +112 -0
- package/dist/es2019/ui/hooks/use-load-items.js +41 -0
- package/dist/es2019/ui/hooks/use-on-force-select.js +38 -0
- package/dist/es2019/utils.js +126 -0
- package/dist/esm/api.js +209 -0
- package/dist/esm/commands/insert-type-ahead-item.js +198 -0
- package/dist/esm/commands/update-list-items.js +17 -0
- package/dist/esm/commands/update-query.js +21 -0
- package/dist/esm/commands/update-selected-index.js +21 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/insert-utils.js +101 -0
- package/dist/esm/messages.js +73 -0
- package/dist/esm/plugin.js +374 -0
- package/dist/esm/pm-plugins/actions.js +10 -0
- package/dist/esm/pm-plugins/decorations.js +141 -0
- package/dist/esm/pm-plugins/input-rules.js +29 -0
- package/dist/esm/pm-plugins/insert-item-plugin.js +16 -0
- package/dist/esm/pm-plugins/key.js +2 -0
- package/dist/esm/pm-plugins/main.js +104 -0
- package/dist/esm/pm-plugins/reducer.js +151 -0
- package/dist/esm/pm-plugins/utils.js +12 -0
- package/dist/esm/stats-modifier.js +35 -0
- package/dist/esm/transforms/close-type-ahead.js +7 -0
- package/dist/esm/transforms/open-typeahead-at-cursor.js +69 -0
- package/dist/esm/transforms/set-selection-before-query.js +12 -0
- package/dist/esm/ui/AssistiveText.js +115 -0
- package/dist/esm/ui/InputQuery.js +390 -0
- package/dist/esm/ui/TypeAheadList.js +276 -0
- package/dist/esm/ui/TypeAheadListItem.js +171 -0
- package/dist/esm/ui/TypeAheadPopup.js +220 -0
- package/dist/esm/ui/WrapperTypeAhead.js +117 -0
- package/dist/esm/ui/hooks/use-item-insert.js +103 -0
- package/dist/esm/ui/hooks/use-load-items.js +43 -0
- package/dist/esm/ui/hooks/use-on-force-select.js +35 -0
- package/dist/esm/utils.js +124 -0
- package/dist/types/api.d.ts +61 -0
- package/dist/types/commands/insert-type-ahead-item.d.ts +12 -0
- package/dist/types/commands/update-list-items.d.ts +3 -0
- package/dist/types/commands/update-query.d.ts +2 -0
- package/dist/types/commands/update-selected-index.d.ts +2 -0
- package/dist/types/constants.d.ts +8 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/insert-utils.d.ts +18 -0
- package/dist/types/messages.d.ts +72 -0
- package/dist/types/plugin.d.ts +10 -0
- package/dist/types/pm-plugins/actions.d.ts +9 -0
- package/dist/types/pm-plugins/decorations.d.ts +14 -0
- package/dist/types/pm-plugins/input-rules.d.ts +6 -0
- package/dist/types/pm-plugins/insert-item-plugin.d.ts +2 -0
- package/dist/types/pm-plugins/key.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +14 -0
- package/dist/types/pm-plugins/reducer.d.ts +10 -0
- package/dist/types/pm-plugins/utils.d.ts +4 -0
- package/dist/types/stats-modifier.d.ts +20 -0
- package/dist/types/transforms/close-type-ahead.d.ts +2 -0
- package/dist/types/transforms/open-typeahead-at-cursor.d.ts +11 -0
- package/dist/types/transforms/set-selection-before-query.d.ts +2 -0
- package/dist/types/types.d.ts +64 -3
- package/dist/types/ui/AssistiveText.d.ts +33 -0
- package/dist/types/ui/InputQuery.d.ts +26 -0
- package/dist/types/ui/TypeAheadList.d.ts +25 -0
- package/dist/types/ui/TypeAheadListItem.d.ts +18 -0
- package/dist/types/ui/TypeAheadPopup.d.ts +29 -0
- package/dist/types/ui/WrapperTypeAhead.d.ts +20 -0
- package/dist/types/ui/hooks/use-item-insert.d.ts +3 -0
- package/dist/types/ui/hooks/use-load-items.d.ts +3 -0
- package/dist/types/ui/hooks/use-on-force-select.d.ts +11 -0
- package/dist/types/utils.d.ts +27 -0
- package/dist/types-ts4.5/api.d.ts +61 -0
- package/dist/types-ts4.5/commands/insert-type-ahead-item.d.ts +12 -0
- package/dist/types-ts4.5/commands/update-list-items.d.ts +3 -0
- package/dist/types-ts4.5/commands/update-query.d.ts +2 -0
- package/dist/types-ts4.5/commands/update-selected-index.d.ts +2 -0
- package/dist/types-ts4.5/constants.d.ts +8 -0
- package/dist/types-ts4.5/index.d.ts +2 -1
- package/dist/types-ts4.5/insert-utils.d.ts +18 -0
- package/dist/types-ts4.5/messages.d.ts +72 -0
- package/dist/types-ts4.5/plugin.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +14 -0
- package/dist/types-ts4.5/pm-plugins/input-rules.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/insert-item-plugin.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +14 -0
- package/dist/types-ts4.5/pm-plugins/reducer.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +4 -0
- package/dist/types-ts4.5/stats-modifier.d.ts +20 -0
- package/dist/types-ts4.5/transforms/close-type-ahead.d.ts +2 -0
- package/dist/types-ts4.5/transforms/open-typeahead-at-cursor.d.ts +11 -0
- package/dist/types-ts4.5/transforms/set-selection-before-query.d.ts +2 -0
- package/dist/types-ts4.5/types.d.ts +64 -3
- package/dist/types-ts4.5/ui/AssistiveText.d.ts +33 -0
- package/dist/types-ts4.5/ui/InputQuery.d.ts +26 -0
- package/dist/types-ts4.5/ui/TypeAheadList.d.ts +25 -0
- package/dist/types-ts4.5/ui/TypeAheadListItem.d.ts +18 -0
- package/dist/types-ts4.5/ui/TypeAheadPopup.d.ts +29 -0
- package/dist/types-ts4.5/ui/WrapperTypeAhead.d.ts +20 -0
- package/dist/types-ts4.5/ui/hooks/use-item-insert.d.ts +7 -0
- package/dist/types-ts4.5/ui/hooks/use-load-items.d.ts +3 -0
- package/dist/types-ts4.5/ui/hooks/use-on-force-select.d.ts +11 -0
- package/dist/types-ts4.5/utils.d.ts +27 -0
- package/package.json +21 -28
- package/report.api.md +32 -1
- package/tmp/api-report-tmp.d.ts +29 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
5
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
6
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
8
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
10
|
+
/** @jsx jsx */
|
|
11
|
+
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { css, jsx } from '@emotion/react';
|
|
14
|
+
import debounce from 'lodash/debounce';
|
|
15
|
+
var statusDebounceMillis = 1400;
|
|
16
|
+
var assitiveTextStyles = css({
|
|
17
|
+
border: 0,
|
|
18
|
+
clip: 'rect(0 0 0 0)',
|
|
19
|
+
height: '1px',
|
|
20
|
+
marginbottom: '-1px',
|
|
21
|
+
marginright: '-1px',
|
|
22
|
+
overflow: 'hidden',
|
|
23
|
+
padding: 0,
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
whitespace: 'nowrap',
|
|
26
|
+
width: '1px'
|
|
27
|
+
});
|
|
28
|
+
var AssistveTextComponent = /*#__PURE__*/function (_React$Component) {
|
|
29
|
+
_inherits(AssistveTextComponent, _React$Component);
|
|
30
|
+
var _super = _createSuper(AssistveTextComponent);
|
|
31
|
+
function AssistveTextComponent() {
|
|
32
|
+
var _this;
|
|
33
|
+
_classCallCheck(this, AssistveTextComponent);
|
|
34
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
35
|
+
args[_key] = arguments[_key];
|
|
36
|
+
}
|
|
37
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
38
|
+
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
39
|
+
bump: false,
|
|
40
|
+
//when the same text needs to be read again, Hence it needs to be toggled between __status--A and __status--B
|
|
41
|
+
debounced: false,
|
|
42
|
+
silenced: false
|
|
43
|
+
});
|
|
44
|
+
return _this;
|
|
45
|
+
}
|
|
46
|
+
_createClass(AssistveTextComponent, [{
|
|
47
|
+
key: "componentWillMount",
|
|
48
|
+
value: function componentWillMount() {
|
|
49
|
+
var _this2 = this;
|
|
50
|
+
this.debounceStatusUpdate = debounce(function () {
|
|
51
|
+
if (!_this2.state.debounced) {
|
|
52
|
+
var shouldSilence = !_this2.props.isInFocus;
|
|
53
|
+
_this2.setState(function (_ref) {
|
|
54
|
+
var bump = _ref.bump;
|
|
55
|
+
return {
|
|
56
|
+
bump: !bump,
|
|
57
|
+
debounced: true,
|
|
58
|
+
silenced: shouldSilence
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, statusDebounceMillis);
|
|
63
|
+
}
|
|
64
|
+
}, {
|
|
65
|
+
key: "componentWillUnmount",
|
|
66
|
+
value: function componentWillUnmount() {
|
|
67
|
+
this.debounceStatusUpdate.cancel();
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
key: "componentWillReceiveProps",
|
|
71
|
+
value: function componentWillReceiveProps() {
|
|
72
|
+
this.setState(function (_ref2) {
|
|
73
|
+
var bump = _ref2.bump;
|
|
74
|
+
return {
|
|
75
|
+
bump: !bump,
|
|
76
|
+
debounced: false
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "render",
|
|
82
|
+
value: function render() {
|
|
83
|
+
var _this$props = this.props,
|
|
84
|
+
assistiveText = _this$props.assistiveText,
|
|
85
|
+
id = _this$props.id;
|
|
86
|
+
var _this$state = this.state,
|
|
87
|
+
bump = _this$state.bump,
|
|
88
|
+
debounced = _this$state.debounced,
|
|
89
|
+
silenced = _this$state.silenced;
|
|
90
|
+
this.debounceStatusUpdate();
|
|
91
|
+
return jsx("div", {
|
|
92
|
+
css: assitiveTextStyles
|
|
93
|
+
}, jsx("div", {
|
|
94
|
+
id: id + '__status--A',
|
|
95
|
+
role: "status",
|
|
96
|
+
"aria-atomic": "true",
|
|
97
|
+
"aria-live": "polite"
|
|
98
|
+
}, "".concat(!silenced && debounced && bump ? assistiveText : '')), jsx("div", {
|
|
99
|
+
id: id + '__status--B',
|
|
100
|
+
role: "status",
|
|
101
|
+
"aria-atomic": "true",
|
|
102
|
+
"aria-live": "polite"
|
|
103
|
+
}, "".concat(!silenced && debounced && !bump ? assistiveText : '')));
|
|
104
|
+
}
|
|
105
|
+
}]);
|
|
106
|
+
return AssistveTextComponent;
|
|
107
|
+
}(React.Component);
|
|
108
|
+
_defineProperty(AssistveTextComponent, "defaultProps", {
|
|
109
|
+
statusDebounceMillis: 1400,
|
|
110
|
+
debounce: true,
|
|
111
|
+
assistiveText: '',
|
|
112
|
+
isInFocus: false,
|
|
113
|
+
id: ''
|
|
114
|
+
});
|
|
115
|
+
export var AssistiveText = AssistveTextComponent;
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
/** @jsx jsx */
|
|
3
|
+
import React, { Fragment, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
4
|
+
import { css, jsx } from '@emotion/react';
|
|
5
|
+
import { useIntl } from 'react-intl-next';
|
|
6
|
+
import { keyName as keyNameNormalized } from 'w3c-keyname';
|
|
7
|
+
import { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
|
|
8
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
9
|
+
import { blockNodesVerticalMargin } from '@atlaskit/editor-shared-styles';
|
|
10
|
+
import { CloseSelectionOptions, TYPE_AHEAD_POPUP_CONTENT_CLASS } from '../constants';
|
|
11
|
+
import { TYPE_AHEAD_DECORATION_ELEMENT_ID } from '../constants';
|
|
12
|
+
import { typeAheadListMessages } from '../messages';
|
|
13
|
+
import { getPluginState } from '../utils';
|
|
14
|
+
import { AssistiveText } from './AssistiveText';
|
|
15
|
+
var querySpanStyles = css({
|
|
16
|
+
outline: 'none',
|
|
17
|
+
'& input': {
|
|
18
|
+
width: '5px',
|
|
19
|
+
border: 'none',
|
|
20
|
+
background: 'transparent',
|
|
21
|
+
padding: 0,
|
|
22
|
+
margin: 0,
|
|
23
|
+
// ED-17022 Fixes firefox caret position
|
|
24
|
+
fontSize: '1em',
|
|
25
|
+
height: blockNodesVerticalMargin,
|
|
26
|
+
caretColor: "var(--ds-text-accent-blue, #0052CC)"
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var isNavigationKey = function isNavigationKey(event) {
|
|
30
|
+
return ['Enter', 'Tab', 'ArrowDown', 'ArrowUp'].includes(event.key);
|
|
31
|
+
};
|
|
32
|
+
var isUndoRedoShortcut = function isUndoRedoShortcut(event) {
|
|
33
|
+
var key = keyNameNormalized(event);
|
|
34
|
+
if (event.ctrlKey && key === 'y') {
|
|
35
|
+
return 'historyRedo';
|
|
36
|
+
}
|
|
37
|
+
if ((event.ctrlKey || event.metaKey) && event.shiftKey && key === 'Z') {
|
|
38
|
+
return 'historyRedo';
|
|
39
|
+
}
|
|
40
|
+
if ((event.ctrlKey || event.metaKey) && key === 'z') {
|
|
41
|
+
return 'historyUndo';
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
var getAriaLabel = function getAriaLabel(triggerPrefix, intl) {
|
|
46
|
+
switch (triggerPrefix) {
|
|
47
|
+
case '@':
|
|
48
|
+
return typeAheadListMessages.mentionInputLabel;
|
|
49
|
+
case '/':
|
|
50
|
+
return typeAheadListMessages.quickInsertInputLabel;
|
|
51
|
+
case ':':
|
|
52
|
+
return typeAheadListMessages.emojiInputLabel;
|
|
53
|
+
default:
|
|
54
|
+
return typeAheadListMessages.quickInsertInputLabel;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export var InputQuery = /*#__PURE__*/React.memo(function (_ref) {
|
|
58
|
+
var triggerQueryPrefix = _ref.triggerQueryPrefix,
|
|
59
|
+
cancel = _ref.cancel,
|
|
60
|
+
onQueryChange = _ref.onQueryChange,
|
|
61
|
+
onItemSelect = _ref.onItemSelect,
|
|
62
|
+
selectNextItem = _ref.selectNextItem,
|
|
63
|
+
selectPreviousItem = _ref.selectPreviousItem,
|
|
64
|
+
forceFocus = _ref.forceFocus,
|
|
65
|
+
reopenQuery = _ref.reopenQuery,
|
|
66
|
+
onQueryFocus = _ref.onQueryFocus,
|
|
67
|
+
onUndoRedo = _ref.onUndoRedo,
|
|
68
|
+
editorView = _ref.editorView,
|
|
69
|
+
items = _ref.items;
|
|
70
|
+
var ref = useRef(document.createElement('span'));
|
|
71
|
+
var inputRef = useRef(null);
|
|
72
|
+
var _useState = useState(null),
|
|
73
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
74
|
+
query = _useState2[0],
|
|
75
|
+
setQuery = _useState2[1];
|
|
76
|
+
var cleanedInputContent = useCallback(function () {
|
|
77
|
+
var _ref$current;
|
|
78
|
+
var raw = ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.textContent) || '';
|
|
79
|
+
return raw;
|
|
80
|
+
}, []);
|
|
81
|
+
var onKeyUp = useCallback(function (event) {
|
|
82
|
+
var text = cleanedInputContent();
|
|
83
|
+
onQueryChange(text);
|
|
84
|
+
}, [onQueryChange, cleanedInputContent]);
|
|
85
|
+
var _useState3 = useState(false),
|
|
86
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
87
|
+
isInFocus = _useState4[0],
|
|
88
|
+
setInFocus = _useState4[1];
|
|
89
|
+
var checkKeyEvent = useCallback(function (event) {
|
|
90
|
+
var _ref$current2;
|
|
91
|
+
var key = keyNameNormalized(event);
|
|
92
|
+
var sel = document.getSelection();
|
|
93
|
+
var raw = ((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.textContent) || '';
|
|
94
|
+
var text = cleanedInputContent();
|
|
95
|
+
var stopDefault = false;
|
|
96
|
+
var _ref2 = getPluginState(editorView.state) || {},
|
|
97
|
+
selectedIndex = _ref2.selectedIndex;
|
|
98
|
+
setInFocus(true);
|
|
99
|
+
switch (key) {
|
|
100
|
+
case ' ':
|
|
101
|
+
// space key
|
|
102
|
+
if (text.length === 0) {
|
|
103
|
+
cancel({
|
|
104
|
+
forceFocusOnEditor: true,
|
|
105
|
+
text: ' ',
|
|
106
|
+
addPrefixTrigger: true,
|
|
107
|
+
setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED
|
|
108
|
+
});
|
|
109
|
+
stopDefault = true;
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
case 'Escape':
|
|
113
|
+
case 'PageUp':
|
|
114
|
+
case 'PageDown':
|
|
115
|
+
case 'Home':
|
|
116
|
+
cancel({
|
|
117
|
+
text: text,
|
|
118
|
+
forceFocusOnEditor: true,
|
|
119
|
+
addPrefixTrigger: true,
|
|
120
|
+
setSelectionAt: CloseSelectionOptions.AFTER_TEXT_INSERTED
|
|
121
|
+
});
|
|
122
|
+
stopDefault = true;
|
|
123
|
+
break;
|
|
124
|
+
case 'Backspace':
|
|
125
|
+
if (raw.length === 0 || (sel === null || sel === void 0 ? void 0 : sel.anchorOffset) === 0) {
|
|
126
|
+
event.stopPropagation();
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
cancel({
|
|
129
|
+
forceFocusOnEditor: true,
|
|
130
|
+
text: text,
|
|
131
|
+
addPrefixTrigger: false,
|
|
132
|
+
setSelectionAt: CloseSelectionOptions.BEFORE_TEXT_INSERTED
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case 'Enter':
|
|
137
|
+
// ED-14758 - Under the W3C specification, any keycode sent under IME would return a keycode 229
|
|
138
|
+
// event.isComposing can't be used alone as this also included a virtual keyboard under a keyboardless device, therefore, it seems the best practice would be intercepting the event as below.
|
|
139
|
+
// Some suggested the other workaround maybe listen on`keypress` instead of `keydown`
|
|
140
|
+
if (!event.isComposing && event.which !== 229 && event.keyCode !== 229) {
|
|
141
|
+
if (selectedIndex === -1) {
|
|
142
|
+
/**
|
|
143
|
+
* TODO DTR-1401: (also see ED-17200) There are two options
|
|
144
|
+
* here, either
|
|
145
|
+
* - set the index directly to 1 in WrapperTypeAhead.tsx's
|
|
146
|
+
* `insertSelectedItem` at the cost of breaking some of the a11y
|
|
147
|
+
* focus changes,
|
|
148
|
+
* - or do this jank at the cost of some small analytics noise.
|
|
149
|
+
*
|
|
150
|
+
* The focus behaviour still needs cleanup
|
|
151
|
+
*/
|
|
152
|
+
selectPreviousItem();
|
|
153
|
+
selectNextItem();
|
|
154
|
+
}
|
|
155
|
+
onItemSelect(event.shiftKey ? SelectItemMode.SHIFT_ENTER : SelectItemMode.ENTER);
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
158
|
+
case 'Tab':
|
|
159
|
+
if (selectedIndex === -1) {
|
|
160
|
+
/**
|
|
161
|
+
* TODO DTR-1401: (also see ED-17200) There are two options
|
|
162
|
+
* here, either
|
|
163
|
+
* - set the index directly to 1 in WrapperTypeAhead.tsx's
|
|
164
|
+
* `insertSelectedItem` at the cost of breaking some of the a11y
|
|
165
|
+
* focus changes,
|
|
166
|
+
* - or do this jank at the cost of some small analytics noise.
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
selectPreviousItem();
|
|
170
|
+
selectNextItem();
|
|
171
|
+
}
|
|
172
|
+
// TODO DTR-1401: why is this calling select item when hitting tab? fix this in DTR-1401
|
|
173
|
+
onItemSelect(SelectItemMode.TAB);
|
|
174
|
+
break;
|
|
175
|
+
case 'ArrowDown':
|
|
176
|
+
selectNextItem();
|
|
177
|
+
break;
|
|
178
|
+
case 'ArrowUp':
|
|
179
|
+
selectPreviousItem();
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
var undoRedoType = isUndoRedoShortcut(event);
|
|
183
|
+
if (onUndoRedo && undoRedoType && onUndoRedo(undoRedoType)) {
|
|
184
|
+
stopDefault = true;
|
|
185
|
+
}
|
|
186
|
+
if (isNavigationKey(event) || stopDefault) {
|
|
187
|
+
event.stopPropagation();
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}, [onUndoRedo, onItemSelect, selectNextItem, selectPreviousItem, cancel, cleanedInputContent, editorView.state]);
|
|
192
|
+
var onClick = useCallback(function (event) {
|
|
193
|
+
var _inputRef$current;
|
|
194
|
+
event.stopPropagation();
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
onQueryFocus();
|
|
197
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
198
|
+
return false;
|
|
199
|
+
}, [onQueryFocus]);
|
|
200
|
+
useLayoutEffect(function () {
|
|
201
|
+
if (!ref.current) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
var element = ref.current;
|
|
205
|
+
var onFocusIn = function onFocusIn(event) {
|
|
206
|
+
onQueryFocus();
|
|
207
|
+
};
|
|
208
|
+
var keyDown = function keyDown(event) {
|
|
209
|
+
var key = keyNameNormalized(event);
|
|
210
|
+
if (['ArrowLeft', 'ArrowRight'].includes(key) && document.getSelection && document.getSelection()) {
|
|
211
|
+
var _ref$current3;
|
|
212
|
+
var q = ((_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.textContent) || '';
|
|
213
|
+
var sel = document.getSelection();
|
|
214
|
+
var isMovingRight = sel && 'ArrowRight' === key && sel.anchorOffset === q.length;
|
|
215
|
+
var isMovingLeft = sel && 'ArrowLeft' === key && (sel.anchorOffset === 0 || event.metaKey);
|
|
216
|
+
if (!isMovingRight && !isMovingLeft) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
cancel({
|
|
220
|
+
forceFocusOnEditor: true,
|
|
221
|
+
addPrefixTrigger: true,
|
|
222
|
+
text: cleanedInputContent(),
|
|
223
|
+
setSelectionAt: isMovingRight ? CloseSelectionOptions.AFTER_TEXT_INSERTED : CloseSelectionOptions.BEFORE_TEXT_INSERTED
|
|
224
|
+
});
|
|
225
|
+
event.preventDefault();
|
|
226
|
+
event.stopPropagation();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
checkKeyEvent(event);
|
|
230
|
+
};
|
|
231
|
+
var onFocusOut = function onFocusOut(event) {
|
|
232
|
+
var _window$getSelection;
|
|
233
|
+
var relatedTarget = event.relatedTarget;
|
|
234
|
+
|
|
235
|
+
// Given the user is changing the focus
|
|
236
|
+
// When the target is inside the TypeAhead Popup
|
|
237
|
+
// Then the popup should stay open
|
|
238
|
+
if (relatedTarget instanceof HTMLElement && relatedTarget.closest && relatedTarget.closest(".".concat(TYPE_AHEAD_POPUP_CONTENT_CLASS))) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// See ED-14909: Chrome may emit focusout events where an input
|
|
243
|
+
// device was not directly responsible. (This rears in react v17+ consumers
|
|
244
|
+
// where react-managed node removal now appears to propagate focusout events to
|
|
245
|
+
// our event listener). As this path is strictly for click or other typeahead
|
|
246
|
+
// dismissals that don't involve typeahead item selection, we carve out an
|
|
247
|
+
// exception for Chrome-specific events where an input device was not the initiator.
|
|
248
|
+
if (browser.chrome && !(((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.type) === 'Range') && !('sourceCapabilities' in event && event.sourceCapabilities)) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
cancel({
|
|
252
|
+
addPrefixTrigger: true,
|
|
253
|
+
text: cleanedInputContent(),
|
|
254
|
+
setSelectionAt: CloseSelectionOptions.BEFORE_TEXT_INSERTED,
|
|
255
|
+
forceFocusOnEditor: false
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
var close = function close() {
|
|
259
|
+
cancel({
|
|
260
|
+
addPrefixTrigger: false,
|
|
261
|
+
text: '',
|
|
262
|
+
forceFocusOnEditor: true,
|
|
263
|
+
setSelectionAt: CloseSelectionOptions.BEFORE_TEXT_INSERTED
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
var beforeinput = function beforeinput(e) {
|
|
267
|
+
var _target$textContent;
|
|
268
|
+
setInFocus(false);
|
|
269
|
+
var target = e.target;
|
|
270
|
+
if (e.isComposing || !(target instanceof HTMLElement)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (e.inputType === 'historyUndo' && ((_target$textContent = target.textContent) === null || _target$textContent === void 0 ? void 0 : _target$textContent.length) === 0) {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
e.stopPropagation();
|
|
276
|
+
close();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (e.data != null && inputRef.current === null) {
|
|
280
|
+
setQuery('');
|
|
281
|
+
|
|
282
|
+
// We need to change the content on Safari
|
|
283
|
+
// and set the cursor at the right place
|
|
284
|
+
if (browser.safari) {
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
var dataElement = document.createTextNode(e.data);
|
|
287
|
+
element.appendChild(dataElement);
|
|
288
|
+
var sel = window.getSelection();
|
|
289
|
+
var range = document.createRange();
|
|
290
|
+
range.setStart(dataElement, dataElement.length);
|
|
291
|
+
range.collapse(true);
|
|
292
|
+
sel === null || sel === void 0 || sel.removeAllRanges();
|
|
293
|
+
sel === null || sel === void 0 || sel.addRange(range);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
var onInput = null;
|
|
298
|
+
if (browser.safari) {
|
|
299
|
+
// On Safari, for reasons beyond my understanding,
|
|
300
|
+
// The undo behavior is totally different from other browsers
|
|
301
|
+
// That why we need to have an specific branch only for Safari.
|
|
302
|
+
var _onInput = function _onInput(e) {
|
|
303
|
+
var _target$textContent2;
|
|
304
|
+
var target = e.target;
|
|
305
|
+
if (e.isComposing || !(target instanceof HTMLElement)) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (e.inputType === 'historyUndo' && ((_target$textContent2 = target.textContent) === null || _target$textContent2 === void 0 ? void 0 : _target$textContent2.length) === 1) {
|
|
309
|
+
e.preventDefault();
|
|
310
|
+
e.stopPropagation();
|
|
311
|
+
close();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
element.addEventListener('input', _onInput);
|
|
316
|
+
}
|
|
317
|
+
element.addEventListener('focusout', onFocusOut);
|
|
318
|
+
element.addEventListener('focusin', onFocusIn);
|
|
319
|
+
element.addEventListener('keydown', keyDown);
|
|
320
|
+
element.addEventListener('beforeinput', beforeinput);
|
|
321
|
+
return function () {
|
|
322
|
+
element.removeEventListener('focusout', onFocusOut);
|
|
323
|
+
element.removeEventListener('focusin', onFocusIn);
|
|
324
|
+
element.removeEventListener('keydown', keyDown);
|
|
325
|
+
element.removeEventListener('beforeinput', beforeinput);
|
|
326
|
+
if (browser.safari) {
|
|
327
|
+
element.removeEventListener('input', onInput);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}, [triggerQueryPrefix, cleanedInputContent, onQueryFocus, cancel, checkKeyEvent, editorView.state]);
|
|
331
|
+
useLayoutEffect(function () {
|
|
332
|
+
var hasReopenQuery = typeof reopenQuery === 'string' && reopenQuery.trim().length > 0;
|
|
333
|
+
if (ref.current && forceFocus) {
|
|
334
|
+
setQuery(hasReopenQuery ? reopenQuery : null);
|
|
335
|
+
requestAnimationFrame(function () {
|
|
336
|
+
if (!(ref !== null && ref !== void 0 && ref.current)) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
var sel = window.getSelection();
|
|
340
|
+
if (sel && hasReopenQuery && ref.current.lastChild instanceof Text) {
|
|
341
|
+
var lastChild = ref.current.lastChild;
|
|
342
|
+
var range = document.createRange();
|
|
343
|
+
range.setStart(ref.current.lastChild, lastChild.length);
|
|
344
|
+
range.collapse(true);
|
|
345
|
+
sel.removeAllRanges();
|
|
346
|
+
sel.addRange(range);
|
|
347
|
+
}
|
|
348
|
+
ref.current.focus();
|
|
349
|
+
setInFocus(true);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}, [forceFocus, reopenQuery]);
|
|
353
|
+
var assistiveHintID = TYPE_AHEAD_DECORATION_ELEMENT_ID + '__assistiveHint';
|
|
354
|
+
var intl = useIntl();
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
When we migrated to emotion from styled component, we started getting this error.
|
|
358
|
+
jsx-a11y/interactive-supports-focus
|
|
359
|
+
Task added in https://product-fabric.atlassian.net/wiki/spaces/E/pages/3182068181/Potential+improvements#Moderate-changes.
|
|
360
|
+
*/
|
|
361
|
+
return jsx(Fragment, null, triggerQueryPrefix, jsx("span", {
|
|
362
|
+
css: querySpanStyles,
|
|
363
|
+
contentEditable: true,
|
|
364
|
+
ref: ref,
|
|
365
|
+
onKeyUp: onKeyUp,
|
|
366
|
+
onClick: onClick,
|
|
367
|
+
role: "combobox",
|
|
368
|
+
"aria-controls": TYPE_AHEAD_DECORATION_ELEMENT_ID,
|
|
369
|
+
"aria-autocomplete": "list",
|
|
370
|
+
"aria-expanded": items.length !== 0,
|
|
371
|
+
"aria-labelledby": assistiveHintID,
|
|
372
|
+
suppressContentEditableWarning: true,
|
|
373
|
+
"data-query-prefix": triggerQueryPrefix
|
|
374
|
+
}, query === null ? jsx("input", {
|
|
375
|
+
ref: inputRef,
|
|
376
|
+
type: "text"
|
|
377
|
+
}) : query), jsx("span", {
|
|
378
|
+
id: assistiveHintID,
|
|
379
|
+
style: {
|
|
380
|
+
display: 'none'
|
|
381
|
+
}
|
|
382
|
+
}, intl.formatMessage(getAriaLabel(triggerQueryPrefix, intl)), ",", intl.formatMessage(typeAheadListMessages.inputQueryAssistiveLabel)), jsx(AssistiveText, {
|
|
383
|
+
assistiveText: items.length === 0 ? intl.formatMessage(typeAheadListMessages.noSearchResultsLabel, {
|
|
384
|
+
itemsLength: items.length
|
|
385
|
+
}) : '',
|
|
386
|
+
isInFocus: items.length === 0 || isInFocus,
|
|
387
|
+
id: TYPE_AHEAD_DECORATION_ELEMENT_ID
|
|
388
|
+
}));
|
|
389
|
+
});
|
|
390
|
+
InputQuery.displayName = 'InputQuery';
|