@lax-wp/editor 0.4.3 → 0.4.4
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 +62 -0
- package/dist/config/EditorConfig.d.ts +35 -0
- package/dist/contexts/EditorShellContext.d.ts +3 -2
- package/dist/index.es.js +13580 -10949
- package/dist/index.umd.js +104 -80
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ A modern, feature-rich WordPress-style editor built with React and TipTap. This
|
|
|
12
12
|
- [Basic Configuration](#basic-configuration)
|
|
13
13
|
- [AI Autocompletion](#ai-autocompletion)
|
|
14
14
|
- [Export Functionality](#export-functionality)
|
|
15
|
+
- [Screenshot Capture](#screenshot-capture)
|
|
15
16
|
- [Variable Text Feature](#variable-text-feature)
|
|
16
17
|
- [Configuration Options Reference](#configuration-options-reference)
|
|
17
18
|
- [Components](#components)
|
|
@@ -298,6 +299,66 @@ insertVariable(key: string, value?: string)
|
|
|
298
299
|
- Dynamic content generation
|
|
299
300
|
- Personalized documents
|
|
300
301
|
|
|
302
|
+
### Screenshot Capture
|
|
303
|
+
|
|
304
|
+
The editor supports host-driven screenshot capture with a serializable trigger (`requestId`) and `File` callbacks.
|
|
305
|
+
|
|
306
|
+
```tsx
|
|
307
|
+
import { useMemo, useState } from 'react';
|
|
308
|
+
import { Editor, type EditorConfig } from 'lax-wp-editor';
|
|
309
|
+
|
|
310
|
+
function App() {
|
|
311
|
+
const [captureRequestId, setCaptureRequestId] = useState<string>();
|
|
312
|
+
const [captureApi, setCaptureApi] =
|
|
313
|
+
useState<((opts?: { fileName?: string; mimeType?: 'image/png' | 'image/jpeg'; quality?: number }) => Promise<File>) | null>(null);
|
|
314
|
+
|
|
315
|
+
const config = useMemo<EditorConfig>(() => ({
|
|
316
|
+
screenshot: {
|
|
317
|
+
requestId: captureRequestId, // capture runs once each time this value changes
|
|
318
|
+
fileName: 'contract-preview',
|
|
319
|
+
mimeType: 'image/png',
|
|
320
|
+
onSuccess: (file) => {
|
|
321
|
+
console.log('Screenshot file:', file);
|
|
322
|
+
},
|
|
323
|
+
onError: (error) => {
|
|
324
|
+
console.error('Screenshot failed:', error);
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
onEditorReady: ({ captureScreenshot }) => {
|
|
328
|
+
setCaptureApi(() => captureScreenshot);
|
|
329
|
+
},
|
|
330
|
+
}), [captureRequestId]);
|
|
331
|
+
|
|
332
|
+
return (
|
|
333
|
+
<div>
|
|
334
|
+
<button onClick={() => setCaptureRequestId(crypto.randomUUID())}>
|
|
335
|
+
Capture via requestId
|
|
336
|
+
</button>
|
|
337
|
+
<button
|
|
338
|
+
onClick={async () => {
|
|
339
|
+
const file = await captureApi?.({ fileName: 'manual-thumbnail', mimeType: 'image/jpeg', quality: 0.9 });
|
|
340
|
+
console.log(file);
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
Capture imperatively
|
|
344
|
+
</button>
|
|
345
|
+
<Editor config={config} />
|
|
346
|
+
</div>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
`screenshot` config options:
|
|
352
|
+
|
|
353
|
+
| Option | Type | Default | Description |
|
|
354
|
+
|--------|------|---------|-------------|
|
|
355
|
+
| `requestId` | `string` | `undefined` | Trigger token. Capture runs when this changes to a new value. |
|
|
356
|
+
| `fileName` | `string` | `editor-thumbnail` | Base file name (extension added automatically). |
|
|
357
|
+
| `mimeType` | `'image/png' \| 'image/jpeg'` | `'image/png'` | Output image format. |
|
|
358
|
+
| `quality` | `number` | `0.92` | JPEG quality (0..1), ignored for PNG. |
|
|
359
|
+
| `onSuccess` | `(file: File) => void` | `undefined` | Called with captured screenshot file. |
|
|
360
|
+
| `onError` | `(error: Error) => void` | `undefined` | Called if capture fails. |
|
|
361
|
+
|
|
301
362
|
### Configuration Options Reference
|
|
302
363
|
|
|
303
364
|
| Option | Type | Default | Description |
|
|
@@ -313,6 +374,7 @@ insertVariable(key: string, value?: string)
|
|
|
313
374
|
| `enableVariableText` | `boolean` | `false` | Enable variable text feature |
|
|
314
375
|
| `variableValues` | `Record<string, string>` | `{}` | Variable name to value mappings |
|
|
315
376
|
| `onEditorReady` | `(methods) => void` | `undefined` | Callback with editor methods when ready |
|
|
377
|
+
| `screenshot` | `ScreenshotConfig` | `undefined` | Declarative screenshot request + callbacks |
|
|
316
378
|
| `onShare` | `() => void` | `undefined` | Callback when share button is clicked |
|
|
317
379
|
| `aiAutocompletion` | `AIAutocompletionConfig` | See below | AI autocompletion configuration |
|
|
318
380
|
|
|
@@ -84,6 +84,33 @@ export interface AIAutocompletionConfig {
|
|
|
84
84
|
}
|
|
85
85
|
/** Pass scan/API JSON or an HTML string into the editor (used with {@link EditorConfig.onScanComplete}). */
|
|
86
86
|
export type ApplyScanCompleteContent = (editorContent: string | Record<string, unknown>) => void;
|
|
87
|
+
export type ScreenshotMimeType = 'image/png' | 'image/jpeg';
|
|
88
|
+
/**
|
|
89
|
+
* Screenshot options accepted by both config-driven and imperative capture APIs.
|
|
90
|
+
*/
|
|
91
|
+
export interface ScreenshotCaptureOptions {
|
|
92
|
+
/** Output file name without extension. Defaults to `editor-thumbnail`. */
|
|
93
|
+
fileName?: string;
|
|
94
|
+
/** Output MIME type. Defaults to `image/png`. */
|
|
95
|
+
mimeType?: ScreenshotMimeType;
|
|
96
|
+
/** JPEG quality from 0..1. Used only when `mimeType` is `image/jpeg`. Defaults to `0.92`. */
|
|
97
|
+
quality?: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Declarative screenshot request configuration.
|
|
101
|
+
*
|
|
102
|
+
* Use `requestId` as a serializable trigger token (e.g. UUID or timestamp). The editor will capture once when this value changes.
|
|
103
|
+
*/
|
|
104
|
+
export interface ScreenshotConfig extends ScreenshotCaptureOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Capture trigger token. Capture runs only when this value changes from the last handled request.
|
|
107
|
+
*/
|
|
108
|
+
requestId?: string;
|
|
109
|
+
/** Callback fired with the generated screenshot file. */
|
|
110
|
+
onSuccess?: (file: File) => void;
|
|
111
|
+
/** Callback fired if capture fails. */
|
|
112
|
+
onError?: (error: Error) => void;
|
|
113
|
+
}
|
|
87
114
|
export interface EditorConfig {
|
|
88
115
|
/** Editor mode */
|
|
89
116
|
mode?: TEditorMode;
|
|
@@ -162,7 +189,15 @@ export interface EditorConfig {
|
|
|
162
189
|
variableTableData?: Record<string, Record<string, unknown | undefined | null>[]>;
|
|
163
190
|
}) => void;
|
|
164
191
|
updateTableValues: () => void;
|
|
192
|
+
captureScreenshot: (options?: ScreenshotCaptureOptions) => Promise<File>;
|
|
165
193
|
}) => void;
|
|
194
|
+
/**
|
|
195
|
+
* Screenshot capture configuration.
|
|
196
|
+
*
|
|
197
|
+
* Use `requestId` as a declarative trigger so host apps can request capture
|
|
198
|
+
* using serializable state updates.
|
|
199
|
+
*/
|
|
200
|
+
screenshot?: ScreenshotConfig;
|
|
166
201
|
/** Parent container id for redline positioning */
|
|
167
202
|
parentContainerId?: string;
|
|
168
203
|
/** PII Anonymization configuration */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import type { Editor } from "@tiptap/react";
|
|
3
|
-
import type { EditorConfig } from "@/config/EditorConfig";
|
|
3
|
+
import type { EditorConfig, ScreenshotCaptureOptions } from "@/config/EditorConfig";
|
|
4
4
|
export interface EditorShellContextType {
|
|
5
5
|
editor: Editor;
|
|
6
6
|
editorConfig: EditorConfig;
|
|
@@ -11,7 +11,8 @@ interface EditorShellProviderProps {
|
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
editor: Editor;
|
|
13
13
|
editorConfig: EditorConfig;
|
|
14
|
+
captureScreenshot: (options?: ScreenshotCaptureOptions) => Promise<File>;
|
|
14
15
|
}
|
|
15
|
-
export declare const EditorShellProvider: ({ children, editor, editorConfig }: EditorShellProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export declare const EditorShellProvider: ({ children, editor, editorConfig, captureScreenshot }: EditorShellProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
17
|
export declare const useEditorShell: () => EditorShellContextType;
|
|
17
18
|
export {};
|