Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed May 16, 2021
1 parent cc1f8da commit 5620ba3
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 151 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
}
};
12 changes: 6 additions & 6 deletions projects/demo/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { NgxTiptapModule } from 'ngx-tiptap';
import { CommonModule } from '@angular/common';

describe('AppComponent', () => {
let fixture: ComponentFixture<AppComponent>
let app: AppComponent
let fixture: ComponentFixture<AppComponent>;
let app: AppComponent;

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -31,16 +31,16 @@ describe('AppComponent', () => {
beforeEach(() => {
app.editor = new Editor({
extensions: [StarterKit]
})
});

fixture.detectChanges()
})
fixture.detectChanges();
});

it('should create the app', () => {
expect(app).toBeTruthy();
});

it(`should render the editor`, () => {
expect(fixture.debugElement.query(By.css('.ProseMirror'))).toBeTruthy()
expect(fixture.debugElement.query(By.css('.ProseMirror'))).toBeTruthy();
});
});
6 changes: 3 additions & 3 deletions projects/demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Injector, OnInit, ViewEncapsulation } from '@angular/core';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit'
import Placeholder from '@tiptap/extension-placeholder'
import StarterKit from '@tiptap/starter-kit';
import Placeholder from '@tiptap/extension-placeholder';

import { AngularComponent, AngularEditableComponent } from './extensions';

Expand Down Expand Up @@ -74,6 +74,6 @@ export class AppComponent implements OnInit {
class: 'p-2 border-black focus:border-blue-700 border-2 rounded-md outline-none'
}
}
})
});
}
}
32 changes: 16 additions & 16 deletions projects/demo/src/app/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injector } from '@angular/core'
import { Node, mergeAttributes } from '@tiptap/core'
import { AngularNodeViewRenderer } from 'ngx-tiptap'
import { Injector } from '@angular/core';
import { Node, mergeAttributes } from '@tiptap/core';
import { AngularNodeViewRenderer } from 'ngx-tiptap';

import { NodeviewCounterComponent } from './nodeviews/counter/counter.component'
import { NodeviewEditableComponent } from './nodeviews/editable/editable.component'
import { NodeviewCounterComponent } from './nodeviews/counter/counter.component';
import { NodeviewEditableComponent } from './nodeviews/editable/editable.component';

export const AngularComponent = (injector: Injector): Node => {
return Node.create({
Expand All @@ -17,26 +17,26 @@ export const AngularComponent = (injector: Injector): Node => {
count: {
default: 0,
},
}
};
},

parseHTML() {
return [
{
tag: 'angular-component-counter',
},
]
];
},

renderHTML({ HTMLAttributes }) {
return ['angular-component-counter', mergeAttributes(HTMLAttributes)]
return ['angular-component-counter', mergeAttributes(HTMLAttributes)];
},

addNodeView() {
return AngularNodeViewRenderer(NodeviewCounterComponent, { injector })
return AngularNodeViewRenderer(NodeviewCounterComponent, { injector });
},
})
}
});
};

export const AngularEditableComponent = (injector: Injector): Node => {
return Node.create({
Expand All @@ -45,15 +45,15 @@ export const AngularEditableComponent = (injector: Injector): Node => {
content: 'inline*',

parseHTML() {
return [{ tag: 'angular-component-editable' }]
return [{ tag: 'angular-component-editable' }];
},

renderHTML({ HTMLAttributes }) {
return ['angular-component-editable', mergeAttributes(HTMLAttributes), 0]
return ['angular-component-editable', mergeAttributes(HTMLAttributes), 0];
},

addNodeView() {
return AngularNodeViewRenderer(NodeviewEditableComponent, { injector })
return AngularNodeViewRenderer(NodeviewEditableComponent, { injector });
},
})
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class NodeviewCounterComponent extends AngularNodeViewComponent {
increment(): void {
this.props.updateAttributes({
count: this.props.node.attrs.count + 1
})
});
}
}
12 changes: 6 additions & 6 deletions projects/ngx-tiptap/src/lib/AngularRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export class AngularRenderer<C> {
private componentRef: ComponentRef<C>

constructor(component: Type<C>, injector: Injector) {
this.applicationRef = injector.get(ApplicationRef)
this.applicationRef = injector.get(ApplicationRef);

const componentFactoryResolver = injector.get(ComponentFactoryResolver)
const componentFactoryResolver = injector.get(ComponentFactoryResolver);
const factory = componentFactoryResolver.resolveComponentFactory(component);

this.componentRef = factory.create(injector, []);
Expand All @@ -20,22 +20,22 @@ export class AngularRenderer<C> {
}

get instance(): C {
return this.componentRef.instance
return this.componentRef.instance;
}

get elementRef(): ElementRef {
return this.componentRef.injector.get(ElementRef)
return this.componentRef.injector.get(ElementRef);
}

get dom(): HTMLElement {
return this.elementRef.nativeElement
return this.elementRef.nativeElement;
}

detectChanges():void {
this.componentRef.changeDetectorRef.detectChanges();
}

destroy(): void {
this.applicationRef.detachView(this.componentRef.hostView)
this.applicationRef.detachView(this.componentRef.hostView);
}
}
58 changes: 29 additions & 29 deletions projects/ngx-tiptap/src/lib/NodeViewRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, Injector, Input, Type } from "@angular/core";
import { Editor, NodeView, NodeViewProps, NodeViewRenderer, NodeViewRendererProps } from "@tiptap/core";
import { Decoration, NodeView as ProseMirrorNodeView } from 'prosemirror-view'
import { Node as ProseMirrorNode } from 'prosemirror-model'
import { Decoration, NodeView as ProseMirrorNodeView } from 'prosemirror-view';
import { Node as ProseMirrorNode } from 'prosemirror-model';
import { AngularRenderer } from "./AngularRenderer";

@Component({ template: '' })
Expand All @@ -20,7 +20,7 @@ class AngularNodeView extends NodeView<Type<AngularNodeViewComponent>, Editor> i
contentDOMElement: HTMLElement | null

mount() {
const injector = (this.options as AngularNodeViewRendererOptions).injector as Injector
const injector = (this.options as AngularNodeViewRendererOptions).injector as Injector;

const props: NodeViewProps = {
editor: this.editor,
Expand All @@ -30,93 +30,93 @@ class AngularNodeView extends NodeView<Type<AngularNodeViewComponent>, Editor> i
extension: this.extension,
getPos: () => this.getPos(),
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
}
};

// create renderer
this.renderer = new AngularRenderer(this.component, injector)
this.renderer = new AngularRenderer(this.component, injector);

// Pass input props to the component
this.renderer.instance.props = props
this.renderer.instance.props = props;

if (this.extension.config.draggable) {
// Register drag handler
this.renderer.elementRef.nativeElement.ondragstart = (e: DragEvent) => {
this.onDragStart(e)
}
this.onDragStart(e);
};
}

this.contentDOMElement = this.node.isLeaf ? null : document.createElement(this.node.isInline ? 'span' : 'div')
this.contentDOMElement = this.node.isLeaf ? null : document.createElement(this.node.isInline ? 'span' : 'div');

if (this.contentDOMElement) {
// For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
// With this fix it seems to work fine
// See: https://github.com/ueberdosis/tiptap/issues/1197
this.contentDOMElement.style.whiteSpace = 'inherit'
this.contentDOMElement.style.whiteSpace = 'inherit';

this.renderer.detectChanges();
}

// attach stopEvent
if (this.options.stopEvent) {
this.stopEvent = this.options.stopEvent
this.stopEvent = this.options.stopEvent;
}
}

private updateProps(props: Partial<NodeViewProps>) {
this.renderer.instance.props = {
...this.renderer.instance.props,
...props
}
};
}

get dom() {
return this.renderer.dom
return this.renderer.dom;
}

get contentDOM() {
if (this.node.isLeaf) {
return null
return null;
}

const contentElement = this.dom.querySelector('[data-node-view-content]')
const contentElement = this.dom.querySelector('[data-node-view-content]');

if (
this.contentDOMElement
&& contentElement
&& !contentElement.contains(this.contentDOMElement)
) {
contentElement.appendChild(this.contentDOMElement)
contentElement.appendChild(this.contentDOMElement);
}

return this.contentDOMElement
return this.contentDOMElement;
}

update(node: ProseMirrorNode, decorations: Decoration[]): boolean {
if (this.options.update) {
return this.options.update(node, decorations)
return this.options.update(node, decorations);
}

if (node.type !== this.node.type) {
return false
return false;
}

if (node === this.node && this.decorations === decorations) {
return true
return true;
}

this.node = node
this.decorations = decorations
this.updateProps({ node, decorations })
this.node = node;
this.decorations = decorations;
this.updateProps({ node, decorations });

return true
return true;
}

selectNode() {
this.updateProps({ selected: true })
this.updateProps({ selected: true });
}

deselectNode() {
this.updateProps({ selected: false })
this.updateProps({ selected: false });
}

destroy() {
Expand All @@ -126,6 +126,6 @@ class AngularNodeView extends NodeView<Type<AngularNodeViewComponent>, Editor> i

export const AngularNodeViewRenderer = (component: Type<AngularNodeViewComponent>, options: AngularNodeViewRendererOptions): NodeViewRenderer => {
return (props: NodeViewRendererProps) => {
return new AngularNodeView(component, props, options) as ProseMirrorNodeView
}
}
return new AngularNodeView(component, props, options) as ProseMirrorNodeView;
};
};
20 changes: 10 additions & 10 deletions projects/ngx-tiptap/src/lib/bubble-menu.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ describe('BubbleMenuDirective', () => {
]
});

await TestBed.compileComponents()
await TestBed.compileComponents();

fixture = TestBed.createComponent(TestComponent)
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;

const editor = new Editor({
extensions: [StarterKit]
})
});

component.editor = editor
fixture.detectChanges()
component.editor = editor;
fixture.detectChanges();
});

it('should create an instance', () => {
Expand All @@ -50,11 +50,11 @@ describe('BubbleMenuDirective', () => {
});

it('should create bubble menu', () => {
expect(fixture.debugElement.query(By.css('[data-tippy-root]'))).toBeFalsy()
expect(fixture.debugElement.query(By.css('[data-tippy-root]'))).toBeFalsy();

component.editor.chain().setContent('Hello world').focus().selectAll().run()
fixture.detectChanges()
component.editor.chain().setContent('Hello world').focus().selectAll().run();
fixture.detectChanges();

expect(fixture.debugElement.query(By.css('[data-tippy-root]'))).toBeTruthy()
})
expect(fixture.debugElement.query(By.css('[data-tippy-root]'))).toBeTruthy();
});
});
8 changes: 4 additions & 4 deletions projects/ngx-tiptap/src/lib/bubble-menu.directive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive, ElementRef, Input, OnDestroy, OnInit } from '@angular/core';
import { Editor } from '@tiptap/core';
import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';

@Directive({
selector: 'tiptap-bubble-menu[editor], [tiptapBubbleMenu][editor]'
Expand All @@ -13,17 +13,17 @@ export class BubbleMenuDirective implements OnInit, OnDestroy {

ngOnInit(): void {
if (!this.editor) {
throw new Error('Required: Input `editor`')
throw new Error('Required: Input `editor`');
}

this.editor.registerPlugin(BubbleMenuPlugin({
editor: this.editor,
element: this._el.nativeElement,
tippyOptions: this.tippyOptions
}))
}));
}

ngOnDestroy(): void {
this.editor.unregisterPlugin(BubbleMenuPluginKey)
this.editor.unregisterPlugin(BubbleMenuPluginKey);
}
}
Loading

0 comments on commit 5620ba3

Please sign in to comment.