@atlaskit/quick-search 8.0.9
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/CHANGELOG.md +763 -0
- package/LICENSE +13 -0
- package/build/tsconfig.json +17 -0
- package/dist/cjs/components/QuickSearch.js +447 -0
- package/dist/cjs/components/ResultItem/ResultItem.js +87 -0
- package/dist/cjs/components/ResultItem/ResultItemGroup.js +57 -0
- package/dist/cjs/components/ResultItem/styled.js +53 -0
- package/dist/cjs/components/Results/ContainerResult.js +93 -0
- package/dist/cjs/components/Results/ObjectResult.js +108 -0
- package/dist/cjs/components/Results/PersonResult.js +99 -0
- package/dist/cjs/components/Results/ResultBase.js +206 -0
- package/dist/cjs/components/Results/index.js +39 -0
- package/dist/cjs/components/Results/types.js +5 -0
- package/dist/cjs/components/Search/Search.js +124 -0
- package/dist/cjs/components/Search/styled.js +61 -0
- package/dist/cjs/components/constants.js +20 -0
- package/dist/cjs/components/context.js +29 -0
- package/dist/cjs/components/decorateWithAnalyticsData.js +80 -0
- package/dist/cjs/components/isReactElement.js +19 -0
- package/dist/cjs/index.js +94 -0
- package/dist/cjs/version.json +4 -0
- package/dist/es2019/components/QuickSearch.js +417 -0
- package/dist/es2019/components/ResultItem/ResultItem.js +41 -0
- package/dist/es2019/components/ResultItem/ResultItemGroup.js +16 -0
- package/dist/es2019/components/ResultItem/styled.js +54 -0
- package/dist/es2019/components/Results/ContainerResult.js +45 -0
- package/dist/es2019/components/Results/ObjectResult.js +60 -0
- package/dist/es2019/components/Results/PersonResult.js +50 -0
- package/dist/es2019/components/Results/ResultBase.js +149 -0
- package/dist/es2019/components/Results/index.js +4 -0
- package/dist/es2019/components/Results/types.js +1 -0
- package/dist/es2019/components/Search/Search.js +80 -0
- package/dist/es2019/components/Search/styled.js +76 -0
- package/dist/es2019/components/constants.js +7 -0
- package/dist/es2019/components/context.js +11 -0
- package/dist/es2019/components/decorateWithAnalyticsData.js +33 -0
- package/dist/es2019/components/isReactElement.js +10 -0
- package/dist/es2019/index.js +23 -0
- package/dist/es2019/version.json +4 -0
- package/dist/esm/components/QuickSearch.js +442 -0
- package/dist/esm/components/ResultItem/ResultItem.js +65 -0
- package/dist/esm/components/ResultItem/ResultItemGroup.js +42 -0
- package/dist/esm/components/ResultItem/styled.js +18 -0
- package/dist/esm/components/Results/ContainerResult.js +78 -0
- package/dist/esm/components/Results/ObjectResult.js +93 -0
- package/dist/esm/components/Results/PersonResult.js +86 -0
- package/dist/esm/components/Results/ResultBase.js +189 -0
- package/dist/esm/components/Results/index.js +4 -0
- package/dist/esm/components/Results/types.js +1 -0
- package/dist/esm/components/Search/Search.js +108 -0
- package/dist/esm/components/Search/styled.js +20 -0
- package/dist/esm/components/constants.js +7 -0
- package/dist/esm/components/context.js +13 -0
- package/dist/esm/components/decorateWithAnalyticsData.js +64 -0
- package/dist/esm/components/isReactElement.js +10 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/version.json +4 -0
- package/dist/types/components/QuickSearch.d.ts +122 -0
- package/dist/types/components/ResultItem/ResultItem.d.ts +38 -0
- package/dist/types/components/ResultItem/ResultItemGroup.d.ts +11 -0
- package/dist/types/components/ResultItem/styled.d.ts +13 -0
- package/dist/types/components/Results/ContainerResult.d.ts +19 -0
- package/dist/types/components/Results/ObjectResult.d.ts +22 -0
- package/dist/types/components/Results/PersonResult.d.ts +20 -0
- package/dist/types/components/Results/ResultBase.d.ts +37 -0
- package/dist/types/components/Results/index.d.ts +4 -0
- package/dist/types/components/Results/types.d.ts +34 -0
- package/dist/types/components/Search/Search.d.ts +31 -0
- package/dist/types/components/Search/styled.d.ts +10 -0
- package/dist/types/components/constants.d.ts +6 -0
- package/dist/types/components/context.d.ts +22 -0
- package/dist/types/components/decorateWithAnalyticsData.d.ts +3 -0
- package/dist/types/components/isReactElement.d.ts +6 -0
- package/dist/types/index.d.ts +17 -0
- package/docs/0-intro.tsx +53 -0
- package/package.json +52 -0
- package/tsconfig.json +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2019 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"target": "es5",
|
|
6
|
+
"paths": {}
|
|
7
|
+
},
|
|
8
|
+
"include": [
|
|
9
|
+
"../src/**/*.ts",
|
|
10
|
+
"../src/**/*.tsx"
|
|
11
|
+
],
|
|
12
|
+
"exclude": [
|
|
13
|
+
"../src/**/__tests__/*",
|
|
14
|
+
"../src/**/*.test.*",
|
|
15
|
+
"../src/**/test.*"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = exports.QuickSearch = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
+
|
|
16
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
+
|
|
18
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
+
|
|
20
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
+
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
+
|
|
24
|
+
var _react = _interopRequireDefault(require("react"));
|
|
25
|
+
|
|
26
|
+
var _keycode = _interopRequireDefault(require("keycode"));
|
|
27
|
+
|
|
28
|
+
var _analytics = require("@atlaskit/analytics");
|
|
29
|
+
|
|
30
|
+
var _Search = _interopRequireDefault(require("./Search/Search"));
|
|
31
|
+
|
|
32
|
+
var _context = require("./context");
|
|
33
|
+
|
|
34
|
+
var _decorateWithAnalyticsData = _interopRequireDefault(require("./decorateWithAnalyticsData"));
|
|
35
|
+
|
|
36
|
+
var _constants = require("./constants");
|
|
37
|
+
|
|
38
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
39
|
+
|
|
40
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
41
|
+
|
|
42
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
43
|
+
|
|
44
|
+
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; } }
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the result ID of a result by its index in the flatResults array
|
|
48
|
+
* Returns null for a failed index or if resultId is empty|undefined
|
|
49
|
+
*/
|
|
50
|
+
var getResultIdByIndex = function getResultIdByIndex(array, index) {
|
|
51
|
+
if (array && index !== null && array[index] && array[index].props && array[index].props.resultId) {
|
|
52
|
+
return array[index].props.resultId;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Find a result in the flatResults array by its ID
|
|
59
|
+
* Returns the result object or null
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
var getResultById = function getResultById(array, id) {
|
|
64
|
+
return array && array.find(function (result) {
|
|
65
|
+
return result.props && result.props.resultId === id;
|
|
66
|
+
}) || null;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Get a result's index in the flatResults array by its ID
|
|
70
|
+
* Returns a numeric index or null
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
var getResultIndexById = function getResultIndexById(array, id) {
|
|
75
|
+
if (!array) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var result = getResultById(array, id);
|
|
80
|
+
|
|
81
|
+
if (!result) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var index = array.indexOf(result);
|
|
86
|
+
return index >= 0 ? index : null;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var adjustIndex = function adjustIndex(arrayLength, currentIndex, adjustment) {
|
|
90
|
+
if (arrayLength === 0) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (adjustment === 0) {
|
|
95
|
+
return currentIndex;
|
|
96
|
+
} // If nothing is selected, select the element on the end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
if (currentIndex === null) {
|
|
100
|
+
return adjustment > 0 ? 0 : arrayLength - 1;
|
|
101
|
+
} // Adjust current index, wrapping around if necessary
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
var adjustedIndex = (currentIndex + adjustment) % arrayLength; // Correct for negative indices
|
|
105
|
+
|
|
106
|
+
return adjustedIndex >= 0 ? adjustedIndex : adjustedIndex + arrayLength;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var QuickSearch = /*#__PURE__*/function (_React$Component) {
|
|
110
|
+
(0, _inherits2.default)(QuickSearch, _React$Component);
|
|
111
|
+
|
|
112
|
+
var _super = _createSuper(QuickSearch);
|
|
113
|
+
|
|
114
|
+
function QuickSearch(props) {
|
|
115
|
+
var _this;
|
|
116
|
+
|
|
117
|
+
(0, _classCallCheck2.default)(this, QuickSearch);
|
|
118
|
+
_this = _super.call(this, props);
|
|
119
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "flatResults", []);
|
|
120
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hasSearchQueryEventFired", false);
|
|
121
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "hasKeyDownEventFired", false);
|
|
122
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "lastKeyPressed", '');
|
|
123
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "adjustSelectedResultIndex", function (adjustment) {
|
|
124
|
+
var currentIndex = getResultIndexById(_this.flatResults, _this.state.selectedResultId);
|
|
125
|
+
var newIndex = adjustIndex(_this.flatResults.length, currentIndex, adjustment);
|
|
126
|
+
var selectedResultId = getResultIdByIndex(_this.flatResults, newIndex);
|
|
127
|
+
|
|
128
|
+
_this.setState({
|
|
129
|
+
selectedResultId: selectedResultId
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (selectedResultId) {
|
|
133
|
+
_this.fireKeyboardControlEvent(selectedResultId);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (_this.props.onSelectedResultIdChanged) {
|
|
137
|
+
_this.props.onSelectedResultIdChanged(selectedResultId);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectNext", function () {
|
|
141
|
+
_this.adjustSelectedResultIndex(+1);
|
|
142
|
+
});
|
|
143
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectPrevious", function () {
|
|
144
|
+
_this.adjustSelectedResultIndex(-1);
|
|
145
|
+
});
|
|
146
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleRegisterResult", function (result) {
|
|
147
|
+
if (!getResultById(_this.flatResults, result.props.resultId)) {
|
|
148
|
+
_this.flatResults.push(result);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleUnregisterResult", function (result) {
|
|
152
|
+
var resultIndex = getResultIndexById(_this.flatResults, result.props.resultId);
|
|
153
|
+
|
|
154
|
+
if (resultIndex !== null && +resultIndex >= 0) {
|
|
155
|
+
_this.flatResults.splice(resultIndex, 1);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleResultMouseEnter", function (resultData) {
|
|
159
|
+
_this.setState({
|
|
160
|
+
selectedResultId: resultData && resultData.resultId
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleResultMouseLeave", function () {
|
|
164
|
+
_this.setState({
|
|
165
|
+
selectedResultId: null
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSearchBlur", function (event) {
|
|
169
|
+
_this.props.onSearchBlur(event);
|
|
170
|
+
|
|
171
|
+
_this.setState({
|
|
172
|
+
selectedResultId: null
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onInput", function (event) {
|
|
176
|
+
var onSearchInput = _this.props.onSearchInput;
|
|
177
|
+
|
|
178
|
+
_this.setState({
|
|
179
|
+
value: event.currentTarget.value
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
if (onSearchInput) {
|
|
183
|
+
onSearchInput(event);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSearchKeyDown", function (event) {
|
|
187
|
+
var firePrivateAnalyticsEvent = _this.props.firePrivateAnalyticsEvent;
|
|
188
|
+
|
|
189
|
+
_this.props.onSearchKeyDown(event);
|
|
190
|
+
|
|
191
|
+
_this.lastKeyPressed = event.key; // Need to check for keyCode for up/down/enter in case user is composing using an IME
|
|
192
|
+
// fixes https://ecosystem.atlassian.net/browse/DS-6518
|
|
193
|
+
|
|
194
|
+
if (event.key === 'ArrowUp' && event.keyCode === (0, _keycode.default)('up')) {
|
|
195
|
+
event.preventDefault(); // Don't move cursor around in search input field
|
|
196
|
+
|
|
197
|
+
_this.selectPrevious();
|
|
198
|
+
} else if (event.key === 'ArrowDown' && event.keyCode === (0, _keycode.default)('down')) {
|
|
199
|
+
event.preventDefault(); // Don't move cursor around in search input field
|
|
200
|
+
|
|
201
|
+
_this.selectNext();
|
|
202
|
+
} else if (event.key === 'Enter' && event.keyCode === (0, _keycode.default)('enter')) {
|
|
203
|
+
// shift key pressed or no result selected
|
|
204
|
+
if (event.shiftKey || !_this.state.selectedResultId) {
|
|
205
|
+
if (firePrivateAnalyticsEvent) {
|
|
206
|
+
firePrivateAnalyticsEvent(_constants.QS_ANALYTICS_EV_SUBMIT, {
|
|
207
|
+
newTab: false,
|
|
208
|
+
// enter always open in the same tab
|
|
209
|
+
resultCount: _this.flatResults.length,
|
|
210
|
+
method: 'shortcut'
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
_this.props.onSearchSubmit(event);
|
|
215
|
+
} else {
|
|
216
|
+
event.preventDefault(); // Don't fire submit event from input
|
|
217
|
+
|
|
218
|
+
var result = getResultById(_this.flatResults, _this.state.selectedResultId);
|
|
219
|
+
|
|
220
|
+
if (!result || !result.props) {
|
|
221
|
+
return;
|
|
222
|
+
} // Capture when users are using the keyboard to submit
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if (typeof firePrivateAnalyticsEvent === 'function') {
|
|
226
|
+
_this.fireKeyboardControlEvent(_this.state.selectedResultId);
|
|
227
|
+
|
|
228
|
+
firePrivateAnalyticsEvent(_constants.QS_ANALYTICS_EV_SUBMIT, _objectSpread(_objectSpread({}, result.getAnalyticsData()), {}, {
|
|
229
|
+
method: 'returnKey',
|
|
230
|
+
newTab: false,
|
|
231
|
+
// enter always open in the same tab
|
|
232
|
+
resultCount: _this.flatResults.length
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
var _preventDefault = false;
|
|
237
|
+
|
|
238
|
+
if (result.props.onClick) {
|
|
239
|
+
result.props.onClick({
|
|
240
|
+
resultId: result.props.resultId,
|
|
241
|
+
type: result.props.type,
|
|
242
|
+
event: Object.assign({}, event, {
|
|
243
|
+
preventDefault: function preventDefault() {
|
|
244
|
+
_preventDefault = true;
|
|
245
|
+
},
|
|
246
|
+
stopPropagation: function stopPropagation() {}
|
|
247
|
+
})
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (result.props.href && !_preventDefault) {
|
|
252
|
+
window.location.assign(result.props.href);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else if (event.key === 'Tab' || event.key === 'ArrowRight') {
|
|
256
|
+
var autocompleteText = _this.props.autocompleteText;
|
|
257
|
+
|
|
258
|
+
if (autocompleteText && autocompleteText.length > 0 && // multiple Tab or ArrowRight
|
|
259
|
+
autocompleteText.slice(-1) !== ' ') {
|
|
260
|
+
_this.acceptAutocomplete(event, autocompleteText);
|
|
261
|
+
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "acceptAutocomplete", function (event, text) {
|
|
267
|
+
var onSearchInput = _this.props.onSearchInput;
|
|
268
|
+
var newValue = "".concat(text, " ");
|
|
269
|
+
|
|
270
|
+
if (_this.inputSearchRef) {
|
|
271
|
+
_this.setState({
|
|
272
|
+
value: newValue
|
|
273
|
+
}); // @ts-ignore unchecked
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
_this.inputSearchRef.value = newValue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (onSearchInput) {
|
|
280
|
+
onSearchInput(event, true);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setSearchInputRef", function (refs) {
|
|
284
|
+
if (refs && refs.inputRef) {
|
|
285
|
+
_this.inputSearchRef = refs.inputRef;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "focusSearchInput", function () {
|
|
289
|
+
if (_this.inputSearchRef && // @ts-ignore unchecked
|
|
290
|
+
typeof _this.inputSearchRef.focus === 'function') {
|
|
291
|
+
// @ts-ignore unchecked
|
|
292
|
+
_this.inputSearchRef.focus();
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
_this.state = {
|
|
296
|
+
/** Select first result by default if `selectedResultId` prop is not provided */
|
|
297
|
+
selectedResultId: _this.props.selectedResultId || null,
|
|
298
|
+
context: {
|
|
299
|
+
registerResult: _this.handleRegisterResult,
|
|
300
|
+
unregisterResult: _this.handleUnregisterResult,
|
|
301
|
+
onMouseEnter: _this.handleResultMouseEnter,
|
|
302
|
+
onMouseLeave: _this.handleResultMouseLeave,
|
|
303
|
+
sendAnalytics: _this.props.firePrivateAnalyticsEvent,
|
|
304
|
+
getIndex: function getIndex(resultId) {
|
|
305
|
+
return getResultIndexById(_this.flatResults, resultId);
|
|
306
|
+
},
|
|
307
|
+
linkComponent: _this.props.linkComponent
|
|
308
|
+
},
|
|
309
|
+
value: props.value
|
|
310
|
+
};
|
|
311
|
+
return _this;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
(0, _createClass2.default)(QuickSearch, [{
|
|
315
|
+
key: "componentDidMount",
|
|
316
|
+
value: function componentDidMount() {
|
|
317
|
+
var firePrivateAnalyticsEvent = this.props.firePrivateAnalyticsEvent;
|
|
318
|
+
|
|
319
|
+
if (firePrivateAnalyticsEvent) {
|
|
320
|
+
firePrivateAnalyticsEvent(_constants.QS_ANALYTICS_EV_OPEN, {});
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}, {
|
|
324
|
+
key: "componentWillUnmount",
|
|
325
|
+
value: function componentWillUnmount() {
|
|
326
|
+
var firePrivateAnalyticsEvent = this.props.firePrivateAnalyticsEvent;
|
|
327
|
+
|
|
328
|
+
if (firePrivateAnalyticsEvent) {
|
|
329
|
+
firePrivateAnalyticsEvent(_constants.QS_ANALYTICS_EV_CLOSE, {});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}, {
|
|
333
|
+
key: "UNSAFE_componentWillReceiveProps",
|
|
334
|
+
value: function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
335
|
+
if (nextProps.children !== this.props.children) {
|
|
336
|
+
this.setState({
|
|
337
|
+
selectedResultId: nextProps.selectedResultId || null
|
|
338
|
+
});
|
|
339
|
+
} else if (nextProps.selectedResultId !== this.props.selectedResultId && nextProps.selectedResultId !== this.state.selectedResultId) {
|
|
340
|
+
this.setState({
|
|
341
|
+
selectedResultId: nextProps.selectedResultId || null
|
|
342
|
+
});
|
|
343
|
+
} // keep context state in sync
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
var _this$state$context = this.state.context,
|
|
347
|
+
sendAnalytics = _this$state$context.sendAnalytics,
|
|
348
|
+
linkComponent = _this$state$context.linkComponent;
|
|
349
|
+
|
|
350
|
+
if (sendAnalytics !== nextProps.firePrivateAnalyticsEvent || linkComponent !== nextProps.linkComponent) {
|
|
351
|
+
this.setState({
|
|
352
|
+
context: _objectSpread(_objectSpread({}, this.state.context), {}, {
|
|
353
|
+
sendAnalytics: nextProps.firePrivateAnalyticsEvent,
|
|
354
|
+
linkComponent: nextProps.linkComponent
|
|
355
|
+
})
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Capture whether user needed to query in order to find their target result.
|
|
360
|
+
* Only fire once per mount. Only fire when a search term is entered and the previous search
|
|
361
|
+
* term was empty.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
if (!this.hasSearchQueryEventFired && !this.props.value && nextProps.value) {
|
|
366
|
+
this.hasSearchQueryEventFired = true;
|
|
367
|
+
var firePrivateAnalyticsEvent = this.props.firePrivateAnalyticsEvent;
|
|
368
|
+
|
|
369
|
+
if (firePrivateAnalyticsEvent) {
|
|
370
|
+
firePrivateAnalyticsEvent(_constants.QS_ANALYTICS_EV_QUERY_ENTERED, {});
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}, {
|
|
375
|
+
key: "fireKeyboardControlEvent",
|
|
376
|
+
value: function fireKeyboardControlEvent(selectedResultId) {
|
|
377
|
+
var firePrivateAnalyticsEvent = this.props.firePrivateAnalyticsEvent;
|
|
378
|
+
|
|
379
|
+
if (firePrivateAnalyticsEvent) {
|
|
380
|
+
var result = getResultById(this.flatResults, selectedResultId);
|
|
381
|
+
|
|
382
|
+
if (result) {
|
|
383
|
+
firePrivateAnalyticsEvent(_constants.QS_ANALYTICS_EV_KB_CTRLS_USED, _objectSpread(_objectSpread({}, result.getAnalyticsData()), {}, {
|
|
384
|
+
key: this.lastKeyPressed,
|
|
385
|
+
resultCount: this.flatResults.length
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
this.lastKeyPressed = '';
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Uses the virtual list, this.flatResults, to move the selection across grouped results as if
|
|
394
|
+
* results were in a single, circular list.
|
|
395
|
+
*
|
|
396
|
+
* Process:
|
|
397
|
+
* 1. Finds the index of the selected result in the flatResults array,
|
|
398
|
+
* 2. Increments or decrements this index by the supplied adjustment amount,
|
|
399
|
+
* 3. Sets the new selectedResultId based on the modifed index
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
}, {
|
|
403
|
+
key: "render",
|
|
404
|
+
value: function render() {
|
|
405
|
+
return /*#__PURE__*/_react.default.createElement(_Search.default, {
|
|
406
|
+
isLoading: this.props.isLoading,
|
|
407
|
+
inputControls: this.props.inputControls,
|
|
408
|
+
onBlur: this.handleSearchBlur,
|
|
409
|
+
onInput: this.onInput,
|
|
410
|
+
onKeyDown: this.handleSearchKeyDown,
|
|
411
|
+
placeholder: this.props.placeholder,
|
|
412
|
+
value: this.state.value,
|
|
413
|
+
autocompleteText: this.props.autocompleteText,
|
|
414
|
+
ref: this.setSearchInputRef
|
|
415
|
+
}, /*#__PURE__*/_react.default.createElement(_context.ResultContext.Provider, {
|
|
416
|
+
value: this.state.context
|
|
417
|
+
}, /*#__PURE__*/_react.default.createElement(_context.SelectedResultIdContext.Provider, {
|
|
418
|
+
value: this.state.selectedResultId
|
|
419
|
+
}, this.props.children)));
|
|
420
|
+
}
|
|
421
|
+
}]);
|
|
422
|
+
return QuickSearch;
|
|
423
|
+
}(_react.default.Component);
|
|
424
|
+
/**
|
|
425
|
+
* HOCs:
|
|
426
|
+
* `decorateWithAnalyticsData` - Wrapper that decorates analytics events with additional data.
|
|
427
|
+
* `withAnalytics` - Injects analytics firing methods that are picked up by
|
|
428
|
+
* @atlaskit/analytics/AnalyticsListener.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
exports.QuickSearch = QuickSearch;
|
|
433
|
+
(0, _defineProperty2.default)(QuickSearch, "defaultProps", {
|
|
434
|
+
children: [],
|
|
435
|
+
firePrivateAnalyticsEvent: function firePrivateAnalyticsEvent(_) {},
|
|
436
|
+
isLoading: false,
|
|
437
|
+
onSearchBlur: function onSearchBlur(_) {},
|
|
438
|
+
onSearchKeyDown: function onSearchKeyDown(_) {},
|
|
439
|
+
onSearchSubmit: function onSearchSubmit(_) {},
|
|
440
|
+
placeholder: 'Search',
|
|
441
|
+
value: ''
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
var _default = (0, _decorateWithAnalyticsData.default)( // @ts-ignore
|
|
445
|
+
(0, _analytics.withAnalytics)(QuickSearch, {}, {}));
|
|
446
|
+
|
|
447
|
+
exports.default = _default;
|