@mdaemon/html-editor-react 1.10.0 → 1.11.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.
Files changed (2) hide show
  1. package/README.md +62 -15
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm](https://img.shields.io/npm/v/@mdaemon/html-editor-react?color=blue)](https://www.npmjs.com/package/@mdaemon/html-editor-react)
4
4
  [![license](https://img.shields.io/npm/l/@mdaemon/html-editor-react?color=green)](LICENSE)
5
5
  [![node](https://img.shields.io/node/v/@mdaemon/html-editor-react)](https://nodejs.org)
6
- [![install size](https://packagephobia.com/badge?p=@mdaemon/html-editor-react)](https://packagephobia.com/result?p=@mdaemon/html-editor-react)
6
+ [![install size](https://img.shields.io/npm/unpacked-size/@mdaemon/html-editor-react)](https://packagephobia.com/result?p=@mdaemon/html-editor-react)
7
7
  [![CI](https://github.com/mdaemon-technologies/MDHTMLEditor-react/actions/workflows/ci.yml/badge.svg)](https://github.com/mdaemon-technologies/MDHTMLEditor-react/actions/workflows/ci.yml)
8
8
 
9
9
  React wrapper for MDHTMLEditor
@@ -19,8 +19,8 @@ npm install @mdaemon/html-editor-react
19
19
  **Peer dependencies:** `react` and `react-dom` (v18 or v19).
20
20
 
21
21
  **TipTap:** the editor is built on TipTap 3, and this package tracks the same version the
22
- engine uses — currently **3.31.3** (`@mdaemon/html-editor` `^1.13.1`,
23
- `@tiptap/react` `^3.31.3`). If your app depends on any `@tiptap/*` package directly, keep
22
+ engine uses — currently **3.32.0** (`@mdaemon/html-editor` `^1.16.0`,
23
+ `@tiptap/react` `^3.32.0`). If your app depends on any `@tiptap/*` package directly, keep
24
24
  it on that version too: ProseMirror throws at runtime if two copies of `@tiptap/core` /
25
25
  `@tiptap/pm` end up in the bundle. If you only use `<Editor>` or `useEditor`, there is
26
26
  nothing to do.
@@ -233,7 +233,7 @@ The `config` prop (or `useEditor`'s `config` option) accepts an `EditorConfig` o
233
233
  | `height` | `string \| number` | `300` | Editor height. |
234
234
  | `min_height` | `string \| number` | &mdash; | Minimum editor height. |
235
235
  | `max_height` | `string \| number` | &mdash; | Maximum editor height. |
236
- | `language` | `string` | `'en'` | UI language code. 31 languages built in. |
236
+ | `language` | `string` | `'en'` | UI language code. 32 languages built in &mdash; see [Supported Languages](#supported-languages). |
237
237
  | `skin` | `'oxide' \| 'oxide-dark' \| 'confab' \| 'confab-dark'` | `'oxide'` | Toolbar and dialog theme. |
238
238
  | `content_css` | `'default' \| 'dark' \| 'confab' \| 'confab-dark'` | `'default'` | Content area theme. |
239
239
  | `content_style` | `string` | &mdash; | Custom CSS injected into the editing surface. |
@@ -246,7 +246,7 @@ The `config` prop (or `useEditor`'s `config` option) accepts an `EditorConfig` o
246
246
  | `block_formats` | `string` | *(Paragraph + H1&ndash;H6)* | Block-format dropdown definitions for the `blocks` button (`Name=tag;...`). |
247
247
  | `style_formats` | `StyleFormat[]` | *(subset)* | Named styles for the `styles` dropdown (CKEditor `stylesSet`-compatible). |
248
248
  | `forced_root_block` | `'p' \| 'div'` | `'p'` | Block element produced on Enter. `'div'` gives CKEditor `ENTER_DIV` parity. |
249
- | `trailingNode` | `boolean` | `false` | Append an empty trailing paragraph after a block node (table, image, code block) so the cursor can sit after it. |
249
+ | `trailingNode` | `boolean` | `false` | Append an empty trailing paragraph after a block node (table, code block) so the cursor can sit after it. |
250
250
  | `directionality` | `'ltr' \| 'rtl'` | `'ltr'` | Text direction. |
251
251
  | `toolbar` | `string` | *(preset)* | Custom toolbar layout string. |
252
252
  | `toolbar_mode` | `'sliding' \| 'floating' \| 'wrap'` | `'wrap'` | Toolbar overflow behavior. |
@@ -258,6 +258,8 @@ The `config` prop (or `useEditor`'s `config` option) accepts an `EditorConfig` o
258
258
  | `quickbars_selection_toolbar` | `string` | `'bold italic \| quicklink blockquote'` | Inline floating toolbar shown over a text selection. |
259
259
  | `quickbars_image_toolbar` | `boolean` | `false` | Inline floating toolbar shown when an image is selected. |
260
260
  | `quickbars_insert_toolbar` | `boolean` | `false` | Inline floating toolbar shown on empty lines for quick insertion. |
261
+ | `object_resizing` | `boolean \| string` | `true` | Show drag handles on a selected image to resize it. `false` turns resizing off; a CSS selector string (TinyMCE-style, e.g. `'img[alt]'`) limits it to the images that match &mdash; see [Resizing Images](#resizing-images). |
262
+ | `resize_img_proportional` | `boolean` | `true` | Corner handles keep the image's aspect ratio. Holding Shift while dragging does the opposite for that drag. |
261
263
  | `elementpath` | `boolean` | `false` | Show a breadcrumb of the node path at the cursor in the status bar. |
262
264
  | `valid_children` | `string` | &mdash; | TinyMCE-style rules controlling which child elements are allowed. |
263
265
  | `auto_focus` | `string` | &mdash; | Auto-focus on init. |
@@ -267,6 +269,7 @@ The `config` prop (or `useEditor`'s `config` option) accepts an `EditorConfig` o
267
269
  | `entity_encoding` | `'raw' \| 'named' \| 'numeric'` | `'raw'` | HTML entity encoding mode. |
268
270
  | `paste_from_office` | `boolean` | `true` | Clean and preserve formatting when pasting from Microsoft Word/Excel. Pasted list indentation is normalized either way &mdash; see [Lists & Indentation](#lists--indentation). |
269
271
  | `paste_markdown` | `boolean` | `false` | Start with paste-as-Markdown on, so a paste is read as Markdown and inserted as real formatting. Toggle at runtime via `getEditor()?.setPasteMarkdown()` or the `pastemarkdown` toolbar button &mdash; see [Pasting Markdown](#pasting-markdown). |
272
+ | `quote_marker_class` | `string` | &mdash; | Class that marks a reply's quoted original. A `<blockquote>` or `<div>` whose class is exactly this value keeps the class and its margin, padding and border in `getContent()`, so the quote can be found again. One class name; off when unset or empty. See the [engine docs](https://github.com/mdaemon-technologies/MDHTMLEditor#quoted-original-of-a-reply). |
270
273
  | `speech_to_text` | `boolean` | `true` | Enable the `speechtotext` and `dictate` toolbar buttons (requires the Web Speech API). |
271
274
  | `convert_unsafe_embeds` | `boolean` | `true` | Sanitize embedded content. |
272
275
  | `format_empty_lines` | `boolean` | `true` | Preserve blank lines outside the editor. On the way out (`getContent()`, the `onChange` payload, preview, and the source dialog) each empty block is filled with a `<br>` &mdash; bare empty blocks otherwise collapse to zero height in mail clients; on the way in (`setContent()`, `insertContent()`, templates) it is stripped back out, so `setContent(getContent(x))` is stable across round-trips. A block is only "empty" if it has no visible content &mdash; a `<div>&nbsp;</div>` spacer counts as content and is left alone. Set `false` to pass content through unchanged in both directions. |
@@ -281,6 +284,7 @@ The `config` prop (or `useEditor`'s `config` option) accepts an `EditorConfig` o
281
284
  | `images_file_types` | `string` | *(permissive)* | Comma/space-separated accepted extensions (e.g. `'jpg,jpeg,png,gif'`). |
282
285
  | `images_upload_validate` | `(file: File) => string \| null` | &mdash; | Pre-upload hook; return a message to reject the file, or `null` to allow. |
283
286
  | `images_upload_error` | `(message: string) => void` | &mdash; | Caller-supplied alert for drag-drop/paste upload rejections and failures. |
287
+ | `images_upload_error_message` | `(response: unknown, status: number) => string \| null \| undefined` | &mdash; | Words the message for a failed upload from the server's reply (parsed JSON body, or `null`, and the HTTP status). Return `null`/`undefined` for the editor's own translated message &mdash; see [Image Upload](#image-upload). |
284
288
  | `setup` | `(editor) => void` | &mdash; | Pre-init callback for registering custom toolbar buttons. |
285
289
 
286
290
  ### Dark Theme
@@ -695,7 +699,7 @@ Buttons after `||` begin collapsed behind a toggle (`...`) button.
695
699
  | `link` | Insert/edit hyperlink (with the caret on a link, edits that link in place) |
696
700
  | `unlink` | Remove the link at the cursor |
697
701
  | `anchor` | Insert a named anchor (`<a id>` target) |
698
- | `codesample` | Toggle code sample |
702
+ | `codesample` | Toggle code sample on the lines the selection touches (lines split by Shift+Enter outside the selection stay text) |
699
703
  | `fullscreen` | Toggle fullscreen |
700
704
  | `preview` | Preview in new window (the window carries a Content Security Policy that blocks script) |
701
705
  | `searchreplace` | Find & Replace dialog |
@@ -726,6 +730,44 @@ SVGs are automatically sanitized (script tags, event handlers, and dangerous ele
726
730
  />
727
731
  ```
728
732
 
733
+ Upload failures are shown in the editor's language. When your server explains a refusal in its reply, `images_upload_error_message` lets you word the message yourself. It receives the parsed JSON body (`null` when the body is not JSON) and the HTTP status, and returns the message to show, or `null`/`undefined` to keep the editor's own. It is not called for a network error or an aborted request. The message is shown in the image dialog, and passed to `images_upload_error` for a dropped or pasted image.
734
+
735
+ ```tsx
736
+ <Editor
737
+ config={{
738
+ images_upload_url: '/api/upload',
739
+ // The server answers a refusal with HTTP 200 and {"error": "<reason>"}
740
+ images_upload_error_message: (response) => {
741
+ const error = (response as { error?: unknown } | null)?.error;
742
+ return typeof error === 'string' ? error : null;
743
+ },
744
+ images_upload_error: (message) => showAlert(message),
745
+ }}
746
+ />
747
+ ```
748
+
749
+ ### Resizing Images
750
+
751
+ Click an image in the full editor to select it, and drag one of the eight handles to resize it. Corners keep the aspect ratio (hold Shift to stretch freely), sides change only the width or the height, and Escape cancels the drag. The new size is saved in the image's `width` and `height` attributes, as TinyMCE does, as one undo step that fires `onDirty` and `onChange` like any other edit. Handles are hidden in read-only mode.
752
+
753
+ Resizing is on by default. Set `object_resizing: false` to turn it off, or pass a CSS selector to allow it only for the images that match. The `objectresizestart` and `objectresized` events have no props; register them on the editor in `onInit`:
754
+
755
+ ```tsx
756
+ <Editor
757
+ config={{
758
+ object_resizing: 'img[alt]', // or true (default) / false
759
+ resize_img_proportional: true, // corners keep the aspect ratio (default)
760
+ }}
761
+ onInit={(editor) => {
762
+ editor.on('objectresized', ({ width, height }) => {
763
+ console.log(`Image resized to ${width} × ${height}`);
764
+ });
765
+ }}
766
+ />
767
+ ```
768
+
769
+ Images are inline, as in TinyMCE and mail HTML: a link around an image is kept, and an `<img>` that is not already in a line of text is put in a `<p>` (or a `<div>` with `forced_root_block: 'div'`).
770
+
729
771
  ## Localization
730
772
 
731
773
  ### Set Language at Init
@@ -745,6 +787,8 @@ setTranslate((key) => myTranslations[key] ?? key);
745
787
  <Editor translate={(key) => myTranslations[key] ?? key} config={{}} />
746
788
  ```
747
789
 
790
+ The built-in locale is the fallback: when your function returns an empty string (or, through `setTranslate()`, `null` or `undefined`), the editor shows its own translation for that key. A custom function therefore only needs the strings it wants to change. Keys with a placeholder, such as `Upload failed: {status}` and `Confidence: {percent}%`, must keep it in the translation.
791
+
748
792
  ### Change Language at Runtime
749
793
 
750
794
  ```tsx
@@ -754,6 +798,8 @@ const editorRef = useRef<EditorRef>(null);
754
798
  editorRef.current?.getEditor()?.setLanguage('fr');
755
799
  ```
756
800
 
801
+ `setLanguage()` keeps a custom translate function; it changes only the fallback locale.
802
+
757
803
  ### Supported Languages
758
804
 
759
805
  | Code | Language | Code | Language |
@@ -764,15 +810,15 @@ editorRef.current?.getEditor()?.setLanguage('fr');
764
810
  | `zh` | Chinese | `pt` | Portugues |
765
811
  | `cs` | Cesky | `ro` | Romana |
766
812
  | `da` | Dansk | `ru` | Russian |
767
- | `en-gb` | English (UK) | `sr` | Srpski |
768
- | `fi` | Suomi | `sl` | Slovenscina |
769
- | `fr` | Francais | `es` | Espanol |
770
- | `fr-ca` | Canadien francais | `sv` | Svenska |
771
- | `de` | Deutsch | `zh-tw` | Chinese (Taiwan) |
772
- | `el` | Greek | `th` | Thai |
773
- | `hu` | Magyar | `tr` | Turkce |
774
- | `id` | Bahasa Indonesia | `vi` | Tieng Viet |
775
- | `it` | Italiano | | |
813
+ | `en-gb` | English (UK) | `sr` | Srpski (Cyrillic) |
814
+ | `fi` | Suomi | `sr-latn` | Srpski (latinica) |
815
+ | `fr` | Francais | `sl` | Slovenscina |
816
+ | `fr-ca` | Canadien francais | `es` | Espanol |
817
+ | `de` | Deutsch | `sv` | Svenska |
818
+ | `el` | Greek | `zh-tw` | Chinese (Taiwan) |
819
+ | `hu` | Magyar | `th` | Thai |
820
+ | `id` | Bahasa Indonesia | `tr` | Turkce |
821
+ | `it` | Italiano | `vi` | Tieng Viet |
776
822
  | `ja` | Japanese | | |
777
823
  | `ko` | Korean | | |
778
824
 
@@ -799,6 +845,7 @@ setGetFileSrc((path) => `https://cdn.example.com${path}`);
799
845
  | Ctrl/Cmd + Z | Undo |
800
846
  | Ctrl/Cmd + Shift + Z | Redo |
801
847
  | Ctrl/Cmd + F | Find & Replace |
848
+ | Ctrl + Alt + C (Cmd + Option + C on macOS) | Toggle code sample |
802
849
  | Tab | Increase indent &mdash; nests or indents a list item, moves to the next table cell, inserts a tab in a code block, or indents the block ([details](#lists--indentation)) |
803
850
  | Shift + Tab | Decrease indent &mdash; un-nests a list item, moves to the previous table cell, or removes block indent ([details](#lists--indentation)) |
804
851
  | Esc, then Tab | Move focus to the next element outside the editor (keyboard escape) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdaemon/html-editor-react",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "React wrapper for MDHTMLEditor",
5
5
  "homepage": "https://github.com/mdaemon-technologies/MDHTMLEditor-react",
6
6
  "repository": {
@@ -56,7 +56,7 @@
56
56
  "react-dom": "^19.0.0 || ^18.0.0"
57
57
  },
58
58
  "dependencies": {
59
- "@mdaemon/html-editor": "^1.14.0",
59
+ "@mdaemon/html-editor": "^1.16.0",
60
60
  "@tiptap/react": "^3.32.0"
61
61
  },
62
62
  "devDependencies": {