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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 gchandru136
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # flowtext-editor
2
+
3
+ A reusable **Email Rich Text Editor** React component, packaged for distribution
4
+ via npm. Built with React + TypeScript and bundled with Vite in library mode.
5
+
6
+ The library ships one component — `FlowTextEditor` — a `contenteditable`
7
+ editor rendered inside an isolated iframe, with a formatting toolbar (bold,
8
+ lists, alignment, links, tables, …) and optional AI text tools.
9
+
10
+ ---
11
+
12
+ ## Requirements
13
+
14
+ - **Node.js** `>= 20.19` (see `engines` in `package.json`)
15
+ - **npm** `>= 10`
16
+
17
+ ## Quick start
18
+
19
+ ```bash
20
+ npm install
21
+ npm run dev
22
+ ```
23
+
24
+ `npm run dev` launches the playground at **http://localhost:5173** with hot reload.
25
+ Edit anything in `src/` and the preview updates instantly.
26
+
27
+ ## npm scripts
28
+
29
+ | Script | What it does |
30
+ | -------------------------- | ----------------------------------------------------------------- |
31
+ | `npm run dev` | Start the playground dev server (HMR). |
32
+ | `npm run build` | Type-check, then build the library (`dist/`) with `.d.ts` + maps. |
33
+ | `npm run build:playground` | Build the playground as a static site (for a shareable preview). |
34
+ | `npm run preview` | Preview the built playground locally. |
35
+ | `npm run typecheck` | Run TypeScript in no-emit mode over app + node projects. |
36
+ | `npm run lint` | Lint with ESLint (type-aware). |
37
+ | `npm run lint:fix` | Lint and auto-fix. |
38
+ | `npm run format` | Format the repo with Prettier. |
39
+ | `npm run format:check` | Verify formatting without writing. |
40
+ | `npm run clean` | Remove `dist/`. |
41
+
42
+ ## Project structure
43
+
44
+ ```
45
+ .
46
+ ├── src/ # Published library source
47
+ │ ├── components/ # React components (public API lives here)
48
+ │ ├── hooks/ # Reusable hooks
49
+ │ ├── utils/ # Framework-agnostic helpers
50
+ │ ├── styles/ # Design tokens + base CSS
51
+ │ ├── types/ # Shared public types
52
+ │ ├── assets/ # Static assets bundled with the library
53
+ │ └── index.ts # The single public entry point (barrel)
54
+
55
+ ├── playground/ # Local demo app — NEVER published
56
+ │ ├── src/ # Playground shell (Storybook-lite layout)
57
+ │ ├── index.html
58
+ │ └── vite.config.ts # Dev-server config (aliases the lib to source)
59
+
60
+ ├── vite.config.ts # Library build (Vite library mode)
61
+ ├── vite.aliases.ts # Shared path aliases (single source of truth)
62
+ ├── tsconfig*.json # Project-reference TS setup (base/app/node)
63
+ ├── eslint.config.js # ESLint flat config (type-aware)
64
+ └── .prettierrc.json
65
+ ```
66
+
67
+ ## How the playground consumes the library
68
+
69
+ The playground imports the library by its **public package name**:
70
+
71
+ ```ts
72
+ import { FlowTextEditor } from 'flowtext-editor';
73
+ ```
74
+
75
+ During development that name is aliased to `src/index.ts` (see
76
+ `playground/vite.config.ts`), so you get **instant HMR against source** while
77
+ still importing exactly the way an external consumer would. To smoke-test the
78
+ real built artifact instead, run `npm run build` and remove the package-name
79
+ alias.
80
+
81
+ ## Path aliases
82
+
83
+ Defined once in `vite.aliases.ts` and mirrored in `tsconfig.app.json`:
84
+
85
+ | Alias | Resolves to |
86
+ | --------------- | ------------------ |
87
+ | `@/*` | `src/*` |
88
+ | `@components/*` | `src/components/*` |
89
+ | `@hooks/*` | `src/hooks/*` |
90
+ | `@utils/*` | `src/utils/*` |
91
+ | `@styles/*` | `src/styles/*` |
92
+ | `@assets/*` | `src/assets/*` |
93
+
94
+ ## Package exports
95
+
96
+ Configured in `package.json` for modern, dual-format consumption:
97
+
98
+ ```jsonc
99
+ {
100
+ ".": {
101
+ "types": "./dist/index.d.ts",
102
+ "import": "./dist/index.js", // ESM
103
+ "require": "./dist/index.cjs", // CJS
104
+ },
105
+ "./styles.css": "./dist/flowtext-editor.css",
106
+ }
107
+ ```
108
+
109
+ - **Tree-shaking** — `"sideEffects": ["**/*.css"]` lets bundlers drop unused code
110
+ while preserving stylesheet imports.
111
+ - **Peer dependencies** — `react` / `react-dom` are peers (`^18 || ^19`); they are
112
+ never bundled into `dist`.
113
+
114
+ ## Usage
115
+
116
+ ```tsx
117
+ import { useState } from 'react';
118
+ import { FlowTextEditor } from 'flowtext-editor';
119
+ import type { AiTextActionHandler } from 'flowtext-editor';
120
+ import 'flowtext-editor/styles.css';
121
+
122
+ // The component is backend-agnostic: you wire the AI transport here.
123
+ const handleAiText: AiTextActionHandler = async ({ action, text, wordCount, toneType }) => {
124
+ const res = await fetch('/api/ai-text-tools', {
125
+ method: 'POST',
126
+ headers: { 'Content-Type': 'application/json' },
127
+ body: JSON.stringify({ action, text, wordCount, toneType }),
128
+ });
129
+ const data = await res.json();
130
+ return data.response ?? null;
131
+ };
132
+
133
+ export function Composer() {
134
+ const [content, setContent] = useState('<p>Hello!</p>');
135
+ return (
136
+ <FlowTextEditor
137
+ mailContent={content}
138
+ setMailContent={setContent}
139
+ onAiTextAction={handleAiText}
140
+ />
141
+ );
142
+ }
143
+ ```
144
+
145
+ ### Props
146
+
147
+ | Prop | Type | Default | Description |
148
+ | ----------------------- | --------------------------- | --------- | --------------------------------------------------------------- |
149
+ | `mailContent` | `string` | — | **Required.** Current HTML content (controlled). |
150
+ | `setMailContent` | `(content: string) => void` | — | **Required.** Called with the editor's HTML on every edit. |
151
+ | `showAiTools` | `boolean` | `true` | Show the AI toolbar. Requires `onAiTextAction`. |
152
+ | `onAiTextAction` | `AiTextActionHandler` | — | Handler powering the AI buttons. Omit to disable AI features. |
153
+ | `resetMailContent` | `boolean` | `false` | Toggle to force the editor to re-sync `mailContent`. |
154
+ | `spellcheckIgnoreWords` | `string[]` | `[]` | Words wrapped in `spellcheck="false"` spans (e.g. brand names). |
155
+ | `modalHeight` | `string` | `'650px'` | Height of the editor iframe (any CSS length). |
156
+
157
+ > **Styles:** import `flowtext-editor/styles.css` once in your app. The
158
+ > toolbar/editor inside the iframe are self-styled; the stylesheet themes the
159
+ > loading spinner and error toast (and exposes `--erte-*` design tokens).
160
+
161
+ ### Decoupling from the original component
162
+
163
+ The source component was adapted for reuse — behavior is unchanged, but
164
+ app-specific coupling was removed so the package stands alone:
165
+
166
+ - **AI backend** → injected via `onAiTextAction` (was a hard-coded `axios` call
167
+ to a `NEXT_PUBLIC_SERVER_API` endpoint).
168
+ - **Spellcheck exceptions** → now the `spellcheckIgnoreWords` prop (were
169
+ hard-coded product names).
170
+ - **Loader / toast** → small internal components (were app-local imports).
171
+ - **Icons** → inlined as SVG strings (Font Awesome 5 Free, MIT). The package has
172
+ **zero runtime dependencies** — only the `react` / `react-dom` peers.
173
+
174
+ ## Publishing (later)
175
+
176
+ Everything is prepared; when you're ready:
177
+
178
+ ```bash
179
+ npm run build # prepublishOnly also runs this automatically
180
+ npm publish
181
+ ```
182
+
183
+ ## License
184
+
185
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Library design tokens + base styles.
3
+ *
4
+ * Consumers opt in with: import 'flowtext-editor/styles.css';
5
+ * Everything is namespaced under `--erte-*` to avoid clashing with host apps.
6
+ */
7
+ :root {
8
+ --erte-font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
9
+ --erte-color-border: #4c6177;
10
+ --erte-color-accent: #d23f00;
11
+ --erte-color-primary: #0e4678;
12
+ --erte-color-surface: #ffffff;
13
+ --erte-color-muted: #f9f9f9;
14
+ --erte-radius: 4px;
15
+ --erte-spacing: 8px;
16
+ }
17
+
18
+ /* Loading overlay shown during AI requests. */
19
+ .erte-spinner-overlay {
20
+ position: fixed;
21
+ inset: 0;
22
+ display: flex;
23
+ align-items: center;
24
+ justify-content: center;
25
+ background: rgba(255, 255, 255, 0.6);
26
+ z-index: 10000;
27
+ }
28
+
29
+ .erte-spinner {
30
+ width: 40px;
31
+ height: 40px;
32
+ border: 4px solid #e6ecf1;
33
+ border-top-color: var(--erte-color-primary);
34
+ border-radius: 50%;
35
+ animation: erte-spin 0.8s linear infinite;
36
+ }
37
+
38
+ @keyframes erte-spin {
39
+ to {
40
+ transform: rotate(360deg);
41
+ }
42
+ }
43
+
44
+ /* Resizable editor frame gutters (grid tracks in the component, OUTSIDE the
45
+ iframe): right gutter = width resize, bottom bar = height resize, corner =
46
+ both. Layout/cursors are inline in the component so resizing works without
47
+ this stylesheet; this layer adds the frame look, grips, and states. */
48
+ .erte-resize-handle {
49
+ --erte-grip-color: #b6bec8;
50
+ background: #f7f8fa;
51
+ transition: background-color 0.15s ease;
52
+ }
53
+ .erte-resize-handle:hover {
54
+ --erte-grip-color: #8a93a0;
55
+ background: #eef0f3;
56
+ }
57
+ .erte-resize-handle.is-active {
58
+ --erte-grip-color: var(--erte-color-accent);
59
+ background: #e9ecef;
60
+ }
61
+
62
+ /* The bottom bar is the only visible resize element: a slim frame rail with
63
+ a soft divider and a faint inset shadow. Edge/corner resizing uses the
64
+ invisible `.erte-resize-zone` hit areas (cursor-only, no visuals). */
65
+ .erte-resize-handle--bottom {
66
+ border-top: 1px solid #e9ecef;
67
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
68
+ }
69
+
70
+ /* Bottom bar grip: three hairline horizontal lines, dead-centred. */
71
+ .erte-resize-handle--bottom::after {
72
+ content: '';
73
+ position: absolute;
74
+ top: 50%;
75
+ left: 50%;
76
+ transform: translate(-50%, -50%);
77
+ width: 14px;
78
+ height: 5px;
79
+ border-radius: 1px;
80
+ background: repeating-linear-gradient(
81
+ to bottom,
82
+ var(--erte-grip-color) 0 1px,
83
+ transparent 1px 2px
84
+ );
85
+ }
86
+
87
+ /* Transient error toast. */
88
+ .erte-toast {
89
+ position: fixed;
90
+ top: 20px;
91
+ left: 50%;
92
+ transform: translateX(-50%);
93
+ z-index: 10001;
94
+ padding: 10px 16px;
95
+ background: var(--erte-color-surface);
96
+ color: var(--erte-color-primary);
97
+ border: 1px solid var(--erte-color-primary);
98
+ border-radius: var(--erte-radius);
99
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
100
+ font-family: var(--erte-font-family);
101
+ font-size: 14px;
102
+ }