snowy-designer
Version:
基于Epic-Designer-Pro版本的设计器,可视化开发页面表单
296 lines (295 loc) • 10.1 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 { deepClone as F, setValueByPath as x, getMatchedById as G } from "../../../utils/src/common/data.js";
import { getUUID as A } from "../../../utils/src/common/string.js";
import "../../../hooks/src/store/index.js";
import "lodash";
import "../../../utils/src/manager/pluginManager.js";
import "monaco-editor";
import "../../../utils/src/request/index.js";
function E(s, l) {
const n = G(s, l);
return n[n.length - 3];
}
function sn(s, l) {
var P, p, a, w;
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "", e = T(u, n);
if (!e) return;
const r = e.colIndex + (((P = e.cell.componentProps) == null ? void 0 : P.colspan) ?? 1);
for (let d = 0; d < (((p = n.children) == null ? void 0 : p.length) || 0); d++) {
const h = (a = n.children) == null ? void 0 : a[d];
if (!h || !h.children) return;
h.children.splice(r, 0, {
id: `td_${A()}`,
label: "单元格",
type: "td",
children: []
});
}
const i = [];
(w = n.children) == null || w.forEach((d, h) => {
var t;
if (!d.children) return;
const o = ((t = d.children[e.colIndex].componentProps) == null ? void 0 : t.colspan) ?? 1;
(o === 0 || o > 1) && i.push(h);
}), i.forEach((d) => {
var c, m, f, I, C;
let h = 0;
if (!n.children) return;
let o;
for (let g = e.colIndex; g >= 0; g--) {
const R = (c = n.children[d].children) == null ? void 0 : c[g], v = ((m = R == null ? void 0 : R.componentProps) == null ? void 0 : m.colspan) ?? 1;
v > 1 && !o && (o = R), h += v;
}
const t = ((f = o == null ? void 0 : o.componentProps) == null ? void 0 : f.rowspan) ?? 1;
for (let g = 0; g < t; g++) {
const $ = (C = (I = n.children[d + g]) == null ? void 0 : I.children) == null ? void 0 : C[r];
h > r && $ && (x($, "componentProps.colspan", 0), x($, "status.invalid", !0));
}
h > r && o && o.children && o.componentProps.colspan++;
});
}
function ln(s, l) {
var d, h;
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "", e = T(u, n);
if (!e || !n.children) return;
const r = e.rowIndex + (((d = e.cell.componentProps) == null ? void 0 : d.rowspan) ?? 1), i = n.children[e.rowIndex];
if (!i.children) return;
const P = [], p = F({
...i,
id: `tr_${A()}`,
// 为新行生成唯一标识符
children: i.children.map((o, t) => {
var m;
const c = ((m = o.componentProps) == null ? void 0 : m.rowspan) ?? 1;
return (c === 0 || c > 1) && P.push(t), {
...o,
id: `td_${A()}`,
// 为新单元格生成唯一标识符
componentProps: {
...o.componentProps,
colspan: 1,
// 重置 colspan 为 1,表示新行不再跨列
rowspan: 1
// 重置 rowspan 为 1,表示新行不再跨行
},
status: {},
// 清空状态
children: []
// 清空子元素
};
})
}), a = [], w = n.children[r];
if (w) {
let o = 0;
(h = w.children) == null || h.forEach((t, c) => {
var m, f;
((m = t.componentProps) == null ? void 0 : m.colspan) > 1 && (o = c + (t.componentProps.colspan ?? 1)), (f = t.status) != null && f.invalid && o <= c && a.push(c);
});
}
n.children.splice(r, 0, p), P.forEach((o) => {
var f, I, C, g;
let t = 0;
if (!n.children) return;
let c = null;
for (let $ = e.rowIndex; $ >= 0; $--) {
const R = n.children[$], v = (f = R.children) == null ? void 0 : f[o], y = ((I = v == null ? void 0 : v.componentProps) == null ? void 0 : I.rowspan) ?? 1;
y > 1 && !c && (c = R), t += y;
}
const m = (g = (C = n.children[r]) == null ? void 0 : C.children) == null ? void 0 : g[o];
t > r && m && (m.componentProps.rowspan = 0, m.status = { invalid: !0 }, c && c.children && (c.children[o].componentProps.rowspan += 1));
}), a.forEach((o) => {
var c, m, f;
const t = (f = (m = (c = n.children) == null ? void 0 : c[r]) == null ? void 0 : m.children) == null ? void 0 : f[o];
t && (t.componentProps.rowspan = 0, t.status = { invalid: !0 });
});
}
function pn(s, l) {
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "", e = T(u, n);
if (!e || !n.children) return;
const r = e.rowIndex, i = n.children[r];
if (!i.children) return;
const P = [];
i.children.forEach((p, a) => {
var d;
const w = ((d = p.componentProps) == null ? void 0 : d.rowspan) ?? 1;
(w === 0 || w > 1) && P.push(a);
}), P.forEach((p) => {
var w, d, h, o, t, c, m;
if (!n.children) return;
let a = null;
for (let f = r - 1; f >= 0; f--) {
const I = n.children[f], C = (w = I.children) == null ? void 0 : w[p];
if ((((d = C == null ? void 0 : C.componentProps) == null ? void 0 : d.rowspan) ?? 1) > 1 && !a) {
a = I;
break;
}
}
if (a)
x(
a,
`children.${p}.componentProps.rowspan`,
((h = a.children) == null ? void 0 : h[p].componentProps.rowspan) - 1
);
else {
const f = (t = (o = n.children[r]) == null ? void 0 : o.children) == null ? void 0 : t[p], I = (m = (c = n.children[r + 1]) == null ? void 0 : c.children) == null ? void 0 : m[p];
I && f && (x(
I,
"componentProps.rowspan",
f.componentProps.rowspan - 1
), x(
I,
"componentProps.colspan",
f.componentProps.colspan
), x(I, "status.invalid", !1));
}
}), n.children.splice(r, 1);
}
function dn(s, l) {
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "", e = T(u, n);
if (!e || !n.children) return;
const r = e.colIndex;
n.children.forEach((i) => {
var a;
if (!i.children) return;
const p = ((a = i.children[r].componentProps) == null ? void 0 : a.colspan) ?? 1;
p > 1 ? (x(
i,
`children.${r}.componentProps.colspan`,
p - 1
), i.children.splice(r + 1, 1)) : i.children.splice(r, 1), i.children.forEach((w, d) => {
var o;
const h = ((o = w.componentProps) == null ? void 0 : o.colspan) ?? 1;
h > 1 && h + d > r && x(
i,
`children.${d}.componentProps.colspan`,
h - 1
);
});
});
}
function an(s, l) {
var w, d, h, o;
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "", e = T(u, n);
if (!e || !n.children) return;
const r = e.rowIndex, i = e.colIndex, P = (w = n.children[r].children) == null ? void 0 : w[i];
if (!P) return;
const p = ((d = P.componentProps) == null ? void 0 : d.rowspan) ?? 1, a = ((h = P.componentProps) == null ? void 0 : h.colspan) ?? 1;
for (let t = 0; t < p; t++)
for (let c = 0; c < a; c++) {
if (t === 0 && c === 0) continue;
const m = r + t, f = i + c, I = (o = n.children[m].children) == null ? void 0 : o[f];
if (!I) return;
x(I, "componentProps.rowspan", 1), x(I, "componentProps.colspan", 1), x(I, "status.invalid", !1);
}
P.componentProps.rowspan = 1, P.componentProps.colspan = 1;
}
function z(s, l, n) {
var f, I, C, g, $, R, v, y, D, _, B, M, U, j, V;
const u = T(s, l);
if (!u || !l.children) return;
const e = n === "down", r = u.rowIndex, i = u.colIndex, P = (I = (f = l.children[r]) == null ? void 0 : f.children) == null ? void 0 : I[i];
if (!P) return;
const p = e ? "rowspan" : "colspan", a = (e ? r : i) + (((C = P.componentProps) == null ? void 0 : C[p]) ?? 1);
if (!(($ = (g = l.children[e ? a : r]) == null ? void 0 : g.children) != null && $[e ? i : a])) {
console.error(`最后一个元素,无法向${e ? "下" : "右"}合并`);
return;
}
const w = (v = (R = l.children[e ? a : r]) == null ? void 0 : R.children) == null ? void 0 : v[e ? i : a];
if (!w) return;
const d = ((y = P.componentProps) == null ? void 0 : y[p]) ?? 1, h = ((D = w.componentProps) == null ? void 0 : D[p]) ?? 1, o = e ? "colspan" : "rowspan", t = ((_ = P.componentProps) == null ? void 0 : _[o]) ?? 1;
let c = ((B = w.componentProps) == null ? void 0 : B[o]) ?? 1;
const m = [];
if (c === 0) {
console.error(`单元格的 ${o} 不相等,无法合并`);
return;
}
if (t > 1 && t !== c) {
let b = null;
for (let k = 0; k < t; k++) {
const S = (U = (M = l.children[e ? a : r + k]) == null ? void 0 : M.children) == null ? void 0 : U[e ? i + k : a], q = ((j = S == null ? void 0 : S.componentProps) == null ? void 0 : j[p]) ?? 1;
if (k === 0)
b = q;
else {
if (!S || b !== q) {
console.error(`下一行单元格的 ${p} 不相等,无法合并`);
return;
}
c += ((V = S.componentProps) == null ? void 0 : V[o]) ?? 1, m.push(S);
}
}
}
if (t !== c) {
console.error(`单元格的 ${o} 不相等,无法合并`);
return;
}
x(
P,
`componentProps.${p}`,
d + h
), x(w, `componentProps.${p}`, 0), x(w, "status.invalid", !0), m.forEach((b) => {
x(b, `componentProps.${p}`, 0), x(b, "status.invalid", !0);
});
}
function hn(s, l) {
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "";
z(u, n, "down");
}
function fn(s, l) {
const n = E(
l.schemas,
s.id ?? ""
), u = s.id ?? "";
z(u, n, "right");
}
function T(s, l) {
if (!l.children) return null;
for (let n = 0; n < l.children.length; n++) {
const u = l.children[n];
if (u.children)
for (let e = 0; e < u.children.length; e++) {
const r = u.children[e];
if (r.id === s)
return { cell: r, colIndex: e, rowIndex: n };
}
}
return null;
}
export {
sn as addColumnAfterRightClick,
ln as addRowAfterRightClick,
dn as deleteColumnAfterRightClick,
pn as deleteRowAfterRightClick,
T as findCellInfo,
E as getTableSchema,
z as mergeCells,
hn as mergeDown,
fn as mergeRight,
an as splitCell
};