@react-aria/i18n 3.2.0 → 3.3.3

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/module.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
2
- import _intlMessageformat from "intl-messageformat";
2
+ import { NumberFormatter } from "@internationalized/number";
3
+ import { DateFormatter } from "@internationalized/date";
4
+ import { MessageDictionary, MessageFormatter } from "@internationalized/message";
3
5
  import { useIsSSR } from "@react-aria/ssr";
4
- import _react, { useEffect, useState, useContext, useCallback, useRef } from "react";
6
+ import _react, { useEffect, useState, useContext, useCallback, useMemo, useRef } from "react";
5
7
 
6
8
  /*
7
9
  * Copyright 2020 Adobe. All rights reserved.
@@ -36,42 +38,6 @@ function $d26e725ad56fbcb2c25f52b7de27$export$isRTL(locale) {
36
38
  return $d26e725ad56fbcb2c25f52b7de27$var$RTL_LANGS.has(lang);
37
39
  }
38
40
 
39
- function $d26e725ad56fbcb2c25f52b7de27$export$numberFormatSignDisplayPolyfill(numberFormat, signDisplay, num) {
40
- if (signDisplay === 'auto') {
41
- return numberFormat.format(num);
42
- } else if (signDisplay === 'never') {
43
- return numberFormat.format(Math.abs(num));
44
- } else {
45
- let needsPositiveSign = false;
46
-
47
- if (signDisplay === 'always') {
48
- needsPositiveSign = num > 0 || Object.is(num, 0);
49
- } else if (signDisplay === 'exceptZero') {
50
- if (Object.is(num, -0) || Object.is(num, 0)) {
51
- num = Math.abs(num);
52
- } else {
53
- needsPositiveSign = num > 0;
54
- }
55
- }
56
-
57
- if (needsPositiveSign) {
58
- let negative = numberFormat.format(-num);
59
- let noSign = numberFormat.format(num); // ignore RTL/LTR marker character
60
-
61
- let minus = negative.replace(noSign, '').replace(/\u200e|\u061C/, '');
62
-
63
- if ([...minus].length !== 1) {
64
- console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');
65
- }
66
-
67
- let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);
68
- return positive;
69
- } else {
70
- return numberFormat.format(num);
71
- }
72
- }
73
- }
74
-
75
41
  /**
76
42
  * Gets the locale setting of the browser.
77
43
  */
@@ -128,7 +94,7 @@ function $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale() {
128
94
  return defaultLocale;
129
95
  }
130
96
 
131
- const $cff8541df3b5c83067b2ab3ee0d20$var$I18nContext = _react.createContext(null);
97
+ const $cff8541df3b5c83067b2ab3ee0d20$var$I18nContext = /*#__PURE__*/_react.createContext(null);
132
98
 
133
99
  export function I18nProvider(props) {
134
100
  let {
@@ -153,185 +119,89 @@ export function useLocale() {
153
119
  let context = useContext($cff8541df3b5c83067b2ab3ee0d20$var$I18nContext);
154
120
  return context || defaultLocale;
155
121
  }
156
- const $f58d206cee90f9c2bf3c03e4522c35$var$formatterCache = new Map();
122
+ const $f58d206cee90f9c2bf3c03e4522c35$var$cache = new WeakMap();
123
+
124
+ function $f58d206cee90f9c2bf3c03e4522c35$var$getCachedDictionary(strings) {
125
+ let dictionary = $f58d206cee90f9c2bf3c03e4522c35$var$cache.get(strings);
126
+
127
+ if (!dictionary) {
128
+ dictionary = new MessageDictionary(strings);
129
+ $f58d206cee90f9c2bf3c03e4522c35$var$cache.set(strings, dictionary);
130
+ }
131
+
132
+ return dictionary;
133
+ }
157
134
  /**
158
135
  * Handles formatting ICU Message strings to create localized strings for the current locale.
159
136
  * Automatically updates when the locale changes, and handles caching of messages for performance.
160
137
  * @param strings - A mapping of languages to strings by key.
161
138
  */
162
139
 
140
+
163
141
  export function useMessageFormatter(strings) {
164
142
  let {
165
- locale: currentLocale
166
- } = useLocale(); // Check the cache
167
-
168
- let localeCache = $f58d206cee90f9c2bf3c03e4522c35$var$formatterCache.get(strings);
169
-
170
- if (localeCache && localeCache.has(currentLocale)) {
171
- return localeCache.get(currentLocale);
172
- } // Add to the formatter cache if needed
173
-
174
-
175
- if (!localeCache) {
176
- localeCache = new Map();
177
- $f58d206cee90f9c2bf3c03e4522c35$var$formatterCache.set(strings, localeCache);
178
- } // Get the strings for the current locale
179
-
180
-
181
- let localeStrings = $f58d206cee90f9c2bf3c03e4522c35$var$selectLocale(strings, currentLocale); // Create a new message formatter
182
-
183
- let cache = {};
184
-
185
- let formatMessage = (key, variables) => {
186
- let message = cache[key + '.' + currentLocale];
187
-
188
- if (!message) {
189
- let msg = localeStrings[key];
190
-
191
- if (!msg) {
192
- throw new Error("Could not find intl message " + key + " in " + currentLocale + " locale");
193
- }
194
-
195
- message = new _intlMessageformat(msg, currentLocale);
196
- cache[key] = message;
197
- }
198
-
199
- return message.format(variables);
200
- };
201
-
202
- localeCache.set(currentLocale, formatMessage);
203
- return formatMessage;
204
- }
205
-
206
- function $f58d206cee90f9c2bf3c03e4522c35$var$selectLocale(strings, locale) {
207
- // If there is an exact match, use it.
208
- if (strings[locale]) {
209
- return strings[locale];
210
- } // Attempt to find the closest match by language.
211
- // For example, if the locale is fr-CA (French Canadian), but there is only
212
- // an fr-FR (France) set of strings, use that.
213
-
214
-
215
- let language = $f58d206cee90f9c2bf3c03e4522c35$var$getLanguage(locale);
216
-
217
- for (let key in strings) {
218
- if (key.startsWith(language + '-')) {
219
- return strings[key];
220
- }
221
- } // Nothing close, use english.
222
-
223
-
224
- return strings['en-US'];
225
- }
226
-
227
- function $f58d206cee90f9c2bf3c03e4522c35$var$getLanguage(locale) {
228
- // @ts-ignore
229
- if (Intl.Locale) {
230
- // @ts-ignore
231
- return new Intl.Locale(locale).language;
232
- }
233
-
234
- return locale.split('-')[0];
143
+ locale
144
+ } = useLocale();
145
+ let dictionary = useMemo(() => $f58d206cee90f9c2bf3c03e4522c35$var$getCachedDictionary(strings), [strings]);
146
+ let formatter = useMemo(() => new MessageFormatter(locale, dictionary), [locale, dictionary]);
147
+ return useCallback((key, variables) => formatter.format(key, variables), [formatter]);
235
148
  }
236
149
 
237
- let $b0007c63a64054c318efb8b6cd0053f$var$formatterCache = new Map();
238
150
  /**
239
151
  * Provides localized date formatting for the current locale. Automatically updates when the locale changes,
240
152
  * and handles caching of the date formatter for performance.
241
153
  * @param options - Formatting options.
242
154
  */
243
-
244
155
  export function useDateFormatter(options) {
156
+ // Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
157
+ let lastOptions = useRef(null);
158
+
159
+ if (options && lastOptions.current && $b0007c63a64054c318efb8b6cd0053f$var$isEqual(options, lastOptions.current)) {
160
+ options = lastOptions.current;
161
+ }
162
+
163
+ lastOptions.current = options;
245
164
  let {
246
165
  locale
247
166
  } = useLocale();
248
- let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
167
+ return useMemo(() => new DateFormatter(locale, options), [locale, options]);
168
+ }
249
169
 
250
- if ($b0007c63a64054c318efb8b6cd0053f$var$formatterCache.has(cacheKey)) {
251
- return $b0007c63a64054c318efb8b6cd0053f$var$formatterCache.get(cacheKey);
170
+ function $b0007c63a64054c318efb8b6cd0053f$var$isEqual(a, b) {
171
+ if (a === b) {
172
+ return true;
252
173
  }
253
174
 
254
- let formatter = new Intl.DateTimeFormat(locale, options);
255
- $b0007c63a64054c318efb8b6cd0053f$var$formatterCache.set(cacheKey, formatter);
256
- return formatter;
257
- }
175
+ let aKeys = Object.keys(a);
176
+ let bKeys = Object.keys(b);
258
177
 
259
- /**
260
- * Provides localized number parsing for the current locale.
261
- * Idea from https://observablehq.com/@mbostock/localized-number-parsing.
262
- */
263
- export function useNumberParser() {
264
- let {
265
- locale
266
- } = useLocale();
267
- const numberData = useRef({
268
- group: null,
269
- decimal: null,
270
- numeral: null,
271
- index: null
272
- });
273
- useEffect(() => {
274
- const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
275
- const numerals = [...new Intl.NumberFormat(locale, {
276
- useGrouping: false
277
- }).format(9876543210)].reverse();
278
- const index = new Map(numerals.map((d, i) => [d, i]));
279
- numberData.current.group = new RegExp("[" + parts.find(d => d.type === 'group').value + "]", 'g');
280
- numberData.current.decimal = new RegExp("[" + parts.find(d => d.type === 'decimal').value + "]");
281
- numberData.current.numeral = new RegExp("[" + numerals.join('') + "]", 'g');
282
-
283
- numberData.current.index = d => index.get(d);
284
- }, [locale]);
285
- const parse = useCallback(value => {
286
- value = value.trim().replace(numberData.current.group, '').replace(numberData.current.decimal, '.').replace(numberData.current.numeral, numberData.current.index);
287
- return value ? +value : NaN;
288
- }, []);
289
- return {
290
- parse
291
- };
178
+ if (aKeys.length !== bKeys.length) {
179
+ return false;
180
+ }
181
+
182
+ for (let key of aKeys) {
183
+ if (b[key] !== a[key]) {
184
+ return false;
185
+ }
186
+ }
187
+
188
+ return true;
292
189
  }
293
- let $ece3e138e83d330f42860705a2ec18a$var$formatterCache = new Map();
294
- let $ece3e138e83d330f42860705a2ec18a$var$supportsSignDisplay = false;
295
190
 
296
- try {
297
- // @ts-ignore
298
- $ece3e138e83d330f42860705a2ec18a$var$supportsSignDisplay = new Intl.NumberFormat('de-DE', {
299
- signDisplay: 'exceptZero'
300
- }).resolvedOptions().signDisplay === 'exceptZero'; // eslint-disable-next-line no-empty
301
- } catch (e) {}
302
191
  /**
303
192
  * Provides localized number formatting for the current locale. Automatically updates when the locale changes,
304
193
  * and handles caching of the number formatter for performance.
305
194
  * @param options - Formatting options.
306
195
  */
307
-
308
-
309
196
  export function useNumberFormatter(options) {
310
- let {
311
- locale
312
- } = useLocale();
313
- let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
314
-
315
- if ($ece3e138e83d330f42860705a2ec18a$var$formatterCache.has(cacheKey)) {
316
- return $ece3e138e83d330f42860705a2ec18a$var$formatterCache.get(cacheKey);
197
+ if (options === void 0) {
198
+ options = {};
317
199
  }
318
200
 
319
- let numberFormatter = new Intl.NumberFormat(locale, options); // @ts-ignore
320
-
321
201
  let {
322
- signDisplay
323
- } = options || {};
324
- $ece3e138e83d330f42860705a2ec18a$var$formatterCache.set(cacheKey, !$ece3e138e83d330f42860705a2ec18a$var$supportsSignDisplay && signDisplay != null ? new Proxy(numberFormatter, {
325
- get(target, property) {
326
- if (property === 'format') {
327
- return v => $d26e725ad56fbcb2c25f52b7de27$export$numberFormatSignDisplayPolyfill(numberFormatter, signDisplay, v);
328
- } else {
329
- return target[property];
330
- }
331
- }
332
-
333
- }) : numberFormatter);
334
- return numberFormatter;
202
+ locale
203
+ } = useLocale();
204
+ return useMemo(() => new NumberFormatter(locale, options), [locale, options]);
335
205
  }
336
206
  let $a4045a18d7252bf6de9312e613c4e$var$cache = new Map();
337
207
  /**
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;;AAYA;AACA,MAAMA,6CAAW,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,2CAAS,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;;;;AAGO,SAASE,0CAAT,CAAeC,MAAf,EAA+B;AACpC;AACA;AACA;AACA,MAAIC,IAAI,CAACC,MAAT,EAAiB;AACf;AACA,QAAIC,MAAM,GAAG,IAAIF,IAAI,CAACC,MAAT,CAAgBF,MAAhB,EAAwBI,QAAxB,GAAmCD,MAAhD;AACA,WAAOP,6CAAW,CAACS,GAAZ,CAAgBF,MAAhB,CAAP;AACD,GARmC,CAUpC;;;AACA,MAAIG,IAAI,GAA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AAGA,MAAM,CAACE,SAAP,CAAiB,KAAjB,CAAT;AACAD,MAAAA,SAAS,GAAGA,SAAS,CAACC,SAAV,CAAoB,KAApB,CAAZ;AACA,aAAOJ,QAAQ,CAACK,OAAT,CAAiBH,MAAM,CAACI,KAAP,CAAa,CAACH,SAAS,CAACxG,MAAxB,CAAjB,EAAkDwG,SAAlD,MAAiE,CAAxE;AACD,KApBI;;AAqBLK,IAAAA,QAAQ,CAACN,MAAD,EAASC,SAAT,EAAoB;AAC1B,UAAIA,SAAS,CAACxG,MAAV,KAAqB,CAAzB,EAA4B;AAC1B,eAAO,IAAP;AACD;;AAEDuG,MAAAA,MAAM,GAAGA,MAAM,CAACE,SAAP,CAAiB,KAAjB,CAAT;AACAD,MAAAA,SAAS,GAAGA,SAAS,CAACC,SAAV,CAAoB,KAApB,CAAZ;AAEA,UAAIK,IAAI,GAAG,CAAX;AACA,UAAIC,QAAQ,GAAGP,SAAS,CAACxG,MAAzB;;AACA,aAAO8G,IAAI,GAAGC,QAAP,IAAmBR,MAAM,CAACvG,MAAjC,EAAyC8G,IAAI,EAA7C,EAAiD;AAC/C,YAAIH,KAAK,GAAGJ,MAAM,CAACI,KAAP,CAAaG,IAAb,EAAmBA,IAAI,GAAGC,QAA1B,CAAZ;;AACA,YAAIV,QAAQ,CAACK,OAAT,CAAiBF,SAAjB,EAA4BG,KAA5B,MAAuC,CAA3C,EAA8C;AAC5C,iBAAO,IAAP;AACD;AACF;;AAED,aAAO,KAAP;AACD;;AAvCI,GAAP;AAyCD","sources":["./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/useNumberParser.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// 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\nexport function numberFormatSignDisplayPolyfill(numberFormat: Intl.NumberFormat, signDisplay: 'always' | 'exceptZero' | 'auto' | 'never', num: number) {\n if (signDisplay === 'auto') {\n return numberFormat.format(num);\n } else if (signDisplay === 'never') {\n return numberFormat.format(Math.abs(num));\n } else {\n let needsPositiveSign = false;\n if (signDisplay === 'always') {\n needsPositiveSign = num > 0 || Object.is(num, 0);\n } else if (signDisplay === 'exceptZero') {\n if (Object.is(num, -0) || Object.is(num, 0)) {\n num = Math.abs(num);\n } else {\n needsPositiveSign = num > 0;\n }\n }\n\n if (needsPositiveSign) {\n let negative = numberFormat.format(-num);\n let noSign = numberFormat.format(num);\n // ignore RTL/LTR marker character\n let minus = negative.replace(noSign, '').replace(/\\u200e|\\u061C/, '');\n if ([...minus].length !== 1) {\n console.warn('@react-aria/i18n polyfill for NumberFormat signDisplay: Unsupported case');\n }\n let positive = negative.replace(noSign, '!!!').replace(minus, '+').replace('!!!', noSign);\n return positive;\n } else {\n return numberFormat.format(num);\n }\n }\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 IntlMessageFormat from 'intl-messageformat';\nimport {useLocale} from './context';\n\ntype MessageFormatterStrings = {\n [lang: string]: {\n [key: string]: string\n }\n};\n\ntype FormatMessage = (key: string, variables?: {[key: string]: any}) => string;\n\nconst formatterCache = new Map();\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: MessageFormatterStrings): FormatMessage {\n let {locale: currentLocale} = useLocale();\n\n // Check the cache\n let localeCache = formatterCache.get(strings);\n if (localeCache && localeCache.has(currentLocale)) {\n return localeCache.get(currentLocale);\n }\n\n // Add to the formatter cache if needed\n if (!localeCache) {\n localeCache = new Map();\n formatterCache.set(strings, localeCache);\n }\n\n // Get the strings for the current locale\n let localeStrings = selectLocale(strings, currentLocale);\n\n // Create a new message formatter\n let cache = {};\n let formatMessage = (key, variables) => {\n let message = cache[key + '.' + currentLocale];\n if (!message) {\n let msg = localeStrings[key];\n if (!msg) {\n throw new Error(`Could not find intl message ${key} in ${currentLocale} locale`);\n }\n\n message = new IntlMessageFormat(msg, currentLocale);\n cache[key] = message;\n }\n\n return message.format(variables);\n };\n\n localeCache.set(currentLocale, formatMessage);\n return formatMessage;\n}\n\nfunction selectLocale(strings, locale) {\n // If there is an exact match, use it.\n if (strings[locale]) {\n return strings[locale];\n }\n\n // Attempt to find the closest match by language.\n // For example, if the locale is fr-CA (French Canadian), but there is only\n // an fr-FR (France) set of strings, use that.\n let language = getLanguage(locale);\n for (let key in strings) {\n if (key.startsWith(language + '-')) {\n return strings[key];\n }\n }\n\n // Nothing close, use english.\n return strings['en-US'];\n}\n\nfunction getLanguage(locale) {\n // @ts-ignore\n if (Intl.Locale) {\n // @ts-ignore\n return new Intl.Locale(locale).language;\n }\n\n return locale.split('-')[0];\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 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?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {\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 (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 {useCallback, useEffect, useRef} from 'react';\nimport {useLocale} from './context';\n\ntype NumberParser = {\n parse: (value:string) => number\n}\n\n/**\n * Provides localized number parsing for the current locale.\n * Idea from https://observablehq.com/@mbostock/localized-number-parsing.\n */\nexport function useNumberParser(): NumberParser {\n let {locale} = useLocale();\n const numberData = useRef({group: null, decimal: null, numeral: null, index: null});\n\n useEffect(() => {\n const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);\n const numerals = [...new Intl.NumberFormat(locale, {useGrouping: false}).format(9876543210)].reverse();\n const index = new Map(numerals.map((d, i) => [d, i]));\n \n numberData.current.group = new RegExp(`[${parts.find(d => d.type === 'group').value}]`, 'g');\n numberData.current.decimal = new RegExp(`[${parts.find(d => d.type === 'decimal').value}]`);\n numberData.current.numeral = new RegExp(`[${numerals.join('')}]`, 'g');\n numberData.current.index = d => index.get(d);\n }, [locale]);\n\n const parse = useCallback((value:string) => {\n value = value.trim()\n .replace(numberData.current.group, '')\n .replace(numberData.current.decimal, '.')\n .replace(numberData.current.numeral, numberData.current.index);\n return value ? +value : NaN;\n }, []);\n\n return {parse};\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 {numberFormatSignDisplayPolyfill} from './utils';\nimport {useLocale} from './context';\n\nlet formatterCache = new Map<string, Intl.NumberFormat>();\n\nlet supportsSignDisplay = false;\ntry {\n // @ts-ignore\n supportsSignDisplay = (new Intl.NumberFormat('de-DE', {signDisplay: 'exceptZero'})).resolvedOptions().signDisplay === 'exceptZero';\n // eslint-disable-next-line no-empty\n} catch (e) {}\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?: Intl.NumberFormatOptions): Intl.NumberFormat {\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 (formatterCache.has(cacheKey)) {\n return formatterCache.get(cacheKey);\n }\n\n let numberFormatter = new Intl.NumberFormat(locale, options);\n // @ts-ignore\n let {signDisplay} = options || {};\n formatterCache.set(cacheKey, (!supportsSignDisplay && signDisplay != null) ? new Proxy(numberFormatter, {\n get(target, property) {\n if (property === 'format') {\n return (v) => numberFormatSignDisplayPolyfill(numberFormatter, signDisplay, v);\n } else {\n return target[property];\n }\n }\n }) : numberFormatter);\n return numberFormatter;\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":["RTL_SCRIPTS","Set","RTL_LANGS","isRTL","locale","Intl","Locale","script","maximize","has","lang","split","numberFormatSignDisplayPolyfill","numberFormat","signDisplay","num","format","Math","abs","needsPositiveSign","Object","is","negative","noSign","minus","replace","length","console","warn","positive","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","formatterCache","Map","useMessageFormatter","strings","localeCache","get","set","localeStrings","selectLocale","cache","formatMessage","key","variables","message","msg","Error","IntlMessageFormat","getLanguage","startsWith","useDateFormatter","options","cacheKey","entries","sort","a","b","join","formatter","DateTimeFormat","useNumberParser","numberData","useRef","group","decimal","numeral","index","parts","NumberFormat","formatToParts","numerals","useGrouping","reverse","map","d","i","current","RegExp","find","type","parse","useCallback","trim","NaN","supportsSignDisplay","resolvedOptions","e","useNumberFormatter","numberFormatter","Proxy","target","property","v","useCollator","Collator","useFilter","collator","usage","string","substring","normalize","compare","slice","endsWith","contains","scan","sliceLen"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;;AAYA;AACA,MAAMA,6CAAW,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,2CAAS,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;;;;AAGO,SAASE,0CAAT,CAAeC,MAAf,EAA+B;AACpC;AACA;AACA;AACA,MAAIC,IAAI,CAACC,MAAT,EAAiB;AACf;AACA,QAAIC,MAAM,GAAG,IAAIF,IAAI,CAACC,MAAT,CAAgBF,MAAhB,EAAwBI,QAAxB,GAAmCD,MAAhD;AACA,WAAOP,6CAAW,CAACS,GAAZ,CAAgBF,MAAhB,CAAP;AACD,GARmC,C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,MAAAA,SAAS,GAAGA,SAAS,CAACC,SAAV,CAAoB,KAApB,CAAZ;AAEA,UAAIK,IAAI,GAAG,CAAX;AACA,UAAIC,QAAQ,GAAGP,SAAS,CAACf,MAAzB;;AACA,aAAOqB,IAAI,GAAGC,QAAP,IAAmBR,MAAM,CAACd,MAAjC,EAAyCqB,IAAI,EAA7C,EAAiD;AAC/C,YAAIH,KAAK,GAAGJ,MAAM,CAACI,KAAP,CAAaG,IAAb,EAAmBA,IAAI,GAAGC,QAA1B,CAAZ;;AACA,YAAIX,QAAQ,CAACM,OAAT,CAAiBF,SAAjB,EAA4BG,KAA5B,MAAuC,CAA3C,EAA8C;AAC5C,iBAAO,IAAP;AACD;AACF;;AAED,aAAO,KAAP;AACD;;AAvCI,GAAP;AAyCD","sources":["./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":["/*\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 {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":["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","useDateFormatter","options","lastOptions","useRef","current","isEqual","DateFormatter","a","b","aKeys","Object","keys","bKeys","length","useNumberFormatter","NumberFormatter","Map","useCollator","cacheKey","entries","sort","join","Collator","useFilter","collator","usage","startsWith","string","substring","normalize","compare","slice","endsWith","contains","scan","sliceLen"],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { Direction } from "@react-types/shared";
2
2
  import { ReactNode } from "react";
3
+ import { LocalizedStrings } from "@internationalized/message";
4
+ import { DateFormatter } from "@internationalized/date";
5
+ import { NumberFormatOptions } from "@internationalized/number";
3
6
  interface Locale {
4
7
  /** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */
5
8
  locale: string;
@@ -20,11 +23,6 @@ export function I18nProvider(props: ProviderProps): JSX.Element;
20
23
  * Returns the current locale and layout direction.
21
24
  */
22
25
  export function useLocale(): Locale;
23
- type MessageFormatterStrings = {
24
- [lang: string]: {
25
- [key: string]: string;
26
- };
27
- };
28
26
  type FormatMessage = (key: string, variables?: {
29
27
  [key: string]: any;
30
28
  }) => string;
@@ -33,27 +31,22 @@ type FormatMessage = (key: string, variables?: {
33
31
  * Automatically updates when the locale changes, and handles caching of messages for performance.
34
32
  * @param strings - A mapping of languages to strings by key.
35
33
  */
36
- export function useMessageFormatter(strings: MessageFormatterStrings): FormatMessage;
34
+ export function useMessageFormatter(strings: LocalizedStrings): FormatMessage;
35
+ interface DateFormatterOptions extends Intl.DateTimeFormatOptions {
36
+ calendar?: string;
37
+ }
37
38
  /**
38
39
  * Provides localized date formatting for the current locale. Automatically updates when the locale changes,
39
40
  * and handles caching of the date formatter for performance.
40
41
  * @param options - Formatting options.
41
42
  */
42
- export function useDateFormatter(options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat;
43
- type NumberParser = {
44
- parse: (value: string) => number;
45
- };
46
- /**
47
- * Provides localized number parsing for the current locale.
48
- * Idea from https://observablehq.com/@mbostock/localized-number-parsing.
49
- */
50
- export function useNumberParser(): NumberParser;
43
+ export function useDateFormatter(options?: DateFormatterOptions): DateFormatter;
51
44
  /**
52
45
  * Provides localized number formatting for the current locale. Automatically updates when the locale changes,
53
46
  * and handles caching of the number formatter for performance.
54
47
  * @param options - Formatting options.
55
48
  */
56
- export function useNumberFormatter(options?: Intl.NumberFormatOptions): Intl.NumberFormat;
49
+ export function useNumberFormatter(options?: NumberFormatOptions): Intl.NumberFormat;
57
50
  /**
58
51
  * Provides localized string collation for the current locale. Automatically updates when the locale changes,
59
52
  * and handles caching of the collator for performance.
@@ -1 +1 @@
1
- {"mappings":"A;A;ACiBA;IACE,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE,SAAS,CAAA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rD;AAED;A;A;GAGG;AACH,0BAA0B,OAAO,CAAC,EAAE,KAAK,eAAe,GAAG,MAAM,CAiDhE","sources":["./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/utils.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useDefaultLocale.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/context.tsx","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useMessageFormatter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useDateFormatter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useNumberParser.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useNumberFormatter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useCollator.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useFilter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":"A;A;A;A;A;ACiBA;IACE,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE,SAAS,CAAA;CACrB;ACND;IACE,oDAAoD;IACpD,QAAQ,EAAE,SAAS,CAAC;IACpB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAID;A;GAEG;AACH,6BAA6B,KAAK,EAAE,aAAa,eAchD;AAED;A;GAEG;AACH,6BAA6B,MAAM,CAIlC;ACnCD,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,KAAK,MAAM,CAAC;AAa/E;A;A;A;GAIG;AACH,oCAAoC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAK5E;ACvBD,8BAA+B,SAAQ,IAAI,CAAC,qBAAqB;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;A;A;A;GAIG;AACH,iCAAiC,OAAO,CAAC,EAAE,oBAAoB,GAAG,aAAa,CAW9E;ACpBD;A;A;A;GAIG;AACH,mCAAmC,OAAO,GAAE,mBAAwB,GAAG,KAAK,YAAY,CAGvF;ACRD;A;A;A;GAIG;AACH,4BAA4B,OAAO,CAAC,EAAE,KAAK,eAAe,GAAG,KAAK,QAAQ,CAWzE;AClBD;IACE,8DAA8D;IAC9D,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACvD,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACrD,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAA;CACrD;AAED;A;A;GAGG;AACH,0BAA0B,OAAO,CAAC,EAAE,KAAK,eAAe,GAAG,MAAM,CAiDhE","sources":["./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/utils.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useDefaultLocale.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/context.tsx","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useMessageFormatter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useDateFormatter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useNumberFormatter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useCollator.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/useFilter.ts","./packages/@react-aria/i18n/src/packages/@react-aria/i18n/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/i18n",
3
- "version": "3.2.0",
3
+ "version": "3.3.3",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,9 +18,12 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-aria/ssr": "^3.0.1",
22
- "@react-types/shared": "^3.3.0",
23
- "intl-messageformat": "^2.2.0"
21
+ "@internationalized/date": "3.0.0-alpha.0",
22
+ "@internationalized/message": "^3.0.2",
23
+ "@internationalized/number": "^3.0.2",
24
+ "@react-aria/ssr": "^3.0.3",
25
+ "@react-aria/utils": "^3.10.0",
26
+ "@react-types/shared": "^3.10.0"
24
27
  },
25
28
  "peerDependencies": {
26
29
  "react": "^16.8.0 || ^17.0.0-rc.1"
@@ -28,5 +31,5 @@
28
31
  "publishConfig": {
29
32
  "access": "public"
30
33
  },
31
- "gitHead": "f5b429ee8615248f2e3c76754bad2ece83f1c444"
34
+ "gitHead": "896eabe5521a0349a675c4773ed7629addd4b8c4"
32
35
  }
package/src/index.ts CHANGED
@@ -10,10 +10,11 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ /// <reference types="intl-types-extension" />
14
+
13
15
  export * from './context';
14
16
  export * from './useMessageFormatter';
15
17
  export * from './useDateFormatter';
16
- export * from './useNumberParser';
17
18
  export * from './useNumberFormatter';
18
19
  export * from './useCollator';
19
20
  export * from './useFilter';
@@ -10,24 +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
- let formatterCache = new Map<string, Intl.DateTimeFormat>();
17
+ interface DateFormatterOptions extends Intl.DateTimeFormatOptions {
18
+ calendar?: string
19
+ }
16
20
 
17
21
  /**
18
22
  * Provides localized date formatting for the current locale. Automatically updates when the locale changes,
19
23
  * and handles caching of the date formatter for performance.
20
24
  * @param options - Formatting options.
21
25
  */
22
- export function useDateFormatter(options?: Intl.DateTimeFormatOptions): Intl.DateTimeFormat {
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
+
23
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
+ }
43
+
44
+ let aKeys = Object.keys(a);
45
+ let bKeys = Object.keys(b);
46
+ if (aKeys.length !== bKeys.length) {
47
+ return false;
48
+ }
24
49
 
25
- let cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : '');
26
- if (formatterCache.has(cacheKey)) {
27
- return formatterCache.get(cacheKey);
50
+ for (let key of aKeys) {
51
+ if (b[key] !== a[key]) {
52
+ return false;
53
+ }
28
54
  }
29
55
 
30
- let formatter = new Intl.DateTimeFormat(locale, options);
31
- formatterCache.set(cacheKey, formatter);
32
- return formatter;
56
+ return true;
33
57
  }