@atlaskit/link-picker 3.2.4 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/ui/link-picker/index.js +103 -25
- package/dist/cjs/ui/link-picker/messages.js +5 -0
- package/dist/cjs/ui/link-picker/text-input/index.js +9 -10
- package/dist/cjs/ui/main.js +1 -1
- package/dist/es2019/ui/link-picker/index.js +48 -10
- package/dist/es2019/ui/link-picker/messages.js +5 -0
- package/dist/es2019/ui/link-picker/text-input/index.js +1 -2
- package/dist/es2019/ui/main.js +1 -1
- package/dist/esm/ui/link-picker/index.js +103 -25
- package/dist/esm/ui/link-picker/messages.js +5 -0
- package/dist/esm/ui/link-picker/text-input/index.js +1 -2
- package/dist/esm/ui/main.js +1 -1
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/ui/link-picker/messages.d.ts +5 -0
- package/dist/types/ui/link-picker/text-input/index.d.ts +2 -2
- package/dist/types-ts4.5/common/types.d.ts +3 -0
- package/dist/types-ts4.5/ui/link-picker/messages.d.ts +5 -0
- package/dist/types-ts4.5/ui/link-picker/text-input/index.d.ts +2 -2
- package/package.json +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/link-picker
|
|
2
2
|
|
|
3
|
+
## 3.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#152919](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/152919)
|
|
8
|
+
[`c64fbd4c5d651`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c64fbd4c5d651) -
|
|
9
|
+
[ux] New prop previewableLinksOnly for link picker that prevents link picker from submitting a URL
|
|
10
|
+
that does not have a preview available and gives an error message
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 3.2.4
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -11,17 +11,21 @@ require("./index.compiled.css");
|
|
|
11
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
12
|
var React = _react;
|
|
13
13
|
var _runtime = require("@compiled/react/runtime");
|
|
14
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
15
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
16
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
17
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
16
18
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
19
|
var _reactIntlNext = require("react-intl-next");
|
|
18
20
|
var _uuid = _interopRequireDefault(require("uuid"));
|
|
19
21
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
20
22
|
var _form = require("@atlaskit/form");
|
|
23
|
+
var _linkProvider = require("@atlaskit/link-provider");
|
|
21
24
|
var _url2 = require("@atlaskit/linking-common/url");
|
|
22
25
|
var _userAgent = require("@atlaskit/linking-common/user-agent");
|
|
23
26
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
24
27
|
var _compiled = require("@atlaskit/primitives/compiled");
|
|
28
|
+
var _linkUrl = _interopRequireDefault(require("@atlaskit/smart-card/link-url"));
|
|
25
29
|
var _colors = require("@atlaskit/theme/colors");
|
|
26
30
|
var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
|
|
27
31
|
var _analytics = require("../../common/analytics");
|
|
@@ -65,12 +69,14 @@ var initState = {
|
|
|
65
69
|
selectedIndex: -1,
|
|
66
70
|
invalidUrl: false,
|
|
67
71
|
activeTab: 0,
|
|
68
|
-
preventHidingRecents: false
|
|
72
|
+
preventHidingRecents: false,
|
|
73
|
+
hasPreview: true
|
|
69
74
|
};
|
|
70
75
|
function reducer(state, payload) {
|
|
71
76
|
if (payload.url && state.url !== payload.url) {
|
|
72
77
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
73
78
|
invalidUrl: false,
|
|
79
|
+
hasPreview: true,
|
|
74
80
|
selectedIndex: (0, _url2.isSafeUrl)(payload.url) && payload.url.length ? -1 : state.selectedIndex
|
|
75
81
|
}, payload);
|
|
76
82
|
}
|
|
@@ -92,6 +98,7 @@ var LinkInputField = (0, _analytics.withInputFieldTracking)(_textInput.TextInput
|
|
|
92
98
|
});
|
|
93
99
|
});
|
|
94
100
|
var DisplayTextInputField = (0, _analytics.withInputFieldTracking)(_textInput.TextInput, 'displayText');
|
|
101
|
+
var client = new _linkProvider.CardClient();
|
|
95
102
|
var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsContext)( /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
96
103
|
var onSubmit = _ref.onSubmit,
|
|
97
104
|
onCancel = _ref.onCancel,
|
|
@@ -109,7 +116,9 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
109
116
|
adaptiveHeight = _ref$adaptiveHeight === void 0 ? false : _ref$adaptiveHeight,
|
|
110
117
|
_ref$moveSubmitButton = _ref.moveSubmitButton,
|
|
111
118
|
moveSubmitButton = _ref$moveSubmitButton === void 0 ? false : _ref$moveSubmitButton,
|
|
112
|
-
inputRef = _ref.inputRef
|
|
119
|
+
inputRef = _ref.inputRef,
|
|
120
|
+
_ref$previewableLinks = _ref.previewableLinksOnly,
|
|
121
|
+
previewableLinksOnly = _ref$previewableLinks === void 0 ? false : _ref$previewableLinks;
|
|
113
122
|
var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
|
|
114
123
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
115
124
|
var _useReducer = (0, _react.useReducer)(reducer, _objectSpread(_objectSpread({}, initState), {}, {
|
|
@@ -124,7 +133,8 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
124
133
|
url = state.url,
|
|
125
134
|
displayText = state.displayText,
|
|
126
135
|
invalidUrl = state.invalidUrl,
|
|
127
|
-
activeTab = state.activeTab
|
|
136
|
+
activeTab = state.activeTab,
|
|
137
|
+
hasPreview = state.hasPreview;
|
|
128
138
|
var intl = (0, _reactIntlNext.useIntl)();
|
|
129
139
|
var queryState = (0, _useSearchQuery.useSearchQuery)(state);
|
|
130
140
|
var _usePlugins = (0, _usePlugins2.usePlugins)(queryState, activeTab, plugins),
|
|
@@ -139,6 +149,7 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
139
149
|
var isEditing = !!initUrl;
|
|
140
150
|
var selectedItem = items === null || items === void 0 ? void 0 : items[selectedIndex];
|
|
141
151
|
var isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
|
|
152
|
+
var previewableOnly = (0, _platformFeatureFlags.fg)('platform-linking-link-picker-previewable-only') && previewableLinksOnly;
|
|
142
153
|
var _useLinkPickerAnalyti = (0, _analytics.useLinkPickerAnalytics)(),
|
|
143
154
|
trackAttribute = _useLinkPickerAnalyti.trackAttribute,
|
|
144
155
|
getAttributes = _useLinkPickerAnalyti.getAttributes;
|
|
@@ -170,10 +181,10 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
170
181
|
});
|
|
171
182
|
}, [dispatch]);
|
|
172
183
|
var handleClear = (0, _react.useCallback)(function (field) {
|
|
173
|
-
dispatch((0, _defineProperty2.default)({
|
|
184
|
+
dispatch((0, _defineProperty2.default)((0, _defineProperty2.default)({
|
|
174
185
|
activeIndex: -1,
|
|
175
186
|
selectedIndex: -1
|
|
176
|
-
}, field, ''));
|
|
187
|
+
}, field, ''), "hasPreview", true));
|
|
177
188
|
}, [dispatch]);
|
|
178
189
|
var handleUrlClear = (0, _react.useCallback)(function () {
|
|
179
190
|
if (isSubmitting) {
|
|
@@ -229,23 +240,78 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
229
240
|
handleInsert(_url, name, 'typeAhead', _objectSpread({}, selectedItem));
|
|
230
241
|
}
|
|
231
242
|
}, [handleInsert, trackAttribute, items, activePlugin, isSubmitting]);
|
|
232
|
-
var handleSubmit = (0, _react.useCallback)(function (
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
243
|
+
var handleSubmit = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
244
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(event) {
|
|
245
|
+
var normalized, urlResponse, responseObject;
|
|
246
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
247
|
+
while (1) switch (_context.prev = _context.next) {
|
|
248
|
+
case 0:
|
|
249
|
+
event === null || event === void 0 || event.preventDefault();
|
|
250
|
+
if (!isSubmitting) {
|
|
251
|
+
_context.next = 3;
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
return _context.abrupt("return");
|
|
255
|
+
case 3:
|
|
256
|
+
if (!(isSelectedItem && selectedItem)) {
|
|
257
|
+
_context.next = 5;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
return _context.abrupt("return", handleInsert(selectedItem.url, selectedItem.name, 'typeAhead'));
|
|
261
|
+
case 5:
|
|
262
|
+
normalized = (0, _url2.normalizeUrl)(url);
|
|
263
|
+
if (!normalized) {
|
|
264
|
+
_context.next = 26;
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (!previewableOnly) {
|
|
268
|
+
_context.next = 25;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
_context.prev = 8;
|
|
272
|
+
_context.next = 11;
|
|
273
|
+
return client.fetchData(normalized);
|
|
274
|
+
case 11:
|
|
275
|
+
urlResponse = _context.sent;
|
|
276
|
+
responseObject = urlResponse === null || urlResponse === void 0 ? void 0 : urlResponse.data;
|
|
277
|
+
if (!(responseObject && 'preview' in responseObject)) {
|
|
278
|
+
_context.next = 17;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
return _context.abrupt("return", handleInsert(normalized, null, 'manual'));
|
|
282
|
+
case 17:
|
|
283
|
+
return _context.abrupt("return", dispatch({
|
|
284
|
+
invalidUrl: true,
|
|
285
|
+
hasPreview: false
|
|
286
|
+
}));
|
|
287
|
+
case 18:
|
|
288
|
+
_context.next = 23;
|
|
289
|
+
break;
|
|
290
|
+
case 20:
|
|
291
|
+
_context.prev = 20;
|
|
292
|
+
_context.t0 = _context["catch"](8);
|
|
293
|
+
return _context.abrupt("return", dispatch({
|
|
294
|
+
invalidUrl: true
|
|
295
|
+
}));
|
|
296
|
+
case 23:
|
|
297
|
+
_context.next = 26;
|
|
298
|
+
break;
|
|
299
|
+
case 25:
|
|
300
|
+
return _context.abrupt("return", handleInsert(normalized, null, 'manual'));
|
|
301
|
+
case 26:
|
|
302
|
+
return _context.abrupt("return", dispatch({
|
|
303
|
+
invalidUrl: true
|
|
304
|
+
}));
|
|
305
|
+
case 27:
|
|
306
|
+
case "end":
|
|
307
|
+
return _context.stop();
|
|
308
|
+
}
|
|
309
|
+
}, _callee, null, [[8, 20]]);
|
|
310
|
+
}));
|
|
311
|
+
return function (_x) {
|
|
312
|
+
return _ref2.apply(this, arguments);
|
|
313
|
+
};
|
|
314
|
+
}(), [dispatch, handleInsert, isSelectedItem, selectedItem, url, isSubmitting, previewableOnly]);
|
|
249
315
|
var handleTabChange = (0, _react.useCallback)(function (activeTab) {
|
|
250
316
|
var _plugins$activeTab$ta, _plugins$activeTab;
|
|
251
317
|
dispatch({
|
|
@@ -256,6 +322,7 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
256
322
|
// We don't want recents to be hidden, even though we don't have a selection
|
|
257
323
|
preventHidingRecents: true,
|
|
258
324
|
invalidUrl: false,
|
|
325
|
+
hasPreview: true,
|
|
259
326
|
activeTab: activeTab
|
|
260
327
|
});
|
|
261
328
|
trackAttribute('tab', (_plugins$activeTab$ta = plugins === null || plugins === void 0 || (_plugins$activeTab = plugins[activeTab]) === null || _plugins$activeTab === void 0 ? void 0 : _plugins$activeTab.tabKey) !== null && _plugins$activeTab$ta !== void 0 ? _plugins$activeTab$ta : null);
|
|
@@ -281,7 +348,8 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
281
348
|
activeIndex: index,
|
|
282
349
|
selectedIndex: index,
|
|
283
350
|
url: item.url,
|
|
284
|
-
invalidUrl: false
|
|
351
|
+
invalidUrl: false,
|
|
352
|
+
hasPreview: true
|
|
285
353
|
});
|
|
286
354
|
}
|
|
287
355
|
}
|
|
@@ -314,7 +382,8 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
314
382
|
activeIndex: updatedIndex,
|
|
315
383
|
selectedIndex: updatedIndex,
|
|
316
384
|
url: item.url,
|
|
317
|
-
invalidUrl: false
|
|
385
|
+
invalidUrl: false,
|
|
386
|
+
hasPreview: true
|
|
318
387
|
});
|
|
319
388
|
}
|
|
320
389
|
}, [items, activeIndex, selectedItem, handleSelected, handleSubmit, trackAttribute, activePlugin]);
|
|
@@ -338,6 +407,15 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
338
407
|
// for details: https://a11y-internal.atlassian.net/browse/AK-740
|
|
339
408
|
var screenReaderText = (0, _userAgent.browser)().safari && (0, _utils.getScreenReaderText)(items !== null && items !== void 0 ? items : [], selectedIndex, intl);
|
|
340
409
|
var customSubmitButtonLabel = customMessages !== null && customMessages !== void 0 && customMessages.submitButtonLabel ? customMessages.submitButtonLabel : undefined;
|
|
410
|
+
var errorMessage = invalidUrl ? previewableOnly && !hasPreview ? /*#__PURE__*/React.createElement(_reactIntlNext.FormattedMessage, (0, _extends2.default)({}, _messages.formMessages.noEmbedAvailable, {
|
|
411
|
+
values: {
|
|
412
|
+
a: function a(chunk) {
|
|
413
|
+
return /*#__PURE__*/React.createElement(_linkUrl.default, {
|
|
414
|
+
href: "https://support.atlassian.com/platform-experiences/docs/smart-links-from-jira-and-other-products/"
|
|
415
|
+
}, chunk);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
})) : intl.formatMessage(_messages.formMessages.linkInvalid) : null;
|
|
341
419
|
return /*#__PURE__*/React.createElement("form", {
|
|
342
420
|
"data-testid": testIds.linkPicker,
|
|
343
421
|
// Use onSubmitCapture instead of onSubmit so that any possible parent form isn't submitted
|
|
@@ -359,7 +437,7 @@ var LinkPicker = exports.LinkPicker = (0, _analytics.withLinkPickerAnalyticsCont
|
|
|
359
437
|
value: url,
|
|
360
438
|
autoFocus: true,
|
|
361
439
|
clearLabel: intl.formatMessage(_messages.formMessages.clearLink),
|
|
362
|
-
error:
|
|
440
|
+
error: errorMessage,
|
|
363
441
|
spotlightTargetName: "link-picker-search-field-spotlight-target",
|
|
364
442
|
"aria-readonly": isSubmitting
|
|
365
443
|
}, a11yList, {
|
|
@@ -49,6 +49,11 @@ var formMessages = exports.formMessages = (0, _reactIntlNext.defineMessages)({
|
|
|
49
49
|
id: 'fabric.linkPicker.clearLink',
|
|
50
50
|
defaultMessage: 'Clear',
|
|
51
51
|
description: 'Tooltip message for link input clear button'
|
|
52
|
+
},
|
|
53
|
+
noEmbedAvailable: {
|
|
54
|
+
id: 'fabric.linkPicker.noEmbed',
|
|
55
|
+
defaultMessage: "Embed view isn't supported for this link. <a>More about why some Smart Links don't display content.</a>",
|
|
56
|
+
description: 'Error message shown for links without embeds'
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
59
|
var linkTextMessages = exports.linkTextMessages = (0, _reactIntlNext.defineMessages)({
|
|
@@ -8,11 +8,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
});
|
|
9
9
|
exports.testIds = exports.TextInput = void 0;
|
|
10
10
|
require("./index.compiled.css");
|
|
11
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
-
var React = _react;
|
|
13
11
|
var _runtime = require("@compiled/react/runtime");
|
|
14
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
15
13
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
16
15
|
var _useCallbackRef = require("use-callback-ref");
|
|
17
16
|
var _form = require("@atlaskit/form");
|
|
18
17
|
var _crossCircleSelectClear = _interopRequireDefault(require("@atlaskit/icon/core/migration/cross-circle--select-clear"));
|
|
@@ -94,33 +93,33 @@ var TextInput = exports.TextInput = function TextInput(_ref) {
|
|
|
94
93
|
onClear === null || onClear === void 0 || onClear(name);
|
|
95
94
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
96
95
|
}, [name, onClear]);
|
|
97
|
-
var clearText = restProps.value !== '' && /*#__PURE__*/
|
|
96
|
+
var clearText = restProps.value !== '' && /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
98
97
|
content: clearLabel
|
|
99
|
-
}, /*#__PURE__*/
|
|
98
|
+
}, /*#__PURE__*/_react.default.createElement(_compiled.Pressable, {
|
|
100
99
|
xcss: styles.clearTextButton,
|
|
101
100
|
onClick: handleClear,
|
|
102
101
|
testId: testIds.clearUrlButton
|
|
103
|
-
}, /*#__PURE__*/
|
|
102
|
+
}, /*#__PURE__*/_react.default.createElement(_crossCircleSelectClear.default, {
|
|
104
103
|
LEGACY_size: "medium",
|
|
105
104
|
label: clearLabel || '',
|
|
106
105
|
color: "var(--ds-icon-subtle, #626F86)",
|
|
107
106
|
spacing: "spacious"
|
|
108
107
|
})));
|
|
109
|
-
return /*#__PURE__*/
|
|
108
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
110
109
|
className: (0, _runtime.ax)(["_7yjtidpf _onzypxbi", (0, _platformFeatureFlags.fg)('platform-linking-visual-refresh-v1') && "_11c81vhk"])
|
|
111
|
-
}, /*#__PURE__*/
|
|
110
|
+
}, /*#__PURE__*/_react.default.createElement(_form.Field, {
|
|
112
111
|
label: label,
|
|
113
112
|
name: name
|
|
114
113
|
}, function (_ref2) {
|
|
115
114
|
var fieldProps = _ref2.fieldProps;
|
|
116
|
-
return /*#__PURE__*/
|
|
115
|
+
return /*#__PURE__*/_react.default.createElement(_conditionalSpotlightTargetWrapper.ConditionalSpotlightTargetWrapper, {
|
|
117
116
|
spotlightTargetName: spotlightTargetName
|
|
118
|
-
}, /*#__PURE__*/
|
|
117
|
+
}, /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_textfield.default, (0, _extends2.default)({}, fieldProps, restProps, {
|
|
119
118
|
onKeyDown: handleKeydown,
|
|
120
119
|
ref: textfieldRef,
|
|
121
120
|
elemAfterInput: clearText,
|
|
122
121
|
isInvalid: !!error
|
|
123
|
-
})), error && /*#__PURE__*/
|
|
122
|
+
})), error && /*#__PURE__*/_react.default.createElement(_form.ErrorMessage, {
|
|
124
123
|
testId: testIds.urlError
|
|
125
124
|
}, error)));
|
|
126
125
|
}));
|
package/dist/cjs/ui/main.js
CHANGED
|
@@ -26,7 +26,7 @@ var testIds = exports.testIds = {
|
|
|
26
26
|
};
|
|
27
27
|
var PACKAGE_DATA = exports.PACKAGE_DATA = {
|
|
28
28
|
packageName: "@atlaskit/link-picker" || '',
|
|
29
|
-
packageVersion: "3.
|
|
29
|
+
packageVersion: "3.3.0" || '',
|
|
30
30
|
componentName: _constants.COMPONENT_NAME,
|
|
31
31
|
source: _constants.COMPONENT_NAME
|
|
32
32
|
};
|
|
@@ -8,10 +8,12 @@ import { FormattedMessage, useIntl } from 'react-intl-next';
|
|
|
8
8
|
import uuid from 'uuid';
|
|
9
9
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
10
10
|
import { HelperMessage } from '@atlaskit/form';
|
|
11
|
+
import { CardClient } from '@atlaskit/link-provider';
|
|
11
12
|
import { isSafeUrl, normalizeUrl } from '@atlaskit/linking-common/url';
|
|
12
13
|
import { browser } from '@atlaskit/linking-common/user-agent';
|
|
13
14
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
15
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
16
|
+
import LinkUrl from '@atlaskit/smart-card/link-url';
|
|
15
17
|
import { N700 } from '@atlaskit/theme/colors';
|
|
16
18
|
import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
17
19
|
import { useLinkPickerAnalytics, withInputFieldTracking, withLinkPickerAnalyticsContext } from '../../common/analytics';
|
|
@@ -54,13 +56,15 @@ const initState = {
|
|
|
54
56
|
selectedIndex: -1,
|
|
55
57
|
invalidUrl: false,
|
|
56
58
|
activeTab: 0,
|
|
57
|
-
preventHidingRecents: false
|
|
59
|
+
preventHidingRecents: false,
|
|
60
|
+
hasPreview: true
|
|
58
61
|
};
|
|
59
62
|
function reducer(state, payload) {
|
|
60
63
|
if (payload.url && state.url !== payload.url) {
|
|
61
64
|
return {
|
|
62
65
|
...state,
|
|
63
66
|
invalidUrl: false,
|
|
67
|
+
hasPreview: true,
|
|
64
68
|
selectedIndex: isSafeUrl(payload.url) && payload.url.length ? -1 : state.selectedIndex,
|
|
65
69
|
...payload
|
|
66
70
|
};
|
|
@@ -85,6 +89,7 @@ const LinkInputField = withInputFieldTracking(TextInput, 'link', (event, attribu
|
|
|
85
89
|
linkFieldContent: getLinkFieldContent(event.currentTarget.value)
|
|
86
90
|
}));
|
|
87
91
|
const DisplayTextInputField = withInputFieldTracking(TextInput, 'displayText');
|
|
92
|
+
const client = new CardClient();
|
|
88
93
|
export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
89
94
|
onSubmit,
|
|
90
95
|
onCancel,
|
|
@@ -99,7 +104,8 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
99
104
|
isSubmitting = false,
|
|
100
105
|
adaptiveHeight = false,
|
|
101
106
|
moveSubmitButton = false,
|
|
102
|
-
inputRef
|
|
107
|
+
inputRef,
|
|
108
|
+
previewableLinksOnly = false
|
|
103
109
|
}) => {
|
|
104
110
|
const {
|
|
105
111
|
createAnalyticsEvent
|
|
@@ -115,7 +121,8 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
115
121
|
url,
|
|
116
122
|
displayText,
|
|
117
123
|
invalidUrl,
|
|
118
|
-
activeTab
|
|
124
|
+
activeTab,
|
|
125
|
+
hasPreview
|
|
119
126
|
} = state;
|
|
120
127
|
const intl = useIntl();
|
|
121
128
|
const queryState = useSearchQuery(state);
|
|
@@ -132,6 +139,7 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
132
139
|
const isEditing = !!initUrl;
|
|
133
140
|
const selectedItem = items === null || items === void 0 ? void 0 : items[selectedIndex];
|
|
134
141
|
const isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
|
|
142
|
+
const previewableOnly = fg('platform-linking-link-picker-previewable-only') && previewableLinksOnly;
|
|
135
143
|
const {
|
|
136
144
|
trackAttribute,
|
|
137
145
|
getAttributes
|
|
@@ -165,7 +173,8 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
165
173
|
dispatch({
|
|
166
174
|
activeIndex: -1,
|
|
167
175
|
selectedIndex: -1,
|
|
168
|
-
[field]: ''
|
|
176
|
+
[field]: '',
|
|
177
|
+
hasPreview: true
|
|
169
178
|
});
|
|
170
179
|
}, [dispatch]);
|
|
171
180
|
const handleUrlClear = useCallback(() => {
|
|
@@ -225,7 +234,7 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
225
234
|
});
|
|
226
235
|
}
|
|
227
236
|
}, [handleInsert, trackAttribute, items, activePlugin, isSubmitting]);
|
|
228
|
-
const handleSubmit = useCallback(event => {
|
|
237
|
+
const handleSubmit = useCallback(async event => {
|
|
229
238
|
event === null || event === void 0 ? void 0 : event.preventDefault();
|
|
230
239
|
if (isSubmitting) {
|
|
231
240
|
// Prevent submit while submitting
|
|
@@ -236,12 +245,31 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
236
245
|
}
|
|
237
246
|
const normalized = normalizeUrl(url);
|
|
238
247
|
if (normalized) {
|
|
239
|
-
|
|
248
|
+
if (previewableOnly) {
|
|
249
|
+
try {
|
|
250
|
+
const urlResponse = await client.fetchData(normalized);
|
|
251
|
+
const responseObject = urlResponse === null || urlResponse === void 0 ? void 0 : urlResponse.data;
|
|
252
|
+
if (responseObject && 'preview' in responseObject) {
|
|
253
|
+
return handleInsert(normalized, null, 'manual');
|
|
254
|
+
} else {
|
|
255
|
+
return dispatch({
|
|
256
|
+
invalidUrl: true,
|
|
257
|
+
hasPreview: false
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
} catch (error) {
|
|
261
|
+
return dispatch({
|
|
262
|
+
invalidUrl: true
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
return handleInsert(normalized, null, 'manual');
|
|
267
|
+
}
|
|
240
268
|
}
|
|
241
269
|
return dispatch({
|
|
242
270
|
invalidUrl: true
|
|
243
271
|
});
|
|
244
|
-
}, [dispatch, handleInsert, isSelectedItem, selectedItem, url, isSubmitting]);
|
|
272
|
+
}, [dispatch, handleInsert, isSelectedItem, selectedItem, url, isSubmitting, previewableOnly]);
|
|
245
273
|
const handleTabChange = useCallback(activeTab => {
|
|
246
274
|
var _plugins$activeTab$ta, _plugins$activeTab;
|
|
247
275
|
dispatch({
|
|
@@ -252,6 +280,7 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
252
280
|
// We don't want recents to be hidden, even though we don't have a selection
|
|
253
281
|
preventHidingRecents: true,
|
|
254
282
|
invalidUrl: false,
|
|
283
|
+
hasPreview: true,
|
|
255
284
|
activeTab
|
|
256
285
|
});
|
|
257
286
|
trackAttribute('tab', (_plugins$activeTab$ta = plugins === null || plugins === void 0 ? void 0 : (_plugins$activeTab = plugins[activeTab]) === null || _plugins$activeTab === void 0 ? void 0 : _plugins$activeTab.tabKey) !== null && _plugins$activeTab$ta !== void 0 ? _plugins$activeTab$ta : null);
|
|
@@ -275,7 +304,8 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
275
304
|
activeIndex: index,
|
|
276
305
|
selectedIndex: index,
|
|
277
306
|
url: item.url,
|
|
278
|
-
invalidUrl: false
|
|
307
|
+
invalidUrl: false,
|
|
308
|
+
hasPreview: true
|
|
279
309
|
});
|
|
280
310
|
}
|
|
281
311
|
}
|
|
@@ -308,7 +338,8 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
308
338
|
activeIndex: updatedIndex,
|
|
309
339
|
selectedIndex: updatedIndex,
|
|
310
340
|
url: item.url,
|
|
311
|
-
invalidUrl: false
|
|
341
|
+
invalidUrl: false,
|
|
342
|
+
hasPreview: true
|
|
312
343
|
});
|
|
313
344
|
}
|
|
314
345
|
}, [items, activeIndex, selectedItem, handleSelected, handleSubmit, trackAttribute, activePlugin]);
|
|
@@ -332,6 +363,13 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
332
363
|
// for details: https://a11y-internal.atlassian.net/browse/AK-740
|
|
333
364
|
const screenReaderText = browser().safari && getScreenReaderText(items !== null && items !== void 0 ? items : [], selectedIndex, intl);
|
|
334
365
|
const customSubmitButtonLabel = customMessages !== null && customMessages !== void 0 && customMessages.submitButtonLabel ? customMessages.submitButtonLabel : undefined;
|
|
366
|
+
const errorMessage = invalidUrl ? previewableOnly && !hasPreview ? /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, formMessages.noEmbedAvailable, {
|
|
367
|
+
values: {
|
|
368
|
+
a: chunk => /*#__PURE__*/React.createElement(LinkUrl, {
|
|
369
|
+
href: "https://support.atlassian.com/platform-experiences/docs/smart-links-from-jira-and-other-products/"
|
|
370
|
+
}, chunk)
|
|
371
|
+
}
|
|
372
|
+
})) : intl.formatMessage(formMessages.linkInvalid) : null;
|
|
335
373
|
return /*#__PURE__*/React.createElement("form", {
|
|
336
374
|
"data-testid": testIds.linkPicker,
|
|
337
375
|
// Use onSubmitCapture instead of onSubmit so that any possible parent form isn't submitted
|
|
@@ -353,7 +391,7 @@ export const LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(({
|
|
|
353
391
|
value: url,
|
|
354
392
|
autoFocus: true,
|
|
355
393
|
clearLabel: intl.formatMessage(formMessages.clearLink),
|
|
356
|
-
error:
|
|
394
|
+
error: errorMessage,
|
|
357
395
|
spotlightTargetName: "link-picker-search-field-spotlight-target",
|
|
358
396
|
"aria-readonly": isSubmitting
|
|
359
397
|
}, a11yList, {
|
|
@@ -43,6 +43,11 @@ export const formMessages = defineMessages({
|
|
|
43
43
|
id: 'fabric.linkPicker.clearLink',
|
|
44
44
|
defaultMessage: 'Clear',
|
|
45
45
|
description: 'Tooltip message for link input clear button'
|
|
46
|
+
},
|
|
47
|
+
noEmbedAvailable: {
|
|
48
|
+
id: 'fabric.linkPicker.noEmbed',
|
|
49
|
+
defaultMessage: "Embed view isn't supported for this link. <a>More about why some Smart Links don't display content.</a>",
|
|
50
|
+
description: 'Error message shown for links without embeds'
|
|
46
51
|
}
|
|
47
52
|
});
|
|
48
53
|
export const linkTextMessages = defineMessages({
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* index.tsx generated by @compiled/babel-plugin v0.36.1 */
|
|
2
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
3
|
import "./index.compiled.css";
|
|
4
|
-
import * as React from 'react';
|
|
5
4
|
import { ax, ix } from "@compiled/react/runtime";
|
|
6
|
-
import { Fragment, useCallback, useMemo, useRef } from 'react';
|
|
5
|
+
import React, { Fragment, useCallback, useMemo, useRef } from 'react';
|
|
7
6
|
import { useMergeRefs } from 'use-callback-ref';
|
|
8
7
|
import { ErrorMessage, Field } from '@atlaskit/form';
|
|
9
8
|
import Selectclear from '@atlaskit/icon/core/migration/cross-circle--select-clear';
|
package/dist/es2019/ui/main.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/* index.tsx generated by @compiled/babel-plugin v0.36.1 */
|
|
2
2
|
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
4
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
5
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
6
|
import "./index.compiled.css";
|
|
6
7
|
import * as React from 'react';
|
|
7
8
|
import { ax, ix } from "@compiled/react/runtime";
|
|
9
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
10
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
11
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
12
|
import { Fragment, memo, useCallback, useLayoutEffect, useMemo, useReducer } from 'react';
|
|
@@ -12,10 +14,12 @@ import { FormattedMessage, useIntl } from 'react-intl-next';
|
|
|
12
14
|
import uuid from 'uuid';
|
|
13
15
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
14
16
|
import { HelperMessage } from '@atlaskit/form';
|
|
17
|
+
import { CardClient } from '@atlaskit/link-provider';
|
|
15
18
|
import { isSafeUrl, normalizeUrl } from '@atlaskit/linking-common/url';
|
|
16
19
|
import { browser } from '@atlaskit/linking-common/user-agent';
|
|
17
20
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
18
21
|
import { Box } from '@atlaskit/primitives/compiled';
|
|
22
|
+
import LinkUrl from '@atlaskit/smart-card/link-url';
|
|
19
23
|
import { N700 } from '@atlaskit/theme/colors';
|
|
20
24
|
import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
21
25
|
import { useLinkPickerAnalytics, withInputFieldTracking, withLinkPickerAnalyticsContext } from '../../common/analytics';
|
|
@@ -55,12 +59,14 @@ var initState = {
|
|
|
55
59
|
selectedIndex: -1,
|
|
56
60
|
invalidUrl: false,
|
|
57
61
|
activeTab: 0,
|
|
58
|
-
preventHidingRecents: false
|
|
62
|
+
preventHidingRecents: false,
|
|
63
|
+
hasPreview: true
|
|
59
64
|
};
|
|
60
65
|
function reducer(state, payload) {
|
|
61
66
|
if (payload.url && state.url !== payload.url) {
|
|
62
67
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
68
|
invalidUrl: false,
|
|
69
|
+
hasPreview: true,
|
|
64
70
|
selectedIndex: isSafeUrl(payload.url) && payload.url.length ? -1 : state.selectedIndex
|
|
65
71
|
}, payload);
|
|
66
72
|
}
|
|
@@ -82,6 +88,7 @@ var LinkInputField = withInputFieldTracking(TextInput, 'link', function (event,
|
|
|
82
88
|
});
|
|
83
89
|
});
|
|
84
90
|
var DisplayTextInputField = withInputFieldTracking(TextInput, 'displayText');
|
|
91
|
+
var client = new CardClient();
|
|
85
92
|
export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(function (_ref) {
|
|
86
93
|
var onSubmit = _ref.onSubmit,
|
|
87
94
|
onCancel = _ref.onCancel,
|
|
@@ -99,7 +106,9 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
99
106
|
adaptiveHeight = _ref$adaptiveHeight === void 0 ? false : _ref$adaptiveHeight,
|
|
100
107
|
_ref$moveSubmitButton = _ref.moveSubmitButton,
|
|
101
108
|
moveSubmitButton = _ref$moveSubmitButton === void 0 ? false : _ref$moveSubmitButton,
|
|
102
|
-
inputRef = _ref.inputRef
|
|
109
|
+
inputRef = _ref.inputRef,
|
|
110
|
+
_ref$previewableLinks = _ref.previewableLinksOnly,
|
|
111
|
+
previewableLinksOnly = _ref$previewableLinks === void 0 ? false : _ref$previewableLinks;
|
|
103
112
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
104
113
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
105
114
|
var _useReducer = useReducer(reducer, _objectSpread(_objectSpread({}, initState), {}, {
|
|
@@ -114,7 +123,8 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
114
123
|
url = state.url,
|
|
115
124
|
displayText = state.displayText,
|
|
116
125
|
invalidUrl = state.invalidUrl,
|
|
117
|
-
activeTab = state.activeTab
|
|
126
|
+
activeTab = state.activeTab,
|
|
127
|
+
hasPreview = state.hasPreview;
|
|
118
128
|
var intl = useIntl();
|
|
119
129
|
var queryState = useSearchQuery(state);
|
|
120
130
|
var _usePlugins = usePlugins(queryState, activeTab, plugins),
|
|
@@ -129,6 +139,7 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
129
139
|
var isEditing = !!initUrl;
|
|
130
140
|
var selectedItem = items === null || items === void 0 ? void 0 : items[selectedIndex];
|
|
131
141
|
var isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
|
|
142
|
+
var previewableOnly = fg('platform-linking-link-picker-previewable-only') && previewableLinksOnly;
|
|
132
143
|
var _useLinkPickerAnalyti = useLinkPickerAnalytics(),
|
|
133
144
|
trackAttribute = _useLinkPickerAnalyti.trackAttribute,
|
|
134
145
|
getAttributes = _useLinkPickerAnalyti.getAttributes;
|
|
@@ -160,10 +171,10 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
160
171
|
});
|
|
161
172
|
}, [dispatch]);
|
|
162
173
|
var handleClear = useCallback(function (field) {
|
|
163
|
-
dispatch(_defineProperty({
|
|
174
|
+
dispatch(_defineProperty(_defineProperty({
|
|
164
175
|
activeIndex: -1,
|
|
165
176
|
selectedIndex: -1
|
|
166
|
-
}, field, ''));
|
|
177
|
+
}, field, ''), "hasPreview", true));
|
|
167
178
|
}, [dispatch]);
|
|
168
179
|
var handleUrlClear = useCallback(function () {
|
|
169
180
|
if (isSubmitting) {
|
|
@@ -219,23 +230,78 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
219
230
|
handleInsert(_url, name, 'typeAhead', _objectSpread({}, selectedItem));
|
|
220
231
|
}
|
|
221
232
|
}, [handleInsert, trackAttribute, items, activePlugin, isSubmitting]);
|
|
222
|
-
var handleSubmit = useCallback(function (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
var handleSubmit = useCallback( /*#__PURE__*/function () {
|
|
234
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(event) {
|
|
235
|
+
var normalized, urlResponse, responseObject;
|
|
236
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
237
|
+
while (1) switch (_context.prev = _context.next) {
|
|
238
|
+
case 0:
|
|
239
|
+
event === null || event === void 0 || event.preventDefault();
|
|
240
|
+
if (!isSubmitting) {
|
|
241
|
+
_context.next = 3;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
return _context.abrupt("return");
|
|
245
|
+
case 3:
|
|
246
|
+
if (!(isSelectedItem && selectedItem)) {
|
|
247
|
+
_context.next = 5;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
return _context.abrupt("return", handleInsert(selectedItem.url, selectedItem.name, 'typeAhead'));
|
|
251
|
+
case 5:
|
|
252
|
+
normalized = normalizeUrl(url);
|
|
253
|
+
if (!normalized) {
|
|
254
|
+
_context.next = 26;
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
if (!previewableOnly) {
|
|
258
|
+
_context.next = 25;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
_context.prev = 8;
|
|
262
|
+
_context.next = 11;
|
|
263
|
+
return client.fetchData(normalized);
|
|
264
|
+
case 11:
|
|
265
|
+
urlResponse = _context.sent;
|
|
266
|
+
responseObject = urlResponse === null || urlResponse === void 0 ? void 0 : urlResponse.data;
|
|
267
|
+
if (!(responseObject && 'preview' in responseObject)) {
|
|
268
|
+
_context.next = 17;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
return _context.abrupt("return", handleInsert(normalized, null, 'manual'));
|
|
272
|
+
case 17:
|
|
273
|
+
return _context.abrupt("return", dispatch({
|
|
274
|
+
invalidUrl: true,
|
|
275
|
+
hasPreview: false
|
|
276
|
+
}));
|
|
277
|
+
case 18:
|
|
278
|
+
_context.next = 23;
|
|
279
|
+
break;
|
|
280
|
+
case 20:
|
|
281
|
+
_context.prev = 20;
|
|
282
|
+
_context.t0 = _context["catch"](8);
|
|
283
|
+
return _context.abrupt("return", dispatch({
|
|
284
|
+
invalidUrl: true
|
|
285
|
+
}));
|
|
286
|
+
case 23:
|
|
287
|
+
_context.next = 26;
|
|
288
|
+
break;
|
|
289
|
+
case 25:
|
|
290
|
+
return _context.abrupt("return", handleInsert(normalized, null, 'manual'));
|
|
291
|
+
case 26:
|
|
292
|
+
return _context.abrupt("return", dispatch({
|
|
293
|
+
invalidUrl: true
|
|
294
|
+
}));
|
|
295
|
+
case 27:
|
|
296
|
+
case "end":
|
|
297
|
+
return _context.stop();
|
|
298
|
+
}
|
|
299
|
+
}, _callee, null, [[8, 20]]);
|
|
300
|
+
}));
|
|
301
|
+
return function (_x) {
|
|
302
|
+
return _ref2.apply(this, arguments);
|
|
303
|
+
};
|
|
304
|
+
}(), [dispatch, handleInsert, isSelectedItem, selectedItem, url, isSubmitting, previewableOnly]);
|
|
239
305
|
var handleTabChange = useCallback(function (activeTab) {
|
|
240
306
|
var _plugins$activeTab$ta, _plugins$activeTab;
|
|
241
307
|
dispatch({
|
|
@@ -246,6 +312,7 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
246
312
|
// We don't want recents to be hidden, even though we don't have a selection
|
|
247
313
|
preventHidingRecents: true,
|
|
248
314
|
invalidUrl: false,
|
|
315
|
+
hasPreview: true,
|
|
249
316
|
activeTab: activeTab
|
|
250
317
|
});
|
|
251
318
|
trackAttribute('tab', (_plugins$activeTab$ta = plugins === null || plugins === void 0 || (_plugins$activeTab = plugins[activeTab]) === null || _plugins$activeTab === void 0 ? void 0 : _plugins$activeTab.tabKey) !== null && _plugins$activeTab$ta !== void 0 ? _plugins$activeTab$ta : null);
|
|
@@ -271,7 +338,8 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
271
338
|
activeIndex: index,
|
|
272
339
|
selectedIndex: index,
|
|
273
340
|
url: item.url,
|
|
274
|
-
invalidUrl: false
|
|
341
|
+
invalidUrl: false,
|
|
342
|
+
hasPreview: true
|
|
275
343
|
});
|
|
276
344
|
}
|
|
277
345
|
}
|
|
@@ -304,7 +372,8 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
304
372
|
activeIndex: updatedIndex,
|
|
305
373
|
selectedIndex: updatedIndex,
|
|
306
374
|
url: item.url,
|
|
307
|
-
invalidUrl: false
|
|
375
|
+
invalidUrl: false,
|
|
376
|
+
hasPreview: true
|
|
308
377
|
});
|
|
309
378
|
}
|
|
310
379
|
}, [items, activeIndex, selectedItem, handleSelected, handleSubmit, trackAttribute, activePlugin]);
|
|
@@ -328,6 +397,15 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
328
397
|
// for details: https://a11y-internal.atlassian.net/browse/AK-740
|
|
329
398
|
var screenReaderText = browser().safari && getScreenReaderText(items !== null && items !== void 0 ? items : [], selectedIndex, intl);
|
|
330
399
|
var customSubmitButtonLabel = customMessages !== null && customMessages !== void 0 && customMessages.submitButtonLabel ? customMessages.submitButtonLabel : undefined;
|
|
400
|
+
var errorMessage = invalidUrl ? previewableOnly && !hasPreview ? /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, formMessages.noEmbedAvailable, {
|
|
401
|
+
values: {
|
|
402
|
+
a: function a(chunk) {
|
|
403
|
+
return /*#__PURE__*/React.createElement(LinkUrl, {
|
|
404
|
+
href: "https://support.atlassian.com/platform-experiences/docs/smart-links-from-jira-and-other-products/"
|
|
405
|
+
}, chunk);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
})) : intl.formatMessage(formMessages.linkInvalid) : null;
|
|
331
409
|
return /*#__PURE__*/React.createElement("form", {
|
|
332
410
|
"data-testid": testIds.linkPicker,
|
|
333
411
|
// Use onSubmitCapture instead of onSubmit so that any possible parent form isn't submitted
|
|
@@ -349,7 +427,7 @@ export var LinkPicker = withLinkPickerAnalyticsContext( /*#__PURE__*/memo(functi
|
|
|
349
427
|
value: url,
|
|
350
428
|
autoFocus: true,
|
|
351
429
|
clearLabel: intl.formatMessage(formMessages.clearLink),
|
|
352
|
-
error:
|
|
430
|
+
error: errorMessage,
|
|
353
431
|
spotlightTargetName: "link-picker-search-field-spotlight-target",
|
|
354
432
|
"aria-readonly": isSubmitting
|
|
355
433
|
}, a11yList, {
|
|
@@ -43,6 +43,11 @@ export var formMessages = defineMessages({
|
|
|
43
43
|
id: 'fabric.linkPicker.clearLink',
|
|
44
44
|
defaultMessage: 'Clear',
|
|
45
45
|
description: 'Tooltip message for link input clear button'
|
|
46
|
+
},
|
|
47
|
+
noEmbedAvailable: {
|
|
48
|
+
id: 'fabric.linkPicker.noEmbed',
|
|
49
|
+
defaultMessage: "Embed view isn't supported for this link. <a>More about why some Smart Links don't display content.</a>",
|
|
50
|
+
description: 'Error message shown for links without embeds'
|
|
46
51
|
}
|
|
47
52
|
});
|
|
48
53
|
export var linkTextMessages = defineMessages({
|
|
@@ -3,9 +3,8 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["name", "label", "autoFocus", "onRedo", "onUndo", "onKeyDown", "onClear", "clearLabel", "error", "spotlightTargetName", "inputRef"];
|
|
5
5
|
import "./index.compiled.css";
|
|
6
|
-
import * as React from 'react';
|
|
7
6
|
import { ax, ix } from "@compiled/react/runtime";
|
|
8
|
-
import { Fragment, useCallback, useMemo, useRef } from 'react';
|
|
7
|
+
import React, { Fragment, useCallback, useMemo, useRef } from 'react';
|
|
9
8
|
import { useMergeRefs } from 'use-callback-ref';
|
|
10
9
|
import { ErrorMessage, Field } from '@atlaskit/form';
|
|
11
10
|
import Selectclear from '@atlaskit/icon/core/migration/cross-circle--select-clear';
|
package/dist/esm/ui/main.js
CHANGED
|
@@ -82,6 +82,7 @@ export interface PickerState {
|
|
|
82
82
|
activeTab: number;
|
|
83
83
|
/** When true, even if the selected index is -1, don't hide the recents. */
|
|
84
84
|
preventHidingRecents: boolean;
|
|
85
|
+
hasPreview: boolean;
|
|
85
86
|
}
|
|
86
87
|
interface Meta {
|
|
87
88
|
/** Indicates how the link was picked. */
|
|
@@ -155,6 +156,8 @@ export interface LinkPickerProps {
|
|
|
155
156
|
moveSubmitButton?: boolean;
|
|
156
157
|
/** Ref to the link picker search input. */
|
|
157
158
|
inputRef?: Ref<HTMLInputElement>;
|
|
159
|
+
/**Disables URLs that do not have an embeddable preview */
|
|
160
|
+
previewableLinksOnly?: boolean;
|
|
158
161
|
}
|
|
159
162
|
type CustomLinkPickerMessages = {
|
|
160
163
|
/** Label for the link input field */
|
|
@@ -43,6 +43,11 @@ export declare const formMessages: {
|
|
|
43
43
|
defaultMessage: string;
|
|
44
44
|
description: string;
|
|
45
45
|
};
|
|
46
|
+
noEmbedAvailable: {
|
|
47
|
+
id: string;
|
|
48
|
+
defaultMessage: string;
|
|
49
|
+
description: string;
|
|
50
|
+
};
|
|
46
51
|
};
|
|
47
52
|
export declare const linkTextMessages: {
|
|
48
53
|
linkTextLabel: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @jsxRuntime classic
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
|
-
import { type Ref } from 'react';
|
|
5
|
+
import React, { type Ref } from 'react';
|
|
6
6
|
import { type TextFieldProps } from '@atlaskit/textfield';
|
|
7
7
|
import { type ConditionalSpotlightTargetWrapperProps } from './conditional-spotlight-target-wrapper';
|
|
8
8
|
export type TextInputProps = Omit<TextFieldProps, 'name' | 'value'> & Pick<ConditionalSpotlightTargetWrapperProps, 'spotlightTargetName'> & {
|
|
@@ -13,7 +13,7 @@ export type TextInputProps = Omit<TextFieldProps, 'name' | 'value'> & Pick<Condi
|
|
|
13
13
|
onRedo?: Function;
|
|
14
14
|
onClear?: (name: string) => void;
|
|
15
15
|
clearLabel?: string;
|
|
16
|
-
error?:
|
|
16
|
+
error?: React.ReactNode;
|
|
17
17
|
/** Ref to the link picker search input. */
|
|
18
18
|
inputRef?: Ref<HTMLInputElement>;
|
|
19
19
|
};
|
|
@@ -85,6 +85,7 @@ export interface PickerState {
|
|
|
85
85
|
activeTab: number;
|
|
86
86
|
/** When true, even if the selected index is -1, don't hide the recents. */
|
|
87
87
|
preventHidingRecents: boolean;
|
|
88
|
+
hasPreview: boolean;
|
|
88
89
|
}
|
|
89
90
|
interface Meta {
|
|
90
91
|
/** Indicates how the link was picked. */
|
|
@@ -158,6 +159,8 @@ export interface LinkPickerProps {
|
|
|
158
159
|
moveSubmitButton?: boolean;
|
|
159
160
|
/** Ref to the link picker search input. */
|
|
160
161
|
inputRef?: Ref<HTMLInputElement>;
|
|
162
|
+
/**Disables URLs that do not have an embeddable preview */
|
|
163
|
+
previewableLinksOnly?: boolean;
|
|
161
164
|
}
|
|
162
165
|
type CustomLinkPickerMessages = {
|
|
163
166
|
/** Label for the link input field */
|
|
@@ -43,6 +43,11 @@ export declare const formMessages: {
|
|
|
43
43
|
defaultMessage: string;
|
|
44
44
|
description: string;
|
|
45
45
|
};
|
|
46
|
+
noEmbedAvailable: {
|
|
47
|
+
id: string;
|
|
48
|
+
defaultMessage: string;
|
|
49
|
+
description: string;
|
|
50
|
+
};
|
|
46
51
|
};
|
|
47
52
|
export declare const linkTextMessages: {
|
|
48
53
|
linkTextLabel: {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @jsxRuntime classic
|
|
3
3
|
* @jsx jsx
|
|
4
4
|
*/
|
|
5
|
-
import { type Ref } from 'react';
|
|
5
|
+
import React, { type Ref } from 'react';
|
|
6
6
|
import { type TextFieldProps } from '@atlaskit/textfield';
|
|
7
7
|
import { type ConditionalSpotlightTargetWrapperProps } from './conditional-spotlight-target-wrapper';
|
|
8
8
|
export type TextInputProps = Omit<TextFieldProps, 'name' | 'value'> & Pick<ConditionalSpotlightTargetWrapperProps, 'spotlightTargetName'> & {
|
|
@@ -13,7 +13,7 @@ export type TextInputProps = Omit<TextFieldProps, 'name' | 'value'> & Pick<Condi
|
|
|
13
13
|
onRedo?: Function;
|
|
14
14
|
onClear?: (name: string) => void;
|
|
15
15
|
clearLabel?: string;
|
|
16
|
-
error?:
|
|
16
|
+
error?: React.ReactNode;
|
|
17
17
|
/** Ref to the link picker search input. */
|
|
18
18
|
inputRef?: Ref<HTMLInputElement>;
|
|
19
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/link-picker",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Standalone link picker",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"platform-linking-visual-refresh-v1": {
|
|
41
41
|
"type": "boolean"
|
|
42
42
|
},
|
|
43
|
+
"platform-linking-link-picker-previewable-only": {
|
|
44
|
+
"type": "boolean"
|
|
45
|
+
},
|
|
43
46
|
"bandicoots-a11y-link-picker-styling": {
|
|
44
47
|
"type": "boolean"
|
|
45
48
|
},
|
|
@@ -76,10 +79,12 @@
|
|
|
76
79
|
"@atlaskit/icon": "^26.0.0",
|
|
77
80
|
"@atlaskit/intl-messages-provider": "^2.0.0",
|
|
78
81
|
"@atlaskit/link": "^3.1.0",
|
|
82
|
+
"@atlaskit/link-provider": "^3.0.0",
|
|
79
83
|
"@atlaskit/linking-common": "^9.0.0",
|
|
80
|
-
"@atlaskit/onboarding": "^14.
|
|
84
|
+
"@atlaskit/onboarding": "^14.1.0",
|
|
81
85
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
82
86
|
"@atlaskit/primitives": "^14.7.0",
|
|
87
|
+
"@atlaskit/smart-card": "^38.1.0",
|
|
83
88
|
"@atlaskit/spinner": "^18.0.0",
|
|
84
89
|
"@atlaskit/tabs": "^18.0.0",
|
|
85
90
|
"@atlaskit/textfield": "^8.0.0",
|
|
@@ -105,8 +110,7 @@
|
|
|
105
110
|
"@af/analytics-codegen": "workspace:^",
|
|
106
111
|
"@af/integration-testing": "workspace:^",
|
|
107
112
|
"@af/visual-regression": "workspace:^",
|
|
108
|
-
"@atlaskit/dropdown-menu": "^14.
|
|
109
|
-
"@atlaskit/link-provider": "^3.0.0",
|
|
113
|
+
"@atlaskit/dropdown-menu": "^14.2.0",
|
|
110
114
|
"@atlaskit/link-test-helpers": "^8.0.0",
|
|
111
115
|
"@atlaskit/visual-regression": "workspace:^",
|
|
112
116
|
"@atlassian/feature-flags-test-utils": "^0.3.0",
|