flowtext-editor 0.1.0

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,87 @@
1
+ import { JSX } from 'react';
2
+ import { useEffect } from 'react';
3
+
4
+ /** AI text operations the editor's toolbar can request. */
5
+ export declare type AiTextAction = 'enhance' | 'proofread' | 'expand' | 'shorten' | 'changeTone';
6
+
7
+ /**
8
+ * Host-supplied handler that performs the AI transformation and resolves with
9
+ * the replacement text (or `null` to leave the selection unchanged).
10
+ *
11
+ * This is how the library stays backend-agnostic: the consumer wires their own
12
+ * API/transport here instead of the component hard-coding a request.
13
+ */
14
+ export declare type AiTextActionHandler = (payload: AiTextActionPayload) => Promise<string | null>;
15
+
16
+ /** Payload passed to the host-provided AI handler. */
17
+ export declare interface AiTextActionPayload {
18
+ /** Which operation to run. */
19
+ action: AiTextAction;
20
+ /** The currently selected text to transform. */
21
+ text: string;
22
+ /** Suggested target word count (used by `expand` / `shorten`), else `null`. */
23
+ wordCount: number | null;
24
+ /** Target tone (used by `changeTone`), else `null`. */
25
+ toneType: AiToneType | null;
26
+ }
27
+
28
+ /** Tone presets used by the `changeTone` action. */
29
+ export declare type AiToneType = 'friendly' | 'formal';
30
+
31
+ export declare type ClassValue = string | false | null | undefined;
32
+
33
+ /**
34
+ * Tiny, dependency-free className combiner. Filters out falsy values and
35
+ * joins the rest with a single space.
36
+ *
37
+ * @example
38
+ * cx('toolbar', isActive && 'toolbar--active', undefined); // 'toolbar toolbar--active'
39
+ */
40
+ export declare const cx: (...values: ClassValue[]) => string;
41
+
42
+ /**
43
+ * Escape a string so it can be embedded literally inside a `RegExp`.
44
+ *
45
+ * @example
46
+ * new RegExp(escapeRegExp('a.b')); // matches the literal "a.b", not "aXb"
47
+ */
48
+ export declare const escapeRegExp: (value: string) => string;
49
+
50
+ /**
51
+ * A self-contained rich-text editor rendered inside an isolated iframe, with a
52
+ * formatting toolbar and optional AI text tools. Content is controlled via
53
+ * `mailContent` / `setMailContent`.
54
+ */
55
+ export declare function FlowTextEditor({ mailContent, setMailContent, resetMailContent, showAiTools, modalHeight, spellcheckIgnoreWords, onAiTextAction, }: FlowTextEditorProps): JSX.Element;
56
+
57
+ export declare interface FlowTextEditorProps {
58
+ /** Current HTML content of the editor (controlled). */
59
+ mailContent: RichTextValue;
60
+ /** Called with the editor's HTML whenever the user edits it. */
61
+ setMailContent: (content: RichTextValue) => void;
62
+ /** Toggle to force the editor to re-sync `mailContent` (e.g. on reset). */
63
+ resetMailContent?: boolean;
64
+ /** Show the AI toolbar (Enhance, Proofread, …). Requires `onAiTextAction`. */
65
+ showAiTools?: boolean;
66
+ /** Height of the editor iframe (any CSS length). Defaults to `650px`. */
67
+ modalHeight?: string;
68
+ /** Words wrapped in `spellcheck="false"` spans (e.g. product/brand names). */
69
+ spellcheckIgnoreWords?: string[];
70
+ /** Handler invoked by the AI toolbar buttons. Omit to disable AI features. */
71
+ onAiTextAction?: AiTextActionHandler;
72
+ }
73
+
74
+ /**
75
+ * Serialized rich-text content, represented as an HTML string.
76
+ * This is the value the editor reads on input and emits on change.
77
+ */
78
+ export declare type RichTextValue = string;
79
+
80
+ /**
81
+ * `useLayoutEffect` that gracefully falls back to `useEffect` during
82
+ * server-side rendering, avoiding React's "useLayoutEffect does nothing on
83
+ * the server" warning. Behaves exactly like `useLayoutEffect` in the browser.
84
+ */
85
+ export declare const useIsomorphicLayoutEffect: typeof useEffect;
86
+
87
+ export { }