@inshapardaz/likhari-react 0.1.21-dev.204 → 0.1.21-dev.205

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":"AAEA,OAAO,EAA4E,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAExH,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,iBAAiB,EACjB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,kEAAkE;IAClE,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,QAwFA"}
1
+ {"version":3,"file":"AutoCorrectPlugin.d.ts","sourceRoot":"","sources":["../../src/autocorrect/AutoCorrectPlugin.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA4E,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAQxH,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,iBAAiB,EACjB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,mFAAmF;IACnF,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;IAC7C,kEAAkE;IAClE,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC,QA0FA"}
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
3
  import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
4
- import { $correctDocument, $correctPunctuationBeforeCaret, $correctPunctuationDocument, $correctWordBeforeCaret } from './autoCorrectActions.js';
4
+ import { $correctDocument, $correctPunctuationBeforeCaret, $correctPunctuationDocument, $correctWordBeforeCaret, $preservingSelection, } from './autoCorrectActions.js';
5
5
  import { activePunctuationRules } from './punctuationRules.js';
6
6
  import { loadAutoCorrections } from './autoCorrectStores.js';
7
7
  import { normalizeUrdu } from '../normalization/urduNormalize.js';
@@ -54,8 +54,10 @@ export function AutoCorrectPlugin({ stores, version, enabled, urduNormalization,
54
54
  return;
55
55
  return editor.registerCommand(CORRECT_DOCUMENT_COMMAND, () => {
56
56
  editor.update(() => {
57
- $correctPunctuationDocument(punctuationRules.current);
58
- $correctDocument(tables.current.get('en') ?? new Map(), rtlTable.current, normalizeRtl);
57
+ $preservingSelection(() => {
58
+ $correctPunctuationDocument(punctuationRules.current);
59
+ $correctDocument(tables.current.get('en') ?? new Map(), rtlTable.current, normalizeRtl);
60
+ });
59
61
  }, { discrete: true });
60
62
  return true;
61
63
  }, COMMAND_PRIORITY_EDITOR);
@@ -24,4 +24,10 @@ export declare function $correctPunctuationBeforeCaret(rules: PunctuationRule[])
24
24
  * Where two matches overlap, the longer one wins. Returns how many were applied.
25
25
  */
26
26
  export declare function $correctPunctuationDocument(rules: PunctuationRule[]): number;
27
+ /**
28
+ * Runs `change` and then puts the caret back where it was. Replacements move the
29
+ * selection onto each match they make, so a whole-document pass would otherwise
30
+ * leave the caret at the last match, or at the end of the document.
31
+ */
32
+ export declare function $preservingSelection(change: () => void): void;
27
33
  //# sourceMappingURL=autoCorrectActions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"autoCorrectActions.d.ts","sourceRoot":"","sources":["../../src/autocorrect/autoCorrectActions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAM1D;;;;;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,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GACtC,MAAM,CA8BR;AAQD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAqBhF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,CA2B5E"}
1
+ {"version":3,"file":"autoCorrectActions.d.ts","sourceRoot":"","sources":["../../src/autocorrect/autoCorrectActions.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAM1D;;;;;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,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GACtC,MAAM,CA8BR;AAQD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,OAAO,CAqBhF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,MAAM,CA2B5E;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,CAoB7D"}
@@ -1,4 +1,4 @@
1
- import { $getRoot, $getSelection, $isRangeSelection, $isTextNode } from 'lexical';
1
+ import { $createRangeSelection, $getNodeByKey, $getRoot, $getSelection, $isRangeSelection, $isTextNode, $setSelection, } from 'lexical';
2
2
  import { $locate, $replaceMatch, $textGroups } from '../find/findReplaceActions.js';
3
3
  import { wordsIn } from '../spellcheck/spellDictionaries.js';
4
4
  /** The part of a word that counts as word characters at its end. */
@@ -141,3 +141,28 @@ export function $correctPunctuationDocument(rules) {
141
141
  }
142
142
  return applied;
143
143
  }
144
+ /**
145
+ * Runs `change` and then puts the caret back where it was. Replacements move the
146
+ * selection onto each match they make, so a whole-document pass would otherwise
147
+ * leave the caret at the last match, or at the end of the document.
148
+ */
149
+ export function $preservingSelection(change) {
150
+ const before = $getSelection();
151
+ const saved = $isRangeSelection(before)
152
+ ? {
153
+ anchor: { key: before.anchor.key, offset: before.anchor.offset, type: before.anchor.type },
154
+ focus: { key: before.focus.key, offset: before.focus.offset, type: before.focus.type },
155
+ }
156
+ : null;
157
+ change();
158
+ if (!saved) {
159
+ $setSelection(null);
160
+ return;
161
+ }
162
+ if (!$getNodeByKey(saved.anchor.key) || !$getNodeByKey(saved.focus.key))
163
+ return;
164
+ const selection = $createRangeSelection();
165
+ selection.anchor.set(saved.anchor.key, saved.anchor.offset, saved.anchor.type);
166
+ selection.focus.set(saved.focus.key, saved.focus.offset, saved.focus.type);
167
+ $setSelection(selection);
168
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inshapardaz/likhari-react",
3
- "version": "0.1.21-dev.204",
3
+ "version": "0.1.21-dev.205",
4
4
  "description": "React implementation of the Likhari editor, built on @lexical/react.",
5
5
  "license": "MIT",
6
6
  "repository": {