fix: highlight formatted json in cell detail
This commit is contained in:
6 files changed
+123
-25
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { shallowRef, onBeforeUnmount, type ShallowRef, createApp, watch } from "vue";
|
||||
import { shallowRef, onBeforeUnmount, getCurrentInstance, type ShallowRef, createApp, watch } from "vue";
|
||||
import { EditorState, Compartment } from "@codemirror/state";
|
||||
import { EditorView, keymap, drawSelection, dropCursor, highlightSpecialChars, highlightActiveLine } from "@codemirror/view";
|
||||
import { json } from "@codemirror/lang-json";
|
||||
@@ -20,6 +20,7 @@ export interface UseCellDetailEditorOptions {
|
||||
onChange?: (value: string) => void;
|
||||
onEscape?: () => void;
|
||||
onBlur?: () => void;
|
||||
language?: "auto" | "json";
|
||||
readOnly?: boolean;
|
||||
editorTheme: () => EditorTheme;
|
||||
appAppearance: () => AppThemeAppearance;
|
||||
@@ -147,7 +148,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
||||
if (destroyed) return;
|
||||
|
||||
const doc = initialValue ?? "";
|
||||
currentIsJson = shouldUseJsonMode(columnType, doc);
|
||||
currentIsJson = options.language === "json" || shouldUseJsonMode(columnType, doc);
|
||||
|
||||
const theme = await loadEditorTheme(options.editorTheme(), options.appAppearance());
|
||||
liveFontSize = clampEditorFontSize(options.fontSize());
|
||||
@@ -251,7 +252,7 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
||||
if (!editor || destroyed) return;
|
||||
|
||||
const text = value ?? "";
|
||||
const newIsJson = shouldUseJsonMode(columnType, text);
|
||||
const newIsJson = options.language === "json" || shouldUseJsonMode(columnType, text);
|
||||
const effects: ReturnType<typeof Compartment.prototype.reconfigure>[] = [];
|
||||
|
||||
if (newIsJson !== currentIsJson) {
|
||||
@@ -297,9 +298,11 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
||||
wrapperEl = null;
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
destroy();
|
||||
});
|
||||
if (getCurrentInstance()) {
|
||||
onBeforeUnmount(() => {
|
||||
destroy();
|
||||
});
|
||||
}
|
||||
|
||||
return { create, setValue, getValue, openSearch, openReplace, destroy, view };
|
||||
}
|
||||
@@ -1,18 +1,32 @@
|
||||
import { ref } from "vue";
|
||||
import { ref, type Ref } from "vue";
|
||||
|
||||
const message = ref("");
|
||||
const visible = ref(false);
|
||||
let timer = 0;
|
||||
type ToastState = {
|
||||
message: Ref<string>;
|
||||
visible: Ref<boolean>;
|
||||
timer: number;
|
||||
};
|
||||
|
||||
declare global {
|
||||
var __DBX_TOAST_STATE__: ToastState | undefined;
|
||||
}
|
||||
|
||||
const toastState =
|
||||
globalThis.__DBX_TOAST_STATE__ ??
|
||||
(globalThis.__DBX_TOAST_STATE__ = {
|
||||
message: ref(""),
|
||||
visible: ref(false),
|
||||
timer: 0,
|
||||
});
|
||||
|
||||
export function useToast() {
|
||||
function toast(msg: string, duration = 2000) {
|
||||
message.value = msg;
|
||||
visible.value = true;
|
||||
clearTimeout(timer);
|
||||
timer = window.setTimeout(() => {
|
||||
visible.value = false;
|
||||
toastState.message.value = msg;
|
||||
toastState.visible.value = true;
|
||||
clearTimeout(toastState.timer);
|
||||
toastState.timer = window.setTimeout(() => {
|
||||
toastState.visible.value = false;
|
||||
}, duration);
|
||||
}
|
||||
|
||||
return { message, visible, toast };
|
||||
return { message: toastState.message, visible: toastState.visible, toast };
|
||||
}
|
||||
Reference in new issue
Block a user