wysimark-lite 0.18.0 → 0.21.2
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 +40 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.js +124 -241
- package/dist/index.mjs +578 -240
- package/dist/index.mjs.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/package.json +5 -7
package/README.md
CHANGED
|
@@ -35,6 +35,44 @@ const Editor: React.FC = () => {
|
|
|
35
35
|
};
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### With Image Upload
|
|
39
|
+
|
|
40
|
+
You can enable image file upload by providing the `onImageChange` callback:
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { Editable, useEditor } from "wysimark-lite";
|
|
44
|
+
import React from "react";
|
|
45
|
+
|
|
46
|
+
const Editor: React.FC = () => {
|
|
47
|
+
const [value, setValue] = React.useState("");
|
|
48
|
+
const editor = useEditor({});
|
|
49
|
+
|
|
50
|
+
const handleImageUpload = async (file: File): Promise<string> => {
|
|
51
|
+
// Upload file to your server and return the URL
|
|
52
|
+
const formData = new FormData();
|
|
53
|
+
formData.append("image", file);
|
|
54
|
+
const response = await fetch("/api/upload", { method: "POST", body: formData });
|
|
55
|
+
const { url } = await response.json();
|
|
56
|
+
return url;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div style={{ width: "800px" }}>
|
|
61
|
+
<Editable
|
|
62
|
+
editor={editor}
|
|
63
|
+
value={value}
|
|
64
|
+
onChange={setValue}
|
|
65
|
+
onImageChange={handleImageUpload}
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
When `onImageChange` is provided:
|
|
73
|
+
- The image dialog shows a radio button to switch between URL input and file upload
|
|
74
|
+
- **Drag and drop** image files directly into the editor to insert them at the cursor position
|
|
75
|
+
|
|
38
76
|
### Direct Initialization
|
|
39
77
|
|
|
40
78
|
You can also initialize the editor directly on an HTML element:
|
|
@@ -63,6 +101,7 @@ pin "wysimark-lite", to: "https://cdn.jsdelivr.net/npm/wysimark-lite@latest/dist
|
|
|
63
101
|
|
|
64
102
|
- **Modern Design**: Clean and contemporary interface that integrates seamlessly with React applications
|
|
65
103
|
- **Raw Markdown Mode**: Switch between WYSIWYG and raw Markdown editing modes
|
|
104
|
+
- **Image Upload Support**: Upload images via file picker or drag and drop when `onImageChange` callback is provided
|
|
66
105
|
- **User-Friendly Interface**:
|
|
67
106
|
- Simplified toolbar with toggle buttons (click to activate/deactivate formatting)
|
|
68
107
|
- Markdown shortcuts (e.g., `**` for **bold**, `#` for heading)
|
|
@@ -71,6 +110,7 @@ pin "wysimark-lite", to: "https://cdn.jsdelivr.net/npm/wysimark-lite@latest/dist
|
|
|
71
110
|
- **Enhanced List Support**:
|
|
72
111
|
- Nested lists support (create hierarchical lists with multiple levels)
|
|
73
112
|
- Mix different list types in the hierarchy
|
|
113
|
+
- **Smart Block Splitting**: When applying heading/paragraph styles to multi-line blocks, only the selected lines are converted
|
|
74
114
|
|
|
75
115
|
## Browser Support
|
|
76
116
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,14 @@ import { SetReturnType, SetOptional, UnionToIntersection, Simplify } from 'type-
|
|
|
7
7
|
import react from 'react';
|
|
8
8
|
import { RenderElementProps, RenderLeafProps, RenderPlaceholderProps, EditableProps as EditableProps$1 } from 'slate-react/dist/components/editable';
|
|
9
9
|
|
|
10
|
+
type OnImageChangeHandler$1 = (file: File) => Promise<string>;
|
|
11
|
+
type ImageDialogState = {
|
|
12
|
+
url: string;
|
|
13
|
+
alt: string;
|
|
14
|
+
title: string;
|
|
15
|
+
imageSource: "url" | "file";
|
|
16
|
+
uploadedUrl: string;
|
|
17
|
+
};
|
|
10
18
|
type WysimarkEditor = {
|
|
11
19
|
/**
|
|
12
20
|
* Private state for the wysimark editor.
|
|
@@ -24,6 +32,14 @@ type WysimarkEditor = {
|
|
|
24
32
|
* Function to toggle Raw mode
|
|
25
33
|
*/
|
|
26
34
|
toggleRawMode?: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Handler for image file upload
|
|
37
|
+
*/
|
|
38
|
+
onImageChange?: OnImageChangeHandler$1;
|
|
39
|
+
/**
|
|
40
|
+
* Persisted state for the image dialog
|
|
41
|
+
*/
|
|
42
|
+
imageDialogState?: ImageDialogState;
|
|
27
43
|
};
|
|
28
44
|
/**
|
|
29
45
|
* Public methods for the wysimark editor.
|
|
@@ -943,6 +959,7 @@ declare module "slate" {
|
|
|
943
959
|
}
|
|
944
960
|
}
|
|
945
961
|
|
|
962
|
+
type OnImageChangeHandler = (file: File) => Promise<string>;
|
|
946
963
|
type EditableProps = {
|
|
947
964
|
editor: Editor;
|
|
948
965
|
value: string;
|
|
@@ -951,8 +968,9 @@ type EditableProps = {
|
|
|
951
968
|
placeholder?: string;
|
|
952
969
|
className?: string;
|
|
953
970
|
style?: React.CSSProperties;
|
|
971
|
+
onImageChange?: OnImageChangeHandler;
|
|
954
972
|
};
|
|
955
|
-
declare function Editable({ editor, value, onChange, throttleInMs, placeholder, className, style, }: EditableProps): react_jsx_runtime.JSX.Element;
|
|
973
|
+
declare function Editable({ editor, value, onChange, throttleInMs, placeholder, className, style, onImageChange, }: EditableProps): react_jsx_runtime.JSX.Element;
|
|
956
974
|
|
|
957
975
|
/**
|
|
958
976
|
* The options passed into the standalone version of Wysimark.
|
|
@@ -976,4 +994,4 @@ type Wysimark = {
|
|
|
976
994
|
*/
|
|
977
995
|
declare function createWysimark(containerElement: HTMLElement, options: StandaloneOptions): Wysimark;
|
|
978
996
|
|
|
979
|
-
export { Editable, Wysimark, createWysimark, useEditor };
|
|
997
|
+
export { Editable, OnImageChangeHandler, Wysimark, createWysimark, useEditor };
|