tiptop-editor 2.0.0 → 2.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/README.md CHANGED
@@ -237,6 +237,12 @@ export function EditorWithSlots() {
237
237
  Controls whether the block drag handle is rendered. Default: `true`.
238
238
  - `extraExtensions`
239
239
  Appends custom Tiptap extensions after the built-in editor set.
240
+ - `imgUploadUrl`
241
+ The URL of the server endpoint that receives image uploads.
242
+ - `imgUploadResponseKey`
243
+ Locates the image URL in the server response. Accepts a top-level key, a dot-separated path, a path array, or a resolver function.
244
+ - `imgUploadHeaders`
245
+ Custom HTTP headers sent with every image upload request (e.g. `Authorization`).
240
246
 
241
247
  ## Built-in Extensions
242
248
 
@@ -367,6 +373,33 @@ The editor sends a `POST` request with `multipart/form-data` and the file under
367
373
  />
368
374
  ```
369
375
 
376
+ ### Sending custom headers
377
+
378
+ Use `imgUploadHeaders` to attach custom HTTP headers to every upload request. This is the standard way to pass an authorization token or any other API header.
379
+
380
+ ```tsx
381
+ <TiptopEditor
382
+ editorOptions={{
383
+ imgUploadUrl: '/api/upload',
384
+ imgUploadResponseKey: 'url',
385
+ imgUploadHeaders: {
386
+ Authorization: 'Bearer YOUR_TOKEN',
387
+ },
388
+ }}
389
+ />
390
+ ```
391
+
392
+ Multiple headers are supported:
393
+
394
+ ```tsx
395
+ imgUploadHeaders: {
396
+ Authorization: 'Bearer YOUR_TOKEN',
397
+ 'X-Api-Key': 'YOUR_API_KEY',
398
+ }
399
+ ```
400
+
401
+ > **Note**: The editor sends `multipart/form-data`. Do **not** include a `Content-Type` header in `imgUploadHeaders` — the browser sets it automatically with the correct boundary string.
402
+
370
403
  Your server response must include the uploaded image URL at the location you describe with `imgUploadResponseKey`.
371
404
 
372
405
  Example:
@@ -3,6 +3,7 @@ import { ImageUploadResponseResolver } from '../../types';
3
3
  interface CreateDefaultExtensionsOptions {
4
4
  imgUploadUrl?: string;
5
5
  imgUploadResponseKey?: ImageUploadResponseResolver;
6
+ imgUploadHeaders?: Record<string, string>;
6
7
  }
7
- export declare const createDefaultExtensions: ({ imgUploadUrl, imgUploadResponseKey, }: CreateDefaultExtensionsOptions) => Extensions;
8
+ export declare const createDefaultExtensions: ({ imgUploadUrl, imgUploadResponseKey, imgUploadHeaders, }: CreateDefaultExtensionsOptions) => Extensions;
8
9
  export {};
package/dist/helpers.d.ts CHANGED
@@ -19,11 +19,12 @@ export declare const removeAllFormatting: (editor: Editor) => void;
19
19
  export declare const transformNodeToAlternative: (editor: Editor, targetOption: SlashCommandGroupCommandsProps) => void;
20
20
  export declare const addOrUpdateLink: (editor: Editor, url: string) => void;
21
21
  export declare const unsetLink: (editor: Editor) => void;
22
- export declare const uploadWithProgress: ({ file, url, onProgress, signal }: {
22
+ export declare const uploadWithProgress: ({ file, url, onProgress, signal, headers }: {
23
23
  file: File;
24
24
  url: string;
25
25
  onProgress: (percent: number) => boolean | void;
26
26
  signal?: AbortSignal;
27
+ headers?: Record<string, string>;
27
28
  }) => Promise<Record<string, unknown>>;
28
29
  export declare const getValueAtPath: (source: Record<string, unknown>, path: string | string[]) => unknown;
29
30
  export declare const generateUniqueId: () => string;