Skip to content
Snippets Groups Projects
Commit a293dac0 authored by rhenck's avatar rhenck
Browse files

Merge branch 'texteditor-extension'

parents ae9c51a5 73bbf0eb
No related branches found
No related tags found
No related merge requests found
...@@ -1788,11 +1788,6 @@ ...@@ -1788,11 +1788,6 @@
"schema-utils": "^2.7.0" "schema-utils": "^2.7.0"
} }
}, },
"@luciusa/extension-font-size": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@luciusa/extension-font-size/-/extension-font-size-1.0.1.tgz",
"integrity": "sha512-5pQe4hAiH3KQRDzfKYAxwkwb+hgOBF9aPrPcFBn1rv0VfXV/h5yyWwPHAoFov4Pjo8zJOpGO3ZUFMvXHzuMLmQ=="
},
"@ngx-translate/core": { "@ngx-translate/core": {
"version": "13.0.0", "version": "13.0.0",
"resolved": "https://registry.npmjs.org/@ngx-translate/core/-/core-13.0.0.tgz", "resolved": "https://registry.npmjs.org/@ngx-translate/core/-/core-13.0.0.tgz",
......
import { Command } from '@tiptap/core';
import { TextStyle } from '@tiptap/extension-text-style';
declare module '@tiptap/core' {
interface Commands<ReturnType> {
fontSizeExtension: {
setFontSize: (fontSize: number) => Command
};
}
}
export const fontSizeExtension = TextStyle.extend({
addAttributes() {
return {
fontSize: {
default: null,
parseHTML: element => Number(element.style.fontSize.slice(0, -2)),
renderHTML: attributes => ({
style: `font-size: ${attributes.fontSize}px`
})
}
};
},
addCommands() {
return {
setFontSize: fontSize => ({ chain }) => chain().setMark('textStyle', { fontSize }).run()
};
}
});
...@@ -34,13 +34,14 @@ ...@@ -34,13 +34,14 @@
<div> <div>
<mat-form-field> <mat-form-field>
<mat-label>Schriftgröße</mat-label> <mat-label>Schriftgröße</mat-label>
<mat-select [value]="'16px'" (valueChange)="applyFontSize($event)"> <mat-select [value]="editor.getAttributes('textStyle').fontSize?.toString() || ''"
<mat-option value="8px">8px</mat-option> (valueChange)="applyFontSize($event)">
<mat-option value="14px">14px</mat-option> <mat-option value="8">8px</mat-option>
<mat-option value="16px">16px</mat-option> <mat-option value="14">14px</mat-option>
<mat-option value="18px">18px</mat-option> <mat-option value="16">16px</mat-option>
<mat-option value="24px">24px</mat-option> <mat-option value="18">18px</mat-option>
<mat-option value="36px">36px</mat-option> <mat-option value="24">24px</mat-option>
<mat-option value="36">36px</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<mat-form-field> <mat-form-field>
......
...@@ -10,10 +10,10 @@ import { Subscript } from '@tiptap/extension-subscript'; ...@@ -10,10 +10,10 @@ import { Subscript } from '@tiptap/extension-subscript';
import { TextStyle } from '@tiptap/extension-text-style'; import { TextStyle } from '@tiptap/extension-text-style';
import { Color } from '@tiptap/extension-color'; import { Color } from '@tiptap/extension-color';
import { Highlight } from '@tiptap/extension-highlight'; import { Highlight } from '@tiptap/extension-highlight';
import { FontSize } from '@luciusa/extension-font-size';
import { TextAlign } from '@tiptap/extension-text-align'; import { TextAlign } from '@tiptap/extension-text-align';
import { Heading } from '@tiptap/extension-heading'; import { Heading } from '@tiptap/extension-heading';
import { Indent } from './indent'; import { Indent } from './indent';
import { fontSizeExtension } from './font-size-extension';
@Component({ @Component({
selector: 'app-rich-text-editor', selector: 'app-rich-text-editor',
...@@ -27,7 +27,7 @@ export class RichTextEditorComponent implements AfterViewInit { ...@@ -27,7 +27,7 @@ export class RichTextEditorComponent implements AfterViewInit {
editor = new Editor({ editor = new Editor({
extensions: [StarterKit, Underline, Superscript, Subscript, extensions: [StarterKit, Underline, Superscript, Subscript,
TextStyle, Color, FontSize, TextStyle, Color,
Highlight.configure({ Highlight.configure({
multicolor: true multicolor: true
}), }),
...@@ -43,6 +43,8 @@ export class RichTextEditorComponent implements AfterViewInit { ...@@ -43,6 +43,8 @@ export class RichTextEditorComponent implements AfterViewInit {
Heading.configure({ Heading.configure({
levels: [1, 2, 3, 4] levels: [1, 2, 3, 4]
}) })
}),
fontSizeExtension
] ]
}); });
...@@ -82,8 +84,8 @@ export class RichTextEditorComponent implements AfterViewInit { ...@@ -82,8 +84,8 @@ export class RichTextEditorComponent implements AfterViewInit {
this.editor.chain().toggleSubscript().focus().run(); this.editor.chain().toggleSubscript().focus().run();
} }
applyFontSize(size: string): void { applyFontSize(size: number): void {
(this.editor.chain().setFontSize(size) as unknown as ChainedCommands).focus().run(); this.editor.commands.setFontSize(size);
} }
applyColor(color: string): void { applyColor(color: string): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment