@mdaemon/html-editor-react 1.4.1 → 1.5.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 +75 -4
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -224,8 +224,8 @@ The `config` prop (or `useEditor`'s `config` option) accepts an `EditorConfig` o
|
|
|
224
224
|
| `skin` | `'oxide' \| 'oxide-dark' \| 'confab' \| 'confab-dark'` | `'oxide'` | Toolbar and dialog theme. |
|
|
225
225
|
| `content_css` | `'default' \| 'dark' \| 'confab' \| 'confab-dark'` | `'default'` | Content area theme. |
|
|
226
226
|
| `content_style` | `string` | — | Custom CSS injected into the editing surface. |
|
|
227
|
-
| `fontName` | `string` |
|
|
228
|
-
| `fontSize` | `string` |
|
|
227
|
+
| `fontName` | `string` | `'arial, helvetica, sans-serif'` | Default font family. Inlined on every block in the exported HTML — see [Fonts](#fonts). |
|
|
228
|
+
| `fontSize` | `string` | `'12pt'` | Default font size. Inlined on every paragraph in the exported HTML — see [Fonts](#fonts). |
|
|
229
229
|
| `font_family_formats` | `string` | *(TinyMCE defaults)* | Semicolon-delimited font list (`Name=family,...`). |
|
|
230
230
|
| `font_size_formats` | `string` | `'8pt 9pt 10pt 12pt 14pt 18pt 24pt 36pt'` | Space-delimited size options. |
|
|
231
231
|
| `font_names` | `string` | — | CKEditor alias for `font_family_formats`. |
|
|
@@ -336,6 +336,77 @@ const isReadOnly = editorRef.current?.getEditor()?.isReadOnly();
|
|
|
336
336
|
|
|
337
337
|
> The `disabled` prop applies a lightweight visual lock (pointer-events off, reduced opacity). For true non-editable behavior that also dims the toolbar, prefer `readonly` / `setReadOnly()`.
|
|
338
338
|
|
|
339
|
+
## Fonts
|
|
340
|
+
|
|
341
|
+
`fontName` and `fontSize` set the editor's default font. The defaults are written directly onto each block in the exported HTML (`font-family` on `<p>`/`<div>`/`<hN>`, `font-size` on `<p>`/`<div>`) rather than relying on the editor's stylesheet being present, so the content keeps its font when it is rendered somewhere else — an email body opened in another client, for example. Headings keep their level-based sizing and carry no block `font-size`.
|
|
342
|
+
|
|
343
|
+
```tsx
|
|
344
|
+
<Editor
|
|
345
|
+
config={{
|
|
346
|
+
fontName: 'Georgia, serif',
|
|
347
|
+
fontSize: '14pt',
|
|
348
|
+
}}
|
|
349
|
+
/>
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Selecting text and picking a font or size from the `fontfamily` / `fontsize` toolbar dropdowns produces an inline `<span>` that overrides the block default, so a single paragraph can mix fonts and sizes.
|
|
353
|
+
|
|
354
|
+
### The Toolbar Shows the Font at the Cursor
|
|
355
|
+
|
|
356
|
+
The `fontfamily` and `fontsize` toolbar buttons display the value in effect at the cursor — "Georgia", "14pt" — and update as the caret moves, instead of showing the static words "Font" and "Font size". A family is shown by its configured name (the label side of `font_family_formats`); a font that is not in the configured list, such as one pasted in from another editor, is shown by its first family name. Labels are width-constrained and ellipsized so the toolbar does not reflow as the caret moves, with the full text on each button's `title`.
|
|
357
|
+
|
|
358
|
+
Where no single value applies, the button falls back to the generic word. That happens for a selection spanning two different fonts or sizes, and for font size inside a heading.
|
|
359
|
+
|
|
360
|
+
> This is styled by rules in `@mdaemon/html-editor/dist/styles.css` — make sure the [stylesheet import](#styles) is present, and re-check any custom CSS you have layered on top of the toolbar buttons.
|
|
361
|
+
|
|
362
|
+
### Reading the Current Font
|
|
363
|
+
|
|
364
|
+
`getFontFamily()` and `getFontSize()` report the font in effect at the cursor, resolving an inline `<span>` override first, then the block's own font, then the configured default:
|
|
365
|
+
|
|
366
|
+
```tsx
|
|
367
|
+
const editor = editorRef.current?.getEditor();
|
|
368
|
+
|
|
369
|
+
const family = editor?.getFontFamily(); // e.g. 'Georgia, serif'
|
|
370
|
+
const size = editor?.getFontSize(); // e.g. '14pt'
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Use these to drive a custom font picker outside the toolbar. Unlike reading the inline mark directly, they still return a value when the font comes from the block or the configured default.
|
|
374
|
+
|
|
375
|
+
Both return `''` when there is no single value to report:
|
|
376
|
+
|
|
377
|
+
- the selection spans more than one font family / size
|
|
378
|
+
- for `getFontSize()`, the cursor is in a heading with no inline override (headings size by level and carry no block `font-size`)
|
|
379
|
+
|
|
380
|
+
Treat `''` as "mixed / not applicable" and blank your picker, rather than falling back to a default — that is what the toolbar does.
|
|
381
|
+
|
|
382
|
+
The editor emits no selection event of its own, so subscribe on the TipTap instance to keep a readout in sync with the caret:
|
|
383
|
+
|
|
384
|
+
```tsx
|
|
385
|
+
const handleInit = useCallback((editor: HTMLEditor) => {
|
|
386
|
+
const sync = () => {
|
|
387
|
+
setFamily(editor.getFontFamily());
|
|
388
|
+
setSize(editor.getFontSize());
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
sync();
|
|
392
|
+
editor.getTipTap()?.on('selectionUpdate', sync);
|
|
393
|
+
editor.getTipTap()?.on('transaction', sync);
|
|
394
|
+
}, []);
|
|
395
|
+
|
|
396
|
+
<Editor config={{ fontName: 'Georgia, serif', fontSize: '14pt' }} onInit={handleInit} />
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Setting a Block Font
|
|
400
|
+
|
|
401
|
+
To change the font on every block the selection touches — instead of adding an inline override — use the `setBlockFontFamily` / `setBlockFontSize` commands on the underlying TipTap instance:
|
|
402
|
+
|
|
403
|
+
```tsx
|
|
404
|
+
const tiptap = editorRef.current?.getEditor()?.getTipTap();
|
|
405
|
+
|
|
406
|
+
tiptap?.chain().focus().setBlockFontFamily('Georgia, serif').run();
|
|
407
|
+
tiptap?.chain().focus().setBlockFontSize('14pt').run();
|
|
408
|
+
```
|
|
409
|
+
|
|
339
410
|
## Templates
|
|
340
411
|
|
|
341
412
|
Enable the template dropdown and provide a `templates` array:
|
|
@@ -666,7 +737,7 @@ A demo app is included to see the editor in action:
|
|
|
666
737
|
npm run demo
|
|
667
738
|
```
|
|
668
739
|
|
|
669
|
-
This starts a Vite dev server at `http://localhost:5173` with
|
|
740
|
+
This starts a Vite dev server at `http://localhost:5173` with three sections: the `<Editor>` component, the `useEditor` hook, and a [Fonts](#fonts) panel with a live `getFontFamily()` / `getFontSize()` readout that follows the cursor and buttons for the block-font commands.
|
|
670
741
|
|
|
671
742
|
## Development
|
|
672
743
|
|
|
@@ -680,7 +751,7 @@ The package is bundled with [Vite 8](https://vite.dev/) (Rolldown) and ships ES,
|
|
|
680
751
|
| `npm test` | Run the Jest test suite. |
|
|
681
752
|
| `npm run test:coverage` | Run tests with coverage. |
|
|
682
753
|
| `npm run lint` | Lint `src` with ESLint. |
|
|
683
|
-
| `npm run typecheck` | Type-check with `tsc --noEmit`. |
|
|
754
|
+
| `npm run typecheck` | Type-check `src` and `demo` with `tsc --noEmit`. |
|
|
684
755
|
| `npm run demo` | Launch the demo app. |
|
|
685
756
|
|
|
686
757
|
> **Node.js:** building the package requires Node `^20.19.0 || >=22.12.0` (a Vite 8 requirement). Consumers of the published package are unaffected.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdaemon/html-editor-react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "React wrapper for MDHTMLEditor",
|
|
5
5
|
"homepage": "https://github.com/mdaemon-technologies/MDHTMLEditor-react",
|
|
6
6
|
"repository": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"react-dom": "^19.0.0 || ^18.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@mdaemon/html-editor": "^1.
|
|
57
|
-
"@tiptap/react": "^3.
|
|
56
|
+
"@mdaemon/html-editor": "^1.9.0",
|
|
57
|
+
"@tiptap/react": "^3.27.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@eslint/js": "^9.39.4",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"vite-plugin-dts": "^5.0.2"
|
|
81
81
|
},
|
|
82
82
|
"allowScripts": {
|
|
83
|
-
"@swc/core
|
|
84
|
-
"esbuild
|
|
85
|
-
"unrs-resolver
|
|
83
|
+
"@swc/core": true,
|
|
84
|
+
"esbuild": true,
|
|
85
|
+
"unrs-resolver": true
|
|
86
86
|
}
|
|
87
87
|
}
|