ai-form-designer
Version:
vue3+adv的设计器,可视化开发页面表单
90 lines (89 loc) • 2.65 kB
JavaScript
import { defineComponent as g, ref as p, onMounted as h, watch as v, nextTick as V, createElementBlock as _, openBlock as b } from "vue";
import * as a from "monaco-editor";
import { r as T } from "./index-DwcJO-0a.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, r = p(null);
let e = null;
const { isDark: o } = T();
function f() {
o.value ? a.editor.setTheme("vs-dark") : a.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 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(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(() => o.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) {
u("update:modelValue", JSON.parse(l));
return;
}
u("update:modelValue", l ?? "");
});
}), i({
setValue: c,
insertText: d
}), (n, l) => (b(), _("div", {
ref_key: "editContainer",
ref: r,
class: "epic-code-editor"
}, null, 512));
}
}), S = /* @__PURE__ */ y(x, [["__scopeId", "data-v-7bdf36f7"]]);
export {
S as default
};