Add copy button, update packages

This commit is contained in:
2024-07-13 11:27:47 +09:30
parent 445346b29b
commit 72c24a70ae
6 changed files with 50 additions and 30 deletions

View File

@@ -10,4 +10,8 @@
} }
</div>
<h2>Preview</h2>
<div class="actions">
<button mat-flat-button (click)="copyToClipboard()">Copy</button>
</div>
<pre *ngIf="showRaw()"><code #code></code></pre>

View File

@@ -13,3 +13,7 @@ div {
div {
padding: 10px;
}
.actions {
flex: 0 0 auto;
}

View File

@@ -13,11 +13,13 @@ import hljs from 'highlight.js/lib/core';
import { ProtoMessage } from '../model/proto-message.model';
import { ProtoFieldComponent } from './proto-field/proto-field.component';
import { DomSanitizer } from '@angular/platform-browser';
import { MatButtonModule } from '@angular/material/button';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-editor',
standalone: true,
imports: [CommonModule, ProtoFieldComponent],
imports: [CommonModule, ProtoFieldComponent, MatButtonModule],
templateUrl: './editor.component.html',
styleUrl: './editor.component.scss',
})
@@ -32,7 +34,7 @@ export class EditorComponent {
private code = viewChild<ElementRef<HTMLElement>>('code');
constructor(sanitizer: DomSanitizer) {
constructor(sanitizer: DomSanitizer, private snackBar: MatSnackBar) {
effect(() => {
const element = this.code()?.nativeElement;
if (element) {
@@ -68,4 +70,13 @@ export class EditorComponent {
existingValue[key] = value;
this.values.set(existingValue);
}
protected async copyToClipboard() {
await navigator.clipboard.writeText(
JSON.stringify(this.values(), undefined, 2)
);
this.snackBar.open('Successully copied to clipboard', 'Close', {
duration: 2000,
});
}
}

View File

@@ -29,6 +29,7 @@ html {
@include mat.form-field-theme(theme.$rose-theme);
@include mat.list-theme(theme.$rose-theme);
@include mat.select-theme(theme.$rose-theme);
@include mat.snack-bar-theme(theme.$rose-theme);
@include custom-colours(theme.$rose-theme);
}