@atlaskit/link-picker 1.4.0 → 1.5.1
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 +308 -599
- 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/styled.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 +288 -467
- 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/styled.js +4 -0
- 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 +298 -601
- 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/styled.js +3 -2
- 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 -13
- package/dist/types/ui/link-picker/link-search-list/index.d.ts +3 -5
- package/dist/types/ui/link-picker/styled.d.ts +1 -0
- package/dist/types/ui/link-picker/text-input/index.d.ts +1 -1
- package/package.json +4 -3
|
@@ -2,30 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
|
-
exports.default = exports.RECENT_SEARCH_LIST_SIZE = void 0;
|
|
10
|
+
exports.testIds = exports.default = exports.RECENT_SEARCH_LIST_SIZE = void 0;
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
13
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
|
-
|
|
18
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
|
-
|
|
20
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
21
|
-
|
|
22
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
23
|
-
|
|
24
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
25
|
-
|
|
26
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
27
|
-
|
|
28
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
29
15
|
|
|
30
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
31
17
|
|
|
@@ -35,15 +21,23 @@ var _react2 = require("@emotion/react");
|
|
|
35
21
|
|
|
36
22
|
var _reactIntlNext = require("react-intl-next");
|
|
37
23
|
|
|
24
|
+
var _button = _interopRequireWildcard(require("@atlaskit/button"));
|
|
25
|
+
|
|
26
|
+
var _form = require("@atlaskit/form");
|
|
27
|
+
|
|
28
|
+
var _search = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/search"));
|
|
29
|
+
|
|
38
30
|
var _tabs = _interopRequireWildcard(require("@atlaskit/tabs"));
|
|
39
31
|
|
|
32
|
+
var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
|
|
33
|
+
|
|
40
34
|
var _messages = require("./messages");
|
|
41
35
|
|
|
42
36
|
var _textInput = _interopRequireDefault(require("./text-input"));
|
|
43
37
|
|
|
44
38
|
var _linkSearchList = _interopRequireDefault(require("./link-search-list"));
|
|
45
39
|
|
|
46
|
-
var
|
|
40
|
+
var _url2 = require("./url");
|
|
47
41
|
|
|
48
42
|
var _styled = require("./styled");
|
|
49
43
|
|
|
@@ -51,610 +45,333 @@ var _browser = require("./browser");
|
|
|
51
45
|
|
|
52
46
|
var _transformTimeStamp = require("./transformTimeStamp");
|
|
53
47
|
|
|
54
|
-
var _announcer = _interopRequireDefault(require("
|
|
55
|
-
|
|
56
|
-
var _button = _interopRequireWildcard(require("@atlaskit/button"));
|
|
57
|
-
|
|
58
|
-
var _form = require("@atlaskit/form");
|
|
59
|
-
|
|
60
|
-
var _search = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/search"));
|
|
61
|
-
|
|
62
|
-
var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
|
|
48
|
+
var _announcer = _interopRequireDefault(require("./announcer"));
|
|
63
49
|
|
|
64
50
|
var _linkSearchNoResults = _interopRequireDefault(require("./link-search-no-results"));
|
|
65
51
|
|
|
52
|
+
var _usePlugins2 = require("../../services/use-plugins");
|
|
53
|
+
|
|
66
54
|
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); }
|
|
67
55
|
|
|
68
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
56
|
+
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; }
|
|
69
57
|
|
|
70
58
|
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; }
|
|
71
59
|
|
|
72
60
|
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; }
|
|
73
61
|
|
|
74
|
-
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); }; }
|
|
75
|
-
|
|
76
|
-
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; } }
|
|
77
|
-
|
|
78
62
|
var RECENT_SEARCH_LIST_SIZE = 5;
|
|
79
63
|
exports.RECENT_SEARCH_LIST_SIZE = RECENT_SEARCH_LIST_SIZE;
|
|
64
|
+
var testIds = {
|
|
65
|
+
linkPicker: 'link-picker',
|
|
66
|
+
urlInputField: 'link-url',
|
|
67
|
+
textInputField: 'link-text',
|
|
68
|
+
searchIcon: 'link-picker-search-icon',
|
|
69
|
+
insertButton: 'link-picker-insert-button',
|
|
70
|
+
cancelButton: 'link-picker-cancel-button',
|
|
71
|
+
clearUrlButton: 'clear-text',
|
|
72
|
+
resultListTitle: 'link-picker-list-title',
|
|
73
|
+
emptyResultPage: 'link-search-no-results',
|
|
74
|
+
searchResultList: 'link-search-list',
|
|
75
|
+
searchResultItem: 'link-search-list-item',
|
|
76
|
+
searchResultLoadingIndicator: 'link-picker.results-loading-indicator',
|
|
77
|
+
urlError: 'link-error',
|
|
78
|
+
tabList: 'link-picker-tabs',
|
|
79
|
+
tabItem: 'link-picker-tab'
|
|
80
|
+
};
|
|
81
|
+
exports.testIds = testIds;
|
|
82
|
+
var initState = {
|
|
83
|
+
url: '',
|
|
84
|
+
displayText: '',
|
|
85
|
+
activeIndex: -1,
|
|
86
|
+
selectedIndex: -1,
|
|
87
|
+
invalidUrl: false,
|
|
88
|
+
activeTab: 0
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function reducer(state, payload) {
|
|
92
|
+
if (payload.url && state.url !== payload.url) {
|
|
93
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
94
|
+
invalidUrl: false,
|
|
95
|
+
selectedIndex: (0, _url2.isSafeUrl)(payload.url) && payload.url.length ? -1 : state.selectedIndex
|
|
96
|
+
}, payload);
|
|
97
|
+
}
|
|
80
98
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var _super = _createSuper(LinkPicker);
|
|
85
|
-
|
|
86
|
-
function LinkPicker(props) {
|
|
87
|
-
var _this;
|
|
88
|
-
|
|
89
|
-
(0, _classCallCheck2.default)(this, LinkPicker);
|
|
90
|
-
_this = _super.call(this, props);
|
|
91
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "queryVersion", 0);
|
|
92
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateInput", /*#__PURE__*/function () {
|
|
93
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(input) {
|
|
94
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
95
|
-
while (1) {
|
|
96
|
-
switch (_context.prev = _context.next) {
|
|
97
|
-
case 0:
|
|
98
|
-
if (!(input.length && (0, _url.isSafeUrl)(input))) {
|
|
99
|
-
_context.next = 2;
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return _context.abrupt("return", _this.setState({
|
|
104
|
-
url: input,
|
|
105
|
-
selectedIndex: -1,
|
|
106
|
-
items: [],
|
|
107
|
-
isLoading: false,
|
|
108
|
-
invalidUrl: null
|
|
109
|
-
}));
|
|
110
|
-
|
|
111
|
-
case 2:
|
|
112
|
-
return _context.abrupt("return", _this.setState({
|
|
113
|
-
url: input,
|
|
114
|
-
// Unset selection on any input change
|
|
115
|
-
selectedIndex: -1,
|
|
116
|
-
invalidUrl: null
|
|
117
|
-
}, function () {
|
|
118
|
-
_this.updateResults();
|
|
119
|
-
}));
|
|
120
|
-
|
|
121
|
-
case 3:
|
|
122
|
-
case "end":
|
|
123
|
-
return _context.stop();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}, _callee);
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
return function (_x) {
|
|
130
|
-
return _ref.apply(this, arguments);
|
|
131
|
-
};
|
|
132
|
-
}());
|
|
133
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createClearHandler", function (field) {
|
|
134
|
-
return function () {
|
|
135
|
-
switch (field) {
|
|
136
|
-
case 'url':
|
|
137
|
-
{
|
|
138
|
-
_this.updateInput('');
|
|
139
|
-
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
case 'displayText':
|
|
144
|
-
{
|
|
145
|
-
_this.setState((0, _defineProperty2.default)({}, field, ''));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getScreenReaderText", function () {
|
|
151
|
-
var intl = _this.props.intl;
|
|
152
|
-
var _this$state = _this.state,
|
|
153
|
-
items = _this$state.items,
|
|
154
|
-
selectedIndex = _this$state.selectedIndex;
|
|
155
|
-
|
|
156
|
-
if (items.length && selectedIndex > -1) {
|
|
157
|
-
var _items$selectedIndex = items[selectedIndex],
|
|
158
|
-
name = _items$selectedIndex.name,
|
|
159
|
-
container = _items$selectedIndex.container,
|
|
160
|
-
lastUpdatedDate = _items$selectedIndex.lastUpdatedDate,
|
|
161
|
-
lastViewedDate = _items$selectedIndex.lastViewedDate;
|
|
162
|
-
var date = (0, _transformTimeStamp.transformTimeStamp)(intl, lastViewedDate, lastUpdatedDate);
|
|
163
|
-
var formattedDate = [date === null || date === void 0 ? void 0 : date.pageAction, date === null || date === void 0 ? void 0 : date.dateString, date === null || date === void 0 ? void 0 : date.timeSince].filter(Boolean).join(' ');
|
|
164
|
-
return [name, container, formattedDate].filter(Boolean).join(', ');
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getTabs", function () {
|
|
168
|
-
if (_this.props.plugins && _this.props.plugins.length > 1) {
|
|
169
|
-
return _this.props.plugins.filter(function (plugin) {
|
|
170
|
-
return !!plugin.tabTitle;
|
|
171
|
-
}).map(function (plugin) {
|
|
172
|
-
return {
|
|
173
|
-
tabTitle: plugin.tabTitle
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return [];
|
|
179
|
-
});
|
|
180
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isUrlPopulatedWithSelectedItem", function () {
|
|
181
|
-
/**
|
|
182
|
-
* When we use ArrowKey to navigate through result items,
|
|
183
|
-
* the URL field will be populated with the content of
|
|
184
|
-
* selected item.
|
|
185
|
-
* This function will check if the URL field is populated
|
|
186
|
-
* with selected item.
|
|
187
|
-
* It can be useful to detect whether we want to insert a
|
|
188
|
-
* smartlink or a hyperlink with customized title
|
|
189
|
-
*/
|
|
190
|
-
var _this$state2 = _this.state,
|
|
191
|
-
items = _this$state2.items,
|
|
192
|
-
selectedIndex = _this$state2.selectedIndex,
|
|
193
|
-
url = _this$state2.url;
|
|
194
|
-
var selectedItem = items[selectedIndex];
|
|
195
|
-
|
|
196
|
-
if (selectedItem && selectedItem.url === url) {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
99
|
+
return _objectSpread(_objectSpread({}, state), payload);
|
|
100
|
+
}
|
|
199
101
|
|
|
200
|
-
|
|
102
|
+
function LinkPicker(_ref) {
|
|
103
|
+
var onSubmit = _ref.onSubmit,
|
|
104
|
+
onCancel = _ref.onCancel,
|
|
105
|
+
plugins = _ref.plugins,
|
|
106
|
+
initUrl = _ref.url,
|
|
107
|
+
initDisplayText = _ref.displayText;
|
|
108
|
+
|
|
109
|
+
var _useReducer = (0, _react.useReducer)(reducer, _objectSpread(_objectSpread({}, initState), {}, {
|
|
110
|
+
url: (0, _url2.normalizeUrl)(initUrl) || '',
|
|
111
|
+
displayText: initDisplayText || ''
|
|
112
|
+
})),
|
|
113
|
+
_useReducer2 = (0, _slicedToArray2.default)(_useReducer, 2),
|
|
114
|
+
state = _useReducer2[0],
|
|
115
|
+
dispatch = _useReducer2[1];
|
|
116
|
+
|
|
117
|
+
var activeIndex = state.activeIndex,
|
|
118
|
+
selectedIndex = state.selectedIndex,
|
|
119
|
+
url = state.url,
|
|
120
|
+
displayText = state.displayText,
|
|
121
|
+
invalidUrl = state.invalidUrl;
|
|
122
|
+
var isEditing = !!initUrl;
|
|
123
|
+
var intl = (0, _reactIntlNext.useIntl)();
|
|
124
|
+
|
|
125
|
+
var _usePlugins = (0, _usePlugins2.usePlugins)(state, plugins),
|
|
126
|
+
items = _usePlugins.items,
|
|
127
|
+
isLoading = _usePlugins.isLoading,
|
|
128
|
+
isSelectedItem = _usePlugins.isSelectedItem,
|
|
129
|
+
isActivePlugin = _usePlugins.isActivePlugin,
|
|
130
|
+
tabs = _usePlugins.tabs;
|
|
131
|
+
|
|
132
|
+
var handleChangeUrl = (0, _react.useCallback)(function (url) {
|
|
133
|
+
dispatch({
|
|
134
|
+
url: url
|
|
201
135
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
if (selectedItem) {
|
|
209
|
-
var url = selectedItem.url,
|
|
210
|
-
name = selectedItem.name;
|
|
211
|
-
|
|
212
|
-
_this.handleInsert(url, name, 'typeAhead');
|
|
213
|
-
}
|
|
136
|
+
}, []);
|
|
137
|
+
var handleChangeText = (0, _react.useCallback)(function (displayText) {
|
|
138
|
+
dispatch({
|
|
139
|
+
displayText: displayText
|
|
214
140
|
});
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
displayText: displayText || null,
|
|
225
|
-
title: title || null,
|
|
226
|
-
meta: {
|
|
227
|
-
inputMethod: inputType
|
|
228
|
-
}
|
|
229
|
-
}, inputType === 'manual' ? {
|
|
230
|
-
rawUrl: rawUrl
|
|
231
|
-
} : {}));
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseEnterResultItem", function (objectId) {
|
|
235
|
-
var items = _this.state.items;
|
|
236
|
-
var index = findIndex(items, function (item) {
|
|
237
|
-
return item.objectId === objectId;
|
|
238
|
-
});
|
|
141
|
+
}, []);
|
|
142
|
+
var handleKeyDown = (0, _react.useCallback)(function (event) {
|
|
143
|
+
var keyCode = event.keyCode;
|
|
144
|
+
var KEY_CODE_ARROW_DOWN = 40;
|
|
145
|
+
var KEY_CODE_ARROW_UP = 38;
|
|
146
|
+
|
|
147
|
+
if (!items || !items.length) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
239
150
|
|
|
240
|
-
|
|
241
|
-
activeIndex: index
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleMouseLeaveResultItem", function (objectId) {
|
|
245
|
-
var _this$state4 = _this.state,
|
|
246
|
-
items = _this$state4.items,
|
|
247
|
-
activeIndex = _this$state4.activeIndex;
|
|
248
|
-
var index = findIndex(items, function (item) {
|
|
249
|
-
return item.objectId === objectId;
|
|
250
|
-
}); // This is to avoid updating index that was set by other mouseenter event
|
|
251
|
-
|
|
252
|
-
if (activeIndex === index) {
|
|
253
|
-
_this.setState({
|
|
254
|
-
activeIndex: -1
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSubmit", function () {
|
|
259
|
-
var _this$state5 = _this.state,
|
|
260
|
-
url = _this$state5.url,
|
|
261
|
-
selectedIndex = _this$state5.selectedIndex,
|
|
262
|
-
items = _this$state5.items;
|
|
263
|
-
var intl = _this.props.intl;
|
|
264
|
-
var selectedItem = items[selectedIndex];
|
|
265
|
-
|
|
266
|
-
if (_this.isUrlPopulatedWithSelectedItem()) {
|
|
267
|
-
return _this.handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
|
|
268
|
-
}
|
|
151
|
+
var updatedIndex = activeIndex;
|
|
269
152
|
|
|
270
|
-
|
|
153
|
+
switch (keyCode) {
|
|
154
|
+
case KEY_CODE_ARROW_DOWN:
|
|
155
|
+
// down
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
updatedIndex = (activeIndex + 1) % items.length;
|
|
158
|
+
break;
|
|
271
159
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
160
|
+
case KEY_CODE_ARROW_UP:
|
|
161
|
+
// up
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
updatedIndex = activeIndex > 0 ? activeIndex - 1 : items.length - 1;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
275
166
|
|
|
276
|
-
|
|
277
|
-
|
|
167
|
+
if ([KEY_CODE_ARROW_DOWN, KEY_CODE_ARROW_UP].includes(keyCode) && items[updatedIndex]) {
|
|
168
|
+
dispatch({
|
|
169
|
+
activeIndex: updatedIndex,
|
|
170
|
+
selectedIndex: updatedIndex,
|
|
171
|
+
url: items[updatedIndex].url,
|
|
172
|
+
invalidUrl: false
|
|
278
173
|
});
|
|
174
|
+
}
|
|
175
|
+
}, [activeIndex, items]);
|
|
176
|
+
var handleClear = (0, _react.useCallback)(function (field) {
|
|
177
|
+
dispatch((0, _defineProperty2.default)({}, field, ''));
|
|
178
|
+
}, []);
|
|
179
|
+
var handleMouseEnterResultItem = (0, _react.useCallback)(function (objectId) {
|
|
180
|
+
var index = findIndex(items, function (item) {
|
|
181
|
+
return item.objectId === objectId;
|
|
279
182
|
});
|
|
280
|
-
(
|
|
281
|
-
|
|
282
|
-
items = _this$state6.items,
|
|
283
|
-
activeIndex = _this$state6.activeIndex;
|
|
284
|
-
var keyCode = event.keyCode;
|
|
285
|
-
var KEY_CODE_ARROW_DOWN = 40;
|
|
286
|
-
var KEY_CODE_ARROW_UP = 38;
|
|
287
|
-
|
|
288
|
-
if (!items || !items.length) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
var updatedIndex = activeIndex;
|
|
293
|
-
|
|
294
|
-
switch (keyCode) {
|
|
295
|
-
case KEY_CODE_ARROW_DOWN:
|
|
296
|
-
// down
|
|
297
|
-
event.preventDefault();
|
|
298
|
-
updatedIndex = (activeIndex + 1) % items.length;
|
|
299
|
-
break;
|
|
300
|
-
|
|
301
|
-
case KEY_CODE_ARROW_UP:
|
|
302
|
-
// up
|
|
303
|
-
event.preventDefault();
|
|
304
|
-
updatedIndex = activeIndex > 0 ? activeIndex - 1 : items.length - 1;
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if ([KEY_CODE_ARROW_DOWN, KEY_CODE_ARROW_UP].includes(keyCode) && items[updatedIndex]) {
|
|
309
|
-
_this.setState({
|
|
310
|
-
activeIndex: updatedIndex,
|
|
311
|
-
selectedIndex: updatedIndex,
|
|
312
|
-
url: items[updatedIndex].url,
|
|
313
|
-
invalidUrl: null
|
|
314
|
-
});
|
|
315
|
-
}
|
|
183
|
+
dispatch({
|
|
184
|
+
activeIndex: index
|
|
316
185
|
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
displayText: displayText
|
|
186
|
+
}, [items]);
|
|
187
|
+
var handleMouseLeaveResultItem = (0, _react.useCallback)(function (objectId) {
|
|
188
|
+
var index = findIndex(items, function (item) {
|
|
189
|
+
return item.objectId === objectId;
|
|
190
|
+
}); // This is to avoid updating index that was set by other mouseenter event
|
|
191
|
+
|
|
192
|
+
if (activeIndex === index) {
|
|
193
|
+
dispatch({
|
|
194
|
+
activeIndex: -1
|
|
327
195
|
});
|
|
196
|
+
}
|
|
197
|
+
}, [activeIndex, items]);
|
|
198
|
+
var handleInsert = (0, _react.useCallback)(function (url, title, inputType) {
|
|
199
|
+
onSubmit(_objectSpread({
|
|
200
|
+
url: url,
|
|
201
|
+
displayText: displayText || null,
|
|
202
|
+
title: title || null,
|
|
203
|
+
meta: {
|
|
204
|
+
inputMethod: inputType
|
|
205
|
+
}
|
|
206
|
+
}, inputType === 'manual' ? {
|
|
207
|
+
rawUrl: state.url
|
|
208
|
+
} : {}));
|
|
209
|
+
}, [displayText, onSubmit, state.url]);
|
|
210
|
+
var handleSelected = (0, _react.useCallback)(function (objectId) {
|
|
211
|
+
var selectedItem = items.find(function (item) {
|
|
212
|
+
return item.objectId === objectId;
|
|
328
213
|
});
|
|
329
|
-
_this.state = {
|
|
330
|
-
selectedIndex: -1,
|
|
331
|
-
activeIndex: -1,
|
|
332
|
-
isLoading: false,
|
|
333
|
-
isEditing: !!props.url,
|
|
334
|
-
url: (0, _url.normalizeUrl)(props.url) || '',
|
|
335
|
-
displayText: props.displayText || '',
|
|
336
|
-
items: [],
|
|
337
|
-
invalidUrl: null,
|
|
338
|
-
activePlugin: 0
|
|
339
|
-
};
|
|
340
|
-
/* Cache functions */
|
|
341
|
-
|
|
342
|
-
_this.handleClearUrl = _this.createClearHandler('url');
|
|
343
|
-
_this.handleClearDisplayText = _this.createClearHandler('displayText');
|
|
344
|
-
return _this;
|
|
345
|
-
}
|
|
346
214
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
215
|
+
if (selectedItem) {
|
|
216
|
+
var _url = selectedItem.url,
|
|
217
|
+
name = selectedItem.name;
|
|
218
|
+
handleInsert(_url, name, 'typeAhead');
|
|
351
219
|
}
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
var url = this.state.url;
|
|
220
|
+
}, [handleInsert, items]);
|
|
221
|
+
var handleSubmit = (0, _react.useCallback)(function () {
|
|
222
|
+
var selectedItem = items[selectedIndex];
|
|
356
223
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
224
|
+
if (isSelectedItem) {
|
|
225
|
+
return handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
|
|
360
226
|
}
|
|
361
|
-
}, {
|
|
362
|
-
key: "getActivePlugin",
|
|
363
|
-
value: function getActivePlugin() {
|
|
364
|
-
if (!this.props.plugins || this.props.plugins.length === 0) {
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
227
|
|
|
368
|
-
|
|
228
|
+
var normalized = (0, _url2.normalizeUrl)(url);
|
|
229
|
+
|
|
230
|
+
if (normalized) {
|
|
231
|
+
return handleInsert(normalized, null, 'manual');
|
|
369
232
|
}
|
|
370
|
-
/**
|
|
371
|
-
* Interface between link picker and plugins to update results
|
|
372
|
-
*/
|
|
373
|
-
|
|
374
|
-
}, {
|
|
375
|
-
key: "updateResults",
|
|
376
|
-
value: function () {
|
|
377
|
-
var _updateResults = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
378
|
-
var _this2 = this;
|
|
379
|
-
|
|
380
|
-
var queryVersion, activePlugin, updates, _loop, _ret;
|
|
381
|
-
|
|
382
|
-
return _regenerator.default.wrap(function _callee2$(_context3) {
|
|
383
|
-
while (1) {
|
|
384
|
-
switch (_context3.prev = _context3.next) {
|
|
385
|
-
case 0:
|
|
386
|
-
queryVersion = ++this.queryVersion;
|
|
387
|
-
activePlugin = this.getActivePlugin();
|
|
388
|
-
|
|
389
|
-
if (activePlugin) {
|
|
390
|
-
_context3.next = 4;
|
|
391
|
-
break;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return _context3.abrupt("return");
|
|
395
|
-
|
|
396
|
-
case 4:
|
|
397
|
-
updates = activePlugin.resolve({
|
|
398
|
-
query: this.state.url
|
|
399
|
-
});
|
|
400
|
-
this.setState({
|
|
401
|
-
isLoading: true,
|
|
402
|
-
items: []
|
|
403
|
-
});
|
|
404
|
-
_context3.prev = 6;
|
|
405
|
-
_loop = /*#__PURE__*/_regenerator.default.mark(function _loop() {
|
|
406
|
-
var done, value, _result$done, result;
|
|
407
|
-
|
|
408
|
-
return _regenerator.default.wrap(function _loop$(_context2) {
|
|
409
|
-
while (1) {
|
|
410
|
-
switch (_context2.prev = _context2.next) {
|
|
411
|
-
case 0:
|
|
412
|
-
done = false;
|
|
413
|
-
value = void 0;
|
|
414
|
-
|
|
415
|
-
if (!(updates instanceof Promise)) {
|
|
416
|
-
_context2.next = 9;
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
done = true;
|
|
421
|
-
_context2.next = 6;
|
|
422
|
-
return updates;
|
|
423
|
-
|
|
424
|
-
case 6:
|
|
425
|
-
value = _context2.sent;
|
|
426
|
-
_context2.next = 14;
|
|
427
|
-
break;
|
|
428
|
-
|
|
429
|
-
case 9:
|
|
430
|
-
_context2.next = 11;
|
|
431
|
-
return updates.next();
|
|
432
|
-
|
|
433
|
-
case 11:
|
|
434
|
-
result = _context2.sent;
|
|
435
|
-
done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
|
|
436
|
-
value = result.value;
|
|
437
|
-
|
|
438
|
-
case 14:
|
|
439
|
-
if (!(queryVersion !== _this2.queryVersion)) {
|
|
440
|
-
_context2.next = 16;
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
return _context2.abrupt("return", {
|
|
445
|
-
v: void 0
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
case 16:
|
|
449
|
-
_this2.setState(function (prev) {
|
|
450
|
-
return {
|
|
451
|
-
items: limit(value.data),
|
|
452
|
-
isLoading: !done
|
|
453
|
-
};
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
if (!done) {
|
|
457
|
-
_context2.next = 19;
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
return _context2.abrupt("return", {
|
|
462
|
-
v: void 0
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
case 19:
|
|
466
|
-
case "end":
|
|
467
|
-
return _context2.stop();
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}, _loop);
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
case 8:
|
|
474
|
-
if (!(queryVersion === this.queryVersion)) {
|
|
475
|
-
_context3.next = 15;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return _context3.delegateYield(_loop(), "t0", 10);
|
|
480
|
-
|
|
481
|
-
case 10:
|
|
482
|
-
_ret = _context3.t0;
|
|
483
|
-
|
|
484
|
-
if (!((0, _typeof2.default)(_ret) === "object")) {
|
|
485
|
-
_context3.next = 13;
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
return _context3.abrupt("return", _ret.v);
|
|
490
|
-
|
|
491
|
-
case 13:
|
|
492
|
-
_context3.next = 8;
|
|
493
|
-
break;
|
|
494
|
-
|
|
495
|
-
case 15:
|
|
496
|
-
_context3.next = 20;
|
|
497
|
-
break;
|
|
498
|
-
|
|
499
|
-
case 17:
|
|
500
|
-
_context3.prev = 17;
|
|
501
|
-
_context3.t1 = _context3["catch"](6);
|
|
502
|
-
this.setState({
|
|
503
|
-
isLoading: false
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
case 20:
|
|
507
|
-
case "end":
|
|
508
|
-
return _context3.stop();
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}, _callee2, this, [[6, 17]]);
|
|
512
|
-
}));
|
|
513
|
-
|
|
514
|
-
function updateResults() {
|
|
515
|
-
return _updateResults.apply(this, arguments);
|
|
516
|
-
}
|
|
517
233
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
error: this.state.invalidUrl,
|
|
597
|
-
clearLabel: formatMessage(_messages.messages.clearLink),
|
|
598
|
-
"aria-controls": linkSearchListId,
|
|
599
|
-
"aria-autocomplete": "list",
|
|
600
|
-
"aria-activedescendant": ariaActiveDescendant,
|
|
601
|
-
"aria-describedby": screenReaderDescriptionId,
|
|
602
|
-
"aria-expanded": true
|
|
603
|
-
}), (0, _react2.jsx)(_textInput.default, {
|
|
604
|
-
name: "link-text",
|
|
605
|
-
testId: "link-text",
|
|
606
|
-
autoComplete: "off",
|
|
607
|
-
label: linkTextLabel,
|
|
608
|
-
placeholder: linkTextPlaceHolder,
|
|
609
|
-
"aria-label": formatMessage(_messages.messages.linkAriaLabel),
|
|
610
|
-
value: displayText,
|
|
611
|
-
onSubmit: this.handleSubmit,
|
|
612
|
-
onKeyDown: this.handleKeyDown,
|
|
613
|
-
onChange: this.updateTextInput,
|
|
614
|
-
onClear: this.handleClearDisplayText,
|
|
615
|
-
clearLabel: formatMessage(_messages.messages.clearText)
|
|
616
|
-
}), !!items.length && (0, _react2.jsx)("div", {
|
|
617
|
-
css: _styled.listTitleStyles,
|
|
618
|
-
id: "link-picker-list-title",
|
|
619
|
-
"data-testid": "link-picker-list-title"
|
|
620
|
-
}, formatMessage(this.state.url ? _messages.messages.titleResults : _messages.messages.titleRecentlyViewed)), (0, _react2.jsx)(_visuallyHidden.default, null, (0, _react2.jsx)("span", {
|
|
621
|
-
"aria-live": "polite",
|
|
622
|
-
"aria-atomic": "true",
|
|
623
|
-
id: "fabric.smartcard.linkpicker.suggested.results"
|
|
624
|
-
}, url && formatMessage(_messages.messages.searchLinkResults, {
|
|
625
|
-
count: items.length
|
|
626
|
-
}))), (0, _react2.jsx)(_linkSearchList.default, {
|
|
627
|
-
ariaLabelledBy: "link-picker-list-title",
|
|
628
|
-
ariaControls: "fabric.smartcard.linkpicker.suggested.results",
|
|
629
|
-
id: linkSearchListId,
|
|
630
|
-
role: "listbox",
|
|
631
|
-
items: items,
|
|
632
|
-
isLoading: isLoading,
|
|
633
|
-
selectedIndex: selectedIndex,
|
|
634
|
-
activeIndex: activeIndex,
|
|
635
|
-
onSelect: this.handleSelected,
|
|
636
|
-
onMouseEnter: this.handleMouseEnterResultItem,
|
|
637
|
-
onMouseLeave: this.handleMouseLeaveResultItem
|
|
638
|
-
}), noResults && (0, _react2.jsx)(_linkSearchNoResults.default, {
|
|
639
|
-
testId: "link-search-no-results",
|
|
640
|
-
header: formatMessage(_messages.messages.noResults),
|
|
641
|
-
description: formatMessage(_messages.messages.noResultsDescription)
|
|
642
|
-
}), (0, _react2.jsx)(_form.FormFooter, {
|
|
643
|
-
align: "end"
|
|
644
|
-
}, (0, _react2.jsx)(_button.ButtonGroup, null, (0, _react2.jsx)(_button.default, {
|
|
645
|
-
appearance: "default",
|
|
646
|
-
onClick: this.handleCancel,
|
|
647
|
-
testId: "link-picker-cancel-button"
|
|
648
|
-
}, formatMessage(_messages.messages.cancelButton)), (0, _react2.jsx)(_button.default, {
|
|
649
|
-
type: "submit",
|
|
650
|
-
appearance: "primary",
|
|
651
|
-
onClick: this.handleSubmit,
|
|
652
|
-
testId: "link-picker-insert-button"
|
|
653
|
-
}, formatMessage(isEditing ? _messages.messages.saveButton : _messages.messages.insertButton)))));
|
|
234
|
+
return dispatch({
|
|
235
|
+
invalidUrl: true
|
|
236
|
+
});
|
|
237
|
+
}, [handleInsert, isSelectedItem, items, selectedIndex, url]);
|
|
238
|
+
var linkPlaceHolder = isActivePlugin ? _messages.messages.placeholder : _messages.messages.linkPlaceholder;
|
|
239
|
+
var linkListTitle = url ? _messages.messages.titleResults : _messages.messages.titleRecentlyViewed;
|
|
240
|
+
var insertButtonMsg = isEditing ? _messages.messages.saveButton : _messages.messages.insertButton;
|
|
241
|
+
var noResults = isActivePlugin && !isLoading && !items.length && !(0, _url2.isSafeUrl)(url);
|
|
242
|
+
var screenReaderDescriptionId = 'search-recent-links-field-description';
|
|
243
|
+
var linkSearchListId = 'link-picker-search-list';
|
|
244
|
+
var ariaActiveDescendant = selectedIndex > -1 ? "link-search-list-item-".concat(selectedIndex) : ''; // Added workaround with a screen reader Announcer specifically for VoiceOver + Safari
|
|
245
|
+
// as the Aria design pattern for combobox does not work in this case
|
|
246
|
+
// for details: https://a11y-internal.atlassian.net/browse/AK-740
|
|
247
|
+
|
|
248
|
+
var screenReaderText = _browser.browser.safari && getScreenReaderText(items, selectedIndex, intl);
|
|
249
|
+
var searchIcon = isActivePlugin && (0, _react2.jsx)("span", {
|
|
250
|
+
css: _styled.searchIconStyles,
|
|
251
|
+
"data-testid": testIds.searchIcon
|
|
252
|
+
}, (0, _react2.jsx)(_search.default, {
|
|
253
|
+
size: "medium",
|
|
254
|
+
label: ''
|
|
255
|
+
}));
|
|
256
|
+
return (0, _react2.jsx)("div", {
|
|
257
|
+
"data-testid": testIds.linkPicker,
|
|
258
|
+
css: _styled.rootContainerStyles
|
|
259
|
+
}, screenReaderText && (0, _react2.jsx)(_announcer.default, {
|
|
260
|
+
ariaLive: "assertive",
|
|
261
|
+
text: screenReaderText,
|
|
262
|
+
ariaRelevant: "additions",
|
|
263
|
+
delay: 250
|
|
264
|
+
}), (0, _react2.jsx)(_visuallyHidden.default, {
|
|
265
|
+
id: screenReaderDescriptionId
|
|
266
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, _messages.messages.searchLinkAriaDescription)), (0, _react2.jsx)(_textInput.default, {
|
|
267
|
+
role: "combobox",
|
|
268
|
+
autoComplete: "off",
|
|
269
|
+
name: "url",
|
|
270
|
+
testId: testIds.urlInputField,
|
|
271
|
+
label: intl.formatMessage(_messages.messages.linkLabel),
|
|
272
|
+
placeholder: intl.formatMessage(linkPlaceHolder),
|
|
273
|
+
value: url,
|
|
274
|
+
autoFocus: true,
|
|
275
|
+
elemBeforeInput: searchIcon,
|
|
276
|
+
clearLabel: intl.formatMessage(_messages.messages.clearLink),
|
|
277
|
+
"aria-expanded": true,
|
|
278
|
+
"aria-autocomplete": "list",
|
|
279
|
+
"aria-controls": linkSearchListId,
|
|
280
|
+
"aria-activedescendant": ariaActiveDescendant,
|
|
281
|
+
"aria-describedby": screenReaderDescriptionId,
|
|
282
|
+
error: invalidUrl ? intl.formatMessage(_messages.messages.linkInvalid) : null,
|
|
283
|
+
onClear: handleClear,
|
|
284
|
+
onSubmit: handleSubmit,
|
|
285
|
+
onKeyDown: handleKeyDown,
|
|
286
|
+
onChange: handleChangeUrl
|
|
287
|
+
}), (0, _react2.jsx)(_textInput.default, {
|
|
288
|
+
autoComplete: "off",
|
|
289
|
+
name: "displayText",
|
|
290
|
+
testId: testIds.textInputField,
|
|
291
|
+
value: displayText,
|
|
292
|
+
label: intl.formatMessage(_messages.messages.linkTextLabel),
|
|
293
|
+
placeholder: intl.formatMessage(_messages.messages.linkTextPlaceholder),
|
|
294
|
+
clearLabel: intl.formatMessage(_messages.messages.clearText),
|
|
295
|
+
"aria-label": intl.formatMessage(_messages.messages.linkAriaLabel),
|
|
296
|
+
onClear: handleClear,
|
|
297
|
+
onSubmit: handleSubmit,
|
|
298
|
+
onKeyDown: handleKeyDown,
|
|
299
|
+
onChange: handleChangeText
|
|
300
|
+
}), tabs.length > 0 && (0, _react2.jsx)("div", {
|
|
301
|
+
css: _styled.tabsWrapperStyles
|
|
302
|
+
}, (0, _react2.jsx)(_tabs.default, {
|
|
303
|
+
id: testIds.tabList,
|
|
304
|
+
testId: testIds.tabList,
|
|
305
|
+
onChange: function onChange(activeTab) {
|
|
306
|
+
return dispatch({
|
|
307
|
+
selectedIndex: -1,
|
|
308
|
+
activeIndex: -1,
|
|
309
|
+
invalidUrl: false,
|
|
310
|
+
activeTab: activeTab
|
|
311
|
+
});
|
|
654
312
|
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
|
|
313
|
+
}, (0, _react2.jsx)(_tabs.TabList, null, tabs.map(function (tab) {
|
|
314
|
+
return (0, _react2.jsx)(_tabs.Tab, {
|
|
315
|
+
key: tab.tabTitle,
|
|
316
|
+
testId: testIds.tabItem
|
|
317
|
+
}, tab.tabTitle);
|
|
318
|
+
})))), !!items.length && (0, _react2.jsx)("div", {
|
|
319
|
+
css: _styled.listTitleStyles,
|
|
320
|
+
id: testIds.resultListTitle,
|
|
321
|
+
"data-testid": testIds.resultListTitle
|
|
322
|
+
}, (0, _react2.jsx)(_reactIntlNext.FormattedMessage, linkListTitle)), (0, _react2.jsx)(_visuallyHidden.default, {
|
|
323
|
+
id: "fabric.smartcard.linkpicker.suggested.results"
|
|
324
|
+
}, url && (0, _react2.jsx)(_reactIntlNext.FormattedMessage, (0, _extends2.default)({}, _messages.messages.searchLinkResults, {
|
|
325
|
+
values: {
|
|
326
|
+
count: items.length
|
|
327
|
+
},
|
|
328
|
+
"aria-live": "polite",
|
|
329
|
+
"aria-atomic": "true"
|
|
330
|
+
}))), (0, _react2.jsx)(_linkSearchList.default, {
|
|
331
|
+
ariaLabelledBy: testIds.resultListTitle,
|
|
332
|
+
ariaControls: "fabric.smartcard.linkpicker.suggested.results",
|
|
333
|
+
id: linkSearchListId,
|
|
334
|
+
role: "listbox",
|
|
335
|
+
items: items,
|
|
336
|
+
isLoading: isLoading,
|
|
337
|
+
selectedIndex: selectedIndex,
|
|
338
|
+
activeIndex: activeIndex,
|
|
339
|
+
onSelect: handleSelected,
|
|
340
|
+
onMouseEnter: handleMouseEnterResultItem,
|
|
341
|
+
onMouseLeave: handleMouseLeaveResultItem
|
|
342
|
+
}), noResults && (0, _react2.jsx)(_linkSearchNoResults.default, {
|
|
343
|
+
testId: testIds.emptyResultPage,
|
|
344
|
+
header: intl.formatMessage(_messages.messages.noResults),
|
|
345
|
+
description: intl.formatMessage(_messages.messages.noResultsDescription)
|
|
346
|
+
}), (0, _react2.jsx)(_form.FormFooter, {
|
|
347
|
+
align: "end"
|
|
348
|
+
}, (0, _react2.jsx)(_button.ButtonGroup, null, (0, _react2.jsx)(_button.default, {
|
|
349
|
+
appearance: "default",
|
|
350
|
+
onClick: onCancel,
|
|
351
|
+
testId: testIds.cancelButton
|
|
352
|
+
}, intl.formatMessage(_messages.messages.cancelButton)), (0, _react2.jsx)(_button.default, {
|
|
353
|
+
type: "submit",
|
|
354
|
+
appearance: "primary",
|
|
355
|
+
onClick: handleSubmit,
|
|
356
|
+
testId: testIds.insertButton
|
|
357
|
+
}, intl.formatMessage(insertButtonMsg)))));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
var _default = LinkPicker;
|
|
361
|
+
exports.default = _default;
|
|
362
|
+
|
|
363
|
+
function getScreenReaderText(items, selectedIndex, intl) {
|
|
364
|
+
if (items.length && selectedIndex > -1) {
|
|
365
|
+
var _items$selectedIndex = items[selectedIndex],
|
|
366
|
+
name = _items$selectedIndex.name,
|
|
367
|
+
container = _items$selectedIndex.container,
|
|
368
|
+
lastUpdatedDate = _items$selectedIndex.lastUpdatedDate,
|
|
369
|
+
lastViewedDate = _items$selectedIndex.lastViewedDate;
|
|
370
|
+
var date = (0, _transformTimeStamp.transformTimeStamp)(intl, lastViewedDate, lastUpdatedDate);
|
|
371
|
+
var formattedDate = [date === null || date === void 0 ? void 0 : date.pageAction, date === null || date === void 0 ? void 0 : date.dateString, date === null || date === void 0 ? void 0 : date.timeSince].filter(Boolean).join(' ');
|
|
372
|
+
return [name, container, formattedDate].filter(Boolean).join(', ');
|
|
373
|
+
}
|
|
374
|
+
}
|
|
658
375
|
|
|
659
376
|
function findIndex(array, predicate) {
|
|
660
377
|
var index = -1;
|
|
@@ -667,12 +384,4 @@ function findIndex(array, predicate) {
|
|
|
667
384
|
return false;
|
|
668
385
|
});
|
|
669
386
|
return index;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function limit(items) {
|
|
673
|
-
return items.slice(0, RECENT_SEARCH_LIST_SIZE);
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
var _default = (0, _reactIntlNext.injectIntl)(LinkPicker);
|
|
677
|
-
|
|
678
|
-
exports.default = _default;
|
|
387
|
+
}
|