UNPKG

epic-designer-gold

Version:

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

89 lines (88 loc) 2.63 kB
import { defineComponent as g, ref as p, onMounted as h, watch as v, nextTick as V, openBlock as _, createElementBlock as b } from "vue"; import * as a from "monaco-editor"; import { b as T } from "./index-Duk9g_wT.js"; import { _ as y } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const x = /* @__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(s, { expose: i, emit: m }) { const t = s, u = m, o = p(null); let e = null; const { isDark: r } = T(); function c() { r.value ? a.editor.setTheme("vs-dark") : a.editor.setTheme("vs-light"); } function f(n) { e == null || e.setValue(n || ""); } function d(n) { const l = e == null ? void 0 : e.getPosition(); l && (e == null || e.executeEdits("", [ { range: new a.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 = a.editor.create(o.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( () => r.value, () => { V(() => c()); }, { 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) { u("update:modelValue", JSON.parse(l)); return; } u("update:modelValue", l ?? ""); }); }), i({ setValue: f, insertText: d }), (n, l) => (_(), b("div", { ref_key: "editContainer", ref: o, class: "epic-code-editor" }, null, 512)); } }), S = /* @__PURE__ */ y(x, [["__scopeId", "data-v-3e2e893c"]]); export { S as default };