@mdaemon/html-editor 1.5.0 → 1.6.1
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 +46 -2
- package/dist/index.d.ts +42 -24
- package/dist/index.js +48548 -50686
- package/dist/index.mjs +48546 -50718
- package/dist/styles.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@mdaemon/html-editor) [](https://packagephobia.com/result?p=@mdaemon/html-editor) [](https://github.com/mdaemon-technologies/MDHTMLEditor/blob/master/LICENSE) [](https://github.com/mdaemon-technologies/MDHTMLEditor/actions/workflows/ci.yml)
|
|
2
|
+
|
|
1
3
|
# MDHTMLEditor
|
|
2
4
|
|
|
3
5
|
A TinyMCE-compatible HTML editor built on TipTap. This is the core vanilla TypeScript package - for React usage, see `@mdaemon/html-editor-react`.
|
|
@@ -95,8 +97,8 @@ const editor = new HTMLEditor(container, {
|
|
|
95
97
|
| `fontSize_sizes` | string | - | CKEditor alias for `font_size_formats` |
|
|
96
98
|
| `block_formats` | string | 'Paragraph=p;Heading 1=h1;…' | Block-format dropdown definitions (`blocks` button) |
|
|
97
99
|
| `style_formats` | StyleFormat[] | *(subset)* | Named styles for the Styles dropdown (`styles` button) |
|
|
98
|
-
| `fontName` | string | - | Default font family |
|
|
99
|
-
| `fontSize` | string |
|
|
100
|
+
| `fontName` | string | `arial, helvetica, sans-serif` | Default font family, inlined on every block element (see [Font Family & Size](#font-family--size)) |
|
|
101
|
+
| `fontSize` | string | `12pt` | Default font size, inlined on every paragraph (see [Font Family & Size](#font-family--size)) |
|
|
100
102
|
| `directionality` | 'ltr' \| 'rtl' | 'ltr' | Text direction |
|
|
101
103
|
| `language` | string | 'en' | UI language code (built-in translations for 31 languages) |
|
|
102
104
|
| `height` | string \| number | 300 | Editor height (fixed) |
|
|
@@ -402,6 +404,48 @@ Tables are resizable by dragging column borders.
|
|
|
402
404
|
|
|
403
405
|
> Note: block elements map to headings/paragraph, `color`/`background-color` map to the editor's text-color/highlight marks, and `classes` apply a CSS class to the selection. Arbitrary element wrapping from CKEditor's stylesSet (e.g. `big`, `tt`, `cite`) is not supported by the underlying TipTap schema.
|
|
404
406
|
|
|
407
|
+
## Font Family & Size
|
|
408
|
+
|
|
409
|
+
The editor inlines a **default font directly on the block elements** of the
|
|
410
|
+
exported HTML so content keeps its font when rendered outside the editor (for
|
|
411
|
+
example, an email body opened in another client that doesn't load the editor's
|
|
412
|
+
CSS). Set the base font with `fontName` / `fontSize`:
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
const editor = new HTMLEditor(container, {
|
|
416
|
+
fontName: 'Georgia, serif',
|
|
417
|
+
fontSize: '14pt',
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
With the config above, `getContent()` produces blocks that carry the font inline:
|
|
422
|
+
|
|
423
|
+
```html
|
|
424
|
+
<p style="font-family: Georgia, serif; font-size: 14pt;">Hello</p>
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
Defaults when the options are omitted: `arial, helvetica, sans-serif` and `12pt`.
|
|
428
|
+
|
|
429
|
+
- `font-family` is inlined on paragraphs **and** headings.
|
|
430
|
+
- `font-size` is inlined on paragraphs only — headings keep their level-based
|
|
431
|
+
sizing (`h1` = 2em, `h2` = 1.5em, …), which a forced default would otherwise
|
|
432
|
+
clobber.
|
|
433
|
+
|
|
434
|
+
**Per-selection changes still work.** Selecting text and picking a font or size
|
|
435
|
+
from the `fontfamily` / `fontsize` toolbar dropdowns (or `execCommand('fontname', …)`
|
|
436
|
+
/ `execCommand('fontsize', …)`) produces an inline `<span>` that overrides the
|
|
437
|
+
block default for just that text — so a single paragraph can mix fonts and sizes:
|
|
438
|
+
|
|
439
|
+
```html
|
|
440
|
+
<p style="font-family: Georgia, serif; font-size: 14pt;">
|
|
441
|
+
this is <span style="font-size: 24pt;">A BIG font</span>, and this is a small font
|
|
442
|
+
</p>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
This is handled by the exported `BlockFontStyle` extension (block defaults) layered
|
|
446
|
+
with the inline `FontSize` mark and TipTap's `FontFamily` mark (per-selection
|
|
447
|
+
overrides).
|
|
448
|
+
|
|
405
449
|
## Read-Only Mode
|
|
406
450
|
|
|
407
451
|
Start the editor read-only with `readonly: true`, or toggle it at runtime. Read-only mode disables editing and dims/blocks the toolbar.
|
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,19 @@ export declare interface AnchorOptions {
|
|
|
33
33
|
/** List of all supported locale codes */
|
|
34
34
|
export declare const availableLocales: string[];
|
|
35
35
|
|
|
36
|
+
export declare const BlockFontStyle: Extension<BlockFontStyleOptions, any>;
|
|
37
|
+
|
|
38
|
+
export declare interface BlockFontStyleOptions {
|
|
39
|
+
/** Node types that receive the default font-family. */
|
|
40
|
+
fontFamilyTypes: string[];
|
|
41
|
+
/** Node types that receive the default font-size. */
|
|
42
|
+
fontSizeTypes: string[];
|
|
43
|
+
/** Default font-family inlined on every matching block. */
|
|
44
|
+
defaultFontFamily: string;
|
|
45
|
+
/** Default font-size inlined on every matching block. */
|
|
46
|
+
defaultFontSize: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
declare type BlurCallback = () => void;
|
|
37
50
|
|
|
38
51
|
declare type ChangeCallback = (content: string) => void;
|
|
@@ -172,6 +185,11 @@ export declare interface EditorConfig {
|
|
|
172
185
|
* 'p' (default) emits <p>; 'div' emits <div> (CKEditor ENTER_DIV parity).
|
|
173
186
|
*/
|
|
174
187
|
forced_root_block?: 'p' | 'div';
|
|
188
|
+
/**
|
|
189
|
+
* Append an empty trailing paragraph when the document ends in a block node
|
|
190
|
+
* (table, image, code block, etc.) so the cursor can be placed after it.
|
|
191
|
+
* Disabled by default.
|
|
192
|
+
*/
|
|
175
193
|
trailingNode?: boolean;
|
|
176
194
|
includeTemplates?: boolean;
|
|
177
195
|
templates?: Template[];
|
|
@@ -828,22 +846,6 @@ export declare interface UIRegistry {
|
|
|
828
846
|
export { }
|
|
829
847
|
|
|
830
848
|
|
|
831
|
-
declare module '@tiptap/core' {
|
|
832
|
-
interface Commands<ReturnType> {
|
|
833
|
-
fontSize: {
|
|
834
|
-
/**
|
|
835
|
-
* Set the font size
|
|
836
|
-
*/
|
|
837
|
-
setFontSize: (size: string) => ReturnType;
|
|
838
|
-
/**
|
|
839
|
-
* Unset the font size
|
|
840
|
-
*/
|
|
841
|
-
unsetFontSize: () => ReturnType;
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
|
|
847
849
|
declare module '@tiptap/core' {
|
|
848
850
|
interface Commands<ReturnType> {
|
|
849
851
|
lineHeight: {
|
|
@@ -878,9 +880,11 @@ declare module '@tiptap/core' {
|
|
|
878
880
|
|
|
879
881
|
declare module '@tiptap/core' {
|
|
880
882
|
interface Commands<ReturnType> {
|
|
881
|
-
|
|
882
|
-
/**
|
|
883
|
-
|
|
883
|
+
inlineStyle: {
|
|
884
|
+
/** Apply a CSS class to the current selection via the textStyle mark. */
|
|
885
|
+
setInlineClass: (className: string) => ReturnType;
|
|
886
|
+
/** Remove the textStyle class. */
|
|
887
|
+
unsetInlineClass: () => ReturnType;
|
|
884
888
|
};
|
|
885
889
|
}
|
|
886
890
|
}
|
|
@@ -888,11 +892,25 @@ declare module '@tiptap/core' {
|
|
|
888
892
|
|
|
889
893
|
declare module '@tiptap/core' {
|
|
890
894
|
interface Commands<ReturnType> {
|
|
891
|
-
|
|
892
|
-
/**
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
895
|
+
fontSize: {
|
|
896
|
+
/**
|
|
897
|
+
* Set the font size
|
|
898
|
+
*/
|
|
899
|
+
setFontSize: (size: string) => ReturnType;
|
|
900
|
+
/**
|
|
901
|
+
* Unset the font size
|
|
902
|
+
*/
|
|
903
|
+
unsetFontSize: () => ReturnType;
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
|
|
909
|
+
declare module '@tiptap/core' {
|
|
910
|
+
interface Commands<ReturnType> {
|
|
911
|
+
anchor: {
|
|
912
|
+
/** Insert a named anchor at the cursor. */
|
|
913
|
+
setAnchor: (name: string) => ReturnType;
|
|
896
914
|
};
|
|
897
915
|
}
|
|
898
916
|
}
|