Debian Codegraph @

frontend/src/reports/query/QueryEditor.svelte

raw
1 <script lang="ts">
2 import { replaceContents } from "../../codemirror/editor-transactions";
3 import { initQueryEditor } from "../../codemirror/setup";
4 import { _ } from "../../i18n";
5 import { keyboardShortcut } from "../../keyboard-shortcuts";
6
7 export let value: string;
8 export let submit: () => void;
9
10 const { editor, renderEditor } = initQueryEditor(
11 value,
12 (state) => {
13 value = state.sliceDoc();
14 },
15 _("...enter a BQL query. 'help' to list available commands."),
16 submit,
17 );
18
19 $: if (value !== editor.state.sliceDoc()) {
20 editor.dispatch(replaceContents(editor.state, value));
21 }
22 </script>
23
24 <form
25 on:submit={(event) => {
26 event.preventDefault();
27 submit();
28 }}
29 >
30 <div use:renderEditor></div>
31 <button type="submit" use:keyboardShortcut={"Control+Enter"}>
32 {_("Submit")}
33 </button>
34 </form>
35
36 <style>
37 form {
38 display: flex;
39 align-items: center;
40 padding-bottom: 1em;
41 }
42
43 button {
44 margin: 0;
45 }
46
47 div {
48 flex-grow: 1;
49 width: 100%;
50 height: auto;
51 margin-right: 0.5em;
52 font-size: 16px;
53 border: 1px solid var(--border);
54 }
55
56 form :global(.cm-editor) {
57 width: 100%;
58 }
59 </style>