Skip to content
Open
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
65 changes: 48 additions & 17 deletions frontend/src/pages/Compose.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,6 @@
<NetworkInput />
</div>
</div>

<!-- <div class="shadow-box big-padding mb-3">
<div class="mb-3">
<label for="name" class="form-label"> Search Templates</label>
<input id="name" v-model="name" type="text" class="form-control" placeholder="Search..." required>
</div>

<prism-editor v-if="false" v-model="yamlConfig" class="yaml-editor" :highlight="highlighter" line-numbers @input="yamlCodeChange"></prism-editor>
</div>-->
</div>
</div>

Expand All @@ -250,9 +241,9 @@ import CodeMirror from "vue-codemirror6";
import { yaml } from "@codemirror/lang-yaml";
import { python } from "@codemirror/lang-python";
import { dracula as editorTheme } from "thememirror";
import { lineNumbers, EditorView } from "@codemirror/view";
import { lineNumbers, EditorView, Decoration, ViewPlugin } from "@codemirror/view";
import { parseDocument, Document } from "yaml";

import { RangeSetBuilder } from "@codemirror/state";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import {
COMBINED_TERMINAL_COLS,
Expand Down Expand Up @@ -282,12 +273,44 @@ let yamlErrorTimeout = null;

let serviceStatusTimeout = null;
let dockerStatsTimeout = null;
let prismjsSymbolDefinition = {
"symbol": {
pattern: /(?<!\$)\$(\{[^{}]*\}|\w+)/,

// Highlight $VAR and ${VAR}
const variableHighlight = ViewPlugin.fromClass(class {
constructor(view) {
this.decorations = this.buildDecorations(view);
}

update(update) {
if (update.docChanged || update.viewportChanged) {
this.decorations = this.buildDecorations(update.view);
}
}
};

buildDecorations(view) {
const builder = new RangeSetBuilder();

for (const { from, to } of view.visibleRanges) {
const text = view.state.doc.sliceString(from, to);
const variableRegex = /\$\{?[A-Za-z0-9_]+\}?/g;
let match;
while ((match = variableRegex.exec(text)) !== null) {
const start = from + match.index;
const end = start + match[0].length;

builder.add(
start,
end,
Decoration.mark({ class: "cm-variable-highlight" })
);
}
}

return builder.finish();
}
}, {
decorations: v => v.decorations
});

export default {
components: {
NetworkInput,
Expand All @@ -312,18 +335,21 @@ export default {
const extensions = [
editorTheme,
yaml(),
variableHighlight,
lineNumbers(),
EditorView.focusChangeEffect.of(focusEffectHandler)
];

const extensionsEnv = [
editorTheme,
python(),
variableHighlight,
lineNumbers(),
EditorView.focusChangeEffect.of(focusEffectHandler)
];

return { extensions,
return {
extensions,
extensionsEnv,
editorFocus };
},
Expand Down Expand Up @@ -778,7 +804,7 @@ export default {
},

checkYAML() {

// TODO: implement validation
},

addContainer() {
Expand Down Expand Up @@ -858,6 +884,11 @@ export default {
height: 200px;
}

:deep(.cm-variable-highlight) {
color: #fe6000;
font-weight: 600;
}

.editor-box {
font-family: 'JetBrains Mono', monospace;
font-size: 14px;
Expand Down
Loading