Initial editor functionality
This commit is contained in:
13
src/app/components/editor/host/host.component.html
Normal file
13
src/app/components/editor/host/host.component.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<ng-container>
|
||||
<div
|
||||
*ngIf="record.type === 'paragraph' || record.type === 'header1' || record.type === 'header2' || record.type === 'header3' || record.type === 'header4' || record.type === 'block_code'"
|
||||
class="host-host ion-padding"
|
||||
contenteditable="true"
|
||||
(keyup)="onKeyUp($event)"
|
||||
(blur)="record.value=hostContainer.innerText"
|
||||
#hostContainer
|
||||
[ngClass]="{'paragraph': record.type === 'paragraph', 'header1': record.type === 'header1', 'header2': record.type === 'header2', 'header3': record.type === 'header3', 'header4': record.type === 'header4', 'block_code': record.type === 'block_code'}"
|
||||
>
|
||||
{{ record.value }}
|
||||
</div>
|
||||
</ng-container>
|
||||
26
src/app/components/editor/host/host.component.scss
Normal file
26
src/app/components/editor/host/host.component.scss
Normal file
@@ -0,0 +1,26 @@
|
||||
.host-host.header1 {
|
||||
font-weight: bold;
|
||||
font-size: 24pt;
|
||||
}
|
||||
|
||||
.host-host.header2 {
|
||||
font-weight: bold;
|
||||
font-size: 21pt;
|
||||
}
|
||||
|
||||
.host-host.header3 {
|
||||
font-weight: bold;
|
||||
font-size: 18pt;
|
||||
}
|
||||
|
||||
.host-host.header4 {
|
||||
font-weight: bold;
|
||||
font-size: 16pt;
|
||||
}
|
||||
|
||||
.host-host.block_code {
|
||||
font-family: monospace;
|
||||
font-size: 12pt;
|
||||
background-color: #ddd;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
24
src/app/components/editor/host/host.component.spec.ts
Normal file
24
src/app/components/editor/host/host.component.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { HostComponent } from './host.component';
|
||||
|
||||
describe('HostComponent', () => {
|
||||
let component: HostComponent;
|
||||
let fixture: ComponentFixture<HostComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ HostComponent ],
|
||||
imports: [IonicModule.forRoot()]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(HostComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
48
src/app/components/editor/host/host.component.ts
Normal file
48
src/app/components/editor/host/host.component.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
|
||||
import HostRecord from '../../../structures/HostRecord';
|
||||
|
||||
@Component({
|
||||
selector: 'editor-host',
|
||||
templateUrl: './host.component.html',
|
||||
styleUrls: ['./host.component.scss'],
|
||||
})
|
||||
export class HostComponent implements OnInit {
|
||||
@Input() record: HostRecord;
|
||||
@Output() recordChange = new EventEmitter<HostRecord>();
|
||||
@Output() newHostRequested = new EventEmitter<HostComponent>();
|
||||
@Output() destroyHostRequested = new EventEmitter<HostComponent>();
|
||||
@ViewChild('hostContainer', {static: false}) hostContainer: ElementRef;
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
onKeyUp($event) {
|
||||
const innerText = this.hostContainer.nativeElement.innerText.trim()
|
||||
if ( $event.code === 'Enter'
|
||||
&& ( this.record.type !== 'block_code'
|
||||
|| (innerText.endsWith('```') && (innerText.match(/`/g) || []).length >= 6)
|
||||
)
|
||||
) {
|
||||
this.newHostRequested.emit(this);
|
||||
this.hostContainer.nativeElement.innerText = this.hostContainer.nativeElement.innerText.trim();
|
||||
} else if ( $event.code === 'Backspace' && !this.hostContainer.nativeElement.innerText.trim() ) {
|
||||
this.destroyHostRequested.emit(this);
|
||||
}
|
||||
|
||||
if ( innerText.startsWith('# ') ) {
|
||||
this.record.type = 'header1';
|
||||
} else if ( innerText.startsWith('## ') ) {
|
||||
this.record.type = 'header2';
|
||||
} else if ( innerText.startsWith('### ') ) {
|
||||
this.record.type = 'header3';
|
||||
} else if ( innerText.startsWith('#### ') ) {
|
||||
this.record.type = 'header4';
|
||||
} else if ( innerText.startsWith('```') ) {
|
||||
this.record.type = 'block_code';
|
||||
} else {
|
||||
this.record.type = 'paragraph';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<p>
|
||||
paragraph works!
|
||||
</p>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { ParagraphComponent } from './paragraph.component';
|
||||
|
||||
describe('ParagraphComponent', () => {
|
||||
let component: ParagraphComponent;
|
||||
let fixture: ComponentFixture<ParagraphComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ParagraphComponent ],
|
||||
imports: [IonicModule.forRoot()]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ParagraphComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
14
src/app/components/editor/paragraph/paragraph.component.ts
Normal file
14
src/app/components/editor/paragraph/paragraph.component.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-paragraph',
|
||||
templateUrl: './paragraph.component.html',
|
||||
styleUrls: ['./paragraph.component.scss'],
|
||||
})
|
||||
export class ParagraphComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
|
||||
ngOnInit() {}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user