wysimark-lite 0.21.2 → 0.24.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
@@ -6,9 +6,11 @@ wysimark ( https://github.com/portive/wysimark ) is a modern and clean rich text
6
6
 
7
7
  Thanks to the original author of wysimark, portive m(_ _)m
8
8
 
9
+ [日本語版 README はこちら](README_ja.md)
10
+
9
11
  ## Demo
10
12
 
11
- You can try out the editor using storybook in the following link:
13
+ You can try out the editor using storybook in the following link:
12
14
  https://takeshy.github.io/wysimark-lite
13
15
 
14
16
  ## Usage
@@ -35,6 +37,33 @@ const Editor: React.FC = () => {
35
37
  };
36
38
  ```
37
39
 
40
+ ### Editor Options
41
+
42
+ The `useEditor` hook accepts the following options:
43
+
44
+ ```tsx
45
+ const editor = useEditor({
46
+ // Enable raw markdown editing mode (default: true = disabled)
47
+ disableRawMode: false,
48
+
49
+ // Enable highlight mark feature (default: true = disabled)
50
+ disableHighlight: false,
51
+
52
+ // Disable task list / checklist (default: false)
53
+ disableTaskList: true,
54
+
55
+ // Disable code block (default: false)
56
+ disableCodeBlock: true,
57
+ });
58
+ ```
59
+
60
+ | Option | Default | Description |
61
+ |--------|---------|-------------|
62
+ | `disableRawMode` | `true` | When `false`, shows a toggle button to switch between WYSIWYG and raw Markdown editing |
63
+ | `disableHighlight` | `true` | When `false`, shows a highlight button in the toolbar. Highlight is saved as `<mark>text</mark>` in Markdown |
64
+ | `disableTaskList` | `false` | When `true`, hides the task list (checklist) button from the toolbar |
65
+ | `disableCodeBlock` | `false` | When `true`, hides the code block button from the toolbar |
66
+
38
67
  ### With Image Upload
39
68
 
40
69
  You can enable image file upload by providing the `onImageChange` callback:
@@ -100,17 +129,27 @@ pin "wysimark-lite", to: "https://cdn.jsdelivr.net/npm/wysimark-lite@latest/dist
100
129
  ## Features
101
130
 
102
131
  - **Modern Design**: Clean and contemporary interface that integrates seamlessly with React applications
103
- - **Raw Markdown Mode**: Switch between WYSIWYG and raw Markdown editing modes
132
+ - **Raw Markdown Mode**: Switch between WYSIWYG and raw Markdown editing modes (enable with `disableRawMode: false`)
133
+ - **Highlight Support**: Highlight text with `<mark>` tags (enable with `disableHighlight: false`)
104
134
  - **Image Upload Support**: Upload images via file picker or drag and drop when `onImageChange` callback is provided
135
+ - **Code Block with Custom Language**: Click on the language label to enter any language name
105
136
  - **User-Friendly Interface**:
106
137
  - Simplified toolbar with toggle buttons (click to activate/deactivate formatting)
107
138
  - Markdown shortcuts (e.g., `**` for **bold**, `#` for heading)
108
139
  - Keyboard shortcuts (e.g., `Ctrl/Cmd + B` for bold)
109
140
  - Japanese localized UI (toolbar and menu items in Japanese)
141
+ - **Enhanced Link Editing**:
142
+ - Edit link text and tooltip directly in the link dialog
143
+ - Both insert and edit dialogs support text and tooltip fields
110
144
  - **Enhanced List Support**:
111
145
  - Nested lists support (create hierarchical lists with multiple levels)
112
146
  - Mix different list types in the hierarchy
147
+ - **Enhanced Table Editing**:
148
+ - Press `Enter` in a table cell to insert a line break (soft break)
149
+ - Press `Shift+Enter` to move to the next cell
150
+ - Press `Tab` in the last cell to exit the table and create a new paragraph
113
151
  - **Smart Block Splitting**: When applying heading/paragraph styles to multi-line blocks, only the selected lines are converted
152
+ - **Cursor Position Preservation**: Cursor position is maintained after element type conversion (e.g., paragraph to heading)
114
153
 
115
154
  ## Browser Support
116
155
 
package/dist/index.d.ts CHANGED
@@ -40,6 +40,22 @@ type WysimarkEditor = {
40
40
  * Persisted state for the image dialog
41
41
  */
42
42
  imageDialogState?: ImageDialogState;
43
+ /**
44
+ * Whether raw mode is disabled
45
+ */
46
+ disableRawMode?: boolean;
47
+ /**
48
+ * Whether task list is disabled
49
+ */
50
+ disableTaskList?: boolean;
51
+ /**
52
+ * Whether code block is disabled
53
+ */
54
+ disableCodeBlock?: boolean;
55
+ /**
56
+ * Whether highlight mark is disabled
57
+ */
58
+ disableHighlight?: boolean;
43
59
  };
44
60
  /**
45
61
  * Public methods for the wysimark editor.
@@ -48,12 +64,65 @@ type WysimarkEditor = {
48
64
  setMarkdown: (markdown: string) => void;
49
65
  };
50
66
 
51
- declare function useEditor({ authToken, height, minHeight, maxHeight, }: {
67
+ type UseEditorOptions = {
52
68
  authToken?: string;
53
69
  height?: string | number;
54
70
  minHeight?: string | number;
55
71
  maxHeight?: string | number;
56
- }): Editor & ReactEditor & WysimarkEditor;
72
+ /**
73
+ * Disable raw Markdown editing mode.
74
+ * When true, the raw mode toggle button will be hidden from the toolbar.
75
+ * Defaults to true (raw mode is disabled by default).
76
+ *
77
+ * @example
78
+ * ```tsx
79
+ * const editor = useEditor({
80
+ * disableRawMode: false // Enable raw mode
81
+ * })
82
+ * ```
83
+ */
84
+ disableRawMode?: boolean;
85
+ /**
86
+ * Disable task list (checklist) functionality.
87
+ * When true, the task list button will be hidden from the toolbar
88
+ * and task list creation will be disabled.
89
+ *
90
+ * @example
91
+ * ```tsx
92
+ * const editor = useEditor({
93
+ * disableTaskList: true
94
+ * })
95
+ * ```
96
+ */
97
+ disableTaskList?: boolean;
98
+ /**
99
+ * Disable code block functionality.
100
+ * When true, the code block button will be hidden from the toolbar.
101
+ *
102
+ * @example
103
+ * ```tsx
104
+ * const editor = useEditor({
105
+ * disableCodeBlock: true
106
+ * })
107
+ * ```
108
+ */
109
+ disableCodeBlock?: boolean;
110
+ /**
111
+ * Disable highlight mark functionality.
112
+ * When true, the highlight button will be hidden from the toolbar.
113
+ * Highlight is serialized as <mark>text</mark> in markdown.
114
+ * Defaults to true (highlight is disabled by default).
115
+ *
116
+ * @example
117
+ * ```tsx
118
+ * const editor = useEditor({
119
+ * disableHighlight: false // Enable highlight
120
+ * })
121
+ * ```
122
+ */
123
+ disableHighlight?: boolean;
124
+ };
125
+ declare function useEditor({ authToken, height, minHeight, maxHeight, disableRawMode, disableTaskList, disableCodeBlock, disableHighlight, }?: UseEditorOptions): Editor & ReactEditor & WysimarkEditor;
57
126
 
58
127
  /**
59
128
  * SinkEditor just adds a `sink` object where we drop all of our sink
@@ -689,6 +758,7 @@ type TableInfo = {
689
758
  declare function createAnchorMethods(editor: Editor): {
690
759
  insertLink: (args_0: string, args_1?: string | undefined, args_2?: {
691
760
  select?: boolean | undefined;
761
+ title?: string | undefined;
692
762
  } | undefined) => void;
693
763
  removeLink: (args_0: {
694
764
  at?: BetterAt | undefined;
@@ -696,6 +766,7 @@ declare function createAnchorMethods(editor: Editor): {
696
766
  editLink: (args_0: {
697
767
  href: string;
698
768
  title?: string | undefined;
769
+ text?: string | undefined;
699
770
  }, args_1: {
700
771
  at?: BetterAt | undefined;
701
772
  }) => boolean;
@@ -806,9 +877,26 @@ type CodeBlockPluginCustomTypes = {
806
877
  };
807
878
  };
808
879
 
880
+ /**
881
+ * HTML block element for preserving raw HTML content
882
+ */
883
+ type HtmlBlockElement = {
884
+ type: "html-block";
885
+ /**
886
+ * The raw HTML content
887
+ */
888
+ html: string;
889
+ children: Text[];
890
+ };
891
+ type HtmlBlockPluginCustomTypes = {
892
+ Name: "html-block";
893
+ Editor: Record<string, never>;
894
+ Element: HtmlBlockElement;
895
+ };
896
+
809
897
  declare function createTableMethods(editor: Editor): {
810
898
  getTableInfo: (args_0?: {
811
- at?: ImageBlockElement | ParagraphElement | OrderedListItemElement | UnorderedListItemElement | TaskListItemElement | HorizontalRuleElement | TableElement | TableRowElement | TableCellElement | TableContentElement | CodeBlockElement | CodeBlockLineElement | BlockQuoteElement | HeadingElement | AnchorElement | slate.Location | null | undefined;
899
+ at?: ImageBlockElement | ParagraphElement | OrderedListItemElement | UnorderedListItemElement | TaskListItemElement | HorizontalRuleElement | TableElement | TableRowElement | TableCellElement | TableContentElement | HtmlBlockElement | CodeBlockElement | CodeBlockLineElement | BlockQuoteElement | HeadingElement | AnchorElement | slate.Location | null | undefined;
812
900
  } | undefined) => TableInfo | undefined;
813
901
  insertTable: (args_0: number, args_1: number, args_2?: {
814
902
  at?: slate.Location | null | undefined;
@@ -830,6 +918,7 @@ declare function createTableMethods(editor: Editor): {
830
918
  } | undefined) => boolean;
831
919
  tabForward: () => boolean;
832
920
  tabBackward: () => boolean | undefined;
921
+ shiftEnterForward: () => boolean;
833
922
  selectCell: (args_0?: {
834
923
  at?: BetterAt | undefined;
835
924
  } | undefined) => boolean;
@@ -869,13 +958,14 @@ declare function createMarksMethods(editor: Editor): {
869
958
  removeMarks: (args_0?: {
870
959
  at?: slate.Location | null | undefined;
871
960
  } | undefined) => void;
872
- toggleMark: (args_0: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline", args_1?: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | undefined, args_2?: {
961
+ toggleMark: (args_0: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | "highlight", args_1?: "bold" | "strike" | "text" | "prismToken" | "code" | "italic" | "underline" | "highlight" | undefined, args_2?: {
873
962
  at?: slate.Location | null | undefined;
874
963
  } | undefined) => void;
875
964
  toggleBold: () => void;
876
965
  toggleItalic: () => void;
877
966
  toggleUnderline: () => void;
878
967
  toggleStrike: () => void;
968
+ toggleHighlight: () => void;
879
969
  };
880
970
 
881
971
  type MarksEditor = {
@@ -899,6 +989,7 @@ type MarksText = {
899
989
  italic?: true;
900
990
  underline?: true;
901
991
  strike?: true;
992
+ highlight?: true;
902
993
  };
903
994
  type MarksPluginCustomTypes = {
904
995
  Name: "marks";
@@ -915,8 +1006,8 @@ type CurriedConvertElements = <T extends Element$1 = Element$1>(matchForToggle:
915
1006
 
916
1007
  declare function createConvertElementMethods(editor: Editor): {
917
1008
  convertElementTypes: string[];
918
- addConvertElementType: (type: "anchor" | "heading" | "block-quote" | "table" | "horizontal-rule" | "code-block" | "paragraph" | "image-block" | "ordered-list-item" | "unordered-list-item" | "task-list-item" | "table-row" | "table-cell" | "table-content" | "code-block-line" | ("anchor" | "heading" | "block-quote" | "table" | "horizontal-rule" | "code-block" | "paragraph" | "image-block" | "ordered-list-item" | "unordered-list-item" | "task-list-item" | "table-row" | "table-cell" | "table-content" | "code-block-line")[]) => void;
919
- isConvertibleElement: (element: ImageBlockElement | ParagraphElement | OrderedListItemElement | UnorderedListItemElement | TaskListItemElement | HorizontalRuleElement | TableElement | TableRowElement | TableCellElement | TableContentElement | CodeBlockElement | CodeBlockLineElement | BlockQuoteElement | HeadingElement | AnchorElement) => boolean;
1009
+ addConvertElementType: (type: "anchor" | "heading" | "block-quote" | "html-block" | "table" | "horizontal-rule" | "code-block" | "paragraph" | "image-block" | "ordered-list-item" | "unordered-list-item" | "task-list-item" | "table-row" | "table-cell" | "table-content" | "code-block-line" | ("anchor" | "heading" | "block-quote" | "html-block" | "table" | "horizontal-rule" | "code-block" | "paragraph" | "image-block" | "ordered-list-item" | "unordered-list-item" | "task-list-item" | "table-row" | "table-cell" | "table-content" | "code-block-line")[]) => void;
1010
+ isConvertibleElement: (element: ImageBlockElement | ParagraphElement | OrderedListItemElement | UnorderedListItemElement | TaskListItemElement | HorizontalRuleElement | TableElement | TableRowElement | TableCellElement | TableContentElement | HtmlBlockElement | CodeBlockElement | CodeBlockLineElement | BlockQuoteElement | HeadingElement | AnchorElement) => boolean;
920
1011
  convertElements: CurriedConvertElements;
921
1012
  };
922
1013
 
@@ -941,7 +1032,10 @@ type PasteMarkdownPluginCustomTypes = {
941
1032
  Editor: PasteMarkdownEditor;
942
1033
  };
943
1034
 
944
- declare const plugins: (TypedPlugin<PasteMarkdownPluginCustomTypes> | TypedPlugin<ConvertElementPluginCustomTypes> | TypedPlugin<AnchorPluginCustomTypes> | TypedPlugin<HeadingPluginCustomTypes> | TypedPlugin<MarksPluginCustomTypes> | TypedPlugin<InlineCodePluginCustomTypes> | TypedPlugin<BlockQuotePluginCustomTypes> | TypedPlugin<CodeBlockPluginCustomTypes> | TypedPlugin<TablePluginCustomTypes> | TypedPlugin<HorizontalRulePluginCustomTypes> | TypedPlugin<{
1035
+ /**
1036
+ * @deprecated Use defaultPlugins instead
1037
+ */
1038
+ declare const plugins: (TypedPlugin<PasteMarkdownPluginCustomTypes> | TypedPlugin<ConvertElementPluginCustomTypes> | TypedPlugin<AnchorPluginCustomTypes> | TypedPlugin<HeadingPluginCustomTypes> | TypedPlugin<MarksPluginCustomTypes> | TypedPlugin<InlineCodePluginCustomTypes> | TypedPlugin<BlockQuotePluginCustomTypes> | TypedPlugin<CodeBlockPluginCustomTypes> | TypedPlugin<HtmlBlockPluginCustomTypes> | TypedPlugin<TablePluginCustomTypes> | TypedPlugin<HorizontalRulePluginCustomTypes> | TypedPlugin<{
945
1039
  Name: "trailing-block";
946
1040
  Editor: {
947
1041
  allowTrailingBlock: true;