@atlaskit/link-picker 1.8.1 → 1.8.4

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 (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/analytics.codegen.js +1 -1
  3. package/dist/cjs/{ui/link-picker → common/utils}/url.js +0 -0
  4. package/dist/cjs/services/use-plugins/index.js +48 -90
  5. package/dist/cjs/services/use-plugins/reducer.js +64 -0
  6. package/dist/cjs/services/use-plugins/utils.js +134 -0
  7. package/dist/cjs/services/use-search-query/index.js +1 -1
  8. package/dist/cjs/services/with-link-picker-analytics/index.js +33 -0
  9. package/dist/cjs/ui/link-picker/index.js +5 -2
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/analytics.codegen.js +1 -1
  12. package/dist/es2019/{ui/link-picker → common/utils}/url.js +0 -0
  13. package/dist/es2019/services/use-plugins/index.js +35 -57
  14. package/dist/es2019/services/use-plugins/reducer.js +37 -0
  15. package/dist/es2019/services/use-plugins/utils.js +59 -0
  16. package/dist/es2019/services/use-search-query/index.js +1 -1
  17. package/dist/es2019/services/with-link-picker-analytics/index.js +15 -0
  18. package/dist/es2019/ui/link-picker/index.js +4 -3
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/analytics.codegen.js +1 -1
  21. package/dist/esm/{ui/link-picker → common/utils}/url.js +0 -0
  22. package/dist/esm/services/use-plugins/index.js +49 -94
  23. package/dist/esm/services/use-plugins/reducer.js +43 -0
  24. package/dist/esm/services/use-plugins/utils.js +111 -0
  25. package/dist/esm/services/use-search-query/index.js +1 -1
  26. package/dist/esm/services/with-link-picker-analytics/index.js +17 -0
  27. package/dist/esm/ui/link-picker/index.js +4 -3
  28. package/dist/esm/version.json +1 -1
  29. package/dist/types/analytics.codegen.d.ts +7 -4
  30. package/dist/types/{ui/link-picker → common/utils}/url.d.ts +0 -0
  31. package/dist/types/services/use-plugins/reducer.d.ts +30 -0
  32. package/dist/types/services/use-plugins/utils.d.ts +18 -0
  33. package/dist/types/services/with-link-picker-analytics/index.d.ts +4 -0
  34. package/dist/types/ui/link-picker/index.d.ts +3 -3
  35. package/package.json +9 -9
  36. package/report.api.md +2 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/link-picker
2
2
 
3
+ ## 1.8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`e94f9f982b4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e94f9f982b4) - Fixes link picker attempting to dispatch updates after being unmounted.
8
+
9
+ ## 1.8.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`7e07778ec20`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7e07778ec20) - Add linkState attribute to link picker analytics context
14
+
15
+ ## 1.8.2
16
+
17
+ ### Patch Changes
18
+
19
+ - [`8d4228767b0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8d4228767b0) - Upgrade Typescript from `4.2.4` to `4.3.5`.
20
+
3
21
  ## 1.8.1
4
22
 
5
23
  ### Patch Changes
@@ -10,7 +10,7 @@ exports.default = void 0;
10
10
  *
11
11
  * Generates analytics utilities from the package analytics spec yaml
12
12
  *
13
- * @codegen <<SignedSource::ffa7ec78cc793f941d06cdb25b07dc8a>>
13
+ * @codegen <<SignedSource::115bafba068f36f76da67200ee2d08c4>>
14
14
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
15
15
  */
16
16
  function createEventPayload(eventKey, attributes) {
File without changes
@@ -13,19 +13,13 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
13
13
 
14
14
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
15
 
16
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
-
18
16
  var _react = require("react");
19
17
 
20
18
  var _linkPicker = require("../../ui/link-picker");
21
19
 
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
20
+ var _utils = require("./utils");
25
21
 
26
- function reducer(state, payload) {
27
- return _objectSpread(_objectSpread({}, state), payload);
28
- }
22
+ var _reducer = require("./reducer");
29
23
 
30
24
  function usePlugins(state, activeTab, plugins) {
31
25
  var _useState = (0, _react.useState)(0),
@@ -33,19 +27,11 @@ function usePlugins(state, activeTab, plugins) {
33
27
  retries = _useState2[0],
34
28
  setRetries = _useState2[1];
35
29
 
36
- var _useReducer = (0, _react.useReducer)(reducer, {
37
- items: null,
38
- error: null,
39
- isLoading: false
40
- }),
41
- _useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
42
- pluginState = _useReducer2[0],
43
- dispatch = _useReducer2[1];
30
+ var _usePluginReducer = (0, _reducer.usePluginReducer)(),
31
+ _usePluginReducer2 = (0, _slicedToArray2.default)(_usePluginReducer, 2),
32
+ pluginState = _usePluginReducer2[0],
33
+ dispatch = _usePluginReducer2[1];
44
34
 
45
- var items = pluginState.items,
46
- isLoading = pluginState.isLoading,
47
- error = pluginState.error;
48
- var queryVersion = (0, _react.useRef)(0);
49
35
  var activePlugin = plugins === null || plugins === void 0 ? void 0 : plugins[activeTab];
50
36
  (0, _react.useEffect)(function () {
51
37
  if (!activePlugin) {
@@ -54,107 +40,75 @@ function usePlugins(state, activeTab, plugins) {
54
40
 
55
41
  if (!state) {
56
42
  dispatch({
57
- items: null,
58
- isLoading: false,
59
- error: null
43
+ type: 'CLEAR'
60
44
  });
61
45
  return;
62
46
  }
63
47
 
64
- var updates = activePlugin.resolve(state);
65
48
  dispatch({
66
- items: null,
67
- isLoading: true,
68
- error: null
49
+ type: 'LOADING'
69
50
  });
70
- var newQuery = ++queryVersion.current;
51
+
52
+ var _resolvePluginUpdates = (0, _utils.resolvePluginUpdates)(activePlugin, state),
53
+ next = _resolvePluginUpdates.next,
54
+ cancel = _resolvePluginUpdates.cancel;
71
55
 
72
56
  var updateResults = /*#__PURE__*/function () {
73
57
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
74
- var done, value, _result$done, result;
58
+ var _isLoading, _yield$next, value, done;
75
59
 
76
60
  return _regenerator.default.wrap(function _callee$(_context) {
77
61
  while (1) {
78
62
  switch (_context.prev = _context.next) {
79
63
  case 0:
80
64
  _context.prev = 0;
65
+ _isLoading = true;
81
66
 
82
- case 1:
83
- if (!(newQuery === queryVersion.current)) {
84
- _context.next = 23;
85
- break;
86
- }
87
-
88
- done = false;
89
- value = void 0;
90
-
91
- if (!(updates instanceof Promise)) {
92
- _context.next = 11;
67
+ case 2:
68
+ if (!_isLoading) {
69
+ _context.next = 12;
93
70
  break;
94
71
  }
95
72
 
96
- done = true;
97
- _context.next = 8;
98
- return updates;
99
-
100
- case 8:
101
- value = _context.sent;
102
- _context.next = 16;
103
- break;
104
-
105
- case 11:
106
- _context.next = 13;
107
- return updates.next();
73
+ _context.next = 5;
74
+ return next();
108
75
 
109
- case 13:
110
- result = _context.sent;
111
- done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
112
- value = result.value;
113
-
114
- case 16:
115
- if (!(newQuery !== queryVersion.current)) {
116
- _context.next = 18;
117
- break;
118
- }
119
-
120
- return _context.abrupt("return");
121
-
122
- case 18:
76
+ case 5:
77
+ _yield$next = _context.sent;
78
+ value = _yield$next.value;
79
+ done = _yield$next.done;
80
+ _isLoading = !done;
123
81
  dispatch({
124
- items: limit(value.data),
125
- isLoading: !done
82
+ type: 'SUCCESS',
83
+ payload: {
84
+ items: limit(value.data),
85
+ isLoading: !done
86
+ }
126
87
  });
127
-
128
- if (!done) {
129
- _context.next = 21;
130
- break;
131
- }
132
-
133
- return _context.abrupt("return");
134
-
135
- case 21:
136
- _context.next = 1;
88
+ _context.next = 2;
137
89
  break;
138
90
 
139
- case 23:
140
- _context.next = 28;
91
+ case 12:
92
+ _context.next = 17;
141
93
  break;
142
94
 
143
- case 25:
144
- _context.prev = 25;
95
+ case 14:
96
+ _context.prev = 14;
145
97
  _context.t0 = _context["catch"](0);
146
- dispatch({
147
- error: _context.t0,
148
- items: null,
149
- isLoading: false
150
- });
151
98
 
152
- case 28:
99
+ if (!(_context.t0 instanceof _utils.CancellationError)) {
100
+ dispatch({
101
+ type: 'ERROR',
102
+ payload: _context.t0
103
+ });
104
+ }
105
+
106
+ case 17:
153
107
  case "end":
154
108
  return _context.stop();
155
109
  }
156
110
  }
157
- }, _callee, null, [[0, 25]]);
111
+ }, _callee, null, [[0, 14]]);
158
112
  }));
159
113
 
160
114
  return function updateResults() {
@@ -163,7 +117,8 @@ function usePlugins(state, activeTab, plugins) {
163
117
  }();
164
118
 
165
119
  updateResults();
166
- }, [activePlugin, queryVersion, state, retries]);
120
+ return cancel;
121
+ }, [activePlugin, state, retries, dispatch]);
167
122
  var tabs = (0, _react.useMemo)(function () {
168
123
  if (!plugins || plugins.length <= 1) {
169
124
  return [];
@@ -182,6 +137,9 @@ function usePlugins(state, activeTab, plugins) {
182
137
  return ++prev;
183
138
  });
184
139
  }, []);
140
+ var items = pluginState.items,
141
+ isLoading = pluginState.isLoading,
142
+ error = pluginState.error;
185
143
  return {
186
144
  tabs: tabs,
187
145
  items: items,
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.INITIAL_STATE = exports.ACTION_SUCCESS = exports.ACTION_LOADING = exports.ACTION_ERRORED = exports.ACTION_CLEAR = void 0;
9
+ exports.reducer = reducer;
10
+ exports.usePluginReducer = void 0;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _react = require("react");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
+
20
+ var ACTION_CLEAR = 'CLEAR';
21
+ exports.ACTION_CLEAR = ACTION_CLEAR;
22
+ var ACTION_LOADING = 'LOADING';
23
+ exports.ACTION_LOADING = ACTION_LOADING;
24
+ var ACTION_SUCCESS = 'SUCCESS';
25
+ exports.ACTION_SUCCESS = ACTION_SUCCESS;
26
+ var ACTION_ERRORED = 'ERROR';
27
+ exports.ACTION_ERRORED = ACTION_ERRORED;
28
+ var INITIAL_STATE = {
29
+ items: null,
30
+ error: null,
31
+ isLoading: false
32
+ };
33
+ exports.INITIAL_STATE = INITIAL_STATE;
34
+
35
+ function reducer(state, action) {
36
+ switch (action.type) {
37
+ case ACTION_CLEAR:
38
+ return _objectSpread({}, INITIAL_STATE);
39
+
40
+ case ACTION_LOADING:
41
+ return _objectSpread(_objectSpread({}, INITIAL_STATE), {}, {
42
+ isLoading: true
43
+ });
44
+
45
+ case ACTION_SUCCESS:
46
+ return _objectSpread(_objectSpread(_objectSpread({}, state), action.payload), {}, {
47
+ error: null
48
+ });
49
+
50
+ case ACTION_ERRORED:
51
+ return _objectSpread(_objectSpread({}, INITIAL_STATE), {}, {
52
+ error: action.payload
53
+ });
54
+
55
+ default:
56
+ return state;
57
+ }
58
+ }
59
+
60
+ var usePluginReducer = function usePluginReducer() {
61
+ return (0, _react.useReducer)(reducer, INITIAL_STATE);
62
+ };
63
+
64
+ exports.usePluginReducer = usePluginReducer;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.resolvePluginUpdates = exports.cancellable = exports.CancellationError = void 0;
9
+
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
+
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
20
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
22
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
24
+ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
25
+
26
+ 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); }; }
27
+
28
+ 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; } }
29
+
30
+ var CancellationError = /*#__PURE__*/function (_Error) {
31
+ (0, _inherits2.default)(CancellationError, _Error);
32
+
33
+ var _super = _createSuper(CancellationError);
34
+
35
+ function CancellationError() {
36
+ (0, _classCallCheck2.default)(this, CancellationError);
37
+ return _super.apply(this, arguments);
38
+ }
39
+
40
+ return (0, _createClass2.default)(CancellationError);
41
+ }( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
42
+
43
+ exports.CancellationError = CancellationError;
44
+
45
+ var cancellable = function cancellable(promise) {
46
+ var reject;
47
+ return {
48
+ promise: new Promise(function (resolve, _reject) {
49
+ reject = _reject;
50
+ promise.then(resolve, reject);
51
+ }),
52
+ cancel: function cancel() {
53
+ reject(new CancellationError('Promise cancelled'));
54
+ }
55
+ };
56
+ };
57
+ /**
58
+ * Wraps the resolve with a cancellation wrapper and makes promise + generator plugin resolves more compatible
59
+ * Calling cancel for generator plugin prevents it from yielding any further updates
60
+ */
61
+
62
+
63
+ exports.cancellable = cancellable;
64
+
65
+ var resolvePluginUpdates = function resolvePluginUpdates(plugin, state) {
66
+ var updates = plugin.resolve(state); // Promise plugin
67
+
68
+ if (updates instanceof Promise) {
69
+ var _cancellable = cancellable(updates),
70
+ promise = _cancellable.promise,
71
+ cancel = _cancellable.cancel;
72
+
73
+ return {
74
+ cancel: cancel,
75
+ next: function () {
76
+ var _next = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
77
+ return _regenerator.default.wrap(function _callee$(_context) {
78
+ while (1) {
79
+ switch (_context.prev = _context.next) {
80
+ case 0:
81
+ _context.next = 2;
82
+ return promise;
83
+
84
+ case 2:
85
+ _context.t0 = _context.sent;
86
+ return _context.abrupt("return", {
87
+ value: _context.t0,
88
+ done: true
89
+ });
90
+
91
+ case 4:
92
+ case "end":
93
+ return _context.stop();
94
+ }
95
+ }
96
+ }, _callee);
97
+ }));
98
+
99
+ function next() {
100
+ return _next.apply(this, arguments);
101
+ }
102
+
103
+ return next;
104
+ }()
105
+ };
106
+ } // Generator plugin
107
+
108
+
109
+ var cancellationCallbacks = [];
110
+ var cancelled = false;
111
+ return {
112
+ cancel: function cancel() {
113
+ cancelled = true;
114
+ cancellationCallbacks.forEach(function (cb) {
115
+ return cb();
116
+ });
117
+ },
118
+ next: function next() {
119
+ var _cancellable2 = cancellable(updates.next()),
120
+ promise = _cancellable2.promise,
121
+ cancel = _cancellable2.cancel;
122
+
123
+ if (cancelled) {
124
+ cancel();
125
+ } else {
126
+ cancellationCallbacks.push(cancel);
127
+ }
128
+
129
+ return promise;
130
+ }
131
+ };
132
+ };
133
+
134
+ exports.resolvePluginUpdates = resolvePluginUpdates;
@@ -7,7 +7,7 @@ exports.useSearchQuery = useSearchQuery;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
- var _url = require("../../ui/link-picker/url");
10
+ var _url = require("../../common/utils/url");
11
11
 
12
12
  function useSearchQuery(state) {
13
13
  var _queryState$current;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.withLinkPickerAnalyticsContext = withLinkPickerAnalyticsContext;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _analyticsNext = require("@atlaskit/analytics-next");
13
+
14
+ var _url = require("../../common/utils/url");
15
+
16
+ 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); }
17
+
18
+ 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; }
19
+
20
+ function withLinkPickerAnalyticsContext(WrappedComponent) {
21
+ return function (props) {
22
+ var data = (0, _react.useMemo)(function () {
23
+ return {
24
+ attributes: {
25
+ linkState: (0, _url.normalizeUrl)(props.url) ? 'editLink' : 'newLink'
26
+ }
27
+ };
28
+ }, [props.url]);
29
+ return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsContext, {
30
+ data: data
31
+ }, /*#__PURE__*/_react.default.createElement(WrappedComponent, props));
32
+ };
33
+ }
@@ -41,13 +41,15 @@ var _usePlugins2 = require("../../services/use-plugins");
41
41
 
42
42
  var _useSearchQuery = require("../../services/use-search-query");
43
43
 
44
+ var _withLinkPickerAnalytics = require("../../services/with-link-picker-analytics");
45
+
44
46
  var _messages = require("./messages");
45
47
 
46
48
  var _textInput = _interopRequireDefault(require("./text-input"));
47
49
 
48
50
  var _linkSearchList = _interopRequireDefault(require("./link-search-list"));
49
51
 
50
- var _url2 = require("./url");
52
+ var _url2 = require("../../common/utils/url");
51
53
 
52
54
  var _styled = require("./styled");
53
55
 
@@ -414,7 +416,8 @@ function LinkPicker(_ref) {
414
416
  }, intl.formatMessage(insertButtonMsg)))));
415
417
  }
416
418
 
417
- var _default = LinkPicker;
419
+ var _default = (0, _withLinkPickerAnalytics.withLinkPickerAnalyticsContext)( /*#__PURE__*/(0, _react.memo)(LinkPicker));
420
+
418
421
  exports.default = _default;
419
422
 
420
423
  function getScreenReaderText(items, selectedIndex, intl) {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.8.1",
3
+ "version": "1.8.4",
4
4
  "sideEffects": false
5
5
  }
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Generates analytics utilities from the package analytics spec yaml
5
5
  *
6
- * @codegen <<SignedSource::ffa7ec78cc793f941d06cdb25b07dc8a>>
6
+ * @codegen <<SignedSource::115bafba068f36f76da67200ee2d08c4>>
7
7
  * @codegenCommand yarn workspace @atlaskit/link-picker run codegen-analytics
8
8
  */
9
9
  function createEventPayload(eventKey, attributes) {
@@ -1,25 +1,10 @@
1
- import { useEffect, useReducer, useMemo, useRef, useState, useCallback } from 'react';
1
+ import { useEffect, useMemo, useState, useCallback } from 'react';
2
2
  import { RECENT_SEARCH_LIST_SIZE } from '../../ui/link-picker';
3
-
4
- function reducer(state, payload) {
5
- return { ...state,
6
- ...payload
7
- };
8
- }
9
-
3
+ import { CancellationError, resolvePluginUpdates } from './utils';
4
+ import { usePluginReducer } from './reducer';
10
5
  export function usePlugins(state, activeTab, plugins) {
11
6
  const [retries, setRetries] = useState(0);
12
- const [pluginState, dispatch] = useReducer(reducer, {
13
- items: null,
14
- error: null,
15
- isLoading: false
16
- });
17
- const {
18
- items,
19
- isLoading,
20
- error
21
- } = pluginState;
22
- const queryVersion = useRef(0);
7
+ const [pluginState, dispatch] = usePluginReducer();
23
8
  const activePlugin = plugins === null || plugins === void 0 ? void 0 : plugins[activeTab];
24
9
  useEffect(() => {
25
10
  if (!activePlugin) {
@@ -28,62 +13,50 @@ export function usePlugins(state, activeTab, plugins) {
28
13
 
29
14
  if (!state) {
30
15
  dispatch({
31
- items: null,
32
- isLoading: false,
33
- error: null
16
+ type: 'CLEAR'
34
17
  });
35
18
  return;
36
19
  }
37
20
 
38
- const updates = activePlugin.resolve(state);
39
21
  dispatch({
40
- items: null,
41
- isLoading: true,
42
- error: null
22
+ type: 'LOADING'
43
23
  });
44
- const newQuery = ++queryVersion.current;
24
+ const {
25
+ next,
26
+ cancel
27
+ } = resolvePluginUpdates(activePlugin, state);
45
28
 
46
29
  const updateResults = async () => {
47
30
  try {
48
- while (newQuery === queryVersion.current) {
49
- let done = false;
50
- let value;
51
-
52
- if (updates instanceof Promise) {
53
- done = true;
54
- value = await updates;
55
- } else {
56
- var _result$done;
57
-
58
- const result = await updates.next();
59
- done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
60
- value = result.value;
61
- }
62
-
63
- if (newQuery !== queryVersion.current) {
64
- return;
65
- }
31
+ let isLoading = true;
66
32
 
33
+ while (isLoading) {
34
+ const {
35
+ value,
36
+ done
37
+ } = await next();
38
+ isLoading = !done;
67
39
  dispatch({
68
- items: limit(value.data),
69
- isLoading: !done
40
+ type: 'SUCCESS',
41
+ payload: {
42
+ items: limit(value.data),
43
+ isLoading: !done
44
+ }
70
45
  });
71
-
72
- if (done) {
73
- return;
74
- }
75
46
  }
76
47
  } catch (error) {
77
- dispatch({
78
- error,
79
- items: null,
80
- isLoading: false
81
- });
48
+ if (!(error instanceof CancellationError)) {
49
+ dispatch({
50
+ type: 'ERROR',
51
+ payload: error
52
+ });
53
+ }
82
54
  }
83
55
  };
84
56
 
85
57
  updateResults();
86
- }, [activePlugin, queryVersion, state, retries]);
58
+ return cancel;
59
+ }, [activePlugin, state, retries, dispatch]);
87
60
  const tabs = useMemo(() => {
88
61
  if (!plugins || plugins.length <= 1) {
89
62
  return [];
@@ -96,6 +69,11 @@ export function usePlugins(state, activeTab, plugins) {
96
69
  const handleRetry = useCallback(() => {
97
70
  setRetries(prev => ++prev);
98
71
  }, []);
72
+ const {
73
+ items,
74
+ isLoading,
75
+ error
76
+ } = pluginState;
99
77
  return {
100
78
  tabs,
101
79
  items,