cozy-ui 114.0.1 → 115.0.1
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/.bundlemonrc +1 -2
- package/CHANGELOG.md +21 -0
- package/package.json +2 -2
- package/react/BarContextProvider/index.spec.jsx +1 -1
- package/react/DateMonthPicker/index.jsx +3 -3
- package/react/FilePicker/FilePickerBodyItem.jsx +1 -1
- package/react/ListItem/ListItemFile/SecondaryText.jsx +1 -1
- package/react/providers/I18n/format.jsx +32 -9
- package/react/providers/I18n/format.spec.jsx +12 -0
- package/react/providers/I18n/index.spec.jsx +1 -1
- package/transpiled/react/DateMonthPicker/index.js +3 -3
- package/transpiled/react/FilePicker/FilePickerBodyItem.js +1 -1
- package/transpiled/react/ListItem/ListItemFile/SecondaryText.js +1 -1
- package/transpiled/react/providers/I18n/format.js +37 -8
package/.bundlemonrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [115.0.1](https://github.com/cozy/cozy-ui/compare/v115.0.0...v115.0.1) (2024-12-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Ensure use correct format locales ([5d078db](https://github.com/cozy/cozy-ui/commit/5d078db)), closes [/github.com/date-fns/date-fns/blob/main/CHANGELOG.md#200---2019-08-20](https://github.com//github.com/date-fns/date-fns/blob/main/CHANGELOG.md/issues/200---2019-08-20)
|
|
7
|
+
|
|
8
|
+
# [115.0.0](https://github.com/cozy/cozy-ui/compare/v114.0.1...v115.0.0) (2024-12-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Upgrade date-fns to 2.30.0 ([a89c524](https://github.com/cozy/cozy-ui/commit/a89c524))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* The date formatting function (`f` from `useI18n`) changes,
|
|
19
|
+
please refer to this doc.
|
|
20
|
+
https://date-fns.org/v2.30.0/docs/format
|
|
21
|
+
|
|
1
22
|
## [114.0.1](https://github.com/cozy/cozy-ui/compare/v114.0.0...v114.0.1) (2024-12-16)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "115.0.1",
|
|
4
4
|
"description": "Cozy apps UI SDK",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"chart.js": "3.7.1",
|
|
163
163
|
"classnames": "^2.2.5",
|
|
164
164
|
"cozy-interapp": "^0.5.4",
|
|
165
|
-
"date-fns": "
|
|
165
|
+
"date-fns": "2.30.0",
|
|
166
166
|
"filesize": "8.0.7",
|
|
167
167
|
"hammerjs": "^2.0.8",
|
|
168
168
|
"intersection-observer": "0.11.0",
|
|
@@ -26,7 +26,7 @@ const MonthButton = ({ monthNum, onClick, isSelected }) => {
|
|
|
26
26
|
)}
|
|
27
27
|
onClick={handleClick}
|
|
28
28
|
>
|
|
29
|
-
{f(d, '
|
|
29
|
+
{f(d, 'LLL')}
|
|
30
30
|
</button>
|
|
31
31
|
)
|
|
32
32
|
}
|
|
@@ -50,7 +50,7 @@ const DateMonthPicker = ({ initialValue, onSelect }) => {
|
|
|
50
50
|
|
|
51
51
|
const handleClickMonth = month => {
|
|
52
52
|
const d = new Date(year, month, 1)
|
|
53
|
-
onSelect(format(d, '
|
|
53
|
+
onSelect(format(d, 'yyyy-LL-dd'))
|
|
54
54
|
}
|
|
55
55
|
return (
|
|
56
56
|
<div>
|
|
@@ -93,7 +93,7 @@ const dateMonthProp = function (props, propName, componentName) {
|
|
|
93
93
|
'` supplied to' +
|
|
94
94
|
' `' +
|
|
95
95
|
componentName +
|
|
96
|
-
'`. Should be in the form
|
|
96
|
+
'`. Should be in the form yyyy-LL.'
|
|
97
97
|
)
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -51,7 +51,7 @@ const FilePickerBodyItem = ({
|
|
|
51
51
|
const Input = multiple ? Checkbox : Radio
|
|
52
52
|
|
|
53
53
|
const listItemSecondaryContent = isFile(item)
|
|
54
|
-
? `${f(item.updated_at, '
|
|
54
|
+
? `${f(item.updated_at, 'dd LLL yyyy')} - ${filesize(item.size, {
|
|
55
55
|
base: 10
|
|
56
56
|
})}`
|
|
57
57
|
: null
|
|
@@ -1,23 +1,43 @@
|
|
|
1
|
-
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'
|
|
2
1
|
import format from 'date-fns/format'
|
|
2
|
+
import formatDistanceToNow from 'date-fns/formatDistanceToNow'
|
|
3
3
|
|
|
4
4
|
import { DEFAULT_LANG } from '.'
|
|
5
5
|
|
|
6
6
|
const locales = {}
|
|
7
7
|
let lang = DEFAULT_LANG
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Ensure that the locale is in the correct format for date-fns (see 2.0.0 BC https://github.com/date-fns/date-fns/blob/main/CHANGELOG.md#200---2019-08-20)
|
|
11
|
+
* @param {string} lang
|
|
12
|
+
*/
|
|
13
|
+
const ensureLocaleFormat = lang => {
|
|
14
|
+
switch (lang) {
|
|
15
|
+
case 'en':
|
|
16
|
+
return 'en-US'
|
|
17
|
+
case 'zh_cn':
|
|
18
|
+
return 'zh-CN'
|
|
19
|
+
case 'zh_tw':
|
|
20
|
+
return 'zh-TW'
|
|
21
|
+
default:
|
|
22
|
+
return lang
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
9
26
|
const getWarningMessage = lang =>
|
|
10
27
|
`The "${lang}" locale isn't supported by date-fns. or has not been included in the build. Check if you have configured a ContextReplacementPlugin that is too restrictive.`
|
|
11
28
|
|
|
12
29
|
export const provideDateFnsLocale = (userLang, defaultLang = DEFAULT_LANG) => {
|
|
13
|
-
lang = userLang
|
|
30
|
+
lang = ensureLocaleFormat(userLang)
|
|
31
|
+
const ensureDefaultLang = ensureLocaleFormat(defaultLang)
|
|
14
32
|
try {
|
|
15
|
-
locales[
|
|
33
|
+
locales[
|
|
34
|
+
ensureDefaultLang
|
|
35
|
+
] = require(`date-fns/locale/${ensureDefaultLang}/index.js`)
|
|
16
36
|
} catch (err) {
|
|
17
|
-
console.warn(getWarningMessage(
|
|
37
|
+
console.warn(getWarningMessage(ensureDefaultLang))
|
|
18
38
|
}
|
|
19
39
|
|
|
20
|
-
if (lang && lang !==
|
|
40
|
+
if (lang && lang !== ensureDefaultLang) {
|
|
21
41
|
try {
|
|
22
42
|
locales[lang] = require(`date-fns/locale/${lang}/index.js`)
|
|
23
43
|
} catch (e) {
|
|
@@ -29,10 +49,13 @@ export const provideDateFnsLocale = (userLang, defaultLang = DEFAULT_LANG) => {
|
|
|
29
49
|
|
|
30
50
|
export const initFormat =
|
|
31
51
|
(userLang, defaultLang = DEFAULT_LANG) =>
|
|
32
|
-
(date, formatStr) => {
|
|
52
|
+
(date, formatStr, opts = {}) => {
|
|
33
53
|
const locale = provideDateFnsLocale(userLang, defaultLang)
|
|
34
|
-
|
|
54
|
+
const ensureDate = date && typeof date === 'string' ? new Date(date) : date
|
|
55
|
+
|
|
56
|
+
return format(ensureDate, formatStr, { locale, ...opts })
|
|
35
57
|
}
|
|
36
58
|
|
|
37
|
-
export const formatLocallyDistanceToNow = date =>
|
|
38
|
-
|
|
59
|
+
export const formatLocallyDistanceToNow = date => {
|
|
60
|
+
return formatDistanceToNow(date, { locale: locales[lang] })
|
|
61
|
+
}
|
|
@@ -10,6 +10,18 @@ describe('initFormat', () => {
|
|
|
10
10
|
it('should not throw if a date-fns locale can not be found', () => {
|
|
11
11
|
expect(() => initFormat('unknown-lang', 'unknown-default')).not.toThrow()
|
|
12
12
|
})
|
|
13
|
+
|
|
14
|
+
it('should use the correct locale', () => {
|
|
15
|
+
const f = initFormat('fr', 'en')
|
|
16
|
+
const date = f(0, 'yyyy-LLLL-dd')
|
|
17
|
+
expect(date).toBe('1970-janvier-01')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should fallback english if a date-fns locale can not be found', () => {
|
|
21
|
+
const f = initFormat('unknown-lang', 'unknown-default')
|
|
22
|
+
const date = f(0, 'yyyy-LLLL-dd')
|
|
23
|
+
expect(date).toBe('1970-January-01')
|
|
24
|
+
})
|
|
13
25
|
})
|
|
14
26
|
|
|
15
27
|
describe('formatLocallyDistanceToNow', () => {
|
|
@@ -36,7 +36,7 @@ var MonthButton = function MonthButton(_ref) {
|
|
|
36
36
|
return /*#__PURE__*/React.createElement("button", {
|
|
37
37
|
className: cx(styles.DateMonthPicker__MonthButton, isSelected ? styles['DateMonthPicker__MonthButton--selected'] : null),
|
|
38
38
|
onClick: handleClick
|
|
39
|
-
}, f(d, '
|
|
39
|
+
}, f(d, 'LLL'));
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
var useCounter = function useCounter(initialValue, min, max) {
|
|
@@ -75,7 +75,7 @@ var DateMonthPicker = function DateMonthPicker(_ref2) {
|
|
|
75
75
|
|
|
76
76
|
var handleClickMonth = function handleClickMonth(month) {
|
|
77
77
|
var d = new Date(year, month, 1);
|
|
78
|
-
onSelect(format(d, '
|
|
78
|
+
onSelect(format(d, 'yyyy-LL-dd'));
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
@@ -108,7 +108,7 @@ var DateMonthPicker = function DateMonthPicker(_ref2) {
|
|
|
108
108
|
|
|
109
109
|
var dateMonthProp = function dateMonthProp(props, propName, componentName) {
|
|
110
110
|
if (!/^[0-9]{4}-[0-9]{2}$/.test(props[propName])) {
|
|
111
|
-
return new Error('Invalid prop `' + propName + '` supplied to' + ' `' + componentName + '`. Should be in the form
|
|
111
|
+
return new Error('Invalid prop `' + propName + '` supplied to' + ' `' + componentName + '`. Should be in the form yyyy-LL.');
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
|
|
@@ -50,7 +50,7 @@ var FilePickerBodyItem = function FilePickerBodyItem(_ref) {
|
|
|
50
50
|
|
|
51
51
|
var hasChoice = isValidFile(item, itemTypesAccepted) || isValidFolder(item, itemTypesAccepted);
|
|
52
52
|
var Input = multiple ? Checkbox : Radio;
|
|
53
|
-
var listItemSecondaryContent = isFile(item) ? "".concat(f(item.updated_at, '
|
|
53
|
+
var listItemSecondaryContent = isFile(item) ? "".concat(f(item.updated_at, 'dd LLL yyyy'), " - ").concat(filesize(item.size, {
|
|
54
54
|
base: 10
|
|
55
55
|
})) : null;
|
|
56
56
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ListItem, {
|
|
@@ -14,7 +14,7 @@ var SecondaryText = function SecondaryText(_ref) {
|
|
|
14
14
|
f = _useI18n.f;
|
|
15
15
|
|
|
16
16
|
if (secondary) return secondary;
|
|
17
|
-
var date = file !== null && file !== void 0 && (_file$metadata = file.metadata) !== null && _file$metadata !== void 0 && _file$metadata.datetime ? f(file === null || file === void 0 ? void 0 : (_file$metadata2 = file.metadata) === null || _file$metadata2 === void 0 ? void 0 : _file$metadata2.datetime, '
|
|
17
|
+
var date = file !== null && file !== void 0 && (_file$metadata = file.metadata) !== null && _file$metadata !== void 0 && _file$metadata.datetime ? f(file === null || file === void 0 ? void 0 : (_file$metadata2 = file.metadata) === null || _file$metadata2 === void 0 ? void 0 : _file$metadata2.datetime, 'dd/LL/yyyy') : null;
|
|
18
18
|
return /*#__PURE__*/React.createElement(React.Fragment, null, date ? date : '', (isExpired(file) || isExpiringSoon(file)) && /*#__PURE__*/React.createElement(React.Fragment, null, date ? ' · ' : '', /*#__PURE__*/React.createElement(ExpirationAnnotation, {
|
|
19
19
|
file: file
|
|
20
20
|
})));
|
|
@@ -1,8 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
2
7
|
import format from 'date-fns/format';
|
|
8
|
+
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
|
|
3
9
|
import { DEFAULT_LANG } from "cozy-ui/transpiled/react/providers/I18n";
|
|
4
10
|
var locales = {};
|
|
5
11
|
var lang = DEFAULT_LANG;
|
|
12
|
+
/**
|
|
13
|
+
* Ensure that the locale is in the correct format for date-fns (see 2.0.0 BC https://github.com/date-fns/date-fns/blob/main/CHANGELOG.md#200---2019-08-20)
|
|
14
|
+
* @param {string} lang
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
var ensureLocaleFormat = function ensureLocaleFormat(lang) {
|
|
18
|
+
switch (lang) {
|
|
19
|
+
case 'en':
|
|
20
|
+
return 'en-US';
|
|
21
|
+
|
|
22
|
+
case 'zh_cn':
|
|
23
|
+
return 'zh-CN';
|
|
24
|
+
|
|
25
|
+
case 'zh_tw':
|
|
26
|
+
return 'zh-TW';
|
|
27
|
+
|
|
28
|
+
default:
|
|
29
|
+
return lang;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
6
32
|
|
|
7
33
|
var getWarningMessage = function getWarningMessage(lang) {
|
|
8
34
|
return "The \"".concat(lang, "\" locale isn't supported by date-fns. or has not been included in the build. Check if you have configured a ContextReplacementPlugin that is too restrictive.");
|
|
@@ -10,15 +36,16 @@ var getWarningMessage = function getWarningMessage(lang) {
|
|
|
10
36
|
|
|
11
37
|
export var provideDateFnsLocale = function provideDateFnsLocale(userLang) {
|
|
12
38
|
var defaultLang = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LANG;
|
|
13
|
-
lang = userLang;
|
|
39
|
+
lang = ensureLocaleFormat(userLang);
|
|
40
|
+
var ensureDefaultLang = ensureLocaleFormat(defaultLang);
|
|
14
41
|
|
|
15
42
|
try {
|
|
16
|
-
locales[
|
|
43
|
+
locales[ensureDefaultLang] = require("date-fns/locale/".concat(ensureDefaultLang, "/index.js"));
|
|
17
44
|
} catch (err) {
|
|
18
|
-
console.warn(getWarningMessage(
|
|
45
|
+
console.warn(getWarningMessage(ensureDefaultLang));
|
|
19
46
|
}
|
|
20
47
|
|
|
21
|
-
if (lang && lang !==
|
|
48
|
+
if (lang && lang !== ensureDefaultLang) {
|
|
22
49
|
try {
|
|
23
50
|
locales[lang] = require("date-fns/locale/".concat(lang, "/index.js"));
|
|
24
51
|
} catch (e) {
|
|
@@ -31,14 +58,16 @@ export var provideDateFnsLocale = function provideDateFnsLocale(userLang) {
|
|
|
31
58
|
export var initFormat = function initFormat(userLang) {
|
|
32
59
|
var defaultLang = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_LANG;
|
|
33
60
|
return function (date, formatStr) {
|
|
61
|
+
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
34
62
|
var locale = provideDateFnsLocale(userLang, defaultLang);
|
|
35
|
-
|
|
63
|
+
var ensureDate = date && typeof date === 'string' ? new Date(date) : date;
|
|
64
|
+
return format(ensureDate, formatStr, _objectSpread({
|
|
36
65
|
locale: locale
|
|
37
|
-
});
|
|
66
|
+
}, opts));
|
|
38
67
|
};
|
|
39
68
|
};
|
|
40
69
|
export var formatLocallyDistanceToNow = function formatLocallyDistanceToNow(date) {
|
|
41
|
-
return
|
|
70
|
+
return formatDistanceToNow(date, {
|
|
42
71
|
locale: locales[lang]
|
|
43
72
|
});
|
|
44
73
|
};
|