Skip to content

Commit 1b7a09a

Browse files
committed
Move things around
1 parent dde5466 commit 1b7a09a

File tree

7 files changed

+39
-52
lines changed

7 files changed

+39
-52
lines changed

apps/codelab/src/app/admin/content/presentation-editor/preview/slide-preview/dynamic-renderer/dynamic-renderer.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { CodelabCodeDemoPreviewComponent } from '../../../wrappers/custom-compon
1616
import { NgxdResolver } from '@ngxd/core';
1717
import { CodelabExerciseEditorComponent } from '../../../wrappers/custom-component-editors/codelab-exercise-preview-editor/codelab-exercise-editor.component';
1818
import { TitleSlideComponent } from '../../../../../../components/slides/title-slide/title-slide.component';
19-
import { CodelabCodeDemoConsoleViewerComponent } from '../../../wrappers/custom-components-viewers/codelab-code-demo-console-viewer.component';
19+
import { CodelabCodeDemoConsoleViewerComponent } from '../../../wrappers/custom-components-viewers/codelab-code-demo-console-viewer/codelab-code-demo-console-viewer.component';
2020

2121
@Injectable({ providedIn: 'root' })
2222
export class PreviewDynamicComponentResolver extends NgxdResolver<string, any> {
@@ -55,7 +55,7 @@ export class ViewDynamicComponentResolver extends NgxdResolver<string, any> {
5555
super([
5656
{ type: 'codelab-title-slide', component: TitleSlideComponent },
5757
{
58-
type: 'codelab-code-demo-console-editor',
58+
type: 'codelab-code-demo-console-viewer',
5959
component: CodelabCodeDemoConsoleViewerComponent,
6060
},
6161
]);

apps/codelab/src/app/admin/content/presentation-editor/slide-editor/action-bar/action-bar.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</button>
1313
<button
1414
mat-icon-button
15-
(click)="addCustom('codelab-code-demo-console-editor', templates.simpleApp)"
15+
(click)="addCustom('codelab-code-demo-console-viewer', templates.simpleApp)"
1616
>
1717
<mat-icon>web</mat-icon>
1818
</button>
@@ -24,15 +24,15 @@
2424
<button
2525
mat-menu-item
2626
(click)="
27-
addCustom('codelab-code-demo-console-editor', templates.simpleApp)
27+
addCustom('codelab-code-demo-console-viewer', templates.simpleApp)
2828
"
2929
>
3030
Simple / One File
3131
</button>
3232
<button
3333
mat-menu-item
3434
(click)="
35-
addCustom('codelab-code-demo-console-editor', templates.angularApp)
35+
addCustom('codelab-code-demo-console-viewer', templates.angularApp)
3636
"
3737
>
3838
Angular App

apps/codelab/src/app/admin/content/presentation-editor/wrappers/custom-component-editors/codelab-code-demo-console-editor/codelab-code-demo-console-editor.component.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface Highlight {
2323
type Highlights2 = Record<string, IRange[]>;
2424

2525
@Component({
26-
selector: 'codelab-code-demo-console-editor',
26+
selector: 'codelab-code-demo-console-viewer',
2727
templateUrl: './codelab-code-demo-console-editor.component.html',
2828
styleUrls: ['./codelab-code-demo-console-editor.component.scss'],
2929
})
@@ -50,7 +50,8 @@ export class CodelabCodeDemoConsoleEditorComponent implements OnInit {
5050
constructor(
5151
private readonly monacoConfigService: MonacoConfigService,
5252
private readonly contentService: ContentService
53-
) {}
53+
) {
54+
}
5455

5556
update() {
5657
this.inferVars();
@@ -69,24 +70,24 @@ export class CodelabCodeDemoConsoleEditorComponent implements OnInit {
6970
private inferVars() {
7071
this.files = Object.keys(this.code);
7172

72-
this.selectedFiles =
73-
this.selectedFiles.length === 0
74-
? this.files.map((name, i) => ({
75-
name,
76-
selected: i === 0,
77-
highlights: [],
78-
highlights2: [],
79-
}))
80-
: this.selectedFiles;
8173

74+
if (this.selectedFiles.length === 0) {
75+
console.log('regen');
76+
this.selectedFiles = this.files.map((name, i) => ({
77+
name,
78+
selected: i === 0,
79+
highlights: [],
80+
highlights2: [],
81+
}));
82+
}
8283
this.highlights2 = this.selectedFiles.reduce((result, file) => {
8384
result[file.name] = file.highlights2 ?? [];
8485
return result;
8586
}, {});
8687

8788
this.openFiles = this.selectedFiles
8889
.filter((file) => file.selected)
89-
.map(({ name }) => name);
90+
.map(({name}) => name);
9091
}
9192

9293
updateFileName(index: number, oldName: string, newName: string) {
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { Component, Input, OnInit } from '@angular/core';
22

33
import { CodeDemoModule, MonacoConfigService } from '@codelab/code-demos';
44

5-
import { ContentSlide, CustomBlock } from '../../types';
5+
import { ContentSlide, CustomBlock } from '../../../types';
66
import { FormsModule } from '@angular/forms';
77

88
@Component({
9-
selector: 'codelab-code-demo-console-editor',
9+
selector: 'codelab-code-demo-console-viewer',
1010
templateUrl: './codelab-code-demo-console-viewer.component.html',
1111
standalone: true,
1212
imports: [CodeDemoModule, FormsModule],
@@ -45,17 +45,7 @@ export class CodelabCodeDemoConsoleViewerComponent implements OnInit {
4545
: this.selectedFiles;
4646

4747
this.highlights = this.selectedFiles.reduce((result, file) => {
48-
result[file.name] = file.highlights.map((highlight) => {
49-
if (typeof highlight.selection === 'string') {
50-
try {
51-
return new RegExp(highlight.selection);
52-
} catch (e) {
53-
console.error('Invalid regexp', highlight.selection);
54-
}
55-
}
56-
57-
return highlight.selection;
58-
});
48+
result[file.name] = file.highlights2;
5949
return result;
6050
}, {});
6151

apps/codelab/src/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ html {
166166

167167
.monaco-editor.vs
168168
.highlighted-code-v2.highlighted-code-v2.highlighted-code-v2.highlighted-code-v2 {
169-
background: #f5d8dd;
169+
background: rgba(230, 255, 0, 0.58);
170170
}
171171

172172
p {

libs/code-demos/src/lib/multitab-editor/multitab-editor.component.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
ChangeDetectorRef,
4-
Component,
5-
forwardRef,
6-
Input,
7-
OnChanges,
8-
OnDestroy,
9-
OnInit,
10-
SimpleChanges,
11-
NgZone,
12-
} from '@angular/core';
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, forwardRef, Input, NgZone, OnChanges, OnDestroy, OnInit, SimpleChanges, } from '@angular/core';
132
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
143
import { editor } from 'monaco-editor';
154
import { Subject, Subscription } from 'rxjs';
165
import { debounceTime } from 'rxjs/operators';
176
import { MonacoConfigService } from '../shared/monaco-config.service';
7+
import { assertObject } from '@codelab/code-demos/src/lib/shared/utils';
188
import ITextModel = editor.ITextModel;
199
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
20-
import { assertObject } from '@codelab/code-demos/src/lib/shared/utils';
2110

2211
declare const monaco;
2312
const extenstionToLang = {
@@ -49,8 +38,7 @@ type Code = Record<string, string>;
4938
],
5039
})
5140
export class MultitabEditorComponent
52-
implements OnChanges, OnInit, OnDestroy, ControlValueAccessor
53-
{
41+
implements OnChanges, OnInit, OnDestroy, ControlValueAccessor {
5442
@Input() code: Code = {};
5543
@Input() solutions: Code = {};
5644
@Input() allowSwitchingFiles = true;
@@ -76,7 +64,8 @@ export class MultitabEditorComponent
7664
private zone: NgZone,
7765
readonly monacoConfigService: MonacoConfigService,
7866
readonly cdr: ChangeDetectorRef
79-
) {}
67+
) {
68+
}
8069

8170
ngOnInit(): void {
8271
assertObject(this.code);
@@ -91,11 +80,13 @@ export class MultitabEditorComponent
9180

9281
ngOnChanges(changes: SimpleChanges): void {
9382
if ('setFiles' in changes) {
83+
console.log(changes.setFiles);
9484
let files = this.setFiles;
9585
if (typeof files === 'string') {
9686
files = files.split(',');
9787
}
9888
this.files = files;
89+
this.processFileChanges(changes.setFiles.currentValue, changes.setFiles.previousValue);
9990
this.updateOpenModels();
10091
}
10192

@@ -104,7 +95,7 @@ export class MultitabEditorComponent
10495
}
10596
}
10697

107-
handleFileChange(index, { value }) {
98+
handleFileChange(index, {value}) {
10899
if (this.models) {
109100
const m = this.getModelByFileName(value.path);
110101
m.model.setValue(m.model.getValue());
@@ -120,7 +111,8 @@ export class MultitabEditorComponent
120111
this.onChange = fn;
121112
}
122113

123-
registerOnTouched(fn: any): void {}
114+
registerOnTouched(fn: any): void {
115+
}
124116

125117
loadSolution(file) {
126118
const model = this.getModelByFileName(file).model;
@@ -140,7 +132,7 @@ export class MultitabEditorComponent
140132

141133
getModelByFileName(file): MonacoModel | undefined {
142134
if (this.models) {
143-
return this.models.find(({ path }) => path === file);
135+
return this.models.find(({path}) => path === file);
144136
}
145137
}
146138

@@ -167,7 +159,7 @@ export class MultitabEditorComponent
167159
model.onDidChangeContent(() => {
168160
this.zone.run(() => {
169161
this.code[path] = model.getValue();
170-
this.changeSubject.next({ ...this.code });
162+
this.changeSubject.next({...this.code});
171163
});
172164
});
173165

@@ -188,7 +180,7 @@ export class MultitabEditorComponent
188180

189181
writeValue(code: Code): void {
190182
if (code) {
191-
this.code = { ...code };
183+
this.code = {...code};
192184
this.generateModels();
193185
}
194186
}
@@ -229,4 +221,8 @@ export class MultitabEditorComponent
229221
this.editor = null;
230222
}
231223
}
224+
225+
private processFileChanges(currentValue: string[], previousValue: string[]) {
226+
227+
}
232228
}

0 commit comments

Comments
 (0)