@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/dist/main.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var {
|
|
13
|
-
useIsSSR
|
|
14
|
-
} = require("@react-aria/ssr");
|
|
15
|
-
|
|
16
|
-
var _react2 = require("react");
|
|
17
|
-
|
|
18
|
-
var _react = $parcel$interopDefault(_react2);
|
|
1
|
+
var $dzMDy$react = require("react");
|
|
2
|
+
var $dzMDy$reactariassr = require("@react-aria/ssr");
|
|
3
|
+
var $dzMDy$internationalizedmessage = require("@internationalized/message");
|
|
4
|
+
var $dzMDy$internationalizeddate = require("@internationalized/date");
|
|
5
|
+
var $dzMDy$internationalizednumber = require("@internationalized/number");
|
|
6
|
+
|
|
7
|
+
function $parcel$exportWildcard(dest, source) {
|
|
8
|
+
Object.keys(source).forEach(function(key) {
|
|
9
|
+
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
13
|
+
Object.defineProperty(dest, key, {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return source[key];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
27
20
|
|
|
21
|
+
return dest;
|
|
22
|
+
}
|
|
28
23
|
function $parcel$interopDefault(a) {
|
|
29
24
|
return a && a.__esModule ? a.default : a;
|
|
30
25
|
}
|
|
26
|
+
function $parcel$export(e, n, v, s) {
|
|
27
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
28
|
+
}
|
|
29
|
+
var $ce1de4dd7c6cf87d$exports = {};
|
|
31
30
|
|
|
31
|
+
$parcel$export($ce1de4dd7c6cf87d$exports, "I18nProvider", () => $ce1de4dd7c6cf87d$export$a54013f0d02a8f82);
|
|
32
|
+
$parcel$export($ce1de4dd7c6cf87d$exports, "useLocale", () => $ce1de4dd7c6cf87d$export$43bb16f9c6d9e3f7);
|
|
32
33
|
/*
|
|
33
34
|
* Copyright 2020 Adobe. All rights reserved.
|
|
34
35
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -39,269 +40,256 @@ function $parcel$interopDefault(a) {
|
|
|
39
40
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
40
41
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
41
42
|
* governing permissions and limitations under the License.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
*/ // https://en.wikipedia.org/wiki/Right-to-left
|
|
44
|
+
const $3dc2d9f4ca99b6b1$var$RTL_SCRIPTS = new Set([
|
|
45
|
+
'Arab',
|
|
46
|
+
'Syrc',
|
|
47
|
+
'Samr',
|
|
48
|
+
'Mand',
|
|
49
|
+
'Thaa',
|
|
50
|
+
'Mend',
|
|
51
|
+
'Nkoo',
|
|
52
|
+
'Adlm',
|
|
53
|
+
'Rohg',
|
|
54
|
+
'Hebr'
|
|
55
|
+
]);
|
|
56
|
+
const $3dc2d9f4ca99b6b1$var$RTL_LANGS = new Set([
|
|
57
|
+
'ae',
|
|
58
|
+
'ar',
|
|
59
|
+
'arc',
|
|
60
|
+
'bcc',
|
|
61
|
+
'bqi',
|
|
62
|
+
'ckb',
|
|
63
|
+
'dv',
|
|
64
|
+
'fa',
|
|
65
|
+
'glk',
|
|
66
|
+
'he',
|
|
67
|
+
'ku',
|
|
68
|
+
'mzn',
|
|
69
|
+
'nqo',
|
|
70
|
+
'pnb',
|
|
71
|
+
'ps',
|
|
72
|
+
'sd',
|
|
73
|
+
'ug',
|
|
74
|
+
'ur',
|
|
75
|
+
'yi'
|
|
76
|
+
]);
|
|
77
|
+
function $3dc2d9f4ca99b6b1$export$702d680b21cbd764(locale) {
|
|
78
|
+
// If the Intl.Locale API is available, use it to get the script for the locale.
|
|
79
|
+
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
|
|
55
80
|
// @ts-ignore
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
if (Intl.Locale) {
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
let script = new Intl.Locale(locale).maximize().script;
|
|
84
|
+
return $3dc2d9f4ca99b6b1$var$RTL_SCRIPTS.has(script);
|
|
85
|
+
}
|
|
86
|
+
// If not, just guess by the language (first part of the locale)
|
|
87
|
+
let lang = locale.split('-')[0];
|
|
88
|
+
return $3dc2d9f4ca99b6b1$var$RTL_LANGS.has(lang);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
59
92
|
|
|
60
93
|
|
|
61
|
-
let lang = locale.split('-')[0];
|
|
62
|
-
return $dbb62b32f79d03a795a46f9fbec514c$var$RTL_LANGS.has(lang);
|
|
63
|
-
}
|
|
64
94
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
95
|
+
function $661cab8d074a4634$export$f09106e7c6677ec5() {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
let locale = typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
|
|
98
|
+
return {
|
|
99
|
+
locale: locale,
|
|
100
|
+
direction: $3dc2d9f4ca99b6b1$export$702d680b21cbd764(locale) ? 'rtl' : 'ltr'
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
let $661cab8d074a4634$var$currentLocale = $661cab8d074a4634$export$f09106e7c6677ec5();
|
|
104
|
+
let $661cab8d074a4634$var$listeners = new Set();
|
|
105
|
+
function $661cab8d074a4634$var$updateLocale() {
|
|
106
|
+
$661cab8d074a4634$var$currentLocale = $661cab8d074a4634$export$f09106e7c6677ec5();
|
|
107
|
+
for (let listener of $661cab8d074a4634$var$listeners)listener($661cab8d074a4634$var$currentLocale);
|
|
108
|
+
}
|
|
109
|
+
function $661cab8d074a4634$export$188ec29ebc2bdc3a() {
|
|
110
|
+
let isSSR = $dzMDy$reactariassr.useIsSSR();
|
|
111
|
+
let [defaultLocale, setDefaultLocale] = $dzMDy$react.useState($661cab8d074a4634$var$currentLocale);
|
|
112
|
+
$dzMDy$react.useEffect(()=>{
|
|
113
|
+
if ($661cab8d074a4634$var$listeners.size === 0) window.addEventListener('languagechange', $661cab8d074a4634$var$updateLocale);
|
|
114
|
+
$661cab8d074a4634$var$listeners.add(setDefaultLocale);
|
|
115
|
+
return ()=>{
|
|
116
|
+
$661cab8d074a4634$var$listeners.delete(setDefaultLocale);
|
|
117
|
+
if ($661cab8d074a4634$var$listeners.size === 0) window.removeEventListener('languagechange', $661cab8d074a4634$var$updateLocale);
|
|
118
|
+
};
|
|
119
|
+
}, []);
|
|
120
|
+
// We cannot determine the browser's language on the server, so default to
|
|
121
|
+
// en-US. This will be updated after hydration on the client to the correct value.
|
|
122
|
+
if (isSSR) return {
|
|
123
|
+
locale: 'en-US',
|
|
124
|
+
direction: 'ltr'
|
|
125
|
+
};
|
|
126
|
+
return defaultLocale;
|
|
75
127
|
}
|
|
76
128
|
|
|
77
|
-
let $c53c7d716f930bd5da78e9efb99e3e$var$currentLocale = $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale();
|
|
78
|
-
let $c53c7d716f930bd5da78e9efb99e3e$var$listeners = new Set();
|
|
79
129
|
|
|
80
|
-
function $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale() {
|
|
81
|
-
$c53c7d716f930bd5da78e9efb99e3e$var$currentLocale = $c53c7d716f930bd5da78e9efb99e3e$export$getDefaultLocale();
|
|
82
130
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
131
|
+
const $ce1de4dd7c6cf87d$var$I18nContext = /*#__PURE__*/ ($parcel$interopDefault($dzMDy$react)).createContext(null);
|
|
132
|
+
function $ce1de4dd7c6cf87d$export$a54013f0d02a8f82(props) {
|
|
133
|
+
let { locale: locale , children: children } = props;
|
|
134
|
+
let defaultLocale = $661cab8d074a4634$export$188ec29ebc2bdc3a();
|
|
135
|
+
let value = locale ? {
|
|
136
|
+
locale: locale,
|
|
137
|
+
direction: $3dc2d9f4ca99b6b1$export$702d680b21cbd764(locale) ? 'rtl' : 'ltr'
|
|
138
|
+
} : defaultLocale;
|
|
139
|
+
return(/*#__PURE__*/ ($parcel$interopDefault($dzMDy$react)).createElement($ce1de4dd7c6cf87d$var$I18nContext.Provider, {
|
|
140
|
+
value: value
|
|
141
|
+
}, children));
|
|
142
|
+
}
|
|
143
|
+
function $ce1de4dd7c6cf87d$export$43bb16f9c6d9e3f7() {
|
|
144
|
+
let defaultLocale = $661cab8d074a4634$export$188ec29ebc2bdc3a();
|
|
145
|
+
let context = $dzMDy$react.useContext($ce1de4dd7c6cf87d$var$I18nContext);
|
|
146
|
+
return context || defaultLocale;
|
|
86
147
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Returns the current browser/system language, and updates when it changes.
|
|
89
|
-
*/
|
|
90
148
|
|
|
91
149
|
|
|
92
|
-
|
|
93
|
-
let isSSR = useIsSSR();
|
|
94
|
-
let [defaultLocale, setDefaultLocale] = useState($c53c7d716f930bd5da78e9efb99e3e$var$currentLocale);
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if ($c53c7d716f930bd5da78e9efb99e3e$var$listeners.size === 0) {
|
|
97
|
-
window.addEventListener('languagechange', $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale);
|
|
98
|
-
}
|
|
150
|
+
var $cba3e55d343674b4$exports = {};
|
|
99
151
|
|
|
100
|
-
|
|
101
|
-
return () => {
|
|
102
|
-
$c53c7d716f930bd5da78e9efb99e3e$var$listeners.delete(setDefaultLocale);
|
|
152
|
+
$parcel$export($cba3e55d343674b4$exports, "useMessageFormatter", () => $cba3e55d343674b4$export$ec23bf898b1eed85);
|
|
103
153
|
|
|
104
|
-
if ($c53c7d716f930bd5da78e9efb99e3e$var$listeners.size === 0) {
|
|
105
|
-
window.removeEventListener('languagechange', $c53c7d716f930bd5da78e9efb99e3e$var$updateLocale);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}, []); // We cannot determine the browser's language on the server, so default to
|
|
109
|
-
// en-US. This will be updated after hydration on the client to the correct value.
|
|
110
154
|
|
|
111
|
-
if (isSSR) {
|
|
112
|
-
return {
|
|
113
|
-
locale: 'en-US',
|
|
114
|
-
direction: 'ltr'
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
155
|
|
|
118
|
-
|
|
156
|
+
const $cba3e55d343674b4$var$cache = new WeakMap();
|
|
157
|
+
function $cba3e55d343674b4$var$getCachedDictionary(strings) {
|
|
158
|
+
let dictionary = $cba3e55d343674b4$var$cache.get(strings);
|
|
159
|
+
if (!dictionary) {
|
|
160
|
+
dictionary = new $dzMDy$internationalizedmessage.MessageDictionary(strings);
|
|
161
|
+
$cba3e55d343674b4$var$cache.set(strings, dictionary);
|
|
162
|
+
}
|
|
163
|
+
return dictionary;
|
|
119
164
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, children);
|
|
165
|
+
function $cba3e55d343674b4$export$ec23bf898b1eed85(strings) {
|
|
166
|
+
let { locale: locale } = $ce1de4dd7c6cf87d$export$43bb16f9c6d9e3f7();
|
|
167
|
+
let dictionary = $dzMDy$react.useMemo(()=>$cba3e55d343674b4$var$getCachedDictionary(strings)
|
|
168
|
+
, [
|
|
169
|
+
strings
|
|
170
|
+
]);
|
|
171
|
+
let formatter = $dzMDy$react.useMemo(()=>new $dzMDy$internationalizedmessage.MessageFormatter(locale, dictionary)
|
|
172
|
+
, [
|
|
173
|
+
locale,
|
|
174
|
+
dictionary
|
|
175
|
+
]);
|
|
176
|
+
return $dzMDy$react.useCallback((key, variables)=>formatter.format(key, variables)
|
|
177
|
+
, [
|
|
178
|
+
formatter
|
|
179
|
+
]);
|
|
136
180
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Returns the current locale and layout direction.
|
|
139
|
-
*/
|
|
140
181
|
|
|
141
182
|
|
|
142
|
-
exports
|
|
183
|
+
var $38b92307964565f8$exports = {};
|
|
143
184
|
|
|
144
|
-
|
|
145
|
-
let defaultLocale = $c53c7d716f930bd5da78e9efb99e3e$export$useDefaultLocale();
|
|
146
|
-
let context = useContext($aa95c2b730b505b265f124d9aec67193$var$I18nContext);
|
|
147
|
-
return context || defaultLocale;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
exports.useLocale = useLocale;
|
|
151
|
-
const $a5aefbc9b72193c190dce301e0eb39$var$cache = new WeakMap();
|
|
185
|
+
$parcel$export($38b92307964565f8$exports, "useDateFormatter", () => $38b92307964565f8$export$85fd5fdf27bacc79);
|
|
152
186
|
|
|
153
|
-
function $a5aefbc9b72193c190dce301e0eb39$var$getCachedDictionary(strings) {
|
|
154
|
-
let dictionary = $a5aefbc9b72193c190dce301e0eb39$var$cache.get(strings);
|
|
155
187
|
|
|
156
|
-
if (!dictionary) {
|
|
157
|
-
dictionary = new MessageDictionary(strings);
|
|
158
|
-
$a5aefbc9b72193c190dce301e0eb39$var$cache.set(strings, dictionary);
|
|
159
|
-
}
|
|
160
188
|
|
|
161
|
-
|
|
189
|
+
function $38b92307964565f8$export$85fd5fdf27bacc79(options) {
|
|
190
|
+
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
|
|
191
|
+
let lastOptions = $dzMDy$react.useRef(null);
|
|
192
|
+
if (options && lastOptions.current && $38b92307964565f8$var$isEqual(options, lastOptions.current)) options = lastOptions.current;
|
|
193
|
+
lastOptions.current = options;
|
|
194
|
+
let { locale: locale } = $ce1de4dd7c6cf87d$export$43bb16f9c6d9e3f7();
|
|
195
|
+
return $dzMDy$react.useMemo(()=>new $dzMDy$internationalizeddate.DateFormatter(locale, options)
|
|
196
|
+
, [
|
|
197
|
+
locale,
|
|
198
|
+
options
|
|
199
|
+
]);
|
|
162
200
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
locale
|
|
173
|
-
} = useLocale();
|
|
174
|
-
let dictionary = useMemo(() => $a5aefbc9b72193c190dce301e0eb39$var$getCachedDictionary(strings), [strings]);
|
|
175
|
-
let formatter = useMemo(() => new MessageFormatter(locale, dictionary), [locale, dictionary]);
|
|
176
|
-
return useCallback((key, variables) => formatter.format(key, variables), [formatter]);
|
|
201
|
+
function $38b92307964565f8$var$isEqual(a, b) {
|
|
202
|
+
if (a === b) return true;
|
|
203
|
+
let aKeys = Object.keys(a);
|
|
204
|
+
let bKeys = Object.keys(b);
|
|
205
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
206
|
+
for (let key of aKeys){
|
|
207
|
+
if (b[key] !== a[key]) return false;
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
177
210
|
}
|
|
178
211
|
|
|
179
|
-
exports.useMessageFormatter = useMessageFormatter;
|
|
180
|
-
let $bdeee39f835a1e28966186127db96579$var$formatterCache = new Map();
|
|
181
|
-
/**
|
|
182
|
-
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
|
|
183
|
-
* and handles caching of the date formatter for performance.
|
|
184
|
-
* @param options - Formatting options.
|
|
185
|
-
*/
|
|
186
212
|
|
|
187
|
-
|
|
188
|
-
let {
|
|
189
|
-
locale
|
|
190
|
-
} = useLocale(); // Polyfill the `calendar` option - not supported in Safari.
|
|
213
|
+
var $28b5a70dd62e3e88$exports = {};
|
|
191
214
|
|
|
192
|
-
|
|
193
|
-
locale += '-u-ca-' + options.calendar;
|
|
194
|
-
}
|
|
215
|
+
$parcel$export($28b5a70dd62e3e88$exports, "useNumberFormatter", () => $28b5a70dd62e3e88$export$b7a616150fdb9f44);
|
|
195
216
|
|
|
196
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
|
|
197
217
|
|
|
198
|
-
if ($bdeee39f835a1e28966186127db96579$var$formatterCache.has(cacheKey)) {
|
|
199
|
-
return $bdeee39f835a1e28966186127db96579$var$formatterCache.get(cacheKey);
|
|
200
|
-
}
|
|
201
218
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
219
|
+
function $28b5a70dd62e3e88$export$b7a616150fdb9f44(options = {
|
|
220
|
+
}) {
|
|
221
|
+
let { locale: locale } = $ce1de4dd7c6cf87d$export$43bb16f9c6d9e3f7();
|
|
222
|
+
return $dzMDy$react.useMemo(()=>new $dzMDy$internationalizednumber.NumberFormatter(locale, options)
|
|
223
|
+
, [
|
|
224
|
+
locale,
|
|
225
|
+
options
|
|
226
|
+
]);
|
|
205
227
|
}
|
|
206
228
|
|
|
207
|
-
exports.useDateFormatter = useDateFormatter;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
|
|
211
|
-
* and handles caching of the number formatter for performance.
|
|
212
|
-
* @param options - Formatting options.
|
|
213
|
-
*/
|
|
214
|
-
function useNumberFormatter(options) {
|
|
215
|
-
if (options === void 0) {
|
|
216
|
-
options = {};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
let {
|
|
220
|
-
locale
|
|
221
|
-
} = useLocale();
|
|
222
|
-
return useMemo(() => new NumberFormatter(locale, options), [locale, options]);
|
|
223
|
-
}
|
|
224
229
|
|
|
225
|
-
exports
|
|
226
|
-
let $f2d7166fa8b4811bca7b68ebd673b$var$cache = new Map();
|
|
227
|
-
/**
|
|
228
|
-
* Provides localized string collation for the current locale. Automatically updates when the locale changes,
|
|
229
|
-
* and handles caching of the collator for performance.
|
|
230
|
-
* @param options - Collator options.
|
|
231
|
-
*/
|
|
232
|
-
|
|
233
|
-
function useCollator(options) {
|
|
234
|
-
let {
|
|
235
|
-
locale
|
|
236
|
-
} = useLocale();
|
|
237
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
|
|
238
|
-
|
|
239
|
-
if ($f2d7166fa8b4811bca7b68ebd673b$var$cache.has(cacheKey)) {
|
|
240
|
-
return $f2d7166fa8b4811bca7b68ebd673b$var$cache.get(cacheKey);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
let formatter = new Intl.Collator(locale, options);
|
|
244
|
-
$f2d7166fa8b4811bca7b68ebd673b$var$cache.set(cacheKey, formatter);
|
|
245
|
-
return formatter;
|
|
246
|
-
}
|
|
230
|
+
var $9beaf39d05e8ead8$exports = {};
|
|
247
231
|
|
|
248
|
-
exports
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Provides localized string search functionality that is useful for filtering or matching items
|
|
252
|
-
* in a list. Options can be provided to adjust the sensitivity to case, diacritics, and other parameters.
|
|
253
|
-
*/
|
|
254
|
-
function useFilter(options) {
|
|
255
|
-
let collator = useCollator(_babelRuntimeHelpersExtends({
|
|
256
|
-
usage: 'search'
|
|
257
|
-
}, options)); // TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
258
|
-
|
|
259
|
-
return {
|
|
260
|
-
startsWith(string, substring) {
|
|
261
|
-
if (substring.length === 0) {
|
|
262
|
-
return true;
|
|
263
|
-
} // Normalize both strings so we can slice safely
|
|
264
|
-
// TODO: take into account the ignorePunctuation option as well...
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
string = string.normalize('NFC');
|
|
268
|
-
substring = substring.normalize('NFC');
|
|
269
|
-
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
270
|
-
},
|
|
271
|
-
|
|
272
|
-
endsWith(string, substring) {
|
|
273
|
-
if (substring.length === 0) {
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
232
|
+
$parcel$export($9beaf39d05e8ead8$exports, "useCollator", () => $9beaf39d05e8ead8$export$a16aca283550c30d);
|
|
276
233
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
234
|
+
let $9beaf39d05e8ead8$var$cache = new Map();
|
|
235
|
+
function $9beaf39d05e8ead8$export$a16aca283550c30d(options) {
|
|
236
|
+
let { locale: locale } = $ce1de4dd7c6cf87d$export$43bb16f9c6d9e3f7();
|
|
237
|
+
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1
|
|
238
|
+
).join() : '');
|
|
239
|
+
if ($9beaf39d05e8ead8$var$cache.has(cacheKey)) return $9beaf39d05e8ead8$var$cache.get(cacheKey);
|
|
240
|
+
let formatter = new Intl.Collator(locale, options);
|
|
241
|
+
$9beaf39d05e8ead8$var$cache.set(cacheKey, formatter);
|
|
242
|
+
return formatter;
|
|
243
|
+
}
|
|
281
244
|
|
|
282
|
-
contains(string, substring) {
|
|
283
|
-
if (substring.length === 0) {
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
245
|
|
|
287
|
-
|
|
288
|
-
substring = substring.normalize('NFC');
|
|
289
|
-
let scan = 0;
|
|
290
|
-
let sliceLen = substring.length;
|
|
246
|
+
var $32747f53e013bdfa$exports = {};
|
|
291
247
|
|
|
292
|
-
|
|
293
|
-
let slice = string.slice(scan, scan + sliceLen);
|
|
248
|
+
$parcel$export($32747f53e013bdfa$exports, "useFilter", () => $32747f53e013bdfa$export$3274cf84b703fff);
|
|
294
249
|
|
|
295
|
-
|
|
296
|
-
|
|
250
|
+
function $32747f53e013bdfa$export$3274cf84b703fff(options) {
|
|
251
|
+
let collator = $9beaf39d05e8ead8$export$a16aca283550c30d({
|
|
252
|
+
usage: 'search',
|
|
253
|
+
...options
|
|
254
|
+
});
|
|
255
|
+
// TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
256
|
+
return {
|
|
257
|
+
startsWith (string, substring) {
|
|
258
|
+
if (substring.length === 0) return true;
|
|
259
|
+
// Normalize both strings so we can slice safely
|
|
260
|
+
// TODO: take into account the ignorePunctuation option as well...
|
|
261
|
+
string = string.normalize('NFC');
|
|
262
|
+
substring = substring.normalize('NFC');
|
|
263
|
+
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
264
|
+
},
|
|
265
|
+
endsWith (string, substring) {
|
|
266
|
+
if (substring.length === 0) return true;
|
|
267
|
+
string = string.normalize('NFC');
|
|
268
|
+
substring = substring.normalize('NFC');
|
|
269
|
+
return collator.compare(string.slice(-substring.length), substring) === 0;
|
|
270
|
+
},
|
|
271
|
+
contains (string, substring) {
|
|
272
|
+
if (substring.length === 0) return true;
|
|
273
|
+
string = string.normalize('NFC');
|
|
274
|
+
substring = substring.normalize('NFC');
|
|
275
|
+
let scan = 0;
|
|
276
|
+
let sliceLen = substring.length;
|
|
277
|
+
for(; scan + sliceLen <= string.length; scan++){
|
|
278
|
+
let slice = string.slice(scan, scan + sliceLen);
|
|
279
|
+
if (collator.compare(substring, slice) === 0) return true;
|
|
280
|
+
}
|
|
281
|
+
return false;
|
|
297
282
|
}
|
|
298
|
-
|
|
283
|
+
};
|
|
284
|
+
}
|
|
299
285
|
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
286
|
|
|
303
|
-
|
|
304
|
-
|
|
287
|
+
$parcel$exportWildcard(module.exports, $ce1de4dd7c6cf87d$exports);
|
|
288
|
+
$parcel$exportWildcard(module.exports, $cba3e55d343674b4$exports);
|
|
289
|
+
$parcel$exportWildcard(module.exports, $38b92307964565f8$exports);
|
|
290
|
+
$parcel$exportWildcard(module.exports, $28b5a70dd62e3e88$exports);
|
|
291
|
+
$parcel$exportWildcard(module.exports, $9beaf39d05e8ead8$exports);
|
|
292
|
+
$parcel$exportWildcard(module.exports, $32747f53e013bdfa$exports);
|
|
293
|
+
|
|
305
294
|
|
|
306
|
-
exports.useFilter = useFilter;
|
|
307
295
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACFD;;;;;;;;;;;AAYA;AACA,MAAMG,gDAAW,GAAG,IAAIC,GAAJ,CAAQ,CAAC,MAAD,EAAS,MAAT,EAAiB,MAAjB,EAAyB,MAAzB,EAAiC,MAAjC,EAAyC,MAAzC,EAAiD,MAAjD,EAAyD,MAAzD,EAAiE,MAAjE,EAAyE,MAAzE,CAAR,CAApB;AACA,MAAMC,8CAAS,GAAG,IAAID,GAAJ,CAAQ,CAAC,IAAD,EAAO,IAAP,EAAa,KAAb,EAAoB,KAApB,EAA2B,KAA3B,EAAkC,KAAlC,EAAyC,IAAzC,EAA+C,IAA/C,EAAqD,KAArD,EAA4D,IAA5D,EAAkE,IAAlE,EAAwE,KAAxE,EAA+E,KAA/E,EAAsF,KAAtF,EAA6F,IAA7F,EAAmG,IAAnG,EAAyG,IAAzG,EAA+G,IAA/G,EAAqH,IAArH,CAAR,CAAlB;AAEA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P,MAAD,EAASC,SAAT,EAAoB;AAC1B,UAAIA,SAAS,CAACC,MAAV,KAAqB,CAAzB,EAA4B;AAC1B,eAAO,IAAP;AACD;;AAEDF,MAAAA,MAAM,GAAGA,MAAM,CAACG,SAAP,CAAiB,KAAjB,CAAT;AACAF,MAAAA,SAAS,GAAGA,SAAS,CAACE,SAAV,CAAoB,KAApB,CAAZ;AAEA,UAAIK,IAAI,GAAG,CAAX;AACA,UAAIC,QAAQ,GAAGR,SAAS,CAACC,MAAzB;;AACA,aAAOM,IAAI,GAAGC,QAAP,IAAmBT,MAAM,CAACE,MAAjC,EAAyCM,IAAI,EAA7C,EAAiD;AAC/C,YAAIH,KAAK,GAAGL,MAAM,CAACK,KAAP,CAAaG,IAAb,EAAmBA,IAAI,GAAGC,QAA1B,CAAZ;;AACA,YAAIZ,QAAQ,CAACO,OAAT,CAAiBH,SAAjB,EAA4BI,KAA5B,MAAuC,CAA3C,EAA8C;AAC5C,iBAAO,IAAP;AACD;AACF;;AAED,aAAO,KAAP;AACD;;AAvCI,GAAP;AAyCD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-aria/i18n/src/utils.ts","./packages/@react-aria/i18n/src/useDefaultLocale.ts","./packages/@react-aria/i18n/src/context.tsx","./packages/@react-aria/i18n/src/useMessageFormatter.ts","./packages/@react-aria/i18n/src/useDateFormatter.ts","./packages/@react-aria/i18n/src/useNumberFormatter.ts","./packages/@react-aria/i18n/src/useCollator.ts","./packages/@react-aria/i18n/src/useFilter.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// https://en.wikipedia.org/wiki/Right-to-left\nconst RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);\nconst RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);\n\n/**\n * Determines if a locale is read right to left using [Intl.Locale]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale}.\n */\nexport function isRTL(locale: string) {\n // If the Intl.Locale API is available, use it to get the script for the locale.\n // This is more accurate than guessing by language, since languages can be written in multiple scripts.\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n let script = new Intl.Locale(locale).maximize().script;\n return RTL_SCRIPTS.has(script);\n }\n\n // If not, just guess by the language (first part of the locale)\n let lang = locale.split('-')[0];\n return RTL_LANGS.has(lang);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Direction} from '@react-types/shared';\nimport {isRTL} from './utils';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport interface Locale {\n /** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */\n locale: string,\n /** The writing direction for the locale. */\n direction: Direction\n}\n\n/**\n * Gets the locale setting of the browser.\n */\nexport function getDefaultLocale(): Locale {\n // @ts-ignore\n let locale = (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) || 'en-US';\n return {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr'\n };\n}\n\nlet currentLocale = getDefaultLocale();\nlet listeners = new Set<(locale: Locale) => void>();\n\nfunction updateLocale() {\n currentLocale = getDefaultLocale();\n for (let listener of listeners) {\n listener(currentLocale);\n }\n}\n\n/**\n * Returns the current browser/system language, and updates when it changes.\n */\nexport function useDefaultLocale(): Locale {\n let isSSR = useIsSSR();\n let [defaultLocale, setDefaultLocale] = useState(currentLocale);\n\n useEffect(() => {\n if (listeners.size === 0) {\n window.addEventListener('languagechange', updateLocale);\n }\n\n listeners.add(setDefaultLocale);\n\n return () => {\n listeners.delete(setDefaultLocale);\n if (listeners.size === 0) {\n window.removeEventListener('languagechange', updateLocale);\n }\n };\n }, []);\n\n // We cannot determine the browser's language on the server, so default to\n // en-US. This will be updated after hydration on the client to the correct value.\n if (isSSR) {\n return {\n locale: 'en-US',\n direction: 'ltr'\n };\n }\n\n return defaultLocale;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {isRTL} from './utils';\nimport {Locale, useDefaultLocale} from './useDefaultLocale';\nimport React, {ReactNode, useContext} from 'react';\n\ninterface ProviderProps {\n /** Contents that should have the locale applied. */\n children: ReactNode,\n /** The locale to apply to the children. */\n locale?: string\n}\n\nconst I18nContext = React.createContext<Locale>(null);\n\n/**\n * Provides the locale for the application to all child components.\n */\nexport function I18nProvider(props: ProviderProps) {\n let {locale, children} = props;\n let defaultLocale = useDefaultLocale();\n\n let value: Locale = locale ? {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr'\n } : defaultLocale;\n\n return (\n <I18nContext.Provider value={value}>\n {children}\n </I18nContext.Provider>\n );\n}\n\n/**\n * Returns the current locale and layout direction.\n */\nexport function useLocale(): Locale {\n let defaultLocale = useDefaultLocale();\n let context = useContext(I18nContext);\n return context || defaultLocale;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {LocalizedStrings, MessageDictionary, MessageFormatter} from '@internationalized/message';\nimport {useCallback, useMemo} from 'react';\nimport {useLocale} from './context';\n\ntype FormatMessage = (key: string, variables?: {[key: string]: any}) => string;\n\nconst cache = new WeakMap();\nfunction getCachedDictionary(strings: LocalizedStrings) {\n let dictionary = cache.get(strings);\n if (!dictionary) {\n dictionary = new MessageDictionary(strings);\n cache.set(strings, dictionary);\n }\n\n return dictionary;\n}\n\n/**\n * Handles formatting ICU Message strings to create localized strings for the current locale.\n * Automatically updates when the locale changes, and handles caching of messages for performance.\n * @param strings - A mapping of languages to strings by key.\n */\nexport function useMessageFormatter(strings: LocalizedStrings): FormatMessage {\n let {locale} = useLocale();\n let dictionary = useMemo(() => getCachedDictionary(strings), [strings]);\n let formatter = useMemo(() => new MessageFormatter(locale, dictionary), [locale, dictionary]);\n return useCallback((key, variables) => formatter.format(key, variables), [formatter]);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useLocale} from './context';\n\ninterface DateFormatterOptions extends Intl.DateTimeFormatOptions {\n calendar?: string\n}\n\nlet formatterCache = new Map<string, Intl.DateTimeFormat>();\n\n/**\n * Provides localized date formatting for the current locale. Automatically updates when the locale changes,\n * and handles caching of the date formatter for performance.\n * @param options - Formatting options.\n */\nexport function useDateFormatter(options?: DateFormatterOptions): Intl.DateTimeFormat {\n let {locale} = useLocale();\n\n // Polyfill the `calendar` option - not supported in Safari.\n if (options?.calendar && !locale.includes('-u-ca-')) {\n locale += '-u-ca-' + options.calendar;\n }\n\n let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');\n if (formatterCache.has(cacheKey)) {\n return formatterCache.get(cacheKey);\n }\n\n let formatter = new Intl.DateTimeFormat(locale, options);\n formatterCache.set(cacheKey, formatter);\n return formatter;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {NumberFormatOptions, NumberFormatter} from '@internationalized/number';\nimport {useLocale} from './context';\nimport {useMemo} from 'react';\n\n/**\n * Provides localized number formatting for the current locale. Automatically updates when the locale changes,\n * and handles caching of the number formatter for performance.\n * @param options - Formatting options.\n */\nexport function useNumberFormatter(options: NumberFormatOptions = {}): Intl.NumberFormat {\n let {locale} = useLocale();\n return useMemo(() => new NumberFormatter(locale, options), [locale, options]);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useLocale} from './context';\n\nlet cache = new Map<string, Intl.Collator>();\n\n/**\n * Provides localized string collation for the current locale. Automatically updates when the locale changes,\n * and handles caching of the collator for performance.\n * @param options - Collator options.\n */\nexport function useCollator(options?: Intl.CollatorOptions): Intl.Collator {\n let {locale} = useLocale();\n\n let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');\n if (cache.has(cacheKey)) {\n return cache.get(cacheKey);\n }\n\n let formatter = new Intl.Collator(locale, options);\n cache.set(cacheKey, formatter);\n return formatter;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCollator} from './useCollator';\n\ninterface Filter {\n /** Returns whether a string starts with a given substring. */\n startsWith(string: string, substring: string): boolean,\n /** Returns whether a string ends with a given substring. */\n endsWith(string: string, substring: string): boolean,\n /** Returns whether a string contains a given substring. */\n contains(string: string, substring: string): boolean\n}\n\n/**\n * Provides localized string search functionality that is useful for filtering or matching items\n * in a list. Options can be provided to adjust the sensitivity to case, diacritics, and other parameters.\n */\nexport function useFilter(options?: Intl.CollatorOptions): Filter {\n let collator = useCollator({\n usage: 'search',\n ...options\n });\n\n // TODO(later): these methods don't currently support the ignorePunctuation option.\n\n return {\n startsWith(string, substring) {\n if (substring.length === 0) {\n return true;\n }\n\n // Normalize both strings so we can slice safely\n // TODO: take into account the ignorePunctuation option as well...\n string = string.normalize('NFC');\n substring = substring.normalize('NFC');\n return collator.compare(string.slice(0, substring.length), substring) === 0;\n },\n endsWith(string, substring) {\n if (substring.length === 0) {\n return true;\n }\n\n string = string.normalize('NFC');\n substring = substring.normalize('NFC');\n return collator.compare(string.slice(-substring.length), substring) === 0;\n },\n contains(string, substring) {\n if (substring.length === 0) {\n return true;\n }\n\n string = string.normalize('NFC');\n substring = substring.normalize('NFC');\n\n let scan = 0;\n let sliceLen = substring.length;\n for (; scan + sliceLen <= string.length; scan++) {\n let slice = string.slice(scan, scan + sliceLen);\n if (collator.compare(substring, slice) === 0) {\n return true;\n }\n }\n\n return false;\n }\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","RTL_SCRIPTS","Set","RTL_LANGS","isRTL","locale","Intl","Locale","script","maximize","has","lang","split","getDefaultLocale","navigator","language","userLanguage","direction","currentLocale","listeners","updateLocale","listener","useDefaultLocale","isSSR","useIsSSR","defaultLocale","setDefaultLocale","useState","useEffect","size","window","addEventListener","add","delete","removeEventListener","I18nContext","React","createContext","I18nProvider","props","children","value","useLocale","context","useContext","cache","WeakMap","getCachedDictionary","strings","dictionary","get","MessageDictionary","set","useMessageFormatter","useMemo","formatter","MessageFormatter","useCallback","key","variables","format","formatterCache","Map","useDateFormatter","options","calendar","includes","cacheKey","Object","entries","sort","b","join","DateTimeFormat","useNumberFormatter","NumberFormatter","useCollator","Collator","useFilter","collator","usage","startsWith","string","substring","length","normalize","compare","slice","endsWith","contains","scan","sliceLen"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEAA,EAUG,AAVH;;;;;;;;;;CAUG,AAVH,EAUG,CAEH,EAA8C,AAA9C,4CAA8C;AAC9C,KAAK,CAAC,iCAAW,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAAA,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;IAAE,CAAM;AAAA,CAAC;AAC5G,KAAK,CAAC,+BAAS,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IAAA,CAAI;IAAE,CAAI;IAAE,CAAK;IAAE,CAAK;IAAE,CAAK;IAAE,CAAK;IAAE,CAAI;IAAE,CAAI;IAAE,CAAK;IAAE,CAAI;IAAE,CAAI;IAAE,CAAK;IAAE,CAAK;IAAE,CAAK;IAAE,CAAI;IAAE,CAAI;IAAE,CAAI;IAAE,CAAI;IAAE,CAAI;AAAA,CAAC;SAKpI,yCAAK,CAAC,MAAc,EAAE,CAAC;IACrC,EAAgF,AAAhF,8EAAgF;IAChF,EAAuG,AAAvG,qGAAuG;IACvG,EAAa,AAAb,WAAa;IACb,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,EAAa,AAAb,WAAa;QACb,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GA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AQ,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,GAAI,CAAC;gBAChD,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ;gBAC9C,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,MAAM,CAAC,EAC1C,MAAM,CAAC,IAAI;YAEf,CAAC;YAED,MAAM,CAAC,KAAK;QACd,CAAC;IACH,CAAC;AACH,CAAC;;","sources":["packages/@react-aria/i18n/src/index.ts","packages/@react-aria/i18n/src/context.tsx","packages/@react-aria/i18n/src/utils.ts","packages/@react-aria/i18n/src/useDefaultLocale.ts","packages/@react-aria/i18n/src/useMessageFormatter.ts","packages/@react-aria/i18n/src/useDateFormatter.ts","packages/@react-aria/i18n/src/useNumberFormatter.ts","packages/@react-aria/i18n/src/useCollator.ts","packages/@react-aria/i18n/src/useFilter.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/// <reference types=\"intl-types-extension\" />\n\nexport * from './context';\nexport * from './useMessageFormatter';\nexport * from './useDateFormatter';\nexport * from './useNumberFormatter';\nexport * from './useCollator';\nexport * from './useFilter';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {isRTL} from './utils';\nimport {Locale, useDefaultLocale} from './useDefaultLocale';\nimport React, {ReactNode, useContext} from 'react';\n\ninterface ProviderProps {\n /** Contents that should have the locale applied. */\n children: ReactNode,\n /** The locale to apply to the children. */\n locale?: string\n}\n\nconst I18nContext = React.createContext<Locale>(null);\n\n/**\n * Provides the locale for the application to all child components.\n */\nexport function I18nProvider(props: ProviderProps) {\n let {locale, children} = props;\n let defaultLocale = useDefaultLocale();\n\n let value: Locale = locale ? {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr'\n } : defaultLocale;\n\n return (\n <I18nContext.Provider value={value}>\n {children}\n </I18nContext.Provider>\n );\n}\n\n/**\n * Returns the current locale and layout direction.\n */\nexport function useLocale(): Locale {\n let defaultLocale = useDefaultLocale();\n let context = useContext(I18nContext);\n return context || defaultLocale;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// https://en.wikipedia.org/wiki/Right-to-left\nconst RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);\nconst RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);\n\n/**\n * Determines if a locale is read right to left using [Intl.Locale]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale}.\n */\nexport function isRTL(locale: string) {\n // If the Intl.Locale API is available, use it to get the script for the locale.\n // This is more accurate than guessing by language, since languages can be written in multiple scripts.\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n let script = new Intl.Locale(locale).maximize().script;\n return RTL_SCRIPTS.has(script);\n }\n\n // If not, just guess by the language (first part of the locale)\n let lang = locale.split('-')[0];\n return RTL_LANGS.has(lang);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Direction} from '@react-types/shared';\nimport {isRTL} from './utils';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport interface Locale {\n /** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */\n locale: string,\n /** The writing direction for the locale. */\n direction: Direction\n}\n\n/**\n * Gets the locale setting of the browser.\n */\nexport function getDefaultLocale(): Locale {\n // @ts-ignore\n let locale = (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) || 'en-US';\n return {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr'\n };\n}\n\nlet currentLocale = getDefaultLocale();\nlet listeners = new Set<(locale: Locale) => void>();\n\nfunction updateLocale() {\n currentLocale = getDefaultLocale();\n for (let listener of listeners) {\n listener(currentLocale);\n }\n}\n\n/**\n * Returns the current browser/system language, and updates when it changes.\n */\nexport function useDefaultLocale(): Locale {\n let isSSR = useIsSSR();\n let [defaultLocale, setDefaultLocale] = useState(currentLocale);\n\n useEffect(() => {\n if (listeners.size === 0) {\n window.addEventListener('languagechange', updateLocale);\n }\n\n listeners.add(setDefaultLocale);\n\n return () => {\n listeners.delete(setDefaultLocale);\n if (listeners.size === 0) {\n window.removeEventListener('languagechange', updateLocale);\n }\n };\n }, []);\n\n // We cannot determine the browser's language on the server, so default to\n // en-US. This will be updated after hydration on the client to the correct value.\n if (isSSR) {\n return {\n locale: 'en-US',\n direction: 'ltr'\n };\n }\n\n return defaultLocale;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {LocalizedStrings, MessageDictionary, MessageFormatter} from '@internationalized/message';\nimport {useCallback, useMemo} from 'react';\nimport {useLocale} from './context';\n\ntype FormatMessage = (key: string, variables?: {[key: string]: any}) => string;\n\nconst cache = new WeakMap();\nfunction getCachedDictionary(strings: LocalizedStrings) {\n let dictionary = cache.get(strings);\n if (!dictionary) {\n dictionary = new MessageDictionary(strings);\n cache.set(strings, dictionary);\n }\n\n return dictionary;\n}\n\n/**\n * Handles formatting ICU Message strings to create localized strings for the current locale.\n * Automatically updates when the locale changes, and handles caching of messages for performance.\n * @param strings - A mapping of languages to strings by key.\n */\nexport function useMessageFormatter(strings: LocalizedStrings): FormatMessage {\n let {locale} = useLocale();\n let dictionary = useMemo(() => getCachedDictionary(strings), [strings]);\n let formatter = useMemo(() => new MessageFormatter(locale, dictionary), [locale, dictionary]);\n return useCallback((key, variables) => formatter.format(key, variables), [formatter]);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DateFormatter} from '@internationalized/date';\nimport {useLocale} from './context';\nimport {useMemo, useRef} from 'react';\n\ninterface DateFormatterOptions extends Intl.DateTimeFormatOptions {\n calendar?: string\n}\n\n/**\n * Provides localized date formatting for the current locale. Automatically updates when the locale changes,\n * and handles caching of the date formatter for performance.\n * @param options - Formatting options.\n */\nexport function useDateFormatter(options?: DateFormatterOptions): DateFormatter {\n // Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.\n let lastOptions = useRef(null);\n if (options && lastOptions.current && isEqual(options, lastOptions.current)) {\n options = lastOptions.current;\n }\n\n lastOptions.current = options;\n\n let {locale} = useLocale();\n return useMemo(() => new DateFormatter(locale, options), [locale, options]);\n}\n\nfunction isEqual(a: DateFormatterOptions, b: DateFormatterOptions) {\n if (a === b) {\n return true;\n }\n\n let aKeys = Object.keys(a);\n let bKeys = Object.keys(b);\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n\n for (let key of aKeys) {\n if (b[key] !== a[key]) {\n return false;\n }\n }\n\n return true;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {NumberFormatOptions, NumberFormatter} from '@internationalized/number';\nimport {useLocale} from './context';\nimport {useMemo} from 'react';\n\n/**\n * Provides localized number formatting for the current locale. Automatically updates when the locale changes,\n * and handles caching of the number formatter for performance.\n * @param options - Formatting options.\n */\nexport function useNumberFormatter(options: NumberFormatOptions = {}): Intl.NumberFormat {\n let {locale} = useLocale();\n return useMemo(() => new NumberFormatter(locale, options), [locale, options]);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useLocale} from './context';\n\nlet cache = new Map<string, Intl.Collator>();\n\n/**\n * Provides localized string collation for the current locale. Automatically updates when the locale changes,\n * and handles caching of the collator for performance.\n * @param options - Collator options.\n */\nexport function useCollator(options?: Intl.CollatorOptions): Intl.Collator {\n let {locale} = useLocale();\n\n let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');\n if (cache.has(cacheKey)) {\n return cache.get(cacheKey);\n }\n\n let formatter = new Intl.Collator(locale, options);\n cache.set(cacheKey, formatter);\n return formatter;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCollator} from './useCollator';\n\ninterface Filter {\n /** Returns whether a string starts with a given substring. */\n startsWith(string: string, substring: string): boolean,\n /** Returns whether a string ends with a given substring. */\n endsWith(string: string, substring: string): boolean,\n /** Returns whether a string contains a given substring. */\n contains(string: string, substring: string): boolean\n}\n\n/**\n * Provides localized string search functionality that is useful for filtering or matching items\n * in a list. Options can be provided to adjust the sensitivity to case, diacritics, and other parameters.\n */\nexport function useFilter(options?: Intl.CollatorOptions): Filter {\n let collator = useCollator({\n usage: 'search',\n ...options\n });\n\n // TODO(later): these methods don't currently support the ignorePunctuation option.\n\n return {\n startsWith(string, substring) {\n if (substring.length === 0) {\n return true;\n }\n\n // Normalize both strings so we can slice safely\n // TODO: take into account the ignorePunctuation option as well...\n string = string.normalize('NFC');\n substring = substring.normalize('NFC');\n return collator.compare(string.slice(0, substring.length), substring) === 0;\n },\n endsWith(string, substring) {\n if (substring.length === 0) {\n return true;\n }\n\n string = string.normalize('NFC');\n substring = substring.normalize('NFC');\n return collator.compare(string.slice(-substring.length), substring) === 0;\n },\n contains(string, substring) {\n if (substring.length === 0) {\n return true;\n }\n\n string = string.normalize('NFC');\n substring = substring.normalize('NFC');\n\n let scan = 0;\n let sliceLen = substring.length;\n for (; scan + sliceLen <= string.length; scan++) {\n let slice = string.slice(scan, scan + sliceLen);\n if (collator.compare(substring, slice) === 0) {\n return true;\n }\n }\n\n return false;\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|