@inshapardaz/likhari-react 0.1.21-dev.199 → 0.1.21-dev.200
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAQjF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;IAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,QA2DhI"}
|
|
@@ -6,6 +6,7 @@ import { loadAutoCorrections } from './autoCorrectStores.js';
|
|
|
6
6
|
/** Keys that end a word: a space or punctuation, in Latin and Arabic-script forms. */
|
|
7
7
|
const BOUNDARY_KEYS = new Set([' ', '.', ',', ';', ':', '!', '?', '،', '؛', '؟', '۔']);
|
|
8
8
|
const LANGUAGES = ['en', 'ur', 'pa-shahmukhi'];
|
|
9
|
+
const RTL_LANGUAGES = ['ur', 'pa-shahmukhi'];
|
|
9
10
|
/**
|
|
10
11
|
* Corrects typed words as the user finishes them, the way the reference editor
|
|
11
12
|
* does, but from any set of stores. Corrections are loaded once per change
|
|
@@ -16,6 +17,7 @@ const LANGUAGES = ['en', 'ur', 'pa-shahmukhi'];
|
|
|
16
17
|
export function AutoCorrectPlugin({ stores, version, enabled }) {
|
|
17
18
|
const [editor] = useLexicalComposerContext();
|
|
18
19
|
const tables = useRef(new Map());
|
|
20
|
+
const rtlTable = useRef(new Map());
|
|
19
21
|
useEffect(() => {
|
|
20
22
|
if (!enabled)
|
|
21
23
|
return;
|
|
@@ -24,6 +26,14 @@ export function AutoCorrectPlugin({ stores, version, enabled }) {
|
|
|
24
26
|
if (!active)
|
|
25
27
|
return;
|
|
26
28
|
tables.current = new Map(loaded);
|
|
29
|
+
// Urdu and Shahmukhi share right-to-left blocks, so both apply there; Urdu wins a clash.
|
|
30
|
+
const combined = new Map();
|
|
31
|
+
for (const language of RTL_LANGUAGES) {
|
|
32
|
+
for (const [from, to] of tables.current.get(language) ?? [])
|
|
33
|
+
if (!combined.has(from))
|
|
34
|
+
combined.set(from, to);
|
|
35
|
+
}
|
|
36
|
+
rtlTable.current = combined;
|
|
27
37
|
});
|
|
28
38
|
return () => {
|
|
29
39
|
active = false;
|
|
@@ -32,10 +42,7 @@ export function AutoCorrectPlugin({ stores, version, enabled }) {
|
|
|
32
42
|
useEffect(() => {
|
|
33
43
|
if (!enabled)
|
|
34
44
|
return;
|
|
35
|
-
const tableFor = (rtl) =>
|
|
36
|
-
const language = rtl ? 'ur' : 'en';
|
|
37
|
-
return tables.current.get(language);
|
|
38
|
-
};
|
|
45
|
+
const tableFor = (rtl) => (rtl ? rtlTable.current : tables.current.get('en'));
|
|
39
46
|
const onKeyDown = (event) => {
|
|
40
47
|
if (event.isComposing || !BOUNDARY_KEYS.has(event.key))
|
|
41
48
|
return;
|