fix blockviewer

This commit is contained in:
Çetin 2022-01-06 17:39:33 +03:00
parent 05a37558d5
commit d761428836

View File

@ -18,19 +18,18 @@ enum BlockView {
</span> </span>
<div class="block-actions"> <div class="block-actions">
<a tabindex="0" [ngClass]="{'block-action-active': blockView == BlockView.PREVIEW}" (click)="activateView($event, BlockView.PREVIEW)"><span>Preview</span></a> <a tabindex="0" [ngClass]="{'block-action-active': blockView == BlockView.PREVIEW}" (click)="activateView($event, BlockView.PREVIEW)"><span>Preview</span></a>
<a [attr.tabindex]="codeDisabled ? null: '0'" [ngClass]="{'block-action-active': blockView == BlockView.CODE, 'block-action-disabled': codeDisabled}" (click)="activateView($event, BlockView.CODE)"> <a [attr.tabindex]="'0'" [ngClass]="{'block-action-active': blockView == BlockView.CODE}" (click)="activateView($event, BlockView.CODE)">
<i class="pi pi-lock" *ngIf="codeDisabled"></i>
<span>Code</span> <span>Code</span>
</a> </a>
<a [attr.tabindex]="codeDisabled ? null: '0'" class="block-action-copy" [ngClass]="{'block-action-disabled': codeDisabled}" (click)="copyCode($event)" <a [attr.tabindex]="'0'" class="block-action-copy" (click)="copyCode($event)"
pTooltip="Copied to clipboard" tooltipEvent="focus" tooltipPosition="bottom" [tooltipDisabled]="codeDisabled"><i class="pi pi-copy"></i></a> pTooltip="Copied to clipboard" tooltipEvent="focus" tooltipPosition="bottom"><i class="pi pi-copy"></i></a>
</div> </div>
</div> </div>
<div class="block-content"> <div class="block-content">
<div [class]="containerClass" [ngStyle]="previewStyle" *ngIf="blockView == BlockView.PREVIEW"> <div [class]="containerClass" [ngStyle]="previewStyle" *ngIf="blockView == BlockView.PREVIEW">
<ng-content></ng-content> <ng-content></ng-content>
</div> </div>
<div *ngIf="blockView == BlockView.CODE && !codeDisabled"> <div *ngIf="blockView == BlockView.CODE">
<app-code lang="markup" ngPreserveWhitespaces>{{code}} <app-code lang="markup" ngPreserveWhitespaces>{{code}}
</app-code> </app-code>
</div> </div>
@ -49,7 +48,7 @@ export class BlockViewer {
@Input() previewStyle: string; @Input() previewStyle: string;
@Input() free: boolean = false; @Input() free: boolean = true;
@Input() new: boolean = false; @Input() new: boolean = false;
@ -58,23 +57,14 @@ export class BlockViewer {
blockView: BlockView = BlockView.PREVIEW; blockView: BlockView = BlockView.PREVIEW;
activateView(event: Event, blockView: BlockView) { activateView(event: Event, blockView: BlockView) {
if (!this.codeDisabled) {
this.blockView = blockView; this.blockView = blockView;
} event.preventDefault();
event.preventDefault();
} }
async copyCode(event: Event) { async copyCode(event: Event) {
if (!this.codeDisabled) { await navigator.clipboard.writeText(this.code);
await navigator.clipboard.writeText(this.code); event.preventDefault();
}
event.preventDefault();
}
get codeDisabled() {
return this.free ? false : (environment ? environment.production: false);
} }
} }