@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.
Files changed (28) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/services/use-plugins/index.js +201 -0
  3. package/dist/cjs/ui/link-picker/index.js +314 -599
  4. package/dist/cjs/ui/link-picker/link-search-list/index.js +54 -82
  5. package/dist/cjs/ui/link-picker/list-item/index.js +5 -3
  6. package/dist/cjs/ui/link-picker/styled.js +5 -3
  7. package/dist/cjs/ui/link-picker/text-input/index.js +6 -4
  8. package/dist/cjs/version.json +1 -1
  9. package/dist/es2019/services/use-plugins/index.js +122 -0
  10. package/dist/es2019/ui/link-picker/index.js +294 -467
  11. package/dist/es2019/ui/link-picker/link-search-list/index.js +49 -50
  12. package/dist/es2019/ui/link-picker/list-item/index.js +4 -3
  13. package/dist/es2019/ui/link-picker/styled.js +4 -0
  14. package/dist/es2019/ui/link-picker/text-input/index.js +5 -4
  15. package/dist/es2019/version.json +1 -1
  16. package/dist/esm/services/use-plugins/index.js +187 -0
  17. package/dist/esm/ui/link-picker/index.js +304 -601
  18. package/dist/esm/ui/link-picker/link-search-list/index.js +51 -79
  19. package/dist/esm/ui/link-picker/list-item/index.js +4 -3
  20. package/dist/esm/ui/link-picker/styled.js +3 -2
  21. package/dist/esm/ui/link-picker/text-input/index.js +5 -4
  22. package/dist/esm/version.json +1 -1
  23. package/dist/types/services/use-plugins/index.d.ts +12 -0
  24. package/dist/types/ui/link-picker/index.d.ts +26 -13
  25. package/dist/types/ui/link-picker/link-search-list/index.d.ts +3 -5
  26. package/dist/types/ui/link-picker/styled.d.ts +1 -0
  27. package/dist/types/ui/link-picker/text-input/index.d.ts +1 -1
  28. package/package.json +5 -3
@@ -1,88 +1,60 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
-
7
- 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); }; }
8
-
9
- 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; } }
10
-
11
1
  /** @jsx jsx */
12
- import { PureComponent } from 'react';
13
2
  import { jsx } from '@emotion/react';
14
3
  import Spinner from '@atlaskit/spinner';
15
4
  import LinkSearchListItem from '../list-item';
16
5
  import { listContainerStyles, spinnerContainerStyles, listStyles } from './styled';
17
-
18
- var LinkSearchList = /*#__PURE__*/function (_PureComponent) {
19
- _inherits(LinkSearchList, _PureComponent);
20
-
21
- var _super = _createSuper(LinkSearchList);
22
-
23
- function LinkSearchList() {
24
- _classCallCheck(this, LinkSearchList);
25
-
26
- return _super.apply(this, arguments);
6
+ import { testIds } from '../';
7
+
8
+ var LinkSearchList = function LinkSearchList(_ref) {
9
+ var onSelect = _ref.onSelect,
10
+ onMouseEnter = _ref.onMouseEnter,
11
+ onMouseLeave = _ref.onMouseLeave,
12
+ items = _ref.items,
13
+ activeIndex = _ref.activeIndex,
14
+ selectedIndex = _ref.selectedIndex,
15
+ isLoading = _ref.isLoading,
16
+ ariaControls = _ref.ariaControls,
17
+ ariaLabelledBy = _ref.ariaLabelledBy,
18
+ role = _ref.role,
19
+ id = _ref.id;
20
+ var itemsContent;
21
+ var loadingContent;
22
+
23
+ if (items && items.length > 0) {
24
+ itemsContent = jsx("ul", {
25
+ id: id,
26
+ role: role,
27
+ css: listStyles,
28
+ "aria-controls": ariaControls,
29
+ "aria-labelledby": ariaLabelledBy,
30
+ "data-testid": testIds.searchResultList
31
+ }, items.map(function (item, index) {
32
+ return jsx(LinkSearchListItem, {
33
+ id: "".concat(testIds.searchResultItem, "-").concat(index),
34
+ role: role && 'option',
35
+ item: item,
36
+ selected: selectedIndex === index,
37
+ active: activeIndex === index,
38
+ onMouseEnter: onMouseEnter,
39
+ onMouseLeave: onMouseLeave,
40
+ onSelect: onSelect,
41
+ key: item.objectId
42
+ });
43
+ }));
27
44
  }
28
45
 
29
- _createClass(LinkSearchList, [{
30
- key: "render",
31
- value: function render() {
32
- var _this$props = this.props,
33
- onSelect = _this$props.onSelect,
34
- onMouseEnter = _this$props.onMouseEnter,
35
- onMouseLeave = _this$props.onMouseLeave,
36
- items = _this$props.items,
37
- activeIndex = _this$props.activeIndex,
38
- selectedIndex = _this$props.selectedIndex,
39
- isLoading = _this$props.isLoading,
40
- ariaControls = _this$props.ariaControls,
41
- ariaLabelledBy = _this$props.ariaLabelledBy,
42
- role = _this$props.role,
43
- id = _this$props.id;
44
- var itemsContent;
45
- var loadingContent;
46
-
47
- if (items && items.length > 0) {
48
- itemsContent = jsx("ul", {
49
- "data-testid": "link-search-list",
50
- css: listStyles,
51
- id: id,
52
- role: role,
53
- "aria-controls": ariaControls,
54
- "aria-labelledby": ariaLabelledBy
55
- }, items.map(function (item, index) {
56
- return jsx(LinkSearchListItem, {
57
- id: "link-search-list-item-".concat(index),
58
- role: role && 'option',
59
- item: item,
60
- selected: selectedIndex === index,
61
- active: activeIndex === index,
62
- onMouseEnter: onMouseEnter,
63
- onMouseLeave: onMouseLeave,
64
- onSelect: onSelect,
65
- key: item.objectId
66
- });
67
- }));
68
- }
69
-
70
- if (isLoading) {
71
- loadingContent = jsx("div", {
72
- css: spinnerContainerStyles
73
- }, jsx(Spinner, {
74
- testId: "link-picker.results-loading-indicator",
75
- size: "medium"
76
- }));
77
- }
78
-
79
- return jsx("div", {
80
- css: listContainerStyles
81
- }, itemsContent, loadingContent);
82
- }
83
- }]);
46
+ if (isLoading) {
47
+ loadingContent = jsx("div", {
48
+ css: spinnerContainerStyles
49
+ }, jsx(Spinner, {
50
+ testId: testIds.searchResultLoadingIndicator,
51
+ size: "medium"
52
+ }));
53
+ }
84
54
 
85
- return LinkSearchList;
86
- }(PureComponent);
55
+ return jsx("div", {
56
+ css: listContainerStyles
57
+ }, itemsContent, loadingContent);
58
+ };
87
59
 
88
- export { LinkSearchList as default };
60
+ export default LinkSearchList;
@@ -4,6 +4,7 @@ import { jsx } from '@emotion/react';
4
4
  import { injectIntl } from 'react-intl-next';
5
5
  import { transformTimeStamp } from '../transformTimeStamp';
6
6
  import { itemNameStyles, itemIconStyles, listItemContextStyles, listItemNameStyles, composeListItemStyles, imgStyles } from './styled';
7
+ import { testIds } from '../';
7
8
 
8
9
  var LinkSearchListItem = function LinkSearchListItem(_ref) {
9
10
  var item = _ref.item,
@@ -35,7 +36,7 @@ var LinkSearchListItem = function LinkSearchListItem(_ref) {
35
36
  role: role,
36
37
  id: id,
37
38
  "aria-selected": selected,
38
- "data-testid": "link-search-list-item",
39
+ "data-testid": testIds.searchResultItem,
39
40
  onMouseEnter: handleMouseEnter,
40
41
  onMouseLeave: handleMouseLeave,
41
42
  onClick: handleSelect
@@ -45,10 +46,10 @@ var LinkSearchListItem = function LinkSearchListItem(_ref) {
45
46
  }), jsx("div", {
46
47
  css: itemNameStyles
47
48
  }, jsx("div", {
48
- "data-testid": "link-search-list-item-title",
49
+ "data-testid": "".concat(testIds.searchResultItem, "-title"),
49
50
  css: listItemNameStyles
50
51
  }, item.name), jsx("div", {
51
- "data-testid": "link-search-list-item-subtitle",
52
+ "data-testid": "".concat(testIds.searchResultItem, "-subtitle"),
52
53
  css: listItemContextStyles
53
54
  }, container, container && date && jsx(Fragment, null, "\xA0 \u2022\xA0 "), date && jsx(Fragment, null, formatDate(date)))));
54
55
  };
@@ -1,6 +1,6 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
2
 
3
- var _templateObject, _templateObject2, _templateObject3, _templateObject4;
3
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
4
4
 
5
5
  import { token } from '@atlaskit/tokens';
6
6
  import { css } from '@emotion/react';
@@ -14,4 +14,5 @@ var LINK_PICKER_MIN_HEIGHT_IN_PX = 234;
14
14
  export var rootContainerStyles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: ", "px;\n padding: ", "px;\n box-sizing: border-box;\n line-height: initial;\n min-height: ", "px;\n"])), LINK_PICKER_WIDTH_IN_PX, gridSize() * 2, LINK_PICKER_MIN_HEIGHT_IN_PX);
15
15
  export var rootContainerStylesForLoader = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n ", "\n display: flex;\n align-items: center;\n justify-content: center;\n"])), rootContainerStyles);
16
16
  export var searchIconStyles = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n margin-left: ", "px;\n color: ", ";\n cursor: default;\n"])), gridSize() / 2, token('color.icon', N500));
17
- export var listTitleStyles = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", "\n text-transform: uppercase;\n margin-bottom: ", "px;\n"])), typography.h100(), gridSize() / 2);
17
+ export var listTitleStyles = css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", "\n text-transform: uppercase;\n margin-bottom: ", "px;\n"])), typography.h100(), gridSize() / 2);
18
+ export var tabsWrapperStyles = css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n margin-left: -", "px;\n margin-right: -", "px;\n"])), gridSize(), gridSize());
@@ -11,6 +11,7 @@ import Textfield from '@atlaskit/textfield';
11
11
  import Selectclear from '@atlaskit/icon/glyph/select-clear';
12
12
  import { isRedoEvent, isUndoEvent } from '../utils';
13
13
  import { clearTextButtonStyles, fieldStyles } from './styled';
14
+ import { testIds } from '../';
14
15
 
15
16
  var PanelTextInput = function PanelTextInput(props) {
16
17
  var name = props.name,
@@ -64,15 +65,15 @@ var PanelTextInput = function PanelTextInput(props) {
64
65
  var handleClear = useCallback(function () {
65
66
  if (inputRef.current && onClear) {
66
67
  inputRef.current.focus();
67
- onClear();
68
+ onClear(name);
68
69
  }
69
- }, [onClear]);
70
+ }, [name, onClear]);
70
71
  var clearText = restProps.value !== '' && jsx(Tooltip, {
71
72
  content: clearLabel
72
73
  }, jsx("button", {
73
74
  css: clearTextButtonStyles,
74
75
  onClick: handleClear,
75
- "data-testid": "clear-text"
76
+ "data-testid": testIds.clearUrlButton
76
77
  }, jsx(Selectclear, {
77
78
  size: "medium",
78
79
  label: clearLabel || ''
@@ -91,7 +92,7 @@ var PanelTextInput = function PanelTextInput(props) {
91
92
  elemAfterInput: clearText,
92
93
  isInvalid: !!error
93
94
  })), error && jsx(ErrorMessage, {
94
- testId: "link-error"
95
+ testId: testIds.urlError
95
96
  }, error));
96
97
  }));
97
98
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,12 @@
1
+ import { PickerState } from '../../ui/link-picker';
2
+ import { LinkPickerPlugin, LinkSearchListItemData } from '../../ui/types';
3
+ export interface LinkPickerPluginsService {
4
+ items: LinkSearchListItemData[];
5
+ isLoading: boolean;
6
+ isSelectedItem: boolean;
7
+ isActivePlugin: boolean;
8
+ tabs: {
9
+ tabTitle: string;
10
+ }[];
11
+ }
12
+ export declare function usePlugins(state: PickerState, plugins?: LinkPickerPlugin[]): LinkPickerPluginsService;
@@ -1,7 +1,23 @@
1
- /// <reference types="react" />
2
- import { WrappedComponentProps } from 'react-intl-next';
3
- import { LinkSearchListItemData, LinkInputType, LinkPickerPlugin } from '../types';
1
+ import { jsx } from '@emotion/react';
2
+ import { LinkInputType, LinkPickerPlugin } from '../types';
4
3
  export declare const RECENT_SEARCH_LIST_SIZE = 5;
4
+ export declare const testIds: {
5
+ linkPicker: string;
6
+ urlInputField: string;
7
+ textInputField: string;
8
+ searchIcon: string;
9
+ insertButton: string;
10
+ cancelButton: string;
11
+ clearUrlButton: string;
12
+ resultListTitle: string;
13
+ emptyResultPage: string;
14
+ searchResultList: string;
15
+ searchResultItem: string;
16
+ searchResultLoadingIndicator: string;
17
+ urlError: string;
18
+ tabList: string;
19
+ tabItem: string;
20
+ };
5
21
  interface Meta {
6
22
  /** Indicates how the link was picked. */
7
23
  inputMethod: LinkInputType;
@@ -28,6 +44,8 @@ export interface LinkPickerProps {
28
44
  onSubmit: (arg: OnSubmitParameter) => void;
29
45
  /** Callback to fire when the cancel button is clicked. */
30
46
  onCancel: () => void;
47
+ /** Callback to fire when content is changed inside the link picker e.g. items, when loading, tabs */
48
+ onContentResize?: () => void;
31
49
  /** The url of the linked resource for editing. */
32
50
  url?: string;
33
51
  /** The desired text to be displayed alternatively to the title of the linked resource for editing. */
@@ -35,18 +53,13 @@ export interface LinkPickerProps {
35
53
  /** Plugins that provide link suggestions / search capabilities. */
36
54
  plugins?: LinkPickerPlugin[];
37
55
  }
38
- export interface State {
39
- items: LinkSearchListItemData[];
56
+ export interface PickerState {
40
57
  selectedIndex: number;
41
58
  activeIndex: number;
42
59
  url: string;
43
- isLoading: boolean;
44
- isEditing: boolean;
45
60
  displayText: string;
46
- invalidUrl: string | null;
47
- activePlugin: number;
61
+ invalidUrl: boolean;
62
+ activeTab: number;
48
63
  }
49
- declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<WrappedComponentProps<"intl"> & LinkPickerProps>> & {
50
- WrappedComponent: import("react").ComponentType<WrappedComponentProps<"intl"> & LinkPickerProps>;
51
- };
52
- export default _default;
64
+ declare function LinkPicker({ onSubmit, onCancel, onContentResize, plugins, url: initUrl, displayText: initDisplayText, }: LinkPickerProps): jsx.JSX.Element;
65
+ export default LinkPicker;
@@ -1,8 +1,7 @@
1
1
  /** @jsx jsx */
2
- import { PureComponent } from 'react';
3
2
  import { jsx } from '@emotion/react';
4
3
  import { LinkSearchListItemData } from '../../types';
5
- export interface Props {
4
+ export interface LinkSearchListProps {
6
5
  items?: LinkSearchListItemData[];
7
6
  isLoading: boolean;
8
7
  selectedIndex: number;
@@ -15,6 +14,5 @@ export interface Props {
15
14
  role?: string;
16
15
  id?: string;
17
16
  }
18
- export default class LinkSearchList extends PureComponent<Props, {}> {
19
- render(): jsx.JSX.Element;
20
- }
17
+ declare const LinkSearchList: ({ onSelect, onMouseEnter, onMouseLeave, items, activeIndex, selectedIndex, isLoading, ariaControls, ariaLabelledBy, role, id, }: LinkSearchListProps) => jsx.JSX.Element;
18
+ export default LinkSearchList;
@@ -2,3 +2,4 @@ export declare const rootContainerStyles: import("@emotion/react").SerializedSty
2
2
  export declare const rootContainerStylesForLoader: import("@emotion/react").SerializedStyles;
3
3
  export declare const searchIconStyles: import("@emotion/react").SerializedStyles;
4
4
  export declare const listTitleStyles: import("@emotion/react").SerializedStyles;
5
+ export declare const tabsWrapperStyles: import("@emotion/react").SerializedStyles;
@@ -9,7 +9,7 @@ export interface Props extends Omit<TextFieldProps, 'value' | 'onChange' | 'auto
9
9
  onSubmit?: (value: string) => void;
10
10
  onUndo?: Function;
11
11
  onRedo?: Function;
12
- onClear?: () => void;
12
+ onClear?: Function;
13
13
  clearLabel?: string;
14
14
  error?: string | null;
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/link-picker",
3
- "version": "1.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "Standalone link picker",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
@@ -57,15 +57,17 @@
57
57
  "@atlaskit/link-test-helpers": "^1.3.0",
58
58
  "@atlaskit/popup": "^1.3.5",
59
59
  "@atlaskit/ssr": "*",
60
+ "@atlaskit/toggle": "^12.4.0",
60
61
  "@atlaskit/visual-regression": "*",
61
62
  "@atlaskit/webdriver-runner": "*",
62
63
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
63
- "@atlassian/link-picker-atlassian-plugin": "^14.0.0",
64
- "@atlassian/link-picker-plugins": "^1.0.0",
64
+ "@atlassian/link-picker-atlassian-plugin": "^16.0.0",
65
+ "@atlassian/link-picker-plugins": "^3.0.0",
65
66
  "@atlassian/search-provider": "^2.3.0",
66
67
  "@testing-library/dom": "^7.7.3",
67
68
  "@testing-library/jest-dom": "^4.1.0",
68
69
  "@testing-library/react": "^8.0.1",
70
+ "@testing-library/react-hooks": "^1.0.4",
69
71
  "@testing-library/user-event": "10.4.0",
70
72
  "enzyme": "^3.10.0",
71
73
  "fetch-mock": "^8.0.0",