diff --git a/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts b/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts index 582c60a13702ff99b15dfa35ab59ad577bb40e3d..55aba5c29f213dbe78957d8208f417cccb278291 100644 --- a/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts +++ b/projects/editor/src/app/components/unit-view/page-view/canvas/canvas.component.ts @@ -121,7 +121,7 @@ export class CanvasComponent implements OnInit, OnDestroy { selectElementComponent(element: UIElement): void { const elementComponent = this.getElementComponent(element); if (elementComponent) { - this.selectionService.selectElement({ componentElement: elementComponent, multiSelect: false }); + this.selectionService.selectElement({ elementComponent: elementComponent, multiSelect: false }); } else { throw Error('Element not found. This is a bug!'); } diff --git a/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts b/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts index d7487eddfe13be3c19e8e3fdd0fe3769b1942bfa..4547062e8ccef1fb60c8be64c0ec0e19bba838df 100644 --- a/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts +++ b/projects/editor/src/app/components/unit-view/page-view/canvas/overlays/canvas-element-overlay.ts @@ -39,7 +39,7 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { // Make children not clickable. This way the only relevant events are managed by the overlay. this.childComponent.location.nativeElement.style.pointerEvents = 'none'; - this.selectionService.selectElement({ componentElement: this, multiSelect: false }); + this.selectionService.selectElement({ elementComponent: this, multiSelect: false }); if (this.childComponent.instance instanceof ClozeComponent) { this.childComponent.location.nativeElement.style.pointerEvents = 'unset'; @@ -69,9 +69,9 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { selectElement(multiSelect: boolean = false): void { if (multiSelect) { - this.selectionService.selectElement({ componentElement: this, multiSelect: true }); + this.selectionService.selectElement({ elementComponent: this, multiSelect: true }); } else { - this.selectionService.selectElement({ componentElement: this, multiSelect: false }); + this.selectionService.selectElement({ elementComponent: this, multiSelect: false }); } } diff --git a/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts b/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts index 942ff09f1f8c74ce6c33b40babd749f774ad0306..f7774d056f719347c9815681e13c35afc3b1f6ac 100644 --- a/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts +++ b/projects/editor/src/app/components/unit-view/page-view/canvas/section-menu.component.ts @@ -237,7 +237,7 @@ export class SectionMenuComponent implements OnInit, OnDestroy { this.updateGridSizes(); } - openColorPicker() { + openColorPicker(): void { this.colorPicker.nativeElement.click(); } diff --git a/projects/editor/src/app/services/selection.service.ts b/projects/editor/src/app/services/selection.service.ts index 803446ee0cdfd650cd04a4099af7946239be289e..6c01eead3747c98da8c2f81ad0cdf6b86267b378 100644 --- a/projects/editor/src/app/services/selection.service.ts +++ b/projects/editor/src/app/services/selection.service.ts @@ -24,13 +24,13 @@ export class SelectionService { return this._selectedElements.value; } - selectElement(event: { componentElement: any; multiSelect: boolean }): void { // TODO UIElement statt any + selectElement(event: { elementComponent: any; multiSelect: boolean }): void { if (!event.multiSelect) { this.clearElementSelection(); } this.removeCompoundChildSelection(); - this.selectedElementComponents.push(event.componentElement); - event.componentElement.setSelected(true); + this.selectedElementComponents.push(event.elementComponent); + event.elementComponent.setSelected(true); this._selectedElements.next(this.selectedElementComponents.map(componentElement => componentElement.element)); } diff --git a/projects/editor/src/app/text-editor/font-size-extension.ts b/projects/editor/src/app/text-editor/font-size-extension.ts index efe67d187508740409cda0521d525bb39bff15d9..94bcdaeb73e5c30ae4c9a9ca65102fefbaaf7516 100644 --- a/projects/editor/src/app/text-editor/font-size-extension.ts +++ b/projects/editor/src/app/text-editor/font-size-extension.ts @@ -2,7 +2,7 @@ import { Command } from '@tiptap/core'; import { TextStyle } from '@tiptap/extension-text-style'; declare module '@tiptap/core' { - interface Commands<ReturnType> { + interface Commands<> { fontSizeExtension: { setFontSize: (fontSize: string) => Command }; diff --git a/projects/editor/src/app/text-editor/hanging-indent.ts b/projects/editor/src/app/text-editor/hanging-indent.ts index 71eb3b7e61d0df0c2ef059d6eb5d6e31db05b9a2..428922d58a913b33b331647677af53a8c6e97698 100644 --- a/projects/editor/src/app/text-editor/hanging-indent.ts +++ b/projects/editor/src/app/text-editor/hanging-indent.ts @@ -68,11 +68,12 @@ export const HangingIndent = Extension.create({ const applyIndent: (hangingIndent: boolean, indentSize: number) => () => Command = (hangingIndent, indentSize) => () => ({ tr, state, dispatch }) => { const { selection } = state; - tr = tr.setSelection(selection); - tr = updateIndentLevel(tr, hangingIndent, indentSize); + let transaction; + transaction = tr.setSelection(selection); + transaction = updateIndentLevel(transaction, hangingIndent, indentSize); - if (tr.docChanged) { - dispatch?.(tr); + if (transaction.docChanged) { + dispatch?.(transaction); return true; } diff --git a/projects/editor/src/app/text-editor/indent.ts b/projects/editor/src/app/text-editor/indent.ts index 7bdc5385c3c93d2cdd40189050df69ff5f92c9f3..6d2e196766a32a5a809837168553e8c10f5db539 100644 --- a/projects/editor/src/app/text-editor/indent.ts +++ b/projects/editor/src/app/text-editor/indent.ts @@ -1,5 +1,5 @@ import { Command, Extension } from '@tiptap/core'; -import { TextSelection, AllSelection, Transaction } from 'prosemirror-state'; +import { TextSelection, Transaction } from 'prosemirror-state'; export interface IndentOptions { types: string[]; @@ -56,7 +56,12 @@ export const Indent = Extension.create<IndentOptions>({ if (node) { const nextLevel = (node.attrs.indent || 0) + delta; const { minLevel, maxLevel } = this.options; - const indent = nextLevel < minLevel ? minLevel : nextLevel > maxLevel ? maxLevel : nextLevel; + let indent: number; + if (nextLevel < minLevel) { + indent = minLevel; + } else { + indent = nextLevel > maxLevel ? maxLevel : nextLevel; + } if (indent !== node.attrs.indent) { const nodeAttrs = { ...node.attrs, indent, indentSize }; @@ -68,29 +73,30 @@ export const Indent = Extension.create<IndentOptions>({ const updateIndentLevel = (tr: Transaction, delta: number, indentSize: number): Transaction => { const { doc, selection } = tr; + let transaction = tr; - if (doc && selection && (selection instanceof TextSelection || selection instanceof AllSelection)) { + if (doc && selection && (selection instanceof TextSelection)) { const { from, to } = selection; doc.nodesBetween(from, to, (node, pos) => { if (this.options.types.includes(node.type.name)) { - tr = setNodeIndentMarkup(tr, pos, delta, indentSize); + transaction = setNodeIndentMarkup(tr, pos, delta, indentSize); return false; } - return true; }); } - - return tr; + return transaction; }; + const applyIndent: (direction: number, indentSize: number) => () => Command = (direction, indentSize) => () => ({ tr, state, dispatch }) => { const { selection } = state; - tr = tr.setSelection(selection); - tr = updateIndentLevel(tr, direction, indentSize); + let transaction; + transaction = tr.setSelection(selection); + transaction = updateIndentLevel(transaction, direction, indentSize); - if (tr.docChanged) { - dispatch?.(tr); + if (transaction.docChanged) { + dispatch?.(transaction); return true; } diff --git a/projects/editor/src/app/text-editor/paragraph-extension.ts b/projects/editor/src/app/text-editor/paragraph-extension.ts index c7735e272f38d7fe24c11448a98ab7276e9a96ac..52415f312937196e2506895b343ec587cbcad506 100644 --- a/projects/editor/src/app/text-editor/paragraph-extension.ts +++ b/projects/editor/src/app/text-editor/paragraph-extension.ts @@ -4,7 +4,7 @@ import { Transaction } from 'prosemirror-state'; declare module '@tiptap/core' { interface Commands<ReturnType> { - setMargin: { // TODO customParagraph: { ? + setMargin: { setMargin: (newMargin: number) => ReturnType; }; } @@ -15,9 +15,7 @@ export const customParagraph = Paragraph.extend({ return { margin: { default: 10, - parseHTML: element => { - return Number(element.style.marginBottom.slice(0, -2)); - }, + parseHTML: element => Number(element.style.marginBottom.slice(0, -2)), renderHTML: attributes => ({ style: `margin-bottom: ${attributes.margin}px; margin-top: 0` })