@react-aria/i18n 3.3.2 → 3.3.6
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/dist/main.js +234 -246
- package/dist/main.js.map +1 -1
- package/dist/module.js +230 -226
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/useDateFormatter.ts +27 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/i18n",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.6",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@internationalized/
|
|
22
|
-
"@internationalized/
|
|
23
|
-
"@
|
|
24
|
-
"@react-aria/
|
|
25
|
-
"@react-
|
|
21
|
+
"@internationalized/date": "3.0.0-alpha.3",
|
|
22
|
+
"@internationalized/message": "^3.0.5",
|
|
23
|
+
"@internationalized/number": "^3.0.5",
|
|
24
|
+
"@react-aria/ssr": "^3.1.2",
|
|
25
|
+
"@react-aria/utils": "^3.11.2",
|
|
26
|
+
"@react-types/shared": "^3.11.1"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -30,5 +31,5 @@
|
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "404d41859b7d6f56201d7fc01bd9f22ae3512937"
|
|
34
35
|
}
|
package/src/useDateFormatter.ts
CHANGED
|
@@ -10,33 +10,48 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import {DateFormatter} from '@internationalized/date';
|
|
13
14
|
import {useLocale} from './context';
|
|
15
|
+
import {useMemo, useRef} from 'react';
|
|
14
16
|
|
|
15
17
|
interface DateFormatterOptions extends Intl.DateTimeFormatOptions {
|
|
16
18
|
calendar?: string
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
let formatterCache = new Map<string, Intl.DateTimeFormat>();
|
|
20
|
-
|
|
21
21
|
/**
|
|
22
22
|
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
|
|
23
23
|
* and handles caching of the date formatter for performance.
|
|
24
24
|
* @param options - Formatting options.
|
|
25
25
|
*/
|
|
26
|
-
export function useDateFormatter(options?: DateFormatterOptions):
|
|
26
|
+
export function useDateFormatter(options?: DateFormatterOptions): DateFormatter {
|
|
27
|
+
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
|
|
28
|
+
let lastOptions = useRef(null);
|
|
29
|
+
if (options && lastOptions.current && isEqual(options, lastOptions.current)) {
|
|
30
|
+
options = lastOptions.current;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
lastOptions.current = options;
|
|
34
|
+
|
|
27
35
|
let {locale} = useLocale();
|
|
36
|
+
return useMemo(() => new DateFormatter(locale, options), [locale, options]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isEqual(a: DateFormatterOptions, b: DateFormatterOptions) {
|
|
40
|
+
if (a === b) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
28
43
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
let aKeys = Object.keys(a);
|
|
45
|
+
let bKeys = Object.keys(b);
|
|
46
|
+
if (aKeys.length !== bKeys.length) {
|
|
47
|
+
return false;
|
|
32
48
|
}
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
for (let key of aKeys) {
|
|
51
|
+
if (b[key] !== a[key]) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
37
54
|
}
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
formatterCache.set(cacheKey, formatter);
|
|
41
|
-
return formatter;
|
|
56
|
+
return true;
|
|
42
57
|
}
|