UNPKG

form-designer-xinyi

Version:

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

86 lines (85 loc) 2.54 kB
import { defineComponent as g, ref as p, onMounted as h, watch as v, nextTick as V, openBlock as _, createElementBlock as T } from "vue"; import * as u from "monaco-editor"; import { useTheme as x } from "./index.js"; import "./revoke-iScTU0eW.js"; import { _ as y } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const N = /* @__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(i, { expose: r, emit: m }) { const l = i, a = m, o = p(null); let e = null; const { isDark: s } = x(); function f() { s.value ? u.editor.setTheme("vs-dark") : u.editor.setTheme("vs-light"); } function d(n) { e == null || e.setValue(n || ""); } function c(n) { const t = e == null ? void 0 : e.getPosition(); t && (e == null || e.executeEdits("", [ { range: new u.Range( t.lineNumber, t.column, t.lineNumber, t.column ), text: n } ]), e == null || e.setPosition({ ...t, column: t.column + n.length }), e == null || e.focus()); } return h(() => { e = u.editor.create(o.value, { value: n(), ...l.config, language: l.language, readOnly: l.readOnly, lineNumbers: l.lineNumbers, theme: l.theme, automaticLayout: !0 }), l.autoToggleTheme && v(() => s.value, () => { V(() => f()); }, { immediate: !0 }); function n() { return l.valueFormat === "json" && l.modelValue ? JSON.stringify(l.modelValue, null, 2) : l.modelValue ?? ""; } e.onDidChangeModelContent(() => { const t = e == null ? void 0 : e.getValue(); if (l.valueFormat === "json" && t) { a("update:modelValue", JSON.parse(t)); return; } a("update:modelValue", t ?? ""); }); }), r({ setValue: d, insertText: c }), (n, t) => (_(), T("div", { ref_key: "editContainer", ref: o, class: "epic-code-editor" }, null, 512)); } }), B = /* @__PURE__ */ y(N, [["__scopeId", "data-v-1e2fef83"]]); export { B as default };