snowy-designer
Version:
基于Epic-Designer-Pro版本的设计器,可视化开发页面表单
316 lines (315 loc) • 8.86 kB
JavaScript
import "vue";
/* empty css */
import "radix-vue";
import "clsx";
import "tailwind-merge";
import "lucide-vue-next";
import "../../../ui-kit/base-ui/src/shadch-ui/button/index.js";
import "@vueuse/core";
import "../../../ui-kit/base-ui/src/shadch-ui/toast/index.js";
import "vuedraggable";
import { getUUID as p } from "./string.js";
import "../../../hooks/src/store/index.js";
import "lodash";
import { pluginManager as w } from "../manager/pluginManager.js";
import "monaco-editor";
import "../request/index.js";
function m(i, o = /* @__PURE__ */ new WeakMap()) {
if (typeof i != "object" || i === null)
return i;
if (o.has(i))
return o.get(i);
if (Array.isArray(i)) {
const t = i.map((e) => m(e, o));
return o.set(i, t), t;
}
const r = {};
return o.set(i, r), Object.keys(i).forEach((t) => {
r[t] = m(
i[t],
o
);
}), r;
}
function W(i, o = []) {
const [r] = b([m(i)], (t) => {
var s, f;
let e = 0, n = `${t.type}_${p(4, "number")}`;
for (; u(
o,
(a) => a.id === n,
!0
); ) {
if (e++, e >= 50)
throw new Error(`ID冲突,已尝试 ${e} 次,无法生成唯一ID`);
n = `${t.type}_${p(4, "number")}`;
}
const l = {
...t,
id: n
};
return (l.field || l.input) && !((f = (s = w.getComponentConfingByType(l.type)) == null ? void 0 : s.editConstraints) != null && f.fixedField) && (l.field = l.id), l;
});
return r;
}
function g(i, o, r = !0) {
const t = i;
for (const [e, n] of Object.entries(o))
t[e] && n && typeof t[e] == "object" && typeof n == "object" ? (Array.isArray(t[e]) && !Array.isArray(n) ? t[e] = {} : !Array.isArray(t[e]) && Array.isArray(n) && (t[e] = []), g(
t[e],
n,
r
)) : t[e] = n;
r && Object.keys(t).reverse().forEach((e) => {
Object.prototype.hasOwnProperty.call(o, e) || (Array.isArray(t) ? t.splice(Number(e), 1) : delete t[e]);
});
}
function v(i, o, r = [], t = /* @__PURE__ */ new WeakMap()) {
const e = (n) => {
if (Array.isArray(n))
return n.map(e);
if (typeof n == "object" && n !== null) {
if (t.has(n))
return "[Circular]";
t.set(n, !0);
const l = Object.keys(n).sort(), s = {};
return l.forEach((f) => {
r.includes(f) || (s[f] = e(n[f]));
}), t.delete(n), s;
} else
return n;
};
return JSON.stringify(e(i)) === JSON.stringify(e(o));
}
function T(i, o) {
const r = [];
let t = !1;
function e(n) {
if (!t) {
if (r.push(n), n.id === o) {
t = !0;
return;
}
if (n.children && n.children.length > 0) {
for (let l = 0; l < n.children.length; l++)
if (e(n.children[l]), t) return;
}
if (n.slots) {
for (const l in n.slots)
for (let s = 0; s < n.slots[l].length; s++)
if (e(n.slots[l][s]), t) return;
}
t || r.pop();
}
}
for (const n of i) {
if (t) break;
e(n);
}
return t || console.error(`没有查询到id为${o}的节点`), r;
}
function q(i, o, r) {
const t = o.split(".");
let e = i;
for (const n of t) {
if (e == null)
return r;
e = e[n];
}
return e === void 0 ? r : e;
}
function D(i, o, r) {
const t = o.replaceAll(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
let e = i;
for (let n = 0; n < t.length - 1; n++) {
const l = t[n];
e[l] == null && (e[l] = Number.isNaN(Number(t[n + 1])) ? {} : []), e = e[l];
}
return e[t[t.length - 1]] = r, i;
}
function J(i, o = "default") {
return A(i, o).map((t) => t.field);
}
function A(i, o = "default") {
const r = u(
i,
(e) => {
var n;
return e.type === "form" && (((n = e.componentProps) == null ? void 0 : n.name) ?? e.name === o);
},
!0
);
return u(
(r == null ? void 0 : r.children) ?? [],
(e) => !!e.input,
!1,
(e) => e.type !== "subform"
);
}
function u(i, o, r = !1, t) {
const e = [], n = [...i];
for (; n.length; ) {
const l = n.pop();
if (l != null && l.children && (!t || t(l)) && n.push(...l.children), l != null && l.slots && (!t || t(l)))
for (const s in l.slots)
n.push(...l.slots[s]);
if (o(l) && (e.push(l), r))
return l;
}
return r ? !1 : e;
}
function b(i, o, r) {
const t = [...i];
for (; t.length; ) {
const e = t.pop();
if (e != null && e.children && (!r || r(e)) && t.push(...e.children), e != null && e.slots && (!r || r(e)))
for (const n in e.slots)
t.push(...e.slots[n]);
g(e, o(e));
}
return i;
}
function U(i, o) {
const r = u(
i,
(t) => t.id === o,
!0
);
return r || null;
}
function _(i, o) {
const r = [{ type: "", children: i }];
let t = 0, e = null;
const n = u(
r,
(l) => {
if (e = l.children ?? null, !e) {
if (l != null && l.slots)
for (const s in l.slots) {
e = l.slots[s];
for (const [f, a] of e.entries())
if (a.id === o)
return t = f, !0;
}
return !1;
}
for (const [s, f] of e.entries())
if (f.id === o)
return t = s, !0;
return !1;
},
!0
);
if (!e)
throw new Error(`没有查询到id为${o}的节点`);
return {
index: t,
parentSchema: n,
schema: e[t],
list: e
};
}
function K(i) {
i.config || (i.config = {});
const o = {
schemas: [
{
componentProps: {
style: {
padding: "16px"
}
},
id: "root",
label: "页面",
type: "page",
children: [
{
label: "表单",
type: "form",
icon: "epic-icon-daibanshixiang",
labelWidth: i.config.labelWidth || 100,
name: "default",
componentProps: {
colon: i.config.colon || !0,
hideRequiredMark: i.config.hideRequiredMark || !1,
labelAlign: i.config.labelAlign || "right",
labelCol: i.config.labelCol || { span: 5 },
labelLayout: i.config.labelLayout === "flex" ? "fixed" : "flex",
labelWidth: i.config.labelWidth || 100,
layout: i.config.layout || "horizontal",
size: i.config.size || "middle",
wrapperCol: i.config.wrapperCol || { span: 19 }
},
children: [],
id: `form_${p()}`
}
]
}
],
script: i.script || ""
};
if (o.schemas && o.schemas.length > 0) {
const r = o.schemas[0];
if (r.children && r.children.length > 0) {
const t = r.children[0];
i.list && (t.children = c(i.list));
}
}
return o;
}
function c(i, o) {
return i.map((r) => {
var f, a, y;
let t = r.type ?? "";
const e = r.options ?? {}, n = (h, d) => {
t === h && (t = d, e.defaultValue && (e.defaultValue = JSON.parse(e.defaultValue)));
};
if (n("uploadImg", "upload-image"), n("uploadFile", "upload-file"), t === "date" && e.range && (e.type = "daterange", delete e.range), (t === "date" || t === "time") && (e.valueFormat = e.format), t === "textarea") {
const { maxRows: h, minRows: d } = e;
e.autoSize = { maxRows: h, minRows: d }, delete e.minRows, delete e.maxRows;
}
t === "number" && !e.precision && delete e.precision, e.width && (e.style = { width: e.width }, delete e.width), t === "grid" && (t = "row"), o && o.type === "grid" && (t = "col", e.span = r.span, r.key = p());
const l = {
componentProps: e,
field: r.model,
icon: r.icon || "",
id: r.key,
label: r.label,
type: t
};
return (e.noFormItem || !e.showLabel) && (l.noFormItem = !0, delete e.noFormItem, delete e.showLabel), e.clearable && (e.allowClear = !0, delete e.clearable), [
"input",
"textarea",
"number",
"password",
"select",
"cascader",
"checkbox",
"radio",
"date",
"time",
"slider",
"switch",
"color-picker",
"upload-file",
"upload-image"
].includes(t) && (l.input = !0, ((a = (f = r.rules) == null ? void 0 : f[0]) == null ? void 0 : a.required) === !1 && r.rules.shift(), ((y = r.rules) == null ? void 0 : y.length) > 0 && (l.rules = r.rules)), r.list && (l.children = c(r.list, r)), r.columns && (l.children = c(r.columns, r)), r.trs && (l.children = c(r.trs, r)), r.tds && (l.children = c(r.tds, r)), l;
});
}
export {
K as convertKFormData,
m as deepClone,
g as deepCompareAndModify,
v as deepEqual,
U as findSchemaById,
_ as findSchemaInfoById,
u as findSchemas,
W as generateNewSchema,
J as getFormFields,
A as getFormSchemas,
T as getMatchedById,
q as getValueByPath,
b as mapSchemas,
c as recursionConvertedNode,
D as setValueByPath
};