UNPKG

epic-designer-cjh

Version:

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

74 lines (73 loc) 2.07 kB
import { defineComponent as d, ref as c, onMounted as p, openBlock as m, createElementBlock as _ } from "vue"; import * as s from "monaco-editor"; import { _ as g } from "./_plugin-vue_export-helper-dad06003.js"; const V = /* @__PURE__ */ d({ __name: "index", props: { language: { default: "json" }, readOnly: { type: Boolean, default: !1 }, valueFormat: { default: "string" }, modelValue: {}, config: { default: () => ({ theme: "vs-light", selectOnLineNumbers: !0, minimap: { enabled: !1 }, lineNumbers: "off" }) } }, emits: ["update:modelValue"], setup(r, { expose: o, emit: u }) { const l = r, a = c(null); let e = null; function i(t) { e == null || e.setValue(t || ""); } function f(t) { const n = e == null ? void 0 : e.getPosition(); n && (e == null || e.executeEdits("", [ { range: new s.Range( n.lineNumber, n.column, n.lineNumber, n.column ), text: t } ]), e == null || e.setPosition({ ...n, column: n.column + t.length }), e == null || e.focus()); } return p(() => { e = s.editor.create(a.value, { value: t(), language: l.language, readOnly: l.readOnly, ...l.config, automaticLayout: !0 }); function t() { return l.valueFormat === "json" && l.modelValue ? JSON.stringify(l.modelValue, null, 2) : l.modelValue ?? ""; } e.onDidChangeModelContent(() => { const n = e == null ? void 0 : e.getValue(); if (l.valueFormat === "json" && n) { u("update:modelValue", JSON.parse(n)); return; } u("update:modelValue", n ?? ""); }); }), o({ setValue: i, insertText: f }), (t, n) => (m(), _("div", { ref_key: "editContainer", ref: a, class: "code-editor" }, null, 512)); } }); const y = /* @__PURE__ */ g(V, [["__scopeId", "data-v-e81d005e"]]); export { y as default };