diff --git a/package-lock.json b/package-lock.json index d30ff4c2ca82a18537746eca151164732794cafc..5cc58b2a29f1d6e8a499c0b4840e8ab222449054 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1788,11 +1788,6 @@ "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": { "version": "13.0.0", "resolved": "https://registry.npmjs.org/@ngx-translate/core/-/core-13.0.0.tgz", diff --git a/package.json b/package.json index f483905852f26d1b2dc4f0441532ad62ad105271..dc8e89ac83dc133b8edae38a9f3101c619103917 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "@tiptap/extension-text-align": "^2.0.0-beta.23", "@tiptap/extension-text-style": "^2.0.0-beta.17", "@tiptap/extension-underline": "^2.0.0-beta.16", - "@luciusa/extension-font-size": "^1.0.1", "prosemirror-state": "^1.3.4", "rxjs": "~6.6.0", "tslib": "^2.1.0", diff --git a/projects/editor/src/app/components/unit-view/page-view/font-size-extension.ts b/projects/editor/src/app/components/unit-view/page-view/font-size-extension.ts new file mode 100644 index 0000000000000000000000000000000000000000..c46088d7c666be20236f46ec0c1e077877c29c30 --- /dev/null +++ b/projects/editor/src/app/components/unit-view/page-view/font-size-extension.ts @@ -0,0 +1,30 @@ +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() + }; + } +}); diff --git a/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.html b/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.html index 0755b0c338e278d3c94dacb58b06e5523fbb2ad5..41f5025e62f5f7fb5c92775cd3444e647339ffed 100644 --- a/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.html +++ b/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.html @@ -34,13 +34,14 @@ <div> <mat-form-field> <mat-label>Schriftgröße</mat-label> - <mat-select [value]="'16px'" (valueChange)="applyFontSize($event)"> - <mat-option value="8px">8px</mat-option> - <mat-option value="14px">14px</mat-option> - <mat-option value="16px">16px</mat-option> - <mat-option value="18px">18px</mat-option> - <mat-option value="24px">24px</mat-option> - <mat-option value="36px">36px</mat-option> + <mat-select [value]="editor.getAttributes('textStyle').fontSize?.toString() || ''" + (valueChange)="applyFontSize($event)"> + <mat-option value="8">8px</mat-option> + <mat-option value="14">14px</mat-option> + <mat-option value="16">16px</mat-option> + <mat-option value="18">18px</mat-option> + <mat-option value="24">24px</mat-option> + <mat-option value="36">36px</mat-option> </mat-select> </mat-form-field> <mat-form-field> diff --git a/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.ts b/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.ts index fa1c49480337d0759349c8f98b3144abdd602e13..dce4725595181982e4578cdb326a1561b37a1827 100644 --- a/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.ts +++ b/projects/editor/src/app/components/unit-view/page-view/rich-text-editor.component.ts @@ -10,10 +10,10 @@ import { Subscript } from '@tiptap/extension-subscript'; import { TextStyle } from '@tiptap/extension-text-style'; import { Color } from '@tiptap/extension-color'; import { Highlight } from '@tiptap/extension-highlight'; -import { FontSize } from '@luciusa/extension-font-size'; import { TextAlign } from '@tiptap/extension-text-align'; import { Heading } from '@tiptap/extension-heading'; import { Indent } from './indent'; +import { fontSizeExtension } from './font-size-extension'; @Component({ selector: 'app-rich-text-editor', @@ -27,7 +27,7 @@ export class RichTextEditorComponent implements AfterViewInit { editor = new Editor({ extensions: [StarterKit, Underline, Superscript, Subscript, - TextStyle, Color, FontSize, + TextStyle, Color, Highlight.configure({ multicolor: true }), @@ -43,6 +43,8 @@ export class RichTextEditorComponent implements AfterViewInit { Heading.configure({ levels: [1, 2, 3, 4] }) + }), + fontSizeExtension ] }); @@ -82,8 +84,8 @@ export class RichTextEditorComponent implements AfterViewInit { this.editor.chain().toggleSubscript().focus().run(); } - applyFontSize(size: string): void { - (this.editor.chain().setFontSize(size) as unknown as ChainedCommands).focus().run(); + applyFontSize(size: number): void { + this.editor.commands.setFontSize(size); } applyColor(color: string): void {