@atlaskit/link-picker 1.4.1 → 1.6.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 +19 -0
- package/dist/cjs/services/use-plugins/index.js +201 -0
- package/dist/cjs/ui/link-picker/index.js +314 -599
- package/dist/cjs/ui/link-picker/link-search-list/index.js +54 -82
- package/dist/cjs/ui/link-picker/list-item/index.js +5 -3
- package/dist/cjs/ui/link-picker/styled.js +5 -3
- package/dist/cjs/ui/link-picker/text-input/index.js +6 -4
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/services/use-plugins/index.js +122 -0
- package/dist/es2019/ui/link-picker/index.js +294 -467
- package/dist/es2019/ui/link-picker/link-search-list/index.js +49 -50
- package/dist/es2019/ui/link-picker/list-item/index.js +4 -3
- package/dist/es2019/ui/link-picker/styled.js +4 -0
- package/dist/es2019/ui/link-picker/text-input/index.js +5 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/services/use-plugins/index.js +187 -0
- package/dist/esm/ui/link-picker/index.js +304 -601
- package/dist/esm/ui/link-picker/link-search-list/index.js +51 -79
- package/dist/esm/ui/link-picker/list-item/index.js +4 -3
- package/dist/esm/ui/link-picker/styled.js +3 -2
- package/dist/esm/ui/link-picker/text-input/index.js +5 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/services/use-plugins/index.d.ts +12 -0
- package/dist/types/ui/link-picker/index.d.ts +26 -13
- package/dist/types/ui/link-picker/link-search-list/index.d.ts +3 -5
- package/dist/types/ui/link-picker/styled.d.ts +1 -0
- package/dist/types/ui/link-picker/text-input/index.d.ts +1 -1
- package/package.json +5 -3
|
@@ -7,19 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
|
|
16
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
20
|
-
var _react = require("react");
|
|
21
|
-
|
|
22
|
-
var _react2 = require("@emotion/react");
|
|
10
|
+
var _react = require("@emotion/react");
|
|
23
11
|
|
|
24
12
|
var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
|
|
25
13
|
|
|
@@ -27,76 +15,60 @@ var _listItem = _interopRequireDefault(require("../list-item"));
|
|
|
27
15
|
|
|
28
16
|
var _styled = require("./styled");
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
18
|
+
var _ = require("../");
|
|
19
|
+
|
|
20
|
+
/** @jsx jsx */
|
|
21
|
+
var LinkSearchList = function LinkSearchList(_ref) {
|
|
22
|
+
var onSelect = _ref.onSelect,
|
|
23
|
+
onMouseEnter = _ref.onMouseEnter,
|
|
24
|
+
onMouseLeave = _ref.onMouseLeave,
|
|
25
|
+
items = _ref.items,
|
|
26
|
+
activeIndex = _ref.activeIndex,
|
|
27
|
+
selectedIndex = _ref.selectedIndex,
|
|
28
|
+
isLoading = _ref.isLoading,
|
|
29
|
+
ariaControls = _ref.ariaControls,
|
|
30
|
+
ariaLabelledBy = _ref.ariaLabelledBy,
|
|
31
|
+
role = _ref.role,
|
|
32
|
+
id = _ref.id;
|
|
33
|
+
var itemsContent;
|
|
34
|
+
var loadingContent;
|
|
35
|
+
|
|
36
|
+
if (items && items.length > 0) {
|
|
37
|
+
itemsContent = (0, _react.jsx)("ul", {
|
|
38
|
+
id: id,
|
|
39
|
+
role: role,
|
|
40
|
+
css: _styled.listStyles,
|
|
41
|
+
"aria-controls": ariaControls,
|
|
42
|
+
"aria-labelledby": ariaLabelledBy,
|
|
43
|
+
"data-testid": _.testIds.searchResultList
|
|
44
|
+
}, items.map(function (item, index) {
|
|
45
|
+
return (0, _react.jsx)(_listItem.default, {
|
|
46
|
+
id: "".concat(_.testIds.searchResultItem, "-").concat(index),
|
|
47
|
+
role: role && 'option',
|
|
48
|
+
item: item,
|
|
49
|
+
selected: selectedIndex === index,
|
|
50
|
+
active: activeIndex === index,
|
|
51
|
+
onMouseEnter: onMouseEnter,
|
|
52
|
+
onMouseLeave: onMouseLeave,
|
|
53
|
+
onSelect: onSelect,
|
|
54
|
+
key: item.objectId
|
|
55
|
+
});
|
|
56
|
+
}));
|
|
42
57
|
}
|
|
43
58
|
|
|
44
|
-
(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
activeIndex = _this$props.activeIndex,
|
|
53
|
-
selectedIndex = _this$props.selectedIndex,
|
|
54
|
-
isLoading = _this$props.isLoading,
|
|
55
|
-
ariaControls = _this$props.ariaControls,
|
|
56
|
-
ariaLabelledBy = _this$props.ariaLabelledBy,
|
|
57
|
-
role = _this$props.role,
|
|
58
|
-
id = _this$props.id;
|
|
59
|
-
var itemsContent;
|
|
60
|
-
var loadingContent;
|
|
61
|
-
|
|
62
|
-
if (items && items.length > 0) {
|
|
63
|
-
itemsContent = (0, _react2.jsx)("ul", {
|
|
64
|
-
"data-testid": "link-search-list",
|
|
65
|
-
css: _styled.listStyles,
|
|
66
|
-
id: id,
|
|
67
|
-
role: role,
|
|
68
|
-
"aria-controls": ariaControls,
|
|
69
|
-
"aria-labelledby": ariaLabelledBy
|
|
70
|
-
}, items.map(function (item, index) {
|
|
71
|
-
return (0, _react2.jsx)(_listItem.default, {
|
|
72
|
-
id: "link-search-list-item-".concat(index),
|
|
73
|
-
role: role && 'option',
|
|
74
|
-
item: item,
|
|
75
|
-
selected: selectedIndex === index,
|
|
76
|
-
active: activeIndex === index,
|
|
77
|
-
onMouseEnter: onMouseEnter,
|
|
78
|
-
onMouseLeave: onMouseLeave,
|
|
79
|
-
onSelect: onSelect,
|
|
80
|
-
key: item.objectId
|
|
81
|
-
});
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (isLoading) {
|
|
86
|
-
loadingContent = (0, _react2.jsx)("div", {
|
|
87
|
-
css: _styled.spinnerContainerStyles
|
|
88
|
-
}, (0, _react2.jsx)(_spinner.default, {
|
|
89
|
-
testId: "link-picker.results-loading-indicator",
|
|
90
|
-
size: "medium"
|
|
91
|
-
}));
|
|
92
|
-
}
|
|
59
|
+
if (isLoading) {
|
|
60
|
+
loadingContent = (0, _react.jsx)("div", {
|
|
61
|
+
css: _styled.spinnerContainerStyles
|
|
62
|
+
}, (0, _react.jsx)(_spinner.default, {
|
|
63
|
+
testId: _.testIds.searchResultLoadingIndicator,
|
|
64
|
+
size: "medium"
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
93
67
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}]);
|
|
99
|
-
return LinkSearchList;
|
|
100
|
-
}(_react.PureComponent);
|
|
68
|
+
return (0, _react.jsx)("div", {
|
|
69
|
+
css: _styled.listContainerStyles
|
|
70
|
+
}, itemsContent, loadingContent);
|
|
71
|
+
};
|
|
101
72
|
|
|
102
|
-
|
|
73
|
+
var _default = LinkSearchList;
|
|
74
|
+
exports.default = _default;
|
|
@@ -15,6 +15,8 @@ var _transformTimeStamp = require("../transformTimeStamp");
|
|
|
15
15
|
|
|
16
16
|
var _styled = require("./styled");
|
|
17
17
|
|
|
18
|
+
var _ = require("../");
|
|
19
|
+
|
|
18
20
|
/** @jsx jsx */
|
|
19
21
|
var LinkSearchListItem = function LinkSearchListItem(_ref) {
|
|
20
22
|
var item = _ref.item,
|
|
@@ -46,7 +48,7 @@ var LinkSearchListItem = function LinkSearchListItem(_ref) {
|
|
|
46
48
|
role: role,
|
|
47
49
|
id: id,
|
|
48
50
|
"aria-selected": selected,
|
|
49
|
-
"data-testid":
|
|
51
|
+
"data-testid": _.testIds.searchResultItem,
|
|
50
52
|
onMouseEnter: handleMouseEnter,
|
|
51
53
|
onMouseLeave: handleMouseLeave,
|
|
52
54
|
onClick: handleSelect
|
|
@@ -56,10 +58,10 @@ var LinkSearchListItem = function LinkSearchListItem(_ref) {
|
|
|
56
58
|
}), (0, _react2.jsx)("div", {
|
|
57
59
|
css: _styled.itemNameStyles
|
|
58
60
|
}, (0, _react2.jsx)("div", {
|
|
59
|
-
"data-testid": "
|
|
61
|
+
"data-testid": "".concat(_.testIds.searchResultItem, "-title"),
|
|
60
62
|
css: _styled.listItemNameStyles
|
|
61
63
|
}, item.name), (0, _react2.jsx)("div", {
|
|
62
|
-
"data-testid": "
|
|
64
|
+
"data-testid": "".concat(_.testIds.searchResultItem, "-subtitle"),
|
|
63
65
|
css: _styled.listItemContextStyles
|
|
64
66
|
}, container, container && date && (0, _react2.jsx)(_react.Fragment, null, "\xA0 \u2022\xA0 "), date && (0, _react2.jsx)(_react.Fragment, null, formatDate(date)))));
|
|
65
67
|
};
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.searchIconStyles = exports.rootContainerStylesForLoader = exports.rootContainerStyles = exports.listTitleStyles = void 0;
|
|
8
|
+
exports.tabsWrapperStyles = exports.searchIconStyles = exports.rootContainerStylesForLoader = exports.rootContainerStyles = exports.listTitleStyles = void 0;
|
|
9
9
|
|
|
10
10
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
11
11
|
|
|
@@ -19,7 +19,7 @@ var _theme = require("@atlaskit/theme");
|
|
|
19
19
|
|
|
20
20
|
var _constants = require("@atlaskit/theme/constants");
|
|
21
21
|
|
|
22
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
22
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
23
23
|
|
|
24
24
|
var LINK_PICKER_WIDTH_IN_PX = 342;
|
|
25
25
|
var LINK_PICKER_MIN_HEIGHT_IN_PX = 234;
|
|
@@ -30,4 +30,6 @@ exports.rootContainerStylesForLoader = rootContainerStylesForLoader;
|
|
|
30
30
|
var searchIconStyles = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n margin-left: ", "px;\n color: ", ";\n cursor: default;\n"])), (0, _constants.gridSize)() / 2, (0, _tokens.token)('color.icon', _colors.N500));
|
|
31
31
|
exports.searchIconStyles = searchIconStyles;
|
|
32
32
|
var listTitleStyles = (0, _react.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n ", "\n text-transform: uppercase;\n margin-bottom: ", "px;\n"])), _theme.typography.h100(), (0, _constants.gridSize)() / 2);
|
|
33
|
-
exports.listTitleStyles = listTitleStyles;
|
|
33
|
+
exports.listTitleStyles = listTitleStyles;
|
|
34
|
+
var tabsWrapperStyles = (0, _react.css)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n margin-left: -", "px;\n margin-right: -", "px;\n"])), (0, _constants.gridSize)(), (0, _constants.gridSize)());
|
|
35
|
+
exports.tabsWrapperStyles = tabsWrapperStyles;
|
|
@@ -27,6 +27,8 @@ var _utils = require("../utils");
|
|
|
27
27
|
|
|
28
28
|
var _styled = require("./styled");
|
|
29
29
|
|
|
30
|
+
var _ = require("../");
|
|
31
|
+
|
|
30
32
|
var _excluded = ["name", "label", "autoFocus", "onSubmit", "onRedo", "onUndo", "onChange", "onKeyDown", "onClear", "clearLabel", "error"];
|
|
31
33
|
|
|
32
34
|
var PanelTextInput = function PanelTextInput(props) {
|
|
@@ -80,15 +82,15 @@ var PanelTextInput = function PanelTextInput(props) {
|
|
|
80
82
|
var handleClear = (0, _react.useCallback)(function () {
|
|
81
83
|
if (inputRef.current && onClear) {
|
|
82
84
|
inputRef.current.focus();
|
|
83
|
-
onClear();
|
|
85
|
+
onClear(name);
|
|
84
86
|
}
|
|
85
|
-
}, [onClear]);
|
|
87
|
+
}, [name, onClear]);
|
|
86
88
|
var clearText = restProps.value !== '' && (0, _react2.jsx)(_tooltip.default, {
|
|
87
89
|
content: clearLabel
|
|
88
90
|
}, (0, _react2.jsx)("button", {
|
|
89
91
|
css: _styled.clearTextButtonStyles,
|
|
90
92
|
onClick: handleClear,
|
|
91
|
-
"data-testid":
|
|
93
|
+
"data-testid": _.testIds.clearUrlButton
|
|
92
94
|
}, (0, _react2.jsx)(_selectClear.default, {
|
|
93
95
|
size: "medium",
|
|
94
96
|
label: clearLabel || ''
|
|
@@ -107,7 +109,7 @@ var PanelTextInput = function PanelTextInput(props) {
|
|
|
107
109
|
elemAfterInput: clearText,
|
|
108
110
|
isInvalid: !!error
|
|
109
111
|
})), error && (0, _react2.jsx)(_form.ErrorMessage, {
|
|
110
|
-
testId:
|
|
112
|
+
testId: _.testIds.urlError
|
|
111
113
|
}, error));
|
|
112
114
|
}));
|
|
113
115
|
};
|
package/dist/cjs/version.json
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useEffect, useRef, useReducer, useMemo } from 'react';
|
|
2
|
+
import { RECENT_SEARCH_LIST_SIZE } from '../../ui/link-picker';
|
|
3
|
+
import { isSafeUrl } from '../../ui/link-picker/url';
|
|
4
|
+
|
|
5
|
+
function reducer(state, payload) {
|
|
6
|
+
return { ...state,
|
|
7
|
+
...payload
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function usePlugins(state, plugins) {
|
|
12
|
+
const [pluginState, dispatch] = useReducer(reducer, {
|
|
13
|
+
items: [],
|
|
14
|
+
isLoading: false
|
|
15
|
+
});
|
|
16
|
+
const {
|
|
17
|
+
url,
|
|
18
|
+
selectedIndex
|
|
19
|
+
} = state;
|
|
20
|
+
const {
|
|
21
|
+
items,
|
|
22
|
+
isLoading
|
|
23
|
+
} = pluginState;
|
|
24
|
+
const activePlugin = !plugins || plugins.length === 0 ? null : plugins[state.activeTab];
|
|
25
|
+
const queryVersion = useRef(0);
|
|
26
|
+
const pluginRef = useRef(activePlugin);
|
|
27
|
+
const selectedItem = items[selectedIndex];
|
|
28
|
+
const isSelectedItem = (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.url) === url;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!activePlugin) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isSelectedItem) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (isSafeUrl(url) && url.length) {
|
|
39
|
+
dispatch({
|
|
40
|
+
items: [],
|
|
41
|
+
isLoading: false
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const updates = activePlugin.resolve({
|
|
47
|
+
query: url
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (pluginRef.current !== activePlugin) {
|
|
51
|
+
dispatch({
|
|
52
|
+
items: [],
|
|
53
|
+
isLoading: true
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
dispatch({
|
|
57
|
+
isLoading: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const newQuery = ++queryVersion.current;
|
|
62
|
+
|
|
63
|
+
const updateResults = async () => {
|
|
64
|
+
try {
|
|
65
|
+
while (newQuery === queryVersion.current) {
|
|
66
|
+
let done = false;
|
|
67
|
+
let value;
|
|
68
|
+
|
|
69
|
+
if (updates instanceof Promise) {
|
|
70
|
+
done = true;
|
|
71
|
+
value = await updates;
|
|
72
|
+
} else {
|
|
73
|
+
var _result$done;
|
|
74
|
+
|
|
75
|
+
const result = await updates.next();
|
|
76
|
+
done = (_result$done = result.done) !== null && _result$done !== void 0 ? _result$done : false;
|
|
77
|
+
value = result.value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (newQuery !== queryVersion.current) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
dispatch({
|
|
85
|
+
items: limit(value.data),
|
|
86
|
+
isLoading: !done
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (done) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
dispatch({
|
|
95
|
+
isLoading: false
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
updateResults();
|
|
101
|
+
}, [activePlugin, queryVersion, url, isSelectedItem]);
|
|
102
|
+
const tabs = useMemo(() => {
|
|
103
|
+
if (!plugins || plugins.length <= 1) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return plugins.filter(plugin => !!plugin.tabTitle).map(plugin => ({
|
|
108
|
+
tabTitle: plugin.tabTitle
|
|
109
|
+
}));
|
|
110
|
+
}, [plugins]);
|
|
111
|
+
return {
|
|
112
|
+
tabs,
|
|
113
|
+
items,
|
|
114
|
+
isLoading,
|
|
115
|
+
isSelectedItem,
|
|
116
|
+
isActivePlugin: !!activePlugin
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function limit(items) {
|
|
121
|
+
return items.slice(0, RECENT_SEARCH_LIST_SIZE);
|
|
122
|
+
}
|