@atlaskit/link-picker 1.16.6 → 1.16.8
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 +14 -0
- package/dist/cjs/common/analytics/context.js +1 -1
- package/dist/cjs/services/use-search-query/index.js +6 -4
- package/dist/cjs/ui/link-picker/form-footer/utils.js +1 -1
- package/dist/cjs/ui/link-picker/index.js +11 -4
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/common/analytics/context.js +1 -1
- package/dist/es2019/services/use-search-query/index.js +6 -4
- package/dist/es2019/ui/link-picker/form-footer/utils.js +1 -1
- package/dist/es2019/ui/link-picker/index.js +11 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/common/analytics/context.js +1 -1
- package/dist/esm/services/use-search-query/index.js +6 -4
- package/dist/esm/ui/link-picker/form-footer/utils.js +1 -1
- package/dist/esm/ui/link-picker/index.js +11 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/ui/link-picker/index.d.ts +2 -0
- package/package.json +3 -3
- package/dist/cjs/common/utils/url.js +0 -104
- package/dist/es2019/common/utils/url.js +0 -88
- package/dist/esm/common/utils/url.js +0 -90
- package/dist/types/common/utils/url.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/link-picker
|
|
2
2
|
|
|
3
|
+
## 1.16.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5441fa9235d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5441fa9235d) - [ux] XPC3P-106 Fix recents not showing when switching tabs in new link picker
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 1.16.7
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`10410539ac9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/10410539ac9) - Url utils added (normalizeURL and isSafeUrl). Available to export
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 1.16.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -22,7 +22,7 @@ var _analyticsNext = require("@atlaskit/analytics-next");
|
|
|
22
22
|
|
|
23
23
|
var _constants = require("../constants");
|
|
24
24
|
|
|
25
|
-
var _url = require("
|
|
25
|
+
var _url = require("@atlaskit/linking-common/url");
|
|
26
26
|
|
|
27
27
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
28
|
|
|
@@ -7,18 +7,20 @@ exports.useSearchQuery = useSearchQuery;
|
|
|
7
7
|
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
|
|
10
|
-
var _url = require("
|
|
10
|
+
var _url = require("@atlaskit/linking-common/url");
|
|
11
11
|
|
|
12
12
|
function useSearchQuery(state) {
|
|
13
13
|
var _queryState$current;
|
|
14
14
|
|
|
15
15
|
var queryState = (0, _react.useRef)(null);
|
|
16
16
|
/*
|
|
17
|
-
* When state contains a valid url AND is NOT selected from results
|
|
18
|
-
* queryState should be null to clear the items in plugin state
|
|
17
|
+
* When state contains a valid url AND is NOT selected from results, and the url was updated
|
|
18
|
+
* from the textbox, queryState should be null to clear the items in plugin state.
|
|
19
|
+
*
|
|
20
|
+
* Checking `lastEditedBy` prevents the items being cleared when the tab is changed.
|
|
19
21
|
*/
|
|
20
22
|
|
|
21
|
-
if ((0, _url.isSafeUrl)(state.url) && state.selectedIndex === -1) {
|
|
23
|
+
if ((0, _url.isSafeUrl)(state.url) && state.selectedIndex === -1 && !state.preventHidingRecents) {
|
|
22
24
|
queryState.current = null;
|
|
23
25
|
}
|
|
24
26
|
/*
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.checkSubmitDisabled = void 0;
|
|
7
7
|
|
|
8
|
-
var _url = require("
|
|
8
|
+
var _url = require("@atlaskit/linking-common/url");
|
|
9
9
|
|
|
10
10
|
var checkSubmitDisabled = function checkSubmitDisabled(isLoading, error, state, items) {
|
|
11
11
|
/*
|
|
@@ -37,7 +37,7 @@ var _constants = require("../../common/constants");
|
|
|
37
37
|
|
|
38
38
|
var _analytics2 = require("../../common/analytics");
|
|
39
39
|
|
|
40
|
-
var _url2 = require("
|
|
40
|
+
var _url2 = require("@atlaskit/linking-common/url");
|
|
41
41
|
|
|
42
42
|
var _usePlugins2 = require("../../services/use-plugins");
|
|
43
43
|
|
|
@@ -100,7 +100,8 @@ var initState = {
|
|
|
100
100
|
activeIndex: -1,
|
|
101
101
|
selectedIndex: -1,
|
|
102
102
|
invalidUrl: false,
|
|
103
|
-
activeTab: 0
|
|
103
|
+
activeTab: 0,
|
|
104
|
+
preventHidingRecents: false
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
function reducer(state, payload) {
|
|
@@ -193,7 +194,9 @@ function LinkPicker(_ref) {
|
|
|
193
194
|
/** Any on change event is triggered by manual input or paste, so source is null */
|
|
194
195
|
trackAttribute('linkFieldContentInputSource', null);
|
|
195
196
|
dispatch({
|
|
196
|
-
url: e.currentTarget.value
|
|
197
|
+
url: e.currentTarget.value,
|
|
198
|
+
// If the last action was changing tabs, make sure we're now allowing recents to be hidden
|
|
199
|
+
preventHidingRecents: false
|
|
197
200
|
});
|
|
198
201
|
}, [dispatch, trackAttribute]);
|
|
199
202
|
var handleChangeText = (0, _react.useCallback)(function (e) {
|
|
@@ -332,8 +335,12 @@ function LinkPicker(_ref) {
|
|
|
332
335
|
var _plugins$activeTab$ta, _plugins$activeTab;
|
|
333
336
|
|
|
334
337
|
dispatch({
|
|
335
|
-
|
|
338
|
+
// We don't want any selection to exist after changing tab, as the selection
|
|
339
|
+
// wouldn't mean anything.
|
|
336
340
|
activeIndex: -1,
|
|
341
|
+
selectedIndex: -1,
|
|
342
|
+
// We don't want recents to be hidden, even though we don't have a selection
|
|
343
|
+
preventHidingRecents: true,
|
|
337
344
|
invalidUrl: false,
|
|
338
345
|
activeTab: activeTab
|
|
339
346
|
});
|
package/dist/cjs/version.json
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import React, { useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { AnalyticsListener } from '@atlaskit/analytics-next';
|
|
4
4
|
import { ANALYTICS_CHANNEL } from '../constants';
|
|
5
|
-
import { normalizeUrl } from '
|
|
5
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
6
6
|
const DEFAULT_CONTEXT_ATTRIBUTES = {
|
|
7
7
|
linkState: 'newLink',
|
|
8
8
|
linkFieldContent: null,
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
-
import { isSafeUrl } from '
|
|
2
|
+
import { isSafeUrl } from '@atlaskit/linking-common/url';
|
|
3
3
|
export function useSearchQuery(state) {
|
|
4
4
|
var _queryState$current;
|
|
5
5
|
|
|
6
6
|
const queryState = useRef(null);
|
|
7
7
|
/*
|
|
8
|
-
* When state contains a valid url AND is NOT selected from results
|
|
9
|
-
* queryState should be null to clear the items in plugin state
|
|
8
|
+
* When state contains a valid url AND is NOT selected from results, and the url was updated
|
|
9
|
+
* from the textbox, queryState should be null to clear the items in plugin state.
|
|
10
|
+
*
|
|
11
|
+
* Checking `lastEditedBy` prevents the items being cleared when the tab is changed.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
|
-
if (isSafeUrl(state.url) && state.selectedIndex === -1) {
|
|
14
|
+
if (isSafeUrl(state.url) && state.selectedIndex === -1 && !state.preventHidingRecents) {
|
|
13
15
|
queryState.current = null;
|
|
14
16
|
}
|
|
15
17
|
/*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeUrl } from '
|
|
1
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
2
2
|
export const checkSubmitDisabled = (isLoading, error, state, items) => {
|
|
3
3
|
/*
|
|
4
4
|
* Enable insert when search term is a valid url and it can be normalized
|
|
@@ -11,7 +11,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
11
11
|
import createEventPayload from '../../analytics.codegen';
|
|
12
12
|
import { ANALYTICS_CHANNEL } from '../../common/constants';
|
|
13
13
|
import { useLinkPickerAnalytics, withInputFieldTracking, withLinkPickerAnalyticsContext } from '../../common/analytics';
|
|
14
|
-
import { normalizeUrl, isSafeUrl } from '
|
|
14
|
+
import { normalizeUrl, isSafeUrl } from '@atlaskit/linking-common/url';
|
|
15
15
|
import { usePlugins } from '../../services/use-plugins';
|
|
16
16
|
import { useSearchQuery } from '../../services/use-search-query';
|
|
17
17
|
import useFixHeight from '../../controllers/use-fix-height';
|
|
@@ -47,7 +47,8 @@ const initState = {
|
|
|
47
47
|
activeIndex: -1,
|
|
48
48
|
selectedIndex: -1,
|
|
49
49
|
invalidUrl: false,
|
|
50
|
-
activeTab: 0
|
|
50
|
+
activeTab: 0,
|
|
51
|
+
preventHidingRecents: false
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
function reducer(state, payload) {
|
|
@@ -137,7 +138,9 @@ function LinkPicker({
|
|
|
137
138
|
/** Any on change event is triggered by manual input or paste, so source is null */
|
|
138
139
|
trackAttribute('linkFieldContentInputSource', null);
|
|
139
140
|
dispatch({
|
|
140
|
-
url: e.currentTarget.value
|
|
141
|
+
url: e.currentTarget.value,
|
|
142
|
+
// If the last action was changing tabs, make sure we're now allowing recents to be hidden
|
|
143
|
+
preventHidingRecents: false
|
|
141
144
|
});
|
|
142
145
|
}, [dispatch, trackAttribute]);
|
|
143
146
|
const handleChangeText = useCallback(e => {
|
|
@@ -277,8 +280,12 @@ function LinkPicker({
|
|
|
277
280
|
var _plugins$activeTab$ta, _plugins$activeTab;
|
|
278
281
|
|
|
279
282
|
dispatch({
|
|
280
|
-
|
|
283
|
+
// We don't want any selection to exist after changing tab, as the selection
|
|
284
|
+
// wouldn't mean anything.
|
|
281
285
|
activeIndex: -1,
|
|
286
|
+
selectedIndex: -1,
|
|
287
|
+
// We don't want recents to be hidden, even though we don't have a selection
|
|
288
|
+
preventHidingRecents: true,
|
|
282
289
|
invalidUrl: false,
|
|
283
290
|
activeTab
|
|
284
291
|
});
|
package/dist/es2019/version.json
CHANGED
|
@@ -9,7 +9,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
9
9
|
import React, { useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
10
10
|
import { AnalyticsListener } from '@atlaskit/analytics-next';
|
|
11
11
|
import { ANALYTICS_CHANNEL } from '../constants';
|
|
12
|
-
import { normalizeUrl } from '
|
|
12
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
13
13
|
var DEFAULT_CONTEXT_ATTRIBUTES = {
|
|
14
14
|
linkState: 'newLink',
|
|
15
15
|
linkFieldContent: null,
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
-
import { isSafeUrl } from '
|
|
2
|
+
import { isSafeUrl } from '@atlaskit/linking-common/url';
|
|
3
3
|
export function useSearchQuery(state) {
|
|
4
4
|
var _queryState$current;
|
|
5
5
|
|
|
6
6
|
var queryState = useRef(null);
|
|
7
7
|
/*
|
|
8
|
-
* When state contains a valid url AND is NOT selected from results
|
|
9
|
-
* queryState should be null to clear the items in plugin state
|
|
8
|
+
* When state contains a valid url AND is NOT selected from results, and the url was updated
|
|
9
|
+
* from the textbox, queryState should be null to clear the items in plugin state.
|
|
10
|
+
*
|
|
11
|
+
* Checking `lastEditedBy` prevents the items being cleared when the tab is changed.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
|
-
if (isSafeUrl(state.url) && state.selectedIndex === -1) {
|
|
14
|
+
if (isSafeUrl(state.url) && state.selectedIndex === -1 && !state.preventHidingRecents) {
|
|
13
15
|
queryState.current = null;
|
|
14
16
|
}
|
|
15
17
|
/*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeUrl } from '
|
|
1
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
2
2
|
export var checkSubmitDisabled = function checkSubmitDisabled(isLoading, error, state, items) {
|
|
3
3
|
/*
|
|
4
4
|
* Enable insert when search term is a valid url and it can be normalized
|
|
@@ -19,7 +19,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
19
19
|
import createEventPayload from '../../analytics.codegen';
|
|
20
20
|
import { ANALYTICS_CHANNEL } from '../../common/constants';
|
|
21
21
|
import { useLinkPickerAnalytics, withInputFieldTracking, withLinkPickerAnalyticsContext } from '../../common/analytics';
|
|
22
|
-
import { normalizeUrl, isSafeUrl } from '
|
|
22
|
+
import { normalizeUrl, isSafeUrl } from '@atlaskit/linking-common/url';
|
|
23
23
|
import { usePlugins } from '../../services/use-plugins';
|
|
24
24
|
import { useSearchQuery } from '../../services/use-search-query';
|
|
25
25
|
import useFixHeight from '../../controllers/use-fix-height';
|
|
@@ -52,7 +52,8 @@ var initState = {
|
|
|
52
52
|
activeIndex: -1,
|
|
53
53
|
selectedIndex: -1,
|
|
54
54
|
invalidUrl: false,
|
|
55
|
-
activeTab: 0
|
|
55
|
+
activeTab: 0,
|
|
56
|
+
preventHidingRecents: false
|
|
56
57
|
};
|
|
57
58
|
|
|
58
59
|
function reducer(state, payload) {
|
|
@@ -145,7 +146,9 @@ function LinkPicker(_ref) {
|
|
|
145
146
|
/** Any on change event is triggered by manual input or paste, so source is null */
|
|
146
147
|
trackAttribute('linkFieldContentInputSource', null);
|
|
147
148
|
dispatch({
|
|
148
|
-
url: e.currentTarget.value
|
|
149
|
+
url: e.currentTarget.value,
|
|
150
|
+
// If the last action was changing tabs, make sure we're now allowing recents to be hidden
|
|
151
|
+
preventHidingRecents: false
|
|
149
152
|
});
|
|
150
153
|
}, [dispatch, trackAttribute]);
|
|
151
154
|
var handleChangeText = useCallback(function (e) {
|
|
@@ -284,8 +287,12 @@ function LinkPicker(_ref) {
|
|
|
284
287
|
var _plugins$activeTab$ta, _plugins$activeTab;
|
|
285
288
|
|
|
286
289
|
dispatch({
|
|
287
|
-
|
|
290
|
+
// We don't want any selection to exist after changing tab, as the selection
|
|
291
|
+
// wouldn't mean anything.
|
|
288
292
|
activeIndex: -1,
|
|
293
|
+
selectedIndex: -1,
|
|
294
|
+
// We don't want recents to be hidden, even though we don't have a selection
|
|
295
|
+
preventHidingRecents: true,
|
|
289
296
|
invalidUrl: false,
|
|
290
297
|
activeTab: activeTab
|
|
291
298
|
});
|
package/dist/esm/version.json
CHANGED
|
@@ -72,6 +72,8 @@ export interface PickerState {
|
|
|
72
72
|
displayText: string;
|
|
73
73
|
invalidUrl: boolean;
|
|
74
74
|
activeTab: number;
|
|
75
|
+
/** When true, even if the selected index is -1, don't hide the recents. */
|
|
76
|
+
preventHidingRecents: boolean;
|
|
75
77
|
}
|
|
76
78
|
declare const _default: import("react").ComponentType<LinkPickerProps>;
|
|
77
79
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/link-picker",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.8",
|
|
4
4
|
"description": "Standalone link picker",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@atlaskit/form": "^8.8.0",
|
|
38
38
|
"@atlaskit/frontend-utilities": "^2.1.0",
|
|
39
39
|
"@atlaskit/icon": "^21.11.0",
|
|
40
|
+
"@atlaskit/linking-common": "^1.18.0",
|
|
40
41
|
"@atlaskit/spinner": "^15.3.0",
|
|
41
42
|
"@atlaskit/tabs": "^13.3.0",
|
|
42
43
|
"@atlaskit/textfield": "^5.3.0",
|
|
@@ -49,7 +50,6 @@
|
|
|
49
50
|
"@emotion/react": "^11.7.1",
|
|
50
51
|
"@react-loosely-lazy/manifest": "^1.0.0",
|
|
51
52
|
"date-fns": "^2.17.0",
|
|
52
|
-
"linkify-it": "^2.0.3",
|
|
53
53
|
"react-loosely-lazy": "^1.0.0",
|
|
54
54
|
"use-debounce": "^3.4.0",
|
|
55
55
|
"uuid": "^3.1.0"
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@atlaskit/webdriver-runner": "*",
|
|
75
75
|
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
76
76
|
"@atlassian/link-picker-atlassian-plugin": "^26.0.0",
|
|
77
|
-
"@atlassian/link-picker-plugins": "^14.
|
|
77
|
+
"@atlassian/link-picker-plugins": "^14.1.0",
|
|
78
78
|
"@atlassian/recent-work-client": "^1.6.0",
|
|
79
79
|
"@atlassian/search-provider": "^2.3.0",
|
|
80
80
|
"@testing-library/dom": "^8.17.1",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.isSafeUrl = void 0;
|
|
9
|
-
exports.normalizeUrl = normalizeUrl;
|
|
10
|
-
|
|
11
|
-
var _linkifyIt = _interopRequireDefault(require("linkify-it"));
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This file has been duplicated in packages/editor/adf-schema/src/utils/url.ts
|
|
15
|
-
* Any changes made here should be mirrored there.
|
|
16
|
-
*/
|
|
17
|
-
var linkify = (0, _linkifyIt.default)();
|
|
18
|
-
linkify.add('sourcetree:', 'http:');
|
|
19
|
-
linkify.add('jamfselfservice:', 'http:');
|
|
20
|
-
var tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
|
|
21
|
-
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]';
|
|
22
|
-
tlds.push(tlds2Char);
|
|
23
|
-
linkify.tlds(tlds, false);
|
|
24
|
-
var whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^jamfselfservice:\/\/[^\s]*$/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];
|
|
25
|
-
|
|
26
|
-
var normaliseLinkHref = function normaliseLinkHref(url) {
|
|
27
|
-
var match = getLinkMatch(url);
|
|
28
|
-
return match && match.url || null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var getLinkMatch = function getLinkMatch(str) {
|
|
32
|
-
if (!str) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var match = linkifyMatch(str);
|
|
37
|
-
|
|
38
|
-
if (!match.length) {
|
|
39
|
-
match = linkify.match(str);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
var LINK_REGEXP = /(https?|ftp|jamfselfservice):\/\/[^\s]+/;
|
|
46
|
-
|
|
47
|
-
var linkifyMatch = function linkifyMatch(text) {
|
|
48
|
-
var matches = [];
|
|
49
|
-
|
|
50
|
-
if (!LINK_REGEXP.test(text)) {
|
|
51
|
-
return matches;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var startpos = 0;
|
|
55
|
-
var substr;
|
|
56
|
-
|
|
57
|
-
while (substr = text.substr(startpos)) {
|
|
58
|
-
var link = (substr.match(LINK_REGEXP) || [''])[0];
|
|
59
|
-
|
|
60
|
-
if (link) {
|
|
61
|
-
var index = substr.search(LINK_REGEXP);
|
|
62
|
-
var start = index >= 0 ? index + startpos : index;
|
|
63
|
-
var end = start + link.length;
|
|
64
|
-
matches.push({
|
|
65
|
-
index: start,
|
|
66
|
-
lastIndex: end,
|
|
67
|
-
raw: link,
|
|
68
|
-
url: link,
|
|
69
|
-
text: link,
|
|
70
|
-
schema: ''
|
|
71
|
-
});
|
|
72
|
-
startpos += end;
|
|
73
|
-
} else {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return matches;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
var isSafeUrl = function isSafeUrl(url) {
|
|
82
|
-
var urlTrimmed = url.trim();
|
|
83
|
-
return whitelistedURLPatterns.some(function (p) {
|
|
84
|
-
return p.test(urlTrimmed);
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Adds protocol to url if needed.
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
exports.isSafeUrl = isSafeUrl;
|
|
93
|
-
|
|
94
|
-
function normalizeUrl(url) {
|
|
95
|
-
if (!url) {
|
|
96
|
-
return '';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (isSafeUrl(url)) {
|
|
100
|
-
return url.trim();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return normaliseLinkHref(url);
|
|
104
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has been duplicated in packages/editor/adf-schema/src/utils/url.ts
|
|
3
|
-
* Any changes made here should be mirrored there.
|
|
4
|
-
*/
|
|
5
|
-
import LinkifyIt from 'linkify-it';
|
|
6
|
-
const linkify = LinkifyIt();
|
|
7
|
-
linkify.add('sourcetree:', 'http:');
|
|
8
|
-
linkify.add('jamfselfservice:', 'http:');
|
|
9
|
-
const tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
|
|
10
|
-
const 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]';
|
|
11
|
-
tlds.push(tlds2Char);
|
|
12
|
-
linkify.tlds(tlds, false);
|
|
13
|
-
const whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^jamfselfservice:\/\/[^\s]*$/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];
|
|
14
|
-
|
|
15
|
-
const normaliseLinkHref = url => {
|
|
16
|
-
const match = getLinkMatch(url);
|
|
17
|
-
return match && match.url || null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getLinkMatch = str => {
|
|
21
|
-
if (!str) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let match = linkifyMatch(str);
|
|
26
|
-
|
|
27
|
-
if (!match.length) {
|
|
28
|
-
match = linkify.match(str);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const LINK_REGEXP = /(https?|ftp|jamfselfservice):\/\/[^\s]+/;
|
|
35
|
-
|
|
36
|
-
const linkifyMatch = text => {
|
|
37
|
-
const matches = [];
|
|
38
|
-
|
|
39
|
-
if (!LINK_REGEXP.test(text)) {
|
|
40
|
-
return matches;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let startpos = 0;
|
|
44
|
-
let substr;
|
|
45
|
-
|
|
46
|
-
while (substr = text.substr(startpos)) {
|
|
47
|
-
const link = (substr.match(LINK_REGEXP) || [''])[0];
|
|
48
|
-
|
|
49
|
-
if (link) {
|
|
50
|
-
const index = substr.search(LINK_REGEXP);
|
|
51
|
-
const start = index >= 0 ? index + startpos : index;
|
|
52
|
-
const end = start + link.length;
|
|
53
|
-
matches.push({
|
|
54
|
-
index: start,
|
|
55
|
-
lastIndex: end,
|
|
56
|
-
raw: link,
|
|
57
|
-
url: link,
|
|
58
|
-
text: link,
|
|
59
|
-
schema: ''
|
|
60
|
-
});
|
|
61
|
-
startpos += end;
|
|
62
|
-
} else {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return matches;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const isSafeUrl = url => {
|
|
71
|
-
const urlTrimmed = url.trim();
|
|
72
|
-
return whitelistedURLPatterns.some(p => p.test(urlTrimmed));
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Adds protocol to url if needed.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
export function normalizeUrl(url) {
|
|
79
|
-
if (!url) {
|
|
80
|
-
return '';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (isSafeUrl(url)) {
|
|
84
|
-
return url.trim();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return normaliseLinkHref(url);
|
|
88
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has been duplicated in packages/editor/adf-schema/src/utils/url.ts
|
|
3
|
-
* Any changes made here should be mirrored there.
|
|
4
|
-
*/
|
|
5
|
-
import LinkifyIt from 'linkify-it';
|
|
6
|
-
var linkify = LinkifyIt();
|
|
7
|
-
linkify.add('sourcetree:', 'http:');
|
|
8
|
-
linkify.add('jamfselfservice:', 'http:');
|
|
9
|
-
var tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
|
|
10
|
-
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]';
|
|
11
|
-
tlds.push(tlds2Char);
|
|
12
|
-
linkify.tlds(tlds, false);
|
|
13
|
-
var whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^jamfselfservice:\/\/[^\s]*$/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];
|
|
14
|
-
|
|
15
|
-
var normaliseLinkHref = function normaliseLinkHref(url) {
|
|
16
|
-
var match = getLinkMatch(url);
|
|
17
|
-
return match && match.url || null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var getLinkMatch = function getLinkMatch(str) {
|
|
21
|
-
if (!str) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var match = linkifyMatch(str);
|
|
26
|
-
|
|
27
|
-
if (!match.length) {
|
|
28
|
-
match = linkify.match(str);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
var LINK_REGEXP = /(https?|ftp|jamfselfservice):\/\/[^\s]+/;
|
|
35
|
-
|
|
36
|
-
var linkifyMatch = function linkifyMatch(text) {
|
|
37
|
-
var matches = [];
|
|
38
|
-
|
|
39
|
-
if (!LINK_REGEXP.test(text)) {
|
|
40
|
-
return matches;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var startpos = 0;
|
|
44
|
-
var substr;
|
|
45
|
-
|
|
46
|
-
while (substr = text.substr(startpos)) {
|
|
47
|
-
var link = (substr.match(LINK_REGEXP) || [''])[0];
|
|
48
|
-
|
|
49
|
-
if (link) {
|
|
50
|
-
var index = substr.search(LINK_REGEXP);
|
|
51
|
-
var start = index >= 0 ? index + startpos : index;
|
|
52
|
-
var end = start + link.length;
|
|
53
|
-
matches.push({
|
|
54
|
-
index: start,
|
|
55
|
-
lastIndex: end,
|
|
56
|
-
raw: link,
|
|
57
|
-
url: link,
|
|
58
|
-
text: link,
|
|
59
|
-
schema: ''
|
|
60
|
-
});
|
|
61
|
-
startpos += end;
|
|
62
|
-
} else {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return matches;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export var isSafeUrl = function isSafeUrl(url) {
|
|
71
|
-
var urlTrimmed = url.trim();
|
|
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
|
-
}
|