@react-aria/i18n 3.10.2 → 3.11.0
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/context.main.js +48 -0
- package/dist/context.main.js.map +1 -0
- package/dist/context.mjs +38 -0
- package/dist/context.module.js +38 -0
- package/dist/context.module.js.map +1 -0
- package/dist/import.mjs +31 -6
- package/dist/main.js +45 -6
- package/dist/main.js.map +1 -0
- package/dist/module.js +31 -6
- package/dist/module.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useCollator.main.js +31 -0
- package/dist/useCollator.main.js.map +1 -0
- package/dist/useCollator.mjs +26 -0
- package/dist/useCollator.module.js +26 -0
- package/dist/useCollator.module.js.map +1 -0
- package/dist/useDateFormatter.main.js +47 -0
- package/dist/useDateFormatter.main.js.map +1 -0
- package/dist/useDateFormatter.mjs +42 -0
- package/dist/useDateFormatter.module.js +42 -0
- package/dist/useDateFormatter.module.js.map +1 -0
- package/dist/useDefaultLocale.main.js +68 -0
- package/dist/useDefaultLocale.main.js.map +1 -0
- package/dist/useDefaultLocale.mjs +63 -0
- package/dist/useDefaultLocale.module.js +63 -0
- package/dist/useDefaultLocale.module.js.map +1 -0
- package/dist/useFilter.main.js +72 -0
- package/dist/useFilter.main.js.map +1 -0
- package/dist/useFilter.mjs +67 -0
- package/dist/useFilter.module.js +67 -0
- package/dist/useFilter.module.js.map +1 -0
- package/dist/useListFormatter.main.js +31 -0
- package/dist/useListFormatter.main.js.map +1 -0
- package/dist/useListFormatter.mjs +26 -0
- package/dist/useListFormatter.module.js +26 -0
- package/dist/useListFormatter.module.js.map +1 -0
- package/dist/useLocalizedStringFormatter.main.js +47 -0
- package/dist/useLocalizedStringFormatter.main.js.map +1 -0
- package/dist/useLocalizedStringFormatter.mjs +41 -0
- package/dist/useLocalizedStringFormatter.module.js +41 -0
- package/dist/useLocalizedStringFormatter.module.js.map +1 -0
- package/dist/useMessageFormatter.main.js +48 -0
- package/dist/useMessageFormatter.main.js.map +1 -0
- package/dist/useMessageFormatter.mjs +43 -0
- package/dist/useMessageFormatter.module.js +28 -27
- package/dist/useMessageFormatter.module.js.map +1 -0
- package/dist/useNumberFormatter.main.js +33 -0
- package/dist/useNumberFormatter.main.js.map +1 -0
- package/dist/useNumberFormatter.mjs +28 -0
- package/dist/useNumberFormatter.module.js +28 -0
- package/dist/useNumberFormatter.module.js.map +1 -0
- package/dist/utils.main.js +71 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +66 -0
- package/dist/utils.module.js +66 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +11 -31
- package/src/index.ts +1 -0
- package/src/useMessageFormatter.ts +1 -1
- package/dist/real-main.js +0 -391
- package/dist/real-main.js.map +0 -1
- package/dist/real-module.js +0 -373
- package/dist/real-module.js.map +0 -1
- package/dist/real-module.mjs +0 -373
- package/dist/real-module.mjs.map +0 -1
- package/dist/useMessageFormatter.js +0 -52
- package/dist/useMessageFormatter.module.mjs +0 -42
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {LocalizedStrings, MessageDictionary, MessageFormatter} from '@internationalized/message';
|
|
14
14
|
import {useCallback, useMemo} from 'react';
|
|
15
|
-
import {useLocale} from '
|
|
15
|
+
import {useLocale} from './context';
|
|
16
16
|
|
|
17
17
|
export type FormatMessage = (key: string, variables?: {[key: string]: any}) => string;
|
|
18
18
|
|
package/dist/real-main.js
DELETED
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
var $87SwK$react = require("react");
|
|
2
|
-
var $87SwK$reactariassr = require("@react-aria/ssr");
|
|
3
|
-
var $87SwK$internationalizedstring = require("@internationalized/string");
|
|
4
|
-
var $87SwK$internationalizeddate = require("@internationalized/date");
|
|
5
|
-
var $87SwK$reactariautils = require("@react-aria/utils");
|
|
6
|
-
var $87SwK$internationalizednumber = require("@internationalized/number");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function $parcel$export(e, n, v, s) {
|
|
10
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function $parcel$interopDefault(a) {
|
|
14
|
-
return a && a.__esModule ? a.default : a;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
$parcel$export(module.exports, "I18nProvider", () => $47fa5ec5ff482271$export$a54013f0d02a8f82);
|
|
18
|
-
$parcel$export(module.exports, "useLocale", () => $47fa5ec5ff482271$export$43bb16f9c6d9e3f7);
|
|
19
|
-
$parcel$export(module.exports, "useMessageFormatter", () => $227f31f0c647c5fc$exports.useMessageFormatter);
|
|
20
|
-
$parcel$export(module.exports, "useLocalizedStringFormatter", () => $fc53663969a3d00a$export$f12b703ca79dfbb1);
|
|
21
|
-
$parcel$export(module.exports, "useLocalizedStringDictionary", () => $fc53663969a3d00a$export$87b761675e8eaa10);
|
|
22
|
-
$parcel$export(module.exports, "useListFormatter", () => $cb6a3e7d490e97a4$export$a2f47a3d2973640);
|
|
23
|
-
$parcel$export(module.exports, "useDateFormatter", () => $b80c530ff2e20243$export$85fd5fdf27bacc79);
|
|
24
|
-
$parcel$export(module.exports, "useNumberFormatter", () => $fea93c5b7c90d9f4$export$b7a616150fdb9f44);
|
|
25
|
-
$parcel$export(module.exports, "useCollator", () => $27a5ce66022270ad$export$a16aca283550c30d);
|
|
26
|
-
$parcel$export(module.exports, "useFilter", () => $832d079b867c7223$export$3274cf84b703fff);
|
|
27
|
-
/*
|
|
28
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
29
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
30
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
31
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
32
|
-
*
|
|
33
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
34
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
35
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
36
|
-
* governing permissions and limitations under the License.
|
|
37
|
-
*/ /*
|
|
38
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
39
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
40
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
41
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
42
|
-
*
|
|
43
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
44
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
45
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
46
|
-
* governing permissions and limitations under the License.
|
|
47
|
-
*/ /*
|
|
48
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
49
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
50
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
51
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
52
|
-
*
|
|
53
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
54
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
55
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
56
|
-
* governing permissions and limitations under the License.
|
|
57
|
-
*/ // https://en.wikipedia.org/wiki/Right-to-left
|
|
58
|
-
const $4d65847630a056a8$var$RTL_SCRIPTS = new Set([
|
|
59
|
-
"Arab",
|
|
60
|
-
"Syrc",
|
|
61
|
-
"Samr",
|
|
62
|
-
"Mand",
|
|
63
|
-
"Thaa",
|
|
64
|
-
"Mend",
|
|
65
|
-
"Nkoo",
|
|
66
|
-
"Adlm",
|
|
67
|
-
"Rohg",
|
|
68
|
-
"Hebr"
|
|
69
|
-
]);
|
|
70
|
-
const $4d65847630a056a8$var$RTL_LANGS = new Set([
|
|
71
|
-
"ae",
|
|
72
|
-
"ar",
|
|
73
|
-
"arc",
|
|
74
|
-
"bcc",
|
|
75
|
-
"bqi",
|
|
76
|
-
"ckb",
|
|
77
|
-
"dv",
|
|
78
|
-
"fa",
|
|
79
|
-
"glk",
|
|
80
|
-
"he",
|
|
81
|
-
"ku",
|
|
82
|
-
"mzn",
|
|
83
|
-
"nqo",
|
|
84
|
-
"pnb",
|
|
85
|
-
"ps",
|
|
86
|
-
"sd",
|
|
87
|
-
"ug",
|
|
88
|
-
"ur",
|
|
89
|
-
"yi"
|
|
90
|
-
]);
|
|
91
|
-
function $4d65847630a056a8$export$702d680b21cbd764(localeString) {
|
|
92
|
-
// If the Intl.Locale API is available, use it to get the locale's text direction.
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
if (Intl.Locale) {
|
|
95
|
-
let locale = new Intl.Locale(localeString).maximize();
|
|
96
|
-
// Use the text info object to get the direction if possible.
|
|
97
|
-
// @ts-ignore - this was implemented as a property by some browsers before it was standardized as a function.
|
|
98
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
|
|
99
|
-
let textInfo = typeof locale.getTextInfo === "function" ? locale.getTextInfo() : locale.textInfo;
|
|
100
|
-
if (textInfo) return textInfo.direction === "rtl";
|
|
101
|
-
// Fallback: guess using the script.
|
|
102
|
-
// This is more accurate than guessing by language, since languages can be written in multiple scripts.
|
|
103
|
-
if (locale.script) return $4d65847630a056a8$var$RTL_SCRIPTS.has(locale.script);
|
|
104
|
-
}
|
|
105
|
-
// If not, just guess by the language (first part of the locale)
|
|
106
|
-
let lang = localeString.split("-")[0];
|
|
107
|
-
return $4d65847630a056a8$var$RTL_LANGS.has(lang);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/*
|
|
112
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
113
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
114
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
115
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
116
|
-
*
|
|
117
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
118
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
119
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
120
|
-
* governing permissions and limitations under the License.
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// Locale passed from server by PackageLocalizationProvider.
|
|
125
|
-
const $2919bdec75484e64$var$localeSymbol = Symbol.for("react-aria.i18n.locale");
|
|
126
|
-
function $2919bdec75484e64$export$f09106e7c6677ec5() {
|
|
127
|
-
let locale = typeof window !== "undefined" && window[$2919bdec75484e64$var$localeSymbol] || typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
|
|
128
|
-
try {
|
|
129
|
-
// @ts-ignore
|
|
130
|
-
Intl.DateTimeFormat.supportedLocalesOf([
|
|
131
|
-
locale
|
|
132
|
-
]);
|
|
133
|
-
} catch (_err) {
|
|
134
|
-
locale = "en-US";
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
locale: locale,
|
|
138
|
-
direction: (0, $4d65847630a056a8$export$702d680b21cbd764)(locale) ? "rtl" : "ltr"
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
let $2919bdec75484e64$var$currentLocale = $2919bdec75484e64$export$f09106e7c6677ec5();
|
|
142
|
-
let $2919bdec75484e64$var$listeners = new Set();
|
|
143
|
-
function $2919bdec75484e64$var$updateLocale() {
|
|
144
|
-
$2919bdec75484e64$var$currentLocale = $2919bdec75484e64$export$f09106e7c6677ec5();
|
|
145
|
-
for (let listener of $2919bdec75484e64$var$listeners)listener($2919bdec75484e64$var$currentLocale);
|
|
146
|
-
}
|
|
147
|
-
function $2919bdec75484e64$export$188ec29ebc2bdc3a() {
|
|
148
|
-
let isSSR = (0, $87SwK$reactariassr.useIsSSR)();
|
|
149
|
-
let [defaultLocale, setDefaultLocale] = (0, $87SwK$react.useState)($2919bdec75484e64$var$currentLocale);
|
|
150
|
-
(0, $87SwK$react.useEffect)(()=>{
|
|
151
|
-
if ($2919bdec75484e64$var$listeners.size === 0) window.addEventListener("languagechange", $2919bdec75484e64$var$updateLocale);
|
|
152
|
-
$2919bdec75484e64$var$listeners.add(setDefaultLocale);
|
|
153
|
-
return ()=>{
|
|
154
|
-
$2919bdec75484e64$var$listeners.delete(setDefaultLocale);
|
|
155
|
-
if ($2919bdec75484e64$var$listeners.size === 0) window.removeEventListener("languagechange", $2919bdec75484e64$var$updateLocale);
|
|
156
|
-
};
|
|
157
|
-
}, []);
|
|
158
|
-
// We cannot determine the browser's language on the server, so default to
|
|
159
|
-
// en-US. This will be updated after hydration on the client to the correct value.
|
|
160
|
-
if (isSSR) return {
|
|
161
|
-
locale: "en-US",
|
|
162
|
-
direction: "ltr"
|
|
163
|
-
};
|
|
164
|
-
return defaultLocale;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const $47fa5ec5ff482271$var$I18nContext = /*#__PURE__*/ (0, ($parcel$interopDefault($87SwK$react))).createContext(null);
|
|
170
|
-
function $47fa5ec5ff482271$export$a54013f0d02a8f82(props) {
|
|
171
|
-
let { locale: locale, children: children } = props;
|
|
172
|
-
let defaultLocale = (0, $2919bdec75484e64$export$188ec29ebc2bdc3a)();
|
|
173
|
-
let value = locale ? {
|
|
174
|
-
locale: locale,
|
|
175
|
-
direction: (0, $4d65847630a056a8$export$702d680b21cbd764)(locale) ? "rtl" : "ltr"
|
|
176
|
-
} : defaultLocale;
|
|
177
|
-
return /*#__PURE__*/ (0, ($parcel$interopDefault($87SwK$react))).createElement($47fa5ec5ff482271$var$I18nContext.Provider, {
|
|
178
|
-
value: value
|
|
179
|
-
}, children);
|
|
180
|
-
}
|
|
181
|
-
function $47fa5ec5ff482271$export$43bb16f9c6d9e3f7() {
|
|
182
|
-
let defaultLocale = (0, $2919bdec75484e64$export$188ec29ebc2bdc3a)();
|
|
183
|
-
let context = (0, $87SwK$react.useContext)($47fa5ec5ff482271$var$I18nContext);
|
|
184
|
-
return context || defaultLocale;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var $227f31f0c647c5fc$exports = {};
|
|
189
|
-
"use strict";
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
/*
|
|
193
|
-
* Copyright 2022 Adobe. All rights reserved.
|
|
194
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
195
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
196
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
-
*
|
|
198
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
199
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
200
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
201
|
-
* governing permissions and limitations under the License.
|
|
202
|
-
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const $fc53663969a3d00a$var$cache = new WeakMap();
|
|
206
|
-
function $fc53663969a3d00a$var$getCachedDictionary(strings) {
|
|
207
|
-
let dictionary = $fc53663969a3d00a$var$cache.get(strings);
|
|
208
|
-
if (!dictionary) {
|
|
209
|
-
dictionary = new (0, $87SwK$internationalizedstring.LocalizedStringDictionary)(strings);
|
|
210
|
-
$fc53663969a3d00a$var$cache.set(strings, dictionary);
|
|
211
|
-
}
|
|
212
|
-
return dictionary;
|
|
213
|
-
}
|
|
214
|
-
function $fc53663969a3d00a$export$87b761675e8eaa10(strings, packageName) {
|
|
215
|
-
return packageName && (0, $87SwK$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage(packageName) || $fc53663969a3d00a$var$getCachedDictionary(strings);
|
|
216
|
-
}
|
|
217
|
-
function $fc53663969a3d00a$export$f12b703ca79dfbb1(strings, packageName) {
|
|
218
|
-
let { locale: locale } = (0, $47fa5ec5ff482271$export$43bb16f9c6d9e3f7)();
|
|
219
|
-
let dictionary = $fc53663969a3d00a$export$87b761675e8eaa10(strings, packageName);
|
|
220
|
-
return (0, $87SwK$react.useMemo)(()=>new (0, $87SwK$internationalizedstring.LocalizedStringFormatter)(locale, dictionary), [
|
|
221
|
-
locale,
|
|
222
|
-
dictionary
|
|
223
|
-
]);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
/*
|
|
228
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
229
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
230
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
231
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
232
|
-
*
|
|
233
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
234
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
235
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
236
|
-
* governing permissions and limitations under the License.
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
function $cb6a3e7d490e97a4$export$a2f47a3d2973640(options = {}) {
|
|
240
|
-
let { locale: locale } = (0, $47fa5ec5ff482271$export$43bb16f9c6d9e3f7)();
|
|
241
|
-
return (0, $87SwK$react.useMemo)(()=>new Intl.ListFormat(locale, options), [
|
|
242
|
-
locale,
|
|
243
|
-
options
|
|
244
|
-
]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
/*
|
|
249
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
250
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
251
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
252
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
253
|
-
*
|
|
254
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
255
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
256
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
257
|
-
* governing permissions and limitations under the License.
|
|
258
|
-
*/
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
function $b80c530ff2e20243$export$85fd5fdf27bacc79(options) {
|
|
263
|
-
// Reuse last options object if it is shallowly equal, which allows the useMemo result to also be reused.
|
|
264
|
-
options = (0, $87SwK$reactariautils.useDeepMemo)(options !== null && options !== void 0 ? options : {}, $b80c530ff2e20243$var$isEqual);
|
|
265
|
-
let { locale: locale } = (0, $47fa5ec5ff482271$export$43bb16f9c6d9e3f7)();
|
|
266
|
-
return (0, $87SwK$react.useMemo)(()=>new (0, $87SwK$internationalizeddate.DateFormatter)(locale, options), [
|
|
267
|
-
locale,
|
|
268
|
-
options
|
|
269
|
-
]);
|
|
270
|
-
}
|
|
271
|
-
function $b80c530ff2e20243$var$isEqual(a, b) {
|
|
272
|
-
if (a === b) return true;
|
|
273
|
-
let aKeys = Object.keys(a);
|
|
274
|
-
let bKeys = Object.keys(b);
|
|
275
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
276
|
-
for (let key of aKeys){
|
|
277
|
-
if (b[key] !== a[key]) return false;
|
|
278
|
-
}
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
/*
|
|
284
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
285
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
286
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
287
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
288
|
-
*
|
|
289
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
290
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
291
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
292
|
-
* governing permissions and limitations under the License.
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
function $fea93c5b7c90d9f4$export$b7a616150fdb9f44(options = {}) {
|
|
297
|
-
let { locale: locale } = (0, $47fa5ec5ff482271$export$43bb16f9c6d9e3f7)();
|
|
298
|
-
return (0, $87SwK$react.useMemo)(()=>new (0, $87SwK$internationalizednumber.NumberFormatter)(locale, options), [
|
|
299
|
-
locale,
|
|
300
|
-
options
|
|
301
|
-
]);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
/*
|
|
306
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
307
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
308
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
309
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
310
|
-
*
|
|
311
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
312
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
313
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
314
|
-
* governing permissions and limitations under the License.
|
|
315
|
-
*/
|
|
316
|
-
let $27a5ce66022270ad$var$cache = new Map();
|
|
317
|
-
function $27a5ce66022270ad$export$a16aca283550c30d(options) {
|
|
318
|
-
let { locale: locale } = (0, $47fa5ec5ff482271$export$43bb16f9c6d9e3f7)();
|
|
319
|
-
let cacheKey = locale + (options ? Object.entries(options).sort((a, b)=>a[0] < b[0] ? -1 : 1).join() : "");
|
|
320
|
-
if ($27a5ce66022270ad$var$cache.has(cacheKey)) return $27a5ce66022270ad$var$cache.get(cacheKey);
|
|
321
|
-
let formatter = new Intl.Collator(locale, options);
|
|
322
|
-
$27a5ce66022270ad$var$cache.set(cacheKey, formatter);
|
|
323
|
-
return formatter;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
/*
|
|
328
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
329
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
330
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
331
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
332
|
-
*
|
|
333
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
334
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
335
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
336
|
-
* governing permissions and limitations under the License.
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
function $832d079b867c7223$export$3274cf84b703fff(options) {
|
|
340
|
-
let collator = (0, $27a5ce66022270ad$export$a16aca283550c30d)({
|
|
341
|
-
usage: "search",
|
|
342
|
-
...options
|
|
343
|
-
});
|
|
344
|
-
// TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
345
|
-
let startsWith = (0, $87SwK$react.useCallback)((string, substring)=>{
|
|
346
|
-
if (substring.length === 0) return true;
|
|
347
|
-
// Normalize both strings so we can slice safely
|
|
348
|
-
// TODO: take into account the ignorePunctuation option as well...
|
|
349
|
-
string = string.normalize("NFC");
|
|
350
|
-
substring = substring.normalize("NFC");
|
|
351
|
-
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
352
|
-
}, [
|
|
353
|
-
collator
|
|
354
|
-
]);
|
|
355
|
-
let endsWith = (0, $87SwK$react.useCallback)((string, substring)=>{
|
|
356
|
-
if (substring.length === 0) return true;
|
|
357
|
-
string = string.normalize("NFC");
|
|
358
|
-
substring = substring.normalize("NFC");
|
|
359
|
-
return collator.compare(string.slice(-substring.length), substring) === 0;
|
|
360
|
-
}, [
|
|
361
|
-
collator
|
|
362
|
-
]);
|
|
363
|
-
let contains = (0, $87SwK$react.useCallback)((string, substring)=>{
|
|
364
|
-
if (substring.length === 0) return true;
|
|
365
|
-
string = string.normalize("NFC");
|
|
366
|
-
substring = substring.normalize("NFC");
|
|
367
|
-
let scan = 0;
|
|
368
|
-
let sliceLen = substring.length;
|
|
369
|
-
for(; scan + sliceLen <= string.length; scan++){
|
|
370
|
-
let slice = string.slice(scan, scan + sliceLen);
|
|
371
|
-
if (collator.compare(substring, slice) === 0) return true;
|
|
372
|
-
}
|
|
373
|
-
return false;
|
|
374
|
-
}, [
|
|
375
|
-
collator
|
|
376
|
-
]);
|
|
377
|
-
return (0, $87SwK$react.useMemo)(()=>({
|
|
378
|
-
startsWith: startsWith,
|
|
379
|
-
endsWith: endsWith,
|
|
380
|
-
contains: contains
|
|
381
|
-
}), [
|
|
382
|
-
startsWith,
|
|
383
|
-
endsWith,
|
|
384
|
-
contains
|
|
385
|
-
]);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
//# sourceMappingURL=real-main.js.map
|
package/dist/real-main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED,8CAA8C;AAC9C,MAAM,oCAAc,IAAI,IAAI;IAAC;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;IAAQ;CAAO;AAC5G,MAAM,kCAAY,IAAI,IAAI;IAAC;IAAM;IAAM;IAAO;IAAO;IAAO;IAAO;IAAM;IAAM;IAAO;IAAM;IAAM;IAAO;IAAO;IAAO;IAAM;IAAM;IAAM;IAAM;CAAK;AAK7I,SAAS,0CAAM,YAAoB;IACxC,kFAAkF;IAClF,aAAa;IACb,IAAI,KAAK,MAAM,EAAE;QACf,IAAI,SAAS,IAAI,KAAK,MAAM,CAAC,cAAc,QAAQ;QAEnD,6DAA6D;QAC7D,6GAA6G;QAC7G,2GAA2G;QAC3G,IAAI,WAAW,OAAO,OAAO,WAAW,KAAK,aAAa,OAAO,WAAW,KAAK,OAAO,QAAQ;QAChG,IAAI,UACF,OAA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CAAC,WAAW,WAAW,GACzC,OAAO;QAEX;QAEA,OAAO;IACT,GAAG;QAAC;KAAS;IAEb,OAAO,CAAA,GAAA,oBAAM,EAAE,IAAO,CAAA;wBACpB;sBACA;sBACA;QACF,CAAA,GAAI;QAAC;QAAY;QAAU;KAAS;AACtC;","sources":["packages/@react-aria/i18n/src/index.ts","packages/@react-aria/i18n/src/context.tsx","packages/@react-aria/i18n/src/utils.ts","packages/@react-aria/i18n/src/useDefaultLocale.ts","node_modules/@parcel/node-resolver-core/lib/_empty.js","packages/@react-aria/i18n/src/useLocalizedStringFormatter.ts","packages/@react-aria/i18n/src/useListFormatter.tsx","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\nexport {I18nProvider, useLocale} from './context';\nexport {useMessageFormatter} from './useMessageFormatter';\nexport {useLocalizedStringFormatter, useLocalizedStringDictionary} from './useLocalizedStringFormatter';\nexport {useListFormatter} from './useListFormatter';\nexport {useDateFormatter} from './useDateFormatter';\nexport {useNumberFormatter} from './useNumberFormatter';\nexport {useCollator} from './useCollator';\nexport {useFilter} from './useFilter';\n\nexport type {FormatMessage} from './useMessageFormatter';\nexport type {I18nProviderProps} from './context';\nexport type {Locale} from './useDefaultLocale';\nexport type {LocalizedStrings} from '@internationalized/message';\nexport type {DateFormatterOptions} from './useDateFormatter';\nexport type {DateFormatter} from '@internationalized/date';\nexport type {Filter} from './useFilter';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {isRTL} from './utils';\nimport {Locale, useDefaultLocale} from './useDefaultLocale';\nimport React, {ReactNode, useContext} from 'react';\n\nexport interface I18nProviderProps {\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>(null);\n\n/**\n * Provides the locale for the application to all child components.\n */\nexport function I18nProvider(props: I18nProviderProps) {\n let {locale, children} = props;\n let defaultLocale = useDefaultLocale();\n\n let value: Locale = locale ? {\n locale,\n direction: isRTL(locale) ? 'rtl' : 'ltr'\n } : defaultLocale;\n\n return (\n <I18nContext.Provider value={value}>\n {children}\n </I18nContext.Provider>\n );\n}\n\n/**\n * Returns the current locale and layout direction.\n */\nexport function useLocale(): Locale {\n let defaultLocale = useDefaultLocale();\n let context = useContext(I18nContext);\n return context || defaultLocale;\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// https://en.wikipedia.org/wiki/Right-to-left\nconst RTL_SCRIPTS = new Set(['Arab', 'Syrc', 'Samr', 'Mand', 'Thaa', 'Mend', 'Nkoo', 'Adlm', 'Rohg', 'Hebr']);\nconst RTL_LANGS = new Set(['ae', 'ar', 'arc', 'bcc', 'bqi', 'ckb', 'dv', 'fa', 'glk', 'he', 'ku', 'mzn', 'nqo', 'pnb', 'ps', 'sd', 'ug', 'ur', 'yi']);\n\n/**\n * Determines if a locale is read right to left using [Intl.Locale]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale}.\n */\nexport function isRTL(localeString: string) {\n // If the Intl.Locale API is available, use it to get the locale's text direction.\n // @ts-ignore\n if (Intl.Locale) {\n let locale = new Intl.Locale(localeString).maximize();\n\n // Use the text info object to get the direction if possible.\n // @ts-ignore - this was implemented as a property by some browsers before it was standardized as a function.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo\n let textInfo = typeof locale.getTextInfo === 'function' ? locale.getTextInfo() : locale.textInfo;\n if (textInfo) {\n return textInfo.direction === 'rtl';\n }\n\n // Fallback: guess using the script.\n // This is more accurate than guessing by language, since languages can be written in multiple scripts.\n if (locale.script) {\n return RTL_SCRIPTS.has(locale.script);\n }\n }\n\n // If not, just guess by the language (first part of the locale)\n let lang = localeString.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// Locale passed from server by PackageLocalizationProvider.\nconst localeSymbol = Symbol.for('react-aria.i18n.locale');\n\n/**\n * Gets the locale setting of the browser.\n */\nexport function getDefaultLocale(): Locale {\n let locale = typeof window !== 'undefined' && window[localeSymbol]\n // @ts-ignore\n || (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage))\n || 'en-US';\n\n try {\n // @ts-ignore\n Intl.DateTimeFormat.supportedLocalesOf([locale]);\n } catch (_err) {\n locale = 'en-US';\n }\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","\"use strict\";","/*\n * Copyright 2022 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 {LocalizedString, LocalizedStringDictionary, LocalizedStringFormatter, LocalizedStrings} from '@internationalized/string';\nimport {useLocale} from './context';\nimport {useMemo} from 'react';\n\nconst cache = new WeakMap();\nfunction getCachedDictionary<K extends string, T extends LocalizedString>(strings: LocalizedStrings<K, T>): LocalizedStringDictionary<K, T> {\n let dictionary = cache.get(strings);\n if (!dictionary) {\n dictionary = new LocalizedStringDictionary(strings);\n cache.set(strings, dictionary);\n }\n\n return dictionary;\n}\n\n/**\n * Returns a cached LocalizedStringDictionary for the given strings.\n */\nexport function useLocalizedStringDictionary<K extends string = string, T extends LocalizedString = string>(strings: LocalizedStrings<K, T>, packageName?: string): LocalizedStringDictionary<K, T> {\n return (packageName && LocalizedStringDictionary.getGlobalDictionaryForPackage(packageName)) || getCachedDictionary(strings);\n}\n\n/**\n * Provides localized string formatting for the current locale. Supports interpolating variables,\n * selecting the correct pluralization, and formatting numbers. Automatically updates when the locale changes.\n * @param strings - A mapping of languages to localized strings by key.\n */\nexport function useLocalizedStringFormatter<K extends string = string, T extends LocalizedString = string>(strings: LocalizedStrings<K, T>, packageName?: string): LocalizedStringFormatter<K, T> {\n let {locale} = useLocale();\n let dictionary = useLocalizedStringDictionary(strings, packageName);\n return useMemo(() => new LocalizedStringFormatter(locale, dictionary), [locale, dictionary]);\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';\nimport {useMemo} from 'react';\n\n/**\n * Provides localized list formatting for the current locale. Automatically updates when the locale changes,\n * and handles caching of the list formatter for performance.\n * @param options - Formatting options.\n */\nexport function useListFormatter(options: Intl.ListFormatOptions = {}): Intl.ListFormat {\n let {locale} = useLocale();\n return useMemo(() => new Intl.ListFormat(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 {DateFormatter} from '@internationalized/date';\nimport {useDeepMemo} from '@react-aria/utils';\nimport {useLocale} from './context';\nimport {useMemo} from 'react';\n\nexport interface 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 options = useDeepMemo(options ?? {}, isEqual);\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 {useCallback, useMemo} from 'react';\nimport {useCollator} from './useCollator';\n\nexport interface 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 let startsWith = useCallback((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 }, [collator]);\n\n let endsWith = useCallback((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 }, [collator]);\n\n let contains = useCallback((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 }, [collator]);\n\n return useMemo(() => ({\n startsWith,\n endsWith,\n contains\n }), [startsWith, endsWith, contains]);\n}\n"],"names":[],"version":3,"file":"real-main.js.map"}
|