Start adding editor, fix up sidebar styling

This commit is contained in:
2024-06-22 14:19:23 +09:30
parent c9c7878263
commit 9c2531a034
24 changed files with 489 additions and 81 deletions

View File

@@ -1,3 +0,0 @@
:host {
display: block;
}

View File

@@ -1 +1,3 @@
<textarea [(ngModel)]="fileContents" disabled></textarea>
<!-- <div>@for (item of items; track $index) {} @switch () {}</div> -->
<pre><code class="language-json" #code>{{fileContents()}}</code></pre>

View File

@@ -1,3 +0,0 @@
:host {
display: block;
}

View File

@@ -1,8 +1,9 @@
import { CommonModule } from '@angular/common';
import { Component, input } from '@angular/core';
import { Component, ElementRef, effect, input, viewChild } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { readTextFile } from '@tauri-apps/api/fs';
import { parse } from 'protobufjs';
import hljs from 'highlight.js/lib/core';
import { ProtoMessage } from '../model/proto-message.model';
import { ProtoDefinitionService } from '../proto-definition.service';
@Component({
selector: 'app-editor',
@@ -13,18 +14,15 @@ import { parse } from 'protobufjs';
})
export class EditorComponent {
fileContents = input<string>();
selectedProtoPath = input<string>();
selectedMessage = input<ProtoMessage>();
private code = viewChild<ElementRef<HTMLElement>>('code');
async loadProtoDefinition() {
try {
const protoPath = this.selectedProtoPath();
if (protoPath) {
const protoContents = await readTextFile(protoPath);
const definition = await parse(protoContents);
console.log(definition);
constructor(private protoDefinitionService: ProtoDefinitionService) {
effect(() => {
const element = this.code()?.nativeElement;
if (element) {
hljs.highlightElement(element);
}
} catch (err) {
console.error(err);
}
});
}
}