@@ -6,9 +6,9 @@ import { Plugin, PluginKey, Transaction } from "prosemirror-state";
6
6
import { Decoration , DecorationSet , EditorView } from "prosemirror-view" ;
7
7
8
8
import {
9
- LanguageToolOptions ,
10
- LanguageToolStorage ,
11
- LanguageToolResponse ,
9
+ GramrFixrOptions ,
10
+ GramrFixrStorage ,
11
+ GramrFixrResponse ,
12
12
Match ,
13
13
TextNodesWithPosition ,
14
14
Range ,
@@ -44,8 +44,9 @@ let match: Match | undefined | null = undefined;
44
44
let matchRange : Range | undefined | null ;
45
45
let proofReadInitially = false ;
46
46
let isLanguageToolActive = true ;
47
+ let lastOriginalFrom = 0 ;
47
48
48
- const db = new Dexie ( "LanguageToolIgnoredSuggestions " ) ;
49
+ const db = new Dexie ( "GramrFixrIgnoredSuggestions " ) ;
49
50
50
51
db . version ( 1 ) . stores ( {
51
52
ignoredWords : `
@@ -55,8 +56,8 @@ db.version(1).stores({
55
56
` ,
56
57
} ) ;
57
58
58
- export enum LanguageToolHelpingWords {
59
- LanguageToolTransactionName = "languageToolTransaction " ,
59
+ export enum GrammarCheckerOperations {
60
+ MainTransactionName = "grammarCheckerTransaction " ,
60
61
MatchUpdatedTransactionName = "matchUpdated" ,
61
62
MatchRangeUpdatedTransactionName = "matchRangeUpdated" ,
62
63
LoadingTransactionName = "languageToolLoading" ,
@@ -72,8 +73,8 @@ const updateMatchAndRange = (m?: Match, range?: Range) => {
72
73
else matchRange = undefined ;
73
74
74
75
const tr = editorView . state . tr ;
75
- tr . setMeta ( LanguageToolHelpingWords . MatchUpdatedTransactionName , true ) ;
76
- tr . setMeta ( LanguageToolHelpingWords . MatchRangeUpdatedTransactionName , true ) ;
76
+ tr . setMeta ( GrammarCheckerOperations . MatchUpdatedTransactionName , true ) ;
77
+ tr . setMeta ( GrammarCheckerOperations . MatchRangeUpdatedTransactionName , true ) ;
77
78
78
79
editorView . dispatch ( tr ) ;
79
80
} ;
@@ -142,7 +143,8 @@ export function changedDescendants(
142
143
143
144
const gimmeDecoration = ( from : number , to : number , match : Match ) =>
144
145
Decoration . inline ( from , to , {
145
- class : `lt lt-${ match . rule . issueType } ` ,
146
+ // class: `lt lt-${match.rule.issueType}`,
147
+ class : "lt lt-misspelling" ,
146
148
nodeName : "span" ,
147
149
match : JSON . stringify ( { match, from, to } ) ,
148
150
} ) ;
@@ -163,7 +165,7 @@ const getMatchAndSetDecorations = async (
163
165
body : `text=${ encodeURIComponent ( text ) } &language=en-US&enabledOnly=false` ,
164
166
} ;
165
167
166
- const ltRes : LanguageToolResponse = await (
168
+ const ltRes : GramrFixrResponse = await (
167
169
await fetch ( apiUrl , postOptions )
168
170
) . json ( ) ;
169
171
@@ -200,7 +202,7 @@ const getMatchAndSetDecorations = async (
200
202
if ( editorView )
201
203
dispatch (
202
204
editorView . state . tr . setMeta (
203
- LanguageToolHelpingWords . LanguageToolTransactionName ,
205
+ GrammarCheckerOperations . MainTransactionName ,
204
206
true
205
207
)
206
208
) ;
@@ -213,8 +215,6 @@ const debouncedGetMatchAndSetDecorations = debounce(
213
215
300
214
216
) ;
215
217
216
- let lastOriginalFrom = 0 ;
217
-
218
218
const onNodeChanged = ( doc : PMNode , text : string , originalFrom : number ) => {
219
219
if ( originalFrom !== lastOriginalFrom )
220
220
getMatchAndSetDecorations ( doc , text , originalFrom ) ;
@@ -308,15 +308,15 @@ const proofreadAndDecorateWholeDoc = async (doc: PMNode, nodePos = 0) => {
308
308
if ( editorView )
309
309
dispatch (
310
310
editorView . state . tr . setMeta (
311
- LanguageToolHelpingWords . LoadingTransactionName ,
311
+ GrammarCheckerOperations . LoadingTransactionName ,
312
312
true
313
313
)
314
314
) ;
315
315
Promise . all ( requests ) . then ( ( ) => {
316
316
if ( editorView )
317
317
dispatch (
318
318
editorView . state . tr . setMeta (
319
- LanguageToolHelpingWords . LoadingTransactionName ,
319
+ GrammarCheckerOperations . LoadingTransactionName ,
320
320
false
321
321
)
322
322
) ;
@@ -330,16 +330,12 @@ const debouncedProofreadAndDecorate = debounce(
330
330
500
331
331
) ;
332
332
333
- export const LanguageTool = Extension . create <
334
- LanguageToolOptions ,
335
- LanguageToolStorage
336
- > ( {
337
- name : "languagetool" ,
333
+ export const GramrFixr = Extension . create < GramrFixrOptions , GramrFixrStorage > ( {
334
+ name : "gramrfixr" ,
338
335
339
336
addOptions ( ) {
340
337
return {
341
- language : "auto" ,
342
- apiUrl : process ?. env ?. VUE_APP_LANGUAGE_TOOL_URL + "check" ,
338
+ apiUrl : "/api/grammar" ,
343
339
automaticMode : true ,
344
340
documentId : undefined ,
345
341
} ;
@@ -405,11 +401,11 @@ export const LanguageTool = Extension.create<
405
401
dispatch (
406
402
tr
407
403
. setMeta (
408
- LanguageToolHelpingWords . MatchRangeUpdatedTransactionName ,
404
+ GrammarCheckerOperations . MatchRangeUpdatedTransactionName ,
409
405
true
410
406
)
411
407
. setMeta (
412
- LanguageToolHelpingWords . MatchUpdatedTransactionName ,
408
+ GrammarCheckerOperations . MatchUpdatedTransactionName ,
413
409
true
414
410
)
415
411
) ;
@@ -441,7 +437,7 @@ export const LanguageTool = Extension.create<
441
437
442
438
return [
443
439
new Plugin ( {
444
- key : new PluginKey ( "languagetoolPlugin " ) ,
440
+ key : new PluginKey ( "gramrfixrPlugin " ) ,
445
441
props : {
446
442
decorations ( state ) {
447
443
return this . getState ( state ) ;
@@ -475,14 +471,14 @@ export const LanguageTool = Extension.create<
475
471
if ( ! isLanguageToolActive ) return DecorationSet . empty ;
476
472
477
473
const matchUpdated = tr . getMeta (
478
- LanguageToolHelpingWords . MatchUpdatedTransactionName
474
+ GrammarCheckerOperations . MatchUpdatedTransactionName
479
475
) ;
480
476
const matchRangeUpdated = tr . getMeta (
481
- LanguageToolHelpingWords . MatchRangeUpdatedTransactionName
477
+ GrammarCheckerOperations . MatchRangeUpdatedTransactionName
482
478
) ;
483
479
484
480
const loading = tr . getMeta (
485
- LanguageToolHelpingWords . LoadingTransactionName
481
+ GrammarCheckerOperations . LoadingTransactionName
486
482
) ;
487
483
488
484
if ( loading ) this . storage . loading = true ;
@@ -493,7 +489,7 @@ export const LanguageTool = Extension.create<
493
489
if ( matchRangeUpdated ) this . storage . matchRange = matchRange ;
494
490
495
491
const languageToolDecorations = tr . getMeta (
496
- LanguageToolHelpingWords . LanguageToolTransactionName
492
+ GrammarCheckerOperations . MainTransactionName
497
493
) ;
498
494
499
495
if ( languageToolDecorations ) return decorationSet ;
0 commit comments