@atlaskit/link-picker 0.11.0 → 1.1.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/example-helpers/mock-data.ts +0 -2
  3. package/package.json +7 -4
  4. package/report.api.md +65 -0
  5. package/dist/cjs/browser.js +0 -39
  6. package/dist/cjs/index.js +0 -13
  7. package/dist/cjs/messages.js +0 -102
  8. package/dist/cjs/transformTimeStamp.js +0 -55
  9. package/dist/cjs/types.js +0 -5
  10. package/dist/cjs/ui/announcer.js +0 -64
  11. package/dist/cjs/ui/link-picker.js +0 -604
  12. package/dist/cjs/ui/link-search-list/index.js +0 -102
  13. package/dist/cjs/ui/link-search-list/styled.js +0 -21
  14. package/dist/cjs/ui/list-item/index.js +0 -103
  15. package/dist/cjs/ui/list-item/styled.js +0 -59
  16. package/dist/cjs/ui/styled.js +0 -32
  17. package/dist/cjs/ui/text-input/index.js +0 -116
  18. package/dist/cjs/ui/text-input/styled.js +0 -25
  19. package/dist/cjs/url.js +0 -104
  20. package/dist/cjs/utils.js +0 -27
  21. package/dist/cjs/version.json +0 -5
  22. package/dist/es2019/browser.js +0 -34
  23. package/dist/es2019/index.js +0 -1
  24. package/dist/es2019/messages.js +0 -93
  25. package/dist/es2019/transformTimeStamp.js +0 -41
  26. package/dist/es2019/types.js +0 -1
  27. package/dist/es2019/ui/announcer.js +0 -38
  28. package/dist/es2019/ui/link-picker.js +0 -493
  29. package/dist/es2019/ui/link-search-list/index.js +0 -60
  30. package/dist/es2019/ui/link-search-list/styled.js +0 -13
  31. package/dist/es2019/ui/list-item/index.js +0 -88
  32. package/dist/es2019/ui/list-item/styled.js +0 -65
  33. package/dist/es2019/ui/styled.js +0 -28
  34. package/dist/es2019/ui/text-input/index.js +0 -99
  35. package/dist/es2019/ui/text-input/styled.js +0 -15
  36. package/dist/es2019/url.js +0 -88
  37. package/dist/es2019/utils.js +0 -13
  38. package/dist/es2019/version.json +0 -5
  39. package/dist/esm/browser.js +0 -34
  40. package/dist/esm/index.js +0 -1
  41. package/dist/esm/messages.js +0 -93
  42. package/dist/esm/transformTimeStamp.js +0 -41
  43. package/dist/esm/types.js +0 -1
  44. package/dist/esm/ui/announcer.js +0 -51
  45. package/dist/esm/ui/link-picker.js +0 -582
  46. package/dist/esm/ui/link-search-list/index.js +0 -88
  47. package/dist/esm/ui/link-search-list/styled.js +0 -8
  48. package/dist/esm/ui/list-item/index.js +0 -90
  49. package/dist/esm/ui/list-item/styled.js +0 -37
  50. package/dist/esm/ui/styled.js +0 -16
  51. package/dist/esm/ui/text-input/index.js +0 -99
  52. package/dist/esm/ui/text-input/styled.js +0 -10
  53. package/dist/esm/url.js +0 -90
  54. package/dist/esm/utils.js +0 -13
  55. package/dist/esm/version.json +0 -5
  56. package/dist/types/browser.d.ts +0 -15
  57. package/dist/types/index.d.ts +0 -3
  58. package/dist/types/messages.d.ts +0 -92
  59. package/dist/types/transformTimeStamp.d.ts +0 -3
  60. package/dist/types/types.d.ts +0 -40
  61. package/dist/types/ui/announcer.d.ts +0 -22
  62. package/dist/types/ui/link-picker.d.ts +0 -51
  63. package/dist/types/ui/link-search-list/index.d.ts +0 -20
  64. package/dist/types/ui/link-search-list/styled.d.ts +0 -3
  65. package/dist/types/ui/list-item/index.d.ts +0 -17
  66. package/dist/types/ui/list-item/styled.d.ts +0 -7
  67. package/dist/types/ui/styled.d.ts +0 -4
  68. package/dist/types/ui/text-input/index.d.ts +0 -17
  69. package/dist/types/ui/text-input/styled.d.ts +0 -2
  70. package/dist/types/url.d.ts +0 -5
  71. package/dist/types/utils.d.ts +0 -3
@@ -1,51 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { forwardRef, memo, useState, useEffect } from 'react'; // How to use:
3
- // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions#Preferring_specialized_live_region_roles
4
- // Demo: https://dequeuniversity.com/library/aria/liveregion-playground
5
- // Important: Strongly recommend test your solution in all supported screen readers
6
- // if you use non default value of properties: ariaAtomic, ariaLive, ariaRelevant, role
7
- // Note: Text won't be announced if the text message doesn't change after the render.
8
- // For using a forced announcement in this case, set the 'key' attribute - key={Date.now()}
9
-
10
- // Note: Flag 'contentRendered' resolves bug with duplicates messages (NVDA + Firefox)
11
- // https://github.com/nvaccess/nvda/labels/bug%2Fdouble-speaking
12
- var timer;
13
- var Announcer = /*#__PURE__*/forwardRef(function (_ref, ref) {
14
- var _ref$ariaAtomic = _ref.ariaAtomic,
15
- ariaAtomic = _ref$ariaAtomic === void 0 ? 'true' : _ref$ariaAtomic,
16
- _ref$ariaLive = _ref.ariaLive,
17
- ariaLive = _ref$ariaLive === void 0 ? 'polite' : _ref$ariaLive,
18
- _ref$ariaRelevant = _ref.ariaRelevant,
19
- ariaRelevant = _ref$ariaRelevant === void 0 ? 'all' : _ref$ariaRelevant,
20
- _ref$role = _ref.role,
21
- role = _ref$role === void 0 ? 'status' : _ref$role,
22
- _ref$text = _ref.text,
23
- text = _ref$text === void 0 ? '' : _ref$text,
24
- _ref$delay = _ref.delay,
25
- delay = _ref$delay === void 0 ? 0 : _ref$delay;
26
-
27
- var _useState = useState(false),
28
- _useState2 = _slicedToArray(_useState, 2),
29
- contentRendered = _useState2[0],
30
- setContentRendered = _useState2[1];
31
-
32
- useEffect(function () {
33
- clearTimeout(timer);
34
- setContentRendered(false);
35
- timer = setTimeout(function () {
36
- setContentRendered(true);
37
- }, delay);
38
- return function () {
39
- return clearTimeout(timer);
40
- };
41
- }, [text, delay]);
42
- return /*#__PURE__*/React.createElement("div", {
43
- className: "assistive",
44
- ref: ref,
45
- role: role,
46
- "aria-atomic": ariaAtomic,
47
- "aria-relevant": ariaRelevant,
48
- "aria-live": ariaLive
49
- }, contentRendered && /*#__PURE__*/React.createElement("span", null, text));
50
- });
51
- export default /*#__PURE__*/memo(Announcer);
@@ -1,582 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
6
- import _inherits from "@babel/runtime/helpers/inherits";
7
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
8
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
9
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
-
11
- 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; }
12
-
13
- 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; }
14
-
15
- 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); }; }
16
-
17
- 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; } }
18
-
19
- /** @jsx jsx */
20
- import React, { PureComponent } from 'react';
21
- import { jsx } from '@emotion/react';
22
- import { injectIntl } from 'react-intl-next';
23
- import { messages } from '../messages';
24
- import PanelTextInput from './text-input';
25
- import LinkSearchList from './link-search-list';
26
- import { normalizeUrl, isSafeUrl } from '../url';
27
- import { recentListStyles, containerStyles, searchIconStyles, listTitleStyles } from './styled';
28
- import { browser } from '../browser';
29
- import { transformTimeStamp } from '../transformTimeStamp';
30
- import Announcer from './announcer';
31
- import Button, { ButtonGroup } from '@atlaskit/button';
32
- import { FormFooter } from '@atlaskit/form';
33
- import EditorSearchIcon from '@atlaskit/icon/glyph/editor/search';
34
- import VisuallyHidden from '@atlaskit/visually-hidden';
35
- export var RECENT_SEARCH_LIST_SIZE = 5;
36
-
37
- var LinkPicker = /*#__PURE__*/function (_PureComponent) {
38
- _inherits(LinkPicker, _PureComponent);
39
-
40
- var _super = _createSuper(LinkPicker);
41
-
42
- function LinkPicker(props) {
43
- var _this;
44
-
45
- _classCallCheck(this, LinkPicker);
46
-
47
- _this = _super.call(this, props);
48
-
49
- _defineProperty(_assertThisInitialized(_this), "wrapperRef", /*#__PURE__*/React.createRef());
50
-
51
- _defineProperty(_assertThisInitialized(_this), "queryVersion", 0);
52
-
53
- _defineProperty(_assertThisInitialized(_this), "updateInput", /*#__PURE__*/function () {
54
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input) {
55
- return _regeneratorRuntime.wrap(function _callee$(_context) {
56
- while (1) {
57
- switch (_context.prev = _context.next) {
58
- case 0:
59
- if (!(input.length && isSafeUrl(input))) {
60
- _context.next = 2;
61
- break;
62
- }
63
-
64
- return _context.abrupt("return", _this.setState({
65
- url: input,
66
- selectedIndex: -1,
67
- items: [],
68
- isLoading: false,
69
- invalidUrl: null
70
- }));
71
-
72
- case 2:
73
- return _context.abrupt("return", _this.setState({
74
- url: input,
75
- // Unset selection on any input change
76
- selectedIndex: -1,
77
- invalidUrl: null
78
- }, function () {
79
- _this.updateResults();
80
- }));
81
-
82
- case 3:
83
- case "end":
84
- return _context.stop();
85
- }
86
- }
87
- }, _callee);
88
- }));
89
-
90
- return function (_x) {
91
- return _ref.apply(this, arguments);
92
- };
93
- }());
94
-
95
- _defineProperty(_assertThisInitialized(_this), "createClearHandler", function (field) {
96
- return function () {
97
- switch (field) {
98
- case 'url':
99
- {
100
- _this.updateInput('');
101
-
102
- break;
103
- }
104
-
105
- case 'displayText':
106
- {
107
- _this.setState(_defineProperty({}, field, ''));
108
- }
109
- }
110
- };
111
- });
112
-
113
- _defineProperty(_assertThisInitialized(_this), "getScreenReaderText", function () {
114
- var intl = _this.props.intl;
115
- var _this$state = _this.state,
116
- items = _this$state.items,
117
- selectedIndex = _this$state.selectedIndex;
118
-
119
- if (items.length && selectedIndex > -1) {
120
- var _items$selectedIndex = items[selectedIndex],
121
- name = _items$selectedIndex.name,
122
- container = _items$selectedIndex.container,
123
- lastUpdatedDate = _items$selectedIndex.lastUpdatedDate,
124
- lastViewedDate = _items$selectedIndex.lastViewedDate;
125
- var date = transformTimeStamp(intl, lastViewedDate, lastUpdatedDate);
126
- 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(' ');
127
- return [name, container, formattedDate].filter(Boolean).join(', ');
128
- }
129
- });
130
-
131
- _defineProperty(_assertThisInitialized(_this), "isUrlPopulatedWithSelectedItem", function () {
132
- /**
133
- * When we use ArrowKey to navigate through result items,
134
- * the URL field will be populated with the content of
135
- * selected item.
136
- * This function will check if the URL field is populated
137
- * with selected item.
138
- * It can be useful to detect whether we want to insert a
139
- * smartlink or a hyperlink with customized title
140
- */
141
- var _this$state2 = _this.state,
142
- items = _this$state2.items,
143
- selectedIndex = _this$state2.selectedIndex,
144
- url = _this$state2.url;
145
- var selectedItem = items[selectedIndex];
146
-
147
- if (selectedItem && selectedItem.url === url) {
148
- return true;
149
- }
150
-
151
- return false;
152
- });
153
-
154
- _defineProperty(_assertThisInitialized(_this), "handleSelected", function (objectId) {
155
- var items = _this.state.items;
156
- var selectedItem = items.find(function (item) {
157
- return item.objectId === objectId;
158
- });
159
-
160
- if (selectedItem) {
161
- var url = selectedItem.url,
162
- name = selectedItem.name;
163
-
164
- _this.handleInsert(url, name, 'typeAhead');
165
- }
166
- });
167
-
168
- _defineProperty(_assertThisInitialized(_this), "handleInsert", function (url, title, inputType) {
169
- var onSubmit = _this.props.onSubmit;
170
- var _this$state3 = _this.state,
171
- rawUrl = _this$state3.url,
172
- displayText = _this$state3.displayText;
173
-
174
- if (onSubmit) {
175
- onSubmit(_objectSpread({
176
- url: url,
177
- displayText: displayText || null,
178
- title: title || null,
179
- meta: {
180
- inputMethod: inputType
181
- }
182
- }, inputType === 'manual' ? {
183
- rawUrl: rawUrl
184
- } : {}));
185
- }
186
- });
187
-
188
- _defineProperty(_assertThisInitialized(_this), "handleMouseEnterResultItem", function (objectId) {
189
- var items = _this.state.items;
190
- var index = findIndex(items, function (item) {
191
- return item.objectId === objectId;
192
- });
193
-
194
- _this.setState({
195
- activeIndex: index
196
- });
197
- });
198
-
199
- _defineProperty(_assertThisInitialized(_this), "handleMouseLeaveResultItem", function (objectId) {
200
- var _this$state4 = _this.state,
201
- items = _this$state4.items,
202
- activeIndex = _this$state4.activeIndex;
203
- var index = findIndex(items, function (item) {
204
- return item.objectId === objectId;
205
- }); // This is to avoid updating index that was set by other mouseenter event
206
-
207
- if (activeIndex === index) {
208
- _this.setState({
209
- activeIndex: -1
210
- });
211
- }
212
- });
213
-
214
- _defineProperty(_assertThisInitialized(_this), "handleSubmit", function () {
215
- var _this$state5 = _this.state,
216
- url = _this$state5.url,
217
- selectedIndex = _this$state5.selectedIndex,
218
- items = _this$state5.items;
219
- var selectedItem = items[selectedIndex];
220
-
221
- if (_this.isUrlPopulatedWithSelectedItem()) {
222
- _this.handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
223
- } else if (url.length > 0) {
224
- var normalized = normalizeUrl(url);
225
-
226
- if (normalized) {
227
- _this.handleInsert(normalized, null, 'manual');
228
- } else {
229
- var intl = _this.props.intl;
230
- var linkInvalid = intl.formatMessage(messages.linkInvalid);
231
-
232
- _this.setState({
233
- invalidUrl: linkInvalid
234
- });
235
- }
236
- }
237
- });
238
-
239
- _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (event) {
240
- var _this$state6 = _this.state,
241
- items = _this$state6.items,
242
- activeIndex = _this$state6.activeIndex;
243
- var keyCode = event.keyCode;
244
- var KEY_CODE_ARROW_DOWN = 40;
245
- var KEY_CODE_ARROW_UP = 38;
246
-
247
- if (!items || !items.length) {
248
- return;
249
- }
250
-
251
- var updatedIndex = activeIndex;
252
-
253
- switch (keyCode) {
254
- case KEY_CODE_ARROW_DOWN:
255
- // down
256
- event.preventDefault();
257
- updatedIndex = (activeIndex + 1) % items.length;
258
- break;
259
-
260
- case KEY_CODE_ARROW_UP:
261
- // up
262
- event.preventDefault();
263
- updatedIndex = activeIndex > 0 ? activeIndex - 1 : items.length - 1;
264
- break;
265
- }
266
-
267
- if ([KEY_CODE_ARROW_DOWN, KEY_CODE_ARROW_UP].includes(keyCode) && items[updatedIndex]) {
268
- _this.setState({
269
- activeIndex: updatedIndex,
270
- selectedIndex: updatedIndex,
271
- url: items[updatedIndex].url,
272
- invalidUrl: null
273
- });
274
- }
275
- });
276
-
277
- _defineProperty(_assertThisInitialized(_this), "handleCancel", function () {
278
- var onCancel = _this.props.onCancel;
279
-
280
- if (onCancel) {
281
- onCancel();
282
- }
283
- });
284
-
285
- _defineProperty(_assertThisInitialized(_this), "updateTextInput", function (displayText) {
286
- _this.setState({
287
- displayText: displayText
288
- });
289
- });
290
-
291
- _this.state = {
292
- selectedIndex: -1,
293
- activeIndex: -1,
294
- isLoading: false,
295
- url: normalizeUrl(props.url) || '',
296
- displayText: props.displayText || '',
297
- items: [],
298
- invalidUrl: null
299
- };
300
- /* Cache functions */
301
-
302
- _this.handleClearUrl = _this.createClearHandler('url');
303
- _this.handleClearDisplayText = _this.createClearHandler('displayText');
304
- return _this;
305
- }
306
-
307
- _createClass(LinkPicker, [{
308
- key: "componentDidMount",
309
- value: function componentDidMount() {
310
- this.loadInitialLinkSearchResult();
311
- }
312
- }, {
313
- key: "loadInitialLinkSearchResult",
314
- value: function loadInitialLinkSearchResult() {
315
- var url = this.state.url;
316
-
317
- if (!url) {
318
- this.updateResults();
319
- }
320
- }
321
- }, {
322
- key: "getActivePlugin",
323
- value: function getActivePlugin() {
324
- if (!this.props.plugins || this.props.plugins.length === 0) {
325
- return null;
326
- }
327
-
328
- return this.props.plugins[0];
329
- }
330
- /**
331
- * Interface between link picker and plugins to update results
332
- */
333
-
334
- }, {
335
- key: "updateResults",
336
- value: function () {
337
- var _updateResults = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
338
- var queryVersion, activePlugin, updates, done, value, _result$done, result;
339
-
340
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
341
- while (1) {
342
- switch (_context2.prev = _context2.next) {
343
- case 0:
344
- queryVersion = ++this.queryVersion;
345
- activePlugin = this.getActivePlugin();
346
-
347
- if (activePlugin) {
348
- _context2.next = 4;
349
- break;
350
- }
351
-
352
- return _context2.abrupt("return");
353
-
354
- case 4:
355
- updates = activePlugin.resolve({
356
- query: this.state.url
357
- });
358
- this.setState({
359
- isLoading: true,
360
- items: []
361
- });
362
- _context2.prev = 6;
363
-
364
- case 7:
365
- if (!(queryVersion === this.queryVersion)) {
366
- _context2.next = 29;
367
- break;
368
- }
369
-
370
- done = false;
371
- value = void 0;
372
-
373
- if (!(updates instanceof Promise)) {
374
- _context2.next = 17;
375
- break;
376
- }
377
-
378
- done = true;
379
- _context2.next = 14;
380
- return updates;
381
-
382
- case 14:
383
- value = _context2.sent;
384
- _context2.next = 22;
385
- break;
386
-
387
- case 17:
388
- _context2.next = 19;
389
- return updates.next();
390
-
391
- case 19:
392
- result = _context2.sent;
393
- done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
394
- value = result.value;
395
-
396
- case 22:
397
- if (!(queryVersion !== this.queryVersion)) {
398
- _context2.next = 24;
399
- break;
400
- }
401
-
402
- return _context2.abrupt("return");
403
-
404
- case 24:
405
- this.setState({
406
- items: limit(value.data),
407
- isLoading: !done
408
- });
409
-
410
- if (!done) {
411
- _context2.next = 27;
412
- break;
413
- }
414
-
415
- return _context2.abrupt("return");
416
-
417
- case 27:
418
- _context2.next = 7;
419
- break;
420
-
421
- case 29:
422
- _context2.next = 34;
423
- break;
424
-
425
- case 31:
426
- _context2.prev = 31;
427
- _context2.t0 = _context2["catch"](6);
428
- this.setState({
429
- isLoading: false
430
- });
431
-
432
- case 34:
433
- case "end":
434
- return _context2.stop();
435
- }
436
- }
437
- }, _callee2, this, [[6, 31]]);
438
- }));
439
-
440
- function updateResults() {
441
- return _updateResults.apply(this, arguments);
442
- }
443
-
444
- return updateResults;
445
- }()
446
- }, {
447
- key: "render",
448
- value: function render() {
449
- var _this$state7 = this.state,
450
- items = _this$state7.items,
451
- isLoading = _this$state7.isLoading,
452
- activeIndex = _this$state7.activeIndex,
453
- selectedIndex = _this$state7.selectedIndex,
454
- url = _this$state7.url,
455
- displayText = _this$state7.displayText;
456
- var formatMessage = this.props.intl.formatMessage;
457
- var activePlugin = this.getActivePlugin();
458
- var linkPlaceHolder = formatMessage(activePlugin ? messages.placeholder : messages.linkPlaceholder);
459
- var linkLabel = formatMessage(messages.linkLabel);
460
- var linkTextLabel = formatMessage(messages.linkTextLabel);
461
- var linkTextPlaceHolder = formatMessage(messages.linkTextPlaceholder);
462
- var screenReaderDescriptionId = 'search-recent-links-field-description';
463
- var linkSearchListId = 'link-picker-search-list';
464
- var ariaActiveDescendant = selectedIndex > -1 ? "link-search-list-item-".concat(selectedIndex) : ''; // Added workaround with a screen reader Announcer specifically for VoiceOver + Safari
465
- // as the Aria design pattern for combobox does not work in this case
466
- // for details: https://a11y-internal.atlassian.net/browse/AK-740
467
-
468
- var screenReaderText = browser.safari && this.getScreenReaderText();
469
- var searchIcon = activePlugin && jsx("span", {
470
- css: searchIconStyles,
471
- "data-testid": "link-picker-search-icon"
472
- }, jsx(EditorSearchIcon, {
473
- size: "medium",
474
- label: ''
475
- }));
476
- return jsx("div", {
477
- "data-testid": "link-picker",
478
- className: "recent-list",
479
- css: recentListStyles
480
- }, jsx("div", {
481
- css: containerStyles,
482
- ref: this.wrapperRef
483
- }, screenReaderText && jsx(Announcer, {
484
- ariaLive: "assertive",
485
- text: screenReaderText,
486
- ariaRelevant: "additions",
487
- delay: 250
488
- }), jsx(VisuallyHidden, null, jsx("span", {
489
- "aria-hidden": "true",
490
- id: screenReaderDescriptionId
491
- }, formatMessage(messages.searchLinkAriaDescription))), jsx(PanelTextInput, {
492
- name: "link",
493
- testId: "link-url",
494
- role: "combobox",
495
- label: linkLabel,
496
- placeholder: linkPlaceHolder,
497
- value: url,
498
- autoFocus: true,
499
- autoComplete: "off",
500
- elemBeforeInput: searchIcon,
501
- onSubmit: this.handleSubmit,
502
- onChange: this.updateInput,
503
- onKeyDown: this.handleKeyDown,
504
- onClear: this.handleClearUrl,
505
- error: this.state.invalidUrl,
506
- clearLabel: formatMessage(messages.clearLink),
507
- "aria-controls": linkSearchListId,
508
- "aria-autocomplete": "list",
509
- "aria-activedescendant": ariaActiveDescendant,
510
- "aria-describedby": screenReaderDescriptionId,
511
- "aria-expanded": true
512
- }), jsx(PanelTextInput, {
513
- name: "link-text",
514
- testId: "link-text",
515
- autoComplete: "off",
516
- label: linkTextLabel,
517
- placeholder: linkTextPlaceHolder,
518
- "aria-label": formatMessage(messages.linkAriaLabel),
519
- value: displayText,
520
- onSubmit: this.handleSubmit,
521
- onKeyDown: this.handleKeyDown,
522
- onChange: this.updateTextInput,
523
- onClear: this.handleClearDisplayText,
524
- clearLabel: formatMessage(messages.clearText)
525
- }), !!items.length && jsx("div", {
526
- css: listTitleStyles,
527
- id: "link-picker-list-title",
528
- "data-testid": "link-picker-list-title"
529
- }, formatMessage(this.state.url ? messages.titleResults : messages.titleRecentlyViewed)), jsx(VisuallyHidden, null, jsx("span", {
530
- "aria-live": "polite",
531
- "aria-atomic": "true",
532
- id: "fabric.smartcard.linkpicker.suggested.results"
533
- }, url && formatMessage(messages.searchLinkResults, {
534
- count: items.length
535
- }))), jsx(LinkSearchList, {
536
- ariaLabelledBy: "link-picker-list-title",
537
- ariaControls: "fabric.smartcard.linkpicker.suggested.results",
538
- id: linkSearchListId,
539
- role: "listbox",
540
- items: items,
541
- isLoading: isLoading,
542
- selectedIndex: selectedIndex,
543
- activeIndex: activeIndex,
544
- onSelect: this.handleSelected,
545
- onMouseEnter: this.handleMouseEnterResultItem,
546
- onMouseLeave: this.handleMouseLeaveResultItem
547
- }), jsx(FormFooter, {
548
- align: "end"
549
- }, jsx(ButtonGroup, null, jsx(Button, {
550
- appearance: "default",
551
- onClick: this.handleCancel,
552
- testId: "link-picker-cancel-button"
553
- }, formatMessage(messages.cancelButton)), jsx(Button, {
554
- type: "submit",
555
- appearance: "primary",
556
- onClick: this.handleSubmit,
557
- testId: "link-picker-insert-button"
558
- }, formatMessage(messages.insertButton))))));
559
- }
560
- }]);
561
-
562
- return LinkPicker;
563
- }(PureComponent);
564
-
565
- function findIndex(array, predicate) {
566
- var index = -1;
567
- array.some(function (item, i) {
568
- if (predicate(item)) {
569
- index = i;
570
- return true;
571
- }
572
-
573
- return false;
574
- });
575
- return index;
576
- }
577
-
578
- function limit(items) {
579
- return items.slice(0, RECENT_SEARCH_LIST_SIZE);
580
- }
581
-
582
- export var LinkPickerWithIntl = injectIntl(LinkPicker);