|
|
@ -1,12 +1,12 @@
|
|
|
|
import { Component, Input, ViewChild } from '@angular/core';
|
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
|
|
|
import { BackendService } from 'src/app/services/backendService.service';
|
|
|
|
import {BackendService} from 'src/app/services/backendService.service';
|
|
|
|
import { Compartment, StateEffect } from '@codemirror/state';
|
|
|
|
import {Compartment, StateEffect} from '@codemirror/state';
|
|
|
|
import { CodeMirrorComponent } from '@sandkasten/codemirror6-editor';
|
|
|
|
import {CodeMirrorComponent} from '@sandkasten/codemirror6-editor';
|
|
|
|
import { LanguageDescription } from '@codemirror/language';
|
|
|
|
import {LanguageDescription} from '@codemirror/language';
|
|
|
|
import { CODE_DEFAULTS, LANGUAGES } from '../languages';
|
|
|
|
import {CODE_DEFAULTS, LANGUAGES} from '../languages';
|
|
|
|
import { SafeHTMLPipe } from '../../safe-html.pipe';
|
|
|
|
import {SafeHTMLPipe} from '../../safe-html.pipe';
|
|
|
|
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
|
|
|
|
import {ReactiveFormsModule, FormsModule} from '@angular/forms';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import {Router} from '@angular/router';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
keymap,
|
|
|
|
keymap,
|
|
|
|
highlightSpecialChars,
|
|
|
|
highlightSpecialChars,
|
|
|
@ -19,7 +19,7 @@ import {
|
|
|
|
highlightActiveLineGutter,
|
|
|
|
highlightActiveLineGutter,
|
|
|
|
gutter,
|
|
|
|
gutter,
|
|
|
|
} from '@codemirror/view';
|
|
|
|
} from '@codemirror/view';
|
|
|
|
import { Extension, EditorState } from '@codemirror/state';
|
|
|
|
import {Extension, EditorState} from '@codemirror/state';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
defaultHighlightStyle,
|
|
|
|
defaultHighlightStyle,
|
|
|
|
syntaxHighlighting,
|
|
|
|
syntaxHighlighting,
|
|
|
@ -28,20 +28,21 @@ import {
|
|
|
|
foldGutter,
|
|
|
|
foldGutter,
|
|
|
|
foldKeymap,
|
|
|
|
foldKeymap,
|
|
|
|
} from '@codemirror/language';
|
|
|
|
} from '@codemirror/language';
|
|
|
|
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
|
|
|
import {defaultKeymap, history, historyKeymap} from '@codemirror/commands';
|
|
|
|
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
|
|
|
import {searchKeymap, highlightSelectionMatches} from '@codemirror/search';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
autocompletion,
|
|
|
|
autocompletion,
|
|
|
|
completionKeymap,
|
|
|
|
completionKeymap,
|
|
|
|
closeBrackets,
|
|
|
|
closeBrackets,
|
|
|
|
closeBracketsKeymap,
|
|
|
|
closeBracketsKeymap,
|
|
|
|
} from '@codemirror/autocomplete';
|
|
|
|
} from '@codemirror/autocomplete';
|
|
|
|
import { lintKeymap } from '@codemirror/lint';
|
|
|
|
import {lintKeymap} from '@codemirror/lint';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
Connection,
|
|
|
|
Connection,
|
|
|
|
getDocument,
|
|
|
|
getDocument,
|
|
|
|
peerExtension,
|
|
|
|
peerExtension,
|
|
|
|
} from '../../services/connection.service';
|
|
|
|
} from '../../services/connection.service';
|
|
|
|
|
|
|
|
import {environment} from "../../../environments/environment";
|
|
|
|
|
|
|
|
|
|
|
|
const basicSetup: Extension = (() => [
|
|
|
|
const basicSetup: Extension = (() => [
|
|
|
|
highlightActiveLineGutter(),
|
|
|
|
highlightActiveLineGutter(),
|
|
|
@ -52,7 +53,7 @@ const basicSetup: Extension = (() => [
|
|
|
|
dropCursor(),
|
|
|
|
dropCursor(),
|
|
|
|
EditorState.allowMultipleSelections.of(true),
|
|
|
|
EditorState.allowMultipleSelections.of(true),
|
|
|
|
indentOnInput(),
|
|
|
|
indentOnInput(),
|
|
|
|
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
|
|
|
syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
|
|
|
|
bracketMatching(),
|
|
|
|
bracketMatching(),
|
|
|
|
closeBrackets(),
|
|
|
|
closeBrackets(),
|
|
|
|
autocompletion(),
|
|
|
|
autocompletion(),
|
|
|
@ -94,6 +95,7 @@ export class EditorComponent {
|
|
|
|
get selectedLanguage(): LanguageDescription {
|
|
|
|
get selectedLanguage(): LanguageDescription {
|
|
|
|
return this._selectedLanguage;
|
|
|
|
return this._selectedLanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set selectedLanguage(value: LanguageDescription) {
|
|
|
|
set selectedLanguage(value: LanguageDescription) {
|
|
|
|
this._selectedLanguage = value;
|
|
|
|
this._selectedLanguage = value;
|
|
|
|
if (value.name in CODE_DEFAULTS) {
|
|
|
|
if (value.name in CODE_DEFAULTS) {
|
|
|
@ -106,10 +108,12 @@ export class EditorComponent {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private _linesNumbers: boolean = true;
|
|
|
|
private _linesNumbers: boolean = true;
|
|
|
|
get linesNumbers() {
|
|
|
|
get linesNumbers() {
|
|
|
|
return this._linesNumbers;
|
|
|
|
return this._linesNumbers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set linesNumbers(lines: boolean) {
|
|
|
|
set linesNumbers(lines: boolean) {
|
|
|
|
this._linesNumbers = lines;
|
|
|
|
this._linesNumbers = lines;
|
|
|
|
this.codemirror.editor?.dispatch({
|
|
|
|
this.codemirror.editor?.dispatch({
|
|
|
@ -138,16 +142,18 @@ export class EditorComponent {
|
|
|
|
];
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
private client: WebSocket | undefined;
|
|
|
|
private client: WebSocket | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
@Input()
|
|
|
|
@Input()
|
|
|
|
set idRoom(idRoom: string) {
|
|
|
|
set idRoom(idRoom: string) {
|
|
|
|
if (idRoom === undefined) {
|
|
|
|
if (idRoom === undefined) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.client = new WebSocket(`ws://127.0.0.1:3000/live/${idRoom}`);
|
|
|
|
// this.client = new WebSocket(`ws://127.0.0.1:3000/live/${idRoom}`);
|
|
|
|
|
|
|
|
this.client = new WebSocket(`${environment.webSocketUrl}/live/${idRoom}`);
|
|
|
|
this.client.addEventListener('open', async () => {
|
|
|
|
this.client.addEventListener('open', async () => {
|
|
|
|
let conn = new Connection(this.client!);
|
|
|
|
let conn = new Connection(this.client!);
|
|
|
|
let { version, doc } = await getDocument(conn);
|
|
|
|
let {version, doc} = await getDocument(conn);
|
|
|
|
|
|
|
|
|
|
|
|
this.codemirror.editor?.dispatch({
|
|
|
|
this.codemirror.editor?.dispatch({
|
|
|
|
changes: {
|
|
|
|
changes: {
|
|
|
@ -212,7 +218,7 @@ export class EditorComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
saveToFile() {
|
|
|
|
saveToFile() {
|
|
|
|
const blob = new Blob([this.editorContent], { type: 'text/plain' });
|
|
|
|
const blob = new Blob([this.editorContent], {type: 'text/plain'});
|
|
|
|
const a = document.createElement('a');
|
|
|
|
const a = document.createElement('a');
|
|
|
|
a.download = `code.${this.selectedLanguage.extensions![0]}`;
|
|
|
|
a.download = `code.${this.selectedLanguage.extensions![0]}`;
|
|
|
|
a.href = URL.createObjectURL(blob);
|
|
|
|
a.href = URL.createObjectURL(blob);
|
|
|
|