hivewrite-sdk 1.1.70 → 1.1.72
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 +12 -12
- package/bundle.min.js +1 -1
- package/index.d.ts +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ Initializes and mounts the editor.
|
|
|
115
115
|
| `onTokenRefresh` | `() => Promise<string>` | Yes | Callback function that returns a new access token when the current one expires |
|
|
116
116
|
| `accessToken` | `string` | Yes | Initial access token for authorization |
|
|
117
117
|
| `container` | `string \| HTMLElement` | Yes | CSS selector or DOM element to mount the editor |
|
|
118
|
-
| `
|
|
118
|
+
| `user_id` | `string` | Yes | Unique identifier for the current user (required) |
|
|
119
119
|
| `mode` | `string` | Yes | `'FULL_EDITOR'`, `'DESIGN_ONLY'`, `'READ_ONLY'` |
|
|
120
120
|
| `theme` | `string` | No | `'light'` (default) or `'dark'` |
|
|
121
121
|
| `locale` | `string` | No | `'en'` (default), `'es'`, or `'fr'` |
|
|
@@ -289,20 +289,20 @@ mergeTags: [
|
|
|
289
289
|
| Callback | Arguments | Description |
|
|
290
290
|
| :----------------- | :------------------------------------------------------------------------------------------------------------------------------ | :------------------------------------------ |
|
|
291
291
|
| `onLoad` | `()` | Editor fully initialized |
|
|
292
|
-
| `onExport` | `(html: string,
|
|
293
|
-
| `onSave` | `(json: {blocks: any[], canvasSettings: CanvasSettings, name: string, description: string, category: string},
|
|
294
|
-
| `onError` | `(err: any,
|
|
295
|
-
| `onTemplateChange` | `(templateId: string,
|
|
296
|
-
| `onImageUpload` | `(file: File,
|
|
292
|
+
| `onExport` | `(html: string, user_id?: string)` | Triggered on HTML export |
|
|
293
|
+
| `onSave` | `(json: {blocks: any[], canvasSettings: CanvasSettings, name: string, description: string, category: string}, user_id?: string)` | Triggered on design save |
|
|
294
|
+
| `onError` | `(err: any, user_id?: string)` | Initialization or processing error |
|
|
295
|
+
| `onTemplateChange` | `(templateId: string, user_id?: string)` | Template selection changed |
|
|
296
|
+
| `onImageUpload` | `(file: File, user_id?: string)` | **Async**. Handle image uploads, return URL |
|
|
297
297
|
|
|
298
298
|
### Image Upload Example
|
|
299
299
|
|
|
300
300
|
```javascript
|
|
301
301
|
callbacks: {
|
|
302
|
-
onImageUpload: async (file,
|
|
302
|
+
onImageUpload: async (file, user_id) => {
|
|
303
303
|
const formData = new FormData();
|
|
304
304
|
formData.append("image", file);
|
|
305
|
-
if (
|
|
305
|
+
if (user_id) formData.append("user_id", user_id);
|
|
306
306
|
const res = await fetch("/api/upload", { method: "POST", body: formData });
|
|
307
307
|
const data = await res.json();
|
|
308
308
|
return data.url; // Return the uploaded image URL
|
|
@@ -319,7 +319,7 @@ Triggers the `onSave` callback with the current design state.
|
|
|
319
319
|
```javascript
|
|
320
320
|
hivewrite.save();
|
|
321
321
|
|
|
322
|
-
// Result sent to onSave(json,
|
|
322
|
+
// Result sent to onSave(json, user_id):
|
|
323
323
|
{
|
|
324
324
|
"body": {
|
|
325
325
|
"blocks": [ ... ] // Array of block objects
|
|
@@ -331,14 +331,14 @@ hivewrite.save();
|
|
|
331
331
|
}
|
|
332
332
|
```
|
|
333
333
|
|
|
334
|
-
#### `onExport(html,
|
|
334
|
+
#### `onExport(html, user_id)`
|
|
335
335
|
|
|
336
336
|
The `html` argument is a string containing the final generated HTML.
|
|
337
337
|
|
|
338
338
|
```javascript
|
|
339
339
|
// Example usage
|
|
340
|
-
onExport: (html,
|
|
341
|
-
console.log(`Exported for user ${
|
|
340
|
+
onExport: (html, user_id) => {
|
|
341
|
+
console.log(`Exported for user ${user_id}`);
|
|
342
342
|
saveToDatabase(html);
|
|
343
343
|
};
|
|
344
344
|
```
|