@inshapardaz/likhari-react 0.1.21-dev.211 → 0.1.21-dev.213
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/autocorrect/AutoCorrectPlugin.d.ts.map +1 -1
- package/dist/autocorrect/AutoCorrectPlugin.js +18 -2
- package/dist/autocorrect/autoCorrectActions.d.ts +6 -0
- package/dist/autocorrect/autoCorrectActions.d.ts.map +1 -1
- package/dist/autocorrect/autoCorrectActions.js +30 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,EAQL,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAWjB,OAAO,EAA0B,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAG9F,sFAAsF;AACtF,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,IAAI,CAA6C,CAAC;AAMxG;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,OAAO,EACP,OAAO,EACP,MAAM,EACN,iBAAiB,EACjB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,oFAAoF;IACpF,MAAM,EAAE,OAAO,CAAC;IAChB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,kEAAkE;IAClE,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,QA0GA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
-
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
|
|
4
|
-
import { $correctDocument, $correctPunctuationBeforeCaret, $correctPunctuationDocument, $correctWordBeforeCaret, $preservingSelection, $spacePunctuationDocument, } from './autoCorrectActions.js';
|
|
3
|
+
import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, BLUR_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ENTER_COMMAND, createCommand, } from 'lexical';
|
|
4
|
+
import { $correctDocument, $correctPunctuationBeforeCaret, $correctPunctuationDocument, $correctWordBeforeCaret, $correctWordEndingAtCaret, $preservingSelection, $spacePunctuationDocument, } from './autoCorrectActions.js';
|
|
5
5
|
import { $cleanUpText } from '../cleanup/textCleanupActions.js';
|
|
6
6
|
import { activePunctuationRules } from './punctuationRules.js';
|
|
7
7
|
import { loadAutoCorrections } from './autoCorrectStores.js';
|
|
@@ -99,8 +99,24 @@ export function AutoCorrectPlugin({ stores, version, enabled, typing, urduNormal
|
|
|
99
99
|
root?.addEventListener('keydown', onKeyDown);
|
|
100
100
|
};
|
|
101
101
|
const unregister = editor.registerRootListener((next) => attach(next));
|
|
102
|
+
// A word with nothing after it (end of line or document) is corrected when the
|
|
103
|
+
// caret leaves it: Enter splits the line, and blur means the user has moved on.
|
|
104
|
+
const correctEndingWord = () => {
|
|
105
|
+
const selection = $getSelection();
|
|
106
|
+
if (!$isRangeSelection(selection))
|
|
107
|
+
return false;
|
|
108
|
+
const rtl = selection.anchor.getNode().getTopLevelElement()?.getDirection() === 'rtl';
|
|
109
|
+
const table = tableFor(rtl);
|
|
110
|
+
if (table)
|
|
111
|
+
$correctWordEndingAtCaret(table, rtl ? normalizeRtl : undefined);
|
|
112
|
+
return false;
|
|
113
|
+
};
|
|
114
|
+
const unregisterEnter = editor.registerCommand(KEY_ENTER_COMMAND, correctEndingWord, COMMAND_PRIORITY_HIGH);
|
|
115
|
+
const unregisterBlur = editor.registerCommand(BLUR_COMMAND, correctEndingWord, COMMAND_PRIORITY_EDITOR);
|
|
102
116
|
return () => {
|
|
103
117
|
unregister();
|
|
118
|
+
unregisterEnter();
|
|
119
|
+
unregisterBlur();
|
|
104
120
|
attach(null);
|
|
105
121
|
};
|
|
106
122
|
}, [editor, enabled, typing]);
|
|
@@ -32,4 +32,10 @@ export declare function $correctPunctuationDocument(rules: PunctuationRule[]): n
|
|
|
32
32
|
export declare function $preservingSelection(change: () => void): void;
|
|
33
33
|
/** Applies urduhack-style punctuation spacing to every text node. Returns how many changed. */
|
|
34
34
|
export declare function $spacePunctuationDocument(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Corrects the word that ends at the caret when nothing follows it, which is the
|
|
37
|
+
* end of a line: the caret is about to leave the line (Enter). The caret ends
|
|
38
|
+
* after the replacement.
|
|
39
|
+
*/
|
|
40
|
+
export declare function $correctWordEndingAtCaret(table: Map<string, string>, normalize?: (word: string) => string): boolean;
|
|
35
41
|
//# sourceMappingURL=autoCorrectActions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoCorrectActions.d.ts","sourceRoot":"","sources":["../../src/autocorrect/autoCorrectActions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMhF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAiCjH;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE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;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,CAoB7D;AAED,+FAA+F;AAC/F,wBAAgB,yBAAyB,IAAI,MAAM,CAWlD;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAuBnH"}
|
|
@@ -180,3 +180,33 @@ export function $spacePunctuationDocument() {
|
|
|
180
180
|
}
|
|
181
181
|
return changed;
|
|
182
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Corrects the word that ends at the caret when nothing follows it, which is the
|
|
185
|
+
* end of a line: the caret is about to leave the line (Enter). The caret ends
|
|
186
|
+
* after the replacement.
|
|
187
|
+
*/
|
|
188
|
+
export function $correctWordEndingAtCaret(table, normalize) {
|
|
189
|
+
const selection = $getSelection();
|
|
190
|
+
if (!$isRangeSelection(selection) || !selection.isCollapsed())
|
|
191
|
+
return false;
|
|
192
|
+
const anchor = selection.anchor;
|
|
193
|
+
const node = anchor.getNode();
|
|
194
|
+
if (!$isTextNode(node))
|
|
195
|
+
return false;
|
|
196
|
+
const before = node.getTextContent().slice(0, anchor.offset);
|
|
197
|
+
const word = WORD_END.exec(before)?.[0];
|
|
198
|
+
if (!word)
|
|
199
|
+
return false;
|
|
200
|
+
const replacement = correctionFor(word, table, normalize);
|
|
201
|
+
if (replacement === undefined || replacement === word)
|
|
202
|
+
return false;
|
|
203
|
+
const start = before.length - word.length;
|
|
204
|
+
$replaceMatch({ anchorKey: node.getKey(), anchorOffset: start, focusKey: node.getKey(), focusOffset: before.length }, replacement);
|
|
205
|
+
const after = $getSelection();
|
|
206
|
+
if ($isRangeSelection(after)) {
|
|
207
|
+
const caret = start + replacement.length;
|
|
208
|
+
after.anchor.set(node.getKey(), caret, 'text');
|
|
209
|
+
after.focus.set(node.getKey(), caret, 'text');
|
|
210
|
+
}
|
|
211
|
+
return true;
|
|
212
|
+
}
|