Skip to content

Commit 6928c25

Browse files
committed
experiment with adding a monaco zone
1 parent 03db183 commit 6928c25

File tree

5 files changed

+69
-18
lines changed

5 files changed

+69
-18
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
</button>
2222

2323
<mat-menu #templatesMenu="matMenu">
24+
<button
25+
mat-menu-item
26+
(click)="
27+
addCustom('codelab-code-demo-console-editor', templates.simpleHtml)
28+
"
29+
>
30+
Simple HTML
31+
</button>
2432
<button
2533
mat-menu-item
2634
(click)="

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export class ActionBarComponent {
1313
@Input() presentationId!: string;
1414

1515
readonly templates = {
16+
simpleHtml: {
17+
code: { 'index.html': '<h1>Hello world</h1> ' },
18+
},
1619
simpleApp: {
1720
code: { 'app.ts': '// Type your code here!' },
1821
},
@@ -27,6 +30,8 @@ export class ActionBarComponent {
2730
bootstrapApplication(AppComponent);
2831
`,
2932
'app.component.ts': `
33+
import {Component} from '@angular/core';
34+
3035
@Component({
3136
selector: 'app-component',
3237
template: '<h1>LOL<h1>',

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
Show preview
2626
</mat-checkbox>
2727
</div>
28+
<div>
29+
<mat-checkbox [(ngModel)]="showCode" (ngModelChange)="update()">
30+
Show preview
31+
</mat-checkbox>
32+
</div>
2833
<div>
2934
<mat-checkbox [(ngModel)]="allowSwitchingFiles" (ngModelChange)="update()">
3035
Allow switching files
@@ -45,5 +50,5 @@
4550
(ngModelChange)="update()"
4651
[files]="openFiles"
4752
[ui]="ui"
48-
[bootstrap]="'main'"
53+
[bootstrap]="false"
4954
></code-demo>

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ export class CodelabCodeDemoConsoleEditorComponent implements OnInit {
3636
@Input() presentationId!: string;
3737
@Input() selectedFiles: SelectableFile[] = [];
3838
@Input() showPreview = true;
39+
@Input() showCode = true;
3940
@Input() allowSwitchingFiles = true;
4041
@Input() displayFileName = false;
4142
readonly defaultNewFileName = 'new.ts';
4243

4344
openFiles: string[] = [];
4445
highlights2: Highlights2 = {};
4546

47+
4648
async ngOnInit() {
4749
this.inferVars();
4850
}

libs/code-demos/src/lib/code-demo-editor/directives/code-demo-editor.highlight.directive.ts

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
1-
import {
2-
AfterViewInit,
3-
Directive,
4-
Input,
5-
OnChanges,
6-
Optional,
7-
Self,
8-
} from '@angular/core';
1+
import { AfterViewInit, Directive, Input, OnChanges, Optional, Self, } from '@angular/core';
92
import { findPosition } from '../utils/utils';
103
import { CodeDemoEditorInjector } from '@codelab/code-demos/src/lib/code-demo-editor/code-demo-editor.injector';
114
import { MonacoConfigService } from '@codelab/code-demos/src/lib/shared/monaco-config.service';
125
import { editor } from 'monaco-editor';
6+
import {
7+
rangeToDecoration
8+
} from '../../../../../../apps/codelab/src/app/admin/content/presentation-editor/wrappers/custom-component-editors/codelab-code-demo-console-editor/highlight-button/highlight-button.component';
139
import IEditorDecorationsCollection = editor.IEditorDecorationsCollection;
14-
import { rangeToDecoration } from '../../../../../../apps/codelab/src/app/admin/content/presentation-editor/wrappers/custom-component-editors/codelab-code-demo-console-editor/highlight-button/highlight-button.component';
10+
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
1511

1612
@Directive({
1713
selector: '[codeDemoHighlight]',
1814
})
1915
export class CodeDemoEditorHighlightDirective
20-
implements OnChanges, AfterViewInit
21-
{
16+
implements OnChanges, AfterViewInit {
2217
readonly decorators = [];
23-
private decorationsCollection?: IEditorDecorationsCollection;
2418
@Input() codeDemoHighlight;
2519
@Input() ngModel;
20+
hasZone = false;
21+
private decorationsCollection?: IEditorDecorationsCollection;
2622

2723
constructor(
2824
@Self() @Optional() private editorInjector: CodeDemoEditorInjector,
2925
readonly monacoConfigService: MonacoConfigService
30-
) {}
26+
) {
27+
}
3128

3229
ngAfterViewInit() {
3330
this.highlight();
@@ -37,6 +34,40 @@ export class CodeDemoEditorHighlightDirective
3734
}, 1000);
3835
}
3936

37+
// addZone(editor: IStandaloneCodeEditor) {
38+
// if (this.hasZone) {
39+
// return;
40+
// }
41+
// this.hasZone = true;
42+
//
43+
// editor.changeViewZones(function (changeAccessor) {
44+
// var domNode = document.createElement('div');
45+
// domNode.style.background = 'transparent';
46+
// domNode.innerHTML = `
47+
// <div style="display: inline-block; padding: 8px; border-radius: 8px; background: #ffcbd5; border: 1px #ddd solid">This is a text lol</div>
48+
// `;
49+
//
50+
// changeAccessor.addZone({
51+
// afterLineNumber: 1,
52+
// heightInLines: 2,
53+
// domNode: domNode
54+
// });
55+
//
56+
//
57+
// var domNode2 = document.createElement('div');
58+
// domNode2.style.background = 'transparent';
59+
// domNode2.innerHTML = `
60+
// <div style="display: inline-block; font-family: 'Helvetica Neue';">This is a text lol</div>
61+
// `;
62+
//
63+
// changeAccessor.addZone({
64+
// afterLineNumber: 0,
65+
// heightInLines: 2,
66+
// domNode: domNode2
67+
// });
68+
// });
69+
// }
70+
4071
highlight() {
4172
if (!this.editorInjector) {
4273
return;
@@ -74,9 +105,9 @@ export class CodeDemoEditorHighlightDirective
74105
} else {
75106
const decorations = this.codeDemoHighlight
76107
.map((match) =>
77-
typeof match !== 'string' && match.match ? match : { match }
108+
typeof match !== 'string' && match.match ? match : {match}
78109
)
79-
.reduce((ranges, { match, className }) => {
110+
.reduce((ranges, {match, className}) => {
80111
let range: [number, number, number, number];
81112
if (match.endColumn) {
82113
range = [
@@ -88,13 +119,13 @@ export class CodeDemoEditorHighlightDirective
88119
} else {
89120
const position = findPosition(code, match);
90121

91-
const { indexStart, lineStart, indexEnd, lineEnd } = position;
122+
const {indexStart, lineStart, indexEnd, lineEnd} = position;
92123
range = [lineStart, indexStart, lineEnd, indexEnd];
93124
}
94125

95126
ranges.push({
96127
range: new this.monacoConfigService.monaco.Range(...range),
97-
options: { inlineClassName: className || 'highlighted-code' },
128+
options: {inlineClassName: className || 'highlighted-code'},
98129
});
99130

100131
return ranges;

0 commit comments

Comments
 (0)