@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
@@ -0,0 +1,37 @@
1
+ import { useReducer } from 'react';
2
+ export const ACTION_CLEAR = 'CLEAR';
3
+ export const ACTION_LOADING = 'LOADING';
4
+ export const ACTION_SUCCESS = 'SUCCESS';
5
+ export const ACTION_ERRORED = 'ERROR';
6
+ export const INITIAL_STATE = {
7
+ items: null,
8
+ error: null,
9
+ isLoading: false
10
+ };
11
+ export function reducer(state, action) {
12
+ switch (action.type) {
13
+ case ACTION_CLEAR:
14
+ return { ...INITIAL_STATE
15
+ };
16
+
17
+ case ACTION_LOADING:
18
+ return { ...INITIAL_STATE,
19
+ isLoading: true
20
+ };
21
+
22
+ case ACTION_SUCCESS:
23
+ return { ...state,
24
+ ...action.payload,
25
+ error: null
26
+ };
27
+
28
+ case ACTION_ERRORED:
29
+ return { ...INITIAL_STATE,
30
+ error: action.payload
31
+ };
32
+
33
+ default:
34
+ return state;
35
+ }
36
+ }
37
+ export const usePluginReducer = () => useReducer(reducer, INITIAL_STATE);
@@ -0,0 +1,59 @@
1
+ export class CancellationError extends Error {}
2
+ export const cancellable = promise => {
3
+ let reject;
4
+ return {
5
+ promise: new Promise((resolve, _reject) => {
6
+ reject = _reject;
7
+ promise.then(resolve, reject);
8
+ }),
9
+ cancel: () => {
10
+ reject(new CancellationError('Promise cancelled'));
11
+ }
12
+ };
13
+ };
14
+ /**
15
+ * Wraps the resolve with a cancellation wrapper and makes promise + generator plugin resolves more compatible
16
+ * Calling cancel for generator plugin prevents it from yielding any further updates
17
+ */
18
+
19
+ export const resolvePluginUpdates = (plugin, state) => {
20
+ const updates = plugin.resolve(state); // Promise plugin
21
+
22
+ if (updates instanceof Promise) {
23
+ const {
24
+ promise,
25
+ cancel
26
+ } = cancellable(updates);
27
+ return {
28
+ cancel,
29
+ next: async () => ({
30
+ value: await promise,
31
+ done: true
32
+ })
33
+ };
34
+ } // Generator plugin
35
+
36
+
37
+ const cancellationCallbacks = [];
38
+ let cancelled = false;
39
+ return {
40
+ cancel: () => {
41
+ cancelled = true;
42
+ cancellationCallbacks.forEach(cb => cb());
43
+ },
44
+ next: () => {
45
+ const {
46
+ promise,
47
+ cancel
48
+ } = cancellable(updates.next());
49
+
50
+ if (cancelled) {
51
+ cancel();
52
+ } else {
53
+ cancellationCallbacks.push(cancel);
54
+ }
55
+
56
+ return promise;
57
+ }
58
+ };
59
+ };
@@ -1,5 +1,5 @@
1
1
  import { useRef } from 'react';
2
- import { isSafeUrl } from '../../ui/link-picker/url';
2
+ import { isSafeUrl } from '../../common/utils/url';
3
3
  export function useSearchQuery(state) {
4
4
  var _queryState$current;
5
5
 
@@ -0,0 +1,15 @@
1
+ import React, { useMemo } from 'react';
2
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
3
+ import { normalizeUrl } from '../../common/utils/url';
4
+ export function withLinkPickerAnalyticsContext(WrappedComponent) {
5
+ return props => {
6
+ const data = useMemo(() => ({
7
+ attributes: {
8
+ linkState: normalizeUrl(props.url) ? 'editLink' : 'newLink'
9
+ }
10
+ }), [props.url]);
11
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
12
+ data: data
13
+ }, /*#__PURE__*/React.createElement(WrappedComponent, props));
14
+ };
15
+ }
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
 
3
3
  /** @jsx jsx */
4
- import { Fragment, useCallback, useEffect, useLayoutEffect, useReducer } from 'react';
4
+ import { Fragment, useCallback, useEffect, useLayoutEffect, useReducer, memo } from 'react';
5
5
  import { jsx } from '@emotion/react';
6
6
  import { useIntl, FormattedMessage } from 'react-intl-next';
7
7
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
@@ -14,10 +14,11 @@ import createEventPayload from '../../analytics.codegen';
14
14
  import { ANALYTICS_CHANNEL } from '../../common/constants';
15
15
  import { usePlugins } from '../../services/use-plugins';
16
16
  import { useSearchQuery } from '../../services/use-search-query';
17
+ import { withLinkPickerAnalyticsContext } from '../../services/with-link-picker-analytics';
17
18
  import { messages } from './messages';
18
19
  import PanelTextInput from './text-input';
19
20
  import LinkSearchList from './link-search-list';
20
- import { normalizeUrl, isSafeUrl } from './url';
21
+ import { normalizeUrl, isSafeUrl } from '../../common/utils/url';
21
22
  import { rootContainerStyles, searchIconStyles, listTitleStyles, tabsWrapperStyles } from './styled';
22
23
  import { browser } from './browser';
23
24
  import Announcer from './announcer';
@@ -361,7 +362,7 @@ function LinkPicker({
361
362
  }, intl.formatMessage(insertButtonMsg)))));
362
363
  }
363
364
 
364
- export default LinkPicker;
365
+ export default withLinkPickerAnalyticsContext( /*#__PURE__*/memo(LinkPicker));
365
366
 
366
367
  function getScreenReaderText(items, selectedIndex, intl) {
367
368
  if (items.length && selectedIndex > -1) {
@@ -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) {
File without changes
@@ -1,38 +1,21 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
-
6
- 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; }
7
-
8
- 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) { _defineProperty(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; }
9
-
10
- import { useEffect, useReducer, useMemo, useRef, useState, useCallback } from 'react';
4
+ import { useEffect, useMemo, useState, useCallback } from 'react';
11
5
  import { RECENT_SEARCH_LIST_SIZE } from '../../ui/link-picker';
12
-
13
- function reducer(state, payload) {
14
- return _objectSpread(_objectSpread({}, state), payload);
15
- }
16
-
6
+ import { CancellationError, resolvePluginUpdates } from './utils';
7
+ import { usePluginReducer } from './reducer';
17
8
  export function usePlugins(state, activeTab, plugins) {
18
9
  var _useState = useState(0),
19
10
  _useState2 = _slicedToArray(_useState, 2),
20
11
  retries = _useState2[0],
21
12
  setRetries = _useState2[1];
22
13
 
23
- var _useReducer = useReducer(reducer, {
24
- items: null,
25
- error: null,
26
- isLoading: false
27
- }),
28
- _useReducer2 = _slicedToArray(_useReducer, 2),
29
- pluginState = _useReducer2[0],
30
- dispatch = _useReducer2[1];
14
+ var _usePluginReducer = usePluginReducer(),
15
+ _usePluginReducer2 = _slicedToArray(_usePluginReducer, 2),
16
+ pluginState = _usePluginReducer2[0],
17
+ dispatch = _usePluginReducer2[1];
31
18
 
32
- var items = pluginState.items,
33
- isLoading = pluginState.isLoading,
34
- error = pluginState.error;
35
- var queryVersion = useRef(0);
36
19
  var activePlugin = plugins === null || plugins === void 0 ? void 0 : plugins[activeTab];
37
20
  useEffect(function () {
38
21
  if (!activePlugin) {
@@ -41,107 +24,75 @@ export function usePlugins(state, activeTab, plugins) {
41
24
 
42
25
  if (!state) {
43
26
  dispatch({
44
- items: null,
45
- isLoading: false,
46
- error: null
27
+ type: 'CLEAR'
47
28
  });
48
29
  return;
49
30
  }
50
31
 
51
- var updates = activePlugin.resolve(state);
52
32
  dispatch({
53
- items: null,
54
- isLoading: true,
55
- error: null
33
+ type: 'LOADING'
56
34
  });
57
- var newQuery = ++queryVersion.current;
35
+
36
+ var _resolvePluginUpdates = resolvePluginUpdates(activePlugin, state),
37
+ next = _resolvePluginUpdates.next,
38
+ cancel = _resolvePluginUpdates.cancel;
58
39
 
59
40
  var updateResults = /*#__PURE__*/function () {
60
41
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
61
- var done, value, _result$done, result;
42
+ var _isLoading, _yield$next, value, done;
62
43
 
63
44
  return _regeneratorRuntime.wrap(function _callee$(_context) {
64
45
  while (1) {
65
46
  switch (_context.prev = _context.next) {
66
47
  case 0:
67
48
  _context.prev = 0;
49
+ _isLoading = true;
68
50
 
69
- case 1:
70
- if (!(newQuery === queryVersion.current)) {
71
- _context.next = 23;
72
- break;
73
- }
74
-
75
- done = false;
76
- value = void 0;
77
-
78
- if (!(updates instanceof Promise)) {
79
- _context.next = 11;
80
- break;
81
- }
82
-
83
- done = true;
84
- _context.next = 8;
85
- return updates;
86
-
87
- case 8:
88
- value = _context.sent;
89
- _context.next = 16;
90
- break;
91
-
92
- case 11:
93
- _context.next = 13;
94
- return updates.next();
95
-
96
- case 13:
97
- result = _context.sent;
98
- done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
99
- value = result.value;
100
-
101
- case 16:
102
- if (!(newQuery !== queryVersion.current)) {
103
- _context.next = 18;
51
+ case 2:
52
+ if (!_isLoading) {
53
+ _context.next = 12;
104
54
  break;
105
55
  }
106
56
 
107
- return _context.abrupt("return");
57
+ _context.next = 5;
58
+ return next();
108
59
 
109
- case 18:
60
+ case 5:
61
+ _yield$next = _context.sent;
62
+ value = _yield$next.value;
63
+ done = _yield$next.done;
64
+ _isLoading = !done;
110
65
  dispatch({
111
- items: limit(value.data),
112
- isLoading: !done
66
+ type: 'SUCCESS',
67
+ payload: {
68
+ items: limit(value.data),
69
+ isLoading: !done
70
+ }
113
71
  });
114
-
115
- if (!done) {
116
- _context.next = 21;
117
- break;
118
- }
119
-
120
- return _context.abrupt("return");
121
-
122
- case 21:
123
- _context.next = 1;
72
+ _context.next = 2;
124
73
  break;
125
74
 
126
- case 23:
127
- _context.next = 28;
75
+ case 12:
76
+ _context.next = 17;
128
77
  break;
129
78
 
130
- case 25:
131
- _context.prev = 25;
79
+ case 14:
80
+ _context.prev = 14;
132
81
  _context.t0 = _context["catch"](0);
133
- dispatch({
134
- error: _context.t0,
135
- items: null,
136
- isLoading: false
137
- });
138
82
 
139
- case 28:
83
+ if (!(_context.t0 instanceof CancellationError)) {
84
+ dispatch({
85
+ type: 'ERROR',
86
+ payload: _context.t0
87
+ });
88
+ }
89
+
90
+ case 17:
140
91
  case "end":
141
92
  return _context.stop();
142
93
  }
143
94
  }
144
- }, _callee, null, [[0, 25]]);
95
+ }, _callee, null, [[0, 14]]);
145
96
  }));
146
97
 
147
98
  return function updateResults() {
@@ -150,7 +101,8 @@ export function usePlugins(state, activeTab, plugins) {
150
101
  }();
151
102
 
152
103
  updateResults();
153
- }, [activePlugin, queryVersion, state, retries]);
104
+ return cancel;
105
+ }, [activePlugin, state, retries, dispatch]);
154
106
  var tabs = useMemo(function () {
155
107
  if (!plugins || plugins.length <= 1) {
156
108
  return [];
@@ -169,6 +121,9 @@ export function usePlugins(state, activeTab, plugins) {
169
121
  return ++prev;
170
122
  });
171
123
  }, []);
124
+ var items = pluginState.items,
125
+ isLoading = pluginState.isLoading,
126
+ error = pluginState.error;
172
127
  return {
173
128
  tabs: tabs,
174
129
  items: items,
@@ -0,0 +1,43 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ 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; }
4
+
5
+ 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) { _defineProperty(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; }
6
+
7
+ import { useReducer } from 'react';
8
+ export var ACTION_CLEAR = 'CLEAR';
9
+ export var ACTION_LOADING = 'LOADING';
10
+ export var ACTION_SUCCESS = 'SUCCESS';
11
+ export var ACTION_ERRORED = 'ERROR';
12
+ export var INITIAL_STATE = {
13
+ items: null,
14
+ error: null,
15
+ isLoading: false
16
+ };
17
+ export function reducer(state, action) {
18
+ switch (action.type) {
19
+ case ACTION_CLEAR:
20
+ return _objectSpread({}, INITIAL_STATE);
21
+
22
+ case ACTION_LOADING:
23
+ return _objectSpread(_objectSpread({}, INITIAL_STATE), {}, {
24
+ isLoading: true
25
+ });
26
+
27
+ case ACTION_SUCCESS:
28
+ return _objectSpread(_objectSpread(_objectSpread({}, state), action.payload), {}, {
29
+ error: null
30
+ });
31
+
32
+ case ACTION_ERRORED:
33
+ return _objectSpread(_objectSpread({}, INITIAL_STATE), {}, {
34
+ error: action.payload
35
+ });
36
+
37
+ default:
38
+ return state;
39
+ }
40
+ }
41
+ export var usePluginReducer = function usePluginReducer() {
42
+ return useReducer(reducer, INITIAL_STATE);
43
+ };
@@ -0,0 +1,111 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
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 _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
8
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
9
+
10
+ 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); }; }
11
+
12
+ 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; } }
13
+
14
+ export var CancellationError = /*#__PURE__*/function (_Error) {
15
+ _inherits(CancellationError, _Error);
16
+
17
+ var _super = _createSuper(CancellationError);
18
+
19
+ function CancellationError() {
20
+ _classCallCheck(this, CancellationError);
21
+
22
+ return _super.apply(this, arguments);
23
+ }
24
+
25
+ return _createClass(CancellationError);
26
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
27
+ export var cancellable = function cancellable(promise) {
28
+ var reject;
29
+ return {
30
+ promise: new Promise(function (resolve, _reject) {
31
+ reject = _reject;
32
+ promise.then(resolve, reject);
33
+ }),
34
+ cancel: function cancel() {
35
+ reject(new CancellationError('Promise cancelled'));
36
+ }
37
+ };
38
+ };
39
+ /**
40
+ * Wraps the resolve with a cancellation wrapper and makes promise + generator plugin resolves more compatible
41
+ * Calling cancel for generator plugin prevents it from yielding any further updates
42
+ */
43
+
44
+ export var resolvePluginUpdates = function resolvePluginUpdates(plugin, state) {
45
+ var updates = plugin.resolve(state); // Promise plugin
46
+
47
+ if (updates instanceof Promise) {
48
+ var _cancellable = cancellable(updates),
49
+ promise = _cancellable.promise,
50
+ cancel = _cancellable.cancel;
51
+
52
+ return {
53
+ cancel: cancel,
54
+ next: function () {
55
+ var _next = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
56
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
57
+ while (1) {
58
+ switch (_context.prev = _context.next) {
59
+ case 0:
60
+ _context.next = 2;
61
+ return promise;
62
+
63
+ case 2:
64
+ _context.t0 = _context.sent;
65
+ return _context.abrupt("return", {
66
+ value: _context.t0,
67
+ done: true
68
+ });
69
+
70
+ case 4:
71
+ case "end":
72
+ return _context.stop();
73
+ }
74
+ }
75
+ }, _callee);
76
+ }));
77
+
78
+ function next() {
79
+ return _next.apply(this, arguments);
80
+ }
81
+
82
+ return next;
83
+ }()
84
+ };
85
+ } // Generator plugin
86
+
87
+
88
+ var cancellationCallbacks = [];
89
+ var cancelled = false;
90
+ return {
91
+ cancel: function cancel() {
92
+ cancelled = true;
93
+ cancellationCallbacks.forEach(function (cb) {
94
+ return cb();
95
+ });
96
+ },
97
+ next: function next() {
98
+ var _cancellable2 = cancellable(updates.next()),
99
+ promise = _cancellable2.promise,
100
+ cancel = _cancellable2.cancel;
101
+
102
+ if (cancelled) {
103
+ cancel();
104
+ } else {
105
+ cancellationCallbacks.push(cancel);
106
+ }
107
+
108
+ return promise;
109
+ }
110
+ };
111
+ };
@@ -1,5 +1,5 @@
1
1
  import { useRef } from 'react';
2
- import { isSafeUrl } from '../../ui/link-picker/url';
2
+ import { isSafeUrl } from '../../common/utils/url';
3
3
  export function useSearchQuery(state) {
4
4
  var _queryState$current;
5
5
 
@@ -0,0 +1,17 @@
1
+ import React, { useMemo } from 'react';
2
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
3
+ import { normalizeUrl } from '../../common/utils/url';
4
+ export function withLinkPickerAnalyticsContext(WrappedComponent) {
5
+ return function (props) {
6
+ var data = useMemo(function () {
7
+ return {
8
+ attributes: {
9
+ linkState: normalizeUrl(props.url) ? 'editLink' : 'newLink'
10
+ }
11
+ };
12
+ }, [props.url]);
13
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
14
+ data: data
15
+ }, /*#__PURE__*/React.createElement(WrappedComponent, props));
16
+ };
17
+ }
@@ -7,7 +7,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
7
7
  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) { _defineProperty(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; }
8
8
 
9
9
  /** @jsx jsx */
10
- import { Fragment, useCallback, useEffect, useLayoutEffect, useReducer } from 'react';
10
+ import { Fragment, useCallback, useEffect, useLayoutEffect, useReducer, memo } from 'react';
11
11
  import { jsx } from '@emotion/react';
12
12
  import { useIntl, FormattedMessage } from 'react-intl-next';
13
13
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
@@ -20,10 +20,11 @@ import createEventPayload from '../../analytics.codegen';
20
20
  import { ANALYTICS_CHANNEL } from '../../common/constants';
21
21
  import { usePlugins } from '../../services/use-plugins';
22
22
  import { useSearchQuery } from '../../services/use-search-query';
23
+ import { withLinkPickerAnalyticsContext } from '../../services/with-link-picker-analytics';
23
24
  import { messages } from './messages';
24
25
  import PanelTextInput from './text-input';
25
26
  import LinkSearchList from './link-search-list';
26
- import { normalizeUrl, isSafeUrl } from './url';
27
+ import { normalizeUrl, isSafeUrl } from '../../common/utils/url';
27
28
  import { rootContainerStyles, searchIconStyles, listTitleStyles, tabsWrapperStyles } from './styled';
28
29
  import { browser } from './browser';
29
30
  import Announcer from './announcer';
@@ -372,7 +373,7 @@ function LinkPicker(_ref) {
372
373
  }, intl.formatMessage(insertButtonMsg)))));
373
374
  }
374
375
 
375
- export default LinkPicker;
376
+ export default withLinkPickerAnalyticsContext( /*#__PURE__*/memo(LinkPicker));
376
377
 
377
378
  function getScreenReaderText(items, selectedIndex, intl) {
378
379
  if (items.length && selectedIndex > -1) {
@@ -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,12 +3,15 @@
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
- declare type FormSubmittedLinkPickerAttributesType = {};
10
- declare type InlineDialogViewedLinkPickerAttributesType = {};
11
- declare type InlineDialogClosedLinkPickerAttributesType = {};
9
+ export declare type LinkPickerAnalyticsContextType = {
10
+ linkState: 'editLink' | 'newLink';
11
+ };
12
+ export declare type FormSubmittedLinkPickerAttributesType = {};
13
+ export declare type InlineDialogViewedLinkPickerAttributesType = {};
14
+ export declare type InlineDialogClosedLinkPickerAttributesType = {};
12
15
  declare type AnalyticsEventAttributes = {
13
16
  'ui.form.submitted.linkPicker': FormSubmittedLinkPickerAttributesType;
14
17
  'ui.inlineDialog.viewed.linkPicker': InlineDialogViewedLinkPickerAttributesType;
@@ -0,0 +1,30 @@
1
+ /// <reference types="react" />
2
+ import { LinkSearchListItemData } from '../../ui/types';
3
+ export interface PluginState {
4
+ items: LinkSearchListItemData[] | null;
5
+ error: unknown | null;
6
+ isLoading: boolean;
7
+ }
8
+ export declare const ACTION_CLEAR = "CLEAR";
9
+ export declare const ACTION_LOADING = "LOADING";
10
+ export declare const ACTION_SUCCESS = "SUCCESS";
11
+ export declare const ACTION_ERRORED = "ERROR";
12
+ interface ClearAction {
13
+ type: typeof ACTION_CLEAR;
14
+ }
15
+ interface ResolveLoadingAction {
16
+ type: typeof ACTION_LOADING;
17
+ }
18
+ interface ResolveSuccessAction {
19
+ type: typeof ACTION_SUCCESS;
20
+ payload: Pick<PluginState, 'items' | 'isLoading'>;
21
+ }
22
+ interface ResolveErrorAction {
23
+ type: typeof ACTION_ERRORED;
24
+ payload: PluginState['error'];
25
+ }
26
+ export declare type ReducerAction = ClearAction | ResolveLoadingAction | ResolveSuccessAction | ResolveErrorAction;
27
+ export declare const INITIAL_STATE: PluginState;
28
+ export declare function reducer(state: PluginState, action: ReducerAction): PluginState;
29
+ export declare const usePluginReducer: () => [PluginState, import("react").Dispatch<ReducerAction>];
30
+ export {};