@atlaskit/link-picker 0.0.2 → 0.7.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/README.md +27 -5
  3. package/dist/cjs/browser.js +39 -0
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/messages.js +102 -0
  6. package/dist/cjs/styles.js +90 -0
  7. package/dist/cjs/transformTimeStamp.js +55 -0
  8. package/dist/cjs/types.js +5 -0
  9. package/dist/cjs/ui/LinkSearchList.js +112 -0
  10. package/dist/cjs/ui/LinkSearchListItem.js +101 -0
  11. package/dist/cjs/ui/PanelTextInput.js +119 -0
  12. package/dist/cjs/ui/announcer.js +64 -0
  13. package/dist/cjs/ui/link-picker.js +584 -0
  14. package/dist/cjs/url.js +104 -0
  15. package/dist/cjs/utils.js +40 -0
  16. package/dist/cjs/version.json +1 -1
  17. package/dist/es2019/browser.js +34 -0
  18. package/dist/es2019/index.js +1 -1
  19. package/dist/es2019/messages.js +93 -0
  20. package/dist/es2019/styles.js +94 -0
  21. package/dist/es2019/transformTimeStamp.js +41 -0
  22. package/dist/es2019/types.js +1 -0
  23. package/dist/es2019/ui/LinkSearchList.js +65 -0
  24. package/dist/es2019/ui/LinkSearchListItem.js +88 -0
  25. package/dist/es2019/ui/PanelTextInput.js +93 -0
  26. package/dist/es2019/ui/announcer.js +38 -0
  27. package/dist/es2019/ui/link-picker.js +480 -0
  28. package/dist/es2019/url.js +88 -0
  29. package/dist/es2019/utils.js +24 -0
  30. package/dist/es2019/version.json +1 -1
  31. package/dist/esm/browser.js +34 -0
  32. package/dist/esm/index.js +1 -1
  33. package/dist/esm/messages.js +93 -0
  34. package/dist/esm/styles.js +46 -0
  35. package/dist/esm/transformTimeStamp.js +41 -0
  36. package/dist/esm/types.js +1 -0
  37. package/dist/esm/ui/LinkSearchList.js +87 -0
  38. package/dist/esm/ui/LinkSearchListItem.js +88 -0
  39. package/dist/esm/ui/PanelTextInput.js +93 -0
  40. package/dist/esm/ui/announcer.js +51 -0
  41. package/dist/esm/ui/link-picker.js +559 -0
  42. package/dist/esm/url.js +90 -0
  43. package/dist/esm/utils.js +24 -0
  44. package/dist/esm/version.json +1 -1
  45. package/dist/types/browser.d.ts +15 -0
  46. package/dist/types/index.d.ts +3 -1
  47. package/dist/types/messages.d.ts +92 -0
  48. package/dist/types/styles.d.ts +18 -0
  49. package/dist/types/transformTimeStamp.d.ts +3 -0
  50. package/dist/types/types.d.ts +37 -0
  51. package/dist/types/ui/LinkSearchList.d.ts +20 -0
  52. package/dist/types/ui/LinkSearchListItem.d.ts +17 -0
  53. package/dist/types/ui/PanelTextInput.d.ts +17 -0
  54. package/dist/types/ui/announcer.d.ts +22 -0
  55. package/dist/types/ui/link-picker.d.ts +79 -0
  56. package/dist/types/url.d.ts +5 -0
  57. package/dist/types/utils.d.ts +4 -0
  58. package/example-helpers/flight-deck/_manifest.json +9 -0
  59. package/example-helpers/flight-deck/mockFDResponse.json +133 -0
  60. package/example-helpers/mock-data.ts +316 -0
  61. package/example-helpers/providers.ts +39 -0
  62. package/package.json +35 -6
  63. package/dist/cjs/link-picker.js +0 -12
  64. package/dist/es2019/link-picker.js +0 -3
  65. package/dist/esm/link-picker.js +0 -3
  66. package/dist/types/link-picker.d.ts +0 -1
@@ -0,0 +1,559 @@
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/core';
22
+ import { injectIntl } from 'react-intl-next';
23
+ import { messages } from '../messages';
24
+ import PanelTextInput from './PanelTextInput';
25
+ import LinkSearchList from './LinkSearchList';
26
+ import { normalizeUrl, isSafeUrl } from '../url';
27
+ import { recentListStyles, Container, SearchIconWrapper, ListTitleStyles } from '../styles';
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
+ export var LinkPicker = /*#__PURE__*/function (_PureComponent) {
37
+ _inherits(LinkPicker, _PureComponent);
38
+
39
+ var _super = _createSuper(LinkPicker);
40
+
41
+ function LinkPicker(props) {
42
+ var _this;
43
+
44
+ _classCallCheck(this, LinkPicker);
45
+
46
+ _this = _super.call(this, props);
47
+
48
+ _defineProperty(_assertThisInitialized(_this), "wrapperRef", /*#__PURE__*/React.createRef());
49
+
50
+ _defineProperty(_assertThisInitialized(_this), "queryVersion", 0);
51
+
52
+ _defineProperty(_assertThisInitialized(_this), "updateInput", /*#__PURE__*/function () {
53
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(input) {
54
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
55
+ while (1) {
56
+ switch (_context.prev = _context.next) {
57
+ case 0:
58
+ if (!(input.length && isSafeUrl(input))) {
59
+ _context.next = 2;
60
+ break;
61
+ }
62
+
63
+ return _context.abrupt("return", _this.setState({
64
+ url: input,
65
+ selectedIndex: -1,
66
+ items: [],
67
+ isLoading: false,
68
+ invalidUrl: null
69
+ }));
70
+
71
+ case 2:
72
+ return _context.abrupt("return", _this.setState({
73
+ url: input,
74
+ // Unset selection on any input change
75
+ selectedIndex: -1,
76
+ invalidUrl: null
77
+ }, function () {
78
+ _this.updateResults();
79
+ }));
80
+
81
+ case 3:
82
+ case "end":
83
+ return _context.stop();
84
+ }
85
+ }
86
+ }, _callee);
87
+ }));
88
+
89
+ return function (_x) {
90
+ return _ref.apply(this, arguments);
91
+ };
92
+ }());
93
+
94
+ _defineProperty(_assertThisInitialized(_this), "createClearHandler", function (field) {
95
+ return function () {
96
+ switch (field) {
97
+ case 'url':
98
+ {
99
+ _this.updateInput('');
100
+
101
+ break;
102
+ }
103
+
104
+ case 'displayText':
105
+ {
106
+ _this.setState(_defineProperty({}, field, ''));
107
+ }
108
+ }
109
+ };
110
+ });
111
+
112
+ _defineProperty(_assertThisInitialized(_this), "getScreenReaderText", function () {
113
+ var intl = _this.props.intl;
114
+ var _this$state = _this.state,
115
+ items = _this$state.items,
116
+ selectedIndex = _this$state.selectedIndex;
117
+
118
+ if (items.length && selectedIndex > -1) {
119
+ var _items$selectedIndex = items[selectedIndex],
120
+ name = _items$selectedIndex.name,
121
+ container = _items$selectedIndex.container,
122
+ lastUpdatedDate = _items$selectedIndex.lastUpdatedDate,
123
+ lastViewedDate = _items$selectedIndex.lastViewedDate;
124
+ var date = transformTimeStamp(intl, lastViewedDate, lastUpdatedDate);
125
+ return "".concat(name, ", ").concat(container, ", ").concat(date === null || date === void 0 ? void 0 : date.pageAction, " ").concat(date === null || date === void 0 ? void 0 : date.dateString, " ").concat((date === null || date === void 0 ? void 0 : date.timeSince) || '');
126
+ }
127
+ });
128
+
129
+ _defineProperty(_assertThisInitialized(_this), "isUrlPopulatedWithSelectedItem", function () {
130
+ /**
131
+ * When we use ArrowKey to navigate through result items,
132
+ * the URL field will be populated with the content of
133
+ * selected item.
134
+ * This function will check if the URL field is populated
135
+ * with selected item.
136
+ * It can be useful to detect whether we want to insert a
137
+ * smartlink or a hyperlink with customized title
138
+ */
139
+ var _this$state2 = _this.state,
140
+ items = _this$state2.items,
141
+ selectedIndex = _this$state2.selectedIndex,
142
+ url = _this$state2.url;
143
+ var selectedItem = items[selectedIndex];
144
+
145
+ if (selectedItem && selectedItem.url === url) {
146
+ return true;
147
+ }
148
+
149
+ return false;
150
+ });
151
+
152
+ _defineProperty(_assertThisInitialized(_this), "handleSelected", function (objectId) {
153
+ var items = _this.state.items;
154
+ var selectedItem = items.find(function (item) {
155
+ return item.objectId === objectId;
156
+ });
157
+
158
+ if (selectedItem) {
159
+ var url = selectedItem.url,
160
+ name = selectedItem.name;
161
+
162
+ _this.handleInsert(url, name, 'typeAhead');
163
+ }
164
+ });
165
+
166
+ _defineProperty(_assertThisInitialized(_this), "handleInsert", function (url, title, inputType) {
167
+ var onSubmit = _this.props.onSubmit;
168
+ var _this$state3 = _this.state,
169
+ rawUrl = _this$state3.url,
170
+ displayText = _this$state3.displayText;
171
+
172
+ if (onSubmit) {
173
+ onSubmit(_objectSpread({
174
+ url: url,
175
+ displayText: displayText || null,
176
+ title: title || null,
177
+ meta: {
178
+ inputMethod: inputType
179
+ }
180
+ }, inputType === 'manual' ? {
181
+ rawUrl: rawUrl
182
+ } : {}));
183
+ }
184
+ });
185
+
186
+ _defineProperty(_assertThisInitialized(_this), "handleMouseEnterResultItem", function (objectId) {
187
+ var items = _this.state.items;
188
+ var index = findIndex(items, function (item) {
189
+ return item.objectId === objectId;
190
+ });
191
+
192
+ _this.setState({
193
+ activeIndex: index
194
+ });
195
+ });
196
+
197
+ _defineProperty(_assertThisInitialized(_this), "handleMouseLeaveResultItem", function (objectId) {
198
+ var _this$state4 = _this.state,
199
+ items = _this$state4.items,
200
+ activeIndex = _this$state4.activeIndex;
201
+ var index = findIndex(items, function (item) {
202
+ return item.objectId === objectId;
203
+ }); // This is to avoid updating index that was set by other mouseenter event
204
+
205
+ if (activeIndex === index) {
206
+ _this.setState({
207
+ activeIndex: -1
208
+ });
209
+ }
210
+ });
211
+
212
+ _defineProperty(_assertThisInitialized(_this), "handleSubmit", function () {
213
+ var _this$state5 = _this.state,
214
+ url = _this$state5.url,
215
+ selectedIndex = _this$state5.selectedIndex,
216
+ items = _this$state5.items;
217
+ var selectedItem = items[selectedIndex];
218
+
219
+ if (_this.isUrlPopulatedWithSelectedItem()) {
220
+ _this.handleInsert(selectedItem.url, selectedItem.name, 'typeAhead');
221
+ } else if (url.length > 0) {
222
+ var normalized = normalizeUrl(url);
223
+
224
+ if (normalized) {
225
+ _this.handleInsert(normalized, null, 'manual');
226
+ } else {
227
+ var intl = _this.props.intl;
228
+ var linkInvalid = intl.formatMessage(messages.linkInvalid);
229
+
230
+ _this.setState({
231
+ invalidUrl: linkInvalid
232
+ });
233
+ }
234
+ }
235
+ });
236
+
237
+ _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (event) {
238
+ var _this$state6 = _this.state,
239
+ items = _this$state6.items,
240
+ activeIndex = _this$state6.activeIndex;
241
+ var keyCode = event.keyCode;
242
+ var KEY_CODE_ARROW_DOWN = 40;
243
+ var KEY_CODE_ARROW_UP = 38;
244
+
245
+ if (!items || !items.length) {
246
+ return;
247
+ }
248
+
249
+ var updatedIndex = activeIndex;
250
+
251
+ switch (keyCode) {
252
+ case KEY_CODE_ARROW_DOWN:
253
+ // down
254
+ event.preventDefault();
255
+ updatedIndex = (activeIndex + 1) % items.length;
256
+ break;
257
+
258
+ case KEY_CODE_ARROW_UP:
259
+ // up
260
+ event.preventDefault();
261
+ updatedIndex = activeIndex > 0 ? activeIndex - 1 : items.length - 1;
262
+ break;
263
+ }
264
+
265
+ if ([KEY_CODE_ARROW_DOWN, KEY_CODE_ARROW_UP].includes(keyCode) && items[updatedIndex]) {
266
+ _this.setState({
267
+ activeIndex: updatedIndex,
268
+ selectedIndex: updatedIndex,
269
+ url: items[updatedIndex].url,
270
+ invalidUrl: null
271
+ });
272
+ }
273
+ });
274
+
275
+ _defineProperty(_assertThisInitialized(_this), "handleCancel", function () {
276
+ var onCancel = _this.props.onCancel;
277
+
278
+ if (onCancel) {
279
+ onCancel();
280
+ }
281
+ });
282
+
283
+ _defineProperty(_assertThisInitialized(_this), "updateTextInput", function (displayText) {
284
+ _this.setState({
285
+ displayText: displayText
286
+ });
287
+ });
288
+
289
+ _this.state = {
290
+ selectedIndex: -1,
291
+ activeIndex: -1,
292
+ isLoading: false,
293
+ url: normalizeUrl(props.url) || '',
294
+ displayText: props.displayText || '',
295
+ items: [],
296
+ invalidUrl: null
297
+ };
298
+ /* Cache functions */
299
+
300
+ _this.handleClearUrl = _this.createClearHandler('url');
301
+ _this.handleClearDisplayText = _this.createClearHandler('displayText');
302
+ return _this;
303
+ }
304
+
305
+ _createClass(LinkPicker, [{
306
+ key: "componentDidMount",
307
+ value: function componentDidMount() {
308
+ this.loadInitialLinkSearchResult();
309
+ }
310
+ }, {
311
+ key: "loadInitialLinkSearchResult",
312
+ value: function loadInitialLinkSearchResult() {
313
+ var url = this.state.url;
314
+
315
+ if (!url) {
316
+ this.updateResults();
317
+ }
318
+ }
319
+ }, {
320
+ key: "getActivePlugin",
321
+ value: function getActivePlugin() {
322
+ if (!this.props.plugins) {
323
+ return null;
324
+ }
325
+
326
+ return this.props.plugins[0];
327
+ }
328
+ /**
329
+ * Interface between link picker and plugins to update results
330
+ */
331
+
332
+ }, {
333
+ key: "updateResults",
334
+ value: function () {
335
+ var _updateResults = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
336
+ var queryVersion, activePlugin, updates, _yield$updates$next, done, value;
337
+
338
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
339
+ while (1) {
340
+ switch (_context2.prev = _context2.next) {
341
+ case 0:
342
+ queryVersion = ++this.queryVersion;
343
+ activePlugin = this.getActivePlugin();
344
+
345
+ if (activePlugin) {
346
+ _context2.next = 4;
347
+ break;
348
+ }
349
+
350
+ return _context2.abrupt("return");
351
+
352
+ case 4:
353
+ updates = activePlugin.resolve({
354
+ query: this.state.url
355
+ });
356
+ this.setState({
357
+ isLoading: true,
358
+ items: []
359
+ });
360
+ _context2.prev = 6;
361
+
362
+ case 7:
363
+ if (!(queryVersion === this.queryVersion)) {
364
+ _context2.next = 20;
365
+ break;
366
+ }
367
+
368
+ _context2.next = 10;
369
+ return updates.next();
370
+
371
+ case 10:
372
+ _yield$updates$next = _context2.sent;
373
+ done = _yield$updates$next.done;
374
+ value = _yield$updates$next.value;
375
+
376
+ if (!(queryVersion !== this.queryVersion)) {
377
+ _context2.next = 15;
378
+ break;
379
+ }
380
+
381
+ return _context2.abrupt("return");
382
+
383
+ case 15:
384
+ this.setState({
385
+ items: limit(value),
386
+ isLoading: !done
387
+ });
388
+
389
+ if (!done) {
390
+ _context2.next = 18;
391
+ break;
392
+ }
393
+
394
+ return _context2.abrupt("return");
395
+
396
+ case 18:
397
+ _context2.next = 7;
398
+ break;
399
+
400
+ case 20:
401
+ _context2.next = 25;
402
+ break;
403
+
404
+ case 22:
405
+ _context2.prev = 22;
406
+ _context2.t0 = _context2["catch"](6);
407
+ this.setState({
408
+ isLoading: false
409
+ });
410
+
411
+ case 25:
412
+ case "end":
413
+ return _context2.stop();
414
+ }
415
+ }
416
+ }, _callee2, this, [[6, 22]]);
417
+ }));
418
+
419
+ function updateResults() {
420
+ return _updateResults.apply(this, arguments);
421
+ }
422
+
423
+ return updateResults;
424
+ }()
425
+ }, {
426
+ key: "render",
427
+ value: function render() {
428
+ var _this$state7 = this.state,
429
+ items = _this$state7.items,
430
+ isLoading = _this$state7.isLoading,
431
+ activeIndex = _this$state7.activeIndex,
432
+ selectedIndex = _this$state7.selectedIndex,
433
+ url = _this$state7.url,
434
+ displayText = _this$state7.displayText;
435
+ var formatMessage = this.props.intl.formatMessage;
436
+ var activePlugin = this.getActivePlugin();
437
+ var linkPlaceHolder = formatMessage(activePlugin ? messages.placeholder : messages.linkPlaceholder);
438
+ var linkLabel = formatMessage(messages.linkLabel);
439
+ var linkTextLabel = formatMessage(messages.linkTextLabel);
440
+ var linkTextPlaceHolder = formatMessage(messages.linkTextPlaceholder);
441
+ var screenReaderDescriptionId = 'search-recent-links-field-description';
442
+ var linkSearchListId = 'link-picker-search-list';
443
+ var ariaActiveDescendant = selectedIndex > -1 ? "link-search-list-item-".concat(selectedIndex) : ''; // Added workaround with a screen reader Announcer specifically for VoiceOver + Safari
444
+ // as the Aria design pattern for combobox does not work in this case
445
+ // for details: https://a11y-internal.atlassian.net/browse/AK-740
446
+
447
+ var screenReaderText = browser.safari && this.getScreenReaderText();
448
+ var searchIcon = activePlugin && jsx(SearchIconWrapper, {
449
+ "data-testid": "link-picker-search-icon"
450
+ }, jsx(EditorSearchIcon, {
451
+ size: "medium",
452
+ label: ''
453
+ }));
454
+ return jsx("div", {
455
+ "data-testid": "link-picker",
456
+ className: "recent-list",
457
+ css: recentListStyles
458
+ }, jsx(Container, {
459
+ innerRef: this.wrapperRef
460
+ }, screenReaderText && jsx(Announcer, {
461
+ ariaLive: "assertive",
462
+ text: screenReaderText,
463
+ ariaRelevant: "additions",
464
+ delay: 250
465
+ }), jsx(VisuallyHidden, null, jsx("span", {
466
+ "aria-hidden": "true",
467
+ id: screenReaderDescriptionId
468
+ }, formatMessage(messages.searchLinkAriaDescription))), jsx(PanelTextInput, {
469
+ name: "link",
470
+ testId: "link-url",
471
+ role: "combobox",
472
+ label: linkLabel,
473
+ placeholder: linkPlaceHolder,
474
+ value: url,
475
+ autoFocus: true,
476
+ autoComplete: "off",
477
+ elemBeforeInput: searchIcon,
478
+ onSubmit: this.handleSubmit,
479
+ onChange: this.updateInput,
480
+ onKeyDown: this.handleKeyDown,
481
+ onClear: this.handleClearUrl,
482
+ error: this.state.invalidUrl,
483
+ clearLabel: formatMessage(messages.clearLink),
484
+ "aria-controls": linkSearchListId,
485
+ "aria-autocomplete": "list",
486
+ "aria-activedescendant": ariaActiveDescendant,
487
+ "aria-describedby": screenReaderDescriptionId,
488
+ "aria-expanded": true
489
+ }), jsx(PanelTextInput, {
490
+ name: "link-text",
491
+ testId: "link-text",
492
+ autoComplete: "off",
493
+ label: linkTextLabel,
494
+ placeholder: linkTextPlaceHolder,
495
+ "aria-label": formatMessage(messages.linkAriaLabel),
496
+ value: displayText,
497
+ onSubmit: this.handleSubmit,
498
+ onKeyDown: this.handleKeyDown,
499
+ onChange: this.updateTextInput,
500
+ onClear: this.handleClearDisplayText,
501
+ clearLabel: formatMessage(messages.clearText)
502
+ }), !!items.length && jsx("div", {
503
+ css: ListTitleStyles,
504
+ id: "link-picker-list-title",
505
+ "data-testid": "link-picker-list-title"
506
+ }, formatMessage(this.state.url ? messages.titleResults : messages.titleRecentlyViewed)), jsx(VisuallyHidden, null, jsx("span", {
507
+ "aria-live": "polite",
508
+ "aria-atomic": "true",
509
+ id: "fabric.smartcard.linkpicker.suggested.results"
510
+ }, url && formatMessage(messages.searchLinkResults, {
511
+ count: items.length
512
+ }))), jsx(LinkSearchList, {
513
+ ariaLabelledBy: "link-picker-list-title",
514
+ ariaControls: "fabric.smartcard.linkpicker.suggested.results",
515
+ id: linkSearchListId,
516
+ role: "listbox",
517
+ items: items,
518
+ isLoading: isLoading,
519
+ selectedIndex: selectedIndex,
520
+ activeIndex: activeIndex,
521
+ onSelect: this.handleSelected,
522
+ onMouseEnter: this.handleMouseEnterResultItem,
523
+ onMouseLeave: this.handleMouseLeaveResultItem
524
+ }), jsx(FormFooter, {
525
+ align: "end"
526
+ }, jsx(ButtonGroup, null, jsx(Button, {
527
+ appearance: "default",
528
+ onClick: this.handleCancel,
529
+ testId: "link-picker-cancel-button"
530
+ }, formatMessage(messages.cancelButton)), jsx(Button, {
531
+ type: "submit",
532
+ appearance: "primary",
533
+ onClick: this.handleSubmit,
534
+ testId: "link-picker-insert-button"
535
+ }, formatMessage(messages.insertButton))))));
536
+ }
537
+ }]);
538
+
539
+ return LinkPicker;
540
+ }(PureComponent);
541
+
542
+ function findIndex(array, predicate) {
543
+ var index = -1;
544
+ array.some(function (item, i) {
545
+ if (predicate(item)) {
546
+ index = i;
547
+ return true;
548
+ }
549
+
550
+ return false;
551
+ });
552
+ return index;
553
+ }
554
+
555
+ function limit(items) {
556
+ return items.slice(0, RECENT_SEARCH_LIST_SIZE);
557
+ }
558
+
559
+ export var LinkPickerWithIntl = injectIntl(LinkPicker);
@@ -0,0 +1,90 @@
1
+ import LinkifyIt from 'linkify-it';
2
+ var linkify = LinkifyIt();
3
+ linkify.add('sourcetree:', 'http:');
4
+ var tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
5
+ var tlds2Char = 'a[cdefgilmnoqrtuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrtuvwxyz]|n[acefgilopruz]|om|p[aefghkmnrtw]|qa|r[eosuw]|s[abcdegijklmnrtuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]';
6
+ tlds.push(tlds2Char);
7
+ linkify.tlds(tlds, false);
8
+ var whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^\//im, /^mailto:/im, /^skype:/im, /^callto:[^\s]*$/im, /^facetime:[^\s]*$/im, /^git:/im, /^irc6?:/im, /^news:/im, /^nntp:/im, /^feed:/im, /^cvs:/im, /^svn:/im, /^mvn:/im, /^ssh:/im, /^scp:\/\//im, /^sftp:\/\//im, /^itms:/im, /^notes:/im, /^hipchat:\/\//im, /^sourcetree:/im, /^urn:/im, /^tel:/im, /^xmpp:/im, /^telnet:/im, /^vnc:/im, /^rdp:/im, /^whatsapp:/im, /^slack:/im, /^sips?:/im, /^magnet:/im, /^foo:/im, /^#/im];
9
+
10
+ var normaliseLinkHref = function normaliseLinkHref(url) {
11
+ var match = getLinkMatch(url);
12
+ return match && match.url || null;
13
+ };
14
+
15
+ var getLinkMatch = function getLinkMatch(str) {
16
+ if (!str) {
17
+ return null;
18
+ }
19
+
20
+ var match = linkifyMatch(str);
21
+
22
+ if (!match.length) {
23
+ match = linkify.match(str);
24
+ }
25
+
26
+ return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
27
+ };
28
+
29
+ var LINK_REGEXP = /(https?|ftp):\/\/[^\s]+/;
30
+
31
+ var linkifyMatch = function linkifyMatch(text) {
32
+ var matches = [];
33
+
34
+ if (!LINK_REGEXP.test(text)) {
35
+ return matches;
36
+ }
37
+
38
+ var startpos = 0;
39
+ var substr;
40
+
41
+ while (substr = text.substr(startpos)) {
42
+ var link = (substr.match(LINK_REGEXP) || [''])[0];
43
+
44
+ if (link) {
45
+ var index = substr.search(LINK_REGEXP);
46
+ var start = index >= 0 ? index + startpos : index;
47
+ var end = start + link.length;
48
+ matches.push({
49
+ index: start,
50
+ lastIndex: end,
51
+ raw: link,
52
+ url: link,
53
+ text: link,
54
+ schema: ''
55
+ });
56
+ startpos += end;
57
+ } else {
58
+ break;
59
+ }
60
+ }
61
+
62
+ return matches;
63
+ };
64
+
65
+ export var isSafeUrl = function isSafeUrl(url) {
66
+ var urlTrimmed = url.trim();
67
+
68
+ if (urlTrimmed.length === 0) {
69
+ return true;
70
+ }
71
+
72
+ return whitelistedURLPatterns.some(function (p) {
73
+ return p.test(urlTrimmed);
74
+ });
75
+ };
76
+ /**
77
+ * Adds protocol to url if needed.
78
+ */
79
+
80
+ export function normalizeUrl(url) {
81
+ if (!url) {
82
+ return '';
83
+ }
84
+
85
+ if (isSafeUrl(url)) {
86
+ return url.trim();
87
+ }
88
+
89
+ return normaliseLinkHref(url);
90
+ }
@@ -0,0 +1,24 @@
1
+ import { browser } from './browser';
2
+ export var relativeFontSizeToBase16 = function relativeFontSizeToBase16(px) {
3
+ if (typeof px === 'string') {
4
+ px = parseInt(px);
5
+ }
6
+
7
+ if (isNaN(px)) {
8
+ throw new Error("Invalid font size: '".concat(px, "'"));
9
+ }
10
+
11
+ return "".concat(px / 16, "rem");
12
+ };
13
+ var KeyZCode = 90;
14
+ var KeyYCode = 89;
15
+ export var isUndoEvent = function isUndoEvent(e) {
16
+ return e.keyCode === KeyZCode && ( // cmd + z for mac
17
+ browser.mac && e.metaKey && !e.shiftKey || // ctrl + z for non-mac
18
+ !browser.mac && e.ctrlKey);
19
+ };
20
+ export var isRedoEvent = function isRedoEvent(e) {
21
+ return (// ctrl + y for non-mac
22
+ !browser.mac && e.ctrlKey && e.keyCode === KeyYCode || browser.mac && e.metaKey && e.shiftKey && e.keyCode === KeyZCode || e.ctrlKey && e.shiftKey && e.keyCode === KeyZCode
23
+ );
24
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "0.0.2",
3
+ "version": "0.7.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,15 @@
1
+ declare const result: {
2
+ mac: boolean;
3
+ ie: boolean;
4
+ ie_version: number;
5
+ gecko: boolean;
6
+ chrome: boolean;
7
+ chrome_version: number;
8
+ android: boolean;
9
+ ios: boolean;
10
+ webkit: boolean;
11
+ safari: boolean;
12
+ supportsIntersectionObserver: boolean;
13
+ supportsResizeObserver: boolean;
14
+ };
15
+ export { result as browser };
@@ -1 +1,3 @@
1
- export { LinkPicker } from './link-picker';
1
+ export type { LinkPickerProps } from './ui/link-picker';
2
+ export { LinkPickerWithIntl as LinkPicker } from './ui/link-picker';
3
+ export type { LinkInputType, LinkPickerPlugin, LinkPickerState, LinkSearchListItemData, } from './types';