Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/iframe/iframe.component.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<iframe #iframe [src]="iframeUrl"></iframe>
<iframe #iframe></iframe>
<app-loading></app-loading>
19 changes: 12 additions & 7 deletions src/app/iframe/iframe.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { AfterViewInit, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, Subscription } from 'rxjs';
import { LoadingService } from '../loading.service';
Expand All @@ -11,11 +10,10 @@
styleUrls: ['./iframe.component.css'],
standalone: false
})
export class IframeComponent implements OnDestroy, OnInit {
export class IframeComponent implements AfterViewInit, OnDestroy, OnInit {
@ViewChild('iframe') iframe: ElementRef;

url: string;
iframeUrl: SafeResourceUrl;
cssSubscription: Subscription;
widgetSubscription: Subscription;
theme: string;
Expand All @@ -24,7 +22,6 @@
constructor(
private route: ActivatedRoute,
private router: Router,
private sanitizer: DomSanitizer,
private metadataService: MetadataRepositoryService,
private loading: LoadingService) {
this.route.params.subscribe((params) => {
Expand All @@ -36,14 +33,22 @@
this.loading.show();
this.theme = params['theme'];
this.url = document.getElementsByTagName('base')[0].href + (widget ? 'preview' : 'wizard') + '/' + this.theme;
this.iframeUrl = this.sanitizer.bypassSecurityTrustResourceUrl(this.url);
if(this.iframe) {
this.iframe.nativeElement.src = this.url;
}
}
});
}

receiveMessage(e): void {
ngAfterViewInit(): void {
if(this.url) {
this.iframe.nativeElement.src = this.url;
}
}

receiveMessage(e: MessageEvent): void {
if(e.data.widget) {
this.router.navigate(['/advanced', this.metadataService.theme.name, this.metadataService.theme.colorScheme, e.data.widget]);

Check warning on line 51 in src/app/iframe/iframe.component.ts

View workflow job for this annotation

GitHub Actions / test

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

if(e.data.hideLoading) {
Expand Down
3 changes: 1 addition & 2 deletions src/app/left-menu/editor/editor.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-magic-numbers */
import { Component, Input } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';

import { MetadataRepositoryService } from '../../meta-repository.service';
Expand Down Expand Up @@ -33,7 +32,7 @@ export class EditorComponent {
return /^[1-9]\d*$/.test(value);
}

highlight(text: string): SafeHtml {
highlight(text: string): string {
return this.names.getHighlightedForLeftMenuName(text, this.searchText);
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/left-menu/main/left-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { NamesService } from '../../names.service';
import { LeftMenuItem } from '../../types/left-menu-item';
import { MetaItem } from '../../types/meta-item';
import { LeftMenuAlias } from '../left-menu.aliases';
import { SafeHtml } from '@angular/platform-browser';
import { AnalyticsEventsService } from '../../analytics-events.service';

const BASE_THEMING_NAME = 'Basic Settings';
Expand Down Expand Up @@ -148,7 +147,7 @@ export class LeftMenuComponent implements OnDestroy, OnInit {
this.filteredData[0] = this.workArea;
}

getRealName(name): SafeHtml {
getRealName(name): string {
return this.names.getHighlightedForLeftMenuName(name, this.searchKeyword);
}

Expand Down
10 changes: 3 additions & 7 deletions src/app/names.service.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { Injectable } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Injectable()
export class NamesService {

constructor(private sanitizer: DomSanitizer) { }

private ORDER_REGEX = /^(\d+).\s/;

getRealName(orderedName): string {
return orderedName.replace(this.ORDER_REGEX, '');
}

getHighlightedForLeftMenuName(orderedName, searchText): SafeHtml {
getHighlightedForLeftMenuName(orderedName, searchText): string {
const text = this.getRealName(orderedName);
if(!searchText) return text;

const highlightedText = text.replace(new RegExp(`(${searchText})`, 'ig'), '<span style="color:#f05b41">$1</span>');

return this.sanitizer.bypassSecurityTrustHtml(highlightedText);
const escapedSearch = searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
return text.replace(new RegExp(`(${escapedSearch})`, 'ig'), '<span class="search-highlight">$1</span>');
}

sortNames(name1, name2): number {
Expand Down
2 changes: 1 addition & 1 deletion src/app/preview/drawer/drawer.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*eslint no-invalid-this: ['Off']*/
/* eslint-disable no-invalid-this */
import { Component, ViewChild } from '@angular/core';
import { DxDrawerComponent } from 'devextreme-angular';
import { Subject } from 'rxjs';
Expand Down
5 changes: 5 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ body {
overflow-y: hidden;
}
}


.search-highlight {
color: #f05b41;
}
Loading