fix(editor): split query editor into focused components

This commit is contained in:
t8y2 committed 2026-09-23 16:06:00 +08:00
1 parent 6869c7fd6e
commit 121bb33b2e
63 files changed
+11857 -7011

No files matched your search

@@ -0,0 +1,40 @@
import type { Ref, ShallowRef } from "vue";
import type { EditorState } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import type { QueryEditorCodeMirrorModules, QueryEditorCodeMirrorRuntime } from "./queryEditorCodeMirrorRuntime";
interface QueryEditorCodeMirrorConfiguration {
state: EditorState;
parent: HTMLElement;
onReady: () => void;
}
interface QueryEditorCodeMirrorOptions {
editorRef: Readonly<Ref<HTMLElement | null | undefined>>;
view: ShallowRef<EditorView | null>;
runtime: QueryEditorCodeMirrorRuntime;
beforeLoad: () => void;
prepare: (modules: QueryEditorCodeMirrorModules) => Promise<QueryEditorCodeMirrorConfiguration | undefined>;
}
export function useQueryEditorCodeMirror(options: QueryEditorCodeMirrorOptions) {
let disposed = false;
async function initialize() {
if (disposed || !options.editorRef.value) return;
options.beforeLoad();
const modules = await options.runtime.load();
if (disposed) return;
const configuration = await options.prepare(modules);
if (disposed || !configuration) return;
options.view.value = new modules.EditorView({ state: configuration.state, parent: configuration.parent });
configuration.onReady();
}
function dispose() {
disposed = true;
options.view.value?.destroy();
}
return { initialize, dispose };
}