Add copy button, update packages
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user