@consilioweb/spellcheck 0.10.1
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/LICENSE +21 -0
- package/README.md +567 -0
- package/dist/client.cjs +1711 -0
- package/dist/client.d.cts +77 -0
- package/dist/client.d.ts +77 -0
- package/dist/client.js +1702 -0
- package/dist/index.cjs +1691 -0
- package/dist/index.d.cts +268 -0
- package/dist/index.d.ts +268 -0
- package/dist/index.js +1677 -0
- package/dist/views.cjs +32 -0
- package/dist/views.d.cts +11 -0
- package/dist/views.d.ts +11 -0
- package/dist/views.js +30 -0
- package/package.json +102 -0
- package/scripts/debug-check.mjs +295 -0
- package/scripts/install.mjs +236 -0
- package/scripts/uninstall.mjs +350 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Plugin } from 'payload';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Spellcheck Plugin — Type definitions.
|
|
5
|
+
*/
|
|
6
|
+
interface SpellCheckIssue {
|
|
7
|
+
/** LanguageTool rule ID (e.g. 'GRAMMAR', 'MORFOLOGIK_RULE_FR') */
|
|
8
|
+
ruleId: string;
|
|
9
|
+
/** LanguageTool category (e.g. 'GRAMMAR', 'TYPOS') */
|
|
10
|
+
category: string;
|
|
11
|
+
/** Human-readable message explaining the issue */
|
|
12
|
+
message: string;
|
|
13
|
+
/** Text context around the error */
|
|
14
|
+
context: string;
|
|
15
|
+
/** Offset of the error within the context string */
|
|
16
|
+
contextOffset: number;
|
|
17
|
+
/** Offset within the full extracted text */
|
|
18
|
+
offset: number;
|
|
19
|
+
/** Length of the problematic text */
|
|
20
|
+
length: number;
|
|
21
|
+
/** The original (wrong) text */
|
|
22
|
+
original: string;
|
|
23
|
+
/** Suggested replacements (max 3) */
|
|
24
|
+
replacements: string[];
|
|
25
|
+
/** Source engine: 'languagetool' or 'claude' */
|
|
26
|
+
source: 'languagetool' | 'claude';
|
|
27
|
+
/** Whether this is a premium-only rule */
|
|
28
|
+
isPremium?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SpellCheckResult {
|
|
31
|
+
/** Document ID */
|
|
32
|
+
docId: string | number;
|
|
33
|
+
/** Collection slug */
|
|
34
|
+
collection: string;
|
|
35
|
+
/** Score 0-100 (100 = no issues) */
|
|
36
|
+
score: number;
|
|
37
|
+
/** Number of issues found */
|
|
38
|
+
issueCount: number;
|
|
39
|
+
/** Word count of the extracted text */
|
|
40
|
+
wordCount: number;
|
|
41
|
+
/** Detailed issues */
|
|
42
|
+
issues: SpellCheckIssue[];
|
|
43
|
+
/** ISO date of last check */
|
|
44
|
+
lastChecked: string;
|
|
45
|
+
}
|
|
46
|
+
interface SpellCheckPluginConfig {
|
|
47
|
+
/** Collections to check (default: ['pages', 'posts']) */
|
|
48
|
+
collections?: string[];
|
|
49
|
+
/** Rich text field name to extract content from (default: 'content') */
|
|
50
|
+
contentField?: string;
|
|
51
|
+
/** Language for LanguageTool (default: 'fr') */
|
|
52
|
+
language?: string;
|
|
53
|
+
/** Run spellcheck automatically on save (default: true) */
|
|
54
|
+
checkOnSave?: boolean;
|
|
55
|
+
/** Add sidebar field in the editor (default: true) */
|
|
56
|
+
addSidebarField?: boolean;
|
|
57
|
+
/** Add dashboard view at /admin/spellcheck (default: true) */
|
|
58
|
+
addDashboardView?: boolean;
|
|
59
|
+
/** Add score column in collection list views (default: true) */
|
|
60
|
+
addListColumn?: boolean;
|
|
61
|
+
/** Base path for API endpoints (default: '/spellcheck') */
|
|
62
|
+
endpointBasePath?: string;
|
|
63
|
+
/** Enable Claude AI as semantic fallback (default: false) */
|
|
64
|
+
enableAiFallback?: boolean;
|
|
65
|
+
/** Anthropic API key for Claude fallback */
|
|
66
|
+
anthropicApiKey?: string;
|
|
67
|
+
/** LanguageTool rule IDs to skip */
|
|
68
|
+
skipRules?: string[];
|
|
69
|
+
/** LanguageTool categories to skip */
|
|
70
|
+
skipCategories?: string[];
|
|
71
|
+
/** Custom dictionary — words to never flag */
|
|
72
|
+
customDictionary?: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Payload CMS Spellcheck Plugin.
|
|
77
|
+
*
|
|
78
|
+
* Adds spellchecking capabilities via LanguageTool + optional Claude AI:
|
|
79
|
+
* - Sidebar field in the editor (real-time spellcheck)
|
|
80
|
+
* - Dashboard view at /admin/spellcheck
|
|
81
|
+
* - API endpoints for validate, fix, bulk scan
|
|
82
|
+
* - afterChange hook for automatic checks on save
|
|
83
|
+
* - SpellCheckResults collection for storing results
|
|
84
|
+
*
|
|
85
|
+
* Usage:
|
|
86
|
+
* import { spellcheckPlugin } from '@consilioweb/spellcheck'
|
|
87
|
+
*
|
|
88
|
+
* export default buildConfig({
|
|
89
|
+
* plugins: [
|
|
90
|
+
* spellcheckPlugin({ collections: ['pages', 'posts'] }),
|
|
91
|
+
* ],
|
|
92
|
+
* })
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
declare const spellcheckPlugin: (pluginConfig?: SpellCheckPluginConfig) => Plugin;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Shared types and constants for Lexical text extraction.
|
|
99
|
+
* Used by both lexicalParser.ts (scan) and fix.ts (correction)
|
|
100
|
+
* to ensure identical traversal behavior.
|
|
101
|
+
*/
|
|
102
|
+
interface LexicalNode {
|
|
103
|
+
type?: string;
|
|
104
|
+
text?: string;
|
|
105
|
+
children?: LexicalNode[];
|
|
106
|
+
root?: LexicalNode;
|
|
107
|
+
tag?: string;
|
|
108
|
+
[key: string]: unknown;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Extract plain text from Lexical JSON nodes.
|
|
113
|
+
* Recursively traverses the Lexical AST, extracting text nodes
|
|
114
|
+
* and skipping code blocks.
|
|
115
|
+
*
|
|
116
|
+
* v0.9.8: Single source of truth for text extraction.
|
|
117
|
+
* extractAllTextFromDocWithSources() returns both the text AND source
|
|
118
|
+
* references, used by scan (validate/bulk) and fix endpoints.
|
|
119
|
+
* This eliminates offset divergence between scan and fix.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
interface TextSegment {
|
|
123
|
+
text: string;
|
|
124
|
+
source: {
|
|
125
|
+
type: 'title';
|
|
126
|
+
} | {
|
|
127
|
+
type: 'lexical';
|
|
128
|
+
data: LexicalNode;
|
|
129
|
+
topField: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: 'plain';
|
|
132
|
+
parent: Record<string, unknown>;
|
|
133
|
+
key: string;
|
|
134
|
+
topField: string;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
interface ExtractedDoc {
|
|
138
|
+
/** Full text sent to LanguageTool (segments joined by \n, trimmed) */
|
|
139
|
+
fullText: string;
|
|
140
|
+
/** Individual text segments with source references (for fix mutation) */
|
|
141
|
+
segments: TextSegment[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Extract all text from a document with source tracking.
|
|
145
|
+
* Single source of truth — used by scan (validate/bulk) and fix endpoints.
|
|
146
|
+
*/
|
|
147
|
+
declare function extractAllTextFromDocWithSources(doc: any, contentField?: string): ExtractedDoc;
|
|
148
|
+
/**
|
|
149
|
+
* Extract all plain text from a document (convenience wrapper).
|
|
150
|
+
* Delegates to extractAllTextFromDocWithSources for consistency.
|
|
151
|
+
*/
|
|
152
|
+
declare function extractAllTextFromDoc(doc: any, contentField?: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Extract all plain text from a Lexical JSON structure.
|
|
155
|
+
* Returns a single string with text nodes separated by newlines.
|
|
156
|
+
*/
|
|
157
|
+
declare function extractTextFromLexical(node: unknown, maxDepth?: number): string;
|
|
158
|
+
/**
|
|
159
|
+
* Count words in extracted text.
|
|
160
|
+
*/
|
|
161
|
+
declare function countWords(text: string): number;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* LanguageTool API client.
|
|
165
|
+
* Sends text to the public LanguageTool API and parses results into SpellCheckIssue[].
|
|
166
|
+
*
|
|
167
|
+
* Rate limit: max 1 request per 3 seconds on the free API.
|
|
168
|
+
* Max text length: 18,000 characters.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Check text with LanguageTool API.
|
|
173
|
+
* Returns raw SpellCheckIssue[] (before filtering).
|
|
174
|
+
*/
|
|
175
|
+
declare function checkWithLanguageTool(text: string, language: string, config: SpellCheckPluginConfig): Promise<SpellCheckIssue[]>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Claude AI semantic analysis (optional fallback).
|
|
179
|
+
* Checks for semantic coherence, tone consistency, and register issues.
|
|
180
|
+
* Does NOT check spelling/grammar (LanguageTool handles that).
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Check text with Claude API for semantic issues.
|
|
185
|
+
* Returns SpellCheckIssue[] with source='claude'.
|
|
186
|
+
*/
|
|
187
|
+
declare function checkWithClaude(text: string, language: string, apiKey: string): Promise<SpellCheckIssue[]>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Filter false positives from LanguageTool results.
|
|
191
|
+
* Removes premium rules, skipped rules/categories, and custom dictionary matches.
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Filter out false positives based on plugin configuration.
|
|
196
|
+
* Merges hardcoded customDictionary with dynamic DB dictionary words.
|
|
197
|
+
*/
|
|
198
|
+
declare function filterFalsePositives(issues: SpellCheckIssue[], config: SpellCheckPluginConfig, payload?: {
|
|
199
|
+
find: Function;
|
|
200
|
+
}): Promise<SpellCheckIssue[]>;
|
|
201
|
+
/**
|
|
202
|
+
* Calculate a spellcheck score (0-100) based on word count and issue count.
|
|
203
|
+
* 100 = no issues, decreases with each issue relative to word count.
|
|
204
|
+
*/
|
|
205
|
+
declare function calculateScore(wordCount: number, issueCount: number): number;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Dictionary endpoints — CRUD for the dynamic spellcheck dictionary.
|
|
209
|
+
* GET /api/spellcheck/dictionary — list all words
|
|
210
|
+
* POST /api/spellcheck/dictionary — add word(s)
|
|
211
|
+
* DELETE /api/spellcheck/dictionary — delete word(s) by id
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
declare function invalidateDictionaryCache(): void;
|
|
215
|
+
/**
|
|
216
|
+
* Load dictionary words from DB with in-memory cache.
|
|
217
|
+
* Returns lowercased word strings.
|
|
218
|
+
*/
|
|
219
|
+
declare function loadDictionaryWords(payload: {
|
|
220
|
+
find: Function;
|
|
221
|
+
}): Promise<string[]>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Spellcheck Plugin — i18n translations (FR/EN).
|
|
225
|
+
*/
|
|
226
|
+
type SpellcheckLocale = 'fr' | 'en';
|
|
227
|
+
interface SpellcheckTranslations {
|
|
228
|
+
dashboardTitle: string;
|
|
229
|
+
dashboardDescription: string;
|
|
230
|
+
scanAll: string;
|
|
231
|
+
scanning: string;
|
|
232
|
+
scanComplete: string;
|
|
233
|
+
noIssues: string;
|
|
234
|
+
issuesFound: (count: number) => string;
|
|
235
|
+
score: string;
|
|
236
|
+
wordCount: string;
|
|
237
|
+
lastChecked: string;
|
|
238
|
+
collection: string;
|
|
239
|
+
document: string;
|
|
240
|
+
issues: string;
|
|
241
|
+
actions: string;
|
|
242
|
+
fieldTitle: string;
|
|
243
|
+
fieldDescription: string;
|
|
244
|
+
checkNow: string;
|
|
245
|
+
checking: string;
|
|
246
|
+
fixAll: string;
|
|
247
|
+
fix: string;
|
|
248
|
+
ignore: string;
|
|
249
|
+
autoChecked: string;
|
|
250
|
+
suggestion: string;
|
|
251
|
+
noSuggestion: string;
|
|
252
|
+
context: string;
|
|
253
|
+
rule: string;
|
|
254
|
+
category: string;
|
|
255
|
+
applied: string;
|
|
256
|
+
source: string;
|
|
257
|
+
excellent: string;
|
|
258
|
+
good: string;
|
|
259
|
+
needsWork: string;
|
|
260
|
+
poor: string;
|
|
261
|
+
errorFetching: string;
|
|
262
|
+
errorFixing: string;
|
|
263
|
+
unauthorized: string;
|
|
264
|
+
}
|
|
265
|
+
declare function getTranslations(locale?: SpellcheckLocale): SpellcheckTranslations;
|
|
266
|
+
declare function getScoreLabel(score: number, t: SpellcheckTranslations): string;
|
|
267
|
+
|
|
268
|
+
export { type ExtractedDoc, type SpellCheckIssue, type SpellCheckPluginConfig, type SpellCheckResult, type SpellcheckLocale, type SpellcheckTranslations, type TextSegment, calculateScore, checkWithClaude, checkWithLanguageTool, countWords, extractAllTextFromDoc, extractAllTextFromDocWithSources, extractTextFromLexical, filterFalsePositives, getScoreLabel, getTranslations, invalidateDictionaryCache, loadDictionaryWords, spellcheckPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Plugin } from 'payload';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Spellcheck Plugin — Type definitions.
|
|
5
|
+
*/
|
|
6
|
+
interface SpellCheckIssue {
|
|
7
|
+
/** LanguageTool rule ID (e.g. 'GRAMMAR', 'MORFOLOGIK_RULE_FR') */
|
|
8
|
+
ruleId: string;
|
|
9
|
+
/** LanguageTool category (e.g. 'GRAMMAR', 'TYPOS') */
|
|
10
|
+
category: string;
|
|
11
|
+
/** Human-readable message explaining the issue */
|
|
12
|
+
message: string;
|
|
13
|
+
/** Text context around the error */
|
|
14
|
+
context: string;
|
|
15
|
+
/** Offset of the error within the context string */
|
|
16
|
+
contextOffset: number;
|
|
17
|
+
/** Offset within the full extracted text */
|
|
18
|
+
offset: number;
|
|
19
|
+
/** Length of the problematic text */
|
|
20
|
+
length: number;
|
|
21
|
+
/** The original (wrong) text */
|
|
22
|
+
original: string;
|
|
23
|
+
/** Suggested replacements (max 3) */
|
|
24
|
+
replacements: string[];
|
|
25
|
+
/** Source engine: 'languagetool' or 'claude' */
|
|
26
|
+
source: 'languagetool' | 'claude';
|
|
27
|
+
/** Whether this is a premium-only rule */
|
|
28
|
+
isPremium?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface SpellCheckResult {
|
|
31
|
+
/** Document ID */
|
|
32
|
+
docId: string | number;
|
|
33
|
+
/** Collection slug */
|
|
34
|
+
collection: string;
|
|
35
|
+
/** Score 0-100 (100 = no issues) */
|
|
36
|
+
score: number;
|
|
37
|
+
/** Number of issues found */
|
|
38
|
+
issueCount: number;
|
|
39
|
+
/** Word count of the extracted text */
|
|
40
|
+
wordCount: number;
|
|
41
|
+
/** Detailed issues */
|
|
42
|
+
issues: SpellCheckIssue[];
|
|
43
|
+
/** ISO date of last check */
|
|
44
|
+
lastChecked: string;
|
|
45
|
+
}
|
|
46
|
+
interface SpellCheckPluginConfig {
|
|
47
|
+
/** Collections to check (default: ['pages', 'posts']) */
|
|
48
|
+
collections?: string[];
|
|
49
|
+
/** Rich text field name to extract content from (default: 'content') */
|
|
50
|
+
contentField?: string;
|
|
51
|
+
/** Language for LanguageTool (default: 'fr') */
|
|
52
|
+
language?: string;
|
|
53
|
+
/** Run spellcheck automatically on save (default: true) */
|
|
54
|
+
checkOnSave?: boolean;
|
|
55
|
+
/** Add sidebar field in the editor (default: true) */
|
|
56
|
+
addSidebarField?: boolean;
|
|
57
|
+
/** Add dashboard view at /admin/spellcheck (default: true) */
|
|
58
|
+
addDashboardView?: boolean;
|
|
59
|
+
/** Add score column in collection list views (default: true) */
|
|
60
|
+
addListColumn?: boolean;
|
|
61
|
+
/** Base path for API endpoints (default: '/spellcheck') */
|
|
62
|
+
endpointBasePath?: string;
|
|
63
|
+
/** Enable Claude AI as semantic fallback (default: false) */
|
|
64
|
+
enableAiFallback?: boolean;
|
|
65
|
+
/** Anthropic API key for Claude fallback */
|
|
66
|
+
anthropicApiKey?: string;
|
|
67
|
+
/** LanguageTool rule IDs to skip */
|
|
68
|
+
skipRules?: string[];
|
|
69
|
+
/** LanguageTool categories to skip */
|
|
70
|
+
skipCategories?: string[];
|
|
71
|
+
/** Custom dictionary — words to never flag */
|
|
72
|
+
customDictionary?: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Payload CMS Spellcheck Plugin.
|
|
77
|
+
*
|
|
78
|
+
* Adds spellchecking capabilities via LanguageTool + optional Claude AI:
|
|
79
|
+
* - Sidebar field in the editor (real-time spellcheck)
|
|
80
|
+
* - Dashboard view at /admin/spellcheck
|
|
81
|
+
* - API endpoints for validate, fix, bulk scan
|
|
82
|
+
* - afterChange hook for automatic checks on save
|
|
83
|
+
* - SpellCheckResults collection for storing results
|
|
84
|
+
*
|
|
85
|
+
* Usage:
|
|
86
|
+
* import { spellcheckPlugin } from '@consilioweb/spellcheck'
|
|
87
|
+
*
|
|
88
|
+
* export default buildConfig({
|
|
89
|
+
* plugins: [
|
|
90
|
+
* spellcheckPlugin({ collections: ['pages', 'posts'] }),
|
|
91
|
+
* ],
|
|
92
|
+
* })
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
declare const spellcheckPlugin: (pluginConfig?: SpellCheckPluginConfig) => Plugin;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Shared types and constants for Lexical text extraction.
|
|
99
|
+
* Used by both lexicalParser.ts (scan) and fix.ts (correction)
|
|
100
|
+
* to ensure identical traversal behavior.
|
|
101
|
+
*/
|
|
102
|
+
interface LexicalNode {
|
|
103
|
+
type?: string;
|
|
104
|
+
text?: string;
|
|
105
|
+
children?: LexicalNode[];
|
|
106
|
+
root?: LexicalNode;
|
|
107
|
+
tag?: string;
|
|
108
|
+
[key: string]: unknown;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Extract plain text from Lexical JSON nodes.
|
|
113
|
+
* Recursively traverses the Lexical AST, extracting text nodes
|
|
114
|
+
* and skipping code blocks.
|
|
115
|
+
*
|
|
116
|
+
* v0.9.8: Single source of truth for text extraction.
|
|
117
|
+
* extractAllTextFromDocWithSources() returns both the text AND source
|
|
118
|
+
* references, used by scan (validate/bulk) and fix endpoints.
|
|
119
|
+
* This eliminates offset divergence between scan and fix.
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
interface TextSegment {
|
|
123
|
+
text: string;
|
|
124
|
+
source: {
|
|
125
|
+
type: 'title';
|
|
126
|
+
} | {
|
|
127
|
+
type: 'lexical';
|
|
128
|
+
data: LexicalNode;
|
|
129
|
+
topField: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: 'plain';
|
|
132
|
+
parent: Record<string, unknown>;
|
|
133
|
+
key: string;
|
|
134
|
+
topField: string;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
interface ExtractedDoc {
|
|
138
|
+
/** Full text sent to LanguageTool (segments joined by \n, trimmed) */
|
|
139
|
+
fullText: string;
|
|
140
|
+
/** Individual text segments with source references (for fix mutation) */
|
|
141
|
+
segments: TextSegment[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Extract all text from a document with source tracking.
|
|
145
|
+
* Single source of truth — used by scan (validate/bulk) and fix endpoints.
|
|
146
|
+
*/
|
|
147
|
+
declare function extractAllTextFromDocWithSources(doc: any, contentField?: string): ExtractedDoc;
|
|
148
|
+
/**
|
|
149
|
+
* Extract all plain text from a document (convenience wrapper).
|
|
150
|
+
* Delegates to extractAllTextFromDocWithSources for consistency.
|
|
151
|
+
*/
|
|
152
|
+
declare function extractAllTextFromDoc(doc: any, contentField?: string): string;
|
|
153
|
+
/**
|
|
154
|
+
* Extract all plain text from a Lexical JSON structure.
|
|
155
|
+
* Returns a single string with text nodes separated by newlines.
|
|
156
|
+
*/
|
|
157
|
+
declare function extractTextFromLexical(node: unknown, maxDepth?: number): string;
|
|
158
|
+
/**
|
|
159
|
+
* Count words in extracted text.
|
|
160
|
+
*/
|
|
161
|
+
declare function countWords(text: string): number;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* LanguageTool API client.
|
|
165
|
+
* Sends text to the public LanguageTool API and parses results into SpellCheckIssue[].
|
|
166
|
+
*
|
|
167
|
+
* Rate limit: max 1 request per 3 seconds on the free API.
|
|
168
|
+
* Max text length: 18,000 characters.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Check text with LanguageTool API.
|
|
173
|
+
* Returns raw SpellCheckIssue[] (before filtering).
|
|
174
|
+
*/
|
|
175
|
+
declare function checkWithLanguageTool(text: string, language: string, config: SpellCheckPluginConfig): Promise<SpellCheckIssue[]>;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Claude AI semantic analysis (optional fallback).
|
|
179
|
+
* Checks for semantic coherence, tone consistency, and register issues.
|
|
180
|
+
* Does NOT check spelling/grammar (LanguageTool handles that).
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Check text with Claude API for semantic issues.
|
|
185
|
+
* Returns SpellCheckIssue[] with source='claude'.
|
|
186
|
+
*/
|
|
187
|
+
declare function checkWithClaude(text: string, language: string, apiKey: string): Promise<SpellCheckIssue[]>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Filter false positives from LanguageTool results.
|
|
191
|
+
* Removes premium rules, skipped rules/categories, and custom dictionary matches.
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Filter out false positives based on plugin configuration.
|
|
196
|
+
* Merges hardcoded customDictionary with dynamic DB dictionary words.
|
|
197
|
+
*/
|
|
198
|
+
declare function filterFalsePositives(issues: SpellCheckIssue[], config: SpellCheckPluginConfig, payload?: {
|
|
199
|
+
find: Function;
|
|
200
|
+
}): Promise<SpellCheckIssue[]>;
|
|
201
|
+
/**
|
|
202
|
+
* Calculate a spellcheck score (0-100) based on word count and issue count.
|
|
203
|
+
* 100 = no issues, decreases with each issue relative to word count.
|
|
204
|
+
*/
|
|
205
|
+
declare function calculateScore(wordCount: number, issueCount: number): number;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Dictionary endpoints — CRUD for the dynamic spellcheck dictionary.
|
|
209
|
+
* GET /api/spellcheck/dictionary — list all words
|
|
210
|
+
* POST /api/spellcheck/dictionary — add word(s)
|
|
211
|
+
* DELETE /api/spellcheck/dictionary — delete word(s) by id
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
declare function invalidateDictionaryCache(): void;
|
|
215
|
+
/**
|
|
216
|
+
* Load dictionary words from DB with in-memory cache.
|
|
217
|
+
* Returns lowercased word strings.
|
|
218
|
+
*/
|
|
219
|
+
declare function loadDictionaryWords(payload: {
|
|
220
|
+
find: Function;
|
|
221
|
+
}): Promise<string[]>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Spellcheck Plugin — i18n translations (FR/EN).
|
|
225
|
+
*/
|
|
226
|
+
type SpellcheckLocale = 'fr' | 'en';
|
|
227
|
+
interface SpellcheckTranslations {
|
|
228
|
+
dashboardTitle: string;
|
|
229
|
+
dashboardDescription: string;
|
|
230
|
+
scanAll: string;
|
|
231
|
+
scanning: string;
|
|
232
|
+
scanComplete: string;
|
|
233
|
+
noIssues: string;
|
|
234
|
+
issuesFound: (count: number) => string;
|
|
235
|
+
score: string;
|
|
236
|
+
wordCount: string;
|
|
237
|
+
lastChecked: string;
|
|
238
|
+
collection: string;
|
|
239
|
+
document: string;
|
|
240
|
+
issues: string;
|
|
241
|
+
actions: string;
|
|
242
|
+
fieldTitle: string;
|
|
243
|
+
fieldDescription: string;
|
|
244
|
+
checkNow: string;
|
|
245
|
+
checking: string;
|
|
246
|
+
fixAll: string;
|
|
247
|
+
fix: string;
|
|
248
|
+
ignore: string;
|
|
249
|
+
autoChecked: string;
|
|
250
|
+
suggestion: string;
|
|
251
|
+
noSuggestion: string;
|
|
252
|
+
context: string;
|
|
253
|
+
rule: string;
|
|
254
|
+
category: string;
|
|
255
|
+
applied: string;
|
|
256
|
+
source: string;
|
|
257
|
+
excellent: string;
|
|
258
|
+
good: string;
|
|
259
|
+
needsWork: string;
|
|
260
|
+
poor: string;
|
|
261
|
+
errorFetching: string;
|
|
262
|
+
errorFixing: string;
|
|
263
|
+
unauthorized: string;
|
|
264
|
+
}
|
|
265
|
+
declare function getTranslations(locale?: SpellcheckLocale): SpellcheckTranslations;
|
|
266
|
+
declare function getScoreLabel(score: number, t: SpellcheckTranslations): string;
|
|
267
|
+
|
|
268
|
+
export { type ExtractedDoc, type SpellCheckIssue, type SpellCheckPluginConfig, type SpellCheckResult, type SpellcheckLocale, type SpellcheckTranslations, type TextSegment, calculateScore, checkWithClaude, checkWithLanguageTool, countWords, extractAllTextFromDoc, extractAllTextFromDocWithSources, extractTextFromLexical, filterFalsePositives, getScoreLabel, getTranslations, invalidateDictionaryCache, loadDictionaryWords, spellcheckPlugin };
|