cozy-sharing 5.0.0 → 6.0.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 (115) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/SharedRecipients.js +1 -1
  3. package/dist/SharedStatus.js +1 -1
  4. package/dist/SharingBanner/hooks/useSharingInfos.js +1 -1
  5. package/dist/SharingDetailsModal.js +1 -1
  6. package/dist/SharingOwnerAvatar.js +1 -1
  7. package/dist/SharingProvider.js +21 -8
  8. package/dist/components/ContactSuggestion.js +15 -27
  9. package/dist/components/EditLinkPermissionDialog.js +72 -0
  10. package/dist/components/EditLinkPermissionDialog.spec.js +48 -0
  11. package/dist/components/EditableSharingModal.js +15 -62
  12. package/dist/components/{AvatarPlusX.js → Recipient/AvatarPlusX.js} +1 -1
  13. package/dist/components/{Identity.js → Recipient/Identity.js} +17 -16
  14. package/dist/components/Recipient/LinkRecipient.js +72 -0
  15. package/dist/components/Recipient/LinkRecipientPermissions.js +159 -0
  16. package/dist/components/Recipient/OwnerIdentity.js +44 -0
  17. package/dist/components/Recipient/Recipient.js +72 -0
  18. package/dist/components/{Recipient.spec.js → Recipient/Recipient.spec.js} +4 -45
  19. package/dist/components/Recipient/RecipientAvatar.js +33 -0
  20. package/dist/components/Recipient/RecipientConfirm.js +63 -0
  21. package/dist/components/Recipient/RecipientPermissions.js +126 -0
  22. package/dist/components/Recipient/RecipientPlusX.js +45 -0
  23. package/dist/components/Recipient/RecipientStatus.js +64 -0
  24. package/dist/components/Recipient/RecipientWithoutStatus.js +45 -0
  25. package/dist/components/Recipient/RecipientsAvatars.js +100 -0
  26. package/dist/components/{RecipientsAvatars.spec.js → Recipient/RecipientsAvatars.spec.js} +43 -2
  27. package/dist/components/{recipient.styl → Recipient/recipient.styl} +6 -2
  28. package/dist/components/ShareAutosuggest.js +176 -252
  29. package/dist/components/ShareAutosuggest.spec.js +3 -2
  30. package/dist/components/ShareByEmail.js +142 -193
  31. package/dist/components/ShareByEmail.spec.js +42 -23
  32. package/dist/components/ShareByLink.js +251 -357
  33. package/dist/components/ShareDialogCozyToCozy.js +16 -4
  34. package/dist/components/ShareDialogCozyToCozy.spec.js +12 -1
  35. package/dist/components/ShareDialogOnlyByLink.js +23 -10
  36. package/dist/components/ShareDialogTwoStepsConfirmationContainer.js +7 -7
  37. package/dist/components/ShareModal.js +5 -1
  38. package/dist/components/ShareRecipientsInput.js +44 -128
  39. package/dist/components/WhoHasAccess.js +43 -5
  40. package/dist/components/WhoHasAccessLight.js +3 -19
  41. package/dist/components/autosuggest.styl +21 -36
  42. package/dist/helpers/documentType.js +6 -0
  43. package/dist/helpers/hooks.js +8 -1
  44. package/dist/helpers/link.js +5 -0
  45. package/dist/helpers/permissions.js +8 -0
  46. package/dist/helpers/recipients.js +24 -0
  47. package/dist/helpers/sharings.js +72 -53
  48. package/dist/helpers/synchronousJobQueue.js +67 -0
  49. package/dist/helpers/synchronousJobQueue.spec.js +97 -0
  50. package/dist/index.js +2 -1
  51. package/dist/queries/queries.js +72 -0
  52. package/dist/share.styl +0 -15
  53. package/dist/stylesheet.css +67 -92
  54. package/locales/en.json +29 -41
  55. package/locales/fr.json +26 -39
  56. package/package.json +10 -10
  57. package/src/SharedRecipients.jsx +1 -1
  58. package/src/SharedStatus.jsx +1 -1
  59. package/src/SharingBanner/hooks/useSharingInfos.jsx +1 -1
  60. package/src/SharingDetailsModal.jsx +1 -1
  61. package/src/SharingOwnerAvatar.jsx +1 -1
  62. package/src/SharingProvider.jsx +17 -4
  63. package/src/components/ContactSuggestion.jsx +25 -10
  64. package/src/components/EditLinkPermissionDialog.jsx +89 -0
  65. package/src/components/EditLinkPermissionDialog.spec.jsx +52 -0
  66. package/src/components/EditableSharingModal.jsx +58 -100
  67. package/src/components/{AvatarPlusX.jsx → Recipient/AvatarPlusX.jsx} +1 -1
  68. package/src/components/{Identity.jsx → Recipient/Identity.jsx} +0 -0
  69. package/src/components/Recipient/LinkRecipient.jsx +59 -0
  70. package/src/components/Recipient/LinkRecipientPermissions.jsx +157 -0
  71. package/src/components/Recipient/OwnerIdentity.jsx +20 -0
  72. package/src/components/Recipient/Recipient.jsx +79 -0
  73. package/src/components/{Recipient.spec.jsx → Recipient/Recipient.spec.jsx} +4 -42
  74. package/src/components/Recipient/RecipientAvatar.jsx +38 -0
  75. package/src/components/Recipient/RecipientConfirm.jsx +37 -0
  76. package/src/components/Recipient/RecipientPermissions.jsx +114 -0
  77. package/src/components/Recipient/RecipientPlusX.jsx +28 -0
  78. package/src/components/Recipient/RecipientStatus.jsx +48 -0
  79. package/src/components/Recipient/RecipientWithoutStatus.jsx +21 -0
  80. package/src/components/Recipient/RecipientsAvatars.jsx +108 -0
  81. package/src/components/{RecipientsAvatars.spec.jsx → Recipient/RecipientsAvatars.spec.jsx} +43 -2
  82. package/src/components/{recipient.styl → Recipient/recipient.styl} +6 -2
  83. package/src/components/ShareAutosuggest.jsx +136 -127
  84. package/src/components/ShareAutosuggest.spec.jsx +12 -8
  85. package/src/components/ShareByEmail.jsx +65 -90
  86. package/src/components/ShareByEmail.spec.jsx +39 -11
  87. package/src/components/ShareByLink.jsx +146 -238
  88. package/src/components/ShareDialogCozyToCozy.jsx +14 -2
  89. package/src/components/ShareDialogCozyToCozy.spec.jsx +8 -1
  90. package/src/components/ShareDialogOnlyByLink.jsx +30 -13
  91. package/src/components/ShareDialogTwoStepsConfirmationContainer.jsx +5 -5
  92. package/src/components/ShareModal.jsx +5 -1
  93. package/src/components/ShareRecipientsInput.jsx +30 -44
  94. package/src/components/WhoHasAccess.jsx +85 -27
  95. package/src/components/WhoHasAccessLight.jsx +2 -1
  96. package/src/components/__snapshots__/ContactSuggestion.spec.jsx.snap +915 -132
  97. package/src/components/__snapshots__/ShareRecipientsInput.spec.jsx.snap +86 -102
  98. package/src/components/autosuggest.styl +21 -36
  99. package/src/helpers/documentType.js +6 -0
  100. package/src/helpers/hooks.js +11 -1
  101. package/src/helpers/link.js +4 -0
  102. package/src/helpers/permissions.js +15 -0
  103. package/src/helpers/recipients.js +21 -0
  104. package/src/helpers/sharings.js +15 -12
  105. package/src/helpers/synchronousJobQueue.js +22 -0
  106. package/src/helpers/synchronousJobQueue.spec.js +75 -0
  107. package/src/index.jsx +1 -0
  108. package/src/queries/queries.js +75 -0
  109. package/src/share.styl +0 -15
  110. package/dist/SharingBanner/helpers/queries.js +0 -12
  111. package/dist/components/ContactsAndGroupsDataLoader.js +0 -50
  112. package/dist/components/Recipient.js +0 -450
  113. package/src/SharingBanner/helpers/queries.js +0 -14
  114. package/src/components/ContactsAndGroupsDataLoader.jsx +0 -30
  115. package/src/components/Recipient.jsx +0 -415
@@ -1,25 +1,12 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
5
- import _inherits from "@babel/runtime/helpers/inherits";
6
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
9
-
10
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
-
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
-
14
- 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); }; }
15
-
16
- 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; } }
17
-
18
- import React, { Component } from 'react';
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import React, { useState, useRef } from 'react';
19
4
  import PropTypes from 'prop-types';
20
5
  import Autosuggest from 'react-autosuggest';
21
6
  import { Spinner } from 'cozy-ui/transpiled/react/Spinner';
22
7
  import palette from 'cozy-ui/transpiled/react/palette';
8
+ import Chip from 'cozy-ui/transpiled/react/Chips';
9
+ import Avatar from 'cozy-ui/transpiled/react/Avatar';
23
10
  var styles = {
24
11
  "CozyTheme--inverted": "autosuggest__CozyTheme--inverted___QJCUa",
25
12
  "CozyTheme--normal": "autosuggest__CozyTheme--normal___1-_dN",
@@ -28,268 +15,205 @@ var styles = {
28
15
  "suggestionsContainerOpen": "autosuggest__suggestionsContainerOpen___LO5cw",
29
16
  "input": "autosuggest__input___3b74d",
30
17
  "suggestionsList": "autosuggest__suggestionsList___211Pt",
31
- "suggestion": "autosuggest__suggestion___NZSt5",
32
18
  "suggestionHighlighted": "autosuggest__suggestionHighlighted___MbW8F",
33
19
  "recipientsContainer": "autosuggest__recipientsContainer___15b1_",
34
- "recipientChip": "autosuggest__recipientChip___oRxU-",
35
- "removeRecipient": "autosuggest__removeRecipient___2wV6s"
36
- };
37
-
38
- var BoldCross = function BoldCross(props) {
39
- return /*#__PURE__*/React.createElement("svg", props, /*#__PURE__*/React.createElement("path", {
40
- fill: "#32363F",
41
- d: "M8 6.586l5.293-5.293a1 1 0 0 1 1.414 1.414L9.414 8l5.293 5.293a1 1 0 0 1-1.414 1.414L8 9.414l-5.293 5.293a1 1 0 1 1-1.414-1.414L6.586 8 1.293 2.707a1 1 0 1 1 1.414-1.414L8 6.586z"
42
- }));
43
- };
44
-
45
- BoldCross.defaultProps = {
46
- width: "16",
47
- height: "16",
48
- xmlns: "http://www.w3.org/2000/svg"
20
+ "recipientChip": "autosuggest__recipientChip___oRxU-"
49
21
  };
50
- import { getDisplayName, Contact } from '../models';
22
+ import { getDisplayName, getInitials, Contact } from '../models';
51
23
  import { cozyUrlMatch, emailMatch, groupNameMatch, fullnameMatch } from '../suggestionMatchers';
52
24
  import ContactSuggestion from './ContactSuggestion';
53
25
  import { extractEmails, validateEmail } from '../helpers/email';
54
26
 
55
- var ShareAutocomplete = /*#__PURE__*/function (_Component) {
56
- _inherits(ShareAutocomplete, _Component);
57
-
58
- var _super = _createSuper(ShareAutocomplete);
59
-
60
- function ShareAutocomplete() {
61
- var _this;
62
-
63
- _classCallCheck(this, ShareAutocomplete);
64
-
65
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
66
- args[_key] = arguments[_key];
67
- }
68
-
69
- _this = _super.call.apply(_super, [this].concat(args));
70
-
71
- _defineProperty(_assertThisInitialized(_this), "state", {
72
- inputValue: '',
73
- suggestions: []
74
- });
75
-
76
- _defineProperty(_assertThisInitialized(_this), "onSuggestionsFetchRequested", function (_ref) {
77
- var value = _ref.value;
78
-
79
- _this.setState(function (state) {
80
- return _objectSpread(_objectSpread({}, state), {}, {
81
- suggestions: _this.computeSuggestions(value)
82
- });
83
- });
84
- });
85
-
86
- _defineProperty(_assertThisInitialized(_this), "onSuggestionsClearRequested", function () {
87
- _this.setState(function (state) {
88
- return _objectSpread(_objectSpread({}, state), {}, {
89
- suggestions: []
90
- });
91
- });
92
- });
93
-
94
- _defineProperty(_assertThisInitialized(_this), "onPaste", function () {
95
- _this.isPasted = true;
27
+ var ShareAutocomplete = function ShareAutocomplete(_ref) {
28
+ var loading = _ref.loading,
29
+ contactsAndGroups = _ref.contactsAndGroups,
30
+ recipients = _ref.recipients,
31
+ onFocus = _ref.onFocus,
32
+ onPick = _ref.onPick,
33
+ onRemove = _ref.onRemove,
34
+ placeholder = _ref.placeholder;
35
+
36
+ var _useState = useState(''),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ inputValue = _useState2[0],
39
+ setInputValue = _useState2[1];
40
+
41
+ var _useState3 = useState([]),
42
+ _useState4 = _slicedToArray(_useState3, 2),
43
+ suggestions = _useState4[0],
44
+ setSuggestions = _useState4[1];
45
+
46
+ var _useState5 = useState(false),
47
+ _useState6 = _slicedToArray(_useState5, 2),
48
+ isPasted = _useState6[0],
49
+ setIsPasted = _useState6[1];
50
+
51
+ var autosuggestRef = useRef(null);
52
+
53
+ var computeSuggestions = function computeSuggestions(value) {
54
+ var inputValue = value.trim().toLowerCase();
55
+ return inputValue.length === 0 ? [] : contactsAndGroups.filter(function (contactOrGroup) {
56
+ return groupNameMatch(inputValue, contactOrGroup) || fullnameMatch(inputValue, contactOrGroup) || emailMatch(inputValue, contactOrGroup) || cozyUrlMatch(inputValue, contactOrGroup);
96
57
  });
97
-
98
- _defineProperty(_assertThisInitialized(_this), "onChange", function (event, _ref2) {
99
- var newValue = _ref2.newValue,
100
- method = _ref2.method;
101
-
102
- if (_this.isPasted) {
103
- var emails = extractEmails(newValue);
104
-
105
- if (emails) {
106
- emails.map(function (email) {
107
- _this.onPick({
108
- email: email
109
- });
110
- });
111
- }
112
-
113
- _this.isPasted = false;
114
- } else {
115
- if (typeof newValue !== 'object') {
116
- _this.setState(function (state) {
117
- return _objectSpread(_objectSpread({}, state), {}, {
118
- inputValue: newValue
119
- });
58
+ };
59
+
60
+ var onSuggestionsFetchRequested = function onSuggestionsFetchRequested(_ref2) {
61
+ var value = _ref2.value;
62
+ var computedSuggestions = computeSuggestions(value);
63
+ var newSuggestions = computedSuggestions.length === 0 && validateEmail(value) ? [{
64
+ email: value,
65
+ _type: Contact.doctype
66
+ }] : computedSuggestions;
67
+ setSuggestions(newSuggestions);
68
+ };
69
+
70
+ var onSuggestionsClearRequested = function onSuggestionsClearRequested() {
71
+ setSuggestions([]);
72
+ };
73
+
74
+ var onAutosuggestPaste = function onAutosuggestPaste() {
75
+ setIsPasted(true);
76
+ };
77
+
78
+ var onAutosuggestChange = function onAutosuggestChange(event, _ref3) {
79
+ var newValue = _ref3.newValue,
80
+ method = _ref3.method;
81
+
82
+ if (isPasted) {
83
+ var emails = extractEmails(newValue);
84
+
85
+ if (emails) {
86
+ emails.map(function (email) {
87
+ onAutosuggestPick({
88
+ email: email
120
89
  });
121
- } else if (method === 'click' || method === 'enter') {
122
- // A suggestion has been picked
123
- _this.onPick(newValue);
124
- }
125
- }
126
- });
127
-
128
- _defineProperty(_assertThisInitialized(_this), "onKeyPress", function (event) {
129
- // The user wants to add an unknown email
130
- if ((event.key === 'Enter' || event.keyCode === 13) && validateEmail(_this.state.inputValue) || (event.key === 'Space' || event.keyCode === 32) && validateEmail(_this.state.inputValue)) {
131
- _this.onPick({
132
- email: _this.state.inputValue
133
90
  });
134
91
  }
135
- });
136
92
 
137
- _defineProperty(_assertThisInitialized(_this), "onFocus", function () {
138
- _this.props.onFocus();
139
- });
140
-
141
- _defineProperty(_assertThisInitialized(_this), "onBlur", function (event, _ref3) {
142
- var highlightedSuggestion = _ref3.highlightedSuggestion;
143
-
144
- if (highlightedSuggestion) {
145
- _this.props.onPick(highlightedSuggestion);
146
-
147
- _this.setState(function (state) {
148
- return _objectSpread(_objectSpread({}, state), {}, {
149
- inputValue: ''
150
- });
151
- });
152
- } else if (_this.state.inputValue !== '' && _this.state.inputValue.match(/\S+@\S+/)) {
153
- _this.props.onPick({
154
- email: _this.state.inputValue
155
- });
156
-
157
- _this.setState(function (state) {
158
- return _objectSpread(_objectSpread({}, state), {}, {
159
- inputValue: ''
160
- });
161
- });
93
+ setIsPasted(false);
94
+ } else {
95
+ if (typeof newValue !== 'object') {
96
+ setInputValue(newValue);
97
+ } else if (method === 'click' || method === 'enter') {
98
+ // A suggestion has been picked
99
+ onAutosuggestPick(newValue);
162
100
  }
163
- });
164
-
165
- _defineProperty(_assertThisInitialized(_this), "onPick", function (value) {
166
- _this.props.onPick(value);
101
+ }
102
+ };
167
103
 
168
- _this.setState(function (state) {
169
- return _objectSpread(_objectSpread({}, state), {}, {
170
- inputValue: ''
171
- });
104
+ var onKeyPress = function onKeyPress(event) {
105
+ // The user wants to add an unknown email
106
+ if ((event.key === 'Enter' || event.keyCode === 13) && validateEmail(inputValue) || (event.key === 'Space' || event.keyCode === 32) && validateEmail(inputValue)) {
107
+ onAutosuggestPick({
108
+ email: inputValue
172
109
  });
110
+ }
111
+ };
173
112
 
174
- requestAnimationFrame(function () {
175
- return _this.input && _this.input.focus();
176
- }, 1); // don't ask...
177
- });
178
-
179
- _defineProperty(_assertThisInitialized(_this), "onRemove", function (value) {
180
- _this.props.onRemove(value);
113
+ var onKeyUp = function onKeyUp(_ref4) {
114
+ var key = _ref4.key,
115
+ keyCode = _ref4.keyCode;
181
116
 
182
- requestAnimationFrame(function () {
183
- return _this.input && _this.input.focus();
184
- }, 1);
185
- });
117
+ if (recipients.length > 0 && inputValue === '' && (key === 'Backspace' || keyCode === 8 || key === 'Delete' || keyCode === 46)) {
118
+ document.getElementById("recipient_".concat(recipients.length - 1)).focus();
119
+ }
120
+ };
186
121
 
187
- return _this;
188
- }
122
+ var onAutosuggestFocus = function onAutosuggestFocus() {
123
+ onFocus();
124
+ };
189
125
 
190
- _createClass(ShareAutocomplete, [{
191
- key: "componentDidUpdate",
192
- value: function componentDidUpdate(prevProps) {
193
- if (this.props.contactsAndGroups.length !== prevProps.contactsAndGroups.length) {
194
- this.onSuggestionsFetchRequested({
195
- value: this.state.inputValue
196
- });
197
- }
198
- }
199
- }, {
200
- key: "computeSuggestions",
201
- value: function computeSuggestions(value) {
202
- var contactsAndGroups = this.props.contactsAndGroups;
203
- var inputValue = value.trim().toLowerCase();
204
- return inputValue.length === 0 ? [] : contactsAndGroups.filter(function (contactOrGroup) {
205
- return groupNameMatch(inputValue, contactOrGroup) || fullnameMatch(inputValue, contactOrGroup) || emailMatch(inputValue, contactOrGroup) || cozyUrlMatch(inputValue, contactOrGroup);
126
+ var onAutosuggestBlur = function onAutosuggestBlur() {
127
+ if (inputValue !== '' && inputValue.match(/\S+@\S+/)) {
128
+ onAutosuggestPick({
129
+ email: inputValue
206
130
  });
207
131
  }
208
- }, {
209
- key: "renderInput",
210
- value: function renderInput(inputProps) {
211
- var _this2 = this;
212
-
213
- var _this$props = this.props,
214
- loading = _this$props.loading,
215
- recipients = _this$props.recipients;
216
- return /*#__PURE__*/React.createElement("div", {
217
- className: styles['recipientsContainer']
218
- }, recipients.map(function (recipient, idx) {
219
- var value = getDisplayName(recipient);
220
- return /*#__PURE__*/React.createElement("div", {
221
- className: styles['recipientChip'],
222
- key: "key_recipient_".concat(idx)
223
- }, /*#__PURE__*/React.createElement("span", null, value), /*#__PURE__*/React.createElement("button", {
224
- className: styles['removeRecipient'],
225
- onClick: function onClick() {
226
- return _this2.onRemove(recipient);
227
- }
228
- }, /*#__PURE__*/React.createElement(BoldCross, null)));
229
- }), /*#__PURE__*/React.createElement("input", _extends({}, inputProps, {
230
- onKeyPress: this.onKeyPress
231
- })), loading && /*#__PURE__*/React.createElement(Spinner, {
232
- color: palette.dodgerBlue,
233
- className: "u-flex u-flex-items-center"
234
- }));
235
- }
236
- }, {
237
- key: "render",
238
- value: function render() {
239
- var _this3 = this;
240
-
241
- var _this$state = this.state,
242
- inputValue = _this$state.inputValue,
243
- suggestions = _this$state.suggestions;
244
- var _this$props2 = this.props,
245
- contactsAndGroups = _this$props2.contactsAndGroups,
246
- placeholder = _this$props2.placeholder;
247
- return /*#__PURE__*/React.createElement(Autosuggest, {
248
- ref: function ref(self) {
249
- _this3.input = self ? self.input : null;
132
+ };
133
+
134
+ var onAutosuggestPick = function onAutosuggestPick(value) {
135
+ var _autosuggestRef$curre, _autosuggestRef$curre2;
136
+
137
+ onPick(value);
138
+ setInputValue('');
139
+ autosuggestRef === null || autosuggestRef === void 0 ? void 0 : (_autosuggestRef$curre = autosuggestRef.current) === null || _autosuggestRef$curre === void 0 ? void 0 : (_autosuggestRef$curre2 = _autosuggestRef$curre.input) === null || _autosuggestRef$curre2 === void 0 ? void 0 : _autosuggestRef$curre2.focus();
140
+ };
141
+
142
+ var onAutosuggestRemove = function onAutosuggestRemove(value) {
143
+ var _autosuggestRef$curre3, _autosuggestRef$curre4;
144
+
145
+ onRemove(value);
146
+ autosuggestRef === null || autosuggestRef === void 0 ? void 0 : (_autosuggestRef$curre3 = autosuggestRef.current) === null || _autosuggestRef$curre3 === void 0 ? void 0 : (_autosuggestRef$curre4 = _autosuggestRef$curre3.input) === null || _autosuggestRef$curre4 === void 0 ? void 0 : _autosuggestRef$curre4.focus();
147
+ };
148
+
149
+ var renderInput = function renderInput(inputProps) {
150
+ return /*#__PURE__*/React.createElement("div", {
151
+ className: styles['recipientsContainer']
152
+ }, recipients.map(function (recipient, idx) {
153
+ var avatarText = getInitials(recipient);
154
+ var name = getDisplayName(recipient);
155
+ return /*#__PURE__*/React.createElement(Chip, {
156
+ id: "recipient_".concat(idx),
157
+ key: "key_recipient_".concat(idx),
158
+ avatar: /*#__PURE__*/React.createElement(Avatar, {
159
+ text: avatarText,
160
+ size: "xsmall"
161
+ }),
162
+ label: name,
163
+ onDelete: function onDelete() {
164
+ onAutosuggestRemove(recipient);
250
165
  },
251
- theme: styles,
252
- suggestions: suggestions.slice(0, 20),
253
- getSuggestionValue: function getSuggestionValue(contact) {
254
- return contact;
255
- },
256
- onSuggestionsFetchRequested: this.onSuggestionsFetchRequested,
257
- onSuggestionsClearRequested: this.onSuggestionsClearRequested,
258
- renderSuggestion: function renderSuggestion(contactOrGroup) {
259
- return /*#__PURE__*/React.createElement(ContactSuggestion, {
260
- contacts: contactsAndGroups.filter(function (item) {
261
- return item._type === Contact.doctype;
262
- }),
263
- contactOrGroup: contactOrGroup
264
- });
265
- },
266
- renderInputComponent: function renderInputComponent(props) {
267
- return _this3.renderInput(props);
268
- },
269
- highlightFirstSuggestion: true,
270
- inputProps: {
271
- onFocus: this.onFocus,
272
- onChange: this.onChange,
273
- onPaste: this.onPaste,
274
- onBlur: this.onBlur,
275
- value: inputValue,
276
- type: 'email',
277
- placeholder: placeholder
278
- }
166
+ className: styles['recipientChip']
279
167
  });
168
+ }), /*#__PURE__*/React.createElement("input", _extends({}, inputProps, {
169
+ onKeyPress: onKeyPress,
170
+ onKeyUp: onKeyUp
171
+ })), loading && /*#__PURE__*/React.createElement(Spinner, {
172
+ color: palette.dodgerBlue,
173
+ className: "u-flex u-flex-items-center"
174
+ }));
175
+ };
176
+
177
+ var renderSuggestion = function renderSuggestion(contactOrGroup) {
178
+ return /*#__PURE__*/React.createElement(ContactSuggestion, {
179
+ contacts: contactsAndGroups.filter(function (item) {
180
+ return item._type === Contact.doctype;
181
+ }),
182
+ contactOrGroup: contactOrGroup
183
+ });
184
+ };
185
+
186
+ return /*#__PURE__*/React.createElement(Autosuggest, {
187
+ ref: autosuggestRef,
188
+ theme: styles,
189
+ suggestions: suggestions.slice(0, 20),
190
+ getSuggestionValue: function getSuggestionValue(contact) {
191
+ return contact;
192
+ },
193
+ onSuggestionsFetchRequested: onSuggestionsFetchRequested,
194
+ onSuggestionsClearRequested: onSuggestionsClearRequested,
195
+ renderSuggestion: renderSuggestion,
196
+ renderInputComponent: renderInput,
197
+ highlightFirstSuggestion: true,
198
+ inputProps: {
199
+ onFocus: onAutosuggestFocus,
200
+ onChange: onAutosuggestChange,
201
+ onPaste: onAutosuggestPaste,
202
+ onBlur: onAutosuggestBlur,
203
+ value: inputValue,
204
+ type: 'email',
205
+ placeholder: placeholder
280
206
  }
281
- }]);
282
-
283
- return ShareAutocomplete;
284
- }(Component);
207
+ });
208
+ };
285
209
 
286
- export { ShareAutocomplete as default };
287
210
  ShareAutocomplete.propTypes = {
211
+ loading: PropTypes.bool,
288
212
  contactsAndGroups: PropTypes.array,
289
- placeholder: PropTypes.string,
213
+ recipients: PropTypes.array.isRequired,
290
214
  onFocus: PropTypes.func.isRequired,
291
215
  onPick: PropTypes.func.isRequired,
292
216
  onRemove: PropTypes.func.isRequired,
293
- loading: PropTypes.bool,
294
- recipients: PropTypes.array.isRequired
295
- };
217
+ placeholder: PropTypes.string
218
+ };
219
+ export default ShareAutocomplete;
@@ -1,20 +1,21 @@
1
1
  import React from 'react';
2
2
  import { render, fireEvent } from '@testing-library/react';
3
3
  import ShareAutosuggest from './ShareAutosuggest';
4
+ import AppLike from '../../test/AppLike';
4
5
  describe('ShareAutosuggest', function () {
5
6
  it('tests if ShareAutosuggest calls onFocus and onPick', function () {
6
7
  var onPick = jest.fn();
7
8
  var onFocus = jest.fn();
8
9
  var onRemove = jest.fn();
9
10
 
10
- var _render = render( /*#__PURE__*/React.createElement(ShareAutosuggest, {
11
+ var _render = render( /*#__PURE__*/React.createElement(AppLike, null, /*#__PURE__*/React.createElement(ShareAutosuggest, {
11
12
  contactsAndGroups: [],
12
13
  placeholder: "myPlaceHolder",
13
14
  onPick: onPick,
14
15
  onFocus: onFocus,
15
16
  recipients: [],
16
17
  onRemove: onRemove
17
- })),
18
+ }))),
18
19
  getByPlaceholderText = _render.getByPlaceholderText;
19
20
 
20
21
  var inputNode = getByPlaceholderText('myPlaceHolder');