dragble-react-editor 1.0.5 → 1.0.6
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/README.md +167 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
# dragble-react-editor
|
|
13
13
|
|
|
14
|
-
AI-powered React
|
|
14
|
+
The **fully AI-powered** React editor for **email templates** and **landing pages**. Your end-users design visually with drag-and-drop — or describe what they want and watch AI agents build it live on the canvas. Powered by the built-in **Model Context Protocol (MCP)** server, connect [Claude Code](https://claude.com/code), [OpenCode](https://opencode.ai), [Codex](https://github.com/openai/codex), [Cursor](https://cursor.com), or your own AI backend directly to the editor. Structured tool calls mean guaranteed-valid output — no prompt engineering, no JSON hallucination, no broken layouts.
|
|
15
15
|
|
|
16
|
-
[Dragble](https://dragble.com)
|
|
16
|
+
[Dragble](https://dragble.com) brings two design experiences together in one React component: a polished visual editor for designers and a conversational AI surface for everyone else — backed by structured tool calls that produce guaranteed-valid HTML emails and landing pages every time.
|
|
17
17
|
|
|
18
18
|
[Website](https://dragble.com) | [Documentation](https://docs.dragble.com) | [Dashboard](https://developers.dragble.com)
|
|
19
19
|
|
|
@@ -24,6 +24,7 @@ AI-powered React component for building **email templates** with drag-and-drop.
|
|
|
24
24
|
## Features
|
|
25
25
|
|
|
26
26
|
- Drag-and-drop **email template builder** with 20+ content blocks
|
|
27
|
+
- **Fully AI-powered via MCP** — connect AI agents (Claude Code, OpenCode, Codex, Cursor) or your own AI backend to build designs live on the canvas. Structured tool calls mean guaranteed-valid output — no prompt engineering, no JSON hallucination
|
|
27
28
|
- Responsive **HTML email** output compatible with all major email clients
|
|
28
29
|
- **Newsletter editor** with merge tags, dynamic content, and display conditions
|
|
29
30
|
- Visual **email designer** — no HTML/CSS knowledge required for end users
|
|
@@ -203,6 +204,170 @@ function AdvancedEmailBuilder() {
|
|
|
203
204
|
export default AdvancedEmailBuilder;
|
|
204
205
|
```
|
|
205
206
|
|
|
207
|
+
## MCP — AI Integration
|
|
208
|
+
|
|
209
|
+
Connect AI agents (Claude Code, OpenCode, Codex, Cursor, or your own backend) to the editor through the Model Context Protocol. The AI calls structured tools — `add_row`, `add_heading`, `update_button`, `export_html` — that mutate design state live on the canvas.
|
|
210
|
+
|
|
211
|
+
### Enabling MCP
|
|
212
|
+
|
|
213
|
+
MCP is off by default. Set `features: { mcp: true }` to opt in:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<DragbleEditor
|
|
217
|
+
ref={editorRef}
|
|
218
|
+
editorKey="db_pxl81cxn92wignwx"
|
|
219
|
+
options={{ features: { mcp: true } }}
|
|
220
|
+
/>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
MCP also requires a **Starter plan or higher**. Both conditions must be true — plan allows it AND SDK enables it.
|
|
224
|
+
|
|
225
|
+
### Quick example — your backend controls the AI
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import { useRef } from "react";
|
|
229
|
+
import { DragbleEditor, DragbleEditorRef } from "dragble-react-editor";
|
|
230
|
+
|
|
231
|
+
function App() {
|
|
232
|
+
const editorRef = useRef<DragbleEditorRef>(null);
|
|
233
|
+
|
|
234
|
+
const handleConnectAI = async () => {
|
|
235
|
+
// The id is YOUR identifier — derive it from your own database/session
|
|
236
|
+
// so the same user editing the same document always gets the same MCP
|
|
237
|
+
// session. Example: if your logged-in user is "alice123" and they're
|
|
238
|
+
// editing document "campaign-summer-2026", build an id like this:
|
|
239
|
+
//
|
|
240
|
+
// const id = "alice123-campaign-summer-2026";
|
|
241
|
+
//
|
|
242
|
+
// Format rules: 8-128 chars, only letters/digits/hyphens/underscores.
|
|
243
|
+
const userIdFromAuth = "alice123"; // from your auth/session
|
|
244
|
+
const docIdFromRoute = "campaign-summer"; // from your URL or DB row
|
|
245
|
+
const id = `${userIdFromAuth}-${docIdFromRoute}`;
|
|
246
|
+
const { sessionId } = await editorRef.current!.editor!.connectMCP({ id });
|
|
247
|
+
// Pass sessionId to your backend — it calls MCP tools with your mcp_key
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div style={{ height: "100vh" }}>
|
|
252
|
+
<button onClick={handleConnectAI}>Connect AI</button>
|
|
253
|
+
<DragbleEditor
|
|
254
|
+
ref={editorRef}
|
|
255
|
+
editorKey="db_pxl81cxn92wignwx"
|
|
256
|
+
options={{ features: { mcp: true } }}
|
|
257
|
+
/>
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Quick example — end-user pairs their own AI client
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
const handleLetUserPair = async () => {
|
|
267
|
+
const editor = editorRef.current!.editor!;
|
|
268
|
+
// Same id you'd use anywhere else for this user+document combination.
|
|
269
|
+
// 8-128 chars, only letters/digits/hyphens/underscores.
|
|
270
|
+
const id = "alice123-campaign-summer-2026";
|
|
271
|
+
await editor.connectMCP({ id });
|
|
272
|
+
|
|
273
|
+
// Explicitly generate a pairing code (not auto-generated)
|
|
274
|
+
const { code, expiresAt } = await editor.getPairingCode();
|
|
275
|
+
alert(`Paste this into Claude Code: ${code}`);
|
|
276
|
+
};
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### One controller per session
|
|
280
|
+
|
|
281
|
+
Each session can be controlled by **either** your backend **or** an end-user's AI client (OpenCode, Claude Code), never both at the same time:
|
|
282
|
+
|
|
283
|
+
- If your backend makes the first tool call → session is locked to **backend**. Pairing codes are rejected.
|
|
284
|
+
- If a user pairs via pairing code first → session is locked to **paired client**. Backend tool calls are rejected.
|
|
285
|
+
|
|
286
|
+
This prevents two AI controllers from conflicting on the same design.
|
|
287
|
+
|
|
288
|
+
### How it works
|
|
289
|
+
|
|
290
|
+
1. **Enable MCP** in the SDK config: `features: { mcp: true }`.
|
|
291
|
+
2. **Generate an MCP key** in the Dragble dashboard: Project → MCP Key → Generate. Store it in your backend env vars — never in browser code.
|
|
292
|
+
3. **Call `editor.connectMCP({ id })`** where `id` is a stable identifier you control (see below).
|
|
293
|
+
4. **Choose your AI path**: either your backend calls MCP tools directly (using the mcp_key), or you generate a pairing code for the end-user to connect their own AI client.
|
|
294
|
+
5. **Mutations stream live** onto the editor canvas as the AI works.
|
|
295
|
+
|
|
296
|
+
### The `id` parameter — why it matters
|
|
297
|
+
|
|
298
|
+
The `id` you pass to `connectMCP()` is a **Bring Your Own ID (BYOI)** that maps to your domain entities. It is NOT a random token — it is how Dragble identifies the session across browser refreshes, server restarts, and device switches.
|
|
299
|
+
|
|
300
|
+
**Rules:**
|
|
301
|
+
|
|
302
|
+
- 8–128 characters long
|
|
303
|
+
- Only letters, numbers, hyphens, and underscores (`a-z A-Z 0-9 - _`)
|
|
304
|
+
- Must be deterministic — the same user editing the same document should always produce the same `id`
|
|
305
|
+
|
|
306
|
+
**Why these rules?**
|
|
307
|
+
|
|
308
|
+
- The `id` is used in database lookups, URL paths, and R2 storage keys — special characters or extreme lengths would break routing
|
|
309
|
+
- Same `id` = resume the same session. Random UUIDs mean every page refresh creates a new session and loses AI context
|
|
310
|
+
- Short IDs (< 8 chars) are too easy to guess, long IDs (> 128 chars) waste storage
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
// Recommended: derive from your domain — concrete examples
|
|
314
|
+
editor.connectMCP({ id: "alice123-campaign-summer-2026" }); // user + doc
|
|
315
|
+
editor.connectMCP({ id: "workspace_acme_template_welcome" }); // workspace + template
|
|
316
|
+
editor.connectMCP({ id: "org-uber-eats-promo-q4-2026" }); // org + campaign
|
|
317
|
+
editor.connectMCP({ id: "tenant_42_invoice_template_v3" }); // tenant + entity
|
|
318
|
+
|
|
319
|
+
// Valid but NOT recommended — random IDs break session continuity
|
|
320
|
+
// (every page refresh creates a brand new session, AI loses context)
|
|
321
|
+
editor.connectMCP({ id: crypto.randomUUID() });
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Storage modes (compliance)
|
|
325
|
+
|
|
326
|
+
Choose how much of the session lives on Dragble's servers:
|
|
327
|
+
|
|
328
|
+
```tsx
|
|
329
|
+
editor.connectMCP({
|
|
330
|
+
id: "user-42-doc-99",
|
|
331
|
+
storage: "full", // default — best UX, refresh + cross-device resume
|
|
332
|
+
// "metadata-only" // audit metadata only, no design content persisted
|
|
333
|
+
// "memory-only" // nothing persisted (HIPAA / SOC2 / data residency)
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Disconnecting
|
|
338
|
+
|
|
339
|
+
`disconnectMCP()` permanently destroys the session — Dragble removes all session data from its servers and the session cannot be reopened:
|
|
340
|
+
|
|
341
|
+
```tsx
|
|
342
|
+
const { destroyed } = await editor.disconnectMCP();
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Your backend can also force-destroy a session server-side (e.g., when a user's subscription ends):
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
curl -X DELETE https://mcp.dragble.io/sessions/user-42-doc-99 \
|
|
349
|
+
-H "X-API-Key: db_mcp_your_key_here"
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Idle sessions are reaped after 2 hours of inactivity. Active sessions never expire — each tool call resets the timer.
|
|
353
|
+
|
|
354
|
+
### MCP method reference
|
|
355
|
+
|
|
356
|
+
| Method | Returns |
|
|
357
|
+
| -------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
358
|
+
| `editor.connectMCP({ id, storage?, editorMode? })` | `{ sessionId, storageMode?, resumed? }` |
|
|
359
|
+
| `editor.disconnectMCP()` | `{ destroyed }` — permanently deletes session |
|
|
360
|
+
| `editor.getPairingCode()` | `{ code, expiresAt }` — generate a pairing code for end-user AI clients |
|
|
361
|
+
| `editor.endPairing()` | `{ revoked }` — invalidate the active pairing code |
|
|
362
|
+
| `editor.getMCPStatus()` | `{ paired: true, sessionId } \| { paired: false, reason? }` |
|
|
363
|
+
| `editor.onAIToolFired(cb)` | unsubscribe fn — fires when AI calls any tool |
|
|
364
|
+
|
|
365
|
+
### Full documentation
|
|
366
|
+
|
|
367
|
+
- [MCP Overview](https://docs.dragble.com/mcp-server/overview)
|
|
368
|
+
- [Credentials & Security](https://docs.dragble.com/mcp-server/credentials)
|
|
369
|
+
- [AI Client Setup (OpenCode, Claude Code, Codex, etc.)](https://docs.dragble.com/mcp-server/ai-client-setup)
|
|
370
|
+
|
|
206
371
|
## Props
|
|
207
372
|
|
|
208
373
|
| Prop | Type | Required | Default | Description |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dragble-react-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "AI-powered React email editor component. Drag-and-drop email builder for creating responsive email templates and newsletters. Build HTML emails visually with Dragble.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|