@atlaskit/quick-search 8.0.12 → 8.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/components/QuickSearch.js +26 -91
  4. package/dist/cjs/components/ResultItem/ResultItem.js +0 -22
  5. package/dist/cjs/components/ResultItem/ResultItemGroup.js +2 -20
  6. package/dist/cjs/components/ResultItem/styled.js +4 -27
  7. package/dist/cjs/components/Results/ContainerResult.js +6 -31
  8. package/dist/cjs/components/Results/ObjectResult.js +9 -36
  9. package/dist/cjs/components/Results/PersonResult.js +8 -34
  10. package/dist/cjs/components/Results/ResultBase.js +20 -52
  11. package/dist/cjs/components/Results/index.js +0 -5
  12. package/dist/cjs/components/Search/Search.js +7 -36
  13. package/dist/cjs/components/Search/styled.js +5 -30
  14. package/dist/cjs/components/constants.js +0 -1
  15. package/dist/cjs/components/context.js +0 -7
  16. package/dist/cjs/components/decorateWithAnalyticsData.js +0 -22
  17. package/dist/cjs/components/isReactElement.js +0 -2
  18. package/dist/cjs/index.js +0 -14
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/components/QuickSearch.js +32 -85
  21. package/dist/es2019/components/ResultItem/ResultItem.js +0 -4
  22. package/dist/es2019/components/ResultItem/ResultItemGroup.js +0 -1
  23. package/dist/es2019/components/ResultItem/styled.js +6 -7
  24. package/dist/es2019/components/Results/ContainerResult.js +0 -5
  25. package/dist/es2019/components/Results/ObjectResult.js +0 -8
  26. package/dist/es2019/components/Results/PersonResult.js +0 -7
  27. package/dist/es2019/components/Results/ResultBase.js +2 -16
  28. package/dist/es2019/components/Search/Search.js +0 -9
  29. package/dist/es2019/components/Search/styled.js +5 -6
  30. package/dist/es2019/components/decorateWithAnalyticsData.js +0 -4
  31. package/dist/es2019/index.js +6 -3
  32. package/dist/es2019/version.json +1 -1
  33. package/dist/esm/components/QuickSearch.js +27 -95
  34. package/dist/esm/components/ResultItem/ResultItem.js +0 -11
  35. package/dist/esm/components/ResultItem/ResultItemGroup.js +2 -12
  36. package/dist/esm/components/ResultItem/styled.js +4 -7
  37. package/dist/esm/components/Results/ContainerResult.js +6 -22
  38. package/dist/esm/components/Results/ObjectResult.js +9 -27
  39. package/dist/esm/components/Results/PersonResult.js +8 -27
  40. package/dist/esm/components/Results/ResultBase.js +20 -44
  41. package/dist/esm/components/Search/Search.js +7 -28
  42. package/dist/esm/components/Search/styled.js +5 -8
  43. package/dist/esm/components/decorateWithAnalyticsData.js +0 -13
  44. package/dist/esm/index.js +6 -3
  45. package/dist/esm/version.json +1 -1
  46. package/package.json +9 -8
  47. package/report.api.md +122 -132
  48. package/tmp/api-report-tmp.d.ts +263 -0
@@ -1,61 +1,36 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
8
  exports.getPlaceholderStyle = exports.getPlaceholderColor = exports.SearchInputTypeAhead = exports.SearchInputControlsContainer = exports.SearchInput = exports.SearchInner = exports.SearchFieldBaseOuter = exports.SearchFieldBaseInner = exports.SearchBox = void 0;
11
-
12
9
  var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
13
-
14
10
  var _styledComponents = _interopRequireWildcard(require("styled-components"));
15
-
16
- var _constants = require("@atlaskit/theme/constants");
17
-
18
11
  var _colors = require("@atlaskit/theme/colors");
19
-
20
12
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
21
-
22
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
-
24
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
-
26
- var inputRightPadding = (0, _constants.gridSize)() * 2;
27
-
15
+ var inputRightPadding = "var(--ds-space-200, 16px)";
28
16
  var SearchBox = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n position: sticky;\n top: 0;\n background-color: ", ";\n color: ", ";\n display: flex;\n height: 36px;\n z-index: 10; /* required to keep the search box on top of icons in results when sticky */\n"])), _colors.N0, _colors.N500);
29
-
30
17
  exports.SearchBox = SearchBox;
31
-
32
18
  var SearchFieldBaseOuter = _styledComponents.default.div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n flex: 1;\n margin-right: auto;\n padding-bottom: 2px;\n border-bottom: 2px solid ", ";\n"])), _colors.B200);
33
-
34
19
  exports.SearchFieldBaseOuter = SearchFieldBaseOuter;
35
-
36
- var SearchFieldBaseInner = _styledComponents.default.div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n align-items: center;\n padding-right: ", "px; /* pad search text from FieldBase's isLoading spinner */\n display: flex;\n flex-grow: 1;\n"])), inputRightPadding);
37
-
20
+ var SearchFieldBaseInner = _styledComponents.default.div(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n align-items: center;\n padding-right: ", "; /* pad search text from FieldBase's isLoading spinner */\n display: flex;\n flex-grow: 1;\n"])), inputRightPadding);
38
21
  exports.SearchFieldBaseInner = SearchFieldBaseInner;
39
-
40
- var SearchInner = _styledComponents.default.div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n padding-right: ", "px;\n"])), (0, _constants.gridSize)() * 3);
41
-
22
+ var SearchInner = _styledComponents.default.div(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n padding-right: ", ";\n"])), "var(--ds-space-300, 24px)");
42
23
  exports.SearchInner = SearchInner;
43
-
44
24
  var getPlaceholderStyle = function getPlaceholderStyle(style) {
45
25
  return (0, _styledComponents.css)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n &::-webkit-input-placeholder {\n ", ";\n }\n &::-moz-placeholder {\n /* Mozilla Firefox 19+ */\n ", " opacity: 1;\n }\n &::-ms-input-placeholder {\n /* Microsoft Edge */\n ", ";\n }\n &:-moz-placeholder {\n /* Mozilla Firefox 4 to 18 */\n ", " opacity: 1;\n }\n &:-ms-input-placeholder {\n /* Internet Explorer 10-11 */\n ", ";\n }\n"])), style, style, style, style, style);
46
26
  };
47
-
48
27
  exports.getPlaceholderStyle = getPlaceholderStyle;
49
28
  var getPlaceholderColor = (0, _styledComponents.css)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n color: ", ";\n"])), _colors.placeholderText);
50
29
  exports.getPlaceholderColor = getPlaceholderColor;
51
-
52
30
  var SearchInput = _styledComponents.default.input(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["\n background-color: transparent;\n border: 0;\n color: ", ";\n flex-grow: 1;\n font-size: 1.4em;\n outline: 0;\n // Safari adds 2px margin-left\n margin-left: 0;\n ", ";\n"])), _colors.N500, getPlaceholderStyle(getPlaceholderColor));
53
-
54
31
  exports.SearchInput = SearchInput;
55
- var SearchInputTypeAhead = (0, _styledComponents.default)(SearchInput)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n color: ", ";\n position: absolute;\n width: calc(100% - ", "px);\n z-index: -1;\n"])), _colors.N50, inputRightPadding);
32
+ var SearchInputTypeAhead = (0, _styledComponents.default)(SearchInput)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n color: ", ";\n position: absolute;\n width: calc(100% - ", ");\n z-index: -1;\n"])), _colors.N50, inputRightPadding);
56
33
  exports.SearchInputTypeAhead = SearchInputTypeAhead;
57
-
58
- var SearchInputControlsContainer = _styledComponents.default.span(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n padding-left: ", "px;\n"])), (0, _constants.gridSize)() * 3);
59
-
34
+ var SearchInputControlsContainer = _styledComponents.default.span(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n padding-left: ", ";\n"])), "var(--ds-space-300, 24px)");
60
35
  exports.SearchInputControlsContainer = SearchInputControlsContainer;
61
36
  SearchInputControlsContainer.displayName = 'SearchInputControlsContainer'; // required for testing
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.QS_ANALYTICS_EV_SUBMIT = exports.QS_ANALYTICS_EV_QUERY_ENTERED = exports.QS_ANALYTICS_EV_OPEN = exports.QS_ANALYTICS_EV_KB_CTRLS_USED = exports.QS_ANALYTICS_EV_CLOSE = exports.ATLASKIT_QUICKSEARCH_NS = void 0;
7
-
8
7
  /* eslint-disable import/prefer-default-export */
9
8
  var ATLASKIT_QUICKSEARCH_NS = 'atlaskit.navigation.quick-search';
10
9
  exports.ATLASKIT_QUICKSEARCH_NS = ATLASKIT_QUICKSEARCH_NS;
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.SelectedResultIdContext = exports.ResultContext = void 0;
9
-
10
8
  var _react = _interopRequireDefault(require("react"));
11
-
12
9
  var defaultState = {
13
10
  sendAnalytics: function sendAnalytics() {},
14
11
  onMouseEnter: function onMouseEnter() {},
@@ -19,11 +16,7 @@ var defaultState = {
19
16
  return Number(n);
20
17
  }
21
18
  };
22
-
23
19
  var ResultContext = /*#__PURE__*/_react.default.createContext(defaultState);
24
-
25
20
  exports.ResultContext = ResultContext;
26
-
27
21
  var SelectedResultIdContext = /*#__PURE__*/_react.default.createContext(null);
28
-
29
22
  exports.SelectedResultIdContext = SelectedResultIdContext;
@@ -1,55 +1,34 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = decorateWithAnalyticsData;
9
-
10
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
10
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
-
16
11
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
-
18
12
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
-
20
13
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
-
22
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
-
24
15
  var _react = _interopRequireDefault(require("react"));
25
-
26
16
  var _analytics = require("@atlaskit/analytics");
27
-
28
17
  var _isReactElement = _interopRequireDefault(require("./isReactElement"));
29
-
30
18
  var _constants = require("./constants");
31
-
32
19
  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); }; }
33
-
34
20
  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; } }
35
-
36
21
  function decorateWithAnalyticsData(WrappedQuickSearch) {
37
22
  var _class;
38
-
39
23
  return _class = /*#__PURE__*/function (_React$Component) {
40
24
  (0, _inherits2.default)(DecorateWithAnalyticsData, _React$Component);
41
-
42
25
  var _super = _createSuper(DecorateWithAnalyticsData);
43
-
44
26
  function DecorateWithAnalyticsData() {
45
27
  var _this;
46
-
47
28
  (0, _classCallCheck2.default)(this, DecorateWithAnalyticsData);
48
-
49
29
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
50
30
  args[_key] = arguments[_key];
51
31
  }
52
-
53
32
  _this = _super.call.apply(_super, [this].concat(args));
54
33
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "countChildren", function () {
55
34
  return _react.default.Children.toArray(_this.props.children).reduce(function (total, group) {
@@ -58,7 +37,6 @@ function decorateWithAnalyticsData(WrappedQuickSearch) {
58
37
  });
59
38
  return _this;
60
39
  }
61
-
62
40
  (0, _createClass2.default)(DecorateWithAnalyticsData, [{
63
41
  key: "render",
64
42
  value: function render() {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  /**
9
8
  * Heuristically check whether an element is a react element or not.
10
9
  * React elements have constructors for their type property but native elements use strings.
@@ -15,5 +14,4 @@ var _default = function _default(element) {
15
14
  var hasProps = element && element.props;
16
15
  return hasFunctionAsType && hasProps;
17
16
  };
18
-
19
17
  exports.default = _default;
package/dist/cjs/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
@@ -68,27 +66,15 @@ Object.defineProperty(exports, "ResultItemGroup", {
68
66
  }
69
67
  });
70
68
  exports.quickSearchResultTypes = void 0;
71
-
72
69
  var resultTypes = _interopRequireWildcard(require("./components/Results"));
73
-
74
70
  exports.quickSearchResultTypes = resultTypes;
75
-
76
71
  var _ResultItemGroup = _interopRequireDefault(require("./components/ResultItem/ResultItemGroup"));
77
-
78
72
  var _ResultItem = _interopRequireDefault(require("./components/ResultItem/ResultItem"));
79
-
80
73
  var _QuickSearch = _interopRequireDefault(require("./components/QuickSearch"));
81
-
82
74
  var _Search = _interopRequireDefault(require("./components/Search/Search"));
83
-
84
75
  var _ObjectResult = _interopRequireDefault(require("./components/Results/ObjectResult"));
85
-
86
76
  var _PersonResult = _interopRequireDefault(require("./components/Results/PersonResult"));
87
-
88
77
  var _ContainerResult = _interopRequireDefault(require("./components/Results/ContainerResult"));
89
-
90
78
  var _ResultBase = _interopRequireDefault(require("./components/Results/ResultBase"));
91
-
92
79
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
93
-
94
80
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/quick-search",
3
- "version": "8.0.12"
3
+ "version": "8.0.14"
4
4
  }
@@ -6,7 +6,6 @@ import AkSearch from './Search/Search';
6
6
  import { ResultContext, SelectedResultIdContext } from './context';
7
7
  import decorateWithAnalyticsData from './decorateWithAnalyticsData';
8
8
  import { QS_ANALYTICS_EV_CLOSE, QS_ANALYTICS_EV_KB_CTRLS_USED, QS_ANALYTICS_EV_OPEN, QS_ANALYTICS_EV_QUERY_ENTERED, QS_ANALYTICS_EV_SUBMIT } from './constants';
9
-
10
9
  /**
11
10
  * Get the result ID of a result by its index in the flatResults array
12
11
  * Returns null for a failed index or if resultId is empty|undefined
@@ -15,69 +14,54 @@ const getResultIdByIndex = (array, index) => {
15
14
  if (array && index !== null && array[index] && array[index].props && array[index].props.resultId) {
16
15
  return array[index].props.resultId;
17
16
  }
18
-
19
17
  return null;
20
18
  };
19
+
21
20
  /**
22
21
  * Find a result in the flatResults array by its ID
23
22
  * Returns the result object or null
24
23
  */
25
-
26
-
27
24
  const getResultById = (array, id) => array && array.find(result => result.props && result.props.resultId === id) || null;
25
+
28
26
  /**
29
27
  * Get a result's index in the flatResults array by its ID
30
28
  * Returns a numeric index or null
31
29
  */
32
-
33
-
34
30
  const getResultIndexById = (array, id) => {
35
31
  if (!array) {
36
32
  return null;
37
33
  }
38
-
39
34
  const result = getResultById(array, id);
40
-
41
35
  if (!result) {
42
36
  return null;
43
37
  }
44
-
45
38
  const index = array.indexOf(result);
46
39
  return index >= 0 ? index : null;
47
40
  };
48
-
49
41
  const adjustIndex = (arrayLength, currentIndex, adjustment) => {
50
42
  if (arrayLength === 0) {
51
43
  return null;
52
44
  }
53
-
54
45
  if (adjustment === 0) {
55
46
  return currentIndex;
56
- } // If nothing is selected, select the element on the end
57
-
47
+ }
58
48
 
49
+ // If nothing is selected, select the element on the end
59
50
  if (currentIndex === null) {
60
51
  return adjustment > 0 ? 0 : arrayLength - 1;
61
- } // Adjust current index, wrapping around if necessary
62
-
63
-
64
- const adjustedIndex = (currentIndex + adjustment) % arrayLength; // Correct for negative indices
65
-
52
+ }
53
+ // Adjust current index, wrapping around if necessary
54
+ const adjustedIndex = (currentIndex + adjustment) % arrayLength;
55
+ // Correct for negative indices
66
56
  return adjustedIndex >= 0 ? adjustedIndex : adjustedIndex + arrayLength;
67
57
  };
68
-
69
58
  export class QuickSearch extends React.Component {
70
59
  constructor(props) {
71
60
  super(props);
72
-
73
61
  _defineProperty(this, "flatResults", []);
74
-
75
62
  _defineProperty(this, "hasSearchQueryEventFired", false);
76
-
77
63
  _defineProperty(this, "hasKeyDownEventFired", false);
78
-
79
64
  _defineProperty(this, "lastKeyPressed", '');
80
-
81
65
  _defineProperty(this, "adjustSelectedResultIndex", adjustment => {
82
66
  const currentIndex = getResultIndexById(this.flatResults, this.state.selectedResultId);
83
67
  const newIndex = adjustIndex(this.flatResults.length, currentIndex, adjustment);
@@ -85,57 +69,46 @@ export class QuickSearch extends React.Component {
85
69
  this.setState({
86
70
  selectedResultId
87
71
  });
88
-
89
72
  if (selectedResultId) {
90
73
  this.fireKeyboardControlEvent(selectedResultId);
91
74
  }
92
-
93
75
  if (this.props.onSelectedResultIdChanged) {
94
76
  this.props.onSelectedResultIdChanged(selectedResultId);
95
77
  }
96
78
  });
97
-
98
79
  _defineProperty(this, "selectNext", () => {
99
80
  this.adjustSelectedResultIndex(+1);
100
81
  });
101
-
102
82
  _defineProperty(this, "selectPrevious", () => {
103
83
  this.adjustSelectedResultIndex(-1);
104
84
  });
105
-
106
85
  _defineProperty(this, "handleRegisterResult", result => {
107
86
  if (!getResultById(this.flatResults, result.props.resultId)) {
108
87
  this.flatResults.push(result);
109
88
  }
110
89
  });
111
-
112
90
  _defineProperty(this, "handleUnregisterResult", result => {
113
91
  const resultIndex = getResultIndexById(this.flatResults, result.props.resultId);
114
-
115
92
  if (resultIndex !== null && +resultIndex >= 0) {
116
93
  this.flatResults.splice(resultIndex, 1);
117
94
  }
118
95
  });
119
-
120
96
  _defineProperty(this, "handleResultMouseEnter", resultData => {
121
97
  this.setState({
122
98
  selectedResultId: resultData && resultData.resultId
123
99
  });
124
100
  });
125
-
126
101
  _defineProperty(this, "handleResultMouseLeave", () => {
127
102
  this.setState({
128
103
  selectedResultId: null
129
104
  });
130
105
  });
131
-
132
106
  _defineProperty(this, "handleSearchBlur", event => {
133
107
  this.props.onSearchBlur(event);
134
108
  this.setState({
135
109
  selectedResultId: null
136
110
  });
137
111
  });
138
-
139
112
  _defineProperty(this, "onInput", event => {
140
113
  const {
141
114
  onSearchInput
@@ -143,27 +116,24 @@ export class QuickSearch extends React.Component {
143
116
  this.setState({
144
117
  value: event.currentTarget.value
145
118
  });
146
-
147
119
  if (onSearchInput) {
148
120
  onSearchInput(event);
149
121
  }
150
122
  });
151
-
152
123
  _defineProperty(this, "handleSearchKeyDown", event => {
153
124
  const {
154
125
  firePrivateAnalyticsEvent
155
126
  } = this.props;
156
127
  this.props.onSearchKeyDown(event);
157
- this.lastKeyPressed = event.key; // Need to check for keyCode for up/down/enter in case user is composing using an IME
158
- // fixes https://ecosystem.atlassian.net/browse/DS-6518
128
+ this.lastKeyPressed = event.key;
159
129
 
130
+ // Need to check for keyCode for up/down/enter in case user is composing using an IME
131
+ // fixes https://ecosystem.atlassian.net/browse/DS-6518
160
132
  if (event.key === 'ArrowUp' && event.keyCode === keycode('up')) {
161
133
  event.preventDefault(); // Don't move cursor around in search input field
162
-
163
134
  this.selectPrevious();
164
135
  } else if (event.key === 'ArrowDown' && event.keyCode === keycode('down')) {
165
136
  event.preventDefault(); // Don't move cursor around in search input field
166
-
167
137
  this.selectNext();
168
138
  } else if (event.key === 'Enter' && event.keyCode === keycode('enter')) {
169
139
  // shift key pressed or no result selected
@@ -176,30 +146,26 @@ export class QuickSearch extends React.Component {
176
146
  method: 'shortcut'
177
147
  });
178
148
  }
179
-
180
149
  this.props.onSearchSubmit(event);
181
150
  } else {
182
151
  event.preventDefault(); // Don't fire submit event from input
183
-
184
152
  const result = getResultById(this.flatResults, this.state.selectedResultId);
185
-
186
153
  if (!result || !result.props) {
187
154
  return;
188
- } // Capture when users are using the keyboard to submit
189
-
155
+ }
190
156
 
157
+ // Capture when users are using the keyboard to submit
191
158
  if (typeof firePrivateAnalyticsEvent === 'function') {
192
159
  this.fireKeyboardControlEvent(this.state.selectedResultId);
193
- firePrivateAnalyticsEvent(QS_ANALYTICS_EV_SUBMIT, { ...result.getAnalyticsData(),
160
+ firePrivateAnalyticsEvent(QS_ANALYTICS_EV_SUBMIT, {
161
+ ...result.getAnalyticsData(),
194
162
  method: 'returnKey',
195
163
  newTab: false,
196
164
  // enter always open in the same tab
197
165
  resultCount: this.flatResults.length
198
166
  });
199
167
  }
200
-
201
168
  let preventDefault = false;
202
-
203
169
  if (result.props.onClick) {
204
170
  result.props.onClick({
205
171
  resultId: result.props.resultId,
@@ -208,13 +174,10 @@ export class QuickSearch extends React.Component {
208
174
  preventDefault() {
209
175
  preventDefault = true;
210
176
  },
211
-
212
177
  stopPropagation() {}
213
-
214
178
  })
215
179
  });
216
180
  }
217
-
218
181
  if (result.props.href && !preventDefault) {
219
182
  window.location.assign(result.props.href);
220
183
  }
@@ -223,48 +186,43 @@ export class QuickSearch extends React.Component {
223
186
  const {
224
187
  autocompleteText
225
188
  } = this.props;
226
-
227
- if (autocompleteText && autocompleteText.length > 0 && // multiple Tab or ArrowRight
189
+ if (autocompleteText && autocompleteText.length > 0 &&
190
+ // multiple Tab or ArrowRight
228
191
  autocompleteText.slice(-1) !== ' ') {
229
192
  this.acceptAutocomplete(event, autocompleteText);
230
193
  event.preventDefault();
231
194
  }
232
195
  }
233
196
  });
234
-
235
197
  _defineProperty(this, "acceptAutocomplete", (event, text) => {
236
198
  const {
237
199
  onSearchInput
238
200
  } = this.props;
239
201
  const newValue = `${text} `;
240
-
241
202
  if (this.inputSearchRef) {
242
203
  this.setState({
243
204
  value: newValue
244
- }); // @ts-ignore unchecked
245
-
205
+ });
206
+ // @ts-ignore unchecked
246
207
  this.inputSearchRef.value = newValue;
247
208
  }
248
-
249
209
  if (onSearchInput) {
250
210
  onSearchInput(event, true);
251
211
  }
252
212
  });
253
-
254
213
  _defineProperty(this, "setSearchInputRef", refs => {
255
214
  if (refs && refs.inputRef) {
256
215
  this.inputSearchRef = refs.inputRef;
257
216
  }
258
217
  });
259
-
260
218
  _defineProperty(this, "focusSearchInput", () => {
261
- if (this.inputSearchRef && // @ts-ignore unchecked
219
+ if (this.inputSearchRef &&
220
+ // @ts-ignore unchecked
262
221
  typeof this.inputSearchRef.focus === 'function') {
263
222
  // @ts-ignore unchecked
264
223
  this.inputSearchRef.focus();
265
224
  }
266
225
  });
267
-
268
226
  this.state = {
269
227
  /** Select first result by default if `selectedResultId` prop is not provided */
270
228
  selectedResultId: this.props.selectedResultId || null,
@@ -282,27 +240,22 @@ export class QuickSearch extends React.Component {
282
240
  value: props.value
283
241
  };
284
242
  }
285
-
286
243
  componentDidMount() {
287
244
  const {
288
245
  firePrivateAnalyticsEvent
289
246
  } = this.props;
290
-
291
247
  if (firePrivateAnalyticsEvent) {
292
248
  firePrivateAnalyticsEvent(QS_ANALYTICS_EV_OPEN, {});
293
249
  }
294
250
  }
295
-
296
251
  componentWillUnmount() {
297
252
  const {
298
253
  firePrivateAnalyticsEvent
299
254
  } = this.props;
300
-
301
255
  if (firePrivateAnalyticsEvent) {
302
256
  firePrivateAnalyticsEvent(QS_ANALYTICS_EV_CLOSE, {});
303
257
  }
304
258
  }
305
-
306
259
  UNSAFE_componentWillReceiveProps(nextProps) {
307
260
  if (nextProps.children !== this.props.children) {
308
261
  this.setState({
@@ -312,59 +265,55 @@ export class QuickSearch extends React.Component {
312
265
  this.setState({
313
266
  selectedResultId: nextProps.selectedResultId || null
314
267
  });
315
- } // keep context state in sync
316
-
268
+ }
317
269
 
270
+ // keep context state in sync
318
271
  const {
319
272
  sendAnalytics,
320
273
  linkComponent
321
274
  } = this.state.context;
322
-
323
275
  if (sendAnalytics !== nextProps.firePrivateAnalyticsEvent || linkComponent !== nextProps.linkComponent) {
324
276
  this.setState({
325
- context: { ...this.state.context,
277
+ context: {
278
+ ...this.state.context,
326
279
  sendAnalytics: nextProps.firePrivateAnalyticsEvent,
327
280
  linkComponent: nextProps.linkComponent
328
281
  }
329
282
  });
330
283
  }
284
+
331
285
  /**
332
286
  * Capture whether user needed to query in order to find their target result.
333
287
  * Only fire once per mount. Only fire when a search term is entered and the previous search
334
288
  * term was empty.
335
289
  */
336
-
337
-
338
290
  if (!this.hasSearchQueryEventFired && !this.props.value && nextProps.value) {
339
291
  this.hasSearchQueryEventFired = true;
340
292
  const {
341
293
  firePrivateAnalyticsEvent
342
294
  } = this.props;
343
-
344
295
  if (firePrivateAnalyticsEvent) {
345
296
  firePrivateAnalyticsEvent(QS_ANALYTICS_EV_QUERY_ENTERED, {});
346
297
  }
347
298
  }
348
299
  }
349
-
350
300
  fireKeyboardControlEvent(selectedResultId) {
351
301
  const {
352
302
  firePrivateAnalyticsEvent
353
303
  } = this.props;
354
-
355
304
  if (firePrivateAnalyticsEvent) {
356
305
  const result = getResultById(this.flatResults, selectedResultId);
357
-
358
306
  if (result) {
359
- firePrivateAnalyticsEvent(QS_ANALYTICS_EV_KB_CTRLS_USED, { ...result.getAnalyticsData(),
307
+ firePrivateAnalyticsEvent(QS_ANALYTICS_EV_KB_CTRLS_USED, {
308
+ ...result.getAnalyticsData(),
360
309
  key: this.lastKeyPressed,
361
310
  resultCount: this.flatResults.length
362
311
  });
363
312
  }
364
313
  }
365
-
366
314
  this.lastKeyPressed = '';
367
315
  }
316
+
368
317
  /**
369
318
  * Uses the virtual list, this.flatResults, to move the selection across grouped results as if
370
319
  * results were in a single, circular list.
@@ -375,7 +324,6 @@ export class QuickSearch extends React.Component {
375
324
  * 3. Sets the new selectedResultId based on the modifed index
376
325
  */
377
326
 
378
-
379
327
  render() {
380
328
  return /*#__PURE__*/React.createElement(AkSearch, {
381
329
  isLoading: this.props.isLoading,
@@ -393,15 +341,14 @@ export class QuickSearch extends React.Component {
393
341
  value: this.state.selectedResultId
394
342
  }, this.props.children)));
395
343
  }
396
-
397
344
  }
345
+
398
346
  /**
399
347
  * HOCs:
400
348
  * `decorateWithAnalyticsData` - Wrapper that decorates analytics events with additional data.
401
349
  * `withAnalytics` - Injects analytics firing methods that are picked up by
402
350
  * @atlaskit/analytics/AnalyticsListener.
403
351
  */
404
-
405
352
  _defineProperty(QuickSearch, "defaultProps", {
406
353
  children: [],
407
354
  firePrivateAnalyticsEvent: _ => {},
@@ -412,6 +359,6 @@ _defineProperty(QuickSearch, "defaultProps", {
412
359
  placeholder: 'Search',
413
360
  value: ''
414
361
  });
415
-
416
- export default decorateWithAnalyticsData( // @ts-ignore
362
+ export default decorateWithAnalyticsData(
363
+ // @ts-ignore
417
364
  withAnalytics(QuickSearch, {}, {}));
@@ -4,7 +4,6 @@ import React from 'react';
4
4
  import baseItem, { withItemClick, withItemFocus } from '@atlaskit/item';
5
5
  import { ResultItemAfter, ResultItemAfterWrapper, ResultItemCaption, ResultItemIcon, ResultItemTextAfter, ResultItemSubText } from './styled';
6
6
  const Item = withItemClick(withItemFocus(baseItem));
7
-
8
7
  class ResultItem extends React.PureComponent {
9
8
  render() {
10
9
  const icon = this.props.icon ? /*#__PURE__*/React.createElement(ResultItemIcon, null, this.props.icon) : null;
@@ -30,12 +29,9 @@ class ResultItem extends React.PureComponent {
30
29
  linkComponent: this.props.linkComponent
31
30
  }, interactiveWrapperProps), this.props.text, wrappedCaption);
32
31
  }
33
-
34
32
  }
35
-
36
33
  _defineProperty(ResultItem, "defaultProps", {
37
34
  isSelected: false,
38
35
  isMouseSelected: false
39
36
  });
40
-
41
37
  export default ResultItem;
@@ -12,5 +12,4 @@ export default class ResultItemGroup extends React.Component {
12
12
  title: wrappedTitle
13
13
  }, children);
14
14
  }
15
-
16
15
  }