cozy-ui 127.10.1 → 127.12.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 +16 -0
- package/package.json +1 -1
- package/react/Contacts/GroupsSelect/GroupCreation.jsx +95 -0
- package/react/Contacts/GroupsSelect/GroupsSelect.jsx +159 -0
- package/react/Contacts/GroupsSelect/GroupsSelect.spec.jsx +248 -0
- package/react/Contacts/GroupsSelect/GroupsSelectProvider.jsx +39 -0
- package/react/Contacts/GroupsSelect/Readme.md +1 -0
- package/react/Contacts/GroupsSelect/SelectBox/Control.jsx +36 -0
- package/react/Contacts/GroupsSelect/SelectBox/EditGroupName.jsx +52 -0
- package/react/Contacts/GroupsSelect/SelectBox/Menu.jsx +26 -0
- package/react/Contacts/GroupsSelect/SelectBox/Option.jsx +67 -0
- package/react/Contacts/GroupsSelect/SelectBox/SelectContainer.jsx +15 -0
- package/react/Contacts/GroupsSelect/SelectBox/styles.styl +2 -0
- package/react/Contacts/GroupsSelect/helpers.js +25 -0
- package/react/Contacts/GroupsSelect/locales/en.json +21 -0
- package/react/Contacts/GroupsSelect/locales/fr.json +21 -0
- package/react/Contacts/GroupsSelect/locales/index.jsx +12 -0
- package/react/Contacts/GroupsSelect/styles.styl +47 -0
- package/react/Contacts/GroupsSelect/useGroupSelect.jsx +88 -0
- package/react/Contacts/Header/GroupsSelection.jsx +74 -0
- package/react/Contacts/Header/ImportDropdown.jsx +78 -0
- package/react/Contacts/Header/Readme.md +40 -0
- package/react/Contacts/Header/SearchInput.jsx +19 -0
- package/react/Contacts/Header/index.jsx +79 -0
- package/react/Contacts/Header/locales/en.json +15 -0
- package/react/Contacts/Header/locales/fr.json +15 -0
- package/react/Contacts/Header/locales/index.jsx +12 -0
- package/react/Contacts/Readme.md +1 -0
- package/react/ContactsList/ContactCell.jsx +58 -0
- package/react/ContactsList/helpers.js +50 -1
- package/react/ContactsList/helpers.spec.js +50 -1
- package/react/ContactsList/locales/en.json +3 -1
- package/react/ContactsList/locales/fr.json +3 -1
- package/react/providers/Selection/Readme.md +28 -0
- package/react/providers/Selection/index.jsx +85 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupCreation.d.ts +3 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupCreation.js +133 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelect.d.ts +56 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelect.js +181 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelect.spec.d.ts +22 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelectProvider.d.ts +5 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelectProvider.js +38 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Control.d.ts +14 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Control.js +37 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/EditGroupName.d.ts +7 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/EditGroupName.js +71 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Menu.d.ts +7 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Menu.js +34 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Option.d.ts +18 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Option.js +66 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/SelectContainer.d.ts +2 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/SelectContainer.js +12 -0
- package/transpiled/react/Contacts/GroupsSelect/helpers.d.ts +9 -0
- package/transpiled/react/Contacts/GroupsSelect/helpers.js +30 -0
- package/transpiled/react/Contacts/GroupsSelect/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/GroupsSelect/locales/index.js +49 -0
- package/transpiled/react/Contacts/GroupsSelect/useGroupSelect.d.ts +11 -0
- package/transpiled/react/Contacts/GroupsSelect/useGroupSelect.js +179 -0
- package/transpiled/react/Contacts/Header/GroupsSelection.d.ts +7 -0
- package/transpiled/react/Contacts/Header/GroupsSelection.js +84 -0
- package/transpiled/react/Contacts/Header/ImportDropdown.d.ts +4 -0
- package/transpiled/react/Contacts/Header/ImportDropdown.js +88 -0
- package/transpiled/react/Contacts/Header/SearchInput.d.ts +4 -0
- package/transpiled/react/Contacts/Header/SearchInput.js +24 -0
- package/transpiled/react/Contacts/Header/index.d.ts +26 -0
- package/transpiled/react/Contacts/Header/index.js +72 -0
- package/transpiled/react/Contacts/Header/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/Header/locales/index.js +37 -0
- package/transpiled/react/ContactsList/ContactCell.d.ts +8 -0
- package/transpiled/react/ContactsList/ContactCell.js +68 -0
- package/transpiled/react/ContactsList/helpers.d.ts +1 -0
- package/transpiled/react/ContactsList/helpers.js +51 -1
- package/transpiled/react/ContactsList/locales/withContactsListLocales.js +6 -2
- package/transpiled/react/providers/Selection/index.d.ts +6 -0
- package/transpiled/react/providers/Selection/index.js +99 -0
- package/transpiled/react/stylesheet.css +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
1
2
|
export function buildLastNameFirst(contact) {
|
|
2
3
|
var givenName = contact.name && contact.name.givenName ? contact.name.givenName.toUpperCase() : '';
|
|
3
4
|
var familyName = contact.name && contact.name.familyName ? contact.name.familyName.toUpperCase() : '';
|
|
@@ -28,15 +29,39 @@ var makeHeader = function makeHeader(contact, t) {
|
|
|
28
29
|
var name = buildLastNameFirst(contact);
|
|
29
30
|
return name[0] || t('empty');
|
|
30
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Build header for a contact (first letter of indexes.byFamilyNameGivenNameEmailCozyUrl)
|
|
34
|
+
* @param {object} contact
|
|
35
|
+
* @param {function} t translation function
|
|
36
|
+
* @returns {string} header
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var makeHeaderForIndexedContacts = function makeHeaderForIndexedContacts(contact, t) {
|
|
41
|
+
var _contact$cozyMetadata;
|
|
42
|
+
|
|
43
|
+
if (contact.me) return t('me');
|
|
44
|
+
if ((_contact$cozyMetadata = contact.cozyMetadata) !== null && _contact$cozyMetadata !== void 0 && _contact$cozyMetadata.favorite) return t('favorite');
|
|
45
|
+
var index = get(contact, 'indexes.byFamilyNameGivenNameEmailCozyUrl', '');
|
|
46
|
+
var hasIndex = index !== null && index.length > 0;
|
|
47
|
+
|
|
48
|
+
if (hasIndex) {
|
|
49
|
+
var firstLetterWithoutAccent = index[0].normalize('NFD').replace(/(?:[\^`\xA8\xAF\xB4\xB7\xB8\u02B0-\u034E\u0350-\u0357\u035D-\u0362\u0374\u0375\u037A\u0384\u0385\u0483-\u0487\u0559\u0591-\u05A1\u05A3-\u05BD\u05BF\u05C1\u05C2\u05C4\u064B-\u0652\u0657\u0658\u06DF\u06E0\u06E5\u06E6\u06EA-\u06EC\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F5\u0818\u0819\u0898-\u089F\u08C9-\u08D2\u08E3-\u08FE\u093C\u094D\u0951-\u0954\u0971\u09BC\u09CD\u0A3C\u0A4D\u0ABC\u0ACD\u0AFD-\u0AFF\u0B3C\u0B4D\u0B55\u0BCD\u0C3C\u0C4D\u0CBC\u0CCD\u0D3B\u0D3C\u0D4D\u0DCA\u0E47-\u0E4C\u0E4E\u0EBA\u0EC8-\u0ECC\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F82-\u0F84\u0F86\u0F87\u0FC6\u1037\u1039\u103A\u1063\u1064\u1069-\u106D\u1087-\u108D\u108F\u109A\u109B\u135D-\u135F\u1714\u1715\u17C9-\u17D3\u17DD\u1939-\u193B\u1A75-\u1A7C\u1A7F\u1AB0-\u1ABE\u1AC1-\u1ACB\u1B34\u1B44\u1B6B-\u1B73\u1BAA\u1BAB\u1C36\u1C37\u1C78-\u1C7D\u1CD0-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1D2C-\u1D6A\u1DC4-\u1DCF\u1DF5-\u1DFF\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u2CEF-\u2CF1\u2E2F\u302A-\u302F\u3099-\u309C\u30FC\uA66F\uA67C\uA67D\uA67F\uA69C\uA69D\uA6F0\uA6F1\uA700-\uA721\uA788-\uA78A\uA7F8\uA7F9\uA8C4\uA8E0-\uA8F1\uA92B-\uA92E\uA953\uA9B3\uA9C0\uA9E5\uAA7B-\uAA7D\uAABF-\uAAC2\uAAF6\uAB5B-\uAB5F\uAB69-\uAB6B\uABEC\uABED\uFB1E\uFE20-\uFE2F\uFF3E\uFF40\uFF70\uFF9E\uFF9F\uFFE3]|\uD800\uDEE0|\uD801[\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDEE5\uDEE6]|\uD803[\uDD22-\uDD27\uDF46-\uDF50\uDF82-\uDF85]|\uD804[\uDC46\uDC70\uDCB9\uDCBA\uDD33\uDD34\uDD73\uDDC0\uDDCA-\uDDCC\uDE35\uDE36\uDEE9\uDEEA\uDF3C\uDF4D\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC42\uDC46\uDCC2\uDCC3\uDDBF\uDDC0\uDE3F\uDEB6\uDEB7\uDF2B]|\uD806[\uDC39\uDC3A\uDD3D\uDD3E\uDD43\uDDE0\uDE34\uDE47\uDE99]|\uD807[\uDC3F\uDD42\uDD44\uDD45\uDD97]|\uD81A[\uDEF0-\uDEF4\uDF30-\uDF36]|\uD81B[\uDF8F-\uDF9F\uDFF0\uDFF1]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD833[\uDF00-\uDF2D\uDF30-\uDF46]|\uD834[\uDD67-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD]|\uD838[\uDD30-\uDD36\uDEAE\uDEEC-\uDEEF]|\uD83A[\uDCD0-\uDCD6\uDD44-\uDD46\uDD48-\uDD4A])/g, '');
|
|
50
|
+
return firstLetterWithoutAccent;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return t('empty');
|
|
54
|
+
};
|
|
31
55
|
/**
|
|
32
56
|
* @typedef {Object.<string, Object>} CategorizedContactsResult
|
|
33
57
|
*/
|
|
34
58
|
|
|
35
59
|
/**
|
|
36
60
|
* Categorize contacts by first letter of last name
|
|
61
|
+
* Expl.: all contacts with A as first letter will be in A category
|
|
37
62
|
* @param {object[]} contacts io.cozy.contacts documents
|
|
38
63
|
* @param {function} t translation function
|
|
39
|
-
* @returns {CategorizedContactsResult}
|
|
64
|
+
* @returns {CategorizedContactsResult} Categorized contacts
|
|
40
65
|
*/
|
|
41
66
|
|
|
42
67
|
|
|
@@ -77,4 +102,29 @@ export var sortHeaders = function sortHeaders(categorized, t) {
|
|
|
77
102
|
}
|
|
78
103
|
|
|
79
104
|
return headersSorted.concat(notEmptyAndMyselfSorted);
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Counts how many contacts are categorized by first letter and store it in `groupCounts`
|
|
108
|
+
* Expl.: if there is 3 contacts in A and 2 in B, it will return [3,2]
|
|
109
|
+
* Also store first letters and store them in `groupLabels`
|
|
110
|
+
* @param {array} contacts - Array of io.cozy.contact documents
|
|
111
|
+
* @returns {object}
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
export var makeGroupLabelsAndCounts = function makeGroupLabelsAndCounts(contacts, t) {
|
|
115
|
+
return contacts.reduce(function (acc, contact) {
|
|
116
|
+
var header = makeHeaderForIndexedContacts(contact, t);
|
|
117
|
+
|
|
118
|
+
if (!acc.groupLabels.includes(header)) {
|
|
119
|
+
acc.groupLabels.push(header);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var idx = acc.groupLabels.indexOf(header);
|
|
123
|
+
var val = acc.groupCounts[idx] || 0;
|
|
124
|
+
acc.groupCounts[idx] = val + 1;
|
|
125
|
+
return acc;
|
|
126
|
+
}, {
|
|
127
|
+
groupLabels: [],
|
|
128
|
+
groupCounts: []
|
|
129
|
+
});
|
|
80
130
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
var en = {
|
|
2
2
|
empty: "EMPTY",
|
|
3
|
-
me: "
|
|
3
|
+
me: "me",
|
|
4
|
+
favorite: "favorites",
|
|
5
|
+
menu: "Menu"
|
|
4
6
|
};
|
|
5
7
|
var fr = {
|
|
6
8
|
empty: "VIDE",
|
|
7
|
-
me: "
|
|
9
|
+
me: "moi",
|
|
10
|
+
favorite: "favoris",
|
|
11
|
+
menu: "Menu"
|
|
8
12
|
};
|
|
9
13
|
import withOnlyLocales from "cozy-ui/transpiled/react/providers/I18n/withOnlyLocales";
|
|
10
14
|
export var locales = {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import isEqual from 'lodash/isEqual';
|
|
4
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
5
|
+
var SelectionContext = /*#__PURE__*/createContext();
|
|
6
|
+
export var useSelection = function useSelection() {
|
|
7
|
+
var context = useContext(SelectionContext);
|
|
8
|
+
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('useSelection must be used within a SelectionProvider');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return context;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* This provider allows you to manage item selection
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
var SelectionProvider = function SelectionProvider(_ref) {
|
|
20
|
+
var children = _ref.children;
|
|
21
|
+
|
|
22
|
+
var _useState = useState([]),
|
|
23
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
+
selectedItemsId = _useState2[0],
|
|
25
|
+
setSelectedItemsId = _useState2[1];
|
|
26
|
+
|
|
27
|
+
var isSelectedItem = function isSelectedItem(item) {
|
|
28
|
+
return selectedItemsId.some(function (selectedItemId) {
|
|
29
|
+
return selectedItemId === item._id;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var isSelectionEnabled = selectedItemsId.length > 0;
|
|
34
|
+
|
|
35
|
+
var addSelectedItem = function addSelectedItem(item) {
|
|
36
|
+
setSelectedItemsId(function (prev) {
|
|
37
|
+
return [].concat(_toConsumableArray(prev), [item._id]);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var removeSelectedItem = function removeSelectedItem(item) {
|
|
42
|
+
setSelectedItemsId(function (prev) {
|
|
43
|
+
return prev.filter(function (el) {
|
|
44
|
+
return el !== item._id;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var toggleSelectedItem = function toggleSelectedItem(item) {
|
|
50
|
+
if (isSelectedItem(item)) {
|
|
51
|
+
removeSelectedItem(item);
|
|
52
|
+
} else {
|
|
53
|
+
addSelectedItem(item);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var selectAll = function selectAll(items) {
|
|
58
|
+
var ids = items.map(function (item) {
|
|
59
|
+
return item._id;
|
|
60
|
+
});
|
|
61
|
+
setSelectedItemsId(ids);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
var unselectAll = function unselectAll() {
|
|
65
|
+
setSelectedItemsId([]);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
var isSelectedAllItems = function isSelectedAllItems(items) {
|
|
69
|
+
var a = selectedItemsId.sort();
|
|
70
|
+
var b = items.map(function (item) {
|
|
71
|
+
return item._id;
|
|
72
|
+
}).sort();
|
|
73
|
+
return isEqual(a, b);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var toggleSelectAllItems = function toggleSelectAllItems(items) {
|
|
77
|
+
if (isSelectedAllItems(items)) {
|
|
78
|
+
unselectAll();
|
|
79
|
+
} else {
|
|
80
|
+
selectAll(items);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return /*#__PURE__*/React.createElement(SelectionContext.Provider, {
|
|
85
|
+
value: {
|
|
86
|
+
selectedItemsId: selectedItemsId,
|
|
87
|
+
addSelectedItem: addSelectedItem,
|
|
88
|
+
removeSelectedItem: removeSelectedItem,
|
|
89
|
+
toggleSelectedItem: toggleSelectedItem,
|
|
90
|
+
selectAll: selectAll,
|
|
91
|
+
toggleSelectAllItems: toggleSelectAllItems,
|
|
92
|
+
isSelectedItem: isSelectedItem,
|
|
93
|
+
isSelectionEnabled: isSelectionEnabled,
|
|
94
|
+
isSelectedAllItems: isSelectedAllItems
|
|
95
|
+
}
|
|
96
|
+
}, children);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default /*#__PURE__*/React.memo(SelectionProvider);
|