@react-aria/i18n 3.6.2 → 3.7.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/import.mjs +6 -0
- package/dist/main.js +1 -1
- package/dist/real-main.js +201 -105
- package/dist/real-main.js.map +1 -1
- package/dist/real-module.js +202 -106
- package/dist/real-module.js.map +1 -1
- package/dist/real-module.mjs +367 -0
- package/dist/real-module.mjs.map +1 -0
- package/dist/types.d.ts +13 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/{useMessageFormatter.cjs.js → useMessageFormatter.js} +2 -2
- package/dist/useMessageFormatter.module.js +1 -1
- package/dist/useMessageFormatter.module.mjs +42 -0
- package/package.json +17 -12
- package/src/main.js +1 -1
- package/src/useFilter.ts +41 -35
- package/src/useMessageFormatter.ts +1 -1
package/src/useFilter.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import {useCallback, useMemo} from 'react';
|
|
13
14
|
import {useCollator} from './useCollator';
|
|
14
15
|
|
|
15
16
|
export interface Filter {
|
|
@@ -32,46 +33,51 @@ export function useFilter(options?: Intl.CollatorOptions): Filter {
|
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
// TODO(later): these methods don't currently support the ignorePunctuation option.
|
|
36
|
+
let startsWith = useCallback((string, substring) => {
|
|
37
|
+
if (substring.length === 0) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
// Normalize both strings so we can slice safely
|
|
42
|
+
// TODO: take into account the ignorePunctuation option as well...
|
|
43
|
+
string = string.normalize('NFC');
|
|
44
|
+
substring = substring.normalize('NFC');
|
|
45
|
+
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
46
|
+
}, [collator]);
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
47
|
-
},
|
|
48
|
-
endsWith(string, substring) {
|
|
49
|
-
if (substring.length === 0) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
48
|
+
let endsWith = useCallback((string, substring) => {
|
|
49
|
+
if (substring.length === 0) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
contains(string, substring) {
|
|
58
|
-
if (substring.length === 0) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
53
|
+
string = string.normalize('NFC');
|
|
54
|
+
substring = substring.normalize('NFC');
|
|
55
|
+
return collator.compare(string.slice(-substring.length), substring) === 0;
|
|
56
|
+
}, [collator]);
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
let contains = useCallback((string, substring) => {
|
|
59
|
+
if (substring.length === 0) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (; scan + sliceLen <= string.length; scan++) {
|
|
68
|
-
let slice = string.slice(scan, scan + sliceLen);
|
|
69
|
-
if (collator.compare(substring, slice) === 0) {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
63
|
+
string = string.normalize('NFC');
|
|
64
|
+
substring = substring.normalize('NFC');
|
|
73
65
|
|
|
74
|
-
|
|
66
|
+
let scan = 0;
|
|
67
|
+
let sliceLen = substring.length;
|
|
68
|
+
for (; scan + sliceLen <= string.length; scan++) {
|
|
69
|
+
let slice = string.slice(scan, scan + sliceLen);
|
|
70
|
+
if (collator.compare(substring, slice) === 0) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
75
73
|
}
|
|
76
|
-
|
|
74
|
+
|
|
75
|
+
return false;
|
|
76
|
+
}, [collator]);
|
|
77
|
+
|
|
78
|
+
return useMemo(() => ({
|
|
79
|
+
startsWith,
|
|
80
|
+
endsWith,
|
|
81
|
+
contains
|
|
82
|
+
}), [startsWith, endsWith, contains]);
|
|
77
83
|
}
|
|
@@ -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 '@react-aria/i18n';
|
|
16
16
|
|
|
17
17
|
export type FormatMessage = (key: string, variables?: {[key: string]: any}) => string;
|
|
18
18
|
|