@atlaskit/link-picker 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/services/use-plugins/index.js +201 -0
- package/dist/cjs/ui/link-picker/index.js +297 -519
- package/dist/cjs/ui/link-picker/link-search-list/index.js +54 -82
- package/dist/cjs/ui/link-picker/list-item/index.js +5 -3
- package/dist/cjs/ui/link-picker/text-input/index.js +6 -4
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/services/use-plugins/index.js +122 -0
- package/dist/es2019/ui/link-picker/index.js +281 -435
- package/dist/es2019/ui/link-picker/link-search-list/index.js +49 -50
- package/dist/es2019/ui/link-picker/list-item/index.js +4 -3
- package/dist/es2019/ui/link-picker/text-input/index.js +5 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/services/use-plugins/index.js +187 -0
- package/dist/esm/ui/link-picker/index.js +291 -526
- package/dist/esm/ui/link-picker/link-search-list/index.js +51 -79
- package/dist/esm/ui/link-picker/list-item/index.js +4 -3
- package/dist/esm/ui/link-picker/text-input/index.js +5 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/services/use-plugins/index.d.ts +12 -0
- package/dist/types/ui/link-picker/index.d.ts +24 -12
- package/dist/types/ui/link-picker/link-search-list/index.d.ts +3 -5
- package/dist/types/ui/link-picker/text-input/index.d.ts +1 -1
- package/dist/types/ui/types.d.ts +4 -0
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/link-picker
|
|
2
2
|
|
|
3
|
+
## 1.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`e54051625bc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e54051625bc) - Convert Link Picker from class component to functional component to comply with tangerine guidelines.
|
|
8
|
+
https://tangerine.staging.atl-paas.net/guides/components-and-hooks-patterns/prefer-functional-components-over-classes/
|
|
9
|
+
|
|
10
|
+
## 1.4.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`140453ba9f6`](https://bitbucket.org/atlassian/atlassian-frontend/commits/140453ba9f6) - [ux] Move tabs to be below input fields
|
|
15
|
+
|
|
16
|
+
## 1.4.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- [`3b5e61f9b3b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3b5e61f9b3b) - [ux] Adds in TAB UI support for Link Picker
|
|
21
|
+
|
|
3
22
|
## 1.3.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.usePlugins = usePlugins;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
|
+
var _react = require("react");
|
|
19
|
+
|
|
20
|
+
var _linkPicker = require("../../ui/link-picker");
|
|
21
|
+
|
|
22
|
+
var _url = require("../../ui/link-picker/url");
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
function reducer(state, payload) {
|
|
29
|
+
return _objectSpread(_objectSpread({}, state), payload);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function usePlugins(state, plugins) {
|
|
33
|
+
var _useReducer = (0, _react.useReducer)(reducer, {
|
|
34
|
+
items: [],
|
|
35
|
+
isLoading: false
|
|
36
|
+
}),
|
|
37
|
+
_useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
|
|
38
|
+
pluginState = _useReducer2[0],
|
|
39
|
+
dispatch = _useReducer2[1];
|
|
40
|
+
|
|
41
|
+
var url = state.url,
|
|
42
|
+
selectedIndex = state.selectedIndex;
|
|
43
|
+
var items = pluginState.items,
|
|
44
|
+
isLoading = pluginState.isLoading;
|
|
45
|
+
var activePlugin = !plugins || plugins.length === 0 ? null : plugins[state.activeTab];
|
|
46
|
+
var queryVersion = (0, _react.useRef)(0);
|
|
47
|
+
var pluginRef = (0, _react.useRef)(activePlugin);
|
|
48
|
+
var selectedItem = items[selectedIndex];
|
|
49
|
+
var isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
|
|
50
|
+
(0, _react.useEffect)(function () {
|
|
51
|
+
if (!activePlugin) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isSelectedItem) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if ((0, _url.isSafeUrl)(url) && url.length) {
|
|
60
|
+
dispatch({
|
|
61
|
+
items: [],
|
|
62
|
+
isLoading: false
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var updates = activePlugin.resolve({
|
|
68
|
+
query: url
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
if (pluginRef.current !== activePlugin) {
|
|
72
|
+
dispatch({
|
|
73
|
+
items: [],
|
|
74
|
+
isLoading: true
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
dispatch({
|
|
78
|
+
isLoading: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var newQuery = ++queryVersion.current;
|
|
83
|
+
|
|
84
|
+
var updateResults = /*#__PURE__*/function () {
|
|
85
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
86
|
+
var done, value, _result$done, result;
|
|
87
|
+
|
|
88
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
89
|
+
while (1) {
|
|
90
|
+
switch (_context.prev = _context.next) {
|
|
91
|
+
case 0:
|
|
92
|
+
_context.prev = 0;
|
|
93
|
+
|
|
94
|
+
case 1:
|
|
95
|
+
if (!(newQuery === queryVersion.current)) {
|
|
96
|
+
_context.next = 23;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
done = false;
|
|
101
|
+
value = void 0;
|
|
102
|
+
|
|
103
|
+
if (!(updates instanceof Promise)) {
|
|
104
|
+
_context.next = 11;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
done = true;
|
|
109
|
+
_context.next = 8;
|
|
110
|
+
return updates;
|
|
111
|
+
|
|
112
|
+
case 8:
|
|
113
|
+
value = _context.sent;
|
|
114
|
+
_context.next = 16;
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
case 11:
|
|
118
|
+
_context.next = 13;
|
|
119
|
+
return updates.next();
|
|
120
|
+
|
|
121
|
+
case 13:
|
|
122
|
+
result = _context.sent;
|
|
123
|
+
done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
|
|
124
|
+
value = result.value;
|
|
125
|
+
|
|
126
|
+
case 16:
|
|
127
|
+
if (!(newQuery !== queryVersion.current)) {
|
|
128
|
+
_context.next = 18;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return _context.abrupt("return");
|
|
133
|
+
|
|
134
|
+
case 18:
|
|
135
|
+
dispatch({
|
|
136
|
+
items: limit(value.data),
|
|
137
|
+
isLoading: !done
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (!done) {
|
|
141
|
+
_context.next = 21;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return _context.abrupt("return");
|
|
146
|
+
|
|
147
|
+
case 21:
|
|
148
|
+
_context.next = 1;
|
|
149
|
+
break;
|
|
150
|
+
|
|
151
|
+
case 23:
|
|
152
|
+
_context.next = 28;
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
case 25:
|
|
156
|
+
_context.prev = 25;
|
|
157
|
+
_context.t0 = _context["catch"](0);
|
|
158
|
+
dispatch({
|
|
159
|
+
isLoading: false
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
case 28:
|
|
163
|
+
case "end":
|
|
164
|
+
return _context.stop();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, _callee, null, [[0, 25]]);
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
return function updateResults() {
|
|
171
|
+
return _ref.apply(this, arguments);
|
|
172
|
+
};
|
|
173
|
+
}();
|
|
174
|
+
|
|
175
|
+
updateResults();
|
|
176
|
+
}, [activePlugin, queryVersion, url, isSelectedItem]);
|
|
177
|
+
var tabs = (0, _react.useMemo)(function () {
|
|
178
|
+
if (!plugins || plugins.length <= 1) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return plugins.filter(function (plugin) {
|
|
183
|
+
return !!plugin.tabTitle;
|
|
184
|
+
}).map(function (plugin) {
|
|
185
|
+
return {
|
|
186
|
+
tabTitle: plugin.tabTitle
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}, [plugins]);
|
|
190
|
+
return {
|
|
191
|
+
tabs: tabs,
|
|
192
|
+
items: items,
|
|
193
|
+
isLoading: isLoading,
|
|
194
|
+
isSelectedItem: isSelectedItem,
|
|
195
|
+
isActivePlugin: !!activePlugin
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function limit(items) {
|
|
200
|
+
return items.slice(0, _linkPicker.RECENT_SEARCH_LIST_SIZE);
|
|
201
|
+
}
|