@react-aria/i18n 3.3.0 → 3.3.4
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 +37 -12
- package/dist/main.js.map +1 -1
- package/dist/module.js +31 -10
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/useDateFormatter.ts +32 -8
package/dist/main.js
CHANGED
|
@@ -4,6 +4,10 @@ var {
|
|
|
4
4
|
NumberFormatter
|
|
5
5
|
} = require("@internationalized/number");
|
|
6
6
|
|
|
7
|
+
var {
|
|
8
|
+
DateFormatter
|
|
9
|
+
} = require("@internationalized/date");
|
|
10
|
+
|
|
7
11
|
var {
|
|
8
12
|
MessageDictionary,
|
|
9
13
|
MessageFormatter
|
|
@@ -22,7 +26,8 @@ var {
|
|
|
22
26
|
useState,
|
|
23
27
|
useContext,
|
|
24
28
|
useCallback,
|
|
25
|
-
useMemo
|
|
29
|
+
useMemo,
|
|
30
|
+
useRef
|
|
26
31
|
} = _react2;
|
|
27
32
|
|
|
28
33
|
function $parcel$interopDefault(a) {
|
|
@@ -118,7 +123,7 @@ function $c53c7d716f930bd5da78e9efb99e3e$export$useDefaultLocale() {
|
|
|
118
123
|
return defaultLocale;
|
|
119
124
|
}
|
|
120
125
|
|
|
121
|
-
const $aa95c2b730b505b265f124d9aec67193$var$I18nContext = _react.createContext(null);
|
|
126
|
+
const $aa95c2b730b505b265f124d9aec67193$var$I18nContext = /*#__PURE__*/_react.createContext(null);
|
|
122
127
|
|
|
123
128
|
function I18nProvider(props) {
|
|
124
129
|
let {
|
|
@@ -177,29 +182,49 @@ function useMessageFormatter(strings) {
|
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
exports.useMessageFormatter = useMessageFormatter;
|
|
180
|
-
|
|
185
|
+
|
|
181
186
|
/**
|
|
182
187
|
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
|
|
183
188
|
* and handles caching of the date formatter for performance.
|
|
184
189
|
* @param options - Formatting options.
|
|
185
190
|
*/
|
|
186
|
-
|
|
187
191
|
function useDateFormatter(options) {
|
|
192
|
+
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
|
|
193
|
+
let lastOptions = useRef(null);
|
|
194
|
+
|
|
195
|
+
if (options && lastOptions.current && $bdeee39f835a1e28966186127db96579$var$isEqual(options, lastOptions.current)) {
|
|
196
|
+
options = lastOptions.current;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
lastOptions.current = options;
|
|
188
200
|
let {
|
|
189
201
|
locale
|
|
190
202
|
} = useLocale();
|
|
191
|
-
|
|
203
|
+
return useMemo(() => new DateFormatter(locale, options), [locale, options]);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
exports.useDateFormatter = useDateFormatter;
|
|
192
207
|
|
|
193
|
-
|
|
194
|
-
|
|
208
|
+
function $bdeee39f835a1e28966186127db96579$var$isEqual(a, b) {
|
|
209
|
+
if (a === b) {
|
|
210
|
+
return true;
|
|
195
211
|
}
|
|
196
212
|
|
|
197
|
-
let
|
|
198
|
-
|
|
199
|
-
return formatter;
|
|
200
|
-
}
|
|
213
|
+
let aKeys = Object.keys(a);
|
|
214
|
+
let bKeys = Object.keys(b);
|
|
201
215
|
|
|
202
|
-
|
|
216
|
+
if (aKeys.length !== bKeys.length) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
for (let key of aKeys) {
|
|
221
|
+
if (b[key] !== a[key]) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
203
228
|
|
|
204
229
|
/**
|
|
205
230
|
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAA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EAAoDD,SAApD,MAAmE,CAA1E;AACD,KAXI;;AAYLK,IAAAA,QAAQ,CAACN,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;AACA,aAAON,QAAQ,CAACO,OAAT,CAAiBJ,MAAM,CAACK,KAAP,CAAa,CAACJ,SAAS,CAACC,MAAxB,CAAjB,EAAkDD,SAAlD,MAAiE,CAAxE;AACD,KApBI;;AAqBLM,IAAAA,QAAQ,CAACP,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\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 {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","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAA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AGA,MAAM,CAACE,SAAP,CAAiB,KAAjB,CAAT;AACAD,MAAAA,SAAS,GAAGA,SAAS,CAACC,SAAV,CAAoB,KAApB,CAAZ;AACA,aAAOL,QAAQ,CAACM,OAAT,CAAiBH,MAAM,CAACI,KAAP,CAAa,CAACH,SAAS,CAACf,MAAxB,CAAjB,EAAkDe,SAAlD,MAAiE,CAAxE;AACD,KApBI;;AAqBLK,IAAAA,QAAQ,CAACN,MAAD,EAASC,SAAT,EAAoB;AAC1B,UAAIA,SAAS,CAACf,MAAV,KAAqB,CAAzB,EAA4B;AAC1B,eAAO,IAAP;AACD;;AAEDc,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,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":["./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 {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":["$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","useDateFormatter","options","lastOptions","useRef","current","isEqual","DateFormatter","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":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { NumberFormatter } from "@internationalized/number";
|
|
3
|
+
import { DateFormatter } from "@internationalized/date";
|
|
3
4
|
import { MessageDictionary, MessageFormatter } from "@internationalized/message";
|
|
4
5
|
import { useIsSSR } from "@react-aria/ssr";
|
|
5
|
-
import _react, { useEffect, useState, useContext, useCallback, useMemo } from "react";
|
|
6
|
+
import _react, { useEffect, useState, useContext, useCallback, useMemo, useRef } from "react";
|
|
6
7
|
|
|
7
8
|
/*
|
|
8
9
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -93,7 +94,7 @@ function $e851d0b81d46abd5f971c8e95c27f1$export$useDefaultLocale() {
|
|
|
93
94
|
return defaultLocale;
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
const $cff8541df3b5c83067b2ab3ee0d20$var$I18nContext = _react.createContext(null);
|
|
97
|
+
const $cff8541df3b5c83067b2ab3ee0d20$var$I18nContext = /*#__PURE__*/_react.createContext(null);
|
|
97
98
|
|
|
98
99
|
export function I18nProvider(props) {
|
|
99
100
|
let {
|
|
@@ -145,26 +146,46 @@ export function useMessageFormatter(strings) {
|
|
|
145
146
|
let formatter = useMemo(() => new MessageFormatter(locale, dictionary), [locale, dictionary]);
|
|
146
147
|
return useCallback((key, variables) => formatter.format(key, variables), [formatter]);
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
+
|
|
149
150
|
/**
|
|
150
151
|
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
|
|
151
152
|
* and handles caching of the date formatter for performance.
|
|
152
153
|
* @param options - Formatting options.
|
|
153
154
|
*/
|
|
154
|
-
|
|
155
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;
|
|
156
164
|
let {
|
|
157
165
|
locale
|
|
158
166
|
} = useLocale();
|
|
159
|
-
|
|
167
|
+
return useMemo(() => new DateFormatter(locale, options), [locale, options]);
|
|
168
|
+
}
|
|
160
169
|
|
|
161
|
-
|
|
162
|
-
|
|
170
|
+
function $b0007c63a64054c318efb8b6cd0053f$var$isEqual(a, b) {
|
|
171
|
+
if (a === b) {
|
|
172
|
+
return true;
|
|
163
173
|
}
|
|
164
174
|
|
|
165
|
-
let
|
|
166
|
-
|
|
167
|
-
|
|
175
|
+
let aKeys = Object.keys(a);
|
|
176
|
+
let bKeys = Object.keys(b);
|
|
177
|
+
|
|
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;
|
|
168
189
|
}
|
|
169
190
|
|
|
170
191
|
/**
|
package/dist/module.js.map
CHANGED
|
@@ -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,GAAGN,MAAM,CAACO,KAAP,CAAa,GAAb,EAAkB,CAAlB,CAA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C,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 {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 {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","formatterCache","Map","useDateFormatter","options","cacheKey","Object","entries","sort","a","b","join","DateTimeFormat","useNumberFormatter","NumberFormatter","useCollator","Collator","useFilter","collator","usage","startsWith","string","substring","length","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,CAUpC;;;AACA,MAAIG,IAAI,GAAGN,MAAM,CAACO,KAAP,CAAa,GAAb,EAAkB,CAAlB,CAAX;AACA,SAAOT,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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,6 +1,7 @@
|
|
|
1
1
|
import { Direction } from "@react-types/shared";
|
|
2
2
|
import { ReactNode } from "react";
|
|
3
3
|
import { LocalizedStrings } from "@internationalized/message";
|
|
4
|
+
import { DateFormatter } from "@internationalized/date";
|
|
4
5
|
import { NumberFormatOptions } from "@internationalized/number";
|
|
5
6
|
interface Locale {
|
|
6
7
|
/** The [BCP47](https://www.ietf.org/rfc/bcp/bcp47.txt) language code for the locale. */
|
|
@@ -31,12 +32,15 @@ type FormatMessage = (key: string, variables?: {
|
|
|
31
32
|
* @param strings - A mapping of languages to strings by key.
|
|
32
33
|
*/
|
|
33
34
|
export function useMessageFormatter(strings: LocalizedStrings): FormatMessage;
|
|
35
|
+
interface DateFormatterOptions extends Intl.DateTimeFormatOptions {
|
|
36
|
+
calendar?: string;
|
|
37
|
+
}
|
|
34
38
|
/**
|
|
35
39
|
* Provides localized date formatting for the current locale. Automatically updates when the locale changes,
|
|
36
40
|
* and handles caching of the date formatter for performance.
|
|
37
41
|
* @param options - Formatting options.
|
|
38
42
|
*/
|
|
39
|
-
export function useDateFormatter(options?:
|
|
43
|
+
export function useDateFormatter(options?: DateFormatterOptions): DateFormatter;
|
|
40
44
|
/**
|
|
41
45
|
* Provides localized number formatting for the current locale. Automatically updates when the locale changes,
|
|
42
46
|
* and handles caching of the number formatter for performance.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"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;A;A;A;GAIG;AACH,iCAAiC,OAAO,CAAC,EAAE,
|
|
1
|
+
{"mappings":"A;A;A;A;A;ACiBA;IACE,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,EAAE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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.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@internationalized/
|
|
22
|
-
"@internationalized/
|
|
23
|
-
"@
|
|
24
|
-
"@react-aria/
|
|
25
|
-
"@react-
|
|
21
|
+
"@internationalized/date": "3.0.0-alpha.1",
|
|
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"
|
|
26
27
|
},
|
|
27
28
|
"peerDependencies": {
|
|
28
29
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -30,5 +31,5 @@
|
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "16fc29ac722793ffaea083f13760d82ab341cc8d"
|
|
34
35
|
}
|
package/src/useDateFormatter.ts
CHANGED
|
@@ -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
|
-
|
|
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?:
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
50
|
+
for (let key of aKeys) {
|
|
51
|
+
if (b[key] !== a[key]) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
28
54
|
}
|
|
29
55
|
|
|
30
|
-
|
|
31
|
-
formatterCache.set(cacheKey, formatter);
|
|
32
|
-
return formatter;
|
|
56
|
+
return true;
|
|
33
57
|
}
|