@@ -52,23 +52,107 @@ For vanilla JS, React, Vue, Angular, or any framework — use the mount API:
5252<div bind:this={container} style="width: 100%; height: 600px;" />
5353```
5454
55- ### Vanilla JS
55+ ### Vanilla JS (with Vite)
56+
57+ FlowDrop works in any project that bundles ES modules. Here's a complete setup with Vite:
58+
59+ ** 1. Scaffold a project**
60+
61+ ``` bash
62+ npm create vite@latest my-flowdrop-app -- --template vanilla
63+ cd my-flowdrop-app
64+ npm install @flowdrop/flowdrop @iconify/svelte @xyflow/svelte svelte
65+ ```
66+
67+ ** 2. Configure Vite**
68+
69+ ``` javascript
70+ // vite.config.js
71+ import { defineConfig } from ' vite' ;
72+ import { svelte } from ' @sveltejs/vite-plugin-svelte' ;
73+
74+ export default defineConfig ({
75+ plugins: [svelte ()],
76+ optimizeDeps: {
77+ exclude: [' @flowdrop/flowdrop' , ' @xyflow/svelte' ]
78+ }
79+ });
80+ ```
81+
82+ You'll also need a minimal Svelte config:
5683
5784``` javascript
58- import { mountFlowDropApp , createEndpointConfig } from ' @flowdrop/flowdrop' ;
85+ // svelte.config.js
86+ export default {};
87+ ```
88+
89+ ** 3. Create the editor page**
90+
91+ ``` html
92+ <!-- index.html -->
93+ <!DOCTYPE html>
94+ <html lang =" en" >
95+ <head >
96+ <meta charset =" UTF-8" />
97+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
98+ <title >My Workflow Editor</title >
99+ <style >
100+ body { margin : 0 ; font-family : system-ui , sans-serif ; }
101+ #editor { width : 100vw ; height : 100vh ; }
102+ </style >
103+ </head >
104+ <body >
105+ <div id =" editor" ></div >
106+ <script type =" module" src =" /main.js" ></script >
107+ </body >
108+ </html >
109+ ```
110+
111+ ``` javascript
112+ // main.js
113+ import { mountFlowDropApp } from ' @flowdrop/flowdrop/editor' ;
114+ import { createEndpointConfig } from ' @flowdrop/flowdrop/core' ;
59115import ' @flowdrop/flowdrop/styles' ;
60116
61117const app = await mountFlowDropApp (document .getElementById (' editor' ), {
62118 endpointConfig: createEndpointConfig (' /api/flowdrop' ),
63119 eventHandlers: {
120+ onDirtyStateChange : (isDirty ) => {
121+ document .title = isDirty ? ' ● Unsaved Changes' : ' My Workflow Editor' ;
122+ },
64123 onAfterSave : (workflow ) => console .log (' Saved!' , workflow)
65124 }
66125});
126+ ```
127+
128+ ** 4. Run it**
129+
130+ ``` bash
131+ npm run dev
132+ ```
133+
134+ Open ` http://localhost:5173 ` — you have a full workflow editor.
67135
68- // Full control over the editor
136+ ** 5. Programmatic control**
137+
138+ The mount function returns an API object you can use from anywhere in your code:
139+
140+ ``` javascript
141+ // Check for unsaved changes
142+ if (app .isDirty ()) {
143+ const confirmed = confirm (' You have unsaved changes. Save now?' );
144+ if (confirmed) await app .save ();
145+ }
146+
147+ // Read the current workflow as JSON
69148const workflow = app .getWorkflow ();
70- await app .save ();
71- app .destroy ();
149+ console .log (JSON .stringify (workflow, null , 2 ));
150+
151+ // Export the workflow as a downloadable JSON file
152+ app .export ();
153+
154+ // Clean up when navigating away
155+ window .addEventListener (' beforeunload' , () => app .destroy ());
72156```
73157
74158## What's Next?
0 commit comments