@ezychat/web 0.1.62 → 0.1.63

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Settings → AI: the team-wide Fix English switch (on by default on a new install, off after an
3
+ * update with a note) and the team words. Spelling needs no AI connection; grammar does.
4
+ */
5
+ export declare function FixEnglishSection(): import("react").JSX.Element;
@@ -0,0 +1,48 @@
1
+ /** The team-wide switch and what the composer checks (any signed-in user may read it). */
2
+ export declare const fixEnglishKey: readonly ["fixEnglish", "status"];
3
+ export declare function useFixEnglishStatus(enabled?: boolean): import("@tanstack/react-query").UseQueryResult<{
4
+ enabled: boolean;
5
+ connected: boolean;
6
+ spelling: "on" | "off";
7
+ grammar: "unavailable" | "on" | "off" | "none";
8
+ upgraded: boolean;
9
+ }, Error>;
10
+ /** Team words and the Business context words: never marked as a spelling mistake. */
11
+ export declare const teamWordsKey: readonly ["fixEnglish", "words"];
12
+ export declare function useTeamWords(enabled?: boolean): import("@tanstack/react-query").UseQueryResult<{
13
+ words: {
14
+ word: string;
15
+ addedBy: string | null;
16
+ createdAt: number;
17
+ }[];
18
+ businessWords: string[];
19
+ }, Error>;
20
+ export declare function addTeamWord(word: string): Promise<{
21
+ words: {
22
+ word: string;
23
+ addedBy: string | null;
24
+ createdAt: number;
25
+ }[];
26
+ businessWords: string[];
27
+ }>;
28
+ export declare function removeTeamWord(word: string): Promise<{
29
+ words: {
30
+ word: string;
31
+ addedBy: string | null;
32
+ createdAt: number;
33
+ }[];
34
+ businessWords: string[];
35
+ }>;
36
+ /** The grammar marks for the draft, from the AI (nothing is sent or stored). */
37
+ export declare function fetchGrammar(jid: string, text: string, signal: AbortSignal): Promise<{
38
+ status: "checked";
39
+ issues: {
40
+ start: number;
41
+ end: number;
42
+ original: string;
43
+ replacement: string;
44
+ }[];
45
+ } | {
46
+ status: "skipped";
47
+ reason: "not_english" | "too_short";
48
+ }>;
@@ -495,6 +495,28 @@ export declare const enResources: {
495
495
  dropHint: string;
496
496
  dropBlocked: string;
497
497
  };
498
+ fixEnglish: {
499
+ spelling: string;
500
+ grammar: string;
501
+ unknown: string;
502
+ cardLabel: string;
503
+ ignore: string;
504
+ close: string;
505
+ remove: string;
506
+ looking: string;
507
+ addWord: string;
508
+ fixAll_one: string;
509
+ fixAll_other: string;
510
+ shortcut: string;
511
+ shortcutKey: string;
512
+ fixed_one: string;
513
+ fixed_other: string;
514
+ undo: string;
515
+ checking: string;
516
+ clean: string;
517
+ unavailable: string;
518
+ unavailableHint: string;
519
+ };
498
520
  };
499
521
  quickReplies: {
500
522
  title: string;
@@ -1461,6 +1483,26 @@ export declare const enResources: {
1461
1483
  uses: string;
1462
1484
  fact: string;
1463
1485
  };
1486
+ fixEnglish: {
1487
+ title: string;
1488
+ description: string;
1489
+ enable: string;
1490
+ cost: string;
1491
+ rules: string;
1492
+ noConnection: string;
1493
+ upgraded: string;
1494
+ wordsTitle: string;
1495
+ wordsHint: string;
1496
+ wordsAdd: string;
1497
+ wordsLabel: string;
1498
+ wordsPlaceholder: string;
1499
+ wordsEmpty: string;
1500
+ wordsAddedBy: string;
1501
+ wordsRemove: string;
1502
+ businessTitle_one: string;
1503
+ businessTitle_other: string;
1504
+ businessHint: string;
1505
+ };
1464
1506
  };
1465
1507
  resolveAll: {
1466
1508
  title: string;
@@ -1,5 +1,5 @@
1
1
  import type React from 'react';
2
- import { type QuickReply, type ReplyPhraseListItem } from '@ezychat/shared';
2
+ import { type QuickReply, type ReplyPhraseListItem, type FixEnglishStatus } from '@ezychat/shared';
3
3
  /** Lets the conversation hand files dropped anywhere on it to the composer. */
4
4
  export interface ComposerHandle {
5
5
  addFiles(files: readonly File[]): void;
@@ -47,5 +47,18 @@ export interface ComposerProps {
47
47
  /** The team's phrase list, matched on every key (docs/features/ai-phrase-dictionary). */
48
48
  phrases?: readonly ReplyPhraseListItem[];
49
49
  } | null;
50
+ /**
51
+ * Fix English (docs/features/grammar-fix/design.md): spelling and grammar marks in this chat
52
+ * (any chat type; null or a status with both checks off = nothing shown).
53
+ */
54
+ fixEnglish?: {
55
+ chatJid: string;
56
+ chatName: string;
57
+ status: FixEnglishStatus | undefined;
58
+ /** Team words and Business context words, lower case: never marked. */
59
+ teamWords: ReadonlySet<string>;
60
+ /** "Add to team words" on a word the dictionary does not know. */
61
+ onAddWord(word: string): Promise<unknown>;
62
+ } | null;
50
63
  }
51
- export declare function Composer({ quickReplies, onSend, onAttach, onVoiceNote, onTyping, confirmSend, disabled, placeholder, replyTo, onCancelReply, aiSuggest, ref, }: ComposerProps): React.JSX.Element;
64
+ export declare function Composer({ quickReplies, onSend, onAttach, onVoiceNote, onTyping, confirmSend, disabled, placeholder, replyTo, onCancelReply, aiSuggest, fixEnglish, ref, }: ComposerProps): React.JSX.Element;
@@ -0,0 +1,88 @@
1
+ import { type FixEnglishStatus } from '@ezychat/shared';
2
+ /**
3
+ * Fix English in the composer (docs/features/grammar-fix/design.md, confirmed mock
4
+ * docs/features/grammar-fix/mock): spelling marked at once from the dictionary in the browser,
5
+ * grammar from the AI after a pause, a card per word, Fix all with Undo.
6
+ */
7
+ /** One mark. `replacement` is what Fix all applies (null: choose in the card, or add the word). */
8
+ export interface FixIssue {
9
+ id: string;
10
+ kind: 'spelling' | 'grammar';
11
+ start: number;
12
+ end: number;
13
+ original: string;
14
+ /** Spelling: up to 3 suggestions (empty = not in the dictionary); grammar: its one fix. */
15
+ suggestions: string[];
16
+ replacement: string | null;
17
+ /** Spelling suggestions are still being looked up. */
18
+ pending?: boolean;
19
+ }
20
+ export type GrammarStatus = 'idle' | 'checking' | 'done' | 'skipped' | 'error';
21
+ /**
22
+ * Keeps marks in place while the teammate types: a mark the edit touched goes, marks after it move
23
+ * with the text. The next check brings back the real list.
24
+ */
25
+ export declare function shiftIssues<T extends {
26
+ start: number;
27
+ end: number;
28
+ }>(issues: T[], before: string, after: string): T[];
29
+ /** Applies the marks that have a fix (they never overlap); a mark whose text changed is skipped. */
30
+ export declare function applyFixes(text: string, issues: readonly FixIssue[], pick?: string): string;
31
+ export declare function useFixEnglish(text: string, { jid, status, chatName, teamWords, disabled, }: {
32
+ jid: string | null;
33
+ status: FixEnglishStatus | undefined;
34
+ chatName: string;
35
+ /** Team words and Business context words, lower case (`acceptedWords`). */
36
+ teamWords: ReadonlySet<string>;
37
+ disabled: boolean;
38
+ }): {
39
+ issues: FixIssue[];
40
+ fixable: FixIssue[];
41
+ grammarStatus: GrammarStatus;
42
+ ignore(issue: FixIssue): void;
43
+ };
44
+ /**
45
+ * The underlines: a copy of the text behind the box's transparent glyphs, like the grey completion.
46
+ * `text-transparent`, not `invisible` (that would hide the underline). One-letter marks also get a
47
+ * light tint, so "i" or "a" is easy to see.
48
+ */
49
+ export declare const FixEnglishMarks: import("react").ForwardRefExoticComponent<{
50
+ text: string;
51
+ issues: readonly FixIssue[];
52
+ activeId: string | null;
53
+ } & import("react").RefAttributes<HTMLDivElement>>;
54
+ /**
55
+ * The card over one marked word: the fix (or up to 3 spelling choices) as buttons and Ignore; a
56
+ * word the dictionary does not know offers Add to team words instead.
57
+ */
58
+ export declare function FixEnglishCard({ issue, position, touch, onPick, onIgnore, onAddWord, onClose, onHover, }: {
59
+ issue: FixIssue;
60
+ /** Viewport coordinates: the word's left edge, and the distance from the word's top to the bottom. */
61
+ position: {
62
+ left: number;
63
+ bottom: number;
64
+ };
65
+ touch: boolean;
66
+ onPick(fix: string): void;
67
+ onIgnore(): void;
68
+ onAddWord(): void;
69
+ onClose(): void;
70
+ onHover(inside: boolean): void;
71
+ }): import("react").JSX.Element;
72
+ /**
73
+ * The composer row's status: "Fix 3" (every mark with a safe fix), the grammar check spinner, a
74
+ * quiet "No mistakes", "3 fixed · Undo" for a few seconds after Fix all, and a note while the AI
75
+ * grammar check is down (spelling keeps working: it needs no AI).
76
+ */
77
+ export declare function FixEnglishButton({ count, marks, grammarStatus, grammar, touch, undo, onFixAll, onUndo, }: {
78
+ count: number;
79
+ marks: number;
80
+ grammarStatus: GrammarStatus;
81
+ grammar: FixEnglishStatus['grammar'];
82
+ touch: boolean;
83
+ undo: {
84
+ count: number;
85
+ } | null;
86
+ onFixAll(): void;
87
+ onUndo(): void;
88
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import type { Speller } from './spelling';
2
+ /** One speller for the page; a failed download is tried again on the next call. */
3
+ export declare function loadSpeller(): Promise<Speller>;
4
+ /** Tests only: forget the loaded speller. */
5
+ export declare function resetSpellerForTests(): void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Fix English spelling (docs/features/grammar-fix/design.md): every word of the draft is checked in
3
+ * the browser against the British English Hunspell dictionary (`nspell`), with no AI and no server
4
+ * call. This file is the pure part (which words to mark, which fix is safe); `dictionary.ts` loads
5
+ * the dictionary and `useSpelling` runs it.
6
+ */
7
+ /** What the composer needs from the dictionary (`nspell` has both). */
8
+ export interface Speller {
9
+ correct(word: string): boolean;
10
+ suggest(word: string): string[];
11
+ }
12
+ /** One marked word. `replacement` is the safe fix for Fix all (null: choose in the card, or add). */
13
+ export interface SpellingIssue {
14
+ start: number;
15
+ end: number;
16
+ original: string;
17
+ /** Up to 3 suggestions, best first; empty = not in the dictionary (offer Add to team words). */
18
+ suggestions: string[];
19
+ replacement: string | null;
20
+ }
21
+ /**
22
+ * Chat short forms the dictionary has no good fix for. "i" alone is always "I"; short forms that
23
+ * are normal in Malaysian chat (ok, lah, ya, tq) are in LOCAL_WORDS and never marked.
24
+ */
25
+ export declare const SHORT_FORMS: Readonly<Record<string, string>>;
26
+ /**
27
+ * Words normal in Malaysian business chat that an English dictionary does not know: particles,
28
+ * food, places, payment and delivery services. Never marked. The team adds its own (team words),
29
+ * and every word of the Business context counts too.
30
+ */
31
+ export declare const LOCAL_WORDS: ReadonlySet<string>;
32
+ /** Damerau–Levenshtein distance (with one transposition), for "is this fix safe". */
33
+ export declare function editDistance(a: string, b: string): number;
34
+ /**
35
+ * The dictionary's suggestions re-ordered for typing slips: swapped letters first, then the
36
+ * closest, then the common word, then the dictionary's own order.
37
+ */
38
+ export declare function rankSuggestions(word: string, suggestions: readonly string[], speller?: Speller | null): string[];
39
+ /**
40
+ * The fix Fix all may apply without asking: the only suggestion, or a first one that is clearly
41
+ * better than the second (a swap of two letters against none, closer by an edit, or a common word
42
+ * against a rare one). Anything less sure is left for the teammate to choose in the card.
43
+ */
44
+ export declare function safeFix(word: string, ranked: readonly string[]): string | null;
45
+ /** Keeps the teammate's capital letter, and a capital at the start of a sentence. */
46
+ export declare function matchCase(original: string, fix: string, sentenceStart: boolean): string;
47
+ /** A word the checker found: where, and whether a capital is needed because a sentence starts. */
48
+ export interface MarkedWord {
49
+ start: number;
50
+ end: number;
51
+ /** The word exactly as typed (`text.slice(start, end)`). */
52
+ word: string;
53
+ sentenceStart: boolean;
54
+ /** A short form with its fix ("pls" → "please"); otherwise suggestions come from the dictionary. */
55
+ shortForm: string | null;
56
+ }
57
+ /** Links, email addresses, @mentions and #tags (whole space-separated tokens): never checked. */
58
+ export declare function skippedSpans(text: string): Array<[number, number]>;
59
+ /**
60
+ * The words to mark, at once on every key (`correct` only; suggestions are slower and come later).
61
+ * Not marked: the word still being typed, a word in a link/email/mention or next to a digit, an
62
+ * all-capitals word (RM, KLCC), a capitalised word inside a sentence (a name), and the accepted
63
+ * words (team words, Business context, the chat's name, LOCAL_WORDS).
64
+ */
65
+ export declare function findMisspelled(text: string, speller: Speller, accepted: ReadonlySet<string>): MarkedWord[];
66
+ /** A marked word with its suggestions (from `SHORT_FORMS` or the dictionary). */
67
+ export declare function toIssue(mark: MarkedWord, suggestions: readonly string[]): SpellingIssue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezychat/web",
3
- "version": "0.1.62",
3
+ "version": "0.1.63",
4
4
  "type": "module",
5
5
  "description": "EzyChat core: the team inbox web app (React) as a library, with createInboxApp and its extension API.",
6
6
  "license": "MIT",
@@ -40,7 +40,7 @@
40
40
  "build:lib": "node ../../scripts/build-web-lib.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@ezychat/shared": "0.1.62",
43
+ "@ezychat/shared": "0.1.63",
44
44
  "@fontsource-variable/inter": "^5.3.0",
45
45
  "@tanstack/react-query": "^5.104.5",
46
46
  "@types/react": "^19.3.0",
@@ -53,6 +53,7 @@
53
53
  "i18next": "^26.5.2",
54
54
  "lucide-react": "^1.59.0",
55
55
  "next-themes": "^0.4.6",
56
+ "nspell": "2.1.5",
56
57
  "opus-recorder": "8.0.5",
57
58
  "qrcode.react": "^4.2.0",
58
59
  "radix-ui": "^1.8.1",
@@ -72,7 +73,9 @@
72
73
  "@testing-library/jest-dom": "^7.0.1",
73
74
  "@testing-library/react": "^16.3.3",
74
75
  "@testing-library/user-event": "^14.6.8",
76
+ "@types/nspell": "2.1.6",
75
77
  "@vitejs/plugin-react": "^6.1.2",
78
+ "dictionary-en-gb": "3.0.0",
76
79
  "jsdom": "^30.1.3",
77
80
  "tailwindcss": "^4.3.3",
78
81
  "vite": "^8.3.5",