UNPKG

gepic

Version:

基于vue3的设计器,可视化开发页面表单

91 lines (90 loc) 2.6 kB
import { defineComponent as g, ref as p, onMounted as h, watch as v, nextTick as V, createElementBlock as T, openBlock as b } from "vue"; import * as u from "monaco-editor"; import "@vueuse/core"; import "../../../hooks/store/index.js"; import { useTheme as y } from "../../../hooks/common/theme.js"; const O = /* @__PURE__ */ g({ __name: "index", props: { language: { default: "json" }, readOnly: { type: Boolean, default: !1 }, valueFormat: { default: "string" }, modelValue: {}, config: { default: () => ({ selectOnLineNumbers: !0, minimap: { enabled: !1 } }) }, lineNumbers: { default: "on" }, autoToggleTheme: { type: Boolean }, theme: { default: "vs-light" } }, emits: ["update:modelValue"], setup(o, { expose: s, emit: m }) { const t = o, a = m, r = p(null); let e = null; const { isDark: i } = y(); function f() { i.value ? u.editor.setTheme("vs-dark") : u.editor.setTheme("vs-light"); } function c(n) { e == null || e.setValue(n || ""); } function d(n) { const l = e == null ? void 0 : e.getPosition(); l && (e == null || e.executeEdits("", [ { range: new u.Range( l.lineNumber, l.column, l.lineNumber, l.column ), text: n } ]), e == null || e.setPosition({ ...l, column: l.column + n.length }), e == null || e.focus()); } return h(() => { e = u.editor.create(r.value, { value: n(), ...t.config, language: t.language, readOnly: t.readOnly, lineNumbers: t.lineNumbers, theme: t.theme, scrollBeyondLastLine: !1, scrollbar: { verticalScrollbarSize: 10, horizontalScrollbarSize: 10 }, automaticLayout: !0 }), t.autoToggleTheme && v(() => i.value, () => { V(() => f()); }, { immediate: !0 }); function n() { return t.valueFormat === "json" && t.modelValue ? JSON.stringify(t.modelValue, null, 2) : t.modelValue ?? ""; } e.onDidChangeModelContent(() => { const l = e == null ? void 0 : e.getValue(); if (t.valueFormat === "json" && l) { a("update:modelValue", JSON.parse(l)); return; } a("update:modelValue", l ?? ""); }); }), s({ setValue: c, insertText: d }), (n, l) => (b(), T("div", { ref_key: "editContainer", ref: r, class: "epic-code-editor" }, null, 512)); } }); export { O as default };